ubusd: make ACL path configurable on the command line
authorFelix Fietkau <nbd@openwrt.org>
Wed, 9 Dec 2015 16:44:00 +0000 (17:44 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Wed, 9 Dec 2015 16:44:00 +0000 (17:44 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
ubusd.c
ubusd.h
ubusd_acl.c

diff --git a/ubusd.c b/ubusd.c
index 6629720..f1f8ac7 100644 (file)
--- a/ubusd.c
+++ b/ubusd.c
@@ -356,6 +356,7 @@ static int usage(const char *progname)
 {
        fprintf(stderr, "Usage: %s [<options>]\n"
                "Options: \n"
+               "  -A <path>:           Set the path to ACL files\n"
                "  -s <socket>:         Set the unix domain socket to listen on\n"
                "\n", progname);
        return 1;
@@ -378,11 +379,14 @@ int main(int argc, char **argv)
        openlog("ubusd", LOG_PID, LOG_DAEMON);
        uloop_init();
 
-       while ((ch = getopt(argc, argv, "s:")) != -1) {
+       while ((ch = getopt(argc, argv, "A:s:")) != -1) {
                switch (ch) {
                case 's':
                        ubus_socket = optarg;
                        break;
+               case 'A':
+                       ubusd_acl_dir = optarg;
+                       break;
                default:
                        return usage(argv[0]);
                }
diff --git a/ubusd.h b/ubusd.h
index 6078e02..5031ed4 100644 (file)
--- a/ubusd.h
+++ b/ubusd.h
@@ -64,6 +64,8 @@ struct ubus_path {
        const char name[];
 };
 
+extern const char *ubusd_acl_dir;
+
 struct ubus_msg_buf *ubus_msg_new(void *data, int len, bool shared);
 void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free);
 void ubus_msg_free(struct ubus_msg_buf *ub);
index e5a7b56..dbfa83a 100644 (file)
@@ -62,6 +62,7 @@ struct ubusd_acl_file {
        int ok;
 };
 
+const char *ubusd_acl_dir = "/usr/share/acl.d";
 static struct blob_buf bbuf;
 static struct avl_tree ubusd_acls;
 static int ubusd_acl_seq;
@@ -379,8 +380,11 @@ ubusd_acl_load(void)
        struct stat st;
        glob_t gl;
        int j;
+       const char *suffix = "/*.json";
+       char *path = alloca(strlen(ubusd_acl_dir) + strlen(suffix) + 1);
 
-       if (glob("/usr/share/acl.d/*.json", GLOB_NOESCAPE | GLOB_MARK, NULL, &gl))
+       sprintf(path, "%s%s", ubusd_acl_dir, suffix);
+       if (glob(path, GLOB_NOESCAPE | GLOB_MARK, NULL, &gl))
                return;
 
        vlist_update(&ubusd_acl_files);