[gnome-keyring] Simpler way to define secure memory callbacks.



commit 1ae76c6396141dfc6736395090779fa0d15764f9
Author: Stef Walter <stef memberwebs com>
Date:   Tue Jun 8 03:26:14 2010 +0000

    Simpler way to define secure memory callbacks.
    
     * Also define locking on the daemon.

 daemon/gkd-main.c                           |    6 ++++--
 daemon/ssh-agent/gkd-ssh-agent-standalone.c |   11 +----------
 egg/egg-secure-memory.h                     |    8 ++++++++
 pkcs11/gkm/tests/dump-data-file.c           |    7 +------
 pkcs11/roots-store/gkm-roots-standalone.c   |    8 +-------
 pkcs11/secret-store/gkm-secret-standalone.c |    8 +-------
 pkcs11/ssh-store/gkm-ssh-standalone.c       |    8 +-------
 pkcs11/user-store/gkm-user-standalone.c     |    8 +-------
 tests/gtest-helpers.c                       |   16 +---------------
 9 files changed, 19 insertions(+), 61 deletions(-)
---
diff --git a/daemon/gkd-main.c b/daemon/gkd-main.c
index 55790eb..f9d9764 100644
--- a/daemon/gkd-main.c
+++ b/daemon/gkd-main.c
@@ -160,16 +160,18 @@ static gboolean do_warning = TRUE;
  * locking for memory between threads
  */
 
+G_LOCK_DEFINE_STATIC (memory_mutex);
+
 void
 egg_memory_lock (void)
 {
-	/* The daemon uses cooperative threading, and doesn't need locking */
+	G_LOCK (memory_mutex);
 }
 
 void
 egg_memory_unlock (void)
 {
-	/* The daemon uses cooperative threading, and doesn't need locking */
+	G_LOCK (memory_mutex);
 }
 
 void*
diff --git a/daemon/ssh-agent/gkd-ssh-agent-standalone.c b/daemon/ssh-agent/gkd-ssh-agent-standalone.c
index 349f86d..d9c1b0a 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-standalone.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-standalone.c
@@ -37,16 +37,7 @@
 #include <string.h>
 #include <unistd.h>
 
-G_LOCK_DEFINE_STATIC (memory_mutex);
-
-void egg_memory_lock (void)
-	{ G_LOCK (memory_mutex); }
-
-void egg_memory_unlock (void)
-	{ G_UNLOCK (memory_mutex); }
-
-void* egg_memory_fallback (void *p, size_t sz)
-	{ return g_realloc (p, sz); }
+EGG_SECURE_GLIB_DEFINITIONS();
 
 static gboolean
 accept_client (GIOChannel *channel, GIOCondition cond, gpointer unused)
diff --git a/egg/egg-secure-memory.h b/egg/egg-secure-memory.h
index 5bb3e12..85ce1f6 100644
--- a/egg/egg-secure-memory.h
+++ b/egg/egg-secure-memory.h
@@ -55,6 +55,14 @@ extern void   egg_memory_unlock (void);
  */
 extern void*  egg_memory_fallback (void *p, size_t length);
 
+#define EGG_SECURE_GLIB_DEFINITIONS() \
+	static GStaticMutex memory_mutex = G_STATIC_MUTEX_INIT; \
+	void egg_memory_lock (void) \
+		{ g_static_mutex_lock (&memory_mutex); } \
+	void egg_memory_unlock (void) \
+		{ g_static_mutex_unlock (&memory_mutex); } \
+	void* egg_memory_fallback (void *p, size_t sz) \
+		{ return g_realloc (p, sz); } \
 
 /* 
  * Main functionality
diff --git a/pkcs11/gkm/tests/dump-data-file.c b/pkcs11/gkm/tests/dump-data-file.c
index d0a7442..aa2e763 100644
--- a/pkcs11/gkm/tests/dump-data-file.c
+++ b/pkcs11/gkm/tests/dump-data-file.c
@@ -36,12 +36,7 @@
 #include <string.h>
 #include <unistd.h>
 
-void egg_memory_lock (void)
-	{ }
-void egg_memory_unlock (void)
-	{ }
-void* egg_memory_fallback (void *p, size_t sz)
-	{ return g_realloc (p, sz); }
+EGG_SECURE_GLIB_DEFINITIONS ();
 
 static void G_GNUC_NORETURN
 failure (const gchar* message, ...)
diff --git a/pkcs11/roots-store/gkm-roots-standalone.c b/pkcs11/roots-store/gkm-roots-standalone.c
index 946571a..a52c4dc 100644
--- a/pkcs11/roots-store/gkm-roots-standalone.c
+++ b/pkcs11/roots-store/gkm-roots-standalone.c
@@ -34,13 +34,7 @@
 #include "pkcs11/pkcs11.h"
 
 /* Module callbacks for secure memory */
-static GStaticMutex memory_mutex = G_STATIC_MUTEX_INIT;
-void egg_memory_lock (void)
-	{ g_static_mutex_lock (&memory_mutex); }
-void egg_memory_unlock (void)
-	{ g_static_mutex_unlock (&memory_mutex); }
-void* egg_memory_fallback (void *p, size_t sz)
-	{ return g_realloc (p, sz); }
+EGG_SECURE_GLIB_DEFINITIONS ();
 
 CK_RV
 C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
diff --git a/pkcs11/secret-store/gkm-secret-standalone.c b/pkcs11/secret-store/gkm-secret-standalone.c
index 0baacbd..681bf4e 100644
--- a/pkcs11/secret-store/gkm-secret-standalone.c
+++ b/pkcs11/secret-store/gkm-secret-standalone.c
@@ -34,13 +34,7 @@
 #include "pkcs11/pkcs11.h"
 
 /* Module callbacks for secure memory */
-static GStaticMutex memory_mutex = G_STATIC_MUTEX_INIT;
-void egg_memory_lock (void)
-	{ g_static_mutex_lock (&memory_mutex); }
-void egg_memory_unlock (void)
-	{ g_static_mutex_unlock (&memory_mutex); }
-void* egg_memory_fallback (void *p, size_t sz)
-	{ return g_realloc (p, sz); }
+EGG_SECURE_GLIB_DEFINITIONS ();
 
 CK_RV
 C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
diff --git a/pkcs11/ssh-store/gkm-ssh-standalone.c b/pkcs11/ssh-store/gkm-ssh-standalone.c
index 2d9798f..fe0260c 100644
--- a/pkcs11/ssh-store/gkm-ssh-standalone.c
+++ b/pkcs11/ssh-store/gkm-ssh-standalone.c
@@ -34,13 +34,7 @@
 #include <glib-object.h>
 
 /* Module callbacks for secure memory */
-static GStaticMutex memory_mutex = G_STATIC_MUTEX_INIT;
-void egg_memory_lock (void)
-	{ g_static_mutex_lock (&memory_mutex); }
-void egg_memory_unlock (void)
-	{ g_static_mutex_unlock (&memory_mutex); }
-void* egg_memory_fallback (void *p, size_t sz)
-	{ return g_realloc (p, sz); }
+EGG_SECURE_GLIB_DEFINITIONS ();
 
 CK_RV
 C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
diff --git a/pkcs11/user-store/gkm-user-standalone.c b/pkcs11/user-store/gkm-user-standalone.c
index 7cbd558..d8dd496 100644
--- a/pkcs11/user-store/gkm-user-standalone.c
+++ b/pkcs11/user-store/gkm-user-standalone.c
@@ -34,13 +34,7 @@
 #include <glib-object.h>
 
 /* Module callbacks for secure memory */
-static GStaticMutex memory_mutex = G_STATIC_MUTEX_INIT;
-void egg_memory_lock (void)
-	{ g_static_mutex_lock (&memory_mutex); }
-void egg_memory_unlock (void)
-	{ g_static_mutex_unlock (&memory_mutex); }
-void* egg_memory_fallback (void *p, size_t sz)
-	{ return g_realloc (p, sz); }
+EGG_SECURE_GLIB_DEFINITIONS ();
 
 CK_RV
 C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
diff --git a/tests/gtest-helpers.c b/tests/gtest-helpers.c
index bf976ea..0fec77f 100644
--- a/tests/gtest-helpers.c
+++ b/tests/gtest-helpers.c
@@ -47,23 +47,9 @@
 /* Forward declaration */
 void test_p11_module (CK_FUNCTION_LIST_PTR module, const gchar *config);
 
-static GStaticMutex memory_mutex = G_STATIC_MUTEX_INIT;
 static const gchar *test_path = NULL;
 
-void egg_memory_lock (void) 
-{ 
-	g_static_mutex_lock (&memory_mutex); 
-}
-
-void egg_memory_unlock (void) 
-{ 
-	g_static_mutex_unlock (&memory_mutex); 
-}
-
-void* egg_memory_fallback (void *p, size_t sz) 
-{ 
-	return g_realloc (p, sz); 
-}
+EGG_SECURE_GLIB_DEFINITIONS ();
 
 static GMainLoop *mainloop = NULL;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]