aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-01-31 18:09:39 +0100
committerJakob Unterwurzacher2016-01-31 18:09:39 +0100
commit6454db68d97667f90ec1f0f838c7da275c46d2b8 (patch)
tree8e7078f815a74c78f0c620723903e1ef1e88d0d3
parent4c9e249e3ac1fc2995e01eb1ed24799c3a3bc66b (diff)
Add new "-wpanic" option and enable it for the automated tests
-rw-r--r--Documentation/MANPAGE.md4
-rw-r--r--cryptfs/log.go16
-rw-r--r--integration_tests/helpers.go2
-rw-r--r--main.go7
-rw-r--r--pathfs_frontend/names.go2
5 files changed, 25 insertions, 6 deletions
diff --git a/Documentation/MANPAGE.md b/Documentation/MANPAGE.md
index 6210190..c47f4b9 100644
--- a/Documentation/MANPAGE.md
+++ b/Documentation/MANPAGE.md
@@ -104,6 +104,10 @@ mounting but makes the password susceptible to brute-force attacks (default 16)
**-version**
: Print version and exit
+**-wpanic**
+: When encountering a warning, panic and exit immediately. This is
+useful in regression testing.
+
**-zerokey**
: Use all-zero dummy master key. This options is only intended for
automated testing as it does not provide any security.
diff --git a/cryptfs/log.go b/cryptfs/log.go
index 44cb84f..19d8b51 100644
--- a/cryptfs/log.go
+++ b/cryptfs/log.go
@@ -2,6 +2,7 @@ package cryptfs
import (
"encoding/json"
+ "fmt"
"log"
"os"
)
@@ -17,7 +18,10 @@ func JSONDump(obj interface{}) string {
// toggledLogger - a Logger than can be enabled and disabled
type toggledLogger struct {
+ // Enable or disable output
Enabled bool
+ // Panic after logging a message, useful in regression tests
+ PanicAfter bool
*log.Logger
}
@@ -26,12 +30,18 @@ func (l *toggledLogger) Printf(format string, v ...interface{}) {
return
}
l.Logger.Printf(format, v...)
+ if l.PanicAfter {
+ panic("PanicAfter: " + fmt.Sprintf(format, v...))
+ }
}
func (l *toggledLogger) Println(v ...interface{}) {
if !l.Enabled {
return
}
l.Logger.Println(v...)
+ if l.PanicAfter {
+ panic("PanicAfter: " + fmt.Sprintln(v...))
+ }
}
// As defined by http://elinux.org/Debugging_by_printing#Log_Levels
@@ -45,7 +55,7 @@ var Info *toggledLogger
var Warn *toggledLogger
func init() {
- Debug = &toggledLogger{false, log.New(os.Stdout, "", 0)}
- Info = &toggledLogger{true, log.New(os.Stdout, "", 0)}
- Warn = &toggledLogger{true, log.New(os.Stderr, "", 0)}
+ Debug = &toggledLogger{false, false, log.New(os.Stdout, "", 0)}
+ Info = &toggledLogger{true, false, log.New(os.Stdout, "", 0)}
+ Warn = &toggledLogger{true, false, log.New(os.Stderr, "", 0)}
}
diff --git a/integration_tests/helpers.go b/integration_tests/helpers.go
index d0e8721..5145b30 100644
--- a/integration_tests/helpers.go
+++ b/integration_tests/helpers.go
@@ -53,7 +53,7 @@ func resetTmpDir() {
func mount(c string, p string, extraArgs ...string) {
var args []string
args = append(args, extraArgs...)
- args = append(args, "-q")
+ args = append(args, "-q", "-wpanic")
//args = append(args, "--fusedebug")
args = append(args, c)
args = append(args, p)
diff --git a/main.go b/main.go
index 09046da..da98481 100644
--- a/main.go
+++ b/main.go
@@ -37,7 +37,7 @@ const (
type argContainer struct {
debug, init, zerokey, fusedebug, openssl, passwd, foreground, version,
- plaintextnames, quiet, diriv, emenames, gcmiv128, nosyslog bool
+ plaintextnames, quiet, diriv, emenames, gcmiv128, nosyslog, wpanic bool
masterkey, mountpoint, cipherdir, cpuprofile, config, extpass,
memprofile string
notifypid, scryptn int
@@ -160,6 +160,7 @@ func main() {
flagSet.BoolVar(&args.emenames, "emenames", true, "Use EME filename encryption. This option implies diriv.")
flagSet.BoolVar(&args.gcmiv128, "gcmiv128", true, "Use an 128-bit IV for GCM encryption instead of Go's default of 96 bits")
flagSet.BoolVar(&args.nosyslog, "nosyslog", false, "Do not redirect output to syslog when running in the background")
+ flagSet.BoolVar(&args.wpanic, "wpanic", false, "When encountering a warning, panic and exit immediately")
flagSet.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key")
flagSet.StringVar(&args.cpuprofile, "cpuprofile", "", "Write cpu profile to specified file")
flagSet.StringVar(&args.memprofile, "memprofile", "", "Write memory profile to specified file")
@@ -184,6 +185,10 @@ func main() {
cryptfs.Debug.Enabled = true
cryptfs.Debug.Printf("Debug output enabled")
}
+ if args.wpanic {
+ cryptfs.Warn.PanicAfter = true
+ cryptfs.Debug.Printf("Panicing on warnings")
+ }
// Every operation below requires CIPHERDIR. Check that we have it.
if flagSet.NArg() >= 1 {
args.cipherdir, _ = filepath.Abs(flagSet.Arg(0))
diff --git a/pathfs_frontend/names.go b/pathfs_frontend/names.go
index 219942e..bd7a249 100644
--- a/pathfs_frontend/names.go
+++ b/pathfs_frontend/names.go
@@ -15,7 +15,7 @@ func (fs *FS) isFiltered(path string) bool {
}
// gocryptfs.conf in the root directory is forbidden
if path == cryptfs.ConfDefaultName {
- cryptfs.Warn.Printf("The name /%s is reserved when -plaintextnames is used\n",
+ cryptfs.Info.Printf("The name /%s is reserved when -plaintextnames is used\n",
cryptfs.ConfDefaultName)
return true
}