|
|
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 ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)field.c 5.12 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include <sys/param.h> ! 25: #include <pwd.h> ! 26: #include <grp.h> ! 27: #include <string.h> ! 28: #include <stdio.h> ! 29: #include <ctype.h> ! 30: #include "chpass.h" ! 31: #include "pathnames.h" ! 32: ! 33: /* ARGSUSED */ ! 34: p_login(p, pw, ep) ! 35: char *p; ! 36: struct passwd *pw; ! 37: struct entry *ep; ! 38: { ! 39: if (!*p) { ! 40: (void)fprintf(stderr, "chpass: empty login field.\n"); ! 41: return(1); ! 42: } ! 43: if (*p == '-') { ! 44: (void)fprintf(stderr, ! 45: "chpass: login names may not begin with a hyphen.\n"); ! 46: return(1); ! 47: } ! 48: if (!(pw->pw_name = strdup(p))) { ! 49: (void)fprintf(stderr, "chpass: can't save entry.\n"); ! 50: return(1); ! 51: } ! 52: if (index(p, '.')) ! 53: (void)fprintf(stderr, ! 54: "chpass: \'.\' is dangerous in a login name.\n"); ! 55: for (; *p; ++p) ! 56: if (isupper(*p)) { ! 57: (void)fprintf(stderr, ! 58: "chpass: upper-case letters are dangerous in a login name.\n"); ! 59: break; ! 60: } ! 61: return(0); ! 62: } ! 63: ! 64: /* ARGSUSED */ ! 65: p_passwd(p, pw, ep) ! 66: char *p; ! 67: struct passwd *pw; ! 68: struct entry *ep; ! 69: { ! 70: if (!*p) ! 71: pw->pw_passwd = ""; /* "NOLOGIN"; */ ! 72: else if (!(pw->pw_passwd = strdup(p))) { ! 73: (void)fprintf(stderr, "chpass: can't save password entry.\n"); ! 74: return(1); ! 75: } ! 76: ! 77: return(0); ! 78: } ! 79: ! 80: /* ARGSUSED */ ! 81: p_uid(p, pw, ep) ! 82: register char *p; ! 83: struct passwd *pw; ! 84: struct entry *ep; ! 85: { ! 86: int id; ! 87: ! 88: if (!*p) { ! 89: (void)fprintf(stderr, "chpass: empty uid field.\n"); ! 90: return(1); ! 91: } ! 92: if (!isdigit(*p)) { ! 93: (void)fprintf(stderr, "chpass: illegal uid.\n"); ! 94: return(1); ! 95: } ! 96: id = atoi(p); ! 97: if ((u_int)id > USHRT_MAX) { ! 98: (void)fprintf(stderr, "chpass: %d > max uid value (%d).\n", ! 99: id, USHRT_MAX); ! 100: return(1); ! 101: } ! 102: pw->pw_uid = id; ! 103: return(0); ! 104: } ! 105: ! 106: /* ARGSUSED */ ! 107: p_gid(p, pw, ep) ! 108: register char *p; ! 109: struct passwd *pw; ! 110: struct entry *ep; ! 111: { ! 112: struct group *gr; ! 113: int id; ! 114: ! 115: if (!*p) { ! 116: (void)fprintf(stderr, "chpass: empty gid field.\n"); ! 117: return(1); ! 118: } ! 119: if (!isdigit(*p)) { ! 120: if (!(gr = getgrnam(p))) { ! 121: (void)fprintf(stderr, ! 122: "chpass: unknown group %s.\n", p); ! 123: return(1); ! 124: } ! 125: pw->pw_gid = gr->gr_gid; ! 126: return(0); ! 127: } ! 128: id = atoi(p); ! 129: if ((u_int)id > USHRT_MAX) { ! 130: (void)fprintf(stderr, "chpass: %d > max gid value (%d).\n", ! 131: id, USHRT_MAX); ! 132: return(1); ! 133: } ! 134: pw->pw_gid = id; ! 135: return(0); ! 136: } ! 137: ! 138: /* ARGSUSED */ ! 139: p_class(p, pw, ep) ! 140: char *p; ! 141: struct passwd *pw; ! 142: struct entry *ep; ! 143: { ! 144: if (!*p) ! 145: pw->pw_class = ""; ! 146: else if (!(pw->pw_class = strdup(p))) { ! 147: (void)fprintf(stderr, "chpass: can't save entry.\n"); ! 148: return(1); ! 149: } ! 150: ! 151: return(0); ! 152: } ! 153: ! 154: /* ARGSUSED */ ! 155: p_change(p, pw, ep) ! 156: char *p; ! 157: struct passwd *pw; ! 158: struct entry *ep; ! 159: { ! 160: if (!atot(p, &pw->pw_change)) ! 161: return(0); ! 162: (void)fprintf(stderr, "chpass: illegal date for change field.\n"); ! 163: return(1); ! 164: } ! 165: ! 166: /* ARGSUSED */ ! 167: p_expire(p, pw, ep) ! 168: char *p; ! 169: struct passwd *pw; ! 170: struct entry *ep; ! 171: { ! 172: if (!atot(p, &pw->pw_expire)) ! 173: return(0); ! 174: (void)fprintf(stderr, "chpass: illegal date for expire field.\n"); ! 175: return(1); ! 176: } ! 177: ! 178: /* ARGSUSED */ ! 179: p_gecos(p, pw, ep) ! 180: char *p; ! 181: struct passwd *pw; ! 182: struct entry *ep; ! 183: { ! 184: if (!*p) ! 185: ep->save = ""; ! 186: else if (!(ep->save = strdup(p))) { ! 187: (void)fprintf(stderr, "chpass: can't save entry.\n"); ! 188: return(1); ! 189: } ! 190: return(0); ! 191: } ! 192: ! 193: /* ARGSUSED */ ! 194: p_hdir(p, pw, ep) ! 195: char *p; ! 196: struct passwd *pw; ! 197: struct entry *ep; ! 198: { ! 199: if (!*p) { ! 200: (void)fprintf(stderr, "chpass: empty home directory field.\n"); ! 201: return(1); ! 202: } ! 203: if (!(pw->pw_dir = strdup(p))) { ! 204: (void)fprintf(stderr, "chpass: can't save entry.\n"); ! 205: return(1); ! 206: } ! 207: return(0); ! 208: } ! 209: ! 210: /* ARGSUSED */ ! 211: p_shell(p, pw, ep) ! 212: register char *p; ! 213: struct passwd *pw; ! 214: struct entry *ep; ! 215: { ! 216: char *t, *ok_shell(); ! 217: ! 218: if (!*p) { ! 219: pw->pw_shell = _PATH_BSHELL; ! 220: return(0); ! 221: } ! 222: /* only admin can change from or to "restricted" shells */ ! 223: if (uid && pw->pw_shell && !ok_shell(pw->pw_shell)) { ! 224: (void)fprintf(stderr, ! 225: "chpass: %s: current shell non-standard.\n", pw->pw_shell); ! 226: return(1); ! 227: } ! 228: if (!(t = ok_shell(p))) { ! 229: if (uid) { ! 230: (void)fprintf(stderr, ! 231: "chpass: %s: non-standard shell.\n", p); ! 232: return(1); ! 233: } ! 234: } ! 235: else ! 236: p = t; ! 237: if (!(pw->pw_shell = strdup(p))) { ! 238: (void)fprintf(stderr, "chpass: can't save entry.\n"); ! 239: return(1); ! 240: } ! 241: return(0); ! 242: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.