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. On error ERRNO is set and NULL returned. */
102 static uidinfo_list_t
103 append_to_uidinfo_list (uidinfo_list_t *list, const char *uid, time_t created)
105 uidinfo_list_t r, sl;
107 sl = xtrymalloc (sizeof *sl + strlen (uid));
111 strcpy (sl->uid, uid);
112 sl->created = created;
113 sl->mbox = mailbox_from_userid (uid);
119 for (r = *list; r->next; r = r->next )
127 /* Free the list of uid infos at LIST. */
129 free_uidinfo_list (uidinfo_list_t list)
133 uidinfo_list_t tmp = list->next;
142 struct get_key_status_parm_s
151 get_key_status_cb (void *opaque, const char *keyword, char *args)
153 struct get_key_status_parm_s *parm = opaque;
155 /*log_debug ("%s: %s\n", keyword, args);*/
156 if (!strcmp (keyword, "EXPORTED"))
159 if (!ascii_strcasecmp (args, parm->fpr))
164 /* Get a key by fingerprint from gpg's keyring and make sure that the
165 * mail address ADDRSPEC is included in the key. If EXACT is set the
166 * returned user id must match Addrspec exactly and not just in the
167 * addr-spec (mailbox) part. The key is returned as a new memory
168 * stream at R_KEY. */
170 wks_get_key (estream_t *r_key, const char *fingerprint, const char *addrspec,
175 const char **argv = NULL;
176 estream_t key = NULL;
177 struct get_key_status_parm_s parm;
178 char *filterexp = NULL;
180 memset (&parm, 0, sizeof parm);
184 key = es_fopenmem (0, "w+b");
187 err = gpg_error_from_syserror ();
188 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
192 /* Prefix the key with the MIME content type. */
193 es_fputs ("Content-Type: application/pgp-keys\n"
196 filterexp = es_bsprintf ("keep-uid=%s= %s", exact? "uid":"mbox", addrspec);
199 err = gpg_error_from_syserror ();
200 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
204 ccparray_init (&ccp, 0);
206 ccparray_put (&ccp, "--no-options");
208 ccparray_put (&ccp, "--quiet");
209 else if (opt.verbose > 1)
210 ccparray_put (&ccp, "--verbose");
211 ccparray_put (&ccp, "--batch");
212 ccparray_put (&ccp, "--status-fd=2");
213 ccparray_put (&ccp, "--always-trust");
214 ccparray_put (&ccp, "--armor");
215 ccparray_put (&ccp, "--export-options=export-minimal");
216 ccparray_put (&ccp, "--export-filter");
217 ccparray_put (&ccp, filterexp);
218 ccparray_put (&ccp, "--export");
219 ccparray_put (&ccp, "--");
220 ccparray_put (&ccp, fingerprint);
222 ccparray_put (&ccp, NULL);
223 argv = ccparray_get (&ccp, NULL);
226 err = gpg_error_from_syserror ();
229 parm.fpr = fingerprint;
230 err = gnupg_exec_tool_stream (opt.gpg_program, argv, NULL,
232 get_key_status_cb, &parm);
233 if (!err && parm.count > 1)
234 err = gpg_error (GPG_ERR_TOO_MANY);
235 else if (!err && !parm.found)
236 err = gpg_error (GPG_ERR_NOT_FOUND);
239 log_error ("export failed: %s\n", gpg_strerror (err));
256 /* Helper for wks_list_key and wks_filter_uid. */
258 key_status_cb (void *opaque, const char *keyword, char *args)
263 log_debug ("gpg status: %s %s\n", keyword, args);
267 /* Run gpg on KEY and store the primary fingerprint at R_FPR and the
268 * list of mailboxes at R_MBOXES. Returns 0 on success; on error NULL
269 * is stored at R_FPR and R_MBOXES and an error code is returned.
270 * R_FPR may be NULL if the fingerprint is not needed. */
272 wks_list_key (estream_t key, char **r_fpr, uidinfo_list_t *r_mboxes)
279 size_t length_of_line = 0;
282 char **fields = NULL;
286 uidinfo_list_t mboxes = NULL;
292 /* Open a memory stream. */
293 listing = es_fopenmem (0, "w+b");
296 err = gpg_error_from_syserror ();
297 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
301 ccparray_init (&ccp, 0);
303 ccparray_put (&ccp, "--no-options");
305 ccparray_put (&ccp, "--quiet");
306 else if (opt.verbose > 1)
307 ccparray_put (&ccp, "--verbose");
308 ccparray_put (&ccp, "--batch");
309 ccparray_put (&ccp, "--status-fd=2");
310 ccparray_put (&ccp, "--always-trust");
311 ccparray_put (&ccp, "--with-colons");
312 ccparray_put (&ccp, "--dry-run");
313 ccparray_put (&ccp, "--import-options=import-minimal,import-show");
314 ccparray_put (&ccp, "--import");
316 ccparray_put (&ccp, NULL);
317 argv = ccparray_get (&ccp, NULL);
320 err = gpg_error_from_syserror ();
323 err = gnupg_exec_tool_stream (opt.gpg_program, argv, key,
325 key_status_cb, NULL);
328 log_error ("import failed: %s\n", gpg_strerror (err));
334 maxlen = 2048; /* Set limit. */
335 while ((len = es_read_line (listing, &line, &length_of_line, &maxlen)) > 0)
340 log_error ("received line too long\n");
341 err = gpg_error (GPG_ERR_LINE_TOO_LONG);
344 /* Strip newline and carriage return, if present. */
346 && (line[len - 1] == '\n' || line[len - 1] == '\r'))
348 /* log_debug ("line '%s'\n", line); */
351 fields = strtokenize (line, ":");
354 err = gpg_error_from_syserror ();
355 log_error ("strtokenize failed: %s\n", gpg_strerror (err));
358 for (nfields = 0; fields[nfields]; nfields++)
362 err = gpg_error (GPG_ERR_INV_ENGINE);
365 if (!strcmp (fields[0], "sec"))
367 /* gpg may return "sec" as the first record - but we do not
368 * accept secret keys. */
369 err = gpg_error (GPG_ERR_NO_PUBKEY);
372 if (lnr == 1 && strcmp (fields[0], "pub"))
374 /* First record is not a public key. */
375 err = gpg_error (GPG_ERR_INV_ENGINE);
378 if (lnr > 1 && !strcmp (fields[0], "pub"))
380 /* More than one public key. */
381 err = gpg_error (GPG_ERR_TOO_MANY);
384 if (!strcmp (fields[0], "sub") || !strcmp (fields[0], "ssb"))
385 break; /* We can stop parsing here. */
387 if (!strcmp (fields[0], "fpr") && nfields > 9 && !fpr)
389 fpr = xtrystrdup (fields[9]);
392 err = gpg_error_from_syserror ();
396 else if (!strcmp (fields[0], "uid") && nfields > 9)
398 /* Fixme: Unescape fields[9] */
399 if (!append_to_uidinfo_list (&mboxes, fields[9],
400 parse_timestamp (fields[5], NULL)))
402 err = gpg_error_from_syserror ();
407 if (len < 0 || es_ferror (listing))
409 err = gpg_error_from_syserror ();
410 log_error ("error reading memory stream\n");
416 err = gpg_error (GPG_ERR_NO_PUBKEY);
430 free_uidinfo_list (mboxes);
439 /* Run gpg as a filter on KEY and write the output to a new stream
440 * stored at R_NEWKEY. The new key will contain only the user id UID.
441 * Returns 0 on success. Only one key is expected in KEY. If BINARY
442 * is set the resulting key is returned as a binary (non-armored)
445 wks_filter_uid (estream_t *r_newkey, estream_t key, const char *uid,
450 const char **argv = NULL;
452 char *filterexp = NULL;
456 /* Open a memory stream. */
457 newkey = es_fopenmem (0, "w+b");
460 err = gpg_error_from_syserror ();
461 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
465 /* Prefix the key with the MIME content type. */
467 es_fputs ("Content-Type: application/pgp-keys\n"
470 filterexp = es_bsprintf ("keep-uid=uid= %s", uid);
473 err = gpg_error_from_syserror ();
474 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
478 ccparray_init (&ccp, 0);
480 ccparray_put (&ccp, "--no-options");
482 ccparray_put (&ccp, "--quiet");
483 else if (opt.verbose > 1)
484 ccparray_put (&ccp, "--verbose");
485 ccparray_put (&ccp, "--batch");
486 ccparray_put (&ccp, "--status-fd=2");
487 ccparray_put (&ccp, "--always-trust");
489 ccparray_put (&ccp, "--armor");
490 ccparray_put (&ccp, "--import-options=import-export");
491 ccparray_put (&ccp, "--import-filter");
492 ccparray_put (&ccp, filterexp);
493 ccparray_put (&ccp, "--import");
495 ccparray_put (&ccp, NULL);
496 argv = ccparray_get (&ccp, NULL);
499 err = gpg_error_from_syserror ();
502 err = gnupg_exec_tool_stream (opt.gpg_program, argv, key,
504 key_status_cb, NULL);
507 log_error ("import/export failed: %s\n", gpg_strerror (err));
523 /* Helper to write mail to the output(s). */
525 wks_send_mime (mime_maker_t mime)
530 /* Without any option we take a short path. */
531 if (!opt.use_sendmail && !opt.output)
533 es_set_binary (es_stdout);
534 return mime_maker_make (mime, es_stdout);
538 mail = es_fopenmem (0, "w+b");
541 err = gpg_error_from_syserror ();
545 err = mime_maker_make (mime, mail);
547 if (!err && opt.output)
550 err = send_mail_to_file (mail, opt.output);
553 if (!err && opt.use_sendmail)
556 err = send_mail (mail);
564 /* Parse the policy flags by reading them from STREAM and storing them
565 * into FLAGS. If IGNORE_UNKNOWN is set unknown keywords are
568 wks_parse_policy (policy_flags_t flags, estream_t stream, int ignore_unknown)
571 TOK_SUBMISSION_ADDRESS,
582 { "submission-address", TOK_SUBMISSION_ADDRESS },
583 { "mailbox-only", TOK_MAILBOX_ONLY },
584 { "dane-only", TOK_DANE_ONLY },
585 { "auth-submit", TOK_AUTH_SUBMIT },
586 { "max-pending", TOK_MAX_PENDING },
587 { "protocol-version", TOK_PROTOCOL_VERSION }
592 char *p, *keyword, *value;
595 memset (flags, 0, sizeof *flags);
597 while (es_fgets (line, DIM(line)-1, stream) )
601 if (!n || line[n-1] != '\n')
603 err = gpg_error (*line? GPG_ERR_LINE_TOO_LONG
604 : GPG_ERR_INCOMPLETE_LINE);
607 trim_trailing_spaces (line);
608 /* Skip empty and comment lines. */
609 for (p=line; spacep (p); p++)
611 if (!*p || *p == '#')
616 err = gpg_error (GPG_ERR_SYNTAX);
622 if ((p = strchr (p, ':')))
624 /* Colon found: Keyword with value. */
626 for (; spacep (p); p++)
630 err = gpg_error (GPG_ERR_MISSING_VALUE);
636 for (i=0; i < DIM (keywords); i++)
637 if (!ascii_strcasecmp (keywords[i].name, keyword))
639 if (!(i < DIM (keywords)))
643 err = gpg_error (GPG_ERR_INV_NAME);
647 switch (keywords[i].token)
649 case TOK_SUBMISSION_ADDRESS:
650 if (!value || !*value)
652 err = gpg_error (GPG_ERR_SYNTAX);
655 xfree (flags->submission_address);
656 flags->submission_address = xtrystrdup (value);
657 if (!flags->submission_address)
659 err = gpg_error_from_syserror ();
663 case TOK_MAILBOX_ONLY: flags->mailbox_only = 1; break;
664 case TOK_DANE_ONLY: flags->dane_only = 1; break;
665 case TOK_AUTH_SUBMIT: flags->auth_submit = 1; break;
666 case TOK_MAX_PENDING:
669 err = gpg_error (GPG_ERR_SYNTAX);
672 /* FIXME: Define whether these are seconds, hours, or days
673 * and decide whether to allow other units. */
674 flags->max_pending = atoi (value);
676 case TOK_PROTOCOL_VERSION:
679 err = gpg_error (GPG_ERR_SYNTAX);
682 flags->protocol_version = atoi (value);
687 if (!err && !es_feof (stream))
688 err = gpg_error_from_syserror ();
692 log_error ("error reading '%s', line %d: %s\n",
693 es_fname_get (stream), lnr, gpg_strerror (err));
700 wks_free_policy (policy_flags_t policy)
704 xfree (policy->submission_address);
705 memset (policy, 0, sizeof *policy);
710 /* Write the content of SRC to the new file FNAME. */
712 write_to_file (estream_t src, const char *fname)
717 size_t nread, written;
719 dst = es_fopen (fname, "wb");
721 return gpg_error_from_syserror ();
725 nread = es_fread (buffer, 1, sizeof buffer, src);
728 written = es_fwrite (buffer, 1, nread, dst);
729 if (written != nread)
732 while (!es_feof (src) && !es_ferror (src) && !es_ferror (dst));
733 if (!es_feof (src) || es_ferror (src) || es_ferror (dst))
735 err = gpg_error_from_syserror ();
737 gnupg_remove (fname);
743 err = gpg_error_from_syserror ();
744 log_error ("error closing '%s': %s\n", fname, gpg_strerror (err));
752 /* Return the filename and optionally the addrspec for USERID at
753 * R_FNAME and R_ADDRSPEC. R_ADDRSPEC might also be set on error. If
754 * HASH_ONLY is set only the has is returned at R_FNAME and no file is
757 wks_fname_from_userid (const char *userid, int hash_only,
758 char **r_fname, char **r_addrspec)
761 char *addrspec = NULL;
765 char shaxbuf[32]; /* Used for SHA-1 and SHA-256 */
771 addrspec = mailbox_from_userid (userid);
774 if (opt.verbose || hash_only)
775 log_info ("\"%s\" is not a proper mail address\n", userid);
776 err = gpg_error (GPG_ERR_INV_USER_ID);
780 domain = strchr (addrspec, '@');
784 /* Hash user ID and create filename. */
785 s = strchr (addrspec, '@');
787 gcry_md_hash_buffer (GCRY_MD_SHA1, shaxbuf, addrspec, s - addrspec);
788 hash = zb32_encode (shaxbuf, 8*20);
791 err = gpg_error_from_syserror ();
803 *r_fname = make_filename_try (opt.directory, domain, "hu", hash, NULL);
805 err = gpg_error_from_syserror ();
811 if (r_addrspec && addrspec)
812 *r_addrspec = addrspec;
820 /* Compute the the full file name for the key with ADDRSPEC and return
823 wks_compute_hu_fname (char **r_fname, const char *addrspec)
834 domain = strchr (addrspec, '@');
835 if (!domain || !domain[1] || domain == addrspec)
836 return gpg_error (GPG_ERR_INV_ARG);
839 gcry_md_hash_buffer (GCRY_MD_SHA1, sha1buf, addrspec, domain - addrspec - 1);
840 hash = zb32_encode (sha1buf, 8*20);
842 return gpg_error_from_syserror ();
844 /* Try to create missing directories below opt.directory. */
845 fname = make_filename_try (opt.directory, domain, NULL);
846 if (fname && gnupg_stat (fname, &sb)
847 && gpg_err_code_from_syserror () == GPG_ERR_ENOENT)
848 if (!gnupg_mkdir (fname, "-rwxr--r--") && opt.verbose)
849 log_info ("directory '%s' created\n", fname);
851 fname = make_filename_try (opt.directory, domain, "hu", NULL);
852 if (fname && gnupg_stat (fname, &sb)
853 && gpg_err_code_from_syserror () == GPG_ERR_ENOENT)
854 if (!gnupg_mkdir (fname, "-rwxr--r--") && opt.verbose)
855 log_info ("directory '%s' created\n", fname);
858 /* Create the filename. */
859 fname = make_filename_try (opt.directory, domain, "hu", hash, NULL);
860 err = fname? 0 : gpg_error_from_syserror ();
865 *r_fname = fname; /* Okay. */
871 /* Make sure that a policy file exists for addrspec. Directories must
874 ensure_policy_file (const char *addrspec)
882 domain = strchr (addrspec, '@');
883 if (!domain || !domain[1] || domain == addrspec)
884 return gpg_error (GPG_ERR_INV_ARG);
887 /* Create the filename. */
888 fname = make_filename_try (opt.directory, domain, "policy", NULL);
889 err = fname? 0 : gpg_error_from_syserror ();
893 /* First a quick check whether it already exists. */
894 if (!(ec = gnupg_access (fname, F_OK)))
896 err = 0; /* File already exists. */
899 err = gpg_error (ec);
900 if (gpg_err_code (err) == GPG_ERR_ENOENT)
904 log_error ("domain %s: problem with '%s': %s\n",
905 domain, fname, gpg_strerror (err));
909 /* Now create the file. */
910 fp = es_fopen (fname, "wxb");
913 err = gpg_error_from_syserror ();
914 if (gpg_err_code (err) == GPG_ERR_EEXIST)
915 err = 0; /* Was created between the gnupg_access() and es_fopen(). */
917 log_error ("domain %s: error creating '%s': %s\n",
918 domain, fname, gpg_strerror (err));
922 es_fprintf (fp, "# Policy flags for domain %s\n", domain);
923 if (es_ferror (fp) || es_fclose (fp))
925 err = gpg_error_from_syserror ();
926 log_error ("error writing '%s': %s\n", fname, gpg_strerror (err));
931 log_info ("policy file '%s' created\n", fname);
933 /* Make sure the policy file world readable. */
934 if (gnupg_chmod (fname, "-rw-r--r--"))
936 err = gpg_error_from_syserror ();
937 log_error ("can't set permissions of '%s': %s\n",
938 fname, gpg_strerror (err));
948 /* Helper form wks_cmd_install_key. */
950 install_key_from_spec_file (const char *fname)
956 size_t maxlen = 2048;
958 unsigned int lnr = 0;
960 if (!fname || !strcmp (fname, ""))
963 fp = es_fopen (fname, "rb");
966 err = gpg_error_from_syserror ();
967 log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
971 while (es_read_line (fp, &line, &linelen, &maxlen) > 0)
975 err = gpg_error (GPG_ERR_LINE_TOO_LONG);
976 log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
981 if (!*line || *line == '#')
983 if (split_fields (line, fields, DIM(fields)) < 2)
985 log_error ("error reading '%s': syntax error at line %u\n",
989 err = wks_cmd_install_key (fields[0], fields[1]);
995 err = gpg_error_from_syserror ();
996 log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
1008 /* Install a single key into the WKD by reading FNAME and extracting
1009 * USERID. If USERID is NULL FNAME is expected to be a list of fpr
1010 * mbox lines and for each line the respective key will be
1013 wks_cmd_install_key (const char *fname, const char *userid)
1016 KEYDB_SEARCH_DESC desc;
1017 estream_t fp = NULL;
1018 char *addrspec = NULL;
1020 uidinfo_list_t uidlist = NULL;
1021 uidinfo_list_t uid, thisuid;
1023 char *huname = NULL;
1027 return install_key_from_spec_file (fname);
1029 addrspec = mailbox_from_userid (userid);
1032 log_error ("\"%s\" is not a proper mail address\n", userid);
1033 err = gpg_error (GPG_ERR_INV_USER_ID);
1037 if (!classify_user_id (fname, &desc, 1)
1038 && (desc.mode == KEYDB_SEARCH_MODE_FPR
1039 || desc.mode == KEYDB_SEARCH_MODE_FPR20))
1041 /* FNAME looks like a fingerprint. Get the key from the
1042 * standard keyring. */
1043 err = wks_get_key (&fp, fname, addrspec, 0);
1046 log_error ("error getting key '%s' (uid='%s'): %s\n",
1047 fname, addrspec, gpg_strerror (err));
1051 else /* Take it from the file */
1053 fp = es_fopen (fname, "rb");
1056 err = gpg_error_from_syserror ();
1057 log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
1062 /* List the key so that we can figure out the newest UID with the
1063 * requested addrspec. */
1064 err = wks_list_key (fp, &fpr, &uidlist);
1067 log_error ("error parsing key: %s\n", gpg_strerror (err));
1068 err = gpg_error (GPG_ERR_NO_PUBKEY);
1074 for (uid = uidlist; uid; uid = uid->next)
1077 continue; /* Should not happen anyway. */
1078 if (ascii_strcasecmp (uid->mbox, addrspec))
1079 continue; /* Not the requested addrspec. */
1081 if (uid->created > thistime)
1083 thistime = uid->created;
1088 thisuid = uidlist; /* This is the case for a missing timestamp. */
1091 log_error ("public key in '%s' has no mail address '%s'\n",
1093 err = gpg_error (GPG_ERR_INV_USER_ID);
1098 log_info ("using key with user id '%s'\n", thisuid->uid);
1104 err = wks_filter_uid (&fp2, fp, thisuid->uid, 1);
1107 log_error ("error filtering key: %s\n", gpg_strerror (err));
1108 err = gpg_error (GPG_ERR_NO_PUBKEY);
1115 /* Hash user ID and create filename. */
1116 err = wks_compute_hu_fname (&huname, addrspec);
1120 /* Now that wks_compute_hu_fname has created missing directories we
1121 * can create a policy file if it does not exist. */
1122 err = ensure_policy_file (addrspec);
1127 err = write_to_file (fp, huname);
1130 log_error ("copying key to '%s' failed: %s\n", huname,gpg_strerror (err));
1134 /* Make sure it is world readable. */
1135 if (gnupg_chmod (huname, "-rw-r--r--"))
1136 log_error ("can't set permissions of '%s': %s\n",
1137 huname, gpg_strerror (gpg_err_code_from_syserror()));
1140 log_info ("key %s published for '%s'\n", fpr, addrspec);
1145 free_uidinfo_list (uidlist);
1153 /* Remove the key with mail address in USERID. */
1155 wks_cmd_remove_key (const char *userid)
1158 char *addrspec = NULL;
1161 err = wks_fname_from_userid (userid, 0, &fname, &addrspec);
1165 if (gnupg_remove (fname))
1167 err = gpg_error_from_syserror ();
1168 if (gpg_err_code (err) == GPG_ERR_ENOENT)
1171 log_info ("key for '%s' is not installed\n", addrspec);
1172 log_inc_errorcount ();
1176 log_error ("error removing '%s': %s\n", fname, gpg_strerror (err));
1181 log_info ("key for '%s' removed\n", addrspec);
1191 /* Print the WKD hash for the user id to stdout. */
1193 wks_cmd_print_wkd_hash (const char *userid)
1196 char *addrspec, *fname;
1198 err = wks_fname_from_userid (userid, 1, &fname, &addrspec);
1202 es_printf ("%s %s\n", fname, addrspec);
1210 /* Print the WKD URL for the user id to stdout. */
1212 wks_cmd_print_wkd_url (const char *userid)
1215 char *addrspec, *fname;
1218 err = wks_fname_from_userid (userid, 1, &fname, &addrspec);
1222 domain = strchr (addrspec, '@');
1226 es_printf ("https://openpgpkey.%s/.well-known/openpgpkey/%s/hu/%s?l=%s\n",
1227 domain, domain, fname, addrspec);