• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Author: Spencer Shimko <sshimko@tresys.com>
2  *
3  * Copyright (C) 2004-2005 Tresys Technology, LLC
4  * Copyright (C) 2006 Red Hat, Inc
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2.1 of the License, or (at your option) any later version.
10  *
11  *  This library 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 GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20 
21 /** standard typemaps **/
22 
23 %header %{
24 	#include <stdlib.h>
25 	#include <semanage/semanage.h>
26 	#include <sys/mman.h>
27 
28 	#define STATUS_SUCCESS 0
29 	#define STATUS_ERR -1
30 %}
31 
32 %include "stdint.i"
33 %ignore semanage_module_install_pp;
34 %ignore semanage_module_install_hll;
35 
36 %wrapper %{
37 
38 
39 	/* There are two ways to call this function:
40 	 * One is with a valid swig_type and destructor.
41 	 * Two is with a NULL swig_type and NULL destructor.
42 	 *
43 	 * In the first mode, the function converts
44 	 * an array of *cloned* objects [of the given pointer swig type]
45 	 * into a PyList, and destroys the array in the process
46 	 * (the objects pointers are preserved).
47 	 *
48 	 * In the second mode, the function converts
49 	 * an array of *constant* strings into a PyList, and destroys
50 	 * the array in the process
51 	 * (the strings are copied, originals not freed). */
52 
semanage_array2plist(semanage_handle_t * handle,void ** arr,unsigned int asize,swig_type_info * swig_type,void (* destructor)(void *),PyObject ** result)53 	static int semanage_array2plist(
54 		semanage_handle_t* handle,
55 		void** arr,
56 		unsigned int asize,
57 		swig_type_info* swig_type,
58 		void (*destructor) (void*),
59 		PyObject** result) {
60 
61 		PyObject* plist = PyList_New(0);
62 		unsigned int i;
63 
64 		if (!plist)
65 			goto err;
66 
67 		for (i = 0; i < asize; i++)  {
68 
69 			PyObject* obj = NULL;
70 
71 			/* NULL indicates string conversion,
72 			 * otherwise create an opaque pointer */
73 			if (!swig_type)
74 				obj = SWIG_FromCharPtr(arr[i]);
75 			else
76 				obj = SWIG_NewPointerObj(arr[i], swig_type, 0);
77 
78 			if (!obj)
79 				goto err;
80 
81 			if (PyList_Append(plist, obj) < 0)
82 				goto err;
83 		}
84 
85 		free(arr);
86 
87 		*result = plist;
88 		return STATUS_SUCCESS;
89 
90 		err:
91 		for (i = 0; i < asize; i++)
92 			if (destructor)
93 				destructor(arr[i]);
94 		free(arr);
95 		return STATUS_ERR;
96 	}
97 %}
98 /* a few helpful typemaps are available in this library */
99 %include <typemaps.i>
100 /* wrap all int*'s so they can be used for results
101    if it becomes necessary to send in data this should be changed to INOUT */
102 %apply int *OUTPUT { int * };
103 %apply int *OUTPUT { size_t * };
104 %apply int *OUTPUT { unsigned int * };
105 %apply int *OUTPUT { uint16_t * };
106 
107 %include <cstring.i>
108 /* This is needed to properly mmaped binary data in SWIG */
109 %cstring_output_allocate_size(void **mapped_data, size_t *data_len, munmap(*$1, *$2));
110 
111 %typemap(in, numinputs=0) char **(char *temp=NULL) {
112 	$1 = &temp;
113 }
114 
115 %typemap(argout) char** {
116 	$result = SWIG_Python_AppendOutput($result, SWIG_FromCharPtr(*$1));
117 	free(*$1);
118 }
119 
120 %typemap(in, numinputs=0) char ***(char **temp=NULL) {
121 	$1 = &temp;
122 }
123 
124 %typemap(argout) (
125  	semanage_handle_t* handle,
126 	const semanage_user_t* user,
127 	const char*** roles_arr,
128 	unsigned int* num_roles) {
129 
130 	if ($result) {
131 		int value;
132 		SWIG_AsVal_int($result, &value);
133 		if (value >= 0) {
134 			PyObject* plist = NULL;
135 			if (semanage_array2plist($1, (void**) *$3, *$4,
136                         	NULL, NULL, &plist) < 0)
137 				$result = SWIG_From_int(STATUS_ERR);
138 			else
139 				$result = SWIG_Python_AppendOutput($result, plist);
140 		}
141 	}
142 }
143 
144 /** module typemaps**/
145 
146 /* the wrapper will setup this parameter for passing... the resulting python functions
147    will not take the semanage_module_info_t ** parameter */
148 %typemap(in, numinputs=0) semanage_module_info_t **(semanage_module_info_t *temp=NULL) {
149 	$1 = &temp;
150 }
151 
152 %typemap(argout) semanage_module_info_t ** {
153 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
154 }
155 
156 /** module key typemaps **/
157 
158 /* the wrapper will setup this parameter for passing... the resulting python functions
159    will not take the semanage_module_key_t ** parameter */
160 %typemap(in, numinputs=0) semanage_module_key_t **(semanage_module_key_t *temp=NULL) {
161 	$1 = &temp;
162 }
163 
164 %typemap(argout) semanage_module_key_t ** {
165 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
166 }
167 
168 /** context typemaps **/
169 
170 /* the wrapper will setup this parameter for passing... the resulting python functions
171    will not take the semanage_context_t ** parameter */
172 %typemap(in, numinputs=0) semanage_context_t **(semanage_context_t *temp=NULL) {
173 	$1 = &temp;
174 }
175 
176 %typemap(argout) semanage_context_t** {
177 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
178 }
179 
180 /** boolean typemaps **/
181 
182 /* the wrapper will setup this parameter for passing... the resulting python functions
183    will not take the semanage_bool_t *** parameter */
184 %typemap(in, numinputs=0) semanage_bool_t ***(semanage_bool_t **temp=NULL) {
185 	$1 = &temp;
186 }
187 
188 %typemap(argout) (
189  	semanage_handle_t* handle,
190 	semanage_bool_t*** records,
191 	unsigned int* count) {
192 
193 	if ($result) {
194 		int value;
195 		SWIG_AsVal_int($result, &value);
196 		if (value >= 0) {
197 			PyObject* plist = NULL;
198 			if (semanage_array2plist($1, (void**) *$2, *$3, SWIGTYPE_p_semanage_bool,
199 				(void (*) (void*)) &semanage_bool_free, &plist) < 0)
200 				$result = SWIG_From_int(STATUS_ERR);
201 			else
202 		   	        $result = SWIG_Python_AppendOutput($result, plist);
203 		}
204 	}
205 }
206 
207 %typemap(in, numinputs=0) semanage_bool_t **(semanage_bool_t *temp=NULL) {
208 	$1 = &temp;
209 }
210 
211 %typemap(argout) semanage_bool_t ** {
212 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
213 }
214 
215 %typemap(argout) semanage_bool_key_t ** {
216 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
217 }
218 
219 %typemap(in, numinputs=0) semanage_bool_key_t **(semanage_bool_key_t *temp=NULL) {
220 	$1 = &temp;
221 }
222 
223 /** fcontext typemaps **/
224 
225 /* the wrapper will setup this parameter for passing... the resulting python functions
226    will not take the semanage_fcontext_t *** parameter */
227 %typemap(in, numinputs=0) semanage_fcontext_t ***(semanage_fcontext_t **temp=NULL) {
228         $1 = &temp;
229 }
230 
231 %typemap(argout) (
232  	semanage_handle_t* handle,
233 	semanage_fcontext_t*** records,
234 	unsigned int* count) {
235 
236 	if ($result) {
237 		int value;
238 		SWIG_AsVal_int($result, &value);
239 		if (value >= 0) {
240 			PyObject* plist = NULL;
241 			if (semanage_array2plist($1, (void**) *$2, *$3, SWIGTYPE_p_semanage_fcontext,
242 				(void (*) (void*)) &semanage_fcontext_free, &plist) < 0)
243 				$result = SWIG_From_int(STATUS_ERR);
244 			else
245 				$result = SWIG_Python_AppendOutput($result, plist);
246 		}
247 	}
248 }
249 
250 %typemap(in, numinputs=0) semanage_fcontext_t **(semanage_fcontext_t *temp=NULL) {
251         $1 = &temp;
252 }
253 
254 %typemap(argout) semanage_fcontext_t ** {
255 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
256 }
257 
258 %typemap(argout) semanage_fcontext_key_t ** {
259         $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
260 }
261 
262 %typemap(in, numinputs=0) semanage_fcontext_key_t **(semanage_fcontext_key_t *temp=NULL) {
263         $1 = &temp;
264 }
265 
266 /** interface typemaps **/
267 
268 /* the wrapper will setup this parameter for passing... the resulting python functions
269    will not take the semanage_iface_t *** parameter */
270 %typemap(in, numinputs=0) semanage_iface_t ***(semanage_iface_t **temp=NULL) {
271 	$1 = &temp;
272 }
273 
274 
275 %typemap(argout) (
276  	semanage_handle_t* handle,
277 	semanage_iface_t*** records,
278 	unsigned int* count) {
279 
280 	if ($result) {
281 		int value;
282 		SWIG_AsVal_int($result, &value);
283 		if (value >= 0) {
284 			PyObject* plist = NULL;
285 			if (semanage_array2plist($1, (void**) *$2, *$3, SWIGTYPE_p_semanage_iface,
286 				(void (*) (void*)) &semanage_iface_free, &plist) < 0)
287 				$result = SWIG_From_int(STATUS_ERR);
288 			else
289 				$result = SWIG_Python_AppendOutput($result, plist);
290 		}
291 	}
292 }
293 
294 %typemap(in, numinputs=0) semanage_iface_t **(semanage_iface_t *temp=NULL) {
295 	$1 = &temp;
296 }
297 
298 %typemap(argout) semanage_iface_t ** {
299 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
300 }
301 
302 %typemap(argout) semanage_iface_key_t ** {
303 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
304 }
305 
306 %typemap(in, numinputs=0) semanage_iface_key_t **(semanage_iface_key_t *temp=NULL) {
307 	$1 = &temp;
308 }
309 
310 /** seuser typemaps **/
311 
312 /* the wrapper will setup this parameter for passing... the resulting python functions
313    will not take the semanage_seuser_t *** parameter */
314 %typemap(in, numinputs=0) semanage_seuser_t ***(semanage_seuser_t **temp=NULL) {
315 	$1 = &temp;
316 }
317 
318 
319 %typemap(argout) (
320  	semanage_handle_t* handle,
321 	semanage_seuser_t*** records,
322 	unsigned int* count) {
323 
324 	if ($result) {
325 		int value;
326 		SWIG_AsVal_int($result, &value);
327 		if (value >= 0) {
328 			PyObject* plist = NULL;
329 			if (semanage_array2plist($1, (void**) *$2, *$3, SWIGTYPE_p_semanage_seuser,
330 				(void (*) (void*)) &semanage_seuser_free, &plist) < 0)
331 				$result = SWIG_From_int(STATUS_ERR);
332 			else
333 				$result = SWIG_Python_AppendOutput($result, plist);
334 		}
335 	}
336 }
337 
338 %typemap(in, numinputs=0) semanage_seuser_t **(semanage_seuser_t *temp=NULL) {
339 	$1 = &temp;
340 }
341 
342 %typemap(argout) semanage_seuser_t ** {
343 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
344 }
345 
346 %typemap(argout) semanage_seuser_key_t ** {
347 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
348 }
349 
350 %typemap(in, numinputs=0) semanage_seuser_key_t **(semanage_seuser_key_t *temp=NULL) {
351 	$1 = &temp;
352 }
353 
354 /** user typemaps **/
355 
356 /* the wrapper will setup this parameter for passing... the resulting python functions
357    will not take the semanage_user_t *** parameter */
358 %typemap(in, numinputs=0) semanage_user_t ***(semanage_user_t **temp=NULL) {
359 	$1 = &temp;
360 }
361 
362 %typemap(argout) (
363  	semanage_handle_t* handle,
364 	semanage_user_t*** records,
365 	unsigned int* count) {
366 
367 	if ($result) {
368 		int value;
369 		SWIG_AsVal_int($result, &value);
370 		if (value >= 0) {
371 			PyObject* plist = NULL;
372 			if (semanage_array2plist($1, (void**) *$2, *$3, SWIGTYPE_p_semanage_user,
373 				(void (*) (void*)) &semanage_user_free, &plist) < 0)
374 				$result = SWIG_From_int(STATUS_ERR);
375 			else
376 				$result = SWIG_Python_AppendOutput($result, plist);
377 		}
378 	}
379 }
380 
381 %typemap(in, numinputs=0) semanage_user_t **(semanage_user_t *temp=NULL) {
382 	$1 = &temp;
383 }
384 
385 %typemap(argout) semanage_user_t ** {
386 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
387 }
388 
389 %typemap(argout) semanage_user_key_t ** {
390 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
391 }
392 
393 %typemap(in, numinputs=0) semanage_user_key_t **(semanage_user_key_t *temp=NULL) {
394 	$1 = &temp;
395 }
396 
397 /** port typemaps **/
398 
399 /* the wrapper will setup this parameter for passing... the resulting python functions
400    will not take the semanage_port_t *** parameter */
401 %typemap(in, numinputs=0) semanage_port_t ***(semanage_port_t **temp=NULL) {
402 	$1 = &temp;
403 }
404 
405 %typemap(argout) (
406  	semanage_handle_t* handle,
407 	semanage_port_t*** records,
408 	unsigned int* count) {
409 
410 	if ($result) {
411 		int value;
412 		SWIG_AsVal_int($result, &value);
413 		if (value >= 0) {
414 			PyObject* plist = NULL;
415 			if (semanage_array2plist($1, (void**) *$2, *$3, SWIGTYPE_p_semanage_port,
416 				(void (*) (void*)) &semanage_port_free, &plist) < 0)
417 				$result = SWIG_From_int(STATUS_ERR);
418 			else
419 				$result = SWIG_Python_AppendOutput($result, plist);
420 		}
421 	}
422 }
423 
424 %typemap(in, numinputs=0) semanage_port_t **(semanage_port_t *temp=NULL) {
425 	$1 = &temp;
426 }
427 
428 %typemap(argout) semanage_port_t ** {
429 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
430 }
431 
432 %typemap(argout) semanage_port_key_t ** {
433 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
434 }
435 
436 %typemap(in, numinputs=0) semanage_port_key_t **(semanage_port_key_t *temp=NULL) {
437 	$1 = &temp;
438 }
439 
440 /** node typemaps **/
441 
442 /* the wrapper will setup this parameter for passing... the resulting python functions
443    will not take the semanage_node_t *** parameter */
444 %typemap(in, numinputs=0) semanage_node_t ***(semanage_node_t **temp=NULL) {
445 	$1 = &temp;
446 }
447 
448 %typemap(argout) (
449  	semanage_handle_t* handle,
450 	semanage_node_t*** records,
451 	unsigned int* count) {
452 
453 	if ($result) {
454 		int value;
455 		SWIG_AsVal_int($result, &value);
456 		if (value >= 0) {
457 			PyObject* plist = NULL;
458 			if (semanage_array2plist($1, (void**) *$2, *$3, SWIGTYPE_p_semanage_node,
459 				(void (*) (void*)) &semanage_node_free, &plist) < 0)
460 				$result = SWIG_From_int(STATUS_ERR);
461 			else
462 				$result = SWIG_Python_AppendOutput($result, plist);
463 		}
464 	}
465 }
466 
467 %typemap(in, numinputs=0) semanage_node_t **(semanage_node_t *temp=NULL) {
468 	$1 = &temp;
469 }
470 
471 %typemap(argout) semanage_node_t ** {
472 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
473 }
474 
475 
476 %typemap(argout) semanage_node_key_t ** {
477 	$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
478 }
479 
480 %typemap(in, numinputs=0) semanage_node_key_t **(semanage_node_key_t *temp=NULL) {
481 	$1 = &temp;
482 }
483 
484 %include "semanageswig_python_exception.i"
485 %include "semanageswig.i"
486