Skip to content

Instantly share code, notes, and snippets.

@fmount
Last active June 11, 2019 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmount/32f21a930f798636e2d4fa4f57feb3f6 to your computer and use it in GitHub Desktop.
Save fmount/32f21a930f798636e2d4fa4f57feb3f6 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
int enter_chroot(const char * root) {
/* chroot */
chdir(root);
if (chroot(root) != 0) {
perror("chroot");
return 1;
}
}
int read_print(const char* path) {
FILE *f;
f = fopen(path, "r");
if (f == NULL) {
perror(path);
return 1;
} else {
char buffer[50];
while (fgets(buffer, sizeof(buffer), f)) {
printf("%s", buffer);
}
}
return 0;
}
int main(void) {
//read_print("/etc/hostname");
if(enter_chroot("/home/fmount/projects/c_gopherd/example")) {
return 1;
}
int val = read_print("gophermap");
return val;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment