Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Computer ¶
type Computer struct {
// LdapSession is the LDAP session object
LdapSession LdapSessionInterface
// DistinguishedName is the distinguished name of the computer
DistinguishedName string
// DNSHostname is the DNS hostname of the computer
DNSHostname []string
}
type Domain ¶
type Domain struct {
// LdapSession is the LDAP session object
LdapSession LdapSessionInterface
// DistinguishedName is the distinguished name of the domain
DistinguishedName string
// NetBIOSName is the NetBIOS name of the domain
NetBIOSName string
// DNSName is the DNS name of the domain
DNSName string
// SID is the SID of the domain
SID string
}
func (*Domain) GetAllComputers ¶
GetAllComputers retrieves all computer objects from the LDAP directory.
This function performs an LDAP search to find all objects with the objectClass "computer" within the domain's distinguished name. It retrieves the distinguished name and DNS hostname attributes for each computer object and constructs a map of Computer objects.
Returns:
- A map where the keys are the distinguished names of the computer objects and the values are pointers to Computer objects representing the retrieved computer objects.
Example usage:
domain := &Domain{LdapSession: ldapSession, DistinguishedName: "DC=example,DC=com"}
computers := domain.GetAllComputers()
for dn, computer := range computers {
fmt.Printf("Computer DN: %s, DNS Hostname: %v\n", dn, computer.DNSHostname)
}
func (*Domain) IsDomainAtLeast ¶
IsDomainAtLeast checks if the domain's functionality level is at least the specified level.
This function retrieves the domain object for the given domain name and queries the LDAP server to get the "msDS-Behavior-Version" attribute, which represents the domain's functionality level. It then compares this value with the provided functionality level.
Parameters:
- domain (string): The name of the domain to check.
- functionalityLevel (int): The minimum functionality level to check against.
Returns:
- bool: True if the domain's functionality level is at least the specified level, false otherwise.
Example:
ldapSession := &Session{}
domain := "example.com"
functionalityLevel := 3
isAtLeast := ldapSession.IsDomainAtLeast(domain, functionalityLevel)
if isAtLeast {
fmt.Println("The domain's functionality level is at least", functionalityLevel)
} else {
fmt.Println("The domain's functionality level is less than", functionalityLevel)
}
Note:
- This function assumes that the Session struct has a valid connection object and that the GetDomain and QueryBaseObject methods are implemented correctly.
- The function logs a warning if the "msDS-Behavior-Version" attribute cannot be parsed to an integer.
type LdapSessionInterface ¶
type LdapSessionInterface interface {
InitSession(string, int, *credentials.Credentials, bool, bool) error
Connect() (bool, error)
ReConnect() (bool, error)
Close()
// Query functions
Query(searchBase string, query string, attributes []string, scope int) ([]*ldap.Entry, error)
QueryWholeSubtree(searchBase string, query string, attributes []string) ([]*ldap.Entry, error)
QueryBaseObject(searchBase string, query string, attributes []string) ([]*ldap.Entry, error)
QuerySingleLevel(searchBase string, query string, attributes []string) ([]*ldap.Entry, error)
QueryChildren(searchBase string, query string, attributes []string) ([]*ldap.Entry, error)
// Domain functions
GetDomain(distinguishedName string) (*Domain, error)
}
type User ¶
type User struct {
// LdapSession is the LDAP session object
LdapSession LdapSessionInterface
// DistinguishedName is the distinguished name of the user
DistinguishedName string
// sAMAccountName is the sAMAccountName of the user
SamAccountName string
}