# dhclient workings



## ckozler (Jun 13, 2011)

Hey guys,

Please see here for more information http://forums.freebsd.org/showthread.php?t=24346. That thread will explain why I am trying to add a user to a modified boot-only ISO and mfsroot.gz.  In short, I would like to add in DHCP support but I am facing an issue.

When I execute *dhclient* I am prompted with


```
no such user: _dhcp, falling back to "nobody"
no such user: nobody
exiting
```

Ok, not a problem, lets go ahead and add them:


```
$ pw user add [ ... ]
pw: passwd file update: bad file descriptor
```

Now, most of my research said that "bad file descriptor" is usually an error because the drive has errors but the issue here is that I am already on a read/write file system from /dev/md0.  I can edit /etc/passwd directly and if I *chroot* into the installed environment in /mnt that my auto-install process does, I am able to successfully run dhclient.  

My main issue here is that I am trying to run dhclient prior to extracting the base system to /mnt but can not because the user does not exist.  When I try to create the user the pw bin gives me an error about bad file descriptor when in reality, I can update /etc/passwd directly.  Is there somewhere else dhclient may look for user information before dying out?

EDIT:

I see that dhclient fails here


```
if ((pw = getpwnam("_dhcp")) == NULL) {
                warning("no such user: _dhcp, falling back to \"nobody\"");
                if ((pw = getpwnam("nobody")) == NULL)
                        error("no such user: nobody");
        }
```

Looks like getpwnam looks up a number of files of which are encrypted and I can't force the user into the database.

Any suggestions?


----------



## ckozler (Jun 13, 2011)

If it's any consolation, for the purpose of my auto-install, I have done the following:


```
//if ((pw = getpwnam("_dhcp")) == NULL) {
        //      warning("no such user: _dhcp, falling back to \"nobody\"");
        //      if ((pw = getpwnam("nobody")) == NULL)
        //              error("no such user: nobody");
        //}
```

And also modified 


```
//if (setgroups(1, &pw->pw_gid) ||
        //    setegid(pw->pw_gid) || setgid(pw->pw_gid) ||
        //    seteuid(pw->pw_uid) || setuid(pw->pw_uid))
        //      error("can't drop privileges: %m");
```

And created the required directory structure.  This allows me to use dhclient without forcing dhclient to use a different user.

It would be good if there was a switch like -n for not dropping privileges and running as root.  Albeit, not advisable, but could come in handy when troubleshooting some things (like this for example).


----------



## wblock@ (Jun 13, 2011)

Take a look at the mfsBSD build scripts.  dhclient(8) runs fine on it, probably because of a writable RAM disk (I haven't looked).


----------

