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.

281 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. if(WBEM_S_NO_ERROR != dns.ValidateServerName(wstrServer.data()))
  109. return WBEM_E_FAILED;
  110. wstring wstrContainer = ObjectPath.GetStringValueForProperty(
  111. PVD_DOMAIN_CONTAINER_NAME);
  112. if(_wcsicmp(
  113. wstrContainer.data(),
  114. PVD_DNS_CACHE) == 0)
  115. {
  116. wstring wstrFQDN= ObjectPath.GetStringValueForProperty(
  117. PVD_DOMAIN_FQDN);
  118. if(_wcsicmp(wstrFQDN.data(),
  119. PVD_DNS_CACHE) == 0)
  120. {
  121. // founded
  122. CWbemClassObject Inst;
  123. m_pClass->SpawnInstance(0, &Inst);
  124. Inst.SetProperty(
  125. dns.GetServerName(),
  126. PVD_DOMAIN_SERVER_NAME);
  127. Inst.SetProperty(
  128. PVD_DNS_CACHE,
  129. PVD_DOMAIN_FQDN);
  130. Inst.SetProperty(
  131. PVD_DNS_CACHE,
  132. PVD_DOMAIN_CONTAINER_NAME);
  133. pHandler->Indicate(1, &Inst);
  134. }
  135. }
  136. return WBEM_S_NO_ERROR;
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. //++
  140. //
  141. // CDnsCache::ExecuteMethod
  142. //
  143. // Description:
  144. // execute methods defined for cache class in the mof
  145. //
  146. // Arguments:
  147. // ObjectPath [IN] object path to cluster object
  148. // wzMethodName [IN] name of the method to be invoked
  149. // lFlags [IN] WMI flag
  150. // pInParams [IN] Input parameters for the method
  151. // pHandler [IN] WMI sink pointer
  152. //
  153. // Return Value:
  154. // WBEM_S_NO_ERROR
  155. // WBEM_E_INVALID_PARAMETER
  156. //
  157. //--
  158. /////////////////////////////////////////////////////////////////////////////
  159. SCODE
  160. CDnsCache::ExecuteMethod(
  161. CObjPath & objPath,
  162. WCHAR * wzMethodName,
  163. long lFlag,
  164. IWbemClassObject * pInArgs,
  165. IWbemObjectSink * pHandler)
  166. {
  167. CDnsWrap& dns = CDnsWrap::DnsObject();
  168. wstring wstrServer = objPath.GetStringValueForProperty(
  169. PVD_DOMAIN_SERVER_NAME);
  170. if( FAILED ( dns.ValidateServerName(wstrServer.data())) )
  171. return WBEM_E_INVALID_PARAMETER;
  172. if(_wcsicmp(
  173. wzMethodName,
  174. PVD_MTH_CACHE_CLEARDNSSERVERCACHE) == 0)
  175. {
  176. return dns.dnsClearCache();
  177. }
  178. else if(_wcsicmp(
  179. wzMethodName,
  180. PVD_MTH_ZONE_GETDISTINGUISHEDNAME) == 0)
  181. {
  182. wstring wstrName;
  183. wstring wstrCache = PVD_DNS_CACHE;
  184. CWbemClassObject OutParams, OutClass, Class ;
  185. HRESULT hr;
  186. dns.dnsDsZoneName(wstrName, wstrCache);
  187. BSTR ClassName=NULL;
  188. ClassName = AllocBstr(PVD_CLASS_CACHE);
  189. hr = m_pNamespace->GetObject(ClassName, 0, 0, &Class, NULL);
  190. SysFreeString(ClassName);
  191. if ( SUCCEEDED ( hr ) )
  192. {
  193. Class.GetMethod( wzMethodName, 0, NULL, &OutClass );
  194. OutClass.SpawnInstance(0, &OutParams);
  195. OutParams.SetProperty(wstrName, PVD_DNS_RETURN_VALUE);
  196. hr = pHandler->Indicate(1, &OutParams);
  197. }
  198. return hr;
  199. }
  200. return S_OK;
  201. }
  202. /////////////////////////////////////////////////////////////////////////////
  203. //++
  204. //
  205. // CDnsCache::PutInstance
  206. //
  207. // Description:
  208. // save this instance
  209. //
  210. // Arguments:
  211. // InstToPut [IN] WMI object to be saved
  212. // lFlags [IN] WMI flag
  213. // pCtx [IN] WMI context
  214. // pHandler [IN] WMI sink pointer
  215. //
  216. // Return Value:
  217. // WBEM_E_NOT_SUPPORTED
  218. //
  219. //--
  220. /////////////////////////////////////////////////////////////////////////////
  221. SCODE
  222. CDnsCache::PutInstance(
  223. IWbemClassObject * pInst ,
  224. long lFlags,
  225. IWbemContext* pCtx ,
  226. IWbemObjectSink * pHandler)
  227. {
  228. return WBEM_E_NOT_SUPPORTED;
  229. };
  230. /////////////////////////////////////////////////////////////////////////////
  231. //++
  232. //
  233. // CDnsCache::DeleteInstance
  234. //
  235. // Description:
  236. // delete the object specified in rObjPath
  237. //
  238. // Arguments:
  239. // rObjPath [IN] ObjPath for the instance to be deleted
  240. // lFlags [IN] WMI flag
  241. // pCtx [IN] WMI context
  242. // pHandler [IN] WMI sink pointer
  243. //
  244. // Return Value:
  245. // WBEM_E_NOT_SUPPORTED
  246. //
  247. //--
  248. /////////////////////////////////////////////////////////////////////////////
  249. SCODE
  250. CDnsCache::DeleteInstance(
  251. CObjPath & ObjectPath,
  252. long lFlags,
  253. IWbemContext * pCtx,
  254. IWbemObjectSink * pResponseHandler)
  255. {
  256. return WBEM_E_NOT_SUPPORTED;
  257. }