forked from github/server
store passwords in swapdb
This commit is contained in:
parent
83959c375f
commit
32009b7043
9 changed files with 31 additions and 24 deletions
|
@ -432,7 +432,7 @@ static int tolua_faction_create(lua_State * L)
|
||||||
static int tolua_faction_get_password(lua_State * L)
|
static int tolua_faction_get_password(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||||
tolua_pushstring(L, self->_password);
|
tolua_pushstring(L, faction_getpassword(self));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,9 @@ int gamedb_update(void)
|
||||||
err = db_driver_open(DB_GAME, dbname);
|
err = db_driver_open(DB_GAME, dbname);
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
for (f = factions; f; f = f->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
int uid = db_driver_faction_save(f->uid, f->no, turn, f->email, f->_password);
|
int uid = db_driver_faction_save(f->uid, f->no, turn,
|
||||||
|
faction_getemail(f),
|
||||||
|
faction_getpassword(f));
|
||||||
if (uid > 0) {
|
if (uid > 0) {
|
||||||
f->uid = uid;
|
f->uid = uid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,9 +51,13 @@ static void test_update_faction(CuTest *tc) {
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
uid = db_driver_faction_save(f->uid, f->no, 0, f->email, f->_password);
|
uid = db_driver_faction_save(f->uid, f->no, 0,
|
||||||
|
faction_getemail(f),
|
||||||
|
faction_getpassword(f));
|
||||||
f->uid = uid;
|
f->uid = uid;
|
||||||
uid = db_driver_faction_save(f->uid, f->no, 0, f->email, f->_password);
|
uid = db_driver_faction_save(f->uid, f->no, 0,
|
||||||
|
faction_getemail(f),
|
||||||
|
faction_getpassword(f));
|
||||||
CuAssertIntEquals(tc, f->uid, uid);
|
CuAssertIntEquals(tc, f->uid, uid);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "calendar.h"
|
#include "calendar.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "database.h"
|
||||||
#include "alliance.h"
|
#include "alliance.h"
|
||||||
#include "ally.h"
|
#include "ally.h"
|
||||||
#include "curse.h"
|
#include "curse.h"
|
||||||
|
@ -106,7 +107,6 @@ static void free_faction(faction * f)
|
||||||
|
|
||||||
free(f->email);
|
free(f->email);
|
||||||
free(f->banner);
|
free(f->banner);
|
||||||
free(f->_password);
|
|
||||||
free(f->name);
|
free(f->name);
|
||||||
if (f->seen_factions) {
|
if (f->seen_factions) {
|
||||||
selist_free(f->seen_factions);
|
selist_free(f->seen_factions);
|
||||||
|
@ -245,7 +245,7 @@ faction *addfaction(const char *email, const char *password,
|
||||||
f->alliance_joindate = turn;
|
f->alliance_joindate = turn;
|
||||||
f->lastorders = turn;
|
f->lastorders = turn;
|
||||||
f->_alive = true;
|
f->_alive = true;
|
||||||
f->_password = NULL;
|
f->password_id = 0;
|
||||||
f->age = 0;
|
f->age = 0;
|
||||||
f->race = frace;
|
f->race = frace;
|
||||||
f->magiegebiet = 0;
|
f->magiegebiet = 0;
|
||||||
|
@ -321,9 +321,11 @@ unit *addplayer(region * r, faction * f)
|
||||||
|
|
||||||
bool checkpasswd(const faction * f, const char *passwd)
|
bool checkpasswd(const faction * f, const char *passwd)
|
||||||
{
|
{
|
||||||
|
const char *pwhash;
|
||||||
if (!passwd) return false;
|
if (!passwd) return false;
|
||||||
|
|
||||||
if (f->_password && password_verify(f->_password, passwd) == VERIFY_FAIL) {
|
pwhash = faction_getpassword(f);
|
||||||
|
if (pwhash && password_verify(pwhash, passwd) == VERIFY_FAIL) {
|
||||||
log_info("password check failed: %s", factionname(f));
|
log_info("password check failed: %s", factionname(f));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -603,11 +605,17 @@ void faction_setbanner(faction * self, const char *banner)
|
||||||
self->banner = str_strdup(banner);
|
self->banner = str_strdup(banner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *faction_getpassword(const faction *f) {
|
||||||
|
if (f->password_id > 0) {
|
||||||
|
return dbstring_load(f->password_id, NULL);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void faction_setpassword(faction * f, const char *pwhash)
|
void faction_setpassword(faction * f, const char *pwhash)
|
||||||
{
|
{
|
||||||
assert(pwhash);
|
assert(pwhash);
|
||||||
free(f->_password);
|
f->password_id = dbstring_save(pwhash);
|
||||||
f->_password = str_strdup(pwhash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool valid_race(const struct faction *f, const struct race *rc)
|
bool valid_race(const struct faction *f, const struct race *rc)
|
||||||
|
@ -844,7 +852,8 @@ int writepasswd(void)
|
||||||
|
|
||||||
for (f = factions; f; f = f->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
fprintf(F, "%s:%s:%s:%d\n",
|
fprintf(F, "%s:%s:%s:%d\n",
|
||||||
itoa36(f->no), faction_getemail(f), f->_password, f->uid);
|
itoa36(f->no), faction_getemail(f),
|
||||||
|
faction_getpassword(f), f->uid);
|
||||||
}
|
}
|
||||||
fclose(F);
|
fclose(F);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "skill.h"
|
#include "skill.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "db/driver.h"
|
||||||
|
|
||||||
#include <util/resolve.h>
|
#include <util/resolve.h>
|
||||||
#include <modules/score.h>
|
#include <modules/score.h>
|
||||||
|
@ -72,7 +73,7 @@ extern "C" {
|
||||||
char *name;
|
char *name;
|
||||||
char *banner;
|
char *banner;
|
||||||
char *email;
|
char *email;
|
||||||
char *_password;
|
dbrow_id password_id;
|
||||||
int max_spelllevel;
|
int max_spelllevel;
|
||||||
struct spellbook *spellbook;
|
struct spellbook *spellbook;
|
||||||
const struct locale *locale;
|
const struct locale *locale;
|
||||||
|
@ -154,6 +155,7 @@ extern "C" {
|
||||||
void faction_setemail(struct faction *self, const char *email);
|
void faction_setemail(struct faction *self, const char *email);
|
||||||
|
|
||||||
void faction_setpassword(struct faction *self, const char *pwhash);
|
void faction_setpassword(struct faction *self, const char *pwhash);
|
||||||
|
const char *faction_getpassword(const struct faction *f);
|
||||||
bool valid_race(const struct faction *f, const struct race *rc);
|
bool valid_race(const struct faction *f, const struct race *rc);
|
||||||
|
|
||||||
void faction_getorigin(const struct faction * f, int id, int *x, int *y);
|
void faction_getorigin(const struct faction * f, int id, int *x, int *y);
|
||||||
|
|
|
@ -931,7 +931,6 @@ static void read_password(gamedata *data, faction *f) {
|
||||||
else {
|
else {
|
||||||
faction_setpassword(f, (data->version >= CRYPT_VERSION) ? name : password_hash(name, PASSWORD_DEFAULT));
|
faction_setpassword(f, (data->version >= CRYPT_VERSION) ? name : password_hash(name, PASSWORD_DEFAULT));
|
||||||
}
|
}
|
||||||
(void)_test_read_password;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _test_read_password(gamedata *data, faction *f) {
|
void _test_read_password(gamedata *data, faction *f) {
|
||||||
|
@ -939,8 +938,7 @@ void _test_read_password(gamedata *data, faction *f) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_password(gamedata *data, const faction *f) {
|
static void write_password(gamedata *data, const faction *f) {
|
||||||
WRITE_TOK(data->store, (const char *)f->_password);
|
WRITE_TOK(data->store, faction_getpassword(f));
|
||||||
(void)_test_write_password;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _test_write_password(gamedata *data, const faction *f) {
|
void _test_write_password(gamedata *data, const faction *f) {
|
||||||
|
|
|
@ -432,7 +432,7 @@ static void test_read_password_external(CuTest *tc) {
|
||||||
}
|
}
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
faction_setpassword(f, password_hash("secret", PASSWORD_DEFAULT));
|
faction_setpassword(f, password_hash("secret", PASSWORD_DEFAULT));
|
||||||
CuAssertPtrNotNull(tc, f->_password);
|
CuAssertPtrNotNull(tc, faction_getpassword(f));
|
||||||
mstream_init(&data.strm);
|
mstream_init(&data.strm);
|
||||||
gamedata_init(&data, &store, RELEASE_VERSION);
|
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||||
WRITE_TOK(data.store, "newpassword");
|
WRITE_TOK(data.store, "newpassword");
|
||||||
|
|
|
@ -1554,14 +1554,6 @@ void prepare_report(report_context *ctx, faction *f)
|
||||||
rule_lighthouse_units = config_get_int("rules.lighthouse.unit_capacity", 0) != 0;
|
rule_lighthouse_units = config_get_int("rules.lighthouse.unit_capacity", 0) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f->age <= 2) {
|
|
||||||
if ((f->flags&FFL_PWMSG) == 0) {
|
|
||||||
/* TODO: this assumes unencrypted passwords */
|
|
||||||
f->flags |= FFL_PWMSG;
|
|
||||||
ADDMSG(&f->msgs, msg_message("changepasswd", "value", f->_password));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->f = f;
|
ctx->f = f;
|
||||||
ctx->report_time = time(NULL);
|
ctx->report_time = time(NULL);
|
||||||
ctx->addresses = NULL;
|
ctx->addresses = NULL;
|
||||||
|
|
|
@ -902,7 +902,7 @@ CuSuite *get_reports_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_region_distance);
|
SUITE_ADD_TEST(suite, test_region_distance);
|
||||||
SUITE_ADD_TEST(suite, test_region_distance_max);
|
SUITE_ADD_TEST(suite, test_region_distance_max);
|
||||||
SUITE_ADD_TEST(suite, test_region_distance_ql);
|
SUITE_ADD_TEST(suite, test_region_distance_ql);
|
||||||
SUITE_ADD_TEST(suite, test_newbie_password_message);
|
DISABLE_TEST(suite, test_newbie_password_message);
|
||||||
SUITE_ADD_TEST(suite, test_prepare_report);
|
SUITE_ADD_TEST(suite, test_prepare_report);
|
||||||
SUITE_ADD_TEST(suite, test_seen_neighbours);
|
SUITE_ADD_TEST(suite, test_seen_neighbours);
|
||||||
SUITE_ADD_TEST(suite, test_seen_travelthru);
|
SUITE_ADD_TEST(suite, test_seen_travelthru);
|
||||||
|
|
Loading…
Reference in a new issue