| 1 |
/* |
| 2 |
* PROGRAM: Firebird authentication |
| 3 |
* MODULE: LegacyClient.cpp |
| 4 |
* DESCRIPTION: Performs legacy actions on password at client side. |
| 5 |
* |
| 6 |
* The contents of this file are subject to the Initial |
| 7 |
* Developer's Public License Version 1.0 (the "License"); |
| 8 |
* you may not use this file except in compliance with the |
| 9 |
* License. You may obtain a copy of the License at |
| 10 |
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. |
| 11 |
* |
| 12 |
* Software distributed under the License is distributed AS IS, |
| 13 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing rights |
| 15 |
* and limitations under the License. |
| 16 |
* |
| 17 |
* The Original Code was created by Alex Peshkov |
| 18 |
* for the Firebird Open Source RDBMS project. |
| 19 |
* |
| 20 |
* Copyright (c) 2010 Alex Peshkov <peshkoff at mail.ru> |
| 21 |
* and all contributors signed below. |
| 22 |
* |
| 23 |
* All Rights Reserved. |
| 24 |
* Contributor(s): ______________________________________. |
| 25 |
* |
| 26 |
* |
| 27 |
*/ |
| 28 |
#include "firebird.h" |
| 29 |
#include "../jrd/ibase.h" |
| 30 |
#include "../auth/SecurityDatabase/LegacyClient.h" |
| 31 |
#include "../auth/SecurityDatabase/LegacyHash.h" |
| 32 |
#include "../common/enc_proto.h" |
| 33 |
#include "../common/classes/ImplementHelper.h" |
| 34 |
#include "../common/classes/init.h" |
| 35 |
|
| 36 |
namespace Auth { |
| 37 |
|
| 38 |
int SecurityDatabaseClient::authenticate(Firebird::CheckStatusWrapper* status, Firebird::IClientBlock* cb) |
| 39 |
{ |
| 40 |
// fprintf(stderr, "Clnt: Legacy: lgn=%s pswd=%s\n", cb->getLogin(), cb->getPassword()); |
| 41 |
if (!(cb->getLogin() && cb->getPassword())) |
| 42 |
{ |
| 43 |
return AUTH_CONTINUE; |
| 44 |
} |
| 45 |
|
| 46 |
TEXT pwt[MAX_LEGACY_PASSWORD_LENGTH + 2]; |
| 47 |
ENC_crypt(pwt, sizeof pwt, cb->getPassword(), LEGACY_PASSWORD_SALT); |
| 48 |
cb->putData(status, static_cast<unsigned>(strlen(&pwt[2])), &pwt[2]); |
| 49 |
if (status->getState() & Firebird::IStatus::STATE_ERRORS) |
| 50 |
{ |
| 51 |
return AUTH_FAILED; |
| 52 |
} |
| 53 |
|
| 54 |
return AUTH_SUCCESS; |
| 55 |
} |
| 56 |
|
| 57 |
int SecurityDatabaseClient::release() |
| 58 |
{ |
| 59 |
if (--refCounter == 0) |
| 60 |
{ |
| 61 |
delete this; |
| 62 |
return 0; |
| 63 |
} |
| 64 |
return 1; |
| 65 |
} |
| 66 |
|
| 67 |
namespace { |
| 68 |
Firebird::SimpleFactory<SecurityDatabaseClient> factory; |
| 69 |
} |
| 70 |
|
| 71 |
void registerLegacyClient(Firebird::IPluginManager* iPlugin) |
| 72 |
{ |
| 73 |
iPlugin->registerPluginFactory(Firebird::IPluginManager::TYPE_AUTH_CLIENT, "Legacy_Auth", &factory); |
| 74 |
} |
| 75 |
|
| 76 |
} // namespace Auth |