joeware - never stop exploring... :)

Information about joeware mixed with wild and crazy opinions...

Adding sAMAccountName and sAMAccountType to ADAM/ADLDS directories

by @ 12:37 am on 3/4/2011. Filed under tech

First and foremost… ADAM rocks. 🙂

With that being said… I regularly like to pull users and groups from AD and stuff them into ADAM. In general the normal ADAM schema is sufficient but for users and groups from an ADAM standpoint, ADAM is a positive step away from the SAM DB and as part of that step they did not put sAMAccountName nor sAMAccountType into the ADAM schema.

However… Sometimes I want the sAMAccountName and sAMAccountType attributes because I am importing user/group objects from AD and those values may be important for some reason and I may need to keep them, this could be for any number of reasons. Regardless of the reason, sometimes I want to do it, and that means I fairly regularly add those attributes to the schema of various ADAM instances I spin up. This can be done specifically for these couple of attributes or you can, if needed, import the whole Windows Server 2003 or Windows Server 2008 Schemas with the MS-adamschemaw2k3.LDF and MS-adamschemaw2k8.LDF files.

So it isn’t exciting to walk through using LDIF to import the K3 or K8 schemas and doing so doesn’t teach you anything about how you can use AdFind and AdMod so I will show how I import just those two attributes in case it proves useful to someone else trying to do something similar.

While you can do this with the older versions of AdFind and AdMod, I have added some features to the latest versions (AdFind V01.44.00 / AdMod V01.15.00) specifically to make it easier. Below I outline the process you can follow to update an ADAM instance on the local PC to have sAMAccountName and sAMAccountType for users and groups.

 

Step 1: Create a CSV file for the import (I ran this command against a Windows Server 2008 R2 Domain):

adfind -sc sdump -csv -af ldapdisplayname=samaccount* > SamAccount.csv

When run you see:

[Wed 03/02/2011 23:23:42.71]
F:\Dev\Current\CPP\SchemaMods>adfind -sc sdump -csv -af ldapdisplayname=samaccount* > SamAccount.csv

[Wed 03/02/2011 23:24:08.33]

This creates the file (it won’t look pretty here) ;o)

__SamAccount.csv__

"dn","adminDescription","adminDisplayName","attributeID","attributeSecurityGUID","attributeSyntax","auxiliaryClass","cn","defaultHidingValue","defaultObjectCategory","defaultSecurityDescriptor","description","extendedCharsAllowed","governsID","isDefunct","isMemberOfPartialAttributeSet","isSingleValued","lDAPDisplayName","linkID","mAPIID","mayContain","mustContain","objectClass","objectClassCategory","oMSyntax","possSuperiors","rangeLower","rangeUpper","rDNAttID","schemaIDGUID","searchFlags","showInAdvancedViewOnly","subClassOf","systemAuxiliaryClass","systemFlags","systemMayContain","systemMustContain","systemOnly","systemPossSuperiors"
"CN=SAM-Account-Name,<SCHEMA>","SAM-Account-Name","SAM-Account-Name","1.2.840.113556.1.4.221","{59BA2F42-79A2-11D0-9020-00C04FC2D3CF}","2.5.5.12","","SAM-Account-Name","","","","","","","","TRUE","TRUE","sAMAccountName","","","","","attributeSchema;top","","64","","0","256","","{3E0ABFD0-126A-11D0-A060-00AA006C33ED}","13","TRUE","","","18","","","FALSE",""
"CN=SAM-Account-Type,<SCHEMA>","SAM-Account-Type","SAM-Account-Type","1.2.840.113556.1.4.302","{59BA2F42-79A2-11D0-9020-00C04FC2D3CF}","2.5.5.9","","SAM-Account-Type","","","","","","","","TRUE","TRUE","sAMAccountType","","","","","attributeSchema;top","","2","","","","","{6E7B626C-64F2-11D0-AFD2-00C04FD930C9}","1","TRUE","","","18","","","FALSE",""

 

Then to import into ADAM with the new importschema shortcut (use –po switch with shortcut to see exact switches enabled for you if curious)…

[Wed 03/02/2011 23:24:08.33]
F:\Dev\Current\CPP\SchemaMods>admod -hh . -sc importschema:SamAccount.csv

AdMod V01.15.00cpp Joe Richards (joe@joeware.net) March 2011

DN Count: 2
Using server: hplt17:389
Directory: Windows Server 2008 Active Directory Application Mode

Adding specified objects…
   DN: CN=SAM-Account-Name,CN=Schema,CN=Configuration,CN={4DC12149-8F6B-4E24-BF3A-7A2E754CBB44}…
   DN: CN=SAM-Account-Type,CN=Schema,CN=Configuration,CN={4DC12149-8F6B-4E24-BF3A-7A2E754CBB44}…

The command completed successfully

 

After you import the attributes, you need to refresh the schema so you can attach them to the classes.

[Wed 03/02/2011 23:25:28.99]
F:\Dev\Current\CPP\SchemaMods>admod -hh . -sc refreshschema

AdMod V01.15.00cpp Joe Richards (joe@joeware.net) March 2011

Modifying ROOTDSE…
DN Count: 1
Using server: hplt17:389
Directory: Windows Server 2008 Active Directory Application Mode

Modifying specified objects…
   DN: ROOTDSE…

The command completed successfully

 

Now add the attributes to the user and group classes.

[Wed 03/02/2011 23:25:57.24]
F:\Dev\Current\CPP\SchemaMods>admod -hh . -schema -rb cn=user maycontain:++:samaccountname;samaccounttype -exterr

AdMod V01.15.00cpp Joe Richards (joe@joeware.net) March 2011

DN Count: 1
Using server: hplt17:389
Directory: Windows Server 2008 Active Directory Application Mode
Base DN: cn=user,CN=Schema,CN=Configuration,CN={4DC12149-8F6B-4E24-BF3A-7A2E754CBB44}

Modifying specified objects…
   DN: cn=user,CN=Schema,CN=Configuration,CN={4DC12149-8F6B-4E24-BF3A-7A2E754CBB44}…

The command completed successfully

[Wed 03/02/2011 23:26:29.42]
F:\Dev\Current\CPP\SchemaMods>admod -hh . -schema -rb cn=group maycontain:++:samaccountname;samaccounttype -exterr

AdMod V01.15.00cpp Joe Richards (joe@joeware.net) March 2011

DN Count: 1
Using server: hplt17:389
Directory: Windows Server 2008 Active Directory Application Mode
Base DN: cn=group,CN=Schema,CN=Configuration,CN={4DC12149-8F6B-4E24-BF3A-7A2E754CBB44}

Modifying specified objects…
   DN: cn=group,CN=Schema,CN=Configuration,CN={4DC12149-8F6B-4E24-BF3A-7A2E754CBB44}…

The command completed successfully

 

And finally now you can refresh the schema again so that you can use the attributes.

[Wed 03/02/2011 23:26:43.77]
F:\Dev\Current\CPP\SchemaMods>admod -hh . -sc refreshschema

AdMod V01.15.00cpp Joe Richards (joe@joeware.net) March 2011

Modifying ROOTDSE…
DN Count: 1
Using server: hplt17:389
Directory: Windows Server 2008 Active Directory Application Mode

Modifying specified objects…
   DN: ROOTDSE…

The command completed successfully

 

Now that you have this info in the schema you can do something like (using the new importpass1 and importpass2 switches)…

 

[Wed 03/02/2011 23:28:31.44]
F:\Dev\Current\CPP\SchemaMods>adfind -default -rb cn=users -sc export_x -csv | admod -hh . -add -importpass1 -unsafe -exterr

AdMod V01.15.00cpp Joe Richards (joe@joeware.net) March 2011

DN Count: 20
Using server: hplt17:389
Directory: Windows Server 2008 Active Directory Application Mode

Adding specified objects…
   DN: CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=$joe,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Administrator,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Allowed RODC Password Replication Group,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Cert Publishers,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Denied RODC Password Replication Group,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Domain Admins,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Domain Computers,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Domain Controllers,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Domain Guests,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Domain Users,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Enterprise Admins,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Enterprise Read-only Domain Controllers,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Group Policy Creator Owners,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Guest,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=krbtgt,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=RAS and IAS Servers,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Read-only Domain Controllers,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Schema Admins,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=testuser,CN=Users,DC=test,DC=loc,DC=adam…

The command completed successfully

 

and

 

[Wed 03/02/2011 23:28:41.20]
F:\Dev\Current\CPP\SchemaMods>adfind -default -rb cn=users -sc export_x -csv | admod -hh . -importpass2 -unsafe -exterr

AdMod V01.15.00cpp Joe Richards (joe@joeware.net) March 2011

DN Count: 20
Using server: hplt17:389
Directory: Windows Server 2008 Active Directory Application Mode

Modifying specified objects…
   DN: CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=krbtgt,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=Domain Computers,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=Domain Controllers,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=Schema Admins,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Enterprise Admins,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Cert Publishers,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=Domain Admins,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Domain Users,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=Domain Guests,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=Group Policy Creator Owners,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=RAS and IAS Servers,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=Allowed RODC Password Replication Group,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=Denied RODC Password Replication Group,CN=Users,DC=test,DC=loc,DC=adam…
   DN: CN=Read-only Domain Controllers,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=Enterprise Read-only Domain Controllers,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=testuser,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=Administrator,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=Guest,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.
   DN: CN=$joe,CN=Users,DC=test,DC=loc,DC=adam…  No LDAP updates to make.

The command completed successfully

 

and you may be wondering… seriously, did it really update the group memberships with the proper members?

 

[Wed 03/02/2011 23:30:17.19]
F:\Dev\Current\CPP\SchemaMods>adfind -hh . -default -rb cn=users -f objectcategory=group member

AdFind V01.44.00cpp Joe Richards (joe@joeware.net) March 2011

Using server: hplt17:389
Directory: Windows Server 2008 Active Directory Application Mode
Base DN: cn=users,DC=test,DC=loc,DC=adam

dn:CN=Allowed RODC Password Replication Group,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=Cert Publishers,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=Denied RODC Password Replication Group,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=Schema Admins,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=Read-only Domain Controllers,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=krbtgt,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=Group Policy Creator Owners,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=Enterprise Admins,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=Domain Controllers,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=Domain Admins,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=Cert Publishers,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=Domain Admins,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=Administrator,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=$joe,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=Domain Computers,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=Domain Controllers,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=Domain Guests,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=Domain Users,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=Enterprise Admins,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=Administrator,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=$joe,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=Enterprise Read-only Domain Controllers,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=Group Policy Creator Owners,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=Administrator,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=RAS and IAS Servers,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=Read-only Domain Controllers,CN=Users,DC=test,DC=loc,DC=adam

dn:CN=Schema Admins,CN=Users,DC=test,DC=loc,DC=adam
>member: CN=Administrator,CN=Users,DC=test,DC=loc,DC=adam

14 Objects returned

 

and AD looks like

 

[Wed 03/02/2011 23:31:03.87]
F:\Dev\Current\CPP\SchemaMods>adfind -default -rb cn=users -f objectcategory=group member

AdFind V01.44.00cpp Joe Richards (joe@joeware.net) March 2011

Using server: K8R2Dom-DC01.K8R2Dom.loc:389
Directory: Windows Server 2008 R2
Base DN: cn=users,DC=K8R2Dom,DC=loc

dn:CN=Domain Computers,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=Domain Controllers,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=Schema Admins,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=Administrator,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=Enterprise Admins,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=$joe,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=Administrator,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=Cert Publishers,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=Domain Admins,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=$joe,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=Administrator,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=Domain Users,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=Domain Guests,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=Group Policy Creator Owners,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=Administrator,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=RAS and IAS Servers,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=Allowed RODC Password Replication Group,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=Denied RODC Password Replication Group,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=Read-only Domain Controllers,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=Group Policy Creator Owners,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=Domain Admins,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=Cert Publishers,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=Enterprise Admins,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=Schema Admins,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=Domain Controllers,CN=Users,DC=K8R2Dom,DC=loc
>member: CN=krbtgt,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=Read-only Domain Controllers,CN=Users,DC=K8R2Dom,DC=loc

dn:CN=Enterprise Read-only Domain Controllers,CN=Users,DC=K8R2Dom,DC=loc

14 Objects returned

 

    joe

Rating 4.60 out of 5

Comments are closed.

[joeware – never stop exploring… :) is proudly powered by WordPress.]