exitcodes: define code 12 for "password incorrect"
This commit is contained in:
parent
57612a278b
commit
427c6c1719
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/rfjakob/gocryptfs/internal/contentenc"
|
"github.com/rfjakob/gocryptfs/internal/contentenc"
|
||||||
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
||||||
|
"github.com/rfjakob/gocryptfs/internal/exitcodes"
|
||||||
"github.com/rfjakob/gocryptfs/internal/tlog"
|
"github.com/rfjakob/gocryptfs/internal/tlog"
|
||||||
)
|
)
|
||||||
import "os"
|
import "os"
|
||||||
|
@ -163,7 +164,7 @@ func LoadConfFile(filename string, password string) ([]byte, *ConfFile, error) {
|
||||||
tlog.Warn.Enabled = true
|
tlog.Warn.Enabled = true
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tlog.Warn.Printf("failed to unlock master key: %s", err.Error())
|
tlog.Warn.Printf("failed to unlock master key: %s", err.Error())
|
||||||
return nil, nil, fmt.Errorf("Password incorrect.")
|
return nil, nil, exitcodes.NewErr("Password incorrect.", exitcodes.PasswordIncorrect)
|
||||||
}
|
}
|
||||||
|
|
||||||
return key, &cf, err
|
return key, &cf, err
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
// Package exitcodes contains all well-defined exit codes that gocryptfs
|
||||||
|
// can return.
|
||||||
|
package exitcodes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Other error - please inspect the message
|
||||||
|
Other = 11
|
||||||
|
// The password was incorrect
|
||||||
|
PasswordIncorrect = 12
|
||||||
|
// TODO several other exit codes are defined in main.go. These will be
|
||||||
|
// ported over here.
|
||||||
|
)
|
||||||
|
|
||||||
|
type Err struct {
|
||||||
|
error
|
||||||
|
code int
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewErr returns an error containing "msg" and the exit code "code".
|
||||||
|
func NewErr(msg string, code int) Err {
|
||||||
|
return Err{
|
||||||
|
error: fmt.Errorf(msg),
|
||||||
|
code: code,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Exit(err error) {
|
||||||
|
err2, ok := err.(Err)
|
||||||
|
if !ok {
|
||||||
|
os.Exit(Other)
|
||||||
|
}
|
||||||
|
os.Exit(err2.code)
|
||||||
|
}
|
3
mount.go
3
mount.go
|
@ -21,6 +21,7 @@ import (
|
||||||
"github.com/rfjakob/gocryptfs/internal/configfile"
|
"github.com/rfjakob/gocryptfs/internal/configfile"
|
||||||
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
"github.com/rfjakob/gocryptfs/internal/cryptocore"
|
||||||
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
"github.com/rfjakob/gocryptfs/internal/ctlsock"
|
||||||
|
"github.com/rfjakob/gocryptfs/internal/exitcodes"
|
||||||
"github.com/rfjakob/gocryptfs/internal/fusefrontend"
|
"github.com/rfjakob/gocryptfs/internal/fusefrontend"
|
||||||
"github.com/rfjakob/gocryptfs/internal/fusefrontend_reverse"
|
"github.com/rfjakob/gocryptfs/internal/fusefrontend_reverse"
|
||||||
"github.com/rfjakob/gocryptfs/internal/readpassword"
|
"github.com/rfjakob/gocryptfs/internal/readpassword"
|
||||||
|
@ -96,7 +97,7 @@ func doMount(args *argContainer) int {
|
||||||
// Close the socket file (which also deletes it)
|
// Close the socket file (which also deletes it)
|
||||||
args._ctlsockFd.Close()
|
args._ctlsockFd.Close()
|
||||||
}
|
}
|
||||||
os.Exit(ErrExitLoadConf)
|
exitcodes.Exit(err)
|
||||||
}
|
}
|
||||||
readpassword.CheckTrailingGarbage()
|
readpassword.CheckTrailingGarbage()
|
||||||
printMasterKey(masterkey)
|
printMasterKey(masterkey)
|
||||||
|
|
Loading…
Reference in New Issue