From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.org!.POSTED!not-for-mail
From: Andy Moreton <andrewjmoreton@gmail.com>
Newsgroups: gmane.emacs.bugs
Subject: bug#25061: consider adding %COMPAT to default gnutls priority string
Date: Wed, 20 Dec 2017 16:38:20 +0000
Message-ID: <vz1mv2dz75v.fsf@gmail.com>
References: <87zikiwpl6.fsf@igalia.com>
	<CAFyQvY2W4ciqX+RbQfC5VRX+ouxoARYLx5YQvcc+q_hKE7+QOg@mail.gmail.com>
	<87shc6k3tf.fsf@lifelogs.com>
	<CAFyQvY02a=ZZZyzH3FSkOYSAPDpwzVhxUR9Qa3QO9-2gTwEG+w@mail.gmail.com>
	<87bmiujjdg.fsf@lifelogs.com> <vz1d139k19m.fsf@gmail.com>
	<83lghxnzi9.fsf@gnu.org>
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: blaine.gmane.org 1513788498 14044 195.159.176.226 (20 Dec 2017 16:48:18 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 20 Dec 2017 16:48:18 +0000 (UTC)
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (windows-nt)
To: 25061@debbugs.gnu.org
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Dec 20 17:48:14 2017
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>
Envelope-to: geb-bug-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([208.118.235.17])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>)
	id 1eRhXJ-0002k6-QR
	for geb-bug-gnu-emacs@m.gmane.org; Wed, 20 Dec 2017 17:48:06 +0100
Original-Received: from localhost ([::1]:59119 helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>)
	id 1eRhZI-0001On-4M
	for geb-bug-gnu-emacs@m.gmane.org; Wed, 20 Dec 2017 11:50:08 -0500
Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57537)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1eRhWR-0007pI-54
	for bug-gnu-emacs@gnu.org; Wed, 20 Dec 2017 11:47:16 -0500
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1eRhWI-0002Qf-F0
	for bug-gnu-emacs@gnu.org; Wed, 20 Dec 2017 11:47:11 -0500
Original-Received: from debbugs.gnu.org ([208.118.235.43]:35982)
	by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
	(Exim 4.71) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
	id 1eRhWI-0002QR-7E
	for bug-gnu-emacs@gnu.org; Wed, 20 Dec 2017 11:47:02 -0500
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
	(envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1eRhWH-0006xU-Vg
	for bug-gnu-emacs@gnu.org; Wed, 20 Dec 2017 11:47:02 -0500
X-Loop: help-debbugs@gnu.org
In-Reply-To: <87zikiwpl6.fsf@igalia.com>
Resent-From: Andy Moreton <andrewjmoreton@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Wed, 20 Dec 2017 16:47:01 +0000
Resent-Message-ID: <handler.25061.B.151378841826738@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 25061
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
X-Debbugs-Original-To: bug-gnu-emacs@gnu.org
Original-Received: via spool by submit@debbugs.gnu.org id=B.151378841826738
	(code B ref -1); Wed, 20 Dec 2017 16:47:01 +0000
Original-Received: (at submit) by debbugs.gnu.org; 20 Dec 2017 16:46:58 +0000
Original-Received: from localhost ([127.0.0.1]:44663 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
	id 1eRhWE-0006xC-96
	for submit@debbugs.gnu.org; Wed, 20 Dec 2017 11:46:58 -0500
Original-Received: from eggs.gnu.org ([208.118.235.92]:37603)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <geb-bug-gnu-emacs@m.gmane.org>) id 1eRhWD-0006x0-3L
	for submit@debbugs.gnu.org; Wed, 20 Dec 2017 11:46:57 -0500
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <geb-bug-gnu-emacs@m.gmane.org>) id 1eRhVq-0001tA-RG
	for submit@debbugs.gnu.org; Wed, 20 Dec 2017 11:46:51 -0500
Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:37300)
	by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
	(Exim 4.71) (envelope-from <geb-bug-gnu-emacs@m.gmane.org>)
	id 1eRhVq-0001ii-Ks
	for submit@debbugs.gnu.org; Wed, 20 Dec 2017 11:46:34 -0500
Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43365)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <geb-bug-gnu-emacs@m.gmane.org>) id 1eRhO6-0001v5-TG
	for bug-gnu-emacs@gnu.org; Wed, 20 Dec 2017 11:38:36 -0500
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <geb-bug-gnu-emacs@m.gmane.org>) id 1eRhO3-0001nV-Vc
	for bug-gnu-emacs@gnu.org; Wed, 20 Dec 2017 11:38:34 -0500
Original-Received: from [195.159.176.226] (port=41142 helo=blaine.gmane.org)
	by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
	(Exim 4.71) (envelope-from <geb-bug-gnu-emacs@m.gmane.org>)
	id 1eRhO3-0001mJ-NP
	for bug-gnu-emacs@gnu.org; Wed, 20 Dec 2017 11:38:31 -0500
Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2)
	(envelope-from <geb-bug-gnu-emacs@m.gmane.org>) id 1eRhLz-0003go-VD
	for bug-gnu-emacs@gnu.org; Wed, 20 Dec 2017 17:36:23 +0100
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 140
Original-X-Complaints-To: usenet@blaine.gmane.org
Cancel-Lock: sha1:zO9dOdjqgCBU8TP3Oy7klRjrbz8=
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
	[fuzzy]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 208.118.235.43
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
	the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
	<mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/bug-gnu-emacs/>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
	<mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org
Original-Sender: "bug-gnu-emacs"
	<bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>
Xref: news.gmane.org gmane.emacs.bugs:141299
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/141299>

On Wed 20 Dec 2017, Eli Zaretskii wrote:

>> From: Andy Moreton <andrewjmoreton@gmail.com>
>> Date: Wed, 20 Dec 2017 12:54:45 +0000
>> 
>> diff --git a/src/gnutls.c b/src/gnutls.c
>> index 8db201ae83..f2b078d964 100644
>> --- a/src/gnutls.c
>> +++ b/src/gnutls.c
>> @@ -238,6 +238,7 @@ DEF_DLL_FN (int, gnutls_hash, (gnutls_hash_hd_t, const void *, size_t));
>>  DEF_DLL_FN (void, gnutls_hash_deinit, (gnutls_hash_hd_t, void *));
>>  DEF_DLL_FN (void, gnutls_hash_output, (gnutls_hash_hd_t, void *));
>>  #  endif        /* HAVE_GNUTLS3 */
>> +DEF_DLL_FN (const char *, gnutls_ext_get_name, (unsigned int));
>> 
>> 
>>  static bool
>> @@ -357,6 +358,7 @@ init_gnutls_functions (void)
>>    LOAD_DLL_FN (library, gnutls_hash_deinit);
>>    LOAD_DLL_FN (library, gnutls_hash_output);
>>  #  endif        /* HAVE_GNUTLS3 */
>> +  LOAD_DLL_FN (library, gnutls_ext_get_name);
>> 
>>    max_log_level = global_gnutls_log_level;
>> 
>> @@ -470,6 +472,8 @@ init_gnutls_functions (void)
>>  #  define gnutls_hash_deinit fn_gnutls_hash_deinit
>>  #  define gnutls_hash_output fn_gnutls_hash_output
>>  #  endif        /* HAVE_GNUTLS3 */
>> +#  define gnutls_ext_get_name fn_gnutls_ext_get_name
>
> Thanks, but this means Emacs will now refuse to load GnuTLS on systems
> that have version 3.4 or older of the library, right?  If so, I think
> the loading and the use of the function should be conditioned by an
> appropriate preprocessor directive to compile that code only for
> 3.5.X.

Agreed. This version also fixes a bug in the previous version, where
the capabilities stored in Vlibrary_cache were not updated properly.


diff --git a/src/gnutls.c b/src/gnutls.c
index 8db201ae83..48ea25397a 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -46,6 +46,10 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 # define HAVE_GNUTLS_MAC_GET_NONCE_SIZE
 #endif
 
+#if GNUTLS_VERSION_NUMBER >= 0x030501
+# define HAVE_GNUTLS_EXT_GET_NAME
+#endif
+
 #ifdef HAVE_GNUTLS
 
 # ifdef WINDOWSNT
@@ -237,6 +241,9 @@ DEF_DLL_FN (int, gnutls_hash_get_len, (gnutls_digest_algorithm_t));
 DEF_DLL_FN (int, gnutls_hash, (gnutls_hash_hd_t, const void *, size_t));
 DEF_DLL_FN (void, gnutls_hash_deinit, (gnutls_hash_hd_t, void *));
 DEF_DLL_FN (void, gnutls_hash_output, (gnutls_hash_hd_t, void *));
+#   ifdef HAVE_GNUTLS_EXT_GET_NAME
+DEF_DLL_FN (const char *, gnutls_ext_get_name, (unsigned int));
+#   endif
 #  endif	 /* HAVE_GNUTLS3 */
 
 
@@ -356,6 +363,9 @@ init_gnutls_functions (void)
   LOAD_DLL_FN (library, gnutls_hash);
   LOAD_DLL_FN (library, gnutls_hash_deinit);
   LOAD_DLL_FN (library, gnutls_hash_output);
+#   ifdef HAVE_GNUTLS_EXT_GET_NAME
+  LOAD_DLL_FN (library, gnutls_ext_get_name);
+#   endif
 #  endif	 /* HAVE_GNUTLS3 */
 
   max_log_level = global_gnutls_log_level;
@@ -469,8 +479,12 @@ init_gnutls_functions (void)
 #  define gnutls_hash fn_gnutls_hash
 #  define gnutls_hash_deinit fn_gnutls_hash_deinit
 #  define gnutls_hash_output fn_gnutls_hash_output
+#   ifdef HAVE_GNUTLS_EXT_GET_NAME
+#    define gnutls_ext_get_name fn_gnutls_ext_get_name
+#   endif
 #  endif	 /* HAVE_GNUTLS3 */
 
+
 /* This wrapper is called from fns.c, which doesn't know about the
    LOAD_DLL_FN stuff above.  */
 int
@@ -2425,6 +2439,18 @@ Any GnuTLS extension with ID up to 100
 
 #ifdef HAVE_GNUTLS
 
+# ifdef WINDOWSNT
+  Lisp_Object found = Fassq (Qgnutls, Vlibrary_cache);
+  if (CONSP (found))
+    return XCDR (found);
+
+  /* Load the GnuTLS DLL and find exported functions.  The external
+     library cache is updated after the capabilities have been
+     determined.  */
+  if (!init_gnutls_functions ())
+    return Qnil;
+# endif /* WINDOWSNT */
+
   capabilities = Fcons (intern("gnutls"), capabilities);
 
 # ifdef HAVE_GNUTLS3
@@ -2437,8 +2463,8 @@ Any GnuTLS extension with ID up to 100
 #  endif
 
   capabilities = Fcons (intern("macs"), capabilities);
-# endif	  /* HAVE_GNUTLS3 */
 
+#  ifdef HAVE_GNUTLS_EXT_GET_NAME
   for (unsigned int ext=0; ext < 100; ext++)
     {
       const char* name = gnutls_ext_get_name(ext);
@@ -2447,18 +2473,11 @@ Any GnuTLS extension with ID up to 100
           capabilities = Fcons (intern(name), capabilities);
         }
     }
+#  endif
+# endif	  /* HAVE_GNUTLS3 */
 
 # ifdef WINDOWSNT
-  Lisp_Object found = Fassq (Qgnutls, Vlibrary_cache);
-  if (CONSP (found))
-    return XCDR (found);
-  else
-    {
-      Lisp_Object status;
-      status = init_gnutls_functions () ? capabilities : Qnil;
-      Vlibrary_cache = Fcons (Fcons (Qgnutls, status), Vlibrary_cache);
-      return status;
-    }
+  Vlibrary_cache = Fcons (Fcons (Qgnutls, capabilities), Vlibrary_cache);
 # endif /* WINDOWSNT */
 #endif	/* HAVE_GNUTLS */