2 Copyright (C) 1989 by the Massachusetts Institute of Technology
4 Export of this software from the United States of America is assumed
5 to require a specific license from the United States Government.
6 It is the responsibility of any person or organization contemplating
7 export to obtain such a license before exporting.
9 WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
10 distribute this software and its documentation for any purpose and
11 without fee is hereby granted, provided that the above copyright
12 notice appear in all copies and that both that copyright notice and
13 this permission notice appear in supporting documentation, and that
14 the name of M.I.T. not be used in advertising or publicity pertaining
15 to distribution of the software without specific, written prior
16 permission. M.I.T. makes no representations about the suitability of
17 this software for any purpose. It is provided "as is" without express
23 * change your password with kerberos
26 #include "kadm_locl.h"
28 RCSID("$Id: kpasswd.c,v 1.29 1999/11/13 06:33:20 assar Exp $");
33 fprintf(stderr, "Usage: ");
34 fprintf(stderr, "kpasswd [-h ] [-n user] [-i instance] [-r realm] ");
35 fprintf(stderr, "[-u fullname]\n");
40 main(int argc, char **argv)
42 krb_principal principal;
43 krb_principal default_principal;
44 int realm_given = 0; /* True if realm was give on cmdline */
45 int use_default = 1; /* True if we should use default name */
46 int status; /* return code */
47 char pword[MAX_KPW_LEN];
49 char tktstring[MaxPathLen];
51 set_progname (argv[0]);
53 memset (&principal, 0, sizeof(principal));
54 memset (&default_principal, 0, sizeof(default_principal));
56 krb_get_default_principal (default_principal.name,
57 default_principal.instance,
58 default_principal.realm);
60 while ((c = getopt(argc, argv, "u:n:i:r:h")) != -1) {
63 status = krb_parse_name (optarg, &principal);
64 if (status != KSUCCESS)
65 errx (2, "%s", krb_get_err_text(status));
66 if (principal.realm[0])
68 else if (krb_get_lrealm(principal.realm, 1) != KSUCCESS)
69 errx (1, "Could not find default realm!");
73 strlcpy(principal.name,
75 sizeof(principal.name));
77 warnx("Bad name: %s", optarg);
83 strlcpy(principal.instance,
85 sizeof(principal.instance));
87 warnx("Bad instance: %s", optarg);
92 if (k_isrealm(optarg)) {
93 strlcpy(principal.realm,
95 sizeof(principal.realm));
98 warnx("Bad realm: %s", optarg);
113 status = krb_parse_name (argv[optind], &principal);
114 if(status != KSUCCESS)
115 errx (1, "%s", krb_get_err_text (status));
119 strlcpy(principal.name,
120 default_principal.name,
121 sizeof(principal.name));
122 strlcpy(principal.instance,
123 default_principal.instance,
124 sizeof(principal.instance));
125 strlcpy(principal.realm,
126 default_principal.realm,
127 sizeof(principal.realm));
129 if (!principal.name[0])
130 strlcpy(principal.name,
131 default_principal.name,
132 sizeof(principal.name));
133 if (!principal.realm[0])
134 strlcpy(principal.realm,
135 default_principal.realm,
136 sizeof(principal.realm));
139 snprintf(tktstring, sizeof(tktstring), "%s_cpw_%u",
140 TKT_ROOT, (unsigned)getpid());
141 krb_set_tkt_string(tktstring);
143 if (get_pw_new_pwd(pword, sizeof(pword), &principal,
149 status = kadm_init_link (PWSERV_NAME, KRB_MASTER, principal.realm);
150 if (status != KADM_SUCCESS)
151 com_err(argv[0], status, "while initializing");
154 char *pw_msg; /* message from server */
156 des_string_to_key(pword, &newkey);
157 status = kadm_change_pw_plain((unsigned char*)&newkey, pword, &pw_msg);
158 memset(newkey, 0, sizeof(newkey));
160 if (status == KADM_INSECURE_PW)
161 warnx ("Insecure password: %s", pw_msg);
162 else if (status != KADM_SUCCESS)
163 com_err(argv[0], status, " attempting to change password.");
165 memset(pword, 0, sizeof(pword));
167 if (status != KADM_SUCCESS)
168 fprintf(stderr,"Password NOT changed.\n");
170 printf("Password changed.\n");