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
|
|
|
{ }
|
|
|
|
|
2012-02-24 13:39:27 +01:00
|
|
|
int FB_CARG DebugServer::authenticate(Firebird::IStatus* status, IServerBlock* sBlock,
|
2011-12-23 13:43:58 +01:00
|
|
|
IWriter* writerInterface)
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2012-02-26 15:27:27 +01:00
|
|
|
/***
|
|
|
|
try
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2011-10-20 14:20:33 +02:00
|
|
|
Firebird::MasterInterfacePtr()->upgradeInterface(dpb, FB_AUTH_CLUMPLETS_VERSION, upInfo);
|
2011-01-14 18:31:40 +01:00
|
|
|
str.erase();
|
|
|
|
|
2011-10-20 14:20:33 +02:00
|
|
|
#ifdef AUTH_VERBOSE
|
2011-10-27 03:04:14 +02:00
|
|
|
fprintf(stderr, "DebugServer::startAuthentication: tA-tag=%d dpb=%p\n", tags->trustedAuth, dpb);
|
2011-10-20 14:20:33 +02:00
|
|
|
#endif
|
|
|
|
if (tags->trustedAuth && dpb && dpb->find(tags->trustedAuth))
|
2011-01-14 18:31:40 +01:00
|
|
|
{
|
2011-10-04 14:51:57 +02:00
|
|
|
unsigned int len;
|
|
|
|
const UCHAR* s = dpb->get(&len);
|
2011-10-20 14:20:33 +02:00
|
|
|
#ifdef AUTH_VERBOSE
|
2011-10-27 03:04:14 +02:00
|
|
|
fprintf(stderr, "DebugServer::startAuthentication: get()=%.*s\n", len, s);
|
2011-10-20 14:20:33 +02:00
|
|
|
#endif
|
2011-10-04 14:51:57 +02:00
|
|
|
str.assign(s, len);
|
2011-01-14 18:31:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
str += '_';
|
2011-10-20 14:20:33 +02:00
|
|
|
#ifdef AUTH_VERBOSE
|
2011-10-27 03:04:14 +02:00
|
|
|
fprintf(stderr, "DebugServer::startAuthentication: %s\n", str.c_str());
|
2011-10-20 14:20:33 +02:00
|
|
|
#endif
|
2011-01-14 18:31:40 +01:00
|
|
|
return AUTH_MORE_DATA;
|
|
|
|
}
|
|
|
|
catch (const Firebird::Exception& ex)
|
|
|
|
{
|
|
|
|
ex.stuffException(status);
|
2012-02-26 15:27:27 +01:00
|
|
|
}
|
|
|
|
***/
|
2011-12-23 13:43:58 +01:00
|
|
|
return AUTH_FAILED;
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
2012-02-26 15:27:27 +01:00
|
|
|
|
|
|
|
/***
|
2012-02-24 13:39:27 +01:00
|
|
|
int FB_CARG DebugServer::contAuthentication(Firebird::IStatus* status, const unsigned char* data,
|
2011-10-04 14:51:57 +02:00
|
|
|
unsigned int size, IWriter* writerInterface)
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2011-01-14 18:31:40 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
#ifdef AUTH_VERBOSE
|
2011-10-27 03:04:14 +02:00
|
|
|
fprintf(stderr, "DebugServer::contAuthentication: %.*s\n", size, data);
|
2011-01-14 18:31:40 +01:00
|
|
|
#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
|
|
|
}
|
2012-02-26 15:27:27 +01:00
|
|
|
***/
|
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
|
|
|
{ }
|
|
|
|
|
2012-02-24 13:39:27 +01:00
|
|
|
int FB_CARG DebugClient::authenticate(Firebird::IStatus* status, IClientBlock* cBlock)
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2012-02-26 15:27:27 +01:00
|
|
|
/***
|
2011-01-14 18:31:40 +01:00
|
|
|
try
|
2010-07-23 14:04:18 +02:00
|
|
|
{
|
2011-01-14 18:31:40 +01:00
|
|
|
str = "HAND";
|
2011-10-20 14:20:33 +02:00
|
|
|
#ifdef AUTH_VERBOSE
|
2011-10-27 03:04:14 +02:00
|
|
|
fprintf(stderr, "DebugClient::startAuthentication: %s\n", str.c_str());
|
2011-10-20 14:20:33 +02:00
|
|
|
#endif
|
|
|
|
if (dpb && tags->trustedAuth)
|
2011-01-14 18:31:40 +01:00
|
|
|
{
|
2011-10-10 19:15:20 +02:00
|
|
|
Firebird::MasterInterfacePtr()->upgradeInterface(dpb, FB_AUTH_CLUMPLETS_VERSION, upInfo);
|
2011-10-04 14:51:57 +02:00
|
|
|
dpb->add(tags->trustedAuth, str.c_str(), str.length());
|
2011-10-20 14:20:33 +02:00
|
|
|
#ifdef AUTH_VERBOSE
|
2011-10-27 03:04:14 +02:00
|
|
|
fprintf(stderr, "DebugClient::startAuthentication: DPB filled\n");
|
2011-10-20 14:20:33 +02:00
|
|
|
#endif
|
2011-01-14 18:31:40 +01:00
|
|
|
return AUTH_SUCCESS;
|
|
|
|
}
|
|
|
|
return AUTH_MORE_DATA;
|
|
|
|
}
|
|
|
|
catch (const Firebird::Exception& ex)
|
|
|
|
{
|
|
|
|
ex.stuffException(status);
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
2012-02-26 15:27:27 +01:00
|
|
|
***/
|
2011-12-23 13:43:58 +01:00
|
|
|
return AUTH_FAILED;
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
2012-02-26 15:27:27 +01:00
|
|
|
|
|
|
|
/***
|
2012-02-24 13:39:27 +01:00
|
|
|
int 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
|
2011-10-27 03:04:14 +02:00
|
|
|
fprintf(stderr, "DebugClient::contAuthentication: %.*s\n", size, data);
|
2011-01-14 18:31:40 +01:00
|
|
|
#endif
|
|
|
|
str.assign(data, size);
|
2011-10-20 14:20:33 +02:00
|
|
|
const char* env = getenv("ISC_DEBUG_AUTH");
|
|
|
|
if (env && env[0] && str.length() > 0 && str[str.length() - 1] == '_')
|
|
|
|
str = env;
|
|
|
|
else
|
|
|
|
str += "SHAKE";
|
2011-01-14 18:31:40 +01:00
|
|
|
return AUTH_CONTINUE;
|
|
|
|
}
|
|
|
|
catch (const Firebird::Exception& ex)
|
|
|
|
{
|
|
|
|
ex.stuffException(status);
|
|
|
|
return AUTH_FAILED;
|
|
|
|
}
|
2010-07-23 14:04:18 +02:00
|
|
|
}
|
2012-02-26 15:27:27 +01:00
|
|
|
***/
|
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
|