From: Michael Albinus Date: Wed, 28 Apr 2010 18:42:20 +0000 (+0200) Subject: * net/tramp.el (tramp-remote-selinux-p): New defun. X-Git-Tag: emacs-pretest-24.0.90~104^2~275^2~438^2~349 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7ba947016008a5fcee64eb8660d688afb4414b96;p=emacs.git * net/tramp.el (tramp-remote-selinux-p): New defun. (tramp-handle-file-selinux-context) (tramp-handle-set-file-selinux-context): Use it. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3eba70f40af..649fa409ff4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2010-04-28 Michael Albinus + + * 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 * progmodes/bug-reference.el (bug-reference-url-format): Mark as diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index a4442e9b54b..f82ecddc3c4 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3030,6 +3030,17 @@ and gid of the corresponding user is taken. Both parameters must be integers." "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 @@ and gid of the corresponding user is taken. Both parameters must be integers." (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 @@ and gid of the corresponding user is taken. Both parameters must be integers." "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 @@ process to set up. VEC specifies the connection." (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 @@ Only works for Bourne-like shells." ;; 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