589ffabc26f1ea7ac965ba70f702853fd3cfc2ee
[lttng-tools.git] / src / common / credentials.c
1 /*
2 * Copyright (C) 2020 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #include <assert.h>
9 #include <stdbool.h>
10 #include "credentials.h"
11
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,
23 const struct lttng_credentials *b)
24 {
25 assert(a);
26 assert(b);
27
28 /* XOR on the is_set value */
29 if (!!a->uid.is_set != !!b->uid.is_set) {
30 return false;
31 }
32
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,
42 const struct lttng_credentials *b)
43 {
44 assert(a);
45 assert(b);
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,
61 const struct lttng_credentials *b)
62 {
63 assert(a);
64 assert(b);
65
66 return lttng_credentials_is_equal_uid(a, b) &&
67 lttng_credentials_is_equal_gid(a, b);
68 }
This page took 0.030163 seconds and 3 git commands to generate.