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.

1052 lines
27 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. wincred.h
  5. Abstract:
  6. This module contains the public data structures and API definitions
  7. needed for the Credential Manager.
  8. Author:
  9. Cliff Van Dyke (CliffV) 11-January-2000
  10. Revision History:
  11. --*/
  12. #ifndef _WINCRED_H_
  13. #define _WINCRED_H_
  14. #if !defined(_ADVAPI32_)
  15. #define WINADVAPI DECLSPEC_IMPORT
  16. #else
  17. #define WINADVAPI
  18. #endif
  19. #if !defined(CREDUIAPI)
  20. #if !defined(_CREDUI_)
  21. #define CREDUIAPI DECLSPEC_IMPORT
  22. #else
  23. #define CREDUIAPI
  24. #endif
  25. #endif
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. //
  30. // Ensure PCtxtHandle is defined
  31. //
  32. #ifndef __SECHANDLE_DEFINED__
  33. typedef struct _SecHandle
  34. {
  35. ULONG_PTR dwLower ;
  36. ULONG_PTR dwUpper ;
  37. } SecHandle, * PSecHandle ;
  38. #define __SECHANDLE_DEFINED__
  39. #endif // __SECHANDLE_DEFINED__
  40. typedef PSecHandle PCtxtHandle;
  41. //
  42. // Ensure FILETIME is defined
  43. //
  44. #ifndef _WINBASE_
  45. #ifndef _FILETIME_
  46. #define _FILETIME_
  47. typedef struct _FILETIME
  48. {
  49. DWORD dwLowDateTime;
  50. DWORD dwHighDateTime;
  51. } FILETIME;
  52. typedef struct _FILETIME *PFILETIME;
  53. typedef struct _FILETIME *LPFILETIME;
  54. #endif // !_FILETIME
  55. #endif // _WINBASE_
  56. //
  57. // Ensure NTSTATUS is defined
  58. //
  59. #ifndef _NTDEF_
  60. typedef LONG NTSTATUS, *PNTSTATUS;
  61. #endif
  62. //-----------------------------------------------------------------------------
  63. // Macros
  64. //-----------------------------------------------------------------------------
  65. //
  66. // Macro to determine whether CredUIPromptForCredentials should be called upon a failed
  67. // authentication attempt.
  68. //
  69. // Implemented as a macro so that the caller can delay load credui.dll only if this
  70. // macro returns TRUE.
  71. //
  72. // Include only status codes that imply the username/password are wrong or that the
  73. // password is expired. In the former case, asking for a another username or password
  74. // is appropriate. In the later case, we put up a different dialog asking the
  75. // user to change the password on the server.
  76. //
  77. // Don't include status codes such as ERROR_ACCOUNT_DISABLED, ERROR_ACCOUNT_RESTRICTION,
  78. // ERROR_ACCOUNT_LOCKED_OUT, ERROR_ACCOUNT_EXPIRED, ERROR_LOGON_TYPE_NOT_GRANTED.
  79. // For those, the user isn't going to have another account so prompting him
  80. // won't help.
  81. //
  82. // STATUS_DOWNGRADE_DETECTED is included to handle the case where a corporate laptop
  83. // is brought to another LAN. A downgrade attack will indeed be detected,
  84. // but we want to popup UI to allow the user to connect to resources in the
  85. // other LAN.
  86. //
  87. // Don't use the CREDUIP_* macros directly. Their definition is private to credui.dll.
  88. //
  89. // Don't require ntstatus.h
  90. #define STATUS_LOGON_FAILURE ((NTSTATUS)0xC000006DL) // ntsubauth
  91. #define STATUS_WRONG_PASSWORD ((NTSTATUS)0xC000006AL) // ntsubauth
  92. #define STATUS_PASSWORD_EXPIRED ((NTSTATUS)0xC0000071L) // ntsubauth
  93. #define STATUS_PASSWORD_MUST_CHANGE ((NTSTATUS)0xC0000224L) // ntsubauth
  94. #define STATUS_ACCESS_DENIED ((NTSTATUS)0xC0000022L)
  95. #define STATUS_DOWNGRADE_DETECTED ((NTSTATUS)0xC0000388L)
  96. #define STATUS_AUTHENTICATION_FIREWALL_FAILED ((NTSTATUS)0xC0000413L)
  97. #define STATUS_ACCOUNT_DISABLED ((NTSTATUS)0xC0000072L) // ntsubauth
  98. #define STATUS_ACCOUNT_RESTRICTION ((NTSTATUS)0xC000006EL) // ntsubauth
  99. #define STATUS_ACCOUNT_LOCKED_OUT ((NTSTATUS)0xC0000234L) // ntsubauth
  100. #define STATUS_ACCOUNT_EXPIRED ((NTSTATUS)0xC0000193L) // ntsubauth
  101. #define STATUS_LOGON_TYPE_NOT_GRANTED ((NTSTATUS)0xC000015BL)
  102. // Don't require lmerr.h
  103. #define NERR_BASE 2100
  104. #define NERR_PasswordExpired (NERR_BASE+142) /* The password of this user has expired. */
  105. #define CREDUIP_IS_USER_PASSWORD_ERROR( _Status ) ( \
  106. (_Status) == ERROR_LOGON_FAILURE || \
  107. (_Status) == HRESULT_FROM_WIN32( ERROR_LOGON_FAILURE ) || \
  108. (_Status) == STATUS_LOGON_FAILURE || \
  109. (_Status) == HRESULT_FROM_NT( STATUS_LOGON_FAILURE ) || \
  110. (_Status) == ERROR_ACCESS_DENIED || \
  111. (_Status) == HRESULT_FROM_WIN32( ERROR_ACCESS_DENIED ) || \
  112. (_Status) == STATUS_ACCESS_DENIED || \
  113. (_Status) == HRESULT_FROM_NT( STATUS_ACCESS_DENIED ) || \
  114. (_Status) == ERROR_INVALID_PASSWORD || \
  115. (_Status) == HRESULT_FROM_WIN32( ERROR_INVALID_PASSWORD ) || \
  116. (_Status) == STATUS_WRONG_PASSWORD || \
  117. (_Status) == HRESULT_FROM_NT( STATUS_WRONG_PASSWORD ) || \
  118. (_Status) == SEC_E_NO_CREDENTIALS || \
  119. (_Status) == SEC_E_LOGON_DENIED \
  120. )
  121. #define CREDUIP_IS_DOWNGRADE_ERROR( _Status ) ( \
  122. (_Status) == ERROR_DOWNGRADE_DETECTED || \
  123. (_Status) == HRESULT_FROM_WIN32( ERROR_DOWNGRADE_DETECTED ) || \
  124. (_Status) == STATUS_DOWNGRADE_DETECTED || \
  125. (_Status) == HRESULT_FROM_NT( STATUS_DOWNGRADE_DETECTED ) \
  126. )
  127. #define CREDUIP_IS_EXPIRED_ERROR( _Status ) ( \
  128. (_Status) == ERROR_PASSWORD_EXPIRED || \
  129. (_Status) == HRESULT_FROM_WIN32( ERROR_PASSWORD_EXPIRED ) || \
  130. (_Status) == STATUS_PASSWORD_EXPIRED || \
  131. (_Status) == HRESULT_FROM_NT( STATUS_PASSWORD_EXPIRED ) || \
  132. (_Status) == ERROR_PASSWORD_MUST_CHANGE || \
  133. (_Status) == HRESULT_FROM_WIN32( ERROR_PASSWORD_MUST_CHANGE ) || \
  134. (_Status) == STATUS_PASSWORD_MUST_CHANGE || \
  135. (_Status) == HRESULT_FROM_NT( STATUS_PASSWORD_MUST_CHANGE ) || \
  136. (_Status) == NERR_PasswordExpired || \
  137. (_Status) == HRESULT_FROM_WIN32( NERR_PasswordExpired ) \
  138. )
  139. #define CREDUI_IS_AUTHENTICATION_ERROR( _Status ) ( \
  140. CREDUIP_IS_USER_PASSWORD_ERROR( _Status ) || \
  141. CREDUIP_IS_DOWNGRADE_ERROR( _Status ) || \
  142. CREDUIP_IS_EXPIRED_ERROR( _Status ) \
  143. )
  144. #define CREDUI_NO_PROMPT_AUTHENTICATION_ERROR( _Status ) ( \
  145. (_Status) == ERROR_AUTHENTICATION_FIREWALL_FAILED || \
  146. (_Status) == HRESULT_FROM_WIN32( ERROR_AUTHENTICATION_FIREWALL_FAILED ) || \
  147. (_Status) == STATUS_AUTHENTICATION_FIREWALL_FAILED || \
  148. (_Status) == HRESULT_FROM_NT( STATUS_AUTHENTICATION_FIREWALL_FAILED ) || \
  149. (_Status) == ERROR_ACCOUNT_DISABLED || \
  150. (_Status) == HRESULT_FROM_WIN32( ERROR_ACCOUNT_DISABLED ) || \
  151. (_Status) == STATUS_ACCOUNT_DISABLED || \
  152. (_Status) == HRESULT_FROM_NT( STATUS_ACCOUNT_DISABLED ) || \
  153. (_Status) == ERROR_ACCOUNT_RESTRICTION || \
  154. (_Status) == HRESULT_FROM_WIN32( ERROR_ACCOUNT_RESTRICTION ) || \
  155. (_Status) == STATUS_ACCOUNT_RESTRICTION || \
  156. (_Status) == HRESULT_FROM_NT( STATUS_ACCOUNT_RESTRICTION ) || \
  157. (_Status) == ERROR_ACCOUNT_LOCKED_OUT || \
  158. (_Status) == HRESULT_FROM_WIN32( ERROR_ACCOUNT_LOCKED_OUT ) || \
  159. (_Status) == STATUS_ACCOUNT_LOCKED_OUT || \
  160. (_Status) == HRESULT_FROM_NT( STATUS_ACCOUNT_LOCKED_OUT ) || \
  161. (_Status) == ERROR_ACCOUNT_EXPIRED || \
  162. (_Status) == HRESULT_FROM_WIN32( ERROR_ACCOUNT_EXPIRED ) || \
  163. (_Status) == STATUS_ACCOUNT_EXPIRED || \
  164. (_Status) == HRESULT_FROM_NT( STATUS_ACCOUNT_EXPIRED ) || \
  165. (_Status) == ERROR_LOGON_TYPE_NOT_GRANTED || \
  166. (_Status) == HRESULT_FROM_WIN32( ERROR_LOGON_TYPE_NOT_GRANTED ) || \
  167. (_Status) == STATUS_LOGON_TYPE_NOT_GRANTED || \
  168. (_Status) == HRESULT_FROM_NT( STATUS_LOGON_TYPE_NOT_GRANTED ) \
  169. )
  170. //-----------------------------------------------------------------------------
  171. // Structures
  172. //-----------------------------------------------------------------------------
  173. //
  174. // Credential Attribute
  175. //
  176. // Maximum length of the various credential string fields (in characters)
  177. #define CRED_MAX_STRING_LENGTH 256
  178. // Maximum length of the UserName field. The worst case is <User>@<DnsDomain>
  179. #define CRED_MAX_USERNAME_LENGTH (256+1+256)
  180. // Maximum length of the TargetName field for CRED_TYPE_GENERIC (in characters)
  181. #define CRED_MAX_GENERIC_TARGET_NAME_LENGTH 32767
  182. // Maximum length of the TargetName field for CRED_TYPE_DOMAIN_* (in characters)
  183. // Largest one is <DfsRoot>\<DfsShare>
  184. #define CRED_MAX_DOMAIN_TARGET_NAME_LENGTH (256+1+80)
  185. // Maximum size of the Credential Attribute Value field (in bytes)
  186. #define CRED_MAX_VALUE_SIZE 256
  187. // Maximum number of attributes per credential
  188. #define CRED_MAX_ATTRIBUTES 64
  189. typedef struct _CREDENTIAL_ATTRIBUTEA {
  190. LPSTR Keyword;
  191. DWORD Flags;
  192. DWORD ValueSize;
  193. LPBYTE Value;
  194. } CREDENTIAL_ATTRIBUTEA, *PCREDENTIAL_ATTRIBUTEA;
  195. typedef struct _CREDENTIAL_ATTRIBUTEW {
  196. #ifdef MIDL_PASS
  197. [string] wchar_t * Keyword;
  198. #else // MIDL_PASS
  199. LPWSTR Keyword;
  200. #endif // MIDL_PASS
  201. DWORD Flags;
  202. #ifdef MIDL_PASS
  203. [range(0,CRED_MAX_VALUE_SIZE)]
  204. #endif // MIDL_PASS
  205. DWORD ValueSize;
  206. #ifdef MIDL_PASS
  207. [size_is(ValueSize)]
  208. #endif // MIDL_PASS
  209. LPBYTE Value;
  210. } CREDENTIAL_ATTRIBUTEW, *PCREDENTIAL_ATTRIBUTEW;
  211. #ifdef UNICODE
  212. typedef CREDENTIAL_ATTRIBUTEW CREDENTIAL_ATTRIBUTE;
  213. typedef PCREDENTIAL_ATTRIBUTEW PCREDENTIAL_ATTRIBUTE;
  214. #else
  215. typedef CREDENTIAL_ATTRIBUTEA CREDENTIAL_ATTRIBUTE;
  216. typedef PCREDENTIAL_ATTRIBUTEA PCREDENTIAL_ATTRIBUTE;
  217. #endif // UNICODE
  218. //
  219. // Special values of the TargetName field
  220. //
  221. #define CRED_SESSION_WILDCARD_NAME_W L"*Session"
  222. #define CRED_SESSION_WILDCARD_NAME_A "*Session"
  223. #define CRED_SESSION_WILDCARD_NAME_LENGTH (sizeof(CRED_SESSION_WILDCARD_NAME_A)-1)
  224. #ifdef UNICODE
  225. #define CRED_SESSION_WILDCARD_NAME CRED_SESSION_WILDCARD_NAME_W
  226. #else
  227. #define CRED_SESSION_WILDCARD_NAME CRED_SESSION_WILDCARD_NAME_A
  228. #endif // UNICODE
  229. //
  230. // Values of the Credential Flags field.
  231. //
  232. #define CRED_FLAGS_PASSWORD_FOR_CERT 0x0001
  233. #define CRED_FLAGS_PROMPT_NOW 0x0002
  234. #define CRED_FLAGS_USERNAME_TARGET 0x0004
  235. #define CRED_FLAGS_OWF_CRED_BLOB 0x0008
  236. #define CRED_FLAGS_VALID_FLAGS 0x000F // Mask of all valid flags
  237. //
  238. // Values of the Credential Type field.
  239. //
  240. #define CRED_TYPE_GENERIC 1
  241. #define CRED_TYPE_DOMAIN_PASSWORD 2
  242. #define CRED_TYPE_DOMAIN_CERTIFICATE 3
  243. #define CRED_TYPE_DOMAIN_VISIBLE_PASSWORD 4
  244. #define CRED_TYPE_MAXIMUM 5 // Maximum supported cred type
  245. #define CRED_TYPE_MAXIMUM_EX (CRED_TYPE_MAXIMUM+1000) // Allow new applications to run on old OSes
  246. //
  247. // Maximum size of the CredBlob field (in bytes)
  248. //
  249. #define CRED_MAX_CREDENTIAL_BLOB_SIZE 512
  250. //
  251. // Values of the Credential Persist field
  252. //
  253. #define CRED_PERSIST_NONE 0
  254. #define CRED_PERSIST_SESSION 1
  255. #define CRED_PERSIST_LOCAL_MACHINE 2
  256. #define CRED_PERSIST_ENTERPRISE 3
  257. //
  258. // A credential
  259. //
  260. typedef struct _CREDENTIALA {
  261. DWORD Flags;
  262. DWORD Type;
  263. LPSTR TargetName;
  264. LPSTR Comment;
  265. FILETIME LastWritten;
  266. DWORD CredentialBlobSize;
  267. LPBYTE CredentialBlob;
  268. DWORD Persist;
  269. DWORD AttributeCount;
  270. PCREDENTIAL_ATTRIBUTEA Attributes;
  271. LPSTR TargetAlias;
  272. LPSTR UserName;
  273. } CREDENTIALA, *PCREDENTIALA;
  274. typedef struct _CREDENTIALW {
  275. DWORD Flags;
  276. DWORD Type;
  277. #ifdef MIDL_PASS
  278. [string] wchar_t *TargetName;
  279. #else // MIDL_PASS
  280. LPWSTR TargetName;
  281. #endif // MIDL_PASS
  282. #ifdef MIDL_PASS
  283. [string] wchar_t *Comment;
  284. #else // MIDL_PASS
  285. LPWSTR Comment;
  286. #endif // MIDL_PASS
  287. FILETIME LastWritten;
  288. #ifdef MIDL_PASS
  289. [range(0,CRED_MAX_CREDENTIAL_BLOB_SIZE)]
  290. #endif // MIDL_PASS
  291. DWORD CredentialBlobSize;
  292. #ifdef MIDL_PASS
  293. [size_is(CredentialBlobSize)]
  294. #endif // MIDL_PASS
  295. LPBYTE CredentialBlob;
  296. DWORD Persist;
  297. #ifdef MIDL_PASS
  298. [range(0,CRED_MAX_ATTRIBUTES)]
  299. #endif // MIDL_PASS
  300. DWORD AttributeCount;
  301. #ifdef MIDL_PASS
  302. [size_is(AttributeCount)]
  303. #endif // MIDL_PASS
  304. PCREDENTIAL_ATTRIBUTEW Attributes;
  305. #ifdef MIDL_PASS
  306. [string] wchar_t *TargetAlias;
  307. #else // MIDL_PASS
  308. LPWSTR TargetAlias;
  309. #endif // MIDL_PASS
  310. #ifdef MIDL_PASS
  311. [string] wchar_t *UserName;
  312. #else // MIDL_PASS
  313. LPWSTR UserName;
  314. #endif // MIDL_PASS
  315. } CREDENTIALW, *PCREDENTIALW;
  316. #ifdef UNICODE
  317. typedef CREDENTIALW CREDENTIAL;
  318. typedef PCREDENTIALW PCREDENTIAL;
  319. #else
  320. typedef CREDENTIALA CREDENTIAL;
  321. typedef PCREDENTIALA PCREDENTIAL;
  322. #endif // UNICODE
  323. //
  324. // Value of the Flags field in CREDENTIAL_TARGET_INFORMATION
  325. //
  326. #define CRED_TI_SERVER_FORMAT_UNKNOWN 0x0001 // Don't know if server name is DNS or netbios format
  327. #define CRED_TI_DOMAIN_FORMAT_UNKNOWN 0x0002 // Don't know if domain name is DNS or netbios format
  328. #define CRED_TI_ONLY_PASSWORD_REQUIRED 0x0004 // Server only requires a password and not a username
  329. #define CRED_TI_USERNAME_TARGET 0x0008 // TargetName is username
  330. #define CRED_TI_CREATE_EXPLICIT_CRED 0x0010 // When creating a cred, create one named TargetInfo->TargetName
  331. #define CRED_TI_WORKGROUP_MEMBER 0x0020 // Indicates the machine is a member of a workgroup
  332. #define CRED_TI_VALID_FLAGS 0x003F
  333. //
  334. // A credential target
  335. //
  336. typedef struct _CREDENTIAL_TARGET_INFORMATIONA {
  337. LPSTR TargetName;
  338. LPSTR NetbiosServerName;
  339. LPSTR DnsServerName;
  340. LPSTR NetbiosDomainName;
  341. LPSTR DnsDomainName;
  342. LPSTR DnsTreeName;
  343. LPSTR PackageName;
  344. ULONG Flags;
  345. DWORD CredTypeCount;
  346. LPDWORD CredTypes;
  347. } CREDENTIAL_TARGET_INFORMATIONA, *PCREDENTIAL_TARGET_INFORMATIONA;
  348. typedef struct _CREDENTIAL_TARGET_INFORMATIONW {
  349. #ifdef MIDL_PASS
  350. [string] wchar_t *TargetName;
  351. [string] wchar_t *NetbiosServerName;
  352. [string] wchar_t *DnsServerName;
  353. [string] wchar_t *NetbiosDomainName;
  354. [string] wchar_t *DnsDomainName;
  355. [string] wchar_t *DnsTreeName;
  356. [string] wchar_t *PackageName;
  357. #else // MIDL_PASS
  358. LPWSTR TargetName;
  359. LPWSTR NetbiosServerName;
  360. LPWSTR DnsServerName;
  361. LPWSTR NetbiosDomainName;
  362. LPWSTR DnsDomainName;
  363. LPWSTR DnsTreeName;
  364. LPWSTR PackageName;
  365. #endif // MIDL_PASS
  366. ULONG Flags;
  367. #ifdef MIDL_PASS
  368. [range(0,CRED_TYPE_MAXIMUM_EX)]
  369. #endif // MIDL_PASS
  370. DWORD CredTypeCount;
  371. #ifdef MIDL_PASS
  372. [size_is(CredTypeCount)]
  373. #endif // MIDL_PASS
  374. LPDWORD CredTypes;
  375. } CREDENTIAL_TARGET_INFORMATIONW, *PCREDENTIAL_TARGET_INFORMATIONW;
  376. #ifdef UNICODE
  377. typedef CREDENTIAL_TARGET_INFORMATIONW CREDENTIAL_TARGET_INFORMATION;
  378. typedef PCREDENTIAL_TARGET_INFORMATIONW PCREDENTIAL_TARGET_INFORMATION;
  379. #else
  380. typedef CREDENTIAL_TARGET_INFORMATIONA CREDENTIAL_TARGET_INFORMATION;
  381. typedef PCREDENTIAL_TARGET_INFORMATIONA PCREDENTIAL_TARGET_INFORMATION;
  382. #endif // UNICODE
  383. //
  384. // Certificate credential information
  385. //
  386. // The cbSize should be the size of the structure, sizeof(CERT_CREDENTIAL_INFO),
  387. // rgbHashofCert is the hash of the cert which is to be used as the credential.
  388. //
  389. #define CERT_HASH_LENGTH 20 // SHA1 hashes are used for cert hashes
  390. typedef struct _CERT_CREDENTIAL_INFO {
  391. ULONG cbSize;
  392. UCHAR rgbHashOfCert[CERT_HASH_LENGTH];
  393. } CERT_CREDENTIAL_INFO, *PCERT_CREDENTIAL_INFO;
  394. //
  395. // Username Target credential information
  396. //
  397. // This credential can be pass to LsaLogonUser to ask it to find a credential with a
  398. // TargetName of UserName.
  399. //
  400. typedef struct _USERNAME_TARGET_CREDENTIAL_INFO {
  401. LPWSTR UserName;
  402. } USERNAME_TARGET_CREDENTIAL_INFO, *PUSERNAME_TARGET_CREDENTIAL_INFO;
  403. //
  404. // Credential type for credential marshaling routines
  405. //
  406. typedef enum _CRED_MARSHAL_TYPE {
  407. CertCredential = 1,
  408. UsernameTargetCredential
  409. } CRED_MARSHAL_TYPE, *PCRED_MARSHAL_TYPE;
  410. //
  411. // Credential UI info
  412. //
  413. typedef struct _CREDUI_INFOA
  414. {
  415. DWORD cbSize;
  416. HWND hwndParent;
  417. PCSTR pszMessageText;
  418. PCSTR pszCaptionText;
  419. HBITMAP hbmBanner;
  420. } CREDUI_INFOA, *PCREDUI_INFOA;
  421. typedef struct _CREDUI_INFOW
  422. {
  423. DWORD cbSize;
  424. HWND hwndParent;
  425. PCWSTR pszMessageText;
  426. PCWSTR pszCaptionText;
  427. HBITMAP hbmBanner;
  428. } CREDUI_INFOW, *PCREDUI_INFOW;
  429. #ifdef UNICODE
  430. typedef CREDUI_INFOW CREDUI_INFO;
  431. typedef PCREDUI_INFOW PCREDUI_INFO;
  432. #else
  433. typedef CREDUI_INFOA CREDUI_INFO;
  434. typedef PCREDUI_INFOA PCREDUI_INFO;
  435. #endif
  436. //-----------------------------------------------------------------------------
  437. // Values
  438. //-----------------------------------------------------------------------------
  439. // String length limits:
  440. #define CREDUI_MAX_MESSAGE_LENGTH 32767
  441. #define CREDUI_MAX_CAPTION_LENGTH 128
  442. #define CREDUI_MAX_GENERIC_TARGET_LENGTH CRED_MAX_GENERIC_TARGET_NAME_LENGTH
  443. #define CREDUI_MAX_DOMAIN_TARGET_LENGTH CRED_MAX_DOMAIN_TARGET_NAME_LENGTH
  444. #define CREDUI_MAX_USERNAME_LENGTH CRED_MAX_USERNAME_LENGTH
  445. #define CREDUI_MAX_PASSWORD_LENGTH (CRED_MAX_CREDENTIAL_BLOB_SIZE / 2)
  446. //
  447. // Flags for CredUIPromptForCredentials and/or CredUICmdLinePromptForCredentials
  448. //
  449. #define CREDUI_FLAGS_INCORRECT_PASSWORD 0x00001 // indicates the username is valid, but password is not
  450. #define CREDUI_FLAGS_DO_NOT_PERSIST 0x00002 // Do not show "Save" checkbox, and do not persist credentials
  451. #define CREDUI_FLAGS_REQUEST_ADMINISTRATOR 0x00004 // Populate list box with admin accounts
  452. #define CREDUI_FLAGS_EXCLUDE_CERTIFICATES 0x00008 // do not include certificates in the drop list
  453. #define CREDUI_FLAGS_REQUIRE_CERTIFICATE 0x00010
  454. #define CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX 0x00040
  455. #define CREDUI_FLAGS_ALWAYS_SHOW_UI 0x00080
  456. #define CREDUI_FLAGS_REQUIRE_SMARTCARD 0x00100
  457. #define CREDUI_FLAGS_PASSWORD_ONLY_OK 0x00200
  458. #define CREDUI_FLAGS_VALIDATE_USERNAME 0x00400
  459. #define CREDUI_FLAGS_COMPLETE_USERNAME 0x00800 //
  460. #define CREDUI_FLAGS_PERSIST 0x01000 // Do not show "Save" checkbox, but persist credentials anyway
  461. #define CREDUI_FLAGS_SERVER_CREDENTIAL 0x04000
  462. #define CREDUI_FLAGS_EXPECT_CONFIRMATION 0x20000 // do not persist unless caller later confirms credential via CredUIConfirmCredential() api
  463. #define CREDUI_FLAGS_GENERIC_CREDENTIALS 0x40000 // Credential is a generic credential
  464. #define CREDUI_FLAGS_USERNAME_TARGET_CREDENTIALS 0x80000 // Credential has a username as the target
  465. #define CREDUI_FLAGS_KEEP_USERNAME 0x100000 // don't allow the user to change the supplied username
  466. //
  467. // Mask of flags valid for CredUIPromptForCredentials
  468. //
  469. #define CREDUI_FLAGS_PROMPT_VALID ( \
  470. CREDUI_FLAGS_INCORRECT_PASSWORD | \
  471. CREDUI_FLAGS_DO_NOT_PERSIST | \
  472. CREDUI_FLAGS_REQUEST_ADMINISTRATOR | \
  473. CREDUI_FLAGS_EXCLUDE_CERTIFICATES | \
  474. CREDUI_FLAGS_REQUIRE_CERTIFICATE | \
  475. CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX | \
  476. CREDUI_FLAGS_ALWAYS_SHOW_UI | \
  477. CREDUI_FLAGS_REQUIRE_SMARTCARD | \
  478. CREDUI_FLAGS_PASSWORD_ONLY_OK | \
  479. CREDUI_FLAGS_VALIDATE_USERNAME | \
  480. CREDUI_FLAGS_COMPLETE_USERNAME | \
  481. CREDUI_FLAGS_PERSIST | \
  482. CREDUI_FLAGS_SERVER_CREDENTIAL | \
  483. CREDUI_FLAGS_EXPECT_CONFIRMATION | \
  484. CREDUI_FLAGS_GENERIC_CREDENTIALS | \
  485. CREDUI_FLAGS_USERNAME_TARGET_CREDENTIALS | \
  486. CREDUI_FLAGS_KEEP_USERNAME )
  487. //-----------------------------------------------------------------------------
  488. // Functions
  489. //-----------------------------------------------------------------------------
  490. //
  491. // Values of flags to CredWrite and CredWriteDomainCredentials
  492. //
  493. #define CRED_PRESERVE_CREDENTIAL_BLOB 0x1
  494. WINADVAPI
  495. BOOL
  496. WINAPI
  497. CredWriteW (
  498. IN PCREDENTIALW Credential,
  499. IN DWORD Flags
  500. );
  501. WINADVAPI
  502. BOOL
  503. WINAPI
  504. CredWriteA (
  505. IN PCREDENTIALA Credential,
  506. IN DWORD Flags
  507. );
  508. #ifdef UNICODE
  509. #define CredWrite CredWriteW
  510. #else
  511. #define CredWrite CredWriteA
  512. #endif // UNICODE
  513. WINADVAPI
  514. BOOL
  515. WINAPI
  516. CredReadW (
  517. IN LPCWSTR TargetName,
  518. IN DWORD Type,
  519. IN DWORD Flags,
  520. OUT PCREDENTIALW *Credential
  521. );
  522. WINADVAPI
  523. BOOL
  524. WINAPI
  525. CredReadA (
  526. IN LPCSTR TargetName,
  527. IN DWORD Type,
  528. IN DWORD Flags,
  529. OUT PCREDENTIALA *Credential
  530. );
  531. #ifdef UNICODE
  532. #define CredRead CredReadW
  533. #else
  534. #define CredRead CredReadA
  535. #endif // UNICODE
  536. WINADVAPI
  537. BOOL
  538. WINAPI
  539. CredEnumerateW (
  540. IN LPCWSTR Filter,
  541. IN DWORD Flags,
  542. OUT DWORD *Count,
  543. OUT PCREDENTIALW **Credential
  544. );
  545. WINADVAPI
  546. BOOL
  547. WINAPI
  548. CredEnumerateA (
  549. IN LPCSTR Filter,
  550. IN DWORD Flags,
  551. OUT DWORD *Count,
  552. OUT PCREDENTIALA **Credential
  553. );
  554. #ifdef UNICODE
  555. #define CredEnumerate CredEnumerateW
  556. #else
  557. #define CredEnumerate CredEnumerateA
  558. #endif // UNICODE
  559. WINADVAPI
  560. BOOL
  561. WINAPI
  562. CredWriteDomainCredentialsW (
  563. IN PCREDENTIAL_TARGET_INFORMATIONW TargetInfo,
  564. IN PCREDENTIALW Credential,
  565. IN DWORD Flags
  566. );
  567. WINADVAPI
  568. BOOL
  569. WINAPI
  570. CredWriteDomainCredentialsA (
  571. IN PCREDENTIAL_TARGET_INFORMATIONA TargetInfo,
  572. IN PCREDENTIALA Credential,
  573. IN DWORD Flags
  574. );
  575. #ifdef UNICODE
  576. #define CredWriteDomainCredentials CredWriteDomainCredentialsW
  577. #else
  578. #define CredWriteDomainCredentials CredWriteDomainCredentialsA
  579. #endif // UNICODE
  580. //
  581. // Values of flags to CredReadDomainCredentials
  582. //
  583. #define CRED_CACHE_TARGET_INFORMATION 0x1
  584. WINADVAPI
  585. BOOL
  586. WINAPI
  587. CredReadDomainCredentialsW (
  588. IN PCREDENTIAL_TARGET_INFORMATIONW TargetInfo,
  589. IN DWORD Flags,
  590. OUT DWORD *Count,
  591. OUT PCREDENTIALW **Credential
  592. );
  593. WINADVAPI
  594. BOOL
  595. WINAPI
  596. CredReadDomainCredentialsA (
  597. IN PCREDENTIAL_TARGET_INFORMATIONA TargetInfo,
  598. IN DWORD Flags,
  599. OUT DWORD *Count,
  600. OUT PCREDENTIALA **Credential
  601. );
  602. #ifdef UNICODE
  603. #define CredReadDomainCredentials CredReadDomainCredentialsW
  604. #else
  605. #define CredReadDomainCredentials CredReadDomainCredentialsA
  606. #endif // UNICODE
  607. WINADVAPI
  608. BOOL
  609. WINAPI
  610. CredDeleteW (
  611. IN LPCWSTR TargetName,
  612. IN DWORD Type,
  613. IN DWORD Flags
  614. );
  615. WINADVAPI
  616. BOOL
  617. WINAPI
  618. CredDeleteA (
  619. IN LPCSTR TargetName,
  620. IN DWORD Type,
  621. IN DWORD Flags
  622. );
  623. #ifdef UNICODE
  624. #define CredDelete CredDeleteW
  625. #else
  626. #define CredDelete CredDeleteA
  627. #endif // UNICODE
  628. WINADVAPI
  629. BOOL
  630. WINAPI
  631. CredRenameW (
  632. IN LPCWSTR OldTargetName,
  633. IN LPCWSTR NewTargetName,
  634. IN DWORD Type,
  635. IN DWORD Flags
  636. );
  637. WINADVAPI
  638. BOOL
  639. WINAPI
  640. CredRenameA (
  641. IN LPCSTR OldTargetName,
  642. IN LPCSTR NewTargetName,
  643. IN DWORD Type,
  644. IN DWORD Flags
  645. );
  646. #ifdef UNICODE
  647. #define CredRename CredRenameW
  648. #else
  649. #define CredRename CredRenameA
  650. #endif // UNICODE
  651. //
  652. // Values of flags to CredGetTargetInfo
  653. //
  654. #define CRED_ALLOW_NAME_RESOLUTION 0x1
  655. WINADVAPI
  656. BOOL
  657. WINAPI
  658. CredGetTargetInfoW (
  659. IN LPCWSTR TargetName,
  660. IN DWORD Flags,
  661. OUT PCREDENTIAL_TARGET_INFORMATIONW *TargetInfo
  662. );
  663. WINADVAPI
  664. BOOL
  665. WINAPI
  666. CredGetTargetInfoA (
  667. IN LPCSTR TargetName,
  668. IN DWORD Flags,
  669. OUT PCREDENTIAL_TARGET_INFORMATIONA *TargetInfo
  670. );
  671. #ifdef UNICODE
  672. #define CredGetTargetInfo CredGetTargetInfoW
  673. #else
  674. #define CredGetTargetInfo CredGetTargetInfoA
  675. #endif // UNICODE
  676. WINADVAPI
  677. BOOL
  678. WINAPI
  679. CredMarshalCredentialW(
  680. IN CRED_MARSHAL_TYPE CredType,
  681. IN PVOID Credential,
  682. OUT LPWSTR *MarshaledCredential
  683. );
  684. WINADVAPI
  685. BOOL
  686. WINAPI
  687. CredMarshalCredentialA(
  688. IN CRED_MARSHAL_TYPE CredType,
  689. IN PVOID Credential,
  690. OUT LPSTR *MarshaledCredential
  691. );
  692. #ifdef UNICODE
  693. #define CredMarshalCredential CredMarshalCredentialW
  694. #else
  695. #define CredMarshalCredential CredMarshalCredentialA
  696. #endif // UNICODE
  697. WINADVAPI
  698. BOOL
  699. WINAPI
  700. CredUnmarshalCredentialW(
  701. IN LPCWSTR MarshaledCredential,
  702. OUT PCRED_MARSHAL_TYPE CredType,
  703. OUT PVOID *Credential
  704. );
  705. WINADVAPI
  706. BOOL
  707. WINAPI
  708. CredUnmarshalCredentialA(
  709. IN LPCSTR MarshaledCredential,
  710. OUT PCRED_MARSHAL_TYPE CredType,
  711. OUT PVOID *Credential
  712. );
  713. #ifdef UNICODE
  714. #define CredUnmarshalCredential CredUnmarshalCredentialW
  715. #else
  716. #define CredUnmarshalCredential CredUnmarshalCredentialA
  717. #endif // UNICODE
  718. WINADVAPI
  719. BOOL
  720. WINAPI
  721. CredIsMarshaledCredentialW(
  722. IN LPCWSTR MarshaledCredential
  723. );
  724. WINADVAPI
  725. BOOL
  726. WINAPI
  727. CredIsMarshaledCredentialA(
  728. IN LPCSTR MarshaledCredential
  729. );
  730. #ifdef UNICODE
  731. #define CredIsMarshaledCredential CredIsMarshaledCredentialW
  732. #else
  733. #define CredIsMarshaledCredential CredIsMarshaledCredentialA
  734. #endif // UNICODE
  735. WINADVAPI
  736. BOOL
  737. WINAPI
  738. CredGetSessionTypes (
  739. IN DWORD MaximumPersistCount,
  740. OUT LPDWORD MaximumPersist
  741. );
  742. WINADVAPI
  743. VOID
  744. WINAPI
  745. CredFree (
  746. IN PVOID Buffer
  747. );
  748. CREDUIAPI
  749. DWORD
  750. WINAPI
  751. CredUIPromptForCredentialsW(
  752. PCREDUI_INFOW pUiInfo,
  753. PCWSTR pszTargetName,
  754. PCtxtHandle pContext,
  755. DWORD dwAuthError,
  756. PWSTR pszUserName,
  757. ULONG ulUserNameBufferSize,
  758. PWSTR pszPassword,
  759. ULONG ulPasswordBufferSize,
  760. BOOL *save,
  761. DWORD dwFlags
  762. );
  763. CREDUIAPI
  764. DWORD
  765. WINAPI
  766. CredUIPromptForCredentialsA(
  767. PCREDUI_INFOA pUiInfo,
  768. PCSTR pszTargetName,
  769. PCtxtHandle pContext,
  770. DWORD dwAuthError,
  771. PSTR pszUserName,
  772. ULONG ulUserNameBufferSize,
  773. PSTR pszPassword,
  774. ULONG ulPasswordBufferSize,
  775. BOOL *save,
  776. DWORD dwFlags
  777. );
  778. #ifdef UNICODE
  779. #define CredUIPromptForCredentials CredUIPromptForCredentialsW
  780. #else
  781. #define CredUIPromptForCredentials CredUIPromptForCredentialsA
  782. #endif
  783. CREDUIAPI
  784. DWORD
  785. WINAPI
  786. CredUIParseUserNameW(
  787. PCWSTR pszUserName,
  788. PWSTR pszUser,
  789. ULONG ulUserBufferSize,
  790. PWSTR pszDomain,
  791. ULONG ulDomainBufferSize
  792. );
  793. CREDUIAPI
  794. DWORD
  795. WINAPI
  796. CredUIParseUserNameA(
  797. PCSTR pszUserName,
  798. PSTR pszUser,
  799. ULONG ulUserBufferSize,
  800. PSTR pszDomain,
  801. ULONG ulDomainBufferSize
  802. );
  803. #ifdef UNICODE
  804. #define CredUIParseUserName CredUIParseUserNameW
  805. #else
  806. #define CredUIParseUserName CredUIParseUserNameA
  807. #endif
  808. CREDUIAPI
  809. DWORD
  810. WINAPI
  811. CredUICmdLinePromptForCredentialsW(
  812. PCWSTR pszTargetName,
  813. PCtxtHandle pContext,
  814. DWORD dwAuthError,
  815. PWSTR UserName,
  816. ULONG ulUserBufferSize,
  817. PWSTR pszPassword,
  818. ULONG ulPasswordBufferSize,
  819. PBOOL pfSave,
  820. DWORD dwFlags
  821. );
  822. CREDUIAPI
  823. DWORD
  824. WINAPI
  825. CredUICmdLinePromptForCredentialsA(
  826. PCSTR pszTargetName,
  827. PCtxtHandle pContext,
  828. DWORD dwAuthError,
  829. PSTR UserName,
  830. ULONG ulUserBufferSize,
  831. PSTR pszPassword,
  832. ULONG ulPasswordBufferSize,
  833. PBOOL pfSave,
  834. DWORD dwFlags
  835. );
  836. #ifdef UNICODE
  837. #define CredUICmdLinePromptForCredentials CredUICmdLinePromptForCredentialsW
  838. #else
  839. #define CredUICmdLinePromptForCredentials CredUICmdLinePromptForCredentialsA
  840. #endif
  841. //
  842. // Call this API with bConfirm set to TRUE to confirm that the credential (previously created
  843. // via CredUIGetCredentials or CredUIPromptForCredentials worked, or with bConfirm set to FALSE
  844. // to indicate it didn't
  845. CREDUIAPI
  846. DWORD
  847. WINAPI
  848. CredUIConfirmCredentialsW(
  849. PCWSTR pszTargetName,
  850. BOOL bConfirm
  851. );
  852. CREDUIAPI
  853. DWORD
  854. WINAPI
  855. CredUIConfirmCredentialsA(
  856. PCSTR pszTargetName,
  857. BOOL bConfirm
  858. );
  859. #ifdef UNICODE
  860. #define CredUIConfirmCredentials CredUIConfirmCredentialsW
  861. #else
  862. #define CredUIConfirmCredentials CredUIConfirmCredentialsA
  863. #endif
  864. CREDUIAPI
  865. DWORD
  866. WINAPI
  867. CredUIStoreSSOCredW (
  868. PCWSTR pszRealm,
  869. PCWSTR pszUsername,
  870. PCWSTR pszPassword,
  871. BOOL bPersist
  872. );
  873. CREDUIAPI
  874. DWORD
  875. WINAPI
  876. CredUIReadSSOCredW (
  877. PCWSTR pszRealm,
  878. PWSTR* ppszUsername
  879. );
  880. #ifdef __cplusplus
  881. }
  882. #endif
  883. #endif // _WINCRED_H_