Sync with 4.4BSD-Lite2 (whew!)

This commit is contained in:
tls 1996-12-28 04:30:02 +00:00
parent c978f3a5c0
commit 28316c21d3
8 changed files with 171 additions and 150 deletions

View File

@ -1,5 +1,6 @@
# $NetBSD: Makefile,v 1.13 1996/08/09 09:19:33 thorpej Exp $
# from: @(#)Makefile 5.11 (Berkeley) 2/19/91
# $NetBSD: Makefile,v 1.14 1996/12/28 04:30:02 tls Exp $
# from: @(#)Makefile 8.3 (Berkeley) 4/2/94
PROG= passwd
SRCS= local_passwd.c yp_passwd.c passwd.c getpwent.c
@ -25,6 +26,9 @@ MLINKS= passwd.1 yppasswd.1
BINOWN= root
BINMODE=4555
.if defined(notyet)
INSTALLFLAGS=-fschg
.endif
.include <bsd.prog.mk>

View File

@ -1,3 +1,6 @@
/* $NetBSD: extern.h,v 1.2 1996/12/28 04:30:03 tls Exp $
*/
/*
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
@ -35,3 +38,5 @@
int krb_passwd __P((void));
int local_passwd __P((char *));
int yp_passwd __P((char *));

View File

@ -1,8 +1,8 @@
/* $NetBSD: kpasswd_proto.h,v 1.2 1996/08/09 09:19:34 thorpej Exp $ */
/* $NetBSD: kpasswd_proto.h,v 1.3 1996/12/28 04:30:04 tls Exp $ */
/*-
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,7 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)kpasswd_proto.h 5.1 (Berkeley) 2/3/91
* from: @(#)kpasswd_proto.h 8.1 (Berkeley) 6/6/93
*/
/*

View File

@ -1,8 +1,8 @@
/* $NetBSD: krb_passwd.c,v 1.2 1996/08/09 09:19:36 thorpej Exp $ */
/* $NetBSD: krb_passwd.c,v 1.3 1996/12/28 04:30:05 tls Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -35,9 +35,9 @@
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)krb_passwd.c 5.4 (Berkeley) 3/1/91";
static char sccsid[] = "from: @(#)krb_passwd.c 8.3 (Berkeley) 4/2/94";
#else
static char rcsid[] = "$NetBSD: krb_passwd.c,v 1.2 1996/08/09 09:19:36 thorpej Exp $";
static char rcsid[] = "$NetBSD: krb_passwd.c,v 1.3 1996/12/28 04:30:05 tls Exp $";
#endif
#endif /* not lint */
@ -61,6 +61,11 @@ static char rcsid[] = "$NetBSD: krb_passwd.c,v 1.2 1996/08/09 09:19:36 thorpej E
#define PROTO "tcp"
static void send_update __P((int, char *, char *));
static void recv_ack __P((int));
static void cleanup __P((void));
static void finish __P((void));
static struct timeval timeout = { CLIENT_KRB_TIMEOUT, 0 };
static struct kpasswd_data proto_data;
static des_cblock okey;
@ -71,6 +76,7 @@ long authopts;
char realm[REALM_SZ], krbhst[MAX_HSTNM];
int sock;
int
krb_passwd()
{
struct servent *se;
@ -89,52 +95,47 @@ 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",
warnx("couldn't find entry for service %s/%s",
SERVICE, PROTO);
return(1);
return (1);
}
if ((rval = krb_get_lrealm(realm,1)) != KSUCCESS) {
(void)fprintf(stderr,
"passwd: couldn't get local Kerberos realm: %s\n",
warnx("couldn't get local Kerberos realm: %s",
krb_err_txt[rval]);
return(1);
return (1);
}
if ((rval = krb_get_krbhst(krbhst, realm, 1)) != KSUCCESS) {
(void)fprintf(stderr,
"passwd: couldn't get Kerberos host: %s\n",
warnx("couldn't get Kerberos host: %s",
krb_err_txt[rval]);
return(1);
return (1);
}
if ((host = gethostbyname(krbhst)) == NULL) {
(void)fprintf(stderr,
"passwd: couldn't get host entry for krb host %s\n",
warnx("couldn't get host entry for krb host %s",
krbhst);
return(1);
return (1);
}
sin.sin_family = host->h_addrtype;
bcopy(host->h_addr, (char *) &sin.sin_addr, host->h_length);
memmove((char *) &sin.sin_addr, host->h_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));
return(1);
warn("socket");
return (1);
}
if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
(void)fprintf(stderr, "passwd: connect: %s\n", strerror(errno));
(void)close(sock);
return(1);
warn("connect");
(void)close(sock);
return (1);
}
rval = krb_sendauth(
@ -154,9 +155,8 @@ krb_passwd()
);
if (rval != KSUCCESS) {
(void)fprintf(stderr, "passwd: Kerberos sendauth error: %s\n",
krb_err_txt[rval]);
return(1);
warnx("Kerberos sendauth error: %s", krb_err_txt[rval]);
return (1);
}
krb_get_cred("krbtgt", realm, realm, &cred);
@ -166,9 +166,8 @@ 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");
return(1);
warnx("error reading old Kerberos password");
return (1);
}
(void)des_string_to_key(pass, okey);
@ -185,23 +184,22 @@ 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);
return (1);
}
(void)fprintf(stderr, "passwd: select failed (aborted)\n");
warnx("passwd: select failed (aborted)");
cleanup();
return(1);
return (1);
}
/* read verification string */
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);
return (1);
}
(void)signal(SIGHUP, finish);
@ -211,36 +209,33 @@ krb_passwd()
cleanup();
/* don't complain loud if user just hit return */
if (pass == NULL || (!*pass))
return(0);
return (0);
(void)fprintf(stderr, "Sorry\n");
return(1);
return (1);
}
(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));
(void)memset(pass, 0, sizeof(pass));
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);
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);
return (1);
}
if (strcmp(password, pass) != 0) {
(void)fprintf(stderr,
"passwd: password mismatch (aborted)\n");
warnx("password mismatch (aborted)");
cleanup();
return(1);
return (1);
}
if (strlen(pass) == 0)
@ -257,20 +252,20 @@ 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);
}
recv_ack(sock);
cleanup();
exit(0);
return (0);
}
static void
send_update(dest, pwd, str)
int dest;
char *pwd, *str;
@ -280,14 +275,14 @@ 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");
bzero((char *)&ud, sizeof(ud));
warnx(couldn't write pw update (abort)");
memset((char *)&ud, 0, sizeof(ud));
cleanup();
exit(1);
}
}
static void
recv_ack(remote)
int remote;
{
@ -296,25 +291,26 @@ 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);
}
(void)printf("%s", buf);
}
static void
cleanup()
{
(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));
(void)memset((char *)&proto_data, 0, sizeof(proto_data));
(void)memset((char *)okey, 0, sizeof(okey));
(void)memset((char *)osched, 0, sizeof(osched));
(void)memset((char *)random_schedule, 0, sizeof(random_schedule));
}
static void
finish()
{
(void)close(sock);
exit(1);
}

View File

@ -1,8 +1,8 @@
/* $NetBSD: local_passwd.c,v 1.9 1996/08/09 09:19:39 thorpej Exp $ */
/* $NetBSD: local_passwd.c,v 1.10 1996/12/28 04:30:05 tls Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -35,9 +35,9 @@
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)local_passwd.c 5.5 (Berkeley) 5/6/91";
static char sccsid[] = "from: @(#)local_passwd.c 8.3 (Berkeley) 4/2/94";
#else
static char rcsid[] = "$NetBSD: local_passwd.c,v 1.9 1996/08/09 09:19:39 thorpej Exp $";
static char rcsid[] = "$NetBSD: local_passwd.c,v 1.10 1996/12/28 04:30:05 tls Exp $";
#endif
#endif /* not lint */
@ -51,56 +51,33 @@ static char rcsid[] = "$NetBSD: local_passwd.c,v 1.9 1996/08/09 09:19:39 thorpej
#include <fcntl.h>
#include <util.h>
uid_t uid;
#include "extern.h"
static uid_t uid;
char *tempname;
local_passwd(uname)
char *uname;
static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
void
to64(s, v, n)
char *s;
long v;
int n;
{
struct passwd *pw;
int pfd, tfd;
char *getnewpasswd();
if (!(pw = getpwnam(uname))) {
(void)fprintf(stderr, "passwd: unknown user %s.\n", uname);
return(1);
while (--n >= 0) {
*s++ = itoa64[v&0x3f];
v >>= 6;
}
uid = getuid();
if (uid && uid != pw->pw_uid) {
(void)fprintf(stderr, "passwd: %s\n", strerror(EACCES));
return(1);
}
pw_init();
tfd = pw_lock(0);
if (tfd < 0)
errx(1, "the passwd file is busy.");
pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
if (pfd < 0)
pw_error(_PATH_MASTERPASSWD, 1, 1);
/*
* Get the new password. Reset passwd change time to zero; when
* classes are implemented, go and get the "offset" value for this
* class and reset the timer.
*/
pw->pw_passwd = getnewpasswd(pw);
pw->pw_change = 0;
pw_copy(pfd, tfd, pw);
if (pw_mkdb() < 0)
pw_error((char *)NULL, 0, 1);
return(0);
}
char *
getnewpasswd(pw)
register struct passwd *pw;
struct passwd *pw;
{
register char *p, *t;
int tries;
char *p, *t;
char buf[_PASSWORD_LEN+1], salt[9], *crypt(), *getpass();
(void)printf("Changing local password for %s.\n", pw->pw_name);
@ -124,7 +101,10 @@ getnewpasswd(pw)
}
for (t = p; *t && islower(*t); ++t);
if (!*t && ++tries < 2) {
(void)printf("Please don't use an all-lower case password.\nUnusual capitalization, control characters or digits are suggested.\n");
(void)printf("Please don't use an all-lower case\
password.\nUnusual capitalization,
control characters or digits are\
suggested.\n");
continue;
}
(void)strcpy(buf, p);
@ -144,16 +124,43 @@ getnewpasswd(pw)
return(crypt(buf, salt));
}
static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
to64(s, v, n)
register char *s;
register long v;
register int n;
int
local_passwd(uname)
char *uname;
{
while (--n >= 0) {
*s++ = itoa64[v&0x3f];
v >>= 6;
struct passwd *pw;
int pfd, tfd;
char *getnewpasswd();
if (!(pw = getpwnam(uname))) {
warnx("unknown user %s", uname);
return (1);
}
uid = getuid();
if (uid && uid != pw->pw_uid) {
warnx("%s", strerror(EACCES));
return (1);
}
pw_init();
tfd = pw_lock(0);
if (tfd < 0)
errx(1, "the passwd file is busy.");
pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
if (pfd < 0)
pw_error(_PATH_MASTERPASSWD, 1, 1);
/*
* Get the new password. Reset passwd change time to zero; when
* classes are implemented, go and get the "offset" value for this
* class and reset the timer.
*/
pw->pw_passwd = getnewpasswd(pw);
pw->pw_change = 0;
pw_copy(pfd, tfd, pw);
if (pw_mkdb() < 0)
pw_error((char *)NULL, 0, 1);
return (0);
}

View File

@ -1,7 +1,7 @@
.\" $NetBSD: passwd.1,v 1.6 1996/08/09 09:19:40 thorpej Exp $
.\" $NetBSD: passwd.1,v 1.7 1996/12/28 04:30:06 tls Exp $
.\"
.\" Copyright (c) 1990 The Regents of the University of California.
.\" All rights reserved.
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@ -31,9 +31,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)passwd.1 6.11 (Berkeley) 7/24/91
.\" from: @(#)passwd.1 8.1 (Berkeley) 6/6/93
.\"
.Dd July 24, 1991
.Dd June 6, 1993
.Dt PASSWD 1
.Os BSD 4
.Sh NAME

View File

@ -1,8 +1,8 @@
/* $NetBSD: passwd.c,v 1.9 1996/11/26 23:35:38 thorpej Exp $ */
/* $NetBSD: passwd.c,v 1.10 1996/12/28 04:30:07 tls Exp $ */
/*
* Copyright (c) 1988 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1988, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -34,16 +34,16 @@
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1988 The Regents of the University of California.\n\
All rights reserved.\n";
static char copyright[] =
"@(#) Copyright (c) 1988, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)passwd.c 5.5 (Berkeley) 7/6/91";
static char sccsid[] = "from: @(#)passwd.c 8.3 (Berkeley) 4/2/94";
#else
static char rcsid[] = "$NetBSD: passwd.c,v 1.9 1996/11/26 23:35:38 thorpej Exp $";
static char rcsid[] = "$NetBSD: passwd.c,v 1.10 1996/12/28 04:30:07 tls Exp $";
#endif
#endif /* not lint */
@ -52,6 +52,10 @@ static char rcsid[] = "$NetBSD: passwd.c,v 1.9 1996/11/26 23:35:38 thorpej Exp $
#include <string.h>
#include <unistd.h>
#include "extern.h"
void usage __P((void));
/*
* Note on configuration:
* Generally one would not use both Kerberos and YP
@ -75,7 +79,7 @@ main(argc, argv)
char **argv;
{
extern int optind;
register int ch;
int ch;
char *username;
#if defined(KERBEROS) || defined(KERBEROS5)
@ -145,9 +149,10 @@ main(argc, argv)
#if defined(KERBEROS) || defined(KERBEROS5)
if (use_kerberos && strcmp(argv[0], username)) {
errx(1, "%s\n\t%s\n%s\n",
"to change another user's Kerberos password, do",
"\"kinit <user>; passwd; kdestroy\";",
"to change a user's local passwd, use \"passwd -l <user>\"");
"to change another user's Kerberos password, do",
"\"kinit <user>; passwd; kdestroy\";",
"to change a user's local passwd, use\
\"passwd -l <user>\"");
}
#endif
username = argv[0];
@ -168,6 +173,7 @@ main(argc, argv)
exit(local_passwd(username));
}
void
usage()
{

View File

@ -1,8 +1,8 @@
/* $NetBSD: yp_passwd.c,v 1.10 1996/11/26 23:35:39 thorpej Exp $ */
/* $NetBSD: yp_passwd.c,v 1.11 1996/12/28 04:30:08 tls Exp $ */
/*
* Copyright (c) 1988 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1988, 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -35,9 +35,9 @@
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)yp_passwd.c 1.0 2/2/93";
static char sccsid[] = "from: @(#)local_passwd.c 8.3 (Berkeley) 4/2/94";
#else
static char rcsid[] = "$NetBSD: yp_passwd.c,v 1.10 1996/11/26 23:35:39 thorpej Exp $";
static char rcsid[] = "$NetBSD: yp_passwd.c,v 1.11 1996/12/28 04:30:08 tls Exp $";
#endif
#endif /* not lint */
@ -185,12 +185,12 @@ yp_passwd(username)
static char *
getnewpasswd(pw, old_pass)
register struct passwd *pw;
struct passwd *pw;
char **old_pass;
{
static char buf[_PASSWORD_LEN+1];
register char *p, *t;
int tries;
char *p, *t;
static char buf[_PASSWORD_LEN+1];
char salt[9], *crypt(), *getpass();
(void)printf("Changing YP password for %s.\n", pw->pw_name);
@ -222,7 +222,10 @@ getnewpasswd(pw, old_pass)
}
for (t = p; *t && islower(*t); ++t);
if (!*t && ++tries < 2) {
(void)printf("Please don't use an all-lower case password.\nUnusual capitalization, control characters or digits are suggested.\n");
(void)printf("Please don't use an all-lower case\
password.\nUnusual capitalization,
control characters or digits are\
suggested.\n");
continue;
}
(void)strcpy(buf, p);