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; }
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; }
static int FreeWbcDomainInfo( IN OUT void* p ) { struct wbcDomainInfo *pDomain = (struct wbcDomainInfo*)p; if (!pDomain) { return 0; } _WBC_FREE(pDomain->short_name); _WBC_FREE(pDomain->dns_name); return 0; }
void wbcFreeMemory(void* p) { if (p) _WBC_FREE(p); return; }
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); }
wbcErr wbcLookupDomainController( const char *domain, uint32_t flags, struct wbcDomainControllerInfo **dc_info ) { DWORD error; PLWNET_DC_INFO pDCInfo = NULL; struct wbcDomainControllerInfo *pResult = NULL; error = LWNetGetDCName( NULL, domain, NULL, flags, &pDCInfo); BAIL_ON_LSA_ERR(error); pResult = _wbc_malloc_zero(sizeof(*pResult), FreeDomainController); BAIL_ON_NULL_PTR(pResult, error); error = LwAllocateString( pDCInfo->pszDomainControllerName, &pResult->dc_name); BAIL_ON_LSA_ERR(error); *dc_info = pResult; cleanup: if (error) { *dc_info = NULL; _WBC_FREE(pResult); } return map_error_to_wbc_status(error); }
wbcErr wbcDomainInfo( IN const char *domain, OUT struct wbcDomainInfo **info ) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; DWORD dwErr = LW_ERROR_INTERNAL; HANDLE hLsa = (HANDLE)NULL; PLSASTATUS pLsaStatus = NULL; struct wbcDomainInfo *pWbcDomInfo = NULL; PLSA_TRUSTED_DOMAIN_INFO pLsaDomInfo = NULL; PLSA_AUTH_PROVIDER_STATUS pADProvStatus = NULL; int i = 0; /* Sanity check */ BAIL_ON_NULL_PTR_PARAM(domain, dwErr); BAIL_ON_NULL_PTR_PARAM(info, dwErr); /* Work */ dwErr = LsaOpenServer(&hLsa); BAIL_ON_LSA_ERR(dwErr); dwErr = LsaGetStatus(hLsa, &pLsaStatus); BAIL_ON_LSA_ERR(dwErr); /* Find the AD provider entry */ for (i=0; i<pLsaStatus->dwCount; i++) { if (strcmp(pLsaStatus->pAuthProviderStatusList[i].pszId, LSA_PROVIDER_TAG_AD) == 0) { pADProvStatus = &pLsaStatus->pAuthProviderStatusList[i]; break; } } if (pADProvStatus == NULL) { dwErr = LW_ERROR_NO_SUCH_DOMAIN; BAIL_ON_LSA_ERR(dwErr); } /* Find the requested domain */ for (i=0; i<pADProvStatus->dwNumTrustedDomains; i++) { PLSA_TRUSTED_DOMAIN_INFO pCursorDomInfo = NULL; pCursorDomInfo = &pADProvStatus->pTrustedDomainInfoArray[i]; if (StrEqual(pCursorDomInfo->pszDnsDomain, domain) || StrEqual(pCursorDomInfo->pszNetbiosDomain, domain)) { pLsaDomInfo = pCursorDomInfo; break; } } if (pLsaDomInfo == NULL) { dwErr = LW_ERROR_NO_SUCH_DOMAIN; BAIL_ON_LSA_ERR(dwErr); } /* Fill in the domain info */ pWbcDomInfo = _wbc_malloc_zero( sizeof(struct wbcDomainInfo), FreeWbcDomainInfo); BAIL_ON_NULL_PTR(pWbcDomInfo, dwErr); dwErr = FillDomainInfo(pWbcDomInfo, pLsaDomInfo); BAIL_ON_LSA_ERR(dwErr); *info = pWbcDomInfo; pWbcDomInfo = NULL; cleanup: if (pLsaStatus) { LsaFreeStatus(pLsaStatus); } if (hLsa != (HANDLE)NULL) { LsaCloseServer(hLsa); } _WBC_FREE(pWbcDomInfo); wbc_status = map_error_to_wbc_status(dwErr); return wbc_status; }
wbcErr wbcLookupDomainControllerEx( const char *domain, struct wbcGuid *guid, const char *site, uint32_t flags, struct wbcDomainControllerInfoEx **dc_info ) { DWORD error; PLWNET_DC_INFO pDCInfo = NULL; struct wbcDomainControllerInfoEx *pResult = NULL; if (guid != NULL) { return WBC_ERR_NOT_IMPLEMENTED; } error = LWNetGetDCName( NULL, domain, site, flags, &pDCInfo); BAIL_ON_LSA_ERR(error); pResult = _wbc_malloc_zero(sizeof(*pResult), FreeDomainControllerEx); BAIL_ON_NULL_PTR(pResult, error); error = LwAllocateStringPrintf( (char **)&pResult->dc_unc, "\\\\%s", pDCInfo->pszDomainControllerAddress); BAIL_ON_LSA_ERR(error); error = LwAllocateString( pDCInfo->pszDomainControllerAddress, (char **)&pResult->dc_address); BAIL_ON_LSA_ERR(error); pResult->dc_address_type = pDCInfo->dwDomainControllerAddressType; error = LwAllocateMemory( sizeof(*pResult->domain_guid), (PVOID*)&pResult->domain_guid); BAIL_ON_LSA_ERR(error); wbcUuidToWbcGuid( pDCInfo->pucDomainGUID, pResult->domain_guid); error = LwAllocateString( pDCInfo->pszFullyQualifiedDomainName, (char **)&pResult->domain_name); BAIL_ON_LSA_ERR(error); error = LwAllocateString( pDCInfo->pszDnsForestName, (char **)&pResult->forest_name); BAIL_ON_LSA_ERR(error); pResult->dc_flags = pDCInfo->dwFlags; error = LwAllocateString( pDCInfo->pszDCSiteName, (char **)&pResult->dc_site_name); BAIL_ON_LSA_ERR(error); error = LwAllocateString( pDCInfo->pszClientSiteName, (char **)&pResult->client_site_name); BAIL_ON_LSA_ERR(error); *dc_info = pResult; cleanup: if (error) { *dc_info = NULL; _WBC_FREE(pResult); } return map_error_to_wbc_status(error); }
wbcErr wbcListTrusts( OUT struct wbcDomainInfo **domains, OUT size_t *num_domains ) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; DWORD dwErr = LW_ERROR_INTERNAL; HANDLE hLsa = (HANDLE)NULL; PLSASTATUS pLsaStatus = NULL; struct wbcDomainInfo *pWbcDomInfoArray = NULL; PLSA_AUTH_PROVIDER_STATUS pADProvStatus = NULL; size_t NumDomains = 0; int i = 0; /* Sanity check */ BAIL_ON_NULL_PTR_PARAM(domains, dwErr); BAIL_ON_NULL_PTR_PARAM(num_domains, dwErr); /* Work */ dwErr = LsaOpenServer(&hLsa); BAIL_ON_LSA_ERR(dwErr); dwErr = LsaGetStatus(hLsa, &pLsaStatus); BAIL_ON_LSA_ERR(dwErr); /* Find the AD provider entry */ for (i=0; i<pLsaStatus->dwCount; i++) { if (strcmp(pLsaStatus->pAuthProviderStatusList[i].pszId, LSA_PROVIDER_TAG_AD) == 0) { pADProvStatus = &pLsaStatus->pAuthProviderStatusList[i]; break; } } if (pADProvStatus == NULL) { dwErr = LW_ERROR_NO_SUCH_DOMAIN; BAIL_ON_LSA_ERR(dwErr); } /* Fill in the domain info */ NumDomains = pADProvStatus->dwNumTrustedDomains; pWbcDomInfoArray = _wbc_malloc_zero( sizeof(struct wbcDomainInfo)*(NumDomains+1), FreeWbcDomainInfoArray); BAIL_ON_NULL_PTR(pWbcDomInfoArray, dwErr); for (i=0; i<NumDomains; i++) { dwErr = FillDomainInfo( &pWbcDomInfoArray[i], &pADProvStatus->pTrustedDomainInfoArray[i]); BAIL_ON_LSA_ERR(dwErr); } *domains = pWbcDomInfoArray; pWbcDomInfoArray = NULL; *num_domains = NumDomains; cleanup: if (hLsa != (HANDLE)NULL) { LsaCloseServer(hLsa); } _WBC_FREE(pWbcDomInfoArray); wbc_status = map_error_to_wbc_status(dwErr); return wbc_status; }