~ubuntu-branches/ubuntu/trusty/ntp/trusty-proposed

« back to all changes in this revision

Viewing changes to sntp/libopts/save.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-04-03 07:21:01 UTC
  • mfrom: (4.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20130403072101-v3vt8xcs18b6uhjf
Tags: 1:4.2.6.p5+dfsg-2ubuntu1
* New upstream version, fixing build failure in raring.
* Merge with Debian; remaining changes:
  + debian/ntp.conf, debian/ntpdate.default: Change default server to
    ntp.ubuntu.com.
  + debian/ntpdate.ifup: Stop ntp before running ntpdate when an interface
    comes up, then start again afterwards.
  + debian/ntp.init, debian/rules: Only stop when entering single user mode.
  + Add enforcing AppArmor profile:
    - debian/control: Add Conflicts/Replaces on apparmor-profiles.
    - debian/control: Add Suggests on apparmor.
    - debian/ntp.dirs: Add apparmor directories.
    - debian/ntp.preinst: Force complain on certain upgrades.
    - debian/ntp.postinst: Reload apparmor profile.
    - debian/ntp.postrm: Remove the force-complain file.
    - add debian/apparmor-profile*.
    - debian/rules: install apparmor-profile and apparmor-profile.tunable.
    - debian/README.Debian: Add note on AppArmor.
  + debian/{control,rules}: Add and enable hardened build for PIE.
  + debian/apparmor-profile: Adjust location of drift files.
  + debian/rules, debian/ntp.dirs, debian/source_ntp.py: Add apport hook.
  + debian/ntpdate-debian: Disregard empty ntp.conf files.
  + debian/ntp.preinst: Remove empty /etc/ntp.conf on fresh intallation.
  + debian/ntpdate.ifup: Fix interaction with openntpd.
  + debian/source_ntp.py: Add filter on AppArmor profile names to prevent
    false positives from denials originating in other packages.
  + debian/apparmor-profile: Add samba4 ntp signing socket to ntpd apparmor
    profile.
  + debian/apparmor-profile: adjust for IPv6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * \file save.c
4
4
 *
5
 
 * Time-stamp:      "2010-07-17 10:27:48 bkorb"
 
5
 * Time-stamp:      "2011-04-06 09:21:44 bkorb"
6
6
 *
7
7
 *  This module's routines will take the currently set options and
8
8
 *  store them into an ".rc" file for re-interpretation the next
10
10
 *
11
11
 *  This file is part of AutoOpts, a companion to AutoGen.
12
12
 *  AutoOpts is free software.
13
 
 *  AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved
 
13
 *  AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved
14
14
 *
15
15
 *  AutoOpts is available under any one of two licenses.  The license
16
16
 *  in use must be one of these two and the choice is under the control
36
36
static tCC*
37
37
findDirName(tOptions* pOpts, int* p_free);
38
38
 
39
 
static tCC*
40
 
findFileName(tOptions* pOpts, int* p_free_name);
 
39
static char const *
 
40
findFileName(tOptions * pOpts, int * p_free_name);
41
41
 
42
42
static void
43
43
printEntry(
117
117
            char z[ AO_NAME_SIZE ];
118
118
            if ((pzEndDir - pzDir) > AO_NAME_LIMIT )
119
119
                return NULL;
120
 
            strncpy(z, pzDir, (size_t)(pzEndDir - pzDir));
121
 
            z[ (pzEndDir - pzDir) ] = NUL;
 
120
            memcpy(z, pzDir, (size_t)(pzEndDir - pzDir));
 
121
            z[pzEndDir - pzDir] = NUL;
122
122
            pzEnv = getenv(z);
123
123
        } else {
124
124
 
157
157
}
158
158
 
159
159
 
160
 
static tCC*
161
 
findFileName(tOptions* pOpts, int* p_free_name)
 
160
static char const *
 
161
findFileName(tOptions * pOpts, int * p_free_name)
162
162
{
163
 
    tCC*   pzDir;
164
163
    struct stat stBuf;
165
164
    int    free_dir_name = 0;
166
165
 
167
 
    pzDir = findDirName(pOpts, &free_dir_name);
 
166
    char const * pzDir = findDirName(pOpts, &free_dir_name);
168
167
    if (pzDir == NULL)
169
168
        return NULL;
170
169
 
173
172
     *  structure so we can bail out early.
174
173
     */
175
174
    if (stat(pzDir, &stBuf) != 0) do {
 
175
        char z[AG_PATH_MAX];
 
176
        char * dirchp;
176
177
 
177
178
        /*
178
179
         *  IF we could not, check to see if we got a full
179
180
         *  path to a file name that has not been created yet.
180
181
         */
181
 
        if (errno == ENOENT) {
182
 
            char z[AG_PATH_MAX];
183
 
 
184
 
            /*
185
 
             *  Strip off the last component, stat the remaining string and
186
 
             *  that string must name a directory
187
 
             */
188
 
            char* pzDirCh = strrchr(pzDir, DIRCH);
189
 
            if (pzDirCh == NULL) {
190
 
                stBuf.st_mode = S_IFREG;
191
 
                continue;  /* bail out of error condition */
192
 
            }
193
 
 
194
 
            strncpy(z, pzDir, (size_t)(pzDirCh - pzDir));
195
 
            z[ pzDirCh - pzDir ] = NUL;
196
 
 
197
 
            if (  (stat(z, &stBuf) == 0)
198
 
               && S_ISDIR(stBuf.st_mode)) {
199
 
 
200
 
                /*
201
 
                 *  We found the directory.  Restore the file name and
202
 
                 *  mark the full name as a regular file
203
 
                 */
204
 
                stBuf.st_mode = S_IFREG;
205
 
                continue;  /* bail out of error condition */
206
 
            }
 
182
        if (errno != ENOENT) {
 
183
        bogus_name:
 
184
            fprintf(stderr, zWarn, pOpts->pzProgName);
 
185
            fprintf(stderr, zNoStat, errno, strerror(errno), pzDir);
 
186
            if (free_dir_name)
 
187
                AGFREE((void*)pzDir);
 
188
            return NULL;
207
189
        }
208
190
 
209
191
        /*
210
 
         *  We got a bogus name.
 
192
         *  Strip off the last component, stat the remaining string and
 
193
         *  that string must name a directory
211
194
         */
212
 
        fprintf(stderr, zWarn, pOpts->pzProgName);
213
 
        fprintf(stderr, zNoStat, errno, strerror(errno), pzDir);
214
 
        if (free_dir_name)
215
 
            AGFREE((void*)pzDir);
216
 
        return NULL;
 
195
        dirchp = strrchr(pzDir, DIRCH);
 
196
        if (dirchp == NULL) {
 
197
            stBuf.st_mode = S_IFREG;
 
198
            break; /* found directory -- viz.,  "." */
 
199
        }
 
200
 
 
201
        if ((dirchp - pzDir) >= sizeof(z))
 
202
            goto bogus_name;
 
203
 
 
204
        memcpy(z, pzDir, (size_t)(dirchp - pzDir));
 
205
        z[dirchp - pzDir] = NUL;
 
206
 
 
207
        if ((stat(z, &stBuf) != 0) || ! S_ISDIR(stBuf.st_mode))
 
208
            goto bogus_name;
 
209
        stBuf.st_mode = S_IFREG; /* file within this directory */
217
210
    } while (0);
218
211
 
219
212
    /*