Пример #1
0
static void TestUserNameAndId(void)
{
    // Test user id.
    uid_t uid;
    gid_t gid;

    LE_ASSERT(user_GetIDs(USER_NAME, &uid, &gid) == LE_OK);
    LE_ASSERT(uid == Uid);
    LE_ASSERT(gid == Gid);

    // Test the GetUid() function.
    LE_ASSERT(user_GetUid(USER_NAME, &uid) == LE_OK);
    LE_ASSERT(uid == Uid);

    // Test the GetGid() function.
    LE_ASSERT(user_GetGid(USER_NAME, &gid) == LE_OK);
    LE_ASSERT(gid == Gid);

    // Test user name.
    char buf[100];
    LE_ASSERT(user_GetName(Uid, buf, sizeof(buf)) == LE_OK);

    LE_ASSERT(strcmp(buf, USER_NAME) == 0);

    // Test group name.
    LE_ASSERT(user_GetGroupName(Gid, buf, sizeof(buf)) == LE_OK);

    LE_ASSERT(strcmp(buf, USER_NAME) == 0);

    // Test app name.
    LE_ASSERT(user_GetAppName(Uid, buf, sizeof(buf)) == LE_NOT_FOUND);

    LE_ASSERT(user_GetAppName(AppUid, buf, sizeof(buf)) == LE_OK);
    LE_ASSERT(strcmp(buf, APP_NAME) == 0);
}
Пример #2
0
static void TestUserDeletion(void)
{
    LE_ASSERT(user_Delete(USER_NAME) == LE_OK);
    LE_ASSERT(user_Delete(APP_USER_NAME) == LE_OK);

    LE_ASSERT(user_GetIDs(USER_NAME, NULL, NULL) == LE_NOT_FOUND);

    char buf[100];
    LE_ASSERT(user_GetName(Uid, buf, sizeof(buf)) == LE_NOT_FOUND);

    LE_ASSERT(user_GetAppName(AppUid, buf, sizeof(buf)) == LE_NOT_FOUND);
}
Пример #3
0
//--------------------------------------------------------------------------------------------------
static tu_UserRef_t GetUser
(
    uid_t userId,     ///< [IN]  The user id to look up.
    bool* wasCreated  ///< [OUT] Was the user info created for this request?  Pass NULL if you don't
                      ///<       need this.
)
//--------------------------------------------------------------------------------------------------
{
    // If the connected user has the same uid we're running under, treat the user as if they're
    // root.
    if (userId == geteuid())
    {
        userId = 0;
    }

    if (wasCreated)
    {
        *wasCreated = false;
    }

    // Now try to look up this user in our hash table.  If not found, create it now.
    tu_UserRef_t userRef = le_hashmap_Get(UserCollectionRef, &userId);

    if (userRef == NULL)
    {
        // At this point, grab the user's app name, which will succeed if it is an app, otherwise we get
        // the standard user name.

        char userName[LIMIT_MAX_USER_NAME_BYTES] = "";

        if (user_GetAppName(userId, userName, sizeof(userName)) != LE_OK)
        {
            LE_ASSERT(user_GetName(userId, userName, sizeof(userName)) == LE_OK);
        }

        userRef = CreateUserInfo(userId, userName, userName);

        if (wasCreated)
        {
            *wasCreated = true;
        }
    }

    return userRef;
}