Exemplo n.º 1
0
static
DWORD
TestAddUser(
    HANDLE hLsaConnection,
    PSTR pszUser
    )
{
    DWORD dwError = LW_ERROR_SUCCESS;
    DWORD dwUserInfoLevel = 0;
    PVOID pUserInfo = NULL;
    PSTR pszShell = "/bin/sh";
    PSTR pszHomedir = "/home";
    gid_t gid = 0;
    LSA_FIND_FLAGS FindFlags = 0;

    PCSTR pszTestDescription = 
        "Verify LsaAddUser adds a user";
    PCSTR pszTestAPIs = 
        "LsaAddUser";
    
    char szTestMsg[512] = { 0 };
    
    dwError = GetGroupId( hLsaConnection, pszUser, &gid);
    BAIL_ON_TEST_BROKE(dwError);

    dwError = BuildUserInfo(0, gid, pszUser, pszShell, pszHomedir, (PLSA_USER_INFO_0*)&pUserInfo);
    BAIL_ON_TEST_BROKE(dwError);

    dwError = LsaAddUser(
                 hLsaConnection,
                 pUserInfo,
                 dwUserInfoLevel);
    BAIL_ON_TEST_BROKE(dwError);

    dwError = LsaFindUserByName(
                    hLsaConnection,
                    pszUser,
                    FindFlags,
                    &pUserInfo);
    BAIL_ON_TEST_BROKE(dwError);
    
    if( !pUserInfo )
    {
        dwError = LW_ERROR_TEST_FAILED;
        snprintf(szTestMsg, sizeof(szTestMsg), 
            "unexpected result while adding the user %s",
            pszUser);
        LWT_LOG_TEST(szTestMsg);
    }

cleanup:
    if (pUserInfo) {
        LsaFreeUserInfo(dwUserInfoLevel, pUserInfo);
    }
    return dwError;
error:
    goto cleanup;
}
Exemplo n.º 2
0
static
DWORD
TestAddGroup(
    HANDLE hLsaConnection,
    PSTR pszGroup
    )
{
    DWORD dwError = LW_ERROR_SUCCESS;
    DWORD dwGroupInfoLevel = 1;
    PVOID pGroupInfo = NULL;
    LSA_FIND_FLAGS FindFlags = 0;

    PCSTR pszTestDescription = 
        "Verify LsaAddGroup adds a group";
    PCSTR pszTestAPIs = 
        "LsaAddGroup";
    
    char szTestMsg[512] = { 0 };

    dwError = BuildGroupInfo(0, pszGroup, (PLSA_GROUP_INFO_1*)&pGroupInfo);
    BAIL_ON_TEST_BROKE(dwError);

    dwError = LsaAddGroup(hLsaConnection, pGroupInfo, dwGroupInfoLevel);
    BAIL_ON_TEST_BROKE(dwError);

    dwError = LsaFindGroupByName(
                    hLsaConnection,
                    pszGroup,
                    FindFlags,
                    dwGroupInfoLevel,
                    &pGroupInfo);
    BAIL_ON_TEST_BROKE(dwError);
    
    if( !pGroupInfo )
    {
        dwError = LW_ERROR_TEST_FAILED;
        snprintf(szTestMsg, sizeof(szTestMsg), 
            "unexpected result while adding the group %s",
            pszGroup);
        LWT_LOG_TEST(szTestMsg);
    }
cleanup:
    
    if (pGroupInfo) {
        LsaFreeGroupInfo(dwGroupInfoLevel, pGroupInfo);
    }

    return dwError;
error:
    goto cleanup;
}
Exemplo n.º 3
0
/*
 * VerifyErrorConditions
 * 
 * Check for proper operation with deliberate errors.
 */
static
DWORD
VerifyErrorConditions(
    HANDLE hLsaConnection
    )
{
    PCSTR pszTestDescription = 
        "LsaEnumUsers returns error given invalid parameters.";
    PCSTR pszTestAPIs = 
        "LsaBeginEnumUsers,"
        "LsaEnumUsers,"
        "LsaFreeUserInfoList,"
        "LsaEndEnumUsers";
    char szTestMsg[128] = { 0 };


    HANDLE hResume = NULL;

    DWORD dwError = LW_ERROR_SUCCESS;
    DWORD dwLocalError = LW_ERROR_SUCCESS;


    /* Case : LsaBeginEnumUsers: Call LsaBeginEnumUsers and then LsaEndEnumUsers. */
    dwLocalError = LsaBeginEnumUsers(
                        hLsaConnection,
                        0,  /* UserInfoLevel. */
                        10, /* Max users to return. */
                        0,  /* Flags. */
                        &hResume);
    BAIL_ON_TEST_BROKE(dwLocalError);
    if ( hResume != (HANDLE)NULL) 
    {
        LsaEndEnumUsers(hLsaConnection, hResume);
        hResume = NULL;
    }

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

error:
    goto cleanup;
}
Exemplo n.º 4
0
/*
 * VerifyNullHandling
 *
 */
static
DWORD
VerifyNullHandling(
    HANDLE hLsaConnection
)
{
    PCSTR pszTestDescription =
        "LsaOpenSession does not accept NULL login id.";
    PCSTR pszTestAPIs =
        "LsaOpenSession";
    char szTestMsg[128] = { 0 };

    DWORD dwLocalError = LW_ERROR_SUCCESS;
    DWORD dwError = LW_ERROR_SUCCESS;

    int bSessionIsOpen = 0;

    dwLocalError = LsaOpenSession(hLsaConnection, NULL);
    if ( dwLocalError == LW_ERROR_SUCCESS )
    {
        bSessionIsOpen = 1;

        snprintf(
            szTestMsg,
            sizeof(szTestMsg),
            "LsaOpenSession did not return error for a NULL login id.");

        dwError = LW_ERROR_TEST_FAILED;
        goto error;
    }

cleanup:

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

    LWT_LOG_TEST(szTestMsg);
    return dwError;

error:

    goto cleanup;

}
Exemplo n.º 5
0
static
DWORD
TestDelUser(
    HANDLE hLsaConnection,
    PSTR pszUser
    )
{
    DWORD dwError = LW_ERROR_SUCCESS;
    LSA_FIND_FLAGS FindFlags = 0;
    PVOID pUserInfo = NULL;

    PCSTR pszTestDescription = 
        "Verify LsaDeleteUserByName adds a user";
    PCSTR pszTestAPIs = 
        "LsaDeleteUserByName";
    
    char szTestMsg[512] = { 0 };

    dwError = LsaDeleteUserByName(
                    hLsaConnection,
                    pszUser);
    BAIL_ON_TEST_BROKE(dwError);
    
    dwError = LsaFindUserByName(
                    hLsaConnection,
                    pszUser,
                    FindFlags,
                    &pUserInfo);
    BAIL_ON_TEST_BROKE(dwError);
    
    if( pUserInfo )
    {
        dwError = LW_ERROR_TEST_FAILED;
        snprintf(szTestMsg, sizeof(szTestMsg), 
            "unexpected result while deleting the user %s",
            pszUser);
        LWT_LOG_TEST(szTestMsg);
    }

cleanup:

    return dwError;

error:
    goto cleanup;
}
Exemplo n.º 6
0
/*
 * VerifyNullHandling
 *
 * Make sure NULL does not crash server.
 */
static
DWORD
VerifyNullHandling(
    HANDLE hLsaConnection
    )
{
    PCSTR pszTestDescription = 
        "LsaFindUserByName returns error given NULL user name.";
    PCSTR pszTestAPIs = 
        "LsaFindUserByName";
    char szTestMsg[128] = { 0 };
    DWORD dwError = LW_ERROR_SUCCESS;
    DWORD dwLocalError = LW_ERROR_SUCCESS;
    LSA_USER_INFO_0 *pUserInfo = NULL;
    size_t i;

    for ( i = 0; i < 3; i++ )
    {
        dwLocalError = LsaFindUserByName( hLsaConnection,
                                          NULL,
                                          i, 
                                          (void**) &pUserInfo);
        
        if ( pUserInfo )
        {
            LsaFreeUserInfo(i, pUserInfo);
        }

        if ( dwLocalError != LW_ERROR_INVALID_PARAMETER )
        {
            dwError = LW_ERROR_TEST_FAILED;
            goto error;
        }
    }

cleanup:
    LWT_LOG_TEST(szTestMsg);
    return dwError;

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

}
Exemplo n.º 8
0
/*
* API for checking invalid error
*
*/
static
DWORD
CheckAPIForInvalidData(
    HANDLE hLsaConnection,
    PLWTFAILDATA pLwtFailData
    )
{
    DWORD dwError = LW_ERROR_SUCCESS;
    HANDLE hResume = (HANDLE)NULL;
    DWORD dwBatchLimit = 10;
    char szTestMsg[256] = { 0 };
    
    PCSTR pszTestDescription = 
        "Verify LsaEnumUsers parametre for invalid Level and Max Entries";
    PCSTR pszTestAPIs = 
        "LsaBeginEnumUsers";
    

    if (pLwtFailData->Field == LWTMAXUSER_INVALID)
    {
        dwError = LsaBeginEnumUsers(
            hLsaConnection,
            pLwtFailData->dwLevel,
            pLwtFailData->dwMaxEntries,     
            0,
            &hResume);

        if (dwError != pLwtFailData->dwErrorCode)
        {
            dwError = LW_ERROR_TEST_FAILED;
            snprintf(
                szTestMsg,
                sizeof(szTestMsg),
                "Invalid Error Code %lu returned for invalid  max userentry %lu for user name %s",
                (unsigned long)dwError,
                (unsigned long)pLwtFailData->dwMaxEntries,
                pLwtFailData->pszUserName);

            LWT_LOG_TEST(szTestMsg);

        }
    }
    if (pLwtFailData->Field == LWTUSERINFOLEVEL_INVALID)
    {
        dwError = LsaBeginEnumUsers(
            hLsaConnection,
            pLwtFailData->dwLevel,
            dwBatchLimit,
            0,
            &hResume);

        if (dwError != pLwtFailData->dwErrorCode)
        {
            dwError = LW_ERROR_TEST_FAILED;
            snprintf(
                szTestMsg,
                sizeof(szTestMsg),
                "Invalid Error Code %lu returned for invalid group info level %lu",
                (unsigned long)dwError,
                (unsigned long)pLwtFailData->dwLevel);
            
            LWT_LOG_TEST(szTestMsg);
        }
    }
    if (hResume)
    {
        LsaEndEnumUsers(hLsaConnection, hResume);
    }
    return dwError;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
/*
 * ValidateForInvalidParams
 * 
 * Function validates the API for Invalid function parameters.
 * 
 */
static
DWORD 
ValidateForInvalidParams(
    HANDLE hLsaConnection,
    PTESTDATA pTestData
    )
{
    DWORD dwError = LW_ERROR_SUCCESS;
    DWORD dwLocalError = LW_ERROR_SUCCESS;
    DWORD dwTest = 0;
    CHAR  szTestMsg[256] = { 0 };
    PLWTFAILDATA pInvalidData = NULL;
    PVOID pUserInfo = NULL;
    PCSTR pszTestAPIs = "LsaFindUserByName";
    PCSTR pszTestDescription = 
            "API returns invalid parameter error for invalid function parameters";

    if ( !pTestData || !pTestData->pInvalidDataIface )
    {
        dwLocalError = LW_ERROR_TEST_SKIPPED;
        BAIL_ON_TEST_BROKE(dwLocalError);
    }

    for ( dwTest = 0; dwTest < pTestData->dwNumInvalidDataSet; dwTest++ )
    {
        dwLocalError = GetInvalidDataRecord( pTestData, 
                                             dwTest, 
                                             &pInvalidData);
        BAIL_ON_TEST_BROKE(dwLocalError);

        if ( LWTUSER_INVALID == pInvalidData->Field )
        {
            dwLocalError = LsaFindUserByName(
                                hLsaConnection,
                                pInvalidData->pszUserName,
                                pInvalidData->dwLevel,
                                &pUserInfo
                                );

            if ( dwLocalError != pInvalidData->dwErrorCode )
            {
                dwError = LW_ERROR_TEST_FAILED;
                snprintf( szTestMsg, 
                          sizeof(szTestMsg), 
                          "API returned with error code (%lu) for invalid user name parameter",
                          (unsigned long)dwLocalError);
                LWT_LOG_TEST(szTestMsg);
            }

            FreeUserInfo(pInvalidData->dwLevel, pUserInfo);
        }

        if ( LWTUSERINFOLEVEL_INVALID == pInvalidData->Field )
        {
            dwLocalError = LsaFindUserByName(
                                hLsaConnection,
                                pInvalidData->pszUserName,
                                pInvalidData->dwLevel,
                                &pUserInfo
                                );

            if ( dwLocalError != pInvalidData->dwErrorCode )
            {
                dwError = LW_ERROR_TEST_FAILED;
                snprintf( szTestMsg, 
                          sizeof(szTestMsg), 
                          "API returned with error code (%lu) for invalid user name parameter",
                          (unsigned long)dwLocalError);
                LWT_LOG_TEST(szTestMsg);
            }

            FreeUserInfo(pInvalidData->dwLevel, pUserInfo);
        }

        FreeInvalidDataRecord(pInvalidData);
    }

error:
    return dwError;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
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;
}