X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fcredentials.c;h=8b4621c7c03970b832b20385c5b641e320baee5a;hb=a0377dfefe40662ba7d68617bce6ff467114136c;hp=dc1bdd89f1182c984bbdf5ecbba4a8d51cddaf7d;hpb=894e6e1c66b3b7288c3cfca2a6f9d916774d6dea;p=lttng-tools.git diff --git a/src/common/credentials.c b/src/common/credentials.c index dc1bdd89f..8b4621c7c 100644 --- a/src/common/credentials.c +++ b/src/common/credentials.c @@ -5,19 +5,68 @@ * */ -#include #include #include "credentials.h" -bool lttng_credentials_is_equal(const struct lttng_credentials *a, +LTTNG_HIDDEN +uid_t lttng_credentials_get_uid(const struct lttng_credentials *creds) +{ + return LTTNG_OPTIONAL_GET(creds->uid); +} + +LTTNG_HIDDEN +gid_t lttng_credentials_get_gid(const struct lttng_credentials *creds) +{ + return LTTNG_OPTIONAL_GET(creds->gid); +} + +LTTNG_HIDDEN +bool lttng_credentials_is_equal_uid(const struct lttng_credentials *a, const struct lttng_credentials *b) { - assert(a); - assert(b); + LTTNG_ASSERT(a); + LTTNG_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; +} + +LTTNG_HIDDEN +bool lttng_credentials_is_equal_gid(const struct lttng_credentials *a, + const struct lttng_credentials *b) +{ + LTTNG_ASSERT(a); + LTTNG_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; +} + +LTTNG_HIDDEN +bool lttng_credentials_is_equal(const struct lttng_credentials *a, + const struct lttng_credentials *b) +{ + LTTNG_ASSERT(a); + LTTNG_ASSERT(b); + + return lttng_credentials_is_equal_uid(a, b) && + lttng_credentials_is_equal_gid(a, b); +}