Add config option for auth cookie support

This commit is contained in:
Gent Semaj 2024-09-05 11:31:49 -04:00
parent a38b14b79a
commit c29899f2b9
Signed by untrusted user: ycc
GPG Key ID: 2D76C57BF6BEADC4
4 changed files with 14 additions and 0 deletions

View File

@ -17,6 +17,8 @@ acceptallcustomnames=true
# should attempts to log into non-existent accounts
# automatically create them?
autocreateaccounts=true
# support logging in with auth cookies?
useauthcookies=false
# how often should everything be flushed to the database?
# the default is 4 minutes
dbsaveinterval=240

View File

@ -112,6 +112,10 @@ void CNLoginServer::login(CNSocket* sock, CNPacketData* data) {
if (isCookieAuth) {
// username encoded in TEGid raw
userLogin = std::string((char*)login->szCookie_TEGid);
// clients that use web login but without proper cookies
// send their passwords instead, so store that
userPassword = std::string((char*)login->szCookie_authid);
} else {
/*
* The std::string -> char* -> std::string maneuver should remove any
@ -121,6 +125,11 @@ void CNLoginServer::login(CNSocket* sock, CNPacketData* data) {
userPassword = std::string(AUTOU16TOU8(login->szPassword).c_str());
}
if (!settings::USEAUTHCOOKIES) {
// use normal login flow
isCookieAuth = false;
}
// check username regex
if (!CNLoginServer::isUsernameGood(userLogin)) {
// send a custom error message

View File

@ -13,6 +13,7 @@ bool settings::SANDBOX = true;
int settings::LOGINPORT = 23000;
bool settings::APPROVEALLNAMES = true;
bool settings::AUTOCREATEACCOUNTS = true;
bool settings::USEAUTHCOOKIES = false;
int settings::DBSAVEINTERVAL = 240;
int settings::SHARDPORT = 23001;
@ -87,6 +88,7 @@ void settings::init() {
LOGINPORT = reader.GetInteger("login", "port", LOGINPORT);
APPROVEALLNAMES = reader.GetBoolean("login", "acceptallcustomnames", APPROVEALLNAMES);
AUTOCREATEACCOUNTS = reader.GetBoolean("login", "autocreateaccounts", AUTOCREATEACCOUNTS);
USEAUTHCOOKIES = reader.GetBoolean("login", "useauthcookies", USEAUTHCOOKIES);
DBSAVEINTERVAL = reader.GetInteger("login", "dbsaveinterval", DBSAVEINTERVAL);
SHARDPORT = reader.GetInteger("shard", "port", SHARDPORT);
SHARDSERVERIP = reader.Get("shard", "ip", SHARDSERVERIP);

View File

@ -8,6 +8,7 @@ namespace settings {
extern int LOGINPORT;
extern bool APPROVEALLNAMES;
extern bool AUTOCREATEACCOUNTS;
extern bool USEAUTHCOOKIES;
extern int DBSAVEINTERVAL;
extern int SHARDPORT;
extern std::string SHARDSERVERIP;