Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: ax plains
RE: Retrieve logon names from an AD grupo [ reply ]  
2008-02-11 17:39
Sorry i found it:
it is "DistinguishedName and not "dn"...

By: ax plains
RE: Retrieve logon names from an AD grupo [ reply ]  
2008-02-11 17:31
I have a problem though: if I search the samaccountname using the following filter it does not work.
Am I missing something?

...
user_filter = Net::LDAP::Filter.eq( "dn", "CN=Doe John,OU=Users,DC=company,DC=com" )
...

By: ax plains
RE: Retrieve logon names from an AD grupo [ reply ]  
2008-02-11 14:56
Thanks a lot. Much appreciated.

By: James Hunt
RE: Retrieve logon names from an AD grupo [ reply ]  
2008-02-11 14:47
Pretty much. You'll have to loop over values in the group's `member' and launch a new LDAP search for each member, unless you can figure out a suitable way of queuing the dn's and running one big query with a huge OR filter.

Unfortunately, since LDAP isn't relational, concepts like SQL joins don't apply. On the upside, LDAP directories (including AD) are optimized for multiple reads.

By: ax plains
RE: Retrieve logon names from an AD grupo [ reply ]  
2008-02-11 14:42
Thanks James

You mean change the parameters and start a new ldap search for every "member" entry?

Do i need to set a new "user_filter" and "op_filter" for each entry?
Is there a more efficient way to do it?

Thank you

By: James Hunt
RE: Retrieve logon names from an AD grupo [ reply ]  
2008-02-11 14:35
Once you have the distinguished names of the members of the groups (which is stored in the `member' attribute of the group), you should do a search on them to retrieve the actual person object and from it, the sAMAccountName.

By: ax plains
Retrieve logon names from an AD grupo [ reply ]  
2008-02-11 11:49
Hello everyone,

Does anyone know how to get a list of logon names ("samaccountname") belonging to a group?

I already figured out how to get the names (but not the logons) this way:

groupname = "G-GROUPNAME"
treebase = "OU=Application,OU=Groups,DC=company,DC=com"
user_filter = Net::LDAP::Filter.eq( "CN", groupname )
op_filter = Net::LDAP::Filter.eq( "objectClass", "group" )
dn = Array.new
member = Array.new
cn = Array.new
attrs = ["cn", "member"]

ldap_con.search( :base => treebase, :filter => op_filter & user_filter, :attributes=> attrs) do |entry|
entry.each do |attr, values|

if "#{attr}" == "member" # THIS RETRIEVES THE "NAME" FIELD
members_of = Array.new
values.each { |str| members_of << str.split(',')[0].split('=')[1] }
for element in members_of
member << element
end
end

etc...

Thanks a lot in advance
axplains@yahoo.com