toggledlog: convert remaing naked fmt.Print*
Several fatal errors were just printed to stdout, which meant they were invisible when running the test suite. Fix this by introducing toggledlog.Fatal and convert as follows: Fatal errors -> toggledlog.Fatal Warnings -> toggledlog.Warn Password prompts -> fmt.Fprintf
This commit is contained in:
parent
ca54b665e3
commit
0c80cca674
|
@ -6,6 +6,8 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/rfjakob/gocryptfs/internal/toggledlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The child sends us USR1 if the mount was successful
|
// The child sends us USR1 if the mount was successful
|
||||||
|
@ -30,7 +32,7 @@ func forkChild() {
|
||||||
c.Stdin = os.Stdin
|
c.Stdin = os.Stdin
|
||||||
err := c.Start()
|
err := c.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("forkChild: starting %s failed: %v\n", name, err)
|
toggledlog.Fatal.Printf("forkChild: starting %s failed: %v\n", name, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
err = c.Wait()
|
err = c.Wait()
|
||||||
|
@ -40,7 +42,7 @@ func forkChild() {
|
||||||
os.Exit(waitstat.ExitStatus())
|
os.Exit(waitstat.ExitStatus())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf("forkChild: wait returned an unknown error: %v\n", err)
|
toggledlog.Fatal.Printf("forkChild: wait returned an unknown error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
// The child exited with 0 - let's do the same.
|
// The child exited with 0 - let's do the same.
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package configfile
|
package configfile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"golang.org/x/crypto/scrypt"
|
"golang.org/x/crypto/scrypt"
|
||||||
|
|
||||||
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
||||||
|
"github.com/rfjakob/gocryptfs/internal/toggledlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -31,7 +32,7 @@ func NewScryptKdf(logN int) scryptKdf {
|
||||||
s.N = 1 << ScryptDefaultLogN
|
s.N = 1 << ScryptDefaultLogN
|
||||||
} else {
|
} else {
|
||||||
if logN < 10 {
|
if logN < 10 {
|
||||||
fmt.Println("Error: scryptn below 10 is too low to make sense. Aborting.")
|
toggledlog.Fatal.Println("Error: scryptn below 10 is too low to make sense. Aborting.")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
s.N = 1 << uint32(logN)
|
s.N = 1 << uint32(logN)
|
||||||
|
@ -45,7 +46,7 @@ func NewScryptKdf(logN int) scryptKdf {
|
||||||
func (s *scryptKdf) DeriveKey(pw string) []byte {
|
func (s *scryptKdf) DeriveKey(pw string) []byte {
|
||||||
k, err := scrypt.Key([]byte(pw), s.Salt, s.N, s.R, s.P, s.KeyLen)
|
k, err := scrypt.Key([]byte(pw), s.Salt, s.N, s.R, s.P, s.KeyLen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("DeriveKey failed: %s", err.Error()))
|
log.Panicf("DeriveKey failed: %v", err)
|
||||||
}
|
}
|
||||||
return k
|
return k
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package prefer_openssl
|
package prefer_openssl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/rfjakob/gocryptfs/internal/toggledlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// filePreferOpenSSL tells us if OpenSSL is faster than Go GCM on this machine.
|
// filePreferOpenSSL tells us if OpenSSL is faster than Go GCM on this machine.
|
||||||
|
@ -17,12 +18,12 @@ import (
|
||||||
func filePreferOpenSSL(file string) bool {
|
func filePreferOpenSSL(file string) bool {
|
||||||
ci, err := ioutil.ReadFile(file)
|
ci, err := ioutil.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
toggledlog.Warn.Println(err)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
haveAes, err := regexp.Match(`(?m)^flags.*\baes\b`, ci)
|
haveAes, err := regexp.Match(`(?m)^flags.*\baes\b`, ci)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
toggledlog.Warn.Println(err)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return !haveAes
|
return !haveAes
|
||||||
|
|
|
@ -49,18 +49,24 @@ func (l *toggledLogger) Println(v ...interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// As defined by http://elinux.org/Debugging_by_printing#Log_Levels
|
|
||||||
// Debug messages
|
// Debug messages
|
||||||
|
// Can be enabled by passing "-d"
|
||||||
var Debug *toggledLogger
|
var Debug *toggledLogger
|
||||||
|
|
||||||
// Informational message e.g. startup information
|
// Informational message
|
||||||
|
// Can be disabled by passing "-q"
|
||||||
var Info *toggledLogger
|
var Info *toggledLogger
|
||||||
|
|
||||||
// A warning, meaning nothing serious by itself but might indicate problems
|
// A warning, meaning nothing serious by itself but might indicate problems.
|
||||||
|
// Passing "-wpanic" will make this function panic after printing the message.
|
||||||
var Warn *toggledLogger
|
var Warn *toggledLogger
|
||||||
|
|
||||||
|
// Fatal error, we are about to exit
|
||||||
|
var Fatal *toggledLogger
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Debug = &toggledLogger{false, false, log.New(os.Stdout, "", 0)}
|
Debug = &toggledLogger{false, false, log.New(os.Stdout, "", 0)}
|
||||||
Info = &toggledLogger{true, false, log.New(os.Stdout, "", 0)}
|
Info = &toggledLogger{true, false, log.New(os.Stdout, "", 0)}
|
||||||
Warn = &toggledLogger{true, false, log.New(os.Stderr, "", 0)}
|
Warn = &toggledLogger{true, false, log.New(os.Stderr, "", 0)}
|
||||||
|
Fatal = &toggledLogger{true, false, log.New(os.Stderr, "", 0)}
|
||||||
}
|
}
|
||||||
|
|
54
main.go
54
main.go
|
@ -61,7 +61,7 @@ var GitVersionFuse = "[version not set - please compile using ./build.bash]"
|
||||||
func initDir(args *argContainer) {
|
func initDir(args *argContainer) {
|
||||||
err := checkDirEmpty(args.cipherdir)
|
err := checkDirEmpty(args.cipherdir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Invalid cipherdir: %v\n", err)
|
toggledlog.Fatal.Printf("Invalid cipherdir: %v\n", err)
|
||||||
os.Exit(ERREXIT_INIT)
|
os.Exit(ERREXIT_INIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ func initDir(args *argContainer) {
|
||||||
creator := toggledlog.ProgramName + " " + GitVersion
|
creator := toggledlog.ProgramName + " " + GitVersion
|
||||||
err = configfile.CreateConfFile(args.config, password, args.plaintextnames, args.scryptn, creator)
|
err = configfile.CreateConfFile(args.config, password, args.plaintextnames, args.scryptn, creator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
toggledlog.Fatal.Println(err)
|
||||||
os.Exit(ERREXIT_INIT)
|
os.Exit(ERREXIT_INIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ func initDir(args *argContainer) {
|
||||||
// Create gocryptfs.diriv in the root dir
|
// Create gocryptfs.diriv in the root dir
|
||||||
err = nametransform.WriteDirIV(args.cipherdir)
|
err = nametransform.WriteDirIV(args.cipherdir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
toggledlog.Fatal.Println(err)
|
||||||
os.Exit(ERREXIT_INIT)
|
os.Exit(ERREXIT_INIT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,10 +103,13 @@ func initDir(args *argContainer) {
|
||||||
|
|
||||||
func usageText() {
|
func usageText() {
|
||||||
printVersion()
|
printVersion()
|
||||||
fmt.Printf("\n")
|
fmt.Printf(`
|
||||||
fmt.Printf("Usage: %s -init|-passwd [OPTIONS] CIPHERDIR\n", toggledlog.ProgramName)
|
Usage: %s -init|-passwd [OPTIONS] CIPHERDIR
|
||||||
fmt.Printf(" or %s [OPTIONS] CIPHERDIR MOUNTPOINT\n", toggledlog.ProgramName)
|
or %s [OPTIONS] CIPHERDIR MOUNTPOINT
|
||||||
fmt.Printf("\nOptions:\n")
|
|
||||||
|
Options:
|
||||||
|
`, toggledlog.ProgramName, toggledlog.ProgramName)
|
||||||
|
|
||||||
flagSet.PrintDefaults()
|
flagSet.PrintDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,17 +118,17 @@ func loadConfig(args *argContainer) (masterkey []byte, confFile *configfile.Conf
|
||||||
// Check if the file exists at all before prompting for a password
|
// Check if the file exists at all before prompting for a password
|
||||||
_, err := os.Stat(args.config)
|
_, err := os.Stat(args.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(colorRed+"Config file not found: %v\n"+colorReset, err)
|
toggledlog.Fatal.Printf(colorRed+"Config file not found: %v\n"+colorReset, err)
|
||||||
os.Exit(ERREXIT_LOADCONF)
|
os.Exit(ERREXIT_LOADCONF)
|
||||||
}
|
}
|
||||||
if args.extpass == "" {
|
if args.extpass == "" {
|
||||||
fmt.Printf("Password: ")
|
fmt.Fprintf(os.Stderr, "Password: ")
|
||||||
}
|
}
|
||||||
pw := readPassword(args.extpass)
|
pw := readPassword(args.extpass)
|
||||||
toggledlog.Info.Printf("Decrypting master key... ")
|
toggledlog.Info.Printf("Decrypting master key... ")
|
||||||
masterkey, confFile, err = configfile.LoadConfFile(args.config, pw)
|
masterkey, confFile, err = configfile.LoadConfFile(args.config, pw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(os.Stderr, colorRed+err.Error()+colorReset)
|
toggledlog.Fatal.Println(colorRed + err.Error() + colorReset)
|
||||||
os.Exit(ERREXIT_LOADCONF)
|
os.Exit(ERREXIT_LOADCONF)
|
||||||
}
|
}
|
||||||
toggledlog.Info.Printf("done.")
|
toggledlog.Info.Printf("done.")
|
||||||
|
@ -136,12 +139,12 @@ func loadConfig(args *argContainer) (masterkey []byte, confFile *configfile.Conf
|
||||||
// changePassword - change the password of config file "filename"
|
// changePassword - change the password of config file "filename"
|
||||||
func changePassword(args *argContainer) {
|
func changePassword(args *argContainer) {
|
||||||
masterkey, confFile := loadConfig(args)
|
masterkey, confFile := loadConfig(args)
|
||||||
fmt.Println("Please enter your new password.")
|
toggledlog.Info.Println("Please enter your new password.")
|
||||||
newPw := readPasswordTwice(args.extpass)
|
newPw := readPasswordTwice(args.extpass)
|
||||||
confFile.EncryptKey(masterkey, newPw, confFile.ScryptObject.LogN())
|
confFile.EncryptKey(masterkey, newPw, confFile.ScryptObject.LogN())
|
||||||
err := confFile.WriteFile()
|
err := confFile.WriteFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
toggledlog.Fatal.Println(err)
|
||||||
os.Exit(ERREXIT_INIT)
|
os.Exit(ERREXIT_INIT)
|
||||||
}
|
}
|
||||||
toggledlog.Info.Printf("Password changed.")
|
toggledlog.Info.Printf("Password changed.")
|
||||||
|
@ -203,7 +206,7 @@ func main() {
|
||||||
} else {
|
} else {
|
||||||
args.openssl, err = strconv.ParseBool(opensslAuto)
|
args.openssl, err = strconv.ParseBool(opensslAuto)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(colorRed+"Invalid \"-openssl\" setting: %v\n"+colorReset, err)
|
toggledlog.Fatal.Printf(colorRed+"Invalid \"-openssl\" setting: %v\n"+colorReset, err)
|
||||||
os.Exit(ERREXIT_USAGE)
|
os.Exit(ERREXIT_USAGE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,7 +233,7 @@ func main() {
|
||||||
args.cipherdir, _ = filepath.Abs(flagSet.Arg(0))
|
args.cipherdir, _ = filepath.Abs(flagSet.Arg(0))
|
||||||
err := checkDir(args.cipherdir)
|
err := checkDir(args.cipherdir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(colorRed+"Invalid cipherdir: %v\n"+colorReset, err)
|
toggledlog.Fatal.Printf(colorRed+"Invalid cipherdir: %v\n"+colorReset, err)
|
||||||
os.Exit(ERREXIT_CIPHERDIR)
|
os.Exit(ERREXIT_CIPHERDIR)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -245,7 +248,8 @@ func main() {
|
||||||
if args.config != "" {
|
if args.config != "" {
|
||||||
args.config, err = filepath.Abs(args.config)
|
args.config, err = filepath.Abs(args.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(colorRed+"Invalid \"-config\" setting: %v\n"+colorReset, err)
|
toggledlog.Fatal.Printf(colorRed+"Invalid \"-config\" setting: %v\n"+colorReset, err)
|
||||||
|
os.Exit(ERREXIT_INIT)
|
||||||
}
|
}
|
||||||
toggledlog.Info.Printf("Using config file at custom location %s", args.config)
|
toggledlog.Info.Printf("Using config file at custom location %s", args.config)
|
||||||
} else {
|
} else {
|
||||||
|
@ -257,7 +261,7 @@ func main() {
|
||||||
var f *os.File
|
var f *os.File
|
||||||
f, err = os.Create(args.cpuprofile)
|
f, err = os.Create(args.cpuprofile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
toggledlog.Fatal.Println(err)
|
||||||
os.Exit(ERREXIT_INIT)
|
os.Exit(ERREXIT_INIT)
|
||||||
}
|
}
|
||||||
pprof.StartCPUProfile(f)
|
pprof.StartCPUProfile(f)
|
||||||
|
@ -269,7 +273,7 @@ func main() {
|
||||||
var f *os.File
|
var f *os.File
|
||||||
f, err = os.Create(args.memprofile)
|
f, err = os.Create(args.memprofile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
toggledlog.Fatal.Println(err)
|
||||||
os.Exit(ERREXIT_INIT)
|
os.Exit(ERREXIT_INIT)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -279,7 +283,7 @@ func main() {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
if args.cpuprofile != "" || args.memprofile != "" {
|
if args.cpuprofile != "" || args.memprofile != "" {
|
||||||
fmt.Printf("Note: You must unmount gracefully, otherwise the profile file(s) will stay empty!\n")
|
toggledlog.Info.Printf("Note: You must unmount gracefully, otherwise the profile file(s) will stay empty!\n")
|
||||||
}
|
}
|
||||||
// "-openssl"
|
// "-openssl"
|
||||||
if args.openssl == false {
|
if args.openssl == false {
|
||||||
|
@ -291,7 +295,7 @@ func main() {
|
||||||
// "-init"
|
// "-init"
|
||||||
if args.init {
|
if args.init {
|
||||||
if flagSet.NArg() > 1 {
|
if flagSet.NArg() > 1 {
|
||||||
fmt.Printf("Usage: %s -init [OPTIONS] CIPHERDIR\n", toggledlog.ProgramName)
|
toggledlog.Fatal.Printf("Usage: %s -init [OPTIONS] CIPHERDIR\n", toggledlog.ProgramName)
|
||||||
os.Exit(ERREXIT_USAGE)
|
os.Exit(ERREXIT_USAGE)
|
||||||
}
|
}
|
||||||
initDir(&args) // does not return
|
initDir(&args) // does not return
|
||||||
|
@ -299,7 +303,7 @@ func main() {
|
||||||
// "-passwd"
|
// "-passwd"
|
||||||
if args.passwd {
|
if args.passwd {
|
||||||
if flagSet.NArg() > 1 {
|
if flagSet.NArg() > 1 {
|
||||||
fmt.Printf("Usage: %s -passwd [OPTIONS] CIPHERDIR\n", toggledlog.ProgramName)
|
toggledlog.Fatal.Printf("Usage: %s -passwd [OPTIONS] CIPHERDIR\n", toggledlog.ProgramName)
|
||||||
os.Exit(ERREXIT_USAGE)
|
os.Exit(ERREXIT_USAGE)
|
||||||
}
|
}
|
||||||
changePassword(&args) // does not return
|
changePassword(&args) // does not return
|
||||||
|
@ -307,17 +311,17 @@ func main() {
|
||||||
// Mount
|
// Mount
|
||||||
// Check mountpoint
|
// Check mountpoint
|
||||||
if flagSet.NArg() != 2 {
|
if flagSet.NArg() != 2 {
|
||||||
usageText()
|
toggledlog.Fatal.Printf("Usage: %s [OPTIONS] CIPHERDIR MOUNTPOINT\n", toggledlog.ProgramName)
|
||||||
os.Exit(ERREXIT_USAGE)
|
os.Exit(ERREXIT_USAGE)
|
||||||
}
|
}
|
||||||
args.mountpoint, err = filepath.Abs(flagSet.Arg(1))
|
args.mountpoint, err = filepath.Abs(flagSet.Arg(1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(colorRed+"Invalid mountpoint: %v\n"+colorReset, err)
|
toggledlog.Fatal.Printf(colorRed+"Invalid mountpoint: %v\n"+colorReset, err)
|
||||||
os.Exit(ERREXIT_MOUNTPOINT)
|
os.Exit(ERREXIT_MOUNTPOINT)
|
||||||
}
|
}
|
||||||
err = checkDirEmpty(args.mountpoint)
|
err = checkDirEmpty(args.mountpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(colorRed+"Invalid mountpoint: %v\n"+colorReset, err)
|
toggledlog.Fatal.Printf(colorRed+"Invalid mountpoint: %v\n"+colorReset, err)
|
||||||
os.Exit(ERREXIT_MOUNTPOINT)
|
os.Exit(ERREXIT_MOUNTPOINT)
|
||||||
}
|
}
|
||||||
// Get master key
|
// Get master key
|
||||||
|
@ -424,7 +428,7 @@ func initFuseFrontend(key []byte, args argContainer, confFile *configfile.ConfFi
|
||||||
|
|
||||||
srv, err := fuse.NewServer(conn.RawFS(), args.mountpoint, &mOpts)
|
srv, err := fuse.NewServer(conn.RawFS(), args.mountpoint, &mOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Mount failed: %v", err)
|
toggledlog.Fatal.Printf("Mount failed: %v", err)
|
||||||
os.Exit(ERREXIT_MOUNT)
|
os.Exit(ERREXIT_MOUNT)
|
||||||
}
|
}
|
||||||
srv.SetDebug(args.fusedebug)
|
srv.SetDebug(args.fusedebug)
|
||||||
|
@ -445,7 +449,7 @@ func handleSigint(srv *fuse.Server, mountpoint string) {
|
||||||
<-ch
|
<-ch
|
||||||
err := srv.Unmount()
|
err := srv.Unmount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Print(err)
|
toggledlog.Warn.Print(err)
|
||||||
toggledlog.Info.Printf("Trying lazy unmount")
|
toggledlog.Info.Printf("Trying lazy unmount")
|
||||||
cmd := exec.Command("fusermount", "-u", "-z", mountpoint)
|
cmd := exec.Command("fusermount", "-u", "-z", mountpoint)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
|
|
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -45,11 +44,11 @@ func parseMasterKey(masterkey string) []byte {
|
||||||
masterkey = strings.Replace(masterkey, "-", "", -1)
|
masterkey = strings.Replace(masterkey, "-", "", -1)
|
||||||
key, err := hex.DecodeString(masterkey)
|
key, err := hex.DecodeString(masterkey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Could not parse master key: %v\n", err)
|
toggledlog.Fatal.Printf("Could not parse master key: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if len(key) != cryptocore.KeyLen {
|
if len(key) != cryptocore.KeyLen {
|
||||||
fmt.Printf("Master key has length %d but we require length %d\n", len(key), cryptocore.KeyLen)
|
toggledlog.Fatal.Printf("Master key has length %d but we require length %d\n", len(key), cryptocore.KeyLen)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return key
|
return key
|
||||||
|
|
16
password.go
16
password.go
|
@ -7,16 +7,18 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
|
|
||||||
|
"github.com/rfjakob/gocryptfs/internal/toggledlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func readPasswordTwice(extpass string) string {
|
func readPasswordTwice(extpass string) string {
|
||||||
if extpass == "" {
|
if extpass == "" {
|
||||||
fmt.Printf("Password: ")
|
fmt.Fprintf(os.Stderr, "Password: ")
|
||||||
p1 := readPassword("")
|
p1 := readPassword("")
|
||||||
fmt.Printf("Repeat: ")
|
fmt.Fprintf(os.Stderr, "Repeat: ")
|
||||||
p2 := readPassword("")
|
p2 := readPassword("")
|
||||||
if p1 != p2 {
|
if p1 != p2 {
|
||||||
fmt.Println(colorRed + "Passwords do not match" + colorReset)
|
toggledlog.Fatal.Println(colorRed + "Passwords do not match" + colorReset)
|
||||||
os.Exit(ERREXIT_PASSWORD)
|
os.Exit(ERREXIT_PASSWORD)
|
||||||
}
|
}
|
||||||
return p1
|
return p1
|
||||||
|
@ -37,7 +39,7 @@ func readPassword(extpass string) string {
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
output, err = cmd.Output()
|
output, err = cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(colorRed+"extpass program returned error: %v\n"+colorReset, err)
|
toggledlog.Fatal.Printf(colorRed+"extpass program returned error: %v\n"+colorReset, err)
|
||||||
os.Exit(ERREXIT_PASSWORD)
|
os.Exit(ERREXIT_PASSWORD)
|
||||||
}
|
}
|
||||||
// Trim trailing newline like terminal.ReadPassword() does
|
// Trim trailing newline like terminal.ReadPassword() does
|
||||||
|
@ -48,14 +50,14 @@ func readPassword(extpass string) string {
|
||||||
fd := int(os.Stdin.Fd())
|
fd := int(os.Stdin.Fd())
|
||||||
output, err = terminal.ReadPassword(fd)
|
output, err = terminal.ReadPassword(fd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(colorRed+"Could not read password from terminal: %v\n"+colorReset, err)
|
toggledlog.Fatal.Printf(colorRed+"Could not read password from terminal: %v\n"+colorReset, err)
|
||||||
os.Exit(ERREXIT_PASSWORD)
|
os.Exit(ERREXIT_PASSWORD)
|
||||||
}
|
}
|
||||||
fmt.Printf("\n")
|
fmt.Fprintf(os.Stderr, "\n")
|
||||||
}
|
}
|
||||||
password = string(output)
|
password = string(output)
|
||||||
if password == "" {
|
if password == "" {
|
||||||
fmt.Printf(colorRed + "Password is empty\n" + colorReset)
|
toggledlog.Fatal.Printf(colorRed + "Password is empty\n" + colorReset)
|
||||||
os.Exit(ERREXIT_PASSWORD)
|
os.Exit(ERREXIT_PASSWORD)
|
||||||
}
|
}
|
||||||
return password
|
return password
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/rfjakob/gocryptfs/internal/toggledlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Send signal USR1 to "pid" (usually our parent process). This notifies it
|
// Send signal USR1 to "pid" (usually our parent process). This notifies it
|
||||||
|
@ -11,11 +12,11 @@ import (
|
||||||
func sendUsr1(pid int) {
|
func sendUsr1(pid int) {
|
||||||
p, err := os.FindProcess(pid)
|
p, err := os.FindProcess(pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("sendUsr1: FindProcess: %v\n", err)
|
toggledlog.Warn.Printf("sendUsr1: FindProcess: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = p.Signal(syscall.SIGUSR1)
|
err = p.Signal(syscall.SIGUSR1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("sendUsr1: Signal: %v\n", err)
|
toggledlog.Warn.Printf("sendUsr1: Signal: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue