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.

664 lines
14 KiB

  1. /*++
  2. Copyright (c) 1987-1996 Microsoft Corporation
  3. Module Name:
  4. logonsrv.h
  5. Abstract:
  6. Netlogon service internal constants and definitions.
  7. Author:
  8. Ported from Lan Man 2.0
  9. Revision History:
  10. 21-May-1991 (cliffv)
  11. Ported to NT. Converted to NT style.
  12. --*/
  13. //
  14. // Define _DC_NETLOGON if _WKSTA_NETLOGON is not defined.
  15. //
  16. #ifndef _WKSTA_NETLOGON
  17. #define _DC_NETLOGON
  18. #endif // _WKSTA_NETLOGON
  19. ////////////////////////////////////////////////////////////////////////////
  20. //
  21. // Common include files needed by ALL netlogon server files
  22. //
  23. ////////////////////////////////////////////////////////////////////////////
  24. #if ( _MSC_VER >= 800 )
  25. #pragma warning ( 3 : 4100 ) // enable "Unreferenced formal parameter"
  26. #pragma warning ( 3 : 4219 ) // enable "trailing ',' used for variable argument list"
  27. #endif
  28. #include <nt.h> // LARGE_INTEGER definition
  29. #include <ntrtl.h> // LARGE_INTEGER definition
  30. #include <nturtl.h> // LARGE_INTEGER definition
  31. #include <ntlsa.h> // Needed by lsrvdata.h
  32. #define NOMINMAX // Avoid redefinition of min and max in stdlib.h
  33. #include <rpc.h> // Needed by logon_s.h
  34. #define INCL_WINSOCK_API_PROTOTYPES 1
  35. #include <winsock2.h> // Winsock support
  36. #include <logon_s.h> // includes lmcons.h, lmaccess.h, netlogon.h, ssi.h, windef.h
  37. #include <windows.h>
  38. #include <alertmsg.h> // ALERT_* defines
  39. #include <align.h> // ROUND_UP_COUNT ...
  40. #include <config.h> // net config helpers.
  41. #include <confname.h> // SECTION_ equates, NETLOGON_KEYWORD_ equates.
  42. #include <debugfmt.h> // FORMAT_*
  43. //#define SDK_DNS_RECORD 1 // Needed for dnsapi.h
  44. #include <windns.h> // DNS API
  45. #include <dnsapi.h> // Dns API
  46. #include <icanon.h> // NAMETYPE_* defines
  47. #include <lmapibuf.h> // NetApiBufferFree
  48. #include <lmerr.h> // NERR_ equates.
  49. #include <lmerrlog.h> // NELOG_*
  50. #include <lmserver.h> // Server API defines and prototypes
  51. #include <lmshare.h> // share API functions and prototypes
  52. #include <lmsname.h> // Needed for NETLOGON service name
  53. #include <lmsvc.h> // SERVICE_UIC codes are defined here
  54. #include <logonp.h> // NetpLogon routines
  55. #include <lsarpc.h> // Needed by lsrvdata.h and logonsrv.h
  56. #include <lsaisrv.h> // LsaI routines
  57. #include <wincrypt.h> // CryptoAPI
  58. #ifndef NETSETUP_JOIN
  59. #define SECURITY_KERBEROS
  60. #include <security.h> // Interface to LSA/Kerberos
  61. #include <secint.h> // needed to get Kerberos interfaces.
  62. #include <sspi.h> // Needed by ssiinit.h
  63. // #include <secext.h> // Needed by secpkg.h
  64. #include <secpkg.h> // Needed by sphelp.h
  65. #endif
  66. #include <names.h> // NetpIsUserNameValid
  67. #include <netlib.h> // NetpCopy...
  68. #include <netlibnt.h> // NetpNtStatusToApiStatus
  69. #include "nlp.h" // Nlp routine
  70. #include <ntddbrow.h> // Interface to browser driver
  71. #include <ntrpcp.h> // Rpcp routines
  72. #include <samrpc.h> // Needed by lsrvdata.h and logonsrv.h
  73. #include <samisrv.h> // SamIFree routines
  74. #include <secobj.h> // NetpAccessCheck
  75. #include <stddef.h> // offsetof()
  76. #include <stdlib.h> // C library functions (rand, etc)
  77. #include <tstring.h> // Transitional string routines.
  78. #include <lmjoin.h> // Needed by netsetup.h
  79. #include <netsetup.h> // NetpSetDnsComputerNameAsRequired
  80. #include <wmistr.h> // WMI trace
  81. #include <evntrace.h> // TRACEHANDLE
  82. #ifndef NETSETUP_JOIN
  83. #include <cryptdll.h>
  84. #include <ntdsa.h>
  85. #include <ntdsapi.h>
  86. #include <ntdsapip.h>
  87. #endif
  88. //
  89. // Netlogon specific header files.
  90. //
  91. #include <nlrepl.h> // I_Net*
  92. #include <dsgetdc.h> // DsGetDcName()
  93. #include <dsgetdcp.h> // DsGetDcOpen()
  94. #include "worker.h" // Worker routines
  95. #include "nlbind.h" // Netlogon RPC binding cache routines
  96. #include "nlcommon.h" // Routines shared with logonsrv\common
  97. #include "domain.h" // Hosted domain definitions
  98. #include "nldns.h" // DNS name registration
  99. #include "changelg.h" // Change Log support
  100. #include "chutil.h" // Change Log utilities
  101. #include "iniparm.h" // DEFAULT_, MIN_, and MAX_ equates.
  102. #include "ssiinit.h" // Misc global definitions
  103. #include "replutil.h"
  104. #include "nldebug.h" // Netlogon debugging
  105. #include "nlsecure.h" // Security Descriptor for APIs
  106. #include "ismapi.h"
  107. #include "nlsite.h"
  108. #include "lsrvdata.h" // Globals
  109. //
  110. // RtlCopyMemory on IA64 is now optimized to do aligned copies inline.
  111. // This doesn't work for us as we use RtlCopyMemory to copy data from
  112. // unaligned buffers to aligned ones, so we cause unaligment exception.
  113. // To avoid this, revert to the old unoptimized version.
  114. //
  115. #if defined(_M_IA64)
  116. #undef RtlCopyMemory
  117. NTSYSAPI
  118. VOID
  119. NTAPI
  120. RtlCopyMemory (
  121. VOID UNALIGNED *Destination,
  122. CONST VOID UNALIGNED *Source,
  123. SIZE_T Length
  124. );
  125. #endif // _M_IA64
  126. #ifdef _DC_NETLOGON
  127. #define NETLOGON_SCRIPTS_SHARE L"NETLOGON"
  128. #define NETLOGON_SYSVOL_SHARE L"SYSVOL"
  129. #endif // _DC_NETLOGON
  130. #define MAX_LOGONREQ_COUNT 3
  131. #define NETLOGON_INSTALL_WAIT 60000 // 60 secs
  132. //
  133. // Exit codes for NlExit
  134. //
  135. typedef enum {
  136. DontLogError,
  137. LogError,
  138. LogErrorAndNtStatus,
  139. LogErrorAndNetStatus
  140. } NL_EXIT_CODE;
  141. ////////////////////////////////////////////////////////////////////////
  142. //
  143. // Procedure Forwards
  144. //
  145. ////////////////////////////////////////////////////////////////////////
  146. //
  147. // error.c
  148. //
  149. NET_API_STATUS
  150. NlCleanup(
  151. VOID
  152. );
  153. VOID
  154. NlExit(
  155. IN DWORD ServiceError,
  156. IN DWORD Data,
  157. IN NL_EXIT_CODE ExitCode,
  158. IN LPWSTR ErrorString
  159. );
  160. BOOL
  161. GiveInstallHints(
  162. IN BOOL Started
  163. );
  164. #ifdef _DC_NETLOGON
  165. VOID
  166. NlControlHandler(
  167. IN DWORD opcode
  168. );
  169. #endif // _DC_NETLOGON
  170. VOID
  171. RaiseAlert(
  172. IN DWORD alert_no,
  173. IN LPWSTR *string_array
  174. );
  175. //
  176. // Nlparse.c
  177. //
  178. BOOL
  179. Nlparse(
  180. IN PNETLOGON_PARAMETERS NlParameters,
  181. IN PNETLOGON_PARAMETERS DefaultParameters OPTIONAL,
  182. IN BOOLEAN IsChangeNotify
  183. );
  184. VOID
  185. NlParseFree(
  186. IN PNETLOGON_PARAMETERS NlParameters
  187. );
  188. VOID
  189. NlReparse(
  190. VOID
  191. );
  192. BOOL
  193. NlparseAllSections(
  194. IN PNETLOGON_PARAMETERS NlParameters,
  195. IN BOOLEAN IsChangeNotify
  196. );
  197. //
  198. // announce.c
  199. //
  200. VOID
  201. NlRemovePendingBdc(
  202. IN PSERVER_SESSION ServerSession
  203. );
  204. VOID
  205. NlPrimaryAnnouncementFinish(
  206. IN PSERVER_SESSION ServerSession,
  207. IN DWORD DatabaseId,
  208. IN PLARGE_INTEGER SerialNumber
  209. );
  210. VOID
  211. NlPrimaryAnnouncementTimeout(
  212. VOID
  213. );
  214. VOID
  215. NlPrimaryAnnouncement(
  216. IN DWORD AnnounceFlags
  217. );
  218. #define ANNOUNCE_FORCE 0x01
  219. #define ANNOUNCE_CONTINUE 0x02
  220. #define ANNOUNCE_IMMEDIATE 0x04
  221. //
  222. // lsrvutil.c
  223. //
  224. NTSTATUS
  225. NlGetOutgoingPassword(
  226. IN PCLIENT_SESSION ClientSession,
  227. OUT PUNICODE_STRING *CurrentValue,
  228. OUT PUNICODE_STRING *OldValue,
  229. OUT PDWORD CurrentVersionNumber,
  230. OUT PLARGE_INTEGER LastSetTime OPTIONAL
  231. );
  232. NTSTATUS
  233. NlSessionSetup(
  234. IN OUT PCLIENT_SESSION ClientSession
  235. );
  236. NTSTATUS
  237. NlEnsureSessionAuthenticated(
  238. IN PCLIENT_SESSION ClientSession,
  239. IN DWORD DesiredFlags
  240. );
  241. BOOLEAN
  242. NlTimeHasElapsedEx(
  243. IN PLARGE_INTEGER StartTime,
  244. IN PLARGE_INTEGER Period,
  245. OUT PULONG RemainingTime OPTIONAL
  246. );
  247. BOOLEAN
  248. NlTimeToReauthenticate(
  249. IN PCLIENT_SESSION ClientSession
  250. );
  251. BOOLEAN
  252. NlTimeToRediscover(
  253. IN PCLIENT_SESSION ClientSession,
  254. BOOLEAN WithAccount
  255. );
  256. NTSTATUS
  257. NlUpdateDomainInfo(
  258. IN PCLIENT_SESSION ClientSession
  259. );
  260. NET_API_STATUS
  261. NlCreateShare(
  262. LPWSTR SharePath,
  263. LPWSTR ShareName,
  264. BOOLEAN AllowAuthenticatedUsers,
  265. BOOL UpdateExclusiveShareAccess,
  266. BOOL AllowExclusiveShareAccess
  267. );
  268. NET_API_STATUS
  269. NlCacheJoinDomainControllerInfo(
  270. VOID
  271. );
  272. NTSTATUS
  273. NlSamOpenNamedUser(
  274. IN PDOMAIN_INFO DomainInfo,
  275. IN LPCWSTR UserName,
  276. OUT SAMPR_HANDLE *UserHandle OPTIONAL,
  277. OUT PULONG UserId OPTIONAL,
  278. PSAMPR_USER_INFO_BUFFER *UserAllInfo OPTIONAL
  279. );
  280. NTSTATUS
  281. NlSamChangePasswordNamedUser(
  282. IN PDOMAIN_INFO DomainInfo,
  283. IN LPCWSTR UserName,
  284. IN PUNICODE_STRING ClearTextPassword OPTIONAL,
  285. IN PNT_OWF_PASSWORD OwfPassword OPTIONAL
  286. );
  287. NTSTATUS
  288. NlGetIncomingPassword(
  289. IN PDOMAIN_INFO DomainInfo,
  290. IN LPCWSTR AccountName,
  291. IN NETLOGON_SECURE_CHANNEL_TYPE SecureChannelType,
  292. IN ULONG AllowableAccountControlBits,
  293. IN BOOL CheckAccountDisabled,
  294. OUT PNT_OWF_PASSWORD OwfPassword OPTIONAL,
  295. OUT PNT_OWF_PASSWORD OwfPreviousPassword OPTIONAL,
  296. OUT PULONG AccountRid OPTIONAL,
  297. OUT PULONG TrustAttributes OPTIONAL,
  298. OUT PBOOL IsDnsDomainTrustAccount OPTIONAL
  299. );
  300. NTSTATUS
  301. NlSetIncomingPassword(
  302. IN PDOMAIN_INFO DomainInfo,
  303. IN LPWSTR AccountName,
  304. IN NETLOGON_SECURE_CHANNEL_TYPE SecureChannelType,
  305. IN PUNICODE_STRING ClearTextPassword OPTIONAL,
  306. IN DWORD ClearPasswordVersionNumber,
  307. IN PNT_OWF_PASSWORD OwfPassword OPTIONAL
  308. );
  309. NTSTATUS
  310. NlChangePassword(
  311. IN PCLIENT_SESSION ClientSession,
  312. IN BOOLEAN ForcePasswordChange,
  313. OUT PULONG RetCallAgainPeriod OPTIONAL
  314. );
  315. NTSTATUS
  316. NlChangePasswordHigher(
  317. IN PCLIENT_SESSION ClientSession,
  318. IN LPWSTR AccountName,
  319. IN NETLOGON_SECURE_CHANNEL_TYPE AccountType,
  320. IN PLM_OWF_PASSWORD NewOwfPassword OPTIONAL,
  321. IN PUNICODE_STRING NewClearPassword OPTIONAL,
  322. IN PDWORD ClearPasswordVersionNumber OPTIONAL
  323. );
  324. NTSTATUS
  325. NlGetUserPriv(
  326. IN PDOMAIN_INFO DomainInfo,
  327. IN ULONG GroupCount,
  328. IN PGROUP_MEMBERSHIP Groups,
  329. IN ULONG UserRelativeId,
  330. OUT LPDWORD Priv,
  331. OUT LPDWORD AuthFlags
  332. );
  333. BOOLEAN
  334. NlGenerateRandomBits(
  335. PUCHAR pBuffer,
  336. ULONG cbBuffer
  337. );
  338. //
  339. // netlogon.c
  340. //
  341. #ifdef _DC_NETLOGON
  342. BOOL
  343. TimerExpired(
  344. IN PTIMER Timer,
  345. IN PLARGE_INTEGER TimeNow,
  346. IN OUT LPDWORD Timeout
  347. );
  348. ULONG
  349. NlGetDomainFlags(
  350. IN PDOMAIN_INFO DomainInfo
  351. );
  352. NTSTATUS
  353. NlWaitForService(
  354. LPWSTR ServiceName,
  355. ULONG Timeout,
  356. BOOLEAN RequireAutoStart
  357. );
  358. int
  359. NlNetlogonMain(
  360. IN DWORD argc,
  361. IN LPWSTR *argv
  362. );
  363. NTSTATUS
  364. NlInitLsaDBInfo(
  365. PDOMAIN_INFO DomainInfo,
  366. DWORD DBIndex
  367. );
  368. NTSTATUS
  369. NlInitSamDBInfo(
  370. PDOMAIN_INFO DomainInfo,
  371. DWORD DBIndex
  372. );
  373. BOOL
  374. NlCreateSysvolShares(
  375. VOID
  376. );
  377. #endif // _DC_NETLOGON
  378. //
  379. // mailslot.c
  380. //
  381. NTSTATUS
  382. NlpWriteMailslot(
  383. IN LPWSTR MailslotName,
  384. IN LPVOID Buffer,
  385. IN DWORD BufferSize
  386. );
  387. #ifdef _DC_NETLOGON
  388. HANDLE
  389. NlBrowserCreateEvent(
  390. VOID
  391. );
  392. VOID
  393. NlBrowserCloseEvent(
  394. IN HANDLE EventHandle
  395. );
  396. BOOL
  397. NlBrowserOpen(
  398. VOID
  399. );
  400. VOID
  401. NlBrowserClose(
  402. VOID
  403. );
  404. NTSTATUS
  405. NlBrowserSendDatagramA(
  406. IN PDOMAIN_INFO DomainInfo,
  407. IN ULONG IpAddress,
  408. IN LPSTR OemServerName,
  409. IN DGRECEIVER_NAME_TYPE NameType,
  410. IN LPWSTR TransportName,
  411. IN LPSTR OemMailslotName,
  412. IN PVOID Buffer,
  413. IN ULONG BufferSize
  414. );
  415. NET_API_STATUS
  416. NlBrowserFixAllNames(
  417. IN PDOMAIN_INFO DomainInfo,
  418. IN PVOID Context
  419. );
  420. VOID
  421. NlBrowserAddName(
  422. IN PDOMAIN_INFO DomainInfo
  423. );
  424. VOID
  425. NlBrowserDelName(
  426. IN PDOMAIN_INFO DomainInfo
  427. );
  428. VOID
  429. NlBrowserUpdate(
  430. IN PDOMAIN_INFO DomainInfo,
  431. IN DWORD Role
  432. );
  433. NTSTATUS
  434. NlBrowserRenameDomain(
  435. IN LPWSTR OldDomainName OPTIONAL,
  436. IN LPWSTR NewDomainName
  437. );
  438. NET_API_STATUS
  439. NlBrowserGetTransportList(
  440. OUT PLMDR_TRANSPORT_LIST *TransportList
  441. );
  442. VOID
  443. NlBrowserSyncHostedDomains(
  444. VOID
  445. );
  446. VOID
  447. NlMailslotPostRead(
  448. IN BOOLEAN IgnoreDuplicatesOfPreviousMessage
  449. );
  450. BOOL
  451. NlMailslotOverlappedResult(
  452. OUT LPBYTE *Message,
  453. OUT PULONG BytesRead,
  454. OUT LPWSTR *TransportName,
  455. OUT PNL_TRANSPORT *Transport,
  456. OUT PSOCKADDR *ClientSockAddr,
  457. OUT LPWSTR *DestinationName,
  458. OUT PBOOLEAN IgnoreDuplicatesOfPreviousMessage,
  459. OUT PNETLOGON_PNP_OPCODE NlPnpOpcode
  460. );
  461. NET_API_STATUS
  462. NlServerComputerNameAdd(
  463. IN LPWSTR HostedDomainName,
  464. IN LPWSTR HostedServerName
  465. );
  466. //
  467. // oldstub.c
  468. //
  469. void _fgs__NETLOGON_DELTA_ENUM (NETLOGON_DELTA_ENUM * _source);
  470. // Use this to free all memory allocated by SAM.
  471. #define SamLsaFreeMemory( _X ) MIDL_user_free(_X)
  472. //
  473. // ds.c
  474. //
  475. NET_API_STATUS
  476. NlGetRoleInformation(
  477. PDOMAIN_INFO DomainInfo,
  478. PBOOLEAN IsPdc,
  479. PBOOLEAN Nt4MixedDomain
  480. );
  481. //
  482. // rgroups.c
  483. //
  484. NTSTATUS
  485. NlpExpandResourceGroupMembership(
  486. IN NETLOGON_VALIDATION_INFO_CLASS ValidationLevel,
  487. IN OUT PNETLOGON_VALIDATION_SAM_INFO4 * UserInfo,
  488. IN PDOMAIN_INFO DomainInfo,
  489. IN ULONG ComputerAccountId
  490. );
  491. NTSTATUS
  492. NlpAddResourceGroupsToSamInfo (
  493. IN NETLOGON_VALIDATION_INFO_CLASS ValidationLevel,
  494. IN OUT PNETLOGON_VALIDATION_SAM_INFO4 *ValidationInformation,
  495. IN PSAMPR_PSID_ARRAY ResourceGroups
  496. );
  497. NTSTATUS
  498. NlpAddOtherOrganizationSid (
  499. IN NETLOGON_VALIDATION_INFO_CLASS ValidationLevel,
  500. IN OUT PNETLOGON_VALIDATION_SAM_INFO4 *ValidationInformation
  501. );
  502. #endif // _DC_NETLOGON
  503. //
  504. // nltrace.c
  505. //
  506. ULONG
  507. _stdcall
  508. NlpInitializeTrace(PVOID Param);
  509. VOID
  510. NlpTraceEvent(
  511. IN ULONG WmiEventType,
  512. IN ULONG TraceGuid );
  513. VOID
  514. NlpTraceServerAuthEvent(
  515. IN ULONG WmiEventType,
  516. IN LPWSTR ComputerName,
  517. IN LPWSTR AccountName,
  518. IN NETLOGON_SECURE_CHANNEL_TYPE SecureChannelType,
  519. IN PULONG NegotiatedFlags,
  520. IN NTSTATUS Status
  521. );
  522. //
  523. // The following "typedef enum" actually is the index of LPGUID in
  524. // the table of NlpTraceGuids[] (defined in nltrace.c). We should
  525. // always change NlpTraceGuids[] if we add any other entry
  526. // in the following enum type.
  527. //
  528. typedef enum _NLPTRACE_GUID {
  529. NlpGuidServerAuth,
  530. NlpGuidSecureChannelSetup
  531. } NLPTRACE_GUID;
  532. //
  533. // parse.c
  534. //
  535. NET_API_STATUS
  536. NlParseOne(
  537. IN LPNET_CONFIG_HANDLE SectionHandle,
  538. IN BOOL GpSection,
  539. IN LPWSTR Keyword,
  540. IN ULONG DefaultValue,
  541. IN ULONG MinimumValue,
  542. IN ULONG MaximumValue,
  543. OUT PULONG Value
  544. );