home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / packages / netunam.el < prev    next >
Encoding:
Text File  |  1992-08-18  |  5.4 KB  |  151 lines

  1. ;; HP-UX RFA Commands
  2. ;; Copyright (C) 1988 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 1, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. ;;; Author: cph@zurich.ai.mit.edu
  21.  
  22. (defconst rfa-node-directory "/net/"
  23.   "Directory in which RFA network special files are stored.
  24. By HP convention, this is \"/net/\".")
  25.  
  26. (defvar rfa-default-node nil
  27.   "If not nil, this is the name of the default RFA network special file.")
  28.  
  29. (defvar rfa-password-memoize-p t
  30.   "If non-nil, remember login user's passwords after they have been entered.")
  31.  
  32. (defvar rfa-password-alist '()
  33.   "An association from node-name strings to password strings.
  34. Used if `rfa-password-memoize-p' is non-nil.")
  35.  
  36. (defvar rfa-password-per-node-p t
  37.   "If nil, login user uses same password on all machines.
  38. Has no effect if `rfa-password-memoize-p' is nil.")
  39.  
  40. (defun rfa-set-password (password &optional node user)
  41.   "Add PASSWORD to the RFA password database.
  42. Optional second arg NODE is a string specifying a particular nodename;
  43.  if supplied and not nil, PASSWORD applies to only that node.
  44. Optional third arg USER is a string specifying the (remote) user whose
  45.  password this is; if not supplied this defaults to (user-login-name)."
  46.   (if (not user) (setq user (user-login-name)))
  47.   (let ((node-entry (assoc node rfa-password-alist)))
  48.     (if node-entry
  49.     (let ((user-entry (assoc user (cdr node-entry))))
  50.       (if user-entry
  51.           (rplacd user-entry password)
  52.           (rplacd node-entry
  53.               (nconc (cdr node-entry)
  54.                  (list (cons user password))))))
  55.     (setq rfa-password-alist
  56.           (nconc rfa-password-alist
  57.              (list (list node (cons user password))))))))
  58.  
  59. (defun rfa-open (node &optional user password)
  60.   "Open a network connection to a server using remote file access.
  61. First argument NODE is the network node for the remote machine.
  62. Second optional argument USER is the user name to use on that machine.
  63.   If called interactively, the user name is prompted for.
  64. Third optional argument PASSWORD is the password string for that user.
  65.   If not given, this is filled in from the value of
  66. `rfa-password-alist', or prompted for.  A prefix argument of - will
  67. cause the password to be prompted for even if previously memoized."
  68.   (interactive
  69.    (list (read-file-name "rfa-open: " rfa-node-directory rfa-default-node t)
  70.      (read-string "user-name: " (user-login-name))))
  71.   (let ((node
  72.      (and (or rfa-password-per-node-p
  73.           (not (equal user (user-login-name))))
  74.           node)))
  75.     (if (not password)
  76.     (setq password
  77.           (let ((password
  78.              (cdr (assoc user (cdr (assoc node rfa-password-alist))))))
  79.         (or (and (not current-prefix-arg) password)
  80.             (rfa-password-read
  81.              (format "password for user %s%s: "
  82.                  user
  83.                  (if node (format " on node \"%s\"" node) ""))
  84.              password))))))
  85.   (let ((result
  86.      (sysnetunam (expand-file-name node rfa-node-directory)
  87.              (concat user ":" password))))
  88.     (if (interactive-p)
  89.     (if result
  90.         (message "Opened network connection to %s as %s" node user)
  91.         (error "Unable to open network connection")))
  92.     (if (and rfa-password-memoize-p result)
  93.     (rfa-set-password password node user))
  94.     result))
  95.  
  96. (defun rfa-close (node)
  97.   "Close a network connection to a server using remote file access.
  98. NODE is the network node for the remote machine."
  99.   (interactive
  100.    (list (read-file-name "rfa-close: " rfa-node-directory rfa-default-node t)))
  101.   (let ((result (sysnetunam (expand-file-name node rfa-node-directory) "")))
  102.     (cond ((not (interactive-p)) result)
  103.       ((not result) (error "Unable to close network connection"))
  104.       (t (message "Closed network connection to %s" node)))))
  105.  
  106. (defun rfa-password-read (prompt default)
  107.   (let ((rfa-password-accumulator (or default "")))
  108.     (read-from-minibuffer prompt
  109.               (and default
  110.                    (let ((copy (concat default))
  111.                      (index 0)
  112.                      (length (length default)))
  113.                  (while (< index length)
  114.                    (aset copy index ?.)
  115.                    (setq index (1+ index)))
  116.                  copy))
  117.               rfa-password-map)
  118.     rfa-password-accumulator))
  119.  
  120. (defvar rfa-password-map nil)
  121. (if (not rfa-password-map)
  122.     (let ((char ? ))
  123.       (setq rfa-password-map (make-keymap))
  124.       (while (< char 127)
  125.     (define-key rfa-password-map (char-to-string char)
  126.       'rfa-password-self-insert)
  127.     (setq char (1+ char)))
  128.       (define-key rfa-password-map "\C-g"
  129.     'abort-recursive-edit)
  130.       (define-key rfa-password-map "\177"
  131.     'rfa-password-rubout)
  132.       (define-key rfa-password-map "\n"
  133.     'exit-minibuffer)
  134.       (define-key rfa-password-map "\r"
  135.     'exit-minibuffer)))
  136.  
  137. (defvar rfa-password-accumulator nil)
  138.  
  139. (defun rfa-password-self-insert ()
  140.   (interactive)
  141.   (setq rfa-password-accumulator
  142.     (concat rfa-password-accumulator
  143.         (char-to-string last-command-char)))
  144.   (insert ?.))
  145.  
  146. (defun rfa-password-rubout ()
  147.   (interactive)
  148.   (delete-char -1)
  149.   (setq rfa-password-accumulator
  150.     (substring rfa-password-accumulator 0 -1)))
  151.