Subject: Re: /etc/login.conf required to exist after user(8) changes
To: None <current-users@NetBSD.org>
From: Jukka Salmi <j+nbsd@2005.salmi.ch>
List: current-users
Date: 07/29/2005 12:33:45
--1yeeQ81UyVL57Vl7
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hubert Feyrer --> current-users (2005-07-28 22:07:22 +0200):
> In article <20050728082535.GA10022@grouper.salmi.ch> you wrote:
> > I just failed to add a user using useradd(8) on a system which does
> > not have a /etc/login.conf; creating an empty file fixed the problem.
> > Yesterday's commit to src/usr.sbin/user/user.c changed this requirement.
> > Is login.conf required to exist now? If yes, this should be mentioned
> > in src/UPDATING, shouldn't it?
> 
> Hard to tell as  you don't say what the useradd(8) change is, but in 
> general login.conf is for something else than useradd(8), and as such 
> useradd(8) should work without it. 

I'm talking about the [1]changes made to src/usr.sbin/user/user.c
between revisions 1.81 and 1.82, committed by christos, including
"patches from Liam Foy" (was there a PR?).

It's the valid_class() function which causes the problem because it
calls err(3) if login.conf does not exist.

Another possible problem: the pointer used in the return expression
is already free()ed.

The attached patch fixes both problems.


Cheers, Jukka

[1] http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.sbin/user/user.c.diff?r1=1.81&r2=1.82

-- 
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~

--1yeeQ81UyVL57Vl7
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="user.c.patch"

Index: usr.sbin/user/user.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/user/user.c,v
retrieving revision 1.83
diff -u -r1.83 user.c
--- usr.sbin/user/user.c	27 Jul 2005 23:32:02 -0000	1.83
+++ usr.sbin/user/user.c	29 Jul 2005 10:16:49 -0000
@@ -974,20 +974,24 @@
 valid_class(char *class)
 {
 	login_cap_t *lc;
+	int ret;
 	
 	/*
 	 * Check if /etc/login.conf exists. login_getclass() will
-	 * return 1 due to it not existing, so not informing the
+	 * not return 0 due to it not existing, so not informing the
 	 * user the actual login class does not exist.
 	 */
 
 	if (access(PATH_LOGINCONF, R_OK) == -1)
-		err(EXIT_FAILURE, "access failed `%s'", PATH_LOGINCONF);
+		return 1;
 
-	if ((lc = login_getclass(class)) != NULL)
+	lc = login_getclass(class);
+	ret = lc != NULL;
+
+	if (lc != NULL)
 		login_close(lc);
 
-	return lc != NULL;
+	return ret;
 }
 #endif
 

--1yeeQ81UyVL57Vl7--