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.

163 lines
4.6 KiB

  1. #include "stdafx.h"
  2. #include "resource.h"
  3. #include "common.h"
  4. #include "remoteenv.h"
  5. #include "util.h"
  6. #include "defaults.h"
  7. #include <strsafe.h>
  8. #define DEFAULT_ROOT_KEY HKEY_LOCAL_MACHINE
  9. const TCHAR g_szRegistryKey[] = _T("SOFTWARE\\Microsoft\\InetMgr");
  10. const TCHAR g_szRegistryKeyOurs[] = _T("IISUIObj\\ImportExport");
  11. void GetRegistryPath(CString &str)
  12. {
  13. str = g_szRegistryKey;
  14. str += _T("\\");
  15. str += g_szRegistryKeyOurs;
  16. }
  17. BOOL CreateInitialRegPath(LPCTSTR lpszMachineName)
  18. {
  19. BOOL bRet = FALSE;
  20. HKEY hKey = NULL;
  21. HKEY RootKey = DEFAULT_ROOT_KEY;
  22. TCHAR szMachineName[MAX_COMPUTERNAME_LENGTH + 3];
  23. CString strRegKey;
  24. GetRegistryPath(strRegKey);
  25. if (lpszMachineName && 0 != _tcscmp(lpszMachineName,_T("")))
  26. {
  27. // check if lpszMachineName already starts with "\\"
  28. if (lpszMachineName[0] == _T('\\') && lpszMachineName[1] == _T('\\'))
  29. {
  30. StringCbCopy(szMachineName, sizeof(szMachineName), lpszMachineName);
  31. }
  32. else
  33. {
  34. StringCbCopy(szMachineName, sizeof(szMachineName), _T("\\\\"));
  35. StringCbCat(szMachineName, sizeof(szMachineName), lpszMachineName);
  36. }
  37. if (ERROR_SUCCESS != RegConnectRegistry((LPTSTR) szMachineName,DEFAULT_ROOT_KEY,&RootKey))
  38. {
  39. return(FALSE);
  40. }
  41. }
  42. if (ERROR_SUCCESS != RegOpenKeyEx(RootKey, strRegKey, 0, KEY_ALL_ACCESS, &hKey))
  43. {
  44. if (ERROR_SUCCESS == RegOpenKeyEx(RootKey,g_szRegistryKey, 0, KEY_CREATE_SUB_KEY, &hKey))
  45. {
  46. HKEY hWizardKey;
  47. if (ERROR_SUCCESS == RegCreateKey(hKey, g_szRegistryKeyOurs, &hWizardKey))
  48. {
  49. bRet = TRUE;
  50. RegCloseKey(hWizardKey);
  51. }
  52. RegCloseKey(hKey);
  53. }
  54. }
  55. else
  56. {
  57. RegCloseKey(hKey);
  58. }
  59. return bRet;
  60. }
  61. BOOL DefaultValueSettingsLoad(LPCTSTR lpszMachineName, LPCTSTR szRegItem, TCHAR * szReturnValue)
  62. {
  63. BOOL bRet = FALSE;
  64. HKEY hKey = NULL;
  65. HKEY RootKey = DEFAULT_ROOT_KEY;
  66. TCHAR szMachineName[MAX_COMPUTERNAME_LENGTH + 3];
  67. CString strRegKey;
  68. GetRegistryPath(strRegKey);
  69. if (lpszMachineName && 0 != _tcscmp(lpszMachineName,_T("")))
  70. {
  71. // check if lpszMachineName already starts with "\\"
  72. if (lpszMachineName[0] == _T('\\') && lpszMachineName[1] == _T('\\'))
  73. {
  74. StringCbCopy(szMachineName, sizeof(szMachineName), lpszMachineName);
  75. }
  76. else
  77. {
  78. StringCbCopy(szMachineName, sizeof(szMachineName), _T("\\\\"));
  79. StringCbCat(szMachineName, sizeof(szMachineName), lpszMachineName);
  80. }
  81. if (ERROR_SUCCESS != RegConnectRegistry((LPTSTR) szMachineName,DEFAULT_ROOT_KEY,&RootKey))
  82. {
  83. return(FALSE);
  84. }
  85. }
  86. if (ERROR_SUCCESS == RegOpenKeyEx(RootKey, strRegKey, 0, KEY_READ, &hKey))
  87. {
  88. DWORD dwType;
  89. DWORD cbData;
  90. if (hKey != NULL)
  91. {
  92. BYTE * pName = NULL;
  93. if (ERROR_SUCCESS == RegQueryValueEx(hKey, szRegItem, NULL, &dwType, NULL, &cbData))
  94. {
  95. pName = (BYTE *) szReturnValue;
  96. RegQueryValueEx(hKey, szRegItem, NULL, &dwType, pName, &cbData);
  97. if (pName != NULL)
  98. {
  99. pName = NULL;
  100. bRet = TRUE;
  101. }
  102. }
  103. RegCloseKey(hKey);
  104. }
  105. }
  106. return bRet;
  107. }
  108. BOOL DefaultValueSettingsSave(LPCTSTR lpszMachineName, LPCTSTR szRegItem, LPCTSTR szInputValue)
  109. {
  110. BOOL bRet = FALSE;
  111. HKEY hKey = NULL;
  112. HKEY RootKey = DEFAULT_ROOT_KEY;
  113. TCHAR szMachineName[MAX_COMPUTERNAME_LENGTH + 3];
  114. CString strRegKey;
  115. GetRegistryPath(strRegKey);
  116. CreateInitialRegPath(lpszMachineName);
  117. if (lpszMachineName && 0 != _tcscmp(lpszMachineName,_T("")))
  118. {
  119. // check if lpszMachineName already starts with "\\"
  120. if (lpszMachineName[0] == _T('\\') && lpszMachineName[1] == _T('\\'))
  121. {
  122. StringCbCopy(szMachineName, sizeof(szMachineName), lpszMachineName);
  123. }
  124. else
  125. {
  126. StringCbCopy(szMachineName, sizeof(szMachineName), _T("\\\\"));
  127. StringCbCat(szMachineName, sizeof(szMachineName), lpszMachineName);
  128. }
  129. if (ERROR_SUCCESS != RegConnectRegistry((LPTSTR) szMachineName,DEFAULT_ROOT_KEY,&RootKey))
  130. {
  131. return(FALSE);
  132. }
  133. }
  134. if (ERROR_SUCCESS == RegOpenKeyEx(RootKey, strRegKey, 0, KEY_ALL_ACCESS, &hKey))
  135. {
  136. if (hKey != NULL)
  137. {
  138. RegSetValueEx(hKey,szRegItem,0,REG_SZ,(const BYTE *)(LPCTSTR)(szInputValue),sizeof(TCHAR) * (_tcslen(szInputValue) + 1));
  139. RegCloseKey(hKey);
  140. bRet = TRUE;
  141. }
  142. }
  143. return bRet;
  144. }