Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ AC_PROG_CC
PKG_CHECK_MODULES([YAJL], [yajl >= 2.0.0])
PKG_CHECK_MODULES([SELINUX], [libselinux >= 2.0.0])

AC_MSG_CHECKING([whether to disable argument checking])
AC_ARG_ENABLE([args], AS_HELP_STRING([--disable-args], [disable checking that cmd args are either init/systemd]))
AS_IF([test "x$enable_args" != "xno"], [AC_DEFINE([ARGS_CHECK], [1], [enable checking arguments])])

AC_CONFIG_FILES(Makefile)
AC_OUTPUT
23 changes: 21 additions & 2 deletions src/systemdhook.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <selinux/selinux.h>
#include <yajl/yajl_tree.h>

#include "config.h"

#define _cleanup_(x) __attribute__((cleanup(x)))

static inline void freep(void *p) {
Expand Down Expand Up @@ -47,6 +49,7 @@ static inline void fclosep(FILE **fp) {
DEFINE_CLEANUP_FUNC(yajl_val, yajl_tree_free)

#define pr_perror(fmt, ...) syslog(LOG_ERR, "systemdhook: " fmt ": %m\n", ##__VA_ARGS__)
#define pr_pinfo(fmt, ...) syslog(LOG_INFO, "systemdhook: " fmt ": %m\n", ##__VA_ARGS__)

#define BUFLEN 1024
#define CONFIGSZ 65536
Expand All @@ -69,7 +72,7 @@ static int makepath(char *dir, mode_t mode)
bool contains_mount(const char **config_mounts, unsigned len, const char *mount) {
for (unsigned i = 0; i < len; i++) {
if (!strcmp(mount, config_mounts[i])) {
fprintf(stdout, "%s already present as a mount point in container configuration, skipping\n", mount);
pr_pinfo("%s already present as a mount point in container configuration, skipping\n", mount);
return true;
}
}
Expand Down Expand Up @@ -358,6 +361,22 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}

#ifdef ARGS_CHECK
const char *cmd_path[] = { "Path", (const char *)0 };
yajl_val v_cmd = yajl_tree_get(config_node, cmd_path, yajl_t_string);
if (!v_cmd) {
pr_perror("Path not found in config\n");
return EXIT_FAILURE;
}
char *cmd = YAJL_GET_STRING(v_cmd);

char *cmd_file_name = basename(cmd);
if (strcmp("init", cmd_file_name) && strcmp("systemd", cmd_file_name)) {
pr_pinfo("Skipping as container command is %s, not init or systemd\n", cmd);
return EXIT_SUCCESS;
}
#endif

/* Extract values from the config json */
const char *mount_label_path[] = { "MountLabel", (const char *)0 };
yajl_val v_mount = yajl_tree_get(config_node, mount_label_path, yajl_t_string);
Expand All @@ -367,7 +386,7 @@ int main(int argc, char *argv[])
}
char *mount_label = YAJL_GET_STRING(v_mount);

fprintf(stdout, "Mount Label parsed as: %s\n", mount_label);
pr_pinfo("Mount Label parsed as: %s\n", mount_label);

/* Extract values from the config json */
const char *mount_points_path[] = { "MountPoints", (const char *)0 };
Expand Down