SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[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
2463b787
JR
12uid_t lttng_credentials_get_uid(const struct lttng_credentials *creds)
13{
14 return LTTNG_OPTIONAL_GET(creds->uid);
15}
16
17gid_t lttng_credentials_get_gid(const struct lttng_credentials *creds)
18{
19 return LTTNG_OPTIONAL_GET(creds->gid);
20}
21
22bool lttng_credentials_is_equal_uid(const struct lttng_credentials *a,
894e6e1c
JR
23 const struct lttng_credentials *b)
24{
25 assert(a);
26 assert(b);
27
2463b787
JR
28 /* XOR on the is_set value */
29 if (!!a->uid.is_set != !!b->uid.is_set) {
894e6e1c
JR
30 return false;
31 }
32
2463b787
JR
33 if (!a->uid.is_set && !b->uid.is_set) {
34 return true;
35 }
36
37 /* Both a and b are set. */
38 return a->uid.value == b->uid.value;
39}
40
41bool lttng_credentials_is_equal_gid(const struct lttng_credentials *a,
42 const struct lttng_credentials *b)
43{
44 assert(a);
45 assert(b);
46
47 /* XOR on the is_set value */
48 if (!!a->gid.is_set != !!b->gid.is_set) {
49 return false;
50 }
51
52 if (!a->gid.is_set && !b->gid.is_set) {
53 return true;
54 }
55
56 /* Both a and b are set. */
57 return a->gid.value == b->gid.value;
58}
59
60bool lttng_credentials_is_equal(const struct lttng_credentials *a,
61 const struct lttng_credentials *b)
62{
63 assert(a);
64 assert(b);
65
66 return lttng_credentials_is_equal_uid(a, b) &&
67 lttng_credentials_is_equal_gid(a, b);
68}
This page took 0.036709 seconds and 5 git commands to generate.