Source code of Windows XP (NT5)
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.

223 lines
4.7 KiB

  1. /*
  2. * Copyright (c) 1998 Microsoft Corporation
  3. *
  4. * Module Name:
  5. *
  6. * registry.cpp
  7. *
  8. * Abstract:
  9. *
  10. * This file handles registry actions needed by License Server setup.
  11. *
  12. * Author:
  13. *
  14. * Breen Hagan (BreenH) Oct-02-98
  15. *
  16. * Environment:
  17. *
  18. * User Mode
  19. */
  20. #include "stdafx.h"
  21. #include "logfile.h"
  22. /*
  23. * Global variables.
  24. */
  25. /*
  26. * Constants.
  27. */
  28. const TCHAR gszLSParamKey[] =
  29. _T("System\\CurrentControlSet\\Services\\TermServLicensing\\Parameters");
  30. const TCHAR gszDatabasePathValue[] = _T("DBPath");
  31. const TCHAR gszServerRoleValue[] = _T("Role");
  32. /*
  33. * Function prototypes.
  34. */
  35. /*
  36. * Function implementations.
  37. */
  38. DWORD
  39. CreateRegistrySettings(
  40. LPCTSTR pszDatabaseDirectory,
  41. DWORD dwServerRole
  42. )
  43. {
  44. DWORD dwErr, dwDisposition;
  45. HKEY hLSParamKey;
  46. LOGMESSAGE(_T("CreateRegistrySettings: Entered with %s, %ld"),
  47. pszDatabaseDirectory, dwServerRole);
  48. dwErr = RegCreateKeyEx(
  49. HKEY_LOCAL_MACHINE,
  50. gszLSParamKey,
  51. 0,
  52. NULL,
  53. REG_OPTION_NON_VOLATILE,
  54. KEY_ALL_ACCESS,
  55. NULL,
  56. &hLSParamKey,
  57. &dwDisposition
  58. );
  59. if (dwErr != ERROR_SUCCESS) {
  60. LOGMESSAGE(_T("CreateRegistrySettings: RegCreateKeyEx: Error %ld"),
  61. dwErr);
  62. return(dwErr);
  63. }
  64. dwErr = RegSetValueEx(
  65. hLSParamKey,
  66. gszDatabasePathValue,
  67. 0,
  68. REG_EXPAND_SZ,
  69. (LPBYTE)pszDatabaseDirectory,
  70. (_tcslen(pszDatabaseDirectory) + 1) * sizeof(TCHAR)
  71. );
  72. if (dwErr != ERROR_SUCCESS) {
  73. RegCloseKey(hLSParamKey);
  74. LOGMESSAGE(_T("CreateRegistrySettings: RegSetValueEx: %s: Error %ld"),
  75. _T("DatabasePath"), dwErr);
  76. return(dwErr);
  77. }
  78. dwErr = RegSetValueEx(
  79. hLSParamKey,
  80. gszServerRoleValue,
  81. 0,
  82. REG_DWORD,
  83. (LPBYTE)&dwServerRole,
  84. sizeof(DWORD)
  85. );
  86. if (dwErr != ERROR_SUCCESS) {
  87. RegCloseKey(hLSParamKey);
  88. LOGMESSAGE(_T("CreateRegistrySettings: RegSetValueEx: %s: Error %ld"),
  89. _T("ServerRole"), dwErr);
  90. return(dwErr);
  91. }
  92. RegCloseKey(hLSParamKey);
  93. return(ERROR_SUCCESS);
  94. }
  95. LPCTSTR
  96. GetDatabaseDirectoryFromRegistry(
  97. VOID
  98. )
  99. {
  100. static TCHAR pRegValue[MAX_PATH + 1];
  101. DWORD dwErr, cbRegValue = (MAX_PATH * sizeof(TCHAR));
  102. HKEY hLSParamKey;
  103. dwErr = RegOpenKeyEx(
  104. HKEY_LOCAL_MACHINE,
  105. gszLSParamKey,
  106. 0,
  107. KEY_READ,
  108. &hLSParamKey
  109. );
  110. if (dwErr != ERROR_SUCCESS) {
  111. return(NULL);
  112. }
  113. dwErr = RegQueryValueEx(
  114. hLSParamKey,
  115. gszDatabasePathValue,
  116. NULL,
  117. NULL,
  118. (LPBYTE)pRegValue,
  119. &cbRegValue
  120. );
  121. if (dwErr != ERROR_SUCCESS) {
  122. return(NULL);
  123. }
  124. RegCloseKey(hLSParamKey);
  125. return(pRegValue);
  126. }
  127. DWORD
  128. GetServerRoleFromRegistry(
  129. VOID
  130. )
  131. {
  132. DWORD dwErr, dwValue, cbValue = sizeof(DWORD);
  133. HKEY hLSParamKey;
  134. dwErr = RegOpenKeyEx(
  135. HKEY_LOCAL_MACHINE,
  136. gszLSParamKey,
  137. 0,
  138. KEY_READ,
  139. &hLSParamKey
  140. );
  141. if (dwErr != ERROR_SUCCESS) {
  142. SetLastError(dwErr);
  143. return((DWORD)-1);
  144. }
  145. dwErr = RegQueryValueEx(
  146. hLSParamKey,
  147. gszServerRoleValue,
  148. NULL,
  149. NULL,
  150. (LPBYTE)&dwValue,
  151. &cbValue
  152. );
  153. if (dwErr != ERROR_SUCCESS) {
  154. SetLastError(dwErr);
  155. return((DWORD)-1);
  156. }
  157. RegCloseKey(hLSParamKey);
  158. return(dwValue);
  159. }
  160. DWORD
  161. RemoveRegistrySettings(
  162. VOID
  163. )
  164. {
  165. DWORD dwErr;
  166. HKEY hLSParamKey;
  167. dwErr = RegOpenKeyEx(
  168. HKEY_LOCAL_MACHINE,
  169. gszLSParamKey,
  170. 0,
  171. KEY_ALL_ACCESS,
  172. &hLSParamKey
  173. );
  174. if (dwErr != ERROR_SUCCESS) {
  175. return(dwErr);
  176. }
  177. dwErr = RegDeleteValue(
  178. hLSParamKey,
  179. gszDatabasePathValue
  180. );
  181. if (dwErr != ERROR_SUCCESS) {
  182. RegCloseKey(hLSParamKey);
  183. return(dwErr);
  184. }
  185. dwErr = RegDeleteValue(
  186. hLSParamKey,
  187. gszServerRoleValue
  188. );
  189. if (dwErr != ERROR_SUCCESS) {
  190. RegCloseKey(hLSParamKey);
  191. return(dwErr);
  192. }
  193. RegCloseKey(hLSParamKey);
  194. return(ERROR_SUCCESS);
  195. }