Add "-q" (quiet) flag

This commit is contained in:
Jakob Unterwurzacher 2015-11-09 22:33:42 +01:00
parent 79b36dd8eb
commit 99dfc84992
4 changed files with 26 additions and 19 deletions

View File

@ -1,5 +1,4 @@
* More robust daemonization, add cli parameter "--sendusr1=pid" * More robust daemonization, add cli parameter "--sendusr1=pid"
* Add "-q" (quiet) flag
* Add test filesystem for "--masterkey" containing an "It works!" file * Add test filesystem for "--masterkey" containing an "It works!" file
* Add fcntl file locking to make multiple concurrent mounts safe * Add fcntl file locking to make multiple concurrent mounts safe
* add test case * add test case

View File

@ -43,6 +43,11 @@ func (l *logChannel) Md5sum(buf []byte) string {
return md5sum(buf) return md5sum(buf)
} }
// As defined by http://elinux.org/Debugging_by_printing#Log_Levels
// Debug messages
var Debug = logChannel{false} var Debug = logChannel{false}
var Notice = logChannel{true} // Informational message e.g. startup information
var Info = logChannel{true}
// A warning, meaning nothing serious by itself but might indicate problems
var Warn = logChannel{true} var Warn = logChannel{true}

35
main.go
View File

@ -46,14 +46,14 @@ func initDir(dirArg string, plaintextNames bool) {
} }
confName := filepath.Join(dir, cryptfs.ConfDefaultName) confName := filepath.Join(dir, cryptfs.ConfDefaultName)
fmt.Printf("Choose a password for protecting your files.\n") cryptfs.Info.Printf("Choose a password for protecting your files.\n")
password := readPasswordTwice() password := readPasswordTwice()
err = cryptfs.CreateConfFile(confName, password, plaintextNames) err = cryptfs.CreateConfFile(confName, password, plaintextNames)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(ERREXIT_INIT) os.Exit(ERREXIT_INIT)
} }
fmt.Printf("The filesystem is now ready for mounting.\n") cryptfs.Info.Printf("The filesystem is now ready for mounting.\n")
os.Exit(0) os.Exit(0)
} }
@ -69,7 +69,7 @@ func main() {
// Parse command line arguments // Parse command line arguments
var args struct { var args struct {
debug, init, zerokey, fusedebug, openssl, passwd, foreground, version, debug, init, zerokey, fusedebug, openssl, passwd, foreground, version,
plaintextnames bool plaintextnames, quiet bool
masterkey, mountpoint, cipherdir string masterkey, mountpoint, cipherdir string
cpuprofile *string cpuprofile *string
} }
@ -85,15 +85,18 @@ func main() {
flag.BoolVar(&args.version, "version", false, "Print version and exit") flag.BoolVar(&args.version, "version", false, "Print version and exit")
flag.BoolVar(&args.plaintextnames, "plaintextnames", false, flag.BoolVar(&args.plaintextnames, "plaintextnames", false,
"Do not encrypt file names - can only be used together with -init") "Do not encrypt file names - can only be used together with -init")
flag.BoolVar(&args.quiet, "q", false, "Quiet - silence informational messages")
flag.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key") flag.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key")
args.cpuprofile = flag.String("cpuprofile", "", "Write cpu profile to specified file") args.cpuprofile = flag.String("cpuprofile", "", "Write cpu profile to specified file")
flag.Parse() flag.Parse()
if args.version { if args.version {
fmt.Printf("%s %s; ", PROGRAM_NAME, GitVersion) fmt.Printf("%s %s; on-disk format %d\n", PROGRAM_NAME, GitVersion, cryptfs.HEADER_CURRENT_VERSION)
fmt.Printf("on-disk format %d\n", cryptfs.HEADER_CURRENT_VERSION)
os.Exit(0) os.Exit(0)
} }
if args.quiet {
cryptfs.Info.Disable()
}
if !args.foreground { if !args.foreground {
daemonize() // does not return daemonize() // does not return
} }
@ -103,7 +106,7 @@ func main() {
fmt.Println(err) fmt.Println(err)
os.Exit(ERREXIT_INIT) os.Exit(ERREXIT_INIT)
} }
fmt.Printf("Writing CPU profile to %s\n", *args.cpuprofile) cryptfs.Info.Printf("Writing CPU profile to %s\n", *args.cpuprofile)
pprof.StartCPUProfile(f) pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile() defer pprof.StopCPUProfile()
} }
@ -112,7 +115,7 @@ func main() {
cryptfs.Debug.Printf("Debug output enabled\n") cryptfs.Debug.Printf("Debug output enabled\n")
} }
if args.openssl == false { if args.openssl == false {
fmt.Printf("Openssl disabled\n") cryptfs.Info.Printf("Openssl disabled\n")
} }
if args.init { if args.init {
if flag.NArg() != 1 && args.plaintextnames == false { if flag.NArg() != 1 && args.plaintextnames == false {
@ -151,11 +154,11 @@ func main() {
var currentPassword string var currentPassword string
key := make([]byte, cryptfs.KEY_LEN) key := make([]byte, cryptfs.KEY_LEN)
if args.zerokey { if args.zerokey {
fmt.Printf("Zerokey mode active: using all-zero dummy master key.\n") cryptfs.Info.Printf("Zerokey mode active: using all-zero dummy master key.\n")
plaintextNames = args.plaintextnames plaintextNames = args.plaintextnames
} else if len(args.masterkey) > 0 { } else if len(args.masterkey) > 0 {
key = parseMasterKey(args.masterkey) key = parseMasterKey(args.masterkey)
fmt.Printf("Using explicit master key.\n") cryptfs.Info.Printf("Using explicit master key.\n")
} else { } else {
// Load config file // Load config file
cfname := filepath.Join(args.cipherdir, cryptfs.ConfDefaultName) cfname := filepath.Join(args.cipherdir, cryptfs.ConfDefaultName)
@ -171,7 +174,7 @@ func main() {
fmt.Printf("Password: ") fmt.Printf("Password: ")
} }
currentPassword = readPassword() currentPassword = readPassword()
fmt.Printf("\nDecrypting master key... ") cryptfs.Info.Printf("\nDecrypting master key... ")
cryptfs.Warn.Disable() // Silence DecryptBlock() error messages on incorrect password cryptfs.Warn.Disable() // Silence DecryptBlock() error messages on incorrect password
key, cf, err = cryptfs.LoadConfFile(cfname, currentPassword) key, cf, err = cryptfs.LoadConfFile(cfname, currentPassword)
cryptfs.Warn.Enable() cryptfs.Warn.Enable()
@ -179,7 +182,7 @@ func main() {
fmt.Println(err) fmt.Println(err)
os.Exit(ERREXIT_LOADCONF) os.Exit(ERREXIT_LOADCONF)
} }
fmt.Printf("done.\n") cryptfs.Info.Printf("done.\n")
} }
if args.passwd == true { if args.passwd == true {
fmt.Printf("Please enter the new password.\n") fmt.Printf("Please enter the new password.\n")
@ -194,7 +197,7 @@ func main() {
fmt.Println(err) fmt.Println(err)
os.Exit(ERREXIT_INIT) os.Exit(ERREXIT_INIT)
} }
fmt.Printf("Password changed.\n") cryptfs.Info.Printf("Password changed.\n")
os.Exit(0) os.Exit(0)
} }
@ -206,12 +209,12 @@ func main() {
if args.zerokey == false && len(args.masterkey) == 0 { if args.zerokey == false && len(args.masterkey) == 0 {
printMasterKey(key) printMasterKey(key)
} else if args.zerokey == true { } else if args.zerokey == true {
fmt.Printf("ZEROKEY MODE PROVIDES NO SECURITY AT ALL AND SHOULD ONLY BE USED FOR TESTING.\n") cryptfs.Info.Printf("ZEROKEY MODE PROVIDES NO SECURITY AT ALL AND SHOULD ONLY BE USED FOR TESTING.\n")
} else if len(args.masterkey) > 0 { } else if len(args.masterkey) > 0 {
fmt.Printf("THE MASTER KEY IS VISIBLE VIA \"ps -auxwww\", ONLY USE THIS MODE FOR EMERGENCIES.\n") cryptfs.Info.Printf("THE MASTER KEY IS VISIBLE VIA \"ps -auxwww\", ONLY USE THIS MODE FOR EMERGENCIES.\n")
} }
fmt.Println("Filesystem ready.") cryptfs.Info.Println("Filesystem ready.")
// Send notification to our parent // Send notification to our parent
sendUsr1() sendUsr1()
// Wait for SIGING in the background and unmount ourselves if we get it // Wait for SIGING in the background and unmount ourselves if we get it
@ -263,7 +266,7 @@ func handleSigint(srv *fuse.Server, mountpoint string) {
err := srv.Unmount() err := srv.Unmount()
if err != nil { if err != nil {
fmt.Print(err) fmt.Print(err)
fmt.Printf("Trying lazy unmount\n") cryptfs.Info.Printf("Trying lazy unmount\n")
cmd := exec.Command("fusermount", "-u", "-z", mountpoint) cmd := exec.Command("fusermount", "-u", "-z", mountpoint)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr

View File

@ -174,7 +174,7 @@ func (fs *FS) Unlink(name string, context *fuse.Context) (code fuse.Status) {
cName := fs.EncryptPath(name) cName := fs.EncryptPath(name)
code = fs.FileSystem.Unlink(cName, context) code = fs.FileSystem.Unlink(cName, context)
if code != fuse.OK { if code != fuse.OK {
cryptfs.Notice.Printf("Unlink failed on %s [%s], code=%s\n", name, cName, code.String()) cryptfs.Warn.Printf("Unlink failed on %s [%s], code=%s\n", name, cName, code.String())
} }
return code return code
} }