-
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
-
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/ ?
-
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
-
> 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