Adding n.p.m.directory and directing followups there, as that's a more
appropriate group for this question.
Aesir wrote:
I am writing a BHO that requires me to authenticate via an LDAP server.
I am writing in Javascript and haven't been able to find much in the
way of documentation or examples. I'm using the following code:
var dataListener =
{
onLDAPInit: function(conn, status)
{
alert("1st con, status = "+status);
},
onLDAPMessage: function(message)
{
alert("Message = "+ message);
},
};
var conListener =
{
onLDAPInit: function(conn, status)
{
alert("Con Conned, status = "+ status);
},
onLDAPMessage: function(message)
{
alert("Con Message = "+ message);
},
};
var dn = "uid="+uname+", ou=People, o=stolaf.edu";
var connection =
Components.classes["@mozilla.org/network/ldap-connection;1"].createInstance(Components.interfaces.nsILDAPConnection);
connection.init("ldap.stolaf.edu",389,true,dn,dataListener,null,2);
var ldapCon =
Components.classes["@mozilla.org/network/ldap-operation;1"].createInstance(Components.interfaces.nsILDAPOperation);
ldapCon.init(connection, conListener, null);
ldapCon.simpleBind(pwd);
I get the following alert: "1st con, status = 0" for the above code.
If I replace ldap.stolaf.edu with ldaps://ldap.stolaf.edu/ I get the
following alert: "1st con, status = 2152398878".
The way the code is now is specifying the hostname correctly. In
general, it's easier to figure out what a status code means if you dump
it in hex (ie status.toString(16)). However, in this case, I can see
the issue from looking at the code: you can't call init until simpleBind
has completed, which means that you need to call simpleBind from the
onLDAPInit() callback (which you may or may not want to proxy back to
the main thread).
Either way I also get the following Javascript error:
Error: [Exception... "Component returned failure code: 0x8000ffff
(NS_ERROR_UNEXPECTED) [nsILDAPOperation.simpleBind]" nsresult:
"0x8000ffff (NS_ERROR_UNEXPECTED)" location: "JS frame ::
chrome://cpet/content/cpet.js :: CPET_ProcessLogon :: line 320" data:
no]
Source File: chrome://cpet/content/cpet.js
Line: 320
NS_ERROR_UNEXPECTED isn't really a good error for this; we can do
better. I've filed bug 304095 about this.
What's more, the LDAP server logs never show the computer I'm working
on as having connected at all so I don't know where the status messages
are coming from. If you can help me or point me to a place where I can
get help I would appreciate it. The xulplanet.com docs just aren't
cutting it.
So basic docs for the latest CVS versions of the LDAP XPCOM SDK can be
found at <http://lxr.mozilla.org/source/directory/xpcom/base/public/>.
Additionally, the LDAP XPCOM SDK is really just a wrapper around the
LDAP C SDK (albeit a slightly dated version), and docs for that live at
<http://www.mozilla.org/directory/csdk.html>. The Programmers Guide
link on that page is likely to be especially useful.
Dan
_______________________________________________
Mozilla-xpcom mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-xpcom