+2005-05-31 Arne J\e,Ax\e(Brgensen <arne@arnested.dk>
+
+ * smime-ldap.el (smime-ldap-search): Add compatibility for XEmacs.
+
+ * smime.el (smime-cert-by-ldap-1): Handle certificates distributed
+ in PEM format. Adjust to the XEmacs compability.
+
2005-05-30 Reiner Steib <Reiner.Steib@gmx.de>
* encrypt.el (encrypt-xor-process-buffer): Replace `string-to-int'
;; made to achieve compatibility with OpenLDAP v2 and to make it
;; possible to retrieve LDAP attributes that are tagged ie ";binary".
-;; When Gnus drops support for Emacs 21.x this file can be removed and
-;; smime.el changed to
-
-;; - (require 'smime-ldap) => (require 'ldap)
-;; - (smime-ldap-search ...) => (ldap-search ...)
-
-;; If we are running in Emacs 22 or newer it just uses the build-in
-;; version of ldap-search.
+;; The file also adds a compatibility layer for Emacs and XEmacs.
;;; Code:
Additional search parameters can be specified through
`ldap-host-parameters-alist', which see."
(interactive "sFilter:")
- (if (>= emacs-major-version 22)
- (ldap-search filter host attributes attrsonly)
- (or host
- (setq host ldap-default-host)
- (error "No LDAP host specified"))
- (let ((host-plist (cdr (assoc host ldap-host-parameters-alist)))
- result)
- (setq result (smime-ldap-search-internal
- (append host-plist
- (list 'host host
- 'filter filter
- 'attributes attributes
- 'attrsonly attrsonly
- 'withdn withdn))))
- (if ldap-ignore-attribute-codings
- result
- (mapcar (function
- (lambda (record)
- (mapcar 'ldap-decode-attribute record)))
- result)))))
+ ;; for XEmacs
+ (if (fboundp 'ldap-search-entries)
+ (ldap-search-entries filter host attributes attrsonly)
+ ;; for Emacs 22
+ (if (>= emacs-major-version 22)
+ (cdr (ldap-search filter host attributes attrsonly))
+ ;; for Emacs 21.x
+ (or host
+ (setq host ldap-default-host)
+ (error "No LDAP host specified"))
+ (let ((host-plist (cdr (assoc host ldap-host-parameters-alist)))
+ result)
+ (setq result (smime-ldap-search-internal
+ (append host-plist
+ (list 'host host
+ 'filter filter
+ 'attributes attributes
+ 'attrsonly attrsonly
+ 'withdn withdn))))
+ (cdr (if ldap-ignore-attribute-codings
+ result
+ (mapcar (function
+ (lambda (record)
+ (mapcar 'ldap-decode-attribute record)))
+ result)))))))
(defun smime-ldap-search-internal (search-plist)
"Perform a search on a LDAP server.
host '("userCertificate") nil))
(retbuf (generate-new-buffer (format "*certificate for %s*" mail)))
cert)
- (if (> (length ldapresult) 1)
+ (if (>= (length ldapresult) 1)
(with-current-buffer retbuf
- (setq cert (base64-encode-string (nth 1 (car (nth 1 ldapresult))) t))
+ ;; Certificates on LDAP servers _should_ be in DER format,
+ ;; but there are some servers out there that distributes the
+ ;; certificates in PEM format (with or without
+ ;; header/footer) so we try to handle them anyway.
+ (if (or (string= (substring (cadaar ldapresult) 0 27)
+ "-----BEGIN CERTIFICATE-----")
+ (condition-case nil
+ (base64-decode-string (cadaar ldapresult))
+ (error nil)))
+ (setq cert
+ (replace-regexp-in-string "\\(\n\||\r\\|-----BEGIN CERTIFICATE-----\\|-----END CERTIFICATE-----\\)" "" (cadaar ldapresult) t))
+ (setq cert (base64-encode-string (cadaar ldapresult) t)))
(insert "-----BEGIN CERTIFICATE-----\n")
(let ((i 0) (len (length cert)))
(while (> (- len 64) i)