aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2024-02-28 12:05:59 +0800
committerPo Lu2024-02-28 12:05:59 +0800
commitf1db8cf9a0595f7db29b548b38ce98196f36e09b (patch)
treec1d574c97f0612794524cfd7e10f4f7bc2189327
parent6a77355527b2f7f1dca9c2296c2684033c9aa875 (diff)
downloademacs-f1db8cf9a0595f7db29b548b38ce98196f36e09b.tar.gz
emacs-f1db8cf9a0595f7db29b548b38ce98196f36e09b.zip
Lift restrictions on `tramp-androidsu's app data access
* lisp/net/tramp-adb.el (tramp-adb-handle-copy-file): Remove code now unnecessary. * lisp/net/tramp-androidsu.el (tramp-androidsu-mount-global-namespace): New user option. (tramp-androidsu-su-mm-supported): New variable. (tramp-androidsu-maybe-open-connection): Detect whether su supports the -mm option, and provide it if so. (tramp-androidsu-adb-handle-copy-file) (tramp-androidsu-adb-handle-rename-file): Delete functions. (tramp-androidsu-sh-handle-copy-file) (tramp-androidsu-sh-handle-rename-file): New functions. (tramp-androidsu-file-name-handler-alist): Switch to tramp-sh's copy and rename handlers.
-rw-r--r--lisp/net/tramp-adb.el21
-rw-r--r--lisp/net/tramp-androidsu.el55
2 files changed, 49 insertions, 27 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index 4f04912c032..3f216ba403a 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -641,23 +641,10 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
641 ;; because `file-attributes' reads the values from 641 ;; because `file-attributes' reads the values from
642 ;; there. 642 ;; there.
643 (tramp-flush-file-properties v localname) 643 (tramp-flush-file-properties v localname)
644 (unless (if (tramp-adb-file-name-p v) 644 (unless (tramp-adb-execute-adb-command
645 (tramp-adb-execute-adb-command 645 v "push"
646 v "push" 646 (file-name-unquote filename)
647 (file-name-unquote filename) 647 (file-name-unquote localname))
648 (file-name-unquote localname))
649 ;; Otherwise, this operation was initiated
650 ;; by the androidsu backend, so both files
651 ;; must be present on the local machine and
652 ;; transferable with a simple local copy.
653 (tramp-adb-send-command-and-check
654 v
655 (format
656 "cp -f %s %s"
657 (tramp-shell-quote-argument
658 (file-name-unquote filename))
659 (tramp-shell-quote-argument
660 (file-name-unquote localname)))))
661 (tramp-error 648 (tramp-error
662 v 'file-error 649 v 'file-error
663 "Cannot copy `%s' `%s'" filename newname))))))))) 650 "Cannot copy `%s' `%s'" filename newname)))))))))
diff --git a/lisp/net/tramp-androidsu.el b/lisp/net/tramp-androidsu.el
index cf6b0d7202c..6d4ac2c17f1 100644
--- a/lisp/net/tramp-androidsu.el
+++ b/lisp/net/tramp-androidsu.el
@@ -41,6 +41,22 @@
41 "When this method name is used, forward all calls to su.") 41 "When this method name is used, forward all calls to su.")
42 42
43;;;###tramp-autoload 43;;;###tramp-autoload
44(defcustom tramp-androidsu-mount-global-namespace t
45 "When non-nil, browse files from within the global mount namespace.
46On systems that assign each application a unique view of the filesystem
47by executing them within individual mount namespaces and thus conceal
48each application's data directories from others, invoke `su' with the
49option `-mm' in order for the shell launched to run within the global
50mount namespace, so that TRAMP may edit files belonging to any and all
51applications."
52 :group 'tramp
53 :version "30.1"
54 :type 'boolean)
55
56(defvar tramp-androidsu-su-mm-supported 'unknown
57 "Whether `su -mm' is supported on this system.")
58
59;;;###tramp-autoload
44(tramp--with-startup 60(tramp--with-startup
45 (add-to-list 'tramp-methods 61 (add-to-list 'tramp-methods
46 `(,tramp-androidsu-method 62 `(,tramp-androidsu-method
@@ -94,7 +110,7 @@ multibyte mode and waits for the shell prompt to appear."
94 ;; Disregard 110 ;; Disregard
95 ;; tramp-encoding-shell, as 111 ;; tramp-encoding-shell, as
96 ;; there's no guarantee that it's 112 ;; there's no guarantee that it's
97 ;; possible to execute with 113 ;; possible to execute it with
98 ;; `android-use-exec-loader' off. 114 ;; `android-use-exec-loader' off.
99 "/system/bin/sh" "-i")) 115 "/system/bin/sh" "-i"))
100 (user (tramp-file-name-user vec)) 116 (user (tramp-file-name-user vec))
@@ -103,13 +119,32 @@ multibyte mode and waits for the shell prompt to appear."
103 (set-process-sentinel p #'tramp-process-sentinel) 119 (set-process-sentinel p #'tramp-process-sentinel)
104 (tramp-post-process-creation p vec) 120 (tramp-post-process-creation p vec)
105 121
106 ;; Replace `login-args' place holders. 122 ;; Replace `login-args' place holders.
107 (setq command (format "exec su - %s || exit" 123 (setq command (format "exec su - %s || exit"
108 (or user "root"))) 124 (or user "root")))
109 ;; Send the command. 125
126 ;; Attempt to execute the shell inside the global mount
127 ;; namespace if requested.
128 (when tramp-androidsu-mount-global-namespace
129 (progn
130 (when (eq tramp-androidsu-su-mm-supported 'unknown)
131 ;; Change the prompt in advance so that
132 ;; tramp-adb-send-command-and-check can call
133 ;; tramp-search-regexp.
134 (tramp-adb-send-command
135 vec (format "PS1=%s"
136 (tramp-shell-quote-argument
137 tramp-end-of-output)))
138 (setq tramp-androidsu-su-mm-supported
139 ;; Detect support for `su -mm'.
140 (tramp-adb-send-command-and-check
141 vec "su -mm -c 'exit 24'" 24)))
142 (when tramp-androidsu-su-mm-supported
143 (setq command (format "exec su -mm - %s || exit"
144 (or user "root"))))))
145 ;; Send the command.
110 (tramp-message vec 3 "Sending command `%s'" command) 146 (tramp-message vec 3 "Sending command `%s'" command)
111 (tramp-adb-send-command vec command t t) 147 (tramp-adb-send-command vec command t t)
112
113 ;; Android su binaries contact a background service to 148 ;; Android su binaries contact a background service to
114 ;; obtain authentication; during this process, input 149 ;; obtain authentication; during this process, input
115 ;; received is discarded, so input cannot be 150 ;; received is discarded, so input cannot be
@@ -204,8 +239,8 @@ FUNCTION."
204(defalias 'tramp-androidsu-handle-copy-directory 239(defalias 'tramp-androidsu-handle-copy-directory
205 (tramp-androidsu-generate-wrapper #'tramp-handle-copy-directory)) 240 (tramp-androidsu-generate-wrapper #'tramp-handle-copy-directory))
206 241
207(defalias 'tramp-androidsu-adb-handle-copy-file 242(defalias 'tramp-androidsu-sh-handle-copy-file
208 (tramp-androidsu-generate-wrapper #'tramp-adb-handle-copy-file)) 243 (tramp-androidsu-generate-wrapper #'tramp-sh-handle-copy-file))
209 244
210(defalias 'tramp-androidsu-adb-handle-delete-directory 245(defalias 'tramp-androidsu-adb-handle-delete-directory
211 (tramp-androidsu-generate-wrapper #'tramp-adb-handle-delete-directory)) 246 (tramp-androidsu-generate-wrapper #'tramp-adb-handle-delete-directory))
@@ -367,8 +402,8 @@ FUNCTION."
367(defalias 'tramp-androidsu-adb-handle-process-file 402(defalias 'tramp-androidsu-adb-handle-process-file
368 (tramp-androidsu-generate-wrapper #'tramp-adb-handle-process-file)) 403 (tramp-androidsu-generate-wrapper #'tramp-adb-handle-process-file))
369 404
370(defalias 'tramp-androidsu-adb-handle-rename-file 405(defalias 'tramp-androidsu-sh-handle-rename-file
371 (tramp-androidsu-generate-wrapper #'tramp-adb-handle-rename-file)) 406 (tramp-androidsu-generate-wrapper #'tramp-sh-handle-rename-file))
372 407
373(defalias 'tramp-androidsu-adb-handle-set-file-modes 408(defalias 'tramp-androidsu-adb-handle-set-file-modes
374 (tramp-androidsu-generate-wrapper #'tramp-adb-handle-set-file-modes)) 409 (tramp-androidsu-generate-wrapper #'tramp-adb-handle-set-file-modes))
@@ -416,7 +451,7 @@ FUNCTION."
416 (add-name-to-file . tramp-androidsu-handle-add-name-to-file) 451 (add-name-to-file . tramp-androidsu-handle-add-name-to-file)
417 ;; `byte-compiler-base-file-name' performed by default handler. 452 ;; `byte-compiler-base-file-name' performed by default handler.
418 (copy-directory . tramp-androidsu-handle-copy-directory) 453 (copy-directory . tramp-androidsu-handle-copy-directory)
419 (copy-file . tramp-androidsu-adb-handle-copy-file) 454 (copy-file . tramp-androidsu-sh-handle-copy-file)
420 (delete-directory . tramp-androidsu-adb-handle-delete-directory) 455 (delete-directory . tramp-androidsu-adb-handle-delete-directory)
421 (delete-file . tramp-androidsu-adb-handle-delete-file) 456 (delete-file . tramp-androidsu-adb-handle-delete-file)
422 ;; `diff-latest-backup-file' performed by default handler. 457 ;; `diff-latest-backup-file' performed by default handler.
@@ -478,7 +513,7 @@ FUNCTION."
478 (memory-info . tramp-androidsu-handle-memory-info) 513 (memory-info . tramp-androidsu-handle-memory-info)
479 (process-attributes . tramp-androidsu-handle-process-attributes) 514 (process-attributes . tramp-androidsu-handle-process-attributes)
480 (process-file . tramp-androidsu-adb-handle-process-file) 515 (process-file . tramp-androidsu-adb-handle-process-file)
481 (rename-file . tramp-androidsu-adb-handle-rename-file) 516 (rename-file . tramp-androidsu-sh-handle-rename-file)
482 (set-file-acl . ignore) 517 (set-file-acl . ignore)
483 (set-file-modes . tramp-androidsu-adb-handle-set-file-modes) 518 (set-file-modes . tramp-androidsu-adb-handle-set-file-modes)
484 (set-file-selinux-context . ignore) 519 (set-file-selinux-context . ignore)