afb-session: remove initial token 54/23154/1
authorJose Bollo <jose.bollo@iot.bzh>
Mon, 18 Nov 2019 16:10:53 +0000 (17:10 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 29 Nov 2019 11:48:17 +0000 (12:48 +0100)
Tokens are no more managed by the binder.

Bug-AGL: SPEC-2968

Change-Id: Idf1c38105f8ede82cd0ed43aeae3e8e69b9845a3
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
src/afb-session.c
src/afb-session.h
src/main-afb-daemon.c
src/main-afs-supervisor.c
src/tests/session/test-session.c

index 8addd7e..3be3f6d 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "afb-session.h"
 #include "afb-hook.h"
-#include "afb-token.h"
 #include "verbose.h"
 #include "pearson.h"
 #include "uuid.h"
@@ -90,7 +89,6 @@ static struct {
        uint16_t genid;         /**< for generating ids */
        int timeout;            /**< common initial timeout */
        struct afb_session *first; /**< sessions */
-       struct afb_token *initok;/**< common initial token */
        pthread_mutex_t mutex;  /**< declare a mutex to protect hash table */
 } sessions = {
        .count = 0,
@@ -98,7 +96,6 @@ static struct {
        .genid = 1,
        .timeout = 3600,
        .first = 0,
-       .initok = 0,
        .mutex = PTHREAD_MUTEX_INITIALIZER
 };
 
@@ -326,25 +323,13 @@ static time_t sessionset_cleanup (int force)
 
 /**
  * Initialize the session manager with a 'max_session_count',
- * an initial common 'timeout' and an initial common token 'initok'.
+ * an initial common 'timeout'
  *
  * @param max_session_count  maximum allowed session count in the same time
  * @param timeout            the initial default timeout of sessions
- * @param initok             the initial default token of sessions
  */
-int afb_session_init (int max_session_count, int timeout, const char *initok)
+int afb_session_init (int max_session_count, int timeout)
 {
-       int rc;
-       uuid_stringz_t uuid;
-
-       /* check parameters */
-       if (initok && strlen(initok) >= sizeof sessions.initok) {
-               ERROR("initial token '%s' too long (max length %d)",
-                       initok, ((int)(sizeof sessions.initok)) - 1);
-               errno = EINVAL;
-               return -1;
-       }
-
        /* init the sessionset (after cleanup) */
        sessionset_lock();
        sessionset_cleanup(1);
@@ -355,16 +340,6 @@ int afb_session_init (int max_session_count, int timeout, const char *initok)
        else
                sessions.max = (uint16_t)max_session_count;
        sessions.timeout = timeout;
-       if (initok == NULL) {
-               uuid_new_stringz(uuid);
-               initok = uuid;
-       }
-       sessions.initok = 0;
-       if (*initok) {
-               rc = afb_token_get(&sessions.initok, initok);
-               if (rc < 0)
-                       return rc;
-       }
        sessionset_unlock();
        return 0;
 }
@@ -398,14 +373,6 @@ void afb_session_purge()
        sessionset_unlock();
 }
 
-/**
- * @return the initial token set at initialization
- */
-const char *afb_session_initial_token()
-{
-       return sessions.initok ? afb_token_string(sessions.initok) : "";
-}
-
 /* Searchs the session of 'uuid' */
 struct afb_session *afb_session_search (const char *uuid)
 {
index bd1c47c..4837c49 100644 (file)
@@ -23,9 +23,8 @@ struct afb_session;
 #define AFB_SESSION_TIMEOUT_DEFAULT   -2
 #define AFB_SESSION_TIMEOUT_IS_VALID(x) ((x) >= AFB_SESSION_TIMEOUT_DEFAULT)
 
-extern int afb_session_init(int max_session_count, int timeout, const char *initok);
+extern int afb_session_init(int max_session_count, int timeout);
 extern void afb_session_purge();
-extern const char *afb_session_initial_token();
 extern void afb_session_foreach(void (*callback)(void *closure, struct afb_session *session), void *closure);
 
 extern struct afb_session *afb_session_create (int timeout);
index 165d140..077c716 100644 (file)
@@ -544,7 +544,7 @@ static char **instanciate_command_args(struct json_object *exec, const char *por
 
 static int execute_command()
 {
-       struct json_object *exec, *oport;
+       struct json_object *exec, *oport, *otok;
        struct sigaction siga;
        char port[20];
        const char *token;
@@ -579,7 +579,10 @@ static int execute_command()
        }
        else {
                /* instantiate arguments and environment */
-               token = afb_session_initial_token();
+               if (json_object_object_get_ex(main_config, "token", &otok))
+                       token = json_object_get_string(otok);
+               else
+                       token = SUBST_STR"p";
                args = instanciate_command_args(exec, port, token);
                if (args && instanciate_environ(port, token) >= 0) {
                        /* run */
@@ -769,7 +772,7 @@ static void start(int signum, void *arg)
        }
 
        /* initialize session handling */
-       if (afb_session_init(max_session_count, session_timeout, token)) {
+       if (afb_session_init(max_session_count, session_timeout)) {
                ERROR("initialisation of session manager failed");
                goto error;
        }
@@ -801,7 +804,7 @@ static void start(int signum, void *arg)
                        goto error;
                }
                if (addenv_int("AFB_PORT", http_port)
-                || addenv("AFB_TOKEN", afb_session_initial_token())) {
+                || addenv("AFB_TOKEN", token?:"")) {
                        ERROR("can't set HTTP environment");
                        goto error;
                }
@@ -894,7 +897,7 @@ static void start(int signum, void *arg)
 
        /* run the command */
        afb_debug("start-exec");
-       if (execute_command() < 0)
+       if (execute_command(http_port, token) < 0)
                goto error;
 
        /* ready */
index e56e1d8..d0c52e3 100644 (file)
@@ -144,7 +144,7 @@ static void start(int signum, void *arg)
        }
 
        /* configure the daemon */
-       if (afb_session_init(main_config->nbSessionMax, main_config->cntxTimeout, main_config->token)) {
+       if (afb_session_init(main_config->nbSessionMax, main_config->cntxTimeout)) {
                ERROR("initialisation of session manager failed");
                goto error;
        }
index 5352c6e..c630cb6 100644 (file)
 /* check the initialisation */
 START_TEST (check_initialisation)
 {
-       ck_assert_int_eq(0, afb_session_init(0, 0, NULL));
-       ck_assert_int_eq(0, afb_session_init(200, 0, NULL));
-       ck_assert_int_eq(0, afb_session_init(10, 0, GOOD_UUID));
-       ck_assert_str_eq(GOOD_UUID, afb_session_initial_token());
-       ck_assert_int_eq(-1, afb_session_init(10, 0, BAD_UUID));
-       ck_assert_int_eq(errno, EINVAL);
+       ck_assert_int_eq(0, afb_session_init(0, 0));
+       ck_assert_int_eq(0, afb_session_init(200, 0));
 }
 END_TEST
 
@@ -45,7 +41,7 @@ START_TEST (check_creation)
        struct afb_session *s, *x;
 
        /* init */
-       ck_assert_int_eq(0, afb_session_init(10, 3600, GOOD_UUID));
+       ck_assert_int_eq(0, afb_session_init(10, 3600));
 
        /* create a session */
        s = afb_session_create(AFB_SESSION_TIMEOUT_DEFAULT);
@@ -83,7 +79,7 @@ END_TEST
 START_TEST (check_capacity)
 {
        struct afb_session *s[3];
-       ck_assert_int_eq(0, afb_session_init(2, 3600, GOOD_UUID));
+       ck_assert_int_eq(0, afb_session_init(2, 3600));
        s[0] = afb_session_create(AFB_SESSION_TIMEOUT_DEFAULT);
        ck_assert(s[0]);
        s[1] = afb_session_create(AFB_SESSION_TIMEOUT_DEFAULT);
@@ -124,7 +120,7 @@ START_TEST (check_cookies)
        int i, j;
 
        /* init */
-       ck_assert_int_eq(0, afb_session_init(10, 3600, GOOD_UUID));
+       ck_assert_int_eq(0, afb_session_init(10, 3600));
 
        /* create a session */
        s = afb_session_create(AFB_SESSION_TIMEOUT_DEFAULT);
@@ -235,7 +231,7 @@ START_TEST (check_hooking)
        struct afb_session *s;
 
        /* init */
-       ck_assert_int_eq(0, afb_session_init(10, 3600, GOOD_UUID));
+       ck_assert_int_eq(0, afb_session_init(10, 3600));
 
        /* create the hooking */
        hs = afb_hook_create_session(NULL, afb_hook_flags_session_all, &hookitf, NULL);