ctdb-event: Force symbolic link targets to be absolute
authorMartin Schwenke <martin@meltin.net>
Fri, 7 Sep 2018 04:47:24 +0000 (14:47 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Tue, 18 Dec 2018 02:36:47 +0000 (13:36 +1100)
If CTDB_BASE is relative then symbolic link targets will be incorrect.

Don't force CTDB_BASE to be absolute because this can result in Unix
domain socket names that are too long.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/event/event_tool.c

index b597279..6cc5dc9 100644 (file)
@@ -308,6 +308,7 @@ static int event_command_script_list(TALLOC_CTX *mem_ctx,
        char *subdir = NULL;
        char *data_dir = NULL;
        char *etc_dir = NULL;
+       char *t = NULL;
        struct event_script_list *data_list = NULL;
        struct event_script_list *etc_list = NULL;
        unsigned int i, j, matched;
@@ -328,6 +329,20 @@ static int event_command_script_list(TALLOC_CTX *mem_ctx,
                return ENOMEM;
        }
 
+       t = talloc_size(mem_ctx, PATH_MAX);
+       if (t == NULL) {
+               return ENOMEM;
+       }
+
+       data_dir = realpath(data_dir, t);
+       if (data_dir == NULL) {
+               if (errno != ENOENT) {
+                       return errno;
+               }
+               D_ERR("Command script list finished with result=%d\n", ENOENT);
+               return ENOENT;
+       }
+
        etc_dir = path_etcdir_append(mem_ctx, subdir);
        if (etc_dir == NULL) {
                return ENOMEM;
@@ -550,6 +565,7 @@ static int event_command_script_enable(TALLOC_CTX *mem_ctx,
                return EINVAL;
        } else {
                if (errno == ENOENT) {
+                       char *t;
                        char *data_script;
 
                        data_script = path_datadir_append(mem_ctx, script);
@@ -557,6 +573,22 @@ static int event_command_script_enable(TALLOC_CTX *mem_ctx,
                                return ENOMEM;
                        }
 
+                       t = talloc_size(mem_ctx, PATH_MAX);
+                       if (t == NULL) {
+                               return ENOMEM;
+                       }
+
+                       data_script = realpath(data_script, t);
+                       if (data_script == NULL) {
+                               if (errno != ENOENT) {
+                                       return errno;
+                               }
+                               printf("Script %s does not exist in %s\n",
+                                      argv[1],
+                                      argv[0]);
+                               return ENOENT;
+                       }
+
                        ret = stat(data_script, &statbuf);
                        if (ret != 0) {
                                printf("Script %s does not exist in %s\n",