[PATCH] make SELinux optional for pyblock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Patch attached (only "does it compile" tested on a non-SELinux box -
no testing at all on an SELinux box).
-- 
Matt Wilson
Founding Engineer
rPath, Inc.
msw@xxxxxxxxx
? pyblock.patch
? pyblock.path
Index: Makefile
===================================================================
RCS file: /usr/local/CVS/pyblock/Makefile,v
retrieving revision 1.25
diff -u -r1.25 Makefile
--- Makefile	23 Feb 2006 03:20:01 -0000	1.25
+++ Makefile	7 Mar 2006 01:34:52 -0000
@@ -8,13 +8,18 @@
 LDFLAGS := -shared
 
 VERSION = 0.15
+USESELINUX = 1
 
 bdevid_LIBS = z
-dm_LIBS = dmraid devmapper selinux
+dm_LIBS = dmraid devmapper
+ifeq (1, $(USESELINUX))
+dm_LIBS += selinux
+CFLAGS += -DUSESELINUX=1
+endif
 dmraid_LIBS = dmraid devmapper
 
 PYFILES=__init__.py maps.py device.py
-LIBS = dmmodule.so dmraidmodule.so bdevidmodule.so
+LIBS = dmmodule.so dmraidmodule.so bdevidmodule.so 
 
 all : $(LIBS)
 
Index: dm.c
===================================================================
RCS file: /usr/local/CVS/pyblock/dm.c,v
retrieving revision 1.39
diff -u -r1.39 dm.c
--- dm.c	13 Feb 2006 23:15:38 -0000	1.39
+++ dm.c	7 Mar 2006 01:34:52 -0000
@@ -14,7 +14,9 @@
 #include <stddef.h>
 
 #include <libdevmapper.h>
+#ifdef USESELINUX
 #include <selinux/selinux.h>
+#endif
 
 #define ARGHA _POSIX_C_SOURCE
 #undef _POSIX_C_SOURCE
@@ -39,10 +41,12 @@
 {
 	self->dev = 0;
 	self->mode = 0600;
+#ifdef USESELINUX
 	if (self->con) {
 		free(self->con);
 		self->con = NULL;
 	}
+#endif
 }
 
 static void
@@ -96,6 +100,7 @@
 		dev->dev = sr.st_rdev;
 		dev->mode = sr.st_mode & ~S_IFMT;
 
+#ifdef USESELINUX
 		if (is_selinux_enabled()) {
 			security_context_t con;
 			if (getfilecon(path, &con) < 0) {
@@ -104,6 +109,7 @@
 			dev->con = strdup(con);
 		}
 		return 0;
+#endif
 	}
 	if (devno != -1)
 		dev->dev = devno;
@@ -155,12 +161,16 @@
 static PyObject *
 pydm_dev_mknod(PyObject *self, PyObject *args, PyObject *kwds)
 {
+#ifdef USESELINUX
 	char *kwlist[] = {"path", "mode", "context", NULL};
+	security_context_t con = NULL;
+#else
+	char *kwlist[] = {"path", "mode", NULL};
+#endif
 	PydmDeviceObject *dev = (PydmDeviceObject *)self;
 	char *path = NULL, *subpath;
 	long long llmode = 0600;
 	mode_t mode;
-	security_context_t con = NULL;
 	int rc;
 
 	if (dev->dev == 0) {
@@ -168,9 +178,15 @@
 		return NULL;
 	}
 
+#ifdef USESELINUX
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|O&s:device.mknod",
 			kwlist, &path, pyblock_potoll, &llmode, &con))
 		return NULL;
+#else
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|O&:device.mknod",
+			kwlist, &path, pyblock_potoll, &llmode))
+		return NULL;
+#endif
 
 	mode = llmode;
 	if (mode < 0)
@@ -216,6 +232,7 @@
 		return NULL;
 	}
 
+#ifdef USESELINUX
 	if (!is_selinux_enabled()) {
 		Py_INCREF(Py_None);
 		return Py_None;
@@ -233,6 +250,7 @@
 		pyblock_PyErr_Format(PyExc_OSError, "path: %s context: %s\n", path, con);
 		return NULL;
 	}
+#endif
 
 	Py_INCREF(Py_None);
 	return Py_None;
@@ -266,12 +284,15 @@
 		return PyLong_FromUnsignedLongLong(dev->dev);
 	} else if (!strcmp(attr, "mode")) {
 		return PyLong_FromUnsignedLongLong(dev->mode);
-	} else if (!strcmp(attr, "context")) {
+	}
+#ifdef USESELINUX
+	else if (!strcmp(attr, "context")) {
 		if (dev->con)
 			return PyString_FromString(dev->con);
 		else
 			return PyString_FromString("");
 	}
+#endif
 
 	return NULL;
 }
@@ -303,7 +324,9 @@
 			return -1;
 
 		dev->mode = v & ~S_IFMT;
-	} else if (!strcmp(attr, "context")) {
+	}
+#ifdef USESELINUX
+	else if (!strcmp(attr, "context")) {
 		char *context = PyString_AsString(value);
 		security_context_t con = NULL;
 
@@ -320,7 +343,7 @@
 			free(dev->con);
 		dev->con = con;
 	}
-
+#endif
 	return 0;
 }
 
@@ -333,8 +356,10 @@
 		"dev", "dev"},
 	{"mode", (getter)pydm_dev_get, (setter)pydm_dev_set,
 		"mode", "mode"},
+#ifdef USESELINUX
 	{"context", (getter)pydm_dev_get, (setter)pydm_dev_set,
 		"context", "context"},
+#endif
 	{NULL},
 };
 
Index: dm.h
===================================================================
RCS file: /usr/local/CVS/pyblock/dm.h,v
retrieving revision 1.10
diff -u -r1.10 dm.h
--- dm.h	28 Jan 2006 16:05:57 -0000	1.10
+++ dm.h	7 Mar 2006 01:34:52 -0000
@@ -8,13 +8,17 @@
 #define PYBLOCK_DM_H 1
 
 #include <libdevmapper.h>
+#ifdef USESELINUX
 #include <selinux/selinux.h>
+#endif
 
 typedef struct {
 	PyObject_HEAD
 
 	dev_t dev;
+#ifdef USESELINUX
 	security_context_t con;
+#endif
 	mode_t mode;
 } PydmDeviceObject;
 

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux