Page 1 of 1 1
Topic Options
#165375 - 2006-08-03 01:09 AM Query LDAP attributes (non-AD)
akn Offline
Lurker

Registered: 2006-08-03
Posts: 2
g'day,

How can I access the attributes in an LDAP database that contains user info? I'm using the following and get the uid but don't know how to read attributes like title or displayName.

Code:

$ldap="LDAP://luke.abc.ca/uid=@userid, ou=people, DC=abc, DC=ca"
dim $aFilter[0], $pos, $objOU
$objOU = GetObject($LDAP)
? $objOU.Name
if VarTypeName($objOU)='Object'
? "object found "
? $objOU.displayName



Thanks, suggestions would be welcome.

ak

Top
#165376 - 2006-08-03 01:16 AM Re: Query LDAP attributes (non-AD)
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Non-AD eh ? Are you at least getting this ...

"object found "

... displayed ? If so, what happens with this:

? $objOU.displayName
?"ERROR @ERROR - @SERROR"

-Shawn

Top
#165377 - 2006-08-03 03:55 AM Re: Query LDAP attributes (non-AD)
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
try changeing uid=@userid to cn=@FullName

or maybe even better try this code:

Code:

Global $UserdistinguishedName,$defaultNamingContext

$objRootDSE = GetObject("LDAP://rootDSE")
$defaultNamingContext = $objRootDSE.Get("defaultNamingContext")

GetUserdistinguishedName(@FULLNAME,@DOMAIN)

? "UserdistinguishedName: " + $UserdistinguishedName

$objOU = GetObject("LDAP://"+$UserdistinguishedName)
;? $objOU.Name
$objUser.GetInfo
$FirstName = $objUser.Get("givenName")
$LastName = $objUser.Get("sn")
$DisplayName = $objUser.Get("displayName")
$Title = $objUser.Get("title")

? $FirstName
? $LastName
? $DisplayName
? $Title

? "Done!"

Get $a

Function GetUserDistinguishedName($FullName,$Domain)

$ADS_UF_ACCOUNTDISABLE = 2

$ObjConnectION = CreateObject("ADODB.ConnectION")
$ObjConnectION.Open("PROVIDER=ADSDSOOBJECT;")
$ObjCOMMAND = CreateObject("ADODB.COMMAND")
$ObjCOMMAND.ActiveConnectION = $ObjConnectION
$ObjCOMMAND.COMMANDTEXT = "<GC://" + $defaultNamingContext + ">;(OBJECTCATEGORY=User);UserACCOUNTCONTROL,DistinguishedName;SUBTREE"
$ObjRecordset = $ObjCOMMAND.Execute
While Not $ObjRecordset.EOF
$POSITIVE = InStr($ObjRecordset.Fields("DistinguishedName"),"CN=" + $FullName)
If $POSITIVE <> 0
$ObjUser = GetObject("LDAP://" + $ObjRecordset.Fields("DistinguishedName"))
$ObjUser.GetInfo
$UserDistinguishedName = $ObjUser.Get("DistinguishedName")
EndIf
$ObjRecordset.MoveNext
Loop
$ObjConnectION.Close

EndFunction




Edited by benny69 (2006-08-03 05:07 AM)

Top
#165378 - 2006-08-04 07:50 PM Re: Query LDAP attributes (non-AD)
akn Offline
Lurker

Registered: 2006-08-03
Posts: 2
g'day,

Thanks for the suggestions. I can get the data in some of the attribute fields, thanks to your help. Attribute fields that can hold multiple entries will return a value. Attribute fields like 'displayName', where only a single entry is allowed, still do not pass on the data to the variable. 'givenName' can hold multiple entries but in this case has only one, and it can be recovered.


Code:

? $objOU.Name
if VarTypeName($objOU)='Object'
? "object found "
; $objOU.GetInfo (this did not seem to be needed)
$dispName = $objOU.Get("displayName")
$dispTitle = $objOU.Get("title")
$dispGName = $objOU.Get("givenName")
? $dispName
? len($dispName)
? $dispGName
for each $item in $dispTitle
? $item
next

------
returns -->
------
uid=akn
object found

0
Agivenname
master
mistress
general



Can someone help by passing on the proper syntax to read single entry fields from the attributes?

akn

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 764 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.061 seconds in which 0.029 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org