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.

290 lines
6.9 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. //
  3. // CopyRight ( c ) 1999 Microsoft Corporation
  4. //
  5. // Module Name: dnscache.cpp
  6. //
  7. // Description:
  8. // Implementation of CDnscache class
  9. //
  10. // Author:
  11. // Henry Wang ( henrywa ) March 8, 2000
  12. //
  13. //
  14. //////////////////////////////////////////////////////////////////////
  15. #include "DnsWmi.h"
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19. CDnsBase*
  20. CDnsCache::CreateThis(
  21. const WCHAR * wszName, //class name
  22. CWbemServices * pNamespace, //namespace
  23. const char * szType //str type id
  24. )
  25. {
  26. return new CDnsCache(wszName, pNamespace);
  27. }
  28. CDnsCache::CDnsCache()
  29. {
  30. }
  31. CDnsCache::CDnsCache(
  32. const WCHAR* wszName,
  33. CWbemServices *pNamespace)
  34. :CDnsBase(wszName, pNamespace)
  35. {
  36. }
  37. CDnsCache::~CDnsCache()
  38. {
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. //++
  42. //
  43. // CDnsCache::EnumInstance
  44. //
  45. // Description:
  46. // enum instances of dns cache
  47. //
  48. // Arguments:
  49. // lFlags [IN] WMI flag
  50. // pCtx [IN] WMI context
  51. // pHandler [IN] WMI sink pointer
  52. //
  53. // Return Value:
  54. // WBEM_S_NO_ERROR
  55. //
  56. //--
  57. /////////////////////////////////////////////////////////////////////////////
  58. SCODE
  59. CDnsCache::EnumInstance(
  60. long lFlags,
  61. IWbemContext * pCtx,
  62. IWbemObjectSink * pHandler )
  63. {
  64. CWbemClassObject Inst;
  65. m_pClass->SpawnInstance(0,&Inst);
  66. CDnsWrap& dns = CDnsWrap::DnsObject();
  67. Inst.SetProperty(
  68. dns.GetServerName(),
  69. PVD_DOMAIN_SERVER_NAME);
  70. Inst.SetProperty(
  71. PVD_DNS_CACHE,
  72. PVD_DOMAIN_FQDN);
  73. Inst.SetProperty(
  74. PVD_DNS_CACHE,
  75. PVD_DOMAIN_CONTAINER_NAME);
  76. pHandler->Indicate(1, &Inst);
  77. return WBEM_S_NO_ERROR;
  78. }
  79. /////////////////////////////////////////////////////////////////////////////
  80. //++
  81. //
  82. // CDnsCache::GetObject
  83. //
  84. // Description:
  85. // retrieve cache object based given object path
  86. //
  87. // Arguments:
  88. // ObjectPath [IN] object path to cluster object
  89. // lFlags [IN] WMI flag
  90. // pCtx [IN] WMI context
  91. // pHandler [IN] WMI sink pointer
  92. //
  93. // Return Value:
  94. // WBEM_S_NO_ERROR
  95. //
  96. //--
  97. /////////////////////////////////////////////////////////////////////////////
  98. SCODE
  99. CDnsCache::GetObject(
  100. CObjPath & ObjectPath,
  101. long lFlags,
  102. IWbemContext * pCtx,
  103. IWbemObjectSink * pHandler)
  104. {
  105. CDnsWrap& dns = CDnsWrap::DnsObject();
  106. wstring wstrServer = ObjectPath.GetStringValueForProperty(
  107. PVD_DOMAIN_SERVER_NAME);
  108. // dww - 6/14/99
  109. // Changed to make see if ValidateServerName does not return WBEM_S_NO_ERROR.
  110. //
  111. if(WBEM_S_NO_ERROR != dns.ValidateServerName(wstrServer.data()))
  112. return WBEM_E_FAILED;
  113. wstring wstrContainer = ObjectPath.GetStringValueForProperty(
  114. PVD_DOMAIN_CONTAINER_NAME);
  115. if(_wcsicmp(
  116. wstrContainer.data(),
  117. PVD_DNS_CACHE) == 0)
  118. {
  119. wstring wstrFQDN= ObjectPath.GetStringValueForProperty(
  120. PVD_DOMAIN_FQDN);
  121. if(_wcsicmp(wstrFQDN.data(),
  122. PVD_DNS_CACHE) == 0)
  123. {
  124. // founded
  125. CWbemClassObject Inst;
  126. m_pClass->SpawnInstance(0, &Inst);
  127. Inst.SetProperty(
  128. dns.GetServerName(),
  129. PVD_DOMAIN_SERVER_NAME);
  130. Inst.SetProperty(
  131. PVD_DNS_CACHE,
  132. PVD_DOMAIN_FQDN);
  133. Inst.SetProperty(
  134. PVD_DNS_CACHE,
  135. PVD_DOMAIN_CONTAINER_NAME);
  136. pHandler->Indicate(1, &Inst);
  137. }
  138. }
  139. return WBEM_S_NO_ERROR;
  140. }
  141. /////////////////////////////////////////////////////////////////////////////
  142. //++
  143. //
  144. // CDnsCache::ExecuteMethod
  145. //
  146. // Description:
  147. // execute methods defined for cache class in the mof
  148. //
  149. // Arguments:
  150. // ObjectPath [IN] object path to cluster object
  151. // wzMethodName [IN] name of the method to be invoked
  152. // lFlags [IN] WMI flag
  153. // pInParams [IN] Input parameters for the method
  154. // pHandler [IN] WMI sink pointer
  155. //
  156. // Return Value:
  157. // WBEM_S_NO_ERROR
  158. // WBEM_E_INVALID_PARAMETER
  159. //
  160. //--
  161. /////////////////////////////////////////////////////////////////////////////
  162. SCODE
  163. CDnsCache::ExecuteMethod(
  164. CObjPath & objPath,
  165. WCHAR * wzMethodName,
  166. long lFlag,
  167. IWbemClassObject * pInArgs,
  168. IWbemObjectSink * pHandler)
  169. {
  170. CDnsWrap& dns = CDnsWrap::DnsObject();
  171. wstring wstrServer = objPath.GetStringValueForProperty(
  172. PVD_DOMAIN_SERVER_NAME);
  173. // dww - 6/14/99
  174. // Changed to make see if ValidateServerName does not return WBEM_S_NO_ERROR.
  175. //
  176. if( FAILED ( dns.ValidateServerName(wstrServer.data())) )
  177. return WBEM_E_INVALID_PARAMETER;
  178. if(_wcsicmp(
  179. wzMethodName,
  180. PVD_MTH_CACHE_CLEARDNSSERVERCACHE) == 0)
  181. {
  182. return dns.dnsClearCache();
  183. }
  184. // dww - 6/14/99
  185. // Added the GetDistinguishedName method in the CDnsCache class.
  186. //
  187. else if(_wcsicmp(
  188. wzMethodName,
  189. PVD_MTH_ZONE_GETDISTINGUISHEDNAME) == 0)
  190. {
  191. wstring wstrName;
  192. wstring wstrCache = PVD_DNS_CACHE;
  193. CWbemClassObject OutParams, OutClass, Class ;
  194. HRESULT hr;
  195. dns.dnsDsZoneName(wstrName, wstrCache);
  196. BSTR ClassName=NULL;
  197. ClassName = AllocBstr(PVD_CLASS_CACHE);
  198. hr = m_pNamespace->GetObject(ClassName, 0, 0, &Class, NULL);
  199. SysFreeString(ClassName);
  200. if ( SUCCEEDED ( hr ) )
  201. {
  202. Class.GetMethod(wzMethodName, 0, NULL, &OutClass);
  203. OutClass.SpawnInstance(0, &OutParams);
  204. OutParams.SetProperty(wstrName, PVD_DNS_RETURN_VALUE);
  205. hr = pHandler->Indicate(1, &OutParams);
  206. }
  207. return hr;
  208. }
  209. return S_OK;
  210. }
  211. /////////////////////////////////////////////////////////////////////////////
  212. //++
  213. //
  214. // CDnsCache::PutInstance
  215. //
  216. // Description:
  217. // save this instance
  218. //
  219. // Arguments:
  220. // InstToPut [IN] WMI object to be saved
  221. // lFlags [IN] WMI flag
  222. // pCtx [IN] WMI context
  223. // pHandler [IN] WMI sink pointer
  224. //
  225. // Return Value:
  226. // WBEM_E_NOT_SUPPORTED
  227. //
  228. //--
  229. /////////////////////////////////////////////////////////////////////////////
  230. SCODE
  231. CDnsCache::PutInstance(
  232. IWbemClassObject * pInst ,
  233. long lFlags,
  234. IWbemContext* pCtx ,
  235. IWbemObjectSink * pHandler)
  236. {
  237. return WBEM_E_NOT_SUPPORTED;
  238. };
  239. /////////////////////////////////////////////////////////////////////////////
  240. //++
  241. //
  242. // CDnsCache::DeleteInstance
  243. //
  244. // Description:
  245. // delete the object specified in rObjPath
  246. //
  247. // Arguments:
  248. // rObjPath [IN] ObjPath for the instance to be deleted
  249. // lFlags [IN] WMI flag
  250. // pCtx [IN] WMI context
  251. // pHandler [IN] WMI sink pointer
  252. //
  253. // Return Value:
  254. // WBEM_E_NOT_SUPPORTED
  255. //
  256. //--
  257. /////////////////////////////////////////////////////////////////////////////
  258. SCODE
  259. CDnsCache::DeleteInstance(
  260. CObjPath & ObjectPath,
  261. long lFlags,
  262. IWbemContext * pCtx,
  263. IWbemObjectSink * pResponseHandler)
  264. {
  265. return WBEM_E_NOT_SUPPORTED;
  266. }