1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-13 22:21:09 +02:00

g13: Run mount after dmsetup.

* g13/g13-syshelp.c (main): Reject userids with a slash.
* g13/sh-dmcrypt.c (sh_dmcrypt_mount_container): Run mount if a
mountpoint is known.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-02-22 10:56:27 +01:00
parent ede0061feb
commit f26867928c
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 51 additions and 15 deletions

View File

@ -512,15 +512,23 @@ main ( int argc, char **argv)
ctrl.client.uid = (uid_t)myuid; ctrl.client.uid = (uid_t)myuid;
} }
pwd = getpwuid (ctrl.client.uid); pwd = getpwuid (ctrl.client.uid);
if (!pwd || !*pwd->pw_name) if (!pwd || !*pwd->pw_name)
{ {
log_info ("WARNING: Name for UID not found: %s\n", strerror (errno)); log_info ("WARNING: Name for UID not found: %s\n", strerror (errno));
ctrl.fail_all_cmds = 1; ctrl.fail_all_cmds = 1;
ctrl.client.uname = xstrdup ("?"); ctrl.client.uname = xstrdup ("?");
} }
else else
ctrl.client.uname = xstrdup (pwd->pw_name); ctrl.client.uname = xstrdup (pwd->pw_name);
/* Check that the user name does not contain a directory
separator. */
if (strchr (ctrl.client.uname, '/'))
{
log_info ("WARNING: Invalid user name passed\n");
ctrl.fail_all_cmds = 1;
}
} }
#else /*!HAVE_PWD_H || !HAVE_GETPWUID*/ #else /*!HAVE_PWD_H || !HAVE_GETPWUID*/
log_info ("WARNING: System does not support required syscalls\n"); log_info ("WARNING: System does not support required syscalls\n");

View File

@ -532,7 +532,8 @@ sh_dmcrypt_mount_container (ctrl_t ctrl, const char *devname,
tupledesc_t keyblob) tupledesc_t keyblob)
{ {
gpg_error_t err; gpg_error_t err;
char *targetname = NULL; char *targetname_abs = NULL;
const char *targetname;
char hexkey[16*2+1]; char hexkey[16*2+1];
char *table = NULL; char *table = NULL;
unsigned long long nblocks, nblocks2; unsigned long long nblocks, nblocks2;
@ -615,14 +616,19 @@ sh_dmcrypt_mount_container (ctrl_t ctrl, const char *devname,
/* Device mapper needs a name for the device: Take it from the label /* Device mapper needs a name for the device: Take it from the label
or use "0". */ or use "0". */
targetname = strconcat ("g13-", ctrl->client.uname, "-", targetname_abs = strconcat ("/dev/mapper/",
ctrl->devti->label? ctrl->devti->label : "0", "g13-", ctrl->client.uname, "-",
NULL); ctrl->devti->label? ctrl->devti->label : "0",
if (!targetname) NULL);
if (!targetname_abs)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
goto leave; goto leave;
} }
targetname = strrchr (targetname_abs, '/');
if (!targetname)
BUG ();
targetname++;
/* Get the algorithm string. */ /* Get the algorithm string. */
algostr = find_tuple (keyblob, KEYBLOB_TAG_ALGOSTR, &algostrlen); algostr = find_tuple (keyblob, KEYBLOB_TAG_ALGOSTR, &algostrlen);
@ -675,6 +681,28 @@ sh_dmcrypt_mount_container (ctrl_t ctrl, const char *devname,
} }
if (result && *result) if (result && *result)
log_debug ("dmsetup result: %s\n", result); log_debug ("dmsetup result: %s\n", result);
xfree (result);
result = NULL;
/* Mount if a mountpoint has been given. */
if (ctrl->devti->mountpoint)
{
const char *argv[3];
argv[0] = targetname_abs;
argv[1] = ctrl->devti->mountpoint;
argv[2] = NULL;
log_debug ("now running \"mount %s %s\"\n",
targetname_abs, ctrl->devti->mountpoint);
err = gnupg_exec_tool ("/bin/mount", argv, NULL, &result, NULL);
if (err)
{
log_error ("error running mount: %s\n", gpg_strerror (err));
goto leave;
}
if (result && *result) /* (We should not see output to stdout). */
log_info ("WARNING: mount returned data on stdout! (%s)\n", result);
}
leave: leave:
@ -684,7 +712,7 @@ sh_dmcrypt_mount_container (ctrl_t ctrl, const char *devname,
wipememory (table, strlen (table)); wipememory (table, strlen (table));
xfree (table); xfree (table);
} }
xfree (targetname); xfree (targetname_abs);
xfree (result); xfree (result);
return err; return err;
} }