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