-# $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 <bsd.own.mk>
.include <bsd.own.mk> # 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
-/* $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.
#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
#include <netdb.h>
#include <signal.h>
#include <pwd.h>
+#include <err.h>
#include <errno.h>
#include <stdio.h>
#include "kpasswd_proto.h"
#include <string.h>
#include <stdlib.h>
+#include <unistd.h>
#define PROTO "tcp"
(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);
}
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);
}
);
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);
}
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);
}
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);
}
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);
}
/* don't complain loud if user just hit return */
if (pass == NULL || (!*pass))
return(0);
- (void)fprintf(stderr, "Sorry\n");
+ warnx("Sorry");
return(1);
}
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);
}
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);
}
(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);
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);
}
-/* $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.
#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 <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
+#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <ctype.h>
#include <fcntl.h>
#include <util.h>
-uid_t uid;
+static uid_t uid;
-char *progname = "passwd";
-char *tempname;
+int
local_passwd(uname)
char *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);
}
-/* $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.
#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 <stdio.h>
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;
register int ch;
char *username;
int status = 0;
- char *basename;
#if defined(KERBEROS) || defined(KERBEROS5)
extern char realm[];
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 */
exit(local_passwd(username));
}
-usage()
+void
+usage(void)
{
fprintf(stderr, "usage: passwd [-l] [-k] [-y] user\n");
}
#include <sys/syslimits.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <pwd.h>
#include <util.h>
+#include <time.h>
void to64( char *, long, int n);
-/* $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.
*/
#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 <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <netdb.h>
#include <time.h>
#include <pwd.h>
+#include <err.h>
#include <errno.h>
+#include <ctype.h>
#include <rpc/rpc.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#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;
/*
* 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);
}
* 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);
}
*/
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);
}
* 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);
}
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);
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);
interpret(struct passwd *pwent, char *line)
{
register char *p = line;
- register int c;
pwent->pw_passwd = "*";
pwent->pw_uid = 0;