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.

395 lines
13 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1997
  4. *
  5. * TITLE: MAKEINF.C
  6. *
  7. * VERSION: 2.0
  8. *
  9. * AUTHOR: ReedB
  10. *
  11. * DATE: 1 Jan, 1997
  12. *
  13. * DESCRIPTION:
  14. * Main code for the default power schemes INF generator, MAKEINF.EXE.
  15. * Generates INF file which can be read by Memphis setup.
  16. *
  17. *******************************************************************************/
  18. #include "parse.h"
  19. /*******************************************************************************
  20. *
  21. * WriteRegBinary
  22. *
  23. * DESCRIPTION:
  24. * Write binary data out to the registry specification file.
  25. *
  26. * PARAMETERS:
  27. *
  28. *******************************************************************************/
  29. VOID WriteRegBinary(FILE *fInf, PVOID pv, UINT uiSize, char *pszIndent, char *pszDecoration)
  30. {
  31. PBYTE pb = pv;
  32. UINT uiRow = 0;
  33. fprintf(fInf, "%s%s", pszDecoration, pszIndent);
  34. while (uiSize) {
  35. if (uiSize > 1) {
  36. fprintf(fInf, "%02X,", *pb++);
  37. }
  38. else {
  39. fprintf(fInf, "%02X", *pb++);
  40. }
  41. uiSize--;
  42. if (uiRow++ == 15) {
  43. uiRow = 0;
  44. if (uiSize > 1) {
  45. fprintf(fInf, "\\\n%s%s", pszDecoration, pszIndent);
  46. }
  47. else {
  48. fprintf(fInf, "\n");
  49. }
  50. }
  51. }
  52. }
  53. /*******************************************************************************
  54. *
  55. * WriteInfHeader
  56. *
  57. * DESCRIPTION:
  58. *
  59. * PARAMETERS:
  60. *
  61. *******************************************************************************/
  62. BOOLEAN WriteInfHeader(FILE *fInf)
  63. {
  64. fprintf(fInf, "; POWERCFG.INF\n");
  65. fprintf(fInf, "; Copyright (c) 1993-2000, Microsoft Corporation\n");
  66. fprintf(fInf, "\n");
  67. fprintf(fInf, "[Version]\n");
  68. fprintf(fInf, "Signature = \"$CHICAGO$\"\n");
  69. fprintf(fInf, "SetupClass = BASE\n");
  70. fprintf(fInf, "LayoutFile = layout.inf, layout1.inf\n");
  71. fprintf(fInf, "\n");
  72. fprintf(fInf, "[DestinationDirs]\n");
  73. fprintf(fInf, "PowerCfg.copy.inf = 17 ; LDID_INF\n");
  74. fprintf(fInf, "PowerCfg.copy.sys = 11 ; LDID_SYS\n");
  75. fprintf(fInf, "\n");
  76. fprintf(fInf, "[BaseWinOptions]\n");
  77. fprintf(fInf, "PowerCfg.base\n");
  78. fprintf(fInf, "\n");
  79. fprintf(fInf, "[PowerCfg.base]\n");
  80. fprintf(fInf, "CopyFiles = PowerCfg.copy.inf, PowerCfg.copy.sys\n");
  81. fprintf(fInf, "AddReg = PowerCfg.addreg\n");
  82. fprintf(fInf, "\n");
  83. fprintf(fInf, "[PowerCfg.copy.inf]\n");
  84. fprintf(fInf, "; files to copy to \\windows\\inf directory\n");
  85. fprintf(fInf, "PowerCfg.inf\n");
  86. fprintf(fInf, "\n");
  87. fprintf(fInf, "[PowerCfg.copy.sys]\n");
  88. fprintf(fInf, "; files to copy to \\windows\\system directory\n");
  89. fprintf(fInf, "powercfg.cpl\n");
  90. fprintf(fInf, "powrprof.dll\n");
  91. fprintf(fInf, "batmeter.dll\n");
  92. fprintf(fInf, "\n");
  93. fprintf(fInf, "[PowerCfg.addreg]\n");
  94. return TRUE;
  95. }
  96. /*******************************************************************************
  97. *
  98. * TabTo
  99. *
  100. * DESCRIPTION:
  101. *
  102. * PARAMETERS:
  103. *
  104. *******************************************************************************/
  105. VOID TabTo(FILE *fInf, UINT uiCharSoFar, UINT uiCol)
  106. {
  107. UINT i;
  108. for (i = 0; i < (uiCol - uiCharSoFar); i++) {
  109. fprintf(fInf, " ");
  110. }
  111. }
  112. /*******************************************************************************
  113. *
  114. * WriteNTInf
  115. *
  116. * DESCRIPTION:
  117. * Write out the NT setup file in INF format.
  118. *
  119. * PARAMETERS:
  120. *
  121. *******************************************************************************/
  122. BOOLEAN WriteNTInf(
  123. char **pszName,
  124. char **pszDesc,
  125. char **pszDecoration,
  126. UINT uiCount
  127. )
  128. {
  129. UINT i, sku;
  130. FILE *fInf;
  131. static char skuDecoration[5];
  132. UINT compareVal;
  133. //
  134. // First, write the Software Hive. (Machine policy.)
  135. //
  136. if ((fInf = fopen(MACHINE_INF_NAME, "w+")) != NULL) {
  137. printf("\nWriting Machine INF specification file: %s", MACHINE_INF_NAME);
  138. }
  139. else {
  140. DefFatalExit(TRUE, "Error opening INF specification file: %s for output\n", MACHINE_INF_NAME);
  141. }
  142. // Write fixed header information.
  143. WriteInfHeader(fInf);
  144. printf(".");
  145. //
  146. // Now we write the machine hives, by SKU. SKU 0 is the default SKU.
  147. // it gets written without any decoration. If another SKU is different
  148. // from the default SKU, it gets written, too, but with its own decoration.
  149. //
  150. for (sku = 0; sku < MAX_SKUS; sku++) {
  151. if (sku == 0) {
  152. strcpy(skuDecoration, "\0");
  153. } else {
  154. //printf("\nSKU decoration %s\n", pszDecoration[sku]);
  155. sprintf(skuDecoration, "@%s:", pszDecoration[sku]);
  156. }
  157. compareVal = 1;
  158. if (sku != 0) {
  159. compareVal = memcmp(&g_gmpp[sku],
  160. &g_gmpp[0],
  161. sizeof(GLOBAL_MACHINE_POWER_POLICY));
  162. }
  163. if (compareVal) {
  164. // Machine misc.
  165. fprintf(fInf, "%sHKLM,\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\",\"LastID\",0x00000002,\"%d\"\n", skuDecoration,uiCount - 1);
  166. fprintf(fInf, "%sHKLM,\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\",\"DiskSpinDownMax\",0x00000002,\"3600\"\n", skuDecoration);
  167. fprintf(fInf, "%sHKLM,\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\",\"DiskSpinDownMin\",0x00000002,\"3\"\n", skuDecoration);
  168. fprintf(fInf, "%sHKLM,\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\GlobalPowerPolicy\",\"Policies\",0x00030001,\\\n", skuDecoration);
  169. WriteRegBinary(fInf, &g_gmpp[sku], sizeof(GLOBAL_MACHINE_POWER_POLICY),
  170. " ", skuDecoration);
  171. fprintf(fInf, "%sHKLM,\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\PowerPolicies\",,0x00000012\n", skuDecoration);
  172. fprintf(fInf, "\n\n");
  173. printf(".");
  174. }
  175. for (i = 0; i < uiCount; i++) {
  176. compareVal = 1;
  177. if (sku != 0) {
  178. compareVal = memcmp(g_pmpp[sku][i],
  179. g_pmpp[0][i],
  180. sizeof(MACHINE_POWER_POLICY));
  181. }
  182. if (compareVal) {
  183. fprintf(fInf, "%sHKLM,\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\PowerPolicies\\%d\",\"Policies\",0x00030003,\\\n", skuDecoration, i);
  184. WriteRegBinary(fInf, g_pmpp[sku][i], sizeof(MACHINE_POWER_POLICY)," ", skuDecoration);
  185. fprintf(fInf, "\n");
  186. printf(".");
  187. }
  188. }
  189. for (i = 0; i < uiCount; i++) {
  190. compareVal = 1;
  191. if (sku != 0) {
  192. compareVal = memcmp(g_ppmpp[sku][i],
  193. g_ppmpp[0][i],
  194. sizeof(MACHINE_PROCESSOR_POWER_POLICY));
  195. }
  196. if (compareVal) {
  197. fprintf(fInf, "%sHKLM,\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\ProcessorPolicies\\%d\",\"Policies\",0x00030001,\\\n", skuDecoration, i);
  198. WriteRegBinary(fInf, g_ppmpp[sku][i], sizeof(MACHINE_PROCESSOR_POWER_POLICY)," ", skuDecoration);
  199. fprintf(fInf, "\n");
  200. printf(".");
  201. }
  202. }
  203. }
  204. fclose(fInf);
  205. //
  206. // Next, write the User Hive. (User Policy.)
  207. //
  208. if ((fInf = fopen(USER_INF_NAME, "w+")) != NULL) {
  209. printf("\nWriting User INF specification file: %s\n", USER_INF_NAME);
  210. }
  211. else {
  212. DefFatalExit(TRUE, "Error opening INF specification file: %s for output\n", USER_INF_NAME);
  213. }
  214. // Write fixed header information.
  215. WriteInfHeader(fInf);
  216. printf(".");
  217. // User misc.
  218. fprintf(fInf, "HKCU,\"Control Panel\\PowerCfg\",CurrentPowerPolicy,0x00000002,\"0\"\n");
  219. for (sku = 0; sku < MAX_SKUS; sku++) {
  220. if (sku == 0) {
  221. strcpy(skuDecoration, "\0");
  222. } else {
  223. sprintf(skuDecoration, "@%s:", pszDecoration[sku]);
  224. }
  225. compareVal = 1;
  226. if (sku != 0) {
  227. compareVal = memcmp(&g_gupp[sku],
  228. &g_gupp[0],
  229. sizeof(GLOBAL_USER_POWER_POLICY));
  230. }
  231. if (compareVal) {
  232. // User global policies.
  233. fprintf(fInf, "%sHKCU,\"Control Panel\\PowerCfg\\GlobalPowerPolicy\",Policies,0x00030003,\\\n", skuDecoration);
  234. WriteRegBinary(fInf, &g_gupp[sku], sizeof(GLOBAL_USER_POWER_POLICY), " ", skuDecoration);
  235. fprintf(fInf, "\n\n");
  236. printf(".");
  237. }
  238. // User power schemes.
  239. for (i = 0; i < uiCount; i++) {
  240. compareVal = 1;
  241. if (sku != 0) {
  242. compareVal = memcmp(g_pupp[sku][i],
  243. g_pupp[0][i],
  244. sizeof(USER_POWER_POLICY));
  245. }
  246. if (compareVal) {
  247. fprintf(fInf, "%sHKCU,\"Control Panel\\PowerCfg\\PowerPolicies\\%d\",Name,0x00000002,\"%s\"\n", skuDecoration, i, pszName[i]);
  248. fprintf(fInf, "%sHKCU,\"Control Panel\\PowerCfg\\PowerPolicies\\%d\",Description,0x00000002,\"%s\"\n", skuDecoration, i, pszDesc[i]);
  249. fprintf(fInf, "%sHKCU,\"Control Panel\\PowerCfg\\PowerPolicies\\%d\",Policies,0x00030003,\\\n", skuDecoration, i);
  250. WriteRegBinary(fInf, g_pupp[sku][i], sizeof(USER_POWER_POLICY)," ", skuDecoration);
  251. fprintf(fInf, "\n\n");
  252. printf(".");
  253. }
  254. }
  255. }
  256. fclose(fInf);
  257. printf("OK\n");
  258. return TRUE;
  259. }
  260. /*******************************************************************************
  261. *
  262. * main
  263. *
  264. * DESCRIPTION:
  265. *
  266. * PARAMETERS:
  267. *
  268. *******************************************************************************/
  269. void __cdecl main (int argc, char **argv)
  270. {
  271. DWORD dwSize;
  272. char *psz;
  273. FILE *fInf;
  274. UINT uiNameCount, uiDescCount, i, sku;
  275. char *p;
  276. char *pszName[MAX_PROFILES];
  277. char *pszDesc[MAX_PROFILES];
  278. char *pszDecoration[MAX_SKUS];
  279. char *pszTok;
  280. printf("Building name and description arrays...\n");
  281. ReadSource();
  282. BuildLineArray();
  283. for (sku = 0; sku < MAX_SKUS; sku++) {
  284. printf(" Parsing names, SKU[%d].", sku);
  285. GetCheckLabelToken(SKU_LINE, "SKU Decoration", sku);
  286. pszTok = strtok(NULL, DELIMITERS);
  287. StrTrimTrailingBlanks(pszTok);
  288. pszDecoration[sku] = malloc(5);
  289. if (!pszDecoration[sku]) {
  290. printf("Failed to alloc memory\n");
  291. exit (0);
  292. }
  293. strncpy(pszDecoration[sku], pszTok, 2);
  294. GetCheckLabelToken(NAME_LINE, "Name", sku);
  295. uiNameCount = GetTokens(NULL, REGSTR_MAX_VALUE_LENGTH, pszName,
  296. MAX_PROFILES, DELIMITERS);
  297. if (uiNameCount) {
  298. printf(" Parsed %d names successfully.\n", uiNameCount);
  299. printf(" Parsing descriptions.");
  300. GetCheckLabelToken(DESCRIPTION_LINE, "Description", sku);
  301. uiDescCount = GetTokens(NULL, MAX_DESC_LEN, pszDesc,
  302. MAX_PROFILES, DELIMITERS);
  303. if (uiDescCount == uiNameCount) {
  304. printf(" Parsed %d descriptions successfully.\n", uiDescCount);
  305. g_uiPoliciesCount[sku] = uiNameCount;
  306. }
  307. else {
  308. printf(" Name count: %d != description count: %d.\n", uiNameCount, uiDescCount);
  309. printf("ProcessAndWrite failed, Last Error: %d\n", GetLastError());
  310. exit(1);
  311. }
  312. }
  313. else {
  314. printf(" Name parsing failure.\n");
  315. printf("ProcessAndWrite failed, Last Error: %d\n", GetLastError());
  316. exit(1);
  317. }
  318. }
  319. // Get the power policies, schemes
  320. GetPolicies();
  321. // Get the global power policies
  322. GetGlobalPolicies();
  323. // Write the INF specification files.
  324. WriteNTInf(pszName, pszDesc, pszDecoration, g_uiPoliciesCount[0]);
  325. printf("\n\nDefault Processing Success. Output files are valid.\n");
  326. exit(0);
  327. }