#define LTTNG_EVENT_RULE_INTERNAL_H
#include <common/macros.h>
+#include <common/credentials.h>
#include <lttng/domain.h>
#include <lttng/event-rule/event-rule.h>
#include <lttng/lttng-error.h>
struct lttng_payload_view *view,
struct lttng_event_rule **event_rule);
typedef enum lttng_error_code (*event_rule_generate_filter_bytecode_cb)(
- struct lttng_event_rule *event_rule, uid_t uid, gid_t gid);
+ struct lttng_event_rule *event_rule,
+ const struct lttng_credentials *creds);
typedef const char *(*event_rule_get_filter_cb)(
const struct lttng_event_rule *event_rule);
typedef const struct lttng_filter_bytecode *(
LTTNG_HIDDEN
enum lttng_error_code lttng_event_rule_generate_filter_bytecode(
- struct lttng_event_rule *rule, uid_t uid, gid_t gid);
+ struct lttng_event_rule *rule,
+ const struct lttng_credentials *creds);
/*
* If not present/implemented returns NULL.
enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction(
const struct lttng_trigger *trigger);
+/*
+ * Generate any bytecode related to the trigger.
+ * On success LTTNG_OK. On error, returns lttng_error code.
+ */
+LTTNG_HIDDEN
+enum lttng_error_code lttng_trigger_generate_bytecode(
+ struct lttng_trigger *trigger,
+ const struct lttng_credentials *creds);
+
#endif /* LTTNG_TRIGGER_INTERNAL_H */
}
}
+ /*
+ * The bytecode generation also serves as a validation step for the
+ * bytecode expressions.
+ */
+ ret = lttng_trigger_generate_bytecode(trigger, &cmd_creds);
+ if (ret != LTTNG_OK) {
+ goto end;
+ }
+
/*
* A reference to the trigger is acquired by the notification thread.
* It is safe to return the same trigger to the caller since it the
LTTNG_HIDDEN
enum lttng_error_code lttng_event_rule_generate_filter_bytecode(
- struct lttng_event_rule *rule, uid_t uid, gid_t gid)
+ struct lttng_event_rule *rule,
+ const struct lttng_credentials *creds)
{
assert(rule->generate_filter_bytecode);
- return rule->generate_filter_bytecode(rule, uid, gid);
+ return rule->generate_filter_bytecode(rule, creds);
}
LTTNG_HIDDEN
*/
#include <assert.h>
+#include <common/credentials.h>
#include <common/error.h>
#include <common/macros.h>
#include <common/payload.h>
}
static enum lttng_error_code lttng_event_rule_kprobe_generate_filter_bytecode(
- struct lttng_event_rule *rule, uid_t uid, gid_t gid)
+ struct lttng_event_rule *rule,
+ const struct lttng_credentials *creds)
{
/* Nothing to do. */
return LTTNG_OK;
*/
#include <assert.h>
+#include <common/credentials.h>
#include <common/error.h>
#include <common/macros.h>
#include <common/payload.h>
}
static enum lttng_error_code lttng_event_rule_syscall_generate_filter_bytecode(
- struct lttng_event_rule *rule, uid_t uid, gid_t gid)
+ struct lttng_event_rule *rule,
+ const struct lttng_credentials *creds)
{
int ret;
enum lttng_error_code ret_code = LTTNG_OK;
}
ret = run_as_generate_filter_bytecode(
- syscall->internal_filter.filter, uid, gid, &bytecode);
+ syscall->internal_filter.filter, creds, &bytecode);
if (ret) {
ret_code = LTTNG_ERR_FILTER_INVAL;
}
*/
#include <assert.h>
+#include <common/credentials.h>
#include <common/error.h>
#include <common/macros.h>
#include <common/payload.h>
static enum lttng_error_code
lttng_event_rule_tracepoint_generate_filter_bytecode(
- struct lttng_event_rule *rule, uid_t uid, gid_t gid)
+ struct lttng_event_rule *rule,
+ const struct lttng_credentials *creds)
{
int ret;
enum lttng_error_code ret_code;
}
ret = run_as_generate_filter_bytecode(
- tracepoint->internal_filter.filter, uid, gid,
+ tracepoint->internal_filter.filter, creds,
&bytecode);
if (ret) {
ret_code = LTTNG_ERR_FILTER_INVAL;
*/
#include <assert.h>
+#include <common/credentials.h>
#include <common/error.h>
#include <common/macros.h>
#include <common/payload.h>
}
static enum lttng_error_code lttng_event_rule_uprobe_generate_filter_bytecode(
- struct lttng_event_rule *rule, uid_t uid, gid_t gid)
+ struct lttng_event_rule *rule,
+ const struct lttng_credentials *creds)
{
/* Nothing to do. */
return LTTNG_OK;
LTTNG_HIDDEN
int run_as_generate_filter_bytecode(const char *filter_expression,
- uid_t uid,
- gid_t gid,
+ const struct lttng_credentials *creds,
struct lttng_filter_bytecode **bytecode)
{
int ret;
struct run_as_ret run_as_ret = {};
const struct lttng_filter_bytecode *view_bytecode = NULL;
struct lttng_filter_bytecode *local_bytecode = NULL;
+ const uid_t uid = lttng_credentials_get_uid(creds);
+ const gid_t gid = lttng_credentials_get_gid(creds);
DBG3("generate_filter_bytecode() from expression=\"%s\" for uid %d and gid %d",
filter_expression, (int) uid, (int) gid);
uint64_t **offsets, uint32_t *num_offset);
LTTNG_HIDDEN
int run_as_generate_filter_bytecode(const char *filter_expression,
- uid_t uid,
- gid_t gid,
+ const struct lttng_credentials *creds,
struct lttng_filter_bytecode **bytecode);
LTTNG_HIDDEN
int run_as_create_worker(const char *procname,
#include <lttng/trigger/trigger-internal.h>
#include <lttng/condition/condition-internal.h>
#include <lttng/condition/event-rule.h>
+#include <lttng/condition/event-rule-internal.h>
#include <lttng/condition/buffer-usage.h>
#include <lttng/event-rule/event-rule-internal.h>
#include <lttng/action/action-internal.h>
return type;
}
+
+/*
+ * Generate bytecode related to the trigger.
+ * On success LTTNG_OK. On error, returns lttng_error code.
+ */
+LTTNG_HIDDEN
+enum lttng_error_code lttng_trigger_generate_bytecode(
+ struct lttng_trigger *trigger,
+ const struct lttng_credentials *creds)
+{
+ enum lttng_error_code ret;
+ struct lttng_condition *condition = NULL;
+
+ condition = lttng_trigger_get_condition(trigger);
+ if (!condition) {
+ ret = LTTNG_ERR_INVALID_TRIGGER;
+ goto end;
+ }
+
+ switch (lttng_condition_get_type(condition)) {
+ case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT:
+ {
+ struct lttng_event_rule *event_rule;
+ const enum lttng_condition_status condition_status =
+ lttng_condition_event_rule_borrow_rule_mutable(
+ condition, &event_rule);
+
+ assert(condition_status == LTTNG_CONDITION_STATUS_OK);
+ ret = lttng_event_rule_generate_filter_bytecode(
+ event_rule, creds);
+ if (ret != LTTNG_OK) {
+ goto end;
+ }
+
+ ret = LTTNG_OK;
+ break;
+ }
+ default:
+ ret = LTTNG_OK;
+ break;
+ }
+end:
+ return ret;
+}