1 /* 2 * Copyright (c) 1988, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char copyright[] = 10 "@(#) Copyright (c) 1988, 1993, 1994\n\ 11 The Regents of the University of California. All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)passwd.c 8.3 (Berkeley) 04/02/94"; 16 #endif /* not lint */ 17 18 #include <err.h> 19 #include <errno.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <unistd.h> 23 24 #include "extern.h" 25 26 void usage __P((void)); 27 28 #ifdef KERBEROS 29 int use_kerberos = 1; 30 #endif 31 32 int 33 main(argc, argv) 34 int argc; 35 char **argv; 36 { 37 int ch; 38 char *uname; 39 40 while ((ch = getopt(argc, argv, "l")) != EOF) 41 switch (ch) { 42 #ifdef KERBEROS 43 case 'l': /* change local password file */ 44 use_kerberos = 0; 45 break; 46 #endif 47 default: 48 case '?': 49 usage(); 50 } 51 52 argc -= optind; 53 argv += optind; 54 55 if ((uname = getlogin()) == NULL) 56 err(1, "getlogin"); 57 58 switch(argc) { 59 case 0: 60 break; 61 case 1: 62 #ifdef KERBEROS 63 if (use_kerberos && strcmp(argv[0], uname)) 64 errx(1,"%s\n\t%s\n%s\n", 65 "to change another user's Kerberos password, do", 66 "\"kinit user; passwd; kdestroy\";", 67 "to change a user's local passwd, use \"passwd -l user\""); 68 #endif 69 uname = argv[0]; 70 break; 71 default: 72 usage(); 73 } 74 75 #ifdef KERBEROS 76 if (use_kerberos) 77 exit(krb_passwd()); 78 #endif 79 exit(local_passwd(uname)); 80 } 81 82 void 83 usage() 84 { 85 86 #ifdef KERBEROS 87 (void)fprintf(stderr, "usage: passwd [-l] user\n"); 88 #else 89 (void)fprintf(stderr, "usage: passwd user\n"); 90 #endif 91 exit(1); 92 } 93