From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Noah Lavine Newsgroups: gmane.emacs.devel Subject: Re: ldap.el Problem and Solution Date: Wed, 24 Oct 2012 14:58:50 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1351105134 24780 80.91.229.3 (24 Oct 2012 18:58:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 24 Oct 2012 18:58:54 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 24 20:59:02 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TR6AP-0003kU-Un for ged-emacs-devel@m.gmane.org; Wed, 24 Oct 2012 20:59:02 +0200 Original-Received: from localhost ([::1]:52956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TR6AI-0000XQ-ET for ged-emacs-devel@m.gmane.org; Wed, 24 Oct 2012 14:58:54 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TR6AG-0000Ws-6U for emacs-devel@gnu.org; Wed, 24 Oct 2012 14:58:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TR6AF-0008VF-2W for emacs-devel@gnu.org; Wed, 24 Oct 2012 14:58:52 -0400 Original-Received: from mail-oa0-f41.google.com ([209.85.219.41]:35920) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TR6AE-0008U3-UK for emacs-devel@gnu.org; Wed, 24 Oct 2012 14:58:51 -0400 Original-Received: by mail-oa0-f41.google.com with SMTP id k14so927251oag.0 for ; Wed, 24 Oct 2012 11:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=pjxQVU5wMV1CiAXNlkc+qqXa4HRJIekAvSBuCxcI5vU=; b=KrYy53pT4BVs2+fcRyuJN47c9MIIkvvNBLVw+ejYjoYNXW7XH3AbxYjRr5kc6O+M02 ZgsQ14iD6R41KN7np2KgIIMb6s0sQL1vbJdxEpRBefnzoq1QSyEt0dTJLm7iLmLaUpfR p/AUJhwyOstLXmFhd7cyXE+8W1oJP9F9+jHRMiACrkjb9Oizkp5Eb1pYgEVYUqe2fkVr /PDnVIe7sAhKYDUsrnodCAI7/GIJqoUDjqvAKcWM4Wd0B8w6YoREvly5NwnPvGNPdoJ1 Hkq0Cwbmu6xGhi4qsIgplb64l1FKvnSjfOLic0rWM4fE05cdwjKMMevJVVPhK5SXqy1b hipA== Original-Received: by 10.60.7.229 with SMTP id m5mr14578358oea.10.1351105130271; Wed, 24 Oct 2012 11:58:50 -0700 (PDT) Original-Received: by 10.76.120.236 with HTTP; Wed, 24 Oct 2012 11:58:50 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: -olp2B-33uiSGygzy_tSpoQ6fI0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.219.41 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:154494 Archived-At: Replying to myself, I found out that the "version:" header is actually required by RFC 2849, which defines LDIF (the LDAP Data Interchange Format). So trying to change my 'ldapsearch' program to omit it is definitely not the right approach here. The solution I posted earlier would work, but to be even more careful, the parser could throw an error if it saw "version: " followed by an integer greater than 1, because it doesn't know how to parse that. However, that seems very unlikely, given that this RFC has lasted since the year 2000 without revisions. Thanks, Noah Lavine On Wed, Oct 24, 2012 at 10:48 AM, Noah Lavine wrote: > Hello, > > I recently hit a problem in which ldap-search (in ldap.el) would > return a list of records where the first record would always be nil. > As far as I can tell, the rest of the list was correct; it just had an > extra nil in the beginning. > > After some debugging, I think the issue is that my ldapsearch program > (from OpenLDAP) doesn't quite use the output format ldap.el expects. > The expected format is > > dn: .......... > : > : > .... more attributes here ...... > > This is the ldif format, which seems to be standardized. But > tragically, my ldapsearch program prints a header, which makes the > results look like this: > > version: 1 > > dn: ......... > : > .... more attributes ..... > > This confuses the ldap.el parsing. I can tell this is the problem > because when I step through in the debugger, the "dn" variable is set > to "version: 1", instead of the obviously correct value. Then when it > attempts to parse its results it finds an empty record, and so pushes > 'nil onto its results list, which is what causes the problem. > > The solution is to insert this after line 579 of ldap.el: > > (if (looking-at "version:") > (forward-line 1)) > > I have tested this, and it seems to work for me. > > The other option is to make the ldapsearch program not print its > version header, but looking at its man page, I don't see a way to do > that. > > If this solution doesn't seem good, I am happy to try a different > approach, but it seems like the easiest solution to me. I have already > signed copyright papers, although for a change as small as this they > might not even be needed. > > Thanks, > Noah Lavine