Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

786 lines
21 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: ldm.cpp
  4. //
  5. // Synopsis: This file holds the implementation of the
  6. // CServiceModule class and WinMain
  7. //
  8. // History: 11/15/2000 serdarun Created
  9. //
  10. // Copyright (C) 1999-2000 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //#--------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "resource.h"
  16. #include <initguid.h>
  17. #include "ldm.h"
  18. #include "ldm_i.c"
  19. #include "mainwindow.h"
  20. #include <stdio.h>
  21. #include "SAKeypadController.h"
  22. #include "display.h"
  23. #include "sacomguid.h"
  24. CServiceModule _Module;
  25. DWORD
  26. SetAclForComObject (
  27. /*[in]*/ PSECURITY_DESCRIPTOR pSD,
  28. /*[out*/ PACL *ppacl
  29. );
  30. BEGIN_OBJECT_MAP(ObjectMap)
  31. OBJECT_ENTRY(CLSID_SAKeypadController, CSAKeypadController)
  32. END_OBJECT_MAP()
  33. const wchar_t szServiceAppID[] = L"{0678A0EA-A69E-4211-8A3E-EBF80BB64D38}";
  34. LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2)
  35. {
  36. while (p1 != NULL && *p1 != NULL)
  37. {
  38. LPCTSTR p = p2;
  39. while (p != NULL && *p != NULL)
  40. {
  41. if (*p1 == *p)
  42. return CharNext(p1);
  43. p = CharNext(p);
  44. }
  45. p1 = CharNext(p1);
  46. }
  47. return NULL;
  48. }
  49. ///////////////////////////////////////////////////////////////////////////////
  50. // Although some of these functions are big they are declared inline
  51. // since they are only used once
  52. ///////////////////////////////////////////////////////////////////////////////
  53. ///////////////////////////////////////////////////////////////////////////////
  54. inline HRESULT CServiceModule::RegisterServer(BOOL bRegTypeLib, BOOL bService)
  55. {
  56. HRESULT hr = CoInitialize(NULL);
  57. if (FAILED(hr))
  58. {
  59. SATraceString ("LDM Service registration failed");
  60. return hr;
  61. }
  62. // Remove any previous service since it may point to
  63. // the incorrect file
  64. Uninstall();
  65. // Add service entries
  66. UpdateRegistryFromResource(IDR_Ldm, TRUE);
  67. // Adjust the AppID for Local Server or Service
  68. CRegKey keyAppID;
  69. LONG lRes = keyAppID.Open(HKEY_CLASSES_ROOT, _T("AppID"), KEY_WRITE);
  70. if (lRes != ERROR_SUCCESS)
  71. return lRes;
  72. CRegKey key;
  73. lRes = key.Open(keyAppID, szServiceAppID, KEY_WRITE);
  74. if (lRes != ERROR_SUCCESS)
  75. return lRes;
  76. key.DeleteValue(_T("LocalService"));
  77. if (bService)
  78. {
  79. key.SetValue(_T("saldm"), _T("LocalService"));
  80. key.SetValue(_T("-Service"), _T("ServiceParameters"));
  81. // Create service
  82. Install();
  83. }
  84. // Add object entries
  85. hr = CComModule::RegisterServer(bRegTypeLib);
  86. CoUninitialize();
  87. return hr;
  88. }
  89. ///////////////////////////////////////////////////////////////////////////////
  90. //
  91. inline HRESULT CServiceModule::UnregisterServer()
  92. {
  93. HRESULT hr = CoInitialize(NULL);
  94. if (FAILED(hr))
  95. return hr;
  96. // Remove service entries
  97. UpdateRegistryFromResource(IDR_Ldm, FALSE);
  98. // Remove service
  99. Uninstall();
  100. // Remove object entries
  101. CComModule::UnregisterServer(TRUE);
  102. CoUninitialize();
  103. return S_OK;
  104. }
  105. ///////////////////////////////////////////////////////////////////////////////
  106. //
  107. inline void CServiceModule::Init(_ATL_OBJMAP_ENTRY* p, HINSTANCE h,
  108. UINT nServiceNameID, UINT nServiceShortNameID,
  109. const GUID* plibid)
  110. {
  111. CComModule::Init(p, h, plibid);
  112. m_bService = TRUE;
  113. LoadString(h, nServiceNameID, m_szServiceName, sizeof(m_szServiceName) / sizeof(TCHAR));
  114. LoadString(h, nServiceShortNameID, m_szServiceShortName, sizeof(m_szServiceShortName) / sizeof(TCHAR));
  115. // set up the initial service status
  116. m_hServiceStatus = NULL;
  117. m_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
  118. m_status.dwCurrentState = SERVICE_STOPPED;
  119. m_status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
  120. m_status.dwWin32ExitCode = 0;
  121. m_status.dwServiceSpecificExitCode = 0;
  122. m_status.dwCheckPoint = 0;
  123. m_status.dwWaitHint = 0;
  124. }
  125. ///////////////////////////////////////////////////////////////////////////////
  126. //
  127. LONG CServiceModule::Unlock()
  128. {
  129. LONG l = CComModule::Unlock();
  130. if (l == 0 && !m_bService)
  131. PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
  132. return l;
  133. }
  134. ///////////////////////////////////////////////////////////////////////////////
  135. //
  136. BOOL CServiceModule::IsInstalled()
  137. {
  138. BOOL bResult = FALSE;
  139. SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
  140. if (hSCM != NULL)
  141. {
  142. SC_HANDLE hService = ::OpenService(hSCM, m_szServiceName, SERVICE_QUERY_CONFIG);
  143. if (hService != NULL)
  144. {
  145. bResult = TRUE;
  146. ::CloseServiceHandle(hService);
  147. }
  148. ::CloseServiceHandle(hSCM);
  149. }
  150. return bResult;
  151. }
  152. ///////////////////////////////////////////////////////////////////////////////
  153. //
  154. inline BOOL CServiceModule::Install()
  155. {
  156. if (IsInstalled())
  157. return TRUE;
  158. SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
  159. if (hSCM == NULL)
  160. {
  161. SATraceString ("CServiceModule::Install, Couldn't open service manager...");
  162. return FALSE;
  163. }
  164. // Get the executable file path
  165. TCHAR szFilePath[_MAX_PATH +1];
  166. DWORD dwResult = ::GetModuleFileName(NULL, szFilePath, _MAX_PATH);
  167. if (0 == dwResult)
  168. {
  169. return (FALSE);
  170. }
  171. szFilePath [_MAX_PATH] = L'\0';
  172. SC_HANDLE hService = ::CreateService(
  173. hSCM, m_szServiceShortName, m_szServiceName,
  174. SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
  175. SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
  176. szFilePath, NULL, NULL, _T("RPCSS\0"), NULL, NULL);
  177. if (hService == NULL)
  178. {
  179. ::CloseServiceHandle(hSCM);
  180. SATraceString ("CServiceModule::Install, Couldn't create service...");
  181. return FALSE;
  182. }
  183. ::CloseServiceHandle(hService);
  184. ::CloseServiceHandle(hSCM);
  185. return TRUE;
  186. }
  187. ///////////////////////////////////////////////////////////////////////////////
  188. //
  189. inline BOOL CServiceModule::Uninstall()
  190. {
  191. if (!IsInstalled())
  192. return TRUE;
  193. SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
  194. if (hSCM == NULL)
  195. {
  196. SATraceString ("CServiceModule::Uninstall, Couldn't open service manager...");
  197. return FALSE;
  198. }
  199. SC_HANDLE hService = ::OpenService(hSCM, m_szServiceName, SERVICE_STOP | DELETE);
  200. if (hService == NULL)
  201. {
  202. ::CloseServiceHandle(hSCM);
  203. SATraceString ("CServiceModule::Uninstall, Couldn't open service...");
  204. return FALSE;
  205. }
  206. SERVICE_STATUS status;
  207. ::ControlService(hService, SERVICE_CONTROL_STOP, &status);
  208. BOOL bDelete = ::DeleteService(hService);
  209. ::CloseServiceHandle(hService);
  210. ::CloseServiceHandle(hSCM);
  211. if (bDelete)
  212. return TRUE;
  213. SATraceString ("CServiceModule::Uninstall, Service could not be deleted...");
  214. return FALSE;
  215. }
  216. ///////////////////////////////////////////////////////////////////////////////////////
  217. // Logging functions
  218. void CServiceModule::LogEvent(LPCTSTR pFormat, ...)
  219. {
  220. TCHAR chMsg[256];
  221. HANDLE hEventSource;
  222. LPTSTR lpszStrings[1];
  223. va_list pArg;
  224. va_start(pArg, pFormat);
  225. _vstprintf(chMsg, pFormat, pArg);
  226. va_end(pArg);
  227. lpszStrings[0] = chMsg;
  228. if (m_bService)
  229. {
  230. /* Get a handle to use with ReportEvent(). */
  231. hEventSource = RegisterEventSource(NULL, m_szServiceName);
  232. if (hEventSource != NULL)
  233. {
  234. /* Write to event log. */
  235. ReportEvent(hEventSource, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (LPCTSTR*) &lpszStrings[0], NULL);
  236. DeregisterEventSource(hEventSource);
  237. }
  238. }
  239. else
  240. {
  241. // As we are not running as a service, just write the error to the console.
  242. _putts(chMsg);
  243. }
  244. }
  245. //////////////////////////////////////////////////////////////////////////////////////////////
  246. // Service startup and registration
  247. inline void CServiceModule::Start()
  248. {
  249. SERVICE_TABLE_ENTRY st[] =
  250. {
  251. { m_szServiceName, _ServiceMain },
  252. { NULL, NULL }
  253. };
  254. if (m_bService && !::StartServiceCtrlDispatcher(st))
  255. {
  256. m_bService = FALSE;
  257. }
  258. if (m_bService == FALSE)
  259. {
  260. //Run();
  261. }
  262. }
  263. ///////////////////////////////////////////////////////////////////////////////
  264. //
  265. inline void CServiceModule::ServiceMain(DWORD /* dwArgc */, LPTSTR* /* lpszArgv */)
  266. {
  267. // Register the control request handler
  268. m_status.dwCurrentState = SERVICE_START_PENDING;
  269. m_hServiceStatus = RegisterServiceCtrlHandler(m_szServiceName, _Handler);
  270. if (m_hServiceStatus == NULL)
  271. {
  272. return;
  273. }
  274. SetServiceStatus(SERVICE_START_PENDING);
  275. m_status.dwWin32ExitCode = S_OK;
  276. m_status.dwCheckPoint = 0;
  277. m_status.dwWaitHint = 0;
  278. // When the Run function returns, the service has stopped.
  279. Run();
  280. SetServiceStatus(SERVICE_STOPPED);
  281. }
  282. ///////////////////////////////////////////////////////////////////////////////
  283. //
  284. inline void CServiceModule::Handler(DWORD dwOpcode)
  285. {
  286. switch (dwOpcode)
  287. {
  288. case SERVICE_CONTROL_STOP:
  289. SetServiceStatus(SERVICE_STOP_PENDING);
  290. //
  291. // If we have a handle to the window, close the window
  292. //
  293. if (_Module.hwnd)
  294. {
  295. PostMessage(_Module.hwnd, WM_CLOSE, 0, 0);
  296. }
  297. //
  298. // quit the message pump with WM_QUIT message
  299. //
  300. else
  301. {
  302. PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
  303. }
  304. break;
  305. case SERVICE_CONTROL_PAUSE:
  306. break;
  307. case SERVICE_CONTROL_CONTINUE:
  308. break;
  309. case SERVICE_CONTROL_INTERROGATE:
  310. break;
  311. case SERVICE_CONTROL_SHUTDOWN:
  312. //
  313. // post IOCTL_SADISPLAY_SHUTDOWN_MESSAGE to display driver
  314. //
  315. PostLCDShutdownMessage();
  316. //
  317. // If we have a handle to the window, close the window
  318. //
  319. if (_Module.hwnd)
  320. {
  321. PostMessage(_Module.hwnd, WM_CLOSE, 0, 0);
  322. }
  323. //
  324. // quit the message pump with WM_QUIT message
  325. //
  326. else
  327. {
  328. PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
  329. }
  330. break;
  331. default:
  332. SATracePrintf ("LDM received unknown control request:%d", dwOpcode);
  333. }
  334. }
  335. //++--------------------------------------------------------------
  336. //
  337. // Function: PostLCDShutdownMessage
  338. //
  339. // Synopsis: This is the CServiceModule private method to send
  340. // the shutdown message to the LCD
  341. //
  342. // Arguments: none
  343. //
  344. // History: serdarun Created 04/05/2001
  345. //
  346. //-----------------------------------------------------------------
  347. void CServiceModule::PostLCDShutdownMessage()
  348. {
  349. CDisplay objDisplay;
  350. //
  351. // send IOCTL_SADISPLAY_SHUTDOWN_MESSAGE message to display driver
  352. // using the CDisplay class method
  353. //
  354. //
  355. // lock the display first
  356. //
  357. objDisplay.Lock ();
  358. //
  359. // post the shutdown now
  360. //
  361. objDisplay.Shutdown ();
  362. } // end of CServiceModule::PostLCDShutdownMessage method
  363. ///////////////////////////////////////////////////////////////////////////////
  364. //
  365. void WINAPI CServiceModule::_ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv)
  366. {
  367. _Module.ServiceMain(dwArgc, lpszArgv);
  368. }
  369. ///////////////////////////////////////////////////////////////////////////////
  370. //
  371. void WINAPI CServiceModule::_Handler(DWORD dwOpcode)
  372. {
  373. _Module.Handler(dwOpcode);
  374. }
  375. ///////////////////////////////////////////////////////////////////////////////
  376. //
  377. void CServiceModule::SetServiceStatus(DWORD dwState)
  378. {
  379. m_status.dwCurrentState = dwState;
  380. ::SetServiceStatus(m_hServiceStatus, &m_status);
  381. }
  382. ///////////////////////////////////////////////////////////////////////////////
  383. //
  384. void CServiceModule::Run()
  385. {
  386. _Module.dwThreadID = GetCurrentThreadId();
  387. HRESULT hr = CoInitialize(NULL);
  388. // If you are running on NT 4.0 or higher you can use the following call
  389. // instead to make the EXE free threaded.
  390. // This means that calls come in on a random RPC thread
  391. // HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  392. _ASSERTE(SUCCEEDED(hr));
  393. if (SUCCEEDED(hr))
  394. {
  395. CSecurityDescriptor sd;
  396. sd.InitializeFromThreadToken();
  397. PACL pacl = NULL;
  398. //
  399. //
  400. // Add ACLs to the SD using the builtin RIDs.
  401. //
  402. DWORD dwRetVal = SetAclForComObject (
  403. (PSECURITY_DESCRIPTOR) sd.m_pSD,
  404. &pacl
  405. );
  406. if (ERROR_SUCCESS != dwRetVal) {return;}
  407. hr = CoInitializeSecurity(
  408. sd,
  409. -1,
  410. NULL,
  411. NULL,
  412. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  413. RPC_C_IMP_LEVEL_IDENTIFY,
  414. NULL,
  415. EOAC_NONE,
  416. NULL);
  417. _ASSERTE(SUCCEEDED(hr));
  418. // Register the class with COM
  419. //
  420. if (SUCCEEDED(hr))
  421. {
  422. hr = _Module.RegisterClassObjects(CLSCTX_SERVER, REGCLS_MULTIPLEUSE);
  423. _ASSERTE(SUCCEEDED(hr));
  424. if (SUCCEEDED(hr))
  425. {
  426. if (m_bService)
  427. SetServiceStatus(SERVICE_RUNNING);
  428. CMainWindow m_ieWindow;
  429. hr = m_ieWindow.Initialize();
  430. m_ieWindow.id = _Module.dwThreadID;
  431. if (FAILED(hr))
  432. {
  433. _Module.hwnd = NULL;
  434. SATraceString ("Main window initialization failed");
  435. }
  436. else
  437. {
  438. _Module.hwnd = m_ieWindow.m_hWnd;
  439. m_ieWindow.ShowWindow(SW_SHOW);
  440. m_ieWindow.UpdateWindow();
  441. }
  442. MSG msg;
  443. while (GetMessage(&msg, NULL, 0, 0))
  444. {
  445. if ( (m_ieWindow.m_pMainInPlaceAO!= 0) && (!m_ieWindow.m_bActiveXFocus)/*&& (msg.wParam == VK_TAB) */)
  446. m_ieWindow.m_pMainInPlaceAO->TranslateAccelerator(&msg);
  447. TranslateMessage(&msg);
  448. DispatchMessage(&msg);
  449. }
  450. }
  451. _Module.RevokeClassObjects();
  452. }
  453. //
  454. // cleanup
  455. //
  456. if (pacl) {LocalFree (pacl);}
  457. CoUninitialize();
  458. }
  459. }
  460. /////////////////////////////////////////////////////////////////////////////
  461. //
  462. extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
  463. HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
  464. {
  465. lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT
  466. _Module.Init(ObjectMap, hInstance, IDS_SERVICENAME,
  467. IDS_SERVICESHORTNAME, &LIBID_LDMLib);
  468. _Module.m_bService = TRUE;
  469. TCHAR szTokens[] = _T("-/");
  470. LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
  471. while (lpszToken != NULL)
  472. {
  473. if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
  474. return _Module.UnregisterServer();
  475. // Register as Local Server
  476. if (lstrcmpi(lpszToken, _T("RegServer"))==0)
  477. return _Module.RegisterServer(TRUE, FALSE);
  478. // Register as Service
  479. if (lstrcmpi(lpszToken, _T("Service"))==0)
  480. return _Module.RegisterServer(TRUE, TRUE);
  481. lpszToken = FindOneOf(lpszToken, szTokens);
  482. }
  483. // Are we Service or Local Server
  484. CRegKey keyAppID;
  485. LONG lRes = keyAppID.Open(HKEY_CLASSES_ROOT, _T("AppID"), KEY_READ);
  486. if (lRes != ERROR_SUCCESS)
  487. {
  488. return lRes;
  489. }
  490. CRegKey key;
  491. lRes = key.Open(keyAppID, szServiceAppID, KEY_READ);
  492. if (lRes != ERROR_SUCCESS)
  493. {
  494. return lRes;
  495. }
  496. TCHAR szValue[_MAX_PATH];
  497. DWORD dwLen = _MAX_PATH;
  498. lRes = key.QueryValue(szValue, _T("LocalService"), &dwLen);
  499. _Module.m_bService = FALSE;
  500. if (lRes == ERROR_SUCCESS)
  501. _Module.m_bService = TRUE;
  502. _Module.Start();
  503. // When we get here, the service has been stopped
  504. return _Module.m_status.dwWin32ExitCode;
  505. }
  506. //++--------------------------------------------------------------
  507. //
  508. // Function: SetAclForComObject
  509. //
  510. // Synopsis: method for providing only the Local System and Admins rights
  511. // to access the COM object
  512. //
  513. // Arguments: none
  514. //
  515. // Returns: HRESULT
  516. //
  517. // History: MKarki 11/15/2001 Created
  518. // serdarun 04/07/2002 remove admin from list
  519. //----------------------------------------------------------------
  520. DWORD
  521. SetAclForComObject (
  522. /*[in]*/ PSECURITY_DESCRIPTOR pSD,
  523. /*[out*/ PACL *ppacl
  524. )
  525. {
  526. DWORD dwError = ERROR_SUCCESS;
  527. int cbAcl = 0;
  528. PACL pacl = NULL;
  529. PSID psidLocalSystemSid = NULL;
  530. SID_IDENTIFIER_AUTHORITY siaLocalSystemSidAuthority = SECURITY_NT_AUTHORITY;
  531. CSATraceFunc objTraceFunc ("SetAclFromComObject");
  532. do
  533. {
  534. if (NULL == pSD)
  535. {
  536. SATraceString ("SetAclFromComObject - invalid parameter passed in");
  537. dwError = ERROR_INVALID_PARAMETER;
  538. break;
  539. }
  540. //
  541. // Create a SID for Local System account
  542. //
  543. BOOL bRetVal = AllocateAndInitializeSid (
  544. &siaLocalSystemSidAuthority,
  545. 1,
  546. SECURITY_LOCAL_SYSTEM_RID,
  547. 0,
  548. 0,
  549. 0,
  550. 0,
  551. 0,
  552. 0,
  553. 0,
  554. &psidLocalSystemSid
  555. );
  556. if (!bRetVal)
  557. {
  558. dwError = GetLastError ();
  559. SATraceFailure ("SetAclFromComObject:AllocateAndInitializeSid (LOCAL SYSTEM) failed", dwError);
  560. break;
  561. }
  562. //
  563. // Calculate the length of required ACL buffer
  564. // with 1 ACE
  565. //
  566. cbAcl = sizeof (ACL)
  567. + sizeof (ACCESS_ALLOWED_ACE)
  568. + GetLengthSid( psidLocalSystemSid );
  569. pacl = (PACL) LocalAlloc ( 0, cbAcl );
  570. if (NULL == pacl)
  571. {
  572. dwError = ERROR_OUTOFMEMORY;
  573. SATraceFailure ("SetAclFromComObject::LocalAlloc failed:", dwError);
  574. break;
  575. }
  576. //
  577. // initialize the ACl now
  578. //
  579. bRetVal =InitializeAcl(
  580. pacl,
  581. cbAcl,
  582. ACL_REVISION2
  583. );
  584. if (!bRetVal)
  585. {
  586. dwError = GetLastError();
  587. SATraceFailure ("SetAclFromComObject::InitializeAcl failed:", dwError);
  588. break;
  589. }
  590. //
  591. // Add ACE with EVENT_ALL_ACCESS for Local System account
  592. //
  593. bRetVal = AddAccessAllowedAce (
  594. pacl,
  595. ACL_REVISION2,
  596. COM_RIGHTS_EXECUTE,
  597. psidLocalSystemSid
  598. );
  599. if (!bRetVal)
  600. {
  601. dwError = GetLastError();
  602. SATraceFailure ("SetAclFromComObject::AddAccessAllowedAce (LOCAL SYSTEM) failed:", dwError);
  603. break;
  604. }
  605. //
  606. // Set the ACL which allows EVENT_ALL_ACCESS for all users and
  607. // Local System to the security descriptor.
  608. bRetVal = SetSecurityDescriptorDacl (
  609. pSD,
  610. TRUE,
  611. pacl,
  612. FALSE
  613. );
  614. if (!bRetVal)
  615. {
  616. dwError = GetLastError();
  617. SATraceFailure ("SetAclFromComObject::SetSecurityDescriptorDacl failed:", dwError);
  618. break;
  619. }
  620. //
  621. // success
  622. //
  623. }
  624. while (false);
  625. //
  626. // in case of error, cleanup
  627. //
  628. if (dwError)
  629. {
  630. if ( pacl )
  631. {
  632. LocalFree ( pacl );
  633. }
  634. }
  635. else
  636. {
  637. *ppacl = pacl;
  638. }
  639. //
  640. // free up resources now
  641. //
  642. if ( psidLocalSystemSid ) {FreeSid ( psidLocalSystemSid );}
  643. return (dwError);
  644. }//End of SetAclFromComObject method