Subject: Re: bug#62260: 30.0.50; [PATCH] Restrict auto-save file mode

From: Eli Zaretskii <[email-masked]>
Date: Sun, 19 Mar 2023 16:11:02 +0200

> From: Michael Albinus <[email-masked]>
> Cc: Manuel Giraud <[email-masked]>,  [email-masked]
> Date: Sun, 19 Mar 2023 13:40:29 +0100
> 
> Tramp has no influence on the permissions of the auto-saved file.

My reading of the code in auto_save_1 is that the permission modes of
the auto-saved files for remote files are determined from their
original files, by calling file-modes (which I believe Tramp
implements?).  See the 'else' branch of this part of auto_save_1:

  /* Get visited file's mode to become the auto save file's mode.  */
  if (! NILP (BVAR (current_buffer, filename)))
    {
      if (emacs_fstatat (AT_FDCWD, SSDATA (BVAR (current_buffer, filename)),
			 &st, 0)
	  == 0)
	/* But make sure we can overwrite it later!  */
	auto_save_mode_bits = (st.st_mode | 0600) & 0777;
      else if (modes = Ffile_modes (BVAR (current_buffer, filename), Qnil),
	       FIXNUMP (modes))
	/* Remote files don't cooperate with fstatat.  */
	auto_save_mode_bits = (XFIXNUM (modes) | 0600) & 0777;
    }

If by "Tramp has no influence on the permissions of the auto-saved
file" you mean the permissions are determined by the file, not by
Tramp, then I agree.  This simply follows what we do with local files,
just by calling an Emacs primitive instead of fstatat.