From a7fe3639ecc2c10329575daf71cd4632a01476fa Mon Sep 17 00:00:00 2001 From: Chris PeBenito Date: Fri, 22 Apr 2016 13:48:39 -0400 Subject: [PATCH] Remove bzip2 dependency. This was needed for bzipped .pp files, but loading modules is no longer supported. --- README.md | 1 - libqpol/config.h | 3 -- libqpol/module.c | 32 ++++----------- libqpol/util.c | 101 ----------------------------------------------- setup.py | 2 - 5 files changed, 7 insertions(+), 132 deletions(-) delete mode 100644 libqpol/util.c diff --git a/README.md b/README.md index 65a142d..dc1b929 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ To run SETools command line tools, the following packages are required: * NetworkX 1.8+ * setuptools * libselinux Python bindings (optional but recommended) -* libbz2 To run SETools graphical tools, the following packages are also required: * PyQt5 diff --git a/libqpol/config.h b/libqpol/config.h index 71104ef..ec6573d 100644 --- a/libqpol/config.h +++ b/libqpol/config.h @@ -13,9 +13,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 -/* Define to 1 if you have the `bz2' library (-lbz2). */ -#define HAVE_LIBBZ2 1 - /* Define to 1 if you have the `sepol' library (-lsepol). */ #define HAVE_LIBSEPOL 1 diff --git a/libqpol/module.c b/libqpol/module.c index 35136d1..2bf8cb0 100644 --- a/libqpol/module.c +++ b/libqpol/module.c @@ -45,7 +45,6 @@ int qpol_module_create_from_file(const char *path, qpol_module_t ** module) int error = 0; char *tmp = NULL; char *data = NULL; - ssize_t size; if (module) *module = NULL; @@ -74,22 +73,12 @@ int qpol_module_create_from_file(const char *path, qpol_module_t ** module) error = errno; goto err; } - size = qpol_bunzip(infile, &data); - - if (size > 0) { - if (!qpol_is_data_mod_pkg(data)) { - error = ENOTSUP; - goto err; - } - sepol_policy_file_set_mem(spf, data, size); - } else { - if (!qpol_is_file_mod_pkg(infile)) { - error = ENOTSUP; - goto err; - } - rewind(infile); - sepol_policy_file_set_fp(spf, infile); - } + if (!qpol_is_file_mod_pkg(infile)) { + error = ENOTSUP; + goto err; + } + rewind(infile); + sepol_policy_file_set_fp(spf, infile); if (sepol_module_package_create(&smp)) { error = EIO; @@ -102,14 +91,7 @@ int qpol_module_create_from_file(const char *path, qpol_module_t ** module) } free(tmp); tmp = NULL; - if (size > 0) { - // Re setting the memory location has the effect of rewind - // API is not accessible from here to explicitly "rewind" the - // in-memory file. - sepol_policy_file_set_mem(spf, data, size); - } else { - rewind(infile); - } + rewind(infile); if (sepol_module_package_read(smp, spf, 0)) { error = EIO; diff --git a/libqpol/util.c b/libqpol/util.c deleted file mode 100644 index 77912fa..0000000 --- a/libqpol/util.c +++ /dev/null @@ -1,101 +0,0 @@ -/** - * @file - * - * Implementation of utility functions. - * - * @author Jeremy A. Mowery jmowery@tresys.com - * @author Jason Tang jtang@tresys.com - * - * Copyright (C) 2006-2008 Tresys Technology, LLC - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include "qpol_internal.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -const char *libqpol_get_version(void) -{ - return LIBQPOL_VERSION_STRING; -} - -#include -#include -#include - -#define BZ2_MAGICSTR "BZh" -#define BZ2_MAGICLEN (sizeof(BZ2_MAGICSTR)-1) - -/* qpol_bunzip() uncompresses a file to '*data', returning the total number of - * uncompressed bytes in the file. - * Returns -1 if file could not be decompressed. - * Originally from libsemanage/src/direct_api.c, with slight mods */ -ssize_t qpol_bunzip(FILE *f, char **data) -{ - BZFILE* b; - size_t nBuf; - char buf[1<<18]; - size_t size = sizeof(buf); - int bzerror; - size_t total=0; - int small=0; // Set to 1 to use less memory decompressing (about 2x slower) - - bzerror = fread(buf, 1, BZ2_MAGICLEN, f); - rewind(f); - if ((bzerror != BZ2_MAGICLEN) || memcmp(buf, BZ2_MAGICSTR, BZ2_MAGICLEN)) - return -1; - - b = BZ2_bzReadOpen ( &bzerror, f, 0, small, NULL, 0 ); - if ( bzerror != BZ_OK ) { - BZ2_bzReadClose ( &bzerror, b ); - return -1; - } - - char *uncompress = realloc(NULL, size); - - while ( bzerror == BZ_OK) { - nBuf = BZ2_bzRead ( &bzerror, b, buf, sizeof(buf)); - if (( bzerror == BZ_OK ) || ( bzerror == BZ_STREAM_END )) { - if (total + nBuf > size) { - size *= 2; - uncompress = realloc(uncompress, size); - } - memcpy(&uncompress[total], buf, nBuf); - total += nBuf; - } - } - if ( bzerror != BZ_STREAM_END ) { - BZ2_bzReadClose ( &bzerror, b ); - free(uncompress); - return -1; - } - BZ2_bzReadClose ( &bzerror, b ); - - *data = uncompress; - return total; -} - diff --git a/setup.py b/setup.py index d0f268c..675ff73 100644 --- a/setup.py +++ b/setup.py @@ -127,12 +127,10 @@ ext_py_mods = [Extension('setools.policyrep._qpol', 'libqpol/terule_query.c', 'libqpol/type_query.c', 'libqpol/user_query.c', - 'libqpol/util.c', 'libqpol/policy_parse.c', 'libqpol/policy_scan.c', 'libqpol/xen_query.c'], include_dirs=['libqpol', 'libqpol/include', 'include'], - libraries=['bz2'], extra_compile_args=['-Werror', '-Wextra', '-Waggregate-return', '-Wcast-align',