[BACK]Return to passwd.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / passwd

Annotation of src/usr.bin/passwd/passwd.c, Revision 1.4

1.4     ! deraadt     1: /*     $OpenBSD$       */
        !             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.4     ! deraadt    44: static char rcsid[] = "$OpenBSD: passwd.c,v 1.3 1996/05/03 18:23:34 tholo 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:
                     68: main(argc, argv)
                     69:        int argc;
                     70:        char **argv;
                     71: {
                     72:        extern int optind;
                     73:        register int ch;
                     74:        char *username;
                     75:        int status = 0;
                     76:        char *basename;
1.3       tholo      77: #if defined(KERBEROS) || defined(KERBEROS5)
                     78:        extern char realm[];
1.1       deraadt    79:
1.3       tholo      80:        if (krb_get_lrealm(realm,1) == KSUCCESS)
                     81:                use_kerberos = 1;
1.1       deraadt    82: #endif
                     83: #ifdef YP
                     84:        use_yp = _yp_check(NULL);
                     85: #endif
                     86:
                     87:        basename = strrchr(argv[0], '/');
                     88:        if (basename == NULL)
                     89:                basename = argv[0];
                     90:
                     91:        while ((ch = getopt(argc, argv, "lky")) != EOF)
                     92:                switch (ch) {
                     93:                case 'l':               /* change local password file */
                     94:                        use_kerberos = 0;
                     95:                        use_yp = 0;
                     96:                        break;
                     97:                case 'k':               /* change Kerberos password */
                     98: #if defined(KERBEROS) || defined(KERBEROS5)
                     99:                        use_kerberos = 1;
                    100:                        use_yp = 0;
                    101:                        break;
                    102: #else
                    103:                        fprintf(stderr, "passwd: Kerberos not compiled in\n");
                    104:                        exit(1);
                    105: #endif
                    106:                case 'y':               /* change YP password */
                    107: #ifdef YP
                    108:                        if (!use_yp) {
                    109:                                fprintf(stderr, "passwd: YP not in use.\n");
                    110:                                exit(1);
                    111:                        }
                    112:                        use_kerberos = 0;
                    113:                        use_yp = 1;
                    114:                        force_yp = 1;
                    115:                        break;
                    116: #else
                    117:                        fprintf(stderr, "passwd: YP not compiled in\n");
                    118:                        exit(1);
                    119: #endif
                    120:                default:
                    121:                        usage();
                    122:                        exit(1);
                    123:                }
                    124:
                    125:        argc -= optind;
                    126:        argv += optind;
                    127:
                    128:        username = getlogin();
                    129:        if (username == NULL) {
                    130:                fprintf(stderr, "passwd: who are you ??\n");
                    131:                exit(1);
                    132:        }
                    133:
                    134:        switch(argc) {
                    135:        case 0:
                    136:                break;
                    137:        case 1:
                    138: #if defined(KERBEROS) || defined(KERBEROS5)
                    139:                if (use_kerberos && strcmp(argv[0], username)) {
                    140:                        (void)fprintf(stderr, "passwd: %s\n\t%s\n%s\n",
                    141: "to change another user's Kerberos password, do",
                    142: "\"kinit <user>; passwd; kdestroy\";",
                    143: "to change a user's local passwd, use \"passwd -l <user>\"");
                    144:                        exit(1);
                    145:                }
                    146: #endif
                    147:                username = argv[0];
                    148:                break;
                    149:        default:
                    150:                usage();
                    151:                exit(1);
                    152:        }
                    153:
                    154: #if defined(KERBEROS) || defined(KERBEROS5)
                    155:        if (use_kerberos)
                    156:                exit(krb_passwd());
                    157: #endif
                    158: #ifdef YP
                    159:        if (force_yp || ((status = local_passwd(username)) && use_yp))
                    160:                exit(yp_passwd(username));
                    161:        exit(status);
                    162: #endif
                    163:        exit(local_passwd(username));
                    164: }
                    165:
                    166: usage()
                    167: {
                    168:        fprintf(stderr, "usage: passwd [-l] [-k] [-y] user\n");
                    169: }