Add condition-targeting error query
[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
8#include <assert.h>
9#include <stdbool.h>
10#include "credentials.h"
11
84e46494 12LTTNG_HIDDEN
ff588497
JR
13uid_t lttng_credentials_get_uid(const struct lttng_credentials *creds)
14{
15 return LTTNG_OPTIONAL_GET(creds->uid);
16}
17
84e46494 18LTTNG_HIDDEN
ff588497
JR
19gid_t lttng_credentials_get_gid(const struct lttng_credentials *creds)
20{
21 return LTTNG_OPTIONAL_GET(creds->gid);
22}
23
84e46494 24LTTNG_HIDDEN
ff588497 25bool lttng_credentials_is_equal_uid(const struct lttng_credentials *a,
894e6e1c
JR
26 const struct lttng_credentials *b)
27{
28 assert(a);
29 assert(b);
30
ff588497
JR
31 /* XOR on the is_set value */
32 if (!!a->uid.is_set != !!b->uid.is_set) {
894e6e1c
JR
33 return false;
34 }
35
ff588497
JR
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
84e46494 44LTTNG_HIDDEN
ff588497
JR
45bool 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
84e46494 64LTTNG_HIDDEN
ff588497
JR
65bool 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.031645 seconds and 4 git commands to generate.