From: Jonathan Rajotte Date: Tue, 24 Mar 2020 16:15:22 +0000 (-0400) Subject: trigger: internal: add credentials information X-Git-Tag: v2.13.0-rc1~543 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3da864a94ccc39239fea82c4803b58b6b56a1003;p=lttng-tools.git trigger: internal: add credentials information These credentials are for internal use only. We plan on using them for listing, run-as filter bytecode generation and more. Introduce LTTNG_OPTIONAL_GET_PTR which is used to assert and return the pointer for an LTTNG_OPTIONAL underlying element. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: I70d7f79918693b52db9b384b56e6476f3449e71d --- diff --git a/include/lttng/trigger/trigger-internal.h b/include/lttng/trigger/trigger-internal.h index 2cef67d07..d857ff78e 100644 --- a/include/lttng/trigger/trigger-internal.h +++ b/include/lttng/trigger/trigger-internal.h @@ -9,7 +9,9 @@ #define LTTNG_TRIGGER_INTERNAL_H #include +#include #include +#include #include #include #include @@ -20,6 +22,7 @@ struct lttng_payload_view; struct lttng_trigger { struct lttng_condition *condition; struct lttng_action *action; + LTTNG_OPTIONAL(struct lttng_credentials) creds; }; struct lttng_trigger_comm { @@ -48,4 +51,13 @@ const struct lttng_action *lttng_trigger_get_const_action( LTTNG_HIDDEN bool lttng_trigger_validate(struct lttng_trigger *trigger); +LTTNG_HIDDEN +const struct lttng_credentials *lttng_trigger_get_credentials( + const struct lttng_trigger *trigger); + +LTTNG_HIDDEN +void lttng_trigger_set_credentials( + struct lttng_trigger *trigger, + const struct lttng_credentials *creds); + #endif /* LTTNG_TRIGGER_INTERNAL_H */ diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 1922fd594..dc1249ff1 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -4264,6 +4264,10 @@ int cmd_register_trigger(struct command_ctx *cmd_ctx, int sock, ssize_t sock_recv_len; 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, + }; lttng_payload_init(&trigger_payload); trigger_len = (size_t) cmd_ctx->lsm.u.trigger.length; @@ -4310,6 +4314,10 @@ int cmd_register_trigger(struct command_ctx *cmd_ctx, int sock, } } + /* Set the trigger credential */ + lttng_trigger_set_credentials(trigger, &cmd_creds); + + /* Inform the notification thread */ ret = notification_thread_command_register_trigger(notification_thread, trigger); /* Ownership of trigger was transferred. */ @@ -4328,6 +4336,10 @@ int cmd_unregister_trigger(struct command_ctx *cmd_ctx, int sock, ssize_t sock_recv_len; 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, + }; lttng_payload_init(&trigger_payload); trigger_len = (size_t) cmd_ctx->lsm.u.trigger.length; @@ -4373,6 +4385,8 @@ int cmd_unregister_trigger(struct command_ctx *cmd_ctx, int sock, } } + lttng_trigger_set_credentials(trigger, &cmd_creds); + ret = notification_thread_command_unregister_trigger(notification_thread, trigger); end: diff --git a/src/bin/lttng-sessiond/rotate.c b/src/bin/lttng-sessiond/rotate.c index e2a3ef9ea..30ec24124 100644 --- a/src/bin/lttng-sessiond/rotate.c +++ b/src/bin/lttng-sessiond/rotate.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,10 @@ int subscribe_session_consumed_size_rotation(struct ltt_session *session, uint64 enum lttng_condition_status condition_status; enum lttng_notification_channel_status nc_status; struct lttng_action *action; + const struct lttng_credentials session_creds = { + .uid = session->uid, + .gid = session->gid, + }; session->rotate_condition = lttng_condition_session_consumed_size_create(); if (!session->rotate_condition) { @@ -88,6 +93,9 @@ int subscribe_session_consumed_size_rotation(struct ltt_session *session, uint64 goto end; } + lttng_trigger_set_credentials( + session->rotate_trigger, &session_creds); + nc_status = lttng_notification_channel_subscribe( rotate_notification_channel, session->rotate_condition); if (nc_status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) { diff --git a/src/common/optional.h b/src/common/optional.h index 05f6054da..0d99fe322 100644 --- a/src/common/optional.h +++ b/src/common/optional.h @@ -67,6 +67,17 @@ (optional).value; \ }) +/* + * This macro is available as a 'convenience' to allow sites that assume + * an optional value is set to assert() that it is set when fecthing the + * underlying value's address. + */ +#define LTTNG_OPTIONAL_GET_PTR(optional) \ + ({ \ + assert((optional).is_set); \ + &(optional).value; \ + }) + /* * Initialize an optional field. * diff --git a/src/common/trigger.c b/src/common/trigger.c index 5ff478a46..ead0fc259 100644 --- a/src/common/trigger.c +++ b/src/common/trigger.c @@ -8,9 +8,11 @@ #include #include #include +#include #include #include #include +#include #include LTTNG_HIDDEN @@ -46,6 +48,7 @@ struct lttng_trigger *lttng_trigger_create( trigger->condition = condition; trigger->action = action; + end: return trigger; } @@ -192,3 +195,19 @@ int lttng_trigger_serialize(struct lttng_trigger *trigger, end: return ret; } + +LTTNG_HIDDEN +const struct lttng_credentials *lttng_trigger_get_credentials( + const struct lttng_trigger *trigger) +{ + return LTTNG_OPTIONAL_GET_PTR(trigger->creds); +} + +LTTNG_HIDDEN +void lttng_trigger_set_credentials( + struct lttng_trigger *trigger, + const struct lttng_credentials *creds) +{ + assert(creds); + LTTNG_OPTIONAL_SET(&trigger->creds, *creds); +}