Force usage of assert() condition when NDEBUG is defined
[lttng-tools.git] / src / common / credentials.c
... / ...
CommitLineData
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 <stdbool.h>
9#include "credentials.h"
10
11LTTNG_HIDDEN
12uid_t lttng_credentials_get_uid(const struct lttng_credentials *creds)
13{
14 return LTTNG_OPTIONAL_GET(creds->uid);
15}
16
17LTTNG_HIDDEN
18gid_t lttng_credentials_get_gid(const struct lttng_credentials *creds)
19{
20 return LTTNG_OPTIONAL_GET(creds->gid);
21}
22
23LTTNG_HIDDEN
24bool lttng_credentials_is_equal_uid(const struct lttng_credentials *a,
25 const struct lttng_credentials *b)
26{
27 LTTNG_ASSERT(a);
28 LTTNG_ASSERT(b);
29
30 /* XOR on the is_set value */
31 if (!!a->uid.is_set != !!b->uid.is_set) {
32 return false;
33 }
34
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
43LTTNG_HIDDEN
44bool lttng_credentials_is_equal_gid(const struct lttng_credentials *a,
45 const struct lttng_credentials *b)
46{
47 LTTNG_ASSERT(a);
48 LTTNG_ASSERT(b);
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
63LTTNG_HIDDEN
64bool lttng_credentials_is_equal(const struct lttng_credentials *a,
65 const struct lttng_credentials *b)
66{
67 LTTNG_ASSERT(a);
68 LTTNG_ASSERT(b);
69
70 return lttng_credentials_is_equal_uid(a, b) &&
71 lttng_credentials_is_equal_gid(a, b);
72}
This page took 0.022308 seconds and 4 git commands to generate.