aboutsummaryrefslogtreecommitdiffstats
path: root/g13/mount.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-08-14 18:17:51 +0000
committerWerner Koch <[email protected]>2016-08-14 18:17:51 +0000
commitb781113cf1391926dedf8dc943624d3bb9726318 (patch)
tree6a1d128f05bd2e18daea306602df026c2966c156 /g13/mount.c
parentg13: Fix double free bug. (diff)
downloadgnupg-b781113cf1391926dedf8dc943624d3bb9726318.tar.gz
gnupg-b781113cf1391926dedf8dc943624d3bb9726318.zip
g13: Implement --umount for dm-crypt.
* g13/g13.c (main): Implement command --umount. * g13/mount.c (g13_umount_container): use the syshelper if needed. * g13/backend.c (be_umount_container): New. * g13/be-dmcrypt.c (be_dmcrypt_umount_container): New. * g13/call-syshelp.c (call_syshelp_run_umount): New. * g13/sh-cmd.c (cmd_umount): New. (register_commands): Register UMOUNT. * g13/sh-dmcrypt.c (sh_dmcrypt_umount_container): New. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g13/mount.c')
-rw-r--r--g13/mount.c58
1 files changed, 39 insertions, 19 deletions
diff --git a/g13/mount.c b/g13/mount.c
index d6825859d..f4371cce5 100644
--- a/g13/mount.c
+++ b/g13/mount.c
@@ -64,10 +64,7 @@ g13_mount_container (ctrl_t ctrl, const char *filename, const char *mountpoint)
if (access (filename, F_OK))
return gpg_error_from_syserror ();
- /* Decide whether we need to use the g13-syshelp because we can't
- use lock files for them. This is most likely the case for device
- files; thus we test for this. FIXME: The correct solution would
- be to call g13-syshelp to match the file against the g13tab. */
+ /* Decide whether we need to use the g13-syshelp. */
err = call_syshelp_find_device (ctrl, filename, &blockdev_buffer);
if (!err)
{
@@ -217,27 +214,50 @@ gpg_error_t
g13_umount_container (ctrl_t ctrl, const char *filename, const char *mountpoint)
{
gpg_error_t err;
- unsigned int rid;
- runner_t runner;
-
- (void)ctrl;
+ char *blockdev;
if (!filename && !mountpoint)
return gpg_error (GPG_ERR_ENOENT);
- err = mountinfo_find_mount (filename, mountpoint, &rid);
- if (err)
- return err;
-
- runner = runner_find_by_rid (rid);
- if (!runner)
+ /* Decide whether we need to use the g13-syshelp. */
+ err = call_syshelp_find_device (ctrl, filename, &blockdev);
+ if (!err)
+ {
+ /* Need to employ the syshelper to umount the file system. */
+ /* FIXME: We should get the CONTTYPE from the blockdev. */
+ err = be_umount_container (ctrl, CONTTYPE_DM_CRYPT, blockdev);
+ if (!err)
+ {
+ /* if (conttype == CONTTYPE_DM_CRYPT) */
+ g13_request_shutdown ();
+ }
+ }
+ else if (gpg_err_code (err) != GPG_ERR_NOT_FOUND)
{
- log_error ("runner %u not found\n", rid);
- return gpg_error (GPG_ERR_NOT_FOUND);
+ log_error ("error finding device '%s': %s <%s>\n",
+ filename, gpg_strerror (err), gpg_strsource (err));
}
+ else
+ {
+ /* Not in g13tab - kill the runner process for this mount. */
+ unsigned int rid;
+ runner_t runner;
- runner_cancel (runner);
- runner_release (runner);
+ err = mountinfo_find_mount (filename, mountpoint, &rid);
+ if (err)
+ return err;
- return 0;
+ runner = runner_find_by_rid (rid);
+ if (!runner)
+ {
+ log_error ("runner %u not found\n", rid);
+ return gpg_error (GPG_ERR_NOT_FOUND);
+ }
+
+ runner_cancel (runner);
+ runner_release (runner);
+ }
+
+ xfree (blockdev);
+ return err;
}