~xnox/ubuntu/quantal/shadow/clear-locks

« back to all changes in this revision

Viewing changes to libmisc/strtoday.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2009-05-05 09:45:21 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090505094521-wpk2wn3q7957tlah
Tags: 1:4.1.3.1-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Ubuntu specific:
    + debian/login.defs: use SHA512 by default for password crypt routine.
  - debian/patches/stdout-encrypted-password.patch: chpasswd can report
    password hashes on stdout (debian bug 505640).
  - debian/login.pam: Enable SELinux support (debian bug 527106).
  - debian/securetty.linux: support Freescale MX-series (debian bug 527095).
* Add debian/patches/300_lastlog_failure: fixed upstream (debian bug 524873).
* Drop debian/patches/593_omit_lastchange_field_if_clock_is_misset: fixed
  upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 1991 - 1994, Julianne Frances Haugh
 
2
 * Copyright (c) 1991 - 1994, Julianne Frances Haugh
 
3
 * Copyright (c) 1996 - 1999, Marek Michałkiewicz
 
4
 * Copyright (c) 2003 - 2005, Tomasz Kłoczko
 
5
 * Copyright (c) 2008       , Nicolas François
3
6
 * All rights reserved.
4
7
 *
5
8
 * Redistribution and use in source and binary forms, with or without
10
13
 * 2. Redistributions in binary form must reproduce the above copyright
11
14
 *    notice, this list of conditions and the following disclaimer in the
12
15
 *    documentation and/or other materials provided with the distribution.
13
 
 * 3. Neither the name of Julianne F. Haugh nor the names of its contributors
14
 
 *    may be used to endorse or promote products derived from this software
15
 
 *    without specific prior written permission.
 
16
 * 3. The name of the copyright holders or contributors may not be used to
 
17
 *    endorse or promote products derived from this software without
 
18
 *    specific prior written permission.
16
19
 *
17
 
 * THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
18
 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 
 * ARE DISCLAIMED.  IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
21
 
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 
 * SUCH DAMAGE.
 
20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
21
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
22
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 
23
 * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
 
24
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
25
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
26
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
27
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
28
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
29
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
30
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
31
 */
29
32
 
30
33
#if !defined(__GLIBC__)
33
36
 
34
37
#include <config.h>
35
38
 
36
 
#ident "$Id: strtoday.c 1633 2008-01-05 13:23:22Z nekral-guest $"
 
39
#ident "$Id: strtoday.c 2139 2008-06-13 19:48:11Z nekral-guest $"
37
40
 
38
41
#include "defines.h"
39
42
#include "prototypes.h"
66
69
         * which is not what we expect, unless you're a BOFH :-).
67
70
         * (useradd sets sp_expire = current date for new lusers)
68
71
         */
69
 
        if (!str || *str == '\0')
 
72
        if ((NULL == str) || ('\0' == *str)) {
70
73
                return -1;
 
74
        }
71
75
 
72
76
        t = get_date (str, (time_t *) 0);
73
 
        if (t == (time_t) - 1)
 
77
        if ((time_t) - 1 == t) {
74
78
                return -1;
 
79
        }
75
80
        /* convert seconds to days since 1970-01-01 */
76
 
        return (t + DAY / 2) / DAY;
 
81
        return (long) (t + DAY / 2) / DAY;
77
82
}
78
83
 
79
84
#else                           /* !USE_GETDATE */
126
131
        memzero (&tp, sizeof tp);
127
132
        for (fmt = date_formats; *fmt; fmt++) {
128
133
                cp = strptime ((char *) str, *fmt, &tp);
129
 
                if (!cp || *cp != '\0')
 
134
                if ((NULL == cp) || ('\0' != *cp)) {
130
135
                        continue;
 
136
                }
131
137
 
132
138
                result = mktime (&tp);
133
 
                if (result == (time_t) - 1)
 
139
                if ((time_t) - 1 == result) {
134
140
                        continue;
 
141
                }
135
142
 
136
 
                return result / DAY;    /* success */
 
143
                return (long) (result / DAY);   /* success */
137
144
        }
138
145
        return -1;
139
146
#else
148
155
         * is compiled in ...
149
156
         */
150
157
 
151
 
        if (sscanf (str, "%d/%d/%d%c", &year, &month, &day, slop) != 3)
 
158
        if (sscanf (str, "%d/%d/%d%c", &year, &month, &day, slop) != 3) {
152
159
                return -1;
 
160
        }
153
161
 
154
162
        /*
155
163
         * the month, day of the month, and year are checked for
157
165
         * 1970 and 2069.
158
166
         */
159
167
 
160
 
        if (month < 1 || month > 12)
161
 
                return -1;
162
 
 
163
 
        if (day < 1)
164
 
                return -1;
165
 
 
166
 
        if ((month != 2 || (year % 4) != 0) && day > days[month])
167
 
                return -1;
168
 
        else if ((month == 2 && (year % 4) == 0) && day > 29)
169
 
                return -1;
170
 
 
171
 
        if (year < 0)
172
 
                return -1;
173
 
        else if (year <= 69)
 
168
        if ((month < 1) || (month > 12)) {
 
169
                return -1;
 
170
        }
 
171
 
 
172
        if (day < 1) {
 
173
                return -1;
 
174
        }
 
175
 
 
176
        if (   ((2 != month) || ((year % 4) != 0))
 
177
            && (day > days[month])) {
 
178
                return -1;
 
179
        } else if ((month == 2) && ((year % 4) == 0) && (day > 29)) {
 
180
                return -1;
 
181
        }
 
182
 
 
183
        if (year < 0) {
 
184
                return -1;
 
185
        } else if (year <= 69) {
174
186
                year += 2000;
175
 
        else if (year <= 99)
 
187
        } else if (year <= 99) {
176
188
                year += 1900;
 
189
        }
177
190
 
178
191
        /*
179
192
         * On systems with 32-bit signed time_t, time wraps around in 2038
181
194
         * This limit can be removed once no one is using 32-bit systems
182
195
         * anymore :-).  --marekm
183
196
         */
184
 
        if (year < 1970 || year > 2037)
 
197
        if ((year < 1970) || (year > 2037)) {
185
198
                return -1;
 
199
        }
186
200
 
187
201
        /*
188
202
         * the total number of days is the total number of days in all