forked from urbanserj/entente
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ranges.h
43 lines (37 loc) · 1.34 KB
/
ranges.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/** \file range.h
* Utilities for storing and matching against uid/gid ranges.
*
* \copyright Copyright (c) 2017 Donovan Baarda <[email protected]>
*
* \licence Licensed under the GPLv3 License. See LICENSE file for details. */
#ifndef RANGE_H
#define RANGE_H
#include <stdbool.h>
#include <sys/types.h>
#define RANGES_SIZE 32
/** The simple range class. */
typedef struct {
uid_t beg; /**< The first value of the range. */
uid_t end; /**< The last value of the range. */
} ldap_range;
int ldap_range_init(ldap_range *r, const char *s);
static inline bool ldap_range_ismatch(const ldap_range *r, const uid_t id);
/** The sequence of ranges class. */
typedef struct {
int count; /**< The number of ranges. */
ldap_range range[RANGES_SIZE]; /**< The ranges. */
} ldap_ranges;
int ldap_ranges_init(ldap_ranges *r, const char *s);
static inline bool ldap_ranges_ismatch(const ldap_ranges *r, const uid_t id);
static inline bool ldap_range_ismatch(const ldap_range *r, const uid_t id)
{
return r->beg <= id && id <= r->end;
}
static inline bool ldap_ranges_ismatch(const ldap_ranges *r, const uid_t id)
{
for (int i = 0; i < r->count; i++)
if (ldap_range_ismatch(&r->range[i], id))
return true;
return false;
}
#endif /* RANGE_H */