mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-06 16:21:50 +00:00
2008-09-08 Dan Williams <dcbw@redhat.com>
Patch from Alexander Sack <asac@ubuntu.com> * libnm-util/crypto_gnutls.c libnm-util/crypto_nss.c - (crypto_init, crypto_deinit): just use a boolean instead of a refcount * libnm-util/nm-utils.c libnm-util/nm-utils.h libnm-util/libnm-util.ver - (nm_utils_init): initialize libnm-util - (nm_utils_deinit): de-initialize libnm-util and clean up resources * libnm-util/nm-setting-8021x.c - (nm_setting_802_1x_class_init): init libnm-util when needed git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4047 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
a5de3b4656
commit
796829ce62
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
2008-09-08 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
Patch from Alexander Sack <asac@ubuntu.com>
|
||||
|
||||
* libnm-util/crypto_gnutls.c
|
||||
libnm-util/crypto_nss.c
|
||||
- (crypto_init, crypto_deinit): just use a boolean instead of a refcount
|
||||
|
||||
* libnm-util/nm-utils.c
|
||||
libnm-util/nm-utils.h
|
||||
libnm-util/libnm-util.ver
|
||||
- (nm_utils_init): initialize libnm-util
|
||||
- (nm_utils_deinit): de-initialize libnm-util and clean up resources
|
||||
|
||||
* libnm-util/nm-setting-8021x.c
|
||||
- (nm_setting_802_1x_class_init): init libnm-util when needed
|
||||
|
||||
2008-09-05 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
Patch from Roy Marples <roy@marples.name> and others
|
||||
|
|
|
@ -29,30 +29,31 @@
|
|||
|
||||
#include "crypto.h"
|
||||
|
||||
static guint32 refcount = 0;
|
||||
static gboolean initialized = FALSE;
|
||||
|
||||
gboolean
|
||||
crypto_init (GError **error)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (initialized)
|
||||
return TRUE;
|
||||
|
||||
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++;
|
||||
|
||||
initialized = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
crypto_deinit (void)
|
||||
{
|
||||
refcount--;
|
||||
if (refcount == 0)
|
||||
if (initialized)
|
||||
gnutls_global_deinit();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,33 +33,35 @@
|
|||
|
||||
#include "crypto.h"
|
||||
|
||||
static guint32 refcount = 0;
|
||||
static gboolean initialized = FALSE;
|
||||
|
||||
gboolean
|
||||
crypto_init (GError **error)
|
||||
{
|
||||
if (refcount == 0) {
|
||||
SECStatus ret;
|
||||
SECStatus ret;
|
||||
|
||||
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 1);
|
||||
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;
|
||||
}
|
||||
if (initialized)
|
||||
return TRUE;
|
||||
|
||||
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 1);
|
||||
ret = NSS_NoDB_Init (NULL);
|
||||
if (ret != SECSuccess) {
|
||||
PR_Cleanup ();
|
||||
g_set_error (error, NM_CRYPTO_ERROR,
|
||||
NM_CRYPTO_ERR_INIT_FAILED,
|
||||
_("Failed to initialize the crypto engine: %d."),
|
||||
PR_GetError ());
|
||||
return FALSE;
|
||||
}
|
||||
refcount++;
|
||||
|
||||
initialized = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
crypto_deinit (void)
|
||||
{
|
||||
refcount--;
|
||||
if (refcount == 0) {
|
||||
if (initialized) {
|
||||
NSS_Shutdown ();
|
||||
PR_Cleanup ();
|
||||
}
|
||||
|
|
|
@ -99,8 +99,10 @@ global:
|
|||
nm_setting_wireless_security_error_quark;
|
||||
nm_setting_wireless_security_get_type;
|
||||
nm_setting_wireless_security_new;
|
||||
nm_utils_deinit;
|
||||
nm_utils_escape_ssid;
|
||||
nm_utils_gvalue_hash_dup;
|
||||
nm_utils_init;
|
||||
nm_utils_ip4_addresses_from_gvalue;
|
||||
nm_utils_ip4_addresses_to_gvalue;
|
||||
nm_utils_ip4_netmask_to_prefix;
|
||||
|
|
|
@ -902,8 +902,8 @@ nm_setting_802_1x_class_init (NMSetting8021xClass *setting_class)
|
|||
G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET));
|
||||
|
||||
/* Initialize crypto lbrary. */
|
||||
if (!crypto_init (&error)) {
|
||||
g_warning ("Couldn't initilize crypto system: %d %s",
|
||||
if (!nm_utils_init (&error)) {
|
||||
g_warning ("Couldn't initilize nm-utils/crypto system: %d %s",
|
||||
error->code, error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
|
|
@ -242,6 +242,34 @@ string_to_utf8 (const char *str, gsize len)
|
|||
return converted;
|
||||
}
|
||||
|
||||
/* init, deinit for libnm_util */
|
||||
|
||||
static gboolean initialized = FALSE;
|
||||
|
||||
gboolean
|
||||
nm_utils_init (GError **error)
|
||||
{
|
||||
if (!initialized) {
|
||||
if (!crypto_init (error)) {
|
||||
return FALSE;
|
||||
}
|
||||
atexit (nm_utils_deinit);
|
||||
initialized = TRUE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nm_utils_deinit (void)
|
||||
{
|
||||
if (initialized) {
|
||||
crypto_deinit ();
|
||||
initialized = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* ssid helpers */
|
||||
|
||||
char *
|
||||
nm_utils_ssid_to_utf8 (const char *ssid, guint32 len)
|
||||
{
|
||||
|
@ -1128,7 +1156,7 @@ nm_utils_uuid_generate_from_string (const char *s)
|
|||
uuid_t *uuid;
|
||||
char *buf = NULL;
|
||||
|
||||
if (!crypto_init (&error)) {
|
||||
if (!nm_utils_init (&error)) {
|
||||
nm_warning ("error initializing crypto: (%d) %s",
|
||||
error ? error->code : 0,
|
||||
error ? error->message : "unknown");
|
||||
|
@ -1152,7 +1180,6 @@ nm_utils_uuid_generate_from_string (const char *s)
|
|||
|
||||
out:
|
||||
g_free (uuid);
|
||||
crypto_deinit ();
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -136,6 +136,10 @@ G_STMT_START \
|
|||
G_BREAKPOINT (); \
|
||||
} G_STMT_END
|
||||
|
||||
/* init, deinit nm_utils */
|
||||
gboolean nm_utils_init (GError **error);
|
||||
void nm_utils_deinit (void);
|
||||
|
||||
/* SSID helpers */
|
||||
gboolean nm_utils_is_empty_ssid (const guint8 * ssid, int len);
|
||||
const char *nm_utils_escape_ssid (const guint8 *ssid, guint32 len);
|
||||
|
|
Loading…
Reference in a new issue