Subject: pkg/6268: addnerd doesn't automatically generate a uid for me...
To: None <gnats-bugs@gnats.netbsd.org>
From: None <elric@imrryr.org>
List: netbsd-bugs
Date: 10/09/1998 14:56:39
>Number:         6268
>Category:       pkg
>Synopsis:       addnerd doesn't automatically generate a uid for me...
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Oct  9 15:05:01 1998
>Last-Modified:
>Originator:     R. C. Dowdeswell
>Organization:
	
>Release:        NetBSD-current 19981004
>Environment:
System: NetBSD mabelode.imrryr.org 1.3H NetBSD 1.3H (MABELODE) #0: Mon Oct 5 15:01:06 PDT 1998 elric@mabelode.imrryr.org:/usr/src/sys/arch/alpha/compile/MABELODE alpha


>Description:
	If I try addnerd (after adding the pkg), I get:

	# addnerd bob
	addnerd: /usr/pkg/sbin/addnerd: [Error] can't get next uid for -1

	It only works if I specify a uid (which is the real reason I might want
	to use addnerd...
>How-To-Repeat:
	# addnerd bob
>Fix:
	The problem is on line 264, in the function getnextuid():


	/* return the next valid unused uid */
	static int
	getnextuid(char *f, int *nextuid)
	{
		struct passwd   *pwp;
		FILE            *fp;

		for (*nextuid = -1; (pwp = getpwent()) != (struct passwd *) NULL ; ) {
			if (pwp->pw_uid > *nextuid && !isnerd(pwp->pw_name)) {
				*nextuid = pwp->pw_uid;
			}
			fprintf(stderr, "Found a uid (%d)\t-- current (%d)\n", pwp->pw_uid, *nextuid);
		}       
		if (*nextuid == -1) { 
			return 0;
		}       
		do {
			*nextuid += 1;
		} while (getpwuid(*nextuid) != (struct passwd *) NULL);
		return 1;
	}

	The line in question is:
			if (pwp->pw_uid > *nextuid && !isnerd(pwp->pw_name)) {
	The problem is that pwp->pw_uid is defined as uid_t, which is u_int32_t, and
	so is never evaluates as true (I'm guessing that -1 is converted to unsigned
	and is hence always larger or equal to pwp->pw_uid.)

	This may be an alpha specific problem or perhaps it is the egcs that I'm
	using, but it should be pretty trivial to fix.
>Audit-Trail:
>Unformatted: