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.

196 lines
4.9 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. hsmdeflt.cpp
  5. Abstract:
  6. This component is an provides functions to access the HSM
  7. default settings. These settings are maintained in the
  8. NT system registry.
  9. Author:
  10. Cat Brant [cbrant] 13-Jan-1997
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "wsb.h"
  15. #include "HsmEng.h"
  16. #include "HsmServ.h"
  17. #include "HsmConn.h"
  18. #include "job.h"
  19. #include "engine.h"
  20. #define WSB_TRACE_IS WSB_TRACE_BIT_HSMENG
  21. enum HSM_PARM_SETTING_VISIBILITY {
  22. HSM_PARM_PERSISTANT = 1, // Always seen in the registry
  23. HSM_PARM_INVISIBLE = 2 // Only written if different from the default
  24. };
  25. HRESULT
  26. CHsmServer::CreateDefaultJobs(
  27. void
  28. )
  29. /*++
  30. Routine Description:
  31. Creates the default jobs and adds them to the engine's data base.
  32. Arguments:
  33. None
  34. Return Value:
  35. S_OK:
  36. --*/
  37. {
  38. HRESULT hr = S_OK;
  39. CComPtr<IHsmJob> pJob;
  40. CComPtr<IHsmStoragePool> pStoragePool;
  41. GUID storagePoolId;
  42. WsbTraceIn(OLESTR("CHsmServer::CreateDefaultJobs"),OLESTR(""));
  43. try {
  44. // Currently the only default job is the manage job.
  45. if (FindJobByName(HSM_DEFAULT_MANAGE_JOB_NAME, &pJob) == WSB_E_NOTFOUND) {
  46. // The manage job needs a storage pool, so make sure that one exists.
  47. hr = m_pStoragePools->First(IID_IHsmStoragePool, (void**) &pStoragePool);
  48. if (hr == WSB_E_NOTFOUND) {
  49. WsbAffirmHr(CoCreateInstance(CLSID_CHsmStoragePool, 0, CLSCTX_ALL, IID_IHsmStoragePool, (void**) &pStoragePool));
  50. WsbAffirmHr(pStoragePool->SetMediaSet(GUID_NULL, OLESTR("Default")));
  51. WsbAssertHr(m_pStoragePools->Add(pStoragePool));
  52. //
  53. // Since we added one, save the data
  54. //
  55. WsbAffirmHr(SavePersistData());
  56. hr = S_OK;
  57. }
  58. WsbAffirmHr(hr);
  59. WsbAssertHr(pStoragePool->GetId(&storagePoolId));
  60. // Create a new job, configure it as a default manage job, and add it
  61. // to the job collection.
  62. WsbAffirmHr(CoCreateInstance(CLSID_CHsmJob, 0, CLSCTX_ALL, IID_IHsmJob, (void**) &pJob));
  63. WsbAffirmHr(pJob->InitAs(HSM_DEFAULT_MANAGE_JOB_NAME, 0, HSM_JOB_DEF_TYPE_MANAGE, storagePoolId, (IHsmServer*) this, FALSE, 0));
  64. WsbAffirmHr(m_pJobs->Add(pJob));
  65. }
  66. } WsbCatch(hr);
  67. WsbTraceOut(OLESTR("CHsmServer::CreateDefaultJobs"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  68. return(hr);
  69. }
  70. HRESULT
  71. CHsmServer::GetSavedTraceSettings(
  72. LONGLONG* pTraceSettings,
  73. BOOLEAN *pTraceOn
  74. )
  75. /*++
  76. Routine Description:
  77. Loads the settings for the HSM engine trace
  78. Arguments:
  79. None
  80. Return Value:
  81. S_OK: The value was obtained
  82. --*/
  83. {
  84. HRESULT hr = S_OK;
  85. WsbTraceIn(OLESTR("CHsmServer::GetSavedTraceSettings"),OLESTR(""));
  86. try {
  87. DWORD sizeGot;
  88. OLECHAR dataString[100];
  89. OLECHAR *stopString;
  90. //
  91. // Get the values
  92. //
  93. WsbAffirmHr(WsbGetRegistryValueString(NULL, HSM_ENGINE_REGISTRY_STRING, HSM_TRACE_SETTINGS,
  94. dataString, 100, &sizeGot));
  95. *pTraceSettings = wcstoul( dataString, &stopString, 10 );
  96. WsbAffirmHr(WsbGetRegistryValueString(NULL, HSM_ENGINE_REGISTRY_STRING, HSM_TRACE_ON,
  97. dataString, 100, &sizeGot));
  98. *pTraceOn = (BOOLEAN) wcstoul( dataString, &stopString, 10 );
  99. } WsbCatch(hr);
  100. WsbTraceOut(OLESTR("CHsmServer::GetSavedTraceSettings"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  101. return(hr);
  102. }
  103. HRESULT
  104. CHsmServer::SetSavedTraceSettings(
  105. LONGLONG traceSettings,
  106. BOOLEAN traceOn
  107. )
  108. /*++
  109. Routine Description:
  110. Saves the settings for trace in the NT registry.
  111. Arguments:
  112. None
  113. Return Value:
  114. S_OK: The value was obtained
  115. --*/
  116. {
  117. HRESULT hr = S_OK;
  118. WsbTraceIn(OLESTR("CHsmServer::SetSavedTraceSettings"),OLESTR(""));
  119. try {
  120. OLECHAR dataString[64];
  121. //
  122. // Save the Saved value
  123. //
  124. swprintf(dataString, OLESTR("%l64x"), traceSettings);
  125. WsbAffirmHr(WsbSetRegistryValueString(NULL, HSM_ENGINE_REGISTRY_STRING, HSM_TRACE_SETTINGS,
  126. dataString));
  127. swprintf(dataString, OLESTR("%d"), traceOn);
  128. WsbAffirmHr(WsbSetRegistryValueString(NULL, HSM_ENGINE_REGISTRY_STRING, HSM_TRACE_ON,
  129. dataString));
  130. } WsbCatch(hr);
  131. WsbTraceOut(OLESTR("CHsmServer::SetSavedTraceSettings"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  132. return(hr);
  133. }