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