From f811b41cc996c70cfc5a1f29938e18cfacec1814 Mon Sep 17 00:00:00 2001 From: Bill Paul Date: Sun, 13 Aug 1995 16:12:28 +0000 Subject: Take the ypchfn/ypchsh stuff that was removed from passwd and graft it into chpass. Chpass can now tell when it's being asked to operate on an NIS user and it displayes the appropriate message in the editor template ("Changing NIS information for foo"). After the changes have been made, chpass will promte the user for his NIS password. If the password is correct, the changes are committed to yppasswdd. Hopefully, this should make NIS more transparent to the end user. Note that even the superuser needs to know a user's password before he can change any NIS information (such is the nature of yppasswdd). Also, changes to the password field are not permitted -- that's what yppasswd is for. (The superuser may specify a new password, but again, he needs to know the user's original password before he can change it.) --- chpass/chpass.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'chpass/chpass.c') diff --git a/chpass/chpass.c b/chpass/chpass.c index 086413d..bba8b3d 100644 --- a/chpass/chpass.c +++ b/chpass/chpass.c @@ -40,7 +40,7 @@ static char copyright[] = #ifndef lint static char sccsid[] = "From: @(#)chpass.c 8.4 (Berkeley) 4/2/94"; static char rcsid[] = - "$Id: chpass.c,v 1.2 1995/01/14 23:14:25 wollman Exp $"; + "$Id: chpass.c,v 1.3 1995/05/30 06:29:36 rgrimes Exp $"; #endif /* not lint */ #include @@ -62,6 +62,9 @@ static char rcsid[] = #include #include #include "pw_copy.h" +#ifdef YP +#include "pw_yp.h" +#endif #include "chpass.h" #include "pathnames.h" @@ -122,7 +125,6 @@ main(argc, argv) default: usage(); } - if (op == NEWSH) { /* protect p_shell -- it thinks NULL is /bin/sh */ if (!arg[0]) @@ -149,6 +151,23 @@ main(argc, argv) pw->pw_passwd = arg; } +#ifdef YP + /* + * XXX The man page says the data returned by getpwent() + * and friends is stored in static buffers that may be + * overwritten after successive invokations. Unfortunately, + * we need to call getpwent() more than once with NIS + * enabled. + */ + pw->pw_name = strdup(pw->pw_name); + pw->pw_passwd = strdup(pw->pw_passwd); + pw->pw_class = strdup(pw->pw_class); + pw->pw_gecos = strdup(pw->pw_gecos); + pw->pw_shell = strdup(pw->pw_shell); + pw->pw_dir = strdup(pw->pw_dir); + _use_yp = use_yp(pw->pw_name); +#endif /* YP */ + /* * The temporary file/file descriptor usage is a little tricky here. * 1: We start off with two fd's, one for the master password @@ -185,10 +204,19 @@ main(argc, argv) tfd = pw_tmp(); } +#ifdef YP + if (_use_yp) { + yp_submit(pw); + (void)unlink(tempname); + } else { +#endif /* YP */ pw_copy(pfd, tfd, pw); if (!pw_mkdb()) pw_error((char *)NULL, 0, 1); +#ifdef YP + } +#endif /* YP */ exit(0); } -- cgit v1.2.3