psss / rpms / libsemanage

Forked from rpms/libsemanage 5 years ago
Clone
b840c70
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/direct_api.c libsemanage-2.0.27/src/direct_api.c
b840c70
--- nsalibsemanage/src/direct_api.c	2008-06-12 23:25:16.000000000 -0400
b138896
+++ libsemanage-2.0.27/src/direct_api.c	2008-08-26 10:25:38.000000000 -0400
b840c70
@@ -489,12 +489,6 @@
b840c70
 	modified |= ifaces->dtable->is_modified(ifaces->dbase);
b840c70
 	modified |= nodes->dtable->is_modified(nodes->dbase);
b840c70
 
b840c70
-	/* FIXME: get rid of these, once we support loading the existing policy,
b840c70
-	 * instead of rebuilding it */
b840c70
-	modified |= seusers_modified;
b840c70
-	modified |= fcontexts_modified;
b840c70
-	modified |= users_extra_modified;
b840c70
-
b840c70
 	/* If there were policy changes, or explicitly requested, rebuild the policy */
b840c70
 	if (sh->do_rebuild || modified) {
b840c70
 
b138896
@@ -667,11 +661,33 @@
b840c70
 		retval = semanage_verify_kernel(sh);
b840c70
 		if (retval < 0)
b840c70
 			goto cleanup;
b840c70
-	}
b840c70
+	} else {
b138896
+		retval = sepol_policydb_create(&out;;
b138896
+		if (retval < 0)
b138896
+			goto cleanup;
b840c70
+		
b840c70
+		retval = semanage_read_policydb(sh, out);
b840c70
+		if (retval < 0)
b840c70
+			goto cleanup;
b840c70
+		
b138896
+		/*		dbase_policydb_attach((dbase_policydb_t *) pusers_base->dbase,out);
b840c70
+		dbase_policydb_attach((dbase_policydb_t *) pports->dbase, out);
b840c70
+		dbase_policydb_attach((dbase_policydb_t *) pifaces->dbase, out);
b840c70
+		dbase_policydb_attach((dbase_policydb_t *) pbools->dbase, out);
b840c70
+		dbase_policydb_attach((dbase_policydb_t *) pnodes->dbase, out);
b138896
+		*/
b840c70
+		if (seusers_modified) {
b840c70
+			retval = pseusers->dtable->clear(sh, pseusers->dbase);
b840c70
+			if (retval < 0)
b840c70
+				goto cleanup;
b840c70
+		}
b840c70
 
b138896
-	/* FIXME: else if !modified, but seusers_modified, 
b138896
-	 * load the existing policy instead of rebuilding */
b840c70
+		retval = semanage_base_merge_components(sh);
b840c70
+		if (retval < 0)
b840c70
+		  goto cleanup;
b138896
 
b840c70
+		/* Seusers */
b840c70
+	}
b840c70
 	/* ======= Post-process: Validate non-policydb components ===== */
b840c70
 
b840c70
 	/* Validate local modifications to file contexts.
b138896
@@ -724,7 +740,8 @@
b138896
 	sepol_policydb_free(out);
b138896
 	out = NULL;
b138896
 
b138896
-	if (sh->do_rebuild || modified) {
b138896
+	if (sh->do_rebuild || modified || 
b138896
+	    seusers_modified || fcontexts_modified || users_extra_modified) {
b138896
 		retval = semanage_install_sandbox(sh);
b138896
 	}
b138896
 
b138896
@@ -733,12 +750,14 @@
b138896
 		free(mod_filenames[i]);
b138896
 	}
b138896
 
b138896
-	/* Detach from policydb, so it can be freed */
b138896
-	dbase_policydb_detach((dbase_policydb_t *) pusers_base->dbase);
b138896
-	dbase_policydb_detach((dbase_policydb_t *) pports->dbase);
b138896
-	dbase_policydb_detach((dbase_policydb_t *) pifaces->dbase);
b138896
-	dbase_policydb_detach((dbase_policydb_t *) pnodes->dbase);
b138896
-	dbase_policydb_detach((dbase_policydb_t *) pbools->dbase);
b138896
+	if (modified) {
b138896
+		/* Detach from policydb, so it can be freed */
b138896
+		dbase_policydb_detach((dbase_policydb_t *) pusers_base->dbase);
b138896
+		dbase_policydb_detach((dbase_policydb_t *) pports->dbase);
b138896
+		dbase_policydb_detach((dbase_policydb_t *) pifaces->dbase);
b138896
+		dbase_policydb_detach((dbase_policydb_t *) pnodes->dbase);
b138896
+		dbase_policydb_detach((dbase_policydb_t *) pbools->dbase);
b138896
+	}
b138896
 
b138896
 	free(mod_filenames);
b138896
 	sepol_policydb_free(out);
b840c70
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/genhomedircon.c libsemanage-2.0.27/src/genhomedircon.c
248b38d
--- nsalibsemanage/src/genhomedircon.c	2008-08-05 09:57:28.000000000 -0400
b138896
+++ libsemanage-2.0.27/src/genhomedircon.c	2008-08-26 10:30:30.000000000 -0400
b138896
@@ -487,7 +487,6 @@
683732d
 				  const char *role_prefix)
683732d
 {
683732d
 	replacement_pair_t repl[] = {
683732d
-		{.search_for = TEMPLATE_SEUSER,.replace_with = seuser},
683732d
 		{.search_for = TEMPLATE_HOME_DIR,.replace_with = home},
683732d
 		{.search_for = TEMPLATE_ROLE,.replace_with = role_prefix},
683732d
 		{NULL, NULL}
b138896
@@ -547,7 +546,6 @@
683732d
 	replacement_pair_t repl[] = {
683732d
 		{.search_for = TEMPLATE_USER,.replace_with = user},
683732d
 		{.search_for = TEMPLATE_ROLE,.replace_with = role_prefix},
683732d
-		{.search_for = TEMPLATE_SEUSER,.replace_with = seuser},
683732d
 		{NULL, NULL}
683732d
 	};
683732d
 	Ustr *line = USTR_NULL;
b840c70
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/semanage.conf libsemanage-2.0.27/src/semanage.conf
8457e95
--- nsalibsemanage/src/semanage.conf	2008-06-12 23:25:16.000000000 -0400
b138896
+++ libsemanage-2.0.27/src/semanage.conf	2008-08-14 14:53:32.000000000 -0400
15aa870
@@ -35,4 +35,4 @@
15aa870
 # given in <sepol/policydb.h>.  Change this setting if a different
15aa870
 # version is necessary.
15aa870
 #policy-version = 19
15aa870
-
15aa870
+expand-check=0
b840c70
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/semanage_store.c libsemanage-2.0.27/src/semanage_store.c
b840c70
--- nsalibsemanage/src/semanage_store.c	2008-06-12 23:25:16.000000000 -0400
b138896
+++ libsemanage-2.0.27/src/semanage_store.c	2008-08-14 14:53:32.000000000 -0400
b840c70
@@ -1648,6 +1648,47 @@
b840c70
 }
b840c70
 
b840c70
 /**
b840c70
+ * Read the policy from the sandbox (kernel)
b840c70
+ */
b840c70
+int semanage_read_policydb(semanage_handle_t * sh, sepol_policydb_t * in)
b840c70
+{
b840c70
+
b840c70
+	int retval = STATUS_ERR;
b840c70
+	const char *kernel_filename = NULL;
b840c70
+	struct sepol_policy_file *pf = NULL;
b840c70
+	FILE *infile = NULL;
b840c70
+
b840c70
+	if ((kernel_filename =
b840c70
+	     semanage_path(SEMANAGE_ACTIVE, SEMANAGE_KERNEL)) == NULL) {
b840c70
+		goto cleanup;
b840c70
+	}
b840c70
+	if ((infile = fopen(kernel_filename, "r")) == NULL) {
b840c70
+		ERR(sh, "Could not open kernel policy %s for reading.",
b840c70
+		    kernel_filename);
b840c70
+		goto cleanup;
b840c70
+	}
b840c70
+	__fsetlocking(infile, FSETLOCKING_BYCALLER);
b840c70
+	if (sepol_policy_file_create(&pf)) {
b840c70
+		ERR(sh, "Out of memory!");
b840c70
+		goto cleanup;
b840c70
+	}
b840c70
+	sepol_policy_file_set_fp(pf, infile);
b840c70
+	sepol_policy_file_set_handle(pf, sh->sepolh);
b840c70
+	if (sepol_policydb_read(in, pf) == -1) {
b840c70
+		ERR(sh, "Error while reading kernel policy from %s.",
b840c70
+		    kernel_filename);
b840c70
+		goto cleanup;
b840c70
+	}
b840c70
+	retval = STATUS_SUCCESS;
b840c70
+
b840c70
+      cleanup:
b840c70
+	if (infile != NULL) {
b840c70
+		fclose(infile);
b840c70
+	}
b840c70
+	sepol_policy_file_free(pf);
b840c70
+	return retval;
b840c70
+}
b840c70
+/**
b840c70
  * Writes the final policy to the sandbox (kernel)
b840c70
  */
b840c70
 int semanage_write_policydb(semanage_handle_t * sh, sepol_policydb_t * out)
b840c70
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/semanage_store.h libsemanage-2.0.27/src/semanage_store.h
b840c70
--- nsalibsemanage/src/semanage_store.h	2008-06-12 23:25:16.000000000 -0400
b138896
+++ libsemanage-2.0.27/src/semanage_store.h	2008-08-14 14:53:32.000000000 -0400
b840c70
@@ -97,6 +97,9 @@
b840c70
 			    sepol_module_package_t * base,
b840c70
 			    sepol_policydb_t ** policydb);
b840c70
 
b840c70
+int semanage_read_policydb(semanage_handle_t * sh,
b840c70
+			    sepol_policydb_t * policydb);
b840c70
+
b840c70
 int semanage_write_policydb(semanage_handle_t * sh,
b840c70
 			    sepol_policydb_t * policydb);
b840c70
 
b138896
diff --exclude-from=exclude -N -u -r nsalibsemanage/tests/test_fcontext.c libsemanage-2.0.27/tests/test_fcontext.c
b138896
--- nsalibsemanage/tests/test_fcontext.c	1969-12-31 19:00:00.000000000 -0500
b138896
+++ libsemanage-2.0.27/tests/test_fcontext.c	2008-08-15 10:59:48.000000000 -0400
b138896
@@ -0,0 +1,72 @@
b138896
+#include <semanage/fcontext_record.h>
b138896
+#include <semanage/semanage.h>
b138896
+#include <semanage/fcontexts_local.h>
b138896
+#include <sepol/sepol.h>
b138896
+
b138896
+#include <errno.h>
b138896
+#include <stdio.h>
b138896
+#include <stdlib.h>
b138896
+
b138896
+int main(const int argc, const char **argv) {
b138896
+	semanage_handle_t *sh = NULL;
b138896
+	semanage_fcontext_t *fcontext;
b138896
+	semanage_context_t *con;
b138896
+	semanage_fcontext_key_t *k;
b138896
+
b138896
+	int exist = 0;
b138896
+	sh = semanage_handle_create();
b138896
+	if (sh == NULL) { 
b138896
+		perror("Can't create semanage handle\n");
b138896
+		return -1;
b138896
+	}
b138896
+        if (semanage_access_check(sh) < 0) {
b138896
+		perror("Semanage access check failed\n");
b138896
+		return -1;
b138896
+	}
b138896
+        if (semanage_connect(sh) < 0) {
b138896
+		perror("Semanage connect failed\n");
b138896
+		return -1;
b138896
+	}
b138896
+
b138896
+	if (semanage_fcontext_key_create(sh, argv[2], SEMANAGE_FCONTEXT_REG, &k) < 0) {
b138896
+		fprintf(stderr, "Could not create key for %s", argv[2]);
b138896
+		return -1;
b138896
+	}
b138896
+
b138896
+	if(semanage_fcontext_exists(sh, k, &exist) < 0) {
b138896
+		fprintf(stderr,"Could not check if key exists for %s", argv[2]);
b138896
+		return -1;
b138896
+	}
b138896
+	if (exist) {
b138896
+		fprintf(stderr,"Could create %s mapping already exists", argv[2]);
b138896
+		return -1;
b138896
+	}
b138896
+
b138896
+	if (semanage_fcontext_create(sh, &fcontext) < 0) {
b138896
+		fprintf(stderr,"Could not create file context for %s", argv[2]);
b138896
+		return -1;
b138896
+	}
b138896
+	semanage_fcontext_set_expr(sh, fcontext, argv[2]);
b138896
+
b138896
+	if (semanage_context_from_string(sh, argv[1], &con)) {
b138896
+		fprintf(stderr,"Could not create context using %s for file context %s", argv[1], argv[2]);
b138896
+		return -1;
b138896
+	}
b138896
+
b138896
+	if (semanage_fcontext_set_con(sh, fcontext, con) < 0) {
b138896
+		fprintf(stderr,"Could not set file context for %s", argv[2]);
b138896
+		return -1;
b138896
+	}
b138896
+
b138896
+	semanage_fcontext_set_type(fcontext, SEMANAGE_FCONTEXT_REG);
b138896
+
b138896
+	if(semanage_fcontext_modify_local(sh, k, fcontext) < 0) {
b138896
+		fprintf(stderr,"Could not add file context for %s", argv[2]);
b138896
+		return -1;
b138896
+	}
b138896
+	semanage_fcontext_key_free(k);
b138896
+	semanage_fcontext_free(fcontext);
b138896
+
b138896
+	return 0;
b138896
+}
b138896
+