Source code of Windows XP (NT5)
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.

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