[git] GnuPG - branch, master, updated. gnupg-2.1.13-105-g7705f31

by Werner Koch cvs at cvs.gnupg.org
Sun Jul 3 00:43:49 CEST 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  7705f310f1406fe49b45e16c371b09863313f24f (commit)
       via  c619035d9cd0c9cef62facf5365321289051f9a0 (commit)
       via  0e36a1d1fb79c2b75c081616eed00075190b38aa (commit)
      from  442efa9b3ff211c692b6967a944b3d9371ad1bb7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 7705f310f1406fe49b45e16c371b09863313f24f
Author: Werner Koch <wk at gnupg.org>
Date:   Sun Jul 3 00:41:30 2016 +0200

    tools: Call sendmail directly from the wks tools.
    
    * tools/send-mail.c, tools/send-mail.h: New.
    * tools/wks-util.c: New.
    * tools/Makefile.am (gpg_wks_server_SOURCES): Add them.
    (gpg_wks_client_SOURCES): Ditto.
    * tools/gpg-wks.h (opt): Add fields use_sendmail and output.
    * tools/gpg-wks-client.c: Add options --send and --output.  Rename
    command --send to --create.
    (command_send, send_confirmation_response): Output via wks_send_mime.
    * tools/gpg-wks-server.c:  Add options --send and --output.
    (send_confirmation_request): Output via wks_send_mime.
    (check_and_publish): Add hack for name-value bug.
    --
    
    With this code, a dedicated user on the server along with a procmail
    script, it was possible to run a basic test.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 362ee1f..7bc1456 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -147,21 +147,25 @@ gpgtar_LDADD = $(libcommon) $(LIBGCRYPT_LIBS) $(GPG_ERROR_LIBS) \
 gpg_wks_server_SOURCES = \
 	gpg-wks-server.c \
 	gpg-wks.h \
+	wks-util.c \
 	wks-receive.c \
 	rfc822parse.c rfc822parse.h \
 	mime-parser.c mime-parser.h \
-	mime-maker.h  mime-maker.c
+	mime-maker.c  mime-maker.h  \
+	send-mail.c   send-mail.h
 
 gpg_wks_server_CFLAGS = $(GPG_ERROR_CFLAGS)
 gpg_wks_server_LDADD = $(libcommon) $(LIBGCRYPT_LIBS) $(GPG_ERROR_LIBS)
 
 gpg_wks_client_SOURCES = \
 	gpg-wks-client.c \
-	gpg-wks.h \
+	gpg-wks.h  \
+	wks-util.c \
 	wks-receive.c \
 	rfc822parse.c rfc822parse.h \
 	mime-parser.c mime-parser.h \
-	mime-maker.h  mime-maker.c \
+	mime-maker.h  mime-maker.c  \
+	send-mail.c   send-mail.h   \
 	call-dirmngr.c call-dirmngr.h
 
 gpg_wks_client_CFLAGS = $(LIBASSUAN_CFLAGS) $(GPG_ERROR_CFLAGS)
diff --git a/tools/gpg-wks-client.c b/tools/gpg-wks-client.c
index c7cb8fb..25ee43f 100644
--- a/tools/gpg-wks-client.c
+++ b/tools/gpg-wks-client.c
@@ -34,6 +34,7 @@
 #include "name-value.h"
 #include "call-dirmngr.h"
 #include "mime-maker.h"
+#include "send-mail.h"
 #include "gpg-wks.h"
 
 
@@ -44,13 +45,15 @@ enum cmd_and_opt_values
 
     oQuiet      = 'q',
     oVerbose	= 'v',
+    oOutput     = 'o',
 
     oDebug      = 500,
 
-    aSend,
+    aCreate,
     aReceive,
 
     oGpgProgram,
+    oSend,
 
     oDummy
   };
@@ -60,8 +63,8 @@ enum cmd_and_opt_values
 static ARGPARSE_OPTS opts[] = {
   ARGPARSE_group (300, ("@Commands:\n ")),
 
-  ARGPARSE_c (aSend,   "send",
-              ("send a publication request")),
+  ARGPARSE_c (aCreate,   "create",
+              ("create a publication request")),
   ARGPARSE_c (aReceive,   "receive",
               ("receive a confirmation request")),
 
@@ -71,6 +74,8 @@ static ARGPARSE_OPTS opts[] = {
   ARGPARSE_s_n (oQuiet,	"quiet",  ("be somewhat more quiet")),
   ARGPARSE_s_s (oDebug, "debug", "@"),
   ARGPARSE_s_s (oGpgProgram, "gpg", "@"),
+  ARGPARSE_s_n (oSend, "send", "send the mail using sendmail"),
+  ARGPARSE_s_s (oOutput, "output", "|FILE|write the mail to FILE"),
 
 
   ARGPARSE_end ()
@@ -112,10 +117,10 @@ my_strusage( int level )
 
     case 1:
     case 40:
-      p = ("Usage: gpg-wks-client --send|--receive [args] (-h for help)");
+      p = ("Usage: gpg-wks-client [command] [options] [args] (-h for help)");
       break;
     case 41:
-      p = ("Syntax: gpg-wks-client --send|--receive [args]\n"
+      p = ("Syntax: gpg-wks-client [command] [options] [args]\n"
            "Client for the Web Key Service\n");
       break;
 
@@ -158,8 +163,14 @@ parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
         case oGpgProgram:
           opt.gpg_program = pargs->r.ret_str;
           break;
+        case oSend:
+          opt.use_sendmail = 1;
+          break;
+        case oOutput:
+          opt.output = pargs->r.ret_str;
+          break;
 
-	case aSend:
+	case aCreate:
 	case aReceive:
           cmd = pargs->r_opt;
           break;
@@ -221,12 +232,12 @@ main (int argc, char **argv)
   /* Run the selected command.  */
   switch (cmd)
     {
-    case aSend:
+    case aCreate:
       if (argc != 2)
-        wrong_args ("--send FINGERPRINT USER-ID");
+        wrong_args ("--create FINGERPRINT USER-ID");
       err = command_send (argv[0], argv[1]);
       if (err)
-        log_error ("sending key failed: %s\n", gpg_strerror (err));
+        log_error ("creating request failed: %s\n", gpg_strerror (err));
       break;
 
     case aReceive:
@@ -234,7 +245,7 @@ main (int argc, char **argv)
         wrong_args ("--receive");
       err = wks_receive (es_stdin, command_receive_cb, NULL);
       if (err)
-        log_error ("reading mail failed: %s\n", gpg_strerror (err));
+        log_error ("processing mail failed: %s\n", gpg_strerror (err));
       break;
 
     default:
@@ -407,7 +418,7 @@ command_send (const char *fingerprint, char *userid)
   if (err)
     goto leave;
 
-  err = mime_maker_make (mime, es_stdout);
+  err = wks_send_mime (mime);
 
  leave:
   mime_maker_release (mime);
@@ -502,7 +513,7 @@ send_confirmation_response (const char *sender, const char *address,
   if (err)
     goto leave;
 
-  err = mime_maker_make (mime, es_stdout);
+  err = wks_send_mime (mime);
 
  leave:
   mime_maker_release (mime);
diff --git a/tools/gpg-wks-server.c b/tools/gpg-wks-server.c
index 1106934..305b454 100644
--- a/tools/gpg-wks-server.c
+++ b/tools/gpg-wks-server.c
@@ -40,6 +40,7 @@
 #include "mbox-util.h"
 #include "name-value.h"
 #include "mime-maker.h"
+#include "send-mail.h"
 #include "gpg-wks.h"
 
 
@@ -50,6 +51,7 @@ enum cmd_and_opt_values
 
     oQuiet      = 'q',
     oVerbose	= 'v',
+    oOutput     = 'o',
 
     oDebug      = 500,
 
@@ -57,6 +59,7 @@ enum cmd_and_opt_values
     aCron,
 
     oGpgProgram,
+    oSend,
     oFrom,
     oHeader,
 
@@ -79,7 +82,9 @@ static ARGPARSE_OPTS opts[] = {
   ARGPARSE_s_n (oQuiet,	"quiet",  ("be somewhat more quiet")),
   ARGPARSE_s_s (oDebug, "debug", "@"),
   ARGPARSE_s_s (oGpgProgram, "gpg", "@"),
-  ARGPARSE_s_s (oFrom, "from" , "|ADDR|use ADDR as the default sender"),
+  ARGPARSE_s_n (oSend, "send", "send the mail using sendmail"),
+  ARGPARSE_s_s (oOutput, "output", "|FILE|write the mail to FILE"),
+  ARGPARSE_s_s (oFrom, "from", "|ADDR|use ADDR as the default sender"),
   ARGPARSE_s_s (oHeader, "header" ,
                 "|NAME=VALUE|add \"NAME: VALUE\" as header to all mails"),
 
@@ -182,6 +187,12 @@ parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
         case oHeader:
           append_to_strlist (&opt.extra_headers, pargs->r.ret_str);
           break;
+        case oSend:
+          opt.use_sendmail = 1;
+          break;
+        case oOutput:
+          opt.output = pargs->r.ret_str;
+          break;
 
 	case aReceive:
         case aCron:
@@ -831,7 +842,7 @@ send_confirmation_request (server_ctx_t ctx,
   if (err)
     goto leave;
 
-  err = mime_maker_make (mime, es_stdout);
+  err = wks_send_mime (mime);
 
  leave:
   mime_maker_release (mime);
@@ -923,6 +934,14 @@ check_and_publish (server_ctx_t ctx, const char *address, const char *nonce)
   const char *s;
   strlist_t sl;
 
+  /* FIXME: There is a bug in name-value.c which adds white space for
+   * the last pair and thus we strip the nonce here until this has
+   * been fixed.  */
+  char *nonce2 = xstrdup (nonce);
+  trim_trailing_spaces (nonce2);
+  nonce = nonce2;
+
+
   domain = strchr (address, '@');
   log_assert (domain && domain[1]);
   domain++;
@@ -1027,6 +1046,7 @@ check_and_publish (server_ctx_t ctx, const char *address, const char *nonce)
   xfree (hash);
   xfree (fnewname);
   xfree (fname);
+  xfree (nonce2);
   return err;
 }
 
diff --git a/tools/gpg-wks.h b/tools/gpg-wks.h
index 873925c..be85eec 100644
--- a/tools/gpg-wks.h
+++ b/tools/gpg-wks.h
@@ -22,6 +22,7 @@
 
 #include "../common/util.h"
 #include "../common/strlist.h"
+#include "mime-maker.h"
 
 /* We keep all global options in the structure OPT.  */
 struct
@@ -29,6 +30,8 @@ struct
   int verbose;
   unsigned int debug;
   int quiet;
+  int use_sendmail;
+  const char *output;
   const char *gpg_program;
   const char *directory;
   const char *default_from;
@@ -43,6 +46,9 @@ struct
 #define DBG_EXTPROG_VALUE 16384 /* debug external program calls */
 
 
+/*-- wks-util.c --*/
+gpg_error_t wks_send_mime (mime_maker_t mime);
+
 /*-- wks-receive.c --*/
 gpg_error_t wks_receive (estream_t fp,
                          gpg_error_t (*result_cb)(void *opaque,
diff --git a/tools/send-mail.c b/tools/send-mail.c
new file mode 100644
index 0000000..2266521
--- /dev/null
+++ b/tools/send-mail.c
@@ -0,0 +1,129 @@
+/* send-mail.c - Invoke sendmail or other delivery tool.
+ * Copyright (C) 2016 g10 Code GmbH
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "util.h"
+#include "exectool.h"
+#include "sysutils.h"
+#include "send-mail.h"
+
+
+static gpg_error_t
+run_sendmail (estream_t data)
+{
+  gpg_error_t err;
+  const char pgmname[] = "/usr/lib/sendmail";
+  const char *argv[3];
+
+  argv[0] = "-oi";
+  argv[1] = "-t";
+  argv[2] = NULL;
+
+  err = gnupg_exec_tool_stream (pgmname, argv, data, NULL, NULL, NULL, NULL);
+  if (err)
+    log_error ("running '%s' failed: %s\n", pgmname, gpg_strerror (err));
+  return err;
+}
+
+
+/* Send the data in FP as mail.  */
+gpg_error_t
+send_mail (estream_t fp)
+{
+  return run_sendmail (fp);
+}
+
+
+/* Convenience function to write a mail to a named file. */
+gpg_error_t
+send_mail_to_file (estream_t fp, const char *fname)
+{
+  gpg_error_t err;
+  estream_t outfp = NULL;
+  char *buffer = NULL;
+  size_t buffersize = 32 * 1024;
+  size_t nbytes, nwritten;
+
+  if (!fname)
+    fname = "-";
+
+  buffer = xtrymalloc (buffersize);
+  if (!buffer)
+    return gpg_error_from_syserror ();
+
+  outfp = !strcmp (fname,"-")? es_stdout : es_fopen (fname, "wb");
+  if (!outfp)
+    {
+      err = gpg_error_from_syserror ();
+      log_error ("error creating '%s': %s\n", fname, gpg_strerror (err));
+      goto leave;
+    }
+  for (;;)
+    {
+      if (es_read (fp, buffer, sizeof buffer, &nbytes))
+        {
+          err = gpg_error_from_syserror ();
+          log_error ("error reading '%s': %s\n",
+                     es_fname_get (fp), gpg_strerror (err));
+          goto leave;
+        }
+
+      if (!nbytes)
+        {
+          err = 0;
+          break; /* Ready.  */
+        }
+
+      if (es_write (outfp, buffer, nbytes, &nwritten))
+        {
+          err = gpg_error_from_syserror ();
+          log_error ("error writing '%s': %s\n", fname, gpg_strerror (err));
+          goto leave;
+        }
+      else if (nwritten != nbytes)
+        {
+          err = gpg_error (GPG_ERR_EIO);
+          log_error ("error writing '%s': %s\n", fname, "short write");
+          goto leave;
+        }
+    }
+
+
+ leave:
+  if (err)
+    {
+      if (outfp && outfp != es_stdout)
+        {
+          es_fclose (outfp);
+          gnupg_remove (fname);
+        }
+    }
+  else if (outfp && outfp != es_stdout && es_fclose (outfp))
+    {
+      err = gpg_error_from_syserror ();
+      log_error ("error closing '%s': %s\n", fname, gpg_strerror (err));
+    }
+
+  xfree (buffer);
+  return err;
+}
diff --git a/tools/send-mail.h b/tools/send-mail.h
new file mode 100644
index 0000000..5f57854
--- /dev/null
+++ b/tools/send-mail.h
@@ -0,0 +1,27 @@
+/* send-mail.h - Invoke sendmail or other delivery tool.
+ * Copyright (C) 2016 g10 Code GmbH
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GNUPG_SEND_MAIL_H
+#define GNUPG_SEND_MAIL_H
+
+gpg_error_t send_mail (estream_t fp);
+gpg_error_t send_mail_to_file (estream_t fp, const char *fname);
+
+
+#endif /*GNUPG_SEND_MAIL_H*/
diff --git a/tools/wks-util.c b/tools/wks-util.c
new file mode 100644
index 0000000..8d9f92b
--- /dev/null
+++ b/tools/wks-util.c
@@ -0,0 +1,65 @@
+/* wks-utils.c - Common helper fucntions for wks tools
+ * Copyright (C) 2016 g10 Code GmbH
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "util.h"
+#include "mime-maker.h"
+#include "send-mail.h"
+#include "gpg-wks.h"
+
+
+/* Helper to write mail to the output(s).  */
+gpg_error_t
+wks_send_mime (mime_maker_t mime)
+{
+  gpg_error_t err;
+  estream_t mail;
+
+  /* Without any option we take a short path.  */
+  if (!opt.use_sendmail && !opt.output)
+    return mime_maker_make (mime, es_stdout);
+
+  mail = es_fopenmem (0, "w+b");
+  if (!mail)
+    {
+      err = gpg_error_from_syserror ();
+      return err;
+    }
+
+  err = mime_maker_make (mime, mail);
+
+  if (!err && opt.output)
+    {
+      es_rewind (mail);
+      err = send_mail_to_file (mail, opt.output);
+    }
+
+  if (!err && opt.use_sendmail)
+    {
+      es_rewind (mail);
+      err = send_mail (mail);
+    }
+
+  es_fclose (mail);
+  return err;
+}

commit c619035d9cd0c9cef62facf5365321289051f9a0
Author: Werner Koch <wk at gnupg.org>
Date:   Sat Jul 2 18:59:22 2016 +0200

    tools: Add options to gpg-wks-server.
    
    * tools/gpg-wks.h (opt): Add 'default_from' and 'extra_headers'.
    * tools/gpg-wks-server.c (oFrom, oHeader): New.
    (parse_arguments): Set them and check args.
    (get_submission_address): New.
    (send_confirmation_request): Set correct From address.  Add extra
    headers.
    (process_new_key): Return an error code.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/tools/gpg-wks-server.c b/tools/gpg-wks-server.c
index 2ae84e2..1106934 100644
--- a/tools/gpg-wks-server.c
+++ b/tools/gpg-wks-server.c
@@ -57,6 +57,8 @@ enum cmd_and_opt_values
     aCron,
 
     oGpgProgram,
+    oFrom,
+    oHeader,
 
     oDummy
   };
@@ -77,7 +79,9 @@ static ARGPARSE_OPTS opts[] = {
   ARGPARSE_s_n (oQuiet,	"quiet",  ("be somewhat more quiet")),
   ARGPARSE_s_s (oDebug, "debug", "@"),
   ARGPARSE_s_s (oGpgProgram, "gpg", "@"),
-
+  ARGPARSE_s_s (oFrom, "from" , "|ADDR|use ADDR as the default sender"),
+  ARGPARSE_s_s (oHeader, "header" ,
+                "|NAME=VALUE|add \"NAME: VALUE\" as header to all mails"),
 
   ARGPARSE_end ()
 };
@@ -172,6 +176,12 @@ parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
         case oGpgProgram:
           opt.gpg_program = pargs->r.ret_str;
           break;
+        case oFrom:
+          opt.default_from = pargs->r.ret_str;
+          break;
+        case oHeader:
+          append_to_strlist (&opt.extra_headers, pargs->r.ret_str);
+          break;
 
 	case aReceive:
         case aCron:
@@ -228,6 +238,24 @@ main (int argc, char **argv)
   if (!opt.directory)
     opt.directory = "/var/lib/gnupg/wks";
 
+  /* Check for syntax errors in the --header option to avoid later
+   * error messages with a not easy to find cause */
+  if (opt.extra_headers)
+    {
+      strlist_t sl;
+
+      for (sl = opt.extra_headers; sl; sl = sl->next)
+        {
+          err = mime_maker_add_header (NULL, sl->d, NULL);
+          if (err)
+            log_error ("syntax error in \"--header %s\": %s\n",
+                       sl->d, gpg_strerror (err));
+        }
+    }
+
+  if (log_get_errorcount (0))
+    exit (2);
+
 
   /* Check that we have a working directory.  */
 #if defined(HAVE_STAT)
@@ -271,7 +299,7 @@ main (int argc, char **argv)
         wrong_args ("--receive");
       err = wks_receive (es_stdin, command_receive_cb, NULL);
       if (err)
-        log_error ("reading mail failed: %s\n", gpg_strerror (err));
+        log_error ("processing mail failed: %s\n", gpg_strerror (err));
       break;
 
     case aCron:
@@ -523,6 +551,74 @@ encrypt_stream (estream_t *r_output, estream_t input, const char *fingerprint)
 }
 
 
+/* Get the submission address for address MBOX.  Caller must free the
+ * value.  If no address can be found NULL is returned.  */
+static char *
+get_submission_address (const char *mbox)
+{
+  gpg_error_t err;
+  const char *domain;
+  char *fname, *line, *p;
+  size_t n;
+  estream_t fp;
+
+  domain = strchr (mbox, '@');
+  if (!domain)
+    return NULL;
+  domain++;
+
+  fname = make_filename_try (opt.directory, domain, "submission-address", NULL);
+  if (!fname)
+    {
+      err = gpg_error_from_syserror ();
+      log_error ("make_filename failed in %s: %s\n",
+                 __func__, gpg_strerror (err));
+      return NULL;
+    }
+
+  fp = es_fopen (fname, "r");
+  if (!fp)
+    {
+      err = gpg_error_from_syserror ();
+      if (gpg_err_code (err) == GPG_ERR_ENOENT)
+        log_info ("Note: no specific submission address configured"
+                  " for domain '%s'\n", domain);
+      else
+        log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
+      xfree (fname);
+      return NULL;
+    }
+
+  line = NULL;
+  n = 0;
+  if (es_getline (&line, &n, fp) < 0)
+    {
+      err = gpg_error_from_syserror ();
+      log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
+      xfree (line);
+      es_fclose (fp);
+      xfree (fname);
+      return NULL;
+    }
+  es_fclose (fp);
+  xfree (fname);
+
+  p = strchr (line, '\n');
+  if (p)
+    *p = 0;
+  trim_spaces (line);
+  if (!is_valid_mailbox (line))
+    {
+      log_error ("invalid submission address for domain '%s' detected\n",
+                 domain);
+      xfree (line);
+      return NULL;
+    }
+
+  return line;
+}
+
+
 /* We store the key under the name of the nonce we will then send to
  * the user.  On success the nonce is stored at R_NONCE.  */
 static gpg_error_t
@@ -631,20 +727,40 @@ store_key_as_pending (const char *dir, estream_t key, char **r_nonce)
 }
 
 
+/* Send a confirmation rewqyest.  DIR is the directory used for the
+ * address MBOX.  NONCE is the nonce we want to see in the response to
+ * this mail.  */
 static gpg_error_t
-send_confirmation_request (server_ctx_t ctx, const char *mbox, const char *nonce)
+send_confirmation_request (server_ctx_t ctx,
+                           const char *mbox, const char *nonce)
 {
   gpg_error_t err;
   estream_t body = NULL;
   estream_t bodyenc = NULL;
   mime_maker_t mime = NULL;
+  char *from_buffer = NULL;
+  const char *from;
+  strlist_t sl;
+
+  from = from_buffer = get_submission_address (mbox);
+  if (!from)
+    {
+      from = opt.default_from;
+      if (!from)
+        {
+          log_error ("no sender address found for '%s'\n", mbox);
+          err = gpg_error (GPG_ERR_CONFIGURATION);
+          goto leave;
+        }
+      log_info ("Note: using default sender address '%s'\n", from);
+    }
 
   body = es_fopenmem (0, "w+b");
   if (!body)
     {
       err = gpg_error_from_syserror ();
       log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
-      return err;
+      goto leave;
     }
   /* It is fine to use 8 bit encosind because that is encrypted and
    * only our client will see it.  */
@@ -658,7 +774,7 @@ send_confirmation_request (server_ctx_t ctx, const char *mbox, const char *nonce
                      "address: %s\n"
                      "fingerprint: %s\n"
                      "nonce: %s\n"),
-              "sender at example.org",
+              from,
               mbox,
               ctx->fpr,
               nonce);
@@ -674,12 +790,21 @@ send_confirmation_request (server_ctx_t ctx, const char *mbox, const char *nonce
   err = mime_maker_new (&mime, NULL);
   if (err)
     goto leave;
+  err = mime_maker_add_header (mime, "From", from);
+  if (err)
+    goto leave;
   err = mime_maker_add_header (mime, "To", mbox);
   if (err)
     goto leave;
-  err = mime_maker_add_header (mime, "Subject", "confirm key publication");
+  err = mime_maker_add_header (mime, "Subject", "Confirm your key publication");
   if (err)
     goto leave;
+  for (sl = opt.extra_headers; sl; sl = sl->next)
+    {
+      err = mime_maker_add_header (mime, sl->d, NULL);
+      if (err)
+        goto leave;
+    }
 
   err = mime_maker_add_header (mime, "Content-Type",
                                "multipart/encrypted; "
@@ -712,6 +837,7 @@ send_confirmation_request (server_ctx_t ctx, const char *mbox, const char *nonce
   mime_maker_release (mime);
   xfree (bodyenc);
   xfree (body);
+  xfree (from_buffer);
   return err;
 }
 
@@ -779,7 +905,7 @@ process_new_key (server_ctx_t ctx, estream_t key)
     wipememory (nonce, strlen (nonce));
   xfree (nonce);
   xfree (dname);
-  return 0;
+  return err;
 }
 
 
diff --git a/tools/gpg-wks.h b/tools/gpg-wks.h
index 249b10a..873925c 100644
--- a/tools/gpg-wks.h
+++ b/tools/gpg-wks.h
@@ -31,6 +31,8 @@ struct
   int quiet;
   const char *gpg_program;
   const char *directory;
+  const char *default_from;
+  strlist_t extra_headers;
 } opt;
 
 /* Debug values and macros.  */

commit 0e36a1d1fb79c2b75c081616eed00075190b38aa
Author: Werner Koch <wk at gnupg.org>
Date:   Sat Jul 2 18:55:22 2016 +0200

    tools: Extend mime-maker.c:mime_maker_add_header.
    
    * tools/mime-maker.c (add_header): Check header name and allow
    name-value syntax.
    (mime_maker_add_header): Add mode for a syntax check.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/tools/mime-maker.c b/tools/mime-maker.c
index 88f9d5f..fa42043 100644
--- a/tools/mime-maker.c
+++ b/tools/mime-maker.c
@@ -27,6 +27,11 @@
 #include "mime-maker.h"
 
 
+/* All valid charachters in a header name.  */
+#define HEADER_NAME_CHARS  ("abcdefghijklmnopqrstuvwxyz" \
+                            "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
+                            "-01234567890")
+
 /* An object to store an header.  Also used for a list of headers.  */
 struct header_s
 {
@@ -294,12 +299,37 @@ add_header (part_t part, const char *name, const char *value)
 {
   gpg_error_t err;
   header_t hdr;
+  size_t namelen;
+  const char *s;
 
-  hdr = xtrymalloc (sizeof *hdr + strlen (name));
+  if (!value)
+    {
+      s = strchr (name, '=');
+      if (!s)
+        return gpg_error (GPG_ERR_INV_ARG);
+      namelen = s - name;
+      value = s+1;
+    }
+  else
+    namelen = strlen (name);
+
+  hdr = xtrymalloc (sizeof *hdr + namelen);
   if (!hdr)
     return gpg_error_from_syserror ();
   hdr->next = NULL;
-  strcpy (hdr->name, name);
+  memcpy (hdr->name, name, namelen);
+  hdr->name[namelen] = 0;
+
+  /* Check that the header name is valid.  We allow all lower and
+   * uppercase letters and, except for the first character, digits and
+   * the dash.  */
+  if (strspn (hdr->name, HEADER_NAME_CHARS) != namelen
+      || strchr ("-0123456789", *hdr->name))
+    {
+      xfree (hdr);
+      return gpg_error (GPG_ERR_INV_NAME);
+    }
+
   capitalize_header_name (hdr->name);
   hdr->value = xtrystrdup (value);
   if (!hdr->value)
@@ -308,21 +338,30 @@ add_header (part_t part, const char *name, const char *value)
       xfree (hdr);
       return err;
     }
-  *part->headers_tail = hdr;
-  part->headers_tail = &hdr->next;
+
+  if (part)
+    {
+      *part->headers_tail = hdr;
+      part->headers_tail = &hdr->next;
+    }
+  else
+    xfree (hdr);
 
   return 0;
 }
 
 
 /* Add a header with NAME and VALUE to the current mail.  A LF in the
- * VALUE will be handled automagically.  If no container has been
- * added, the header will be used for the regular mail headers and not
- * for a MIME part.  If the current part is in a container and a body
- * has been added, we append a new part to the current container.
- * Thus for a non-MIME mail the caller needs to call this function
- * followed by a call to add a body.  When adding a Content-Type the
- * boundary parameter must not be included.
+ * VALUE will be handled automagically.  If NULL is used for VALUE it
+ * is expected that the NAME has the format "NAME=VALUE" and VALUE is
+ * taken from there.
+ *
+ * If no container has been added, the header will be used for the
+ * regular mail headers and not for a MIME part.  If the current part
+ * is in a container and a body has been added, we append a new part
+ * to the current container.  Thus for a non-MIME mail the caller
+ * needs to call this function followed by a call to add a body.  When
+ * adding a Content-Type the boundary parameter must not be included.
  */
 gpg_error_t
 mime_maker_add_header (mime_maker_t ctx, const char *name, const char *value)
@@ -330,6 +369,10 @@ mime_maker_add_header (mime_maker_t ctx, const char *name, const char *value)
   gpg_error_t err;
   part_t part, parent;
 
+  /* Hack to use this fucntion for a synacx check of NAME and VALUE.  */
+  if (!ctx)
+    return add_header (NULL, name, value);
+
   err = ensure_part (ctx, &parent);
   if (err)
     return err;

-----------------------------------------------------------------------

Summary of changes:
 tools/Makefile.am                    |  10 ++-
 tools/gpg-wks-client.c               |  35 +++++---
 tools/gpg-wks-server.c               | 162 +++++++++++++++++++++++++++++++++--
 tools/gpg-wks.h                      |   8 ++
 tools/mime-maker.c                   |  65 +++++++++++---
 tools/send-mail.c                    | 129 ++++++++++++++++++++++++++++
 sm/passphrase.h => tools/send-mail.h |  14 +--
 tools/wks-util.c                     |  65 ++++++++++++++
 8 files changed, 447 insertions(+), 41 deletions(-)
 create mode 100644 tools/send-mail.c
 copy sm/passphrase.h => tools/send-mail.h (74%)
 create mode 100644 tools/wks-util.c


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list