Skip to content

Commit a57d83b

Browse files
committedJul 21, 2015
Ask auth handler to create auth when a default password is set
-> Fix server crash with protocol >=25 if a default password is set. -> Remove some useless and possibly confusion causing code for the TOCLIENT_FIRST_SRP packet handler
1 parent 403e6e6 commit a57d83b

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed
 

Diff for: ‎src/clientiface.h

+2
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class RemoteClient
232232

233233
/* Authentication information */
234234
std::string enc_pwd;
235+
bool create_player_on_auth_success;
235236
AuthMechanism chosen_mech;
236237
void * auth_data;
237238
u32 allowed_auth_mechs;
@@ -246,6 +247,7 @@ class RemoteClient
246247
peer_id(PEER_ID_INEXISTENT),
247248
serialization_version(SER_FMT_VER_INVALID),
248249
net_proto_version(0),
250+
create_player_on_auth_success(false),
249251
chosen_mech(AUTH_MECHANISM_NONE),
250252
auth_data(NULL),
251253
m_time_from_building(9999),

Diff for: ‎src/network/serverpackethandler.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
263263
// Take care of default passwords.
264264
client->enc_pwd = getSRPVerifier(playerName, default_password);
265265
auth_mechs |= AUTH_MECHANISM_SRP;
266+
// Create auth, but only on successful login
267+
client->create_player_on_auth_success = true;
266268
}
267269
}
268270

@@ -1858,14 +1860,8 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt)
18581860
}
18591861

18601862
std::string initial_ver_key;
1861-
std::string raw_default_password = g_settings->get("default_password");
1862-
// If default_password is empty, allow any initial password
1863-
if (raw_default_password.length() == 0) {
1864-
initial_ver_key = encodeSRPVerifier(verification_key, salt);
1865-
} else {
1866-
initial_ver_key = getSRPVerifier(playername, raw_default_password);
1867-
}
18681863

1864+
initial_ver_key = encodeSRPVerifier(verification_key, salt);
18691865
m_script->createAuth(playername, initial_ver_key);
18701866

18711867
acceptAuth(pkt->getPeerId(), false);
@@ -2072,5 +2068,19 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
20722068
}
20732069
}
20742070

2071+
if (client->create_player_on_auth_success) {
2072+
std::string playername = client->getName();
2073+
m_script->createAuth(playername, client->enc_pwd);
2074+
2075+
std::string checkpwd; // not used, but needed for passing something
2076+
if (!m_script->getAuth(playername, &checkpwd, NULL)) {
2077+
actionstream << "Server: " << playername << " cannot be authenticated"
2078+
<< " (auth handler does not work?)" << std::endl;
2079+
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_SERVER_FAIL);
2080+
return;
2081+
}
2082+
client->create_player_on_auth_success = false;
2083+
}
2084+
20752085
acceptAuth(pkt->getPeerId(), wantSudo);
20762086
}

0 commit comments

Comments
 (0)