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.

403 lines
12 KiB

  1. /*++
  2. Copyright (c) 1994-7 Microsoft Corporation
  3. Module Name:
  4. binldef.h
  5. Abstract:
  6. This file contains manifest constants and internal data structures
  7. for the BINL service.
  8. Author:
  9. Colin Watson (colinw) 14-Apr-1997
  10. Environment:
  11. User Mode - Win32
  12. Revision History:
  13. --*/
  14. #ifndef _BINL_
  15. #define _BINL_
  16. #if DBG
  17. #define STATIC
  18. #else
  19. #define STATIC static
  20. #endif // DBG
  21. //
  22. // Globals
  23. //
  24. extern DWORD BinlRepeatSleep;
  25. // Connection information to a DC in our domain
  26. extern PLDAP DCLdapHandle;
  27. extern PWCHAR * DCBase;
  28. // Connection information to the Global Catalog for our enterprise
  29. extern PLDAP GCLdapHandle;
  30. extern PWCHAR * GCBase;
  31. //
  32. // useful macros
  33. //
  34. #define WSTRSIZE( wsz ) (( wcslen( wsz ) + 1 ) * sizeof( WCHAR ))
  35. #define STRSIZE( sz ) (( strlen( sz ) + 1 ) * sizeof( char ))
  36. #define SWAP( p1, p2 ) \
  37. { \
  38. VOID *pvTemp = p1; \
  39. p1 = p2; \
  40. p2 = pvTemp; \
  41. }
  42. //
  43. // calculates the size of a field
  44. //
  45. #define GET_SIZEOF_FIELD( struct, field ) ( sizeof(((struct*)0)->field))
  46. //
  47. // Constants
  48. //
  49. #define BINL_SERVER L"BINLSVC"
  50. //
  51. // Timeouts, this is the length of time we wait for our threads to terminate.
  52. //
  53. #define THREAD_TERMINATION_TIMEOUT INFINITE // wait a long time,
  54. // but don't AV
  55. #define BINL_HYPERMODE_TIMEOUT 60*1000 // in msecs. 1 min
  56. #define BINL_HYPERMODE_RETRY_COUNT 30 // do it for 30 mins
  57. //
  58. // message queue length.
  59. //
  60. #define BINL_RECV_QUEUE_LENGTH 50
  61. #define BINL_MAX_PROCESSING_THREADS 20
  62. //
  63. // macros
  64. //
  65. #define LOCK_INPROGRESS_LIST() EnterCriticalSection(&BinlGlobalInProgressCritSect)
  66. #define UNLOCK_INPROGRESS_LIST() LeaveCriticalSection(&BinlGlobalInProgressCritSect)
  67. #define LOCK_RECV_LIST() EnterCriticalSection(&BinlGlobalRecvListCritSect)
  68. #define UNLOCK_RECV_LIST() LeaveCriticalSection(&BinlGlobalRecvListCritSect)
  69. //
  70. // An endpoint represents a socket and the addresses associated with
  71. // the socket.
  72. //
  73. typedef struct _ENDPOINT {
  74. SOCKET Socket;
  75. DWORD Port;
  76. DHCP_IP_ADDRESS IpAddress;
  77. DHCP_IP_ADDRESS SubnetMask;
  78. DHCP_IP_ADDRESS SubnetAddress;
  79. } ENDPOINT, *LPENDPOINT, *PENDPOINT;
  80. //
  81. // A request context, one per processing thread.
  82. //
  83. typedef struct _BINL_REQUEST_CONTEXT {
  84. //
  85. // list pointer.
  86. //
  87. LIST_ENTRY ListEntry;
  88. //
  89. // pointer to a received buffer.
  90. //
  91. LPBYTE ReceiveBuffer;
  92. //
  93. // A buffer to send response.
  94. //
  95. LPBYTE SendBuffer;
  96. //
  97. // The actual amount of data received in the buffer.
  98. //
  99. DWORD ReceiveMessageSize;
  100. //
  101. // The actual amount of data send in the buffer.
  102. //
  103. DWORD SendMessageSize;
  104. //
  105. // The source of the current message
  106. //
  107. PENDPOINT ActiveEndpoint;
  108. struct sockaddr SourceName;
  109. DWORD SourceNameLength;
  110. DWORD TimeArrived;
  111. BYTE MessageType;
  112. } BINL_REQUEST_CONTEXT, *LPBINL_REQUEST_CONTEXT, *PBINL_REQUEST_CONTEXT;
  113. #define BOOT_FILE_SIZE 128
  114. #define BOOT_SERVER_SIZE 64
  115. #define BOOT_FILE_SIZE_W ( BOOT_FILE_SIZE * sizeof( WCHAR ))
  116. #define BOOT_SERVER_SIZE_W ( BOOT_SERVER_SIZE * sizeof( WCHAR ))
  117. //
  118. // Registry data
  119. //
  120. #define BINL_PARAMETERS_KEY L"System\\CurrentControlSet\\Services\\Binlsvc\\Parameters"
  121. #define BINL_PORT_NAME L"Port"
  122. #define BINL_DEFAULT_PORT 4011
  123. #define BINL_DEBUG_KEY L"Debug"
  124. #if DBG
  125. #define BINL_REPEAT_RESPONSE L"RepeatResponse"
  126. #endif // DBG
  127. #define BINL_LDAP_OPT_REFERRALS L"LdapOptReferrals"
  128. #define BINL_MIN_RESPONSE_TIME L"ResponseDelay"
  129. #define BINL_LDAP_SEARCH_TIMEOUT L"LdapTimeout"
  130. #define BINL_CACHE_EXPIRE L"CacheExpire"
  131. #define BINL_CACHE_MAX_COUNT L"CacheMaxCount"
  132. #define BINL_ALLOW_NEW_CLIENTS L"AllowNewClients"
  133. #define BINL_DEFAULT_CONTAINER L"DefaultContainer"
  134. #define BINL_DEFAULT_DOMAIN L"DefaultDomain"
  135. #define BINL_DEFAULT_DS L"DefaultServer"
  136. #define BINL_DEFAULT_GC L"DefaultGCServer"
  137. #define BINL_CLIENT_TIMEOUT L"ClientTimeout"
  138. #define BINL_SCAVENGER_SLEEP L"ScavengerSleep"
  139. #define BINL_SCAVENGER_SIFFILE L"SifFileSleep"
  140. #define BINL_DEFAULT_LANGUAGE L"DefaultLanguage"
  141. #define BINL_UPDATE_PARAMETER_POLL L"UpdateParameterPoll"
  142. #define BINL_DS_ERROR_COUNT_PARAMETER L"MaxDSErrorsToLog"
  143. #define BINL_DS_ERROR_SLEEP L"DSErrorInterval"
  144. #define BINL_ASSIGN_NEW_CLIENTS_TO_SERVER L"AssignNewClientsToServer"
  145. #define BINL_SCP_CREATED L"ScpCreated"
  146. #define BINL_SCP_NEWCLIENTS L"netbootAllowNewClients"
  147. #define BINL_SCP_LIMITCLIENTS L"netbootLimitClients"
  148. #define BINL_SCP_CURRENTCLIENTCOUNT L"netbootCurrentClientCount"
  149. #define BINL_SCP_MAXCLIENTS L"netbootMaxClients"
  150. #define BINL_SCP_ANSWER_REQUESTS L"netbootAnswerRequests"
  151. #define BINL_SCP_ANSWER_VALID L"netbootAnswerOnlyValidClients"
  152. #define BINL_SCP_NEWMACHINENAMEPOLICY L"netbootNewMachineNamingPolicy"
  153. #define BINL_SCP_NEWMACHINEOU L"netbootNewMachineOU"
  154. #define BINL_SCP_NETBOOTSERVER L"netbootServer"
  155. typedef struct _DHCP_BINARY_DATA {
  156. DWORD DataLength;
  157. #if defined(MIDL_PASS)
  158. [size_is(DataLength)]
  159. #endif // MIDL_PASS
  160. BYTE *Data;
  161. } DHCP_BINARY_DATA, *LPDHCP_BINARY_DATA;
  162. //
  163. // Structure that defines the state of a client.
  164. //
  165. // The reason we use a separate Positive and Negative RefCount is so that
  166. // we don't have to re-acquire the global ClientsCriticalSection when
  167. // we are done with a CLIENT_STATE, just to decrement the ref count.
  168. // Instead we guard the NegativeRefCount with just the CLIENT_STATE's
  169. // CriticalSection. Then we compare Positive and Negative and if they
  170. // are equal we delete the CLIENT_STATE. Even if PositiveRefCount is
  171. // being added to just as we do this comparison, it won't ever be equal
  172. // to Negative RefCount unless we really are the last thread to use the
  173. // CLIENT_STATE.
  174. //
  175. // Padding is in the structure so that the first two elements, which are
  176. // guarded by ClientsCriticalSection, aren't in the same quadword as
  177. // anything else.
  178. //
  179. // search and replace structure
  180. typedef struct {
  181. LPSTR pszToken;
  182. struct {
  183. LPSTR pszStringA;
  184. LPWSTR pszStringW;
  185. };
  186. } SAR, * LPSAR;
  187. #define MAX_VARIABLES 64
  188. typedef struct _CLIENT_STATE {
  189. LIST_ENTRY Linkage; // in ClientsQueue
  190. ULONG PositiveRefCount; // guarded by global ClientsCriticalSection
  191. ULONG Padding;
  192. CRITICAL_SECTION CriticalSection; // prevents two messages processed at once
  193. ULONG NegativeRefCount; // guarded by our CriticalSection; delete when equal to PositiveRC
  194. ULONG RemoteIp; // IP address of the client
  195. CtxtHandle ServerContextHandle;
  196. PLDAP AuthenticatedDCLdapHandle; // returned by ldap_bind (with credentials)
  197. HANDLE UserToken; // returned by LogonUser with same credentials
  198. ULONG ContextAttributes;
  199. UCHAR Seed; // seed used for run encoding-decoding
  200. BOOL NegotiateProcessed;
  201. BOOL CustomInstall; // true if custom, false if auto
  202. BOOL AuthenticateProcessed; // if TRUE, then AuthenticateStatus is valid
  203. BOOL CriticalSectionHeld; // just a quick check, not 100% accurate.
  204. BOOL InitializeOnFirstRequest; // call OscInitializeClientVariables on initial request?
  205. SECURITY_STATUS AuthenticateStatus;
  206. ULONG LastSequenceNumber;
  207. PUCHAR LastResponse; // buffer holding the last packet sent
  208. ULONG LastResponseAllocated; // size LastResponse is allocated at
  209. ULONG LastResponseLength; // size of current data in LastResponse
  210. DWORD LastUpdate; // Last time this client state was entered
  211. ULONG nVariables; // current number of defined varaibles
  212. SAR Variables[ MAX_VARIABLES ]; // "variables" that are replaced in OSCs and SIFs
  213. INT nCreateAccountCounter; // Counts up each time a different computer name was tired
  214. BOOL fCreateNewAccount; // FALSE if a pre-staged account exists
  215. BOOL fAutomaticMachineName; // TRUE is BINL generated the machine name
  216. BOOL fHaveSetupMachineDN; // TRUE if we've already called OscCheckMachineDN
  217. WCHAR MachineAccountPassword[LM20_PWLEN+1];
  218. DWORD MachineAccountPasswordLength;
  219. } CLIENT_STATE, *PCLIENT_STATE;
  220. //
  221. // The structure that tracks info based on GUID.
  222. //
  223. // Because checking the DS is a expensive, we track the results we received
  224. // from the DS per GUID in this structure. This also allows us to ignore
  225. // duplicate requests from clients when we're already working on them.
  226. //
  227. // These cache entries are very short lived, on the order of a minute or so.
  228. // We'd hold them longer except we have no idea when they get stale in the DS.
  229. //
  230. // The list of cache entries is protected by BinlCacheListLock. An entry
  231. // is in use when the InProgress flag is set. If this flag is set, it means
  232. // that a thread is actively using it and the entry shouldn't be touched.
  233. //
  234. // If the hostname is not filled in and the NotMyClient flag is set to FALSE,
  235. // then the entry, though allocated, hasn't been fully filled in.
  236. //
  237. // The XXX_ALLOC bits indicate that the corresponding field was allocated
  238. // and needs to be freed when the cache entry is freed.
  239. //
  240. #define BINL_GUID_LENGTH 16
  241. #define MI_NAME 0x00000001
  242. #define MI_SETUPPATH 0x00000002
  243. #define MI_HOSTNAME 0x00000004
  244. #define MI_BOOTFILENAME 0x00000008
  245. #define MI_SAMNAME 0x00000010
  246. #define MI_PASSWORD 0x00000020
  247. #define MI_DOMAIN 0x00000040
  248. #define MI_HOSTIP 0x00000080
  249. #define MI_MACHINEDN 0x00000100
  250. #define MI_NAME_ALLOC 0x00010000
  251. #define MI_SETUPPATH_ALLOC 0x00020000
  252. #define MI_HOSTNAME_ALLOC 0x00040000
  253. #define MI_BOOTFILENAME_ALLOC 0x00080000
  254. #define MI_SAMNAME_ALLOC 0x00100000
  255. #define MI_DOMAIN_ALLOC 0x00400000
  256. #define MI_SIFFILENAME_ALLOC 0x00800000
  257. #define MI_MACHINEDN_ALLOC 0x01000000
  258. #define MI_ALL_ALLOC 0x03ff0000
  259. #define MI_GUID 0x80000000 // UpdateCreate forces a new guid to be written
  260. typedef struct _MACHINE_INFO {
  261. LIST_ENTRY CacheListEntry; // global is BinlCacheList
  262. DWORD TimeCreated; // from GetTickCount
  263. BOOLEAN InProgress; // is a thread currently working on this?
  264. BOOLEAN MyClient; // do we not respond to this client?
  265. BOOLEAN EntryExists; // does the entry exist in the DS?
  266. DWORD dwFlags; // "MI_" bits saying what information is currently valid
  267. UCHAR Guid[BINL_GUID_LENGTH]; // client's GUID
  268. PWCHAR Name; // client's name
  269. PWCHAR MachineDN; // client's FQ Distinguished Name
  270. PWCHAR SetupPath; // client's orginal installation path
  271. PWCHAR HostName; // client's host server name
  272. DHCP_IP_ADDRESS HostAddress; // address of host - this is filled when HostName is filled
  273. PWCHAR BootFileName; // client's boot filename
  274. PWCHAR SamName; // client's SAM name
  275. PWCHAR Password; // client's password (for setting only)
  276. ULONG PasswordLength; // client's password length (for setting only)
  277. PWCHAR Domain; // client's domain
  278. LIST_ENTRY DNsWithSameGuid; // list of DNs with same GUID, except for MachineDN above.
  279. PWCHAR ForcedSifFileName; // client's sif file it must use.
  280. } MACHINE_INFO, *PMACHINE_INFO;
  281. //
  282. // Structure that tracks duplicate DNs for this machine account. The structure
  283. // is allocated with room for the two strings at the end.
  284. //
  285. typedef struct _DUP_GUID_DN {
  286. LIST_ENTRY ListEntry;
  287. ULONG DuplicateDNOffset; // offset from the start of DuplicateName to DuplicateDN
  288. WCHAR DuplicateName[1]; // name of the duplicate account (without final '$')
  289. // WCHAR DuplicateDN[]; // this follows at DuplicateDNOffset
  290. } DUP_GUID_DN, *PDUP_GUID_DN;
  291. //
  292. // The largest size of any client architecture name
  293. // (current choices: i386 alpha mips ia64 ppc arci386) --
  294. // assume it won't exceed 8 chars for now.
  295. //
  296. #define MAX_ARCHITECTURE_LENGTH 8
  297. #define DHCP_OPTION_CLIENT_ARCHITECTURE_X86 0
  298. #define DHCP_OPTION_CLIENT_ARCHITECTURE_NEC98 1
  299. #define DHCP_OPTION_CLIENT_ARCHITECTURE_IA64 2
  300. #define DHCP_OPTION_CLIENT_ARCHITECTURE_ALPHA 3
  301. #define DHCP_OPTION_CLIENT_ARCHITECTURE_ARCX86 4
  302. #define DHCP_OPTION_CLIENT_ARCHITECTURE_INTELLEAN 5
  303. #endif _BINL_