|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/lkarlslund/ldap/v3" |
| 5 | +) |
| 6 | + |
| 7 | +var defaultDumpAttrs = []string{ |
| 8 | + "configurationNamingContext", |
| 9 | + "currentTime", |
| 10 | + "defaultNamingContext", |
| 11 | + "dNSHostName", |
| 12 | + "dsSchemaAttrCount", |
| 13 | + "dsSchemaClassCount", |
| 14 | + "dsSchemaPrefixCount", |
| 15 | + "dsServiceName", |
| 16 | + "highestCommittedUSN", |
| 17 | + "isGlobalCatalogReady", |
| 18 | + "isSynchronized", |
| 19 | + "ldapServiceName", |
| 20 | + "namingContexts", |
| 21 | + "netlogon", |
| 22 | + "pendingPropagations", |
| 23 | + "rootDomainNamingContext", |
| 24 | + "schemaNamingContext", |
| 25 | + "serverName", |
| 26 | + "subschemaSubentry", |
| 27 | + "supportedCapabilities", |
| 28 | + "supportedControl", |
| 29 | + "supportedLDAPPolicies", |
| 30 | + "supportedLDAPVersion", |
| 31 | + "supportedSASLMechanisms", |
| 32 | + "domainControllerFunctionality", |
| 33 | + "domainFunctionality", |
| 34 | + "forestFunctionality", |
| 35 | + "msDS-ReplAllInboundNeighbors", |
| 36 | + "msDS-ReplAllOutboundNeighbors", |
| 37 | + "msDS-ReplConnectionFailures", |
| 38 | + "msDS-ReplLinkFailures", |
| 39 | + "msDS-ReplPendingOps", |
| 40 | + "msDS-ReplQueueStatistics", |
| 41 | + "msDS-TopQuotaUsage", |
| 42 | + "supportedConfigurableSettings", |
| 43 | + "supportedExtension", |
| 44 | + "validFSMOs", |
| 45 | + "dsaVersionString", |
| 46 | + "msDS-PortLDAP", |
| 47 | + "msDS-PortSSL", |
| 48 | + "msDS-PrincipalName", |
| 49 | + "serviceAccountInfo", |
| 50 | + "spnRegistrationResult", |
| 51 | + "tokenGroups", |
| 52 | + "usnAtRifm", |
| 53 | + "approximateHighestInternalObjectID", |
| 54 | + "databaseGuid", |
| 55 | + "schemaIndexUpdateState", |
| 56 | + "dumpLdapNotifications", |
| 57 | + "msDS-ProcessLinksOperations", |
| 58 | + "msDS-SegmentCacheInfo", |
| 59 | + "msDS-ThreadStates", |
| 60 | + "ConfigurableSettingsEffective", |
| 61 | + "LDAPPoliciesEffective", |
| 62 | + "msDS-ArenaInfo", |
| 63 | + "msDS-Anchor", |
| 64 | + "msDS-PrefixTable", |
| 65 | + "msDS-SupportedRootDSEAttributes", |
| 66 | + "msDS-SupportedRootDSEModifications", |
| 67 | +} |
| 68 | + |
| 69 | +func dumpRootDSE(conn *ldap.Conn) (map[string][]string, error) { |
| 70 | + result := make(map[string][]string) |
| 71 | + |
| 72 | + // See if we can ask the server what attributes it knows about |
| 73 | + probeAttrs := getRootDSEAttribute(conn, "msDS-SupportedRootDSEAttributes") |
| 74 | + if len(probeAttrs) == 0 { |
| 75 | + probeAttrs = defaultDumpAttrs |
| 76 | + } |
| 77 | + |
| 78 | + // Extract what we can |
| 79 | + for _, attribute := range probeAttrs { |
| 80 | + result[attribute] = getRootDSEAttribute(conn, attribute) |
| 81 | + } |
| 82 | + return result, nil |
| 83 | +} |
| 84 | + |
| 85 | +func getRootDSEAttribute(conn *ldap.Conn, attribute string) []string { |
| 86 | + request := ldap.NewSearchRequest( |
| 87 | + "", // The base dn to search |
| 88 | + ldap.ScopeBaseObject, ldap.NeverDerefAliases, 0, 0, false, |
| 89 | + "(objectClass=*)", // The filter to apply |
| 90 | + []string{attribute}, // A list attributes to retrieve |
| 91 | + nil, |
| 92 | + ) |
| 93 | + response, err := conn.Search(request) |
| 94 | + if err == nil && len(response.Entries) == 1 && len(response.Entries[0].Attributes) == 1 { |
| 95 | + return response.Entries[0].Attributes[0].Values |
| 96 | + } |
| 97 | + return nil |
| 98 | +} |
0 commit comments