1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793
|
/*
* Copyright 2011 Tresys Technology, LLC. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of Tresys Technology, LLC.
*/
#include <stdio.h>
#include <stdarg.h>
#include <inttypes.h>
#include <sepol/policydb/conditional.h>
#include "cil_internal.h"
#include "cil_flavor.h"
#include "cil_log.h"
#include "cil_tree.h"
#include "cil_list.h"
#include "cil_parser.h"
#include "cil_strpool.h"
void cil_tree_print_perms_list(struct cil_tree_node *current_perm);
void cil_tree_print_classperms(struct cil_classperms *cp);
void cil_tree_print_level(struct cil_level *level);
void cil_tree_print_levelrange(struct cil_levelrange *lvlrange);
void cil_tree_print_context(struct cil_context *context);
void cil_tree_print_expr_tree(struct cil_tree_node *expr_root);
void cil_tree_print_constrain(struct cil_constrain *cons);
void cil_tree_print_node(struct cil_tree_node *node);
__attribute__((noreturn)) __attribute__((format (printf, 1, 2))) void cil_tree_error(const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
cil_vlog(CIL_ERR, msg, ap);
va_end(ap);
exit(1);
}
struct cil_tree_node *cil_tree_get_next_path(struct cil_tree_node *node, char **path, int* is_cil)
{
if (!node) {
return NULL;
}
node = node->parent;
while (node) {
if (node->flavor == CIL_NODE && node->data == NULL) {
if (node->cl_head->data == CIL_KEY_SRC_INFO) {
/* Parse Tree */
*path = node->cl_head->next->next->data;
*is_cil = (node->cl_head->next->data == CIL_KEY_SRC_CIL);
return node;
}
node = node->parent;
} else if (node->flavor == CIL_SRC_INFO) {
/* AST */
struct cil_src_info *info = node->data;
*path = info->path;
*is_cil = info->is_cil;
return node;
} else {
if (node->flavor == CIL_CALL) {
struct cil_call *call = node->data;
node = NODE(call->macro);
} else if (node->flavor == CIL_BLOCKINHERIT) {
struct cil_blockinherit *inherit = node->data;
node = NODE(inherit->block);
} else {
node = node->parent;
}
}
}
return NULL;
}
char *cil_tree_get_cil_path(struct cil_tree_node *node)
{
char *path = NULL;
int is_cil;
while (node) {
node = cil_tree_get_next_path(node, &path, &is_cil);
if (node && is_cil) {
return path;
}
}
return NULL;
}
__attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *node, enum cil_log_level lvl, const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
cil_vlog(lvl, msg, ap);
va_end(ap);
if (node) {
char *path = NULL;
int is_cil;
unsigned hll_line = node->hll_line;
path = cil_tree_get_cil_path(node);
if (path != NULL) {
cil_log(lvl, " at %s:%d", path, node->line);
}
while (node) {
node = cil_tree_get_next_path(node, &path, &is_cil);
if (node && !is_cil) {
cil_log(lvl," from %s:%d", path, hll_line);
path = NULL;
hll_line = node->hll_line;
}
}
}
cil_log(lvl,"\n");
}
int cil_tree_init(struct cil_tree **tree)
{
struct cil_tree *new_tree = cil_malloc(sizeof(*new_tree));
cil_tree_node_init(&new_tree->root);
*tree = new_tree;
return SEPOL_OK;
}
void cil_tree_destroy(struct cil_tree **tree)
{
if (tree == NULL || *tree == NULL) {
return;
}
cil_tree_subtree_destroy((*tree)->root);
free(*tree);
*tree = NULL;
}
void cil_tree_subtree_destroy(struct cil_tree_node *node)
{
cil_tree_children_destroy(node);
cil_tree_node_destroy(&node);
}
void cil_tree_children_destroy(struct cil_tree_node *node)
{
struct cil_tree_node *start_node = node;
struct cil_tree_node *next = NULL;
if (node == NULL) {
return;
}
if (node->cl_head != NULL) {
node = node->cl_head;
}
while (node != start_node) {
if (node->cl_head != NULL){
next = node->cl_head;
} else {
if (node->next == NULL) {
next = node->parent;
if (node->parent != NULL) {
node->parent->cl_head = NULL;
}
cil_tree_node_destroy(&node);
} else {
next = node->next;
cil_tree_node_destroy(&node);
}
}
node = next;
}
}
void cil_tree_node_init(struct cil_tree_node **node)
{
struct cil_tree_node *new_node = cil_malloc(sizeof(*new_node));
new_node->cl_head = NULL;
new_node->cl_tail = NULL;
new_node->parent = NULL;
new_node->data = NULL;
new_node->next = NULL;
new_node->flavor = CIL_ROOT;
new_node->line = 0;
new_node->hll_line = 0;
*node = new_node;
}
void cil_tree_node_destroy(struct cil_tree_node **node)
{
struct cil_symtab_datum *datum;
if (node == NULL || *node == NULL) {
return;
}
if ((*node)->flavor >= CIL_MIN_DECLARATIVE) {
datum = (*node)->data;
cil_symtab_datum_remove_node(datum, *node);
if (datum->nodes == NULL) {
cil_destroy_data(&(*node)->data, (*node)->flavor);
}
} else {
cil_destroy_data(&(*node)->data, (*node)->flavor);
}
free(*node);
*node = NULL;
}
/* Perform depth-first walk of the tree
Parameters:
start_node: root node to start walking from
process_node: function to call when visiting a node
Takes parameters:
node: node being visited
finished: boolean indicating to the tree walker that it should move on from this branch
extra_args: additional data
first_child: Function to call before entering list of children
Takes parameters:
node: node of first child
extra args: additional data
last_child: Function to call when finished with the last child of a node's children
extra_args: any additional data to be passed to the helper functions
*/
int cil_tree_walk_core(struct cil_tree_node *node,
int (*process_node)(struct cil_tree_node *node, uint32_t *finished, void *extra_args),
int (*first_child)(struct cil_tree_node *node, void *extra_args),
int (*last_child)(struct cil_tree_node *node, void *extra_args),
void *extra_args)
{
int rc = SEPOL_ERR;
while (node) {
uint32_t finished = CIL_TREE_SKIP_NOTHING;
if (process_node != NULL) {
rc = (*process_node)(node, &finished, extra_args);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_INFO, "Problem");
return rc;
}
}
if (finished & CIL_TREE_SKIP_NEXT) {
return SEPOL_OK;
}
if (node->cl_head != NULL && !(finished & CIL_TREE_SKIP_HEAD)) {
rc = cil_tree_walk(node, process_node, first_child, last_child, extra_args);
if (rc != SEPOL_OK) {
return rc;
}
}
node = node->next;
}
return SEPOL_OK;
}
int cil_tree_walk(struct cil_tree_node *node,
int (*process_node)(struct cil_tree_node *node, uint32_t *finished, void *extra_args),
int (*first_child)(struct cil_tree_node *node, void *extra_args),
int (*last_child)(struct cil_tree_node *node, void *extra_args),
void *extra_args)
{
int rc = SEPOL_ERR;
if (!node || !node->cl_head) {
return SEPOL_OK;
}
if (first_child != NULL) {
rc = (*first_child)(node->cl_head, extra_args);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_INFO, "Problem");
return rc;
}
}
rc = cil_tree_walk_core(node->cl_head, process_node, first_child, last_child, extra_args);
if (rc != SEPOL_OK) {
return rc;
}
if (last_child != NULL) {
rc = (*last_child)(node->cl_tail, extra_args);
if (rc != SEPOL_OK) {
cil_tree_log(node, CIL_INFO, "Problem");
return rc;
}
}
return SEPOL_OK;
}
/* Copied from cil_policy.c, but changed to prefix -- Need to refactor */
static int cil_expr_to_string(struct cil_list *expr, char **out)
{
int rc = SEPOL_ERR;
struct cil_list_item *curr;
char *stack[COND_EXPR_MAXDEPTH] = {};
int pos = 0;
cil_list_for_each(curr, expr) {
if (pos >= COND_EXPR_MAXDEPTH) {
rc = SEPOL_ERR;
goto exit;
}
switch (curr->flavor) {
case CIL_LIST:
rc = cil_expr_to_string(curr->data, &stack[pos]);
if (rc != SEPOL_OK) {
goto exit;
}
pos++;
break;
case CIL_STRING:
stack[pos] = curr->data;
pos++;
break;
case CIL_DATUM:
stack[pos] = ((struct cil_symtab_datum *)curr->data)->name;
pos++;
break;
case CIL_OP: {
int len;
char *expr_str;
enum cil_flavor op_flavor = *((enum cil_flavor *)curr->data);
char *op_str = NULL;
if (pos == 0) {
rc = SEPOL_ERR;
goto exit;
}
switch (op_flavor) {
case CIL_AND:
op_str = CIL_KEY_AND;
break;
case CIL_OR:
op_str = CIL_KEY_OR;
break;
case CIL_NOT:
op_str = CIL_KEY_NOT;
break;
case CIL_ALL:
op_str = CIL_KEY_ALL;
break;
case CIL_EQ:
op_str = CIL_KEY_EQ;
break;
case CIL_NEQ:
op_str = CIL_KEY_NEQ;
break;
case CIL_XOR:
op_str = CIL_KEY_XOR;
break;
case CIL_RANGE:
op_str = CIL_KEY_RANGE;
break;
case CIL_CONS_DOM:
op_str = CIL_KEY_CONS_DOM;
break;
case CIL_CONS_DOMBY:
op_str = CIL_KEY_CONS_DOMBY;
break;
case CIL_CONS_INCOMP:
op_str = CIL_KEY_CONS_INCOMP;
break;
default:
cil_log(CIL_ERR, "Unknown operator in expression\n");
goto exit;
break;
}
if (op_flavor == CIL_NOT) {
len = strlen(stack[pos-1]) + strlen(op_str) + 4;
expr_str = cil_malloc(len);
snprintf(expr_str, len, "(%s %s)", op_str, stack[pos-1]);
free(stack[pos-1]);
stack[pos-1] = NULL;
pos--;
} else {
if (pos < 2) {
rc = SEPOL_ERR;
goto exit;
}
len = strlen(stack[pos-1]) + strlen(stack[pos-2]) + strlen(op_str) + 5;
expr_str = cil_malloc(len);
snprintf(expr_str, len, "(%s %s %s)", op_str, stack[pos-1], stack[pos-2]);
free(stack[pos-2]);
free(stack[pos-1]);
stack[pos-2] = NULL;
stack[pos-1] = NULL;
pos -= 2;
}
stack[pos] = expr_str;
pos++;
break;
}
case CIL_CONS_OPERAND: {
enum cil_flavor operand_flavor = *((enum cil_flavor *)curr->data);
char *operand_str = NULL;
switch (operand_flavor) {
case CIL_CONS_U1:
operand_str = CIL_KEY_CONS_U1;
break;
case CIL_CONS_U2:
operand_str = CIL_KEY_CONS_U2;
break;
case CIL_CONS_U3:
operand_str = CIL_KEY_CONS_U3;
break;
case CIL_CONS_T1:
operand_str = CIL_KEY_CONS_T1;
break;
case CIL_CONS_T2:
operand_str = CIL_KEY_CONS_T2;
break;
case CIL_CONS_T3:
operand_str = CIL_KEY_CONS_T3;
break;
case CIL_CONS_R1:
operand_str = CIL_KEY_CONS_R1;
break;
case CIL_CONS_R2:
operand_str = CIL_KEY_CONS_R2;
break;
case CIL_CONS_R3:
operand_str = CIL_KEY_CONS_R3;
break;
case CIL_CONS_L1:
operand_str = CIL_KEY_CONS_L1;
break;
case CIL_CONS_L2:
operand_str = CIL_KEY_CONS_L2;
break;
case CIL_CONS_H1:
operand_str = CIL_KEY_CONS_H1;
break;
case CIL_CONS_H2:
operand_str = CIL_KEY_CONS_H2;
break;
default:
cil_log(CIL_ERR, "Unknown operand in expression\n");
goto exit;
break;
}
stack[pos] = operand_str;
pos++;
break;
}
default:
cil_log(CIL_ERR, "Unknown flavor in expression\n");
goto exit;
break;
}
}
*out = stack[0];
return SEPOL_OK;
exit:
return rc;
}
void cil_tree_print_expr(struct cil_list *datum_expr, struct cil_list *str_expr)
{
char *expr_str;
int rc;
cil_log(CIL_INFO, "(");
if (datum_expr != NULL) {
rc = cil_expr_to_string(datum_expr, &expr_str);
} else {
rc = cil_expr_to_string(str_expr, &expr_str);
}
if (rc < 0) {
cil_log(CIL_INFO, "ERROR)");
return;
}
cil_log(CIL_INFO, "%s)", expr_str);
free(expr_str);
}
void cil_tree_print_perms_list(struct cil_tree_node *current_perm)
{
while (current_perm != NULL) {
if (current_perm->flavor == CIL_PERM) {
cil_log(CIL_INFO, " %s", ((struct cil_perm *)current_perm->data)->datum.name);
} else if (current_perm->flavor == CIL_MAP_PERM) {
cil_log(CIL_INFO, " %s", ((struct cil_perm*)current_perm->data)->datum.name);
} else {
cil_log(CIL_INFO, "\n\n perms list contained unexpected data type: %d\n", current_perm->flavor);
break;
}
current_perm = current_perm->next;
}
}
void cil_tree_print_cats(struct cil_cats *cats)
{
cil_tree_print_expr(cats->datum_expr, cats->str_expr);
}
void cil_tree_print_perm_strs(struct cil_list *perm_strs)
{
struct cil_list_item *curr;
if (perm_strs == NULL) {
return;
}
cil_log(CIL_INFO, " (");
cil_list_for_each(curr, perm_strs) {
cil_log(CIL_INFO, " %s", (char*)curr->data);
}
cil_log(CIL_INFO, " )");
}
void cil_tree_print_classperms(struct cil_classperms *cp)
{
if (cp == NULL) {
return;
}
cil_log(CIL_INFO, " class: %s", cp->class_str);
cil_log(CIL_INFO, ", perm_strs:");
cil_tree_print_perm_strs(cp->perm_strs);
}
void cil_tree_print_classperms_set(struct cil_classperms_set *cp_set)
{
if (cp_set == NULL) {
return;
}
cil_log(CIL_INFO, " %s", cp_set->set_str);
}
void cil_tree_print_classperms_list(struct cil_list *cp_list)
{
struct cil_list_item *i;
if (cp_list == NULL) {
return;
}
cil_list_for_each(i, cp_list) {
if (i->flavor == CIL_CLASSPERMS) {
cil_tree_print_classperms(i->data);
} else {
cil_tree_print_classperms_set(i->data);
}
}
}
void cil_tree_print_level(struct cil_level *level)
{
if (level->sens != NULL) {
cil_log(CIL_INFO, " %s", level->sens->datum.name);
} else if (level->sens_str != NULL) {
cil_log(CIL_INFO, " %s", level->sens_str);
}
cil_tree_print_cats(level->cats);
return;
}
void cil_tree_print_levelrange(struct cil_levelrange *lvlrange)
{
cil_log(CIL_INFO, " (");
if (lvlrange->low != NULL) {
cil_log(CIL_INFO, " (");
cil_tree_print_level(lvlrange->low);
cil_log(CIL_INFO, " )");
} else if (lvlrange->low_str != NULL) {
cil_log(CIL_INFO, " %s", lvlrange->low_str);
}
if (lvlrange->high != NULL) {
cil_log(CIL_INFO, " (");
cil_tree_print_level(lvlrange->high);
cil_log(CIL_INFO, " )");
} else if (lvlrange->high_str != NULL) {
cil_log(CIL_INFO, " %s", lvlrange->high_str);
}
cil_log(CIL_INFO, " )");
}
void cil_tree_print_context(struct cil_context *context)
{
cil_log(CIL_INFO, " (");
if (context->user != NULL) {
cil_log(CIL_INFO, " %s", context->user->datum.name);
} else if (context->user_str != NULL) {
cil_log(CIL_INFO, " %s", context->user_str);
}
if (context->role != NULL) {
cil_log(CIL_INFO, " %s", context->role->datum.name);
} else if (context->role_str != NULL) {
cil_log(CIL_INFO, " %s", context->role_str);
}
if (context->type != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)context->type)->name);
} else if (context->type_str != NULL) {
cil_log(CIL_INFO, " %s", context->type_str);
}
if (context->range != NULL) {
cil_tree_print_levelrange(context->range);
} else if (context->range_str != NULL) {
cil_log(CIL_INFO, " %s", context->range_str);
}
cil_log(CIL_INFO, " )");
return;
}
void cil_tree_print_constrain(struct cil_constrain *cons)
{
cil_tree_print_classperms_list(cons->classperms);
cil_tree_print_expr(cons->datum_expr, cons->str_expr);
cil_log(CIL_INFO, "\n");
}
void cil_tree_print_node(struct cil_tree_node *node)
{
if (node->data == NULL) {
cil_log(CIL_INFO, "FLAVOR: %d", node->flavor);
return;
} else {
switch( node->flavor ) {
case CIL_BLOCK: {
struct cil_block *block = node->data;
cil_log(CIL_INFO, "BLOCK: %s\n", block->datum.name);
return;
}
case CIL_BLOCKINHERIT: {
struct cil_blockinherit *inherit = node->data;
cil_log(CIL_INFO, "BLOCKINHERIT: %s\n", inherit->block_str);
return;
}
case CIL_BLOCKABSTRACT: {
struct cil_blockabstract *abstract = node->data;
cil_log(CIL_INFO, "BLOCKABSTRACT: %s\n", abstract->block_str);
return;
}
case CIL_IN: {
struct cil_in *in = node->data;
cil_log(CIL_INFO, "IN: %s\n", in->block_str);
return;
}
case CIL_USER: {
struct cil_user *user = node->data;
cil_log(CIL_INFO, "USER: %s\n", user->datum.name);
return;
}
case CIL_TYPE: {
struct cil_type *type = node->data;
cil_log(CIL_INFO, "TYPE: %s\n", type->datum.name);
return;
}
case CIL_EXPANDTYPEATTRIBUTE: {
struct cil_expandtypeattribute *attr = node->data;
fprintf(stderr, "%s %u\n", __func__, __LINE__);
cil_log(CIL_INFO, "(EXPANDTYPEATTRIBUTE ");
cil_tree_print_expr(attr->attr_datums, attr->attr_strs);
cil_log(CIL_INFO, "%s)\n",attr->expand ?
CIL_KEY_CONDTRUE : CIL_KEY_CONDFALSE);
return;
}
case CIL_TYPEATTRIBUTESET: {
struct cil_typeattributeset *attr = node->data;
cil_log(CIL_INFO, "(TYPEATTRIBUTESET %s ", attr->attr_str);
cil_tree_print_expr(attr->datum_expr, attr->str_expr);
cil_log(CIL_INFO, "\n");
return;
}
case CIL_TYPEATTRIBUTE: {
struct cil_typeattribute *attr = node->data;
cil_log(CIL_INFO, "TYPEATTRIBUTE: %s\n", attr->datum.name);
return;
}
case CIL_ROLE: {
struct cil_role *role = node->data;
cil_log(CIL_INFO, "ROLE: %s\n", role->datum.name);
return;
}
case CIL_USERROLE: {
struct cil_userrole *userrole = node->data;
cil_log(CIL_INFO, "USERROLE:");
struct cil_symtab_datum *datum = NULL;
if (userrole->user != NULL) {
datum = userrole->user;
cil_log(CIL_INFO, " %s", datum->name);
} else if (userrole->user_str != NULL) {
cil_log(CIL_INFO, " %s", userrole->user_str);
}
if (userrole->role != NULL) {
datum = userrole->role;
cil_log(CIL_INFO, " %s", datum->name);
} else if (userrole->role_str != NULL) {
cil_log(CIL_INFO, " %s", userrole->role_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_USERLEVEL: {
struct cil_userlevel *usrlvl = node->data;
cil_log(CIL_INFO, "USERLEVEL:");
if (usrlvl->user_str != NULL) {
cil_log(CIL_INFO, " %s", usrlvl->user_str);
}
if (usrlvl->level != NULL) {
cil_log(CIL_INFO, " (");
cil_tree_print_level(usrlvl->level);
cil_log(CIL_INFO, " )");
} else if (usrlvl->level_str != NULL) {
cil_log(CIL_INFO, " %s", usrlvl->level_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_USERRANGE: {
struct cil_userrange *userrange = node->data;
cil_log(CIL_INFO, "USERRANGE:");
if (userrange->user_str != NULL) {
cil_log(CIL_INFO, " %s", userrange->user_str);
}
if (userrange->range != NULL) {
cil_log(CIL_INFO, " (");
cil_tree_print_levelrange(userrange->range);
cil_log(CIL_INFO, " )");
} else if (userrange->range_str != NULL) {
cil_log(CIL_INFO, " %s", userrange->range_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_USERBOUNDS: {
struct cil_bounds *bnds = node->data;
cil_log(CIL_INFO, "USERBOUNDS: user: %s, bounds: %s\n", bnds->parent_str, bnds->child_str);
return;
}
case CIL_ROLETYPE: {
struct cil_roletype *roletype = node->data;
struct cil_symtab_datum *datum = NULL;
cil_log(CIL_INFO, "ROLETYPE:");
if (roletype->role != NULL) {
datum = roletype->role;
cil_log(CIL_INFO, " %s", datum->name);
} else if (roletype->role_str != NULL) {
cil_log(CIL_INFO, " %s", roletype->role_str);
}
if (roletype->type != NULL) {
datum = roletype->type;
cil_log(CIL_INFO, " %s", datum->name);
} else if (roletype->type_str != NULL) {
cil_log(CIL_INFO, " %s", roletype->type_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_ROLETRANSITION: {
struct cil_roletransition *roletrans = node->data;
cil_log(CIL_INFO, "ROLETRANSITION:");
if (roletrans->src != NULL) {
cil_log(CIL_INFO, " %s", roletrans->src->datum.name);
} else {
cil_log(CIL_INFO, " %s", roletrans->src_str);
}
if (roletrans->tgt != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)roletrans->tgt)->name);
} else {
cil_log(CIL_INFO, " %s", roletrans->tgt_str);
}
if (roletrans->obj != NULL) {
cil_log(CIL_INFO, " %s", roletrans->obj->datum.name);
} else {
cil_log(CIL_INFO, " %s", roletrans->obj_str);
}
if (roletrans->result != NULL) {
cil_log(CIL_INFO, " %s\n", roletrans->result->datum.name);
} else {
cil_log(CIL_INFO, " %s\n", roletrans->result_str);
}
return;
}
case CIL_ROLEALLOW: {
struct cil_roleallow *roleallow = node->data;
cil_log(CIL_INFO, "ROLEALLOW:");
if (roleallow->src != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum*)roleallow->src)->name);
} else {
cil_log(CIL_INFO, " %s", roleallow->src_str);
}
if (roleallow->tgt != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum*)roleallow->tgt)->name);
} else {
cil_log(CIL_INFO, " %s", roleallow->tgt_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_ROLEATTRIBUTESET: {
struct cil_roleattributeset *attr = node->data;
cil_log(CIL_INFO, "(ROLEATTRIBUTESET %s ", attr->attr_str);
cil_tree_print_expr(attr->datum_expr, attr->str_expr);
cil_log(CIL_INFO, "\n");
return;
}
case CIL_ROLEATTRIBUTE: {
struct cil_roleattribute *attr = node->data;
cil_log(CIL_INFO, "ROLEATTRIBUTE: %s\n", attr->datum.name);
return;
}
case CIL_USERATTRIBUTESET: {
struct cil_userattributeset *attr = node->data;
cil_log(CIL_INFO, "(USERATTRIBUTESET %s ", attr->attr_str);
cil_tree_print_expr(attr->datum_expr, attr->str_expr);
cil_log(CIL_INFO, "\n");
return;
}
case CIL_USERATTRIBUTE: {
struct cil_userattribute *attr = node->data;
cil_log(CIL_INFO, "USERATTRIBUTE: %s\n", attr->datum.name);
return;
}
case CIL_ROLEBOUNDS: {
struct cil_bounds *bnds = node->data;
cil_log(CIL_INFO, "ROLEBOUNDS: role: %s, bounds: %s\n", bnds->parent_str, bnds->child_str);
return;
}
case CIL_CLASS: {
struct cil_class *cls = node->data;
cil_log(CIL_INFO, "CLASS: %s ", cls->datum.name);
if (cls->common != NULL) {
cil_log(CIL_INFO, "inherits: %s ", cls->common->datum.name);
}
cil_log(CIL_INFO, "(");
cil_tree_print_perms_list(node->cl_head);
cil_log(CIL_INFO, " )");
return;
}
case CIL_CLASSORDER: {
struct cil_classorder *classorder = node->data;
struct cil_list_item *class;
if (classorder->class_list_str == NULL) {
cil_log(CIL_INFO, "CLASSORDER: ()\n");
return;
}
cil_log(CIL_INFO, "CLASSORDER: (");
cil_list_for_each(class, classorder->class_list_str) {
cil_log(CIL_INFO, " %s", (char*)class->data);
}
cil_log(CIL_INFO, " )\n");
return;
}
case CIL_COMMON: {
struct cil_class *common = node->data;
cil_log(CIL_INFO, "COMMON: %s (", common->datum.name);
cil_tree_print_perms_list(node->cl_head);
cil_log(CIL_INFO, " )");
return;
}
case CIL_CLASSCOMMON: {
struct cil_classcommon *clscom = node->data;
cil_log(CIL_INFO, "CLASSCOMMON: class: %s, common: %s\n", clscom->class_str, clscom->common_str);
return;
}
case CIL_CLASSPERMISSION: {
struct cil_classpermission *cp = node->data;
cil_log(CIL_INFO, "CLASSPERMISSION: %s", cp->datum.name);
cil_log(CIL_INFO, "\n");
return;
}
case CIL_CLASSPERMISSIONSET: {
struct cil_classpermissionset *cps = node->data;
cil_log(CIL_INFO, "CLASSPERMISSIONSET: %s", cps->set_str);
cil_tree_print_classperms_list(cps->classperms);
cil_log(CIL_INFO, "\n");
return;
}
case CIL_MAP_CLASS: {
struct cil_class *cm = node->data;
cil_log(CIL_INFO, "MAP_CLASS: %s", cm->datum.name);
cil_log(CIL_INFO, " (");
cil_tree_print_perms_list(node->cl_head);
cil_log(CIL_INFO, " )\n");
return;
}
case CIL_MAP_PERM: {
struct cil_perm *cmp = node->data;
cil_log(CIL_INFO, "MAP_PERM: %s", cmp->datum.name);
if (cmp->classperms == NULL) {
cil_log(CIL_INFO, " perms: ()");
return;
}
cil_log(CIL_INFO, " kernel class perms: (");
cil_tree_print_classperms_list(cmp->classperms);
cil_log(CIL_INFO, " )\n");
return;
}
case CIL_CLASSMAPPING: {
struct cil_classmapping *mapping = node->data;
cil_log(CIL_INFO, "CLASSMAPPING: map class: %s, map perm: %s,", mapping->map_class_str, mapping->map_perm_str);
cil_log(CIL_INFO, " (");
cil_tree_print_classperms_list(mapping->classperms);
cil_log(CIL_INFO, " )\n");
return;
}
case CIL_BOOL: {
struct cil_bool *boolean = node->data;
cil_log(CIL_INFO, "BOOL: %s, value: %d\n", boolean->datum.name, boolean->value);
return;
}
case CIL_TUNABLE: {
struct cil_tunable *tunable = node->data;
cil_log(CIL_INFO, "TUNABLE: %s, value: %d\n", tunable->datum.name, tunable->value);
return;
}
case CIL_BOOLEANIF: {
struct cil_booleanif *bif = node->data;
cil_log(CIL_INFO, "(BOOLEANIF ");
cil_tree_print_expr(bif->datum_expr, bif->str_expr);
cil_log(CIL_INFO, " )\n");
return;
}
case CIL_TUNABLEIF: {
struct cil_tunableif *tif = node->data;
cil_log(CIL_INFO, "(TUNABLEIF ");
cil_tree_print_expr(tif->datum_expr, tif->str_expr);
cil_log(CIL_INFO, " )\n");
return;
}
case CIL_CONDBLOCK: {
struct cil_condblock *cb = node->data;
if (cb->flavor == CIL_CONDTRUE) {
cil_log(CIL_INFO, "true\n");
} else if (cb->flavor == CIL_CONDFALSE) {
cil_log(CIL_INFO, "false\n");
}
return;
}
case CIL_ALL:
cil_log(CIL_INFO, "all");
return;
case CIL_AND:
cil_log(CIL_INFO, "&&");
return;
case CIL_OR:
cil_log(CIL_INFO, "|| ");
return;
case CIL_NOT:
cil_log(CIL_INFO, "!");
return;
case CIL_EQ:
cil_log(CIL_INFO, "==");
return;
case CIL_NEQ:
cil_log(CIL_INFO, "!=");
return;
case CIL_TYPEALIAS: {
struct cil_alias *alias = node->data;
cil_log(CIL_INFO, "TYPEALIAS: %s\n", alias->datum.name);
return;
}
case CIL_TYPEALIASACTUAL: {
struct cil_aliasactual *aliasactual = node->data;
cil_log(CIL_INFO, "TYPEALIASACTUAL: type: %s, alias: %s\n", aliasactual->alias_str, aliasactual->actual_str);
return;
}
case CIL_TYPEBOUNDS: {
struct cil_bounds *bnds = node->data;
cil_log(CIL_INFO, "TYPEBOUNDS: type: %s, bounds: %s\n", bnds->parent_str, bnds->child_str);
return;
}
case CIL_TYPEPERMISSIVE: {
struct cil_typepermissive *typeperm = node->data;
if (typeperm->type != NULL) {
cil_log(CIL_INFO, "TYPEPERMISSIVE: %s\n", ((struct cil_symtab_datum *)typeperm->type)->name);
} else {
cil_log(CIL_INFO, "TYPEPERMISSIVE: %s\n", typeperm->type_str);
}
return;
}
case CIL_NAMETYPETRANSITION: {
struct cil_nametypetransition *nametypetrans = node->data;
cil_log(CIL_INFO, "TYPETRANSITION:");
if (nametypetrans->src != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)nametypetrans->src)->name);
} else {
cil_log(CIL_INFO, " %s", nametypetrans->src_str);
}
if (nametypetrans->tgt != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)nametypetrans->tgt)->name);
} else {
cil_log(CIL_INFO, " %s", nametypetrans->tgt_str);
}
if (nametypetrans->obj != NULL) {
cil_log(CIL_INFO, " %s", nametypetrans->obj->datum.name);
} else {
cil_log(CIL_INFO, " %s", nametypetrans->obj_str);
}
cil_log(CIL_INFO, " %s\n", nametypetrans->name_str);
if (nametypetrans->result != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)nametypetrans->result)->name);
} else {
cil_log(CIL_INFO, " %s", nametypetrans->result_str);
}
return;
}
case CIL_RANGETRANSITION: {
struct cil_rangetransition *rangetrans = node->data;
cil_log(CIL_INFO, "RANGETRANSITION:");
if (rangetrans->src != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)rangetrans->src)->name);
} else {
cil_log(CIL_INFO, " %s", rangetrans->src_str);
}
if (rangetrans->exec != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)rangetrans->exec)->name);
} else {
cil_log(CIL_INFO, " %s", rangetrans->exec_str);
}
if (rangetrans->obj != NULL) {
cil_log(CIL_INFO, " %s", rangetrans->obj->datum.name);
} else {
cil_log(CIL_INFO, " %s", rangetrans->obj_str);
}
if (rangetrans->range != NULL) {
cil_log(CIL_INFO, " (");
cil_tree_print_levelrange(rangetrans->range);
cil_log(CIL_INFO, " )");
} else {
cil_log(CIL_INFO, " %s", rangetrans->range_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_AVRULE: {
struct cil_avrule *rule = node->data;
switch (rule->rule_kind) {
case CIL_AVRULE_ALLOWED:
cil_log(CIL_INFO, "ALLOW:");
break;
case CIL_AVRULE_AUDITALLOW:
cil_log(CIL_INFO, "AUDITALLOW:");
break;
case CIL_AVRULE_DONTAUDIT:
cil_log(CIL_INFO, "DONTAUDIT:");
break;
case CIL_AVRULE_NEVERALLOW:
cil_log(CIL_INFO, "NEVERALLOW:");
break;
}
if (rule->src != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum*)rule->src)->name);
} else {
cil_log(CIL_INFO, " %s", rule->src_str);
}
if (rule->tgt != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum*)rule->tgt)->name);
} else {
cil_log(CIL_INFO, " %s", rule->tgt_str);
}
cil_tree_print_classperms_list(rule->perms.classperms);
cil_log(CIL_INFO, "\n");
return;
}
case CIL_TYPE_RULE: {
struct cil_type_rule *rule = node->data;
switch (rule->rule_kind) {
case CIL_TYPE_TRANSITION:
cil_log(CIL_INFO, "TYPETRANSITION:");
break;
case CIL_TYPE_MEMBER:
cil_log(CIL_INFO, "TYPEMEMBER:");
break;
case CIL_TYPE_CHANGE:
cil_log(CIL_INFO, "TYPECHANGE:");
break;
}
if (rule->src != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)rule->src)->name);
} else {
cil_log(CIL_INFO, " %s", rule->src_str);
}
if (rule->tgt != NULL) {
cil_log(CIL_INFO, " %s", ((struct cil_symtab_datum *)rule->tgt)->name);
} else {
cil_log(CIL_INFO, " %s", rule->tgt_str);
}
if (rule->obj != NULL) {
cil_log(CIL_INFO, " %s", rule->obj->datum.name);
} else {
cil_log(CIL_INFO, " %s", rule->obj_str);
}
if (rule->result != NULL) {
cil_log(CIL_INFO, " %s\n", ((struct cil_symtab_datum *)rule->result)->name);
} else {
cil_log(CIL_INFO, " %s\n", rule->result_str);
}
return;
}
case CIL_SENS: {
struct cil_sens *sens = node->data;
cil_log(CIL_INFO, "SENSITIVITY: %s\n", sens->datum.name);
return;
}
case CIL_SENSALIAS: {
struct cil_alias *alias = node->data;
cil_log(CIL_INFO, "SENSITIVITYALIAS: %s\n", alias->datum.name);
return;
}
case CIL_SENSALIASACTUAL: {
struct cil_aliasactual *aliasactual = node->data;
cil_log(CIL_INFO, "SENSITIVITYALIAS: alias: %s, sensitivity: %s\n", aliasactual->alias_str, aliasactual->actual_str);
return;
}
case CIL_CAT: {
struct cil_cat *cat = node->data;
cil_log(CIL_INFO, "CATEGORY: %s\n", cat->datum.name);
return;
}
case CIL_CATALIAS: {
struct cil_alias *alias = node->data;
cil_log(CIL_INFO, "CATEGORYALIAS: %s\n", alias->datum.name);
return;
}
case CIL_CATALIASACTUAL: {
struct cil_aliasactual *aliasactual = node->data;
cil_log(CIL_INFO, "CATEGORYALIAS: alias %s, category: %s\n", aliasactual->alias_str, aliasactual->actual_str);
return;
}
case CIL_CATSET: {
struct cil_catset *catset = node->data;
cil_log(CIL_INFO, "CATSET: %s ",catset->datum.name);
cil_tree_print_cats(catset->cats);
return;
}
case CIL_CATORDER: {
struct cil_catorder *catorder = node->data;
struct cil_list_item *cat;
if (catorder->cat_list_str == NULL) {
cil_log(CIL_INFO, "CATORDER: ()\n");
return;
}
cil_log(CIL_INFO, "CATORDER: (");
cil_list_for_each(cat, catorder->cat_list_str) {
cil_log(CIL_INFO, " %s", (char*)cat->data);
}
cil_log(CIL_INFO, " )\n");
return;
}
case CIL_SENSCAT: {
struct cil_senscat *senscat = node->data;
cil_log(CIL_INFO, "SENSCAT: sens:");
if (senscat->sens_str != NULL) {
cil_log(CIL_INFO, " %s ", senscat->sens_str);
} else {
cil_log(CIL_INFO, " [processed]");
}
cil_tree_print_cats(senscat->cats);
return;
}
case CIL_SENSITIVITYORDER: {
struct cil_sensorder *sensorder = node->data;
struct cil_list_item *sens;
cil_log(CIL_INFO, "SENSITIVITYORDER: (");
if (sensorder->sens_list_str != NULL) {
cil_list_for_each(sens, sensorder->sens_list_str) {
if (sens->flavor == CIL_LIST) {
struct cil_list_item *sub;
cil_log(CIL_INFO, " (");
cil_list_for_each(sub, (struct cil_list*)sens->data) {
cil_log(CIL_INFO, " %s", (char*)sub->data);
}
cil_log(CIL_INFO, " )");
} else {
cil_log(CIL_INFO, " %s", (char*)sens->data);
}
}
}
cil_log(CIL_INFO, " )\n");
return;
}
case CIL_LEVEL: {
struct cil_level *level = node->data;
cil_log(CIL_INFO, "LEVEL %s:", level->datum.name);
cil_tree_print_level(level);
cil_log(CIL_INFO, "\n");
return;
}
case CIL_LEVELRANGE: {
struct cil_levelrange *lvlrange = node->data;
cil_log(CIL_INFO, "LEVELRANGE %s:", lvlrange->datum.name);
cil_tree_print_levelrange(lvlrange);
cil_log(CIL_INFO, "\n");
return;
}
case CIL_CONSTRAIN: {
struct cil_constrain *cons = node->data;
cil_log(CIL_INFO, "CONSTRAIN: (");
cil_tree_print_constrain(cons);
return;
}
case CIL_MLSCONSTRAIN: {
struct cil_constrain *cons = node->data;
cil_log(CIL_INFO, "MLSCONSTRAIN: (");
cil_tree_print_constrain(cons);
return;
}
case CIL_VALIDATETRANS: {
struct cil_validatetrans *vt = node->data;
cil_log(CIL_INFO, "(VALIDATETRANS ");
if (vt->class != NULL) {
cil_log(CIL_INFO, "%s ", vt->class->datum.name);
} else if (vt->class_str != NULL) {
cil_log(CIL_INFO, "%s ", vt->class_str);
}
cil_tree_print_expr(vt->datum_expr, vt->str_expr);
cil_log(CIL_INFO, ")\n");
return;
}
case CIL_MLSVALIDATETRANS: {
struct cil_validatetrans *vt = node->data;
cil_log(CIL_INFO, "(MLSVALIDATETRANS ");
if (vt->class != NULL) {
cil_log(CIL_INFO, "%s ", vt->class->datum.name);
} else if (vt->class_str != NULL) {
cil_log(CIL_INFO, "%s ", vt->class_str);
}
cil_tree_print_expr(vt->datum_expr, vt->str_expr);
cil_log(CIL_INFO, ")\n");
return;
}
case CIL_CONTEXT: {
struct cil_context *context = node->data;
cil_log(CIL_INFO, "CONTEXT %s:", context->datum.name);
cil_tree_print_context(context);
cil_log(CIL_INFO, "\n");
return;
}
case CIL_FILECON: {
struct cil_filecon *filecon = node->data;
cil_log(CIL_INFO, "FILECON:");
cil_log(CIL_INFO, " %s %d", filecon->path_str, filecon->type);
if (filecon->context != NULL) {
cil_tree_print_context(filecon->context);
} else if (filecon->context_str != NULL) {
cil_log(CIL_INFO, " %s", filecon->context_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_IBPKEYCON: {
struct cil_ibpkeycon *ibpkeycon = node->data;
cil_log(CIL_INFO, "IBPKEYCON: %s", ibpkeycon->subnet_prefix_str);
cil_log(CIL_INFO, " (%d %d) ", ibpkeycon->pkey_low, ibpkeycon->pkey_high);
if (ibpkeycon->context)
cil_tree_print_context(ibpkeycon->context);
else if (ibpkeycon->context_str)
cil_log(CIL_INFO, " %s", ibpkeycon->context_str);
cil_log(CIL_INFO, "\n");
return;
}
case CIL_PORTCON: {
struct cil_portcon *portcon = node->data;
cil_log(CIL_INFO, "PORTCON:");
if (portcon->proto == CIL_PROTOCOL_UDP) {
cil_log(CIL_INFO, " udp");
} else if (portcon->proto == CIL_PROTOCOL_TCP) {
cil_log(CIL_INFO, " tcp");
} else if (portcon->proto == CIL_PROTOCOL_DCCP) {
cil_log(CIL_INFO, " dccp");
} else if (portcon->proto == CIL_PROTOCOL_SCTP) {
cil_log(CIL_INFO, " sctp");
}
cil_log(CIL_INFO, " (%d %d)", portcon->port_low, portcon->port_high);
if (portcon->context != NULL) {
cil_tree_print_context(portcon->context);
} else if (portcon->context_str != NULL) {
cil_log(CIL_INFO, " %s", portcon->context_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_NODECON: {
struct cil_nodecon *nodecon = node->data;
char buf[256];
cil_log(CIL_INFO, "NODECON:");
if (nodecon->addr) {
inet_ntop(nodecon->addr->family, &nodecon->addr->ip, buf, 256);
cil_log(CIL_INFO, " %s", buf);
} else {
cil_log(CIL_INFO, " %s", nodecon->addr_str);
}
if (nodecon->mask) {
inet_ntop(nodecon->mask->family, &nodecon->mask->ip, buf, 256);
cil_log(CIL_INFO, " %s", buf);
} else {
cil_log(CIL_INFO, " %s", nodecon->mask_str);
}
if (nodecon->context != NULL) {
cil_tree_print_context(nodecon->context);
} else if (nodecon->context_str != NULL) {
cil_log(CIL_INFO, " %s", nodecon->context_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_GENFSCON: {
struct cil_genfscon *genfscon = node->data;
cil_log(CIL_INFO, "GENFSCON:");
cil_log(CIL_INFO, " %s %s", genfscon->fs_str, genfscon->path_str);
if (genfscon->context != NULL) {
cil_tree_print_context(genfscon->context);
} else if (genfscon->context_str != NULL) {
cil_log(CIL_INFO, " %s", genfscon->context_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_NETIFCON: {
struct cil_netifcon *netifcon = node->data;
cil_log(CIL_INFO, "NETIFCON %s", netifcon->interface_str);
if (netifcon->if_context != NULL) {
cil_tree_print_context(netifcon->if_context);
} else if (netifcon->if_context_str != NULL) {
cil_log(CIL_INFO, " %s", netifcon->if_context_str);
}
if (netifcon->packet_context != NULL) {
cil_tree_print_context(netifcon->packet_context);
} else if (netifcon->packet_context_str != NULL) {
cil_log(CIL_INFO, " %s", netifcon->packet_context_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_IBENDPORTCON: {
struct cil_ibendportcon *ibendportcon = node->data;
cil_log(CIL_INFO, "IBENDPORTCON: %s %u ", ibendportcon->dev_name_str, ibendportcon->port);
if (ibendportcon->context)
cil_tree_print_context(ibendportcon->context);
else if (ibendportcon->context_str)
cil_log(CIL_INFO, " %s", ibendportcon->context_str);
cil_log(CIL_INFO, "\n");
return;
}
case CIL_PIRQCON: {
struct cil_pirqcon *pirqcon = node->data;
cil_log(CIL_INFO, "PIRQCON %d", pirqcon->pirq);
if (pirqcon->context != NULL) {
cil_tree_print_context(pirqcon->context);
} else {
cil_log(CIL_INFO, " %s", pirqcon->context_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_IOMEMCON: {
struct cil_iomemcon *iomemcon = node->data;
cil_log(CIL_INFO, "IOMEMCON ( %"PRId64" %"PRId64" )", iomemcon->iomem_low, iomemcon->iomem_high);
if (iomemcon->context != NULL) {
cil_tree_print_context(iomemcon->context);
} else {
cil_log(CIL_INFO, " %s", iomemcon->context_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_IOPORTCON: {
struct cil_ioportcon *ioportcon = node->data;
cil_log(CIL_INFO, "IOPORTCON ( %d %d )", ioportcon->ioport_low, ioportcon->ioport_high);
if (ioportcon->context != NULL) {
cil_tree_print_context(ioportcon->context);
} else {
cil_log(CIL_INFO, " %s", ioportcon->context_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_PCIDEVICECON: {
struct cil_pcidevicecon *pcidevicecon = node->data;
cil_log(CIL_INFO, "PCIDEVICECON %d", pcidevicecon->dev);
if (pcidevicecon->context != NULL) {
cil_tree_print_context(pcidevicecon->context);
} else {
cil_log(CIL_INFO, " %s", pcidevicecon->context_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_DEVICETREECON: {
struct cil_devicetreecon *devicetreecon = node->data;
cil_log(CIL_INFO, "DEVICETREECON %s", devicetreecon->path);
if (devicetreecon->context != NULL) {
cil_tree_print_context(devicetreecon->context);
} else {
cil_log(CIL_INFO, " %s", devicetreecon->context_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_FSUSE: {
struct cil_fsuse *fsuse = node->data;
cil_log(CIL_INFO, "FSUSE: ");
if (fsuse->type == CIL_FSUSE_XATTR) {
cil_log(CIL_INFO, "xattr ");
} else if (fsuse->type == CIL_FSUSE_TASK) {
cil_log(CIL_INFO, "task ");
} else if (fsuse->type == CIL_FSUSE_TRANS) {
cil_log(CIL_INFO, "trans ");
} else {
cil_log(CIL_INFO, "unknown ");
}
cil_log(CIL_INFO, "%s ", fsuse->fs_str);
if (fsuse->context != NULL) {
cil_tree_print_context(fsuse->context);
} else {
cil_log(CIL_INFO, " %s", fsuse->context_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_SID: {
struct cil_sid *sid = node->data;
cil_log(CIL_INFO, "SID: %s\n", sid->datum.name);
return;
}
case CIL_SIDCONTEXT: {
struct cil_sidcontext *sidcon = node->data;
cil_log(CIL_INFO, "SIDCONTEXT: %s", sidcon->sid_str);
if (sidcon->context != NULL) {
cil_tree_print_context(sidcon->context);
} else {
cil_log(CIL_INFO, " %s", sidcon->context_str);
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_SIDORDER: {
struct cil_sidorder *sidorder = node->data;
struct cil_list_item *sid;
if (sidorder->sid_list_str == NULL) {
cil_log(CIL_INFO, "SIDORDER: ()\n");
return;
}
cil_log(CIL_INFO, "SIDORDER: (");
cil_list_for_each(sid, sidorder->sid_list_str) {
cil_log(CIL_INFO, " %s", (char*)sid->data);
}
cil_log(CIL_INFO, " )\n");
return;
}
case CIL_POLICYCAP: {
struct cil_policycap *polcap = node->data;
cil_log(CIL_INFO, "POLICYCAP: %s\n", polcap->datum.name);
return;
}
case CIL_MACRO: {
struct cil_macro *macro = node->data;
cil_log(CIL_INFO, "MACRO %s:", macro->datum.name);
if (macro->params != NULL && macro->params->head != NULL) {
struct cil_list_item *curr_param;
cil_log(CIL_INFO, " parameters: (");
cil_list_for_each(curr_param, macro->params) {
cil_log(CIL_INFO, " flavor: %d, string: %s;", ((struct cil_param*)curr_param->data)->flavor, ((struct cil_param*)curr_param->data)->str);
}
cil_log(CIL_INFO, " )");
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_CALL: {
struct cil_call *call = node->data;
cil_log(CIL_INFO, "CALL: macro name:");
if (call->macro != NULL) {
cil_log(CIL_INFO, " %s", call->macro->datum.name);
} else {
cil_log(CIL_INFO, " %s", call->macro_str);
}
if (call->args != NULL) {
cil_log(CIL_INFO, ", args: ( ");
struct cil_list_item *item;
cil_list_for_each(item, call->args) {
struct cil_symtab_datum *datum = ((struct cil_args*)item->data)->arg;
if (datum != NULL) {
if (datum->nodes != NULL && datum->nodes->head != NULL) {
cil_tree_print_node((struct cil_tree_node*)datum->nodes->head->data);
}
} else if (((struct cil_args*)item->data)->arg_str != NULL) {
switch (item->flavor) {
case CIL_TYPE: cil_log(CIL_INFO, "type:"); break;
case CIL_USER: cil_log(CIL_INFO, "user:"); break;
case CIL_ROLE: cil_log(CIL_INFO, "role:"); break;
case CIL_SENS: cil_log(CIL_INFO, "sensitivity:"); break;
case CIL_CAT: cil_log(CIL_INFO, "category:"); break;
case CIL_CATSET: cil_log(CIL_INFO, "categoryset:"); break;
case CIL_LEVEL: cil_log(CIL_INFO, "level:"); break;
case CIL_CLASS: cil_log(CIL_INFO, "class:"); break;
default: break;
}
cil_log(CIL_INFO, "%s ", ((struct cil_args*)item->data)->arg_str);
}
}
cil_log(CIL_INFO, ")");
}
cil_log(CIL_INFO, "\n");
return;
}
case CIL_OPTIONAL: {
struct cil_optional *optional = node->data;
cil_log(CIL_INFO, "OPTIONAL: %s\n", optional->datum.name);
return;
}
case CIL_IPADDR: {
struct cil_ipaddr *ipaddr = node->data;
char buf[256];
inet_ntop(ipaddr->family, &ipaddr->ip, buf, 256);
cil_log(CIL_INFO, "IPADDR %s: %s\n", ipaddr->datum.name, buf);
break;
}
default : {
cil_log(CIL_INFO, "CIL FLAVOR: %d\n", node->flavor);
return;
}
}
}
}
void cil_tree_print(struct cil_tree_node *tree, uint32_t depth)
{
struct cil_tree_node *current = NULL;
current = tree;
uint32_t x = 0;
if (current != NULL) {
if (current->cl_head == NULL) {
if (current->flavor == CIL_NODE) {
if (current->parent->cl_head == current) {
cil_log(CIL_INFO, "%s", (char*)current->data);
} else {
cil_log(CIL_INFO, " %s", (char*)current->data);
}
} else if (current->flavor != CIL_PERM) {
for (x = 0; x<depth; x++) {
cil_log(CIL_INFO, "\t");
}
cil_tree_print_node(current);
}
} else {
if (current->parent != NULL) {
cil_log(CIL_INFO, "\n");
for (x = 0; x<depth; x++) {
cil_log(CIL_INFO, "\t");
}
cil_log(CIL_INFO, "(");
if (current->flavor != CIL_NODE) {
cil_tree_print_node(current);
}
}
cil_tree_print(current->cl_head, depth + 1);
}
if (current->next == NULL) {
if ((current->parent != NULL) && (current->parent->cl_tail == current) && (current->parent->parent != NULL)) {
if (current->flavor == CIL_PERM) {
cil_log(CIL_INFO, ")\n");
} else if (current->flavor != CIL_NODE) {
for (x = 0; x<depth-1; x++) {
cil_log(CIL_INFO, "\t");
}
cil_log(CIL_INFO, ")\n");
} else {
cil_log(CIL_INFO, ")");
}
}
if ((current->parent != NULL) && (current->parent->parent == NULL))
cil_log(CIL_INFO, "\n\n");
} else {
cil_tree_print(current->next, depth);
}
} else {
cil_log(CIL_INFO, "Tree is NULL\n");
}
}
|