Subject: bin/10401: useradd doesn't add home dir when using the -d option
To: None <gnats-bugs@gnats.netbsd.org>
From: None <root@segue.brwn.org>
List: netbsd-bugs
Date: 06/20/2000 04:32:12
>Number:         10401
>Category:       bin
>Synopsis:       useradd doesn't add the home dir to the passwd file if specified with the -d option
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 20 04:33:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Charlie Root
>Release:        NetBSD-1.4.2 RELEASE
>Organization:
	
>Environment:
	
System: NetBSD segue 1.4.2 NetBSD 1.4.2 (SEGUE) #1: Thu Mar 23 22:21:15 SAST 2000 root@segue:/usr/src/sys/arch/i386/compile/SEGUE i386


>Description:
	The home directory field is not added to the passwd database if it is specfified on
	the command line using the -d option to the /usr/sbin/useradd tool.

	If the -d option is specified, the u_homeset variable is set to 1. The relevent code
	checks to see if the u_homeset variable is not set.

        /* if home directory hasn't been given, make it up */
        if (!up->u_homeset) {
                (void) snprintf(home, sizeof(home), "%s/%s", up->u_basedir, login);
        }

	It only set the home variable if the -d is not specfified.

>How-To-Repeat:
	This command is used by the PostgreSQL package to add a user for PostgreSQL.

	user add -c "PostgreSQL database administrator" -d /usr/pkg/pgsql -g ingres -s /bin/sh pgsql

	It will leave the home directory field in the password database with no value or whatever whas
	in the memory the home variable occupied at the time.
>Fix:
	This patch attempts to fix this problem.

	RCS id of the file.

/* $NetBSD: user.c,v 1.10.2.2 2000/02/04 22:57:21 he Exp $ */

	The patch.

--- usr.sbin/user/user.c.orig   Tue Jun 20 12:18:58 2000
+++ usr.sbin/user/user.c        Tue Jun 20 13:28:27 2000
@@ -708,6 +708,8 @@
        /* if home directory hasn't been given, make it up */
        if (!up->u_homeset) {
                (void) snprintf(home, sizeof(home), "%s/%s", up->u_basedir, login);
+       } else {
+               (void) strlcpy(home, up->u_home, sizeof(home));
        }
        expire = 0;
        if (up->u_expire != (char *) NULL) {
>Release-Note:
>Audit-Trail:
>Unformatted: