summaryrefslogtreecommitdiffstats
path: root/g10/keyedit.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2015-12-24 02:41:23 +0100
committerNIIBE Yutaka <gniibe@fsij.org>2015-12-24 03:48:16 +0100
commitee433d2b00c93b5a4e4ed54b9fb5806361df1b71 (patch)
tree17ebfcf457f00276c6135f28389c859f3aaff716 /g10/keyedit.c
parentg10: fix regression of bkuptocard subcommand in --edit-key. (diff)
downloadgnupg2-ee433d2b00c93b5a4e4ed54b9fb5806361df1b71.tar.xz
gnupg2-ee433d2b00c93b5a4e4ed54b9fb5806361df1b71.zip
g10: Allow relative path for specifying the file for bkuptocard.
* g10/keyedit.c (keyedit_menu): Assume the file is under GNUPGHOME. Also support tilda expansion.
Diffstat (limited to '')
-rw-r--r--g10/keyedit.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/g10/keyedit.c b/g10/keyedit.c
index 15500ef1d..cfbbed7c9 100644
--- a/g10/keyedit.c
+++ b/g10/keyedit.c
@@ -1927,17 +1927,23 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
backup key as generated by the card generation, parse
that key and store it on card. */
KBNODE node;
- const char *fname;
+ char *fname;
PACKET *pkt;
IOBUF a;
- fname = arg_string;
- if (!*fname)
+ if (!*arg_string)
{
tty_printf (_("Command expects a filename argument\n"));
break;
}
+ if (*arg_string == DIRSEP_C)
+ fname = xstrdup (arg_string);
+ else if (*arg_string == '~')
+ fname = make_filename (arg_string, NULL);
+ else
+ fname = make_filename (opt.homedir, arg_string, NULL);
+
/* Open that file. */
a = iobuf_open (fname);
if (a && is_secured_file (iobuf_get_fd (a)))
@@ -1946,12 +1952,13 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
a = NULL;
gpg_err_set_errno (EPERM);
}
- if (!a)
- {
- tty_printf (_("Can't open '%s': %s\n"),
- fname, strerror (errno));
- break;
- }
+ if (!a)
+ {
+ tty_printf (_("Can't open '%s': %s\n"),
+ fname, strerror (errno));
+ xfree (fname);
+ break;
+ }
/* Parse and check that file. */
pkt = xmalloc (sizeof *pkt);
@@ -1962,14 +1969,17 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
if (!err && pkt->pkttype != PKT_SECRET_KEY
&& pkt->pkttype != PKT_SECRET_SUBKEY)
err = GPG_ERR_NO_SECKEY;
- if (err)
- {
- tty_printf (_("Error reading backup key from '%s': %s\n"),
- fname, gpg_strerror (err));
- free_packet (pkt);
- xfree (pkt);
- break;
- }
+ if (err)
+ {
+ tty_printf (_("Error reading backup key from '%s': %s\n"),
+ fname, gpg_strerror (err));
+ xfree (fname);
+ free_packet (pkt);
+ xfree (pkt);
+ break;
+ }
+
+ xfree (fname);
node = new_kbnode (pkt);
if (cmd == cmdCHECKBKUPKEY)