[MSWSOCK] Change functions to be able to use control flags with DnsQuery.
authorPeter Hater <7element@mail.bg>
Thu, 1 Jun 2017 15:22:06 +0000 (15:22 +0000)
committerPeter Hater <7element@mail.bg>
Thu, 1 Jun 2017 15:22:06 +0000 (15:22 +0000)
Add host aliases to hostent if available and requested.
Only copy servent aliases if available and requested.

svn path=/trunk/; revision=74730

reactos/dll/win32/mswsock/mswhelper.c
reactos/dll/win32/mswsock/mswhelper.h
reactos/dll/win32/mswsock/nsplookup.c

index ce84408..e3f20d0 100644 (file)
@@ -226,6 +226,7 @@ mswBufferAppendStrLstA(_Inout_ PMSW_BUFFER mswBuf,
 BOOL
 mswBufferAppendBlob_Hostent(_Inout_ PMSW_BUFFER mswBuf,
                             _Inout_ LPWSAQUERYSETW lpRes,
+                            _In_ char** hostAliasesA,
                             _In_ char* hostnameA,
                             _In_ DWORD ip4addr)
 {
@@ -256,8 +257,18 @@ mswBufferAppendBlob_Hostent(_Inout_ PMSW_BUFFER mswBuf,
     /* aliases */
     phe->h_aliases = (char**)(mswBufferEndPtr(mswBuf) - bytesOfs);
 
-    if (!mswBufferAppendPtr(mswBuf, NULL))
-        return FALSE;
+    if (hostAliasesA)
+    {
+        if (!mswBufferAppendStrLstA(mswBuf,
+                                    (void**)hostAliasesA,
+                                    -(DWORD)bytesOfs))
+            return FALSE;
+    }
+    else
+    {
+        if (!mswBufferAppendPtr(mswBuf, NULL))
+            return FALSE;
+    }
 
     /* addr_list */
     RtlZeroMemory(lst, sizeof(lst));
@@ -308,10 +319,18 @@ mswBufferAppendBlob_Servent(_Inout_ PMSW_BUFFER mswBuf,
 
     pse->s_aliases = (char**)(mswBufferEndPtr(mswBuf) - bytesOfs);
 
-    if (!mswBufferAppendStrLstA(mswBuf,
-                                (void**)serviceAliasesA,
-                                -(DWORD)bytesOfs))
-        return FALSE;
+    if (serviceAliasesA)
+    {
+        if (!mswBufferAppendStrLstA(mswBuf,
+                                    (void**)serviceAliasesA,
+                                    -(DWORD)bytesOfs))
+            return FALSE;
+    }
+    else
+    {
+        if (!mswBufferAppendPtr(mswBuf, NULL))
+            return FALSE;
+    }
 
     pse->s_name = (char*)(mswBufferEndPtr(mswBuf) - bytesOfs);
 
index 588ea58..1680752 100644 (file)
@@ -69,7 +69,8 @@ BOOL
 mswBufferAppendBlob_Hostent(
   _Inout_ PMSW_BUFFER mswBuf,
   _Inout_ LPWSAQUERYSETW lpRes,
-  _In_ char* hostnameA,
+    _In_ char** hostAliasesA,
+    _In_ char* hostnameA,
   _In_ DWORD ip4addr);
 
 BOOL
index de3efe5..23bbe59 100644 (file)
@@ -106,7 +106,7 @@ NSP_LookupServiceBeginW(
 INT
 NSP_LookupServiceNextW(
   _In_ PWSHANDLEINTERN data,
-  _In_ DWORD CallID,
+  _In_ DWORD dwControlFlags,
   _Inout_ LPWSAQUERYSETW lpRes,
   _Inout_ LPDWORD lpResLen);
 
@@ -116,14 +116,14 @@ NSP_GetHostNameHeapAllocW(
 
 INT
 NSP_GetHostByNameHeapAllocW(
-  _In_ WCHAR* name,
-  _In_ GUID* lpProviderId,
+  _In_ PWSHANDLEINTERN data,
+  _In_ DWORD dwControlFlags,
   _Out_ PWSHOSTINFOINTERN hostinfo);
 
 INT
 NSP_GetServiceByNameHeapAllocW(
-  _In_ WCHAR* nameW,
-  _In_ GUID* lpProviderId,
+  _In_ PWSHANDLEINTERN data,
+  _In_ DWORD dwControlFlags,
   _Out_ PWSHOSTINFOINTERN hostinfo);
 
 /* Implementations - Internal */
@@ -303,7 +303,7 @@ mwsNSPLookupServiceNext(_In_ HANDLE hLookup,
     lpqsResults->dwSize = sizeof(*lpqsResults);
 
     wsaErr = NSP_LookupServiceNextW(pLook,
-                                    pLook->CallID,
+                                    dwControlFlags,
                                     lpqsResults,
                                     lpdwBufferLength);
 
@@ -464,8 +464,8 @@ NSP_GetHostNameHeapAllocW(_Out_ WCHAR** hostname)
 }
 
 INT
-NSP_GetHostByNameHeapAllocW(_In_ WCHAR* name,
-                            _In_ GUID* lpProviderId,
+NSP_GetHostByNameHeapAllocW(_In_ PWSHANDLEINTERN data,
+                            _In_ DWORD dwControlFlags,
                             _Out_ PWSHOSTINFOINTERN hostinfo)
 {
     HANDLE hHeap = GetProcessHeap();
@@ -474,21 +474,27 @@ NSP_GetHostByNameHeapAllocW(_In_ WCHAR* name,
     PDNS_RECORD dp;
     PDNS_RECORD curr;
     INT result = ERROR_SUCCESS;
+    DWORD dwQueryFlags = DNS_QUERY_STANDARD;
 
     /* needed to be cleaned up if != NULL */
     dp = NULL;
 
-    if (name == NULL)
+    if (data->hostnameW == NULL)
     {
         result = ERROR_INVALID_PARAMETER;
         goto cleanup;
     }
 
+    if ((data->dwControlFlags & LUP_DEEP) == 0)
+    {
+        dwQueryFlags |= DNS_QUERY_NO_RECURSION;
+    }
+
     /* DNS_TYPE_A: include/WinDNS.h */
     /* DnsQuery -- lib/dnsapi/dnsapi/query.c */
-    dns_status = DnsQuery(name,
+    dns_status = DnsQuery(data->hostnameW,
                           DNS_TYPE_A,
-                          DNS_QUERY_STANDARD,
+                          dwQueryFlags,
                           /* extra dns servers */ 0,
                           &dp,
                           0);
@@ -511,6 +517,7 @@ NSP_GetHostByNameHeapAllocW(_In_ WCHAR* name,
     curr = dp;
     while ((curr->pNext != NULL) || (curr->wType != DNS_TYPE_A))
     {
+        /* FIXME build aliases list */
         curr = curr->pNext;
     }
 
@@ -522,6 +529,7 @@ NSP_GetHostByNameHeapAllocW(_In_ WCHAR* name,
 
     hostinfo->hostnameW = StrCpyHeapAllocW(hHeap, curr->pName);
     hostinfo->addr4 = curr->Data.A.IpAddress;
+    /* FIXME attach built aliases list */
     result = ERROR_SUCCESS;
 
 cleanup:
@@ -684,8 +692,8 @@ OpenNetworkDatabase(_In_ LPCWSTR Name)
 }
 
 INT
-NSP_GetServiceByNameHeapAllocW(_In_ WCHAR* nameW,
-                               _In_ GUID* lpProviderId,
+NSP_GetServiceByNameHeapAllocW(_In_ PWSHANDLEINTERN data,
+                               _In_ DWORD dwControlFlags,
                                _Out_ PWSHOSTINFOINTERN hostinfo)
 {
     BOOL Found = FALSE;
@@ -703,14 +711,14 @@ NSP_GetServiceByNameHeapAllocW(_In_ WCHAR* nameW,
     PCHAR nameProtoA = NULL;
     INT res = WSANO_RECOVERY;
     
-    if (!nameW)
+    if (!data->hostnameW)
     {
         res = WSANO_RECOVERY;
         goto End;
     }
 
     hHeap = GetProcessHeap();
-    nameA = StrW2AHeapAlloc(hHeap, nameW);
+    nameA = StrW2AHeapAlloc(hHeap, data->hostnameW);
 
     /* nameA has the form <service-name>/<protocol>
        we split these now */
@@ -837,7 +845,7 @@ End:
 
 INT
 NSP_LookupServiceNextW(_In_ PWSHANDLEINTERN data,
-                       _In_ DWORD CallID,
+                       _In_ DWORD dwControlFlags,
                        _Inout_ LPWSAQUERYSETW lpRes,
                        _Inout_ LPDWORD lpResLen)
 {
@@ -860,9 +868,9 @@ NSP_LookupServiceNextW(_In_ PWSHANDLEINTERN data,
     lpRes->dwSize = sizeof(*lpRes);
     lpRes->dwNameSpace = NS_DNS;
 
-    if ((CallID == NSP_CALLID_HOSTNAME) ||
-        (CallID == NSP_CALLID_HOSTBYNAME) ||
-        (CallID == NSP_CALLID_SERVICEBYNAME))
+    if ((data->CallID == NSP_CALLID_HOSTNAME) ||
+        (data->CallID == NSP_CALLID_HOSTBYNAME) ||
+        (data->CallID == NSP_CALLID_SERVICEBYNAME))
     {
         if (data->CallIDCounter >= 1)
         {
@@ -877,7 +885,7 @@ NSP_LookupServiceNextW(_In_ PWSHANDLEINTERN data,
     }
     data->CallIDCounter++;
 
-    if (CallID == NSP_CALLID_HOSTNAME)
+    if (data->CallID == NSP_CALLID_HOSTNAME)
     {
         result = NSP_GetHostNameHeapAllocW(&hostinfo.hostnameW);
 
@@ -886,19 +894,19 @@ NSP_LookupServiceNextW(_In_ PWSHANDLEINTERN data,
 
         hostinfo.addr4 = 0;
     }
-    else if (CallID == NSP_CALLID_HOSTBYNAME)
+    else if (data->CallID == NSP_CALLID_HOSTBYNAME)
     {
-        result = NSP_GetHostByNameHeapAllocW(data->hostnameW,
-                                             &data->providerId,
+        result = NSP_GetHostByNameHeapAllocW(data,
+                                             dwControlFlags,
                                              &hostinfo);
         if (result != ERROR_SUCCESS)
             goto End;
     }
     else
     {
-        ASSERT(CallID == NSP_CALLID_SERVICEBYNAME);
-        result = NSP_GetServiceByNameHeapAllocW(data->hostnameW,
-                                                &data->providerId,
+        ASSERT(data->CallID == NSP_CALLID_SERVICEBYNAME);
+        result = NSP_GetServiceByNameHeapAllocW(data,
+                                                dwControlFlags,
                                                 &hostinfo);
         if (result != ERROR_SUCCESS)
             goto End;
@@ -907,7 +915,7 @@ NSP_LookupServiceNextW(_In_ PWSHANDLEINTERN data,
     if (((LUP_RETURN_BLOB & data->dwControlFlags) != 0) ||
         ((LUP_RETURN_NAME & data->dwControlFlags) != 0))
     {
-        if (CallID == NSP_CALLID_HOSTNAME || CallID == NSP_CALLID_HOSTBYNAME)
+        if (data->CallID == NSP_CALLID_HOSTNAME || data->CallID == NSP_CALLID_HOSTBYNAME)
         {
             ServiceInstanceNameW = hostinfo.hostnameW;
             ServiceInstanceNameA = StrW2AHeapAlloc(hHeap, ServiceInstanceNameW);
@@ -918,7 +926,7 @@ NSP_LookupServiceNextW(_In_ PWSHANDLEINTERN data,
 
             }
         }
-        if (CallID == NSP_CALLID_SERVICEBYNAME)
+        if (data->CallID == NSP_CALLID_SERVICEBYNAME)
         {
             ServiceInstanceNameW = hostinfo.servnameW;
             ServiceInstanceNameA = StrW2AHeapAlloc(hHeap, ServiceInstanceNameW);
@@ -950,11 +958,12 @@ NSP_LookupServiceNextW(_In_ PWSHANDLEINTERN data,
 
     if ((LUP_RETURN_BLOB & data->dwControlFlags) != 0)
     {
-        if (CallID == NSP_CALLID_HOSTBYNAME)
+        if (data->CallID == NSP_CALLID_HOSTBYNAME)
         {
             /* Write data for PBLOB (hostent) */
             if (!mswBufferAppendBlob_Hostent(&buf,
                                              lpRes,
+                                             (LUP_RETURN_ALIASES & data->dwControlFlags) != 0 ? hostinfo.servaliasesA : NULL,
                                              ServiceInstanceNameA,
                                              hostinfo.addr4))
             {
@@ -963,13 +972,13 @@ NSP_LookupServiceNextW(_In_ PWSHANDLEINTERN data,
                 goto End;
             }
         }
-        else if (CallID == NSP_CALLID_SERVICEBYNAME)
+        else if (data->CallID == NSP_CALLID_SERVICEBYNAME)
         {
             /* Write data for PBLOB (servent) */
             if (!mswBufferAppendBlob_Servent(&buf,
                                              lpRes,
                                              ServiceInstanceNameA,/* ServiceName */
-                                             hostinfo.servaliasesA,
+                                             (LUP_RETURN_ALIASES & data->dwControlFlags) != 0 ? hostinfo.servaliasesA : NULL,
                                              ServiceProtocolNameA,
                                              hostinfo.servport))
             {