X-Git-Url: https://git.cameronkatri.com/pw-darwin.git/blobdiff_plain/4071e799547aef1aad5f8690453556d743f576b8..9911194b74d0be840e13a1607c63922e24a68fa6:/chpass/util.c diff --git a/chpass/util.c b/chpass/util.c index fe89d79..07d96e2 100644 --- a/chpass/util.c +++ b/chpass/util.c @@ -1,6 +1,13 @@ /*- * Copyright (c) 1988, 1993, 1994 * The Regents of the University of California. All rights reserved. + * Copyright (c) 2002 Networks Associates Technology, Inc. + * All rights reserved. + * + * Portions of this software were developed for the FreeBSD Project by + * ThinkSec AS and NAI Labs, the Security Research Division of Network + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 + * ("CBOSS"), as part of the DARPA CHATS research program. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,13 +39,16 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)util.c 8.4 (Berkeley) 4/2/94"; +#endif #endif /* not lint */ +#include +__FBSDID("$FreeBSD$"); #include #include -#include #include #include #include @@ -46,16 +56,14 @@ static char sccsid[] = "@(#)util.c 8.4 (Berkeley) 4/2/94"; #include #include "chpass.h" -#include "pathnames.h" -static char *months[] = +static const char *months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", NULL }; char * -ttoa(tval) - time_t tval; +ttoa(time_t tval) { struct tm *tp; static char tbuf[50]; @@ -71,12 +79,11 @@ ttoa(tval) } int -atot(p, store) - char *p; - time_t *store; +atot(char *p, time_t *store) { static struct tm *lt; - char *t, **mp; + char *t; + const char **mp; time_t tval; int day, month, year; @@ -91,12 +98,16 @@ atot(p, store) } if (!(t = strtok(p, " \t"))) goto bad; - for (mp = months;; ++mp) { - if (!*mp) - goto bad; - if (!strncasecmp(*mp, t, 3)) { - month = mp - months + 1; - break; + if (isdigit(*t)) { + month = atoi(t); + } else { + for (mp = months;; ++mp) { + if (!*mp) + goto bad; + if (!strncasecmp(*mp, t, 3)) { + month = mp - months + 1; + break; + } } } if (!(t = strtok((char *)NULL, " \t,")) || !isdigit(*t)) @@ -105,11 +116,14 @@ atot(p, store) if (!(t = strtok((char *)NULL, " \t,")) || !isdigit(*t)) goto bad; year = atoi(t); - if (day < 1 || day > 31 || month < 1 || month > 12 || !year) + if (day < 1 || day > 31 || month < 1 || month > 12) goto bad; - if (year < 100) + /* Allow two digit years 1969-2068 */ + if (year < 69) + year += 2000; + else if (year < 100) year += 1900; - if (year <= 1970) + if (year < 1969) bad: return (1); lt->tm_year = year - 1900; lt->tm_mon = month - 1; @@ -124,19 +138,45 @@ bad: return (1); return (0); } -char * -ok_shell(name) - char *name; +int +ok_shell(char *name) { char *p, *sh; setusershell(); - while (sh = getusershell()) { - if (!strcmp(name, sh)) - return (name); + while ((sh = getusershell())) { + if (!strcmp(name, sh)) { + endusershell(); + return (1); + } /* allow just shell name, but use "real" path */ - if ((p = strrchr(sh, '/')) && strcmp(name, p + 1) == 0) - return (sh); + if ((p = strrchr(sh, '/')) && strcmp(name, p + 1) == 0) { + endusershell(); + return (1); + } + } + endusershell(); + return (0); +} + +char * +dup_shell(char *name) +{ + char *p, *sh, *ret; + + setusershell(); + while ((sh = getusershell())) { + if (!strcmp(name, sh)) { + endusershell(); + return (strdup(name)); + } + /* allow just shell name, but use "real" path */ + if ((p = strrchr(sh, '/')) && strcmp(name, p + 1) == 0) { + ret = strdup(sh); + endusershell(); + return (ret); + } } + endusershell(); return (NULL); }