wbcErr wbcInterfaceDetails(struct wbcInterfaceDetails **details) { DWORD dwErr = LW_ERROR_INTERNAL; wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; HANDLE hLsa = NULL; PLSA_MACHINE_ACCOUNT_INFO_A pAccountInfo = NULL; size_t hostnameLen = 0; BAIL_ON_NULL_PTR_PARAM(details, dwErr); /* Find our domain */ dwErr = LsaOpenServer(&hLsa); BAIL_ON_LSA_ERR(dwErr); dwErr = LsaAdGetMachineAccountInfo(hLsa, NULL, &pAccountInfo); BAIL_ON_LSA_ERR(dwErr); *details = _wbc_malloc(sizeof(struct wbcInterfaceDetails), FreeInterfaceDetails); BAIL_ON_NULL_PTR(*details, dwErr); (*details)->interface_version = LSA_WBC_INTERFACE_VERSION; (*details)->winbind_version = LSA_WBC_WINBIND_VERSION; (*details)->winbind_separator = '\\'; (*details)->netbios_name = _wbc_strdup(pAccountInfo->SamAccountName); BAIL_ON_NULL_PTR((*details)->netbios_name, dwErr); // Strip off the trailing dollar sign hostnameLen = strlen((*details)->netbios_name); if (hostnameLen > 0 && (*details)->netbios_name[hostnameLen - 1] == '$') { ((char *)(*details)->netbios_name)[hostnameLen - 1] = 0; } (*details)->netbios_domain = _wbc_strdup(pAccountInfo->NetbiosDomainName); BAIL_ON_NULL_PTR((*details)->netbios_domain, dwErr); (*details)->dns_domain = _wbc_strdup(pAccountInfo->DnsDomainName); BAIL_ON_NULL_PTR((*details)->dns_domain, dwErr); cleanup: if (pAccountInfo) { LsaAdFreeMachineAccountInfo(pAccountInfo); } if (hLsa) { LsaCloseServer(hLsa); } wbc_status = map_error_to_wbc_status(dwErr); return wbc_status; }
BOOLEAN StrEqual( PCSTR pszStr1, PCSTR pszStr2 ) { PSTR pszCopy1 = NULL; PSTR pszCopy2 = NULL; BOOLEAN bEqual = FALSE; /* If same pointer, then must be equal */ if (pszStr1 == pszStr2) return TRUE; /* If either is NULL, cannot be substrings */ if (!pszStr1 || !pszStr2) return FALSE; /* Check lengths */ if (strlen(pszStr1) != strlen(pszStr2)) return FALSE; /* Now copy, convert to upper case, and compare */ pszCopy1 = _wbc_strdup(pszStr1); if (!pszCopy1) { goto cleanup; } pszCopy2 = _wbc_strdup(pszStr2); if (!pszCopy2) { goto cleanup; } StrUpper(pszCopy1); StrUpper(pszCopy2); if (strcmp(pszCopy1, pszCopy2) == 0) { bEqual = TRUE; } cleanup: _WBC_FREE(pszCopy1); _WBC_FREE(pszCopy2); return bEqual; }
BOOLEAN StrnEqual( PCSTR pszStr1, PCSTR pszStr2, DWORD dwChars ) { DWORD dwLen1, dwLen2; PSTR pszCopy1 = NULL; PSTR pszCopy2 = NULL; BOOLEAN bResult = FALSE; /* If same pointer, then must be equal */ if (pszStr1 == pszStr2) return TRUE; /* If either is NULL, cannot be substrings */ if (!pszStr1 || !pszStr2) return FALSE; dwLen1 = strlen(pszStr1); dwLen2 = strlen(pszStr2); pszCopy1 = _wbc_strdup(pszStr1); if (!pszCopy1) { goto cleanup; } pszCopy2 = _wbc_strdup(pszStr2); if (!pszCopy2) { goto cleanup; } if (dwLen1 > dwChars) { *(pszCopy1 + dwChars) = '\0'; } if (dwLen2 > dwChars) { *(pszCopy2 + dwChars) = '\0'; } bResult = StrEqual(pszCopy1, pszCopy2); cleanup: _WBC_FREE(pszCopy1); _WBC_FREE(pszCopy2); return bResult; }
wbcErr wbcDcInfo( const char *domain, size_t *num_dcs, const char ***dc_names, const char ***dc_ips ) { DWORD error; PLWNET_DC_INFO pDCInfo = NULL; error = LWNetGetDCName( NULL, domain, NULL, 0, &pDCInfo); BAIL_ON_LSA_ERR(error); *num_dcs = 1; *dc_names = _wbc_malloc_zero(sizeof(**dc_names) * 2, _wbc_free_string_array); BAIL_ON_NULL_PTR(*dc_names, error); (*dc_names)[0] = _wbc_strdup(pDCInfo->pszDomainControllerName); BAIL_ON_NULL_PTR((*dc_names)[0], error); *dc_ips = _wbc_malloc_zero(sizeof(**dc_ips) * 2, _wbc_free_string_array); BAIL_ON_NULL_PTR(*dc_ips, error); (*dc_ips)[0] = _wbc_strdup(pDCInfo->pszDomainControllerAddress); BAIL_ON_NULL_PTR((*dc_ips)[0], error); cleanup: if (error) { _WBC_FREE(*dc_ips); _WBC_FREE(*dc_names); } return map_error_to_wbc_status(error); }
static DWORD FillDomainInfo( OUT struct wbcDomainInfo *pWbcDomInfo, IN PLSA_TRUSTED_DOMAIN_INFO pLsaDomInfo ) { DWORD dwErr = LW_ERROR_INTERNAL; if (pLsaDomInfo->pszDnsDomain) { pWbcDomInfo->dns_name = _wbc_strdup(pLsaDomInfo->pszDnsDomain); BAIL_ON_NULL_PTR(pLsaDomInfo->pszDnsDomain, dwErr); } if (pLsaDomInfo->pszNetbiosDomain) { pWbcDomInfo->short_name = _wbc_strdup(pLsaDomInfo->pszNetbiosDomain); BAIL_ON_NULL_PTR(pLsaDomInfo->pszNetbiosDomain, dwErr); } if (pLsaDomInfo->pszDomainSID) { dwErr = wbcStringToSid(pLsaDomInfo->pszDomainSID, &pWbcDomInfo->sid); BAIL_ON_LSA_ERR(dwErr); } /* Domain flags */ pWbcDomInfo->domain_flags = WBC_DOMINFO_DOMAIN_AD; if (pLsaDomInfo->dwDomainFlags & LSA_DM_DOMAIN_FLAG_PRIMARY) { pWbcDomInfo->domain_flags |= WBC_DOMINFO_DOMAIN_PRIMARY; pWbcDomInfo->trust_flags |= WBC_DOMINFO_TRUST_INCOMING; pWbcDomInfo->trust_flags |= WBC_DOMINFO_TRUST_OUTGOING; pWbcDomInfo->trust_flags |= WBC_DOMINFO_TRUST_TRANSITIVE; } if ((pLsaDomInfo->dwDomainFlags & LSA_DM_DOMAIN_FLAG_OFFLINE) || (pLsaDomInfo->dwDomainFlags & LSA_DM_DOMAIN_FLAG_FORCE_OFFLINE)) { pWbcDomInfo->domain_flags |= WBC_DOMINFO_DOMAIN_OFFLINE; } /* Trust Flags */ if (pLsaDomInfo->dwTrustFlags & LSA_TRUST_FLAG_INBOUND) { pWbcDomInfo->trust_flags |= WBC_DOMINFO_TRUST_INCOMING; } if (pLsaDomInfo->dwTrustFlags & LSA_TRUST_FLAG_OUTBOUND) { pWbcDomInfo->trust_flags |= WBC_DOMINFO_TRUST_OUTGOING; } if ((pLsaDomInfo->dwTrustAttributes & (LSA_TRUST_ATTRIBUTE_WITHIN_FOREST| LSA_TRUST_ATTRIBUTE_FOREST_TRANSITIVE)) || (pLsaDomInfo->dwTrustFlags & LSA_TRUST_FLAG_IN_FOREST)) { pWbcDomInfo->trust_flags |= WBC_DOMINFO_TRUST_TRANSITIVE; } /* Trust Type */ if (pLsaDomInfo->dwTrustAttributes & LSA_TRUST_ATTRIBUTE_WITHIN_FOREST) { pWbcDomInfo->trust_type |= WBC_DOMINFO_TRUSTTYPE_IN_FOREST; } if (pLsaDomInfo->dwTrustAttributes & LSA_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) { pWbcDomInfo->trust_type |= WBC_DOMINFO_TRUSTTYPE_FOREST; } if (pLsaDomInfo->dwTrustAttributes & LSA_TRUST_ATTRIBUTE_NON_TRANSITIVE) { pWbcDomInfo->trust_type |= WBC_DOMINFO_TRUSTTYPE_EXTERNAL; } switch (pLsaDomInfo->dwTrustMode) { case LSA_TRUST_MODE_MY_FOREST: pWbcDomInfo->trust_type = WBC_DOMINFO_TRUSTTYPE_IN_FOREST; pWbcDomInfo->trust_flags |= (WBC_DOMINFO_TRUST_INCOMING| WBC_DOMINFO_TRUST_OUTGOING); break; case LSA_TRUST_MODE_OTHER_FOREST: pWbcDomInfo->trust_type = WBC_DOMINFO_TRUSTTYPE_FOREST; break; case LSA_TRUST_MODE_EXTERNAL: pWbcDomInfo->trust_type = WBC_DOMINFO_TRUSTTYPE_EXTERNAL; break; } cleanup: return dwErr; }