mirror of
https://github.com/D-Modem/login.git
synced 2026-11-28 20:38:06 -08:00
LICENSE is the GNU Affero General Public License, version 3 (gnu.org's text); each source file names it (SPDX-License-Identifier: AGPL-3.0-only) and Neo-Desktop as the copyright holder. COMMERCIAL-LICENSE.md: for uses the AGPL does not allow, Neo-Desktop grants commercial licenses on agreed terms; asked for by a GitHub issue. CONTRIBUTING.md: contributions come with an agreement (Signed-off-by) that licenses them to Neo-Desktop under the AGPL and other terms, commercial ones included, so that they can be part of both. The README has a License section, and says how a modified modemmenu offers callers its source (the AGPL's section 13). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RvtV8Dg9kqRaakbTEfyH3f
53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
// Copyright (C) 2026 Neo-Desktop
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package main
|
|
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|