Karsten Hopp 45ca85
To: vim-dev@vim.org
Karsten Hopp 45ca85
Subject: Patch 7.1.296
Karsten Hopp 45ca85
Fcc: outbox
Karsten Hopp 45ca85
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 45ca85
Mime-Version: 1.0
Karsten Hopp 45ca85
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp 45ca85
Content-Transfer-Encoding: 8bit
Karsten Hopp 45ca85
------------
Karsten Hopp 45ca85
Karsten Hopp 45ca85
Patch 7.1.296
Karsten Hopp 45ca85
Problem:    SELinux is not supported.
Karsten Hopp 45ca85
Solution:   Detect the selinux library and use mch_copy_sec(). (James Vega)
Karsten Hopp 45ca85
Files:	    src/auto/configure, src/config.h.in, src/configure.in,
Karsten Hopp 45ca85
	    src/fileio.c, src/memfile.c, src/os_unix.c, src/proto/os_unix.pro
Karsten Hopp 45ca85
Karsten Hopp 45ca85
Karsten Hopp 45ca85
*** ../vim-7.1.295/src/auto/configure	Wed Feb 20 12:43:05 2008
Karsten Hopp 45ca85
--- src/auto/configure	Wed May  7 18:16:09 2008
Karsten Hopp 45ca85
***************
Karsten Hopp 45ca85
*** 845,850 ****
Karsten Hopp 45ca85
--- 845,851 ----
Karsten Hopp 45ca85
    --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
Karsten Hopp 45ca85
    --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
Karsten Hopp 45ca85
    --disable-darwin        Disable Darwin (Mac OS X) support.
Karsten Hopp 45ca85
+   --disable-selinux	  Don't check for SELinux support.
Karsten Hopp 45ca85
    --disable-xsmp          Disable XSMP session management
Karsten Hopp 45ca85
    --disable-xsmp-interact Disable XSMP interaction
Karsten Hopp 45ca85
    --enable-mzschemeinterp   Include MzScheme interpreter.
Karsten Hopp 45ca85
***************
Karsten Hopp 45ca85
*** 3611,3616 ****
Karsten Hopp 45ca85
--- 3612,3705 ----
Karsten Hopp 45ca85
  esac
Karsten Hopp 45ca85
  fi
Karsten Hopp 45ca85
  
Karsten Hopp 45ca85
+ echo "$as_me:$LINENO: checking --disable-selinux argument" >&5
Karsten Hopp 45ca85
+ echo $ECHO_N "checking --disable-selinux argument... $ECHO_C" >&6
Karsten Hopp 45ca85
+ # Check whether --enable-selinux or --disable-selinux was given.
Karsten Hopp 45ca85
+ if test "${enable_selinux+set}" = set; then
Karsten Hopp 45ca85
+   enableval="$enable_selinux"
Karsten Hopp 45ca85
+ 
Karsten Hopp 45ca85
+ else
Karsten Hopp 45ca85
+   enable_selinux="yes"
Karsten Hopp 45ca85
+ fi;
Karsten Hopp 45ca85
+ if test "$enable_selinux" = "yes"; then
Karsten Hopp 45ca85
+   echo "$as_me:$LINENO: result: no" >&5
Karsten Hopp 45ca85
+ echo "${ECHO_T}no" >&6
Karsten Hopp 45ca85
+   echo "$as_me:$LINENO: checking for is_selinux_enabled in -lselinux" >&5
Karsten Hopp 45ca85
+ echo $ECHO_N "checking for is_selinux_enabled in -lselinux... $ECHO_C" >&6
Karsten Hopp 45ca85
+ if test "${ac_cv_lib_selinux_is_selinux_enabled+set}" = set; then
Karsten Hopp 45ca85
+   echo $ECHO_N "(cached) $ECHO_C" >&6
Karsten Hopp 45ca85
+ else
Karsten Hopp 45ca85
+   ac_check_lib_save_LIBS=$LIBS
Karsten Hopp 45ca85
+ LIBS="-lselinux  $LIBS"
Karsten Hopp 45ca85
+ cat >conftest.$ac_ext <<_ACEOF
Karsten Hopp 45ca85
+ /* confdefs.h.  */
Karsten Hopp 45ca85
+ _ACEOF
Karsten Hopp 45ca85
+ cat confdefs.h >>conftest.$ac_ext
Karsten Hopp 45ca85
+ cat >>conftest.$ac_ext <<_ACEOF
Karsten Hopp 45ca85
+ /* end confdefs.h.  */
Karsten Hopp 45ca85
+ 
Karsten Hopp 45ca85
+ /* Override any gcc2 internal prototype to avoid an error.  */
Karsten Hopp 45ca85
+ #ifdef __cplusplus
Karsten Hopp 45ca85
+ extern "C"
Karsten Hopp 45ca85
+ #endif
Karsten Hopp 45ca85
+ /* We use char because int might match the return type of a gcc2
Karsten Hopp 45ca85
+    builtin and then its argument prototype would still apply.  */
Karsten Hopp 45ca85
+ char is_selinux_enabled ();
Karsten Hopp 45ca85
+ int
Karsten Hopp 45ca85
+ main ()
Karsten Hopp 45ca85
+ {
Karsten Hopp 45ca85
+ is_selinux_enabled ();
Karsten Hopp 45ca85
+   ;
Karsten Hopp 45ca85
+   return 0;
Karsten Hopp 45ca85
+ }
Karsten Hopp 45ca85
+ _ACEOF
Karsten Hopp 45ca85
+ rm -f conftest.$ac_objext conftest$ac_exeext
Karsten Hopp 45ca85
+ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
Karsten Hopp 45ca85
+   (eval $ac_link) 2>conftest.er1
Karsten Hopp 45ca85
+   ac_status=$?
Karsten Hopp 45ca85
+   grep -v '^ *+' conftest.er1 >conftest.err
Karsten Hopp 45ca85
+   rm -f conftest.er1
Karsten Hopp 45ca85
+   cat conftest.err >&5
Karsten Hopp 45ca85
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
Karsten Hopp 45ca85
+   (exit $ac_status); } &&
Karsten Hopp 45ca85
+ 	 { ac_try='test -z "$ac_c_werror_flag"
Karsten Hopp 45ca85
+ 			 || test ! -s conftest.err'
Karsten Hopp 45ca85
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
Karsten Hopp 45ca85
+   (eval $ac_try) 2>&5
Karsten Hopp 45ca85
+   ac_status=$?
Karsten Hopp 45ca85
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
Karsten Hopp 45ca85
+   (exit $ac_status); }; } &&
Karsten Hopp 45ca85
+ 	 { ac_try='test -s conftest$ac_exeext'
Karsten Hopp 45ca85
+   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
Karsten Hopp 45ca85
+   (eval $ac_try) 2>&5
Karsten Hopp 45ca85
+   ac_status=$?
Karsten Hopp 45ca85
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
Karsten Hopp 45ca85
+   (exit $ac_status); }; }; then
Karsten Hopp 45ca85
+   ac_cv_lib_selinux_is_selinux_enabled=yes
Karsten Hopp 45ca85
+ else
Karsten Hopp 45ca85
+   echo "$as_me: failed program was:" >&5
Karsten Hopp 45ca85
+ sed 's/^/| /' conftest.$ac_ext >&5
Karsten Hopp 45ca85
+ 
Karsten Hopp 45ca85
+ ac_cv_lib_selinux_is_selinux_enabled=no
Karsten Hopp 45ca85
+ fi
Karsten Hopp 45ca85
+ rm -f conftest.err conftest.$ac_objext \
Karsten Hopp 45ca85
+       conftest$ac_exeext conftest.$ac_ext
Karsten Hopp 45ca85
+ LIBS=$ac_check_lib_save_LIBS
Karsten Hopp 45ca85
+ fi
Karsten Hopp 45ca85
+ echo "$as_me:$LINENO: result: $ac_cv_lib_selinux_is_selinux_enabled" >&5
Karsten Hopp 45ca85
+ echo "${ECHO_T}$ac_cv_lib_selinux_is_selinux_enabled" >&6
Karsten Hopp 45ca85
+ if test $ac_cv_lib_selinux_is_selinux_enabled = yes; then
Karsten Hopp 45ca85
+   LIBS="$LIBS -lselinux"
Karsten Hopp 45ca85
+ 	   cat >>confdefs.h <<\_ACEOF
Karsten Hopp 45ca85
+ #define HAVE_SELINUX 1
Karsten Hopp 45ca85
+ _ACEOF
Karsten Hopp 45ca85
+ 
Karsten Hopp 45ca85
+ fi
Karsten Hopp 45ca85
+ 
Karsten Hopp 45ca85
+ else
Karsten Hopp 45ca85
+    echo "$as_me:$LINENO: result: yes" >&5
Karsten Hopp 45ca85
+ echo "${ECHO_T}yes" >&6
Karsten Hopp 45ca85
+ fi
Karsten Hopp 45ca85
  
Karsten Hopp 45ca85
  
Karsten Hopp 45ca85
  echo "$as_me:$LINENO: checking --with-features argument" >&5
Karsten Hopp 45ca85
*** ../vim-7.1.295/src/config.h.in	Tue May  1 13:37:23 2007
Karsten Hopp 45ca85
--- src/config.h.in	Wed May  7 18:10:49 2008
Karsten Hopp 45ca85
***************
Karsten Hopp 45ca85
*** 156,161 ****
Karsten Hopp 45ca85
--- 156,162 ----
Karsten Hopp 45ca85
  #undef HAVE_READLINK
Karsten Hopp 45ca85
  #undef HAVE_RENAME
Karsten Hopp 45ca85
  #undef HAVE_SELECT
Karsten Hopp 45ca85
+ #undef HAVE_SELINUX
Karsten Hopp 45ca85
  #undef HAVE_SETENV
Karsten Hopp 45ca85
  #undef HAVE_SETPGID
Karsten Hopp 45ca85
  #undef HAVE_SETSID
Karsten Hopp 45ca85
*** ../vim-7.1.295/src/configure.in	Wed Feb 20 12:43:05 2008
Karsten Hopp 45ca85
--- src/configure.in	Wed May  7 18:15:40 2008
Karsten Hopp 45ca85
***************
Karsten Hopp 45ca85
*** 299,304 ****
Karsten Hopp 45ca85
--- 299,317 ----
Karsten Hopp 45ca85
  esac
Karsten Hopp 45ca85
  fi
Karsten Hopp 45ca85
  
Karsten Hopp 45ca85
+ dnl Link with -lselinux for SELinux stuff; if not found
Karsten Hopp 45ca85
+ AC_MSG_CHECKING(--disable-selinux argument)
Karsten Hopp 45ca85
+ AC_ARG_ENABLE(selinux,
Karsten Hopp 45ca85
+ 	[  --disable-selinux	  Don't check for SELinux support.],
Karsten Hopp 45ca85
+ 	, enable_selinux="yes")
Karsten Hopp 45ca85
+ if test "$enable_selinux" = "yes"; then
Karsten Hopp 45ca85
+   AC_MSG_RESULT(no)
Karsten Hopp 45ca85
+   AC_CHECK_LIB(selinux, is_selinux_enabled,
Karsten Hopp 45ca85
+ 	  [LIBS="$LIBS -lselinux"
Karsten Hopp 45ca85
+ 	   AC_DEFINE(HAVE_SELINUX)])
Karsten Hopp 45ca85
+ else
Karsten Hopp 45ca85
+    AC_MSG_RESULT(yes)
Karsten Hopp 45ca85
+ fi
Karsten Hopp 45ca85
  
Karsten Hopp 45ca85
  dnl Check user requested features.
Karsten Hopp 45ca85
  
Karsten Hopp 45ca85
*** ../vim-7.1.295/src/fileio.c	Tue Mar 11 22:01:16 2008
Karsten Hopp 45ca85
--- src/fileio.c	Wed May  7 18:17:45 2008
Karsten Hopp 45ca85
***************
Karsten Hopp 45ca85
*** 3651,3656 ****
Karsten Hopp 45ca85
--- 3660,3668 ----
Karsten Hopp 45ca85
  						)
Karsten Hopp 45ca85
  			    mch_setperm(backup,
Karsten Hopp 45ca85
  					  (perm & 0707) | ((perm & 07) << 3));
Karsten Hopp 45ca85
+ # ifdef HAVE_SELINUX
Karsten Hopp 45ca85
+ 			mch_copy_sec(fname, backup);
Karsten Hopp 45ca85
+ # endif
Karsten Hopp 45ca85
  #endif
Karsten Hopp 45ca85
  
Karsten Hopp 45ca85
  			/*
Karsten Hopp 45ca85
***************
Karsten Hopp 45ca85
*** 3687,3692 ****
Karsten Hopp 45ca85
--- 3699,3707 ----
Karsten Hopp 45ca85
  #ifdef HAVE_ACL
Karsten Hopp 45ca85
  			mch_set_acl(backup, acl);
Karsten Hopp 45ca85
  #endif
Karsten Hopp 45ca85
+ #ifdef HAVE_SELINUX
Karsten Hopp 45ca85
+ 			mch_copy_sec(fname, backup);
Karsten Hopp 45ca85
+ #endif
Karsten Hopp 45ca85
  			break;
Karsten Hopp 45ca85
  		    }
Karsten Hopp 45ca85
  		}
Karsten Hopp 45ca85
***************
Karsten Hopp 45ca85
*** 4309,4314 ****
Karsten Hopp 45ca85
--- 4324,4335 ----
Karsten Hopp 45ca85
      }
Karsten Hopp 45ca85
  #endif
Karsten Hopp 45ca85
  
Karsten Hopp 45ca85
+ #ifdef HAVE_SELINUX
Karsten Hopp 45ca85
+     /* Probably need to set the security context. */
Karsten Hopp 45ca85
+     if (!backup_copy)
Karsten Hopp 45ca85
+ 	mch_copy_sec(backup, wfname);
Karsten Hopp 45ca85
+ #endif
Karsten Hopp 45ca85
+ 
Karsten Hopp 45ca85
  #ifdef UNIX
Karsten Hopp 45ca85
      /* When creating a new file, set its owner/group to that of the original
Karsten Hopp 45ca85
       * file.  Get the new device and inode number. */
Karsten Hopp 45ca85
*** ../vim-7.1.295/src/memfile.c	Fri May 11 20:15:45 2007
Karsten Hopp 45ca85
--- src/memfile.c	Wed May  7 18:10:49 2008
Karsten Hopp 45ca85
***************
Karsten Hopp 45ca85
*** 1346,1350 ****
Karsten Hopp 45ca85
--- 1346,1355 ----
Karsten Hopp 45ca85
  	mfp->mf_ffname = NULL;
Karsten Hopp 45ca85
      }
Karsten Hopp 45ca85
      else
Karsten Hopp 45ca85
+     {
Karsten Hopp 45ca85
+ #ifdef HAVE_SELINUX
Karsten Hopp 45ca85
+ 	mch_copy_sec(fname, mfp->mf_fname);
Karsten Hopp 45ca85
+ #endif
Karsten Hopp 45ca85
  	mch_hide(mfp->mf_fname);    /* try setting the 'hidden' flag */
Karsten Hopp 45ca85
+     }
Karsten Hopp 45ca85
  }
Karsten Hopp 45ca85
*** ../vim-7.1.295/src/os_unix.c	Wed Mar 12 13:16:37 2008
Karsten Hopp 45ca85
--- src/os_unix.c	Wed May  7 18:24:46 2008
Karsten Hopp 45ca85
***************
Karsten Hopp 45ca85
*** 45,50 ****
Karsten Hopp 45ca85
--- 45,55 ----
Karsten Hopp 45ca85
  # include <X11/SM/SMlib.h>
Karsten Hopp 45ca85
  #endif
Karsten Hopp 45ca85
  
Karsten Hopp 45ca85
+ #ifdef HAVE_SELINUX
Karsten Hopp 45ca85
+ # include <selinux/selinux.h>
Karsten Hopp 45ca85
+ static int selinux_enabled = -1;
Karsten Hopp 45ca85
+ #endif
Karsten Hopp 45ca85
+ 
Karsten Hopp 45ca85
  /*
Karsten Hopp 45ca85
   * Use this prototype for select, some include files have a wrong prototype
Karsten Hopp 45ca85
   */
Karsten Hopp 45ca85
***************
Karsten Hopp 45ca85
*** 2557,2562 ****
Karsten Hopp 45ca85
--- 2562,2623 ----
Karsten Hopp 45ca85
  } vim_acl_solaris_T;
Karsten Hopp 45ca85
  # endif
Karsten Hopp 45ca85
  
Karsten Hopp 45ca85
+ #if defined(HAVE_SELINUX) || defined(PROTO)
Karsten Hopp 45ca85
+ /*
Karsten Hopp 45ca85
+  * Copy security info from "from_file" to "to_file".
Karsten Hopp 45ca85
+  */
Karsten Hopp 45ca85
+     void
Karsten Hopp 45ca85
+ mch_copy_sec(from_file, to_file)
Karsten Hopp 45ca85
+     char_u	*from_file;
Karsten Hopp 45ca85
+     char_u	*to_file;
Karsten Hopp 45ca85
+ {
Karsten Hopp 45ca85
+     if (from_file == NULL)
Karsten Hopp 45ca85
+ 	return;
Karsten Hopp 45ca85
+ 
Karsten Hopp 45ca85
+     if (selinux_enabled == -1)
Karsten Hopp 45ca85
+ 	selinux_enabled = is_selinux_enabled();
Karsten Hopp 45ca85
+ 
Karsten Hopp 45ca85
+     if (selinux_enabled > 0)
Karsten Hopp 45ca85
+     {
Karsten Hopp 45ca85
+ 	security_context_t from_context = NULL;
Karsten Hopp 45ca85
+ 	security_context_t to_context = NULL;
Karsten Hopp 45ca85
+ 
Karsten Hopp 45ca85
+ 	if (getfilecon((char *)from_file, &from_context) < 0)
Karsten Hopp 45ca85
+ 	{
Karsten Hopp 45ca85
+ 	    /* If the filesystem doesn't support extended attributes,
Karsten Hopp 45ca85
+ 	       the original had no special security context and the
Karsten Hopp 45ca85
+ 	       target cannot have one either.  */
Karsten Hopp 45ca85
+ 	    if (errno == EOPNOTSUPP)
Karsten Hopp 45ca85
+ 		return;
Karsten Hopp 45ca85
+ 
Karsten Hopp 45ca85
+ 	    MSG_PUTS(_("\nCould not get security context for "));
Karsten Hopp 45ca85
+ 	    msg_outtrans(from_file);
Karsten Hopp 45ca85
+ 	    msg_putchar('\n');
Karsten Hopp 45ca85
+ 	    return;
Karsten Hopp 45ca85
+ 	}
Karsten Hopp 45ca85
+ 	if (getfilecon((char *)to_file, &to_context) < 0)
Karsten Hopp 45ca85
+ 	{
Karsten Hopp 45ca85
+ 	    MSG_PUTS(_("\nCould not get security context for "));
Karsten Hopp 45ca85
+ 	    msg_outtrans(to_file);
Karsten Hopp 45ca85
+ 	    msg_putchar('\n');
Karsten Hopp 45ca85
+ 	    freecon (from_context);
Karsten Hopp 45ca85
+ 	    return ;
Karsten Hopp 45ca85
+ 	}
Karsten Hopp 45ca85
+ 	if (strcmp(from_context, to_context) != 0)
Karsten Hopp 45ca85
+ 	{
Karsten Hopp 45ca85
+ 	    if (setfilecon((char *)to_file, from_context) < 0)
Karsten Hopp 45ca85
+ 	    {
Karsten Hopp 45ca85
+ 		MSG_PUTS(_("\nCould not set security context for "));
Karsten Hopp 45ca85
+ 		msg_outtrans(to_file);
Karsten Hopp 45ca85
+ 		msg_putchar('\n');
Karsten Hopp 45ca85
+ 	    }
Karsten Hopp 45ca85
+ 	}
Karsten Hopp 45ca85
+ 	freecon(to_context);
Karsten Hopp 45ca85
+ 	freecon(from_context);
Karsten Hopp 45ca85
+     }
Karsten Hopp 45ca85
+ }
Karsten Hopp 45ca85
+ #endif /* HAVE_SELINUX */
Karsten Hopp 45ca85
+ 
Karsten Hopp 45ca85
  /*
Karsten Hopp 45ca85
   * Return a pointer to the ACL of file "fname" in allocated memory.
Karsten Hopp 45ca85
   * Return NULL if the ACL is not available for whatever reason.
Karsten Hopp 45ca85
*** ../vim-7.1.295/src/proto/os_unix.pro	Sat May  5 20:23:37 2007
Karsten Hopp 45ca85
--- src/proto/os_unix.pro	Wed May  7 18:25:14 2008
Karsten Hopp 45ca85
***************
Karsten Hopp 45ca85
*** 34,39 ****
Karsten Hopp 45ca85
--- 34,40 ----
Karsten Hopp 45ca85
  void fname_case __ARGS((char_u *name, int len));
Karsten Hopp 45ca85
  long mch_getperm __ARGS((char_u *name));
Karsten Hopp 45ca85
  int mch_setperm __ARGS((char_u *name, long perm));
Karsten Hopp 45ca85
+ void mch_copy_sec __ARGS((char_u *from_file, char_u *to_file));
Karsten Hopp 45ca85
  vim_acl_T mch_get_acl __ARGS((char_u *fname));
Karsten Hopp 45ca85
  void mch_set_acl __ARGS((char_u *fname, vim_acl_T aclent));
Karsten Hopp 45ca85
  void mch_free_acl __ARGS((vim_acl_T aclent));
Karsten Hopp 45ca85
*** ../vim-7.1.295/src/version.c	Wed May  7 17:39:17 2008
Karsten Hopp 45ca85
--- src/version.c	Wed May  7 18:50:01 2008
Karsten Hopp 45ca85
***************
Karsten Hopp 45ca85
*** 668,669 ****
Karsten Hopp 45ca85
--- 673,676 ----
Karsten Hopp 45ca85
  {   /* Add new patch number below this line */
Karsten Hopp 45ca85
+ /**/
Karsten Hopp 45ca85
+     296,
Karsten Hopp 45ca85
  /**/
Karsten Hopp 45ca85
Karsten Hopp 45ca85
-- 
Karsten Hopp 45ca85
Michael: There is no such thing as a dump question.
Karsten Hopp 45ca85
Bernard: Sure there is.  For example "what is a core dump?"
Karsten Hopp 45ca85
Karsten Hopp 45ca85
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 45ca85
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 45ca85
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 45ca85
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///