1 ;;; gssapi.el --- GSSAPI/Kerberos 5 interface for Emacs
3 ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
5 ;; Author: Simon Josefsson <simon@josefsson.org>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 (require 'format-spec
)
30 (defcustom gssapi-program
(list
31 (concat "gsasl %s %p "
33 "--authentication-id %l")
34 "imtest -m gssapi -u %l -p %p %s")
35 "List of strings containing commands for GSSAPI (krb5) authentication.
36 %s is replaced with server hostname, %p with port to connect to,
37 and %l with the user name. The program should accept commands on
38 stdin and return responses to stdout. Each entry in the list is
39 tried until a successful connection is made."
42 :type
'(repeat string
))
44 (defun open-gssapi-stream (name buffer server port user
)
45 (let ((cmds gssapi-program
)
47 (with-current-buffer buffer
48 (while (and (not done
)
49 (setq cmd
(pop cmds
)))
50 (message "Opening GSSAPI connection with `%s'..." cmd
)
52 (let* ((coding-system-for-read 'binary
)
53 (coding-system-for-write 'binary
)
54 (process (start-process
55 name buffer shell-file-name shell-command-switch
60 ?p
(number-to-string port
)
64 (while (and (memq (process-status process
) '(open run
))
65 (goto-char (point-min))
66 ;; Athena IMTEST can output SSL verify errors
67 (or (while (looking-at "^verify error:num=")
70 (or (while (looking-at "^TLS connection established")
73 ;; cyrus 1.6.x (13? < x <= 22) queries capabilities
74 (or (while (looking-at "^C:")
77 ;; cyrus 1.6 imtest print "S: " before server greeting
78 (or (not (looking-at "S: "))
81 ;; GNU SASL may print 'Trying ...' first.
82 (or (not (looking-at "Trying "))
85 (not (and (looking-at "\\* \\(OK\\|PREAUTH\\|BYE\\) ")
86 ;; success in imtest 1.6:
88 (concat "^\\(\\(Authenticat.*\\)\\|\\("
89 "Client authentication "
92 (setq response
(match-string 1)))))
93 (accept-process-output process
1)
96 (message "GSSAPI connection: %s" (or response
"failed"))
97 (if (and response
(let ((case-fold-search nil
))
98 (not (string-match "failed" response
))))
100 (delete-process process
)
106 ;;; gssapi.el ends here