diff options
author | Martin Blapp <mbr@FreeBSD.org> | 2003-06-15 21:24:45 +0000 |
---|---|---|
committer | Martin Blapp <mbr@FreeBSD.org> | 2003-06-15 21:24:45 +0000 |
commit | 5169db8c9633ad94ed42e07262e90ca40ad456e4 (patch) | |
tree | 67b68a008e504b77f76c01849ce78cf1061a3ea5 /usr.sbin | |
parent | 77b12dfe8f68cc4f29ecf3c89d6404d028390b5a (diff) | |
download | src-5169db8c9633ad94ed42e07262e90ca40ad456e4.tar.gz src-5169db8c9633ad94ed42e07262e90ca40ad456e4.zip |
Fix yppasswdproc_update_master_1_svc() too.
Only call pw_mkdb if passfile == _PATH_MASTERPASSWD.
Otherwise, rename master.passwd to a temp filename, rename
the new passwd to master.passwd, and let yppwupdate update
passwd as it sees fit.
Reviewed by: phk
Tested by: genesys
Notes
Notes:
svn path=/head/; revision=116421
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rpc.yppasswdd/yppasswdd_server.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/usr.sbin/rpc.yppasswdd/yppasswdd_server.c b/usr.sbin/rpc.yppasswdd/yppasswdd_server.c index 7932753688bb..04adf31ed85f 100644 --- a/usr.sbin/rpc.yppasswdd/yppasswdd_server.c +++ b/usr.sbin/rpc.yppasswdd/yppasswdd_server.c @@ -706,6 +706,7 @@ yppasswdproc_update_master_1_svc(master_yppasswd *argp, DBT key, data; char *passfile_hold; char passfile_buf[MAXPATHLEN + 2]; + char passfile_hold_buf[MAXPATHLEN + 2]; struct sockaddr_in *rqhost; SVCXPRT *transp; @@ -797,6 +798,14 @@ allow additions to be made to the password database"); passfile = (char *)&passfile_buf; } + /* + * Create a filename to hold the original master.passwd + * so if our call to yppwupdate fails we can roll back + */ + snprintf(passfile_hold_buf, sizeof(passfile_hold_buf), + "%s.hold", passfile); + passfile_hold = (char *)&passfile_hold_buf; + if (pw_init(dirname(passfile), passfile)) { yp_error("pw_init() failed"); return &result; @@ -816,10 +825,33 @@ allow additions to be made to the password database"); yp_error("pw_copy() failed"); return &result; } + if (rename(passfile, passfile_hold) == -1) { + pw_fini(); + yp_error("rename of %s to %s failed", passfile, + passfile_hold); + return &result; + } if (strcmp(passfile, _PATH_MASTERPASSWD) == 0) { + /* + * NIS server is exporting the system's master.passwd. + * Call pw_mkdb to rebuild passwd and the .db files + */ if (pw_mkdb(argp->newpw.pw_name) == -1) { pw_fini(); yp_error("pw_mkdb() failed"); + rename(passfile_hold, passfile); + return &result; + } + } else { + /* + * NIS server is exporting a private master.passwd. + * Rename tempfile into final location + */ + if (rename(pw_tempname(), passfile) == -1) { + pw_fini(); + yp_error("rename of %s to %s failed", + pw_tempname(), passfile); + rename(passfile_hold, passfile); return &result; } } |