Bug 234972 - yppasswdd cannot update passwd (rename of /var/yp to /var/yp/master. passwd.hold failed)
Summary: yppasswdd cannot update passwd (rename of /var/yp to /var/yp/master. passwd.h...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Mark Johnston
Keywords: patch, regression
Depends on:
Reported: 2019-01-15 12:27 UTC by Bernard Marshall
Modified: 2019-06-06 03:05 UTC (History)
3 users (show)

See Also:

Fixes issue when rpc.yppasswdd fails to copy master.passwd (1.52 KB, patch)
2019-01-24 03:36 UTC, Edward Fuhr
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bernard Marshall 2019-01-15 12:27:27 UTC
After upgrading to 12.0 RELEASE the yppasswdd RPC no longer updates passwords successfully. When trying to update a password the following is output:

$ passwd fred
Changing NIS password for fred
New Password:
Retype New Password:
passwd: pam_chauthtok(): Error in service module

A check of /var/log/messages shows one of the following errors depending on whether the -t option was set for nis_yppasswdd_flags in /etc/rc.conf:

rename of / to /.hold failed
rename of /var to /var/yp.hold failed
rename of /var/yp to /var/yp/master.passwd.hold failed

The error is in /usr/src/usr.sbin/rpc.yppasswdd/yppasswdd_server.c where dirname() is used twice (line 609 and 832). Both lines have the code:

if (pw_init(dirname(passfile), passfile)) {

It looks like the implementation of dirname in 12.0 RELEASE has changed to now apply changes to the string passed into the function. The change is to make the call thread safe according to the updated manual entry. The problem here is that the call to dirname() now truncates "passfile" meaning the variable no longer holds the path to the master password file, rather just the directory and hence the error.

In order to use dirname() now "passfile" will need to be copied before being passed into dirname().
Comment 1 Edward Fuhr 2019-01-24 03:36:19 UTC
Created attachment 201374 [details]
Fixes issue when rpc.yppasswdd fails to copy master.passwd

As of FreeBSD 12.0 rpc.yppasswdd was failing to copy the master.passwd file due to call pw_init truncating the filename value stored in passfile

This fix copies the value of passfile to a temporary variable, passdir. This prevents passfile from being truncated while also allowing the necessary directory name to be passed.
Comment 2 Edward Fuhr 2019-01-24 03:38:15 UTC
(In reply to Edward Fuhr from comment #1)
I wish it to be known that this is my own amateur-hour patch, and in no way should this be considered an official patch. I thought the description was for the file and not to replace the blurb previously written up specifying this is NOT an official patch, but my own doing.
Comment 3 Bernard Marshall 2019-01-28 15:16:03 UTC
(In reply to Edward Fuhr from comment #2)

Thanks for looking into this Edward. A quick comment on your patch. I think you have forgotten to initialise "passdir_buf" in "yppasswdproc_update_master_1_svc". I suspect you need to add:

/* Hold a copy of the passfile in passdir */
snprintf(passdir_buf, sizeof(passdir_buf), "%s", passfile);
passdir = (char *)&passdir_buf;

around line 831 in the current file, otherwise passdir_buf will not be initialised with passfile.
Comment 4 u.drolshagen 2019-06-03 11:48:58 UTC
I am running into the same problem on a recently installed box running 12.0-stable. 
I'd like to know if it's to be expected that this bug gets fixed offically any time soon. Thank you
Comment 5 commit-hook freebsd_committer 2019-06-03 16:51:52 UTC
A commit references this bug:

Author: markj
Date: Mon Jun  3 16:51:07 UTC 2019
New revision: 348547
URL: https://svnweb.freebsd.org/changeset/base/348547

  rpc.yppasswdd: Fix dirname(3) usage after r305952.

  PR:		234972
  Submitted by:	Edward Fuhr <edward.fuhr@us.fujitsu.com> (original)
  MFC after:	3 days

Comment 6 u.drolshagen 2019-06-05 07:07:18 UTC
It works. Thanks a lot
Comment 7 commit-hook freebsd_committer 2019-06-06 03:02:27 UTC
A commit references this bug:

Author: markj
Date: Thu Jun  6 03:01:06 UTC 2019
New revision: 348716
URL: https://svnweb.freebsd.org/changeset/base/348716

  MFC r348547:
  rpc.yppasswdd: Fix dirname(3) usage after r305952.

  PR:	234972

_U  stable/12/
Comment 8 Mark Johnston freebsd_committer 2019-06-06 03:05:47 UTC
Thanks for the report and analysis.