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.

471 lines
12 KiB

  1. #include <pch.cxx>
  2. #pragma hdrstop
  3. #define TRKDATA_ALLOCATE
  4. #include "trklib.hxx"
  5. #include "trkwks.hxx"
  6. #include "trkstub.h"
  7. extern "C"
  8. NTSTATUS
  9. WINAPI
  10. StartTrkWksServiceStubs(
  11. PSVCS_START_RPC_SERVER RpcpStartRpcServer,
  12. LPTSTR SvcsRpcPipeName
  13. )
  14. {
  15. NTSTATUS dwStatus = STATUS_SUCCESS;
  16. dwStatus = RpcpStartRpcServer(
  17. SvcsRpcPipeName,
  18. Stubtrkwks_v1_2_s_ifspec
  19. );
  20. if(NT_SUCCESS(dwStatus))
  21. {
  22. dwStatus = RpcpStartRpcServer(
  23. SvcsRpcPipeName,
  24. Stubtrkwks_v1_2_s_ifspec
  25. );
  26. }
  27. return dwStatus;
  28. }
  29. extern "C"
  30. NTSTATUS
  31. WINAPI
  32. StopTrkWksServiceStubs(
  33. PSVCS_STOP_RPC_SERVER RpcpStopRpcServer
  34. )
  35. {
  36. NTSTATUS dwStatus = STATUS_SUCCESS;
  37. RpcpStopRpcServer(
  38. Stubtrkwks_v1_2_s_ifspec
  39. );
  40. dwStatus = RpcpStopRpcServer(
  41. Stubtrkwks_v1_2_s_ifspec
  42. );
  43. return dwStatus;
  44. }
  45. HRESULT
  46. GetBinding( const TCHAR *ptszProtSeq,
  47. const TCHAR *ptszEndPoint,
  48. RPC_BINDING_HANDLE *phBinding )
  49. {
  50. WCHAR *pwszStringBinding = NULL;
  51. HRESULT hr = E_FAIL;
  52. RPC_STATUS rpcstatus;
  53. rpcstatus = RpcStringBindingCompose( NULL,
  54. const_cast<TCHAR*>(ptszProtSeq),
  55. NULL,
  56. const_cast<TCHAR*>(ptszEndPoint),
  57. NULL,
  58. &pwszStringBinding);
  59. if( RPC_S_OK != rpcstatus )
  60. {
  61. hr = rpcstatus;
  62. goto Exit;
  63. }
  64. rpcstatus = RpcBindingFromStringBinding( pwszStringBinding, phBinding );
  65. if( RPC_S_OK != rpcstatus )
  66. {
  67. hr = rpcstatus;
  68. goto Exit;
  69. }
  70. hr = S_OK;
  71. Exit:
  72. if( NULL != pwszStringBinding )
  73. {
  74. RpcStringFree( &pwszStringBinding );
  75. pwszStringBinding = NULL;
  76. }
  77. return hr;
  78. }
  79. HRESULT StubLnkSearchMachine(RPC_BINDING_HANDLE IDL_handle,
  80. ULONG RestrictionsIn,
  81. const CDomainRelativeObjId *pdroidBirthLast,
  82. const CDomainRelativeObjId *pdroidLast,
  83. CDomainRelativeObjId *pdroidBirthNext,
  84. CDomainRelativeObjId *pdroidNext,
  85. CMachineId *pmcidNext,
  86. TCHAR *ptsz )
  87. {
  88. HRESULT hr;
  89. RPC_STATUS rpcstatus;
  90. RPC_BINDING_HANDLE hBinding = NULL;
  91. BOOL fImpersonating = FALSE;
  92. hr = GetBinding( s_tszTrkWksRemoteRpcProtocol,
  93. s_tszTrkWksRemoteRpcEndPoint,
  94. &hBinding );
  95. if( FAILED(hr) ) goto Exit;
  96. rpcstatus = RpcImpersonateClient( IDL_handle );
  97. if( STATUS_SUCCESS != rpcstatus )
  98. {
  99. hr = HRESULT_FROM_WIN32( rpcstatus );
  100. goto Exit;
  101. }
  102. fImpersonating = TRUE;
  103. __try
  104. {
  105. hr = LnkSearchMachine( hBinding,
  106. RestrictionsIn,
  107. pdroidBirthLast,
  108. pdroidLast,
  109. pdroidBirthNext,
  110. pdroidNext,
  111. pmcidNext,
  112. ptsz );
  113. }
  114. __except( EXCEPTION_EXECUTE_HANDLER )
  115. {
  116. hr = GetExceptionCode();
  117. }
  118. Exit:
  119. if( fImpersonating )
  120. {
  121. RpcRevertToSelf();
  122. }
  123. if( NULL != hBinding )
  124. {
  125. RpcBindingFree( &hBinding );
  126. hBinding = NULL;
  127. }
  128. return hr;
  129. }
  130. HRESULT StubLnkCallSvrMessage(
  131. /* [in] */ handle_t IDL_handle,
  132. /* [switch_is][out][in] */ TRKSVR_MESSAGE_UNION __RPC_FAR *pMsg)
  133. {
  134. HRESULT hr;
  135. RPC_STATUS rpcstatus;
  136. RPC_BINDING_HANDLE hBinding = NULL;
  137. BOOL fImpersonating = FALSE;
  138. hr = GetBinding( s_tszTrkWksRemoteRpcProtocol,
  139. s_tszTrkWksRemoteRpcEndPoint,
  140. &hBinding );
  141. if( FAILED(hr) ) goto Exit;
  142. rpcstatus = RpcImpersonateClient( IDL_handle );
  143. if( STATUS_SUCCESS != rpcstatus )
  144. {
  145. hr = HRESULT_FROM_WIN32( rpcstatus );
  146. goto Exit;
  147. }
  148. fImpersonating = TRUE;
  149. __try
  150. {
  151. hr = LnkCallSvrMessage( hBinding, pMsg );
  152. }
  153. __except( EXCEPTION_EXECUTE_HANDLER )
  154. {
  155. hr = GetExceptionCode();
  156. }
  157. Exit:
  158. if( fImpersonating )
  159. {
  160. RpcRevertToSelf();
  161. }
  162. if( NULL != hBinding )
  163. {
  164. RpcBindingFree( &hBinding );
  165. hBinding = NULL;
  166. }
  167. return hr;
  168. }
  169. void
  170. StubLnkMendLink(PRPC_ASYNC_STATE pAsync_handle,
  171. RPC_BINDING_HANDLE IDL_handle,
  172. FILETIME ftLimit,
  173. DWORD RestrictionsIn,
  174. const CDomainRelativeObjId *pdroidBirth,
  175. const CDomainRelativeObjId *pdroidLast,
  176. const CMachineId * pmcidLast,
  177. CDomainRelativeObjId * pdroidCurrent,
  178. CMachineId * pmcidCurrent,
  179. ULONG * pcbPath,
  180. WCHAR * wsz)
  181. {
  182. HRESULT hr;
  183. RPC_STATUS rpcstatus;
  184. RPC_BINDING_HANDLE hBinding = NULL;
  185. BOOL fImpersonating = FALSE;
  186. RPC_ASYNC_STATE RpcAsyncState;
  187. HANDLE hEvent = NULL;
  188. hr = GetBinding( s_tszTrkWksLocalRpcProtocol,
  189. s_tszTrkWksLocalRpcEndPoint,
  190. &hBinding );
  191. if( FAILED(hr) ) goto Exit;
  192. rpcstatus = RpcImpersonateClient( IDL_handle );
  193. if( STATUS_SUCCESS != rpcstatus )
  194. {
  195. hr = HRESULT_FROM_WIN32( rpcstatus );
  196. goto Exit;
  197. }
  198. fImpersonating = TRUE;
  199. __try
  200. {
  201. DWORD dwWaitReturn;
  202. rpcstatus = RpcAsyncInitializeHandle( &RpcAsyncState, RPC_ASYNC_VERSION_1_0 );
  203. if ( RPC_S_OK != rpcstatus )
  204. {
  205. hr = HRESULT_FROM_WIN32( rpcstatus );
  206. __leave;
  207. }
  208. hEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); // Auto-reset, not initially signaled
  209. if( NULL == hEvent )
  210. {
  211. hr = HRESULT_FROM_WIN32( GetLastError() );
  212. __leave;
  213. }
  214. RpcAsyncState.NotificationType = RpcNotificationTypeEvent;
  215. RpcAsyncState.u.hEvent = hEvent;
  216. RpcAsyncState.UserInfo = NULL;
  217. LnkMendLink( &RpcAsyncState,
  218. hBinding,
  219. ftLimit,
  220. RestrictionsIn,
  221. pdroidBirth,
  222. pdroidLast,
  223. pmcidLast,
  224. pdroidCurrent,
  225. pmcidCurrent,
  226. pcbPath,
  227. wsz );
  228. dwWaitReturn = WaitForSingleObject( hEvent, INFINITE );
  229. if ( WAIT_OBJECT_0 != dwWaitReturn )
  230. {
  231. // There was an error of some kind.
  232. hr = HRESULT_FROM_WIN32( GetLastError() );
  233. __leave;
  234. }
  235. // Now we find out how the LnkMendLink call completed. If we get
  236. // RPC_S_OK, then it completed normally, and the result is
  237. // in hr.
  238. rpcstatus = RpcAsyncCompleteCall( &RpcAsyncState, &hr );
  239. if ( RPC_S_OK != rpcstatus )
  240. {
  241. // The call either failed or was cancelled (the reason for the
  242. // cancel would be that the UI thread called CTracker::CancelSearch,
  243. // or because we timed out above and called RpcAsyncCancelCall).
  244. hr = HRESULT_FROM_WIN32(rpcstatus);
  245. __leave;
  246. }
  247. }
  248. __except( EXCEPTION_EXECUTE_HANDLER )
  249. {
  250. hr = GetExceptionCode();
  251. }
  252. Exit:
  253. if( NULL != hEvent )
  254. {
  255. CloseHandle( hEvent );
  256. hEvent = NULL;
  257. }
  258. if( fImpersonating )
  259. {
  260. RpcRevertToSelf();
  261. }
  262. if( NULL != hBinding )
  263. {
  264. RpcBindingFree( &hBinding );
  265. hBinding = NULL;
  266. }
  267. if( NULL != pAsync_handle )
  268. {
  269. HRESULT hrT = RpcAsyncCompleteCall( pAsync_handle, &hr );
  270. }
  271. }
  272. HRESULT Stubold_LnkMendLink(
  273. /* [in] */ handle_t IDL_handle,
  274. /* [in] */ FILETIME ftLimit,
  275. /* [in] */ ULONG Restrictions,
  276. /* [in] */ const CDomainRelativeObjId __RPC_FAR *pdroidBirth,
  277. /* [in] */ const CDomainRelativeObjId __RPC_FAR *pdroidLast,
  278. /* [out] */ CDomainRelativeObjId __RPC_FAR *pdroidCurrent,
  279. /* [string][out] */ WCHAR __RPC_FAR wsz[ MAX_PATH + 1 ] )
  280. {
  281. return E_NOTIMPL;
  282. }
  283. HRESULT Stubold2_LnkSearchMachine( RPC_BINDING_HANDLE IDL_handle,
  284. ULONG RestrictionsIn,
  285. const CDomainRelativeObjId *pdroidLast,
  286. CDomainRelativeObjId *pdroidNext,
  287. CMachineId *pmcidNext,
  288. TCHAR *tsz )
  289. {
  290. return E_NOTIMPL;
  291. }
  292. HRESULT Stubold_LnkSearchMachine(
  293. /* [in] */ handle_t IDL_handle,
  294. /* [in] */ ULONG Restrictions,
  295. /* [in] */ const CDomainRelativeObjId __RPC_FAR *pdroidLast,
  296. /* [out] */ CDomainRelativeObjId __RPC_FAR *pdroidReferral,
  297. /* [string][out] */ TCHAR __RPC_FAR tsz[ MAX_PATH + 1 ])
  298. {
  299. return E_NOTIMPL;
  300. }
  301. HRESULT
  302. StubLnkGetBackup(
  303. /* [in] */ handle_t IDL_handle,
  304. /* [out][in] */ DWORD __RPC_FAR *pcVolumes,
  305. /* [size_is][size_is][out] */ VolumeMapEntry __RPC_FAR *__RPC_FAR *ppVolumeChanges,
  306. /* [out] */ FILETIME __RPC_FAR *pft)
  307. {
  308. return E_NOTIMPL;
  309. }
  310. HRESULT
  311. StubGetFileTrackingInformation( RPC_BINDING_HANDLE IDL_handle,
  312. /*[in]*/ CDomainRelativeObjId droidCurrent,
  313. /*[in]*/ TrkInfoScope scope,
  314. /*[out]*/ TRK_FILE_TRACKING_INFORMATION_PIPE pipeFileInfo )
  315. {
  316. return E_NOTIMPL;
  317. }
  318. HRESULT
  319. StubGetVolumeTrackingInformation( RPC_BINDING_HANDLE IDL_handle,
  320. /*[in]*/ CVolumeId volid,
  321. /*[in]*/ TrkInfoScope scope,
  322. /*[out]*/ TRK_VOLUME_TRACKING_INFORMATION_PIPE pipeVolInfo )
  323. {
  324. return E_NOTIMPL;
  325. }
  326. HRESULT StubLnkRestartDcSynchronization(
  327. RPC_BINDING_HANDLE IDL_handle
  328. )
  329. {
  330. return E_NOTIMPL;
  331. }
  332. HRESULT StubLnkSetVolumeId(
  333. handle_t IDL_handle,
  334. ULONG iVolume,
  335. const CVolumeId VolId)
  336. {
  337. RPC_STATUS rpcstatus;
  338. RPC_BINDING_HANDLE hBinding = NULL;
  339. HRESULT hr = E_FAIL;
  340. BOOL fImpersonating = FALSE;
  341. hr = GetBinding( s_tszTrkWksRemoteRpcProtocol,
  342. s_tszTrkWksRemoteRpcEndPoint,
  343. &hBinding );
  344. if( FAILED(hr) ) goto Exit;
  345. rpcstatus = RpcImpersonateClient( IDL_handle );
  346. if( STATUS_SUCCESS != rpcstatus )
  347. {
  348. hr = HRESULT_FROM_WIN32( rpcstatus );
  349. goto Exit;
  350. }
  351. fImpersonating = TRUE;
  352. __try
  353. {
  354. hr = LnkSetVolumeId( hBinding, iVolume, VolId );
  355. }
  356. __except( EXCEPTION_EXECUTE_HANDLER )
  357. {
  358. hr = GetExceptionCode();
  359. }
  360. Exit:
  361. if( fImpersonating )
  362. {
  363. RpcRevertToSelf();
  364. }
  365. if( NULL != hBinding )
  366. {
  367. RpcBindingFree( &hBinding );
  368. hBinding = NULL;
  369. }
  370. return hr;
  371. }
  372. HRESULT
  373. StubTriggerVolumeClaims( RPC_BINDING_HANDLE IDL_handle,
  374. /*[in]*/ ULONG cVolumes,
  375. /*[in]*/ const CVolumeId *rgvolid )
  376. {
  377. return E_NOTIMPL;
  378. }
  379. HRESULT StubLnkOnRestore(/*[in]*/ RPC_BINDING_HANDLE IDL_handle)
  380. {
  381. return E_NOTIMPL;
  382. }
  383. HRESULT Stubold_LnkCallSvrMessage(
  384. /* [in] */ handle_t IDL_handle,
  385. /* [out][in] */ TRKSVR_MESSAGE_UNION_OLD __RPC_FAR *pMsg)
  386. {
  387. return E_NOTIMPL;
  388. }