|
|
@ -2308,15 +2308,18 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, |
|
|
|
char *code, char *inet, tv_t *cd, |
|
|
|
char *code, char *inet, tv_t *cd, |
|
|
|
K_TREE *trf_root) |
|
|
|
K_TREE *trf_root) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
char reply[1024] = ""; |
|
|
|
char reply[1024] = ""; |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
K_ITEM *i_poolinstance, *i_username, *i_workername, *i_clientid; |
|
|
|
K_ITEM *i_poolinstance, *i_username, *i_workername, *i_clientid; |
|
|
|
K_ITEM *i_enonce1, *i_useragent, *i_preauth, *u_item, *oc_item; |
|
|
|
K_ITEM *i_enonce1, *i_useragent, *i_preauth, *u_item, *oc_item, *w_item; |
|
|
|
USERS *users = NULL; |
|
|
|
USERS *users = NULL; |
|
|
|
char *username; |
|
|
|
char *username; |
|
|
|
WORKERS *workers = NULL; |
|
|
|
WORKERS *workers = NULL; |
|
|
|
OPTIONCONTROL *optioncontrol; |
|
|
|
OPTIONCONTROL *optioncontrol; |
|
|
|
bool ok; |
|
|
|
size_t len, off; |
|
|
|
|
|
|
|
char *buf; |
|
|
|
|
|
|
|
bool ok, first; |
|
|
|
|
|
|
|
|
|
|
|
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); |
|
|
|
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); |
|
|
|
|
|
|
|
|
|
|
@ -2378,18 +2381,42 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, |
|
|
|
if (!ok) { |
|
|
|
if (!ok) { |
|
|
|
LOGDEBUG("%s() %s.failed.DBE", __func__, id); |
|
|
|
LOGDEBUG("%s() %s.failed.DBE", __func__, id); |
|
|
|
return strdup("failed.DBE"); |
|
|
|
return strdup("failed.DBE"); |
|
|
|
} else { |
|
|
|
|
|
|
|
// Only flag a successful auth
|
|
|
|
|
|
|
|
ck_wlock(&last_lock); |
|
|
|
|
|
|
|
setnow(&last_auth); |
|
|
|
|
|
|
|
ck_wunlock(&last_lock); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Only flag a successful auth
|
|
|
|
|
|
|
|
ck_wlock(&last_lock); |
|
|
|
|
|
|
|
setnow(&last_auth); |
|
|
|
|
|
|
|
ck_wunlock(&last_lock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
APPEND_REALLOC_INIT(buf, off, len); |
|
|
|
snprintf(reply, siz, |
|
|
|
snprintf(reply, siz, |
|
|
|
"ok.authorise={\"secondaryuserid\":\"%s\"," |
|
|
|
"ok.authorise={\"secondaryuserid\":\"%s\"," |
|
|
|
"\"difficultydefault\":%d}", |
|
|
|
"\"workers\":[", |
|
|
|
users->secondaryuserid, workers->difficultydefault); |
|
|
|
users->secondaryuserid); |
|
|
|
LOGDEBUG("%s.%s", id, reply); |
|
|
|
APPEND_REALLOC(buf, off, len, reply); |
|
|
|
return strdup(reply); |
|
|
|
first = true; |
|
|
|
|
|
|
|
K_RLOCK(workers_free); |
|
|
|
|
|
|
|
w_item = first_workers(users->userid, ctx); |
|
|
|
|
|
|
|
DATA_WORKERS_NULL(workers, w_item); |
|
|
|
|
|
|
|
while (w_item && workers->userid == users->userid) { |
|
|
|
|
|
|
|
if (CURRENT(&(workers->expirydate))) { |
|
|
|
|
|
|
|
snprintf(reply, siz, |
|
|
|
|
|
|
|
"%s{\"workername\":\"%s\"," |
|
|
|
|
|
|
|
"\"difficultydefault\":%"PRId32"}", |
|
|
|
|
|
|
|
first ? EMPTY : ",", |
|
|
|
|
|
|
|
workers->workername, |
|
|
|
|
|
|
|
workers->difficultydefault); |
|
|
|
|
|
|
|
APPEND_REALLOC(buf, off, len, reply); |
|
|
|
|
|
|
|
first = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
w_item = next_in_ktree(ctx); |
|
|
|
|
|
|
|
DATA_WORKERS_NULL(workers, w_item); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
K_RUNLOCK(workers_free); |
|
|
|
|
|
|
|
APPEND_REALLOC(buf, off, len, "]}"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOGDEBUG("%s.%s", id, buf); |
|
|
|
|
|
|
|
return buf; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_auth(PGconn *conn, char *cmd, char *id, |
|
|
|
static char *cmd_auth(PGconn *conn, char *cmd, char *id, |
|
|
@ -2404,13 +2431,16 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, |
|
|
|
char *code, char *inet, tv_t *cd, |
|
|
|
char *code, char *inet, tv_t *cd, |
|
|
|
K_TREE *trf_root) |
|
|
|
K_TREE *trf_root) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
K_TREE_CTX ctx[1]; |
|
|
|
char reply[1024] = ""; |
|
|
|
char reply[1024] = ""; |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
size_t siz = sizeof(reply); |
|
|
|
K_ITEM *i_poolinstance, *i_username, *i_workername, *i_clientid; |
|
|
|
K_ITEM *i_poolinstance, *i_username, *i_workername, *i_clientid; |
|
|
|
K_ITEM *i_enonce1, *i_useragent, *i_preauth; |
|
|
|
K_ITEM *i_enonce1, *i_useragent, *i_preauth, *w_item; |
|
|
|
USERS *users = NULL; |
|
|
|
USERS *users = NULL; |
|
|
|
WORKERS *workers = NULL; |
|
|
|
WORKERS *workers = NULL; |
|
|
|
bool ok; |
|
|
|
size_t len, off; |
|
|
|
|
|
|
|
char *buf; |
|
|
|
|
|
|
|
bool ok, first; |
|
|
|
|
|
|
|
|
|
|
|
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); |
|
|
|
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); |
|
|
|
|
|
|
|
|
|
|
@ -2456,18 +2486,42 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, |
|
|
|
if (!ok) { |
|
|
|
if (!ok) { |
|
|
|
LOGDEBUG("%s() %s.failed.DBE", __func__, id); |
|
|
|
LOGDEBUG("%s() %s.failed.DBE", __func__, id); |
|
|
|
return strdup("failed.DBE"); |
|
|
|
return strdup("failed.DBE"); |
|
|
|
} else { |
|
|
|
|
|
|
|
// Only flag a successful auth
|
|
|
|
|
|
|
|
ck_wlock(&last_lock); |
|
|
|
|
|
|
|
setnow(&last_auth); |
|
|
|
|
|
|
|
ck_wunlock(&last_lock); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Only flag a successful auth
|
|
|
|
|
|
|
|
ck_wlock(&last_lock); |
|
|
|
|
|
|
|
setnow(&last_auth); |
|
|
|
|
|
|
|
ck_wunlock(&last_lock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
APPEND_REALLOC_INIT(buf, off, len); |
|
|
|
snprintf(reply, siz, |
|
|
|
snprintf(reply, siz, |
|
|
|
"ok.addrauth={\"secondaryuserid\":\"%s\"," |
|
|
|
"ok.addrauth={\"secondaryuserid\":\"%s\"," |
|
|
|
"\"difficultydefault\":%d}", |
|
|
|
"\"workers\":[", |
|
|
|
users->secondaryuserid, workers->difficultydefault); |
|
|
|
users->secondaryuserid); |
|
|
|
LOGDEBUG("%s.%s", id, reply); |
|
|
|
APPEND_REALLOC(buf, off, len, reply); |
|
|
|
return strdup(reply); |
|
|
|
first = true; |
|
|
|
|
|
|
|
K_RLOCK(workers_free); |
|
|
|
|
|
|
|
w_item = first_workers(users->userid, ctx); |
|
|
|
|
|
|
|
DATA_WORKERS_NULL(workers, w_item); |
|
|
|
|
|
|
|
while (w_item && workers->userid == users->userid) { |
|
|
|
|
|
|
|
if (CURRENT(&(workers->expirydate))) { |
|
|
|
|
|
|
|
snprintf(reply, siz, |
|
|
|
|
|
|
|
"%s{\"workername\":\"%s\"," |
|
|
|
|
|
|
|
"\"difficultydefault\":%"PRId32"}", |
|
|
|
|
|
|
|
first ? EMPTY : ",", |
|
|
|
|
|
|
|
workers->workername, |
|
|
|
|
|
|
|
workers->difficultydefault); |
|
|
|
|
|
|
|
APPEND_REALLOC(buf, off, len, reply); |
|
|
|
|
|
|
|
first = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
w_item = next_in_ktree(ctx); |
|
|
|
|
|
|
|
DATA_WORKERS_NULL(workers, w_item); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
K_RUNLOCK(workers_free); |
|
|
|
|
|
|
|
APPEND_REALLOC(buf, off, len, "]}"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOGDEBUG("%s.%s", id, buf); |
|
|
|
|
|
|
|
return buf; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_addrauth(PGconn *conn, char *cmd, char *id, |
|
|
|
static char *cmd_addrauth(PGconn *conn, char *cmd, char *id, |
|
|
|