* [POLICYREP] [PATCHv2 2/3] policy package implementation
2007-07-26 14:45 [POLICYREP] [PATCHv2 0/3] policy package implentation with xar method
2007-07-26 14:45 ` [POLICYREP] [PATCHv2 1/3] policy package class method
@ 2007-07-26 14:45 ` method
2007-07-26 14:45 ` [POLICYREP] [PATCHv2 3/3] semodule_package implementation in cpp for libpolicyrep method
2 siblings, 0 replies; 4+ messages in thread
From: method @ 2007-07-26 14:45 UTC (permalink / raw)
To: kmacmillan, selinux; +Cc: sds
This includes 2 classes, one for handling "files" --> "policy package" (PolicyPackageArchive) and one for handling "policy package" <--> "package class" (PolicyPackage). Currently PolicyPackage::write() doesn't work but it is all implemented so I just return; at the top of that function for now.
This policy package format uses xar and uses the file attribute "selinuxfiletype" to determine what kind of file each one in the archive is (eg., module, file_contexts, etc).
---
libpolicyrep/src/policy_package.cpp | 433 ++++++++++++++++++++++++++++++++++++
1 file changed, 433 insertions(+)
--- /dev/null
+++ policyrep-policy_package/libpolicyrep/src/policy_package.cpp
@@ -0,0 +1,433 @@
+/*
+ * Author : Joshua Brindle <jbrindle@tresys.com>
+ *
+ * Copyright (C) 2007 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
+ */
+
+extern "C" {
+#include <xar/xar.h>
+#include <string.h>
+}
+#define SELINUX_XAR_PROPERTY "selinuxfiletype"
+#include <policyrep/parse.hpp>
+#include <policyrep/policy_package.hpp>
+#include <sstream>
+#include <iostream>
+#include <stdexcept>
+namespace policyrep {
+
+ struct PolicyPackageImpl {
+ Module & policy_module;
+ char *file_contexts;
+ char *seusers;
+ char *user_extra;
+ char *netfilter_contexts;
+ };
+
+ void PolicyPackage::init() {
+ impl = new PolicyPackageImpl;
+ impl->file_contexts = NULL;
+ impl->seusers = NULL;
+ impl->user_extra = NULL;
+ impl->netfilter_contexts = NULL;
+ } PolicyPackage::PolicyPackage() {
+ init();
+ }
+
+ Module & PolicyPackage::get_policy_module()const {
+ return impl->policy_module;
+ } void PolicyPackage::set_policy_module(Module & module) {
+ impl->policy_module = module;
+ }
+
+ char *PolicyPackage::get_file_contexts() const {
+ return impl->file_contexts;
+ } void PolicyPackage::set_file_contexts(char *fc) {
+ impl->file_contexts = fc;
+ }
+
+ char *PolicyPackage::get_seusers() const {
+ return impl->seusers;
+ } void PolicyPackage::set_seusers(char *se) {
+ impl->seusers = se;
+ }
+
+ char *PolicyPackage::get_user_extra() const {
+ return impl->user_extra;
+ } void PolicyPackage::set_user_extra(char *ue) {
+ impl->user_extra = ue;
+ }
+
+ char *PolicyPackage::get_netfilter_contexts() const {
+ return impl->netfilter_contexts;
+ } void PolicyPackage::set_netfilter_contexts(char *nc) {
+ impl->netfilter_contexts = nc;
+ }
+
+ void PolicyPackage::read(char *filename) {
+ xar_t x;
+ xar_file_t f;
+ xar_iter_t i;
+
+ i = xar_iter_new();
+ if (i == NULL) {
+ throw std::bad_alloc();
+ }
+
+ x = xar_open(filename, READ);
+ if (x == NULL) {
+ throw std::
+ runtime_error("Unable to open policy package");
+ }
+
+ for (f = xar_file_first(x, i); f; f = xar_file_next(i)) {
+ size_t sz;
+ char *fbuf;
+ const char *filetype;
+ int32_t ret;
+
+ ret = xar_extract_tobuffersz(x, f, &fbuf, &sz);
+ if (ret) {
+ // This can happen if the file is 0 bytes
+ // or is a symlink, directory, etc. We might want
+ // to put code here to check those cases and bail
+ // but for now we just ignore them and continue.
+ continue;
+ }
+
+ ret = xar_prop_get(f, SELINUX_XAR_PROPERTY, &filetype);
+ if (ret) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error getting name property of file");
+ }
+ if (strcmp(filetype, "policy_module") == 0) {
+ Parser p;
+ // TODO add parser constructor that takes a char * and call here
+ continue;
+ } else if (strcmp(filetype, "file_contexts") == 0) {
+ if (impl->file_contexts) {
+ xar_close(x);
+ throw std::
+ range_error
+ ("Multiple file_contexts files in policy package");
+ }
+ impl->file_contexts = fbuf;
+ continue;
+ } else if (strcmp(filetype, "seusers") == 0) {
+ if (impl->seusers) {
+ xar_close(x);
+ throw std::
+ range_error
+ ("Multiple seusers files in policy package");
+ }
+ impl->seusers = fbuf;
+ continue;
+ } else if (strcmp(filetype, "user_extra") == 0) {
+ if (impl->user_extra) {
+ xar_close(x);
+ throw std::
+ range_error
+ ("Multiple user_extra files in policy package");
+ }
+ impl->user_extra = fbuf;
+ continue;
+ } else if (strcmp(filetype, "netfilter_contexts") == 0) {
+ if (impl->netfilter_contexts) {
+ xar_close(x);
+ throw std::
+ range_error
+ ("Multiple netfilter_contexts files in policy package");
+ }
+ impl->netfilter_contexts = fbuf;
+ continue;
+ } else {
+ // unrecognized file, just skip it
+ free(fbuf);
+ continue;
+ }
+
+ }
+
+ xar_close(x);
+ }
+
+ void PolicyPackage::write(char *filename) {
+
+ // just return -1 for now, this method exposes a xar bug and won't
+ // work until the bug is fixed.
+
+ return;
+
+ xar_t x;
+ xar_file_t f;
+
+ x = xar_open(filename, WRITE);
+ if (x == NULL) {
+ throw std::
+ runtime_error("Unable to open policy package");
+ }
+ // write policy module
+
+ if (impl->file_contexts) {
+ f = xar_add_frombuffer(x, NULL, "file_contexts",
+ impl->file_contexts,
+ strlen(impl->file_contexts));
+ if (!f) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error writing file_contexts to policy package");
+ }
+
+ if (xar_prop_set
+ (f, SELINUX_XAR_PROPERTY, "file_contexts")) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error setting file_contexts property in policy package");
+ }
+ }
+
+ if (impl->seusers) {
+ f = xar_add_frombuffer(x, NULL, "seusers",
+ impl->seusers,
+ strlen(impl->seusers));
+ if (!f) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error writing seusers to policy package");
+ }
+
+ if (xar_prop_set(f, SELINUX_XAR_PROPERTY, "seusers")) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error setting seusers property in policy package");
+ }
+ }
+
+ if (impl->user_extra) {
+ f = xar_add_frombuffer(x, NULL, "user_extra",
+ impl->user_extra,
+ strlen(impl->user_extra));
+ if (!f) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error writing user_extra to policy package");
+ }
+
+ if (xar_prop_set(f, SELINUX_XAR_PROPERTY, "user_extra")) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error setting user_extra property in policy package");
+ }
+ }
+
+ if (impl->netfilter_contexts) {
+ f = xar_add_frombuffer(x, NULL, "netfilter_contexts",
+ impl->netfilter_contexts,
+ strlen(impl->
+ netfilter_contexts));
+ if (!f) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error writing netfilter_contexts to policy package");
+ }
+
+ if (xar_prop_set
+ (f, SELINUX_XAR_PROPERTY, "netfilter_contexts")) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error setting netfilter_contexts property in policy package");
+ }
+ }
+
+ xar_close(x);
+ }
+
+ PolicyPackage::~PolicyPackage() {
+ delete impl;
+ }
+
+ //
+ // PolicyPackageArchive
+ // This class is used for creating a policy package file from individual files.
+ // Set the filenames for each kind of file (module, file_contexts, etc) then
+ // call create_archive.
+
+ struct PolicyPackageArchiveImpl {
+ char *mod_file;
+ char *fc_file;
+ char *seusers_file;
+ char *user_extra_file;
+ char *nc_file;
+ };
+
+ void PolicyPackageArchive::init() {
+ impl = new PolicyPackageArchiveImpl;
+ impl->mod_file = NULL;
+ impl->fc_file = NULL;
+ impl->seusers_file = NULL;
+ impl->user_extra_file = NULL;
+ impl->nc_file = NULL;
+ }
+
+ PolicyPackageArchive::PolicyPackageArchive() {
+ init();
+ }
+
+ void PolicyPackageArchive::set_mod_file(char *mod) {
+ impl->mod_file = mod;
+ }
+
+ char *PolicyPackageArchive::get_mod_file() const {
+ return impl->mod_file;
+ } void PolicyPackageArchive::set_fc_file(char *fc) {
+ impl->fc_file = fc;
+ }
+
+ char *PolicyPackageArchive::get_fc_file() const {
+ return impl->fc_file;
+ } void PolicyPackageArchive::set_seusers_file(char *su) {
+ impl->seusers_file = su;
+ }
+
+ char *PolicyPackageArchive::get_seusers_file() const {
+ return impl->seusers_file;
+ } void PolicyPackageArchive::set_user_extra_file(char *ue) {
+ impl->user_extra_file = ue;
+ }
+
+ char *PolicyPackageArchive::get_user_extra_file() const {
+ return impl->user_extra_file;
+ } void PolicyPackageArchive::set_nc_file(char *nc) {
+ impl->nc_file = nc;
+ }
+
+ char *PolicyPackageArchive::get_nc_file() const {
+ return impl->nc_file;
+ } void PolicyPackageArchive::create_archive(char *filename) {
+ xar_t x;
+ xar_file_t f;
+
+ x = xar_open(filename, WRITE);
+ if (x == NULL) {
+ throw std::
+ runtime_error("Unable to open policy package");
+ }
+
+ if (impl->mod_file) {
+ f = xar_add(x, impl->mod_file);
+ if (!f) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error writing module to policy package");
+ }
+ if (xar_prop_set(f, SELINUX_XAR_PROPERTY, "module")) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error setting module property in policy package");
+ }
+ }
+
+ if (impl->fc_file) {
+ f = xar_add(x, impl->fc_file);
+ if (!f) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error writing file_contexts to policy package");
+ }
+
+ if (xar_prop_set
+ (f, SELINUX_XAR_PROPERTY, "file_contexts")) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error setting file_contexts property in policy package");
+ }
+ }
+
+ if (impl->seusers_file) {
+ f = xar_add(x, impl->seusers_file);
+ if (!f) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error writing seusers to policy package");
+ }
+
+ if (xar_prop_set(f, SELINUX_XAR_PROPERTY, "seusers")) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error setting seusers property in policy package");
+ }
+ }
+
+ if (impl->user_extra_file) {
+ f = xar_add(x, impl->user_extra_file);
+ if (!f) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error writing user_extra to policy package");
+ }
+
+ if (xar_prop_set(f, SELINUX_XAR_PROPERTY, "user_extra")) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error setting user_extra property in policy package");
+ }
+ }
+
+ if (impl->nc_file) {
+ f = xar_add(x, impl->nc_file);
+ if (!f) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error writing netfilter_contexts to policy package");
+ }
+
+ if (xar_prop_set
+ (f, SELINUX_XAR_PROPERTY, "netfilter_contexts")) {
+ xar_close(x);
+ throw std::
+ runtime_error
+ ("Error setting netfilter_contexts property in policy package");
+ }
+ }
+
+ xar_close(x);
+ }
+
+ PolicyPackageArchive::~PolicyPackageArchive() {
+ delete impl;
+ }
+
+} // namespace policyrep
--
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.
^ permalink raw reply [flat|nested] 4+ messages in thread* [POLICYREP] [PATCHv2 3/3] semodule_package implementation in cpp for libpolicyrep
2007-07-26 14:45 [POLICYREP] [PATCHv2 0/3] policy package implentation with xar method
2007-07-26 14:45 ` [POLICYREP] [PATCHv2 1/3] policy package class method
2007-07-26 14:45 ` [POLICYREP] [PATCHv2 2/3] policy package implementation method
@ 2007-07-26 14:45 ` method
2 siblings, 0 replies; 4+ messages in thread
From: method @ 2007-07-26 14:45 UTC (permalink / raw)
To: kmacmillan, selinux; +Cc: sds
---
policycoreutils/semodule_package/semodule_package.c | 257 ------------------
policycoreutils/semodule_package/semodule_package.cpp | 60 ++--
2 files changed, 35 insertions(+), 282 deletions(-)
--- policyrep-policy_package.orig/policycoreutils/semodule_package/semodule_package.c
+++ /dev/null
@@ -1,257 +0,0 @@
-/* Authors: Karl MacMillan <kmacmillan@tresys.com>
- *
- * Copyright (C) 2004 Tresys Technology, LLC
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
- */
-
-#include <sepol/module.h>
-#include <getopt.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <errno.h>
-
-char *progname = NULL;
-extern char *optarg;
-
-static void usage(char *prog)
-{
- printf("usage: %s -o <output file> -m <module> [-f <file contexts>]\n",
- prog);
- printf("Options:\n");
- printf(" -o --outfile Output file (required)\n");
- printf(" -m --module Module file (required)\n");
- printf(" -f --fc File contexts file\n");
- printf(" -s --seuser Seusers file (only valid in base)\n");
- printf
- (" -u --user_extra user_extra file (only valid in base)\n");
- printf(" -n --nc Netfilter contexts file\n");
- exit(1);
-}
-
-static int file_to_policy_file(char *filename, struct sepol_policy_file **pf,
- char *mode)
-{
- FILE *f;
-
- if (sepol_policy_file_create(pf)) {
- fprintf(stderr, "%s: Out of memory\n", progname);
- return -1;
- }
-
- f = fopen(filename, mode);
- if (!f) {
- fprintf(stderr, "%s: Could not open file %s: %s\n", progname,
- strerror(errno), filename);
- return -1;
- }
- sepol_policy_file_set_fp(*pf, f);
- return 0;
-}
-
-static int file_to_data(const char *path, char **data, size_t * len)
-{
- int fd;
- struct stat sb;
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "%s: Failed to open %s: %s\n", progname, path,
- strerror(errno));
- return -1;
- }
- if (fstat(fd, &sb) < 0) {
- fprintf(stderr, "%s: Failed to fstat %s: %s\n", progname,
- path, strerror(errno));
- goto err;
- }
-
- *data = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- if (*data == MAP_FAILED) {
- fprintf(stderr, "%s: Failed to mmap %s: %s\n", progname, path,
- strerror(errno));
- goto err;
- }
- *len = sb.st_size;
- close(fd);
- return 0;
- err:
- close(fd);
- return -1;
-}
-
-int main(int argc, char **argv)
-{
- struct sepol_module_package *pkg;
- struct sepol_policy_file *mod, *out;
- char *module = NULL, *file_contexts = NULL, *seusers =
- NULL, *user_extra = NULL;
- char *fcdata = NULL, *outfile = NULL, *seusersdata =
- NULL, *user_extradata = NULL;
- char *netfilter_contexts = NULL, *ncdata = NULL;
- size_t fclen = 0, seuserslen = 0, user_extralen = 0, nclen = 0;
- int i;
-
- static struct option opts[] = {
- {"module", required_argument, NULL, 'm'},
- {"fc", required_argument, NULL, 'f'},
- {"seuser", required_argument, NULL, 's'},
- {"user_extra", required_argument, NULL, 'u'},
- {"nc", required_argument, NULL, 'n'},
- {"outfile", required_argument, NULL, 'o'},
- {"help", 0, NULL, 'h'},
- {NULL, 0, NULL, 0}
- };
-
- while ((i = getopt_long(argc, argv, "m:f:s:u:o:n:h", opts, NULL)) != -1) {
- switch (i) {
- case 'h':
- usage(argv[0]);
- exit(0);
- case 'm':
- if (module) {
- fprintf(stderr,
- "May not specify more than one module\n");
- exit(1);
- }
- module = strdup(optarg);
- if (!module)
- exit(1);
- break;
- case 'f':
- if (file_contexts) {
- fprintf(stderr,
- "May not specify more than one file context file\n");
- exit(1);
- }
- file_contexts = strdup(optarg);
- if (!file_contexts)
- exit(1);
- break;
- case 'o':
- if (outfile) {
- fprintf(stderr,
- "May not specify more than one output file\n");
- exit(1);
- }
- outfile = strdup(optarg);
- if (!outfile)
- exit(1);
- break;
- case 's':
- if (seusers) {
- fprintf(stderr,
- "May not specify more than one seuser file\n");
- exit(1);
- }
- seusers = strdup(optarg);
- if (!seusers)
- exit(1);
- break;
- case 'u':
- if (user_extra) {
- fprintf(stderr,
- "May not specify more than one user_extra file\n");
- exit(1);
- }
- user_extra = strdup(optarg);
- if (!user_extra)
- exit(1);
- break;
- case 'n':
- if (netfilter_contexts) {
- fprintf(stderr,
- "May not specify more than one netfilter contexts file\n");
- exit(1);
- }
- netfilter_contexts = strdup(optarg);
- if (!netfilter_contexts)
- exit(1);
- break;
- }
- }
-
- progname = argv[0];
-
- if (!module || !outfile) {
- usage(argv[0]);
- exit(0);
- }
-
- if (file_contexts) {
- if (file_to_data(file_contexts, &fcdata, &fclen))
- exit(1);
- }
-
- if (seusers) {
- if (file_to_data(seusers, &seusersdata, &seuserslen))
- exit(1);
- }
-
- if (user_extra) {
- if (file_to_data(user_extra, &user_extradata, &user_extralen))
- exit(1);
- }
-
- if (netfilter_contexts) {
- if (file_to_data(netfilter_contexts, &ncdata, &nclen))
- exit(1);
- }
-
- if (file_to_policy_file(module, &mod, "r"))
- exit(1);
-
- if (sepol_module_package_create(&pkg)) {
- fprintf(stderr, "%s: Out of memory\n", argv[0]);
- exit(1);
- }
-
- if (sepol_policydb_read(sepol_module_package_get_policy(pkg), mod)) {
- fprintf(stderr,
- "%s: Error while reading policy module from %s\n",
- argv[0], module);
- exit(1);
- }
-
- if (fclen)
- sepol_module_package_set_file_contexts(pkg, fcdata, fclen);
-
- if (seuserslen)
- sepol_module_package_set_seusers(pkg, seusersdata, seuserslen);
-
- if (user_extra)
- sepol_module_package_set_user_extra(pkg, user_extradata,
- user_extralen);
-
- if (nclen)
- sepol_module_package_set_netfilter_contexts(pkg, ncdata, nclen);
-
- if (file_to_policy_file(outfile, &out, "w"))
- exit(1);
-
- if (sepol_module_package_write(pkg, out)) {
- fprintf(stderr,
- "%s: Error while writing module package to %s\n",
- argv[0], argv[1]);
- exit(1);
- }
-
- if (fclen)
- munmap(fcdata, fclen);
- if (nclen)
- munmap(ncdata, nclen);
- sepol_policy_file_free(mod);
- sepol_policy_file_free(out);
- sepol_module_package_free(pkg);
- free(file_contexts);
- free(outfile);
- free(module);
- exit(0);
-}
--- policyrep-policy_package.orig/policycoreutils/semodule_package/semodule_package.cpp
+++ policyrep-policy_package/policycoreutils/semodule_package/semodule_package.cpp
@@ -10,11 +10,9 @@
extern "C" {
#include <getopt.h>
}
-
#include <policyrep/policy_package.hpp>
#include <iostream>
#include <sstream>
-
char *progname = NULL;
extern char *optarg;
@@ -22,7 +20,8 @@ using namespace std;
static void usage(char *prog)
{
- cout << "usage: " << prog << " -o <output file> -m <module> [-f <file contexts>]" << endl;
+ cout << "usage: " << prog <<
+ " -o <output file> -m <module> [-f <file contexts>]" << endl;
cout << "Options:" << endl;
cout << " -o --outfile Output file (required)" << endl;
cout << " -m --module Module file" << endl;
@@ -33,14 +32,12 @@ static void usage(char *prog)
exit(1);
}
-
int main(int argc, char **argv)
{
policyrep::PolicyPackageArchive package;
- char *module = NULL, *file_contexts = NULL,
- *seusers = NULL, *user_extra = NULL,
- *netfilter_contexts = NULL, *outfile = NULL,
- *unpack = NULL;
+ char *module = NULL, *file_contexts = NULL,
+ *seusers = NULL, *user_extra = NULL,
+ *netfilter_contexts = NULL, *outfile = NULL, *unpack = NULL;
int i;
static struct option opts[] = {
@@ -61,7 +58,8 @@ int main(int argc, char **argv)
exit(0);
case 'm':
if (module) {
- cout << "May not specify more than one module" << endl;
+ cout << "May not specify more than one module"
+ << endl;
exit(1);
}
module = strdup(optarg);
@@ -70,7 +68,9 @@ int main(int argc, char **argv)
break;
case 'f':
if (file_contexts) {
- cout << "May not specify more than one file context file" << endl;
+ cout <<
+ "May not specify more than one file context file"
+ << endl;
exit(1);
}
file_contexts = strdup(optarg);
@@ -79,7 +79,9 @@ int main(int argc, char **argv)
break;
case 'o':
if (outfile) {
- cout << "May not specify more than one output file" << endl;
+ cout <<
+ "May not specify more than one output file"
+ << endl;
exit(1);
}
outfile = strdup(optarg);
@@ -88,7 +90,9 @@ int main(int argc, char **argv)
break;
case 's':
if (seusers) {
- cout << "May not specify more than one seuser file" << endl;
+ cout <<
+ "May not specify more than one seuser file"
+ << endl;
exit(1);
}
seusers = strdup(optarg);
@@ -97,7 +101,9 @@ int main(int argc, char **argv)
break;
case 'u':
if (user_extra) {
- cout << "May not specify more than one user_extra file" << endl;
+ cout <<
+ "May not specify more than one user_extra file"
+ << endl;
exit(1);
}
user_extra = strdup(optarg);
@@ -106,17 +112,19 @@ int main(int argc, char **argv)
break;
case 'n':
if (netfilter_contexts) {
- cout << "May not specify more than one netfilter contexts file" << endl;
+ cout <<
+ "May not specify more than one netfilter contexts file"
+ << endl;
exit(1);
}
netfilter_contexts = strdup(optarg);
if (!netfilter_contexts)
exit(1);
break;
- }
case '?':
- usage();
+ usage(argv[0]);
exit(1);
+ }
}
progname = argv[0];
@@ -128,25 +136,27 @@ int main(int argc, char **argv)
if (module)
package.set_mod_file(module);
-
- if (file_contexts)
+
+ if (file_contexts)
package.set_fc_file(file_contexts);
- if (seusers)
+ if (seusers)
package.set_seusers_file(seusers);
- if (user_extra)
+ if (user_extra)
package.set_user_extra_file(user_extra);
- if (netfilter_contexts)
+ if (netfilter_contexts)
package.set_nc_file(netfilter_contexts);
try {
package.create_archive(outfile);
- } catch (exception *e) {
- cerr << "Exception thrown" << e.what() << endl;
- } catch (const bad_alloc& x) {
- cerr << "Out of memory" << x.what() << endl;
+ }
+ catch(const bad_alloc & x) {
+ cerr << "Out of memory " << x.what() << endl;
+ } catch(exception & e) {
+ cerr << "Exception thrown: " << e.what() << endl;
+ }
free(module);
free(file_contexts);
--
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.
^ permalink raw reply [flat|nested] 4+ messages in thread