use btree instead of hashing, don't have to resort later
[unix-history] / usr / src / usr.bin / passwd / passwd.c
CommitLineData
1f978f4c 1/*
259b2b93
KB
2 * Copyright (c) 1988 The Regents of the University of California.
3 * All rights reserved.
4 *
87198c0c 5 * %sccs.include.redist.c%
1f978f4c
KM
6 */
7
8#ifndef lint
9char copyright[] =
259b2b93 10"@(#) Copyright (c) 1988 The Regents of the University of California.\n\
1f978f4c 11 All rights reserved.\n";
259b2b93 12#endif /* not lint */
1f978f4c 13
252e456d 14#ifndef lint
6c2e82da 15static char sccsid[] = "@(#)passwd.c 5.5 (Berkeley) %G%";
259b2b93 16#endif /* not lint */
252e456d 17
259b2b93 18#include <stdio.h>
51611a4e 19#include <unistd.h>
252e456d 20
0a5d1840 21#ifdef KERBEROS
8e5709bc 22int use_kerberos = 1;
8e5709bc
KF
23#endif
24
252e456d 25main(argc, argv)
259b2b93
KB
26 int argc;
27 char **argv;
252e456d 28{
51611a4e 29 extern int optind;
8e5709bc 30 register int ch;
51611a4e 31 char *uname;
259b2b93 32
51611a4e
KB
33#ifdef KERBEROS
34 while ((ch = getopt(argc, argv, "l")) != EOF)
8e5709bc 35 switch (ch) {
51611a4e 36 case 'l': /* change local password file */
8e5709bc
KF
37 use_kerberos = 0;
38 break;
dbc50378
KB
39#else
40 while ((ch = getopt(argc, argv, "")) != EOF)
41 switch (ch) {
42#endif
8e5709bc
KF
43 default:
44 case '?':
45 usage();
46 exit(1);
47 }
48
49 argc -= optind;
50 argv += optind;
8e5709bc 51
51611a4e
KB
52 uname = getlogin();
53
8e5709bc 54 switch(argc) {
259b2b93 55 case 0:
259b2b93
KB
56 break;
57 case 1:
8e5709bc 58#ifdef KERBEROS
51611a4e 59 if (use_kerberos && strcmp(argv[1], uname)) {
6c2e82da
MK
60 (void)fprintf(stderr, "passwd: %s\n\t%s\n%s\n",
61"to change another user's Kerberos password, do",
62"\"kinit user; passwd; kdestroy\";",
63"to change a user's local passwd, use \"passwd -l user\"");
8e5709bc
KF
64 exit(1);
65 }
66#endif
3edd2701 67 uname = argv[0];
259b2b93
KB
68 break;
69 default:
8e5709bc 70 usage();
9ae20471
RC
71 exit(1);
72 }
8e5709bc
KF
73
74#ifdef KERBEROS
51611a4e
KB
75 if (use_kerberos)
76 exit(krb_passwd());
91c574da 77#endif
51611a4e 78 exit(local_passwd(uname));
252e456d 79}
8e5709bc
KF
80
81usage()
82{
83#ifdef KERBEROS
51611a4e 84 (void)fprintf(stderr, "usage: passwd [-l] user\n");
8e5709bc 85#else
51611a4e 86 (void)fprintf(stderr, "usage: passwd user\n");
8e5709bc
KF
87#endif
88}