summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2020-05-21 15:09:49 -0400
committerGitHub <noreply@github.com>2020-05-21 13:09:49 -0600
commitbb67e19d7bacd70a13647538c8e9820eb42090b2 (patch)
treee210b62e41bdf31da0c812268ecf7c9393799daf /modules
parent1dc4ec2d77f6f239f4c17e8ba754e71655796a4d (diff)
cmd: hash-password: Fix broken terminal state on SIGINT (#3416)
* caddyauth: Fix hash-password broken terminal state on SIGINT * caddycmd: Move TrapSignals calls to only subcommands that run long
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/caddyauth/command.go27
-rw-r--r--modules/caddyhttp/fileserver/command.go2
-rw-r--r--modules/caddyhttp/reverseproxy/command.go2
3 files changed, 24 insertions, 7 deletions
diff --git a/modules/caddyhttp/caddyauth/command.go b/modules/caddyhttp/caddyauth/command.go
index 2c08815..f3e1809 100644
--- a/modules/caddyhttp/caddyauth/command.go
+++ b/modules/caddyhttp/caddyauth/command.go
@@ -21,6 +21,7 @@ import (
"flag"
"fmt"
"os"
+ "os/signal"
"github.com/caddyserver/caddy/v2"
caddycmd "github.com/caddyserver/caddy/v2/cmd"
@@ -67,17 +68,29 @@ func cmdHashPassword(fs caddycmd.Flags) (int, error) {
salt := []byte(fs.String("salt"))
if len(plaintext) == 0 {
- if terminal.IsTerminal(int(os.Stdin.Fd())) {
- fmt.Print("Enter password: ")
- plaintext, err = terminal.ReadPassword(int(os.Stdin.Fd()))
- fmt.Println()
+ fd := int(os.Stdin.Fd())
+ if terminal.IsTerminal(fd) {
+ // ensure the terminal state is restored on SIGINT
+ state, _ := terminal.GetState(fd)
+ c := make(chan os.Signal)
+ signal.Notify(c, os.Interrupt)
+ go func() {
+ <-c
+ _ = terminal.Restore(fd, state)
+ os.Exit(caddy.ExitCodeFailedStartup)
+ }()
+ defer signal.Stop(c)
+
+ fmt.Fprint(os.Stderr, "Enter password: ")
+ plaintext, err = terminal.ReadPassword(fd)
+ fmt.Fprintln(os.Stderr)
if err != nil {
return caddy.ExitCodeFailedStartup, err
}
- fmt.Print("Confirm password: ")
- confirmation, err := terminal.ReadPassword(int(os.Stdin.Fd()))
- fmt.Println()
+ fmt.Fprint(os.Stderr, "Confirm password: ")
+ confirmation, err := terminal.ReadPassword(fd)
+ fmt.Fprintln(os.Stderr)
if err != nil {
return caddy.ExitCodeFailedStartup, err
}
diff --git a/modules/caddyhttp/fileserver/command.go b/modules/caddyhttp/fileserver/command.go
index 53aa7aa..6a44b3c 100644
--- a/modules/caddyhttp/fileserver/command.go
+++ b/modules/caddyhttp/fileserver/command.go
@@ -61,6 +61,8 @@ respond with a file listing.`,
}
func cmdFileServer(fs caddycmd.Flags) (int, error) {
+ caddy.TrapSignals()
+
domain := fs.String("domain")
root := fs.String("root")
listen := fs.String("listen")
diff --git a/modules/caddyhttp/reverseproxy/command.go b/modules/caddyhttp/reverseproxy/command.go
index 6de052e..a5939a2 100644
--- a/modules/caddyhttp/reverseproxy/command.go
+++ b/modules/caddyhttp/reverseproxy/command.go
@@ -66,6 +66,8 @@ default, all incoming headers are passed through unmodified.)
}
func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
+ caddy.TrapSignals()
+
from := fs.String("from")
to := fs.String("to")
changeHost := fs.Bool("change-host-header")