Commit Graph

97 Commits

Author SHA1 Message Date
Chris PeBenito
e7ec9ccb60 Fix symbol hashing and provide more useful symbol repr
Hash on the value since there are multiple levels of indirection to the
underlying object.  Otherwise hashing keys never match up multiple
instances of a Python object that point to the same policy object.

Also add a repr function that will make debugging doable when dealing
with Symbol objects instead of string representations.
2014-11-09 11:27:38 -05:00
Chris PeBenito
5be254a309 Change infoflow to use TypeAttr objects rather than string representations
This will also catch invalid types passed in for analysis.
2014-11-09 11:27:38 -05:00
Chris PeBenito
a52af4c606 Add a lookup function for types/attributes.
Fix SWIG to properly raise exception on error.
2014-11-09 11:27:31 -05:00
Chris PeBenito
e53be65ebe Silence error message output generated by libqpol. 2014-11-09 10:20:33 -05:00
Chris PeBenito
4f5486f033 Add netifcon query to seinfo. 2014-11-08 22:44:58 -05:00
Chris PeBenito
669bc5194a Implement NodeconQuery. 2014-11-08 22:40:42 -05:00
Chris PeBenito
248df414ab Add MLSRuleQuery unit tests.
Turns out the rules are always expanded, so indirect options had
no effect.
2014-11-06 19:59:02 -05:00
Chris PeBenito
0fb0940fe3 Documentation fixes. 2014-11-06 19:56:30 -05:00
Chris PeBenito
fc597fed99 Add nodecon query.
It could use IPv6 tests, but those have the same code paths as IPv4.
2014-11-05 13:09:35 -05:00
Chris PeBenito
574919cec3 Be explicit about which field to match in seinfo. 2014-11-03 15:00:02 -05:00
Chris PeBenito
2842962942 Add FSUseQuery. 2014-11-03 13:50:06 -05:00
Chris PeBenito
63e483f0d3 Undo incorrect signedness change in define_compute_type_helper(). 2014-11-03 08:28:50 -05:00
Chris PeBenito
24eed203c2 Remove one additional incorrect pointer check missed in cb20942. 2014-11-02 22:14:06 -05:00
Chris PeBenito
6475a73a36 Change qpol wrapper to return strings for rule types.
Removes low-level policy representation details from the interface for
avrule/terule structs and adds the member function for filename_trans,
role_allow, role_trans, and range_trans structs.
2014-11-02 14:20:30 -05:00
Chris PeBenito
3058b24357 Add additional compiler warnings, as suggested by Nicolas Iooss. 2014-11-02 13:38:41 -05:00
Chris PeBenito
d0d78cebda One pair of additional signedness fixes from -Wsign-compare. 2014-11-02 13:21:38 -05:00
Chris PeBenito
dee8055c8e Merge branch 'fishilico-fix-gcc-warnings'
Closes #1
2014-11-02 13:19:43 -05:00
Nicolas Iooss
f40cb645f7 Constify yyerror argument in libqpol 2014-11-02 13:02:59 -05:00
Nicolas Iooss
6be638327f Cast the return value to non-const void in ebitmap_state_get_cur_polcap
libqpol' hashtable iterator uses non-const data, so
ebitmap_state_get_cur_polcap needs to return a "void *" out of a "const
char *".

This fixes the following gcc warning:

    libqpol/iterator.c: In function 'ebitmap_state_get_cur_polcap':
    libqpol/iterator.c:653:2: warning: return discards 'const' qualifier
    from pointer target type
      return sepol_polcap_getname(es->cur);
      ^

This also adds a warning from "gcc -Wcast-qual" but compiling with this
switch leads to way more warnings.
2014-11-02 13:02:59 -05:00
Nicolas Iooss
edca1ac4c7 Treat literal strings as constant
Literal strings are located in read-only memory and should be "const
char*".  "gcc -Wwrite-strings" warns when using non-const literal
strings with messages like:

    libqpol/policy_parse.y: In function 'yyparse':
    libqpol/policy_parse.y:381:21: warning: passing argument 1 of
    'insert_id' discards 'const' qualifier from pointer target type
         { if (insert_id("T",0)) return -1; }
                     ^

Fix these warnings by using "const char*" instead of "char*" for some
function parameters.

This makes gcc report other warnings about hashtab_search (from
libsepol).  This function incorrectly defines its second parameter as
"char *const key" instead of "const char* key" (this fact is hidden
behind hashtab_key_t typedef).
2014-11-02 13:02:59 -05:00
Nicolas Iooss
2994d1ca1d Cast the 2nd parameter of hashtab_search to hashtab_key_t
"gcc -Wwrite-strings" reported warnings when using hashtab_search (from
libsepol) with string literals as its second parameter is a non-constant
string.

Indeed /usr/include/sepol/policydb/hashtab.h contains:

    typedef char *hashtab_key_t;
    /* ... */
    extern hashtab_datum_t hashtab_search(hashtab_t h, const hashtab_key_t k);

This means the second parameter is "char *const k", not "const char *k".
As a consequence:

* Casting to "const hashtab_key_t" leads to misunderstanding the code.
* "const char*" variables need to be explicitly casted to "char*" or
  "hashtab_key_t" before calling hashtab_search.
* When using "gcc -Wwrite-strings", literal strings need to be casted to
  "char*" or "hashtab_key_t" before calling hashtab_search.
* "gcc -Wcast-qual" reports an awful amount of warnings due to
  const-to-nonconst pointer casts.

Add missing casts to hashtab_key_t to help finding real bugs in
setools/libqpol with gcc flags.
2014-11-02 13:02:58 -05:00
Nicolas Iooss
2b380727e0 Fix typo in variable name in qpol_policy_get_genfscon_by_name
This bug was found with "gcc -Wunused-but-set-variable" because error
variable was never used in qpol_policy_get_genfscon_by_name
2014-11-02 13:02:58 -05:00
Nicolas Iooss
ce8323954d Remove unused-by-set variables
This fixes gcc warnings like:

    libqpol/avrule_query.c: In function 'qpol_avrule_get_perm_iter':
    libqpol/avrule_query.c:159:14: warning: variable 'db' set but not used
    [-Wunused-but-set-variable]
      policydb_t *db = NULL;
                  ^
2014-11-02 13:02:58 -05:00
Nicolas Iooss
b8f6292bfa Use abort() instead of assert(0) to mark unreachable code
"python setup.py build" compiles libqpol with -DNDEBUG, which disables
the effect of assert(0).  abort() is not affected by NDEBUG, so use it
instead.

This fixes gcc warnings like this:

    libqpol/module_compiler.c: In function 'declare_role':
    libqpol/module_compiler.c:314:1: warning: control reaches end of
    non-void function [-Wreturn-type]
2014-11-02 13:02:58 -05:00
Nicolas Iooss
b029b164c4 Fix comparisons between numbers with mismatched signedness in libqpol
Fix warnings reported by "gcc -Wsign-compare"
2014-11-02 13:02:58 -05:00
Nicolas Iooss
b5da5313d4 Fix policy_version sign in qpol_constraint_expr_node_get_names_iter
gcc reported:

    libqpol/constraint_query.c: In function 'qpol_constraint_expr_node_get_names_iter':
    libqpol/constraint_query.c:783:45: error: pointer targets in passing
    argument 2 of 'qpol_policy_get_policy_version' differ in signedness
    [-Werror=pointer-sign]
      if (qpol_policy_get_policy_version(policy, &policy_version))
                                                 ^
    In file included from libqpol/constraint_query.c:29:0:
    libqpol/include/qpol/policy.h:250:13: note: expected 'unsigned int
    *' but argument is of type 'int *'
      extern int qpol_policy_get_policy_version(const qpol_policy_t * policy, unsigned int *version);
                 ^
2014-11-02 13:02:57 -05:00
Nicolas Iooss
679accae37 Add missing explicit cast in libqpol/policy.c
libqpol/policy.c:650:36: warning: passing argument 2 of
    'qpol_type_get_isattr' from incompatible pointer type
       if (qpol_type_get_isattr(policy, attr, &isattr)) {
                                        ^
    libqpol/include/qpol/type_query.h:96:13: note: expected 'const
    struct qpol_type_t *' but argument is of type 'struct type_datum_t
    *'
      extern int qpol_type_get_isattr(const qpol_policy_t * policy, const qpol_type_t * datum, unsigned char *isattr);
                 ^
2014-11-02 13:02:57 -05:00
Nicolas Iooss
856fa108e0 Fix gcc -Wstrict-prototypes warnings
Python builds C extensions with -Wstrict-prototypes.  This triggers
warnings when defining functions wirth () for "any number of
parameters".

Remove these warnings by always specifying parameters.
2014-11-02 13:02:57 -05:00
Nicolas Iooss
1a02a86836 Include sys/stat.h in libqpol/policy.c for fstat
The declaration of fstat was missing.  "gcc -Wall" reported:

  libqpol/policy.c: In function 'qpol_policy_open_from_file_opt':
  libqpol/policy.c:1060:3: warning: implicit declaration of function
  'fstat' [-Wimplicit-function-declaration]
     if (fstat(fd, &sb) < 0) {
     ^
2014-11-02 13:02:11 -05:00
Nicolas Iooss
8e488c23f1 Use %s instead of %S to print strings in printf format
gcc reported the following warnings:

    libqpol/policy_extend.c: In function 'qpol_avrule_get_syn_avrule_iter':
    libqpol/policy_extend.c:1219:3: warning: format '%S' expects
    argument of type 'wchar_t *', but argument 4 has type 'char *'
    [-Wformat=]
       ERR(policy, "%S", strerror(error));
       ^
    libqpol/policy_extend.c: In function 'qpol_terule_get_syn_terule_iter':
    libqpol/policy_extend.c:1320:3: warning: format '%S' expects
    argument of type 'wchar_t *', but argument 4 has type 'char *'
    [-Wformat=]
       ERR(policy, "%S", strerror(error));
       ^
2014-11-02 13:02:11 -05:00
Nicolas Iooss
ee7064a711 Add printf format attribute to relevant functions in libqpol
"gcc -Wformat" needs printing functions to be marked with a format
attribute to be able to work.  Add this attribute to some functions in
libqpol, found with "gcc -Werror=missing-format-attribute"

gcc documentation about format attribute:
https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
2014-11-02 13:02:11 -05:00
Nicolas Iooss
0db48cbbc3 Use %lx instead of %x when printing unsigned long values 2014-11-02 13:02:10 -05:00
Nicolas Iooss
35722ab22d Improve libqpol yyerror/yywarn prototypes
* Add printf format specifier for yyerror2 to be able to use
  "gcc -Wformat-security"
* Constify message string to avoid gcc warnings about casting string
  literals to non-const char*.
2014-11-02 13:02:10 -05:00
Nicolas Iooss
7aace4d52a Remove unused variables in libqpol 2014-11-02 13:02:10 -05:00
Chris PeBenito
278ababe61 Whitespace fix in sesearch. 2014-11-02 12:33:28 -05:00
Chris PeBenito
9381ae10d7 Add missing property decorator to Genfscon filetype. 2014-11-02 12:33:11 -05:00
Chris PeBenito
cb209426d2 Fix inconsistent/incorrect qpol_iterator_policy() use in class_perm_query.c
The return needs to be checked before dereferencing.  Fixes #2.
2014-11-02 12:32:29 -05:00
Chris PeBenito
4e7aeed9ff Implement genfscon query. 2014-11-02 10:47:30 -05:00
Chris PeBenito
49fd39c9c2 Change wrapper to use decorators instead of overriding member functions.
This eliminates the need for referencing the C extension's generated
member function, making maintenance less error prone.
2014-11-02 00:57:03 -04:00
Chris PeBenito
76749e650c Add rule_type() member function for qpol_filename_trans_t wrapper.
Eliminates special case in TERule ruletype() member function.
2014-11-01 15:55:36 -04:00
Chris PeBenito
8d3b4d35a0 PEP8 fix in SELinuxPolicy. 2014-11-01 15:38:31 -04:00
Chris PeBenito
20c5998b54 Fix TERule __str__ handling for type_change and type_member rules. 2014-11-01 15:38:06 -04:00
Chris PeBenito
c48efb1c5f Create a generator function for qpol iterators.
Makes them an Iterable in Python.
2014-11-01 15:32:13 -04:00
Chris PeBenito
0420764749 Whitespace change in qpol.i. 2014-11-01 13:48:44 -04:00
Chris PeBenito
f8cce2898b Fix other missing parentheses in policy_define.c. 2014-10-31 20:38:28 -04:00
Chris PeBenito
6ff47214b1 Fix missing parentheses in policy_define.c. 2014-10-31 20:36:06 -04:00
Chris PeBenito
177c185a77 Correct SWIG wrapper to return IP address text representations for nodecons
Otherwise the Python would have to use unsafe cdata.i SWIG functions to
access the memory areas to do the same thing.

Also eliminate the QPOL_IPV4/QPOL_IPV6 from the protocol funtion, to
abstract away the binary policy representation details.
2014-10-30 15:44:37 -04:00
Chris PeBenito
d16207c114 Python 3: fix more dict .keys() usage.
Uncovered by 2to3.  Unit tests now pass in Python 3.
2014-10-30 10:02:04 -04:00
Chris PeBenito
51d8e3e421 Fix more missed qpol refactoring. 2014-10-30 10:00:47 -04:00
Chris PeBenito
be32a92f79 Python 3: fix manual generator consuming 2014-10-29 21:51:19 -04:00