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.

569 lines
11 KiB

  1. //=============================================================================
  2. // Copyright (c) 2000 Microsoft Corporation
  3. //
  4. // dialogs.hpp
  5. //
  6. // Credential manager user interface classes used to get credentials.
  7. //
  8. // Created 02/29/2000 johnstep (John Stephens)
  9. //=============================================================================
  10. #ifndef __UTILS_HPP__
  11. #define __UTILS_HPP__
  12. #include <wincrypt.h>
  13. #include <cryptui.h>
  14. #include <lm.h>
  15. //
  16. // Determine if the passed in DWORD has precisely one bit set.
  17. //
  18. #define JUST_ONE_BIT( _x ) (((_x) != 0 ) && ( ( (~(_x) + 1) & (_x) ) == (_x) ))
  19. // Singly-linked list Structure for holding a cred awaiting confirmation
  20. typedef struct _CRED_AWAITING_CONFIRMATION
  21. {
  22. WCHAR szTargetName[CRED_MAX_STRING_LENGTH+1+CRED_MAX_STRING_LENGTH + 1];
  23. PCREDENTIAL_TARGET_INFORMATION TargetInfo;
  24. PCREDENTIAL EncodedCredential;
  25. DWORD dwCredWriteFlags;
  26. BOOL DelayCredentialWrite;
  27. void* pNext; // pointer to next cred in list
  28. } CRED_AWAITING_CONFIRMATION;
  29. //-----------------------------------------------------------------------------
  30. // Functions
  31. //-----------------------------------------------------------------------------
  32. BOOL
  33. CreduiIsSpecialCredential(
  34. CREDENTIAL *credential
  35. );
  36. BOOL
  37. CreduiLookupLocalSidFromRid(
  38. DWORD rid,
  39. PSID *sid
  40. );
  41. BOOL
  42. CreduiLookupLocalNameFromRid(
  43. DWORD rid,
  44. LPWSTR *name
  45. );
  46. BOOL
  47. CreduiGetAdministratorsGroupInfo(
  48. LOCALGROUP_MEMBERS_INFO_2 **groupInfo,
  49. DWORD *memberCount
  50. );
  51. BOOL
  52. CreduiIsRemovableCertificate(
  53. CONST CERT_CONTEXT *certContext
  54. );
  55. BOOL
  56. CreduiIsExpiredCertificate(
  57. CONST CERT_CONTEXT *certContext
  58. );
  59. BOOL
  60. CreduiIsClientAuthCertificate(
  61. CONST CERT_CONTEXT *certContext
  62. );
  63. BOOL
  64. CreduiGetCertificateDisplayName(
  65. CONST CERT_CONTEXT *certContext,
  66. WCHAR *displayName,
  67. ULONG displayNameMaxChars,
  68. WCHAR *certificateString,
  69. DWORD dwDisplayType
  70. );
  71. BOOL
  72. CreduiIsWildcardTargetName(
  73. WCHAR *targetName
  74. );
  75. BOOL
  76. CreduiIsPostfixString(
  77. WCHAR *source,
  78. WCHAR *postfix
  79. );
  80. // returns TRUE if pszUserName exists as a substring in pszCredential, FALSE if not
  81. BOOL
  82. LookForUserNameMatch (
  83. const WCHAR * pszUserName,
  84. const WCHAR * pszCredential
  85. );
  86. // copies the marshalled name of pCert into pszMarshalledName.
  87. // pszMarshalledName must be at least CREDUI_MAX_USERNAME_LENGTH in length
  88. //
  89. // returns TRUE if successful, FALSE if not
  90. BOOL
  91. CredUIMarshallNode (
  92. CERT_ENUM * pCert,
  93. WCHAR* pszMarshalledName
  94. );
  95. DWORD
  96. WriteCred(
  97. IN PCWSTR pszTargetName,
  98. IN DWORD Flags,
  99. IN PCREDENTIAL_TARGET_INFORMATION TargetInfo OPTIONAL,
  100. IN PCREDENTIAL Credential,
  101. IN DWORD dwCredWriteFlags,
  102. IN BOOL DelayCredentialWrite,
  103. IN BOOL EncryptedVisiblePassword
  104. );
  105. BOOL AddCredToConfirmationList (
  106. IN PCWSTR pszTargetName,
  107. IN PCREDENTIAL_TARGET_INFORMATION TargetInfo OPTIONAL,
  108. IN PCREDENTIAL Credential,
  109. IN DWORD dwCredWriteFlags,
  110. IN BOOL DelayCredentialWrite
  111. );
  112. DWORD
  113. ConfirmCred (
  114. IN PCWSTR pszTargetName,
  115. IN BOOL bConfirm,
  116. IN BOOL bOkToDelete
  117. );
  118. void CleanUpConfirmationList();
  119. BOOL InitConfirmationList();
  120. BOOL IsDeaultSSORealm ( WCHAR* pszTargetName );
  121. #define MAX_SSO_URL_SIZE 4096
  122. #define SSOBRAND_X_SIZE 320
  123. #define SSOBRAND_Y_SIZE 60
  124. typedef struct _SSOPACKAGE {
  125. WCHAR szBrand[MAX_SSO_URL_SIZE];
  126. WCHAR szURL[MAX_SSO_URL_SIZE];
  127. WCHAR szAttrib[CRED_MAX_STRING_LENGTH];
  128. WCHAR szRegURL[MAX_SSO_URL_SIZE];
  129. WCHAR szHelpURL[MAX_SSO_URL_SIZE];
  130. DWORD dwRegistrationCompleted; // 0 if not completed, 1 if completed
  131. DWORD dwNumRegistrationRuns; // number of times we've prompted for registration
  132. CONST CLSID* pRegistrationWizard; // CLSID of any registration wizard
  133. } SSOPACKAGE;
  134. // Looks in the registry for an SSO entry for the specified package.
  135. // Fills in the SSOPackage struct and returns TRUE if found. Returns
  136. // FALSE if no registry entry found
  137. BOOL
  138. GetSSOPackageInfo (
  139. CREDENTIAL_TARGET_INFORMATION* TargetInfo,
  140. SSOPACKAGE* pSSOStruct
  141. );
  142. // returns TRUE if it was found, with the value copied to pszRealm.
  143. // pszRealm is expected to be at least CREDUI_MAX_DOMAIN_TARGET_LENGTH in length
  144. // returns FALSE if not found
  145. BOOL ReadPassportRealmFromRegistry (
  146. WCHAR* pszRealm );
  147. void GetDeaultSSORealm ( WCHAR* pszTargetName, BOOL bForceLookup = TRUE );
  148. // returns TRUE if a cred is saved for that realm
  149. BOOL CheckForSSOCred( WCHAR* pszTargetRealm );
  150. DWORD EncryptPassword ( PWSTR pszPassword, PVOID* ppszEncryptedPassword, DWORD* pSize );
  151. BOOL IsPasswordEncrypted ( PVOID pPassword, DWORD cbSize );
  152. // Uses GDI+ to load an image as an HBITMAP
  153. HBITMAP LoadImageFromFileViaGdiPlus(
  154. PWSTR pszFileName,
  155. UINT *pcWidth,
  156. UINT *pcHeight);
  157. ///////////////////////////////////////////////////////////////////////////////////////////////
  158. //
  159. // Wincred.h functions
  160. //
  161. // these are local mirrors of the credmgr functions so we can handle downlevel cases properly
  162. //
  163. ///////////////////////////////////////////////////////////////////////////////////////////////
  164. // Prototypes for Whistler functions
  165. typedef
  166. BOOL
  167. (WINAPI
  168. *PFN_CREDWRITEW) (
  169. IN PCREDENTIALW Credential,
  170. IN DWORD Flags
  171. );
  172. typedef
  173. BOOL
  174. (WINAPI
  175. *PFN_CREDREADW) (
  176. IN LPCWSTR TargetName,
  177. IN DWORD Type,
  178. IN DWORD Flags,
  179. OUT PCREDENTIALW *Credential
  180. );
  181. typedef
  182. BOOL
  183. (WINAPI
  184. *PFN_CREDENUMERATEW) (
  185. IN LPCWSTR Filter,
  186. IN DWORD Flags,
  187. OUT DWORD *Count,
  188. OUT PCREDENTIALW **Credential
  189. );
  190. typedef
  191. BOOL
  192. (WINAPI
  193. *PFN_CREDWRITEDOMAINCREDENTIALSW) (
  194. IN PCREDENTIAL_TARGET_INFORMATIONW TargetInfo,
  195. IN PCREDENTIALW Credential,
  196. IN DWORD Flags
  197. );
  198. typedef
  199. BOOL
  200. (WINAPI
  201. *PFN_CREDREADDOMAINCREDENTIALSW) (
  202. IN PCREDENTIAL_TARGET_INFORMATIONW TargetInfo,
  203. IN DWORD Flags,
  204. OUT DWORD *Count,
  205. OUT PCREDENTIALW **Credential
  206. );
  207. typedef
  208. BOOL
  209. (WINAPI
  210. *PFN_CREDDELETEW) (
  211. IN LPCWSTR TargetName,
  212. IN DWORD Type,
  213. IN DWORD Flags
  214. );
  215. typedef
  216. BOOL
  217. (WINAPI
  218. *PFN_CREDRENAMEW) (
  219. IN LPCWSTR OldTargetName,
  220. IN LPCWSTR NewTargetName,
  221. IN DWORD Type,
  222. IN DWORD Flags
  223. );
  224. typedef
  225. BOOL
  226. (WINAPI
  227. *PFN_CREDGETTARGETINFOW) (
  228. IN LPCWSTR TargetName,
  229. IN DWORD Flags,
  230. OUT PCREDENTIAL_TARGET_INFORMATIONW *TargetInfo
  231. );
  232. typedef
  233. BOOL
  234. (WINAPI
  235. *PFN_CREDMARSHALCREDENTIALW) (
  236. IN CRED_MARSHAL_TYPE CredType,
  237. IN PVOID Credential,
  238. OUT LPWSTR *MarshaledCredential
  239. );
  240. typedef
  241. BOOL
  242. (WINAPI
  243. *PFN_CREDUNMARSHALCREDENTIALW) (
  244. IN LPCWSTR MarshaledCredential,
  245. OUT PCRED_MARSHAL_TYPE CredType,
  246. OUT PVOID *Credential
  247. );
  248. typedef
  249. BOOL
  250. (WINAPI
  251. *PFN_CREDISMARSHALEDCREDENTIALW) (
  252. IN LPCWSTR MarshaledCredential
  253. );
  254. typedef
  255. BOOL
  256. (WINAPI
  257. *PFN_CREDISMARSHALEDCREDENTIALA) (
  258. IN LPCSTR MarshaledCredential
  259. );
  260. typedef
  261. BOOL
  262. (WINAPI
  263. *PFN_CREDGETSESSIONTYPES) (
  264. IN DWORD MaximumPersistCount,
  265. OUT LPDWORD MaximumPersist
  266. );
  267. typedef
  268. VOID
  269. (WINAPI
  270. *PFN_CREDFREE) (
  271. IN PVOID Buffer
  272. );
  273. // pointers to Whistler functions
  274. extern BOOL bCredMgrAvailable;
  275. extern PFN_CREDWRITEW pfnCredWriteW;
  276. extern PFN_CREDREADW pfnCredReadW;
  277. extern PFN_CREDENUMERATEW pfnCredEnumerateW;
  278. extern PFN_CREDWRITEDOMAINCREDENTIALSW pfnCredWriteDomainCredentialsW;
  279. extern PFN_CREDREADDOMAINCREDENTIALSW pfnCredReadDomainCredentialsW;
  280. extern PFN_CREDDELETEW pfnCredDeleteW;
  281. extern PFN_CREDRENAMEW pfnCredRenameW;
  282. extern PFN_CREDGETTARGETINFOW pfnCredGetTargetInfoW;
  283. extern PFN_CREDMARSHALCREDENTIALW pfnCredMarshalCredentialW;
  284. extern PFN_CREDUNMARSHALCREDENTIALW pfnCredUnMarshalCredentialW;
  285. extern PFN_CREDISMARSHALEDCREDENTIALW pfnCredIsMarshaledCredentialW;
  286. extern PFN_CREDISMARSHALEDCREDENTIALA pfnCredIsMarshaledCredentialA;
  287. extern PFN_CREDGETSESSIONTYPES pfnCredGetSessionType;
  288. extern PFN_CREDFREE pfnCredFree;
  289. //////
  290. // local functions prototypes
  291. //
  292. BOOL
  293. WINAPI
  294. LocalCredWriteW (
  295. IN PCREDENTIALW Credential,
  296. IN DWORD Flags
  297. );
  298. BOOL
  299. WINAPI
  300. LocalCredReadW (
  301. IN LPCWSTR TargetName,
  302. IN DWORD Type,
  303. IN DWORD Flags,
  304. OUT PCREDENTIALW *Credential
  305. );
  306. BOOL
  307. WINAPI
  308. LocalCredEnumerateW (
  309. IN LPCWSTR Filter,
  310. IN DWORD Flags,
  311. OUT DWORD *Count,
  312. OUT PCREDENTIALW **Credential
  313. );
  314. BOOL
  315. WINAPI
  316. LocalCredWriteDomainCredentialsW (
  317. IN PCREDENTIAL_TARGET_INFORMATIONW TargetInfo,
  318. IN PCREDENTIALW Credential,
  319. IN DWORD Flags
  320. );
  321. BOOL
  322. WINAPI
  323. LocalCredReadDomainCredentialsW (
  324. IN PCREDENTIAL_TARGET_INFORMATIONW TargetInfo,
  325. IN DWORD Flags,
  326. OUT DWORD *Count,
  327. OUT PCREDENTIALW **Credential
  328. );
  329. BOOL
  330. WINAPI
  331. LocalCredDeleteW (
  332. IN LPCWSTR TargetName,
  333. IN DWORD Type,
  334. IN DWORD Flags
  335. );
  336. BOOL
  337. WINAPI
  338. LocalCredRenameW (
  339. IN LPCWSTR OldTargetName,
  340. IN LPCWSTR NewTargetName,
  341. IN DWORD Type,
  342. IN DWORD Flags
  343. );
  344. BOOL
  345. WINAPI
  346. LocalCredGetTargetInfoW (
  347. IN LPCWSTR TargetName,
  348. IN DWORD Flags,
  349. OUT PCREDENTIAL_TARGET_INFORMATIONW *TargetInfo
  350. );
  351. BOOL
  352. WINAPI
  353. LocalCredMarshalCredentialW(
  354. IN CRED_MARSHAL_TYPE CredType,
  355. IN PVOID Credential,
  356. OUT LPWSTR *MarshaledCredential
  357. );
  358. BOOL
  359. WINAPI
  360. LocalCredUnmarshalCredentialW(
  361. IN LPCWSTR MarshaledCredential,
  362. OUT PCRED_MARSHAL_TYPE CredType,
  363. OUT PVOID *Credential
  364. );
  365. BOOL
  366. WINAPI
  367. LocalCredIsMarshaledCredentialW(
  368. IN LPCWSTR MarshaledCredential
  369. );
  370. BOOL
  371. WINAPI
  372. LocalCredIsMarshaledCredentialA(
  373. IN LPCSTR MarshaledCredential
  374. );
  375. BOOL
  376. WINAPI
  377. LocalCredGetSessionTypes (
  378. IN DWORD MaximumPersistCount,
  379. OUT LPDWORD MaximumPersist
  380. );
  381. VOID
  382. WINAPI
  383. LocalCredFree (
  384. IN PVOID Buffer
  385. );
  386. // function to load pointers
  387. BOOL
  388. InitializeCredMgr ();
  389. // function to unload lib
  390. void
  391. UninitializeCredMgr();
  392. VOID
  393. CredPutStdout(
  394. IN LPWSTR String
  395. );
  396. VOID
  397. CredGetStdin(
  398. OUT LPWSTR Buffer,
  399. IN DWORD BufferLength,
  400. IN BOOLEAN EchoChars
  401. );
  402. //=============================================================================
  403. // CreduiIsCapsLockOn
  404. //
  405. // Returns TRUE if the Caps Lock key was on at the time the most recent
  406. // message was posted or FALSE otherwise.
  407. //
  408. // Created 02/27/2000 johnstep (John Stephens)
  409. //=============================================================================
  410. inline
  411. BOOL
  412. CreduiIsCapsLockOn()
  413. {
  414. return (GetKeyState(VK_CAPITAL) & 1) == 1;
  415. }
  416. //
  417. // Type of username
  418. //
  419. typedef enum _CREDUI_USERNAME_TYPE {
  420. CreduiMarshalledUsername, // @@...
  421. CreduiAbsoluteUsername, // <DomainName>\<UserName>
  422. CreduiUpn, // <UserName>@<DnsDomainName>
  423. CreduiRelativeUsername, // <UserName>
  424. } CREDUI_USERNAME_TYPE, *PCREDUI_USERNAME_TYPE;
  425. DWORD
  426. CredUIParseUserNameWithType(
  427. CONST WCHAR *UserName,
  428. WCHAR *user,
  429. ULONG userMaxChars,
  430. WCHAR *domain,
  431. ULONG domainMaxChars,
  432. PCREDUI_USERNAME_TYPE UsernameType
  433. );
  434. LPWSTR
  435. GetAccountDomainName(
  436. VOID
  437. );
  438. BOOL
  439. CompleteUserName(
  440. IN OUT LPWSTR UserName,
  441. IN ULONG UserNameMaxChars,
  442. IN PCREDENTIAL_TARGET_INFORMATIONW TargetInfo OPTIONAL,
  443. IN LPWSTR TargetName OPTIONAL,
  444. IN DWORD Flags
  445. );
  446. BOOL TryLauchRegWizard (
  447. SSOPACKAGE* pSSOPackage,
  448. HWND hwndParent,
  449. BOOL HasLogonSession,
  450. WCHAR *userName,
  451. ULONG userNameMaxChars,
  452. WCHAR *password,
  453. ULONG passwordMaxChars,
  454. DWORD* pResult
  455. );
  456. //-----------------------------------------------------------------------------
  457. #endif // __UTILS_HPP__