Force usage of assert() condition when NDEBUG is defined
[lttng-tools.git] / src / common / credentials.c
CommitLineData
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 11LTTNG_HIDDEN
ff588497
JR
12uid_t lttng_credentials_get_uid(const struct lttng_credentials *creds)
13{
14 return LTTNG_OPTIONAL_GET(creds->uid);
15}
16
84e46494 17LTTNG_HIDDEN
ff588497
JR
18gid_t lttng_credentials_get_gid(const struct lttng_credentials *creds)
19{
20 return LTTNG_OPTIONAL_GET(creds->gid);
21}
22
84e46494 23LTTNG_HIDDEN
ff588497 24bool 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 43LTTNG_HIDDEN
ff588497
JR
44bool 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 63LTTNG_HIDDEN
ff588497
JR
64bool 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}
This page took 0.028781 seconds and 4 git commands to generate.