home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / lisp / 2432 < prev    next >
Encoding:
Text File  |  1992-09-14  |  10.6 KB  |  308 lines

  1. Newsgroups: comp.lang.lisp
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!Sirius.dfn.de!solaris.rz.tu-clausthal.de!news!artemis!dehning
  3. From: dehning@tnt.uni-hannover.de (Oliver Dehning)
  4. Subject: Re: (ed), CLX, and OpenWindows
  5. Message-ID: <1992Sep15.064521.9977@newsserver.rrzn.uni-hannover.de>
  6. Sender: news@newsserver.rrzn.uni-hannover.de (News Service)
  7. Reply-To: dehning@tnt.uni-hannover.de
  8. Organization: Universitaet Hannover, Theoretische Nachrichtentechnik
  9. References: <1992Sep11.062847.11139@csis.dit.csiro.au>
  10. Date: Tue, 15 Sep 1992 06:45:21 GMT
  11. Lines: 295
  12.  
  13. In article 11139@csis.dit.csiro.au, gjw@csis.dit.csiro.au (Graham Williams) writes:
  14. >In Lucid Common Lisp and CMU Common Lisp, for example, when running
  15. >under X11 I have things configured to run the supplied X11 Window based
  16. >editor when (ed) is called (both implemented, I presume, using CLX).  This
  17. >works fine under straight X11R4.  Under OpenWindows, with the default
  18. >usage of xauthority rather than xhost, I get the following
  19. >authorization error:
  20. >
  21. >    Connection failure to X11.0 server unix display 0: Internal error
  22. >    during connection authorization check
  23. >
  24. >    (xlib::x-error xlib:connection-failure :major-version 11 
  25. >    :minor-version ...)
  26. >
  27. >Short of asking OpenWindows not to use the xauthority security
  28. >mechanism, how can I convince OpenWindows that the editor is
  29. >authorised!
  30.  
  31. There is a patch to CLX from Simon Leinen <simon@lia.di.epfl.ch>:
  32.  
  33. ---------- Cut here ------------------------------------
  34. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  35. ;;; File Name:      clx-auth.lisp
  36. ;;; Description:  Reading X Authority Databases
  37. ;;; Author:      Simon Leinen (simon@lia.di.epfl.ch)
  38. ;;; Date Created: 14-Feb-92
  39. ;;; RCS $Header$  
  40. ;;; RCS $Log$      
  41. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  42. ;;; Copyright (C) 1987 Texas Instruments Incorporated.
  43. ;;; Copyright (C) 1992 Ecole Polytechnique Federale de Lausanne
  44. ;;; 
  45. ;;; Permission is granted to any individual or institution to use,
  46. ;;; copy, modify, and distribute this software, provided that this
  47. ;;; complete copyright and permission notice is maintained, intact, in
  48. ;;; all copies and supporting documentation.
  49. ;;; 
  50. ;;; Texas Instruments Incorporated provides this software "as is" without
  51. ;;; express or implied warranty.
  52. ;;; 
  53. ;;; EPFL provides this software "as is" without express or implied
  54. ;;; warranty.
  55. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  56. ;;; This replacement version of the CLX open-display function tries to
  57. ;;; retrieve the authorization data for the given display from a file.
  58. ;;; The name of the authorization file is given by the XAUTHORITY
  59. ;;; environment variable.  If this variable is not set, a file named
  60. ;;; ".Xauthority" under the user's home directory is scanned.  In
  61. ;;; connection with automatic cookie setup as with XDM, this change
  62. ;;; increases network transparency (and security).
  63. ;;;
  64. ;;; Tested on:
  65. ;;;    CMU CL 16e (Sun 4)
  66. ;;;    Allegro CL 4.1 (Sun 4) and 4.1BETA (SGI)
  67. ;;;    Lucid CL 4.0.2 (Sun 4)
  68. ;;;    Genera 8.0.2 (UX Ivory)
  69. ;;; [should work with other releases of these Lisps as well.]
  70. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  71.  
  72. (in-package "XLIB")
  73.  
  74. #-CLX-MIT-R5
  75. (defvar *output-buffer-size* 8192)
  76.  
  77. (defun open-display (host  &rest options &key (display 0) protocol
  78.              authorization-name authorization-data &allow-other-keys)
  79.   ;; Changed by Simon Leinen <simon@lia.di.epfl.ch>:
  80.   ;; If no authorization information is given, try to find it out.
  81.   ;;
  82.   (declare (type integer display)
  83.        (dynamic-extent options))
  84.   (declare (values display))
  85.   (unless (or authorization-name authorization-data)
  86.     (multiple-value-setq (authorization-name authorization-data)
  87.       (get-authorization-key host display protocol)))
  88.   ;; PROTOCOL is the network protocol (something like :TCP :DNA or :CHAOS). See OPEN-X-STREAM.
  89.   (let* ((stream (open-x-stream host display protocol))
  90.      (disp (apply #'make-buffer
  91.               *output-buffer-size*
  92.               'make-display-internal
  93.               :host host
  94.               :display display
  95.               :output-stream stream
  96.               :input-stream stream
  97.               :allow-other-keys t
  98.               options))
  99.      (ok-p nil))
  100.     (unwind-protect
  101.     (progn
  102.       (display-connect disp
  103.                :authorization-name authorization-name
  104.                :authorization-data authorization-data)
  105.       (initialize-resource-allocator disp)
  106.       (initialize-predefined-atoms disp)
  107.       (initialize-extensions disp)
  108.       (setq ok-p t))
  109.       (unless ok-p (close-display disp :abort t)))
  110.     disp))
  111.  
  112. (defun get-authorization-key (host display protocol)
  113.   (let ((auth-file (authority-file-name)))
  114.     (if (not (probe-file auth-file))
  115.     (values nil nil)
  116.       (let ((display-number-as-string (prin1-to-string display)))
  117.     (ecase protocol
  118.       ((:tcp nil)
  119.        (let ((host-address (host-address host :internet)))
  120.          (with-open-file (auth auth-file)
  121.            (loop
  122.            (multiple-value-bind (address number name data)
  123.                (read-xauth-entry auth)
  124.              (unless address
  125.                (return nil))
  126.              (when (and (equal host-address address)
  127.                 (string= number display-number-as-string))
  128.                (return (values name data)))))))))))))
  129.  
  130. (defun authority-file-name ()
  131.   (let ((xauthority (getenv "XAUTHORITY")))
  132.     (or xauthority
  133.     #-Genera
  134.     (make-pathname
  135.      :name ".Xauthority"
  136.      :type nil
  137.      :defaults (user-homedir-pathname))
  138.     #+Genera
  139.     (make-pathname
  140.      :name ""
  141.      :type "Xauthority"
  142.      :defaults (user-homedir-pathname)))))
  143.  
  144. (defun getenv (name)
  145.   #+Allegro (sys:getenv name)
  146.   #+Lucid (lcl:environment-variable name)
  147.   #+CMU (cdr (assoc name ext:*environment-list* :test #'string=))
  148.   #-(or Allegro Lucid CMU)
  149.   nil)
  150.  
  151. (defun read-xauth-entry (stream)
  152.   (let ((family (net-read-short stream nil)))
  153.     (and family
  154.      (let* ((address (net-read-short-length-string stream))
  155.         (number (net-read-short-length-string stream))
  156.         (name (net-read-short-length-string stream))
  157.         (data (net-read-short-length-string stream)))
  158.        (values (decode-address family address) number name data)))))
  159.  
  160. (defun decode-address (family address)
  161.   (ecase family
  162.     ((0)
  163.      (list :internet (char-int (schar address 0))
  164.        (char-int (schar address 1))
  165.        (char-int (schar address 2))
  166.        (char-int (schar address 3))))
  167.     ((256)
  168.      ;; is it ok to return address as a string?
  169.      (list :unix address))))
  170.  
  171. (defun net-read-short (stream &optional (errorp t) (eof-value nil))
  172.   (let ((high-byte-char (read-char stream errorp nil)))
  173.     (if (not high-byte-char)
  174.     eof-value
  175.     (+ (* (char-int high-byte-char) 256)
  176.        (char-int (read-char stream))))))
  177.  
  178. (defun net-read-short-length-string (stream)
  179.   (let ((length (net-read-short stream)))
  180.     (let ((string (make-string length)))
  181.       (dotimes (k length)
  182.     (setf (schar string k) (read-char stream)))
  183.       string)))
  184.  
  185. #+Allegro
  186. (defun host-address (host &optional (family :internet))
  187.   (labels ((no-host-error ()
  188.          (error "Unknown host ~S" host))
  189.        (no-address-error ()
  190.          (error "Host ~S has no ~S address" host family)))
  191.     (let ((hostent (ipc::gethostbyname host)))
  192.       (unwind-protect
  193.        (progn
  194.          (when (zerop hostent)
  195.            (no-host-error))
  196.          (ecase family
  197.            ((:internet)
  198.         (unless (= (ipc::hostent-addrtype hostent) 2)
  199.           (no-address-error))
  200.         (assert (= (ipc::hostent-length hostent) 4))
  201.         (let ((addr (ipc::hostent-addr hostent)))
  202.            (when (or (member comp::.target.
  203.                      '(:hp :sgi4d :sony :dec3100)
  204.                      :test #'eq)
  205.                  (probe-file "/lib/ld.so"))
  206.              ;; BSD 4.3 based systems require an extra indirection
  207.              (setq addr (si:memref-int addr 0 0 :unsigned-long)))
  208.           (list :internet
  209.             (si:memref-int addr 0 0 :unsigned-byte)
  210.             (si:memref-int addr 1 0 :unsigned-byte)
  211.             (si:memref-int addr 2 0 :unsigned-byte)
  212.             (si:memref-int addr 3 0 :unsigned-byte))))))
  213.     (ff:free-cstruct hostent)))))
  214.  
  215. #+CMU
  216. (defun host-address (host &optional (family :internet))
  217.   (labels ((no-host-error ()
  218.          (error "Unknown host ~S" host))
  219.        (no-address-error ()
  220.          (error "Host ~S has no ~S address" host family)))
  221.     (let ((hostent (ext:lookup-host-entry host)))
  222.       (when (not hostent)
  223.     (no-host-error))
  224.       (ecase family
  225.     ((:internet)
  226.      (unless (= (ext::host-entry-addr-type hostent) 2)
  227.        (no-address-error))
  228.      (let ((addr (first (ext::host-entry-addr-list hostent))))
  229.        (list :internet
  230.          (ldb (byte 8 24) addr)
  231.          (ldb (byte 8 16) addr)
  232.          (ldb (byte 8  8) addr)
  233.          (ldb (byte 8  0) addr))))))))
  234.  
  235. #+Lucid
  236. (progn
  237.  
  238. (lcl:def-foreign-struct sockaddr-in
  239.             (family :type :signed-16bit)
  240.             (port :type :unsigned-16bit)
  241.             (addr :type (:array :unsigned-8bit (4)))
  242.             (zero :type (:array :signed-8bit (8))))
  243.  
  244. (lcl:def-foreign-struct hostent
  245.             (h_name :type (:pointer :char))
  246.             (h_aliases :type (:pointer (:pointer :char)))
  247.             (h_addrtype :type :signed-32bit)
  248.             (h_length :type :signed-32bit)
  249.             (h_addr_list :type (:pointer (:array (:pointer :char) (1)))))
  250.  
  251. (lcl:def-foreign-function
  252.  (libc-gethostbyname (:return-type (:pointer hostent))
  253.              (:name "_gethostbyname")
  254.              (:language :c))
  255.  (name (:pointer :character)))
  256.  
  257. (defun malloc-foreign-string (string)
  258.   (check-type string string)
  259.   (let ((foreign-string
  260.      (lcl:malloc-foreign-pointer
  261.       :type
  262.       `(:pointer (:array :character (,(1+ (length string))))))))
  263.     (setf (lcl:foreign-string-value foreign-string) string)
  264.     (setf (lcl:foreign-pointer-type foreign-string)
  265.       '(:pointer :character))
  266.     foreign-string))
  267.  
  268. (defun host-address (name &optional (family :internet))
  269.   (check-type name string)
  270.   (let ((foreign-name (malloc-foreign-string name)))
  271.     (unwind-protect
  272.     (let ((hostent (libc-gethostbyname foreign-name)))
  273.       (if (zerop (lcl:foreign-pointer-address hostent))
  274.           nil
  275.         (case (hostent-h_addrtype hostent)
  276.            ((2) ;AF_INET
  277.             (and (eq family :internet)
  278.              (cons :internet
  279.                    (make-ip-address
  280.                 (lcl:foreign-aref
  281.                  (hostent-h_addr_list hostent)
  282.                  0)))))
  283.            (otherwise nil))))
  284.       (lcl:free-foreign-pointer foreign-name))))
  285.  
  286. (defun make-ip-address (foreign-char-pointer)
  287.   (setf (lcl:foreign-pointer-type foreign-char-pointer)
  288.     '(:pointer (:array :unsigned-8bit (4))))
  289.   (list (lcl:foreign-aref foreign-char-pointer 0)
  290.     (lcl:foreign-aref foreign-char-pointer 1)
  291.     (lcl:foreign-aref foreign-char-pointer 2)
  292.     (lcl:foreign-aref foreign-char-pointer 3)))
  293.  
  294. );; #+Lucid
  295.  
  296. ---------- Cut here ------------------------------------
  297.  
  298.  
  299.  
  300.  Oliver Dehning
  301. ______________________________________________________________________________
  302. Dipl.-Ing. Oliver Dehning               |Universitaet Hannover
  303. RFC:dehning@tnt.uni-hannover.de                   |Theoretische Nachrichtentechnik
  304. X400:c=de;a=dbp;p=uni-hannover;ou=tnt;s=dehning|Appelstr. 9A
  305. PSI: 4551104302::dehning               |D W3000 Hannover 1
  306. FAX: +49-511-762-5333  PHONE: +49-511-762-5327 |Federal Republic of Germany
  307.  
  308.