8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-31 20:43:03 +01:00
firebird-mirror/src/auth/AuthDbg.cpp

185 lines
4.0 KiB
C++
Raw Normal View History

/*
* 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
//#define AUTH_VERBOSE
static Firebird::MakeUpgradeInfo<> upInfo;
// register plugin
static Firebird::SimpleFactory<Auth::DebugClient> clientFactory;
static Firebird::SimpleFactory<Auth::DebugServer> serverFactory;
extern "C" void FB_PLUGIN_ENTRY_POINT(Firebird::IMaster* master)
{
Firebird::CachedMasterInterface::set(master);
const char* name = "Auth_Debug";
Firebird::PluginManagerInterfacePtr iPlugin;
iPlugin->registerPluginFactory(Firebird::PluginType::AuthClient, name, &clientFactory);
iPlugin->registerPluginFactory(Firebird::PluginType::AuthServer, name, &serverFactory);
}
namespace Auth {
DebugServer::DebugServer(Firebird::IPluginConfig*)
: str(getPool())
{ }
2013-05-22 09:31:34 +02:00
int FB_CARG DebugServer::authenticate(Firebird::IStatus* status, IServerBlock* sb,
IWriter* writerInterface)
{
2012-02-26 15:27:27 +01:00
try
{
#ifdef AUTH_VERBOSE
2013-05-22 09:31:34 +02:00
fprintf(stderr, "DebugServer::authenticate\n");
#endif
2013-05-22 09:31:34 +02:00
unsigned int length;
const unsigned char* val = sb->getData(&length);
#ifdef AUTH_VERBOSE
2013-05-22 09:31:34 +02:00
fprintf(stderr, "DebugServer::authenticate: get()=%.*s\n", length, val);
#endif
2013-05-22 09:31:34 +02:00
if (str.isEmpty())
{
str.assign(val, length);
str += '_';
#ifdef AUTH_VERBOSE
2013-05-22 09:31:34 +02:00
fprintf(stderr, "DebugServer::authenticate1: %s\n", str.c_str());
#endif
2013-05-22 09:31:34 +02:00
sb->putData(status, str.length(), str.c_str());
if (!status->isSuccess())
{
return AUTH_FAILED;
}
2012-02-26 15:27:27 +01:00
2013-05-22 09:31:34 +02:00
return AUTH_MORE_DATA;
}
str.assign(val, length);
#ifdef AUTH_VERBOSE
2013-05-22 09:31:34 +02:00
fprintf(stderr, "DebugServer::authenticate2: %s\n", str.c_str());
#endif
2013-05-22 09:31:34 +02:00
writerInterface->add(str.c_str());
str.erase();
return AUTH_SUCCESS;
}
catch (const Firebird::Exception& ex)
{
ex.stuffException(status);
}
2013-05-22 09:31:34 +02:00
return AUTH_FAILED;
}
int FB_CARG DebugServer::release()
{
if (--refCounter == 0)
{
delete this;
return 0;
}
return 1;
}
DebugClient::DebugClient(Firebird::IPluginConfig*)
: str(getPool())
{ }
2013-05-22 09:31:34 +02:00
int FB_CARG DebugClient::authenticate(Firebird::IStatus* status, IClientBlock* cb)
{
try
{
2013-05-22 09:31:34 +02:00
if (str != "HAND")
{
str = "HAND";
}
else
{
unsigned int length;
const unsigned char* v = cb->getData(&length);
str.assign(v, length);
#ifdef AUTH_VERBOSE
2013-05-22 09:31:34 +02:00
fprintf(stderr, "DebugClient::authenticate2: from srv=%s\n", str.c_str());
#endif
2013-05-22 09:31:34 +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";
}
#ifdef AUTH_VERBOSE
2013-05-22 09:31:34 +02:00
fprintf(stderr, "DebugClient::authenticate: sending %s\n", str.c_str());
#endif
2013-05-22 09:31:34 +02:00
cb->putData(status, str.length(), str.c_str());
if (! status->isSuccess())
{
return AUTH_FAILED;
}
2012-02-26 15:27:27 +01:00
#ifdef AUTH_VERBOSE
2013-05-22 09:31:34 +02:00
fprintf(stderr, "DebugClient::authenticate: data filled\n");
#endif
2013-05-22 09:31:34 +02:00
return AUTH_SUCCESS;
}
catch (const Firebird::Exception& ex)
{
ex.stuffException(status);
}
2013-05-22 09:31:34 +02:00
return AUTH_FAILED;
}
int FB_CARG DebugClient::release()
{
if (--refCounter == 0)
{
delete this;
return 0;
}
return 1;
}
} // namespace Auth
#endif // AUTH_DEBUG