liblttng-ctl: use export list to define exported symbols
[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
ff588497
JR
11uid_t lttng_credentials_get_uid(const struct lttng_credentials *creds)
12{
13 return LTTNG_OPTIONAL_GET(creds->uid);
14}
15
16gid_t lttng_credentials_get_gid(const struct lttng_credentials *creds)
17{
18 return LTTNG_OPTIONAL_GET(creds->gid);
19}
20
21bool lttng_credentials_is_equal_uid(const struct lttng_credentials *a,
894e6e1c
JR
22 const struct lttng_credentials *b)
23{
a0377dfe
FD
24 LTTNG_ASSERT(a);
25 LTTNG_ASSERT(b);
894e6e1c 26
ff588497
JR
27 /* XOR on the is_set value */
28 if (!!a->uid.is_set != !!b->uid.is_set) {
894e6e1c
JR
29 return false;
30 }
31
ff588497
JR
32 if (!a->uid.is_set && !b->uid.is_set) {
33 return true;
34 }
35
36 /* Both a and b are set. */
37 return a->uid.value == b->uid.value;
38}
39
40bool lttng_credentials_is_equal_gid(const struct lttng_credentials *a,
41 const struct lttng_credentials *b)
42{
a0377dfe
FD
43 LTTNG_ASSERT(a);
44 LTTNG_ASSERT(b);
ff588497
JR
45
46 /* XOR on the is_set value */
47 if (!!a->gid.is_set != !!b->gid.is_set) {
48 return false;
49 }
50
51 if (!a->gid.is_set && !b->gid.is_set) {
52 return true;
53 }
54
55 /* Both a and b are set. */
56 return a->gid.value == b->gid.value;
57}
58
59bool lttng_credentials_is_equal(const struct lttng_credentials *a,
60 const struct lttng_credentials *b)
61{
a0377dfe
FD
62 LTTNG_ASSERT(a);
63 LTTNG_ASSERT(b);
ff588497
JR
64
65 return lttng_credentials_is_equal_uid(a, b) &&
66 lttng_credentials_is_equal_gid(a, b);
67}
This page took 0.028816 seconds and 4 git commands to generate.