I have two domains. One production. One testing. There is no trust between the two.
I can import all user objects and group objects successfully using ldifde commands. When I attempt to also include group members in my export/import I can't seem to successfully import.
Here are the variations I have tried:
Attempt 1:
file format:
dn: CN=Group-name,OU=Groups,OU=Managed,DC=dev,DC=net
changetype: add
member: CN=USER1,OU=Users,OU=Managed,DC=dev,DC=net
member: CN=USER2,OU=Users,OU=Managed,DC=dev,DC=net
ldifde command used:
ldifde -i -k -f groupexp12072012-test.ldf -v
output:
Connecting to "DC"
Logging in as current user using SSPI
Importing directory from file "groupexp12072012-test.ldf"
Loading entries
1: CN=Group-name,OU=Groups,OU=Managed,DC=dev,DC=net
Add error on line 1: Object Class Violation
The server side error is "The object class attribute must be specified."
0 entries modified successfully.
An error has occurred in the program
No log files were written. In order to generate a log file, please
specify the log file path via the -j option.
Attempt 2:
Added in the correct objectClass to my ldifde import file:
file format:
dn: CN=Group-name,OU=Groups,OU=Managed,DC=dev,DC=net
changetype: add
objectClass: top
objectClass: group
member: CN=USER1,OU=Users,OU=Managed,DC=dev,DC=net
member: CN=USER2,OU=Users,OU=Managed,DC=dev,DC=net
ldifde command used:
ldifde -i -k -f groupexp12072012-test.ldf -v
output:
Connecting to "DC"
Logging in as current user using SSPI
Importing directory from file "groupexp12072012-test.ldf"
Loading entries
1: CN=Group-name,OU=Groups,OU=Managed,DC=dev,DC=net
Entry already exists, entry skipped
0 entries modified successfully.
The command has completed successfully
Attempt 3:
Deleted the existing group object and used the same command and format as "Attempt 2":
Connecting to "DC"
Logging in as current user using SSPI
Importing directory from file "groupexp12072012-test.ldf"
Loading entries
1: CN=Group-name,OU=Groups,OU=Managed,DC=dev,DC=net
Object does not exist, entry skipped
0 entries modified successfully.
So I'm stuck. Apparently 'ldifde' can be used to import group members - all my colleagues say it has never worked but I stumble upon MS articles that say otherwise;
http://social.technet.microsoft.com/Forums/nl/winserverDS/thread/089a3f3b-617f-4c66-a3fc-be543d97a612
Then I stumble on "5. LDIFDE doesn’t support changing Group Membership. You can use CSVDE or ADDUSERS.exe or DStools for Windows 2003 Editions." here:
http://support.microsoft.com/kb/555634
Am I going crazy for no reason - will I ever succeed using 'ldifde'?
edit: Yes, I was going crazy for no reason. One of my targeted users was actually in a different OU I was specifying for 'ldifde'. Because of this, 'ldifde' would just give up and not add any members to the group.
Here is a way to add users to an existing group (ldifde -i -k -f AddGrpMember.ldf -v
):
dn: CN=MonGrpSec,OU=MonOu,DC=dom,DC=fr
changeType: Modify
add: member
member: CN=jblanc,OU=MonOu,DC=dom,DC=fr
member: CN=Jean Paul Blanc,OU=MonOu,DC=dom,DC=fr
-
Here is a way to create a new group with members (ldifde -i -k -f NewGrpWithMember.ldf -v
):
dn: CN=NewGrpSec,OU=MonOu,DC=dom,DC=fr
changeType: Add
objectClass: top
objectClass: group
CN: NewGrpSec
member: CN=jblanc,OU=MonOu,DC=dom,DC=fr
member: CN=Jean Paul Blanc,OU=MonOu,DC=dom,DC=fr
ldifde import of group members fails if the group members do not exist, or the dn in the file does not match the dn of the target group.
For a few important groups in my test domain, I word to replace "member:" with the entire header to modify a group. That way any individual group member doesn't halt the rest of the group members from importing.
Simple find and replace
find: member:
replace with: -^p^pdn:CN=[groupname],OU=[ou name],OU=Domain Users,DC=TEST,DC=ORG^pchangetype: modify^padd:member^pmember:
Basically, add a "-" followed by a blank line, and then the header lines.
Related
Given a username and a group, I need a simple LDAP query to run that can query if the username is a member of an Active Directory security group.
Here is what I have tried, but it is not running:
<LDAP://DC=subdomain,DC=domain,DC=com>;(&(objectClass=user)(sAMAccountName=myusername)(memberof=CN=Domain Admins,OU=Users,DC=subdomain,DC=domain,DC=com))
Am I missing something? Single quotes around Domain Admins? Or something else?
Generally LDAP queries for groups require the fully distinguished name of the user and the Group.
If you know the specific group then a LDAP Query like:
ldapsearch -H ldaps://server.domain.com:636 -x -D "adminguy#domain.com" -W -b "CN=myusername,CN=Users,DC=domain,DC=com" -s sub -a always -z 1000 "(&(sAMAccountName=myusername)(Memberof=CN=Domain Admins,OU=Users,DC=subdomain,DC=domain,DC=com))" "objectClass"
That returns a DN implies there the user sAMAccountName=myusername is a member of that specific Group.
If no DNS are returned then there is not sAMAccountName=myusername that is a member of that specific group.
However, this would not include any nested groups.
I'm really bad at LDAP so I don't really know where to start.
Is it possible to make a new distrubution or security group with users from another group that has a specific Title? There are too many users to add them manually.
It would be helpful to know how you want to interact with AD -- writing a program (language?) or using an LDAP client (which one?). I'll provide info on using ldifde.exe from the remote server administration tools. To get a list of DNs that are in another group and have a specific title, use a filter with the title and membership requirement
ldifde -f output.txt -r "(&(title=Desired Title)(memberOf=cn=GroupName,ou=Groups,dc=example,dc=com))" -l "NULL"
This returns user records that are direct members of the specified group (you'll need the fully qualified LDAP DN of the group, wildcards are not supported for memberOf -- the example is a group named "GroupName" in an OU called "Groups" at the root of the example.com AD).
Then you need to create a new group with the identified user DNs as members. The output.txt file will have a lot of lines that say "changetype: add\n\n" ... get rid of those so you've just got DNs. Change the "dn: " to "member: ". Prepend the following information to the list of group members to create an LDIF file to create a new global security group:
dn: CN=GroupName,OU=Groups,dc=example,dc=com
changetype: add
objectClass: group
cn: GroupName
distinguishedName: CN=GroupName,OU=Groups,dc=example,dc=com
instanceType: 4
name: GroupName
sAMAccountName: GroupName
groupType: -2147483646
objectCategory: CN=Group,CN=Schema,CN=Configuration,dc=example,dc=com
member: CN=Person1,OU=ResourceUsers,dc=example,dc=com
member: CN=Person2,OU=ResourceUsers,dc=example,dc=com
member: CN=Person3,OU=ResourceUsers,dc=example,dc=com
member: CN=Person4,OU=ResourceUsers,dc=example,dc=com
member: CN=Person5,OU=ResourceUsers,dc=example,dc=com
Import the LDIF file using:
ldifde -i -v -k -y -f output.txt
The group will be created & populated with the accounts listed in the "member" attribute.
This doesn't do anything if you add a new person to the first group with the desired title -- this is a one-time snapshot. You can easily identify people who should be added/removed from the second group
Need to be added -- anyone with desired title who is a member of SourceGroupName but not a member of CreatedGroupName:
(&(title=Desired Title)(memberOf=cn=SourceGroupName,ou=Groups,dc=example,dc=com)(!(memberOf=cn=CreatedGroupName,ou=Groups,dc=example,dc=com)))
Need to be removed -- anyone who is a member of CreatedGroupName who is not a member of SourceGroupName or does not have the desired title.
(&(memberOf=cn=CreatedGroupName,ou=Groups,dc=example,dc=com)(|(!(title=Desired Title))(!(memberOf=cn=SourceGroupName,ou=Groups,dc=example,dc=com))))
Add/remove members from the new group as individuals match one of these two filters.
I am trying to search for All Groups and Members under a specific OU in my Active Directory.
The below query works fine.
ldapsearch -o ldif-wrap=no -b OU=BUSINESS_DOMAIN,OU=ONE,DC=myserver,DC=com -s one '(cn=*)' member cn
I can get the group names and member names(CN) from the AD. But is there a way to get the member emails as well?
Should I iterate over each member and trigger a separate LDAP Search programmatically or can I create a chained query?
EDIT
Based on the comments, adding more clarity- I am looking for email id of all users embedded under groups under a given OU.
This should work:
ldapsearch -o ldif-wrap=no -b OU=BUSINESS_DOMAIN,OU=ONE,DC=myserver,DC=com -s one '(cn=*)' member cn mail
Assuming you are using the LDAP standard email address attribute "mail" for the email address.
What is the best way to remove all members from a group in AD?
The help for ldapmodify doesn't seem to support the ability to remove all members of a group.
I found an example of removing a particular dn using:
ldapmodify -h 127.0.0.1 -D "cn=admin" -w xxxx -f modStaticGrp.ldif
Where modStaticGrp.ldif contains:
dn: cn=group1, o=Your Company
changetype: modify
delete: member
member: cn=jeff, cn=tim, o=Your Company
I would like to have a bash script with ldapmodify running a command that removes all the users in a group. What would be the best way to accomplish this?
ldapmodify doesn't seem to support the ability to remove all members of a group.
Yes it does. See man ldapmodify and man ldif. Just truncate your LDIF after the delete: member line. If no attribute values to delete are supplied, the entire attribute is deleted.
We have an LDAP login problem of a specific user and I'm suspecting that this is due to cyclic groups assignment in LDAP, i.e. the user is assigned to groups A,B,C,D. Group A contains sub-groups E,F,G and group E contains group A again.
If I query for the user I can see that he has been assigned with 50+ groups and each group may contain more groups and each of those may contain more....
My question is if there's a query I can run to get the nested groups inside those main groups all the way down instead of going each group and do it manually?
The server is AD
To find all the groups that "user1" is a member of (adaptation of this answer see AD search filter):
Set the base to the groups container DN; for example root DN (dc=dom,dc=fr)
Set the scope to subtree
Use the following filter : (member:1.2.840.113556.1.4.1941:=cn=user1,cn=users,DC=x)
Example with LDIFDE.EXE (native command line AD search on windows) :
ldifde -f t.txt -d "DC=dom,DC=fr" -r "(member:1.2.840.113556.1.4.1941:=CN=jblanc,OU=MonOu,DC=dom,DC=fr)"
Remark : as far as I remember there is a small syntax difference with in brackets user DN name. '1.2.840.113556.1.4.1941' is not working in W2K3 SP1, it begins to work with SP2. I presume it's the same with W2K3 R2. I test here with W2K8R2.
With Apache Directory Studio :
Result :