NetBSD Problem Report #11707

Received: (qmail 8809 invoked from network); 12 Dec 2000 18:29:50 -0000
Message-Id: <200012121829.KAA00703@nbwww.isc.org>
Date: Tue, 12 Dec 2000 10:29:50 -0800 (PST)
From: jmaier@midamerica.net
Reply-To: jmaier@midamerica.net
To: gnats-bugs@gnats.netbsd.org
Subject: usermod doesn't move home directory and -m does work as documented
X-Send-Pr-Version: www-1.0

>Number:         11707
>Category:       bin
>Synopsis:       usermod doesn't move home directory and -m does work as documented
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 12 18:30:01 +0000 2000
>Closed-Date:    Sat Dec 23 17:20:55 +0000 2000
>Last-Modified:  Sat Dec 23 17:20:55 +0000 2000
>Originator:     John Maier
>Release:        NetBSD 1.5 release
>Organization:
>Environment:
NetBSD newmail 1.5 NetBSD 1.5 (MAIL) #6: Tue Dec  5 10:03:39 CST 2000     root@newmail:/usr/src/sys/arch/i386/compile/MAIL i386

>Description:
usermod is unable to move the original home director to the new home directory. (see example in How to repeat the problem)

I omited the -m option and it still trys to move the directory, which seem counter to what the man page says.

-m      moves the home directory from its old position to the new one.

and

-d home-directory
             is the home directory which will be created and populated for the
             user, should the -m option be specified.

It seems to me that the manpage implies that if the -m option is omited the directory isn't moved, but never specifies what happens to the directory specified my -d.  A new /etc/skel/.* populated directory is created?

I was going to submit this as a admin bug and a doc bug, but I think they are too related.
>How-To-Repeat:
I have this test account jmaier, I want to move it to jmaiera so...

$ usermod -v -m -d/usr/home/jmaiera -ljmaiera jmaier
Command: /bin/mv /usr/home/jmaiera /usr/home/jmaiera
mv: rename /usr/home/jmaiera to /usr/home/jmaiera: No such file or directory
usermod: [Warning] can't system `/bin/mv /usr/home/jmaiera /usr/home/jmaiera'
usermod: can't move `/usr/home/jmaiera' to `/usr/home/jmaiera': Inappropriate ioctl for device

>Fix:
I'm just scripting around the problem for now.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: netbsd-admin->bin-bug-people 
Responsible-Changed-By: fair 
Responsible-Changed-When: Tue Dec 12 10:32:55 PST 2000 
Responsible-Changed-Why:  
This is not a NetBSD *Server Operations* problem. 

From: "John Maier" <jmaier@midamerica.net>
To: <gnats-bugs@netbsd.org>
Cc: "Alistair Crooks" <AlistairCrooks@excite.com>
Subject: Re: bin/11707
Date: Thu, 14 Dec 2000 17:56:03 -0600

 Here is a patch that fixes bin/11707 and bin/11710

 This is the behavior I have specified for usermod (user mod):

 If -m and -d is are passed together, the directory specified in the password
 file is moved to the new home directory specifed after -d.
 i.e. usermod -m -d /var/home/test validuser (the home directory
 /usr/home/validuser in in the passwd file)
 then: update passwd so that the home directory is /usr/home/validuser
 then: mv /usr/home/validuser /var/home/test

 If -m is passed and -l is passed, the directory specified in the password
 file is moved to the default base dir of of the new user name.
 i.e. usermod -m -l newuser validuser (the home directory /usr/home/validuser
 in in the passwd file)
 then: update passwd so that the home directory is $BASEDIR/newuser
 then: mv /usr/home/validuser $BASEDIR/newuser

 If -m -d and -l are passed together, -d takes precidence over the -l
 behavior.

 If -m is passed and neither -l or -d are specifed, well this is just wrong
 and I should check for this condition, but nothing is really done except to
 try to move the home dir to itself.

 If -m is omited and -l or -d are specified, the home directory is NOT moved,
 but the passwd file is updated.  Thus it is up to the person invoking
 usermod to ensure the new home dir exists.

 BTW, there is some real logic problem with user mod's modification.  We can
 take that offline though.

 Here's the patch!

 --- user/user.c Sat Nov  4 19:18:41 2000
 +++ user.new/user.c Thu Dec 14 17:22:01 2000
 @@ -1008,6 +1008,7 @@
   size_t  colonc, len, loginc;
   FILE  *master;
   char  *buf, *colon, *line;
 + char  newhome[MaxFileNameLen];
   int  masterfd;
   int  ptmpfd;

 @@ -1017,7 +1018,10 @@
   if ((pwp = getpwnam(login)) == NULL) {
    errx(EXIT_FAILURE, "No such user `%s'", login);
   }
 - newpwp = pwp;
 + newpwp = malloc(sizeof(struct passwd));
 + memcpy(newpwp, pwp, sizeof(struct passwd));
 +
 +
   if ((masterfd = open(_PATH_MASTERPASSWD, O_RDONLY)) < 0) {
    err(EXIT_FAILURE, "can't open `%s'", _PATH_MASTERPASSWD);
   }
 @@ -1089,8 +1093,16 @@
    }
    if (up->u_flags & F_COMMENT)
     newpwp->pw_gecos = up->u_comment;
 -  if (up->u_flags & F_HOMEDIR)
 -   newpwp->pw_dir = up->u_home;
 +  if (up->u_flags & F_HOMEDIR)
 +   strcpy(newhome, up->u_home);
 +  else {
 +   if ((up->u_flags & F_MKDIR) && (strlen(newlogin) > 0))
 +    sprintf(newhome, "%s/%s", up->u_basedir, newlogin);
 +   else
 +    /* default to what's already in the passwd
 +    file if the dir is NOT to be moved */
 +    strcpy(newhome, pwp->pw_dir);
 +  }
    if (up->u_flags & F_SHELL)
     newpwp->pw_shell = up->u_shell;
   }
 @@ -1111,7 +1123,7 @@
       (long)newpwp->pw_change,
       (long)newpwp->pw_expire,
       newpwp->pw_gecos,
 -     newpwp->pw_dir,
 +     newhome,
       newpwp->pw_shell);
      if (write(ptmpfd, buf, len) != len) {
       (void) close(ptmpfd);
 @@ -1131,11 +1143,11 @@
   }
   if (up != NULL) {
    if ((up->u_flags & F_MKDIR) &&
 -      asystem("%s %s %s", MV, pwp->pw_dir, newpwp->pw_dir) != 0) {
 +      asystem("%s %s %s", MV, pwp->pw_dir, newhome) != 0) {
     (void) close(ptmpfd);
     (void) pw_abort();
     err(EXIT_FAILURE, "can't move `%s' to `%s'",
 -     pwp->pw_dir, newpwp->pw_dir);
 +     pwp->pw_dir, newhome);
    }
    if (up->u_groupc > 0 &&
        !append_group(newlogin, up->u_groupc, up->u_groupv)) {
 @@ -1390,7 +1402,7 @@
     break;
    case 'd':
     memsave(&u.u_home, optarg, strlen(optarg));
 -   u.u_flags |= (F_MKDIR | F_HOMEDIR);
 +   u.u_flags |= (F_HOMEDIR);
     break;
    case 'e':
     memsave(&u.u_expire, optarg, strlen(optarg));


State-Changed-From-To: open->closed 
State-Changed-By: wiz 
State-Changed-When: Sat Dec 23 08:34:03 PST 2000 
State-Changed-Why:  
Fix committed to NetBSD-current, and pull-up to the 1.5 branch requested. 
Thanks for the PR! 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.