SlackwareThis Forum is for the discussion of Slackware Linux.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I'm no newbie to slackware but I've run across a problem I am not sure how to solve.
I created an openssh3.4p1 package. No problem.
In order to use privilege separation I need to add a user to the system.
My question is: How do I add a user to the system from within the package? I can't use useradd since /etc/passwd|shadow are not guaranteed to be the "real" passwd and shadow files (think of a new install, / is the RAM disk).
Similarly, I can't just append a line on to etc/passwd|shadow (note: no leading /) because I can't guarantee that the uid isn't already used. Well, I can, but that's a lot of extra work to generate the next free uid to use.
I compile specific options in (paths, etc.) so the stock one from ftp does me no good.
I will, however take a look and see what they did (or if they just turned off Privilege Separation)...
[update, 5 min later]
They cheat. <sigh>
# If the sshd user/group don't exist, add them:
if grep "^sshd:x:" etc/passwd 1> /dev/null 2> /dev/null ; then
echo "sshd:x:33:33:sshd:/:" >> /etc/passwd
if grep "^sshd::" etc/group 1> /dev/null 2> /dev/null ; then
echo "sshd::33:sshd" >> etc/group
if grep "^sshd:" etc/shadow 1> /dev/null 2> /dev/null ; then
echo "sshd:*:9797:0:::::" >> etc/shadow
At any rate the question is a general question, not specific to openssh; in *any* package I create, how would I add users to the system without resorting to tricks like this? (say postgresql, or a backup package, or anything really)
Last edited by akohlsmith; 07-08-2002 at 03:14 PM.
The reason I ask is because you aren't reading my message, and slack users are often the ones which have read quite a bit. :-)
useradd *will*not*work* in all instances since / may not be the actual root of the final filesystem!
e.g. pop in the slack cd, boot from it with the intention of installing a new system. run useradd; it won't add it to the real system, just the boot system.
That is because useradd expects the /etc/passwd and /etc/shadow to be off of the root filesystem. That is *not* the case with ramdisk-root systems such as a CD-based install, since the eventual / is actually /mnt or /var/mount or wherever the installer happens to mount it.
I read the useradd manpage but it doesn't appear to have any option to specific which passwd/shadow file to use. If it did, I'd just tell it to use etc/passwd instead of /etc/passwd.
I've been a slack user since '96 or so... It's just been recently that I've been creating my own packages which is why I'd never run across this before. a.out to elf conversion? no problem. libc5 to glibc conversion? no problem. Intelligently adding a user to a system from inside a package? <grumble>
Why don't you cross-post the a couple of other list, maybe one like dev. I think your off base here. The locations of the
passwd file (which you seem to be hung up on), is a Unix stardard ...... since ATT wrote it way back when.....
BTW, Have you taken apart a Slack package and study how
Last edited by pickledbeans; 07-08-2002 at 04:36 PM.
I posted here specifically because it is a slackware-specific issue.
I know that /etc/passwd and shadow are the correct locations. I don't think you're understanding the question though :-(
useradd adds a user to a running system. It does this without flaws.
Packages can be installed into running systems or into temporary "set up" systems. These temporary systems (usually) run from ram disk, in which case /etc/passwd|shadow aren't the "real" /etc/passwd|shadow, they're the passwd and shadow files for the setup system image.
It's trivial to use useradd to add a user to a running system. That is not the issue.
The issue is that since packages can be installed from a setup system or a running system, I need a method for adding to the passwd/shadow files in both cases.
I've taken a few packages apart but it appears that they don't worry about this; they use a specific uid and gid and simply cat that on to the end of the existing passwd|shadow file. That works fine, but if that uid or gid is already used you'll get funny results.
The uid or gid may already be used on a running system. There are general conventions which can be followed but no real way to be sure, whcih is what useradd does perfectly.
<sigh> oh well; I guess I can use shell scripting to scan the passwd file for a uid that doesn't exist. I was hoping there was a better way to do it. :-)
Thanks for your time in this; I really do appreciate your effort. And I love your signature.