Skip to content

Commit

Permalink
Fixed CORE-5189: Codes of operation of user management plugin are mis…
Browse files Browse the repository at this point in the history
…sing in public API
  • Loading branch information
AlexPeshkoff committed Apr 7, 2016
1 parent 54cde2c commit c8698ce
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 36 deletions.
15 changes: 7 additions & 8 deletions src/auth/SecureRemotePassword/manage/SrpManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,18 @@ class SrpManagement FB_FINAL : public Firebird::StdPlugin<Firebird::IManagementI

switch(user->operation())
{
case MAP_DROP_OPER:
case MAP_SET_OPER:
case Firebird::IUser::OP_USER_DROP_MAP:
case Firebird::IUser::OP_USER_SET_MAP:
{
Firebird::string sql;
sql.printf("ALTER ROLE " ADMIN_ROLE " %s AUTO ADMIN MAPPING",
user->operation() == MAP_SET_OPER ? "SET" : "DROP");
user->operation() == Firebird::IUser::OP_USER_SET_MAP ? "SET" : "DROP");
att->execute(status, tra, sql.length(), sql.c_str(), SQL_DIALECT_V6, NULL, NULL, NULL, NULL);
check(status);
}
break;

case ADD_OPER:
case Firebird::IUser::OP_USER_ADD:
{
const char* insert =
"INSERT INTO plg$srp_view(PLG$USER_NAME, PLG$VERIFIER, PLG$SALT, PLG$FIRST, PLG$MIDDLE, PLG$LAST,"
Expand Down Expand Up @@ -378,7 +378,7 @@ class SrpManagement FB_FINAL : public Firebird::StdPlugin<Firebird::IManagementI
}
break;

case MOD_OPER:
case Firebird::IUser::OP_USER_MODIFY:
{
Firebird::string update = "UPDATE plg$srp_view SET ";

Expand Down Expand Up @@ -482,7 +482,7 @@ class SrpManagement FB_FINAL : public Firebird::StdPlugin<Firebird::IManagementI
}
break;

case DEL_OPER:
case Firebird::IUser::OP_USER_DELETE:
{
const char* del = "DELETE FROM plg$srp_view WHERE PLG$USER_NAME=?";
Firebird::IStatement* stmt = NULL;
Expand Down Expand Up @@ -525,8 +525,7 @@ class SrpManagement FB_FINAL : public Firebird::StdPlugin<Firebird::IManagementI
}
break;

case OLD_DIS_OPER:
case DIS_OPER:
case Firebird::IUser::OP_USER_DISPLAY:
{
Firebird::string disp = "SELECT PLG$USER_NAME, PLG$FIRST, PLG$MIDDLE, PLG$LAST, PLG$COMMENT, PLG$ATTRIBUTES, "
" CASE WHEN RDB$RELATION_NAME IS NULL THEN FALSE ELSE TRUE END, PLG$ACTIVE "
Expand Down
15 changes: 7 additions & 8 deletions src/auth/SecurityDatabase/LegacyManagement.epp
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ int SecurityDatabaseManagement::execute(Firebird::CheckStatusWrapper* st, Firebi

switch (user->operation())
{
case MAP_DROP_OPER:
case MAP_SET_OPER:
case Firebird::IUser::OP_USER_DROP_MAP:
case Firebird::IUser::OP_USER_SET_MAP:
{
Firebird::string sql;
sql.printf("ALTER ROLE " ADMIN_ROLE " %s AUTO ADMIN MAPPING",
user->operation() == MAP_SET_OPER ? "SET" : "DROP");
user->operation() == Firebird::IUser::OP_USER_SET_MAP ? "SET" : "DROP");
isc_dsql_execute_immediate(isc_status, &database, &transaction, sql.length(), sql.c_str(), 1, NULL);
if (isc_status[1] != 0)
{
Expand All @@ -338,7 +338,7 @@ int SecurityDatabaseManagement::execute(Firebird::CheckStatusWrapper* st, Firebi
}
break;

case ADD_OPER:
case Firebird::IUser::OP_USER_ADD:
// this checks the "entered" flags for each parameter (except the name)
// and makes all non-entered parameters null valued

Expand Down Expand Up @@ -412,7 +412,7 @@ int SecurityDatabaseManagement::execute(Firebird::CheckStatusWrapper* st, Firebi
}
break;

case MOD_OPER:
case Firebird::IUser::OP_USER_MODIFY:
// this updates an existing record, replacing all fields that are
// entered, and for those that were specified but not entered, it
// changes the current value to the null value
Expand Down Expand Up @@ -509,7 +509,7 @@ int SecurityDatabaseManagement::execute(Firebird::CheckStatusWrapper* st, Firebi
}
break;

case DEL_OPER:
case Firebird::IUser::OP_USER_DELETE:
// looks up the specified user record and deletes it

found = false;
Expand Down Expand Up @@ -546,8 +546,7 @@ int SecurityDatabaseManagement::execute(Firebird::CheckStatusWrapper* st, Firebi
}
break;

case DIS_OPER:
case OLD_DIS_OPER:
case Firebird::IUser::OP_USER_DISPLAY:
// gets either the desired record, or all records, and displays them

found = false;
Expand Down
5 changes: 2 additions & 3 deletions src/common/call_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,11 @@ isc_svc_handle attachRemoteServiceManager(ISC_STATUS* status,
userInfoToSpb
@brief Writes data from awful borland's struct internal_user_data
to not less awful borland's format of spb.
@brief Writes data from UserData to spb.
@param spb
@param userInfo
@param userData
**/
static void userInfoToSpb(char*& spb, Auth::UserData& userData)
Expand Down
8 changes: 8 additions & 0 deletions src/include/firebird/FirebirdInterface.idl
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,14 @@ interface User : Versioned
IntUserField admin();

void clear(Status status);

// code of operation()
const int OP_USER_ADD = 1;
const int OP_USER_MODIFY = 2;
const int OP_USER_DELETE = 3;
const int OP_USER_DISPLAY = 4;
const int OP_USER_SET_MAP = 5;
const int OP_USER_DROP_MAP = 6;
}

interface ListUsers : Versioned
Expand Down
7 changes: 7 additions & 0 deletions src/include/firebird/IdlFbInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -2601,6 +2601,13 @@ namespace Firebird
public:
static const unsigned VERSION = 2;

static const int OP_USER_ADD = 1;
static const int OP_USER_MODIFY = 2;
static const int OP_USER_DELETE = 3;
static const int OP_USER_DISPLAY = 4;
static const int OP_USER_SET_MAP = 5;
static const int OP_USER_DROP_MAP = 6;

This comment has been minimized.

Copy link
@asfernandes

asfernandes Apr 10, 2016

Member

With the exception of Status::RESULT_* and Auth::AUTH_* which has negative values, we used uint as type in the others constants.

This comment has been minimized.

Copy link
@AlexPeshkoff

AlexPeshkoff via email Apr 10, 2016

Author Member

This comment has been minimized.

Copy link
@dyemanov

dyemanov Apr 10, 2016

Member

We may move the tag tomorrow, there's still a day or two before building the packages.

This comment has been minimized.

Copy link
@AlexPeshkoff

AlexPeshkoff via email Apr 10, 2016

Author Member

This comment has been minimized.

Copy link
@AlexPeshkoff

AlexPeshkoff via email Apr 10, 2016

Author Member
int operation()
{
int ret = static_cast<VTable*>(this->cloopVTable)->operation(this);
Expand Down
18 changes: 11 additions & 7 deletions src/utilities/gsec/gsec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ namespace {
public Firebird::AutoIface<Firebird::IListUsersImpl<Display, Firebird::CheckStatusWrapper> >
{
public:
explicit Display(tsec* t)
: tdsec(t), first(true)
Display(tsec* t, int op)
: tdsec(t), first(true), putAdmin(op != OLD_DIS_OPER)
{ }

// IListUsers implementation
Expand All @@ -257,7 +257,7 @@ namespace {
tdsec->utilSvc->putLine(isc_spb_sec_lastname, data->lastName()->entered() ? data->lastName()->get() : "");
tdsec->utilSvc->putSLong(isc_spb_sec_userid, attr["uid"]);
tdsec->utilSvc->putSLong(isc_spb_sec_groupid, attr["gid"]);
if (data->operation() == DIS_OPER)
if (putAdmin)
{
tdsec->utilSvc->putSLong(isc_spb_sec_admin, data->admin()->get());
}
Expand Down Expand Up @@ -288,6 +288,7 @@ namespace {
private:
tsec* tdsec;
bool first;
bool putAdmin;
};


Expand Down Expand Up @@ -521,14 +522,17 @@ int gsec(Firebird::UtilSvc* uSvc)
{
if (ret == 0)
{
Display disp(tdsec, user_data->op);
if (user_data->op == OLD_DIS_OPER)
user_data->op = DIS_OPER;

// Signal the start of the service here ONLY if we are displaying users
// since the number of users may exceed the service buffer. This
// will cause the service to wait for the client to request data. However,
// if the server is not signaled, then the client can never request anything.
if (user_data->operation() == DIS_OPER || user_data->operation() == OLD_DIS_OPER)
if (user_data->operation() == DIS_OPER)
uSvc->started();

Display disp(tdsec);
if (! useServices)
{
if (user_data->operation() == ADD_OPER)
Expand All @@ -543,7 +547,7 @@ int gsec(Firebird::UtilSvc* uSvc)
(fieldSet(&user_data->u) || fieldSet(&user_data->g) || fieldSet(&user_data->group)))
{
StackUserData u;
u.op = OLD_DIS_OPER;
u.op = DIS_OPER;
u.user.set(&statusWrapper, user_data->userName()->get());
check(&statusWrapper);
u.user.setEntered(&statusWrapper, 1);
Expand Down Expand Up @@ -658,7 +662,7 @@ int gsec(Firebird::UtilSvc* uSvc)

if (ret == 0)
{
Display disp(tdsec);
Display disp(tdsec, DIS_OPER);
callRemoteServiceManager(status, sHandle, *user_data, &disp);
if (status[1])
{
Expand Down
22 changes: 12 additions & 10 deletions src/utilities/gsec/gsec.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#ifndef UTILITIES_GSEC_H
#define UTILITIES_GSEC_H

#include "firebird/Interface.h"
#include "../common/ThreadData.h"
#include "../jrd/constants.h"

Expand All @@ -40,16 +41,17 @@ class UserData;
operation to perform and any parameters entered (sizes are determined
by the size of the fields in the USERS relation in USERINFO.GDB) */

const int ADD_OPER = 1;
const int DEL_OPER = 2;
const int DIS_OPER = 3;
const int MOD_OPER = 4;
const int QUIT_OPER = 5;
const int HELP_OPER = 6;
const int ADDMOD_OPER = 7; // This oper never goes to plugins
const int MAP_SET_OPER = 8;
const int MAP_DROP_OPER = 9;
const int OLD_DIS_OPER = 10;
const int ADD_OPER = Firebird::IUser::OP_USER_ADD;
const int MOD_OPER = Firebird::IUser::OP_USER_MODIFY;
const int DEL_OPER = Firebird::IUser::OP_USER_DELETE;
const int DIS_OPER = Firebird::IUser::OP_USER_DISPLAY;
const int MAP_SET_OPER = Firebird::IUser::OP_USER_SET_MAP;
const int MAP_DROP_OPER = Firebird::IUser::OP_USER_DROP_MAP;
// Foolowing operations never go to plugins
const int QUIT_OPER = 101;
const int HELP_OPER = 102;
const int ADDMOD_OPER = 103;
const int OLD_DIS_OPER = 104;

const int USER_NAME_LEN = 133;
const int ALT_NAME_LEN = 129;
Expand Down

0 comments on commit c8698ce

Please sign in to comment.