Changeset 4924

Show
Ignore:
Timestamp:
04/21/10 08:07:04 (5 months ago)
Author:
joliver
Message:

Bring up to date with trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/module-loading/ChangeLog

    r4893 r4924  
     12010-04-20  Chris PeBenito <cpebenito@tresys.com> 
     2 
     3        * Fix seinfo to correctly handle cases where there are 
     4          no nodecon statements in the policy. 
     5 
     62010-04-20  Spencer Shimko <sshimko@tresys.com> 
     7 
     8        * Fixes error conditions that prevent apol from exiting.  If  
     9          window/tab was already destroyed on exit 
     10          then apol threw an error and refused to exit.  
     11 
     122010-04-15  Spencer Shimko <sshimko@tresys.com> 
     13 
     14        * Add support for displaying constraints to seinfo. 
     15        * Add constraint CUnit tests. 
     16 
    1172010-03-12  John Oliver <joliver@tresys.com> 
    218 
  • branches/module-loading/apol/analysis_tab.tcl

    r4635 r4924  
    200200    variable widgets 
    201201    variable tabs 
     202    $widgets(new) configure -state disabled 
     203    $widgets(update) configure -state disabled 
    202204 
    203205    set m [$widgets(search_opts) raise] 
     
    223225        $widgets(update) configure -state normal 
    224226    } 
     227     
     228    $widgets(new) configure -state normal 
    225229} 
    226230 
  • branches/module-loading/apol/cond_rules_tab.tcl

    r4585 r4924  
    141141    variable vals 
    142142    variable widgets 
     143    .mainframe.frame.nb.frules.nb.fApol_Cond_Rules.top.obox.f.ok configure -state disabled 
    143144 
    144145    Apol_Widget::clearSearchResults $widgets(results) 
    145146    if {![ApolTop::is_policy_open]} { 
    146147        tk_messageBox -icon error -type ok -title "Error" -message "No current policy file is opened." 
     148        .mainframe.frame.nb.frules.nb.fApol_Cond_Rules.top.obox.f.ok configure -state normal 
    147149        return 
    148150    } 
     
    158160    if {$avrule_selection == 0 && $terule_selection == 0} { 
    159161            tk_messageBox -icon error -type ok -title "Error" -message "At least one rule must be selected." 
     162            .mainframe.frame.nb.frules.nb.fApol_Cond_Rules.top.obox.f.ok configure -state normal 
    160163            return 
    161164    } 
     
    165168        if {[set bool_name $vals(name)] == {}} { 
    166169            tk_messageBox -icon error -type ok -title "Error" -message "No booleean selected." 
     170            .mainframe.frame.nb.frules.nb.fApol_Cond_Rules.top.obox.f.ok configure -state normal 
    167171            return 
    168172        } 
     
    192196    } 
    193197    Apol_Widget::appendSearchResultText $widgets(results) $text 
    194     Apol_Progress_Dialog::wait "Conditional Expressions" "Rendering conditionals" \ 
     198    if {![info exists apol_progress]} { 
     199        Apol_Progress_Dialog::wait "Conditional Expressions" "Rendering conditionals" \ 
    195200        { 
    196201            if {[ApolTop::is_capable "syntactic rules"]} { 
     
    206211            } 
    207212        } 
     213    } 
     214    .mainframe.frame.nb.frules.nb.fApol_Cond_Rules.top.obox.f.ok configure -state normal 
    208215} 
    209216 
  • branches/module-loading/apol/context_dialog.tcl

    r4585 r4924  
    2929    variable dialog 
    3030    variable vars 
     31     
    3132    if {![winfo exists $dialog]} { 
    3233        _create_dialog $parent 
     
    3839    set low_level {} 
    3940    set high_level {} 
    40  
     41     
    4142    # initialize widget states 
    4243    array set vars [list $dialog:low_enable 0  $dialog:high_enable 0] 
     
    6263        set vars($dialog:user_enable) 1 
    6364    } 
     65     
     66     
    6467 
    6568    $vars($dialog:role_box) configure -values [Apol_Roles::getRoles] 
     
    127130    set vars($dialog:user_cb) [checkbutton $user_f.enable -text "User" \ 
    128131                                  -variable Apol_Context_Dialog::vars($dialog:user_enable)] 
    129     set vars($dialog:user_box) [ComboBox $user_f.user -entrybg white -width 12 \ 
    130                                    -textvariable Apol_Context_Dialog::vars($dialog:user) -autopost 1] 
     132    set vars($dialog:user_box) [ComboBox $user_f.user -entrybg white \ 
     133                                   -width 12 \ 
     134                                   -textvariable Apol_Context_Dialog::vars($dialog:user) \ 
     135                                   -autopost 1] 
    131136    trace add variable Apol_Context_Dialog::vars($dialog:user_enable) write \ 
    132137        [list Apol_Context_Dialog::_user_changed $dialog] 
  • branches/module-loading/apol/context_selector.tcl

    r4585 r4924  
    124124proc Apol_Widget::_show_context_dialog {path} { 
    125125    variable vars 
     126    $path.context.button configure -state disabled 
    126127    set new_context [Apol_Context_Dialog::getContext $vars($path:context) $vars($path:attribute)] 
    127128    if {$new_context != {}} { 
     
    129130        set vars($path:attribute) [lindex $new_context 1] 
    130131    } 
     132     
     133    $path.context.button configure -state normal 
    131134    # the trace on this variable will trigger [_update_context_display] to execute 
    132135} 
  • branches/module-loading/apol/domaintrans_module.tcl

    r4894 r4924  
    323323 
    324324proc Apol_Analysis_domaintrans::_createAccessDialog {} { 
     325    variable widgets 
     326    $widgets(access) configure -state disabled 
    325327    destroy .domaintrans_adv 
    326328    set d [Dialog .domaintrans_adv -modal local -separator 1 -title "Domain Transition Access Filter" -parent .] 
     
    329331    _createAccessClasses [$d getframe] 
    330332    $d draw 
     333    $widgets(access) configure -state normal 
    331334} 
    332335 
  • branches/module-loading/apol/file_contexts_tab.tcl

    r4697 r4924  
    228228 
    229229proc Apol_File_Contexts::_show_info {} { 
     230    .mainframe.frame.nb.fApol_File_Contexts.opts.f.bb.b1 configure -state disabled 
    230231    Apol_Widget::showPopupParagraph "File Contexts Information" $Apol_File_Contexts::info_button_text 
     232    .mainframe.frame.nb.fApol_File_Contexts.opts.f.bb.b1 configure -state normal 
    231233} 
    232234 
  • branches/module-loading/apol/initial_sids_tab.tcl

    r4585 r4924  
    105105 
    106106    set q [new_apol_isid_query_t] 
     107     
    107108    if {[Apol_Widget::getContextSelectorState $widgets(context)]} { 
    108109        foreach {context range_match attribute} [Apol_Widget::getContextSelectorValue $widgets(context)] {break} 
    109110        $q set_context $::ApolTop::policy $context $range_match 
    110111    } 
     112     
    111113    set v [$q run $::ApolTop::policy] 
     114     
    112115    $q -acquire 
    113116    $q -delete 
     
    124127        } 
    125128    } 
     129     
    126130    Apol_Widget::appendSearchResultText $widgets(results) $results 
    127131} 
  • branches/module-loading/apol/open_policy_dialog.tcl

    r4912 r4924  
    196196    variable vars 
    197197    variable dialog 
     198    .open_policy_dialog.frame.primary.f.b configure -state disabled 
    198199    if {$vars(path_type) == "monolithic"} { 
    199200        set title "Open Monolithic Policy" 
     
    213214        $dialog itemconfigure 0 -state normal 
    214215    } 
     216    .open_policy_dialog.frame.primary.f.b configure -state normal 
    215217} 
    216218 
     
    365367    variable dialog 
    366368    variable vars 
    367  
     369    .open_policy_dialog.bbox.b0 configure -state disabled 
    368370    if {[string trim $vars(primary_file)] != {}} { 
    369371        set ppath [list_to_policy_path $vars(path_type) $vars(primary_file) $vars(mod_paths)] 
     
    372374        } 
    373375    } 
     376    .open_policy_dialog.bbox.b0 configure -state normal 
    374377} 
    375378 
  • branches/module-loading/apol/progress_dialog.tcl

    r4912 r4924  
    3636        set text_width 32 
    3737    } 
    38     ProgressDlg .apol_progress -title $title \ 
    39         -type normal -stop {} -separator 1 -parent [focus] -maximum 2 \ 
    40         -width $text_width -textvariable Apol_Progress_Dialog::text \ 
    41         -variable Apol_Progress_Dialog::val 
     38 
     39    if {[info exists .apol_progress] == 0} { 
     40        ProgressDlg .apol_progress -title $title \ 
     41            -type normal -stop {} -separator 1 -parent . -maximum 2 \ 
     42            -width $text_width -textvariable Apol_Progress_Dialog::text \ 
     43            -variable Apol_Progress_Dialog::val 
     44    } 
    4245 
    4346    set orig_cursor [. cget -cursor] 
  • branches/module-loading/apol/range_selector.tcl

    r4585 r4924  
    131131 
    132132proc Apol_Widget::_show_mls_range_dialog {path} { 
     133    $path.range.button configure -state disabled 
    133134    set range [Apol_Range_Dialog::getRange $Apol_Widget::vars($path:range)] 
    134135    if {$range != {}} { 
     
    136137        $range -acquire 
    137138    } 
     139     
     140    $path.range.button configure -state normal 
    138141    # the trace on this variable will trigger [_update_range_display] 
    139142    # to execute 
  • branches/module-loading/apol/relabel_module.tcl

    r4635 r4924  
    327327 
    328328proc Apol_Analysis_relabel::_createAdvancedDialog {} { 
     329    variable widgets 
     330    $widgets(advanced) configure -state disabled 
    329331    destroy .relabel_analysis_adv 
    330332    variable vals 
     
    373375 
    374376    $d draw 
     377    $widgets(advanced) configure -state normal 
    375378} 
    376379 
  • branches/module-loading/apol/top.tcl

    r4912 r4924  
    478478        "attribs" new_apol_attr_query_t 
    479479    } 
     480     
    480481    foreach {key func} $query_funcs { 
    481482        set q [$func] 
     
    585586        _close_policy 
    586587    } 
     588     
    587589    Apol_File_Contexts::close 
    588590    _write_configuration_file 
  • branches/module-loading/apol/transflow_module.tcl

    r4635 r4924  
    311311 
    312312proc Apol_Analysis_transflow::_createAdvancedDialog {} { 
     313    variable widgets 
     314    $widgets(advanced) configure -state disabled 
    313315    destroy .transflow_adv 
    314316    variable vals 
     
    318320        if {![ApolTop::openDefaultPermMap]} { 
    319321            return "This analysis requires that a permission map is loaded." 
    320        
     322       
    321323    } 
    322324 
     
    352354    pack $attrib_box -side top -expand 1 -fill x -padx 10 
    353355    _attribEnabled $attrib_box 
    354  
     356     
    355357    $d draw 
     358    $widgets(advanced) configure -state normal 
    356359} 
    357360 
     
    386389    set cb [checkbutton $f.cb -text "Exclude permissions with weights below:" \ 
    387390                -variable Apol_Analysis_transflow::vals(classes:threshold_enable)] 
     391     
    388392    set weight [spinbox $f.threshold -from 1 -to 10 -increment 1 \ 
    389393                    -width 2 -bg white -justify right \ 
     
    627631        if {![ApolTop::openDefaultPermMap]} { 
    628632            return "This analysis requires that a permission map is loaded." 
    629        
     633       
    630634        apol_tcl_clear_info_string 
    631635    } 
  • branches/module-loading/apol/users_tab.tcl

    r4585 r4924  
    156156    variable opts 
    157157    if {$opts($name2)} { 
    158        $path configure -state normal -entrybg white 
     158    $path configure -state normal -entrybg white 
    159159    } else { 
    160160        $path configure -state disabled -entrybg $ApolTop::default_bg_color 
     
    175175proc Apol_Users::_show_level_dialog {} { 
    176176    variable opts 
     177    .mainframe.frame.nb.fcomponents.nb.fApol_Users.pw.f1.frame.obox.f.default.button configure -state disabled 
    177178    set new_level [Apol_Level_Dialog::getLevel $opts(default_level)] 
    178179    if {$new_level != {}} { 
     
    180181        $opts(default_level) -acquire 
    181182    } 
     183    .mainframe.frame.nb.fcomponents.nb.fApol_Users.pw.f1.frame.obox.f.default.button configure -state normal 
    182184} 
    183185 
     
    205207    variable opts 
    206208    variable widgets 
     209    .mainframe.frame.nb.fcomponents.nb.fApol_Users.pw.f1.frame.obox.f.ok configure -state disabled 
    207210 
    208211    Apol_Widget::clearSearchResults $widgets(results) 
    209212    if {![ApolTop::is_policy_open]} { 
    210213        tk_messageBox -icon error -type ok -title "Error" -message "No current policy file is opened." 
     214        .mainframe.frame.nb.fcomponents.nb.fApol_Users.pw.f1.frame.obox.f.ok configure -state normal 
    211215        return 
    212216    } 
     
    214218        if {$opts(role) == ""} { 
    215219            tk_messageBox -icon error -type ok -title "Error" -message "No role selected." 
     220            .mainframe.frame.nb.fcomponents.nb.fApol_Users.pw.f1.frame.obox.f.ok configure -state normal 
    216221            return 
    217222        } 
     
    223228        if {$opts(default_level) == {}} { 
    224229            tk_messageBox -icon error -type ok -title "Error" -message "No default level selected." 
     230            .mainframe.frame.nb.fcomponents.nb.fApol_Users.pw.f1.frame.obox.f.ok configure -state normal 
    225231            return 
    226232        } 
     
    235241        if {$range == {}} { 
    236242            tk_messageBox -icon error -type ok -title "Error" -message "No range selected." 
     243            .mainframe.frame.nb.fcomponents.nb.fApol_Users.pw.f1.frame.obox.f.ok configure -state normal 
    237244            return 
    238245        } 
     
    267274    } 
    268275    Apol_Widget::appendSearchResultText $widgets(results) $text 
     276    .mainframe.frame.nb.fcomponents.nb.fApol_Users.pw.f1.frame.obox.f.ok configure -state normal 
    269277} 
    270278 
  • branches/module-loading/configure.ac

    r4880 r4924  
    704704 
    705705have_cunit="no" 
    706 AC_CHECK_LIB(cunit, CU_initialize_registry, have_cunit="yes", AC_MSG_WARN([CUnit not found; `make check' will fail.])) 
    707 if test ${have_cunit} = "yes"; then 
    708   CUNIT_LIB_FLAG="-lcunit" 
    709   AC_SUBST(CUNIT_LIB_FLAG) 
    710 fi 
     706AC_CHECK_LIB(cunit,  
     707    CU_initialize_registry,  
     708    [have_cunit="yes" 
     709     CUNIT_LIB_FLAG="-lcunit"], 
     710    [AC_CHECK_LIB(cunit, 
     711         CU_curses_run_tests, 
     712         [have_cunit="yes" 
     713          CUNIT_LIB_FLAG="-lcunit -lncurses"], 
     714         AC_MSG_WARN([Compatible CUnit not found; "make check" will fail.]), 
     715         -lncurses) 
     716    ] 
     717
     718AC_SUBST([CUNIT_LIB_FLAG]) 
     719 
    711720#AC_MSG_CHECKING([for FUSE]) 
    712721#pkg-config --exists fuse 
  • branches/module-loading/libapol/tests/Makefile.am

    r4692 r4924  
    1010        terule-tests.c terule-tests.h \ 
    1111        user-tests.c user-tests.h \ 
     12        constrain-tests.c constrain-tests.h \ 
     13        ../../libqpol/src/queue.c ../../libqpol/src/queue.h \ 
    1214        libapol-tests.c 
    1315 
  • branches/module-loading/libapol/tests/libapol-tests.c

    r4692 r4924  
    3535#include "role-tests.h" 
    3636#include "terule-tests.h" 
     37#include "constrain-tests.h" 
    3738#include "user-tests.h" 
    3839 
     
    4445 
    4546        CU_SuiteInfo suites[] = { 
    46                 {"Policy Version 21", policy_21_init, policy_21_cleanup, policy_21_tests} 
    47                 , 
    48                 {"AV Rule Query", avrule_init, avrule_cleanup, avrule_tests} 
    49                 , 
    50                 {"Domain Transition Analysis", dta_init, dta_cleanup, dta_tests} 
    51                 , 
    52                 {"Infoflow Analysis", infoflow_init, infoflow_cleanup, infoflow_tests} 
    53                 , 
    54                 {"Role Query", role_init, role_cleanup, role_tests} 
    55                 , 
    56                 {"TE Rule Query", terule_init, terule_cleanup, terule_tests} 
    57                 , 
    58                 {"User Query", user_init, user_cleanup, user_tests} 
    59                 , 
     47                {"Policy Version 21", policy_21_init, policy_21_cleanup, policy_21_tests}, 
     48                {"AV Rule Query", avrule_init, avrule_cleanup, avrule_tests}, 
     49                {"Domain Transition Analysis", dta_init, dta_cleanup, dta_tests}, 
     50                {"Infoflow Analysis", infoflow_init, infoflow_cleanup, infoflow_tests}, 
     51                {"Role Query", role_init, role_cleanup, role_tests}, 
     52                {"TE Rule Query", terule_init, terule_cleanup, terule_tests}, 
     53                {"User Query", user_init, user_cleanup, user_tests}, 
     54                {"Constrain query", constrain_init, constrain_cleanup, constrain_tests}, 
    6055                CU_SUITE_INFO_NULL 
    6156        }; 
  • branches/module-loading/libqpol/src/constraint_query.c

    r4585 r4924  
    752752        constraint_expr_t *internal_expr = NULL; 
    753753        cexpr_name_state_t *cns = NULL; 
     754        int policy_type = 0; 
    754755 
    755756        if (iter) 
     
    761762                return STATUS_ERR; 
    762763        } 
     764 
     765        if (qpol_policy_get_type(policy, &policy_type)) 
     766                return STATUS_ERR; 
    763767 
    764768        internal_expr = (constraint_expr_t *) expr; 
     
    776780        } 
    777781        if (internal_expr->attr & QPOL_CEXPR_SYM_TYPE) { 
    778                 cns->inc = &(internal_expr->type_names->types); 
    779                 cns->sub = &(internal_expr->type_names->negset); 
     782                if (policy_type == QPOL_POLICY_KERNEL_BINARY) { 
     783                        cns->inc = &(internal_expr->names); 
     784                } else { 
     785                        cns->inc = &(internal_expr->type_names->types); 
     786                        cns->sub = &(internal_expr->type_names->negset); 
     787                } 
    780788        } else { 
    781789                cns->inc = &(internal_expr->names); 
  • branches/module-loading/libqpol/swig/python/Makefile.am

    r4893 r4924  
    3333        -rm -rf $(DESTDIR)$(wrappedsodir)/$(wrappedso_SONAME) $(DESTDIR)$(wrappedsodir)/_qpol.so 
    3434 
    35 MOSTLYCLEANFILES = $(BUILT_SOURCES) $(wrappedso_DATA) $(wrappedpy_DATA) $(wrappedso_SONAME) _qpol.so qpol.pyc 
     35MOSTLYCLEANFILES = $(BUILT_SOURCES) $(wrappedso_DATA) qpol.py $(wrappedso_SONAME) _qpol.so qpol.pyc 
  • branches/module-loading/secmds/seinfo.c

    r4867 r4924  
    4949 
    5050#define COPYRIGHT_INFO "Copyright (C) 2003-2007 Tresys Technology, LLC" 
     51 
     52/* placeholder for empty set in constraint statements */ 
     53#define CONSTRAIN_NULL_SET "<empty set>" 
    5154 
    5255static char *policy_file = NULL; 
     
    6871        OPT_NETIFCON, OPT_NODECON, OPT_PORTCON, OPT_PROTOCOL, 
    6972        OPT_PERMISSIVE, OPT_POLCAP, 
    70         OPT_ALL, OPT_STATS 
     73        OPT_ALL, OPT_STATS, OPT_CONSTRAIN 
    7174}; 
    7275 
     
    8083        {"user", optional_argument, NULL, 'u'}, 
    8184        {"bool", optional_argument, NULL, 'b'}, 
     85        {"constrain", no_argument, NULL, OPT_CONSTRAIN}, 
    8286        {"initialsid", optional_argument, NULL, OPT_INITIALSID}, 
    8387        {"fs_use", optional_argument, NULL, OPT_FS_USE}, 
     
    9195        {"stats", no_argument, NULL, OPT_STATS}, 
    9296        {"all", no_argument, NULL, OPT_ALL}, 
     97        {"line-breaks", no_argument, NULL, 'l'}, 
    9398        {"expand", no_argument, NULL, 'x'}, 
    9499        {"help", no_argument, NULL, 'h'}, 
     
    121126        printf("  -u[NAME], --user[=NAME]          print users\n"); 
    122127        printf("  -b[NAME], --bool[=NAME]          print conditional booleans\n"); 
     128        printf("  --constrain                      print constrain statements\n"); 
     129        printf("  -l, --line-breaks                print line breaks in constrain statements\n"); 
    123130        printf("  --initialsid[=NAME]              print initial SIDs\n"); 
    124131        printf("  --fs_use[=TYPE]                  print fs_use statements\n"); 
     
    10751082 
    10761083        n_nodecons = apol_vector_get_size(v); 
    1077         if (!n_nodecons) { 
    1078                 ERR(policydb, "Provided address (%s) is not valid.", addr); 
    1079                 goto cleanup; 
    1080         } 
    1081  
    1082         if (!addr) 
     1084 
     1085        if (!addr) { 
    10831086                fprintf(fp, "Nodecon: %zd\n", n_nodecons); 
    1084  
    1085         for (i = 0; i < apol_vector_get_size(v); i++) { 
     1087        } else if (!n_nodecons) { 
     1088                ERR(policydb, "No matching nodecon for address %s.", addr); 
     1089                retval = 1; 
     1090                goto cleanup; 
     1091        } 
     1092 
     1093        for (i = 0; i < n_nodecons; i++) { 
    10861094                nodecon = apol_vector_get_element(v, i); 
    10871095                tmp = apol_nodecon_render(policydb, nodecon); 
     
    10911099                free(tmp); 
    10921100        } 
    1093  
    1094         if (addr && !n_nodecons) 
    1095                 ERR(policydb, "No matching nodecon for address %s.", addr); 
    10961101 
    10971102        retval = 0; 
     
    13341339} 
    13351340 
     1341static const char *get_attr_string(int attr) 
     1342{ 
     1343        const char *string = ""; 
     1344        switch (attr) 
     1345        { 
     1346                case QPOL_CEXPR_SYM_USER: 
     1347                        string = "u1"; 
     1348                        break; 
     1349                case QPOL_CEXPR_SYM_ROLE: 
     1350                        string = "r1"; 
     1351                        break; 
     1352                case QPOL_CEXPR_SYM_TYPE: 
     1353                        string = "t1"; 
     1354                        break; 
     1355 
     1356                case QPOL_CEXPR_SYM_USER+QPOL_CEXPR_SYM_TARGET: 
     1357                        string = "u2"; 
     1358                        break; 
     1359                case QPOL_CEXPR_SYM_ROLE+QPOL_CEXPR_SYM_TARGET: 
     1360                        string = "r2"; 
     1361                        break; 
     1362                case QPOL_CEXPR_SYM_TYPE+QPOL_CEXPR_SYM_TARGET: 
     1363                        string = "t2"; 
     1364                        break; 
     1365 
     1366                case QPOL_CEXPR_SYM_USER+QPOL_CEXPR_SYM_XTARGET: 
     1367                        string = "u3"; 
     1368                        break; 
     1369                case QPOL_CEXPR_SYM_ROLE+QPOL_CEXPR_SYM_XTARGET: 
     1370                        string = "r3"; 
     1371                        break; 
     1372                case QPOL_CEXPR_SYM_TYPE+QPOL_CEXPR_SYM_XTARGET: 
     1373                        string = "t3"; 
     1374                        break; 
     1375 
     1376                case QPOL_CEXPR_SYM_L1L2: 
     1377                        string = "l1 l2"; 
     1378                        break; 
     1379                case QPOL_CEXPR_SYM_L1H2: 
     1380                        string = "l1 h2"; 
     1381                        break; 
     1382                case QPOL_CEXPR_SYM_H1L2: 
     1383                        string = "h1 l2"; 
     1384                        break; 
     1385                case QPOL_CEXPR_SYM_H1H2: 
     1386                        string = "h1 h2"; 
     1387                        break; 
     1388                case QPOL_CEXPR_SYM_L1H1: 
     1389                        string = "l1 h1"; 
     1390                        break; 
     1391                case QPOL_CEXPR_SYM_L2H2: 
     1392                        string = "l2 h2"; 
     1393                        break; 
     1394        } 
     1395 
     1396        return string; 
     1397} 
     1398 
     1399static const char *get_op_string(int op) 
     1400{ 
     1401        char *string = ""; 
     1402 
     1403        switch (op) 
     1404        { 
     1405                case QPOL_CEXPR_OP_EQ: 
     1406                        string = "=="; 
     1407                        break; 
     1408                case QPOL_CEXPR_OP_NEQ: 
     1409                        string = "!="; 
     1410                        break; 
     1411                case QPOL_CEXPR_OP_DOM: 
     1412                        string = "dom"; 
     1413                        break; 
     1414                case QPOL_CEXPR_OP_DOMBY: 
     1415                        string = "domby"; 
     1416                        break; 
     1417                case QPOL_CEXPR_OP_INCOMP: 
     1418                        string = "incomp"; 
     1419                        break; 
     1420        } 
     1421 
     1422        return string; 
     1423} 
     1424 
     1425static int print_constraints(FILE * fp, int expand, const apol_policy_t * policydb, int linebreaks) 
     1426{ 
     1427        int retval = -1; 
     1428        const char *class_name = NULL; 
     1429        char *constrain_type; 
     1430        char *perm_list = "No Perms Extracted"; 
     1431        const qpol_constraint_expr_node_t *expr = NULL; 
     1432        qpol_iterator_t *policy_iter = NULL;    // Iterates over all constraints in a policy 
     1433        qpol_iterator_t *perm_iter = NULL;              // Iterates over permissions in a constraint 
     1434        qpol_iterator_t *expr_iter = NULL;              // Iterates over expression in a constraint 
     1435        qpol_policy_t *q = apol_policy_get_qpol(policydb); 
     1436        qpol_constraint_t *constraint = NULL; 
     1437        const qpol_class_t *class; 
     1438        size_t n_constraints = 0; 
     1439        int expr_type = 0; 
     1440        int sym_type = 0;               // 'attr' in struct constraint_expr 
     1441        int op = 0; 
     1442 
     1443        if (qpol_policy_get_constraint_iter(q, &policy_iter) != 0) 
     1444        { 
     1445                ERR (policydb, "%s", "Policy constraint iterator not accessible"); 
     1446                return retval; 
     1447        } 
     1448        if (qpol_iterator_get_size(policy_iter, &n_constraints) != 0) 
     1449        { 
     1450                ERR(policydb, "%s", "Policy size computation failed"); 
     1451                goto cleanup; 
     1452        } 
     1453 
     1454        fprintf(fp, "\nConstraints: %zd\n", n_constraints); 
     1455 
     1456        // Iterate through constraints 
     1457        for (; qpol_iterator_end(policy_iter) == 0; qpol_iterator_next(policy_iter)) 
     1458        { 
     1459                constrain_type = ""; 
     1460                if (qpol_iterator_get_item(policy_iter, (void **)&constraint) != 0) 
     1461                { 
     1462                        ERR(policydb, "%s", "Can't get constraint from iterator\n"); 
     1463                        goto cleanup; 
     1464                } 
     1465 
     1466                if (qpol_constraint_get_class(q, constraint, &class) != 0) 
     1467                { 
     1468                        ERR(policydb, "%s", "Can't get class from constraint\n"); 
     1469                        goto cleanup; 
     1470                } 
     1471 
     1472                if (qpol_class_get_name(q, class, &class_name) != 0) 
     1473                { 
     1474                        ERR(policydb, "%s", "Can't get class name from constraint\n"); 
     1475                        goto cleanup; 
     1476                } 
     1477 
     1478                // Get expression, we need to look into it. 
     1479                if (qpol_constraint_get_expr_iter (q, constraint, &expr_iter) != 0) 
     1480                { 
     1481                        ERR(policydb, "%s", "Can't get expression from constraint\n"); 
     1482                        goto cleanup; 
     1483                } 
     1484                // Traverse the iterator to see if this is mlsconstrain 
     1485                for (; qpol_iterator_end(expr_iter) == 0; qpol_iterator_next(expr_iter)) 
     1486                { 
     1487                        if (qpol_iterator_get_item(expr_iter, (void **)&expr) != 0) 
     1488                        { 
     1489                                ERR(policydb, "%s", "Can't get expression from iterator\n"); 
     1490                                goto cleanup; 
     1491                        } 
     1492 
     1493                        if (qpol_constraint_expr_node_get_sym_type(q, expr, &sym_type) != 0) 
     1494                        { 
     1495                                ERR(policydb, "%s", "Can't get sym_type from expression\n"); 
     1496                                goto cleanup; 
     1497                        } 
     1498 
     1499                        if (sym_type >= QPOL_CEXPR_SYM_L1L2) 
     1500                        { 
     1501                                constrain_type = "mls"; 
     1502                                break; 
     1503                        } 
     1504                } 
     1505 
     1506        // print permissions 
     1507                fprintf (fp, "%sconstrain { %s } { ", constrain_type, class_name); 
     1508 
     1509                if (qpol_constraint_get_perm_iter (q, constraint, &perm_iter) != 0) 
     1510                { 
     1511                        ERR(policydb, "%s", "Can't get permissions from constraint\n"); 
     1512                        goto cleanup; 
     1513                } 
     1514 
     1515                for (; qpol_iterator_end(perm_iter) == 0; qpol_iterator_next(perm_iter)) 
     1516                { 
     1517                        if (qpol_iterator_get_item(perm_iter, (void **)&perm_list) != 0) 
     1518                        { 
     1519                                ERR(policydb, "%s", "Can't get permissions from iterator\n"); 
     1520                                goto cleanup; 
     1521                        } 
     1522 
     1523                        fprintf (fp, "%s ", perm_list); 
     1524                        free (perm_list);               // Strdup created the string. 
     1525                } 
     1526                fprintf (fp, " } "); 
     1527 
     1528                // dump RPN expressions 
     1529                if (qpol_constraint_get_expr_iter (q, constraint, &expr_iter) != 0) 
     1530                { 
     1531                        ERR(policydb, "%s", "Can't get expression from constraint\n"); 
     1532                        goto cleanup; 
     1533                } 
     1534 
     1535                fprintf (fp, "\n( "); 
     1536                for (; qpol_iterator_end(expr_iter) == 0; qpol_iterator_next(expr_iter)) 
     1537                { 
     1538                        qpol_iterator_t *names_iter = NULL; 
     1539 
     1540                        if (qpol_iterator_get_item(expr_iter, (void **)&expr) != 0) 
     1541                        { 
     1542                                ERR(policydb, "%s", "Can't get expression from iterator\n"); 
     1543                                goto cleanup; 
     1544                        } 
     1545 
     1546                        if (qpol_constraint_expr_node_get_op (q, expr, &op) != 0) 
     1547                        { 
     1548                                ERR(policydb, "%s", "Can't get op from expression\n"); 
     1549                                goto cleanup; 
     1550                        } 
     1551 
     1552                        if (qpol_constraint_expr_node_get_sym_type(q, expr, &sym_type) != 0) 
     1553                        { 
     1554                                ERR(policydb, "%s", "Can't get sym_type from expression\n"); 
     1555                                goto cleanup; 
     1556                        } 
     1557 
     1558                        if (qpol_constraint_expr_node_get_expr_type(q, expr, &expr_type) != 0) 
     1559                        { 
     1560                                ERR(policydb, "%s", "Can't get expr_type from expression\n"); 
     1561                                goto cleanup; 
     1562                        } 
     1563 
     1564                        if (linebreaks) 
     1565                                fprintf (fp, "\n\t"); 
     1566 
     1567                        if (expr_type == QPOL_CEXPR_TYPE_NOT) 
     1568                        { 
     1569                                fprintf (fp, " ! "); 
     1570                        } 
     1571                        if (expr_type == QPOL_CEXPR_TYPE_AND) 
     1572                        { 
     1573                                fprintf (fp, " && "); 
     1574                        } 
     1575                        if (expr_type == QPOL_CEXPR_TYPE_OR) 
     1576                        { 
     1577                                fprintf (fp, " || "); 
     1578                        } 
     1579                        if (expr_type == QPOL_CEXPR_TYPE_ATTR) 
     1580                        { 
     1581                                fprintf (fp, " %s ", get_attr_string(sym_type)); 
     1582                                fprintf (fp, "%s ", get_attr_string(sym_type | QPOL_CEXPR_SYM_TARGET)); 
     1583                                fprintf (fp, "%s ", get_op_string(op)); 
     1584                        } 
     1585                        if (expr_type == QPOL_CEXPR_TYPE_NAMES) 
     1586                        { 
     1587                                size_t name_size=0; 
     1588 
     1589                                fprintf (fp, " %s ", get_attr_string(sym_type)); 
     1590 
     1591                                if (qpol_constraint_expr_node_get_names_iter (q, expr, &names_iter) != 0) 
     1592                                { 
     1593                                        ERR(policydb, "%s", "Can't get names iterator from expression\n"); 
     1594                                        goto cleanup; 
     1595                                } 
     1596 
     1597                                if (qpol_iterator_get_size(names_iter, &name_size) != 0) 
     1598                                { 
     1599                                        ERR(policydb, "%s", "Can't get size from names iterator\n"); 
     1600                                        goto cleanup; 
     1601                                } 
     1602                                if (name_size > 0) 
     1603                                { 
     1604                                        if (name_size > 1) 
     1605                                                fprintf (fp, "{ "); 
     1606 
     1607                                        for (; qpol_iterator_end(names_iter) == 0; qpol_iterator_next(names_iter)) 
     1608                                        { 
     1609                                                char *lname = NULL; 
     1610 
     1611                                                if (qpol_iterator_get_item (names_iter, (void **)&lname) != 0) 
     1612                                                { 
     1613                                                        ERR(policydb, "%s", "Can't get names from iterator\n"); 
     1614                                                        goto cleanup; 
     1615                                                } 
     1616 
     1617                                                fprintf (fp, "%s ", lname); 
     1618                                                free (lname); 
     1619 
     1620                                        } 
     1621                                        if (name_size > 1) 
     1622                                                fprintf (fp, "} "); 
     1623                                } else { 
     1624                                        fprintf (fp, "%s ", CONSTRAIN_NULL_SET); 
     1625                                } 
     1626 
     1627                                fprintf (fp, "%s ", get_op_string(op)); 
     1628                        } 
     1629                } 
     1630                if (linebreaks) 
     1631                        fprintf (fp, "\n);\n\n"); 
     1632                else 
     1633                        fprintf (fp, ");\n\n"); 
     1634        } 
     1635 
     1636        retval = 0; 
     1637 
     1638cleanup:        // close and destroy iterators etc. 
     1639        if (policy_iter != NULL) qpol_iterator_destroy(&policy_iter); 
     1640        if (perm_iter != NULL) qpol_iterator_destroy(&perm_iter); 
     1641        if (expr_iter != NULL) qpol_iterator_destroy(&expr_iter); 
     1642 
     1643        return retval; 
     1644} 
     1645 
     1646 
    13361647int main(int argc, char **argv) 
    13371648{ 
    13381649        int classes, types, attribs, roles, users, all, expand, stats, rt, optc, isids, bools, sens, cats, fsuse, genfs, netif, 
    1339                 node, port, permissives, polcaps
     1650                node, port, permissives, polcaps, constrain, linebreaks
    13401651        apol_policy_t *policydb = NULL; 
    13411652        apol_policy_path_t *pol_path = NULL; 
     
    13491660                genfs_type = netif_name = node_addr = port_num = permissive_name = polcap_name = NULL; 
    13501661        classes = types = attribs = roles = users = all = expand = stats = isids = bools = sens = cats = fsuse = genfs = netif = 
    1351                 node = port = permissives = polcaps = 0; 
    1352         while ((optc = getopt_long(argc, argv, "c::t::a::r::u::b::xhV", longopts, NULL)) != -1) { 
     1662                node = port = permissives = polcaps = constrain = linebreaks = 0; 
     1663        while ((optc = getopt_long(argc, argv, "c::t::a::r::u::b::lxhV", longopts, NULL)) != -1) { 
    13531664                switch (optc) { 
    13541665                case 0: 
     
    14431754                case 'x':              /* expand */ 
    14441755                        expand = 1; 
     1756                        break; 
     1757                case 'l':       /* Print line breaks in constraints */ 
     1758                        linebreaks=1; 
     1759                        break; 
     1760                case OPT_CONSTRAIN:     /* Print constraints */ 
     1761                        constrain=1; 
    14451762                        break; 
    14461763                case OPT_STATS: 
     
    14661783 
    14671784        /* if no options, then show stats */ 
    1468         if (classes + types + attribs + roles + users + isids + bools + sens + cats + fsuse + genfs + netif + node + port + permissives + polcaps + all < 1) { 
     1785        if (classes + types + attribs + roles + users + isids + bools + sens + cats + fsuse + genfs + netif + node + port + permissives + polcaps + constrain + all < 1) { 
    14691786                stats = 1; 
    14701787        } 
     
    15681885        if (polcaps || all) 
    15691886                print_polcaps(stdout, polcap_name, expand, policydb); 
     1887        if (constrain || all) 
     1888                print_constraints(stdout, expand, policydb, linebreaks); 
    15701889 
    15711890        apol_policy_destroy(&policydb);