1 /* wks-utils.c - Common helper functions for wks tools
2 * Copyright (C) 2016 g10 Code GmbH
3 * Copyright (C) 2016 Bundesamt für Sicherheit in der Informationstechnik
5 * This file is part of GnuPG.
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
22 #include <sys/types.h>
26 #include "../common/util.h"
27 #include "../common/status.h"
28 #include "../common/ccparray.h"
29 #include "../common/exectool.h"
30 #include "../common/zb32.h"
31 #include "../common/userids.h"
32 #include "../common/mbox-util.h"
33 #include "../common/sysutils.h"
34 #include "mime-maker.h"
35 #include "send-mail.h"
38 /* The stream to output the status information. Output is disabled if
40 static estream_t statusfp;
44 /* Set the status FD. */
46 wks_set_status_fd (int fd)
48 static int last_fd = -1;
50 if (fd != -1 && last_fd == fd)
53 if (statusfp && statusfp != es_stdout && statusfp != es_stderr)
64 statusfp = es_fdopen (fd, "w");
67 log_fatal ("can't open fd %d for status output: %s\n",
68 fd, gpg_strerror (gpg_error_from_syserror ()));
74 /* Write a status line with code NO followed by the outout of the
75 * printf style FORMAT. The caller needs to make sure that LFs and
76 * CRs are not printed. */
78 wks_write_status (int no, const char *format, ...)
83 return; /* Not enabled. */
85 es_fputs ("[GNUPG:] ", statusfp);
86 es_fputs (get_status_string (no), statusfp);
89 es_putc (' ', statusfp);
90 va_start (arg_ptr, format);
91 es_vfprintf (statusfp, format, arg_ptr);
94 es_putc ('\n', statusfp);
100 /* Append UID to LIST and return the new item. On success LIST is
101 * updated. C-style escaping is removed from UID. On error ERRNO is
102 * set and NULL returned. */
103 static uidinfo_list_t
104 append_to_uidinfo_list (uidinfo_list_t *list, const char *uid, time_t created)
106 uidinfo_list_t r, sl;
109 plainuid = decode_c_string (uid);
113 sl = xtrymalloc (sizeof *sl + strlen (plainuid));
120 strcpy (sl->uid, plainuid);
121 sl->created = created;
122 sl->mbox = mailbox_from_userid (plainuid);
128 for (r = *list; r->next; r = r->next )
138 /* Free the list of uid infos at LIST. */
140 free_uidinfo_list (uidinfo_list_t list)
144 uidinfo_list_t tmp = list->next;
153 struct get_key_status_parm_s
162 get_key_status_cb (void *opaque, const char *keyword, char *args)
164 struct get_key_status_parm_s *parm = opaque;
166 /*log_debug ("%s: %s\n", keyword, args);*/
167 if (!strcmp (keyword, "EXPORTED"))
170 if (!ascii_strcasecmp (args, parm->fpr))
175 /* Get a key by fingerprint from gpg's keyring and make sure that the
176 * mail address ADDRSPEC is included in the key. If EXACT is set the
177 * returned user id must match Addrspec exactly and not just in the
178 * addr-spec (mailbox) part. The key is returned as a new memory
179 * stream at R_KEY. */
181 wks_get_key (estream_t *r_key, const char *fingerprint, const char *addrspec,
186 const char **argv = NULL;
187 estream_t key = NULL;
188 struct get_key_status_parm_s parm;
189 char *filterexp = NULL;
191 memset (&parm, 0, sizeof parm);
195 key = es_fopenmem (0, "w+b");
198 err = gpg_error_from_syserror ();
199 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
203 /* Prefix the key with the MIME content type. */
204 es_fputs ("Content-Type: application/pgp-keys\n"
207 filterexp = es_bsprintf ("keep-uid=%s= %s", exact? "uid":"mbox", addrspec);
210 err = gpg_error_from_syserror ();
211 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
215 ccparray_init (&ccp, 0);
217 ccparray_put (&ccp, "--no-options");
219 ccparray_put (&ccp, "--quiet");
220 else if (opt.verbose > 1)
221 ccparray_put (&ccp, "--verbose");
222 ccparray_put (&ccp, "--batch");
223 ccparray_put (&ccp, "--status-fd=2");
224 ccparray_put (&ccp, "--always-trust");
225 ccparray_put (&ccp, "--armor");
226 ccparray_put (&ccp, "--export-options=export-minimal");
227 ccparray_put (&ccp, "--export-filter");
228 ccparray_put (&ccp, filterexp);
229 ccparray_put (&ccp, "--export");
230 ccparray_put (&ccp, "--");
231 ccparray_put (&ccp, fingerprint);
233 ccparray_put (&ccp, NULL);
234 argv = ccparray_get (&ccp, NULL);
237 err = gpg_error_from_syserror ();
240 parm.fpr = fingerprint;
241 err = gnupg_exec_tool_stream (opt.gpg_program, argv, NULL,
243 get_key_status_cb, &parm);
244 if (!err && parm.count > 1)
245 err = gpg_error (GPG_ERR_TOO_MANY);
246 else if (!err && !parm.found)
247 err = gpg_error (GPG_ERR_NOT_FOUND);
250 log_error ("export failed: %s\n", gpg_strerror (err));
267 /* Helper for wks_list_key and wks_filter_uid. */
269 key_status_cb (void *opaque, const char *keyword, char *args)
274 log_debug ("gpg status: %s %s\n", keyword, args);
278 /* Run gpg on KEY and store the primary fingerprint at R_FPR and the
279 * list of mailboxes at R_MBOXES. Returns 0 on success; on error NULL
280 * is stored at R_FPR and R_MBOXES and an error code is returned.
281 * R_FPR may be NULL if the fingerprint is not needed. */
283 wks_list_key (estream_t key, char **r_fpr, uidinfo_list_t *r_mboxes)
290 size_t length_of_line = 0;
293 char **fields = NULL;
297 uidinfo_list_t mboxes = NULL;
303 /* Open a memory stream. */
304 listing = es_fopenmem (0, "w+b");
307 err = gpg_error_from_syserror ();
308 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
312 ccparray_init (&ccp, 0);
314 ccparray_put (&ccp, "--no-options");
316 ccparray_put (&ccp, "--quiet");
317 else if (opt.verbose > 1)
318 ccparray_put (&ccp, "--verbose");
319 ccparray_put (&ccp, "--batch");
320 ccparray_put (&ccp, "--status-fd=2");
321 ccparray_put (&ccp, "--always-trust");
322 ccparray_put (&ccp, "--with-colons");
323 ccparray_put (&ccp, "--dry-run");
324 ccparray_put (&ccp, "--import-options=import-minimal,import-show");
325 ccparray_put (&ccp, "--import");
327 ccparray_put (&ccp, NULL);
328 argv = ccparray_get (&ccp, NULL);
331 err = gpg_error_from_syserror ();
334 err = gnupg_exec_tool_stream (opt.gpg_program, argv, key,
336 key_status_cb, NULL);
339 log_error ("import failed: %s\n", gpg_strerror (err));
345 maxlen = 2048; /* Set limit. */
346 while ((len = es_read_line (listing, &line, &length_of_line, &maxlen)) > 0)
351 log_error ("received line too long\n");
352 err = gpg_error (GPG_ERR_LINE_TOO_LONG);
355 /* Strip newline and carriage return, if present. */
357 && (line[len - 1] == '\n' || line[len - 1] == '\r'))
359 /* log_debug ("line '%s'\n", line); */
362 fields = strtokenize_nt (line, ":");
365 err = gpg_error_from_syserror ();
366 log_error ("strtokenize failed: %s\n", gpg_strerror (err));
369 for (nfields = 0; fields[nfields]; nfields++)
373 err = gpg_error (GPG_ERR_INV_ENGINE);
376 if (!strcmp (fields[0], "sec"))
378 /* gpg may return "sec" as the first record - but we do not
379 * accept secret keys. */
380 err = gpg_error (GPG_ERR_NO_PUBKEY);
383 if (lnr == 1 && strcmp (fields[0], "pub"))
385 /* First record is not a public key. */
386 err = gpg_error (GPG_ERR_INV_ENGINE);
389 if (lnr > 1 && !strcmp (fields[0], "pub"))
391 /* More than one public key. */
392 err = gpg_error (GPG_ERR_TOO_MANY);
395 if (!strcmp (fields[0], "sub") || !strcmp (fields[0], "ssb"))
396 break; /* We can stop parsing here. */
398 if (!strcmp (fields[0], "fpr") && nfields > 9 && !fpr)
400 fpr = xtrystrdup (fields[9]);
403 err = gpg_error_from_syserror ();
407 else if (!strcmp (fields[0], "uid") && nfields > 9)
409 if (!append_to_uidinfo_list (&mboxes, fields[9],
410 parse_timestamp (fields[5], NULL)))
412 err = gpg_error_from_syserror ();
417 if (len < 0 || es_ferror (listing))
419 err = gpg_error_from_syserror ();
420 log_error ("error reading memory stream\n");
426 err = gpg_error (GPG_ERR_NO_PUBKEY);
440 free_uidinfo_list (mboxes);
449 /* Run gpg as a filter on KEY and write the output to a new stream
450 * stored at R_NEWKEY. The new key will contain only the user id UID.
451 * Returns 0 on success. Only one key is expected in KEY. If BINARY
452 * is set the resulting key is returned as a binary (non-armored)
455 wks_filter_uid (estream_t *r_newkey, estream_t key, const char *uid,
460 const char **argv = NULL;
462 char *filterexp = NULL;
466 /* Open a memory stream. */
467 newkey = es_fopenmem (0, "w+b");
470 err = gpg_error_from_syserror ();
471 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
475 /* Prefix the key with the MIME content type. */
477 es_fputs ("Content-Type: application/pgp-keys\n"
480 filterexp = es_bsprintf ("keep-uid=-t uid= %s", uid);
483 err = gpg_error_from_syserror ();
484 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
488 ccparray_init (&ccp, 0);
490 ccparray_put (&ccp, "--no-options");
492 ccparray_put (&ccp, "--quiet");
493 else if (opt.verbose > 1)
494 ccparray_put (&ccp, "--verbose");
495 ccparray_put (&ccp, "--batch");
496 ccparray_put (&ccp, "--status-fd=2");
497 ccparray_put (&ccp, "--always-trust");
499 ccparray_put (&ccp, "--armor");
500 ccparray_put (&ccp, "--import-options=import-export");
501 ccparray_put (&ccp, "--import-filter");
502 ccparray_put (&ccp, filterexp);
503 ccparray_put (&ccp, "--import");
505 ccparray_put (&ccp, NULL);
506 argv = ccparray_get (&ccp, NULL);
509 err = gpg_error_from_syserror ();
512 err = gnupg_exec_tool_stream (opt.gpg_program, argv, key,
514 key_status_cb, NULL);
517 log_error ("import/export failed: %s\n", gpg_strerror (err));
533 /* Helper to write mail to the output(s). */
535 wks_send_mime (mime_maker_t mime)
540 /* Without any option we take a short path. */
541 if (!opt.use_sendmail && !opt.output)
543 es_set_binary (es_stdout);
544 return mime_maker_make (mime, es_stdout);
548 mail = es_fopenmem (0, "w+b");
551 err = gpg_error_from_syserror ();
555 err = mime_maker_make (mime, mail);
557 if (!err && opt.output)
560 err = send_mail_to_file (mail, opt.output);
563 if (!err && opt.use_sendmail)
566 err = send_mail (mail);
574 /* Parse the policy flags by reading them from STREAM and storing them
575 * into FLAGS. If IGNORE_UNKNOWN is set unknown keywords are
578 wks_parse_policy (policy_flags_t flags, estream_t stream, int ignore_unknown)
581 TOK_SUBMISSION_ADDRESS,
592 { "submission-address", TOK_SUBMISSION_ADDRESS },
593 { "mailbox-only", TOK_MAILBOX_ONLY },
594 { "dane-only", TOK_DANE_ONLY },
595 { "auth-submit", TOK_AUTH_SUBMIT },
596 { "max-pending", TOK_MAX_PENDING },
597 { "protocol-version", TOK_PROTOCOL_VERSION }
602 char *p, *keyword, *value;
605 memset (flags, 0, sizeof *flags);
607 while (es_fgets (line, DIM(line)-1, stream) )
611 if (!n || line[n-1] != '\n')
613 err = gpg_error (*line? GPG_ERR_LINE_TOO_LONG
614 : GPG_ERR_INCOMPLETE_LINE);
617 trim_trailing_spaces (line);
618 /* Skip empty and comment lines. */
619 for (p=line; spacep (p); p++)
621 if (!*p || *p == '#')
626 err = gpg_error (GPG_ERR_SYNTAX);
632 if ((p = strchr (p, ':')))
634 /* Colon found: Keyword with value. */
636 for (; spacep (p); p++)
640 err = gpg_error (GPG_ERR_MISSING_VALUE);
646 for (i=0; i < DIM (keywords); i++)
647 if (!ascii_strcasecmp (keywords[i].name, keyword))
649 if (!(i < DIM (keywords)))
653 err = gpg_error (GPG_ERR_INV_NAME);
657 switch (keywords[i].token)
659 case TOK_SUBMISSION_ADDRESS:
660 if (!value || !*value)
662 err = gpg_error (GPG_ERR_SYNTAX);
665 xfree (flags->submission_address);
666 flags->submission_address = xtrystrdup (value);
667 if (!flags->submission_address)
669 err = gpg_error_from_syserror ();
673 case TOK_MAILBOX_ONLY: flags->mailbox_only = 1; break;
674 case TOK_DANE_ONLY: flags->dane_only = 1; break;
675 case TOK_AUTH_SUBMIT: flags->auth_submit = 1; break;
676 case TOK_MAX_PENDING:
679 err = gpg_error (GPG_ERR_SYNTAX);
682 /* FIXME: Define whether these are seconds, hours, or days
683 * and decide whether to allow other units. */
684 flags->max_pending = atoi (value);
686 case TOK_PROTOCOL_VERSION:
689 err = gpg_error (GPG_ERR_SYNTAX);
692 flags->protocol_version = atoi (value);
697 if (!err && !es_feof (stream))
698 err = gpg_error_from_syserror ();
702 log_error ("error reading '%s', line %d: %s\n",
703 es_fname_get (stream), lnr, gpg_strerror (err));
710 wks_free_policy (policy_flags_t policy)
714 xfree (policy->submission_address);
715 memset (policy, 0, sizeof *policy);
720 /* Write the content of SRC to the new file FNAME. */
722 write_to_file (estream_t src, const char *fname)
727 size_t nread, written;
729 dst = es_fopen (fname, "wb");
731 return gpg_error_from_syserror ();
735 nread = es_fread (buffer, 1, sizeof buffer, src);
738 written = es_fwrite (buffer, 1, nread, dst);
739 if (written != nread)
742 while (!es_feof (src) && !es_ferror (src) && !es_ferror (dst));
743 if (!es_feof (src) || es_ferror (src) || es_ferror (dst))
745 err = gpg_error_from_syserror ();
747 gnupg_remove (fname);
753 err = gpg_error_from_syserror ();
754 log_error ("error closing '%s': %s\n", fname, gpg_strerror (err));
762 /* Return the filename and optionally the addrspec for USERID at
763 * R_FNAME and R_ADDRSPEC. R_ADDRSPEC might also be set on error. If
764 * HASH_ONLY is set only the has is returned at R_FNAME and no file is
767 wks_fname_from_userid (const char *userid, int hash_only,
768 char **r_fname, char **r_addrspec)
771 char *addrspec = NULL;
775 char shaxbuf[32]; /* Used for SHA-1 and SHA-256 */
781 addrspec = mailbox_from_userid (userid);
784 if (opt.verbose || hash_only)
785 log_info ("\"%s\" is not a proper mail address\n", userid);
786 err = gpg_error (GPG_ERR_INV_USER_ID);
790 domain = strchr (addrspec, '@');
794 /* Hash user ID and create filename. */
795 s = strchr (addrspec, '@');
797 gcry_md_hash_buffer (GCRY_MD_SHA1, shaxbuf, addrspec, s - addrspec);
798 hash = zb32_encode (shaxbuf, 8*20);
801 err = gpg_error_from_syserror ();
813 *r_fname = make_filename_try (opt.directory, domain, "hu", hash, NULL);
815 err = gpg_error_from_syserror ();
821 if (r_addrspec && addrspec)
822 *r_addrspec = addrspec;
830 /* Compute the the full file name for the key with ADDRSPEC and return
833 wks_compute_hu_fname (char **r_fname, const char *addrspec)
844 domain = strchr (addrspec, '@');
845 if (!domain || !domain[1] || domain == addrspec)
846 return gpg_error (GPG_ERR_INV_ARG);
849 gcry_md_hash_buffer (GCRY_MD_SHA1, sha1buf, addrspec, domain - addrspec - 1);
850 hash = zb32_encode (sha1buf, 8*20);
852 return gpg_error_from_syserror ();
854 /* Try to create missing directories below opt.directory. */
855 fname = make_filename_try (opt.directory, domain, NULL);
856 if (fname && gnupg_stat (fname, &sb)
857 && gpg_err_code_from_syserror () == GPG_ERR_ENOENT)
858 if (!gnupg_mkdir (fname, "-rwxr-xr-x") && opt.verbose)
859 log_info ("directory '%s' created\n", fname);
861 fname = make_filename_try (opt.directory, domain, "hu", NULL);
862 if (fname && gnupg_stat (fname, &sb)
863 && gpg_err_code_from_syserror () == GPG_ERR_ENOENT)
864 if (!gnupg_mkdir (fname, "-rwxr-xr-x") && opt.verbose)
865 log_info ("directory '%s' created\n", fname);
868 /* Create the filename. */
869 fname = make_filename_try (opt.directory, domain, "hu", hash, NULL);
870 err = fname? 0 : gpg_error_from_syserror ();
875 *r_fname = fname; /* Okay. */
881 /* Make sure that a policy file exists for addrspec. Directories must
884 ensure_policy_file (const char *addrspec)
892 domain = strchr (addrspec, '@');
893 if (!domain || !domain[1] || domain == addrspec)
894 return gpg_error (GPG_ERR_INV_ARG);
897 /* Create the filename. */
898 fname = make_filename_try (opt.directory, domain, "policy", NULL);
899 err = fname? 0 : gpg_error_from_syserror ();
903 /* First a quick check whether it already exists. */
904 if (!(ec = gnupg_access (fname, F_OK)))
906 err = 0; /* File already exists. */
909 err = gpg_error (ec);
910 if (gpg_err_code (err) == GPG_ERR_ENOENT)
914 log_error ("domain %s: problem with '%s': %s\n",
915 domain, fname, gpg_strerror (err));
919 /* Now create the file. */
920 fp = es_fopen (fname, "wxb");
923 err = gpg_error_from_syserror ();
924 if (gpg_err_code (err) == GPG_ERR_EEXIST)
925 err = 0; /* Was created between the gnupg_access() and es_fopen(). */
927 log_error ("domain %s: error creating '%s': %s\n",
928 domain, fname, gpg_strerror (err));
932 es_fprintf (fp, "# Policy flags for domain %s\n", domain);
933 if (es_ferror (fp) || es_fclose (fp))
935 err = gpg_error_from_syserror ();
936 log_error ("error writing '%s': %s\n", fname, gpg_strerror (err));
941 log_info ("policy file '%s' created\n", fname);
943 /* Make sure the policy file world readable. */
944 if (gnupg_chmod (fname, "-rw-r--r--"))
946 err = gpg_error_from_syserror ();
947 log_error ("can't set permissions of '%s': %s\n",
948 fname, gpg_strerror (err));
958 /* Helper form wks_cmd_install_key. */
960 install_key_from_spec_file (const char *fname)
966 size_t maxlen = 2048;
968 unsigned int lnr = 0;
970 if (!fname || !strcmp (fname, ""))
973 fp = es_fopen (fname, "rb");
976 err = gpg_error_from_syserror ();
977 log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
981 while (es_read_line (fp, &line, &linelen, &maxlen) > 0)
985 err = gpg_error (GPG_ERR_LINE_TOO_LONG);
986 log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
991 if (!*line || *line == '#')
993 if (split_fields (line, fields, DIM(fields)) < 2)
995 log_error ("error reading '%s': syntax error at line %u\n",
999 err = wks_cmd_install_key (fields[0], fields[1]);
1005 err = gpg_error_from_syserror ();
1006 log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
1018 /* Install a single key into the WKD by reading FNAME and extracting
1019 * USERID. If USERID is NULL FNAME is expected to be a list of fpr
1020 * mbox lines and for each line the respective key will be
1023 wks_cmd_install_key (const char *fname, const char *userid)
1026 KEYDB_SEARCH_DESC desc;
1027 estream_t fp = NULL;
1028 char *addrspec = NULL;
1030 uidinfo_list_t uidlist = NULL;
1031 uidinfo_list_t uid, thisuid;
1033 char *huname = NULL;
1037 return install_key_from_spec_file (fname);
1039 addrspec = mailbox_from_userid (userid);
1042 log_error ("\"%s\" is not a proper mail address\n", userid);
1043 err = gpg_error (GPG_ERR_INV_USER_ID);
1047 if (!classify_user_id (fname, &desc, 1)
1048 && (desc.mode == KEYDB_SEARCH_MODE_FPR
1049 || desc.mode == KEYDB_SEARCH_MODE_FPR20))
1051 /* FNAME looks like a fingerprint. Get the key from the
1052 * standard keyring. */
1053 err = wks_get_key (&fp, fname, addrspec, 0);
1056 log_error ("error getting key '%s' (uid='%s'): %s\n",
1057 fname, addrspec, gpg_strerror (err));
1061 else /* Take it from the file */
1063 fp = es_fopen (fname, "rb");
1066 err = gpg_error_from_syserror ();
1067 log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
1072 /* List the key so that we can figure out the newest UID with the
1073 * requested addrspec. */
1074 err = wks_list_key (fp, &fpr, &uidlist);
1077 log_error ("error parsing key: %s\n", gpg_strerror (err));
1078 err = gpg_error (GPG_ERR_NO_PUBKEY);
1084 for (uid = uidlist; uid; uid = uid->next)
1087 continue; /* Should not happen anyway. */
1088 if (ascii_strcasecmp (uid->mbox, addrspec))
1089 continue; /* Not the requested addrspec. */
1091 if (uid->created > thistime)
1093 thistime = uid->created;
1098 thisuid = uidlist; /* This is the case for a missing timestamp. */
1101 log_error ("public key in '%s' has no mail address '%s'\n",
1103 err = gpg_error (GPG_ERR_INV_USER_ID);
1108 log_info ("using key with user id '%s'\n", thisuid->uid);
1114 err = wks_filter_uid (&fp2, fp, thisuid->uid, 1);
1117 log_error ("error filtering key: %s\n", gpg_strerror (err));
1118 err = gpg_error (GPG_ERR_NO_PUBKEY);
1125 /* Hash user ID and create filename. */
1126 err = wks_compute_hu_fname (&huname, addrspec);
1130 /* Now that wks_compute_hu_fname has created missing directories we
1131 * can create a policy file if it does not exist. */
1132 err = ensure_policy_file (addrspec);
1137 err = write_to_file (fp, huname);
1140 log_error ("copying key to '%s' failed: %s\n", huname,gpg_strerror (err));
1144 /* Make sure it is world readable. */
1145 if (gnupg_chmod (huname, "-rw-r--r--"))
1146 log_error ("can't set permissions of '%s': %s\n",
1147 huname, gpg_strerror (gpg_err_code_from_syserror()));
1150 log_info ("key %s published for '%s'\n", fpr, addrspec);
1155 free_uidinfo_list (uidlist);
1163 /* Remove the key with mail address in USERID. */
1165 wks_cmd_remove_key (const char *userid)
1168 char *addrspec = NULL;
1171 err = wks_fname_from_userid (userid, 0, &fname, &addrspec);
1175 if (gnupg_remove (fname))
1177 err = gpg_error_from_syserror ();
1178 if (gpg_err_code (err) == GPG_ERR_ENOENT)
1181 log_info ("key for '%s' is not installed\n", addrspec);
1182 log_inc_errorcount ();
1186 log_error ("error removing '%s': %s\n", fname, gpg_strerror (err));
1191 log_info ("key for '%s' removed\n", addrspec);
1201 /* Print the WKD hash for the user id to stdout. */
1203 wks_cmd_print_wkd_hash (const char *userid)
1206 char *addrspec, *fname;
1208 err = wks_fname_from_userid (userid, 1, &fname, &addrspec);
1212 es_printf ("%s %s\n", fname, addrspec);
1220 /* Print the WKD URL for the user id to stdout. */
1222 wks_cmd_print_wkd_url (const char *userid)
1225 char *addrspec, *fname;
1228 err = wks_fname_from_userid (userid, 1, &fname, &addrspec);
1232 domain = strchr (addrspec, '@');
1236 es_printf ("https://openpgpkey.%s/.well-known/openpgpkey/%s/hu/%s?l=%s\n",
1237 domain, domain, fname, addrspec);