pw_user.c (110df1daa0281082a7d5fde2b57a144b29c19c7d) | pw_user.c (644af48df68c2e5b309de3f1287fe64a449c825d) |
---|---|
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 --- 93 unchanged lines hidden (view full) --- 102 struct carg *a_name; 103 struct carg *a_uid; 104 struct carg *arg; 105 struct passwd *pwd = NULL; 106 struct group *grp; 107 struct stat st; 108 char line[_PASSWORD_LEN+1]; 109 FILE *fp; | 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 --- 93 unchanged lines hidden (view full) --- 102 struct carg *a_name; 103 struct carg *a_uid; 104 struct carg *arg; 105 struct passwd *pwd = NULL; 106 struct group *grp; 107 struct stat st; 108 char line[_PASSWORD_LEN+1]; 109 FILE *fp; |
110 mode_t dmode; | |
111 char *dmode_c; 112 void *set = NULL; 113 114 static struct passwd fakeuser = 115 { 116 NULL, 117 "*", 118 -1, --- 27 unchanged lines hidden (view full) --- 146 /* 147 * We can do all of the common legwork here 148 */ 149 150 if ((arg = getarg(args, 'b')) != NULL) { 151 cnf->home = arg->val; 152 } 153 | 110 char *dmode_c; 111 void *set = NULL; 112 113 static struct passwd fakeuser = 114 { 115 NULL, 116 "*", 117 -1, --- 27 unchanged lines hidden (view full) --- 145 /* 146 * We can do all of the common legwork here 147 */ 148 149 if ((arg = getarg(args, 'b')) != NULL) { 150 cnf->home = arg->val; 151 } 152 |
154 dmode = S_IRWXU | S_IRWXG | S_IRWXO; | |
155 if ((arg = getarg(args, 'M')) != NULL) { 156 dmode_c = arg->val; 157 if ((set = setmode(dmode_c)) == NULL) 158 errx(EX_DATAERR, "invalid directory creation mode '%s'", 159 dmode_c); | 153 if ((arg = getarg(args, 'M')) != NULL) { 154 dmode_c = arg->val; 155 if ((set = setmode(dmode_c)) == NULL) 156 errx(EX_DATAERR, "invalid directory creation mode '%s'", 157 dmode_c); |
160 cnf->homemode = getmode(set, dmode); | 158 cnf->homemode = getmode(set, _DEF_DIRMODE); |
161 free(set); 162 } 163 164 /* 165 * If we'll need to use it or we're updating it, 166 * then create the base home directory if necessary 167 */ 168 if (arg != NULL || getarg(args, 'm') != NULL) { --- 12 unchanged lines hidden (view full) --- 181 * This is a kludge especially for Joerg :) 182 * If the home directory would be created in the root partition, then 183 * we really create it under /usr which is likely to have more space. 184 * But we create a symlink from cnf->home -> "/usr" -> cnf->home 185 */ 186 if (strchr(cnf->home+1, '/') == NULL) { 187 strcpy(dbuf, "/usr"); 188 strncat(dbuf, cnf->home, MAXPATHLEN-5); | 159 free(set); 160 } 161 162 /* 163 * If we'll need to use it or we're updating it, 164 * then create the base home directory if necessary 165 */ 166 if (arg != NULL || getarg(args, 'm') != NULL) { --- 12 unchanged lines hidden (view full) --- 179 * This is a kludge especially for Joerg :) 180 * If the home directory would be created in the root partition, then 181 * we really create it under /usr which is likely to have more space. 182 * But we create a symlink from cnf->home -> "/usr" -> cnf->home 183 */ 184 if (strchr(cnf->home+1, '/') == NULL) { 185 strcpy(dbuf, "/usr"); 186 strncat(dbuf, cnf->home, MAXPATHLEN-5); |
189 if (mkdir(dbuf, dmode) != -1 || errno == EEXIST) { | 187 if (mkdir(dbuf, _DEF_DIRMODE) != -1 || errno == EEXIST) { |
190 chown(dbuf, 0, 0); 191 /* 192 * Skip first "/" and create symlink: 193 * /home -> usr/home 194 */ 195 symlink(dbuf+1, cnf->home); 196 } 197 /* If this falls, fall back to old method */ 198 } 199 strlcpy(dbuf, cnf->home, sizeof(dbuf)); 200 p = dbuf; 201 if (stat(dbuf, &st) == -1) { 202 while ((p = strchr(++p, '/')) != NULL) { 203 *p = '\0'; 204 if (stat(dbuf, &st) == -1) { | 188 chown(dbuf, 0, 0); 189 /* 190 * Skip first "/" and create symlink: 191 * /home -> usr/home 192 */ 193 symlink(dbuf+1, cnf->home); 194 } 195 /* If this falls, fall back to old method */ 196 } 197 strlcpy(dbuf, cnf->home, sizeof(dbuf)); 198 p = dbuf; 199 if (stat(dbuf, &st) == -1) { 200 while ((p = strchr(++p, '/')) != NULL) { 201 *p = '\0'; 202 if (stat(dbuf, &st) == -1) { |
205 if (mkdir(dbuf, dmode) == -1) | 203 if (mkdir(dbuf, _DEF_DIRMODE) == -1) |
206 goto direrr; 207 chown(dbuf, 0, 0); 208 } else if (!S_ISDIR(st.st_mode)) 209 errx(EX_OSFILE, "'%s' (root home parent) is not a directory", dbuf); 210 *p = '/'; 211 } 212 } 213 if (stat(dbuf, &st) == -1) { | 204 goto direrr; 205 chown(dbuf, 0, 0); 206 } else if (!S_ISDIR(st.st_mode)) 207 errx(EX_OSFILE, "'%s' (root home parent) is not a directory", dbuf); 208 *p = '/'; 209 } 210 } 211 if (stat(dbuf, &st) == -1) { |
214 if (mkdir(dbuf, dmode) == -1) { | 212 if (mkdir(dbuf, _DEF_DIRMODE) == -1) { |
215 direrr: err(EX_OSFILE, "mkdir '%s'", dbuf); 216 } 217 chown(dbuf, 0, 0); 218 } 219 } else if (!S_ISDIR(st.st_mode)) 220 errx(EX_OSFILE, "root home `%s' is not a directory", cnf->home); 221 } 222 --- 1052 unchanged lines hidden --- | 213 direrr: err(EX_OSFILE, "mkdir '%s'", dbuf); 214 } 215 chown(dbuf, 0, 0); 216 } 217 } else if (!S_ISDIR(st.st_mode)) 218 errx(EX_OSFILE, "root home `%s' is not a directory", cnf->home); 219 } 220 --- 1052 unchanged lines hidden --- |