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.

790 lines
24 KiB

  1. /*++
  2. Copyright (c) 2000,2001 Microsoft Corporation
  3. Module Name:
  4. EDITDLG.CPP
  5. Abstract:
  6. Implementation of the properties dialog which allows the user to create
  7. a new credential or edit an old one.
  8. Author:
  9. Environment:
  10. WinXP
  11. --*/
  12. //////////////////////////////////////////////////////////////////////////////
  13. //
  14. // Include files
  15. //
  16. #include <stdlib.h>
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <winbase.h>
  22. #include <tchar.h>
  23. #include <windns.h>
  24. #include <shellapi.h>
  25. #include <wincrui.h>
  26. #include <htmlhelp.h>
  27. #include <wincred.h>
  28. #include <credp.h>
  29. #include <comctrlp.h>
  30. #include <scuisupp.h>
  31. #include <shfusion.h>
  32. #include "switches.h"
  33. #include "Dlg.h"
  34. #include "Res.h"
  35. #include "KRDlg.h"
  36. #include "keymgr.h"
  37. #include "testaudit.h"
  38. // character length of buffer to contain localized description string for
  39. // the credential being created/edited
  40. #define DESCBUFFERLEN 500
  41. BOOL g_fPswChanged; // password window touched by user
  42. extern BOOL g_fReloadList;
  43. /**********************************************************************
  44. Return the help string associated with the UI element passed by ID
  45. as input.
  46. **********************************************************************/
  47. UINT C_AddKeyDlg::MapID(UINT uiID)
  48. {
  49. switch(uiID)
  50. {
  51. case 1003:
  52. return IDH_CUIUSER;
  53. case 1005:
  54. return IDH_CUIPSW;
  55. case 1010:
  56. return IDH_CUIVIEW;
  57. case IDOK:
  58. return IDH_CLOSE;
  59. case IDCANCEL:
  60. return IDH_DCANCEL;
  61. case IDD_ADDCRED:
  62. return IDH_ADDCRED;
  63. case IDC_TARGET_NAME:
  64. return IDH_TARGETNAME;
  65. case IDC_OLD_PASSWORD:
  66. return IDH_OLDPASSWORD;
  67. case IDC_NEW_PASSWORD:
  68. return IDH_NEWPASSWORD;
  69. case IDC_CONFIRM_PASSWORD:
  70. return IDH_CONFIRM;
  71. case IDD_KEYRING:
  72. return IDH_KEYRING;
  73. case IDC_KEYLIST:
  74. return IDH_KEYLIST;
  75. case IDC_NEWKEY:
  76. return IDH_NEW;
  77. case IDC_EDITKEY:
  78. return IDH_EDIT;
  79. case IDC_DELETEKEY:
  80. return IDH_DELETE;
  81. case IDC_CHANGE_PASSWORD:
  82. return IDH_CHANGEPASSWORD;
  83. default:
  84. return IDS_NOHELP;
  85. }
  86. }
  87. //////////////////////////////////////////////////////////////////////////////
  88. //
  89. // C_AddKeyDlg
  90. //
  91. // Constructor.
  92. //
  93. // parameters:
  94. // hwndParent parent window for the dialog (may be NULL)
  95. // hInstance instance handle of the parent window (may be NULL)
  96. // lIDD dialog template id
  97. // pfnDlgProc pointer to the function that will process messages for
  98. // the dialog. if it is NULL, the default dialog proc
  99. // will be used.
  100. //
  101. // returns:
  102. // Nothing.
  103. //
  104. //////////////////////////////////////////////////////////////////////////////
  105. C_AddKeyDlg::C_AddKeyDlg(
  106. HWND hwndParent,
  107. HINSTANCE hInstance,
  108. LONG lIDD,
  109. DLGPROC pfnDlgProc // = NULL
  110. )
  111. : C_Dlg(hwndParent, hInstance, lIDD, pfnDlgProc)
  112. {
  113. m_hInst = hInstance;
  114. } // C_AddKeyDlg::C_AddKeyDlg
  115. /**********************************************************************
  116. Fill properties dialog fields with values taken from the currently selected
  117. credential.
  118. **********************************************************************/
  119. void
  120. C_AddKeyDlg::EditFillDialog(void)
  121. {
  122. TCHAR szTitle[CRED_MAX_STRING_LENGTH + 1]; // buffer to hold window title string
  123. ASSERT(g_pExistingCred);
  124. if (NULL == g_pExistingCred) return;
  125. // Set up persistence in the UI
  126. g_dwPersist = g_pExistingCred->Persist;
  127. g_dwType = g_pExistingCred->Type;
  128. // Enable the change password stuff only on domain password creds
  129. //
  130. switch (g_pExistingCred->Type)
  131. {
  132. case CRED_TYPE_DOMAIN_PASSWORD:
  133. CHECKPOINT(1,"Keymgr: Edit - Password cred edit");
  134. ShowWindow(m_hwndChgPsw,SW_NORMAL);
  135. ShowWindow(m_hwndPswLbl,SW_NORMAL);
  136. //deliberate fallthrough
  137. case CRED_TYPE_DOMAIN_CERTIFICATE:
  138. CHECKPOINT(2,"keymgr: Edit - Certificate cred edit");
  139. LoadString ( m_hInst, IDS_TITLE, szTitle, 200 );
  140. SendMessage(m_hDlg,WM_SETTEXT,0,(LPARAM) szTitle);
  141. break;
  142. case CRED_TYPE_GENERIC:
  143. // generic cred not supported yet
  144. break;
  145. case CRED_TYPE_DOMAIN_VISIBLE_PASSWORD:
  146. // passport cred should not get this far.
  147. ASSERT(0);
  148. break;
  149. default:
  150. // type data bad
  151. ASSERT(0);
  152. break;
  153. }
  154. // Write targetname to the UI
  155. SendMessage(m_hwndTName, WM_SETTEXT,0,(LPARAM) g_pExistingCred->TargetName);
  156. // Write username to the UI - take directly from the existing cred
  157. if (!Credential_SetUserName(m_hwndCred,g_pExistingCred->UserName))
  158. {
  159. // make a copy of the original username
  160. _tcsncpy(m_szUsername,g_pExistingCred->UserName,CRED_MAX_USERNAME_LENGTH);
  161. m_szUsername[CRED_MAX_USERNAME_LENGTH] = 0;
  162. }
  163. }
  164. /**********************************************************************
  165. Compose the UI string which describes the type and persistence of the
  166. credential being created or edited. Write the text to the text control
  167. on the dialog.
  168. **********************************************************************/
  169. void C_AddKeyDlg::ShowDescriptionText(DWORD dwtype, DWORD Persist)
  170. {
  171. WCHAR szMsg[DESCBUFFERLEN + 1];
  172. WCHAR szTemp[DESCBUFFERLEN + 1];
  173. INT iRem = DESCBUFFERLEN; // remaining space in the buffer
  174. CHECKPOINT(3,"Keymgr: Edit - Show description on prop dialog");
  175. memset(szMsg,0,sizeof(szMsg));
  176. if ((dwtype != CRED_TYPE_DOMAIN_PASSWORD) &&
  177. (dwtype != CRED_TYPE_DOMAIN_CERTIFICATE))
  178. {
  179. // A generic credential - not currently supported
  180. LoadString ( m_hInst, IDS_DESCAPPCRED, szTemp, DESCBUFFERLEN );
  181. wcsncpy(szMsg,szTemp,DESCBUFFERLEN);
  182. szMsg[DESCBUFFERLEN] = 0;
  183. iRem -= wcslen(szMsg);
  184. }
  185. else
  186. {
  187. // a domain-type credential
  188. // Show usage local machine versis domain
  189. if (Persist != CRED_PERSIST_ENTERPRISE)
  190. {
  191. // either local persist or session persist creds show this string
  192. CHECKPOINT(12,L"Keymgr: Edit - Show properties of non-enterprise persist cred");
  193. LoadString ( m_hInst, IDS_DESCLOCAL, szTemp, DESCBUFFERLEN );
  194. }
  195. else
  196. {
  197. // enterprise persistence - if you have a roaming profile, etc...
  198. CHECKPOINT(13,L"Keymgr: Edit - Show properties of enterprise persist cred");
  199. LoadString ( m_hInst, IDS_DESCBASE, szTemp, DESCBUFFERLEN );
  200. }
  201. wcsncpy(szMsg,szTemp,DESCBUFFERLEN);
  202. szMsg[DESCBUFFERLEN] = 0;
  203. iRem -= wcslen(szMsg);
  204. }
  205. // String: until you log off -or- until you delete it
  206. if (Persist == CRED_PERSIST_SESSION)
  207. {
  208. // until you log off
  209. CHECKPOINT(18,L"Keymgr: Edit - Show properties of session cred");
  210. LoadString ( m_hInst, IDS_PERSISTLOGOFF, szTemp, DESCBUFFERLEN );
  211. }
  212. else
  213. {
  214. // until you delete it
  215. CHECKPOINT(19,L"Keymgr: Edit - Show properties of non-session cred");
  216. LoadString ( m_hInst, IDS_PERSISTDELETE, szTemp, DESCBUFFERLEN );
  217. }
  218. iRem -= wcslen(szTemp);
  219. if (0 < iRem) wcsncat(szMsg,szTemp,iRem);
  220. szMsg[DESCBUFFERLEN] = 0;
  221. SendMessage(m_hwndDescription, WM_SETTEXT,0,(LPARAM) szMsg);
  222. return;
  223. }
  224. //////////////////////////////////////////////////////////////////////////////
  225. //
  226. // OnInitDialog
  227. //
  228. // Dialog control and data initialization.
  229. //
  230. // parameters:
  231. // hwndDlg window handle of the dialog box
  232. // hwndFocus window handle of the control that will receive focus
  233. //
  234. // returns:
  235. // TRUE if the system should set the default keyboard focus
  236. // FALSE if the keyboard focus is set by this app
  237. //
  238. //////////////////////////////////////////////////////////////////////////////
  239. BOOL
  240. C_AddKeyDlg::OnInitDialog(
  241. HWND hwndDlg,
  242. HWND hwndFocus
  243. )
  244. {
  245. C_Dlg::OnInitDialog(hwndDlg, hwndFocus);
  246. m_hDlg = hwndDlg;
  247. // get control handles, used for various purposes by other member fns
  248. m_hwndCred = GetDlgItem(m_hDlg,IDC_CRED);
  249. m_hwndTName = GetDlgItem(m_hDlg,IDC_TARGET_NAME);
  250. m_hwndChgPsw = GetDlgItem(m_hDlg,IDC_CHGPSW);
  251. m_hwndPswLbl = GetDlgItem(m_hDlg,IDC_DOMAINPSWLABEL);
  252. m_hwndDescription = GetDlgItem(m_hDlg,IDC_DESCRIPTION);
  253. // Initialize the cred control to show all usable authenticators
  254. if (!Credential_InitStyle(m_hwndCred,CRS_USERNAMES | CRS_CERTIFICATES | CRS_SMARTCARDS))
  255. {
  256. return FALSE;
  257. }
  258. // Establish limits on string lengths from the user
  259. SendMessage(m_hwndTName,EM_LIMITTEXT,CRED_MAX_GENERIC_TARGET_NAME_LENGTH,0);
  260. // Show dummy password for edited credential
  261. if (m_bEdit)
  262. {
  263. Credential_SetPassword(m_hwndCred,L"********");
  264. }
  265. // Set up the allowable persistence options depending on the type of user session
  266. // Set the default persistence unless overriden by a cred read on edit
  267. g_dwType = CRED_TYPE_DOMAIN_PASSWORD;
  268. g_dwPersist = GetPersistenceOptions(CRED_TYPE_DOMAIN_PASSWORD);
  269. // By default, hide all optional controls. These will be enabled as appropriate
  270. ShowWindow(m_hwndChgPsw,SW_HIDE);
  271. ShowWindow(m_hwndPswLbl,SW_HIDE);
  272. // If editing an existing credential, fill dialog fields with existing data
  273. // will also override type and persistence globals
  274. if (m_bEdit)
  275. {
  276. EditFillDialog();
  277. }
  278. g_fPswChanged = FALSE; // password so far unedited
  279. ShowDescriptionText(g_dwType,g_dwPersist);
  280. return TRUE;
  281. // On exit from OnInitDialog, g_szTargetName holds the currently selected
  282. // credential's old name, undecorated (having had a null dropped before
  283. // the suffix)
  284. } // end C_AddKeyDlg::OnInitDialog
  285. /**********************************************************************
  286. Pro forma OnDestroyDialog()
  287. **********************************************************************/
  288. BOOL
  289. C_AddKeyDlg::OnDestroyDialog(
  290. void )
  291. {
  292. return TRUE;
  293. }
  294. //////////////////////////////////////////////////////////////////////////////
  295. //
  296. // OnAppMessage
  297. //
  298. //////////////////////////////////////////////////////////////////////////////
  299. BOOL
  300. C_AddKeyDlg::OnAppMessage(
  301. UINT uMessage,
  302. WPARAM wparam,
  303. LPARAM lparam)
  304. {
  305. return TRUE;
  306. }
  307. /**********************************************************************
  308. On a help request event, get the control ID, map it to a help string,
  309. and present this as a tooltip over the control.
  310. **********************************************************************/
  311. BOOL
  312. C_AddKeyDlg::OnHelpInfo(LPARAM lp)
  313. {
  314. HELPINFO* pH;
  315. INT iMapped;
  316. pH = (HELPINFO *) lp;
  317. HH_POPUP stPopUp;
  318. RECT rcW;
  319. UINT gID;
  320. gID = pH->iCtrlId;
  321. iMapped = MapID(gID);
  322. CHECKPOINT(5,"Keymgr: Edit - Add dialog OnHelpInfo");
  323. if (iMapped == 0) return TRUE;
  324. if (IDS_NOHELP != iMapped)
  325. {
  326. memset(&stPopUp,0,sizeof(stPopUp));
  327. stPopUp.cbStruct = sizeof(HH_POPUP);
  328. stPopUp.hinst = g_hInstance;
  329. stPopUp.idString = iMapped;
  330. stPopUp.pszText = NULL;
  331. stPopUp.clrForeground = -1;
  332. stPopUp.clrBackground = -1;
  333. stPopUp.rcMargins.top = -1;
  334. stPopUp.rcMargins.bottom = -1;
  335. stPopUp.rcMargins.left = -1;
  336. stPopUp.rcMargins.right = -1;
  337. // bug 393244 - leave NULL to allow HHCTRL.OCX to get font information of its own,
  338. // which it needs to perform the UNICODE to multibyte conversion. Otherwise,
  339. // HHCTRL must convert using this font without charset information.
  340. stPopUp.pszFont = NULL;
  341. if (GetWindowRect((HWND)pH->hItemHandle,&rcW))
  342. {
  343. stPopUp.pt.x = (rcW.left + rcW.right) / 2;
  344. stPopUp.pt.y = (rcW.top + rcW.bottom) / 2;
  345. }
  346. else stPopUp.pt = pH->MousePos;
  347. HtmlHelp((HWND) pH->hItemHandle,NULL,HH_DISPLAY_TEXT_POPUP,(DWORD_PTR) &stPopUp);
  348. }
  349. return TRUE;
  350. }
  351. //////////////////////////////////////////////////////////////////////////////
  352. //
  353. // OnCommand
  354. //
  355. // Route WM_COMMAND message to appropriate handlers.
  356. //
  357. // parameters:
  358. // wNotifyCode code describing action that has occured
  359. // wSenderId id of the control sending the message, if the message
  360. // is from a dialog
  361. // hwndSender window handle of the window sending the message if the
  362. // message is not from a dialog
  363. //
  364. // returns:
  365. // TRUE if the message was processed completely
  366. // FALSE if Windows is to process the message
  367. //
  368. ////////////////////////////////////////////////////////////////////////////
  369. BOOL
  370. C_AddKeyDlg::OnCommand(
  371. WORD wNotifyCode,
  372. WORD wSenderId,
  373. HWND hwndSender
  374. )
  375. {
  376. BOOL fHandled = FALSE; // indicate message handled
  377. switch (wSenderId)
  378. {
  379. case IDC_CRED:
  380. {
  381. if (wNotifyCode == CRN_PASSWORDCHANGE)
  382. {
  383. g_fPswChanged = TRUE;
  384. }
  385. }
  386. break;
  387. case IDOK:
  388. if (BN_CLICKED == wNotifyCode)
  389. {
  390. OnOK( );
  391. fHandled = TRUE;
  392. }
  393. break;
  394. case IDC_CHGPSW:
  395. {
  396. OnChangePassword();
  397. //EndDialog(IDCANCEL); do not cancel out of properties dialog
  398. break;
  399. }
  400. case IDCANCEL:
  401. if (BN_CLICKED == wNotifyCode)
  402. {
  403. EndDialog(IDCANCEL);
  404. fHandled = TRUE;
  405. }
  406. break;
  407. } // switch
  408. return fHandled;
  409. } // C_AddKeyDlg::OnCommand
  410. ////////////////////////////////////////////////////////////////////////////
  411. //
  412. // OnOK
  413. //
  414. // Validate user name, synthesize computer name, and destroy dialog.
  415. //
  416. // parameters:
  417. // None.
  418. //
  419. // returns:
  420. // Nothing.
  421. //
  422. //////////////////////////////////////////////////////////////////////////////
  423. void
  424. C_AddKeyDlg::OnOK( )
  425. {
  426. LONG_PTR j,lCType;
  427. TCHAR szMsg[MAX_STRING_SIZE + 1];
  428. TCHAR szTitle[MAX_STRING_SIZE + 1];
  429. TCHAR szUser[FULLNAMEMAXLENGTH + 1]; // in from dialog
  430. TCHAR szPsw[PWLEN + 1]; // in from dialog
  431. TCHAR *pszNewTarget; // in from dialog
  432. TCHAR *pszTrimdName; // mod'd in from dialog
  433. DWORD dwFlags = 0; // in from dialog
  434. CREDENTIAL stCredential; // local copy of cred
  435. UINT cbPassword;
  436. BOOL bResult;
  437. BOOL IsCertificate = FALSE;
  438. BOOL fDeleteOldCred = FALSE;
  439. BOOL fRenameCred = FALSE;
  440. BOOL fPsw = FALSE;
  441. ASSERT(::IsWindow(m_hwnd));
  442. szPsw[0]= 0;
  443. szUser[0] = 0;
  444. // Start with a blank cred if this is not an edit, else make a copy of existing one
  445. if ((m_bEdit) && (g_pExistingCred))
  446. memcpy((void *) &stCredential,(void *) g_pExistingCred,sizeof(CREDENTIAL));
  447. else
  448. memset((void *) &stCredential,0,sizeof(CREDENTIAL));
  449. pszNewTarget = (TCHAR *) malloc((CRED_MAX_GENERIC_TARGET_NAME_LENGTH + 1) * sizeof(TCHAR));
  450. if (NULL == pszNewTarget)
  451. {
  452. return;
  453. }
  454. pszNewTarget[0] = 0;
  455. // Get Username from the cred control - find out if is a certificate by
  456. // IsMarshalledName().
  457. if (Credential_GetUserName(m_hwndCred,szUser,FULLNAMEMAXLENGTH))
  458. {
  459. IsCertificate = CredIsMarshaledCredential(szUser);
  460. }
  461. // fetch password/PIN into szPsw. set fPsw if value is valid
  462. fPsw = Credential_GetPassword(m_hwndCred,szPsw,CRED_MAX_STRING_LENGTH);
  463. // Check to see that both name and psw are not missing
  464. if ( wcslen ( szUser ) == 0 &&
  465. wcslen ( szPsw ) == 0 )
  466. {
  467. LoadString ( m_hInst, IDS_ADDFAILED, szMsg, MAX_STRING_SIZE );
  468. LoadString ( m_hInst, IDS_APP_NAME, szTitle, MAX_STRING_SIZE );
  469. MessageBox ( m_hDlg, szMsg, szTitle, MB_OK );
  470. free(pszNewTarget);
  471. return;
  472. }
  473. // If the user has typed a \\server style target name, strip the leading hacks
  474. j = SendMessage(m_hwndTName,WM_GETTEXT,CRED_MAX_GENERIC_TARGET_NAME_LENGTH,(LPARAM)pszNewTarget);
  475. ASSERT(j);
  476. pszTrimdName = pszNewTarget;
  477. while (*pszTrimdName == TCHAR('\\')) pszTrimdName++;
  478. // Now have:
  479. // pszTrimdName
  480. // uzUser
  481. // szPsw
  482. // fPsw
  483. // If target name edited, will need to rename
  484. // If type changed or psw edited, psw blob will be removed/replaced
  485. // If type changed, will need to remove old cred
  486. if ((m_bEdit) && (g_pExistingCred))
  487. {
  488. CHECKPOINT(4,"Keymgr: Edit - OnOK for add/prop dialog");
  489. if (0 != _tcscmp(pszTrimdName,g_szTargetName)) fRenameCred = TRUE;
  490. // Note that currently DOMAIN_VISIBLE_PASSWORD creds cannot be edited
  491. // or created, so there is no handler for those types.
  492. if (g_pExistingCred->Type == CRED_TYPE_GENERIC)
  493. {
  494. lCType = CRED_TYPE_GENERIC;
  495. }
  496. else
  497. {
  498. if (IsCertificate) lCType = CRED_TYPE_DOMAIN_CERTIFICATE;
  499. else lCType = CRED_TYPE_DOMAIN_PASSWORD;
  500. }
  501. // If the type of the cred changes, you can't save the psw info
  502. if ((DWORD)lCType != g_pExistingCred->Type)
  503. {
  504. dwFlags &= ~CRED_PRESERVE_CREDENTIAL_BLOB;
  505. fDeleteOldCred = TRUE;
  506. }
  507. else
  508. {
  509. dwFlags |= CRED_PRESERVE_CREDENTIAL_BLOB;
  510. }
  511. // You also don't save the psw info if the user changed it explicitly
  512. if (g_fPswChanged)
  513. {
  514. dwFlags &= ~CRED_PRESERVE_CREDENTIAL_BLOB;
  515. }
  516. #if TESTAUDIT
  517. if (dwFlags & CRED_PRESERVE_CREDENTIAL_BLOB)
  518. {
  519. CHECKPOINT(21,L"Keymgr: Edit - Saving a cred preserving the old psw (rename)");
  520. }
  521. else
  522. {
  523. CHECKPOINT(20,L"Keymgr: Edit - Saving a cred while not preserving the old password");
  524. }
  525. #endif
  526. }
  527. else
  528. {
  529. // if is a certificate marshalled name is cert or generic
  530. // if not is generic or domain
  531. if (IsCertificate)
  532. {
  533. lCType = CRED_TYPE_DOMAIN_CERTIFICATE;
  534. }
  535. else
  536. {
  537. lCType = CRED_TYPE_DOMAIN_PASSWORD;
  538. }
  539. }
  540. // Save credential. If certificate type, do not include a psw blob.
  541. // After save, if the name had changed, rename the cred
  542. stCredential.UserName = szUser;
  543. stCredential.Type = (DWORD) lCType;
  544. // If not an edit, fill in targetname, else do rename later
  545. if (!m_bEdit)
  546. {
  547. stCredential.TargetName = pszTrimdName;
  548. }
  549. stCredential.Persist = g_dwPersist;
  550. // fill credential blob data with nothing if the cred control UI has
  551. // disabled the password box. Otherwise supply psw information if
  552. // the user has edited the box contents.
  553. if (fPsw)
  554. {
  555. if (g_fPswChanged)
  556. {
  557. #ifdef LOUDLY
  558. OutputDebugString(L"Storing new password data\n");
  559. #endif
  560. cbPassword = wcslen(szPsw) * sizeof(TCHAR);
  561. stCredential.CredentialBlob = (unsigned char *)szPsw;
  562. stCredential.CredentialBlobSize = cbPassword;
  563. }
  564. #ifdef LOUDLY
  565. else
  566. {
  567. OutputDebugString(L"No password data stored.\n");
  568. }
  569. #endif
  570. }
  571. bResult = CredWrite(&stCredential,dwFlags);
  572. SecureZeroMemory(szPsw,sizeof(szPsw)); // delete psw local copy
  573. if ( bResult != TRUE )
  574. {
  575. #ifdef LOUDLY
  576. WCHAR szw[200];
  577. DWORD dwE = GetLastError();
  578. swprintf(szw,L"CredWrite failed. Last Error is %x\n",dwE);
  579. OutputDebugString(szw);
  580. #endif
  581. AdviseUser();
  582. free(pszNewTarget);
  583. return;
  584. }
  585. // Delete old credential only if type has changed
  586. // Otherwise if name changed, do a rename of the cred
  587. // If the old cred is deleted, rename is obviated
  588. if (fDeleteOldCred)
  589. {
  590. #ifdef LOUDLY
  591. OutputDebugString(L"CredDelete called\n");
  592. #endif
  593. CHECKPOINT(7,"Keymgr: Edit - OnOK - deleting old cred (type changed)");
  594. CredDelete(g_szTargetName,(ULONG) g_pExistingCred->Type,0);
  595. g_fReloadList = TRUE;
  596. }
  597. else if (fRenameCred)
  598. {
  599. CHECKPOINT(8,"Keymgr: Edit - OnOK - renaming current cred, same type");
  600. bResult = CredRename(g_szTargetName, pszTrimdName, (ULONG) stCredential.Type,0);
  601. g_fReloadList = TRUE;
  602. #ifdef LOUDLY
  603. OutputDebugString(L"CredRename called\n");
  604. #endif
  605. if (!bResult)
  606. {
  607. // bugbug: How can rename fail?
  608. // If it does, what would you tell the user?
  609. LoadString ( m_hInst, IDS_RENAMEFAILED, szMsg, MAX_STRING_SIZE );
  610. LoadString ( m_hInst, IDS_APP_NAME, szTitle, MAX_STRING_SIZE );
  611. MessageBox ( m_hDlg, szMsg, szTitle, MB_OK );
  612. free(pszNewTarget);
  613. return;
  614. }
  615. }
  616. #if TESTAUDIT
  617. if (stCredential.Type == CRED_TYPE_DOMAIN_PASSWORD) CHECKPOINT(16,"Keymgr: Edit - Saving password cred");
  618. if (stCredential.Type == CRED_TYPE_DOMAIN_CERTIFICATE) CHECKPOINT(17,"Keymgr: Edit - Saving certificate cred");
  619. #endif
  620. free(pszNewTarget);
  621. EndDialog(IDOK);
  622. } // C_AddKeyDlg::OnOK
  623. /**********************************************************************
  624. **********************************************************************/
  625. void C_AddKeyDlg::OnChangePassword()
  626. {
  627. CHECKPOINT(10,"Keymgr: Edit - Changing password on the domain for the cred");
  628. C_ChangePasswordDlg CPdlg(m_hDlg, g_hInstance, IDD_CHANGEPASSWORD, NULL);
  629. CPdlg.m_szDomain[0] = 0;
  630. CPdlg.m_szUsername[0] = 0;
  631. CPdlg.DoModal((LPARAM)&CPdlg);
  632. }
  633. /**********************************************************************
  634. **********************************************************************/
  635. void C_AddKeyDlg::AdviseUser(void)
  636. {
  637. DWORD dwErr;
  638. TCHAR szMsg[MAX_STRING_SIZE];
  639. TCHAR szTitle[MAX_STRING_SIZE];
  640. dwErr = GetLastError();
  641. CHECKPOINT(11,"Keymgr: Edit - Add/Edit failed: Show error message box to user");
  642. if (dwErr == ERROR_NO_SUCH_LOGON_SESSION)
  643. {
  644. LoadString ( m_hInst, IDS_NOLOGON, szMsg, MAX_STRING_SIZE );
  645. LoadString ( m_hInst, IDS_APP_NAME, szTitle, MAX_STRING_SIZE );
  646. MessageBox ( m_hDlg, szMsg, szTitle, MB_OK );
  647. // return leaving credential dialog up
  648. return;
  649. }
  650. else if (dwErr == ERROR_BAD_USERNAME)
  651. {
  652. LoadString ( m_hInst, IDS_BADUNAME, szMsg, MAX_STRING_SIZE );
  653. LoadString ( m_hInst, IDS_APP_NAME, szTitle, MAX_STRING_SIZE );
  654. MessageBox ( m_hDlg, szMsg, szTitle, MB_OK );
  655. // return leaving credential dialog up
  656. return;
  657. }
  658. else if (dwErr == ERROR_INVALID_PASSWORD)
  659. {
  660. LoadString ( m_hInst, IDS_BADPASSWORD, szMsg, MAX_STRING_SIZE );
  661. LoadString ( m_hInst, IDS_APP_NAME, szTitle, MAX_STRING_SIZE );
  662. MessageBox ( m_hDlg, szMsg, szTitle, MB_OK );
  663. // return leaving credential dialog up
  664. return;
  665. }
  666. else
  667. {
  668. // ERROR_INVALID_PARAMETER, ERROR_INVALID_FLAGS, etc
  669. LoadString ( m_hInst, IDS_ADDFAILED, szMsg, MAX_STRING_SIZE );
  670. LoadString ( m_hInst, IDS_APP_NAME, szTitle, MAX_STRING_SIZE );
  671. MessageBox ( m_hDlg, szMsg, szTitle, MB_OK );
  672. // return leaving credential dialog up
  673. return;
  674. }
  675. }