comparison lisp/ldap.el @ 282:c42ec1d1cded r21-0b39

Import from CVS: tag r21-0b39
author cvs
date Mon, 13 Aug 2007 10:33:18 +0200
parents 7df0dd720c89
children 70ad99077275
comparison
equal deleted inserted replaced
281:090b52736db2 282:c42ec1d1cded
3 ;; Copyright (C) 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
4 4
5 ;; Author: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch> 5 ;; Author: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch>
6 ;; Maintainer: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch> 6 ;; Maintainer: Oscar Figueiredo <Oscar.Figueiredo@di.epfl.ch>
7 ;; Created: Jan 1998 7 ;; Created: Jan 1998
8 ;; Version: $Revision: 1.4 $ 8 ;; Version: $Revision: 1.5 $
9 ;; Keywords: help comm 9 ;; Keywords: help comm
10 10
11 ;; This file is part of XEmacs 11 ;; This file is part of XEmacs
12 12
13 ;; XEmacs is free software; you can redistribute it and/or modify it 13 ;; XEmacs is free software; you can redistribute it and/or modify it
39 (require 'ldap)) 39 (require 'ldap))
40 40
41 (defvar ldap-default-host nil 41 (defvar ldap-default-host nil
42 "*Default LDAP server.") 42 "*Default LDAP server.")
43 43
44 (defvar ldap-host-parameters-alist nil 44 (defvar ldap-host-parameters-plist nil
45 "*An alist describing per host options to use for LDAP transactions 45 "*A property list of per host options for LDAP transactions
46 The list has the form ((HOST OPTION OPTION ...) (HOST OPTION OPTION ...)) 46 The list elements look like (HOST PROP1 VAL1 PROP2 VAL2 ...)
47 HOST is the name of an LDAP server. OPTIONs are cons cells describing 47 HOST is the name of an LDAP server. PROPn and VALn are property/value pairs
48 parameters for the server. Valid options are: 48 describing parameters for the server. Valid properties:
49 (binddn . BINDDN) 49 `binddn' is the distinguished name of the user to bind as
50 (passwd . PASSWD) 50 (in RFC 1779 syntax).
51 (auth . AUTH) 51 `passwd' is the password to use for simple authentication.
52 (base . BASE) 52 `auth' is the authentication method to use.
53 (scope . SCOPE) 53 Possible values are: `simple', `krbv41' and `krbv42'.
54 (deref . DEREF) 54 `base' is the base for the search as described in RFC 1779.
55 (timelimit . TL) 55 `scope' is one of the three symbols `subtree', `base' or `onelevel'.
56 (sizelimit . SL)) 56 `deref' is one of the symbols `never', `always', `search' or `find'.
57 BINDDN is the distinguished name of the user to bind as (in RFC 1779 syntax). 57 `timelimit' is the timeout limit for the connection in seconds.
58 PASSWD is the password to use for simple authentication. 58 `sizelimit' is the maximum number of matches to return." )
59 AUTH is the authentication method to use, possible values are:
60 `simple', `krbv41' and `krbv42'.
61 BASE is the base for the search as described in RFC 1779.
62 SCOPE is one of the three symbols `subtree', `base' or `onelevel'.
63 DEREF is one of the symbols `never', `always', `search' or `find'.
64 TL is the timeout limit for the connection in seconds.
65 SL is the maximum number of matches to return." )
66 59
67 60
68 (defun ldap-search (filter &optional host attributes attrsonly) 61 (defun ldap-search (filter &optional host attributes attrsonly)
69 "Perform an LDAP search. 62 "Perform an LDAP search.
70 FILTER is the search filter in RFC1558 syntax 63 FILTER is the search filter in RFC1558 syntax
72 ATTRIBUTES is the specific attributes to retrieve, nil means 65 ATTRIBUTES is the specific attributes to retrieve, nil means
73 retrieve all 66 retrieve all
74 ATTRSONLY if non nil retrieves the attributes only without 67 ATTRSONLY if non nil retrieves the attributes only without
75 the associated values. 68 the associated values.
76 Additional search parameters can be specified through 69 Additional search parameters can be specified through
77 `ldap-host-parameters-alist' which see." 70 `ldap-host-parameters-plist' which see."
78 (interactive "sFilter:") 71 (interactive "sFilter:")
79 (let (host-alist res ldap) 72 (let (host-plist res ldap)
80 (if (null host) 73 (if (null host)
81 (setq host ldap-default-host)) 74 (setq host ldap-default-host))
82 (if (null host) 75 (if (null host)
83 (error "No LDAP host specified")) 76 (error "No LDAP host specified"))
84 (setq host-alist 77 (setq host-plist
85 (assoc host ldap-host-parameters-alist)) 78 (cdr (assoc host ldap-host-parameters-plist)))
86 (message "Opening LDAP connection to %s..." host) 79 (message "Opening LDAP connection to %s..." host)
87 (setq ldap (ldap-open host (alist-to-plist (cdr host-alist)))) 80 (setq ldap (ldap-open host host-plist))
88 (message "Searching with LDAP on %s..." host) 81 (message "Searching with LDAP on %s..." host)
89 (setq res (ldap-search-internal ldap filter 82 (setq res (ldap-search-internal ldap filter
90 (cdr (assq 'base host-alist)) 83 (plist-get host-plist 'base)
91 (cdr (assq 'scope host-alist)) 84 (plist-get host-plist 'scope)
92 attributes attrsonly)) 85 attributes attrsonly))
93 (ldap-close ldap) 86 (ldap-close ldap)
94 res)) 87 res))
95 88
96 89