* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)krb_passwd.c 8.1 (Berkeley) %G%";
#include <sys/resource.h>
#include <kerberosIV/des.h>
#include <kerberosIV/krb.h>
#include "kpasswd_proto.h"
static struct timeval timeout
= { CLIENT_KRB_TIMEOUT
, 0 };
static struct kpasswd_data proto_data
;
static Key_schedule osched
;
Key_schedule random_schedule
;
char realm
[REALM_SZ
], krbhst
[MAX_HSTNM
];
char pass
[_PASSWORD_LEN
], password
[_PASSWORD_LEN
];
static struct rlimit rl
= { 0, 0 };
(void)signal(SIGHUP
, SIG_IGN
);
(void)signal(SIGINT
, SIG_IGN
);
(void)signal(SIGTSTP
, SIG_IGN
);
if (setrlimit(RLIMIT_CORE
, &rl
) < 0) {
"passwd: setrlimit: %s\n", strerror(errno
));
if ((se
= getservbyname(SERVICE
, PROTO
)) == NULL
) {
"passwd: couldn't find entry for service %s/%s\n",
if ((rval
= krb_get_lrealm(realm
,1)) != KSUCCESS
) {
"passwd: couldn't get local Kerberos realm: %s\n",
if ((rval
= krb_get_krbhst(krbhst
, realm
, 1)) != KSUCCESS
) {
"passwd: couldn't get Kerberos host: %s\n",
if ((host
= gethostbyname(krbhst
)) == NULL
) {
"passwd: couldn't get host entry for krb host %s\n",
sin
.sin_family
= host
->h_addrtype
;
bcopy(host
->h_addr
, (char *) &sin
.sin_addr
, host
->h_length
);
sin
.sin_port
= se
->s_port
;
if ((sock
= socket(AF_INET
, SOCK_STREAM
, IPPROTO_TCP
)) < 0) {
(void)fprintf(stderr
, "passwd: socket: %s\n", strerror(errno
));
if (connect(sock
, (struct sockaddr
*) &sin
, sizeof(sin
)) < 0) {
(void)fprintf(stderr
, "passwd: connect: %s\n", strerror(errno
));
authopts
, /* NOT mutual */
&ticket
, /* (filled in) */
krbhst
, /* instance (krbhst) */
(u_long
) getpid(), /* checksum */
(void)fprintf(stderr
, "passwd: Kerberos sendauth error: %s\n",
krb_get_cred("krbtgt", realm
, realm
, &cred
);
(void)printf("Changing Kerberos password for %s.%s@%s.\n",
cred
.pname
, cred
.pinst
, realm
);
if (des_read_pw_string(pass
,
sizeof(pass
)-1, "Old Kerberos password:", 0)) {
"passwd: error reading old Kerberos password\n");
(void)des_string_to_key(pass
, okey
);
(void)des_key_sched(okey
, osched
);
(void)des_set_key(okey
, osched
);
/* wait on the verification string */
select(sock
+ 1, &readfds
, (fd_set
*) 0, (fd_set
*) 0, &timeout
);
if ((rval
< 1) || !FD_ISSET(sock
, &readfds
)) {
(void)fprintf(stderr
, "passwd: timed out (aborted)\n");
(void)fprintf(stderr
, "passwd: select failed (aborted)\n");
/* read verification string */
if (des_read(sock
, &proto_data
, sizeof(proto_data
)) !=
"passwd: couldn't read verification string (aborted)\n");
(void)signal(SIGHUP
, finish
);
(void)signal(SIGINT
, finish
);
if (strcmp(SECURE_STRING
, proto_data
.secure_msg
) != 0) {
/* don't complain loud if user just hit return */
if (pass
== NULL
|| (!*pass
))
(void)fprintf(stderr
, "Sorry\n");
(void)des_key_sched(proto_data
.random_key
, random_schedule
);
(void)des_set_key(proto_data
.random_key
, random_schedule
);
(void)bzero(pass
, sizeof(pass
));
if (des_read_pw_string(pass
,
sizeof(pass
)-1, "New Kerberos password:", 0)) {
"passwd: error reading new Kerberos password (aborted)\n");
if (des_read_pw_string(password
,
sizeof(password
)-1, "Retype new Kerberos password:", 0)) {
"passwd: error reading new Kerberos password (aborted)\n");
if (strcmp(password
, pass
) != 0) {
"passwd: password mismatch (aborted)\n");
(void)printf("using NULL password\n");
send_update(sock
, password
, SECURE_STRING
);
select(sock
+ 1, &readfds
, (fd_set
*) 0, (fd_set
*) 0, &timeout
);
if ((rval
< 1) || !FD_ISSET(sock
, &readfds
)) {
"passwd: timed out reading ACK (aborted)\n");
(void)fprintf(stderr
, "passwd: select failed (aborted)\n");
send_update(dest
, pwd
, str
)
static struct update_data ud
;
(void)strncpy(ud
.secure_msg
, str
, _PASSWORD_LEN
);
(void)strncpy(ud
.pw
, pwd
, sizeof(ud
.pw
));
if (des_write(dest
, &ud
, sizeof(ud
)) != sizeof(ud
)) {
"passwd: couldn't write pw update (abort)\n");
bzero((char *)&ud
, sizeof(ud
));
cc
= des_read(remote
, buf
, sizeof(buf
));
"passwd: error reading acknowledgement (aborted)\n");
(void)bzero((char *)&proto_data
, sizeof(proto_data
));
(void)bzero((char *)okey
, sizeof(okey
));
(void)bzero((char *)osched
, sizeof(osched
));
(void)bzero((char *)random_schedule
, sizeof(random_schedule
));