summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/MANPAGE.md8
-rw-r--r--cli_args.go25
-rw-r--r--main.go4
3 files changed, 34 insertions, 3 deletions
diff --git a/Documentation/MANPAGE.md b/Documentation/MANPAGE.md
index 87265d8..b945a1d 100644
--- a/Documentation/MANPAGE.md
+++ b/Documentation/MANPAGE.md
@@ -18,7 +18,7 @@ gocryptfs -init [OPTIONS] CIPHERDIR
Mount
-----
-gocryptfs [OPTIONS] CIPHERDIR MOUNTPOINT
+gocryptfs [OPTIONS] CIPHERDIR MOUNTPOINT [-o COMMA-SEPARATED-OPTIONS]
Change password
---------------
@@ -143,6 +143,12 @@ useful in regression testing.
automated testing as it does not provide any security.
+Comma-Separated-Options:
+
+For compatability with mount(1), options are also accepted as
+"-o COMMA-SEPARATED-OPTIONS" at the end of the command line.
+For example, "-o q,zerokey" is equivalent to "-q -zerokey".
+
EXAMPLES
========
diff --git a/cli_args.go b/cli_args.go
index 94363d0..0db5ba6 100644
--- a/cli_args.go
+++ b/cli_args.go
@@ -4,6 +4,7 @@ import (
"flag"
"os"
"strconv"
+ "strings"
"github.com/rfjakob/gocryptfs/internal/configfile"
"github.com/rfjakob/gocryptfs/internal/prefer_openssl"
@@ -27,8 +28,32 @@ type argContainer struct {
var flagSet *flag.FlagSet
+// prefixOArgs transform options passed via "-o foo,bar" into regular options
+// like "-foo -bar" and prefixes them to the command line.
+func prefixOArgs(osArgs []string) []string {
+ l := len(osArgs)
+ // Need at least 3, example: gocryptfs -o foo,bar
+ if l < 3 {
+ return osArgs
+ }
+ if osArgs[l-2] != "-o" {
+ return osArgs
+ }
+ oOpts := strings.Split(osArgs[l-1], ",")
+ osArgs = osArgs[:l-2]
+ newArgs := []string{osArgs[0]}
+ // Add options from "-o"
+ for _, a := range oOpts {
+ newArgs = append(newArgs, "-"+a)
+ }
+ newArgs = append(newArgs, osArgs[1:]...)
+ return newArgs
+}
+
// parseCliOpts - parse command line options (i.e. arguments that start with "-")
func parseCliOpts() (args argContainer) {
+ os.Args = prefixOArgs(os.Args)
+
var err error
var opensslAuto string
diff --git a/main.go b/main.go
index 2033e23..6d03ee2 100644
--- a/main.go
+++ b/main.go
@@ -42,7 +42,7 @@ func usageText() {
printVersion()
fmt.Printf(`
Usage: %s -init|-passwd [OPTIONS] CIPHERDIR
- or %s [OPTIONS] CIPHERDIR MOUNTPOINT
+ or %s [OPTIONS] CIPHERDIR MOUNTPOINT [-o COMMA-SEPARATED-OPTIONS]
Options:
`, tlog.ProgramName, tlog.ProgramName)
@@ -221,7 +221,7 @@ func main() {
prettyArgs = prettyArgs[1 : len(prettyArgs)-1]
tlog.Info.Printf("Wrong number of arguments (have %d, want 2). You passed: %s",
flagSet.NArg(), prettyArgs)
- tlog.Fatal.Printf("Usage: %s [OPTIONS] CIPHERDIR MOUNTPOINT", tlog.ProgramName)
+ tlog.Fatal.Printf("Usage: %s [OPTIONS] CIPHERDIR MOUNTPOINT [-o COMMA-SEPARATED-OPTIONS]", tlog.ProgramName)
os.Exit(ErrExitUsage)
}
os.Exit(doMount(&args))