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 | ||
c9e313bc | 8 | #include "credentials.hpp" |
894e6e1c | 9 | |
28ab034a JG |
10 | #include <stdbool.h> |
11 | ||
ff588497 JR |
12 | uid_t lttng_credentials_get_uid(const struct lttng_credentials *creds) |
13 | { | |
14 | return LTTNG_OPTIONAL_GET(creds->uid); | |
15 | } | |
16 | ||
17 | gid_t lttng_credentials_get_gid(const struct lttng_credentials *creds) | |
18 | { | |
19 | return LTTNG_OPTIONAL_GET(creds->gid); | |
20 | } | |
21 | ||
22 | bool lttng_credentials_is_equal_uid(const struct lttng_credentials *a, | |
28ab034a | 23 | const struct lttng_credentials *b) |
894e6e1c | 24 | { |
a0377dfe FD |
25 | LTTNG_ASSERT(a); |
26 | LTTNG_ASSERT(b); | |
894e6e1c | 27 | |
ff588497 JR |
28 | /* XOR on the is_set value */ |
29 | if (!!a->uid.is_set != !!b->uid.is_set) { | |
894e6e1c JR |
30 | return false; |
31 | } | |
32 | ||
ff588497 JR |
33 | if (!a->uid.is_set && !b->uid.is_set) { |
34 | return true; | |
35 | } | |
36 | ||
37 | /* Both a and b are set. */ | |
38 | return a->uid.value == b->uid.value; | |
39 | } | |
40 | ||
41 | bool lttng_credentials_is_equal_gid(const struct lttng_credentials *a, | |
28ab034a | 42 | const struct lttng_credentials *b) |
ff588497 | 43 | { |
a0377dfe FD |
44 | LTTNG_ASSERT(a); |
45 | LTTNG_ASSERT(b); | |
ff588497 JR |
46 | |
47 | /* XOR on the is_set value */ | |
48 | if (!!a->gid.is_set != !!b->gid.is_set) { | |
49 | return false; | |
50 | } | |
51 | ||
52 | if (!a->gid.is_set && !b->gid.is_set) { | |
53 | return true; | |
54 | } | |
55 | ||
56 | /* Both a and b are set. */ | |
57 | return a->gid.value == b->gid.value; | |
58 | } | |
59 | ||
60 | bool lttng_credentials_is_equal(const struct lttng_credentials *a, | |
28ab034a | 61 | const struct lttng_credentials *b) |
ff588497 | 62 | { |
a0377dfe FD |
63 | LTTNG_ASSERT(a); |
64 | LTTNG_ASSERT(b); | |
ff588497 | 65 | |
28ab034a | 66 | return lttng_credentials_is_equal_uid(a, b) && lttng_credentials_is_equal_gid(a, b); |
ff588497 | 67 | } |