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.

191 lines
5.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: svcattch.cpp
  7. //
  8. // Contents: implementation of CComponentDataImpl
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "snapmgr.h"
  13. #include <scesvc.h>
  14. #define TEMPLATE_MAGIC_NUMBER (DWORD)-1
  15. /*-------------------------------------------------------------------------------
  16. This is a private structure used for SceSvcQueryInfo it expects the handle to
  17. be one step above what it is now.
  18. -------------------------------------------------------------------------------*/
  19. typedef struct _tag_SCEP_HANDLE
  20. {
  21. LPVOID hProfile; // SCE_HANDLE
  22. PWSTR ServiceName; // Service name.
  23. } SCEP_HANDLE, *LPSCEP_HANDLE;
  24. STDMETHODIMP
  25. CComponentDataImpl::GetData (SCESVC_HANDLE sceHandle,
  26. SCESVC_INFO_TYPE sceType,
  27. PVOID *ppvData,
  28. PSCE_ENUMERATION_CONTEXT psceEnumHandle) {
  29. SCESTATUS status;
  30. SCESVCP_HANDLE *scesvcHandle;
  31. // if (m_fSvcNotReady) {
  32. // return E_PENDING;
  33. // }
  34. if (!sceHandle) {
  35. return E_INVALIDARG;
  36. }
  37. if (!ppvData) {
  38. return E_POINTER;
  39. }
  40. scesvcHandle = (SCESVCP_HANDLE *) sceHandle;
  41. if (!scesvcHandle->ServiceName) {
  42. return E_INVALIDARG;
  43. }
  44. if (scesvcHandle->TemplateName &&
  45. lstrcmp(GT_COMPUTER_TEMPLATE, scesvcHandle->TemplateName) != 0 ) {
  46. if (psceEnumHandle &&
  47. *psceEnumHandle == TEMPLATE_MAGIC_NUMBER) {
  48. *ppvData = NULL;
  49. status = SCESTATUS_SUCCESS;
  50. } else {
  51. if (psceEnumHandle) {
  52. *psceEnumHandle = TEMPLATE_MAGIC_NUMBER;
  53. }
  54. status = SceSvcGetInformationTemplate(scesvcHandle->TemplateName,
  55. scesvcHandle->ServiceName,
  56. 0,
  57. (PSCESVC_CONFIGURATION_INFO *) ppvData);
  58. }
  59. } else {
  60. //
  61. // This structure needs to be sent to SceSvcQueryInfo;
  62. //
  63. SCEP_HANDLE hScep;
  64. ZeroMemory(&hScep, sizeof(SCEP_HANDLE));
  65. hScep.hProfile = SadHandle;
  66. hScep.ServiceName = scesvcHandle->ServiceName;
  67. status = SceSvcQueryInfo((SCE_HANDLE)&hScep,sceType,0,0,ppvData,psceEnumHandle);
  68. }
  69. if (SCESTATUS_SUCCESS == status) {
  70. return S_OK;
  71. } else {
  72. return E_FAIL;
  73. }
  74. }
  75. STDMETHODIMP
  76. CComponentDataImpl::Initialize(LPCTSTR ServiceName,
  77. LPCTSTR TemplateName,
  78. LPSCESVCATTACHMENTPERSISTINFO lpSceSvcPersistInfo,
  79. SCESVC_HANDLE *sceHandle) {
  80. SCESVCP_HANDLE *scesvcHandle;
  81. CEditTemplate *pET;
  82. ASSERT(ServiceName);
  83. ASSERT(lpSceSvcPersistInfo);
  84. ASSERT(sceHandle);
  85. if (!ServiceName || !lpSceSvcPersistInfo || !sceHandle) {
  86. return E_POINTER;
  87. }
  88. *sceHandle = NULL;
  89. //
  90. // Cache Service & Template -> lpUnknown.
  91. //
  92. if (TemplateName && lstrlen(TemplateName)) {
  93. //
  94. // If TemplateName is not NULL then find the template and store it there
  95. //
  96. pET = GetTemplate(TemplateName);
  97. if (!pET) {
  98. return E_FAIL;
  99. }
  100. pET->AddService(ServiceName,lpSceSvcPersistInfo);
  101. } else {
  102. return E_INVALIDARG;
  103. }
  104. // Open & retrieve SCE_HANDLE
  105. scesvcHandle = new SCESVCP_HANDLE;
  106. if (!scesvcHandle) {
  107. return E_OUTOFMEMORY;
  108. }
  109. scesvcHandle->ServiceName = new TCHAR [ lstrlen(ServiceName)+1 ];
  110. if (!scesvcHandle->ServiceName) {
  111. delete scesvcHandle;
  112. return E_OUTOFMEMORY;
  113. }
  114. //This is a safe usage.
  115. lstrcpy(scesvcHandle->ServiceName,ServiceName);
  116. if (TemplateName) {
  117. scesvcHandle->TemplateName = new TCHAR [ lstrlen(TemplateName)+1 ];
  118. if (!scesvcHandle->TemplateName) {
  119. delete [] scesvcHandle->ServiceName;
  120. delete scesvcHandle;
  121. return E_OUTOFMEMORY;
  122. }
  123. //This is a safe usage.
  124. lstrcpy(scesvcHandle->TemplateName,TemplateName);
  125. } else {
  126. scesvcHandle->TemplateName = NULL;
  127. }
  128. *sceHandle = (SCESVC_HANDLE *) scesvcHandle;
  129. return S_OK;
  130. }
  131. STDMETHODIMP
  132. CComponentDataImpl::FreeBuffer(PVOID pvData) {
  133. HRESULT hr;
  134. if (!pvData) {
  135. hr = E_POINTER;
  136. } else if (SCESTATUS_SUCCESS == SceSvcFree(pvData)) {
  137. hr = S_OK;
  138. } else {
  139. hr = E_FAIL;
  140. }
  141. return hr;
  142. }
  143. STDMETHODIMP
  144. CComponentDataImpl::CloseHandle(SCESVC_HANDLE sceHandle) {
  145. HRESULT hr;
  146. PSCESVCP_HANDLE pHandle;
  147. if (sceHandle) {
  148. pHandle = (PSCESVCP_HANDLE) sceHandle;
  149. // Free the handle
  150. if (pHandle->TemplateName) {
  151. delete[] pHandle->TemplateName;
  152. }
  153. delete[] pHandle->ServiceName;
  154. delete pHandle;
  155. hr = S_OK;
  156. } else {
  157. hr = E_INVALIDARG;
  158. }
  159. return hr;
  160. }