annotate lisp/efs/efs-kerberos.el @ 51:69ce12f60f55

Added tag r19-16b91 for changeset ee648375d8d6
author cvs
date Mon, 13 Aug 2007 08:56:44 +0200
parents 8b8b7f3559a2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;; -*-Emacs-Lisp-*-
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;;
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
4 ;; File: efs-kerberos.el
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;; Release: $efs release: 1.15 $
42
8b8b7f3559a2 Import from CVS: tag r19-15b104
cvs
parents: 24
diff changeset
6 ;; Version: #Revision: 1.0 $
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7 ;; RCS:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
8 ;; Description: Support for Kerberos gateways.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9 ;; Author: Sandy Rutherford <sandy@gandalf.sissa.it>
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10 ;; Created: Thu Nov 24 21:19:25 1994 by sandy on gandalf
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 ;; Modified:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15 ;;; Support for the Kerberos gateway authentication system from MIT's
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16 ;;; Project Athena.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18 (provide 'efs-kerberos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19 (require 'efs)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21 (defconst efs-kerberos-version
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22 (concat (substring "$efs release: 1.15 $" 14 -2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 "/"
42
8b8b7f3559a2 Import from CVS: tag r19-15b104
cvs
parents: 24
diff changeset
24 (substring "#Revision: 1.0 $" 11 -2)))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
25
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26 ;;; Internal Variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
27
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
28 (defvar efs-kerberos-passwd-sent nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
29 ;; Set to t after the passwd has been sent.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
30 (defvar efs-kerberos-output "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
31 ;; Holds the output lines from the kinit process.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
32 (defvar efs-kerberos-buffer-name "*efs kerberos*")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33 ;; Buffer where kinit output is logged.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34 (defvar efs-kerberos-passwd-prompt-regexp "^Password: *$")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
35 ;; Regular expression to match prompt used by the kinit program.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36 (defvar efs-kerberos-failed-msgs "[^ ]+")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37 ;; Regular expression to match output for an invalid kinit ticket password.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38 ;; Is this too general?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
39 (defvar efs-kerberos-passwd-failed nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 ;; Whether the kinit command worked.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41 (defvar efs-kerberos-passwd-retry nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43 ;;; Code
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45 (defun efs-kerberos-process-filter (proc str)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 ;; Process filter for the kinit process.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47 (setq efs-kerberos-output (concat efs-kerberos-output str))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48 (let ((buff (get-buffer (process-buffer proc))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49 (if buff
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 (efs-save-buffer-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51 (set-buffer buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52 (efs-save-match-data
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 (goto-char (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54 (while (string-match "\n" efs-kerberos-output)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55 (let ((line (substring efs-kerberos-output 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56 (match-beginning 0))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57 (insert line "\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 (and efs-kerberos-passwd-sent
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59 (string-match efs-kerberos-failed-msgs line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
60 (setq efs-kerberos-passwd-failed t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
61 (setq efs-kerberos-output (substring efs-kerberos-output
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
62 (match-end 0))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
63 (and (null efs-kerberos-passwd-sent)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
64 (string-match efs-kerberos-passwd-prompt-regexp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
65 efs-kerberos-output)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
66 (memq (process-status proc) '(run open))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67 (let ((passwd (or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68 (efs-lookup-passwd efs-gateway-host "kerberos")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 (read-passwd
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70 (if efs-kerberos-passwd-retry
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71 "Password failed. Try again: "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 (format "Kerberos password for %s: "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73 efs-gateway-host))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76 (insert efs-kerberos-output)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77 (setq efs-kerberos-output "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 (process-send-string proc passwd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 (insert "Turtle Power!\n"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 (fillarray passwd 0)))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82 (defun efs-kerberos-get-ticket ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 ;; Gets a kerbos ticket. The password is actually sent by the process
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84 ;; filter.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85 (let ((mess (format "Getting kerberos ticket for %s..." efs-gateway-host)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86 (message mess)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 (setq efs-kerberos-passwd-failed nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 efs-kerberos-passwd-sent nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 efs-kerberos-output "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 (condition-case nil (delete-process "*efs kerberos*") (eror nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91 (let* ((program (or (nth 3 efs-gateway-type) "kinit"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 (args (nth 4 efs-gateway-type))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 (proc (apply 'start-process
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94 "*efs kerberos*" efs-kerberos-buffer-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95 program args)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
96 (set-process-filter proc (function efs-kerberos-process-filter))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97 ;; Should check for a pty, but efs-pty-check will potentially eat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 ;; important output. Need to wait until Emacs 19.29 to do this properly.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99 (while (memq (process-status proc) '(run open))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100 (accept-process-output proc))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101 (if efs-kerberos-passwd-failed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
102 (let ((efs-kerberos-passwd-failed t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
103 (efs-kerberos-get-ticket))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
104 (message "%sdone" mess)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
105
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
106 (defun efs-kerberos-login (host user proc)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
107 ;; Open a connection using process PROC to HOST adn USER, using a
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
108 ;; kerberos gateway. Returns the process object of the connection.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
109 ;; This may not be PROC, if a ticket collection was necessary.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
110 (let ((to host)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
111 result port cmd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
112 (if (string-match "#" host)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113 (setq to (substring host 0 (match-beginning 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114 port (substring host (match-end 0))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115 (and efs-nslookup-on-connect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116 (string-match "[^0-9.]" to)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117 (setq to (efs-nslookup-host to)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118 (setq cmd (concat "open " to))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 (if port (setq cmd (concat cmd " " port)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120 (setq result (efs-raw-send-cmd proc cmd))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121 (while (and (car result)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
122 (string-match "\\bcannot authenticate to server\\b"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
123 (nth 1 result)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124 (let ((name (process-name proc)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 (condition-case nil (delete-process proc) (error nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126 (efs-kerberos-get-ticket)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 (setq proc (efs-start-process host user name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128 result (efs-raw-send-cmd proc cmd))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129 (if (car result)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131 (condition-case nil (delete-process proc) (error nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132 (efs-error host user (concat "OPEN request failed: "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133 (nth 1 result)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
134 proc))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136 ;;; End of efs-kerberos.el