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.

195 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 2000,2001 Microsoft Corporation
  3. Module Name:
  4. KRDLG.CPP
  5. Abstract:
  6. Implementation of the dialog behaviors for three application dialogs:
  7. the add/edit credential dialog, the delete credential dialog, and
  8. the password change dialog. These dialogs are derived fom C_Dlg
  9. Password change operates only on credentials of the form
  10. domain\username. Note that changing a password for such a credential
  11. will change the psw for all creds with the same domain\username to
  12. match (this is done by the credential mgr).
  13. Add and Edit use the same dialog, differing in implementation on
  14. the basis of a flag which initializes the two dialogs differently
  15. and causes the edit case to also delete the underlying previous
  16. version of the credential.
  17. Author:
  18. johnhaw 991118 original version created
  19. georgema 000310 modified, removed "gizmo" services, modified
  20. to use the new credential mgr
  21. georgema 000415 modified, use comboboxex to hold icon as well
  22. as user name
  23. georgema 000515 modified to CPL from EXE, smartcard support
  24. added
  25. georgema 000712 modified to use cred control in lieu of combo
  26. and edit boxes for username/password entry.
  27. Delegating smartcard handling to cred ctrl.
  28. Environment:
  29. Win2000
  30. --*/
  31. #pragma comment(user, "Compiled on " __DATE__ " at " __TIME__)
  32. #pragma comment(compiler)
  33. static const char _THIS_FILE_[ ] = __FILE__;
  34. #define KRDLG_CPP
  35. //////////////////////////////////////////////////////////////////////////////
  36. //
  37. // Include files
  38. //
  39. #include <stdlib.h>
  40. #include <nt.h>
  41. #include <ntrtl.h>
  42. #include <nturtl.h>
  43. #include <windows.h>
  44. #include <winbase.h>
  45. #include <tchar.h>
  46. #include <wincrui.h>
  47. #include <wincred.h>
  48. #include <comctrlp.h>
  49. #include <shfusion.h>
  50. #include <lmcons.h>
  51. #include <scuisupp.h>
  52. #include "switches.h"
  53. #include "Dlg.h"
  54. #include "Res.h"
  55. #include "KRDlg.h"
  56. #include "keymgr.h"
  57. #include "testaudit.h"
  58. extern C_KeyringDlg *pDlg;
  59. // Named mutex used to prevent running multiple instances
  60. #define KEYMGRMUTEX (TEXT("KeyMgrMutex"))
  61. //////////////////////////////////////////////////////////////////////////////
  62. //
  63. // DLLMain
  64. //
  65. //
  66. //////////////////////////////////////////////////////////////////////////////
  67. BOOL WINAPI DllMain(HINSTANCE hinstDll,DWORD fdwReason,LPVOID lpvReserved)
  68. {
  69. BOOL bSuccess = TRUE;
  70. switch(fdwReason)
  71. {
  72. case DLL_PROCESS_ATTACH:
  73. CHECKPOINTINIT;
  74. CHECKPOINT(9,"DLL Attach");
  75. SHFusionInitializeFromModuleID(hinstDll,123);
  76. DisableThreadLibraryCalls(hinstDll);
  77. g_hInstance = hinstDll;
  78. ASSERT(g_hInstance);
  79. break;
  80. case DLL_PROCESS_DETACH:
  81. CHECKPOINTFINISH;
  82. SHFusionUninitialize();
  83. break;
  84. }
  85. return bSuccess;
  86. }
  87. /**********************************************************************
  88. Create and show the keyring main dialog. Return -1 (unable to create)
  89. on errors. If creation goes OK, call the DoModal method of the
  90. dialog object.
  91. **********************************************************************/
  92. void WINAPI KRShowKeyMgr(HWND hwParent,HINSTANCE hInstance,LPWSTR pszCmdLine,int nCmdShow)
  93. {
  94. HANDLE hMutex = CreateMutex(NULL,TRUE,KEYMGRMUTEX);
  95. ASSERT(hMutex);
  96. if (NULL == hMutex)
  97. {
  98. return;
  99. }
  100. if (ERROR_ALREADY_EXISTS == GetLastError())
  101. {
  102. // disallow duplicate dialogs
  103. CloseHandle(hMutex);
  104. return;
  105. }
  106. INITCOMMONCONTROLSEX stICC;
  107. BOOL fICC;
  108. stICC.dwSize = sizeof(INITCOMMONCONTROLSEX);
  109. stICC.dwICC = ICC_WIN95_CLASSES | ICC_STANDARD_CLASSES;
  110. fICC = InitCommonControlsEx(&stICC);
  111. // bail if initialization fails
  112. ASSERT(NULL == pDlg);
  113. if (NULL != pDlg)
  114. {
  115. return;
  116. }
  117. if (!CredUIInitControls())
  118. {
  119. return;
  120. }
  121. pDlg = new C_KeyringDlg(hwParent,g_hInstance,IDD_KEYRING,NULL);
  122. // probably out of memory
  123. if (NULL == pDlg)
  124. {
  125. return;
  126. }
  127. pDlg->DoModal((LPARAM) pDlg);
  128. delete pDlg;
  129. pDlg = NULL;
  130. CloseHandle(hMutex);
  131. return;
  132. }
  133. /********************************************************************
  134. Get allowable persistence value for the current logon session given
  135. the type of the credential to be saved. This routine used by both
  136. the main dialog and the edit dialog.
  137. Gets an array of persistence values, one for each cred type, and returns
  138. the value associated with the passed type.
  139. ********************************************************************/
  140. DWORD GetPersistenceOptions(DWORD dwPType)
  141. {
  142. BOOL bResult;
  143. DWORD i[CRED_TYPE_MAXIMUM];
  144. DWORD dwCount = CRED_TYPE_MAXIMUM;
  145. #if DBG
  146. if ((dwPType != CRED_TYPE_DOMAIN_CERTIFICATE) &&
  147. (dwPType != CRED_TYPE_DOMAIN_PASSWORD) &&
  148. (dwPType != CRED_TYPE_DOMAIN_VISIBLE_PASSWORD) &&
  149. (dwPType != CRED_TYPE_GENERIC))
  150. {
  151. ASSERT(0);
  152. }
  153. #endif
  154. bResult = CredGetSessionTypes(dwCount,&i[0]);
  155. if (!bResult)
  156. {
  157. return CRED_PERSIST_NONE;
  158. }
  159. return i[dwPType];
  160. }