From 3770d8a15d8a904c404db836e045b6a42a6714ce Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Sun, 18 May 2025 10:41:47 +0200 Subject: [PATCH 1/4] Added all Microsoft LDAP OIDs --- v3/control.go | 196 ++++++++++++++++++++++++++++++++++++-------- v3/examples_test.go | 2 +- v3/search.go | 6 +- 3 files changed, 166 insertions(+), 38 deletions(-) diff --git a/v3/control.go b/v3/control.go index f1c2746b..38418960 100644 --- a/v3/control.go +++ b/v3/control.go @@ -29,14 +29,86 @@ const ( // ControlTypeServerSideSorting - https://www.ietf.org/rfc/rfc2891.txt ControlTypeServerSideSortingResult = "1.2.840.113556.1.4.474" - // ControlTypeMicrosoftNotification - https://msdn.microsoft.com/en-us/library/aa366983(v=vs.85).aspx + // ControlTypeMicrosoftPagedResults - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftPagedResults = "1.2.840.113556.1.4.319" + // ControlTypeMicrosoftCrossDomainMoveTarget - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftCrossDomainMoveTarget = "1.2.840.113556.1.4.521" + // ControlTypeMicrosoftDirSync - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftDirSync = "1.2.840.113556.1.4.841" + // ControlTypeMicrosoftDomainScope - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftDomainScope = "1.2.840.113556.1.4.1339" + // ControlTypeMicrosoftExtendedDN - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftExtendedDN = "1.2.840.113556.1.4.529" + // ControlTypeMicrosoftGetStats - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftGetStats = "1.2.840.113556.1.4.970" + // ControlTypeMicrosoftLazyCommit - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftLazyCommit = "1.2.840.113556.1.4.619" + // ControlTypeMicrosoftPermissiveModify - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftPermissiveModify = "1.2.840.113556.1.4.1413" + // ControlTypeMicrosoftNotification - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea ControlTypeMicrosoftNotification = "1.2.840.113556.1.4.528" - // ControlTypeMicrosoftShowDeleted - https://msdn.microsoft.com/en-us/library/aa366989(v=vs.85).aspx + // ControlTypeMicrosoftRespSort - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftRespSort = "1.2.840.113556.1.4.474" + // ControlTypeMicrosoftSDFlags - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftSDFlags = "1.2.840.113556.1.4.801" + // ControlTypeMicrosoftSearchOptions - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftSearchOptions = "1.2.840.113556.1.4.1340" + // ControlTypeMicrosoftSort - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftSort = "1.2.840.113556.1.4.473" + // ControlTypeMicrosoftShowDeleted - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea ControlTypeMicrosoftShowDeleted = "1.2.840.113556.1.4.417" - // ControlTypeMicrosoftServerLinkTTL - https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/f4f523a8-abc0-4b3a-a471-6b2fef135481?redirectedfrom=MSDN - ControlTypeMicrosoftServerLinkTTL = "1.2.840.113556.1.4.2309" - // ControlTypeDirSync - Active Directory DirSync - https://msdn.microsoft.com/en-us/library/aa366978(v=vs.85).aspx - ControlTypeDirSync = "1.2.840.113556.1.4.841" + // ControlTypeMicrosoftTreeDelete - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftTreeDelete = "1.2.840.113556.1.4.805" + // ControlTypeMicrosoftVerifyName - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftVerifyName = "1.2.840.113556.1.4.1338" + // ControlTypeVLVRequest - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeVLVRequest = "2.16.840.1.113730.3.4.9" + // ControlTypeVLVResponse - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeVLVResponse = "2.16.840.1.113730.3.4.10" + // ControlTypeMicrosoftASQ - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftASQ = "1.2.840.113556.1.4.1504" + // ControlTypeMicrosoftQuotaControl - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftQuotaControl = "1.2.840.113556.1.4.1852" + // ControlTypeMicrosoftRangeOption - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftRangeOption = "1.2.840.113556.1.4.802" + // ControlTypeMicrosoftShutdownNotify - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftShutdownNotify = "1.2.840.113556.1.4.1907" + // ControlTypeMicrosoftForceUpdate - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftForceUpdate = "1.2.840.113556.1.4.1974" + // ControlTypeMicrosoftRangeRetrievalNoErr - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftRangeRetrievalNoErr = "1.2.840.113556.1.4.1948" + // ControlTypeMicrosoftRODCDCPromo - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftRODCDCPromo = "1.2.840.113556.1.4.1341" + // ControlTypeMicrosoftDNInput - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftDNInput = "1.2.840.113556.1.4.2026" + // ControlTypeMicrosoftShowDeactivatedLink - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftShowDeactivatedLink = "1.2.840.113556.1.4.2065" + // ControlTypeMicrosoftShowRecycled - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftShowRecycled = "1.2.840.113556.1.4.2064" + // ControlTypeMicrosoftPolicyHintsDeprecated - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftPolicyHintsDeprecated = "1.2.840.113556.1.4.2066" + // ControlTypeMicrosoftDirSyncEX - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftDirSyncEX = "1.2.840.113556.1.4.2090" + // ControlTypeMicrosoftUpdateStats - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftUpdateStats = "1.2.840.113556.1.4.2205" + // ControlTypeMicrosoftTreeDeleteEX - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftTreeDeleteEX = "1.2.840.113556.1.4.2204" + // ControlTypeMicrosoftSearchHints - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftSearchHints = "1.2.840.113556.1.4.2206" + // ControlTypeMicrosoftExpectedEntryCount - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftExpectedEntryCount = "1.2.840.113556.1.4.2211" + // ControlTypeMicrosoftPolicyHints - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftPolicyHints = "1.2.840.113556.1.4.2239" + // ControlTypeMicrosoftSetOwner - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftSetOwner = "1.2.840.113556.1.4.2255" + // ControlTypeMicrosoftBypassQuota - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftBypassQuota = "1.2.840.113556.1.4.2256" + // ControlTypeMicrosoftLinkTTL - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftLinkTTL = "1.2.840.113556.1.4.2309" + // ControlTypeMicrosoftSetCorrelationID - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftSetCorrelationID = "1.2.840.113556.1.4.2330" + // ControlTypeMicrosoftThreadTraceOverride - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftThreadTraceOverride = "1.2.840.113556.1.4.2354" // ControlTypeSyncRequest - https://www.ietf.org/rfc/rfc4533.txt ControlTypeSyncRequest = "1.3.6.1.4.1.4203.1.9.1.1" @@ -49,29 +121,85 @@ const ( ) // Flags for DirSync control +// Source: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/2213a7f2-0a36-483c-b2a4-8574d53aa1e3 const ( - DirSyncIncrementalValues int64 = 2147483648 - DirSyncPublicDataOnly int64 = 8192 - DirSyncAncestorsFirstOrder int64 = 2048 - DirSyncObjectSecurity int64 = 1 + // Windows Server 2003 and later: If this flag is not present, all of the values, + // up to a server-specified limit, in a multivalued attribute are returned when + // any value changes. If this flag is present, only the changed values are + // returned, provided the attribute is a forward link value. + // Windows 2000: Not supported. + DirSyncIncrementalValues int64 = 0x80000000 + + // Do not return private data in the search results. + // Windows Server 2003 and later: This flag can optionally be passed to the DC, + // but it has no effect. + // Windows 2000: Not supported. + DirSyncPublicDataOnly int64 = 0x00002000 + + // Return parent objects before child objects, otherwise parent + // objects would appear later in the replication stream. + DirSyncAncestorsFirstOrder int64 = 0x00000800 + + // Windows Server 2003 operating system and later: If this flag is present, + // the client can only view objects and attributes that are otherwise accessible + // to the client. If this flag is not present, the server checks if the client + // has access rights to read the changes in the NC. + // Windows 2000 operating system: Not supported. + DirSyncObjectSecurity int64 = 0x00000001 ) // ControlTypeMap maps controls to text descriptions var ControlTypeMap = map[string]string{ - ControlTypePaging: "Paging", - ControlTypeBeheraPasswordPolicy: "Password Policy - Behera Draft", - ControlTypeManageDsaIT: "Manage DSA IT", - ControlTypeSubtreeDelete: "Subtree Delete Control", - ControlTypeMicrosoftNotification: "Change Notification - Microsoft", - ControlTypeMicrosoftShowDeleted: "Show Deleted Objects - Microsoft", - ControlTypeMicrosoftServerLinkTTL: "Return TTL-DNs for link values with associated expiry times - Microsoft", - ControlTypeServerSideSorting: "Server Side Sorting Request - LDAP Control Extension for Server Side Sorting of Search Results (RFC2891)", - ControlTypeServerSideSortingResult: "Server Side Sorting Results - LDAP Control Extension for Server Side Sorting of Search Results (RFC2891)", - ControlTypeDirSync: "DirSync", - ControlTypeSyncRequest: "Sync Request", - ControlTypeSyncState: "Sync State", - ControlTypeSyncDone: "Sync Done", - ControlTypeSyncInfo: "Sync Info", + ControlTypePaging: "Paging", + ControlTypeBeheraPasswordPolicy: "Password Policy - Behera Draft", + ControlTypeVChuPasswordMustChange: "Password Must Change - VChu Draft", + ControlTypeVChuPasswordWarning: "Password Warning - VChu Draft", + ControlTypeManageDsaIT: "Manage DSA IT", + ControlTypeWhoAmI: "Who Am I", + ControlTypeSubtreeDelete: "Subtree Delete Control", + + ControlTypeServerSideSorting: "Server Side Sorting", + ControlTypeServerSideSortingResult: "Server Side Sorting Result", + + ControlTypeMicrosoftCrossDomainMoveTarget: "Cross Domain Move Target - Microsoft", + ControlTypeMicrosoftDirSync: "DirSync - Microsoft", + ControlTypeMicrosoftDomainScope: "Domain Scope - Microsoft", + ControlTypeMicrosoftExtendedDN: "Extended DN - Microsoft", + ControlTypeMicrosoftGetStats: "Get Stats - Microsoft", + ControlTypeMicrosoftLazyCommit: "Lazy Commit - Microsoft", + ControlTypeMicrosoftPermissiveModify: "Permissive Modify - Microsoft", + ControlTypeMicrosoftNotification: "Change Notification - Microsoft", + ControlTypeMicrosoftSDFlags: "SD Flags - Microsoft", + ControlTypeMicrosoftSearchOptions: "Search Options - Microsoft", + ControlTypeMicrosoftShowDeleted: "Show Deleted Objects - Microsoft", + ControlTypeMicrosoftVerifyName: "Verify Name - Microsoft", + ControlTypeMicrosoftASQ: "ASQ - Microsoft", + ControlTypeMicrosoftQuotaControl: "Quota Control - Microsoft", + ControlTypeMicrosoftRangeOption: "Range Option - Microsoft", + ControlTypeMicrosoftShutdownNotify: "Shutdown Notify - Microsoft", + ControlTypeMicrosoftForceUpdate: "Force Update - Microsoft", + ControlTypeMicrosoftRangeRetrievalNoErr: "Range Retrieval No Error - Microsoft", + ControlTypeMicrosoftRODCDCPromo: "RODC DC Promo - Microsoft", + ControlTypeMicrosoftDNInput: "DN Input - Microsoft", + ControlTypeMicrosoftShowDeactivatedLink: "Show Deactivated Link - Microsoft", + ControlTypeMicrosoftShowRecycled: "Show Recycled - Microsoft", + ControlTypeMicrosoftPolicyHintsDeprecated: "Policy Hints Deprecated - Microsoft", + ControlTypeMicrosoftDirSyncEX: "DirSync EX - Microsoft", + ControlTypeMicrosoftUpdateStats: "Update Stats - Microsoft", + ControlTypeMicrosoftTreeDeleteEX: "Tree Delete EX - Microsoft", + ControlTypeMicrosoftSearchHints: "Search Hints - Microsoft", + ControlTypeMicrosoftExpectedEntryCount: "Expected Entry Count - Microsoft", + ControlTypeMicrosoftPolicyHints: "Policy Hints - Microsoft", + ControlTypeMicrosoftSetOwner: "Set Owner - Microsoft", + ControlTypeMicrosoftBypassQuota: "Bypass Quota - Microsoft", + ControlTypeMicrosoftLinkTTL: "Link TTL - Microsoft", + ControlTypeMicrosoftSetCorrelationID: "Set Correlation ID - Microsoft", + ControlTypeMicrosoftThreadTraceOverride: "Thread Trace Override - Microsoft", + + ControlTypeSyncRequest: "Sync Request", + ControlTypeSyncState: "Sync State", + ControlTypeSyncDone: "Sync Done", + ControlTypeSyncInfo: "Sync Info", } // Control defines an interface controls provide to encode and describe themselves @@ -350,13 +478,13 @@ type ControlMicrosoftServerLinkTTL struct{} // GetControlType returns the OID func (c *ControlMicrosoftServerLinkTTL) GetControlType() string { - return ControlTypeMicrosoftServerLinkTTL + return ControlTypeMicrosoftLinkTTL } // Encode returns the ber packet representation func (c *ControlMicrosoftServerLinkTTL) Encode() *ber.Packet { packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control") - packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeMicrosoftServerLinkTTL, "Control Type ("+ControlTypeMap[ControlTypeMicrosoftServerLinkTTL]+")")) + packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeMicrosoftLinkTTL, "Control Type ("+ControlTypeMap[ControlTypeMicrosoftLinkTTL]+")")) return packet } @@ -365,8 +493,8 @@ func (c *ControlMicrosoftServerLinkTTL) Encode() *ber.Packet { func (c *ControlMicrosoftServerLinkTTL) String() string { return fmt.Sprintf( "Control Type: %s (%q)", - ControlTypeMap[ControlTypeMicrosoftServerLinkTTL], - ControlTypeMicrosoftServerLinkTTL) + ControlTypeMap[ControlTypeMicrosoftLinkTTL], + ControlTypeMicrosoftLinkTTL) } // NewControlMicrosoftServerLinkTTL returns a ControlMicrosoftServerLinkTTL control @@ -524,7 +652,7 @@ func DecodeControl(packet *ber.Packet) (Control, error) { return NewControlMicrosoftNotification(), nil case ControlTypeMicrosoftShowDeleted: return NewControlMicrosoftShowDeleted(), nil - case ControlTypeMicrosoftServerLinkTTL: + case ControlTypeMicrosoftLinkTTL: return NewControlMicrosoftServerLinkTTL(), nil case ControlTypeSubtreeDelete: return NewControlSubtreeDelete(), nil @@ -532,7 +660,7 @@ func DecodeControl(packet *ber.Packet) (Control, error) { return NewControlServerSideSorting(value) case ControlTypeServerSideSortingResult: return NewControlServerSideSortingResult(value) - case ControlTypeDirSync: + case ControlTypeMicrosoftDirSync: value.Description += " (DirSync)" return NewResponseControlDirSync(value) case ControlTypeSyncState: @@ -684,15 +812,15 @@ func NewResponseControlDirSync(value *ber.Packet) (*ControlDirSync, error) { // GetControlType returns the OID func (c *ControlDirSync) GetControlType() string { - return ControlTypeDirSync + return ControlTypeMicrosoftDirSync } // String returns a human-readable description func (c *ControlDirSync) String() string { return fmt.Sprintf( "ControlType: %s (%q) Criticality: %t ControlValue: Flags: %d MaxAttrCount: %d", - ControlTypeMap[ControlTypeDirSync], - ControlTypeDirSync, + ControlTypeMap[ControlTypeMicrosoftDirSync], + ControlTypeMicrosoftDirSync, c.Criticality, c.Flags, c.MaxAttrCount, @@ -708,7 +836,7 @@ func (c *ControlDirSync) Encode() *ber.Packet { } packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control") - packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeDirSync, "Control Type ("+ControlTypeMap[ControlTypeDirSync]+")")) + packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeMicrosoftDirSync, "Control Type ("+ControlTypeMap[ControlTypeMicrosoftDirSync]+")")) packet.AppendChild(ber.NewLDAPBoolean(ber.ClassUniversal, ber.TypePrimitive, ber.TagBoolean, c.Criticality, "Criticality")) // must be true always val := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Control Value (DirSync)") diff --git a/v3/examples_test.go b/v3/examples_test.go index e4e980d8..aa4ff2e7 100644 --- a/v3/examples_test.go +++ b/v3/examples_test.go @@ -446,7 +446,7 @@ func ExampleConn_DirSync() { for _, entry := range res.Entries { entry.Print() } - ctrl := FindControl(res.Controls, ControlTypeDirSync) + ctrl := FindControl(res.Controls, ControlTypeMicrosoftDirSync) if ctrl == nil || ctrl.(*ControlDirSync).Flags == 0 { doMore = false } diff --git a/v3/search.go b/v3/search.go index 72dbd9df..cf8d1c68 100644 --- a/v3/search.go +++ b/v3/search.go @@ -305,7 +305,7 @@ func (e *Entry) Unmarshal(i interface{}) (err error) { }) } -// UnmarshalFunc allows you to define a custom unmarshaler to parse an Entry values. +// UnmarshalFunc allows you to define a custom unmarshaler to parse an Entry values. // A custom unmarshaler can be found in the Unmarshal function or in the test files. func (e *Entry) UnmarshalFunc(i interface{}, fn func(entry *Entry, fieldType reflect.StructField, fieldValue reflect.Value) error) error { @@ -675,7 +675,7 @@ func unpackAttributes(children []*ber.Packet) []*EntryAttribute { func (l *Conn) DirSync( searchRequest *SearchRequest, flags int64, maxAttrCount int64, cookie []byte, ) (*SearchResult, error) { - control := FindControl(searchRequest.Controls, ControlTypeDirSync) + control := FindControl(searchRequest.Controls, ControlTypeMicrosoftDirSync) if control == nil { c := NewRequestControlDirSync(flags, maxAttrCount, cookie) searchRequest.Controls = append(searchRequest.Controls, c) @@ -698,7 +698,7 @@ func (l *Conn) DirSync( } l.Debug.Printf("Looking for DirSync Control...") - resultControl := FindControl(searchResult.Controls, ControlTypeDirSync) + resultControl := FindControl(searchResult.Controls, ControlTypeMicrosoftDirSync) if resultControl == nil { l.Debug.Printf("Could not find dirSyncControl control. Breaking...") return searchResult, nil From 04e1e3c907f5f7c1c80794426ed184b54c61e9d1 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Sun, 18 May 2025 10:53:26 +0200 Subject: [PATCH 2/4] Fixed unit tests mismatch in expected strings --- v3/control.go | 2 +- v3/control_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/v3/control.go b/v3/control.go index 38418960..3f2667ed 100644 --- a/v3/control.go +++ b/v3/control.go @@ -192,7 +192,7 @@ var ControlTypeMap = map[string]string{ ControlTypeMicrosoftPolicyHints: "Policy Hints - Microsoft", ControlTypeMicrosoftSetOwner: "Set Owner - Microsoft", ControlTypeMicrosoftBypassQuota: "Bypass Quota - Microsoft", - ControlTypeMicrosoftLinkTTL: "Link TTL - Microsoft", + ControlTypeMicrosoftLinkTTL: "Return TTL-DNs for link values with associated expiry times - Microsoft", ControlTypeMicrosoftSetCorrelationID: "Set Correlation ID - Microsoft", ControlTypeMicrosoftThreadTraceOverride: "Thread Trace Override - Microsoft", diff --git a/v3/control_test.go b/v3/control_test.go index 5f43ccb2..df70aa71 100644 --- a/v3/control_test.go +++ b/v3/control_test.go @@ -122,7 +122,7 @@ func TestDescribeControlString(t *testing.T) { } func TestDescribeControlDirSync(t *testing.T) { - runAddControlDescriptions(t, NewRequestControlDirSync(DirSyncObjectSecurity, 1000, nil), "Control Type (DirSync)", "Criticality", "Control Value") + runAddControlDescriptions(t, NewRequestControlDirSync(DirSyncObjectSecurity, 1000, nil), "Control Type (DirSync - Microsoft)", "Criticality", "Control Value") } func runAddControlDescriptions(t *testing.T, originalControl Control, childDescriptions ...string) { From 9a2d04b777ca9ba37216a422a1fb97ff99f93036 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Tue, 20 May 2025 20:13:37 +0200 Subject: [PATCH 3/4] Reverted name changes of existing OIDs to allow backwards compatibility --- v3/control.go | 32 ++++++++++++++++---------------- v3/control_test.go | 2 +- v3/examples_test.go | 2 +- v3/search.go | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/v3/control.go b/v3/control.go index 3f2667ed..720bf2c5 100644 --- a/v3/control.go +++ b/v3/control.go @@ -33,8 +33,8 @@ const ( ControlTypeMicrosoftPagedResults = "1.2.840.113556.1.4.319" // ControlTypeMicrosoftCrossDomainMoveTarget - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea ControlTypeMicrosoftCrossDomainMoveTarget = "1.2.840.113556.1.4.521" - // ControlTypeMicrosoftDirSync - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea - ControlTypeMicrosoftDirSync = "1.2.840.113556.1.4.841" + // ControlTypeDirSync - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeDirSync = "1.2.840.113556.1.4.841" // ControlTypeMicrosoftDomainScope - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea ControlTypeMicrosoftDomainScope = "1.2.840.113556.1.4.1339" // ControlTypeMicrosoftExtendedDN - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea @@ -103,8 +103,8 @@ const ( ControlTypeMicrosoftSetOwner = "1.2.840.113556.1.4.2255" // ControlTypeMicrosoftBypassQuota - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea ControlTypeMicrosoftBypassQuota = "1.2.840.113556.1.4.2256" - // ControlTypeMicrosoftLinkTTL - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea - ControlTypeMicrosoftLinkTTL = "1.2.840.113556.1.4.2309" + // ControlTypeMicrosoftServerLinkTTL - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea + ControlTypeMicrosoftServerLinkTTL = "1.2.840.113556.1.4.2309" // ControlTypeMicrosoftSetCorrelationID - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea ControlTypeMicrosoftSetCorrelationID = "1.2.840.113556.1.4.2330" // ControlTypeMicrosoftThreadTraceOverride - https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/3c5e87db-4728-4f29-b164-01dd7d7391ea @@ -162,7 +162,7 @@ var ControlTypeMap = map[string]string{ ControlTypeServerSideSortingResult: "Server Side Sorting Result", ControlTypeMicrosoftCrossDomainMoveTarget: "Cross Domain Move Target - Microsoft", - ControlTypeMicrosoftDirSync: "DirSync - Microsoft", + ControlTypeDirSync: "DirSync - Microsoft", ControlTypeMicrosoftDomainScope: "Domain Scope - Microsoft", ControlTypeMicrosoftExtendedDN: "Extended DN - Microsoft", ControlTypeMicrosoftGetStats: "Get Stats - Microsoft", @@ -192,7 +192,7 @@ var ControlTypeMap = map[string]string{ ControlTypeMicrosoftPolicyHints: "Policy Hints - Microsoft", ControlTypeMicrosoftSetOwner: "Set Owner - Microsoft", ControlTypeMicrosoftBypassQuota: "Bypass Quota - Microsoft", - ControlTypeMicrosoftLinkTTL: "Return TTL-DNs for link values with associated expiry times - Microsoft", + ControlTypeMicrosoftServerLinkTTL: "Return TTL-DNs for link values with associated expiry times - Microsoft", ControlTypeMicrosoftSetCorrelationID: "Set Correlation ID - Microsoft", ControlTypeMicrosoftThreadTraceOverride: "Thread Trace Override - Microsoft", @@ -478,13 +478,13 @@ type ControlMicrosoftServerLinkTTL struct{} // GetControlType returns the OID func (c *ControlMicrosoftServerLinkTTL) GetControlType() string { - return ControlTypeMicrosoftLinkTTL + return ControlTypeMicrosoftServerLinkTTL } // Encode returns the ber packet representation func (c *ControlMicrosoftServerLinkTTL) Encode() *ber.Packet { packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control") - packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeMicrosoftLinkTTL, "Control Type ("+ControlTypeMap[ControlTypeMicrosoftLinkTTL]+")")) + packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeMicrosoftServerLinkTTL, "Control Type ("+ControlTypeMap[ControlTypeMicrosoftServerLinkTTL]+")")) return packet } @@ -493,8 +493,8 @@ func (c *ControlMicrosoftServerLinkTTL) Encode() *ber.Packet { func (c *ControlMicrosoftServerLinkTTL) String() string { return fmt.Sprintf( "Control Type: %s (%q)", - ControlTypeMap[ControlTypeMicrosoftLinkTTL], - ControlTypeMicrosoftLinkTTL) + ControlTypeMap[ControlTypeMicrosoftServerLinkTTL], + ControlTypeMicrosoftServerLinkTTL) } // NewControlMicrosoftServerLinkTTL returns a ControlMicrosoftServerLinkTTL control @@ -652,7 +652,7 @@ func DecodeControl(packet *ber.Packet) (Control, error) { return NewControlMicrosoftNotification(), nil case ControlTypeMicrosoftShowDeleted: return NewControlMicrosoftShowDeleted(), nil - case ControlTypeMicrosoftLinkTTL: + case ControlTypeMicrosoftServerLinkTTL: return NewControlMicrosoftServerLinkTTL(), nil case ControlTypeSubtreeDelete: return NewControlSubtreeDelete(), nil @@ -660,7 +660,7 @@ func DecodeControl(packet *ber.Packet) (Control, error) { return NewControlServerSideSorting(value) case ControlTypeServerSideSortingResult: return NewControlServerSideSortingResult(value) - case ControlTypeMicrosoftDirSync: + case ControlTypeDirSync: value.Description += " (DirSync)" return NewResponseControlDirSync(value) case ControlTypeSyncState: @@ -812,15 +812,15 @@ func NewResponseControlDirSync(value *ber.Packet) (*ControlDirSync, error) { // GetControlType returns the OID func (c *ControlDirSync) GetControlType() string { - return ControlTypeMicrosoftDirSync + return ControlTypeDirSync } // String returns a human-readable description func (c *ControlDirSync) String() string { return fmt.Sprintf( "ControlType: %s (%q) Criticality: %t ControlValue: Flags: %d MaxAttrCount: %d", - ControlTypeMap[ControlTypeMicrosoftDirSync], - ControlTypeMicrosoftDirSync, + ControlTypeMap[ControlTypeDirSync], + ControlTypeDirSync, c.Criticality, c.Flags, c.MaxAttrCount, @@ -836,7 +836,7 @@ func (c *ControlDirSync) Encode() *ber.Packet { } packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control") - packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeMicrosoftDirSync, "Control Type ("+ControlTypeMap[ControlTypeMicrosoftDirSync]+")")) + packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeDirSync, "Control Type ("+ControlTypeMap[ControlTypeDirSync]+")")) packet.AppendChild(ber.NewLDAPBoolean(ber.ClassUniversal, ber.TypePrimitive, ber.TagBoolean, c.Criticality, "Criticality")) // must be true always val := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Control Value (DirSync)") diff --git a/v3/control_test.go b/v3/control_test.go index df70aa71..5f43ccb2 100644 --- a/v3/control_test.go +++ b/v3/control_test.go @@ -122,7 +122,7 @@ func TestDescribeControlString(t *testing.T) { } func TestDescribeControlDirSync(t *testing.T) { - runAddControlDescriptions(t, NewRequestControlDirSync(DirSyncObjectSecurity, 1000, nil), "Control Type (DirSync - Microsoft)", "Criticality", "Control Value") + runAddControlDescriptions(t, NewRequestControlDirSync(DirSyncObjectSecurity, 1000, nil), "Control Type (DirSync)", "Criticality", "Control Value") } func runAddControlDescriptions(t *testing.T, originalControl Control, childDescriptions ...string) { diff --git a/v3/examples_test.go b/v3/examples_test.go index aa4ff2e7..e4e980d8 100644 --- a/v3/examples_test.go +++ b/v3/examples_test.go @@ -446,7 +446,7 @@ func ExampleConn_DirSync() { for _, entry := range res.Entries { entry.Print() } - ctrl := FindControl(res.Controls, ControlTypeMicrosoftDirSync) + ctrl := FindControl(res.Controls, ControlTypeDirSync) if ctrl == nil || ctrl.(*ControlDirSync).Flags == 0 { doMore = false } diff --git a/v3/search.go b/v3/search.go index cf8d1c68..151817c2 100644 --- a/v3/search.go +++ b/v3/search.go @@ -675,7 +675,7 @@ func unpackAttributes(children []*ber.Packet) []*EntryAttribute { func (l *Conn) DirSync( searchRequest *SearchRequest, flags int64, maxAttrCount int64, cookie []byte, ) (*SearchResult, error) { - control := FindControl(searchRequest.Controls, ControlTypeMicrosoftDirSync) + control := FindControl(searchRequest.Controls, ControlTypeDirSync) if control == nil { c := NewRequestControlDirSync(flags, maxAttrCount, cookie) searchRequest.Controls = append(searchRequest.Controls, c) @@ -698,7 +698,7 @@ func (l *Conn) DirSync( } l.Debug.Printf("Looking for DirSync Control...") - resultControl := FindControl(searchResult.Controls, ControlTypeMicrosoftDirSync) + resultControl := FindControl(searchResult.Controls, ControlTypeDirSync) if resultControl == nil { l.Debug.Printf("Could not find dirSyncControl control. Breaking...") return searchResult, nil From b1d02d67b21ea6a0e9afd4164f0d02b87fbb56f9 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Tue, 20 May 2025 20:15:47 +0200 Subject: [PATCH 4/4] Reverted name changes of existing OIDs to allow backwards compatibility --- v3/control.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v3/control.go b/v3/control.go index 720bf2c5..e0dc0e13 100644 --- a/v3/control.go +++ b/v3/control.go @@ -162,7 +162,7 @@ var ControlTypeMap = map[string]string{ ControlTypeServerSideSortingResult: "Server Side Sorting Result", ControlTypeMicrosoftCrossDomainMoveTarget: "Cross Domain Move Target - Microsoft", - ControlTypeDirSync: "DirSync - Microsoft", + ControlTypeDirSync: "DirSync", ControlTypeMicrosoftDomainScope: "Domain Scope - Microsoft", ControlTypeMicrosoftExtendedDN: "Extended DN - Microsoft", ControlTypeMicrosoftGetStats: "Get Stats - Microsoft",