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.

1542 lines
42 KiB

  1. /*
  2. File usertab.c
  3. Implementation of the users dialog tab for the dialup server ui.
  4. Paul Mayfield, 9/29/97
  5. */
  6. #include "rassrv.h"
  7. #include "usertab.h"
  8. #define USERTAB_PASSWORD_BUFFER_SIZE 33
  9. static const WCHAR pszDummyPassword[] = L"XXXXXXXXXXXXXXX";
  10. // Help maps
  11. static const DWORD phmUserTab[] =
  12. {
  13. CID_UserTab_LV_Users, IDH_UserTab_LV_Users,
  14. CID_UserTab_PB_New, IDH_UserTab_PB_New,
  15. CID_UserTab_PB_Delete, IDH_UserTab_PB_Delete,
  16. CID_UserTab_PB_Properties, IDH_UserTab_PB_Properties,
  17. CID_UserTab_PB_SwitchToMMC, IDH_UserTab_PB_SwitchToMMC,
  18. CID_UserTab_CB_Encryption, IDH_UserTab_CB_Encryption,
  19. CID_UserTab_CB_BypassDcc, IDH_UserTab_CB_BypassDcc,
  20. 0, 0
  21. };
  22. static const DWORD phmCallback[] =
  23. {
  24. CID_UserTab_Callback_RB_Caller, IDH_UserTab_Callback_RB_Caller,
  25. CID_UserTab_Callback_RB_Admin, IDH_UserTab_Callback_RB_Admin,
  26. CID_UserTab_Callback_EB_Number, IDH_UserTab_Callback_EB_Number,
  27. CID_UserTab_Callback_RB_No, IDH_UserTab_Callback_RB_No,
  28. 0, 0
  29. };
  30. static const DWORD phmNewUser[] =
  31. {
  32. CID_UserTab_New_EB_Username, IDH_UserTab_New_EB_Username,
  33. CID_UserTab_New_EB_Fullname, IDH_UserTab_New_EB_Fullname,
  34. CID_UserTab_New_EB_Password1, IDH_UserTab_New_EB_Password1,
  35. CID_UserTab_New_EB_Password2, IDH_UserTab_New_EB_Password2,
  36. 0, 0
  37. };
  38. // Parameters to track net users
  39. //
  40. typedef struct _RASSRV_USER_PARAMS
  41. {
  42. BOOL bCanceled; // Set by property sheets when cancel pressed
  43. // General properties
  44. //For whistler bug 210032 to allow username be 20 characters long
  45. WCHAR pszLogonName[22];
  46. WCHAR pszFullName [129];
  47. WCHAR pszPassword1[USERTAB_PASSWORD_BUFFER_SIZE];
  48. WCHAR pszPassword2[USERTAB_PASSWORD_BUFFER_SIZE];
  49. DWORD dwErrorCode;
  50. // Callback properties
  51. HANDLE hUser;
  52. BOOL bNone;
  53. BOOL bCaller;
  54. BOOL bAdmin;
  55. WCHAR pszNumber[MAX_PHONE_NUMBER_LEN];
  56. } RASSRV_USER_PARAMS;
  57. // Fills in the property sheet structure with the information
  58. // required to display the user database tab.
  59. //
  60. DWORD
  61. UserTabGetPropertyPage(
  62. IN LPPROPSHEETPAGE ppage,
  63. IN LPARAM lpUserData)
  64. {
  65. // Initialize
  66. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  67. // Fill in the values
  68. ppage->dwSize = sizeof(PROPSHEETPAGE);
  69. ppage->hInstance = Globals.hInstDll;
  70. ppage->pszTemplate = MAKEINTRESOURCE(PID_UserTab);
  71. ppage->pfnDlgProc = UserTabDialogProc;
  72. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  73. ppage->dwFlags = PSP_USECALLBACK;
  74. ppage->lParam = lpUserData;
  75. return NO_ERROR;
  76. }
  77. //
  78. // Error reporting
  79. //
  80. VOID
  81. UserTabDisplayError(
  82. IN HWND hwnd,
  83. IN DWORD err)
  84. {
  85. ErrDisplayError(
  86. hwnd,
  87. err,
  88. ERR_USERTAB_CATAGORY,
  89. ERR_USERDB_SUBCAT,
  90. Globals.dwErrorData);
  91. }
  92. // Fills in the user list view with the names of the users stored in the
  93. // user database provide. Also, initializes the checked/unchecked status
  94. // of each user.
  95. DWORD
  96. UserTabFillUserList(
  97. IN HWND hwndLV,
  98. IN HANDLE hUserDatabase)
  99. {
  100. LV_ITEM lvi;
  101. DWORD dwCount, i, dwErr, dwSize;
  102. HANDLE hUser;
  103. WCHAR pszName[512];
  104. char pszAName[512];
  105. HIMAGELIST checks;
  106. BOOL bDialinEnabled;
  107. // Get the count of all the users
  108. if ((dwErr = usrGetUserCount(hUserDatabase, &dwCount)) != NO_ERROR)
  109. {
  110. UserTabDisplayError(hwndLV, ERR_USER_DATABASE_CORRUPT);
  111. return dwErr;
  112. }
  113. ListView_SetUserImageList(hwndLV, Globals.hInstDll);
  114. // Initialize the list item
  115. ZeroMemory(&lvi, sizeof(LV_ITEM));
  116. lvi.mask = LVIF_TEXT | LVIF_IMAGE;
  117. // Looop through all of the users adding their names as we go
  118. for (i=0; i<dwCount; i++)
  119. {
  120. dwSize = 512;
  121. if ((dwErr = usrGetUserHandle(hUserDatabase, i, &hUser)) == NO_ERROR)
  122. {
  123. usrGetDisplayName (hUser, pszName, &dwSize);
  124. usrGetDialin(hUser, &bDialinEnabled);
  125. lvi.iImage = UI_Connections_User;
  126. lvi.iItem = i;
  127. lvi.pszText = pszName;
  128. lvi.cchTextMax = wcslen(pszName)+1;
  129. ListView_InsertItem(hwndLV,&lvi);
  130. ListView_SetCheck(hwndLV, i, bDialinEnabled);
  131. }
  132. }
  133. // Select the first item in the list view
  134. ListView_SetItemState(
  135. hwndLV,
  136. 0,
  137. LVIS_SELECTED | LVIS_FOCUSED,
  138. LVIS_SELECTED | LVIS_FOCUSED);
  139. return NO_ERROR;
  140. }
  141. //
  142. // Initialize the user tab, returns false if focus was set,
  143. // true otherwise.
  144. //
  145. DWORD
  146. UserTabInitializeDialog(
  147. HWND hwndDlg,
  148. WPARAM wParam,
  149. LPARAM lParam)
  150. {
  151. HANDLE hUserDatabase = NULL;
  152. HWND hwndLV, hwndEnc, hwndBypass;
  153. LV_COLUMN lvc;
  154. RECT r;
  155. BOOL bEncrypt;
  156. DWORD dwErr;
  157. BOOL bPure = FALSE, bBypass = FALSE;
  158. // Obtain handle to user database
  159. RasSrvGetDatabaseHandle(hwndDlg, ID_USER_DATABASE, &hUserDatabase);
  160. // Figure out if MMC has been used.
  161. dwErr = usrIsDatabasePure (hUserDatabase, &bPure);
  162. if ((dwErr == NO_ERROR) && (bPure == FALSE))
  163. {
  164. PWCHAR pszWarning, pszTitle;
  165. pszWarning = (PWCHAR) PszLoadString(
  166. Globals.hInstDll,
  167. WRN_USERS_CONFIGURED_MMC);
  168. pszTitle = (PWCHAR) PszLoadString(
  169. Globals.hInstDll,
  170. ERR_USERTAB_CATAGORY);
  171. MessageBox(hwndDlg, pszWarning, pszTitle, MB_OK | MB_ICONWARNING);
  172. usrSetDatabasePure(hUserDatabase, TRUE);
  173. }
  174. // Fill in the user list if it's not already filled
  175. hwndLV = GetDlgItem(hwndDlg, CID_UserTab_LV_Users);
  176. if (ListView_GetItemCount (hwndLV) == 0)
  177. {
  178. ListView_InstallChecks(hwndLV, Globals.hInstDll);
  179. UserTabFillUserList(hwndLV, hUserDatabase);
  180. // Add a colum so that we'll display in report view
  181. GetClientRect(hwndLV, &r);
  182. lvc.mask = LVCF_FMT;
  183. lvc.fmt = LVCFMT_LEFT;
  184. ListView_InsertColumn(hwndLV,0,&lvc);
  185. ListView_SetColumnWidth(hwndLV, 0, LVSCW_AUTOSIZE_USEHEADER);
  186. // Initialize the encryption check box
  187. hwndEnc = GetDlgItem(hwndDlg, CID_UserTab_CB_Encryption);
  188. usrGetEncryption(hUserDatabase, &bEncrypt);
  189. if (hwndEnc != NULL)
  190. {
  191. SendMessage(
  192. hwndEnc,
  193. BM_SETCHECK,
  194. (bEncrypt) ? BST_CHECKED : BST_UNCHECKED,
  195. 0);
  196. }
  197. // Initialize the "bypass dcc" checkbox
  198. hwndBypass = GetDlgItem(hwndDlg, CID_UserTab_CB_BypassDcc);
  199. if (hwndBypass != NULL)
  200. {
  201. usrGetDccBypass(hUserDatabase, &bBypass);
  202. SendMessage(
  203. hwndBypass,
  204. BM_SETCHECK,
  205. (bBypass) ? BST_CHECKED : BST_UNCHECKED,
  206. 0);
  207. }
  208. }
  209. return TRUE;
  210. }
  211. //
  212. // Cleanup anything done in the initialization function
  213. //
  214. DWORD
  215. UserTabCleanupDialog(
  216. IN HWND hwndDlg,
  217. IN WPARAM wParam,
  218. IN LPARAM lParam)
  219. {
  220. // Restore the user data
  221. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
  222. return NO_ERROR;
  223. }
  224. //
  225. // Grants/revokes the dialin privelege of a user and reflects this
  226. // in the UI
  227. //
  228. DWORD
  229. UserTabHandleUserCheck(
  230. IN HWND hwndDlg,
  231. IN DWORD dwIndex)
  232. {
  233. DWORD dwErr;
  234. HANDLE hUser = NULL, hUserDatabase = NULL;
  235. HWND hwndLV = GetDlgItem(hwndDlg, CID_UserTab_LV_Users);
  236. // Get the user handle from the user database
  237. RasSrvGetDatabaseHandle(hwndDlg, ID_USER_DATABASE, &hUserDatabase);
  238. dwErr = usrGetUserHandle(hUserDatabase, dwIndex, &hUser);
  239. if (dwErr != NO_ERROR)
  240. {
  241. UserTabDisplayError(hwndDlg, ERR_USER_DATABASE_CORRUPT);
  242. return dwErr;
  243. }
  244. // Set the dialin permission of the given user
  245. usrEnableDialin(hUser, ListView_GetCheck(hwndLV, dwIndex));
  246. return NO_ERROR;
  247. }
  248. //
  249. // Encrypts an in-memory password
  250. //
  251. DWORD
  252. UserTabEncryptPassword(
  253. IN PWCHAR pszPassword,
  254. IN DWORD dwLength)
  255. {
  256. DWORD i;
  257. WCHAR ENCRYPT_MASK = (WCHAR)0xA5;
  258. for (i = 0; i < dwLength; i++)
  259. {
  260. pszPassword[i] ^= ENCRYPT_MASK;
  261. pszPassword[i] ^= ENCRYPT_MASK;
  262. }
  263. return NO_ERROR;
  264. }
  265. DWORD
  266. UserTabDecryptPassword(
  267. IN PWCHAR pszPassword,
  268. IN DWORD dwLength)
  269. {
  270. return UserTabEncryptPassword(pszPassword, dwLength);
  271. }
  272. //
  273. // Loads the New User parameters and returns whether they
  274. // have been correctly entered or not.
  275. //
  276. BOOL
  277. UserTabNewUserParamsOk(
  278. IN HWND hwndDlg,
  279. IN RASSRV_USER_PARAMS * pNuParams)
  280. {
  281. USER_MODALS_INFO_0 * pModInfo;
  282. NET_API_STATUS nStatus;
  283. DWORD dwMinPasswordLength=0, dwLength;
  284. BOOL bOk = FALSE;
  285. // Find the minium password length
  286. nStatus = NetUserModalsGet(NULL, 0, (LPBYTE*)&pModInfo);
  287. if (nStatus == NERR_Success)
  288. {
  289. dwMinPasswordLength = pModInfo->usrmod0_min_passwd_len;
  290. NetApiBufferFree((LPBYTE)pModInfo);
  291. }
  292. // Load the parameters
  293. GetWindowTextW(
  294. GetDlgItem(hwndDlg, CID_UserTab_New_EB_Username),
  295. pNuParams->pszLogonName,
  296. (sizeof(pNuParams->pszLogonName)/sizeof(WCHAR)) - 1);
  297. GetWindowTextW(
  298. GetDlgItem(hwndDlg, CID_UserTab_New_EB_Fullname),
  299. pNuParams->pszFullName,
  300. (sizeof(pNuParams->pszFullName)/sizeof(WCHAR)) - 1);
  301. GetWindowTextW(
  302. GetDlgItem(hwndDlg, CID_UserTab_New_EB_Password1),
  303. pNuParams->pszPassword1,
  304. (sizeof(pNuParams->pszPassword1)/sizeof(WCHAR)) - 1);
  305. GetWindowTextW(
  306. GetDlgItem(hwndDlg, CID_UserTab_New_EB_Password2),
  307. pNuParams->pszPassword2,
  308. (sizeof(pNuParams->pszPassword2)/sizeof(WCHAR)) - 1);
  309. do
  310. {
  311. // Verify that we have a login name
  312. dwLength = wcslen(pNuParams->pszLogonName);
  313. if (dwLength < 1)
  314. {
  315. pNuParams->dwErrorCode = ERR_LOGON_NAME_TOO_SMALL;
  316. bOk = FALSE;
  317. break;
  318. }
  319. // Verify the minimum password length
  320. dwLength = wcslen(pNuParams->pszPassword1);
  321. if (dwLength < dwMinPasswordLength)
  322. {
  323. pNuParams->dwErrorCode = ERR_PASSWORD_TOO_SMALL;
  324. bOk = FALSE;
  325. break;
  326. }
  327. // Verify the passwords was entered correctly
  328. if (wcscmp(pNuParams->pszPassword1, pNuParams->pszPassword2))
  329. {
  330. pNuParams->dwErrorCode = ERR_PASSWORD_MISMATCH;
  331. bOk = FALSE;
  332. break;
  333. }
  334. bOk = TRUE;
  335. } while (FALSE);
  336. // Cleanup
  337. {
  338. if (!bOk)
  339. {
  340. ZeroMemory(
  341. pNuParams->pszPassword1,
  342. USERTAB_PASSWORD_BUFFER_SIZE);
  343. ZeroMemory(
  344. pNuParams->pszPassword2,
  345. USERTAB_PASSWORD_BUFFER_SIZE);
  346. }
  347. }
  348. // Encrypt the passwords in memory for security
  349. UserTabEncryptPassword(pNuParams->pszPassword1, dwLength);
  350. UserTabEncryptPassword(pNuParams->pszPassword2, dwLength);
  351. return bOk;
  352. }
  353. //
  354. // Initialize the callback properties of the given user
  355. //
  356. DWORD
  357. UserTabLoadUserProps (
  358. IN RASSRV_USER_PARAMS * pParams)
  359. {
  360. PWCHAR pszName;
  361. DWORD dwErr, dwSize;
  362. PWCHAR pszNumber;
  363. if (!pParams)
  364. {
  365. return ERROR_INVALID_PARAMETER;
  366. }
  367. // If this is a new user, default to user specified callback
  368. // (convienience mode)
  369. if (!pParams->hUser)
  370. {
  371. ZeroMemory(pParams, sizeof(*pParams));
  372. pParams->bNone = TRUE;
  373. pParams->bCaller = FALSE;
  374. pParams->bAdmin = FALSE;
  375. }
  376. // Otherwise, load the user parameters from the user database
  377. else
  378. {
  379. pParams->bCanceled = FALSE;
  380. dwSize = sizeof(pParams->pszFullName);
  381. usrGetFullName (pParams->hUser, pParams->pszFullName, &dwSize);
  382. usrGetName(pParams->hUser, &pszName);
  383. lstrcpynW(
  384. pParams->pszLogonName,
  385. pszName,
  386. sizeof(pParams->pszLogonName) / sizeof(WCHAR));
  387. lstrcpynW(
  388. pParams->pszPassword1,
  389. pszDummyPassword,
  390. sizeof(pParams->pszPassword1) / sizeof(WCHAR));
  391. lstrcpynW(
  392. pParams->pszPassword2,
  393. pszDummyPassword,
  394. sizeof(pParams->pszPassword2) / sizeof(WCHAR));
  395. dwErr = usrGetCallback(
  396. pParams->hUser,
  397. &pParams->bAdmin,
  398. &pParams->bCaller);
  399. if (dwErr != NO_ERROR)
  400. {
  401. return dwErr;
  402. }
  403. dwErr = usrGetCallbackNumber(pParams->hUser, &pszNumber);
  404. if (dwErr != NO_ERROR)
  405. {
  406. return dwErr;
  407. }
  408. lstrcpynW(
  409. pParams->pszNumber,
  410. pszNumber,
  411. sizeof(pParams->pszNumber) / sizeof(WCHAR));
  412. }
  413. return NO_ERROR;
  414. }
  415. //
  416. // Commit the call back properties of the given user.
  417. //
  418. DWORD
  419. UserTabSaveCallbackProps (
  420. IN RASSRV_USER_PARAMS * pParams)
  421. {
  422. if (!pParams)
  423. {
  424. return ERROR_INVALID_PARAMETER;
  425. }
  426. // If we have a valid handle to the user, set his/her
  427. // properties
  428. if (pParams->hUser)
  429. {
  430. pParams->bNone =
  431. (pParams->bCaller == FALSE && pParams->bAdmin == FALSE);
  432. // Set the enabling and number
  433. usrEnableCallback(
  434. pParams->hUser,
  435. pParams->bNone,
  436. pParams->bCaller,
  437. pParams->bAdmin);
  438. if (pParams->bAdmin)
  439. {
  440. usrSetCallbackNumber(pParams->hUser, pParams->pszNumber);
  441. }
  442. }
  443. return NO_ERROR;
  444. }
  445. // Commit the parameters of the given user. If pOrig is non-null, then all
  446. // fields of pParams will be compare against pOrig and only those that have changed
  447. // will be committed. (optimization)
  448. //
  449. DWORD
  450. UserTabSaveUserProps (
  451. IN RASSRV_USER_PARAMS * pParams,
  452. IN RASSRV_USER_PARAMS * pOrig,
  453. IN PBOOL pbChanged)
  454. {
  455. DWORD dwLength;
  456. if (!pParams || !pOrig || !pbChanged)
  457. {
  458. return ERROR_INVALID_PARAMETER;
  459. }
  460. *pbChanged = FALSE;
  461. // Commit the full name if changed
  462. if (wcscmp(pParams->pszFullName, pOrig->pszFullName))
  463. {
  464. usrSetFullName(pParams->hUser, pParams->pszFullName);
  465. *pbChanged = TRUE;
  466. }
  467. // Commit the password if changed
  468. dwLength = wcslen(pParams->pszPassword1);
  469. UserTabDecryptPassword(pParams->pszPassword1, dwLength);
  470. if (wcscmp(pParams->pszPassword1, pszDummyPassword))
  471. {
  472. usrSetPassword(pParams->hUser, pParams->pszPassword1);
  473. }
  474. UserTabEncryptPassword(pParams->pszPassword1, dwLength);
  475. UserTabSaveCallbackProps(pParams);
  476. return NO_ERROR;
  477. }
  478. DWORD
  479. UserTabCallbackApply(
  480. IN HWND hwndDlg)
  481. {
  482. RASSRV_USER_PARAMS * pParams = NULL;
  483. LONG dwResult = PSNRET_NOERROR;
  484. pParams = (RASSRV_USER_PARAMS *)
  485. GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  486. pParams->bNone = (BOOL)
  487. SendMessage(
  488. GetDlgItem(hwndDlg,CID_UserTab_Callback_RB_No),
  489. BM_GETCHECK,
  490. 0,
  491. 0);
  492. pParams->bCaller = (BOOL)
  493. SendMessage(
  494. GetDlgItem(hwndDlg,CID_UserTab_Callback_RB_Caller),
  495. BM_GETCHECK,
  496. 0,
  497. 0);
  498. pParams->bAdmin = (BOOL)
  499. SendMessage(
  500. GetDlgItem(hwndDlg,CID_UserTab_Callback_RB_Admin),
  501. BM_GETCHECK,
  502. 0,
  503. 0);
  504. if (pParams->bAdmin)
  505. {
  506. GetWindowTextW(
  507. GetDlgItem(hwndDlg,CID_UserTab_Callback_EB_Number),
  508. pParams->pszNumber,
  509. MAX_PHONE_NUMBER_LEN);
  510. // If admin callback was set, but no admin callback number was set,
  511. // then popup an error and don't to refuse the apply
  512. //
  513. if (wcslen(pParams->pszNumber) == 0)
  514. {
  515. UserTabDisplayError(hwndDlg, ERR_CALLBACK_NUM_REQUIRED);
  516. PropSheet_SetCurSel ( GetParent(hwndDlg), hwndDlg, 0 );
  517. dwResult = PSNRET_INVALID;
  518. }
  519. }
  520. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, dwResult);
  521. return TRUE;
  522. }
  523. //
  524. // Dialog procedure that implements getting callback properties
  525. //
  526. INT_PTR
  527. CALLBACK
  528. UserTabCallbackDialogProc(
  529. IN HWND hwndDlg,
  530. IN UINT uMsg,
  531. IN WPARAM wParam,
  532. IN LPARAM lParam)
  533. {
  534. switch (uMsg)
  535. {
  536. case WM_INITDIALOG:
  537. {
  538. PWCHAR lpzNumber, lpzName;
  539. HWND hwCb = GetDlgItem(hwndDlg, CID_UserTab_Callback_EB_Number);
  540. RASSRV_USER_PARAMS * pu =
  541. (RASSRV_USER_PARAMS *)(((PROPSHEETPAGE*)lParam)->lParam);
  542. // Initialize
  543. SendMessage(
  544. hwCb,
  545. EM_SETLIMITTEXT,
  546. sizeof(pu->pszNumber)/2 - 1, 0);
  547. SetWindowLongPtr(
  548. hwndDlg,
  549. GWLP_USERDATA,
  550. (LONG_PTR)pu);
  551. // Display the callback properties
  552. if (!pu->bAdmin && !pu->bCaller)
  553. {
  554. SendMessage(
  555. GetDlgItem(hwndDlg,CID_UserTab_Callback_RB_No),
  556. BM_SETCHECK,BST_CHECKED,
  557. 0);
  558. SetFocus(
  559. GetDlgItem(hwndDlg, CID_UserTab_Callback_RB_No));
  560. }
  561. else if (pu->bCaller)
  562. {
  563. SendMessage(
  564. GetDlgItem(hwndDlg,CID_UserTab_Callback_RB_Caller),
  565. BM_SETCHECK,BST_CHECKED,
  566. 0);
  567. SetFocus(
  568. GetDlgItem(hwndDlg, CID_UserTab_Callback_RB_Caller));
  569. }
  570. else
  571. {
  572. SendMessage(
  573. GetDlgItem(hwndDlg,CID_UserTab_Callback_RB_Admin),
  574. BM_SETCHECK,BST_CHECKED,
  575. 0);
  576. SetFocus(
  577. GetDlgItem(hwndDlg, CID_UserTab_Callback_RB_Admin));
  578. }
  579. SetWindowTextW(hwCb, pu->pszNumber);
  580. EnableWindow(hwCb, !!pu->bAdmin);
  581. }
  582. return TRUE;
  583. case WM_HELP:
  584. case WM_CONTEXTMENU:
  585. {
  586. RasSrvHelp (hwndDlg, uMsg, wParam, lParam, phmCallback);
  587. break;
  588. }
  589. case WM_DESTROY:
  590. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
  591. break;
  592. case WM_NOTIFY:
  593. {
  594. NMHDR* pNotifyData;
  595. NM_LISTVIEW* pLvNotifyData;
  596. pNotifyData = (NMHDR*)lParam;
  597. switch (pNotifyData->code)
  598. {
  599. // The property sheet apply button was pressed
  600. case PSN_APPLY:
  601. return UserTabCallbackApply(hwndDlg);
  602. break;
  603. // The property sheet cancel was pressed
  604. case PSN_RESET:
  605. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  606. break;
  607. }
  608. }
  609. break;
  610. case WM_COMMAND:
  611. switch (wParam)
  612. {
  613. case CID_UserTab_Callback_RB_No:
  614. case CID_UserTab_Callback_RB_Caller:
  615. case CID_UserTab_Callback_RB_Admin:
  616. {
  617. HWND hwndNumber = NULL;
  618. HWND hwndAdmin = NULL;
  619. hwndNumber =
  620. GetDlgItem(hwndDlg, CID_UserTab_Callback_EB_Number);
  621. hwndAdmin =
  622. GetDlgItem(hwndDlg, CID_UserTab_Callback_RB_Admin);
  623. EnableWindow(
  624. hwndNumber,
  625. (BOOL) SendMessage(
  626. hwndAdmin,
  627. BM_GETCHECK,
  628. 0,
  629. 0));
  630. }
  631. break;
  632. }
  633. break;
  634. }
  635. return FALSE;
  636. }
  637. //
  638. // Initializes the user properties dialog procedure.
  639. //
  640. // Return TRUE if focus is set, false otherwise.
  641. //
  642. BOOL
  643. UserTabInitUserPropsDlg(
  644. IN HWND hwndDlg,
  645. IN WPARAM wParam,
  646. IN LPARAM lParam)
  647. {
  648. HWND hwLogon, hwFull, hwPass1, hwPass2, hwOk, hwCancel;
  649. RASSRV_USER_PARAMS * pu =
  650. (RASSRV_USER_PARAMS *)(((PROPSHEETPAGE*)lParam)->lParam);
  651. hwLogon = GetDlgItem(
  652. hwndDlg,
  653. CID_UserTab_New_EB_Username);
  654. hwFull = GetDlgItem(
  655. hwndDlg,
  656. CID_UserTab_New_EB_Fullname);
  657. hwPass1 = GetDlgItem(
  658. hwndDlg,
  659. CID_UserTab_New_EB_Password1);
  660. hwPass2 = GetDlgItem(
  661. hwndDlg,
  662. CID_UserTab_New_EB_Password2);
  663. hwOk = GetDlgItem(
  664. hwndDlg,
  665. IDOK);
  666. hwCancel = GetDlgItem(
  667. hwndDlg,
  668. IDCANCEL);
  669. // Store the parameters with the window handle
  670. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)pu);
  671. // Set limits to the text that can be entered
  672. SendMessage(
  673. hwLogon,
  674. EM_SETLIMITTEXT,
  675. sizeof(pu->pszLogonName)/2 - 2,
  676. 0);
  677. SendMessage(
  678. hwFull,
  679. EM_SETLIMITTEXT,
  680. sizeof(pu->pszFullName)/2 - 2,
  681. 0);
  682. SendMessage(
  683. hwPass1,
  684. EM_SETLIMITTEXT,
  685. sizeof(pu->pszPassword1)/2 - 2 ,
  686. 0);
  687. SendMessage(
  688. hwPass2,
  689. EM_SETLIMITTEXT,
  690. sizeof(pu->pszPassword2)/2 - 2,
  691. 0);
  692. // Fill out the fields
  693. SetWindowTextW(hwLogon, pu->pszLogonName);
  694. SetWindowTextW(hwFull, pu->pszFullName);
  695. SetWindowTextW(hwPass1, pu->pszPassword1);
  696. SetWindowTextW(hwPass2, pu->pszPassword2);
  697. // Don't allow editing of the logon name if user already exists
  698. // Also, don't show the ok and cancel buttons if the user already
  699. // exits (because it's a property sheet with its own buttons)
  700. if (pu->hUser) {
  701. EnableWindow(hwLogon, FALSE);
  702. ShowWindow(hwOk, SW_HIDE);
  703. ShowWindow(hwCancel, SW_HIDE);
  704. }
  705. // Otherwise, we are creating a new user. Change the window
  706. // title to other than "General". Also disable the ok button
  707. // since it will be enabled when a user name is typed in.
  708. else {
  709. PWCHAR pszTitle;
  710. pszTitle = (PWCHAR) PszLoadString (
  711. Globals.hInstDll,
  712. SID_NEWUSER);
  713. SetWindowTextW (hwndDlg, pszTitle);
  714. EnableWindow(hwOk, FALSE);
  715. }
  716. return FALSE;
  717. }
  718. // Dialog procedure that implements the new user
  719. INT_PTR
  720. CALLBACK
  721. UserTabGenUserPropsDlgProc(
  722. HWND hwndDlg,
  723. UINT uMsg,
  724. WPARAM wParam,
  725. LPARAM lParam)
  726. {
  727. switch (uMsg) {
  728. case WM_INITDIALOG:
  729. return UserTabInitUserPropsDlg(hwndDlg, wParam, lParam);
  730. break;
  731. case WM_HELP:
  732. case WM_CONTEXTMENU:
  733. {
  734. RasSrvHelp (hwndDlg, uMsg, wParam, lParam, phmNewUser);
  735. break;
  736. }
  737. case WM_DESTROY:
  738. // Cleanup the work done at WM_INITDIALOG
  739. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
  740. break;
  741. case WM_NOTIFY:
  742. {
  743. NMHDR* pNotifyData;
  744. NM_LISTVIEW* pLvNotifyData;
  745. pNotifyData = (NMHDR*)lParam;
  746. switch (pNotifyData->code) {
  747. // The property sheet apply button was pressed
  748. case PSN_APPLY:
  749. {
  750. RASSRV_USER_PARAMS * pParams;
  751. pParams = (RASSRV_USER_PARAMS *)
  752. GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  753. if (UserTabNewUserParamsOk(hwndDlg, pParams))
  754. {
  755. SetWindowLongPtr(
  756. hwndDlg,
  757. DWLP_MSGRESULT,
  758. PSNRET_NOERROR);
  759. }
  760. else
  761. {
  762. ErrDisplayError(
  763. hwndDlg,
  764. pParams->dwErrorCode,
  765. ERR_USERTAB_CATAGORY,ERR_USERDB_SUBCAT,
  766. 0);
  767. SetWindowLongPtr(
  768. hwndDlg,
  769. DWLP_MSGRESULT,
  770. PSNRET_INVALID_NOCHANGEPAGE);
  771. }
  772. }
  773. return TRUE;
  774. // The property sheet cancel was pressed
  775. case PSN_RESET:
  776. {
  777. RASSRV_USER_PARAMS * pParams;
  778. pParams = (RASSRV_USER_PARAMS *)
  779. GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  780. pParams->bCanceled = TRUE;
  781. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  782. break;
  783. }
  784. }
  785. }
  786. break;
  787. case WM_COMMAND:
  788. // Handle ok being pressed
  789. //
  790. if (wParam == IDOK)
  791. {
  792. RASSRV_USER_PARAMS * pParams;
  793. pParams = (RASSRV_USER_PARAMS *)
  794. GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  795. if (UserTabNewUserParamsOk(hwndDlg, pParams))
  796. {
  797. EndDialog(hwndDlg, 1);
  798. }
  799. else
  800. {
  801. ErrDisplayError(
  802. hwndDlg,
  803. pParams->dwErrorCode,
  804. ERR_USERTAB_CATAGORY,ERR_USERDB_SUBCAT,
  805. 0);
  806. }
  807. }
  808. // And cancel being pressed
  809. else if (wParam == IDCANCEL)
  810. {
  811. EndDialog(hwndDlg, 0);
  812. }
  813. // Notice whether the user name has been updated and
  814. // if so enable/disable the "Ok" button according to
  815. // whether a name has been entered.
  816. if (HIWORD(wParam) == EN_UPDATE)
  817. {
  818. WCHAR pszName[256];
  819. HWND hwndName;
  820. BOOL bEnable = FALSE;
  821. if (CID_UserTab_New_EB_Username == LOWORD(wParam))
  822. {
  823. // Get the current name
  824. hwndName = (HWND)lParam;
  825. pszName[0] = (WCHAR)0;
  826. GetWindowTextW(
  827. hwndName,
  828. pszName,
  829. sizeof(pszName)/sizeof(WCHAR));
  830. // If the length is greater than 1, enable the
  831. // ok button. Otherwise, disable it.
  832. bEnable = pszName[0] != (WCHAR)0;
  833. EnableWindow(GetDlgItem(hwndDlg, IDOK), bEnable);
  834. }
  835. }
  836. break;
  837. }
  838. return FALSE;
  839. }
  840. // Brings up the new user/properties property sheet.
  841. //
  842. // If bNewUser is set, this is a new user, otherwise pUserParams
  843. // contains the pertanent user information.
  844. //
  845. // Returns:
  846. // NO_ERROR on success, pUserParams will be filled in
  847. // ERROR_CANCELLED if cancel was pressed
  848. // win32 error otherwise
  849. //
  850. DWORD
  851. UserTabRaiseProperties (
  852. IN HWND hwndParent,
  853. IN RASSRV_USER_PARAMS * pUserParams)
  854. {
  855. PROPSHEETPAGE Pages[2];
  856. PROPSHEETHEADER Header;
  857. INT_PTR ret;
  858. if (!pUserParams)
  859. return ERROR_INVALID_PARAMETER;
  860. // Initialize
  861. ZeroMemory(&Pages, sizeof(Pages));
  862. ZeroMemory(&Header, sizeof(Header));
  863. // Fill in the values for the general tab
  864. Pages[0].dwSize = sizeof(PROPSHEETPAGE);
  865. Pages[0].hInstance = Globals.hInstDll;
  866. Pages[0].pszTemplate = MAKEINTRESOURCE(DID_UserTab_New);
  867. Pages[0].pfnDlgProc = UserTabGenUserPropsDlgProc;
  868. Pages[0].pfnCallback = NULL;
  869. Pages[0].dwFlags = 0;
  870. Pages[0].lParam = (LPARAM)pUserParams;
  871. // Fill in the values for the callback tab
  872. Pages[1].dwSize = sizeof(PROPSHEETPAGE);
  873. Pages[1].hInstance = Globals.hInstDll;
  874. Pages[1].pszTemplate = MAKEINTRESOURCE(DID_UserTab_Callback);
  875. Pages[1].pfnDlgProc = UserTabCallbackDialogProc;
  876. Pages[1].pfnCallback = NULL;
  877. Pages[1].dwFlags = 0;
  878. Pages[1].lParam = (LPARAM)pUserParams;
  879. // Fill in the values for the header
  880. Header.dwSize = sizeof(Header);
  881. Header.dwFlags = PSH_DEFAULT |
  882. PSH_PROPSHEETPAGE |
  883. PSH_PROPTITLE |
  884. PSH_NOAPPLYNOW;
  885. Header.hwndParent = hwndParent;
  886. Header.hInstance = Globals.hInstDll;
  887. Header.pszCaption = (pUserParams->hUser) ?
  888. pUserParams->pszLogonName :
  889. pUserParams->pszFullName;
  890. Header.nPages = sizeof(Pages) / sizeof(Pages[0]);
  891. Header.ppsp = Pages;
  892. // Popup the dialog box
  893. if ((ret = PropertySheet(&Header)) == -1)
  894. {
  895. return GetLastError();
  896. }
  897. if (pUserParams->bCanceled)
  898. {
  899. return ERROR_CANCELLED;
  900. }
  901. return NO_ERROR;
  902. }
  903. //
  904. // Raises the new user dialog
  905. //
  906. DWORD
  907. UserTabRaiseNewUserDialog(
  908. IN HWND hwndDlg,
  909. IN RASSRV_USER_PARAMS * pParams)
  910. {
  911. PROPSHEETPAGE Pages;
  912. INT_PTR iRet = 0;
  913. if (!pParams)
  914. {
  915. return ERROR_INVALID_PARAMETER;
  916. }
  917. // Initialize
  918. ZeroMemory(&Pages, sizeof(Pages));
  919. Pages.lParam = (LPARAM)pParams;
  920. // Raise the dialog
  921. iRet = DialogBoxParam(
  922. Globals.hInstDll,
  923. MAKEINTRESOURCE(DID_UserTab_New),
  924. hwndDlg,
  925. UserTabGenUserPropsDlgProc,
  926. (LPARAM)&Pages);
  927. if (iRet == -1)
  928. {
  929. return GetLastError();
  930. }
  931. if (iRet == 0)
  932. {
  933. return ERROR_CANCELLED;
  934. }
  935. return NO_ERROR;
  936. }
  937. //
  938. // Handles a request to add a new user
  939. //
  940. DWORD
  941. UserTabHandleNewUserRequest(
  942. IN HWND hwndDlg)
  943. {
  944. RASSRV_USER_PARAMS Params;
  945. DWORD dwErr, dwLength;
  946. HANDLE hUserDatabase = NULL;
  947. HWND hwndLV;
  948. // Initializes the callback properties
  949. Params.hUser = NULL;
  950. UserTabLoadUserProps (&Params);
  951. // Show the new user property sheet
  952. dwErr = UserTabRaiseNewUserDialog(hwndDlg, &Params);
  953. if (dwErr != NO_ERROR)
  954. {
  955. return dwErr;
  956. }
  957. // Flush any changes to the local user database. These can be
  958. // rolled back later with usrRollbackLocalDatabase
  959. RasSrvGetDatabaseHandle(hwndDlg, ID_USER_DATABASE, &hUserDatabase);
  960. // Unencrypt the passwords
  961. dwLength = wcslen(Params.pszPassword1);
  962. UserTabDecryptPassword(Params.pszPassword1, dwLength);
  963. // Make sure you can add the user
  964. dwErr = RasSrvAddUser (
  965. Params.pszLogonName,
  966. Params.pszFullName,
  967. Params.pszPassword1);
  968. UserTabEncryptPassword(Params.pszPassword1, dwLength);
  969. // Figure out whether the user was added successfully
  970. if (dwErr != NO_ERROR)
  971. {
  972. // Clear the passwords from memory
  973. ZeroMemory(Params.pszPassword1, USERTAB_PASSWORD_BUFFER_SIZE);
  974. ZeroMemory(Params.pszPassword2, USERTAB_PASSWORD_BUFFER_SIZE);
  975. switch (dwErr) {
  976. case ERROR_ACCESS_DENIED:
  977. UserTabDisplayError(hwndDlg, ERR_CANT_ADD_USER_ACCESS);
  978. break;
  979. case ERROR_USER_EXISTS:
  980. UserTabDisplayError(hwndDlg, ERR_CANT_ADD_USER_DUPLICATE);
  981. break;
  982. case ERROR_INVALID_PASSWORDNAME:
  983. UserTabDisplayError(hwndDlg, ERR_CANT_ADD_USER_PASSWORD);
  984. break;
  985. default:
  986. UserTabDisplayError(hwndDlg, ERR_CANT_ADD_USER_GENERIC);
  987. }
  988. return dwErr;
  989. }
  990. // Delete the user (since he/she will be added later when the database
  991. // is flushed
  992. RasSrvDeleteUser(Params.pszLogonName);
  993. // Add the user to the database
  994. dwErr = usrAddUser(hUserDatabase, Params.pszLogonName, &(Params.hUser));
  995. if (dwErr == ERROR_ALREADY_EXISTS)
  996. {
  997. UserTabDisplayError(hwndDlg, ERR_CANT_ADD_USER_DUPLICATE);
  998. return dwErr;
  999. }
  1000. if (dwErr != NO_ERROR)
  1001. {
  1002. UserTabDisplayError(hwndDlg, ERR_CANT_ADD_USER_GENERIC);
  1003. return dwErr;
  1004. }
  1005. // Commit the parameters of this user
  1006. if (wcslen(Params.pszFullName) > 0)
  1007. {
  1008. usrSetFullName (Params.hUser, Params.pszFullName);
  1009. }
  1010. if (dwLength > 0)
  1011. {
  1012. UserTabDecryptPassword(Params.pszPassword1, dwLength);
  1013. usrSetPassword (Params.hUser, Params.pszPassword1);
  1014. ZeroMemory(Params.pszPassword1, USERTAB_PASSWORD_BUFFER_SIZE);
  1015. ZeroMemory(Params.pszPassword2, USERTAB_PASSWORD_BUFFER_SIZE);
  1016. }
  1017. UserTabSaveCallbackProps (&Params);
  1018. // Delete all of the old items from the list view
  1019. hwndLV = GetDlgItem(hwndDlg, CID_UserTab_LV_Users);
  1020. if (!ListView_DeleteAllItems(hwndLV))
  1021. {
  1022. UserTabDisplayError(hwndDlg, ERR_GENERIC_CODE);
  1023. return ERR_GENERIC_CODE;
  1024. }
  1025. // Finally, restock the list view
  1026. UserTabFillUserList(hwndLV, hUserDatabase);
  1027. return NO_ERROR;
  1028. }
  1029. DWORD
  1030. UserTabHandleProperties(
  1031. IN HWND hwndDlg,
  1032. IN DWORD dwIndex)
  1033. {
  1034. HANDLE hUser = NULL, hUserDatabase = NULL;
  1035. RASSRV_USER_PARAMS Params, Orig;
  1036. DWORD dwErr = NO_ERROR;
  1037. BOOL bNameChanged;
  1038. // Get a handle to the user in question
  1039. RasSrvGetDatabaseHandle(hwndDlg, ID_USER_DATABASE, &hUserDatabase);
  1040. dwErr = usrGetUserHandle (hUserDatabase, dwIndex, &hUser);
  1041. if (dwErr != NO_ERROR)
  1042. {
  1043. UserTabDisplayError(hwndDlg, ERR_USER_DATABASE_CORRUPT);
  1044. return dwErr;
  1045. }
  1046. // Initializes the callback properties
  1047. Params.hUser = hUser;
  1048. if ((dwErr = UserTabLoadUserProps (&Params)) != NO_ERROR)
  1049. {
  1050. return dwErr;
  1051. }
  1052. CopyMemory(&Orig, &Params, sizeof(Params));
  1053. // Show the user property sheet
  1054. if ((dwErr = UserTabRaiseProperties(hwndDlg, &Params)) != NO_ERROR)
  1055. {
  1056. return dwErr;
  1057. }
  1058. // Commit any changes needed
  1059. UserTabSaveUserProps(&Params, &Orig, &bNameChanged);
  1060. // If the name changed, update the list view
  1061. if (bNameChanged)
  1062. {
  1063. LV_ITEM lvi;
  1064. WCHAR pszDispName[128];
  1065. DWORD dwSize = sizeof(pszDispName);
  1066. HWND hwndLV = GetDlgItem(hwndDlg, CID_UserTab_LV_Users);
  1067. // Initialize the list item
  1068. ZeroMemory(&lvi, sizeof(LV_ITEM));
  1069. lvi.mask = LVIF_TEXT;
  1070. lvi.iItem = dwIndex;
  1071. lvi.pszText = pszDispName;
  1072. usrGetDisplayName(hUser, pszDispName, &dwSize);
  1073. ListView_SetItem(hwndLV, &lvi);
  1074. ListView_RedrawItems(hwndLV, dwIndex, dwIndex);
  1075. }
  1076. return NO_ERROR;
  1077. }
  1078. //
  1079. // Handles the request to delete the user at index dwIndex
  1080. //
  1081. DWORD
  1082. UserTabHandleDeleteUser(
  1083. IN HWND hwndDlg,
  1084. IN DWORD dwIndex)
  1085. {
  1086. WCHAR *pszCapString, pszCaption[512];
  1087. WCHAR *pszTitle, *pszName, pszFullName[128];
  1088. HANDLE hUserDatabase = NULL, hUser = NULL;
  1089. DWORD dwErr= NO_ERROR, dwSize = sizeof(pszFullName);
  1090. HWND hwndLV = NULL;
  1091. INT iRet;
  1092. // Get a handle to the user in question
  1093. RasSrvGetDatabaseHandle(hwndDlg, ID_USER_DATABASE, &hUserDatabase);
  1094. dwErr = usrGetUserHandle (hUserDatabase, dwIndex, &hUser);
  1095. if (dwErr != NO_ERROR)
  1096. {
  1097. UserTabDisplayError(hwndDlg, ERR_USER_DATABASE_CORRUPT);
  1098. return dwErr;
  1099. }
  1100. if ((dwErr = usrGetName(hUser, &pszName)) != NO_ERROR)
  1101. {
  1102. return dwErr;
  1103. }
  1104. if ((dwErr = usrGetFullName(hUser, pszFullName, &dwSize)) != NO_ERROR)
  1105. {
  1106. return dwErr;
  1107. }
  1108. // Load resources
  1109. pszCapString =
  1110. (PWCHAR) PszLoadString (Globals.hInstDll, WRN_DELETE_USER_PERMANENT);
  1111. pszTitle =
  1112. (PWCHAR) PszLoadString (Globals.hInstDll, WRN_TITLE);
  1113. // Format the caption
  1114. if (wcslen(pszFullName))
  1115. wsprintfW(pszCaption, pszCapString, pszFullName);
  1116. else
  1117. wsprintfW(pszCaption, pszCapString, pszName);
  1118. // Advertise the warning
  1119. iRet = MessageBox(
  1120. hwndDlg,
  1121. pszCaption,
  1122. pszTitle,
  1123. MB_YESNO | MB_ICONWARNING);
  1124. if (iRet == IDNO)
  1125. {
  1126. return NO_ERROR;
  1127. }
  1128. // Delete the user
  1129. if ((dwErr = usrDeleteUser(hUserDatabase, dwIndex)) != NO_ERROR)
  1130. {
  1131. UserTabDisplayError(hwndDlg, ERR_CANT_DELETE_USER_GENERAL);
  1132. return dwErr;
  1133. }
  1134. // Remove all items from the list view
  1135. hwndLV = GetDlgItem(hwndDlg, CID_UserTab_LV_Users);
  1136. if (!ListView_DeleteAllItems(hwndLV))
  1137. {
  1138. UserTabDisplayError(hwndDlg, ERR_GENERIC_CODE);
  1139. return ERR_GENERIC_CODE;
  1140. }
  1141. // Finally, restock the list view
  1142. UserTabFillUserList(hwndLV, hUserDatabase);
  1143. return NO_ERROR;
  1144. }
  1145. //
  1146. // Saves the encryption setting
  1147. //
  1148. DWORD
  1149. UserTabSaveEncryption(
  1150. IN HWND hwndDlg)
  1151. {
  1152. HANDLE hUserDatabase = NULL;
  1153. BOOL bEncrypt;
  1154. HWND hwndCtrl;
  1155. // Get reference to the misc database
  1156. RasSrvGetDatabaseHandle(
  1157. hwndDlg,
  1158. ID_USER_DATABASE,
  1159. &hUserDatabase);
  1160. hwndCtrl = GetDlgItem(hwndDlg, CID_UserTab_CB_Encryption);
  1161. if (hwndCtrl != NULL)
  1162. {
  1163. // Get the setting of the checkbox and commit it
  1164. bEncrypt = SendMessage(
  1165. hwndCtrl,
  1166. BM_GETCHECK,
  1167. 0,
  1168. 0) == BST_CHECKED;
  1169. usrSetEncryption(hUserDatabase, bEncrypt);
  1170. }
  1171. return NO_ERROR;
  1172. }
  1173. //
  1174. // Saves the dcc bypass setting
  1175. //
  1176. DWORD
  1177. UserTabSaveBypassDcc(
  1178. IN HWND hwndDlg)
  1179. {
  1180. HANDLE hUserDatabase = NULL;
  1181. BOOL bBypass = FALSE;
  1182. HWND hwndCtrl;
  1183. // Get reference to the misc database
  1184. RasSrvGetDatabaseHandle(
  1185. hwndDlg,
  1186. ID_USER_DATABASE,
  1187. &hUserDatabase);
  1188. hwndCtrl = GetDlgItem(hwndDlg, CID_UserTab_CB_BypassDcc);
  1189. if (hwndCtrl != NULL)
  1190. {
  1191. // Get the setting of the checkbox and commit it
  1192. bBypass = SendMessage(
  1193. hwndCtrl,
  1194. BM_GETCHECK,
  1195. 0,
  1196. 0) == BST_CHECKED;
  1197. usrSetDccBypass(hUserDatabase, bBypass);
  1198. }
  1199. return NO_ERROR;
  1200. }
  1201. //
  1202. // Handles WM_COMMAND messages on the user tab.
  1203. //
  1204. DWORD
  1205. UserTabCommand (
  1206. HWND hwndDlg,
  1207. WPARAM wParam,
  1208. LPARAM lParam)
  1209. {
  1210. DWORD dwIndex;
  1211. dwIndex =
  1212. ListView_GetSelectionMark(
  1213. GetDlgItem(hwndDlg, CID_UserTab_LV_Users));
  1214. switch (wParam) {
  1215. case CID_UserTab_PB_New:
  1216. UserTabHandleNewUserRequest(hwndDlg);
  1217. break;
  1218. case CID_UserTab_PB_Properties:
  1219. dwIndex =
  1220. UserTabHandleProperties(hwndDlg, dwIndex);
  1221. break;
  1222. case CID_UserTab_PB_Delete:
  1223. UserTabHandleDeleteUser(hwndDlg, dwIndex);
  1224. break;
  1225. case CID_UserTab_CB_Encryption:
  1226. UserTabSaveEncryption (hwndDlg);
  1227. break;
  1228. case CID_UserTab_CB_BypassDcc:
  1229. UserTabSaveBypassDcc (hwndDlg);
  1230. break;
  1231. case CID_UserTab_PB_SwitchToMMC:
  1232. if (RassrvWarnMMCSwitch(hwndDlg))
  1233. {
  1234. PropSheet_PressButton(GetParent(hwndDlg), PSBTN_OK);
  1235. RassrvLaunchMMC(RASSRVUI_USERCONSOLE);
  1236. }
  1237. break;
  1238. }
  1239. return NO_ERROR;
  1240. }
  1241. //
  1242. // This dialog procedure responds to messages sent to the
  1243. // user tab.
  1244. //
  1245. INT_PTR
  1246. CALLBACK
  1247. UserTabDialogProc(
  1248. IN HWND hwndDlg,
  1249. IN UINT uMsg,
  1250. IN WPARAM wParam,
  1251. IN LPARAM lParam)
  1252. {
  1253. // Filter the customized list view messages
  1254. if (ListView_OwnerHandler(
  1255. hwndDlg,
  1256. uMsg,
  1257. wParam,
  1258. lParam,
  1259. LvDrawInfoCallback)
  1260. )
  1261. {
  1262. return TRUE;
  1263. }
  1264. // Filter the customized ras server ui page messages.
  1265. // By filtering messages through here, we are able to
  1266. // call RasSrvGetDatabaseHandle below
  1267. if (RasSrvMessageFilter(hwndDlg, uMsg, wParam, lParam))
  1268. {
  1269. return TRUE;
  1270. }
  1271. switch (uMsg)
  1272. {
  1273. case WM_INITDIALOG:
  1274. return FALSE;
  1275. case WM_HELP:
  1276. case WM_CONTEXTMENU:
  1277. {
  1278. RasSrvHelp (hwndDlg, uMsg, wParam, lParam, phmUserTab);
  1279. break;
  1280. }
  1281. case WM_NOTIFY:
  1282. {
  1283. NMHDR* pNotifyData;
  1284. NM_LISTVIEW* pLvNotifyData;
  1285. pNotifyData = (NMHDR*)lParam;
  1286. switch (pNotifyData->code) {
  1287. //
  1288. // Note: PSN_APPLY and PSN_CANCEL are handled
  1289. // by RasSrvMessageFilter
  1290. //
  1291. case PSN_SETACTIVE:
  1292. PropSheet_SetWizButtons(GetParent(hwndDlg), 0);
  1293. if (! GetWindowLongPtr(hwndDlg, GWLP_USERDATA))
  1294. {
  1295. UserTabInitializeDialog(
  1296. hwndDlg,
  1297. wParam,
  1298. lParam);
  1299. SetWindowLongPtr(
  1300. hwndDlg,
  1301. GWLP_USERDATA,
  1302. (LONG_PTR)1);
  1303. }
  1304. PropSheet_SetWizButtons(
  1305. GetParent(hwndDlg),
  1306. PSWIZB_NEXT | PSWIZB_BACK);
  1307. break;
  1308. // The check of an item is changing
  1309. case LVXN_SETCHECK:
  1310. pLvNotifyData = (NM_LISTVIEW*)lParam;
  1311. UserTabHandleUserCheck(
  1312. hwndDlg,
  1313. (DWORD)pLvNotifyData->iItem);
  1314. break;
  1315. case LVXN_DBLCLK:
  1316. pLvNotifyData = (NM_LISTVIEW*)lParam;
  1317. UserTabHandleProperties(
  1318. hwndDlg,
  1319. pLvNotifyData->iItem);
  1320. break;
  1321. }
  1322. }
  1323. break;
  1324. case WM_COMMAND:
  1325. UserTabCommand (hwndDlg, wParam, lParam);
  1326. break;
  1327. // Cleanup the work done at WM_INITDIALOG
  1328. case WM_DESTROY:
  1329. UserTabCleanupDialog(hwndDlg, wParam, lParam);
  1330. break;
  1331. }
  1332. return FALSE;
  1333. }