#165375 - 2006-08-03 01:09 AM
Query LDAP attributes (non-AD)
|
akn
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
|
|
|
|
#165377 - 2006-08-03 03:55 AM
Re: Query LDAP attributes (non-AD)
|
Benny69
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
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 764 anonymous users online.
|
|
|