X-Git-Url: https://git.cameronkatri.com/pw-darwin.git/blobdiff_plain/49800698c8a29ccb35c04022d63b4f4e62b9bb6b..9911194b74d0be840e13a1607c63922e24a68fa6:/chpass/util.c diff --git a/chpass/util.c b/chpass/util.c index d8917f5..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 @@ -35,14 +42,13 @@ #if 0 static char sccsid[] = "@(#)util.c 8.4 (Berkeley) 4/2/94"; #endif -static const char rcsid[] = - "$Id: util.c,v 1.6 1998/03/23 07:41:49 charnier Exp $"; #endif /* not lint */ +#include +__FBSDID("$FreeBSD$"); #include #include -#include #include #include #include @@ -50,16 +56,14 @@ static const char rcsid[] = #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]; @@ -75,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; @@ -113,7 +116,7 @@ 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; /* Allow two digit years 1969-2068 */ if (year < 69) @@ -135,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); + if (!strcmp(name, sh)) { + endusershell(); + return (1); + } + /* allow just shell name, but use "real" path */ + 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) - return (sh); + if ((p = strrchr(sh, '/')) && strcmp(name, p + 1) == 0) { + ret = strdup(sh); + endusershell(); + return (ret); + } } + endusershell(); return (NULL); }