d262007be705 — Sebastian Messmer 10 years ago
Allow using an external encfs6 config file (see ENCFS6_CONFIG env variable)
1 files changed, 24 insertions(+), 7 deletions(-)

M gnome-encfs
M gnome-encfs +24 -7
@@ 121,6 121,8 @@ def _options():
                   help="Input for mount point edit")
     og.add_option("", "--amount", default=None,
                   help="Input for auto mount question")
+    og.add_option("", "--encfs6config", default=None,
+                  help="Set an encfs6 config file to use (instead of using the one in the encfs path)")
     op.add_option_group(og)
 
     opts, args = op.parse_args()

          
@@ 157,6 159,7 @@ def _options():
     preset.epath = opts.epath
     preset.mpoint = opts.mpoint
     preset.amount = opts.amount
+    preset.encfs6config = opts.encfs6config
 
     return opts
 

          
@@ 181,6 184,12 @@ def _pathify(path):
     path = os.path.realpath(path)
     return path
 
+def _env_with_encfs6config(encfs6config):
+    env = os.environ.copy()
+    if encfs6config != "":
+        env["ENCFS6_CONFIG"] = encfs6config
+    return env
+
 def _is_mounted(mpoint):
     """Check of something is mounted at given mount point."""
 

          
@@ 191,11 200,11 @@ def _is_mounted(mpoint):
     points = [os.path.abspath(p) for p in points]
     return os.path.abspath(mpoint) in points
 
-def _is_encfs(epath):
+def _is_encfs(epath, encfs6config):
     """Check if 'epath' points to an EncFS directory."""
 
     p = subprocess.Popen(["encfsctl", "info", epath], stdout=subprocess.PIPE,
-                         stderr=subprocess.PIPE)
+                         stderr=subprocess.PIPE, env = _env_with_encfs6config(encfs6config))
     p.communicate()
     return p.returncode == 0
 

          
@@ 273,17 282,21 @@ def list_items(path=None):
         epath = item.attributes["encfs-path"]
         mpoint = item.attributes["mount-point"]
         amount = item.attributes["auto-mount"]
+        encfs6config = item.attributes.get("encfs6config", "[in encfs path]")
         print("* encfs path     : %s" % epath)
         print("  mount point    : %s" % mpoint)
         print("  mount at login : %s" % (amount == "y" and "yes" or "no"))
+        print("  encfs6config   : %s" % encfs6config)
 
     return RC_OK
 
 def add_item(epath, mpoint):
     """Add new EncFS item to keyring."""
 
-    if not _is_encfs(epath):
-        _proceed("no EncFS at given path")
+    encfs6config = preset.encfs6config or ""
+
+    if not _is_encfs(epath, encfs6config):
+        _proceed("no EncFS at given path (maybe you want to specify an external encfs configfile using --encfsconfig)")
     if not os.path.isdir(mpoint):
         _proceed("mount point is not a directory")
     if _get_items(mpoint=mpoint):

          
@@ 292,7 305,7 @@ def add_item(epath, mpoint):
     secret = preset.password or getpass.getpass("EncFS password: ")
     amount = preset.amount or raw_input("Mount at login [Y/n]: ") or "y"
     amount = amount.strip()[0].lower() == "y" and "y" or "n"
-    attr = {"encfs-path": epath, "mount-point": mpoint, "auto-mount": amount}
+    attr = {"encfs-path": epath, "mount-point": mpoint, "auto-mount": amount, "encfs6config": encfs6config}
     attr.update(GENCFS_ATTR)
     name = "EncFS mount at %s" % mpoint
     gk.item_create_sync(KEYRING, ITYPE, name, attr, secret, False)

          
@@ 318,11 331,13 @@ def edit_item(mpoint):
         epath = item.attributes["encfs-path"]
         mpoint = item.attributes["mount-point"]
         amount = item.attributes["auto-mount"]
+        encfs6config = item.attributes.get("encfs6config","")
         epath = preset.epath or raw_input("EncFS path [%s]: " % epath) or epath
         mpoint = preset.mpoint or raw_input("Mount point [%s]: " % mpoint) or mpoint
         secret = preset.password or getpass.getpass("Password [**current**]: ") or item.secret
         hint = amount == "y" and "Y/n" or "y/N"
         amount = preset.amount or raw_input("Mount at login [%s]: " % hint) or amount
+        encfs6config = preset.encfs6config or encfs6config
         amount = amount.strip()[0].lower() == "y" and "y" or "n"
         mpoint = _pathify(mpoint)
         epath = _pathify(epath)

          
@@ 331,7 346,7 @@ def edit_item(mpoint):
         for other in [i for i in items if i.item_id != item.item_id]:
             if other.attributes["mount-point"] == mpoint:
                 _proceed("mount point already in use")
-        if not _is_encfs(epath):
+        if not _is_encfs(epath, encfs6config):
             _proceed("no EncFS at given path")
         if not os.path.isdir(mpoint):
             _proceed("mount point is not a directory")

          
@@ 341,6 356,7 @@ def edit_item(mpoint):
         attributes["encfs-path"] = epath
         attributes["mount-point"] = mpoint
         attributes["auto-mount"] = amount
+        attributes["encfs6config"] = encfs6config
         gk.item_set_attributes_sync(KEYRING, item.item_id, attributes)
         info = gk.item_get_info_sync(KEYRING, item.item_id)
         info.set_secret(secret)

          
@@ 390,6 406,7 @@ def mount_items(path, autostart):
     for item in items:
         epath = item.attributes["encfs-path"]
         mpoint = item.attributes["mount-point"]
+        encfs6config = item.attributes["encfs6config"]
         msg = "Mounting %s at %s: " % (epath, mpoint)
         if _is_mounted(mpoint):
             msg += "mount point already in use"

          
@@ 399,7 416,7 @@ def mount_items(path, autostart):
             rc |= RC_INVALID_PATH
         else:
             cmd = ["encfs", "-o", "nonempty", "-S", epath, mpoint]
-            p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
+            p = subprocess.Popen(cmd, stdin=subprocess.PIPE, env = _env_with_encfs6config(encfs6config))
             p.communicate(input="%s\n" % item.secret)
             msg += p.returncode and "FAILED" or "OK"
             rc |= 0 if p.returncode == os.EX_OK else RC_MOUNT_FAILED