unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* yes I'm root but want 444 files found readonly
@ 2002-06-26 18:29 Dan Jacobson
       [not found] ` <86bs9vq671.fsf@eden-hda7.my.local>
  2002-07-02  1:31 ` Jeff Sheinberg
  0 siblings, 2 replies; 7+ messages in thread
From: Dan Jacobson @ 2002-06-26 18:29 UTC (permalink / raw)


$ 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.

Also there's the case of 444 but not owned by root.  Here also I would
find-readonly. 
-- 
http://jidanni.org/ Taiwan(04)25854780

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

* Re: yes I'm root but want 444 files found readonly
       [not found] ` <86bs9vq671.fsf@eden-hda7.my.local>
@ 2002-06-30 21:50   ` Dan Jacobson
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Jacobson @ 2002-06-30 21:50 UTC (permalink / raw)


>> $ 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 <jeffsh@erols.com> 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

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

* Re: yes I'm root but want 444 files found readonly
  2002-06-26 18:29 yes I'm root but want 444 files found readonly Dan Jacobson
       [not found] ` <86bs9vq671.fsf@eden-hda7.my.local>
@ 2002-07-02  1:31 ` Jeff Sheinberg
  2002-07-02 16:16   ` Francesco Potorti`
  1 sibling, 1 reply; 7+ messages in thread
From: Jeff Sheinberg @ 2002-07-02  1:31 UTC (permalink / raw)


jidanni@dman.ddts.net (Dan Jacobson) writes:
 > 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.

Greetings Zen Master "jidanni",

See below for a sample implementation that finds such files in
read-only mode.  IMO, there is no need for prompting, since %%
shows in the mode line, and C-x C-q will easily toggle read-only
off when and if desired.

 > Also there's the case of 444 but not owned by root.  Here also I would
 > find-readonly. 

My version of Emacs (GNU Emacs 21.2.1) already finds files with
mode 444 read-only, just like versions 18, 19, and 20 did.


;;----------------------------------------------------------------------
;; 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)
;;----------------------------------------------------------------------

HTH,
-- 
Jeff Sheinberg  <jeffsh@erols.com>

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

* Re: yes I'm root but want 444 files found readonly
  2002-07-02  1:31 ` Jeff Sheinberg
@ 2002-07-02 16:16   ` Francesco Potorti`
  2002-07-03  2:18     ` Dan Jacobson
  0 siblings, 1 reply; 7+ messages in thread
From: Francesco Potorti` @ 2002-07-02 16:16 UTC (permalink / raw)


   See below for a sample implementation that finds such files in
   read-only mode.

This one does no prompting, and does the trick as well, if I forgot
nothing: 

(defun set-read-only-if-file-not-writable ()
  (when (zerop (logand (file-modes (buffer-file-name)) #o222))
    (setq buffer-read-only t)))
(add-hook 'find-file-hooks 'set-read-only-if-file-not-writable)

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

* Re: yes I'm root but want 444 files found readonly
  2002-07-02 16:16   ` Francesco Potorti`
@ 2002-07-03  2:18     ` Dan Jacobson
  2002-07-03 16:01       ` Francesco Potorti`
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Jacobson @ 2002-07-03  2:18 UTC (permalink / raw)


>>>>> "Francesco" == Francesco Potorti` <pot@gnu.org> writes:

Francesco>    See below for a sample implementation that finds such files in
Francesco>    read-only mode.

Of course you understand that I hope these things get implemented in
emacs, otherwise they are just bytes in one ear and out the other for
me, as I rarely save them as they breeze by.
-- 
http://jidanni.org/ Taiwan(04)25854780

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

* Re: yes I'm root but want 444 files found readonly
  2002-07-03  2:18     ` Dan Jacobson
@ 2002-07-03 16:01       ` Francesco Potorti`
  2002-07-03 18:46         ` David desJardins
  0 siblings, 1 reply; 7+ messages in thread
From: Francesco Potorti` @ 2002-07-03 16:01 UTC (permalink / raw)


   Of course you understand that I hope these things get implemented in
   emacs, otherwise they are just bytes in one ear and out the other for
   me, as I rarely save them as they breeze by.

In my opinion, that should be standard Emacs behaviour.  root should be
protected against writing its own read-only files justa as anyone else.

But anyway, why don't you put those four lines in your
/etc/emacs/default.el or ~root/.emacs?  I did the former.

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

* Re: yes I'm root but want 444 files found readonly
  2002-07-03 16:01       ` Francesco Potorti`
@ 2002-07-03 18:46         ` David desJardins
  0 siblings, 0 replies; 7+ messages in thread
From: David desJardins @ 2002-07-03 18:46 UTC (permalink / raw)


"Francesco Potorti`" writes:
> In my opinion, that should be standard Emacs behaviour.  root should be
> protected against writing its own read-only files justa as anyone else.
> 
> But anyway, why don't you put those four lines in your
> /etc/emacs/default.el or ~root/.emacs?  I did the former.

Modifying emacs on his system protects one, or a few users, from this
problem.  Reporting the bug, and getting it fixed everywhere, protects
many thousands of users.  I tend to agree with him, the latter is worth
the trouble but the former isn't.

                                        David desJardins

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

end of thread, other threads:[~2002-07-03 18:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-26 18:29 yes I'm root but want 444 files found readonly Dan Jacobson
     [not found] ` <86bs9vq671.fsf@eden-hda7.my.local>
2002-06-30 21:50   ` Dan Jacobson
2002-07-02  1:31 ` Jeff Sheinberg
2002-07-02 16:16   ` Francesco Potorti`
2002-07-03  2:18     ` Dan Jacobson
2002-07-03 16:01       ` Francesco Potorti`
2002-07-03 18:46         ` David desJardins

Code repositories for project(s) associated with this public 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).