2010-07-23 14:04:18 +02:00
|
|
|
/*
|
|
|
|
* PROGRAM: Firebird authentication
|
|
|
|
* MODULE: Auth.cpp
|
|
|
|
* DESCRIPTION: Implementation of interfaces, passed to plugins
|
|
|
|
* Plugins loader
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Alex Peshkov
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Alex Peshkov <peshkoff at mail.ru>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "firebird.h"
|
|
|
|
#include "../auth/AuthDbg.h"
|
|
|
|
#include "../jrd/ibase.h"
|
|
|
|
|
|
|
|
#ifdef AUTH_DEBUG
|
|
|
|
|
2011-01-14 18:31:40 +01:00
|
|
|
//#define AUTH_VERBOSE
|
2010-07-23 14:04:18 +02:00
|
|
|
|
2011-06-10 14:53:51 +02:00
|
|
|
static Firebird::MakeUpgradeInfo<> upInfo;
|
|
|
|
|
2011-01-14 18:31:40 +01:00
|
|
|
// register plugin
|
|
|
|
static Firebird::SimpleFactory<Auth::DebugClient> clientFactory;
|
|
|
|
static Firebird::SimpleFactory<Auth::DebugServer> serverFactory;
|
2010-07-23 14:04:18 +02:00
|
|
|
|
2011-01-14 18:31:40 +01:00
|
|
|
extern "C" void FB_PLUGIN_ENTRY_POINT(Firebird::IMaster* master)
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2011-01-14 18:31:40 +01:00
|
|
|
const char* name = "Auth_Debug";
|
2010-07-23 14:04:18 +02:00
|
|
|
|
2011-04-08 17:18:50 +02:00
|
|
|
Firebird::PluginManagerInterfacePtr iPlugin(master);
|
2011-01-14 18:31:40 +01:00
|
|
|
|
2011-04-07 19:16:00 +02:00
|
|
|
iPlugin->registerPluginFactory(Firebird::PluginType::AuthClient, name, &clientFactory);
|
|
|
|
iPlugin->registerPluginFactory(Firebird::PluginType::AuthServer, name, &serverFactory);
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
|
|
|
|
2011-01-14 18:31:40 +01:00
|
|
|
|
|
|
|
namespace Auth {
|
|
|
|
|
2011-04-07 19:16:00 +02:00
|
|
|
DebugServer::DebugServer(Firebird::IPluginConfig*)
|
2011-01-14 18:31:40 +01:00
|
|
|
: str(getPool())
|
2010-07-23 14:04:18 +02:00
|
|
|
{ }
|
|
|
|
|
2011-04-07 19:16:00 +02:00
|
|
|
Result FB_CARG DebugServer::startAuthentication(Firebird::IStatus* status, bool isService, const char* dbName,
|
2011-01-14 18:31:40 +01:00
|
|
|
const unsigned char* dpb, unsigned int dpbSize,
|
2011-04-08 17:18:50 +02:00
|
|
|
IWriter* writerInterface)
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2011-01-14 18:31:40 +01:00
|
|
|
try
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2011-06-10 14:53:51 +02:00
|
|
|
Firebird::MasterInterfacePtr()->upgradeInterface(writerInterface, FB_AUTH_WRITER_VERSION, upInfo);
|
2011-01-14 18:31:40 +01:00
|
|
|
str.erase();
|
|
|
|
Firebird::ClumpletReader rdr(isService ?
|
|
|
|
Firebird::ClumpletReader::spbList :
|
|
|
|
Firebird::ClumpletReader::dpbList, dpb, dpbSize);
|
|
|
|
|
|
|
|
if (rdr.find(isService ? isc_spb_trusted_auth : isc_dpb_trusted_auth))
|
|
|
|
{
|
|
|
|
str.assign(rdr.getBytes(), rdr.getClumpLength());
|
|
|
|
}
|
|
|
|
|
|
|
|
str += '_';
|
|
|
|
return AUTH_MORE_DATA;
|
|
|
|
}
|
|
|
|
catch (const Firebird::Exception& ex)
|
|
|
|
{
|
|
|
|
ex.stuffException(status);
|
|
|
|
return AUTH_FAILED;
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-08 17:18:50 +02:00
|
|
|
Result FB_CARG DebugServer::contAuthentication(Firebird::IStatus* status, IWriter* writerInterface,
|
2011-01-14 18:31:40 +01:00
|
|
|
const unsigned char* data, unsigned int size)
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2011-01-14 18:31:40 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
#ifdef AUTH_VERBOSE
|
|
|
|
fprintf(stderr, "DebugServerInstance::contAuthentication: %.*s\n", size, data);
|
|
|
|
#endif
|
2011-06-10 14:53:51 +02:00
|
|
|
Firebird::MasterInterfacePtr()->upgradeInterface(writerInterface, FB_AUTH_WRITER_VERSION, upInfo);
|
2011-08-09 14:11:17 +02:00
|
|
|
writerInterface->add(Firebird::string((const char*) data, size).c_str());
|
2011-01-14 18:31:40 +01:00
|
|
|
return AUTH_SUCCESS;
|
|
|
|
}
|
|
|
|
catch (const Firebird::Exception& ex)
|
|
|
|
{
|
|
|
|
ex.stuffException(status);
|
|
|
|
return AUTH_FAILED;
|
|
|
|
}
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
|
|
|
|
2011-01-14 18:31:40 +01:00
|
|
|
void FB_CARG DebugServer::getData(const unsigned char** data, unsigned short* dataSize)
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
|
|
|
*data = reinterpret_cast<const unsigned char*>(str.c_str());
|
|
|
|
*dataSize = str.length();
|
2011-01-14 18:31:40 +01:00
|
|
|
#ifdef AUTH_VERBOSE
|
|
|
|
fprintf(stderr, "DebugServerInstance::getData: %.*s\n", *dataSize, *data);
|
|
|
|
#endif
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
|
|
|
|
2011-01-14 18:31:40 +01:00
|
|
|
int FB_CARG DebugServer::release()
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2011-01-14 18:31:40 +01:00
|
|
|
if (--refCounter == 0)
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
|
|
|
|
2011-04-07 19:16:00 +02:00
|
|
|
DebugClient::DebugClient(Firebird::IPluginConfig*)
|
2011-01-14 18:31:40 +01:00
|
|
|
: str(getPool())
|
2010-07-23 14:04:18 +02:00
|
|
|
{ }
|
|
|
|
|
2011-04-08 17:18:50 +02:00
|
|
|
Result FB_CARG DebugClient::startAuthentication(Firebird::IStatus* status, bool isService, const char*, IDpbReader* dpb)
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2011-01-14 18:31:40 +01:00
|
|
|
try
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2011-06-10 14:53:51 +02:00
|
|
|
Firebird::MasterInterfacePtr()->upgradeInterface(dpb, FB_AUTH_DPB_READER_VERSION, upInfo);
|
2011-01-14 18:31:40 +01:00
|
|
|
str = "HAND";
|
|
|
|
if (dpb)
|
|
|
|
{
|
|
|
|
dpb->add((isService ? isc_spb_trusted_auth : isc_dpb_trusted_auth),
|
|
|
|
str.c_str(), str.length());
|
|
|
|
return AUTH_SUCCESS;
|
|
|
|
}
|
|
|
|
return AUTH_MORE_DATA;
|
|
|
|
}
|
|
|
|
catch (const Firebird::Exception& ex)
|
|
|
|
{
|
|
|
|
ex.stuffException(status);
|
|
|
|
return AUTH_FAILED;
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-07 19:16:00 +02:00
|
|
|
Result FB_CARG DebugClient::contAuthentication(Firebird::IStatus* status, const unsigned char* data, unsigned int size)
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2011-01-14 18:31:40 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
#ifdef AUTH_VERBOSE
|
|
|
|
fprintf(stderr, "DebugClientInstance::contAuthentication: %.*s\n", size, data);
|
|
|
|
#endif
|
|
|
|
str.assign(data, size);
|
|
|
|
str += "SHAKE";
|
|
|
|
return AUTH_CONTINUE;
|
|
|
|
}
|
|
|
|
catch (const Firebird::Exception& ex)
|
|
|
|
{
|
|
|
|
ex.stuffException(status);
|
|
|
|
return AUTH_FAILED;
|
|
|
|
}
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
|
|
|
|
2011-01-14 18:31:40 +01:00
|
|
|
void FB_CARG DebugClient::getData(const unsigned char** data, unsigned short* dataSize)
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
|
|
|
*data = reinterpret_cast<const unsigned char*>(str.c_str());
|
|
|
|
*dataSize = str.length();
|
2011-01-14 18:31:40 +01:00
|
|
|
#ifdef AUTH_VERBOSE
|
|
|
|
fprintf(stderr, "DebugClientInstance::getData: %.*s\n", *dataSize, *data);
|
|
|
|
#endif
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
|
|
|
|
2011-01-14 18:31:40 +01:00
|
|
|
int FB_CARG DebugClient::release()
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2011-01-14 18:31:40 +01:00
|
|
|
if (--refCounter == 0)
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Auth
|
|
|
|
|
|
|
|
#endif // AUTH_DEBUG
|