Skip to content

Commit cc512a3

Browse files
committed
Merge pull request #8262 from FirebirdSQL/work/gh-8256
Make server to correctly handle case when accept() returns both success and data for client.
1 parent 77cc0ba commit cc512a3

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

src/auth/trusted/AuthSspi.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ bool AuthSspi::getLogin(string& login, bool& wh, GroupsList& grNames)
367367

368368

369369
WinSspiServer::WinSspiServer(Firebird::IPluginConfig*)
370-
: sspiData(getPool())
370+
: sspiData(getPool()),
371+
done(false)
371372
{ }
372373

373374
int WinSspiServer::authenticate(Firebird::CheckStatusWrapper* status,
@@ -376,17 +377,18 @@ int WinSspiServer::authenticate(Firebird::CheckStatusWrapper* status,
376377
{
377378
try
378379
{
379-
const bool wasActive = sspi.isActive();
380-
381380
sspiData.clear();
382381
unsigned int length;
383382
const unsigned char* bytes = sBlock->getData(&length);
384383
sspiData.add(bytes, length);
385384

385+
if (done && !length && !sspi.isActive())
386+
return AUTH_SUCCESS;
387+
386388
if (!sspi.accept(sspiData))
387389
return AUTH_CONTINUE;
388390

389-
if (wasActive && !sspi.isActive())
391+
if (!sspi.isActive())
390392
{
391393
bool wheel = false;
392394
string login;
@@ -445,7 +447,9 @@ int WinSspiServer::authenticate(Firebird::CheckStatusWrapper* status,
445447
return AUTH_FAILED;
446448
}
447449

448-
return AUTH_SUCCESS;
450+
done = true;
451+
if (sspiData.isEmpty())
452+
return AUTH_SUCCESS;
449453
}
450454

451455
sBlock->putData(status, sspiData.getCount(), sspiData.begin());
@@ -456,7 +460,7 @@ int WinSspiServer::authenticate(Firebird::CheckStatusWrapper* status,
456460
return AUTH_FAILED;
457461
}
458462

459-
return AUTH_MORE_DATA;
463+
return done ? AUTH_SUCCESS_WITH_DATA : AUTH_MORE_DATA;
460464
}
461465

462466

src/auth/trusted/AuthSspi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class WinSspiServer :
124124
private:
125125
AuthSspi::DataHolder sspiData;
126126
AuthSspi sspi;
127+
bool done;
127128
};
128129

129130
class WinSspiClient :

src/include/firebird/FirebirdInterface.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ interface Auth : PluginBase
769769
const int AUTH_SUCCESS = 0;
770770
const int AUTH_MORE_DATA = 1;
771771
const int AUTH_CONTINUE = 2;
772+
const int AUTH_SUCCESS_WITH_DATA = 3;
772773
}
773774

774775
interface Writer : Versioned

src/include/firebird/IdlFbInterfaces.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,6 +3063,7 @@ namespace Firebird
30633063
static CLOOP_CONSTEXPR int AUTH_SUCCESS = 0;
30643064
static CLOOP_CONSTEXPR int AUTH_MORE_DATA = 1;
30653065
static CLOOP_CONSTEXPR int AUTH_CONTINUE = 2;
3066+
static CLOOP_CONSTEXPR int AUTH_SUCCESS_WITH_DATA = 3;
30663067
};
30673068

30683069
#define FIREBIRD_IWRITER_VERSION 2u

src/include/gen/Firebird.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,7 @@ IAuth = class(IPluginBase)
19711971
const AUTH_SUCCESS = Integer(0);
19721972
const AUTH_MORE_DATA = Integer(1);
19731973
const AUTH_CONTINUE = Integer(2);
1974+
const AUTH_SUCCESS_WITH_DATA = Integer(3);
19741975

19751976
end;
19761977

src/remote/server/server.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,10 @@ class ServerAuth : public GlobalStorage, public ServerAuthBase
657657
}
658658

659659
// if we asked for more data but received nothing switch to next plugin
660-
const bool forceNext = (flags & AUTH_CONTINUE) && (!authPort->port_srv_auth_block->hasDataForPlugin());
660+
const bool forceNext = (flags & AUTH_CONTINUE) &&
661+
(!authPort->port_srv_auth_block->hasDataForPlugin()) &&
662+
(!authPort->port_srv_auth_block->authCompleted());
663+
661664
HANDSHAKE_DEBUG(fprintf(stderr, "Srv: authenticate: ServerAuth calls plug %s\n",
662665
forceNext ? "forced-NEXT" : authItr->name()));
663666
int authResult = forceNext ? IAuth::AUTH_CONTINUE :
@@ -686,6 +689,11 @@ class ServerAuth : public GlobalStorage, public ServerAuthBase
686689
authServer = NULL;
687690
continue;
688691

692+
case IAuth::AUTH_SUCCESS_WITH_DATA:
693+
HANDSHAKE_DEBUG(fprintf(stderr, "Srv: authenticate: success with data\n"));
694+
fb_assert(!authPort->port_srv_auth_block->authCompleted());
695+
// fall thru
696+
689697
case IAuth::AUTH_MORE_DATA:
690698
HANDSHAKE_DEBUG(fprintf(stderr, "Srv: authenticate: plugin wants more data\n"));
691699
if (authPort->port_protocol < PROTOCOL_VERSION11)
@@ -739,6 +747,13 @@ class ServerAuth : public GlobalStorage, public ServerAuthBase
739747
if (send->p_acpt.p_acpt_type & pflag_compress)
740748
authPort->port_flags |= PORT_compressed;
741749
memset(&send->p_auth_cont, 0, sizeof send->p_auth_cont);
750+
751+
if (authResult == IAuth::AUTH_SUCCESS_WITH_DATA)
752+
{
753+
authPort->port_srv_auth_block->authCompleted(true);
754+
HANDSHAKE_DEBUG(fprintf(stderr, "Srv: authenticate: success with data, completed\n"));
755+
}
756+
742757
return false;
743758

744759
case IAuth::AUTH_FAILED:

0 commit comments

Comments
 (0)