diff options
-rw-r--r-- | internal/configfile/config_file.go | 6 | ||||
-rw-r--r-- | main.go | 19 | ||||
-rw-r--r-- | mount.go | 9 |
3 files changed, 24 insertions, 10 deletions
diff --git a/internal/configfile/config_file.go b/internal/configfile/config_file.go index 0bee16f..c4865d7 100644 --- a/internal/configfile/config_file.go +++ b/internal/configfile/config_file.go @@ -83,9 +83,11 @@ func CreateConfFile(filename string, password string, plaintextNames bool, logN } // LoadConfFile - read config file from disk and decrypt the -// contained key using password. -// +// contained key using "password". // Returns the decrypted key and the ConfFile object +// +// If "password" is empty, the config file is read +// but the key is not decrypted (returns nil in its place). func LoadConfFile(filename string, password string) ([]byte, *ConfFile, error) { var cf ConfFile cf.filename = filename @@ -51,14 +51,16 @@ Options: } // loadConfig loads the config file "args.config", prompting the user for the password -func loadConfig(args *argContainer) (masterkey []byte, confFile *configfile.ConfFile) { +func loadConfig(args *argContainer) (masterkey []byte, confFile *configfile.ConfFile, err error) { // Check if the file can be opened at all before prompting for a password fd, err := os.Open(args.config) if err != nil { tlog.Fatal.Printf("Cannot open config file: %v", err) - os.Exit(ErrExitLoadConf) + return nil, nil, err } fd.Close() + // The user has passed the master key (probably because he forgot the + // password). if args.masterkey != "" { masterkey = parseMasterKey(args.masterkey) _, confFile, err = configfile.LoadConfFile(args.config, "") @@ -69,20 +71,23 @@ func loadConfig(args *argContainer) (masterkey []byte, confFile *configfile.Conf } if err != nil { tlog.Fatal.Println(err) - os.Exit(ErrExitLoadConf) + return nil, nil, err } - return masterkey, confFile + return masterkey, confFile, nil } // changePassword - change the password of config file "filename" func changePassword(args *argContainer) { - masterkey, confFile := loadConfig(args) + masterkey, confFile, err := loadConfig(args) + if err != nil { + os.Exit(ErrExitLoadConf) + } tlog.Info.Println("Please enter your new password.") newPw := readpassword.Twice(args.extpass) confFile.EncryptKey(masterkey, newPw, confFile.ScryptObject.LogN()) if args.masterkey != "" { bak := args.config + ".bak" - err := os.Link(args.config, bak) + err = os.Link(args.config, bak) if err != nil { tlog.Fatal.Printf("Could not create backup file: %v", err) os.Exit(ErrExitInit) @@ -92,7 +97,7 @@ func changePassword(args *argContainer) { "Delete it after you have verified that you can access your files with the new password."+ tlog.ColorReset, bak) } - err := confFile.WriteFile() + err = confFile.WriteFile() if err != nil { tlog.Fatal.Println(err) os.Exit(ErrExitInit) @@ -88,7 +88,14 @@ func doMount(args *argContainer) int { } else { // Load master key from config file // Prompts the user for the password - masterkey, confFile = loadConfig(args) + masterkey, confFile, err = loadConfig(args) + if err != nil { + if args._ctlsockFd != nil { + // Close the socket file (which also deletes it) + args._ctlsockFd.Close() + } + os.Exit(ErrExitLoadConf) + } printMasterKey(masterkey) } // We cannot use JSON for pretty-printing as the fields are unexported |