cvsdist 1401a3e
--- vim62/src/configure.in.selinux	2004-01-20 11:34:17.177103792 -0500
cvsdist 1401a3e
+++ vim62/src/configure.in	2004-01-20 11:34:18.507126105 -0500
eb3561f
@@ -195,6 +195,21 @@
cvsdist 1401a3e
 fi
cvsdist 1401a3e
 
cvsdist 1401a3e
 
cvsdist 1401a3e
+dnl vim: set sw=2 tw=78 fo+=l:
cvsdist 1401a3e
+dnl Link with -lselinux for SELinux stuff; if not found
cvsdist 1401a3e
+AC_MSG_CHECKING(--disable-selinux argument)
cvsdist 1401a3e
+AC_ARG_ENABLE(selinux,
cvsdist 1401a3e
+	[  --disable-selinux	  Don't check for SELinux support.],
cvsdist 1401a3e
+	, [enable_selinux="yes"])
cvsdist 1401a3e
+if test "$enable_selinux" = "yes"; then
cvsdist 1401a3e
+   AC_MSG_RESULT(no)
eb3561f
+   AC_CHECK_LIB(selinux, is_selinux_enabled,
eb3561f
+     [LIBS="$LIBS -lselinux"
eb3561f
+      AC_DEFINE(HAVE_SELINUX)])
cvsdist 1401a3e
+else
cvsdist 1401a3e
+   AC_MSG_RESULT(yes)
cvsdist 1401a3e
+fi
cvsdist 1401a3e
+
cvsdist 1401a3e
 dnl Check user requested features.
cvsdist 1401a3e
 
cvsdist 1401a3e
 AC_MSG_CHECKING(--with-features argument)
cvsdist 1401a3e
--- vim62/src/config.h.in.selinux	2003-05-25 12:07:42.000000000 -0400
cvsdist 1401a3e
+++ vim62/src/config.h.in	2004-01-20 11:34:18.507126105 -0500
cvsdist 1401a3e
@@ -155,6 +155,7 @@
cvsdist 1401a3e
 #undef HAVE_READLINK
cvsdist 1401a3e
 #undef HAVE_RENAME
cvsdist 1401a3e
 #undef HAVE_SELECT
cvsdist 1401a3e
+#undef HAVE_SELINUX
cvsdist 1401a3e
 #undef HAVE_SETENV
cvsdist 1401a3e
 #undef HAVE_SETPGID
cvsdist 1401a3e
 #undef HAVE_SETSID
cvsdist 1401a3e
--- vim62/src/fileio.c.selinux	2004-01-20 11:34:16.577093725 -0500
cvsdist 1401a3e
+++ vim62/src/fileio.c	2004-01-20 11:34:18.517126273 -0500
cvsdist 1401a3e
@@ -1,3 +1,4 @@
cvsdist 1401a3e
+
cvsdist 1401a3e
 /* vi:set ts=8 sts=4 sw=4:
cvsdist 1401a3e
  *
cvsdist 1401a3e
  * VIM - Vi IMproved	by Bram Moolenaar
cvsdist 1401a3e
@@ -3079,6 +3080,9 @@
cvsdist 1401a3e
 						)
cvsdist 1401a3e
 			    mch_setperm(backup,
cvsdist 1401a3e
 					  (perm & 0707) | ((perm & 07) << 3));
cvsdist 1401a3e
+#ifdef HAVE_SELINUX
cvsdist a46b9f1
+			mch_copy_sec(fname, backup);
cvsdist 1401a3e
+#endif
cvsdist 1401a3e
 #endif
cvsdist 1401a3e
 
cvsdist 1401a3e
 			/*
cvsdist 1401a3e
@@ -3115,6 +3119,9 @@
cvsdist 1401a3e
 #ifdef HAVE_ACL
cvsdist 1401a3e
 			mch_set_acl(backup, acl);
cvsdist 1401a3e
 #endif
cvsdist 1401a3e
+#ifdef HAVE_SELINUX
cvsdist a46b9f1
+			mch_copy_sec(fname, backup);
cvsdist 1401a3e
+#endif
cvsdist 1401a3e
 			break;
cvsdist 1401a3e
 		    }
cvsdist 1401a3e
 		}
cvsdist 1401a3e
@@ -3719,6 +3726,12 @@
cvsdist 1401a3e
 	mch_set_acl(wfname, acl);
cvsdist 1401a3e
 #endif
cvsdist 1401a3e
 
cvsdist 1401a3e
+#ifdef HAVE_SELINUX
cvsdist 1401a3e
+    /* Probably need to set the security context */
cvsdist 1401a3e
+    if (!backup_copy)
cvsdist 1401a3e
+	mch_copy_sec(backup, wfname);
cvsdist 1401a3e
+#endif
cvsdist 1401a3e
+
cvsdist 1401a3e
 #ifdef UNIX
cvsdist 1401a3e
     /* When creating a new file, set its owner/group to that of the original
cvsdist 1401a3e
      * file.  Get the new device and inode number. */
cvsdist 1401a3e
--- vim62/src/os_unix.c.selinux	2004-01-20 11:34:15.897082317 -0500
cvsdist 1401a3e
+++ vim62/src/os_unix.c	2004-01-20 11:37:54.310746614 -0500
cvsdist 1401a3e
@@ -41,6 +41,10 @@
cvsdist 1401a3e
 # include <X11/SM/SMlib.h>
cvsdist 1401a3e
 #endif
cvsdist 1401a3e
 
cvsdist 1401a3e
+#ifdef HAVE_SELINUX
cvsdist 1401a3e
+#include <selinux/selinux.h>
cvsdist 1401a3e
+static int selinux_enabled=-1;
cvsdist 1401a3e
+#endif
cvsdist 1401a3e
 /*
cvsdist 1401a3e
  * Use this prototype for select, some include files have a wrong prototype
cvsdist 1401a3e
  */
cvsdist 1401a3e
@@ -2279,6 +2283,55 @@
cvsdist 1401a3e
 } vim_acl_solaris_T;
cvsdist 1401a3e
 # endif
cvsdist 1401a3e
 
cvsdist 1401a3e
+mch_copy_sec(from_file, to_file)
cvsdist 1401a3e
+     char_u	*from_file;
cvsdist 1401a3e
+     char_u	*to_file;
cvsdist 1401a3e
+{
cvsdist 1401a3e
+  if (from_file == NULL)
cvsdist 1401a3e
+    return;
cvsdist 1401a3e
+  
cvsdist 1401a3e
+#ifdef HAVE_SELINUX
cvsdist 1401a3e
+  if (selinux_enabled == -1)
cvsdist 1401a3e
+    selinux_enabled = is_selinux_enabled ();
cvsdist 1401a3e
+
cvsdist 1401a3e
+  if (selinux_enabled>0)
cvsdist 1401a3e
+    {
cvsdist 1401a3e
+      security_context_t from_context=NULL;
cvsdist 1401a3e
+      security_context_t to_context=NULL;
cvsdist 1401a3e
+      if (getfilecon (from_file, &from_context) < 0)
cvsdist 1401a3e
+	{
cvsdist 1401a3e
+	  /* If the filesystem doesn't support extended attributes,
cvsdist 1401a3e
+	     the original had no special security context and the
cvsdist 1401a3e
+	     target cannot have one either.  */
cvsdist 1401a3e
+	  if (errno == EOPNOTSUPP)
cvsdist 1401a3e
+	    return ;
cvsdist 1401a3e
+	  
cvsdist 1401a3e
+	  MSG_PUTS(_("\nCould not get security context for "));
cvsdist 1401a3e
+	  msg_outtrans(from_file);
cvsdist 1401a3e
+	  msg_putchar('\n');
cvsdist 1401a3e
+	  return ;
cvsdist 1401a3e
+	}
cvsdist 1401a3e
+      if (getfilecon (to_file, &to_context) < 0)
cvsdist 1401a3e
+	{
cvsdist 1401a3e
+	  MSG_PUTS(_("\nCould not get security context for "));
cvsdist 1401a3e
+	  msg_outtrans(to_file);
cvsdist 1401a3e
+	  msg_putchar('\n');
cvsdist 1401a3e
+	  freecon (from_context);
cvsdist 1401a3e
+	  return ;
cvsdist 1401a3e
+	}
cvsdist 1401a3e
+      if (strcmp(from_context,to_context) != 0 ) {
cvsdist 1401a3e
+	if (setfilecon (to_file, from_context) < 0)
cvsdist 1401a3e
+	  {
cvsdist 1401a3e
+	    MSG_PUTS(_("\nCould not set security context for "));
cvsdist 1401a3e
+	    msg_outtrans(to_file);
cvsdist 1401a3e
+	    msg_putchar('\n');
cvsdist 1401a3e
+	  }
cvsdist 1401a3e
+      }
cvsdist 1401a3e
+      freecon (to_context);
cvsdist 1401a3e
+      freecon (from_context);
cvsdist 1401a3e
+    }
cvsdist 1401a3e
+#endif /* HAVE_SELINUX */
cvsdist 1401a3e
+}
cvsdist 1401a3e
 /*
cvsdist 1401a3e
  * Return a pointer to the ACL of file "fname" in allocated memory.
cvsdist 1401a3e
  * Return NULL if the ACL is not available for whatever reason.