diff --git a/README.md b/README.md index faa831b..62f21cb 100644 --- a/README.md +++ b/README.md @@ -395,13 +395,16 @@ and the sample's PPP item says so. BBS doors (games and utilities written for BBSs) learn who called, on what line and for how long from a drop file. An exec item with -`dropfile = door32.sys door.sys` writes those files before its program -starts and removes them after: +`dropfile = door32.sys door.sys dorinfo1.def` writes those files before +its program starts and removes them after, laid out as Synchronet, +Mystic and MBSE write them: -| file | what | -|---|---| -| `DOOR32.SYS` | 11 lines: comm type and handle, rate, BBS name, user number, name, alias, security level, **time left in minutes**, emulation, node | -| `DOOR.SYS` | the 52-line GAP format: port, rate, node, name, phone (the caller ID), security level, **seconds and minutes left**, graphics mode, user number, sysop, ... | +| `dropfile =` | file | for | what | +|---|---|---|---| +| `door32.sys` | `DOOR32.SYS` | 32-bit doors on stdin/stdout or a socket (Mystic's Door32) | 11 lines: comm type and handle, rate, BBS name, user number, name, alias, security level, **minutes left**, emulation, node | +| `door.sys` | `DOOR.SYS` | DOS doors (GAP, Wildcat, PCBoard...) | 52 lines: port, rate, node, name, phone (the caller ID), security level, **seconds and minutes left**, graphics mode, user number, sysop... (`door_sys_lines = 31`: the old 31, the rest blank) | +| `dorinfo1.def` | `DORINFO1.DEF` | RBBS, QuickBBS, RemoteAccess doors | 13 lines, upper case: BBS, sysop, port, `38400 BAUD,N,8,1`, caller's first and last name, graphics, security level, **minutes left**, FOSSIL | +| `dorinfo#.def` | `DORINFO1.DEF` to `DORINFOF.DEF` | the same, a file per node | the node as one hex digit, so 15 nodes at most | ``` [dropfile] @@ -412,7 +415,7 @@ security = 10 [item lord] key = L label = Legend of the Red Dragon -dropfile = door.sys +dropfile = door.sys dorinfo1.def dropfile_dir = /srv/doors/lord/node{node} security = 20 tty = sane @@ -436,11 +439,29 @@ version and setup.) - **Time left:** the session's at the start (a day, without a limit); the door's own clock counts down from there. - **Password:** not in the files. Doors do not need it. +- **Path:** the first file's is `{dropfile}` and `MODEM_DROPFILE`, for + doors that take it on their command line (Synchronet's `%f`). -The files have DOS line ends, as doors expect. `comm_type`, -`comm_handle` and `com_port` say how the door reaches the caller: a -door on Linux uses its stdin and stdout (the caller's line); one under -DOSEMU uses the port DOSEMU maps to them. +The files have DOS line ends, as doors expect, and upper-case names +unless `dropfile_lowercase = yes` (doors on Linux often look for +`door32.sys`). `[dropfile]` holds what they say of the BBS and the +line; its defaults are what Synchronet writes for a door on stdin and +stdout, which is how modemmenu runs doors: + +| `[dropfile]` | default | why | +|---|---|---| +| `comm_type`, `comm_handle` | `0`, `-1` | `DOOR32.SYS`: local, no handle to inherit: the door talks on its stdin and stdout, the caller's line (Synchronet's choice for stdio doors; MBSE, on a modem's tty, writes `1` serial) | +| `rate` | `38400` | the DTE rate, as Synchronet writes: doors built on DMlib and others refuse a rate a FOSSIL does not have, such as a modem's 26400. `connect` gives the modems' rate | +| `com_port`, `fossil` | `COM1:`, `yes` | a DOS door under DOSEMU reaches the caller through the port DOSEMU maps to the line, with a FOSSIL driver (`COM0:` is a local login) | +| `four_digit_years` | `no` | `DOOR.SYS`'s dates as MM/DD/YYYY, which some newer doors want (MBSE's option) | +| `bbs_name`, `sysop`, `security`, `emulation` | | what the BBS is called, its sysop, the callers' security level (an item's `security =` overrides it), `ansi` or `ascii` | + +Synchronet's documents the formats in its wiki +([DOOR32.SYS](https://wiki.synchro.net/ref:door32.sys), +[DOOR.SYS](https://wiki.synchro.net/ref:door.sys), +[DORINFO1.DEF](https://wiki.synchro.net/ref:dorinfo1.def)), and how it +runs doors on Linux ([doors](https://wiki.synchro.net/howto:door:index), +[DOSEMU](https://wiki.synchro.net/howto:dosemu)). ### Last callers @@ -620,7 +641,10 @@ and back to the menu, a cooked shell, and an exec selection's environment and session file. It also runs `modemmenu -serve` on a unix socket: a session from an app_dmodem header (on a pty of its own), a caller hanging up, another modemmenu handing a logged-in caller over by -a `mode = unix` item, and `SIGTERM`. Calls test who sees what (users, +a `mode = unix` item, and `SIGTERM`. Drop files are tested line by line in all three formats +(Synchronet's defaults, the other settings, the 31-line `DOOR.SYS`, +names split for `DORINFO1.DEF`) and on a call (the files, their names, +the node, the environment, the clean-up). Calls test who sees what (users, groups, `min_baud`, caller ID), a guest, signups (logged in at once, and pending), refused and known numbers, and a selection hung up at the day's limit, then the day's next call refused. Password changes are diff --git a/dropfile.go b/dropfile.go index 7a94ccc..a6aecd1 100644 --- a/dropfile.go +++ b/dropfile.go @@ -8,6 +8,7 @@ import ( "fmt" "os" "path/filepath" + "regexp" "strconv" "strings" "time" @@ -16,11 +17,13 @@ import ( ) // Drop files: what a BBS door reads of its caller (who, the line, the -// time left), DOOR32.SYS and DOOR.SYS, written for an exec item with -// dropfile = before its program starts, removed after. Doors want a node -// number of their own per caller and a number for each user: the nodes -// are lock files in state_dir/nodes, held while the door runs; the users' -// numbers are given once each in state_dir/usernumbers. +// time left), written for an exec item with dropfile = before its +// program starts, removed after: DOOR32.SYS, DOOR.SYS and DORINFO1.DEF +// (or DORINFO#.DEF, # the node), in the layouts the Synchronet, Mystic +// and MBSE BBSs write. Doors want a node number of their own per caller +// and a number for each user: the nodes are lock files in +// state_dir/nodes, held while the door runs; the users' numbers are +// given once each in state_dir/usernumbers. // dropfileSettings: [dropfile] type dropfileSettings struct { @@ -28,10 +31,20 @@ type dropfileSettings struct { sysop string security int emulation string // ansi, ascii - comType int // DOOR32.SYS's comm type: 0 local, 1 serial, 2 telnet - comHandle int // DOOR32.SYS's comm handle - comPort string // DOOR.SYS's port, COM1: - maxNodes int + // how the door reaches the caller: DOOR32.SYS's comm type (0 local: + // stdin and stdout, 1 serial, 2 telnet) and handle (-1 for local), + // DOOR.SYS's and DORINFO's port (COM1:, COM0: local), DORINFO's + // FOSSIL flag + comType int + comHandle int + comPort string + fossil bool + // the rate the files give: a fixed DTE rate (doors built on DMlib + // and others refuse rates a FOSSIL does not have, such as 26400), or + // "connect": the modems' + rate string + fourDigitYears bool + maxNodes int } func loadDropfile(sec *section) (dropfileSettings, error) { @@ -40,15 +53,26 @@ func loadDropfile(sec *section) (dropfileSettings, error) { bbsName: sec.get("bbs_name", "modemmenu"), sysop: sec.get("sysop", "Sysop"), emulation: strings.ToLower(sec.get("emulation", "ansi")), - comPort: sec.get("com_port", "COM1:"), + comPort: strings.ToUpper(sec.get("com_port", "COM1:")), + rate: strings.ToLower(sec.get("rate", "38400")), } if d.security, err = sec.int("security", 10); err != nil { return d, err } - if d.comType, err = sec.int("comm_type", 2); err != nil { + if d.comType, err = sec.int("comm_type", 0); err != nil { return d, err } - if d.comHandle, err = sec.int("comm_handle", 0); err != nil { + defHandle := 0 + if d.comType == 0 { + defHandle = -1 + } + if d.comHandle, err = sec.int("comm_handle", defHandle); err != nil { + return d, err + } + if d.fossil, err = sec.bool("fossil", true); err != nil { + return d, err + } + if d.fourDigitYears, err = sec.bool("four_digit_years", false); err != nil { return d, err } if d.maxNodes, err = sec.int("max_nodes", 64); err != nil { @@ -60,27 +84,46 @@ func loadDropfile(sec *section) (dropfileSettings, error) { if d.comType < 0 || d.comType > 2 { return d, fmt.Errorf("[dropfile] comm_type: %d (0 local, 1 serial, 2 telnet)", d.comType) } + if !regexp.MustCompile(`^COM[0-9]:?$`).MatchString(d.comPort) { + return d, fmt.Errorf("[dropfile] com_port: %q (COM0: to COM9:)", d.comPort) + } + if _, err := strconv.Atoi(d.rate); err != nil && d.rate != "connect" { + return d, fmt.Errorf("[dropfile] rate: %q (a number, or connect)", d.rate) + } if d.maxNodes < 1 { return d, fmt.Errorf("[dropfile] max_nodes: %d", d.maxNodes) } return d, nil } -var dropfileNames = map[string]string{"door32.sys": "DOOR32.SYS", "door.sys": "DOOR.SYS"} +// the drop files an item's dropfile = names +var dropfileNames = map[string]string{ + "door32.sys": "DOOR32.SYS", "door.sys": "DOOR.SYS", + "dorinfo1.def": "DORINFO1.DEF", "dorinfo#.def": "DORINFO#.DEF", +} -// dropfiles: what an item's dropfile = names, the files' names func loadItemDropfiles(name string, sec *section) ([]string, error) { var out []string for _, f := range fields(strings.ToLower(sec.get("dropfile", ""))) { n, ok := dropfileNames[f] if !ok { - return nil, fmt.Errorf("[item %s] dropfile: %q (door32.sys, door.sys)", name, f) + return nil, fmt.Errorf("[item %s] dropfile: %q (door32.sys, door.sys, dorinfo1.def or dorinfo#.def)", name, f) } out = append(out, n) } return out, nil } +// checkDropfiles: DORINFO#.DEF names nodes 1 to 15 (one hex digit) +func checkDropfiles(s *settings) error { + for _, it := range s.items { + if contains(it.dropfiles, "DORINFO#.DEF") && s.dropfile.maxNodes > 15 { + return fmt.Errorf("[item %s] dropfile dorinfo#.def: its name has the node as one hex digit, 1 to F: [dropfile] max_nodes must be 15 or less (it is %d)", it.name, s.dropfile.maxNodes) + } + } + return nil +} + // dropfiles: the files written for a door, and its node, until close type dropfiles struct { node int @@ -147,13 +190,22 @@ func writeDropfiles(cfg *settings, it *menuItem, s *session, deadline time.Time, security = it.security } in := dropfileInfo{s: s, df: cfg.dropfile, node: node, userNo: userNo, security: security, - minutes: minutes, seconds: seconds, now: time.Now()} + minutes: minutes, seconds: seconds, now: time.Now(), doorSysLines: it.doorSysLines} for _, name := range it.dropfiles { var lines []string - if name == "DOOR32.SYS" { + switch name { + case "DOOR32.SYS": lines = in.door32() - } else { + case "DOOR.SYS": lines = in.doorSys() + default: + lines = in.dorinfo() + if name == "DORINFO#.DEF" { + name = fmt.Sprintf("DORINFO%X.DEF", node) + } + } + if it.dropfileLower { + name = strings.ToLower(name) } path := filepath.Join(d.dir, name) // DOS's line ends: what doors read @@ -176,16 +228,34 @@ type dropfileInfo struct { security int minutes, seconds int now time.Time + doorSysLines int // 52, or 31 (then the last 21 blank) } -func (in dropfileInfo) baud() string { +// rate: the rate the files give +func (in dropfileInfo) rate() string { + if in.df.rate != "connect" { + return in.df.rate + } if in.s.Baud != "" { return in.s.Baud } return "0" } -// door32: DOOR32.SYS, its 11 lines +func (in dropfileInfo) date(t time.Time) string { + if in.df.fourDigitYears { + return t.Format("01/02/2006") + } + return t.Format("01/02/06") +} + +// split: a name's first word and the rest +func split(name string) (string, string) { + first, rest, _ := strings.Cut(strings.TrimSpace(name), " ") + return first, strings.TrimSpace(rest) +} + +// door32: DOOR32.SYS (Mystic's Door32 revision 1), its 11 lines func (in dropfileInfo) door32() []string { emu := "1" if in.df.emulation == "ascii" { @@ -193,8 +263,8 @@ func (in dropfileInfo) door32() []string { } return []string{ strconv.Itoa(in.df.comType), // comm type: 0 local, 1 serial, 2 telnet - strconv.Itoa(in.df.comHandle), // comm or socket handle - in.baud(), // baud rate + strconv.Itoa(in.df.comHandle), // comm or socket handle (-1 local) + in.rate(), // baud rate in.df.bbsName, // BBS software strconv.Itoa(in.userNo), // user record number in.s.User, // real name @@ -206,19 +276,22 @@ func (in dropfileInfo) door32() []string { } } -// doorSys: DOOR.SYS (the GAP format), its 52 lines +// doorSys: DOOR.SYS (the GAP format), its 52 lines; with door_sys_lines = +// 31 the first 31, then the rest blank (as Synchronet writes it, for +// doors that do not take the longer one) func (in dropfileInfo) doorSys() []string { - date := in.now.Format("01/02/06") + date := in.date(in.now) graphics := "GR" if in.df.emulation == "ascii" { graphics = "NG" } - return []string{ - in.df.comPort, // 1 port, COM0: local - in.baud(), // 2 baud rate + port := strings.TrimSuffix(in.df.comPort, ":") + ":" + lines := []string{ + port, // 1 port, COM0: local + in.rate(), // 2 baud rate "8", // 3 data bits strconv.Itoa(in.node), // 4 node - in.baud(), // 5 DTE rate + in.rate(), // 5 DTE rate "Y", // 6 screen display "N", // 7 printer "N", // 8 page bell @@ -237,36 +310,76 @@ func (in dropfileInfo) doorSys() []string { "24", // 21 screen length "Y", // 22 expert mode "", // 23 conferences - "", // 24 conference - "12/31/99", // 25 expiration - strconv.Itoa(in.userNo), // 26 user record number - "Z", // 27 protocol: ZMODEM - "0", // 28 uploads - "0", // 29 downloads - "0", // 30 K downloaded today - "0", // 31 K a day at most - "01/01/80", // 32 birth date - "", // 33 main directory - "", // 34 GEN directory - in.df.sysop, // 35 sysop - in.s.User, // 36 alias - "00:00", // 37 event time - "Y", // 38 error-correcting connection - "N", // 39 ANSI in NG mode - "Y", // 40 record locking - "7", // 41 default color - "0", // 42 time credits, minutes - date, // 43 last new files scan - in.now.Format("15:04"), // 44 time of this call - in.now.Format("15:04"), // 45 time of the last call - "0", // 46 files a day at most - "0", // 47 files downloaded today - "0", // 48 K uploaded - "0", // 49 K downloaded - "", // 50 comment - "0", // 51 doors opened - "0", // 52 messages left + "0", // 24 conference + in.date(time.Date(2099, 12, 31, 0, 0, 0, 0, time.UTC)), // 25 expiration + strconv.Itoa(in.userNo), // 26 user record number + "Z", // 27 protocol: ZMODEM + "0", // 28 uploads + "0", // 29 downloads + "0", // 30 K downloaded today + "999999", // 31 K a day at most + in.date(time.Date(1980, 1, 1, 0, 0, 0, 0, time.UTC)), // 32 birth date + "", // 33 main directory + "", // 34 GEN directory + in.df.sysop, // 35 sysop + in.s.User, // 36 alias + "00:00", // 37 event time + "Y", // 38 error-correcting connection + "N", // 39 ANSI in NG mode + "Y", // 40 record locking + "7", // 41 default color + "0", // 42 time credits, minutes + date, // 43 last new files scan + in.now.Format("15:04"), // 44 time of this call + in.now.Format("15:04"), // 45 time of the last call + "32768", // 46 files a day at most + "0", // 47 files downloaded today + "0", // 48 K uploaded + "0", // 49 K downloaded + "", // 50 comment + "0", // 51 doors opened + "0", // 52 messages left } + if in.doorSysLines == 31 { + for i := 31; i < len(lines); i++ { + lines[i] = "" + } + } + return lines +} + +// dorinfo: DORINFO1.DEF (RBBS-PC, QuickBBS, RemoteAccess), its 13 lines, +// in upper case as RBBS wrote it; the names split at their first space +func (in dropfileInfo) dorinfo() []string { + sysFirst, sysLast := split(in.df.sysop) + first, last := split(in.s.User) + graphics := "1" + if in.df.emulation == "ascii" { + graphics = "0" + } + fossil := "0" + if in.df.fossil { + fossil = "-1" + } + lines := []string{ + in.df.bbsName, // 1 BBS name + sysFirst, // 2 sysop's first name + sysLast, // 3 sysop's last name + strings.TrimSuffix(in.df.comPort, ":"), // 4 port: COM1, COM0 local + in.rate() + " BAUD,N,8,1", // 5 rate and line settings + "0", // 6 networked: no + first, // 7 caller's first name + last, // 8 caller's last name + "", // 9 caller's city + graphics, // 10 graphics: 0 ASCII, 1 ANSI + strconv.Itoa(in.security), // 11 security level + strconv.Itoa(in.minutes), // 12 minutes left + fossil, // 13 FOSSIL: -1 yes, 0 no + } + for i := range lines { + lines[i] = strings.ToUpper(lines[i]) + } + return lines } // takeNode: the first free node of max (its lock file in dir/nodes, held diff --git a/dropfile_test.go b/dropfile_test.go index 47a3035..3f225cd 100644 --- a/dropfile_test.go +++ b/dropfile_test.go @@ -16,24 +16,70 @@ import ( ) func TestDropfileFormats(t *testing.T) { - s := &session{User: "alice", Baud: "33600", CallerID: "5559999"} - in := dropfileInfo{s: s, df: dropfileSettings{bbsName: "Test BBS", sysop: "Sysop", emulation: "ansi", - comType: 2, comPort: "COM1:"}, node: 3, userNo: 7, security: 50, minutes: 42, seconds: 2530, - now: time.Date(2026, 10, 15, 21, 5, 0, 0, time.UTC)} - d32 := in.door32() - if len(d32) != 11 || d32[0] != "2" || d32[2] != "33600" || d32[3] != "Test BBS" || d32[4] != "7" || - d32[5] != "alice" || d32[7] != "50" || d32[8] != "42" || d32[9] != "1" || d32[10] != "3" { - t.Errorf("DOOR32.SYS %q", d32) + sec := §ion{name: "dropfile", vals: map[string]string{"bbs_name": "Test BBS", "sysop": "Ada Lovelace"}} + df, err := loadDropfile(sec) + if err != nil { + t.Fatal(err) } + s := &session{User: "alice", Baud: "26400", CallerID: "5559999"} + in := dropfileInfo{s: s, df: df, node: 3, userNo: 7, security: 50, minutes: 42, seconds: 2530, + now: time.Date(2026, 10, 15, 21, 5, 0, 0, time.UTC), doorSysLines: 52} + + // DOOR32.SYS: a stdio door is local, handle -1 (as Synchronet); the + // DTE rate, 38400, not the modems' 26400 + d32 := in.door32() + want32 := []string{"0", "-1", "38400", "Test BBS", "7", "alice", "alice", "50", "42", "1", "3"} + if strings.Join(d32, "|") != strings.Join(want32, "|") { + t.Errorf("DOOR32.SYS\n%q\nwant\n%q", d32, want32) + } + ds := in.doorSys() - if len(ds) != 52 || ds[0] != "COM1:" || ds[3] != "3" || ds[9] != "alice" || ds[13] != "" || - ds[14] != "50" || ds[16] != "10/15/26" || ds[17] != "2530" || ds[18] != "42" || ds[19] != "GR" || - ds[25] != "7" || ds[34] != "Sysop" { + if len(ds) != 52 || ds[0] != "COM1:" || ds[1] != "38400" || ds[3] != "3" || ds[4] != "38400" || + ds[9] != "alice" || ds[11] != "5559999" || ds[13] != "" || ds[14] != "50" || ds[16] != "10/15/26" || + ds[17] != "2530" || ds[18] != "42" || ds[19] != "GR" || ds[24] != "12/31/99" || ds[25] != "7" || + ds[30] != "999999" || ds[34] != "Ada Lovelace" || ds[45] != "32768" || ds[51] != "0" { t.Errorf("DOOR.SYS %q", ds) } - in.df.emulation = "ascii" - if in.door32()[9] != "0" || in.doorSys()[19] != "NG" { - t.Error("ascii") + in.doorSysLines = 31 + if ds := in.doorSys(); len(ds) != 52 || ds[30] != "999999" || ds[31] != "" || ds[34] != "" || ds[51] != "" { + t.Errorf("DOOR.SYS, 31 lines: %q", ds) + } + in.doorSysLines = 52 + + // DORINFO1.DEF: 13 lines, upper case, names split at the first space + di := in.dorinfo() + wantDI := []string{"TEST BBS", "ADA", "LOVELACE", "COM1", "38400 BAUD,N,8,1", "0", "ALICE", "", "", "1", "50", "42", "-1"} + if strings.Join(di, "|") != strings.Join(wantDI, "|") { + t.Errorf("DORINFO1.DEF\n%q\nwant\n%q", di, wantDI) + } + in.s = &session{User: "bob smith jr"} + if di := in.dorinfo(); di[6] != "BOB" || di[7] != "SMITH JR" { + t.Errorf("a name with spaces: %q %q", di[6], di[7]) + } + in.s = s + + // the modems' rate, ASCII, four-digit years, no FOSSIL, local port + sec.vals["rate"], sec.vals["emulation"], sec.vals["four_digit_years"] = "connect", "ascii", "yes" + sec.vals["fossil"], sec.vals["com_port"], sec.vals["comm_type"] = "no", "com0:", "2" + if in.df, err = loadDropfile(sec); err != nil { + t.Fatal(err) + } + d32, ds, di = in.door32(), in.doorSys(), in.dorinfo() + if d32[0] != "2" || d32[1] != "0" || d32[2] != "26400" || d32[9] != "0" { + t.Errorf("DOOR32.SYS %q", d32) + } + if ds[0] != "COM0:" || ds[1] != "26400" || ds[16] != "10/15/2026" || ds[19] != "NG" { + t.Errorf("DOOR.SYS %q", ds) + } + if di[3] != "COM0" || di[4] != "26400 BAUD,N,8,1" || di[9] != "0" || di[12] != "0" { + t.Errorf("DORINFO1.DEF %q", di) + } + + for k, v := range map[string]string{"comm_type": "3", "com_port": "LPT1", "rate": "fast", "emulation": "rip", "max_nodes": "0"} { + bad := §ion{name: "dropfile", vals: map[string]string{k: v}} + if _, err := loadDropfile(bad); err == nil { + t.Errorf("%s = %s: no error", k, v) + } } } @@ -90,10 +136,11 @@ state_dir = %s path = %s [dropfile] bbs_name = Test BBS +max_nodes = 15 [item door] -dropfile = door32.sys door.sys +dropfile = door32.sys door.sys dorinfo#.def security = 90 -command = cp {dropfile_dir}/DOOR32.SYS {dropfile_dir}/DOOR.SYS %s/; echo DOOR node={node} "$MODEM_NODE left=$MODEM_TIME_LEFT/$MODEM_SECONDS_LEFT dir=$MODEM_DROPFILE_DIR" +command = cp {dropfile_dir}/* %s/; echo DOOR node={node} "$MODEM_NODE left=$MODEM_TIME_LEFT/$MODEM_SECONDS_LEFT first=$(basename $MODEM_DROPFILE) dir=$MODEM_DROPFILE_DIR" after = menu `, filepath.Join(dir, "state"), users, out)), 0o600) @@ -113,14 +160,22 @@ after = menu d32, _ := os.ReadFile(filepath.Join(out, "DOOR32.SYS")) lines := strings.Split(string(d32), "\r\n") - if len(lines) != 12 || lines[2] != "26400" || lines[3] != "Test BBS" || lines[5] != "alice" || - lines[7] != "90" || (lines[8] != "9" && lines[8] != "10") || lines[10] != "1" { + if len(lines) != 12 || lines[0] != "0" || lines[1] != "-1" || lines[2] != "38400" || lines[3] != "Test BBS" || + lines[5] != "alice" || lines[7] != "90" || (lines[8] != "9" && lines[8] != "10") || lines[10] != "1" { t.Errorf("DOOR32.SYS %q", d32) } ds, _ := os.ReadFile(filepath.Join(out, "DOOR.SYS")) if n := strings.Count(string(ds), "\r\n"); n != 52 { t.Errorf("DOOR.SYS: %d lines", n) } + // DORINFO#.DEF: the node as a hex digit + di, err := os.ReadFile(filepath.Join(out, "DORINFO1.DEF")) + if n := strings.Count(string(di), "\r\n"); err != nil || n != 13 || !strings.HasPrefix(string(di), "TEST BBS\r\n") { + t.Errorf("DORINFO1.DEF: %d lines, %v:\n%q", n, err, di) + } + if !strings.Contains(got, "first=DOOR32.SYS") { + t.Errorf("MODEM_DROPFILE: %q", got) + } // the files and their directory are gone, the node free i := strings.Index(got, "dir=") tmp := strings.TrimSpace(strings.SplitN(got[i+4:], "\r\n", 2)[0]) @@ -226,3 +281,53 @@ func TestHeaderTimeLeft(t *testing.T) { t.Errorf("from minutes: %s", env) } } + +func TestDropfileSettings(t *testing.T) { + dir := t.TempDir() + users := filepath.Join(dir, "users") + os.WriteFile(users, nil, 0o600) + load := func(extra string) error { + p := filepath.Join(dir, "c.conf") + os.WriteFile(p, []byte("[general]\nauth = file\n[file]\npath = "+users+"\n"+extra), 0o600) + _, err := loadSettings(p) + return err + } + if err := load("[item d]\ndropfile = dorinfo#.def\ncommand = true\n"); err == nil { + t.Error("dorinfo#.def with 64 nodes: no error") + } + if err := load("[dropfile]\nmax_nodes = 15\n[item d]\ndropfile = dorinfo#.def door.sys\ndoor_sys_lines = 31\ndropfile_lowercase = yes\ncommand = true\n"); err != nil { + t.Errorf("dorinfo#.def with 15 nodes: %v", err) + } + for _, bad := range []string{"dropfile = chain.txt", "dropfile = door.sys\ndoor_sys_lines = 40", "dropfile = door.sys\nmode = tcp"} { + if err := load("[item d]\n" + bad + "\ncommand = true\n"); err == nil { + t.Errorf("%q: no error", bad) + } + } +} + +// the files' names in lower case, for doors on case-sensitive systems +func TestDropfileLowercase(t *testing.T) { + dir := t.TempDir() + cfg := &settings{} + cfg.limits.stateDir = dir + cfg.dropfile, _ = loadDropfile(§ion{name: "dropfile", vals: map[string]string{}}) + it := &menuItem{name: "d", dropfiles: []string{"DOOR32.SYS", "DORINFO1.DEF"}, dropfileLower: true, doorSysLines: 52} + df, err := writeDropfiles(cfg, it, &session{User: "alice"}, time.Time{}, -1, -1) + if err != nil { + t.Fatal(err) + } + for _, f := range []string{"door32.sys", "dorinfo1.def"} { + if _, err := os.Stat(filepath.Join(df.dir, f)); err != nil { + t.Errorf("%s: %v", f, err) + } + } + // no limit: a day + b, _ := os.ReadFile(filepath.Join(df.dir, "door32.sys")) + if strings.Split(string(b), "\r\n")[8] != "1440" { + t.Errorf("no limit: %q", b) + } + df.close() + if _, err := os.Stat(df.dir); err == nil { + t.Error("the directory is still there") + } +} diff --git a/launch.go b/launch.go index c877083..169dc93 100644 --- a/launch.go +++ b/launch.go @@ -95,7 +95,10 @@ func runExec(t *term, cfg *settings, it *menuItem, s *session, deadline time.Tim } defer df.close() v["node"], v["dropfile_dir"] = strconv.Itoa(df.node), df.dir - env = append(env, "MODEM_NODE="+v["node"], "MODEM_DROPFILE_DIR="+df.dir) + // the first file's path, as BBSs pass it (Synchronet's %f) + v["dropfile"] = df.files[0] + env = append(env, "MODEM_NODE="+v["node"], "MODEM_DROPFILE_DIR="+df.dir, + "MODEM_DROPFILE="+df.files[0]) } cmd := exec.Command("/bin/sh", "-c", expand(it.command, v, shellQuote)) diff --git a/modemmenu.conf.sample b/modemmenu.conf.sample index 198c871..bc18c03 100644 --- a/modemmenu.conf.sample +++ b/modemmenu.conf.sample @@ -235,7 +235,8 @@ max_sessions = 32 ;max_clients = 16 ; drop files for doors (an exec item's dropfile =): what they say of the -; BBS, and how the door reaches the caller +; BBS, and how the door reaches the caller. The defaults are what +; Synchronet writes for a door on stdin and stdout [dropfile] bbs_name = modemmenu sysop = Sysop @@ -243,14 +244,22 @@ sysop = Sysop security = 10 ; ansi or ascii emulation = ansi -; DOOR32.SYS: 0 local, 1 serial, 2 telnet, and its handle; DOOR.SYS's port -; (COM0: is local). A door on Linux talks on its stdin and stdout, which -; is the caller's line, whatever these say; doors under DOSEMU want the -; port DOSEMU gives them -comm_type = 2 -comm_handle = 0 +; DOOR32.SYS's comm type: 0 local (stdin and stdout: a door on the line), +; 1 serial, 2 telnet; its handle (-1 for 0, else 0 by default) +comm_type = 0 +;comm_handle = -1 +; DOOR.SYS's and DORINFO's port: COM1: (COM0: is local); a DOS door under +; DOSEMU wants the port DOSEMU gives it, with a FOSSIL driver (DORINFO's +; FOSSIL flag) com_port = COM1: -; doors running at once, each on a node of its own (state_dir/nodes) +fossil = yes +; the rate the files give: a FOSSIL's rate (doors built on DMlib refuse +; others, such as a modem's 26400), or connect for the modems' +rate = 38400 +; MM/DD/YYYY instead of MM/DD/YY in DOOR.SYS (some newer doors) +four_digit_years = no +; doors running at once, each on a node of its own (state_dir/nodes); +; 15 at most with dorinfo#.def max_nodes = 64 [menu] @@ -307,14 +316,19 @@ hotkeys = no ; guest = no yes: guests see it too ; ; A door (mode = exec) and its drop files: -; dropfile = door32.sys door.sys +; dropfile = door32.sys door.sys dorinfo1.def dorinfo#.def ; written before the program starts, removed after, ; with the user, the rate and the time left; the -; node and the directory are {node} and -; {dropfile_dir} in command, MODEM_NODE and -; MODEM_DROPFILE_DIR in the environment +; node, the directory and the first file are +; {node}, {dropfile_dir} and {dropfile} in command, +; MODEM_NODE, MODEM_DROPFILE_DIR and MODEM_DROPFILE +; in the environment. dorinfo#.def: DORINFO1.DEF to +; DORINFOF.DEF by the node ; dropfile_dir = where (e.g. /srv/doors/node{node}); default: a new ; directory each time +; dropfile_lowercase = no yes: door32.sys..., for doors on Linux +; door_sys_lines = 52 31: the old DOOR.SYS (the rest blank), for doors +; that do not take the longer one ; security = 0 the drop files' security level ([dropfile]'s if 0) ; A BBS by rlogin: Synchronet and Mystic log the caller in with the user @@ -386,7 +400,7 @@ after = menu ;[item lord] ;key = L ;label = Legend of the Red Dragon -;dropfile = door.sys +;dropfile = door.sys dorinfo1.def ;dropfile_dir = /srv/doors/lord/node{node} ;tty = sane ;command = cd /srv/doors/lord && exec dosemu -dumb -E "lord.bat $MODEM_NODE" diff --git a/settings.go b/settings.go index 2e46e54..511c7ba 100644 --- a/settings.go +++ b/settings.go @@ -32,34 +32,36 @@ type general struct { } type menuItem struct { - name string - key string // shown in the menu - choices []string // what selects it, upper case: key, name, aliases - label string - mode string // exec, tcp, rlogin, telnet - command string - host string - port int - path string // a unix socket instead of host and port - header bool // the session header first - send string - rloginLocal string - rloginUser string - rloginTerm string - terminal string - runAs string - tty string // raw, sane - password bool - sessionFile bool - after string // hangup, menu - timeout time.Duration - access itemAccess - minPassword int // mode = passwd - timeWarning bool // the time_warning is written on the line - dropfiles []string // DOOR32.SYS, DOOR.SYS - dropfileDir string // where ("": a new directory each time) - security int // the drop files' security level (0: [dropfile]'s) - count int // mode = callers: how many + name string + key string // shown in the menu + choices []string // what selects it, upper case: key, name, aliases + label string + mode string // exec, tcp, rlogin, telnet + command string + host string + port int + path string // a unix socket instead of host and port + header bool // the session header first + send string + rloginLocal string + rloginUser string + rloginTerm string + terminal string + runAs string + tty string // raw, sane + password bool + sessionFile bool + after string // hangup, menu + timeout time.Duration + access itemAccess + minPassword int // mode = passwd + timeWarning bool // the time_warning is written on the line + dropfiles []string // DOOR32.SYS, DOOR.SYS + dropfileDir string // where ("": a new directory each time) + security int // the drop files' security level (0: [dropfile]'s) + doorSysLines int // DOOR.SYS: 52, or 31 (the rest blank) + dropfileLower bool // the files' names in lower case + count int // mode = callers: how many } // serverSettings: [server], for modemmenu -serve @@ -220,6 +222,9 @@ func loadSettings(path string) (*settings, error) { if err := checkAccess(s); err != nil { return nil, err } + if err := checkDropfiles(s); err != nil { + return nil, err + } if s.hotkeys { for _, it := range s.items { if len(it.key) != 1 { @@ -285,6 +290,15 @@ func loadItem(name string, sec *section) (*menuItem, error) { if it.security, err = sec.int("security", 0); err != nil { return nil, err } + if it.doorSysLines, err = sec.int("door_sys_lines", 52); err != nil { + return nil, err + } + if it.doorSysLines != 52 && it.doorSysLines != 31 { + return nil, fmt.Errorf("[item %s] door_sys_lines: %d (52 or 31)", name, it.doorSysLines) + } + if it.dropfileLower, err = sec.bool("dropfile_lowercase", false); err != nil { + return nil, err + } if len(it.dropfiles) > 0 && strings.ToLower(sec.get("mode", "exec")) != "exec" { return nil, fmt.Errorf("[item %s] dropfile is for mode = exec", name) }