1 /** 2 * SWIG declarations for libqpol. 3 * 4 * @author Jeremy A. Mowery jmowery (at) tresys.com 5 * @author Jason Tang jtang (at) tresys.com 6 * 7 * Copyright (C) 2006-2008 Tresys Technology, LLC 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public 11 * License as published by the Free Software Foundation; either 12 * version 2.1 of the License, or (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this library; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 */ 23 24 %module qpol 25 26 %{ 27 #include <sys/stat.h> 28 #include <arpa/inet.h> 29 #include <sepol/policydb.h> 30 #include <sepol/policydb/policydb.h> 31 #include "include/qpol/avrule_query.h" 32 #include "include/qpol/bool_query.h" 33 #include "include/qpol/class_perm_query.h" 34 #include "include/qpol/cond_query.h" 35 #include "include/qpol/constraint_query.h" 36 #include "include/qpol/context_query.h" 37 #include "include/qpol/fs_use_query.h" 38 #include "include/qpol/genfscon_query.h" 39 #include "include/qpol/isid_query.h" 40 #include "include/qpol/iterator.h" 41 #include "include/qpol/mls_query.h" 42 #include "include/qpol/mlsrule_query.h" 43 #include "include/qpol/module.h" 44 #include "include/qpol/netifcon_query.h" 45 #include "include/qpol/nodecon_query.h" 46 #include "include/qpol/policy.h" 47 #include "include/qpol/policy_extend.h" 48 #include "include/qpol/portcon_query.h" 49 #include "include/qpol/rbacrule_query.h" 50 #include "include/qpol/role_query.h" 51 #include "include/qpol/syn_rule_query.h" 52 #include "include/qpol/terule_query.h" 53 #include "include/qpol/type_query.h" 54 #include "include/qpol/user_query.h" 55 #include "include/qpol/util.h" 56 #include "include/qpol/xen_query.h" 57 58 /* Provide hooks so that language-specific modules can define the 59 * callback function, used by the handler in 60 * qpol_policy_open_from_file(). 61 */ 62 SWIGEXPORT qpol_callback_fn_t qpol_swig_message_callback = NULL; 63 SWIGEXPORT void * qpol_swig_message_callback_arg = NULL; 64 65 %} 66 67 %include exception.i 68 %include stdint.i 69 70 /* handle size_t as architecture dependent */ 71 #ifdef SWIGWORDSIZE64 72 typedef uint64_t size_t; 73 #else 74 typedef uint32_t size_t; 75 #endif 76 77 %inline %{ 78 /* cast void * to char * as it can't have a constructor */ 79 const char * to_str(void *x) { 80 return (const char *)x; 81 } 82 83 /* cast a void * to int, while freeing the pointer */ 84 int to_int_with_free(void *x) { 85 int i = *(int *)x; 86 free(x); 87 return i; 88 } 89 %} 90 %{ 91 /* C Bridge to Python logging callback */ 92 __attribute__ ((format(printf, 4, 0))) 93 static void qpol_log_callback(void *varg, 94 const qpol_policy_t * p __attribute__ ((unused)), 95 int level, 96 const char *fmt, 97 va_list va_args) 98 { 99 /* Expand to a full string to avoid any C format string 100 * or variable args handling when passing to Python 101 */ 102 103 PyObject *py_callback, *rc; 104 char *str = NULL; 105 106 if(vasprintf(&str, fmt, va_args) < 0) 107 return; 108 109 py_callback = (PyObject *) varg; 110 111 /* this char* casting doesn't make sense, but this runs afoul of -Werror 112 * otherwise as the Python library doesn't do const char* */ 113 rc = PyObject_CallFunction(py_callback, (char*)"(is)", level, str); 114 Py_XDECREF(rc); 115 free(str); 116 } 117 %} 118 119 %pythoncode %{ 120 import logging 121 from functools import wraps 122 123 def QpolGenerator(cast): 124 """ 125 A decorator which converts qpol iterators into Python generators. 126 127 Qpol iterators use void* to be generic about their contents. 128 The purpose of the _from_void functions below is to wrap 129 the pointer casting, hence the "cast" variable name here. 130 131 Decorator parameter: 132 cast A wrapper function which casts the qpol iterator return pointer 133 to the proper C data type pointer. The Python function 134 reference to the C Python extension is used, for example: 135 136 @QpolGenerator(_qpol.qpol_type_from_void) 137 """ 138 139 def decorate(func): 140 @wraps(func) 141 def wrapper(*args, **kwargs): 142 qpol_iter = func(*args) 143 while not qpol_iter.isend(): 144 yield cast(qpol_iter.item()) 145 qpol_iter.next_() 146 147 return wrapper 148 return decorate 149 150 def qpol_logger(level, msg): 151 """Log qpol messages via Python logging.""" 152 logging.getLogger(__name__).debug(msg) 153 154 def qpol_policy_factory(path): 155 """Factory function for qpol policy objects.""" 156 # The main purpose here is to hook in the 157 # above logger callback. 158 return qpol_policy_t(path, 0, qpol_logger) 159 %} 160 161 /* qpol_policy */ 162 #define QPOL_POLICY_OPTION_NO_NEVERALLOWS 0x00000001 163 #define QPOL_POLICY_OPTION_NO_RULES 0x00000002 164 #define QPOL_POLICY_OPTION_MATCH_SYSTEM 0x00000004 165 /* add maximum and minimum policy versions supported by the statically linked libsepol */ 166 %constant int QPOL_POLICY_MAX_VERSION = POLICYDB_VERSION_MAX; 167 %constant int QPOL_POLICY_MIN_VERSION = POLICYDB_VERSION_MIN; 168 typedef struct qpol_policy {} qpol_policy_t; 169 typedef void (*qpol_callback_fn_t) (void *varg, struct qpol_policy * policy, int level, const char *fmt, va_list va_args); 170 171 typedef enum qpol_capability 172 { 173 QPOL_CAP_ATTRIB_NAMES, 174 QPOL_CAP_SYN_RULES, 175 QPOL_CAP_LINE_NUMBERS, 176 QPOL_CAP_CONDITIONALS, 177 QPOL_CAP_MLS, 178 QPOL_CAP_MODULES, 179 QPOL_CAP_RULES_LOADED, 180 QPOL_CAP_SOURCE, 181 QPOL_CAP_NEVERALLOW, 182 QPOL_CAP_POLCAPS, 183 QPOL_CAP_BOUNDS, 184 QPOL_CAP_DEFAULT_OBJECTS, 185 QPOL_CAP_DEFAULT_TYPE, 186 QPOL_CAP_PERMISSIVE, 187 QPOL_CAP_FILENAME_TRANS, 188 QPOL_CAP_ROLETRANS, 189 QPOL_CAP_XPERM_IOCTL 190 } qpol_capability_e; 191 %exception qpol_policy { 192 $action 193 if (!result) { 194 if (errno == EINVAL) { 195 PyErr_SetString(PyExc_SyntaxError, "Invalid policy."); 196 } else { 197 PyErr_SetFromErrnoWithFilename(PyExc_OSError, arg1); 198 } 199 return NULL; 200 } 201 } 202 %extend qpol_policy { 203 qpol_policy(const char *path, const int options, PyObject *py_callback) { 204 qpol_policy_t *p; 205 206 if (!PyCallable_Check(py_callback)) { 207 PyErr_SetString(PyExc_TypeError, "Callback parameter must be callable"); 208 return NULL; 209 } 210 211 qpol_policy_open_from_file(path, &p, qpol_log_callback, (void*)py_callback, options); 212 return p; 213 } 214 ~qpol_policy() { 215 qpol_policy_destroy(&self); 216 }; 217 218 int version () { 219 unsigned int v; 220 (void)qpol_policy_get_policy_version(self, &v); /* only error is on null parameters neither can be here */ 221 return (int) v; 222 }; 223 224 const char *handle_unknown () { 225 unsigned int h; 226 qpol_policy_get_policy_handle_unknown(self, &h); 227 228 switch (h) { 229 case SEPOL_DENY_UNKNOWN: return "deny"; 230 case SEPOL_REJECT_UNKNOWN: return "reject"; 231 case SEPOL_ALLOW_UNKNOWN: return "allow"; 232 default: return "unknown"; 233 } 234 }; 235 236 /* This is whether SELinux or XEN policy */ 237 const char *target_platform () { 238 int t; 239 (void)qpol_policy_get_target_platform(self, &t); 240 switch (t) { 241 case SEPOL_TARGET_SELINUX: return "selinux"; 242 case SEPOL_TARGET_XEN: return "xen"; 243 default: return "unknown"; 244 } 245 }; 246 247 int capability (qpol_capability_e cap) { 248 return qpol_policy_has_capability(self, cap); 249 }; 250 251 %newobject type_iter(); 252 %pythoncode %{ @QpolGenerator(_qpol.qpol_type_from_void) %} 253 qpol_iterator_t *type_iter() { 254 qpol_iterator_t *iter; 255 if (qpol_policy_get_type_iter(self, &iter)) { 256 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 257 } 258 return iter; 259 fail: 260 return NULL; 261 }; 262 263 size_t type_count() { 264 qpol_iterator_t *iter; 265 size_t count = 0; 266 if (qpol_policy_get_type_iter(self, &iter)) { 267 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 268 } 269 qpol_iterator_get_size(iter, &count); 270 return count; 271 fail: 272 return 0; 273 }; 274 275 %newobject role_iter(); 276 %pythoncode %{ @QpolGenerator(_qpol.qpol_role_from_void) %} 277 qpol_iterator_t *role_iter() { 278 qpol_iterator_t *iter; 279 if (qpol_policy_get_role_iter(self, &iter)) { 280 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 281 } 282 return iter; 283 fail: 284 return NULL; 285 }; 286 287 size_t role_count() { 288 qpol_iterator_t *iter; 289 size_t count = 0; 290 if (qpol_policy_get_role_iter(self, &iter)) { 291 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 292 } 293 qpol_iterator_get_size(iter, &count); 294 return count; 295 fail: 296 return 0; 297 }; 298 299 %newobject level_iter(); 300 %pythoncode %{ @QpolGenerator(_qpol.qpol_level_from_void) %} 301 qpol_iterator_t *level_iter() { 302 qpol_iterator_t *iter; 303 if (qpol_policy_get_level_iter(self, &iter)) { 304 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 305 } 306 return iter; 307 fail: 308 return NULL; 309 }; 310 311 size_t level_count() { 312 qpol_iterator_t *iter; 313 size_t count = 0; 314 if (qpol_policy_get_level_iter(self, &iter)) { 315 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 316 } 317 qpol_iterator_get_size(iter, &count); 318 return count; 319 fail: 320 return 0; 321 }; 322 323 %newobject cat_iter(); 324 %pythoncode %{ @QpolGenerator(_qpol.qpol_cat_from_void) %} 325 qpol_iterator_t *cat_iter() { 326 qpol_iterator_t *iter; 327 if (qpol_policy_get_cat_iter(self, &iter)) { 328 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 329 } 330 return iter; 331 fail: 332 return NULL; 333 }; 334 335 size_t cat_count() { 336 qpol_iterator_t *iter; 337 size_t count = 0; 338 if (qpol_policy_get_cat_iter(self, &iter)) { 339 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 340 } 341 qpol_iterator_get_size(iter, &count); 342 return count; 343 fail: 344 return 0; 345 }; 346 347 %newobject user_iter(); 348 %pythoncode %{ @QpolGenerator(_qpol.qpol_user_from_void) %} 349 qpol_iterator_t *user_iter() { 350 qpol_iterator_t *iter; 351 if (qpol_policy_get_user_iter(self, &iter)) { 352 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 353 } 354 return iter; 355 fail: 356 return NULL; 357 }; 358 359 size_t user_count() { 360 qpol_iterator_t *iter; 361 size_t count = 0; 362 if (qpol_policy_get_user_iter(self, &iter)) { 363 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 364 } 365 qpol_iterator_get_size(iter, &count); 366 return count; 367 fail: 368 return 0; 369 }; 370 371 372 %newobject bool_iter(); 373 %pythoncode %{ @QpolGenerator(_qpol.qpol_bool_from_void) %} 374 qpol_iterator_t *bool_iter() { 375 qpol_iterator_t *iter; 376 if (qpol_policy_get_bool_iter(self, &iter)) { 377 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 378 } 379 return iter; 380 fail: 381 return NULL; 382 }; 383 384 size_t bool_count() { 385 qpol_iterator_t *iter; 386 size_t count = 0; 387 if (qpol_policy_get_bool_iter(self, &iter)) { 388 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 389 } 390 qpol_iterator_get_size(iter, &count); 391 return count; 392 fail: 393 return 0; 394 }; 395 396 %newobject class_iter(char*); 397 %pythoncode %{ @QpolGenerator(_qpol.qpol_class_from_void) %} 398 qpol_iterator_t *class_iter(char *perm=NULL) { 399 qpol_iterator_t *iter; 400 if (perm) { 401 if (qpol_perm_get_class_iter(self, perm, &iter)) { 402 SWIG_exception(SWIG_RuntimeError, "Could not get class iterator"); 403 } 404 } else { 405 if (qpol_policy_get_class_iter(self, &iter)) { 406 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 407 } 408 } 409 return iter; 410 fail: 411 return NULL; 412 }; 413 414 size_t class_count() { 415 qpol_iterator_t *iter; 416 size_t count = 0; 417 if (qpol_policy_get_class_iter(self, &iter)) { 418 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 419 } 420 qpol_iterator_get_size(iter, &count); 421 return count; 422 fail: 423 return 0; 424 }; 425 426 %newobject common_iter(char*); 427 %pythoncode %{ @QpolGenerator(_qpol.qpol_common_from_void) %} 428 qpol_iterator_t *common_iter(char *perm=NULL) { 429 qpol_iterator_t *iter; 430 if (perm) { 431 if (qpol_perm_get_common_iter(self, perm, &iter)) { 432 SWIG_exception(SWIG_RuntimeError, "Could not get common iterator"); 433 } 434 } else { 435 if (qpol_policy_get_common_iter(self, &iter)) { 436 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 437 } 438 } 439 return iter; 440 fail: 441 return NULL; 442 }; 443 444 size_t common_count() { 445 qpol_iterator_t *iter; 446 size_t count = 0; 447 if (qpol_policy_get_common_iter(self, &iter)) { 448 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 449 } 450 qpol_iterator_get_size(iter, &count); 451 return count; 452 fail: 453 return 0; 454 }; 455 456 %newobject fs_use_iter(); 457 %pythoncode %{ @QpolGenerator(_qpol.qpol_fs_use_from_void) %} 458 qpol_iterator_t *fs_use_iter() { 459 qpol_iterator_t *iter; 460 if (qpol_policy_get_fs_use_iter(self, &iter)) { 461 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 462 } 463 return iter; 464 fail: 465 return NULL; 466 }; 467 468 size_t fs_use_count() { 469 qpol_iterator_t *iter; 470 size_t count = 0; 471 if (qpol_policy_get_fs_use_iter(self, &iter)) { 472 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 473 } 474 qpol_iterator_get_size(iter, &count); 475 return count; 476 fail: 477 return 0; 478 }; 479 480 %newobject genfscon_iter(); 481 %pythoncode %{ @QpolGenerator(_qpol.qpol_genfscon_from_void) %} 482 qpol_iterator_t *genfscon_iter() { 483 qpol_iterator_t *iter; 484 if (qpol_policy_get_genfscon_iter(self, &iter)) { 485 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 486 } 487 return iter; 488 fail: 489 return NULL; 490 }; 491 492 size_t genfscon_count() { 493 qpol_iterator_t *iter; 494 size_t count = 0; 495 if (qpol_policy_get_genfscon_iter(self, &iter)) { 496 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 497 } 498 qpol_iterator_get_size(iter, &count); 499 return count; 500 fail: 501 return 0; 502 }; 503 504 %newobject isid_iter(); 505 %pythoncode %{ @QpolGenerator(_qpol.qpol_isid_from_void) %} 506 qpol_iterator_t *isid_iter() { 507 qpol_iterator_t *iter; 508 if (qpol_policy_get_isid_iter(self, &iter)) { 509 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 510 } 511 return iter; 512 fail: 513 return NULL; 514 }; 515 516 size_t isid_count() { 517 qpol_iterator_t *iter; 518 size_t count = 0; 519 if (qpol_policy_get_isid_iter(self, &iter)) { 520 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 521 } 522 qpol_iterator_get_size(iter, &count); 523 return count; 524 fail: 525 return 0; 526 }; 527 528 %newobject netifcon_iter(); 529 %pythoncode %{ @QpolGenerator(_qpol.qpol_netifcon_from_void) %} 530 qpol_iterator_t *netifcon_iter() { 531 qpol_iterator_t *iter; 532 if (qpol_policy_get_netifcon_iter(self, &iter)) { 533 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 534 } 535 return iter; 536 fail: 537 return NULL; 538 }; 539 540 size_t netifcon_count() { 541 qpol_iterator_t *iter; 542 size_t count = 0; 543 if (qpol_policy_get_netifcon_iter(self, &iter)) { 544 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 545 } 546 qpol_iterator_get_size(iter, &count); 547 return count; 548 fail: 549 return 0; 550 }; 551 552 %newobject nodecon_iter(); 553 %pythoncode %{ @QpolGenerator(_qpol.qpol_nodecon_from_void) %} 554 qpol_iterator_t *nodecon_iter() { 555 qpol_iterator_t *iter; 556 if (qpol_policy_get_nodecon_iter(self, &iter)) { 557 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 558 } 559 return iter; 560 fail: 561 return NULL; 562 }; 563 564 size_t nodecon_count() { 565 qpol_iterator_t *iter; 566 size_t count = 0; 567 if (qpol_policy_get_nodecon_iter(self, &iter)) { 568 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 569 } 570 qpol_iterator_get_size(iter, &count); 571 return count; 572 fail: 573 return 0; 574 }; 575 576 %newobject portcon_iter(); 577 %pythoncode %{ @QpolGenerator(_qpol.qpol_portcon_from_void) %} 578 qpol_iterator_t *portcon_iter() { 579 qpol_iterator_t *iter; 580 if (qpol_policy_get_portcon_iter(self, &iter)) { 581 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 582 } 583 return iter; 584 fail: 585 return NULL; 586 }; 587 588 size_t portcon_count() { 589 qpol_iterator_t *iter; 590 size_t count = 0; 591 if (qpol_policy_get_portcon_iter(self, &iter)) { 592 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 593 } 594 qpol_iterator_get_size(iter, &count); 595 return count; 596 fail: 597 return 0; 598 }; 599 600 %newobject constraint_iter(); 601 %pythoncode %{ @QpolGenerator(_qpol.qpol_constraint_from_void) %} 602 qpol_iterator_t *constraint_iter() { 603 qpol_iterator_t *iter; 604 if (qpol_policy_get_constraint_iter(self, &iter)) { 605 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 606 } 607 return iter; 608 fail: 609 return NULL; 610 }; 611 612 size_t constraint_count() { 613 qpol_iterator_t *iter; 614 size_t count = 0; 615 if (qpol_policy_get_constraint_iter(self, &iter)) { 616 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 617 } 618 qpol_iterator_get_size(iter, &count); 619 return count; 620 fail: 621 return 0; 622 }; 623 624 %newobject validatetrans_iter(); 625 %pythoncode %{ @QpolGenerator(_qpol.qpol_validatetrans_from_void) %} 626 qpol_iterator_t *validatetrans_iter() { 627 qpol_iterator_t *iter; 628 if (qpol_policy_get_validatetrans_iter(self, &iter)) { 629 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 630 } 631 return iter; 632 fail: 633 return NULL; 634 }; 635 636 size_t validatetrans_count() { 637 qpol_iterator_t *iter; 638 size_t count = 0; 639 if (qpol_policy_get_validatetrans_iter(self, &iter)) { 640 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 641 } 642 qpol_iterator_get_size(iter, &count); 643 return count; 644 fail: 645 return 0; 646 }; 647 648 %newobject role_allow_iter(); 649 %pythoncode %{ @QpolGenerator(_qpol.qpol_role_allow_from_void) %} 650 qpol_iterator_t *role_allow_iter() { 651 qpol_iterator_t *iter; 652 if (qpol_policy_get_role_allow_iter(self, &iter)) { 653 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 654 } 655 return iter; 656 fail: 657 return NULL; 658 }; 659 660 size_t role_allow_count() { 661 qpol_iterator_t *iter; 662 size_t count = 0; 663 if (qpol_policy_get_role_allow_iter(self, &iter)) { 664 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 665 } 666 qpol_iterator_get_size(iter, &count); 667 return count; 668 fail: 669 return 0; 670 }; 671 672 %newobject role_trans_iter(); 673 %pythoncode %{ @QpolGenerator(_qpol.qpol_role_trans_from_void) %} 674 qpol_iterator_t *role_trans_iter() { 675 qpol_iterator_t *iter; 676 if (qpol_policy_get_role_trans_iter(self, &iter)) { 677 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 678 } 679 return iter; 680 fail: 681 return NULL; 682 }; 683 684 size_t role_trans_count() { 685 qpol_iterator_t *iter; 686 size_t count = 0; 687 if (qpol_policy_get_role_trans_iter(self, &iter)) { 688 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 689 } 690 qpol_iterator_get_size(iter, &count); 691 return count; 692 fail: 693 return 0; 694 }; 695 696 %newobject range_trans_iter(); 697 %pythoncode %{ @QpolGenerator(_qpol.qpol_range_trans_from_void) %} 698 qpol_iterator_t *range_trans_iter() { 699 qpol_iterator_t *iter; 700 if (qpol_policy_get_range_trans_iter(self, &iter)) { 701 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 702 } 703 return iter; 704 fail: 705 return NULL; 706 }; 707 708 size_t range_trans_count() { 709 qpol_iterator_t *iter; 710 size_t count = 0; 711 if (qpol_policy_get_range_trans_iter(self, &iter)) { 712 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 713 } 714 qpol_iterator_get_size(iter, &count); 715 return count; 716 fail: 717 return 0; 718 }; 719 720 %newobject avrule_iter(int); 721 %pythoncode %{ @QpolGenerator(_qpol.qpol_avrule_from_void) %} 722 qpol_iterator_t *avrule_iter() { 723 qpol_iterator_t *iter; 724 uint32_t rule_types = QPOL_RULE_ALLOW | QPOL_RULE_AUDITALLOW | QPOL_RULE_DONTAUDIT; 725 726 if (qpol_policy_has_capability(self, QPOL_CAP_NEVERALLOW)) 727 rule_types |= QPOL_RULE_NEVERALLOW; 728 729 if (qpol_policy_get_avrule_iter(self, rule_types, &iter)) { 730 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 731 } 732 return iter; 733 fail: 734 return NULL; 735 }; 736 737 size_t avrule_allow_count() { 738 qpol_iterator_t *iter; 739 size_t count = 0; 740 if (qpol_policy_get_avrule_iter(self, QPOL_RULE_ALLOW, &iter)) { 741 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 742 } 743 qpol_iterator_get_size(iter, &count); 744 return count; 745 fail: 746 return 0; 747 }; 748 749 size_t avrule_auditallow_count() { 750 qpol_iterator_t *iter; 751 size_t count = 0; 752 if (qpol_policy_get_avrule_iter(self, QPOL_RULE_AUDITALLOW, &iter)) { 753 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 754 } 755 qpol_iterator_get_size(iter, &count); 756 return count; 757 fail: 758 return 0; 759 }; 760 761 size_t avrule_neverallow_count() { 762 if (qpol_policy_has_capability(self, QPOL_CAP_NEVERALLOW)) { 763 qpol_iterator_t *iter; 764 size_t count = 0; 765 if (qpol_policy_get_avrule_iter(self, QPOL_RULE_NEVERALLOW, &iter)) { 766 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 767 } 768 qpol_iterator_get_size(iter, &count); 769 return count; 770 } else { 771 return 0; 772 } 773 fail: 774 return 0; 775 }; 776 777 size_t avrule_dontaudit_count() { 778 qpol_iterator_t *iter; 779 size_t count = 0; 780 if (qpol_policy_get_avrule_iter(self, QPOL_RULE_DONTAUDIT, &iter)) { 781 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 782 } 783 qpol_iterator_get_size(iter, &count); 784 return count; 785 fail: 786 return 0; 787 }; 788 789 %newobject avulex_iter(int); 790 %pythoncode %{ @QpolGenerator(_qpol.qpol_avrule_from_void) %} 791 qpol_iterator_t *avrulex_iter() { 792 qpol_iterator_t *iter; 793 uint32_t rule_types = QPOL_RULE_XPERMS_ALLOW | QPOL_RULE_XPERMS_AUDITALLOW | QPOL_RULE_XPERMS_DONTAUDIT; 794 795 if (qpol_policy_has_capability(self, QPOL_CAP_NEVERALLOW)) 796 rule_types |= QPOL_RULE_XPERMS_NEVERALLOW; 797 798 if (qpol_policy_get_avrule_iter(self, rule_types, &iter)) { 799 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 800 } 801 return iter; 802 fail: 803 return NULL; 804 }; 805 806 size_t avrule_allowx_count() { 807 qpol_iterator_t *iter; 808 size_t count = 0; 809 if (qpol_policy_get_avrule_iter(self, QPOL_RULE_XPERMS_ALLOW, &iter)) { 810 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 811 } 812 qpol_iterator_get_size(iter, &count); 813 return count; 814 fail: 815 return 0; 816 }; 817 818 size_t avrule_auditallowx_count() { 819 qpol_iterator_t *iter; 820 size_t count = 0; 821 if (qpol_policy_get_avrule_iter(self, QPOL_RULE_XPERMS_AUDITALLOW, &iter)) { 822 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 823 } 824 qpol_iterator_get_size(iter, &count); 825 return count; 826 fail: 827 return 0; 828 }; 829 830 size_t avrule_neverallowx_count() { 831 if (qpol_policy_has_capability(self, QPOL_CAP_NEVERALLOW)) { 832 qpol_iterator_t *iter; 833 size_t count = 0; 834 if (qpol_policy_get_avrule_iter(self, QPOL_RULE_XPERMS_NEVERALLOW, &iter)) { 835 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 836 } 837 qpol_iterator_get_size(iter, &count); 838 return count; 839 } else { 840 return 0; 841 } 842 fail: 843 return 0; 844 }; 845 846 size_t avrule_dontauditx_count() { 847 qpol_iterator_t *iter; 848 size_t count = 0; 849 if (qpol_policy_get_avrule_iter(self, QPOL_RULE_XPERMS_DONTAUDIT, &iter)) { 850 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 851 } 852 qpol_iterator_get_size(iter, &count); 853 return count; 854 fail: 855 return 0; 856 }; 857 858 %newobject terule_iter(int); 859 %pythoncode %{ @QpolGenerator(_qpol.qpol_terule_from_void) %} 860 qpol_iterator_t *terule_iter() { 861 qpol_iterator_t *iter; 862 uint32_t rule_types = QPOL_RULE_TYPE_TRANS | QPOL_RULE_TYPE_CHANGE | QPOL_RULE_TYPE_MEMBER; 863 864 if (qpol_policy_get_terule_iter(self, rule_types, &iter)) { 865 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 866 } 867 return iter; 868 fail: 869 return NULL; 870 }; 871 872 size_t terule_trans_count() { 873 qpol_iterator_t *iter; 874 size_t count = 0; 875 if (qpol_policy_get_terule_iter(self, QPOL_RULE_TYPE_TRANS, &iter)) { 876 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 877 } 878 qpol_iterator_get_size(iter, &count); 879 return count; 880 fail: 881 return 0; 882 }; 883 884 size_t terule_change_count() { 885 qpol_iterator_t *iter; 886 size_t count = 0; 887 if (qpol_policy_get_terule_iter(self, QPOL_RULE_TYPE_CHANGE, &iter)) { 888 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 889 } 890 qpol_iterator_get_size(iter, &count); 891 return count; 892 fail: 893 return 0; 894 }; 895 896 size_t terule_member_count() { 897 qpol_iterator_t *iter; 898 size_t count = 0; 899 if (qpol_policy_get_terule_iter(self, QPOL_RULE_TYPE_MEMBER, &iter)) { 900 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 901 } 902 qpol_iterator_get_size(iter, &count); 903 return count; 904 fail: 905 return 0; 906 }; 907 908 %newobject cond_iter(); 909 qpol_iterator_t *cond_iter() { 910 qpol_iterator_t *iter; 911 if (qpol_policy_get_cond_iter(self, &iter)) { 912 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 913 } 914 return iter; 915 fail: 916 return NULL; 917 }; 918 919 size_t cond_count() { 920 qpol_iterator_t *iter; 921 size_t count = 0; 922 if (qpol_policy_get_cond_iter(self, &iter)) { 923 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 924 } 925 qpol_iterator_get_size(iter, &count); 926 return count; 927 fail: 928 return 0; 929 }; 930 931 %newobject filename_trans_iter(); 932 %pythoncode %{ @QpolGenerator(_qpol.qpol_filename_trans_from_void) %} 933 qpol_iterator_t *filename_trans_iter() { 934 qpol_iterator_t *iter; 935 if (qpol_policy_get_filename_trans_iter(self, &iter)) { 936 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 937 } 938 return iter; 939 fail: 940 return NULL; 941 }; 942 943 size_t filename_trans_count() { 944 qpol_iterator_t *iter; 945 size_t count = 0; 946 if (qpol_policy_get_filename_trans_iter(self, &iter)) { 947 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 948 } 949 qpol_iterator_get_size(iter, &count); 950 return count; 951 fail: 952 return 0; 953 }; 954 955 %newobject permissive_iter(); 956 %pythoncode %{ @QpolGenerator(_qpol.qpol_type_from_void) %} 957 qpol_iterator_t *permissive_iter() { 958 qpol_iterator_t *iter; 959 if (qpol_policy_get_permissive_iter(self, &iter)) { 960 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 961 } 962 return iter; 963 fail: 964 return NULL; 965 }; 966 967 size_t permissive_count() { 968 qpol_iterator_t *iter; 969 size_t count = 0; 970 if (qpol_policy_get_permissive_iter(self, &iter)) { 971 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 972 } 973 qpol_iterator_get_size(iter, &count); 974 return count; 975 fail: 976 return 0; 977 }; 978 979 %newobject typebounds_iter(); 980 %pythoncode %{ @QpolGenerator(_qpol.qpol_typebounds_from_void) %} 981 qpol_iterator_t *typebounds_iter() { 982 qpol_iterator_t *iter; 983 if (qpol_policy_get_typebounds_iter(self, &iter)) { 984 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 985 } 986 return iter; 987 fail: 988 return NULL; 989 }; 990 991 %newobject polcap_iter(); 992 %pythoncode %{ @QpolGenerator(_qpol.qpol_polcap_from_void) %} 993 qpol_iterator_t *polcap_iter() { 994 qpol_iterator_t *iter; 995 if (qpol_policy_get_polcap_iter(self, &iter)) { 996 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 997 } 998 return iter; 999 fail: 1000 return NULL; 1001 }; 1002 1003 size_t polcap_count() { 1004 qpol_iterator_t *iter; 1005 size_t count = 0; 1006 if (qpol_policy_get_polcap_iter(self, &iter)) { 1007 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1008 } 1009 qpol_iterator_get_size(iter, &count); 1010 return count; 1011 fail: 1012 return 0; 1013 }; 1014 1015 %newobject default_iter(); 1016 %pythoncode %{ @QpolGenerator(_qpol.qpol_default_object_from_void) %} 1017 qpol_iterator_t *default_iter() { 1018 qpol_iterator_t *iter; 1019 if (qpol_policy_get_default_object_iter(self, &iter)) { 1020 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1021 } 1022 return iter; 1023 fail: 1024 return NULL; 1025 }; 1026 1027 %newobject iomemcon_iter(); 1028 %pythoncode %{ @QpolGenerator(_qpol.qpol_iomemcon_from_void) %} 1029 qpol_iterator_t *iomemcon_iter() { 1030 qpol_iterator_t *iter; 1031 if (qpol_policy_get_iomemcon_iter(self, &iter)) { 1032 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1033 } 1034 return iter; 1035 fail: 1036 return NULL; 1037 }; 1038 size_t iomemcon_count() { 1039 qpol_iterator_t *iter; 1040 size_t count = 0; 1041 if (qpol_policy_get_iomemcon_iter(self, &iter)) { 1042 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1043 } 1044 qpol_iterator_get_size(iter, &count); 1045 return count; 1046 fail: 1047 return 0; 1048 }; 1049 1050 %newobject ioportcon_iter(); 1051 %pythoncode %{ @QpolGenerator(_qpol.qpol_ioportcon_from_void) %} 1052 qpol_iterator_t *ioportcon_iter() { 1053 qpol_iterator_t *iter; 1054 if (qpol_policy_get_ioportcon_iter(self, &iter)) { 1055 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1056 } 1057 return iter; 1058 fail: 1059 return NULL; 1060 }; 1061 1062 size_t ioportcon_count() { 1063 qpol_iterator_t *iter; 1064 size_t count = 0; 1065 if (qpol_policy_get_ioportcon_iter(self, &iter)) { 1066 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1067 } 1068 qpol_iterator_get_size(iter, &count); 1069 return count; 1070 fail: 1071 return 0; 1072 }; 1073 1074 %newobject pcidevicecon_iter(); 1075 %pythoncode %{ @QpolGenerator(_qpol.qpol_pcidevicecon_from_void) %} 1076 qpol_iterator_t *pcidevicecon_iter() { 1077 qpol_iterator_t *iter; 1078 if (qpol_policy_get_pcidevicecon_iter(self, &iter)) { 1079 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1080 } 1081 return iter; 1082 fail: 1083 return NULL; 1084 }; 1085 size_t pcidevicecon_count() { 1086 qpol_iterator_t *iter; 1087 size_t count = 0; 1088 if (qpol_policy_get_pcidevicecon_iter(self, &iter)) { 1089 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1090 } 1091 qpol_iterator_get_size(iter, &count); 1092 return count; 1093 fail: 1094 return 0; 1095 }; 1096 1097 %newobject pirqcon_iter(); 1098 %pythoncode %{ @QpolGenerator(_qpol.qpol_pirqcon_from_void) %} 1099 qpol_iterator_t *pirqcon_iter() { 1100 qpol_iterator_t *iter; 1101 if (qpol_policy_get_pirqcon_iter(self, &iter)) { 1102 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1103 } 1104 return iter; 1105 fail: 1106 return NULL; 1107 }; 1108 size_t pirqcon_count() { 1109 qpol_iterator_t *iter; 1110 size_t count = 0; 1111 if (qpol_policy_get_pirqcon_iter(self, &iter)) { 1112 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1113 } 1114 qpol_iterator_get_size(iter, &count); 1115 return count; 1116 fail: 1117 return 0; 1118 }; 1119 1120 %newobject devicetreecon_iter(); 1121 %pythoncode %{ @QpolGenerator(_qpol.qpol_devicetreecon_from_void) %} 1122 qpol_iterator_t *devicetreecon_iter() { 1123 qpol_iterator_t *iter; 1124 if (qpol_policy_get_devicetreecon_iter(self, &iter)) { 1125 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1126 } 1127 return iter; 1128 fail: 1129 return NULL; 1130 }; 1131 size_t devicetreecon_count() { 1132 qpol_iterator_t *iter; 1133 size_t count = 0; 1134 if (qpol_policy_get_devicetreecon_iter(self, &iter)) { 1135 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1136 } 1137 qpol_iterator_get_size(iter, &count); 1138 return count; 1139 fail: 1140 return 0; 1141 }; 1142 }; 1143 1144 /* qpol iterator */ 1145 typedef struct qpol_iterator {} qpol_iterator_t; 1146 %extend qpol_iterator { 1147 /* user never directly creates, but SWIG expects a constructor */ 1148 qpol_iterator() { 1149 SWIG_exception(SWIG_TypeError, "User may not create iterators difectly"); 1150 fail: 1151 return NULL; 1152 }; 1153 ~qpol_iterator() { 1154 qpol_iterator_destroy(&self); 1155 }; 1156 void *item() { 1157 void *i; 1158 if (qpol_iterator_get_item(self, &i)) { 1159 SWIG_exception(SWIG_RuntimeError, "Could not get item"); 1160 } 1161 return i; 1162 fail: 1163 return NULL; 1164 }; 1165 void next_() { 1166 if (qpol_iterator_next(self)) { 1167 SWIG_exception(SWIG_RuntimeError, "Error advancing iterator"); 1168 } 1169 fail: 1170 return; 1171 }; 1172 int isend() { 1173 return qpol_iterator_end(self); 1174 }; 1175 size_t size() { 1176 size_t s; 1177 if (qpol_iterator_get_size(self, &s)) { 1178 SWIG_exception(SWIG_ValueError, "Could not get iterator size"); 1179 } 1180 return s; 1181 fail: 1182 return 0; 1183 }; 1184 }; 1185 1186 /* qpol type */ 1187 typedef struct qpol_type {} qpol_type_t; 1188 %extend qpol_type { 1189 %exception qpol_type { 1190 $action 1191 if (!result) { 1192 PyErr_SetString(PyExc_ValueError, "Invalid type or attribute."); 1193 return NULL; 1194 } 1195 } 1196 qpol_type(qpol_policy_t *p, const char *name) { 1197 const qpol_type_t *t; 1198 qpol_policy_get_type_by_name(p, name, &t); 1199 return (qpol_type_t*)t; 1200 }; 1201 ~qpol_type() { 1202 /* no op */ 1203 return; 1204 }; 1205 const char *name(qpol_policy_t *p) { 1206 const char *name; 1207 if (qpol_type_get_name(p, self, &name)) { 1208 SWIG_exception(SWIG_ValueError, "Could not get type name"); 1209 } 1210 return name; 1211 fail: 1212 return NULL; 1213 }; 1214 int value(qpol_policy_t *p) { 1215 uint32_t v; 1216 if (qpol_type_get_value(p, self, &v)) { 1217 SWIG_exception(SWIG_ValueError, "Could not get type value"); 1218 } 1219 fail: 1220 return (int) v; 1221 }; 1222 int isalias(qpol_policy_t *p) { 1223 unsigned char i; 1224 if (qpol_type_get_isalias(p, self, &i)) { 1225 SWIG_exception(SWIG_ValueError, "Could not determine whether type is an alias"); 1226 } 1227 fail: 1228 return (int)i; 1229 }; 1230 int isattr(qpol_policy_t *p) { 1231 unsigned char i; 1232 if (qpol_type_get_isattr(p, self, &i)) { 1233 SWIG_exception(SWIG_ValueError, "Could not determine whether type is an attribute"); 1234 } 1235 fail: 1236 return (int)i; 1237 }; 1238 int ispermissive(qpol_policy_t *p) { 1239 unsigned char i; 1240 if (qpol_type_get_ispermissive(p, self, &i)) { 1241 SWIG_exception(SWIG_ValueError, "Could not determine whether type is permissive"); 1242 } 1243 fail: 1244 return (int)i; 1245 }; 1246 1247 %newobject type_iter(qpol_policy_t*); 1248 %pythoncode %{ @QpolGenerator(_qpol.qpol_type_from_void) %} 1249 qpol_iterator_t *type_iter(qpol_policy_t *p) { 1250 qpol_iterator_t *iter; 1251 int retv = qpol_type_get_type_iter(p, self, &iter); 1252 if (retv < 0) { 1253 SWIG_exception(SWIG_RuntimeError, "Could not get attribute types"); 1254 } else if (retv > 0) { 1255 SWIG_exception(SWIG_TypeError, "Type is not an attribute"); 1256 } 1257 fail: 1258 return iter; 1259 }; 1260 1261 %newobject attr_iter(qpol_policy_t*); 1262 %pythoncode %{ @QpolGenerator(_qpol.qpol_type_from_void) %} 1263 qpol_iterator_t *attr_iter(qpol_policy_t *p) { 1264 qpol_iterator_t *iter; 1265 int retv = qpol_type_get_attr_iter(p, self, &iter); 1266 if (retv < 0) { 1267 SWIG_exception(SWIG_RuntimeError, "Could not get type attributes"); 1268 } else if (retv > 0) { 1269 SWIG_exception(SWIG_TypeError, "Type is an attribute"); 1270 } 1271 fail: 1272 return iter; 1273 }; 1274 1275 %newobject alias_iter(qpol_policy_t*); 1276 %pythoncode %{ @QpolGenerator(_qpol.to_str) %} 1277 qpol_iterator_t *alias_iter(qpol_policy_t *p) { 1278 qpol_iterator_t *iter; 1279 if (qpol_type_get_alias_iter(p, self, &iter)) { 1280 SWIG_exception(SWIG_RuntimeError, "Could not get type aliases"); 1281 } 1282 fail: 1283 return iter; 1284 }; 1285 1286 const char *name(qpol_policy_t *p) { 1287 const char *name; 1288 if (qpol_permissive_get_name(p, self, &name)) { 1289 SWIG_exception(SWIG_ValueError, "Could not get permissive type name"); 1290 } 1291 return name; 1292 fail: 1293 return NULL; 1294 }; 1295 }; 1296 %inline %{ 1297 qpol_type_t *qpol_type_from_void(void *x) { 1298 return (qpol_type_t*)x; 1299 }; 1300 %} 1301 1302 /* qpol role */ 1303 typedef struct qpol_role {} qpol_role_t; 1304 %extend qpol_role { 1305 %exception qpol_role { 1306 $action 1307 if (!result) { 1308 PyErr_SetString(PyExc_ValueError, "Invalid type or attribute."); 1309 return NULL; 1310 } 1311 } 1312 qpol_role(qpol_policy_t *p, const char *name) { 1313 const qpol_role_t *r; 1314 qpol_policy_get_role_by_name(p, name, &r); 1315 return (qpol_role_t*)r; 1316 }; 1317 ~qpol_role() { 1318 /* no op */ 1319 return; 1320 }; 1321 int value (qpol_policy_t *p) { 1322 uint32_t v; 1323 if (qpol_role_get_value(p, self, &v)) { 1324 SWIG_exception(SWIG_ValueError, "Could not get role value"); 1325 } 1326 fail: 1327 return (int) v; 1328 }; 1329 const char *name(qpol_policy_t *p) { 1330 const char *name; 1331 if (qpol_role_get_name(p, self, &name)) { 1332 SWIG_exception(SWIG_ValueError, "Could not get role name"); 1333 } 1334 return name; 1335 fail: 1336 return NULL; 1337 }; 1338 1339 %newobject type_iter(qpol_policy_t*); 1340 %pythoncode %{ @QpolGenerator(_qpol.qpol_type_from_void) %} 1341 qpol_iterator_t *type_iter(qpol_policy_t *p) { 1342 qpol_iterator_t *iter; 1343 if (qpol_role_get_type_iter(p, self, &iter)) { 1344 SWIG_exception(SWIG_RuntimeError, "Could not get role types"); 1345 } 1346 fail: 1347 return iter; 1348 }; 1349 1350 %newobject dominate_iter(qpol_policy_t*); 1351 qpol_iterator_t *dominate_iter(qpol_policy_t *p) { 1352 qpol_iterator_t *iter; 1353 if (qpol_role_get_dominate_iter(p, self, &iter)) { 1354 SWIG_exception(SWIG_RuntimeError, "Could not get dominated roles"); 1355 } 1356 fail: 1357 return iter; 1358 }; 1359 }; 1360 %inline %{ 1361 qpol_role_t *qpol_role_from_void(void *x) { 1362 return (qpol_role_t*)x; 1363 }; 1364 %} 1365 1366 /* qpol level */ 1367 typedef struct qpol_level {} qpol_level_t; 1368 %extend qpol_level { 1369 %exception qpol_level { 1370 $action 1371 if (!result) { 1372 if (errno == EINVAL) { 1373 PyErr_SetString(PyExc_ValueError, "Invalid level."); 1374 } else { 1375 PyErr_SetFromErrno(PyExc_OSError); 1376 } 1377 1378 return NULL; 1379 } 1380 } 1381 qpol_level(qpol_policy_t *p, const char *name) { 1382 const qpol_level_t *l; 1383 qpol_policy_get_level_by_name(p, name, &l); 1384 return (qpol_level_t*)l; 1385 }; 1386 1387 ~qpol_level() { 1388 /* no op */ 1389 return; 1390 }; 1391 int isalias(qpol_policy_t *p) { 1392 unsigned char i; 1393 if (qpol_level_get_isalias(p, self, &i)) { 1394 SWIG_exception(SWIG_ValueError, "Could not determine whether level is an alias"); 1395 } 1396 fail: 1397 return (int)i; 1398 }; 1399 int value(qpol_policy_t *p) { 1400 uint32_t v; 1401 if (qpol_level_get_value(p, self, &v)) { 1402 SWIG_exception(SWIG_ValueError, "Could not get level sensitivity value"); 1403 } 1404 fail: 1405 return (int) v; 1406 }; 1407 const char *name(qpol_policy_t *p) { 1408 const char *name; 1409 if (qpol_level_get_name(p, self, &name)) { 1410 SWIG_exception(SWIG_ValueError, "Could not get level sensitivity name"); 1411 } 1412 return name; 1413 fail: 1414 return NULL; 1415 }; 1416 1417 %newobject cat_iter(qpol_policy_t*); 1418 %pythoncode %{ @QpolGenerator(_qpol.qpol_cat_from_void) %} 1419 qpol_iterator_t *cat_iter(qpol_policy_t *p) { 1420 qpol_iterator_t *iter; 1421 if (qpol_level_get_cat_iter(p, self, &iter)) { 1422 SWIG_exception(SWIG_RuntimeError, "Could not get level categories"); 1423 } 1424 fail: 1425 return iter; 1426 }; 1427 1428 %newobject alias_iter(qpol_policy_t*); 1429 %pythoncode %{ @QpolGenerator(_qpol.to_str) %} 1430 qpol_iterator_t *alias_iter(qpol_policy_t *p) { 1431 qpol_iterator_t *iter; 1432 if (qpol_level_get_alias_iter(p, self, &iter)) { 1433 SWIG_exception(SWIG_RuntimeError, "Could not get level aliases"); 1434 } 1435 fail: 1436 return iter; 1437 }; 1438 }; 1439 %inline %{ 1440 qpol_level_t *qpol_level_from_void(void *x) { 1441 return (qpol_level_t*)x; 1442 }; 1443 %} 1444 1445 /* qpol cat */ 1446 typedef struct qpol_cat {} qpol_cat_t; 1447 %extend qpol_cat { 1448 %exception qpol_cat { 1449 $action 1450 if (!result) { 1451 if (errno == EINVAL) { 1452 PyErr_SetString(PyExc_ValueError, "Invalid category."); 1453 } else { 1454 PyErr_SetFromErrno(PyExc_OSError); 1455 } 1456 1457 return NULL; 1458 } 1459 } 1460 qpol_cat(qpol_policy_t *p, const char *name) { 1461 const qpol_cat_t *c; 1462 qpol_policy_get_cat_by_name(p, name, &c); 1463 return (qpol_cat_t*)c; 1464 }; 1465 1466 ~qpol_cat() { 1467 /* no op */ 1468 return; 1469 }; 1470 int isalias(qpol_policy_t *p) { 1471 unsigned char i; 1472 if (qpol_cat_get_isalias(p, self, &i)) { 1473 SWIG_exception(SWIG_ValueError, "Could not determine whether category is an alias"); 1474 } 1475 fail: 1476 return (int)i; 1477 }; 1478 int value(qpol_policy_t *p) { 1479 uint32_t v; 1480 if (qpol_cat_get_value(p, self, &v)) { 1481 SWIG_exception(SWIG_ValueError, "Could not get category value"); 1482 } 1483 fail: 1484 return (int) v; 1485 }; 1486 const char *name(qpol_policy_t *p) { 1487 const char *name; 1488 if (qpol_cat_get_name(p, self, &name)) { 1489 SWIG_exception(SWIG_ValueError, "Could not get category name"); 1490 } 1491 return name; 1492 fail: 1493 return NULL; 1494 }; 1495 %newobject alias_iter(qpol_policy_t*); 1496 %pythoncode %{ @QpolGenerator(_qpol.to_str) %} 1497 qpol_iterator_t *alias_iter(qpol_policy_t *p) { 1498 qpol_iterator_t *iter; 1499 if (qpol_cat_get_alias_iter(p, self, &iter)) { 1500 SWIG_exception(SWIG_RuntimeError, "Could not get category aliases"); 1501 } 1502 fail: 1503 return iter; 1504 }; 1505 }; 1506 %inline %{ 1507 qpol_cat_t *qpol_cat_from_void(void *x) { 1508 return (qpol_cat_t*)x; 1509 }; 1510 %} 1511 1512 /* qpol mls range */ 1513 typedef struct qpol_mls_range {} qpol_mls_range_t; 1514 %extend qpol_mls_range { 1515 /* 1516 * TODO: determine how to conditionally destroy this range. 1517 * It should only be destroyed if it was looked up (user-entered) 1518 * Otherwise qpol will destroy the others when the policy closes. 1519 */ 1520 %exception qpol_mls_range { 1521 $action 1522 if (!result) { 1523 if (errno == EINVAL) { 1524 PyErr_SetString(PyExc_ValueError, "Invalid range."); 1525 } else { 1526 PyErr_SetFromErrno(PyExc_OSError); 1527 } 1528 1529 return NULL; 1530 } 1531 } 1532 1533 qpol_mls_range(qpol_policy_t *p, qpol_mls_level_t *l, qpol_mls_level_t *h) { 1534 qpol_mls_range_t *range; 1535 qpol_policy_get_mls_range_from_mls_levels(p, l, h, &range); 1536 return range; 1537 } 1538 1539 ~qpol_mls_range() { 1540 /* no op */ 1541 return; 1542 }; 1543 const qpol_mls_level_t *high_level(qpol_policy_t *p) { 1544 const qpol_mls_level_t *l; 1545 if (qpol_mls_range_get_high_level(p, self, &l)) { 1546 SWIG_exception(SWIG_ValueError, "Could not get range high levl"); 1547 } 1548 fail: 1549 return l; 1550 }; 1551 const qpol_mls_level_t *low_level(qpol_policy_t *p) { 1552 const qpol_mls_level_t *l; 1553 if (qpol_mls_range_get_low_level(p, self, &l)) { 1554 SWIG_exception(SWIG_ValueError, "Could not get range low levl"); 1555 } 1556 fail: 1557 return l; 1558 }; 1559 }; 1560 %inline %{ 1561 qpol_mls_range_t *qpol_mls_range_from_void(void *x) { 1562 return (qpol_mls_range_t*)x; 1563 }; 1564 %} 1565 1566 /* qpol semantic mls level */ 1567 typedef struct qpol_semantic_level {} qpol_semantic_level_t; 1568 %extend qpol_semantic_level { 1569 %exception qpol_semantic_level { 1570 $action 1571 if (!result) { 1572 PyErr_SetString(PyExc_ValueError, "Invalid sensitivity name."); 1573 return NULL; 1574 } 1575 } 1576 1577 qpol_semantic_level(qpol_policy_t *p, const char *name) { 1578 const qpol_semantic_level_t *l; 1579 qpol_policy_get_semantic_level_by_name(p, name, &l); 1580 return (qpol_semantic_level_t*)l; 1581 }; 1582 1583 ~qpol_semantic_level() { 1584 qpol_semantic_level_destroy(self); 1585 return; 1586 }; 1587 1588 %exception add_cats { 1589 $action 1590 if (result) { 1591 PyErr_SetString(PyExc_ValueError, "Invalid category name or category range."); 1592 return NULL; 1593 } 1594 } 1595 int add_cats(qpol_policy_t *p, const char *low, const char *high) { 1596 return qpol_semantic_level_add_cats_by_name(p, self, low, high); 1597 } 1598 }; 1599 1600 /* qpol mls level */ 1601 typedef struct qpol_mls_level {} qpol_mls_level_t; 1602 %extend qpol_mls_level { 1603 %exception qpol_mls_level { 1604 $action 1605 if (!result) { 1606 PyErr_SetString(PyExc_ValueError, "Invalid level."); 1607 return NULL; 1608 } 1609 } 1610 1611 qpol_mls_level(qpol_policy_t *p, qpol_semantic_level_t *l) { 1612 qpol_mls_level_t *level; 1613 qpol_mls_level_from_semantic_level(p, l, &level); 1614 return level; 1615 } 1616 1617 ~qpol_mls_level() { 1618 /* no op */ 1619 return; 1620 }; 1621 const char *sens_name(qpol_policy_t *p) { 1622 const char *name; 1623 if (qpol_mls_level_get_sens_name(p, self, &name)) { 1624 SWIG_exception(SWIG_ValueError, "Could not get level sensitivity name"); 1625 } 1626 fail: 1627 return name; 1628 }; 1629 1630 %newobject cat_iter(qpol_policy_t*); 1631 %pythoncode %{ @QpolGenerator(_qpol.qpol_cat_from_void) %} 1632 qpol_iterator_t *cat_iter(qpol_policy_t *p) { 1633 qpol_iterator_t *iter; 1634 if (qpol_mls_level_get_cat_iter(p, self, &iter)) { 1635 SWIG_exception(SWIG_RuntimeError, "Could not get level categories"); 1636 } 1637 fail: 1638 return iter; 1639 }; 1640 }; 1641 %inline %{ 1642 qpol_mls_level_t *qpol_mls_level_from_void(void *x) { 1643 return (qpol_mls_level_t*)x; 1644 }; 1645 %} 1646 1647 /* qpol user */ 1648 typedef struct qpol_user {} qpol_user_t; 1649 %extend qpol_user { 1650 %exception qpol_user { 1651 $action 1652 if (!result) { 1653 PyErr_SetString(PyExc_ValueError, "Invalid user."); 1654 return NULL; 1655 } 1656 } 1657 qpol_user(qpol_policy_t *p, const char *name) { 1658 const qpol_user_t *u; 1659 qpol_policy_get_user_by_name(p, name, &u); 1660 return (qpol_user_t*)u; 1661 }; 1662 ~qpol_user() { 1663 /* no op */ 1664 return; 1665 }; 1666 int value(qpol_policy_t *p) { 1667 uint32_t v; 1668 if (qpol_user_get_value(p, self, &v)) { 1669 SWIG_exception(SWIG_ValueError, "Could not get user value"); 1670 } 1671 fail: 1672 return (int) v; 1673 }; 1674 1675 %newobject role_iter(qpol_policy_t*); 1676 %pythoncode %{ @QpolGenerator(_qpol.qpol_role_from_void) %} 1677 qpol_iterator_t *role_iter(qpol_policy_t *p) { 1678 qpol_iterator_t *iter; 1679 if (qpol_user_get_role_iter(p, self, &iter)) { 1680 SWIG_exception(SWIG_MemoryError, "Out of Memory"); 1681 } 1682 fail: 1683 return iter; 1684 }; 1685 1686 const qpol_mls_range_t *range(qpol_policy_t *p) { 1687 const qpol_mls_range_t *r; 1688 if (qpol_user_get_range(p, self, &r)) { 1689 SWIG_exception(SWIG_ValueError, "Could not get user range"); 1690 } 1691 fail: 1692 return r; 1693 }; 1694 const char *name(qpol_policy_t *p) { 1695 const char *name; 1696 if (qpol_user_get_name(p, self, &name)) { 1697 SWIG_exception(SWIG_ValueError, "Could not get user name"); 1698 } 1699 fail: 1700 return name; 1701 }; 1702 const qpol_mls_level_t *dfltlevel(qpol_policy_t *p) { 1703 const qpol_mls_level_t *l; 1704 if (qpol_user_get_dfltlevel(p, self, &l)) { 1705 SWIG_exception(SWIG_ValueError, "Could not get user default level"); 1706 } 1707 fail: 1708 return l; 1709 }; 1710 }; 1711 %inline %{ 1712 qpol_user_t *qpol_user_from_void(void *x) { 1713 return (qpol_user_t*)x; 1714 }; 1715 %} 1716 1717 /* qpol bool */ 1718 typedef struct qpol_bool {} qpol_bool_t; 1719 %extend qpol_bool { 1720 qpol_bool(qpol_policy_t *p, const char *name) { 1721 qpol_bool_t *b; 1722 if (qpol_policy_get_bool_by_name(p, name, &b)) { 1723 SWIG_exception(SWIG_RuntimeError, "Boolean does not exist"); 1724 } 1725 fail: 1726 return b; 1727 }; 1728 ~qpol_bool() { 1729 /* no op */ 1730 return; 1731 }; 1732 int value(qpol_policy_t *p) { 1733 uint32_t v; 1734 if (qpol_bool_get_value(p, self, &v)) { 1735 SWIG_exception(SWIG_ValueError, "Could not get boolean value"); 1736 } 1737 fail: 1738 return (int) v; 1739 }; 1740 int state(qpol_policy_t *p) { 1741 int s; 1742 if (qpol_bool_get_state(p, self, &s)) { 1743 SWIG_exception(SWIG_ValueError, "Could not get boolean state"); 1744 } 1745 fail: 1746 return s; 1747 }; 1748 1749 const char *name(qpol_policy_t *p) { 1750 const char *name; 1751 if (qpol_bool_get_name(p, self, &name)) { 1752 SWIG_exception(SWIG_ValueError, "Could not get boolean name"); 1753 } 1754 fail: 1755 return name; 1756 }; 1757 }; 1758 %inline %{ 1759 qpol_bool_t *qpol_bool_from_void(void *x) { 1760 return (qpol_bool_t*)x; 1761 }; 1762 %} 1763 1764 /* qpol context */ 1765 typedef struct qpol_context {} qpol_context_t; 1766 %extend qpol_context { 1767 qpol_context() { 1768 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_context_t objects"); 1769 fail: 1770 return NULL; 1771 }; 1772 ~qpol_context() { 1773 /* no op */ 1774 return; 1775 }; 1776 const qpol_user_t *user(qpol_policy_t *p) { 1777 const qpol_user_t *u; 1778 if (qpol_context_get_user(p, self, &u)) { 1779 SWIG_exception(SWIG_ValueError, "Could not get user from context"); 1780 } 1781 fail: 1782 return u; 1783 }; 1784 const qpol_role_t *role(qpol_policy_t *p) { 1785 const qpol_role_t *r; 1786 if (qpol_context_get_role(p, self, &r)) { 1787 SWIG_exception(SWIG_ValueError, "Could not get role from context"); 1788 } 1789 fail: 1790 return r; 1791 }; 1792 const qpol_type_t *type_(qpol_policy_t *p) { 1793 const qpol_type_t *t; 1794 if (qpol_context_get_type(p, self, &t)) { 1795 SWIG_exception(SWIG_ValueError, "Could not get type from context"); 1796 } 1797 fail: 1798 return t; 1799 }; 1800 const qpol_mls_range_t *range(qpol_policy_t *p) { 1801 const qpol_mls_range_t *r; 1802 if (qpol_context_get_range(p, self, &r)) { 1803 SWIG_exception(SWIG_ValueError, "Could not get range from context"); 1804 } 1805 fail: 1806 return r; 1807 }; 1808 }; 1809 %inline %{ 1810 qpol_context_t *qpol_context_from_void(void *x) { 1811 return (qpol_context_t*)x; 1812 }; 1813 %} 1814 1815 /* qpol class */ 1816 typedef struct qpol_class {} qpol_class_t; 1817 %extend qpol_class { 1818 %exception qpol_class { 1819 $action 1820 if (!result) { 1821 if (errno == EINVAL) { 1822 PyErr_SetString(PyExc_ValueError, "Invalid class."); 1823 } else { 1824 PyErr_SetFromErrno(PyExc_OSError); 1825 } 1826 1827 return NULL; 1828 } 1829 } 1830 qpol_class(qpol_policy_t *p, const char *name) { 1831 const qpol_class_t *c; 1832 qpol_policy_get_class_by_name(p, name, &c); 1833 return (qpol_class_t*)c; 1834 }; 1835 1836 ~qpol_class() { 1837 /* no op */ 1838 return; 1839 }; 1840 int value(qpol_policy_t *p) { 1841 uint32_t v; 1842 if (qpol_class_get_value(p, self, &v)) { 1843 SWIG_exception(SWIG_ValueError, "Could not get value for class"); 1844 } 1845 fail: 1846 return (int) v; 1847 }; 1848 1849 %exception common { 1850 $action 1851 if (!result) { 1852 PyErr_SetString(PyExc_ValueError, "Class does not inherit a common."); 1853 return NULL; 1854 } 1855 } 1856 const qpol_common_t *common(qpol_policy_t *p) { 1857 const qpol_common_t *c; 1858 if(qpol_class_get_common(p, self, &c)) { 1859 SWIG_exception(SWIG_ValueError, "Could not get common for class"); 1860 } 1861 fail: 1862 return c; 1863 }; 1864 %newobject perm_iter(qpol_policy_t*); 1865 %pythoncode %{ @QpolGenerator(_qpol.to_str) %} 1866 qpol_iterator_t *perm_iter(qpol_policy_t *p) { 1867 qpol_iterator_t *iter; 1868 if(qpol_class_get_perm_iter(p, self, &iter)) { 1869 SWIG_exception(SWIG_RuntimeError, "Could not get class permissions"); 1870 } 1871 fail: 1872 return iter; 1873 }; 1874 1875 %newobject constraint_iter(qpol_policy_t*); 1876 %pythoncode %{ @QpolGenerator(_qpol.qpol_constraint_from_void) %} 1877 qpol_iterator_t *constraint_iter(qpol_policy_t *p) { 1878 qpol_iterator_t *iter; 1879 if(qpol_class_get_constraint_iter(p, self, &iter)) { 1880 SWIG_exception(SWIG_RuntimeError, "Could not get class constraints"); 1881 } 1882 fail: 1883 return iter; 1884 }; 1885 1886 %newobject validatetrans_iter(qpol_policy_t*); 1887 %pythoncode %{ @QpolGenerator(_qpol.qpol_validatetrans_from_void) %} 1888 qpol_iterator_t *validatetrans_iter(qpol_policy_t *p) { 1889 qpol_iterator_t *iter; 1890 if(qpol_class_get_validatetrans_iter(p, self, &iter)) { 1891 SWIG_exception(SWIG_RuntimeError, "Could not get class validatetrans statements"); 1892 } 1893 fail: 1894 return iter; 1895 }; 1896 1897 const char *name(qpol_policy_t *p) { 1898 const char *name; 1899 if (qpol_class_get_name(p, self, &name)) { 1900 SWIG_exception(SWIG_ValueError, "Could not get class name"); 1901 } 1902 fail: 1903 return name; 1904 }; 1905 }; 1906 %inline %{ 1907 qpol_class_t *qpol_class_from_void(void *x) { 1908 return (qpol_class_t*)x; 1909 }; 1910 %} 1911 1912 /* qpol common */ 1913 typedef struct qpol_common {} qpol_common_t; 1914 %extend qpol_common { 1915 %exception qpol_common { 1916 $action 1917 if (!result) { 1918 if (errno == EINVAL) { 1919 PyErr_SetString(PyExc_ValueError, "Invalid common."); 1920 } else { 1921 PyErr_SetFromErrno(PyExc_OSError); 1922 } 1923 1924 return NULL; 1925 } 1926 } 1927 qpol_common(qpol_policy_t *p, const char *name) { 1928 const qpol_common_t *c; 1929 qpol_policy_get_common_by_name(p, name, &c); 1930 return (qpol_common_t*)c; 1931 }; 1932 1933 ~qpol_common() { 1934 /* no op */ 1935 return; 1936 }; 1937 int value(qpol_policy_t *p) { 1938 uint32_t v; 1939 if (qpol_common_get_value(p, self, &v)) { 1940 SWIG_exception(SWIG_ValueError, "Could not get value for common"); 1941 } 1942 fail: 1943 return (int) v; 1944 }; 1945 1946 %newobject perm_iter(qpol_policy_t*); 1947 %pythoncode %{ @QpolGenerator(_qpol.to_str) %} 1948 qpol_iterator_t *perm_iter(qpol_policy_t *p) { 1949 qpol_iterator_t *iter; 1950 if(qpol_common_get_perm_iter(p, self, &iter)) { 1951 SWIG_exception(SWIG_RuntimeError, "Could not get common permissions"); 1952 } 1953 fail: 1954 return iter; 1955 }; 1956 1957 const char *name(qpol_policy_t *p) { 1958 const char *name; 1959 if (qpol_common_get_name(p, self, &name)) { 1960 SWIG_exception(SWIG_ValueError, "Could not get common name"); 1961 } 1962 fail: 1963 return name; 1964 }; 1965 }; 1966 %inline %{ 1967 qpol_common_t *qpol_common_from_void(void *x) { 1968 return (qpol_common_t*)x; 1969 }; 1970 %} 1971 1972 /* qpol fs_use */ 1973 /* The defines QPOL_FS_USE_XATTR through QPOL_FS_USE_NONE are 1974 * copied from sepol/policydb/services.h. 1975 * QPOL_FS_USE_PSID is an extension to support v12 policies. */ 1976 #define QPOL_FS_USE_XATTR 1U 1977 #define QPOL_FS_USE_TRANS 2U 1978 #define QPOL_FS_USE_TASK 3U 1979 #define QPOL_FS_USE_GENFS 4U 1980 #define QPOL_FS_USE_NONE 5U 1981 #define QPOL_FS_USE_PSID 6U 1982 typedef struct qpol_fs_use {} qpol_fs_use_t; 1983 %extend qpol_fs_use { 1984 qpol_fs_use(qpol_policy_t *p, const char *name) { 1985 const qpol_fs_use_t *f; 1986 if (qpol_policy_get_fs_use_by_name(p, name, &f)) { 1987 SWIG_exception(SWIG_RuntimeError, "FS Use Statement does not exist"); 1988 } 1989 fail: 1990 return (qpol_fs_use_t*)f; 1991 }; 1992 ~qpol_fs_use() { 1993 /* no op */ 1994 return; 1995 }; 1996 const char *name(qpol_policy_t *p) { 1997 const char *name; 1998 if (qpol_fs_use_get_name(p, self, &name)) { 1999 SWIG_exception(SWIG_ValueError, "Could not get file system name"); 2000 } 2001 fail: 2002 return name; 2003 }; 2004 int behavior(qpol_policy_t *p) { 2005 uint32_t behav; 2006 if (qpol_fs_use_get_behavior(p, self, &behav)) { 2007 SWIG_exception(SWIG_ValueError, "Could not get file system labeling behavior"); 2008 } 2009 fail: 2010 return (int) behav; 2011 }; 2012 const qpol_context_t *context(qpol_policy_t *p) { 2013 uint32_t behav; 2014 const qpol_context_t *ctx = NULL; 2015 qpol_fs_use_get_behavior(p, self, &behav); 2016 if (behav == QPOL_FS_USE_PSID) { 2017 SWIG_exception(SWIG_TypeError, "Cannot get context for fs_use_psid statements"); 2018 } else if (qpol_fs_use_get_context(p, self, &ctx)) { 2019 SWIG_exception(SWIG_ValueError, "Could not get file system context"); 2020 } 2021 fail: 2022 return ctx; 2023 }; 2024 }; 2025 %inline %{ 2026 qpol_fs_use_t *qpol_fs_use_from_void(void *x) { 2027 return (qpol_fs_use_t*)x; 2028 }; 2029 %} 2030 2031 /* qpol genfscon */ 2032 /* values from flask do not change */ 2033 #define QPOL_CLASS_ALL 0U 2034 #define QPOL_CLASS_BLK_FILE 11U 2035 #define QPOL_CLASS_CHR_FILE 10U 2036 #define QPOL_CLASS_DIR 7U 2037 #define QPOL_CLASS_FIFO_FILE 13U 2038 #define QPOL_CLASS_FILE 6U 2039 #define QPOL_CLASS_LNK_FILE 9U 2040 #define QPOL_CLASS_SOCK_FILE 12U 2041 typedef struct qpol_genfscon {} qpol_genfscon_t; 2042 %extend qpol_genfscon { 2043 qpol_genfscon(qpol_policy_t *p, const char *name, const char *path) { 2044 qpol_genfscon_t *g; 2045 if (qpol_policy_get_genfscon_by_name(p, name, path, &g)) { 2046 SWIG_exception(SWIG_RuntimeError, "Genfscon statement does not exist"); 2047 } 2048 fail: 2049 return g; 2050 }; 2051 ~qpol_genfscon() { 2052 free(self); 2053 }; 2054 const char *name(qpol_policy_t *p) { 2055 const char *name; 2056 if (qpol_genfscon_get_name(p, self, &name)) { 2057 SWIG_exception(SWIG_ValueError, "Could not get file system name"); 2058 } 2059 fail: 2060 return name; 2061 }; 2062 const char *path(qpol_policy_t *p) { 2063 const char *path; 2064 if (qpol_genfscon_get_path(p, self, &path)) { 2065 SWIG_exception(SWIG_ValueError, "Could not get file system path"); 2066 } 2067 fail: 2068 return path; 2069 }; 2070 unsigned int object_class(qpol_policy_t *p) { 2071 uint32_t cls; 2072 if (qpol_genfscon_get_class(p, self, &cls)) { 2073 SWIG_exception(SWIG_ValueError, "Could not get genfscon statement class"); 2074 } 2075 switch (cls) { 2076 case QPOL_CLASS_BLK_FILE: return S_IFBLK; 2077 case QPOL_CLASS_CHR_FILE: return S_IFCHR; 2078 case QPOL_CLASS_DIR: return S_IFDIR; 2079 case QPOL_CLASS_FIFO_FILE: return S_IFIFO; 2080 case QPOL_CLASS_FILE: return S_IFREG; 2081 case QPOL_CLASS_LNK_FILE: return S_IFLNK; 2082 case QPOL_CLASS_SOCK_FILE: return S_IFSOCK; 2083 default: return 0; /* all file types */ 2084 } 2085 fail: 2086 return 0; 2087 }; 2088 const qpol_context_t *context(qpol_policy_t *p) { 2089 const qpol_context_t *ctx; 2090 if (qpol_genfscon_get_context(p, self, &ctx)) { 2091 SWIG_exception(SWIG_ValueError, "Could not get context for genfscon statement"); 2092 } 2093 fail: 2094 return ctx; 2095 }; 2096 }; 2097 %inline %{ 2098 qpol_genfscon_t *qpol_genfscon_from_void(void *x) { 2099 return (qpol_genfscon_t*)x; 2100 }; 2101 %} 2102 2103 /* qpol isid */ 2104 typedef struct qpol_isid {} qpol_isid_t; 2105 %extend qpol_isid { 2106 %exception qpol_isid { 2107 $action 2108 if (!result) { 2109 if (errno == EINVAL) { 2110 PyErr_SetString(PyExc_ValueError, "Invalid initial sid name."); 2111 } else { 2112 PyErr_SetFromErrno(PyExc_OSError); 2113 } 2114 2115 return NULL; 2116 } 2117 } 2118 qpol_isid(qpol_policy_t *p, const char *name) { 2119 const qpol_isid_t *i; 2120 qpol_policy_get_isid_by_name(p, name, &i); 2121 return (qpol_isid_t*)i; 2122 }; 2123 2124 ~qpol_isid() { 2125 /* no op */ 2126 return; 2127 }; 2128 const char *name(qpol_policy_t *p) { 2129 const char *name; 2130 if (qpol_isid_get_name(p, self, &name)) { 2131 SWIG_exception(SWIG_ValueError, "Could not get name for initial sid"); 2132 } 2133 fail: 2134 return name; 2135 }; 2136 const qpol_context_t *context(qpol_policy_t *p) { 2137 const qpol_context_t *ctx; 2138 if (qpol_isid_get_context(p, self, &ctx)) { 2139 SWIG_exception(SWIG_ValueError, "Could not get context for initial sid"); 2140 } 2141 fail: 2142 return ctx; 2143 }; 2144 }; 2145 %inline %{ 2146 qpol_isid_t *qpol_isid_from_void(void *x) { 2147 return (qpol_isid_t*)x; 2148 }; 2149 %} 2150 2151 /* qpol netifcon */ 2152 typedef struct qpol_netifcon {} qpol_netifcon_t; 2153 %extend qpol_netifcon { 2154 qpol_netifcon(qpol_policy_t *p, const char *name) { 2155 const qpol_netifcon_t *n; 2156 if (qpol_policy_get_netifcon_by_name(p, name, &n)) { 2157 SWIG_exception(SWIG_RuntimeError, "Netifcon statement does not exist"); 2158 } 2159 fail: 2160 return (qpol_netifcon_t*)n; 2161 }; 2162 ~qpol_netifcon() { 2163 /* no op */ 2164 return; 2165 }; 2166 const char *name(qpol_policy_t *p) { 2167 const char *name; 2168 if (qpol_netifcon_get_name(p, self, &name)) { 2169 SWIG_exception(SWIG_ValueError, "Could not get name for netifcon statement"); 2170 } 2171 fail: 2172 return name; 2173 }; 2174 const qpol_context_t *msg_con(qpol_policy_t *p) { 2175 const qpol_context_t *ctx; 2176 if (qpol_netifcon_get_msg_con(p, self, &ctx)) { 2177 SWIG_exception(SWIG_ValueError, "Could not get message context for netifcon statement"); 2178 } 2179 fail: 2180 return ctx; 2181 }; 2182 const qpol_context_t *if_con(qpol_policy_t *p) { 2183 const qpol_context_t *ctx; 2184 if (qpol_netifcon_get_if_con(p, self, &ctx)) { 2185 SWIG_exception(SWIG_ValueError, "Could not get interface context for netifcon statement"); 2186 } 2187 fail: 2188 return ctx; 2189 }; 2190 }; 2191 %inline %{ 2192 qpol_netifcon_t *qpol_netifcon_from_void(void *x) { 2193 return (qpol_netifcon_t*)x; 2194 }; 2195 %} 2196 2197 /* qpol nodecon */ 2198 #define QPOL_IPV4 0 2199 #define QPOL_IPV6 1 2200 typedef struct qpol_nodecon {} qpol_nodecon_t; 2201 %extend qpol_nodecon { 2202 qpol_nodecon(qpol_policy_t *p, int addr[4], int mask[4], int protocol) { 2203 uint32_t a[4], m[4]; 2204 qpol_nodecon_t *n; 2205 a[0] = (uint32_t) addr[0]; a[1] = (uint32_t) addr[1]; 2206 a[2] = (uint32_t) addr[2]; a[3] = (uint32_t) addr[3]; 2207 m[0] = (uint32_t) mask[0]; m[1] = (uint32_t) mask[1]; 2208 m[2] = (uint32_t) mask[2]; m[3] = (uint32_t) mask[3]; 2209 if (qpol_policy_get_nodecon_by_node(p, a, m, protocol, &n)) { 2210 SWIG_exception(SWIG_RuntimeError, "Nodecon statement does not exist"); 2211 } 2212 fail: 2213 return n; 2214 } 2215 ~qpol_nodecon() { 2216 free(self); 2217 }; 2218 char *addr(qpol_policy_t *p) { 2219 uint32_t *a; 2220 unsigned char proto; 2221 char *addr = NULL; 2222 2223 addr = malloc(INET6_ADDRSTRLEN * sizeof(char)); 2224 if(!addr) 2225 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2226 2227 if (qpol_nodecon_get_addr(p, self, &a, &proto)) { 2228 SWIG_exception(SWIG_ValueError, "Could not get address of nodecon statement"); 2229 } 2230 2231 if(proto == QPOL_IPV4) { 2232 inet_ntop(AF_INET, a, addr, INET6_ADDRSTRLEN); 2233 } else { 2234 inet_ntop(AF_INET6, a, addr, INET6_ADDRSTRLEN); 2235 } 2236 2237 fail: 2238 return addr; 2239 }; 2240 char *mask(qpol_policy_t *p) { 2241 uint32_t *m; 2242 unsigned char proto; 2243 char *mask; 2244 mask = malloc(INET6_ADDRSTRLEN * sizeof(char)); 2245 if (!mask) 2246 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2247 2248 if (qpol_nodecon_get_mask(p, self, &m, &proto)) { 2249 SWIG_exception(SWIG_ValueError, "Could not get mask of nodecon statement"); 2250 } 2251 2252 if(proto == QPOL_IPV4) { 2253 inet_ntop(AF_INET, m, mask, INET6_ADDRSTRLEN); 2254 } else { 2255 inet_ntop(AF_INET6, m, mask, INET6_ADDRSTRLEN); 2256 } 2257 fail: 2258 return mask; 2259 }; 2260 int protocol(qpol_policy_t *p) { 2261 unsigned char proto; 2262 if (qpol_nodecon_get_protocol(p, self, &proto)) { 2263 SWIG_exception(SWIG_ValueError, "Could not get protocol for nodecon statement"); 2264 } 2265 fail: 2266 if(proto == QPOL_IPV4) { 2267 return AF_INET; 2268 } else { 2269 return AF_INET6; 2270 } 2271 }; 2272 const qpol_context_t *context(qpol_policy_t *p) { 2273 const qpol_context_t *ctx; 2274 if (qpol_nodecon_get_context(p, self, &ctx)) { 2275 SWIG_exception(SWIG_ValueError, "Could not get context for nodecon statement"); 2276 } 2277 fail: 2278 return ctx; 2279 }; 2280 }; 2281 %inline %{ 2282 qpol_nodecon_t *qpol_nodecon_from_void(void *x) { 2283 return (qpol_nodecon_t*)x; 2284 }; 2285 %} 2286 2287 /* qpol portcon */ 2288 /* from netinet/in.h */ 2289 #define IPPROTO_TCP 6 2290 #define IPPROTO_UDP 17 2291 typedef struct qpol_portcon {} qpol_portcon_t; 2292 %extend qpol_portcon { 2293 qpol_portcon(qpol_policy_t *p, uint16_t low, uint16_t high, uint8_t protocol) { 2294 const qpol_portcon_t *qp; 2295 if (qpol_policy_get_portcon_by_port(p, low, high, protocol, &qp)) { 2296 SWIG_exception(SWIG_RuntimeError, "Portcon statement does not exist"); 2297 } 2298 fail: 2299 return (qpol_portcon_t*)qp; 2300 }; 2301 ~qpol_portcon() { 2302 /* no op */ 2303 return; 2304 }; 2305 uint16_t low_port(qpol_policy_t *p) { 2306 uint16_t port = 0; 2307 if(qpol_portcon_get_low_port(p, self, &port)) { 2308 SWIG_exception(SWIG_RuntimeError, "Could not get low port for portcon statement"); 2309 } 2310 fail: 2311 return port; 2312 }; 2313 uint16_t high_port(qpol_policy_t *p) { 2314 uint16_t port = 0; 2315 if(qpol_portcon_get_high_port(p, self, &port)) { 2316 SWIG_exception(SWIG_RuntimeError, "Could not get high port for portcon statement"); 2317 } 2318 fail: 2319 return port; 2320 }; 2321 uint8_t protocol(qpol_policy_t *p) { 2322 uint8_t proto = 0; 2323 if (qpol_portcon_get_protocol(p, self, &proto)) { 2324 SWIG_exception(SWIG_RuntimeError, "Could not get protocol for portcon statement"); 2325 } 2326 fail: 2327 return proto; 2328 }; 2329 const qpol_context_t *context(qpol_policy_t *p) { 2330 const qpol_context_t *ctx; 2331 if (qpol_portcon_get_context(p, self, &ctx)) { 2332 SWIG_exception(SWIG_ValueError, "Could not get context for portcon statement"); 2333 } 2334 fail: 2335 return ctx; 2336 }; 2337 } 2338 %inline %{ 2339 qpol_portcon_t *qpol_portcon_from_void(void *x) { 2340 return (qpol_portcon_t*)x; 2341 }; 2342 %} 2343 2344 /* qpol constraint */ 2345 typedef struct qpol_constraint {} qpol_constraint_t; 2346 %extend qpol_constraint { 2347 qpol_constraint() { 2348 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_constraint_t objects"); 2349 fail: 2350 return NULL; 2351 }; 2352 ~qpol_constraint() { 2353 free(self); 2354 }; 2355 const qpol_class_t *object_class(qpol_policy_t *p) { 2356 const qpol_class_t *cls; 2357 if (qpol_constraint_get_class(p, self, &cls)) { 2358 SWIG_exception(SWIG_ValueError, "Could not get class for constraint"); 2359 } 2360 fail: 2361 return cls; 2362 }; 2363 2364 %newobject perm_iter(qpol_policy_t*); 2365 %pythoncode %{ @QpolGenerator(_qpol.to_str) %} 2366 qpol_iterator_t *perm_iter(qpol_policy_t *p) { 2367 qpol_iterator_t *iter; 2368 if (qpol_constraint_get_perm_iter(p, self, &iter)) { 2369 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2370 } 2371 fail: 2372 return iter; 2373 }; 2374 2375 %newobject expr_iter(qpol_policy_t*); 2376 %pythoncode %{ @QpolGenerator(_qpol.qpol_constraint_expr_node_from_void) %} 2377 qpol_iterator_t *expr_iter(qpol_policy_t *p) { 2378 qpol_iterator_t *iter; 2379 if (qpol_constraint_get_expr_iter(p, self, &iter)) { 2380 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2381 } 2382 fail: 2383 return iter; 2384 }; 2385 }; 2386 %inline %{ 2387 qpol_constraint_t *qpol_constraint_from_void(void *x) { 2388 return (qpol_constraint_t*)x; 2389 }; 2390 %} 2391 2392 /* qpol validatetrans */ 2393 typedef struct qpol_validatetrans {} qpol_validatetrans_t; 2394 %extend qpol_validatetrans { 2395 qpol_validatetrans() { 2396 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_validatetrans_t objects"); 2397 fail: 2398 return NULL; 2399 }; 2400 ~qpol_validatetrans() { 2401 free(self); 2402 }; 2403 const qpol_class_t *object_class(qpol_policy_t *p) { 2404 const qpol_class_t *cls; 2405 if (qpol_validatetrans_get_class(p, self, &cls)) { 2406 SWIG_exception(SWIG_ValueError, "Could not get class for validatetrans"); 2407 } 2408 fail: 2409 return cls; 2410 }; 2411 %newobject expr_iter(qpol_policy_t*); 2412 %pythoncode %{ @QpolGenerator(_qpol.qpol_constraint_expr_node_from_void) %} 2413 qpol_iterator_t *expr_iter(qpol_policy_t *p) { 2414 qpol_iterator_t *iter; 2415 if (qpol_validatetrans_get_expr_iter(p, self, &iter)) { 2416 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2417 } 2418 fail: 2419 return iter; 2420 }; 2421 }; 2422 %inline %{ 2423 qpol_validatetrans_t *qpol_validatetrans_from_void(void *x) { 2424 return (qpol_validatetrans_t*)x; 2425 }; 2426 %} 2427 2428 /* qpol constraint expression node */ 2429 /* expr_type values */ 2430 #define QPOL_CEXPR_TYPE_NOT 1 2431 #define QPOL_CEXPR_TYPE_AND 2 2432 #define QPOL_CEXPR_TYPE_OR 3 2433 #define QPOL_CEXPR_TYPE_ATTR 4 2434 #define QPOL_CEXPR_TYPE_NAMES 5 2435 /* symbol type values */ 2436 #define QPOL_CEXPR_SYM_USER 1 2437 #define QPOL_CEXPR_SYM_ROLE 2 2438 #define QPOL_CEXPR_SYM_TYPE 4 2439 #define QPOL_CEXPR_SYM_TARGET 8 2440 #define QPOL_CEXPR_SYM_XTARGET 16 2441 #define QPOL_CEXPR_SYM_L1L2 32 2442 #define QPOL_CEXPR_SYM_L1H2 64 2443 #define QPOL_CEXPR_SYM_H1L2 128 2444 #define QPOL_CEXPR_SYM_H1H2 256 2445 #define QPOL_CEXPR_SYM_L1H1 512 2446 #define QPOL_CEXPR_SYM_L2H2 1024 2447 /* op values */ 2448 #define QPOL_CEXPR_OP_EQ 1 2449 #define QPOL_CEXPR_OP_NEQ 2 2450 #define QPOL_CEXPR_OP_DOM 3 2451 #define QPOL_CEXPR_OP_DOMBY 4 2452 #define QPOL_CEXPR_OP_INCOMP 5 2453 typedef struct qpol_constraint_expr_node {} qpol_constraint_expr_node_t; 2454 %extend qpol_constraint_expr_node { 2455 qpol_constraint_expr_node() { 2456 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_constraint_expr_node_t objects"); 2457 fail: 2458 return NULL; 2459 }; 2460 ~qpol_constraint_expr_node() { 2461 /* no op */ 2462 return; 2463 }; 2464 int expr_type(qpol_policy_t *p) { 2465 uint32_t et; 2466 if (qpol_constraint_expr_node_get_expr_type(p, self, &et)) { 2467 SWIG_exception(SWIG_ValueError, "Could not get expression type for node"); 2468 } 2469 fail: 2470 return (int) et; 2471 }; 2472 int sym_type(qpol_policy_t *p) { 2473 uint32_t st; 2474 if (qpol_constraint_expr_node_get_sym_type(p, self, &st)) { 2475 SWIG_exception(SWIG_ValueError, "Could not get symbol type for node"); 2476 } 2477 fail: 2478 return (int) st; 2479 }; 2480 int op(qpol_policy_t *p) { 2481 uint32_t op; 2482 if (qpol_constraint_expr_node_get_op(p, self, &op)) { 2483 SWIG_exception(SWIG_ValueError, "Could not get operator for node"); 2484 } 2485 fail: 2486 return (int) op; 2487 }; 2488 %newobject names_iter(qpol_policy_t*); 2489 %pythoncode %{ @QpolGenerator(_qpol.to_str) %} 2490 qpol_iterator_t *names_iter(qpol_policy_t *p) { 2491 qpol_iterator_t *iter; 2492 if (qpol_constraint_expr_node_get_names_iter(p, self, &iter)) { 2493 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2494 } 2495 fail: 2496 return iter; 2497 }; 2498 }; 2499 %inline %{ 2500 qpol_constraint_expr_node_t *qpol_constraint_expr_node_from_void(void *x) { 2501 return (qpol_constraint_expr_node_t*)x; 2502 }; 2503 %} 2504 2505 /* qpol role allow */ 2506 typedef struct qpol_role_allow {} qpol_role_allow_t; 2507 %extend qpol_role_allow { 2508 qpol_role_allow() { 2509 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_role_allow_t objects"); 2510 fail: 2511 return NULL; 2512 }; 2513 ~qpol_role_allow() { 2514 /* no op */ 2515 return; 2516 }; 2517 %pythoncode %{ 2518 def rule_type(self,policy): 2519 return "allow" 2520 %} 2521 const qpol_role_t *source_role(qpol_policy_t *p) { 2522 const qpol_role_t *r; 2523 if (qpol_role_allow_get_source_role(p, self, &r)) { 2524 SWIG_exception(SWIG_ValueError, "Could not get source for role allow rule"); 2525 } 2526 fail: 2527 return r; 2528 }; 2529 const qpol_role_t *target_role(qpol_policy_t *p) { 2530 const qpol_role_t *r; 2531 if (qpol_role_allow_get_target_role(p, self, &r)) { 2532 SWIG_exception(SWIG_ValueError, "Could not get target for role allow rule"); 2533 } 2534 fail: 2535 return r; 2536 }; 2537 }; 2538 %inline %{ 2539 qpol_role_allow_t *qpol_role_allow_from_void(void *x) { 2540 return (qpol_role_allow_t*)x; 2541 }; 2542 %} 2543 2544 /* qpol role trans */ 2545 typedef struct qpol_role_trans {} qpol_role_trans_t; 2546 %extend qpol_role_trans { 2547 qpol_role_trans() { 2548 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_role_trans_t objects"); 2549 fail: 2550 return NULL; 2551 }; 2552 ~qpol_role_trans() { 2553 /* no op */ 2554 return; 2555 }; 2556 %pythoncode %{ 2557 def rule_type(self,policy): 2558 return "role_transition" 2559 %} 2560 const qpol_role_t *source_role(qpol_policy_t *p) { 2561 const qpol_role_t *r; 2562 if (qpol_role_trans_get_source_role(p, self, &r)) { 2563 SWIG_exception(SWIG_ValueError, "Could not get source for role_transition rule"); 2564 } 2565 fail: 2566 return r; 2567 }; 2568 const qpol_type_t *target_type(qpol_policy_t *p) { 2569 const qpol_type_t *t; 2570 if (qpol_role_trans_get_target_type(p, self, &t)) { 2571 SWIG_exception(SWIG_ValueError, "Could not get target for role_transition rule"); 2572 } 2573 fail: 2574 return t; 2575 }; 2576 const qpol_class_t *object_class(qpol_policy_t *p) { 2577 const qpol_class_t *c; 2578 if (qpol_role_trans_get_object_class(p, self, &c)) { 2579 SWIG_exception(SWIG_ValueError, "Could not get class for role_transition rule"); 2580 } 2581 fail: 2582 return c; 2583 }; 2584 const qpol_role_t *default_role(qpol_policy_t *p) { 2585 const qpol_role_t *r; 2586 if (qpol_role_trans_get_default_role(p, self, &r)) { 2587 SWIG_exception(SWIG_ValueError, "Could not get default for role_transition rule"); 2588 } 2589 fail: 2590 return r; 2591 }; 2592 }; 2593 %inline %{ 2594 qpol_role_trans_t *qpol_role_trans_from_void(void *x) { 2595 return (qpol_role_trans_t*)x; 2596 }; 2597 %} 2598 2599 /* qpol range trans */ 2600 typedef struct qpol_range_trans {} qpol_range_trans_t; 2601 %extend qpol_range_trans { 2602 qpol_range_trans() { 2603 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_range_trans_t objects"); 2604 fail: 2605 return NULL; 2606 }; 2607 ~qpol_range_trans() { 2608 /* no op */ 2609 return; 2610 }; 2611 %pythoncode %{ 2612 def rule_type(self,policy): 2613 return "range_transition" 2614 %} 2615 2616 const qpol_type_t *source_type (qpol_policy_t *p) { 2617 const qpol_type_t *t; 2618 if (qpol_range_trans_get_source_type(p, self, &t)) { 2619 SWIG_exception(SWIG_ValueError, "Could not get source for range_transition rule"); 2620 } 2621 fail: 2622 return t; 2623 }; 2624 const qpol_type_t *target_type (qpol_policy_t *p) { 2625 const qpol_type_t *t; 2626 if (qpol_range_trans_get_target_type(p, self, &t)) { 2627 SWIG_exception(SWIG_ValueError, "Could not get target for range_transition rule"); } 2628 fail: 2629 return t; 2630 }; 2631 const qpol_class_t *object_class(qpol_policy_t *p) { 2632 const qpol_class_t *cls; 2633 if (qpol_range_trans_get_target_class(p, self, &cls)) { 2634 SWIG_exception(SWIG_ValueError, "Could not get class for range_transition rule"); } 2635 fail: 2636 return cls; 2637 }; 2638 const qpol_mls_range_t *range(qpol_policy_t *p) { 2639 const qpol_mls_range_t *r; 2640 if (qpol_range_trans_get_range(p, self, &r)) { 2641 SWIG_exception(SWIG_ValueError, "Could not get range for range_transition rule"); 2642 } 2643 fail: 2644 return r; 2645 }; 2646 }; 2647 %inline %{ 2648 qpol_range_trans_t *qpol_range_trans_from_void(void *x) { 2649 return (qpol_range_trans_t*)x; 2650 }; 2651 %} 2652 2653 /* qpol av rule */ 2654 #define QPOL_RULE_ALLOW 0x0001 2655 #define QPOL_RULE_NEVERALLOW 0x0080 2656 #define QPOL_RULE_AUDITALLOW 0x0002 2657 #define QPOL_RULE_DONTAUDIT 0x0004 2658 #define QPOL_RULE_XPERMS_ALLOW 0x0100 2659 #define QPOL_RULE_XPERMS_AUDITALLOW 0x0200 2660 #define QPOL_RULE_XPERMS_DONTAUDIT 0x0400 2661 #define QPOL_RULE_XPERMS_NEVERALLOW 0x0800 2662 typedef struct qpol_avrule {} qpol_avrule_t; 2663 %extend qpol_avrule { 2664 qpol_avrule() { 2665 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_avrule_t objects"); 2666 fail: 2667 return NULL; 2668 }; 2669 ~qpol_avrule() { 2670 /* no op */ 2671 return; 2672 }; 2673 const char * rule_type(qpol_policy_t *p) { 2674 uint32_t rt; 2675 if (qpol_avrule_get_rule_type(p, self, &rt)) { 2676 SWIG_exception(SWIG_ValueError, "Could not get rule type for av rule"); 2677 } 2678 switch (rt) { 2679 case QPOL_RULE_ALLOW: return "allow"; break; 2680 case QPOL_RULE_NEVERALLOW: return "neverallow"; break; 2681 case QPOL_RULE_AUDITALLOW: return "auditallow"; break; 2682 case QPOL_RULE_DONTAUDIT: return "dontaudit"; break; 2683 case QPOL_RULE_XPERMS_ALLOW: return "allowxperm"; break; 2684 case QPOL_RULE_XPERMS_NEVERALLOW: return "neverallowxperm"; break; 2685 case QPOL_RULE_XPERMS_AUDITALLOW: return "auditallowxperm"; break; 2686 case QPOL_RULE_XPERMS_DONTAUDIT: return "dontauditxperm"; break; 2687 } 2688 fail: 2689 return NULL; 2690 }; 2691 const qpol_type_t *source_type(qpol_policy_t *p) { 2692 const qpol_type_t *t; 2693 if (qpol_avrule_get_source_type(p, self, &t)) { 2694 SWIG_exception(SWIG_ValueError, "Could not get source for av rule"); 2695 } 2696 fail: 2697 return t; 2698 }; 2699 const qpol_type_t *target_type(qpol_policy_t *p) { 2700 const qpol_type_t *t; 2701 if (qpol_avrule_get_target_type(p, self, &t)) { 2702 SWIG_exception(SWIG_ValueError, "Could not get target for av rule"); 2703 } 2704 fail: 2705 return t; 2706 }; 2707 const qpol_class_t *object_class(qpol_policy_t *p) { 2708 const qpol_class_t *cls; 2709 if (qpol_avrule_get_object_class(p, self, &cls)) { 2710 SWIG_exception(SWIG_ValueError, "Could not get class for av rule"); 2711 } 2712 fail: 2713 return cls; 2714 }; 2715 2716 %newobject perm_iter(qpol_policy_t *p); 2717 %pythoncode %{ @QpolGenerator(_qpol.to_str) %} 2718 qpol_iterator_t *perm_iter(qpol_policy_t *p) { 2719 qpol_iterator_t *iter; 2720 if (qpol_avrule_get_perm_iter(p, self, &iter)) { 2721 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2722 } 2723 fail: 2724 return iter; 2725 }; 2726 2727 /* TODO, do I need an exception (similar to cond) that is thrown if you ask this on a non extended avrule? Likewise for asking for prems an an extended rule */ 2728 %newobject xperm_iter(qpol_policy_t *p); 2729 %pythoncode %{ @QpolGenerator(_qpol.to_int_with_free) %} 2730 qpol_iterator_t *xperm_iter(qpol_policy_t *p) { 2731 qpol_iterator_t *iter; 2732 if (qpol_avrule_get_xperm_iter(p, self, &iter)) { 2733 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2734 } 2735 fail: 2736 return iter; 2737 }; 2738 int is_extended(qpol_policy_t *p) { 2739 uint32_t e; 2740 if (qpol_avrule_get_is_extended(p, self, &e)) { 2741 SWIG_exception(SWIG_ValueError, "Could not determine if av rule is extended"); 2742 } 2743 fail: 2744 return (int) e; 2745 }; 2746 const char * xperm_type(qpol_policy_t *p) { 2747 char *xt; 2748 if (qpol_avrule_get_xperm_type(p, self, &xt)) { 2749 SWIG_exception(SWIG_ValueError, "Could not get xperm type for av rule"); 2750 } 2751 fail: 2752 return xt; 2753 }; 2754 2755 %exception cond { 2756 $action 2757 if (!result) { 2758 PyErr_SetString(PyExc_AttributeError, "Rule is not conditional."); 2759 return NULL; 2760 } 2761 } 2762 const qpol_cond_t *cond(qpol_policy_t *p) { 2763 const qpol_cond_t *c; 2764 qpol_avrule_get_cond(p, self, &c); 2765 return c; 2766 }; 2767 int is_enabled(qpol_policy_t *p) { 2768 uint32_t e; 2769 if (qpol_avrule_get_is_enabled(p, self, &e)) { 2770 SWIG_exception(SWIG_ValueError, "Could not determine if av rule is enabled"); 2771 } 2772 fail: 2773 return (int) e; 2774 }; 2775 2776 %exception which_list { 2777 $action 2778 if (result < 0) { 2779 PyErr_SetString(PyExc_AttributeError, "Rule is not conditional."); 2780 return NULL; 2781 } 2782 } 2783 int which_list(qpol_policy_t *p) { 2784 const qpol_cond_t *c; 2785 uint32_t which = 0; 2786 qpol_avrule_get_cond(p, self, &c); 2787 if (c == NULL) { 2788 return -1; 2789 } else if (qpol_avrule_get_which_list(p, self, &which)) { 2790 return -1; 2791 } 2792 return (int) which; 2793 }; 2794 %newobject syn_avrule_iter(qpol_policy_t*); 2795 qpol_iterator_t *syn_avrule_iter(qpol_policy_t *p) { 2796 qpol_iterator_t *iter; 2797 if (qpol_avrule_get_syn_avrule_iter(p, self, &iter)) { 2798 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2799 } 2800 fail: 2801 return iter; 2802 }; 2803 }; 2804 %inline %{ 2805 qpol_avrule_t *qpol_avrule_from_void(void *x) { 2806 return (qpol_avrule_t*)x; 2807 }; 2808 %} 2809 2810 /* qpol te rule */ 2811 #define QPOL_RULE_TYPE_TRANS 16 2812 #define QPOL_RULE_TYPE_CHANGE 64 2813 #define QPOL_RULE_TYPE_MEMBER 32 2814 typedef struct qpol_terule {} qpol_terule_t; 2815 %extend qpol_terule { 2816 qpol_terule() { 2817 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_terule_t objects"); 2818 fail: 2819 return NULL; 2820 }; 2821 ~qpol_terule() { 2822 /* no op */ 2823 return; 2824 }; 2825 const char * rule_type(qpol_policy_t *p) { 2826 uint32_t rt; 2827 if (qpol_terule_get_rule_type(p, self, &rt)) { 2828 SWIG_exception(SWIG_ValueError, "Could not get rule type for te rule"); 2829 } 2830 switch (rt) { 2831 case QPOL_RULE_TYPE_TRANS: return "type_transition"; break; 2832 case QPOL_RULE_TYPE_CHANGE: return "type_change"; break; 2833 case QPOL_RULE_TYPE_MEMBER: return "type_member"; break; 2834 } 2835 fail: 2836 return NULL; 2837 }; 2838 const qpol_type_t *source_type(qpol_policy_t *p) { 2839 const qpol_type_t *t; 2840 if (qpol_terule_get_source_type(p, self, &t)) { 2841 SWIG_exception(SWIG_ValueError, "Could not get source for te rule"); 2842 } 2843 fail: 2844 return t; 2845 }; 2846 const qpol_type_t *target_type(qpol_policy_t *p) { 2847 const qpol_type_t *t; 2848 if (qpol_terule_get_target_type(p, self, &t)) { 2849 SWIG_exception(SWIG_ValueError, "Could not get target for te rule"); 2850 } 2851 fail: 2852 return t; 2853 }; 2854 const qpol_class_t *object_class(qpol_policy_t *p) { 2855 const qpol_class_t *cls; 2856 if (qpol_terule_get_object_class(p, self, &cls)) { 2857 SWIG_exception(SWIG_ValueError, "Could not get class for te rule"); 2858 } 2859 fail: 2860 return cls; 2861 }; 2862 const qpol_type_t *default_type(qpol_policy_t *p) { 2863 const qpol_type_t *t; 2864 if (qpol_terule_get_default_type(p, self, &t)) { 2865 SWIG_exception(SWIG_ValueError, "Could not get default for te rule"); 2866 } 2867 fail: 2868 return t; 2869 }; 2870 2871 %exception cond { 2872 $action 2873 if (!result) { 2874 PyErr_SetString(PyExc_AttributeError, "Rule is not conditional."); 2875 return NULL; 2876 } 2877 } 2878 const qpol_cond_t *cond(qpol_policy_t *p) { 2879 const qpol_cond_t *c; 2880 qpol_terule_get_cond(p, self, &c); 2881 return c; 2882 }; 2883 int is_enabled(qpol_policy_t *p) { 2884 uint32_t e; 2885 if (qpol_terule_get_is_enabled(p, self, &e)) { 2886 SWIG_exception(SWIG_ValueError, "Could not determine if te rule is enabled"); 2887 } 2888 fail: 2889 return (int) e; 2890 }; 2891 2892 %exception which_list { 2893 $action 2894 if (result < 0) { 2895 PyErr_SetString(PyExc_AttributeError, "Rule is not conditional."); 2896 return NULL; 2897 } 2898 } 2899 int which_list(qpol_policy_t *p) { 2900 const qpol_cond_t *c; 2901 uint32_t which = 0; 2902 qpol_terule_get_cond(p, self, &c); 2903 if (c == NULL) { 2904 return -1; 2905 } else if (qpol_terule_get_which_list(p, self, &which)) { 2906 return -1; 2907 } 2908 return (int) which; 2909 }; 2910 2911 %newobject syn_terule_iter(qpol_policy_t*); 2912 qpol_iterator_t *syn_terule_iter(qpol_policy_t *p) { 2913 qpol_iterator_t *iter; 2914 if (qpol_terule_get_syn_terule_iter(p, self, &iter)) { 2915 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2916 } 2917 fail: 2918 return iter; 2919 }; 2920 }; 2921 %inline %{ 2922 qpol_terule_t *qpol_terule_from_void(void *x) { 2923 return (qpol_terule_t*)x; 2924 }; 2925 %} 2926 2927 /* qpol conditional */ 2928 typedef struct qpol_cond {} qpol_cond_t; 2929 %extend qpol_cond { 2930 qpol_cond() { 2931 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_cond_t objects"); 2932 fail: 2933 return NULL; 2934 }; 2935 ~qpol_cond() { 2936 /* no op */ 2937 return; 2938 }; 2939 2940 %newobject expr_node_iter(qpol_policy_t*); 2941 %pythoncode %{ @QpolGenerator(_qpol.qpol_cond_expr_node_from_void) %} 2942 qpol_iterator_t *expr_node_iter(qpol_policy_t *p) { 2943 qpol_iterator_t *iter; 2944 if (qpol_cond_get_expr_node_iter(p, self, &iter)) { 2945 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2946 } 2947 fail: 2948 return iter; 2949 }; 2950 2951 %newobject av_true_iter(qpol_policy_t*, int); 2952 qpol_iterator_t *av_true_iter(qpol_policy_t *p, int rule_types) { 2953 qpol_iterator_t *iter; 2954 if (qpol_cond_get_av_true_iter(p, self, rule_types, &iter)) { 2955 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2956 } 2957 fail: 2958 return iter; 2959 }; 2960 %newobject av_false_iter(qpol_policy_t*, int); 2961 qpol_iterator_t *av_false_iter(qpol_policy_t *p, int rule_types) { 2962 qpol_iterator_t *iter; 2963 if (qpol_cond_get_av_false_iter(p, self, rule_types, &iter)) { 2964 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2965 } 2966 fail: 2967 return iter; 2968 }; 2969 %newobject te_true_iter(qpol_policy_t*, int); 2970 qpol_iterator_t *te_true_iter(qpol_policy_t *p, int rule_types) { 2971 qpol_iterator_t *iter; 2972 if (qpol_cond_get_te_true_iter(p, self, rule_types, &iter)) { 2973 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2974 } 2975 fail: 2976 return iter; 2977 }; 2978 %newobject te_false_iter(qpol_policy_t*, int); 2979 qpol_iterator_t *te_false_iter(qpol_policy_t *p, int rule_types) { 2980 qpol_iterator_t *iter; 2981 if (qpol_cond_get_te_false_iter(p, self, rule_types, &iter)) { 2982 SWIG_exception(SWIG_MemoryError, "Out of memory"); 2983 } 2984 fail: 2985 return iter; 2986 }; 2987 int evaluate(qpol_policy_t *p) { 2988 uint32_t e; 2989 if (qpol_cond_eval(p, self, &e)) { 2990 SWIG_exception(SWIG_RuntimeError, "Could not evaluate conditional"); 2991 } 2992 fail: 2993 return (int) e; 2994 }; 2995 }; 2996 %inline %{ 2997 qpol_cond_t *qpol_cond_from_void(void *x) { 2998 return (qpol_cond_t*)x; 2999 }; 3000 %} 3001 3002 /* qpol conditional expression node */ 3003 #define QPOL_COND_EXPR_BOOL 1 /* plain bool */ 3004 #define QPOL_COND_EXPR_NOT 2 /* !bool */ 3005 #define QPOL_COND_EXPR_OR 3 /* bool || bool */ 3006 #define QPOL_COND_EXPR_AND 4 /* bool && bool */ 3007 #define QPOL_COND_EXPR_XOR 5 /* bool ^ bool */ 3008 #define QPOL_COND_EXPR_EQ 6 /* bool == bool */ 3009 #define QPOL_COND_EXPR_NEQ 7 /* bool != bool */ 3010 typedef struct qpol_cond_expr_node {} qpol_cond_expr_node_t; 3011 %extend qpol_cond_expr_node { 3012 qpol_cond_expr_node() { 3013 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_cond_expr_node_t objects"); 3014 fail: 3015 return NULL; 3016 }; 3017 ~qpol_cond_expr_node() { 3018 /* no op */ 3019 return; 3020 }; 3021 int expr_type(qpol_policy_t *p) { 3022 uint32_t et; 3023 if (qpol_cond_expr_node_get_expr_type(p, self, &et)) { 3024 SWIG_exception(SWIG_ValueError, "Could not get node expression type"); 3025 } 3026 fail: 3027 return (int) et; 3028 }; 3029 qpol_bool_t *get_boolean(qpol_policy_t *p) { 3030 uint32_t et; 3031 qpol_bool_t *b = NULL; 3032 qpol_cond_expr_node_get_expr_type(p, self, &et); 3033 if (et != QPOL_COND_EXPR_BOOL) { 3034 SWIG_exception(SWIG_TypeError, "Node does not contain a boolean"); 3035 } else if (qpol_cond_expr_node_get_bool(p, self, &b)) { 3036 SWIG_exception(SWIG_ValueError, "Could not get boolean for node"); 3037 } 3038 fail: 3039 return b; 3040 }; 3041 }; 3042 %inline %{ 3043 qpol_cond_expr_node_t *qpol_cond_expr_node_from_void(void *x) { 3044 return (qpol_cond_expr_node_t*)x; 3045 }; 3046 %} 3047 3048 /* qpol filename trans */ 3049 typedef struct qpol_filename_trans {} qpol_filename_trans_t; 3050 %extend qpol_filename_trans { 3051 qpol_filename_trans() { 3052 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_filename_trans_t objects"); 3053 fail: 3054 return NULL; 3055 }; 3056 ~qpol_filename_trans() { 3057 /* no op */ 3058 return; 3059 }; 3060 %pythoncode %{ 3061 def rule_type(self,policy): 3062 return "type_transition" 3063 %} 3064 3065 const qpol_type_t *source_type (qpol_policy_t *p) { 3066 const qpol_type_t *t; 3067 if (qpol_filename_trans_get_source_type(p, self, &t)) { 3068 SWIG_exception(SWIG_ValueError, "Could not get source for filename transition rule"); 3069 } 3070 fail: 3071 return t; 3072 }; 3073 const qpol_type_t *target_type (qpol_policy_t *p) { 3074 const qpol_type_t *t; 3075 if (qpol_filename_trans_get_target_type(p, self, &t)) { 3076 SWIG_exception(SWIG_ValueError, "Could not get target for filename transition rule"); } 3077 fail: 3078 return t; 3079 }; 3080 const qpol_class_t *object_class(qpol_policy_t *p) { 3081 const qpol_class_t *cls; 3082 if (qpol_filename_trans_get_object_class(p, self, &cls)) { 3083 SWIG_exception(SWIG_ValueError, "Could not get class for filename transition rule"); } 3084 fail: 3085 return cls; 3086 }; 3087 const qpol_type_t *default_type(qpol_policy_t *p) { 3088 const qpol_type_t *t; 3089 if (qpol_filename_trans_get_default_type(p, self, &t)) { 3090 SWIG_exception(SWIG_ValueError, "Could not get default for filename transition rule"); 3091 } 3092 fail: 3093 return t; 3094 }; 3095 const char *filename(qpol_policy_t *p) { 3096 const char *name; 3097 if (qpol_filename_trans_get_filename(p, self, &name)) { 3098 SWIG_exception(SWIG_ValueError, "Could not get file for filename transition rule"); 3099 } 3100 fail: 3101 return name; 3102 }; 3103 3104 }; 3105 %inline %{ 3106 qpol_filename_trans_t *qpol_filename_trans_from_void(void *x) { 3107 return (qpol_filename_trans_t*)x; 3108 }; 3109 %} 3110 3111 /* qpol polcap */ 3112 typedef struct qpol_polcap {} qpol_polcap_t; 3113 %extend qpol_polcap { 3114 qpol_polcap() { 3115 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_polcap_t objects"); 3116 fail: 3117 return NULL; 3118 }; 3119 ~qpol_polcap() { 3120 /* no op */ 3121 return; 3122 }; 3123 const char *name(qpol_policy_t *p) { 3124 const char *name; 3125 if (qpol_polcap_get_name(p, self, &name)) { 3126 SWIG_exception(SWIG_ValueError, "Could not get polcap name rule"); 3127 } 3128 fail: 3129 return name; 3130 }; 3131 3132 }; 3133 %inline %{ 3134 qpol_polcap_t *qpol_polcap_from_void(void *x) { 3135 return (qpol_polcap_t*)x; 3136 }; 3137 %} 3138 3139 /* qpol typebounds */ 3140 typedef struct qpol_typebounds {} qpol_typebounds_t; 3141 %extend qpol_typebounds { 3142 qpol_typebounds() { 3143 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_typebounds_t objects"); 3144 fail: 3145 return NULL; 3146 }; 3147 ~qpol_typebounds() { 3148 /* no op */ 3149 return; 3150 }; 3151 const char *parent_name(qpol_policy_t *p) { 3152 const char *name; 3153 if (qpol_typebounds_get_parent_name(p, self, &name)) { 3154 SWIG_exception(SWIG_ValueError, "Could not get parent name"); 3155 } 3156 fail: 3157 return name; 3158 }; 3159 const char *child_name(qpol_policy_t *p) { 3160 const char *name; 3161 if (qpol_typebounds_get_child_name(p, self, &name)) { 3162 SWIG_exception(SWIG_ValueError, "Could not get child name"); 3163 } 3164 fail: 3165 return name; 3166 }; 3167 }; 3168 %inline %{ 3169 qpol_typebounds_t *qpol_typebounds_from_void(void *x) { 3170 return (qpol_typebounds_t*)x; 3171 }; 3172 %} 3173 3174 /* qpol rolebounds */ 3175 typedef struct qpol_rolebounds {} qpol_rolebounds_t; 3176 %extend qpol_rolebounds { 3177 qpol_rolebounds() { 3178 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_rolebounds_t objects"); 3179 fail: 3180 return NULL; 3181 }; 3182 ~qpol_rolebounds() { 3183 /* no op */ 3184 return; 3185 }; 3186 const char *parent_name(qpol_policy_t *p) { 3187 const char *name; 3188 if (qpol_rolebounds_get_parent_name(p, self, &name)) { 3189 SWIG_exception(SWIG_ValueError, "Could not get parent name"); 3190 } 3191 fail: 3192 return name; 3193 }; 3194 const char *child_name(qpol_policy_t *p) { 3195 const char *name; 3196 if (qpol_rolebounds_get_child_name(p, self, &name)) { 3197 SWIG_exception(SWIG_ValueError, "Could not get child name"); 3198 } 3199 fail: 3200 return name; 3201 }; 3202 }; 3203 %inline %{ 3204 qpol_rolebounds_t *qpol_rolebounds_from_void(void *x) { 3205 return (qpol_rolebounds_t*)x; 3206 }; 3207 %} 3208 3209 /* qpol userbounds */ 3210 typedef struct qpol_userbounds {} qpol_userbounds_t; 3211 %extend qpol_userbounds { 3212 qpol_userbounds() { 3213 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_userbounds_t objects"); 3214 fail: 3215 return NULL; 3216 }; 3217 ~qpol_userbounds() { 3218 /* no op */ 3219 return; 3220 }; 3221 const char *parent_name(qpol_policy_t *p) { 3222 const char *name; 3223 if (qpol_userbounds_get_parent_name(p, self, &name)) { 3224 SWIG_exception(SWIG_ValueError, "Could not get parent name"); 3225 } 3226 fail: 3227 return name; 3228 }; 3229 const char *child_name(qpol_policy_t *p) { 3230 const char *name; 3231 if (qpol_userbounds_get_child_name(p, self, &name)) { 3232 SWIG_exception(SWIG_ValueError, "Could not get child name"); 3233 } 3234 fail: 3235 return name; 3236 }; 3237 }; 3238 %inline %{ 3239 qpol_userbounds_t *qpol_userbounds_from_void(void *x) { 3240 return (qpol_userbounds_t*)x; 3241 }; 3242 %} 3243 3244 /* qpol default_object */ 3245 typedef struct qpol_default_object {} qpol_default_object_t; 3246 %extend qpol_default_object { 3247 qpol_default_object() { 3248 SWIG_exception(SWIG_RuntimeError, "Cannot directly create qpol_default_object_t objects"); 3249 fail: 3250 return NULL; 3251 }; 3252 ~qpol_default_object() { 3253 /* no op */ 3254 return; 3255 }; 3256 3257 %newobject object_class(); 3258 const qpol_class_t *object_class(qpol_policy_t *p) { 3259 const qpol_class_t *cls; 3260 if (qpol_default_object_get_class(p, self, &cls)) { 3261 SWIG_exception(SWIG_ValueError, "Could not get class"); 3262 } 3263 fail: 3264 return cls; 3265 }; 3266 3267 const char *user_default(qpol_policy_t *p) { 3268 const char *value; 3269 if (qpol_default_object_get_user_default(p, self, &value)) { 3270 SWIG_exception(SWIG_ValueError, "Could not get user default"); 3271 } 3272 fail: 3273 return value; 3274 }; 3275 const char *role_default(qpol_policy_t *p) { 3276 const char *value; 3277 if (qpol_default_object_get_role_default(p, self, &value)) { 3278 SWIG_exception(SWIG_ValueError, "Could not get role default"); 3279 } 3280 fail: 3281 return value; 3282 }; 3283 const char *type_default(qpol_policy_t *p) { 3284 const char *value; 3285 if (qpol_default_object_get_type_default(p, self, &value)) { 3286 SWIG_exception(SWIG_ValueError, "Could not get type default"); 3287 } 3288 fail: 3289 return value; 3290 }; 3291 const char *range_default(qpol_policy_t *p) { 3292 const char *value; 3293 if (qpol_default_object_get_range_default(p, self, &value)) { 3294 SWIG_exception(SWIG_ValueError, "Could not get range defaults"); 3295 } 3296 fail: 3297 return value; 3298 }; 3299 }; 3300 %inline %{ 3301 qpol_default_object_t *qpol_default_object_from_void(void *x) { 3302 return (qpol_default_object_t*)x; 3303 }; 3304 %} 3305 3306 /* qpol iomemcon */ 3307 typedef struct qpol_iomemcon {} qpol_iomemcon_t; 3308 %extend qpol_iomemcon { 3309 qpol_iomemcon(qpol_policy_t *p, uint64_t low, uint64_t high) { 3310 const qpol_iomemcon_t *qp; 3311 if (qpol_policy_get_iomemcon_by_addr(p, low, high, &qp)) { 3312 SWIG_exception(SWIG_RuntimeError, "iomemcon statement does not exist"); 3313 } 3314 fail: 3315 return (qpol_iomemcon_t*)qp; 3316 }; 3317 ~qpol_iomemcon() { 3318 /* no op */ 3319 return; 3320 }; 3321 uint64_t low_addr(qpol_policy_t *p) { 3322 uint64_t addr = 0; 3323 if(qpol_iomemcon_get_low_addr(p, self, &addr)) { 3324 SWIG_exception(SWIG_RuntimeError, "Could not get low addr for iomemcon statement"); 3325 } 3326 fail: 3327 return addr; 3328 }; 3329 uint64_t high_addr(qpol_policy_t *p) { 3330 uint64_t addr = 0; 3331 if(qpol_iomemcon_get_high_addr(p, self, &addr)) { 3332 SWIG_exception(SWIG_RuntimeError, "Could not get high addr for iomemcon statement"); 3333 } 3334 fail: 3335 return addr; 3336 }; 3337 const qpol_context_t *context(qpol_policy_t *p) { 3338 const qpol_context_t *ctx; 3339 if (qpol_iomemcon_get_context(p, self, &ctx)) { 3340 SWIG_exception(SWIG_ValueError, "Could not get context for iomemcon statement"); 3341 } 3342 fail: 3343 return ctx; 3344 }; 3345 } 3346 %inline %{ 3347 qpol_iomemcon_t *qpol_iomemcon_from_void(void *x) { 3348 return (qpol_iomemcon_t*)x; 3349 }; 3350 %} 3351 3352 /* qpol ioportcon */ 3353 typedef struct qpol_ioportcon {} qpol_ioportcon_t; 3354 %extend qpol_ioportcon { 3355 qpol_ioportcon(qpol_policy_t *p, uint32_t low, uint32_t high) { 3356 const qpol_ioportcon_t *qp; 3357 if (qpol_policy_get_ioportcon_by_port(p, low, high, &qp)) { 3358 SWIG_exception(SWIG_RuntimeError, "ioportcon statement does not exist"); 3359 } 3360 fail: 3361 return (qpol_ioportcon_t*)qp; 3362 }; 3363 ~qpol_ioportcon() { 3364 /* no op */ 3365 return; 3366 }; 3367 uint32_t low_port(qpol_policy_t *p) { 3368 uint32_t port = 0; 3369 if(qpol_ioportcon_get_low_port(p, self, &port)) { 3370 SWIG_exception(SWIG_RuntimeError, "Could not get low port for ioportcon statement"); 3371 } 3372 fail: 3373 return port; 3374 }; 3375 uint32_t high_port(qpol_policy_t *p) { 3376 uint32_t port = 0; 3377 if(qpol_ioportcon_get_high_port(p, self, &port)) { 3378 SWIG_exception(SWIG_RuntimeError, "Could not get high port for ioportcon statement"); 3379 } 3380 fail: 3381 return port; 3382 }; 3383 const qpol_context_t *context(qpol_policy_t *p) { 3384 const qpol_context_t *ctx; 3385 if (qpol_ioportcon_get_context(p, self, &ctx)) { 3386 SWIG_exception(SWIG_ValueError, "Could not get context for ioportcon statement"); 3387 } 3388 fail: 3389 return ctx; 3390 }; 3391 } 3392 %inline %{ 3393 qpol_ioportcon_t *qpol_ioportcon_from_void(void *x) { 3394 return (qpol_ioportcon_t*)x; 3395 }; 3396 %} 3397 3398 /* qpol pcidevicecon */ 3399 typedef struct qpol_pcidevicecon {} qpol_pcidevicecon_t; 3400 %extend qpol_pcidevicecon { 3401 qpol_pcidevicecon() { 3402 SWIG_exception(SWIG_RuntimeError, "pcidevicecon statement does not exist"); 3403 fail: 3404 return NULL; 3405 }; 3406 ~qpol_pcidevicecon() { 3407 return; 3408 }; 3409 uint32_t device(qpol_policy_t *p) { 3410 uint32_t device = 0; 3411 if(qpol_pcidevicecon_get_device(p, self, &device)) { 3412 SWIG_exception(SWIG_RuntimeError, "Could not get device for pcidevicecon statement"); 3413 } 3414 fail: 3415 return device; 3416 }; 3417 const qpol_context_t *context(qpol_policy_t *p) { 3418 const qpol_context_t *ctx; 3419 if (qpol_pcidevicecon_get_context(p, self, &ctx)) { 3420 SWIG_exception(SWIG_ValueError, "Could not get context for pcidevicecon statement"); 3421 } 3422 fail: 3423 return ctx; 3424 }; 3425 } 3426 %inline %{ 3427 qpol_pcidevicecon_t *qpol_pcidevicecon_from_void(void *x) { 3428 return (qpol_pcidevicecon_t*)x; 3429 }; 3430 %} 3431 3432 /* qpol pirqcon */ 3433 typedef struct qpol_pirqcon {} qpol_pirqcon_t; 3434 %extend qpol_pirqcon { 3435 qpol_pirqcon() { 3436 SWIG_exception(SWIG_RuntimeError, "pirqcon statement does not exist"); 3437 fail: 3438 return NULL; 3439 }; 3440 ~qpol_pirqcon() { 3441 return; 3442 }; 3443 uint32_t irq(qpol_policy_t *p) { 3444 uint16_t irq = 0; 3445 if(qpol_pirqcon_get_irq(p, self, &irq)) { 3446 SWIG_exception(SWIG_RuntimeError, "Could not get irq for pirqcon statement"); 3447 } 3448 fail: 3449 return irq; 3450 }; 3451 const qpol_context_t *context(qpol_policy_t *p) { 3452 const qpol_context_t *ctx; 3453 if (qpol_pirqcon_get_context(p, self, &ctx)) { 3454 SWIG_exception(SWIG_ValueError, "Could not get context for pirqcon statement"); 3455 } 3456 fail: 3457 return ctx; 3458 }; 3459 } 3460 %inline %{ 3461 qpol_pirqcon_t *qpol_pirqcon_from_void(void *x) { 3462 return (qpol_pirqcon_t*)x; 3463 }; 3464 %} 3465 3466 /* qpol devicetreecon */ 3467 typedef struct qpol_devicetreecon {} qpol_devicetreecon_t; 3468 %extend qpol_devicetreecon { 3469 qpol_devicetreecon() { 3470 3471 SWIG_exception(SWIG_RuntimeError, "devicetreecon statement does not exist"); 3472 3473 fail: 3474 return NULL; 3475 }; 3476 char *path(qpol_policy_t *p) { 3477 char *path = NULL; 3478 if(qpol_devicetreecon_get_path(p, self, &path)) { 3479 SWIG_exception(SWIG_RuntimeError, "Could not get path for devicetreecon statement"); 3480 } 3481 fail: 3482 return path; 3483 }; 3484 const qpol_context_t *context(qpol_policy_t *p) { 3485 const qpol_context_t *ctx; 3486 if (qpol_devicetreecon_get_context(p, self, &ctx)) { 3487 SWIG_exception(SWIG_ValueError, "Could not get context for devicetreecon statement"); 3488 } 3489 fail: 3490 return ctx; 3491 }; 3492 } 3493 %inline %{ 3494 qpol_devicetreecon_t *qpol_devicetreecon_from_void(void *x) { 3495 return (qpol_devicetreecon_t*)x; 3496 }; 3497 %} 3498 3499