From 08a937768c9c5dcb2dbcbf3271791d95c21dd7bf Mon Sep 17 00:00:00 2001 From: kanoi Date: Tue, 13 Sep 2016 19:07:04 +1000 Subject: [PATCH] ckdb - change username fields and all relevant fields in paymentaddresses and payments to intransient --- src/ckdb.c | 5 + src/ckdb.h | 32 ++++--- src/ckdb_cmd.c | 241 +++++++++++++++++++++++++---------------------- src/ckdb_crypt.c | 12 +-- src/ckdb_data.c | 66 +++++++------ src/ckdb_dbio.c | 66 ++++++------- 6 files changed, 223 insertions(+), 199 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index 52d89278..b8e64e90 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -459,6 +459,9 @@ K_TREE *intransient_root; K_LIST *intransient_free; K_STORE *intransient_store; +/* *** WARNING *** all incoming field names processed by breakdown(), + * that are used as intransient anywhere, MUST be here + * TODO: this should be a hash table */ char *intransient_fields[] = { "workername", "blockhash", @@ -466,6 +469,7 @@ char *intransient_fields[] = { CODETRF, INETTRF, "username", + "admin", "agent", "useragent", "address", @@ -474,6 +478,7 @@ char *intransient_fields[] = { "version", "poolinstance", "payaddress", + "subname", "originaltxn", "committxn", "commitblockhash", diff --git a/src/ckdb.h b/src/ckdb.h index b5ed6019..cd0895b7 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -58,7 +58,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.7" -#define CKDB_VERSION DB_VERSION"-2.500" +#define CKDB_VERSION DB_VERSION"-2.501" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -1790,7 +1790,7 @@ extern K_LIST *seqtrans_free; // USERS typedef struct users { int64_t userid; - char username[TXT_BIG+1]; + char *in_username; char usertrim[TXT_BIG+1]; // non-DB field // Anything in 'status' fails mining authentication char status[TXT_BIG+1]; @@ -1942,10 +1942,10 @@ extern K_LIST *workers_db_free; typedef struct paymentaddresses { int64_t paymentaddressid; int64_t userid; - char payaddress[TXT_BIG+1]; + char *in_payaddress; int32_t payratio; char payname[TXT_SML+1]; - HISTORYDATECONTROLFIELDS; + HISTORYDATECONTROLIN; bool match; // non-DB field } PAYMENTADDRESSES; @@ -1967,14 +1967,14 @@ typedef struct payments { int64_t paymentid; int64_t payoutid; int64_t userid; - char subname[TXT_BIG+1]; + char *in_subname; tv_t paydate; - char payaddress[TXT_BIG+1]; - char originaltxn[TXT_BIG+1]; + char *in_payaddress; + char *in_originaltxn; int64_t amount; double diffacc; - char committxn[TXT_BIG+1]; - char commitblockhash[TXT_BIG+1]; + char *in_committxn; + char *in_commitblockhash; HISTORYDATECONTROLIN; K_ITEM *old_item; // non-DB field } PAYMENTS; @@ -3152,7 +3152,7 @@ enum info_type { // USERINFO from various incoming data typedef struct userinfo { int64_t userid; - char username[TXT_BIG+1]; + char *in_username; int blocks; int orphans; // How many blocks are orphans int rejects; // How many blocks are rejects @@ -3643,14 +3643,16 @@ extern bool users_update(PGconn *conn, K_ITEM *u_item, char *oldhash, char *newhash, char *email, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root, char *status, int *event); -extern K_ITEM *users_add(PGconn *conn, char *username, char *emailaddress, - char *passwordhash, int64_t userbits, char *by, - char *code, char *inet, tv_t *cd, K_TREE *trf_root); +extern K_ITEM *users_add(PGconn *conn, INTRANSIENT *in_username, + char *emailaddress, char *passwordhash, + int64_t userbits, char *by, char *code, char *inet, + tv_t *cd, K_TREE *trf_root); extern bool users_replace(PGconn *conn, K_ITEM *u_item, K_ITEM *old_u_item, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root); extern bool users_fill(PGconn *conn); -extern bool useratts_item_add(PGconn *conn, K_ITEM *ua_item, tv_t *cd, bool begun); +extern bool useratts_item_add(PGconn *conn, K_ITEM *ua_item, tv_t *cd, + bool begun); extern K_ITEM *useratts_add(PGconn *conn, char *username, char *attname, char *status, char *attstr, char *attstr2, char *attnum, char *attnum2, char *attdate, @@ -3753,7 +3755,7 @@ extern int _events_add(int id, char *by, char *inet, tv_t *cd, K_TREE *trf_root) #define events_add(_id, _trf_root) _events_add(_id, NULL, NULL, NULL, _trf_root) extern int _ovents_add(int id, char *by, char *inet, tv_t *cd, K_TREE *trf_root); #define ovents_add(_id, _trf_root) _ovents_add(_id, NULL, NULL, NULL, _trf_root) -extern bool auths_add(PGconn *conn, char *poolinstance, char *username, +extern bool auths_add(PGconn *conn, char *poolinstance, INTRANSIENT *in_username, INTRANSIENT *in_workername, char *clientid, char *enonce1, char *useragent, char *preauth, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root, diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 91331bfb..4a7f4ec4 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -14,22 +14,22 @@ * This should ONLY be used for web reporting cmds i.e. read only * Current PHP allows this for a hard coded user */ -static K_ITEM *adminuser(K_TREE *trf_root, char *reply, size_t siz) +static INTRANSIENT *adminuser(K_TREE *trf_root, char *reply, size_t siz) { - K_ITEM *i_username, *i_admin; + INTRANSIENT *in_username, *in_admin; char reply2[1024] = ""; - i_username = require_name(trf_root, "username", MIN_USERNAME, - (char *)userpatt, reply, siz); - if (!i_username) + in_username = require_in(trf_root, "username", MIN_USERNAME, + (char *)userpatt, reply, siz); + if (!in_username) return NULL; - i_admin = optional_name(trf_root, "admin", MIN_USERNAME, + in_admin = optional_in(trf_root, "admin", MIN_USERNAME, (char *)userpatt, reply2, sizeof(reply2)); - if (i_admin) - return i_admin; + if (in_admin) + return in_admin; - return i_username; + return in_username; } static char *cmd_adduser(PGconn *conn, char *cmd, char *id, tv_t *now, char *by, @@ -38,14 +38,15 @@ static char *cmd_adduser(PGconn *conn, char *cmd, char *id, tv_t *now, char *by, { char reply[1024] = ""; size_t siz = sizeof(reply); - K_ITEM *i_username, *i_emailaddress, *i_passwordhash, *u_item = NULL; + K_ITEM *i_emailaddress, *i_passwordhash, *u_item = NULL; + INTRANSIENT *in_username; int event = EVENT_OK; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_username = require_name(trf_root, "username", MIN_USERNAME, - (char *)userpatt, reply, siz); - if (!i_username) + in_username = require_in(trf_root, "username", MIN_USERNAME, + (char *)userpatt, reply, siz); + if (!in_username) return strdup(reply); /* If a username added from the web site looks like an address @@ -56,7 +57,7 @@ static char *cmd_adduser(PGconn *conn, char *cmd, char *id, tv_t *now, char *by, * ... and the person who owns the payout address can't check that * in advance, they'll just find out with their first payout not * arriving at their payout address */ - if (!like_address(transfer_data(i_username))) { + if (!like_address(in_username->str)) { i_emailaddress = require_name(trf_root, "emailaddress", 7, (char *)mailpatt, reply, siz); if (!i_emailaddress) @@ -69,7 +70,7 @@ static char *cmd_adduser(PGconn *conn, char *cmd, char *id, tv_t *now, char *by, event = events_add(EVENTID_CREACC, trf_root); if (event == EVENT_OK) { - u_item = users_add(conn, transfer_data(i_username), + u_item = users_add(conn, in_username, transfer_data(i_emailaddress), transfer_data(i_passwordhash), 0, by, code, inet, now, trf_root); @@ -80,8 +81,8 @@ static char *cmd_adduser(PGconn *conn, char *cmd, char *id, tv_t *now, char *by, LOGERR("%s() %s.failed.DBE", __func__, id); return reply_event(event, "failed.DBE"); } - LOGDEBUG("%s.ok.added %s", id, transfer_data(i_username)); - snprintf(reply, siz, "ok.added %s", transfer_data(i_username)); + LOGDEBUG("%s.ok.added %s", id, in_username->str); + snprintf(reply, siz, "ok.added %s", in_username->str); return strdup(reply); } @@ -292,7 +293,7 @@ static char *cmd_2fa(__maybe_unused PGconn *conn, char *cmd, char *id, LOGERR("%s() users databits invalid for " "'%s/%"PRId64, __func__, - st = safe_text_nonull(users->username), + st = safe_text_nonull(users->in_username), users->databits); FREENULL(st); goto dame; @@ -406,7 +407,7 @@ static char *cmd_2fa(__maybe_unused PGconn *conn, char *cmd, char *id, LOGERR("%s() invalid key for '%s/%s " "len(%d) != %d", __func__, - st = safe_text_nonull(users->username), + st = safe_text_nonull(users->in_username), USER_TOTPAUTH_NAME, (int)binlen, TOTPAUTH_KEYSIZE); FREENULL(st); @@ -470,11 +471,12 @@ static char *cmd_userset(PGconn *conn, char *cmd, char *id, __maybe_unused tv_t *notcd, K_TREE *trf_root, __maybe_unused bool reload_data) { - K_ITEM *i_username, *i_passwordhash, *i_2fa, *i_rows, *i_address; + INTRANSIENT *in_username, *in_address; + K_ITEM *i_passwordhash, *i_2fa, *i_rows; K_ITEM *i_ratio, *i_payname, *i_email, *u_item, *pa_item, *old_pa_item; K_ITEM *ua_item = NULL; USERATTS *useratts = NULL; - char *email, *address, *payname; + char *email, *payname; char reply[1024] = ""; size_t siz = sizeof(reply); int event = EVENT_OK; @@ -493,16 +495,16 @@ static char *cmd_userset(PGconn *conn, char *cmd, char *id, LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_username = require_name(trf_root, "username", MIN_USERNAME, - (char *)userpatt, reply, siz); - if (!i_username) { + in_username = require_in(trf_root, "username", MIN_USERNAME, + (char *)userpatt, reply, siz); + if (!in_username) { // For web this message is detailed enough reason = "System error"; goto struckout; } K_RLOCK(users_free); - u_item = find_users(transfer_data(i_username)); + u_item = find_users(in_username->str); K_RUNLOCK(users_free); if (!u_item) { @@ -549,7 +551,7 @@ static char *cmd_userset(PGconn *conn, char *cmd, char *id, while (pa_item && CURRENT(&(row->expirydate)) && row->userid == users->userid) { snprintf(tmp, sizeof(tmp), "addr:%d=%s%c", - rows, row->payaddress, FLDSEP); + rows, row->in_payaddress, FLDSEP); APPEND_REALLOC(answer, off, len, tmp); snprintf(tmp, sizeof(tmp), "ratio:%d=%d%c", rows, row->payratio, FLDSEP); @@ -649,22 +651,21 @@ static char *cmd_userset(PGconn *conn, char *cmd, char *id, continue; snprintf(tmp, sizeof(tmp), "address:%d", i); - i_address = require_name(trf_root, tmp, - ADDR_MIN_LEN, - (char *)addrpatt, - reply, siz); - if (!i_address) { + in_address = require_in(trf_root, tmp, + ADDR_MIN_LEN, + (char *)addrpatt, + reply, siz); + if (!in_address) { K_WUNLOCK(paymentaddresses_free); event = events_add(EVENTID_INCBTC, trf_root); reason = "Invalid address"; goto struckout; } - address = transfer_data(i_address); pa_item = STORE_HEAD_NOLOCK(pa_store); while (pa_item) { DATA_PAYMENTADDRESSES(row, pa_item); - if (strcmp(row->payaddress, address) == 0) { + if (INTREQ(row->in_payaddress, in_address->str)) { K_WUNLOCK(paymentaddresses_free); reason = "Duplicate address"; goto struckout; @@ -682,7 +683,7 @@ static char *cmd_userset(PGconn *conn, char *cmd, char *id, pa_item = k_unlink_head(paymentaddresses_free); DATA_PAYMENTADDRESSES(row, pa_item); bzero(row, sizeof(*row)); - STRNCPY(row->payaddress, address); + row->in_payaddress = in_address->str; row->payratio = ratio; STRNCPY(row->payname, payname); k_add_head(pa_store, pa_item); @@ -704,7 +705,7 @@ static char *cmd_userset(PGconn *conn, char *cmd, char *id, DATA_PAYMENTADDRESSES(row, pa_item); // Only EVER validate addresses once ... for now K_RLOCK(paymentaddresses_free); - old_pa_item = find_any_payaddress(row->payaddress); + old_pa_item = find_any_payaddress(row->in_payaddress); K_RUNLOCK(paymentaddresses_free); if (old_pa_item) { /* This test effectively means that @@ -717,7 +718,7 @@ static char *cmd_userset(PGconn *conn, char *cmd, char *id, reason = "Unavailable BTC address"; goto struckout; } - } else if (!btc_valid_address(row->payaddress)) { + } else if (!btc_valid_address(row->in_payaddress)) { event = events_add(EVENTID_INVBTC, trf_root); reason = "Invalid BTC address"; @@ -767,8 +768,8 @@ struckout: if (reason) { char *user, *st = NULL; snprintf(reply, siz, "ERR.%s", reason); - if (i_username) - user = st = safe_text(transfer_data(i_username)); + if (in_username) + user = st = safe_text(in_username->str); else user = EMPTY; LOGERR("%s.%s.%s (%s)", cmd, id, reply, user); @@ -852,7 +853,7 @@ static char *cmd_workerset(PGconn *conn, char *cmd, char *id, tv_t *now, update = true; } if (update) { - ua_item = useratts_add(conn, users->username, + ua_item = useratts_add(conn, users->in_username, USER_OLD_WORKERS, EMPTY, EMPTY, EMPTY, transfer_data(i_oldworkers), @@ -1736,7 +1737,8 @@ static char *cmd_payments(__maybe_unused PGconn *conn, char *cmd, char *id, __maybe_unused K_TREE *trf_root, __maybe_unused bool reload_data) { - K_ITEM *i_username, *u_item, *p_item, *p2_item, *po_item; + K_ITEM *u_item, *p_item, *p2_item, *po_item; + INTRANSIENT *in_username; K_TREE_CTX ctx[1]; K_STORE *pay_store; PAYMENTS *payments, *last_payments = NULL; @@ -1752,12 +1754,12 @@ static char *cmd_payments(__maybe_unused PGconn *conn, char *cmd, char *id, LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_username = adminuser(trf_root, reply, siz); - if (!i_username) + in_username = adminuser(trf_root, reply, siz); + if (!in_username) return strdup(reply); K_RLOCK(users_free); - u_item = find_users(transfer_data(i_username)); + u_item = find_users(in_username->str); K_RUNLOCK(users_free); if (!u_item) return strdup("bad"); @@ -1774,13 +1776,17 @@ static char *cmd_payments(__maybe_unused PGconn *conn, char *cmd, char *id, * if it has multiple items (percent payout user) */ while (p_item && payments->userid == users->userid) { if (CURRENT(&(payments->expirydate))) { - if (!last_payments || payments->payoutid != last_payments->payoutid) { + if (!last_payments || + payments->payoutid != last_payments->payoutid) { p2_item = k_unlink_head(payments_free); DATA_PAYMENTS_NULL(last_payments, p2_item); - memcpy(last_payments, payments, sizeof(*last_payments)); + memcpy(last_payments, payments, + sizeof(*last_payments)); k_add_tail(pay_store, p2_item); } else { - STRNCPY(last_payments->payaddress, "*Multiple"); + /* This is OK since it's a local store and + * we don't use INTREQ() on it */ + last_payments->in_payaddress = "*Multiple"; last_payments->amount += payments->amount; } } @@ -1808,7 +1814,7 @@ static char *cmd_payments(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), "height:%d=%s%c", rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); - str_to_buf(payments->payaddress, reply, sizeof(reply)); + str_to_buf(payments->in_payaddress, reply, sizeof(reply)); snprintf(tmp, sizeof(tmp), "payaddress:%d=%s%c", rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); @@ -1824,6 +1830,9 @@ static char *cmd_payments(__maybe_unused PGconn *conn, char *cmd, char *id, } p_item = p_item->next; } + K_WLOCK(payments_free); + k_list_transfer_to_head(pay_store, payments_free); + K_WUNLOCK(payments_free); snprintf(tmp, sizeof(tmp), "rows=%d%cflds=%s%c", rows, FLDSEP, @@ -1833,7 +1842,7 @@ static char *cmd_payments(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), "arn=%s%carp=%s", "Payments", FLDSEP, ""); APPEND_REALLOC(buf, off, len, tmp); - LOGDEBUG("%s.ok.%s", id, transfer_data(i_username)); + LOGDEBUG("%s.ok.%s", id, in_username->str); return buf; } @@ -1953,7 +1962,7 @@ static char *cmd_percent(char *cmd, char *id, tv_t *now, USERS *users) ratio = (double)(pa->payratio) / (double)paytotal; snprintf(tmp, sizeof(tmp), "payaddress:%d=%s%c", - rows, pa->payaddress, FLDSEP); + rows, pa->in_payaddress, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); snprintf(tmp, sizeof(tmp), "payratio:%d=%"PRId32"%c", @@ -2065,7 +2074,7 @@ static char *cmd_percent(char *cmd, char *id, tv_t *now, USERS *users) snprintf(tmp, sizeof(tmp), "arn=%s%carp=%s", "Percents", FLDSEP, ""); APPEND_REALLOC(buf, off, len, tmp); - LOGDEBUG("%s.ok.%s", id, users->username); + LOGDEBUG("%s.ok.%s", id, users->in_username); return buf; } @@ -2075,8 +2084,9 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id, __maybe_unused tv_t *notcd, K_TREE *trf_root, __maybe_unused bool reload_data) { - K_ITEM *i_username, *i_stats, *i_percent, w_look, *u_item, *w_item; + K_ITEM *i_stats, *i_percent, w_look, *u_item, *w_item; K_ITEM *ua_item, *us_item, *ws_item; + INTRANSIENT *in_username; K_TREE_CTX w_ctx[1]; WORKERS lookworkers, *workers; WORKERSTATUS *workerstatus; @@ -2102,12 +2112,12 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id, return reply_ovent(ovent, reply); } - i_username = adminuser(trf_root, reply, siz); - if (!i_username) + in_username = adminuser(trf_root, reply, siz); + if (!in_username) return strdup(reply); K_RLOCK(users_free); - u_item = find_users(transfer_data(i_username)); + u_item = find_users(in_username->str); K_RUNLOCK(users_free); if (!u_item) return strdup("bad"); @@ -2391,7 +2401,7 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), "arn=%s%carp=%s", "Workers", FLDSEP, ""); APPEND_REALLOC(buf, off, len, tmp); - LOGDEBUG("%s.ok.%s", id, transfer_data(i_username)); + LOGDEBUG("%s.ok.%s", id, in_username->str); return buf; } @@ -2465,7 +2475,7 @@ static char *cmd_allusers(__maybe_unused PGconn *conn, char *cmd, char *id, userstats_u->in_workername); } else { DATA_USERS(users, u_item); - str_to_buf(users->username, reply, sizeof(reply)); + str_to_buf(users->in_username, reply, sizeof(reply)); snprintf(tmp, sizeof(tmp), "username:%d=%s%c", rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); @@ -3041,11 +3051,10 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, char reply[1024] = ""; size_t siz = sizeof(reply); int event = EVENT_OK; - K_ITEM *i_poolinstance, *i_username, *i_clientid; + K_ITEM *i_poolinstance, *i_clientid; K_ITEM *i_enonce1, *i_useragent, *i_preauth, *u_item, *oc_item, *w_item; - INTRANSIENT *in_workername; + INTRANSIENT *in_username, *in_workername; USERS *users = NULL; - char *username; WORKERS *workers = NULL; OPTIONCONTROL *optioncontrol; size_t len, off; @@ -3075,10 +3084,9 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, } } - i_username = require_name(trf_root, "username", 1, NULL, reply, siz); - if (!i_username) + in_username = require_in(trf_root, "username", 1, NULL, reply, siz); + if (!in_username) return strdup(reply); - username = transfer_data(i_username); in_workername = require_in(trf_root, "workername", 1, NULL, reply, siz); if (!in_workername) @@ -3103,14 +3111,14 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, oc_item = find_optioncontrol(OPTIONCONTROL_AUTOADDUSER, cd, pool.height); if (oc_item) { K_RLOCK(users_free); - u_item = find_users(username); + u_item = find_users(in_username->str); K_RUNLOCK(users_free); if (!u_item) { if (!reload_data) event = events_add(EVENTID_AUTOACC, trf_root); if (event == EVENT_OK) { DATA_OPTIONCONTROL(optioncontrol, oc_item); - u_item = users_add(conn, username, EMPTY, + u_item = users_add(conn, in_username, EMPTY, optioncontrol->optionvalue, 0, by, code, inet, cd, trf_root); @@ -3121,8 +3129,7 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, if (ok) { ok = auths_add(conn, transfer_data(i_poolinstance), - username, - in_workername, + in_username, in_workername, transfer_data(i_clientid), transfer_data(i_enonce1), transfer_data(i_useragent), @@ -3200,9 +3207,9 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, char reply[1024] = ""; size_t siz = sizeof(reply); int event = EVENT_OK; - K_ITEM *i_poolinstance, *i_username, *i_clientid; + K_ITEM *i_poolinstance, *i_clientid; K_ITEM *i_enonce1, *i_useragent, *i_preauth, *w_item; - INTRANSIENT *in_workername; + INTRANSIENT *in_username, *in_workername; USERS *users = NULL; WORKERS *workers = NULL; size_t len, off; @@ -3232,8 +3239,8 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, } } - i_username = require_name(trf_root, "username", 1, NULL, reply, siz); - if (!i_username) + in_username = require_in(trf_root, "username", 1, NULL, reply, siz); + if (!in_username) return strdup(reply); in_workername = require_in(trf_root, "workername", 1, NULL, reply, siz); @@ -3257,8 +3264,7 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, return strdup(reply); ok = auths_add(conn, transfer_data(i_poolinstance), - transfer_data(i_username), - in_workername, + in_username, in_workername, transfer_data(i_clientid), transfer_data(i_enonce1), transfer_data(i_useragent), @@ -3700,7 +3706,8 @@ static char *cmd_getatts(__maybe_unused PGconn *conn, char *cmd, char *id, __maybe_unused tv_t *notcd, K_TREE *trf_root, __maybe_unused bool reload_data) { - K_ITEM *i_username, *i_attlist, *u_item, *ua_item; + K_ITEM *i_attlist, *u_item, *ua_item; + INTRANSIENT *in_username; char reply[1024] = ""; size_t siz = sizeof(reply); int event = EVENT_OK; @@ -3715,16 +3722,16 @@ static char *cmd_getatts(__maybe_unused PGconn *conn, char *cmd, char *id, LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_username = require_name(trf_root, "username", MIN_USERNAME, - (char *)userpatt, reply, siz); - if (!i_username) { + in_username = require_in(trf_root, "username", MIN_USERNAME, + (char *)userpatt, reply, siz); + if (!in_username) { // Shouldn't happen except with a code problem no event required reason = "Missing username"; goto nuts; } K_RLOCK(users_free); - u_item = find_users(transfer_data(i_username)); + u_item = find_users(in_username->str); K_RUNLOCK(users_free); if (!u_item) { @@ -3880,7 +3887,8 @@ static char *cmd_setatts(PGconn *conn, char *cmd, char *id, ExecStatusType rescode; PGresult *res; bool conned = false; - K_ITEM *i_username, *t_item, *u_item, *ua_item = NULL; + K_ITEM *t_item, *u_item, *ua_item = NULL; + INTRANSIENT *in_username; K_TREE_CTX ctx[1]; char reply[1024] = ""; size_t siz = sizeof(reply); @@ -3895,15 +3903,15 @@ static char *cmd_setatts(PGconn *conn, char *cmd, char *id, LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_username = require_name(trf_root, "username", MIN_USERNAME, - (char *)userpatt, reply, siz); - if (!i_username) { + in_username = require_in(trf_root, "username", MIN_USERNAME, + (char *)userpatt, reply, siz); + if (!in_username) { reason = "Missing user"; goto bats; } K_RLOCK(users_free); - u_item = find_users(transfer_data(i_username)); + u_item = find_users(in_username->str); K_RUNLOCK(users_free); if (!u_item) { @@ -4047,7 +4055,8 @@ static char *cmd_expatts(__maybe_unused PGconn *conn, char *cmd, char *id, __maybe_unused tv_t *notcd, K_TREE *trf_root, __maybe_unused bool reload_data) { - K_ITEM *i_username, *i_attlist, *u_item, *ua_item; + K_ITEM *i_attlist, *u_item, *ua_item; + INTRANSIENT *in_username; char reply[1024] = ""; size_t siz = sizeof(reply); USERATTS *useratts; @@ -4058,15 +4067,15 @@ static char *cmd_expatts(__maybe_unused PGconn *conn, char *cmd, char *id, LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_username = require_name(trf_root, "username", MIN_USERNAME, - (char *)userpatt, reply, siz); - if (!i_username) { + in_username = require_in(trf_root, "username", MIN_USERNAME, + (char *)userpatt, reply, siz); + if (!in_username) { reason = "Missing username"; goto rats; } K_RLOCK(users_free); - u_item = find_users(transfer_data(i_username)); + u_item = find_users(in_username->str); K_RUNLOCK(users_free); if (!u_item) { @@ -4733,8 +4742,8 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), "user:%d=%s.%d%cpayaddress:%d=%s%c", - rows, users->username, ++count, FLDSEP, - rows, pa->payaddress, FLDSEP); + rows, users->in_username, ++count, + FLDSEP, rows, pa->in_payaddress, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); snprintf(tmp, sizeof(tmp), "diffacc_user:%d=%.1f%c", @@ -4750,7 +4759,7 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id, K_RUNLOCK(paymentaddresses_free); snprintf(tmp, sizeof(tmp), "user:%d=%s.0%cpayaddress:%d=%s%c", - rows, users->username, FLDSEP, + rows, users->in_username, FLDSEP, rows, "none", FLDSEP); APPEND_REALLOC(buf, off, len, tmp); snprintf(tmp, sizeof(tmp), @@ -5020,11 +5029,13 @@ static char *cmd_pplns2(__maybe_unused PGconn *conn, char *cmd, char *id, "payaddress:%d=%s%c" "amount:%d=%"PRId64"%c" "diffacc:%d=%.1f%c", - rows, payments->subname, FLDSEP, - rows, ua_item ? HOLD_ADDRESS : - payments->payaddress, FLDSEP, - rows, payments->amount, FLDSEP, - rows, payments->diffacc, FLDSEP); + rows, payments->in_subname, + FLDSEP, rows, + ua_item ? HOLD_ADDRESS : + payments->in_payaddress, + FLDSEP, rows, payments->amount, + FLDSEP, rows, + payments->diffacc, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); rows++; out++; @@ -5039,7 +5050,7 @@ static char *cmd_pplns2(__maybe_unused PGconn *conn, char *cmd, char *id, "payaddress:%d=%s%c" "amount:%d=%"PRId64"%c" "diffacc:%d=%.1f%c", - rows, users->username, FLDSEP, + rows, users->in_username, FLDSEP, rows, NONE_ADDRESS, FLDSEP, rows, miningpayouts->amount, FLDSEP, rows, miningpayouts->diffacc, FLDSEP); @@ -5360,7 +5371,8 @@ static char *cmd_mpayouts(__maybe_unused PGconn *conn, char *cmd, char *id, __maybe_unused K_TREE *trf_root, __maybe_unused bool reload_data) { - K_ITEM *i_username, *u_item, *mp_item, *po_item; + K_ITEM *u_item, *mp_item, *po_item; + INTRANSIENT *in_username; K_TREE_CTX ctx[1]; MININGPAYOUTS *mp; PAYOUTS *payouts; @@ -5374,12 +5386,12 @@ static char *cmd_mpayouts(__maybe_unused PGconn *conn, char *cmd, char *id, LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_username = adminuser(trf_root, reply, siz); - if (!i_username) + in_username = adminuser(trf_root, reply, siz); + if (!in_username) return strdup(reply); K_RLOCK(users_free); - u_item = find_users(transfer_data(i_username)); + u_item = find_users(in_username->str); K_RUNLOCK(users_free); if (!u_item) return strdup("bad"); @@ -5471,7 +5483,7 @@ static char *cmd_mpayouts(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), "arn=%s%carp=%s", "MiningPayouts", FLDSEP, ""); APPEND_REALLOC(buf, off, len, tmp); - LOGDEBUG("%s.ok.%s", id, transfer_data(i_username)); + LOGDEBUG("%s.ok.%s", id, in_username->str); return buf; } @@ -5553,7 +5565,8 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id, __maybe_unused tv_t *notcd, K_TREE *trf_root, __maybe_unused bool reload_data) { - K_ITEM *i_username, *i_select; + INTRANSIENT *in_username; + K_ITEM *i_select; K_ITEM *u_item, *p_item, *m_item, ms_look, *wm_item, *ms_item, *wi_item; K_TREE_CTX wm_ctx[1], ms_ctx[1]; WORKMARKERS *wm; @@ -5577,12 +5590,12 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id, LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_username = adminuser(trf_root, reply, siz); - if (!i_username) + in_username = adminuser(trf_root, reply, siz); + if (!in_username) return strdup(reply); K_RLOCK(users_free); - u_item = find_users(transfer_data(i_username)); + u_item = find_users(in_username->str); K_RUNLOCK(users_free); if (!u_item) return strdup("bad"); @@ -5645,7 +5658,7 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), " where_all=%d", where_all); APPEND_REALLOC(buf, off, len, tmp); LOGDEBUG("%s() user=%"PRId64"/%s' %s", - __func__, users->userid, users->username, buf+1); + __func__, users->userid, users->in_username, buf+1); FREENULL(buf); APPEND_REALLOC_INIT(buf, off, len); @@ -5892,7 +5905,7 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id, } } - LOGDEBUG("%s.ok.%s", id, transfer_data(i_username)); + LOGDEBUG("%s.ok.%s", id, in_username->str); return(buf); } @@ -6092,7 +6105,7 @@ static char *cmd_userstatus(PGconn *conn, char *cmd, char *id, tv_t *now, char * DATA_USERS(users, u_item); snprintf(reply, siz, "ok.updated %"PRId64" %s status %s", users->userid, - users->username, + users->in_username, status[0] ? "disabled" : "enabled"); LOGWARNING("%s.%s", id, reply); return strdup(reply); @@ -6626,7 +6639,7 @@ static char *cmd_pshift(__maybe_unused PGconn *conn, char *cmd, char *id, __maybe_unused tv_t *notcd, K_TREE *trf_root, __maybe_unused bool reload_data) { - K_ITEM *i_username; + INTRANSIENT *in_username; K_ITEM *u_item, *p_item, *m_item, *wm_item, *ms_item, *wi_item; K_TREE_CTX wm_ctx[1]; WORKMARKERS *wm; @@ -6647,12 +6660,12 @@ static char *cmd_pshift(__maybe_unused PGconn *conn, char *cmd, char *id, LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_username = adminuser(trf_root, reply, siz); - if (!i_username) + in_username = adminuser(trf_root, reply, siz); + if (!in_username) return strdup(reply); K_RLOCK(users_free); - u_item = find_users(transfer_data(i_username)); + u_item = find_users(in_username->str); K_RUNLOCK(users_free); if (!u_item) return strdup("bad"); @@ -6824,7 +6837,7 @@ static char *cmd_pshift(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), ",%d_", 0); APPEND_REALLOC(buf, off, len, tmp); - LOGDEBUG("%s.ok.%s", id, transfer_data(i_username)); + LOGDEBUG("%s.ok.%s", id, in_username->str); return(buf); } @@ -6872,7 +6885,7 @@ static char *cmd_userinfo(__maybe_unused PGconn *conn, char *cmd, char *id, while (ui_item) { DATA_USERINFO(userinfo, ui_item); - str_to_buf(userinfo->username, reply, sizeof(reply)); + str_to_buf(userinfo->in_username, reply, sizeof(reply)); snprintf(tmp, sizeof(tmp), "username:%d=%s%c", rows, reply, FLDSEP); APPEND_REALLOC(buf, off, len, tmp); diff --git a/src/ckdb_crypt.c b/src/ckdb_crypt.c index 524b0e6c..1750a754 100644 --- a/src/ckdb_crypt.c +++ b/src/ckdb_crypt.c @@ -36,7 +36,7 @@ char *_tob32(USERS *users, unsigned char *bin, size_t len, char *name, if (osiz != olen) { LOGEMERG("%s() of '%s' data for '%s' invalid olen=%d != osiz=%d" WHERE_FFL, - __func__, name, st = safe_text_nonull(users->username), + __func__, name, st = safe_text_nonull(users->in_username), (int)olen, (int)osiz, WHERE_FFL_PASS); FREENULL(st); olen = osiz; @@ -59,7 +59,7 @@ char *_tob32(USERS *users, unsigned char *bin, size_t len, char *name, "ch=%d, i=%d j=%d bits=%d bin=0x%s len=%d " "olen=%d" WHERE_FFL, __func__, name, - st = safe_text_nonull(users->username), + st = safe_text_nonull(users->in_username), ch, i, j, bits, binstr, (int)len, (int)olen, WHERE_FFL_PASS); FREENULL(st); @@ -150,7 +150,7 @@ bool check_2fa(USERS *users, int32_t value) LOGERR("%s() invalid key for '%s/%s " "len(%d) != %d", __func__, - st = safe_text_nonull(users->username), + st = safe_text_nonull(users->in_username), USER_TOTPAUTH_NAME, (int)binlen, TOTPAUTH_KEYSIZE); FREENULL(st); @@ -160,7 +160,7 @@ bool check_2fa(USERS *users, int32_t value) tim[i] = (now >> 8 * ((sizeof(int64_t) - 1) - i)) & 0xff; LOGDEBUG("%s() '%s/%s tim=%"PRId64"=%s key=%s=%s", __func__, - st = safe_text_nonull(users->username), + st = safe_text_nonull(users->in_username), USER_TOTPAUTH_NAME, now, tmp1 = (char *)bin2hex(&tim, sizeof(tim)), tmp2 = (char *)bin2hex(bin, TOTPAUTH_KEYSIZE), @@ -180,7 +180,7 @@ bool check_2fa(USERS *users, int32_t value) HMAC_Final(&ctx, hash, &reslen); LOGDEBUG("%s() '%s/%s hash=%s", __func__, - st = safe_text_nonull(users->username), + st = safe_text_nonull(users->in_username), USER_TOTPAUTH_NAME, tmp1 = (char *)bin2hex(hash, SHA256_DIGEST_LENGTH)); FREENULL(tmp1); @@ -195,7 +195,7 @@ bool check_2fa(USERS *users, int32_t value) LOGDEBUG("%s() '%s/%s offset=%d otp=%"PRId32" value=%"PRId32 " lastvalue=%"PRId32, - __func__, st = safe_text_nonull(users->username), + __func__, st = safe_text_nonull(users->in_username), USER_TOTPAUTH_NAME, offset, otp, value, users->lastvalue); FREENULL(st); FREENULL(hash); diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 89d9a723..e95ebb3c 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -255,7 +255,7 @@ void username_trim(USERS *users) { char *front, *trail; - front = users->username; + front = users->in_username; while (*front && TRIM_IGNORE(*front)) front++; @@ -1460,7 +1460,7 @@ cmp_t cmp_users(K_ITEM *a, K_ITEM *b) USERS *ua, *ub; DATA_USERS(ua, a); DATA_USERS(ub, b); - cmp_t c = CMP_STR(ua->username, ub->username); + cmp_t c = CMP_STR(ua->in_username, ub->in_username); if (c == 0) c = CMP_TV(ub->expirydate, ua->expirydate); return c; @@ -1485,7 +1485,7 @@ K_ITEM *find_users(char *username) K_TREE_CTX ctx[1]; K_ITEM look; - STRNCPY(users.username, username); + users.in_username = username; users.expirydate.tv_sec = default_expiry.tv_sec; users.expirydate.tv_usec = default_expiry.tv_usec; @@ -1596,7 +1596,7 @@ bool check_hash(USERS *users, char *passwordhash) char hex[SHA256SIZHEX+1]; if (*(users->salt)) { - password_hash(users->username, passwordhash, users->salt, hex, sizeof(hex)); + password_hash(users->in_username, passwordhash, users->salt, hex, sizeof(hex)); return (strcasecmp(hex, users->passwordhash) == 0); } else return (strcasecmp(passwordhash, users->passwordhash) == 0); @@ -1640,7 +1640,7 @@ char *_users_userdata_get_hex(USERS *users, char *name, int64_t bit, LOGEMERG("%s() users userdata/databits mismatch for " "%s/%"PRId64 WHERE_FFL, __func__, - st = safe_text_nonull(users->username), + st = safe_text_nonull(users->in_username), users->databits, WHERE_FFL_PASS); FREENULL(st); } else { @@ -1699,7 +1699,7 @@ void _users_userdata_del(USERS *users, char *name, int64_t bit, WHERE_FFL_ARGS) LOGEMERG("%s() users userdata/databits mismatch for " "%s/%"PRId64 WHERE_FFL, __func__, - st = safe_text_nonull(users->username), + st = safe_text_nonull(users->in_username), users->databits, WHERE_FFL_PASS); FREENULL(st); } else { @@ -1917,7 +1917,7 @@ void dsp_paymentaddresses(K_ITEM *item, FILE *stream) fprintf(stream, " id=%"PRId64" userid=%"PRId64" addr='%s' " "ratio=%"PRId32" exp=%s cd=%s\n", pa->paymentaddressid, pa->userid, - pa->payaddress, pa->payratio, + pa->in_payaddress, pa->payratio, expirydate_buf, createdate_buf); } } @@ -1932,7 +1932,7 @@ cmp_t cmp_paymentaddresses(K_ITEM *a, K_ITEM *b) if (c == 0) { c = CMP_BIGINT(pa->userid, pb->userid); if (c == 0) - c = CMP_STR(pa->payaddress, pb->payaddress); + c = CMP_STR(pa->in_payaddress, pb->in_payaddress); } return c; } @@ -1947,7 +1947,7 @@ cmp_t cmp_payaddr_create(K_ITEM *a, K_ITEM *b) if (c == 0) { c = CMP_TV(pa->createdate, pb->createdate); if (c == 0) - c = CMP_STR(pa->payaddress, pb->payaddress); + c = CMP_STR(pa->in_payaddress, pb->in_payaddress); } return c; } @@ -1963,7 +1963,7 @@ K_ITEM *find_paymentaddresses(int64_t userid, K_TREE_CTX *ctx) paymentaddresses.expirydate.tv_sec = default_expiry.tv_sec; paymentaddresses.expirydate.tv_usec = default_expiry.tv_usec; paymentaddresses.userid = userid+1; - paymentaddresses.payaddress[0] = '\0'; + paymentaddresses.in_payaddress = EMPTY; INIT_PAYMENTADDRESSES(&look); look.data = (void *)(&paymentaddresses); @@ -1987,7 +1987,7 @@ K_ITEM *find_paymentaddresses_create(int64_t userid, K_TREE_CTX *ctx) paymentaddresses.userid = userid; DATE_ZERO(&(paymentaddresses.createdate)); - paymentaddresses.payaddress[0] = '\0'; + paymentaddresses.in_payaddress = EMPTY; INIT_PAYMENTADDRESSES(&look); look.data = (void *)(&paymentaddresses); @@ -2010,14 +2010,14 @@ K_ITEM *find_one_payaddress(int64_t userid, char *payaddress, K_TREE_CTX *ctx) paymentaddresses.expirydate.tv_sec = default_expiry.tv_sec; paymentaddresses.expirydate.tv_usec = default_expiry.tv_usec; paymentaddresses.userid = userid; - STRNCPY(paymentaddresses.payaddress, payaddress); + paymentaddresses.in_payaddress = payaddress; INIT_PAYMENTADDRESSES(&look); look.data = (void *)(&paymentaddresses); return find_in_ktree(paymentaddresses_root, &look, ctx); } -/* This will match any user that has the payaddress +/* This will match any user that has the intransient payaddress * This avoids the bitcoind delay of rechecking an address * that has EVER been seen before * However, also, cmd_userset() that uses it, effectively ensures @@ -2026,7 +2026,7 @@ K_ITEM *find_one_payaddress(int64_t userid, char *payaddress, K_TREE_CTX *ctx) * N.B. this is faster than a bitcoind check, but still slow * It needs a tree based on payaddress to speed it up * N.B.2 paymentadresses_root doesn't contain addrauth usernames */ -K_ITEM *find_any_payaddress(char *payaddress) +K_ITEM *find_any_payaddress(char *in_payaddress) { PAYMENTADDRESSES *pa; K_TREE_CTX ctx[1]; @@ -2035,7 +2035,7 @@ K_ITEM *find_any_payaddress(char *payaddress) item = first_in_ktree(paymentaddresses_root, ctx); while (item) { DATA_PAYMENTADDRESSES(pa, item); - if (strcmp(pa->payaddress, payaddress) == 0) + if (INTREQ(pa->in_payaddress, in_payaddress)) return item; item = next_in_ktree(ctx); } @@ -2052,7 +2052,7 @@ cmp_t cmp_payments(K_ITEM *a, K_ITEM *b) if (c == 0) { c = CMP_BIGINT(pa->payoutid, pb->payoutid); if (c == 0) { - c = CMP_STR(pa->subname, pb->subname); + c = CMP_STR(pa->in_subname, pb->in_subname); if (c == 0) c = CMP_TV(pb->expirydate, pa->expirydate); } @@ -2068,7 +2068,7 @@ K_ITEM *find_payments(int64_t payoutid, int64_t userid, char *subname) payments.payoutid = payoutid; payments.userid = userid; - STRNCPY(payments.subname, subname); + payments.in_subname = subname; payments.expirydate.tv_sec = default_expiry.tv_sec; payments.expirydate.tv_usec = default_expiry.tv_usec; @@ -2107,7 +2107,7 @@ K_ITEM *find_first_paypayid(int64_t userid, int64_t payoutid, K_TREE_CTX *ctx) payments.userid = userid; payments.payoutid = payoutid; - payments.subname[0] = '\0'; + payments.in_subname = EMPTY; INIT_PAYMENTS(&look); look.data = (void *)(&payments); @@ -4484,7 +4484,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) K_TREE *mu_root = NULL; int usercount; double ndiff, total_diff, diff_want, elapsed; - char rewardbuf[32]; + char rewardbuf[32], subnamebuf[TXT_BIG+1]; double diff_times, diff_add; char cd_buf[CDATE_BUFSIZ]; tv_t end_tv = { 0L, 0L }; @@ -4949,7 +4949,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) pa_item2 = k_unlink_head(paymentaddresses_free); DATA_PAYMENTADDRESSES(pa2, pa_item2); pa2->userid = pa->userid; - STRNCPY(pa2->payaddress, pa->payaddress); + pa2->in_payaddress = pa->in_payaddress; pa2->payratio = pa->payratio; k_add_tail(addr_store, pa_item2); } @@ -4971,10 +4971,10 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) bzero(payments, sizeof(*payments)); payments->payoutid = payouts->payoutid; payments->userid = miningpayouts->userid; - snprintf(payments->subname, - sizeof(payments->subname), - "%s.%d", users->username, ++count); - STRNCPY(payments->payaddress, pa->payaddress); + snprintf(subnamebuf, sizeof(subnamebuf), + "%s.%d", users->in_username, ++count); + payments->in_subname = intransient_str("subname", subnamebuf); + payments->in_payaddress = pa->in_payaddress; d64 = floor((double)amount * (double)(pa->payratio) / (double)paytotal); @@ -5005,10 +5005,10 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd) bzero(payments, sizeof(*payments)); payments->payoutid = payouts->payoutid; payments->userid = miningpayouts->userid; - snprintf(payments->subname, - sizeof(payments->subname), - "%s.0", users->username); - STRNCPY(payments->payaddress, users->username); + snprintf(subnamebuf, sizeof(subnamebuf), + "%s.0", users->in_username); + payments->in_subname = intransient_str("subname", subnamebuf); + payments->in_payaddress = users->in_username; payments->amount = amount; payments->diffacc = miningpayouts->diffacc; used = amount; @@ -7136,6 +7136,7 @@ K_ITEM *_find_create_userinfo(int64_t userid, WHERE_FFL_ARGS) K_ITEM *ui_item, *u_item; USERS *users = NULL; USERINFO *row; + char usernamebuf[TXT_BIG+1]; ui_item = get_userinfo(userid); if (!ui_item) { @@ -7150,9 +7151,12 @@ K_ITEM *_find_create_userinfo(int64_t userid, WHERE_FFL_ARGS) bzero(row, sizeof(*row)); row->userid = userid; if (u_item) - STRNCPY(row->username, users->username); - else - bigint_to_buf(userid, row->username, sizeof(row->username)); + row->in_username = users->in_username; + else { + bigint_to_buf(userid, usernamebuf, sizeof(usernamebuf)); + row->in_username = intransient_str("username", + usernamebuf); + } add_to_ktree(userinfo_root, ui_item); k_add_head(userinfo_store, ui_item); diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index 81522ac1..079c1a98 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -599,7 +599,7 @@ bool users_update(PGconn *conn, K_ITEM *u_item, char *oldhash, if (hash) { // New salt each password change make_salt(row); - password_hash(row->username, newhash, row->salt, + password_hash(row->in_username, newhash, row->salt, row->passwordhash, sizeof(row->passwordhash)); } if (email) @@ -705,7 +705,7 @@ unparam: return ok; } -K_ITEM *users_add(PGconn *conn, char *username, char *emailaddress, +K_ITEM *users_add(PGconn *conn, INTRANSIENT *in_username, char *emailaddress, char *passwordhash, int64_t userbits, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root) { @@ -730,7 +730,7 @@ K_ITEM *users_add(PGconn *conn, char *username, char *emailaddress, K_WLOCK(users_db_free); K_RLOCK(users_free); - item = find_users(username); + item = find_users(in_username->str); K_RUNLOCK(users_free); if (item) { ok = true; @@ -744,7 +744,7 @@ K_ITEM *users_add(PGconn *conn, char *username, char *emailaddress, DATA_USERS(row, item); bzero(row, sizeof(*row)); - STRNCPY(row->username, username); + row->in_username = in_username->str; username_trim(row); dup = false; @@ -771,7 +771,7 @@ K_ITEM *users_add(PGconn *conn, char *username, char *emailaddress, row->status[0] = '\0'; STRNCPY(row->emailaddress, emailaddress); - snprintf(tohash, sizeof(tohash), "%s&#%s", username, emailaddress); + snprintf(tohash, sizeof(tohash), "%s&#%s", in_username->str, emailaddress); HASH_BER(tohash, strlen(tohash), 1, hash, tmp); __bin2hex(row->secondaryuserid, (void *)(&hash), sizeof(hash)); @@ -780,7 +780,7 @@ K_ITEM *users_add(PGconn *conn, char *username, char *emailaddress, // Make it impossible to login for a BTC Address username row->passwordhash[0] = '\0'; } else { - password_hash(row->username, passwordhash, row->salt, + password_hash(row->in_username, passwordhash, row->salt, row->passwordhash, sizeof(row->passwordhash)); } @@ -796,7 +796,7 @@ K_ITEM *users_add(PGconn *conn, char *username, char *emailaddress, par = 0; params[par++] = bigint_to_buf(row->userid, NULL, 0); - params[par++] = str_to_buf(row->username, NULL, 0); + params[par++] = str_to_buf(row->in_username, NULL, 0); params[par++] = str_to_buf(row->status, NULL, 0); params[par++] = str_to_buf(row->emailaddress, NULL, 0); params[par++] = tv_to_buf(&(row->joineddate), NULL, 0); @@ -909,7 +909,7 @@ bool users_replace(PGconn *conn, K_ITEM *u_item, K_ITEM *old_u_item, char *by, par = 0; params[par++] = bigint_to_buf(users->userid, NULL, 0); - params[par++] = str_to_buf(users->username, NULL, 0); + params[par++] = str_to_buf(users->in_username, NULL, 0); params[par++] = str_to_buf(users->status, NULL, 0); params[par++] = str_to_buf(users->emailaddress, NULL, 0); params[par++] = tv_to_buf(&(users->joineddate), NULL, 0); @@ -1026,7 +1026,7 @@ bool users_fill(PGconn *conn) PQ_GET_FLD(res, i, "username", field, ok); if (!ok) break; - TXT_TO_STR("username", field, row->username); + row->in_username = intransient_str("username", field); PQ_GET_FLD(res, i, "status", field, ok); if (!ok) @@ -2004,7 +2004,7 @@ bool paymentaddresses_set(PGconn *conn, int64_t userid, K_STORE *pa_store, match = STORE_HEAD_NOLOCK(pa_store); while (match) { DATA_PAYMENTADDRESSES(pa, match); - if (strcmp(pa->payaddress, row->payaddress) == 0 && + if (INTREQ(pa->in_payaddress, row->in_payaddress) && pa->payratio == row->payratio && strcmp(pa->payname, row->payname) == 0) { pa->match = true; // Don't store it @@ -2015,7 +2015,7 @@ bool paymentaddresses_set(PGconn *conn, int64_t userid, K_STORE *pa_store, } if (!match) { // No matching replacement, so expire 'row' - params[par++] = str_to_buf(row->payaddress, NULL, 0); + params[par++] = str_to_buf(row->in_payaddress, NULL, 0); if (!first) APPEND_REALLOC(upd, off, len, ","); first = false; @@ -2071,16 +2071,16 @@ bool paymentaddresses_set(PGconn *conn, int64_t userid, K_STORE *pa_store, row->userid = userid; - HISTORYDATEINIT(row, cd, by, code, inet); - HISTORYDATETRANSFER(trf_root, row); + HISTORYDATEINTRANS(row, cd, by, code, inet); + HISTORYDATETRANSFERIN(trf_root, row); par = 0; params[par++] = bigint_to_buf(row->paymentaddressid, NULL, 0); params[par++] = bigint_to_buf(row->userid, NULL, 0); - params[par++] = str_to_buf(row->payaddress, NULL, 0); + params[par++] = str_to_buf(row->in_payaddress, NULL, 0); params[par++] = int_to_buf(row->payratio, NULL, 0); params[par++] = str_to_buf(row->payname, NULL, 0); - HISTORYDATEPARAMS(params, par, row); + HISTORYDATEPARAMSIN(params, par, row); PARCHKVAL(par, 10, params); // As per PQPARAM10 above res = PQexecParams(conn, ins, par, NULL, (const char **)params, @@ -2129,7 +2129,7 @@ unparam: match = STORE_HEAD_NOLOCK(pa_store); while (match) { DATA_PAYMENTADDRESSES(pa, match); - if (strcmp(pa->payaddress, row->payaddress) == 0 && + if (INTREQ(pa->in_payaddress, row->in_payaddress) && pa->payratio == row->payratio && strcmp(pa->payname, row->payname) == 0) { break; @@ -2236,7 +2236,7 @@ bool paymentaddresses_fill(PGconn *conn) PQ_GET_FLD(res, i, "payaddress", field, ok); if (!ok) break; - TXT_TO_STR("payaddress", field, row->payaddress); + row->in_payaddress = intransient_str("payaddress", field); PQ_GET_FLD(res, i, "payratio", field, ok); if (!ok) @@ -2248,7 +2248,7 @@ bool paymentaddresses_fill(PGconn *conn) break; TXT_TO_STR("payname", field, row->payname); - HISTORYDATEFLDS(res, i, row, ok); + HISTORYDATEIN(res, i, row, ok); if (!ok) break; @@ -2317,7 +2317,7 @@ bool payments_add(PGconn *conn, bool add, K_ITEM *p_item, K_ITEM **old_p_item, DATA_PAYMENTS(row, p_item); K_RLOCK(payments_free); - *old_p_item = find_payments(row->payoutid, row->userid, row->subname); + *old_p_item = find_payments(row->payoutid, row->userid, row->in_subname); K_RUNLOCK(payments_free); conned = CKPQConn(&conn); @@ -2373,14 +2373,14 @@ bool payments_add(PGconn *conn, bool add, K_ITEM *p_item, K_ITEM **old_p_item, params[par++] = bigint_to_buf(row->paymentid, NULL, 0); params[par++] = bigint_to_buf(row->payoutid, NULL, 0); params[par++] = bigint_to_buf(row->userid, NULL, 0); - params[par++] = str_to_buf(row->subname, NULL, 0); + params[par++] = str_to_buf(row->in_subname, NULL, 0); params[par++] = tv_to_buf(&(row->paydate), NULL, 0); - params[par++] = str_to_buf(row->payaddress, NULL, 0); - params[par++] = str_to_buf(row->originaltxn, NULL, 0); + params[par++] = str_to_buf(row->in_payaddress, NULL, 0); + params[par++] = str_to_buf(row->in_originaltxn, NULL, 0); params[par++] = bigint_to_buf(row->amount, NULL, 0); params[par++] = double_to_buf(row->diffacc, NULL, 0); - params[par++] = str_to_buf(row->committxn, NULL, 0); - params[par++] = str_to_buf(row->commitblockhash, NULL, 0); + params[par++] = str_to_buf(row->in_committxn, NULL, 0); + params[par++] = str_to_buf(row->in_commitblockhash, NULL, 0); HISTORYDATEPARAMSIN(params, par, row); PARCHK(par, params); @@ -2502,7 +2502,7 @@ bool payments_fill(PGconn *conn) PQ_GET_FLD(res, i, "subname", field, ok); if (!ok) break; - TXT_TO_STR("subname", field, row->subname); + row->in_subname = intransient_str("subname", field); PQ_GET_FLD(res, i, "paydate", field, ok); if (!ok) @@ -2512,12 +2512,12 @@ bool payments_fill(PGconn *conn) PQ_GET_FLD(res, i, "payaddress", field, ok); if (!ok) break; - TXT_TO_STR("payaddress", field, row->payaddress); + row->in_payaddress = intransient_str("payaddress", field); PQ_GET_FLD(res, i, "originaltxn", field, ok); if (!ok) break; - TXT_TO_STR("originaltxn", field, row->originaltxn); + row->in_originaltxn = intransient_str("originaltxn", field); PQ_GET_FLD(res, i, "amount", field, ok); if (!ok) @@ -2532,12 +2532,12 @@ bool payments_fill(PGconn *conn) PQ_GET_FLD(res, i, "committxn", field, ok); if (!ok) break; - TXT_TO_STR("committxn", field, row->committxn); + row->in_committxn = intransient_str("committxn", field); PQ_GET_FLD(res, i, "commitblockhash", field, ok); if (!ok) break; - TXT_TO_STR("commitblockhash", field, row->commitblockhash); + row->in_commitblockhash = intransient_str("commitblockhash", field); HISTORYDATEIN(res, i, row, ok); if (!ok) @@ -7783,7 +7783,7 @@ void ips_add(char *group, char *ip, char *eventname, bool is_event, char *des, } // TODO: discard them from RAM -bool auths_add(PGconn *conn, char *poolinstance, char *username, +bool auths_add(PGconn *conn, char *poolinstance, INTRANSIENT *in_username, INTRANSIENT *in_workername, char *clientid, char *enonce1, char *useragent, char *preauth, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root, @@ -7807,17 +7807,17 @@ bool auths_add(PGconn *conn, char *poolinstance, char *username, bzero(row, sizeof(*row)); K_RLOCK(users_free); - u_item = find_users(username); + u_item = find_users(in_username->str); K_RUNLOCK(users_free); if (!u_item) { if (addressuser) { - u_item = users_add(conn, username, EMPTY, EMPTY, + u_item = users_add(conn, in_username, EMPTY, EMPTY, USER_ADDRESS, by, code, inet, cd, trf_root); } else { LOGDEBUG("%s(): unknown user '%s'", __func__, - st = safe_text_nonull(username)); + st = safe_text_nonull(in_username->str)); FREENULL(st); if (!reload_data) *event = events_add(EVENTID_INVAUTH, trf_root);