1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-18 14:17:03 +01:00

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>
This commit is contained in:
Werner Koch 2017-09-18 11:16:07 +02:00
parent 006ca124ed
commit 4e0696de89
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
4 changed files with 91 additions and 32 deletions

View File

@ -119,7 +119,7 @@ const char *fake_submission_addr;
static void wrong_args (const char *text) GPGRT_ATTR_NORETURN; static void wrong_args (const char *text) GPGRT_ATTR_NORETURN;
static gpg_error_t command_supported (char *userid); static gpg_error_t command_supported (char *userid);
static gpg_error_t command_check (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, static gpg_error_t encrypt_response (estream_t *r_output, estream_t input,
const char *addrspec, const char *addrspec,
const char *fingerprint); const char *fingerprint);
@ -597,8 +597,8 @@ command_check (char *userid)
char *addrspec = NULL; char *addrspec = NULL;
estream_t key = NULL; estream_t key = NULL;
char *fpr = NULL; char *fpr = NULL;
strlist_t mboxes = NULL; uidinfo_list_t mboxes = NULL;
strlist_t sl; uidinfo_list_t sl;
int found = 0; int found = 0;
addrspec = mailbox_from_userid (userid); addrspec = mailbox_from_userid (userid);
@ -657,10 +657,14 @@ command_check (char *userid)
for (sl = mboxes; sl; sl = sl->next) for (sl = mboxes; sl; sl = sl->next)
{ {
if (!strcmp (sl->d, addrspec)) if (sl->mbox && !strcmp (sl->mbox, addrspec))
found = 1; found = 1;
if (opt.verbose) 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) if (!found)
{ {
@ -671,7 +675,7 @@ command_check (char *userid)
leave: leave:
xfree (fpr); xfree (fpr);
free_strlist (mboxes); free_uidinfo_list (mboxes);
es_fclose (key); es_fclose (key);
xfree (addrspec); xfree (addrspec);
return err; return err;
@ -682,7 +686,7 @@ command_check (char *userid)
/* Locate the key by fingerprint and userid and send a publication /* Locate the key by fingerprint and userid and send a publication
* request. */ * request. */
static gpg_error_t static gpg_error_t
command_send (const char *fingerprint, char *userid) command_send (const char *fingerprint, const char *userid)
{ {
gpg_error_t err; gpg_error_t err;
KEYDB_SEARCH_DESC desc; KEYDB_SEARCH_DESC desc;
@ -706,6 +710,7 @@ command_send (const char *fingerprint, char *userid)
err = gpg_error (GPG_ERR_INV_NAME); err = gpg_error (GPG_ERR_INV_NAME);
goto leave; goto leave;
} }
addrspec = mailbox_from_userid (userid); addrspec = mailbox_from_userid (userid);
if (!addrspec) if (!addrspec)
{ {

View File

@ -127,7 +127,7 @@ static struct debug_flags_s debug_flags [] =
struct server_ctx_s struct server_ctx_s
{ {
char *fpr; 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. */ unsigned int draft_version_2:1; /* Client supports the draft 2. */
}; };
typedef struct server_ctx_s *server_ctx_t; 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) process_new_key (server_ctx_t ctx, estream_t key)
{ {
gpg_error_t err; gpg_error_t err;
strlist_t sl; uidinfo_list_t sl;
const char *s; const char *s;
char *dname = NULL; char *dname = NULL;
char *nonce = 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. */ /* First figure out the user id from the key. */
xfree (ctx->fpr); xfree (ctx->fpr);
free_strlist (ctx->mboxes); free_uidinfo_list (ctx->mboxes);
err = wks_list_key (key, &ctx->fpr, &ctx->mboxes); err = wks_list_key (key, &ctx->fpr, &ctx->mboxes);
if (err) if (err)
goto leave; goto leave;
@ -1114,14 +1114,17 @@ process_new_key (server_ctx_t ctx, estream_t key)
log_info ("fingerprint: %s\n", ctx->fpr); log_info ("fingerprint: %s\n", ctx->fpr);
for (sl = ctx->mboxes; sl; sl = sl->next) 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 /* Walk over all user ids and send confirmation requests for those
* we support. */ * we support. */
for (sl = ctx->mboxes; sl; sl = sl->next) 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]); log_assert (s && s[1]);
xfree (dname); xfree (dname);
dname = make_filename_try (opt.directory, s+1, NULL); 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)) 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; 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; continue;
} }
if (policybuf.auth_submit) if (policybuf.auth_submit)
{ {
/* Bypass the confirmation stuff and publish the key as is. */ /* 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 /* FIXME: We need to make sure that we do this only for the
* address in the mail. */ * address in the mail. */
log_debug ("auth-submit not yet working!\n"); log_debug ("auth-submit not yet working!\n");
} }
else else
{ {
log_info ("storing address '%s'\n", sl->d); log_info ("storing address '%s'\n", sl->mbox);
xfree (nonce); xfree (nonce);
xfree (fname); xfree (fname);
@ -1160,7 +1163,7 @@ process_new_key (server_ctx_t ctx, estream_t key)
if (err) if (err)
goto leave; goto leave;
err = send_confirmation_request (ctx, sl->d, nonce, fname); err = send_confirmation_request (ctx, sl->mbox, nonce, fname);
if (err) if (err)
goto leave; goto leave;
} }
@ -1313,7 +1316,7 @@ check_and_publish (server_ctx_t ctx, const char *address, const char *nonce)
char *hash = NULL; char *hash = NULL;
const char *domain; const char *domain;
const char *s; const char *s;
strlist_t sl; uidinfo_list_t sl;
char shaxbuf[32]; /* Used for SHA-1 and SHA-256 */ char shaxbuf[32]; /* Used for SHA-1 and SHA-256 */
/* FIXME: There is a bug in name-value.c which adds white space for /* 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. */ /* We need to get the fingerprint from the key. */
xfree (ctx->fpr); xfree (ctx->fpr);
free_strlist (ctx->mboxes); free_uidinfo_list (ctx->mboxes);
err = wks_list_key (key, &ctx->fpr, &ctx->mboxes); err = wks_list_key (key, &ctx->fpr, &ctx->mboxes);
if (err) if (err)
goto leave; 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); log_info ("fingerprint: %s\n", ctx->fpr);
for (sl = ctx->mboxes; sl; sl = sl->next) 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 /* Check that the key has 'address' as a user id. We use
* case-insensitive matching because the client is expected to * case-insensitive matching because the client is expected to
* return the address verbatim. */ * return the address verbatim. */
for (sl = ctx->mboxes; sl; sl = sl->next) for (sl = ctx->mboxes; sl; sl = sl->next)
if (!strcmp (sl->d, address)) if (sl->mbox && !strcmp (sl->mbox, address))
break; break;
if (!sl) if (!sl)
{ {
@ -1565,7 +1569,7 @@ command_receive_cb (void *opaque, const char *mediatype,
} }
xfree (ctx.fpr); xfree (ctx.fpr);
free_strlist (ctx.mboxes); free_uidinfo_list (ctx.mboxes);
return err; return err;
} }

View File

@ -69,11 +69,23 @@ struct policy_flags_s
typedef struct policy_flags_s *policy_flags_t; 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 --*/ /*-- wks-util.c --*/
void wks_set_status_fd (int fd); void wks_set_status_fd (int fd);
void wks_write_status (int no, const char *format, ...) GPGRT_ATTR_PRINTF(2,3); 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_send_mime (mime_maker_t mime);
gpg_error_t wks_parse_policy (policy_flags_t flags, estream_t stream, gpg_error_t wks_parse_policy (policy_flags_t flags, estream_t stream,
int ignore_unknown); int ignore_unknown);

View File

@ -89,6 +89,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. */ /* Helper for wks_list_key. */
static void static void
@ -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 * 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. */ * is stored at R_FPR and R_MBOXES and an error code is returned. */
gpg_error_t 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; gpg_error_t err;
ccparray_t ccp; ccparray_t ccp;
@ -118,9 +160,8 @@ wks_list_key (estream_t key, char **r_fpr, strlist_t *r_mboxes)
char **fields = NULL; char **fields = NULL;
int nfields; int nfields;
int lnr; int lnr;
char *mbox = NULL;
char *fpr = NULL; char *fpr = NULL;
strlist_t mboxes = NULL; uidinfo_list_t mboxes = NULL;
*r_fpr = NULL; *r_fpr = NULL;
*r_mboxes = 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) else if (!strcmp (fields[0], "uid") && nfields > 9)
{ {
/* Fixme: Unescape fields[9] */ /* Fixme: Unescape fields[9] */
xfree (mbox); if (!append_to_uidinfo_list (&mboxes, fields[9]))
mbox = mailbox_from_userid (fields[9]);
if (mbox && !append_to_strlist_try (&mboxes, mbox))
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
goto leave; goto leave;
@ -255,8 +294,7 @@ wks_list_key (estream_t key, char **r_fpr, strlist_t *r_mboxes)
leave: leave:
xfree (fpr); xfree (fpr);
xfree (mboxes); free_uidinfo_list (mboxes);
xfree (mbox);
xfree (fields); xfree (fields);
es_free (line); es_free (line);
xfree (argv); xfree (argv);