1*2d543d20SAndroid Build Coastguard Worker /*
2*2d543d20SAndroid Build Coastguard Worker * Authors: Jan Zarsky <[email protected]>
3*2d543d20SAndroid Build Coastguard Worker *
4*2d543d20SAndroid Build Coastguard Worker * Copyright (C) 2019 Red Hat, Inc.
5*2d543d20SAndroid Build Coastguard Worker *
6*2d543d20SAndroid Build Coastguard Worker * This library is free software; you can redistribute it and/or
7*2d543d20SAndroid Build Coastguard Worker * modify it under the terms of the GNU Lesser General Public
8*2d543d20SAndroid Build Coastguard Worker * License as published by the Free Software Foundation; either
9*2d543d20SAndroid Build Coastguard Worker * version 2.1 of the License, or (at your option) any later version.
10*2d543d20SAndroid Build Coastguard Worker *
11*2d543d20SAndroid Build Coastguard Worker * This library is distributed in the hope that it will be useful,
12*2d543d20SAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*2d543d20SAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14*2d543d20SAndroid Build Coastguard Worker * Lesser General Public License for more details.
15*2d543d20SAndroid Build Coastguard Worker *
16*2d543d20SAndroid Build Coastguard Worker * You should have received a copy of the GNU Lesser General Public
17*2d543d20SAndroid Build Coastguard Worker * License along with this library; if not, write to the Free Software
18*2d543d20SAndroid Build Coastguard Worker * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19*2d543d20SAndroid Build Coastguard Worker */
20*2d543d20SAndroid Build Coastguard Worker
21*2d543d20SAndroid Build Coastguard Worker #include "utilities.h"
22*2d543d20SAndroid Build Coastguard Worker #include "test_handle.h"
23*2d543d20SAndroid Build Coastguard Worker
24*2d543d20SAndroid Build Coastguard Worker static void test_handle_create(void);
25*2d543d20SAndroid Build Coastguard Worker static void test_connect(void);
26*2d543d20SAndroid Build Coastguard Worker static void test_disconnect(void);
27*2d543d20SAndroid Build Coastguard Worker static void test_transaction(void);
28*2d543d20SAndroid Build Coastguard Worker static void test_commit(void);
29*2d543d20SAndroid Build Coastguard Worker static void test_is_connected(void);
30*2d543d20SAndroid Build Coastguard Worker static void test_access_check(void);
31*2d543d20SAndroid Build Coastguard Worker static void test_is_managed(void);
32*2d543d20SAndroid Build Coastguard Worker static void test_mls_enabled(void);
33*2d543d20SAndroid Build Coastguard Worker static void test_msg_set_callback(void);
34*2d543d20SAndroid Build Coastguard Worker static void test_root(void);
35*2d543d20SAndroid Build Coastguard Worker static void test_select_store(void);
36*2d543d20SAndroid Build Coastguard Worker
37*2d543d20SAndroid Build Coastguard Worker extern semanage_handle_t *sh;
38*2d543d20SAndroid Build Coastguard Worker
handle_test_init(void)39*2d543d20SAndroid Build Coastguard Worker int handle_test_init(void)
40*2d543d20SAndroid Build Coastguard Worker {
41*2d543d20SAndroid Build Coastguard Worker if (create_test_store() < 0) {
42*2d543d20SAndroid Build Coastguard Worker fprintf(stderr, "Could not create test store\n");
43*2d543d20SAndroid Build Coastguard Worker return 1;
44*2d543d20SAndroid Build Coastguard Worker }
45*2d543d20SAndroid Build Coastguard Worker
46*2d543d20SAndroid Build Coastguard Worker if (write_test_policy_from_file("test_handle.policy") < 0) {
47*2d543d20SAndroid Build Coastguard Worker fprintf(stderr, "Could not write test policy\n");
48*2d543d20SAndroid Build Coastguard Worker return 1;
49*2d543d20SAndroid Build Coastguard Worker }
50*2d543d20SAndroid Build Coastguard Worker
51*2d543d20SAndroid Build Coastguard Worker return 0;
52*2d543d20SAndroid Build Coastguard Worker }
53*2d543d20SAndroid Build Coastguard Worker
handle_test_cleanup(void)54*2d543d20SAndroid Build Coastguard Worker int handle_test_cleanup(void)
55*2d543d20SAndroid Build Coastguard Worker {
56*2d543d20SAndroid Build Coastguard Worker if (destroy_test_store() < 0) {
57*2d543d20SAndroid Build Coastguard Worker fprintf(stderr, "Could not destroy test store\n");
58*2d543d20SAndroid Build Coastguard Worker return 1;
59*2d543d20SAndroid Build Coastguard Worker }
60*2d543d20SAndroid Build Coastguard Worker
61*2d543d20SAndroid Build Coastguard Worker return 0;
62*2d543d20SAndroid Build Coastguard Worker }
63*2d543d20SAndroid Build Coastguard Worker
handle_add_tests(CU_pSuite suite)64*2d543d20SAndroid Build Coastguard Worker int handle_add_tests(CU_pSuite suite)
65*2d543d20SAndroid Build Coastguard Worker {
66*2d543d20SAndroid Build Coastguard Worker CU_add_test(suite, "test_handle_create", test_handle_create);
67*2d543d20SAndroid Build Coastguard Worker CU_add_test(suite, "test_connect", test_connect);
68*2d543d20SAndroid Build Coastguard Worker CU_add_test(suite, "test_disconnect", test_disconnect);
69*2d543d20SAndroid Build Coastguard Worker CU_add_test(suite, "test_transaction", test_transaction);
70*2d543d20SAndroid Build Coastguard Worker CU_add_test(suite, "test_commit", test_commit);
71*2d543d20SAndroid Build Coastguard Worker CU_add_test(suite, "test_is_connected", test_is_connected);
72*2d543d20SAndroid Build Coastguard Worker CU_add_test(suite, "test_access_check", test_access_check);
73*2d543d20SAndroid Build Coastguard Worker CU_add_test(suite, "test_is_managed", test_is_managed);
74*2d543d20SAndroid Build Coastguard Worker CU_add_test(suite, "test_mls_enabled", test_mls_enabled);
75*2d543d20SAndroid Build Coastguard Worker CU_add_test(suite, "msg_set_callback", test_msg_set_callback);
76*2d543d20SAndroid Build Coastguard Worker CU_add_test(suite, "test_root", test_root);
77*2d543d20SAndroid Build Coastguard Worker CU_add_test(suite, "test_select_store", test_select_store);
78*2d543d20SAndroid Build Coastguard Worker
79*2d543d20SAndroid Build Coastguard Worker return 0;
80*2d543d20SAndroid Build Coastguard Worker }
81*2d543d20SAndroid Build Coastguard Worker
82*2d543d20SAndroid Build Coastguard Worker /* Function semanage_handle_create */
test_handle_create(void)83*2d543d20SAndroid Build Coastguard Worker static void test_handle_create(void)
84*2d543d20SAndroid Build Coastguard Worker {
85*2d543d20SAndroid Build Coastguard Worker sh = semanage_handle_create();
86*2d543d20SAndroid Build Coastguard Worker CU_ASSERT_PTR_NOT_NULL(sh);
87*2d543d20SAndroid Build Coastguard Worker semanage_handle_destroy(sh);
88*2d543d20SAndroid Build Coastguard Worker }
89*2d543d20SAndroid Build Coastguard Worker
90*2d543d20SAndroid Build Coastguard Worker /* Function semanage_connect */
test_connect(void)91*2d543d20SAndroid Build Coastguard Worker static void test_connect(void)
92*2d543d20SAndroid Build Coastguard Worker {
93*2d543d20SAndroid Build Coastguard Worker /* test handle created */
94*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_HANDLE);
95*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_connect(sh) >= 0);
96*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_disconnect(sh) >= 0);
97*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_HANDLE);
98*2d543d20SAndroid Build Coastguard Worker
99*2d543d20SAndroid Build Coastguard Worker /* test invalid store */
100*2d543d20SAndroid Build Coastguard Worker setup_handle_invalid_store(SH_HANDLE);
101*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_connect(sh) < 0);
102*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_HANDLE);
103*2d543d20SAndroid Build Coastguard Worker
104*2d543d20SAndroid Build Coastguard Worker /* test normal use */
105*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_HANDLE);
106*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_connect(sh) >= 0);
107*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_disconnect(sh) >= 0);
108*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_HANDLE);
109*2d543d20SAndroid Build Coastguard Worker }
110*2d543d20SAndroid Build Coastguard Worker
111*2d543d20SAndroid Build Coastguard Worker /* Function semanage_disconnect */
test_disconnect(void)112*2d543d20SAndroid Build Coastguard Worker static void test_disconnect(void)
113*2d543d20SAndroid Build Coastguard Worker {
114*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_CONNECT);
115*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_disconnect(sh) >= 0);
116*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_HANDLE);
117*2d543d20SAndroid Build Coastguard Worker }
118*2d543d20SAndroid Build Coastguard Worker
119*2d543d20SAndroid Build Coastguard Worker /* Function semanage_begin_transaction */
test_transaction(void)120*2d543d20SAndroid Build Coastguard Worker static void test_transaction(void)
121*2d543d20SAndroid Build Coastguard Worker {
122*2d543d20SAndroid Build Coastguard Worker /* test disconnected */
123*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_CONNECT);
124*2d543d20SAndroid Build Coastguard Worker helper_disconnect();
125*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_begin_transaction(sh) < 0);
126*2d543d20SAndroid Build Coastguard Worker
127*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_HANDLE);
128*2d543d20SAndroid Build Coastguard Worker
129*2d543d20SAndroid Build Coastguard Worker /* test normal use */
130*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_CONNECT);
131*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_begin_transaction(sh) >= 0);
132*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_commit(sh) >= 0);
133*2d543d20SAndroid Build Coastguard Worker
134*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_CONNECT);
135*2d543d20SAndroid Build Coastguard Worker }
136*2d543d20SAndroid Build Coastguard Worker
137*2d543d20SAndroid Build Coastguard Worker /* Function semanage_commit */
test_commit(void)138*2d543d20SAndroid Build Coastguard Worker static void test_commit(void)
139*2d543d20SAndroid Build Coastguard Worker {
140*2d543d20SAndroid Build Coastguard Worker /* test without transaction */
141*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_CONNECT);
142*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_commit(sh) < 0);
143*2d543d20SAndroid Build Coastguard Worker
144*2d543d20SAndroid Build Coastguard Worker /* test with transaction */
145*2d543d20SAndroid Build Coastguard Worker helper_begin_transaction();
146*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_commit(sh) >= 0);
147*2d543d20SAndroid Build Coastguard Worker
148*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_CONNECT);
149*2d543d20SAndroid Build Coastguard Worker }
150*2d543d20SAndroid Build Coastguard Worker
151*2d543d20SAndroid Build Coastguard Worker /* Function semanage_is_connected */
test_is_connected(void)152*2d543d20SAndroid Build Coastguard Worker static void test_is_connected(void)
153*2d543d20SAndroid Build Coastguard Worker {
154*2d543d20SAndroid Build Coastguard Worker /* test disconnected */
155*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_HANDLE);
156*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_is_connected(sh) == 0);
157*2d543d20SAndroid Build Coastguard Worker
158*2d543d20SAndroid Build Coastguard Worker /* test connected */
159*2d543d20SAndroid Build Coastguard Worker helper_connect();
160*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_is_connected(sh) == 1);
161*2d543d20SAndroid Build Coastguard Worker
162*2d543d20SAndroid Build Coastguard Worker /* test in transaction */
163*2d543d20SAndroid Build Coastguard Worker helper_begin_transaction();
164*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_is_connected(sh) == 1);
165*2d543d20SAndroid Build Coastguard Worker
166*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_TRANS);
167*2d543d20SAndroid Build Coastguard Worker }
168*2d543d20SAndroid Build Coastguard Worker
169*2d543d20SAndroid Build Coastguard Worker /* Function semanage_access_check */
test_access_check(void)170*2d543d20SAndroid Build Coastguard Worker static void test_access_check(void)
171*2d543d20SAndroid Build Coastguard Worker {
172*2d543d20SAndroid Build Coastguard Worker int res = 0;
173*2d543d20SAndroid Build Coastguard Worker
174*2d543d20SAndroid Build Coastguard Worker /* test with handle */
175*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_HANDLE);
176*2d543d20SAndroid Build Coastguard Worker res = semanage_access_check(sh);
177*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(res == 0 || res == SEMANAGE_CAN_READ
178*2d543d20SAndroid Build Coastguard Worker || res == SEMANAGE_CAN_WRITE);
179*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_HANDLE);
180*2d543d20SAndroid Build Coastguard Worker
181*2d543d20SAndroid Build Coastguard Worker /* test with invalid store */
182*2d543d20SAndroid Build Coastguard Worker setup_handle_invalid_store(SH_HANDLE);
183*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_access_check(sh) < 0);
184*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_HANDLE);
185*2d543d20SAndroid Build Coastguard Worker
186*2d543d20SAndroid Build Coastguard Worker /* test connected */
187*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_CONNECT);
188*2d543d20SAndroid Build Coastguard Worker res = semanage_access_check(sh);
189*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(res == 0 || res == SEMANAGE_CAN_READ
190*2d543d20SAndroid Build Coastguard Worker || res == SEMANAGE_CAN_WRITE);
191*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_CONNECT);
192*2d543d20SAndroid Build Coastguard Worker }
193*2d543d20SAndroid Build Coastguard Worker
194*2d543d20SAndroid Build Coastguard Worker /* Function semanage_is_managed */
test_is_managed(void)195*2d543d20SAndroid Build Coastguard Worker static void test_is_managed(void)
196*2d543d20SAndroid Build Coastguard Worker {
197*2d543d20SAndroid Build Coastguard Worker int res = 0;
198*2d543d20SAndroid Build Coastguard Worker
199*2d543d20SAndroid Build Coastguard Worker /* test with handle */
200*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_HANDLE);
201*2d543d20SAndroid Build Coastguard Worker res = semanage_is_managed(sh);
202*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(res == 0 || res == 1);
203*2d543d20SAndroid Build Coastguard Worker
204*2d543d20SAndroid Build Coastguard Worker /* test connected */
205*2d543d20SAndroid Build Coastguard Worker helper_connect();
206*2d543d20SAndroid Build Coastguard Worker res = semanage_is_managed(sh);
207*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(res < 0);
208*2d543d20SAndroid Build Coastguard Worker
209*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_CONNECT);
210*2d543d20SAndroid Build Coastguard Worker }
211*2d543d20SAndroid Build Coastguard Worker
212*2d543d20SAndroid Build Coastguard Worker /* Function semanage_mls_enabled */
test_mls_enabled(void)213*2d543d20SAndroid Build Coastguard Worker static void test_mls_enabled(void)
214*2d543d20SAndroid Build Coastguard Worker {
215*2d543d20SAndroid Build Coastguard Worker int res = 0;
216*2d543d20SAndroid Build Coastguard Worker
217*2d543d20SAndroid Build Coastguard Worker /* test with handle */
218*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_HANDLE);
219*2d543d20SAndroid Build Coastguard Worker res = semanage_mls_enabled(sh);
220*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(res == 0 || res == 1);
221*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_HANDLE);
222*2d543d20SAndroid Build Coastguard Worker
223*2d543d20SAndroid Build Coastguard Worker /* test with invalid store */
224*2d543d20SAndroid Build Coastguard Worker setup_handle_invalid_store(SH_HANDLE);
225*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_mls_enabled(sh) < 0);
226*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_HANDLE);
227*2d543d20SAndroid Build Coastguard Worker
228*2d543d20SAndroid Build Coastguard Worker /* test connected */
229*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_CONNECT);
230*2d543d20SAndroid Build Coastguard Worker res = semanage_mls_enabled(sh);
231*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(res == 0 || res == 1);
232*2d543d20SAndroid Build Coastguard Worker
233*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_CONNECT);
234*2d543d20SAndroid Build Coastguard Worker }
235*2d543d20SAndroid Build Coastguard Worker
236*2d543d20SAndroid Build Coastguard Worker /* Function semanage_set_callback */
237*2d543d20SAndroid Build Coastguard Worker int msg_set_callback_count = 0;
238*2d543d20SAndroid Build Coastguard Worker
helper_msg_set_callback(void * varg,semanage_handle_t * handle,const char * fmt,...)239*2d543d20SAndroid Build Coastguard Worker static void helper_msg_set_callback(void *varg, semanage_handle_t *handle,
240*2d543d20SAndroid Build Coastguard Worker const char *fmt, ...)
241*2d543d20SAndroid Build Coastguard Worker {
242*2d543d20SAndroid Build Coastguard Worker msg_set_callback_count++;
243*2d543d20SAndroid Build Coastguard Worker }
244*2d543d20SAndroid Build Coastguard Worker
test_msg_set_callback(void)245*2d543d20SAndroid Build Coastguard Worker static void test_msg_set_callback(void)
246*2d543d20SAndroid Build Coastguard Worker {
247*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_CONNECT);
248*2d543d20SAndroid Build Coastguard Worker
249*2d543d20SAndroid Build Coastguard Worker semanage_msg_set_callback(sh, helper_msg_set_callback, NULL);
250*2d543d20SAndroid Build Coastguard Worker
251*2d543d20SAndroid Build Coastguard Worker /* produce error message */
252*2d543d20SAndroid Build Coastguard Worker semanage_commit(sh);
253*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(msg_set_callback_count == 1);
254*2d543d20SAndroid Build Coastguard Worker semanage_msg_set_callback(sh, NULL, NULL);
255*2d543d20SAndroid Build Coastguard Worker
256*2d543d20SAndroid Build Coastguard Worker /* produce error message */
257*2d543d20SAndroid Build Coastguard Worker semanage_commit(sh);
258*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(msg_set_callback_count == 1);
259*2d543d20SAndroid Build Coastguard Worker
260*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_CONNECT);
261*2d543d20SAndroid Build Coastguard Worker }
262*2d543d20SAndroid Build Coastguard Worker
263*2d543d20SAndroid Build Coastguard Worker /* Function semanage_root, semanage_set_root */
helper_root(void)264*2d543d20SAndroid Build Coastguard Worker static void helper_root(void)
265*2d543d20SAndroid Build Coastguard Worker {
266*2d543d20SAndroid Build Coastguard Worker const char *root = NULL;
267*2d543d20SAndroid Build Coastguard Worker
268*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_set_root("asdf") >= 0);
269*2d543d20SAndroid Build Coastguard Worker root = semanage_root();
270*2d543d20SAndroid Build Coastguard Worker CU_ASSERT_STRING_EQUAL(root, "asdf");
271*2d543d20SAndroid Build Coastguard Worker
272*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(semanage_set_root("") >= 0);
273*2d543d20SAndroid Build Coastguard Worker root = semanage_root();
274*2d543d20SAndroid Build Coastguard Worker CU_ASSERT_STRING_EQUAL(root, "");
275*2d543d20SAndroid Build Coastguard Worker }
276*2d543d20SAndroid Build Coastguard Worker
test_root(void)277*2d543d20SAndroid Build Coastguard Worker static void test_root(void)
278*2d543d20SAndroid Build Coastguard Worker {
279*2d543d20SAndroid Build Coastguard Worker /* test without handle */
280*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_NULL);
281*2d543d20SAndroid Build Coastguard Worker helper_root();
282*2d543d20SAndroid Build Coastguard Worker
283*2d543d20SAndroid Build Coastguard Worker /* test with handle */
284*2d543d20SAndroid Build Coastguard Worker helper_handle_create();
285*2d543d20SAndroid Build Coastguard Worker helper_root();
286*2d543d20SAndroid Build Coastguard Worker
287*2d543d20SAndroid Build Coastguard Worker /* test connected */
288*2d543d20SAndroid Build Coastguard Worker helper_connect();
289*2d543d20SAndroid Build Coastguard Worker helper_root();
290*2d543d20SAndroid Build Coastguard Worker
291*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_CONNECT);
292*2d543d20SAndroid Build Coastguard Worker }
293*2d543d20SAndroid Build Coastguard Worker
294*2d543d20SAndroid Build Coastguard Worker /* Function semanage_select_store */
helper_select_store(const char * name,enum semanage_connect_type type,int exp_res)295*2d543d20SAndroid Build Coastguard Worker static void helper_select_store(const char *name, enum semanage_connect_type type,
296*2d543d20SAndroid Build Coastguard Worker int exp_res)
297*2d543d20SAndroid Build Coastguard Worker {
298*2d543d20SAndroid Build Coastguard Worker setup_handle(SH_HANDLE);
299*2d543d20SAndroid Build Coastguard Worker
300*2d543d20SAndroid Build Coastguard Worker /* FIXME: the storename parameter of semanage_select_store should be
301*2d543d20SAndroid Build Coastguard Worker * 'const char *'
302*2d543d20SAndroid Build Coastguard Worker */
303*2d543d20SAndroid Build Coastguard Worker semanage_select_store(sh, (char *) name, type);
304*2d543d20SAndroid Build Coastguard Worker
305*2d543d20SAndroid Build Coastguard Worker int res = semanage_connect(sh);
306*2d543d20SAndroid Build Coastguard Worker
307*2d543d20SAndroid Build Coastguard Worker if (exp_res < 0) {
308*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(res < 0);
309*2d543d20SAndroid Build Coastguard Worker } else {
310*2d543d20SAndroid Build Coastguard Worker CU_ASSERT(res >= 0);
311*2d543d20SAndroid Build Coastguard Worker }
312*2d543d20SAndroid Build Coastguard Worker
313*2d543d20SAndroid Build Coastguard Worker if (res >= 0)
314*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_CONNECT);
315*2d543d20SAndroid Build Coastguard Worker else
316*2d543d20SAndroid Build Coastguard Worker cleanup_handle(SH_HANDLE);
317*2d543d20SAndroid Build Coastguard Worker }
318*2d543d20SAndroid Build Coastguard Worker
test_select_store(void)319*2d543d20SAndroid Build Coastguard Worker static void test_select_store(void)
320*2d543d20SAndroid Build Coastguard Worker {
321*2d543d20SAndroid Build Coastguard Worker helper_select_store("asdf", SEMANAGE_CON_INVALID - 1, -1);
322*2d543d20SAndroid Build Coastguard Worker helper_select_store("asdf", SEMANAGE_CON_POLSERV_REMOTE + 1, -1);
323*2d543d20SAndroid Build Coastguard Worker helper_select_store("", SEMANAGE_CON_DIRECT, 0);
324*2d543d20SAndroid Build Coastguard Worker
325*2d543d20SAndroid Build Coastguard Worker helper_select_store("asdf", SEMANAGE_CON_INVALID, -1);
326*2d543d20SAndroid Build Coastguard Worker helper_select_store("asdf", SEMANAGE_CON_DIRECT, 0);
327*2d543d20SAndroid Build Coastguard Worker helper_select_store("asdf", SEMANAGE_CON_POLSERV_LOCAL, -1);
328*2d543d20SAndroid Build Coastguard Worker helper_select_store("asdf", SEMANAGE_CON_POLSERV_REMOTE, -1);
329*2d543d20SAndroid Build Coastguard Worker }
330