aboutsummaryrefslogtreecommitdiff
path: root/cli_args.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2019-05-13 23:01:44 +0200
committerJakob Unterwurzacher2019-05-13 23:01:44 +0200
commit991adfc934d714897e3c0ad39d37fca3edf59bcb (patch)
tree6c63f27a46ea35d6244d3b5cd125e883bff05d5a /cli_args.go
parent2cb0e8a1aeb42920f965956995d99cd2c8dbaa67 (diff)
-passwd now takes a passed -scryptn flag into account
https://github.com/rfjakob/gocryptfs/issues/400
Diffstat (limited to 'cli_args.go')
-rw-r--r--cli_args.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/cli_args.go b/cli_args.go
index f1cefb4..cae7723 100644
--- a/cli_args.go
+++ b/cli_args.go
@@ -50,6 +50,8 @@ type argContainer struct {
_ctlsockFd net.Listener
// _forceOwner is, if non-nil, a parsed, validated Owner (as opposed to the string above)
_forceOwner *fuse.Owner
+ // _explicitScryptn is true then the user passed "-scryptn=xyz"
+ _explicitScryptn bool
}
type multipleStrings []string
@@ -205,7 +207,8 @@ func parseCliOpts() (args argContainer) {
flagSet.IntVar(&args.notifypid, "notifypid", 0, "Send USR1 to the specified process after "+
"successful mount - used internally for daemonization")
- flagSet.IntVar(&args.scryptn, "scryptn", configfile.ScryptDefaultLogN, "scrypt cost parameter logN. Possible values: 10-28. "+
+ const scryptn = "scryptn"
+ flagSet.IntVar(&args.scryptn, scryptn, configfile.ScryptDefaultLogN, "scrypt cost parameter logN. Possible values: 10-28. "+
"A lower value speeds up mounting and reduces its memory needs, but makes the password susceptible to brute-force attacks")
flagSet.DurationVar(&args.idle, "i", 0, "Alias for -idle")
@@ -227,6 +230,10 @@ func parseCliOpts() (args argContainer) {
tlog.Fatal.Printf("Invalid command line: %s. Try '%s -help'.", prettyArgs(), tlog.ProgramName)
os.Exit(exitcodes.Usage)
}
+ // We want to know if -scryptn was passed explicitely
+ if isFlagPassed(flagSet, scryptn) {
+ args._explicitScryptn = true
+ }
// "-openssl" needs some post-processing
if opensslAuto == "auto" {
args.openssl = prefer_openssl.PreferOpenSSL()
@@ -311,3 +318,15 @@ func countOpFlags(args *argContainer) int {
}
return count
}
+
+// isFlagPassed finds out if the flag was explictely passed on the command line.
+// https://stackoverflow.com/a/54747682/1380267
+func isFlagPassed(flagSet *flag.FlagSet, name string) bool {
+ found := false
+ flagSet.Visit(func(f *flag.Flag) {
+ if f.Name == name {
+ found = true
+ }
+ })
+ return found
+}