diff options
author | wpaul <wpaul@FreeBSD.org> | 1996-02-23 16:08:59 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 1996-02-23 16:08:59 +0000 |
commit | fe4185f0276539508fb2aac6cf2396609f0114b3 (patch) | |
tree | 63fdeb3efaed446e57edb0c129cc0139d5c75d71 /usr.bin/passwd | |
parent | d2379a0d6ef39dc3696a7b6452546c5a93deb2d6 (diff) | |
download | FreeBSD-src-fe4185f0276539508fb2aac6cf2396609f0114b3.zip FreeBSD-src-fe4185f0276539508fb2aac6cf2396609f0114b3.tar.gz |
Merge in changes to support the new rpc.yppasswdd(8) and fix a few bugs.
In passwd(1):
- Gut most of yp_passwd.c and leave only a few things that aren't common
to pw_yp.c.
- Add support for -d and -h flags to select domains and NIS server hosts
to use when updating NIS passwords. This allows passwd(1) to be used
for changing NIS passwords from machines that aren't configured as
NIS clients. (This is mostly to allow passwd(1) to work on NIS master
servers that aren't configured as clients -- an NIS server need not
necessarily be configured as a client itself.)
NOTE: Realize that having the ability to specify a domain and hostname
lets you use passwd(1) (and chpass(1) too) to submit update requests
to yppasswd daemons running on remote servers in remote domains which
you may not even be bound to. For example, my machine at home is not
an NIS client of the servers on the network that I manage, yet I can
easily change my password at work using my FreeBSD box at home by doing:
'passwd -d work.net.domain -h any.nis.server.on.my.net wpaul'. (Yes,
I do use securenets at work; temporarily modified my securenets file
to give my home system access.) Some people may not be too thrilled
with this idea. Those who don't like this feature can recompile passwd(1)
and chpass(1) with -DPARANOID to restrict the use of these flags to
the superuser.
(Oh, I should be adding proper securenets support to ypserv(8) and
rpc.yppasswdd(8) over the weekend.)
- Merge in changes to allow root on the NIS master server to bypass
authentication and change any user's NIS password. (The super-user
on the NIS master already has privileges to do this, but doing it
through passwd(1) is much easier than updating the maps by hand.)
Note that passwd(1) communicates with rpc.yppasswdd(8) via a UNIX
domain socket instead of via standard RPC/IP in this case.
- Update man page.
In chpass(1):
- Fix pw_yp.c to work properly in environments where NIS client
services aren't available.
- Use realloc() instead of malloc() in copy_yp_pass() and copy_local_pass().
- Fix silly bug in copy_yp_pass(); some of the members of the passwd
structure weren't being filled in correctly. (This went unnoticed
for a while since the old yppasswdd didn't allow changes to the
fields that were being botched.)
- chpass(1) now also allows the superuser on the NIS master server to
make unrestricted changes to any user's NIS password information.
- Use UNIX domain comm channel to rpc.yppasswdd(8) when run by the
superuser on the NIS master. This allows several new things:
o superuser can update an entire master.passwd.{byname,byuid} entry
o superuser can update records in arbitrary domains using -d flag to
select a domain (before you could only change the default domain)
o superuser can _add_ records to the NIS master.passwd maps, provided
rpc.yppasswdd(8) has been started with the -a flag (to do this,
the superuser must force NIS operation by specifying the -y flag
to chpass(1) along with -a, i.e. 'chpass -y -a 'foo:::::::::')
- Back out the 'chpass -a <new password entry> breaks with NIS' fix
from the last revision and fix it properly this time. The previous
revision fixed the immediate problem but broke NIS operation in
some cases.
- In edit.c, be a little more reasonable about deciding when to
prevent the shell field from being changed.
Submitted by Charles Owens <owensc@enc.edu>, who said:
"I made a minor (one-line) modification to chpass, with regards
to whether or not it allows the changing of shells. In the 2.0.5 code,
field changing follows the settings specified in the "list" structure
defined in table.c . For the shell, though, this is ignored. A quick
look in edit.c showed me why, but I don't understand why it was written as
such. The logic was
if shell is standard shell, allow changing
I changed it to
if shell changing is allowed (per table.c) and it is a standard shell
OR if uid=0, then allow changing."
Makes sense to me.
- Update man page.
Diffstat (limited to 'usr.bin/passwd')
-rw-r--r-- | usr.bin/passwd/Makefile | 42 | ||||
-rw-r--r-- | usr.bin/passwd/passwd.1 | 55 | ||||
-rw-r--r-- | usr.bin/passwd/passwd.c | 49 | ||||
-rw-r--r-- | usr.bin/passwd/yp_passwd.c | 256 |
4 files changed, 251 insertions, 151 deletions
diff --git a/usr.bin/passwd/Makefile b/usr.bin/passwd/Makefile index b7866de..b5d7a3c 100644 --- a/usr.bin/passwd/Makefile +++ b/usr.bin/passwd/Makefile @@ -1,15 +1,47 @@ # From: @(#)Makefile 8.3 (Berkeley) 4/2/94 -# $Id: Makefile,v 1.17 1995/09/03 11:40:37 markm 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 pw_yp.c +SRCS= local_passwd.c yppasswd_private_xdr.c yppasswd_comm.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 \ - ${.CURDIR}/../rlogin + ${.CURDIR}/../rlogin ${.CURDIR}/../../libexec/ypxfr \ + ${.CURDIR}/../../usr.sbin/rpc.yppasswdd + +CFLAGS+= -DCRYPT -DYP -I. -I${.CURDIR} -I${.CURDIR}/../../usr.sbin/vipw \ + -I${.CURDIR}/../../usr.bin/chpass -I${.CURDIR}/../../libexec/ypxfr \ + -I${.CURDIR}/../../usr.sbin/rpc.yppasswdd -Dyp_error=warnx + +SRCS+= ypxfr_misc.c yp_clnt.c yppasswd_clnt.c + +CLEANFILES= yp.h yp_clnt.c yppasswd.h yppasswd_clnt.c \ + yppasswd_private.h yppasswd_private_xdr.c + +RPCGEN= rpcgen -C +RPCSRC= ${DESTDIR}/usr/include/rpcsvc/yp.x +RPCSRC_PW= ${DESTDIR}/usr/include/rpcsvc/yppasswd.x +RPCSRC_PRIV= ${.CURDIR}/../../usr.sbin/rpc.yppasswdd/yppasswd_private.x + +yp.h: ${RPCSRC} + ${RPCGEN} -h -o ${.TARGET} ${RPCSRC} + +yp_clnt.c: ${RPCSRC} yp.h + ${RPCGEN} -l -o ${.TARGET} ${RPCSRC} + +yppasswd.h: ${RPCSRC_PW} + ${RPCGEN} -h -o ${.TARGET} ${RPCSRC_PW} + +yppasswd_clnt.c: ${RPCSRC_PW} yppasswd.h + ${RPCGEN} -l -o ${.TARGET} ${RPCSRC_PW} + +yppasswd_private.h: ${RPCSRC_PRIV} + ${RPCGEN} -h -o ${.TARGET} ${RPCSRC_PRIV} -CFLAGS+=-DCRYPT -DYP -I${.CURDIR} -I${.CURDIR}/../../usr.sbin/vipw \ - -I${.CURDIR}/../../usr.bin/chpass +yppasswd_private_xdr.c: ${RPCSRC_PRIV} yppasswd_private.h + ${RPCGEN} -c -o ${.TARGET} ${RPCSRC_PRIV} BINOWN= root BINMODE=4555 diff --git a/usr.bin/passwd/passwd.1 b/usr.bin/passwd/passwd.1 index 47a337a..533cd5e 100644 --- a/usr.bin/passwd/passwd.1 +++ b/usr.bin/passwd/passwd.1 @@ -87,6 +87,19 @@ user does not exist in either the local password database of the NIS password maps, .Nm passwd returns an error. +.Pp +When changing an NIS password, unprivileged users are required to provide +their old password for authentication (the +.Xr rpc.yppasswdd 8 +daemon requires the original password before +it will allow any changes to the NIS password maps). +This restriction applies even to the +super-user, with one important exception: the password authentication is +bypassed for the super-user on the NIS master server. This means that +the super-user on the NIS master server can make unrestricted changes to +anyone's NIS password. The super-user on NIS client systems and NIS slave +servers still needs to provide a password before the update will be processed. +.Pp The following additional options are supported for use with NIS: .Bl -tag -width flag .It Fl y @@ -114,17 +127,39 @@ default, will try to change the NIS password. The .Fl l flag can be used to change the local password instead. -.El +.It Fl d Ar domain +Specify what domain to use when changing an NIS password. By default, +.Nm passwd +assumes that the system default domain should be used. This flag is +primarily for use by the superuser on the NIS master server: a single +NIS server can support multiple domains. It is also possible that the +domainname on the NIS master may not be set (it is not necessary for +an NIS server to also be a client) in which case the +.Nm passwd +command needs to be told what domain to operate on. +.It Fl s Ar host +Specify the name of an NIS server. This option, in conjunction +with the +.Fl d +option, can be used to change an NIS password on a non-local NIS +server. When a domain is specified with the +.Fl d +option and +.Nm passwd +is unable to determine the name of the NIS master server (possibly because +the local domainname isn't set), the name of the NIS master is assumed to +be ``localhost''. This can be overriden with the +.Fl s +flag. The specified hostname need not be the name of an NIS master: the +name of the NIS master for a given map can be determined by querying any +NIS server (master or slave) in a domain, so specifying the name of a +slave server will work equally well. .Pp -When changing an NIS password, the user is required to provide -the old password for authentication (the -.Xr yppasswdd 8 -daemon requires the original password before -it will allow any changes to the NIS password maps). -This restriction applies even to the -super-user: the only way for an administrator to override a -user's NIS password is by modifying the NIS password maps on -the master NIS server. +.It Fl o +Do not automatically override the password authentication checks for the +super-user on the NIS master server; assume 'old' mode instead. This +flag is of limited practical use but is useful for testing. +.El .Sh FILES .Bl -tag -width /etc/master.passwd -compact .It Pa /etc/master.passwd diff --git a/usr.bin/passwd/passwd.c b/usr.bin/passwd/passwd.c index 92dd895..a7e2623 100644 --- a/usr.bin/passwd/passwd.c +++ b/usr.bin/passwd/passwd.c @@ -43,7 +43,7 @@ static const char copyright[] = #ifndef lint static const char sccsid[] = "From: @(#)passwd.c 8.3 (Berkeley) 4/2/94"; static const char rcsid[] = - "$Id$"; + "$Id: passwd.c,v 1.7 1995/12/16 09:45:15 markm Exp $"; #endif /* not lint */ #include <err.h> @@ -56,9 +56,10 @@ static const char rcsid[] = #ifdef YP #include <pwd.h> #include <pw_yp.h> -char *prog_name; +#include <rpcsvc/yp.h> int __use_yp = 0; -int yp_passwd(char *user); +int yp_errno = YP_TRUE; +extern int yp_passwd __P(( char * )); #endif #ifdef KERBEROS @@ -83,9 +84,9 @@ main(argc, argv) #ifdef YP #ifdef KERBEROS char realm[REALM_SZ]; -#define OPTIONS "lysfi:r:u:" +#define OPTIONS "d:h:lysfoi:r:u:" #else -#define OPTIONS "lysf" +#define OPTIONS "d:h:lysfo" #endif #else #ifdef KERBEROS @@ -99,7 +100,7 @@ main(argc, argv) #ifdef YP int res = 0; - if (strstr(argv[0], (prog_name = "yppasswd"))) __use_yp = 1; + if (strstr(argv[0], "yppasswd")) __use_yp = 1; #endif while ((ch = getopt(argc, argv, OPTIONS)) != EOF) { @@ -122,6 +123,33 @@ main(argc, argv) case 'y': /* Change NIS password */ __use_yp = 1; break; + case 'd': /* Specify NIS domain. */ +#ifdef PARANOID + if (!getuid()) { +#endif + yp_domain = optarg; + if (yp_server == NULL) + yp_server = "localhost"; +#ifdef PARANOID + } else { + warnx("Only the super-user may use the -d flag."); + } +#endif + break; + case 'h': /* Specify NIS server. */ +#ifdef PARANOID + if (!getuid()) { +#endif + yp_server = optarg; +#ifdef PARANOID + } else { + warnx("Only the super-user may use the -h flag."); + } +#endif + break; + case 'o': + force_old++; + break; #endif default: case '?': @@ -152,8 +180,8 @@ main(argc, argv) #ifdef KERBEROS if (__use_yp || (iflag == NULL && rflag == NULL && uflag == NULL)) { #endif - res = use_yp(uname); - if (res == USER_YP_ONLY) { + res = use_yp(uname, 0, 0); + if (res == USER_YP_ONLY || __use_yp) { if (!use_local_passwd) { exit(yp_passwd(uname)); } else { @@ -198,9 +226,10 @@ usage() fprintf(stderr, "usage: passwd [-l] [-i instance] [-r realm] [-u fullname]\n"); fprintf(stderr, - " [-l] [-y] [user]\n"); + " [-l] [-y] [-o] [-d domain [-h host]] [user]\n"); #else - (void)fprintf(stderr, "usage: passwd [-l] [-y] [user] \n"); + (void)fprintf(stderr, "usage: passwd [-l] [-y] [-o] [-d domain \ +[-h host]] [user] \n"); #endif #else #ifdef KERBEROS diff --git a/usr.bin/passwd/yp_passwd.c b/usr.bin/passwd/yp_passwd.c index fc6b0e4..b83e9f1 100644 --- a/usr.bin/passwd/yp_passwd.c +++ b/usr.bin/passwd/yp_passwd.c @@ -45,137 +45,141 @@ #include <rpcsvc/ypclnt.h> #include <rpcsvc/yppasswd.h> #include <pw_yp.h> - -extern char *prog_name; -uid_t uid; +#include "yppasswd_comm.h" extern char *getnewpasswd __P(( struct passwd * , int )); -char * -getserver( void ) -{ - char *domainname, *master; - int port, err; - int getrpcport(); - - if ((err = yp_get_default_domain(&domainname)) != 0) { - fprintf(stderr, "%s: can't get local yp domain: %s\n", - prog_name, yperr_string(err)); - return NULL; - } - - if ((err = yp_master(domainname, "passwd.byname", &master)) != 0) { - fprintf(stderr, "%s: can't find the master ypserver: %s\n", - prog_name, yperr_string(err)); - return NULL; - } - port = getrpcport(master, YPPASSWDPROG, YPPASSWDPROC_UPDATE, IPPROTO_UDP); - if (port==0) { - fprintf (stderr, "%s: yppasswdd not running on NIS master host\n", - prog_name); - return NULL; - } - if (port >= IPPORT_RESERVED) { - fprintf (stderr, "%s: yppasswd daemon running on illegal port.\n", - prog_name); - return NULL; - } - return master; -} - int yp_passwd(char *user) { - struct timeval timeout; - struct yppasswd yppasswd; - struct passwd *pw; - CLIENT *clnt; - char *master; - int err, status; - char *s; - - if ((master = getserver()) == NULL) { - exit(1); - } - - /* Obtain the passwd struct for the user whose password is to be changed. - */ - uid = getuid(); - if (user == NULL) { - if ((pw = getpwuid(uid)) == NULL) { - fprintf ( stderr, "%s: unknown user (uid=%d).\n", - prog_name, (int)uid ); - exit(1); - } - } else { - if ((pw = getpwnam(user)) == NULL) { - fprintf ( stderr, "%s: unknown user: %s.\n", prog_name, user ); - exit(1); - } - if (pw->pw_uid != uid && uid != 0) { - fprintf ( stderr, "%s: Only root may change account information " - "for others\n", prog_name ); - exit(1); - } - } - - /* 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; - yppasswd.newpw.pw_uid = pw->pw_uid; - yppasswd.newpw.pw_gid = pw->pw_gid; - yppasswd.newpw.pw_gecos = pw->pw_gecos; - yppasswd.newpw.pw_dir = pw->pw_dir; - yppasswd.newpw.pw_shell = pw->pw_shell; - yppasswd.oldpass = NULL; - - printf("Changing NIS password for %s on %s.\n", pw->pw_name, master); - - /* Get old password */ - if(pw->pw_passwd[0]) { - - s = getpass ("Old password: "); - if( strcmp(crypt(s, pw->pw_passwd), pw->pw_passwd)) { - fprintf(stderr, "Sorry.\n"); - exit (1); - } - yppasswd.oldpass = strdup(s); - } else - yppasswd.oldpass = ""; - - if ((s = getnewpasswd(pw, 1)) == NULL) - exit (1); - yppasswd.newpw.pw_passwd = s; - - /* The yppasswd.x file said `unix authentication required', - * so I added it. This is the only reason it is in here. - * My yppasswdd doesn't use it, but maybe some others out there - * do. --okir - */ - clnt = clnt_create( master, YPPASSWDPROG, YPPASSWDVERS, "udp" ); - clnt->cl_auth = authunix_create_default(); - bzero( (char*)&status, sizeof(status) ); - timeout.tv_sec = 25; timeout.tv_usec = 0; - err = clnt_call( clnt, YPPASSWDPROC_UPDATE, - xdr_yppasswd, (char*)&yppasswd, - xdr_int, (char*)&status, - &timeout ); - - if (err) { - clnt_perrno(err); - fprintf( stderr, "\n" ); - } else if (status) { - fprintf( stderr, "Error while changing NIS password.\n"); - } - - printf("\nNIS password has%s been changed on %s.\n", - (err || status)? " not" : "", master); - - auth_destroy( clnt->cl_auth ); - clnt_destroy( clnt ); - exit ((err || status) != 0); + struct timeval timeout; + struct yppasswd yppasswd; + struct master_yppasswd master_yppasswd; + struct passwd *pw; + CLIENT *clnt; + struct rpc_err err; + char *master; + int *status = NULL; + uid_t uid; + + _use_yp = 1; + + uid = getuid(); + + if ((master = get_yp_master(1)) == NULL) { + warnx("failed to find NIS master server"); + return(1); + } + + /* + * It is presumed that by the time we get here, use_yp() + * has been called and that we have verified that the user + * actually exists. This being the case, the yp_password + * stucture has already been filled in for us. + */ + + /* Use the correct password */ + pw = (struct passwd *)&yp_password; + + if (pw->pw_uid != uid && uid != 0) { + warnx("Only the super-user may change account information \ +for other users"); + return(1); + } + + /* Initialize password information */ + if (suser_override) { + master_yppasswd.newpw.pw_passwd = strdup(pw->pw_passwd); + master_yppasswd.newpw.pw_name = strdup(pw->pw_name); + master_yppasswd.newpw.pw_uid = pw->pw_uid; + master_yppasswd.newpw.pw_gid = pw->pw_gid; + master_yppasswd.newpw.pw_expire = pw->pw_expire; + master_yppasswd.newpw.pw_change = pw->pw_change; + master_yppasswd.newpw.pw_fields = pw->pw_fields; + master_yppasswd.newpw.pw_gecos = strdup(pw->pw_gecos); + master_yppasswd.newpw.pw_dir = strdup(pw->pw_dir); + master_yppasswd.newpw.pw_shell = strdup(pw->pw_shell); + master_yppasswd.newpw.pw_class = strdup(pw->pw_class); + master_yppasswd.oldpass = ""; + master_yppasswd.domain = yp_domain; + } else { + yppasswd.newpw.pw_passwd = strdup(pw->pw_passwd); + yppasswd.newpw.pw_name = strdup(pw->pw_name); + yppasswd.newpw.pw_uid = pw->pw_uid; + yppasswd.newpw.pw_gid = pw->pw_gid; + yppasswd.newpw.pw_gecos = strdup(pw->pw_gecos); + yppasswd.newpw.pw_dir = strdup(pw->pw_dir); + yppasswd.newpw.pw_shell = strdup(pw->pw_shell); + yppasswd.oldpass = ""; + } + + if (suser_override) + printf("Changing NIS password for %s on %s in domain %s.\n", + pw->pw_name, master, yp_domain); + else + printf("Changing NIS password for %s on %s.\n", + pw->pw_name, master); + + /* Get old password */ + + if(pw->pw_passwd[0] && !suser_override) { + yppasswd.oldpass = strdup(getpass("Old Password: ")); + if (strcmp(crypt(yppasswd.oldpass, pw->pw_passwd), + pw->pw_passwd)) { + errx(1, "Sorry."); + } + + } + + if (suser_override) { + if ((master_yppasswd.newpw.pw_passwd = getnewpasswd(pw, 1)) == NULL) + return(1); + } else { + if ((yppasswd.newpw.pw_passwd = getnewpasswd(pw, 1)) == NULL) + return(1); + } + + if (suser_override) { + if (senddat(&master_yppasswd)) { + warnx("failed to send request to rpc.yppasswdd"); + return(1); + } + status = getresp(); + } else { + if ((clnt = clnt_create(master, YPPASSWDPROG, + YPPASSWDVERS, "udp")) == NULL) { + warnx("failed to contact rpc.yppasswdd on host %s: %s", + master, clnt_spcreateerror("")); + return(1); + } + /* + * The yppasswd.x file said `unix authentication required', + * so I added it. This is the only reason it is in here. + * My yppasswdd doesn't use it, but maybe some others out there + * do. --okir + */ + clnt->cl_auth = authunix_create_default(); + + status = yppasswdproc_update_1(&yppasswd, clnt); + clnt_geterr(clnt, &err); + + auth_destroy(clnt->cl_auth); + clnt_destroy(clnt); + } + + if ((!suser_override && err.re_status != RPC_SUCCESS) || + status == NULL || *status) { + errx(1, "Failed to change NIS password: %s", + (err.re_status != RPC_SUCCESS && !suser_override) ? + clnt_sperrno(err.re_status) : + "rpc.yppasswdd returned error status"); + } + + printf("\nNIS password has%s been changed on %s.\n", + ((err.re_status != RPC_SUCCESS && !suser_override) + || status == NULL || *status) ? + " not" : "", master); + + return ((err.re_status || status == NULL || *status)); } #endif /* YP */ |