Ejemplo n.º 1
0
/*
 * CheckLsaOpenSession
 *
 */
static
DWORD
CheckLsaOpenSession(
    HANDLE hLsaConnection,
    PCSTR pszLoginId,
    PLWTUSER pUser
)
{
    PCSTR pszTestDescription =
        "Home directory exists after call to LsaOpenSession for valid user.";
    PCSTR pszTestAPIs =
        "LsaOpenSession,"
        "LsaCloseSession,"
        "LsaCheckUserInList,"
        "LsaAuthenticateUser";
    char szTestMsg[128] = { 0 };

    DWORD dwError = LW_ERROR_SUCCESS;

    int bSessionIsOpen = 0;

    snprintf(szTestMsg, sizeof(szTestMsg), "Session for %s", pszLoginId);

    dwError = LsaOpenSession(hLsaConnection, pszLoginId);
    if ( dwError )
        goto error;
    bSessionIsOpen = 1;

    if ( !IsNullOrEmpty(pUser->pszUnixHomeDirectory) )
    {
        struct stat statbuf;
        if ( stat(pUser->pszUnixHomeDirectory, &statbuf) < 0 )
        {
            char buf[64];
            snprintf(
                buf,
                sizeof(buf),
                ",could not stat %s",
                pUser->pszUnixHomeDirectory);
            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
            goto error;
        }

        if ( !S_ISDIR(statbuf.st_mode) )
        {
            Lwt_strcat(
                szTestMsg,
                sizeof(szTestMsg),
                ",home is not a directory.");
            dwError = LW_ERROR_TEST_FAILED;
        }

        if ( !IsNullOrEmpty(pUser->pszUnixUid) )
        {
            if ( statbuf.st_uid != pUser->nUnixUid )
            {
                Lwt_strcat(
                    szTestMsg,
                    sizeof(szTestMsg),
                    ",uid doesn't match expected");
                dwError = LW_ERROR_TEST_FAILED;
            }
        }
    }


cleanup:

    if ( bSessionIsOpen )
    {
        dwError = LsaCloseSession(hLsaConnection, pszLoginId);
        bSessionIsOpen = 0;
    }

    LWT_LOG_TEST(szTestMsg);
    return dwError;

error:

    goto cleanup;

}
Ejemplo n.º 2
0
/*
 * MatchUserInfo0
 *
 * Check LSA_USER_INFO_0 matches information in CSV.
 */
static
DWORD
MatchUserInfo0(
    PLWTUSER pUser,
    PCSTR pszLookedUpBy,
    PLSA_USER_INFO_0 pUserInfo
    )
{
    PCSTR pszTestDescription =
        "LsaFindUserByName retrieved LSA_USER_INFO_0 that matches expected values.";
    PCSTR pszTestAPIs = 
        "LsaFindUserByName";
    char szTestMsg[128] = { 0 };
    DWORD dwError = LW_ERROR_SUCCESS;

    snprintf( szTestMsg, 
              sizeof(szTestMsg), 
              "\n\tAccount %s.\n", 
              pszLookedUpBy);

    if ( pUser->pszAlias )
    {
        if ( !pUserInfo->pszName || 
             strcasecmp(pUser->pszAlias, pUserInfo->pszName) )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tAlias: test[%s] != lsassd[%s]\n",
                      pUser->pszAlias,
                      pUserInfo->pszName);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }
    else if ( pUser->pszNTName )
    {
        if ( !pUserInfo->pszName || 
             strcasecmp(pUser->pszNTName, pUserInfo->pszName) )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tNT Name: test[%s] != lsassd[%s]\n",
                      pUser->pszNTName,
                      pUserInfo->pszName);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }

    if ( !IsNullOrEmpty(pUser->pszSid) )
    {
        if ( ! pUserInfo->pszSid || 
             strcmp(pUser->pszSid, pUserInfo->pszSid) )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tsid: test[%s] != lsassd[%s]\n",
                      pUser->pszSid,
                      pUserInfo->pszSid);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }


    if ( pUser->pszUnixUid )
    {
        if ( pUser->nUnixUid != pUserInfo->uid )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tuid: test[%lu (%s)] != lsassd[%lu]\n",
                      (unsigned long) pUser->nUnixUid,
                      pUser->pszUnixUid,
                      (unsigned long) pUserInfo->uid);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }

    if ( pUser->pszUnixGid )
    {
        if ( pUser->nUnixGid != pUserInfo->gid )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tgid: test[%lu (%s)] != lsassd[%lu]\n",
                      (unsigned long)pUser->nUnixGid,
                      pUser->pszUnixGid,
                      (unsigned long)pUserInfo->gid);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }

    if ( !IsNullOrEmpty(pUser->pszUnixGecos) )
    {
        if ( ! pUserInfo->pszGecos ||
             strcmp(pUser->pszUnixGecos, pUserInfo->pszGecos) )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tgecos: test[%s] != lsassd[%s]\n",
                      pUser->pszUnixGecos,
                      pUserInfo->pszGecos ? pUserInfo->pszGecos : "<null>");

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }

    if ( !IsNullOrEmpty(pUser->pszUnixLoginShell) )
    {
        if ( ! pUserInfo->pszShell || 
             strcmp(pUser->pszUnixLoginShell, pUserInfo->pszShell) )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\tshell: test[%s] != lsassd[%s]\n",
                      pUser->pszUnixLoginShell,
                      pUserInfo->pszShell);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }

    if ( !IsNullOrEmpty(pUser->pszUnixHomeDirectory) )
    {
        if ( ! pUserInfo->pszHomedir || 
             strcmp(pUser->pszUnixHomeDirectory, pUserInfo->pszHomedir) )
        {
            char buf[128];

            snprintf( buf,
                      sizeof(buf),
                      "\thome directory: test[%s] != lsassd[%s]\n",
                      pUser->pszUnixHomeDirectory,
                      pUserInfo->pszHomedir);

            Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
            dwError = LW_ERROR_TEST_FAILED;
        }
    }

    LWT_LOG_TEST(szTestMsg);
    return dwError;
}
Ejemplo n.º 3
0
/*
 * CheckLsaEnumUsers
 * 
 * Check LSA_USER_INFO_* list from LsaEnumUsers has expected user.
 * 
 */
DWORD
CheckLsaEnumUsers(
    HANDLE hLsaConnection,
    PCSTR pszUser,
    DWORD dwUserInfoLevel,
    DWORD dwMaxNumUsers
    )
{
    DWORD dwError = LW_ERROR_SUCCESS;
    DWORD dwLocalError = LW_ERROR_SUCCESS;
    DWORD dwNumUsers = 0;
    HANDLE hResume = NULL;
    PVOID  *ppUserInfoList = NULL;
    /* Set to true if we ever return more users than we should.
     * Used to avoid repeating messages uselessly.
     */
    BOOL bViolated_dwMaxNumUsers = 0;

    char szTestMsg[128] = { 0 };
    PCSTR pszTestDescription = 
        "LsaEnumUsers retrieved LSA_USER_INFO_* list containing expected user.";
    PCSTR pszTestAPIs = 
        "LsaBeginEnumUsers,"
        "LsaEnumUsers,"
        "LsaFreeUserInfoList,"
        "LsaEndEnumUsers";

    snprintf(
        szTestMsg,
        sizeof(szTestMsg),
        "Looking for %s, lists of max length %lu, dwUserInfoLevel = %lu.",
        pszUser,
        (unsigned long)dwMaxNumUsers,
        (unsigned long)dwUserInfoLevel);


    /* Only one flag right now: LSA_FIND_FLAGS_NSS */
    dwLocalError = LsaBeginEnumUsers(
                        hLsaConnection,
                        dwUserInfoLevel,
                        dwMaxNumUsers,
                        0, /* Flags */
                        &hResume);
    BAIL_ON_TEST_BROKE(dwLocalError);

    do
    {
        dwNumUsers = 0;
        dwLocalError = LsaEnumUsers(
                        hLsaConnection,
                        hResume,
                        &dwNumUsers,
                        (PVOID**) &ppUserInfoList);
        BAIL_ON_TEST_BROKE(dwLocalError);

        /* Avoid testing/reporting problem more than once. */
        if ( ! bViolated_dwMaxNumUsers )
        {
            if ( dwNumUsers > dwMaxNumUsers )
            {
                char buf[64];

                bViolated_dwMaxNumUsers = 1;

                snprintf(
                    buf,
                    sizeof(buf),
                    "Violation: returned %lu users.",
                    (unsigned long)dwNumUsers);

                Lwt_strcat(
                    szTestMsg,
                    sizeof(szTestMsg),
                    buf);

                dwError = LW_ERROR_TEST_FAILED;
            }
        }

        if (  CheckForUserInUserInfoList(
                    dwUserInfoLevel,
                    ppUserInfoList, 
                    dwNumUsers,
                    pszUser) == LW_ERROR_SUCCESS )
        {
             /* Found user, good, time to leave. */
            goto cleanup;
        }

        LsaFreeUserInfoList(dwUserInfoLevel, ppUserInfoList, dwNumUsers);
        ppUserInfoList = NULL;

    } while ( dwNumUsers > 0 );

    /* If we are here, a user was missing. */
    dwError = LW_ERROR_TEST_FAILED;

cleanup:
    if ( ppUserInfoList )
    { 
        LsaFreeUserInfoList(dwUserInfoLevel, ppUserInfoList, dwNumUsers);
        ppUserInfoList = NULL;
        dwNumUsers = 0;
    }

    if ( hResume != (HANDLE)NULL) 
    {
        LsaEndEnumUsers(hLsaConnection, hResume);
        hResume = NULL;
    }
    LWT_LOG_TEST(szTestMsg);
    return dwError;

error:
    goto cleanup;
}
Ejemplo n.º 4
0
/*
 * FindUserByName1
 * 
 * Check that LsaFindUserByName gets LSA_USER_INFO_1 for given user.
 */
static
DWORD
FindUserByName1(
    HANDLE hLsaConnection,
    PLWTUSER pUser,
    PCSTR pszLookedUpBy,
    PLSA_USER_INFO_1 *ppUserInfo1
    )
{
    PCSTR pszTestDescription =
        "LsaFindUserByName retrieved LSA_USER_INFO_1 for given user.";
    PCSTR pszTestAPIs = 
        "LsaFindUserByName";
    char szTestMsg[128] = { 0 };
    DWORD dwError = LW_ERROR_SUCCESS;
    DWORD dwLocalError = LW_ERROR_SUCCESS;
    PLSA_USER_INFO_1 pUserInfo1 = NULL;

    snprintf( szTestMsg, 
              sizeof(szTestMsg), 
              "\n\tAccount %s.\n", 
              pszLookedUpBy);

    dwLocalError = LsaFindUserByName( hLsaConnection,
                                      pszLookedUpBy,
                                      1, 
                                      (PVOID*)&pUserInfo1);
    if ( dwLocalError )
    {
        char buf[128];
        char szErrorMsg[128];

        LwGetErrorString( dwLocalError, 
                          szErrorMsg, 
                          sizeof(szErrorMsg));

        snprintf( buf,
                  sizeof(buf),
                  "\tLsaFindUserByName reports %lu (%s)\n",
                  (unsigned long)dwLocalError,
                  szErrorMsg);

        Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
        dwError = LW_ERROR_TEST_FAILED;
        goto error;
    }

cleanup:

    *ppUserInfo1 = pUserInfo1;

    LWT_LOG_TEST(szTestMsg);
    return dwError;

error:

    if ( pUserInfo1 )
    {
        LsaFreeUserInfo(1, pUserInfo1);
        pUserInfo1 = NULL;
    }

    goto cleanup;
}