Exemplo n.º 1
0
NTSTATUS
NtRegReadConfigEnum(
    PLWREG_CONFIG_REG pReg,
    PCSTR   pszName,
    BOOLEAN bUsePolicy,
    DWORD   dwMin,
    DWORD   dwMax,
    const PCSTR   *ppszEnumNames,
    PDWORD  pdwValue
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    PSTR pszValue = NULL;
    DWORD dwEnumIndex = 0;

    ntStatus = NtRegReadConfigString(
                pReg,
                pszName,
                bUsePolicy,
                &pszValue,
                NULL);
    BAIL_ON_NT_STATUS(ntStatus);

    if (pszValue != NULL )
    {
        for (dwEnumIndex = 0;
             dwEnumIndex <= dwMax - dwMin;
             dwEnumIndex++)
        {
            if(LwRtlCStringCompare(
                   pszValue,
                   ppszEnumNames[dwEnumIndex], FALSE) == 0)
            {
                *pdwValue = dwEnumIndex + dwMin;
                break;
            }
        }
    }

cleanup:
    LwRtlCStringFree(&pszValue);

    return ntStatus;

error:
    goto cleanup;
}
Exemplo n.º 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;
}
Exemplo n.º 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;
}