From 3288b156225043ccb5c4d90352d52364c1aca8b7 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 7 Oct 2014 10:29:59 +1100 Subject: [PATCH] Parse new auth command from ckdb --- src/ckpool.c | 2 +- src/ckpool.h | 1 + src/stratifier.c | 26 +++++++++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index b350291d..620cd925 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -851,7 +851,7 @@ static void sighandler(int sig) exit(0); } -static void json_get_string(char **store, json_t *val, const char *res) +void json_get_string(char **store, json_t *val, const char *res) { json_t *entry = json_object_get(val, res); const char *buf; diff --git a/src/ckpool.h b/src/ckpool.h index 9e3311cb..f5e6aa2b 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -199,5 +199,6 @@ char *_ckdb_msg_call(const ckpool_t *ckp, char *msg, const char *file, const ch json_t *json_rpc_call(connsock_t *cs, const char *rpc_req); int process_exit(ckpool_t *ckp, proc_instance_t *pi, int ret); +void json_get_string(char **store, json_t *val, const char *res); #endif /* CKPOOL_H */ diff --git a/src/stratifier.c b/src/stratifier.c index 139c8912..bb431c57 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1588,20 +1588,32 @@ static int send_recv_auth(stratum_instance_t *client) free(json_msg); if (likely(buf)) { - char *secondaryuserid, response[PAGESIZE] = {}; + char *cmd = NULL, *secondaryuserid = NULL; + char response[PAGESIZE] = {}; + json_error_t err_val; + json_t *val = NULL; LOGINFO("Got ckdb response: %s", buf); sscanf(buf, "id.%*d.%s", response); - secondaryuserid = response; - strsep(&secondaryuserid, "."); - LOGINFO("User %s Worker %s got auth response: %s suid: %s", + cmd = response; + strsep(&cmd, "="); + LOGINFO("User %s Worker %s got auth response: %s cmd: %s", user_instance->username, client->workername, - response, secondaryuserid); - if (!safecmp(response, "ok") && secondaryuserid) { + response, cmd); + val = json_loads(cmd, 0, &err_val); + if (unlikely(!val)) + LOGWARNING("AUTH JSON decode failed(%d): %s", err_val.line, err_val.text); + else + json_get_string(&secondaryuserid, val, "secondaryuserid"); + if (!safecmp(response, "ok.auth") && secondaryuserid) { if (!user_instance->secondaryuserid) - user_instance->secondaryuserid = strdup(secondaryuserid); + user_instance->secondaryuserid = secondaryuserid; + else + dealloc(secondaryuserid); ret = 0; } + if (likely(val)) + json_decref(val); } else { ret = -1; LOGWARNING("Got no auth response from ckdb :(");