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.

1231 lines
25 KiB

  1. /*++
  2. Copyright (c) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. dnslibp.h
  5. Abstract:
  6. Domain Name System (DNS) Library
  7. Private DNS Library Routines
  8. Author:
  9. Jim Gilroy (jamesg) December 7, 1996
  10. Revision History:
  11. --*/
  12. #ifndef _DNSLIBP_INCLUDED_
  13. #define _DNSLIBP_INCLUDED_
  14. #include <winsock2.h>
  15. #include <ws2tcpip.h>
  16. #include <ws2atm.h>
  17. #include <windns.h>
  18. #include <dnsapi.h>
  19. #include <dnslib.h>
  20. #include <dnsip.h>
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif // __cplusplus
  25. // headers are screwed up
  26. // neither ntdef.h nor winnt.h brings in complete set, so depending
  27. // on whether you include nt.h or not you end up with different set
  28. #define MINCHAR 0x80
  29. #define MAXCHAR 0x7f
  30. #define MINSHORT 0x8000
  31. #define MAXSHORT 0x7fff
  32. #define MINLONG 0x80000000
  33. #define MAXLONG 0x7fffffff
  34. #define MAXBYTE 0xff
  35. #define MAXUCHAR 0xff
  36. #define MAXWORD 0xffff
  37. #define MAXUSHORT 0xffff
  38. #define MAXDWORD 0xffffffff
  39. #define MAXULONG 0xffffffff
  40. //
  41. // Handy bad ptr
  42. //
  43. #define DNS_BAD_PTR ((PVOID)(-1))
  44. //
  45. // "Wire" char set
  46. //
  47. // Explicitly create wire char set in case the ACE format
  48. // wins out.
  49. //
  50. #define DnsCharSetWire DnsCharSetUtf8
  51. //
  52. // DCR: move these to windns.h
  53. //
  54. #define DNS_IP4_REVERSE_DOMAIN_STRING_W (L"in-addr.arpa.")
  55. #define DNS_IP6_REVERSE_DOMAIN_STRING_W (L"ip6.arpa.")
  56. //
  57. // Private DNS_RECORD Flag field structure definition and macros
  58. //
  59. typedef struct _PrivateRecordFlags
  60. {
  61. DWORD Section : 2;
  62. DWORD Delete : 1;
  63. DWORD CharSet : 2;
  64. DWORD Cached : 1; // or maybe a "Source" field
  65. DWORD HostsFile : 1;
  66. DWORD Cluster : 1;
  67. DWORD Unused : 3;
  68. DWORD Matched : 1;
  69. DWORD FreeData : 1;
  70. DWORD FreeOwner : 1;
  71. DWORD Reserved : 18;
  72. }
  73. PRIV_RR_FLAGS, *PPRIV_RR_FLAGS;
  74. #define RRFLAGS( pRecord ) ((PPRIV_RR_FLAGS)&pRecord->Flags.DW)
  75. // Defined in dnslib.h too late to pull now
  76. //#define FLAG_Section( pRecord ) (RRFLAGS( pRecord )->Section)
  77. //#define FLAG_Delete( pRecord ) (RRFLAGS( pRecord )->Delete)
  78. //#define FLAG_CharSet( pRecord ) (RRFLAGS( pRecord )->CharSet)
  79. //#define FLAG_FreeData( pRecord ) (RRFLAGS( pRecord )->FreeData)
  80. //#define FLAG_FreeOwner( pRecord ) (RRFLAGS( pRecord )->FreeOwner)
  81. //#define FLAG_Matched( pRecord ) (RRFLAGS( pRecord )->Matched)
  82. //#define FLAG_Cached( pRecord ) (RRFLAGS( pRecord )->Cached)
  83. #define FLAG_HostsFile( pRecord ) (RRFLAGS( pRecord )->HostsFile)
  84. #define FLAG_Cluster( pRecord ) (RRFLAGS( pRecord )->Cluster)
  85. //#define SET_FREE_OWNER(pRR) (FLAG_FreeOwner(pRR) = TRUE)
  86. //#define SET_FREE_DATA(pRR) (FLAG_FreeData(pRR) = TRUE)
  87. //#define SET_RR_MATCHED(pRR) (FLAG_Matched(pRR) = TRUE)
  88. #define SET_RR_HOSTS_FILE(pRR) (FLAG_HostsFile(pRR) = TRUE)
  89. #define SET_RR_CLUSTER(pRR) (FLAG_Cluster(pRR) = TRUE)
  90. //#define CLEAR_FREE_OWNER(pRR) (FLAG_FreeOwner(pRR) = FALSE)
  91. //#define CLEAR_FREE_DATA(pRR) (FLAG_FreeData(pRR) = FALSE)
  92. //#define CLEAR_RR_MATCHED(pRR) (FLAG_Matched(pRR) = FALSE)
  93. #define CLEAR_RR_HOSTS_FILE(pRR) (FLAG_HostsFile(pRR) = FALSE)
  94. //#define IS_FREE_OWNER(pRR) (FLAG_FreeOwner(pRR))
  95. //#define IS_FREE_DATA(pRR) (FLAG_FreeData(pRR))
  96. //#define IS_RR_MATCHED(pRR) (FLAG_Matched(pRR))
  97. #define IS_HOSTS_FILE_RR(pRR) (FLAG_HostsFile(pRR))
  98. #define IS_CLUSTER_RR(pRR) (FLAG_Cluster(pRR))
  99. //#define IS_ANSWER_RR(pRR) (FLAG_Section(pRR) == DNSREC_ANSWER)
  100. //#define IS_AUTHORITY_RR(pRR) (FLAG_Section(pRR) == DNSREC_AUTHORITY)
  101. //#define IS_ADDITIONAL_RR(pRR) (FLAG_Section(pRR) == DNSREC_ADDITIONAL)
  102. //
  103. // DWORD flag definitions
  104. // #defines to match the windns.h ones for private fields
  105. // Charset
  106. #define DNSREC_CHARSET (0x00000018) // bits 4 and 5
  107. #define DNSREC_UNICODE (0x00000008) // DnsCharSetUnicode = 1
  108. #define DNSREC_UTF8 (0x00000010) // DnsCharSetUtf8 = 2
  109. #define DNSREC_ANSI (0x00000018) // DnsCharSetAnsi = 3
  110. //
  111. // Address family info (addr.c)
  112. //
  113. typedef struct _AddrFamilyInfo
  114. {
  115. WORD Family;
  116. WORD DnsType;
  117. DWORD LengthAddr;
  118. DWORD LengthSockaddr;
  119. DWORD OffsetToAddrInSockaddr;
  120. }
  121. FAMILY_INFO, *PFAMILY_INFO;
  122. extern FAMILY_INFO AddrFamilyTable[];
  123. #define FamilyInfoIp4 (AddrFamilyTable[0])
  124. #define FamilyInfoIp6 (AddrFamilyTable[1])
  125. #define FamilyInfoAtm (AddrFamilyTable[2])
  126. #define pFamilyInfoIp4 (&AddrFamilyTable[0])
  127. #define pFamilyInfoIp6 (&AddrFamilyTable[1])
  128. #define pFamilyInfoAtm (&AddrFamilyTable[2])
  129. PFAMILY_INFO
  130. FamilyInfo_GetForFamily(
  131. IN DWORD Family
  132. );
  133. #define FamilyInfo_GetForSockaddr(pSA) \
  134. FamilyInfo_GetForFamily( (pSA)->sa_family )
  135. WORD
  136. Family_DnsType(
  137. IN WORD Family
  138. );
  139. DWORD
  140. Family_SockaddrLength(
  141. IN WORD Family
  142. );
  143. DWORD
  144. Family_GetFromDnsType(
  145. IN WORD wType
  146. );
  147. //
  148. // Sockaddr
  149. //
  150. DWORD
  151. Sockaddr_Length(
  152. IN PSOCKADDR pSockaddr
  153. );
  154. IP6_ADDRESS
  155. Sockaddr_GetIp6(
  156. IN PSOCKADDR pSockaddr
  157. );
  158. VOID
  159. Sockaddr_BuildFromIp6(
  160. OUT PSOCKADDR pSockaddr,
  161. IN IP6_ADDRESS Ip6Addr,
  162. IN WORD Port
  163. );
  164. DNS_STATUS
  165. Sockaddr_BuildFromFlatAddr(
  166. OUT PSOCKADDR pSockaddr,
  167. IN OUT PDWORD pSockaddrLength,
  168. IN BOOL fClearSockaddr,
  169. IN PBYTE pAddr,
  170. IN DWORD AddrLength,
  171. IN DWORD AddrFamily
  172. );
  173. //
  174. // Hostents (hostent.c)
  175. // (used by sablob.c)
  176. //
  177. PHOSTENT
  178. Hostent_Init(
  179. IN OUT PBYTE * ppBuffer,
  180. IN INT Family,
  181. IN INT AddrLength,
  182. IN DWORD AddrCount,
  183. IN DWORD AliasCount
  184. );
  185. VOID
  186. Hostent_ConvertToOffsets(
  187. IN OUT PHOSTENT pHostent
  188. );
  189. //
  190. // Sting to address (straddr.c)
  191. //
  192. //
  193. // Need for hostent routine which doesn't unicode\ANSI.
  194. //
  195. BOOL
  196. Dns_StringToAddressEx(
  197. OUT PCHAR pAddrBuf,
  198. IN OUT PDWORD pBufLength,
  199. IN PCSTR pString,
  200. IN OUT PDWORD pAddrFamily,
  201. IN BOOL fUnicode,
  202. IN BOOL fReverse
  203. );
  204. BOOL
  205. Dns_StringToDnsAddrEx(
  206. OUT PDNS_ADDR pAddr,
  207. IN PCSTR pString,
  208. IN DWORD Family, OPTIONAL
  209. IN BOOL fUnicode,
  210. IN BOOL fReverse
  211. );
  212. //
  213. // Handle non-NULL terminated strings for DNS server file load.
  214. //
  215. BOOL
  216. Dns_Ip4StringToAddressEx_A(
  217. OUT PIP4_ADDRESS pIp4Addr,
  218. IN PCSTR pchString,
  219. IN DWORD StringLength
  220. );
  221. BOOL
  222. Dns_Ip6StringToAddressEx_A(
  223. OUT PIP6_ADDRESS pIp6Addr,
  224. IN PCSTR pchString,
  225. IN DWORD StringLength
  226. );
  227. //
  228. // Random
  229. //
  230. BOOL
  231. Dns_ReverseNameToSockaddrPrivate(
  232. OUT PSOCKADDR pSockaddr,
  233. IN OUT PDWORD pSockaddrLength,
  234. IN PCSTR pString,
  235. IN BOOL fUnicode
  236. );
  237. //
  238. // UPNP IP6 literal hack
  239. //
  240. VOID
  241. Dns_Ip6AddressToLiteralName(
  242. OUT PWCHAR pBuffer,
  243. IN PIP6_ADDRESS pIp6
  244. );
  245. BOOL
  246. Dns_Ip6LiteralNameToAddress(
  247. OUT PSOCKADDR_IN6 pSockAddr,
  248. IN PCWSTR pwsString
  249. );
  250. //
  251. // Mcast address build (dnsaddr.c)
  252. //
  253. BOOL
  254. DnsAddr_BuildMcast(
  255. OUT PDNS_ADDR pAddr,
  256. IN DWORD Family,
  257. IN PWSTR pName
  258. );
  259. //
  260. // IP6 mcast address (ip6.c)
  261. //
  262. BOOL
  263. Ip6_McastCreate(
  264. OUT PIP6_ADDRESS pIp,
  265. IN PWSTR pName
  266. );
  267. //
  268. // IP4 networking (dnsutil.c)
  269. //
  270. BOOL
  271. Dns_AreIp4InSameDefaultNetwork(
  272. IN IP4_ADDRESS IpAddr1,
  273. IN IP4_ADDRESS IpAddr2
  274. );
  275. //
  276. // RPC-able type (record.c)
  277. //
  278. BOOL
  279. Dns_IsRpcRecordType(
  280. IN WORD wType
  281. );
  282. //
  283. // Record copy (rrcopy.c)
  284. //
  285. PDNS_RECORD
  286. WINAPI
  287. Dns_RecordCopy_W(
  288. IN PDNS_RECORD pRecord
  289. );
  290. PDNS_RECORD
  291. WINAPI
  292. Dns_RecordCopy_A(
  293. IN PDNS_RECORD pRecord
  294. );
  295. PDNS_RECORD
  296. Dns_RecordListCopyEx(
  297. IN PDNS_RECORD pRR,
  298. IN DWORD ScreenFlag,
  299. IN DNS_CHARSET CharSetIn,
  300. IN DNS_CHARSET CharSetOut
  301. );
  302. //
  303. // Record list routines (rrlist.c)
  304. //
  305. //
  306. // Record screening (rrlist.c)
  307. //
  308. #define SCREEN_OUT_ANSWER (0x00000001)
  309. #define SCREEN_OUT_AUTHORITY (0x00000010)
  310. #define SCREEN_OUT_ADDITIONAL (0x00000100)
  311. #define SCREEN_OUT_NON_RPC (0x00100000)
  312. #define SCREEN_OUT_SECTION \
  313. (SCREEN_OUT_ANSWER | SCREEN_OUT_AUTHORITY | SCREEN_OUT_ADDITIONAL)
  314. BOOL
  315. Dns_ScreenRecord(
  316. IN PDNS_RECORD pRR,
  317. IN DWORD ScreenFlag
  318. );
  319. PDNS_RECORD
  320. Dns_RecordListScreen(
  321. IN PDNS_RECORD pRR,
  322. IN DWORD ScreenFlag
  323. );
  324. DWORD
  325. Dns_RecordListGetMinimumTtl(
  326. IN PDNS_RECORD pRRList
  327. );
  328. //
  329. // Record priorities (rrlist.c)
  330. //
  331. PDNS_RECORD
  332. Dns_PrioritizeSingleRecordSet(
  333. IN OUT PDNS_RECORD pRecordSet,
  334. IN PDNS_ADDR_ARRAY pArray
  335. );
  336. PDNS_RECORD
  337. Dns_PrioritizeRecordList(
  338. IN OUT PDNS_RECORD pRecordList,
  339. IN PDNS_ADDR_ARRAY pArray
  340. );
  341. //
  342. // Record comparison (rrcomp.c)
  343. //
  344. BOOL
  345. WINAPI
  346. Dns_DeleteRecordFromList(
  347. IN OUT PDNS_RECORD * ppRRList,
  348. IN PDNS_RECORD pRRDelete
  349. );
  350. //
  351. // New free
  352. // DCR: switch to dnslib.h when world builds clean
  353. //
  354. #undef Dns_RecordListFree
  355. VOID
  356. WINAPI
  357. Dns_RecordListFree(
  358. IN OUT PDNS_RECORD pRRList
  359. );
  360. //
  361. // String (string.c)
  362. //
  363. DWORD
  364. MultiSz_Size_A(
  365. IN PCSTR pmszString
  366. );
  367. PSTR
  368. MultiSz_NextString_A(
  369. IN PCSTR pmszString
  370. );
  371. PSTR
  372. MultiSz_Copy_A(
  373. IN PCSTR pmszString
  374. );
  375. BOOL
  376. MultiSz_Equal_A(
  377. IN PCSTR pmszString1,
  378. IN PCSTR pmszString2
  379. );
  380. DWORD
  381. MultiSz_Size_W(
  382. IN PCWSTR pmszString
  383. );
  384. PWSTR
  385. MultiSz_NextString_W(
  386. IN PCWSTR pmszString
  387. );
  388. PWSTR
  389. MultiSz_Copy_W(
  390. IN PCWSTR pmszString
  391. );
  392. BOOL
  393. MultiSz_Equal_W(
  394. IN PCWSTR pmszString1,
  395. IN PCWSTR pmszString2
  396. );
  397. BOOL
  398. MultiSz_ContainsName_W(
  399. IN PCWSTR pmszString,
  400. IN PCWSTR pString
  401. );
  402. DWORD
  403. String_ReplaceCharW(
  404. IN OUT PWSTR pwsString,
  405. IN WCHAR TargetChar,
  406. IN WCHAR ReplaceChar
  407. );
  408. DWORD
  409. String_ReplaceCharA(
  410. IN OUT PSTR pszString,
  411. IN CHAR TargetChar,
  412. IN CHAR ReplaceChar
  413. );
  414. PSTR *
  415. Argv_CopyEx(
  416. IN DWORD Argc,
  417. IN PCHAR * Argv,
  418. IN DNS_CHARSET CharSetIn,
  419. IN DNS_CHARSET CharSetOut
  420. );
  421. VOID
  422. Argv_Free(
  423. IN OUT PSTR * Argv
  424. );
  425. //
  426. // Timed locks (locks.c)
  427. //
  428. typedef struct _TimedLock
  429. {
  430. HANDLE hEvent;
  431. DWORD ThreadId;
  432. LONG RecursionCount;
  433. DWORD WaitTime;
  434. }
  435. TIMED_LOCK, *PTIMED_LOCK;
  436. #define TIMED_LOCK_DEFAULT_WAIT (0xf0000000)
  437. DWORD
  438. TimedLock_Initialize(
  439. OUT PTIMED_LOCK pTimedLock,
  440. IN DWORD DefaultWait
  441. );
  442. BOOL
  443. TimedLock_Enter(
  444. IN OUT PTIMED_LOCK pTimedLock,
  445. IN DWORD WaitTime
  446. );
  447. VOID
  448. TimedLock_Leave(
  449. IN OUT PTIMED_LOCK pTimedLock
  450. );
  451. VOID
  452. TimedLock_Cleanup(
  453. IN OUT PTIMED_LOCK pTimedLock
  454. );
  455. //
  456. // Name utilities (name.c)
  457. //
  458. DWORD
  459. Dns_MakeCanonicalNameW(
  460. OUT PWSTR pBuffer,
  461. IN DWORD BufLength,
  462. IN PWSTR pwsString,
  463. IN DWORD StringLength
  464. );
  465. DWORD
  466. Dns_MakeCanonicalNameInPlaceW(
  467. IN PWCHAR pwString,
  468. IN DWORD StringLength
  469. );
  470. INT
  471. Dns_DowncaseNameLabel(
  472. OUT PCHAR pchResult,
  473. IN PCHAR pchLabel,
  474. IN DWORD cchLabel,
  475. IN DWORD dwFlags
  476. );
  477. //
  478. // Name checking -- server name checking levels
  479. //
  480. #define DNS_ALLOW_RFC_NAMES_ONLY (0)
  481. #define DNS_ALLOW_NONRFC_NAMES (1)
  482. #define DNS_ALLOW_MULTIBYTE_NAMES (2)
  483. #define DNS_ALLOW_ALL_NAMES (3)
  484. PCHAR
  485. _fastcall
  486. Dns_GetDomainNameA(
  487. IN PCSTR pszName
  488. );
  489. PWSTR
  490. _fastcall
  491. Dns_GetDomainNameW(
  492. IN PCWSTR pwsName
  493. );
  494. PSTR
  495. _fastcall
  496. Dns_GetTldForNameA(
  497. IN PCSTR pszName
  498. );
  499. PWSTR
  500. _fastcall
  501. Dns_GetTldForNameW(
  502. IN PCWSTR pszName
  503. );
  504. BOOL
  505. _fastcall
  506. Dns_IsNameShortA(
  507. IN PCSTR pszName
  508. );
  509. BOOL
  510. _fastcall
  511. Dns_IsNameShortW(
  512. IN PCWSTR pszName
  513. );
  514. BOOL
  515. _fastcall
  516. Dns_IsNameNumericA(
  517. IN PCSTR pszName
  518. );
  519. BOOL
  520. _fastcall
  521. Dns_IsNameNumericW(
  522. IN PCWSTR pszName
  523. );
  524. BOOL
  525. _fastcall
  526. Dns_IsNameFQDN_A(
  527. IN PCSTR pszName
  528. );
  529. BOOL
  530. _fastcall
  531. Dns_IsNameFQDN_W(
  532. IN PCWSTR pszName
  533. );
  534. DWORD
  535. _fastcall
  536. Dns_GetNameAttributesA(
  537. IN PCSTR pszName
  538. );
  539. DWORD
  540. _fastcall
  541. Dns_GetNameAttributesW(
  542. IN PCWSTR pszName
  543. );
  544. DNS_STATUS
  545. Dns_ValidateAndCategorizeDnsNameA(
  546. IN PCSTR pszName,
  547. OUT PDWORD pLabelCount
  548. );
  549. DNS_STATUS
  550. Dns_ValidateAndCategorizeDnsNameW(
  551. IN PCWSTR pszName,
  552. OUT PDWORD pLabelCount
  553. );
  554. DWORD
  555. Dns_NameLabelCountA(
  556. IN PCSTR pszName
  557. );
  558. DWORD
  559. Dns_NameLabelCountW(
  560. IN PCWSTR pszName
  561. );
  562. PSTR
  563. Dns_NameAppend_A(
  564. OUT PCHAR pNameBuffer,
  565. IN DWORD BufferLength,
  566. IN PSTR pszName,
  567. IN PSTR pszDomain
  568. );
  569. PWSTR
  570. Dns_NameAppend_W(
  571. OUT PWCHAR pNameBuffer,
  572. IN DWORD BufferLength,
  573. IN PWSTR pwsName,
  574. IN PWSTR pwsDomain
  575. );
  576. PSTR
  577. Dns_SplitHostFromDomainNameA(
  578. IN PSTR pszName
  579. );
  580. PWSTR
  581. Dns_SplitHostFromDomainNameW(
  582. IN PWSTR pszName
  583. );
  584. BOOL
  585. Dns_CopyNameLabelA(
  586. OUT PCHAR pBuffer,
  587. IN PCSTR pszName
  588. );
  589. BOOL
  590. Dns_CopyNameLabelW(
  591. OUT PWCHAR pBuffer,
  592. IN PCWSTR pszName
  593. );
  594. //
  595. // Common name transformations
  596. //
  597. DWORD
  598. Dns_NameCopyWireToUnicode(
  599. OUT PWCHAR pBufferUnicode,
  600. IN PCSTR pszNameWire
  601. );
  602. DWORD
  603. Dns_NameCopyUnicodeToWire(
  604. OUT PCHAR pBufferWire,
  605. IN PCWSTR pwsNameUnicode
  606. );
  607. DWORD
  608. Dns_NameCopyStandard_W(
  609. OUT PWCHAR pBuffer,
  610. IN PCWSTR pwsNameUnicode
  611. );
  612. DWORD
  613. Dns_NameCopyStandard_A(
  614. OUT PCHAR pBuffer,
  615. IN PCSTR pszName
  616. );
  617. //
  618. // Special record creation (rralloc.c)
  619. //
  620. PDNS_RECORD
  621. Dns_CreateFlatRecord(
  622. IN PDNS_NAME pOwnerName,
  623. IN WORD wType,
  624. IN PCHAR pData,
  625. IN DWORD DataLength,
  626. IN DWORD Ttl,
  627. IN DNS_CHARSET NameCharSet,
  628. IN DNS_CHARSET RecordCharSet
  629. );
  630. PDNS_RECORD
  631. Dns_CreatePtrTypeRecord(
  632. IN PDNS_NAME pOwnerName,
  633. IN BOOL fCopyName,
  634. IN PDNS_NAME pTargetName,
  635. IN WORD wType,
  636. IN DWORD Ttl,
  637. IN DNS_CHARSET NameCharSet,
  638. IN DNS_CHARSET RecordCharSet
  639. );
  640. PDNS_RECORD
  641. Dns_CreatePtrRecordEx(
  642. IN PDNS_ADDR pAddr,
  643. IN PDNS_NAME pszHostName,
  644. IN DWORD Ttl,
  645. IN DNS_CHARSET NameCharSet,
  646. IN DNS_CHARSET RecordCharSet
  647. );
  648. PDNS_RECORD
  649. Dns_CreatePtrRecordExEx(
  650. IN PDNS_ADDR pAddr,
  651. IN PSTR pszHostName,
  652. IN PSTR pszDomainName,
  653. IN DWORD Ttl,
  654. IN DNS_CHARSET NameCharSet,
  655. IN DNS_CHARSET RecordCharSet
  656. );
  657. PDNS_RECORD
  658. Dns_CreateARecord(
  659. IN PDNS_NAME pOwnerName,
  660. IN IP4_ADDRESS Ip4Address,
  661. IN DWORD Ttl,
  662. IN DNS_CHARSET NameCharSet,
  663. IN DNS_CHARSET RecordCharSet
  664. );
  665. PDNS_RECORD
  666. Dns_CreateAAAARecord(
  667. IN PDNS_NAME pOwnerName,
  668. IN IP6_ADDRESS Ip6Address,
  669. IN DWORD Ttl,
  670. IN DNS_CHARSET NameCharSet,
  671. IN DNS_CHARSET RecordCharSet
  672. );
  673. PDNS_RECORD
  674. Dns_CreateForwardRecord(
  675. IN PDNS_NAME pOwnerName,
  676. IN WORD wType, OPTIONAL
  677. IN PDNS_ADDR pAddr,
  678. IN DWORD Ttl,
  679. IN DNS_CHARSET NameCharSet,
  680. IN DNS_CHARSET RecordCharSet
  681. );
  682. PDNS_RECORD
  683. Dns_CreateForwardRecordFromIp6(
  684. IN PDNS_NAME pOwnerName,
  685. IN PIP6_ADDRESS pIp,
  686. IN DWORD Ttl,
  687. IN DNS_CHARSET NameCharSet,
  688. IN DNS_CHARSET RecordCharSet
  689. );
  690. PDNS_RECORD
  691. Dns_CreateForwardRecordFromSockaddr(
  692. IN PDNS_NAME pOwnerName,
  693. IN PSOCKADDR pSockaddr,
  694. IN DWORD Ttl,
  695. IN DNS_CHARSET NameCharSet,
  696. IN DNS_CHARSET RecordCharSet
  697. );
  698. PDNS_RECORD
  699. Dns_CreateRecordForIpString_W(
  700. IN PCWSTR pwsName,
  701. IN WORD wType,
  702. IN DWORD Ttl
  703. );
  704. //
  705. // Record read\write (rrwrite.c rrread.c)
  706. //
  707. // Need here to export to dnsapi\packet.c
  708. //
  709. typedef PCHAR (* RR_WRITE_FUNCTION)(
  710. PDNS_RECORD,
  711. PCHAR,
  712. PCHAR );
  713. extern RR_WRITE_FUNCTION RR_WriteTable[];
  714. typedef PDNS_RECORD (* RR_READ_FUNCTION)(
  715. PDNS_RECORD,
  716. DNS_CHARSET,
  717. PCHAR,
  718. PCHAR,
  719. PCHAR );
  720. extern RR_READ_FUNCTION RR_ReadTable[];
  721. //
  722. // Security stuff (security.c)
  723. //
  724. #define SECURITY_WIN32
  725. #include <sspi.h>
  726. #define DNS_SPN_SERVICE_CLASS "DNS"
  727. #define DNS_SPN_SERVICE_CLASS_W L"DNS"
  728. //
  729. // Some useful stats
  730. //
  731. extern DWORD SecContextCreate;
  732. extern DWORD SecContextFree;
  733. extern DWORD SecContextQueue;
  734. extern DWORD SecContextQueueInNego;
  735. extern DWORD SecContextDequeue;
  736. extern DWORD SecContextTimeout;
  737. extern DWORD SecPackAlloc;
  738. extern DWORD SecPackFree;
  739. // Security packet verifications
  740. extern DWORD SecTkeyInvalid;
  741. extern DWORD SecTkeyBadTime;
  742. extern DWORD SecTsigFormerr;
  743. extern DWORD SecTsigEcho;
  744. extern DWORD SecTsigBadKey;
  745. extern DWORD SecTsigVerifySuccess;
  746. extern DWORD SecTsigVerifyOldSig;
  747. extern DWORD SecTsigVerifyFailed;
  748. // Hacks
  749. // Allowing old TSIG off by default, server can turn on.
  750. // Big Time skew on by default
  751. extern BOOL SecAllowOldTsig;
  752. extern DWORD SecTsigVerifyOldSig;
  753. extern DWORD SecTsigVerifyOldFailed;
  754. extern DWORD SecBigTimeSkew;
  755. extern DWORD SecBigTimeSkewBypass;
  756. //
  757. // Security globals
  758. // expose some of these which may be accessed by update library
  759. //
  760. extern BOOL g_fSecurityPackageInitialized;
  761. extern DWORD g_SecurityTokenMaxLength;
  762. //
  763. // Security context cache
  764. //
  765. VOID
  766. Dns_TimeoutSecurityContextList(
  767. IN BOOL fClearList
  768. );
  769. //
  770. // Security API
  771. //
  772. BOOL
  773. Dns_DnsNameToKerberosTargetName(
  774. IN LPSTR pszDnsName,
  775. IN LPSTR pszKerberosTargetName
  776. );
  777. DNS_STATUS
  778. Dns_StartSecurity(
  779. IN BOOL fProcessAttach
  780. );
  781. DNS_STATUS
  782. Dns_StartServerSecurity(
  783. VOID
  784. );
  785. VOID
  786. Dns_TerminateSecurityPackage(
  787. VOID
  788. );
  789. HANDLE
  790. Dns_CreateAPIContext(
  791. IN DWORD Flags,
  792. IN PVOID Credentials, OPTIONAL
  793. IN BOOL fUnicode
  794. );
  795. VOID
  796. Dns_FreeAPIContext(
  797. IN OUT HANDLE hContextHandle
  798. );
  799. PVOID
  800. Dns_GetApiContextCredentials(
  801. IN HANDLE hContextHandle
  802. );
  803. DWORD
  804. Dns_GetCurrentRid(
  805. VOID
  806. );
  807. BOOL
  808. Dns_CreateUserCredentials(
  809. IN PCHAR pszUser,
  810. IN DWORD dwUserLength,
  811. IN PCHAR pszDomain,
  812. IN DWORD dwDomainLength,
  813. IN PCHAR pszPassword,
  814. IN DWORD dwPasswordLength,
  815. IN BOOL FromWide,
  816. OUT PCHAR * ppCreds
  817. );
  818. PSEC_WINNT_AUTH_IDENTITY_W
  819. Dns_AllocateAndInitializeCredentialsW(
  820. IN PSEC_WINNT_AUTH_IDENTITY_W pAuthIn
  821. );
  822. PSEC_WINNT_AUTH_IDENTITY_A
  823. Dns_AllocateAndInitializeCredentialsA(
  824. IN PSEC_WINNT_AUTH_IDENTITY_A pAuthIn
  825. );
  826. VOID
  827. Dns_FreeAuthIdentityCredentials(
  828. IN PVOID pAuthIn
  829. );
  830. DNS_STATUS
  831. Dns_SignMessageWithGssTsig(
  832. IN HANDLE hContext,
  833. IN PDNS_HEADER pMsgHead,
  834. IN PCHAR pMsgBufEnd,
  835. IN OUT PCHAR * ppCurrent
  836. );
  837. #if 1
  838. DNS_STATUS
  839. Dns_RefreshSSpiCredentialsHandle(
  840. IN BOOL bDnsSvr,
  841. IN PCHAR pCreds );
  842. #endif
  843. VOID
  844. Dns_FreeSecurityContextList(
  845. VOID
  846. );
  847. //
  848. // Server security routines
  849. //
  850. DNS_STATUS
  851. Dns_FindSecurityContextFromAndVerifySignature(
  852. OUT PHANDLE phContext,
  853. IN PDNS_ADDR pRemoteAddr,
  854. IN PDNS_HEADER pMsgHead,
  855. IN PCHAR pMsgEnd
  856. );
  857. DNS_STATUS
  858. Dns_FindSecurityContextFromAndVerifySignature_Ip4(
  859. IN PHANDLE phContext,
  860. IN IP4_ADDRESS IpRemote,
  861. IN PDNS_HEADER pMsgHead,
  862. IN PCHAR pMsgEnd
  863. );
  864. DNS_STATUS
  865. Dns_ServerNegotiateTkey(
  866. IN PDNS_ADDR pRemoteAddr,
  867. IN PDNS_HEADER pMsgHead,
  868. IN PCHAR pMsgEnd,
  869. IN PCHAR pMsgBufEnd,
  870. IN BOOL fBreakOnAscFailure,
  871. OUT PCHAR * ppCurrent
  872. );
  873. DNS_STATUS
  874. Dns_ServerNegotiateTkey_Ip4(
  875. IN IP4_ADDRESS IpRemote,
  876. IN PDNS_HEADER pMsgHead,
  877. IN PCHAR pMsgEnd,
  878. IN PCHAR pMsgBufEnd,
  879. IN BOOL fBreakOnAscFailure,
  880. OUT PCHAR * ppCurrent
  881. );
  882. DNS_STATUS
  883. Dns_SrvImpersonateClient(
  884. IN HANDLE hContext
  885. );
  886. DNS_STATUS
  887. Dns_SrvRevertToSelf(
  888. IN HANDLE hContext
  889. );
  890. VOID
  891. Dns_CleanupSessionAndEnlistContext(
  892. IN OUT HANDLE hSession
  893. );
  894. DWORD
  895. Dns_GetKeyVersion(
  896. IN LPSTR pszContext
  897. );
  898. //
  899. // Security utilities
  900. //
  901. DNS_STATUS
  902. Dns_CreateSecurityDescriptor(
  903. OUT PSECURITY_DESCRIPTOR * ppSD,
  904. IN DWORD AclCount,
  905. IN PSID * SidPtrArray,
  906. IN DWORD * AccessMaskArray
  907. );
  908. //
  909. // Security credentials
  910. //
  911. // Only defined if WINNT_AUTH_IDENTITY defined
  912. #ifdef __RPCDCE_H__
  913. PSEC_WINNT_AUTH_IDENTITY_W
  914. Dns_AllocateCredentials(
  915. IN PWSTR pwsUserName,
  916. IN PWSTR pwsDomain,
  917. IN PWSTR pwsPassword
  918. );
  919. #endif
  920. DNS_STATUS
  921. Dns_ImpersonateUser(
  922. IN PDNS_CREDENTIALS pCreds
  923. );
  924. VOID
  925. Dns_FreeCredentials(
  926. IN PDNS_CREDENTIALS pCreds
  927. );
  928. PDNS_CREDENTIALS
  929. Dns_CopyCredentials(
  930. IN PDNS_CREDENTIALS pCreds
  931. );
  932. //
  933. // Debug globals
  934. //
  935. // Expose here to allow debug file sharing
  936. //
  937. typedef struct _DnsDebugInfo
  938. {
  939. DWORD Flag;
  940. HANDLE hFile;
  941. DWORD FileCurrentSize;
  942. DWORD FileWrapCount;
  943. DWORD FileWrapSize;
  944. DWORD LastThreadId;
  945. DWORD LastSecond;
  946. BOOL fConsole;
  947. CHAR FileName[ MAX_PATH ];
  948. }
  949. DNS_DEBUG_INFO, *PDNS_DEBUG_INFO;
  950. // WANING: MUST ONLY be called in dnsapi.dll
  951. PDNS_DEBUG_INFO
  952. Dns_SetDebugGlobals(
  953. IN OUT PDNS_DEBUG_INFO pInfo
  954. );
  955. #ifdef __cplusplus
  956. }
  957. #endif // __cplusplus
  958. #endif // _DNSLIBP_INCLUDED_