DWORD VmAfdGeneratePtrNameFromIp( PCSTR pszIPAddress, PSTR* ppszPtrName ) { DWORD dwError = 0; DWORD dwAddr = 0; PSTR pszPtrName = NULL; BYTE* pByte = NULL; DWORD ret = 0; int af = AF_INET; unsigned char buf[sizeof(struct in6_addr)]; BAIL_ON_VMAFD_EMPTY_STRING(pszIPAddress, dwError); BAIL_ON_VMAFD_INVALID_POINTER(ppszPtrName, dwError); if (VmAfdStringChrA(pszIPAddress, ':')) { af = AF_INET6; } ret = inet_pton(af, pszIPAddress, buf); if (ret <= 0) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } if (af == AF_INET) { dwAddr = ((struct in_addr*)buf)->s_addr; // See RFC 1035 for name format // In short, record name is octets in reverse order appened with "in-addr.arpa". // Example: 11.1.193.128.in-addr.arpa dwError = VmAfdAllocateStringPrintf( &pszPtrName, "%d.%d.%d.%d%s.", (dwAddr & 0xFF000000) >> 24, (dwAddr & 0xFF0000) >> 16, (dwAddr & 0xFF00) >> 8, (dwAddr & 0xFF), PTR_NAME_SUFFIX_IP4 ); BAIL_ON_VMAFD_ERROR(dwError); }
/* * If pszServerName is in IP format, use it as Lotus Server Name. * If pszServerName is NOT "localhost" which means caller specify a name they prefer, use it as the Lotus Server Name. * * Otherwise, derive FQDN based on existing network naming configuration. * i.e. Call gethostname then perform forward+reverse lookup to derive the FQDN as Lotus Server Name. * The forward+reverse look up is for kerberos naming consistency between server (Lotus) and clients, which * could be Lotus or open sources, e.g. openldap. * However, this auto name resolution is error-prone as system could have multiple IF(s) defined and * we have no idea which IF we should pick to perform reverse lookup. * Thus, the best chance to get Kerberos working is - customer provides proper FQDN as Lotus Server Name. */ static DWORD VmAfSrvGetLotusServerName( PCSTR pszServerName, PSTR* ppOutServerName ) { DWORD dwError = 0; PSTR pszHostnameCanon = NULL; PSTR pszLocalHostName = NULL; PSTR pszFQDN = NULL; if ( !pszServerName || !ppOutServerName ) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } if ( VmAfdStringCompareA( pszServerName, "localhost", FALSE ) != 0 ) { // caller provides preferred Lotus Server Name or IP dwError = VmAfdAllocateStringA( pszServerName, &pszHostnameCanon ); BAIL_ON_VMAFD_ERROR(dwError); } else { // caller does NOT specify preferred Lotus Server Name, derives it ourselves. dwError = VmAfdGetHostName(&pszLocalHostName); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdGetCanonicalHostName(pszLocalHostName, &pszHostnameCanon); BAIL_ON_VMAFD_ERROR(dwError); } BAIL_ON_VMAFD_EMPTY_STRING(pszHostnameCanon, dwError); if (!VmAfdCheckIfIPV4AddressA(pszHostnameCanon) && !VmAfdCheckIfIPV6AddressA(pszHostnameCanon) && pszHostnameCanon[VmAfdStringLenA(pszHostnameCanon) - 1] != '.') { dwError = VmAfdAllocateStringPrintf( &pszFQDN, "%s.", pszHostnameCanon); BAIL_ON_VMAFD_ERROR(dwError); } else { pszFQDN = pszHostnameCanon; pszHostnameCanon = NULL; } *ppOutServerName = pszFQDN; VmAfdLog(VMAFD_DEBUG_ANY, "Lotus server name: (%s)", *ppOutServerName); cleanup: VMAFD_SAFE_FREE_MEMORY(pszHostnameCanon); return dwError; error: VMAFD_SAFE_FREE_MEMORY(pszFQDN); VmAfdLog(VMAFD_DEBUG_ANY, "%s failed (%s). Error(%u)", __FUNCTION__, pszServerName, dwError); goto cleanup; }