mirror of
https://github.com/D-Modem/bbs.git
synced 2026-11-28 17:38:04 -08:00
Merge pull request #9 from D-Modem/claude/project-thread-zk8c8q
Ask modemmenu's auth socket with menu's authd client
This commit is contained in:
6 files changed
+5
-138
No files matched your search
+2
-2
@@ -68,7 +68,6 @@ import (
|
||||
"github.com/D-Modem/bbs/internal/gopher"
|
||||
"github.com/D-Modem/bbs/internal/imageboard"
|
||||
"github.com/D-Modem/bbs/internal/ircd"
|
||||
"github.com/D-Modem/bbs/internal/menuauth"
|
||||
"github.com/D-Modem/bbs/internal/mrc"
|
||||
"github.com/D-Modem/bbs/internal/news"
|
||||
"github.com/D-Modem/bbs/internal/nntp"
|
||||
@@ -77,6 +76,7 @@ import (
|
||||
"github.com/D-Modem/bbs/internal/server"
|
||||
"github.com/D-Modem/bbs/internal/sockets"
|
||||
"github.com/D-Modem/bbs/internal/store"
|
||||
"github.com/D-Modem/menu/authd"
|
||||
)
|
||||
|
||||
// usage prints the commands and exits 2.
|
||||
@@ -403,7 +403,7 @@ func serve(cfg *server.Config, path string) int {
|
||||
b.Screens, b.Menus, b.Text, b.ScriptsDir = cfg.Screens, cfg.Menus, cfg.Text, cfg.ScriptsDir
|
||||
b.Guard = cfg.Guard
|
||||
if m := cfg.MenuAuth; m != nil {
|
||||
b.MenuAuth = &menuauth.Client{Socket: m.Socket, Timeout: m.Timeout}
|
||||
b.MenuAuth = &authd.Client{Socket: m.Socket, Timeout: m.Timeout}
|
||||
b.MenuAuthCreate = m.Create
|
||||
}
|
||||
if len(cfg.Events) > 0 {
|
||||
|
||||
@@ -10,7 +10,6 @@ cover.
|
||||
| `internal/server` | listeners, session headers, rlogin, SSH, telling 3270s from the rest |
|
||||
| `internal/telnet` | the server side of telnet: options, terminal type, window size, the handoff to go3270 |
|
||||
| `internal/confedit` | bbs.conf edited as a sysop would by hand, comments kept; the catalog of keys read from bbs.conf.sample (embedded by the root package), and which take effect at a reload |
|
||||
| `internal/menuauth` | modemmenu's auth socket: passwords of the accounts it logs in, asked of its backends |
|
||||
| `internal/sockets` | ports bound as root and handed down: the BBS becomes its user, the same process |
|
||||
| `internal/backup` | backups: the configuration, a database snapshot and the files in one tar.gz; listing, pruning, restoring |
|
||||
| `internal/confui` | the configuration menus (sheets of internal/view), for `bbs config` and the sysop's tools: changes held until saved |
|
||||
|
||||
@@ -6,6 +6,7 @@ toolchain go1.24.7
|
||||
|
||||
require (
|
||||
github.com/D-Modem/go3270 v0.9.14-0.20261105104944-a6550eb72c38
|
||||
github.com/D-Modem/menu v0.0.0-20261106031303-853189d86fb2
|
||||
github.com/coder/websocket v1.8.13
|
||||
github.com/dop251/goja v0.0.0-20260603125802-cfe4039cb6d7
|
||||
github.com/ergochat/irc-go v0.7.0
|
||||
|
||||
@@ -2,6 +2,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
github.com/D-Modem/go3270 v0.9.14-0.20261105104944-a6550eb72c38 h1:fHnFrNziFJicoB5eZsBdrKHVgG5/WPV1NWZJ1CD1g7A=
|
||||
github.com/D-Modem/go3270 v0.9.14-0.20261105104944-a6550eb72c38/go.mod h1:WgdusPrfmqSMltzVXhywre6YHt9XHsKhfo9nWidkoUA=
|
||||
github.com/D-Modem/menu v0.0.0-20261106031303-853189d86fb2 h1:D7hJgxHbKQzr8850CdRuDIokcgcGOSlN1zGsh/ZuZqg=
|
||||
github.com/D-Modem/menu v0.0.0-20261106031303-853189d86fb2/go.mod h1:A+lNApUdQ5HSXW07R5aRm97MkhHYTQ1DkN0m+Vgorwg=
|
||||
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
|
||||
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
|
||||
github.com/coder/websocket v1.8.13 h1:f3QZdXy7uGVz+4uCJy2nTZyM0yTBj8yANEHhqlXZ9FE=
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
// Package menuauth asks modemmenu's auth socket ([authd] there) whether a
|
||||
// password is a user's: modemmenu's backends (its users file, LDAP, SQL,
|
||||
// the system's accounts by PAM) answer, so that callers who log in by
|
||||
// modemmenu use the same password for the BBS's telnet, SSH and web.
|
||||
package menuauth
|
||||
|
||||
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 (modemmenu waits fail_delay before a no)
|
||||
}
|
||||
|
||||
type request struct {
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type reply struct {
|
||||
OK bool `json:"ok"`
|
||||
Auth string `json:"auth"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// Check asks whether pw is user's password: true and the backend that
|
||||
// said so, false if it is not; an error if modemmenu could not be asked
|
||||
// or would not answer (refused: not a user 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)
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package menuauth
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// serve answers as modemmenu's [authd] would: alice/secret, then a
|
||||
// refusal for "eve", and silence for "slow".
|
||||
func serve(t *testing.T) string {
|
||||
sock := filepath.Join(t.TempDir(), "auth.sock")
|
||||
ln, err := net.Listen("unix", sock)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { ln.Close() })
|
||||
go func() {
|
||||
for {
|
||||
c, err := ln.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
defer c.Close()
|
||||
line, _ := bufio.NewReader(c).ReadBytes('\n')
|
||||
var r request
|
||||
json.Unmarshal(line, &r)
|
||||
switch {
|
||||
case r.User == "slow":
|
||||
time.Sleep(time.Second)
|
||||
case r.User == "eve":
|
||||
c.Write([]byte(`{"ok":false,"error":"refused"}` + "\n"))
|
||||
case r.User == "alice" && r.Password == "secret":
|
||||
c.Write([]byte(`{"ok":true,"auth":"file"}` + "\n"))
|
||||
default:
|
||||
c.Write([]byte(`{"ok":false,"error":"denied"}` + "\n"))
|
||||
}
|
||||
}()
|
||||
}
|
||||
}()
|
||||
return sock
|
||||
}
|
||||
|
||||
// TestCheck: the helper's yes (with how), its no, its refusal (an error),
|
||||
// a helper too slow, and no helper at all.
|
||||
func TestCheck(t *testing.T) {
|
||||
c := &Client{Socket: serve(t), Timeout: 300 * time.Millisecond}
|
||||
if ok, auth, err := c.Check("alice", "secret"); !ok || auth != "file" || err != nil {
|
||||
t.Errorf("alice: %v %q %v", ok, auth, err)
|
||||
}
|
||||
if ok, _, err := c.Check("alice", "wrong"); ok || err != nil {
|
||||
t.Errorf("wrong: %v %v", ok, err)
|
||||
}
|
||||
if _, _, err := c.Check("eve", "x"); err == nil || err.Error() != "refused" {
|
||||
t.Errorf("eve: %v", err)
|
||||
}
|
||||
if _, _, err := c.Check("slow", "x"); err == nil {
|
||||
t.Error("slow: no time out")
|
||||
}
|
||||
if _, _, err := (&Client{Socket: "/nonexistent/auth.sock"}).Check("alice", "secret"); err == nil {
|
||||
t.Error("no socket")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user