Commit Graph

11 Commits

Author SHA1 Message Date
Richard Haines
dd29dc9c43 setools-V4: libqpol policy V30 updates (xen/xperm statements)
Updated libqpol services to use the latest checkpolicy 2.4 source
files to support Xen and extended permissions (allowxperm etc.).

TODO: Add support for querying the xperm values.

Signed-off-by: Richard Haines <richard_c_haines@btinternet.com>
2016-03-21 10:56:37 -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
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
926da1f675 Change libqpol message output.
Changing ERR/WARN/INFO did not catch error output from libsepol.
2015-02-21 17:50:19 -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
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
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
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
7aace4d52a Remove unused variables in libqpol 2014-11-02 13:02:10 -05: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