aboutsummaryrefslogtreecommitdiff
path: root/src/jail.c
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2018-05-02 00:22:25 +0200
committerToni Uhlig <matzeton@googlemail.com>2018-05-02 00:22:25 +0200
commit3ef3c65b4d19df39e020c1d5f778dafdf493a635 (patch)
treeb0ddf82f8a7ea213ecefc056848800af8ede30f3 /src/jail.c
parent8002952a4e49ed0a38779727783e1eb273e536ff (diff)
POTD skeleton #39.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src/jail.c')
-rw-r--r--src/jail.c65
1 files changed, 26 insertions, 39 deletions
diff --git a/src/jail.c b/src/jail.c
index fc2e843..8e05352 100644
--- a/src/jail.c
+++ b/src/jail.c
@@ -66,11 +66,11 @@ int jail_setup(jail_ctx *ctx,
return 1;
}
if (socket_bind_in(&ctx->sock, &srv_addr)) {
- E_STRERR("Could not bind server socket");
+ E_STRERR("Could not bind server socket to %s:%s", listen_addr, listen_port);
return 1;
}
if (socket_listen_in(&ctx->sock)) {
- E_STRERR("Could not listen on server socket");
+ E_STRERR("Could not listen on server socket on %s:%s", listen_addr, listen_port);
return 1;
}
@@ -141,7 +141,7 @@ pid_t jail_daemonize(int epoll_fd, jail_ctx *ctx[], size_t siz)
p = fork();
switch (p) {
case -1:
- W_STRERR("Jail daemonize");
+ W_STRERR("%s", "Jail daemonize");
return -1;
case 0:
N("%s", "Jail daemon mainloop");
@@ -182,8 +182,7 @@ static int jail_mainloop_epoll(int epoll_fd, jail_ctx *ctx[], size_t siz)
(events[i].events & EPOLLHUP) ||
(!(events[i].events & EPOLLIN)))
{
- E("Epoll for descriptor %d failed", events[i].data.fd);
- E_STRERR("epoll_wait");
+ E_STRERR("Epoll for descriptor %d", events[i].data.fd);
close(events[i].data.fd);
continue;
} else {
@@ -219,7 +218,8 @@ static int jail_accept_client(jail_ctx *ctx[],
args->newroot = ctx[i]->newroot;
if (socket_accept_in(&ctx[i]->sock, &args->client_psock)) {
- E_STRERR("Could not accept client connection");
+ E_STRERR("Could not accept client connection for fd %d",
+ args->client_psock.fd);
goto error;
}
@@ -261,53 +261,39 @@ static int jail_childfn(void *arg)
assert(arg);
args = (jail_prisoner_process *) arg;
- if (prctl(PR_SET_PDEATHSIG, SIGKILL) != 0) {
- E_STRERR("Jail child prctl");
- exit(EXIT_FAILURE);
- }
+ if (prctl(PR_SET_PDEATHSIG, SIGKILL) != 0)
+ FATAL("Jail child prctl for pid %d", args->prisoner_pid);
+ if (!args->newroot)
+ FATAL("New root set for pid %d", args->prisoner_pid);
- if (!args->newroot) {
- E2("%s", "No new root set");
- exit(EXIT_FAILURE);
- }
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);
}
- D2("Mounting rootfs to %s", args->newroot);
+ D2("Mounting rootfs to '%s'", args->newroot);
mount_root();
- D2("Mounting devtmpfs to %s%s", args->newroot, path_dev);
+ D2("Mounting devtmpfs to '%s%s'", args->newroot, path_dev);
s = mkdir(path_dev, S_IRUSR|S_IWUSR|S_IXUSR|
S_IRGRP|S_IXGRP|
S_IROTH|S_IXOTH);
- if (s && errno != EEXIST) {
- E2("Could not create directory: %s", path_dev);
- E_STRERR("mkdir");
- exit(EXIT_FAILURE);
- }
- 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);
- }
+ if (s && errno != EEXIST)
+ FATAL("Create directory '%s'", path_dev);
+ if (!dir_is_mountpoint(path_dev) && mount_dev(path_dev))
+ FATAL("Mount devtmpfs to '%s%s'", args->newroot, path_dev);
- D2("Mounting devpts to %s%s", args->newroot, path_devpts);
+ D2("Mounting devpts to '%s%s'", args->newroot, path_devpts);
s = mkdir(path_devpts, S_IRUSR|S_IWUSR|S_IXUSR|
S_IRGRP|S_IXGRP|
S_IROTH|S_IXOTH);
- if (s && errno != EEXIST) {
- E2("Could not create directory: %s", path_devpts);
- E_STRERR("mkdir");
- exit(EXIT_FAILURE);
- }
- if (!dir_is_mountpoint(path_devpts) && mount_pts(path_devpts)) {
- E2("Can not mount devpts to %s%s", args->newroot, path_devpts);
- exit(EXIT_FAILURE);
- }
+ if (s && errno != EEXIST)
+ FATAL("Create directory '%s'", path_devpts);
+ if (!dir_is_mountpoint(path_devpts) && mount_pts(path_devpts))
+ FATAL("Mount devpts to '%s%s'", args->newroot, path_devpts);
- D2("Creating device files in %s%s", args->newroot, path_dev);
+ 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);
@@ -318,12 +304,13 @@ static int jail_childfn(void *arg)
child_pid = forkpty(&term_fd, NULL, term, win);
switch (child_pid) {
case -1:
- W_STRERR("Forking a new pseudo terminal");
- break;
+ FATAL("Forking a new pseudo terminal for pid %d",
+ args->prisoner_pid);
+ break;
case 0:
D2("Executing '%s'", "/bin/bash");
if (execl("/bin(bash", "/bin/bash", (char *) NULL))
- W_STRERR("Execute a shell");
+ FATAL("Execute a shell for pid %d", args->prisoner_pid);
break;
default:
waitpid(child_pid, &s, 0);