main: doMount: use a deferred function for wipeKeys
Also drop the unused int return.
This commit is contained in:
parent
5b5c7a0a5d
commit
14c063428d
8
main.go
8
main.go
@ -267,10 +267,6 @@ func main() {
|
|||||||
tlog.Fatal.Printf("Usage: %s [OPTIONS] CIPHERDIR MOUNTPOINT [-o COMMA-SEPARATED-OPTIONS]", tlog.ProgramName)
|
tlog.Fatal.Printf("Usage: %s [OPTIONS] CIPHERDIR MOUNTPOINT [-o COMMA-SEPARATED-OPTIONS]", tlog.ProgramName)
|
||||||
os.Exit(exitcodes.Usage)
|
os.Exit(exitcodes.Usage)
|
||||||
}
|
}
|
||||||
ret := doMount(&args)
|
doMount(&args)
|
||||||
if ret != 0 {
|
// Don't call os.Exit to give deferred functions a chance to run
|
||||||
os.Exit(ret)
|
|
||||||
}
|
|
||||||
// Don't call os.Exit on success to give deferred functions a chance to
|
|
||||||
// run
|
|
||||||
}
|
}
|
||||||
|
9
mount.go
9
mount.go
@ -35,7 +35,7 @@ import (
|
|||||||
|
|
||||||
// doMount mounts an encrypted directory.
|
// doMount mounts an encrypted directory.
|
||||||
// Called from main.
|
// Called from main.
|
||||||
func doMount(args *argContainer) int {
|
func doMount(args *argContainer) {
|
||||||
// Check mountpoint
|
// Check mountpoint
|
||||||
var err error
|
var err error
|
||||||
args.mountpoint, err = filepath.Abs(flagSet.Arg(1))
|
args.mountpoint, err = filepath.Abs(flagSet.Arg(1))
|
||||||
@ -95,7 +95,6 @@ func doMount(args *argContainer) int {
|
|||||||
}
|
}
|
||||||
var confFile *configfile.ConfFile
|
var confFile *configfile.ConfFile
|
||||||
var srv *fuse.Server
|
var srv *fuse.Server
|
||||||
var wipeKeys func()
|
|
||||||
{
|
{
|
||||||
// Get master key (may prompt for the password)
|
// Get master key (may prompt for the password)
|
||||||
var masterkey []byte
|
var masterkey []byte
|
||||||
@ -126,7 +125,10 @@ func doMount(args *argContainer) int {
|
|||||||
// We cannot use JSON for pretty-printing as the fields are unexported
|
// We cannot use JSON for pretty-printing as the fields are unexported
|
||||||
tlog.Debug.Printf("cli args: %#v", args)
|
tlog.Debug.Printf("cli args: %#v", args)
|
||||||
// Initialize FUSE server
|
// Initialize FUSE server
|
||||||
|
var wipeKeys func()
|
||||||
srv, wipeKeys = initFuseFrontend(masterkey, args, confFile)
|
srv, wipeKeys = initFuseFrontend(masterkey, args, confFile)
|
||||||
|
// Try to wipe secrect keys from memory after unmount
|
||||||
|
defer wipeKeys()
|
||||||
// fusefrontend / fusefrontend_reverse have initialized their crypto,
|
// fusefrontend / fusefrontend_reverse have initialized their crypto,
|
||||||
// we can purge the master key from memory.
|
// we can purge the master key from memory.
|
||||||
for i := range masterkey {
|
for i := range masterkey {
|
||||||
@ -172,9 +174,6 @@ func doMount(args *argContainer) int {
|
|||||||
debug.FreeOSMemory()
|
debug.FreeOSMemory()
|
||||||
// Jump into server loop. Returns when it gets an umount request from the kernel.
|
// Jump into server loop. Returns when it gets an umount request from the kernel.
|
||||||
srv.Serve()
|
srv.Serve()
|
||||||
// Try to wipe secrect keys from memory
|
|
||||||
wipeKeys()
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setOpenFileLimit tries to increase the open file limit to 4096 (the default hard
|
// setOpenFileLimit tries to increase the open file limit to 4096 (the default hard
|
||||||
|
Loading…
Reference in New Issue
Block a user