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.

461 lines
13 KiB

  1. /*++
  2. Copyright (c) 1999, Microsoft Corporation
  3. Module Name:
  4. sample\samplecfg.c
  5. Abstract:
  6. The file contains functions to change configuration for IP SAMPLE.
  7. --*/
  8. #include "precomp.h"
  9. #pragma hdrstop
  10. DWORD
  11. SgcMake (
  12. OUT PBYTE *ppbStart,
  13. OUT PDWORD pdwSize
  14. )
  15. /*++
  16. Routine Description:
  17. Creates a SAMPLE global configuration block.
  18. Callee should take care to deallocate the configuration block once done.
  19. Arguments:
  20. ppbStart pointer to the configuration block address
  21. pdwSize pointer to size of the configuration block
  22. Return Value:
  23. NO_ERROR, ERROR_NOT_ENOUGH_MEMORY
  24. --*/
  25. {
  26. *pdwSize = sizeof(IPSAMPLE_GLOBAL_CONFIG);
  27. *ppbStart = MALLOC(*pdwSize);
  28. if (*ppbStart is NULL)
  29. return ERROR_NOT_ENOUGH_MEMORY;
  30. CopyMemory(*ppbStart, g_ceSample.pDefaultGlobal, *pdwSize);
  31. return NO_ERROR;
  32. }
  33. DWORD
  34. SgcShow (
  35. IN FORMAT fFormat
  36. )
  37. /*++
  38. Routine Description:
  39. Displays SAMPLE global configuration.
  40. Used for dump as well as show commands.
  41. Arguments:
  42. hFile NULL, or dump file handle
  43. Return Value:
  44. NO_ERROR
  45. --*/
  46. {
  47. DWORD dwErr = NO_ERROR;
  48. PIPSAMPLE_GLOBAL_CONFIG pigc = NULL;
  49. DWORD dwBlockSize, dwNumBlocks;
  50. PWCHAR pwszLogLevel = NULL;
  51. VALUE_TOKEN vtLogLevelTable[] =
  52. {
  53. IPSAMPLE_LOGGING_NONE, TOKEN_NONE,
  54. IPSAMPLE_LOGGING_ERROR, TOKEN_ERROR,
  55. IPSAMPLE_LOGGING_WARN, TOKEN_WARN,
  56. IPSAMPLE_LOGGING_INFO, TOKEN_INFO
  57. };
  58. VALUE_STRING vsLogLevelTable[] =
  59. {
  60. IPSAMPLE_LOGGING_NONE, STRING_LOGGING_NONE,
  61. IPSAMPLE_LOGGING_ERROR, STRING_LOGGING_ERROR,
  62. IPSAMPLE_LOGGING_WARN, STRING_LOGGING_WARN,
  63. IPSAMPLE_LOGGING_INFO, STRING_LOGGING_INFO
  64. };
  65. do // breakout loop
  66. {
  67. // get global configuration
  68. dwErr = GetGlobalConfiguration(MS_IP_SAMPLE,
  69. (PBYTE *) &pigc,
  70. &dwBlockSize,
  71. &dwNumBlocks);
  72. if (dwErr isnot NO_ERROR)
  73. {
  74. if (dwErr is ERROR_NOT_FOUND)
  75. dwErr = EMSG_PROTO_NO_GLOBAL_CONFIG;
  76. break;
  77. }
  78. // getting logging mode string
  79. dwErr = GetString(g_hModule,
  80. fFormat,
  81. pigc->dwLoggingLevel,
  82. vtLogLevelTable,
  83. vsLogLevelTable,
  84. NUM_VALUES_IN_TABLE(vtLogLevelTable),
  85. &pwszLogLevel);
  86. if (dwErr isnot NO_ERROR)
  87. break;
  88. // dump or show
  89. if (fFormat is FORMAT_DUMP)
  90. {
  91. // dump SAMPLE global configuration
  92. DisplayMessageT(DMP_SAMPLE_INSTALL) ;
  93. DisplayMessageT(DMP_SAMPLE_SET_GLOBAL,
  94. pwszLogLevel);
  95. } else {
  96. // show SAMPLE global configuration
  97. DisplayMessage(g_hModule,
  98. MSG_SAMPLE_GLOBAL_CONFIG,
  99. pwszLogLevel);
  100. }
  101. dwErr = NO_ERROR;
  102. } while (FALSE);
  103. // deallocate memory
  104. if (pigc) FREE(pigc);
  105. if (pwszLogLevel) FreeString(pwszLogLevel);
  106. if (dwErr isnot NO_ERROR)
  107. {
  108. // display error message. We first search for the error code in
  109. // the module specified by the caller (if one is specified). If no
  110. // module is given, or the error code doesnt exist we look for MPR
  111. // errors, RAS errors and Win32 errors - in that order.
  112. if (fFormat isnot FORMAT_DUMP) DisplayError(g_hModule, dwErr);
  113. dwErr = ERROR_SUPPRESS_OUTPUT;
  114. }
  115. return dwErr;
  116. }
  117. DWORD
  118. SgcUpdate (
  119. IN PIPSAMPLE_GLOBAL_CONFIG pigcNew,
  120. IN DWORD dwBitVector
  121. )
  122. /*++
  123. Routine Description:
  124. Updates SAMPLE global configuration
  125. Arguments:
  126. pigcNew new values to be set
  127. dwBitVector which fields need to be modified
  128. Return Value:
  129. NO_ERROR, ERROR_NOT_ENOUGH_MEMORY
  130. --*/
  131. {
  132. DWORD dwErr = NO_ERROR;
  133. PIPSAMPLE_GLOBAL_CONFIG pigc = NULL;
  134. DWORD dwBlockSize, dwNumBlocks;
  135. // no updates required
  136. if (dwBitVector is 0)
  137. return NO_ERROR;
  138. do // breakout loop
  139. {
  140. // get global configuration
  141. dwErr = GetGlobalConfiguration(MS_IP_SAMPLE,
  142. (PBYTE *) &pigc,
  143. &dwBlockSize,
  144. &dwNumBlocks);
  145. if (dwErr isnot NO_ERROR)
  146. break;
  147. // can be updated in place since only fixed sized fields
  148. if (dwBitVector & SAMPLE_LOG_MASK)
  149. pigc->dwLoggingLevel = pigcNew->dwLoggingLevel;
  150. // set the new configuration
  151. dwErr = SetGlobalConfiguration(MS_IP_SAMPLE,
  152. (PBYTE) pigc,
  153. dwBlockSize,
  154. dwNumBlocks);
  155. if (dwErr isnot NO_ERROR)
  156. break;
  157. } while (FALSE);
  158. // deallocate memory
  159. if (pigc) FREE(pigc);
  160. return dwErr;
  161. }
  162. DWORD
  163. SicMake (
  164. OUT PBYTE *ppbStart,
  165. OUT PDWORD pdwSize
  166. )
  167. /*++
  168. Routine Description:
  169. Creates a SAMPLE interface configuration block.
  170. Callee should take care to deallocate the configuration block once done.
  171. Arguments:
  172. ppbStart pointer to the configuration block address
  173. pdwSize pointer to size of the configuration block
  174. Return Value:
  175. NO_ERROR, ERROR_NOT_ENOUGH_MEMORY
  176. --*/
  177. {
  178. *pdwSize = sizeof(IPSAMPLE_IF_CONFIG);
  179. *ppbStart = MALLOC(*pdwSize);
  180. if (*ppbStart is NULL)
  181. return ERROR_NOT_ENOUGH_MEMORY;
  182. CopyMemory(*ppbStart, g_ceSample.pDefaultInterface, *pdwSize);
  183. return NO_ERROR;
  184. }
  185. DWORD
  186. SicShowAll (
  187. IN FORMAT fFormat
  188. )
  189. /*++
  190. Routine Description:
  191. Displays SAMPLE configuration for all interfaces.
  192. Used for dump as well as show commands.
  193. Arguments:
  194. fFormat TABLE or DUMP
  195. --*/
  196. {
  197. DWORD dwErr = NO_ERROR;
  198. BOOL bSomethingDisplayed = FALSE;
  199. PMPR_INTERFACE_0 pmi0;
  200. DWORD dwCount, dwTotal;
  201. ULONG i;
  202. // enumerate all interfaces
  203. dwErr = IpmontrInterfaceEnum((PBYTE *) &pmi0, &dwCount, &dwTotal);
  204. if (dwErr isnot NO_ERROR)
  205. {
  206. if (fFormat isnot FORMAT_DUMP) DisplayError(g_hModule, dwErr);
  207. return ERROR_SUPPRESS_OUTPUT;
  208. }
  209. for(i = 0; i < dwCount; i++)
  210. {
  211. // make sure that SAMPLE is configured on that interface
  212. if (IsInterfaceInstalled(pmi0[i].wszInterfaceName, MS_IP_SAMPLE))
  213. {
  214. // print table header if first entry
  215. if (!bSomethingDisplayed and (fFormat is FORMAT_TABLE))
  216. DisplayMessage(g_hModule, MSG_SAMPLE_IF_CONFIG_HEADER);
  217. bSomethingDisplayed = TRUE;
  218. SicShow(fFormat, pmi0[i].wszInterfaceName);
  219. }
  220. }
  221. return bSomethingDisplayed ? NO_ERROR : ERROR_OKAY;
  222. }
  223. DWORD
  224. SicShow (
  225. IN FORMAT fFormat,
  226. IN LPCWSTR pwszInterfaceGuid
  227. )
  228. /*++
  229. Routine Description:
  230. Displays SAMPLE configuration for an interface.
  231. Used for dump as well as show commands.
  232. Arguments:
  233. pwszInterfaceGuid interface name
  234. --*/
  235. {
  236. DWORD dwErr = NO_ERROR;
  237. PIPSAMPLE_IF_CONFIG piic = NULL;
  238. DWORD dwBlockSize, dwNumBlocks, dwIfType;
  239. PWCHAR pwszInterfaceName = NULL;
  240. do // breakout loop
  241. {
  242. // get interface configuration
  243. dwErr = GetInterfaceConfiguration(pwszInterfaceGuid,
  244. MS_IP_SAMPLE,
  245. (PBYTE *) &piic,
  246. &dwBlockSize,
  247. &dwNumBlocks,
  248. &dwIfType);
  249. if (dwErr isnot NO_ERROR)
  250. {
  251. if (dwErr is ERROR_NOT_FOUND)
  252. dwErr = EMSG_PROTO_NO_IF_CONFIG;
  253. break;
  254. }
  255. // get quoted friendly name for interface
  256. dwErr = QuotedInterfaceNameFromGuid(pwszInterfaceGuid,
  257. &pwszInterfaceName);
  258. if (dwErr isnot NO_ERROR)
  259. break;
  260. // dump or show
  261. switch(fFormat)
  262. {
  263. case FORMAT_DUMP: // dump SAMPLE interface configuration
  264. DisplayMessage(g_hModule,
  265. DMP_SAMPLE_INTERFACE_HEADER,
  266. pwszInterfaceName);
  267. DisplayMessageT(DMP_SAMPLE_ADD_INTERFACE,
  268. pwszInterfaceName,
  269. piic->ulMetric);
  270. break;
  271. case FORMAT_TABLE: // show sample interface configuration
  272. DisplayMessage(g_hModule,
  273. MSG_SAMPLE_IF_CONFIG_ENTRY,
  274. pwszInterfaceName,
  275. piic->ulMetric);
  276. break;
  277. case FORMAT_VERBOSE: // show sample interface configuration
  278. DisplayMessage(g_hModule,
  279. MSG_SAMPLE_IF_CONFIG,
  280. pwszInterfaceName,
  281. piic->ulMetric);
  282. break;
  283. }
  284. } while (FALSE);
  285. // deallocate memory
  286. if (piic) FREE(piic);
  287. if (pwszInterfaceName)
  288. FreeQuotedString(pwszInterfaceName);
  289. // display error message.
  290. if (dwErr isnot NO_ERROR)
  291. {
  292. if (fFormat isnot FORMAT_DUMP) DisplayError(g_hModule, dwErr);
  293. dwErr = ERROR_SUPPRESS_OUTPUT;
  294. }
  295. return dwErr;
  296. }
  297. DWORD
  298. SicUpdate (
  299. IN LPCWSTR pwszInterfaceGuid,
  300. IN PIPSAMPLE_IF_CONFIG piicNew,
  301. IN DWORD dwBitVector,
  302. IN BOOL bAdd
  303. )
  304. /*++
  305. Routine Description:
  306. Updates SAMPLE interface configuration
  307. Arguments:
  308. pwszInterfaceGuid interface name
  309. piicNew the changes to be applied
  310. dwBitVector which fields need to be modified
  311. bAdd interface being added (TRUE) or set (FALSE)
  312. Return Value:
  313. NO_ERROR, ERROR_NOT_ENOUGH_MEMORY
  314. --*/
  315. {
  316. DWORD dwErr = NO_ERROR;
  317. PIPSAMPLE_IF_CONFIG piic = NULL;
  318. DWORD dwBlockSize, dwNumBlocks, dwIfType;
  319. do // breakout loop
  320. {
  321. if (bAdd)
  322. {
  323. // create default protocol interface configuration
  324. dwNumBlocks = 1;
  325. dwErr = SicMake((PBYTE *)&piic, &dwBlockSize);
  326. if (dwErr isnot NO_ERROR)
  327. break;
  328. } else {
  329. // get current protocol interface configuration
  330. dwErr = GetInterfaceConfiguration(pwszInterfaceGuid,
  331. MS_IP_SAMPLE,
  332. (PBYTE *) &piic,
  333. &dwBlockSize,
  334. &dwNumBlocks,
  335. &dwIfType);
  336. if (dwErr isnot NO_ERROR)
  337. {
  338. if (dwErr is ERROR_NOT_FOUND)
  339. {
  340. DisplayError(g_hModule, EMSG_PROTO_NO_IF_CONFIG);
  341. dwErr = ERROR_SUPPRESS_OUTPUT;
  342. }
  343. break;
  344. }
  345. }
  346. // can be updated in place since only fixed sized fields
  347. if (dwBitVector & SAMPLE_IF_METRIC_MASK)
  348. piic->ulMetric = piicNew->ulMetric;
  349. // set the new configuration
  350. dwErr = SetInterfaceConfiguration(pwszInterfaceGuid,
  351. MS_IP_SAMPLE,
  352. (PBYTE) piic,
  353. dwBlockSize,
  354. dwNumBlocks);
  355. if (dwErr isnot NO_ERROR)
  356. break;
  357. } while (FALSE);
  358. // deallocate memory
  359. if (piic) FREE(piic);
  360. return dwErr;
  361. }