Esempio n. 1
0
wbcErr
wbcPingDc(
    const char *domain,
    struct wbcAuthErrorInfo **ppError
    )
{
    DWORD error;
    LWNET_UNIX_TIME_T dCTime = 0;

    error = LWNetGetDCTime(
            domain,
            &dCTime);
    BAIL_ON_LSA_ERR(error);

cleanup:
    wbcFillErrorInfo(map_error_to_wbc_status(error), ppError);
    return map_error_to_wbc_status(error);
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
wbcErr wbcLibraryDetails(struct wbcLibraryDetails **details)
{
    DWORD dwErr = LW_ERROR_INTERNAL;
    wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;

    BAIL_ON_NULL_PTR_PARAM(details, dwErr);

    *details = _wbc_malloc(sizeof(struct wbcLibraryDetails), NULL);
    BAIL_ON_NULL_PTR(*details, dwErr);

    (*details)->major_version   = LSA_WBC_LIBRARY_MAJOR_VERSION;
    (*details)->minor_version   = LSA_WBC_LIBRARY_MINOR_VERSION;
    (*details)->vendor_version  = LSA_WBC_LIBRARY_VENDOR_STRING;

cleanup:
    wbc_status = map_error_to_wbc_status(dwErr);

    return wbc_status;
}
Esempio n. 4
0
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);
}
Esempio n. 5
0
wbcErr wbcPing(void)
{
    HANDLE hLsa = (HANDLE)NULL;
    DWORD dwErr = LW_ERROR_INTERNAL;
    wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;

    /* Just open and close an LsaServerHandle */

    dwErr = LsaOpenServer(&hLsa);
    BAIL_ON_LSA_ERR(dwErr);

    dwErr = LsaCloseServer(hLsa);
    hLsa = (HANDLE)NULL;
    BAIL_ON_LSA_ERR(dwErr);

cleanup:
    wbc_status = map_error_to_wbc_status(dwErr);

    return wbc_status;
}
Esempio n. 6
0
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);
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
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);
}
Esempio n. 9
0
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;
}