Created
January 23, 2019 17:56
-
-
Save joxer/1cd0a4495af4e3abd9564401c23bb2d8 to your computer and use it in GitHub Desktop.
exit the chroot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create first a directory called chroot! | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <fcntl.h> | |
#include <dirent.h> | |
#include <stdio.h> | |
#include <sys/types.h> | |
void printDirInformation(DIR* dir) { | |
char* name; | |
struct dirent* current_dir; | |
do { | |
current_dir = readdir(dir); | |
if(current_dir != NULL) { | |
name = current_dir->d_name; | |
printf("%s\n", name); | |
} | |
} while(current_dir != NULL ); | |
} | |
int main() { | |
int fd; | |
fd = open(".", O_RDONLY); | |
chdir("chroot"); | |
int ret = chroot("."); | |
if(ret == -1) { | |
printf("cannot enter in chroot\n"); | |
exit(1); | |
} | |
printf("open first chroot\n"); | |
DIR *dir = opendir("."); | |
if(dir != NULL) | |
printDirInformation(dir); | |
printf("open second chroot\n"); | |
fchdir(fd); | |
chroot("."); | |
dir = opendir("."); | |
if(dir != NULL) | |
printDirInformation(dir); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment