[Pvfs2-cvs] commit by dbonnie in pvfs2/src/common/security:
security-hash.c
CVS commit program
cvs at parl.clemson.edu
Thu May 15 10:38:11 EDT 2008
Update of /anoncvs/pvfs2/src/common/security
In directory parlweb1:/tmp/cvs-serv5999
Modified Files:
Tag: cu-security-branch
security-hash.c
Log Message:
Added mutex for init and add. Added checking on init/finalize. Completed finalize.
Index: security-hash.c
===================================================================
RCS file: /anoncvs/pvfs2/src/common/security/Attic/security-hash.c,v
diff -p -u -r1.1.2.3 -r1.1.2.4
--- security-hash.c 15 May 2008 00:18:22 -0000 1.1.2.3
+++ security-hash.c 15 May 2008 14:38:11 -0000 1.1.2.4
@@ -11,49 +11,71 @@
#include "pvfs2-types.h"
#include "quickhash.h"
#include "security-hash.h"
-
+#include "gen-locks.h"
#define DEFAULT_SECURITY_TABLE_SIZE 71
-
typedef struct pubkey_entry_s {
struct qlist_head hash_link;
PVFS_handle host;
EVP_PKEY *pubkey;
} pubkey_entry_t;
-
static struct qhash_table *pubkey_table = NULL;
-/* TODO: use locking */
-
+static int hash_init_status = 0;
+static gen_mutex_t hash_init_mutex = GEN_MUTEX_INITIALIZER;
+static gen_mutex_t hash_pubkey_mutex = GEN_MUTEX_INITIALIZER;
static int pubkey_compare(void*, struct qhash_head*);
int SECURITY_hash_initialize(void)
{
- /* XXX: prevent multiple initializations? */
+ gen_mutex_lock(&hash_init_mutex);
+ if (hash_init_status)
+ {
+ gen_mutex_unlock(&hash_init_mutex);
+ return -1;
+ }
+
pubkey_table = qhash_init(pubkey_compare, quickhash_64bit_hash,
DEFAULT_SECURITY_TABLE_SIZE);
if (pubkey_table == NULL)
{
+ gen_mutex_unlock(&hash_init_mutex);
return -1;
}
+
+ hash_init_status = 1;
+ gen_mutex_unlock(&hash_init_mutex);
return 0;
}
void SECURITY_hash_finalize(void)
{
- /* TODO: free entries */
- qhash_finalize(pubkey_table);
+ /* qhash_finalize(pubkey_table); // incomplete free */
+
+ gen_mutex_lock(&hash_init_mutex);
+ if (!hash_init_status)
+ {
+ gen_mutex_unlock(&hash_init_mutex);
+ return;
+ }
+
+ qhash_destroy_and_finalize(pubkey_table, pubkey_entry_t, hash_link, free);
+
+ hash_init_status = 0;
+ gen_mutex_unlock(&hash_init_mutex);
}
int SECURITY_add_pubkey(PVFS_handle host, EVP_PKEY *pubkey)
{
/* XXX: who is responsible for keys? */
/* XXX: what about duplicates? */
+
+ gen_mutex_lock(&hash_pubkey_mutex);
pubkey_entry_t *entry;
entry = (pubkey_entry_t*)malloc(sizeof(pubkey_entry_t));
@@ -65,6 +87,8 @@ int SECURITY_add_pubkey(PVFS_handle host
entry->host = host;
entry->pubkey = pubkey;
qhash_add(pubkey_table, &entry->host, &entry->hash_link);
+
+ gen_mutex_unlock(&hash_pubkey_mutex);
return 0;
}
@@ -87,14 +111,13 @@ EVP_PKEY *SECURITY_lookup_pubkey(PVFS_ha
static int pubkey_compare(void *key, struct qhash_head *link)
{
- PVFS_handle host = *((PVFS_handle*)key);
+ PVFS_handle host = *((PVFS_handle *)key);
pubkey_entry_t *temp;
temp = qlist_entry(link, pubkey_entry_t, hash_link);
return (temp->host == host);
}
-
/*
* Local variables:
More information about the Pvfs2-cvs
mailing list