From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Dan Jacobson Newsgroups: gmane.emacs.bugs Subject: Re: yes I'm root but want 444 files found readonly Date: 01 Jul 2002 05:50:58 +0800 Sender: bug-gnu-emacs-admin@gnu.org Message-ID: <874rfktozh.fsf@jidanni.org> References: <87ptyd99ml.fsf@jidanni.org> <86bs9vq671.fsf@eden-hda7.my.local> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=big5 Content-Transfer-Encoding: 8bit X-Trace: main.gmane.org 1025499234 1900 127.0.0.1 (1 Jul 2002 04:53:54 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 1 Jul 2002 04:53:54 +0000 (UTC) Return-path: Original-Received: from fencepost.gnu.org ([199.232.76.164]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 17OtCD-0000UX-00 for ; Mon, 01 Jul 2002 06:53:53 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 17OtCe-0005fU-00; Mon, 01 Jul 2002 00:54:20 -0400 Original-Received: from chx400.switch.ch ([130.59.10.2]) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 17Ot9S-0005ay-00 for ; Mon, 01 Jul 2002 00:51:02 -0400 Original-Received: from mail.fu-berlin.de ([160.45.11.165]) by chx400.switch.ch with esmtp (Exim 3.20 #1) id 17Ot9P-0006gk-00 for gnu-emacs-bug@moderators.isc.org; Mon, 01 Jul 2002 06:50:59 +0200 Original-Received: by mail.fu-berlin.de (Smail3.2.0.98) from Curry.ZEDAT.FU-Berlin.DE (160.45.10.36) with esmtp id ; Mon, 1 Jul 2002 06:50:58 +0200 (MEST) Original-Received: by Curry.ZEDAT.FU-Berlin.DE (Smail3.2.0.98) from news.fu-berlin.de with bsmtp id ; Mon, 1 Jul 2002 06:50:57 +0200 (MEST) Original-To: gnu-emacs-bug@moderators.isc.org Original-Path: 61-227-47-110.hinet-ip.hinet.NET!not-for-mail Original-Newsgroups: gnu.emacs.bug Original-Lines: 85 X-Orig-NNTP-Posting-Host: 61-227-47-110.hinet-ip.hinet.net (61.227.47.110) X-Orig-X-Trace: fu-berlin.de 1025499057 16087600 61.227.47.110 (16 [99749]) X-Orig-Path: 127.0.0.1!nobody User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Errors-To: bug-gnu-emacs-admin@gnu.org X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.bugs:2361 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:2361 >> $ su >> # chmod 0 file >> # chmod 444 otherfile >> # emacs file otherfile >> and the files are found without the "%%" readonly in the mode line. >> >> OK, I'm root with the royal blood. But that doesn't mean I don't want >> to enjoy the same protection against altering my files all over the >> place just like the other guy. Sure wish there was an option in emacs >> that would respect the hints from the file modes even if I'm root. Or >> what, do you expect me to do C-x C-q on each file? Unfair. >> >> Yes, for my mode 0 file the option could have a third etc. choice, not >> only find-readonly, but also ask the user if he really wants to see it >> etc. >>>>> "J" == Jeff Sheinberg writes: J> See below for a sample implementation. IMO, there is no need for J> prompting, since %% shows in the mode line, and C-x C-q will easily J> toggle read-only off. OK, hope the FSF folks implement something. >> Also there's the case of 444 but not owned by root. Here also I would >> find-readonly. J> My version of Emacs (GNU Emacs 21.2.1) already finds files with J> mode 444 read-only, just like versions 18, 19, and 20 did. # ls -l index_en.html -r--r--r-- 1 jidanni jidanni 4018 6ды 27 04:19 index_en.html # emacs -q -nw index_en.html [And I am free to go wreck the file any way I feel fit to, with not the slightest beep to hold me back. I feel nothing different than if it were 666, 000, etc.] [No I didn't try writing it, I just started to type chars into its buffer and nothing about being read only was mentioned.] [Jeff's file:] ;;---------------------------------------------------------------------- ;; Put buffer in read-only mode if there are no write bits set in the ;; file's mode. This can occur when uid=0 edits a non-writable file. (defun my-set-read-only-if-no-writeable-mode-bits () "This function is used to warn the super-user that the current buffer has been set read-only because none of the file's write mode bits are set." (interactive) (let* ((file (buffer-file-name)) (mode (file-modes file))) (if mode (progn (if (and (not buffer-read-only) (file-writable-p file) (= (logand mode 146) 0)) ; 146 decimal is 222 octal. (progn (setq buffer-read-only t) (ding) (message "File's mode is %o, buffer set read-only, use `toggle-read-only' wisely!" mode))))))) (add-hook 'find-file-hooks 'my-set-read-only-if-no-writeable-mode-bits) ;; Put all buffers in `/usr/share/*' hierarchy in read-only mode. (defun my-set-read-only-usr-share-files () "This function is used to warn the user that the current buffer has been set read-only because the file being visited is in the `/usr/share/*' hierarchy." (interactive) (let* ((dir "/usr/share/") (len (- (length dir) 1))) (if (and (not buffer-read-only) (stringp buffer-file-truename) (file-writable-p buffer-file-truename) (fboundp 'compare-strings) ; keep emacs-19 happy (eq t (compare-strings dir 0 len buffer-file-truename 0 len))) (progn (setq buffer-read-only t) (ding) (message "Buffer %s set read-only, use `toggle-read-only' wisely!" (buffer-name)))))) (add-hook 'find-file-hooks 'my-set-read-only-usr-share-files) ;;---------------------------------------------------------------------- -- http://jidanni.org/ Taiwan(04)25854780