Documentation
¶
Overview ¶
Package auth checks a user's password with dmodem-login's backends (a users file, LDAP, SQL, the system's accounts by PAM), in turn, and changes it in the backend that holds the account.
Index ¶
- Variables
- func Authenticate(ctx context.Context, backends []Authenticator, user, password string, ...) (string, error)
- func Burn(password string)
- func CheckPassword(stored, password, scheme string) (bool, error)
- func CreateAccounts(ctx context.Context, creators []AccountCreator, acct NewAccount, ...) ([]string, error)
- func InGroupsNSS(acct *Account, groups []string) (bool, error)
- func UserTaken(ctx context.Context, checkers []UserChecker, user string) (string, error)
- type Account
- type AccountCreator
- type Authenticator
- type DirUser
- type File
- func (a *File) Authenticate(_ context.Context, user, password string) error
- func (a *File) CanChangePassword() bool
- func (a *File) CanCreate() bool
- func (a *File) CanLock() bool
- func (a *File) ChangePassword(_ context.Context, _ Messenger, user, old, new string) error
- func (a *File) CreateUser(_ context.Context, acct NewAccount) error
- func (a *File) HasUser(_ context.Context, user string) (bool, bool, error)
- func (a *File) ListUsers() ([]DirUser, error)
- func (a *File) LookupUser(name string) (DirUser, error)
- func (a *File) Name() string
- func (a *File) RemoveUser(_ context.Context, user string) error
- func (a *File) Scheme() string
- type LDAP
- func (a *LDAP) Authenticate(ctx context.Context, user, password string) error
- func (a *LDAP) CanChangePassword() bool
- func (a *LDAP) CanCreate() bool
- func (a *LDAP) CanLock() bool
- func (a *LDAP) ChangePassword(_ context.Context, _ Messenger, user, old, new string) error
- func (a *LDAP) CreateUser(_ context.Context, acct NewAccount) error
- func (a *LDAP) HasGroups() bool
- func (a *LDAP) HasUser(_ context.Context, user string) (bool, bool, error)
- func (a *LDAP) MemberOf(user, password, group string) (bool, error)
- func (a *LDAP) Name() string
- func (a *LDAP) RemoveUser(_ context.Context, user string) error
- type Lister
- type Looker
- type Messenger
- type NewAccount
- type PasswordChanger
- type SQL
- func (a *SQL) Authenticate(ctx context.Context, user, password string) error
- func (a *SQL) CanChangePassword() bool
- func (a *SQL) CanCreate() bool
- func (a *SQL) CanLock() bool
- func (a *SQL) ChangePassword(ctx context.Context, _ Messenger, user, old, new string) error
- func (a *SQL) CreateUser(ctx context.Context, acct NewAccount) error
- func (a *SQL) HasUser(ctx context.Context, user string) (bool, bool, error)
- func (a *SQL) Name() string
- func (a *SQL) RemoveUser(ctx context.Context, user string) error
- type System
- func (a *System) Authenticate(_ context.Context, user, password string) error
- func (a *System) CanChangePassword() bool
- func (a *System) CanCreate() bool
- func (a *System) CanLock() bool
- func (a *System) ChangePassword(_ context.Context, t Messenger, user, old, new string) error
- func (a *System) CreateUser(ctx context.Context, acct NewAccount) error
- func (a *System) HasUser(_ context.Context, user string) (bool, bool, error)
- func (a *System) LookupUser(name string) (DirUser, error)
- func (a *System) Name() string
- func (a *System) RemoveUser(ctx context.Context, user string) error
- type UserChecker
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoUser = errors.New("no such user") ErrBadPassword = errors.New("wrong password") )
ErrNoUser: the backend does not know the user (the next one is asked); ErrBadPassword: it knows the user, the password is wrong (no other backend is asked)
var ErrCannotRemove = errors.New("cannot remove accounts")
ErrCannotRemove: the backend cannot take back an account it made (the undo of a signup that failed in a later backend)
var ErrRefused = errors.New("new password refused")
ErrRefused: the backend did not take the new password (its policy)
var ErrTaken = errors.New("user name taken")
ErrTaken: the backend has an account of that name already
Functions ¶
func Authenticate ¶
func Authenticate(ctx context.Context, backends []Authenticator, user, password string, logf func(string, ...any)) (string, error)
Authenticate with each backend in turn: the name of the one that accepted the user, or why none did
func CheckPassword ¶
CheckPassword against a stored password, in the scheme its prefix or scheme (auto: by prefix) names:
$2a$, $2b$, $2y$ ... bcrypt
{SHA256}hex, {SHA512}hex (or base64), {SSHA256}/{SSHA512}base64(hash+salt)
{PLAIN}text, or text with scheme = plain
func CreateAccounts ¶
func CreateAccounts(ctx context.Context, creators []AccountCreator, acct NewAccount, logf func(string, ...any)) ([]string, error)
CreateAccounts: acct made in each of creators, in turn. When one fails, the accounts already made are taken back (in the reverse sequence) and the error says which backend failed. The result is the names of the backends that have the account.
func InGroupsNSS ¶
InGroupsNSS: whether the account is in any of the groups, by the name service (/etc/group, LDAP via NSS...)
Types ¶
type Account ¶
type Account struct {
// contains filtered or unexported fields
}
Account: a user of the name service
type AccountCreator ¶
type AccountCreator interface {
UserChecker
// CanCreate: whether this backend is set up to make accounts (sql:
// insert_query; ldap: add_dn; system: create_command)
CanCreate() bool
// CanLock: whether a pending account can be made locked here
CanLock() bool
// CreateUser: the account made; ErrTaken when the name is there
CreateUser(ctx context.Context, acct NewAccount) error
// RemoveUser: the account that CreateUser made taken back, or
// ErrCannotRemove
RemoveUser(ctx context.Context, user string) error
}
AccountCreator: a backend that can make a new account (a signup)
type Authenticator ¶
type Authenticator interface {
Name() string
Authenticate(ctx context.Context, user, password string) error
}
func NewFile ¶
func NewFile(s *config.Section) (Authenticator, error)
NewFile: the [file] backend, its users file checked to exist
func NewLDAP ¶
func NewLDAP(s *config.Section) (Authenticator, error)
NewLDAP: the ldap backend from its section, checked
type DirUser ¶
type DirUser struct {
Name string
FullName string
Posix bool // a system account: UID, GID, Home and Shell are set
UID, GID int
Home string
Shell string
}
DirUser is what the LDAP provider ([ldapd]) shows of a user. It never has the password.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File: a text file of user:password lines (the password hashed as CheckPassword reads it, ! before it for a locked account; # comments), read at each login so that edits take effect at once
func FileAt ¶
FileAt: a users file backend for path (a signup's [signup] file, which can differ from the [file] path)
func (*File) Authenticate ¶
Authenticate: the user's line in the users file and its hash checked; a locked entry (!) is refused
func (*File) CanChangePassword ¶
func (*File) ChangePassword ¶
ChangePassword in the users file: the user's line rewritten in place (other lines as they are) under the lock signups take, the password as bcrypt (as text with hash = plain), a note after it kept
func (*File) CreateUser ¶
func (a *File) CreateUser(_ context.Context, acct NewAccount) error
CreateUser: user:bcrypt:note at the end of the users file (user:!bcrypt for a pending account), under the lock that password changes take. The name is looked at again under the lock: two signups at one time.
func (*File) LookupUser ¶
LookupUser: the user's line in the users file; ErrNoUser when it is not there or locked
func (*File) RemoveUser ¶
RemoveUser: the line of user (this name exactly) taken out of the users file, under its lock; the other lines stay as they are
type LDAP ¶
type LDAP struct {
// contains filtered or unexported fields
}
LDAP: a bind as the user, to bind_dn with {user} in it, or to the DN that search_filter finds under search_base (searched as search_bind_dn, anonymously if none)
func (*LDAP) Authenticate ¶
Authenticate: a bind as the user (found by search, or by bind_dn)
func (*LDAP) CanChangePassword ¶
CanChangePassword: always (exop or ad)
func (*LDAP) CanLock ¶
CanLock: whether add_pending_attributes is set (the attributes that lock an entry differ for each server: pwdAccountLockedTime for OpenLDAP, nsAccountLock for 389 DS, userAccountControl for AD)
func (*LDAP) ChangePassword ¶
ChangePassword bound as the user, so that the server applies its own password policy: by the Password Modify extended operation (RFC 3062), or for Active Directory (password_change = ad, which does not have it) by replacing unicodePwd, the old value deleted and the new one added (which AD takes only over TLS: ldaps:// or starttls)
func (*LDAP) CreateUser ¶
func (a *LDAP) CreateUser(_ context.Context, acct NewAccount) error
CreateUser: the entry added as add_bind_dn, then (not for AD, where the entry has unicodePwd) its password set by the Password Modify extended operation, so that the server makes the hash by its own policy. If the password cannot be set, the entry is deleted again.
func (*LDAP) HasUser ¶
HasUser: with add_dn, whether the entry at add_dn or an entry that search_filter finds is there, searched as add_bind_dn. Without add_dn, the search of a login (search_base) only; with bind_dn and no search, known is false.
type Looker ¶
Looker is a backend that can find one user by name without the password (the users file, the system's accounts).
type NewAccount ¶
type NewAccount struct {
User string
Password string // as the caller typed it; each backend hashes it its own way
Pending bool // locked until the sysop unlocks it
Note string // signup DATE CALLERID, where the backend keeps one
}
NewAccount: what a signup gives each backend that makes the account
type PasswordChanger ¶
type PasswordChanger interface {
ChangePassword(ctx context.Context, t Messenger, user, old, new string) error
// CanChangePassword: whether this backend is set up to (sql: an
// update_query)
CanChangePassword() bool
}
PasswordChanger: a backend that can change a user's password; old has been checked already. t is the caller's line, for a backend (PAM) that has something to tell them.
type SQL ¶
type SQL struct {
// contains filtered or unexported fields
}
SQL: query, with the user (and the password, for args = user password) as its arguments, returns the stored password of the user (checked as hash says), or with hash = none any row for a valid login
func (*SQL) Authenticate ¶
Authenticate: the query's row for the user, its first column the stored hash checked against the password (hash = none: a row is enough)
func (*SQL) CanChangePassword ¶
func (*SQL) CanLock ¶
CanLock: whether insert_args gives the query pending (the query stores the lock, and query or the database refuses locked rows)
func (*SQL) ChangePassword ¶
ChangePassword in the database: update_query with update_args, the password as update_hash says
func (*SQL) CreateUser ¶
func (a *SQL) CreateUser(ctx context.Context, acct NewAccount) error
CreateUser: insert_query with insert_args (user, password, pending as 1 or 0, note), the password as insert_hash says. An error of the database (for example, a unique key) is not ErrTaken: the database does not say why.
type System ¶
type System struct {
// contains filtered or unexported fields
}
System: the accounts of the system, by PAM: the auth and account stacks of pam_service, in a build with -tags pam. Only accounts with a uid of at least min_uid (not root, unless allow_root), in one of groups if it is set, may log in.
func (*System) Authenticate ¶
Authenticate: the account looked up, min_uid, root and groups checked, then the password by PAM
func (*System) CanChangePassword ¶
func (*System) ChangePassword ¶
ChangePassword by PAM: the service's password stack
func (*System) CreateUser ¶
func (a *System) CreateUser(ctx context.Context, acct NewAccount) error
CreateUser: create_command by /bin/sh, {user} and {pending} (yes or no) in it, the password and a line end on its input
func (*System) HasUser ¶
HasUser: whether the name service has user (any account, also one below min_uid: a new user must not get the name of a system account)
func (*System) LookupUser ¶
LookupUser: the system account, when it is one that may log in (min_uid, root, groups)
type UserChecker ¶
type UserChecker interface {
Name() string
// HasUser: whether the backend has user; known is false when this
// backend, as configured, cannot tell
HasUser(ctx context.Context, user string) (has, known bool, err error)
}
UserChecker: a backend that can tell whether it has an account of a name, without a password (a signup's check of the new name)