]>
Commit | Line | Data |
---|---|---|
52ad194e | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
5eef597e MP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2014 Lennart Poettering | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
21 | #include <stddef.h> | |
22 | ||
db2df898 | 23 | #include "alloc-util.h" |
5eef597e | 24 | #include "uid-range.h" |
db2df898 MP |
25 | #include "user-util.h" |
26 | #include "util.h" | |
5eef597e MP |
27 | |
28 | int main(int argc, char *argv[]) { | |
29 | _cleanup_free_ UidRange *p = NULL; | |
30 | unsigned n = 0; | |
31 | uid_t search; | |
32 | ||
33 | assert_se(uid_range_add_str(&p, &n, "500-999") >= 0); | |
34 | assert_se(n == 1); | |
35 | assert_se(p[0].start == 500); | |
36 | assert_se(p[0].nr == 500); | |
37 | ||
38 | assert_se(!uid_range_contains(p, n, 499)); | |
39 | assert_se(uid_range_contains(p, n, 500)); | |
40 | assert_se(uid_range_contains(p, n, 999)); | |
41 | assert_se(!uid_range_contains(p, n, 1000)); | |
42 | ||
f47781d8 | 43 | search = UID_INVALID; |
5eef597e MP |
44 | assert_se(uid_range_next_lower(p, n, &search)); |
45 | assert_se(search == 999); | |
46 | assert_se(uid_range_next_lower(p, n, &search)); | |
47 | assert_se(search == 998); | |
48 | search = 501; | |
49 | assert_se(uid_range_next_lower(p, n, &search)); | |
50 | assert_se(search == 500); | |
51 | assert_se(uid_range_next_lower(p, n, &search) == -EBUSY); | |
52 | ||
53 | assert_se(uid_range_add_str(&p, &n, "1000") >= 0); | |
54 | assert_se(n == 1); | |
55 | assert_se(p[0].start == 500); | |
56 | assert_se(p[0].nr == 501); | |
57 | ||
58 | assert_se(uid_range_add_str(&p, &n, "30-40") >= 0); | |
59 | assert_se(n == 2); | |
60 | assert_se(p[0].start == 30); | |
61 | assert_se(p[0].nr == 11); | |
62 | assert_se(p[1].start == 500); | |
63 | assert_se(p[1].nr == 501); | |
64 | ||
65 | assert_se(uid_range_add_str(&p, &n, "60-70") >= 0); | |
66 | assert_se(n == 3); | |
67 | assert_se(p[0].start == 30); | |
68 | assert_se(p[0].nr == 11); | |
69 | assert_se(p[1].start == 60); | |
70 | assert_se(p[1].nr == 11); | |
71 | assert_se(p[2].start == 500); | |
72 | assert_se(p[2].nr == 501); | |
73 | ||
74 | assert_se(uid_range_add_str(&p, &n, "20-2000") >= 0); | |
75 | assert_se(n == 1); | |
76 | assert_se(p[0].start == 20); | |
77 | assert_se(p[0].nr == 1981); | |
78 | ||
79 | assert_se(uid_range_add_str(&p, &n, "2002") >= 0); | |
80 | assert_se(n == 2); | |
81 | assert_se(p[0].start == 20); | |
82 | assert_se(p[0].nr == 1981); | |
83 | assert_se(p[1].start == 2002); | |
84 | assert_se(p[1].nr == 1); | |
85 | ||
86 | assert_se(uid_range_add_str(&p, &n, "2001") >= 0); | |
87 | assert_se(n == 1); | |
88 | assert_se(p[0].start == 20); | |
89 | assert_se(p[0].nr == 1983); | |
90 | ||
91 | return 0; | |
92 | } |