7eb3b23
--- util-linux-2.13-pre6/disk-utils/mkswap.c.selinux	2005-08-14 17:34:49.000000000 +0200
7eb3b23
+++ util-linux-2.13-pre6/disk-utils/mkswap.c	2006-03-08 16:35:08.000000000 +0100
7eb3b23
@@ -39,6 +39,12 @@
5896f9a
 #include <sys/ioctl.h>		/* for _IO */
5896f9a
 #include <sys/utsname.h>
5896f9a
 #include <sys/stat.h>
5896f9a
+#include <errno.h>
7eb3b23
+#ifdef HAVE_LIBSELINUX
5896f9a
+#include <selinux/selinux.h>
7eb3b23
+#include <selinux/context.h>
7eb3b23
+#endif
7eb3b23
+
5896f9a
 #include "swapheader.h"
5896f9a
 #include "xstrncpy.h"
5896f9a
 #include "nls.h"
7eb3b23
@@ -76,6 +82,8 @@
5896f9a
 
5896f9a
 #define MAKE_VERSION(p,q,r)	(65536*(p) + 256*(q) + (r))
5896f9a
 
7eb3b23
+#define SELINUX_SWAPFILE_TYPE	"swapfile_t"
5896f9a
+
5896f9a
 static int
5896f9a
 linux_version_code(void) {
5896f9a
 	struct utsname my_utsname;
7eb3b23
@@ -718,5 +726,39 @@
5896f9a
 	if (fsync(DEV))
5896f9a
 		 die(_("fsync failed"));
5896f9a
 #endif
5896f9a
+
7eb3b23
+#ifdef HAVE_LIBSELINUX
7eb3b23
+	if (S_ISREG(statbuf.st_mode) && is_selinux_enabled()) {
7eb3b23
+		security_context_t context_string;
7eb3b23
+		security_context_t oldcontext;
7eb3b23
+		context_t newcontext;
5896f9a
+
7eb3b23
+		if ((fgetfilecon(DEV, &oldcontext) < 0) && 
7eb3b23
+		    (errno != ENODATA)) {
bd3a2b8
+			fprintf(stderr, _("%s: %s: unable to obtain selinux file label: %s\n"),
7eb3b23
+					program_name, device_name, 
7eb3b23
+					strerror(errno));
7eb3b23
+			exit(1);
5896f9a
+		}
7eb3b23
+		if (!(newcontext = context_new(oldcontext)))
7eb3b23
+			die(_("unable to create new selinux context"));
7eb3b23
+		if (context_type_set(newcontext, SELINUX_SWAPFILE_TYPE))
7eb3b23
+			die(_("couldn't compute selinux context"));
7eb3b23
+		
7eb3b23
+		context_string = context_str(newcontext);
7eb3b23
+		
7eb3b23
+		if (strcmp(context_string, oldcontext)!=0) {
7eb3b23
+			if (fsetfilecon(DEV, context_string)) {
bd3a2b8
+				fprintf(stderr, _("%s: unable to relabel %s to %s: %s\n"),
5896f9a
+						program_name, device_name, 
7eb3b23
+						context_string,
5896f9a
+						strerror(errno));
5896f9a
+				exit(1);
5896f9a
+			}
5896f9a
+		}
7eb3b23
+		context_free(newcontext);
7eb3b23
+		freecon(oldcontext);
5896f9a
+	}
7eb3b23
+#endif
5896f9a
 	return 0;
5896f9a
 }
7eb3b23
--- util-linux-2.13-pre6/disk-utils/Makefile.am.selinux	2005-09-10 19:46:10.000000000 +0200
7eb3b23
+++ util-linux-2.13-pre6/disk-utils/Makefile.am	2006-03-08 16:27:03.000000000 +0100
7eb3b23
@@ -30,6 +30,13 @@
7eb3b23
 mkfs_cramfs_LDADD = -lz $(top_srcdir)/lib/libmd5.a
5896f9a
 endif
5896f9a
 
7eb3b23
+mkswap_LDADD =
7eb3b23
+
5896f9a
 if HAVE_UUID
5896f9a
-mkswap_LDADD = -luuid
7eb3b23
+mkswap_LDADD += -luuid
7eb3b23
+endif
7eb3b23
+
7eb3b23
+if HAVE_SELINUX
7eb3b23
+mkswap_LDADD += -lselinux
5896f9a
 endif
7eb3b23
+