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.

433 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. if (iResult == DLG_CANCEL) {
  166. m_dwLE = ERROR_CANCELLED;
  167. }
  168. else
  169. bRet = (iResult == DLG_OK);
  170. }
  171. }
  172. else {
  173. DisplayLastError (m_hWnd, IDS_CONFIG_ERR);
  174. bRet = TRUE;
  175. }
  176. return bRet;
  177. }
  178. BOOL
  179. TConfigDlg::SetConfiguration ()
  180. {
  181. INET_CONFIGUREPORT_RESPDATA RespData;
  182. DWORD dwStatus;
  183. DWORD dwNeeded;
  184. BOOL bRet = FALSE;
  185. PBYTE pEncryptedData;
  186. DWORD dwSize;
  187. if (EncryptData ((PBYTE) &m_ConfigurationData,
  188. sizeof (INET_XCV_CONFIGURATION),
  189. (PBYTE *) &pEncryptedData,
  190. &dwSize)) {
  191. if (XcvData (m_hXcvPort,
  192. INET_XCV_SET_CONFIGURATION,
  193. pEncryptedData,
  194. dwSize,
  195. (PBYTE) &RespData,
  196. sizeof (INET_CONFIGUREPORT_RESPDATA),
  197. &dwNeeded,
  198. &dwStatus)) {
  199. if (dwStatus == ERROR_SUCCESS) {
  200. bRet = TRUE;
  201. }
  202. else
  203. SetLastError (dwStatus);
  204. }
  205. else {
  206. //
  207. // The server might be running an old version of inetpp which does not support XcvData
  208. // We need to fail the call
  209. //
  210. }
  211. LocalFree (pEncryptedData);
  212. }
  213. return bRet;
  214. }
  215. BOOL
  216. TConfigDlg::GetConfiguration ()
  217. {
  218. static CONST WCHAR cszGetConfigration[] = INET_XCV_GET_CONFIGURATION;
  219. INET_XCV_GETCONFIGURATION_REQ_DATA ReqData;
  220. DWORD dwStatus;
  221. BOOL bRet = FALSE;
  222. DWORD dwNeeded;
  223. PBYTE pEncryptedData = NULL;
  224. PBYTE pConfigData = NULL;
  225. DWORD cbConfigData;
  226. ReqData.dwVersion = 1;
  227. if (XcvData (m_hXcvPort,
  228. cszGetConfigration,
  229. (PBYTE) &ReqData,
  230. sizeof (ReqData),
  231. NULL,
  232. 0,
  233. &dwNeeded,
  234. &dwStatus)) {
  235. if (dwStatus == ERROR_INSUFFICIENT_BUFFER) {
  236. // Allocate a buffer
  237. pEncryptedData = new BYTE[dwNeeded];
  238. if (pEncryptedData) {
  239. if (XcvData (m_hXcvPort,
  240. cszGetConfigration,
  241. (PBYTE) &ReqData,
  242. sizeof (ReqData),
  243. pEncryptedData,
  244. dwNeeded,
  245. &dwNeeded,
  246. &dwStatus) && dwStatus == ERROR_SUCCESS) {
  247. //
  248. // Great! We've got the encypted configuration data
  249. //
  250. if (DecryptData (pEncryptedData, dwNeeded, &pConfigData, &cbConfigData)) {
  251. if (cbConfigData == sizeof (m_ConfigurationData)) {
  252. CopyMemory (&m_ConfigurationData, pConfigData, cbConfigData);
  253. bRet = TRUE;
  254. }
  255. else
  256. SetLastError (ERROR_INVALID_PARAMETER);
  257. LocalFree (pConfigData);
  258. }
  259. }
  260. else {
  261. SetLastError (ERROR_INVALID_PARAMETER);
  262. }
  263. delete [] pEncryptedData;
  264. }
  265. }
  266. else
  267. SetLastError (dwStatus);
  268. }
  269. else
  270. //
  271. // The server might be running an old version of inetpp which does not support XcvData
  272. // We need to fail the call
  273. //
  274. SetLastError (ERROR_NOT_SUPPORTED);
  275. return bRet;
  276. }
  277. VOID
  278. TConfigDlg::AuthDialogOnInit (HWND hDlg)
  279. {
  280. SetDlgItemText (hDlg, IDC_PORT_NAME, (LPTSTR) m_pszPortName);
  281. SetWindowLongPtr (hDlg, GWLP_USERDATA, (UINT_PTR) this);
  282. }
  283. VOID
  284. TConfigDlg::AuthDialogOnOK (HWND hDlg)
  285. {
  286. m_ConfigurationData.dwAuthMethod = AUTH_OTHER;
  287. GetDlgItemText (hDlg, IDC_USER_NAME, m_ConfigurationData.szUserName, MAX_USERNAME_LEN);
  288. if (SendMessage (GetDlgItem (hDlg, IDC_PASSWORD), EM_GETMODIFY, 0, 0)) {
  289. m_ConfigurationData.bPasswordChanged = TRUE;
  290. GetDlgItemText (hDlg, IDC_PASSWORD, m_ConfigurationData.szPassword , MAX_PASSWORD_LEN);
  291. }
  292. DBGMSG (DBG_TRACE, ("Call: TConfigDlg::DialogOnOK (%d, User:%ws Password:%ws)\n",
  293. m_ConfigurationData.dwAuthMethod,
  294. m_ConfigurationData.szUserName,
  295. m_ConfigurationData.szPassword));
  296. if (SetConfiguration ()) {
  297. EndDialog (hDlg, DLG_OK);
  298. }
  299. else {
  300. DisplayLastError (m_hWnd, IDS_AUTH_ERROR);
  301. }
  302. }
  303. VOID
  304. TConfigDlg::AuthDialogOnCancel (HWND hDlg)
  305. {
  306. SetLastError (ERROR_ACCESS_DENIED);
  307. EndDialog (hDlg, DLG_CANCEL);
  308. }
  309. INT_PTR CALLBACK
  310. TConfigDlg::AuthDialogProc(
  311. HWND hDlg, // handle to dialog box
  312. UINT message, // message
  313. WPARAM wParam, // first message parameter
  314. LPARAM lParam // second message parameter
  315. )
  316. {
  317. TConfigDlg *pAuthInfo = NULL;
  318. switch (message) {
  319. case WM_INITDIALOG:
  320. if (pAuthInfo = (TConfigDlg *)lParam)
  321. pAuthInfo->AuthDialogOnInit(hDlg);
  322. return TRUE;
  323. case WM_COMMAND:
  324. switch (wParam) {
  325. case IDOK:
  326. if (pAuthInfo = (TConfigDlg *) GetWindowLongPtr (hDlg, GWLP_USERDATA))
  327. pAuthInfo->AuthDialogOnOK (hDlg);
  328. return TRUE;
  329. case IDCANCEL:
  330. if (pAuthInfo = (TConfigDlg *) GetWindowLongPtr (hDlg, GWLP_USERDATA))
  331. pAuthInfo->AuthDialogOnCancel (hDlg);
  332. return TRUE;
  333. default:
  334. break;
  335. }
  336. break;
  337. default:
  338. break;
  339. }
  340. return FALSE;
  341. }