コード例 #1
0
ファイル: config_api.c プロジェクト: twistround/pbis
NTSTATUS
NtRegReadConfigBoolean(
    PLWREG_CONFIG_REG pReg,
    PCSTR pszName,
    BOOLEAN bUsePolicy,
    PBOOLEAN pbValue
    )
{

    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD dwValue = *pbValue == TRUE ? 0x00000001 : 0x00000000;

    ntStatus = NtRegReadConfigDword(
                pReg,
                pszName,
                bUsePolicy,
                0,
                -1,
                &dwValue);
    BAIL_ON_NT_STATUS(ntStatus);

    *pbValue = dwValue ? TRUE : FALSE;

cleanup:

    return ntStatus;

error:
    goto cleanup;
}
コード例 #2
0
NTSTATUS
NtRegProcessConfigUsingAttributeRanges(
    PCSTR pszConfigKey,
    PCSTR pszPolicyKey,
    PLWREG_CONFIG_ITEM pConfig,
    DWORD dwConfigEntries
    )
{
    PLWREG_CURRENT_VALUEINFO* DONT_RETRIEVE_CURRENT_VALUE = NULL;

    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD dwEntry = 0;
    PLWREG_CONFIG_REG pReg = NULL;

    PWSTR pwszConfigKey = NULL;
    PWSTR pwszValueName = NULL;
    PLWREG_VALUE_ATTRIBUTES pValueAttributes = NULL;

    ntStatus = NtRegOpenConfig(pszConfigKey, pszPolicyKey, &pReg);
    BAIL_ON_NT_STATUS(ntStatus);

    if (pReg == NULL)
    {
        goto error;
    }

    ntStatus = LwRtlWC16StringAllocateFromCString(&pwszConfigKey, pReg->pszConfigKey);
    BAIL_ON_NT_STATUS(ntStatus);

    for (dwEntry = 0; dwEntry < dwConfigEntries; dwEntry++)
    {
        ntStatus = STATUS_SUCCESS;
    
        pValueAttributes = NULL;
        if (pwszValueName) 
        {
            free(pwszValueName);
            pwszValueName = NULL;
        }
        
        switch (pConfig[dwEntry].Type)
        {
            case LwRegTypeString:
                ntStatus = NtRegReadConfigString(
                            pReg,
                            pConfig[dwEntry].pszName,
                            pConfig[dwEntry].bUsePolicy,
                            pConfig[dwEntry].pValue,
                            pConfig[dwEntry].pdwSize);
                break;

            case LwRegTypeMultiString:
                ntStatus = NtRegReadConfigMultiString(
                            pReg,
                            pConfig[dwEntry].pszName,
                            pConfig[dwEntry].bUsePolicy,
                            pConfig[dwEntry].pValue,
                            pConfig[dwEntry].pdwSize);
                break;

            case LwRegTypeDword:
                ntStatus = LwRtlWC16StringAllocateFromCString(&pwszValueName, pConfig[dwEntry].pszName);
                if (ntStatus) 
                {
                    break;
                }

                ntStatus = NtRegGetValueAttributesW(
                        pReg->hConnection,
                        pReg->hKey,
                        pwszConfigKey,
                        pwszValueName,
                        DONT_RETRIEVE_CURRENT_VALUE,
                        &pValueAttributes
                        );

                if (ntStatus == STATUS_OBJECT_NAME_NOT_FOUND)
                {
                    ntStatus = STATUS_SUCCESS;
                } 

                if (ntStatus) 
                {
                    break;
                }

                ntStatus = NtRegReadConfigDword(
                            pReg,
                            pConfig[dwEntry].pszName,
                            pConfig[dwEntry].bUsePolicy,
                            ((pValueAttributes && pValueAttributes->RangeType == LWREG_VALUE_RANGE_TYPE_INTEGER) 
                                ? pValueAttributes->Range.RangeInteger.Min
                                : pConfig[dwEntry].dwMin),
                            ((pValueAttributes && pValueAttributes->RangeType == LWREG_VALUE_RANGE_TYPE_INTEGER) 
                                ? pValueAttributes->Range.RangeInteger.Max
                                : pConfig[dwEntry].dwMax),
                            pConfig[dwEntry].pValue);
                break;

            case LwRegTypeBoolean:
                ntStatus = NtRegReadConfigBoolean(
                            pReg,
                            pConfig[dwEntry].pszName,
                            pConfig[dwEntry].bUsePolicy,
                            pConfig[dwEntry].pValue);
                break;

            case LwRegTypeEnum:
                ntStatus = NtRegReadConfigEnum(
                            pReg,
                            pConfig[dwEntry].pszName,
                            pConfig[dwEntry].bUsePolicy,
                            pConfig[dwEntry].dwMin,
                            pConfig[dwEntry].dwMax,
                            pConfig[dwEntry].ppszEnumNames,
                            pConfig[dwEntry].pValue);
                break;

            default:
                break;
        }

        if (ntStatus == STATUS_OBJECT_NAME_NOT_FOUND)
        {
            ntStatus = STATUS_SUCCESS;
        }
        BAIL_ON_NT_STATUS(ntStatus);
    }

cleanup:
    if (pwszValueName) 
    {
        free(pwszValueName);
        pwszValueName = NULL;
    }

    if (pwszConfigKey) 
    {
        free(pwszConfigKey);
        pwszConfigKey = NULL;
    }

    NtRegCloseConfig(pReg);
    pReg = NULL;

    return ntStatus;

error:
    goto cleanup;
}
コード例 #3
0
NTSTATUS
NtRegProcessConfig(
    PCSTR pszConfigKey,
    PCSTR pszPolicyKey,
    PLWREG_CONFIG_ITEM pConfig,
    DWORD dwConfigEntries
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    DWORD dwEntry = 0;
    PLWREG_CONFIG_REG pReg = NULL;

    ntStatus = NtRegOpenConfig(pszConfigKey, pszPolicyKey, &pReg);
    BAIL_ON_NT_STATUS(ntStatus);

    if (pReg == NULL)
    {
        goto error;
    }

    for (dwEntry = 0; dwEntry < dwConfigEntries; dwEntry++)
    {
        ntStatus = STATUS_SUCCESS;
        switch (pConfig[dwEntry].Type)
        {
            case LwRegTypeString:
                ntStatus = NtRegReadConfigString(
                            pReg,
                            pConfig[dwEntry].pszName,
                            pConfig[dwEntry].bUsePolicy,
                            pConfig[dwEntry].pValue,
                            pConfig[dwEntry].pdwSize);
                break;

            case LwRegTypeMultiString:
                ntStatus = NtRegReadConfigMultiString(
                            pReg,
                            pConfig[dwEntry].pszName,
                            pConfig[dwEntry].bUsePolicy,
                            pConfig[dwEntry].pValue,
                            pConfig[dwEntry].pdwSize);
                break;

            case LwRegTypeDword:
                ntStatus = NtRegReadConfigDword(
                            pReg,
                            pConfig[dwEntry].pszName,
                            pConfig[dwEntry].bUsePolicy,
                            pConfig[dwEntry].dwMin,
                            pConfig[dwEntry].dwMax,
                            pConfig[dwEntry].pValue);
                break;

            case LwRegTypeBoolean:
                ntStatus = NtRegReadConfigBoolean(
                            pReg,
                            pConfig[dwEntry].pszName,
                            pConfig[dwEntry].bUsePolicy,
                            pConfig[dwEntry].pValue);
                break;

            case LwRegTypeEnum:
                ntStatus = NtRegReadConfigEnum(
                            pReg,
                            pConfig[dwEntry].pszName,
                            pConfig[dwEntry].bUsePolicy,
                            pConfig[dwEntry].dwMin,
                            pConfig[dwEntry].dwMax,
                            pConfig[dwEntry].ppszEnumNames,
                            pConfig[dwEntry].pValue);
                break;

            default:
                break;
        }
        if (ntStatus == STATUS_OBJECT_NAME_NOT_FOUND)
        {
            ntStatus = STATUS_SUCCESS;
        }
        BAIL_ON_NT_STATUS(ntStatus);
    }

cleanup:
    NtRegCloseConfig(pReg);
    pReg = NULL;

    return ntStatus;

error:
    goto cleanup;
}