Line data Source code
1 : /*
2 : * Unix SMB/CIFS implementation.
3 : * Test dbwrap_watch API
4 : * Copyright (C) Volker Lendecke 2017
5 : *
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.
10 : *
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.
15 : *
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/>.
18 : */
19 :
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"
25 :
26 0 : bool run_local_idmap_cache1(int dummy)
27 : {
28 : struct dom_sid sid, found_sid;
29 : struct unixid xid, found_xid;
30 0 : bool ret = false;
31 0 : bool expired = false;
32 :
33 0 : xid = (struct unixid) { .id = 1234, .type = ID_TYPE_UID };
34 0 : dom_sid_parse("S-1-5-21-2864185242-3846410404-2398417794-1235", &sid);
35 0 : idmap_cache_set_sid2unixid(&sid, &xid);
36 :
37 0 : ret = idmap_cache_find_sid2unixid(&sid, &found_xid, &expired);
38 0 : if (!ret) {
39 0 : fprintf(stderr, "idmap_cache_find_sid2unixid failed\n");
40 0 : goto done;
41 : }
42 0 : if (expired) {
43 0 : fprintf(stderr,
44 : "idmap_cache_find_sid2unixid returned an expired "
45 : "value\n");
46 0 : goto done;
47 : }
48 0 : if ((xid.type != found_xid.type) || (xid.id != found_xid.id)) {
49 0 : fprintf(stderr,
50 : "idmap_cache_find_sid2unixid returned wrong "
51 : "values\n");
52 0 : goto done;
53 : }
54 :
55 0 : ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
56 0 : if (!ret) {
57 0 : fprintf(stderr, "idmap_cache_find_xid2sid failed\n");
58 0 : goto done;
59 : }
60 0 : if (expired) {
61 0 : fprintf(stderr,
62 : "idmap_cache_find_xid2sid returned an expired "
63 : "value\n");
64 0 : goto done;
65 : }
66 0 : if (!dom_sid_equal(&sid, &found_sid)) {
67 0 : fprintf(stderr,
68 : "idmap_cache_find_xid2sid returned wrong sid\n");
69 0 : goto done;
70 : }
71 :
72 0 : xid.type = ID_TYPE_GID;
73 :
74 0 : ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
75 0 : if (ret) {
76 0 : fprintf(stderr,
77 : "idmap_cache_find_xid2sid found a GID where it "
78 : "should not\n");
79 0 : goto done;
80 : }
81 :
82 0 : idmap_cache_del_sid(&sid);
83 :
84 0 : xid.type = ID_TYPE_UID;
85 0 : ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
86 0 : if (ret) {
87 0 : fprintf(stderr,
88 : "idmap_cache_find_xid2sid found a UID where it "
89 : "should not\n");
90 0 : goto done;
91 : }
92 :
93 : /*
94 : * Test that negative mappings can also be cached
95 : */
96 0 : sid = (struct dom_sid) {0};
97 0 : xid = (struct unixid) { .id = 1234, .type = ID_TYPE_UID };
98 0 : idmap_cache_set_sid2unixid(&sid, &xid);
99 :
100 0 : ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
101 0 : if (!ret) {
102 0 : fprintf(stderr,
103 : "idmap_cache_find_xid2sid failed to find "
104 : "negative mapping\n");
105 0 : goto done;
106 : }
107 0 : if (expired) {
108 0 : fprintf(stderr,
109 : "idmap_cache_find_xid2sid returned an expired "
110 : "value\n");
111 0 : goto done;
112 : }
113 0 : if (!dom_sid_equal(&sid, &found_sid)) {
114 0 : fprintf(stderr,
115 : "idmap_cache_find_xid2sid returned wrong sid\n");
116 0 : goto done;
117 : }
118 :
119 0 : ret = true;
120 0 : done:
121 0 : return ret;
122 : }
|