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

« back to all changes in this revision

Viewing changes to sntp/libopts/time.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 time.c
4
4
 *
5
 
 *  Time-stamp:      "2010-07-17 10:36:19 bkorb"
 
5
 *  Time-stamp:      "2011-03-06 11:52:23 bkorb"
6
6
 *
7
7
 *  This file is part of AutoOpts, a companion to AutoGen.
8
8
 *  AutoOpts is free software.
9
 
 *  AutoOpts is Copyright (c) 1992-2010 by Bruce Korb - all rights reserved
 
9
 *  AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved
10
10
 *
11
11
 *  AutoOpts is available under any one of two licenses.  The license
12
12
 *  in use must be one of these two and the choice is under the control
25
25
 *  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd
26
26
 */
27
27
 
28
 
#ifndef HAVE_PARSE_DURATION
29
 
#include <time.h>
30
 
 
31
 
static inline char *
32
 
ao_xstrdup(char const * pz)
33
 
{
34
 
    char * str;
35
 
    AGDUPSTR(str, pz, "time val str");
36
 
    return str;
37
 
}
38
 
 
39
 
#define xstrdup(_s) ao_xstrdup(_s)
40
 
 
41
 
#include "parse-duration.c"
42
 
 
43
 
#undef xstrdup
44
 
#endif
45
 
 
46
28
/*=export_func  optionTimeVal
47
29
 * private:
48
30
 *
49
 
 * what:  process an option with a time value.
 
31
 * what:  process an option with a time duration.
50
32
 * arg:   + tOptions* + pOpts    + program options descriptor +
51
33
 * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
52
34
 *
54
36
 *  Decipher a time duration value.
55
37
=*/
56
38
void
57
 
optionTimeVal(tOptions* pOpts, tOptDesc* pOD )
 
39
optionTimeVal(tOptions * pOpts, tOptDesc * pOD)
58
40
{
59
 
    long  val;
 
41
    time_t val;
60
42
 
61
43
    if ((pOD->fOptState & OPTST_RESET) != 0)
62
44
        return;
63
45
 
64
46
    val = parse_duration(pOD->optArg.argString);
65
 
    if (errno != 0)
66
 
        goto bad_time;
 
47
    if (val == BAD_TIME) {
 
48
        fprintf(stderr, zNotDuration, pOpts->pzProgName, pOD->optArg.argString);
 
49
        if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
 
50
            (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
 
51
    }
67
52
 
68
53
    if (pOD->fOptState & OPTST_ALLOC_ARG) {
69
54
        AGFREE(pOD->optArg.argString);
71
56
    }
72
57
 
73
58
    pOD->optArg.argInt = val;
 
59
}
 
60
 
 
61
/*=export_func  optionTimeDate
 
62
 * private:
 
63
 *
 
64
 * what:  process an option with a time and date.
 
65
 * arg:   + tOptions* + pOpts    + program options descriptor +
 
66
 * arg:   + tOptDesc* + pOptDesc + the descriptor for this arg +
 
67
 *
 
68
 * doc:
 
69
 *  Decipher a time and date value.
 
70
=*/
 
71
void
 
72
optionTimeDate(tOptions * pOpts, tOptDesc * pOD)
 
73
{
 
74
#if defined(HAVE_GETDATE_R) && defined(HAVE_PUTENV)
 
75
    if ((! HAS_pzPkgDataDir(pOpts)) || (pOpts->pzPkgDataDir == NULL))
 
76
        goto default_action;
 
77
 
 
78
    /*
 
79
     *  Export the DATEMSK environment variable.  getdate_r() uses it to
 
80
     *  find the file with the strptime formats.  If we cannot find the file
 
81
     *  we need ($PKGDATADIR/datemsk), then fall back to just a time duration.
 
82
     */
 
83
    {
 
84
        static char * envptr = NULL;
 
85
 
 
86
        if (envptr == NULL) {
 
87
            static char const fmt[] = "DATEMSK=%s/datemsk";
 
88
            envptr = AGALOC(sizeof(fmt) + strlen(pOpts->pzPkgDataDir), fmt);
 
89
            sprintf(envptr, fmt, pOpts->pzPkgDataDir);
 
90
 
 
91
            putenv(envptr);
 
92
        }
 
93
 
 
94
        if (access(envptr+8, R_OK) != 0)
 
95
            goto default_action;
 
96
    }
 
97
 
 
98
    /*
 
99
     *  Convert the date to a time since the epoch and stash it in a long int.
 
100
     */
 
101
    {
 
102
        struct tm stm;
 
103
        time_t tm;
 
104
 
 
105
        if (getdate_r(pOD->optArg.argString, &stm) != 0) {
 
106
            fprintf(stderr, zNotDate, pOpts->pzProgName,
 
107
                    pOD->optArg.argString);
 
108
            if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
 
109
                (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
 
110
            return;
 
111
        }
 
112
 
 
113
        tm = mktime(&stm);
 
114
 
 
115
        if (pOD->fOptState & OPTST_ALLOC_ARG) {
 
116
            AGFREE(pOD->optArg.argString);
 
117
            pOD->fOptState &= ~OPTST_ALLOC_ARG;
 
118
        }
 
119
 
 
120
        pOD->optArg.argInt = tm;
 
121
    }
74
122
    return;
75
123
 
76
 
bad_time:
77
 
    fprintf(stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString);
78
 
    if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0)
79
 
        (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE);
 
124
default_action:
80
125
 
81
 
    pOD->optArg.argInt = ~0;
 
126
#endif
 
127
    optionTimeVal(pOpts, pOD);
 
128
    if (pOD->optArg.argInt != BAD_TIME)
 
129
        pOD->optArg.argInt += (unsigned long)time(NULL);
82
130
}
83
131
/*
84
132
 * Local Variables: