Skip to content

Commit d86cfda

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 f641601 commit d86cfda

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
@@ -758,6 +758,7 @@ interface Auth : PluginBase
758758
const int AUTH_SUCCESS = 0;
759759
const int AUTH_MORE_DATA = 1;
760760
const int AUTH_CONTINUE = 2;
761+
const int AUTH_SUCCESS_WITH_DATA = 3;
761762
}
762763

763764
interface Writer : Versioned

src/include/firebird/IdlFbInterfaces.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,6 +2956,7 @@ namespace Firebird
29562956
static const int AUTH_SUCCESS = 0;
29572957
static const int AUTH_MORE_DATA = 1;
29582958
static const int AUTH_CONTINUE = 2;
2959+
static const int AUTH_SUCCESS_WITH_DATA = 3;
29592960
};
29602961

29612962
class IWriter : public IVersioned

src/include/gen/Firebird.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,7 @@ IAuth = class(IPluginBase)
19271927
const AUTH_SUCCESS = Integer(0);
19281928
const AUTH_MORE_DATA = Integer(1);
19291929
const AUTH_CONTINUE = Integer(2);
1930+
const AUTH_SUCCESS_WITH_DATA = Integer(3);
19301931

19311932
end;
19321933

src/remote/server/server.cpp

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

634634
// if we asked for more data but received nothing switch to next plugin
635-
const bool forceNext = (flags & AUTH_CONTINUE) && (!authPort->port_srv_auth_block->hasDataForPlugin());
635+
const bool forceNext = (flags & AUTH_CONTINUE) &&
636+
(!authPort->port_srv_auth_block->hasDataForPlugin()) &&
637+
(!authPort->port_srv_auth_block->authCompleted());
638+
636639
HANDSHAKE_DEBUG(fprintf(stderr, "Srv: authenticate: ServerAuth calls plug %s\n",
637640
forceNext ? "forced-NEXT" : authItr->name()));
638641
int authResult = forceNext ? IAuth::AUTH_CONTINUE :
@@ -661,6 +664,11 @@ class ServerAuth : public GlobalStorage, public ServerAuthBase
661664
authServer = NULL;
662665
continue;
663666

667+
case IAuth::AUTH_SUCCESS_WITH_DATA:
668+
HANDSHAKE_DEBUG(fprintf(stderr, "Srv: authenticate: success with data\n"));
669+
fb_assert(!authPort->port_srv_auth_block->authCompleted());
670+
// fall thru
671+
664672
case IAuth::AUTH_MORE_DATA:
665673
HANDSHAKE_DEBUG(fprintf(stderr, "Srv: authenticate: plugin wants more data\n"));
666674
if (authPort->port_protocol < PROTOCOL_VERSION11)
@@ -714,6 +722,13 @@ class ServerAuth : public GlobalStorage, public ServerAuthBase
714722
if (send->p_acpt.p_acpt_type & pflag_compress)
715723
authPort->port_flags |= PORT_compressed;
716724
memset(&send->p_auth_cont, 0, sizeof send->p_auth_cont);
725+
726+
if (authResult == IAuth::AUTH_SUCCESS_WITH_DATA)
727+
{
728+
authPort->port_srv_auth_block->authCompleted(true);
729+
HANDSHAKE_DEBUG(fprintf(stderr, "Srv: authenticate: success with data, completed\n"));
730+
}
731+
717732
return false;
718733

719734
case IAuth::AUTH_FAILED:

0 commit comments

Comments
 (0)