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.

380 lines
15 KiB

  1. /*
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. UnAttend.cpp
  5. Abstract:
  6. Reads entries from the ini file and adds them to the registry.We assume that the
  7. ini file key name and registry key name are the same.
  8. Revision History:
  9. created a-josem 12/11/00
  10. revised a-josem 12/12/00 Changed TCHAR to WCHAR, moved the global variables to
  11. local scope.
  12. */
  13. #include "UnAttend.h"
  14. /*
  15. This generic structure has the Key Name, datatype of the key and iterate says if
  16. the Key Name is to be appended with 1,2,3.. or used directly.
  17. */
  18. struct RegEntries
  19. {
  20. WCHAR strIniKey[MAX_PATH];//Name of the key in the Ini file
  21. WCHAR strKey[MAX_PATH]; //Name of the key in the registry
  22. DWORD dwType; //Type of the key to be used when writing into the registry
  23. BOOL bIterate; //TRUE or FALSE for iterating 1,2,3,....
  24. };
  25. #define ARRAYSIZE(a) (sizeof(a)/sizeof(*a))
  26. //Section name in the registry.
  27. static const WCHAR strSection[] = L"PCHealth";
  28. static const WCHAR strErrorReportingSubKey[] = L"SOFTWARE\\Microsoft\\PCHealth\\ErrorReporting\\";
  29. static const RegEntries ErrorReportingRegEntries[] =
  30. {
  31. {L"ER_Display_UI",L"ShowUI",REG_DWORD,FALSE},
  32. {L"ER_Enable_Kernel_Errors",L"IncludeKernelFaults",REG_DWORD,FALSE},
  33. {L"ER_Enable_Reporting",L"DoReport",REG_DWORD,FALSE},
  34. {L"ER_Enable_Windows_Components",L"IncludeWindowsApps",REG_DWORD,FALSE},
  35. {L"ER_Include_MSApps",L"IncludeMicrosoftApps",REG_DWORD,FALSE},
  36. {L"ER_Force_Queue_Mode",L"ForceQueueMode",REG_DWORD,FALSE},
  37. {L"ER_Include_Shutdown_Errs",L"IncludeShutdownErrs",REG_DWORD,FALSE},
  38. };
  39. static const WCHAR strExclusionSubKey[] = L"SOFTWARE\\Microsoft\\PCHealth\\ErrorReporting\\ExclusionList\\";
  40. static const RegEntries ExclusionRegEntries[] =
  41. {
  42. {L"ER_Exclude_EXE",L"",REG_DWORD,TRUE}
  43. };
  44. static const WCHAR strInclusionSubKey[] = L"SOFTWARE\\Microsoft\\PCHealth\\ErrorReporting\\InclusionList\\";
  45. static const RegEntries InclusionRegEntries[] =
  46. {
  47. {L"ER_Include_EXE",L"",REG_DWORD,TRUE}
  48. };
  49. static const WCHAR strTerminalServerSubKey[] = L"SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\";
  50. static const RegEntries TerminalServerRegEntries[] =
  51. {
  52. {L"RA_AllowToGetHelp",L"fAllowToGetHelp",REG_DWORD,FALSE},
  53. {L"RA_AllowUnSolicited",L"fAllowUnsolicited",REG_DWORD,FALSE},
  54. {L"RA_AllowFullControl",L"fAllowFullControl",REG_DWORD,FALSE},
  55. {L"RA_AllowRemoteAssistance",L"fAllowRemoteAssistance",REG_DWORD,FALSE},
  56. // {L"RA_MaxTicketExpiry",L"MaxTicketExpiry",REG_DWORD,FALSE},
  57. };
  58. /*++
  59. Routine Description:
  60. Reads ini file and adds those values in the registry
  61. Arguments:
  62. lpstrSubKey - SubKey under which the entries are to be made.
  63. arrRegEntries - Array of RegEntries structure
  64. nCount - Count of elements in the array.
  65. Return Value:
  66. TRUE or FALSE depending on the Registry key opening.
  67. --*/
  68. static BOOL UnAttendedSetup(LPCWSTR lpstrSubKey,const RegEntries *arrRegEntries,int nCount)
  69. {
  70. //Ini File Path Temprorary path will be overwritten.
  71. WCHAR strFilePath[MAX_PATH];// = L"C:\\PCHealth.ini";
  72. BOOL fRetVal = TRUE;
  73. HKEY hKey = NULL;
  74. //The Key already exists just open the key.
  75. // BUGBUG: Change this to Create
  76. // Did the changes
  77. DWORD dwDisposition = 0;
  78. if (ERROR_SUCCESS != ::RegCreateKeyEx(HKEY_LOCAL_MACHINE,lpstrSubKey,0,NULL,
  79. REG_OPTION_VOLATILE,KEY_WRITE,NULL,&hKey,&dwDisposition))
  80. {
  81. fRetVal = FALSE;
  82. goto doneUnAttend;
  83. }
  84. //Comment out the following three lines for testing purposes.
  85. GetSystemDirectory(strFilePath,MAX_PATH);
  86. lstrcat(strFilePath,TEXT("\\"));
  87. lstrcat(strFilePath,WINNT_GUI_FILE);
  88. ///////
  89. WCHAR strRetVal[MAX_PATH];
  90. for (int nIndex = 0; nIndex < nCount; nIndex++)
  91. {
  92. if (arrRegEntries[nIndex].bIterate == FALSE)
  93. {
  94. if (GetPrivateProfileString(strSection,arrRegEntries[nIndex].strIniKey,
  95. NULL,strRetVal,MAX_PATH,strFilePath) != 0)
  96. {
  97. if (arrRegEntries[nIndex].dwType == REG_DWORD)
  98. {
  99. DWORD nVal = 0;
  100. nVal = _wtol(strRetVal);
  101. RegSetValueEx(hKey,arrRegEntries[nIndex].strKey,0,REG_DWORD,
  102. (unsigned char *)&nVal,sizeof(DWORD));
  103. }
  104. else if (arrRegEntries[nIndex].dwType == REG_SZ)
  105. {
  106. RegSetValueEx(hKey,arrRegEntries[nIndex].strKey,0,REG_SZ,
  107. (LPBYTE)strRetVal, (lstrlen(strRetVal) + 1) * sizeof(WCHAR) );
  108. }
  109. }
  110. }
  111. else
  112. {
  113. if(arrRegEntries[nIndex].dwType == REG_DWORD)
  114. {
  115. int nCount = 0;
  116. int nFileIndex = 0;
  117. do
  118. {
  119. WCHAR strFileTagName[MAX_PATH];
  120. WCHAR strI[10];
  121. lstrcpy(strFileTagName,arrRegEntries[nIndex].strIniKey);
  122. _itow(++nFileIndex,strI,10);
  123. lstrcat(strFileTagName,strI);
  124. nCount = GetPrivateProfileString(strSection,strFileTagName,0,
  125. strRetVal,MAX_PATH,strFilePath);
  126. if (nCount)
  127. {
  128. DWORD dwVal = 1;
  129. RegSetValueEx(hKey,strRetVal,0,REG_DWORD,
  130. (unsigned char*)&dwVal,sizeof(DWORD));
  131. }
  132. }while(nCount);
  133. }
  134. }
  135. }
  136. doneUnAttend:
  137. if (hKey)
  138. RegCloseKey(hKey);
  139. return fRetVal;
  140. }
  141. /*++
  142. Routine Description:
  143. Handles the special case of ER_Enable_Application
  144. Arguments:
  145. lpstrSubKey - SubKey under which the entries are to be made.
  146. Return Value:
  147. TRUE or FALSE depending on the Registry key opening.
  148. --*/
  149. static BOOL ErrorReportingSpecialCase(LPCWSTR lpstrSubKey)
  150. {
  151. //Ini File Path temprorary path will be overwritten.
  152. WCHAR strFilePath[MAX_PATH];// = L"C:\\PCHealth.ini";
  153. BOOL fRetVal = TRUE;
  154. //Handling special cases
  155. WCHAR strRetVal[MAX_PATH];
  156. HKEY hKey = NULL;
  157. DWORD dwDisposition = 0;
  158. if (ERROR_SUCCESS != ::RegCreateKeyEx(HKEY_LOCAL_MACHINE,lpstrSubKey,0,NULL,
  159. REG_OPTION_VOLATILE,KEY_WRITE,NULL,&hKey,&dwDisposition))
  160. {
  161. fRetVal = FALSE;
  162. goto done;
  163. }
  164. //Comment out the following three lines for testing purposes.
  165. GetSystemDirectory(strFilePath,MAX_PATH);
  166. lstrcat(strFilePath,TEXT("\\"));
  167. lstrcat(strFilePath,WINNT_GUI_FILE);
  168. ///////
  169. if (GetPrivateProfileString(strSection,TEXT("ER_Enable_Applications"),NULL,
  170. strRetVal,MAX_PATH,strFilePath) != 0)
  171. {
  172. DWORD nVal = 0;
  173. if (!lstrcmpi(L"all",strRetVal))
  174. {
  175. nVal = 1;
  176. RegSetValueEx(hKey,L"AllOrNone",0,REG_DWORD,
  177. (unsigned char *)&nVal,sizeof(DWORD));
  178. }
  179. else if (!lstrcmpi(L"Listed",strRetVal))
  180. {
  181. nVal = 0;
  182. RegSetValueEx(hKey,L"AllOrNone",0,REG_DWORD,
  183. (unsigned char *)&nVal,sizeof(DWORD));
  184. }
  185. else if (!lstrcmpi(L"None",strRetVal))
  186. {
  187. nVal = 2;
  188. RegSetValueEx(hKey,L"AllOrNone",0,REG_DWORD,
  189. (unsigned char *)&nVal,sizeof(DWORD));
  190. }
  191. }
  192. done:
  193. if (hKey)
  194. RegCloseKey(hKey);
  195. return fRetVal;
  196. }
  197. static BOOL TerminalServerSpecialCase(LPCWSTR lpstrSubKey)
  198. {
  199. //Ini File Path temprorary path will be overwritten.
  200. WCHAR strFilePath[MAX_PATH];// = L"C:\\PCHealth.ini";
  201. BOOL fRetVal = TRUE;
  202. //Handling special cases
  203. WCHAR strRetVal[MAX_PATH];
  204. HKEY hKey = NULL;
  205. DWORD dwDisposition = 0;
  206. if (ERROR_SUCCESS != ::RegCreateKeyEx(HKEY_LOCAL_MACHINE,lpstrSubKey,0,NULL,
  207. REG_OPTION_VOLATILE,KEY_WRITE,NULL,&hKey,&dwDisposition))
  208. {
  209. fRetVal = FALSE;
  210. goto done;
  211. }
  212. //Comment out the following three lines for testing purposes.
  213. GetSystemDirectory(strFilePath,MAX_PATH);
  214. lstrcat(strFilePath,TEXT("\\"));
  215. lstrcat(strFilePath,WINNT_GUI_FILE);
  216. ///////
  217. if (GetPrivateProfileString(strSection,TEXT("RA_MaxTicketExpiry_Units"),NULL,
  218. strRetVal,MAX_PATH,strFilePath) != 0)
  219. {
  220. DWORD nVal = 0;
  221. if (!lstrcmpi(L"days",strRetVal))
  222. {
  223. nVal = 2;
  224. RegSetValueEx(hKey,L"MaxTicketExpiryUnits",0,REG_DWORD,
  225. (unsigned char *)&nVal,sizeof(DWORD));
  226. if (GetPrivateProfileString(strSection,TEXT("RA_MaxTicketExpiry"),NULL,
  227. strRetVal,MAX_PATH,strFilePath) != 0)
  228. {
  229. DWORD nVal = 0;
  230. nVal = _wtol(strRetVal);
  231. RegSetValueEx(hKey,L"MaxTicketExpiry",0,REG_DWORD,
  232. (unsigned char *)&nVal,sizeof(DWORD));
  233. }
  234. }
  235. else if (!lstrcmpi(L"hours",strRetVal))
  236. {
  237. nVal = 1;
  238. RegSetValueEx(hKey,L"MaxTicketExpiryUnits",0,REG_DWORD,
  239. (unsigned char *)&nVal,sizeof(DWORD));
  240. if (GetPrivateProfileString(strSection,TEXT("RA_MaxTicketExpiry"),NULL,
  241. strRetVal,MAX_PATH,strFilePath) != 0)
  242. {
  243. DWORD nVal = 0;
  244. nVal = _wtol(strRetVal);
  245. RegSetValueEx(hKey,L"MaxTicketExpiry",0,REG_DWORD,
  246. (unsigned char *)&nVal,sizeof(DWORD));
  247. }
  248. }
  249. else if (!lstrcmpi(L"minutes",strRetVal))
  250. {
  251. nVal = 0;
  252. RegSetValueEx(hKey,L"MaxTicketExpiryUnits",0,REG_DWORD,
  253. (unsigned char *)&nVal,sizeof(DWORD));
  254. if (GetPrivateProfileString(strSection,TEXT("RA_MaxTicketExpiry"),NULL,
  255. strRetVal,MAX_PATH,strFilePath) != 0)
  256. {
  257. DWORD nVal = 0;
  258. nVal = _wtol(strRetVal);
  259. RegSetValueEx(hKey,L"MaxTicketExpiry",0,REG_DWORD,
  260. (unsigned char *)&nVal,sizeof(DWORD));
  261. }
  262. }
  263. else
  264. {
  265. if (GetPrivateProfileString(strSection,TEXT("RA_MaxTicketExpiry"),NULL,
  266. strRetVal,MAX_PATH,strFilePath) != 0)
  267. {
  268. DWORD nVal = 0;
  269. nVal = _wtol(strRetVal);
  270. if (nVal > 0)
  271. {
  272. nVal = nVal / 60;
  273. if (nVal == 0) nVal = 1;
  274. }
  275. RegSetValueEx(hKey,L"MaxTicketExpiry",0,REG_DWORD,
  276. (unsigned char *)&nVal,sizeof(DWORD));
  277. }
  278. }
  279. }
  280. else //default is minutes
  281. {
  282. if (GetPrivateProfileString(strSection,TEXT("RA_MaxTicketExpiry"),NULL,
  283. strRetVal,MAX_PATH,strFilePath) != 0)
  284. {
  285. DWORD nVal = 0;
  286. nVal = _wtol(strRetVal);
  287. if (nVal > 0)
  288. {
  289. nVal = nVal / 60;
  290. if (nVal == 0)
  291. nVal = 1;
  292. RegSetValueEx(hKey,L"MaxTicketExpiry",0,REG_DWORD,
  293. (unsigned char *)&nVal,sizeof(DWORD));
  294. nVal = 0;
  295. RegSetValueEx(hKey,L"MaxTicketExpiryUnits",0,REG_DWORD,
  296. (unsigned char *)&nVal,sizeof(DWORD));
  297. }
  298. }
  299. }
  300. done:
  301. if (hKey)
  302. RegCloseKey(hKey);
  303. return fRetVal;
  304. }
  305. /*++
  306. Routine Description:
  307. To be called from Register Server.
  308. Arguments:
  309. None
  310. Return Value:
  311. TRUE or FALSE depending on the Registry key opening.
  312. --*/
  313. BOOL PCHealthUnAttendedSetup()
  314. {
  315. BOOL bRetVal1,bRetVal2,bRetVal3,bRetVal4;
  316. ErrorReportingSpecialCase(strErrorReportingSubKey);
  317. TerminalServerSpecialCase(strTerminalServerSubKey);
  318. bRetVal1 = UnAttendedSetup(strErrorReportingSubKey,
  319. ErrorReportingRegEntries,ARRAYSIZE(ErrorReportingRegEntries));
  320. bRetVal2 = UnAttendedSetup(strExclusionSubKey,ExclusionRegEntries,
  321. ARRAYSIZE(ExclusionRegEntries));
  322. bRetVal3 = UnAttendedSetup(strInclusionSubKey,InclusionRegEntries,
  323. ARRAYSIZE(InclusionRegEntries));
  324. bRetVal4 = UnAttendedSetup(strTerminalServerSubKey,TerminalServerRegEntries,
  325. ARRAYSIZE(TerminalServerRegEntries));
  326. if ((bRetVal1== TRUE) && (bRetVal2 == TRUE) && (bRetVal3 == TRUE) &&
  327. (bRetVal4 == TRUE))
  328. return TRUE;
  329. else
  330. return FALSE;
  331. }