ldap

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 7 Imported by: 0

README

Simple LDAP Go

This package has been extracted from netresearch/raybeam and is for providing a simple API around go-ldap/ldap/v3.

License

This package is licensed under the MIT License. See the included LICENSE file for details.

Contributing

Feel free to contribute by creating a Pull Request!

This project uses Conventional Commits for commit messages and the default gofmt formatting rules.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound             = errors.New("user not found")
	ErrSAMAccountNameDuplicated = errors.New("sAMAccountName is not unique")
	ErrMailDuplicated           = errors.New("mail is not unique")
)
View Source
var (
	ErrActiveDirectoryMustBeLDAPS = errors.New("ActiveDirectory servers must be connected to via LDAPS to change passwords")
)
View Source
var ErrComputerNotFound = errors.New("computer not found")
View Source
var ErrDNDuplicated = errors.New("DN is not unique")
View Source
var ErrGroupNotFound = errors.New("group not found")

Functions

This section is empty.

Types

type Computer

type Computer struct {
	Object
	SAMAccountName string
	Enabled        bool
	OS             string
	OSVersion      string
	// Groups is a list of CNs
	Groups []string
}

type Config

type Config struct {
	Server string
	BaseDN string

	IsActiveDirectory bool

	DialOptions []ldap.DialOpt
}

type FullUser

type FullUser struct {
	CN             string
	SAMAccountName *string
	FirstName      string
	LastName       string
	DisplayName    *string
	Description    *string
	Email          *string
	ObjectClasses  []string
	// AccountExpires represents the expiration date of the user's account.
	// When set to nil, the account never expires.
	AccountExpires     *time.Time
	UserAccountControl UAC
	Path               *string
}

type Group

type Group struct {
	Object
	// Members is a list of DNs
	Members []string
}

type LDAP

type LDAP struct {
	// contains filtered or unexported fields
}

func New

func New(config Config, user, password string) (*LDAP, error)

func (*LDAP) AddUserToGroup

func (l *LDAP) AddUserToGroup(dn, groupDN string) error

func (*LDAP) ChangePasswordForSAMAccountName

func (l *LDAP) ChangePasswordForSAMAccountName(sAMAccountName, oldPassword, newPassword string) (err error)

func (*LDAP) CheckPasswordForDN

func (l *LDAP) CheckPasswordForDN(dn, password string) (*User, error)

func (*LDAP) CheckPasswordForSAMAccountName

func (l *LDAP) CheckPasswordForSAMAccountName(sAMAccountName, password string) (*User, error)

func (*LDAP) CreateUser

func (l *LDAP) CreateUser(user FullUser, password string) (string, error)

func (*LDAP) DeleteUser

func (l *LDAP) DeleteUser(dn string) error

func (*LDAP) FindComputerByDN

func (l *LDAP) FindComputerByDN(dn string) (computer *Computer, err error)

func (*LDAP) FindComputerBySAMAccountName

func (l *LDAP) FindComputerBySAMAccountName(sAMAccountName string) (computer *Computer, err error)

func (*LDAP) FindComputers

func (l *LDAP) FindComputers() (computers []Computer, err error)

func (*LDAP) FindGroupByDN

func (l *LDAP) FindGroupByDN(dn string) (group *Group, err error)

func (*LDAP) FindGroups

func (l *LDAP) FindGroups() (groups []Group, err error)

func (*LDAP) FindUserByDN

func (l *LDAP) FindUserByDN(dn string) (user *User, err error)

func (*LDAP) FindUserByMail

func (l *LDAP) FindUserByMail(mail string) (user *User, err error)

func (*LDAP) FindUserBySAMAccountName

func (l *LDAP) FindUserBySAMAccountName(sAMAccountName string) (user *User, err error)

func (*LDAP) FindUsers

func (l *LDAP) FindUsers() (users []User, err error)

func (LDAP) GetConnection

func (l LDAP) GetConnection() (*ldap.Conn, error)

func (*LDAP) RemoveUserFromGroup

func (l *LDAP) RemoveUserFromGroup(dn, groupDN string) error

func (*LDAP) WithCredentials

func (l *LDAP) WithCredentials(dn, password string) (*LDAP, error)

type Object

type Object struct {
	// contains filtered or unexported fields
}

func (Object) CN

func (o Object) CN() string

func (Object) DN

func (o Object) DN() string

type SamAccountType

type SamAccountType uint32

SamAccountType is a bit mask that defines the type of an account. https://learn.microsoft.com/en-us/windows/win32/adschema/a-samaccounttype

const (
	SamDomainObject           SamAccountType = 0x0
	SamGroupObject            SamAccountType = 0x10000000
	SamNonSecurityGroupObject SamAccountType = 0x10000001
	SamAliasObject            SamAccountType = 0x20000000
	SamNonSecurityAliasObject SamAccountType = 0x20000001
	// SamUserObject is also known as SAM_NORMAL_USER_ACCOUNT
	SamUserObject     SamAccountType = 0x30000000
	SamMachineAccount SamAccountType = 0x30000001
	SamTrustAccount   SamAccountType = 0x30000002
	SamAppBasicGroup  SamAccountType = 0x40000000
	SamAppQueryGroup  SamAccountType = 0x40000001
	SamAccountTypeMax SamAccountType = 0x7fffffff
)

func (SamAccountType) String

func (t SamAccountType) String() string

type UAC

type UAC struct {
	LogonScript                        bool
	AccountDisabled                    bool
	HomeDirRequired                    bool
	Lockout                            bool
	PasswordNotRequired                bool
	PasswordCantChange                 bool
	EncryptedTextPasswordAllowed       bool
	TempDuplicateAccount               bool
	NormalAccount                      bool
	InterdomainTrustAccount            bool
	WorkstationTrustAccount            bool
	ServerTrustAccount                 bool
	NoPasswordExpiration               bool
	MNSLogonAccount                    bool
	SmartCardRequired                  bool
	TrustedForDelegation               bool
	NotDelegated                       bool
	UseDESKeyOnly                      bool
	DontRequirePreauth                 bool
	PasswordExpired                    bool
	TrustedToAuthenticateForDelegation bool
}

UAC represents the User Account Control flags for a user. https://learn.microsoft.com/en-us/windows/win32/adschema/a-useraccountcontrol

func UACFromUint32

func UACFromUint32(v uint32) UAC

func (UAC) String

func (u UAC) String() string

func (UAC) Uint32

func (u UAC) Uint32() uint32

type User

type User struct {
	Object
	Enabled        bool
	SAMAccountName string
	Description    string
	Mail           *string
	// Groups is a list of CNs
	Groups []string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL