|
|
1.1 ! root 1: /*- ! 2: * Copyright (c) 1988 The Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted provided ! 6: * that: (1) source distributions retain this entire copyright notice and ! 7: * comment, and (2) distributions including binaries display the following ! 8: * acknowledgement: ``This product includes software developed by the ! 9: * University of California, Berkeley and its contributors'' in the ! 10: * documentation or other materials provided with the distribution and in ! 11: * all advertising materials mentioning features or use of this software. ! 12: * Neither the name of the University nor the names of its contributors may ! 13: * be used to endorse or promote products derived from this software without ! 14: * specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 16: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 17: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)util.c 5.13 (Berkeley) 6/29/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include <sys/types.h> ! 25: #include <sys/time.h> ! 26: #include <tzfile.h> ! 27: #include <pwd.h> ! 28: #include <stdio.h> ! 29: #include <string.h> ! 30: #include <ctype.h> ! 31: #include "chpass.h" ! 32: #include "pathnames.h" ! 33: ! 34: static int dmsize[] = ! 35: { -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; ! 36: static char *months[] = ! 37: { "January", "February", "March", "April", "May", "June", ! 38: "July", "August", "September", "October", "November", ! 39: "December", NULL }; ! 40: char * ! 41: ttoa(tval) ! 42: time_t tval; ! 43: { ! 44: struct tm *tp; ! 45: static char tbuf[50]; ! 46: ! 47: if (tval) { ! 48: tp = localtime(&tval); ! 49: (void)sprintf(tbuf, "%s %d, 19%d", months[tp->tm_mon], ! 50: tp->tm_mday, tp->tm_year); ! 51: } ! 52: else ! 53: *tbuf = '\0'; ! 54: return(tbuf); ! 55: } ! 56: ! 57: atot(p, store) ! 58: char *p; ! 59: time_t *store; ! 60: { ! 61: register char *t, **mp; ! 62: static struct tm *lt; ! 63: time_t tval, time(); ! 64: int day, month, year; ! 65: ! 66: if (!*p) { ! 67: *store = 0; ! 68: return(0); ! 69: } ! 70: if (!lt) { ! 71: unsetenv("TZ"); ! 72: (void)time(&tval); ! 73: lt = localtime(&tval); ! 74: } ! 75: if (!(t = strtok(p, " \t"))) ! 76: goto bad; ! 77: for (mp = months;; ++mp) { ! 78: if (!*mp) ! 79: goto bad; ! 80: if (!strncasecmp(*mp, t, 3)) { ! 81: month = mp - months + 1; ! 82: break; ! 83: } ! 84: } ! 85: if (!(t = strtok((char *)NULL, " \t,")) || !isdigit(*t)) ! 86: goto bad; ! 87: day = atoi(t); ! 88: if (!(t = strtok((char *)NULL, " \t,")) || !isdigit(*t)) ! 89: goto bad; ! 90: year = atoi(t); ! 91: if (day < 1 || day > 31 || month < 1 || month > 12 || !year) ! 92: goto bad; ! 93: if (year < 100) ! 94: year += TM_YEAR_BASE; ! 95: if (year <= EPOCH_YEAR) ! 96: bad: return(1); ! 97: tval = isleap(year) && month > 2; ! 98: for (--year; year >= EPOCH_YEAR; --year) ! 99: tval += isleap(year) ? ! 100: DAYSPERLYEAR : DAYSPERNYEAR; ! 101: while (--month) ! 102: tval += dmsize[month]; ! 103: tval += day; ! 104: tval = tval * HOURSPERDAY * MINSPERHOUR * SECSPERMIN; ! 105: tval -= lt->tm_gmtoff; ! 106: *store = tval; ! 107: return(0); ! 108: } ! 109: ! 110: /* ! 111: * print -- ! 112: * print out the file for the user to edit; strange side-effect: ! 113: * return if the user is allowed to modify their shell. ! 114: */ ! 115: print(fp, pw) ! 116: FILE *fp; ! 117: struct passwd *pw; ! 118: { ! 119: register char *p; ! 120: int shellval; ! 121: char *bp; ! 122: char *getusershell(), *ok_shell(), *ttoa(); ! 123: ! 124: shellval = 1; ! 125: (void)fprintf(fp, "#Changing user database information for %s.\n", ! 126: pw->pw_name); ! 127: if (!uid) { ! 128: (void)fprintf(fp, "Login: %s\n", pw->pw_name); ! 129: (void)fprintf(fp, "Password: %s\n", pw->pw_passwd); ! 130: (void)fprintf(fp, "Uid [#]: %d\n", pw->pw_uid); ! 131: (void)fprintf(fp, "Gid [# or name]: %d\n", pw->pw_gid); ! 132: (void)fprintf(fp, "Change [month day year]: %s\n", ! 133: ttoa(pw->pw_change)); ! 134: (void)fprintf(fp, "Expire [month day year]: %s\n", ! 135: ttoa(pw->pw_expire)); ! 136: (void)fprintf(fp, "Class: %s\n", pw->pw_class); ! 137: (void)fprintf(fp, "Home directory: %s\n", pw->pw_dir); ! 138: (void)fprintf(fp, "Shell: %s\n", ! 139: *pw->pw_shell ? pw->pw_shell : _PATH_BSHELL); ! 140: } ! 141: /* only admin can change "restricted" shells */ ! 142: else if (ok_shell(pw->pw_shell)) ! 143: (void)fprintf(fp, "Shell: %s\n", ! 144: *pw->pw_shell ? pw->pw_shell : _PATH_BSHELL); ! 145: else ! 146: shellval = 0; ! 147: bp = pw->pw_gecos; ! 148: p = strsep(&bp, ","); ! 149: (void)fprintf(fp, "Full Name: %s\n", p ? p : ""); ! 150: p = strsep(&bp, ","); ! 151: (void)fprintf(fp, "Location: %s\n", p ? p : ""); ! 152: p = strsep(&bp, ","); ! 153: (void)fprintf(fp, "Office Phone: %s\n", p ? p : ""); ! 154: p = strsep(&bp, ","); ! 155: (void)fprintf(fp, "Home Phone: %s\n", p ? p : ""); ! 156: return(shellval); ! 157: } ! 158: ! 159: char * ! 160: ok_shell(name) ! 161: register char *name; ! 162: { ! 163: register char *p, *sh; ! 164: char *getusershell(); ! 165: ! 166: setusershell(); ! 167: while (sh = getusershell()) { ! 168: if (!strcmp(name, sh)) ! 169: return(name); ! 170: /* allow just shell name, but use "real" path */ ! 171: if ((p = rindex(sh, '/')) && !strcmp(name, p + 1)) ! 172: return(sh); ! 173: } ! 174: return(NULL); ! 175: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.