another fix for new users

This commit is contained in:
Andrew Pamment 2018-10-18 12:04:51 +10:00
parent a681703a76
commit aa2e4bced8

View File

@ -16,6 +16,35 @@ extern struct bbs_config conf;
extern struct user_record *gUser; extern struct user_record *gUser;
static void open_users_db_or_die(sqlite3 **db) { static void open_users_db_or_die(sqlite3 **db) {
char *err_msg = NULL;
int rc = 0;
static const char *create_sql =
"CREATE TABLE IF NOT EXISTS users ("
"Id INTEGER PRIMARY KEY,"
"loginname TEXT COLLATE NOCASE,"
"password TEXT,"
"salt TEXT,"
"firstname TEXT,"
"lastname TEXT,"
"email TEXT,"
"location TEXT,"
"sec_level INTEGER,"
"last_on INTEGER,"
"time_left INTEGER,"
"cur_mail_conf INTEGER,"
"cur_mail_area INTEGER,"
"cur_file_sub INTEGER,"
"cur_file_dir INTEGER,"
"times_on INTEGER,"
"bwavepktno INTEGER,"
"archiver INTEGER,"
"protocol INTEGER,"
"nodemsgs INTEGER,"
"codepage INTEGER,"
"exteditor INTEGER,"
"bwavestyle INTEGER,"
"signature TEXT,"
"autosig INTEGER);";
char buffer[PATH_MAX]; char buffer[PATH_MAX];
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path); snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
if (sqlite3_open(buffer, db) != SQLITE_OK) { if (sqlite3_open(buffer, db) != SQLITE_OK) {
@ -25,6 +54,13 @@ static void open_users_db_or_die(sqlite3 **db) {
} }
assert(db != NULL); assert(db != NULL);
sqlite3_busy_timeout(*db, 5000); sqlite3_busy_timeout(*db, 5000);
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg);
sqlite3_free(err_msg);
sqlite3_close(db);
exit(1);
}
} }
char *hash_sha256(char *pass, char *salt) { char *hash_sha256(char *pass, char *salt) {
@ -310,34 +346,6 @@ int inst_user(struct user_record *user) {
char *err_msg = NULL; char *err_msg = NULL;
int rc = 0; int rc = 0;
static const char *create_sql =
"CREATE TABLE IF NOT EXISTS users ("
"Id INTEGER PRIMARY KEY,"
"loginname TEXT COLLATE NOCASE,"
"password TEXT,"
"salt TEXT,"
"firstname TEXT,"
"lastname TEXT,"
"email TEXT,"
"location TEXT,"
"sec_level INTEGER,"
"last_on INTEGER,"
"time_left INTEGER,"
"cur_mail_conf INTEGER,"
"cur_mail_area INTEGER,"
"cur_file_sub INTEGER,"
"cur_file_dir INTEGER,"
"times_on INTEGER,"
"bwavepktno INTEGER,"
"archiver INTEGER,"
"protocol INTEGER,"
"nodemsgs INTEGER,"
"codepage INTEGER,"
"exteditor INTEGER,"
"bwavestyle INTEGER,"
"signature TEXT,"
"autosig INTEGER);";
static const char *insert_sql = static const char *insert_sql =
"INSERT INTO users (loginname, password, salt, firstname," "INSERT INTO users (loginname, password, salt, firstname,"
"lastname, email, location, sec_level, last_on, time_left, " "lastname, email, location, sec_level, last_on, time_left, "
@ -348,14 +356,6 @@ int inst_user(struct user_record *user) {
open_users_db_or_die(&db); open_users_db_or_die(&db);
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
if (rc != SQLITE_OK) {
dolog("SQL error: %s", err_msg);
sqlite3_free(err_msg);
sqlite3_close(db);
exit(1);
}
rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0); rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); dolog("Failed to execute statement: %s", sqlite3_errmsg(db));