psss / rpms / libselinux

Forked from rpms/libselinux 5 years ago
Clone
86ce8d4
diff --exclude-from=exclude -N -u -r nsalibselinux/ChangeLog libselinux-2.0.70/ChangeLog
86ce8d4
--- nsalibselinux/ChangeLog	2008-08-01 06:48:06.000000000 -0400
86ce8d4
+++ libselinux-2.0.70/ChangeLog	2008-08-01 06:51:25.000000000 -0400
86ce8d4
@@ -1,6 +1,3 @@
86ce8d4
-2.0.70 2008-07-30
86ce8d4
-	* Merge ruby bindings from Dan Walsh.
86ce8d4
-
86ce8d4
 2.0.69 2008-07-29
86ce8d4
 	* Handle duplicate file context regexes as a fatal error from Stephen Smalley.
86ce8d4
 	  This prevents adding them via semanage.
86ce8d4
diff --exclude-from=exclude -N -u -r nsalibselinux/VERSION libselinux-2.0.70/VERSION
86ce8d4
--- nsalibselinux/VERSION	2008-08-01 06:48:06.000000000 -0400
86ce8d4
+++ libselinux-2.0.70/VERSION	2008-08-01 06:51:25.000000000 -0400
86ce8d4
@@ -1 +1 @@
86ce8d4
-2.0.70
86ce8d4
+2.0.69
86ce8d4
diff --exclude-from=exclude -N -u -r nsalibselinux/man/man8/selinuxconlist.8 libselinux-2.0.70/man/man8/selinuxconlist.8
792921f
--- nsalibselinux/man/man8/selinuxconlist.8	1969-12-31 19:00:00.000000000 -0500
86ce8d4
+++ libselinux-2.0.70/man/man8/selinuxconlist.8	2008-08-01 06:51:25.000000000 -0400
792921f
@@ -0,0 +1,18 @@
792921f
+.TH "selinuxconlist" "1" "7 May 2008" "dwalsh@redhat.com" "SELinux Command Line documentation"
792921f
+.SH "NAME"
792921f
+selinuxconlist \- list all SELinux context reachable for user
792921f
+.SH "SYNOPSIS"
792921f
+.B selinuxconlist [-l level] user [context]
792921f
+
792921f
+.SH "DESCRIPTION"
792921f
+.B selinuxconlist
792921f
+reports the list of context reachable for user from the current context or specified context
792921f
+
792921f
+.B \-l level
792921f
+mcs/mls level
792921f
+
792921f
+.SH AUTHOR	
792921f
+This manual page was written by Dan Walsh <dwalsh@redhat.com>.
792921f
+
792921f
+.SH "SEE ALSO"
792921f
+secon(8), selinuxdefcon(8)
86ce8d4
diff --exclude-from=exclude -N -u -r nsalibselinux/man/man8/selinuxdefcon.8 libselinux-2.0.70/man/man8/selinuxdefcon.8
792921f
--- nsalibselinux/man/man8/selinuxdefcon.8	1969-12-31 19:00:00.000000000 -0500
86ce8d4
+++ libselinux-2.0.70/man/man8/selinuxdefcon.8	2008-08-01 06:51:25.000000000 -0400
792921f
@@ -0,0 +1,19 @@
792921f
+.TH "selinuxdefcon" "1" "7 May 2008" "dwalsh@redhat.com" "SELinux Command Line documentation"
792921f
+.SH "NAME"
792921f
+selinuxdefcon \- list default SELinux context for user 
792921f
+
792921f
+.SH "SYNOPSIS"
792921f
+.B selinuxdefcon [-l level] user [fromcon]
792921f
+
792921f
+.SH "DESCRIPTION"
792921f
+.B seconlist
792921f
+reports the default context for the specified user from current context or specified context
792921f
+
792921f
+.B \-l level
792921f
+mcs/mls level
792921f
+
792921f
+.SH AUTHOR	
792921f
+This manual page was written by Dan Walsh <dwalsh@redhat.com>.
792921f
+
792921f
+.SH "SEE ALSO"
792921f
+secon(8), selinuxconlist(8)
86ce8d4
diff --exclude-from=exclude -N -u -r nsalibselinux/src/callbacks.c libselinux-2.0.70/src/callbacks.c
d0a06b2
--- nsalibselinux/src/callbacks.c	2008-06-12 23:25:14.000000000 -0400
86ce8d4
+++ libselinux-2.0.70/src/callbacks.c	2008-08-01 06:51:25.000000000 -0400
d0a06b2
@@ -16,6 +16,7 @@
ee77868
 {
d0a06b2
 	int rc;
d0a06b2
 	va_list ap;
d0a06b2
+	if (is_selinux_enabled() == 0) return 0;
d0a06b2
 	va_start(ap, fmt);
d0a06b2
 	rc = vfprintf(stderr, fmt, ap);
d0a06b2
 	va_end(ap);
86ce8d4
diff --exclude-from=exclude -N -u -r nsalibselinux/src/matchpathcon.c libselinux-2.0.70/src/matchpathcon.c
6359e2a
--- nsalibselinux/src/matchpathcon.c	2008-06-12 23:25:14.000000000 -0400
86ce8d4
+++ libselinux-2.0.70/src/matchpathcon.c	2008-08-01 06:51:25.000000000 -0400
71cd138
@@ -2,6 +2,7 @@
71cd138
 #include <string.h>
71cd138
 #include <errno.h>
71cd138
 #include <stdio.h>
71cd138
+#include <syslog.h>
71cd138
 #include "selinux_internal.h"
71cd138
 #include "label_internal.h"
71cd138
 #include "callbacks.h"
0fa749d
@@ -57,7 +58,7 @@
71cd138
 {
71cd138
 	va_list ap;
71cd138
 	va_start(ap, fmt);
71cd138
-	vfprintf(stderr, fmt, ap);
0fa749d
+	vsyslog(LOG_ERR, fmt, ap);
71cd138
 	va_end(ap);
71cd138
 }
71cd138
 
86ce8d4
diff --exclude-from=exclude -N -u -r nsalibselinux/src/seusers.c libselinux-2.0.70/src/seusers.c
86ce8d4
--- nsalibselinux/src/seusers.c	2008-06-12 23:25:14.000000000 -0400
86ce8d4
+++ libselinux-2.0.70/src/seusers.c	2008-08-01 06:53:03.000000000 -0400
86ce8d4
@@ -89,6 +89,62 @@
86ce8d4
 
86ce8d4
 int require_seusers hidden = 0;
86ce8d4
 
86ce8d4
+#include <pwd.h>
86ce8d4
+#include <grp.h>
ee77868
+
86ce8d4
+static gid_t get_default_gid(const char *name) {
86ce8d4
+	struct passwd pwstorage, *pwent = NULL;
86ce8d4
+	gid_t gid = -1;
86ce8d4
+	/* Allocate space for the getpwnam_r buffer */
86ce8d4
+	long rbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
86ce8d4
+	if (rbuflen <= 0) return -1;
86ce8d4
+	char *rbuf = malloc(rbuflen);
86ce8d4
+	if (rbuf == NULL) return -1;
ee77868
+
86ce8d4
+	int retval = getpwnam_r(name, &pwstorage, rbuf, rbuflen, &pwent);
86ce8d4
+	if (retval == 0 || pwent != NULL) {
86ce8d4
+		gid = pwent->pw_gid;
86ce8d4
+	}
86ce8d4
+	free(rbuf);
86ce8d4
+	return gid;
ee77868
+}
ee77868
+
86ce8d4
+static int check_group(const char *group, const char *name, const gid_t gid) {
86ce8d4
+	int match = 0;
86ce8d4
+	int i, ng = 0;
86ce8d4
+	gid_t *groups = NULL;
86ce8d4
+	struct group gbuf, *grent = NULL;
86ce8d4
+
86ce8d4
+	long rbuflen = sysconf(_SC_GETGR_R_SIZE_MAX);
86ce8d4
+	if (rbuflen <= 0)
86ce8d4
+		return 0;
86ce8d4
+	char *rbuf = malloc(rbuflen);
86ce8d4
+	if (rbuf == NULL)
86ce8d4
+		return 0;
86ce8d4
+
86ce8d4
+	if (getgrnam_r(group, &gbuf, rbuf, rbuflen, 
86ce8d4
+		       &grent) != 0)
86ce8d4
+		goto done;
86ce8d4
+
86ce8d4
+	if (getgrouplist(name, gid, NULL, &ng) < 0) {
86ce8d4
+		groups = (gid_t *) malloc(sizeof (gid_t) * ng);
86ce8d4
+		if (!groups) goto done;
86ce8d4
+		if (getgrouplist(name, gid, groups, &ng) < 0) goto done;
ee77868
+	}
ee77868
+
86ce8d4
+	for (i = 0; i < ng; i++) {
86ce8d4
+		if (grent->gr_gid == groups[i]) {
86ce8d4
+			match = 1;
86ce8d4
+			goto done;
86ce8d4
+		}
ee77868
+	}
86ce8d4
+
86ce8d4
+ done:
86ce8d4
+	free(groups);
86ce8d4
+	free(rbuf);
86ce8d4
+	return match;
ee77868
+}
ee77868
+
86ce8d4
 int getseuserbyname(const char *name, char **r_seuser, char **r_level)
86ce8d4
 {
86ce8d4
 	FILE *cfg = NULL;
86ce8d4
@@ -101,9 +157,14 @@
86ce8d4
 	char *username = NULL;
86ce8d4
 	char *seuser = NULL;
86ce8d4
 	char *level = NULL;
86ce8d4
+	char *groupseuser = NULL;
86ce8d4
+	char *grouplevel = NULL;
86ce8d4
 	char *defaultseuser = NULL;
86ce8d4
 	char *defaultlevel = NULL;
86ce8d4
 
86ce8d4
+	gid_t gid = get_default_gid(name);
86ce8d4
+	if ( gid == (gid_t) -1 ) goto nomatch;
86ce8d4
+
86ce8d4
 	cfg = fopen(selinux_usersconf_path(), "r");
86ce8d4
 	if (!cfg)
86ce8d4
 		goto nomatch;
86ce8d4
@@ -124,31 +185,48 @@
86ce8d4
 		if (!strcmp(username, name))
86ce8d4
 			break;
86ce8d4
 
86ce8d4
-		if (!defaultseuser && !strcmp(username, "__default__")) {
86ce8d4
-			free(username);
86ce8d4
-			defaultseuser = seuser;
86ce8d4
-			defaultlevel = level;
86ce8d4
+		if (username[0] == '%' && 
86ce8d4
+		    !groupseuser && 
86ce8d4
+		    check_group(&username[1], name, gid)) {
86ce8d4
+				groupseuser = seuser;
86ce8d4
+				grouplevel = level;
86ce8d4
 		} else {
86ce8d4
-			free(username);
86ce8d4
-			free(seuser);
86ce8d4
-			free(level);
86ce8d4
+			if (!defaultseuser && 
86ce8d4
+			    !strcmp(username, "__default__")) {
86ce8d4
+				defaultseuser = seuser;
86ce8d4
+				defaultlevel = level;
86ce8d4
+			} else {
86ce8d4
+				free(seuser);
86ce8d4
+				free(level);
86ce8d4
+			}
86ce8d4
 		}
86ce8d4
+		free(username);
86ce8d4
+		username = NULL;
86ce8d4
 		seuser = NULL;
86ce8d4
 	}
86ce8d4
 
86ce8d4
-	if (buffer)
86ce8d4
-		free(buffer);
86ce8d4
+	free(buffer);
86ce8d4
 	fclose(cfg);
86ce8d4
 
86ce8d4
 	if (seuser) {
86ce8d4
 		free(username);
86ce8d4
 		free(defaultseuser);
86ce8d4
 		free(defaultlevel);
86ce8d4
+		free(groupseuser);
86ce8d4
+		free(grouplevel);
86ce8d4
 		*r_seuser = seuser;
86ce8d4
 		*r_level = level;
86ce8d4
 		return 0;
86ce8d4
 	}
86ce8d4
 
86ce8d4
+	if (groupseuser) {
86ce8d4
+		free(defaultseuser);
86ce8d4
+		free(defaultlevel);
86ce8d4
+		*r_seuser = groupseuser;
86ce8d4
+		*r_level = grouplevel;
86ce8d4
+		return 0;
ee77868
+	}
ee77868
+
86ce8d4
 	if (defaultseuser) {
86ce8d4
 		*r_seuser = defaultseuser;
86ce8d4
 		*r_level = defaultlevel;