2016-03-22 01:48:59 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sqlite3.h>
|
|
|
|
#include <ctype.h>
|
2018-05-26 02:35:06 +00:00
|
|
|
#include <openssl/evp.h>
|
2016-03-22 01:48:59 +00:00
|
|
|
#include "bbs.h"
|
|
|
|
#include "inih/ini.h"
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
|
2018-05-26 02:57:50 +00:00
|
|
|
#define EVP_MD_CTX_new EVP_MD_CTX_create
|
|
|
|
#define EVP_MD_CTX_free EVP_MD_CTX_destroy
|
|
|
|
#endif
|
|
|
|
|
2016-03-22 01:48:59 +00:00
|
|
|
extern struct bbs_config conf;
|
2017-09-21 00:21:51 +00:00
|
|
|
extern struct user_record *gUser;
|
2016-03-22 01:48:59 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
static void open_users_db_or_die(sqlite3 **db) {
|
2018-10-18 02:04:51 +00:00
|
|
|
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);";
|
2018-10-15 18:19:54 +00:00
|
|
|
char buffer[PATH_MAX];
|
|
|
|
snprintf(buffer, PATH_MAX, "%s/users.sq3", conf.bbs_path);
|
|
|
|
if (sqlite3_open(buffer, db) != SQLITE_OK) {
|
|
|
|
dolog("Cannot open database: %s", sqlite3_errmsg(*db));
|
|
|
|
sqlite3_close(*db);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
assert(db != NULL);
|
|
|
|
sqlite3_busy_timeout(*db, 5000);
|
2018-10-18 02:13:10 +00:00
|
|
|
rc = sqlite3_exec(*db, create_sql, 0, 0, &err_msg);
|
2018-10-18 02:04:51 +00:00
|
|
|
if (rc != SQLITE_OK) {
|
|
|
|
dolog("SQL error: %s", err_msg);
|
|
|
|
sqlite3_free(err_msg);
|
2018-10-18 02:13:10 +00:00
|
|
|
sqlite3_close(*db);
|
2018-10-18 02:04:51 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2018-10-15 18:19:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-04 11:41:37 +00:00
|
|
|
char *hash_sha256(char *pass, char *salt) {
|
2018-10-09 15:55:13 +00:00
|
|
|
char *buffer = NULL;
|
2018-05-26 02:35:06 +00:00
|
|
|
char *shash = NULL;
|
|
|
|
unsigned char hash[EVP_MAX_MD_SIZE];
|
|
|
|
unsigned int length_of_hash = 0;
|
|
|
|
int i;
|
2016-08-04 11:41:37 +00:00
|
|
|
|
2018-10-09 15:55:13 +00:00
|
|
|
buffer = str2dup(pass, salt);
|
2016-08-04 11:41:37 +00:00
|
|
|
|
2018-05-26 02:35:06 +00:00
|
|
|
EVP_MD_CTX *context = EVP_MD_CTX_new();
|
|
|
|
|
|
|
|
if (context != NULL) {
|
2018-10-08 14:13:11 +00:00
|
|
|
if (EVP_DigestInit_ex(context, EVP_sha256(), NULL)) {
|
|
|
|
if (EVP_DigestUpdate(context, buffer, strlen(buffer))) {
|
|
|
|
if (EVP_DigestFinal_ex(context, hash, &length_of_hash)) {
|
2018-10-15 18:19:54 +00:00
|
|
|
stralloc shash = EMPTY_STRALLOC;
|
|
|
|
for (i = 0; i < length_of_hash; i++)
|
|
|
|
stralloc_cat_byte(&shash, hash[i]);
|
|
|
|
stralloc_0(&shash);
|
2018-05-26 02:35:06 +00:00
|
|
|
EVP_MD_CTX_free(context);
|
|
|
|
free(buffer);
|
2018-10-15 18:19:54 +00:00
|
|
|
return shash.s;
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2018-05-26 02:35:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EVP_MD_CTX_free(context);
|
2016-08-04 11:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(buffer);
|
2018-05-26 02:35:06 +00:00
|
|
|
dolog("Error creating hash!");
|
|
|
|
exit(-1);
|
2016-08-04 11:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gen_salt(char **s) {
|
|
|
|
FILE *fptr;
|
|
|
|
int i;
|
|
|
|
char c;
|
2018-10-09 15:55:13 +00:00
|
|
|
*s = (char *)malloz(11);
|
2016-08-04 11:41:37 +00:00
|
|
|
|
|
|
|
char *salt = *s;
|
|
|
|
|
|
|
|
if (!salt) {
|
|
|
|
dolog("Out of memory..");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
fptr = fopen("/dev/urandom", "rb");
|
|
|
|
if (!fptr) {
|
|
|
|
dolog("Unable to open /dev/urandom!");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
for (i = 0; i < 10; i++) {
|
2016-08-04 11:41:37 +00:00
|
|
|
fread(&c, 1, 1, fptr);
|
|
|
|
salt[i] = (char)((abs(c) % 93) + 33);
|
|
|
|
}
|
|
|
|
fclose(fptr);
|
|
|
|
salt[10] = '\0';
|
|
|
|
}
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
static int secLevel(void *user, const char *section, const char *name,
|
|
|
|
const char *value) {
|
2016-03-22 01:48:59 +00:00
|
|
|
struct sec_level_t *conf = (struct sec_level_t *)user;
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-03-22 01:48:59 +00:00
|
|
|
if (strcasecmp(section, "main") == 0) {
|
|
|
|
if (strcasecmp(name, "time per day") == 0) {
|
|
|
|
conf->timeperday = atoi(value);
|
2016-08-04 09:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-22 01:48:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int save_user(struct user_record *user) {
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3 *db = NULL;
|
|
|
|
sqlite3_stmt *res = NULL;
|
|
|
|
int rc = 0;
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
const char *update_sql =
|
2018-10-16 15:21:42 +00:00
|
|
|
"UPDATE users SET password=?, salt=?, firstname=?,"
|
|
|
|
"lastname=?, email=?, location=?, sec_level=?, last_on=?, "
|
|
|
|
"time_left=?, cur_mail_conf=?, cur_mail_area=?, "
|
|
|
|
"cur_file_dir=?, cur_file_sub=?, times_on=?, bwavepktno=?, "
|
|
|
|
"archiver=?, protocol=?,nodemsgs=?,codepage=?,exteditor=?,"
|
|
|
|
"bwavestyle=?,signature=?,autosig=? where loginname LIKE ?";
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
open_users_db_or_die(&db);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, update_sql, -1, &res, 0);
|
2016-03-22 01:48:59 +00:00
|
|
|
if (rc != SQLITE_OK) {
|
2018-10-15 18:19:54 +00:00
|
|
|
dolog("Failed to prepare statement: %s", sqlite3_errmsg(db));
|
2018-10-08 14:13:11 +00:00
|
|
|
sqlite3_close(db);
|
|
|
|
exit(1);
|
|
|
|
}
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3_bind_text(res, 1, user->password, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 2, user->salt, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 3, user->firstname, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 4, user->lastname, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 5, user->email, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 6, user->location, -1, 0);
|
|
|
|
sqlite3_bind_int(res, 7, user->sec_level);
|
|
|
|
sqlite3_bind_int(res, 8, user->laston);
|
|
|
|
sqlite3_bind_int(res, 9, user->timeleft);
|
|
|
|
sqlite3_bind_int(res, 10, user->cur_mail_conf);
|
|
|
|
sqlite3_bind_int(res, 11, user->cur_mail_area);
|
|
|
|
sqlite3_bind_int(res, 12, user->cur_file_dir);
|
|
|
|
sqlite3_bind_int(res, 13, user->cur_file_sub);
|
|
|
|
sqlite3_bind_int(res, 14, user->timeson);
|
|
|
|
sqlite3_bind_int(res, 15, user->bwavepktno);
|
|
|
|
sqlite3_bind_int(res, 16, user->defarchiver);
|
|
|
|
sqlite3_bind_int(res, 17, user->defprotocol);
|
|
|
|
sqlite3_bind_int(res, 18, user->nodemsgs);
|
|
|
|
sqlite3_bind_int(res, 19, user->codepage);
|
|
|
|
sqlite3_bind_int(res, 20, user->exteditor);
|
|
|
|
sqlite3_bind_int(res, 21, user->bwavestyle);
|
|
|
|
sqlite3_bind_text(res, 22, user->signature, -1, 0);
|
|
|
|
sqlite3_bind_int(res, 23, user->autosig);
|
|
|
|
sqlite3_bind_text(res, 24, user->loginname, -1, 0);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
rc = sqlite3_step(res);
|
|
|
|
if (rc != SQLITE_DONE) {
|
2018-02-10 06:01:30 +00:00
|
|
|
sqlite3_finalize(res);
|
2018-10-08 14:13:11 +00:00
|
|
|
dolog("execution failed: %s", sqlite3_errmsg(db));
|
2016-08-04 09:25:49 +00:00
|
|
|
sqlite3_close(db);
|
2016-03-22 01:48:59 +00:00
|
|
|
exit(1);
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2018-02-10 06:01:30 +00:00
|
|
|
sqlite3_finalize(res);
|
2016-03-22 01:48:59 +00:00
|
|
|
sqlite3_close(db);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-05-21 22:55:44 +00:00
|
|
|
int msgbase_flag_unflag(struct user_record *user, int conference, int msgbase, int msgid) {
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3 *db = NULL;
|
|
|
|
sqlite3_stmt *res = NULL;
|
|
|
|
int rc = 0;
|
|
|
|
char *err_msg = NULL;
|
2018-10-08 14:13:11 +00:00
|
|
|
int flagunflag = 0;
|
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
static const char *create_sql =
|
2018-10-16 15:21:42 +00:00
|
|
|
"CREATE TABLE IF NOT EXISTS msg_flags (conference INTEGER, msgbase INTEGER, uid INTEGER, msg INTEGER);";
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
flagunflag = msgbase_is_flagged(user, conference, msgbase, msgid);
|
2018-05-21 22:55:44 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
open_users_db_or_die(&db);
|
2018-05-21 22:55:44 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
rc = sqlite3_exec(db, create_sql, 0, 0, &err_msg);
|
|
|
|
if (rc != SQLITE_OK) {
|
2018-05-21 22:55:44 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
dolog("SQL error: %s", err_msg);
|
2018-05-21 22:55:44 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
sqlite3_free(err_msg);
|
|
|
|
sqlite3_close(db);
|
2018-05-21 22:55:44 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (flagunflag == 1) {
|
2018-10-15 18:19:54 +00:00
|
|
|
static const char *unflag_buf =
|
2018-10-16 15:21:42 +00:00
|
|
|
"DELETE FROM msg_flags WHERE conference=? AND msgbase=? AND uid=? AND msg=?";
|
2018-05-21 22:55:44 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, unflag_buf, -1, &res, 0);
|
|
|
|
} else {
|
2018-10-15 18:19:54 +00:00
|
|
|
static const char *flag_buf =
|
2018-10-16 15:21:42 +00:00
|
|
|
"INSERT INTO msg_flags (conference, msgbase, uid, msg) VALUES(?, ?, ?, ?)";
|
2018-05-21 22:55:44 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, flag_buf, -1, &res, 0);
|
|
|
|
}
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
sqlite3_bind_int(res, 1, conference);
|
|
|
|
sqlite3_bind_int(res, 2, msgbase);
|
|
|
|
sqlite3_bind_int(res, 3, user->id);
|
|
|
|
sqlite3_bind_int(res, 4, msgid);
|
|
|
|
|
|
|
|
rc = sqlite3_step(res);
|
|
|
|
|
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
2018-05-21 22:55:44 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int msgbase_is_flagged(struct user_record *user, int conference, int msgbase, int msgid) {
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3 *db = NULL;
|
|
|
|
sqlite3_stmt *res = NULL;
|
|
|
|
int rc = 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
static const char *sql_buf =
|
2018-10-16 15:21:42 +00:00
|
|
|
"SELECT * FROM msg_flags WHERE conference=? AND msgbase=? AND uid=? AND msg=?";
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
open_users_db_or_die(&db);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-05-21 22:55:44 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
|
|
|
|
if (rc != SQLITE_OK) {
|
|
|
|
sqlite3_close(db);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
sqlite3_bind_int(res, 1, conference);
|
|
|
|
sqlite3_bind_int(res, 2, msgbase);
|
|
|
|
sqlite3_bind_int(res, 3, user->id);
|
2018-05-21 22:55:44 +00:00
|
|
|
sqlite3_bind_int(res, 4, msgid);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-05-21 22:55:44 +00:00
|
|
|
if (sqlite3_step(res) != SQLITE_ROW) {
|
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
|
|
|
return 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2018-05-21 22:55:44 +00:00
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-09-21 00:21:51 +00:00
|
|
|
int msgbase_sub_unsub(int conference, int msgbase) {
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3 *db = NULL;
|
|
|
|
sqlite3_stmt *res = NULL;
|
|
|
|
int rc = 0;
|
|
|
|
static const char *create_sql =
|
2018-10-16 15:21:42 +00:00
|
|
|
"CREATE TABLE IF NOT EXISTS msg_subs (conference INTEGER, msgbase INTEGER, uid INTEGER);";
|
2018-10-15 18:19:54 +00:00
|
|
|
char *err_msg = NULL;
|
|
|
|
int subunsub = msgbase_is_subscribed(conference, msgbase);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
open_users_db_or_die(&db);
|
2017-09-21 00:21:51 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
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);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (subunsub == 1) {
|
2018-10-15 18:19:54 +00:00
|
|
|
static char *unsub_buf =
|
2018-10-16 15:21:42 +00:00
|
|
|
"DELETE FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?";
|
2017-09-21 00:21:51 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, unsub_buf, -1, &res, 0);
|
|
|
|
} else {
|
2018-10-15 18:19:54 +00:00
|
|
|
static const char *sub_buf =
|
2018-10-16 15:21:42 +00:00
|
|
|
"INSERT INTO msg_subs (conference, msgbase, uid) VALUES(?, ?, ?)";
|
2017-09-21 00:21:51 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, sub_buf, -1, &res, 0);
|
|
|
|
}
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
sqlite3_bind_int(res, 1, conference);
|
|
|
|
sqlite3_bind_int(res, 2, msgbase);
|
|
|
|
sqlite3_bind_int(res, 3, gUser->id);
|
|
|
|
|
|
|
|
rc = sqlite3_step(res);
|
|
|
|
|
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
|
|
|
|
2017-09-21 00:21:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int msgbase_is_subscribed(int conference, int msgbase) {
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3 *db = NULL;
|
|
|
|
sqlite3_stmt *res = NULL;
|
|
|
|
int rc = 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
static const char *sql_buf =
|
2018-10-16 15:21:42 +00:00
|
|
|
"SELECT * FROM msg_subs WHERE conference=? AND msgbase=? AND uid=?";
|
2017-09-21 00:21:51 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
open_users_db_or_die(&db);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2017-09-21 00:21:51 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, sql_buf, -1, &res, 0);
|
|
|
|
if (rc != SQLITE_OK) {
|
|
|
|
sqlite3_close(db);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
sqlite3_bind_int(res, 1, conference);
|
|
|
|
sqlite3_bind_int(res, 2, msgbase);
|
|
|
|
sqlite3_bind_int(res, 3, gUser->id);
|
|
|
|
|
2017-09-21 00:21:51 +00:00
|
|
|
if (sqlite3_step(res) != SQLITE_ROW) {
|
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
|
|
|
return 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2017-09-21 00:21:51 +00:00
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
2018-10-15 18:19:54 +00:00
|
|
|
|
2017-09-21 00:21:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-03-22 01:48:59 +00:00
|
|
|
int inst_user(struct user_record *user) {
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3 *db = NULL;
|
|
|
|
sqlite3_stmt *res = NULL;
|
|
|
|
char *err_msg = NULL;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
static const char *insert_sql =
|
2018-10-16 15:21:42 +00:00
|
|
|
"INSERT INTO users (loginname, password, salt, firstname,"
|
|
|
|
"lastname, email, location, sec_level, last_on, time_left, "
|
|
|
|
"cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, "
|
|
|
|
"times_on, bwavepktno, archiver, protocol, nodemsgs, "
|
|
|
|
"codepage, exteditor, bwavestyle, signature, autosig) "
|
|
|
|
"VALUES(?,?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
open_users_db_or_die(&db);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, insert_sql, -1, &res, 0);
|
2018-10-15 18:19:54 +00:00
|
|
|
if (rc != SQLITE_OK) {
|
2018-10-08 14:13:11 +00:00
|
|
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
|
|
|
sqlite3_close(db);
|
|
|
|
exit(1);
|
|
|
|
}
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 2, user->password, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 3, user->salt, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 4, user->firstname, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 5, user->lastname, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 6, user->email, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 7, user->location, -1, 0);
|
|
|
|
sqlite3_bind_int(res, 8, user->sec_level);
|
|
|
|
sqlite3_bind_int(res, 9, user->laston);
|
|
|
|
sqlite3_bind_int(res, 10, user->timeleft);
|
|
|
|
sqlite3_bind_int(res, 11, user->cur_mail_conf);
|
|
|
|
sqlite3_bind_int(res, 12, user->cur_mail_area);
|
|
|
|
sqlite3_bind_int(res, 13, user->cur_file_dir);
|
|
|
|
sqlite3_bind_int(res, 14, user->cur_file_sub);
|
|
|
|
sqlite3_bind_int(res, 15, user->timeson);
|
|
|
|
sqlite3_bind_int(res, 16, user->bwavepktno);
|
|
|
|
sqlite3_bind_int(res, 17, user->defarchiver);
|
|
|
|
sqlite3_bind_int(res, 18, user->defprotocol);
|
|
|
|
sqlite3_bind_int(res, 19, user->nodemsgs);
|
|
|
|
sqlite3_bind_int(res, 20, user->codepage);
|
|
|
|
sqlite3_bind_int(res, 21, user->exteditor);
|
|
|
|
sqlite3_bind_int(res, 22, user->bwavestyle);
|
|
|
|
sqlite3_bind_text(res, 23, user->signature, -1, 0);
|
|
|
|
sqlite3_bind_int(res, 24, user->autosig);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
rc = sqlite3_step(res);
|
|
|
|
if (rc != SQLITE_DONE) {
|
|
|
|
dolog("execution failed: %s", sqlite3_errmsg(db));
|
2017-09-21 00:21:51 +00:00
|
|
|
sqlite3_close(db);
|
|
|
|
exit(1);
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
user->id = sqlite3_last_insert_rowid(db);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
sqlite3_finalize(res);
|
2016-03-22 01:48:59 +00:00
|
|
|
sqlite3_close(db);
|
2018-10-15 18:19:54 +00:00
|
|
|
|
2016-03-22 01:48:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-08-06 04:36:36 +00:00
|
|
|
struct user_record *check_user_pass(char *loginname, char *password) {
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3 *db = NULL;
|
|
|
|
sqlite3_stmt *res = NULL;
|
|
|
|
int rc = NULL;
|
|
|
|
int pass_ok = 0;
|
|
|
|
char pathbuf[PATH_MAX];
|
|
|
|
|
|
|
|
static const char *sql =
|
2018-10-16 15:21:42 +00:00
|
|
|
"SELECT Id, loginname, password, salt, firstname,"
|
|
|
|
"lastname, email, location, sec_level, last_on, time_left, "
|
|
|
|
"cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, "
|
|
|
|
"times_on, bwavepktno, archiver, protocol,nodemsgs, "
|
|
|
|
"codepage, exteditor, bwavestyle, signature, autosig "
|
|
|
|
"FROM users WHERE loginname LIKE ?";
|
2018-10-15 18:19:54 +00:00
|
|
|
|
|
|
|
open_users_db_or_die(&db);
|
2018-10-08 14:13:11 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
2018-10-15 18:19:54 +00:00
|
|
|
if (rc != SQLITE_OK) {
|
2018-10-08 14:13:11 +00:00
|
|
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
2016-03-22 01:48:59 +00:00
|
|
|
sqlite3_finalize(res);
|
2016-08-04 09:25:49 +00:00
|
|
|
sqlite3_close(db);
|
|
|
|
return NULL;
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3_bind_text(res, 1, loginname, -1, 0);
|
2018-10-08 14:13:11 +00:00
|
|
|
int step = sqlite3_step(res);
|
2018-10-15 18:19:54 +00:00
|
|
|
if (step != SQLITE_ROW) {
|
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
struct user_record *user = malloz(sizeof(struct user_record));
|
|
|
|
user->id = sqlite3_column_int(res, 0);
|
|
|
|
user->loginname = strdup((char *)sqlite3_column_text(res, 1));
|
|
|
|
user->password = strdup((char *)sqlite3_column_text(res, 2));
|
|
|
|
user->salt = strdup((char *)sqlite3_column_text(res, 3));
|
|
|
|
user->firstname = strdup((char *)sqlite3_column_text(res, 4));
|
|
|
|
user->lastname = strdup((char *)sqlite3_column_text(res, 5));
|
|
|
|
user->email = strdup((char *)sqlite3_column_text(res, 6));
|
|
|
|
user->location = strdup((char *)sqlite3_column_text(res, 7));
|
|
|
|
user->sec_level = sqlite3_column_int(res, 8);
|
|
|
|
user->laston = (time_t)sqlite3_column_int(res, 9);
|
|
|
|
user->timeleft = sqlite3_column_int(res, 10);
|
|
|
|
user->cur_mail_conf = sqlite3_column_int(res, 11);
|
|
|
|
user->cur_mail_area = sqlite3_column_int(res, 12);
|
|
|
|
user->cur_file_dir = sqlite3_column_int(res, 13);
|
|
|
|
user->cur_file_sub = sqlite3_column_int(res, 14);
|
|
|
|
user->timeson = sqlite3_column_int(res, 15);
|
|
|
|
user->bwavepktno = sqlite3_column_int(res, 16);
|
|
|
|
user->defarchiver = sqlite3_column_int(res, 17);
|
|
|
|
user->defprotocol = sqlite3_column_int(res, 18);
|
|
|
|
user->nodemsgs = sqlite3_column_int(res, 19);
|
|
|
|
user->codepage = sqlite3_column_int(res, 20);
|
|
|
|
user->exteditor = sqlite3_column_int(res, 21);
|
|
|
|
user->bwavestyle = sqlite3_column_int(res, 22);
|
|
|
|
user->signature = strdup((char *)sqlite3_column_text(res, 23));
|
|
|
|
user->autosig = sqlite3_column_int(res, 24);
|
|
|
|
char *pass_hash = hash_sha256(password, user->salt);
|
|
|
|
|
|
|
|
if (strcmp(pass_hash, user->password) != 0) {
|
|
|
|
free(user->loginname);
|
|
|
|
free(user->firstname);
|
|
|
|
free(user->lastname);
|
|
|
|
free(user->email);
|
|
|
|
free(user->location);
|
|
|
|
free(user->salt);
|
|
|
|
free(user->signature);
|
|
|
|
free(user);
|
2016-08-04 11:41:37 +00:00
|
|
|
free(pass_hash);
|
2016-03-22 01:48:59 +00:00
|
|
|
sqlite3_finalize(res);
|
2016-08-04 09:25:49 +00:00
|
|
|
sqlite3_close(db);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-10-15 18:19:54 +00:00
|
|
|
free(pass_hash);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-09 15:55:13 +00:00
|
|
|
user->sec_info = (struct sec_level_t *)malloz(sizeof(struct sec_level_t));
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
snprintf(pathbuf, sizeof pathbuf, "%s/s%d.ini", conf.config_path, user->sec_level);
|
|
|
|
if (ini_parse(pathbuf, secLevel, user->sec_info) < 0) {
|
|
|
|
dolog("Unable to load sec Level ini (%s)!", pathbuf);
|
2016-03-22 01:48:59 +00:00
|
|
|
exit(-1);
|
2016-08-04 09:25:49 +00:00
|
|
|
}
|
2018-10-16 15:05:15 +00:00
|
|
|
if (user->cur_mail_conf >= ptr_vector_len(&conf.mail_conferences)) {
|
2016-03-24 07:23:42 +00:00
|
|
|
user->cur_mail_conf = 0;
|
|
|
|
}
|
2018-10-16 15:05:15 +00:00
|
|
|
if (user->cur_file_dir >= ptr_vector_len(&conf.file_directories)) {
|
2016-03-24 07:23:42 +00:00
|
|
|
user->cur_file_dir = 0;
|
|
|
|
}
|
2018-10-16 15:05:15 +00:00
|
|
|
struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, user->cur_mail_conf);
|
|
|
|
assert(mc != NULL);
|
|
|
|
if (user->cur_mail_area >= ptr_vector_len(&mc->mail_areas)) {
|
2016-03-24 07:23:42 +00:00
|
|
|
user->cur_mail_area = 0;
|
|
|
|
}
|
2018-10-16 15:05:15 +00:00
|
|
|
struct file_directory *dir = ptr_vector_get(&conf.file_directories, user->cur_file_dir);
|
|
|
|
assert(dir != NULL);
|
|
|
|
if (user->cur_file_sub >= ptr_vector_len(&dir->file_subs)) {
|
2016-03-24 07:23:42 +00:00
|
|
|
user->cur_file_sub = 0;
|
|
|
|
}
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
return user;
|
2016-03-22 01:48:59 +00:00
|
|
|
}
|
|
|
|
|
2016-08-06 04:36:36 +00:00
|
|
|
void list_users(struct user_record *user) {
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3 *db = NULL;
|
|
|
|
sqlite3_stmt *res = NULL;
|
|
|
|
int rc = 0;
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
static const char *sql = "SELECT loginname,location,times_on FROM users";
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
open_users_db_or_die(&db);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
2016-03-23 06:31:00 +00:00
|
|
|
if (rc != SQLITE_OK) {
|
2018-10-08 14:13:11 +00:00
|
|
|
dolog("Cannot prepare statement: %s", sqlite3_errmsg(db));
|
|
|
|
sqlite3_close(db);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
s_printf(get_string(161));
|
|
|
|
s_printf(get_string(162));
|
|
|
|
s_printf(get_string(163));
|
2018-10-15 18:19:54 +00:00
|
|
|
for (int i = 0; sqlite3_step(res) == SQLITE_ROW; ++i) {
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(164), sqlite3_column_text(res, 0), sqlite3_column_text(res, 1), sqlite3_column_int(res, 2));
|
2016-03-23 06:31:00 +00:00
|
|
|
if (i == 20) {
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(6));
|
2016-08-06 04:36:36 +00:00
|
|
|
s_getc();
|
2016-03-23 06:31:00 +00:00
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
s_printf(get_string(165));
|
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
s_printf(get_string(6));
|
2016-08-06 04:36:36 +00:00
|
|
|
s_getc();
|
2016-03-23 06:31:00 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 06:48:33 +00:00
|
|
|
int check_fullname(char *firstname, char *lastname) {
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3 *db = NULL;
|
|
|
|
sqlite3_stmt *res = NULL;
|
|
|
|
int rc = 0;
|
2018-01-06 06:48:33 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
static const char *sql =
|
2018-10-16 15:21:42 +00:00
|
|
|
"SELECT * FROM users WHERE firstname = ? AND lastname = ?";
|
2018-01-06 06:48:33 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
open_users_db_or_die(&db);
|
2018-10-08 14:13:11 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
2018-10-15 18:19:54 +00:00
|
|
|
if (rc != SQLITE_OK) {
|
|
|
|
dolog("Failed to prepare statement: %s", sqlite3_errmsg(db));
|
2018-01-06 06:48:33 +00:00
|
|
|
sqlite3_close(db);
|
|
|
|
return 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3_bind_text(res, 1, firstname, -1, 0);
|
|
|
|
sqlite3_bind_text(res, 2, lastname, -1, 0);
|
|
|
|
int step = sqlite3_step(res);
|
2018-10-08 14:13:11 +00:00
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
2018-10-15 18:19:54 +00:00
|
|
|
|
2018-10-18 01:50:56 +00:00
|
|
|
return (!(step == SQLITE_ROW));
|
2018-01-06 06:48:33 +00:00
|
|
|
}
|
|
|
|
|
2016-03-22 01:48:59 +00:00
|
|
|
int check_user(char *loginname) {
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3 *db = NULL;
|
|
|
|
sqlite3_stmt *res = NULL;
|
|
|
|
int rc = 0;
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
static const char *sql = "SELECT * FROM users WHERE loginname = ?";
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-15 18:19:54 +00:00
|
|
|
open_users_db_or_die(&db);
|
2018-10-08 14:13:11 +00:00
|
|
|
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
2018-10-15 18:19:54 +00:00
|
|
|
if (rc != SQLITE_OK) {
|
2018-10-08 14:13:11 +00:00
|
|
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
2016-03-22 01:48:59 +00:00
|
|
|
sqlite3_close(db);
|
2018-10-15 18:19:54 +00:00
|
|
|
return 1;
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2018-10-15 18:19:54 +00:00
|
|
|
sqlite3_bind_text(res, 1, loginname, -1, 0);
|
|
|
|
int step = sqlite3_step(res);
|
2018-10-08 14:13:11 +00:00
|
|
|
sqlite3_finalize(res);
|
|
|
|
sqlite3_close(db);
|
2018-10-15 18:19:54 +00:00
|
|
|
|
|
|
|
return (step != SQLITE_ROW);
|
2016-03-22 01:48:59 +00:00
|
|
|
}
|
|
|
|
|
2016-08-06 04:36:36 +00:00
|
|
|
struct user_record *new_user() {
|
2018-02-16 11:35:09 +00:00
|
|
|
char buffer[PATH_MAX];
|
2016-03-22 01:48:59 +00:00
|
|
|
struct user_record *user;
|
|
|
|
int done = 0;
|
|
|
|
char c;
|
|
|
|
int nameok = 0;
|
|
|
|
int passok = 0;
|
2016-03-28 07:26:42 +00:00
|
|
|
int i;
|
2018-01-06 06:48:33 +00:00
|
|
|
int fullnameok = 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-09 15:55:13 +00:00
|
|
|
user = (struct user_record *)malloz(sizeof(struct user_record));
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf("\r\n\r\n");
|
|
|
|
s_displayansi("newuser");
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-03-22 01:48:59 +00:00
|
|
|
do {
|
|
|
|
passok = 0;
|
|
|
|
nameok = 0;
|
|
|
|
do {
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(166));
|
2016-08-06 04:36:36 +00:00
|
|
|
s_readstring(buffer, 16);
|
|
|
|
s_printf("\r\n");
|
2018-02-14 10:49:26 +00:00
|
|
|
if (strlen(buffer) < 2) {
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(167));
|
2016-03-22 01:48:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-01-06 05:59:35 +00:00
|
|
|
if (buffer[0] == ' ' || buffer[strlen(buffer) - 1] == ' ') {
|
|
|
|
s_printf(get_string(240));
|
|
|
|
continue;
|
|
|
|
}
|
2018-10-15 18:19:54 +00:00
|
|
|
for (const char *p = buffer; *p != '\0'; ++p) {
|
|
|
|
if (!(tolower(*p) >= 97 && tolower(*p) <= 122) && *p != 32 && !(*p >= '0' && *p <= '9')) {
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(168));
|
2016-03-28 07:26:42 +00:00
|
|
|
nameok = 1;
|
2016-08-04 09:25:49 +00:00
|
|
|
break;
|
2016-03-28 07:26:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nameok == 1) {
|
|
|
|
nameok = 0;
|
|
|
|
continue;
|
2016-03-22 01:48:59 +00:00
|
|
|
}
|
|
|
|
if (strcasecmp(buffer, "unknown") == 0) {
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(169));
|
2016-08-04 09:25:49 +00:00
|
|
|
continue;
|
2016-03-22 01:48:59 +00:00
|
|
|
}
|
2016-04-03 05:26:25 +00:00
|
|
|
if (strcasecmp(buffer, "all") == 0) {
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(169));
|
2016-08-04 09:25:49 +00:00
|
|
|
continue;
|
2016-04-03 05:26:25 +00:00
|
|
|
}
|
2016-04-03 06:42:14 +00:00
|
|
|
if (strcasecmp(buffer, "new") == 0) {
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(169));
|
2016-08-04 09:25:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-03-22 03:00:41 +00:00
|
|
|
if (strcasecmp(buffer, "anonymous") == 0) {
|
|
|
|
s_printf(get_string(169));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcasecmp(buffer, "ftp") == 0) {
|
|
|
|
s_printf(get_string(169));
|
|
|
|
continue;
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2016-03-22 01:48:59 +00:00
|
|
|
user->loginname = strdup(buffer);
|
|
|
|
nameok = check_user(user->loginname);
|
|
|
|
if (!nameok) {
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(170));
|
2016-03-22 01:48:59 +00:00
|
|
|
free(user->loginname);
|
|
|
|
memset(buffer, 0, 256);
|
|
|
|
}
|
|
|
|
} while (!nameok);
|
2018-01-06 06:48:33 +00:00
|
|
|
do {
|
|
|
|
nameok = 0;
|
|
|
|
do {
|
|
|
|
s_printf(get_string(171));
|
|
|
|
memset(buffer, 0, 256);
|
|
|
|
s_readstring(buffer, 32);
|
|
|
|
if (buffer[0] == ' ' || buffer[strlen(buffer) - 1] == ' ') {
|
|
|
|
s_printf(get_string(241));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strlen(buffer) == 0) {
|
|
|
|
s_printf(get_string(167));
|
|
|
|
continue;
|
|
|
|
}
|
2018-01-07 12:59:39 +00:00
|
|
|
if (strchr(buffer, ' ') != NULL) {
|
|
|
|
s_printf(get_string(244));
|
|
|
|
continue;
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2018-01-06 06:48:33 +00:00
|
|
|
s_printf("\r\n");
|
|
|
|
user->firstname = strdup(buffer);
|
|
|
|
nameok = 1;
|
|
|
|
} while (!nameok);
|
|
|
|
nameok = 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
|
|
|
|
do {
|
2018-01-06 06:48:33 +00:00
|
|
|
s_printf(get_string(172));
|
|
|
|
memset(buffer, 0, 256);
|
|
|
|
s_readstring(buffer, 32);
|
|
|
|
if (buffer[0] == ' ' || buffer[strlen(buffer) - 1] == ' ') {
|
|
|
|
s_printf(get_string(242));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strlen(buffer) == 0) {
|
|
|
|
s_printf(get_string(167));
|
|
|
|
continue;
|
|
|
|
}
|
2018-01-07 12:59:39 +00:00
|
|
|
if (strchr(buffer, ' ') != NULL) {
|
|
|
|
s_printf(get_string(244));
|
|
|
|
continue;
|
|
|
|
}
|
2018-01-06 06:48:33 +00:00
|
|
|
s_printf("\r\n");
|
|
|
|
nameok = 1;
|
|
|
|
user->lastname = strdup(buffer);
|
|
|
|
} while (!nameok);
|
|
|
|
fullnameok = check_fullname(user->firstname, user->lastname);
|
|
|
|
if (!fullnameok) {
|
|
|
|
free(user->firstname);
|
|
|
|
free(user->lastname);
|
2018-01-06 06:51:09 +00:00
|
|
|
s_printf(get_string(243));
|
2018-01-06 06:48:33 +00:00
|
|
|
}
|
|
|
|
} while (!fullnameok);
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(173));
|
2016-03-22 01:48:59 +00:00
|
|
|
memset(buffer, 0, 256);
|
2016-08-06 04:36:36 +00:00
|
|
|
s_readstring(buffer, 64);
|
|
|
|
s_printf("\r\n");
|
2016-03-22 01:48:59 +00:00
|
|
|
user->email = strdup(buffer);
|
|
|
|
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(174));
|
2016-03-22 01:48:59 +00:00
|
|
|
memset(buffer, 0, 256);
|
2016-08-06 04:36:36 +00:00
|
|
|
s_readstring(buffer, 32);
|
|
|
|
s_printf("\r\n");
|
2016-08-04 09:25:49 +00:00
|
|
|
user->location = strdup(buffer);
|
2016-03-22 01:48:59 +00:00
|
|
|
|
|
|
|
do {
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(175));
|
2016-03-22 01:48:59 +00:00
|
|
|
memset(buffer, 0, 256);
|
2016-08-06 04:36:36 +00:00
|
|
|
s_readstring(buffer, 16);
|
|
|
|
s_printf("\r\n");
|
2016-03-22 01:48:59 +00:00
|
|
|
if (strlen(buffer) >= 8) {
|
|
|
|
passok = 1;
|
|
|
|
} else {
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(158));
|
2016-03-22 01:48:59 +00:00
|
|
|
}
|
|
|
|
} while (!passok);
|
2016-08-04 11:41:37 +00:00
|
|
|
gen_salt(&user->salt);
|
2016-08-04 11:43:53 +00:00
|
|
|
user->password = hash_sha256(buffer, user->salt);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(176));
|
|
|
|
s_printf(get_string(177));
|
|
|
|
s_printf(get_string(178));
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf(user->loginname);
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(179));
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf(user->firstname);
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(180));
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf(user->lastname);
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(181));
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf(user->email);
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(182));
|
2016-08-06 04:36:36 +00:00
|
|
|
s_printf(user->location);
|
2016-08-14 09:56:15 +00:00
|
|
|
s_printf(get_string(183));
|
|
|
|
s_printf(get_string(184));
|
2016-08-06 04:36:36 +00:00
|
|
|
c = s_getchar();
|
2016-03-22 01:48:59 +00:00
|
|
|
while (tolower(c) != 'y' && tolower(c) != 'n') {
|
2016-08-06 04:36:36 +00:00
|
|
|
c = s_getchar();
|
2016-03-22 01:48:59 +00:00
|
|
|
}
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-03-22 01:48:59 +00:00
|
|
|
if (tolower(c) == 'y') {
|
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
} while (!done);
|
|
|
|
user->sec_level = conf.newuserlvl;
|
2016-12-06 07:06:28 +00:00
|
|
|
user->bwavepktno = 0;
|
2018-10-09 15:55:13 +00:00
|
|
|
user->sec_info = (struct sec_level_t *)malloz(sizeof(struct sec_level_t));
|
2018-02-16 11:35:09 +00:00
|
|
|
snprintf(buffer, PATH_MAX, "%s/config/s%d.ini", conf.bbs_path, user->sec_level);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
if (ini_parse(buffer, secLevel, user->sec_info) < 0) {
|
2016-08-04 09:25:49 +00:00
|
|
|
dolog("Unable to load sec Level ini (%s)!", buffer);
|
2016-03-22 01:48:59 +00:00
|
|
|
exit(-1);
|
2016-08-04 09:25:49 +00:00
|
|
|
}
|
2016-03-22 01:48:59 +00:00
|
|
|
|
|
|
|
user->laston = time(NULL);
|
|
|
|
user->timeleft = user->sec_info->timeperday;
|
2016-03-23 03:26:12 +00:00
|
|
|
user->cur_file_dir = 0;
|
|
|
|
user->cur_file_sub = 0;
|
|
|
|
user->cur_mail_area = 0;
|
|
|
|
user->cur_mail_conf = 0;
|
2016-03-23 06:31:00 +00:00
|
|
|
user->timeson = 0;
|
2016-12-08 04:08:04 +00:00
|
|
|
user->defprotocol = 1;
|
|
|
|
user->defarchiver = 1;
|
2017-04-19 05:57:29 +00:00
|
|
|
user->nodemsgs = 1;
|
2017-04-23 02:28:01 +00:00
|
|
|
user->codepage = conf.codepage;
|
2017-09-11 06:10:38 +00:00
|
|
|
user->exteditor = 2;
|
2017-10-17 21:36:58 +00:00
|
|
|
user->bwavestyle = 0;
|
2018-01-13 09:17:22 +00:00
|
|
|
user->signature = strdup("");
|
|
|
|
user->autosig = 0;
|
2016-03-22 01:48:59 +00:00
|
|
|
inst_user(user);
|
2016-08-04 09:25:49 +00:00
|
|
|
|
2016-03-22 01:48:59 +00:00
|
|
|
return user;
|
|
|
|
}
|