changeset 108158:94e4a7a7cadf

* net/tramp.el (tramp-remote-selinux-p): New defun. (tramp-handle-file-selinux-context) (tramp-handle-set-file-selinux-context): Use it.
author Michael Albinus <albinus@detlef>
date Wed, 28 Apr 2010 20:42:20 +0200
parents 852f6a14d31e
children 56d11bda8235
files lisp/ChangeLog lisp/net/tramp.el
diffstat 2 files changed, 25 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Wed Apr 28 12:14:41 2010 -0400
+++ b/lisp/ChangeLog	Wed Apr 28 20:42:20 2010 +0200
@@ -1,3 +1,9 @@
+2010-04-28  Michael Albinus  <michael.albinus@gmx.de>
+
+	* net/tramp.el (tramp-remote-selinux-p): New defun.
+	(tramp-handle-file-selinux-context)
+	(tramp-handle-set-file-selinux-context): Use it.
+
 2010-04-28  Sam Steingold  <sds@gnu.org>
 
 	* progmodes/bug-reference.el (bug-reference-url-format): Mark as
--- a/lisp/net/tramp.el	Wed Apr 28 12:14:41 2010 -0400
+++ b/lisp/net/tramp.el	Wed Apr 28 20:42:20 2010 +0200
@@ -3030,6 +3030,17 @@
 	 "chown" nil nil nil
          (format "%d:%d" uid gid) (tramp-shell-quote-argument filename))))))
 
+(defun tramp-remote-selinux-p (vec)
+  "Check, whether SELINUX is enabled on the remote host."
+  (with-connection-property (tramp-get-connection-process vec) "selinux-p"
+    (let ((result (tramp-find-executable
+		   vec "getenforce" (tramp-get-remote-path vec) t t)))
+      (and result
+	   (string-equal
+	    (tramp-send-command-and-read
+	     vec (format "echo \\\"`%S`\\\"" result))
+	    "Enforcing")))))
+
 (defun tramp-handle-file-selinux-context (filename)
   "Like `file-selinux-context' for Tramp files."
   (with-parsed-tramp-file-name filename nil
@@ -3037,11 +3048,12 @@
       (let ((context '(nil nil nil nil))
 	    (regexp (concat "\\([a-z0-9_]+\\):" "\\([a-z0-9_]+\\):"
 			    "\\([a-z0-9_]+\\):" "\\([a-z0-9_]+\\)")))
-	(when (zerop (tramp-send-command-and-check
-		      v (format
-			 "%s -d -Z %s"
-			 (tramp-get-ls-command v)
-			 (tramp-shell-quote-argument localname))))
+	(when (and (tramp-remote-selinux-p v)
+		   (zerop (tramp-send-command-and-check
+			   v (format
+			      "%s -d -Z %s"
+			      (tramp-get-ls-command v)
+			      (tramp-shell-quote-argument localname)))))
 	  (with-current-buffer (tramp-get-connection-buffer v)
 	    (goto-char (point-min))
 	    (when (re-search-forward regexp (tramp-compat-line-end-position) t)
@@ -3054,6 +3066,7 @@
   "Like `set-file-selinux-context' for Tramp files."
   (with-parsed-tramp-file-name filename nil
     (if (and (consp context)
+	     (tramp-remote-selinux-p v)
 	     (zerop (tramp-send-command-and-check
 		     v (format "chcon %s %s %s %s %s"
 			       (if (stringp (nth 0 context))
@@ -6924,7 +6937,7 @@
 	  (tramp-send-command-and-read vec "echo \\\"`uname -sr`\\\""))))
     (when (and (stringp old-uname) (not (string-equal old-uname new-uname)))
       (with-current-buffer (tramp-get-debug-buffer vec)
-	;; Keep the debug buffer
+	;; Keep the debug buffer.
 	(rename-buffer
 	 (generate-new-buffer-name tramp-temp-buffer-name) 'unique)
 	(funcall (symbol-function 'tramp-cleanup-connection) vec)
@@ -8752,7 +8765,6 @@
 ;;   on remote hosts.
 ;; * Use secrets.el for password handling.
 ;; * Load ~/.emacs_SHELLNAME on the remote host for `shell'.
-;; * Implement selinux-context.
 
 ;; Functions for file-name-handler-alist:
 ;; diff-latest-backup-file -- in diff.el