diff options
author | Cedric BAIL <cedric.bail@samsung.com> | 2015-03-17 08:50:03 +0100 |
---|---|---|
committer | Cedric BAIL <cedric@osg.samsung.com> | 2015-03-17 09:58:17 +0100 |
commit | 32c5f691c89c84c522c606feed58f02eebd81c6b (patch) | |
tree | e1198172b58cbd04b926a9407a2f6c443d93fb37 /src/lib/emile/emile_main.c | |
parent | f9dd639a92399006090ceb57dd141f6b247895f3 (diff) |
emile: make cipher initialization optional.
Diffstat (limited to '')
-rw-r--r-- | src/lib/emile/emile_main.c | 78 |
1 files changed, 46 insertions, 32 deletions
diff --git a/src/lib/emile/emile_main.c b/src/lib/emile/emile_main.c index 9171b565a6..63f1c5aa8a 100644 --- a/src/lib/emile/emile_main.c +++ b/src/lib/emile/emile_main.c | |||
@@ -23,24 +23,14 @@ | |||
23 | GCRY_THREAD_OPTION_PTHREAD_IMPL; | 23 | GCRY_THREAD_OPTION_PTHREAD_IMPL; |
24 | #endif /* ifdef HAVE_GNUTLS */ | 24 | #endif /* ifdef HAVE_GNUTLS */ |
25 | 25 | ||
26 | static Eina_Bool _emile_cipher_init = EINA_FALSE; | ||
26 | static unsigned int _emile_init_count = 0; | 27 | static unsigned int _emile_init_count = 0; |
27 | int _emile_log_dom_global = -1; | 28 | int _emile_log_dom_global = -1; |
28 | 29 | ||
29 | EAPI int | 30 | EAPI Eina_Bool |
30 | emile_init(void) | 31 | emile_cipher_init(void) |
31 | { | 32 | { |
32 | if (++_emile_init_count != 1) | 33 | if (_emile_cipher_init) return EINA_TRUE; |
33 | return _emile_init_count; | ||
34 | |||
35 | if (!eina_init()) | ||
36 | return --_emile_init_count; | ||
37 | |||
38 | _emile_log_dom_global = eina_log_domain_register("emile", EINA_COLOR_CYAN); | ||
39 | if (_emile_log_dom_global < 0) | ||
40 | { | ||
41 | EINA_LOG_ERR("Emile can not create a general log domain."); | ||
42 | goto shutdown_eina; | ||
43 | } | ||
44 | 34 | ||
45 | #ifdef HAVE_GNUTLS | 35 | #ifdef HAVE_GNUTLS |
46 | /* Before the library can be used, it must initialize itself if needed. */ | 36 | /* Before the library can be used, it must initialize itself if needed. */ |
@@ -50,7 +40,7 @@ emile_init(void) | |||
50 | /* Disable warning messages about problems with the secure memory subsystem. | 40 | /* Disable warning messages about problems with the secure memory subsystem. |
51 | This command should be run right after gcry_check_version. */ | 41 | This command should be run right after gcry_check_version. */ |
52 | if (gcry_control(GCRYCTL_DISABLE_SECMEM_WARN)) | 42 | if (gcry_control(GCRYCTL_DISABLE_SECMEM_WARN)) |
53 | goto shutdown_eet; /* This command is used to allocate a pool of secure memory and thus | 43 | return EINA_FALSE; /* This command is used to allocate a pool of secure memory and thus |
54 | enabling the use of secure memory. It also drops all extra privileges the | 44 | enabling the use of secure memory. It also drops all extra privileges the |
55 | process has (i.e. if it is run as setuid (root)). If the argument nbytes | 45 | process has (i.e. if it is run as setuid (root)). If the argument nbytes |
56 | is 0, secure memory will be disabled. The minimum amount of secure memory | 46 | is 0, secure memory will be disabled. The minimum amount of secure memory |
@@ -67,7 +57,7 @@ emile_init(void) | |||
67 | "YOU ARE USING PTHREADS, BUT I CANNOT INITIALIZE THREADSAFE GCRYPT OPERATIONS!"); | 57 | "YOU ARE USING PTHREADS, BUT I CANNOT INITIALIZE THREADSAFE GCRYPT OPERATIONS!"); |
68 | 58 | ||
69 | if (gnutls_global_init()) | 59 | if (gnutls_global_init()) |
70 | goto shutdown_eet; | 60 | return EINA_FALSE; |
71 | 61 | ||
72 | #endif /* ifdef HAVE_GNUTLS */ | 62 | #endif /* ifdef HAVE_GNUTLS */ |
73 | #ifdef HAVE_OPENSSL | 63 | #ifdef HAVE_OPENSSL |
@@ -77,6 +67,27 @@ emile_init(void) | |||
77 | OpenSSL_add_all_algorithms(); | 67 | OpenSSL_add_all_algorithms(); |
78 | #endif /* ifdef HAVE_OPENSSL */ | 68 | #endif /* ifdef HAVE_OPENSSL */ |
79 | 69 | ||
70 | _emile_cipher_init = EINA_TRUE; | ||
71 | |||
72 | return EINA_TRUE; | ||
73 | } | ||
74 | |||
75 | EAPI int | ||
76 | emile_init(void) | ||
77 | { | ||
78 | if (++_emile_init_count != 1) | ||
79 | return _emile_init_count; | ||
80 | |||
81 | if (!eina_init()) | ||
82 | return --_emile_init_count; | ||
83 | |||
84 | _emile_log_dom_global = eina_log_domain_register("emile", EINA_COLOR_CYAN); | ||
85 | if (_emile_log_dom_global < 0) | ||
86 | { | ||
87 | EINA_LOG_ERR("Emile can not create a general log domain."); | ||
88 | goto shutdown_eina; | ||
89 | } | ||
90 | |||
80 | eina_log_timing(_emile_log_dom_global, | 91 | eina_log_timing(_emile_log_dom_global, |
81 | EINA_LOG_STATE_STOP, | 92 | EINA_LOG_STATE_STOP, |
82 | EINA_LOG_STATE_INIT); | 93 | EINA_LOG_STATE_INIT); |
@@ -99,26 +110,29 @@ emile_shutdown(void) | |||
99 | EINA_LOG_STATE_START, | 110 | EINA_LOG_STATE_START, |
100 | EINA_LOG_STATE_SHUTDOWN); | 111 | EINA_LOG_STATE_SHUTDOWN); |
101 | 112 | ||
113 | if (_emile_cipher_init) | ||
114 | { | ||
102 | #ifdef HAVE_GNUTLS | 115 | #ifdef HAVE_GNUTLS |
103 | /* Note that gnutls has a leak where it doesnt free stuff it alloced | 116 | /* Note that gnutls has a leak where it doesnt free stuff it alloced |
104 | * on init. valgrind trace here: | 117 | * on init. valgrind trace here: |
105 | * 21 bytes in 1 blocks are definitely lost in loss record 24 of 194 | 118 | * 21 bytes in 1 blocks are definitely lost in loss record 24 of 194 |
106 | * at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) | 119 | * at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) |
107 | * by 0x68AC801: strdup (strdup.c:43) | 120 | * by 0x68AC801: strdup (strdup.c:43) |
108 | * by 0xD215B6A: p11_kit_registered_module_to_name (in /usr/lib/x86_64-linux-gnu/libp11-kit.so.0.0.0) | 121 | * by 0xD215B6A: p11_kit_registered_module_to_name (in /usr/lib/x86_64-linux-gnu/libp11-kit.so.0.0.0) |
109 | * by 0x9571574: gnutls_pkcs11_init (in /usr/lib/x86_64-linux-gnu/libgnutls.so.26.21.8) | 122 | * by 0x9571574: gnutls_pkcs11_init (in /usr/lib/x86_64-linux-gnu/libgnutls.so.26.21.8) |
110 | * by 0x955B031: gnutls_global_init (in /usr/lib/x86_64-linux-gnu/libgnutls.so.26.21.8) | 123 | * by 0x955B031: gnutls_global_init (in /usr/lib/x86_64-linux-gnu/libgnutls.so.26.21.8) |
111 | * by 0x6DFD6D0: eet_init (eet_lib.c:608) | 124 | * by 0x6DFD6D0: eet_init (eet_lib.c:608) |
112 | * | 125 | * |
113 | * yes - i've tried calling gnutls_pkcs11_deinit() by hand but no luck. | 126 | * yes - i've tried calling gnutls_pkcs11_deinit() by hand but no luck. |
114 | * the leak is in there. | 127 | * the leak is in there. |
115 | */ | 128 | */ |
116 | gnutls_global_deinit(); | 129 | gnutls_global_deinit(); |
117 | #endif /* ifdef HAVE_GNUTLS */ | 130 | #endif /* ifdef HAVE_GNUTLS */ |
118 | #ifdef HAVE_OPENSSL | 131 | #ifdef HAVE_OPENSSL |
119 | EVP_cleanup(); | 132 | EVP_cleanup(); |
120 | ERR_free_strings(); | 133 | ERR_free_strings(); |
121 | #endif /* ifdef HAVE_OPENSSL */ | 134 | #endif /* ifdef HAVE_OPENSSL */ |
135 | } | ||
122 | 136 | ||
123 | eina_log_domain_unregister(_emile_log_dom_global); | 137 | eina_log_domain_unregister(_emile_log_dom_global); |
124 | _emile_log_dom_global = -1; | 138 | _emile_log_dom_global = -1; |