diff options
| author | David Greenman <dg@FreeBSD.org> | 1995-10-06 01:58:47 +0000 |
|---|---|---|
| committer | David Greenman <dg@FreeBSD.org> | 1995-10-06 01:58:47 +0000 |
| commit | 31278d3589ecadba84a12ae2c2cc0d45284bc9e8 (patch) | |
| tree | c02f1c5f8e23447bf0c8c1dbc5dd49676d063541 /usr.bin | |
| parent | 2bd7b1181384009e3dc7f57afd84f81bdc4fc22b (diff) | |
Notes
Diffstat (limited to 'usr.bin')
| -rw-r--r-- | usr.bin/passwd/Makefile | 4 | ||||
| -rw-r--r-- | usr.bin/passwd/local_passwd.c | 7 | ||||
| -rw-r--r-- | usr.bin/passwd/passwd.c | 68 | ||||
| -rw-r--r-- | usr.bin/passwd/yp_passwd.c | 7 |
4 files changed, 36 insertions, 50 deletions
diff --git a/usr.bin/passwd/Makefile b/usr.bin/passwd/Makefile index 36b9e7feda016..511b2c432f552 100644 --- a/usr.bin/passwd/Makefile +++ b/usr.bin/passwd/Makefile @@ -1,8 +1,8 @@ # From: @(#)Makefile 8.3 (Berkeley) 4/2/94 -# $Id: Makefile,v 1.14.2.1 1995/08/26 09:53:02 davidg Exp $ +# $Id: Makefile,v 1.18 1995/09/14 21:02:16 gibbs Exp $ PROG= passwd -SRCS= local_passwd.c yp_passwd.c passwd.c pw_copy.c pw_util.c +SRCS= local_passwd.c yp_passwd.c passwd.c pw_copy.c pw_util.c pw_yp.c DPADD= ${LIBCRYPT} ${LIBRPCSVC} LDADD= -lcrypt -lrpcsvc .PATH: ${.CURDIR}/../../usr.bin/chpass ${.CURDIR}/../../usr.sbin/vipw \ diff --git a/usr.bin/passwd/local_passwd.c b/usr.bin/passwd/local_passwd.c index 44c8ffeb7a9b1..a8700ea35fefc 100644 --- a/usr.bin/passwd/local_passwd.c +++ b/usr.bin/passwd/local_passwd.c @@ -50,6 +50,9 @@ static char sccsid[] = "@(#)local_passwd.c 8.3 (Berkeley) 4/2/94"; #include <pw_copy.h> #include <pw_util.h> +#ifdef YP +#include <pw_yp.h> +#endif #include "extern.h" @@ -139,6 +142,10 @@ local_passwd(uname) if (!(pw = getpwnam(uname))) errx(1, "unknown user %s", uname); +#ifdef YP + /* Use the right password information. */ + pw = (struct passwd *)&local_password; +#endif uid = getuid(); if (uid && uid != pw->pw_uid) errx(1, "%s", strerror(EACCES)); diff --git a/usr.bin/passwd/passwd.c b/usr.bin/passwd/passwd.c index 6118ec6149ff2..ff1e1861a4591 100644 --- a/usr.bin/passwd/passwd.c +++ b/usr.bin/passwd/passwd.c @@ -40,7 +40,7 @@ static char copyright[] = #ifndef lint static char sccsid[] = "From: @(#)passwd.c 8.3 (Berkeley) 4/2/94"; static const char rcsid[] = - "$Id: passwd.c,v 1.5 1995/08/13 16:07:35 wpaul Exp $"; + "$Id: passwd.c,v 1.6 1995/09/02 04:02:27 wpaul Exp $"; #endif /* not lint */ #include <err.h> @@ -51,13 +51,9 @@ static const char rcsid[] = #ifdef YP #include <pwd.h> -#include <limits.h> -#include <db.h> -#include <fcntl.h> -#include <utmp.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/param.h> +#include <pw_yp.h> +char *prog_name; +int __use_yp = 0; #endif #ifdef KERBEROS @@ -70,20 +66,6 @@ void usage __P((void)); int use_local_passwd = 0; -#ifdef YP -#define PERM_SECURE (S_IRUSR|S_IWUSR) -int _use_yp = 0; -char *prog_name; -HASHINFO openinfo = { - 4096, /* bsize */ - 32, /* ffactor */ - 256, /* nelem */ - 2048 * 1024, /* cachesize */ - NULL, /* hash */ - 0, /* lorder */ -}; -#endif - int main(argc, argv) int argc; @@ -110,11 +92,9 @@ main(argc, argv) #endif #ifdef YP - DB *dbp; - DBT key,data; - char bf[UT_NAMESIZE + 2]; + int res = 0; - if (strstr(argv[0], (prog_name = "yppasswd"))) _use_yp = 1; + if (strstr(argv[0], (prog_name = "yppasswd"))) __use_yp = 1; #endif while ((ch = getopt(argc, argv, OPTIONS)) != EOF) { @@ -135,7 +115,7 @@ main(argc, argv) #endif /* KERBEROS */ #ifdef YP case 'y': /* Change NIS password */ - _use_yp = 1; + __use_yp = 1; break; #endif default: @@ -165,36 +145,28 @@ main(argc, argv) * If NIS is turned on in the password database, use it, else punt. */ #ifdef KERBEROS - if (iflag == NULL && rflag == NULL && uflag == NULL) { + if (__use_yp || (iflag == NULL && rflag == NULL && uflag == NULL)) { #endif - if ((dbp = dbopen(_PATH_MP_DB, O_RDONLY, PERM_SECURE, - DB_HASH, &openinfo)) == NULL) - errx(1, "error opening database: %s.", _PATH_MP_DB); - - bf[0] = _PW_KEYYPENABLED; - key.data = (u_char *)bf; - key.size = 1; - if ((dbp->get)(dbp,&key,&data,0)) - (dbp->close)(dbp); - else { + res = use_yp(uname); + if (res == USER_YP_ONLY) { if (!use_local_passwd) { - (dbp->close)(dbp); exit(yp_passwd(uname)); } else { /* * Reject -l flag if NIS is turned on and the user * doesn't exist in the local password database. */ - bf[0] = _PW_KEYBYNAME; - bcopy(uname, bf + 1, MIN(strlen(uname), UT_NAMESIZE)); - key.data = (u_char *)bf; - key.size = strlen(uname) + 1; - if ((dbp->get)(dbp,&key,&data,0)) { - (dbp->close)(dbp); - errx(1, "unknown local user: %s.", uname); - } - (dbp->close)(dbp); + errx(1, "unknown local user: %s.", uname); } + } else if (res == USER_LOCAL_ONLY) { + /* + * Reject -y flag if user only exists locally. + */ + if (__use_yp) + errx(1, "unknown NIS user: %s.", uname); + } else if (res == USER_YP_AND_LOCAL) { + if (!use_local_passwd) + exit(yp_passwd(uname)); } #ifdef KERBEROS } diff --git a/usr.bin/passwd/yp_passwd.c b/usr.bin/passwd/yp_passwd.c index f6e7d6f4bd751..a481f2dbaed5f 100644 --- a/usr.bin/passwd/yp_passwd.c +++ b/usr.bin/passwd/yp_passwd.c @@ -1,6 +1,7 @@ /* * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca> * Copyright (c) 1994 Olaf Kirch <okir@monad.swb.de> + * Copyright (c) 1995 Bill Paul <wpaul@ctr.columbia.edu> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,6 +29,7 @@ * SUCH DAMAGE. */ +#ifdef YP #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -42,6 +44,7 @@ #include <rpcsvc/yp_prot.h> #include <rpcsvc/ypclnt.h> #include <rpcsvc/yppasswd.h> +#include <pw_yp.h> extern char *prog_name; uid_t uid; @@ -116,6 +119,9 @@ yp_passwd(char *user) } } + /* Use the correct password */ + pw = (struct passwd *)&yp_password; + /* Initialize password information */ yppasswd.newpw.pw_passwd = pw->pw_passwd; yppasswd.newpw.pw_name = pw->pw_name; @@ -172,3 +178,4 @@ yp_passwd(char *user) clnt_destroy( clnt ); exit ((err || status) != 0); } +#endif /* YP */ |
