| 305 | */ |
| 306 | |
| 307 | int 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 | { |
nothing calls this directly
no test coverage detected