gnome-keyring r1469 - in trunk: . gp11



Author: nnielsen
Date: Tue Jan 20 16:41:14 2009
New Revision: 1469
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1469&view=rev

Log:
	* gp11/gp11.h:
	* gp11/gp11-misc.c:
	* gp11/gp11-module.c:
	* gp11/gp11-private.h:
	* gp11/gp11-session.c:
	* gp11/gp11-slot.c: Expose looking up slot flags,
	and a few other helpful functions.

Modified:
   trunk/ChangeLog
   trunk/gp11/gp11-misc.c
   trunk/gp11/gp11-module.c
   trunk/gp11/gp11-private.h
   trunk/gp11/gp11-session.c
   trunk/gp11/gp11-slot.c
   trunk/gp11/gp11.h

Modified: trunk/gp11/gp11-misc.c
==============================================================================
--- trunk/gp11/gp11-misc.c	(original)
+++ trunk/gp11/gp11-misc.c	Tue Jan 20 16:41:14 2009
@@ -24,6 +24,7 @@
 #include "config.h"
 
 #include "gp11.h"
+#include "gp11-private.h"
 
 #include <glib/gi18n.h>
 
@@ -67,6 +68,27 @@
 }
 
 /**
+ * gp11_list_ref_copy:
+ * reflist: List of GObject reference counted objects.
+ * 
+ * Copy a list of GObject based pointers. All objects 
+ * in the list will be reffed and the list will be copied.
+ * 
+ * Return value: The copied and reffed list. When done, free it with 
+ * gp11_list_unref_free ()
+ */
+GList*
+gp11_list_ref_copy (GList *reflist)
+{
+	GList *l, *copy = g_list_copy (reflist);
+	for (l = copy; l; l = g_list_next (l)) {
+		g_return_val_if_fail (G_IS_OBJECT (l->data), NULL);
+		g_object_ref (l->data);
+	}
+	return copy;
+}
+
+/**
  * gp11_message_from_rv:
  * rv: The PKCS#11 return value to get a message for.
  * 
@@ -280,3 +302,21 @@
 	g_strchomp (string);
 	return string;
 }
+
+guint
+_gp11_ulong_hash (gconstpointer v)
+{
+	const signed char *p = v;
+	guint32 i, h = *p;
+
+	for(i = 0; i < sizeof (gulong); ++i)
+		h = (h << 5) - h + *(p++);
+
+	return h;
+}
+
+gboolean
+_gp11_ulong_equal (gconstpointer v1, gconstpointer v2)
+{
+	return *((const gulong*)v1) == *((const gulong*)v2);
+}

Modified: trunk/gp11/gp11-module.c
==============================================================================
--- trunk/gp11/gp11-module.c	(original)
+++ trunk/gp11/gp11-module.c	Tue Jan 20 16:41:14 2009
@@ -65,7 +65,6 @@
 	gboolean finalized;
 	GHashTable *open_sessions;
 	gboolean auto_authenticate;
-	GP11TokenInfo *token_info;
 } GP11ModulePrivate;
 
 #define GP11_MODULE_GET_DATA(o) \
@@ -86,24 +85,6 @@
  * HELPERS
  */
 
-static guint
-ulong_hash (gconstpointer v)
-{
-	const signed char *p = v;
-	guint32 i, h = *p;
-
-	for(i = 0; i < sizeof (gulong); ++i)
-		h = (h << 5) - h + *(p++);
-
-	return h;
-}
-
-static gboolean
-ulong_equal (gconstpointer v1, gconstpointer v2)
-{
-	return *((const gulong*)v1) == *((const gulong*)v2);
-}
-
 static CK_RV
 create_mutex (void **mutex)
 {
@@ -302,7 +283,7 @@
 create_session_table (GP11ModulePrivate *pv)
 {
 	if (!pv->open_sessions)
-		pv->open_sessions = g_hash_table_new_full (ulong_hash, ulong_equal, g_free, free_session_pool);
+		pv->open_sessions = g_hash_table_new_full (_gp11_ulong_hash, _gp11_ulong_equal, g_free, free_session_pool);
 }
 
 CK_SESSION_HANDLE

Modified: trunk/gp11/gp11-private.h
==============================================================================
--- trunk/gp11/gp11-private.h	(original)
+++ trunk/gp11/gp11-private.h	Tue Jan 20 16:41:14 2009
@@ -50,6 +50,15 @@
                                                              CK_ULONG_PTR n_attrs);
 
 /* ----------------------------------------------------------------------------
+ * MISC
+ */
+
+guint               _gp11_ulong_hash                        (gconstpointer v);
+
+gboolean            _gp11_ulong_equal                       (gconstpointer v1, 
+                                                             gconstpointer v2);
+
+/* ----------------------------------------------------------------------------
  * MODULE
  */
 
@@ -75,7 +84,8 @@
  * SLOT
  */
 
-gboolean            _gp11_slot_is_protected_auth_path       (GP11Slot *slot);
+GP11Object*         _gp11_slot_object_from_handle           (GP11Slot *slot,
+                                                             CK_OBJECT_HANDLE handle);
 
 /* ----------------------------------------------------------------------------
  * CALL

Modified: trunk/gp11/gp11-session.c
==============================================================================
--- trunk/gp11/gp11-session.c	(original)
+++ trunk/gp11/gp11-session.c	Tue Jan 20 16:41:14 2009
@@ -1138,7 +1138,7 @@
 	module = gp11_slot_get_module (slot);
 	if (gp11_module_get_auto_authenticate (module)) {
 		auth->state = AUTHENTICATE_CAN;
-		auth->protected_auth = _gp11_slot_is_protected_auth_path (slot);
+		auth->protected_auth = gp11_slot_has_flags (slot, CKF_PROTECTED_AUTHENTICATION_PATH);
 		auth->module = module;
 		auth->object = g_object_ref (object);
 	} else {

Modified: trunk/gp11/gp11-slot.c
==============================================================================
--- trunk/gp11/gp11-slot.c	(original)
+++ trunk/gp11/gp11-slot.c	Tue Jan 20 16:41:14 2009
@@ -199,25 +199,6 @@
 }
 
 /* ----------------------------------------------------------------------------
- * INTERNAL AUTHENTICATION
- */
-
-gboolean
-_gp11_slot_is_protected_auth_path (GP11Slot *self)
-{
-	GP11TokenInfo *info;
-	gboolean ret;
-
-	g_assert (GP11_IS_SLOT (self));
-
-	info = gp11_slot_get_token_info (self);
-	ret = (info && info->flags & CKF_PROTECTED_AUTHENTICATION_PATH);
-	gp11_token_info_free (info);
-	
-	return ret;
-}
-
-/* ----------------------------------------------------------------------------
  * PUBLIC 
  */
 
@@ -576,6 +557,36 @@
 	return mechinfo;
 }
 
+gboolean
+gp11_slot_has_flags (GP11Slot *self, gulong flags)
+{
+	CK_FUNCTION_LIST_PTR funcs;
+	GP11Module *module = NULL;
+	CK_TOKEN_INFO info;
+	CK_SLOT_ID handle;
+	CK_RV rv;
+	
+	g_return_val_if_fail (GP11_IS_SLOT (self), FALSE);
+
+	g_object_get (self, "module", &module, "handle", &handle, NULL);
+	g_return_val_if_fail (GP11_IS_MODULE (module), FALSE);
+	
+	funcs = gp11_module_get_functions (module);
+	g_return_val_if_fail (funcs, FALSE);
+	
+	memset (&info, 0, sizeof (info));
+	rv = (funcs->C_GetTokenInfo) (handle, &info);
+	
+	g_object_unref (module);
+	
+	if (rv != CKR_OK) {
+		g_warning ("couldn't get slot info: %s", gp11_message_from_rv (rv));
+		return FALSE;
+	}
+	
+	return (info.flags & flags) != 0;
+}
+
 #if UNIMPLEMENTED
 
 typedef struct InitToken {

Modified: trunk/gp11/gp11.h
==============================================================================
--- trunk/gp11/gp11.h	(original)
+++ trunk/gp11/gp11.h	Tue Jan 20 16:41:14 2009
@@ -41,6 +41,8 @@
 
 GQuark              gp11_get_error_quark                    (void);
 
+GList*              gp11_list_ref_copy                      (GList *reflist);
+
 void                gp11_list_unref_free                    (GList *reflist);
 
 const gchar*        gp11_message_from_rv                    (CK_RV rv);
@@ -441,6 +443,9 @@
 GP11MechanismInfo*  gp11_slot_get_mechanism_info            (GP11Slot *self,
                                                              gulong mech_type);
 
+gboolean            gp11_slot_has_flags                     (GP11Slot *self,
+                                                             gulong flags);
+
 #if UNIMPLEMENTED
 
 gboolean            gp11_slot_init_token                    (GP11Slot *self, 



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