386BSD 0.1 development
[unix-history] / usr / src / usr.bin / chpass / util.c
index 83ba5cd..b3db7c9 100644 (file)
@@ -1,52 +1,70 @@
-/*
+/*-
  * Copyright (c) 1988 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1988 The Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)util.c     5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)util.c     5.14 (Berkeley) 2/12/91";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/time.h>
 #include <tzfile.h>
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/time.h>
 #include <tzfile.h>
-#include </usr/src/include/pwd.h>
+#include <pwd.h>
 #include <stdio.h>
 #include <stdio.h>
-#include <chpass.h>
-#include <strings.h>
+#include <string.h>
 #include <ctype.h>
 #include <ctype.h>
+#include "chpass.h"
+#include "pathnames.h"
 
 static int dmsize[] =
        { -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 static char *months[] =
 
 static int dmsize[] =
        { -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 static char *months[] =
-       { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
-         "Sep", "Oct", "Nov", "Dec", NULL };
+       { "January", "February", "March", "April", "May", "June",
+         "July", "August", "September", "October", "November",
+         "December", NULL };
 char *
 ttoa(tval)
        time_t tval;
 {
        struct tm *tp;
 char *
 ttoa(tval)
        time_t tval;
 {
        struct tm *tp;
-       static char tbuf[10];
+       static char tbuf[50];
 
 
-       if (!tval)
-               bcopy("None", tbuf, 6);
-       else {
+       if (tval) {
                tp = localtime(&tval);
                (void)sprintf(tbuf, "%s %d, 19%d", months[tp->tm_mon],
                    tp->tm_mday, tp->tm_year);
        }
                tp = localtime(&tval);
                (void)sprintf(tbuf, "%s %d, 19%d", months[tp->tm_mon],
                    tp->tm_mday, tp->tm_year);
        }
+       else
+               *tbuf = '\0';
        return(tbuf);
 } 
 
        return(tbuf);
 } 
 
@@ -59,7 +77,7 @@ atot(p, store)
        time_t tval, time();
        int day, month, year;
 
        time_t tval, time();
        int day, month, year;
 
-       if (!strncasecmp(p, "none", 4)) {
+       if (!*p) {
                *store = 0;
                return(0);
        }
                *store = 0;
                return(0);
        }
@@ -93,54 +111,30 @@ bad:               return(1);
        tval = isleap(year) && month > 2;
        for (--year; year >= EPOCH_YEAR; --year)
                tval += isleap(year) ?
        tval = isleap(year) && month > 2;
        for (--year; year >= EPOCH_YEAR; --year)
                tval += isleap(year) ?
-                   DAYS_PER_LYEAR : DAYS_PER_NYEAR;
+                   DAYSPERLYEAR : DAYSPERNYEAR;
        while (--month)
                tval += dmsize[month];
        while (--month)
                tval += dmsize[month];
-       tval += day - 1;
-       tval = tval * HOURS_PER_DAY * MINS_PER_HOUR * SECS_PER_MIN;
+       tval += day;
+       tval = tval * HOURSPERDAY * MINSPERHOUR * SECSPERMIN;
        tval -= lt->tm_gmtoff;
        *store = tval;
        return(0);
 }
 
        tval -= lt->tm_gmtoff;
        *store = tval;
        return(0);
 }
 
-print(fp, pw)
-       FILE *fp;
-       struct passwd *pw;
+char *
+ok_shell(name)
+       register char *name;
 {
 {
-       register char *p;
-       char *getusershell(), *ttoa();
+       register char *p, *sh;
+       char *getusershell();
 
 
-       fprintf(fp, "Changing user database information for %s.\n",
-           pw->pw_name);
-       if (!uid) {
-               fprintf(fp, "Login: %s\n", pw->pw_name);
-               fprintf(fp, "Uid [#]: %d\n", pw->pw_uid);
-               fprintf(fp, "Gid [# or name]: %d\n", pw->pw_gid);
-               fprintf(fp, "Change [dd month yy]: %s\n", ttoa(pw->pw_change));
-               fprintf(fp, "Expire [dd month yy]: %s\n", ttoa(pw->pw_expire));
-               fprintf(fp, "Class: %s\n", pw->pw_class);
-               fprintf(fp, "Home directory: %s\n", pw->pw_dir);
-               fprintf(fp, "Shell: %s\n",
-                   *pw->pw_shell ? pw->pw_shell : "/bin/sh");
-       }
-       else {
-               /* only admin can change "restricted" shells */
-               setusershell();
-               for (;;)
-                       if (!(p = getusershell()))
-                               break;
-                       else if (!strcmp(pw->pw_shell, p)) {
-                               fprintf(fp, "Shell: %s\n",
-                                   *pw->pw_shell ? pw->pw_shell : "/bin/sh");
-                               break;
-                       }
+       setusershell();
+       while (sh = getusershell()) {
+               if (!strcmp(name, sh))
+                       return(name);
+               /* allow just shell name, but use "real" path */
+               if ((p = rindex(sh, '/')) && !strcmp(name, p + 1))
+                       return(sh);
        }
        }
-       p = strsep(pw->pw_gecos, ",");
-       fprintf(fp, "Full Name: %s\n", p ? p : "");
-       p = strsep((char *)NULL, ",");
-       fprintf(fp, "Location: %s\n", p ? p : "");
-       p = strsep((char *)NULL, ",");
-       fprintf(fp, "Office Phone: %s\n", p ? p : "");
-       p = strsep((char *)NULL, ",");
-       fprintf(fp, "Home Phone: %s\n", p ? p : "");
+       return(NULL);
 }
 }