File compat_flags_base.patch of Package gpg2.42517

commit 03f04dfb9a03f0b10dfd7e01ee06df7495b95667
Author: Werner Koch <wk@gnupg.org>
Date:   Mon Oct 31 15:01:24 2022 +0100

    gpg: New option --compatibility-flags
    
    * g10/gpg.c (oCompatibilityFlags): New.
    (opts): Add option.
    (compatibility_flags): New list.
    (main): Set flags and print help.
    * g10/options.h (opt): Add field compatibility_flags.
    --
    
    No flags are yet defined but it is good to have the framework.

Index: gnupg-2.0.24/doc/gpg.texi
===================================================================
--- gnupg-2.0.24.orig/doc/gpg.texi
+++ gnupg-2.0.24/doc/gpg.texi
@@ -2428,6 +2428,14 @@ therefore enables a fast listing of the
 @opindex interactive
 Prompt before overwriting any files.
 
+@item --compatibility-flags @var{flags}
+@opindex compatibility-flags
+Set compatibility flags to work around problems due to non-compliant
+keys or data.  The @var{flags} are given as a comma separated
+list of flag names and are OR-ed together.  The special flag "none"
+clears the list and allows to start over with an empty list.  To get a
+list of available flags the sole word "help" can be used.
+
 @item --debug-level @var{level}
 @opindex debug-level
 Select the debug level for investigating problems. @var{level} may be
Index: gnupg-2.0.24/g10/gpg.c
===================================================================
--- gnupg-2.0.24.orig/g10/gpg.c
+++ gnupg-2.0.24/g10/gpg.c
@@ -370,7 +370,7 @@ enum cmd_and_opt_values
     oNoAllowMultipleMessages,
     oAllowWeakDigestAlgos,
     oSetLegacyFips,
-
+    oCompatibilityFlags,
     oNoop
   };
 
@@ -748,7 +748,7 @@ static ARGPARSE_OPTS opts[] = {
   ARGPARSE_s_n (oNoAllowMultipleMessages, "no-allow-multiple-messages", "@"),
   ARGPARSE_s_n (oAllowWeakDigestAlgos, "allow-weak-digest-algos", "@"),
   ARGPARSE_s_n (oSetLegacyFips, "set-legacy-fips", "@"),
-
+  ARGPARSE_s_s (oCompatibilityFlags, "compatibility-flags", "@"),
   /* These two are aliases to help users of the PGP command line
      product use gpg with minimal pain.  Many commands are common
      already as they seem to have borrowed commands from us.  Now I'm
@@ -769,6 +769,13 @@ static ARGPARSE_OPTS opts[] = {
 };
 
 
+/* The list of compatibility flags.  */
+static struct compatibility_flags_s compatibility_flags [] =
+  {
+    { 0, NULL }
+  };
+
+
 #ifdef ENABLE_SELINUX_HACKS
 #define ALWAYS_ADD_KEYRINGS 1
 #else
@@ -2263,6 +2270,15 @@ main (int argc, char **argv)
 	  case oDebugAll: opt.debug = ~0; break;
           case oDebugLevel: debug_level = pargs.r.ret_str; break;
 
+          case oCompatibilityFlags:
+            if (parse_compatibility_flags (pargs.r.ret_str, &opt.compat_flags,
+                                           compatibility_flags))
+              {
+                pargs.r_opt = ARGPARSE_INVALID_ARG;
+                pargs.err = ARGPARSE_PRINT_ERROR;
+              }
+            break;
+
 	  case oStatusFD:
             set_status_fd ( translate_sys2libc_fd_int (pargs.r.ret_int, 1) );
             break;
@@ -3088,7 +3104,8 @@ main (int argc, char **argv)
       }
 
     set_debug (debug_level);
-
+    if (opt.verbose) /* Print the compatibility flags.  */
+      parse_compatibility_flags (NULL, &opt.compat_flags, compatibility_flags);
     /* Do these after the switch(), so they can override settings. */
     if(PGP2)
       {
Index: gnupg-2.0.24/g10/options.h
===================================================================
--- gnupg-2.0.24.orig/g10/options.h
+++ gnupg-2.0.24/g10/options.h
@@ -253,8 +253,14 @@ struct
   } *auto_key_locate;
 
   int passphrase_repeat;
+  
+  /* Compatibility flags (COMPAT_FLAG_xxxx).  */
+  unsigned int compat_flags;
 } opt;
 
+/* Compatibility flags */
+/* #define COMPAT_FOO   1 */
+
 /* CTRL is used to keep some global variables we currently can't
    avoid.  Future concurrent versions of gpg will put it into a per
    request structure CTRL. */
@@ -301,7 +307,7 @@ EXTERN_UNLESS_MAIN_MODULE int memory_deb
 EXTERN_UNLESS_MAIN_MODULE int memory_stat_debug_mode;
 
 
-
+/* Compliance test macors.  */
 #define GNUPG   (opt.compliance==CO_GNUPG)
 #define RFC1991 (opt.compliance==CO_RFC1991 || opt.compliance==CO_PGP2)
 #define RFC2440 (opt.compliance==CO_RFC2440)
Index: gnupg-2.0.24/jnlib/argparse.h
===================================================================
--- gnupg-2.0.24.orig/jnlib/argparse.h
+++ gnupg-2.0.24/jnlib/argparse.h
@@ -177,7 +177,13 @@ typedef struct
 #define ARGPARSE_AMBIGUOUS_COMMAND (-9)
 #define ARGPARSE_INVALID_ALIAS     (-10)
 #define ARGPARSE_OUT_OF_CORE       (-11)
-
+#define ARGPARSE_INVALID_ARG       (-12)
+#define ARGPARSE_PERMISSION_ERROR  (-13)
+#define ARGPARSE_NO_CONFFILE       (-14)
+#define ARGPARSE_CONFFILE          (-15)
+#define ARGPARSE_INVALID_META      (-16)
+#define ARGPARSE_UNKNOWN_META      (-17)
+#define ARGPARSE_UNEXPECTED_META   (-18)
 
 int arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
 int optfile_parse( FILE *fp, const char *filename, unsigned *lineno,
Index: gnupg-2.0.24/jnlib/stringhelp.c
===================================================================
--- gnupg-2.0.24.orig/jnlib/stringhelp.c
+++ gnupg-2.0.24/jnlib/stringhelp.c
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <ctype.h>
+#include <assert.h>
 #include <errno.h>
 #ifdef HAVE_PWD_H
 # include <pwd.h>
@@ -36,10 +37,15 @@
 # include <windows.h>
 #endif
 
+#include "util.h"
 #include "libjnlib-config.h"
 #include "utf8conv.h"
 #include "stringhelp.h"
 
+#ifndef spacep
+  #define spacep(p)   (*(p) == ' ' || *(p) == '\t')
+#endif
+
 
 #define tohex_lower(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'a'))
 
@@ -1142,3 +1148,68 @@ xstrconcat (const char *s1, ...)
   return result;
 }
 
+
+/* Tokenize STRING using the set of delimiters in DELIM.  Leading
+ * spaces and tabs are removed from all tokens.  The caller must xfree
+ * the result.
+ *
+ * Returns: A malloced and NULL delimited array with the tokens.  On
+ *          memory error NULL is returned and ERRNO is set.
+ */
+char **
+strtokenize (const char *string, const char *delim)
+{
+  const char *s;
+  size_t fields;
+  size_t bytes, n;
+  char *buffer;
+  char *p, *px, *pend;
+  char **result;
+
+  /* Count the number of fields.  */
+  for (fields = 1, s = strpbrk (string, delim); s; s = strpbrk (s + 1, delim))
+    fields++;
+  fields++; /* Add one for the terminating NULL.  */
+
+  /* Allocate an array for all fields, a terminating NULL, and space
+     for a copy of the string.  */
+  bytes = fields * sizeof *result;
+  if (bytes / sizeof *result != fields)
+    {
+      errno = ENOMEM;
+      return NULL;
+    }
+  n = strlen (string) + 1;
+  bytes += n;
+  if (bytes < n)
+    {
+      errno = ENOMEM;
+      return NULL;
+    }
+  result = jnlib_xmalloc (bytes);
+  if (!result)
+    return NULL;
+  buffer = (char*)(result + fields);
+
+  /* Copy and parse the string.  */
+  strcpy (buffer, string);
+  for (n = 0, p = buffer; (pend = strpbrk (p, delim)); p = pend + 1)
+    {
+      *pend = 0;
+      while (spacep (p))
+        p++;
+      for (px = pend - 1; px >= p && spacep (px); px--)
+        *px = 0;
+      result[n++] = p;
+    }
+  while (spacep (p))
+    p++;
+  for (px = p + strlen (p) - 1; px >= p && spacep (px); px--)
+    *px = 0;
+  result[n++] = p;
+  result[n] = NULL;
+
+  assert ((char*)(result + n + 1) == buffer);
+
+  return result;
+}
\ No newline at end of file
Index: gnupg-2.0.24/jnlib/stringhelp.h
===================================================================
--- gnupg-2.0.24.orig/jnlib/stringhelp.h
+++ gnupg-2.0.24/jnlib/stringhelp.h
@@ -34,6 +34,8 @@ size_t length_sans_trailing_chars (const
                                    const char *trimchars );
 size_t length_sans_trailing_ws (const unsigned char *line, size_t len);
 
+/* Tokenize STRING using the set of delimiters in DELIM.  */
+char **strtokenize (const char *string, const char *delim);
 
 char *make_basename(const char *filepath, const char *inputpath);
 char *make_dirname(const char *filepath);
Index: gnupg-2.0.24/jnlib/Makefile.am
===================================================================
--- gnupg-2.0.24.orig/jnlib/Makefile.am
+++ gnupg-2.0.24/jnlib/Makefile.am
@@ -24,7 +24,7 @@ EXTRA_DIST = README ChangeLog-2011
 noinst_PROGRAMS = $(module_tests)
 TESTS = $(module_tests)
 
-AM_CPPFLAGS = -I$(top_srcdir)/intl
+AM_CPPFLAGS = -I$(top_srcdir)/intl  -I$(top_srcdir)/common 
 
 # We need libgcrypt because libjnlib-config includes gcrypt.h
 AM_CFLAGS = -DJNLIB_IN_JNLIB $(GPG_ERROR_CFLAGS) $(LIBGCRYPT_CFLAGS)
@@ -68,3 +68,4 @@ t_jnlib_ldadd = libjnlib.a $(LIBINTL) $(
 t_stringhelp_SOURCES = t-stringhelp.c $(t_jnlib_src)
 t_stringhelp_LDADD = $(t_jnlib_ldadd)
 
+
openSUSE Build Service is sponsored by