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.

499 lines
13 KiB

  1. /*++
  2. Copyright (c) 1989-1997 Microsoft Corporation
  3. Module Name:
  4. nlp.h
  5. Abstract:
  6. NETLOGON private definitions.
  7. Author:
  8. Jim Kelly 11-Apr-1991
  9. Revision History:
  10. Chandana Surlu 21-Jul-96 Stolen from \\kernel\razzle3\src\security\msv1_0\nlp.h
  11. Adam Barr 15-Dec-97 Copied from private\security\msv_sspi
  12. --*/
  13. #ifndef _NLP_
  14. #define _NLP_
  15. #include <windef.h>
  16. #include <winbase.h>
  17. #include <crypt.h>
  18. #include <lmcons.h>
  19. #include <ntsam.h>
  20. #include <ntsamp.h>
  21. #include <logonmsv.h>
  22. #include <samrpc.h>
  23. #include <align.h>
  24. #include <dsgetdc.h>
  25. //
  26. // nlmain.c will #include this file with NLP_ALLOCATE defined.
  27. // That will cause each of these variables to be allocated.
  28. //
  29. #ifdef NLP_ALLOCATE
  30. #define EXTERN
  31. #define INIT(_X) = _X
  32. #else
  33. #define EXTERN extern
  34. #define INIT(_X)
  35. #endif
  36. #define NETLOGON_STARTUP_TIME 900
  37. ///////////////////////////////////////////////////////////////////////////////
  38. // //
  39. // Private data structures //
  40. // //
  41. ///////////////////////////////////////////////////////////////////////////////
  42. //
  43. // Structure used to keep track of all private information related to a
  44. // particular LogonId.
  45. //
  46. typedef struct _PACTIVE_LOGON {
  47. LUID LogonId; // The logon Id of this logon session
  48. ULONG EnumHandle; // The enumeration handle of this logon session
  49. SECURITY_LOGON_TYPE LogonType; // Type of logon (interactive or service)
  50. PSID UserSid; // Sid of the logged on user
  51. UNICODE_STRING UserName; // Name of the logged on user
  52. UNICODE_STRING LogonDomainName; // Name of the domain logged onto
  53. UNICODE_STRING LogonServer; // Name of the server which logged this user on
  54. ULONG Flags; // Attributes of this entry.
  55. #define LOGON_BY_NETLOGON 0x01 // Entry was validated by NETLOGON service
  56. #define LOGON_BY_CACHE 0x02 // Entry was validated by local cache
  57. #define LOGON_BY_OTHER_PACKAGE 0x04 // Entry was validated by another authentication package
  58. #define LOGON_BY_LOCAL 0x08 // Entry was validated by local sam
  59. struct _PACTIVE_LOGON * Next; // Next entry in linked list.
  60. } ACTIVE_LOGON, *PACTIVE_LOGON;
  61. ///////////////////////////////////////////////////////////////////////////////
  62. // //
  63. // CREDENTIAL Related Data Structures //
  64. // //
  65. ///////////////////////////////////////////////////////////////////////////////
  66. //
  67. // Following is a description of the content and format of each type
  68. // of credential maintained by the MsV1_0 authentication package.
  69. //
  70. // The MsV1_0 authentication package defines the following credential
  71. // primary key string values:
  72. //
  73. // "Primary" - Is used to hold the primary credentials provided at
  74. // initial logon time. This includes the username and both
  75. // case-sensitive and case-insensitive forms of the user's
  76. // password.
  77. //
  78. // NOTE: All poitners stored in credentials must be
  79. // changed to be an offset to the body rather than a pointer. This is
  80. // because credential fields are copied by the LSA and so the pointer
  81. // would become invalid.
  82. //
  83. //
  84. // MsV1_0 Primary Credentials
  85. //
  86. //
  87. // The PrimaryKeyValue string of this type of credential contains the
  88. // following string:
  89. //
  90. // "Primary"
  91. //
  92. // The Credential string of a Primary credential contains the following
  93. // values:
  94. //
  95. // o The user's username
  96. //
  97. // o A one-way function of the user's password as typed.
  98. //
  99. // o A one-way function of the user's password upper-cased.
  100. //
  101. // These values are structured as follows:
  102. //
  103. #define MSV1_0_PRIMARY_KEY "Primary"
  104. typedef struct _MSV1_0_PRIMARY_CREDENTIAL {
  105. UNICODE_STRING LogonDomainName;
  106. UNICODE_STRING UserName;
  107. NT_OWF_PASSWORD NtOwfPassword;
  108. LM_OWF_PASSWORD LmOwfPassword;
  109. BOOLEAN NtPasswordPresent;
  110. BOOLEAN LmPasswordPresent;
  111. } MSV1_0_PRIMARY_CREDENTIAL, *PMSV1_0_PRIMARY_CREDENTIAL;
  112. //
  113. // Structure describing a buffer in the clients address space.
  114. //
  115. typedef struct _CLIENT_BUFFER_DESC {
  116. PLSA_CLIENT_REQUEST ClientRequest;
  117. LPBYTE UserBuffer; // Address of buffer in client's address space
  118. LPBYTE MsvBuffer; // Address of mirror buffer in MSV's address space
  119. ULONG StringOffset; // Current offset to variable length data
  120. ULONG TotalSize; // Size (in bytes) of buffer
  121. } CLIENT_BUFFER_DESC, *PCLIENT_BUFFER_DESC;
  122. //
  123. // Structure describing logon information and credential use flags
  124. //
  125. typedef struct _MS_LOGON_CREDENTIAL {
  126. LUID LogonId;
  127. ULONG_PTR CredentialUse;
  128. } MS_LOGON_CREDENTIAL, *PMS_LOGON_CREDENTIAL;
  129. ///////////////////////////////////////////////////////////////////////////////
  130. // //
  131. // Internal routine definitions //
  132. // //
  133. ///////////////////////////////////////////////////////////////////////////////
  134. //
  135. // From nlmain.c.
  136. //
  137. NTSTATUS
  138. NlSamInitialize(
  139. ULONG Timeout
  140. );
  141. //
  142. // From nlp.c.
  143. //
  144. VOID
  145. NlpPutString(
  146. IN PUNICODE_STRING OutString,
  147. IN PUNICODE_STRING InString,
  148. IN PUCHAR *Where
  149. );
  150. VOID
  151. NlpInitClientBuffer(
  152. OUT PCLIENT_BUFFER_DESC ClientBufferDesc,
  153. IN PLSA_CLIENT_REQUEST ClientRequest
  154. );
  155. NTSTATUS
  156. NlpAllocateClientBuffer(
  157. IN OUT PCLIENT_BUFFER_DESC ClientBufferDesc,
  158. IN ULONG FixedSize,
  159. IN ULONG TotalSize
  160. );
  161. NTSTATUS
  162. NlpFlushClientBuffer(
  163. IN OUT PCLIENT_BUFFER_DESC ClientBufferDesc,
  164. OUT PVOID* UserBuffer
  165. );
  166. VOID
  167. NlpFreeClientBuffer(
  168. IN OUT PCLIENT_BUFFER_DESC ClientBufferDesc
  169. );
  170. VOID
  171. NlpPutClientString(
  172. IN OUT PCLIENT_BUFFER_DESC ClientBufferDesc,
  173. IN PUNICODE_STRING OutString,
  174. IN PUNICODE_STRING InString
  175. );
  176. VOID
  177. NlpMakeRelativeString(
  178. IN PUCHAR BaseAddress,
  179. IN OUT PUNICODE_STRING String
  180. );
  181. VOID
  182. NlpRelativeToAbsolute(
  183. IN PVOID BaseAddress,
  184. IN OUT PULONG RelativeValue
  185. );
  186. BOOLEAN
  187. NlpFindActiveLogon(
  188. IN PLUID LogonId,
  189. OUT PACTIVE_LOGON **ActiveLogon
  190. );
  191. ULONG
  192. NlpCountActiveLogon(
  193. IN PUNICODE_STRING LogonDomainName,
  194. IN PUNICODE_STRING UserName
  195. );
  196. NTSTATUS
  197. NlpAllocateInteractiveProfile (
  198. IN PLSA_CLIENT_REQUEST ClientRequest,
  199. OUT PMSV1_0_INTERACTIVE_PROFILE *ProfileBuffer,
  200. OUT PULONG ProfileBufferSize,
  201. IN PNETLOGON_VALIDATION_SAM_INFO2 NlpUser
  202. );
  203. NTSTATUS
  204. NlpAllocateNetworkProfile (
  205. IN PLSA_CLIENT_REQUEST ClientRequest,
  206. OUT PMSV1_0_LM20_LOGON_PROFILE *ProfileBuffer,
  207. OUT PULONG ProfileBufferSize,
  208. IN PNETLOGON_VALIDATION_SAM_INFO2 NlpUser
  209. );
  210. PSID
  211. NlpMakeDomainRelativeSid(
  212. IN PSID DomainId,
  213. IN ULONG RelativeId
  214. );
  215. NTSTATUS
  216. NlpMakeTokenInformationV1(
  217. IN PNETLOGON_VALIDATION_SAM_INFO2 NlpUser,
  218. OUT PLSA_TOKEN_INFORMATION_V1 *TokenInformation
  219. );
  220. NTSTATUS
  221. NlpMakePrimaryCredential(
  222. IN PUNICODE_STRING LogonDomainName,
  223. IN PUNICODE_STRING UserName,
  224. IN PUNICODE_STRING CleartextPassword,
  225. OUT PMSV1_0_PRIMARY_CREDENTIAL *CredentialBuffer,
  226. OUT PULONG CredentialSize,
  227. IN BOOLEAN OwfPasswordProvided
  228. );
  229. NTSTATUS
  230. NlpAddPrimaryCredential(
  231. IN PLUID LogonId,
  232. IN PMSV1_0_PRIMARY_CREDENTIAL Credential,
  233. IN ULONG CredentialSize
  234. );
  235. NTSTATUS
  236. NlpGetPrimaryCredential(
  237. IN PLUID LogonId,
  238. OUT PMSV1_0_PRIMARY_CREDENTIAL *CredentialBuffer,
  239. OUT PULONG CredentialSize
  240. );
  241. NTSTATUS
  242. NlpDeletePrimaryCredential(
  243. IN PLUID LogonId
  244. );
  245. NTSTATUS
  246. NlpChangePassword(
  247. IN PUNICODE_STRING DomainName,
  248. IN PUNICODE_STRING UserName,
  249. IN PLM_OWF_PASSWORD LmOwfPassword,
  250. IN PNT_OWF_PASSWORD NtOwfPassword
  251. );
  252. //
  253. // msvsam.c
  254. //
  255. BOOLEAN
  256. MsvpPasswordValidate (
  257. IN BOOLEAN UasCompatibilityRequired,
  258. IN NETLOGON_LOGON_INFO_CLASS LogonLevel,
  259. IN PVOID LogonInformation,
  260. IN PUSER_INTERNAL1_INFORMATION Passwords,
  261. OUT PULONG UserFlags,
  262. OUT PUSER_SESSION_KEY UserSessionKey,
  263. OUT PLM_SESSION_KEY LmSessionKey
  264. );
  265. //
  266. // nlnetapi.c
  267. //
  268. VOID
  269. NlpLoadNetapiDll (
  270. VOID
  271. );
  272. VOID
  273. NlpLoadNetlogonDll (
  274. VOID
  275. );
  276. //
  277. // subauth.c
  278. //
  279. VOID
  280. Msv1_0SubAuthenticationInitialization(
  281. VOID
  282. );
  283. ///////////////////////////////////////////////////////////////////////
  284. // //
  285. // Global variables //
  286. // //
  287. ///////////////////////////////////////////////////////////////////////
  288. ////////////////////////////////////////////////////////////////////////
  289. // //
  290. // READ ONLY Variables //
  291. // //
  292. ////////////////////////////////////////////////////////////////////////
  293. //
  294. // Null copies of Lanman and NT OWF password.
  295. //
  296. //
  297. EXTERN LM_OWF_PASSWORD NlpNullLmOwfPassword;
  298. EXTERN NT_OWF_PASSWORD NlpNullNtOwfPassword;
  299. //
  300. // Routines in NetApi32.dll
  301. //
  302. EXTERN BOOLEAN NlpNetapiDllLoaded;
  303. EXTERN NET_API_STATUS (NET_API_FUNCTION *NlpNetApiBufferFree)(LPVOID);
  304. EXTERN NET_API_STATUS (NET_API_FUNCTION *NlpRxNetUserPasswordSet)(LPWSTR, LPWSTR, LPWSTR, LPWSTR);
  305. EXTERN NET_API_STATUS (NET_API_FUNCTION *NlpDsGetDcName)(LPCWSTR, LPCWSTR, GUID *, LPCWSTR, ULONG, PDOMAIN_CONTROLLER_INFOW *);
  306. EXTERN NTSTATUS (*NlpNetpApiStatusToNtStatus)( NET_API_STATUS );
  307. //
  308. // Routines in netlogon.dll
  309. //
  310. EXTERN HANDLE NlpNetlogonDllHandle;
  311. EXTERN PNETLOGON_SAM_LOGON_PROCEDURE NlpNetLogonSamLogon;
  312. EXTERN PNETLOGON_SAM_LOGOFF_PROCEDURE NlpNetLogonSamLogoff;
  313. //
  314. // TRUE if package is initialized
  315. //
  316. EXTERN BOOLEAN NlpMsvInitialized INIT(FALSE);
  317. //
  318. // TRUE if this is a workstation.
  319. //
  320. EXTERN BOOLEAN NlpWorkstation INIT(TRUE);
  321. //
  322. // TRUE once the MSV AP has initialized its connection to SAM.
  323. //
  324. EXTERN BOOLEAN NlpSamInitialized INIT(FALSE);
  325. //
  326. // TRUE if the MSV AP has initialized its connection to the NETLOGON service
  327. //
  328. EXTERN BOOLEAN NlpNetlogonInitialized INIT(FALSE);
  329. //
  330. // TRUE if LanMan is installed.
  331. //
  332. EXTERN BOOLEAN NlpLanmanInstalled INIT(FALSE);
  333. //
  334. // Computername of this computer.
  335. //
  336. EXTERN UNICODE_STRING NlpComputerName;
  337. //
  338. // Name and domain id of the SAM account database.
  339. //
  340. EXTERN UNICODE_STRING NlpSamDomainName;
  341. EXTERN PSID NlpSamDomainId;
  342. EXTERN SAMPR_HANDLE NlpSamDomainHandle;
  343. EXTERN BOOLEAN NlpUasCompatibilityRequired INIT(TRUE);
  344. //
  345. // Trusted Handle to the Lsa database.
  346. //
  347. EXTERN LSA_HANDLE NlpPolicyHandle INIT(NULL);
  348. ////////////////////////////////////////////////////////////////////////
  349. // //
  350. // READ/WRITE Variables //
  351. // //
  352. ////////////////////////////////////////////////////////////////////////
  353. //
  354. // Define the list of active interactive logons.
  355. //
  356. // The NlpActiveLogonLock must be locked while referencing the list or
  357. // any of its elements.
  358. //
  359. #define NlpLockActiveLogons() RtlEnterCriticalSection(&NlpActiveLogonLock)
  360. #define NlpUnlockActiveLogons() RtlLeaveCriticalSection(&NlpActiveLogonLock)
  361. EXTERN RTL_CRITICAL_SECTION NlpActiveLogonLock;
  362. EXTERN PACTIVE_LOGON NlpActiveLogons;
  363. //
  364. // Define the running enumeration handle.
  365. //
  366. // This variable defines the enumeration handle to assign to a logon
  367. // session. It will be incremented prior to assigning it value to
  368. // the next created logon session. Access is serialize using
  369. // NlpActiveLogonLocks.
  370. EXTERN ULONG NlpEnumerationHandle;
  371. //
  372. // Define a running Session Number which is incremented once for each
  373. // challenge given to the server.
  374. //
  375. EXTERN RTL_CRITICAL_SECTION NlpSessionCountLock;
  376. EXTERN ULONG NlpSessionCount;
  377. EXTERN ULONG NlpLogonAttemptCount;
  378. #undef EXTERN
  379. #undef INIT
  380. #endif _NLP_