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.

430 lines
11 KiB

  1. /*****************************************************************************\
  2. * MODULE: configdlg.cxx
  3. *
  4. * The module contains routines for handling the authentication dialog
  5. * for internet priting
  6. *
  7. * Copyright (C) 1996-1998 Microsoft Corporation
  8. *
  9. * History:
  10. * 07/31/98 WeihaiC Created
  11. * 04/10/00 WeihaiC Moved it to client side
  12. *
  13. \*****************************************************************************/
  14. #include "precomp.h"
  15. #include "priv.h"
  16. TConfigDlg::TConfigDlg (
  17. LPCWSTR pServerName,
  18. HWND hWnd,
  19. LPCWSTR pszPortName):
  20. TXcvDlg (pServerName, hWnd, pszPortName)
  21. {
  22. }
  23. TConfigDlg::~TConfigDlg ()
  24. {
  25. }
  26. VOID
  27. TConfigDlg::EnableUserNamePassword (
  28. HWND hDlg,
  29. BOOL bEnable)
  30. {
  31. EnableWindow( GetDlgItem( hDlg, IDC_USER_NAME ), bEnable );
  32. EnableWindow( GetDlgItem( hDlg, IDC_PASSWORD ), bEnable );
  33. }
  34. VOID
  35. TConfigDlg::DialogOnInit (
  36. HWND hDlg)
  37. {
  38. int nIDButton;
  39. SetDlgItemText (hDlg, IDC_PORT_NAME, (LPTSTR) m_pszPortName);
  40. switch (m_ConfigurationData.dwAuthMethod) {
  41. case AUTH_NT:
  42. nIDButton = IDC_IMPERSONATION;
  43. break;
  44. case AUTH_OTHER:
  45. nIDButton = IDC_SPECFIEDUSER;
  46. break;
  47. case AUTH_ANONYMOUS:
  48. nIDButton = IDC_ANONYMOUS;
  49. break;
  50. }
  51. CheckDlgButton (hDlg, nIDButton, BST_CHECKED);
  52. EnableUserNamePassword (hDlg, m_ConfigurationData.dwAuthMethod == AUTH_OTHER);
  53. if (m_ConfigurationData.szUserName[0]) {
  54. SetDlgItemText (hDlg, IDC_USER_NAME, (LPTSTR) m_ConfigurationData.szUserName);
  55. SetDlgItemText (hDlg, IDC_PASSWORD, (LPTSTR) TEXT ("***********"));
  56. }
  57. SetWindowLongPtr (hDlg, GWLP_USERDATA, (UINT_PTR) this);
  58. // Disable all user settings for non admins
  59. EnableWindow( GetDlgItem( hDlg, IDC_CHECK_ALL_USER ), m_bAdmin );
  60. }
  61. VOID
  62. TConfigDlg::DialogOnOK (
  63. HWND hDlg)
  64. {
  65. WCHAR szBuffer [MAX_USERNAME_LEN];
  66. DWORD dwRet = DLG_ERROR;
  67. BOOL bChecked;
  68. if (IsDlgButtonChecked (hDlg, IDC_ANONYMOUS)) {
  69. m_ConfigurationData.dwAuthMethod = AUTH_ANONYMOUS;
  70. }
  71. else if (IsDlgButtonChecked (hDlg, IDC_SPECFIEDUSER)) {
  72. m_ConfigurationData.dwAuthMethod = AUTH_OTHER;
  73. }
  74. else
  75. m_ConfigurationData.dwAuthMethod = AUTH_NT;
  76. if (m_ConfigurationData.dwAuthMethod == AUTH_OTHER) {
  77. GetDlgItemText (hDlg, IDC_USER_NAME, m_ConfigurationData.szUserName, MAX_USERNAME_LEN);
  78. if (SendMessage (GetDlgItem (hDlg, IDC_PASSWORD), EM_GETMODIFY, 0, 0)) {
  79. m_ConfigurationData.bPasswordChanged = TRUE;
  80. GetDlgItemText (hDlg, IDC_PASSWORD, m_ConfigurationData.szPassword , MAX_PASSWORD_LEN);
  81. }
  82. }
  83. if (m_bAdmin && IsDlgButtonChecked (hDlg,IDC_CHECK_ALL_USER ))
  84. m_ConfigurationData.bSettingForAll = TRUE;
  85. else
  86. m_ConfigurationData.bSettingForAll = FALSE;
  87. dwRet = DLG_OK;
  88. DBGMSG (DBG_TRACE, ("Call: TConfigDlg::DialogOnOK (%d, User:%ws Password:%ws)\n",
  89. m_ConfigurationData.dwAuthMethod,
  90. m_ConfigurationData.szUserName,
  91. m_ConfigurationData.szPassword));
  92. if (!SetConfiguration ()) {
  93. DisplayLastError (m_hWnd, IDS_CONFIG_ERR);
  94. }
  95. else
  96. EndDialog (hDlg, dwRet);
  97. }
  98. INT_PTR CALLBACK
  99. TConfigDlg::DialogProc(
  100. HWND hDlg, // handle to dialog box
  101. UINT message, // message
  102. WPARAM wParam, // first message parameter
  103. LPARAM lParam // second message parameter
  104. )
  105. {
  106. BOOL bRet = FALSE;
  107. TConfigDlg *pConfigInfo = NULL;
  108. switch (message) {
  109. case WM_INITDIALOG:
  110. if (pConfigInfo = (TConfigDlg *)lParam)
  111. pConfigInfo->DialogOnInit(hDlg);
  112. bRet = TRUE;
  113. break;
  114. case WM_COMMAND:
  115. switch (wParam) {
  116. case IDOK:
  117. if (pConfigInfo = (TConfigDlg *) GetWindowLongPtr (hDlg, GWLP_USERDATA))
  118. pConfigInfo->DialogOnOK (hDlg);
  119. bRet = TRUE;
  120. break;
  121. case IDCANCEL:
  122. EndDialog (hDlg, DLG_CANCEL);
  123. bRet = TRUE;
  124. break;
  125. case IDC_IMPERSONATION:
  126. case IDC_ANONYMOUS:
  127. EnableUserNamePassword (hDlg, FALSE);
  128. bRet = TRUE;
  129. break;
  130. case IDC_SPECFIEDUSER:
  131. EnableUserNamePassword (hDlg, TRUE);
  132. bRet = TRUE;
  133. break;
  134. }
  135. break;
  136. }
  137. return bRet;
  138. }
  139. BOOL
  140. TConfigDlg::PromptDialog (
  141. HINSTANCE hInst)
  142. {
  143. INT_PTR iResult;
  144. BOOL bRet = FALSE;;
  145. m_hInst = hInst;
  146. if (GetConfiguration ()) {
  147. if (m_ConfigurationData.dwAuthMethod == AUTH_ACCESS_DENIED) {
  148. iResult = DialogBoxParam( hInst,
  149. TEXT("AuthDlg"),
  150. m_hWnd,
  151. TConfigDlg::AuthDialogProc,
  152. (LPARAM) this );
  153. if (iResult == DLG_CANCEL) {
  154. m_dwLE = ERROR_ACCESS_DENIED;
  155. }
  156. else
  157. bRet = iResult == DLG_OK;
  158. }
  159. else {
  160. iResult = DialogBoxParam( hInst,
  161. TEXT("IDD_CONFIGURE_DLG"),
  162. m_hWnd,
  163. TConfigDlg::DialogProc,
  164. (LPARAM) this );
  165. bRet = (iResult == DLG_OK || iResult == DLG_CANCEL);
  166. }
  167. }
  168. else {
  169. DisplayLastError (m_hWnd, IDS_CONFIG_ERR);
  170. bRet = TRUE;
  171. }
  172. return bRet;
  173. }
  174. BOOL
  175. TConfigDlg::SetConfiguration ()
  176. {
  177. static CONST WCHAR cszSetConfiguration[] = INET_XCV_SET_CONFIGURATION;
  178. INET_CONFIGUREPORT_RESPDATA RespData;
  179. DWORD dwStatus;
  180. DWORD dwNeeded;
  181. BOOL bRet = FALSE;
  182. PBYTE pEncryptedData;
  183. DWORD dwSize;
  184. if (EncryptData ((PBYTE) &m_ConfigurationData,
  185. sizeof (INET_XCV_CONFIGURATION),
  186. (PBYTE *) &pEncryptedData,
  187. &dwSize)) {
  188. if (XcvData (m_hXcvPort,
  189. cszSetConfiguration,
  190. pEncryptedData,
  191. dwSize,
  192. (PBYTE) &RespData,
  193. sizeof (INET_CONFIGUREPORT_RESPDATA),
  194. &dwNeeded,
  195. &dwStatus)) {
  196. if (dwStatus == ERROR_SUCCESS) {
  197. bRet = TRUE;
  198. }
  199. else
  200. SetLastError (dwStatus);
  201. }
  202. else {
  203. //
  204. // The server might be running an old version of inetpp which does not support XcvData
  205. // We need to fail the call
  206. //
  207. }
  208. LocalFree (pEncryptedData);
  209. }
  210. return bRet;
  211. }
  212. BOOL
  213. TConfigDlg::GetConfiguration ()
  214. {
  215. static CONST WCHAR cszGetConfigration[] = INET_XCV_GET_CONFIGURATION;
  216. INET_XCV_GETCONFIGURATION_REQ_DATA ReqData;
  217. DWORD dwStatus;
  218. BOOL bRet = FALSE;
  219. DWORD dwNeeded;
  220. PBYTE pEncryptedData = NULL;
  221. PBYTE pConfigData = NULL;
  222. DWORD cbConfigData;
  223. ReqData.dwVersion = 1;
  224. if (XcvData (m_hXcvPort,
  225. cszGetConfigration,
  226. (PBYTE) &ReqData,
  227. sizeof (ReqData),
  228. NULL,
  229. 0,
  230. &dwNeeded,
  231. &dwStatus)) {
  232. if (dwStatus == ERROR_INSUFFICIENT_BUFFER) {
  233. // Allocate a buffer
  234. pEncryptedData = new BYTE[dwNeeded];
  235. if (pEncryptedData) {
  236. if (XcvData (m_hXcvPort,
  237. cszGetConfigration,
  238. (PBYTE) &ReqData,
  239. sizeof (ReqData),
  240. pEncryptedData,
  241. dwNeeded,
  242. &dwNeeded,
  243. &dwStatus) && dwStatus == ERROR_SUCCESS) {
  244. //
  245. // Great! We've got the encypted configuration data
  246. //
  247. if (DecryptData (pEncryptedData, dwNeeded, &pConfigData, &cbConfigData)) {
  248. if (cbConfigData == sizeof (m_ConfigurationData)) {
  249. CopyMemory (&m_ConfigurationData, pConfigData, cbConfigData);
  250. bRet = TRUE;
  251. }
  252. else
  253. SetLastError (ERROR_INVALID_PARAMETER);
  254. LocalFree (pConfigData);
  255. }
  256. }
  257. else {
  258. SetLastError (ERROR_INVALID_PARAMETER);
  259. }
  260. delete [] pEncryptedData;
  261. }
  262. }
  263. else
  264. SetLastError (dwStatus);
  265. }
  266. else
  267. //
  268. // The server might be running an old version of inetpp which does not support XcvData
  269. // We need to fail the call
  270. //
  271. SetLastError (ERROR_NOT_SUPPORTED);
  272. return bRet;
  273. }
  274. VOID
  275. TConfigDlg::AuthDialogOnInit (HWND hDlg)
  276. {
  277. SetDlgItemText (hDlg, IDC_PORT_NAME, (LPTSTR) m_pszPortName);
  278. SetWindowLongPtr (hDlg, GWLP_USERDATA, (UINT_PTR) this);
  279. }
  280. VOID
  281. TConfigDlg::AuthDialogOnOK (HWND hDlg)
  282. {
  283. m_ConfigurationData.dwAuthMethod = AUTH_OTHER;
  284. GetDlgItemText (hDlg, IDC_USER_NAME, m_ConfigurationData.szUserName, MAX_USERNAME_LEN);
  285. if (SendMessage (GetDlgItem (hDlg, IDC_PASSWORD), EM_GETMODIFY, 0, 0)) {
  286. m_ConfigurationData.bPasswordChanged = TRUE;
  287. GetDlgItemText (hDlg, IDC_PASSWORD, m_ConfigurationData.szPassword , MAX_PASSWORD_LEN);
  288. }
  289. DBGMSG (DBG_TRACE, ("Call: TConfigDlg::DialogOnOK (%d, User:%ws Password:%ws)\n",
  290. m_ConfigurationData.dwAuthMethod,
  291. m_ConfigurationData.szUserName,
  292. m_ConfigurationData.szPassword));
  293. if (SetConfiguration ()) {
  294. EndDialog (hDlg, DLG_OK);
  295. }
  296. else {
  297. DisplayLastError (m_hWnd, IDS_AUTH_ERROR);
  298. }
  299. }
  300. VOID
  301. TConfigDlg::AuthDialogOnCancel (HWND hDlg)
  302. {
  303. SetLastError (ERROR_ACCESS_DENIED);
  304. EndDialog (hDlg, DLG_CANCEL);
  305. }
  306. INT_PTR CALLBACK
  307. TConfigDlg::AuthDialogProc(
  308. HWND hDlg, // handle to dialog box
  309. UINT message, // message
  310. WPARAM wParam, // first message parameter
  311. LPARAM lParam // second message parameter
  312. )
  313. {
  314. TConfigDlg *pAuthInfo = NULL;
  315. switch (message) {
  316. case WM_INITDIALOG:
  317. if (pAuthInfo = (TConfigDlg *)lParam)
  318. pAuthInfo->AuthDialogOnInit(hDlg);
  319. return TRUE;
  320. case WM_COMMAND:
  321. switch (wParam) {
  322. case IDOK:
  323. if (pAuthInfo = (TConfigDlg *) GetWindowLongPtr (hDlg, GWLP_USERDATA))
  324. pAuthInfo->AuthDialogOnOK (hDlg);
  325. return TRUE;
  326. case IDCANCEL:
  327. if (pAuthInfo = (TConfigDlg *) GetWindowLongPtr (hDlg, GWLP_USERDATA))
  328. pAuthInfo->AuthDialogOnCancel (hDlg);
  329. return TRUE;
  330. default:
  331. break;
  332. }
  333. break;
  334. default:
  335. break;
  336. }
  337. return FALSE;
  338. }