ubus: Support static builds
[project/ubus.git] / ubusd_event.c
index 0469c20aed590f7b3757e4fbb2485a23794a8aa9..712e7049946a88acba0207ce72ed0fc78653ec05 100644 (file)
@@ -88,6 +88,9 @@ static int ubusd_alloc_event_pattern(struct ubus_client *cl, struct blob_attr *m
                len--;
        }
 
+       if (pattern[0] && ubusd_acl_check(cl, pattern, NULL, UBUS_ACL_LISTEN))
+               return UBUS_STATUS_PERMISSION_DENIED;
+
        ev = calloc(1, sizeof(*ev) + len + 1);
        if (!ev)
                return UBUS_STATUS_NO_DATA;
@@ -132,15 +135,6 @@ static void ubusd_send_event_msg(struct ubus_msg_buf **ub, struct ubus_client *c
        ubus_msg_send(obj->client, *ub);
 }
 
-static bool strmatch_len(const char *s1, const char *s2, int *len)
-{
-       for (*len = 0; s1[*len] == s2[*len]; (*len)++)
-               if (!s1[*len])
-                       return true;
-
-       return false;
-}
-
 int ubusd_send_event(struct ubus_client *cl, const char *id,
                     event_fill_cb fill_cb, void *cb_priv)
 {
@@ -148,6 +142,9 @@ int ubusd_send_event(struct ubus_client *cl, const char *id,
        struct event_source *ev;
        int match_len = 0;
 
+       if (ubusd_acl_check(cl, id, NULL, UBUS_ACL_SEND))
+               return UBUS_STATUS_PERMISSION_DENIED;
+
        obj_event_seq++;
 
        /*
@@ -160,7 +157,7 @@ int ubusd_send_event(struct ubus_client *cl, const char *id,
                int cur_match_len;
                bool full_match;
 
-               full_match = strmatch_len(id, key, &cur_match_len);
+               full_match = ubus_strmatch_len(id, key, &cur_match_len);
                if (cur_match_len < match_len)
                        break;