2011-03-02 14:42:56 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* PROGRAM: Security data base manager
|
|
|
|
* MODULE: security.cpp
|
|
|
|
* DESCRIPTION: Security routines
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Interbase 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.Inprise.com/IPL.html
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an
|
|
|
|
* "AS IS" basis, 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 Inprise Corporation
|
|
|
|
* and its predecessors. Portions created by Inprise Corporation are
|
|
|
|
* Copyright (C) Inprise Corporation.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
* Alex Peshkoff
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "firebird.h"
|
|
|
|
#include "../common/security.h"
|
|
|
|
#include "../common/StatusArg.h"
|
2011-12-26 17:06:00 +01:00
|
|
|
#include "../utilities/gsec/gsec.h" // gsec error codes
|
2011-03-02 14:42:56 +01:00
|
|
|
|
|
|
|
using namespace Firebird;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void raise()
|
|
|
|
{
|
|
|
|
(Arg::Gds(isc_random) << "Missing user management plugin").raise();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace Auth {
|
|
|
|
|
|
|
|
Get::Get(Config* firebirdConf)
|
2015-02-18 16:01:17 +01:00
|
|
|
: GetPlugins<Firebird::IManagement>(IPluginManager::TYPE_AUTH_USER_MANAGEMENT, firebirdConf)
|
2011-03-02 14:42:56 +01:00
|
|
|
{
|
|
|
|
if (!hasData())
|
|
|
|
{
|
|
|
|
raise();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-13 12:24:38 +01:00
|
|
|
Get::Get(Config* firebirdConf, const char* plugName)
|
2015-02-18 16:01:17 +01:00
|
|
|
: GetPlugins<Firebird::IManagement>(IPluginManager::TYPE_AUTH_USER_MANAGEMENT, firebirdConf, plugName)
|
2014-12-24 15:50:03 +01:00
|
|
|
{
|
|
|
|
if (!hasData())
|
|
|
|
{
|
|
|
|
raise();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-12 01:21:38 +01:00
|
|
|
void UserData::clear(Firebird::CheckStatusWrapper*)
|
2011-03-02 14:42:56 +01:00
|
|
|
{
|
2014-04-04 17:57:18 +02:00
|
|
|
op = 0;
|
2013-12-06 18:10:10 +01:00
|
|
|
|
|
|
|
// interface fields
|
2011-03-02 14:42:56 +01:00
|
|
|
user.clear();
|
|
|
|
pass.clear();
|
|
|
|
first.clear();
|
|
|
|
last.clear();
|
|
|
|
middle.clear();
|
2013-12-06 18:10:10 +01:00
|
|
|
com.clear();
|
|
|
|
attr.clear();
|
2011-03-02 14:42:56 +01:00
|
|
|
adm.clear();
|
2013-12-17 15:20:25 +01:00
|
|
|
act.clear();
|
2011-03-02 14:42:56 +01:00
|
|
|
|
2013-12-06 18:10:10 +01:00
|
|
|
// internally used fields
|
2011-03-02 14:42:56 +01:00
|
|
|
database.clear();
|
|
|
|
dba.clear();
|
|
|
|
dbaPassword.clear();
|
|
|
|
role.clear();
|
2013-12-06 18:10:10 +01:00
|
|
|
|
2011-10-04 14:51:57 +02:00
|
|
|
// never clear this permanent block! authenticationBlock.clear();
|
2013-12-06 18:10:10 +01:00
|
|
|
|
|
|
|
// internal support for deprecated fields
|
|
|
|
group.clear();
|
|
|
|
u.clear();
|
|
|
|
g.clear();
|
2011-03-02 14:42:56 +01:00
|
|
|
}
|
|
|
|
|
2011-12-26 17:06:00 +01:00
|
|
|
// This function sets typical gsec return code based on requested operation if it was not set by plugin
|
2015-11-06 18:10:27 +01:00
|
|
|
int setGsecCode(int code, int operation)
|
2011-12-26 17:06:00 +01:00
|
|
|
{
|
|
|
|
if (code >= 0)
|
|
|
|
{
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2015-11-06 18:10:27 +01:00
|
|
|
switch(operation)
|
2011-12-26 17:06:00 +01:00
|
|
|
{
|
|
|
|
case ADD_OPER:
|
|
|
|
return GsecMsg19;
|
|
|
|
|
|
|
|
case MOD_OPER:
|
|
|
|
return GsecMsg20;
|
|
|
|
|
|
|
|
case DEL_OPER:
|
|
|
|
return GsecMsg23;
|
|
|
|
|
|
|
|
case OLD_DIS_OPER:
|
|
|
|
case DIS_OPER:
|
|
|
|
return GsecMsg28;
|
|
|
|
|
|
|
|
case MAP_DROP_OPER:
|
|
|
|
case MAP_SET_OPER:
|
|
|
|
return GsecMsg97;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GsecMsg17;
|
|
|
|
}
|
|
|
|
|
2016-01-24 18:58:28 +01:00
|
|
|
void parseList(ParsedList& parsed, PathName list)
|
|
|
|
{
|
|
|
|
list.alltrim(" \t");
|
|
|
|
parsed.clear();
|
|
|
|
const char* sep = " \t,;";
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
PathName::size_type p = list.find_first_of(sep);
|
|
|
|
if (p == PathName::npos)
|
|
|
|
{
|
|
|
|
if (list.hasData())
|
|
|
|
{
|
|
|
|
parsed.push(list);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
parsed.push(list.substr(0, p));
|
|
|
|
list = list.substr(p + 1);
|
|
|
|
list.ltrim(" \t,;");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void makeList(PathName& list, const ParsedList& parsed)
|
|
|
|
{
|
|
|
|
fb_assert(parsed.hasData());
|
|
|
|
list = parsed[0];
|
|
|
|
for (unsigned i = 1; i < parsed.getCount(); ++i)
|
|
|
|
{
|
|
|
|
list += ' ';
|
|
|
|
list += parsed[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mergeLists(PathName& list, const PathName& serverList, const PathName& clientList)
|
|
|
|
{
|
|
|
|
ParsedList onClient, onServer, merged;
|
|
|
|
parseList(onClient, clientList);
|
|
|
|
parseList(onServer, serverList);
|
|
|
|
|
|
|
|
// do not expect too long lists, therefore use double loop
|
|
|
|
for (unsigned c = 0; c < onClient.getCount(); ++c)
|
|
|
|
{
|
|
|
|
for (unsigned s = 0; s < onServer.getCount(); ++s)
|
|
|
|
{
|
|
|
|
if (onClient[c] == onServer[s])
|
|
|
|
{
|
|
|
|
merged.push(onClient[c]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
makeList(list, merged);
|
|
|
|
}
|
|
|
|
|
2011-03-02 14:42:56 +01:00
|
|
|
} // namespace Auth
|