From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: MON KEY Newsgroups: gmane.emacs.devel Subject: visudo with Emacs Date: Sat, 18 Jun 2011 17:48:27 -0400 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: dough.gmane.org 1308434024 13173 80.91.229.12 (18 Jun 2011 21:53:44 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 18 Jun 2011 21:53:44 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 18 23:53:40 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QY3SW-0004zw-G2 for ged-emacs-devel@m.gmane.org; Sat, 18 Jun 2011 23:53:40 +0200 Original-Received: from localhost ([::1]:32797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QY3SV-0008Bs-CC for ged-emacs-devel@m.gmane.org; Sat, 18 Jun 2011 17:53:39 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:49640) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QY3NX-0007GG-M9 for emacs-devel@gnu.org; Sat, 18 Jun 2011 17:48:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QY3NV-0006Jm-Vs for emacs-devel@gnu.org; Sat, 18 Jun 2011 17:48:31 -0400 Original-Received: from mail-iw0-f169.google.com ([209.85.214.169]:47482) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QY3NV-0006JX-Ld for emacs-devel@gnu.org; Sat, 18 Jun 2011 17:48:29 -0400 Original-Received: by iwn8 with SMTP id 8so68308iwn.0 for ; Sat, 18 Jun 2011 14:48:27 -0700 (PDT) Original-Received: by 10.231.74.18 with SMTP id s18mr3397225ibj.135.1308433707478; Sat, 18 Jun 2011 14:48:27 -0700 (PDT) Original-Received: by 10.231.200.200 with HTTP; Sat, 18 Jun 2011 14:48:27 -0700 (PDT) X-Google-Sender-Auth: pHdzK6ZlLJ5cERSvZP_iF21m88s X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.214.169 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:140663 Archived-At: Using visudo with $EDITOR set to emacs when saving /etc/sudoers I'm left with /etc/sudoers.tmp~ in /etc with permissions as rw, i.e: root> ls -ldZ /etc/sudoers -r--r-----. root root unconfined_u:object_r:etc_t:s0 /etc/sudoers root> ls -ldZ /etc/sudoers.tmp~ -rw-------. root root unconfined_u:object_r:etc_t:s0 /etc/sudoers.tmp~ When $EDITOR is not set visudo falls back to using the nonsensical editor (i.e. /bin/vi). However, unlike Emacs, that editor does not leave behind an /etc/sudoers.tmp~ AFAICT the stray /etc/sudoers.tmp~ is not in keeping with the spirit of visudo. Emacs should operate equivalently with vi. I'm able to remedy this by modifying /root/.bashrc and /root/.emacs to contain the following: ,---- in /root/.emacs | (when (member "_=/usr/sbin/visudo" process-environment) | (add-hook 'find-file-hook 'visudo-sudoers-p)) | | (defun visudo-sudoers-p () | (setq backup-enable-predicate 'visudo-no-tmp~) | (add-hook 'after-save-hook 'kill-sudoers.tmp~))) | | (defun kill-sudoers.tmp~ () | (when (file-exists-p "/etc/sudoers.tmp~") | (delete-file "/etc/sudoers.tmp~"))) | | (defun visudo-no-tmp~ (maybe-sudoers.tmp) | (if (string= maybe-sudoers.tmp "/etc/sudoers.tmp") | (with-current-buffer (get-buffer-create "sudoers.tmp") | (setq backup-inhibited t) | (auto-save-mode -1) | nil) | t)) `---- ,---- /root/.bashrc | export EMACS="emacs --no-window-system --no-site-file --no-init-file | -u root -fg white -bg red" | export EDITOR="$EMACS" | export VISUAL="$EMACS" `---- The above exports are bash centric and should really prob. run with an Emacs built specifically without X support, instead we just pass the --no-window-system and assume invocation from something resembling a terminal. The fg/bg params are mostly so we _know_ we're in a root'd Emacs. The --no-init-file is to prevent picking up the init file from the environment of an su'd user. I would think something like the elisp above should be included with Emacs if only to save users the agony of having to use vi :P I've tested the above configurations from a tty and a gdm'd X session with an Emacs built from distribution sources and the following build specs: GNU Emacs 23.3.1 (i686-pc-linux-gnu, GTK+ Version 2.24.4) of 2011-06-15 Windowing system distributor `Fedora Project', version 11.0.11001000 configured using `configure ''--without-xft' '--with-x-toolkit=gtk' '--with-dbus' '--with-gif' '--with-jpeg' '--with-png' '--with-rsvg' '--with-tiff' '--with-xpm' '--without-sound'' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: nil value of $LC_CTYPE: nil value of $LC_MESSAGES: nil value of $LC_MONETARY: nil value of $LC_NUMERIC: nil value of $LC_TIME: nil value of $LANG: en_US.UTF-8 value of $XMODIFIERS: @im=none locale-coding-system: utf-8-unix default enable-multibyte-characters: t -- /s_P\