mirror of
https://github.com/D-Modem/login.git
synced 2026-11-28 20:38:06 -08:00
All of modemmenu was one package main in the repository's root. It is
now one module with the program and the pieces it is made of apart:
cmd/modemmenu/ the program (the login, the menu, access, limits,
the selections, -serve, AutoPPP, drop files, the
auth socket's server)
internal/config/ modemmenu.conf's sections and keys, {name} templates
internal/term/ the caller's line, terminal detection, PETSCII
internal/auth/ the backends and password changes
internal/telnet/ the telnet client of mode = telnet items
authd/ the auth socket's protocol and a client, for a BBS
to import (bbs's internal/menuauth is a copy of it)
samples/ the .conf, .users, .pam and .service samples
make builds ./cmd/modemmenu and installs the samples from samples/; the
docs, confref and the site's reference follow. The tests are where
their code is, none lost. TestSampleHasEveryKey now reads the keys of
internal/ too (and the exported Get, Bool...: it would have found none).
.gitignore's "modemmenu" ignored cmd/modemmenu/ as well: it is
/modemmenu now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRRbjf74j8oq9R3PXhA
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
// Copyright (C) 2026 D-Modem Authors
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package auth
|
|
|
|
import (
|
|
"errors"
|
|
"os/user"
|
|
"strconv"
|
|
)
|
|
|
|
// LookupNSS: the account from the name service (getpwnam with cgo)
|
|
func LookupNSS(name string) (*Account, error) {
|
|
u, err := user.Lookup(name)
|
|
var unknown user.UnknownUserError
|
|
if errors.As(err, &unknown) {
|
|
return nil, ErrNoUser
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
uid, err := strconv.Atoi(u.Uid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
gid, err := strconv.Atoi(u.Gid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &Account{name: u.Username, uid: uid, gid: gid}, nil
|
|
}
|
|
|
|
// InGroupsNSS: whether the account is in any of the groups, by the
|
|
// name service (/etc/group, LDAP via NSS...)
|
|
func InGroupsNSS(acct *Account, groups []string) (bool, error) {
|
|
u, err := user.Lookup(acct.name)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
ids, err := u.GroupIds()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
have := map[string]bool{}
|
|
for _, id := range ids {
|
|
have[id] = true
|
|
}
|
|
for _, name := range groups {
|
|
if g, err := user.LookupGroup(name); err == nil && have[g.Gid] {
|
|
return true, nil
|
|
}
|
|
}
|
|
return false, nil
|
|
}
|