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

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

1.3       hin         1: /*
                      2:  * Copyright (c) 1997-2000 Kungliga Tekniska Högskolan
                      3:  * (Royal Institute of Technology, Stockholm, Sweden).
                      4:  * All rights reserved.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  *
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  *
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
1.1       deraadt    16:  *
1.3       hin        17:  * 3. Neither the name of the Institute nor the names of its contributors
                     18:  *    may be used to endorse or promote products derived from this software
                     19:  *    without specific prior written permission.
1.1       deraadt    20:  *
1.3       hin        21:  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
                     22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
                     25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     31:  * SUCH DAMAGE.
1.1       deraadt    32:  */
                     33:
1.4     ! hin        34: #include <stdio.h>
        !            35: #include <stdlib.h>
        !            36: #include <string.h>
        !            37: #include <sys/types.h>
        !            38: #include <fcntl.h>
        !            39: #include <sys/uio.h>
        !            40: #include <unistd.h>
        !            41: #include <pwd.h>
        !            42: #include <sys/time.h>
        !            43: #include <sys/select.h>
        !            44: #include <sys/socket.h>
        !            45: #include <netinet/in.h>
        !            46: #include <arpa/inet.h>
        !            47: #include <netdb.h>
        !            48: #include <errno.h>
        !            49: #include <dlfcn.h>
        !            50: #include <util.h>
        !            51: #include <err.h>
        !            52: #include <kerberosV/krb5.h>
1.1       deraadt    53:
1.4     ! hin        54: /* RCSID("$KTH: kpasswd.c,v 1.23 2000/12/31 07:48:34 assar Exp $"); */
1.1       deraadt    55:
1.3       hin        56: int
1.4     ! hin        57: krb5_passwd (int argc, char **argv)
1.1       deraadt    58: {
1.3       hin        59:     krb5_error_code ret;
                     60:     krb5_context context;
                     61:     krb5_principal principal;
                     62:     krb5_get_init_creds_opt opt;
                     63:     krb5_creds cred;
                     64:     int result_code;
                     65:     krb5_data result_code_string, result_string;
                     66:     char pwbuf[BUFSIZ];
1.1       deraadt    67:
1.3       hin        68:     krb5_get_init_creds_opt_init (&opt);
1.1       deraadt    69:
1.3       hin        70:     krb5_get_init_creds_opt_set_tkt_life (&opt, 300);
                     71:     krb5_get_init_creds_opt_set_forwardable (&opt, FALSE);
                     72:     krb5_get_init_creds_opt_set_proxiable (&opt, FALSE);
1.1       deraadt    73:
1.3       hin        74:     ret = krb5_init_context (&context);
                     75:     if (ret)
                     76:        errx (1, "krb5_init_context failed: %d", ret);
                     77:
                     78:     if(argv[0]) {
                     79:        ret = krb5_parse_name (context, argv[0], &principal);
                     80:        if (ret)
                     81:            krb5_err (context, 1, ret, "krb5_parse_name");
                     82:     } else
                     83:        principal = NULL;
1.1       deraadt    84:
1.3       hin        85:     ret = krb5_get_init_creds_password (context,
                     86:                                        &cred,
                     87:                                        principal,
                     88:                                        NULL,
                     89:                                        krb5_prompter_posix,
                     90:                                        NULL,
                     91:                                        0,
                     92:                                        "kadmin/changepw",
                     93:                                        &opt);
                     94:     switch (ret) {
                     95:     case 0:
                     96:        break;
                     97:     case KRB5_LIBOS_PWDINTR :
                     98:        return 1;
                     99:     case KRB5KRB_AP_ERR_BAD_INTEGRITY :
                    100:     case KRB5KRB_AP_ERR_MODIFIED :
                    101:        krb5_errx(context, 1, "Password incorrect");
                    102:        break;
                    103:     default:
                    104:        krb5_err(context, 1, ret, "krb5_get_init_creds");
                    105:     }
                    106:
                    107:     krb5_data_zero (&result_code_string);
                    108:     krb5_data_zero (&result_string);
                    109:
                    110:     if(des_read_pw_string (pwbuf, sizeof(pwbuf), "New password: ", 1) != 0)
                    111:        return 1;
                    112:
                    113:     ret = krb5_change_password (context, &cred, pwbuf,
                    114:                                &result_code,
                    115:                                &result_code_string,
                    116:                                &result_string);
                    117:     if (ret)
                    118:        krb5_err (context, 1, ret, "krb5_change_password");
                    119:
                    120:     printf ("Reply from server: %.*s\n", (int)result_string.length,
                    121:            (char *)result_string.data);
                    122:
                    123:     krb5_data_free (&result_code_string);
                    124:     krb5_data_free (&result_string);
                    125:
                    126:     krb5_free_creds_contents (context, &cred);
                    127:     krb5_free_context (context);
                    128:     return result_code;
1.1       deraadt   129: }