From 16323dcc9df15020e368d4324cf1c1d9dceac805 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Mon, 20 Jun 2016 20:57:25 +0200 Subject: build: Change install directories and set correct permissions This sets the correct install directories for all the binaries, library and header files. It also sets the right permissions on the sockets and shared memory so that regular users can also use the ouroboros library. Root privileges are required to run the irmd. Fixes #7 --- src/irmd/main.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/irmd/main.c') diff --git a/src/irmd/main.c b/src/irmd/main.c index 7ad7a23a..68789e94 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -49,6 +49,7 @@ #include #include #include +#include #ifndef IRMD_MAX_FLOWS #define IRMD_MAX_FLOWS 4096 @@ -1571,11 +1572,13 @@ void * mainloop() static struct irm * irm_create() { + struct stat st = {0}; + struct irm * i = malloc(sizeof(*i)); if (i == NULL) return NULL; - if (access("/dev/shm/" SHM_DU_MAP_FILENAME, F_OK) != -1) { + if (access(INSTALL_DIR "dev/shm/" SHM_DU_MAP_FILENAME, F_OK) != -1) { struct shm_du_map * dum = shm_du_map_open(); if (dum == NULL) { LOG_ERR("Could not examine existing shm file."); @@ -1592,6 +1595,11 @@ static struct irm * irm_create() } } + if (rw_lock_init(&i->state_lock)) { + irm_destroy(i); + return NULL; + } + i->threadpool = malloc(sizeof(pthread_t) * IRMD_THREADPOOL_SIZE); if (i->threadpool == NULL) { irm_destroy(i); @@ -1613,13 +1621,22 @@ static struct irm * irm_create() return NULL; } + if (stat(SOCK_PATH, &st) == -1) { + if (mkdir(SOCK_PATH, 0777)) { + LOG_ERR("Failed to create sockets directory."); + irm_destroy(i); + return NULL; + } + } + i->sockfd = server_socket_open(IRM_SOCK_PATH); if (i->sockfd < 0) { irm_destroy(i); return NULL; } - if (rw_lock_init(&i->state_lock)) { + if (chmod(IRM_SOCK_PATH, 0666)) { + LOG_ERR("Failed to chmod socket."); irm_destroy(i); return NULL; } @@ -1643,6 +1660,11 @@ int main() int t = 0; + if (geteuid() != 0) { + LOG_ERR("IPC Resource Manager must be run as root."); + exit(EXIT_FAILURE); + } + /* init sig_act */ memset(&sig_act, 0, sizeof sig_act); @@ -1661,7 +1683,7 @@ int main() instance = irm_create(); if (instance == NULL) - return 1; + exit(EXIT_FAILURE); pthread_create(&instance->cleanup_flows, NULL, irm_flow_cleaner, NULL); -- cgit v1.2.3 From 550cfa775b048abe183c4fdcc8ada8476e562185 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Mon, 20 Jun 2016 21:53:42 +0200 Subject: lib, irmd: Change sockets and shm path Reverting from previous commit. Even when running Ouroboros sandboxed, the sockets and shared memory should be created in the default system paths. --- include/ouroboros/sockets.h | 2 +- src/irmd/main.c | 4 +++- src/lib/ipcp.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/irmd/main.c') diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h index b765b55b..0a215a76 100644 --- a/include/ouroboros/sockets.h +++ b/include/ouroboros/sockets.h @@ -36,7 +36,7 @@ typedef IrmMsg irm_msg_t; #include "ipcpd_messages.pb-c.h" typedef IpcpMsg ipcp_msg_t; -#define SOCK_PATH INSTALL_DIR "var/run/ouroboros/" +#define SOCK_PATH "/var/run/ouroboros/" #define SOCK_PATH_SUFFIX ".sock" #define IRM_SOCK_PATH SOCK_PATH "irm" SOCK_PATH_SUFFIX diff --git a/src/irmd/main.c b/src/irmd/main.c index 68789e94..5f7c1ddc 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1578,12 +1578,14 @@ static struct irm * irm_create() if (i == NULL) return NULL; - if (access(INSTALL_DIR "dev/shm/" SHM_DU_MAP_FILENAME, F_OK) != -1) { + if (access("/dev/shm/" SHM_DU_MAP_FILENAME, F_OK) != -1) { struct shm_du_map * dum = shm_du_map_open(); + if (dum == NULL) { LOG_ERR("Could not examine existing shm file."); exit(EXIT_FAILURE); } + if (kill(shm_du_map_owner(dum), 0) < 0) { LOG_INFO("IRMd didn't properly shut down last time."); shm_du_map_destroy(dum); diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index fcaf9f83..a43afd21 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -109,7 +109,7 @@ pid_t ipcp_create(char * ipcp_name, char * full_name = NULL; char * exec_name = NULL; - sprintf (irmd_pid, "%u", getpid()); + sprintf(irmd_pid, "%u", getpid()); pid = fork(); if (pid == -1) { -- cgit v1.2.3