Recently I had to deal with a LDAP server using my old beloved LotusScript language.
After some search I found the following free LotusScript extension (LSX) that is really useful for my needs:
LotusScript Directory Service for Windows
From the IBM Sandbox:
LotusScript Directory Service is a small LotusScript Extension utility which is developed for testing LDAP protocol in Domino 5.0. It provides a simple and direct access to LDAP protocol using LotusScript. It facilitates four LotusScript classes to manipulate basic LDAP protocol, including search directory, add, modify and delete operation. Further operations like compare and rename will be available soon in future implementation.
Here's a sample code from Robein Shi (IBM) written in 1999!
1: Uselsx "lsxldap"
2: Option Explicit
3:
4:
5: Sub Initialize
6:
7: '----------------------------------------------------------------
8: ' Variable definition
9: '
10: Dim session As LDAPSession
11: Dim search As LDAPSearch
12: Dim result As LDAPResultSet
13: Dim entry As LDAPEntry
14:
15: Dim status As Variant
16: Dim num As Long
17: '---------------------------------------------------------------
18: ' Object instances
19: '
20: Set session = New LDAPSession
21: Set search = New LDAPSearch
22: Set result = New LDAPResultSet
23:
24: '--------------------------------------------------------------
25: ' Connect to LDAP server
26: '
27: session.dn = "cn=Cristian D'Aloisio,o=MyOrg,c=It"
28: session.password = "xxxx"
29:
30: 'using anonymouse here
31: session.Host = "172.30.10.25"
32: Print "Connecting to..." , session.Host
33:
34: status = session.Connect
35:
36: If status Then
37: Print "Connected to ", session.Host
38: Else
39: Print "Can't connect to", session.Host
40: Exit Sub
41: End If
42:
43:
44:
45: '------------------------------------------------------------
46: ' Object instances
47: '
48: Set search.Session = session
49: Set search.ResultSet = result
50:
51: '-------------------------------------------------------------
52: ' Perform a search - search specified entry
53: '
54: search.filter = "(objectclass=*)"
55: search.base = "cn=Cristian D'Aloisio,o=MyOrg,c=It"
56: search.scope = LDAP_SCOPE_BASE
57:
58: status = search.Execute
59: Print "Search.Execute", status
60:
61: num = result.count
62: Print "Result.count", num
63:
64: '-------------------------------------------------------------
65: 'Iterate search result using LDAPResultSet.GetNextEntry
66: '
67: ' Dim entry As LDAPEntry
68: Dim attr_name As String
69: Dim valuestr As String
70: Dim avalue As Variant
71:
72:
73: Set entry = result.GetFirstEntry()
74:
75: While Not (entry Is Nothing)
76: 'print "DN=", entry.DN
77:
78: '-------------------------------------------------------------
79: 'Iterate all attributes of this entry using GetNextAttr
80: '
81: attr_name = entry.getFirstAttr()
82: While Not (attr_name = "")
83:
84: '-------------------------------------------------------------
85: 'Get an array of values from LDAPEntry.GetValue
86: '
87: Dim i As Integer
88:
89: Print "Attribute: ", attr_name
90: avalue = entry.getValue(attr_name)
91: For i=Lbound(avalue) To Ubound(avalue)
92: Print ,, avalue(i)
93: Next
94:
95: attr_name = entry.getNextAttr()
96: Wend
97:
98: Set entry = result.GetNextEntry(entry)
99: Wend
100:
101: '--------------------------------------------------------------
102: 'Disconnect the session
103:
104: session.disconnect
105:
106:
107: End Sub
Things I'm worried about that utility are:
- it is a LSX written for the Windows OS, so I cannot use it on Linux;
- it's a little bit old code, published in year 2000;
- some users in the Sandox complain about some bugs (memory leaks, http crashes)
So what?
I wrote a small Java class, taking advantage of JNDI classes, to:
- connect to any LDAP server, using authentication ;
- get one specific (text) attribute (eg "cn") for a Distinguished Name (DN)
The Java class will be available in LotusScript via LS2J, I guess...
I know, that's really too little for a utility, but it's just the beginning ;-)
What I would like to add later to the Java class:
- reading any LDAP attribute, text or binary type, for a specific DN;
- writing some binary attribute, e.g. uploading images to a Domino LDAP server for Sametime contacts photos.. ( see previous Italian post )
Stay tuned...
4 comments:
I used this dll before. It is ok, if you restart your server or client on a regular basis, because the dll has a memory leak which consumes 40k each time a function is called in the dll.
Take a look at http://www.eknori.de/2008-06-23/autopopulategroup-scheduled-agent/
the function uses java to access LDAP. You can easily modify the code for your own need and use it on Linux and stuff.
Hi Ulrich,
thanks for your feedback!
I'll take a look to your Java agent, it is interesting.
My goal is letting LS developers use LDAP functions.
I could write a Java agent as you, and later call it by a LS agent and some params.
I already wrote a Java class in Eclipse to interface the LDAP server: next step should be coding the LS2J calls.
LS2J or Notes agent written in Java? ;-) What is best?
Since Blogger comment form brakes URL links, here is the link to Ulrich's article:
link
I'd love to see a nice LDAP util for LS. An agent would work fine too. Right now I'm on a project to search an AD LDAP and use the returned data to update Notes docs nightly. Ideally the Java/agent would return a result set, and then I could iterate through it and pull out the elements that I need (email, surname, cn, etc) to update the Notes doc.
I'll check out Ulrich's work tomorrow to see if I can get it to work for my purposes...thanks! Cristian, if you have anything ready for release, please let us know.
Post a Comment