From bb6b79a2a623cf401a9c7b81979f40911dede7e1 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 5 Sep 2008 18:10:39 +0000 Subject: [PATCH] 2008-09-05 Dan Williams * libnm-util/crypto_nss.c libnm-util/crypto_gnutls.c libnm-util/crypto.h - (crypto_init): return error when init fails git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4042 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 7 +++++++ libnm-util/crypto.h | 1 + libnm-util/crypto_gnutls.c | 12 ++++++++++-- libnm-util/crypto_nss.c | 12 +++++++++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70e7c086c3..5fed9c539c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-09-05 Dan Williams + + * libnm-util/crypto_nss.c + libnm-util/crypto_gnutls.c + libnm-util/crypto.h + - (crypto_init): return error when init fails + 2008-09-05 Dan Williams * libnm-glib/nm-device-wifi.c diff --git a/libnm-util/crypto.h b/libnm-util/crypto.h index 0481efa4b1..7cfd25c229 100644 --- a/libnm-util/crypto.h +++ b/libnm-util/crypto.h @@ -29,6 +29,7 @@ enum { NM_CRYPTO_ERR_NONE = 0, + NM_CRYPTO_ERR_INIT_FAILED, NM_CRYPTO_ERR_CANT_READ_FILE, NM_CRYPTO_ERR_PEM_FORMAT_INVALID, NM_CRYPTO_ERR_CERT_FORMAT_INVALID, diff --git a/libnm-util/crypto_gnutls.c b/libnm-util/crypto_gnutls.c index 16a92a9f26..922f379215 100644 --- a/libnm-util/crypto_gnutls.c +++ b/libnm-util/crypto_gnutls.c @@ -34,8 +34,16 @@ static guint32 refcount = 0; gboolean crypto_init (GError **error) { - if (refcount == 0) - gnutls_global_init(); + if (refcount == 0) { + if (gnutls_global_init() != 0) { + gnutls_global_deinit(); + g_set_error (error, NM_CRYPTO_ERROR, + NM_CRYPTO_ERR_INIT_FAILED, + "%s", + _("Failed to initialize the crypto engine.")); + return FALSE; + } + } refcount++; return TRUE; } diff --git a/libnm-util/crypto_nss.c b/libnm-util/crypto_nss.c index b938f4253d..fae4f6d4d2 100644 --- a/libnm-util/crypto_nss.c +++ b/libnm-util/crypto_nss.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "crypto.h" @@ -38,8 +39,17 @@ gboolean crypto_init (GError **error) { if (refcount == 0) { + SECStatus ret; + PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 1); - NSS_NoDB_Init (NULL); + ret = NSS_NoDB_Init (NULL); + if (ret != SECSuccess) { + g_set_error (error, NM_CRYPTO_ERROR, + NM_CRYPTO_ERR_INIT_FAILED, + _("Failed to initialize the crypto engine: %d."), + PR_GetError ()); + return FALSE; + } } refcount++; return TRUE;