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.

595 lines
20 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1997
  4. *
  5. * TITLE: Select.Cpp
  6. *
  7. * VERSION: 2.0
  8. *
  9. * AUTHOR: ReedB
  10. *
  11. * DATE: 11 Feb, 1998
  12. *
  13. * DESCRIPTION:
  14. * Implements device selection UI of the WIA device manager.
  15. * These methods execute only on the client side.
  16. *
  17. *******************************************************************************/
  18. #include <windows.h>
  19. #include <wia.h>
  20. #include <waitcurs.h>
  21. #include "wiadevdp.h"
  22. /*******************************************************************************
  23. *
  24. * CallSelectDeviceDlg
  25. *
  26. * DESCRIPTION:
  27. * Wrapper for dynamically loaded select device dll procedure
  28. *
  29. * PARAMETERS:
  30. *
  31. *******************************************************************************/
  32. HRESULT _stdcall CallSelectDeviceDlg(
  33. IWiaDevMgr __RPC_FAR * This,
  34. HWND hwndParent,
  35. LONG lDeviceType,
  36. LONG lFlags,
  37. BSTR *pbstrDeviceID,
  38. IWiaItem **ppWiaItemRoot)
  39. {
  40. IWiaGetImageDlg *pWiaGetImageDlg = NULL;
  41. HRESULT hr = CoCreateInstance( CLSID_WiaDefaultUi, NULL, CLSCTX_INPROC_SERVER, IID_IWiaGetImageDlg, (void**)&pWiaGetImageDlg );
  42. if (SUCCEEDED(hr) && pWiaGetImageDlg)
  43. {
  44. hr = pWiaGetImageDlg->SelectDeviceDlg( hwndParent, NULL, lDeviceType, lFlags, pbstrDeviceID, ppWiaItemRoot );
  45. pWiaGetImageDlg->Release();
  46. }
  47. return hr;
  48. }
  49. /*******************************************************************************
  50. *
  51. * IWiaDevMgr_SelectDeviceDlg_Proxy
  52. *
  53. * DESCRIPTION:
  54. * Present UI to select then create an WIA device.
  55. *
  56. * PARAMETERS:
  57. *
  58. *******************************************************************************/
  59. HRESULT _stdcall IWiaDevMgr_SelectDeviceDlg_Proxy(
  60. IWiaDevMgr __RPC_FAR * This,
  61. HWND hwndParent,
  62. LONG lDeviceType,
  63. LONG lFlags,
  64. BSTR *pbstrDeviceID,
  65. IWiaItem **ppWiaItemRoot)
  66. {
  67. CWaitCursor wc; // Put up a wait cursor.
  68. if (!ppWiaItemRoot)
  69. {
  70. return E_POINTER;
  71. }
  72. *ppWiaItemRoot = NULL;
  73. if (pbstrDeviceID)
  74. {
  75. *pbstrDeviceID = 0;
  76. }
  77. return CallSelectDeviceDlg( This, hwndParent, lDeviceType, lFlags, pbstrDeviceID, ppWiaItemRoot );
  78. }
  79. /*******************************************************************************
  80. *
  81. * IWiaDevMgr_SelectDeviceDlg_Stub
  82. *
  83. * DESCRIPTION:
  84. * Never called.
  85. *
  86. * PARAMETERS:
  87. *
  88. *******************************************************************************/
  89. HRESULT _stdcall IWiaDevMgr_SelectDeviceDlg_Stub(
  90. IWiaDevMgr __RPC_FAR * This,
  91. HWND hwndParent,
  92. LONG lDeviceType,
  93. LONG lFlags,
  94. BSTR *pbstrDeviceID,
  95. IWiaItem **ppWiaItemRoot)
  96. {
  97. return S_OK;
  98. }
  99. /*******************************************************************************
  100. *
  101. * IWiaDevMgr_SelectDeviceDlgID_Proxy
  102. *
  103. * DESCRIPTION:
  104. * Present UI to select and return the device ID
  105. *
  106. * PARAMETERS:
  107. *
  108. *******************************************************************************/
  109. HRESULT _stdcall IWiaDevMgr_SelectDeviceDlgID_Proxy(
  110. IWiaDevMgr __RPC_FAR * This,
  111. HWND hwndParent,
  112. LONG lDeviceType,
  113. LONG lFlags,
  114. BSTR *pbstrDeviceID )
  115. {
  116. CWaitCursor wc; // Put up a wait cursor.
  117. if (!pbstrDeviceID)
  118. {
  119. return E_POINTER;
  120. }
  121. *pbstrDeviceID = 0;
  122. return CallSelectDeviceDlg( This, hwndParent, lDeviceType, lFlags, pbstrDeviceID, NULL );
  123. }
  124. /*******************************************************************************
  125. *
  126. * IWiaDevMgr_SelectDeviceDlgID_Stub
  127. *
  128. * DESCRIPTION:
  129. * Never called.
  130. *
  131. * PARAMETERS:
  132. *
  133. *******************************************************************************/
  134. HRESULT _stdcall IWiaDevMgr_SelectDeviceDlgID_Stub(
  135. IWiaDevMgr __RPC_FAR * This,
  136. HWND hwndParent,
  137. LONG lDeviceType,
  138. LONG lFlags,
  139. BSTR *pbstr )
  140. {
  141. return S_OK;
  142. }
  143. /*******************************************************************************
  144. *
  145. * IWiaDevMgr_CreateDevice_Proxy
  146. *
  147. * DESCRIPTION:
  148. * Proxy code to adjust COM security before calling into STISVC.
  149. *
  150. * PARAMETERS:
  151. * Same as IWiaDevMgr::CreateDevice()
  152. *
  153. *******************************************************************************/
  154. HRESULT _stdcall IWiaDevMgr_CreateDevice_Proxy(
  155. IWiaDevMgr __RPC_FAR *This,
  156. BSTR bstrDeviceID,
  157. IWiaItem **ppWiaItemRoot)
  158. {
  159. HRESULT hr;
  160. IClientSecurity *pcs;
  161. DWORD dwAuthnSvc, dwAuthzSvc, dwAuthnLevel, dwImpLevel, dwCaps;
  162. OLECHAR *pServerPrincName = NULL;
  163. RPC_AUTH_IDENTITY_HANDLE AuthInfo;
  164. hr = This->QueryInterface(IID_IClientSecurity,
  165. (void **) &pcs);
  166. if(SUCCEEDED(hr)) {
  167. hr = pcs->QueryBlanket(This,
  168. &dwAuthnSvc,
  169. &dwAuthzSvc,
  170. &pServerPrincName,
  171. &dwAuthnLevel,
  172. &dwImpLevel,
  173. &AuthInfo,
  174. &dwCaps);
  175. }
  176. if(SUCCEEDED(hr)) {
  177. hr = pcs->SetBlanket(This,
  178. dwAuthnSvc,
  179. dwAuthzSvc,
  180. pServerPrincName,
  181. dwAuthnLevel,
  182. RPC_C_IMP_LEVEL_IMPERSONATE,
  183. AuthInfo,
  184. dwCaps);
  185. }
  186. if (pServerPrincName) {
  187. CoTaskMemFree(pServerPrincName);
  188. pServerPrincName = NULL;
  189. }
  190. if(SUCCEEDED(hr)) {
  191. hr = IWiaDevMgr_LocalCreateDevice_Proxy(This,
  192. bstrDeviceID,
  193. ppWiaItemRoot);
  194. }
  195. if(pcs) pcs->Release();
  196. return hr;
  197. }
  198. /*******************************************************************************
  199. *
  200. * IWiaDevMgr_CreateDevice_Stub
  201. *
  202. *******************************************************************************/
  203. HRESULT _stdcall IWiaDevMgr_CreateDevice_Stub(
  204. IWiaDevMgr __RPC_FAR *This,
  205. BSTR bstrDeviceID,
  206. IWiaItem **ppWiaItemRoot)
  207. {
  208. return This->CreateDevice(bstrDeviceID, ppWiaItemRoot);
  209. }
  210. /*******************************************************************************
  211. *
  212. * IWiaDevMgr_RegisterEventCallbackProgram_Proxy
  213. *
  214. * DESCRIPTION:
  215. * Proxy code to adjust COM security before calling into STISVC. This is so we
  216. * can impersonate client todo security check on server side.
  217. *
  218. * PARAMETERS:
  219. * Same as IWiaDevMgr::RegisterEventCallbackProgram()
  220. *
  221. *******************************************************************************/
  222. HRESULT _stdcall IWiaDevMgr_RegisterEventCallbackProgram_Proxy(
  223. IWiaDevMgr __RPC_FAR *This,
  224. LONG lFlags,
  225. BSTR bstrDeviceID,
  226. const GUID *pEventGUID,
  227. BSTR bstrCommandline,
  228. BSTR bstrName,
  229. BSTR bstrDescription,
  230. BSTR bstrIcon)
  231. {
  232. HRESULT hr;
  233. IClientSecurity *pcs;
  234. DWORD dwAuthnSvc, dwAuthzSvc, dwAuthnLevel, dwImpLevel, dwCaps;
  235. OLECHAR *pServerPrincName = NULL;
  236. RPC_AUTH_IDENTITY_HANDLE AuthInfo;
  237. hr = This->QueryInterface(IID_IClientSecurity,
  238. (void **) &pcs);
  239. if(SUCCEEDED(hr)) {
  240. hr = pcs->QueryBlanket(This,
  241. &dwAuthnSvc,
  242. &dwAuthzSvc,
  243. &pServerPrincName,
  244. &dwAuthnLevel,
  245. &dwImpLevel,
  246. &AuthInfo,
  247. &dwCaps);
  248. }
  249. if(SUCCEEDED(hr)) {
  250. hr = pcs->SetBlanket(This,
  251. dwAuthnSvc,
  252. dwAuthzSvc,
  253. pServerPrincName,
  254. dwAuthnLevel,
  255. RPC_C_IMP_LEVEL_IMPERSONATE,
  256. AuthInfo,
  257. dwCaps);
  258. }
  259. if (pServerPrincName) {
  260. CoTaskMemFree(pServerPrincName);
  261. pServerPrincName = NULL;
  262. }
  263. if(SUCCEEDED(hr)) {
  264. hr = IWiaDevMgr_LocalRegisterEventCallbackProgram_Proxy(This,
  265. lFlags,
  266. bstrDeviceID,
  267. pEventGUID,
  268. bstrCommandline,
  269. bstrName,
  270. bstrDescription,
  271. bstrIcon);
  272. }
  273. if(pcs) pcs->Release();
  274. return hr;
  275. }
  276. /*******************************************************************************
  277. *
  278. * IWiaDevMgr_RegisterEventCallbackProgram_Stub
  279. *
  280. *******************************************************************************/
  281. HRESULT _stdcall IWiaDevMgr_RegisterEventCallbackProgram_Stub(
  282. IWiaDevMgr __RPC_FAR *This,
  283. LONG lFlags,
  284. BSTR bstrDeviceID,
  285. const GUID *pEventGUID,
  286. BSTR bstrCommandline,
  287. BSTR bstrName,
  288. BSTR bstrDescription,
  289. BSTR bstrIcon)
  290. {
  291. return This->RegisterEventCallbackProgram(lFlags,
  292. bstrDeviceID,
  293. pEventGUID,
  294. bstrCommandline,
  295. bstrName,
  296. bstrDescription,
  297. bstrIcon);
  298. }
  299. /*******************************************************************************
  300. *
  301. * IWiaDevMgr_RegisterEventCallbackCLSID_Proxy
  302. *
  303. * DESCRIPTION:
  304. * Proxy code to adjust COM security before calling into STISVC. This is so we
  305. * can impersonate client todo security check on server side.
  306. *
  307. * PARAMETERS:
  308. * Same as IWiaDevMgr::RegisterEventCallbackCLSID()
  309. *
  310. *******************************************************************************/
  311. HRESULT _stdcall IWiaDevMgr_RegisterEventCallbackCLSID_Proxy(
  312. IWiaDevMgr __RPC_FAR *This,
  313. LONG lFlags,
  314. BSTR bstrDeviceID,
  315. const GUID *pEventGUID,
  316. const GUID *pClsID,
  317. BSTR bstrName,
  318. BSTR bstrDescription,
  319. BSTR bstrIcon)
  320. {
  321. HRESULT hr;
  322. IClientSecurity *pcs;
  323. DWORD dwAuthnSvc, dwAuthzSvc, dwAuthnLevel, dwImpLevel, dwCaps;
  324. OLECHAR *pServerPrincName = NULL;
  325. RPC_AUTH_IDENTITY_HANDLE AuthInfo;
  326. hr = This->QueryInterface(IID_IClientSecurity,
  327. (void **) &pcs);
  328. if(SUCCEEDED(hr)) {
  329. hr = pcs->QueryBlanket(This,
  330. &dwAuthnSvc,
  331. &dwAuthzSvc,
  332. &pServerPrincName,
  333. &dwAuthnLevel,
  334. &dwImpLevel,
  335. &AuthInfo,
  336. &dwCaps);
  337. }
  338. if(SUCCEEDED(hr)) {
  339. hr = pcs->SetBlanket(This,
  340. dwAuthnSvc,
  341. dwAuthzSvc,
  342. pServerPrincName,
  343. dwAuthnLevel,
  344. RPC_C_IMP_LEVEL_IMPERSONATE,
  345. AuthInfo,
  346. dwCaps);
  347. }
  348. if (pServerPrincName) {
  349. CoTaskMemFree(pServerPrincName);
  350. pServerPrincName = NULL;
  351. }
  352. if(SUCCEEDED(hr)) {
  353. hr = IWiaDevMgr_LocalRegisterEventCallbackCLSID_Proxy(This,
  354. lFlags,
  355. bstrDeviceID,
  356. pEventGUID,
  357. pClsID,
  358. bstrName,
  359. bstrDescription,
  360. bstrIcon);
  361. }
  362. if(pcs) pcs->Release();
  363. return hr;
  364. }
  365. /*******************************************************************************
  366. *
  367. * IWiaDevMgr_LocalRegisterEventCallbackCLSID_Stub
  368. *
  369. *******************************************************************************/
  370. HRESULT _stdcall IWiaDevMgr_RegisterEventCallbackCLSID_Stub(
  371. IWiaDevMgr __RPC_FAR *This,
  372. LONG lFlags,
  373. BSTR bstrDeviceID,
  374. const GUID *pEventGUID,
  375. const GUID *pClsID,
  376. BSTR bstrName,
  377. BSTR bstrDescription,
  378. BSTR bstrIcon)
  379. {
  380. return This->RegisterEventCallbackCLSID(lFlags,
  381. bstrDeviceID,
  382. pEventGUID,
  383. pClsID,
  384. bstrName,
  385. bstrDescription,
  386. bstrIcon);
  387. }
  388. /*******************************************************************************
  389. *
  390. * IWiaPropertyStorage_WriteMultiple_Proxy
  391. *
  392. * DESCRIPTION:
  393. * Proxy code to adjust COM security before calling into STISVC. This is so we
  394. * can impersonate client todo security check on server side.
  395. *
  396. * PARAMETERS:
  397. * Same as IWiaPropertyStorage::WriteMultiple()
  398. *
  399. *******************************************************************************/
  400. HRESULT IWiaPropertyStorage_WriteMultiple_Proxy(
  401. IWiaPropertyStorage __RPC_FAR *This,
  402. ULONG cpspec,
  403. const PROPSPEC rgpspec[],
  404. const PROPVARIANT rgpropvar[],
  405. PROPID propidNameFirst)
  406. {
  407. HRESULT hr;
  408. IClientSecurity *pcs;
  409. DWORD dwAuthnSvc, dwAuthzSvc, dwAuthnLevel, dwImpLevel, dwCaps;
  410. OLECHAR *pServerPrincName = NULL;
  411. RPC_AUTH_IDENTITY_HANDLE AuthInfo;
  412. hr = This->QueryInterface(IID_IClientSecurity,
  413. (void **) &pcs);
  414. if(SUCCEEDED(hr)) {
  415. hr = pcs->QueryBlanket(This,
  416. &dwAuthnSvc,
  417. &dwAuthzSvc,
  418. &pServerPrincName,
  419. &dwAuthnLevel,
  420. &dwImpLevel,
  421. &AuthInfo,
  422. &dwCaps);
  423. }
  424. if(SUCCEEDED(hr)) {
  425. hr = pcs->SetBlanket(This,
  426. dwAuthnSvc,
  427. dwAuthzSvc,
  428. pServerPrincName,
  429. dwAuthnLevel,
  430. RPC_C_IMP_LEVEL_IMPERSONATE,
  431. AuthInfo,
  432. dwCaps);
  433. }
  434. if (pServerPrincName) {
  435. CoTaskMemFree(pServerPrincName);
  436. pServerPrincName = NULL;
  437. }
  438. if(SUCCEEDED(hr)) {
  439. hr = IWiaPropertyStorage_RemoteWriteMultiple_Proxy(This,
  440. cpspec,
  441. rgpspec,
  442. rgpropvar,
  443. propidNameFirst);
  444. }
  445. if(pcs) pcs->Release();
  446. return hr;
  447. }
  448. /*******************************************************************************
  449. *
  450. * IWiaPropertyStorage_WriteMultiple_Stub
  451. *
  452. *******************************************************************************/
  453. HRESULT IWiaPropertyStorage_WriteMultiple_Stub(
  454. IWiaPropertyStorage __RPC_FAR *This,
  455. ULONG cpspec,
  456. const PROPSPEC rgpspec[],
  457. const PROPVARIANT rgpropvar[],
  458. PROPID propidNameFirst)
  459. {
  460. return This->WriteMultiple(cpspec,
  461. rgpspec,
  462. rgpropvar,
  463. propidNameFirst);
  464. }
  465. /*******************************************************************************
  466. *
  467. * IWiaPropertyStorage_SetPropertyStream_Proxy
  468. *
  469. * DESCRIPTION:
  470. * Proxy code to adjust COM security before calling into STISVC. This is so we
  471. * can impersonate client todo security check on server side.
  472. *
  473. * PARAMETERS:
  474. * Same as IWiaPropertyStorage::SetPropertyStream()
  475. *
  476. *******************************************************************************/
  477. HRESULT IWiaPropertyStorage_SetPropertyStream_Proxy(
  478. IWiaPropertyStorage __RPC_FAR *This,
  479. GUID *pCompatibilityId,
  480. IStream *pIStream)
  481. {
  482. HRESULT hr;
  483. IClientSecurity *pcs;
  484. DWORD dwAuthnSvc, dwAuthzSvc, dwAuthnLevel, dwImpLevel, dwCaps;
  485. OLECHAR *pServerPrincName = NULL;
  486. RPC_AUTH_IDENTITY_HANDLE AuthInfo;
  487. hr = This->QueryInterface(IID_IClientSecurity,
  488. (void **) &pcs);
  489. if(SUCCEEDED(hr)) {
  490. hr = pcs->QueryBlanket(This,
  491. &dwAuthnSvc,
  492. &dwAuthzSvc,
  493. &pServerPrincName,
  494. &dwAuthnLevel,
  495. &dwImpLevel,
  496. &AuthInfo,
  497. &dwCaps);
  498. }
  499. if(SUCCEEDED(hr)) {
  500. hr = pcs->SetBlanket(This,
  501. dwAuthnSvc,
  502. dwAuthzSvc,
  503. pServerPrincName,
  504. dwAuthnLevel,
  505. RPC_C_IMP_LEVEL_IMPERSONATE,
  506. AuthInfo,
  507. dwCaps);
  508. }
  509. if (pServerPrincName) {
  510. CoTaskMemFree(pServerPrincName);
  511. pServerPrincName = NULL;
  512. }
  513. if(SUCCEEDED(hr)) {
  514. hr = IWiaPropertyStorage_RemoteSetPropertyStream_Proxy(This,
  515. pCompatibilityId,
  516. pIStream);
  517. }
  518. if(pcs) pcs->Release();
  519. return hr;
  520. }
  521. /*******************************************************************************
  522. *
  523. * IWiaPropertyStorage_SetPropertyStream_Stub
  524. *
  525. *******************************************************************************/
  526. HRESULT IWiaPropertyStorage_SetPropertyStream_Stub(
  527. IWiaPropertyStorage __RPC_FAR *This,
  528. GUID *pCompatibilityId,
  529. IStream *pIStream)
  530. {
  531. return This->SetPropertyStream(pCompatibilityId,
  532. pIStream);
  533. }