Problems with chroot()

This is a discussion on Problems with chroot() within the C Programming forums, part of the General Programming Boards category; Im having problems on my ubuntu system writing a small program which start a chroot'ed apache server. The following is ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    12

    Problems with chroot()

    Im having problems on my ubuntu system writing a small program which start a chroot'ed apache server. The following is my code

    Code:
    int main() {
    
    pid_t apache_pid;
    
    if ((apache_pid = fork()) == 0 )
     {   chroot("/var/webjail/");
        execl("/usr/local/apache/bin/apachectl", "apachectl", "-k", "start", NULL);
      }
    
    waitpid(apache_pid,NULL,0);
    
    return 0;
    }
    It always seems to fail whilst creating a chroot. I put some debugging in there and chroot always returns null. I run the process as root and I have tried chrooting to other directories, of which all fail. I have changed the permissions to 777 on these directories so permissions would not be a problem (not that it should be as root anyway).


    Any ideas?
    Cheers
    Ray

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,341
    http://www.hmug.org/man/2/chroot.php
    Apparently, 0 means success.
    But if it is -1, then look at the global variable errno, or use perror() to find out the reason for failure.

    > /usr/local/apache/bin/apachectl
    Does this path exist below /var/webjail/ ?

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    12
    Exactly, and Im getting null, hence no success

    Yes the path does exist, and I've tried it with other chroot directories and subsequent commands, and to no avail.

    perror looks like it is causing some buffer overflow as it gives me \uffff^\uffff\uffff\uffff\uffff\uffff\uffff\uffffZ \u0777\uffff\uffff1 Mon Oc : as the value of errno !

    Weird huh. Im actually having problems just getting anything to work from a chroot on the command line...whats up with that ?!

    Ray

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,341
    > Exactly, and Im getting null,
    null implies a pointer, chroot() returns an integer.

    Code:
    if ( chroot("/var/webjail/") != 0 ) {
      printf( "The value of errno = %d\n", errno );
      perror( "The error message is" );
    }
    Maybe it doesn't like the trailing / on the directory name

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 05:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 08:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 03:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21