//---------------------------------------------------------------- // CImpIRestrictedProcess::RP_HelperWSALookupServiceBeginW() // //---------------------------------------------------------------- STDMETHODIMP CImpIRestrictedProcess::RP_HelperWSALookupServiceBeginW( IN RPC_WSAQUERYSETW *pRestrictions, IN DWORD dwControlFlags, OUT DWORD *pdwLookupHandle, OUT int *piRet, OUT int *piErrno ) { *piRet = SOCKET_ERROR; *piErrno = WSAEOPNOTSUPP; if ((!pRestrictions)||(!pRestrictions->lpServiceClassId)) { *piErrno = WSAEINVAL; return NOERROR; } if ( (0 != memcmp(pRestrictions->lpServiceClassId,&HostnameGuid,sizeof(GUID))) && (0 != memcmp(pRestrictions->lpServiceClassId,&AddressGuid,sizeof(GUID)))) { *piErrno = WSAEACCES; // or WSAEOPNOTSUPP? return NOERROR; } DWORD dwFlagsMask = ~( LUP_RETURN_NAME | LUP_RETURN_TYPE | LUP_RETURN_VERSION | LUP_RETURN_COMMENT | LUP_RETURN_ADDR | LUP_RETURN_BLOB ); if (dwFlagsMask & dwControlFlags) { *piErrno = WSAEACCES; // or WSAEOPNOTSUPP? return NOERROR; } *piRet = WSALookupServiceBeginW( (WSAQUERYSETW *)pRestrictions, dwControlFlags, (HANDLE*)pdwLookupHandle ); if (*piRet == SOCKET_ERROR) { *piErrno = WSAGetLastError(); } else { *piErrno = NO_ERROR; } return NOERROR; }
/* * @implemented */ INT WSAAPI WSALookupServiceBeginA(IN LPWSAQUERYSETA lpqsRestrictions, IN DWORD dwControlFlags, OUT LPHANDLE lphLookup) { INT ErrorCode; LPWSAQUERYSETW UnicodeQuerySet = NULL; DWORD UnicodeQuerySetSize = 0; DPRINT("WSALookupServiceBeginA: %p\n", lpqsRestrictions); /* Verifiy pointer */ if (IsBadReadPtr(lpqsRestrictions, sizeof(*lpqsRestrictions))) { /* Invalid */ SetLastError(WSAEFAULT); return SOCKET_ERROR; } /* Clear the reserved fields */ lpqsRestrictions->dwOutputFlags = 0; lpqsRestrictions->lpszComment = NULL; lpqsRestrictions->dwNumberOfCsAddrs = 0; /* Find out the side we'll need */ ErrorCode = MapAnsiQuerySetToUnicode(lpqsRestrictions, &UnicodeQuerySetSize, UnicodeQuerySet); /* We should've failed */ if (ErrorCode == WSAEFAULT) { /* Allocate the buffer we'll need */ UnicodeQuerySet = HeapAlloc(WsSockHeap, 0, UnicodeQuerySetSize); if (UnicodeQuerySet) { /* Do the conversion for real */ ErrorCode = MapAnsiQuerySetToUnicode(lpqsRestrictions, &UnicodeQuerySetSize, UnicodeQuerySet); if (ErrorCode == ERROR_SUCCESS) { /* Now call the Unicode function */ ErrorCode = WSALookupServiceBeginW(UnicodeQuerySet, dwControlFlags, lphLookup); } else { /* Fail, conversion failed */ SetLastError(ErrorCode); } /* Free our buffer */ HeapFree(WsSockHeap, 0, UnicodeQuerySet); } else { /* No memory to allocate */ SetLastError(WSAEFAULT); } } else { /* We couldn't get the size for some reason */ SetLastError(ErrorCode); } /* Return to caller */ return ErrorCode == ERROR_SUCCESS ? ErrorCode : SOCKET_ERROR; }
static INT WINAPI LookupNodeByAddr(IN LPWSTR pNodeBuffer, IN DWORD NodeBufferSize, IN BOOLEAN OnlyNodeName, IN PVOID Addr, IN DWORD AddrSize, IN INT AddressFamily) { GUID LookupGuid = SVCID_DNS_TYPE_PTR; PIN_ADDR Ip4Addr = Addr; WCHAR ReverseBuffer[76]; WSAQUERYSETW Restrictions, Reply; DWORD BufferLength; INT ErrorCode; HANDLE LookupHandle; /* Validate the address */ if (!Addr) return WSAEFAULT; /* Make sure the family and address size match */ if (AddressFamily == AF_INET6) { /* Check the address size for this type */ if (AddrSize != sizeof(IN6_ADDR)) return WSAEFAULT; Ip4Addr = (PIN_ADDR)&((PIN6_ADDR)Addr)->u.Byte[12]; } else if (AddressFamily == AF_INET) { /* Check the address size for this type */ if (AddrSize != sizeof(IN_ADDR)) return WSAEFAULT; } else { /* Address family not supported */ return WSAEAFNOSUPPORT; } /* Check if this is a mapped V4 IPv6 or pure IPv4 */ if (((AddressFamily == AF_INET6) && (IN6_IS_ADDR_V4MAPPED(Addr))) || (AddressFamily == AF_INET)) { /* Get the reverse name */ Dns_Ip4AddressToReverseName_W(ReverseBuffer, *Ip4Addr); } /* FIXME: Not implemented for now else if ( */ /* By this point we have the Reverse Name, so prepare for lookup */ RtlZeroMemory(&Restrictions, sizeof(Restrictions)); Restrictions.dwSize = sizeof(Restrictions); Restrictions.lpszServiceInstanceName = ReverseBuffer; Restrictions.lpServiceClassId = &LookupGuid; Restrictions.dwNameSpace = NS_DNS; /* Now do the lookup */ ErrorCode = WSALookupServiceBeginW(&Restrictions, LUP_RETURN_NAME, &LookupHandle); if (ErrorCode == ERROR_SUCCESS) { /* Lookup successful, now get the data */ BufferLength = (NI_MAXHOST - 1) * sizeof(WCHAR) + sizeof(Restrictions); ErrorCode = WSALookupServiceNextW(LookupHandle, 0, &BufferLength, &Restrictions); if (ErrorCode == ERROR_SUCCESS) { /* Now check if we have a name back */ Reply = Restrictions; if (!Reply.lpszServiceInstanceName) { /* Fail */ ErrorCode = WSAHOST_NOT_FOUND; } else { /* Check if the caller only wants the node name */ if (OnlyNodeName) { /* Split it and get only the partial host name */ Dns_SplitHostFromDomainNameW(Reply.lpszServiceInstanceName); } /* Check the length and see if it's within our limit */ if (wcslen(Reply.lpszServiceInstanceName) + 1 > NodeBufferSize) { /* It's not, so fail */ ErrorCode = WSAEFAULT; } else { /* It will fit, let's copy it*/ wcscpy(pNodeBuffer, Reply.lpszServiceInstanceName); } } } } else if (ErrorCode == WSASERVICE_NOT_FOUND) { /* Normalize the error code */ ErrorCode = WSAHOST_NOT_FOUND; } /* Finish the lookup if one was in progress */ if (LookupHandle) WSALookupServiceEnd(LookupHandle); /* Return the error code */ return ErrorCode; }