2 * Copyright (c) 1995, 1996, 1997, 1998 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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.
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.
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
34 #include "kadm_locl.h"
36 RCSID("$Id: new_pwd.c,v 1.14 1999/12/02 16:58:36 joda Exp $");
39 #define read_long_pw_string placebo_read_pw_string
41 #define read_long_pw_string des_read_pw_string
45 check_pw (char *pword)
47 int ret = kadm_check_pw(pword);
51 case KADM_PASS_Q_NULL:
52 return "Null passwords are not allowed - "
53 "Please enter a longer password.";
54 case KADM_PASS_Q_TOOSHORT:
55 return "Password is to short - Please enter a longer password.";
56 case KADM_PASS_Q_CLASS:
58 return "Please don't use an all-lower case password.\n"
59 "\tUnusual capitalization, delimiter characters or "
60 "digits are suggested.";
62 return "Password is insecure"; /* XXX this shouldn't happen */
66 get_pw_new_pwd(char *pword, int pwlen, krb_principal *pr, int print_realm)
68 char ppromp[40+ANAME_SZ+INST_SZ+REALM_SZ]; /* for the password prompt */
69 char npromp[40+ANAME_SZ+INST_SZ+REALM_SZ]; /* for the password prompt */
71 char p[MAX_K_NAME_SZ];
73 char local_realm[REALM_SZ];
78 * We don't care about failure; this is to determine whether or
79 * not to print the realm in the prompt for a new password.
81 krb_get_lrealm(local_realm, 1);
83 if (strcmp(local_realm, pr->realm))
88 krb_unparse_name_r(pr, p);
89 if(print_realm == 0 && (q = strrchr(p, '@')))
93 snprintf(ppromp, sizeof(ppromp), "Old password for %s:", p);
94 if (read_long_pw_string(pword, pwlen-1, ppromp, 0)) {
95 fprintf(stderr, "Error reading old password.\n");
99 status = krb_get_pw_in_tkt(pr->name, pr->instance, pr->realm,
100 PWSERV_NAME, KADM_SINST, 1, pword);
101 if (status != KSUCCESS) {
102 if (status == INTK_BADPW) {
103 printf("Incorrect old password.\n");
107 fprintf(stderr, "Kerberos error: %s\n", krb_get_err_text(status));
111 memset(pword, 0, pwlen);
114 char verify[MAX_KPW_LEN];
116 snprintf(npromp, sizeof(npromp), "New Password for %s:",p);
117 if (read_long_pw_string(pword, pwlen-1, npromp, 0)) {
119 "Error reading new password, password unchanged.\n");
122 expl = check_pw (pword);
124 printf("\n\t%s\n\n", expl);
127 /* Now we got an ok password, verify it. */
128 snprintf(npromp, sizeof(npromp), "Verifying New Password for %s:", p);
129 if (read_long_pw_string(verify, MAX_KPW_LEN-1, npromp, 0)) {
131 "Error reading new password, password unchanged.\n");
134 if (strcmp(pword, verify) != 0) {
135 printf("Verify failure - try again\n");
136 expl = ""; /* continue */