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.

360 lines
12 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. netsh.h
  5. Abstract:
  6. This file contains definitions which are needed by all NetSh helper DLLs.
  7. --*/
  8. #ifndef _NETSH_H_
  9. #define _NETSH_H_
  10. #if _MSC_VER > 1000
  11. #pragma once
  12. #endif
  13. #pragma warning(push)
  14. #pragma warning(disable:4201) // nameless struct/union
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. //
  19. // Error codes
  20. //
  21. #define NETSH_ERROR_BASE 15000
  22. #define ERROR_NO_ENTRIES (NETSH_ERROR_BASE + 0)
  23. #define ERROR_INVALID_SYNTAX (NETSH_ERROR_BASE + 1)
  24. #define ERROR_PROTOCOL_NOT_IN_TRANSPORT (NETSH_ERROR_BASE + 2)
  25. #define ERROR_NO_CHANGE (NETSH_ERROR_BASE + 3)
  26. #define ERROR_CMD_NOT_FOUND (NETSH_ERROR_BASE + 4)
  27. #define ERROR_ENTRY_PT_NOT_FOUND (NETSH_ERROR_BASE + 5)
  28. #define ERROR_DLL_LOAD_FAILED (NETSH_ERROR_BASE + 6)
  29. #define ERROR_INIT_DISPLAY (NETSH_ERROR_BASE + 7)
  30. #define ERROR_TAG_ALREADY_PRESENT (NETSH_ERROR_BASE + 8)
  31. #define ERROR_INVALID_OPTION_TAG (NETSH_ERROR_BASE + 9)
  32. #define ERROR_NO_TAG (NETSH_ERROR_BASE + 10)
  33. #define ERROR_MISSING_OPTION (NETSH_ERROR_BASE + 11)
  34. #define ERROR_TRANSPORT_NOT_PRESENT (NETSH_ERROR_BASE + 12)
  35. #define ERROR_SHOW_USAGE (NETSH_ERROR_BASE + 13)
  36. #define ERROR_INVALID_OPTION_VALUE (NETSH_ERROR_BASE + 14)
  37. #define ERROR_OKAY (NETSH_ERROR_BASE + 15)
  38. #define ERROR_CONTINUE_IN_PARENT_CONTEXT (NETSH_ERROR_BASE + 16)
  39. #define ERROR_SUPPRESS_OUTPUT (NETSH_ERROR_BASE + 17)
  40. #define ERROR_HELPER_ALREADY_REGISTERED (NETSH_ERROR_BASE + 18)
  41. #define ERROR_CONTEXT_ALREADY_REGISTERED (NETSH_ERROR_BASE + 19)
  42. #define NETSH_ERROR_END ERROR_CONTEXT_ALREADY_REGISTERED
  43. // Flags
  44. enum NS_CMD_FLAGS
  45. {
  46. CMD_FLAG_PRIVATE = 0x01, // not valid in sub-contexts
  47. CMD_FLAG_INTERACTIVE = 0x02, // not valid from outside netsh
  48. CMD_FLAG_LOCAL = 0x08, // not valid from a remote machine
  49. CMD_FLAG_ONLINE = 0x10, // not valid in offline/non-commit mode
  50. CMD_FLAG_HIDDEN = 0x20, // hide from help but allow execution
  51. CMD_FLAG_LIMIT_MASK = 0xffff,
  52. CMD_FLAG_PRIORITY = 0x80000000 // ulPriority field is used*/
  53. };
  54. typedef enum _NS_REQS
  55. {
  56. NS_REQ_ZERO = 0,
  57. NS_REQ_PRESENT = 1,
  58. NS_REQ_ALLOW_MULTIPLE = 2,
  59. NS_REQ_ONE_OR_MORE = 3
  60. } NS_REQS;
  61. enum NS_EVENTS
  62. {
  63. NS_EVENT_LOOP = 0x00010000,
  64. NS_EVENT_LAST_N = 0x00000001,
  65. NS_EVENT_LAST_SECS = 0x00000002,
  66. NS_EVENT_FROM_N = 0x00000004,
  67. NS_EVENT_FROM_START = 0x00000008
  68. };
  69. enum NS_MODE_CHANGE
  70. {
  71. NETSH_COMMIT = 0,
  72. NETSH_UNCOMMIT = 1,
  73. NETSH_FLUSH = 2,
  74. NETSH_COMMIT_STATE = 3,
  75. NETSH_SAVE = 4
  76. };
  77. #define NS_GET_EVENT_IDS_FN_NAME "GetEventIds"
  78. #define MAX_NAME_LEN MAX_DLL_NAME
  79. #define NETSH_VERSION_50 0x0005000
  80. #define NETSH_ARG_DELIMITER L"="
  81. #define NETSH_CMD_DELIMITER L" "
  82. #define NETSH_MAX_TOKEN_LENGTH 64
  83. #define NETSH_MAX_CMD_TOKEN_LENGTH 128
  84. #define NETSH_ROOT_GUID { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }
  85. #define DEFAULT_CONTEXT_PRIORITY 100
  86. typedef struct _TOKEN_VALUE
  87. {
  88. LPCWSTR pwszToken; // literal token string
  89. DWORD dwValue; // ID of info string
  90. } TOKEN_VALUE, *PTOKEN_VALUE;
  91. // Macros
  92. #define CREATE_CMD_ENTRY(t,f) {CMD_##t, f, HLP_##t, HLP_##t##_EX, CMD_FLAG_PRIVATE, NULL}
  93. #define CREATE_CMD_ENTRY_EX(t,f,i) {CMD_##t, f, HLP_##t, HLP_##t##_EX, i, NULL}
  94. #define CREATE_CMD_ENTRY_EX_VER(t,f,i,v) {CMD_##t, f, HLP_##t, HLP_##t##_EX, i, v}
  95. #define CREATE_CMD_GROUP_ENTRY(t,s) {CMD_##t, HLP_##t, sizeof(s)/sizeof(CMD_ENTRY), 0, s, NULL }
  96. #define CREATE_CMD_GROUP_ENTRY_EX(t,s,i) {CMD_##t, HLP_##t, sizeof(s)/sizeof(CMD_ENTRY), i, s, NULL }
  97. #define CREATE_CMD_GROUP_ENTRY_EX_VER(t,s,i,v) {CMD_##t, HLP_##t, sizeof(s)/sizeof(CMD_ENTRY), i, s, v }
  98. #define NUM_TOKENS_IN_TABLE(TokenArray) sizeof(TokenArray)/sizeof(TOKEN_VALUE)
  99. #define NUM_TAGS_IN_TABLE(TagsArray) sizeof(TagsArray)/sizeof(TAG_TYPE)
  100. // Callbacks
  101. typedef
  102. DWORD
  103. (WINAPI NS_CONTEXT_COMMIT_FN)(
  104. IN DWORD dwAction
  105. );
  106. typedef NS_CONTEXT_COMMIT_FN *PNS_CONTEXT_COMMIT_FN;
  107. typedef
  108. DWORD
  109. (WINAPI NS_CONTEXT_CONNECT_FN)(
  110. IN LPCWSTR pwszMachine
  111. );
  112. typedef NS_CONTEXT_CONNECT_FN *PNS_CONTEXT_CONNECT_FN;
  113. typedef struct _NS_CONTEXT_ATTRIBUTES NS_CONTEXT_ATTRIBUTES;
  114. typedef
  115. DWORD
  116. (WINAPI NS_CONTEXT_DUMP_FN)(
  117. IN LPCWSTR pwszRouter,
  118. IN OUT LPWSTR *ppwcArguments,
  119. IN DWORD dwArgCount,
  120. IN LPCVOID pvData
  121. );
  122. typedef NS_CONTEXT_DUMP_FN *PNS_CONTEXT_DUMP_FN;
  123. typedef
  124. DWORD
  125. (WINAPI NS_DLL_STOP_FN)(
  126. IN DWORD dwReserved
  127. );
  128. typedef NS_DLL_STOP_FN *PNS_DLL_STOP_FN;
  129. typedef
  130. DWORD
  131. (WINAPI NS_HELPER_START_FN)(
  132. IN CONST GUID *pguidParent,
  133. IN DWORD dwVersion
  134. );
  135. typedef NS_HELPER_START_FN *PNS_HELPER_START_FN;
  136. typedef
  137. DWORD
  138. (WINAPI NS_HELPER_STOP_FN)(
  139. IN DWORD dwReserved
  140. );
  141. typedef NS_HELPER_STOP_FN *PNS_HELPER_STOP_FN;
  142. typedef DWORD (FN_HANDLE_CMD)(
  143. IN LPCWSTR pwszMachine,
  144. IN OUT LPWSTR *ppwcArguments,
  145. IN DWORD dwCurrentIndex,
  146. IN DWORD dwArgCount,
  147. IN DWORD dwFlags,
  148. IN LPCVOID pvData,
  149. OUT BOOL *pbDone
  150. );
  151. typedef FN_HANDLE_CMD *PFN_HANDLE_CMD;
  152. typedef
  153. BOOL
  154. (WINAPI NS_OSVERSIONCHECK)(
  155. IN UINT CIMOSType, // WMI: Win32_OperatingSystem OSType
  156. IN UINT CIMOSProductSuite, // WMI: Win32_OperatingSystem OSProductSuite
  157. IN LPCWSTR CIMOSVersion, // WMI: Win32_OperatingSystem Version
  158. IN LPCWSTR CIMOSBuildNumber, // WMI: Win32_OperatingSystem BuildNumber
  159. IN LPCWSTR CIMServicePackMajorVersion, // WMI: Win32_OperatingSystem ServicePackMajorVersion
  160. IN LPCWSTR CIMServicePackMinorVersion, // WMI: Win32_OperatingSystem ServicePackMinorVersion
  161. IN UINT CIMProcessorArchitecture, // WMI: Win32_Processor Architecture
  162. IN DWORD dwReserved
  163. );
  164. typedef NS_OSVERSIONCHECK *PNS_OSVERSIONCHECK;
  165. // Structures
  166. typedef struct _NS_HELPER_ATTRIBUTES
  167. {
  168. union
  169. {
  170. struct
  171. {
  172. DWORD dwVersion;
  173. DWORD dwReserved;
  174. };
  175. ULONGLONG _ullAlign;
  176. };
  177. GUID guidHelper; // GUID associated with the helper
  178. PNS_HELPER_START_FN pfnStart; // Function to start this helper
  179. PNS_HELPER_STOP_FN pfnStop; // Function to stop this helper
  180. } NS_HELPER_ATTRIBUTES, *PNS_HELPER_ATTRIBUTES;
  181. typedef struct _CMD_ENTRY
  182. {
  183. LPCWSTR pwszCmdToken; // The token for the command
  184. PFN_HANDLE_CMD pfnCmdHandler; // The function which handles this command
  185. DWORD dwShortCmdHelpToken; // The short help message
  186. DWORD dwCmdHlpToken; // The message to display if the only thing after the command is a help token (HELP, /?, -?, ?)
  187. DWORD dwFlags; // Flags (see CMD_FLAGS_xxx above)
  188. PNS_OSVERSIONCHECK pOsVersionCheck; // Check for the version of the OS this command can run against
  189. } CMD_ENTRY, *PCMD_ENTRY;
  190. typedef struct _CMD_GROUP_ENTRY
  191. {
  192. LPCWSTR pwszCmdGroupToken; // The token for the command verb
  193. DWORD dwShortCmdHelpToken; // The message to display in a command listing.
  194. ULONG ulCmdGroupSize; // The number of entries in the cmd table
  195. DWORD dwFlags; // Flags (see CMD_FLAG_xxx)
  196. PCMD_ENTRY pCmdGroup; // The command table
  197. PNS_OSVERSIONCHECK pOsVersionCheck; // Check for the version of the OS this command can run against
  198. } CMD_GROUP_ENTRY, *PCMD_GROUP_ENTRY;
  199. typedef struct _NS_CONTEXT_ATTRIBUTES
  200. {
  201. union
  202. {
  203. struct
  204. {
  205. DWORD dwVersion;
  206. DWORD dwReserved;
  207. };
  208. ULONGLONG _ullAlign;
  209. };
  210. LPWSTR pwszContext; // Name of the context
  211. GUID guidHelper; // GUID of the helper servicing this context
  212. DWORD dwFlags; // Flags limiting when context is available. (See CMD_FLAG_xxx)
  213. ULONG ulPriority; // Priority field is only relevant if CMD_FLAG_PRIORITY is set in dwFlags
  214. ULONG ulNumTopCmds; // Number of top-level commands
  215. struct _CMD_ENTRY (*pTopCmds)[]; // Array of top-level commands
  216. ULONG ulNumGroups; // Number of command groups
  217. struct _CMD_GROUP_ENTRY (*pCmdGroups)[]; // Array of command groups
  218. PNS_CONTEXT_COMMIT_FN pfnCommitFn;
  219. PNS_CONTEXT_DUMP_FN pfnDumpFn;
  220. PNS_CONTEXT_CONNECT_FN pfnConnectFn;
  221. PVOID pReserved;
  222. PNS_OSVERSIONCHECK pfnOsVersionCheck;
  223. } NS_CONTEXT_ATTRIBUTES, *PNS_CONTEXT_ATTRIBUTES;
  224. typedef CONST struct _NS_CONTEXT_ATTRIBUTES * PCNS_CONTEXT_ATTRIBUTES;
  225. typedef struct _TAG_TYPE
  226. {
  227. LPCWSTR pwszTag; // tag string
  228. DWORD dwRequired; // required or not
  229. BOOL bPresent; // present or not
  230. } TAG_TYPE, *PTAG_TYPE;
  231. typedef
  232. DWORD
  233. (NS_DLL_INIT_FN)(
  234. IN DWORD dwNetshVersion,
  235. OUT PVOID pReserved
  236. );
  237. typedef NS_DLL_INIT_FN *PNS_DLL_INIT_FN;
  238. // Exports
  239. DWORD WINAPI GetHostMachineInfo(
  240. OUT UINT *puiCIMOSType, // WMI: Win32_OperatingSystem OSType
  241. OUT UINT *puiCIMOSProductSuite, // WMI: Win32_OperatingSystem OSProductSuite
  242. OUT LPWSTR pszCIMOSVersion, // WMI: Win32_OperatingSystem Version
  243. OUT LPWSTR pszCIMOSBuildNumber, // WMI: Win32_OperatingSystem BuildNumber
  244. OUT LPWSTR pszCIMServicePackMajorVersion, // WMI: Win32_OperatingSystem ServicePackMajorVersion
  245. OUT LPWSTR pszCIMServicePackMinorVersion, // WMI: Win32_OperatingSystem ServicePackMinorVersion
  246. OUT UINT *puiCIMProcessorArchitecture); // WMI: Win32_Processor Architecture
  247. DWORD WINAPI MatchEnumTag(
  248. IN HANDLE hModule,
  249. IN LPCWSTR pwcArg,
  250. IN DWORD dwNumArg,
  251. IN CONST TOKEN_VALUE *pEnumTable,
  252. OUT PDWORD pdwValue
  253. );
  254. BOOL WINAPI MatchToken(
  255. IN LPCWSTR pwszUserToken,
  256. IN LPCWSTR pwszCmdToken
  257. );
  258. DWORD WINAPI PreprocessCommand(
  259. IN HANDLE hModule,
  260. IN OUT LPWSTR *ppwcArguments,
  261. IN DWORD dwCurrentIndex,
  262. IN DWORD dwArgCount,
  263. IN OUT PTAG_TYPE pttTags,
  264. IN DWORD dwTagCount,
  265. IN DWORD dwMinArgs,
  266. IN DWORD dwMaxArgs,
  267. OUT DWORD *pdwTagType
  268. );
  269. DWORD PrintError(
  270. IN HANDLE hModule, OPTIONAL
  271. IN DWORD dwErrId,
  272. ...
  273. );
  274. DWORD PrintMessageFromModule(
  275. IN HANDLE hModule,
  276. IN DWORD dwMsgId,
  277. ...
  278. );
  279. DWORD PrintMessage(
  280. IN LPCWSTR pwszFormat,
  281. ...
  282. );
  283. DWORD WINAPI RegisterContext(
  284. IN CONST NS_CONTEXT_ATTRIBUTES *pChildContext
  285. );
  286. DWORD WINAPI RegisterHelper(
  287. IN CONST GUID *pguidParentContext,
  288. IN CONST NS_HELPER_ATTRIBUTES *pfnRegisterSubContext
  289. );
  290. #ifdef __cplusplus
  291. }
  292. #endif
  293. #pragma warning(pop)
  294. #endif // _NETSH_H_