Exemple #1
0
//--------------------------------------------------------------------------------------------------
static tu_UserRef_t GetUserInfo
(
    le_msg_SessionRef_t currentSession,  ///< [IN]  Get the user information for this message
                                         ///<       session.
    bool* wasCreated                     ///< [OUT] Was the user info created for this request?
                                         ///<       Pass NULL if you don't need this.
)
//--------------------------------------------------------------------------------------------------
{
    LE_FATAL_IF(currentSession == NULL, "Bad user message session reference.");

    // Look up the user id of the requesting connection...
    uid_t userId;

    LE_FATAL_IF(le_msg_GetClientUserId(currentSession, &userId) == LE_CLOSED,
                "tu_GetUserInfo must be called within an active connection.");

    // Now that we have a user ID, let's see if we can look them up.
    tu_UserRef_t userRef = GetUser(userId, wasCreated);
    LE_ASSERT(userRef != NULL);

    LE_DEBUG("** Found user <%p>: '%s', %u with default tree, '%s'.",
             userRef,
             userRef->userName,
             userRef->userId,
             userRef->treeName);

    return userRef;
}
Exemple #2
0
//--------------------------------------------------------------------------------------------------
static void NewSessionHandler
(
    le_msg_SessionRef_t sessionRef,
    void*               contextPtr
)
//--------------------------------------------------------------------------------------------------
{
    LE_INFO("Client started a new session.");

    LE_INFO("contextPtr = %p.", contextPtr);
    LE_TEST(contextPtr == &ServiceOpenContextPtr);

    // Because the unit tests are run always as a single, non-root user, we expect the user ID
    // of the client to be the same user ID that we are running as.
    uid_t clientUserId;
    uid_t myUserId = getuid();
    le_result_t result = le_msg_GetClientUserId(sessionRef, &clientUserId);
    LE_INFO("le_msg_GetClientUserId() returned '%s' with UID %u.",
            LE_RESULT_TXT(result),
            clientUserId);
    LE_INFO("getuid() returned %u.", myUserId);
    LE_TEST(clientUserId == myUserId);
}