Skip to contentSkip to conversation

Add modules support to semanage

PATCH Daniel J Walsh 2 participants 9 messages Sep 30, 2009 – Dec 30, 2009 SELinux security module

lore
Share & tools
lore
#0 lore raw

Includes enable and disable.

policycoreutils/semanage/semanage +34 -1
index 437eca3..128ab47 100644
@@ -44,11 +44,12 @@ if __name__ == '__main__':
                text = _("""
 semanage [ -S store ] -i [ input_file | - ]
 
-semanage {boolean|login|user|port|interface|node|fcontext} -{l|D} [-n]
+semanage {boolean|login|user|port|interface|module|node|fcontext} -{l|D} [-n]
 semanage login -{a|d|m} [-sr] login_name | %groupname
 semanage user -{a|d|m} [-LrRP] selinux_name
 semanage port -{a|d|m} [-tr] [ -p proto ] port | port_range
 semanage interface -{a|d|m} [-tr] interface_spec
+semanage module -{a|d|m} [--enable|--disable] module
 semanage node -{a|d|m} [-tr] [ -p protocol ] [-M netmask] addr
 semanage fcontext -{a|d|m} [-frst] file_spec
 semanage boolean -{d|m} [--on|--off|-1|-0] -F boolean | boolean_file
@@ -90,6 +91,8 @@ Object-specific Options (see above):
 	-s, --seuser     SELinux User Name
 	-t, --type       SELinux Type for the object
 	-r, --range      MLS/MCS Security Range (MLS/MCS Systems only)
+        --enable         Enable a module
+        --disable        Disable a module
 """)
                raise ValueError("%s\n%s" % (text, message))
 		
@@ -110,6 +113,8 @@ Object-specific Options (see above):
 		valid_option["port"] += valid_everyone + [ '-t', '--type', '-r', '--range', '-p', '--proto' ]
 		valid_option["interface"] = []
 		valid_option["interface"] += valid_everyone + [ '-t', '--type', '-r', '--range']
+		valid_option["module"] = []
+		valid_option["module"] += valid_everyone + [ '--enable', '--disable']
 		valid_option["node"] = []
 		valid_option["node"] += valid_everyone + [ '-M', '--mask', '-t', '--type', '-r', '--range', '-p', '--protocol']
 		valid_option["fcontext"] = []
@@ -188,6 +193,8 @@ Object-specific Options (see above):
 		locallist = False
 		use_file = False
                 store = ""
+                enable = False
+                disable = False
 			
 		object = argv[0]
 		option_dict=get_options()
@@ -240,6 +247,18 @@ Object-specific Options (see above):
 				if modify:
                                        raise ValueError(_("%s bad option") % o)
 				deleteall = True
+
+			if o == "--enable":
+                                if disable:
+                                       raise ValueError(_("You can't disable and enable at the same time"))
+
+				enable = True
+
+			if o == "--disable":
+                                if enable:
+                                       raise ValueError(_("You can't disable and enable at the same time"))
+				disable = True
+
 			if o == "-f"  or o == "--ftype":
 				ftype=a
 
@@ -307,6 +326,9 @@ Object-specific Options (see above):
 		if object == "interface":
 			OBJECT = seobject.interfaceRecords(store)
 
+		if object == "module":
+			OBJECT = seobject.moduleRecords(store)
+
 		if object == "node":
 			OBJECT = seobject.nodeRecords(store)
 
@@ -355,6 +377,9 @@ Object-specific Options (see above):
 			if object == "interface":
 				OBJECT.add(target, serange, setype)
 
+			if object == "module":
+				OBJECT.add(target)
+
 			if object == "node":
 				OBJECT.add(target, mask, proto, serange, setype)
 
@@ -382,6 +407,14 @@ Object-specific Options (see above):
 			if object == "interface":
 				OBJECT.modify(target, serange, setype)
 
+			if object == "module":
+                                if enable:
+                                       OBJECT.enable(target)
+                                elif disable:
+                                       OBJECT.disable(target)
+                                else:
+                                       OBJECT.modify(target)
+
 			if object == "node":
 				OBJECT.modify(target, mask, proto, serange, setype)
 
policycoreutils/semanage/seobject.py +71 -0

77 lines not on this page · raw message

#1 lore raw
Quoted 2 lines · Daniel J Walsh

Includes enable and disable.

I presume I should hold off on this patch until you have a chance to resubmit the libsemanage support that it relies on. Let me know if that's not the case.

Thanks,
Chad

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
Quoted 11 lines · Chad Sellers
Quoted 2 lines · Daniel J Walsh

Includes enable and disable.

I presume I should hold off on this patch until you have a chance to resubmit the libsemanage support that it relies on. Let me know if that's not the case.

Thanks,
Chad

Lets do this patch.

Moves load_policy from /usr/sbin to /sbin

Removed cruft.

libsemanage/src/conf-parse.y +7 -1
index 23661bf..931448f 100644
@@ -263,7 +263,13 @@ static int semanage_conf_init(semanage_conf_t * conf)
 	     calloc(1, sizeof(*(current_conf->load_policy)))) == NULL) {
 		return -1;
 	}
-	if ((conf->load_policy->path = strdup("/usr/sbin/load_policy")) == NULL) {
+
+	if (access("/sbin/load_policy", X_OK) == 0) {
+		conf->load_policy->path = strdup("/sbin/load_policy");
+	} else {
+		conf->load_policy->path = strdup("/usr/sbin/load_policy");
+	}
+	if (conf->load_policy->path == NULL)
 		return -1;
 	}
 	conf->load_policy->args = NULL;
policycoreutils/load_policy/Makefile +4 -1
index 2dd2943..91dc6c8 100644
@@ -1,6 +1,7 @@
 # Installation directories.
 PREFIX ?= ${DESTDIR}/usr
-SBINDIR ?= $(PREFIX)/sbin
+SBINDIR ?= $(DESTDIR)/sbin
+USRSBINDIR ?= $(PREFIX)/sbin
 MANDIR ?= $(PREFIX)/share/man
 LOCALEDIR ?= /usr/share/locale
 
@@ -17,6 +18,8 @@ install: all
 	install -m 755 $(TARGETS) $(SBINDIR)
 	test -d $(MANDIR)/man8 || install -m 755 -d $(MANDIR)/man8
 	install -m 644 load_policy.8 $(MANDIR)/man8/
+	-mkdir -p $(USRSBINDIR)
+	ln -s /sbin/load_policy $(USRSBINDIR)/load_policy
 
 clean:
 	-rm -f $(TARGETS) *.o 
#6 lore raw
In reply to Chad Sellers
Quoted 11 lines · Chad Sellers
Quoted 2 lines · Daniel J Walsh

Includes enable and disable.

I presume I should hold off on this patch until you have a chance to resubmit the libsemanage support that it relies on. Let me know if that's not the case.

Thanks,
Chad

This patch is provided the old fashioned way since I am fighting with guilt right now.

Just the enable/disable changes to libsemanage.

include/semanage/modules.h +4 -1
diff --exclude-from=exclude -N -u -r nsalibsemanage/include/semanage/modules.h libsemanage-2.0.41/include/semanage/modules.h
@@ -40,10 +40,12 @@
 				 char *module_data, size_t data_len);
 int semanage_module_install_base_file(semanage_handle_t *,
 				      const char *module_name);
+int semanage_module_enable(semanage_handle_t *, char *module_name);
+int semanage_module_disable(semanage_handle_t *, char *module_name);
 int semanage_module_remove(semanage_handle_t *, char *module_name);
 
 /* semanage_module_info is for getting information on installed
-   modules, only name and version at this time */
+   modules, only name and version, and enabled/disabled flag at this time */
 typedef struct semanage_module_info semanage_module_info_t;
 
 int semanage_module_list(semanage_handle_t *,
@@ -53,5 +55,6 @@
 						 int n);
 const char *semanage_module_get_name(semanage_module_info_t *);
 const char *semanage_module_get_version(semanage_module_info_t *);
+int semanage_module_get_enabled(semanage_module_info_t *);
 
 #endif
src/direct_api.c +116 -3

164 lines not on this page · raw message

src/libsemanage.map +3 -0
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/libsemanage.map libsemanage-2.0.41/src/libsemanage.map
@@ -6,10 +6,13 @@
 	  semanage_module_install; semanage_module_install_file;
 	  semanage_module_upgrade; semanage_module_upgrade_file;
 	  semanage_module_install_base; semanage_module_install_base_file;
+	  semanage_module_enable;
+	  semanage_module_disable;
 	  semanage_module_remove;
 	  semanage_module_list; semanage_module_info_datum_destroy;
 	  semanage_module_list_nth; semanage_module_get_name;
 	  semanage_module_get_version; semanage_select_store;
+	  semanage_module_get_enabled;
 	  semanage_reload_policy; semanage_set_reload; semanage_set_rebuild;
 	  semanage_user_*; semanage_bool_*; semanage_seuser_*;
 	  semanage_iface_*; semanage_port_*; semanage_context_*;
src/module_internal.h +1 -0
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/module_internal.h libsemanage-2.0.41/src/module_internal.h
@@ -6,6 +6,7 @@
 
 hidden_proto(semanage_module_get_name)
     hidden_proto(semanage_module_get_version)
+    hidden_proto(semanage_module_get_enabled)
     hidden_proto(semanage_module_info_datum_destroy)
     hidden_proto(semanage_module_list_nth)
 #endif
src/modules.c +41 -0

53 lines not on this page · raw message

src/modules.h +1 -0
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/modules.h libsemanage-2.0.41/src/modules.h
@@ -26,6 +26,7 @@
 struct semanage_module_info {
 	char *name;		/* Key */
 	char *version;
+	int enabled;
 };
 
 #endif
src/policy.h +6 -0
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/policy.h libsemanage-2.0.41/src/policy.h
@@ -58,6 +58,12 @@
 	/* Upgrade a policy module */
 	int (*upgrade_file) (struct semanage_handle *, const char *);
 
+	/* Enable a policy module */
+	int (*enable) (struct semanage_handle *, char *);
+
+	/* Disable a policy module */
+	int (*disable) (struct semanage_handle *, char *);
+
 	/* Remove a policy module */
 	int (*remove) (struct semanage_handle *, char *);
 
src/semanage_store.c +49 -11

96 lines not on this page · raw message

src/semanage_store.h +2 -0
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/semanage_store.h libsemanage-2.0.41/src/semanage_store.h
@@ -128,4 +128,6 @@
 		     size_t buf_len,
 		     char **sorted_buf, size_t * sorted_buf_len);
 
+extern const char *DISABLESTR;
+
 #endif
#8 lore raw
In reply to Chad Sellers
Quoted 11 lines · Chad Sellers
Quoted 2 lines · Daniel J Walsh

Includes enable and disable.

I presume I should hold off on this patch until you have a chance to resubmit the libsemanage support that it relies on. Let me know if that's not the case.

Thanks,
Chad

I have updated the sandbox patch to include a setsid call in seunshare.

policycoreutils/Makefile +1 -1
index 538302b..394069a 100644
@@ -1,4 +1,4 @@
-SUBDIRS = setfiles semanage load_policy newrole run_init secon audit2allow audit2why scripts sestatus semodule_package semodule semodule_link semodule_expand semodule_deps setsebool po
+SUBDIRS = sandbox setfiles semanage load_policy newrole run_init secon audit2allow audit2why scripts sestatus semodule_package semodule semodule_link semodule_expand semodule_deps setsebool po
 
 INOTIFYH = $(shell ls /usr/include/sys/inotify.h 2>/dev/null)
 
policycoreutils/sandbox/Makefile new file +31 -0
new file mode 100644
index 0000000..299276a
@@ -0,0 +1,31 @@
+# Installation directories.
+PREFIX ?= ${DESTDIR}/usr
+BINDIR ?= $(PREFIX)/bin
+SBINDIR ?= $(PREFIX)/sbin
+MANDIR ?= $(PREFIX)/share/man
+LOCALEDIR ?= /usr/share/locale
+SHAREDIR ?= $(PREFIX)/share/sandbox
+override CFLAGS += $(LDFLAGS) -I$(PREFIX)/include -DPACKAGE="\"policycoreutils\""
+LDLIBS += -lselinux -lcap-ng 
+
+all: sandbox seunshare sandboxX.sh 
+
+seunshare: seunshare.o $(EXTRA_OBJS)
+	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
+install: all
+	-mkdir -p $(BINDIR)
+	install -m 755 sandbox $(BINDIR)
+	-mkdir -p $(MANDIR)/man8
+	install -m 644 sandbox.8 $(MANDIR)/man8/
+	install -m 4755 seunshare $(SBINDIR)/
+	-mkdir -p $(SHAREDIR)
+	install -m 755 sandboxX.sh $(SHAREDIR)
+
+clean:
+	-rm -f seunshare *.o *~
+
+indent:
+	../../scripts/Lindent $(wildcard *.[ch])
+
+relabel:
policycoreutils/sandbox/sandbox new file +242 -0

242 lines not on this page · raw message

policycoreutils/sandbox/sandbox.8 new file +26 -0
new file mode 100644
index 0000000..c3f8a1f
@@ -0,0 +1,26 @@
+.TH SANDBOX "8" "May 2009" "chcat" "User Commands"
+.SH NAME
+sandbox \- Run cmd under an SELinux sandbox
+.SH SYNOPSIS
+.B sandbox
+[-X] [[-i file ]...] [ -t type ] cmd
+.br
+.SH DESCRIPTION
+.PP
+Run application within a tightly confined SELinux domain,   The default sandbox allows the application to only read and write stdin and stdout along with files handled to it by the shell.  
+Additionaly a -X qualifier allows you to run sandboxed X applications.  These apps will start up their own X Server and create a temporary homedir and /tmp.  The default policy does not allow any capabilities or network access.  Also prevents all access to the users other processes and files.  Any file specified on the command line will be copied into the sandbox.
+.PP
+.TP
+\fB\-t type\fR
+Use alternate sandbox type, defaults to sandbox_t or sandbox_x_t for -X.
+.TP
+\fB\-i file\fR
+Copy this file into the temporary sandbox homedir. Command can be repeated.
+.TP
+\fB\-X\fR
+Create an X based Sandbox for gui apps, temporary files for $HOME and /tmp, seconday Xserver, defaults to sandbox_x_t
+.TP
+.SH "SEE ALSO"
+.TP
+runcon(1)
+.PP
policycoreutils/sandbox/sandboxX.sh new file +16 -0
new file mode 100644
index 0000000..21e6b0d
@@ -0,0 +1,16 @@
+#!/bin/bash 
+export TITLE="Sandbox: `/usr/bin/tail -1 ~/.sandboxrc | /usr/bin/cut -b1-70`"
+export SCREEN=`/usr/bin/xdpyinfo -display $DISPLAY | /bin/awk '/dimensions/ { print $2 }'`
+
+(/usr/bin/Xephyr -title "$TITLE" -terminate -screen 1000x700 -displayfd 5 5>&1 2>/dev/null) | while read D; do 
+    export DISPLAY=:$D
+    /usr/bin/matchbox-window-manager -use_titlebar no &
+    WM_PID=$!
+    ~/.sandboxrc &
+    CLIENT_PID=$!
+    wait $CLIENT_PID
+    export EXITCODE=$?
+    kill -TERM $WM_PID
+    kill -HUP 0
+    break
+done
policycoreutils/sandbox/seunshare.c new file +265 -0

265 lines not on this page · raw message

#3 lore raw
In reply to Daniel J Walsh
Quoted 26 lines · Daniel J Walsh
Quoted 11 lines · Chad Sellers
Quoted 2 lines · Daniel J Walsh

Includes enable and disable.

I presume I should hold off on this patch until you have a chance to resubmit the libsemanage support that it relies on. Let me know if that's not the case.

Thanks,
Chad

Lets do this patch.

Moves load_policy from /usr/sbin to /sbin

Removed cruft.

libsemanage/src/conf-parse.y +0 -0
index 23661bf..931448f 100644
@@ -263,7 +263,13 @@ static int semanage_conf_init(semanage_conf_t * conf)
          calloc(1, sizeof(*(current_conf->load_policy)))) == NULL) {
         return -1;

libsemanage/src/conf-parse.y static int semanage_conf_init(semanage_conf_t * conf) · line 273

Quoted 10 lines
libsemanage/src/conf-parse.y +7 -1
     }
-    if ((conf->load_policy->path = strdup("/usr/sbin/load_policy")) == NULL)
 {
+
+    if (access("/sbin/load_policy", X_OK) == 0) {
+        conf->load_policy->path = strdup("/sbin/load_policy");
+    } else {
+        conf->load_policy->path = strdup("/usr/sbin/load_policy");
+    }
+    if (conf->load_policy->path == NULL)

Still missing a curly brace.

Quoted 18 lines
libsemanage/src/conf-parse.y +0 -0
         return -1;
     }
     conf->load_policy->args = NULL;
policycoreutils/load_policy/Makefile +2 -1
index 2dd2943..91dc6c8 100644
@@ -1,6 +1,7 @@
 # Installation directories.
 PREFIX ?= ${DESTDIR}/usr
-SBINDIR ?= $(PREFIX)/sbin
+SBINDIR ?= $(DESTDIR)/sbin
+USRSBINDIR ?= $(PREFIX)/sbin
 MANDIR ?= $(PREFIX)/share/man
 LOCALEDIR ?= /usr/share/locale
 

policycoreutils/load_policy/Makefile install: all · line 23

Quoted 6 lines
policycoreutils/load_policy/Makefile +2 -0
@@ -17,6 +18,8 @@ install: all
     install -m 755 $(TARGETS) $(SBINDIR)
     test -d $(MANDIR)/man8 || install -m 755 -d $(MANDIR)/man8
     install -m 644 load_policy.8 $(MANDIR)/man8/
+    -mkdir -p $(USRSBINDIR)
+    ln -s /sbin/load_policy $(USRSBINDIR)/load_policy
 

Still using -s instead of -sf. You never responded to my previous email (
http://marc.info/?l=selinux&m=125788814205762&w=2 ). Are you ok with these 2 fixes? If so, I can make the changes and merge this.

Thanks,
Chad

policycoreutils/load_policy/Makefile install: all · line 25

Quoted 2 lines
policycoreutils/load_policy/Makefile +0 -0
 clean:
     -rm -f $(TARGETS) *.o 

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw
Quoted 69 lines · Chad Sellers
Quoted 26 lines · Daniel J Walsh
Quoted 11 lines · Chad Sellers
Quoted 2 lines · Daniel J Walsh

Includes enable and disable.

I presume I should hold off on this patch until you have a chance to resubmit the libsemanage support that it relies on. Let me know if that's not the case.

Thanks,
Chad

Lets do this patch.

Moves load_policy from /usr/sbin to /sbin

Removed cruft.

libsemanage/src/conf-parse.y +0 -0
index 23661bf..931448f 100644
@@ -263,7 +263,13 @@ static int semanage_conf_init(semanage_conf_t * conf)
          calloc(1, sizeof(*(current_conf->load_policy)))) == NULL) {
         return -1;

libsemanage/src/conf-parse.y static int semanage_conf_init(semanage_conf_t * conf) · line 273

Quoted 10 lines
libsemanage/src/conf-parse.y +7 -1
     }
-    if ((conf->load_policy->path = strdup("/usr/sbin/load_policy")) == NULL)
 {
+
+    if (access("/sbin/load_policy", X_OK) == 0) {
+        conf->load_policy->path = strdup("/sbin/load_policy");
+    } else {
+        conf->load_policy->path = strdup("/usr/sbin/load_policy");
+    }
+    if (conf->load_policy->path == NULL)

Still missing a curly brace.

Quoted 18 lines
libsemanage/src/conf-parse.y +0 -0
         return -1;
     }
     conf->load_policy->args = NULL;
policycoreutils/load_policy/Makefile +2 -1
index 2dd2943..91dc6c8 100644
@@ -1,6 +1,7 @@
 # Installation directories.
 PREFIX ?= ${DESTDIR}/usr
-SBINDIR ?= $(PREFIX)/sbin
+SBINDIR ?= $(DESTDIR)/sbin
+USRSBINDIR ?= $(PREFIX)/sbin
 MANDIR ?= $(PREFIX)/share/man
 LOCALEDIR ?= /usr/share/locale
 

policycoreutils/load_policy/Makefile install: all · line 23

Quoted 6 lines
policycoreutils/load_policy/Makefile +2 -0
@@ -17,6 +18,8 @@ install: all
     install -m 755 $(TARGETS) $(SBINDIR)
     test -d $(MANDIR)/man8 || install -m 755 -d $(MANDIR)/man8
     install -m 644 load_policy.8 $(MANDIR)/man8/
+    -mkdir -p $(USRSBINDIR)
+    ln -s /sbin/load_policy $(USRSBINDIR)/load_policy
 

Still using -s instead of -sf. You never responded to my previous email (
http://marc.info/?l=selinux&m=125788814205762&w=2 ). Are you ok with these 2 fixes? If so, I can make the changes and merge this.

Quoted 6 lines

Thanks,
Chad

Quoted 2 lines
policycoreutils/load_policy/Makefile +0 -0
 clean:
     -rm -f $(TARGETS) *.o 

Yes go ahead.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#5 lore raw
Quoted 71 lines · Daniel J Walsh
Quoted 70 lines · Chad Sellers
Quoted 27 lines · Daniel J Walsh
Quoted 11 lines · Chad Sellers
Quoted 2 lines · Daniel J Walsh

Includes enable and disable.

I presume I should hold off on this patch until you have a chance to resubmit the libsemanage support that it relies on. Let me know if that's not the case.

Thanks,
Chad

Lets do this patch.

Moves load_policy from /usr/sbin to /sbin

Removed cruft.

libsemanage/src/conf-parse.y +0 -0
index 23661bf..931448f 100644
@@ -263,7 +263,13 @@ static int semanage_conf_init(semanage_conf_t * conf)
          calloc(1, sizeof(*(current_conf->load_policy)))) == NULL) {
         return -1;
     }

libsemanage/src/conf-parse.y static int semanage_conf_init(semanage_conf_t * conf) · line 274

Quoted 10 lines
libsemanage/src/conf-parse.y +7 -1
-    if ((conf->load_policy->path = strdup("/usr/sbin/load_policy")) ==
 NULL)
 {
+
+    if (access("/sbin/load_policy", X_OK) == 0) {
+        conf->load_policy->path = strdup("/sbin/load_policy");
+    } else {
+        conf->load_policy->path = strdup("/usr/sbin/load_policy");
+    }
+    if (conf->load_policy->path == NULL)

Still missing a curly brace.

Quoted 18 lines
libsemanage/src/conf-parse.y +0 -0
         return -1;
     }
     conf->load_policy->args = NULL;
policycoreutils/load_policy/Makefile +2 -1
index 2dd2943..91dc6c8 100644
@@ -1,6 +1,7 @@
 # Installation directories.
 PREFIX ?= ${DESTDIR}/usr
-SBINDIR ?= $(PREFIX)/sbin
+SBINDIR ?= $(DESTDIR)/sbin
+USRSBINDIR ?= $(PREFIX)/sbin
 MANDIR ?= $(PREFIX)/share/man
 LOCALEDIR ?= /usr/share/locale
 

policycoreutils/load_policy/Makefile install: all · line 23

Quoted 6 lines
policycoreutils/load_policy/Makefile +2 -0
@@ -17,6 +18,8 @@ install: all
     install -m 755 $(TARGETS) $(SBINDIR)
     test -d $(MANDIR)/man8 || install -m 755 -d $(MANDIR)/man8
     install -m 644 load_policy.8 $(MANDIR)/man8/
+    -mkdir -p $(USRSBINDIR)
+    ln -s /sbin/load_policy $(USRSBINDIR)/load_policy
 

Still using -s instead of -sf. You never responded to my previous email (
http://marc.info/?l=selinux&m=125788814205762&w=2 ). Are you ok with these 2 fixes? If so, I can make the changes and merge this.

Quoted 7 lines
Quoted 6 lines

Thanks,
Chad

Quoted 2 lines
policycoreutils/load_policy/Makefile +0 -0
 clean:
     -rm -f $(TARGETS) *.o

Yes go ahead.

OK, merged as of policycoreutils 2.0.76 and libsemanage 2.0.42.

Thanks,
Chad

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#7 lore raw
In reply to Daniel J Walsh
Quoted 43 lines · Daniel J Walsh
Quoted 11 lines · Chad Sellers
Quoted 2 lines · Daniel J Walsh

Includes enable and disable.

I presume I should hold off on this patch until you have a chance to resubmit the libsemanage support that it relies on. Let me know if that's not the case.

Thanks,
Chad

This patch is provided the old fashioned way since I am fighting with guilt right now.

Just the enable/disable changes to libsemanage.

policycoreutils/Makefile +0 -1
index 538302b..394069a 100644
@@ -1,4 +1,4 @@
-SUBDIRS = setfiles semanage load_policy newrole run_init secon audit2allow

audit2why scripts sestatus semodule_package semodule semodule_link semodule_expand semodule_deps setsebool po
+SUBDIRS = sandbox setfiles semanage load_policy newrole run_init secon audit2allow audit2why scripts sestatus semodule_package semodule semodule_link semodule_expand semodule_deps setsebool po

INOTIFYH = $(shell ls /usr/include/sys/inotify.h 2>/dev/null)

policycoreutils/sandbox/Makefile new file +4 -0
new file mode 100644
index 0000000..299276a
@@ -0,0 +1,31 @@
+# Installation directories.
+PREFIX ?= ${DESTDIR}/usr
+BINDIR ?= $(PREFIX)/bin
+SBINDIR ?= $(PREFIX)/sbin

policycoreutils/sandbox/Makefile

Quoted 10 lines
policycoreutils/sandbox/Makefile new file +9 -1
+MANDIR ?= $(PREFIX)/share/man
+LOCALEDIR ?= /usr/share/locale
+SHAREDIR ?= $(PREFIX)/share/sandbox
+override CFLAGS += $(LDFLAGS) -I$(PREFIX)/include
-DPACKAGE="\"policycoreutils\""
+LDLIBS += -lselinux -lcap-ng
+
+all: sandbox seunshare sandboxX.sh
+
+seunshare: seunshare.o $(EXTRA_OBJS)

EXTRA_OBJS? I don't see that anywhere else.

Quoted 79 lines
policycoreutils/sandbox/Makefile new file +18 -0
+    $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
+install: all
+    -mkdir -p $(BINDIR)
+    install -m 755 sandbox $(BINDIR)
+    -mkdir -p $(MANDIR)/man8
+    install -m 644 sandbox.8 $(MANDIR)/man8/
+    install -m 4755 seunshare $(SBINDIR)/
+    -mkdir -p $(SHAREDIR)
+    install -m 755 sandboxX.sh $(SHAREDIR)
+
+clean:
+    -rm -f seunshare *.o *~
+
+indent:
+    ../../scripts/Lindent $(wildcard *.[ch])
+
+relabel:
policycoreutils/sandbox/sandbox new file +55 -0
new file mode 100644
index 0000000..bc257bf
@@ -0,0 +1,242 @@
+#!/usr/bin/python -E
+import os, sys, getopt, socket, random, fcntl, shutil
+import selinux
+import signal
+
+PROGNAME = "policycoreutils"
+
+import gettext
+gettext.bindtextdomain(PROGNAME, "/usr/share/locale")
+gettext.textdomain(PROGNAME)
+
+try:
+       gettext.install(PROGNAME,
+                       localedir = "/usr/share/locale",
+                       unicode=False,
+                       codeset = 'utf-8')
+except IOError:
+       import __builtin__
+       __builtin__.__dict__['_'] = unicode
+
+
+DEFAULT_TYPE = "sandbox_t"
+DEFAULT_X_TYPE = "sandbox_x_t"
+X_FILES = {}
+
+random.seed(None)
+
+def sighandler(signum, frame):
+    signal.signal(signum,  signal.SIG_IGN)
+    os.kill(0, signum)
+    raise KeyboardInterrupt
+
+def setup_sighandlers():
+    signal.signal(signal.SIGHUP,  sighandler)
+    signal.signal(signal.SIGQUIT, sighandler)
+    signal.signal(signal.SIGTERM, sighandler)
+
+def error_exit(msg):
+    sys.stderr.write("%s: " % sys.argv[0])
+    sys.stderr.write("%s\n" % msg)
+    sys.stderr.flush()
+    sys.exit(1)
+
+def reserve(mcs):
+    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+    sock.bind("\0%s" % mcs)
+    fcntl.fcntl(sock.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC)
+
+def gen_context(setype):
+    while True:
+        i1 = random.randrange(0, 1024)
+        i2 = random.randrange(0, 1024)
+        if i1 == i2:
+            continue
+        if i1 > i2:

policycoreutils/sandbox/sandbox line 65

Quoted 10 lines
policycoreutils/sandbox/sandbox new file +10 -0
+            tmp = i1
+            i1 = i2
+            i2 = tmp
+        mcs = "s0:c%d,c%d" % (i1, i2)
+        reserve(mcs)
+        try:
+            reserve(mcs)
+        except:
+            continue
+        break

I'm guessing this is supposed to ensure that 2 sandboxes have different category sets. It looks like it's supposed to bind to an abstract socket to prevent other processes from doing the same. I don't understand why reserve() is called twice (once outside the try block, then once inside). Regardless, in my testing it doesn't seem to work (I switched i1 and i2 to hardcoded values and can run multiple sandboxes with the same category sets simultaneously). So perhaps I'm misunderstanding the intent here.

Also, assuming I'm guessing what this is supposed to do correctly, this logic will hang when the system runs out of categories. Admittedly that's a million sandboxes, but an error message would be much better than an infinite loop.

Quoted 27 lines
policycoreutils/sandbox/sandbox new file +27 -0
+    con = selinux.getcon()[1].split(":")
+
+    execcon = "%s:%s:%s:%s" % (con[0], con[1], setype, mcs)
+    
+    filecon = "%s:%s:%s:%s" % (con[0],
+                               "object_r",
+                               "%s_file_t" % setype[:-2],
+                               mcs)
+    return execcon, filecon
+
+def copyfile(file, dir, dest):
+       import re
+       if file.startswith(dir):
+              dname = os.path.dirname(file)
+              bname = os.path.basename(file)
+              if dname == dir:
+                     dest = dest + "/" + bname
+              else:
+                     newdir = re.sub(dir, dest, dname)
+                     os.makedirs(newdir)
+                     dest = newdir + "/" + bname
+
+              if os.path.isdir(file):
+                     shutil.copytree(file, dest)
+              else:
+                     shutil.copy2(file, dest)
+              X_FILES[file] = (dest, os.path.getmtime(dest))

policycoreutils/sandbox/sandbox line 102

Quoted 10 lines
policycoreutils/sandbox/sandbox new file +10 -0
+
+def copyfiles(newhomedir, newtmpdir, files):
+       import pwd
+       homedir=pwd.getpwuid(os.getuid()).pw_dir
+       for f in files:
+              copyfile(f,homedir, newhomedir)
+              copyfile(f,"/tmp", newtmpdir)
+
+def savefile(new, orig):
+       import gtk

Hmmm, this adds a gtk requirement to policycoreutils which we've never had before. Could we wrap this in a try block and use the console if gtk is not available? That way we could still support graphical messages if it was available, but work anyway if not.

policycoreutils/sandbox/sandbox

Quoted 12 lines
policycoreutils/sandbox/sandbox new file +3 -0
+       dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO,
+                               gtk.BUTTONS_YES_NO,
+                               _("Do you want to save changes to '%s' (Y/N):

") % orig)

policycoreutils/sandbox/sandbox new file +8 -0
+       dlg.set_title(_("Sandbox Message"))
+       dlg.set_position(gtk.WIN_POS_MOUSE)
+       dlg.show_all()
+       rc = dlg.run()
+       dlg.destroy()
+       if rc == gtk.RESPONSE_YES:
+              shutil.copy2(new,orig)
+

copyfile() above allows for copying individual files or full directory trees into the sandbox, but savefile() here seems to only allow copying individual files out of it. I'm guessing this will blow up if someone clicks Yes on a changed directory.

Quoted 12 lines
policycoreutils/sandbox/sandbox new file +12 -0
+if __name__ == '__main__':
+    setup_sighandlers()
+    if selinux.is_selinux_enabled() != 1:
+        error_exit("Requires an SELinux enabled system")
+        
+    init_files = []
+
+    def usage(message = ""):
+        text = _("""
+sandbox [-h] [-I includefile ] [[-i file ] ...] [ -t type ] command
+""")
+        error_exit("%s\n%s" % (message, text))

policycoreutils/sandbox/sandbox

Quoted 10 lines
policycoreutils/sandbox/sandbox new file +10 -0
+
+    setype = DEFAULT_TYPE
+    X_ind = False
+    try:
+           gopts, cmds = getopt.getopt(sys.argv[1:], "i:ht:XI:",
+                                       ["help",
+                                        "include=",
+                                        "includefile=",
+                                        "type="
+                                        ])

This does not agree with the usage message above or the man page (and they don't agree with each other either). The usage leaves out -X. The man page leaves out -h and -I.

Quoted 100 lines
policycoreutils/sandbox/sandbox new file +34 -0
+           for o, a in gopts:
+                  if o == "-t" or o == "--type":
+                         setype = a
+                
+                  if o == "-i" or o == "--include":
+                         rp = os.path.realpath(a)
+                         if rp not in init_files:
+                                init_files.append(rp)
+                
+                  if o == "-I" or o == "--includefile":
+                         fd = open(a, "r")
+                         for i in fd.read().split("\n"):
+                                if os.path.exists(i):
+                                       rp = os.path.realpath(i)
+                                       if rp not in init_files:
+                                              init_files.append(rp)
+                
+                         fd.close
+                
+                  if o == "-X":
+                         if DEFAULT_TYPE == setype:
+                                setype = DEFAULT_X_TYPE
+                         X_ind = True
+
+                  if o == "-h" or o == "--help":
+                         usage(_("Usage"));
+            
+           if len(cmds) == 0:
+                  usage(_("Command required"))
+
+           execcon, filecon = gen_context(setype)
+           rc = -1
+
+           if cmds[0][0] != "/" and cmds[0][:2] != "./" and cmds[0][:3] !=

"../":

policycoreutils/sandbox/sandbox new file +12 -0
+                  for i in  os.environ["PATH"].split(':'):
+                         f = "%s/%s" % (i, cmds[0])
+                         if os.access(f, os.X_OK):
+                                cmds[0] = f
+                                break
+
+           try:
+                  newhomedir = None
+                  newtmpdir = None
+                  if X_ind:
+                         if not os.path.exists("/usr/sbin/seunshare"):
+                                raise ValueError("""/usr/sbin/seunshare

required for sandbox -X, to install you need to execute

policycoreutils/sandbox/sandbox new file +28 -0
+#yum install /usr/sbin/seunshare""")
+                         import warnings
+                         warnings.simplefilter("ignore")
+                         newhomedir = os.tempnam(".", ".sandbox%s")
+                         os.mkdir(newhomedir)
+                         selinux.setfilecon(newhomedir, filecon)
+                         newtmpdir = os.tempnam("/tmp", ".sandbox")
+                         os.mkdir(newtmpdir)
+                         selinux.setfilecon(newtmpdir, filecon)
+                         warnings.resetwarnings()
+                         paths = []
+                         for i in cmds:
+                                f = os.path.realpath(i)
+                                if os.path.exists(f):
+                                       paths.append(f)
+                                else:
+                                       paths.append(i)
+                
+                         copyfiles(newhomedir, newtmpdir, init_files + paths)
+                         execfile = newhomedir + "/.sandboxrc"
+                         fd = open(execfile, "w+")
+                         fd.write("""#! /bin/sh
+%s
+""" % " ".join(paths))
+                         fd.close()
+                         os.chmod(execfile, 0700)
+                
+                         cmds =  ("/usr/sbin/seunshare -t %s -h %s -- %s

/usr/share/sandbox/sandboxX.sh" % (newtmpdir, newhomedir, execcon)).split()

policycoreutils/sandbox/sandbox new file +23 -0
+                         rc = os.spawnvp(os.P_WAIT, cmds[0], cmds)
+                         for i in paths:
+                                if i not in X_FILES:
+                                       continue
+                                (dest, mtime) = X_FILES[i]
+                                if os.path.getmtime(dest) > mtime:
+                                       savefile(dest, i)
+                  else:
+                         selinux.setexeccon(execcon)
+                         rc = os.spawnvp(os.P_WAIT, cmds[0], cmds)
+                         selinux.setexeccon(None)
+           finally:
+                  if X_ind:
+                         if newhomedir:
+                                shutil.rmtree(newhomedir)
+                         if newtmpdir:
+                                shutil.rmtree(newtmpdir)
+                
+    except getopt.GetoptError, error:
+           usage(_("Options Error %s ") % error.msg)
+    except OSError, error:
+           error_exit(error.args[1])
+    except ValueError, error:

policycoreutils/sandbox/sandbox

Quoted 10 lines
policycoreutils/sandbox/sandbox new file +10 -0
+           error_exit(error.args[0])
+    except KeyError, error:
+           error_exit(_("Invalid value %s") % error.args[0])
+    except IOError, error:
+           error_exit(error.args[1])
+    except KeyboardInterrupt:
+           rc = 0
+           
+    sys.exit(rc)
+

The other potential problem I see with this utility is that it makes some assumptions about the configuration (and mostly policy) of the system. These include:
1) The system is using an mcs policy
2) The sandbox file type is foo_file_t if the sandbox type is foo_t
3) There are 1024 categories
4) seunshare is found in /usr/sbin

I think #1 and #2 are necessary assumptions, and hard to avoid. #3 could be solved with an optional command line arg. #4 probably isn't a big deal, but I'd move it to a variable at the top so other distros can easily change it if necessary.

policycoreutils/sandbox/sandbox.8 line 6

Quoted 13 lines
policycoreutils/sandbox/sandbox.8 new file +6 -0
new file mode 100644
index 0000000..c3f8a1f
@@ -0,0 +1,26 @@
+.TH SANDBOX "8" "May 2009" "chcat" "User Commands"
+.SH NAME
+sandbox \- Run cmd under an SELinux sandbox
+.SH SYNOPSIS
+.B sandbox
+[-X] [[-i file ]...] [ -t type ] cmd

This should probably be:
[-X [-i file ]...] [ -t type ] cmd
or something similar to indicate that -i is only valid if you're using -X.

Speaking of which, any reason you chose not to allow the unshared tmp/home for non-X apps? It seems like useful functionality for command-line programs as well.

Quoted 191 lines
policycoreutils/sandbox/sandbox.8 new file +4 -0
+.br
+.SH DESCRIPTION
+.PP
+Run application within a tightly confined SELinux domain,   The default

sandbox allows the application to only read and write stdin and stdout along with files handled to it by the shell.
+Additionaly a -X qualifier allows you to run sandboxed X applications. These apps will start up their own X Server and create a temporary homedir and /tmp. The default policy does not allow any capabilities or network access. Also prevents all access to the users other processes and files. Any file specified on the command line will be copied into the sandbox. +.PP
+.TP
+\fB\-t type\fR

policycoreutils/sandbox/sandbox.8 new file +7 -0
+Use alternate sandbox type, defaults to sandbox_t or sandbox_x_t for -X.
+.TP
+\fB\-i file\fR
+Copy this file into the temporary sandbox homedir. Command can be repeated.
+.TP
+\fB\-X\fR
+Create an X based Sandbox for gui apps, temporary files for $HOME and /tmp,

seconday Xserver, defaults to sandbox_x_t
+.TP
+.SH "SEE ALSO"
+.TP

policycoreutils/sandbox/sandbox.8 new file +2 -0
+runcon(1)
+.PP
policycoreutils/sandbox/sandboxX.sh new file +3 -0
new file mode 100644
index 0000000..21e6b0d
@@ -0,0 +1,16 @@
+#!/bin/bash 
+export TITLE="Sandbox: `/usr/bin/tail -1 ~/.sandboxrc | /usr/bin/cut -b1-70`"
+export SCREEN=`/usr/bin/xdpyinfo -display $DISPLAY | /bin/awk '/dimensions/ {

print $2 }'`

policycoreutils/sandbox/sandboxX.sh new file +2 -0
+
+(/usr/bin/Xephyr -title "$TITLE" -terminate -screen 1000x700 -displayfd 5

5>&1 2>/dev/null) | while read D; do

policycoreutils/sandbox/sandboxX.sh new file +11 -0
+    export DISPLAY=:$D
+    /usr/bin/matchbox-window-manager -use_titlebar no &
+    WM_PID=$!
+    ~/.sandboxrc &
+    CLIENT_PID=$!
+    wait $CLIENT_PID
+    export EXITCODE=$?
+    kill -TERM $WM_PID
+    kill -HUP 0
+    break
+done
policycoreutils/sandbox/seunshare.c new file +71 -0
new file mode 100644
index 0000000..ddf6bf1
@@ -0,0 +1,265 @@
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <syslog.h>
+#include <sys/mount.h>
+#include <pwd.h>
+#define _GNU_SOURCE
+#include <sched.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <cap-ng.h>
+#include <getopt.h>        /* for getopt_long() form of getopt() */
+#include <limits.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <selinux/selinux.h>
+#include <selinux/context.h>    /* for context-mangling functions */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+/**
+ * This function will drop all capabilities
+ * Returns zero on success, non-zero otherwise
+ */
+static int drop_capabilities(uid_t uid)
+{
+    capng_clear(CAPNG_SELECT_BOTH);
+
+    if (capng_lock() < 0)
+        return -1;
+    /* Change uid */
+    if (setresuid(uid, uid, uid)) {
+        fprintf(stderr, "Error changing uid, aborting.\n");
+        return -1;
+    }
+    return capng_apply(CAPNG_SELECT_BOTH);
+}
+
+#define DEFAULT_PATH "/usr/bin:/bin"
+#define TRUE 1
+#define FALSE 0
+
+/**
+ * Take care of any signal setup
+ */
+static int set_signal_handles(void)
+{
+    sigset_t empty;
+
+    /* Empty the signal mask in case someone is blocking a signal */
+    if (sigemptyset(&empty)) {
+        fprintf(stderr, "Unable to obtain empty signal set\n");
+        return -1;
+    }
+
+    (void)sigprocmask(SIG_SETMASK, &empty, NULL);
+
+    /* Terminate on SIGHUP. */
+    if (signal(SIGHUP, SIG_DFL) == SIG_ERR) {
+        perror("Unable to set SIGHUP handler");
+        return -1;
+    }
+
+    return 0;
+}
+#define USAGE_STRING "USAGE: seunshare [ -t tmpdir ] [ -h homedir ] --

CONTEXT executable [args] "

policycoreutils/sandbox/seunshare.c new file +12 -0
+
+
+
+static int verify_mount(const char *mntdir, struct passwd *pwd) {
+    struct stat sb;
+    if (stat(mntdir, &sb) == -1) {
+        perror("Invalid mount point");
+        return -1;
+    }
+    if (sb.st_uid != pwd->pw_uid) {
+        errno = EPERM;
+        syslog(LOG_AUTHPRIV | LOG_ALERT, "%s attempted to mount an invalid

directory, %s", pwd->pw_name, mntdir);

policycoreutils/sandbox/seunshare.c new file +47 -0
+        perror("Invalid mount point, reporting to administrator");
+        return -1;
+    }
+    return 0;
+}
+
+/**
+ * This function checks to see if the shell is known in /etc/shells.
+ * If so, it returns 1. On error or illegal shell, it returns 0.
+ */
+static int verify_shell(const char *shell_name)
+{
+    int found = 0;
+    const char *buf;
+
+    if (!(shell_name && shell_name[0]))
+        return found;
+
+    while ((buf = getusershell()) != NULL) {
+        /* ignore comments */
+        if (*buf == '#')
+            continue;
+
+        /* check the shell skipping newline char */
+        if (!strcmp(shell_name, buf)) {
+            found = 1;
+            break;
+        }
+    }
+    endusershell();
+    return found;
+}
+
+int main(int argc, char **argv) {
+    int rc;
+    int status = -1;
+
+    security_context_t scontext;
+
+    int flag_index;        /* flag index in argv[] */
+    int clflag;        /* holds codes for command line flags */
+    char *tmpdir_s = NULL;    /* tmpdir spec'd by user in argv[] */
+    char *homedir_s = NULL;    /* homedir spec'd by user in argv[] */
+
+    const struct option long_options[] = {
+        {"homedir", 1, 0, 'h'},
+        {"tmpdir", 1, 0, 't'},

policycoreutils/sandbox/seunshare.c

Quoted 10 lines
policycoreutils/sandbox/seunshare.c new file +10 -0
+        {NULL, 0, 0, 0}
+    };
+
+    uid_t uid = getuid();
+
+    if (!uid) {
+        fprintf(stderr, "Must not be root");
+        return -1;
+    }
+

Why? Root can't run graphical things in a sandbox? Seems like an unnecessary restriction.

Quoted 118 lines
policycoreutils/sandbox/seunshare.c new file +56 -0
+    struct passwd *pwd=getpwuid(uid);
+    if (!pwd) {
+        perror("getpwduid failed");
+        return -1;
+    }
+
+    if (verify_shell(pwd->pw_shell) == 0) {
+        fprintf(stderr, "Error!  Shell is not valid.\n");
+        return -1;
+    }
+
+    while (1) {
+        clflag = getopt_long(argc, argv, "h:t:", long_options,
+                     &flag_index);
+        if (clflag == -1)
+            break;
+
+        switch (clflag) {
+        case 't':
+            tmpdir_s = optarg;
+            if (verify_mount(tmpdir_s, pwd) < 0) return -1;
+            break;
+        case 'h':
+            homedir_s = optarg;
+            if (verify_mount(homedir_s, pwd) < 0) return -1;
+            if (verify_mount(pwd->pw_dir, pwd) < 0) return -1;
+            break;
+        default:
+            fprintf(stderr, "%s\n", USAGE_STRING);
+            return -1;
+        }
+    }
+
+    if (! homedir_s && ! tmpdir_s) {
+        fprintf(stderr, "Error: tmpdir and/or homedir required \n"
+            "%s\n", USAGE_STRING);
+        return -1;
+    }
+
+    if (argc - optind < 2) {
+        fprintf(stderr, "Error: executable required \n"
+            "%s\n", USAGE_STRING);
+        return -1;
+    }
+
+    scontext = argv[optind++];
+    
+    if (set_signal_handles())
+        return -1;
+
+        if (unshare(CLONE_NEWNS) < 0) {
+        perror("Failed to unshare");
+        return -1;
+    }
+
+    if (homedir_s && mount(homedir_s, pwd->pw_dir, NULL, MS_BIND, NULL) < 0)

{

policycoreutils/sandbox/seunshare.c new file +59 -0
+        perror("Failed to mount HOMEDIR");
+        return -1;
+    }
+
+    if (homedir_s && verify_mount(pwd->pw_dir, pwd) < 0)
+        return -1;
+
+    if (tmpdir_s && mount(tmpdir_s, "/tmp", NULL, MS_BIND, NULL) < 0) {
+        perror("Failed to mount /tmp");
+        return -1;
+    }
+
+    if (tmpdir_s && verify_mount("/tmp", pwd) < 0)
+        return -1;
+
+    if (drop_capabilities(uid)) {
+        perror("Failed to drop all capabilities");
+        return -1;
+    }
+
+    int child = fork();
+    if (!child) {
+        char *display=NULL;
+        /* Construct a new environment */
+        char *d = getenv("DISPLAY");
+        if (d) {
+            display =  strdup(d);
+            if (!display) {
+                perror("Out of memory");
+                exit(-1);
+            }
+        }
+
+        if ((rc = clearenv())) {
+            perror("Unable to clear environment");
+            free(display);
+            exit(-1);
+        }
+        
+        if (setexeccon(scontext)) {
+            fprintf(stderr, "Could not set exec context to %s.\n",
+                scontext);
+            free(display);
+            exit(-1);
+        }
+
+        if (display)
+            rc |= setenv("DISPLAY", display, 1);
+        rc |= setenv("HOME", pwd->pw_dir, 1);
+        rc |= setenv("SHELL", pwd->pw_shell, 1);
+        rc |= setenv("USER", pwd->pw_name, 1);
+        rc |= setenv("LOGNAME", pwd->pw_name, 1);
+        rc |= setenv("PATH", DEFAULT_PATH, 1);
+        
+        if (chdir(pwd->pw_dir)) {
+            perror("Failed to change dir to homedir");
+            exit(-1);
+        }
+        setsid();

policycoreutils/sandbox/seunshare.c

Quoted 10 lines
policycoreutils/sandbox/seunshare.c new file +10 -0
+        execv(argv[optind], argv + optind);
+        free(display);
+        perror("execv");
+        exit(-1);
+    } else {
+        waitpid(child, &status, 0);
+    }
+
+    return status;
+}

Thanks for submitting this. I'm think it will be great to get it upstream, as it's such a useful utility. I'd be happy to help out with any changes to it that are necessary once I understand a few of the things I asked about. Just let me know.

Chad Sellers

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.