tests: Expected failures in reparse point tests should not be errors
[Samba.git] / source3 / torture / test_idmap_cache.c
blobb9cba3b4a53bd3fa6aba4a3a278a3a0fe7ba7e1a
1 /*
2 * Unix SMB/CIFS implementation.
3 * Test dbwrap_watch API
4 * Copyright (C) Volker Lendecke 2017
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "torture/proto.h"
22 #include "lib/idmap_cache.h"
23 #include "librpc/gen_ndr/idmap.h"
24 #include "libcli/security/dom_sid.h"
26 bool run_local_idmap_cache1(int dummy)
28 struct dom_sid sid, found_sid;
29 struct unixid xid, found_xid;
30 bool ret = false;
31 bool expired = false;
33 xid = (struct unixid) { .id = 1234, .type = ID_TYPE_UID };
34 dom_sid_parse("S-1-5-21-2864185242-3846410404-2398417794-1235", &sid);
35 idmap_cache_set_sid2unixid(&sid, &xid);
37 ret = idmap_cache_find_sid2unixid(&sid, &found_xid, &expired);
38 if (!ret) {
39 fprintf(stderr, "idmap_cache_find_sid2unixid failed\n");
40 goto done;
42 if (expired) {
43 fprintf(stderr,
44 "idmap_cache_find_sid2unixid returned an expired "
45 "value\n");
46 goto done;
48 if ((xid.type != found_xid.type) || (xid.id != found_xid.id)) {
49 fprintf(stderr,
50 "idmap_cache_find_sid2unixid returned wrong "
51 "values\n");
52 goto done;
55 ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
56 if (!ret) {
57 fprintf(stderr, "idmap_cache_find_xid2sid failed\n");
58 goto done;
60 if (expired) {
61 fprintf(stderr,
62 "idmap_cache_find_xid2sid returned an expired "
63 "value\n");
64 goto done;
66 if (!dom_sid_equal(&sid, &found_sid)) {
67 fprintf(stderr,
68 "idmap_cache_find_xid2sid returned wrong sid\n");
69 goto done;
72 xid.type = ID_TYPE_GID;
74 ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
75 if (ret) {
76 fprintf(stderr,
77 "idmap_cache_find_xid2sid found a GID where it "
78 "should not\n");
79 goto done;
82 idmap_cache_del_sid(&sid);
84 xid.type = ID_TYPE_UID;
85 ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
86 if (ret) {
87 fprintf(stderr,
88 "idmap_cache_find_xid2sid found a UID where it "
89 "should not\n");
90 goto done;
94 * Test that negative mappings can also be cached
96 sid = (struct dom_sid) {0};
97 xid = (struct unixid) { .id = 1234, .type = ID_TYPE_UID };
98 idmap_cache_set_sid2unixid(&sid, &xid);
100 ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
101 if (!ret) {
102 fprintf(stderr,
103 "idmap_cache_find_xid2sid failed to find "
104 "negative mapping\n");
105 goto done;
107 if (expired) {
108 fprintf(stderr,
109 "idmap_cache_find_xid2sid returned an expired "
110 "value\n");
111 goto done;
113 if (!dom_sid_equal(&sid, &found_sid)) {
114 fprintf(stderr,
115 "idmap_cache_find_xid2sid returned wrong sid\n");
116 goto done;
119 ret = true;
120 done:
121 return ret;