CMakeLists.txt: bump minimum cmake version
[project/ubus.git] / ubusd_acl.c
index e426a4af95efaf1e610bf640013dd8b7978ec015..352c581c3d38b23c76ae520e66f1698e542b3e76 100644 (file)
@@ -26,6 +26,7 @@
 #include <libubox/vlist.h>
 #include <libubox/blobmsg_json.h>
 #include <libubox/avl-cmp.h>
+#include <libubox/ulog.h>
 
 #include "ubusd.h"
 
@@ -147,12 +148,16 @@ ubusd_acl_check(struct ubus_client *cl, const char *obj,
                case UBUS_ACL_ACCESS:
                        if (acl->methods) {
                                struct blob_attr *cur;
+                               char *cur_method;
                                size_t rem;
 
                                blobmsg_for_each_attr(cur, acl->methods, rem)
-                                       if (blobmsg_type(cur) == BLOBMSG_TYPE_STRING)
-                                               if (!strcmp(method, blobmsg_get_string(cur)))
+                                       if (blobmsg_type(cur) == BLOBMSG_TYPE_STRING) {
+                                               cur_method = blobmsg_get_string(cur);
+
+                                               if (!strcmp(method, cur_method) || !strcmp("*", cur_method))
                                                        return 0;
+                                       }
                        }
                        break;
                }
@@ -171,19 +176,25 @@ ubusd_acl_init_client(struct ubus_client *cl, int fd)
 #ifdef SO_PEERCRED
        unsigned int len = sizeof(struct ucred);
 
-       if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1)
+       if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1) {
+               ULOG_ERR("Failed getsockopt(): %m\n");
                return -1;
+       }
 #else
        memset(&cred, 0, sizeof(cred));
 #endif
 
        pwd = getpwuid(cred.uid);
-       if (!pwd)
+       if (!pwd) {
+               ULOG_ERR("Failed getpwuid(): %m\n");
                return -1;
+       }
 
        group = getgrgid(cred.gid);
-       if (!group)
+       if (!group) {
+               ULOG_ERR("Failed getgrgid(): %m\n");
                return -1;
+       }
 
        cl->uid = cred.uid;
        cl->gid = cred.gid;