diff options
author | lns <matzeton@googlemail.com> | 2018-04-27 21:18:11 +0200 |
---|---|---|
committer | lns <matzeton@googlemail.com> | 2018-04-27 21:18:11 +0200 |
commit | 45e0049315f9ca7e68a97fcfa73778f1c5dc1d75 (patch) | |
tree | f3de637feeba570be22cadbc2daca2fdc802f758 | |
parent | 533f9b6dea8365fe911955cc93f5c6d59daebfec (diff) |
POTD skeleton #35.
Signed-off-by: lns <matzeton@googlemail.com>
-rw-r--r-- | src/jail.c | 20 | ||||
-rw-r--r-- | src/utils.c | 32 | ||||
-rw-r--r-- | src/utils.h | 6 |
3 files changed, 54 insertions, 4 deletions
@@ -2,6 +2,7 @@ #include <stdlib.h> #include <sched.h> #include <signal.h> +#include <pty.h> #include <sys/epoll.h> #include <sys/prctl.h> #include <assert.h> @@ -248,6 +249,10 @@ error: static int jail_childfn(void *arg) { jail_prisoner_process *args; + int term_fd; + struct termios *term = NULL; + struct winsize *win = NULL; + pid_t child_pid; assert(arg); args = (jail_prisoner_process *) arg; @@ -261,14 +266,21 @@ static int jail_childfn(void *arg) E2("%s", "No new root set"); exit(EXIT_FAILURE); } - N2("Safe change root to: '%s'", args->newroot); + D2("Safe change root to: '%s'", args->newroot); if (safe_chroot(args->newroot)) { E2("Safe jail chroot to '%s' failed", args->newroot); exit(EXIT_FAILURE); } - printf("----> CHILD FN: %d <----\n", args->client_psock.fd); - sleep(10); + D2("%s", "Forking a new pseudo terminal"); + child_pid = forkpty(&term_fd, NULL, term, win); + if (!child_pid) { + if (execl("/bin/bash", "/bin/bash", (char *) NULL)) { + exit(EXIT_FAILURE); + } + } else { + W_STRERR("Forking a new pseudo terminal"); + } - exit(EXIT_SUCCESS); + exit(EXIT_FAILURE); } diff --git a/src/utils.c b/src/utils.c index 7671ac5..ac0856c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -226,3 +226,35 @@ int safe_chroot(const char *newroot) return 0; } + +int dir_is_mountpoint(const char *path) +{ + struct stat current, parent; + size_t plen = strlen(path); + char parent_path[plen + 4]; + + if (stat(path, ¤t)) + return -1; + parent_path[plen] = '/'; + parent_path[plen+1] = '.'; + parent_path[plen+2] = '.'; + parent_path[plen+3] = 0; + + if (stat(parent_path, &parent)) + return -1; + + return current.st_dev == parent.st_dev; +} + +int mount_dev(const char *mount_path) +{ + if (!mount_path) { + } + + return 0; +} + +int mount_pts(const char *mount_path) +{ + return 0; +} diff --git a/src/utils.h b/src/utils.h index 2cabfd0..f9c9e8b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -22,4 +22,10 @@ int change_user_group(const char *user, const char *group); int safe_chroot(const char *newroot); +int dir_is_mountpoint(const char *path); + +int mount_dev(const char *mount_path); + +int mount_pts(const char *mount_path); + #endif |