aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/afb-session.c37
-rw-r--r--src/afb-session.h3
-rw-r--r--src/main-afb-daemon.c13
-rw-r--r--src/main-afs-supervisor.c2
-rw-r--r--src/tests/session/test-session.c16
5 files changed, 18 insertions, 53 deletions
diff --git a/src/afb-session.c b/src/afb-session.c
index 8addd7eb..3be3f6da 100644
--- a/src/afb-session.c
+++ b/src/afb-session.c
@@ -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)
{
diff --git a/src/afb-session.h b/src/afb-session.h
index bd1c47c7..4837c494 100644
--- a/src/afb-session.h
+++ b/src/afb-session.h
@@ -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);
diff --git a/src/main-afb-daemon.c b/src/main-afb-daemon.c
index 165d1400..077c7163 100644
--- a/src/main-afb-daemon.c
+++ b/src/main-afb-daemon.c
@@ -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 */
diff --git a/src/main-afs-supervisor.c b/src/main-afs-supervisor.c
index e56e1d86..d0c52e37 100644
--- a/src/main-afs-supervisor.c
+++ b/src/main-afs-supervisor.c
@@ -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;
}
diff --git a/src/tests/session/test-session.c b/src/tests/session/test-session.c
index 5352c6ee..c630cb6f 100644
--- a/src/tests/session/test-session.c
+++ b/src/tests/session/test-session.c
@@ -16,12 +16,8 @@
/* 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);