Changeset 4927

Show
Ignore:
Timestamp:
04/22/10 13:57:08 (3 years ago)
Author:
joliver
Message:

Final changes to module loading, including addition of bzip expansion
to module .pp files

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/module-loading/apol/apol_tcl.i

    r4890 r4927  
    111111                apol_policy_t *p = apol_policy_create_from_policy_path(ppath, QPOL_POLICY_OPTION_NO_NEVERALLOWS, 
    112112                                                                       apol_tcl_route_apol_to_string, interp); 
    113                 if (p == NULL) { 
    114                         if (errno != 0) { 
    115                 SWIG_exception(SWIG_RuntimeError, strerror(errno)); 
    116             } else { 
    117                             SWIG_exception(SWIG_RuntimeError, "The selected file does not appear to be a valid SELinux Policy."); 
    118            
     113                if (p == NULL && message == NULL) {  // Assume lower level has generated error message 
     114                        if (errno != 0) {   // otherwise take a guess at it 
     115                               SWIG_exception(SWIG_RuntimeError, strerror(errno)); 
     116                       } else { 
     117                               SWIG_exception(SWIG_RuntimeError, "The selected file does not appear to be a valid SELinux Policy."); 
     118                       
    119119                } 
    120120        fail: 
     
    448448extern char *apol_tcl_get_info_string(void); 
    449449extern void apol_tcl_set_info_string(apol_policy_t *p, const char *s); 
     450 
     451// vim:ft=c noexpandtab 
  • branches/module-loading/apol/open_policy_dialog.tcl

    r4924 r4927  
    378378 
    379379# Retrieve information about a policy module file, either source or 
    380 # binary, from disk.  This will be a 2-ple of module name and version
     380# binary, from disk.  This will be a 3-ple of module name, version and type
    381381# The policy module will be closed afterwards. 
    382382proc Apol_Open_Policy_Dialog::getModuleInfo {f} { 
  • branches/module-loading/configure.ac

    r4924 r4927  
    718718AC_SUBST([CUNIT_LIB_FLAG]) 
    719719 
     720AC_CHECK_LIB(bz2, 
     721        BZ2_bzReadOpen, , 
     722        AC_MSG_ERROR([could not find libbz2 - make sure bzip2-libs is installed]), 
     723        -lbz2 
     724) 
     725 
    720726#AC_MSG_CHECKING([for FUSE]) 
    721727#pkg-config --exists fuse 
  • branches/module-loading/libapol/src/policy.c

    r4585 r4927  
    106106        if (apol_policy_path_get_type(path) == APOL_POLICY_PATH_TYPE_MODULAR) { 
    107107                if (!qpol_policy_has_capability(policy->p, QPOL_CAP_MODULES)) { 
    108                         ERR(policy, "%s is not a base policy.", primary_path); 
    109                         apol_policy_destroy(&policy); 
    110                         return NULL; 
     108                        INFO(policy, "%s is not a base policy.", primary_path); 
     109                        return policy; 
    111110                } 
    112111                const apol_vector_t *modules = apol_policy_path_get_modules(path); 
  • branches/module-loading/libapol/swig/apol.i

    r4908 r4927  
    32183218        }; 
    32193219%} 
     3220// vim:ft=c 
  • branches/module-loading/libqpol/include/qpol/util.h

    r4157 r4927  
    5151        extern int qpol_default_policy_find(char **path); 
    5252 
     53/* bunzip() a file to '*data', returning the total number of uncompressed bytes 
     54 * in the file.  Returns -1 if file could not be decompressed. */ 
     55        extern ssize_t qpol_bunzip(FILE *f, char **data); 
     56 
    5357#ifdef  __cplusplus 
    5458} 
  • branches/module-loading/libqpol/src/Makefile.am

    r4867 r4927  
    6868 
    6969$(qpolso_DATA): $(tmp_sepol) $(libqpol_so_OBJS) libqpol.map 
    70         $(CC) -shared -o $@ $(libqpol_so_OBJS) $(AM_LDFLAGS) $(LDFLAGS) -Wl,-soname,$(LIBQPOL_SONAME),--version-script=$(srcdir)/libqpol.map,-z,defs -Wl,--whole-archive $(sepol_srcdir)/libsepol.a -Wl,--no-whole-archive @SELINUX_LIB_FLAG@ -lselinux -lsepol 
     70        $(CC) -shared -o $@ $(libqpol_so_OBJS) $(AM_LDFLAGS) $(LDFLAGS) -Wl,-soname,$(LIBQPOL_SONAME),--version-script=$(srcdir)/libqpol.map,-z,defs -Wl,--whole-archive $(sepol_srcdir)/libsepol.a -Wl,--no-whole-archive @SELINUX_LIB_FLAG@ -lselinux -lsepol -lbz2 
    7171        $(LN_S) -f $@ @libqpol_soname@ 
    7272        $(LN_S) -f $@ libqpol.so 
  • branches/module-loading/libqpol/src/module.c

    r4585 r4927  
    4444        int error = 0; 
    4545        char *tmp = NULL; 
     46        char *data = NULL; 
     47        ssize_t size; 
    4648 
    4749        if (module) 
     
    7274                goto err; 
    7375        } 
    74         if (!qpol_is_file_mod_pkg(infile)) { 
    75                 error = ENOTSUP; 
    76                 goto err; 
    77         } 
    78         sepol_policy_file_set_fp(spf, infile); 
     76        size = qpol_bunzip(infile, &data); 
     77 
     78        if (size > 0) { 
     79                if (!qpol_is_data_mod_pkg(data)) { 
     80                        error = ENOTSUP; 
     81                        goto err; 
     82                } 
     83                sepol_policy_file_set_mem(spf, data, size); 
     84        } else { 
     85                if (!qpol_is_file_mod_pkg(infile)) { 
     86                        error = ENOTSUP; 
     87                        goto err; 
     88                } 
     89                rewind(infile); 
     90                sepol_policy_file_set_fp(spf, infile); 
     91        } 
    7992 
    8093        if (sepol_module_package_create(&smp)) { 
     
    89102        free(tmp); 
    90103        tmp = NULL; 
    91         rewind(infile); 
     104        if (size > 0) { 
     105                // Re setting the memory location has the effect of rewind 
     106                // API is not accessible from here to explicitly "rewind" the 
     107                // in-memory file. 
     108                sepol_policy_file_set_mem(spf, data, size); 
     109        } else { 
     110                rewind(infile); 
     111        } 
     112 
    92113        if (sepol_module_package_read(smp, spf, 0)) { 
    93114                error = EIO; 
     
    107128        sepol_module_package_free(smp); 
    108129        fclose(infile); 
     130        if (data != NULL) 
     131                free (data); 
    109132        sepol_policy_file_free(spf); 
    110133 
     
    117140        if (infile) 
    118141                fclose(infile); 
    119         free(tmp); 
     142        if (data != NULL) 
     143                free (data); 
     144        if (tmp != NULL) 
     145                free(tmp); 
    120146        errno = error; 
    121147        return STATUS_ERR; 
  • branches/module-loading/libqpol/src/policy.c

    r4890 r4927  
    338338} 
    339339 
     340int qpol_is_data_mod_pkg(char * data) 
     341{ 
     342        size_t sz; 
     343        __u32 ubuf; 
     344 
     345        memcpy(&ubuf, data, sizeof(__u32)); 
     346 
     347        ubuf = le32_to_cpu(ubuf); 
     348        if (ubuf == SEPOL_MODULE_PACKAGE_MAGIC) 
     349                return 1; 
     350 
     351        return 0; 
     352} 
     353 
    340354int qpol_is_file_mod_pkg(FILE * fp) 
    341355{ 
     
    921935        } 
    922936 
     937    errno = 0; 
    923938        if (!(*policy = calloc(1, sizeof(qpol_policy_t)))) { 
    924939                error = errno; 
     
    966981        sepol_policy_file_set_handle(pfile, (*policy)->sh); 
    967982 
     983    errno=0; 
    968984        if (qpol_is_file_binpol(infile)) { 
    969985                (*policy)->type = retv = QPOL_POLICY_KERNEL_BINARY; 
     
    980996                        goto err; 
    981997                } 
    982         } else if (qpol_is_file_mod_pkg(infile)) { 
     998        } else if (qpol_module_create_from_file(path, &mod) == STATUS_SUCCESS) { 
    983999                (*policy)->type = retv = QPOL_POLICY_MODULE_BINARY; 
    984                 if (qpol_module_create_from_file(path, &mod)) { 
    985                         error = errno; 
    986                         ERR(*policy, "%s", strerror(error)); 
    987                         goto err; 
    988                 } 
     1000 
    9891001                if (qpol_policy_append_module(*policy, mod)) { 
    9901002                        error = errno; 
  • branches/module-loading/libqpol/src/policy_parse.y

    r4908 r4927  
    216216                        | sensitivities sensitivity_def 
    217217                        ; 
     218/* Need to call define_mls here, as we are working with files */ 
     219/* only, not command line options */ 
    218220sensitivity_def         : SENSITIVITY identifier alias_def ';' 
    219                         {if (define_sens()) return -1;} 
     221                        {if (define_mls() | define_sens()) return -1;} 
    220222                        | SENSITIVITY identifier ';' 
    221                         {if (define_sens()) return -1;} 
     223                        {if (define_mls() | define_sens()) return -1;} 
    222224                        ; 
    223225alias_def               : ALIAS names 
  • branches/module-loading/libqpol/src/util.c

    r4778 r4927  
    172172        return search_policy_binary_file(path); 
    173173} 
     174 
     175#include <stdlib.h> 
     176#include <bzlib.h> 
     177#include <string.h> 
     178#include <sys/sendfile.h> 
     179 
     180#define BZ2_MAGICSTR "BZh" 
     181#define BZ2_MAGICLEN (sizeof(BZ2_MAGICSTR)-1) 
     182 
     183/* qpol_bunzip() uncompresses a file to '*data', returning the total number of 
     184 * uncompressed bytes in the file. 
     185 * Returns -1 if file could not be decompressed. 
     186 * Originally from libsemanage/src/direct_api.c, with slight mods */ 
     187ssize_t qpol_bunzip(FILE *f, char **data) 
     188{ 
     189        BZFILE* b; 
     190        size_t  nBuf; 
     191        char    buf[1<<18]; 
     192        size_t  size = sizeof(buf); 
     193        int     bzerror; 
     194        size_t  total=0; 
     195        int             small=0;        // Set to 1 to use less memory decompressing (about 2x slower) 
     196 
     197        bzerror = fread(buf, 1, BZ2_MAGICLEN, f); 
     198        rewind(f); 
     199        if ((bzerror != BZ2_MAGICLEN) || memcmp(buf, BZ2_MAGICSTR, BZ2_MAGICLEN)) 
     200                return -1; 
     201         
     202        b = BZ2_bzReadOpen ( &bzerror, f, 0, small, NULL, 0 ); 
     203        if ( bzerror != BZ_OK ) { 
     204                BZ2_bzReadClose ( &bzerror, b ); 
     205                return -1; 
     206        } 
     207         
     208        char *uncompress = realloc(NULL, size); 
     209         
     210        while ( bzerror == BZ_OK) { 
     211                nBuf = BZ2_bzRead ( &bzerror, b, buf, sizeof(buf)); 
     212                if (( bzerror == BZ_OK ) || ( bzerror == BZ_STREAM_END )) { 
     213                        if (total + nBuf > size) { 
     214                                size *= 2; 
     215                                uncompress = realloc(uncompress, size); 
     216                        } 
     217                        memcpy(&uncompress[total], buf, nBuf); 
     218                        total += nBuf; 
     219                } 
     220        } 
     221        if ( bzerror != BZ_STREAM_END ) { 
     222                BZ2_bzReadClose ( &bzerror, b ); 
     223                free(uncompress); 
     224                return -1; 
     225        } 
     226        BZ2_bzReadClose ( &bzerror, b ); 
     227 
     228        *data = uncompress; 
     229        return  total; 
     230} 
     231 
  • branches/module-loading/libqpol/swig/qpol.i

    r4806 r4927  
    232232                qpol_module_t *m; 
    233233                BEGIN_EXCEPTION 
     234                errno=0; 
    234235                if (qpol_module_create_from_file(path, &m)) { 
    235236                        SWIG_exception(SWIG_IOError, "Error opening module"); 
     
    28772878        }; 
    28782879%} 
     2880// vim:ft=c noexpandtab