2012-10-18 16:24:00 +00:00
|
|
|
diff -up patch-2.7/src/common.h.selinux patch-2.7/src/common.h
|
|
|
|
--- patch-2.7/src/common.h.selinux 2012-04-17 21:13:36.000000000 +0100
|
|
|
|
+++ patch-2.7/src/common.h 2012-10-18 17:04:21.215420195 +0100
|
|
|
|
@@ -30,6 +30,8 @@
|
2009-02-17 15:36:59 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <time.h>
|
2007-10-04 16:05:37 +00:00
|
|
|
|
2009-02-17 15:36:59 +00:00
|
|
|
+#include <selinux/selinux.h>
|
|
|
|
+
|
|
|
|
#include <sys/stat.h>
|
2012-10-18 16:24:00 +00:00
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
@@ -80,6 +82,7 @@ XTERN char *outfile;
|
2009-02-17 15:36:59 +00:00
|
|
|
XTERN int inerrno;
|
|
|
|
XTERN int invc;
|
|
|
|
XTERN struct stat instat;
|
|
|
|
+XTERN security_context_t incontext;
|
|
|
|
XTERN bool dry_run;
|
|
|
|
XTERN bool posixly_correct;
|
|
|
|
|
2012-10-18 16:24:00 +00:00
|
|
|
diff -up patch-2.7/src/inp.c.selinux patch-2.7/src/inp.c
|
|
|
|
--- patch-2.7/src/inp.c.selinux 2012-08-07 20:46:33.000000000 +0100
|
|
|
|
+++ patch-2.7/src/inp.c 2012-10-18 17:18:31.335799300 +0100
|
|
|
|
@@ -138,7 +138,22 @@ get_input_file (char const *filename, ch
|
2008-06-12 10:14:43 +00:00
|
|
|
char *getbuf;
|
|
|
|
|
2012-10-18 16:24:00 +00:00
|
|
|
if (inerrno == -1)
|
|
|
|
- inerrno = lstat (filename, &instat) == 0 ? 0 : errno;
|
2008-06-12 10:14:43 +00:00
|
|
|
+ {
|
2012-10-18 16:24:00 +00:00
|
|
|
+ inerrno = lstat (filename, &instat) == 0 ? 0 : errno;
|
|
|
|
+ if (inerrno == 0)
|
|
|
|
+ {
|
|
|
|
+ inerrno = getfilecon (inname, &incontext) == -1 ? errno : 0;
|
|
|
|
+ if (inerrno == ENODATA || inerrno == ENOTSUP)
|
|
|
|
+ {
|
|
|
|
+ inerrno = 0;
|
|
|
|
+ incontext = NULL;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ incontext = NULL;
|
2008-06-12 10:14:43 +00:00
|
|
|
+ }
|
2010-08-16 16:44:01 +00:00
|
|
|
+ else
|
|
|
|
+ incontext = NULL;
|
2008-06-12 10:14:43 +00:00
|
|
|
|
|
|
|
/* Perhaps look for RCS or SCCS versions. */
|
2012-10-18 16:24:00 +00:00
|
|
|
if (S_ISREG (mode)
|
|
|
|
@@ -183,7 +198,7 @@ get_input_file (char const *filename, ch
|
2008-06-12 10:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cs && version_get (filename, cs, ! inerrno, elsewhere, getbuf,
|
|
|
|
- &instat))
|
|
|
|
+ &instat, &incontext))
|
|
|
|
inerrno = 0;
|
|
|
|
|
|
|
|
free (getbuf);
|
2012-10-18 16:24:00 +00:00
|
|
|
@@ -194,6 +209,7 @@ get_input_file (char const *filename, ch
|
2008-06-12 10:14:43 +00:00
|
|
|
{
|
|
|
|
instat.st_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
|
|
|
|
instat.st_size = 0;
|
|
|
|
+ incontext = NULL;
|
|
|
|
}
|
2012-10-18 16:24:00 +00:00
|
|
|
else if (! ((S_ISREG (mode) || S_ISLNK (mode))
|
|
|
|
&& (mode & S_IFMT) == (instat.st_mode & S_IFMT)))
|
|
|
|
diff -up patch-2.7/src/Makefile.am.selinux patch-2.7/src/Makefile.am
|
|
|
|
--- patch-2.7/src/Makefile.am.selinux 2012-04-17 08:59:41.000000000 +0100
|
|
|
|
+++ patch-2.7/src/Makefile.am 2012-10-18 17:04:21.216420199 +0100
|
|
|
|
@@ -34,7 +34,7 @@ patch_SOURCES = \
|
|
|
|
|
|
|
|
AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
|
|
|
|
patch_LDADD = $(LDADD) $(top_builddir)/lib/libpatch.a $(LIB_CLOCK_GETTIME) \
|
|
|
|
- $(LIB_XATTR)
|
|
|
|
+ $(LIB_XATTR) -lselinux
|
|
|
|
|
|
|
|
if ENABLE_MERGE
|
|
|
|
patch_SOURCES += merge.c
|
|
|
|
diff -up patch-2.7/src/Makefile.in.selinux patch-2.7/src/Makefile.in
|
|
|
|
--- patch-2.7/src/Makefile.in.selinux 2012-09-12 02:40:57.000000000 +0100
|
|
|
|
+++ patch-2.7/src/Makefile.in 2012-10-18 17:04:21.217420203 +0100
|
|
|
|
@@ -989,7 +989,7 @@ patch_SOURCES = bestmatch.h common.h inp
|
|
|
|
AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib \
|
|
|
|
$(am__append_2)
|
|
|
|
patch_LDADD = $(LDADD) $(top_builddir)/lib/libpatch.a $(LIB_CLOCK_GETTIME) \
|
|
|
|
- $(LIB_XATTR)
|
|
|
|
+ $(LIB_XATTR) -lselinux
|
|
|
|
|
|
|
|
all: all-am
|
|
|
|
|
|
|
|
diff -up patch-2.7/src/patch.c.selinux patch-2.7/src/patch.c
|
|
|
|
--- patch-2.7/src/patch.c.selinux 2012-08-08 12:24:46.000000000 +0100
|
|
|
|
+++ patch-2.7/src/patch.c 2012-10-18 17:04:21.219420213 +0100
|
|
|
|
@@ -552,7 +552,7 @@ main (int argc, char **argv)
|
|
|
|
mode, &new_time);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
- attr |= FA_IDS | FA_MODE | FA_XATTRS;
|
|
|
|
+ attr |= FA_IDS | FA_MODE | FA_XATTRS | FA_SECCONTEXT;
|
|
|
|
set_file_attributes (TMPOUTNAME, attr, inname, &instat,
|
|
|
|
mode, &new_time);
|
2009-11-16 17:08:44 +00:00
|
|
|
}
|
2012-10-18 16:24:00 +00:00
|
|
|
diff -up patch-2.7/src/pch.c.selinux patch-2.7/src/pch.c
|
|
|
|
--- patch-2.7/src/pch.c.selinux 2012-08-11 09:19:49.000000000 +0100
|
|
|
|
+++ patch-2.7/src/pch.c 2012-10-18 17:04:21.220420217 +0100
|
|
|
|
@@ -295,7 +295,12 @@ there_is_another_patch (bool need_header
|
2009-11-16 17:08:44 +00:00
|
|
|
inname[t - buf - 1] = 0;
|
2012-10-18 16:24:00 +00:00
|
|
|
if (lstat (inname, &instat) == 0)
|
2007-10-04 16:05:37 +00:00
|
|
|
{
|
|
|
|
- inerrno = 0;
|
2008-06-12 10:14:43 +00:00
|
|
|
+ inerrno = getfilecon (inname, &incontext) == -1 ? errno : 0;
|
2012-10-18 16:24:00 +00:00
|
|
|
+ if (errno == ENODATA || inerrno == ENOTSUP)
|
2007-10-04 16:05:37 +00:00
|
|
|
+ {
|
|
|
|
+ inerrno = 0;
|
|
|
|
+ incontext = NULL;
|
|
|
|
+ }
|
|
|
|
invc = -1;
|
|
|
|
}
|
|
|
|
else
|
2012-10-18 16:24:00 +00:00
|
|
|
@@ -927,7 +932,7 @@ intuit_diff_type (bool need_header, mode
|
2007-10-04 16:05:37 +00:00
|
|
|
if (cs)
|
|
|
|
{
|
2009-11-16 17:08:44 +00:00
|
|
|
if (version_get (p_name[i], cs, false, readonly,
|
2007-10-04 16:05:37 +00:00
|
|
|
- getbuf, &st[i]))
|
|
|
|
+ getbuf, &st[i], NULL))
|
|
|
|
stat_errno[i] = 0;
|
|
|
|
else
|
|
|
|
version_controlled[i] = 0;
|
2012-10-18 16:24:00 +00:00
|
|
|
@@ -993,6 +998,9 @@ intuit_diff_type (bool need_header, mode
|
|
|
|
inerrno = stat_errno[i];
|
2008-06-12 10:14:43 +00:00
|
|
|
invc = version_controlled[i];
|
|
|
|
instat = st[i];
|
2011-05-04 14:56:54 +00:00
|
|
|
+ if (getfilecon (inname, &incontext) == -1)
|
|
|
|
+ if (errno == ENODATA || errno == ENOTSUP)
|
2011-11-25 18:07:08 +00:00
|
|
|
+ incontext = NULL;
|
2008-06-12 10:14:43 +00:00
|
|
|
}
|
|
|
|
|
2009-11-16 17:08:44 +00:00
|
|
|
return retval;
|
2012-10-18 16:24:00 +00:00
|
|
|
diff -up patch-2.7/src/util.c.selinux patch-2.7/src/util.c
|
|
|
|
--- patch-2.7/src/util.c.selinux 2012-08-11 09:20:49.000000000 +0100
|
|
|
|
+++ patch-2.7/src/util.c 2012-10-18 17:20:25.397226771 +0100
|
|
|
|
@@ -291,6 +291,19 @@ set_file_attributes (char const *to, enu
|
|
|
|
S_ISLNK (mode) ? "symbolic link" : "file",
|
|
|
|
quotearg (to));
|
|
|
|
}
|
|
|
|
+ if (attr & FA_SECCONTEXT)
|
|
|
|
+ {
|
|
|
|
+ security_context_t outcontext;
|
|
|
|
+ if (incontext && getfilecon (to, &outcontext) != -1 &&
|
|
|
|
+ outcontext &&
|
|
|
|
+ strcmp (outcontext, incontext) &&
|
|
|
|
+ setfilecon (to, incontext) != 0)
|
|
|
|
+ {
|
|
|
|
+ if (errno != ENOTSUP && errno != EPERM)
|
|
|
|
+ pfatal ("Can't set security context on file %s",
|
|
|
|
+ quotearg (to));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
@@ -807,7 +820,8 @@ version_controller (char const *filename
|
2009-11-16 17:08:44 +00:00
|
|
|
Return true if successful. */
|
|
|
|
bool
|
|
|
|
version_get (char const *filename, char const *cs, bool exists, bool readonly,
|
2009-02-17 15:36:59 +00:00
|
|
|
- char const *getbuf, struct stat *filestat)
|
|
|
|
+ char const *getbuf, struct stat *filestat,
|
|
|
|
+ security_context_t *filecontext)
|
|
|
|
{
|
|
|
|
if (patch_get < 0)
|
|
|
|
{
|
2012-10-18 16:24:00 +00:00
|
|
|
@@ -832,6 +846,13 @@ version_get (char const *filename, char
|
2009-02-17 15:36:59 +00:00
|
|
|
fatal ("Can't get file %s from %s", quotearg (filename), cs);
|
|
|
|
if (stat (filename, filestat) != 0)
|
|
|
|
pfatal ("%s", quotearg (filename));
|
|
|
|
+ if (filecontext && getfilecon (filename, filecontext) == -1)
|
|
|
|
+ {
|
|
|
|
+ if (errno == ENODATA || errno == ENOTSUP)
|
|
|
|
+ *filecontext = NULL;
|
|
|
|
+ else
|
|
|
|
+ pfatal ("%s", quotearg (filename));
|
|
|
|
+ }
|
|
|
|
}
|
2008-06-12 10:14:43 +00:00
|
|
|
|
2009-02-17 15:36:59 +00:00
|
|
|
return 1;
|
2012-10-18 16:24:00 +00:00
|
|
|
diff -up patch-2.7/src/util.h.selinux patch-2.7/src/util.h
|
|
|
|
--- patch-2.7/src/util.h.selinux 2012-08-11 09:20:01.000000000 +0100
|
|
|
|
+++ patch-2.7/src/util.h 2012-10-18 17:04:21.220420217 +0100
|
|
|
|
@@ -45,7 +45,7 @@ char *parse_name (char const *, int, cha
|
2009-11-16 17:08:44 +00:00
|
|
|
char *savebuf (char const *, size_t);
|
|
|
|
char *savestr (char const *);
|
|
|
|
char const *version_controller (char const *, bool, struct stat const *, char **, char **);
|
|
|
|
-bool version_get (char const *, char const *, bool, bool, char const *, struct stat *);
|
|
|
|
+bool version_get (char const *, char const *, bool, bool, char const *, struct stat *, security_context_t *);
|
|
|
|
int create_file (char const *, int, mode_t, bool);
|
|
|
|
int systemic (char const *);
|
2012-10-18 16:24:00 +00:00
|
|
|
char *format_linenum (char[LINENUM_LENGTH_BOUND + 1], lin);
|
|
|
|
@@ -73,7 +73,8 @@ enum file_attributes {
|
|
|
|
FA_TIMES = 1,
|
|
|
|
FA_IDS = 2,
|
|
|
|
FA_MODE = 4,
|
|
|
|
- FA_XATTRS = 8
|
|
|
|
+ FA_XATTRS = 8,
|
|
|
|
+ FA_SECCONTEXT = 16
|
|
|
|
};
|
|
|
|
|
|
|
|
void set_file_attributes (char const *, enum file_attributes, char const *,
|