unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#56180: 29.0.50; editing file with tramp's "sudo:" changes file owner
@ 2022-06-24  5:26 Platon Pronko
  2022-06-24 15:32 ` Michael Albinus
  0 siblings, 1 reply; 3+ messages in thread
From: Platon Pronko @ 2022-06-24  5:26 UTC (permalink / raw)
  To: 56180

When I'm editing some root-owned file on the local system with via tramp's "sudo:"
file owner and group are changed to my username (the one Emacs is running under).

This is unfortunate, both due to security reasons and due to the fact that some programs/daemons
refuse to function properly when certain files have incorrect owners (for example cronie
won't run the crontab if it is not owned by root).

Steps to reproduce:

1. sudo touch /tmp/test.txt

2. Check that owner is root:
$ ls -l /tmp/test.txt
-rw-r--r-- 1 root root 0 Jun 24 05:17 /tmp/test.txt

3. emacs -Q --eval "(require 'tramp)"

4. Open the test file with sudo. C-x C-f, /sudo:root@your-machine:/tmp/test.txt

5. Type something into the file, save.

6. Observe that file owner is now changed:
$ ls -l /tmp/test.txt
-rw-r--r-- 1 user user 5 Jun 24 05:19 /tmp/test.txt


It seems that this is a regression from a commit 4e7879f8 in May, which tweaked
how tramp decides whether to chown the file after it is written. I think that
one of the checks needs to be inverted (patch below), because currently it reads
"if uid is different, then skip setting the uid, but if it is equal then set it to the same value".

diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 59a2710e00..c6665c2792 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3462,8 +3462,8 @@ tramp-skeleton-write-region
                   ;; `file-precious-flag' is set.
                   (or (file-attribute-modification-time file-attr)
                       (current-time)))
-                (unless (and (= (file-attribute-user-id file-attr) uid)
-                             (= (file-attribute-group-id file-attr) gid))
+                (when (and (= (file-attribute-user-id file-attr) uid)
+                           (= (file-attribute-group-id file-attr) gid))
                    (setq need-chown nil))))
  
              ;; Set the ownership.



In GNU Emacs 29.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.34, cairo version 1.17.6)
  of 2022-05-29 built on the-big-maker
Repository revision: 96d056b3aa7bc689e2550bddd56f51a88c69fe2f
Repository branch: makepkg
System Description: Arch Linux

Configured using:
  'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
  --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
  --with-modules --without-libotf --without-m17n-flt --without-gconf
  --with-xinput2 --with-pgtk --without-xaw3d --with-sound=no
  --without-gpm --without-compress-install
  '--program-transform-name=s/\([ec]tags\)/\1.emacs/'
  'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions
  -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security
  -fstack-clash-protection -fcf-protection -fuse-ld=gold -fuse-ld=gold'
  LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now
  'CXXFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions
  -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security
  -fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS
  -fuse-ld=gold -fuse-ld=gold''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LCMS2 LIBSYSTEMD LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PGTK PNG RSVG
SECCOMP SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS WEBP XIM GTK3 ZLIB

Important settings:
   value of $LC_TIME: en_SE.UTF-8
   value of $LANG: en_US.utf8
   locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
   bug-reference-prog-mode: t
   global-so-long-mode: t
   global-git-commit-mode: t
   magit-auto-revert-mode: t
   rainbow-delimiters-mode: t
   counsel-mode: t
   ivy-mode: t
   smartparens-strict-mode: t
   smartparens-mode: t
   global-git-gutter-mode: t
   git-gutter-mode: t
   shell-dirtrack-mode: t
   global-auto-revert-mode: t
   global-whitespace-mode: t
   global-dvorak-mode: t
   dvorak-minor-mode: t
   tooltip-mode: t
   global-eldoc-mode: t
   eldoc-mode: t
   show-paren-mode: t
   electric-indent-mode: t
   mouse-wheel-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   column-number-mode: t
   line-number-mode: t
   transient-mark-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t

Load-path shadows:
/home/platon/.emacs.d/elpa/lispy-20220209.1138/elpa hides /home/platon/.emacs.d/elpa/ivy-20220529.1130/elpa
/home/platon/.emacs.d/elpa/protobuf-mode-20220303.1716/protobuf-mode hides /usr/share/emacs/site-lisp/protobuf-mode
/home/platon/.emacs.d/elpa/transient-20220527.2213/transient hides /usr/share/emacs/29.0.50/lisp/transient
/home/platon/.emacs.d/elpa/less-css-mode-20161001.453/less-css-mode hides /usr/share/emacs/29.0.50/lisp/textmodes/less-css-mode

Features:
(shadow sort emacsbug crontab-mode sh-script smie executable rfc2104
flymake-proc flymake warnings lsp-diagnostics company-oddmuse
company-keywords company-etags company-gtags company-dabbrev-code
company-dabbrev company-files company-clang company-capf company-cmake
company-semantic company-template company-bbdb lsp-modeline lsp-lens
view lsp-zig lsp-steep lsp-svelte lsp-sqls lsp-yaml lsp-xml
lsp-vimscript lsp-vhdl lsp-volar lsp-vetur lsp-html lsp-verilog lsp-vala
lsp-v lsp-typeprof lsp-ttcn3 lsp-toml lsp-terraform lsp-tex lsp-sorbet
lsp-solargraph lsp-rust lsp-rf lsp-remark lsp-r lsp-purescript lsp-pylsp
lsp-pyls lsp-pwsh lsp-php lsp-perlnavigator lsp-perl lsp-openscad
lsp-ocaml lsp-magik lsp-nix lsp-nim lsp-nginx lsp-markdown lsp-lua
lsp-kotlin lsp-json lsp-javascript lsp-idris lsp-haxe lsp-groovy
lsp-hack lsp-graphql lsp-gleam lsp-go lsp-completion lsp-gdscript
lsp-fsharp lsp-fortran lsp-eslint lsp-erlang lsp-emmet lsp-elixir
lsp-elm lsp-dockerfile lsp-dhall lsp-d lsp-css lsp-csharp lsp-crystal
lsp-cmake lsp-clojure lsp-semantic-tokens lsp-clangd lsp-beancount
lsp-bash lsp-ansible lsp-angular lsp-ada lsp-actionscript
smartparens-python python vc vc-dispatcher bug-reference magit-extras
face-remap mail-extr smartparens-scala scala-mode
scala-mode-prettify-symbols scala-mode-imenu scala-mode-map
scala-mode-fontlock scala-mode-indent scala-mode-paragraph
scala-mode-syntax scala-mode-lib dabbrev smartparens-c cc-mode cc-fonts
cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs
ace-window misearch multi-isearch bs conf-mode tramp-cmds tramp-sh
tramp-cache ffap org-element avl-tree ol-w3m ol-rmail ol-mhe ol-irc
ol-info org-habit org-agenda org-refile ol-gnus nnselect gnus-art mm-uu
mml2015 mm-view mml-smime smime gnutls dig gnus-sum gnus-group gnus-undo
gnus-start gnus-dbus dbus gnus-cloud nnimap nnmail mail-source utf7
netrc nnoo gnus-spec gnus-int gnus-range gnus-win ol-eww eww url-queue
shr pixel-fill kinsoku url-file url-dired svg xml dom mm-url gnus
nnheader range ol-docview doc-view jka-compr image-mode exif ol-bibtex
ol-bbdb so-long lsp lsp-mode lsp-protocol tree-widget spinner
network-stream nsm smartparens-markdown markdown-mode inline ht f
f-shortdoc shortdoc s ewoc company org-archive magit-submodule
magit-obsolete magit-blame magit-stash magit-reflog magit-bisect
magit-push magit-pull magit-fetch magit-clone magit-remote magit-commit
magit-sequence magit-notes magit-worktree magit-tag magit-merge
magit-branch magit-reset magit-files magit-refs magit-status magit
magit-repos magit-apply magit-wip magit-log which-func imenu magit-diff
smerge-mode diff diff-mode git-commit log-edit message sendmail
yank-media rmc puny rfc822 mml mml-sec epa derived epg rfc6068
epg-config gnus-util mm-decode mm-bodies mm-encode mail-parse rfc2231
rfc2047 rfc2045 mm-util ietf-drums mail-prsvr mailabbrev mail-utils
gmm-utils mailheader pcvs-util add-log magit-core magit-autorevert
magit-margin magit-transient magit-process with-editor server magit-mode
transient magit-git magit-base magit-section crm compat-27 compat-26
compat rainbow-delimiters compat-macs lispy lispy-inline avy etags
fileloop generator edebug debug backtrace help-fns radix-tree lispy-tags
mode-local counsel xdg xref project dired dired-loaddefs swiper ivy
delsel ivy-faces ivy-overlay colir color edmacro kmacro
smartparens-config smartparens-rust smartparens-org smartparens-text
smartparens dash cl-extra git-gutter-fringe fringe-helper git-gutter
hydra lv tramp tramp-loaddefs trampver tramp-integration cus-edit pp
cus-load wid-edit files-x tramp-compat shell parse-time ls-lisp lpr
rust-utils thingatpt rust-mode rust-rustfmt rust-playpen rust-compile
compile text-property-search rust-cargo autorevert filenotify disp-table
whitespace quail help-mode org ob ob-tangle ob-ref ob-lob ob-table
ob-exp org-macro org-footnote org-src ob-comint org-pcomplete pcomplete
comint ansi-color ring org-list org-faces org-entities noutline outline
easy-mmode org-version ob-emacs-lisp ob-core ob-eval org-table oc-basic
bibtex iso8601 time-date ol rx org-keys oc org-compat advice org-macs
org-loaddefs format-spec find-func cal-menu calendar cal-loaddefs pcase
darcula-theme finder-inf info package browse-url url url-proxy
url-privacy url-expand url-methods url-history url-cookie url-domsuf
url-util mailcap url-handlers url-parse auth-source cl-seq eieio
eieio-core cl-macs eieio-loaddefs password-cache json map url-vars seq
gv subr-x byte-opt bytecomp byte-compile cconv cl-loaddefs cl-lib
iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/pgtk-win pgtk-win term/common-win
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer nadvice
simple cl-generic indonesian philippine cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite emoji-zwj charscript charprop case-table
epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify
dynamic-setting system-font-setting font-render-setting cairo gtk pgtk
lcms2 multi-tty make-network-process emacs)

Memory information:
((conses 16 690043 406875)
   (symbols 48 52930 131)
   (strings 32 224243 35010)
   (string-bytes 1 7116190)
   (vectors 16 110060)
   (vector-slots 8 2069208 667484)
   (floats 8 551 1215)
   (intervals 56 15669 7168)
   (buffers 992 38))





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#56180: 29.0.50; editing file with tramp's "sudo:" changes file owner
  2022-06-24  5:26 bug#56180: 29.0.50; editing file with tramp's "sudo:" changes file owner Platon Pronko
@ 2022-06-24 15:32 ` Michael Albinus
  2022-06-24 15:35   ` Michael Albinus
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Albinus @ 2022-06-24 15:32 UTC (permalink / raw)
  To: Platon Pronko; +Cc: 56180-done

Version: 29.1

Platon Pronko <platon7pronko@gmail.com> writes:

Hi Platon,

> When I'm editing some root-owned file on the local system with via tramp's "sudo:"
> file owner and group are changed to my username (the one Emacs is running under).

Thanks for your report!

> It seems that this is a regression from a commit 4e7879f8 in May, which tweaked
> how tramp decides whether to chown the file after it is written. I think that
> one of the checks needs to be inverted (patch below), because currently it reads
> "if uid is different, then skip setting the uid, but if it is equal then set it to the same value".

Indeed. Accidently, the logic of this check was inverted by commits
47fe7a59 and 4e7879f8.

I've pushed your patch to the master branch, closing the bug.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#56180: 29.0.50; editing file with tramp's "sudo:" changes file owner
  2022-06-24 15:32 ` Michael Albinus
@ 2022-06-24 15:35   ` Michael Albinus
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Albinus @ 2022-06-24 15:35 UTC (permalink / raw)
  To: Platon Pronko; +Cc: 56180

Michael Albinus <michael.albinus@gmx.de> writes:

Hi Platon,

> I've pushed your patch to the master branch, closing the bug.

PS: Since it changes a macro in tramp.el, the file tramp-sh.el must be
recompiled, too.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-24 15:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24  5:26 bug#56180: 29.0.50; editing file with tramp's "sudo:" changes file owner Platon Pronko
2022-06-24 15:32 ` Michael Albinus
2022-06-24 15:35   ` Michael Albinus

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).