Skip to content

Commit f6a2392

Browse files
committed
Call CoInitializeSecurity during startup to enable lower privilege clients to connect.
1 parent 7227e35 commit f6a2392

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

MyServerCpp/Main.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@ MyserverModule _AtlModule;
1919

2020
// EXE Entry Point
2121
int wmain(int /*argc*/, wchar_t* /*argv*/[]) {
22-
ComInitialize com(COINIT_MULTITHREADED);
22+
// initialize COM early for programmatic COM security
23+
_AtlModule.InitializeCom();
24+
25+
// Disable COM security to allow any client to connect.
26+
// WARNING: Enables non-admin clients to connect to a server running with admin privileges.
27+
HRESULT hr = CoInitializeSecurity(nullptr, -1/*auto*/, nullptr, NULL/*reserved*/,
28+
RPC_C_AUTHN_LEVEL_DEFAULT, ///<
29+
RPC_C_IMP_LEVEL_IDENTIFY, ///< allow server to identify but not impersonate client
30+
nullptr, EOAC_NONE/*capabilities*/, NULL/*reserved*/);
31+
if (FAILED(hr))
32+
abort();
2333

2434
return _AtlModule.WinMain(SW_SHOWDEFAULT);
2535
}

0 commit comments

Comments
 (0)