diff options
author | Sander Vrijders <[email protected]> | 2016-07-05 15:47:23 +0200 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2016-07-05 15:47:23 +0200 |
commit | 63510348c9dd72e0f1d9146cfb90f88adb34e1eb (patch) | |
tree | b737bcdcedec9ce16487c2aa931aaf5c620f28ad | |
parent | a315150a16c02f3cb694e639d5aba555fce4b4c3 (diff) | |
parent | 656db09805cbff0b6af3c34f611b710116df4b82 (diff) | |
download | ouroboros-63510348c9dd72e0f1d9146cfb90f88adb34e1eb.tar.gz ouroboros-63510348c9dd72e0f1d9146cfb90f88adb34e1eb.zip |
Merge remote-tracking branch 'upstream/be' into be
-rw-r--r-- | src/ipcpd/ipcp-data.c | 5 | ||||
-rw-r--r-- | src/irmd/main.c | 7 | ||||
-rw-r--r-- | src/lib/irm.c | 96 | ||||
-rw-r--r-- | src/lib/utils.c | 19 |
4 files changed, 100 insertions, 27 deletions
diff --git a/src/ipcpd/ipcp-data.c b/src/ipcpd/ipcp-data.c index 76fc4bcd..8dc708b2 100644 --- a/src/ipcpd/ipcp-data.c +++ b/src/ipcpd/ipcp-data.c @@ -21,15 +21,16 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "ipcp-data.h" +#include <ouroboros/config.h> #include <ouroboros/shm_du_map.h> #include <ouroboros/list.h> -#include <ouroboros/utils.h> #define OUROBOROS_PREFIX "ipcp-utils" #include <ouroboros/logs.h> +#include "ipcp-data.h" + #include <string.h> #include <stdlib.h> diff --git a/src/irmd/main.c b/src/irmd/main.c index 0d23ec58..2ea59eee 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1103,6 +1103,8 @@ static int bind_name(char * name, pthread_rwlock_unlock(&instance->reg_lock); pthread_rwlock_unlock(&instance->state_lock); + LOG_INFO("Bound %s to registered name %s.", ap_name, name); + return 0; } @@ -1142,6 +1144,8 @@ static int unbind_name(char * name, pthread_rwlock_unlock(&instance->reg_lock); pthread_rwlock_unlock(&instance->state_lock); + LOG_INFO("Removed binding from %s to %s.", ap_name, name); + return 0; } @@ -1280,6 +1284,9 @@ static int ap_unreg(char * name, "%s in DIF %s.", rne->name, e->dif_name); --ret; + } else { + LOG_INFO("Unregistered %s from %s.", + rne->name, e->dif_name); } } } diff --git a/src/lib/irm.c b/src/lib/irm.c index da3cfb62..ca2111ca 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -22,6 +22,7 @@ #define OUROBOROS_PREFIX "libouroboros-irm" +#include <ouroboros/config.h> #include <ouroboros/errno.h> #include <ouroboros/irm.h> #include <ouroboros/common.h> @@ -29,6 +30,7 @@ #include <ouroboros/sockets.h> #include <stdbool.h> +#include <string.h> #include <stdlib.h> #include <sys/stat.h> @@ -239,6 +241,84 @@ int irm_enroll_ipcp(pid_t api, return ret; } +static int check_ap(char * ap_name) +{ + struct stat s; + + if (stat(ap_name, &s) != 0) + return -ENOENT; + + if (!(s.st_mode & S_IXUSR)) + return -EPERM; + + return 0; +} + +static int check_ap_path(char ** ap_name) +{ + char * path = getenv("PATH"); + char * path_end = path + strlen(path) + 1; + char * pstart; + char * pstop = path; + char * tmp; + char * tstop; + char * tstart; + bool perm = true; + int ret = 0; + + if (*ap_name == NULL || path == NULL) + return -EINVAL; + + if (!strlen(path) || strchr(*ap_name, '/') == NULL) + if ((ret = check_ap(*ap_name)) < 0) + return ret; + + tmp = malloc(strlen(path) + strlen(*ap_name) + 2); + if (tmp == NULL) + return -ENOMEM; + + tstop = tmp + strlen(path) + 1; + strcpy(tstop--, *ap_name); + + while (pstop < path_end) { + ret = 0; + pstart = pstop; + if (*pstart != '/') { + free(tmp); + return -EINVAL; + } + + while (*pstop != '\0' && *pstop != ':') + pstop++; + + *pstop = '\0'; + tstart = tstop - (pstop++ - pstart); + strcpy(tstart, pstart); + *tstop = '/'; + + if ((ret = check_ap(tstart)) < 0) { + if (ret == -EPERM) + perm = false; + continue; + } + + free(*ap_name); + *ap_name = strdup(tstart); + free(tmp); + + if (*ap_name == NULL) + return -ENOMEM; + + return 0; + } + + free(tmp); + if (!perm) + return -EPERM; + + return -ENOENT; +} + int irm_bind(char * name, char * ap_name, uint16_t opts, @@ -248,20 +328,23 @@ int irm_bind(char * name, irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; int ret = -1; - struct stat s; + char * full_ap_name; if (name == NULL || ap_name == NULL) return -EINVAL; - if (stat(ap_name, &s) != 0) - return -ENOENT; + full_ap_name = strdup(ap_name); + if (full_ap_name == NULL) + return -ENOMEM; - if (!(s.st_mode & S_IXUSR)) - return -EPERM; + if ((ret = check_ap_path(&full_ap_name)) < 0) { + free(full_ap_name); + return ret; + } msg.code = IRM_MSG_CODE__IRM_BIND; msg.dst_name = name; - msg.ap_name = ap_name; + msg.ap_name = full_ap_name; if (argv != NULL) { msg.n_args = argc; @@ -283,6 +366,7 @@ int irm_bind(char * name, ret = recv_msg->result; irm_msg__free_unpacked(recv_msg, NULL); + free(full_ap_name); return ret; } diff --git a/src/lib/utils.c b/src/lib/utils.c index 49065138..acaf1176 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -35,25 +35,6 @@ int n_digits(unsigned i) return n; } -char * strdup(const char * src) -{ - int len = 0; - char * dst = NULL; - - if (src == NULL) - return NULL; - - len = strlen(src) + 1; - - dst = malloc(len); - if (dst == NULL) - return NULL; - - memcpy(dst, src, len); - - return dst; -} - char * path_strip(char * src) { char * dst = NULL; |