[comp.emacs] Suggestion: An su mode for Emacs???

and@ux.rfhsm.lon.ac.UK (Andy Holyer) (12/16/88)

Dear Net-things,
	I've just thought of a possible extra command for emacs: I
often find, right in the middle of an emacs session, that I need to do
something in SuperUser mode. Is it possible to have a command
(su-emacs, say) which asks for the su password, and from then on acts
as if it was run by root? I'ts a pain in the middle of a make to have
to halt emacs, run su, chmod a file (or some such) go out of su, and
then re-run emacs again.
Initial thoughts:
	I appreciate that this could be a security risk, but then so's
su itself, and with good programming it should be fairly secure (And
we're big boys now who know how to program good :-)).
	I have a feeling that emacs would have to be running suid root....?


	Any Comments? I'm willing to put in the work, but collaborators
would be welcome. Flames, suggestions, thoughts etc. to the usual....

------------------------------------------------------------------------------
|       &&       |                                                           |
|      &  &      |       &ndy Holyer                                         |
|      &  &      |       Snail:  Dept. of Medical Informatics & Computing,   |
|       &&       |               Royal Free Hospital School of Medicine,     |
|      &  &   &  |               Rowland Hill St.                            |
|     &    & &   |               London NW3 2PF                              |
|    &      &    |               England                                     |
|    &     & &   |       JANET:  and@uk.ac.lon.rfhsm.ux                      |
|     &   &   &  |       Voice:  (+44) 1 794 8673                            |
|      &&&     & |                                                           |
|----------------+-----------------------------------------------------------|
|"Handy Hint: Re-use old telephone directories as a handy address            |
|            book; simply cross out the names of everybody you don't know."  |
|               - Viz Comic                                                  |
------------------------------------------------------------------------------
	#include <disclaimer.h>

ron@ron.rutgers.edu (Ron Natalie) (12/17/88)

It's a bit early for April Fools day.  Surely your joking.
I don't even want to think about EMACS running setuid
again.  If it bothers you that much, start an rlogin
window, which is already supported.

-Ron

jr@bbn.com (John Robinson) (12/17/88)

In article <8812161518.AA20708@uk.ac.lon.rfhsm.ux>, and@ux (Andy Holyer) writes:
>Dear Net-things,
>	I've just thought of a possible extra command for emacs: I
>often find, right in the middle of an emacs session, that I need to do
>something in SuperUser mode. Is it possible to have a command
>(su-emacs, say) which asks for the su password, and from then on acts
>as if it was run by root?

Um, why not switch to your shell buffer and type the 'su -c ...' there?

I decided the function you want should be easy enough to write.  Well,
it wsa a tad difficult because of having to handle process i/o, but
here's one that seems to work with limited testing, though it may not
be optimally speedy.  I liked it enough to bind it to M-#.  It started
out as the code for shell-command, but little of that is left.  It
does not have the option of shell-command of inserting the output in
the curent buffer; that's an exercise for the reader :-).

(defun su-command (password command)
  "Prompt for root password and a command, then do the latter as root."
  (interactive "sRoot password: \nsCommand: ")
  (let ((buffer (get-buffer-create "*Shell Command Output*"))
        proc)
    (if (save-excursion
	  (set-buffer buffer)
	  (erase-buffer)
	  (setq proc (start-process "su-emacs" buffer "/bin/su"
				    "-c" command))
	  (goto-char (point-min))
	  (while (not (looking-at "Password:"))
	    (accept-process-output proc)
	    (goto-char (point-min)))
	  (erase-buffer)
	  (send-string proc (concat password "\n"))
	  (while (not (looking-at "\n"))
	    (accept-process-output proc)
	    (goto-char (point-min)))
	  (delete-char 1)
	  (while (not (equal (process-status proc) 'exit))
	    (accept-process-output))
	  (> (buffer-size) 0))
	(set-window-start (display-buffer buffer) 1)
      (message "(Command completed with no output)"))))

I agree that nothing in what you have proposed is worse than having an
su at all.  And that already is no less secure than the root password.
--
/jr
jr@bbn.com or bbn!jr

nate@hobbes.intel.com (Nate Hess) (12/20/88)

In article <8812161518.AA20708@uk.ac.lon.rfhsm.ux>, and@ux (Andy Holyer) writes:
>Dear Net-things,
>Is it possible to have a command (su-emacs, say) which asks for the su
>password, and from then on acts as if it was run by root?

Here is something quick'n'dirty that should do what you want:


(defun emacs-su ()
  "Don superuser costume in a seperate terminal emulator buffer."
  (interactive)
  (terminal-emulator "*Emacs su*" "/bin/su"))


Hope it helps,
--woodstock
--
	   "What I like is when you're looking and thinking and looking
	   and thinking...and suddenly you wake up."   - Hobbes

woodstock@sc.intel.com    ...!{decwrl|hplabs!oliveb|amd}!intelca!mipos3!nate