Skip to content

Commit ee17194

Browse files
committed
constexpr + noexcept in AuthSspi
1 parent ab0bd5a commit ee17194

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/auth/trusted/AuthSspi.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ namespace
4141
Firebird::SimpleFactory<Auth::WinSspiClient> clientFactory;
4242
Firebird::SimpleFactory<Auth::WinSspiServer> serverFactory;
4343

44-
const char* plugName = "Win_Sspi";
44+
constexpr const char* plugName = "Win_Sspi";
4545

46-
void makeDesc(SecBufferDesc& d, SecBuffer& b, FB_SIZE_T len, void* p)
46+
void makeDesc(SecBufferDesc& d, SecBuffer& b, FB_SIZE_T len, void* p) noexcept
4747
{
4848
b.BufferType = SECBUFFER_TOKEN;
4949
b.cbBuffer = len;
@@ -57,7 +57,7 @@ namespace
5757
ToType getProc(HINSTANCE lib, const char* entry)
5858
{
5959
FARPROC rc = GetProcAddress(lib, entry);
60-
if (! rc)
60+
if (!rc)
6161
{
6262
LongJump::raise();
6363
}
@@ -70,21 +70,21 @@ namespace Auth {
7070

7171
static thread_local bool legacySSP = false;
7272

73-
void setLegacySSP(bool value)
73+
void setLegacySSP(bool value) noexcept
7474
{
7575
legacySSP = value;
7676
}
7777

7878

7979
HINSTANCE AuthSspi::library = 0;
8080

81-
bool AuthSspi::initEntries()
81+
bool AuthSspi::initEntries() noexcept
8282
{
83-
if (! library)
83+
if (!library)
8484
{
8585
library = LoadLibrary("secur32.dll");
8686
}
87-
if (! library)
87+
if (!library)
8888
{
8989
return false;
9090
}
@@ -136,7 +136,7 @@ AuthSspi::~AuthSspi()
136136
}
137137
}
138138

139-
const AuthSspi::Key* AuthSspi::getKey() const
139+
const AuthSspi::Key* AuthSspi::getKey() const noexcept
140140
{
141141
if (sessionKey.hasData())
142142
return &sessionKey;
@@ -152,6 +152,7 @@ bool AuthSspi::checkAdminPrivilege()
152152
{
153153
return false;
154154
}
155+
fb_assert(spc.AccessToken);
155156

156157
// Query required buffer size
157158
DWORD token_len = 0;
@@ -187,7 +188,6 @@ bool AuthSspi::checkAdminPrivilege()
187188
bool matched = false;
188189
char groupName[256];
189190
char domainName[256];
190-
DWORD dwAcctName = 1, dwDomainName = 1;
191191
SID_NAME_USE snu = SidTypeUnknown;
192192

193193
groupNames.clear();
@@ -200,8 +200,9 @@ bool AuthSspi::checkAdminPrivilege()
200200
if ((ptg->Groups[i].Attributes & SE_GROUP_ENABLED) &&
201201
!(ptg->Groups[i].Attributes & SE_GROUP_USE_FOR_DENY_ONLY))
202202
{
203-
DWORD dwSize = 256;
204-
if (LookupAccountSid(NULL, ptg->Groups[i].Sid, groupName, &dwSize, domainName, &dwSize, &snu) &&
203+
DWORD dwGroupName = sizeof(groupName);
204+
DWORD dwDomainName = sizeof(domainName);
205+
if (LookupAccountSid(NULL, ptg->Groups[i].Sid, groupName, &dwGroupName, domainName, &dwDomainName, &snu) &&
205206
domainName[0] && strcmp(domainName, "NT AUTHORITY"))
206207
{
207208
string sumName = domainName;
@@ -246,7 +247,7 @@ bool AuthSspi::request(AuthSspi::DataHolder& data)
246247

247248
ULONG fContextAttr = 0;
248249

249-
SECURITY_STATUS x = fInitializeSecurityContext(
250+
const SECURITY_STATUS x = fInitializeSecurityContext(
250251
&secHndl, hasContext ? &ctxtHndl : 0, 0, 0, 0, SECURITY_NATIVE_DREP,
251252
hasContext ? &inputDesc : 0, 0, &ctxtHndl, &outputDesc, &fContextAttr, &timeOut);
252253

@@ -308,7 +309,7 @@ bool AuthSspi::accept(AuthSspi::DataHolder& data)
308309
ULONG fContextAttr = 0;
309310
SecPkgContext_Names name;
310311
SecPkgContext_SessionKey key;
311-
SECURITY_STATUS x = fAcceptSecurityContext(
312+
const SECURITY_STATUS x = fAcceptSecurityContext(
312313
&secHndl, hasContext ? &ctxtHndl : 0, &inputDesc, 0,
313314
SECURITY_NATIVE_DREP, &ctxtHndl, &outputDesc,
314315
&fContextAttr, &timeOut);

src/auth/trusted/AuthSspi.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class AuthSspi
5858
typedef Firebird::UCharBuffer Key;
5959

6060
private:
61-
enum {BUFSIZE = 4096};
61+
static constexpr size_t BUFSIZE = 4096;
6262

6363
SecHandle secHndl;
6464
bool hasCredentials;
@@ -82,7 +82,7 @@ class AuthSspi
8282
ACCEPT_SECURITY_CONTEXT_FN fAcceptSecurityContext;
8383

8484
bool checkAdminPrivilege();
85-
bool initEntries();
85+
bool initEntries() noexcept;
8686

8787
public:
8888
typedef Firebird::Array<unsigned char> DataHolder;
@@ -92,7 +92,7 @@ class AuthSspi
9292

9393
// true when has non-empty security context,
9494
// ready to be sent to the other side
95-
bool isActive() const
95+
bool isActive() const noexcept
9696
{
9797
return hasContext;
9898
}
@@ -107,7 +107,7 @@ class AuthSspi
107107
bool getLogin(Firebird::string& login, bool& wh, GroupsList& grNames);
108108

109109
// returns session key for wire encryption
110-
const Key* getKey() const;
110+
const Key* getKey() const noexcept;
111111
};
112112

113113
class WinSspiServer :
@@ -117,7 +117,7 @@ class WinSspiServer :
117117
// IServer implementation
118118
int authenticate(Firebird::CheckStatusWrapper* status, Firebird::IServerBlock* sBlock,
119119
Firebird::IWriter* writerInterface);
120-
void setDbCryptCallback(Firebird::CheckStatusWrapper* status, Firebird::ICryptKeyCallback* callback) {}; // do nothing
120+
void setDbCryptCallback(Firebird::CheckStatusWrapper* status, Firebird::ICryptKeyCallback* callback) noexcept {}; // do nothing
121121

122122
WinSspiServer(Firebird::IPluginConfig*);
123123

@@ -147,7 +147,7 @@ void registerTrustedServer(Firebird::IPluginManager* iPlugin);
147147

148148
// Set per-thread flag that specify which security package should be used by
149149
// newly created plugin instances: true - use NTLM, false - use Negotiate.
150-
void setLegacySSP(bool value);
150+
void setLegacySSP(bool value) noexcept;
151151

152152
} // namespace Auth
153153

0 commit comments

Comments
 (0)