Merge pull request #8518 from neheb/i
[feed/packages.git] / mail / dovecot / patches / 110-openssl-engine.patch
1 --- a/src/lib-dcrypt/dcrypt-openssl.c
2 +++ b/src/lib-dcrypt/dcrypt-openssl.c
3 @@ -17,10 +17,12 @@
4 #include <openssl/bio.h>
5 #include <openssl/pem.h>
6 #include <openssl/x509.h>
7 -#include <openssl/engine.h>
8 #include <openssl/hmac.h>
9 #include <openssl/objects.h>
10 #include <openssl/bn.h>
11 +#ifndef OPENSSL_NO_ENGINE
12 +#include <openssl/engine.h>
13 +#endif
14 #include "dcrypt.h"
15 #include "dcrypt-private.h"
16
17 @@ -179,11 +181,13 @@ static bool dcrypt_openssl_error(const char **error_r)
18 static bool dcrypt_openssl_initialize(const struct dcrypt_settings *set,
19 const char **error_r)
20 {
21 +#ifndef OPENSSL_NO_ENGINE
22 if (set->crypto_device != NULL && set->crypto_device[0] != '\0') {
23 if (dovecot_openssl_common_global_set_engine(
24 set->crypto_device, error_r) <= 0)
25 return FALSE;
26 }
27 +#endif
28 return TRUE;
29 }
30
31 --- a/src/lib-ssl-iostream/dovecot-openssl-common.c
32 +++ b/src/lib-ssl-iostream/dovecot-openssl-common.c
33 @@ -5,11 +5,14 @@
34 #include "dovecot-openssl-common.h"
35
36 #include <openssl/ssl.h>
37 -#include <openssl/engine.h>
38 #include <openssl/rand.h>
39 +#ifndef OPENSSL_NO_ENGINE
40 +#include <openssl/engine.h>
41
42 -static int openssl_init_refcount = 0;
43 static ENGINE *dovecot_openssl_engine;
44 +#endif
45 +
46 +static int openssl_init_refcount = 0;
47
48 #ifdef HAVE_SSL_NEW_MEM_FUNCS
49 static void *dovecot_openssl_malloc(size_t size, const char *u0 ATTR_UNUSED, int u1 ATTR_UNUSED)
50 @@ -77,10 +80,12 @@ bool dovecot_openssl_common_global_unref(void)
51 if (--openssl_init_refcount > 0)
52 return TRUE;
53
54 +#ifndef OPENSSL_NO_ENGINE
55 if (dovecot_openssl_engine != NULL) {
56 ENGINE_finish(dovecot_openssl_engine);
57 dovecot_openssl_engine = NULL;
58 }
59 +#endif
60 #if OPENSSL_VERSION_NUMBER < 0x10100000L
61 /* OBJ_cleanup() is called automatically by EVP_cleanup() in
62 newer versions. Doesn't hurt to call it anyway. */
63 @@ -88,7 +93,9 @@ bool dovecot_openssl_common_global_unref(void)
64 #ifdef HAVE_SSL_COMP_FREE_COMPRESSION_METHODS
65 SSL_COMP_free_compression_methods();
66 #endif
67 +#ifndef OPENSSL_NO_ENGINE
68 ENGINE_cleanup();
69 +#endif
70 EVP_cleanup();
71 CRYPTO_cleanup_all_ex_data();
72 #ifdef HAVE_OPENSSL_AUTO_THREAD_DEINIT
73 @@ -111,6 +118,7 @@ bool dovecot_openssl_common_global_unref(void)
74 int dovecot_openssl_common_global_set_engine(const char *engine,
75 const char **error_r)
76 {
77 +#ifndef OPENSSL_NO_ENGINE
78 if (dovecot_openssl_engine != NULL)
79 return 1;
80
81 @@ -132,5 +140,6 @@ int dovecot_openssl_common_global_set_engine(const char *engine,
82 dovecot_openssl_engine = NULL;
83 return -1;
84 }
85 +#endif
86 return 1;
87 }