[libselinux] * Makefiles: syntax, convert all ${VAR} to $(VAR) * load_policy: handle selinux=0 and /sys/fs/seli

Daniel J Walsh dwalsh at fedoraproject.org
Fri Nov 4 13:13:59 UTC 2011


commit 5cb2893d59879f742ba9b74ab8641937fd59aa3c
Author: Dan Walsh <dwalsh at redhat.com>
Date:   Fri Nov 4 09:13:56 2011 -0400

    	* Makefiles: syntax, convert all ${VAR} to $(VAR)
    	* load_policy: handle selinux=0 and /sys/fs/selinux not exist
    	* regenerate .pc on VERSION change
    	* label: cosmetic cleanups
    	* simple interface for access checks
    	* Don't reinitialize avc_init if it has been called previously
    	* seusers: fix to handle large sets of groups
    	* audit2why: close fd on enomem
    	* rename and export symlink_realpath
    	* label_file: style changes to make Eric happy.

 .gitignore            |    1 +
 libselinux-rhat.patch |  349 ++++++++++++++++++------------------------------
 libselinux.spec       |   18 ++-
 sources               |    2 +-
 4 files changed, 148 insertions(+), 222 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 52a6ebf..a1ffd78 100644
--- a/.gitignore
+++ b/.gitignore
@@ -188,3 +188,4 @@ libselinux-2.0.96.tgz
 /libselinux-2.1.4.tgz
 /libselinux-2.1.5.tgz
 /libselinux-2.1.6.tgz
+/libselinux-2.1.7.tgz
diff --git a/libselinux-rhat.patch b/libselinux-rhat.patch
index b3fbef9..2c5ee11 100644
--- a/libselinux-rhat.patch
+++ b/libselinux-rhat.patch
@@ -1,78 +1,77 @@
+diff --git a/libselinux/include/selinux/label.h b/libselinux/include/selinux/label.h
+index 1a54307..f6eeb21 100644
+--- a/libselinux/include/selinux/label.h
++++ b/libselinux/include/selinux/label.h
+@@ -46,8 +46,10 @@ struct selabel_handle;
+ #define SELABEL_OPT_PATH	3
+ /* select a subset of the search space as an optimization (file backend) */
+ #define SELABEL_OPT_SUBSET	4
++/* like subset, but an array of subsets */
++#define SELABEL_OPT_PREFIXES	5
+ /* total number of options */
+-#define SELABEL_NOPT		5
++#define SELABEL_NOPT		6
+ 
+ /*
+  * Label operations
 diff --git a/libselinux/include/selinux/selinux.h b/libselinux/include/selinux/selinux.h
-index d29b0c1..792e68e 100644
+index 2985f6f..826ed71 100644
 --- a/libselinux/include/selinux/selinux.h
 +++ b/libselinux/include/selinux/selinux.h
-@@ -500,6 +500,25 @@ extern const char *selinux_colors_path(void);
- extern const char *selinux_netfilter_context_path(void);
- extern const char *selinux_path(void);
+@@ -139,7 +139,10 @@ struct av_decision {
+ /* Structure for passing options, used by AVC and label subsystems */
+ struct selinux_opt {
+ 	int type;
+-	const char *value;
++	union {
++		const char *value;
++		const char **values;
++	};
+ };
+ 
+ /* Callback facilities */
+@@ -410,6 +413,11 @@ extern int matchpathcon_init(const char *path);
+    regexes that have stems that are prefixes of 'prefix'. */
+ extern int matchpathcon_init_prefix(const char *path, const char *prefix);
  
-+/**
-+ * selinux_check_access - Check permissions and perform appropriate auditing.
-+ * @scon: source security context
-+ * @tcon: target security context
-+ * @tclass: target security class string
-+ * @perm: requested permissions string, interpreted based on @tclass
-+ * @auditdata: auxiliary audit data
-+ *
-+ * Check the AVC to determine whether the @perm permissions are granted
-+ * for the SID pair (@scon, @tcon), interpreting the permissions
-+ * based on @tclass.
-+ * Return %0 if all @perm permissions are granted, -%1 with 
-+ * @errno set to %EACCES if any permissions are denied or to another 
-+ * value upon other errors.
-+ * If auditing or logging is configured the appropriate callbacks will be called
-+ * and passed the auditdata field
-+ */
-+extern int selinux_check_access(const security_context_t scon, const security_context_t tcon, const char *tclass, const char *perm, void *auditdata);
++/* Same as matchpathcon_init, but only load entries with
++ * regexes that have stems that are prefixes of the 'prefixes'
++ * array of entries.  The last entry must be NULL. */
++extern int matchpathcon_init_prefixes(const char *patch, const char **prefixes);
 +
- /* Check a permission in the passwd class.
-    Return 0 if granted or -1 otherwise. */
- extern int selinux_check_passwd_access(access_vector_t requested);
+ /* Free the memory allocated by matchpathcon_init. */
+ extern void matchpathcon_fini(void);
+ 
 diff --git a/libselinux/man/man3/matchpathcon.3 b/libselinux/man/man3/matchpathcon.3
-index cdbb252..e2a4371 100644
+index cdbb252..b6814ed 100644
 --- a/libselinux/man/man3/matchpathcon.3
 +++ b/libselinux/man/man3/matchpathcon.3
-@@ -8,7 +8,7 @@ matchpathcon, matchpathcon_index \- get the default SELinux security context for
+@@ -8,7 +8,9 @@ matchpathcon, matchpathcon_index \- get the default SELinux security context for
  
  .BI "int matchpathcon_init(const char *" path ");"
  
 -.BI "int matchpathcon_init_prefix(const char *" path ", const char *" subset ");"
 +.BI "int matchpathcon_init_prefix(const char *" path ", const char *" prefix ");"
++
++.BI "int matchpathcon_init_prefixes(const char *" path ", const char **" prefixes ");"
  
  .BI "int matchpathcon_fini(void);"
  .sp
-@@ -48,7 +48,7 @@ is the same as
- but only loads entries with regular expressions that have stems prefixed
- by
+@@ -50,6 +52,14 @@ by
  .I prefix.
--
-+prefix can have multiple paths separated by ":", for example "/dev:/var/run:/tmp"
+ 
  .sp
++.B matchpathcon_init_prefixes
++is the same as
++.B matchpathcon_init_prefix
++but takes an array of
++.I prefixes
++instead of a single prefix.  The last entry in the array must be NULL.
++
++.sp
  .B matchpathcon_fini
  frees the memory allocated by a prior call to
-diff --git a/libselinux/man/man3/security_compute_av.3 b/libselinux/man/man3/security_compute_av.3
-index f2d9f30..1e36952 100644
---- a/libselinux/man/man3/security_compute_av.3
-+++ b/libselinux/man/man3/security_compute_av.3
-@@ -24,6 +24,8 @@ the SELinux policy database in the kernel.
- .BI "int security_get_initial_context(const char *" name ", security_context_t
- "con );
- .sp
-+.BI "int selinux_check_access(const security_context_t " scon, " const security_context_t " tcon, " const char *" class, " const char *" perm, "void *" auditdata);
-+.sp
- .BI "int selinux_check_passwd_access(access_vector_t " requested );
- .sp
- .BI "int checkPasswdAccess(access_vector_t " requested );
-@@ -74,6 +76,9 @@ source context. It is mainly used by
- is used to get the context of a kernel initial security identifier specified by 
- .I name
- 
-+.B selinux_check_access
-+is used to check if the source context has the access permission for the specified class on the target context.
-+
- .B selinux_check_passwd_access
- is used to check for a permission in the
- .I passwd
+ .B matchpathcon_init.
 diff --git a/libselinux/man/man3/selabel_open.3 b/libselinux/man/man3/selabel_open.3
 index 8674e37..89bb4d3 100644
 --- a/libselinux/man/man3/selabel_open.3
@@ -96,27 +95,6 @@ index 8674e37..89bb4d3 100644
  .BR selinux_set_callback (3),
  .BR selinux (8)
 -
-diff --git a/libselinux/man/man3/selinux_check_access.3 b/libselinux/man/man3/selinux_check_access.3
-new file mode 100644
-index 0000000..a60bca4
---- /dev/null
-+++ b/libselinux/man/man3/selinux_check_access.3
-@@ -0,0 +1 @@
-+.so man3/security_compute_av.3
-diff --git a/libselinux/src/avc.c b/libselinux/src/avc.c
-index 74591b4..e7ad31d 100644
---- a/libselinux/src/avc.c
-+++ b/libselinux/src/avc.c
-@@ -165,6 +165,9 @@ int avc_init(const char *prefix,
- 	struct avc_node *new;
- 	int i, rc = 0;
- 
-+	if (avc_running)
-+		return 0;
-+
- 	if (prefix)
- 		strncpy(avc_prefix, prefix, AVC_PREFIX_SIZE - 1);
- 
 diff --git a/libselinux/src/callbacks.c b/libselinux/src/callbacks.c
 index b245364..7c47222 100644
 --- a/libselinux/src/callbacks.c
@@ -129,53 +107,8 @@ index b245364..7c47222 100644
  	va_start(ap, fmt);
  	rc = vfprintf(stderr, fmt, ap);
  	va_end(ap);
-diff --git a/libselinux/src/checkAccess.c b/libselinux/src/checkAccess.c
-index c1982c7..59c8abb 100644
---- a/libselinux/src/checkAccess.c
-+++ b/libselinux/src/checkAccess.c
-@@ -4,8 +4,40 @@
- #include <errno.h>
- #include "selinux_internal.h"
- #include <selinux/flask.h>
-+#include <selinux/avc.h>
- #include <selinux/av_permissions.h>
- 
-+static pthread_once_t once = PTHREAD_ONCE_INIT;
-+
-+static void avc_init_once(void)
-+{
-+	avc_open(NULL, 0);
-+}
-+
-+int selinux_check_access(const security_context_t scon, const security_context_t tcon, const char *class, const char *perm, void *aux) {
-+	int status = -1;
-+	int rc = -1;
-+	security_id_t scon_id;
-+	security_id_t tcon_id;
-+	security_class_t sclass;
-+	access_vector_t av;
-+
-+	if (is_selinux_enabled() == 0)
-+		return 0;
-+
-+	__selinux_once(once, avc_init_once);
-+
-+	if ((rc = avc_context_to_sid(scon, &scon_id)) < 0)  return rc;
-+
-+	if ((rc = avc_context_to_sid(tcon, &tcon_id)) < 0)  return rc;
-+
-+	if ((sclass = string_to_security_class(class)) == 0) return status;
-+
-+	if ((av = string_to_av_perm(sclass, perm)) == 0) return status;
-+
-+	return avc_has_perm (scon_id, tcon_id, sclass, av, NULL, aux);
-+}
-+
- int selinux_check_passwd_access(access_vector_t requested)
- {
- 	int status = -1;
 diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
-index 3b8346d..02f3f98 100644
+index ac11b37..42889cf 100644
 --- a/libselinux/src/label_file.c
 +++ b/libselinux/src/label_file.c
 @@ -27,6 +27,7 @@
@@ -186,7 +119,7 @@ index 3b8346d..02f3f98 100644
  /* A file security context specification. */
  typedef struct spec {
  	struct selabel_lookup_rec lr;	/* holds contexts for lookup result */
-@@ -279,7 +280,7 @@ static int compile_regex(struct saved_data *data, spec_t *spec, char **errbuf)
+@@ -276,7 +277,7 @@ static int compile_regex(struct saved_data *data, spec_t *spec, char **errbuf)
  
  
  static int process_line(struct selabel_handle *rec,
@@ -195,7 +128,7 @@ index 3b8346d..02f3f98 100644
  			char *line_buf, int pass, unsigned lineno)
  {
  	int items, len;
-@@ -313,12 +314,24 @@ static int process_line(struct selabel_handle *rec,
+@@ -310,12 +311,24 @@ static int process_line(struct selabel_handle *rec,
  	}
  
  	len = get_stem_from_spec(regex);
@@ -226,78 +159,57 @@ index 3b8346d..02f3f98 100644
  	}
  
  	if (pass == 1) {
-@@ -400,7 +413,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
+@@ -397,7 +410,8 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
  {
  	struct saved_data *data = (struct saved_data *)rec->data;
  	const char *path = NULL;
 -	const char *prefix = NULL;
-+	const char *prefix_array[MAX_PREFIX] = {NULL,};
++	const char *static_prefix_array[2] = {NULL, };
++	const char **prefix_array = static_prefix_array;
  	FILE *fp;
  	FILE *localfp = NULL;
  	FILE *homedirfp = NULL;
-@@ -421,8 +434,19 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
+@@ -418,7 +432,10 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
  			path = opts[n].value;
  			break;
  		case SELABEL_OPT_SUBSET:
 -			prefix = opts[n].value;
-+		{ 
-+			char *ptr;
-+			i = 0;
-+			if (opts[n].value) {
-+				prefix_array[i] = strtok_r((char *)opts[n].value, ":", &ptr);
-+				while ((prefix_array[i] != NULL) && i < MAX_PREFIX - 1) {
-+					i++;
-+					prefix_array[i] = strtok_r(NULL, ":", &ptr);
-+				}
-+			}
-+
++			static_prefix_array[0] = opts[n].value;
++			break;
++		case SELABEL_OPT_PREFIXES:
++			prefix_array = opts[n].values;
  			break;
-+		}
  		case SELABEL_OPT_BASEONLY:
  			baseonly = !!opts[n].value;
- 			break;
-@@ -481,7 +505,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
- 		data->ncomp = 0;
- 		while (getline(&line_buf, &line_len, fp) > 0
- 		       && data->nspec < maxnspec) {
--			if (process_line(rec, path, prefix, line_buf,
-+			if (process_line(rec, path, prefix_array, line_buf,
- 					 pass, ++lineno) != 0)
+@@ -480,7 +497,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
+ 		while (getline(&line_buf, &line_len, fp) > 0) {
+ 			if (data->nspec >= maxnspec)
+ 				break;
+-			status = process_line(rec, path, prefix, line_buf, pass, ++lineno);
++			status = process_line(rec, path, prefix_array, line_buf, pass, ++lineno);
+ 			if (status)
  				goto finish;
  		}
-@@ -495,7 +519,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
- 			while (getline(&line_buf, &line_len, homedirfp) > 0
- 			       && data->nspec < maxnspec) {
- 				if (process_line
--				    (rec, homedir_path, prefix,
-+				    (rec, homedir_path, prefix_array,
- 				     line_buf, pass, ++lineno) != 0)
+@@ -496,7 +513,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
+ 			while (getline(&line_buf, &line_len, homedirfp) > 0) {
+ 				if (data->nspec >= maxnspec)
+ 					break;
+-				status = process_line(rec, homedir_path, prefix, line_buf, pass, ++lineno);
++				status = process_line(rec, homedir_path, prefix_array, line_buf, pass, ++lineno);
+ 				if (status)
  					goto finish;
  			}
-@@ -505,7 +529,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
- 			while (getline(&line_buf, &line_len, localfp) > 0
- 			       && data->nspec < maxnspec) {
- 				if (process_line
--				    (rec, local_path, prefix, line_buf,
-+				    (rec, local_path, prefix_array, line_buf,
- 				     pass, ++lineno) != 0)
+@@ -506,7 +523,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
+ 			while (getline(&line_buf, &line_len, localfp) > 0) {
+ 				if (data->nspec >= maxnspec)
+ 					break;
+-				status = process_line(rec, local_path, prefix, line_buf, pass, ++lineno);
++				status = process_line(rec, local_path, prefix_array, line_buf, pass, ++lineno);
+ 				if (status)
  					goto finish;
  			}
-diff --git a/libselinux/src/load_policy.c b/libselinux/src/load_policy.c
-index 868660f..7fa6383 100644
---- a/libselinux/src/load_policy.c
-+++ b/libselinux/src/load_policy.c
-@@ -380,7 +380,7 @@ int selinux_init_load_policy(int *enforce)
- 	}
- 
- 	if (! mntpoint ) {
--		if (errno == ENODEV) {
-+		if (errno == ENODEV || errno == ENOENT) {
- 			/*
- 			 * SELinux was disabled in the kernel, either
- 			 * omitted entirely or disabled at boot via selinux=0.
 diff --git a/libselinux/src/matchpathcon.c b/libselinux/src/matchpathcon.c
-index 5914afa..df83b30 100644
+index c396add..489ef3a 100644
 --- a/libselinux/src/matchpathcon.c
 +++ b/libselinux/src/matchpathcon.c
 @@ -2,6 +2,7 @@
@@ -317,48 +229,49 @@ index 5914afa..df83b30 100644
  	va_end(ap);
  }
  
-diff --git a/libselinux/src/seusers.c b/libselinux/src/seusers.c
-index fc75cb6..b653cad 100644
---- a/libselinux/src/seusers.c
-+++ b/libselinux/src/seusers.c
-@@ -5,6 +5,7 @@
- #include <stdio.h>
- #include <stdio_ext.h>
- #include <ctype.h>
-+#include <errno.h>
- #include <selinux/selinux.h>
- #include <selinux/context.h>
- #include "selinux_internal.h"
-@@ -118,13 +119,26 @@ static int check_group(const char *group, const char *name, const gid_t gid) {
- 	long rbuflen = sysconf(_SC_GETGR_R_SIZE_MAX);
- 	if (rbuflen <= 0)
- 		return 0;
--	char *rbuf = malloc(rbuflen);
--	if (rbuf == NULL)
--		return 0;
-+	char *rbuf;
+@@ -304,7 +305,7 @@ static void matchpathcon_init_once(void)
+ 		destructor_key_initialized = 1;
+ }
  
--	if (getgrnam_r(group, &gbuf, rbuf, rbuflen, 
--		       &grent) != 0)
--		goto done;
-+	while(1) {
-+		rbuf = malloc(rbuflen);
-+		if (rbuf == NULL)
-+			return 0;
-+		int retval = getgrnam_r(group, &gbuf, rbuf, 
-+				rbuflen, &grent);
-+		if ( retval == ERANGE )
-+		{
-+			free(rbuf);
-+			rbuflen = rbuflen * 2;
-+		} else if ( retval != 0 || grent == NULL )
-+		{
-+			goto done;
-+		} else
-+		{
-+			break;
-+		}
-+	}
+-int matchpathcon_init_prefix(const char *path, const char *subset)
++int matchpathcon_init_prefixes(const char *path, const char **prefixes)
+ {
+ 	if (!mycanoncon)
+ 		mycanoncon = default_canoncon;
+@@ -312,15 +313,22 @@ int matchpathcon_init_prefix(const char *path, const char *subset)
+ 	__selinux_once(once, matchpathcon_init_once);
+ 	__selinux_setspecific(destructor_key, (void *)1);
+ 
+-	options[SELABEL_OPT_SUBSET].type = SELABEL_OPT_SUBSET;
+-	options[SELABEL_OPT_SUBSET].value = subset;
++	options[SELABEL_OPT_PREFIXES].type = SELABEL_OPT_PREFIXES;
++	options[SELABEL_OPT_PREFIXES].values = prefixes;
+ 	options[SELABEL_OPT_PATH].type = SELABEL_OPT_PATH;
+ 	options[SELABEL_OPT_PATH].value = path;
+ 
+ 	hnd = selabel_open(SELABEL_CTX_FILE, options, SELABEL_NOPT);
+ 	return hnd ? 0 : -1;
+ }
++hidden_def(matchpathcon_init_prefixes)
+ 
++int matchpathcon_init_prefix(const char *path, const char *prefix)
++{
++	const char *prefixes[2] = { prefix, NULL };
++
++	return matchpathcon_init_prefixes(path, prefixes);
++}
+ hidden_def(matchpathcon_init_prefix)
  
- 	if (getgrouplist(name, gid, NULL, &ng) < 0) {
- 		groups = (gid_t *) malloc(sizeof (gid_t) * ng);
+ int matchpathcon_init(const char *path)
+diff --git a/libselinux/src/selinux_internal.h b/libselinux/src/selinux_internal.h
+index 710396a..9a3fc14 100644
+--- a/libselinux/src/selinux_internal.h
++++ b/libselinux/src/selinux_internal.h
+@@ -80,6 +80,7 @@ hidden_proto(selinux_mkload_policy)
+     hidden_proto(selinux_path)
+     hidden_proto(selinux_check_passwd_access)
+     hidden_proto(selinux_check_securetty_context)
++    hidden_proto(matchpathcon_init_prefixes)
+     hidden_proto(matchpathcon_init_prefix)
+     hidden_proto(selinux_users_path)
+     hidden_proto(selinux_usersconf_path);
diff --git a/libselinux.spec b/libselinux.spec
index e727884..8c386b4 100644
--- a/libselinux.spec
+++ b/libselinux.spec
@@ -1,13 +1,13 @@
 %global with_python3 1
 
 %define ruby_sitearch %(ruby -rrbconfig -e "puts Config::CONFIG['sitearchdir']")
-%define libsepolver 2.1.3-1
+%define libsepolver 2.1.3-2
 %{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
 
 Summary: SELinux library and simple utilities
 Name: libselinux
-Version: 2.1.6
-Release: 4%{?dist}
+Version: 2.1.7
+Release: 1%{?dist}
 License: Public Domain
 Group: System Environment/Libraries
 Source: %{name}-%{version}.tgz
@@ -231,6 +231,18 @@ rm -rf %{buildroot}
 %{ruby_sitearch}/selinux.so
 
 %changelog
+* Fri Nov 4 2011 Dan Walsh <dwalsh at redhat.com> - 2.1.7-1
+	* Makefiles: syntax, convert all ${VAR} to $(VAR)
+	* load_policy: handle selinux=0 and /sys/fs/selinux not exist
+	* regenerate .pc on VERSION change
+	* label: cosmetic cleanups
+	* simple interface for access checks
+	* Don't reinitialize avc_init if it has been called previously
+	* seusers: fix to handle large sets of groups
+	* audit2why: close fd on enomem
+	* rename and export symlink_realpath
+	* label_file: style changes to make Eric happy.
+
 * Mon Oct 24 2011 Dan Walsh <dwalsh at redhat.com> - 2.1.6-4
 - Apply libselinux patch to handle large groups in seusers.
 
diff --git a/sources b/sources
index e3724b3..ea0101d 100644
--- a/sources
+++ b/sources
@@ -1 +1 @@
-94fa8daf439f79db14821d4ff7f68f98  libselinux-2.1.6.tgz
+77352e66fff6d0a48b30dc851dc50f82  libselinux-2.1.7.tgz


More information about the scm-commits mailing list