From a413066de10f31a5db98cc1a0564a49f8779157f Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 19 Nov 2001 16:17:43 +0000 Subject: [PATCH] Added basic code for keylisting. New Assuan command LISTKEYS. --- sm/Makefile.am | 1 + sm/fingerprint.c | 2 +- sm/gpgsm.c | 7 +++---- sm/gpgsm.h | 5 +++-- sm/server.c | 14 ++++++++++++++ 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/sm/Makefile.am b/sm/Makefile.am index 4b74672ab..a7bd02f4f 100644 --- a/sm/Makefile.am +++ b/sm/Makefile.am @@ -34,6 +34,7 @@ gpgsm_SOURCES = \ certdump.c \ certcheck.c \ certpath.c \ + keylist.c \ verify.c \ import.c diff --git a/sm/fingerprint.c b/sm/fingerprint.c index a612f3b87..c6571ab14 100644 --- a/sm/fingerprint.c +++ b/sm/fingerprint.c @@ -33,7 +33,7 @@ #include "gpgsm.h" /* Return the fingerprint of the certificate (we can't put this into - libksba becuase we need libgcrypt support). The caller must + libksba because we need libgcrypt support). The caller must provide an array of sufficient length or NULL so that the function allocates the array. If r_len is not NULL, the length of the digest is return, well, this can also be done by using diff --git a/sm/gpgsm.c b/sm/gpgsm.c index 3a84777e1..72e6d41ec 100644 --- a/sm/gpgsm.c +++ b/sm/gpgsm.c @@ -730,7 +730,7 @@ main ( int argc, char **argv) break; case oWithKeyData: opt.with_key_data=1; /* fall thru */ - case oWithColons: opt.with_colons=':'; break; + case oWithColons: ctrl.with_colons = 1; break; case oSkipVerify: opt.skip_verify=1; break; @@ -969,10 +969,9 @@ main ( int argc, char **argv) break; case aListKeys: - sl = NULL; - for ( ; argc; argc--, argv++ ) + for (sl=NULL; argc; argc--, argv++) add_to_strlist (&sl, *argv); -/* public_key_list( sl ); */ + gpgsm_list_keys (&ctrl, sl, stdout); free_strlist(sl); break; diff --git a/sm/gpgsm.h b/sm/gpgsm.h index 5f7f56454..f26228105 100644 --- a/sm/gpgsm.h +++ b/sm/gpgsm.h @@ -130,7 +130,6 @@ struct { const char *homedir; /* configuration directory name */ char *outfile; /* name of output file */ - int with_colons; /* use column delimited output format */ int with_key_data;/* include raw key in the column delimted output */ int fingerprint; /* list fingerprints in all key listings */ @@ -176,6 +175,7 @@ struct server_control_s { int no_server; /* we are not running under server control */ int status_fd; /* only for non-server mode */ struct server_local_s *server_local; + int with_colons; /* use column delimited output format */ }; typedef struct server_control_s *CTRL; @@ -204,7 +204,8 @@ int gpgsm_check_cms_signature (KsbaCert cert, const char *sigval, /*-- certpath.c --*/ int gpgsm_validate_path (KsbaCert cert); - +/*-- keylist.c --*/ +void gpgsm_list_keys (CTRL ctrl, STRLIST names, FILE *fp); /*-- import.c --*/ diff --git a/sm/server.c b/sm/server.c index c44de16da..69287e06a 100644 --- a/sm/server.c +++ b/sm/server.c @@ -185,6 +185,19 @@ cmd_message (ASSUAN_CONTEXT ctx, char *line) return 0; } +static int +cmd_listkeys (ASSUAN_CONTEXT ctx, char *line) +{ + CTRL ctrl = assuan_get_pointer (ctx); + + ctrl->with_colons = 1; + /* fixme: check that the returned data_fp is not NULL */ + gpgsm_list_keys (assuan_get_pointer (ctx), NULL, assuan_get_data_fp (ctx)); + + return 0; +} + + @@ -206,6 +219,7 @@ register_commands (ASSUAN_CONTEXT ctx) { "", ASSUAN_CMD_INPUT, NULL }, { "", ASSUAN_CMD_OUTPUT, NULL }, { "MESSAGE", 0, cmd_message }, + { "LISTKEYS", 0, cmd_listkeys }, { NULL } }; int i, j, rc;