trigger: internal: add credentials information
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 24 Mar 2020 16:15:22 +0000 (12:15 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 11 Aug 2020 16:23:06 +0000 (12:23 -0400)
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 <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I70d7f79918693b52db9b384b56e6476f3449e71d

include/lttng/trigger/trigger-internal.h
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/rotate.c
src/common/optional.h
src/common/trigger.c

index 2cef67d077d3cf47bd08104c75faacb9ea31a200..d857ff78e20ee54bdc9d98cc10854f371391ef06 100644 (file)
@@ -9,7 +9,9 @@
 #define LTTNG_TRIGGER_INTERNAL_H
 
 #include <lttng/trigger/trigger.h>
+#include <common/credentials.h>
 #include <common/macros.h>
+#include <common/optional.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include <sys/types.h>
@@ -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 */
index 1922fd594c6dc519838a359dc9704eab7318ab01..dc1249ff1c845bef46a560e4221fd207a49d9b37 100644 (file)
@@ -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:
index e2a3ef9eaac221ef97cc611004db602d7af347f0..30ec241249e5a1020b88b63ee01845122fbb9b2a 100644 (file)
@@ -17,6 +17,7 @@
 #include <common/time.h>
 #include <common/hashtable/utils.h>
 #include <common/kernel-ctl/kernel-ctl.h>
+#include <common/credentials.h>
 #include <sys/eventfd.h>
 #include <sys/stat.h>
 #include <time.h>
@@ -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) {
index 05f6054dade7c0a8fecbf20b5ef0bb5de1023807..0d99fe3224f4e419679d22627a0f4899f0c2a9d2 100644 (file)
                (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.
  *
index 5ff478a46f220c7815dd0f4db48343d7577e7690..ead0fc259a0eb09af3211df7038aeda00fb28f72 100644 (file)
@@ -8,9 +8,11 @@
 #include <lttng/trigger/trigger-internal.h>
 #include <lttng/condition/condition-internal.h>
 #include <lttng/action/action-internal.h>
+#include <common/credentials.h>
 #include <common/payload.h>
 #include <common/payload-view.h>
 #include <common/error.h>
+#include <common/optional.h>
 #include <assert.h>
 
 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);
+}
This page took 0.029669 seconds and 4 git commands to generate.