Aracılığıyla paylaş


LDIF Betikleri

LDAP Veri Değişim Biçimi (LDIF), LDAP hizmet sağlayıcılarını kullanan dizin sunucuları arasında dizin verilerini içeri ve dışarı aktarmayı tanımlayan bir İnternet Mühendisliği Görev Gücü (IETF) standardıdır. Windows 2000 ve Windows Server 2003, LDIF dosyalarını kullanarak dizin nesnelerini Active Directory Etki Alanı Hizmetleri'ne aktarmak için kullanılabilen LDIFDE adlı bir komut satırı yardımcı programı içerir. LDIFDE, Active Directory Etki Alanı Hizmetleri'ndeki dizin nesnelerini, şema yöneticileri tarafından kolayca okunabilen LDIF dosyaları olarak aramak ve listelemek için belirli bir dizeye filtre ayarlamanıza olanak tanır.

Bir Unicode dosyasını içeri aktarırken, LDIFDE dosyanın başında Unicode tanımlayıcısı varsa dosyayı Unicode olarak içeri aktarır. Dosyanın başında Unicode tanımlayıcısı olmadığında dosyayı Unicode olarak içeri aktarmak isterseniz, -u anahtarını kullanarak Unicode olarak içeri aktarılmaya zorlayabilirsiniz.

Dosyaları dışarı aktarmak için varsayılan mod ANSI'dir. Unicode girdileri varsa, bunlar temel 64 biçimine dönüştürülür. Dosyayı Unicode biçiminde dışarı aktarmak için -u anahtarını kullanın.

Bir LDIF dosyası, eklenen öznitelikler arasında bağımlılıklar olduğunda şema değişikliklerini uygulamalıdır. Örneğin, ileri bağlantı öznitelikleri ilgili geri bağlantı özniteliğinden önce eklenmelidir. Ayrıca, LDIF betiğinde daha önce eklenen özniteliklere veya sınıflara bağlı sınıflar eklemeden önce şema önbelleğini güncelleştirmeniz gerekir. Daha fazla bilgi için aşağıdaki kod örneğine bakın.

İkili değerler için değerleri base64 olarak kodlamanız gerektiğini unutmayın. Base64 kodlaması IETF RFC 2045, Bölüm 6.8'de tanımlanır.

LDIF dosyalarının biçimi hakkında daha fazla bilgi için İnternet Mühendisliği Görev Gücü web sitesindeki LDAP Veri Değişim Biçimi (LDIF) - Teknik Belirtim (RFC 2849) bakın.

NTDS'ye özgü LDIF değişiklik türleri

ldifde -k çağırmak yerine ntdsSchema* changetypes kullanmak daha iyidir. ldifde -k seçeneği daha büyük bir LDAP hata kümesini yoksayar. Yoksayılan hataların tam listesi aşağıdaki gibidir:

  • Nesnesi zaten grubun bir üyesidir.
  • İçeri aktarılan nesnenin başka öznitelikleri yoksa nesne sınıfı ihlali (belirtilen nesne sınıfı yok anlamına gelir).
  • nesnesi zaten var (LDAP_ALREADY_EXISTS)
  • kısıtlama ihlali (LDAP_CONSTRAINT_VIOLATION)
  • özniteliği veya değeri zaten var (LDAP_ATTRIBUTE_OR_VALUE_EXISTS)
  • böyle bir nesne yok (LDAP_NO_SUCH_OBJECT)

Aşağıdaki değişiklik türleri özellikle şema yükseltme işlemleri için tasarlanmıştır.

Değişiklik Türü Açıklama
ntdsSchemaAdd
ntdsSchemaAdd, LDIF dosyasında ekleme karşılık gelir. Tek fark, ntdsSchemaAdd, nesne şemada zaten varsa ldifde'nin ekleme işlemini atlayıp işlemi eklemesine neden olmasıdır. (LDAP_ALREADY_EXISTS yoksayılır.)
ntdsSchemaModify
ntdsSchemaModify, LDIF dosyasındaki değiştirme karşılık gelir. Tek fark, ntdsSchemaModify nesne şemada bulunamazsa ldifde'nin değişiklik işlemini atmasına neden olmasıdır. (LDAP_NO_SUCH_OBJECT yoksayılır.)
ntdsSchemaDelete
ntdsSchemaDelete, LDIF dosyasındaki silme karşılık gelir. Tek fark, ntdsSchemaDelete nesne şemada bulunamazsa ldifde'nin silme işlemini atlamasına neden olmasıdır. (LDAP_NO_SUCH_OBJECT yoksayılır.)
ntdsSchemaModRdn
ntdsSchemaModRdn, LDIF dosyasındaki modrdn karşılık gelir. Tek fark, ntdsSchemaModRdn nesne şemada bulunamazsa ldifde'nin bir modify-relative-distinguished-name işlemini atlamasına neden olmasıdır. (LDAP_NO_SUCH_OBJECT yoksayılır.)

Örnek

Aşağıdaki kod örneği şunları içerir:

  • Myschemaext.ldf, yeni öznitelikler ve sınıflar içeren bir LDIF betiğidir. Bu dosyanın Lgetattcls.vbs dosyasından oluşturulan değiştirilmiş bir sürümü olduğunu unutmayın. Ayrıca, My-Test-Attribute-DN-FL özniteliğinin My-Test-Attribute-DN-BL önüne taşındığını unutmayın çünkü arka bağlantı (My-Test-Attribute-DN-BL) ileri bağlantı (My-Test-Attribute-DN-FL). Ayrıca, schemaUpdateNow işlem özniteliği, şema önbelleği güncelleştirmelerini tetikleyecek şekilde iki yerde ayarlanır, böylece bağımlı öznitelikler ve sınıflar betikte iki sınıfı eklemek için kullanılabilir.

    Not

    linkID: deyimlerindeki kimliğin kaynağı hakkında bilgi için bağlantı kimliği alma konusuna bakın.

  • Lgetattcls.vbs, Myschemaext.ldf için başlangıç noktası olarak kullanılan LDIF betiğini oluşturan bir VBScript dosyasıdır. Geçerli şema yolunun CN=Schema,CN=Configuration,DC=myorg,DC=com ile değiştirildiğini unutmayın. DC=myorg,DC=com yerine LDIF betiğinde yayımlamak üzere ayırt edici adı (DN) yansıtarak LSETATTCLS'nin sağlandığından emin olabilirsiniz. VBS, LDIF betiği uygulandığında doğru DN'nin değiştirilmesi için değişikliği sFromDN yansıtır. Ayrıca betiğin, tüm sınıflarınız ve öznitelikleriniz için de tanımlamanız ve kullanmanız gereken sınıfları ve öznitelikleri bulmak için bir ön ek kullandığını unutmayın. Daha fazla bilgi için bkz. Adlandırma Öznitelikleri ve Sınıfları. Buna ek olarak, betik yalnızca attributeSchema için gerekli öznitelikleri ve classSchema nesneleri LDIF dosyasına verir.

  • Lsetattcls.vbs, betikteki yeni öznitelikleri ve sınıfları eklemek için Myschemaext.ldf betiğini kullanan bir VBScript dosyasıdır. Betiği çalıştırmadan önce şema yöneticisinin yazılabilmesini sağlayın.

MYSCHEMAEXT. LDF

dn: CN=My-Test-Attribute-CaseExactString,CN=Schema,CN=Configuration,DC=myorg,DC=com
changetype: add
adminDisplayName: My-Test-Attribute-CaseExactString
attributeID: 1.2.840.113556.1.4.7000.159.24.10.65
attributeSyntax: 2.5.5.3
cn: My-Test-Attribute-CaseExactString
description: Test attribute of syntax CaseExactString used to show how to add a CaseExactString attribute.
isMemberOfPartialAttributeSet: FALSE
isSingleValued: TRUE
lDAPDisplayName: myTestAttributeCaseExactString
distinguishedName: CN=My-Test-Attribute-CaseExactString,CN=Schema,CN=Configuration,DC=myorg,DC=com
objectCategory: CN=Attribute-Schema,CN=Schema,CN=Configuration,DC=myorg,DC=com
objectClass: attributeSchema
oMSyntax: 27
name: My-Test-Attribute-CaseExactString
schemaIDGUID:: 6ASznA3W0hGBpwDAT7mMGg==
searchFlags: 0
 
dn: CN=My-Test-Attribute-DN-FL,CN=Schema,CN=Configuration,DC=myorg,DC=com
changetype: add
adminDisplayName: My-Test-Attribute-DN-FL
attributeID: 1.2.840.113556.1.4.7000.159.24.10.614
attributeSyntax: 2.5.5.1
cn: My-Test-Attribute-DN-FL
description: Test forward link attribute of syntax DN used to show how to add a forward link attribute. Back link is My-Test-Attribute-DN-BL.
isMemberOfPartialAttributeSet: FALSE
isSingleValued: TRUE
lDAPDisplayName: myTestAttributeDNFL
linkID: 1.2.840.113556.1.2.50
distinguishedName: CN=My-Test-Attribute-DN-FL,CN=Schema,CN=Configuration,DC=myorg,DC=com
objectCategory: CN=Attribute-Schema,CN=Schema,CN=Configuration,DC=myorg,DC=com
objectClass: attributeSchema
oMObjectClass:: KwwCh3McAIVK
oMSyntax: 127
rangeLower: 0
rangeUpper: 257
name: My-Test-Attribute-DN-FL
schemaIDGUID:: YGLudffa0hGLEwDAT7mMGg==
searchFlags: 0
 
dn: CN=My-Test-Attribute-DN-BL,CN=Schema,CN=Configuration,DC=myorg,DC=com
changetype: add
adminDisplayName: My-Test-Attribute-DN-BL
attributeID: 1.2.840.113556.1.4.7000.159.24.10.615
attributeSyntax: 2.5.5.1
cn: My-Test-Attribute-DN-BL
description: Test back link attribute of syntax DN used to show how to add a back link attribute. Forward link is My-Test-Attribute-DN-FL.
isMemberOfPartialAttributeSet: FALSE
isSingleValued: TRUE
lDAPDisplayName: myTestAttributeDNBL
linkID: 1.2.840.113556.6.1234
distinguishedName: CN=My-Test-Attribute-DN-BL,CN=Schema,CN=Configuration,DC=myorg,DC=com
objectCategory: CN=Attribute-Schema,CN=Schema,CN=Configuration,DC=myorg,DC=com
objectClass: attributeSchema
oMObjectClass:: KwwCh3McAIVK
oMSyntax: 127
rangeLower: 0
rangeUpper: 257
name: My-Test-Attribute-DN-BL
schemaIDGUID:: jFfbhffa0hGLEwDAT7mMGg==
searchFlags: 0
 
dn: CN=My-Test-Attribute-DN-Regular,CN=Schema,CN=Configuration,DC=myorg,DC=com
changetype: add
adminDisplayName: My-Test-Attribute-DN-Regular
attributeID: 1.2.840.113556.1.4.7000.159.24.10.613
attributeSyntax: 2.5.5.12
cn: My-Test-Attribute-DN-Regular
description: Test attribute of syntax DN used to show how to add a DN attribute.
isMemberOfPartialAttributeSet: FALSE
isSingleValued: TRUE
lDAPDisplayName: myTestAttributeDNRegular
distinguishedName: CN=My-Test-Attribute-DN-Regular,CN=Schema,CN=Configuration,DC=myorg,DC=com
objectCategory: CN=Attribute-Schema,CN=Schema,CN=Configuration,DC=myorg,DC=com
objectClass: attributeSchema
oMObjectClass:: KwwCh3McAIVK
oMSyntax: 64
rangeLower: 0
rangeUpper: 257
name: My-Test-Attribute-DN-Regular
schemaIDGUID:: 5QSznA3W0hGBpwDAT7mMGg==
searchFlags: 0
 
dn: CN=My-Test-Attribute-DNString,CN=Schema,CN=Configuration,DC=myorg,DC=com
changetype: add
adminDisplayName: My-Test-Attribute-DNString
attributeID: 1.2.840.113556.1.4.7000.159.24.10.611
attributeSyntax: 2.5.5.14
cn: My-Test-Attribute-DNString
description: Test attribute of syntax DNString used to show how to add a DNString attribute.
isMemberOfPartialAttributeSet: FALSE
isSingleValued: TRUE
lDAPDisplayName: myTestAttributeDNString
distinguishedName: CN=My-Test-Attribute-DNString,CN=Schema,CN=Configuration,DC=myorg,DC=com
objectCategory: CN=Attribute-Schema,CN=Schema,CN=Configuration,DC=myorg,DC=com
objectClass: attributeSchema
oMObjectClass:: KoZIhvcUAQEBDA==
oMSyntax: 127
rangeLower: 1
rangeUpper: 64
name: My-Test-Attribute-DNString
schemaIDGUID:: 5ASznA3W0hGBpwDAT7mMGg==
searchFlags: 0

DN:
changetype: modify
add: schemaUpdateNow
schemaUpdateNow: 1
-
 
dn: CN=My-Test-Auxiliary-Class1,CN=Schema,CN=Configuration,DC=Fabrikam,DC=com
changetype: add
adminDisplayName: My-Test-Auxiliary-Class1
description: Test class used to show how to add an auxiliary class.
objectCategory: CN=Class-Schema,CN=Schema,CN=Configuration,DC=Fabrikam,DC=com
objectClass: classSchema
lDAPDisplayName: myTestAuxiliaryClass1
governsID: 1.2.840.113556.1.4.7000.159.24.10.611.11
instanceType: 4
objectClassCategory: 3
schemaIDGUID:: mmsxdsXb0hGL0AAA+HW2YA==
subClassOf: Top
mayContain: my-Test-Attribute-DNString
mustContain: description
 
DN:
changetype: modify
add: schemaUpdateNow
schemaUpdateNow: 1
-
 
dn: CN=My-Test-Structural-Class1,CN=Schema,CN=Configuration,DC=Fabrikam,DC=com
changetype: add
adminDisplayName: My-Test-Structural-Class1
auxiliaryClass: myTestAuxiliaryClass1
defaultHidingValue: FALSE
defaultObjectCategory: CN=Organizational-Unit,CN=Schema,CN=Configuration,DC=Fabrikam,DC=com
defaultSecurityDescriptor: D:(A;;RPWPCRCCDCLCLOLORCWOWDSDDTDTSW;;;DA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)
admindescription: Test class used to show how to add a structure class.
objectCategory: CN=Class-Schema,CN=Schema,CN=Configuration,DC=Fabrikam,DC=com
objectClass: classSchema
lDAPDisplayName: myTestStructuralClass1
governsID: 1.2.840.113556.1.4.7000.159.24.10.611.12
mayContain: myTestAttributeDNFL
mayContain: wWWHomePage
mustContain: url
instanceType: 4
objectClassCategory: 1
possSuperiors: organizationalUnit
rDNAttID: ou
schemaIDGUID:: 1HsnsL7b0hGL0AAA+HW2YA==
subClassOf: organizationalUnit
 
DN:
changetype: modify
add: schemaUpdateNow
schemaUpdateNow: 1
-

LGETATTCLS. VBS

On Error Resume Next
 
'''''''''''''''''''
' Bind to the rootDSE
'''''''''''''''''''
sPrefix = "LDAP://"
Set root= GetObject(sPrefix & "rootDSE")
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on GetObject method"
End If
 
'''''''''''''''''''
' Get the DN for the Schema
'''''''''''''''''''
sSchema = root.Get("schemaNamingContext")
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on Get method"
End If
 
'''''''''''''''''''
' Bind to the Schema container
'''''''''''''''''''
Set Schema= GetObject(sPrefix & sSchema )
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on GetObject method to bind to Schema"
End If
''''''''''''''''''''
' Read the fsmoRoleOwner attribute to see which server is the schema master.
''''''''''''''''''''
sMaster = Schema.Get("fsmoRoleOwner")
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on IADs::Get method for fsmoRoleOwner"
End If
''''''''''''''''''''
' fsmoRoleOwner attribute returns the nTDSDSA object.
' The parent is the server object.
' Bind to NTDSDSA object and get parent
''''''''''''''''''''
Set NTDS = GetObject(sPrefix & sMaster)
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on GetObject method for NTDS"
End If
sServer = NTDS.Parent
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on IADs::get_Parent method"
End If
''''''''''''''''''''
' Bind to server object and get the
' reference to the computer object.
''''''''''''''''''''
Set Server = GetObject(sServer)
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on GetObject method for " & sServer
End If
'''''''''''''''''''''
' Display the DN for the computer object.
'''''''''''''''''''''
sComputerDNSName = Server.Get("DNSHostName")
strText = "Schema Master has the following DNS Name: "& sComputerDNSName
WScript.echo strText
 
sFile = "myschemaext1.ldf"
sFromDN = sSchema
sToDN = "CN=Schema,CN=Configuration,DC=myorg,DC=com"
sAttrPrefix = "My-Test"
sFilter = "(&((cn=" & sAttrPrefix & "*)(|(objectCategory=classSchema)_
(objectCategory=attributeSchema))))"
sRetAttr = "dn,adminDescription,adminDisplayName,governsID,cn,mayContain,_
mustContain,systemMayContain,systemMustContain,lDAPDisplayName,_
objectClassCategory,distinguishedName,objectCategory,objectClass,_
possSuperiors,systemPossSuperiors,subClassOf,defaultObjectCategory,_
name,schemaIDGUID,auxiliaryClass,auxiliaryClass,systemAuxiliaryClass,_
description,defaultHidingValue,rDNAttId,defaultSecurityDescriptor,_
attributeID,attributeSecurityGUID,attributeSyntax,_
isMemberOfPartialAttributeSet,isSingleValued,mAPIID,oMSyntax,rangeLower,_
rangeUpper,searchFlags,oMObjectClass,linkID"
 
' Add flag rootDN.
sCommand = "ldifde -d " & sSchema 
sCommand = sCommand & " -c " & sFromDN & " " & sToDN
' Add flag schema master.
sCommand = sCommand & " -s " & sComputerDNSName
' Add flag filename.
sCommand = sCommand & " -f " & sFile
' Add flag filter to search for attributes.
sCommand = sCommand & " -r " & sFilter
' Add flag for attributes to return.
sCommand = sCommand & " -l " & sRetAttr
 
WScript.echo sCommand
Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.Run (sCommand)
 
 
''''''''''''''''''''
' Display subroutines
''''''''''''''''''''
 
Sub BailOnFailure(ErrNum, ErrText) strText = "Error 0x"_
 & Hex(ErrNum) & " " & ErrText
    MsgBox strText, vbInformation, "ADSI Error"
    WScript.Quit
End Sub

LSETATTCLS. VBS

On Error Resume Next
 
'''''''''''''''''''
' Bind to the rootDSE
'''''''''''''''''''
sPrefix = "LDAP://"
Set root= GetObject(sPrefix & "rootDSE")
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on GetObject method"
End If
 
'''''''''''''''''''
' Get the DN for the Schema
'''''''''''''''''''
sSchema = root.Get("schemaNamingContext")
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on Get method"
End If
 
'''''''''''''''''''
' Bind to the Schema container
'''''''''''''''''''
Set Schema= GetObject(sPrefix & sSchema )
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on GetObject method to bind to Schema"
End If
''''''''''''''''''''''''''''''''''''''
' Read the fsmoRoleOwner attribute to see which server is the schema master.
''''''''''''''''''''''''''''''''''''''
sMaster = Schema.Get("fsmoRoleOwner")
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on IADs::Get method for fsmoRoleOwner"
End If
'''''''''''''''''''''''''''
' fsmoRoleOwner attribute returns the nTDSDSA object.
' The parent is the server object.
' Bind to NTDSDSA object and get parent
'''''''''''''''''''''''''''
Set NTDS = GetObject(sPrefix & sMaster)
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on GetObject method for NTDS"
End If
sServer = NTDS.Parent
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on IADs::get_Parent method"
End If
''''''''''''''''''''''''
' Bind to server object
' and get the reference to the computer object.
''''''''''''''''''''''''
Set Server = GetObject(sServer)
If (Err.Number <> 0) Then
   BailOnFailure Err.Number, "on GetObject method for " & sServer
End If
sComputer = Server.Get("serverReference")
'''''''''''''''''''''
' Display the DN for the computer object.
'''''''''''''''''''''
sComputerDNSName = Server.Get("DNSHostName")
' strText = "Schema Master has the following DN: "& sComputer
strText = "Schema Master has the following DNS Name: "& sComputerDNSName
WScript.echo strText
 
sFile = "myschemaext.ldf"
sFromDN = "CN=Schema,CN=Configuration,DC=myorg,DC=com"
sToDN = sSchema
' Add flag replace fromDN with ToDN.
sCommand = "ldifde -i -k -c " & sFromDN & " " & sToDN
' Add flag schema master.
sCommand = sCommand & " -s " & sComputerDNSName
'Add flag filename.
sCommand = sCommand & " -f " & sFile
' Add flag filter to search for my attributes.
 
WScript.echo sCommand
Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.Run (sCommand)
 
 
''''''''''''''''''''
' Display subroutines
''''''''''''''''''''
 
Sub BailOnFailure(ErrNum, ErrText)    strText = "Error 0x" & Hex(ErrNum) & " " & ErrText
    MsgBox strText, vbInformation, "ADSI Error"
    WScript.Quit
End Sub