Annotation of src/usr.bin/passwd/passwd.c, Revision 1.6
1.6 ! weingart 1: /* $OpenBSD: passwd.c,v 1.5 1997/01/15 23:43:01 millert Exp $ */
1.4 deraadt 2:
1.1 deraadt 3: /*
4: * Copyright (c) 1988 The Regents of the University of California.
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: */
35:
36: #ifndef lint
37: char copyright[] =
38: "@(#) Copyright (c) 1988 The Regents of the University of California.\n\
39: All rights reserved.\n";
40: #endif /* not lint */
41:
42: #ifndef lint
43: /*static char sccsid[] = "from: @(#)passwd.c 5.5 (Berkeley) 7/6/91";*/
1.6 ! weingart 44: static char rcsid[] = "$OpenBSD: passwd.c,v 1.5 1997/01/15 23:43:01 millert Exp $";
1.1 deraadt 45: #endif /* not lint */
46:
47: #include <stdio.h>
48: #include <string.h>
49: #include <unistd.h>
1.3 tholo 50: #ifdef KERBEROS
51: #include <kerberosIV/krb.h>
52: #endif
1.1 deraadt 53:
54: /*
55: * Note on configuration:
56: * Generally one would not use both Kerberos and YP
57: * to maintain passwords.
58: *
59: */
60:
61: int use_kerberos;
62: int use_yp;
63:
64: #ifdef YP
65: int force_yp;
66: #endif
67:
1.6 ! weingart 68:
! 69: extern int local_passwd(char *);
! 70: extern int yp_passwd(char *);
! 71: extern int krb_passwd(void);
! 72: void usage(void);
! 73:
! 74:
! 75: int
1.1 deraadt 76: main(argc, argv)
77: int argc;
78: char **argv;
79: {
80: extern int optind;
81: register int ch;
82: char *username;
83: int status = 0;
1.3 tholo 84: #if defined(KERBEROS) || defined(KERBEROS5)
85: extern char realm[];
1.1 deraadt 86:
1.3 tholo 87: if (krb_get_lrealm(realm,1) == KSUCCESS)
88: use_kerberos = 1;
1.1 deraadt 89: #endif
90: #ifdef YP
91: use_yp = _yp_check(NULL);
92: #endif
93:
1.6 ! weingart 94: /* Process args and options */
1.5 millert 95: while ((ch = getopt(argc, argv, "lky")) != -1)
1.1 deraadt 96: switch (ch) {
97: case 'l': /* change local password file */
98: use_kerberos = 0;
99: use_yp = 0;
100: break;
101: case 'k': /* change Kerberos password */
102: #if defined(KERBEROS) || defined(KERBEROS5)
103: use_kerberos = 1;
104: use_yp = 0;
105: break;
106: #else
107: fprintf(stderr, "passwd: Kerberos not compiled in\n");
108: exit(1);
109: #endif
110: case 'y': /* change YP password */
111: #ifdef YP
112: if (!use_yp) {
113: fprintf(stderr, "passwd: YP not in use.\n");
114: exit(1);
115: }
116: use_kerberos = 0;
117: use_yp = 1;
118: force_yp = 1;
119: break;
120: #else
121: fprintf(stderr, "passwd: YP not compiled in\n");
122: exit(1);
123: #endif
124: default:
125: usage();
126: exit(1);
127: }
128:
129: argc -= optind;
130: argv += optind;
131:
132: username = getlogin();
133: if (username == NULL) {
134: fprintf(stderr, "passwd: who are you ??\n");
135: exit(1);
136: }
137:
138: switch(argc) {
139: case 0:
140: break;
141: case 1:
142: #if defined(KERBEROS) || defined(KERBEROS5)
143: if (use_kerberos && strcmp(argv[0], username)) {
144: (void)fprintf(stderr, "passwd: %s\n\t%s\n%s\n",
145: "to change another user's Kerberos password, do",
146: "\"kinit <user>; passwd; kdestroy\";",
147: "to change a user's local passwd, use \"passwd -l <user>\"");
148: exit(1);
149: }
150: #endif
151: username = argv[0];
152: break;
153: default:
154: usage();
155: exit(1);
156: }
157:
158: #if defined(KERBEROS) || defined(KERBEROS5)
159: if (use_kerberos)
160: exit(krb_passwd());
161: #endif
162: #ifdef YP
163: if (force_yp || ((status = local_passwd(username)) && use_yp))
164: exit(yp_passwd(username));
165: exit(status);
166: #endif
167: exit(local_passwd(username));
168: }
169:
1.6 ! weingart 170: void
! 171: usage(void)
1.1 deraadt 172: {
173: fprintf(stderr, "usage: passwd [-l] [-k] [-y] user\n");
174: }