Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File permissions break sudoedit #1343

Open
Artefact2 opened this issue Sep 23, 2021 · 5 comments
Open

File permissions break sudoedit #1343

Artefact2 opened this issue Sep 23, 2021 · 5 comments
Labels

Comments

@Artefact2
Copy link

I am running Prelude (emacs 27.2) on Arch Linux. It seems that when editing a file that looks like a bash script, something will automatically set +x on that file upon saving. Unfortunately that breaks sudoedit :

% echo $SUDO_EDITOR
emacsclient -nw -c
% sudoedit /etc/makepkg.conf 
sudoedit: /var/tmp/makepkgXXgBYd1E.conf: bad file mode: 0711
sudoedit: /etc/makepkg.conf left unmodified

Steps to reproduce:

% mkdir bar
% echo '#!/hint/bash\nfoo' > bar/foo.conf
% chmod 644 bar/foo.conf
% sudo chown root:root bar bar/foo.conf
% SUDO_EDITOR=emacsclient sudoedit bar/foo.conf
# (make any change then C-x C-s)
sudoedit: /var/tmp/fooXXiFtpLJ.conf: bad file mode: 0711
sudoedit: bar/foo.conf left unmodified

How can I disable this behaviour? Thanks.

@bbatsov
Copy link
Owner

bbatsov commented Sep 29, 2021

There's a hook in prelude-editor.el that does this:

;; make a shell script executable automatically on save
(add-hook 'after-save-hook
          'executable-make-buffer-file-executable-if-script-p)

You can use remove-hook to remove it.

@duckwork
Copy link
Contributor

Is there any way to make Emacs "smart" on this? I'm not sure what it'd look like exactly (I can't find where sudoedit changes any environment variables with light testing), but it might come in handy.

@bbatsov
Copy link
Owner

bbatsov commented Sep 30, 2021

We can have a more sophisticated hook - e.g. one that ignores certain files or runs additional predicate checks. It's easy to do, but I think it's going to be an overkill for most people.

@duckwork
Copy link
Contributor

I figured as much -- I was scratching my head trying to figure out the predicate checks to make. Not sure if just checking whether the owner of the file is root is enough... but like you say, it's probably overkill.

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@stale stale bot added the stale label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants