MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / authenticate

Method authenticate

src/auth/SecurityDatabase/LegacyServer.cpp:307–397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305 */
306
307int SecurityDatabaseServer::authenticate(CheckStatusWrapper* status, IServerBlock* sBlock,
308 IWriter* authBlock)
309{
310 status->init();
311
312 try
313 {
314 const char* user = sBlock->getLogin();
315 if (!user)
316 {
317 HANDSHAKE_DEBUG(fprintf(stderr, "LegacyServer (nologin) %d\n", IAuth::AUTH_CONTINUE));
318 return IAuth::AUTH_CONTINUE;
319 }
320 string login(user);
321
322 unsigned length;
323 const unsigned char* data = sBlock->getData(&length);
324 if (!(data && length))
325 {
326 HANDSHAKE_DEBUG(fprintf(stderr, "LegacyServer (nopw) %d\n", IAuth::AUTH_MORE_DATA));
327 return IAuth::AUTH_MORE_DATA;
328 }
329
330 bool found = false;
331 char pw1[MAX_LEGACY_PASSWORD_LENGTH + 1];
332 PathName secureDbName;
333 { // instance scope
334 // Get database block from cache
335 CachedSecurityDatabase::Instance instance;
336 instances->getInstance(iParameter, instance);
337
338 secureDbName = instance->secureDbName;
339 if (!instance->secDb)
340 instance->secDb = FB_NEW SecurityDatabase(instance->secureDbName);
341
342 user_name uname; // user name buffer
343 login.copyTo(uname, sizeof uname);
344 user_record user_block; // user record
345 found = instance->secDb->lookup(uname, &user_block);
346 fb_utils::copy_terminate(pw1, user_block.password, MAX_LEGACY_PASSWORD_LENGTH + 1);
347 }
348 if (!found)
349 {
350 HANDSHAKE_DEBUG(fprintf(stderr, "LegacyServer (badlogin) %d\n", IAuth::AUTH_CONTINUE));
351 return IAuth::AUTH_CONTINUE;
352 }
353
354 string storedHash(pw1, MAX_LEGACY_PASSWORD_LENGTH);
355 storedHash.rtrim();
356 storedHash.recalculate_length();
357
358 string passwordEnc;
359 passwordEnc.assign(data, length);
360
361 string newHash;
362 LegacyHash::hash(newHash, login, passwordEnc, storedHash);
363 if (newHash != storedHash)
364 {

Callers

nothing calls this directly

Calls 15

ENC_cryptFunction · 0.85
rtrimMethod · 0.80
recalculate_lengthMethod · 0.80
SecurityDatabaseClass · 0.70
copy_terminateFunction · 0.50
hashFunction · 0.50
checkFunction · 0.50
initMethod · 0.45
getLoginMethod · 0.45
getDataMethod · 0.45
getInstanceMethod · 0.45
copyToMethod · 0.45

Tested by

no test coverage detected