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.

891 lines
30 KiB

  1. /**********************************************************************************
  2. *
  3. *
  4. * UI_DPROP.C - contains functions for the Directory Service Property dialog
  5. *
  6. *
  7. *
  8. **********************************************************************************/
  9. #include "_apipch.h"
  10. #ifdef OLD_LDAP_UI
  11. extern HINSTANCE ghCommCtrlDLLInst;
  12. extern LPPROPERTYSHEET gpfnPropertySheet;
  13. // Params passed to dialog box
  14. typedef struct _tagLSP
  15. {
  16. LPTSTR lpszName;
  17. LDAPSERVERPARAMS ldapsp;
  18. int nRetVal;
  19. BOOL bAddNew;
  20. } LSP, * LPLSP;
  21. // Return codes from Dialog Box
  22. enum _DSPROPS
  23. {
  24. DSPROP_ERROR=0,
  25. DSPROP_OK,
  26. DSPROP_CANCEL
  27. };
  28. /*
  29. * Prototypes
  30. */
  31. int CreateDSPropertySheet( HWND hwndOwner, LPLSP lpLsp);
  32. BOOL APIENTRY_16 fnDSPropsProc(HWND hDlg,UINT message,UINT wParam,LPARAM lParam);
  33. BOOL APIENTRY_16 fnDSAdvancedPropsProc(HWND hDlg,UINT message,UINT wParam,LPARAM lParam);
  34. BOOL FillDSPropsUI( HWND hDlg,
  35. int nPropSheet,
  36. LPLSP lpLsp);
  37. BOOL GetDSPropsFromUI( HWND hDlg,
  38. int nPropSheet,
  39. LPLSP lpLsp);
  40. BOOL SetDSPropsUI(HWND hDlg,
  41. int nPropSheet);
  42. // List of property sheets in this UI
  43. enum _DSProps
  44. {
  45. propDSProp=0,
  46. propDSPropAdvanced,
  47. propDSMax
  48. };
  49. #define EDIT_LEN MAX_UI_STR-16
  50. /*
  51. * Help IDs
  52. */
  53. static DWORD rgDsPropsHelpIDs[] =
  54. {
  55. IDC_LDAP_PROPS_FRAME, IDH_WAB_COMM_GROUPBOX,
  56. IDC_LDAP_PROPS_FRAME2, IDH_WAB_COMM_GROUPBOX,
  57. //IDC_LDAP_PROPS_STATIC_CAPTION,
  58. IDC_LDAP_PROPS_STATIC_NAME_FRIENDLY,IDH_WABLDAP_DIRSSERV_FRIENDLY_NAME,
  59. IDC_LDAP_PROPS_EDIT_NAME_FRIENDLY, IDH_WABLDAP_DIRSSERV_FRIENDLY_NAME,
  60. IDC_LDAP_PROPS_RADIO_SICILY, IDH_WABLDAP_DIRSSERV_AUTH_SICILY,
  61. IDC_LDAP_PROPS_CHECK_NAMES, IDH_WABLDAP_DIRSSERV_CHECK_AGAINST,
  62. IDC_LDAP_PROPS_STATIC_NAME, IDH_WABLDAP_DIRSSERV_NAME,
  63. IDC_LDAP_PROPS_EDIT_NAME, IDH_WABLDAP_DIRSSERV_NAME,
  64. IDC_LDAP_PROPS_RADIO_ANON, IDH_WABLDAP_DIRSSERV_AUTH_ANON,
  65. IDC_LDAP_PROPS_RADIO_USERPASS, IDH_WABLDAP_DIRSSERV_AUTH_PASS,
  66. IDC_LDAP_PROPS_STATIC_USERNAME, IDH_WABLDAP_DIRSSERV_AUTH_PASS_UNAME,
  67. IDC_LDAP_PROPS_EDIT_USERNAME, IDH_WABLDAP_DIRSSERV_AUTH_PASS_UNAME,
  68. IDC_LDAP_PROPS_STATIC_PASSWORD, IDH_WABLDAP_DIRSSERV_AUTH_PASS_PASS,
  69. IDC_LDAP_PROPS_EDIT_PASSWORD, IDH_WABLDAP_DIRSSERV_AUTH_PASS_PASS,
  70. IDC_LDAP_PROPS_STATIC_PASSWORD2, IDH_WABLDAP_DIRSSERV_AUTH_PASS_PASS_CONF,
  71. IDC_LDAP_PROPS_EDIT_CONFIRMPASSWORD,IDH_WABLDAP_DIRSSERV_AUTH_PASS_PASS_CONF,
  72. IDC_LDAP_PROPS_FRAME_ROOT, IDH_LDAP_SEARCH_BASE,
  73. IDC_LDAP_PROPS_EDIT_ROOT, IDH_LDAP_SEARCH_BASE,
  74. IDC_LDAP_PROPS_STATIC_SEARCH, IDH_WABLDAP_SEARCH_TIMEOUT,
  75. IDC_LDAP_PROPS_EDIT_SEARCH, IDH_WABLDAP_SEARCH_TIMEOUT,
  76. IDC_LDAP_PROPS_STATIC_NUMRESULTS, IDH_WABLDAP_SEARCH_LIMIT,
  77. IDC_LDAP_PROPS_EDIT_NUMRESULTS, IDH_WABLDAP_SEARCH_LIMIT,
  78. 0,0
  79. };
  80. #endif // OLD_LDAP_UI
  81. ///////////////////////////////////////////////////////////////////
  82. //
  83. // HrShowDSProps - shows Directory Service properties UI
  84. //
  85. // hWndParent - hWnd of Parent
  86. // lpszName - pointer to a buffer ... also contains name of LDAP
  87. // server to view prperties on - this name can be modified so
  88. // lpszName should point to a big enough buffer
  89. // bAddNew - TRUE if this is a new entry, false if this is props
  90. ///////////////////////////////////////////////////////////////////
  91. HRESULT HrShowDSProps(HWND hWndParent,
  92. LPTSTR lpszName,
  93. BOOL bAddNew)
  94. {
  95. HRESULT hr = hrSuccess;
  96. IImnAccountManager * lpAccountManager = NULL;
  97. IImnAccount * lpAccount = NULL;
  98. // init account manager
  99. // Make sure there is an account manager
  100. if (hr = InitAccountManager(&lpAccountManager)) {
  101. ShowMessageBox(hWndParent, idsLDAPUnconfigured, MB_ICONEXCLAMATION | MB_OK);
  102. goto out;
  103. }
  104. // find this account
  105. if (hr = lpAccountManager->lpVtbl->FindAccount(lpAccountManager,
  106. AP_ACCOUNT_NAME,
  107. lpszName,
  108. &lpAccount)) {
  109. DebugTrace("FindAccount(%s) -> %x\n", lpszName, GetScode(hr));
  110. goto out;
  111. }
  112. // show properties
  113. if (hr = lpAccount->lpVtbl->ShowProperties(lpAccount,
  114. hWndParent,
  115. 0)) {
  116. DebugTrace("ShowProperties(%s) -> %x\n", lpszName, GetScode(hr));
  117. goto out;
  118. }
  119. {
  120. TCHAR szBuf[MAX_UI_STR];
  121. // Get the friendly name (== account name if this changed)
  122. if (! (HR_FAILED(hr = lpAccount->lpVtbl->GetPropSz(lpAccount,
  123. AP_ACCOUNT_NAME,
  124. szBuf,
  125. sizeof(szBuf)))))
  126. {
  127. lstrcpy(lpszName, szBuf);
  128. }
  129. }
  130. #ifdef OLD_LDAP_UI
  131. SCODE sc = SUCCESS_SUCCESS;
  132. TCHAR szOldName[MAX_UI_STR];
  133. ULONG i = 0, j = 0;
  134. LSP lsp = {0};
  135. DebugPrintTrace(("----------\nHrShowDSProps Entry\n"));
  136. // if no common control, exit
  137. if (NULL == ghCommCtrlDLLInst) {
  138. hr = ResultFromScode(MAPI_E_UNCONFIGURED);
  139. goto out;
  140. }
  141. lsp.lpszName = lpszName;
  142. lsp.nRetVal = DSPROP_ERROR;
  143. lsp.bAddNew = bAddNew;
  144. // Store the old name in case it changes later on ...
  145. szOldName[0]='\0';
  146. if (! bAddNew) {
  147. lstrcpy(szOldName, lpszName);
  148. }
  149. // Get the details of this DS from the registry
  150. if (lpszName && *lpszName) {
  151. if (hr = GetLDAPServerParams(lpszName, &(lsp.ldapsp))) {
  152. DebugTrace("No Account Manager\n");
  153. ShowMessageBox(hWndParent, idsLDAPUnconfigured, MB_ICONEXCLAMATION | MB_OK);
  154. goto out;
  155. }
  156. } else {
  157. // Fill in the default values for the props here:
  158. lsp.ldapsp.dwSearchSizeLimit = LDAP_SEARCH_SIZE_LIMIT;
  159. lsp.ldapsp.dwSearchTimeLimit = LDAP_SEARCH_TIME_LIMIT;
  160. lsp.ldapsp.dwAuthMethod = LDAP_AUTH_METHOD_ANONYMOUS;
  161. lsp.ldapsp.lpszUserName = NULL;
  162. lsp.ldapsp.lpszPassword = NULL;
  163. lsp.ldapsp.lpszURL = NULL;
  164. lsp.ldapsp.fResolve = FALSE;
  165. lsp.ldapsp.lpszBase = NULL;
  166. lsp.ldapsp.lpszName = NULL;
  167. }
  168. retry:
  169. // PropSheets
  170. if (CreateDSPropertySheet(hWndParent,&lsp) == -1)
  171. {
  172. // Something failed ...
  173. hr = E_FAIL;
  174. goto out;
  175. }
  176. switch(lsp.nRetVal)
  177. {
  178. case DSPROP_OK:
  179. if(lstrlen(lsp.lpszName))
  180. {
  181. // If this was an old entry that changed, remove the old entry from the
  182. // registry and rewrite this again ...
  183. // if(!bAddNew &&
  184. // (lstrcmpi(szOldName, lsp.lpszName)))
  185. // SetLDAPServerParams(szOldName, NULL);
  186. //
  187. // On second thoughts, we will let the calling function handle the old new thing
  188. // because the calling function should be able to recover from a User Cancel ...
  189. if (GetScode(SetLDAPServerParams(lpszName, &(lsp.ldapsp))) == MAPI_E_COLLISION) {
  190. // Name collision with existing account.
  191. DebugTrace("Collision in LDAP server names\n");
  192. ShowMessageBoxParam(hWndParent, IDE_SERVER_NAME_COLLISION, MB_ICONERROR, lsp.lpszName);
  193. goto retry;
  194. }
  195. }
  196. hr = S_OK;
  197. break;
  198. case DSPROP_CANCEL:
  199. hr = MAPI_E_USER_CANCEL;
  200. break;
  201. case DSPROP_ERROR:
  202. hr = E_FAIL;
  203. break;
  204. }
  205. out:
  206. FreeLDAPServerParams(lsp.ldapsp);
  207. #endif // OLD_LDAP_UI
  208. out:
  209. if (lpAccount) {
  210. lpAccount->lpVtbl->Release(lpAccount);
  211. }
  212. // Don't release the account manager. It will be done when the IAdrBook is released.
  213. // if (lpAccountManager) {
  214. // lpAccountManager->lpVtbl->Release(lpAccountManager);
  215. // }
  216. return hr;
  217. }
  218. #ifdef OLD_LDAP_UI
  219. /****************************************************************************
  220. * FUNCTION: CreateDSPropertySheet(HWND)
  221. *
  222. * PURPOSE: Creates the DL property sheet
  223. *
  224. ****************************************************************************/
  225. int CreateDSPropertySheet( HWND hwndOwner,
  226. LPLSP lpLsp)
  227. {
  228. PROPSHEETPAGE psp[propDSMax];
  229. PROPSHEETHEADER psh;
  230. TCHAR szBuf[propDSMax][MAX_UI_STR];
  231. TCHAR szBuf2[MAX_UI_STR];
  232. psp[propDSProp].dwSize = sizeof(PROPSHEETPAGE);
  233. psp[propDSProp].dwFlags = PSP_USETITLE;
  234. psp[propDSProp].hInstance = hinstMapiX;
  235. psp[propDSProp].pszTemplate = MAKEINTRESOURCE(IDD_DIALOG_LDAP_PROPERTIES);
  236. psp[propDSProp].pszIcon = NULL;
  237. psp[propDSProp].pfnDlgProc = (DLGPROC) fnDSPropsProc;
  238. LoadString(hinstMapiX, idsCertGeneralTitle, szBuf[propDSProp], sizeof(szBuf[propDSProp]));
  239. psp[propDSProp].pszTitle = szBuf[propDSProp];
  240. psp[propDSProp].lParam = (LPARAM) lpLsp;
  241. psp[propDSPropAdvanced].dwSize = sizeof(PROPSHEETPAGE);
  242. psp[propDSPropAdvanced].dwFlags = PSP_USETITLE;
  243. psp[propDSPropAdvanced].hInstance = hinstMapiX;
  244. psp[propDSPropAdvanced].pszTemplate = MAKEINTRESOURCE(IDD_DIALOG_LDAP_PROPERTIES_ADVANCED);
  245. psp[propDSPropAdvanced].pszIcon = NULL;
  246. psp[propDSPropAdvanced].pfnDlgProc = (DLGPROC) fnDSAdvancedPropsProc;
  247. LoadString(hinstMapiX, idsCertAdvancedTitle, szBuf[propDSPropAdvanced], sizeof(szBuf[propDSPropAdvanced]));
  248. psp[propDSPropAdvanced].pszTitle = szBuf[propDSPropAdvanced];
  249. psp[propDSPropAdvanced].lParam = (LPARAM) lpLsp;
  250. psh.dwSize = sizeof(PROPSHEETHEADER);
  251. psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  252. psh.hwndParent = hwndOwner;
  253. psh.hInstance = hinstMapiX;
  254. psh.pszIcon = NULL;
  255. LoadString(hinstMapiX, IDS_DETAILS_CAPTION, szBuf2, sizeof(szBuf2));
  256. psh.pszCaption = szBuf2;
  257. psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
  258. psh.nStartPage = propDSProp;
  259. psh.ppsp = (LPCPROPSHEETPAGE) &psp;
  260. return (gpfnPropertySheet(&psh));
  261. }
  262. /****************************************************************************
  263. * FUNCTION: SetDSPropsUI(HWND)
  264. *
  265. * PURPOSE: Sets up the UI for this PropSheet
  266. *
  267. * hDlg - Dialog
  268. * nPropSheet - property sheet
  269. *
  270. ****************************************************************************/
  271. BOOL SetDSPropsUI(HWND hDlg, int nPropSheet)
  272. {
  273. ULONG i =0;
  274. // Set the font of all the children to the default GUI font
  275. EnumChildWindows( hDlg,
  276. SetChildDefaultGUIFont,
  277. (LPARAM) 0);
  278. switch(nPropSheet)
  279. {
  280. case propDSProp:
  281. SendMessage(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_NAME),EM_SETLIMITTEXT,(WPARAM) EDIT_LEN,0);
  282. SendMessage(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_NAME_FRIENDLY),EM_SETLIMITTEXT,(WPARAM) EDIT_LEN,0);
  283. SendMessage(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_USERNAME),EM_SETLIMITTEXT,(WPARAM) EDIT_LEN,0);
  284. SendMessage(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_PASSWORD),EM_SETLIMITTEXT,(WPARAM) EDIT_LEN,0);
  285. SendMessage(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_CONFIRMPASSWORD),EM_SETLIMITTEXT,(WPARAM) EDIT_LEN,0);
  286. break;
  287. case propDSPropAdvanced:
  288. SendMessage(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_SEARCH),EM_SETLIMITTEXT,(WPARAM) EDIT_LEN,0);
  289. SendMessage(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_NUMRESULTS),EM_SETLIMITTEXT,(WPARAM) EDIT_LEN,0);
  290. SendMessage(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_ROOT),EM_SETLIMITTEXT,(WPARAM) EDIT_LEN,0);
  291. break;
  292. }
  293. return TRUE;
  294. }
  295. /****************************************************************************
  296. * FUNCTION: FillDSPropsUI(HWND)
  297. *
  298. * PURPOSE: Fills in the dialog items on the property sheet
  299. *
  300. ****************************************************************************/
  301. BOOL FillDSPropsUI(HWND hDlg, int nPropSheet, LPLSP lpLsp)
  302. {
  303. ULONG i = 0,j = 0;
  304. BOOL bRet = FALSE;
  305. int id;
  306. switch(nPropSheet)
  307. {
  308. case propDSProp:
  309. {
  310. // Set the authentication method UI
  311. switch(lpLsp->ldapsp.dwAuthMethod)
  312. {
  313. case LDAP_AUTH_METHOD_ANONYMOUS:
  314. id = IDC_LDAP_PROPS_RADIO_ANON;
  315. break;
  316. case LDAP_AUTH_METHOD_SIMPLE:
  317. id = IDC_LDAP_PROPS_RADIO_USERPASS;
  318. break;
  319. case LDAP_AUTH_METHOD_SICILY:
  320. id = IDC_LDAP_PROPS_RADIO_SICILY;
  321. break;
  322. }
  323. if( (id == IDC_LDAP_PROPS_RADIO_ANON) ||
  324. (id == IDC_LDAP_PROPS_RADIO_SICILY) )
  325. {
  326. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_USERNAME),FALSE);
  327. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_PASSWORD),FALSE);
  328. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_CONFIRMPASSWORD),FALSE);
  329. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_STATIC_USERNAME),FALSE);
  330. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_STATIC_PASSWORD),FALSE);
  331. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_STATIC_PASSWORD2),FALSE);
  332. }
  333. //
  334. // Club the radio buttons togethor ...
  335. CheckRadioButton( hDlg,
  336. IDC_LDAP_PROPS_RADIO_ANON,
  337. IDC_LDAP_PROPS_RADIO_USERPASS,
  338. id);
  339. // Fill in other details
  340. if(lstrlen(lpLsp->lpszName))
  341. {
  342. SetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_NAME_FRIENDLY, lpLsp->lpszName);
  343. SetWindowPropertiesTitle(GetParent(hDlg), lpLsp->lpszName);
  344. }
  345. if(lpLsp->ldapsp.lpszName)
  346. SetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_NAME, lpLsp->ldapsp.lpszName);
  347. if(lpLsp->ldapsp.lpszUserName)
  348. SetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_USERNAME, lpLsp->ldapsp.lpszUserName);
  349. if(lpLsp->ldapsp.lpszPassword)
  350. {
  351. SetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_PASSWORD, lpLsp->ldapsp.lpszPassword);
  352. SetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_CONFIRMPASSWORD, lpLsp->ldapsp.lpszPassword);
  353. }
  354. id = (lpLsp->ldapsp.fResolve) ? BST_CHECKED : BST_UNCHECKED;
  355. CheckDlgButton(hDlg, IDC_LDAP_PROPS_CHECK_NAMES, id);
  356. }
  357. break;
  358. case propDSPropAdvanced:
  359. {
  360. SetDlgItemInt( hDlg,
  361. IDC_LDAP_PROPS_EDIT_SEARCH,
  362. lpLsp->ldapsp.dwSearchTimeLimit,
  363. FALSE);
  364. SetDlgItemInt( hDlg,
  365. IDC_LDAP_PROPS_EDIT_NUMRESULTS,
  366. lpLsp->ldapsp.dwSearchSizeLimit,
  367. FALSE);
  368. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_ROOT),TRUE);
  369. if(lpLsp->ldapsp.lpszBase)
  370. {
  371. SetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_ROOT, lpLsp->ldapsp.lpszBase);
  372. }
  373. else
  374. {
  375. LPTSTR lpszBase = TEXT("c=%s"); //Hopefully this string doesnt need localization
  376. TCHAR szBuf[32], szCode[4];
  377. ReadRegistryLDAPDefaultCountry(NULL, szCode);
  378. wsprintf(szBuf, lpszBase, szCode);
  379. SetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_ROOT, szBuf);
  380. }
  381. }
  382. break;
  383. }
  384. bRet = TRUE;
  385. return bRet;
  386. }
  387. ////////////////////////////////////////////////////////////////////////////////
  388. //
  389. // GetDSPropsFromUI - reads the UI for its parameters and verifies that
  390. // all required fields are set. Params are stored back in the lpLsp struct
  391. //
  392. ////////////////////////////////////////////////////////////////////////////////
  393. BOOL GetDSPropsFromUI(HWND hDlg, int nPropSheet, LPLSP lpLsp)
  394. {
  395. BOOL bRet = FALSE;
  396. LDAPSERVERPARAMS Params={0};
  397. TCHAR szBuf[2 * EDIT_LEN];
  398. switch(nPropSheet)
  399. {
  400. case propDSProp:
  401. {
  402. //
  403. // First check the required property (which is the Name and Friendly Name)
  404. //
  405. BOOL bName = FALSE, bFName = FALSE;
  406. DWORD dwID = 0;
  407. BOOL bExists = FALSE;
  408. szBuf[0]='\0'; //reset
  409. GetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_NAME_FRIENDLY, szBuf, sizeof(szBuf));
  410. TrimSpaces(szBuf);
  411. if(lstrlen(szBuf))
  412. bFName = TRUE;
  413. // We want the friendly names to be unique .. hence check if this friendly name
  414. // already exists or not ...
  415. bExists = GetLDAPServerParams(szBuf, &Params);
  416. if((bExists && lpLsp->bAddNew) ||
  417. (bExists && !lpLsp->bAddNew && (Params.dwID != lpLsp->ldapsp.dwID)))
  418. {
  419. // We are adding a new entry, but we found that another entry exists with the
  420. // same name or we are editing an existing entry and then found that another
  421. // entry exists whose ID does not match this entries ID.
  422. // Warn them that they must add a unique friendly name
  423. ShowMessageBoxParam(hDlg, idsEnterUniqueLDAPName, MB_ICONEXCLAMATION | MB_OK, szBuf);
  424. goto out;
  425. }
  426. szBuf[0]='\0'; //
  427. GetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_NAME, szBuf, sizeof(szBuf));
  428. TrimSpaces(szBuf);
  429. if(lstrlen(szBuf))
  430. bName = TRUE;
  431. if(!bName || !bFName)
  432. {
  433. ShowMessageBox(hDlg, idsEnterLDAPServerName, MB_ICONEXCLAMATION | MB_OK);
  434. goto out;
  435. }
  436. GetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_NAME, szBuf, sizeof(szBuf));
  437. TrimSpaces(szBuf);
  438. LocalFreeAndNull(&lpLsp->ldapsp.lpszName);
  439. lpLsp->ldapsp.lpszName = LocalAlloc(LMEM_ZEROINIT, lstrlen(szBuf)+1);
  440. if(lpLsp->ldapsp.lpszName)
  441. lstrcpy(lpLsp->ldapsp.lpszName, szBuf);
  442. GetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_NAME_FRIENDLY, szBuf, sizeof(szBuf));
  443. TrimSpaces(szBuf);
  444. lstrcpy(lpLsp->lpszName, szBuf);
  445. //
  446. // check the selected authentication type
  447. //
  448. if(IsDlgButtonChecked(hDlg, IDC_LDAP_PROPS_RADIO_ANON) == 1)
  449. lpLsp->ldapsp.dwAuthMethod = LDAP_AUTH_METHOD_ANONYMOUS;
  450. else if(IsDlgButtonChecked(hDlg, IDC_LDAP_PROPS_RADIO_USERPASS) == 1)
  451. lpLsp->ldapsp.dwAuthMethod = LDAP_AUTH_METHOD_SIMPLE;
  452. else if(IsDlgButtonChecked(hDlg, IDC_LDAP_PROPS_RADIO_SICILY) == 1)
  453. lpLsp->ldapsp.dwAuthMethod = LDAP_AUTH_METHOD_SICILY;
  454. LocalFreeAndNull(&lpLsp->ldapsp.lpszUserName);
  455. LocalFreeAndNull(&lpLsp->ldapsp.lpszPassword);
  456. //
  457. // Get the user name password, if applicable
  458. //
  459. if(lpLsp->ldapsp.dwAuthMethod == LDAP_AUTH_METHOD_SIMPLE)
  460. {
  461. TCHAR szBuf2[MAX_UI_STR*2];
  462. //
  463. // Verify that the entered password matches the confirmed password
  464. //
  465. szBuf[0]='\0'; //reset
  466. GetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_PASSWORD, szBuf, sizeof(szBuf));
  467. szBuf2[0]='\0'; //reset
  468. GetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_CONFIRMPASSWORD, szBuf2, sizeof(szBuf2));
  469. TrimSpaces(szBuf);
  470. TrimSpaces(szBuf2);
  471. if(lstrcmp(szBuf,szBuf2))
  472. {
  473. ShowMessageBox(hDlg, idsConfirmPassword, MB_ICONEXCLAMATION | MB_OK);
  474. SetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_PASSWORD, szEmpty);
  475. SetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_CONFIRMPASSWORD, szEmpty);
  476. goto out;
  477. }
  478. // otherwise keep this password ...
  479. lpLsp->ldapsp.lpszPassword = LocalAlloc(LMEM_ZEROINIT, lstrlen(szBuf)+1);
  480. if(!(lpLsp->ldapsp.lpszPassword))
  481. {
  482. DebugPrintError(("LocalAlloc failed to allocate memory\n"));
  483. goto out;
  484. }
  485. lstrcpy(lpLsp->ldapsp.lpszPassword,szBuf);
  486. szBuf[0]='\0'; //reset
  487. GetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_USERNAME, szBuf, sizeof(szBuf));
  488. TrimSpaces(szBuf);
  489. if(lstrlen(szBuf))
  490. {
  491. lpLsp->ldapsp.lpszUserName = LocalAlloc(LMEM_ZEROINIT, lstrlen(szBuf)+1);
  492. if(!(lpLsp->ldapsp.lpszUserName))
  493. {
  494. DebugPrintError(("LocalAlloc failed to allocate memory\n"));
  495. goto out;
  496. }
  497. lstrcpy(lpLsp->ldapsp.lpszUserName,szBuf);
  498. }
  499. }
  500. if(IsDlgButtonChecked(hDlg, IDC_LDAP_PROPS_CHECK_NAMES) == BST_CHECKED)
  501. lpLsp->ldapsp.fResolve = TRUE;
  502. else
  503. lpLsp->ldapsp.fResolve = FALSE;
  504. if(lpLsp->bAddNew)
  505. lpLsp->ldapsp.dwID = GetLDAPNextServerID(0);
  506. }
  507. break;
  508. case propDSPropAdvanced:
  509. {
  510. lpLsp->ldapsp.dwSearchTimeLimit = GetDlgItemInt(
  511. hDlg,
  512. IDC_LDAP_PROPS_EDIT_SEARCH,
  513. NULL,
  514. FALSE);
  515. lpLsp->ldapsp.dwSearchSizeLimit = GetDlgItemInt(
  516. hDlg,
  517. IDC_LDAP_PROPS_EDIT_NUMRESULTS,
  518. NULL,
  519. FALSE);
  520. GetDlgItemText(hDlg, IDC_LDAP_PROPS_EDIT_ROOT, szBuf, sizeof(szBuf));
  521. TrimSpaces(szBuf);
  522. if(lstrlen(szBuf))
  523. {
  524. LocalFreeAndNull(&lpLsp->ldapsp.lpszBase);
  525. lpLsp->ldapsp.lpszBase = LocalAlloc(LMEM_ZEROINIT, lstrlen(szBuf)+1);
  526. if(lpLsp->ldapsp.lpszBase)
  527. lstrcpy(lpLsp->ldapsp.lpszBase, szBuf);
  528. }
  529. }
  530. break;
  531. }
  532. bRet = TRUE;
  533. out:
  534. FreeLDAPServerParams(Params);
  535. return bRet;
  536. }
  537. #define lpLSP ((LPLSP) pps->lParam)
  538. /*//$$***********************************************************************
  539. * FUNCTION: fnDSPropsProc
  540. *
  541. * PURPOSE: Window proc for property sheet ...
  542. *
  543. ****************************************************************************/
  544. BOOL APIENTRY_16 fnDSPropsProc(HWND hDlg,UINT message,UINT wParam,LPARAM lParam)
  545. {
  546. PROPSHEETPAGE * pps;
  547. BOOL bRet = FALSE;
  548. ULONG ulcPropCount = 0;
  549. pps = (PROPSHEETPAGE *) GetWindowLong(hDlg, DWL_USER);
  550. switch(message)
  551. {
  552. case WM_INITDIALOG:
  553. SetWindowLong(hDlg,DWL_USER,lParam);
  554. pps = (PROPSHEETPAGE *) lParam;
  555. SetDSPropsUI(hDlg, propDSProp);
  556. FillDSPropsUI(hDlg, propDSProp, lpLSP);
  557. return TRUE;
  558. case WM_HELP:
  559. #ifndef WIN16
  560. WinHelp( ((LPHELPINFO)lParam)->hItemHandle,
  561. g_szWABHelpFileName,
  562. HELP_WM_HELP,
  563. (DWORD)(LPSTR) rgDsPropsHelpIDs );
  564. #else
  565. WinHelp( hDlg,
  566. g_szWABHelpFileName,
  567. HELP_CONTENTS,
  568. 0L );
  569. #endif // !WIN16
  570. break;
  571. #ifndef WIN16
  572. case WM_CONTEXTMENU:
  573. WinHelp((HWND) wParam,
  574. g_szWABHelpFileName,
  575. HELP_CONTEXTMENU,
  576. (DWORD)(LPVOID) rgDsPropsHelpIDs );
  577. break;
  578. #endif // !WIN16
  579. case WM_COMMAND:
  580. switch(GET_WM_COMMAND_CMD(wParam,lParam)) //check the notification code
  581. {
  582. case EN_CHANGE:
  583. switch(LOWORD(wParam))
  584. {
  585. case IDC_LDAP_PROPS_EDIT_NAME_FRIENDLY:
  586. {
  587. // Update the dialog title with the friendly name
  588. TCHAR szBuf[MAX_UI_STR];
  589. GetWindowText((HWND) lParam,szBuf,sizeof(szBuf));
  590. SetWindowPropertiesTitle(GetParent(hDlg), szBuf);
  591. }
  592. break;
  593. }
  594. break;
  595. }
  596. switch(GET_WM_COMMAND_ID(wParam,lParam))
  597. {
  598. case IDCANCEL:
  599. // This is a windows bug that prevents ESC canceling prop sheets
  600. // which have MultiLine Edit boxes KB: Q130765
  601. SendMessage(GetParent(hDlg),message,wParam,lParam);
  602. break;
  603. case IDC_LDAP_PROPS_RADIO_ANON:
  604. case IDC_LDAP_PROPS_RADIO_USERPASS:
  605. case IDC_LDAP_PROPS_RADIO_SICILY:
  606. CheckRadioButton( hDlg,
  607. IDC_LDAP_PROPS_RADIO_ANON,
  608. IDC_LDAP_PROPS_RADIO_USERPASS,
  609. LOWORD(wParam));
  610. {
  611. int id = LOWORD(wParam);
  612. if( (id == IDC_LDAP_PROPS_RADIO_ANON) ||
  613. (id == IDC_LDAP_PROPS_RADIO_SICILY) )
  614. {
  615. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_USERNAME),FALSE);
  616. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_PASSWORD),FALSE);
  617. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_CONFIRMPASSWORD),FALSE);
  618. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_STATIC_USERNAME),FALSE);
  619. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_STATIC_PASSWORD),FALSE);
  620. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_STATIC_PASSWORD2),FALSE);
  621. }
  622. else if (id = IDC_LDAP_PROPS_RADIO_USERPASS)
  623. {
  624. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_USERNAME),TRUE);
  625. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_PASSWORD),TRUE);
  626. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_EDIT_CONFIRMPASSWORD),TRUE);
  627. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_STATIC_USERNAME),TRUE);
  628. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_STATIC_PASSWORD),TRUE);
  629. EnableWindow(GetDlgItem(hDlg,IDC_LDAP_PROPS_STATIC_PASSWORD2),TRUE);
  630. }
  631. }
  632. break;
  633. }
  634. break;
  635. case WM_NOTIFY:
  636. switch(((NMHDR FAR *)lParam)->code)
  637. {
  638. case PSN_SETACTIVE: //initialize
  639. break;
  640. case PSN_APPLY: //ok
  641. if (!GetDSPropsFromUI(hDlg, propDSProp, lpLSP))
  642. {
  643. //something failed ... abort this OK ... ie dont let them close
  644. SetWindowLong(hDlg,DWL_MSGRESULT, TRUE);
  645. return TRUE;
  646. }
  647. lpLSP->nRetVal = DSPROP_OK;
  648. break;
  649. case PSN_KILLACTIVE: //Losing activation to another page
  650. break;
  651. case PSN_RESET: //cancel
  652. lpLSP->nRetVal = DSPROP_CANCEL;
  653. break;
  654. }
  655. return TRUE;
  656. }
  657. return bRet;
  658. }
  659. /*//$$***********************************************************************
  660. * FUNCTION: fnDSAdvancedPropsProc
  661. *
  662. * PURPOSE: Window proc for advanced property sheet ...
  663. *
  664. ****************************************************************************/
  665. BOOL APIENTRY_16 fnDSAdvancedPropsProc(HWND hDlg,UINT message,UINT wParam,LPARAM lParam)
  666. {
  667. PROPSHEETPAGE * pps;
  668. BOOL bRet = FALSE;
  669. ULONG ulcPropCount = 0;
  670. pps = (PROPSHEETPAGE *) GetWindowLong(hDlg, DWL_USER);
  671. switch(message)
  672. {
  673. case WM_INITDIALOG:
  674. SetWindowLong(hDlg,DWL_USER,lParam);
  675. pps = (PROPSHEETPAGE *) lParam;
  676. SetDSPropsUI(hDlg, propDSPropAdvanced);
  677. FillDSPropsUI(hDlg, propDSPropAdvanced, lpLSP);
  678. return TRUE;
  679. case WM_HELP:
  680. #ifndef WIN16
  681. WinHelp( ((LPHELPINFO)lParam)->hItemHandle,
  682. g_szWABHelpFileName,
  683. HELP_WM_HELP,
  684. (DWORD)(LPSTR) rgDsPropsHelpIDs );
  685. #else
  686. WinHelp( hDlg,
  687. g_szWABHelpFileName,
  688. HELP_CONTENTS,
  689. 0L );
  690. #endif // !WIN16
  691. break;
  692. #ifndef WIN16
  693. case WM_CONTEXTMENU:
  694. WinHelp((HWND) wParam,
  695. g_szWABHelpFileName,
  696. HELP_CONTEXTMENU,
  697. (DWORD)(LPVOID) rgDsPropsHelpIDs );
  698. break;
  699. #endif // !WIN16
  700. case WM_COMMAND:
  701. switch(GET_WM_COMMAND_ID(wParam,lParam))
  702. {
  703. case IDCANCEL:
  704. // This is a windows bug that prevents ESC canceling prop sheets
  705. // which have MultiLine Edit boxes KB: Q130765
  706. SendMessage(GetParent(hDlg),message,wParam,lParam);
  707. break;
  708. }
  709. break;
  710. case WM_NOTIFY:
  711. switch(((NMHDR FAR *)lParam)->code)
  712. {
  713. case PSN_SETACTIVE: //initialize
  714. break;
  715. case PSN_APPLY: //ok
  716. if (!GetDSPropsFromUI(hDlg, propDSPropAdvanced, lpLSP))
  717. {
  718. //something failed ... abort this OK ... ie dont let them close
  719. SetWindowLong(hDlg,DWL_MSGRESULT, TRUE);
  720. return TRUE;
  721. }
  722. lpLSP->nRetVal = DSPROP_OK;
  723. break;
  724. case PSN_KILLACTIVE: //Losing activation to another page
  725. break;
  726. case PSN_RESET: //cancel
  727. lpLSP->nRetVal = DSPROP_CANCEL;
  728. break;
  729. }
  730. return TRUE;
  731. }
  732. return bRet;
  733. }
  734. #endif // OLD_LDAP_UI