credentials: uid and gid now use LTTNG_OPTIONAL
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 25 Sep 2020 20:35:28 +0000 (16:35 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 28 Oct 2020 21:13:52 +0000 (17:13 -0400)
The triggers will only use the uid element.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ia96e7def5ab560d9af1476920426635fc49f92ef

15 files changed:
src/bin/lttng-sessiond/action-executor.c
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/consumer.c
src/bin/lttng-sessiond/notification-thread-events.c
src/bin/lttng-sessiond/rotate.c
src/bin/lttng-sessiond/session.c
src/bin/lttng-sessiond/ust-app.c
src/bin/lttng-sessiond/ust-consumer.c
src/common/compat/directory-handle.c
src/common/credentials.c
src/common/credentials.h
src/common/kernel-consumer/kernel-consumer.c
src/common/trace-chunk.c
src/common/ust-consumer/ust-consumer.c
src/common/utils.c

index fc7d03d70a9fa4a3701ec5cce53ff98422df0a76..ca969074382174efb466c6cc278d31676d5bceda 100644 (file)
@@ -113,22 +113,21 @@ static bool is_trigger_allowed_for_session(const struct lttng_trigger *trigger,
 {
        bool is_allowed = false;
        const struct lttng_credentials session_creds = {
-               .uid = session->uid,
-               .gid = session->gid,
+               .uid = LTTNG_OPTIONAL_INIT_VALUE(session->uid),
+               .gid = LTTNG_OPTIONAL_INIT_VALUE(session->gid),
        };
        /* Can never be NULL. */
        const struct lttng_credentials *trigger_creds =
                        lttng_trigger_get_credentials(trigger);
 
-       is_allowed = (trigger_creds->uid == session_creds.uid) ||
-                       (trigger_creds->uid == 0);
+       is_allowed = (lttng_credentials_is_equal_uid(trigger_creds, &session_creds)) ||
+                       (lttng_credentials_get_uid(trigger_creds) == 0);
        if (!is_allowed) {
-               WARN("Trigger is not allowed to interact with session `%s`: session uid = %ld, session gid = %ld, trigger uid = %ld, trigger gid = %ld",
+               WARN("Trigger is not allowed to interact with session `%s`: session uid = %ld, session gid = %ld, trigger uid = %ld",
                                session->name,
                                (long int) session->uid,
                                (long int) session->gid,
-                               (long int) trigger_creds->uid,
-                               (long int) trigger_creds->gid);
+                               (long int) lttng_credentials_get_uid(trigger_creds));
        }
 
        return is_allowed;
index dc442035a3fe21e6b4c487a1007c9f05d1b38c56..9a832b4558679f1a3586d578a9eca9a8b3e8980b 100644 (file)
@@ -4265,8 +4265,8 @@ int cmd_register_trigger(struct command_ctx *cmd_ctx, int sock,
        struct lttng_trigger *trigger = NULL;
        struct lttng_payload trigger_payload;
        struct lttng_credentials cmd_creds = {
-               .uid = cmd_ctx->creds.uid,
-               .gid = cmd_ctx->creds.gid,
+               .uid = LTTNG_OPTIONAL_INIT_VALUE(cmd_ctx->creds.uid),
+               .gid = LTTNG_OPTIONAL_INIT_VALUE(cmd_ctx->creds.gid),
        };
 
        lttng_payload_init(&trigger_payload);
@@ -4337,8 +4337,8 @@ int cmd_unregister_trigger(struct command_ctx *cmd_ctx, int sock,
        struct lttng_trigger *trigger = NULL;
        struct lttng_payload trigger_payload;
        struct lttng_credentials cmd_creds = {
-               .uid = cmd_ctx->creds.uid,
-               .gid = cmd_ctx->creds.gid,
+               .uid = LTTNG_OPTIONAL_INIT_VALUE(cmd_ctx->creds.uid),
+               .gid = LTTNG_OPTIONAL_INIT_VALUE(cmd_ctx->creds.gid),
        };
 
        lttng_payload_init(&trigger_payload);
index 4bd9d80abc5655283435fa34473ddbb0215eda5b..115a46e2e1898c1e49213ef2dde91aaf07309ce9 100644 (file)
@@ -951,8 +951,10 @@ void consumer_init_ask_channel_comm_msg(struct lttcomm_consumer_msg *msg,
                assert(chunk_status == LTTNG_TRACE_CHUNK_STATUS_OK);
                LTTNG_OPTIONAL_SET(&msg->u.ask_channel.chunk_id, chunk_id);
        }
-       msg->u.ask_channel.buffer_credentials.uid = buffer_credentials->uid;
-       msg->u.ask_channel.buffer_credentials.gid = buffer_credentials->gid;
+       msg->u.ask_channel.buffer_credentials.uid =
+                       lttng_credentials_get_uid(buffer_credentials);
+       msg->u.ask_channel.buffer_credentials.gid =
+                       lttng_credentials_get_gid(buffer_credentials);
 
        msg->cmd_type = LTTNG_CONSUMER_ASK_CHANNEL_CREATION;
        msg->u.ask_channel.subbuf_size = subbuf_size;
@@ -1930,9 +1932,9 @@ int consumer_create_trace_chunk(struct consumer_socket *socket,
                assert(domain_dirfd >= 0);
 
                msg.u.create_trace_chunk.credentials.value.uid =
-                               chunk_credentials.uid;
+                               lttng_credentials_get_uid(&chunk_credentials);
                msg.u.create_trace_chunk.credentials.value.gid =
-                               chunk_credentials.gid;
+                               lttng_credentials_get_gid(&chunk_credentials);
                msg.u.create_trace_chunk.credentials.is_set = 1;
        }
 
index e01a00538ba8d2f04c389086860ebfd933798e9f..9e9a83888d81dac23e933c686846d0b8572b0e3a 100644 (file)
@@ -1807,8 +1807,8 @@ int handle_notification_thread_command_session_rotation(
        struct lttng_trigger_list_element *trigger_list_element;
        struct session_info *session_info;
        const struct lttng_credentials session_creds = {
-               .uid = session_uid,
-               .gid = session_gid,
+               .uid = LTTNG_OPTIONAL_INIT_VALUE(session_uid),
+               .gid = LTTNG_OPTIONAL_INIT_VALUE(session_gid),
        };
 
        rcu_read_lock();
@@ -2117,6 +2117,8 @@ int handle_notification_thread_command_register_trigger(
        bool free_trigger = true;
        struct lttng_evaluation *evaluation = NULL;
        struct lttng_credentials object_creds;
+       uid_t object_uid;
+       gid_t object_gid;
        enum action_executor_status executor_status;
 
        rcu_read_lock();
@@ -2260,13 +2262,13 @@ int handle_notification_thread_command_register_trigger(
        switch (get_condition_binding_object(condition)) {
        case LTTNG_OBJECT_TYPE_SESSION:
                ret = evaluate_session_condition_for_client(condition, state,
-                               &evaluation, &object_creds.uid,
-                               &object_creds.gid);
+                               &evaluation, &object_uid,
+                               &object_gid);
                break;
        case LTTNG_OBJECT_TYPE_CHANNEL:
                ret = evaluate_channel_condition_for_client(condition, state,
-                               &evaluation, &object_creds.uid,
-                               &object_creds.gid);
+                               &evaluation, &object_uid,
+                               &object_gid);
                break;
        case LTTNG_OBJECT_TYPE_NONE:
                ret = 0;
@@ -2282,6 +2284,9 @@ int handle_notification_thread_command_register_trigger(
                goto error_put_client_list;
        }
 
+       LTTNG_OPTIONAL_SET(&object_creds.uid, object_uid);
+       LTTNG_OPTIONAL_SET(&object_creds.gid, object_gid);
+
        DBG("Newly registered trigger's condition evaluated to %s",
                        evaluation ? "true" : "false");
        if (!evaluation) {
@@ -3582,11 +3587,15 @@ int send_evaluation_to_clients(const struct lttng_trigger *trigger,
                struct notification_thread_state *state,
                uid_t object_uid, gid_t object_gid)
 {
+       const struct lttng_credentials creds = {
+               .uid = LTTNG_OPTIONAL_INIT_VALUE(object_uid),
+               .gid = LTTNG_OPTIONAL_INIT_VALUE(object_gid),
+       };
+
        return notification_client_list_send_evaluation(client_list,
                        lttng_trigger_get_const_condition(trigger), evaluation,
                        lttng_trigger_get_credentials(trigger),
-                       &(struct lttng_credentials){
-                                       .uid = object_uid, .gid = object_gid},
+                       &creds,
                        client_handle_transmission_status_wrapper, state);
 }
 
@@ -3693,8 +3702,8 @@ int notification_client_list_send_evaluation(
                }
 
                if (source_object_creds) {
-                       if (client->uid != source_object_creds->uid &&
-                                       client->gid != source_object_creds->gid &&
+                       if (client->uid != lttng_credentials_get_uid(source_object_creds) &&
+                                       client->gid != lttng_credentials_get_gid(source_object_creds) &&
                                        client->uid != 0) {
                                /*
                                 * Client is not allowed to monitor this
@@ -3705,7 +3714,7 @@ int notification_client_list_send_evaluation(
                        }
                }
 
-               if (client->uid != trigger_creds->uid && client->gid != trigger_creds->gid) {
+               if (client->uid != lttng_credentials_get_uid(trigger_creds) && client->gid != lttng_credentials_get_gid(trigger_creds)) {
                        DBG("[notification-thread] Skipping client at it does not have the permission to receive notification for this trigger");
                        goto skip_client;
                }
@@ -3894,8 +3903,8 @@ int handle_notification_thread_channel_sample(
        }
 
        channel_creds = (typeof(channel_creds)) {
-               .uid = channel_info->session_info->uid,
-               .gid = channel_info->session_info->gid,
+               .uid = LTTNG_OPTIONAL_INIT_VALUE(channel_info->session_info->uid),
+               .gid = LTTNG_OPTIONAL_INIT_VALUE(channel_info->session_info->gid),
        };
 
        trigger_list = caa_container_of(node, struct lttng_channel_trigger_list,
index 813a1a0dc0847d699da2cf72251e8af0d4c88e45..097da860a1e2f40013cc80f325615e19017954f5 100644 (file)
@@ -47,8 +47,8 @@ int subscribe_session_consumed_size_rotation(struct ltt_session *session, uint64
        enum lttng_notification_channel_status nc_status;
        struct lttng_action *action;
        const struct lttng_credentials session_creds = {
-               .uid = session->uid,
-               .gid = session->gid,
+               .uid = LTTNG_OPTIONAL_INIT_VALUE(session->uid),
+               .gid = LTTNG_OPTIONAL_INIT_VALUE(session->gid),
        };
 
        session->rotate_condition = lttng_condition_session_consumed_size_create();
index f8134f8ad966a950b0c97f13bbb18f2ba12d89b9..a4d1163399e7cd74975b754b8c51160d1eb189f1 100644 (file)
@@ -574,8 +574,8 @@ struct lttng_trace_chunk *session_create_new_trace_chunk(
        const char *base_path;
        struct lttng_directory_handle *session_output_directory = NULL;
        const struct lttng_credentials session_credentials = {
-               .uid = session->uid,
-               .gid = session->gid,
+               .uid = LTTNG_OPTIONAL_INIT_VALUE(session->uid),
+               .gid = LTTNG_OPTIONAL_INIT_VALUE(session->gid),
        };
        uint64_t next_chunk_id;
        const struct consumer_output *output;
index c332f5c75b1df8bb698520b2d14bc67b7f7fe618..1f2d4238ef673825312e29b19f397c49ef482a9d 100644 (file)
@@ -245,7 +245,7 @@ static struct ust_registry_session *get_session_registry(
        {
                struct buffer_reg_uid *reg_uid = buffer_reg_uid_find(
                                ua_sess->tracing_id, ua_sess->bits_per_long,
-                               ua_sess->real_credentials.uid);
+                               lttng_credentials_get_uid(&ua_sess->real_credentials));
                if (!reg_uid) {
                        goto error;
                }
@@ -1847,10 +1847,10 @@ static void shadow_copy_session(struct ust_app_session *ua_sess,
 
        ua_sess->tracing_id = usess->id;
        ua_sess->id = get_next_session_id();
-       ua_sess->real_credentials.uid = app->uid;
-       ua_sess->real_credentials.gid = app->gid;
-       ua_sess->effective_credentials.uid = usess->uid;
-       ua_sess->effective_credentials.gid = usess->gid;
+       LTTNG_OPTIONAL_SET(&ua_sess->real_credentials.uid, app->uid);
+       LTTNG_OPTIONAL_SET(&ua_sess->real_credentials.gid, app->gid);
+       LTTNG_OPTIONAL_SET(&ua_sess->effective_credentials.uid, usess->uid);
+       LTTNG_OPTIONAL_SET(&ua_sess->effective_credentials.gid, usess->gid);
        ua_sess->buffer_type = usess->buffer_type;
        ua_sess->bits_per_long = app->bits_per_long;
 
@@ -1872,7 +1872,7 @@ static void shadow_copy_session(struct ust_app_session *ua_sess,
        case LTTNG_BUFFER_PER_UID:
                ret = snprintf(ua_sess->path, sizeof(ua_sess->path),
                                DEFAULT_UST_TRACE_UID_PATH,
-                               ua_sess->real_credentials.uid,
+                               lttng_credentials_get_uid(&ua_sess->real_credentials),
                                app->bits_per_long);
                break;
        default:
@@ -1995,8 +1995,9 @@ static int setup_buffer_reg_pid(struct ust_app_session *ua_sess,
                        app->uint64_t_alignment, app->long_alignment,
                        app->byte_order, app->version.major, app->version.minor,
                        reg_pid->root_shm_path, reg_pid->shm_path,
-                       ua_sess->effective_credentials.uid,
-                       ua_sess->effective_credentials.gid, ua_sess->tracing_id,
+                       lttng_credentials_get_uid(&ua_sess->effective_credentials),
+                       lttng_credentials_get_gid(&ua_sess->effective_credentials),
+                       ua_sess->tracing_id,
                        app->uid);
        if (ret < 0) {
                /*
@@ -2887,8 +2888,9 @@ static int create_channel_per_uid(struct ust_app *app,
 
        notification_ret = notification_thread_command_add_channel(
                        notification_thread_handle, session->name,
-                       ua_sess->effective_credentials.uid,
-                       ua_sess->effective_credentials.gid, ua_chan->name,
+                       lttng_credentials_get_uid(&ua_sess->effective_credentials),
+                       lttng_credentials_get_gid(&ua_sess->effective_credentials),
+                       ua_chan->name,
                        ua_chan->key, LTTNG_DOMAIN_UST,
                        ua_chan->attr.subbuf_size * ua_chan->attr.num_subbuf);
        if (notification_ret != LTTNG_OK) {
@@ -2987,8 +2989,9 @@ static int create_channel_per_pid(struct ust_app *app,
 
        cmd_ret = notification_thread_command_add_channel(
                        notification_thread_handle, session->name,
-                       ua_sess->effective_credentials.uid,
-                       ua_sess->effective_credentials.gid, ua_chan->name,
+                       lttng_credentials_get_uid(&ua_sess->effective_credentials),
+                       lttng_credentials_get_gid(&ua_sess->effective_credentials),
+                       ua_chan->name,
                        ua_chan->key, LTTNG_DOMAIN_UST,
                        ua_chan->attr.subbuf_size * ua_chan->attr.num_subbuf);
        if (cmd_ret != LTTNG_OK) {
@@ -5965,10 +5968,8 @@ enum lttng_error_code ust_app_snapshot_record(
                                        ua_chan, node.node) {
                                status = consumer_snapshot_channel(socket,
                                                ua_chan->key, output, 0,
-                                               ua_sess->effective_credentials
-                                                               .uid,
-                                               ua_sess->effective_credentials
-                                                               .gid,
+                                               lttng_credentials_get_uid(&ua_sess->effective_credentials),
+                                               lttng_credentials_get_gid(&ua_sess->effective_credentials),
                                                &trace_path[consumer_path_offset], wait,
                                                nb_packets_per_stream);
                                switch (status) {
@@ -5988,8 +5989,8 @@ enum lttng_error_code ust_app_snapshot_record(
                        }
                        status = consumer_snapshot_channel(socket,
                                        registry->metadata_key, output, 1,
-                                       ua_sess->effective_credentials.uid,
-                                       ua_sess->effective_credentials.gid,
+                                       lttng_credentials_get_uid(&ua_sess->effective_credentials),
+                                       lttng_credentials_get_gid(&ua_sess->effective_credentials),
                                        &trace_path[consumer_path_offset], wait, 0);
                        switch (status) {
                        case LTTNG_OK:
@@ -6345,10 +6346,8 @@ enum lttng_error_code ust_app_rotate_session(struct ltt_session *session)
                                        ua_chan, node.node) {
                                ret = consumer_rotate_channel(socket,
                                                ua_chan->key,
-                                               ua_sess->effective_credentials
-                                                               .uid,
-                                               ua_sess->effective_credentials
-                                                               .gid,
+                                               lttng_credentials_get_uid(&ua_sess->effective_credentials),
+                                               lttng_credentials_get_gid(&ua_sess->effective_credentials),
                                                ua_sess->consumer,
                                                /* is_metadata_channel */ false);
                                if (ret < 0) {
@@ -6364,8 +6363,8 @@ enum lttng_error_code ust_app_rotate_session(struct ltt_session *session)
                        (void) push_metadata(registry, usess->consumer);
                        ret = consumer_rotate_channel(socket,
                                        registry->metadata_key,
-                                       ua_sess->effective_credentials.uid,
-                                       ua_sess->effective_credentials.gid,
+                                       lttng_credentials_get_uid(&ua_sess->effective_credentials),
+                                       lttng_credentials_get_gid(&ua_sess->effective_credentials),
                                        ua_sess->consumer,
                                        /* is_metadata_channel */ true);
                        if (ret < 0) {
index 25dc7ed1c6da96c5fa8cfba14e95d78dab0e9ac1..70e3d165835974479ebad8e08e5460adaa1fbeb2 100644 (file)
@@ -151,7 +151,7 @@ static int ask_channel_creation(struct ust_app_session *ua_sess,
                        ua_chan->tracefile_count,
                        ua_sess->id,
                        ua_sess->output_traces,
-                       ua_sess->real_credentials.uid,
+                       lttng_credentials_get_uid(&ua_sess->real_credentials),
                        ua_chan->attr.blocking_timeout,
                        root_shm_path, shm_path,
                        trace_chunk,
index 356376ac0ed00a516fe9cadee59ac6a68b6835c5..a66d768e871f5eef5ae4be4556d3636c69c9fdca 100644 (file)
@@ -1019,8 +1019,9 @@ int lttng_directory_handle_create_subdirectory_as_user(
                ret = create_directory_check_exists(handle,
                                subdirectory, mode);
        } else {
-               ret = _run_as_mkdir(handle, subdirectory,
-                               mode, creds->uid, creds->gid);
+               ret = _run_as_mkdir(handle, subdirectory, mode,
+                               lttng_credentials_get_uid(creds),
+                               lttng_credentials_get_gid(creds));
        }
 
        return ret;
@@ -1040,7 +1041,7 @@ int lttng_directory_handle_create_subdirectory_recursive_as_user(
                                subdirectory_path, mode);
        } else {
                ret = _run_as_mkdir_recursive(handle, subdirectory_path,
-                               mode, creds->uid, creds->gid);
+                               mode, lttng_credentials_get_uid(creds), lttng_credentials_get_gid(creds));
        }
 
        return ret;
@@ -1081,7 +1082,7 @@ int lttng_directory_handle_open_file_as_user(
                                mode);
        } else {
                ret = _run_as_open(handle, filename, flags, mode,
-                               creds->uid, creds->gid);
+                               lttng_credentials_get_uid(creds), lttng_credentials_get_gid(creds));
        }
        return ret;
 }
@@ -1108,7 +1109,7 @@ int lttng_directory_handle_unlink_file_as_user(
                /* Run as current user. */
                ret = lttng_directory_handle_unlink(handle, filename);
        } else {
-               ret = _run_as_unlink(handle, filename, creds->uid, creds->gid);
+               ret = _run_as_unlink(handle, filename, lttng_credentials_get_uid(creds), lttng_credentials_get_gid(creds));
        }
        return ret;
 }
@@ -1149,7 +1150,7 @@ int lttng_directory_handle_rename_as_user(
                                old_name, new_handle, new_name);
        } else {
                ret = _run_as_rename(old_handle, old_name, new_handle,
-                               new_name, creds->uid, creds->gid);
+                               new_name, lttng_credentials_get_uid(creds), lttng_credentials_get_gid(creds));
        }
        return ret;
 }
@@ -1175,7 +1176,7 @@ int lttng_directory_handle_remove_subdirectory_as_user(
                /* Run as current user. */
                ret = lttng_directory_handle_rmdir(handle, name);
        } else {
-               ret = _run_as_rmdir(handle, name, creds->uid, creds->gid);
+               ret = _run_as_rmdir(handle, name, lttng_credentials_get_uid(creds), lttng_credentials_get_gid(creds));
        }
        return ret;
 }
@@ -1409,8 +1410,8 @@ int lttng_directory_handle_remove_subdirectory_recursive_as_user(
                /* Run as current user. */
                ret = remove_directory_recursive(handle, name, flags);
        } else {
-               ret = _run_as_rmdir_recursive(handle, name, creds->uid,
-                               creds->gid, flags);
+               ret = _run_as_rmdir_recursive(handle, name, lttng_credentials_get_uid(creds),
+                               lttng_credentials_get_gid(creds), flags);
        }
        return ret;
 }
index dc1bdd89f1182c984bbdf5ecbba4a8d51cddaf7d..589ffabc26f1ea7ac965ba70f702853fd3cfc2ee 100644 (file)
@@ -9,15 +9,60 @@
 #include <stdbool.h>
 #include "credentials.h"
 
-bool lttng_credentials_is_equal(const struct lttng_credentials *a,
+uid_t lttng_credentials_get_uid(const struct lttng_credentials *creds)
+{
+       return LTTNG_OPTIONAL_GET(creds->uid);
+}
+
+gid_t lttng_credentials_get_gid(const struct lttng_credentials *creds)
+{
+       return LTTNG_OPTIONAL_GET(creds->gid);
+}
+
+bool lttng_credentials_is_equal_uid(const struct lttng_credentials *a,
                const struct lttng_credentials *b)
 {
        assert(a);
        assert(b);
 
-       if ((a->uid != b->uid) || (a->gid != b->gid)) {
+       /* XOR on the is_set value */
+       if (!!a->uid.is_set != !!b->uid.is_set) {
                return false;
        }
 
-       return true;
-};
+       if (!a->uid.is_set && !b->uid.is_set) {
+               return true;
+       }
+
+       /* Both a and b are set. */
+       return a->uid.value == b->uid.value;
+}
+
+bool lttng_credentials_is_equal_gid(const struct lttng_credentials *a,
+               const struct lttng_credentials *b)
+{
+       assert(a);
+       assert(b);
+
+       /* XOR on the is_set value */
+       if (!!a->gid.is_set != !!b->gid.is_set) {
+               return false;
+       }
+
+       if (!a->gid.is_set && !b->gid.is_set) {
+               return true;
+       }
+
+       /* Both a and b are set. */
+       return a->gid.value == b->gid.value;
+}
+
+bool lttng_credentials_is_equal(const struct lttng_credentials *a,
+               const struct lttng_credentials *b)
+{
+       assert(a);
+       assert(b);
+
+       return lttng_credentials_is_equal_uid(a, b) &&
+                       lttng_credentials_is_equal_gid(a, b);
+}
index 9e5fc62608e9f828fadf8f6c37e637a7353c618e..c0dc6d7f14dfc6d7035088d3ad7eeb4ee0eaf59f 100644 (file)
 #include <sys/types.h>
 #include <stdbool.h>
 
+#include "optional.h"
+
 struct lttng_credentials {
-       uid_t uid;
-       gid_t gid;
+       LTTNG_OPTIONAL(uid_t) uid;
+       LTTNG_OPTIONAL(gid_t) gid;
 };
 
+uid_t lttng_credentials_get_uid(const struct lttng_credentials *creds);
+gid_t lttng_credentials_get_gid(const struct lttng_credentials *creds);
+
+bool lttng_credentials_is_equal_uid(const struct lttng_credentials *a,
+               const struct lttng_credentials *b);
+
+bool lttng_credentials_is_equal_gid(const struct lttng_credentials *a,
+               const struct lttng_credentials *b);
+
 bool lttng_credentials_is_equal(const struct lttng_credentials *a,
                const struct lttng_credentials *b);
 
index de1a14c218729bd9e88b0a1c1e9cf8219f85e596..b9d843714550c5821d3b091eb7fb6e390a3c6786 100644 (file)
@@ -1207,8 +1207,8 @@ error_rotate_channel:
        case LTTNG_CONSUMER_CREATE_TRACE_CHUNK:
        {
                const struct lttng_credentials credentials = {
-                       .uid = msg.u.create_trace_chunk.credentials.value.uid,
-                       .gid = msg.u.create_trace_chunk.credentials.value.gid,
+                       .uid = LTTNG_OPTIONAL_INIT_VALUE(msg.u.create_trace_chunk.credentials.value.uid),
+                       .gid = LTTNG_OPTIONAL_INIT_VALUE(msg.u.create_trace_chunk.credentials.value.gid),
                };
                const bool is_local_trace =
                                !msg.u.create_trace_chunk.relayd_id.is_set;
index b303607e348d8501133fe41a6b9b53683c35fc0f..8a8481b5d41e4ce77e0dbf21a53347d0fa39198a 100644 (file)
@@ -966,8 +966,8 @@ enum lttng_trace_chunk_status lttng_trace_chunk_get_credentials(
        pthread_mutex_lock(&chunk->lock);
        if (chunk->credentials.is_set) {
                if (chunk->credentials.value.use_current_user) {
-                       credentials->uid = geteuid();
-                       credentials->gid = getegid();
+                       LTTNG_OPTIONAL_SET(&credentials->uid, geteuid());
+                       LTTNG_OPTIONAL_SET(&credentials->gid, getegid());
                } else {
                        *credentials = chunk->credentials.value.user;
                }
index 209931f5644a3d74dc27ed1a8f7dbb3d3863d387..1a7de1cfd59cf0a095f80794e0ff96d462386a93 100644 (file)
@@ -409,7 +409,8 @@ static int open_ust_stream_fd(struct lttng_consumer_channel *channel, int cpu,
        }
        return run_as_open(shm_path,
                O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR,
-               session_credentials->uid, session_credentials->gid);
+               lttng_credentials_get_uid(session_credentials),
+               lttng_credentials_get_gid(session_credentials));
 
 error_shm_path:
        return -1;
@@ -487,8 +488,10 @@ error_open:
                                ERR("Cannot get stream shm path");
                        }
                        closeret = run_as_unlink(shm_path,
-                                       channel->buffer_credentials.value.uid,
-                                       channel->buffer_credentials.value.gid);
+                                       lttng_credentials_get_uid(LTTNG_OPTIONAL_GET_PTR(
+                                                       channel->buffer_credentials)),
+                                       lttng_credentials_get_gid(LTTNG_OPTIONAL_GET_PTR(
+                                                       channel->buffer_credentials)));
                        if (closeret) {
                                PERROR("unlink %s", shm_path);
                        }
@@ -497,8 +500,10 @@ error_open:
        /* Try to rmdir all directories under shm_path root. */
        if (channel->root_shm_path[0]) {
                (void) run_as_rmdir_recursive(channel->root_shm_path,
-                               channel->buffer_credentials.value.uid,
-                               channel->buffer_credentials.value.gid,
+                               lttng_credentials_get_uid(LTTNG_OPTIONAL_GET_PTR(
+                                               channel->buffer_credentials)),
+                               lttng_credentials_get_gid(LTTNG_OPTIONAL_GET_PTR(
+                                               channel->buffer_credentials)),
                                LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG);
        }
        free(stream_fds);
@@ -1461,8 +1466,8 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                struct ustctl_consumer_channel_attr attr;
                const uint64_t chunk_id = msg.u.ask_channel.chunk_id.value;
                const struct lttng_credentials buffer_credentials = {
-                       .uid = msg.u.ask_channel.buffer_credentials.uid,
-                       .gid = msg.u.ask_channel.buffer_credentials.gid,
+                       .uid = LTTNG_OPTIONAL_INIT_VALUE(msg.u.ask_channel.buffer_credentials.uid),
+                       .gid = LTTNG_OPTIONAL_INIT_VALUE(msg.u.ask_channel.buffer_credentials.gid),
                };
 
                /* Create a plain object and reserve a channel key. */
@@ -2072,8 +2077,8 @@ end_rotate_channel_nosignal:
        case LTTNG_CONSUMER_CREATE_TRACE_CHUNK:
        {
                const struct lttng_credentials credentials = {
-                       .uid = msg.u.create_trace_chunk.credentials.value.uid,
-                       .gid = msg.u.create_trace_chunk.credentials.value.gid,
+                       .uid = LTTNG_OPTIONAL_INIT_VALUE(msg.u.create_trace_chunk.credentials.value.uid),
+                       .gid = LTTNG_OPTIONAL_INIT_VALUE(msg.u.create_trace_chunk.credentials.value.gid),
                };
                const bool is_local_trace =
                                !msg.u.create_trace_chunk.relayd_id.is_set;
@@ -2402,8 +2407,10 @@ void lttng_ustconsumer_del_channel(struct lttng_consumer_channel *chan)
                                ERR("Cannot get stream shm path");
                        }
                        ret = run_as_unlink(shm_path,
-                                       chan->buffer_credentials.value.uid,
-                                       chan->buffer_credentials.value.gid);
+                                       lttng_credentials_get_uid(LTTNG_OPTIONAL_GET_PTR(
+                                                       chan->buffer_credentials)),
+                                       lttng_credentials_get_gid(LTTNG_OPTIONAL_GET_PTR(
+                                                       chan->buffer_credentials)));
                        if (ret) {
                                PERROR("unlink %s", shm_path);
                        }
@@ -2422,8 +2429,10 @@ void lttng_ustconsumer_free_channel(struct lttng_consumer_channel *chan)
        /* Try to rmdir all directories under shm_path root. */
        if (chan->root_shm_path[0]) {
                (void) run_as_rmdir_recursive(chan->root_shm_path,
-                               chan->buffer_credentials.value.uid,
-                               chan->buffer_credentials.value.gid,
+                               lttng_credentials_get_uid(LTTNG_OPTIONAL_GET_PTR(
+                                               chan->buffer_credentials)),
+                               lttng_credentials_get_gid(LTTNG_OPTIONAL_GET_PTR(
+                                               chan->buffer_credentials)),
                                LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG);
        }
        free(chan->stream_fds);
index 2a20e5a8c4ab4cca1557ca917cfa2de02defd905..bd61fff3d52ad8c6c16d68b0ca9e195009225018 100644 (file)
@@ -679,8 +679,8 @@ int utils_mkdir(const char *path, mode_t mode, int uid, int gid)
        int ret;
        struct lttng_directory_handle *handle;
        const struct lttng_credentials creds = {
-               .uid = (uid_t) uid,
-               .gid = (gid_t) gid,
+               .uid = LTTNG_OPTIONAL_INIT_VALUE(uid),
+               .gid = LTTNG_OPTIONAL_INIT_VALUE(gid),
        };
 
        handle = lttng_directory_handle_create(NULL);
@@ -708,8 +708,8 @@ int utils_mkdir_recursive(const char *path, mode_t mode, int uid, int gid)
        int ret;
        struct lttng_directory_handle *handle;
        const struct lttng_credentials creds = {
-               .uid = (uid_t) uid,
-               .gid = (gid_t) gid,
+               .uid = LTTNG_OPTIONAL_INIT_VALUE(uid),
+               .gid = LTTNG_OPTIONAL_INIT_VALUE(gid),
        };
 
        handle = lttng_directory_handle_create(NULL);
This page took 0.060066 seconds and 4 git commands to generate.