* Copyright (c) 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)kpasswd.c 1.2 (Berkeley) %G%";
* kpasswd - client program to update Kerberos password
#include <sys/resource.h>
#include <kerberos/krb.h>
#include "kpasswd_proto.h"
Key_schedule random_schedule
;
char realm
[REALM_SZ
], krbhst
[MAX_HSTNM
];
static struct kpasswd_data proto_data
;
static Key_schedule osched
;
static struct timeval timeout
= { CLIENT_KRB_TIMEOUT
, 0 };
char password
[255], *pass
;
static struct rlimit rl
= { 0, 0 };
signal(SIGTSTP
, SIG_IGN
);
if(setrlimit(RLIMIT_CORE
, &rl
) < 0) {
if((se
= getservbyname(SERVICE
, PROTO
)) == NULL
) {
fprintf(stderr
, "couldn't find entry for service %s/%s\n",
if((rval
= krb_get_lrealm(realm
,1)) != KSUCCESS
) {
fprintf(stderr
, "couldn't get local Kerberos realm: %s\n",
if((rval
= krb_get_krbhst(krbhst
, realm
, 1)) != KSUCCESS
) {
fprintf(stderr
, "couldn't get Kerberos host: %s\n",
if((host
= gethostbyname(krbhst
)) == NULL
) {
fprintf(stderr
, "couldn't get host entry for 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) {
if(connect(sock
, (struct sockaddr
*) &sin
, sizeof(sin
)) < 0) {
authopts
, /* NOT mutual */
&ticket
, /* (filled in) */
krbhst
, /* instance (krbhst) */
(u_long
) getpid(), /* checksum */
fprintf(stderr
, "Kerberos sendauth error: %s\n",
pass
= getpass("Old Kerberos password:");
string_to_key(pass
, okey
);
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
)) {
fprintf(stderr
, "Timed out\n");
fprintf(stderr
, "select failed\n");
/* read verification string */
if(des_read(sock
, &proto_data
, sizeof(proto_data
)) != sizeof(proto_data
)) {
"%s: couldn't read verification string (aborted)\n",
if(strcmp(SECURE_STRING
, proto_data
.secure_msg
)) {
fprintf(stderr
, "Sorry.\n");
key_sched(proto_data
.random_key
, random_schedule
);
des_set_key(proto_data
.random_key
, random_schedule
);
pass
= getpass("New Kerberos password:");
pass
= getpass("Retype new Kerberos password:");
if(strcmp(password
, pass
)) {
fprintf(stderr
, "Password mismatch (aborted)\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
)) {
fprintf(stderr
, "Timed out reading ACK\n");
fprintf(stderr
, "select failed\n");
send_update(dest
, pwd
, str
)
static struct update_data ud
;
strncpy(ud
.secure_msg
, str
, MSGSIZE
);
strncpy(ud
.pw
, pwd
, sizeof(ud
.pw
));
if(des_write(dest
, &ud
, sizeof(ud
)) != sizeof(ud
)) {
fprintf(stderr
, "couldn't write pw update (abort)\n");
cc
= des_read(remote
, buf
, sizeof(buf
));
fprintf(stderr
, "error reading acknowledgement\n");
bzero(&proto_data
, sizeof(proto_data
));
bzero(okey
, sizeof(okey
));
bzero(osched
, sizeof(osched
));
bzero(random_schedule
, sizeof(random_schedule
));