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.

579 lines
11 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // Dnsrpcrecord.h
  7. //
  8. // Implementation File:
  9. // Dnsrpcrecord.cpp
  10. //
  11. // Description:
  12. // Definition of the dns rpc record related class.
  13. //
  14. // Author:
  15. // Henry Wang (Henrywa) March 8, 2000
  16. //
  17. // Notes:
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #pragma once
  21. #include "dnsclip.h"
  22. #include "common.h"
  23. #ifndef DNS_WINSOCK2
  24. #define DNS_WINSOCK_VERSION (0x0101) // Winsock 1.1
  25. #else // Winsock2
  26. #define DNS_WINSOCK_VERSION (0x0002) // Winsock 2.0
  27. #endif
  28. class CDnsRpcRecord ;
  29. class CWbemClassObject;
  30. /////////////////////////////////////////////////////////////////////////////
  31. //++
  32. //
  33. // class CDnsRpcMemory
  34. //
  35. // Description:
  36. // Define common pointer increment operation in memory block that's
  37. // returned from dns rpc call
  38. //
  39. //
  40. // Inheritance:
  41. //
  42. //
  43. //--
  44. /////////////////////////////////////////////////////////////////////////////
  45. class CDnsRpcMemory
  46. {
  47. public:
  48. CDnsRpcMemory();
  49. virtual ~CDnsRpcMemory();
  50. PBYTE IncrementPtrByRecord(PBYTE);
  51. PBYTE IncrementPtrByNodeHead(PBYTE);
  52. };
  53. /////////////////////////////////////////////////////////////////////////////
  54. //++
  55. //
  56. // class CDnsRpcNode
  57. //
  58. // Description:
  59. // represents a dns rpc node structure and related operations
  60. //
  61. //
  62. // Inheritance:
  63. // CDnsRpcMemory
  64. //
  65. //--
  66. /////////////////////////////////////////////////////////////////////////////
  67. class CDnsRpcNode : public CDnsRpcMemory
  68. {
  69. public:
  70. CDnsRpcNode();
  71. ~CDnsRpcNode();
  72. BOOL Init(PDNS_RPC_NODE);
  73. BOOL IsDomainNode();
  74. CDnsRpcRecord* GetNextRecord();
  75. wstring GetNodeName();
  76. protected:
  77. wstring m_wstrNodeName;
  78. PBYTE m_pCurrent;
  79. PDNS_RPC_NODE m_pNode;
  80. WORD m_cRecord;
  81. WORD m_Index;
  82. };
  83. /////////////////////////////////////////////////////////////////////////////
  84. //++
  85. //
  86. // class CDnsRpcNode
  87. //
  88. // Description:
  89. // base class for all concrete dns record type such A, SOA. defines operation and
  90. // data member common to concrete record type
  91. //
  92. //
  93. // Inheritance:
  94. // CDnsRpcMemory
  95. //
  96. //--
  97. /////////////////////////////////////////////////////////////////////////////
  98. class CDnsRpcRecord
  99. {
  100. public:
  101. enum ActionType
  102. {
  103. AddRecord,
  104. DeleteRecord
  105. } ;
  106. CDnsRpcRecord( WORD wRdataSize );
  107. virtual ~CDnsRpcRecord();
  108. wstring GetTypeString();
  109. BOOL Init(
  110. PDNS_RPC_RECORD pRecord
  111. );
  112. wstring GetClass(
  113. void
  114. ) {return L"IN";};
  115. WORD GetType() ;
  116. DWORD GetTtl();
  117. char* GetNextArg(
  118. char * pszIn,
  119. char ** ppszOut
  120. );
  121. static BOOL RpcNameCopy(
  122. wstring& wstrTarget,
  123. PDNS_RPC_NAME pName
  124. );
  125. SCODE SendToServer(
  126. const char* szContainerName,
  127. ActionType Type
  128. );
  129. BOOL RdataIsChanged();
  130. virtual SCODE ConvertToWbemObject(
  131. CWbemClassObject& Inst
  132. );
  133. virtual SCODE Init(
  134. string&,
  135. string&,
  136. DWORD =0
  137. );
  138. virtual SCODE Init(
  139. wstring& wstrClass,
  140. string& strOwner,
  141. string& strRdata,
  142. CWbemClassObject& Inst
  143. );
  144. virtual SCODE GetObjectPath(
  145. wstring wstrServer,
  146. wstring wstrZone,
  147. wstring wstrDomain,
  148. wstring wstrOwner,
  149. CObjPath& objOP
  150. );
  151. virtual wstring GetTextRepresentation(
  152. wstring wstrNodeName
  153. );
  154. virtual wstring GetData(
  155. void
  156. ) {return L"";};
  157. static SCODE CreateClass(
  158. WORD wType,
  159. PVOID * pptr
  160. );
  161. protected:
  162. virtual const WCHAR** GetRdataName(void){return (const WCHAR**)NULL;};
  163. SCODE ParseRdata(
  164. string& strRdata,
  165. WORD wSize
  166. );
  167. virtual SCODE BuildRpcRecord(
  168. WORD argc,
  169. char ** argv
  170. );
  171. virtual wstring GetRecDomain(
  172. wstring wstrZone,
  173. wstring wstrDomain,
  174. wstring wstrOwner
  175. );
  176. SCODE ReplaceRdata(
  177. WORD wIndex, // index for m_ppRdata
  178. const WCHAR* pwsz, // Name for Rdata field
  179. CWbemClassObject& Inst
  180. );
  181. //member data
  182. BOOL m_bRdataChange;
  183. string m_strOwnerName; //record owner name
  184. WORD m_wType; // record type
  185. DWORD m_dwTtl; // time to live
  186. WORD m_cRdata;
  187. char** m_ppRdata; // Rdata pointer;
  188. const WCHAR* m_pwszClassName;
  189. PDNS_RPC_RECORD m_pRecord;
  190. BOOL m_pRecordRequiresFree; // m_pRecord is allocated?
  191. };
  192. /* for record type
  193. DNS_TYPE_SOA
  194. */
  195. class CDnsRpcSOA : public CDnsRpcRecord
  196. {
  197. enum{NUM_OF_ARG_IN_RDATA = 7};
  198. public:
  199. CDnsRpcSOA(WORD);
  200. ~CDnsRpcSOA();
  201. SCODE ConvertToWbemObject(
  202. CWbemClassObject&
  203. );
  204. wstring GetData(void);
  205. protected:
  206. DWORD GetSerialNo();
  207. DWORD GetRefresh();
  208. DWORD GetRetry();
  209. DWORD GetExpire();
  210. DWORD GetMinimumTtl();
  211. const WCHAR** GetRdataName();
  212. wstring GetPrimaryServer(void);
  213. wstring GetResponsible(void);
  214. SCODE BuildRpcRecord(
  215. WORD,
  216. char** );
  217. };
  218. /* for record type
  219. DNS_TYPE_A
  220. */
  221. class CDnsRpcA : public CDnsRpcRecord
  222. {
  223. enum{NUM_OF_ARG_IN_RDATA = 1};
  224. public:
  225. ~CDnsRpcA();
  226. CDnsRpcA(WORD);
  227. SCODE ConvertToWbemObject(
  228. CWbemClassObject&
  229. );
  230. wstring GetData(void);
  231. protected:
  232. const WCHAR** GetRdataName(void);
  233. wstring GetIP(void);
  234. }
  235. ;
  236. /* for record type
  237. DNS_TYPE_PTR
  238. DNS_TYPE_NS
  239. DNS_TYPE_CNAME
  240. DNS_TYPE_MD
  241. DNS_TYPE_MB
  242. DNS_TYPE_MF
  243. DNS_TYPE_MG
  244. DNS_TYPE_MR
  245. */
  246. class CDnsRpcNS : public CDnsRpcRecord
  247. {
  248. enum{NUM_OF_ARG_IN_RDATA = 1};
  249. public:
  250. CDnsRpcNS(WORD);
  251. ~CDnsRpcNS();
  252. SCODE ConvertToWbemObject(
  253. CWbemClassObject&
  254. );
  255. wstring GetData(void);
  256. protected:
  257. wstring GetNodeName();
  258. SCODE BuildRpcRecord(
  259. WORD,
  260. char**);
  261. wstring GetRecDomain(
  262. wstring ,
  263. wstring ,
  264. wstring );
  265. const WCHAR** GetRdataName();
  266. };
  267. /* for record type
  268. DNS_TYPE_RT
  269. DNS_TYPE_AFSDB
  270. */
  271. class CDnsRpcMX : public CDnsRpcRecord
  272. {
  273. enum{NUM_OF_ARG_IN_RDATA = 2};
  274. public:
  275. CDnsRpcMX(WORD);
  276. ~CDnsRpcMX();
  277. SCODE ConvertToWbemObject(
  278. CWbemClassObject&
  279. );
  280. wstring GetData(void);
  281. protected:
  282. wstring GetNodeName();
  283. DWORD GetPreference();
  284. const WCHAR** GetRdataName();
  285. };
  286. /* for record type
  287. DNS_TYPE_MINFO
  288. DNS_TYPE_RP
  289. */
  290. class CDnsRpcMINFO : public CDnsRpcRecord
  291. {
  292. enum{NUM_OF_ARG_IN_RDATA = 2};
  293. public:
  294. CDnsRpcMINFO(WORD);
  295. ~CDnsRpcMINFO();
  296. SCODE ConvertToWbemObject(
  297. CWbemClassObject&
  298. );
  299. wstring GetData(void);
  300. protected:
  301. wstring GetRPMailBox();
  302. wstring GetErrMailBox();
  303. const WCHAR** GetRdataName();
  304. };
  305. /* for record type
  306. DNS_TYPE_AAAA
  307. */
  308. class CDnsRpcAAAA : public CDnsRpcRecord
  309. {
  310. enum{NUM_OF_ARG_IN_RDATA = 1};
  311. public:
  312. CDnsRpcAAAA(WORD);
  313. ~CDnsRpcAAAA();
  314. SCODE ConvertToWbemObject(
  315. CWbemClassObject&
  316. );
  317. wstring GetData(void);
  318. protected:
  319. wstring GetIP(void);
  320. const WCHAR** GetRdataName();
  321. };
  322. /* for record type
  323. DNS_TYPE_HINFO:
  324. DNS_TYPE_ISDN:
  325. DNS_TYPE_X25:
  326. DNS_TYPE_TEXT
  327. */
  328. class CDnsRpcTXT : public CDnsRpcRecord
  329. {
  330. enum{NUM_OF_ARG_IN_RDATA_TXT=1,
  331. NUM_OF_ARG_IN_RDATA_HINFO = 2
  332. };
  333. public:
  334. CDnsRpcTXT(WORD);
  335. ~CDnsRpcTXT();
  336. SCODE ConvertToWbemObject(
  337. CWbemClassObject&
  338. );
  339. wstring GetTextRepresentation(
  340. wstring
  341. );
  342. wstring GetData(void);
  343. protected:
  344. wstring GetString1(void);
  345. wstring GetString2(void);
  346. const WCHAR** GetRdataName();
  347. };
  348. /* for record type
  349. DNS_TYPE_WKS
  350. */
  351. class CDnsRpcWKS : CDnsRpcRecord
  352. {
  353. enum{NUM_OF_ARG_IN_RDATA = 3};
  354. public:
  355. CDnsRpcWKS(WORD);
  356. ~CDnsRpcWKS();
  357. SCODE ConvertToWbemObject(
  358. CWbemClassObject&
  359. );
  360. wstring GetData(void);
  361. protected:
  362. wstring GetIP(void);
  363. wstring GetIPProtocal(void);
  364. wstring GetServices(void);
  365. const WCHAR** GetRdataName();
  366. };
  367. /* for record type
  368. DNS_TYPE_SRV
  369. */
  370. class CDnsRpcSRV : public CDnsRpcRecord
  371. {
  372. enum{NUM_OF_ARG_IN_RDATA = 4};
  373. public:
  374. CDnsRpcSRV(WORD);
  375. ~CDnsRpcSRV();
  376. SCODE ConvertToWbemObject(
  377. CWbemClassObject&
  378. );
  379. wstring GetData(void);
  380. protected:
  381. DWORD GetPriority(void);
  382. DWORD GetWeight(void);
  383. DWORD GetPort(void);
  384. wstring GetDomainName(void);
  385. const WCHAR** GetRdataName();
  386. };
  387. /* for record type
  388. DNS_TYPE_WINS
  389. */
  390. class CDnsRpcWINS : public CDnsRpcRecord
  391. {
  392. enum{NUM_OF_ARG_IN_RDATA = 4};
  393. public:
  394. CDnsRpcWINS(WORD);
  395. ~CDnsRpcWINS();
  396. SCODE ConvertToWbemObject(
  397. CWbemClassObject&
  398. );
  399. wstring GetData(void);
  400. protected:
  401. DWORD GetMapFlag(void);
  402. DWORD GetLookupTimeOut(void);
  403. DWORD GetCacheTimeOut(void);
  404. wstring GetWinServer(void);
  405. const WCHAR** GetRdataName();
  406. SCODE BuildRpcRecord(
  407. WORD,
  408. char**);
  409. };
  410. /* for record type
  411. DNS_TYPE_WINSR
  412. */
  413. class CDnsRpcWINSR : public CDnsRpcRecord
  414. {
  415. enum{NUM_OF_ARG_IN_RDATA = 4};
  416. public:
  417. CDnsRpcWINSR(WORD);
  418. ~CDnsRpcWINSR();
  419. SCODE ConvertToWbemObject(
  420. CWbemClassObject&
  421. );
  422. wstring GetData(void);
  423. protected:
  424. DWORD GetMapFlag(void);
  425. DWORD GetLookupTimeOut(void);
  426. DWORD GetCacheTimeOut(void);
  427. wstring GetResultDomain(void);
  428. const WCHAR** GetRdataName();
  429. };
  430. /* DNS_TYPE_NULL
  431. */
  432. class CDnsRpcNULL: public CDnsRpcRecord
  433. {
  434. enum{NUM_OF_ARG_IN_RDATA = 1};
  435. public:
  436. CDnsRpcNULL(WORD);
  437. ~CDnsRpcNULL();
  438. SCODE Init(
  439. string&,
  440. string&,
  441. DWORD
  442. );
  443. SCODE Init(
  444. wstring&,
  445. string&,
  446. string&,
  447. CWbemClassObject&
  448. );
  449. SCODE ConvertToWbemObject(
  450. CWbemClassObject&
  451. );
  452. wstring GetData(void);
  453. protected:
  454. wstring GetNullData(void);
  455. const WCHAR** GetRdataName();
  456. };
  457. class CDnsRpcATMA : public CDnsRpcRecord
  458. {
  459. enum{NUM_OF_ARG_IN_RDATA = 2};
  460. public:
  461. CDnsRpcATMA(WORD);
  462. ~CDnsRpcATMA();
  463. SCODE Init(
  464. string&,
  465. string&,
  466. DWORD =0
  467. );
  468. SCODE Init(
  469. wstring&,
  470. string&,
  471. string&,
  472. CWbemClassObject&
  473. );
  474. SCODE ConvertToWbemObject(
  475. CWbemClassObject&
  476. );
  477. wstring GetData(void);
  478. protected:
  479. DWORD GetFormat(void);
  480. wstring GetAddress(void);
  481. const WCHAR** GetRdataName();
  482. };
  483. /////////////////////////////////////////////////////////////////////////////
  484. //++
  485. //
  486. // class CDnsRpcNode
  487. //
  488. // Description:
  489. // a recordset are collection of records can be returned for a query.
  490. // when number of records are too large( eg error more data), mutiple
  491. // rpc call has to make to bring back all record. this class manage this
  492. // and retrieve nodes from the set
  493. //
  494. //
  495. // Inheritance:
  496. // CDnsRpcMemory
  497. //
  498. //--
  499. /////////////////////////////////////////////////////////////////////////////
  500. class CDnsRpcRecordSet : public CDnsRpcMemory
  501. {
  502. public:
  503. BOOL IsDomainNode();
  504. const PDNS_RPC_NODE GetNextNode();
  505. CDnsRpcRecordSet(
  506. CDomainNode&,
  507. WORD wType,
  508. DWORD dwFlag,
  509. LPCSTR pszFilterStart,
  510. LPCSTR pszFilterStop
  511. );
  512. ~CDnsRpcRecordSet();
  513. protected:
  514. void GetRecordSet();
  515. DWORD m_cRecord; //number of records in a node
  516. PBYTE m_pbPrevious;
  517. PBYTE m_pbCurrent; // current node
  518. PBYTE m_pbStop; // end position
  519. PBYTE m_pbStart; // start position
  520. string m_strZone;
  521. string m_strNode;
  522. string m_strStartChild;
  523. string m_strFilterStart;
  524. string m_strFilterStop ;
  525. WORD m_wType; // record type
  526. DWORD m_dwFlag;
  527. BOOL m_bMoreData; //more data indicator
  528. };