forked from github/server
make the password pseudo-private to faction.c
This commit is contained in:
parent
dc6cc41d2d
commit
b6d44410b7
11 changed files with 51 additions and 94 deletions
|
@ -380,13 +380,6 @@ static int tolua_faction_create(lua_State * L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_get_password(lua_State * L)
|
|
||||||
{
|
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
||||||
tolua_pushstring(L, faction_getpassword(self));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tolua_faction_set_password(lua_State * L)
|
static int tolua_faction_set_password(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||||
|
@ -561,7 +554,7 @@ void tolua_faction_open(lua_State * L)
|
||||||
tolua_variable(L, TOLUA_CAST "heroes", tolua_faction_get_heroes, NULL);
|
tolua_variable(L, TOLUA_CAST "heroes", tolua_faction_get_heroes, NULL);
|
||||||
tolua_variable(L, TOLUA_CAST "maxheroes", tolua_faction_get_maxheroes,
|
tolua_variable(L, TOLUA_CAST "maxheroes", tolua_faction_get_maxheroes,
|
||||||
NULL);
|
NULL);
|
||||||
tolua_variable(L, TOLUA_CAST "password", tolua_faction_get_password,
|
tolua_variable(L, TOLUA_CAST "password", NULL,
|
||||||
tolua_faction_set_password);
|
tolua_faction_set_password);
|
||||||
tolua_variable(L, TOLUA_CAST "email", tolua_faction_get_email,
|
tolua_variable(L, TOLUA_CAST "email", tolua_faction_get_email,
|
||||||
tolua_faction_set_email);
|
tolua_faction_set_email);
|
||||||
|
|
|
@ -104,7 +104,7 @@ static void free_faction(faction * f)
|
||||||
|
|
||||||
free(f->email);
|
free(f->email);
|
||||||
free(f->banner);
|
free(f->banner);
|
||||||
free(f->passw);
|
free(f->_password);
|
||||||
free(f->name);
|
free(f->name);
|
||||||
if (f->seen_factions) {
|
if (f->seen_factions) {
|
||||||
ql_free(f->seen_factions);
|
ql_free(f->seen_factions);
|
||||||
|
@ -251,7 +251,9 @@ faction *addfaction(const char *email, const char *password,
|
||||||
log_warning("Invalid email address for faction %s: %s\n", itoa36(f->no), email);
|
log_warning("Invalid email address for faction %s: %s\n", itoa36(f->no), email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!password) password = itoa36(rng_int());
|
||||||
faction_setpassword(f, password);
|
faction_setpassword(f, password);
|
||||||
|
ADDMSG(&f->msgs, msg_message("changepasswd", "value", password));
|
||||||
|
|
||||||
f->alliance_joindate = turn;
|
f->alliance_joindate = turn;
|
||||||
f->lastorders = turn;
|
f->lastorders = turn;
|
||||||
|
@ -314,8 +316,8 @@ unit *addplayer(region * r, faction * f)
|
||||||
bool checkpasswd(const faction * f, const char *passwd)
|
bool checkpasswd(const faction * f, const char *passwd)
|
||||||
{
|
{
|
||||||
if (!passwd) return false;
|
if (!passwd) return false;
|
||||||
if (strcmp(f->passw, passwd)==0) return true;
|
if (strcmp(f->_password, passwd)==0) return true;
|
||||||
if (unicode_utf8_strcasecmp(f->passw, passwd) == 0) {
|
if (unicode_utf8_strcasecmp(f->_password, passwd) == 0) {
|
||||||
log_warning("case-sensitive password check failed: %s", factionname(f));
|
log_warning("case-sensitive password check failed: %s", factionname(f));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -565,11 +567,9 @@ void faction_setbanner(faction * self, const char *banner)
|
||||||
|
|
||||||
void faction_setpassword(faction * f, const char *passw)
|
void faction_setpassword(faction * f, const char *passw)
|
||||||
{
|
{
|
||||||
free(f->passw);
|
assert(passw);
|
||||||
if (passw)
|
free(f->_password);
|
||||||
f->passw = _strdup(passw);
|
f->_password = _strdup(passw);
|
||||||
else
|
|
||||||
f->passw = _strdup(itoa36(rng_int()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool valid_race(const struct faction *f, const struct race *rc)
|
bool valid_race(const struct faction *f, const struct race *rc)
|
||||||
|
@ -584,11 +584,6 @@ bool valid_race(const struct faction *f, const struct race *rc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *faction_getpassword(const faction * f)
|
|
||||||
{
|
|
||||||
return f->passw;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct alliance *f_get_alliance(const struct faction *f)
|
struct alliance *f_get_alliance(const struct faction *f)
|
||||||
{
|
{
|
||||||
if (f->alliance && !(f->alliance->flags & ALF_NON_ALLIED)) {
|
if (f->alliance && !(f->alliance->flags & ALF_NON_ALLIED)) {
|
||||||
|
@ -853,3 +848,28 @@ faction *dfindhash(int no)
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int writepasswd(void)
|
||||||
|
{
|
||||||
|
FILE *F;
|
||||||
|
char zText[128];
|
||||||
|
|
||||||
|
sprintf(zText, "%s/passwd", basepath());
|
||||||
|
F = fopen(zText, "w");
|
||||||
|
if (!F) {
|
||||||
|
perror(zText);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
faction *f;
|
||||||
|
log_info("writing passwords...");
|
||||||
|
|
||||||
|
for (f = factions; f; f = f->next) {
|
||||||
|
fprintf(F, "%s:%s:%s:%u\n",
|
||||||
|
factionid(f), f->email, f->_password, f->subscription);
|
||||||
|
}
|
||||||
|
fclose(F);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ extern "C" {
|
||||||
char *name;
|
char *name;
|
||||||
char *banner;
|
char *banner;
|
||||||
char *email;
|
char *email;
|
||||||
char *passw;
|
char *_password;
|
||||||
int max_spelllevel;
|
int max_spelllevel;
|
||||||
struct spellbook *spellbook;
|
struct spellbook *spellbook;
|
||||||
const struct locale *locale;
|
const struct locale *locale;
|
||||||
|
@ -121,6 +121,7 @@ extern "C" {
|
||||||
struct faction *addfaction(const char *email, const char *password,
|
struct faction *addfaction(const char *email, const char *password,
|
||||||
const struct race *frace, const struct locale *loc, int subscription);
|
const struct race *frace, const struct locale *loc, int subscription);
|
||||||
bool checkpasswd(const faction * f, const char *passwd);
|
bool checkpasswd(const faction * f, const char *passwd);
|
||||||
|
int writepasswd(void);
|
||||||
void destroyfaction(faction ** f);
|
void destroyfaction(faction ** f);
|
||||||
|
|
||||||
bool faction_alive(const struct faction *f);
|
bool faction_alive(const struct faction *f);
|
||||||
|
@ -152,7 +153,7 @@ extern "C" {
|
||||||
const char *faction_getemail(const struct faction *self);
|
const char *faction_getemail(const struct faction *self);
|
||||||
void faction_setemail(struct faction *self, const char *email);
|
void faction_setemail(struct faction *self, const char *email);
|
||||||
|
|
||||||
const char *faction_getpassword(const struct faction *self);
|
// const char *faction_getpassword(const struct faction *self);
|
||||||
void faction_setpassword(struct faction *self, const char *password);
|
void faction_setpassword(struct faction *self, const char *password);
|
||||||
bool valid_race(const struct faction *f, const struct race *rc);
|
bool valid_race(const struct faction *f, const struct race *rc);
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ static void test_addfaction(CuTest *tc) {
|
||||||
CuAssertPtrEquals(tc, NULL, (void *)f->ursprung);
|
CuAssertPtrEquals(tc, NULL, (void *)f->ursprung);
|
||||||
CuAssertPtrEquals(tc, (void *)factions, (void *)f);
|
CuAssertPtrEquals(tc, (void *)factions, (void *)f);
|
||||||
CuAssertStrEquals(tc, "test@eressea.de", f->email);
|
CuAssertStrEquals(tc, "test@eressea.de", f->email);
|
||||||
CuAssertStrEquals(tc, "hurrdurr", f->passw);
|
CuAssertIntEquals(tc, true, checkpasswd(f, "hurrdurr"));
|
||||||
CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale);
|
CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale);
|
||||||
CuAssertIntEquals(tc, 1234, f->subscription);
|
CuAssertIntEquals(tc, 1234, f->subscription);
|
||||||
CuAssertIntEquals(tc, 0, f->flags);
|
CuAssertIntEquals(tc, 0, f->flags);
|
||||||
|
|
|
@ -1216,7 +1216,7 @@ faction *readfaction(struct gamedata * data)
|
||||||
}
|
}
|
||||||
|
|
||||||
READ_STR(data->store, name, sizeof(name));
|
READ_STR(data->store, name, sizeof(name));
|
||||||
f->passw = _strdup(name);
|
faction_setpassword(f, name);
|
||||||
if (data->version < NOOVERRIDE_VERSION) {
|
if (data->version < NOOVERRIDE_VERSION) {
|
||||||
READ_STR(data->store, 0, 0);
|
READ_STR(data->store, 0, 0);
|
||||||
}
|
}
|
||||||
|
@ -1320,10 +1320,10 @@ void writefaction(struct gamedata *data, const faction * f)
|
||||||
}
|
}
|
||||||
WRITE_INT(data->store, f->alliance_joindate);
|
WRITE_INT(data->store, f->alliance_joindate);
|
||||||
|
|
||||||
WRITE_STR(data->store, (const char *)f->name);
|
WRITE_STR(data->store, f->name);
|
||||||
WRITE_STR(data->store, (const char *)f->banner);
|
WRITE_STR(data->store, f->banner);
|
||||||
WRITE_STR(data->store, f->email);
|
WRITE_STR(data->store, f->email);
|
||||||
WRITE_TOK(data->store, (const char *)f->passw);
|
WRITE_TOK(data->store, f->_password);
|
||||||
WRITE_TOK(data->store, locale_name(f->locale));
|
WRITE_TOK(data->store, locale_name(f->locale));
|
||||||
WRITE_INT(data->store, f->lastorders);
|
WRITE_INT(data->store, f->lastorders);
|
||||||
WRITE_INT(data->store, f->age);
|
WRITE_INT(data->store, f->age);
|
||||||
|
|
63
src/laws.c
63
src/laws.c
|
@ -733,9 +733,6 @@ void nmr_warnings(void)
|
||||||
faction *f, *fa;
|
faction *f, *fa;
|
||||||
#define FRIEND (HELP_GUARD|HELP_MONEY)
|
#define FRIEND (HELP_GUARD|HELP_MONEY)
|
||||||
for (f = factions; f; f = f->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
if (f->age <= 1) {
|
|
||||||
ADDMSG(&f->msgs, msg_message("changepasswd", "value", f->passw));
|
|
||||||
}
|
|
||||||
if (!fval(f, FFL_NOIDLEOUT) && turn > f->lastorders) {
|
if (!fval(f, FFL_NOIDLEOUT) && turn > f->lastorders) {
|
||||||
ADDMSG(&f->msgs, msg_message("nmr_warning", ""));
|
ADDMSG(&f->msgs, msg_message("nmr_warning", ""));
|
||||||
if (turn - f->lastorders == NMRTimeout() - 1) {
|
if (turn - f->lastorders == NMRTimeout() - 1) {
|
||||||
|
@ -2168,16 +2165,13 @@ int password_cmd(unit * u, struct order *ord)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(u->faction->passw);
|
|
||||||
if (!pwok) {
|
if (!pwok) {
|
||||||
cmistake(u, ord, 283, MSG_EVENT);
|
cmistake(u, ord, 283, MSG_EVENT);
|
||||||
u->faction->passw = _strdup(itoa36(rng_int()));
|
strlcpy(pwbuf, itoa36(rng_int()), sizeof(pwbuf));
|
||||||
}
|
|
||||||
else {
|
|
||||||
u->faction->passw = _strdup(pwbuf);
|
|
||||||
}
|
}
|
||||||
|
faction_setpassword(u->faction, pwbuf);
|
||||||
ADDMSG(&u->faction->msgs, msg_message("changepasswd",
|
ADDMSG(&u->faction->msgs, msg_message("changepasswd",
|
||||||
"value", u->faction->passw));
|
"value", pwbuf));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4256,32 +4250,6 @@ static void maintain_buildings_1(region * r)
|
||||||
maintain_buildings(r, false);
|
maintain_buildings(r, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** warn about passwords that are not US ASCII.
|
|
||||||
* even though passwords are technically UTF8 strings, the server receives
|
|
||||||
* them as part of the Subject of an email when reports are requested.
|
|
||||||
* This means that we need to limit them to ASCII characters until that
|
|
||||||
* mechanism has been changed.
|
|
||||||
*/
|
|
||||||
static int warn_password(void)
|
|
||||||
{
|
|
||||||
faction *f;
|
|
||||||
for (f = factions; f; f = f->next) {
|
|
||||||
bool pwok = true;
|
|
||||||
const char *c = f->passw;
|
|
||||||
while (*c && pwok) {
|
|
||||||
if (!isalnum((unsigned char)*c))
|
|
||||||
pwok = false;
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
if (!pwok) {
|
|
||||||
free(f->passw);
|
|
||||||
f->passw = _strdup(itoa36(rng_int()));
|
|
||||||
ADDMSG(&f->msgs, msg_message("illegal_password", "newpass", f->passw));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_processor(void)
|
void init_processor(void)
|
||||||
{
|
{
|
||||||
int p;
|
int p;
|
||||||
|
@ -4463,31 +4431,6 @@ void processorders(void)
|
||||||
/* immer ausführen, wenn neue Sprüche dazugekommen sind, oder sich
|
/* immer ausführen, wenn neue Sprüche dazugekommen sind, oder sich
|
||||||
* Beschreibungen geändert haben */
|
* Beschreibungen geändert haben */
|
||||||
update_spells();
|
update_spells();
|
||||||
warn_password();
|
|
||||||
}
|
|
||||||
|
|
||||||
int writepasswd(void)
|
|
||||||
{
|
|
||||||
FILE *F;
|
|
||||||
char zText[128];
|
|
||||||
|
|
||||||
sprintf(zText, "%s/passwd", basepath());
|
|
||||||
F = fopen(zText, "w");
|
|
||||||
if (!F) {
|
|
||||||
perror(zText);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
faction *f;
|
|
||||||
log_info("writing passwords...");
|
|
||||||
|
|
||||||
for (f = factions; f; f = f->next) {
|
|
||||||
fprintf(F, "%s:%s:%s:%u\n",
|
|
||||||
factionid(f), f->email, f->passw, f->subscription);
|
|
||||||
}
|
|
||||||
fclose(F);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_subscriptions(void)
|
void update_subscriptions(void)
|
||||||
|
|
|
@ -38,7 +38,6 @@ extern "C" {
|
||||||
extern int dropouts[2];
|
extern int dropouts[2];
|
||||||
extern int *age;
|
extern int *age;
|
||||||
|
|
||||||
int writepasswd(void);
|
|
||||||
void demographics(void);
|
void demographics(void);
|
||||||
void immigration(void);
|
void immigration(void);
|
||||||
void update_guards(void);
|
void update_guards(void);
|
||||||
|
|
|
@ -1061,6 +1061,7 @@ static void test_ally_cmd(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
f = test_create_faction(0);
|
f = test_create_faction(0);
|
||||||
|
|
||||||
u->faction->locale = lang = get_or_create_locale("de");
|
u->faction->locale = lang = get_or_create_locale("de");
|
||||||
locale_setstring(lang, parameters[P_NOT], "NICHT");
|
locale_setstring(lang, parameters[P_NOT], "NICHT");
|
||||||
locale_setstring(lang, parameters[P_GUARD], "BEWACHE");
|
locale_setstring(lang, parameters[P_GUARD], "BEWACHE");
|
||||||
|
@ -1105,8 +1106,9 @@ static void test_nmr_warnings(CuTest *tc) {
|
||||||
CuAssertIntEquals(tc, 0, f1->age);
|
CuAssertIntEquals(tc, 0, f1->age);
|
||||||
nmr_warnings();
|
nmr_warnings();
|
||||||
CuAssertPtrNotNull(tc, f1->msgs);
|
CuAssertPtrNotNull(tc, f1->msgs);
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f1->msgs, "changepasswd"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f1->msgs, "nmr_warning"));
|
||||||
CuAssertPtrNotNull(tc, f2->msgs);
|
CuAssertPtrNotNull(tc, f2->msgs);
|
||||||
|
CuAssertPtrNotNull(tc, f2->msgs->begin);
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f2->msgs, "nmr_warning"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f2->msgs, "nmr_warning"));
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(f2->msgs, "nmr_warning_final"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(f2->msgs, "nmr_warning_final"));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
|
|
@ -1427,7 +1427,7 @@ report_template(const char *filename, report_context * ctx, const char *charset)
|
||||||
newline(out);
|
newline(out);
|
||||||
newline(out);
|
newline(out);
|
||||||
|
|
||||||
sprintf(buf, "%s %s \"%s\"", LOC(f->locale, "ERESSEA"), factionid(f), f->passw);
|
sprintf(buf, "%s %s \"password\"", LOC(f->locale, "ERESSEA"), factionid(f));
|
||||||
rps_nowrap(out, buf);
|
rps_nowrap(out, buf);
|
||||||
newline(out);
|
newline(out);
|
||||||
newline(out);
|
newline(out);
|
||||||
|
@ -2112,9 +2112,6 @@ const char *charset)
|
||||||
|
|
||||||
if (f->age <= 2) {
|
if (f->age <= 2) {
|
||||||
const char *s;
|
const char *s;
|
||||||
RENDER(f, buf, sizeof(buf), ("newbie_password", "password", f->passw));
|
|
||||||
newline(out);
|
|
||||||
centre(out, buf, true);
|
|
||||||
s = locale_getstring(f->locale, "newbie_info_1");
|
s = locale_getstring(f->locale, "newbie_info_1");
|
||||||
if (s) {
|
if (s) {
|
||||||
newline(out);
|
newline(out);
|
||||||
|
|
|
@ -45,6 +45,7 @@ static void setup_study(study_fixture *fix, skill_t sk) {
|
||||||
fix->teachers[1] = test_create_unit(f, r);
|
fix->teachers[1] = test_create_unit(f, r);
|
||||||
assert(fix->teachers[1]);
|
assert(fix->teachers[1]);
|
||||||
fix->teachers[1]->thisorder = create_order(K_TEACH, f->locale, "%s", itoa36(fix->u->no));
|
fix->teachers[1]->thisorder = create_order(K_TEACH, f->locale, "%s", itoa36(fix->u->no));
|
||||||
|
test_clear_messages(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_study_no_teacher(CuTest *tc) {
|
static void test_study_no_teacher(CuTest *tc) {
|
||||||
|
|
|
@ -64,6 +64,7 @@ struct region *test_create_region(int x, int y, const terrain_type *terrain)
|
||||||
struct faction *test_create_faction(const struct race *rc)
|
struct faction *test_create_faction(const struct race *rc)
|
||||||
{
|
{
|
||||||
faction *f = addfaction("nobody@eressea.de", NULL, rc ? rc : test_create_race("human"), default_locale, 0);
|
faction *f = addfaction("nobody@eressea.de", NULL, rc ? rc : test_create_race("human"), default_locale, 0);
|
||||||
|
test_clear_messages(f);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue