aboutsummaryrefslogtreecommitdiffstats
path: root/sm
diff options
context:
space:
mode:
Diffstat (limited to 'sm')
-rw-r--r--sm/ChangeLog14
-rw-r--r--sm/gpgsm.c85
-rw-r--r--sm/keylist.c4
-rw-r--r--sm/server.c57
4 files changed, 94 insertions, 66 deletions
diff --git a/sm/ChangeLog b/sm/ChangeLog
index 3c60f6f9c..7bf2c0713 100644
--- a/sm/ChangeLog
+++ b/sm/ChangeLog
@@ -1,3 +1,17 @@
+2006-09-13 Werner Koch <[email protected]>
+
+ * keylist.c (list_internal_keys): Print marker line to FP and not
+ to stdout.
+
+ * gpgsm.c (main): All list key list commands now make ose of
+ --output. Cleaned up calls to list modes. New command
+ --dump-chain. Renamed --list-sigs to --list-chain and added an
+ alias for the old one.
+
+ * server.c (cmd_message): Changed to use assuan_command_parse_fd.
+ (option_handler): New option list-to-output.
+ (do_listkeys): Use it.
+
2006-09-06 Werner Koch <[email protected]>
* gpgsm.h (OUT_OF_CORE): Removed and changed all callers to
diff --git a/sm/gpgsm.c b/sm/gpgsm.c
index aaf5c42fe..49a56cd7c 100644
--- a/sm/gpgsm.c
+++ b/sm/gpgsm.c
@@ -80,7 +80,7 @@ enum cmd_and_opt_values {
aVerify,
aVerifyFiles,
aListExternalKeys,
- aListSigs,
+ aListChain,
aSendKeys,
aRecvKeys,
aExport,
@@ -93,6 +93,7 @@ enum cmd_and_opt_values {
aPasswd,
aGPGConfList,
aDumpKeys,
+ aDumpChain,
aDumpSecretKeys,
aDumpExternalKeys,
aKeydbClearSomeCertFlags,
@@ -251,8 +252,7 @@ static ARGPARSE_OPTS opts[] = {
{ aListKeys, "list-keys", 256, N_("list keys")},
{ aListExternalKeys, "list-external-keys", 256, N_("list external keys")},
{ aListSecretKeys, "list-secret-keys", 256, N_("list secret keys")},
- { aListSigs, "list-sigs", 256, N_("list certificate chain")},
- { aListSigs, "check-sigs",256, "@"},
+ { aListChain, "list-chain", 256, N_("list certificate chain")},
{ oFingerprint, "fingerprint", 256, N_("list keys and fingerprints")},
{ aKeygen, "gen-key", 256, N_("generate a new key pair")},
{ aDeleteKey, "delete-key",256, N_("remove key from the public keyring")},
@@ -269,6 +269,7 @@ static ARGPARSE_OPTS opts[] = {
{ aGPGConfList, "gpgconf-list", 256, "@" },
{ aDumpKeys, "dump-keys", 256, "@"},
+ { aDumpChain, "dump-chain", 256, "@"},
{ aDumpExternalKeys, "dump-external-keys", 256, "@"},
{ aDumpSecretKeys, "dump-secret-keys", 256, "@"},
{ aKeydbClearSomeCertFlags, "keydb-clear-some-cert-flags", 256, "@"},
@@ -428,9 +429,11 @@ static ARGPARSE_OPTS opts[] = {
{ oWithValidation, "with-validation", 0, "@"},
{ oWithMD5Fingerprint, "with-md5-fingerprint", 0, "@"},
{ oWithEphemeralKeys, "with-ephemeral-keys", 0, "@"},
- { aListKeys, "list-key", 0, "@" }, /* alias */
- { aListSigs, "list-sig", 0, "@" }, /* alias */
- { aListSigs, "check-sig",0, "@" }, /* alias */
+ { aListKeys, "list-key", 256, "@" }, /* alias */
+ { aListChain, "list-sig", 256, "@" }, /* alias */
+ { aListChain, "list-sigs",256, "@" }, /* alias */
+ { aListChain, "check-sig",256, "@" }, /* alias */
+ { aListChain, "check-sigs",256, "@"}, /* alias */
{ oSkipVerify, "skip-verify",0, "@" },
{ oCompressKeys, "compress-keys",0, "@"},
{ oCompressSigs, "compress-sigs",0, "@"},
@@ -930,12 +933,13 @@ main ( int argc, char **argv)
case aExport:
case aExportSecretKeyP12:
case aDumpKeys:
+ case aDumpChain:
case aDumpExternalKeys:
case aDumpSecretKeys:
case aListKeys:
case aListExternalKeys:
case aListSecretKeys:
- case aListSigs:
+ case aListChain:
case aLearnCard:
case aPasswd:
case aKeydbClearSomeCertFlags:
@@ -1518,52 +1522,43 @@ main ( int argc, char **argv)
free_strlist(sl);
break;
- case aListSigs:
- ctrl.with_chain = 1;
+ case aListChain:
+ case aDumpChain:
+ ctrl.with_chain = 1;
case aListKeys:
- for (sl=NULL; argc; argc--, argv++)
- add_to_strlist (&sl, *argv);
- gpgsm_list_keys (&ctrl, sl, stdout, (0 | (1<<6)));
- free_strlist(sl);
- break;
-
case aDumpKeys:
- for (sl=NULL; argc; argc--, argv++)
- add_to_strlist (&sl, *argv);
- gpgsm_list_keys (&ctrl, sl, stdout, (256 | (1<<6)));
- free_strlist(sl);
- break;
-
case aListExternalKeys:
- for (sl=NULL; argc; argc--, argv++)
- add_to_strlist (&sl, *argv);
- gpgsm_list_keys (&ctrl, sl, stdout,
- (0 | (1<<7)));
- free_strlist(sl);
- break;
-
case aDumpExternalKeys:
- for (sl=NULL; argc; argc--, argv++)
- add_to_strlist (&sl, *argv);
- gpgsm_list_keys (&ctrl, sl, stdout,
- (256 | (1<<7)));
- free_strlist(sl);
- break;
-
case aListSecretKeys:
- for (sl=NULL; argc; argc--, argv++)
- add_to_strlist (&sl, *argv);
- gpgsm_list_keys (&ctrl, sl, stdout, (2 | (1<<6)));
- free_strlist(sl);
- break;
-
case aDumpSecretKeys:
- for (sl=NULL; argc; argc--, argv++)
- add_to_strlist (&sl, *argv);
- gpgsm_list_keys (&ctrl, sl, stdout, (256 | 2 | (1<<6)));
- free_strlist(sl);
+ {
+ unsigned int mode;
+ FILE *fp;
+
+ switch (cmd)
+ {
+ case aListChain:
+ case aListKeys: mode = (0 | 0 | (1<<6)); break;
+ case aDumpChain:
+ case aDumpKeys: mode = (256 | 0 | (1<<6)); break;
+ case aListExternalKeys: mode = (0 | 0 | (1<<7)); break;
+ case aDumpExternalKeys: mode = (256 | 0 | (1<<7)); break;
+ case aListSecretKeys: mode = (0 | 2 | (1<<6)); break;
+ case aDumpSecretKeys: mode = (256 | 2 | (1<<6)); break;
+ default: BUG();
+ }
+
+ fp = open_fwrite (opt.outfile?opt.outfile:"-");
+ for (sl=NULL; argc; argc--, argv++)
+ add_to_strlist (&sl, *argv);
+ gpgsm_list_keys (&ctrl, sl, fp, mode);
+ free_strlist(sl);
+ if (fp != stdout)
+ fclose (fp);
+ }
break;
+
case aKeygen: /* generate a key */
log_error ("this function is not yet available from the commandline\n");
break;
diff --git a/sm/keylist.c b/sm/keylist.c
index 4b8f418b2..927bc88a6 100644
--- a/sm/keylist.c
+++ b/sm/keylist.c
@@ -1130,7 +1130,7 @@ list_cert_chain (ctrl_t ctrl, KEYDB_HANDLE hd,
/* List all internal keys or just the keys given as NAMES. MODE is a
bit vector to specify what keys are to be included; see
gpgsm_list_keys (below) for details. If RAW_MODE is true, the raw
- output mode will be used intead of the standard beautified one.
+ output mode will be used instead of the standard beautified one.
*/
static gpg_error_t
list_internal_keys (ctrl_t ctrl, STRLIST names, FILE *fp,
@@ -1229,7 +1229,7 @@ list_internal_keys (ctrl_t ctrl, STRLIST names, FILE *fp,
{
fprintf (fp, "%s\n", resname );
for (i=strlen(resname); i; i-- )
- putchar('-');
+ putc ('-', fp);
putc ('\n', fp);
lastresname = resname;
}
diff --git a/sm/server.c b/sm/server.c
index d7046c59e..16475f66e 100644
--- a/sm/server.c
+++ b/sm/server.c
@@ -44,6 +44,7 @@ struct server_local_s {
int message_fd;
int list_internal;
int list_external;
+ int list_to_output; /* Write keylistings to the output fd. */
certlist_t recplist;
certlist_t signerlist;
certlist_t default_recplist; /* As set by main() - don't release. */
@@ -171,6 +172,11 @@ option_handler (assuan_context_t ctx, const char *key, const char *value)
else
return gpg_error (GPG_ERR_ASS_PARAMETER);
}
+ else if (!strcmp (key, "list-to-output"))
+ {
+ int i = *value? atoi (value) : 0;
+ ctrl->server_local->list_to_output = i;
+ }
else if (!strcmp (key, "with-validation"))
{
int i = *value? atoi (value) : 0;
@@ -624,40 +630,33 @@ cmd_delkeys (assuan_context_t ctx, char *line)
static int
cmd_message (assuan_context_t ctx, char *line)
{
- char *endp;
+ int rc;
int fd;
ctrl_t ctrl = assuan_get_pointer (ctx);
- if (strncmp (line, "FD=", 3))
- return set_error (GPG_ERR_ASS_SYNTAX, "FD=<n> expected");
- line += 3;
- if (!digitp (line))
- return set_error (GPG_ERR_ASS_SYNTAX, "number required");
- fd = strtoul (line, &endp, 10);
- if (*endp)
- return set_error (GPG_ERR_ASS_SYNTAX, "garbage found");
+ rc = assuan_command_parse_fd (ctx, line, &fd);
+ if (rc)
+ return rc;
if (fd == -1)
return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
-
ctrl->server_local->message_fd = fd;
return 0;
}
-
+/* LISTKEYS [<patterns>]
+ LISTSECRETKEYS [<patterns>]
+*/
static int
do_listkeys (assuan_context_t ctx, char *line, int mode)
{
ctrl_t ctrl = assuan_get_pointer (ctx);
- FILE *fp = assuan_get_data_fp (ctx);
+ FILE *fp;
char *p;
STRLIST list, sl;
unsigned int listmode;
gpg_error_t err;
- if (!fp)
- return set_error (GPG_ERR_ASS_GENERAL, "no data stream");
-
- /* break the line down into an STRLIST */
+ /* Break the line down into an STRLIST. */
list = NULL;
for (p=line; *p; line = p)
{
@@ -680,6 +679,21 @@ do_listkeys (assuan_context_t ctx, char *line, int mode)
}
}
+ if (ctrl->server_local->list_to_output)
+ {
+ if ( assuan_get_output_fd (ctx) == -1 )
+ return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
+ fp = fdopen (assuan_get_output_fd (ctx), "w");
+ if (!fp)
+ return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed");
+ }
+ else
+ {
+ fp = assuan_get_data_fp (ctx);
+ if (!fp)
+ return set_error (GPG_ERR_ASS_GENERAL, "no data stream");
+ }
+
ctrl->with_colons = 1;
listmode = mode;
if (ctrl->server_local->list_internal)
@@ -688,6 +702,11 @@ do_listkeys (assuan_context_t ctx, char *line, int mode)
listmode |= (1<<7);
err = gpgsm_list_keys (assuan_get_pointer (ctx), list, fp, listmode);
free_strlist (list);
+ if (ctrl->server_local->list_to_output)
+ {
+ fclose (fp);
+ assuan_close_output_fd (ctx);
+ }
return err;
}
@@ -793,9 +812,9 @@ gpgsm_server (certlist_t default_recplist)
memset (&ctrl, 0, sizeof ctrl);
gpgsm_init_default_ctrl (&ctrl);
- /* For now we use a simple pipe based server so that we can work
- from scripts. We will later add options to run as a daemon and
- wait for requests on a Unix domain socket */
+ /* We use a pipe based server so that we can work from scripts.
+ assuan_init_pipe_server will automagically detect when we are
+ called with a socketpair and ignore FIELDES in this case. */
filedes[0] = 0;
filedes[1] = 1;
rc = assuan_init_pipe_server (&ctx, filedes);