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.

658 lines
18 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: rotif.cxx
  7. //
  8. // Contents: Initialization for SCM ROT and RPC interface
  9. //
  10. // Functions: InitScmRot
  11. // IrotRegister
  12. // IrotRevoke
  13. // IrotIsRunning
  14. // IrotGetObject
  15. // IrotNoteChangeTime
  16. // IrotGetTimeOfLastChange
  17. // IrotEnumRunning
  18. // GetObjectFromRot
  19. //
  20. // History: 24-Jan-95 Ricksa Created
  21. //
  22. //--------------------------------------------------------------------------
  23. #include "act.hxx"
  24. CScmRot *gpscmrot = NULL;
  25. //+-------------------------------------------------------------------------
  26. //
  27. // Function: InitScmRot
  28. //
  29. // Synopsis: Initialize ROT Directory for the SCM
  30. // NOTE: if InitRotDir is ever called by any process other than the
  31. // SCM then the RpcServerRegisterIf may fail with RPC_S_TYPE_ALREADY_REGISTERED
  32. // in some unusal cases. Change the error checking code to ignore that error.
  33. //
  34. // Returns: S_OK - Created ROT directory successfully
  35. //
  36. // History: 17-Nov-93 Ricksa Created
  37. // 26-Jul-94 AndyH Added warning above while bug hunting.
  38. // 25-Jan-95 Ricksa New rot
  39. //
  40. // Notes: This routine is only in non-chicago builds
  41. //
  42. //--------------------------------------------------------------------------
  43. HRESULT InitScmRot()
  44. {
  45. CairoleDebugOut((DEB_ROT, "%p _IN InitScmRot \n", NULL));
  46. HRESULT hr = E_OUTOFMEMORY;
  47. gpscmrot = new CScmRot(hr, ROTHINT_NAME);
  48. if (SUCCEEDED(hr))
  49. {
  50. RPC_STATUS status;
  51. status = RpcServerRegisterIfEx(IROT_ServerIfHandle,
  52. NULL,
  53. NULL,
  54. 0,
  55. RPC_C_LISTEN_MAX_CALLS_DEFAULT,
  56. LocalInterfaceOnlySecCallback);
  57. ASSERT((status == RPC_S_OK) && "RpcServerRegisterIf for IROT failed!");
  58. if (status == RPC_S_OK)
  59. {
  60. hr = S_OK;
  61. }
  62. else
  63. {
  64. hr = HRESULT_FROM_WIN32(status);
  65. delete gpscmrot;
  66. gpscmrot = NULL;
  67. }
  68. }
  69. CairoleDebugOut((DEB_ROT, "%p OUT InitScmRot ( %lx )\n", NULL, hr));
  70. return hr;
  71. }
  72. //+-------------------------------------------------------------------------
  73. //
  74. // Function: IrotRegister
  75. //
  76. // Synopsis: Main entry point for registering an item in the ROT
  77. //
  78. // Arguments: [hRpc] - rpc handle to SCM
  79. // [phProcess] - context handle (CProcess)
  80. // [pmkeqbuf] - moniker equality buffer
  81. // [pifdObject] - marshaled object
  82. // [pifdObjectName] - marshaled moniker
  83. // [pfiletime] - time of last change
  84. // [dwProcessID] - process ID for object
  85. // [psrkRegister] - SCM registration ID
  86. // [prpcstat] - RPC communication status
  87. //
  88. // Returns: NOERROR
  89. //
  90. // History: 30-Jan-95 Ricksa Created
  91. //
  92. // Notes: The purpose of this routine is really just to make the
  93. // code more readable.
  94. //
  95. //--------------------------------------------------------------------------
  96. extern "C" HRESULT IrotRegister(
  97. handle_t hRpc,
  98. PHPROCESS phProcess,
  99. WCHAR *pwszWinstaDesktop,
  100. MNKEQBUF *pmkeqbuf,
  101. InterfaceData *pifdObject,
  102. InterfaceData *pifdObjectName,
  103. FILETIME *pfiletime,
  104. DWORD dwProcessID,
  105. WCHAR *pwszServerExe,
  106. SCMREGKEY *psrkRegister,
  107. error_status_t *prpcstat)
  108. {
  109. CProcess* pProcess = CheckLocalSecurity(hRpc, phProcess);
  110. if (!pProcess)
  111. return E_ACCESSDENIED;
  112. // Ole32 always sends us a desktop. Since NULL is a reserved value
  113. // internally, don't let anybody send us such a value from outside.
  114. if (!pwszWinstaDesktop)
  115. return E_ACCESSDENIED;
  116. VDATEHEAP();
  117. if (!prpcstat)
  118. return E_ACCESSDENIED;
  119. *prpcstat = RPC_S_OK;
  120. #if DBG == 1
  121. CairoleDebugOut((DEB_SCM, "%p _IN IrotRegister\n", NULL));
  122. DbgPrintMnkEqBuf("_IN Moinker Compare Buffer:", pmkeqbuf);
  123. DbgPrintIFD("_IN Object Interface Data:", pifdObject);
  124. DbgPrintIFD("_IN Moniker Interface Data:", pifdObject);
  125. DbgPrintFileTime("_IN FileTime: ", pfiletime);
  126. CairoleDebugOut((DEB_SCM, "_IN Process ID: %lX\n", dwProcessID));
  127. #endif // DBG == 1
  128. HRESULT hr = E_OUTOFMEMORY;
  129. if (gpscmrot != NULL)
  130. {
  131. hr = gpscmrot->Register(pProcess,
  132. pwszWinstaDesktop,
  133. pmkeqbuf,
  134. pifdObject,
  135. pifdObjectName,
  136. pfiletime,
  137. dwProcessID,
  138. pwszServerExe,
  139. psrkRegister);
  140. }
  141. #if DBG == 1
  142. CairoleDebugOut((DEB_SCM, "%p OUT IrotRegister\n", NULL));
  143. CairoleDebugOut((DEB_SCM, "OUT Hresult %lX\n", hr));
  144. if (SUCCEEDED(hr))
  145. {
  146. DbgPrintScmRegKey("OUT Register Key: ", psrkRegister);
  147. }
  148. #endif // DBG == 1
  149. VDATEHEAP();
  150. return hr;
  151. }
  152. //+-------------------------------------------------------------------------
  153. //
  154. // Function: IrotRevoke
  155. //
  156. // Synopsis: Main entry point for revoking an item from the ROT
  157. //
  158. // Arguments: [hRpc] - rpc handle to SCM
  159. // [phProcess] - context handle (CProcess)
  160. // [psrkRegister] - SCM registration ID
  161. // [ppifdObject] - returned marshaled object
  162. // [ppifdObjectName] - returned marshaled moniker
  163. // [prpcstat] - RPC communication status
  164. //
  165. // Returns: NOERROR
  166. //
  167. // History: 30-Jan-95 Ricksa Created
  168. //
  169. // Notes: The purpose of this routine is really just to make the
  170. // code more readable.
  171. //
  172. //--------------------------------------------------------------------------
  173. extern "C" HRESULT IrotRevoke(
  174. handle_t hRpc,
  175. PHPROCESS phProcess,
  176. SCMREGKEY *psrkRegister,
  177. InterfaceData **ppifdObject,
  178. InterfaceData **ppifdName,
  179. error_status_t *prpcstat)
  180. {
  181. CProcess* pProcess = CheckLocalSecurity(hRpc, phProcess);
  182. if (!pProcess)
  183. return E_ACCESSDENIED;
  184. VDATEHEAP();
  185. if (!prpcstat)
  186. return E_ACCESSDENIED;
  187. *prpcstat = RPC_S_OK;
  188. #if DBG == 1
  189. CairoleDebugOut((DEB_SCM, "%p _IN IrotRevoke\n", NULL));
  190. DbgPrintScmRegKey("_IN Revoke Key: ", psrkRegister);
  191. CairoleDebugOut((DEB_SCM, "_IN Object Interface Data Ptr: %lx\n",
  192. ppifdObject));
  193. CairoleDebugOut((DEB_SCM, "_IN Moniker Interface Data Ptr: %lx\n",
  194. ppifdName));
  195. #endif // DBG == 1
  196. HRESULT hr = E_OUTOFMEMORY;
  197. if (gpscmrot != NULL)
  198. {
  199. hr = gpscmrot->Revoke(pProcess, psrkRegister, ppifdObject, ppifdName);
  200. }
  201. #if DBG == 1
  202. CairoleDebugOut((DEB_SCM, "%p OUT IrotRevoke\n", NULL));
  203. CairoleDebugOut((DEB_SCM, "OUT Hresult : %lx\n", hr));
  204. if (*ppifdObject != NULL)
  205. {
  206. DbgPrintIFD("OUT Object Interface Data:", *ppifdObject);
  207. }
  208. if (*ppifdName != NULL)
  209. {
  210. DbgPrintIFD("OUT Moniker Interface Data:", *ppifdName);
  211. }
  212. #endif // DBG == 1
  213. VDATEHEAP();
  214. return hr;
  215. }
  216. //+-------------------------------------------------------------------------
  217. //
  218. // Function: IrotIsRunning
  219. //
  220. // Synopsis: Main entry point for determining if an entry is in the ROT
  221. //
  222. // Arguments: [hRpc] - rpc handle to SCM
  223. // [pmkeqbuf] - moniker equality buffer
  224. // [prpcstat] - RPC communication status
  225. //
  226. // Returns: NOERROR
  227. //
  228. // History: 30-Jan-95 Ricksa Created
  229. //
  230. // Notes: The purpose of this routine is really just to make the
  231. // code more readable.
  232. //
  233. //--------------------------------------------------------------------------
  234. extern "C" HRESULT IrotIsRunning(
  235. handle_t hRpc,
  236. PHPROCESS phProcess,
  237. WCHAR *pwszWinstaDesktop,
  238. MNKEQBUF *pmkeqbuf,
  239. error_status_t *prpcstat)
  240. {
  241. CProcess* pProcess = CheckLocalSecurity(hRpc, phProcess);
  242. if (!pProcess)
  243. return E_ACCESSDENIED;
  244. VDATEHEAP();
  245. if (!prpcstat)
  246. return E_ACCESSDENIED;
  247. *prpcstat = RPC_S_OK;
  248. #if DBG == 1
  249. CairoleDebugOut((DEB_SCM, "%p _IN IrotIsRunning\n", NULL));
  250. DbgPrintMnkEqBuf("_IN Moniker Compare Buffer:", pmkeqbuf);
  251. #endif // DBG == 1
  252. HRESULT hr = E_OUTOFMEMORY;
  253. if (gpscmrot != NULL)
  254. {
  255. hr = gpscmrot->IsRunning(
  256. pProcess->GetToken(),
  257. pwszWinstaDesktop,
  258. pmkeqbuf);
  259. }
  260. #if DBG == 1
  261. CairoleDebugOut((DEB_SCM, "%p OUT IrotIsRunning\n", NULL));
  262. CairoleDebugOut((DEB_SCM, "OUT Hresult : %lx\n", hr));
  263. #endif // DBG == 1
  264. VDATEHEAP();
  265. return hr;
  266. }
  267. //+-------------------------------------------------------------------------
  268. //
  269. // Function: IrotGetObject
  270. //
  271. // Synopsis: Main entry point for getting an object from the ROT
  272. //
  273. // Arguments: [hRpc] - rpc handle to SCM
  274. // [dwProcessID] - process id for object
  275. // [pmkeqbuf] - moniker equality buffer
  276. // [psrkRegister] - Registration ID of returned Object
  277. // [ppifdObject] - returned marshaled object
  278. // [prpcstat] - RPC communication status
  279. //
  280. // Returns: NOERROR
  281. //
  282. // History: 30-Jan-95 Ricksa Created
  283. //
  284. // Notes:
  285. //
  286. //--------------------------------------------------------------------------
  287. extern "C" HRESULT IrotGetObject(
  288. handle_t hRpc,
  289. PHPROCESS phProcess,
  290. WCHAR *pwszWinstaDesktop,
  291. DWORD dwProcessID,
  292. MNKEQBUF *pmkeqbuf,
  293. SCMREGKEY *psrkRegister,
  294. InterfaceData **ppifdObject,
  295. error_status_t *prpcstat)
  296. {
  297. CProcess* pProcess = CheckLocalSecurity(hRpc, phProcess);
  298. if (!pProcess)
  299. return E_ACCESSDENIED;
  300. VDATEHEAP();
  301. if (!prpcstat)
  302. return E_ACCESSDENIED;
  303. *prpcstat = RPC_S_OK;
  304. #if DBG == 1
  305. CairoleDebugOut((DEB_SCM, "%p _IN IrotGetObject\n", NULL));
  306. CairoleDebugOut((DEB_SCM, "_IN Process ID: %lX\n", dwProcessID));
  307. DbgPrintMnkEqBuf("_IN Moniker Compare Buffer:", pmkeqbuf);
  308. #endif // DBG == 1
  309. HRESULT hr = E_OUTOFMEMORY;
  310. if (gpscmrot != NULL)
  311. {
  312. hr = gpscmrot->GetObject(
  313. pProcess->GetToken(),
  314. pwszWinstaDesktop,
  315. dwProcessID,
  316. pmkeqbuf,
  317. psrkRegister,
  318. ppifdObject);
  319. }
  320. #if DBG == 1
  321. CairoleDebugOut((DEB_SCM, "%p OUT IrotGetObject\n", NULL));
  322. CairoleDebugOut((DEB_SCM, "OUT Hresult : %lx\n", hr));
  323. if (SUCCEEDED(hr))
  324. {
  325. DbgPrintScmRegKey("OUT Register Key: ", psrkRegister);
  326. DbgPrintIFD("OUT Object Interface Data:", *ppifdObject);
  327. }
  328. #endif // DBG == 1
  329. VDATEHEAP();
  330. return hr;
  331. }
  332. //+-------------------------------------------------------------------------
  333. //
  334. // Function: IrotNoteChangeTime
  335. //
  336. // Synopsis: Main entry point for setting the change time of an object
  337. // int the ROT.
  338. //
  339. // Arguments: [hRpc] - rpc handle to SCM
  340. // [psrkRegister] - Registration ID of Object to update
  341. // [pfiletime] - new change time for the object
  342. // [prpcstat] - RPC communication status
  343. //
  344. // Returns: NOERROR
  345. //
  346. // History: 30-Jan-95 Ricksa Created
  347. //
  348. // Notes:
  349. //
  350. //--------------------------------------------------------------------------
  351. extern "C" HRESULT IrotNoteChangeTime(
  352. handle_t hRpc,
  353. PHPROCESS phProcess,
  354. SCMREGKEY *psrkRegister,
  355. FILETIME *pfiletime,
  356. error_status_t *prpcstat)
  357. {
  358. CProcess* pProcess = CheckLocalSecurity(hRpc, phProcess);
  359. if (!pProcess)
  360. return E_ACCESSDENIED;
  361. VDATEHEAP();
  362. if (!prpcstat)
  363. return E_ACCESSDENIED;
  364. *prpcstat = RPC_S_OK;
  365. #if DBG == 1
  366. CairoleDebugOut((DEB_SCM, "%p _IN IrotNoteChangeTime\n", NULL));
  367. DbgPrintScmRegKey("_IN Revoke Key: ", psrkRegister);
  368. DbgPrintFileTime("_IN FileTime: ", pfiletime);
  369. #endif // DBG == 1
  370. HRESULT hr = E_OUTOFMEMORY;
  371. if (gpscmrot != NULL)
  372. {
  373. hr = gpscmrot->NoteChangeTime(psrkRegister, pfiletime);
  374. }
  375. #if DBG == 1
  376. CairoleDebugOut((DEB_SCM, "%p OUT IrotRevoke\n", NULL));
  377. CairoleDebugOut((DEB_SCM, "OUT Hresult : %lx\n", hr));
  378. #endif // DBG == 1
  379. VDATEHEAP();
  380. return hr;
  381. }
  382. //+-------------------------------------------------------------------------
  383. //
  384. // Function: IrotGetTimeOfLastChange
  385. //
  386. // Synopsis: Main entry point for getting the change time of an object
  387. // int the ROT.
  388. //
  389. // Arguments: [hRpc] - rpc handle to SCM
  390. // [pmkeqbuf] - Moniker for object
  391. // [pfiletime] - new change time for the object
  392. // [prpcstat] - RPC communication status
  393. //
  394. // Returns: NOERROR
  395. //
  396. // History: 30-Jan-95 Ricksa Created
  397. //
  398. // Notes:
  399. //
  400. //--------------------------------------------------------------------------
  401. extern "C" HRESULT IrotGetTimeOfLastChange(
  402. handle_t hRpc,
  403. PHPROCESS phProcess,
  404. WCHAR *pwszWinstaDesktop,
  405. MNKEQBUF *pmkeqbuf,
  406. FILETIME *pfiletime,
  407. error_status_t *prpcstat)
  408. {
  409. CProcess* pProcess = CheckLocalSecurity(hRpc, phProcess);
  410. if (!pProcess)
  411. return E_ACCESSDENIED;
  412. VDATEHEAP();
  413. if (!prpcstat)
  414. return E_ACCESSDENIED;
  415. *prpcstat = RPC_S_OK;
  416. #if DBG == 1
  417. CairoleDebugOut((DEB_SCM, "%p _IN IrotGetTimeOfLastChange\n", NULL));
  418. DbgPrintMnkEqBuf("_IN Moniker Compare Buffer:", pmkeqbuf);
  419. #endif // DBG == 1
  420. HRESULT hr = E_OUTOFMEMORY;
  421. if (gpscmrot != NULL)
  422. {
  423. hr = gpscmrot->GetTimeOfLastChange(
  424. pProcess->GetToken(),
  425. pwszWinstaDesktop,
  426. pmkeqbuf,
  427. pfiletime);
  428. }
  429. #if DBG == 1
  430. CairoleDebugOut((DEB_SCM, "%p OUT IrotGetTimeOfLastChange\n", NULL));
  431. CairoleDebugOut((DEB_SCM, "OUT Hresult : %lx\n", hr));
  432. DbgPrintFileTime("OUT FileTime: ", pfiletime);
  433. #endif // DBG == 1
  434. VDATEHEAP();
  435. return hr;
  436. }
  437. //+-------------------------------------------------------------------------
  438. //
  439. // Function: IrotEnumRunning
  440. //
  441. // Synopsis: Main entry point for getting all monikers to running objects
  442. // int the ROT.
  443. //
  444. // Arguments: [hRpc] - rpc handle to SCM
  445. // [ppMKIFList] - list of marshaled monikers to running objects
  446. // [prpcstat] - RPC communication status
  447. //
  448. // Returns: NOERROR
  449. //
  450. // History: 30-Jan-95 Ricksa Created
  451. //
  452. // Notes:
  453. //
  454. //--------------------------------------------------------------------------
  455. extern "C" HRESULT IrotEnumRunning(
  456. handle_t hRpc,
  457. PHPROCESS phProcess,
  458. WCHAR *pwszWinstaDesktop,
  459. MkInterfaceList **ppMkIFList,
  460. error_status_t *prpcstat)
  461. {
  462. CProcess* pProcess = CheckLocalSecurity(hRpc, phProcess);
  463. if (!pProcess)
  464. return E_ACCESSDENIED;
  465. VDATEHEAP();
  466. if (!prpcstat)
  467. return E_ACCESSDENIED;
  468. *prpcstat = RPC_S_OK;
  469. CairoleDebugOut((DEB_SCM, "%p _IN IrotEnumRunning\n", NULL));
  470. HRESULT hr = E_OUTOFMEMORY;
  471. if (gpscmrot != NULL)
  472. {
  473. hr = gpscmrot->EnumRunning(
  474. pProcess->GetToken(),
  475. pwszWinstaDesktop,
  476. ppMkIFList);
  477. }
  478. #if DBG == 1
  479. CairoleDebugOut((DEB_SCM, "%p OUT IrotEnumRunning\n", NULL));
  480. CairoleDebugOut((DEB_SCM, "OUT Hresult : %lx\n", hr));
  481. if (SUCCEEDED(hr))
  482. {
  483. DbgPrintMkIfList("OUT Moniker IF List: ", ppMkIFList);
  484. }
  485. #endif // DBG == 1
  486. VDATEHEAP();
  487. return hr;
  488. }
  489. //+-------------------------------------------------------------------------
  490. //
  491. // Function: GetObjectFromRot
  492. //
  493. // Synopsis: Helper for binding to locate an object in the ROT
  494. //
  495. // Arguments: [pwszPath] - path for bind
  496. // [ppifdObject] - marshaled output buffer
  497. //
  498. // Returns: NOERROR
  499. //
  500. // Algorithm: Get the ROT. Create a moniker comparison buffer for searching
  501. // the ROT. Then try to get the object out of the ROT.
  502. //
  503. // History: 30-Jan-95 Ricksa Created
  504. //
  505. // Notes:
  506. //
  507. //--------------------------------------------------------------------------
  508. HRESULT GetObjectFromRot(
  509. CToken *pToken,
  510. WCHAR *pwszWinstaDesktop,
  511. WCHAR *pwszPath,
  512. InterfaceData **ppifdObject)
  513. {
  514. VDATEHEAP();
  515. CairoleDebugOut((DEB_ROT, "%p _IN GetObjectFromRot "
  516. "( %p , %p )\n", NULL, pwszPath, ppifdObject));
  517. HRESULT hr = E_OUTOFMEMORY;
  518. if (gpscmrot != NULL)
  519. {
  520. // Create a moniker equality buffer from path
  521. CTmpMkEqBuf tmeb;
  522. hr = CreateFileMonikerComparisonBuffer(pwszPath, tmeb.GetBuf(),
  523. tmeb.GetSize(), tmeb.GetSizeAddr());
  524. if (hr == NOERROR)
  525. {
  526. // SCMREGKEY which we won't really use
  527. SCMREGKEY srkRegister;
  528. hr = gpscmrot->GetObject(
  529. pToken,
  530. pwszWinstaDesktop,
  531. 0,
  532. tmeb.GetMkEqBuf(),
  533. &srkRegister,
  534. ppifdObject );
  535. }
  536. }
  537. CairoleDebugOut((DEB_ROT, "%p OUT GetObjectFromRot ( %lx ) [ %p ]\n",
  538. NULL, hr, *ppifdObject));
  539. return hr;
  540. }