summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2017-09-18 11:16:07 +0200
committerWerner Koch <wk@gnupg.org>2017-09-18 11:16:07 +0200
commit4e0696de897cac6a34d55a69d8889faf26f1a923 (patch)
tree9f3c6e2b4bf1a23b85000ded5380f0d8f52b631b /tools
parentgpgv: Initialize compliance checker. (diff)
downloadgnupg2-4e0696de897cac6a34d55a69d8889faf26f1a923.tar.xz
gnupg2-4e0696de897cac6a34d55a69d8889faf26f1a923.zip
wks: Use dedicated type to convey user ids.
* tools/gpg-wks.h (uidinfo_list_s, uidinfo_list_t): New. * tools/wks-util.c (append_to_uidinfo_list): New. (free_uidinfo_list): New. (wks_list_key): Change arg r_mboxes to uidinfo_list_t. Use append_to_uidinfo_list. * tools/gpg-wks-server.c (sserver_ctx_s): Replace strlist_t by uidinfo_list_t. (process_new_key): Ditto. (check_and_publish): Ditto. (command_receive_cb): Replace free_strlist by free_uidinfo_list. * tools/gpg-wks-client.c (command_check): Replace strlist_t by uidinfo_list_t. Also print user id in verbose mode. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/gpg-wks-client.c19
-rw-r--r--tools/gpg-wks-server.c36
-rw-r--r--tools/gpg-wks.h14
-rw-r--r--tools/wks-util.c54
4 files changed, 91 insertions, 32 deletions
diff --git a/tools/gpg-wks-client.c b/tools/gpg-wks-client.c
index e703640e1..6b83de8c5 100644
--- a/tools/gpg-wks-client.c
+++ b/tools/gpg-wks-client.c
@@ -119,7 +119,7 @@ const char *fake_submission_addr;
static void wrong_args (const char *text) GPGRT_ATTR_NORETURN;
static gpg_error_t command_supported (char *userid);
static gpg_error_t command_check (char *userid);
-static gpg_error_t command_send (const char *fingerprint, char *userid);
+static gpg_error_t command_send (const char *fingerprint, const char *userid);
static gpg_error_t encrypt_response (estream_t *r_output, estream_t input,
const char *addrspec,
const char *fingerprint);
@@ -597,8 +597,8 @@ command_check (char *userid)
char *addrspec = NULL;
estream_t key = NULL;
char *fpr = NULL;
- strlist_t mboxes = NULL;
- strlist_t sl;
+ uidinfo_list_t mboxes = NULL;
+ uidinfo_list_t sl;
int found = 0;
addrspec = mailbox_from_userid (userid);
@@ -657,10 +657,14 @@ command_check (char *userid)
for (sl = mboxes; sl; sl = sl->next)
{
- if (!strcmp (sl->d, addrspec))
+ if (sl->mbox && !strcmp (sl->mbox, addrspec))
found = 1;
if (opt.verbose)
- log_info (" addr-spec: %s\n", sl->d);
+ {
+ log_info (" user-id: %s\n", sl->uid);
+ if (sl->mbox)
+ log_info (" addr-spec: %s\n", sl->mbox);
+ }
}
if (!found)
{
@@ -671,7 +675,7 @@ command_check (char *userid)
leave:
xfree (fpr);
- free_strlist (mboxes);
+ free_uidinfo_list (mboxes);
es_fclose (key);
xfree (addrspec);
return err;
@@ -682,7 +686,7 @@ command_check (char *userid)
/* Locate the key by fingerprint and userid and send a publication
* request. */
static gpg_error_t
-command_send (const char *fingerprint, char *userid)
+command_send (const char *fingerprint, const char *userid)
{
gpg_error_t err;
KEYDB_SEARCH_DESC desc;
@@ -706,6 +710,7 @@ command_send (const char *fingerprint, char *userid)
err = gpg_error (GPG_ERR_INV_NAME);
goto leave;
}
+
addrspec = mailbox_from_userid (userid);
if (!addrspec)
{
diff --git a/tools/gpg-wks-server.c b/tools/gpg-wks-server.c
index 1633a2084..f7aadba3d 100644
--- a/tools/gpg-wks-server.c
+++ b/tools/gpg-wks-server.c
@@ -127,7 +127,7 @@ static struct debug_flags_s debug_flags [] =
struct server_ctx_s
{
char *fpr;
- strlist_t mboxes; /* List of addr-specs taken from the UIDs. */
+ uidinfo_list_t mboxes; /* List with addr-specs taken from the UIDs. */
unsigned int draft_version_2:1; /* Client supports the draft 2. */
};
typedef struct server_ctx_s *server_ctx_t;
@@ -1092,7 +1092,7 @@ static gpg_error_t
process_new_key (server_ctx_t ctx, estream_t key)
{
gpg_error_t err;
- strlist_t sl;
+ uidinfo_list_t sl;
const char *s;
char *dname = NULL;
char *nonce = NULL;
@@ -1101,7 +1101,7 @@ process_new_key (server_ctx_t ctx, estream_t key)
/* First figure out the user id from the key. */
xfree (ctx->fpr);
- free_strlist (ctx->mboxes);
+ free_uidinfo_list (ctx->mboxes);
err = wks_list_key (key, &ctx->fpr, &ctx->mboxes);
if (err)
goto leave;
@@ -1114,14 +1114,17 @@ process_new_key (server_ctx_t ctx, estream_t key)
log_info ("fingerprint: %s\n", ctx->fpr);
for (sl = ctx->mboxes; sl; sl = sl->next)
{
- log_info (" addr-spec: %s\n", sl->d);
+ if (sl->mbox)
+ log_info (" addr-spec: %s\n", sl->mbox);
}
/* Walk over all user ids and send confirmation requests for those
* we support. */
for (sl = ctx->mboxes; sl; sl = sl->next)
{
- s = strchr (sl->d, '@');
+ if (!sl->mbox)
+ continue;
+ s = strchr (sl->mbox, '@');
log_assert (s && s[1]);
xfree (dname);
dname = make_filename_try (opt.directory, s+1, NULL);
@@ -1133,26 +1136,26 @@ process_new_key (server_ctx_t ctx, estream_t key)
if (access (dname, W_OK))
{
- log_info ("skipping address '%s': Domain not configured\n", sl->d);
+ log_info ("skipping address '%s': Domain not configured\n", sl->mbox);
continue;
}
- if (get_policy_flags (&policybuf, sl->d))
+ if (get_policy_flags (&policybuf, sl->mbox))
{
- log_info ("skipping address '%s': Bad policy flags\n", sl->d);
+ log_info ("skipping address '%s': Bad policy flags\n", sl->mbox);
continue;
}
if (policybuf.auth_submit)
{
/* Bypass the confirmation stuff and publish the key as is. */
- log_info ("publishing address '%s'\n", sl->d);
+ log_info ("publishing address '%s'\n", sl->mbox);
/* FIXME: We need to make sure that we do this only for the
* address in the mail. */
log_debug ("auth-submit not yet working!\n");
}
else
{
- log_info ("storing address '%s'\n", sl->d);
+ log_info ("storing address '%s'\n", sl->mbox);
xfree (nonce);
xfree (fname);
@@ -1160,7 +1163,7 @@ process_new_key (server_ctx_t ctx, estream_t key)
if (err)
goto leave;
- err = send_confirmation_request (ctx, sl->d, nonce, fname);
+ err = send_confirmation_request (ctx, sl->mbox, nonce, fname);
if (err)
goto leave;
}
@@ -1313,7 +1316,7 @@ check_and_publish (server_ctx_t ctx, const char *address, const char *nonce)
char *hash = NULL;
const char *domain;
const char *s;
- strlist_t sl;
+ uidinfo_list_t sl;
char shaxbuf[32]; /* Used for SHA-1 and SHA-256 */
/* FIXME: There is a bug in name-value.c which adds white space for
@@ -1351,7 +1354,7 @@ check_and_publish (server_ctx_t ctx, const char *address, const char *nonce)
/* We need to get the fingerprint from the key. */
xfree (ctx->fpr);
- free_strlist (ctx->mboxes);
+ free_uidinfo_list (ctx->mboxes);
err = wks_list_key (key, &ctx->fpr, &ctx->mboxes);
if (err)
goto leave;
@@ -1363,13 +1366,14 @@ check_and_publish (server_ctx_t ctx, const char *address, const char *nonce)
}
log_info ("fingerprint: %s\n", ctx->fpr);
for (sl = ctx->mboxes; sl; sl = sl->next)
- log_info (" addr-spec: %s\n", sl->d);
+ if (sl->mbox)
+ log_info (" addr-spec: %s\n", sl->mbox);
/* Check that the key has 'address' as a user id. We use
* case-insensitive matching because the client is expected to
* return the address verbatim. */
for (sl = ctx->mboxes; sl; sl = sl->next)
- if (!strcmp (sl->d, address))
+ if (sl->mbox && !strcmp (sl->mbox, address))
break;
if (!sl)
{
@@ -1565,7 +1569,7 @@ command_receive_cb (void *opaque, const char *mediatype,
}
xfree (ctx.fpr);
- free_strlist (ctx.mboxes);
+ free_uidinfo_list (ctx.mboxes);
return err;
}
diff --git a/tools/gpg-wks.h b/tools/gpg-wks.h
index caea98e2f..7fc8d9acd 100644
--- a/tools/gpg-wks.h
+++ b/tools/gpg-wks.h
@@ -69,11 +69,23 @@ struct policy_flags_s
typedef struct policy_flags_s *policy_flags_t;
+/* An object to convey user ids of a key. */
+struct uidinfo_list_s
+{
+ struct uidinfo_list_s *next;
+ char *mbox; /* NULL or the malloced mailbox from UID. */
+ char uid[1];
+};
+typedef struct uidinfo_list_s *uidinfo_list_t;
+
+
/*-- wks-util.c --*/
void wks_set_status_fd (int fd);
void wks_write_status (int no, const char *format, ...) GPGRT_ATTR_PRINTF(2,3);
-gpg_error_t wks_list_key (estream_t key, char **r_fpr, strlist_t *r_mboxes);
+void free_uidinfo_list (uidinfo_list_t list);
+gpg_error_t wks_list_key (estream_t key, char **r_fpr,
+ uidinfo_list_t *r_mboxes);
gpg_error_t wks_send_mime (mime_maker_t mime);
gpg_error_t wks_parse_policy (policy_flags_t flags, estream_t stream,
int ignore_unknown);
diff --git a/tools/wks-util.c b/tools/wks-util.c
index 45237b2b4..bc076a7c0 100644
--- a/tools/wks-util.c
+++ b/tools/wks-util.c
@@ -90,6 +90,48 @@ wks_write_status (int no, const char *format, ...)
+
+/* Append UID to LIST and return the new item. On success LIST is
+ * updated. On error ERRNO is set and NULL returned. */
+static uidinfo_list_t
+append_to_uidinfo_list (uidinfo_list_t *list, const char *uid)
+{
+ uidinfo_list_t r, sl;
+
+ sl = xtrymalloc (sizeof *sl + strlen (uid));
+ if (!sl)
+ return NULL;
+
+ strcpy (sl->uid, uid);
+ sl->mbox = mailbox_from_userid (uid);
+ sl->next = NULL;
+ if (!*list)
+ *list = sl;
+ else
+ {
+ for (r = *list; r->next; r = r->next )
+ ;
+ r->next = sl;
+ }
+ return sl;
+}
+
+
+/* Free the list of uid infos at LIST. */
+void
+free_uidinfo_list (uidinfo_list_t list)
+{
+ while (list)
+ {
+ uidinfo_list_t tmp = list->next;
+ xfree (list->mbox);
+ xfree (list);
+ list = tmp;
+ }
+}
+
+
+
/* Helper for wks_list_key. */
static void
list_key_status_cb (void *opaque, const char *keyword, char *args)
@@ -105,7 +147,7 @@ list_key_status_cb (void *opaque, const char *keyword, char *args)
* list of mailboxes at R_MBOXES. Returns 0 on success; on error NULL
* is stored at R_FPR and R_MBOXES and an error code is returned. */
gpg_error_t
-wks_list_key (estream_t key, char **r_fpr, strlist_t *r_mboxes)
+wks_list_key (estream_t key, char **r_fpr, uidinfo_list_t *r_mboxes)
{
gpg_error_t err;
ccparray_t ccp;
@@ -118,9 +160,8 @@ wks_list_key (estream_t key, char **r_fpr, strlist_t *r_mboxes)
char **fields = NULL;
int nfields;
int lnr;
- char *mbox = NULL;
char *fpr = NULL;
- strlist_t mboxes = NULL;
+ uidinfo_list_t mboxes = NULL;
*r_fpr = NULL;
*r_mboxes = NULL;
@@ -232,9 +273,7 @@ wks_list_key (estream_t key, char **r_fpr, strlist_t *r_mboxes)
else if (!strcmp (fields[0], "uid") && nfields > 9)
{
/* Fixme: Unescape fields[9] */
- xfree (mbox);
- mbox = mailbox_from_userid (fields[9]);
- if (mbox && !append_to_strlist_try (&mboxes, mbox))
+ if (!append_to_uidinfo_list (&mboxes, fields[9]))
{
err = gpg_error_from_syserror ();
goto leave;
@@ -255,8 +294,7 @@ wks_list_key (estream_t key, char **r_fpr, strlist_t *r_mboxes)
leave:
xfree (fpr);
- xfree (mboxes);
- xfree (mbox);
+ free_uidinfo_list (mboxes);
xfree (fields);
es_free (line);
xfree (argv);