4 * Copyright (C) 2006 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
23 #include "wine/debug.h"
28 #include <sys/types.h>
30 #ifdef HAVE_NETINET_IN_H
31 # include <netinet/in.h>
33 #ifdef HAVE_ARPA_NAMESER_H
34 # include <arpa/nameser.h>
52 WINE_DEFAULT_DEBUG_CHANNEL(dnsapi
);
56 /* call res_init() just once because of a bug in Mac OS X 10.4 */
57 /* call once per thread on systems that have per-thread _res */
58 static void initialise_resolver( void )
60 if ((_res
.options
& RES_INIT
) == 0)
64 static const char *dns_section_to_str( ns_sect section
)
68 case ns_s_qd
: return "Question";
69 case ns_s_an
: return "Answer";
70 case ns_s_ns
: return "Authority";
71 case ns_s_ar
: return "Additional";
75 FIXME( "unknown section: 0x%02x\n", section
);
76 sprintf( tmp
, "0x%02x", section
);
82 static unsigned long dns_map_options( DWORD options
)
84 unsigned long ret
= 0;
86 if (options
== DNS_QUERY_STANDARD
)
89 if (options
& DNS_QUERY_ACCEPT_TRUNCATED_RESPONSE
)
91 if (options
& DNS_QUERY_USE_TCP_ONLY
)
93 if (options
& DNS_QUERY_NO_RECURSION
)
95 if (options
& DNS_QUERY_NO_LOCAL_NAME
)
97 if (options
& DNS_QUERY_NO_HOSTS_FILE
)
99 if (options
& DNS_QUERY_TREAT_AS_FQDN
)
100 ret
&= ~RES_DEFNAMES
;
102 if (options
& DNS_QUERY_DONT_RESET_TTL_VALUES
)
103 FIXME( "option DNS_QUERY_DONT_RESET_TTL_VALUES not implemented\n" );
104 if (options
& DNS_QUERY_RESERVED
)
105 FIXME( "option DNS_QUERY_RESERVED not implemented\n" );
106 if (options
& DNS_QUERY_WIRE_ONLY
)
107 FIXME( "option DNS_QUERY_WIRE_ONLY not implemented\n" );
108 if (options
& DNS_QUERY_NO_WIRE_QUERY
)
109 FIXME( "option DNS_QUERY_NO_WIRE_QUERY not implemented\n" );
110 if (options
& DNS_QUERY_BYPASS_CACHE
)
111 FIXME( "option DNS_QUERY_BYPASS_CACHE not implemented\n" );
112 if (options
& DNS_QUERY_RETURN_MESSAGE
)
113 FIXME( "option DNS_QUERY_RETURN_MESSAGE not implemented\n" );
115 if (options
& DNS_QUERY_NO_NETBT
)
116 TRACE( "netbios query disabled\n" );
121 static DNS_STATUS
dns_map_error( int error
)
125 case ns_r_noerror
: return ERROR_SUCCESS
;
126 case ns_r_formerr
: return DNS_ERROR_RCODE_FORMAT_ERROR
;
127 case ns_r_servfail
: return DNS_ERROR_RCODE_SERVER_FAILURE
;
128 case ns_r_nxdomain
: return DNS_ERROR_RCODE_NAME_ERROR
;
129 case ns_r_notimpl
: return DNS_ERROR_RCODE_NOT_IMPLEMENTED
;
130 case ns_r_refused
: return DNS_ERROR_RCODE_REFUSED
;
131 case ns_r_yxdomain
: return DNS_ERROR_RCODE_YXDOMAIN
;
132 case ns_r_yxrrset
: return DNS_ERROR_RCODE_YXRRSET
;
133 case ns_r_nxrrset
: return DNS_ERROR_RCODE_NXRRSET
;
134 case ns_r_notauth
: return DNS_ERROR_RCODE_NOTAUTH
;
135 case ns_r_notzone
: return DNS_ERROR_RCODE_NOTZONE
;
137 FIXME( "unmapped error code: %d\n", error
);
138 return DNS_ERROR_RCODE_NOT_IMPLEMENTED
;
142 static DNS_STATUS
dns_map_h_errno( int error
)
147 case HOST_NOT_FOUND
: return DNS_ERROR_RCODE_NAME_ERROR
;
148 case TRY_AGAIN
: return DNS_ERROR_RCODE_SERVER_FAILURE
;
149 case NO_RECOVERY
: return DNS_ERROR_RCODE_REFUSED
;
150 #ifdef NETDB_INTERNAL
151 case NETDB_INTERNAL
: return DNS_ERROR_RCODE
;
154 FIXME( "unmapped error code: %d\n", error
);
155 return DNS_ERROR_RCODE_NOT_IMPLEMENTED
;
159 static char *dns_dname_from_msg( ns_msg msg
, const unsigned char *pos
)
162 char *str
, dname
[NS_MAXDNAME
] = ".";
164 /* returns *compressed* length, ignore it */
165 dns_ns_name_uncompress( ns_msg_base(msg
), ns_msg_end(msg
), pos
, dname
, sizeof(dname
) );
167 len
= strlen( dname
);
168 str
= heap_alloc( len
+ 1 );
169 if (str
) strcpy( str
, dname
);
173 static char *dns_str_from_rdata( const unsigned char *rdata
)
176 unsigned int len
= rdata
[0];
178 str
= heap_alloc( len
+ 1 );
181 memcpy( str
, ++rdata
, len
);
187 static unsigned int dns_get_record_size( const ns_rr
*rr
)
189 const unsigned char *pos
= rr
->rdata
;
190 unsigned int num
= 0, size
= sizeof(DNS_RECORDA
);
196 pos
+= sizeof(WORD
) + sizeof(BYTE
) + sizeof(BYTE
);
197 size
+= rr
->rdata
+ rr
->rdlength
- pos
- 1;
202 pos
+= sizeof(PCHAR
) + sizeof(WORD
) + 2 * sizeof(BYTE
);
203 pos
+= 3 * sizeof(DWORD
) + 2 * sizeof(WORD
);
204 size
+= rr
->rdata
+ rr
->rdlength
- pos
- 1;
212 while (pos
[0] && pos
< rr
->rdata
+ rr
->rdlength
)
217 size
+= (num
- 1) * sizeof(PCHAR
);
222 size
+= rr
->rdlength
- 1;
227 case 0xff01: /* WINS */
229 FIXME( "unhandled type: %s\n", dns_type_to_str( rr
->type
) );
238 static DNS_STATUS
dns_copy_rdata( ns_msg msg
, const ns_rr
*rr
, DNS_RECORDA
*r
, WORD
*dlen
)
240 DNS_STATUS ret
= ERROR_SUCCESS
;
241 const unsigned char *pos
= rr
->rdata
;
242 unsigned int i
, size
;
248 r
->Data
.A
.IpAddress
= *(const DWORD
*)pos
;
249 *dlen
= sizeof(DNS_A_DATA
);
254 for (i
= 0; i
< sizeof(IP6_ADDRESS
)/sizeof(DWORD
); i
++)
256 r
->Data
.AAAA
.Ip6Address
.IP6Dword
[i
] = *(const DWORD
*)pos
;
257 pos
+= sizeof(DWORD
);
260 *dlen
= sizeof(DNS_AAAA_DATA
);
265 /* FIXME: byte order? */
266 r
->Data
.KEY
.wFlags
= *(const WORD
*)pos
; pos
+= sizeof(WORD
);
267 r
->Data
.KEY
.chProtocol
= *pos
++;
268 r
->Data
.KEY
.chAlgorithm
= *pos
++;
270 size
= rr
->rdata
+ rr
->rdlength
- pos
;
272 for (i
= 0; i
< size
; i
++)
273 r
->Data
.KEY
.Key
[i
] = *pos
++;
275 *dlen
= sizeof(DNS_KEY_DATA
) + (size
- 1) * sizeof(BYTE
);
281 r
->Data
.MINFO
.pNameMailbox
= dns_dname_from_msg( msg
, pos
);
282 if (!r
->Data
.MINFO
.pNameMailbox
) return ERROR_NOT_ENOUGH_MEMORY
;
284 if (dns_ns_name_skip( &pos
, ns_msg_end( msg
) ) < 0)
285 return DNS_ERROR_BAD_PACKET
;
287 r
->Data
.MINFO
.pNameErrorsMailbox
= dns_dname_from_msg( msg
, pos
);
288 if (!r
->Data
.MINFO
.pNameErrorsMailbox
)
290 heap_free( r
->Data
.MINFO
.pNameMailbox
);
291 return ERROR_NOT_ENOUGH_MEMORY
;
294 *dlen
= sizeof(DNS_MINFO_DATAA
);
301 r
->Data
.MX
.wPreference
= ntohs( *(const WORD
*)pos
);
302 r
->Data
.MX
.pNameExchange
= dns_dname_from_msg( msg
, pos
+ sizeof(WORD
) );
303 if (!r
->Data
.MX
.pNameExchange
) return ERROR_NOT_ENOUGH_MEMORY
;
305 *dlen
= sizeof(DNS_MX_DATAA
);
310 r
->Data
.Null
.dwByteCount
= rr
->rdlength
;
311 memcpy( r
->Data
.Null
.Data
, rr
->rdata
, rr
->rdlength
);
313 *dlen
= sizeof(DNS_NULL_DATA
) + rr
->rdlength
- 1;
325 r
->Data
.PTR
.pNameHost
= dns_dname_from_msg( msg
, pos
);
326 if (!r
->Data
.PTR
.pNameHost
) return ERROR_NOT_ENOUGH_MEMORY
;
328 *dlen
= sizeof(DNS_PTR_DATAA
);
333 r
->Data
.SIG
.pNameSigner
= dns_dname_from_msg( msg
, pos
);
334 if (!r
->Data
.SIG
.pNameSigner
) return ERROR_NOT_ENOUGH_MEMORY
;
336 if (dns_ns_name_skip( &pos
, ns_msg_end( msg
) ) < 0)
337 return DNS_ERROR_BAD_PACKET
;
339 /* FIXME: byte order? */
340 r
->Data
.SIG
.wTypeCovered
= *(const WORD
*)pos
; pos
+= sizeof(WORD
);
341 r
->Data
.SIG
.chAlgorithm
= *pos
++;
342 r
->Data
.SIG
.chLabelCount
= *pos
++;
343 r
->Data
.SIG
.dwOriginalTtl
= *(const DWORD
*)pos
; pos
+= sizeof(DWORD
);
344 r
->Data
.SIG
.dwExpiration
= *(const DWORD
*)pos
; pos
+= sizeof(DWORD
);
345 r
->Data
.SIG
.dwTimeSigned
= *(const DWORD
*)pos
; pos
+= sizeof(DWORD
);
346 r
->Data
.SIG
.wKeyTag
= *(const WORD
*)pos
;
348 size
= rr
->rdata
+ rr
->rdlength
- pos
;
350 for (i
= 0; i
< size
; i
++)
351 r
->Data
.SIG
.Signature
[i
] = *pos
++;
353 *dlen
= sizeof(DNS_SIG_DATAA
) + (size
- 1) * sizeof(BYTE
);
358 r
->Data
.SOA
.pNamePrimaryServer
= dns_dname_from_msg( msg
, pos
);
359 if (!r
->Data
.SOA
.pNamePrimaryServer
) return ERROR_NOT_ENOUGH_MEMORY
;
361 if (dns_ns_name_skip( &pos
, ns_msg_end( msg
) ) < 0)
362 return DNS_ERROR_BAD_PACKET
;
364 r
->Data
.SOA
.pNameAdministrator
= dns_dname_from_msg( msg
, pos
);
365 if (!r
->Data
.SOA
.pNameAdministrator
)
367 heap_free( r
->Data
.SOA
.pNamePrimaryServer
);
368 return ERROR_NOT_ENOUGH_MEMORY
;
371 if (dns_ns_name_skip( &pos
, ns_msg_end( msg
) ) < 0)
372 return DNS_ERROR_BAD_PACKET
;
374 r
->Data
.SOA
.dwSerialNo
= ntohl( *(const DWORD
*)pos
); pos
+= sizeof(DWORD
);
375 r
->Data
.SOA
.dwRefresh
= ntohl( *(const DWORD
*)pos
); pos
+= sizeof(DWORD
);
376 r
->Data
.SOA
.dwRetry
= ntohl( *(const DWORD
*)pos
); pos
+= sizeof(DWORD
);
377 r
->Data
.SOA
.dwExpire
= ntohl( *(const DWORD
*)pos
); pos
+= sizeof(DWORD
);
378 r
->Data
.SOA
.dwDefaultTtl
= ntohl( *(const DWORD
*)pos
); pos
+= sizeof(DWORD
);
380 *dlen
= sizeof(DNS_SOA_DATAA
);
385 r
->Data
.SRV
.wPriority
= ntohs( *(const WORD
*)pos
); pos
+= sizeof(WORD
);
386 r
->Data
.SRV
.wWeight
= ntohs( *(const WORD
*)pos
); pos
+= sizeof(WORD
);
387 r
->Data
.SRV
.wPort
= ntohs( *(const WORD
*)pos
); pos
+= sizeof(WORD
);
389 r
->Data
.SRV
.pNameTarget
= dns_dname_from_msg( msg
, pos
);
390 if (!r
->Data
.SRV
.pNameTarget
) return ERROR_NOT_ENOUGH_MEMORY
;
392 *dlen
= sizeof(DNS_SRV_DATAA
);
401 while (pos
[0] && pos
< rr
->rdata
+ rr
->rdlength
)
403 r
->Data
.TXT
.pStringArray
[i
] = dns_str_from_rdata( pos
);
404 if (!r
->Data
.TXT
.pStringArray
[i
])
406 while (i
> 0) heap_free( r
->Data
.TXT
.pStringArray
[--i
] );
407 return ERROR_NOT_ENOUGH_MEMORY
;
412 r
->Data
.TXT
.dwStringCount
= i
;
413 *dlen
= sizeof(DNS_TXT_DATAA
) + (i
- 1) * sizeof(PCHAR
);
421 case 0x00f9: /* TKEY */
422 case 0xff01: /* WINS */
423 case 0xff02: /* WINSR */
425 FIXME( "unhandled type: %s\n", dns_type_to_str( rr
->type
) );
426 return DNS_ERROR_RCODE_NOT_IMPLEMENTED
;
432 static DNS_STATUS
dns_copy_record( ns_msg msg
, ns_sect section
,
433 unsigned short num
, DNS_RECORDA
**recp
)
440 if (dns_ns_parserr( &msg
, section
, num
, &rr
) < 0)
441 return DNS_ERROR_BAD_PACKET
;
443 if (!(record
= heap_alloc_zero( dns_get_record_size( &rr
) )))
444 return ERROR_NOT_ENOUGH_MEMORY
;
446 record
->pName
= dns_strdup_u( rr
.name
);
450 return ERROR_NOT_ENOUGH_MEMORY
;
453 record
->wType
= rr
.type
;
454 record
->Flags
.S
.Section
= section
;
455 record
->Flags
.S
.CharSet
= DnsCharSetUtf8
;
456 record
->dwTtl
= rr
.ttl
;
458 if ((ret
= dns_copy_rdata( msg
, &rr
, record
, &dlen
)))
460 heap_free( record
->pName
);
464 record
->wDataLength
= dlen
;
467 TRACE( "found %s record in %s section\n",
468 dns_type_to_str( rr
.type
), dns_section_to_str( section
) );
469 return ERROR_SUCCESS
;
472 #define DEFAULT_TTL 1200
474 static DNS_STATUS
dns_do_query_netbios( PCSTR name
, DNS_RECORDA
**recp
)
479 FIND_NAME_BUFFER
*buffer
;
480 FIND_NAME_HEADER
*header
;
481 DNS_RECORDA
*record
= NULL
;
483 DNS_STATUS status
= ERROR_INVALID_NAME
;
485 len
= strlen( name
);
486 if (len
>= NCBNAMSZ
) return DNS_ERROR_RCODE_NAME_ERROR
;
488 DNS_RRSET_INIT( rrset
);
490 memset( &ncb
, 0, sizeof(ncb
) );
491 ncb
.ncb_command
= NCBFINDNAME
;
493 memset( ncb
.ncb_callname
, ' ', sizeof(ncb
.ncb_callname
) );
494 memcpy( ncb
.ncb_callname
, name
, len
);
495 ncb
.ncb_callname
[NCBNAMSZ
- 1] = '\0';
497 ret
= Netbios( &ncb
);
498 if (ret
!= NRC_GOODRET
) return ERROR_INVALID_NAME
;
500 header
= (FIND_NAME_HEADER
*)ncb
.ncb_buffer
;
501 buffer
= (FIND_NAME_BUFFER
*)((char *)header
+ sizeof(FIND_NAME_HEADER
));
503 for (i
= 0; i
< header
->node_count
; i
++)
505 record
= heap_alloc_zero( sizeof(DNS_RECORDA
) );
508 status
= ERROR_NOT_ENOUGH_MEMORY
;
513 record
->pName
= dns_strdup_u( name
);
516 status
= ERROR_NOT_ENOUGH_MEMORY
;
520 record
->wType
= DNS_TYPE_A
;
521 record
->Flags
.S
.Section
= DnsSectionAnswer
;
522 record
->Flags
.S
.CharSet
= DnsCharSetUtf8
;
523 record
->dwTtl
= DEFAULT_TTL
;
525 /* FIXME: network byte order? */
526 record
->Data
.A
.IpAddress
= *(DWORD
*)((char *)buffer
[i
].destination_addr
+ 2);
528 DNS_RRSET_ADD( rrset
, (DNS_RECORD
*)record
);
531 status
= ERROR_SUCCESS
;
534 DNS_RRSET_TERMINATE( rrset
);
536 if (status
!= ERROR_SUCCESS
)
537 DnsRecordListFree( rrset
.pFirstRR
, DnsFreeRecordList
);
539 *recp
= (DNS_RECORDA
*)rrset
.pFirstRR
;
544 /* res_init() must have been called before calling these three functions.
546 static DNS_STATUS
dns_set_serverlist( const IP4_ARRAY
*addrs
)
550 if (addrs
->AddrCount
> MAXNS
)
552 WARN( "too many servers: %d only using the first: %d\n",
553 addrs
->AddrCount
, MAXNS
);
554 _res
.nscount
= MAXNS
;
556 else _res
.nscount
= addrs
->AddrCount
;
558 for (i
= 0; i
< _res
.nscount
; i
++)
559 _res
.nsaddr_list
[i
].sin_addr
.s_addr
= addrs
->AddrArray
[i
];
561 return ERROR_SUCCESS
;
564 static DNS_STATUS
dns_get_serverlist( PIP4_ARRAY addrs
, PDWORD len
)
569 size
= FIELD_OFFSET(IP4_ARRAY
, AddrArray
[_res
.nscount
]);
570 if (!addrs
|| *len
< size
)
573 return ERROR_INSUFFICIENT_BUFFER
;
576 addrs
->AddrCount
= _res
.nscount
;
578 for (i
= 0; i
< _res
.nscount
; i
++)
579 addrs
->AddrArray
[i
] = _res
.nsaddr_list
[i
].sin_addr
.s_addr
;
581 return ERROR_SUCCESS
;
584 #define DNS_MAX_PACKET_SIZE 4096
585 static DNS_STATUS
dns_do_query( PCSTR name
, WORD type
, DWORD options
, PDNS_RECORDA
*result
)
587 DNS_STATUS ret
= DNS_ERROR_RCODE_NOT_IMPLEMENTED
;
590 unsigned char answer
[DNS_MAX_PACKET_SIZE
];
591 ns_sect sections
[] = { ns_s_an
, ns_s_ar
};
594 DNS_RECORDA
*record
= NULL
;
598 DNS_RRSET_INIT( rrset
);
600 len
= res_query( name
, ns_c_in
, type
, answer
, sizeof(answer
) );
603 ret
= dns_map_h_errno( h_errno
);
607 if (dns_ns_initparse( answer
, len
, &msg
) < 0)
609 ret
= DNS_ERROR_BAD_PACKET
;
613 #define RCODE_MASK 0x0f
614 if ((msg
._flags
& RCODE_MASK
) != ns_r_noerror
)
616 ret
= dns_map_error( msg
._flags
& RCODE_MASK
);
620 for (i
= 0; i
< sizeof(sections
)/sizeof(sections
[0]); i
++)
622 for (num
= 0; num
< ns_msg_count( msg
, sections
[i
] ); num
++)
624 ret
= dns_copy_record( msg
, sections
[i
], num
, &record
);
625 if (ret
!= ERROR_SUCCESS
) goto exit
;
627 DNS_RRSET_ADD( rrset
, (DNS_RECORD
*)record
);
632 DNS_RRSET_TERMINATE( rrset
);
634 if (ret
!= ERROR_SUCCESS
)
635 DnsRecordListFree( rrset
.pFirstRR
, DnsFreeRecordList
);
637 *result
= (DNS_RECORDA
*)rrset
.pFirstRR
;
642 #endif /* HAVE_RESOLV */
644 /******************************************************************************
645 * DnsQuery_A [DNSAPI.@]
648 DNS_STATUS WINAPI
DnsQuery_A( PCSTR name
, WORD type
, DWORD options
, PVOID servers
,
649 PDNS_RECORDA
*result
, PVOID
*reserved
)
652 DNS_RECORDW
*resultW
;
655 TRACE( "(%s,%s,0x%08x,%p,%p,%p)\n", debugstr_a(name
), dns_type_to_str( type
),
656 options
, servers
, result
, reserved
);
658 if (!name
|| !result
)
659 return ERROR_INVALID_PARAMETER
;
661 nameW
= dns_strdup_aw( name
);
662 if (!nameW
) return ERROR_NOT_ENOUGH_MEMORY
;
664 status
= DnsQuery_W( nameW
, type
, options
, servers
, &resultW
, reserved
);
666 if (status
== ERROR_SUCCESS
)
668 *result
= (DNS_RECORDA
*)DnsRecordSetCopyEx(
669 (DNS_RECORD
*)resultW
, DnsCharSetUnicode
, DnsCharSetAnsi
);
671 if (!*result
) status
= ERROR_NOT_ENOUGH_MEMORY
;
672 DnsRecordListFree( (DNS_RECORD
*)resultW
, DnsFreeRecordList
);
679 /******************************************************************************
680 * DnsQuery_UTF8 [DNSAPI.@]
683 DNS_STATUS WINAPI
DnsQuery_UTF8( PCSTR name
, WORD type
, DWORD options
, PVOID servers
,
684 PDNS_RECORDA
*result
, PVOID
*reserved
)
686 DNS_STATUS ret
= DNS_ERROR_RCODE_NOT_IMPLEMENTED
;
689 TRACE( "(%s,%s,0x%08x,%p,%p,%p)\n", debugstr_a(name
), dns_type_to_str( type
),
690 options
, servers
, result
, reserved
);
692 if (!name
|| !result
)
693 return ERROR_INVALID_PARAMETER
;
695 initialise_resolver();
696 _res
.options
|= dns_map_options( options
);
698 if (servers
&& (ret
= dns_set_serverlist( servers
)))
701 ret
= dns_do_query( name
, type
, options
, result
);
703 if (ret
== DNS_ERROR_RCODE_NAME_ERROR
&& type
== DNS_TYPE_A
&&
704 !(options
& DNS_QUERY_NO_NETBT
))
706 TRACE( "dns lookup failed, trying netbios query\n" );
707 ret
= dns_do_query_netbios( name
, result
);
714 /******************************************************************************
715 * DnsQuery_W [DNSAPI.@]
718 DNS_STATUS WINAPI
DnsQuery_W( PCWSTR name
, WORD type
, DWORD options
, PVOID servers
,
719 PDNS_RECORDW
*result
, PVOID
*reserved
)
722 DNS_RECORDA
*resultA
;
725 TRACE( "(%s,%s,0x%08x,%p,%p,%p)\n", debugstr_w(name
), dns_type_to_str( type
),
726 options
, servers
, result
, reserved
);
728 if (!name
|| !result
)
729 return ERROR_INVALID_PARAMETER
;
731 nameU
= dns_strdup_wu( name
);
732 if (!nameU
) return ERROR_NOT_ENOUGH_MEMORY
;
734 status
= DnsQuery_UTF8( nameU
, type
, options
, servers
, &resultA
, reserved
);
736 if (status
== ERROR_SUCCESS
)
738 *result
= (DNS_RECORDW
*)DnsRecordSetCopyEx(
739 (DNS_RECORD
*)resultA
, DnsCharSetUtf8
, DnsCharSetUnicode
);
741 if (!*result
) status
= ERROR_NOT_ENOUGH_MEMORY
;
742 DnsRecordListFree( (DNS_RECORD
*)resultA
, DnsFreeRecordList
);
749 static DNS_STATUS
dns_get_hostname_a( COMPUTER_NAME_FORMAT format
,
750 PSTR buffer
, PDWORD len
)
753 DWORD size
= sizeof(name
)/sizeof(name
[0]);
755 if (!GetComputerNameExA( format
, name
, &size
))
756 return DNS_ERROR_NAME_DOES_NOT_EXIST
;
758 if (!buffer
|| (size
= lstrlenA( name
) + 1) > *len
)
761 return ERROR_INSUFFICIENT_BUFFER
;
764 lstrcpyA( buffer
, name
);
765 return ERROR_SUCCESS
;
768 static DNS_STATUS
dns_get_hostname_w( COMPUTER_NAME_FORMAT format
,
769 PWSTR buffer
, PDWORD len
)
772 DWORD size
= sizeof(name
)/sizeof(name
[0]);
774 if (!GetComputerNameExW( format
, name
, &size
))
775 return DNS_ERROR_NAME_DOES_NOT_EXIST
;
777 if (!buffer
|| (size
= lstrlenW( name
) + 1) > *len
)
780 return ERROR_INSUFFICIENT_BUFFER
;
783 lstrcpyW( buffer
, name
);
784 return ERROR_SUCCESS
;
787 /******************************************************************************
788 * DnsQueryConfig [DNSAPI.@]
791 DNS_STATUS WINAPI
DnsQueryConfig( DNS_CONFIG_TYPE config
, DWORD flag
, PCWSTR adapter
,
792 PVOID reserved
, PVOID buffer
, PDWORD len
)
794 DNS_STATUS ret
= ERROR_INVALID_PARAMETER
;
796 TRACE( "(%d,0x%08x,%s,%p,%p,%p)\n", config
, flag
, debugstr_w(adapter
),
797 reserved
, buffer
, len
);
799 if (!len
) return ERROR_INVALID_PARAMETER
;
803 case DnsConfigDnsServerList
:
806 initialise_resolver();
807 ret
= dns_get_serverlist( buffer
, len
);
810 WARN( "compiled without resolver support\n" );
814 case DnsConfigHostName_A
:
815 case DnsConfigHostName_UTF8
:
816 return dns_get_hostname_a( ComputerNameDnsHostname
, buffer
, len
);
818 case DnsConfigFullHostName_A
:
819 case DnsConfigFullHostName_UTF8
:
820 return dns_get_hostname_a( ComputerNameDnsFullyQualified
, buffer
, len
);
822 case DnsConfigPrimaryDomainName_A
:
823 case DnsConfigPrimaryDomainName_UTF8
:
824 return dns_get_hostname_a( ComputerNameDnsDomain
, buffer
, len
);
826 case DnsConfigHostName_W
:
827 return dns_get_hostname_w( ComputerNameDnsHostname
, buffer
, len
);
829 case DnsConfigFullHostName_W
:
830 return dns_get_hostname_w( ComputerNameDnsFullyQualified
, buffer
, len
);
832 case DnsConfigPrimaryDomainName_W
:
833 return dns_get_hostname_w( ComputerNameDnsDomain
, buffer
, len
);
835 case DnsConfigAdapterDomainName_A
:
836 case DnsConfigAdapterDomainName_W
:
837 case DnsConfigAdapterDomainName_UTF8
:
838 case DnsConfigSearchList
:
839 case DnsConfigAdapterInfo
:
840 case DnsConfigPrimaryHostNameRegistrationEnabled
:
841 case DnsConfigAdapterHostNameRegistrationEnabled
:
842 case DnsConfigAddressRegistrationMaxCount
:
843 FIXME( "unimplemented config type %d\n", config
);
847 WARN( "unknown config type: %d\n", config
);