prettyness police
[unix-history] / usr / src / usr.bin / passwd / passwd.c
CommitLineData
1f978f4c 1/*
e5090888
KB
2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
259b2b93 4 *
87198c0c 5 * %sccs.include.redist.c%
1f978f4c
KM
6 */
7
8#ifndef lint
e5090888
KB
9static char copyright[] =
10"@(#) Copyright (c) 1988, 1993\n\
11 The Regents of the University of California. All rights reserved.\n";
259b2b93 12#endif /* not lint */
1f978f4c 13
252e456d 14#ifndef lint
c09e47ff 15static char sccsid[] = "@(#)passwd.c 8.2 (Berkeley) %G%";
259b2b93 16#endif /* not lint */
252e456d 17
c09e47ff 18#include <err.h>
033ad209 19#include <errno.h>
259b2b93 20#include <stdio.h>
c09e47ff 21#include <stdlib.h>
51611a4e 22#include <unistd.h>
252e456d 23
c09e47ff
JSP
24#include "extern.h"
25
26void usage __P((void));
27
0a5d1840 28#ifdef KERBEROS
8e5709bc 29int use_kerberos = 1;
8e5709bc
KF
30#endif
31
c09e47ff 32int
252e456d 33main(argc, argv)
259b2b93
KB
34 int argc;
35 char **argv;
252e456d 36{
c09e47ff 37 int ch;
51611a4e 38 char *uname;
259b2b93 39
51611a4e 40 while ((ch = getopt(argc, argv, "l")) != EOF)
8e5709bc 41 switch (ch) {
c09e47ff 42#ifdef KERBEROS
51611a4e 43 case 'l': /* change local password file */
8e5709bc
KF
44 use_kerberos = 0;
45 break;
dbc50378 46#endif
8e5709bc
KF
47 default:
48 case '?':
49 usage();
8e5709bc
KF
50 }
51
52 argc -= optind;
53 argv += optind;
8e5709bc 54
c09e47ff
JSP
55 if ((uname = getlogin()) == NULL)
56 err(1, "getlogin");
51611a4e 57
8e5709bc 58 switch(argc) {
259b2b93 59 case 0:
259b2b93
KB
60 break;
61 case 1:
8e5709bc 62#ifdef KERBEROS
c09e47ff
JSP
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\"");
8e5709bc 68#endif
3edd2701 69 uname = argv[0];
259b2b93
KB
70 break;
71 default:
8e5709bc 72 usage();
9ae20471 73 }
8e5709bc
KF
74
75#ifdef KERBEROS
51611a4e
KB
76 if (use_kerberos)
77 exit(krb_passwd());
91c574da 78#endif
51611a4e 79 exit(local_passwd(uname));
252e456d 80}
8e5709bc 81
c09e47ff 82void
8e5709bc
KF
83usage()
84{
c09e47ff 85
8e5709bc 86#ifdef KERBEROS
51611a4e 87 (void)fprintf(stderr, "usage: passwd [-l] user\n");
8e5709bc 88#else
51611a4e 89 (void)fprintf(stderr, "usage: passwd user\n");
8e5709bc 90#endif
c09e47ff 91 exit(1);
8e5709bc 92}