467,923 Members | 1,393 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,923 developers. It's quick & easy.

this code should chroot and exec program but fails

/************************************************** ***
*** chrexec.c ***
*This shit can be called from root or from any user (in that case executable
* should have 06755 permisions) and should chroot and exec program
* (specified in command line parameter) in general, but it doesn`t.
* ************************************************** **/
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>

#define VALIDATE(f,err) \
if (f == -1)\
exit (-1);\

int main(int args, char *argv[])
int i;
for (i = 0; i < args; i++)
fprintf(stderr, "param %02d: %s\n", i, argv[i]);
int initialUID = getuid();
int initialGID = getgid();
fprintf(stderr, "initial UID: %d initial GID: %d\n", initialUID, initialGID);


fprintf(stderr, "chrooting to .\n");

DIR *curr = opendir(".");
if (!curr)
struct dirent *dir;
fprintf(stderr, "Files in \".\":\n");
while (dir = readdir(curr))
fprintf(stderr, ">> %s\n", dir->d_name);
fprintf(stderr, "No more files in \".\"\n");
VALIDATE(execv(argv[1], &argv[1]),"execv")
// execv: No such file or directory in most cases
return 0;
/************************************************** *****
* "chrexec" works if do not perform "chroot" call, and if "." (current dir) is "/".
* With chrexec I try to call another executable in "." directory (and even list
* files to show that this executable really exist in ".")
* That`s my first experience of using chroot, can anyone show me mistake?
************************************************** ******/
Apr 13 '07 #1
  • viewed: 1808
1 Reply
sorry code was working, I just forgot to carry out some libs to new chroot...
Apr 13 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Jimmy Jim | last post: by
8 posts views Thread by Stefan Seefeld | last post: by
5 posts views Thread by Carlos Moreno | last post: by
6 posts views Thread by Gordowey | last post: by
1 post views Thread by ashore | last post: by
12 posts views Thread by gregpinero | last post: by
8 posts views Thread by John Henry | last post: by
4 posts views Thread by support\.intranet | last post: by
9 posts views Thread by Emanuele D'Arrigo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.