Fix: validate that array expression contains constant
[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 LTTNG_HIDDEN
13 uid_t lttng_credentials_get_uid(const struct lttng_credentials *creds)
14 {
15 return LTTNG_OPTIONAL_GET(creds->uid);
16 }
17
18 LTTNG_HIDDEN
19 gid_t lttng_credentials_get_gid(const struct lttng_credentials *creds)
20 {
21 return LTTNG_OPTIONAL_GET(creds->gid);
22 }
23
24 LTTNG_HIDDEN
25 bool lttng_credentials_is_equal_uid(const struct lttng_credentials *a,
26 const struct lttng_credentials *b)
27 {
28 assert(a);
29 assert(b);
30
31 /* XOR on the is_set value */
32 if (!!a->uid.is_set != !!b->uid.is_set) {
33 return false;
34 }
35
36 if (!a->uid.is_set && !b->uid.is_set) {
37 return true;
38 }
39
40 /* Both a and b are set. */
41 return a->uid.value == b->uid.value;
42 }
43
44 LTTNG_HIDDEN
45 bool lttng_credentials_is_equal_gid(const struct lttng_credentials *a,
46 const struct lttng_credentials *b)
47 {
48 assert(a);
49 assert(b);
50
51 /* XOR on the is_set value */
52 if (!!a->gid.is_set != !!b->gid.is_set) {
53 return false;
54 }
55
56 if (!a->gid.is_set && !b->gid.is_set) {
57 return true;
58 }
59
60 /* Both a and b are set. */
61 return a->gid.value == b->gid.value;
62 }
63
64 LTTNG_HIDDEN
65 bool lttng_credentials_is_equal(const struct lttng_credentials *a,
66 const struct lttng_credentials *b)
67 {
68 assert(a);
69 assert(b);
70
71 return lttng_credentials_is_equal_uid(a, b) &&
72 lttng_credentials_is_equal_gid(a, b);
73 }
This page took 0.030038 seconds and 4 git commands to generate.