• Ctrl-C Trapping

    From nathanael@21:4/123 to All on Mon Jan 21 08:52:22 2019
    As I've been playing around with the issue more, it seems to be a general
    issue with Ctrl-C trapping within the Mystic client. When I run any of the following examples from a Bash prompt, Ctrl-C is trapped:

    trap '' 2;frotz seastalk.dat
    trap '' 2;nudoku
    trap '' 2;znake

    But if I run the exact same command from a Mystic menu via (DD) or (D3) Ctrl-C breaks out to a command line.

    Now this is interesting:

    If I run a trap before launching Mystic:

    trap '' 2;./mystic

    then Ctrl-C *IS* trapped and I can no longer break out to a command line.

    From the playing around I've been doing, trapping Ctrl-C before running the Mystic client makes it possible to securely run pretty much any Linux console app as a door.

    Any way I can do this?

    --nathanael
    *HUMONGOUS* BBS - jenandcal.familyds.org:2323

    --- Mystic BBS v1.12 A41 2018/12/27 (Raspberry Pi/32)
    * Origin: *HUMONGOUS* BBS (21:4/123)
  • From nathanael@21:4/123 to nathanael on Mon Jan 21 09:37:48 2019
    Any way I can do this?

    Hey, nathanael!

    (I'm talking to myself :-) )

    Here's what I've done: I renamed the mystic command to _mystic, then
    replaced it with a bash script called 'mystic':

    #!/bin/bash
    cd /mystic
    trap '' 2
    ./_mystic "$*"

    And voila! Ran across the street to 7-11, was still able to log in remotely, and it appears Ctrl-C is now being trapped.

    I'll continue testing before I go live with this, but am I missing anything obvious? Like a way to natively trap Ctrl-C in Mystic, or security concerns?

    --nathanael
    *HUMONGOUS* BBS - jenandcal.familyds.org:2323

    --- Mystic BBS v1.12 A41 2018/12/27 (Raspberry Pi/32)
    * Origin: *HUMONGOUS* BBS (21:4/123)
  • From tenser@21:1/112 to nathanael on Sun Jan 20 21:34:40 2019
    #!/bin/bash
    cd /mystic
    trap '' 2
    ./_mystic "$*"

    And voila! Ran across the street to 7-11, was still able to log in remotely, and it appears Ctrl-C is now being trapped.

    I'll continue testing before I go live with this, but am I missing anything obvious? Like a way to natively trap Ctrl-C in Mystic, or security concerns?

    Unfortunately, there is a race condition here....

    You execute `trap` to trap signal number 2 (SIGINT,
    presumably...the thing the tty driver generates if
    you hit ^C) but nothing prevents SIGINT from being
    delivered to your process *before* the `trap` command
    is interpreted by the shell.

    Also, there are a lot of other signals you might
    want to trap: SIGQUIT (generated by '^\' usually),
    SIGTSTP (^Z) etc.

    In general, trying to trap signals in a shell script
    is rough. It's better to have the forking process
    do it for you.

    --- Mystic BBS v1.12 A39 2018/04/21 (Windows/32)
    * Origin: Black Flag <ACiD Telnet HQ> blackflagbbs.com (21:1/112)
  • From nathanael@21:4/123 to tenser on Mon Jan 21 11:38:16 2019
    Unfortunately, there is a race condition here....

    True, of course. Without a way to trap from within Mystic or its door
    process, however, this is the best I could come up with.

    Also, there are a lot of other signals you might

    Thanks for the remind about ^\. I'm now trapping SIGINT(2) SIGQUIT(3) SIGTERM(15) and SIGTSTP(20). I think that covers everything a user could do from the keyboard.

    --nathanael
    *HUMONGOUS* BBS - jenandcal.familyds.org:2323

    --- Mystic BBS v1.12 A41 2018/12/27 (Raspberry Pi/32)
    * Origin: *HUMONGOUS* BBS (21:4/123)
  • From Michael Borthwick@21:4/132.1 to nathanael on Mon Jan 21 15:29:02 2019
    SIGTERM(15) and SIGTSTP(20). I think that covers everything a user could do from the keyboard.

    Not really. Work in an office environment and you'll be suprised what a
    user can do from the keyboard......

    --- MagickaBBS v0.12alpha (Linux/armv7l)
    * Origin: Fusion ~ MagickaBBS (21:4/132.1)
  • From nathanael@21:4/123 to Michael Borthwick on Mon Jan 21 13:07:58 2019
    :-) Yeah, I know. I did my time in IT desk support, including a few years of tech support for MS. Even today I still provide tech support for my mother -- who (true story!) once tried to type on the keyboard with the mouse.

    But in this case I'm only thinking as far as "accidentally break out of a
    door in unanticipated ways". So long as they stay inside the door, I'm not worried.

    --nathanael
    *HUMONGOUS* BBS - jenandcal.familyds.org:2323

    --- Mystic BBS v1.12 A41 2018/12/27 (Raspberry Pi/32)
    * Origin: *HUMONGOUS* BBS (21:4/123)
  • From Michael Borthwick@21:4/132.1 to nathanael on Mon Jan 21 17:40:48 2019
    But in this case I'm only thinking as far as "accidentally break out of a door in unanticipated ways". So long as they stay inside the door, I'm
    not worried.

    Like when they spill an entire cup of coffee on the keyboard then spend
    20 minutes mashing every button with a tea towel trying to clean it all
    up not realizing they are actually typing tons of garbage into a database
    or google search :P

    --- MagickaBBS v0.12alpha (Linux/armv7l)
    * Origin: Fusion ~ MagickaBBS (21:4/132.1)
  • From Avon@21:1/101 to Avon on Mon Jan 21 21:02:56 2019
    On 21 Jan 2019, nathanael pondered and said...

    Any way I can do this?

    Hey, nathanael!

    (I'm talking to myself :-) )


    Oh no, he's talking to himself...

    Best, Paul

    --- E:avon@bbs.nz ------ W:bbs.nz ---
    --- K:keybase.io/avon --------------

    --- Mystic BBS v1.12 A42 2018/12/30 (Windows/32)
    * Origin: Agency BBS | Dunedin, New Zealand | agency.bbs.nz (21:1/101)
  • From Avon@21:1/101 to Avon on Mon Jan 21 21:03:30 2019
    On 21 Jan 2019, Avon pondered and said...

    On 21 Jan 2019, nathanael pondered and said...

    Any way I can do this?

    Hey, nathanael!

    (I'm talking to myself :-) )


    Oh no, he's talking to himself...

    Yeah I fear it's worse than we first thought :)

    Best, Paul

    --- E:avon@bbs.nz ------ W:bbs.nz ---
    --- K:keybase.io/avon --------------

    --- Mystic BBS v1.12 A42 2018/12/30 (Windows/32)
    * Origin: Agency BBS | Dunedin, New Zealand | agency.bbs.nz (21:1/101)
  • From Fireball@21:4/145 to Avon on Mon Jan 21 09:38:22 2019
    Any way I can do this?

    Hey, nathanael!

    (I'm talking to myself :-) )


    Oh no, he's talking to himself...


    As long as he doesn't answer himself, he's ok... lol!

    Fireball

    --- Mystic BBS v1.12 A41 2018/12/27 (Linux/64)
    * Origin: Fireball Express!!! Mystic Edition (21:4/145)
  • From nathanael@21:4/123 to Michael Borthwick on Tue Jan 22 09:40:02 2019
    up not realizing they are actually typing tons of garbage into a database or google search :P

    Databases? Young'uns these days. Back in my day "databases" meant notes Scotch-taped to the fridge.

    +-----------------------+ +-------+
    | *:H:U:M:O:N:G:O:U:S:* | | B:B:S | nathanael : jenandcal.familyds.org:2323 +-----------------------+ +-------+

    --- Mystic BBS v1.12 A41 2018/12/27 (Raspberry Pi/32)
    * Origin: *HUMONGOUS* BBS (21:4/123)
  • From nathanael@21:4/123 to nathanael on Tue Jan 22 09:41:58 2019
    Nonsense. No, I'm not.

    Yes, you are.

    +-----------------------+ +-------+
    | *:H:U:M:O:N:G:O:U:S:* | | B:B:S | nathanael : jenandcal.familyds.org:2323 +-----------------------+ +-------+

    --- Mystic BBS v1.12 A41 2018/12/27 (Raspberry Pi/32)
    * Origin: *HUMONGOUS* BBS (21:4/123)
  • From nathanael@21:4/123 to nathanael on Tue Jan 22 09:42:38 2019
    Yes, you are.

    You're just jealous 'cause Mom always like me best.

    +-----------------------+ +-------+
    | *:H:U:M:O:N:G:O:U:S:* | | B:B:S | nathanael : jenandcal.familyds.org:2323 +-----------------------+ +-------+

    --- Mystic BBS v1.12 A41 2018/12/27 (Raspberry Pi/32)
    * Origin: *HUMONGOUS* BBS (21:4/123)
  • From tenser@21:1/112 to nathanael on Mon Jan 21 23:44:08 2019
    True, of course. Without a way to trap from within Mystic or its door process, however, this is the best I could come up with.

    Yeah.... Without support in the spawning process, you'll always
    have a race. Something you might do is spawn a wrapper (written
    in "C" or a similarly low-level language) that sets up signal
    handlers and then exec's the real door program. Then, if that
    C (or whatever) program takes a signal before the exec, it just
    executes the default signal action, which is hopefully harmless
    (but not, e.g., invoking a shell or something).

    Thanks for the remind about ^\. I'm now trapping SIGINT(2) SIGQUIT(3) SIGTERM(15) and SIGTSTP(20). I think that covers everything a user could do from the keyboard.

    Not a problem. A quick grep through tty.c in the kernel
    running on my machine shows the driver generating the
    following signals:

    SIGINT (^C)
    SIGQUIT (^\)
    SIGINFO (^T)
    SIGTSTP (^Z)
    SIGHUP (sent to processes on revoke(2) or close())
    SIGWINCH (Remote window size change)
    SIGTTIN (TTY read from background process)
    SIGTTOU (controlling terminal action from background process)
    SIGIO (async IO; TTY device ready for IO)

    I might have missed one, but this list looks reasonable.
    Most are pretty innocuous.

    SIGTTOU is kind of interesting; it's when a background
    process tries to do something like an ioctl() on the terminal
    device to put it into raw mode.

    --- Mystic BBS v1.12 A39 2018/04/21 (Windows/32)
    * Origin: Black Flag <ACiD Telnet HQ> blackflagbbs.com (21:1/112)
  • From g00r00@21:1/108 to nathanael on Tue Jan 22 01:10:34 2019
    Thanks for the remind about ^\. I'm now trapping SIGINT(2) SIGQUIT(3) SIGTERM(15) and SIGTSTP(20). I think that covers everything a user could do from the keyboard.

    If you trap some of these you may interfere with the operating system trying to work with Mystic's processes though. SIGTERM, SIGHUP and SIGPIPE are all trapped by Mystic itself, everything else is ignored.

    I am pretty sure I trap CTRL-C in Windows (not for doors but Mystic itself) but its been so long I'd have to go look at the code to see what I am doing in Linux. Maybe the solution is that I add whatever it is that you need to do into Mystic.

    I'll have to set up a door or something that mimics your situation for
    testing purposes, but let me make sure I understand the issue:

    You want to run a text-based non-BBS program as a door but users are able to CTRL-C out of it and end up on a bash shell. Is that correct?

    --- Mystic BBS v1.12 A42 2018/12/31 (Windows/32)
    * Origin: Sector 7 [Mystic BBS WHQ] (21:1/108)
  • From nathanael@21:4/123 to g00r00 on Wed Jan 23 02:01:56 2019
    You want to run a text-based non-BBS program as a door but users are
    able to CTRL-C out of it and end up on a bash shell. Is that correct?

    Correct.

    I've presently got BSD Games, for example, set up as doors, but they can all
    be ^C-ed. Trapping SIGINT in a bash wrapper script before running the mystic client fixes it. In theory, as tenser mentioned, it's vulnerable to a racing condition (though I suspect most folk type too slowly to make it a practical concern).

    +-----------------------+ +-------+
    | *:H:U:M:O:N:G:O:U:S:* | | B:B:S | nathanael : jenandcal.familyds.org:2323 +-----------------------+ +-------+

    --- Mystic BBS v1.12 A41 2018/12/27 (Raspberry Pi/32)
    * Origin: *HUMONGOUS* BBS (21:4/123)
  • From nathanael@21:4/123 to g00r00 on Wed Jan 23 02:12:36 2019
    trying to work with Mystic's processes though. SIGTERM, SIGHUP and SIGPIPE are all trapped by Mystic itself, everything else is ignored.

    ATM I'm trapping SIGINT, SIGQUIT SIGTERM and SIGTSTP -- basically, ^C, ^Z, ^T and ^\. Most of the BSD games still respond to ^C, I just end up back in
    Mystic instead of a command line.

    In any case, my menu entries are pretty simple:

    (DD) Exec external program
    clear;adventure

    +-----------------------+ +-------+
    | *:H:U:M:O:N:G:O:U:S:* | | B:B:S | nathanael : jenandcal.familyds.org:2323 +-----------------------+ +-------+

    --- Mystic BBS v1.12 A41 2018/12/27 (Raspberry Pi/32)
    * Origin: *HUMONGOUS* BBS (21:4/123)
  • From g00r00@21:1/108 to nathanael on Thu Jan 24 03:35:30 2019
    Correct.

    I've presently got BSD Games, for example, set up as doors, but they can all be ^C-ed. Trapping SIGINT in a bash wrapper script before running
    the mystic client fixes it. In theory, as tenser mentioned, it's vulnerable to a racing condition (though I suspect most folk type too slowly to make it a practical concern).

    Thanks! I'll have to experiment with it and see what code I already have in place and maybe I can build off of it to do something to prevent this.

    I know that Mystic already does a "watchdog" on the process while its running, so for example if the connection is dropped by the user and Mystic is executing something that isn't a BBS door capable of detecting it, then Mystic will send a SIGTERM to the subprocess the user is in and wait until it returns.

    Maybe I can build something into that system to prevent SIGINT on the child process.

    --- Mystic BBS v1.12 A42 2019/01/23 (Windows/32)
    * Origin: Sector 7 [Mystic BBS WHQ] (21:1/108)
  • From g00r00@21:1/108 to nathanael on Thu Jan 24 03:37:02 2019
    trying to work with Mystic's processes though. SIGTERM, SIGHUP and SIGPIPE are all trapped by Mystic itself, everything else is ignored.

    ATM I'm trapping SIGINT, SIGQUIT SIGTERM and SIGTSTP -- basically, ^C,
    ^Z, ^T and ^\. Most of the BSD games still respond to ^C, I just end up back in Mystic instead of a command line.

    In any case, my menu entries are pretty simple:
    (DD) Exec external program
    clear;adventure

    Perfect thanks for the clarification. I've added it to my list of things to look into and I consider this to be a pretty serious thing to address so I'll try to work on it the next time I have a good chunk of time to do some coding/testing.

    --- Mystic BBS v1.12 A42 2019/01/23 (Windows/32)
    * Origin: Sector 7 [Mystic BBS WHQ] (21:1/108)
  • From nathanael@21:4/123 to g00r00 on Thu Jan 24 23:36:10 2019
    Maybe I can build something into that system to prevent SIGINT on the child process.

    I'm not a programmer, but sometimes I want to send a Ctrl-C to the door program. For most of the BSD Games, for example, it's the only way to exit out of them.

    If I'm not trapping SIGINT, typing Ctrl-C inside a BSD game running in a door shuts down the game *and* drops me to a command line. Running fg will foreground Mystic again.

    If I am trapping SIGINT typing Ctrl-C still shuts down the game, but returns me to Mystic.

    +=======================+ +=========+ ---------------------------------------
    | *:H:U:M:O:N:G:O:U:S:* | | :B:B:S: | nathanael : jenandcal.familyds.org:2323 +=======================+ +=========+ ---------------------------------------

    --- Mystic BBS v1.12 A41 2018/12/27 (Raspberry Pi/32)
    * Origin: *HUMONGOUS* BBS (21:4/123)