pw_user.c (20590) | pw_user.c (20679) |
---|---|
1/*- 2 * Copyright (C) 1996 3 * David L. Nugent. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (C) 1996 3 * David L. Nugent. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $Id: pw_user.c,v 1.4 1996/12/17 01:43:30 davidn Exp $ | 26 * $Id: pw_user.c,v 1.5 1996/12/17 14:15:35 davidn Exp $ |
27 */ 28 29#include <unistd.h> 30#include <fcntl.h> 31#include <ctype.h> 32#include <paths.h> 33#include <sys/param.h> 34#include <dirent.h> --- 9 unchanged lines hidden (view full) --- 44static int print_user(struct passwd * pwd, int pretty); 45static uid_t pw_uidpolicy(struct userconf * cnf, struct cargs * args); 46static uid_t pw_gidpolicy(struct userconf * cnf, struct cargs * args, char *nam, gid_t prefer); 47static time_t pw_pwdpolicy(struct userconf * cnf, struct cargs * args); 48static time_t pw_exppolicy(struct userconf * cnf, struct cargs * args); 49static char *pw_homepolicy(struct userconf * cnf, struct cargs * args, char const * user); 50static char *pw_shellpolicy(struct userconf * cnf, struct cargs * args, char *newshell); 51static char *pw_password(struct userconf * cnf, struct cargs * args, char const * user); | 27 */ 28 29#include <unistd.h> 30#include <fcntl.h> 31#include <ctype.h> 32#include <paths.h> 33#include <sys/param.h> 34#include <dirent.h> --- 9 unchanged lines hidden (view full) --- 44static int print_user(struct passwd * pwd, int pretty); 45static uid_t pw_uidpolicy(struct userconf * cnf, struct cargs * args); 46static uid_t pw_gidpolicy(struct userconf * cnf, struct cargs * args, char *nam, gid_t prefer); 47static time_t pw_pwdpolicy(struct userconf * cnf, struct cargs * args); 48static time_t pw_exppolicy(struct userconf * cnf, struct cargs * args); 49static char *pw_homepolicy(struct userconf * cnf, struct cargs * args, char const * user); 50static char *pw_shellpolicy(struct userconf * cnf, struct cargs * args, char *newshell); 51static char *pw_password(struct userconf * cnf, struct cargs * args, char const * user); |
52static char *pw_checkname(char *name, int gecos); | |
53static char *shell_path(char const * path, char *shells[], char *sh); 54static void rmat(uid_t uid); 55 56/*- 57 * -C config configuration file 58 * -q quiet operation 59 * -n name login name 60 * -u uid user id --- 82 unchanged lines hidden (view full) --- 143 p = arg->val; 144 if ((grp = getgrnam(p)) == NULL) { 145 if (!isdigit(*p) || (grp = getgrgid((gid_t) atoi(p))) == NULL) 146 cmderr(EX_NOUSER, "group `%s' does not exist\n", p); 147 } 148 cnf->default_group = newstr(grp->gr_name); 149 } 150 if ((arg = getarg(args, 'L')) != NULL) | 52static char *shell_path(char const * path, char *shells[], char *sh); 53static void rmat(uid_t uid); 54 55/*- 56 * -C config configuration file 57 * -q quiet operation 58 * -n name login name 59 * -u uid user id --- 82 unchanged lines hidden (view full) --- 142 p = arg->val; 143 if ((grp = getgrnam(p)) == NULL) { 144 if (!isdigit(*p) || (grp = getgrgid((gid_t) atoi(p))) == NULL) 145 cmderr(EX_NOUSER, "group `%s' does not exist\n", p); 146 } 147 cnf->default_group = newstr(grp->gr_name); 148 } 149 if ((arg = getarg(args, 'L')) != NULL) |
151 cnf->default_class = pw_checkname(arg->val, 0); | 150 cnf->default_class = pw_checkname((u_char *)arg->val, 0); |
152 153 if ((arg = getarg(args, 'G')) != NULL && arg->val) { 154 int i = 0; 155 156 for (p = strtok(arg->val, ", \t"); i < _UC_MAXGROUPS && p != NULL; p = strtok(NULL, ", \t")) { 157 if ((grp = getgrnam(p)) == NULL) { 158 if (!isdigit(*p) || (grp = getgrgid((gid_t) atoi(p))) == NULL) 159 cmderr(EX_NOUSER, "group `%s' does not exist\n", p); --- 39 unchanged lines hidden (view full) --- 199 200 setpwent(); 201 while ((pwd = getpwent()) != NULL) 202 print_user(pwd, pretty); 203 endpwent(); 204 return EXIT_SUCCESS; 205 } 206 if ((a_name = getarg(args, 'n')) != NULL) | 151 152 if ((arg = getarg(args, 'G')) != NULL && arg->val) { 153 int i = 0; 154 155 for (p = strtok(arg->val, ", \t"); i < _UC_MAXGROUPS && p != NULL; p = strtok(NULL, ", \t")) { 156 if ((grp = getgrnam(p)) == NULL) { 157 if (!isdigit(*p) || (grp = getgrgid((gid_t) atoi(p))) == NULL) 158 cmderr(EX_NOUSER, "group `%s' does not exist\n", p); --- 39 unchanged lines hidden (view full) --- 198 199 setpwent(); 200 while ((pwd = getpwent()) != NULL) 201 print_user(pwd, pretty); 202 endpwent(); 203 return EXIT_SUCCESS; 204 } 205 if ((a_name = getarg(args, 'n')) != NULL) |
207 pwd = getpwnam(pw_checkname(a_name->val, 0)); | 206 pwd = getpwnam(pw_checkname((u_char *)a_name->val, 0)); |
208 a_uid = getarg(args, 'u'); 209 210 if (a_uid == NULL) { 211 if (a_name == NULL) 212 cmderr(EX_DATAERR, "user name or id required\n"); 213 214 /* 215 * Determine whether 'n' switch is name or uid - we don't --- 85 unchanged lines hidden (view full) --- 301 return print_user(pwd, getarg(args, 'P') != NULL); 302 303 /* 304 * The rest is edit code 305 */ 306 if ((arg = getarg(args, 'l')) != NULL) { 307 if (strcmp(pwd->pw_name, "root") == 0) 308 cmderr(EX_DATAERR, "can't rename `root' account\n"); | 207 a_uid = getarg(args, 'u'); 208 209 if (a_uid == NULL) { 210 if (a_name == NULL) 211 cmderr(EX_DATAERR, "user name or id required\n"); 212 213 /* 214 * Determine whether 'n' switch is name or uid - we don't --- 85 unchanged lines hidden (view full) --- 300 return print_user(pwd, getarg(args, 'P') != NULL); 301 302 /* 303 * The rest is edit code 304 */ 305 if ((arg = getarg(args, 'l')) != NULL) { 306 if (strcmp(pwd->pw_name, "root") == 0) 307 cmderr(EX_DATAERR, "can't rename `root' account\n"); |
309 pwd->pw_name = pw_checkname(arg->val, 0); | 308 pwd->pw_name = pw_checkname((u_char *)arg->val, 0); |
310 } 311 if ((arg = getarg(args, 'u')) != NULL && isdigit(*arg->val)) { 312 pwd->pw_uid = (uid_t) atol(arg->val); 313 if (pwd->pw_uid != 0 && strcmp(pwd->pw_name, "root") == 0) 314 cmderr(EX_DATAERR, "can't change uid of `root' account\n"); 315 if (pwd->pw_uid == 0 && strcmp(pwd->pw_name, "root") != 0) 316 fprintf(stderr, "WARNING: account `%s' will have a uid of 0 (superuser access!)\n", pwd->pw_name); 317 } --- 56 unchanged lines hidden (view full) --- 374 if (pwd->pw_uid == 0 && strcmp(pwd->pw_name, "root") != 0) 375 fprintf(stderr, "WARNING: new account `%s' has a uid of 0 (superuser access!)\n", pwd->pw_name); 376 } 377 378 /* 379 * Shared add/edit code 380 */ 381 if ((arg = getarg(args, 'c')) != NULL) | 309 } 310 if ((arg = getarg(args, 'u')) != NULL && isdigit(*arg->val)) { 311 pwd->pw_uid = (uid_t) atol(arg->val); 312 if (pwd->pw_uid != 0 && strcmp(pwd->pw_name, "root") == 0) 313 cmderr(EX_DATAERR, "can't change uid of `root' account\n"); 314 if (pwd->pw_uid == 0 && strcmp(pwd->pw_name, "root") != 0) 315 fprintf(stderr, "WARNING: account `%s' will have a uid of 0 (superuser access!)\n", pwd->pw_name); 316 } --- 56 unchanged lines hidden (view full) --- 373 if (pwd->pw_uid == 0 && strcmp(pwd->pw_name, "root") != 0) 374 fprintf(stderr, "WARNING: new account `%s' has a uid of 0 (superuser access!)\n", pwd->pw_name); 375 } 376 377 /* 378 * Shared add/edit code 379 */ 380 if ((arg = getarg(args, 'c')) != NULL) |
382 pwd->pw_gecos = pw_checkname(arg->val, 1); | 381 pwd->pw_gecos = pw_checkname((u_char *)arg->val, 1); |
383 384 if ((arg = getarg(args, 'h')) != NULL) { 385 if (strcmp(arg->val, "-") == 0) 386 pwd->pw_passwd = "*"; /* No access */ 387 else { 388 int fd = atoi(arg->val); 389 int b; 390 int istty = isatty(fd); --- 537 unchanged lines hidden (view full) --- 928 } 929 } 930 endgrent(); 931 printf("%s\n", j ? "\n" : ""); 932 } 933 return EXIT_SUCCESS; 934} 935 | 382 383 if ((arg = getarg(args, 'h')) != NULL) { 384 if (strcmp(arg->val, "-") == 0) 385 pwd->pw_passwd = "*"; /* No access */ 386 else { 387 int fd = atoi(arg->val); 388 int b; 389 int istty = isatty(fd); --- 537 unchanged lines hidden (view full) --- 927 } 928 } 929 endgrent(); 930 printf("%s\n", j ? "\n" : ""); 931 } 932 return EXIT_SUCCESS; 933} 934 |
936static char * 937pw_checkname(char *name, int gecos) | 935char * 936pw_checkname(u_char *name, int gecos) |
938{ 939 int l = 0; 940 char const *notch = gecos ? ":" : " ,\t:+-&#%$^()!@~*?<>=|\\/\""; 941 942 while (name[l]) { | 937{ 938 int l = 0; 939 char const *notch = gecos ? ":" : " ,\t:+-&#%$^()!@~*?<>=|\\/\""; 940 941 while (name[l]) { |
943 if (strchr(notch, name[l]) != NULL || name[l] < ' ' || name[l] > 126) 944 cmderr(EX_DATAERR, (name[l]<' ' || (unsigned char)name[l] > 126) | 942 if (strchr(notch, name[l]) != NULL || name[l] < ' ' || 943 name[l] == 127 || (!gecos && name[l] & 0x80)) /* 8-bit */ 944 cmderr(EX_DATAERR, (name[l]<' ' || name[l] > 126) |
945 ? "invalid character `%c' in field\n" 946 : "invalid character 0x$02x in field\n", 947 name[l]); 948 ++l; 949 } 950 if (!gecos && l > MAXLOGNAME) 951 cmderr(EX_DATAERR, "name too long `%s'\n", name); | 945 ? "invalid character `%c' in field\n" 946 : "invalid character 0x$02x in field\n", 947 name[l]); 948 ++l; 949 } 950 if (!gecos && l > MAXLOGNAME) 951 cmderr(EX_DATAERR, "name too long `%s'\n", name); |
952 return name; | 952 return (char *)name; |
953} 954 955 956static void 957rmat(uid_t uid) 958{ 959 DIR *d = opendir("/var/at/jobs"); 960 --- 19 unchanged lines hidden --- | 953} 954 955 956static void 957rmat(uid_t uid) 958{ 959 DIR *d = opendir("/var/at/jobs"); 960 --- 19 unchanged lines hidden --- |