pw.c (20303) | pw.c (21330) |
---|---|
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.c,v 1.1.1.2 1996/12/09 23:55:20 joerg Exp $ | 26 * $Id: pw.c,v 1.1.1.3 1996/12/10 23:58:58 joerg Exp $ |
27 */ 28 29#include "pw.h" | 27 */ 28 29#include "pw.h" |
30#include <paths.h> 31#include <sys/wait.h> |
|
30 31static char *progname = "pw"; 32 33const char *Modes[] = {"add", "del", "mod", "show", "next", NULL}; 34const char *Which[] = {"user", "group", NULL}; 35static const char *Combo1[] = { 36 "useradd", "userdel", "usermod", "usershow", "usernext", 37 "groupadd", "groupdel", "groupmod", "groupshow", "groupnext", --- 15 unchanged lines hidden (view full) --- 53 int ch; 54 int mode = -1; 55 int which = -1; 56 struct userconf *cnf; 57 58 static const char *opts[W_NUM][M_NUM] = 59 { 60 { /* user */ | 32 33static char *progname = "pw"; 34 35const char *Modes[] = {"add", "del", "mod", "show", "next", NULL}; 36const char *Which[] = {"user", "group", NULL}; 37static const char *Combo1[] = { 38 "useradd", "userdel", "usermod", "usershow", "usernext", 39 "groupadd", "groupdel", "groupmod", "groupshow", "groupnext", --- 15 unchanged lines hidden (view full) --- 55 int ch; 56 int mode = -1; 57 int which = -1; 58 struct userconf *cnf; 59 60 static const char *opts[W_NUM][M_NUM] = 61 { 62 { /* user */ |
61 "C:qn:u:c:d:e:p:g:G:mk:s:oL:i:w:h:Db:NP", 62 "C:qn:u:r", 63 "C:qn:u:c:d:e:p:g:G:mk:s:w:L:h:FNP", | 63 "C:qn:u:c:d:e:p:g:G:mk:s:oL:i:w:h:Db:NPy:Y", 64 "C:qn:u:rY", 65 "C:qn:u:c:d:e:p:g:G:mk:s:w:L:h:FNPY", |
64 "C:qn:u:FPa", 65 "C:q" 66 }, 67 { /* grp */ | 66 "C:qn:u:FPa", 67 "C:q" 68 }, 69 { /* grp */ |
68 "C:qn:g:h:M:pNP", 69 "C:qn:g:", 70 "C:qn:g:l:h:FM:m:NP", | 70 "C:qn:g:h:M:pNPY", 71 "C:qn:g:Y", 72 "C:qn:g:l:h:FM:m:NPY", |
71 "C:qn:g:FPa", 72 "C:q" 73 } 74 }; 75 76 static int (*funcs[W_NUM]) (struct userconf * _cnf, int _mode, struct cargs * _args) = 77 { /* Request handlers */ 78 pw_user, --- 66 unchanged lines hidden (view full) --- 145 */ 146 if (getarg(&arglist, 'q') != NULL) 147 freopen("/dev/null", "w", stderr); 148 149 /* 150 * Now, let's do the common initialisation 151 */ 152 cnf = read_userconfig(getarg(&arglist, 'C') ? getarg(&arglist, 'C')->val : NULL); | 73 "C:qn:g:FPa", 74 "C:q" 75 } 76 }; 77 78 static int (*funcs[W_NUM]) (struct userconf * _cnf, int _mode, struct cargs * _args) = 79 { /* Request handlers */ 80 pw_user, --- 66 unchanged lines hidden (view full) --- 147 */ 148 if (getarg(&arglist, 'q') != NULL) 149 freopen("/dev/null", "w", stderr); 150 151 /* 152 * Now, let's do the common initialisation 153 */ 154 cnf = read_userconfig(getarg(&arglist, 'C') ? getarg(&arglist, 'C')->val : NULL); |
153 return funcs[which] (cnf, mode, &arglist); | 155 ch = funcs[which] (cnf, mode, &arglist); 156 157 /* 158 * If everything went ok, and we've been asked to update 159 * the NIS maps, then do it now 160 */ 161 if (ch == EXIT_SUCCESS && getarg(&arglist, 'Y') != NULL) { 162 pid_t pid; 163 164 fflush(NULL); 165 if (chdir(_PATH_YP) == -1) 166 perror("chdir(" _PATH_YP ")"); 167 else if ((pid = fork()) == -1) 168 perror("fork()"); 169 else if (pid == 0) { 170 /* Is make anywhere else? */ 171 execlp("/usr/bin/make", "make", NULL); 172 _exit(1); 173 } else { 174 int i; 175 waitpid(pid, &i, 0); 176 if ((i = WEXITSTATUS(i)) != 0) 177 cmderr(ch, "warning: make exited with status %d\n", i); 178 else 179 pw_log(cnf, mode, which, "NIS maps updated"); 180 } 181 } 182 return ch; |
154} 155 156static int 157getindex(const char *words[], const char *word) 158{ 159 int i = 0; 160 161 while (words[i]) { --- 58 unchanged lines hidden (view full) --- 220 "\t-p date password expiry date\n" 221 "\t-g grp initial group\n" 222 "\t-G grp1,grp2 additional groups\n" 223 "\t-m [ -k dir ] create and set up home\n" 224 "\t-s shell name of login shell\n" 225 "\t-o duplicate uid ok\n" 226 "\t-L class user class\n" 227 "\t-h fd read password on fd\n" | 183} 184 185static int 186getindex(const char *words[], const char *word) 187{ 188 int i = 0; 189 190 while (words[i]) { --- 58 unchanged lines hidden (view full) --- 249 "\t-p date password expiry date\n" 250 "\t-g grp initial group\n" 251 "\t-G grp1,grp2 additional groups\n" 252 "\t-m [ -k dir ] create and set up home\n" 253 "\t-s shell name of login shell\n" 254 "\t-o duplicate uid ok\n" 255 "\t-L class user class\n" 256 "\t-h fd read password on fd\n" |
257 "\t-Y update NIS maps\n" |
|
228 "\t-N no update\n" 229 " Setting defaults:\n" 230 "\t-D set user defaults\n" 231 "\t-b dir default home root dir\n" 232 "\t-e period default expiry period\n" 233 "\t-p period default password change period\n" 234 "\t-g group default group\n" 235 "\t-G grp1,grp2 additional groups\n" 236 "\t-L class default user class\n" 237 "\t-k dir default home skeleton\n" 238 "\t-u min,max set min,max uids\n" 239 "\t-i min,max set min,max gids\n" 240 "\t-w method set default password method\n" | 258 "\t-N no update\n" 259 " Setting defaults:\n" 260 "\t-D set user defaults\n" 261 "\t-b dir default home root dir\n" 262 "\t-e period default expiry period\n" 263 "\t-p period default password change period\n" 264 "\t-g group default group\n" 265 "\t-G grp1,grp2 additional groups\n" 266 "\t-L class default user class\n" 267 "\t-k dir default home skeleton\n" 268 "\t-u min,max set min,max uids\n" 269 "\t-i min,max set min,max gids\n" 270 "\t-w method set default password method\n" |
241 "\t-s shell default shell\n", | 271 "\t-s shell default shell\n" 272 "\t-y path set NIS passwd file path\n", |
242 "usage: %s userdel [uid|name] [switches]\n" 243 "\t-n name login name\n" 244 "\t-u uid user id\n" | 273 "usage: %s userdel [uid|name] [switches]\n" 274 "\t-n name login name\n" 275 "\t-u uid user id\n" |
276 "\t-Y update NIS maps\n" |
|
245 "\t-r remove home & contents\n", 246 "usage: %s usermod [uid|name] [switches]\n" 247 "\t-C config configuration file\n" 248 "\t-q quiet operation\n" 249 "\t-F force add if no user\n" 250 "\t-n name login name\n" 251 "\t-u uid user id\n" 252 "\t-c comment user name/comment\n" 253 "\t-d directory home directory\n" 254 "\t-e date account expiry date\n" 255 "\t-p date password expiry date\n" 256 "\t-g grp initial group\n" 257 "\t-G grp1,grp2 additional groups\n" 258 "\t-l name new login name\n" 259 "\t-L class user class\n" 260 "\t-m [ -k dir ] create and set up home\n" 261 "\t-s shell name of login shell\n" 262 "\t-w method set new password using method\n" 263 "\t-h fd read password on fd\n" | 277 "\t-r remove home & contents\n", 278 "usage: %s usermod [uid|name] [switches]\n" 279 "\t-C config configuration file\n" 280 "\t-q quiet operation\n" 281 "\t-F force add if no user\n" 282 "\t-n name login name\n" 283 "\t-u uid user id\n" 284 "\t-c comment user name/comment\n" 285 "\t-d directory home directory\n" 286 "\t-e date account expiry date\n" 287 "\t-p date password expiry date\n" 288 "\t-g grp initial group\n" 289 "\t-G grp1,grp2 additional groups\n" 290 "\t-l name new login name\n" 291 "\t-L class user class\n" 292 "\t-m [ -k dir ] create and set up home\n" 293 "\t-s shell name of login shell\n" 294 "\t-w method set new password using method\n" 295 "\t-h fd read password on fd\n" |
296 "\t-Y update NIS maps\n" |
|
264 "\t-N no update\n", 265 "usage: %s usershow [uid|name] [switches]\n" 266 "\t-n name login name\n" 267 "\t-u uid user id\n" 268 "\t-F force print\n" 269 "\t-P prettier format\n" 270 "\t-a print all users\n", 271 "usage: %s usernext [switches]\n" 272 "\t-C config configuration file\n" 273 }, 274 { 275 "usage: %s groupadd [group|gid] [switches]\n" 276 "\t-C config configuration file\n" 277 "\t-q quiet operation\n" 278 "\t-n group group name\n" 279 "\t-g gid group id\n" 280 "\t-M usr1,usr2 add users as group members\n" 281 "\t-o duplicate gid ok\n" | 297 "\t-N no update\n", 298 "usage: %s usershow [uid|name] [switches]\n" 299 "\t-n name login name\n" 300 "\t-u uid user id\n" 301 "\t-F force print\n" 302 "\t-P prettier format\n" 303 "\t-a print all users\n", 304 "usage: %s usernext [switches]\n" 305 "\t-C config configuration file\n" 306 }, 307 { 308 "usage: %s groupadd [group|gid] [switches]\n" 309 "\t-C config configuration file\n" 310 "\t-q quiet operation\n" 311 "\t-n group group name\n" 312 "\t-g gid group id\n" 313 "\t-M usr1,usr2 add users as group members\n" 314 "\t-o duplicate gid ok\n" |
315 "\t-Y update NIS maps\n" |
|
282 "\t-N no update\n", 283 "usage: %s groupdel [group|gid] [switches]\n" 284 "\t-n name group name\n" | 316 "\t-N no update\n", 317 "usage: %s groupdel [group|gid] [switches]\n" 318 "\t-n name group name\n" |
285 "\t-g gid group id\n", | 319 "\t-g gid group id\n" 320 "\t-Y update NIS maps\n", |
286 "usage: %s groupmod [group|gid] [switches]\n" 287 "\t-C config configuration file\n" 288 "\t-q quiet operation\n" 289 "\t-F force add if not exists\n" 290 "\t-n name group name\n" 291 "\t-g gid group id\n" 292 "\t-M usr1,usr2 replaces users as group members\n" 293 "\t-m usr1,usr2 add users as group members\n" 294 "\t-l name new group name\n" | 321 "usage: %s groupmod [group|gid] [switches]\n" 322 "\t-C config configuration file\n" 323 "\t-q quiet operation\n" 324 "\t-F force add if not exists\n" 325 "\t-n name group name\n" 326 "\t-g gid group id\n" 327 "\t-M usr1,usr2 replaces users as group members\n" 328 "\t-m usr1,usr2 add users as group members\n" 329 "\t-l name new group name\n" |
330 "\t-Y update NIS maps\n" |
|
295 "\t-N no update\n", 296 "usage: %s groupshow [group|gid] [switches]\n" 297 "\t-n name group name\n" 298 "\t-g gid group id\n" 299 "\t-F force print\n" 300 "\t-P prettier format\n" 301 "\t-a print all accounting groups\n", 302 "usage: %s groupnext [switches]\n" --- 31 unchanged lines hidden --- | 331 "\t-N no update\n", 332 "usage: %s groupshow [group|gid] [switches]\n" 333 "\t-n name group name\n" 334 "\t-g gid group id\n" 335 "\t-F force print\n" 336 "\t-P prettier format\n" 337 "\t-a print all accounting groups\n", 338 "usage: %s groupnext [switches]\n" --- 31 unchanged lines hidden --- |