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.

532 lines
15 KiB

  1. //============================================================================
  2. // Copyright (c) 1996, Microsoft Corporation
  3. //
  4. // File: rtcfg.h
  5. //
  6. // History:
  7. // 05/04/96 Abolade-Gbadegesin Created.
  8. //
  9. // Contains private declarations for the router-configuration access APIs.
  10. //
  11. // The handles supplied by the MprConfig APIs are actually pointers
  12. // to context-blocks defined below. MprConfigServerConnect supplies
  13. // a handle which is a pointer to a SERVERCB. The other handles are pointers
  14. // to contexts which are in lists hanging off the master SERVERCB.
  15. // For instance, when MprConfigInterfaceGetHandle is called, an INTERFACECB
  16. // is allocated and linked into the SERVERCB's list of interfaces,
  17. // and the registry key for the interface is saved in the INTERFACECB.
  18. // When MprConfigServerDisconnect is called, all the open registry keys
  19. // are closed and all the contexts are freed.
  20. //
  21. // The following shows the structure of the relevant sections of the registry:
  22. //
  23. // HKLM\System\CurrentControlSet\Services
  24. // RemoteAccess
  25. // Parameters
  26. // RouterType = REG_DWORD 0x0
  27. // RouterManagers
  28. // Stamp = REG_DWORD 0x0
  29. // IP
  30. // ProtocolId = REG_SZ 0x21
  31. // DLLPath = REG_EXPAND_SZ ...
  32. // Interfaces
  33. // Stamp = REG_DWORD 0x0
  34. // 0
  35. // Stamp = REG_DWORD 0x0
  36. // InterfaceName = REG_SZ EPRO1
  37. // Type = REG_DWORD 0x3
  38. // IP
  39. // ProtocolId = REG_DWORD 0x21
  40. //
  41. // When modifying this file, respect its coding conventions and organization.
  42. //============================================================================
  43. #ifndef _RTCFG_H_
  44. #define _RTCFG_H_
  45. //----------------------------------------------------------------------------
  46. // Structure: SERVERCB
  47. //
  48. // Context block created as a handle by 'MprConfigServerConnect'.
  49. //----------------------------------------------------------------------------
  50. typedef struct _SERVERCB {
  51. //
  52. // Signiture to validate this structure
  53. //
  54. DWORD dwSigniture;
  55. //
  56. // name of router machine
  57. //
  58. LPWSTR lpwsServerName;
  59. //
  60. // handle to remote HKEY_LOCAL_MACHINE
  61. //
  62. HKEY hkeyMachine;
  63. //
  64. // handle to remote RemoteAccess\Parameters registry key,
  65. // and last-write-time
  66. //
  67. HKEY hkeyParameters;
  68. FILETIME ftParametersStamp;
  69. //
  70. // handle to remote RemoteAccess\RouterManagers registry key,
  71. // and last-write-time
  72. //
  73. HKEY hkeyTransports;
  74. FILETIME ftTransportsStamp;
  75. //
  76. // handle to remote RemoteAccess\Interfaces registry key,
  77. // and last-write-time
  78. //
  79. HKEY hkeyInterfaces;
  80. FILETIME ftInterfacesStamp;
  81. //
  82. // 'RouterType' setting, and flag indicating it is loaded
  83. //
  84. DWORD fRouterType;
  85. BOOL bParametersLoaded;
  86. //
  87. // head of sorted TRANSPORTCB list, and flag indicating list is loaded
  88. //
  89. LIST_ENTRY lhTransports;
  90. BOOL bTransportsLoaded;
  91. //
  92. // head of sorted INTERFACECB list, and flag indicating list is loaded
  93. //
  94. LIST_ENTRY lhInterfaces;
  95. BOOL bInterfacesLoaded;
  96. //
  97. // handle to data used to provide mapping of interface name to guid name
  98. // and vice versa.
  99. //
  100. HANDLE hGuidMap;
  101. //
  102. // reference count to this server control block
  103. //
  104. DWORD dwRefCount;
  105. } SERVERCB;
  106. //----------------------------------------------------------------------------
  107. // Structure: TRANSPORTCB
  108. //
  109. // Context block created as a handle by 'MprConfigTransportGetHandle'.
  110. //----------------------------------------------------------------------------
  111. typedef struct _TRANSPORTCB {
  112. //
  113. // transport ID of transport
  114. //
  115. DWORD dwTransportId;
  116. //
  117. // name of the registry key for the transport
  118. //
  119. LPWSTR lpwsTransportKey;
  120. //
  121. // handle to remote RemoteAccess\RouterManagers subkey for transport
  122. //
  123. HKEY hkey;
  124. //
  125. // Deletion flag, set when we detect the transport was removed.
  126. //
  127. BOOL bDeleted;
  128. //
  129. // node in the SERVERCB's list of transports
  130. //
  131. LIST_ENTRY leNode;
  132. } TRANSPORTCB;
  133. //----------------------------------------------------------------------------
  134. // Structure: INTERFACECB
  135. //
  136. // Context block created as a handle by 'MprConfigInterfaceGetHandle'.
  137. //----------------------------------------------------------------------------
  138. typedef struct _INTERFACECB {
  139. //
  140. // name of this interface
  141. //
  142. LPWSTR lpwsInterfaceName;
  143. //
  144. // name of the registry key for the interface
  145. //
  146. LPWSTR lpwsInterfaceKey;
  147. //
  148. // Type of interface (see mprapi.h)
  149. //
  150. DWORD dwIfType;
  151. //
  152. // Is this interface marked as persistant?
  153. //
  154. BOOL fEnabled;
  155. //
  156. // Dialout hours restriction (optional)
  157. //
  158. LPWSTR lpwsDialoutHoursRestriction;
  159. //
  160. // handle to remote RemoteAccess\Interfaces subkey for interface
  161. //
  162. HKEY hkey;
  163. //
  164. // Last-write-time for the key, and deletion flag
  165. //
  166. FILETIME ftStamp;
  167. BOOL bDeleted;
  168. //
  169. // node in the SERVERCB's list of interfaces
  170. //
  171. LIST_ENTRY leNode;
  172. //
  173. // head of this interface's sorted IFTRANSPORTCB list,
  174. // and flag indicating list is loaded
  175. //
  176. LIST_ENTRY lhIfTransports;
  177. BOOL bIfTransportsLoaded;
  178. } INTERFACECB;
  179. //----------------------------------------------------------------------------
  180. // Structure: IFTRANSPORTCB
  181. //
  182. // Context block created as a handle by MprConfigInterfaceGetTransportHandle
  183. //----------------------------------------------------------------------------
  184. typedef struct _IFTRANSPORTCB {
  185. //
  186. // transport ID of transport
  187. //
  188. DWORD dwTransportId;
  189. //
  190. // name of the registry key for the interface-transport
  191. //
  192. LPWSTR lpwsIfTransportKey;
  193. //
  194. // handle to remote RemoteAccess\Interfaces\<interface> subkey for transport
  195. //
  196. HKEY hkey;
  197. //
  198. // Deletion flag, set when we detect the interface-transport was removed.
  199. //
  200. BOOL bDeleted;
  201. //
  202. // node in an INTERFACECB's list of transports
  203. //
  204. LIST_ENTRY leNode;
  205. } IFTRANSPORTCB;
  206. //----------------------------------------------------------------------------
  207. // Macros: Malloc
  208. // Free
  209. // Free0
  210. //
  211. // Allocations are done from the process-heap using these macros.
  212. //----------------------------------------------------------------------------
  213. #define Malloc(s) HeapAlloc(GetProcessHeap(), 0, (s))
  214. #define Free(p) HeapFree(GetProcessHeap(), 0, (p))
  215. #define Free0(p) ((p) ? Free(p) : TRUE)
  216. //----------------------------------------------------------------------------
  217. // Function: AccessRouterSubkey
  218. //
  219. // Creates/opens a subkey of the Router service key on 'hkeyMachine'.
  220. // When a key is created, 'lpwsSubkey' must be a child of the Router key.
  221. //----------------------------------------------------------------------------
  222. DWORD
  223. AccessRouterSubkey(
  224. IN HKEY hkeyMachine,
  225. IN LPCWSTR lpwsSubkey,
  226. IN BOOL bCreate,
  227. OUT HKEY* phkeySubkey
  228. );
  229. //----------------------------------------------------------------------------
  230. // Function: EnableBackupPrivilege
  231. //
  232. // Enables/disables backup privilege for the current process.
  233. //----------------------------------------------------------------------------
  234. DWORD
  235. EnableBackupPrivilege(
  236. IN BOOL bEnable,
  237. IN LPWSTR pszPrivilege
  238. );
  239. //----------------------------------------------------------------------------
  240. // Function: FreeInterface
  241. //
  242. // Frees the context for an interface.
  243. // Assumes the interface is no longer in the list of interfaces.
  244. //----------------------------------------------------------------------------
  245. VOID
  246. FreeInterface(
  247. IN INTERFACECB* pinterface
  248. );
  249. //----------------------------------------------------------------------------
  250. // Function: FreeIfTransport
  251. //
  252. // Frees the context for an interface-transport.
  253. // Assumes the interface-transport is no longer in any list.
  254. //----------------------------------------------------------------------------
  255. VOID
  256. FreeIfTransport(
  257. IN IFTRANSPORTCB* piftransport
  258. );
  259. //----------------------------------------------------------------------------
  260. // Function: FreeTransport
  261. //
  262. // Frees the context for a transport.
  263. // Assumes the transport is no longer in the list of transports.
  264. //----------------------------------------------------------------------------
  265. VOID
  266. FreeTransport(
  267. IN TRANSPORTCB* ptransport
  268. );
  269. //----------------------------------------------------------------------------
  270. // Function: GetLocalMachine
  271. //
  272. // Retrieves the name of the local machine (e.g. "\\MACHINE").
  273. // Assumes the string supplied can hold MAX_COMPUTERNAME_LENGTH + 3 characters.
  274. //----------------------------------------------------------------------------
  275. VOID
  276. GetLocalMachine(
  277. IN LPWSTR lpszMachine
  278. );
  279. //----------------------------------------------------------------------------
  280. // Function: GetSizeOfDialoutHoursRestriction
  281. //
  282. // Will return the size of the dialout hours restriction in bytes. This
  283. // is a MULTI_SZ. The count will include the terminating NULL characters.
  284. //----------------------------------------------------------------------------
  285. DWORD
  286. GetSizeOfDialoutHoursRestriction(
  287. IN LPWSTR lpwsDialoutHoursRestriction
  288. );
  289. //----------------------------------------------------------------------------
  290. // Function: IsNt40Machine
  291. //
  292. // Returns whether the given hkeyMachine belongs to an nt40 registry
  293. //----------------------------------------------------------------------------
  294. DWORD
  295. IsNt40Machine (
  296. IN HKEY hkeyMachine,
  297. OUT PBOOL pbIsNt40
  298. );
  299. //----------------------------------------------------------------------------
  300. // Function: LoadIfTransports
  301. //
  302. // Loads all the transports added to an interface.
  303. //----------------------------------------------------------------------------
  304. DWORD
  305. LoadIfTransports(
  306. IN INTERFACECB* pinterface
  307. );
  308. //----------------------------------------------------------------------------
  309. // Function: LoadInterfaces
  310. //
  311. // Loads all the interfaces.
  312. //----------------------------------------------------------------------------
  313. DWORD
  314. LoadInterfaces(
  315. IN SERVERCB* pserver
  316. );
  317. //----------------------------------------------------------------------------
  318. // Function: LoadParameters
  319. //
  320. // Loads all the parameters
  321. //----------------------------------------------------------------------------
  322. DWORD
  323. LoadParameters(
  324. IN SERVERCB* pserver
  325. );
  326. //----------------------------------------------------------------------------
  327. // Function: LoadTransports
  328. //
  329. // Loads all the transports
  330. //----------------------------------------------------------------------------
  331. DWORD
  332. LoadTransports(
  333. IN SERVERCB* pserver
  334. );
  335. //----------------------------------------------------------------------------
  336. // Function: QueryValue
  337. //
  338. // Queries the 'hkey' for the value 'lpwsValue', allocating memory
  339. // for the resulting data
  340. //----------------------------------------------------------------------------
  341. DWORD
  342. QueryValue(
  343. IN HKEY hkey,
  344. IN LPCWSTR lpwsValue,
  345. IN OUT LPBYTE* lplpValue,
  346. OUT LPDWORD lpdwSize
  347. );
  348. //----------------------------------------------------------------------------
  349. // Function: RegDeleteTree
  350. //
  351. // Removes an entire subtree from the registry.
  352. //----------------------------------------------------------------------------
  353. DWORD
  354. RegDeleteTree(
  355. IN HKEY hkey,
  356. IN LPWSTR lpwsSubkey
  357. );
  358. //----------------------------------------------------------------------------
  359. // Function: RestoreAndTranslateInterfaceKey
  360. //
  361. // Restores the interfaces key from the given file and then maps lan interface
  362. // names from friendly versions to their guid equivalents.
  363. //
  364. //----------------------------------------------------------------------------
  365. DWORD
  366. RestoreAndTranslateInterfaceKey(
  367. IN SERVERCB * pserver,
  368. IN CHAR* pszFileName,
  369. IN DWORD dwFlags
  370. );
  371. //----------------------------------------------------------------------------
  372. // Function: StrDupW
  373. //
  374. // Returns a heap-allocated copy of the specified string.
  375. //----------------------------------------------------------------------------
  376. LPWSTR
  377. StrDupW(
  378. IN LPCWSTR lpsz
  379. );
  380. //----------------------------------------------------------------------------
  381. // Function: TimeStampChanged
  382. //
  383. // Checks the current last-write-time for the given key,
  384. // and returns TRUE if it is different from the given file-time.
  385. // The new last-write-time is saved in 'pfiletime'.
  386. //----------------------------------------------------------------------------
  387. BOOL
  388. TimeStampChanged(
  389. IN HKEY hkey,
  390. IN OUT FILETIME* pfiletime
  391. );
  392. //----------------------------------------------------------------------------
  393. // Function: TranslateAndSaveInterfaceKey
  394. //
  395. // Saves the interfaces key in the router's registry into the given file. All
  396. // lan interfaces are stored with friendly interface names.
  397. //
  398. //----------------------------------------------------------------------------
  399. DWORD
  400. TranslateAndSaveInterfaceKey(
  401. IN SERVERCB * pserver,
  402. IN PWCHAR pwsFileName,
  403. IN LPSECURITY_ATTRIBUTES lpSecurityAttributes
  404. );
  405. //----------------------------------------------------------------------------
  406. // Function: UpdateTimeStamp
  407. //
  408. // Creates (or sets) a value named 'Stamp' under the given key,
  409. // and saves the last-write-time for the key in 'pfiletime'.
  410. //----------------------------------------------------------------------------
  411. DWORD
  412. UpdateTimeStamp(
  413. IN HKEY hkey,
  414. OUT FILETIME* pfiletime
  415. );
  416. //
  417. // Private ex version of this function that allows you to specify
  418. // whether you want all interfaces loaded, or just those that are
  419. // up according to pnp. (see MPRFLAG_IF_* for values for dwFlags)
  420. //
  421. DWORD APIENTRY
  422. MprConfigInterfaceEnumInternal(
  423. IN HANDLE hMprConfig,
  424. IN DWORD dwLevel,
  425. IN OUT LPBYTE* lplpBuffer,
  426. IN DWORD dwPrefMaxLen,
  427. OUT LPDWORD lpdwEntriesRead,
  428. OUT LPDWORD lpdwTotalEntries,
  429. IN OUT LPDWORD lpdwResumeHandle, OPTIONAL
  430. IN DWORD dwFlags
  431. );
  432. #endif // _RTCFG_H_