Re: Outstanding question
Jeff King <[email protected]> Sun, 9 Feb 2003 18:33:54 -0500 (EST)
| Newsgroups | gmane.comp.djb.publicfile |
|---|---|
| Message-ID | <[email protected]> |
On Sun, 9 Feb 2003, adam morley wrote:
> On Sun, Feb 09, 2003 at 03:24:09PM +0800, Adrian Ho wrote:
> > No, you should be seeing /tcpserver/ running as root -- it spawns ftpd
> > or httpd after accepting a connection.
This is right.
> > As a one-off test, simply replace the call to httpd in your run script
> > with /usr/bin/id (or whatever utility you use to determine the real and
> > effective UIDs/GIDs on your system) and restart the service. Then telnet
> > to your httpd port and see for yourself. Once you're satisfied, undo
> > the above change and restart the service again.
This is incorrect advice. tcpserver does have an option to read the
UID/GID environment variables and automatically switch ids (while
waiting for connections). However, publicfile is not able to use them
because it also wants to chroot. So it execs httpd/ftpd as root, which
chroot, chdir("."), and then drop privs. This can be clearly seen in the
strace output you provided:
> [...]
> execve("/usr/bin/httpd", ["/usr/bin/httpd", "/home/public/file"], [/* 20 vars */]) = 0
> [...]
> chdir("/home/public/file") = 0
> chroot(".") = 0
> setgroups32(0x1, 0xbffffd30) = 0
> setgid32(0x15) = 0
> setuid32(0x15) = 0
tcpserver doesn't handle chrooting automatically. And even if it did, it
would be a collosal pain since it would require .../bin/{ftpd,httpd} and
all of their dynamic libraries to be in the new root.
> Looks to me like httpd does do the proper setuid32 and setgid32 calls,
> but id does not. Why? Well, I looked at main.c from publicfile-0.52,
> and I found it was doing some testing with gid/uid, so I'm guessing
> thats where the setuid/setgid happen (but I could be wrong)
Right. It looks like Adrian was thinking of tcpserver's -G/-U. However,
if those are in use, the tcpserver process should show up as the ftpd id
(it drops privs after opening the listen socket).
-Peff