]> git.pld-linux.org Git - packages/util-linux.git/blob - util-linux-mkswap-selinux.patch
- pass --enable-login-chown-vcs to configure
[packages/util-linux.git] / util-linux-mkswap-selinux.patch
1 - mkswap should automatically add selinux label to swapfile
2
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
5 @@ -39,6 +39,12 @@
6  #include <sys/ioctl.h>         /* for _IO */
7  #include <sys/utsname.h>
8  #include <sys/stat.h>
9 +#include <errno.h>
10 +#ifdef HAVE_LIBSELINUX
11 +#include <selinux/selinux.h>
12 +#include <selinux/context.h>
13 +#endif
14 +
15  #include "swapheader.h"
16  #include "xstrncpy.h"
17  #include "nls.h"
18 @@ -76,6 +82,8 @@
19  
20  #define MAKE_VERSION(p,q,r)    (65536*(p) + 256*(q) + (r))
21  
22 +#define SELINUX_SWAPFILE_TYPE  "swapfile_t"
23 +
24  static int
25  linux_version_code(void) {
26         struct utsname my_utsname;
27 @@ -718,5 +726,39 @@
28         if (fsync(DEV))
29                  die(_("fsync failed"));
30  #endif
31 +
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;
37 +
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, 
42 +                                       strerror(errno));
43 +                       exit(1);
44 +               }
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"));
49 +               
50 +               context_string = context_str(newcontext);
51 +               
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, 
56 +                                               context_string,
57 +                                               strerror(errno));
58 +                               exit(1);
59 +                       }
60 +               }
61 +               context_free(newcontext);
62 +               freecon(oldcontext);
63 +       }
64 +#endif
65         return 0;
66  }
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
69 @@ -30,6 +30,13 @@
70  mkfs_cramfs_LDADD = -lz $(top_srcdir)/lib/libmd5.a
71  endif
72  
73 +mkswap_LDADD =
74 +
75  if HAVE_UUID
76 -mkswap_LDADD = -luuid
77 +mkswap_LDADD += -luuid
78 +endif
79 +
80 +if HAVE_SELINUX
81 +mkswap_LDADD += -lselinux
82  endif
83 +
This page took 0.222265 seconds and 3 git commands to generate.