VOID
LsaPstorepBackendCleanup(
    IN PLSA_PSTORE_BACKEND_STATE State
    )
{
    if (State)
    {
        if (State->OldStoreHandle)
        {
            LwpsLegacyCloseProvider(State->OldStoreHandle);
            State->OldStoreHandle = NULL;
        }
        LSA_PSTORE_FREE(&State);
    }
}
DWORD
LwpsLegacyOpenProvider(
    OUT PLWPS_LEGACY_STATE* ppContext
    )
{
    DWORD dwError = 0;
    int EE = 0;
    PLWPS_LEGACY_STATE pContext = NULL;

    dwError = LwAllocateMemory(sizeof(*pContext), OUT_PPVOID(&pContext));
    GOTO_CLEANUP_ON_WINERROR_EE(dwError, EE);

    dwError = RegOpenServer(&pContext->hReg);
    GOTO_CLEANUP_ON_WINERROR_EE(dwError, EE);

    dwError = LwpsLegacyCreateSecurityDescriptor(
                    FALSE,
                    &pContext->pPasswordSecurityDescriptor);
    GOTO_CLEANUP_ON_WINERROR_EE(dwError, EE);

    dwError = LwpsLegacyCreateSecurityDescriptor(
                    TRUE,
                    &pContext->pAccountSecurityDescriptor);
    GOTO_CLEANUP_ON_WINERROR_EE(dwError, EE);

cleanup:
    if (dwError)
    {
        if (pContext)
        {
            LwpsLegacyCloseProvider(pContext);
            pContext = NULL;
        }
    }

    *ppContext = pContext;

    LSA_PSTORE_LOG_LEAVE_ERROR_EE(dwError, EE);
    return dwError;
}