Commit Graph

45 Commits

Author SHA1 Message Date
Chris PeBenito
1406eb30c3 Implement InitialSIDTest. 2015-04-24 08:56:56 -04:00
Chris PeBenito
6de35b81f7 Implement CommonTest and ObjClassTest.
Also fix bugs uncovered by testing.
2015-04-23 11:04:37 -04:00
Chris PeBenito
4e0b7d853b Thoroughly test MLS representations.
Implement category and level decl. lookups along the way.
2015-04-09 14:27:51 -04:00
Chris PeBenito
11fdaa7ad6 Route libqpol meessages through Python logging.
Does not include errors from the lex/yacc.
2015-03-21 16:23:59 -04:00
Chris PeBenito
757a16750b Fix qpol_context_get_range() not to segfault on MLS-disabled policy.
Correspondingly fix MLS object factories to immediately check if MLS is
disabled and short circuit if so.
2015-03-15 12:37:24 -04:00
Chris PeBenito
0b295755de Distinguish policy syntax errors from other OS errors, eg ENOENT.
The policy parser does not set errno, so the libqpol code assumes the
errors from parser code are always invalid syntax, rather than something
else like out of memory.  This may not always be the case, but any other
kind of error is unlikely (and likely catastrophic)
2015-03-06 10:44:32 -05:00
Chris PeBenito
a44a82a8a1 Fix compile error. 2015-02-22 09:43:15 -05:00
Chris PeBenito
a8d7f740b2 Change range constructor to use regular levels instead of semantic ones.
This affords better error reporting since levels can be invalid for
several reasons.

* Fix memory leak in qpol_semantic_level
* Add unit tests
2015-02-22 09:24:39 -05:00
Chris PeBenito
926da1f675 Change libqpol message output.
Changing ERR/WARN/INFO did not catch error output from libsepol.
2015-02-21 17:50:19 -05:00
Chris PeBenito
4953ebdcc4 Implement MLS range lookup. 2015-02-21 16:43:32 -05:00
Chris PeBenito
2dd517b4b3 Implement MLS level lookup. 2015-02-21 15:09:52 -05:00
Chris PeBenito
b67bd76e0c Move libqpol parser further in line with checkpolicy.
* Especially remove buggy conditional branch verification -- keep the same
  behavior as checkpolicy.
* No-rules-loading logic no longer needed
2015-02-10 11:43:31 -05:00
Chris PeBenito
0192ff6ddd Restore abort() use.
Otherwise -NDEBUG builds get compile errors.
2015-02-05 13:28:08 -05:00
Chris PeBenito
79320ba0cc Update parsers to checkpolicy 2.4.
Start dropping ancient psid support and other unused #ifdefs.
2015-02-05 13:05:55 -05:00
Chris PeBenito
3937946900 Update to libsepol 2.4 parser.
There was a struct change internally. Now setools4 requires libsepol 2.4.
2015-02-04 14:34:47 -05:00
Fernand Lone-Sang
bc081bbccd Fixed -Werror=unused-but-set-variable in libqpol/policy_extend.c 2015-01-23 15:23:38 +01:00
Fernand Lone-Sang
6a8dbe88a5 Fixed -Werror=unused-variable in libqpol/policy_extend.c 2015-01-23 15:23:32 +01:00
Fernand Lone-Sang
43ab9251fd Fixed -Werror=unused-but-set-variable in libqpol/default_object_query.c 2015-01-23 15:23:32 +01:00
Chris PeBenito
0c0534e824 Change libqpol to return qpol_class_t instead of string for default objects 2014-12-16 12:21:33 -05:00
Chris PeBenito
e53be65ebe Silence error message output generated by libqpol. 2014-11-09 10:20:33 -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
d0d78cebda One pair of additional signedness fixes from -Wsign-compare. 2014-11-02 13:21:38 -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
cb209426d2 Fix inconsistent/incorrect qpol_iterator_policy() use in class_perm_query.c
The return needs to be checked before dereferencing.  Fixes .
2014-11-02 12:32:29 -05: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
8a37ea0ed9 Remove generated files (lex/yacc)
Add setuptools/distutils commands to run bison and flex when building.
2014-10-29 12:03:44 -04:00
Chris PeBenito
8363f8edf7 Import libqpol from setools3.
Break setools3 dependence. Also fix SWIG wrapper to work with SWIG 2.x.
2014-10-24 21:00:24 -04:00