Files
Claude 3b86b397ad Rename modemmenu to dmodem-login, the repository to D-Modem/login
The program is dmodem-login (like dmodemd and dmodem-ari), the Go module
github.com/D-Modem/login, the site d-modem.github.io/login.  Its files,
units, sockets, PAM service, pppd plugin, environment (DMODEM_LOGIN_*)
and nftables tables follow.

An old installation keeps working:
- make install puts a modemmenu link to dmodem-login, and a modemmenu.so
  link to the plugin, which also takes its old modemmenu-socket option
- the default configuration, users file, state_dir and PAM service fall
  back to modemmenu's when only those are there (config.Legacy)

docs/rename.md (Simplified Technical English) lists the new names and
what an old installation must change (the -serve socket, the units, the
/etc/modemmenu files, the old nftables tables).  CI's bbs job moves a
bbs that still imports github.com/D-Modem/menu to the new path.  The
pppd plugin builds clean with -Wall -Wextra on GCC and Clang.

COMMERCIAL-LICENSE.md and CONTRIBUTING.md (legal text) are not changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRTD8BSptdpaUWGcs65
2026-11-23 05:04:16 +00:00

57 lines
1.4 KiB
Go

// Copyright (C) 2026 D-Modem Authors
// SPDX-License-Identifier: AGPL-3.0-only
package authd
import (
"bufio"
"encoding/json"
"errors"
"fmt"
"net"
"time"
)
// Client asks the socket at Socket.
type Client struct {
Socket string
Timeout time.Duration // for an answer (dmodem-login waits fail_delay before a no); 0: 15s
}
// Check asks whether pw is user's password: true and the backend that
// said so, false if it is not; an error if dmodem-login could not be asked
// or would not answer (refused: not a client it answers).
func (c *Client) Check(user, pw string) (bool, string, error) {
timeout := c.Timeout
if timeout <= 0 {
timeout = 15 * time.Second
}
conn, err := net.DialTimeout("unix", c.Socket, timeout)
if err != nil {
return false, "", err
}
defer conn.Close()
conn.SetDeadline(time.Now().Add(timeout))
b, _ := json.Marshal(Request{User: user, Password: pw})
if _, err := conn.Write(append(b, '\n')); err != nil {
return false, "", err
}
line, err := bufio.NewReader(conn).ReadSlice('\n')
if err != nil {
return false, "", fmt.Errorf("no answer: %w", err)
}
var r Reply
if err := json.Unmarshal(line, &r); err != nil {
return false, "", fmt.Errorf("an answer not understood: %q", line)
}
switch {
case r.OK:
return true, r.Auth, nil
case r.Error == "denied":
return false, "", nil
case r.Error != "":
return false, "", errors.New(r.Error)
}
return false, "", fmt.Errorf("an answer not understood: %q", line)
}