Commits

Sebastian Meßmer committed d262007

Allow using an external encfs6 config file (see ENCFS6_CONFIG env variable)

Comments (0)

Files changed (1)

                   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()
     preset.epath = opts.epath
     preset.mpoint = opts.mpoint
     preset.amount = opts.amount
+    preset.encfs6config = opts.encfs6config
 
     return opts
 
     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."""
 
     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
 
         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):
     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)
         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)
         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")
         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)
     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"
             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