mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* How to emulate 'chroot /jail/ su httpd -c' ?
@ 2004-02-26 10:56 Tetsuo Handa
       [not found] ` <403DEB2B.2030705@aitel.hist.no>
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Tetsuo Handa @ 2004-02-26 10:56 UTC (permalink / raw)
  To: linux-kernel

Hello,

Sorry for querying userland program in this list.

I have the following line in /etc/rc.d/init.d/httpd

daemon chroot /jail/ su httpd -c $httpd $OPTIONS

This needs /bin/su after /usr/sbin/chroot, but I don't
want to place /bin/su (and related files) in the jail.
So, I want to do this with one program.

But, the problem is... there are so many 'set*id()'
system calls and their behavior are slightly differ.
I'm not sure how to emulate 'chroot /jail/ su httpd -c'.
The following is the code I wrote, but is this equivalent?
(I want Apache never re-gain root privilege unless
executing setuid-root program.)

--- Is this a correct code to 'chroot /jail/ su httpd -c' ?---

#include <stdio.h>
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
    struct passwd *pw = getpwnam("httpd");
    if (!pw) return 1;
    if (chroot("/jail/") || chdir("/") || setuid(pw->pw_uid) || setgid(pw->pw_gid)) return 1;
    printf("OK\n"); // Now call execvl() to run Apache.
    return 0;
}

---

Kernel version is 2.4.25.
No need to worry for listening port 80,
I'm using iptables to redirect port 80 to 8000
and Apache doesn't need root privilege from the beginning.


Regards...

                  PANDA   (a5497108 at anet.ne.jp)

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: How to emulate 'chroot /jail/ su httpd -c' ?
@ 2004-02-26 14:24 Tetsuo Handa
  0 siblings, 0 replies; 5+ messages in thread
From: Tetsuo Handa @ 2004-02-26 14:24 UTC (permalink / raw)
  To: linux-kernel


# Daily digest mail didn't arrive to me yesterday(2/25) and
# today(2/26), may be something is wrong with my mail server.
# Sorry for ignoring thread tree, this is a reply to
http://www.ussg.iu.edu/hypermail/linux/kernel/0402.3/0848.html

Ma*ns Rullga*rd wrote:
> Tetsuo Handa <a5497108@xxxxxxxxxx> writes:
> 
> > Hello,
> >
> > Sorry for querying userland program in this list.
> >
> > I have the following line in /etc/rc.d/init.d/httpd
> >
> > daemon chroot /jail/ su httpd -c $httpd $OPTIONS
> >
> > This needs /bin/su after /usr/sbin/chroot, but I don't
> > want to place /bin/su (and related files) in the jail.
> > So, I want to do this with one program.
> 
> If you remove the suid bit from the su program in the chroot it should
> be rather harmless.

Oh! What a nice idea! 
'chmod 500 /bin/su' is to the purpose.
Thank you.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-02-26 14:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-26 10:56 How to emulate 'chroot /jail/ su httpd -c' ? Tetsuo Handa
     [not found] ` <403DEB2B.2030705@aitel.hist.no>
2004-02-26 13:07   ` Tetsuo Handa
     [not found] ` <20040226045855.A2529@pr.es.to>
2004-02-26 13:23   ` Tetsuo Handa
2004-02-26 13:34 ` Måns Rullgård
2004-02-26 14:24 Tetsuo Handa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®