aboutsummaryrefslogtreecommitdiff
path: root/src/jail.c
diff options
context:
space:
mode:
authorlns <matzeton@googlemail.com>2018-04-29 18:48:51 +0200
committerlns <matzeton@googlemail.com>2018-04-29 18:48:51 +0200
commit8002952a4e49ed0a38779727783e1eb273e536ff (patch)
tree48d49601253aac2c6e07715765fe6edd85f27ee0 /src/jail.c
parenta4fc4120d474ee277e3f24c8c7ea5929b489d477 (diff)
POTD sekeleton #38.
Signed-off-by: lns <matzeton@googlemail.com>
Diffstat (limited to 'src/jail.c')
-rw-r--r--src/jail.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/jail.c b/src/jail.c
index 7f38804..fc2e843 100644
--- a/src/jail.c
+++ b/src/jail.c
@@ -3,6 +3,7 @@
#include <sched.h>
#include <signal.h>
#include <pty.h>
+#include <sys/wait.h>
#include <sys/epoll.h>
#include <sys/prctl.h>
#include <sys/stat.h>
@@ -287,10 +288,7 @@ static int jail_childfn(void *arg)
E_STRERR("mkdir");
exit(EXIT_FAILURE);
}
- if (dir_is_mountpoint(path_dev)) {
- W2("%s%s is already a mountpoint", args->newroot, path_dev);
- }
- if (mount_dev(path_dev)) {
+ if (!dir_is_mountpoint(path_dev) && mount_dev(path_dev)) {
E2("Can not mount devtmpfs to %s%s", args->newroot, path_dev);
exit(EXIT_FAILURE);
}
@@ -309,15 +307,30 @@ static int jail_childfn(void *arg)
exit(EXIT_FAILURE);
}
+ D2("Creating device files in %s%s", args->newroot, path_dev);
+ if (create_device_files(path_dev)) {
+ E2("Device file creation failed for rootfs '%s%s'",
+ args->newroot, path_dev);
+ exit(EXIT_FAILURE);
+ }
+
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");
+ switch (child_pid) {
+ case -1:
+ W_STRERR("Forking a new pseudo terminal");
+ break;
+ case 0:
+ D2("Executing '%s'", "/bin/bash");
+ if (execl("/bin(bash", "/bin/bash", (char *) NULL))
+ W_STRERR("Execute a shell");
+ break;
+ default:
+ waitpid(child_pid, &s, 0);
}
+printf("_%d,%d_\n", child_pid, getuid());
+sleep(10);
+
exit(EXIT_FAILURE);
}