Commit | Line | Data |
---|---|---|
894e6e1c JR |
1 | /* |
2 | * Copyright (C) 2020 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: LGPL-2.1-only | |
5 | * | |
6 | */ | |
7 | ||
894e6e1c | 8 | #include <stdbool.h> |
c9e313bc | 9 | #include "credentials.hpp" |
894e6e1c | 10 | |
ff588497 JR |
11 | uid_t lttng_credentials_get_uid(const struct lttng_credentials *creds) |
12 | { | |
13 | return LTTNG_OPTIONAL_GET(creds->uid); | |
14 | } | |
15 | ||
16 | gid_t lttng_credentials_get_gid(const struct lttng_credentials *creds) | |
17 | { | |
18 | return LTTNG_OPTIONAL_GET(creds->gid); | |
19 | } | |
20 | ||
21 | bool lttng_credentials_is_equal_uid(const struct lttng_credentials *a, | |
894e6e1c JR |
22 | const struct lttng_credentials *b) |
23 | { | |
a0377dfe FD |
24 | LTTNG_ASSERT(a); |
25 | LTTNG_ASSERT(b); | |
894e6e1c | 26 | |
ff588497 JR |
27 | /* XOR on the is_set value */ |
28 | if (!!a->uid.is_set != !!b->uid.is_set) { | |
894e6e1c JR |
29 | return false; |
30 | } | |
31 | ||
ff588497 JR |
32 | if (!a->uid.is_set && !b->uid.is_set) { |
33 | return true; | |
34 | } | |
35 | ||
36 | /* Both a and b are set. */ | |
37 | return a->uid.value == b->uid.value; | |
38 | } | |
39 | ||
40 | bool lttng_credentials_is_equal_gid(const struct lttng_credentials *a, | |
41 | const struct lttng_credentials *b) | |
42 | { | |
a0377dfe FD |
43 | LTTNG_ASSERT(a); |
44 | LTTNG_ASSERT(b); | |
ff588497 JR |
45 | |
46 | /* XOR on the is_set value */ | |
47 | if (!!a->gid.is_set != !!b->gid.is_set) { | |
48 | return false; | |
49 | } | |
50 | ||
51 | if (!a->gid.is_set && !b->gid.is_set) { | |
52 | return true; | |
53 | } | |
54 | ||
55 | /* Both a and b are set. */ | |
56 | return a->gid.value == b->gid.value; | |
57 | } | |
58 | ||
59 | bool lttng_credentials_is_equal(const struct lttng_credentials *a, | |
60 | const struct lttng_credentials *b) | |
61 | { | |
a0377dfe FD |
62 | LTTNG_ASSERT(a); |
63 | LTTNG_ASSERT(b); | |
ff588497 JR |
64 | |
65 | return lttng_credentials_is_equal_uid(a, b) && | |
66 | lttng_credentials_is_equal_gid(a, b); | |
67 | } |