1 - mkswap should automatically add selinux label to swapfile
3 --- util-linux-2.13-pre6/disk-utils/mkswap.c.selinux 2005-08-14 17:34:49.000000000 +0200
4 +++ util-linux-2.13-pre6/disk-utils/mkswap.c 2006-03-08 16:35:08.000000000 +0100
6 #include <sys/ioctl.h> /* for _IO */
7 #include <sys/utsname.h>
10 +#ifdef HAVE_LIBSELINUX
11 +#include <selinux/selinux.h>
12 +#include <selinux/context.h>
15 #include "swapheader.h"
20 #define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r))
22 +#define SELINUX_SWAPFILE_TYPE "swapfile_t"
25 linux_version_code(void) {
26 struct utsname my_utsname;
29 die(_("fsync failed"));
32 +#ifdef HAVE_LIBSELINUX
33 + if (S_ISREG(statbuf.st_mode) && is_selinux_enabled()) {
34 + security_context_t context_string;
35 + security_context_t oldcontext;
36 + context_t newcontext;
38 + if ((fgetfilecon(DEV, &oldcontext) < 0) &&
39 + (errno != ENODATA)) {
40 + fprintf(stderr, _("%s: %s: unable to obtain selinux file label: %s\n"),
41 + program_name, device_name,
45 + if (!(newcontext = context_new(oldcontext)))
46 + die(_("unable to create new selinux context"));
47 + if (context_type_set(newcontext, SELINUX_SWAPFILE_TYPE))
48 + die(_("couldn't compute selinux context"));
50 + context_string = context_str(newcontext);
52 + if (strcmp(context_string, oldcontext)!=0) {
53 + if (fsetfilecon(DEV, context_string)) {
54 + fprintf(stderr, _("%s: unable to relabel %s to %s: %s\n"),
55 + program_name, device_name,
61 + context_free(newcontext);
62 + freecon(oldcontext);
67 --- util-linux-2.13-pre6/disk-utils/Makefile.am.selinux 2005-09-10 19:46:10.000000000 +0200
68 +++ util-linux-2.13-pre6/disk-utils/Makefile.am 2006-03-08 16:27:03.000000000 +0100
70 mkfs_cramfs_LDADD = -lz $(top_srcdir)/lib/libmd5.a
76 -mkswap_LDADD = -luuid
77 +mkswap_LDADD += -luuid
81 +mkswap_LDADD += -lselinux