util-linux/util-linux-2.13-mkswap-selinux.patch

82 lines
2.1 KiB
Diff
Raw Normal View History

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