[Pvfs2-cvs] commit by nlmills in pvfs2/src/common/security: security-util.c security-util.h

CVS commit program cvs at parl.clemson.edu
Mon Dec 1 22:35:51 EST 2008


Update of /anoncvs/pvfs2/src/common/security
In directory parlweb1:/tmp/cvs-serv7995/src/common/security

Modified Files:
      Tag: cu-security-branch
	security-util.c security-util.h 
Log Message:
new server state machine to handle getcred requests


Index: security-util.c
===================================================================
RCS file: /anoncvs/pvfs2/src/common/security/Attic/security-util.c,v
diff -p -u -r1.1.2.6 -r1.1.2.7
--- security-util.c	6 Nov 2008 22:13:41 -0000	1.1.2.6
+++ security-util.c	2 Dec 2008 03:35:51 -0000	1.1.2.7
@@ -111,71 +111,91 @@ int PINT_capability_is_null(const PVFS_c
     return (memcmp(cap, &null_capability, sizeof(PVFS_capability)) == 0);
 }
 
-void PINT_release_credential(PVFS_credential *cred)
+void PINT_cleanup_credential(PVFS_credential *cred)
 {
     if (cred)
     {
         free(cred->group_array);
         free(cred->issuer_id);
         free(cred->signature);
-        free(cred);
     }
 }
 
+void PINT_release_credential(PVFS_credential *cred)
+{
+    PINT_cleanup_credential(cred);
+    free(cred);
+}
+
 /* TODO: fix for the no security case. the previous assumption that
  * credentials are always signed will probably no longer hold.
  */
-PVFS_credential *PINT_dup_credential(const PVFS_credential *cred)
+int PINT_copy_credential(const PVFS_credential *src, PVFS_credential *dest)
 {
-    PVFS_credential *ret = NULL;
+    if (!src || !dest || (src == dest))
+    {
+        return -PVFS_EINVAL;
+    }
 
-    if (!cred)
+    memcpy(dest, src, sizeof(PVFS_credential));
+    dest->group_array = NULL;
+    dest->issuer_id = NULL;
+    dest->signature = NULL;
+
+    if (src->num_groups)
     {
-        return NULL;
+        dest->group_array = calloc(src->num_groups, sizeof(PVFS_gid));
+        if (!dest->group_array)
+        {
+            return -PVFS_ENOMEM;
+        }
+        memcpy(dest->group_array, src->group_array,
+               src->num_groups * sizeof(PVFS_gid));
     }
 
-    ret = (PVFS_credential*)calloc(1, sizeof(PVFS_credential));
-    if (!ret)
+    dest->issuer_id = strdup(src->issuer_id);
+    if (!dest->issuer_id)
     {
-        return NULL;
+        free(dest->group_array);
+        return -PVFS_ENOMEM;
+    }
+
+    dest->signature = calloc(src->sig_size, 1);
+    if (!dest->signature)
+    {
+        free(dest->issuer_id);
+        free(dest->group_array);
+        return -PVFS_ENOMEM;
     }
+    memcpy(dest->signature, src->signature, src->sig_size);
+
+    return 0;
+}
 
-    memcpy(ret, cred, sizeof(PVFS_credential));
-    ret->group_array = NULL;
-    ret->issuer_id = NULL;
-    ret->signature = NULL;
+PVFS_credential *PINT_dup_credential(const PVFS_credential *cred)
+{
+    PVFS_credential *newcred;
+    int ret;
 
-    if (cred->num_groups)
+    if (!cred)
     {
-        ret->group_array = calloc(cred->num_groups, sizeof(PVFS_gid));
-        if (!ret->group_array)
-        {
-            free(ret);
-            return NULL;
-        }
-        memcpy(ret->group_array, cred->group_array, 
-               cred->num_groups * sizeof(PVFS_gid));
+        return NULL;
     }
 
-    ret->issuer_id = strdup(cred->issuer_id);
-    if (!ret->issuer_id)
+    newcred = (PVFS_credential*)malloc(sizeof(PVFS_credential));
+    if (!newcred)
     {
-        free(ret->group_array);
-        free(ret);
         return NULL;
     }
 
-    ret->signature = (unsigned char*)calloc(cred->sig_size, 1);
-    if (!ret->signature)
+    ret = PINT_copy_credential(cred, newcred);
+    if (ret < 0)
     {
-        free(ret->issuer_id);
-        free(ret->group_array);
-        free(ret);
+        free(newcred);
         return NULL;
     }
-    memcpy(ret->signature, cred->signature, cred->sig_size);
 
-    return ret;
+    return newcred;
 }
 
 

Index: security-util.h
===================================================================
RCS file: /anoncvs/pvfs2/src/common/security/Attic/security-util.h,v
diff -p -u -r1.1.2.5 -r1.1.2.6
--- security-util.h	25 Jul 2008 19:05:53 -0000	1.1.2.5
+++ security-util.h	2 Dec 2008 03:35:51 -0000	1.1.2.6
@@ -36,7 +36,11 @@ const PVFS_capability *PINT_null_capabil
 
 int PINT_capability_is_null(const PVFS_capability* cap);
 
+int PINT_copy_credential(const PVFS_credential *src, PVFS_credential *dest);
+
 PVFS_credential *PINT_dup_credential(const PVFS_credential *cred);
+
+void PINT_cleanup_credential(PVFS_credential *cred);
 
 void PINT_release_credential(PVFS_credential *cred);
 



More information about the Pvfs2-cvs mailing list