From 98c2e2377bd644fc6a87dba031a846830a9d30ff Mon Sep 17 00:00:00 2001 From: weingart Date: Thu, 27 Mar 1997 00:30:52 +0000 Subject: [PATCH] Slight cleanup, more needed --- usr.bin/passwd/Makefile | 4 +-- usr.bin/passwd/krb_passwd.c | 64 +++++++++++++---------------------- usr.bin/passwd/local_passwd.c | 15 ++++---- usr.bin/passwd/passwd.c | 21 +++++++----- usr.bin/passwd/pwd_gensalt.c | 2 ++ usr.bin/passwd/yp_passwd.c | 56 ++++++++++++------------------ 6 files changed, 70 insertions(+), 92 deletions(-) diff --git a/usr.bin/passwd/Makefile b/usr.bin/passwd/Makefile index 5ee6cddcd11..848669c31d1 100644 --- a/usr.bin/passwd/Makefile +++ b/usr.bin/passwd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.13 1997/03/26 00:35:32 deraadt Exp $ +# $OpenBSD: Makefile,v 1.14 1997/03/27 00:30:52 weingart Exp $ .include @@ -16,7 +16,7 @@ CFLAGS+=-DYP -I${.CURDIR}/../../lib/libc/yp .include # For Kerberos .if defined(KERBEROS5) -#SRCS+= krb5_passwd.c XXX fix the /tmp/tkt_cpw_%d race first +#SRCS+= krb5_passwd.c XXX fix the /tmp/tkt_cpw_%d race first + others CFLAGS+= -DKERBEROS5 DPADD+= ${LIBKRB5} ${LIBCRYPTO} LDADD+= -lkrb5 -lcrypto diff --git a/usr.bin/passwd/krb_passwd.c b/usr.bin/passwd/krb_passwd.c index cd3e1811c3f..b0ec6a5c5d1 100644 --- a/usr.bin/passwd/krb_passwd.c +++ b/usr.bin/passwd/krb_passwd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: krb_passwd.c,v 1.4 1996/06/26 05:37:46 deraadt Exp $ */ +/* $OpenBSD: krb_passwd.c,v 1.5 1997/03/27 00:30:52 weingart Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -35,7 +35,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)krb_passwd.c 5.4 (Berkeley) 3/1/91";*/ -static char rcsid[] = "$OpenBSD: krb_passwd.c,v 1.4 1996/06/26 05:37:46 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: krb_passwd.c,v 1.5 1997/03/27 00:30:52 weingart Exp $"; #endif /* not lint */ #ifdef KERBEROS @@ -50,11 +50,13 @@ static char rcsid[] = "$OpenBSD: krb_passwd.c,v 1.4 1996/06/26 05:37:46 deraadt #include #include #include +#include #include #include #include "kpasswd_proto.h" #include #include +#include #define PROTO "tcp" @@ -86,36 +88,27 @@ krb_passwd() (void)signal(SIGTSTP, SIG_IGN); if (setrlimit(RLIMIT_CORE, &rl) < 0) { - (void)fprintf(stderr, - "passwd: setrlimit: %s\n", strerror(errno)); + warn("setrlimit"); return(1); } if ((se = getservbyname(SERVICE, PROTO)) == NULL) { - (void)fprintf(stderr, - "passwd: couldn't find entry for service %s/%s\n", - SERVICE, PROTO); + warnx("couldn't find entry for service %s/%s", SERVICE, PROTO); return(1); } if ((rval = krb_get_lrealm(realm,1)) != KSUCCESS) { - (void)fprintf(stderr, - "passwd: couldn't get local Kerberos realm: %s\n", - krb_err_txt[rval]); + warnx("couldn't get local Kerberos realm: %s", krb_err_txt[rval]); return(1); } if ((rval = krb_get_krbhst(krbhst, realm, 1)) != KSUCCESS) { - (void)fprintf(stderr, - "passwd: couldn't get Kerberos host: %s\n", - krb_err_txt[rval]); + warnx("couldn't get Kerberos host: %s", krb_err_txt[rval]); return(1); } if ((host = gethostbyname(krbhst)) == NULL) { - (void)fprintf(stderr, - "passwd: couldn't get host entry for krb host %s\n", - krbhst); + warnx("couldn't get host entry for krb host %s", krbhst); return(1); } @@ -124,12 +117,12 @@ krb_passwd() 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)); + warn("socket"); return(1); } if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) < 0) { - (void)fprintf(stderr, "passwd: connect: %s\n", strerror(errno)); + warn("connect"); (void)close(sock); return(1); } @@ -151,8 +144,7 @@ krb_passwd() ); if (rval != KSUCCESS) { - (void)fprintf(stderr, "passwd: Kerberos sendauth error: %s\n", - krb_err_txt[rval]); + warnx("Kerberos sendauth error: %s", krb_err_txt[rval]); return(1); } @@ -163,8 +155,7 @@ krb_passwd() if (des_read_pw_string(pass, sizeof(pass)-1, "Old Kerberos password:", 0)) { - (void)fprintf(stderr, - "passwd: error reading old Kerberos password\n"); + warnx("error reading old Kerberos password"); return(1); } @@ -182,11 +173,11 @@ krb_passwd() if ((rval < 1) || !FD_ISSET(sock, &readfds)) { if(rval == 0) { - (void)fprintf(stderr, "passwd: timed out (aborted)\n"); + warnx("timed out (aborted)"); cleanup(); return(1); } - (void)fprintf(stderr, "passwd: select failed (aborted)\n"); + warnx("select failed (aborted)"); cleanup(); return(1); } @@ -195,8 +186,7 @@ krb_passwd() if (des_read(sock, &proto_data, sizeof(proto_data)) != sizeof(proto_data)) { - (void)fprintf(stderr, - "passwd: couldn't read verification string (aborted)\n"); + warnx("couldn't read verification string (aborted)"); cleanup(); return(1); } @@ -209,7 +199,7 @@ krb_passwd() /* don't complain loud if user just hit return */ if (pass == NULL || (!*pass)) return(0); - (void)fprintf(stderr, "Sorry\n"); + warnx("Sorry"); return(1); } @@ -219,23 +209,20 @@ krb_passwd() if (des_read_pw_string(pass, sizeof(pass)-1, "New Kerberos password:", 0)) { - (void)fprintf(stderr, - "passwd: error reading new Kerberos password (aborted)\n"); + warnx("error reading new Kerberos password (aborted)"); cleanup(); return(1); } if (des_read_pw_string(password, sizeof(password)-1, "Retype new Kerberos password:", 0)) { - (void)fprintf(stderr, - "passwd: error reading new Kerberos password (aborted)\n"); + warnx("error reading new Kerberos password (aborted)"); cleanup(); return(1); } if (strcmp(password, pass) != 0) { - (void)fprintf(stderr, - "passwd: password mismatch (aborted)\n"); + warnx("password mismatch (aborted)"); cleanup(); return(1); } @@ -254,12 +241,11 @@ krb_passwd() select(sock + 1, &readfds, (fd_set *) 0, (fd_set *) 0, &timeout); if ((rval < 1) || !FD_ISSET(sock, &readfds)) { if(rval == 0) { - (void)fprintf(stderr, - "passwd: timed out reading ACK (aborted)\n"); + warnx("timed out reading ACK (aborted)"); cleanup(); exit(1); } - (void)fprintf(stderr, "passwd: select failed (aborted)\n"); + warnx("select failed (aborted)"); cleanup(); exit(1); } @@ -277,8 +263,7 @@ send_update(dest, pwd, str) (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)) { - (void)fprintf(stderr, - "passwd: couldn't write pw update (abort)\n"); + warnx("couldn't write pw update (abort)"); bzero((char *)&ud, sizeof(ud)); cleanup(); exit(1); @@ -293,8 +278,7 @@ recv_ack(remote) cc = des_read(remote, buf, sizeof(buf)); if (cc <= 0) { - (void)fprintf(stderr, - "passwd: error reading acknowledgement (aborted)\n"); + warnx("error reading acknowledgement (aborted)"); cleanup(); exit(1); } diff --git a/usr.bin/passwd/local_passwd.c b/usr.bin/passwd/local_passwd.c index f54dc12ab6d..b8b50660feb 100644 --- a/usr.bin/passwd/local_passwd.c +++ b/usr.bin/passwd/local_passwd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: local_passwd.c,v 1.6 1997/02/16 20:08:56 provos Exp $ */ +/* $OpenBSD: local_passwd.c,v 1.7 1997/03/27 00:30:53 weingart Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -35,24 +35,25 @@ #ifndef lint /*static char sccsid[] = "from: @(#)local_passwd.c 5.5 (Berkeley) 5/6/91";*/ -static char rcsid[] = "$OpenBSD: local_passwd.c,v 1.6 1997/02/16 20:08:56 provos Exp $"; +static char rcsid[] = "$OpenBSD: local_passwd.c,v 1.7 1997/03/27 00:30:53 weingart Exp $"; #endif /* not lint */ #include #include #include +#include #include #include #include #include +#include #include #include -uid_t uid; +static uid_t uid; -char *progname = "passwd"; -char *tempname; +int local_passwd(uname) char *uname; { @@ -65,13 +66,13 @@ local_passwd(uname) extern int use_yp; if (!use_yp) #endif - (void)fprintf(stderr, "passwd: unknown user %s.\n", uname); + warnx("unknown user %s.", uname); return(1); } uid = getuid(); if (uid && uid != pw->pw_uid) { - (void)fprintf(stderr, "passwd: %s\n", strerror(EACCES)); + warnx("login != uid: %s", strerror(EACCES)); return(1); } diff --git a/usr.bin/passwd/passwd.c b/usr.bin/passwd/passwd.c index a0b984ce6c2..83fa90c9f49 100644 --- a/usr.bin/passwd/passwd.c +++ b/usr.bin/passwd/passwd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: passwd.c,v 1.5 1997/01/15 23:43:01 millert Exp $ */ +/* $OpenBSD: passwd.c,v 1.6 1997/03/27 00:30:54 weingart Exp $ */ /* * Copyright (c) 1988 The Regents of the University of California. @@ -41,7 +41,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)passwd.c 5.5 (Berkeley) 7/6/91";*/ -static char rcsid[] = "$OpenBSD: passwd.c,v 1.5 1997/01/15 23:43:01 millert Exp $"; +static char rcsid[] = "$OpenBSD: passwd.c,v 1.6 1997/03/27 00:30:54 weingart Exp $"; #endif /* not lint */ #include @@ -65,6 +65,14 @@ int use_yp; int force_yp; #endif + +extern int local_passwd(char *); +extern int yp_passwd(char *); +extern int krb_passwd(void); +void usage(void); + + +int main(argc, argv) int argc; char **argv; @@ -73,7 +81,6 @@ main(argc, argv) register int ch; char *username; int status = 0; - char *basename; #if defined(KERBEROS) || defined(KERBEROS5) extern char realm[]; @@ -84,10 +91,7 @@ main(argc, argv) use_yp = _yp_check(NULL); #endif - basename = strrchr(argv[0], '/'); - if (basename == NULL) - basename = argv[0]; - + /* Process args and options */ while ((ch = getopt(argc, argv, "lky")) != -1) switch (ch) { case 'l': /* change local password file */ @@ -163,7 +167,8 @@ main(argc, argv) exit(local_passwd(username)); } -usage() +void +usage(void) { fprintf(stderr, "usage: passwd [-l] [-k] [-y] user\n"); } diff --git a/usr.bin/passwd/pwd_gensalt.c b/usr.bin/passwd/pwd_gensalt.c index 2c7ce64c2c0..a4729cbdc80 100644 --- a/usr.bin/passwd/pwd_gensalt.c +++ b/usr.bin/passwd/pwd_gensalt.c @@ -30,10 +30,12 @@ #include #include +#include #include #include #include #include +#include void to64( char *, long, int n); diff --git a/usr.bin/passwd/yp_passwd.c b/usr.bin/passwd/yp_passwd.c index f7bc86c030c..7d56018d9bf 100644 --- a/usr.bin/passwd/yp_passwd.c +++ b/usr.bin/passwd/yp_passwd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: yp_passwd.c,v 1.7 1997/02/17 10:34:41 provos Exp $ */ +/* $OpenBSD: yp_passwd.c,v 1.8 1997/03/27 00:30:55 weingart Exp $ */ /* * Copyright (c) 1988 The Regents of the University of California. @@ -34,17 +34,21 @@ */ #ifndef lint /*static char sccsid[] = "from: @(#)yp_passwd.c 1.0 2/2/93";*/ -static char rcsid[] = "$OpenBSD: yp_passwd.c,v 1.7 1997/02/17 10:34:41 provos Exp $"; +static char rcsid[] = "$OpenBSD: yp_passwd.c,v 1.8 1997/03/27 00:30:55 weingart Exp $"; #endif /* not lint */ #ifdef YP #include +#include #include +#include #include #include #include +#include #include +#include #include #include #include @@ -56,37 +60,29 @@ static char rcsid[] = "$OpenBSD: yp_passwd.c,v 1.7 1997/02/17 10:34:41 provos Ex #define _PASSWORD_LEN PASS_MAX #endif -extern char *progname; static char *getnewpasswd(); static struct passwd *ypgetpwnam(); static uid_t uid; char *domain; -static +static int pw_error(name, err, eval) char *name; int err, eval; { - int sverrno; + if(err) + warn(name != NULL ? name : ""); - if (err) { - sverrno = errno; - (void)fprintf(stderr, "%s: ", progname); - if (name) - (void)fprintf(stderr, "%s: ", name); - (void)fprintf(stderr, "%s\n", strerror(sverrno)); - } - (void)fprintf(stderr, - "%s: YP passwd database unchanged\n", progname); + warnx("YP passwd database unchanged."); exit(eval); } +int yp_passwd(username) char *username; { char *master; - char *pp; int r, rpcport, status; struct yppasswd yppasswd; struct passwd *pw; @@ -98,9 +94,8 @@ yp_passwd(username) /* * Get local domain */ - if (r = yp_get_default_domain(&domain)) { - fprintf(stderr, "%s: can't get local YP domain. Reason: %s\n", - progname, yperr_string(r)); + if ((r = yp_get_default_domain(&domain)) != 0) { + warnx("can't get local YP domain. Reason: %s", yperr_string(r)); exit(1); } @@ -109,9 +104,7 @@ yp_passwd(username) * the daemon. */ if ((r = yp_master(domain, "passwd.byname", &master)) != 0) { - fprintf(stderr, - "%s: can't find the master YP server. Reason: %s\n", - progname, yperr_string(r)); + warnx("can't find the master YP server. Reason: %s\n", yperr_string(r)); exit(1); } @@ -120,10 +113,8 @@ yp_passwd(username) */ if ((rpcport = getrpcport(master, YPPASSWDPROG, YPPASSWDPROC_UPDATE, IPPROTO_UDP)) == 0) { - fprintf(stderr, - "%s: master YP server not running yppasswd daemon.\n", - progname); - fprintf(stderr, "\tCan't change password.\n"); + warnx("master YP server not running yppasswd daemon."); + warnx("Can't change password."); exit(1); } @@ -131,22 +122,18 @@ yp_passwd(username) * Be sure the port is priviledged */ if (rpcport >= IPPORT_RESERVED) { - fprintf(stderr, "%s: yppasswd daemon is on an invalid port.\n", - progname); + warnx("yppasswd daemon is on an invalid port."); exit(1); } /* Get user's login identity */ if (!(pw = ypgetpwnam(username))) { - (void)fprintf(stderr, "%s: unknown user %s.\n", - progname, username); + warnx("unknown user %s.", username); exit(1); } if (uid && uid != pw->pw_uid) { - fprintf(stderr, - "%s: you may only change your own password: %s\n", - progname, strerror(EACCES)); + warnx("you may only change your own password: %s", strerror(EACCES)); exit(1); } @@ -163,7 +150,7 @@ yp_passwd(username) client = clnt_create(master, YPPASSWDPROG, YPPASSWDVERS, "udp"); if (client==NULL) { - fprintf(stderr, "cannot contact yppasswdd on %s: Reason: %s\n", + warnx("cannot contact yppasswdd on %s: Reason: %s\n", master, yperr_string(YPERR_YPBIND)); free(yppasswd.newpw.pw_passwd); return(YPERR_YPBIND); @@ -174,7 +161,7 @@ yp_passwd(username) r = clnt_call(client, YPPASSWDPROC_UPDATE, xdr_yppasswd, &yppasswd, xdr_int, &status, tv); if (r) - fprintf(stderr, "%s: rpc to yppasswdd failed.\n", progname); + warnx("rpc to yppasswdd failed."); else if (status) { printf("Couldn't change YP password.\n"); free(yppasswd.newpw.pw_passwd); @@ -255,7 +242,6 @@ struct passwd * interpret(struct passwd *pwent, char *line) { register char *p = line; - register int c; pwent->pw_passwd = "*"; pwent->pw_uid = 0; -- 2.20.1