Browse Source

Parse new auth command from ckdb

master
Con Kolivas 10 years ago
parent
commit
3288b15622
  1. 2
      src/ckpool.c
  2. 1
      src/ckpool.h
  3. 26
      src/stratifier.c

2
src/ckpool.c

@ -851,7 +851,7 @@ static void sighandler(int sig)
exit(0); 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); json_t *entry = json_object_get(val, res);
const char *buf; const char *buf;

1
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); json_t *json_rpc_call(connsock_t *cs, const char *rpc_req);
int process_exit(ckpool_t *ckp, proc_instance_t *pi, int ret); 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 */ #endif /* CKPOOL_H */

26
src/stratifier.c

@ -1588,20 +1588,32 @@ static int send_recv_auth(stratum_instance_t *client)
free(json_msg); free(json_msg);
if (likely(buf)) { 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); LOGINFO("Got ckdb response: %s", buf);
sscanf(buf, "id.%*d.%s", response); sscanf(buf, "id.%*d.%s", response);
secondaryuserid = response; cmd = response;
strsep(&secondaryuserid, "."); strsep(&cmd, "=");
LOGINFO("User %s Worker %s got auth response: %s suid: %s", LOGINFO("User %s Worker %s got auth response: %s cmd: %s",
user_instance->username, client->workername, user_instance->username, client->workername,
response, secondaryuserid); response, cmd);
if (!safecmp(response, "ok") && secondaryuserid) { 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) if (!user_instance->secondaryuserid)
user_instance->secondaryuserid = strdup(secondaryuserid); user_instance->secondaryuserid = secondaryuserid;
else
dealloc(secondaryuserid);
ret = 0; ret = 0;
} }
if (likely(val))
json_decref(val);
} else { } else {
ret = -1; ret = -1;
LOGWARNING("Got no auth response from ckdb :("); LOGWARNING("Got no auth response from ckdb :(");

Loading…
Cancel
Save