static NEOERR* aux_cmd_memoryget(struct aux_entry *e, QueueEntry *q) { unsigned char *val = NULL; size_t vsize = 0; NEOERR *err; int id = 0; mdb_conn *db = e->db; struct cache *cd = e->cd; REQ_FETCH_PARAM_INT(q->hdfrcv, "id", id); if (m_memory_maxid < 1) return nerr_raise(NERR_ASSERT, "empty memory"); /* * neo_rand() may get 0, so, +1 */ if (id == 0) id = neo_rand(m_memory_maxid) + 1; if (cache_getf(cd, &val, &vsize, PREFIX_MEMORY"%d", id)) { unpack_hdf(val, vsize, &q->hdfsnd); } else { MDB_QUERY_RAW(db, "memory", _COL_MEMORY, "id<=%d AND statu=%d ORDER BY id DESC LIMIT 1", NULL, id, MEMORY_ST_OK); err = mdb_set_row(q->hdfsnd, db, _COL_MEMORY, NULL); if (err != STATUS_OK) return nerr_pass(err); CACHE_HDF(q->hdfsnd, MEMORY_CC_SEC, PREFIX_MEMORY"%d", id); } return STATUS_OK; }
char* user_login_auth(mdb_conn *conn, char *uid, char *pass) { if (!conn || !uid || !pass) return NULL; char *p, *r; int ret, x; mdb_exec(conn, NULL, "SELECT password from account WHERE userid=$1;", "s", uid); if (mdb_get(conn, "s", &p) == MDB_ERR_NONE) { if (!strcmp(p, pass)) { r = calloc(1, LEN_SKEY+1); for (x = 0; x < LEN_SKEY; x++) { r[x] = (char)(65 + neo_rand(90-65)); } r[x] = '\0'; ret = mdb_exec(conn, NULL, "UPDATE account SET skey='$1' WHERE " " userid=$2;", "ss", r, uid); if (ret != MDB_ERR_NONE) { mtc_err("exec failure %s", mdb_get_errmsg(conn)); free(r); return NULL; } return r; } } return NULL; }
static void gen_ml_break(char *ml, size_t len) { int nlen; int x = 0; ml[x++] = '\n'; nlen = 2 + neo_rand(len-5); if (nlen == 0) { nlen = len / 2; } while (nlen) { ml[x++] = ('A' + neo_rand(26)); nlen--; } ml[x++] = '\n'; ml[x] = '\0'; }
int rand_name (char *s, int slen) { char buf[256]; int x, m, l, rl; m = neo_rand(10); while (1) { neo_rand_word(s, slen); if (!strchr(s, '.') && !strchr(s, '\'')) break; } for (x = 1; x < m; x++) { l = strlen(s); neo_rand_word(buf, sizeof(buf)); rl = strlen(buf); /* fprintf(stderr, "%s\n", buf); */ if (rl && slen - l - rl > 1 && !strchr(buf, '.') && ! strchr(buf, '\'')) { snprintf(s + l, slen - l, ".%s", buf); } } return 0; }