build: Allow building without SQLlite support.
authorWerner Koch <wk@gnupg.org>
Tue, 20 Oct 2015 15:32:23 +0000 (17:32 +0200)
committerWerner Koch <wk@gnupg.org>
Tue, 20 Oct 2015 15:32:23 +0000 (17:32 +0200)
* configure.ac: Add option --dsiable-tofu and --disable-sqlite.
(NEED_SQLITE_VERSION): New var.
(USE_TOFU): New ac_define and am_conditional.
* autogen.sh (build-w32): Add PKG_CONFIG_LIBDIR to configure so that
pkg-config find the correct .pc file.

* g10/Makefile.am (tofu_source): New.  Build only if enabled.
* g10/gpg.c (parse_trust_model)[!USE_TOFU]: Disable tofu models.
(parse_tofu_policy)[!USE_TOFU]: Disable all.
(parse_tofu_db_format)[!USE_TOFU]: Disable all.
(main) <aTOFUPolicy>[!USE_TOFU]: Skip.
* g10/keyedit.c (show_key_with_all_names_colon)[!USE_TOFU]: Do not
call tofu functions.
* g10/keylist.c (list_keyblock_colon)[!USE_TOFU]: Ditto.
* g10/trustdb.c (tdb_get_validity_core)[!USE_TOFU]: Skip tofu
processing.
--

This allows to build a minimal version of GnuPG.  It is also currently
required to build for Windows.

Signed-off-by: Werner Koch <wk@gnupg.org>
autogen.sh
configure.ac
g10/Makefile.am
g10/gpg.c
g10/keyedit.c
g10/keylist.c
g10/tofu.h
g10/trustdb.c

index 7effd56..3fe24ea 100755 (executable)
@@ -311,6 +311,7 @@ if [ "$myhost" = "w32" ]; then
     $tsdir/configure --enable-maintainer-mode ${SILENT} \
              --prefix=${w32root}  \
              --host=${host} --build=${build} SYSROOT=${w32root} \
+             PKG_CONFIG_LIBDIR=${w32root} \
              ${configure_opts} ${extraoptions} "$@"
     rc=$?
     exit $rc
index ddbc065..3ec9895 100644 (file)
@@ -69,6 +69,7 @@ NEED_NPTH_VERSION=0.91
 
 NEED_GNUTLS_VERSION=3.0
 
+NEED_SQLITE_VERSION=3.7
 
 development_version=mym4_isbeta
 PACKAGE=$PACKAGE_NAME
@@ -91,6 +92,7 @@ have_libassuan=no
 have_ksba=no
 have_ntbtls=no
 have_gnutls=no
+have_sqlite=no
 have_npth=no
 have_libusb=no
 have_adns=no
@@ -100,6 +102,7 @@ use_zip=yes
 use_bzip2=yes
 use_exec=yes
 use_trust_models=yes
+use_tofu=yes
 card_support=yes
 use_ccid_driver=yes
 dirmngr_auto_start=yes
@@ -247,6 +250,14 @@ if test "$use_trust_models" = no ; then
              [Define to include only trust-model always])
 fi
 
+AC_MSG_CHECKING([whether to enable TOFU])
+AC_ARG_ENABLE(tofu,
+                AC_HELP_STRING([--disable-tofu],
+                               [disable the TOFU trust model]),
+              use_tofu=$enableval, use_tofu=yes)
+AC_MSG_RESULT($use_tofu)
+
+
 
 #
 # Options to disable algorithm
@@ -780,11 +791,39 @@ DL_LIBS=$LIBS
 AC_SUBST(DL_LIBS)
 LIBS="$gnupg_dlopen_save_libs"
 
+
 # Checks for g10
 
-PKG_CHECK_MODULES(SQLITE3, sqlite3)
-AC_SUBST(SQLITE3_CFLAGS)
-AC_SUBST(SQLITE3_LIBS)
+AC_ARG_ENABLE(sqlite,
+                AC_HELP_STRING([--disable-sqlite],
+                               [disable the use of SQLITE]),
+              try_sqlite=$enableval, try_sqlite=yes)
+
+if test x"$use_tofu" = xyes ; then
+  if test x"$try_sqlite" = xyes ; then
+    PKG_CHECK_MODULES([SQLITE3], [sqlite3 >= $NEED_SQLITE_VERSION],
+                                 [have_sqlite=yes],
+                                 [have_sqlite=no])
+  fi
+  if test "$have_sqlite" = "yes"; then
+    :
+    AC_SUBST([SQLITE3_CFLAGS])
+    AC_SUBST([SQLITE3_LIBS])
+  else
+    use_tofu=no
+    tmp=$(echo "$SQLITE3_PKG_ERRORS" | tr '\n' '\v' | sed 's/\v/\n*** /g')
+    AC_MSG_WARN([[
+***
+*** Building without SQLite support - TOFU disabled
+***
+*** $tmp]])
+  fi
+fi
+
+if test x"$use_tofu" = xyes ; then
+    AC_DEFINE(USE_TOFU, 1, [Enable to build the TOFU code])
+fi
+
 
 # Checks for g13
 
@@ -1547,7 +1586,8 @@ AM_CONDITIONAL(BUILD_SYMCRYPTRUN, test "$build_symcryptrun" = "yes")
 AM_CONDITIONAL(BUILD_GPGTAR,      test "$build_gpgtar" = "yes")
 
 AM_CONDITIONAL(ENABLE_CARD_SUPPORT, test "$card_support" = yes)
-AM_CONDITIONAL(NO_TRUST_MODELS, test "$use_trust_models" = no)
+AM_CONDITIONAL(NO_TRUST_MODELS,     test "$use_trust_models" = no)
+AM_CONDITIONAL(USE_TOFU,            test "$use_tofu" = yes)
 
 AM_CONDITIONAL(RUN_GPG_TESTS,
                test x$cross_compiling = xno -a "$build_gpg" = yes )
@@ -1800,6 +1840,7 @@ echo "
         LDAP support:        $gnupg_have_ldap
         DNS SRV support:     $use_dns_srv
         TLS support:         $use_tls_library
+        TOFU support:        $use_tofu
 "
 if test x"$use_regex" != xyes ; then
 echo "
index 7357843..75ccac8 100644 (file)
@@ -56,6 +56,12 @@ else
 trust_source = trustdb.c trustdb.h tdbdump.c tdbio.c tdbio.h
 endif
 
+if USE_TOFU
+tofu_source = tofu.h tofu.c
+else
+tofu_source =
+endif
+
 
 if HAVE_W32_SYSTEM
 resource_objs += gpg-w32info.o
@@ -124,10 +130,9 @@ gpg2_SOURCES  = gpg.c              \
              call-dirmngr.c call-dirmngr.h \
              photoid.c photoid.h \
              call-agent.c call-agent.h \
-             trust.c $(trust_source) \
+             trust.c $(trust_source) $(tofu_source) \
              $(card_source) \
-             exec.c exec.h \
-             tofu.h tofu.c
+             exec.c exec.h
 
 gpgv2_SOURCES = gpgv.c           \
              $(common_source)  \
index 794d5ea..ff6e59f 100644 (file)
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -1949,10 +1949,12 @@ parse_trust_model(const char *model)
     opt.trust_model=TM_ALWAYS;
   else if(ascii_strcasecmp(model,"direct")==0)
     opt.trust_model=TM_DIRECT;
+#ifdef USE_TOFU
   else if(ascii_strcasecmp(model,"tofu")==0)
     opt.trust_model=TM_TOFU;
   else if(ascii_strcasecmp(model,"tofu+pgp")==0)
     opt.trust_model=TM_TOFU_PGP;
+#endif /*USE_TOFU*/
   else if(ascii_strcasecmp(model,"auto")==0)
     opt.trust_model=TM_AUTO;
   else
@@ -1963,6 +1965,7 @@ parse_trust_model(const char *model)
 static int
 parse_tofu_policy (const char *policy)
 {
+#ifdef USE_TOFU
   if (ascii_strcasecmp (policy, "auto") == 0)
     return TOFU_POLICY_AUTO;
   else if (ascii_strcasecmp (policy, "good") == 0)
@@ -1974,6 +1977,7 @@ parse_tofu_policy (const char *policy)
   else if (ascii_strcasecmp (policy, "ask") == 0)
     return TOFU_POLICY_ASK;
   else
+#endif /*USE_TOFU*/
     {
       log_error (_("unknown TOFU policy '%s'\n"), policy);
       g10_exit (1);
@@ -1983,6 +1987,7 @@ parse_tofu_policy (const char *policy)
 static int
 parse_tofu_db_format (const char *db_format)
 {
+#ifdef USE_TOFU
   if (ascii_strcasecmp (db_format, "auto") == 0)
     return TOFU_DB_AUTO;
   else if (ascii_strcasecmp (db_format, "split") == 0)
@@ -1990,6 +1995,7 @@ parse_tofu_db_format (const char *db_format)
   else if (ascii_strcasecmp (db_format, "flat") == 0)
     return TOFU_DB_FLAT;
   else
+#endif /*USE_TOFU*/
     {
       log_error (_("unknown TOFU DB format '%s'\n"), db_format);
       g10_exit (1);
@@ -4417,6 +4423,7 @@ main (int argc, char **argv)
         break;
 
       case aTOFUPolicy:
+#ifdef USE_TOFU
        {
          int policy;
          int i;
@@ -4487,7 +4494,6 @@ main (int argc, char **argv)
                }
 
              merge_keys_and_selfsig (kb);
-
              if (tofu_set_policy (kb, policy))
                g10_exit (1);
            }
@@ -4495,6 +4501,7 @@ main (int argc, char **argv)
          keydb_release (hd);
 
        }
+#endif /*USE_TOFU*/
        break;
 
       case aListPackets:
index 432ba86..fba7d35 100644 (file)
@@ -2930,10 +2930,12 @@ show_key_with_all_names_colon (ctrl_t ctrl, estream_t fp, kbnode_t keyblock)
          es_putc (':', fp);
          if (opt.trust_model == TM_TOFU || opt.trust_model == TM_TOFU_PGP)
            {
+#ifdef USE_TOFU
              enum tofu_policy policy;
              if (! tofu_get_policy (primary, uid, &policy)
                  && policy != TOFU_POLICY_NONE)
                es_fprintf (fp, "%s", tofu_policy_str (policy));
+#endif /*USE_TOFU*/
            }
          es_putc (':', fp);
          es_putc ('\n', fp);
index 1541697..2a766a1 100644 (file)
@@ -1501,10 +1501,12 @@ list_keyblock_colon (KBNODE keyblock, int secret, int has_secret, int fpr)
          es_fprintf (es_stdout, "::::::::");
          if (opt.trust_model == TM_TOFU || opt.trust_model == TM_TOFU_PGP)
            {
+#ifdef USE_TOFU
              enum tofu_policy policy;
              if (! tofu_get_policy (pk, uid, &policy)
                  && policy != TOFU_POLICY_NONE)
                es_fprintf (es_stdout, "%s", tofu_policy_str (policy));
+#endif /*USE_TOFU*/
            }
          es_putc (':', es_stdout);
          es_putc ('\n', es_stdout);
index b0fcc5b..adf87ab 100644 (file)
@@ -106,4 +106,4 @@ gpg_error_t tofu_set_policy_by_keyid (u32 *keyid, enum tofu_policy policy);
 gpg_error_t tofu_get_policy (PKT_public_key *pk, PKT_user_id *user_id,
                             enum tofu_policy *policy);
 
-#endif
+#endif /*G10_TOFU_H*/
index f58051a..cadc7e9 100644 (file)
@@ -1001,6 +1001,7 @@ tdb_get_validity_core (PKT_public_key *pk, PKT_user_id *uid,
       goto leave;
     }
 
+#ifdef USE_TOFU
   if (opt.trust_model == TM_TOFU || opt.trust_model == TM_TOFU_PGP)
     {
       kbnode_t user_id_node = NULL; /* Silence -Wmaybe-uninitialized.  */
@@ -1078,6 +1079,7 @@ tdb_get_validity_core (PKT_public_key *pk, PKT_user_id *uid,
            break;
        }
     }
+#endif /*USE_TOFU*/
 
   if (opt.trust_model == TM_TOFU_PGP
       || opt.trust_model == TM_CLASSIC
@@ -1137,7 +1139,18 @@ tdb_get_validity_core (PKT_public_key *pk, PKT_user_id *uid,
     }
 
  leave:
+#ifdef USE_TOFU
   validity = tofu_wot_trust_combine (tofu_validity, validity);
+#else /*!USE_TOFU*/
+  validity &= TRUST_MASK;
+
+  if (validity == TRUST_NEVER)
+    /* TRUST_NEVER trumps everything else.  */
+    validity |= TRUST_NEVER;
+  if (validity == TRUST_EXPIRED)
+    /* TRUST_EXPIRED trumps everything but TRUST_NEVER.  */
+    validity |= TRUST_EXPIRED;
+#endif /*!USE_TOFU*/
 
   if (opt.trust_model != TM_TOFU
       && pending_check_trustdb)