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.

472 lines
15 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. msp.h
  5. Abstract:
  6. MSV1_0 authentication package private definitions.
  7. Author:
  8. Jim Kelly 11-Apr-1991
  9. Revision History:
  10. Scott Field (sfield) 05-Oct-98 Add NTLM3
  11. Scott Field (sfield) 15-Jan-98 Add MspNtDeriveCredential
  12. Chandana Surlu 21-Jul-96 Stolen from \\kernel\razzle3\src\security\msv1_0\msv1_0.c
  13. --*/
  14. #ifndef _MSP_
  15. #define _MSP_
  16. #if ( _MSC_VER >= 800 )
  17. #pragma warning ( 3 : 4100 ) // enable "Unreferenced formal parameter"
  18. #pragma warning ( 3 : 4219 ) // enable "trailing ',' used for variable argument list"
  19. #endif
  20. #include <nt.h>
  21. #include <ntrtl.h>
  22. #include <nturtl.h>
  23. #include <crypt.h>
  24. #include <ntmsv1_0.h>
  25. #include <windows.h>
  26. #ifndef SECURITY_WIN32
  27. #define SECURITY_WIN32
  28. #endif // SECURITY_WIN32
  29. #define SECURITY_PACKAGE
  30. #define SECURITY_NTLM
  31. #include <security.h>
  32. #include <secint.h>
  33. ///////////////////////////////////////////////////////////////////////////////
  34. // //
  35. // Miscellaneous macros //
  36. // //
  37. ///////////////////////////////////////////////////////////////////////////////
  38. //
  39. // RELOCATE_ONE - Relocate a single pointer in a client buffer.
  40. //
  41. // Note: this macro is dependent on parameter names as indicated in the
  42. // description below. On error, this macro goes to 'Cleanup' with
  43. // 'Status' set to the NT Status code.
  44. //
  45. // The MaximumLength is forced to be Length.
  46. //
  47. // Define a macro to relocate a pointer in the buffer the client passed in
  48. // to be relative to 'ProtocolSubmitBuffer' rather than being relative to
  49. // 'ClientBufferBase'. The result is checked to ensure the pointer and
  50. // the data pointed to is within the first 'SubmitBufferSize' of the
  51. // 'ProtocolSubmitBuffer'.
  52. //
  53. // The relocated field must be aligned to a WCHAR boundary.
  54. //
  55. // _q - Address of UNICODE_STRING structure which points to data to be
  56. // relocated
  57. //
  58. #define RELOCATE_ONE( _q ) \
  59. { \
  60. ULONG_PTR Offset; \
  61. \
  62. Offset = (((PUCHAR)((_q)->Buffer)) - ((PUCHAR)ClientBufferBase)); \
  63. if ( Offset >= SubmitBufferSize || \
  64. Offset + (_q)->Length > SubmitBufferSize || \
  65. !COUNT_IS_ALIGNED( Offset, ALIGN_WCHAR) ) { \
  66. \
  67. SspPrint((SSP_CRITICAL, "Failed RELOCATE_ONE\n")); \
  68. Status = STATUS_INVALID_PARAMETER; \
  69. goto Cleanup; \
  70. } \
  71. \
  72. (_q)->Buffer = (PWSTR)(((PUCHAR)ProtocolSubmitBuffer) + Offset); \
  73. (_q)->MaximumLength = (_q)->Length ; \
  74. }
  75. //
  76. // NULL_RELOCATE_ONE - Relocate a single (possibly NULL) pointer in a client
  77. // buffer.
  78. //
  79. // This macro special cases a NULL pointer then calls RELOCATE_ONE. Hence
  80. // it has all the restrictions of RELOCATE_ONE.
  81. //
  82. //
  83. // _q - Address of UNICODE_STRING structure which points to data to be
  84. // relocated
  85. //
  86. #define NULL_RELOCATE_ONE( _q ) \
  87. { \
  88. if ( (_q)->Buffer == NULL ) { \
  89. if ( (_q)->Length != 0 ) { \
  90. SspPrint((SSP_CRITICAL, "Failed NULL_RELOCATE_ONE\n")); \
  91. Status = STATUS_INVALID_PARAMETER; \
  92. goto Cleanup; \
  93. } \
  94. } else if ( (_q)->Length == 0 ) { \
  95. (_q)->Buffer = NULL; \
  96. } else { \
  97. RELOCATE_ONE( _q ); \
  98. } \
  99. }
  100. //
  101. // RELOCATE_ONE_ENCODED - Relocate a unicode string pointer in a client
  102. // buffer. The upper byte of the length field may be an encryption seed
  103. // and should not be used for error checking.
  104. //
  105. // Note: this macro is dependent on parameter names as indicated in the
  106. // description below. On error, this macro goes to 'Cleanup' with
  107. // 'Status' set to the NT Status code.
  108. //
  109. // The MaximumLength is forced to be Length & 0x00ff.
  110. //
  111. // Define a macro to relocate a pointer in the buffer the client passed in
  112. // to be relative to 'ProtocolSubmitBuffer' rather than being relative to
  113. // 'ClientBufferBase'. The result is checked to ensure the pointer and
  114. // the data pointed to is within the first 'SubmitBufferSize' of the
  115. // 'ProtocolSubmitBuffer'.
  116. //
  117. // The relocated field must be aligned to a WCHAR boundary.
  118. //
  119. // _q - Address of UNICODE_STRING structure which points to data to be
  120. // relocated
  121. //
  122. #define RELOCATE_ONE_ENCODED( _q ) \
  123. { \
  124. ULONG_PTR Offset; \
  125. \
  126. Offset = (((PUCHAR)((_q)->Buffer)) - ((PUCHAR)ClientBufferBase)); \
  127. if ( Offset >= SubmitBufferSize || \
  128. Offset + ((_q)->Length & 0x00ff) > SubmitBufferSize || \
  129. !COUNT_IS_ALIGNED( Offset, ALIGN_WCHAR) ) { \
  130. \
  131. SspPrint((SSP_CRITICAL, "Failed RELOCATE_ONE_ENCODED\n")); \
  132. Status = STATUS_INVALID_PARAMETER; \
  133. goto Cleanup; \
  134. } \
  135. \
  136. (_q)->Buffer = (PWSTR)(((PUCHAR)ProtocolSubmitBuffer) + Offset); \
  137. (_q)->MaximumLength = (_q)->Length & 0x00ff; \
  138. }
  139. //
  140. // Following macro is used to initialize UNICODE strings
  141. //
  142. #ifndef CONSTANT_UNICODE_STRING
  143. #define CONSTANT_UNICODE_STRING(s) { sizeof( s ) - sizeof( WCHAR ), sizeof( s ), s }
  144. #endif // CONSTANT_UNICODE_STRING
  145. //
  146. // General arrary count.
  147. //
  148. #ifndef COUNTOF
  149. #define COUNTOF(s) ( sizeof( (s) ) / sizeof( *(s) ) )
  150. #endif // COUNTOF
  151. #define NULL_SESSION_REQUESTED RETURN_RESERVED_PARAMETER
  152. #define PRIMARY_CREDENTIAL_NEEDED \
  153. (RETURN_PRIMARY_LOGON_DOMAINNAME | \
  154. RETURN_PRIMARY_USERNAME | \
  155. USE_PRIMARY_PASSWORD )
  156. ///////////////////////////////////////////////////////////////////////
  157. // //
  158. // Authentication package dispatch routine definitions //
  159. // //
  160. ///////////////////////////////////////////////////////////////////////
  161. NTSTATUS
  162. LsaApInitializePackage(
  163. IN ULONG AuthenticationPackageId,
  164. IN PLSA_DISPATCH_TABLE LsaDispatchTable,
  165. IN PSTRING Database OPTIONAL,
  166. IN PSTRING Confidentiality OPTIONAL,
  167. OUT PSTRING *AuthenticationPackageName
  168. );
  169. NTSTATUS
  170. LsaApLogonUser(
  171. IN PLSA_CLIENT_REQUEST ClientRequest,
  172. IN SECURITY_LOGON_TYPE LogonType,
  173. IN PVOID AuthenticationInformation,
  174. IN PVOID ClientAuthenticationBase,
  175. IN ULONG AuthenticationInformationLength,
  176. OUT PVOID *ProfileBuffer,
  177. OUT PULONG ProfileBufferSize,
  178. OUT PLUID LogonId,
  179. OUT PNTSTATUS SubStatus,
  180. OUT PLSA_TOKEN_INFORMATION_TYPE TokenInformationType,
  181. OUT PVOID *TokenInformation,
  182. OUT PUNICODE_STRING *AccountName,
  183. OUT PUNICODE_STRING *AuthenticatingAuthority
  184. );
  185. NTSTATUS
  186. LsaApCallPackage(
  187. IN PLSA_CLIENT_REQUEST ClientRequest,
  188. IN PVOID ProtocolSubmitBuffer,
  189. IN PVOID ClientBufferBase,
  190. IN ULONG SubmitBufferSize,
  191. OUT PVOID *ProtocolReturnBuffer,
  192. OUT PULONG ReturnBufferSize,
  193. OUT PNTSTATUS ProtocolStatus
  194. );
  195. NTSTATUS
  196. LsaApCallPackagePassthrough(
  197. IN PLSA_CLIENT_REQUEST ClientRequest,
  198. IN PVOID ProtocolSubmitBuffer,
  199. IN PVOID ClientBufferBase,
  200. IN ULONG SubmitBufferSize,
  201. OUT PVOID *ProtocolReturnBuffer,
  202. OUT PULONG ReturnBufferSize,
  203. OUT PNTSTATUS ProtocolStatus
  204. );
  205. VOID
  206. LsaApLogonTerminated(
  207. IN PLUID LogonId
  208. );
  209. ///////////////////////////////////////////////////////////////////////
  210. // //
  211. // LsaApCallPackage function dispatch routines //
  212. // //
  213. ///////////////////////////////////////////////////////////////////////
  214. NTSTATUS
  215. MspLm20Challenge(
  216. IN PLSA_CLIENT_REQUEST ClientRequest,
  217. IN PVOID ProtocolSubmitBuffer,
  218. IN PVOID ClientBufferBase,
  219. IN ULONG SubmitBufferSize,
  220. OUT PVOID *ProtocolReturnBuffer,
  221. OUT PULONG ReturnBufferSize,
  222. OUT PNTSTATUS ProtocolStatus
  223. );
  224. NTSTATUS
  225. MspLm20GetChallengeResponse(
  226. IN PLSA_CLIENT_REQUEST ClientRequest,
  227. IN PVOID ProtocolSubmitBuffer,
  228. IN PVOID ClientBufferBase,
  229. IN ULONG SubmitBufferSize,
  230. OUT PVOID *ProtocolReturnBuffer,
  231. OUT PULONG ReturnBufferSize,
  232. OUT PNTSTATUS ProtocolStatus
  233. );
  234. NTSTATUS
  235. MspLm20EnumUsers(
  236. IN PLSA_CLIENT_REQUEST ClientRequest,
  237. IN PVOID ProtocolSubmitBuffer,
  238. IN PVOID ClientBufferBase,
  239. IN ULONG SubmitBufferSize,
  240. OUT PVOID *ProtocolReturnBuffer,
  241. OUT PULONG ReturnBufferSize,
  242. OUT PNTSTATUS ProtocolStatus
  243. );
  244. NTSTATUS
  245. MspLm20GetUserInfo(
  246. IN PLSA_CLIENT_REQUEST ClientRequest,
  247. IN PVOID ProtocolSubmitBuffer,
  248. IN PVOID ClientBufferBase,
  249. IN ULONG SubmitBufferSize,
  250. OUT PVOID *ProtocolReturnBuffer,
  251. OUT PULONG ReturnBufferSize,
  252. OUT PNTSTATUS ProtocolStatus
  253. );
  254. NTSTATUS
  255. MspLm20ReLogonUsers(
  256. IN PLSA_CLIENT_REQUEST ClientRequest,
  257. IN PVOID ProtocolSubmitBuffer,
  258. IN PVOID ClientBufferBase,
  259. IN ULONG SubmitBufferSize,
  260. OUT PVOID *ProtocolReturnBuffer,
  261. OUT PULONG ReturnBufferSize,
  262. OUT PNTSTATUS ProtocolStatus
  263. );
  264. NTSTATUS
  265. MspLm20ChangePassword(
  266. IN PLSA_CLIENT_REQUEST ClientRequest,
  267. IN PVOID ProtocolSubmitBuffer,
  268. IN PVOID ClientBufferBase,
  269. IN ULONG SubmitBufferSize,
  270. OUT PVOID *ProtocolReturnBuffer,
  271. OUT PULONG ReturnBufferSize,
  272. OUT PNTSTATUS ProtocolStatus
  273. );
  274. NTSTATUS
  275. MspLm20GenericPassthrough(
  276. IN PLSA_CLIENT_REQUEST ClientRequest,
  277. IN PVOID ProtocolSubmitBuffer,
  278. IN PVOID ClientBufferBase,
  279. IN ULONG SubmitBufferSize,
  280. OUT PVOID *ProtocolReturnBuffer,
  281. OUT PULONG ReturnBufferSize,
  282. OUT PNTSTATUS ProtocolStatus
  283. );
  284. NTSTATUS
  285. MspLm20CacheLogon(
  286. IN PLSA_CLIENT_REQUEST ClientRequest,
  287. IN PVOID ProtocolSubmitBuffer,
  288. IN PVOID ClientBufferBase,
  289. IN ULONG SubmitBufferSize,
  290. OUT PVOID *ProtocolReturnBuffer,
  291. OUT PULONG ReturnBufferSize,
  292. OUT PNTSTATUS ProtocolStatus
  293. );
  294. NTSTATUS
  295. MspLm20CacheLookup(
  296. IN PLSA_CLIENT_REQUEST ClientRequest,
  297. IN PVOID ProtocolSubmitBuffer,
  298. IN PVOID ClientBufferBase,
  299. IN ULONG SubmitBufferSize,
  300. OUT PVOID *ProtocolReturnBuffer,
  301. OUT PULONG ReturnBufferSize,
  302. OUT PNTSTATUS ProtocolStatus
  303. );
  304. NTSTATUS
  305. MspNtSubAuth(
  306. IN PLSA_CLIENT_REQUEST ClientRequest,
  307. IN PVOID ProtocolSubmitBuffer,
  308. IN PVOID ClientBufferBase,
  309. IN ULONG SubmitBufferSize,
  310. OUT PVOID *ProtocolReturnBuffer,
  311. OUT PULONG ReturnBufferSize,
  312. OUT PNTSTATUS ProtocolStatus
  313. );
  314. NTSTATUS
  315. MspNtDeriveCredential(
  316. IN PLSA_CLIENT_REQUEST ClientRequest,
  317. IN PVOID ProtocolSubmitBuffer,
  318. IN PVOID ClientBufferBase,
  319. IN ULONG SubmitBufferSize,
  320. OUT PVOID *ProtocolReturnBuffer,
  321. OUT PULONG ReturnBufferSize,
  322. OUT PNTSTATUS ProtocolStatus
  323. );
  324. NTSTATUS
  325. MspSetProcessOption(
  326. IN PLSA_CLIENT_REQUEST ClientRequest,
  327. IN PVOID ProtocolSubmitBuffer,
  328. IN PVOID ClientBufferBase,
  329. IN ULONG SubmitBufferSize,
  330. OUT PVOID *ProtocolReturnBuffer,
  331. OUT PULONG ReturnBufferSize,
  332. OUT PNTSTATUS ProtocolStatus
  333. );
  334. ///////////////////////////////////////////////////////////////////////
  335. // //
  336. // NETLOGON routines visible to main msv1_0 code //
  337. // //
  338. ///////////////////////////////////////////////////////////////////////
  339. NTSTATUS
  340. NlInitialize(
  341. VOID
  342. );
  343. NTSTATUS
  344. MspLm20LogonUser (
  345. IN PLSA_CLIENT_REQUEST ClientRequest,
  346. IN SECURITY_LOGON_TYPE LogonType,
  347. IN PVOID AuthenticationInformation,
  348. IN PVOID ClientAuthenticationBase,
  349. IN ULONG AuthenticationInformationSize,
  350. OUT PVOID *ProfileBuffer,
  351. OUT PULONG ProfileBufferSize,
  352. OUT PLUID LogonId,
  353. OUT PNTSTATUS SubStatus,
  354. OUT PLSA_TOKEN_INFORMATION_TYPE TokenInformationType,
  355. OUT PVOID *TokenInformation
  356. );
  357. VOID
  358. MsvLm20LogonTerminated (
  359. IN PLUID LogonId
  360. );
  361. ///////////////////////////////////////////////////////////////////////
  362. // //
  363. // Global variables //
  364. // //
  365. ///////////////////////////////////////////////////////////////////////
  366. //
  367. // Variables defined in msvars.c
  368. //
  369. extern ULONG MspAuthenticationPackageId;
  370. extern LSA_SECPKG_FUNCTION_TABLE Lsa;
  371. //
  372. // Change password log support routines
  373. //
  374. #ifndef DONT_LOG_PASSWORD_CHANGES
  375. ULONG
  376. MsvPaswdInitializeLog(
  377. VOID
  378. );
  379. ULONG
  380. MsvPaswdSetAndClearLog(
  381. VOID
  382. );
  383. ULONG
  384. MsvPaswdCloseLog(
  385. VOID
  386. );
  387. VOID
  388. MsvPaswdLogPrintRoutine(
  389. IN LPSTR Format,
  390. ...
  391. );
  392. #define MsvPaswdLogPrint( x ) MsvPaswdLogPrintRoutine x
  393. #else
  394. #define MsvPaswdInitializeLog()
  395. #define MsvPaswdCloseLog()
  396. #define MsvPaswdLogPrint( x )
  397. #define MsvPaswdSetAndClearLog()
  398. #endif
  399. #endif // _MSP_