Bug 19664

Summary: rpc.yppasswdd can't deal with comments in master.passwd
Product: Base System Reporter: Andre Albsmeier <Andre.Albsmeier>
Component: binAssignee: davidn
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 3.4-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
pw_copy.c.diff none

Description Andre Albsmeier 2000-07-03 11:30:00 UTC
When using yppasswd, rpc.yppasswdd can't deal with comments
in the $(YPDIR)/master.passwd file. Instead it logs to syslog:

rpc.yppasswdd[2623]: /var/yp/src/master.passwd: corrupted entry
rpc.yppasswdd[2623]: /var/yp/src/master.passwd: unchanged
rpc.yppasswdd[2623]: /var/yp/src/master.passwd: unchanged
rpc.yppasswdd[2623]: failed to created updated password file -- cleaning up and bailing out

How-To-Repeat: 
Enter a comment in $(YPDIR)/master.passwd. Run yppasswd to
produce the error.
Comment 1 Sheldon Hearn freebsd_committer freebsd_triage 2000-07-03 12:28:33 UTC
Responsible Changed
From-To: freebsd-bugs->davidn

David likes passwd-related problems. :-)
Comment 2 davidn 2000-07-11 03:06:42 UTC
Please try the enclosed patch and test to ensure that it resolves your
problem.
Comment 3 Andre Albsmeier 2000-07-11 12:42:55 UTC
On Tue, 11-Jul-2000 at 12:06:42 +1000, David Nugent wrote:
> Please try the enclosed patch and test to ensure that it resolves your
> problem.
> 

Content-Description: pw_copy.c.diff
> Executing: cvs diff -c pw_copy.c
> Index: pw_copy.c
> ===================================================================
> RCS file: /home/ncvs/src/usr.sbin/rpc.yppasswdd/pw_copy.c,v
> retrieving revision 1.4
> diff -c -r1.4 pw_copy.c
> *** pw_copy.c	1999/08/28 01:19:40	1.4
> --- pw_copy.c	2000/07/11 01:59:32
> ***************
> *** 90,95 ****
> --- 90,105 ----
>   				goto err;
>   			continue;
>   		}
> + 		/*
> + 		 * Just copy comments and blank lines
> + 		 */
> + 		p = buf + strcspn(buf, " \t\n");
> + 		if (*p == '\0' || *p == '#') {
> + 		        (void)fprintf(to, "%s", buf);
> + 			if (ferror(to))
> + 				goto err;
> + 			continue;
> + 		}
>   		if (!(p = strchr(buf, ':'))) {
>   			yp_error("%s: corrupted entry", passfile);
>   			pw_error(NULL, 0, 1);



Adding the '#' char to " \t\n" made it work. So the line reads

	p = buf + strcspn(buf, "# \t\n");


	-Andre
Comment 4 davidn 2000-07-11 14:23:24 UTC
Andre Albsmeier wrote:
> > +             p = buf + strcspn(buf, " \t\n");
> > +             if (*p == '\0' || *p == '#') {
> > +                     (void)fprintf(to, "%s", buf);
> > +                     if (ferror(to))
> > +                             goto err;
> > +                     continue;
> > +             }
> >               if (!(p = strchr(buf, ':'))) {
> >                       yp_error("%s: corrupted entry", passfile);
> >                       pw_error(NULL, 0, 1);
> 
> Adding the '#' char to " \t\n" made it work. So the line reads
> 
>         p = buf + strcspn(buf, "# \t\n");

Hmm. But this would mean

    # blah this is supposed to be a comment

have variable 'p' pointing at 'b' on the first 'if' statement above.
It would not be detected as a comment and it would get junked by
the next 'if'.

ACK! I see the bug. Change strcspn() to strspn() in my original
patch and try it again. Sorry about that - I've *always* confused
those two. :-) That statement is intended to skip leading whitespace
and test the next char for end of string (empty line) or the start
of a comment. If either, copy and continue, otherwise fall through
to the sanity check that caused the hiccup before.


David
Comment 5 davidn freebsd_committer freebsd_triage 2000-07-11 18:09:15 UTC
State Changed
From-To: open->feedback

Patch submitted to user for testing.
Comment 6 Andre Albsmeier 2000-07-12 10:46:05 UTC
On Tue, 11-Jul-2000 at 23:23:24 +1000, David Nugent wrote:
> Andre Albsmeier wrote:
> > > +             p = buf + strcspn(buf, " \t\n");
> > > +             if (*p == '\0' || *p == '#') {
> > > +                     (void)fprintf(to, "%s", buf);
> > > +                     if (ferror(to))
> > > +                             goto err;
> > > +                     continue;
> > > +             }
> > >               if (!(p = strchr(buf, ':'))) {
> > >                       yp_error("%s: corrupted entry", passfile);
> > >                       pw_error(NULL, 0, 1);
> > 
> > Adding the '#' char to " \t\n" made it work. So the line reads
> > 
> >         p = buf + strcspn(buf, "# \t\n");
> 
> Hmm. But this would mean
> 
>     # blah this is supposed to be a comment
> 
> have variable 'p' pointing at 'b' on the first 'if' statement above.
> It would not be detected as a comment and it would get junked by
> the next 'if'.

Oops, of course...

> 
> ACK! I see the bug. Change strcspn() to strspn() in my original
> patch and try it again. Sorry about that - I've *always* confused
> those two. :-) That statement is intended to skip leading whitespace
> and test the next char for end of string (empty line) or the start
> of a comment. If either, copy and continue, otherwise fall through
> to the sanity check that caused the hiccup before.

Works! Thanks a lot.

	-Andre

> 
> 
> David

-- 
Your mouse has moved.
Windows NT must be restarted for the change to take effect!

Reboot now?  [OK]
Comment 7 davidn freebsd_committer freebsd_triage 2000-07-13 03:02:03 UTC
State Changed
From-To: feedback->closed

Fix committed in: 
Checking in pw_copy.c; 
/home/ncvs/src/usr.sbin/rpc.yppasswdd/pw_copy.c,v  <--  pw_copy.c 
new revision: 1.5; previous revision: 1.4