afb-api: Enforce api names to be hookable
authorJosé Bollo <jose.bollo@iot.bzh>
Wed, 31 Jan 2018 13:52:08 +0000 (14:52 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Wed, 31 Jan 2018 13:57:21 +0000 (14:57 +0100)
Change-Id: Ic1d5cb208c636d3261e1a96c4a81b488cb84a60e
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-api-dbus.c
src/afb-api-so-v1.c
src/afb-api-so-v2.c
src/afb-api-ws.c
src/afb-api.c
src/afb-api.h
src/afb-export.c

index c66426e..ad640fb 100644 (file)
@@ -113,7 +113,7 @@ static struct api_dbus *make_api_dbus_3(int system, const char *path, size_t pat
                goto error2;
        }
        api->api++;
-       if (!afb_api_is_valid_name(api->api)) {
+       if (!afb_api_is_valid_name(api->api, 1)) {
                errno = EINVAL;
                goto error2;
        }
index 9a9e47a..c77ab72 100644 (file)
@@ -239,7 +239,7 @@ int afb_api_so_v1_add(const char *path, void *handle, struct afb_apiset *apiset)
                ERROR("binding [%s] bad prefix...", path);
                goto error;
        }
-       if (!afb_api_is_valid_name(desc->binding->v1.prefix)) {
+       if (!afb_api_is_valid_name(desc->binding->v1.prefix, 1)) {
                ERROR("binding [%s] invalid prefix...", path);
                goto error;
        }
index ba53223..5954eb1 100644 (file)
@@ -230,7 +230,7 @@ int afb_api_so_v2_add(const char *path, void *handle, struct afb_apiset *apiset)
                ERROR("binding [%s] bad api name...", path);
                goto error;
        }
-       if (!afb_api_is_valid_name(binding->api)) {
+       if (!afb_api_is_valid_name(binding->api, 1)) {
                ERROR("binding [%s] invalid api name...", path);
                goto error;
        }
index 1a46358..0e4d1d0 100644 (file)
@@ -73,7 +73,7 @@ static struct api_ws *api_ws_make(const char *path)
        while (length && path[length - 1] != '/' && path[length - 1] != ':')
                length = length - 1;
        api->api = &api->path[length];
-       if (api->api == NULL || !afb_api_is_valid_name(api->api)) {
+       if (api->api == NULL || !afb_api_is_valid_name(api->api, 1)) {
                errno = EINVAL;
                goto error2;
        }
index 38ec4f2..7c4598d 100644 (file)
@@ -29,7 +29,7 @@
  * Checks wether 'name' is a valid API name.
  * @return 1 if valid, 0 otherwise
  */
-int afb_api_is_valid_name(const char *name)
+int afb_api_is_valid_name(const char *name, int hookable)
 {
        unsigned char c;
 
@@ -60,6 +60,6 @@ int afb_api_is_valid_name(const char *name)
                }
                c = (unsigned char)*++name;
        } while(c != 0);
-       return 1;
+       return !hookable || afb_api_is_hookable(name);
 }
 
index a9de843..ff1bc10 100644 (file)
@@ -38,7 +38,7 @@ struct afb_api
        const void *group;
 };
 
-extern int afb_api_is_valid_name(const char *name);
+extern int afb_api_is_valid_name(const char *name, int hookable);
 
 #define AFB_API_UNHOOKABLE_PREFIX_CHAR    '$'
 #define AFB_API_UNHOOKABLE_PREFIX_STRING  "$"
index 304395a..98964bf 100644 (file)
@@ -241,7 +241,7 @@ static int rename_api_cb(void *closure, const char *name)
                errno = EINVAL;
                return -1;
        }
-       if (!afb_api_is_valid_name(name)) {
+       if (!afb_api_is_valid_name(name, 1)) {
                ERROR("[API %s] Can't rename to %s: bad API name", export->apiname, name);
                errno = EINVAL;
                return -1;