Esempio n. 1
0
NTSTATUS
SvcmRefresh(
    PLW_SVCM_INSTANCE pInstance
)
{
    DWORD dwError = 0;

    UMN_LOG_VERBOSE("Refreshing configuration");
    dwError = UmnSrvRefreshConfiguration();

    if (dwError) {
        UMN_LOG_WARNING("Failed refreshing configuration: error %d", dwError);
    } else {
        UMN_LOG_INFO("Succeeded refreshing configuration");
    }

    return dwError;
}
Esempio n. 2
0
DWORD
UmnSrvFindDeletedUsers(
    PLW_EVENTLOG_CONNECTION pEventlog,
    HANDLE hReg,
    PCSTR pUserKeyName,
    HKEY hUsers,
    long long Now
    )
{
    DWORD dwError = 0;
    DWORD subKeyCount = 0;
    DWORD maxSubKeyLen = 0;
    DWORD subKeyLen = 0;
    DWORD i = 0;
    PSTR pKeyName = NULL;
    DWORD lastUpdated = 0;
    DWORD lastUpdatedLen = 0;
    USER_MONITOR_PASSWD old = { 0 };

    dwError = RegQueryInfoKeyA(
                    hReg,
                    hUsers,
                    NULL,
                    NULL,
                    NULL,
                    &subKeyCount,
                    &maxSubKeyLen,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    NULL);
    BAIL_ON_UMN_ERROR(dwError);

    dwError = LwAllocateMemory(
                    maxSubKeyLen + 1,
                    (PVOID *)&pKeyName);

    for (i = 0; i < subKeyCount; i++)
    {
        if (gbPollerThreadShouldExit)
        {
            dwError = ERROR_CANCELLED;
            BAIL_ON_UMN_ERROR(dwError);
        }
        subKeyLen = maxSubKeyLen;

        dwError = RegEnumKeyExA(
                        hReg,
                        hUsers,
                        i,
                        pKeyName,
                        &subKeyLen,
                        NULL,
                        NULL,
                        NULL,
                        NULL);
        BAIL_ON_UMN_ERROR(dwError);

        pKeyName[subKeyLen] = 0;

        lastUpdatedLen = sizeof(lastUpdated);
        dwError = RegGetValueA(
                        hReg,
                        hUsers,
                        pKeyName,
                        "LastUpdated",
                        0,
                        NULL,
                        (PBYTE)&lastUpdated,
                        &lastUpdatedLen);
        if (dwError == LWREG_ERROR_NO_SUCH_KEY_OR_VALUE)
        {
            UMN_LOG_WARNING("User %s not completely written. The user monitor service may have previously terminated ungracefully.",
                        LW_SAFE_LOG_STRING(pKeyName));
            lastUpdated = 0;
            dwError = 0;
        }
        else
        {
            BAIL_ON_UMN_ERROR(dwError);
        }

        if (lastUpdated < Now)
        {
            UmnSrvFreeUserContents(&old);
            dwError = UmnSrvReadUser(
                            pUserKeyName,
                            pKeyName,
                            &old);
            BAIL_ON_UMN_ERROR(dwError);

            UMN_LOG_INFO("User '%s' deleted",
                            old.pw_name);

            dwError = RegDeleteKeyA(
                            hReg,
                            hUsers,
                            pKeyName);
            BAIL_ON_UMN_ERROR(dwError);

            if (!strcmp(pUserKeyName, "Users"))
            {
                dwError = UmnSrvWriteUserEvent(
                                pEventlog,
                                old.LastUpdated,
                                &old,
                                Now,
                                NULL);
                BAIL_ON_UMN_ERROR(dwError);
            }
            else
            {
                dwError = UmnSrvWriteADUserEvent(
                                pEventlog,
                                old.LastUpdated,
                                &old,
                                Now,
                                NULL);
                BAIL_ON_UMN_ERROR(dwError);
            }

            // Make sure we don't skip the next key since this one was deleted
            i--;
            subKeyCount--;
        }
    }

cleanup:
    UmnSrvFreeUserContents(&old);

    LW_SAFE_FREE_STRING(pKeyName);
    return dwError;

error:
    goto cleanup;
}