Commit d193c164 authored by Alexandre Julliard's avatar Alexandre Julliard

dnsapi: Build the DNS reply records on the PE side.

parent aec19e86
...@@ -125,7 +125,7 @@ struct resolv_funcs ...@@ -125,7 +125,7 @@ struct resolv_funcs
{ {
DNS_STATUS (CDECL *get_searchlist)( DNS_TXT_DATAW *list, DWORD *len ); DNS_STATUS (CDECL *get_searchlist)( DNS_TXT_DATAW *list, DWORD *len );
DNS_STATUS (CDECL *get_serverlist)( USHORT family, DNS_ADDR_ARRAY *addrs, DWORD *len ); DNS_STATUS (CDECL *get_serverlist)( USHORT family, DNS_ADDR_ARRAY *addrs, DWORD *len );
DNS_STATUS (CDECL *query)( const char *name, WORD type, DWORD options, DNS_RECORDA **result ); DNS_STATUS (CDECL *query)( const char *name, WORD type, DWORD options, void *buf, DWORD *len );
DNS_STATUS (CDECL *set_serverlist)( const IP4_ARRAY *addrs ); DNS_STATUS (CDECL *set_serverlist)( const IP4_ARRAY *addrs );
}; };
......
...@@ -168,6 +168,8 @@ DNS_STATUS WINAPI DnsQuery_UTF8( PCSTR name, WORD type, DWORD options, PVOID ser ...@@ -168,6 +168,8 @@ DNS_STATUS WINAPI DnsQuery_UTF8( PCSTR name, WORD type, DWORD options, PVOID ser
PDNS_RECORDA *result, PVOID *reserved ) PDNS_RECORDA *result, PVOID *reserved )
{ {
DNS_STATUS ret = DNS_ERROR_RCODE_NOT_IMPLEMENTED; DNS_STATUS ret = DNS_ERROR_RCODE_NOT_IMPLEMENTED;
unsigned char answer[4096];
DWORD len = sizeof(answer);
TRACE( "(%s,%s,0x%08x,%p,%p,%p)\n", debugstr_a(name), debugstr_type( type ), TRACE( "(%s,%s,0x%08x,%p,%p,%p)\n", debugstr_a(name), debugstr_type( type ),
options, servers, result, reserved ); options, servers, result, reserved );
...@@ -177,7 +179,29 @@ DNS_STATUS WINAPI DnsQuery_UTF8( PCSTR name, WORD type, DWORD options, PVOID ser ...@@ -177,7 +179,29 @@ DNS_STATUS WINAPI DnsQuery_UTF8( PCSTR name, WORD type, DWORD options, PVOID ser
if ((ret = resolv_funcs->set_serverlist( servers ))) return ret; if ((ret = resolv_funcs->set_serverlist( servers ))) return ret;
ret = resolv_funcs->query( name, type, options, result ); ret = resolv_funcs->query( name, type, options, answer, &len );
if (!ret)
{
DNS_MESSAGE_BUFFER *buffer = (DNS_MESSAGE_BUFFER *)answer;
if (len < sizeof(buffer->MessageHead)) return DNS_ERROR_BAD_PACKET;
DNS_BYTE_FLIP_HEADER_COUNTS( &buffer->MessageHead );
switch (buffer->MessageHead.ResponseCode)
{
case DNS_RCODE_NOERROR: ret = DnsExtractRecordsFromMessage_UTF8( buffer, len, result ); break;
case DNS_RCODE_FORMERR: ret = DNS_ERROR_RCODE_FORMAT_ERROR; break;
case DNS_RCODE_SERVFAIL: ret = DNS_ERROR_RCODE_SERVER_FAILURE; break;
case DNS_RCODE_NXDOMAIN: ret = DNS_ERROR_RCODE_NAME_ERROR; break;
case DNS_RCODE_NOTIMPL: ret = DNS_ERROR_RCODE_NOT_IMPLEMENTED; break;
case DNS_RCODE_REFUSED: ret = DNS_ERROR_RCODE_REFUSED; break;
case DNS_RCODE_YXDOMAIN: ret = DNS_ERROR_RCODE_YXDOMAIN; break;
case DNS_RCODE_YXRRSET: ret = DNS_ERROR_RCODE_YXRRSET; break;
case DNS_RCODE_NXRRSET: ret = DNS_ERROR_RCODE_NXRRSET; break;
case DNS_RCODE_NOTAUTH: ret = DNS_ERROR_RCODE_NOTAUTH; break;
case DNS_RCODE_NOTZONE: ret = DNS_ERROR_RCODE_NOTZONE; break;
default: ret = DNS_ERROR_RCODE_NOT_IMPLEMENTED; break;
}
}
if (ret == DNS_ERROR_RCODE_NAME_ERROR && type == DNS_TYPE_A && if (ret == DNS_ERROR_RCODE_NAME_ERROR && type == DNS_TYPE_A &&
!(options & DNS_QUERY_NO_NETBT)) !(options & DNS_QUERY_NO_NETBT))
......
...@@ -108,6 +108,18 @@ extern "C" { ...@@ -108,6 +108,18 @@ extern "C" {
#define DNS_QUERY_DNSSEC_CHECKING_DISABLED 0x02000000 #define DNS_QUERY_DNSSEC_CHECKING_DISABLED 0x02000000
#define DNS_QUERY_RESERVED 0xff000000 #define DNS_QUERY_RESERVED 0xff000000
#define INLINE_WORD_FLIP(out, in) { WORD _in = (in); (out) = (_in << 8) | (_in >> 8); }
#define INLINE_HTONS(out, in) INLINE_WORD_FLIP(out, in)
#define INLINE_NTOHS(out, in) INLINE_WORD_FLIP(out, in)
#define DNS_BYTE_FLIP_HEADER_COUNTS(header) { \
DNS_HEADER *_head = (header); \
INLINE_HTONS( _head->Xid, _head->Xid ); \
INLINE_HTONS( _head->QuestionCount, _head->QuestionCount ); \
INLINE_HTONS( _head->AnswerCount, _head->AnswerCount ); \
INLINE_HTONS( _head->NameServerCount, _head->NameServerCount ); \
INLINE_HTONS( _head->AdditionalCount, _head->AdditionalCount ); }
typedef enum _DNS_NAME_FORMAT typedef enum _DNS_NAME_FORMAT
{ {
DnsNameDomain, DnsNameDomain,
...@@ -182,7 +194,11 @@ typedef struct ...@@ -182,7 +194,11 @@ typedef struct
#define DNS_ADDRESS_STRING_LENGTH IP6_ADDRESS_STRING_LENGTH #define DNS_ADDRESS_STRING_LENGTH IP6_ADDRESS_STRING_LENGTH
#define IP4_ADDRESS_STRING_BUFFER_LENGTH IP4_ADDRESS_STRING_LENGTH #define IP4_ADDRESS_STRING_BUFFER_LENGTH IP4_ADDRESS_STRING_LENGTH
#define IP6_ADDRESS_STRING_BUFFER_LENGTH IP6_ADDRESS_STRING_LENGTH #define IP6_ADDRESS_STRING_BUFFER_LENGTH IP6_ADDRESS_STRING_LENGTH
#define DNS_MAX_NAME_BUFFER_LENGTH 256
#define DNS_MAX_NAME_LENGTH 255
#define DNS_MAX_LABEL_LENGTH 63
#define DNS_MAX_NAME_BUFFER_LENGTH (DNS_MAX_NAME_LENGTH + 1)
#define DNS_MAX_LABEL_BUFFER_LENGTH (DNS_MAX_LABEL_LENGTH + 1)
typedef struct _IP4_ARRAY typedef struct _IP4_ARRAY
{ {
...@@ -190,6 +206,36 @@ typedef struct _IP4_ARRAY ...@@ -190,6 +206,36 @@ typedef struct _IP4_ARRAY
IP4_ADDRESS AddrArray[1]; IP4_ADDRESS AddrArray[1];
} IP4_ARRAY, *PIP4_ARRAY; } IP4_ARRAY, *PIP4_ARRAY;
#define DNS_OPCODE_QUERY 0
#define DNS_OPCODE_IQUERY 1
#define DNS_OPCODE_SERVER_STATUS 2
#define DNS_OPCODE_UNKNOWN 3
#define DNS_OPCODE_NOTIFY 4
#define DNS_OPCODE_UPDATE 5
#define DNS_RCODE_NOERROR 0
#define DNS_RCODE_FORMERR 1
#define DNS_RCODE_SERVFAIL 2
#define DNS_RCODE_NXDOMAIN 3
#define DNS_RCODE_NOTIMPL 4
#define DNS_RCODE_REFUSED 5
#define DNS_RCODE_YXDOMAIN 6
#define DNS_RCODE_YXRRSET 7
#define DNS_RCODE_NXRRSET 8
#define DNS_RCODE_NOTAUTH 9
#define DNS_RCODE_NOTZONE 10
#define DNS_RCODE_MAX 15
#define DNS_RCODE_BADVERS 16
#define DNS_RCODE_BADSIG 16
#define DNS_RCODE_BADKEY 17
#define DNS_RCODE_BADTIME 18
#define DNS_RCODE_NO_ERROR DNS_RCODE_NOERROR
#define DNS_RCODE_FORMAT_ERROR DNS_RCODE_FORMERR
#define DNS_RCODE_SERVER_FAILURE DNS_RCODE_SERVFAIL
#define DNS_RCODE_NAME_ERROR DNS_RCODE_NXDOMAIN
#define DNS_RCODE_NOT_IMPLEMENTED DNS_RCODE_NOTIMPL
#include <pshpack1.h> #include <pshpack1.h>
typedef struct _DNS_HEADER typedef struct _DNS_HEADER
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment