aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.md1
-rw-r--r--cryptfs/log.go7
-rw-r--r--main.go35
-rw-r--r--pathfs_frontend/fs.go2
4 files changed, 26 insertions, 19 deletions
diff --git a/TODO.md b/TODO.md
index 308d500..ec64d2e 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,5 +1,4 @@
* More robust daemonization, add cli parameter "--sendusr1=pid"
-* Add "-q" (quiet) flag
* Add test filesystem for "--masterkey" containing an "It works!" file
* Add fcntl file locking to make multiple concurrent mounts safe
* add test case
diff --git a/cryptfs/log.go b/cryptfs/log.go
index 2183679..6173e63 100644
--- a/cryptfs/log.go
+++ b/cryptfs/log.go
@@ -43,6 +43,11 @@ func (l *logChannel) Md5sum(buf []byte) string {
return md5sum(buf)
}
+// As defined by http://elinux.org/Debugging_by_printing#Log_Levels
+
+// Debug messages
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}
diff --git a/main.go b/main.go
index 2adf656..c648aee 100644
--- a/main.go
+++ b/main.go
@@ -46,14 +46,14 @@ func initDir(dirArg string, plaintextNames bool) {
}
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()
err = cryptfs.CreateConfFile(confName, password, plaintextNames)
if err != nil {
fmt.Println(err)
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)
}
@@ -69,7 +69,7 @@ func main() {
// Parse command line arguments
var args struct {
debug, init, zerokey, fusedebug, openssl, passwd, foreground, version,
- plaintextnames bool
+ plaintextnames, quiet bool
masterkey, mountpoint, cipherdir string
cpuprofile *string
}
@@ -85,15 +85,18 @@ func main() {
flag.BoolVar(&args.version, "version", false, "Print version and exit")
flag.BoolVar(&args.plaintextnames, "plaintextnames", false,
"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")
args.cpuprofile = flag.String("cpuprofile", "", "Write cpu profile to specified file")
flag.Parse()
if args.version {
- fmt.Printf("%s %s; ", PROGRAM_NAME, GitVersion)
- fmt.Printf("on-disk format %d\n", cryptfs.HEADER_CURRENT_VERSION)
+ fmt.Printf("%s %s; on-disk format %d\n", PROGRAM_NAME, GitVersion, cryptfs.HEADER_CURRENT_VERSION)
os.Exit(0)
}
+ if args.quiet {
+ cryptfs.Info.Disable()
+ }
if !args.foreground {
daemonize() // does not return
}
@@ -103,7 +106,7 @@ func main() {
fmt.Println(err)
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)
defer pprof.StopCPUProfile()
}
@@ -112,7 +115,7 @@ func main() {
cryptfs.Debug.Printf("Debug output enabled\n")
}
if args.openssl == false {
- fmt.Printf("Openssl disabled\n")
+ cryptfs.Info.Printf("Openssl disabled\n")
}
if args.init {
if flag.NArg() != 1 && args.plaintextnames == false {
@@ -151,11 +154,11 @@ func main() {
var currentPassword string
key := make([]byte, cryptfs.KEY_LEN)
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
} else if len(args.masterkey) > 0 {
key = parseMasterKey(args.masterkey)
- fmt.Printf("Using explicit master key.\n")
+ cryptfs.Info.Printf("Using explicit master key.\n")
} else {
// Load config file
cfname := filepath.Join(args.cipherdir, cryptfs.ConfDefaultName)
@@ -171,7 +174,7 @@ func main() {
fmt.Printf("Password: ")
}
currentPassword = readPassword()
- fmt.Printf("\nDecrypting master key... ")
+ cryptfs.Info.Printf("\nDecrypting master key... ")
cryptfs.Warn.Disable() // Silence DecryptBlock() error messages on incorrect password
key, cf, err = cryptfs.LoadConfFile(cfname, currentPassword)
cryptfs.Warn.Enable()
@@ -179,7 +182,7 @@ func main() {
fmt.Println(err)
os.Exit(ERREXIT_LOADCONF)
}
- fmt.Printf("done.\n")
+ cryptfs.Info.Printf("done.\n")
}
if args.passwd == true {
fmt.Printf("Please enter the new password.\n")
@@ -194,7 +197,7 @@ func main() {
fmt.Println(err)
os.Exit(ERREXIT_INIT)
}
- fmt.Printf("Password changed.\n")
+ cryptfs.Info.Printf("Password changed.\n")
os.Exit(0)
}
@@ -206,12 +209,12 @@ func main() {
if args.zerokey == false && len(args.masterkey) == 0 {
printMasterKey(key)
} 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 {
- 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
sendUsr1()
// 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()
if err != nil {
fmt.Print(err)
- fmt.Printf("Trying lazy unmount\n")
+ cryptfs.Info.Printf("Trying lazy unmount\n")
cmd := exec.Command("fusermount", "-u", "-z", mountpoint)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
diff --git a/pathfs_frontend/fs.go b/pathfs_frontend/fs.go
index bd97f9a..9f5b1d6 100644
--- a/pathfs_frontend/fs.go
+++ b/pathfs_frontend/fs.go
@@ -174,7 +174,7 @@ func (fs *FS) Unlink(name string, context *fuse.Context) (code fuse.Status) {
cName := fs.EncryptPath(name)
code = fs.FileSystem.Unlink(cName, context)
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
}