diff options
author | Werner Koch <[email protected]> | 2016-08-13 10:49:54 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2016-08-13 11:49:41 +0000 |
commit | b57f55321295846d47144bd6b39fbbcac0127421 (patch) | |
tree | 4469af47dd36b04c9e1a4309f127d02194b1ff54 /g13/call-syshelp.c | |
parent | Avoid leading ": " in the log output when there are no prefixes. (diff) | |
download | gnupg-b57f55321295846d47144bd6b39fbbcac0127421.tar.gz gnupg-b57f55321295846d47144bd6b39fbbcac0127421.zip |
g13: New command --find-device.
* common/status.h (STATUS_BLOCKDEV: New.
* g13/call-syshelp.c: Include "call-syshelp.h".
(finddevice_status_cb, call_syshelp_find_device): New.
* g13/g13.c (aFindDevice): New.
(opts): Add "--find-device".
(main): Implement --find-device.
* g13/sh-cmd.c (cmd_finddevice): New.
(register_commands): Register new command.
--
This might be useful for scripting.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to '')
-rw-r--r-- | g13/call-syshelp.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/g13/call-syshelp.c b/g13/call-syshelp.c index bc93d2014..d0f1b0070 100644 --- a/g13/call-syshelp.c +++ b/g13/call-syshelp.c @@ -33,6 +33,7 @@ #include "keyblob.h" #include "membuf.h" #include "create.h" +#include "call-syshelp.h" /* Local data for this module. A pointer to this is stored in the @@ -172,6 +173,68 @@ call_syshelp_release (ctrl_t ctrl) } + +/* Staus callback for call_syshelp_find_device. */ +static gpg_error_t +finddevice_status_cb (void *opaque, const char *line) +{ + char **r_blockdev = opaque; + char *p; + + if ((p = has_leading_keyword (line, "BLOCKDEV")) && *p && !*r_blockdev) + { + *r_blockdev = xtrystrdup (p); + if (!*r_blockdev) + return gpg_error_from_syserror (); + } + + return 0; +} + + +/* Send the FINDDEVICE command to the syshelper. On success the name + * of the block device is stored at R_BLOCKDEV. */ +gpg_error_t +call_syshelp_find_device (ctrl_t ctrl, const char *name, char **r_blockdev) +{ + gpg_error_t err; + assuan_context_t ctx; + char *line = NULL; + char *blockdev = NULL; /* The result. */ + + *r_blockdev = NULL; + + err = start_syshelp (ctrl, &ctx); + if (err) + goto leave; + + line = xtryasprintf ("FINDDEVICE %s", name); + if (!line) + { + err = gpg_error_from_syserror (); + goto leave; + } + err = assuan_transact (ctx, line, NULL, NULL, NULL, NULL, + finddevice_status_cb, &blockdev); + if (err) + goto leave; + if (!blockdev) + { + log_error ("status line for successful FINDDEVICE missing\n"); + err = gpg_error (GPG_ERR_UNEXPECTED); + goto leave; + } + *r_blockdev = blockdev; + blockdev = NULL; + + leave: + xfree (blockdev); + xfree (line); + return err; +} + + + /* Send the DEVICE command to the syshelper. FNAME is the name of the device. */ gpg_error_t |