Updates of portable CCAPI sources. All code compiles
authorJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 19 May 2006 09:18:37 +0000 (09:18 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 19 May 2006 09:18:37 +0000 (09:18 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/branches/ccapi@18022 dc483132-0cff-0310-8789-dd5450dbe970

38 files changed:
src/lib/ccapi/client/NTMakefile
src/lib/ccapi/client/cacheapi.c
src/lib/ccapi/client/cacheapi.def [new file with mode: 0644]
src/lib/ccapi/client/ccache.c
src/lib/ccapi/client/ccache.h
src/lib/ccapi/client/ccache_iterator.c
src/lib/ccapi/client/ccache_iterator.h
src/lib/ccapi/client/ccapiv2.c [new file with mode: 0644]
src/lib/ccapi/client/context.c
src/lib/ccapi/client/context.h
src/lib/ccapi/client/credentials.c
src/lib/ccapi/client/credentials.h
src/lib/ccapi/client/credentials_iterator.c
src/lib/ccapi/client/credentials_iterator.h
src/lib/ccapi/client/marshall.c [new file with mode: 0644]
src/lib/ccapi/client/msg.c [moved from src/lib/ccapi/msg.c with 79% similarity]
src/lib/ccapi/include/CredentialsCache.h
src/lib/ccapi/include/CredentialsCache2.h
src/lib/ccapi/include/cc_rpc.h [new file with mode: 0644]
src/lib/ccapi/include/generic_lists.h [new file with mode: 0644]
src/lib/ccapi/include/marshall.h
src/lib/ccapi/include/msg.h
src/lib/ccapi/include/msg_headers.h
src/lib/ccapi/marshall.c [deleted file]
src/lib/ccapi/server/NTMakefile
src/lib/ccapi/server/ccs_ccache.c [moved from src/lib/ccapi/server/ccache.c with 83% similarity]
src/lib/ccapi/server/ccs_context.c [moved from src/lib/ccapi/server/context.c with 76% similarity]
src/lib/ccapi/server/ccs_lists.c [moved from src/lib/ccapi/server/lists.c with 84% similarity]
src/lib/ccapi/server/datastore.h
src/lib/ccapi/server/main.c [new file with mode: 0644]
src/lib/ccapi/server/serv_ops.c
src/lib/ccapi/server/serv_ops.h
src/lib/ccapi/unit-test/NTMakefile [new file with mode: 0644]
src/lib/ccapi/windows/rpcsstest/NTMakefile [new file with mode: 0644]
src/lib/ccapi/windows/rpcsstest/client.c [new file with mode: 0644]
src/lib/ccapi/windows/rpcsstest/cstest.acf [new file with mode: 0644]
src/lib/ccapi/windows/rpcsstest/cstest.idl [new file with mode: 0644]
src/lib/ccapi/windows/rpcsstest/server.c [new file with mode: 0644]

index 09ef9df38b88792a9bd5ae59d716e336ab2007d6..57ff87416eba54b2602cff84137b21acc1be5138 100644 (file)
@@ -12,11 +12,11 @@ $(CCAPI_LIB): $(CCAPI_OBJS)
 
 CCAPI_DLLFILE = krbcc32.dll
 
-
-
 $(CCAPI_DLLFILE): $(CCAPI_LIB)
         $(DLLGUILINK) -def:windows\krbcc32.def
         $(DLLPREP)
 
+all: $(CCAPI_DLLFILE)
+
 clean:
         del *.obj *.lib
index 2c874bec0fd70a542a72e8763daa17654d46b37b..704925dfd7ec71b7fa32039b6416c8d4ecfee737 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
 #include "ccache.h"
 #include "ccache_iterator.h"
 #include "context.h"
+#include "cc_rpc.h"
 #include "msg.h"
 #include "msg_headers.h"
 
-cc_int32 
+/*! \fn cc_initialize
+ *  \brief A function that initializes a ccapi context for the caller.
+ *  \param[out] outContext a cc_context_t pointer to which is assigned the newly created context upon success.
+ *  \param[in]  inVersion  a cc_int32 that specifies the 
+ */
+
+CCACHE_API cc_int32 
 cc_initialize (        cc_context_t*           outContext,
                 cc_int32               inVersion,
                 cc_int32*              outSupportedVersion,
@@ -60,16 +67,18 @@ cc_initialize (     cc_context_t*           outContext,
     cc_msg_t     *request;
     ccmsg_init_t *request_header;
     cc_msg_t     *response;
+    cc_uint32 type;
     ccmsg_init_resp_t *response_header;
     cc_int32 code;
 
     if ((inVersion != ccapi_version_2) &&
          (inVersion != ccapi_version_3) &&
          (inVersion != ccapi_version_4) &&
-         (inVersion != ccapi_version_5)) {
+         (inVersion != ccapi_version_5) &&
+        (inVersion != ccapi_version_6)) {
 
         if (outSupportedVersion != NULL) {
-            *outSupportedVersion = ccapi_version_5;
+            *outSupportedVersion = ccapi_version_6;
         }
         return ccErrBadAPIVersion;
     }   
@@ -78,7 +87,17 @@ cc_initialize (      cc_context_t*           outContext,
     if (request_header == NULL)
         return ccErrNoMem;
 
-    request_header->in_version = inVersion;
+    /* If the version number is 2, the caller will be passing
+     * the structure into the v2 compatibility functions which
+     * in turn will call the v6 functions.  Set the version to
+     * ccapi_version_max since that is what the compatibility 
+     * functions will be expecting.
+     */
+    if (inVersion == ccapi_version_2)
+       inVersion = ccapi_version_max;
+
+    /* Construct the request */
+    request_header->in_version = htonl(inVersion);
 
     code = cci_msg_new(ccmsg_INIT, &request);
     if (code != ccNoError) {
@@ -90,17 +109,18 @@ cc_initialize (    cc_context_t*           outContext,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         response_header = (ccmsg_init_resp_t *)response->header;
-        *outSupportedVersion = response_header->out_version;
-        code = cc_context_int_new(outContext, response_header->out_ctx, response_header->out_version);
+        *outSupportedVersion = ntohl(response_header->out_version);
+        code = cc_int_context_new(outContext, ntohl(response_header->out_ctx), ntohl(response_header->out_version));
 
         if (!vendor[0]) {
             char * string;
-            code = cci_msg_retrieve_blob(response, response_header->vendor_offset, response_header->vendor_length, &string);
+            code = cci_msg_retrieve_blob(response, ntohl(response_header->vendor_offset), ntohl(response_header->vendor_length), &string);
             strncpy(vendor, string, sizeof(vendor)-1);
             vendor[sizeof(vendor)-1] = '\0';
             free(string);
diff --git a/src/lib/ccapi/client/cacheapi.def b/src/lib/ccapi/client/cacheapi.def
new file mode 100644 (file)
index 0000000..c54cc11
--- /dev/null
@@ -0,0 +1,29 @@
+EXPORTS\r
+       ; ccapi v3 only exports one function\r
+        cc_initialize                  @14\r
+\r
+       ; ccapi v2 compatibility functions\r
+        cc_close                       @2\r
+        cc_create                      @3\r
+        cc_destroy                     @4\r
+        cc_free_NC_info                        @5\r
+        cc_free_creds                  @6\r
+        cc_free_name                   @7\r
+        cc_free_principal              @8\r
+        cc_get_NC_info                 @9\r
+        cc_get_change_time             @10\r
+        cc_get_cred_version            @11\r
+        cc_get_name                    @12\r
+        cc_get_principal               @13\r
+        cc_lock_request                        @15\r
+        cc_open                                @16\r
+        cc_remove_cred                 @17\r
+        cc_seq_fetch_NCs_begin         @18\r
+        cc_seq_fetch_NCs_end           @19\r
+        cc_seq_fetch_NCs_next          @20\r
+        cc_seq_fetch_creds_begin       @21\r
+        cc_seq_fetch_creds_end         @22\r
+        cc_seq_fetch_creds_next                @23\r
+        cc_set_principal               @24\r
+        cc_shutdown                    @25\r
+        cc_store                       @26\r
index 5de3880e4fd1f08e2acd7e5d7a432d34b6e84415..42064d54de0cd1b4d00d4a7f806c9700e708b654 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
 #include <CredentialsCache.h>
 #include "credentials.h"
 #include "ccache.h"
+#include "cc_rpc.h"
 #include "msg.h"
 #include "msg_headers.h"
 
+/* 
+ * cc_int_ccache_new
+ *
+ * Input parameters in host order.
+ */
+
 cc_int32
 cc_int_ccache_new( cc_ccache_t * pccache, cc_handle hctx, cc_handle hccache )
 {
@@ -97,11 +104,12 @@ cc_int_ccache_new( cc_ccache_t * pccache, cc_handle hctx, cc_handle hccache )
 cc_int32    
 cc_int_ccache_release( cc_ccache_t ccache )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
-    ccmsg_ccache_release_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_int_ccache_t            int_ccache;
+    cc_msg_t                   *request;
+    ccmsg_ccache_release_t     *request_header;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_int32                   code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -114,8 +122,8 @@ cc_int_ccache_release( cc_ccache_t ccache )
     request_header = (ccmsg_ccache_release_t*)malloc(sizeof(ccmsg_ccache_release_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_RELEASE, &request);
     if (code != ccNoError) {
@@ -127,10 +135,11 @@ cc_int_ccache_release( cc_ccache_t ccache )
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -146,11 +155,12 @@ cc_int_ccache_release( cc_ccache_t ccache )
 cc_int32    
 cc_int_ccache_destroy( cc_ccache_t ccache )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
-    ccmsg_ccache_destroy_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_int_ccache_t            int_ccache;
+    cc_msg_t                   *request;
+    ccmsg_ccache_destroy_t     *request_header;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_int32                   code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -163,8 +173,8 @@ cc_int_ccache_destroy( cc_ccache_t ccache )
     request_header = (ccmsg_ccache_destroy_t*)malloc(sizeof(ccmsg_ccache_destroy_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_DESTROY, &request);
     if (code != ccNoError) {
@@ -176,10 +186,11 @@ cc_int_ccache_destroy( cc_ccache_t ccache )
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -194,11 +205,12 @@ cc_int_ccache_destroy( cc_ccache_t ccache )
 cc_int32
 cc_int_ccache_set_default( cc_ccache_t ccache )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
-    ccmsg_ccache_set_default_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_int_ccache_t                    int_ccache;
+    cc_msg_t                           *request;
+    ccmsg_ccache_set_default_t                 *request_header;
+    cc_msg_t                           *response;
+    cc_uint32                          type;
+    cc_int32                           code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -211,8 +223,8 @@ cc_int_ccache_set_default( cc_ccache_t ccache )
     request_header = (ccmsg_ccache_set_default_t*)malloc(sizeof(ccmsg_ccache_set_default_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_SET_DEFAULT, &request);
     if (code != ccNoError) {
@@ -224,10 +236,11 @@ cc_int_ccache_set_default( cc_ccache_t ccache )
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -241,11 +254,12 @@ cc_int32
 cc_int_ccache_get_credentials_version( cc_ccache_t ccache,
                                    cc_uint32* credentials_version)
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
+    cc_int_ccache_t            int_ccache;
+    cc_msg_t                   *request;
     ccmsg_ccache_get_creds_version_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_int32                   code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -258,8 +272,8 @@ cc_int_ccache_get_credentials_version( cc_ccache_t ccache,
     request_header = (ccmsg_ccache_get_creds_version_t*)malloc(sizeof(ccmsg_ccache_get_creds_version_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_CREDS_VERSION, &request);
     if (code != ccNoError) {
@@ -271,12 +285,13 @@ cc_int_ccache_get_credentials_version( cc_ccache_t ccache,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         ccmsg_ccache_get_creds_version_resp_t * response_header = (ccmsg_ccache_get_creds_version_resp_t*)response->header;
-        *credentials_version = response_header->version;
+        *credentials_version = ntohl(response_header->version);
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -287,14 +302,14 @@ cc_int_ccache_get_credentials_version( cc_ccache_t ccache,
 }
 
 cc_int32
-cc_int_ccache_get_name( cc_ccache_t ccache,
-                    cc_string_t* name )
+cc_int_ccache_get_name( cc_ccache_t ccache, cc_string_t* name )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
+    cc_int_ccache_t    int_ccache;
+    cc_msg_t           *request;
     ccmsg_ccache_get_name_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t           *response;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -307,8 +322,8 @@ cc_int_ccache_get_name( cc_ccache_t ccache,
     request_header = (ccmsg_ccache_get_name_t*)malloc(sizeof(ccmsg_ccache_get_name_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_NAME, &request);
     if (code != ccNoError) {
@@ -320,10 +335,11 @@ cc_int_ccache_get_name( cc_ccache_t ccache,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         char * string;
         ccmsg_ccache_get_name_resp_t * response_header = (ccmsg_ccache_get_name_resp_t*)response->header;
         code = cci_msg_retrieve_blob(response, response_header->name_offset, 
@@ -345,11 +361,12 @@ cc_int_ccache_get_principal( cc_ccache_t ccache,
                         cc_uint32 credentials_version,
                         cc_string_t* principal )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
+    cc_int_ccache_t    int_ccache;
+    cc_msg_t           *request;
     ccmsg_ccache_get_principal_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t           *response;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -362,9 +379,9 @@ cc_int_ccache_get_principal( cc_ccache_t ccache,
     request_header = (ccmsg_ccache_get_principal_t*)malloc(sizeof(ccmsg_ccache_get_principal_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
-    request_header->version = credentials_version;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
+    request_header->version = htonl(credentials_version);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_PRINCIPAL, &request);
     if (code != ccNoError) {
@@ -376,10 +393,11 @@ cc_int_ccache_get_principal( cc_ccache_t ccache,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         char * string;
         ccmsg_ccache_get_principal_resp_t * response_header = (ccmsg_ccache_get_principal_resp_t*)response->header;
         code = cci_msg_retrieve_blob(response, response_header->principal_offset, 
@@ -401,12 +419,13 @@ cc_int_ccache_set_principal( cc_ccache_t ccache,
                          cc_uint32 credentials_version,
                          const char* principal )
 {
-    cc_uint32   blob_pos;
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
+    cc_uint32          blob_pos;
+    cc_int_ccache_t    int_ccache;
+    cc_msg_t           *request;
     ccmsg_ccache_set_principal_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t           *response;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -419,9 +438,9 @@ cc_int_ccache_set_principal( cc_ccache_t ccache,
     request_header = (ccmsg_ccache_set_principal_t*)malloc(sizeof(ccmsg_ccache_set_principal_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
-    request_header->version = credentials_version;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
+    request_header->version = htonl(credentials_version);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_PRINCIPAL, &request);
     if (code != ccNoError) {
@@ -436,17 +455,18 @@ cc_int_ccache_set_principal( cc_ccache_t ccache,
         return code;
     }
     
-    request_header->principal_offset = blob_pos;
-    request_header->principal_len = strlen(principal) + 1;
+    request_header->principal_offset = htonl(blob_pos);
+    request_header->principal_len = htonl(strlen(principal) + 1);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_set_principal_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -460,11 +480,12 @@ cc_int32
 cc_int_ccache_new_credentials_iterator( cc_ccache_t ccache,
                                         cc_credentials_iterator_t* iterator )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
+    cc_int_ccache_t    int_ccache;
+    cc_msg_t           *request;
     ccmsg_ccache_creds_iterator_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t           *response;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -477,10 +498,10 @@ cc_int_ccache_new_credentials_iterator( cc_ccache_t ccache,
     request_header = (ccmsg_ccache_creds_iterator_t*)malloc(sizeof(ccmsg_ccache_creds_iterator_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
 
-    code = cci_msg_new(ccmsg_CCACHE_CREDS_ITERATOR, &request);
+    code = cci_msg_new(ccmsg_CCACHE_NEW_CREDS_ITERATOR, &request);
     if (code != ccNoError) {
         free(request_header);
         return code;
@@ -490,12 +511,14 @@ cc_int_ccache_new_credentials_iterator( cc_ccache_t ccache,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         ccmsg_ccache_creds_iterator_resp_t * response_header = (ccmsg_ccache_creds_iterator_resp_t*)response->header;
-        code = cc_int_credentials_iterator_new(iterator, response_header->iterator);
+        code = cc_int_credentials_iterator_new(iterator, int_ccache->ctx, int_ccache->handle,
+                                               ntohll(response_header->iterator));
     } else {
         code = ccErrBadInternalMessage;
     }
@@ -508,14 +531,15 @@ cc_int32
 cc_int_ccache_store_credentials( cc_ccache_t ccache,
                              const cc_credentials_union* credentials )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
+    cc_int_ccache_t    int_ccache;
+    cc_msg_t           *request;
     ccmsg_ccache_store_creds_t *request_header;
-    cc_msg_t        *response;
-    char            *flat_cred = 0;
-    cc_uint32       flat_cred_len = 0;
-    cc_uint32       blob_pos;
-    cc_int32 code;
+    cc_msg_t           *response;
+    char               *flat_cred = 0;
+    cc_uint32          flat_cred_len = 0;
+    cc_uint32          blob_pos;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( ccache == NULL || credentials == NULL )
         return ccErrBadParam;
@@ -528,8 +552,8 @@ cc_int_ccache_store_credentials( cc_ccache_t ccache,
     request_header = (ccmsg_ccache_store_creds_t*)malloc(sizeof(ccmsg_ccache_store_creds_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_STORE_CREDS, &request);
     if (code != ccNoError) {
@@ -562,18 +586,19 @@ cc_int_ccache_store_credentials( cc_ccache_t ccache,
         return code;
     }
     
-    request_header->creds_version = credentials->version;
-    request_header->creds_offset = blob_pos;
-    request_header->creds_len = flat_cred_len;
+    request_header->creds_version = htonl(credentials->version);
+    request_header->creds_offset = htonl(blob_pos);
+    request_header->creds_len = htonl(flat_cred_len);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_store_creds_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -588,12 +613,13 @@ cc_int32
 cc_int_ccache_remove_credentials( cc_ccache_t ccache,
                               cc_credentials_t credentials )
 {
-    cc_int_ccache_t int_ccache;
-    cc_int_credentials_t  int_creds;
-    cc_msg_t        *request;
-    ccmsg_ccache_rem_creds_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_int_ccache_t            int_ccache;
+    cc_int_credentials_t       int_creds;
+    cc_msg_t                   *request;
+    ccmsg_ccache_rem_creds_t   *request_header;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_int32                   code;
 
     if ( ccache == NULL || credentials == NULL )
         return ccErrBadParam;
@@ -611,9 +637,9 @@ cc_int_ccache_remove_credentials( cc_ccache_t ccache,
     if (request_header == NULL)
         return ccErrNoMem;
     
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
-    request_header->creds  = int_creds->handle;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
+    request_header->creds  = htonll(int_creds->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_REM_CREDS, &request);
     if (code != ccNoError) {
@@ -625,10 +651,11 @@ cc_int_ccache_remove_credentials( cc_ccache_t ccache,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -643,12 +670,13 @@ cc_int32
 cc_int_ccache_move( cc_ccache_t source,
                     cc_ccache_t destination )
 {
-    cc_int_ccache_t int_ccache_source;
-    cc_int_ccache_t int_ccache_dest;
-    cc_msg_t        *request;
+    cc_int_ccache_t    int_ccache_source;
+    cc_int_ccache_t    int_ccache_dest;
+    cc_msg_t           *request;
     ccmsg_ccache_move_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t           *response;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( source == NULL || destination == NULL )
         return ccErrBadParam;
@@ -673,18 +701,19 @@ cc_int_ccache_move( cc_ccache_t source,
         return code;
     }
 
-    request_header->ctx = int_ccache_source->ctx;
-    request_header->ccache_source = int_ccache_source->handle;
-    request_header->ccache_dest = int_ccache_dest->handle;
+    request_header->ctx = htonll(int_ccache_source->ctx);
+    request_header->ccache_source = htonll(int_ccache_source->handle);
+    request_header->ccache_dest = htonll(int_ccache_dest->handle);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_move_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -698,14 +727,16 @@ cc_int_ccache_lock( cc_ccache_t ccache,
                 cc_uint32 lock_type,
                 cc_uint32 block )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
+    cc_int_ccache_t    int_ccache;
+    cc_msg_t           *request;
     ccmsg_ccache_lock_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t           *response;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( ccache == NULL || 
-         (lock_type != cc_lock_read && lock_type != cc_lock_write) ||
+         (lock_type != cc_lock_read && lock_type != cc_lock_write &&
+         lock_type != cc_lock_upgrade && lock_type != cc_lock_downgrade) ||
          (block != cc_lock_block && block != cc_lock_noblock) )
         return ccErrBadParam;
 
@@ -724,17 +755,18 @@ cc_int_ccache_lock( cc_ccache_t ccache,
         return code;
     }
 
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
-    request_header->lock_type;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
+    request_header->lock_type = htonl(lock_type);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_lock_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
+        code = ntohl(nack_header->err_code);
 
         // TODO: if (block == cc_lock_block) .....
     } else if (response->type == ccmsg_ACK) {
@@ -750,11 +782,12 @@ cc_int_ccache_lock( cc_ccache_t ccache,
 cc_int32
 cc_int_ccache_unlock( cc_ccache_t ccache )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
-    ccmsg_ccache_unlock_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_int_ccache_t            int_ccache;
+    cc_msg_t                   *request;
+    ccmsg_ccache_unlock_t      *request_header;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_int32                   code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -774,17 +807,18 @@ cc_int_ccache_unlock( cc_ccache_t ccache )
         return code;
     }
 
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_unlock_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = htonl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = htonl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -797,13 +831,15 @@ cc_int_ccache_unlock( cc_ccache_t ccache )
 
 cc_int32
 cc_int_ccache_get_last_default_time( cc_ccache_t ccache,
-                                     cc_time_t* time_offset )
+                                     cc_time* time_offset )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
+    cc_int_ccache_t            int_ccache;
+    cc_msg_t                   *request;
     ccmsg_ccache_get_last_default_time_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_time64                  t64;
+    cc_int32                   code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -816,8 +852,8 @@ cc_int_ccache_get_last_default_time( cc_ccache_t ccache,
     request_header = (ccmsg_ccache_get_last_default_time_t*)malloc(sizeof(ccmsg_ccache_get_last_default_time_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_LAST_DEFAULT_TIME, &request);
     if (code != ccNoError) {
@@ -829,13 +865,16 @@ cc_int_ccache_get_last_default_time( cc_ccache_t ccache,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         ccmsg_ccache_get_last_default_time_resp_t * response_header = (ccmsg_ccache_get_last_default_time_resp_t*)response->header;
-        *time_offset = response_header->last_default_time;
-        code = ccNoError;
+        t64 = ntohll(response_header->last_default_time);
+       /* TODO: validate that we do not overflow the max value of time_offset */
+        *time_offset = t64;
+       code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
     }
@@ -845,14 +884,15 @@ cc_int_ccache_get_last_default_time( cc_ccache_t ccache,
 }
 
 cc_int32
-cc_int_ccache_get_change_time( cc_ccache_t ccache,
-                           cc_time_t* time )
+cc_int_ccache_get_change_time( cc_ccache_t ccache, cc_time* time )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
+    cc_int_ccache_t    int_ccache;
+    cc_msg_t           *request;
     ccmsg_ccache_get_change_time_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t           *response;
+    cc_time64          t64;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -865,8 +905,8 @@ cc_int_ccache_get_change_time( cc_ccache_t ccache,
     request_header = (ccmsg_ccache_get_change_time_t*)malloc(sizeof(ccmsg_ccache_get_change_time_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_CHANGE_TIME, &request);
     if (code != ccNoError) {
@@ -878,12 +918,15 @@ cc_int_ccache_get_change_time( cc_ccache_t ccache,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         ccmsg_ccache_get_change_time_resp_t * response_header = (ccmsg_ccache_get_change_time_resp_t*)response->header;
-        *time = response_header->time;
+        t64 = htonll(response_header->time);
+       /* TODO: validate that we do not overflow 'time' */
+       *time = t64;
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -898,12 +941,13 @@ cc_int_ccache_compare( cc_ccache_t ccache,
                    cc_ccache_t compare_to,
                    cc_uint32* equal )
 {
-    cc_int_ccache_t int_ccache;
-    cc_int_ccache_t int_compare_to;
-    cc_msg_t        *request;
-    ccmsg_ccache_compare_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_int_ccache_t            int_ccache;
+    cc_int_ccache_t            int_compare_to;
+    cc_msg_t                   *request;
+    ccmsg_ccache_compare_t     *request_header;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_int32                   code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -918,9 +962,9 @@ cc_int_ccache_compare( cc_ccache_t ccache,
     request_header = (ccmsg_ccache_compare_t*)malloc(sizeof(ccmsg_ccache_compare_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache1 = int_ccache->handle;
-    request_header->ccache2 = int_compare_to->handle;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache1 = htonll(int_ccache->handle);
+    request_header->ccache2 = htonll(int_compare_to->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_COMPARE, &request);
     if (code != ccNoError) {
@@ -932,12 +976,13 @@ cc_int_ccache_compare( cc_ccache_t ccache,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         ccmsg_ccache_compare_resp_t * response_header = (ccmsg_ccache_compare_resp_t*)response->header;
-        *equal = response_header->is_equal;
+        *equal = ntohl(response_header->is_equal);
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -950,13 +995,14 @@ cc_int_ccache_compare( cc_ccache_t ccache,
 cc_int32       
 cc_int_ccache_get_kdc_time_offset( cc_ccache_t ccache,
                                cc_int32        credentials_version,
-                               cc_time_t*      time_offset )
+                               cc_time*        time_offset )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
+    cc_int_ccache_t            int_ccache;
+    cc_msg_t                   *request;
     ccmsg_ccache_get_kdc_time_offset_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_int32                   code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -969,9 +1015,9 @@ cc_int_ccache_get_kdc_time_offset( cc_ccache_t ccache,
     request_header = (ccmsg_ccache_get_kdc_time_offset_t*)malloc(sizeof(ccmsg_ccache_get_kdc_time_offset_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
-    request_header->creds_version = credentials_version;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
+    request_header->creds_version = htonl(credentials_version);
 
     code = cci_msg_new(ccmsg_CCACHE_GET_KDC_TIME_OFFSET, &request);
     if (code != ccNoError) {
@@ -983,12 +1029,13 @@ cc_int_ccache_get_kdc_time_offset( cc_ccache_t ccache,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
+        code = ntohl(nack_header->err_code);
     } else if (response->type == ccmsg_ACK) {
         ccmsg_ccache_get_kdc_time_offset_resp_t * response_header = (ccmsg_ccache_get_kdc_time_offset_resp_t*)response->header;
-        *time_offset = response_header->offset;
+        *time_offset = ntohll(response_header->offset);
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -1001,13 +1048,15 @@ cc_int_ccache_get_kdc_time_offset( cc_ccache_t ccache,
 cc_int32
 cc_int_ccache_set_kdc_time_offset( cc_ccache_t ccache,
                                cc_int32        credentials_version,
-                               cc_time_t       time_offset )
+                               cc_time time_offset )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
+    cc_int_ccache_t    int_ccache;
+    cc_msg_t           *request;
     ccmsg_ccache_set_kdc_time_offset_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t           *response;
+    cc_int64           t64;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -1020,9 +1069,11 @@ cc_int_ccache_set_kdc_time_offset( cc_ccache_t ccache,
     request_header = (ccmsg_ccache_set_kdc_time_offset_t*)malloc(sizeof(ccmsg_ccache_set_kdc_time_offset_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
-    request_header->creds_version = credentials_version;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
+    request_header->creds_version = htonl(credentials_version);
+    t64 = time_offset;
+    request_header->offset = htonll(t64);
 
     code = cci_msg_new(ccmsg_CCACHE_SET_KDC_TIME_OFFSET, &request);
     if (code != ccNoError) {
@@ -1034,10 +1085,11 @@ cc_int_ccache_set_kdc_time_offset( cc_ccache_t ccache,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -1051,11 +1103,12 @@ cc_int32
 cc_int_ccache_clear_kdc_time_offset( cc_ccache_t       ccache,
                                  cc_int32      credentials_version )
 {
-    cc_int_ccache_t int_ccache;
-    cc_msg_t        *request;
+    cc_int_ccache_t    int_ccache;
+    cc_msg_t           *request;
     ccmsg_ccache_clear_kdc_time_offset_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t           *response;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -1068,9 +1121,9 @@ cc_int_ccache_clear_kdc_time_offset( cc_ccache_t  ccache,
     request_header = (ccmsg_ccache_clear_kdc_time_offset_t*)malloc(sizeof(ccmsg_ccache_clear_kdc_time_offset_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_ccache->ctx;
-    request_header->ccache = int_ccache->handle;
-    request_header->creds_version = credentials_version;
+    request_header->ctx = htonll(int_ccache->ctx);
+    request_header->ccache = htonll(int_ccache->handle);
+    request_header->creds_version = htonl(credentials_version);
 
     code = cci_msg_new(ccmsg_CCACHE_CLEAR_KDC_TIME_OFFSET, &request);
     if (code != ccNoError) {
@@ -1082,10 +1135,11 @@ cc_int_ccache_clear_kdc_time_offset( cc_ccache_t        ccache,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -1094,5 +1148,3 @@ cc_int_ccache_clear_kdc_time_offset( cc_ccache_t  ccache,
     cci_msg_destroy(response);
     return code;
 }
-
-
index e3b3993ee0f92910df8631a16a109396eced2df8..0a92ebf63d3beed4b1522efd2397428d1f157472 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -114,11 +114,11 @@ cc_int_ccache_unlock( cc_ccache_t ccache );
 
 cc_int32
 cc_int_ccache_get_last_default_time( cc_ccache_t ccache,
-                                cc_time_t* time );
+                                cc_time* time );
 
 cc_int32
 cc_int_ccache_get_change_time( cc_ccache_t ccache,
-                          cc_time_t* time );
+                          cc_time* time );
 
 cc_int32
 cc_int_ccache_compare( cc_ccache_t ccache,
@@ -128,12 +128,12 @@ cc_int_ccache_compare( cc_ccache_t ccache,
 cc_int32       
 cc_int_ccache_get_kdc_time_offset( cc_ccache_t ccache,
                               cc_int32 credentials_version,
-                              cc_time_t*       time_offset );
+                              cc_time* time_offset );
 
 cc_int32
 cc_int_ccache_set_kdc_time_offset( cc_ccache_t ccache,
                               cc_int32 credentials_version,
-                              cc_time_t        time_offset );
+                              cc_time  time_offset );
                                 
 cc_int32
 cc_int_ccache_clear_kdc_time_offset( cc_ccache_t       ccache,
index 03266b1bbe2eba6ba2a2cf5e05c3c67ec317bcbd..3f3e1675e225e5b5b11230ea9af8b3e5fd73eb92 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -47,6 +47,7 @@
 #include <stdio.h>
 #include <CredentialsCache.h>
 #include "ccache_iterator.h"
+#include "cc_rpc.h"
 #include "msg.h"
 #include "msg_headers.h"
 
@@ -84,11 +85,12 @@ cc_int_ccache_iterator_new( cc_ccache_iterator_t * piter,
 cc_int32
 cc_int_ccache_iterator_release( cc_ccache_iterator_t iter )
 {
-    cc_int_ccache_iterator_t int_iter;
-    cc_msg_t        *request;
+    cc_int_ccache_iterator_t   int_iter;
+    cc_msg_t                   *request;
     ccmsg_ccache_iterator_release_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_int32                   code;
 
 
     if ( iter == NULL )
@@ -102,8 +104,8 @@ cc_int_ccache_iterator_release( cc_ccache_iterator_t iter )
     request_header = (ccmsg_ccache_iterator_release_t*)malloc(sizeof(ccmsg_ccache_iterator_release_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_iter->ctx;
-    request_header->iterator = int_iter->handle;
+    request_header->ctx = htonll(int_iter->ctx);
+    request_header->iterator = htonll(int_iter->handle);
     code = cci_msg_new(ccmsg_CCACHE_ITERATOR_RELEASE, &request);
     if (code != ccNoError) {
         free(request_header);
@@ -114,10 +116,11 @@ cc_int_ccache_iterator_release( cc_ccache_iterator_t iter )
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -134,11 +137,12 @@ cc_int32
 cc_int_ccache_iterator_next( cc_ccache_iterator_t iter,
                              cc_ccache_t * ccache )
 {
-    cc_int_ccache_iterator_t int_iter;
-    cc_msg_t        *request;
+    cc_int_ccache_iterator_t   int_iter;
+    cc_msg_t                   *request;
     ccmsg_ccache_iterator_next_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_int32                   code;
 
     if ( ccache == NULL )
         return ccErrBadParam;
@@ -151,8 +155,8 @@ cc_int_ccache_iterator_next( cc_ccache_iterator_t iter,
     request_header = (ccmsg_ccache_iterator_next_t*)malloc(sizeof(ccmsg_ccache_iterator_next_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_iter->ctx;
-    request_header->iterator = int_iter->handle;
+    request_header->ctx = htonll(int_iter->ctx);
+    request_header->iterator = htonll(int_iter->handle);
 
     code = cci_msg_new(ccmsg_CCACHE_ITERATOR_NEXT, &request);
     if (code != ccNoError) {
@@ -164,12 +168,63 @@ cc_int_ccache_iterator_next( cc_ccache_iterator_t iter,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
         code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+    } else if (type == ccmsg_ACK) {
         ccmsg_ccache_iterator_next_resp_t * response_header = (ccmsg_ccache_iterator_next_resp_t*)response->header;
-        code = cc_ccache_new(ccache, int_iter->ctx, response_header->ccache);
+        code = cc_int_ccache_new(ccache, int_iter->ctx, ntohll(response_header->ccache));
+    } else {
+        code = ccErrBadInternalMessage;
+    }
+    cci_msg_destroy(request);
+    cci_msg_destroy(response);
+    return code;
+}
+
+cc_int32
+cc_int_ccache_iterator_clone( cc_ccache_iterator_t iter,
+                              cc_ccache_iterator_t * new_iter )
+{
+    cc_int_ccache_iterator_t   int_iter;
+    cc_msg_t                   *request;
+    ccmsg_ccache_iterator_clone_t *request_header;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_int32                   code;
+
+    if ( iter == NULL || new_iter == NULL )
+        return ccErrBadParam;
+
+    int_iter = (cc_int_ccache_iterator_t)iter;
+
+    if ( int_iter->magic != CC_CCACHE_ITER_MAGIC )
+        return ccErrInvalidCCacheIterator;
+
+    request_header = (ccmsg_ccache_iterator_clone_t*)malloc(sizeof(ccmsg_ccache_iterator_clone_t));
+    if (request_header == NULL)
+        return ccErrNoMem;
+    request_header->ctx = htonll(int_iter->ctx);
+    request_header->iterator = htonll(int_iter->handle);
+
+    code = cci_msg_new(ccmsg_CCACHE_ITERATOR_CLONE, &request);
+    if (code != ccNoError) {
+        free(request_header);
+        return code;
+    }
+
+    code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_iterator_clone_t));
+
+    code = cci_perform_rpc(request, &response);
+
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
+        ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
+        ccmsg_ccache_iterator_clone_resp_t * response_header = (ccmsg_ccache_iterator_clone_resp_t*)response->header;
+        code = cc_int_ccache_iterator_new(new_iter, int_iter->ctx, ntohll(response_header->iterator));
     } else {
         code = ccErrBadInternalMessage;
     }
index c55d72ee67de716bbf471b2b9911f2af44d940fb..5a390b82ed80827af83f10fcd5b604a799001fe6 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -73,6 +73,10 @@ cc_int32
 cc_int_ccache_iterator_next( cc_ccache_iterator_t iter,
                              cc_ccache_t * ccache );
 
+cc_int32
+cc_int_ccache_iterator_clone( cc_ccache_iterator_t iter,
+                              cc_ccache_iterator_t * iter_new );
+
 cc_int32
 cc_int_ccache_iterator_set_repeat_count( cc_int_ccache_iterator_t iter, 
                                          cc_uint32 count );
diff --git a/src/lib/ccapi/client/ccapiv2.c b/src/lib/ccapi/client/ccapiv2.c
new file mode 100644 (file)
index 0000000..ffbb589
--- /dev/null
@@ -0,0 +1,286 @@
+/* $Copyright:\r
+ *\r
+ * Copyright 1998-2006 by the Massachusetts Institute of Technology.\r
+ * \r
+ * All rights reserved.\r
+ * \r
+ * Export of this software from the United States of America may require a\r
+ * specific license from the United States Government.  It is the\r
+ * responsibility of any person or organization contemplating export to\r
+ * obtain such a license before exporting.\r
+ * \r
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute\r
+ * this software and its documentation for any purpose and without fee is\r
+ * hereby granted, provided that the above copyright notice appear in all\r
+ * copies and that both that copyright notice and this permission notice\r
+ * appear in supporting documentation, and that the name of M.I.T. not be\r
+ * used in advertising or publicity pertaining to distribution of the\r
+ * software without specific, written prior permission.  Furthermore if you\r
+ * modify this software you must label your software as modified software\r
+ * and not distribute it in such a fashion that it might be confused with\r
+ * the original MIT software. M.I.T. makes no representations about the\r
+ * suitability of this software for any purpose.  It is provided "as is"\r
+ * without express or implied warranty.\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\r
+ * \r
+ * Individual source code files are copyright MIT, Cygnus Support,\r
+ * OpenVision, Oracle, Sun Soft, FundsXpress, and others.\r
+ * \r
+ * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,\r
+ * and Zephyr are trademarks of the Massachusetts Institute of Technology\r
+ * (MIT).  No commercial use of these trademarks may be made without prior\r
+ * written permission of MIT.\r
+ * \r
+ * "Commercial use" means use of a name in a product or other for-profit\r
+ * manner.  It does NOT prevent a commercial firm from referring to the MIT\r
+ * trademarks in order to convey information (although in doing so,\r
+ * recognition of their trademark status should be given).\r
+ * $\r
+ */\r
+/*\r
+ * This is backwards compatibility for CCache API v2 clients to be able to run \r
+ * against the CCache API v3 library\r
+ */\r
\r
+#include "CredentialsCache2.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif /* __cplusplus */\r
+\r
+CCACHE_API cc_int32 cc_shutdown (\r
+        apiCB**                                ioContext)\r
+{\r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_get_NC_info (\r
+       apiCB*                          inContext,\r
+       infoNC***                       outInfo)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_get_change_time (\r
+       apiCB*                          inContext,\r
+       cc_time_t*                      outTime)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_open (\r
+       apiCB*                          inContext,\r
+       const char*                     inName,\r
+       cc_int32                        inVersion,\r
+       cc_uint32                       inFlags,\r
+       ccache_p**                      outCCache)\r
+{\r
+    if (inVersion != CC_CRED_V4 && inVersion != CC_CRED_V5)\r
+       return CC_ERR_CRED_VERSION;\r
+\r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_create (\r
+       apiCB*                          inContext,\r
+       const char*                     inName,\r
+       const char*                     inPrincipal,\r
+       cc_int32                        inVersion,\r
+       cc_uint32                       inFlags,\r
+       ccache_p**                      outCCache)\r
+{\r
+    if (inVersion != CC_CRED_V4 && inVersion != CC_CRED_V5)\r
+       return CC_ERR_CRED_VERSION;\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_close (\r
+       apiCB*                          inContext,\r
+       ccache_p**                      ioCCache)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_destroy (\r
+       apiCB*                          inContext,\r
+       ccache_p**                      ioCCache)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_seq_fetch_NCs_begin (\r
+       apiCB*                          inContext,\r
+       ccache_cit**                    outIterator)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+\r
+CCACHE_API cc_int32 cc_seq_fetch_NCs_next (\r
+       apiCB*                          inContext,\r
+       ccache_p**                      outCCache,\r
+       ccache_cit*                     inIterator)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+\r
+CCACHE_API cc_int32 cc_seq_fetch_NCs_end (\r
+       apiCB*                          inContext,\r
+       ccache_cit**                    ioIterator)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+\r
+CCACHE_API cc_int32 cc_get_name (\r
+       apiCB*                          inContext,\r
+       ccache_p*                       inCCache,\r
+       char**                          outName)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_get_cred_version (\r
+       apiCB*                          inContext,\r
+       ccache_p*                       inCCache,\r
+       cc_int32*                       outVersion)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_set_principal (\r
+       apiCB*                          inContext,\r
+       ccache_p*                       inCCache,\r
+       cc_int32                        inVersion,\r
+       char*                           inPrincipal)\r
+{\r
+    if (inVersion != CC_CRED_V4 && inVersion != CC_CRED_V5)\r
+       return CC_ERR_CRED_VERSION;\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_get_principal (\r
+       apiCB*                          inContext,\r
+       ccache_p*                       inCCache,\r
+       char**                          outPrincipal)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_store (\r
+       apiCB*                          inContext,\r
+       ccache_p*                       inCCache,\r
+       cred_union                      inCredentials)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+\r
+CCACHE_API cc_int32 cc_remove_cred (\r
+       apiCB*                          inContext,\r
+       ccache_p*                       inCCache,\r
+       cred_union                      inCredentials)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+\r
+CCACHE_API cc_int32 cc_seq_fetch_creds_begin (\r
+       apiCB*                          inContext,\r
+       const ccache_p*                 inCCache,\r
+       ccache_cit**                    outIterator)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+\r
+CCACHE_API cc_int32 cc_seq_fetch_creds_next (\r
+       apiCB*                          inContext,\r
+       cred_union**                    outCreds,\r
+       ccache_cit*                     inIterator)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_seq_fetch_creds_end (\r
+       apiCB*                          inContext,\r
+       ccache_cit**                    ioIterator)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+       \r
+CCACHE_API cc_int32 cc_free_principal (\r
+       apiCB*                          inContext,\r
+       char**                          ioPrincipal)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+\r
+CCACHE_API cc_int32 cc_free_name (\r
+       apiCB*                          inContext,\r
+       char**                          ioName)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+\r
+CCACHE_API cc_int32 cc_free_creds (\r
+       apiCB*                          inContext,\r
+       cred_union**                    creds)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+\r
+CCACHE_API cc_int32 cc_free_NC_info (\r
+       apiCB*                          inContext,\r
+       infoNC***                       ioInfo)\r
+{\r
+       \r
+    /* replace this return value when the function is implemented */\r
+    return CC_NOT_SUPP;\r
+}\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif /* __cplusplus */\r
+\r
index 86c41b8e7018671bba982f9d4c989bb05490af96..efac3020c8a2c5ffe4a09c0224801ba8594c216e 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
 #include <stdio.h>
 #include <CredentialsCache.h>
 #include "context.h"
+#include "cc_rpc.h"
 #include "msg.h"
 #include "msg_headers.h"
 
+/* cc_int_context_new
+ *
+ * input parameters (handle, version) are in host order 
+ */
+
 cc_int32
 cc_int_context_new( cc_context_t * pcontext, cc_handle handle, cc_uint32 version )
 {
@@ -87,11 +93,13 @@ cc_int_context_new( cc_context_t * pcontext, cc_handle handle, cc_uint32 version
 cc_int32    
 cc_int_context_release( cc_context_t context )
 {
-    cc_int_context_t int_context;
-    cc_msg_t        *request;
+    cc_int_context_t   int_context;
+    cc_msg_t           *request;
     ccmsg_ctx_release_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t           *response;
+    cc_uint32          type;
+    cc_time64          t64;
+    cc_int32           code;
 
     if ( context == NULL )
         return ccErrBadParam;
@@ -104,7 +112,7 @@ cc_int_context_release( cc_context_t context )
     request_header = (ccmsg_ctx_release_t*)malloc(sizeof(ccmsg_ctx_release_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_context->handle;
+    request_header->ctx = htonl(int_context->handle);
 
     code = cci_msg_new(ccmsg_CTX_RELEASE, &request);
     if (code != ccNoError) {
@@ -116,10 +124,11 @@ cc_int_context_release( cc_context_t context )
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -133,14 +142,16 @@ cc_int_context_release( cc_context_t context )
 
 cc_int32
 cc_int_context_get_change_time( cc_context_t context,
-                                cc_time_t* time)
+                                cc_time* time)
 {
-    cc_int_context_t int_context;
-    cc_msg_t        *request;
+    cc_int_context_t           int_context;
+    cc_msg_t                   *request;
     ccmsg_ctx_get_change_time_t *request_header;
-    cc_msg_t        *response;
+    cc_msg_t                   *response;
     ccmsg_ctx_get_change_time_resp_t *response_header;
-    cc_int32 code;
+    cc_time64          t64;
+    cc_uint32                  type;
+    cc_int32                   code;
 
     if ( context == NULL || time == NULL )
         return ccErrBadParam;
@@ -153,7 +164,7 @@ cc_int_context_get_change_time( cc_context_t context,
     request_header = (ccmsg_ctx_get_change_time_t*)malloc(sizeof(ccmsg_ctx_get_change_time_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_context->handle;
+    request_header->ctx = htonll(int_context->handle);
 
     code = cci_msg_new(ccmsg_CTX_GET_CHANGE_TIME, &request);
     if (code != ccNoError) {
@@ -165,12 +176,15 @@ cc_int_context_get_change_time( cc_context_t context,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
+        code = ntohl(nack_header->err_code);
     } else if (response->type == ccmsg_ACK) {
         response_header = (ccmsg_ctx_get_change_time_resp_t*)response->header;
-        *time = response_header->time;
+        t64 = ntohll(response_header->time);
+       /* TODO: validate that value is not greater than can fit in cc_time */
+       *time = (cc_time)t64;
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -184,12 +198,13 @@ cc_int32
 cc_int_context_get_default_ccache_name( cc_context_t context,
                                         cc_string_t* name )
 {
-    cc_int_context_t int_context;
-    cc_msg_t        *request;
+    cc_int_context_t   int_context;
+    cc_msg_t           *request;
     ccmsg_ctx_get_default_ccache_name_t *request_header;
-    cc_msg_t        *response;
+    cc_msg_t           *response;
     ccmsg_ctx_get_default_ccache_name_resp_t *response_header;
-    cc_int32 code;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( context == NULL || name == NULL )
         return ccErrBadParam;
@@ -202,7 +217,7 @@ cc_int_context_get_default_ccache_name( cc_context_t context,
     request_header = (ccmsg_ctx_get_default_ccache_name_t*)malloc(sizeof(ccmsg_ctx_get_default_ccache_name_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_context->handle;
+    request_header->ctx = htonll(int_context->handle);
 
     code = cci_msg_new(ccmsg_CTX_GET_DEFAULT_CCACHE_NAME, &request);
     if (code != ccNoError) {
@@ -214,10 +229,11 @@ cc_int_context_get_default_ccache_name( cc_context_t context,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         char * string;
         response_header = (ccmsg_ctx_get_default_ccache_name_resp_t*)response->header;
         code = cci_msg_retrieve_blob(response, response_header->name_offset, 
@@ -244,7 +260,8 @@ cc_int_context_compare( cc_context_t context,
     ccmsg_ctx_compare_t *request_header;
     cc_msg_t        *response;
     ccmsg_ctx_compare_resp_t *response_header;
-    cc_int32 code;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( context == NULL || compare_to == NULL || 
          equal == NULL )
@@ -260,8 +277,8 @@ cc_int_context_compare( cc_context_t context,
     request_header = (ccmsg_ctx_compare_t*)malloc(sizeof(ccmsg_ctx_compare_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx1 = int_context->handle;
-    request_header->ctx2 = int_compare_to->handle;
+    request_header->ctx1 = htonl(int_context->handle);
+    request_header->ctx2 = htonl(int_compare_to->handle);
 
     code = cci_msg_new(ccmsg_CTX_COMPARE, &request);
     if (code != ccNoError) {
@@ -273,12 +290,13 @@ cc_int_context_compare( cc_context_t context,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         response_header = (ccmsg_ctx_compare_resp_t*)response->header;
-        *equal = response_header->is_equal;
+        *equal = ntohl(response_header->is_equal);
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -293,12 +311,13 @@ cc_int32
 cc_int_context_new_ccache_iterator( cc_context_t context,
                                     cc_ccache_iterator_t* iterator )
 {
-    cc_int_context_t int_context;
-    cc_msg_t        *request;
+    cc_int_context_t   int_context;
+    cc_msg_t           *request;
     ccmsg_ctx_new_ccache_iterator_t *request_header;
-    cc_msg_t        *response;
+    cc_msg_t           *response;
     ccmsg_ctx_new_ccache_iterator_resp_t *response_header;
-    cc_int32 code;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( context == NULL || iterator == NULL )
         return ccErrBadParam;
@@ -311,7 +330,7 @@ cc_int_context_new_ccache_iterator( cc_context_t context,
     request_header = (ccmsg_ctx_new_ccache_iterator_t*)malloc(sizeof(ccmsg_ctx_new_ccache_iterator_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_context->handle;
+    request_header->ctx = htonll(int_context->handle);
 
     code = cci_msg_new(ccmsg_CTX_NEW_CCACHE_ITERATOR, &request);
     if (code != ccNoError) {
@@ -323,12 +342,14 @@ cc_int_context_new_ccache_iterator( cc_context_t context,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         response_header = (ccmsg_ctx_new_ccache_iterator_resp_t*)response->header;
-        code = cc_int_ccache_iterator_new(iterator, int_context->handle, response_header->iterator);
+        code = cc_int_ccache_iterator_new(iterator, int_context->handle,
+                                          ntohll(response_header->iterator));
     } else {
         code = ccErrBadInternalMessage;
     }
@@ -342,13 +363,14 @@ cc_int_context_open_ccache( cc_context_t context,
                             const char* name,
                             cc_ccache_t* ccache )
 {
-    cc_uint32 blob_pos;
-    cc_int_context_t int_context;
-    cc_msg_t        *request;
+    cc_uint32          blob_pos;
+    cc_int_context_t   int_context;
+    cc_msg_t           *request;
     ccmsg_ccache_open_t *request_header;
-    cc_msg_t        *response;
+    cc_msg_t           *response;
     ccmsg_ccache_open_resp_t *response_header;
-    cc_int32 code;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( context == NULL || name == NULL || ccache == NULL )
         return ccErrBadParam;
@@ -362,7 +384,7 @@ cc_int_context_open_ccache( cc_context_t context,
     if (request_header == NULL)
         return ccErrNoMem;
 
-    code = cci_msg_new(ccmsg_CCACHE_OPEN, &request);
+    code = cci_msg_new(ccmsg_CTX_CCACHE_OPEN, &request);
     if (code != ccNoError) {
         free(request_header);
         return code;
@@ -375,20 +397,21 @@ cc_int_context_open_ccache( cc_context_t context,
         return code;
     }
     
-    request_header->ctx = int_context->handle;
-    request_header->name_offset = blob_pos;
-    request_header->name_len = strlen(name) + 1;
+    request_header->ctx = htonll(int_context->handle);
+    request_header->name_offset = htonl(blob_pos);
+    request_header->name_len = htonl(strlen(name) + 1);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_open_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         response_header = (ccmsg_ccache_open_resp_t*)response->header;
-        code = cc_cache_new(ccache, response_header->ccache);
+        code = cc_int_cache_new(ccache, int_context->handle, ntohll(response_header->ccache));
     } else {
         code = ccErrBadInternalMessage;
     }
@@ -401,12 +424,13 @@ cc_int32
 cc_int_context_open_default_ccache( cc_context_t context,
                                     cc_ccache_t* ccache)
 {
-    cc_int_context_t int_context;
-    cc_msg_t        *request;
+    cc_int_context_t   int_context;
+    cc_msg_t           *request;
     ccmsg_ccache_open_default_t *request_header;
-    cc_msg_t        *response;
+    cc_msg_t           *response;
     ccmsg_ccache_open_resp_t *response_header;
-    cc_int32 code;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( context == NULL || ccache == NULL )
         return ccErrBadParam;
@@ -420,24 +444,25 @@ cc_int_context_open_default_ccache( cc_context_t context,
     if (request_header == NULL)
         return ccErrNoMem;
 
-    code = cci_msg_new(ccmsg_CCACHE_OPEN_DEFAULT, &request);
+    code = cci_msg_new(ccmsg_CTX_CCACHE_OPEN_DEFAULT, &request);
     if (code != ccNoError) {
         free(request_header);
         return code;
     }
 
-    request_header->ctx = int_context->handle;
+    request_header->ctx = htonll(int_context->handle);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_open_default_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         response_header = (ccmsg_ccache_open_resp_t*)response->header;
-        code = cc_cache_new(ccache, response_header->ccache);
+        code = cc_int_cache_new(ccache, int_context->handle, ntohll(response_header->ccache));
     } else {
         code = ccErrBadInternalMessage;
     }
@@ -453,13 +478,14 @@ cc_int_context_create_ccache( cc_context_t context,
                               const char* principal, 
                               cc_ccache_t* ccache )
 {
-    cc_uint32 blob_pos;
-    cc_int_context_t int_context;
-    cc_msg_t        *request;
+    cc_uint32          blob_pos;
+    cc_int_context_t   int_context;
+    cc_msg_t           *request;
     ccmsg_ccache_create_t *request_header;
-    cc_msg_t        *response;
+    cc_msg_t           *response;
     ccmsg_ccache_create_resp_t *response_header;
-    cc_int32 code;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( context == NULL || name == NULL || 
          cred_vers == 0 || cred_vers > cc_credentials_v4_v5 ||
@@ -475,7 +501,7 @@ cc_int_context_create_ccache( cc_context_t context,
     if (request_header == NULL)
         return ccErrNoMem;
 
-    code = cci_msg_new(ccmsg_CCACHE_CREATE, &request);
+    code = cci_msg_new(ccmsg_CTX_CCACHE_CREATE, &request);
     if (code != ccNoError) {
         free(request_header);
         return code;
@@ -488,10 +514,10 @@ cc_int_context_create_ccache( cc_context_t context,
         return code;
     }
     
-    request_header->ctx = int_context->handle;
-    request_header->version = cred_vers;
-    request_header->name_offset = blob_pos;
-    request_header->name_len = strlen(name) + 1;
+    request_header->ctx = htonll(int_context->handle);
+    request_header->version = htonl(cred_vers);
+    request_header->name_offset = htonl(blob_pos);
+    request_header->name_len = htonl(strlen(name) + 1);
 
     code = cci_msg_add_data_blob(request, (void *)principal, strlen(principal) + 1, &blob_pos);
     if (code != ccNoError) {
@@ -499,19 +525,20 @@ cc_int_context_create_ccache( cc_context_t context,
         free(request_header);
         return code;
     }
-    request_header->principal_offset = blob_pos;
-    request_header->principal_len = strlen(principal) + 1;
+    request_header->principal_offset = htonl(blob_pos);
+    request_header->principal_len = htonl(strlen(principal) + 1);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_create_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         response_header = (ccmsg_ccache_create_resp_t*)response->header;
-        code = cc_cache_new(ccache, response_header->ccache);
+        code = cc_int_cache_new(ccache, int_context->handle, ntohll(response_header->ccache));
     } else {
         code = ccErrBadInternalMessage;
     }
@@ -526,13 +553,14 @@ cc_int_context_create_default_ccache( cc_context_t context,
                                       const char* principal, 
                                       cc_ccache_t* ccache )
 {
-    cc_uint32 blob_pos;
-    cc_int_context_t int_context;
-    cc_msg_t        *request;
+    cc_uint32          blob_pos;
+    cc_int_context_t   int_context;
+    cc_msg_t           *request;
     ccmsg_ccache_create_default_t *request_header;
-    cc_msg_t        *response;
+    cc_msg_t           *response;
     ccmsg_ccache_create_resp_t *response_header;
-    cc_int32 code;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( context == NULL ||
          cred_vers == 0 || cred_vers > cc_credentials_v4_v5 ||
@@ -548,14 +576,14 @@ cc_int_context_create_default_ccache( cc_context_t context,
     if (request_header == NULL)
         return ccErrNoMem;
 
-    code = cci_msg_new(ccmsg_CCACHE_CREATE_DEFAULT, &request);
+    code = cci_msg_new(ccmsg_CTX_CCACHE_CREATE_DEFAULT, &request);
     if (code != ccNoError) {
         free(request_header);
         return code;
     }
 
-    request_header->ctx = int_context->handle;
-    request_header->version = cred_vers;
+    request_header->ctx = htonll(int_context->handle);
+    request_header->version = htonl(cred_vers);
 
     code = cci_msg_add_data_blob(request, (void *)principal, strlen(principal) + 1, &blob_pos);
     if (code != ccNoError) {
@@ -563,19 +591,20 @@ cc_int_context_create_default_ccache( cc_context_t context,
         free(request_header);
         return code;
     }
-    request_header->principal_offset = blob_pos;
-    request_header->principal_len = strlen(principal) + 1;
+    request_header->principal_offset = htonl(blob_pos);
+    request_header->principal_len = htonl(strlen(principal) + 1);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_create_default_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         response_header = (ccmsg_ccache_create_resp_t*)response->header;
-        code = cc_cache_new(ccache, response_header->ccache);
+        code = cc_int_cache_new(ccache, int_context->handle, ntohll(response_header->ccache));
     } else {
         code = ccErrBadInternalMessage;
     }
@@ -590,13 +619,14 @@ cc_int_context_create_new_ccache( cc_context_t context,
                                   const char* principal, 
                                   cc_ccache_t* ccache )
 {
-    cc_uint32 blob_pos;
-    cc_int_context_t int_context;
-    cc_msg_t        *request;
+    cc_uint32          blob_pos;
+    cc_int_context_t   int_context;
+    cc_msg_t           *request;
     ccmsg_ccache_create_unique_t *request_header;
-    cc_msg_t        *response;
+    cc_msg_t           *response;
     ccmsg_ccache_create_resp_t *response_header;
-    cc_int32 code;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( context == NULL ||
          cred_vers == 0 || cred_vers > cc_credentials_v4_v5 ||
@@ -612,14 +642,14 @@ cc_int_context_create_new_ccache( cc_context_t context,
     if (request_header == NULL)
         return ccErrNoMem;
 
-    code = cci_msg_new(ccmsg_CCACHE_CREATE_UNIQUE, &request);
+    code = cci_msg_new(ccmsg_CTX_CCACHE_CREATE_UNIQUE, &request);
     if (code != ccNoError) {
         free(request_header);
         return code;
     }
 
-    request_header->ctx = int_context->handle;
-    request_header->version = cred_vers;
+    request_header->ctx = htonll(int_context->handle);
+    request_header->version = htonl(cred_vers);
 
     code = cci_msg_add_data_blob(request, (void *)principal, strlen(principal) + 1, &blob_pos);
     if (code != ccNoError) {
@@ -627,19 +657,20 @@ cc_int_context_create_new_ccache( cc_context_t context,
         free(request_header);
         return code;
     }
-    request_header->principal_offset = blob_pos;
-    request_header->principal_len = strlen(principal) + 1;
+    request_header->principal_offset = htonl(blob_pos);
+    request_header->principal_len = htonl(strlen(principal) + 1);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_create_unique_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = htonl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         response_header = (ccmsg_ccache_create_resp_t*)response-> header;
-        code = cc_cache_new(ccache, response_header->ccache);
+        code = cc_int_cache_new(ccache, int_context->handle, ntohll(response_header->ccache));
     } else {
         code = ccErrBadInternalMessage;
     }
@@ -653,14 +684,16 @@ cc_int_context_lock( cc_context_t context,
                      cc_uint32 lock_type,
                      cc_uint32 block )
 {
-    cc_int_context_t int_context;
-    cc_msg_t        *request;
-    ccmsg_ctx_lock_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_int_context_t   int_context;
+    cc_msg_t           *request;
+    ccmsg_ctx_lock_t   *request_header;
+    cc_msg_t           *response;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( context == NULL || 
-         (lock_type != cc_lock_read && lock_type != cc_lock_write) ||
+         (lock_type != cc_lock_read && lock_type != cc_lock_write &&
+         lock_type != cc_lock_upgrade && lock_type != cc_lock_downgrade) ||
          (block != cc_lock_block && block != cc_lock_noblock) )
         return ccErrBadParam;
 
@@ -679,19 +712,20 @@ cc_int_context_lock( cc_context_t context,
         return code;
     }
 
-    request_header->ctx = int_context->handle;
-    request_header->lock_type;
+    request_header->ctx = htonll(int_context->handle);
+    request_header->lock_type = htonl(lock_type);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_lock_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
+        code = ntohl(nack_header->err_code);
 
         // TODO: if (block == cc_lock_block) .....
-    } else if (response->type == ccmsg_ACK) {
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -704,11 +738,12 @@ cc_int_context_lock( cc_context_t context,
 cc_int32
 cc_int_context_unlock( cc_context_t context )
 {
-    cc_int_context_t int_context;
-    cc_msg_t        *request;
+    cc_int_context_t   int_context;
+    cc_msg_t           *request;
     ccmsg_ctx_unlock_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t           *response;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( context == NULL )
         return ccErrBadParam;
@@ -728,16 +763,17 @@ cc_int_context_unlock( cc_context_t context )
         return code;
     }
 
-    request_header->ctx = int_context->handle;
+    request_header->ctx = htonll(int_context->handle);
 
     code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_unlock_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -754,20 +790,21 @@ cc_int_context_clone( cc_context_t      inContext,
                       cc_int32*         supportedVersion,
                       char const**      vendor )
 {
-    cc_int_context_t int_context, new_context;
-    static char vendor_st[128] = "";
-    cc_msg_t     *request;
-    ccmsg_clone_t *request_header;
-    cc_msg_t     *response;
-    ccmsg_clone_resp_t *response_header;
-    cc_int32 code;
+    cc_int_context_t   int_context, new_context;
+    static char        vendor_st[128] = "";
+    cc_msg_t           *request;
+    ccmsg_ctx_clone_t  *request_header;
+    cc_msg_t           *response;
+    ccmsg_ctx_clone_resp_t *response_header;
+    cc_uint32          type;
+    cc_int32           code;
 
     if ( inContext == NULL ||
          outContext == NULL ||
          supportedVersion == NULL )
         return ccErrBadParam;
 
-    int_context = (cc_int_context_t)context;
+    int_context = (cc_int_context_t)inContext;
 
     if ( int_context->magic != CC_CONTEXT_MAGIC )
         return ccErrInvalidContext;
@@ -775,20 +812,21 @@ cc_int_context_clone( cc_context_t      inContext,
     if ((requestedVersion != ccapi_version_2) &&
          (requestedVersion != ccapi_version_3) &&
          (requestedVersion != ccapi_version_4) &&
-         (requestedVersion != ccapi_version_5)) {
+         (requestedVersion != ccapi_version_5) &&
+        (requestedVersion != ccapi_version_6)) {
 
         if (supportedVersion != NULL) {
-            *supportedVersion = ccapi_version_5;
+            *supportedVersion = ccapi_version_max;
         }
         return ccErrBadAPIVersion;
     }   
 
-    request_header = (ccmsg_clone_t*)malloc(sizeof(ccmsg_clone_t));
+    request_header = (ccmsg_ctx_clone_t*)malloc(sizeof(ccmsg_ctx_clone_t));
     if (request_header == NULL)
         return ccErrNoMem;
 
-    request_header->ctx = int_context->handle;
-    request_header->in_version = requestedVersion;
+    request_header->ctx = htonll(int_context->handle);
+    request_header->in_version = htonl(requestedVersion);
 
     code = cci_msg_new(ccmsg_INIT, &request);
     if (code != ccNoError) {
@@ -796,21 +834,22 @@ cc_int_context_clone( cc_context_t      inContext,
         return code;
     }
 
-    code = cci_msg_add_header(request, request_header, sizeof(ccmsg_init_t));
+    code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_clone_t));
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
-        response_header = (ccmsg_clone_resp_t *)response->header;
-        *supportedVersion = response_header->out_version;
-        code = cc_int_context_new(outContext, response_header->out_ctx, response_header->out_version);
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
+        response_header = (ccmsg_ctx_clone_resp_t *)response->header;
+        *supportedVersion = ntohl(response_header->out_version);
+        code = cc_int_context_new(outContext, ntohll(response_header->out_ctx), nthol(response_header->out_version));
 
         if (!vendor_st[0]) {
             char * string;
-            code = cci_msg_retrieve_blob(response, response_header->vendor_offset, response_header->vendor_length, &string);
+            code = cci_msg_retrieve_blob(response, ntohl(response_header->vendor_offset), ntohl(response_header->vendor_length), &string);
             strncpy(vendor_st, string, sizeof(vendor_st)-1);
             vendor_st[sizeof(vendor_st)-1] = '\0';
             free(string);
index cd5ca678d443cc3e0c6c604450f1f3cccded2933..6ff113a26928a4da32b06aa656f532c68ecd946f 100644 (file)
@@ -66,7 +66,7 @@ cc_int_context_release( cc_context_t context );
 
 cc_int32
 cc_int_context_get_change_time( cc_context_t context,
-                                cc_time_t* time);
+                                cc_time* time);
 
 cc_int32
 cc_int_context_get_default_ccache_name( cc_context_t context,
index b0a3df2b7531d81936b3003c9d00ac3be9b1f619..8b886768921be4d7ba5f13bd34329fd0b362605c 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -159,23 +159,23 @@ cc_int_credentials_release( cc_credentials_t creds )
 
 cc_int32
 cc_int_credentials_compare( cc_credentials_t credentials,
-                        cc_credentials_t compare_to,
-                        cc_uint32* equal )
+                           cc_credentials_t compare_to,
+                           cc_uint32* equal )
 {
     cc_int_credentials_t int_credentials;
     cc_int_credentials_t int_compare_to;
 
     if ( credentials == NULL || compare_to == NULL || equal == NULL )
         return ccErrBadParam;
-
     
+    int_credentials = (cc_int_credentials_t)credentials;
+    int_compare_to  = (cc_int_credentials_t)compare_to;
+
     if ( int_credentials->magic != CC_CREDS_MAGIC ||
          int_compare_to->magic != CC_CREDS_MAGIC )
         return ccErrInvalidCredentials;
 
-    int_credentials = (cc_int_credentials_t)credentials;
-    int_compare_to  = (cc_int_credentials_t)compare_to;
-
     *equal = (int_credentials->handle == int_compare_to->handle);
+   
     return ccNoError;
 }
index 320c6182573231592ca4ef4db29b27f187dea006..dfd589f3267ff964a14de0d09fe4f32c7c3fec6f 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -84,8 +84,8 @@ cci_creds_v5_marshall( cc_credentials_v5_t * creds,
 
 cc_int32
 cci_creds_v4_unmarshall( char * flat, 
-                             cc_uint32 len,
-                             cc_credentials_union * creds);
+                         cc_uint32 len,
+                         cc_credentials_union * creds);
 
 cc_int32
 cci_creds_v5_unmarshall( char * flat, 
index b7333daf30077958fc9eaf0bae7d8e7a9d1308e2..bae60ffdf05070091321990d83ec6dd379420606 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -47,6 +47,7 @@
 #include <stdio.h>
 #include <CredentialsCache.h>
 #include "credentials_iterator.h"
+#include "cc_rpc.h"
 #include "msg.h"
 #include "msg_headers.h"
 
@@ -74,6 +75,7 @@ cc_int_credentials_iterator_new( cc_credentials_iterator_t * piter,
 
     iter->functions->release = cc_int_credentials_iterator_release;
     iter->functions->next = cc_int_credentials_iterator_next;
+    iter->functions->clone = cc_int_credentials_iterator_clone;
     iter->magic = CC_CREDS_ITER_MAGIC;
     iter->ctx = ctx;
     iter->ccache = ccache;
@@ -87,10 +89,11 @@ cc_int32
 cc_int_credentials_iterator_release( cc_credentials_iterator_t iter )
 {
     cc_int_credentials_iterator_t int_iter;
-    cc_msg_t        *request;
+    cc_msg_t                   *request;
     ccmsg_creds_iterator_release_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_int32                   code;
 
     if ( iter == NULL )
         return ccErrBadParam;
@@ -103,9 +106,10 @@ cc_int_credentials_iterator_release( cc_credentials_iterator_t iter )
     request_header = (ccmsg_creds_iterator_release_t*)malloc(sizeof(ccmsg_creds_iterator_release_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_iter->ctx;
-    request_header->ccache = int_iter->ccache;
-    request_header->iterator = int_iter->handle;
+    request_header->ctx = htonll(int_iter->ctx);
+    request_header->ccache = htonll(int_iter->ccache);
+    request_header->iterator = htonll(int_iter->handle);
+
     code = cci_msg_new(ccmsg_CREDS_ITERATOR_RELEASE, &request);
     if (code != ccNoError) {
         free(request_header);
@@ -116,10 +120,11 @@ cc_int_credentials_iterator_release( cc_credentials_iterator_t iter )
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = htonl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = htonl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         code = ccNoError;
     } else {
         code = ccErrBadInternalMessage;
@@ -137,10 +142,11 @@ cc_int_credentials_iterator_next( cc_credentials_iterator_t iter,
                                   cc_credentials_t * credentials )
 {
     cc_int_credentials_iterator_t int_iter;
-    cc_msg_t        *request;
+    cc_msg_t                   *request;
     ccmsg_creds_iterator_next_t *request_header;
-    cc_msg_t        *response;
-    cc_int32 code;
+    cc_msg_t                   *response;
+    cc_uint32                  type;
+    cc_int32                   code;
 
     if ( credentials == NULL )
         return ccErrBadParam;
@@ -153,9 +159,9 @@ cc_int_credentials_iterator_next( cc_credentials_iterator_t iter,
     request_header = (ccmsg_creds_iterator_next_t*)malloc(sizeof(ccmsg_creds_iterator_next_t));
     if (request_header == NULL)
         return ccErrNoMem;
-    request_header->ctx = int_iter->ctx;
-    request_header->ccache = int_iter->ccache;
-    request_header->iterator = int_iter->handle;
+    request_header->ctx = htonll(int_iter->ctx);
+    request_header->ccache = htonll(int_iter->ccache);
+    request_header->iterator = htonll(int_iter->handle);
 
     code = cci_msg_new(ccmsg_CREDS_ITERATOR_NEXT, &request);
     if (code != ccNoError) {
@@ -167,16 +173,17 @@ cc_int_credentials_iterator_next( cc_credentials_iterator_t iter,
 
     code = cci_perform_rpc(request, &response);
 
-    if (response->type == ccmsg_NACK) {
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
         ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
-        code = nack_header->err_code;
-    } else if (response->type == ccmsg_ACK) {
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
         char * blob;
         ccmsg_creds_iterator_next_resp_t * response_header = (ccmsg_creds_iterator_next_resp_t*)response->header;
-        code = cci_msg_retrieve_blob(response, response_header->creds_offset, response_header->creds_len, &blob);
-        code = cc_credentials_new(credentials, response_header->version,
-                                  int_iter->ctx, int_iter->ccache, response_header->creds_handle
-                                  blob, response_header->creds_len);
+        code = cci_msg_retrieve_blob(response, ntohl(response_header->creds_offset), ntohl(response_header->creds_len), &blob);
+        code = cc_int_credentials_new(credentials, ntohl(response_header->version),
+                                  int_iter->ctx, int_iter->ccache, ntohll(response_header->creds_handle)
+                                  blob, ntohl(response_header->creds_len));
         free(blob);
     } else {
         code = ccErrBadInternalMessage;
@@ -185,3 +192,54 @@ cc_int_credentials_iterator_next( cc_credentials_iterator_t iter,
     cci_msg_destroy(response);
     return code;
 }
+
+cc_int32
+cc_int_credentials_iterator_clone( cc_credentials_iterator_t iter,
+                                  cc_credentials_iterator_t* new_iter)
+{
+    cc_int_credentials_iterator_t      int_iter;
+    cc_msg_t                           *request;
+    ccmsg_creds_iterator_clone_t       *request_header;
+    cc_msg_t                           *response;
+    cc_uint32                          type;
+    cc_int32                           code;
+
+    if ( iter == NULL || new_iter == NULL )
+        return ccErrBadParam;
+
+    int_iter = (cc_int_credentials_iterator_t)iter;
+
+    if ( int_iter->magic != CC_CREDS_ITER_MAGIC )
+        return ccErrInvalidCCacheIterator;
+
+    request_header = (ccmsg_creds_iterator_clone_t*)malloc(sizeof(ccmsg_creds_iterator_clone_t));
+    if (request_header == NULL)
+        return ccErrNoMem;
+    request_header->ctx = htonll(int_iter->ctx);
+    request_header->iterator = htonll(int_iter->handle);
+
+    code = cci_msg_new(ccmsg_CREDS_ITERATOR_CLONE, &request);
+    if (code != ccNoError) {
+        free(request_header);
+        return code;
+    }
+
+    code = cci_msg_add_header(request, request_header, sizeof(ccmsg_creds_iterator_clone_t));
+
+    code = cci_perform_rpc(request, &response);
+
+    type = ntohl(response->type);
+    if (type == ccmsg_NACK) {
+        ccmsg_nack_t * nack_header = (ccmsg_nack_t *)response->header;
+        code = ntohl(nack_header->err_code);
+    } else if (type == ccmsg_ACK) {
+        ccmsg_creds_iterator_clone_resp_t * response_header = (ccmsg_creds_iterator_clone_resp_t*)response->header;
+        code = cc_int_credentials_iterator_new(new_iter, int_iter->ctx, int_iter->ccache, ntohll(response_header->iterator));
+    } else {
+        code = ccErrBadInternalMessage;
+    }
+    cci_msg_destroy(request);
+    cci_msg_destroy(response);
+    return code;
+}
+
index 2a6f8edf2d8554104b6ca5ea22f8627e987828ea..954d2f1afaf2a3971310e1c8a556c27192ad3305 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -69,4 +69,8 @@ cc_int32
 cc_int_credentials_iterator_next( cc_credentials_iterator_t iter,
                                   cc_credentials_t * credentials );
 
+cc_int32
+cc_int_credentials_iterator_clone( cc_credentials_iterator_t iter,
+                                   cc_credentials_iterator_t * new_iter );
+
 
diff --git a/src/lib/ccapi/client/marshall.c b/src/lib/ccapi/client/marshall.c
new file mode 100644 (file)
index 0000000..31ebacd
--- /dev/null
@@ -0,0 +1,445 @@
+/* $Copyright:\r
+ *\r
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.\r
+ * \r
+ * All rights reserved.\r
+ * \r
+ * Export of this software from the United States of America may require a\r
+ * specific license from the United States Government.  It is the\r
+ * responsibility of any person or organization contemplating export to\r
+ * obtain such a license before exporting.\r
+ * \r
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute\r
+ * this software and its documentation for any purpose and without fee is\r
+ * hereby granted, provided that the above copyright notice appear in all\r
+ * copies and that both that copyright notice and this permission notice\r
+ * appear in supporting documentation, and that the name of M.I.T. not be\r
+ * used in advertising or publicity pertaining to distribution of the\r
+ * software without specific, written prior permission.  Furthermore if you\r
+ * modify this software you must label your software as modified software\r
+ * and not distribute it in such a fashion that it might be confused with\r
+ * the original MIT software. M.I.T. makes no representations about the\r
+ * suitability of this software for any purpose.  It is provided "as is"\r
+ * without express or implied warranty.\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\r
+ * \r
+ * Individual source code files are copyright MIT, Cygnus Support,\r
+ * OpenVision, Oracle, Sun Soft, FundsXpress, and others.\r
+ * \r
+ * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,\r
+ * and Zephyr are trademarks of the Massachusetts Institute of Technology\r
+ * (MIT).  No commercial use of these trademarks may be made without prior\r
+ * written permission of MIT.\r
+ * \r
+ * "Commercial use" means use of a name in a product or other for-profit\r
+ * manner.  It does NOT prevent a commercial firm from referring to the MIT\r
+ * trademarks in order to convey information (although in doing so,\r
+ * recognition of their trademark status should be given).\r
+ * $\r
+ */\r
+\r
+/* marshall.c */\r
+\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+#include <CredentialsCache.h>\r
+#include "msg.h"\r
+#include "msg_headers.h"\r
+#include "marshall.h"\r
+\r
+cc_int32\r
+cci_creds_v4_marshall( cc_credentials_v4_t * creds, \r
+                       char ** pflat, \r
+                       cc_uint32 * plen)\r
+{\r
+    cc_uint32 len;\r
+    char * flat;\r
+    cci_flat_creds_v4_t * header;\r
+    cc_uint32 length;\r
+    cc_time64 t64;\r
+\r
+    if ( creds == NULL || pflat == NULL || plen == NULL )\r
+        return ccErrBadParam;\r
+\r
+    len = sizeof(cci_flat_creds_v4_t);\r
+    flat = (char *)malloc(len);\r
+    if ( flat == NULL )\r
+        return ccErrNoMem;\r
+    memset(flat, 0, len);\r
+\r
+    header = (cci_flat_creds_v4_t *)flat;\r
+    header->version = htonl(creds->version);\r
+    memcpy(header->principal, creds->principal, cc_v4_name_size);\r
+    memcpy(header->principal_instance, creds->principal_instance, cc_v4_instance_size);\r
+    memcpy(header->service, creds->service, cc_v4_name_size);\r
+    memcpy(header->service_instance, creds->service_instance, cc_v4_instance_size);\r
+    memcpy(header->realm, creds->realm, cc_v4_realm_size);\r
+    memcpy(header->session_key, creds->session_key, cc_v4_key_size);\r
+    header->kvno = htonl(creds->kvno);\r
+    header->string_to_key_type = htonl(creds->string_to_key_type);\r
+    t64 = creds->issue_date;\r
+    header->issue_date = htonll(t64);\r
+    header->lifetime = htonl(creds->lifetime);\r
+    /* TODO: verify that address is stored in host order */\r
+    header->address = htonl(creds->address);\r
+    header->ticket_size = htonl(creds->ticket_size);\r
+    memcpy(header->ticket, creds->ticket, cc_v4_ticket_size);\r
+\r
+    *pflat = flat;\r
+    *plen = len;\r
+\r
+    return ccNoError;  \r
+}\r
+\r
+cc_int32\r
+cci_creds_v4_unmarshall( char * flat, \r
+                         cc_uint32 len,\r
+                         cc_credentials_union * creds_union)\r
+{\r
+    struct cci_flat_creds_v4 * header;\r
+    cc_credentials_v4_t * creds;\r
+    cc_flat_data * flat_data;\r
+    cc_time64 t64;\r
+    cc_uint32  length;\r
+    cc_int32   code;\r
+\r
+    if ( flat == NULL || len == 0 || creds_union == NULL )\r
+        return ccErrBadParam;\r
+\r
+    creds_union->version = cc_credentials_v4;\r
+\r
+    header = (cci_flat_creds_v4_t *)flat;\r
+\r
+    creds = (cc_credentials_v4_t *)malloc(sizeof(cc_credentials_v4_t));\r
+    if ( creds == NULL )\r
+       return ccErrNoMem;\r
+\r
+    creds->version = ntohl(header->version);\r
+    memcpy(creds->principal, header->principal, cc_v4_name_size);\r
+    memcpy(creds->principal_instance, header->principal_instance, cc_v4_instance_size);\r
+    memcpy(creds->service, header->service, cc_v4_name_size);\r
+    memcpy(creds->service_instance, header->service_instance, cc_v4_instance_size);\r
+    memcpy(creds->realm, header->realm, cc_v4_realm_size);\r
+    memcpy(creds->session_key, header->session_key, cc_v4_key_size);\r
+    creds->kvno = htonl(header->kvno);\r
+    creds->string_to_key_type = htonl(header->string_to_key_type);\r
+    t64 = header->issue_date;\r
+    creds->issue_date = ntohll(t64);\r
+    creds->lifetime = ntohl(header->lifetime);\r
+    /* TODO: verify that address is stored in host order */\r
+    creds->address = ntohl(header->address);\r
+    creds->ticket_size = ntohl(header->ticket_size);\r
+    memcpy(creds->ticket, header->ticket, cc_v4_ticket_size);\r
+\r
+    creds_union->credentials.credentials_v4 = creds;\r
+\r
+    return ccNoError;\r
+}\r
+\r
+\r
+cc_int32\r
+cci_creds_cc_data_array_count_entries( cc_data ** array, cc_uint32 * pcount)\r
+{\r
+    cc_uint32 count;\r
+\r
+    if (array == NULL) {\r
+        *pcount = 0;\r
+        return ccNoError;\r
+    }\r
+\r
+    for ( count=0; array[count] != NULL ; count++) ;\r
+\r
+    *pcount = count;\r
+    return ccNoError;\r
+}\r
+\r
+cc_int32\r
+cci_creds_v5_compute_flat_size( cc_credentials_v5_t * creds, cc_uint32 * plen)\r
+{\r
+    cc_uint32 len;\r
+    cc_uint32 i, count;\r
+\r
+    len = sizeof(struct cci_flat_creds_v5);\r
+\r
+    if (creds->client)\r
+        len += strlen(creds->client) + 1;\r
+\r
+    if (creds->server)\r
+        len += strlen(creds->server) + 1;\r
+\r
+    len += creds->keyblock.length;\r
+\r
+    cci_creds_cc_data_array_count_entries( creds->addresses, &count );\r
+    len += count * sizeof(cc_flat_data);\r
+    for ( i=0; i<count; i++ ) {\r
+        len += creds->addresses[i]->length;\r
+    }\r
+\r
+    len += creds->ticket.length;\r
+    len += creds->second_ticket.length;\r
+\r
+    cci_creds_cc_data_array_count_entries( creds->authdata, &count );\r
+    len += count * sizeof(cc_flat_data);\r
+    for ( i=0; i<count; i++ ) {\r
+        len += creds->authdata[i]->length;\r
+    }\r
+\r
+    *plen = len;\r
+    return ccNoError;\r
+}\r
+\r
+cc_int32\r
+cci_creds_v5_marshall( cc_credentials_v5_t * creds, \r
+                       char ** pflat, \r
+                       cc_uint32 * plen)\r
+{\r
+    cc_uint32 len;\r
+    char * flat;\r
+    struct cci_flat_creds_v5 * header;\r
+    cc_uint32 length;\r
+    cc_uint32 offset;\r
+    cc_time64 t64;\r
+    cc_uint32 count;\r
+    cc_uint32 i;\r
+\r
+    if ( creds == NULL || pflat == NULL || plen == NULL )\r
+        return ccErrBadParam;\r
+\r
+    cci_creds_v5_compute_flat_size(creds, &len);\r
+\r
+    flat = (char *)malloc(len);\r
+    if ( flat == NULL )\r
+        return ccErrNoMem;\r
+    memset(flat, 0, len);\r
+\r
+    offset = sizeof(struct cci_flat_creds_v5);\r
+    header = (struct cci_flat_creds_v5 *)flat;\r
+    header->version = htonl(FLAT_CREDS_V5_VERSION);\r
+    if (creds->client) {\r
+       length = strlen(creds->client) + 1;\r
+        header->client.length = htonl(length);\r
+        header->client.data = htonl(offset);\r
+        memcpy(flat + offset, creds->client, length);\r
+        offset += length;\r
+    }\r
+\r
+    if (creds->server) {\r
+       length = strlen(creds->server) + 1;\r
+        header->server.length = htonl(length);\r
+        header->server.data = htonl(offset);\r
+        memcpy(flat + offset, creds->server, length);\r
+        offset += length;\r
+    }\r
+\r
+    header->keyblock.type = htonl(creds->keyblock.type);\r
+    if (creds->keyblock.length) {\r
+       length = creds->keyblock.length;\r
+        header->keyblock.length = htonl(length);\r
+        header->keyblock.data = htonl(offset);\r
+        memcpy(flat + offset, creds->keyblock.data, length);\r
+        offset += length;\r
+    }           \r
+\r
+    t64 = creds->authtime;\r
+    header->authtime = htonll(t64);\r
+    t64 = creds->starttime;\r
+    header->starttime = htonll(t64);\r
+    t64 = creds->endtime;\r
+    header->endtime = htonll(t64);\r
+    t64 = creds->renew_till;\r
+    header->renew_till = htonll(t64);\r
+\r
+    header->is_skey = htonl(creds->is_skey);\r
+    header->ticket_flags = htonl(creds->ticket_flags);\r
+\r
+    cci_creds_cc_data_array_count_entries( creds->addresses, &count );\r
+    if ( count ) {\r
+        cc_flat_data * addresses = (cc_flat_data *)flat + offset;\r
+       header->address_count = htonl(count);\r
+        header->addresses = htonl(offset);\r
+        offset += count * sizeof(cc_flat_data);\r
+\r
+        for ( i=0; i < count; i++ ) {\r
+            addresses[i].type = htonl(creds->addresses[i]->type);\r
+            if (creds->addresses[i]->length) {\r
+               length = creds->addresses[i]->length;\r
+                addresses[i].length = htonl(length);\r
+                addresses[i].data = htonl(offset);\r
+               /* TODO: verify that addresses are stored in network order */\r
+                memcpy(flat + offset, creds->addresses[i]->data, length);\r
+                offset += length;\r
+            }\r
+        }\r
+    }\r
+\r
+    header->ticket.type = htonl(creds->ticket.type);\r
+    if (creds->ticket.length) {\r
+       length = creds->ticket.length;\r
+        header->ticket.length = htonl(length);\r
+        header->ticket.data = htonl(offset);\r
+        memcpy(flat + offset, creds->ticket.data, length);\r
+        offset += length;\r
+    }           \r
+\r
+    header->second_ticket.type = htonl(creds->second_ticket.type);\r
+    if (creds->second_ticket.length) {\r
+       length = creds->second_ticket.length;\r
+        header->second_ticket.length = htonl(length);\r
+        header->second_ticket.data = htonl(offset);\r
+        memcpy(flat + offset, creds->second_ticket.data, length);\r
+        offset += length;\r
+    }           \r
+\r
+    cci_creds_cc_data_array_count_entries( creds->authdata, &count );\r
+    if ( count ) {\r
+        cc_flat_data * authdata = (cc_flat_data *)flat + offset;\r
+\r
+       header->authdata_count = htonl(count);\r
+        header->authdata = (offset);\r
+        offset += count * sizeof(cc_flat_data);\r
+\r
+        for ( i=0; i < count; i++ ) {\r
+            authdata[i].type = htonl(creds->authdata[i]->type);\r
+            if (creds->authdata[i]->length) {\r
+               length = creds->authdata[i]->length;\r
+                authdata[i].length = htonl(length);\r
+                authdata[i].data = htonl(offset);\r
+                memcpy(flat + offset, creds->authdata[i]->data, length);\r
+                offset += length;\r
+            }\r
+        }\r
+    }\r
+\r
+    *pflat = flat;\r
+    *plen = len;\r
+    return ccNoError;\r
+}\r
+\r
+\r
+// TODO: a much better job of checking for out of memory errors\r
+//       and validating that we do not read beyond the flat input\r
+//       data buffer\r
+\r
+cc_int32\r
+cci_creds_v5_unmarshall( char * flat, \r
+                         cc_uint32 len,\r
+                         cc_credentials_union * creds_union)\r
+{\r
+    struct cci_flat_creds_v5 * header;\r
+    cc_credentials_v5_t * creds;\r
+    cc_flat_data * flat_data;\r
+    cc_time64 t64;\r
+    cc_uint32  length;\r
+    cc_uint32  count;\r
+    cc_uint32  i;\r
+    cc_int32   code;\r
+\r
+    if ( flat == NULL || len == 0 || creds_union == NULL )\r
+        return ccErrBadParam;\r
+\r
+    creds_union->version = cc_credentials_v5;\r
+\r
+    header = (struct cci_flat_creds_v5 *)flat;\r
+\r
+    if ( ntohl(header->version) != FLAT_CREDS_V5_VERSION )\r
+        return ccErrBadParam;\r
+\r
+    creds = (cc_credentials_v5_t *)malloc(sizeof(cc_credentials_v5_t));\r
+    if ( creds == NULL )\r
+        return ccErrNoMem;\r
+    memset(creds, 0, sizeof(cc_credentials_v5_t));\r
+\r
+    if ( header->client.length ) {\r
+       length = ntohl(header->client.length);\r
+        creds->client = (char *)malloc(length);\r
+        memcpy(creds->client, flat + header->client.data, length);\r
+    }\r
+\r
+    if ( header->server.length ) {\r
+       length = ntohl(header->server.length);\r
+        creds->server = (char *)malloc(length);\r
+        memcpy(creds->server, flat + header->server.data, length);\r
+    }\r
+\r
+    creds->keyblock.type = ntohl(header->keyblock.type);\r
+    if ( header->keyblock.length ) {\r
+       length = ntohl(header->keyblock.length);\r
+        creds->keyblock.length = length;\r
+        creds->keyblock.data = malloc(length);\r
+        memcpy(creds->keyblock.data, flat + header->keyblock.data, length);\r
+    }\r
+\r
+    /* TODO: need to perform overflow validation checks to ensure\r
+     * that we do not attempt to store too large a value into cc_time_t\r
+     * when it is a 32-bit field.\r
+     */\r
+    t64 = ntohll(header->authtime);\r
+    creds->authtime = (cc_time)t64;\r
+    t64 = ntohll(header->starttime);\r
+    creds->starttime = (cc_time)t64;\r
+    t64 = ntohll(header->endtime);\r
+    creds->endtime = (cc_time)t64;\r
+    t64 = ntohll(header->renew_till);\r
+    creds->renew_till = (cc_time)t64;\r
+\r
+    creds->is_skey = ntohl(header->is_skey);\r
+    creds->ticket_flags = ntohl(header->ticket_flags);\r
+\r
+    count = ntohl(header->address_count);\r
+    creds->addresses = (cc_data **) malloc((count + 1) * sizeof(cc_data *));\r
+    flat_data = (cc_flat_data *)flat + header->addresses;\r
+    for ( i=0 ; i < count ; i++ ) {\r
+        creds->addresses[i] = (cc_data *)malloc(sizeof(cc_data));\r
+        creds->addresses[i]->type = ntohl(flat_data[i].type);\r
+       length = ntohl(flat_data[i].length);\r
+        creds->addresses[i]->length = length;\r
+        if ( length ) {\r
+            creds->addresses[i]->data = malloc(length);\r
+           /* TODO: verify that addresses are stored in network order */\r
+            memcpy(creds->addresses[i]->data, flat + flat_data[i].data, length);\r
+        } else {\r
+            creds->addresses[i]->data = NULL;\r
+        }\r
+    }\r
+    creds->addresses[i] = NULL;\r
+\r
+    creds->ticket.type = ntohl(header->ticket.type);\r
+    length = ntohl(header->ticket.length);\r
+    if ( length ) {\r
+        creds->ticket.length = length;\r
+        creds->ticket.data = malloc(length);\r
+        memcpy(creds->ticket.data, flat + header->ticket.data, length);\r
+    }\r
+\r
+    creds->second_ticket.type = header->second_ticket.type;\r
+    if ( header->second_ticket.length ) {\r
+        creds->second_ticket.length = header->second_ticket.length;\r
+        creds->second_ticket.data = malloc(creds->second_ticket.length);\r
+        memcpy(creds->second_ticket.data, flat + header->second_ticket.data, creds->second_ticket.length);\r
+    }\r
+\r
+    count = ntohl(header->authdata_count);\r
+    creds->authdata = (cc_data **) malloc((count + 1) * sizeof(cc_data *));\r
+    flat_data = (cc_flat_data *)flat + header->authdata;\r
+    for ( i=0 ; i < count ; i++ ) {\r
+        creds->authdata[i] = (cc_data *)malloc(sizeof(cc_data));\r
+        creds->authdata[i]->type = ntohl(flat_data[i].type);\r
+       length = ntohl(flat_data[i].length);\r
+        creds->authdata[i]->length = length;\r
+        if ( length ) {\r
+            creds->authdata[i]->data = malloc(length);\r
+            memcpy(creds->authdata[i]->data, flat + flat_data[i].data, length);\r
+        } else {\r
+            creds->authdata[i]->data = NULL;\r
+        }\r
+    }\r
+    creds->authdata[i] = NULL;\r
+\r
+    creds_union->credentials.credentials_v5 = creds;\r
+\r
+    return ccNoError;\r
+}\r
+\r
similarity index 79%
rename from src/lib/ccapi/msg.c
rename to src/lib/ccapi/client/msg.c
index f5f074aa04beef93a879cdb92b34b322c7572b5e..facaffffccf91dd0a83702367e4d9eeb930b35de 100644 (file)
-/* $Copyright:
- *
- * Copyright 2004 by the Massachusetts Institute of Technology.
- * 
- * All rights reserved.
- * 
- * Export of this software from the United States of America may require a
- * specific license from the United States Government.  It is the
- * responsibility of any person or organization contemplating export to
- * obtain such a license before exporting.
- * 
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute
- * this software and its documentation for any purpose and without fee is
- * hereby granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission notice
- * appear in supporting documentation, and that the name of M.I.T. not be
- * used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.  Furthermore if you
- * modify this software you must label your software as modified software
- * and not distribute it in such a fashion that it might be confused with
- * the original MIT software. M.I.T. makes no representations about the
- * suitability of this software for any purpose.  It is provided "as is"
- * without express or implied warranty.
- * 
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- * 
- * Individual source code files are copyright MIT, Cygnus Support,
- * OpenVision, Oracle, Sun Soft, FundsXpress, and others.
- * 
- * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,
- * and Zephyr are trademarks of the Massachusetts Institute of Technology
- * (MIT).  No commercial use of these trademarks may be made without prior
- * written permission of MIT.
- * 
- * "Commercial use" means use of a name in a product or other for-profit
- * manner.  It does NOT prevent a commercial firm from referring to the MIT
- * trademarks in order to convey information (although in doing so,
- * recognition of their trademark status should be given).
- * $
- */
-
-/*
- * Verifiable, extensible message format.
- */
-
-#include "CredentialsCache.h"
-#include "msg.h"
-#include "datastore.h"
-
-#include <stdlib.h>
-#include <memory.h>
-#include <stdio.h>
-#include <string.h>
-
-/**
- * cci_msg_new()
- *
- * Purpose: Allocate and initialize a new cc_msg_t structure
- *
- * Return:  non-NULL, the msg
- *          NULL, failure
- *
- * Errors:  ccErrNoMem
- *
- */
-cc_int32
-cci_msg_new(cc_uint32 type, cc_msg_t** msgpp) 
-{
-    // type should be validated.  If invalid set error to ccErrBadParam
-    cc_msg_t* msg;
-    
-    if ( type > CC_MSG_MAX_TYPE || msgpp == NULL )
-        return ccErrBadParam;
-
-    msg = (cc_msg_t*)malloc(sizeof(cc_msg_t));
-    if (msg == NULL)
-        return ccErrNoMem;
-
-    msg->type = type;
-    msg->flat = NULL;
-    msg->header = NULL;
-    msg->flat_len = 0;
-    msg->header_len = 0;
-    msg->magic = 0;
-    cci_generic_list_new(&msg->data_blobs);
-    if (msg->data_blobs == NULL) {
-        // pass on error from previous call
-        free(msg);
-        return ccErrNoMem;
-    }
-
-    *msgpp = msg;     
-    return ccNoError;
-}
-
-/**
- * cci_msg_calc_header_size()
- *
- * Purpose: Calculates the size of the header
- *
- * Return:  the size in bytes
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32
-cci_msg_calc_header_size(cc_msg_t* msg, cc_uint32 * lenp) 
-{
-    int header_len = 12; /* header size, entire size, type */
-
-    if ( msg == NULL || lenp == NULL )
-        return ccErrBadParam;
-
-    header_len += msg->header_len;
-    *lenp = header_len;
-    return ccNoError;
-}
-
-/**
- * cci_msg_calc_size()
- *
- * Purpose: Calculates the size of the message
- *          (does not include the magic bytes)
- *
- * Return:  the size in bytes
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32 
-cci_msg_calc_size(cc_msg_t* msg, cc_uint32 * lenp) 
-{
-    cc_uint32 flat_len;
-    cc_generic_list_node_t* gen_node;
-    cc_generic_iterate_t* gen_iterator;
-       cc_int32 code;
-
-    if ( msg == NULL || lenp == NULL ) 
-        return ccErrBadParam;
-
-    code = cci_msg_calc_header_size(msg, &flat_len);
-    if (code != ccNoError)
-        goto bad;
-
-    code = cci_generic_list_iterator(msg->data_blobs, &gen_iterator);
-    if ( code != ccNoError )
-        goto bad;
-
-    while (cci_generic_iterate_has_next(gen_iterator)) {
-        code = cci_generic_iterate_next(gen_iterator, &gen_node);
-        if (code != ccNoError)
-            break;
-        flat_len += gen_node->len + BLOB_LEN;
-    }
-    cci_generic_free_iterator(gen_iterator);
-    if (code != ccNoError)
-        goto bad;
-
-    flat_len += MAGIC_HEAD_LEN + MAGIC_DATA_LEN;
-    *lenp = flat_len;
-
-  bad:
-    return code;
-}
-
-/**
- * cci_msg_add_data_blob()
- *
- * Purpose: Adds 'len' bytes of data to the msg
- *
- * Return: 
- *
- * Errors: 
- *
- */
-cc_int32 
-cci_msg_add_data_blob(cc_msg_t* msg, void *data, cc_uint32 len, cc_uint32 *lenp) 
-{
-    cc_int32 code;
-
-    if (msg == NULL || data == NULL || len <= 0 || lenp == NULL)
-        return ccErrBadParam;
-
-    code = cci_generic_list_append(msg->data_blobs, data, len, NULL);
-    if ( code != ccNoError )
-        return code;
-    return cci_msg_calc_blob_pos(msg, data, len, lenp);
-}
-
-/**
- * cc_msg_
- *
- * Purpose:
- *
- * Return: 
- *
- * Errors: 
- *
- */
-cc_int32 
-cci_msg_calc_blob_pos(cc_msg_t* msg, void *data, cc_uint32 len, cc_uint32 * posp) 
-{
-    cc_uint32 pos;
-    cc_generic_list_node_t* gen_node;
-    cc_generic_iterate_t* gen_iterator;
-    cc_int32 code;
-
-    code = cci_msg_calc_header_size(msg, &pos);
-    pos += sizeof(cc_uint32); /*+ sizeof(cc_uint32) for magic*/
-
-    code = cci_generic_list_iterator(msg->data_blobs, &gen_iterator);
-    while (cci_generic_iterate_has_next(gen_iterator)) {
-        code = cci_generic_iterate_next(gen_iterator, &gen_node);
-        if (gen_node->len != len && gen_node->data != data) {
-            pos += gen_node->len + sizeof(cc_uint32);
-        } else {
-            cci_generic_free_iterator(gen_iterator);
-            *posp = pos + sizeof(cc_uint32);
-            return ccNoError;
-        }
-    }
-    
-    cci_generic_free_iterator(gen_iterator);
-    return ccIteratorEnd;
-}
-
-/**
- * cc_msg_
- *
- * Purpose:
- *
- * Return: 
- *
- * Errors: 
- *
- */
-cc_int32 
-cci_msg_add_header(cc_msg_t* msg, void *header, cc_uint32 header_len) 
-{
-    if ( msg == NULL || header == NULL )
-        return ccErrBadParam;
-
-    msg->header = header;
-    msg->header_len = header_len;
-    return ccNoError;
-}
-
-
-/**
- * cc_msg_
- *
- * Purpose:
- *
- * Return: 
- *
- * Errors: 
- *
- */
-cc_int32
-cci_msg_flatten(cc_msg_t* msg, void **flatpp) 
-{
-    cc_generic_list_node_t* gen_node;
-    cc_generic_iterate_t* gen_iterator;
-    char *cur_pos;
-    cc_uint32 zero = 0;
-    cc_uint32 magic = 0;
-    cc_uint32 msg_len;
-    cc_int32 code;
-
-    if (msg == NULL || flatpp == NULL)
-        return ccErrBadParam;
-
-    code = cci_msg_calc_size(msg,&msg->flat_len);
-    if ( code != ccNoError )
-        return code;
-
-    if (msg->flat_len > CC_MSG_MAX_SIZE)
-        return ccErrBadParam;
-
-    msg->flat = (void *)malloc(msg->flat_len);
-    if (msg->flat == NULL)
-        return ccErrNoMem;
-    
-    cur_pos = msg->flat;
-
-    memcpy(cur_pos,&msg->header_len,sizeof(cc_uint32));
-    cur_pos+=sizeof(cc_uint32);
-
-    memcpy(cur_pos,&msg->flat_len,sizeof(cc_uint32));
-    cur_pos+=sizeof(cc_uint32);
-
-    memcpy(cur_pos,&msg->type,sizeof(cc_uint32));
-    cur_pos+=sizeof(cc_uint32);
-
-    memcpy(cur_pos, msg->header, msg->header_len);
-    cur_pos += msg->header_len;
-
-    memcpy(cur_pos, &zero, sizeof(cc_uint32)); /*will be magic number later*/
-    cur_pos += sizeof(cc_uint32);
-
-    code = cci_generic_list_iterator(msg->data_blobs,&gen_iterator);
-    if ( code != ccNoError ) {
-        free(msg->flat);
-        return code;
-    }
-
-    while (cci_generic_iterate_has_next(gen_iterator)) {
-        code = cci_generic_iterate_next(gen_iterator, &gen_node);
-        if (code != ccNoError) {
-            free(gen_iterator);
-            free(msg->flat);
-            return code;
-        }
-        memcpy(cur_pos, &gen_node->len, sizeof(cc_uint32));
-        cur_pos+=sizeof(cc_uint32);
-               
-        memcpy(cur_pos, gen_node->data, gen_node->len);
-        cur_pos += gen_node->len;
-    }
-    free(gen_iterator);
-
-    memcpy(cur_pos, &zero, sizeof(cc_uint32)); /*magic number will go here later*/
-    cur_pos += sizeof(cc_uint32);
-
-    if (cur_pos - (char *)msg->flat != msg->flat_len) {
-        printf("ERRORR cur_pos - msg->flat = %d\n",msg->flat_len);
-    }
-
-    cci_msg_calc_magic(msg->flat, msg->flat_len, &magic);
-    printf("magic = %d\n",magic);
-       
-    cci_msg_calc_header_size(msg, &msg_len);
-    memcpy((char *)msg->flat + msg_len, &magic, sizeof(cc_uint32));
-    memcpy((char *)msg->flat + msg->flat_len - sizeof(cc_uint32), &magic, sizeof(cc_uint32));
-
-    if ( flatpp != NULL )
-        *flatpp = msg->flat;
-    return ccNoError;
-}
-
-/**
- * cc_msg_
- *
- * Purpose:
- *
- * Return: 
- *
- * Errors: 
- *
- */
-cc_int32
-cci_msg_calc_magic(void *flat, int flat_len, cc_uint32 * magicp)
-{
-    cc_uint32 magic = 0;
-    int i;
-       
-    for (i = 0; i < flat_len; i += sizeof(cc_uint32)) {
-        magic = magic ^ *(int *)((char *)flat + i);
-    }
-    *magicp = magic;
-    return ccNoError;
-}
-
-/**
- * cc_msg_
- *
- * Purpose:
- *
- * Return: 
- *
- * Errors: 
- *
- */
-cc_int32 
-cci_msg_verify(void *flat, int flat_len, cc_uint32 * validp)  
-{
-    cc_uint32 *magic1, *magic2;
-    cc_uint32 *pheader_len;
-    cc_uint32 *ptotal_len;
-    cc_uint32 *pblob_len;
-    cc_uint32 *ptype;
-    cc_uint32 num_blobs = 0;
-    cc_uint32 zero = 0;
-    cc_uint32 msg_magic, msg_magic2;
-
-    if (flat == NULL || flat_len <= 0 || validp == NULL)
-        return ccErrBadParam;
-
-    pheader_len = flat;
-    ptotal_len = (cc_uint32 *)((char *)pheader_len + sizeof(cc_uint32));
-    ptype = (cc_uint32 *)((char *)ptotal_len + sizeof(cc_uint32));
-
-    if (*ptotal_len != flat_len) {
-        *validp = 0;
-        return ccNoError;
-    }
-    
-    if (*pheader_len > flat_len) {
-        /*too weak. We could verify header_len against type spec header.*/
-        *validp = 0;
-        return ccNoError;
-    }
-    if (*ptype > CC_MSG_MAX_TYPE) {
-        *validp = 0;
-        return ccNoError;
-    }
-
-    magic1 = (cc_uint32 *)((char *)ptype + sizeof(cc_uint32) + *pheader_len); 
-    if ((char *)magic1 - (char *)flat == (flat_len - 8)) {
-        /*There are no data blobs*/
-        magic2 = (cc_uint32 *)((char *)magic1 + sizeof(cc_uint32));
-        num_blobs = 0;
-    } else {
-        pblob_len = (cc_uint32 *)((char *)magic1 + sizeof(cc_uint32));
-        num_blobs = 1;
-
-        while (*pblob_len + sizeof(cc_uint32) + ((char *)pblob_len - (char *)flat) < (flat_len - sizeof(cc_uint32))) {
-            pblob_len = (cc_uint32 *)((char *)pblob_len + *pblob_len + sizeof(cc_uint32));
-            num_blobs++;
-        }
-
-        if (*pblob_len + sizeof(cc_uint32) + ((char *)pblob_len - (char *)flat) != (flat_len - sizeof(cc_uint32))) {
-            /*blobs didn't line up*/
-            *validp = 0;
-            return ccNoError;
-        }
-        magic2 = (cc_uint32 *)((char *)pblob_len + *pblob_len + sizeof(cc_uint32)); /*2nd magic should be directly after the last blob*/
-    }
-       
-    if (*magic1 != *magic2) {
-        *validp = 0;
-        return ccNoError;
-    }
-    msg_magic = *magic1;
-
-    printf("%d %d\n", (char *)magic1 - (char *)flat, (char *)magic2 - (char *)flat);
-
-    memcpy(magic1, &zero, sizeof(cc_uint32));
-    memcpy(magic2, &zero, sizeof(cc_uint32));
-    cci_msg_calc_magic(flat, flat_len, &msg_magic2);
-    if (msg_magic != msg_magic2) {
-        *validp = 0;
-        return ccNoError;
-    }
-    memcpy(magic1, &msg_magic, sizeof(cc_uint32));
-    memcpy(magic2, &msg_magic, sizeof(cc_uint32));
-
-    *validp = 1;
-    return ccNoError;
-}
-
-/**
- * cc_msg_
- *
- * Purpose:
- *
- * Return: 
- *
- * Errors: 
- *
- */
-cc_int32
-cci_msg_unflatten(void *flat, int flat_len, cc_msg_t** msgpp) 
-{
-    cc_msg_t* msg;
-    char *cur_pos;
-    cc_uint32 blob_len;
-    char *blob;
-    cc_uint32 valid;
-    cc_int32 code;
-
-    if ( flat == NULL || flat_len <= 0 || msgpp == NULL )
-        return ccErrBadParam;
-
-    code = cci_msg_new(0, &msg);
-    if (code)
-        return code;
-
-    cci_msg_verify(flat, flat_len, &valid);
-    if (valid != 1) {
-        cci_msg_destroy(msg);
-        return ccErrBadParam;
-    }
-
-    cur_pos = flat;
-    msg->flat = flat;
-
-    msg->header_len = *(cc_uint32 *)cur_pos;
-    cur_pos += sizeof(cc_uint32);
-
-    msg->flat_len = *(cc_uint32 *)cur_pos;
-    cur_pos += sizeof(cc_uint32);
-
-    msg->type = *(cc_uint32 *)cur_pos;
-    cur_pos += sizeof(cc_uint32);
-
-    msg->header = (void *)malloc(msg->header_len);
-    if (msg->header == NULL) {
-        cci_msg_destroy(msg);
-        return ccErrNoMem;
-    }
-    memcpy(msg->header, cur_pos, msg->header_len);
-    cur_pos += msg->header_len;
-       
-    msg->magic = *(cc_uint32 *)cur_pos;
-    cur_pos += sizeof(cc_uint32);
-
-    if (cur_pos - (char *)flat != flat_len - 8) { /*at least 1 blob*/
-        blob_len = *(cc_uint32 *)cur_pos;
-        while (blob_len + (cur_pos - (char *)flat) + sizeof(cc_uint32) <= flat_len - sizeof(cc_uint32)) {
-            blob = (void *)malloc(blob_len);
-            if (blob == NULL) {
-                cci_msg_destroy(msg);
-                return ccErrNoMem;
-            }
-            memcpy(blob, cur_pos + sizeof(cc_uint32), blob_len);
-            cci_generic_list_append(msg->data_blobs, blob, blob_len, NULL);
-
-            cur_pos += sizeof(cc_uint32) + blob_len;
-            blob_len = *(int *)cur_pos;
-        }
-    }
-    *msgpp = msg;
-    return ccNoError;
-}
-
-cc_int32
-cci_msg_retrieve_blob(cc_msg_t* msg, cc_uint32 blob_offset, cc_uint32 blob_len, void **blobp) 
-{
-    cc_generic_iterate_t*      gen_iterator;
-    cc_generic_list_node_t*    gen_node;
-    void *ret;
-    cc_uint32                   blob_pos;
-    cc_int32                    code;
-
-    /*Ensure that the message has been unflattened*/
-    if ( msg == NULL || msg->flat == NULL || blob_offset > msg->flat_len || 
-         blob_len > msg->flat_len - blob_offset || blobp == NULL)
-        return ccErrBadParam;
-
-    code = cci_generic_list_iterator(msg->data_blobs, &gen_iterator);
-    while (cci_generic_iterate_has_next(gen_iterator)) {
-        code = cci_generic_iterate_next(gen_iterator, &gen_node);
-        code = cci_msg_calc_blob_pos(msg, gen_node->data, gen_node->len, &blob_pos);
-        if (blob_pos == blob_offset && gen_node->len == blob_len)  {
-            free(gen_iterator);
-            ret = (void *)malloc(blob_len);
-            if (ret == NULL)
-                return ccErrNoMem;
-            memcpy(ret,(char *)msg->flat + blob_offset, blob_len);     
-            *blobp = ret;
-            return ccNoError;
-        }
-    }
-    free(gen_iterator);
-    return ccIteratorEnd;
-}
-
-/**
- * cc_msg_
- *
- * Purpose:
- *
- * Return: 
- *
- * Errors: 
- *
- */
-cc_int32 
-cci_msg_destroy(cc_msg_t* msg) 
-{
-    if (msg->flat != NULL) 
-        free(msg->flat);
-    if (msg->header != NULL)
-        free(msg->flat);
-    cci_generic_list_destroy(msg->data_blobs);
-    free(msg);
-    return ccNoError;
-}
-
+/* $Copyright:\r
+ *\r
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.\r
+ * \r
+ * All rights reserved.\r
+ * \r
+ * Export of this software from the United States of America may require a\r
+ * specific license from the United States Government.  It is the\r
+ * responsibility of any person or organization contemplating export to\r
+ * obtain such a license before exporting.\r
+ * \r
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute\r
+ * this software and its documentation for any purpose and without fee is\r
+ * hereby granted, provided that the above copyright notice appear in all\r
+ * copies and that both that copyright notice and this permission notice\r
+ * appear in supporting documentation, and that the name of M.I.T. not be\r
+ * used in advertising or publicity pertaining to distribution of the\r
+ * software without specific, written prior permission.  Furthermore if you\r
+ * modify this software you must label your software as modified software\r
+ * and not distribute it in such a fashion that it might be confused with\r
+ * the original MIT software. M.I.T. makes no representations about the\r
+ * suitability of this software for any purpose.  It is provided "as is"\r
+ * without express or implied warranty.\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\r
+ * \r
+ * Individual source code files are copyright MIT, Cygnus Support,\r
+ * OpenVision, Oracle, Sun Soft, FundsXpress, and others.\r
+ * \r
+ * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,\r
+ * and Zephyr are trademarks of the Massachusetts Institute of Technology\r
+ * (MIT).  No commercial use of these trademarks may be made without prior\r
+ * written permission of MIT.\r
+ * \r
+ * "Commercial use" means use of a name in a product or other for-profit\r
+ * manner.  It does NOT prevent a commercial firm from referring to the MIT\r
+ * trademarks in order to convey information (although in doing so,\r
+ * recognition of their trademark status should be given).\r
+ * $\r
+ */\r
+\r
+/*\r
+ * Verifiable, extensible message format.\r
+ *\r
+ * Format:\r
+ * <size of header block (header_len)>\r
+ * <size of *entire* message, including previous field (flat_len)>\r
+ * <message type (type)>\r
+ * <type specific header (header)>\r
+ * <magic number (magic)>\r
+ * <data blob 1 length>\r
+ * <data blob 1>\r
+ * <data blob 2 length>\r
+ * <data blob 2>\r
+ * ...\r
+ * <magic number (magic)>\r
+ *\r
+ * If the header has variable length data it is included in the data blobs. \r
+ * The header field has the offset from the beginning of the message of the 1st \r
+ * byte of the data and the length of the data.\r
+ */\r
+\r
+#include "CredentialsCache.h"\r
+#include "msg.h"\r
+#include "generic_lists.h"\r
+\r
+#include <stdlib.h>\r
+#include <memory.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+/**\r
+ * cci_msg_new()\r
+ *\r
+ * Purpose: Allocate and initialize a new cc_msg_t structure\r
+ *\r
+ * Input parameter (type) in host order\r
+ *\r
+ * Return:  non-NULL, the msg\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem\r
+ *\r
+ */\r
+cc_int32\r
+cci_msg_new(cc_uint32 type, cc_msg_t** msgpp) \r
+{\r
+    // type should be validated.  If invalid set error to ccErrBadParam\r
+    cc_msg_t* msg;\r
+    \r
+    if ( type > CC_MSG_MAX_TYPE || msgpp == NULL )\r
+        return ccErrBadParam;\r
+\r
+    msg = (cc_msg_t*)malloc(sizeof(cc_msg_t));\r
+    if (msg == NULL)\r
+        return ccErrNoMem;\r
+\r
+    msg->type = htonl(type);\r
+    msg->flat = NULL;\r
+    msg->header = NULL;\r
+    msg->flat_len = 0;\r
+    msg->header_len = 0;\r
+    msg->magic = 0;\r
+    cci_generic_list_new(&msg->data_blobs);\r
+    if (msg->data_blobs == NULL) {\r
+        // pass on error from previous call\r
+        free(msg);\r
+        return ccErrNoMem;\r
+    }\r
+\r
+    *msgpp = msg;     \r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * cci_msg_calc_header_size()\r
+ *\r
+ * Purpose: Calculates the size of the header\r
+ *\r
+ * Return:  the size in bytes\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+cci_msg_calc_header_size(cc_msg_t* msg, cc_uint32 * lenp) \r
+{\r
+    int header_len = 12; /* header size, entire size, type */\r
+\r
+    if ( msg == NULL || lenp == NULL )\r
+        return ccErrBadParam;\r
+\r
+    header_len += msg->header_len;\r
+    *lenp = header_len;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * cci_msg_calc_size()\r
+ *\r
+ * Purpose: Calculates the size of the message\r
+ *          (does not include the magic bytes)\r
+ *\r
+ * Return:  the size in bytes\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32 \r
+cci_msg_calc_size(cc_msg_t* msg, cc_uint32 * lenp) \r
+{\r
+    cc_uint32 flat_len;\r
+    cc_generic_list_node_t* gen_node;\r
+    cc_generic_iterate_t* gen_iterator;\r
+       cc_int32 code;\r
+\r
+    if ( msg == NULL || lenp == NULL ) \r
+        return ccErrBadParam;\r
+\r
+    code = cci_msg_calc_header_size(msg, &flat_len);\r
+    if (code != ccNoError)\r
+        goto bad;\r
+\r
+    code = cci_generic_list_iterator(msg->data_blobs, &gen_iterator);\r
+    if ( code != ccNoError )\r
+        goto bad;\r
+\r
+    while (cci_generic_iterate_has_next(gen_iterator)) {\r
+        code = cci_generic_iterate_next(gen_iterator, &gen_node);\r
+        if (code != ccNoError)\r
+            break;\r
+        flat_len += gen_node->len + BLOB_LEN;\r
+    }\r
+    cci_generic_free_iterator(gen_iterator);\r
+    if (code != ccNoError)\r
+        goto bad;\r
+\r
+    flat_len += MAGIC_HEAD_LEN + MAGIC_DATA_LEN;\r
+    *lenp = flat_len;\r
+\r
+  bad:\r
+    return code;\r
+}\r
+\r
+/**\r
+ * cci_msg_add_data_blob()\r
+ *\r
+ * Purpose: Adds 'len' bytes of data to the msg\r
+ *\r
+ * Return: \r
+ *\r
+ * Errors: \r
+ *\r
+ */\r
+cc_int32 \r
+cci_msg_add_data_blob(cc_msg_t* msg, void *data, cc_uint32 len, cc_uint32 *lenp) \r
+{\r
+    cc_int32 code;\r
+\r
+    if (msg == NULL || data == NULL || len <= 0 || lenp == NULL)\r
+        return ccErrBadParam;\r
+\r
+    code = cci_generic_list_append(msg->data_blobs, data, len, NULL);\r
+    if ( code != ccNoError )\r
+        return code;\r
+    return cci_msg_calc_blob_pos(msg, data, len, lenp);\r
+}\r
+\r
+/**\r
+ * cc_msg_\r
+ *\r
+ * Purpose:\r
+ *\r
+ * Return: \r
+ *\r
+ * Errors: \r
+ *\r
+ */\r
+cc_int32 \r
+cci_msg_calc_blob_pos(cc_msg_t* msg, void *data, cc_uint32 len, cc_uint32 * posp) \r
+{\r
+    cc_uint32 pos;\r
+    cc_generic_list_node_t* gen_node;\r
+    cc_generic_iterate_t* gen_iterator;\r
+    cc_int32 code;\r
+\r
+    code = cci_msg_calc_header_size(msg, &pos);\r
+    pos += sizeof(cc_uint32); /*+ sizeof(cc_uint32) for magic*/\r
+\r
+    code = cci_generic_list_iterator(msg->data_blobs, &gen_iterator);\r
+    while (cci_generic_iterate_has_next(gen_iterator)) {\r
+        code = cci_generic_iterate_next(gen_iterator, &gen_node);\r
+        if (gen_node->len != len && gen_node->data != data) {\r
+            pos += gen_node->len + sizeof(cc_uint32);\r
+        } else {\r
+            cci_generic_free_iterator(gen_iterator);\r
+            *posp = pos + sizeof(cc_uint32);\r
+            return ccNoError;\r
+        }\r
+    }\r
+    \r
+    cci_generic_free_iterator(gen_iterator);\r
+    return ccIteratorEnd;\r
+}\r
+\r
+/**\r
+ * cc_msg_\r
+ *\r
+ * Purpose:\r
+ *\r
+ * Return: \r
+ *\r
+ * Errors: \r
+ *\r
+ */\r
+cc_int32 \r
+cci_msg_add_header(cc_msg_t* msg, void *header, cc_uint32 header_len) \r
+{\r
+    if ( msg == NULL || header == NULL )\r
+        return ccErrBadParam;\r
+\r
+    msg->header = header;\r
+    msg->header_len = header_len;\r
+    return ccNoError;\r
+}\r
+\r
+\r
+/**\r
+ * cc_msg_\r
+ *\r
+ * Purpose:\r
+ *\r
+ * Return: \r
+ *\r
+ * Errors: \r
+ *\r
+ */\r
+cc_int32\r
+cci_msg_flatten(cc_msg_t* msg, void **flatpp) \r
+{\r
+    cc_generic_list_node_t* gen_node;\r
+    cc_generic_iterate_t* gen_iterator;\r
+    char *cur_pos;\r
+    cc_uint32 zero = 0;\r
+    cc_uint32 magic = 0;\r
+    cc_uint32 msg_len;\r
+    cc_uint32 u32;\r
+    cc_int32 code;\r
+\r
+    if (msg == NULL || flatpp == NULL)\r
+        return ccErrBadParam;\r
+\r
+    code = cci_msg_calc_size(msg,&msg->flat_len);\r
+    if ( code != ccNoError )\r
+        return code;\r
+\r
+    if (msg->flat_len > CC_MSG_MAX_SIZE)\r
+        return ccErrBadParam;\r
+\r
+    msg->flat = (void *)malloc(msg->flat_len);\r
+    if (msg->flat == NULL)\r
+        return ccErrNoMem;\r
+    \r
+    cur_pos = msg->flat;\r
+\r
+    u32 = msg->header_len;\r
+    htonl(u32);\r
+    memcpy(cur_pos,&u32,sizeof(cc_uint32));\r
+    cur_pos+=sizeof(cc_uint32);\r
+\r
+    u32 = msg->flat_len;\r
+    htonl(u32);\r
+    memcpy(cur_pos,&u32,sizeof(cc_uint32));\r
+    cur_pos+=sizeof(cc_uint32);\r
+\r
+    u32 = msg->type;\r
+    htonl(u32);\r
+    memcpy(cur_pos,&u32,sizeof(cc_uint32));\r
+    cur_pos+=sizeof(cc_uint32);\r
+\r
+    /* header data is already in network order */\r
+    memcpy(cur_pos, msg->header, msg->header_len);\r
+    cur_pos += msg->header_len;\r
+\r
+    u32 = zero;\r
+    htonl(zero);\r
+    memcpy(cur_pos, &u32, sizeof(cc_uint32)); /*will be magic number later*/\r
+    cur_pos += sizeof(cc_uint32);\r
+\r
+    code = cci_generic_list_iterator(msg->data_blobs, &gen_iterator);\r
+    if ( code != ccNoError ) {\r
+        free(msg->flat);\r
+        return code;\r
+    }\r
+\r
+    while (cci_generic_iterate_has_next(gen_iterator)) {\r
+        code = cci_generic_iterate_next(gen_iterator, &gen_node);\r
+        if (code != ccNoError) {\r
+            free(gen_iterator);\r
+            free(msg->flat);\r
+            return code;\r
+        }\r
+       u32 = gen_node->len;\r
+       htonl(u32);\r
+        memcpy(cur_pos, &u32, sizeof(cc_uint32));\r
+        cur_pos+=sizeof(cc_uint32);\r
+               \r
+       /* data already in network order */\r
+        memcpy(cur_pos, gen_node->data, gen_node->len);\r
+        cur_pos += gen_node->len;\r
+    }\r
+    free(gen_iterator);\r
+\r
+    u32 = zero;\r
+    htonl(zero);\r
+    memcpy(cur_pos, &u32, sizeof(cc_uint32)); /*magic number will go here later*/\r
+    cur_pos += sizeof(cc_uint32);\r
+\r
+    if (cur_pos - (char *)msg->flat != msg->flat_len) {\r
+        fprintf(stderr, "ERROR cur_pos - msg->flat = %d\n",msg->flat_len);\r
+    }\r
+\r
+    cci_msg_calc_magic(msg->flat, msg->flat_len, &magic);\r
+    printf("magic = %d\n",magic);\r
+       \r
+    cci_msg_calc_header_size(msg, &msg_len);\r
+    memcpy((char *)msg->flat + msg_len, &magic, sizeof(cc_uint32));\r
+    memcpy((char *)msg->flat + msg->flat_len - sizeof(cc_uint32), &magic, sizeof(cc_uint32));\r
+\r
+    if ( flatpp != NULL )\r
+        *flatpp = msg->flat;\r
+\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * cc_msg_\r
+ *\r
+ * Purpose:\r
+ *\r
+ * Return: \r
+ *\r
+ * Errors: \r
+ *\r
+ */\r
+cc_int32\r
+cci_msg_calc_magic(void *flat, int flat_len, cc_uint32 * magicp)\r
+{\r
+    cc_uint32 magic = 0;\r
+    int i;\r
+       \r
+    for (i = 0; i < flat_len; i += sizeof(cc_uint32)) {\r
+        magic = magic ^ *(int *)((char *)flat + i);\r
+    }\r
+    *magicp = htonl(magic);\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * cc_msg_\r
+ *\r
+ * Purpose:\r
+ *\r
+ * Return: \r
+ *\r
+ * Errors: \r
+ *\r
+ */\r
+cc_int32 \r
+cci_msg_verify(void *flat, int flat_len, cc_uint32 * validp)  \r
+{\r
+    cc_uint32 *magic1, *magic2;\r
+    cc_uint32 *pheader_len;\r
+    cc_uint32 header_len;\r
+    cc_uint32 *ptotal_len;\r
+    cc_uint32 total_len;\r
+    cc_uint32 *pblob_len;\r
+    cc_uint32 blob_len;\r
+    cc_uint32 *ptype;\r
+    cc_uint32 type;\r
+    cc_uint32 num_blobs = 0;\r
+    cc_uint32 zero = 0;\r
+    cc_uint32 msg_magic, msg_magic2;\r
+\r
+    if (flat == NULL || flat_len <= 0 || validp == NULL)\r
+        return ccErrBadParam;\r
+\r
+    pheader_len = flat;\r
+    ptotal_len = (cc_uint32 *)((char *)pheader_len + sizeof(cc_uint32));\r
+    ptype = (cc_uint32 *)((char *)ptotal_len + sizeof(cc_uint32));\r
+\r
+    header_len = ntohl(*pheader_len);\r
+    total_len = ntohl(*ptotal_len);\r
+    type = ntohl(*ptype);\r
+\r
+    if (total_len != flat_len) {\r
+        *validp = 0;\r
+        return ccNoError;\r
+    }\r
+    \r
+    if (header_len > flat_len) {\r
+        /*too weak. We could verify header_len against type spec header.*/\r
+        *validp = 0;\r
+        return ccNoError;\r
+    }\r
+    if (type > CC_MSG_MAX_TYPE) {\r
+        *validp = 0;\r
+        return ccNoError;\r
+    }\r
+\r
+    magic1 = (cc_uint32 *)((char *)ptype + sizeof(cc_uint32) + header_len); \r
+    if ((char *)magic1 - (char *)flat == (flat_len - 8)) {\r
+        /*There are no data blobs*/\r
+        magic2 = (cc_uint32 *)((char *)magic1 + sizeof(cc_uint32));\r
+        num_blobs = 0;\r
+    } else {\r
+        pblob_len = (cc_uint32 *)((char *)magic1 + sizeof(cc_uint32));\r
+        num_blobs = 1;\r
+       blob_len = nothl(*pblob_len);\r
+\r
+        while (blob_len + sizeof(cc_uint32) + ((char *)pblob_len - (char *)flat) < (flat_len - sizeof(cc_uint32))) {\r
+            pblob_len = (cc_uint32 *)((char *)pblob_len + blob_len + sizeof(cc_uint32));\r
+            num_blobs++;\r
+           blob_len = ntohl(*pblob_len);\r
+        }\r
+\r
+        if (blob_len + sizeof(cc_uint32) + ((char *)pblob_len - (char *)flat) != (flat_len - sizeof(cc_uint32))) {\r
+            /*blobs didn't line up*/\r
+            *validp = 0;\r
+            return ccNoError;\r
+        }\r
+        magic2 = (cc_uint32 *)((char *)pblob_len + blob_len + sizeof(cc_uint32)); /*2nd magic should be directly after the last blob*/\r
+    }\r
+       \r
+    if (*magic1 != *magic2) {\r
+        *validp = 0;\r
+        return ccNoError;\r
+    }\r
+    msg_magic = *magic1;\r
+\r
+    printf("%d %d\n", (char *)magic1 - (char *)flat, (char *)magic2 - (char *)flat);\r
+\r
+    memcpy(magic1, &zero, sizeof(cc_uint32));\r
+    memcpy(magic2, &zero, sizeof(cc_uint32));\r
+    cci_msg_calc_magic(flat, flat_len, &msg_magic2);\r
+    /* both msg_magic and msg_magic2 are in network order */\r
+    if (msg_magic != msg_magic2) {\r
+        *validp = 0;\r
+        return ccNoError;\r
+    }\r
+    memcpy(magic1, &msg_magic, sizeof(cc_uint32));\r
+    memcpy(magic2, &msg_magic, sizeof(cc_uint32));\r
+\r
+    *validp = 1;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * cc_msg_\r
+ *\r
+ * Purpose:\r
+ *\r
+ * Return: \r
+ *\r
+ * Errors: \r
+ *\r
+ */\r
+cc_int32\r
+cci_msg_unflatten(void *flat, int flat_len, cc_msg_t** msgpp) \r
+{\r
+    cc_msg_t* msg;\r
+    char *cur_pos;\r
+    cc_uint32 blob_len;\r
+    char *blob;\r
+    cc_uint32 valid;\r
+    cc_int32 code;\r
+\r
+    if ( flat == NULL || flat_len <= 0 || msgpp == NULL )\r
+        return ccErrBadParam;\r
+\r
+    code = cci_msg_new(0, &msg);\r
+    if (code)\r
+        return code;\r
+\r
+    cci_msg_verify(flat, flat_len, &valid);\r
+    if (valid != 1) {\r
+        cci_msg_destroy(msg);\r
+        return ccErrBadParam;\r
+    }\r
+\r
+    cur_pos = flat;\r
+    msg->flat = flat;\r
+\r
+    msg->header_len = ntohl(*(cc_uint32 *)cur_pos);\r
+    cur_pos += sizeof(cc_uint32);\r
+\r
+    msg->flat_len = ntohl(*(cc_uint32 *)cur_pos);\r
+    cur_pos += sizeof(cc_uint32);\r
+\r
+    msg->type = ntohl(*(cc_uint32 *)cur_pos);\r
+    cur_pos += sizeof(cc_uint32);\r
+\r
+    msg->header = (void *)malloc(msg->header_len);\r
+    if (msg->header == NULL) {\r
+        cci_msg_destroy(msg);\r
+        return ccErrNoMem;\r
+    }\r
+    memcpy(msg->header, cur_pos, msg->header_len);\r
+    cur_pos += msg->header_len;\r
+       \r
+    msg->magic = nothl(*(cc_uint32 *)cur_pos);\r
+    cur_pos += sizeof(cc_uint32);\r
+\r
+    if (cur_pos - (char *)flat != flat_len - 8) { /*at least 1 blob*/\r
+        blob_len = ntohl(*(cc_uint32 *)cur_pos);\r
+        while (blob_len + (cur_pos - (char *)flat) + sizeof(cc_uint32) <= flat_len - sizeof(cc_uint32)) {\r
+            blob = (void *)malloc(blob_len);\r
+            if (blob == NULL) {\r
+                cci_msg_destroy(msg);\r
+                return ccErrNoMem;\r
+            }\r
+            memcpy(blob, cur_pos + sizeof(cc_uint32), blob_len);\r
+            cci_generic_list_append(msg->data_blobs, blob, blob_len, NULL);\r
+\r
+            cur_pos += sizeof(cc_uint32) + blob_len;\r
+            blob_len = ntohl(*(int *)cur_pos);\r
+        }\r
+    }\r
+    *msgpp = msg;\r
+    return ccNoError;\r
+}\r
+\r
+cc_int32\r
+cci_msg_retrieve_blob(cc_msg_t* msg, cc_uint32 blob_offset, cc_uint32 blob_len, void **blobp) \r
+{\r
+    cc_generic_iterate_t*      gen_iterator;\r
+    cc_generic_list_node_t*    gen_node;\r
+    void *ret;\r
+    cc_uint32                   blob_pos;\r
+    cc_int32                    code;\r
+\r
+    /*Ensure that the message has been unflattened*/\r
+    if ( msg == NULL || msg->flat == NULL || blob_offset > msg->flat_len || \r
+         blob_len > msg->flat_len - blob_offset || blobp == NULL)\r
+        return ccErrBadParam;\r
+\r
+    code = cci_generic_list_iterator(msg->data_blobs, &gen_iterator);\r
+    while (cci_generic_iterate_has_next(gen_iterator)) {\r
+        code = cci_generic_iterate_next(gen_iterator, &gen_node);\r
+        code = cci_msg_calc_blob_pos(msg, gen_node->data, gen_node->len, &blob_pos);\r
+        if (blob_pos == blob_offset && gen_node->len == blob_len)  {\r
+            free(gen_iterator);\r
+            ret = (void *)malloc(blob_len);\r
+            if (ret == NULL)\r
+                return ccErrNoMem;\r
+            memcpy(ret,(char *)msg->flat + blob_offset, blob_len);     \r
+            *blobp = ret;\r
+            return ccNoError;\r
+        }\r
+    }\r
+    free(gen_iterator);\r
+    return ccIteratorEnd;\r
+}\r
+\r
+/**\r
+ * cc_msg_\r
+ *\r
+ * Purpose:\r
+ *\r
+ * Return: \r
+ *\r
+ * Errors: \r
+ *\r
+ */\r
+cc_int32 \r
+cci_msg_destroy(cc_msg_t* msg) \r
+{\r
+    if (msg->flat != NULL) \r
+        free(msg->flat);\r
+    if (msg->header != NULL)\r
+        free(msg->flat);\r
+    cci_generic_list_destroy(msg->data_blobs);\r
+    free(msg);\r
+    return ccNoError;\r
+}\r
+\r
index dd60fa46d6542a0cf8ca4d7e65df59ed61ac3f09..7143da4e255509cdf6ee13351905849c7f2bd347 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 1998-2004 by the Massachusetts Institute of Technology.
+ * Copyright 1998-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
 /*
  * Declarations for Credentials Cache API Library
  *
- * API specification: <http://web.mit.edu/pismere/kerberos/ccache-api-v2.html>
+ * API specification: <http://web.mit.edu/pismere/kerberos/ccache-api-v3.html>
  *
  *     Revision 1: Frank Dabek, 6/4/1998
  *     Revision 2: meeroh, 2/24/1999
  *      Revision 3: meeroh, 11/12/1999
- *      Revision 4: jaltman, 10/27/2004
+ *      Revision 6: jaltman, 10/27/2004
  *
  */
  
@@ -81,6 +81,17 @@ extern "C" {
     #pragma options align=mac68k
 #endif
 
+#if defined(_WIN32)
+#define CCACHE_API     __declspec(dllexport)
+
+#if _INTEGRAL_MAX_BITS >= 64 && _MSC_VER >= 1400 && !defined(_WIN64) && !defined(_USE_32BIT_TIME_T)
+#if defined(_TIME_T_DEFINED) || defined(_INC_IO) || defined(_INC_TIME) || defined(_INC_WCHAR)
+#error time_t has been defined as a 64-bit integer which is incompatible with Kerberos on this platform.
+#endif /* _TIME_T_DEFINED */
+#define _USE_32BIT_TIME_T
+#endif 
+#endif
+
 #include <time.h>
 
 /*
@@ -92,14 +103,16 @@ enum {
     ccapi_version_2 = 2,
     ccapi_version_3 = 3,
     ccapi_version_4 = 4,
-    ccapi_version_5 = 5
+    ccapi_version_5 = 5,
+    ccapi_version_6 = 6,
+    ccapi_version_max = ccapi_version_6
 };
  
 /* Errors */
 enum {
-    ccNoError                                                  = 0,
+    ccNoError                                          = 0,
 
-    ccIteratorEnd                                              = 201,
+    ccIteratorEnd                                      = 201,
     ccErrBadParam,
     ccErrNoMem,
     ccErrInvalidContext,
@@ -111,7 +124,7 @@ enum {
     ccErrInvalidCredentialsIterator,
     ccErrInvalidLock,
 
-    ccErrBadName,                                              /* 211 */
+    ccErrBadName,                                      /* 211 */
     ccErrBadCredentialsVersion,
     ccErrBadAPIVersion,
     ccErrContextLocked,
@@ -123,7 +136,7 @@ enum {
     ccErrNeverDefault,
     ccErrCredentialsNotFound,
 
-    ccErrCCacheNotFound,                                       /* 221 */
+    ccErrCCacheNotFound,                               /* 221 */
     ccErrContextNotFound,
     ccErrServerUnavailable,
     ccErrServerInsecure,
@@ -135,20 +148,22 @@ enum {
 };
 
 /* Credentials versions */
-enum {
+enum cc_credential_versions {
     cc_credentials_v4 = 1,
     cc_credentials_v5 = 2,
     cc_credentials_v4_v5 = 3
 };
 
 /* Lock types */
-enum {
-    cc_lock_read = 1,
-    cc_lock_write = 2
+enum cc_lock_types {
+    cc_lock_read = 0,
+    cc_lock_write = 1,
+    cc_lock_upgrade = 2,
+    cc_lock_downgrade = 3
 };
 
 /* Locking Modes */
-enum {
+enum cc_lock_modes {
     cc_lock_noblock = 0,
     cc_lock_block = 1
 };
@@ -157,12 +172,20 @@ enum {
  * Basic types
  */
  
-typedef char           cc_int8;
-typedef unsigned char  cc_uint8;
-typedef int            cc_int32;
-typedef unsigned int   cc_uint32;
-typedef time_t         cc_time_t;
-typedef void *         cc_handle;
+typedef char                           cc_int8;
+typedef unsigned char                  cc_uint8;
+typedef int                            cc_int32;
+typedef unsigned int                   cc_uint32;
+#if defined (WIN32)
+typedef __int64                        cc_int64;
+typedef unsigned __int64       cc_uint64;
+#else
+typedef long long              cc_int64;
+typedef unsigned long long     cc_uint64;
+#endif
+typedef time_t                         cc_time;
+typedef cc_int64               cc_time64;
+typedef cc_uint64                      cc_handle;
 
 /*
  * API types
@@ -190,10 +213,11 @@ typedef struct cc_credentials_f cc_credentials_f;
 /* Credentials types */
 
 enum { /* Make sure all of these are multiples of four (for alignment sanity) */
-    cc_v4_name_size            = 40,
+    cc_v4_name_size    = 40,
     cc_v4_instance_size        = 40,
     cc_v4_realm_size   = 40,
-    cc_v4_ticket_size  = 1254
+    cc_v4_ticket_size  = 1254,
+    cc_v4_key_size     = 8
 };
 
 enum cc_string_to_key_type {
@@ -211,10 +235,10 @@ struct cc_credentials_v4_t {
     char                       service [cc_v4_name_size];
     char                       service_instance [cc_v4_instance_size];
     char                       realm [cc_v4_realm_size];
-    unsigned char              session_key [8];
+    unsigned char              session_key [cc_v4_key_size];
     cc_int32                   kvno;
     cc_int32                   string_to_key_type;
-    cc_time_t                  issue_date;
+    cc_time                    issue_date;
     cc_int32                   lifetime;
     cc_uint32                  address;
     cc_int32                   ticket_size;
@@ -233,10 +257,10 @@ struct cc_credentials_v5_t {
     char*                      client;
     char*                      server;
     cc_data                    keyblock;
-    cc_time_t                  authtime;
-    cc_time_t                  starttime;
-    cc_time_t                  endtime;
-    cc_time_t                  renew_till;
+    cc_time                    authtime;
+    cc_time                    starttime;
+    cc_time                    endtime;
+    cc_time                    renew_till;
     cc_uint32                  is_skey;
     cc_uint32                  ticket_flags;
     cc_data**                  addresses;
@@ -320,7 +344,7 @@ struct  cc_context_f {
                                 cc_context_t context);
     cc_int32    (*get_change_time) (
                                 cc_context_t context,
-                                cc_time_t* time);
+                                cc_time* time);
     cc_int32    (*get_default_ccache_name) (
                                 cc_context_t context,
                                 cc_string_t* name);
@@ -397,16 +421,16 @@ struct cc_ccache_f {
                                  cc_ccache_t destination);
     cc_int32    (*lock) (
                                  cc_ccache_t ccache,
-                                 cc_uint32 block,
-                                 cc_uint32 lock_type);
+                                 cc_uint32 lock_type,
+                                 cc_uint32 block);
     cc_int32    (*unlock) (
                                  cc_ccache_t ccache);
     cc_int32    (*get_last_default_time) (
                                  cc_ccache_t ccache,
-                                 cc_time_t* time);
+                                 cc_time* time);
     cc_int32    (*get_change_time) (
                                  cc_ccache_t ccache,
-                                 cc_time_t* time);
+                                 cc_time* time);
     cc_int32    (*compare) (
                                 cc_ccache_t ccache,
                                 cc_ccache_t compare_to,
@@ -414,11 +438,11 @@ struct cc_ccache_f {
     cc_int32   (*get_kdc_time_offset) (
                                 cc_ccache_t ccache,
                                 cc_int32       credentials_version,
-                                cc_time_t*     time_offset);
+                                cc_time*       time_offset);
     cc_int32   (*set_kdc_time_offset) (
                                 cc_ccache_t ccache,
                                 cc_int32       credentials_version,
-                                cc_time_t      time_offset);
+                                cc_time        time_offset);
                                 
     cc_int32   (*clear_kdc_time_offset) (
                                 cc_ccache_t    ccache,
@@ -446,6 +470,9 @@ struct cc_ccache_iterator_f {
     cc_int32    (*next) (
                                  cc_ccache_iterator_t iter,
                                  cc_ccache_t* ccache);
+
+    cc_int32   (*clone) (       cc_ccache_iterator_t iter,
+                                cc_ccache_iterator_t* new_iter);
 };
 
 struct cc_credentials_iterator_f {
@@ -454,16 +481,19 @@ struct cc_credentials_iterator_f {
     cc_int32    (*next) (
                                  cc_credentials_iterator_t iter,
                                  cc_credentials_t* ccache);
+
+    cc_int32   (*clone) (       cc_credentials_iterator_t iter,
+                                cc_credentials_iterator_t* new_iter);
 };
 
 /*
  * API functions
  */
  
-cc_int32 cc_initialize (
+CCACHE_API cc_int32 cc_initialize (
        cc_context_t*           outContext,
-       cc_int32                        inVersion,
-       cc_int32*                       outSupportedVersion,
+       cc_int32                inVersion,
+       cc_int32*               outSupportedVersion,
        char const**            outVendor);
        
 /*
@@ -488,8 +518,8 @@ cc_int32 cc_initialize (
                        ((context) -> functions -> create_new_ccache (context, version, principal, ccache))
 #define                cc_context_new_ccache_iterator(context, iterator)                                               \
                        ((context) -> functions -> new_ccache_iterator (context, iterator))
-#define                cc_context_lock(context, type, lock)                                                                    \
-                       ((context) -> functions -> lock (context, type, lock))
+#define                cc_context_lock(context, type, block)                                                                   \
+                       ((context) -> functions -> lock (context, type, block))
 #define                cc_context_unlock(context)                                                                                              \
                        ((context) -> functions -> unlock (context))
 #define                cc_context_compare(context, compare_to, equal)                                                  \
@@ -515,8 +545,8 @@ cc_int32 cc_initialize (
                        ((ccache) -> functions -> remove_credentials (ccache, credentials))
 #define                cc_ccache_new_credentials_iterator(ccache, iterator)                                    \
                        ((ccache) -> functions -> new_credentials_iterator (ccache, iterator))
-#define                cc_ccache_lock(ccache, lock)                                                                                    \
-                       ((ccache) -> functions -> lock (ccache, lock))
+#define                cc_ccache_lock(ccache, type, block)                                                                                     \
+                       ((ccache) -> functions -> lock (ccache, type, block))
 #define                cc_ccache_unlock(ccache, unlock)                                                                                \
                        ((ccache) -> functions -> unlock (ccache, unlock))
 #define                cc_ccache_get_last_default_time(ccache, time)                                                   \
@@ -528,11 +558,11 @@ cc_int32 cc_initialize (
 #define                cc_ccache_compare(ccache, compare_to, equal)                                                    \
                        ((ccache) -> functions -> compare (ccache, compare_to, equal))
 #define                cc_ccache_get_kdc_time_offset(ccache, version, time)                                    \
-            ((ccache) -> functions -> get_kdc_time_offset (version, time))
+                        ((ccache) -> functions -> get_kdc_time_offset (version, time))
 #define                cc_ccache_set_kdc_time_offset(ccache, version, time)                                    \
-            ((ccache) -> functions -> set_kdc_time_offset (version, time))
+                        ((ccache) -> functions -> set_kdc_time_offset (version, time))
 #define                cc_ccache_clear_kdc_time_offset(ccache, version)                                                \
-            ((ccache) -> functions -> clear_kdc_time_offset (version))
+                        ((ccache) -> functions -> clear_kdc_time_offset (version))
 
 #define                cc_string_release(string)                                                                                               \
                        ((string) -> functions -> release (string))
@@ -546,11 +576,15 @@ cc_int32 cc_initialize (
                        ((iterator) -> functions -> release (iterator))
 #define                cc_ccache_iterator_next(iterator, ccache)                                                               \
                        ((iterator) -> functions -> next (iterator, ccache))
+#define                cc_ccache_iterator_clone(iterator, new_iter)                                                            \
+                       ((iterator) -> functions -> clone (iterator, new_iter))
        
 #define                cc_credentials_iterator_release(iterator)                                                               \
                        ((iterator) -> functions -> release (iterator))
 #define                cc_credentials_iterator_next(iterator, credentials)                                             \
                        ((iterator) -> functions -> next (iterator, credentials))
+#define                cc_credentials_iterator_clone(iterator, new_iter)                                                               \
+                       ((iterator) -> functions -> clone (iterator, new_iter))
                        
 #if TARGET_OS_MAC
     #if defined(__MWERKS__)
index 401e093f43f7871726fbe44d93c13db27574fe2c..214d93a02f0a74b0b8a32a880737ea154d982b10 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 1998-2004 by the Massachusetts Institute of Technology.
+ * Copyright 1998-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -48,7 +48,7 @@
 #ifndef __CREDENTIALSCACHE2__
 #define __CREDENTIALSCACHE2__
  
-#include <Kerberos/CredentialsCache.h>
+#include "CredentialsCache.h"
 #if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
        #include <TargetConditionals.h>
     #if TARGET_RT_MAC_CFM
@@ -185,25 +185,25 @@ enum {
     CC_CRED_MAX
 };
 
-cc_int32 cc_shutdown (
+CCACHE_API cc_int32 cc_shutdown (
         apiCB**                                ioContext);
        
-cc_int32 cc_get_NC_info (
+CCACHE_API cc_int32 cc_get_NC_info (
        apiCB*                          inContext,
        infoNC***                       outInfo);
        
-cc_int32 cc_get_change_time (
+CCACHE_API cc_int32 cc_get_change_time (
        apiCB*                          inContext,
        cc_time_t*                      outTime);
        
-cc_int32 cc_open (
+CCACHE_API cc_int32 cc_open (
        apiCB*                          inContext,
        const char*                     inName,
        cc_int32                        inVersion,
        cc_uint32                       inFlags,
        ccache_p**                      outCCache);
        
-cc_int32 cc_create (
+CCACHE_API cc_int32 cc_create (
        apiCB*                          inContext,
        const char*                     inName,
        const char*                     inPrincipal,
@@ -211,85 +211,85 @@ cc_int32 cc_create (
        cc_uint32                       inFlags,
        ccache_p**                      outCCache);
        
-cc_int32 cc_close (
+CCACHE_API cc_int32 cc_close (
        apiCB*                          inContext,
        ccache_p**                      ioCCache);
        
-cc_int32 cc_destroy (
+CCACHE_API cc_int32 cc_destroy (
        apiCB*                          inContext,
        ccache_p**                      ioCCache);
        
-cc_int32 cc_seq_fetch_NCs_begin (
+CCACHE_API cc_int32 cc_seq_fetch_NCs_begin (
        apiCB*                          inContext,
-       ccache_cit**            outIterator);
+       ccache_cit**                    outIterator);
 
-cc_int32 cc_seq_fetch_NCs_next (
+CCACHE_API cc_int32 cc_seq_fetch_NCs_next (
        apiCB*                          inContext,
        ccache_p**                      outCCache,
        ccache_cit*                     inIterator);
 
-cc_int32 cc_seq_fetch_NCs_end (
+CCACHE_API cc_int32 cc_seq_fetch_NCs_end (
        apiCB*                          inContext,
-       ccache_cit**            ioIterator);
+       ccache_cit**                    ioIterator);
 
-cc_int32 cc_get_name (
+CCACHE_API cc_int32 cc_get_name (
        apiCB*                          inContext,
        ccache_p*                       inCCache,
        char**                          outName);
        
-cc_int32 cc_get_cred_version (
+CCACHE_API cc_int32 cc_get_cred_version (
        apiCB*                          inContext,
        ccache_p*                       inCCache,
        cc_int32*                       outVersion);
        
-cc_int32 cc_set_principal (
+CCACHE_API cc_int32 cc_set_principal (
        apiCB*                          inContext,
        ccache_p*                       inCCache,
        cc_int32                        inVersion,
        char*                           inPrincipal);
        
-cc_int32 cc_get_principal (
+CCACHE_API cc_int32 cc_get_principal (
        apiCB*                          inContext,
        ccache_p*                       inCCache,
        char**                          outPrincipal);
        
-cc_int32 cc_store (
+CCACHE_API cc_int32 cc_store (
        apiCB*                          inContext,
        ccache_p*                       inCCache,
        cred_union                      inCredentials);
 
-cc_int32 cc_remove_cred (
+CCACHE_API cc_int32 cc_remove_cred (
        apiCB*                          inContext,
        ccache_p*                       inCCache,
        cred_union                      inCredentials);
 
-cc_int32 cc_seq_fetch_creds_begin (
+CCACHE_API cc_int32 cc_seq_fetch_creds_begin (
        apiCB*                          inContext,
-       const ccache_p*         inCCache,
-       ccache_cit**            outIterator);
+       const ccache_p*                 inCCache,
+       ccache_cit**                    outIterator);
 
-cc_int32 cc_seq_fetch_creds_next (
+CCACHE_API cc_int32 cc_seq_fetch_creds_next (
        apiCB*                          inContext,
-       cred_union**            outCreds,
+       cred_union**                    outCreds,
        ccache_cit*                     inIterator);
        
-cc_int32 cc_seq_fetch_creds_end (
+CCACHE_API cc_int32 cc_seq_fetch_creds_end (
        apiCB*                          inContext,
-       ccache_cit**            ioIterator);
+       ccache_cit**                    ioIterator);
        
-cc_int32 cc_free_principal (
+CCACHE_API cc_int32 cc_free_principal (
        apiCB*                          inContext,
        char**                          ioPrincipal);
 
-cc_int32 cc_free_name (
+CCACHE_API cc_int32 cc_free_name (
        apiCB*                          inContext,
        char**                          ioName);
 
-cc_int32 cc_free_creds (
+CCACHE_API cc_int32 cc_free_creds (
        apiCB*                          inContext,
-       cred_union**            creds);
+       cred_union**                    creds);
 
-cc_int32 cc_free_NC_info (
+CCACHE_API cc_int32 cc_free_NC_info (
        apiCB*                          inContext,
        infoNC***                       ioInfo);
        
diff --git a/src/lib/ccapi/include/cc_rpc.h b/src/lib/ccapi/include/cc_rpc.h
new file mode 100644 (file)
index 0000000..0f14724
--- /dev/null
@@ -0,0 +1,52 @@
+/* $Copyright:\r
+ *\r
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.\r
+ * \r
+ * All rights reserved.\r
+ * \r
+ * Export of this software from the United States of America may require a\r
+ * specific license from the United States Government.  It is the\r
+ * responsibility of any person or organization contemplating export to\r
+ * obtain such a license before exporting.\r
+ * \r
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute\r
+ * this software and its documentation for any purpose and without fee is\r
+ * hereby granted, provided that the above copyright notice appear in all\r
+ * copies and that both that copyright notice and this permission notice\r
+ * appear in supporting documentation, and that the name of M.I.T. not be\r
+ * used in advertising or publicity pertaining to distribution of the\r
+ * software without specific, written prior permission.  Furthermore if you\r
+ * modify this software you must label your software as modified software\r
+ * and not distribute it in such a fashion that it might be confused with\r
+ * the original MIT software. M.I.T. makes no representations about the\r
+ * suitability of this software for any purpose.  It is provided "as is"\r
+ * without express or implied warranty.\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\r
+ * \r
+ * Individual source code files are copyright MIT, Cygnus Support,\r
+ * OpenVision, Oracle, Sun Soft, FundsXpress, and others.\r
+ * \r
+ * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,\r
+ * and Zephyr are trademarks of the Massachusetts Institute of Technology\r
+ * (MIT).  No commercial use of these trademarks may be made without prior\r
+ * written permission of MIT.\r
+ * \r
+ * "Commercial use" means use of a name in a product or other for-profit\r
+ * manner.  It does NOT prevent a commercial firm from referring to the MIT\r
+ * trademarks in order to convey information (although in doing so,\r
+ * recognition of their trademark status should be given).\r
+ * $\r
+ */\r
+\r
+\r
+#ifndef __CC_RPC_H__\r
+#define __CC_RPC_H__\r
+\r
+#include "msg.h"\r
+\r
+cc_int32 cci_perform_rpc(cc_msg_t *request, cc_msg_t **response);\r
+\r
+#endif /* __CC_RPC_H__ */\r
diff --git a/src/lib/ccapi/include/generic_lists.h b/src/lib/ccapi/include/generic_lists.h
new file mode 100644 (file)
index 0000000..4d49e27
--- /dev/null
@@ -0,0 +1,95 @@
+/* $Copyright:\r
+ *\r
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.\r
+ * \r
+ * All rights reserved.\r
+ * \r
+ * Export of this software from the United States of America may require a\r
+ * specific license from the United States Government.  It is the\r
+ * responsibility of any person or organization contemplating export to\r
+ * obtain such a license before exporting.\r
+ * \r
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute\r
+ * this software and its documentation for any purpose and without fee is\r
+ * hereby granted, provided that the above copyright notice appear in all\r
+ * copies and that both that copyright notice and this permission notice\r
+ * appear in supporting documentation, and that the name of M.I.T. not be\r
+ * used in advertising or publicity pertaining to distribution of the\r
+ * software without specific, written prior permission.  Furthermore if you\r
+ * modify this software you must label your software as modified software\r
+ * and not distribute it in such a fashion that it might be confused with\r
+ * the original MIT software. M.I.T. makes no representations about the\r
+ * suitability of this software for any purpose.  It is provided "as is"\r
+ * without express or implied warranty.\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\r
+ * \r
+ * Individual source code files are copyright MIT, Cygnus Support,\r
+ * OpenVision, Oracle, Sun Soft, FundsXpress, and others.\r
+ * \r
+ * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,\r
+ * and Zephyr are trademarks of the Massachusetts Institute of Technology\r
+ * (MIT).  No commercial use of these trademarks may be made without prior\r
+ * written permission of MIT.\r
+ * \r
+ * "Commercial use" means use of a name in a product or other for-profit\r
+ * manner.  It does NOT prevent a commercial firm from referring to the MIT\r
+ * trademarks in order to convey information (although in doing so,\r
+ * recognition of their trademark status should be given).\r
+ * $\r
+ */\r
+/*\r
+ * Prototypes and data structures for datastore.\r
+ *\r
+ */\r
+\r
+\r
+#ifndef __CC_GENERIC_LISTS_H_\r
+#define __CC_GENERIC_LISTS_H_\r
+\r
+struct cc_generic_list_node_t {\r
+    cc_uint8*                          data;\r
+    cc_uint32                          len;\r
+    struct cc_generic_list_node_t*     next;\r
+    struct cc_generic_list_node_t*     prev;\r
+};\r
+typedef struct cc_generic_list_node_t cc_generic_list_node_t;\r
+\r
+struct cc_generic_list_head_t {\r
+    enum cc_list_type                   type;\r
+    cc_generic_list_node_t*            head;\r
+    cc_generic_list_node_t*            tail; \r
+};      \r
+typedef struct cc_generic_list_head_t cc_generic_list_head_t;\r
+\r
+\r
+struct cc_generic_iterate_t {\r
+    cc_generic_list_node_t*            next;\r
+};\r
+typedef struct cc_generic_iterate_t cc_generic_iterate_t;\r
+\r
+typedef cc_generic_list_head_t cc_context_list_head_t;\r
+typedef cc_generic_list_node_t cc_context_list_node_t;\r
+\r
+typedef cc_generic_list_head_t cc_ccache_list_head_t;\r
+typedef cc_generic_list_node_t cc_ccache_list_node_t;\r
+\r
+typedef cc_generic_list_head_t cc_credentials_list_head_t;\r
+typedef cc_generic_list_node_t cc_credentials_list_node_t;\r
+\r
+cc_int32 cci_generic_iterate_has_next(cc_generic_iterate_t *iterate);\r
+cc_int32 cci_generic_iterate_next(cc_generic_iterate_t *iterate, cc_generic_list_node_t**);\r
+\r
+cc_int32 cci_generic_list_new(cc_generic_list_head_t **);\r
+cc_int32 cci_generic_list_append(cc_generic_list_head_t *head, void *data, cc_uint32 len, cc_generic_list_node_t**);\r
+cc_int32 cci_generic_list_prepend(cc_generic_list_head_t *head, void *data, cc_uint32 len, cc_generic_list_node_t**);\r
+cc_int32 cci_generic_list_remove_element(cc_generic_list_head_t* head, cc_generic_list_node_t* rem);\r
+cc_int32 cci_generic_free_element(cc_generic_list_node_t* node);\r
+cc_int32 cci_generic_list_destroy(cc_generic_list_head_t* head);\r
+cc_int32 cci_generic_list_copy(cc_generic_list_head_t* head, cc_generic_list_head_t**);\r
+cc_int32 cci_generic_list_iterator(cc_generic_list_head_t *head, cc_generic_iterate_t**);\r
+cc_int32 cci_generic_free_iterator(cc_generic_iterate_t* iterator);\r
+\r
+#endif /* __CC_GENERIC_LISTS_H_ */\r
index 19b9463b08246c4d7744b33d48787befae16a972..ca6b12e968f0803b7d1a1670e1623cd8c60fccbf 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -41,7 +41,6 @@
  * $
  */
 
-#define FLAT_CREDS_V5_VERSION   1
 struct cc_flat_data {
     cc_uint32                   type;
     cc_uint32                   length;
@@ -49,15 +48,16 @@ struct cc_flat_data {
 };
 typedef struct cc_flat_data cc_flat_data;
 
+#define FLAT_CREDS_V5_VERSION   1
 struct cci_flat_creds_v5 {
     cc_uint32                   version;        /* version of this structure */
     cc_flat_data                client;
     cc_flat_data                server;
     cc_flat_data               keyblock;
-    cc_time_t                  authtime;
-    cc_time_t                  starttime;
-    cc_time_t                  endtime;
-    cc_time_t                  renew_till;
+    cc_time64                  authtime;
+    cc_time64                  starttime;
+    cc_time64                  endtime;
+    cc_time64                  renew_till;
     cc_uint32                  is_skey;
     cc_uint32                  ticket_flags;
     cc_uint32                   address_count;
@@ -67,6 +67,25 @@ struct cci_flat_creds_v5 {
     cc_uint32                   authdata_count;
     cc_uint32                  authdata;  /* offset to array */
 };
+typedef struct cci_flat_creds_v5 cci_flat_creds_v5_t;
+
+struct cci_flat_creds_v4 {
+    cc_uint32                  version;
+    char                       principal [cc_v4_name_size];
+    char                       principal_instance [cc_v4_instance_size];
+    char                       service [cc_v4_name_size];
+    char                       service_instance [cc_v4_instance_size];
+    char                       realm [cc_v4_realm_size];
+    unsigned char              session_key [cc_v4_key_size];
+    cc_int32                   kvno;
+    cc_int32                   string_to_key_type;
+    cc_time64                  issue_date;
+    cc_int32                   lifetime;
+    cc_uint32                  address;
+    cc_int32                   ticket_size;
+    unsigned char              ticket [cc_v4_ticket_size];
+};      
+typedef struct cci_flat_creds_v4 cci_flat_creds_v4_t;
 
 cc_int32
 cci_creds_v4_marshall( cc_credentials_v4_t * creds, 
index 0d712d666415790949860ae3b6e315c87e0bb92b..182ebc161166f14bdb9e23fbb7ef9e7cca46ecac 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -43,7 +43,7 @@
 
 /*
  * Verifiable, extensible message format.
- *
+ * 
  * Format:
  * <size of header block (header_len)>
  * <size of *entire* message, including previous field (flat_len)>
  * If the header has variable length data it is included in the data blobs. 
  * The header field has the offset from the beginning of the message of the 1st 
  * byte of the data and the length of the data.
- *
  */
 
 #ifndef __CC_MSG_H__
 #define __CC_MSG_H__
 
 #include "CredentialsCache.h"
+#include "generic_lists.h"
 
 struct  cc_msg_t {
     cc_uint32 type;                    /*type of message*/
@@ -87,16 +87,15 @@ enum {
     ccmsg_CTX_RELEASE,
     ccmsg_CTX_GET_CHANGE_TIME,
     ccmsg_CTX_GET_DEFAULT_CCACHE_NAME,
-    ccmsg_CTX_COMPARE,
+    ccmsg_CTX_CCACHE_OPEN,
+    ccmsg_CTX_CCACHE_OPEN_DEFAULT,
+    ccmsg_CTX_CCACHE_CREATE,
+    ccmsg_CTX_CCACHE_CREATE_DEFAULT,
+    ccmsg_CTX_CCACHE_CREATE_UNIQUE,
     ccmsg_CTX_NEW_CCACHE_ITERATOR,
     ccmsg_CTX_LOCK,
     ccmsg_CTX_UNLOCK,
-    ccmsg_CTX_CLONE,
-    ccmsg_CCACHE_OPEN,
-    ccmsg_CCACHE_OPEN_DEFAULT,
-    ccmsg_CCACHE_CREATE,
-    ccmsg_CCACHE_CREATE_DEFAULT,
-    ccmsg_CCACHE_CREATE_UNIQUE,
+    ccmsg_CTX_COMPARE,
     ccmsg_CCACHE_RELEASE,
     ccmsg_CCACHE_DESTROY,
     ccmsg_CCACHE_SET_DEFAULT,
@@ -104,29 +103,28 @@ enum {
     ccmsg_CCACHE_GET_NAME,
     ccmsg_CCACHE_GET_PRINCIPAL,
     ccmsg_CCACHE_SET_PRINCIPAL,
-    ccmsg_CCACHE_CREDS_ITERATOR,
+    ccmsg_CCACHE_NEW_CREDS_ITERATOR,
     ccmsg_CCACHE_STORE_CREDS,
     ccmsg_CCACHE_REM_CREDS,
+    ccmsg_CCACHE_MOVE,
+    ccmsg_CCACHE_LOCK,
+    ccmsg_CCACHE_UNLOCK,
     ccmsg_CCACHE_GET_LAST_DEFAULT_TIME,
     ccmsg_CCACHE_GET_CHANGE_TIME,
-    ccmsg_CCACHE_MOVE,
     ccmsg_CCACHE_COMPARE,
     ccmsg_CCACHE_GET_KDC_TIME_OFFSET,
     ccmsg_CCACHE_SET_KDC_TIME_OFFSET,
     ccmsg_CCACHE_CLEAR_KDC_TIME_OFFSET,
     ccmsg_CCACHE_ITERATOR_RELEASE,
     ccmsg_CCACHE_ITERATOR_NEXT,
-    ccmsg_CCACHE_LOCK,
-    ccmsg_CCACHE_UNLOCK,
+    ccmsg_CCACHE_ITERATOR_CLONE,
     ccmsg_CREDS_ITERATOR_RELEASE,
     ccmsg_CREDS_ITERATOR_NEXT,
-    ccmsg_CREDS_RELEASE,
-    ccmsg_CREDS_V4,
-    ccmsg_CREDS_V5
+    ccmsg_CREDS_ITERATOR_CLONE
 };      
 
 #define CC_MSG_MAX_SIZE        1073741824 /*2^30*/
-#define CC_MSG_MAX_TYPE ccmsg_CREDS_V5
+#define CC_MSG_MAX_TYPE ccmsg_CREDS_ITERATOR_CLONE
 #define BLOB_LEN (sizeof(cc_uint32))
 #define MAGIC_DATA_LEN (sizeof(cc_uint32))
 #define MAGIC_HEAD_LEN (sizeof(cc_uint32))
@@ -143,4 +141,21 @@ cc_int32 cci_msg_verify(void* flat, int flat_len, cc_uint32 * sizep);
 cc_int32 cci_msg_unflatten(void *flat, int flat_len, cc_msg_t** msgpp);
 cc_int32 cci_msg_retrieve_blob(cc_msg_t* msg, cc_uint32 blob_offset, cc_uint32 blob_len, void **);
 cc_int32 cci_msg_destroy(cc_msg_t* msg);
+
+/* Add missing byte swapping macros for 64-bit values */
+#ifdef MAC
+#define htonll(x) OSSwapHostToBigInt64(x)
+#define ntohll(x) OSSwapBigToHostInt64(x)
+#else 
+#ifdef _WIN32
+#ifdef _M_IX86
+#define htonll(x) _byteswap_uint64(x)
+#define ntohll(x) _byteswap_uint64(x)
+#else
+#define htonll(x) (x)
+#define ntohll(x) (x)
+#endif
+#endif
+#endif
+
 #endif /*__CC_MSG_H__*/
index a27c2d2f126e1eb3abbfd64b40efea48b19dee56..b5a9acd6d56439f3f05cb34c6ff88f0a6e091510 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -57,6 +57,8 @@
  * size divisible by 4. This is to ensure correct alignment
  * and stop different compilers from inserting padding bytes in
  * different places.
+ *
+ * All values are stored in network byte order.
  */
 
 struct ccmsg_ctx_only_t {
@@ -81,18 +83,18 @@ struct ccmsg_init_resp_t {
 typedef struct ccmsg_init_t ccmsg_init_t;
 typedef struct ccmsg_init_resp_t ccmsg_init_resp_t;
 
-struct ccmsg_clone_t {
+struct ccmsg_ctx_clone_t {
     cc_handle   ctx;
     cc_uint32  in_version;             /*client API version*/
 };
-struct ccmsg_clone_resp_t {
+struct ccmsg_ctx_clone_resp_t {
     cc_handle  out_ctx;                /*handle on this ctx*/
     cc_uint32  out_version;            /*server API version*/
     cc_uint32  vendor_offset;          /*offset of vendor blob*/
     cc_uint32  vendor_length;          /*length of vendor blob*/
 };      
-typedef struct ccmsg_clone_t ccmsg_clone_t;
-typedef struct ccmsg_clone_resp_t ccmsg_clone_resp_t;
+typedef struct ccmsg_ctx_clone_t ccmsg_ctx_clone_t;
+typedef struct ccmsg_ctx_clone_resp_t ccmsg_ctx_clone_resp_t;
 
 struct ccmsg_ctx_release_t {
     cc_handle  ctx;    /*# of ctx to release*/
@@ -103,7 +105,7 @@ struct ccmsg_ctx_get_change_time_t {
     cc_handle  ctx;
 };
 struct ccmsg_ctx_get_change_time_resp_t {
-    cc_time_t  time;
+    cc_time64  time;
 };
 typedef struct ccmsg_ctx_get_change_time_t ccmsg_ctx_get_change_time_t;
 typedef struct ccmsg_ctx_get_change_time_resp_t ccmsg_ctx_get_change_time_resp_t;
@@ -304,7 +306,7 @@ struct ccmsg_ccache_get_last_default_time_t {
     cc_handle  ccache;
 };
 struct ccmsg_ccache_get_last_default_time_resp_t {
-    cc_time_t  last_default_time;
+    cc_time64  last_default_time;
 };
 typedef struct ccmsg_ccache_get_last_default_time_t ccmsg_ccache_get_last_default_time_t;
 typedef struct ccmsg_ccache_get_last_default_time_resp_t ccmsg_ccache_get_last_default_time_resp_t;
@@ -314,7 +316,7 @@ struct ccmsg_ccache_get_change_time_t {
     cc_handle  ccache;
 };
 struct ccmsg_ccache_get_change_time_resp_t {
-    cc_time_t  time;
+    cc_time64  time;
 };
 typedef struct ccmsg_ccache_get_change_time_t ccmsg_ccache_get_change_time_t;
 typedef struct ccmsg_ccache_get_change_time_resp_t ccmsg_ccache_get_change_time_resp_t;
@@ -336,7 +338,7 @@ struct ccmsg_ccache_get_kdc_time_offset_t {
     cc_int32    creds_version;
 };      
 struct ccmsg_ccache_get_kdc_time_offset_resp_t {
-    cc_time_t  offset;
+    cc_time64  offset;
 };
 typedef struct ccmsg_ccache_get_kdc_time_offset_t ccmsg_ccache_get_kdc_time_offset_t;
 typedef struct ccmsg_ccache_get_kdc_time_offset_resp_t ccmsg_ccache_get_kdc_time_offset_resp_t;
@@ -344,7 +346,7 @@ typedef struct ccmsg_ccache_get_kdc_time_offset_resp_t ccmsg_ccache_get_kdc_time
 struct ccmsg_ccache_set_kdc_time_offset_t {
     cc_handle  ctx;
     cc_handle  ccache;
-    cc_time_t  offset;
+    cc_time64  offset;
     cc_int32    creds_version;
 };
 typedef struct ccmsg_ccache_set_kdc_time_offset_t ccmsg_ccache_set_kdc_time_offset_t;
@@ -372,6 +374,16 @@ struct ccmsg_ccache_iterator_next_resp_t {
 typedef struct ccmsg_ccache_iterator_next_t ccmsg_ccache_iterator_next_t;
 typedef struct ccmsg_ccache_iterator_next_resp_t ccmsg_ccache_iterator_next_resp_t;
 
+struct ccmsg_ccache_iterator_clone_t {
+    cc_handle   ctx;
+    cc_handle  iterator;
+};
+struct ccmsg_ccache_iterator_clone_resp_t {
+    cc_handle  iterator;
+};      
+typedef struct ccmsg_ccache_iterator_clone_t ccmsg_ccache_iterator_clone_t;
+typedef struct ccmsg_ccache_iterator_clone_resp_t ccmsg_ccache_iterator_clone_resp_t;
+
 struct ccmsg_creds_iterator_release_t {
     cc_handle  ctx;
     cc_handle  ccache;
@@ -393,37 +405,14 @@ struct ccmsg_creds_iterator_next_resp_t {
 typedef struct ccmsg_creds_iterator_next_t ccmsg_creds_iterator_next_t;
 typedef struct ccmsg_creds_iterator_next_resp_t ccmsg_creds_iterator_next_resp_t;
 
-struct ccmsg_creds_v4_t {
-    cc_uint32 offset;
-    cc_uint32 len;
-};
-typedef struct ccmsg_creds_v4_t ccmsg_creds_v4_t;
-
-struct ccmsg_creds_v5_t {
-    cc_uint32 client_offset;
-    cc_uint32 client_len;
-    cc_uint32 server_offset;
-    cc_uint32 server_len;
-    cc_uint32 keyblock_offset;
-    cc_uint32 keyblock_len;
-    cc_time_t authtime;
-    cc_time_t starttime;
-    cc_time_t endtime;
-    cc_time_t renewtime;
-    cc_uint32 is_skey;
-    cc_uint32 ticket_flags;
-    cc_uint32 address_count;
-    cc_uint32 address_offset;
-    cc_uint32 address_len;
-    cc_uint32 ticket_offset;
-    cc_uint32 ticket_len;
-    cc_uint32 ticket2_offset;
-    cc_uint32 ticket2_len;
-    cc_uint32 authdata_count;
-    cc_uint32 authdata_offset;
-    cc_uint32 authdata_len;
-};
-typedef struct ccmsg_creds_v5_t ccmsg_creds_v5_t;
-
+struct ccmsg_creds_iterator_clone_t {
+    cc_handle   ctx;
+    cc_handle  iterator;
+};
+struct ccmsg_creds_iterator_clone_resp_t {
+    cc_handle  iterator;
+};      
+typedef struct ccmsg_creds_iterator_clone_t ccmsg_creds_iterator_clone_t;
+typedef struct ccmsg_creds_iterator_clone_resp_t ccmsg_creds_iterator_clone_resp_t;
 
 #endif /*__MSG_HEADERS_H__*/
diff --git a/src/lib/ccapi/marshall.c b/src/lib/ccapi/marshall.c
deleted file mode 100644 (file)
index 7027d65..0000000
+++ /dev/null
@@ -1,378 +0,0 @@
-/* $Copyright:
- *
- * Copyright 2004 by the Massachusetts Institute of Technology.
- * 
- * All rights reserved.
- * 
- * Export of this software from the United States of America may require a
- * specific license from the United States Government.  It is the
- * responsibility of any person or organization contemplating export to
- * obtain such a license before exporting.
- * 
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute
- * this software and its documentation for any purpose and without fee is
- * hereby granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission notice
- * appear in supporting documentation, and that the name of M.I.T. not be
- * used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.  Furthermore if you
- * modify this software you must label your software as modified software
- * and not distribute it in such a fashion that it might be confused with
- * the original MIT software. M.I.T. makes no representations about the
- * suitability of this software for any purpose.  It is provided "as is"
- * without express or implied warranty.
- * 
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- * 
- * Individual source code files are copyright MIT, Cygnus Support,
- * OpenVision, Oracle, Sun Soft, FundsXpress, and others.
- * 
- * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,
- * and Zephyr are trademarks of the Massachusetts Institute of Technology
- * (MIT).  No commercial use of these trademarks may be made without prior
- * written permission of MIT.
- * 
- * "Commercial use" means use of a name in a product or other for-profit
- * manner.  It does NOT prevent a commercial firm from referring to the MIT
- * trademarks in order to convey information (although in doing so,
- * recognition of their trademark status should be given).
- * $
- */
-
-/* marshall.c */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <CredentialsCache.h>
-#include "msg.h"
-#include "msg_headers.h"
-#include "marshall.h"
-
-cc_int32
-cci_creds_v4_marshall( cc_credentials_v4_t * creds, 
-                       char ** flat, 
-                       cc_uint32 * len)
-{
-    cc_msg_t *  msg;
-    ccmsg_creds_v4_t * header;
-    cc_uint32   blob_pos;
-    cc_int32    code;
-
-    if ( creds == NULL || flat == NULL || len == NULL )
-        return ccErrBadParam;
-
-    header = (ccmsg_creds_v4_t *)malloc(sizeof(ccmsg_creds_v4_t));
-    if ( header == NULL )
-        return ccErrNoMem;
-
-    code = cci_msg_new(ccmsg_CREDS_V4, &msg);
-
-    code = cci_msg_add_header(msg, header, sizeof(ccmsg_creds_v4_t));
-
-    code = cci_msg_add_data_blob(msg, creds, sizeof(cc_credentials_v4_t), &blob_pos);
-
-    header->offset = blob_pos;
-    header->len    = sizeof(cc_credentials_v4_t);
-
-    code = cci_msg_flatten( msg, NULL );
-
-    *flat = msg->flat;
-    *len  = msg->flat_len;
-    msg->flat = NULL;
-    msg->flat_len = 0;
-
-    cci_msg_destroy(msg);
-
-    return ccNoError;
-}
-
-cc_int32
-cci_creds_v4_unmarshall( char * flat, 
-                         cc_uint32 len,
-                         cc_credentials_union * creds)
-{
-    cc_msg_t * msg; 
-    ccmsg_creds_v4_t * header;
-    cc_int32   code;
-
-    if ( flat == NULL || len == 0 || creds == NULL )
-        return ccErrBadParam;
-
-    code = cci_msg_unflatten( flat, len, &msg );
-
-    header = (ccmsg_creds_v4_t *)msg->header;
-
-    creds->version = cc_credentials_v4;
-    code = cci_msg_retrieve_blob(msg, header->offset, header->len, &creds->credentials.credentials_v4);
-
-    cci_msg_destroy(msg);
-
-    return ccNoError;
-}
-
-
-cc_int32
-cci_creds_cc_data_array_count_entries( cc_data ** array, cc_uint32 * pcount)
-{
-    cc_uint32 count;
-
-    if (array == NULL) {
-        *pcount = 0;
-        return ccNoError;
-    }
-
-    for ( count=0; array[count] != NULL ; count++) ;
-
-    *pcount = count;
-    return ccNoError;
-}
-
-cc_int32
-cci_creds_v5_compute_flat_size( cc_credentials_v5_t * creds, cc_uint32 * plen)
-{
-    cc_uint32 len;
-    cc_uint32 i, count;
-
-    len = sizeof(struct cci_flat_creds_v5);
-
-    if (creds->client)
-        len += strlen(creds->client) + 1;
-
-    if (creds->server)
-        len += strlen(creds->server) + 1;
-
-    len += creds->keyblock.length;
-
-    cci_creds_cc_data_array_count_entries( creds->addresses, &count );
-    len += count * sizeof(cc_flat_data);
-    for ( i=0; i<count; i++ ) {
-        len += creds->addresses[i]->length;
-    }
-
-    len += creds->ticket.length;
-    len += creds->second_ticket.length;
-
-    cci_creds_cc_data_array_count_entries( creds->authdata, &count );
-    len += count * sizeof(cc_flat_data);
-    for ( i=0; i<count; i++ ) {
-        len += creds->authdata[i]->length;
-    }
-
-    *plen = len;
-    return ccNoError;
-}
-
-cc_int32
-cci_creds_v5_marshall( cc_credentials_v5_t * creds, 
-                       char ** pflat, 
-                       cc_uint32 * plen)
-{
-    cc_uint32 len;
-    char * flat;
-    struct cci_flat_creds_v5 * header;
-    cc_uint32 offset;
-    cc_uint32 i;
-
-    if ( creds == NULL || pflat == NULL || plen == NULL )
-        return ccErrBadParam;
-
-    cci_creds_v5_compute_flat_size(creds, &len);
-
-    flat = (char *)malloc(len);
-    if ( flat == NULL )
-        return ccErrNoMem;
-    memset(flat, 0, len);
-
-    offset = sizeof(struct cci_flat_creds_v5);
-    header = (struct cci_flat_creds_v5 *)flat;
-    header->version = FLAT_CREDS_V5_VERSION;
-    if (creds->client) {
-        header->client.length = strlen(creds->client) + 1;
-        header->client.data = offset;
-        memcpy(flat + offset, creds->client, header->client.length);
-        offset += header->client.length;
-    }
-
-    if (creds->server) {
-        header->server.length = strlen(creds->server) + 1;
-        header->server.data = offset;
-        memcpy(flat + offset, creds->server, header->server.length);
-        offset += header->server.length;
-    }
-
-    header->keyblock.type = creds->keyblock.type;
-    if (creds->keyblock.length) {
-        header->keyblock.length = creds->keyblock.length;
-        header->keyblock.data = offset;
-        memcpy(flat + offset, creds->keyblock.data, header->keyblock.length);
-        offset += header->keyblock.length;
-    }           
-
-    header->authtime = creds->authtime;
-    header->starttime = creds->starttime;
-    header->endtime = creds->endtime;
-    header->renew_till = creds->renew_till;
-    header->is_skey = creds->is_skey;
-    header->ticket_flags = creds->ticket_flags;
-
-    cci_creds_cc_data_array_count_entries( creds->addresses, &header->address_count );
-    if ( header->address_count ) {
-        cc_flat_data * addresses = (cc_flat_data *)flat + offset;
-        header->addresses = offset;
-        offset += header->address_count * sizeof(cc_flat_data);
-
-        for ( i=0; i<header->address_count; i++ ) {
-            addresses[i].type = creds->addresses[i]->type;
-            if (creds->addresses[i]->length) {
-                addresses[i].length = creds->addresses[i]->length;
-                addresses[i].data = offset;
-                memcpy(flat + offset, creds->addresses[i]->data, addresses[i].length);
-                offset += addresses[i].length;
-            }
-        }
-    }
-
-    header->ticket.type = creds->ticket.type;
-    if (creds->ticket.length) {
-        header->ticket.length = creds->ticket.length;
-        header->ticket.data = offset;
-        memcpy(flat + offset, creds->ticket.data, header->ticket.length);
-        offset += header->ticket.length;
-    }           
-
-    header->second_ticket.type = creds->second_ticket.type;
-    if (creds->second_ticket.length) {
-        header->second_ticket.length = creds->second_ticket.length;
-        header->second_ticket.data = offset;
-        memcpy(flat + offset, creds->second_ticket.data, header->second_ticket.length);
-        offset += header->second_ticket.length;
-    }           
-
-    cci_creds_cc_data_array_count_entries( creds->authdata, &header->authdata_count );
-    if ( header->authdata_count ) {
-        cc_flat_data * authdata = (cc_flat_data *)flat + offset;
-        header->authdata = offset;
-        offset += header->authdata_count * sizeof(cc_flat_data);
-
-        for ( i=0; i<header->authdata_count; i++ ) {
-            authdata[i].type = creds->authdata[i]->type;
-            if (creds->authdata[i]->length) {
-                authdata[i].length = creds->authdata[i]->length;
-                authdata[i].data = offset;
-                memcpy(flat + offset, creds->authdata[i]->data, authdata[i].length);
-                offset += authdata[i].length;
-            }
-        }
-    }
-
-    *pflat = flat;
-    *plen = len;
-    return ccNoError;
-}
-
-
-// TODO: a much better job of checking for out of memory errors
-//       and validating that we do not read beyond the flat input
-//       data buffer
-
-cc_int32
-cci_creds_v5_unmarshall( char * flat, 
-                         cc_uint32 len,
-                         cc_credentials_union * creds_union)
-{
-    struct cci_flat_creds_v5 * header;
-    cc_credentials_v5_t * creds;
-    cc_flat_data * flat_data;
-    cc_uint32  i;
-    cc_int32   code;
-
-    if ( flat == NULL || len == 0 || creds_union == NULL )
-        return ccErrBadParam;
-
-    creds_union->version = cc_credentials_v5;
-
-    header = (struct cci_flat_creds_v5 *)flat;
-
-    if ( header->version != FLAT_CREDS_V5_VERSION )
-        return ccErrBadParam;
-
-    creds = (cc_credentials_v5_t *)malloc(sizeof(cc_credentials_v5_t));
-    if ( creds == NULL )
-        return ccErrNoMem;
-    memset(creds, 0, sizeof(ccmsg_creds_v5_t));
-
-    if ( header->client.length ) {
-        creds->client = (char *)malloc(header->client.length);
-        memcpy(creds->client, flat + header->client.data, header->client.length);
-    }
-
-    if ( header->server.length ) {
-        creds->server = (char *)malloc(header->server.length);
-        memcpy(creds->server, flat + header->server.data, header->server.length);
-    }
-
-    creds->keyblock.type = header->keyblock.type;
-    if ( header->keyblock.length ) {
-        creds->keyblock.length = header->keyblock.length;
-        creds->keyblock.data = malloc(creds->keyblock.length);
-        memcpy(creds->keyblock.data, flat + header->keyblock.data, creds->keyblock.length);
-    }
-
-    creds->authtime = header->authtime;
-    creds->starttime = header->starttime;
-    creds->endtime = header->endtime;
-    creds->renew_till = header->renew_till;
-    creds->is_skey = header->is_skey;
-    creds->ticket_flags = header->ticket_flags;
-
-    creds->addresses = (cc_data **) malloc((header->address_count + 1) * sizeof(cc_data *));
-    flat_data = (cc_flat_data *)flat + header->addresses;
-    for ( i=0 ; i < header->address_count ; i++ ) {
-        creds->addresses[i] = (cc_data *)malloc(sizeof(cc_data));
-        creds->addresses[i]->type = flat_data[i].type;
-        creds->addresses[i]->length = flat_data[i].length;
-        if ( flat_data[i].length ) {
-            creds->addresses[i]->data = malloc(flat_data[i].length);
-            memcpy(creds->addresses[i]->data, flat + flat_data[i].data, flat_data[i].length);
-        } else {
-            creds->addresses[i]->data = NULL;
-        }
-    }
-    creds->addresses[i] = NULL;
-
-    creds->ticket.type = header->ticket.type;
-    if ( header->ticket.length ) {
-        creds->ticket.length = header->ticket.length;
-        creds->ticket.data = malloc(creds->ticket.length);
-        memcpy(creds->ticket.data, flat + header->ticket.data, creds->ticket.length);
-    }
-
-    creds->second_ticket.type = header->second_ticket.type;
-    if ( header->second_ticket.length ) {
-        creds->second_ticket.length = header->second_ticket.length;
-        creds->second_ticket.data = malloc(creds->second_ticket.length);
-        memcpy(creds->second_ticket.data, flat + header->second_ticket.data, creds->second_ticket.length);
-    }
-
-    creds->authdata = (cc_data **) malloc((header->authdata_count + 1) * sizeof(cc_data *));
-    flat_data = (cc_flat_data *)flat + header->authdata;
-    for ( i=0 ; i < header->authdata_count ; i++ ) {
-        creds->authdata[i] = (cc_data *)malloc(sizeof(cc_data));
-        creds->authdata[i]->type = flat_data[i].type;
-        creds->authdata[i]->length = flat_data[i].length;
-        if ( flat_data[i].length ) {
-            creds->authdata[i]->data = malloc(flat_data[i].length);
-            memcpy(creds->authdata[i]->data, flat + flat_data[i].data, flat_data[i].length);
-        } else {
-            creds->authdata[i]->data = NULL;
-        }
-    }
-    creds->authdata[i] = NULL;
-
-    creds_union->credentials.credentials_v5 = creds;
-
-    return ccNoError;
-}
-
index 671b6905f24961f5b5ab2372a5db79d55791e360..b221bcb9413eefa0dfca8eac8f2d8ecc11542ceb 100644 (file)
@@ -4,23 +4,11 @@
 
 CFLAGS = -I../include
 
-CCAPI_LIB = ../lib/ccapi.lib
+CCAPI_LIB = ../client/ccapi.lib
 WINLIBS = user32.lib advapi32.lib
-CCSOBJS = context.obj ccache.obj lists.obj rpc_auth.obj serv_ops.obj
+CCSOBJS = ccs_context.obj ccs_ccache.obj ccs_lists.obj rpc_auth.obj serv_ops.obj
 
-all: t_lists.exe t_msg.exe t_ccache.exe t_context.exe ccapi_server.exe
-
-t_lists.exe: t_lists.obj $(CCSOBJS) $(CCAPI_LIB)
-        link -out:$@ t_lists.obj $(CCSOBJS) $(CCAPI_LIB) $(WINLIBS)
-
-t_msg.exe: t_msg.obj $(CCSOBJS) $(CCAPI_LIB)
-        link -out:$@ t_msg.obj $(CCSOBJS) $(CCAPI_LIB) $(WINLIBS)
-
-t_ccache.exe: t_ccache.obj $(CCSOBJS) $(CCAPI_LIB)
-        link -out:$@ t_ccache.obj $(CCSOBJS) $(CCAPI_LIB) $(WINLIBS)
-
-t_context.exe: t_context.obj $(CCSOBJS) $(CCAPI_LIB)
-        link -out:$@ t_context.obj $(CCSOBJS) $(CCAPI_LIB) $(WINLIBS)
+all: ccapi_server.exe
 
 ccapi_server.exe: main.obj $(CCSOBJS) $(CCAPI_LIB)
         link -out:$@ main.obj $(CCSOBJS) $(CCAPI_LIB) $(WINLIBS)
similarity index 83%
rename from src/lib/ccapi/server/ccache.c
rename to src/lib/ccapi/server/ccs_ccache.c
index 2c3a745afef010c9d131866ba88beb85203eda14..d632ee349413280d3aa45ddbb4f7eded3a4e5a9e 100644 (file)
-/* $Copyright:
- *
- * Copyright 2004 by the Massachusetts Institute of Technology.
- * 
- * All rights reserved.
- * 
- * Export of this software from the United States of America may require a
- * specific license from the United States Government.  It is the
- * responsibility of any person or organization contemplating export to
- * obtain such a license before exporting.
- * 
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute
- * this software and its documentation for any purpose and without fee is
- * hereby granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission notice
- * appear in supporting documentation, and that the name of M.I.T. not be
- * used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.  Furthermore if you
- * modify this software you must label your software as modified software
- * and not distribute it in such a fashion that it might be confused with
- * the original MIT software. M.I.T. makes no representations about the
- * suitability of this software for any purpose.  It is provided "as is"
- * without express or implied warranty.
- * 
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- * 
- * Individual source code files are copyright MIT, Cygnus Support,
- * OpenVision, Oracle, Sun Soft, FundsXpress, and others.
- * 
- * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,
- * and Zephyr are trademarks of the Massachusetts Institute of Technology
- * (MIT).  No commercial use of these trademarks may be made without prior
- * written permission of MIT.
- * 
- * "Commercial use" means use of a name in a product or other for-profit
- * manner.  It does NOT prevent a commercial firm from referring to the MIT
- * trademarks in order to convey information (although in doing so,
- * recognition of their trademark status should be given).
- * $
- */
-
-/*
- * Manages ccache objects.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include "CredentialsCache.h"
-#include "datastore.h"
-
-/**
- * ccache_new()
- * 
- * Purpose: Allocate and initialize new credentials cache for the specified principal
- *          and version
- * 
- * Return:  ccNoError - success
- *          ccErrInvalidString - name or principal is NULL
- *          ccErrBadCredentialsVersion - unsupported creds type
- *          ccErrBadParam - outCcachepp is NULL
- *          ccErrNoMem - malloc failed
- */
-cc_int32
-cci_ccache_new( char *name, char *principal, int cred_vers, 
-                cc_server_ccache_t** outCCachepp)
-{
-    cc_server_ccache_t* ccache;
-
-    if (name == NULL || principal == NULL)
-        return ccErrInvalidString;
-
-    if (cred_vers != cc_credentials_v4 && cred_vers != cc_credentials_v5 && 
-         cred_vers != cc_credentials_v4_v5)
-        return ccErrBadCredentialsVersion;
-
-    if (outCCachepp == NULL)
-        return ccErrBadParam;
-
-    ccache = (cc_server_ccache_t*)malloc(sizeof(cc_server_ccache_t));
-    if (ccache == NULL)
-        return ccErrNoMem;
-
-    ccache->name = name;
-    ccache->principal_v4 = NULL;
-    ccache->principal_v5 = NULL;
-    ccache->changed = time(NULL);
-    ccache->kdc_offset = 0;
-    ccache->last_default = 0;
-    cci_generic_list_new(&ccache->active_iterators);
-    cci_credentials_list_new(&ccache->creds);
-    ccache->is_default = 0;
-    ccache->kdc_set = 0;
-    ccache->versions = cred_vers;
-    ccache->mycontext = NULL;
-
-    cci_ccache_set_principal(ccache, cred_vers, principal);
-    *outCCachepp = ccache;
-    return ccNoError;
-}
-
-/**
- * cci_ccache_check_version()
- * 
- * Purpose: Check to see if the ccache and the creds have compatible versions. 
- * 
- * Return:  ccNoError and compat = 1 if they are compatible 
- *          ccNoError and compat = 0 if they are not compatible
- * 
- * Errors:  ccErrInvalidCCache - ccache is NULL
- *          ccErrBadParam - either creds or compat are NULL
- */
-cc_int32 
-cci_ccache_check_version( const cc_server_ccache_t *ccache,
-                          const cc_credentials_union* creds,
-                          cc_uint32* compat)
-{
-    if (ccache == NULL)
-        return ccErrInvalidCCache;
-
-    if (creds == NULL || compat == NULL)
-        return ccErrBadParam;
-
-    if (ccache->versions == cc_credentials_v4_v5)
-        *compat = 1;
-    else if (ccache->versions == creds->version)
-        *compat = 1;
-    else
-        *compat = 0;
-
-    return ccNoError;
-}
-
-/** 
-cci_ccache_check_principal()
-
-Check to see if the client principal from the credentials matches
-the principal associated with the cache.
-
-* Return:  ccNoError and compat = 1 if they are compatible 
-*          ccNoError and compat = 0 if they are not compatible
-* 
-* Errors:  ccErrInvalidCCache - ccache is NULL
-*          ccErrBadParam - either creds or compat are NULL
-*          ccErrBadCredentialVersion - unsupported credential type
-*/
-cc_int32 
-cci_ccache_check_principal( const cc_server_ccache_t *ccache,
-                            const cc_credentials_union* creds,
-                            cc_uint32* compat)
-{
-    if (ccache == NULL)
-        return ccErrInvalidCCache;
-
-    if (creds == NULL || compat == NULL)
-        return ccErrBadParam;
-
-    if (creds->version == cc_credentials_v4) {
-        if (strcmp(creds->credentials.credentials_v4->principal, ccache->principal_v4) == 0) 
-            *compat = 1;
-        else 
-            *compat = 0;
-    } else if (creds->version == cc_credentials_v5) {
-        if (strcmp(creds->credentials.credentials_v5->client, ccache->principal_v5) == 0)
-            *compat = 1;
-        else 
-            *compat = 0;
-    } else {        
-        return ccErrBadCredentialsVersion;
-    }
-    return ccNoError;
-}
-
-
-/** 
- * cci_ccache_store_creds()
- *
- * Purpose: Stores the provided credentials into the provided cache.  Validates the
- *          ability of the cache to store credentials of the given version and client
- *          principal.
- *
- * Return:  0 on success
- *         -1 on error
- *
- * Errors: ccErrNoMem
- *         ccErrBadCredentialsVersion
- *         ccErrBadInvalidCredentials
- *         ccErrInvalidCache
- *         ccErrBadParam
- */
-cc_int32 
-cci_ccache_store_creds(cc_server_ccache_t *ccache, const cc_credentials_union* credentials) 
-{
-    cc_server_credentials_t* stored_cred=NULL;
-    cc_uint32 valid_version, valid_principal;
-    cc_int32 code;
-
-    if (ccache == NULL)
-        return ccErrInvalidCCache;
-    
-    if (credentials == NULL)
-        return ccErrBadParam;
-
-    code = cci_ccache_check_version(ccache, credentials, &valid_version);
-    if (code != ccNoError) {
-        /* pass error on to caller */
-        goto bad;
-    }
-    code = cci_ccache_check_principal(ccache, credentials, &valid_principal);
-    if (code != ccNoError) {
-        /* pass error on to caller */
-        goto bad;
-    }
-    if (valid_version && valid_principal) {
-        stored_cred = (cc_server_credentials_t*)malloc(sizeof(cc_server_credentials_t));
-        if (stored_cred == NULL) {
-            code = ccErrNoMem;
-            goto bad;
-        }
-        memcpy(&stored_cred->creds, credentials, sizeof(cc_credentials_union));
-
-        if (credentials->version == cc_credentials_v4) {
-            stored_cred->creds.credentials.credentials_v4 = (cc_credentials_v4_t*)malloc(sizeof(cc_credentials_v4_t));
-            if (stored_cred->creds.credentials.credentials_v4 == NULL) {
-                code = ccErrNoMem;
-                goto bad;
-            }
-
-            memcpy(stored_cred->creds.credentials.credentials_v4, credentials->credentials.credentials_v4, sizeof(cc_credentials_v4_t));
-        } else if (credentials->version == cc_credentials_v5) {
-            stored_cred->creds.credentials.credentials_v5 = (cc_credentials_v5_t*)malloc(sizeof(cc_credentials_v5_t));
-            if (stored_cred->creds.credentials.credentials_v5 == NULL) {
-                code = ccErrNoMem;
-                goto bad;
-            }
-
-            memcpy(stored_cred->creds.credentials.credentials_v5, credentials->credentials.credentials_v5, sizeof(cc_credentials_v5_t));
-        } else {
-            code = ccErrBadCredentialsVersion;
-            goto bad;
-        }
-
-        code = cci_credentials_list_append(ccache->creds, stored_cred, NULL);
-        if ( code != ccNoError ) {
-            /* pass error on to caller */
-            goto bad;
-        }
-        if (ccache->creds->head->data == (cc_uint8 *)stored_cred) 
-            stored_cred->is_default = 1; /*we're first on the list, so we're default*/
-
-        cci_ccache_changed(ccache);
-        return ccNoError;
-    } else {
-#ifdef DEBUG
-        printf("vers: %d\tprincipal: %d\n",
-                valid_version, valid_principal);
-#endif /* DEBUG */
-        code = ccErrInvalidCredentials;
-        goto bad;
-    }
-
-  bad:
-    if (stored_cred)
-        free(stored_cred);
-    return code;      /* error */
-}
-
-/**
- * cci_ccache_changed()
- *
- * Purpose: Updates the last update time for the ccache and its associated context.
- *          Provides a location from which interested parties should be notified
- *          of cache updates.
- *
- * Return:  none
- *
- * Errors:  none
- */
-void 
-cci_ccache_changed(cc_server_ccache_t* ccache) 
-{
-    ccache->changed = time(NULL);
-    if (ccache->mycontext != NULL)
-        ccache->mycontext->changed = time(NULL);
-
-    /* XXX - notify registered listeners when implemented */
-}
-
-/**
- * cci_ccache_rem_creds()
- *
- * Purpose: Removes the specified credential object from the specified cache if
- *          it exists
- *
- * Return:  0 on success (credential is not in the cache)
- *         -1 on error
- *
- * Errors: ccErrBadParam, ccErrNoMem (from cc_credentials_list_iterator)
- *
- * Verify: does the memory associated with stored_cred->creds need to be freed?
- *
- */
-cc_int32 
-cci_ccache_rem_creds(cc_server_ccache_t *ccache, const cc_credentials_union* credentials) 
-{
-    cc_credentials_iterate_t* credentials_iterator=NULL, *active;
-    cc_generic_iterate_t* generic_iterator=NULL;
-    cc_credentials_list_node_t* credentials_node;
-    cc_generic_list_node_t* generic_node;
-    cc_server_credentials_t* stored_cred;
-    cc_int8 changed = 0;
-    cc_int32 code = 0;
-
-    if (ccache == NULL)
-        return ccErrInvalidCCache;
-
-    if (credentials == NULL)
-        return ccErrBadParam;
-
-    code = cci_credentials_list_iterator(ccache->creds, &credentials_iterator);
-    if (code != ccNoError) {
-        /* pass error to caller */
-        goto cleanup;
-    }
-
-    while (cci_credentials_iterate_has_next(credentials_iterator)) {
-        code = cci_credentials_iterate_next(credentials_iterator, &credentials_node);
-        stored_cred = (cc_server_credentials_t*)credentials_node->data;
-        if (memcmp(&stored_cred->creds,credentials,sizeof(cc_credentials_union)) == 0) {
-            /* XXX - do we need to free(stored_cred->creds) ? */
-            free(credentials_node->data);
-            changed = 1;
-               
-            /*If any iterator's next points to the deleted node, make it point to the next node*/
-            code = cci_generic_list_iterator(ccache->active_iterators, &generic_iterator);
-            while (cci_generic_iterate_has_next(generic_iterator)) {
-                code = cci_generic_iterate_next(generic_iterator, &generic_node);                      
-                active = (cc_credentials_iterate_t*)generic_node->data;
-                if (active->next == credentials_node) 
-                    active->next = active->next->next;
-            }
-            code = cci_generic_free_iterator(generic_iterator);
-            generic_iterator = NULL;
-
-            if (credentials_node == ccache->creds->head) { /*removing the default, must make next cred default*/
-                code = cci_credentials_list_remove_element(ccache->creds, credentials_node);
-
-                if (ccache->creds->head != NULL)
-                    ((cc_server_credentials_t*)ccache->creds->head->data)->is_default = 1;
-            } else {
-                code = cci_credentials_list_remove_element(ccache->creds, credentials_node);
-            }
-            break;
-        }
-    }
-
-  cleanup:
-    if (changed)
-        cci_ccache_changed(ccache);
-    if (credentials_iterator)
-        cci_credentials_free_iterator(credentials_iterator);
-    if (generic_iterator)
-        cci_generic_free_iterator(generic_iterator);
-    return code;
-}
-
-/**
- * cci_ccache_move()
- * 
- * Purpose: Destroys the existing contents of the destination and copies
- *          all credentials from the source to the destination
- *
- * Return:  0 on success
- *         -1 on error
- *
- * Errors:  ccBadNoMem
- *
- */
-
-cc_int32 
-cci_ccache_move(cc_server_ccache_t *source, cc_server_ccache_t* destination) 
-{
-    cc_generic_list_node_t* node;
-    cc_generic_iterate_t* iterator;
-    cc_credentials_iterate_t* cur;
-    cc_int32 code;
-
-    if (source == NULL || destination == NULL)
-        return ccErrBadParam;
-       
-    code = cci_credentials_list_destroy(destination->creds);
-    if ( code != ccNoError )
-        return code;
-
-    code = cci_credentials_list_copy(source->creds, &destination->creds);
-    if ( code != ccNoError ) 
-        return code;
-
-    destination->versions = source->versions;
-    destination->kdc_offset = source->kdc_offset;
-    destination->last_default = 0;
-
-    /*reset all active iterators to point to the head of the new creds list*/
-    if (destination->active_iterators->head != NULL) {
-        code = cci_generic_list_iterator(destination->active_iterators, &iterator);
-        while (cci_generic_iterate_has_next(iterator)) {
-            code = cci_generic_iterate_next(iterator, &node);
-            cur = (cc_credentials_iterate_t*)node->data;
-            cur->next = destination->creds->head;
-        }
-        code = cci_generic_free_iterator(iterator);
-    }
-
-    cci_ccache_changed(destination);
-    return code;
-}
-
-/**
- * cci_ccache_get_kdc_time_offset()
- * 
- * Purpose: Retrieves the kdc_time_offset from the ccache if set
- *
- * Return:  0 on success
- *         -1 on error
- *
- * Errors:  ccErrBadParam, ccErrTimeOffsetNotSet
- *
- */
-cc_int32 
-cci_ccache_get_kdc_time_offset(cc_server_ccache_t* ccache, cc_time_t* offset) 
-{
-    if (ccache == NULL)
-        return ccErrInvalidCCache;
-    
-    if (offset == NULL)
-        return ccErrBadParam;
-
-    if (!ccache->kdc_set)
-        return ccErrTimeOffsetNotSet;
-
-    *offset = ccache->kdc_offset;
-    return ccNoError;
-}
-
-/**
- * cci_ccache_set_kdc_time_offset()
- *
- * Purpose: Sets the kdc time offset in the designated ccache
- * 
- * Return:  0 on success
- *         -1 on error
- * 
- * Errors: ccErrBadParam
- *
- */
-cc_int32 
-cci_ccache_set_kdc_time_offset(cc_server_ccache_t* ccache, cc_time_t offset) 
-{
-    if (ccache == NULL)
-        return ccErrInvalidCCache;
-
-    ccache->kdc_offset = offset;
-    ccache->kdc_set = 1;
-    cci_ccache_changed(ccache);
-
-    return ccNoError;
-}
-
-/**
- * cci_ccache_clear_kdc_time_offset()
- *
- * Purpose: Clear the kdc time offset in the designated ccache
- *
- * Return:  0 on success
- *         -1 on error
- *
- * Errors: ccErrBadParam
- */
-cc_int32 
-cci_ccache_clear_kdc_time_offset(cc_server_ccache_t* ccache) 
-{
-    if (ccache == NULL)
-        return ccErrInvalidCCache;
-
-    ccache->kdc_offset = 0;
-    ccache->kdc_set = 0;
-    cci_ccache_changed(ccache);
-
-    return ccNoError;
-}
-
-/**
- * cci_ccache_new_iterator()
- *
- * Purpose: Retrieve an iterator for the designated cache
- *
- * Return:  0 on success
- *         -1 on error
- *
- * Errors: ccErrBadParam, ccBadNoMem
- */
-cc_int32 
-cci_ccache_new_iterator(cc_server_ccache_t* ccache, cc_credentials_iterate_t** iterator)
-{
-    cc_int32 code;
-
-    if (ccache == NULL)
-        return ccErrInvalidCCache;
-
-    if (iterator == NULL)
-        return ccErrBadParam;
-
-    code = cci_credentials_list_iterator(ccache->creds, iterator);
-    if (code != ccNoError)
-        return code;
-
-    code = cci_generic_list_prepend(ccache->active_iterators, *iterator, sizeof(cc_credentials_iterate_t), NULL);
-    if (code != ccNoError)
-        return code;
-
-    return ccNoError;
-}
-
-/**
- * cci_ccache_get_principal()
- * 
- * Purpose: Retrieves the client principal associated with the designated cache.
- *          The value is returned 
- * Return:
- *
- * Errors:
- */
-cc_int32 
-cci_ccache_get_principal(cc_server_ccache_t* ccache, cc_int32 version, char ** principal) 
-{
-    char *p = NULL;
-    
-    switch ( version ) {
-    case cc_credentials_v4:
-        p = ccache->principal_v4;
-        break;
-    case cc_credentials_v5:
-        p = ccache->principal_v5;
-        break;
-    default:
-        return ccErrBadCredentialsVersion;
-    }
-
-    *principal = (char *)malloc(strlen(p)+1);
-    if ( *principal == NULL )
-        return ccErrNoMem;
-
-    strcpy(*principal, p);
-    return ccNoError;
-}
-
-/**
- * Purpose: Releases the memory associated with a ccache principal
- * 
- * Return:
- *
- * Errors:
- *
- */
-cc_int32
-cci_ccache_free_principal(char * principal)
-{
-    if ( principal == NULL )
-        return ccErrBadParam;
-
-    free(principal);
-    return ccNoError;
-}
-
-/**
- * ccache_set_principal()
- *
- * Purpose: Assigns a principal to the designated ccache and credential version.
- *          If the api version is 2, the cache is cleared of all existing
- *          credentials.
- *
- * Return:  0 on success
- *         -1 on error
- *
- * Errors: ccErrNoMem, ccErrBadCredentialsVersion
- */
-cc_int32 
-cci_ccache_set_principal( cc_server_ccache_t* ccache, cc_int32 cred_version, 
-                          char* principal)
-{
-    cc_generic_iterate_t* generic_iterator;
-    cc_generic_list_node_t* generic_node;
-    cc_ccache_iterate_t* ccache_iterator;
-    cc_int32 code = ccNoError;
-
-    if (ccache == NULL)
-        return ccErrInvalidCCache;
-    
-    if (principal == NULL)
-        return ccErrInvalidString;
-
-    switch (cred_version) {
-    case cc_credentials_v4:
-    case cc_credentials_v4_v5:
-        ccache->principal_v4 = (char *)malloc(strlen(principal) + 1);
-        if (ccache->principal_v4 == NULL)
-            return ccErrNoMem;
-        strcpy(ccache->principal_v4, principal);
-        if (cred_version != cc_credentials_v4_v5)
-            break;
-        /* fall-through if we are v4_v5 */
-    case cc_credentials_v5:
-        ccache->principal_v5 = (char *)malloc(strlen(principal) + 1);
-        if (ccache->principal_v5 == NULL) {
-            if (cred_version == cc_credentials_v4_v5) {
-                free(ccache->principal_v4);
-                ccache->principal_v4 = NULL;
-            }
-            return ccErrNoMem;
-        }
-        strcpy(ccache->principal_v5, principal);
-        break;
-    default:
-        return ccErrBadCredentialsVersion;
-    }
-
-    /*For API version 2 clients set_principal implies a flush of all creds*/
-    if (ccache->mycontext != NULL && ccache->mycontext->api_version == ccapi_version_2) {
-        cci_credentials_list_destroy(ccache->creds);
-        cci_credentials_list_new(&ccache->creds);
-
-        /*clean up active_iterators*/
-        code = cci_generic_list_iterator(ccache->active_iterators, &generic_iterator);
-        if (code == ccNoError) {
-            while (cci_generic_iterate_has_next(generic_iterator)) {
-                code = cci_generic_iterate_next(generic_iterator, &generic_node);
-                ccache_iterator = (cc_ccache_iterate_t*)generic_node->data;
-                ccache_iterator->next = NULL;
-            }
-        }
-    }
-
-    cci_ccache_changed(ccache);
-
-    return code;
-}
-
-/**
- * cci_ccache_destroy()
- *
- * Purpose: Destroys an existing ccache 
- *
- * Return:  0 on success
- *         -1 on errors
- *
- * Errors:  ccErrBadParam
- */
-cc_int32 
-cci_ccache_destroy(cc_server_ccache_t* ccache) 
-{
-    cc_int32 code;
-
-    if ( ccache == NULL )
-        return ccErrInvalidCCache;
-
-    code = cci_generic_list_destroy(ccache->active_iterators);
-    code = cci_credentials_list_destroy(ccache->creds);
-
-    if (ccache->mycontext != NULL)
-        code = cci_context_rem_ccache(ccache->mycontext, ccache);
-
-    return code;
-}
-
-/**
- * cci_ccache_compare()
- *
- * Purpose: Returns a boolean value indicating if two caches are identical
- *          Implemented as pointer equivalence.
- *
- * Return:  1 if TRUE
- *          0 if FALSE
- *
- * Errors:  No errors
- */
-cc_int32 
-cci_ccache_compare(cc_server_ccache_t* ccache1, cc_server_ccache_t* ccache2, cc_uint32 *result) 
-{
-    if ( ccache1 == NULL || ccache2 == NULL )
-        return ccErrInvalidCCache;
-
-    if (ccache1 == ccache2)
-        *result = 1;
-    else 
-        *result = 0;
-
-    return ccNoError;
-}
-
+/* $Copyright:\r
+ *\r
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.\r
+ * \r
+ * All rights reserved.\r
+ * \r
+ * Export of this software from the United States of America may require a\r
+ * specific license from the United States Government.  It is the\r
+ * responsibility of any person or organization contemplating export to\r
+ * obtain such a license before exporting.\r
+ * \r
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute\r
+ * this software and its documentation for any purpose and without fee is\r
+ * hereby granted, provided that the above copyright notice appear in all\r
+ * copies and that both that copyright notice and this permission notice\r
+ * appear in supporting documentation, and that the name of M.I.T. not be\r
+ * used in advertising or publicity pertaining to distribution of the\r
+ * software without specific, written prior permission.  Furthermore if you\r
+ * modify this software you must label your software as modified software\r
+ * and not distribute it in such a fashion that it might be confused with\r
+ * the original MIT software. M.I.T. makes no representations about the\r
+ * suitability of this software for any purpose.  It is provided "as is"\r
+ * without express or implied warranty.\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\r
+ * \r
+ * Individual source code files are copyright MIT, Cygnus Support,\r
+ * OpenVision, Oracle, Sun Soft, FundsXpress, and others.\r
+ * \r
+ * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,\r
+ * and Zephyr are trademarks of the Massachusetts Institute of Technology\r
+ * (MIT).  No commercial use of these trademarks may be made without prior\r
+ * written permission of MIT.\r
+ * \r
+ * "Commercial use" means use of a name in a product or other for-profit\r
+ * manner.  It does NOT prevent a commercial firm from referring to the MIT\r
+ * trademarks in order to convey information (although in doing so,\r
+ * recognition of their trademark status should be given).\r
+ * $\r
+ */\r
+\r
+/*\r
+ * Manages ccache objects.\r
+ *\r
+ */\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <time.h>\r
+#include "CredentialsCache.h"\r
+#include "datastore.h"\r
+\r
+/**\r
+ * ccache_new()\r
+ * \r
+ * Purpose: Allocate and initialize new credentials cache for the specified principal\r
+ *          and version\r
+ * \r
+ * Return:  ccNoError - success\r
+ *          ccErrInvalidString - name or principal is NULL\r
+ *          ccErrBadCredentialsVersion - unsupported creds type\r
+ *          ccErrBadParam - outCcachepp is NULL\r
+ *          ccErrNoMem - malloc failed\r
+ */\r
+cc_int32\r
+ccs_ccache_new( char *name, char *principal, int cred_vers, \r
+                cc_server_ccache_t** outCCachepp)\r
+{\r
+    cc_server_ccache_t* ccache;\r
+\r
+    if (name == NULL || principal == NULL)\r
+        return ccErrInvalidString;\r
+\r
+    if (cred_vers != cc_credentials_v4 && cred_vers != cc_credentials_v5 && \r
+         cred_vers != cc_credentials_v4_v5)\r
+        return ccErrBadCredentialsVersion;\r
+\r
+    if (outCCachepp == NULL)\r
+        return ccErrBadParam;\r
+\r
+    ccache = (cc_server_ccache_t*)malloc(sizeof(cc_server_ccache_t));\r
+    if (ccache == NULL)\r
+        return ccErrNoMem;\r
+\r
+    ccache->name = name;\r
+    ccache->principal_v4 = NULL;\r
+    ccache->principal_v5 = NULL;\r
+    ccache->changed = time(NULL);\r
+    ccache->kdc_offset = 0;\r
+    ccache->last_default = 0;\r
+    cci_generic_list_new(&ccache->active_iterators);\r
+    ccs_credentials_list_new(&ccache->creds);\r
+    ccache->is_default = 0;\r
+    ccache->kdc_set = 0;\r
+    ccache->versions = cred_vers;\r
+    ccache->mycontext = NULL;\r
+\r
+    ccs_ccache_set_principal(ccache, cred_vers, principal);\r
+    *outCCachepp = ccache;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_ccache_check_version()\r
+ * \r
+ * Purpose: Check to see if the ccache and the creds have compatible versions. \r
+ * \r
+ * Return:  ccNoError and compat = 1 if they are compatible \r
+ *          ccNoError and compat = 0 if they are not compatible\r
+ * \r
+ * Errors:  ccErrInvalidCCache - ccache is NULL\r
+ *          ccErrBadParam - either creds or compat are NULL\r
+ */\r
+cc_int32 \r
+ccs_ccache_check_version( const cc_server_ccache_t *ccache,\r
+                          const cc_credentials_union* creds,\r
+                          cc_uint32* compat)\r
+{\r
+    if (ccache == NULL)\r
+        return ccErrInvalidCCache;\r
+\r
+    if (creds == NULL || compat == NULL)\r
+        return ccErrBadParam;\r
+\r
+    if (ccache->versions == cc_credentials_v4_v5)\r
+        *compat = 1;\r
+    else if (ccache->versions == creds->version)\r
+        *compat = 1;\r
+    else\r
+        *compat = 0;\r
+\r
+    return ccNoError;\r
+}\r
+\r
+/** \r
+ccs_ccache_check_principal()\r
+\r
+Check to see if the client principal from the credentials matches\r
+the principal associated with the cache.\r
+\r
+* Return:  ccNoError and compat = 1 if they are compatible \r
+*          ccNoError and compat = 0 if they are not compatible\r
+* \r
+* Errors:  ccErrInvalidCCache - ccache is NULL\r
+*          ccErrBadParam - either creds or compat are NULL\r
+*          ccErrBadCredentialVersion - unsupported credential type\r
+*/\r
+cc_int32 \r
+ccs_ccache_check_principal( const cc_server_ccache_t *ccache,\r
+                            const cc_credentials_union* creds,\r
+                            cc_uint32* compat)\r
+{\r
+    if (ccache == NULL)\r
+        return ccErrInvalidCCache;\r
+\r
+    if (creds == NULL || compat == NULL)\r
+        return ccErrBadParam;\r
+\r
+    if (creds->version == cc_credentials_v4) {\r
+        if (strcmp(creds->credentials.credentials_v4->principal, ccache->principal_v4) == 0) \r
+            *compat = 1;\r
+        else \r
+            *compat = 0;\r
+    } else if (creds->version == cc_credentials_v5) {\r
+        if (strcmp(creds->credentials.credentials_v5->client, ccache->principal_v5) == 0)\r
+            *compat = 1;\r
+        else \r
+            *compat = 0;\r
+    } else {        \r
+        return ccErrBadCredentialsVersion;\r
+    }\r
+    return ccNoError;\r
+}\r
+\r
+\r
+/** \r
+ * ccs_ccache_store_creds()\r
+ *\r
+ * Purpose: Stores the provided credentials into the provided cache.  Validates the\r
+ *          ability of the cache to store credentials of the given version and client\r
+ *          principal.\r
+ *\r
+ * Return:  0 on success\r
+ *         -1 on error\r
+ *\r
+ * Errors: ccErrNoMem\r
+ *         ccErrBadCredentialsVersion\r
+ *         ccErrBadInvalidCredentials\r
+ *         ccErrInvalidCache\r
+ *         ccErrBadParam\r
+ */\r
+cc_int32 \r
+ccs_ccache_store_creds(cc_server_ccache_t *ccache, const cc_credentials_union* credentials) \r
+{\r
+    cc_server_credentials_t* stored_cred=NULL;\r
+    cc_uint32 valid_version, valid_principal;\r
+    cc_int32 code;\r
+\r
+    if (ccache == NULL)\r
+        return ccErrInvalidCCache;\r
+    \r
+    if (credentials == NULL)\r
+        return ccErrBadParam;\r
+\r
+    code = ccs_ccache_check_version(ccache, credentials, &valid_version);\r
+    if (code != ccNoError) {\r
+        /* pass error on to caller */\r
+        goto bad;\r
+    }\r
+    code = ccs_ccache_check_principal(ccache, credentials, &valid_principal);\r
+    if (code != ccNoError) {\r
+        /* pass error on to caller */\r
+        goto bad;\r
+    }\r
+    if (valid_version && valid_principal) {\r
+        stored_cred = (cc_server_credentials_t*)malloc(sizeof(cc_server_credentials_t));\r
+        if (stored_cred == NULL) {\r
+            code = ccErrNoMem;\r
+            goto bad;\r
+        }\r
+        memcpy(&stored_cred->creds, credentials, sizeof(cc_credentials_union));\r
+\r
+        if (credentials->version == cc_credentials_v4) {\r
+            stored_cred->creds.credentials.credentials_v4 = (cc_credentials_v4_t*)malloc(sizeof(cc_credentials_v4_t));\r
+            if (stored_cred->creds.credentials.credentials_v4 == NULL) {\r
+                code = ccErrNoMem;\r
+                goto bad;\r
+            }\r
+\r
+            memcpy(stored_cred->creds.credentials.credentials_v4, credentials->credentials.credentials_v4, sizeof(cc_credentials_v4_t));\r
+        } else if (credentials->version == cc_credentials_v5) {\r
+            stored_cred->creds.credentials.credentials_v5 = (cc_credentials_v5_t*)malloc(sizeof(cc_credentials_v5_t));\r
+            if (stored_cred->creds.credentials.credentials_v5 == NULL) {\r
+                code = ccErrNoMem;\r
+                goto bad;\r
+            }\r
+\r
+            memcpy(stored_cred->creds.credentials.credentials_v5, credentials->credentials.credentials_v5, sizeof(cc_credentials_v5_t));\r
+        } else {\r
+            code = ccErrBadCredentialsVersion;\r
+            goto bad;\r
+        }\r
+\r
+        code = ccs_credentials_list_append(ccache->creds, stored_cred, NULL);\r
+        if ( code != ccNoError ) {\r
+            /* pass error on to caller */\r
+            goto bad;\r
+        }\r
+        if (ccache->creds->head->data == (cc_uint8 *)stored_cred) \r
+            stored_cred->is_default = 1; /*we're first on the list, so we're default*/\r
+\r
+        ccs_ccache_changed(ccache);\r
+        return ccNoError;\r
+    } else {\r
+#ifdef DEBUG\r
+        printf("vers: %d\tprincipal: %d\n",\r
+                valid_version, valid_principal);\r
+#endif /* DEBUG */\r
+        code = ccErrInvalidCredentials;\r
+        goto bad;\r
+    }\r
+\r
+  bad:\r
+    if (stored_cred)\r
+        free(stored_cred);\r
+    return code;      /* error */\r
+}\r
+\r
+/**\r
+ * ccs_ccache_changed()\r
+ *\r
+ * Purpose: Updates the last update time for the ccache and its associated context.\r
+ *          Provides a location from which interested parties should be notified\r
+ *          of cache updates.\r
+ *\r
+ * Return:  none\r
+ *\r
+ * Errors:  none\r
+ */\r
+void \r
+ccs_ccache_changed(cc_server_ccache_t* ccache) \r
+{\r
+    ccache->changed = time(NULL);\r
+    if (ccache->mycontext != NULL)\r
+        ccache->mycontext->changed = time(NULL);\r
+\r
+    /* XXX - notify registered listeners when implemented */\r
+}\r
+\r
+/**\r
+ * ccs_ccache_rem_creds()\r
+ *\r
+ * Purpose: Removes the specified credential object from the specified cache if\r
+ *          it exists\r
+ *\r
+ * Return:  0 on success (credential is not in the cache)\r
+ *         -1 on error\r
+ *\r
+ * Errors: ccErrBadParam, ccErrNoMem (from cc_credentials_list_iterator)\r
+ *\r
+ * Verify: does the memory associated with stored_cred->creds need to be freed?\r
+ *\r
+ */\r
+cc_int32 \r
+ccs_ccache_rem_creds(cc_server_ccache_t *ccache, const cc_credentials_union* credentials) \r
+{\r
+    cc_credentials_iterate_t* credentials_iterator=NULL, *active;\r
+    cc_generic_iterate_t* generic_iterator=NULL;\r
+    cc_credentials_list_node_t* credentials_node;\r
+    cc_generic_list_node_t* generic_node;\r
+    cc_server_credentials_t* stored_cred;\r
+    cc_int8 changed = 0;\r
+    cc_int32 code = 0;\r
+\r
+    if (ccache == NULL)\r
+        return ccErrInvalidCCache;\r
+\r
+    if (credentials == NULL)\r
+        return ccErrBadParam;\r
+\r
+    code = ccs_credentials_list_iterator(ccache->creds, &credentials_iterator);\r
+    if (code != ccNoError) {\r
+        /* pass error to caller */\r
+        goto cleanup;\r
+    }\r
+\r
+    while (ccs_credentials_iterate_has_next(credentials_iterator)) {\r
+        code = ccs_credentials_iterate_next(credentials_iterator, &credentials_node);\r
+        stored_cred = (cc_server_credentials_t*)credentials_node->data;\r
+        if (memcmp(&stored_cred->creds,credentials,sizeof(cc_credentials_union)) == 0) {\r
+            /* XXX - do we need to free(stored_cred->creds) ? */\r
+            free(credentials_node->data);\r
+            changed = 1;\r
+               \r
+            /*If any iterator's next points to the deleted node, make it point to the next node*/\r
+            code = cci_generic_list_iterator(ccache->active_iterators, &generic_iterator);\r
+            while (cci_generic_iterate_has_next(generic_iterator)) {\r
+                code = cci_generic_iterate_next(generic_iterator, &generic_node);                      \r
+                active = (cc_credentials_iterate_t*)generic_node->data;\r
+                if (active->next == credentials_node) \r
+                    active->next = active->next->next;\r
+            }\r
+            code = cci_generic_free_iterator(generic_iterator);\r
+            generic_iterator = NULL;\r
+\r
+            if (credentials_node == ccache->creds->head) { /*removing the default, must make next cred default*/\r
+                code = ccs_credentials_list_remove_element(ccache->creds, credentials_node);\r
+\r
+                if (ccache->creds->head != NULL)\r
+                    ((cc_server_credentials_t*)ccache->creds->head->data)->is_default = 1;\r
+            } else {\r
+                code = ccs_credentials_list_remove_element(ccache->creds, credentials_node);\r
+            }\r
+            break;\r
+        }\r
+    }\r
+\r
+  cleanup:\r
+    if (changed)\r
+        ccs_ccache_changed(ccache);\r
+    if (credentials_iterator)\r
+        ccs_credentials_free_iterator(credentials_iterator);\r
+    if (generic_iterator)\r
+        cci_generic_free_iterator(generic_iterator);\r
+    return code;\r
+}\r
+\r
+/**\r
+ * ccs_ccache_move()\r
+ * \r
+ * Purpose: Destroys the existing contents of the destination and copies\r
+ *          all credentials from the source to the destination\r
+ *\r
+ * Return:  0 on success\r
+ *         -1 on error\r
+ *\r
+ * Errors:  ccBadNoMem\r
+ *\r
+ */\r
+\r
+cc_int32 \r
+ccs_ccache_move(cc_server_ccache_t *source, cc_server_ccache_t* destination) \r
+{\r
+    cc_generic_list_node_t* node;\r
+    cc_generic_iterate_t* iterator;\r
+    cc_credentials_iterate_t* cur;\r
+    cc_int32 code;\r
+\r
+    if (source == NULL || destination == NULL)\r
+        return ccErrBadParam;\r
+       \r
+    code = ccs_credentials_list_destroy(destination->creds);\r
+    if ( code != ccNoError )\r
+        return code;\r
+\r
+    code = ccs_credentials_list_copy(source->creds, &destination->creds);\r
+    if ( code != ccNoError ) \r
+        return code;\r
+\r
+    destination->versions = source->versions;\r
+    destination->kdc_offset = source->kdc_offset;\r
+    destination->last_default = 0;\r
+\r
+    /*reset all active iterators to point to the head of the new creds list*/\r
+    if (destination->active_iterators->head != NULL) {\r
+        code = cci_generic_list_iterator(destination->active_iterators, &iterator);\r
+        while (cci_generic_iterate_has_next(iterator)) {\r
+            code = cci_generic_iterate_next(iterator, &node);\r
+            cur = (cc_credentials_iterate_t*)node->data;\r
+            cur->next = destination->creds->head;\r
+        }\r
+        code = cci_generic_free_iterator(iterator);\r
+    }\r
+\r
+    ccs_ccache_changed(destination);\r
+    return code;\r
+}\r
+\r
+/**\r
+ * ccs_ccache_get_kdc_time_offset()\r
+ * \r
+ * Purpose: Retrieves the kdc_time_offset from the ccache if set\r
+ *\r
+ * Return:  0 on success\r
+ *         -1 on error\r
+ *\r
+ * Errors:  ccErrBadParam, ccErrTimeOffsetNotSet\r
+ *\r
+ */\r
+cc_int32 \r
+ccs_ccache_get_kdc_time_offset(cc_server_ccache_t* ccache, cc_time64* offset) \r
+{\r
+    if (ccache == NULL)\r
+        return ccErrInvalidCCache;\r
+    \r
+    if (offset == NULL)\r
+        return ccErrBadParam;\r
+\r
+    if (!ccache->kdc_set)\r
+        return ccErrTimeOffsetNotSet;\r
+\r
+    *offset = ccache->kdc_offset;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_ccache_set_kdc_time_offset()\r
+ *\r
+ * Purpose: Sets the kdc time offset in the designated ccache\r
+ * \r
+ * Return:  0 on success\r
+ *         -1 on error\r
+ * \r
+ * Errors: ccErrBadParam\r
+ *\r
+ */\r
+cc_int32 \r
+ccs_ccache_set_kdc_time_offset(cc_server_ccache_t* ccache, cc_time64 offset) \r
+{\r
+    if (ccache == NULL)\r
+        return ccErrInvalidCCache;\r
+\r
+    ccache->kdc_offset = offset;\r
+    ccache->kdc_set = 1;\r
+    ccs_ccache_changed(ccache);\r
+\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_ccache_clear_kdc_time_offset()\r
+ *\r
+ * Purpose: Clear the kdc time offset in the designated ccache\r
+ *\r
+ * Return:  0 on success\r
+ *         -1 on error\r
+ *\r
+ * Errors: ccErrBadParam\r
+ */\r
+cc_int32 \r
+ccs_ccache_clear_kdc_time_offset(cc_server_ccache_t* ccache) \r
+{\r
+    if (ccache == NULL)\r
+        return ccErrInvalidCCache;\r
+\r
+    ccache->kdc_offset = 0;\r
+    ccache->kdc_set = 0;\r
+    ccs_ccache_changed(ccache);\r
+\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_ccache_new_iterator()\r
+ *\r
+ * Purpose: Retrieve an iterator for the designated cache\r
+ *\r
+ * Return:  0 on success\r
+ *         -1 on error\r
+ *\r
+ * Errors: ccErrBadParam, ccBadNoMem\r
+ */\r
+cc_int32 \r
+ccs_ccache_new_iterator(cc_server_ccache_t* ccache, cc_credentials_iterate_t** iterator)\r
+{\r
+    cc_int32 code;\r
+\r
+    if (ccache == NULL)\r
+        return ccErrInvalidCCache;\r
+\r
+    if (iterator == NULL)\r
+        return ccErrBadParam;\r
+\r
+    code = ccs_credentials_list_iterator(ccache->creds, iterator);\r
+    if (code != ccNoError)\r
+        return code;\r
+\r
+    code = cci_generic_list_prepend(ccache->active_iterators, *iterator, sizeof(cc_credentials_iterate_t), NULL);\r
+    if (code != ccNoError)\r
+        return code;\r
+\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_ccache_get_principal()\r
+ * \r
+ * Purpose: Retrieves the client principal associated with the designated cache.\r
+ *          The value is returned \r
+ * Return:\r
+ *\r
+ * Errors:\r
+ */\r
+cc_int32 \r
+ccs_ccache_get_principal(cc_server_ccache_t* ccache, cc_int32 version, char ** principal) \r
+{\r
+    char *p = NULL;\r
+    \r
+    switch ( version ) {\r
+    case cc_credentials_v4:\r
+        p = ccache->principal_v4;\r
+        break;\r
+    case cc_credentials_v5:\r
+        p = ccache->principal_v5;\r
+        break;\r
+    default:\r
+        return ccErrBadCredentialsVersion;\r
+    }\r
+\r
+    *principal = (char *)malloc(strlen(p)+1);\r
+    if ( *principal == NULL )\r
+        return ccErrNoMem;\r
+\r
+    strcpy(*principal, p);\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * Purpose: Releases the memory associated with a ccache principal\r
+ * \r
+ * Return:\r
+ *\r
+ * Errors:\r
+ *\r
+ */\r
+cc_int32\r
+ccs_ccache_free_principal(char * principal)\r
+{\r
+    if ( principal == NULL )\r
+        return ccErrBadParam;\r
+\r
+    free(principal);\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccache_set_principal()\r
+ *\r
+ * Purpose: Assigns a principal to the designated ccache and credential version.\r
+ *          If the api version is 2, the cache is cleared of all existing\r
+ *          credentials.\r
+ *\r
+ * Return:  0 on success\r
+ *         -1 on error\r
+ *\r
+ * Errors: ccErrNoMem, ccErrBadCredentialsVersion\r
+ */\r
+cc_int32 \r
+ccs_ccache_set_principal( cc_server_ccache_t* ccache, cc_int32 cred_version, \r
+                          char* principal)\r
+{\r
+    cc_generic_iterate_t* generic_iterator;\r
+    cc_generic_list_node_t* generic_node;\r
+    cc_ccache_iterate_t* ccache_iterator;\r
+    cc_int32 code = ccNoError;\r
+\r
+    if (ccache == NULL)\r
+        return ccErrInvalidCCache;\r
+    \r
+    if (principal == NULL)\r
+        return ccErrInvalidString;\r
+\r
+    switch (cred_version) {\r
+    case cc_credentials_v4:\r
+    case cc_credentials_v4_v5:\r
+        ccache->principal_v4 = (char *)malloc(strlen(principal) + 1);\r
+        if (ccache->principal_v4 == NULL)\r
+            return ccErrNoMem;\r
+        strcpy(ccache->principal_v4, principal);\r
+        if (cred_version != cc_credentials_v4_v5)\r
+            break;\r
+        /* fall-through if we are v4_v5 */\r
+    case cc_credentials_v5:\r
+        ccache->principal_v5 = (char *)malloc(strlen(principal) + 1);\r
+        if (ccache->principal_v5 == NULL) {\r
+            if (cred_version == cc_credentials_v4_v5) {\r
+                free(ccache->principal_v4);\r
+                ccache->principal_v4 = NULL;\r
+            }\r
+            return ccErrNoMem;\r
+        }\r
+        strcpy(ccache->principal_v5, principal);\r
+        break;\r
+    default:\r
+        return ccErrBadCredentialsVersion;\r
+    }\r
+\r
+    /*For API version 2 clients set_principal implies a flush of all creds*/\r
+    if (ccache->mycontext != NULL && ccache->mycontext->api_version == ccapi_version_2) {\r
+        ccs_credentials_list_destroy(ccache->creds);\r
+        ccs_credentials_list_new(&ccache->creds);\r
+\r
+        /*clean up active_iterators*/\r
+        code = cci_generic_list_iterator(ccache->active_iterators, &generic_iterator);\r
+        if (code == ccNoError) {\r
+            while (cci_generic_iterate_has_next(generic_iterator)) {\r
+                code = cci_generic_iterate_next(generic_iterator, &generic_node);\r
+                ccache_iterator = (cc_ccache_iterate_t*)generic_node->data;\r
+                ccache_iterator->next = NULL;\r
+            }\r
+        }\r
+    }\r
+\r
+    ccs_ccache_changed(ccache);\r
+\r
+    return code;\r
+}\r
+\r
+/**\r
+ * ccs_ccache_destroy()\r
+ *\r
+ * Purpose: Destroys an existing ccache \r
+ *\r
+ * Return:  0 on success\r
+ *         -1 on errors\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ */\r
+cc_int32 \r
+ccs_ccache_destroy(cc_server_ccache_t* ccache) \r
+{\r
+    cc_int32 code;\r
+\r
+    if ( ccache == NULL )\r
+        return ccErrInvalidCCache;\r
+\r
+    code = cci_generic_list_destroy(ccache->active_iterators);\r
+    code = ccs_credentials_list_destroy(ccache->creds);\r
+\r
+    if (ccache->mycontext != NULL)\r
+        code = ccs_context_rem_ccache(ccache->mycontext, ccache);\r
+\r
+    return code;\r
+}\r
+\r
+/**\r
+ * ccs_ccache_compare()\r
+ *\r
+ * Purpose: Returns a boolean value indicating if two caches are identical\r
+ *          Implemented as pointer equivalence.\r
+ *\r
+ * Return:  1 if TRUE\r
+ *          0 if FALSE\r
+ *\r
+ * Errors:  No errors\r
+ */\r
+cc_int32 \r
+ccs_ccache_compare(cc_server_ccache_t* ccache1, cc_server_ccache_t* ccache2, cc_uint32 *result) \r
+{\r
+    if ( ccache1 == NULL || ccache2 == NULL )\r
+        return ccErrInvalidCCache;\r
+\r
+    if (ccache1 == ccache2)\r
+        *result = 1;\r
+    else \r
+        *result = 0;\r
+\r
+    return ccNoError;\r
+}\r
+\r
similarity index 76%
rename from src/lib/ccapi/server/context.c
rename to src/lib/ccapi/server/ccs_context.c
index f405a4defbefb792a4c3d80ae9b58fb1f4143c96..a168147940c422dcdaff828f6c327470489fc7db 100644 (file)
-/* $Copyright:
- *
- * Copyright 2004 by the Massachusetts Institute of Technology.
- * 
- * All rights reserved.
- * 
- * Export of this software from the United States of America may require a
- * specific license from the United States Government.  It is the
- * responsibility of any person or organization contemplating export to
- * obtain such a license before exporting.
- * 
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute
- * this software and its documentation for any purpose and without fee is
- * hereby granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission notice
- * appear in supporting documentation, and that the name of M.I.T. not be
- * used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.  Furthermore if you
- * modify this software you must label your software as modified software
- * and not distribute it in such a fashion that it might be confused with
- * the original MIT software. M.I.T. makes no representations about the
- * suitability of this software for any purpose.  It is provided "as is"
- * without express or implied warranty.
- * 
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- * 
- * Individual source code files are copyright MIT, Cygnus Support,
- * OpenVision, Oracle, Sun Soft, FundsXpress, and others.
- * 
- * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,
- * and Zephyr are trademarks of the Massachusetts Institute of Technology
- * (MIT).  No commercial use of these trademarks may be made without prior
- * written permission of MIT.
- * 
- * "Commercial use" means use of a name in a product or other for-profit
- * manner.  It does NOT prevent a commercial firm from referring to the MIT
- * trademarks in order to convey information (although in doing so,
- * recognition of their trademark status should be given).
- * $
- */
-
-/*
- * Functions to manipulate datastore layer contexts.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <string.h>
-
-#include "CredentialsCache.h"
-#include "datastore.h"
-
-int cc_myversion = 5;
-char cc_vendor[] = "MIT C lang CCache V5";
-char cc_default_ccache_name[] = "krb5cc";
-
-
-cc_int32
-cci_context_new( int api_version, cc_auth_info_t* auth_info, 
-                 cc_session_info_t* session_info, cc_server_context_t** outContextpp )
-{
-    cc_server_context_t* ctx;
-       
-    if ( outContextpp == NULL )
-        return ccErrBadParam;
-
-       ctx = (cc_server_context_t*)malloc(sizeof(cc_server_context_t));
-    if (ctx == NULL)
-        return ccErrNoMem;
-               
-    cci_ccache_list_new(&ctx->ccaches);
-    cci_generic_list_new(&ctx->active_iterators);      
-    ctx->api_version = api_version;
-    ctx->auth_info = auth_info;
-    ctx->session_info = session_info;
-    ctx->changed = time(NULL);
-
-    *outContextpp = ctx;
-    return ccNoError;
-}
-
-cc_int32
-cci_context_get_default_ccache_name(cc_server_context_t* ctx, char ** outNamepp) 
-{
-    cc_server_ccache_t* default_ccache;
-
-    if (outNamepp == NULL)
-        return ccErrBadParam;
-    
-    if (ctx == NULL)
-        return ccErrInvalidContext;
-
-    if (ctx->ccaches->head != NULL) {
-        default_ccache = (cc_server_ccache_t*)ctx->ccaches->head->data;
-        *outNamepp = default_ccache->name;
-    } else {
-        *outNamepp = cc_default_ccache_name;
-    }
-    return ccNoError;
-}
-
-
-cc_int32
-cci_context_find_ccache( cc_server_context_t* ctx, char *name, 
-                         cc_server_ccache_t** outCcachepp )
-{
-    cc_ccache_iterate_t* ccache_iterator;
-    cc_ccache_list_node_t* ccache_node;
-    cc_server_ccache_t* ccache;
-       cc_int32 code;
-
-    if (ctx == NULL) 
-        return ccErrInvalidContext;
-    
-    if (name == NULL)
-        return ccErrInvalidString;
-
-    if (outCcachepp == NULL)
-        return ccErrBadParam;
-
-    code = cci_ccache_list_iterator(ctx->ccaches, &ccache_iterator);
-    while (cci_ccache_iterate_has_next(ccache_iterator)) {
-        code = cci_ccache_iterate_next(ccache_iterator, &ccache_node);
-        ccache = (cc_server_ccache_t *)ccache_node->data;
-        if (strcmp(ccache->name, name) == 0)  {
-            free(ccache_iterator);
-            *outCcachepp = ccache;
-            return ccNoError;
-        }
-    }
-    free(ccache_iterator);
-    return ccErrCCacheNotFound;
-}       
-
-cc_int32
-cci_context_open_ccache( cc_server_context_t* ctx, char *name, 
-                         cc_server_ccache_t** outCcachepp )
-{
-    return cci_context_find_ccache(ctx, name, outCcachepp);
-}
-
-
-cc_int32
-cci_context_create_ccache( cc_server_context_t* ctx, char *name, int creds_version, 
-                           char *principal, cc_server_ccache_t** outCcachepp )
-{
-    cc_server_ccache_t* ccache;
-    cc_int32 code;
-
-    if (ctx == NULL) 
-        return ccErrInvalidContext;
-    
-    if (outCcachepp == NULL)
-        return ccErrBadParam;
-
-    if (name == NULL || principal == NULL)
-        return ccErrInvalidString;
-
-    if (creds_version != cc_credentials_v4 && creds_version != cc_credentials_v5 && 
-         creds_version != cc_credentials_v4_v5)
-        return ccErrBadCredentialsVersion;
-       
-    code = cci_context_find_ccache(ctx, name, &ccache);
-    if (code == ccNoError) {
-        code = cci_ccache_set_principal(ccache, creds_version, principal);
-    } else {
-        code = cci_ccache_new(name, principal, creds_version, &ccache);
-        if (code != ccNoError)
-            return code;       /*let caller deal with error*/
-
-        ccache->mycontext = ctx;
-        ctx->changed = time(NULL);
-        cci_ccache_list_append(ctx->ccaches, ccache, NULL);
-
-        if (ctx->ccaches->head->data == (cc_uint8 *)ccache) {
-            ccache->is_default = 1;
-        }
-    }
-    *outCcachepp = ccache;
-    return ccNoError;
-}
-
-cc_int32
-cci_context_create_default_ccache( cc_server_context_t* ctx, int creds_version, 
-                                   char *principal, cc_server_ccache_t** outCcachepp )
-{
-    cc_server_ccache_t* ccache, *old_default;
-    cc_int32 code;
-
-    if (ctx == NULL) 
-        return ccErrInvalidContext;
-    
-    if (outCcachepp == NULL)
-        return ccErrBadParam;
-
-    if (principal == NULL)
-        return ccErrInvalidString;
-
-    if (creds_version != cc_credentials_v4 && creds_version != cc_credentials_v5 && 
-         creds_version != cc_credentials_v4_v5)
-        return ccErrBadCredentialsVersion;
-       
-    code = cci_context_find_ccache(ctx, cc_default_ccache_name, &ccache);
-    if (code == ccNoError) {
-        cci_ccache_set_principal(ccache, creds_version, principal);
-    } else {
-        code = cci_ccache_new(cc_default_ccache_name, principal, creds_version, &ccache);
-        if (code != ccNoError)
-            return code;       /*let caller deal with error*/
-
-        ccache->mycontext = ctx;
-        ccache->is_default = 1;
-        ctx->changed = time(NULL);
-       
-        if (ctx->ccaches->head != NULL) {
-            old_default = (cc_server_ccache_t *)ctx->ccaches->head->data;
-            old_default->is_default = 0;
-            old_default->last_default = time(NULL);
-        }
-
-        cci_ccache_list_prepend(ctx->ccaches, ccache, NULL);
-    }
-    *outCcachepp = ccache;
-    return ccNoError;
-}
-
-cc_int32
-cci_context_ccache_iterator(cc_server_context_t* ctx, cc_ccache_iterate_t** iterpp) 
-{
-    cc_ccache_iterate_t* ccache_iterator;
-    cc_int32 code;
-
-    if (ctx == NULL) 
-        return ccErrInvalidContext;
-    
-    if (iterpp == NULL)
-        return ccErrBadParam;
-
-    code = cci_ccache_list_iterator(ctx->ccaches, &ccache_iterator);
-    if (code != ccNoError)
-        return code;
-    cci_generic_list_prepend(ctx->active_iterators, ccache_iterator, sizeof(cc_ccache_iterate_t), NULL);
-
-    *iterpp = ccache_iterator;
-    return ccNoError;
-}
-
-cc_int32 
-cci_context_compare(cc_server_context_t* a, cc_server_context_t* b) 
-{
-    if (a == b)
-        return 1;
-    else
-        return 0;
-}
-
-cc_int32 
-cci_context_destroy(cc_server_context_t* ctx) 
-{
-    cc_ccache_iterate_t* ccache_iterator;
-    cc_ccache_list_node_t* ccache_node;
-    cc_server_ccache_t* ccache;
-    cc_int32 code;
-
-    if (ctx == NULL) 
-        return ccErrInvalidContext;
-
-    cci_generic_list_destroy(ctx->active_iterators);
-       
-    code = cci_ccache_list_iterator(ctx->ccaches, &ccache_iterator);
-    while (cci_ccache_iterate_has_next(ccache_iterator)) {
-        code = cci_ccache_iterate_next(ccache_iterator, &ccache_node);
-        ccache = (cc_server_ccache_t *)ccache_node->data;
-        ccache_node->data = NULL;
-        cci_ccache_destroy(ccache);
-    }
-    cci_ccache_list_destroy(ctx->ccaches);
-
-    return ccNoError;
-}
-
-cc_int32 
-cci_context_rem_ccache(cc_server_context_t* ctx, cc_server_ccache_t* ccache) 
-{
-    cc_ccache_iterate_t* ccache_iterator;
-    cc_ccache_iterate_t* active_ccache_iterator;
-    cc_ccache_list_node_t* ccache_node;
-    cc_server_ccache_t* list_ccache;
-    cc_generic_list_node_t* gen_node;
-    cc_generic_iterate_t* gen_iterator;
-    cc_int32 code;
-
-    if (ctx == NULL) 
-        return ccErrInvalidContext;
-
-    if (ccache == NULL) 
-        return ccErrInvalidCCache;
-
-    code = cci_ccache_list_iterator(ctx->ccaches, &ccache_iterator);
-    while (cci_ccache_iterate_has_next(ccache_iterator)) {
-        code = cci_ccache_iterate_next(ccache_iterator, &ccache_node);
-        list_ccache = (cc_server_ccache_t *)ccache_node->data;
-
-        if (list_ccache == ccache) {
-            code = cci_generic_list_iterator(ctx->active_iterators, &gen_iterator);
-            while (cci_generic_iterate_has_next(gen_iterator)) {
-                code = cci_generic_iterate_next(gen_iterator, &gen_node);
-                active_ccache_iterator = (cc_server_ccache_t *)gen_node->data;
-                if (active_ccache_iterator->next == ccache_node) {
-                    active_ccache_iterator->next = active_ccache_iterator->next->next;
-                }
-            }
-            free(gen_iterator);
-            code = cci_ccache_list_remove_element(ctx->ccaches, ccache_node);
-            break;
-        }
-    }
-    free(ccache_iterator);
-    return ccNoError;
-}
-
+/* $Copyright:\r
+ *\r
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.\r
+ * \r
+ * All rights reserved.\r
+ * \r
+ * Export of this software from the United States of America may require a\r
+ * specific license from the United States Government.  It is the\r
+ * responsibility of any person or organization contemplating export to\r
+ * obtain such a license before exporting.\r
+ * \r
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute\r
+ * this software and its documentation for any purpose and without fee is\r
+ * hereby granted, provided that the above copyright notice appear in all\r
+ * copies and that both that copyright notice and this permission notice\r
+ * appear in supporting documentation, and that the name of M.I.T. not be\r
+ * used in advertising or publicity pertaining to distribution of the\r
+ * software without specific, written prior permission.  Furthermore if you\r
+ * modify this software you must label your software as modified software\r
+ * and not distribute it in such a fashion that it might be confused with\r
+ * the original MIT software. M.I.T. makes no representations about the\r
+ * suitability of this software for any purpose.  It is provided "as is"\r
+ * without express or implied warranty.\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\r
+ * \r
+ * Individual source code files are copyright MIT, Cygnus Support,\r
+ * OpenVision, Oracle, Sun Soft, FundsXpress, and others.\r
+ * \r
+ * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,\r
+ * and Zephyr are trademarks of the Massachusetts Institute of Technology\r
+ * (MIT).  No commercial use of these trademarks may be made without prior\r
+ * written permission of MIT.\r
+ * \r
+ * "Commercial use" means use of a name in a product or other for-profit\r
+ * manner.  It does NOT prevent a commercial firm from referring to the MIT\r
+ * trademarks in order to convey information (although in doing so,\r
+ * recognition of their trademark status should be given).\r
+ * $\r
+ */\r
+\r
+/*\r
+ * Functions to manipulate datastore layer contexts.\r
+ *\r
+ */\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <time.h>\r
+#include <string.h>\r
+\r
+#include "CredentialsCache.h"\r
+#include "datastore.h"\r
+\r
+int cc_myversion = 5;\r
+char cc_vendor[] = "MIT C lang CCache V5";\r
+char cc_default_ccache_name[] = "krb5cc";\r
+\r
+\r
+cc_int32\r
+ccs_context_new( int api_version, cc_auth_info_t* auth_info, \r
+                 cc_session_info_t* session_info, cc_server_context_t** outContextpp )\r
+{\r
+    cc_server_context_t* ctx;\r
+       \r
+    if ( outContextpp == NULL )\r
+        return ccErrBadParam;\r
+\r
+       ctx = (cc_server_context_t*)malloc(sizeof(cc_server_context_t));\r
+    if (ctx == NULL)\r
+        return ccErrNoMem;\r
+               \r
+    ccs_ccache_list_new(&ctx->ccaches);\r
+    cci_generic_list_new(&ctx->active_iterators);      \r
+    ctx->api_version = api_version;\r
+    ctx->auth_info = auth_info;\r
+    ctx->session_info = session_info;\r
+    ctx->changed = time(NULL);\r
+\r
+    *outContextpp = ctx;\r
+    return ccNoError;\r
+}\r
+\r
+cc_int32\r
+ccs_context_get_default_ccache_name(cc_server_context_t* ctx, char ** outNamepp) \r
+{\r
+    cc_server_ccache_t* default_ccache;\r
+\r
+    if (outNamepp == NULL)\r
+        return ccErrBadParam;\r
+    \r
+    if (ctx == NULL)\r
+        return ccErrInvalidContext;\r
+\r
+    if (ctx->ccaches->head != NULL) {\r
+        default_ccache = (cc_server_ccache_t*)ctx->ccaches->head->data;\r
+        *outNamepp = default_ccache->name;\r
+    } else {\r
+        *outNamepp = cc_default_ccache_name;\r
+    }\r
+    return ccNoError;\r
+}\r
+\r
+\r
+cc_int32\r
+ccs_context_find_ccache( cc_server_context_t* ctx, char *name, \r
+                         cc_server_ccache_t** outCcachepp )\r
+{\r
+    cc_ccache_iterate_t* ccache_iterator;\r
+    cc_ccache_list_node_t* ccache_node;\r
+    cc_server_ccache_t* ccache;\r
+       cc_int32 code;\r
+\r
+    if (ctx == NULL) \r
+        return ccErrInvalidContext;\r
+    \r
+    if (name == NULL)\r
+        return ccErrInvalidString;\r
+\r
+    if (outCcachepp == NULL)\r
+        return ccErrBadParam;\r
+\r
+    code = ccs_ccache_list_iterator(ctx->ccaches, &ccache_iterator);\r
+    while (ccs_ccache_iterate_has_next(ccache_iterator)) {\r
+        code = ccs_ccache_iterate_next(ccache_iterator, &ccache_node);\r
+        ccache = (cc_server_ccache_t *)ccache_node->data;\r
+        if (strcmp(ccache->name, name) == 0)  {\r
+            free(ccache_iterator);\r
+            *outCcachepp = ccache;\r
+            return ccNoError;\r
+        }\r
+    }\r
+    free(ccache_iterator);\r
+    return ccErrCCacheNotFound;\r
+}       \r
+\r
+cc_int32\r
+ccs_context_open_ccache( cc_server_context_t* ctx, char *name, \r
+                         cc_server_ccache_t** outCcachepp )\r
+{\r
+    return ccs_context_find_ccache(ctx, name, outCcachepp);\r
+}\r
+\r
+\r
+cc_int32\r
+ccs_context_create_ccache( cc_server_context_t* ctx, char *name, int creds_version, \r
+                           char *principal, cc_server_ccache_t** outCcachepp )\r
+{\r
+    cc_server_ccache_t* ccache;\r
+    cc_int32 code;\r
+\r
+    if (ctx == NULL) \r
+        return ccErrInvalidContext;\r
+    \r
+    if (outCcachepp == NULL)\r
+        return ccErrBadParam;\r
+\r
+    if (name == NULL || principal == NULL)\r
+        return ccErrInvalidString;\r
+\r
+    if (creds_version != cc_credentials_v4 && creds_version != cc_credentials_v5 && \r
+         creds_version != cc_credentials_v4_v5)\r
+        return ccErrBadCredentialsVersion;\r
+       \r
+    code = ccs_context_find_ccache(ctx, name, &ccache);\r
+    if (code == ccNoError) {\r
+        code = ccs_ccache_set_principal(ccache, creds_version, principal);\r
+    } else {\r
+        code = ccs_ccache_new(name, principal, creds_version, &ccache);\r
+        if (code != ccNoError)\r
+            return code;       /*let caller deal with error*/\r
+\r
+        ccache->mycontext = ctx;\r
+        ctx->changed = time(NULL);\r
+        ccs_ccache_list_append(ctx->ccaches, ccache, NULL);\r
+\r
+        if (ctx->ccaches->head->data == (cc_uint8 *)ccache) {\r
+            ccache->is_default = 1;\r
+        }\r
+    }\r
+    *outCcachepp = ccache;\r
+    return ccNoError;\r
+}\r
+\r
+cc_int32\r
+ccs_context_create_default_ccache( cc_server_context_t* ctx, int creds_version, \r
+                                   char *principal, cc_server_ccache_t** outCcachepp )\r
+{\r
+    cc_server_ccache_t* ccache, *old_default;\r
+    cc_int32 code;\r
+\r
+    if (ctx == NULL) \r
+        return ccErrInvalidContext;\r
+    \r
+    if (outCcachepp == NULL)\r
+        return ccErrBadParam;\r
+\r
+    if (principal == NULL)\r
+        return ccErrInvalidString;\r
+\r
+    if (creds_version != cc_credentials_v4 && creds_version != cc_credentials_v5 && \r
+         creds_version != cc_credentials_v4_v5)\r
+        return ccErrBadCredentialsVersion;\r
+       \r
+    code = ccs_context_find_ccache(ctx, cc_default_ccache_name, &ccache);\r
+    if (code == ccNoError) {\r
+        ccs_ccache_set_principal(ccache, creds_version, principal);\r
+    } else {\r
+        code = ccs_ccache_new(cc_default_ccache_name, principal, creds_version, &ccache);\r
+        if (code != ccNoError)\r
+            return code;       /*let caller deal with error*/\r
+\r
+        ccache->mycontext = ctx;\r
+        ccache->is_default = 1;\r
+        ctx->changed = time(NULL);\r
+       \r
+        if (ctx->ccaches->head != NULL) {\r
+            old_default = (cc_server_ccache_t *)ctx->ccaches->head->data;\r
+            old_default->is_default = 0;\r
+            old_default->last_default = time(NULL);\r
+        }\r
+\r
+        ccs_ccache_list_prepend(ctx->ccaches, ccache, NULL);\r
+    }\r
+    *outCcachepp = ccache;\r
+    return ccNoError;\r
+}\r
+\r
+cc_int32\r
+ccs_context_ccache_iterator(cc_server_context_t* ctx, cc_ccache_iterate_t** iterpp) \r
+{\r
+    cc_ccache_iterate_t* ccache_iterator;\r
+    cc_int32 code;\r
+\r
+    if (ctx == NULL) \r
+        return ccErrInvalidContext;\r
+    \r
+    if (iterpp == NULL)\r
+        return ccErrBadParam;\r
+\r
+    code = ccs_ccache_list_iterator(ctx->ccaches, &ccache_iterator);\r
+    if (code != ccNoError)\r
+        return code;\r
+    cci_generic_list_prepend(ctx->active_iterators, ccache_iterator, sizeof(cc_ccache_iterate_t), NULL);\r
+\r
+    *iterpp = ccache_iterator;\r
+    return ccNoError;\r
+}\r
+\r
+cc_int32 \r
+ccs_context_compare(cc_server_context_t* a, cc_server_context_t* b) \r
+{\r
+    if (a == b)\r
+        return 1;\r
+    else\r
+        return 0;\r
+}\r
+\r
+cc_int32 \r
+ccs_context_destroy(cc_server_context_t* ctx) \r
+{\r
+    cc_ccache_iterate_t* ccache_iterator;\r
+    cc_ccache_list_node_t* ccache_node;\r
+    cc_server_ccache_t* ccache;\r
+    cc_int32 code;\r
+\r
+    if (ctx == NULL) \r
+        return ccErrInvalidContext;\r
+\r
+    cci_generic_list_destroy(ctx->active_iterators);\r
+       \r
+    code = ccs_ccache_list_iterator(ctx->ccaches, &ccache_iterator);\r
+    while (ccs_ccache_iterate_has_next(ccache_iterator)) {\r
+        code = ccs_ccache_iterate_next(ccache_iterator, &ccache_node);\r
+        ccache = (cc_server_ccache_t *)ccache_node->data;\r
+        ccache_node->data = NULL;\r
+        ccs_ccache_destroy(ccache);\r
+    }\r
+    ccs_ccache_list_destroy(ctx->ccaches);\r
+\r
+    return ccNoError;\r
+}\r
+\r
+cc_int32 \r
+ccs_context_rem_ccache(cc_server_context_t* ctx, cc_server_ccache_t* ccache) \r
+{\r
+    cc_ccache_iterate_t* ccache_iterator;\r
+    cc_ccache_iterate_t* active_ccache_iterator;\r
+    cc_ccache_list_node_t* ccache_node;\r
+    cc_server_ccache_t* list_ccache;\r
+    cc_generic_list_node_t* gen_node;\r
+    cc_generic_iterate_t* gen_iterator;\r
+    cc_int32 code;\r
+\r
+    if (ctx == NULL) \r
+        return ccErrInvalidContext;\r
+\r
+    if (ccache == NULL) \r
+        return ccErrInvalidCCache;\r
+\r
+    code = ccs_ccache_list_iterator(ctx->ccaches, &ccache_iterator);\r
+    while (ccs_ccache_iterate_has_next(ccache_iterator)) {\r
+        code = ccs_ccache_iterate_next(ccache_iterator, &ccache_node);\r
+        list_ccache = (cc_server_ccache_t *)ccache_node->data;\r
+\r
+        if (list_ccache == ccache) {\r
+            code = cci_generic_list_iterator(ctx->active_iterators, &gen_iterator);\r
+            while (cci_generic_iterate_has_next(gen_iterator)) {\r
+                code = cci_generic_iterate_next(gen_iterator, &gen_node);\r
+                active_ccache_iterator = (cc_ccache_iterate_t *)gen_node->data;\r
+                if (active_ccache_iterator->next == ccache_node) {\r
+                    active_ccache_iterator->next = active_ccache_iterator->next->next;\r
+                }\r
+            }\r
+            free(gen_iterator);\r
+            code = ccs_ccache_list_remove_element(ctx->ccaches, ccache_node);\r
+            break;\r
+        }\r
+    }\r
+    free(ccache_iterator);\r
+    return ccNoError;\r
+}\r
+\r
similarity index 84%
rename from src/lib/ccapi/server/lists.c
rename to src/lib/ccapi/server/ccs_lists.c
index 882ecb7a0643ab054988adbfcbad2623b76b2ead..06f8ced87395a7c49fe5aa4103291fd6dd3465a0 100644 (file)
-/* $Copyright:
- *
- * Copyright 2004 by the Massachusetts Institute of Technology.
- * 
- * All rights reserved.
- * 
- * Export of this software from the United States of America may require a
- * specific license from the United States Government.  It is the
- * responsibility of any person or organization contemplating export to
- * obtain such a license before exporting.
- * 
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute
- * this software and its documentation for any purpose and without fee is
- * hereby granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission notice
- * appear in supporting documentation, and that the name of M.I.T. not be
- * used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.  Furthermore if you
- * modify this software you must label your software as modified software
- * and not distribute it in such a fashion that it might be confused with
- * the original MIT software. M.I.T. makes no representations about the
- * suitability of this software for any purpose.  It is provided "as is"
- * without express or implied warranty.
- * 
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- * 
- * Individual source code files are copyright MIT, Cygnus Support,
- * OpenVision, Oracle, Sun Soft, FundsXpress, and others.
- * 
- * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,
- * and Zephyr are trademarks of the Massachusetts Institute of Technology
- * (MIT).  No commercial use of these trademarks may be made without prior
- * written permission of MIT.
- * 
- * "Commercial use" means use of a name in a product or other for-profit
- * manner.  It does NOT prevent a commercial firm from referring to the MIT
- * trademarks in order to convey information (although in doing so,
- * recognition of their trademark status should be given).
- * $
- */
-
-
-/*
- * Lists implementation.
- * 
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <memory.h>
-
-#include "CredentialsCache.h"
-#include "datastore.h"
-
-/**
- * cci_generic_iterate_has_next()
- *
- * Purpose: Determine if an iterator has a next element
- *
- * Return:  1 if another element exists
- *          0 if no additional elements exist
- *
- * Errors:  None
- *
- */
-cc_int32 
-cci_generic_iterate_has_next(cc_generic_iterate_t *iterate) 
-{
-    return ((iterate == NULL || iterate->next == NULL) ? 0 : 1);
-}
-
-/**
- * cci_generic_iterate_next()
- *
- * Purpose: Retrieve the next element from an iterator and advance
- *          the iterator
- *
- * Return:  non-NULL, the next element in the iterator
- *          NULL, the iterator list is empty or iterator is invalid
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32
-cci_generic_iterate_next(cc_generic_iterate_t *iterator, cc_generic_list_node_t** nodepp) 
-{
-    cc_generic_list_node_t* ret;
-    
-    if (iterator == NULL || nodepp == NULL)
-        return ccErrBadParam;
-
-    ret = iterator->next;
-    if (iterator->next != NULL)
-        iterator->next = iterator->next->next;
-
-    *nodepp = ret;
-    return ccNoError;
-}
-
-/**
- * cci_context_iterate_has_next()
- *
- * Purpose: Determine if a context iterator has a next element
- *
- * Return:  1 if another element exists
- *          0 if no additional elements exist
- */
-cc_int32 
-cci_context_iterate_has_next(cc_context_iterate_t *iterate) 
-{
-    if ( iterate == NULL )
-        return 0;
-    
-    return cci_generic_iterate_has_next((cc_generic_iterate_t*)iterate);
-}
-
-/**
- * cci_context_iterate_next()
- *
- * Purpose: Retrieve the next element from a context iterator and advance
- *          the iterator
- *
- * Return:  non-NULL, the next element in the iterator
- *          NULL, the iterator list is empty or iterator is invalid
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32
-cci_context_iterate_next(cc_context_iterate_t *iterate, cc_context_list_node_t ** nodepp)
-{
-    if ( iterate == NULL || nodepp == NULL)
-        return ccErrBadParam;
-    
-    return cci_generic_iterate_next((cc_generic_iterate_t*)iterate,(cc_context_list_node_t**)nodepp);
-}
-
-/**
- * cci_ccache_iterate_has_next()
- *
- * Purpose: Determine if a cache iterator has a next element
- *
- * Return:  1 if another element exists
- *          0 if no additional elements exist
- *         -1 if error
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32 
-cci_ccache_iterate_has_next(cc_ccache_iterate_t *iterate) 
-{
-    if ( iterate == NULL )
-        return 0;
-    return cci_generic_iterate_has_next((cc_generic_iterate_t*)iterate);
-}
-
-/**
- * cci_ccache_iterate_next()
- * 
- * Purpose: Retrieve the next element from a ccache iterator and advance
- *          the iterator
- *
- * Return:  non-NULL, the next element in the iterator
- *          NULL, the iterator list is empty or iterator is invalid
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32
-cci_ccache_iterate_next(cc_ccache_iterate_t *iterate, cc_ccache_list_node_t ** nodepp)
-{
-    if ( iterate == NULL || nodepp == NULL)
-        return ccErrBadParam;
-    
-    return cci_generic_iterate_next((cc_generic_iterate_t*)iterate, (cc_ccache_list_node_t**)nodepp);
-}
-
-/**
- * cci_credentials_iterate_has_next()
- *
- * Purpose: Determine if a credentials iterator has a next element
- *
- * Return:  1 if another element exists
- *          0 if no additional elements exist
- *         -1 if error
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32 
-cci_credentials_iterate_has_next(cc_credentials_iterate_t *iterate) 
-{
-    if ( iterate == NULL )
-        return 0;
-    
-    return cci_generic_iterate_has_next((cc_generic_iterate_t*)iterate);
-}
-
-/**
- * cci_credentials_iterate_next()
- * 
- * Purpose: Retrieve the next element from a credentials iterator and advance
- *          the iterator
- *
- * Return:  non-NULL, the next element in the iterator
- *          NULL, the iterator list is empty or iterator is invalid
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32
-cci_credentials_iterate_next(cc_credentials_iterate_t *iterate, cc_credentials_list_node_t** nodepp) 
-{
-    if ( iterate == NULL || nodepp == NULL )
-        return ccErrBadParam;
-    return cci_generic_iterate_next((cc_generic_iterate_t*)iterate, (cc_credentials_list_node_t**)nodepp);
-}
-
-/**
- * cci_generic_list_new()
- *
- * Purpose: Allocate new generic list
- *
- * Return:  non-NULL, an empty list
- *          NULL, failure
- *
- * Errors:  ccErrNoMem
- *
- */
-cc_int32
-cci_generic_list_new(cc_generic_list_head_t ** listpp) 
-{
-    cc_generic_list_head_t* ret = (cc_generic_list_head_t *)malloc(sizeof(cc_generic_list_head_t));
-    if (ret == NULL)
-        return ccErrNoMem;
-       
-       ret->type = generic;
-    ret->head = ret->tail = NULL;
-    *listpp = ret;
-
-    return ccNoError;
-}
-
-/**
- * cci_generic_list_append()
- *
- * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' 
- *
- * Return:  non-NULL, a pointer to the newly allocated node
- *          NULL, failure
- *
- * Errors:  ccErrNoMem,ccErrBadParam
- *
- */
-cc_int32
-cci_generic_list_append(cc_generic_list_head_t *head, void *data, cc_uint32 len, cc_generic_list_node_t** nodepp) 
-{
-    cc_generic_list_node_t* new_node;
-
-    if ( data == NULL || len == 0 )
-        return ccErrBadParam;
-
-    new_node = (cc_generic_list_node_t *)malloc(sizeof(cc_generic_list_node_t));
-    if (new_node == NULL)
-        return ccErrNoMem;
-
-    new_node->data = malloc(len);
-    if ( new_node->data == NULL ) {
-        free(new_node);
-        return ccErrNoMem;         
-    }
-    
-    memcpy(new_node->data,data,len);
-    new_node->len = len;
-
-    if (head->head == NULL) { /*empty list*/
-        head->head = new_node;
-        head->tail = new_node;
-           new_node->next = new_node->prev = NULL;
-    } else {
-        new_node->prev = head->tail;
-        head->tail->next = new_node;
-        head->tail = new_node;
-               new_node->next = NULL;
-    }
-       if (nodepp != NULL)
-           *nodepp = new_node;
-    return ccNoError;
-}
-
-/**
- * cci_generic_list_prepend()
- *
- * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data'
- *
- * Return:  non-NULL, a pointer to the newly allocated node
- *          NULL, failure
- *
- * Errors:  ccErrNoMem, ccErrBadParam
- *
- */
-cc_int32 
-cci_generic_list_prepend(cc_generic_list_head_t *head, void *data, cc_uint32 len, cc_generic_list_node_t** nodepp) 
-{
-    cc_generic_list_node_t* new_node;
-
-    if ( data == NULL || len == 0 )
-        return ccErrBadParam;
-
-    new_node = (cc_generic_list_node_t *)malloc(sizeof(cc_generic_list_node_t));
-    if (new_node == NULL)
-        return ccErrNoMem;
-
-    new_node->data = malloc(len);
-    if ( new_node->data == NULL ) {
-        free(new_node);
-        return ccErrNoMem;
-    }
-    
-    memcpy(new_node->data,data,len);
-    new_node->len = len;
-       
-    if (head->head == NULL) { /*empty list*/
-        head->head = new_node;
-        head->tail = new_node;
-        new_node->prev = new_node->next = NULL;
-    } else {
-        new_node->next = head->head;
-        head->head->prev = new_node;
-        new_node->prev = NULL;
-        head->head = new_node;
-    }
-
-       if (nodepp != NULL)
-               *nodepp = new_node;
-
-    return ccNoError;
-}
-
-/**
- * cci_generic_list_remove_element()
- *
- * Purpose: Remove a node from the list
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32 
-cci_generic_list_remove_element(cc_generic_list_head_t* head, cc_generic_list_node_t* rem) 
-{
-    if (head->head == NULL || rem == NULL)
-        return ccErrBadParam;
-
-    if (head->head == rem && head->tail == rem) { /*removing only element of list*/
-        head->head = head->tail = NULL;
-    } else if (head->head == rem) { /*removing head*/
-        head->head = head->head->next;
-    } else if (head->tail == rem) { /*removing tail*/
-        head->tail = head->tail->prev;
-        head->tail->next = NULL;
-    } else {
-        rem->prev->next = rem->next;
-        rem->next->prev = rem->prev;
-    }
-    free(rem);
-    return ccNoError;
-}
-
-/**
- * cci_generic_free_element()
- *
- * Purpose: Free the memory associated with a node
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32
-cci_generic_free_element(cc_generic_list_node_t* node)
-{
-    if ( node == NULL )
-        return ccErrBadParam;
-
-    if ( node->data ) {
-        free(node->data);
-        node->data = NULL;
-    }
-    node->len = 0;
-    node->next = node->prev = NULL;
-    free(node);
-    return ccNoError;
-}
-
-
-/**
- * cci_generic_list_destroy()
- *
- * Purpose: Deallocate a list and all of its contents
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- */
-cc_int32
-cci_generic_list_destroy(cc_generic_list_head_t* head) 
-{
-    cc_generic_list_node_t *cur, *next;
-    cc_int32 ret = ccNoError;
-
-    if ( head == NULL )
-        return ccErrBadParam;
-       
-    for (cur = head->head; ret == ccNoError && cur != NULL; cur = next) {
-        next = cur->next;
-        ret = cci_generic_free_element(cur);
-    }       
-    free(head);
-    return(ret);
-}
-
-/**
- * cci_context_list_destroy()
- *
- * Purpose: Deallocate a list and all of its contents
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- */
-cc_int32
-cci_context_list_destroy(cc_context_list_head_t* head) 
-{
-    return cci_generic_list_destroy((cc_generic_list_head_t*)head);
-}
-
-/**
- * cci_ccache_list_destroy()
- *
- * Purpose: Deallocate a list and all of its contents
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- */
-cc_int32
-cci_ccache_list_destroy(cc_ccache_list_head_t* head) 
-{
-    return cci_generic_list_destroy((cc_generic_list_head_t*)head);
-}
-
-/**
- * cci_credentials_list_destroy()
- *
- * Purpose: Deallocate a list and all of its contents
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- */
-cc_int32
-cci_credentials_list_destroy(cc_credentials_list_head_t* head) 
-{
-    return cci_generic_list_destroy((cc_generic_list_head_t*)head);
-}
-
-/**
- * cci_generic_list_copy()
- *
- * Purpose: Copy a list
- *
- * Return:  non-NULL, a new list
- *          NULL, failure
- *
- * Errors:  ccErrBadParam, ccErrNoMem
- *
- */
-cc_int32
-cci_generic_list_copy(cc_generic_list_head_t* head, cc_generic_list_head_t** headpp) 
-{
-    cc_generic_list_head_t* copy;
-    cc_generic_list_node_t *src_node, *dst_node;
-    cc_int32 code;
-
-    if (head == NULL || headpp == NULL)
-        return ccErrBadParam;
-
-    code = cci_generic_list_new(&copy);
-    if (code != ccNoError)
-        return code;
-
-    for (src_node = head->head; src_node != NULL; src_node = src_node->next) {
-        code = cci_generic_list_append(copy, src_node->data, src_node->len, &dst_node);
-        if (code != ccNoError) {
-            cci_generic_list_destroy(copy);
-            return code;
-        }
-    }
-    *headpp = copy;
-    return ccNoError;
-}
-
-/**
- * cci_context_list_copy()
- *
- * Purpose: Copy a list
- *
- * Return:  non-NULL, a new list
- *          NULL, failure
- *
- * Errors:  ccErrBadParam, ccErrNoMem
- *
- */
-cc_int32
-cci_context_list_copy(cc_context_list_head_t* head, cc_context_list_head_t** headpp ) 
-{
-    return cci_generic_list_copy((cc_generic_list_head_t*)head, (cc_context_list_head_t **)headpp);
-}
-
-/**
- * cci_ccache_list_copy()
- *
- * Purpose: Copy a list
- *
- * Return:  non-NULL, a new list
- *          NULL, failure
- *
- * Errors:  ccErrBadParam, ccErrNoMem
- */
-cc_int32
-cci_ccache_list_copy(cc_ccache_list_head_t* head, cc_ccache_list_head_t** headpp)
-{
-    return cci_generic_list_copy((cc_generic_list_head_t*)head, (cc_ccache_list_head_t **)headpp);
-}
-
-/**
- * cci_credentials_list_copy()
- *
- * Purpose: Copy a list
- *
- * Return:  non-NULL, a new list
- *          NULL, failure
- *
- * Errors:  ccErrBadParam, ccErrNoMem
- *
- */
-cc_int32
-cci_credentials_list_copy(cc_credentials_list_head_t* head, cc_credentials_list_head_t** headpp) 
-{
-    return cci_generic_list_copy((cc_generic_list_head_t*)head, (cc_credentials_list_head_t **)headpp);
-}
-
-
-/**
- * cci_generic_list_iterator()
- *
- * Purpose: Allocate an iterator for the specified list
- *
- * Return:  non-NULL, an iterator
- *          NULL, failure
- *
- * Errors:  ccErrNoMem
- *
- */
-cc_int32
-cci_generic_list_iterator(cc_generic_list_head_t *head, cc_generic_iterate_t** headpp) 
-{
-    cc_generic_iterate_t* iterator;
-
-    if ( head == NULL || headpp == NULL )
-        return ccErrBadParam;
-
-    iterator = (cc_generic_iterate_t*)malloc(sizeof(cc_generic_iterate_t));
-    if (iterator == NULL)
-        return ccErrNoMem;
-    
-    iterator->next = head->head;
-    *headpp = iterator;
-    return ccNoError;
-}
-
-/**
- * cci_generic_free_iterator()
- *
- * Purpose: Deallocate memory associated with an iterator
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32
-cci_generic_free_iterator(cc_generic_iterate_t* iterator)
-{
-    if ( iterator == NULL )
-        return ccErrBadParam;
-
-    iterator->next = NULL;
-    free(iterator);
-    return ccNoError;
-}
-
-
-/**
- * cci_context_list_new()
- *
- * Purpose: Allocate a new context list
- *
- * Return:  non-NULL, a new list
- *          NULL, failure
- *
- * Errors:  ccErrNoMem
- *
- */
-cc_int32
-cci_context_list_new(cc_context_list_head_t ** headpp) 
-{
-    cc_context_list_head_t *ret;
-    
-    if ( headpp == NULL )
-        return ccErrBadParam;
-
-    ret = (cc_context_list_head_t *)malloc(sizeof(cc_context_list_head_t));
-    if (ret == NULL)
-        return ccErrNoMem;
-    ret->head = ret->tail = NULL;
-    *headpp = ret;
-    return ccNoError;
-}
-
-/**
- * cci_context_list_append()
- *
- * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' 
- *
- * Return:  non-NULL, a pointer to the newly allocated node
- *          NULL, failure
- *
- * Errors:  ccErrNoMem,ccErrBadParam
- *
- */
-cc_int32
-cci_context_list_append(cc_context_list_head_t *head, cc_server_context_t *data, cc_context_list_node_t** nodepp) 
-{
-    return cci_generic_list_append((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_context_t), (cc_context_list_node_t**)nodepp);
-}
-
-/**
- * cci_context_list_prepend()
- *
- * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data' 
- *
- * Return:  non-NULL, a pointer to the newly allocated node
- *          NULL, failure
- *
- * Errors:  ccErrNoMem,ccErrBadParam
- *
- */
-cc_int32
-cci_context_list_prepend(cc_context_list_head_t *head, cc_server_context_t *data, cc_context_list_node_t** nodepp ) 
-{
-    return cci_generic_list_prepend((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_context_t), (cc_context_list_node_t**)nodepp);
-}
-
-/**
- * cci_context_list_remove_element
- *
- * Purpose: Remove a node from the list
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- */
-cc_int32
-cci_context_list_remove_element(cc_context_list_head_t* head, cc_context_list_node_t* rem) 
-{
-    return cci_generic_list_remove_element((cc_generic_list_head_t*)head, (cc_generic_list_node_t*)rem);
-}
-
-/**
- * cci_context_list_iterator()
- *
- * Purpose: Allocate an iterator for the specified list
- *
- * Return:  non-NULL, an iterator
- *          NULL, failure
- *
- * Errors:  ccErrNoMem
- *
- */
-cc_int32
-cci_context_list_iterator(cc_context_list_head_t *head, cc_context_iterate_t** iterpp) 
-{
-    cc_context_iterate_t* iterator;
-    
-    if ( head == NULL || iterpp == NULL )
-        return ccErrBadParam;
-
-    iterator = (cc_context_iterate_t*)malloc(sizeof(cc_context_iterate_t));
-    if (iterator == NULL)
-        return ccErrNoMem;
-
-    iterator->next = head->head;
-    *iterpp = iterator;
-    return ccNoError;
-}
-
-/**
- * cci_context_free_iterator()
- *
- * Purpose: Deallocate memory associated with an iterator
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32
-cci_context_free_iterator(cc_context_iterate_t* iterator)
-{
-    if ( iterator == NULL )
-        return ccErrBadParam;
-
-    iterator->next = NULL;
-    free(iterator);
-    return ccNoError;
-}
-
-/**
- * cci_ccache_list_new()
- *
- * Purpose: Allocate a new ccache list
- *
- * Return:  non-NULL, a new list
- *          NULL, failure
- *
- * Errors:  ccErrNoMem
- */
-cc_int32
-cci_ccache_list_new(cc_ccache_list_head_t ** listpp)
-{
-    cc_ccache_list_head_t *ret;
-    
-    if ( listpp == NULL )
-        return ccErrBadParam;
-
-    ret = (cc_ccache_list_head_t *)malloc(sizeof(cc_ccache_list_head_t));
-    if (ret == NULL)
-        return ccErrNoMem;
-
-    ret->head = ret->tail = NULL;
-    *listpp = ret;
-    return ccNoError;
-}
-
-/**
- * cci_ccache_list_append()
- *
- * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' 
- *
- * Return:  non-NULL, a pointer to the newly allocated node
- *          NULL, failure
- *
- * Errors:  ccErrNoMem,ccErrBadParam
- *
- */
-cc_int32
-cci_ccache_list_append(cc_ccache_list_head_t *head, cc_server_ccache_t *data, cc_ccache_list_node_t** nodepp) 
-{
-    return cci_generic_list_append((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_ccache_t), (cc_ccache_list_node_t**)nodepp);
-}
-
-/**
- * cci_ccache_list_prepend()
- *
- * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data' 
- *
- * Return:  non-NULL, a pointer to the newly allocated node
- *          NULL, failure
- *
- * Errors:  ccErrNoMem,ccErrBadParam
- *
- */
-cc_int32
-cci_ccache_list_prepend(cc_ccache_list_head_t *head, cc_server_ccache_t *data, cc_ccache_list_node_t** nodepp) 
-{
-    return cci_generic_list_prepend((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_ccache_t), (cc_ccache_list_node_t**)nodepp);
-}
-
-/**
- * cci_ccache_list_remove_element()
- *
- * Purpose: Remove a node from the list
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32
-cci_ccache_list_remove_element(cc_ccache_list_head_t* head, cc_ccache_list_node_t* rem) 
-{
-    return cci_generic_list_remove_element((cc_generic_list_head_t*)head, (cc_generic_list_node_t*)rem);
-}
-
-/**
- * cci_ccache_list_iterator()
- *
- * Purpose: Allocate an iterator for the specified list
- *
- * Return:  non-NULL, an iterator
- *          NULL, failure
- *
- * Errors:  ccErrNoMem
- *
- */
-cc_int32
-cci_ccache_list_iterator(cc_ccache_list_head_t *head, cc_ccache_iterate_t** iterpp) 
-{
-    cc_ccache_iterate_t* iterator;
-    
-    if ( head == NULL || iterpp == NULL )
-        return ccErrBadParam;
-
-    iterator = (cc_ccache_iterate_t*)malloc(sizeof(cc_ccache_iterate_t));
-    if (iterator == NULL)
-        return ccErrNoMem;
-
-    iterator->next = head->head;
-    *iterpp = iterator;
-    return ccNoError;
-}
-
-/**
- * cci_ccache_free_iterator()
- *
- * Purpose: Deallocate memory associated with an iterator
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32
-cci_ccache_free_iterator(cc_ccache_iterate_t* iterator)
-{
-    if ( iterator == NULL )
-        return ccErrBadParam;
-
-    iterator->next = NULL;
-    free(iterator);
-    return ccNoError;
-}
-
-/**
- * cci_credentials_list_new()
- *
- * Purpose: Allocate a new ccache list
- *
- * Return:  non-NULL, a new list
- *          NULL, failure
- *
- * Errors:  ccErrNoMem
- *
- */
-cc_int32
-cci_credentials_list_new(cc_credentials_list_head_t ** list) 
-{
-    if ( list == NULL )
-        return ccErrBadParam;
-
-    *list = (cc_credentials_list_head_t *)malloc(sizeof(cc_credentials_list_head_t));
-    if (*list == NULL)
-        return ccErrNoMem;
-
-    (*list)->head = (*list)->tail = NULL;
-    return ccNoError;
-}
-
-/**
- * cci_credentials_list_append()
- *
- * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' 
- *
- * Return:  non-NULL, a pointer to the newly allocated node
- *          NULL, failure
- *
- * Errors:  ccErrNoMem,ccErrBadParam
- *
- */
-cc_int32
-cci_credentials_list_append(cc_credentials_list_head_t *head, cc_server_credentials_t *data, cc_credentials_list_node_t** nodepp ) 
-{
-    return cci_generic_list_append((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_credentials_t), (cc_credentials_list_node_t**)nodepp);
-}
-
-/**
- * cci_credentials_list_prepend()
- *
- * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data' 
- *
- * Return:  non-NULL, a pointer to the newly allocated node
- *          NULL, failure
- *
- * Errors:  ccErrNoMem,ccErrBadParam
- *
- */
-cc_int32
-cci_credentials_list_prepend(cc_credentials_list_head_t *head, cc_server_credentials_t *data, cc_credentials_list_node_t** nodepp) 
-{
-    return cci_generic_list_prepend((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_credentials_t), (cc_credentials_list_node_t**)nodepp);
-}
-
-/**
- * cci_credentials_list_remove_element()
- *
- * Purpose: Remove a node from the list
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32 
-cci_credentials_list_remove_element(cc_credentials_list_head_t* head, cc_credentials_list_node_t* rem) 
-{
-    return cci_generic_list_remove_element((cc_generic_list_head_t*)head, (cc_generic_list_node_t*)rem);
-}
-
-/**
- * cci_credentials_list_iterator()
- *
- * Purpose: Allocate an iterator for the specified list
- *
- * Return:  non-NULL, an iterator
- *          NULL, failure
- *
- * Errors:  ccErrNoMem
- *
- */
-cc_int32
-cci_credentials_list_iterator(cc_credentials_list_head_t *head, cc_credentials_iterate_t** iterpp) 
-{
-    cc_credentials_iterate_t* iterator;
-    
-    if ( head == NULL || iterpp == NULL )
-        return ccErrBadParam;
-
-    iterator = (cc_credentials_iterate_t*)malloc(sizeof(cc_credentials_iterate_t));
-    if (iterator == NULL)
-        return ccErrNoMem;
-
-    iterator->next = head->head;
-    *iterpp = iterator;
-    return ccNoError;
-}
-
-/**
- * cci_credentials_free_iterator()
- *
- * Purpose: Deallocate memory associated with an iterator
- *
- * Return:  0, success
- *         -1, failure
- *
- * Errors:  ccErrBadParam
- *
- */
-cc_int32
-cci_credentials_free_iterator(cc_credentials_iterate_t* iterator)
-{
-    if ( iterator == NULL )
-        return ccErrBadParam;
-
-    iterator->next = NULL;
-    free(iterator);
-    return ccNoError;
-}
-
+/* $Copyright:\r
+ *\r
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.\r
+ * \r
+ * All rights reserved.\r
+ * \r
+ * Export of this software from the United States of America may require a\r
+ * specific license from the United States Government.  It is the\r
+ * responsibility of any person or organization contemplating export to\r
+ * obtain such a license before exporting.\r
+ * \r
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute\r
+ * this software and its documentation for any purpose and without fee is\r
+ * hereby granted, provided that the above copyright notice appear in all\r
+ * copies and that both that copyright notice and this permission notice\r
+ * appear in supporting documentation, and that the name of M.I.T. not be\r
+ * used in advertising or publicity pertaining to distribution of the\r
+ * software without specific, written prior permission.  Furthermore if you\r
+ * modify this software you must label your software as modified software\r
+ * and not distribute it in such a fashion that it might be confused with\r
+ * the original MIT software. M.I.T. makes no representations about the\r
+ * suitability of this software for any purpose.  It is provided "as is"\r
+ * without express or implied warranty.\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\r
+ * \r
+ * Individual source code files are copyright MIT, Cygnus Support,\r
+ * OpenVision, Oracle, Sun Soft, FundsXpress, and others.\r
+ * \r
+ * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira,\r
+ * and Zephyr are trademarks of the Massachusetts Institute of Technology\r
+ * (MIT).  No commercial use of these trademarks may be made without prior\r
+ * written permission of MIT.\r
+ * \r
+ * "Commercial use" means use of a name in a product or other for-profit\r
+ * manner.  It does NOT prevent a commercial firm from referring to the MIT\r
+ * trademarks in order to convey information (although in doing so,\r
+ * recognition of their trademark status should be given).\r
+ * $\r
+ */\r
+\r
+\r
+/*\r
+ * Lists implementation.\r
+ * \r
+ */\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <memory.h>\r
+\r
+#include "CredentialsCache.h"\r
+#include "datastore.h"\r
+\r
+/**\r
+ * cci_generic_iterate_has_next()\r
+ *\r
+ * Purpose: Determine if an iterator has a next element\r
+ *\r
+ * Return:  1 if another element exists\r
+ *          0 if no additional elements exist\r
+ *\r
+ * Errors:  None\r
+ *\r
+ */\r
+cc_int32 \r
+cci_generic_iterate_has_next(cc_generic_iterate_t *iterate) \r
+{\r
+    return ((iterate == NULL || iterate->next == NULL) ? 0 : 1);\r
+}\r
+\r
+/**\r
+ * cci_generic_iterate_next()\r
+ *\r
+ * Purpose: Retrieve the next element from an iterator and advance\r
+ *          the iterator\r
+ *\r
+ * Return:  non-NULL, the next element in the iterator\r
+ *          NULL, the iterator list is empty or iterator is invalid\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+cci_generic_iterate_next(cc_generic_iterate_t *iterator, cc_generic_list_node_t** nodepp) \r
+{\r
+    cc_generic_list_node_t* ret;\r
+    \r
+    if (iterator == NULL || nodepp == NULL)\r
+        return ccErrBadParam;\r
+\r
+    ret = iterator->next;\r
+    if (iterator->next != NULL)\r
+        iterator->next = iterator->next->next;\r
+\r
+    *nodepp = ret;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_context_iterate_has_next()\r
+ *\r
+ * Purpose: Determine if a context iterator has a next element\r
+ *\r
+ * Return:  1 if another element exists\r
+ *          0 if no additional elements exist\r
+ */\r
+cc_int32 \r
+ccs_context_iterate_has_next(cc_context_iterate_t *iterate) \r
+{\r
+    if ( iterate == NULL )\r
+        return 0;\r
+    \r
+    return cci_generic_iterate_has_next((cc_generic_iterate_t*)iterate);\r
+}\r
+\r
+/**\r
+ * ccs_context_iterate_next()\r
+ *\r
+ * Purpose: Retrieve the next element from a context iterator and advance\r
+ *          the iterator\r
+ *\r
+ * Return:  non-NULL, the next element in the iterator\r
+ *          NULL, the iterator list is empty or iterator is invalid\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_context_iterate_next(cc_context_iterate_t *iterate, cc_context_list_node_t ** nodepp)\r
+{\r
+    if ( iterate == NULL || nodepp == NULL)\r
+        return ccErrBadParam;\r
+    \r
+    return cci_generic_iterate_next((cc_generic_iterate_t*)iterate,(cc_context_list_node_t**)nodepp);\r
+}\r
+\r
+/**\r
+ * ccs_ccache_iterate_has_next()\r
+ *\r
+ * Purpose: Determine if a cache iterator has a next element\r
+ *\r
+ * Return:  1 if another element exists\r
+ *          0 if no additional elements exist\r
+ *         -1 if error\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32 \r
+ccs_ccache_iterate_has_next(cc_ccache_iterate_t *iterate) \r
+{\r
+    if ( iterate == NULL )\r
+        return 0;\r
+    return cci_generic_iterate_has_next((cc_generic_iterate_t*)iterate);\r
+}\r
+\r
+/**\r
+ * ccs_ccache_iterate_next()\r
+ * \r
+ * Purpose: Retrieve the next element from a ccache iterator and advance\r
+ *          the iterator\r
+ *\r
+ * Return:  non-NULL, the next element in the iterator\r
+ *          NULL, the iterator list is empty or iterator is invalid\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_ccache_iterate_next(cc_ccache_iterate_t *iterate, cc_ccache_list_node_t ** nodepp)\r
+{\r
+    if ( iterate == NULL || nodepp == NULL)\r
+        return ccErrBadParam;\r
+    \r
+    return cci_generic_iterate_next((cc_generic_iterate_t*)iterate, (cc_ccache_list_node_t**)nodepp);\r
+}\r
+\r
+/**\r
+ * ccs_credentials_iterate_has_next()\r
+ *\r
+ * Purpose: Determine if a credentials iterator has a next element\r
+ *\r
+ * Return:  1 if another element exists\r
+ *          0 if no additional elements exist\r
+ *         -1 if error\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32 \r
+ccs_credentials_iterate_has_next(cc_credentials_iterate_t *iterate) \r
+{\r
+    if ( iterate == NULL )\r
+        return 0;\r
+    \r
+    return cci_generic_iterate_has_next((cc_generic_iterate_t*)iterate);\r
+}\r
+\r
+/**\r
+ * ccs_credentials_iterate_next()\r
+ * \r
+ * Purpose: Retrieve the next element from a credentials iterator and advance\r
+ *          the iterator\r
+ *\r
+ * Return:  non-NULL, the next element in the iterator\r
+ *          NULL, the iterator list is empty or iterator is invalid\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_credentials_iterate_next(cc_credentials_iterate_t *iterate, cc_credentials_list_node_t** nodepp) \r
+{\r
+    if ( iterate == NULL || nodepp == NULL )\r
+        return ccErrBadParam;\r
+    return cci_generic_iterate_next((cc_generic_iterate_t*)iterate, (cc_credentials_list_node_t**)nodepp);\r
+}\r
+\r
+/**\r
+ * cci_generic_list_new()\r
+ *\r
+ * Purpose: Allocate new generic list\r
+ *\r
+ * Return:  non-NULL, an empty list\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem\r
+ *\r
+ */\r
+cc_int32\r
+cci_generic_list_new(cc_generic_list_head_t ** listpp) \r
+{\r
+    cc_generic_list_head_t* ret = (cc_generic_list_head_t *)malloc(sizeof(cc_generic_list_head_t));\r
+    if (ret == NULL)\r
+        return ccErrNoMem;\r
+       \r
+       ret->type = generic;\r
+    ret->head = ret->tail = NULL;\r
+    *listpp = ret;\r
+\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * cci_generic_list_append()\r
+ *\r
+ * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' \r
+ *\r
+ * Return:  non-NULL, a pointer to the newly allocated node\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem,ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+cci_generic_list_append(cc_generic_list_head_t *head, void *data, cc_uint32 len, cc_generic_list_node_t** nodepp) \r
+{\r
+    cc_generic_list_node_t* new_node;\r
+\r
+    if ( data == NULL || len == 0 )\r
+        return ccErrBadParam;\r
+\r
+    new_node = (cc_generic_list_node_t *)malloc(sizeof(cc_generic_list_node_t));\r
+    if (new_node == NULL)\r
+        return ccErrNoMem;\r
+\r
+    new_node->data = malloc(len);\r
+    if ( new_node->data == NULL ) {\r
+        free(new_node);\r
+        return ccErrNoMem;         \r
+    }\r
+    \r
+    memcpy(new_node->data,data,len);\r
+    new_node->len = len;\r
+\r
+    if (head->head == NULL) { /*empty list*/\r
+        head->head = new_node;\r
+        head->tail = new_node;\r
+           new_node->next = new_node->prev = NULL;\r
+    } else {\r
+        new_node->prev = head->tail;\r
+        head->tail->next = new_node;\r
+        head->tail = new_node;\r
+               new_node->next = NULL;\r
+    }\r
+       if (nodepp != NULL)\r
+           *nodepp = new_node;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * cci_generic_list_prepend()\r
+ *\r
+ * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data'\r
+ *\r
+ * Return:  non-NULL, a pointer to the newly allocated node\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem, ccErrBadParam\r
+ *\r
+ */\r
+cc_int32 \r
+cci_generic_list_prepend(cc_generic_list_head_t *head, void *data, cc_uint32 len, cc_generic_list_node_t** nodepp) \r
+{\r
+    cc_generic_list_node_t* new_node;\r
+\r
+    if ( data == NULL || len == 0 )\r
+        return ccErrBadParam;\r
+\r
+    new_node = (cc_generic_list_node_t *)malloc(sizeof(cc_generic_list_node_t));\r
+    if (new_node == NULL)\r
+        return ccErrNoMem;\r
+\r
+    new_node->data = malloc(len);\r
+    if ( new_node->data == NULL ) {\r
+        free(new_node);\r
+        return ccErrNoMem;\r
+    }\r
+    \r
+    memcpy(new_node->data,data,len);\r
+    new_node->len = len;\r
+       \r
+    if (head->head == NULL) { /*empty list*/\r
+        head->head = new_node;\r
+        head->tail = new_node;\r
+        new_node->prev = new_node->next = NULL;\r
+    } else {\r
+        new_node->next = head->head;\r
+        head->head->prev = new_node;\r
+        new_node->prev = NULL;\r
+        head->head = new_node;\r
+    }\r
+\r
+       if (nodepp != NULL)\r
+               *nodepp = new_node;\r
+\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * cci_generic_list_remove_element()\r
+ *\r
+ * Purpose: Remove a node from the list\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32 \r
+cci_generic_list_remove_element(cc_generic_list_head_t* head, cc_generic_list_node_t* rem) \r
+{\r
+    if (head->head == NULL || rem == NULL)\r
+        return ccErrBadParam;\r
+\r
+    if (head->head == rem && head->tail == rem) { /*removing only element of list*/\r
+        head->head = head->tail = NULL;\r
+    } else if (head->head == rem) { /*removing head*/\r
+        head->head = head->head->next;\r
+    } else if (head->tail == rem) { /*removing tail*/\r
+        head->tail = head->tail->prev;\r
+        head->tail->next = NULL;\r
+    } else {\r
+        rem->prev->next = rem->next;\r
+        rem->next->prev = rem->prev;\r
+    }\r
+    free(rem);\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * cci_generic_free_element()\r
+ *\r
+ * Purpose: Free the memory associated with a node\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+cci_generic_free_element(cc_generic_list_node_t* node)\r
+{\r
+    if ( node == NULL )\r
+        return ccErrBadParam;\r
+\r
+    if ( node->data ) {\r
+        free(node->data);\r
+        node->data = NULL;\r
+    }\r
+    node->len = 0;\r
+    node->next = node->prev = NULL;\r
+    free(node);\r
+    return ccNoError;\r
+}\r
+\r
+\r
+/**\r
+ * cci_generic_list_destroy()\r
+ *\r
+ * Purpose: Deallocate a list and all of its contents\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ */\r
+cc_int32\r
+cci_generic_list_destroy(cc_generic_list_head_t* head) \r
+{\r
+    cc_generic_list_node_t *cur, *next;\r
+    cc_int32 ret = ccNoError;\r
+\r
+    if ( head == NULL )\r
+        return ccErrBadParam;\r
+       \r
+    for (cur = head->head; ret == ccNoError && cur != NULL; cur = next) {\r
+        next = cur->next;\r
+        ret = cci_generic_free_element(cur);\r
+    }       \r
+    free(head);\r
+    return(ret);\r
+}\r
+\r
+/**\r
+ * ccs_context_list_destroy()\r
+ *\r
+ * Purpose: Deallocate a list and all of its contents\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ */\r
+cc_int32\r
+ccs_context_list_destroy(cc_context_list_head_t* head) \r
+{\r
+    return cci_generic_list_destroy((cc_generic_list_head_t*)head);\r
+}\r
+\r
+/**\r
+ * ccs_ccache_list_destroy()\r
+ *\r
+ * Purpose: Deallocate a list and all of its contents\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ */\r
+cc_int32\r
+ccs_ccache_list_destroy(cc_ccache_list_head_t* head) \r
+{\r
+    return cci_generic_list_destroy((cc_generic_list_head_t*)head);\r
+}\r
+\r
+/**\r
+ * ccs_credentials_list_destroy()\r
+ *\r
+ * Purpose: Deallocate a list and all of its contents\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ */\r
+cc_int32\r
+ccs_credentials_list_destroy(cc_credentials_list_head_t* head) \r
+{\r
+    return cci_generic_list_destroy((cc_generic_list_head_t*)head);\r
+}\r
+\r
+/**\r
+ * cci_generic_list_copy()\r
+ *\r
+ * Purpose: Copy a list\r
+ *\r
+ * Return:  non-NULL, a new list\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrBadParam, ccErrNoMem\r
+ *\r
+ */\r
+cc_int32\r
+cci_generic_list_copy(cc_generic_list_head_t* head, cc_generic_list_head_t** headpp) \r
+{\r
+    cc_generic_list_head_t* copy;\r
+    cc_generic_list_node_t *src_node, *dst_node;\r
+    cc_int32 code;\r
+\r
+    if (head == NULL || headpp == NULL)\r
+        return ccErrBadParam;\r
+\r
+    code = cci_generic_list_new(&copy);\r
+    if (code != ccNoError)\r
+        return code;\r
+\r
+    for (src_node = head->head; src_node != NULL; src_node = src_node->next) {\r
+        code = cci_generic_list_append(copy, src_node->data, src_node->len, &dst_node);\r
+        if (code != ccNoError) {\r
+            cci_generic_list_destroy(copy);\r
+            return code;\r
+        }\r
+    }\r
+    *headpp = copy;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_context_list_copy()\r
+ *\r
+ * Purpose: Copy a list\r
+ *\r
+ * Return:  non-NULL, a new list\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrBadParam, ccErrNoMem\r
+ *\r
+ */\r
+cc_int32\r
+ccs_context_list_copy(cc_context_list_head_t* head, cc_context_list_head_t** headpp ) \r
+{\r
+    return cci_generic_list_copy((cc_generic_list_head_t*)head, (cc_context_list_head_t **)headpp);\r
+}\r
+\r
+/**\r
+ * ccs_ccache_list_copy()\r
+ *\r
+ * Purpose: Copy a list\r
+ *\r
+ * Return:  non-NULL, a new list\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrBadParam, ccErrNoMem\r
+ */\r
+cc_int32\r
+ccs_ccache_list_copy(cc_ccache_list_head_t* head, cc_ccache_list_head_t** headpp)\r
+{\r
+    return cci_generic_list_copy((cc_generic_list_head_t*)head, (cc_ccache_list_head_t **)headpp);\r
+}\r
+\r
+/**\r
+ * ccs_credentials_list_copy()\r
+ *\r
+ * Purpose: Copy a list\r
+ *\r
+ * Return:  non-NULL, a new list\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrBadParam, ccErrNoMem\r
+ *\r
+ */\r
+cc_int32\r
+ccs_credentials_list_copy(cc_credentials_list_head_t* head, cc_credentials_list_head_t** headpp) \r
+{\r
+    return cci_generic_list_copy((cc_generic_list_head_t*)head, (cc_credentials_list_head_t **)headpp);\r
+}\r
+\r
+\r
+/**\r
+ * cci_generic_list_iterator()\r
+ *\r
+ * Purpose: Allocate an iterator for the specified list\r
+ *\r
+ * Return:  non-NULL, an iterator\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem\r
+ *\r
+ */\r
+cc_int32\r
+cci_generic_list_iterator(cc_generic_list_head_t *head, cc_generic_iterate_t** headpp) \r
+{\r
+    cc_generic_iterate_t* iterator;\r
+\r
+    if ( head == NULL || headpp == NULL )\r
+        return ccErrBadParam;\r
+\r
+    iterator = (cc_generic_iterate_t*)malloc(sizeof(cc_generic_iterate_t));\r
+    if (iterator == NULL)\r
+        return ccErrNoMem;\r
+    \r
+    iterator->next = head->head;\r
+    *headpp = iterator;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * cci_generic_free_iterator()\r
+ *\r
+ * Purpose: Deallocate memory associated with an iterator\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+cci_generic_free_iterator(cc_generic_iterate_t* iterator)\r
+{\r
+    if ( iterator == NULL )\r
+        return ccErrBadParam;\r
+\r
+    iterator->next = NULL;\r
+    free(iterator);\r
+    return ccNoError;\r
+}\r
+\r
+\r
+/**\r
+ * ccs_context_list_new()\r
+ *\r
+ * Purpose: Allocate a new context list\r
+ *\r
+ * Return:  non-NULL, a new list\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem\r
+ *\r
+ */\r
+cc_int32\r
+ccs_context_list_new(cc_context_list_head_t ** headpp) \r
+{\r
+    cc_context_list_head_t *ret;\r
+    \r
+    if ( headpp == NULL )\r
+        return ccErrBadParam;\r
+\r
+    ret = (cc_context_list_head_t *)malloc(sizeof(cc_context_list_head_t));\r
+    if (ret == NULL)\r
+        return ccErrNoMem;\r
+    ret->head = ret->tail = NULL;\r
+    *headpp = ret;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_context_list_append()\r
+ *\r
+ * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' \r
+ *\r
+ * Return:  non-NULL, a pointer to the newly allocated node\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem,ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_context_list_append(cc_context_list_head_t *head, cc_server_context_t *data, cc_context_list_node_t** nodepp) \r
+{\r
+    return cci_generic_list_append((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_context_t), (cc_context_list_node_t**)nodepp);\r
+}\r
+\r
+/**\r
+ * ccs_context_list_prepend()\r
+ *\r
+ * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data' \r
+ *\r
+ * Return:  non-NULL, a pointer to the newly allocated node\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem,ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_context_list_prepend(cc_context_list_head_t *head, cc_server_context_t *data, cc_context_list_node_t** nodepp ) \r
+{\r
+    return cci_generic_list_prepend((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_context_t), (cc_context_list_node_t**)nodepp);\r
+}\r
+\r
+/**\r
+ * ccs_context_list_remove_element\r
+ *\r
+ * Purpose: Remove a node from the list\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ */\r
+cc_int32\r
+ccs_context_list_remove_element(cc_context_list_head_t* head, cc_context_list_node_t* rem) \r
+{\r
+    return cci_generic_list_remove_element((cc_generic_list_head_t*)head, (cc_generic_list_node_t*)rem);\r
+}\r
+\r
+/**\r
+ * ccs_context_list_iterator()\r
+ *\r
+ * Purpose: Allocate an iterator for the specified list\r
+ *\r
+ * Return:  non-NULL, an iterator\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem\r
+ *\r
+ */\r
+cc_int32\r
+ccs_context_list_iterator(cc_context_list_head_t *head, cc_context_iterate_t** iterpp) \r
+{\r
+    cc_context_iterate_t* iterator;\r
+    \r
+    if ( head == NULL || iterpp == NULL )\r
+        return ccErrBadParam;\r
+\r
+    iterator = (cc_context_iterate_t*)malloc(sizeof(cc_context_iterate_t));\r
+    if (iterator == NULL)\r
+        return ccErrNoMem;\r
+\r
+    iterator->next = head->head;\r
+    *iterpp = iterator;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_context_free_iterator()\r
+ *\r
+ * Purpose: Deallocate memory associated with an iterator\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_context_free_iterator(cc_context_iterate_t* iterator)\r
+{\r
+    if ( iterator == NULL )\r
+        return ccErrBadParam;\r
+\r
+    iterator->next = NULL;\r
+    free(iterator);\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_ccache_list_new()\r
+ *\r
+ * Purpose: Allocate a new ccache list\r
+ *\r
+ * Return:  non-NULL, a new list\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem\r
+ */\r
+cc_int32\r
+ccs_ccache_list_new(cc_ccache_list_head_t ** listpp)\r
+{\r
+    cc_ccache_list_head_t *ret;\r
+    \r
+    if ( listpp == NULL )\r
+        return ccErrBadParam;\r
+\r
+    ret = (cc_ccache_list_head_t *)malloc(sizeof(cc_ccache_list_head_t));\r
+    if (ret == NULL)\r
+        return ccErrNoMem;\r
+\r
+    ret->head = ret->tail = NULL;\r
+    *listpp = ret;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_ccache_list_append()\r
+ *\r
+ * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' \r
+ *\r
+ * Return:  non-NULL, a pointer to the newly allocated node\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem,ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_ccache_list_append(cc_ccache_list_head_t *head, cc_server_ccache_t *data, cc_ccache_list_node_t** nodepp) \r
+{\r
+    return cci_generic_list_append((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_ccache_t), (cc_ccache_list_node_t**)nodepp);\r
+}\r
+\r
+/**\r
+ * ccs_ccache_list_prepend()\r
+ *\r
+ * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data' \r
+ *\r
+ * Return:  non-NULL, a pointer to the newly allocated node\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem,ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_ccache_list_prepend(cc_ccache_list_head_t *head, cc_server_ccache_t *data, cc_ccache_list_node_t** nodepp) \r
+{\r
+    return cci_generic_list_prepend((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_ccache_t), (cc_ccache_list_node_t**)nodepp);\r
+}\r
+\r
+/**\r
+ * ccs_ccache_list_remove_element()\r
+ *\r
+ * Purpose: Remove a node from the list\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_ccache_list_remove_element(cc_ccache_list_head_t* head, cc_ccache_list_node_t* rem) \r
+{\r
+    return cci_generic_list_remove_element((cc_generic_list_head_t*)head, (cc_generic_list_node_t*)rem);\r
+}\r
+\r
+/**\r
+ * ccs_ccache_list_iterator()\r
+ *\r
+ * Purpose: Allocate an iterator for the specified list\r
+ *\r
+ * Return:  non-NULL, an iterator\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem\r
+ *\r
+ */\r
+cc_int32\r
+ccs_ccache_list_iterator(cc_ccache_list_head_t *head, cc_ccache_iterate_t** iterpp) \r
+{\r
+    cc_ccache_iterate_t* iterator;\r
+    \r
+    if ( head == NULL || iterpp == NULL )\r
+        return ccErrBadParam;\r
+\r
+    iterator = (cc_ccache_iterate_t*)malloc(sizeof(cc_ccache_iterate_t));\r
+    if (iterator == NULL)\r
+        return ccErrNoMem;\r
+\r
+    iterator->next = head->head;\r
+    *iterpp = iterator;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_ccache_free_iterator()\r
+ *\r
+ * Purpose: Deallocate memory associated with an iterator\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_ccache_free_iterator(cc_ccache_iterate_t* iterator)\r
+{\r
+    if ( iterator == NULL )\r
+        return ccErrBadParam;\r
+\r
+    iterator->next = NULL;\r
+    free(iterator);\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_credentials_list_new()\r
+ *\r
+ * Purpose: Allocate a new ccache list\r
+ *\r
+ * Return:  non-NULL, a new list\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem\r
+ *\r
+ */\r
+cc_int32\r
+ccs_credentials_list_new(cc_credentials_list_head_t ** list) \r
+{\r
+    if ( list == NULL )\r
+        return ccErrBadParam;\r
+\r
+    *list = (cc_credentials_list_head_t *)malloc(sizeof(cc_credentials_list_head_t));\r
+    if (*list == NULL)\r
+        return ccErrNoMem;\r
+\r
+    (*list)->head = (*list)->tail = NULL;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_credentials_list_append()\r
+ *\r
+ * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' \r
+ *\r
+ * Return:  non-NULL, a pointer to the newly allocated node\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem,ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_credentials_list_append(cc_credentials_list_head_t *head, cc_server_credentials_t *data, cc_credentials_list_node_t** nodepp ) \r
+{\r
+    return cci_generic_list_append((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_credentials_t), (cc_credentials_list_node_t**)nodepp);\r
+}\r
+\r
+/**\r
+ * ccs_credentials_list_prepend()\r
+ *\r
+ * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data' \r
+ *\r
+ * Return:  non-NULL, a pointer to the newly allocated node\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem,ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_credentials_list_prepend(cc_credentials_list_head_t *head, cc_server_credentials_t *data, cc_credentials_list_node_t** nodepp) \r
+{\r
+    return cci_generic_list_prepend((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_credentials_t), (cc_credentials_list_node_t**)nodepp);\r
+}\r
+\r
+/**\r
+ * ccs_credentials_list_remove_element()\r
+ *\r
+ * Purpose: Remove a node from the list\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32 \r
+ccs_credentials_list_remove_element(cc_credentials_list_head_t* head, cc_credentials_list_node_t* rem) \r
+{\r
+    return cci_generic_list_remove_element((cc_generic_list_head_t*)head, (cc_generic_list_node_t*)rem);\r
+}\r
+\r
+/**\r
+ * ccs_credentials_list_iterator()\r
+ *\r
+ * Purpose: Allocate an iterator for the specified list\r
+ *\r
+ * Return:  non-NULL, an iterator\r
+ *          NULL, failure\r
+ *\r
+ * Errors:  ccErrNoMem\r
+ *\r
+ */\r
+cc_int32\r
+ccs_credentials_list_iterator(cc_credentials_list_head_t *head, cc_credentials_iterate_t** iterpp) \r
+{\r
+    cc_credentials_iterate_t* iterator;\r
+    \r
+    if ( head == NULL || iterpp == NULL )\r
+        return ccErrBadParam;\r
+\r
+    iterator = (cc_credentials_iterate_t*)malloc(sizeof(cc_credentials_iterate_t));\r
+    if (iterator == NULL)\r
+        return ccErrNoMem;\r
+\r
+    iterator->next = head->head;\r
+    *iterpp = iterator;\r
+    return ccNoError;\r
+}\r
+\r
+/**\r
+ * ccs_credentials_free_iterator()\r
+ *\r
+ * Purpose: Deallocate memory associated with an iterator\r
+ *\r
+ * Return:  0, success\r
+ *         -1, failure\r
+ *\r
+ * Errors:  ccErrBadParam\r
+ *\r
+ */\r
+cc_int32\r
+ccs_credentials_free_iterator(cc_credentials_iterate_t* iterator)\r
+{\r
+    if ( iterator == NULL )\r
+        return ccErrBadParam;\r
+\r
+    iterator->next = NULL;\r
+    free(iterator);\r
+    return ccNoError;\r
+}\r
+\r
index a92c60636bfc032fdbc82580cd7f642a23178d46..4f119f969ff4446b6df05fe76a32476b8a12952a 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -51,6 +51,7 @@
 
 #include "CredentialsCache.h"
 #include "rpc_auth.h"
+#include "generic_lists.h"
 
 enum cc_list_type {
     generic = 0,
@@ -59,36 +60,6 @@ enum cc_list_type {
     credentials
 };
 
-struct cc_generic_list_node_t {
-    cc_uint8*                          data;
-    cc_uint32                          len;
-    struct cc_generic_list_node_t*     next;
-    struct cc_generic_list_node_t*     prev;
-};
-typedef struct cc_generic_list_node_t cc_generic_list_node_t;
-
-struct cc_generic_list_head_t {
-    enum cc_list_type                   type;
-    cc_generic_list_node_t*            head;
-    cc_generic_list_node_t*            tail; 
-};      
-typedef struct cc_generic_list_head_t cc_generic_list_head_t;
-
-
-struct cc_generic_iterate_t {
-    cc_generic_list_node_t*            next;
-};
-typedef struct cc_generic_iterate_t cc_generic_iterate_t;
-
-typedef cc_generic_list_head_t cc_context_list_head_t;
-typedef cc_generic_list_node_t cc_context_list_node_t;
-
-typedef cc_generic_list_head_t cc_ccache_list_head_t;
-typedef cc_generic_list_node_t cc_ccache_list_node_t;
-
-typedef cc_generic_list_head_t cc_credentials_list_head_t;
-typedef cc_generic_list_node_t cc_credentials_list_node_t;
-
 struct cc_context_iterate_t {
     cc_context_list_node_t*    next;
 };
@@ -104,7 +75,7 @@ struct cc_credentials_iterate_t {
 };
 typedef struct cc_credentials_iterate_t cc_credentials_iterate_t;
 
-struct cc_lock_t {
+struct cc_lock {
     cc_uint32                           read_locks;             /* count of read locks (>= 0) */
     cc_uint32                           write_locks;            /* count of write locks (0 or 1) */
     void *                              platform_data;          /* platform specific implementation data */
@@ -118,7 +89,7 @@ struct cc_server_context_t {
     cc_int32                           api_version;            /*Version our client passed in on init (ccapi_version_X) */
     cc_auth_info_t*                    auth_info;              /*auth info passed in from RPC*/
     cc_session_info_t*                 session_info;           /*session info passed in from RPC*/
-    cc_time_t                          changed;                /*date of last change to this context*/
+    cc_time64                          changed;                /*date of last change to this context*/
     cc_int32                            error;                  /*last error code*/
     cc_lock_t                           locks;                  /*are we locked?*/
 };                                                              
@@ -129,10 +100,10 @@ struct cc_server_ccache_t {
     char*                              principal_v4;           /*v4 principal associated with this cache*/
     char*                              principal_v5;           /*v5 principal associated with this cache*/
     cc_uint32                          versions;               /*versions of creds supported (from cc_credentials enum in CredentialsCache.h)*/
-    cc_time_t                          changed;                /*date of last change to ccache*/
+    cc_time64                          changed;                /*date of last change to ccache*/
     cc_int32                           kdc_set;                /*is the KDC time offset initialized?*/
-    cc_time_t                          kdc_offset;             /*offset of our clock relative kdc*/
-    cc_time_t                          last_default;           /*the last date when we were default*/
+    cc_time64                          kdc_offset;             /*offset of our clock relative kdc*/
+    cc_time64                          last_default;           /*the last date when we were default*/
     cc_int32                           is_default;             /*is this the default cred on this ccache?*/
     cc_generic_list_head_t*            active_iterators;       /*iterators which clients have opened on this cache*/
     cc_credentials_list_head_t*        creds;                          /*list of creds stored in this ccache*/
@@ -150,82 +121,69 @@ typedef struct cc_server_credentials_t cc_server_credentials_t;
 
 /*Note: cci means Credential Cache Internal, to differentiate from exported API macros*/
 
-cc_int32 cci_generic_iterate_has_next(cc_generic_iterate_t *iterate);
-cc_int32 cci_generic_iterate_next(cc_generic_iterate_t *iterate, cc_generic_list_node_t**);
-
-cc_int32 cci_generic_list_new(cc_generic_list_head_t **);
-cc_int32 cci_generic_list_append(cc_generic_list_head_t *head, void *data, cc_uint32 len, cc_generic_list_node_t**);
-cc_int32 cci_generic_list_prepend(cc_generic_list_head_t *head, void *data, cc_uint32 len, cc_generic_list_node_t**);
-cc_int32 cci_generic_list_remove_element(cc_generic_list_head_t* head, cc_generic_list_node_t* rem);
-cc_int32 cci_generic_free_element(cc_generic_list_node_t* node);
-cc_int32 cci_generic_list_destroy(cc_generic_list_head_t* head);
-cc_int32 cci_generic_list_copy(cc_generic_list_head_t* head, cc_generic_list_head_t**);
-cc_int32 cci_generic_list_iterator(cc_generic_list_head_t *head, cc_generic_iterate_t**);
-cc_int32 cci_generic_free_iterator(cc_generic_iterate_t* iterator);
-
-cc_int32 cci_context_iterate_has_next(struct cc_context_iterate_t *iterate);
-cc_int32 cci_context_iterate_next(struct cc_context_iterate_t *iterate, cc_context_list_node_t**);
-
-cc_int32 cci_ccache_iterate_has_next(struct cc_ccache_iterate_t *iterate);
-cc_int32 cci_ccache_iterate_next(struct cc_ccache_iterate_t *iterate, cc_ccache_list_node_t**);
-
-cc_int32 cci_credentials_iterate_has_next(cc_credentials_iterate_t *iterate);
-cc_int32 cci_credentials_iterate_next(cc_credentials_iterate_t *iterate, cc_credentials_list_node_t **);
-
-cc_int32 cci_context_list_new(cc_context_list_head_t**);
-cc_int32 cci_context_list_append(cc_context_list_head_t *head, cc_server_context_t *data, cc_context_list_node_t**);
-cc_int32 cci_context_list_prepend(cc_context_list_head_t *head, cc_server_context_t *data, cc_context_list_node_t**);
-cc_int32 cci_context_list_remove_element(cc_context_list_head_t* head, cc_context_list_node_t* rem);
-cc_int32 cci_context_list_iterator(cc_context_list_head_t *head, struct cc_context_iterate_t**);
-cc_int32 cci_context_free_iterator(struct cc_context_iterate_t *iterator);
-cc_int32 cci_context_list_destroy(cc_context_list_head_t* head) ;
-cc_int32 cci_context_list_copy(cc_context_list_head_t* head, cc_context_list_head_t**);
-
-cc_int32 cci_ccache_list_new(cc_ccache_list_head_t**);
-cc_int32 cci_ccache_list_append(cc_ccache_list_head_t *head, cc_server_ccache_t *data, cc_ccache_list_node_t**);
-cc_int32 cci_ccache_list_prepend(cc_ccache_list_head_t *head, cc_server_ccache_t *data, cc_ccache_list_node_t**);
-cc_int32 cci_ccache_list_remove_element(cc_ccache_list_head_t* head, cc_ccache_list_node_t* rem);
-cc_int32 cci_ccache_list_iterator(cc_ccache_list_head_t *head, struct cc_ccache_iterate_t**);
-cc_int32 cci_ccache_free_iterator(struct cc_ccache_iterate_t *iterator);
-cc_int32 cci_ccache_list_destroy(cc_ccache_list_head_t* head) ;
-cc_int32 cci_ccache_list_copy(cc_ccache_list_head_t* head, cc_ccache_list_head_t**);
-
-
-cc_int32 cci_credentials_list_new(cc_credentials_list_head_t**);
-cc_int32 cci_credentials_list_append(cc_credentials_list_head_t *head, cc_server_credentials_t *data, cc_credentials_list_node_t**);
-cc_int32 cci_credentials_list_prepend(cc_credentials_list_head_t *head, cc_server_credentials_t *data, cc_credentials_list_node_t**);
-cc_int32 cci_credentials_list_remove_element(cc_credentials_list_head_t* head, cc_credentials_list_node_t* rem);
-cc_int32 cci_credentials_list_iterator(cc_credentials_list_head_t *head, cc_credentials_iterate_t**);
-cc_int32 cci_credentials_free_iterator(cc_credentials_iterate_t* iterator);
-cc_int32 cci_credentials_list_destroy(cc_credentials_list_head_t* head) ;
-cc_int32 cci_credentials_list_copy(cc_credentials_list_head_t* head, cc_credentials_list_head_t**) ;
-
-
-cc_int32 cci_context_new(int api_version, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_server_context_t** ) ;
-cc_int32 cci_context_get_default_ccache_name(cc_server_context_t* ctx, char **);
-cc_int32 cci_context_find_ccache(cc_server_context_t* ctx, char *name, cc_server_ccache_t**);
-cc_int32 cci_context_open_ccache(cc_server_context_t* ctx, char *name, cc_server_ccache_t** );
-cc_int32 cci_context_create_ccache(cc_server_context_t* ctx, char *name, int creds_version, char *principal, cc_server_ccache_t**);
-cc_int32 cci_context_create_default_ccache(cc_server_context_t* ctx, int creds_version, char *principal, cc_server_ccache_t**);
-cc_int32 cci_context_ccache_iterator(cc_server_context_t* ctx, cc_ccache_iterate_t**);
-cc_int32 cci_context_compare(cc_server_context_t* a, cc_server_context_t* b);
-cc_int32 cci_context_destroy(cc_server_context_t* ctx);
-cc_int32 cci_context_rem_ccache(cc_server_context_t* ctx, cc_server_ccache_t* ccache);
-
-cc_int32 cci_ccache_new(char *name, char *principal, int cred_vers, cc_server_ccache_t**);
-cc_int32 cci_ccache_check_version(const cc_server_ccache_t *ccache, const cc_credentials_union* creds, cc_uint32* compat);
-cc_int32 cci_ccache_check_principal(const cc_server_ccache_t *ccache, const cc_credentials_union* creds, cc_uint32* compat);
-cc_int32 cci_ccache_store_creds(cc_server_ccache_t *ccache, const cc_credentials_union* credentials);
-cc_int32 cci_ccache_rem_creds(cc_server_ccache_t *ccache, const cc_credentials_union* credentials);
-cc_int32 cci_ccache_move(cc_server_ccache_t *source, cc_server_ccache_t* destination);
-cc_int32 cci_ccache_get_kdc_time_offset(cc_server_ccache_t* ccache, cc_time_t* offset);
-cc_int32 cci_ccache_set_kdc_time_offset(cc_server_ccache_t* ccache, cc_time_t offset);
-cc_int32 cci_ccache_clear_kdc_time_offset(cc_server_ccache_t* ccache);
-cc_int32 cci_ccache_new_iterator(cc_server_ccache_t* ccache, cc_credentials_iterate_t** iterator);
-cc_int32 cci_ccache_get_principal(cc_server_ccache_t* ccache, cc_int32 version, char ** principal);
-cc_int32 cci_ccache_set_principal(cc_server_ccache_t* ccache, cc_int32 version, char * principal);
-cc_int32 cci_ccache_free_principal(char * principal);
-cc_int32 cci_ccache_destroy(cc_server_ccache_t* ccache);
-void    cci_ccache_changed(cc_server_ccache_t* ccache);
-cc_int32 cci_ccache_compare(cc_server_ccache_t* ccache1, cc_server_ccache_t* ccache2, cc_uint32 *result);
+cc_int32 ccs_context_iterate_has_next(struct cc_context_iterate_t *iterate);
+cc_int32 ccs_context_iterate_next(struct cc_context_iterate_t *iterate, cc_context_list_node_t**);
+
+cc_int32 ccs_ccache_iterate_has_next(struct cc_ccache_iterate_t *iterate);
+cc_int32 ccs_ccache_iterate_next(struct cc_ccache_iterate_t *iterate, cc_ccache_list_node_t**);
+
+cc_int32 ccs_credentials_iterate_has_next(cc_credentials_iterate_t *iterate);
+cc_int32 ccs_credentials_iterate_next(cc_credentials_iterate_t *iterate, cc_credentials_list_node_t **);
+
+cc_int32 ccs_context_list_new(cc_context_list_head_t**);
+cc_int32 ccs_context_list_append(cc_context_list_head_t *head, cc_server_context_t *data, cc_context_list_node_t**);
+cc_int32 ccs_context_list_prepend(cc_context_list_head_t *head, cc_server_context_t *data, cc_context_list_node_t**);
+cc_int32 ccs_context_list_remove_element(cc_context_list_head_t* head, cc_context_list_node_t* rem);
+cc_int32 ccs_context_list_iterator(cc_context_list_head_t *head, struct cc_context_iterate_t**);
+cc_int32 ccs_context_free_iterator(struct cc_context_iterate_t *iterator);
+cc_int32 ccs_context_list_destroy(cc_context_list_head_t* head) ;
+cc_int32 ccs_context_list_copy(cc_context_list_head_t* head, cc_context_list_head_t**);
+
+cc_int32 ccs_ccache_list_new(cc_ccache_list_head_t**);
+cc_int32 ccs_ccache_list_append(cc_ccache_list_head_t *head, cc_server_ccache_t *data, cc_ccache_list_node_t**);
+cc_int32 ccs_ccache_list_prepend(cc_ccache_list_head_t *head, cc_server_ccache_t *data, cc_ccache_list_node_t**);
+cc_int32 ccs_ccache_list_remove_element(cc_ccache_list_head_t* head, cc_ccache_list_node_t* rem);
+cc_int32 ccs_ccache_list_iterator(cc_ccache_list_head_t *head, struct cc_ccache_iterate_t**);
+cc_int32 ccs_ccache_free_iterator(struct cc_ccache_iterate_t *iterator);
+cc_int32 ccs_ccache_list_destroy(cc_ccache_list_head_t* head) ;
+cc_int32 ccs_ccache_list_copy(cc_ccache_list_head_t* head, cc_ccache_list_head_t**);
+
+
+cc_int32 ccs_credentials_list_new(cc_credentials_list_head_t**);
+cc_int32 ccs_credentials_list_append(cc_credentials_list_head_t *head, cc_server_credentials_t *data, cc_credentials_list_node_t**);
+cc_int32 ccs_credentials_list_prepend(cc_credentials_list_head_t *head, cc_server_credentials_t *data, cc_credentials_list_node_t**);
+cc_int32 ccs_credentials_list_remove_element(cc_credentials_list_head_t* head, cc_credentials_list_node_t* rem);
+cc_int32 ccs_credentials_list_iterator(cc_credentials_list_head_t *head, cc_credentials_iterate_t**);
+cc_int32 ccs_credentials_free_iterator(cc_credentials_iterate_t* iterator);
+cc_int32 ccs_credentials_list_destroy(cc_credentials_list_head_t* head) ;
+cc_int32 ccs_credentials_list_copy(cc_credentials_list_head_t* head, cc_credentials_list_head_t**) ;
+
+
+cc_int32 ccs_context_new(int api_version, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_server_context_t** ) ;
+cc_int32 ccs_context_get_default_ccache_name(cc_server_context_t* ctx, char **);
+cc_int32 ccs_context_find_ccache(cc_server_context_t* ctx, char *name, cc_server_ccache_t**);
+cc_int32 ccs_context_open_ccache(cc_server_context_t* ctx, char *name, cc_server_ccache_t** );
+cc_int32 ccs_context_create_ccache(cc_server_context_t* ctx, char *name, int creds_version, char *principal, cc_server_ccache_t**);
+cc_int32 ccs_context_create_default_ccache(cc_server_context_t* ctx, int creds_version, char *principal, cc_server_ccache_t**);
+cc_int32 ccs_context_ccache_iterator(cc_server_context_t* ctx, cc_ccache_iterate_t**);
+cc_int32 ccs_context_compare(cc_server_context_t* a, cc_server_context_t* b);
+cc_int32 ccs_context_destroy(cc_server_context_t* ctx);
+cc_int32 ccs_context_rem_ccache(cc_server_context_t* ctx, cc_server_ccache_t* ccache);
+
+cc_int32 ccs_ccache_new(char *name, char *principal, int cred_vers, cc_server_ccache_t**);
+cc_int32 ccs_ccache_check_version(const cc_server_ccache_t *ccache, const cc_credentials_union* creds, cc_uint32* compat);
+cc_int32 ccs_ccache_check_principal(const cc_server_ccache_t *ccache, const cc_credentials_union* creds, cc_uint32* compat);
+cc_int32 ccs_ccache_store_creds(cc_server_ccache_t *ccache, const cc_credentials_union* credentials);
+cc_int32 ccs_ccache_rem_creds(cc_server_ccache_t *ccache, const cc_credentials_union* credentials);
+cc_int32 ccs_ccache_move(cc_server_ccache_t *source, cc_server_ccache_t* destination);
+cc_int32 ccs_ccache_get_kdc_time_offset(cc_server_ccache_t* ccache, cc_time64* offset);
+cc_int32 ccs_ccache_set_kdc_time_offset(cc_server_ccache_t* ccache, cc_time64 offset);
+cc_int32 ccs_ccache_clear_kdc_time_offset(cc_server_ccache_t* ccache);
+cc_int32 ccs_ccache_new_iterator(cc_server_ccache_t* ccache, cc_credentials_iterate_t** iterator);
+cc_int32 ccs_ccache_get_principal(cc_server_ccache_t* ccache, cc_int32 version, char ** principal);
+cc_int32 ccs_ccache_set_principal(cc_server_ccache_t* ccache, cc_int32 version, char * principal);
+cc_int32 ccs_ccache_free_principal(char * principal);
+cc_int32 ccs_ccache_destroy(cc_server_ccache_t* ccache);
+void    ccs_ccache_changed(cc_server_ccache_t* ccache);
+cc_int32 ccs_ccache_compare(cc_server_ccache_t* ccache1, cc_server_ccache_t* ccache2, cc_uint32 *result);
 #endif /*__CCDATASTOREH__*/
diff --git a/src/lib/ccapi/server/main.c b/src/lib/ccapi/server/main.c
new file mode 100644 (file)
index 0000000..cf69af3
--- /dev/null
@@ -0,0 +1,12 @@
+#include <stdarg.h>\r
+#include <stdio.h>\r
+\r
+int main( int argc, char *argv[] )\r
+{\r
+    /* we need a set of functions we want to support.\r
+     * so we can provide an abstract platform independent\r
+     * interface.\r
+     */\r
+\r
+    return 0;\r
+}\r
index 30a108a344592466b6f749c3ece59c5be3619513..360536a928a0db99e7ff4dadb55444d6ea53be2f 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -62,33 +62,36 @@ extern int cc_myversion;
 extern char cc_vendor[];
 
 cc_int32 
-cci_serv_initialize(void) 
+ccs_serv_initialize(void) 
 {
     cc_int32 code;
 
-    code = cci_context_list_new(&AllContexts);
+    code = ccs_context_list_new(&AllContexts);
     if ( code != ccNoError )
         return code;
     TypeToOpMapping = (type_to_op_mapping_t*)malloc(sizeof(type_to_op_mapping_t));
     if (TypeToOpMapping == NULL) {
-        cci_context_list_destroy(AllContexts);
+        ccs_context_list_destroy(AllContexts);
         return ccErrNoMem;
     }
 
+#if 0
+    TypeToOpMapping->operations[ccmsg_ACK] = ccop_ACK;
+    TypeToOpMapping->operations[ccmsg_NACK] = ccop_NACK;
+#endif
     TypeToOpMapping->operations[ccmsg_INIT] = ccop_INIT;
     TypeToOpMapping->operations[ccmsg_CTX_RELEASE] = ccop_CTX_RELEASE;
     TypeToOpMapping->operations[ccmsg_CTX_GET_CHANGE_TIME] = ccop_CTX_GET_CHANGE_TIME;
     TypeToOpMapping->operations[ccmsg_CTX_GET_DEFAULT_CCACHE_NAME] = ccop_CTX_GET_DEFAULT_CCACHE_NAME;
-    TypeToOpMapping->operations[ccmsg_CTX_COMPARE] = ccop_CTX_COMPARE;
+    TypeToOpMapping->operations[ccmsg_CTX_CCACHE_OPEN] = ccop_CTX_CCACHE_OPEN;
+    TypeToOpMapping->operations[ccmsg_CTX_CCACHE_OPEN_DEFAULT] = ccop_CTX_CCACHE_OPEN_DEFAULT;
+    TypeToOpMapping->operations[ccmsg_CTX_CCACHE_CREATE] = ccop_CTX_CCACHE_CREATE;
+    TypeToOpMapping->operations[ccmsg_CTX_CCACHE_CREATE_DEFAULT] = ccop_CTX_CCACHE_CREATE_DEFAULT;
+    TypeToOpMapping->operations[ccmsg_CTX_CCACHE_CREATE_UNIQUE] = ccop_CTX_CCACHE_CREATE_UNIQUE;
     TypeToOpMapping->operations[ccmsg_CTX_NEW_CCACHE_ITERATOR] = ccop_CTX_NEW_CCACHE_ITERATOR;
     TypeToOpMapping->operations[ccmsg_CTX_LOCK] = ccop_CTX_LOCK;
     TypeToOpMapping->operations[ccmsg_CTX_UNLOCK] = ccop_CTX_UNLOCK;
-    TypeToOpMapping->operations[ccmsg_CTX_CLONE] = ccop_CTX_CLONE;
-    TypeToOpMapping->operations[ccmsg_CCACHE_OPEN] = ccop_CCACHE_OPEN;
-    TypeToOpMapping->operations[ccmsg_CCACHE_OPEN_DEFAULT] = ccop_CCACHE_OPEN_DEFAULT;
-    TypeToOpMapping->operations[ccmsg_CCACHE_CREATE] = ccop_CCACHE_CREATE;
-    TypeToOpMapping->operations[ccmsg_CCACHE_CREATE_DEFAULT] = ccop_CCACHE_CREATE_DEFAULT;
-    TypeToOpMapping->operations[ccmsg_CCACHE_CREATE_UNIQUE] = ccop_CCACHE_CREATE_UNIQUE;
+    TypeToOpMapping->operations[ccmsg_CTX_COMPARE] = ccop_CTX_COMPARE;
     TypeToOpMapping->operations[ccmsg_CCACHE_RELEASE] = ccop_CCACHE_RELEASE;
     TypeToOpMapping->operations[ccmsg_CCACHE_DESTROY] = ccop_CCACHE_DESTROY;
     TypeToOpMapping->operations[ccmsg_CCACHE_SET_DEFAULT] = ccop_CCACHE_SET_DEFAULT;
@@ -96,9 +99,12 @@ cci_serv_initialize(void)
     TypeToOpMapping->operations[ccmsg_CCACHE_GET_NAME] = ccop_CCACHE_GET_NAME;
     TypeToOpMapping->operations[ccmsg_CCACHE_GET_PRINCIPAL] = ccop_CCACHE_GET_PRINCIPAL;
     TypeToOpMapping->operations[ccmsg_CCACHE_SET_PRINCIPAL] = ccop_CCACHE_SET_PRINCIPAL;
-    TypeToOpMapping->operations[ccmsg_CCACHE_CREDS_ITERATOR] = ccop_CCACHE_CREDS_ITERATOR;
+    TypeToOpMapping->operations[ccmsg_CCACHE_NEW_CREDS_ITERATOR] = ccop_CCACHE_NEW_CREDS_ITERATOR;
     TypeToOpMapping->operations[ccmsg_CCACHE_STORE_CREDS] = ccop_CCACHE_STORE_CREDS;
     TypeToOpMapping->operations[ccmsg_CCACHE_REM_CREDS] = ccop_CCACHE_REM_CREDS;
+    TypeToOpMapping->operations[ccmsg_CCACHE_MOVE] = ccop_CCACHE_MOVE;
+    TypeToOpMapping->operations[ccmsg_CCACHE_LOCK] = ccop_CCACHE_LOCK;
+    TypeToOpMapping->operations[ccmsg_CCACHE_UNLOCK] = ccop_CCACHE_UNLOCK;
     TypeToOpMapping->operations[ccmsg_CCACHE_GET_LAST_DEFAULT_TIME] = ccop_CCACHE_GET_LAST_DEFAULT_TIME;
     TypeToOpMapping->operations[ccmsg_CCACHE_GET_CHANGE_TIME] = ccop_CCACHE_GET_CHANGE_TIME;
     TypeToOpMapping->operations[ccmsg_CCACHE_COMPARE] = ccop_CCACHE_COMPARE;
@@ -107,15 +113,16 @@ cci_serv_initialize(void)
     TypeToOpMapping->operations[ccmsg_CCACHE_CLEAR_KDC_TIME_OFFSET] = ccop_CCACHE_CLEAR_KDC_TIME_OFFSET;
     TypeToOpMapping->operations[ccmsg_CCACHE_ITERATOR_RELEASE] = ccop_CCACHE_ITERATOR_RELEASE;
     TypeToOpMapping->operations[ccmsg_CCACHE_ITERATOR_NEXT] = ccop_CCACHE_ITERATOR_NEXT;
+    TypeToOpMapping->operations[ccmsg_CCACHE_ITERATOR_CLONE] = ccop_CCACHE_ITERATOR_CLONE;
     TypeToOpMapping->operations[ccmsg_CREDS_ITERATOR_RELEASE] = ccop_CREDS_ITERATOR_RELEASE;
     TypeToOpMapping->operations[ccmsg_CREDS_ITERATOR_NEXT] = ccop_CREDS_ITERATOR_NEXT;
-    TypeToOpMapping->operations[ccmsg_CREDS_RELEASE] = ccop_CREDS_RELEASE;
+    TypeToOpMapping->operations[ccmsg_CREDS_ITERATOR_CLONE] = ccop_CREDS_ITERATOR_CLONE;
 
     return ccNoError;
 };
 
 cc_int32 
-cci_serv_process_msg(cc_msg_t * msg, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** resp_msg) 
+ccs_serv_process_msg(cc_msg_t * msg, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** resp_msg) 
 {
     cc_server_context_t* ctx;
     ccmsg_ctx_only_t* header = (ccmsg_ctx_only_t *)msg->header;
@@ -125,7 +132,7 @@ cci_serv_process_msg(cc_msg_t * msg, cc_auth_info_t* auth_info, cc_session_info_
         return ccErrBadParam;
 
     if (AllContexts == NULL) {
-        code = cci_serv_initialize();
+        code = ccs_serv_initialize();
         if ( code != ccNoError )
             return code;
     }
@@ -137,9 +144,9 @@ cci_serv_process_msg(cc_msg_t * msg, cc_auth_info_t* auth_info, cc_session_info_
             return ccErrBadParam;
         }
 
-        code = cci_serv_find_ctx_by_handle(header->ctx, auth_info, session_info, &ctx);
+        code = ccs_serv_find_ctx_by_handle(header->ctx, auth_info, session_info, &ctx);
         if (code != ccNoError) {
-            cci_serv_make_nack(ccErrContextNotFound, auth_info, session_info, resp_msg);
+            ccs_serv_make_nack(ccErrContextNotFound, auth_info, session_info, resp_msg);
             return code;
         }
         return TypeToOpMapping->operations[msg->type] (ctx, auth_info, session_info, msg, resp_msg);
@@ -148,7 +155,7 @@ cci_serv_process_msg(cc_msg_t * msg, cc_auth_info_t* auth_info, cc_session_info_
 
 /*deprecated*/
 cc_int32
-cci_serv_find_ctx(cc_auth_info_t* auth_info, cc_session_info_t* session_info,
+ccs_serv_find_ctx(cc_auth_info_t* auth_info, cc_session_info_t* session_info,
                   cc_server_context_t** ctxpp)
 {
     cc_context_iterate_t* ctx_iterator;
@@ -157,35 +164,35 @@ cci_serv_find_ctx(cc_auth_info_t* auth_info, cc_session_info_t* session_info,
     cc_int32 code;
     cc_uint32 authorized;
 
-    code = cci_context_list_iterator(AllContexts, &ctx_iterator);
+    code = ccs_context_list_iterator(AllContexts, &ctx_iterator);
     if (code != ccNoError)
         return code;
 
-    while (cci_context_iterate_has_next(ctx_iterator)) {
-        code = cci_context_iterate_next(ctx_iterator, &ctx_node);
+    while (ccs_context_iterate_has_next(ctx_iterator)) {
+        code = ccs_context_iterate_next(ctx_iterator, &ctx_node);
         if (code != ccNoError) {
-            cci_context_free_iterator(ctx_iterator);
+            ccs_context_free_iterator(ctx_iterator);
             return code;
         }
         ctx = (cc_server_context_t *)ctx_node->data;
         code = cci_rpc_is_authorized(auth_info, session_info, ctx->auth_info, ctx->session_info, &authorized);
         if (code != ccNoError) {
-            cci_context_free_iterator(ctx_iterator);
+            ccs_context_free_iterator(ctx_iterator);
             return code;
         }
 
         if (authorized) {
-            cci_context_free_iterator(ctx_iterator);
+            ccs_context_free_iterator(ctx_iterator);
             *ctxpp = ctx;
             return ccNoError;
         }
     }
-    cci_context_free_iterator(ctx_iterator);
+    ccs_context_free_iterator(ctx_iterator);
     return ccIteratorEnd;
 }
 
 cc_int32
-cci_serv_find_ctx_by_handle(cc_handle ctx_num, cc_auth_info_t* auth, cc_session_info_t* session, cc_server_context_t** ctxpp) 
+ccs_serv_find_ctx_by_handle(cc_handle ctx_num, cc_auth_info_t* auth, cc_session_info_t* session, cc_server_context_t** ctxpp) 
 {
     cc_server_context_t* input_ctx = (cc_server_context_t*)ctx_num;
     cc_context_iterate_t* ctx_iterator;
@@ -194,36 +201,36 @@ cci_serv_find_ctx_by_handle(cc_handle ctx_num, cc_auth_info_t* auth, cc_session_
     cc_uint32 authorized;
     cc_int32 code;
 
-    code = cci_context_list_iterator(AllContexts, &ctx_iterator);
+    code = ccs_context_list_iterator(AllContexts, &ctx_iterator);
     if (code != ccNoError)
         return code;
 
-    while (cci_context_iterate_has_next(ctx_iterator)) {
-        code = cci_context_iterate_next(ctx_iterator, &ctx_node);
+    while (ccs_context_iterate_has_next(ctx_iterator)) {
+        code = ccs_context_iterate_next(ctx_iterator, &ctx_node);
         ctx = (cc_server_context_t *)ctx_node->data;
         if (code != ccNoError) {
-            cci_context_free_iterator(ctx_iterator);
+            ccs_context_free_iterator(ctx_iterator);
             return code;
         }
 
         code = cci_rpc_is_authorized(auth, session, ctx->auth_info, ctx->session_info, &authorized);
         if (code != ccNoError) {
-            cci_context_free_iterator(ctx_iterator);
+            ccs_context_free_iterator(ctx_iterator);
             return code;
         }
 
         if (ctx == input_ctx && authorized) {
-            cci_context_free_iterator(ctx_iterator);
+            ccs_context_free_iterator(ctx_iterator);
             *ctxpp = ctx;
             return ccNoError;
         }
     }
-    cci_context_free_iterator(ctx_iterator);
+    ccs_context_free_iterator(ctx_iterator);
     return ccIteratorEnd;
 }
 
 cc_int32
-cci_serv_find_ccache_by_handle(cc_server_context_t* ctx, cc_handle ccache, cc_server_ccache_t** ccachepp ) 
+ccs_serv_find_ccache_by_handle(cc_server_context_t* ctx, cc_handle ccache, cc_server_ccache_t** ccachepp ) 
 {
     cc_ccache_iterate_t* ccache_iterator;
     cc_ccache_list_node_t* ccache_node;
@@ -231,31 +238,31 @@ cci_serv_find_ccache_by_handle(cc_server_context_t* ctx, cc_handle ccache, cc_se
     cc_server_ccache_t* target_ccache = (cc_server_ccache_t*)ccache;
     cc_int32 code;
 
-    code = cci_ccache_list_iterator(ctx->ccaches, &ccache_iterator);
+    code = ccs_ccache_list_iterator(ctx->ccaches, &ccache_iterator);
     if (code != ccNoError)
         return code;
 
-    while (cci_ccache_iterate_has_next(ccache_iterator)) {
-        code = cci_ccache_iterate_next(ccache_iterator, &ccache_node);
+    while (ccs_ccache_iterate_has_next(ccache_iterator)) {
+        code = ccs_ccache_iterate_next(ccache_iterator, &ccache_node);
         if (code != ccNoError) {
-            cci_ccache_free_iterator(ccache_iterator);
+            ccs_ccache_free_iterator(ccache_iterator);
             return code;
         }
 
         stored_ccache = (cc_server_ccache_t *)ccache_node->data;
        
         if (stored_ccache == target_ccache) {
-            cci_ccache_free_iterator(ccache_iterator);
+            ccs_ccache_free_iterator(ccache_iterator);
             *ccachepp = stored_ccache;
             return ccNoError;
         }
     }
-    cci_ccache_free_iterator(ccache_iterator);
+    ccs_ccache_free_iterator(ccache_iterator);
     return ccIteratorEnd;
 }
 
 cc_int32
-cci_serv_find_ccache_iterator_by_handle(cc_server_context_t* ctx, cc_handle iterator, cc_generic_list_node_t** nodepp ) 
+ccs_serv_find_ccache_iterator_by_handle(cc_server_context_t* ctx, cc_handle iterator, cc_generic_list_node_t** nodepp ) 
 {
     cc_generic_iterate_t* gen_iterator;
     cc_generic_list_node_t* gen_node;
@@ -286,7 +293,7 @@ cci_serv_find_ccache_iterator_by_handle(cc_server_context_t* ctx, cc_handle iter
 }
 
 cc_int32
-cci_serv_find_creds_iterator_by_handle(cc_server_ccache_t* ccache, cc_handle iterator, cc_generic_list_node_t** nodepp) 
+ccs_serv_find_creds_iterator_by_handle(cc_server_ccache_t* ccache, cc_handle iterator, cc_generic_list_node_t** nodepp) 
 {
     cc_generic_iterate_t* gen_iterator;
     cc_generic_list_node_t* gen_node;
@@ -317,7 +324,7 @@ cci_serv_find_creds_iterator_by_handle(cc_server_ccache_t* ccache, cc_handle ite
 }       
 
 cc_int32 
-cci_serv_make_nack(cc_int32 err_code, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** resp_msg) 
+ccs_serv_make_nack(cc_int32 err_code, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** resp_msg) 
 {
     ccmsg_nack_t* nack_header;
     cc_int32 code;
@@ -345,7 +352,7 @@ cci_serv_make_nack(cc_int32 err_code, cc_auth_info_t* auth_info, cc_session_info
 }
 
 cc_int32 
-cci_serv_make_ack(void * header, cc_int32 header_len, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** resp_msg) 
+ccs_serv_make_ack(void * header, cc_int32 header_len, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** resp_msg) 
 {
     cc_int32 code;
 
@@ -383,46 +390,46 @@ ccop_INIT( cc_server_context_t* ctx,            /* not used */
         return ccErrBadParam;
     }
 
-    code = cci_context_new(header->in_version, auth_info, session_info, &new_ctx);
+    code = ccs_context_new(header->in_version, auth_info, session_info, &new_ctx);
     if (code != ccNoError) {
         return code;
     }
 
-    code = cci_context_list_append(AllContexts, ctx, &ctx_node);
+    code = ccs_context_list_append(AllContexts, ctx, &ctx_node);
     if (code != ccNoError) {
-        cci_context_destroy(new_ctx);
+        ccs_context_destroy(new_ctx);
         return code;
     }
 
     resp_header = (ccmsg_init_resp_t*)malloc(sizeof(ccmsg_init_resp_t));
     if (resp_header == NULL) {
-        cci_context_destroy(new_ctx);
+        ccs_context_destroy(new_ctx);
         return ccErrNoMem;
     }
 
     code = cci_msg_new(ccmsg_ACK, resp_msg);
     if (code != ccNoError) {
         free(resp_header);
-        cci_context_destroy(new_ctx);
+        ccs_context_destroy(new_ctx);
         return code;
     }
     code = cci_msg_add_data_blob(*resp_msg, cc_vendor, strlen(cc_vendor) + 1, &blob_pos);
     if (code != ccNoError) {
         free(resp_header);
-        cci_context_destroy(new_ctx);
+        ccs_context_destroy(new_ctx);
         cci_msg_destroy(*resp_msg);
         *resp_msg = 0;
         return code;
     }
 
-    resp_header->out_ctx = new_ctx;
+    resp_header->out_ctx = (cc_handle) new_ctx;
     resp_header->out_version = cc_myversion;
     resp_header->vendor_offset = blob_pos;
     resp_header->vendor_length = strlen(cc_vendor) + 1;
     code = cci_msg_add_header(*resp_msg, resp_header, sizeof(ccmsg_init_resp_t));
     if (code != ccNoError) {
         free(resp_header);
-        cci_context_destroy(new_ctx);
+        ccs_context_destroy(new_ctx);
         cci_msg_destroy(*resp_msg);
         *resp_msg = 0;
         return code;
@@ -446,8 +453,8 @@ ccop_CTX_RELEASE( cc_server_context_t* ctx,
         return ccErrBadParam;
     }
 
-    code = cci_context_destroy(header->ctx);
-    return cci_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
+    code = ccs_context_destroy((cc_server_context_t *)header->ctx);
+    return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
 }       
 
 cc_int32 
@@ -471,7 +478,7 @@ ccop_CTX_GET_CHANGE_TIME( cc_server_context_t* ctx,
     }
 
     resp_header->time = ctx->changed;
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ctx_get_change_time_resp_t), auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ctx_get_change_time_resp_t), auth_info, session_info, resp_msg);
 }       
 
 cc_int32 
@@ -491,7 +498,7 @@ ccop_CTX_GET_DEFAULT_CCACHE_NAME( cc_server_context_t* ctx,
         return ccErrBadParam;
     }
        
-    code = cci_context_get_default_ccache_name(ctx, &name);
+    code = ccs_context_get_default_ccache_name(ctx, &name);
     if (code != ccNoError)
         return code;
 
@@ -527,14 +534,14 @@ ccop_CTX_COMPARE(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ctx_compare_t))
         return ccErrBadParam;
 
-    code = cci_serv_find_ctx_by_handle(header->ctx2, auth_info, session_info, &ctx2);
+    code = ccs_serv_find_ctx_by_handle(header->ctx2, auth_info, session_info, &ctx2);
 
     resp_header = (ccmsg_ctx_compare_resp_t*)malloc(sizeof(ccmsg_ctx_compare_resp_t));
     if (resp_header == NULL)
         return ccErrNoMem;
 
-    resp_header->is_equal = cci_context_compare(ctx, ctx2);
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ctx_compare_resp_t), auth_info, session_info, resp_msg);
+    resp_header->is_equal = ccs_context_compare(ctx, ctx2);
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ctx_compare_resp_t), auth_info, session_info, resp_msg);
 }       
 
 cc_int32 
@@ -553,15 +560,15 @@ ccop_CTX_NEW_CCACHE_ITERATOR(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ctx_new_ccache_iterator_t))
         return ccErrBadParam;
 
-    code = cci_context_ccache_iterator(ctx,&ccache_iterator);
+    code = ccs_context_ccache_iterator(ctx,&ccache_iterator);
 
     resp_header = (ccmsg_ctx_new_ccache_iterator_resp_t*)malloc(sizeof(ccmsg_ctx_new_ccache_iterator_resp_t));
     if (resp_header == NULL) 
         return ccErrNoMem;
 
-    resp_header->iterator = ccache_iterator;
+    resp_header->iterator = (cc_handle) ccache_iterator;
 
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ctx_new_ccache_iterator_resp_t), auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ctx_new_ccache_iterator_resp_t), auth_info, session_info, resp_msg);
 }       
 
 cc_int32
@@ -571,7 +578,7 @@ ccop_CTX_LOCK( cc_server_context_t* ctx,
                cc_msg_t *msg, cc_msg_t **resp_msg) 
 {
     // TODO
-    return cci_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
+    return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
 }
 
 cc_int32
@@ -581,7 +588,7 @@ ccop_CTX_UNLOCK( cc_server_context_t* ctx,
                  cc_msg_t *msg, cc_msg_t **resp_msg) 
 {
     // TODO
-    return cci_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
+    return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
 }
 
 cc_int32
@@ -591,11 +598,11 @@ ccop_CTX_CLONE( cc_server_context_t* ctx,
                 cc_msg_t *msg, cc_msg_t **resp_msg) 
 {
     // TODO
-    return cci_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
+    return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
 }
 
 cc_int32 
-ccop_CCACHE_OPEN(cc_server_context_t* ctx,
+ccop_CTX_CCACHE_OPEN(cc_server_context_t* ctx,
                   cc_auth_info_t* auth_info,
                   cc_session_info_t* session_info,
                   cc_msg_t *msg, cc_msg_t **resp_msg) 
@@ -612,24 +619,24 @@ ccop_CCACHE_OPEN(cc_server_context_t* ctx,
         return ccErrBadParam;
 
     code = cci_msg_retrieve_blob(msg, header->name_offset, header->name_len, &name);
-    code = cci_context_find_ccache(ctx, name, &ccache);
+    code = ccs_context_find_ccache(ctx, name, &ccache);
 
     free(name);
 
     if (ccache == NULL)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
     resp_header = (ccmsg_ccache_open_resp_t*)malloc(sizeof(ccmsg_ccache_open_resp_t));
     if (resp_header == NULL)
         return ccErrNoMem;
 
-    resp_header->ccache = ccache;
-    cci_serv_make_ack(resp_header, sizeof(ccmsg_ccache_open_resp_t), auth_info, session_info, resp_msg);
+    resp_header->ccache = (cc_handle) ccache;
+    ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_open_resp_t), auth_info, session_info, resp_msg);
     return ccNoError;
 }       
 
 cc_int32 
-ccop_CCACHE_OPEN_DEFAULT(cc_server_context_t* ctx,
+ccop_CTX_CCACHE_OPEN_DEFAULT(cc_server_context_t* ctx,
                           cc_auth_info_t* auth_info,
                           cc_session_info_t* session_info,
                           cc_msg_t *msg, cc_msg_t **resp_msg) 
@@ -644,7 +651,7 @@ ccop_CCACHE_OPEN_DEFAULT(cc_server_context_t* ctx,
         return ccErrBadParam;
 
     if (ctx->ccaches->head->data == NULL)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
     
     ccache = (cc_server_ccache_t*) ctx->ccaches->head->data;
 
@@ -652,12 +659,12 @@ ccop_CCACHE_OPEN_DEFAULT(cc_server_context_t* ctx,
     if (resp_header == NULL) 
         return ccErrNoMem;
 
-    resp_header->ccache = ccache;
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ccache_open_resp_t), auth_info, session_info, resp_msg);
+    resp_header->ccache = (cc_handle) ccache;
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_open_resp_t), auth_info, session_info, resp_msg);
 }       
 
 cc_int32 
-ccop_CCACHE_CREATE(cc_server_context_t* ctx,
+ccop_CTX_CCACHE_CREATE(cc_server_context_t* ctx,
                     cc_auth_info_t* auth_info,
                     cc_session_info_t* session_info,
                     cc_msg_t *msg, cc_msg_t **resp_msg) 
@@ -684,7 +691,7 @@ ccop_CCACHE_CREATE(cc_server_context_t* ctx,
         return code;
     name[header->name_len] = '\0'; /*Ensure null termination*/
 
-    code = cci_context_create_ccache(ctx, name, header->version, principal, &ccache);
+    code = ccs_context_create_ccache(ctx, name, header->version, principal, &ccache);
     if (code != ccNoError)
         return code;
 
@@ -692,12 +699,12 @@ ccop_CCACHE_CREATE(cc_server_context_t* ctx,
     if (resp_header == NULL)
         return ccErrNoMem;
 
-    resp_header->ccache = ccache;
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ccache_create_resp_t), auth_info, session_info, resp_msg);
+    resp_header->ccache = (cc_handle) ccache;
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_create_resp_t), auth_info, session_info, resp_msg);
 }
 
 cc_int32 
-ccop_CCACHE_CREATE_DEFAULT( cc_server_context_t* ctx,
+ccop_CTX_CCACHE_CREATE_DEFAULT( cc_server_context_t* ctx,
                             cc_auth_info_t* auth_info,
                             cc_session_info_t* session_info,
                             cc_msg_t *msg, cc_msg_t **resp_msg) 
@@ -719,11 +726,11 @@ ccop_CCACHE_CREATE_DEFAULT( cc_server_context_t* ctx,
         return code;
     principal[header->principal_len] = '\0'; /*Ensure null termination*/
 
-    code = cci_context_get_default_ccache_name(ctx, &name);
+    code = ccs_context_get_default_ccache_name(ctx, &name);
     if (code != ccNoError)
         return code;
 
-    code = cci_context_create_ccache(ctx, name, header->version, principal, &ccache);
+    code = ccs_context_create_ccache(ctx, name, header->version, principal, &ccache);
     if (code != ccNoError)
         return code;
 
@@ -731,12 +738,12 @@ ccop_CCACHE_CREATE_DEFAULT( cc_server_context_t* ctx,
     if (resp_header == NULL)
         return ccErrNoMem;
 
-    resp_header->ccache = ccache;
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ccache_create_resp_t), auth_info, session_info, resp_msg);
+    resp_header->ccache = (cc_handle) ccache;
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_create_resp_t), auth_info, session_info, resp_msg);
 }
 
 cc_int32 
-ccop_CCACHE_CREATE_UNIQUE( cc_server_context_t* ctx,
+ccop_CTX_CCACHE_CREATE_UNIQUE( cc_server_context_t* ctx,
                            cc_auth_info_t* auth_info,
                            cc_session_info_t* session_info,
                            cc_msg_t *msg, cc_msg_t **resp_msg) 
@@ -758,9 +765,10 @@ ccop_CCACHE_CREATE_UNIQUE( cc_server_context_t* ctx,
         return code;
     principal[header->principal_len] = '\0'; /*Ensure null termination*/
 
-    // TODO: Generate a unique ccache name 
+    // TODO: Generate a unique ccache name
+    name = "unique";
 
-    code = cci_context_create_ccache(ctx, name, header->version, principal, &ccache);
+    code = ccs_context_create_ccache(ctx, name, header->version, principal, &ccache);
     if (code != ccNoError)
         return code;
 
@@ -768,8 +776,8 @@ ccop_CCACHE_CREATE_UNIQUE( cc_server_context_t* ctx,
     if (resp_header == NULL)
         return ccErrNoMem;
 
-    resp_header->ccache = ccache;
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ccache_create_resp_t), auth_info, session_info, resp_msg);
+    resp_header->ccache = (cc_handle) ccache;
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_create_resp_t), auth_info, session_info, resp_msg);
 }
 
 cc_int32 
@@ -797,13 +805,13 @@ ccop_CCACHE_DESTROY( cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_release_t)) 
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
-    cci_ccache_destroy(ccache);
+    ccs_ccache_destroy(ccache);
 
-    return cci_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
 }
 
 cc_int32 
@@ -823,32 +831,32 @@ ccop_CCACHE_SET_DEFAULT(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_set_default_t))
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
     if (ccache == (cc_server_ccache_t*)ctx->ccaches->head->data) /*already default*/
-        return cci_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
+        return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
 
     old_default = (cc_server_ccache_t*)ctx->ccaches->head->data;
     old_default->last_default = time(NULL);
 
-    code = cci_ccache_list_iterator(ctx->ccaches, &ccache_iterator);
+    code = ccs_ccache_list_iterator(ctx->ccaches, &ccache_iterator);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
-    while (cci_ccache_iterate_has_next(ccache_iterator)) {
-        code = cci_ccache_iterate_next(ccache_iterator,&ccache_node);
+    while (ccs_ccache_iterate_has_next(ccache_iterator)) {
+        code = ccs_ccache_iterate_next(ccache_iterator,&ccache_node);
         stored_ccache = (cc_server_ccache_t*)ccache_node->data;
 
         if (stored_ccache == ccache) {
             ccache_node->data = NULL; /*don't want list removal code free()ing ccache*/
-            cci_ccache_list_remove_element(ctx->ccaches, ccache_node);
-            cci_ccache_list_prepend(ctx->ccaches, ccache, NULL);
+            ccs_ccache_list_remove_element(ctx->ccaches, ccache_node);
+            ccs_ccache_list_prepend(ctx->ccaches, ccache, NULL);
             break;
         }
     }       
-    return cci_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
 }       
 
 cc_int32 
@@ -867,16 +875,16 @@ ccop_CCACHE_GET_CREDS_VERSION(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_get_creds_version_t))
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError) 
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
     resp_header = (ccmsg_ccache_get_creds_version_resp_t*)malloc(sizeof(ccmsg_ccache_get_creds_version_resp_t));       
     if (resp_header == NULL)
         return ccErrNoMem;
 
     resp_header->version = ccache->versions;
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ccache_get_creds_version_resp_t), auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_get_creds_version_resp_t), auth_info, session_info, resp_msg);
 }
 
 cc_int32 
@@ -895,9 +903,9 @@ ccop_CCACHE_GET_NAME(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_get_name_resp_t)) 
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (ccache == NULL)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
     resp_header = (ccmsg_ccache_get_name_resp_t*)malloc(sizeof(ccmsg_ccache_get_name_resp_t));
     if (resp_header == NULL)
@@ -931,13 +939,13 @@ ccop_CCACHE_GET_PRINCIPAL(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_get_principal_t)) 
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
-    code = cci_ccache_get_principal(ccache, header->version, &principal);
+    code = ccs_ccache_get_principal(ccache, header->version, &principal);
     if (code != ccNoError)
-        return cci_serv_make_nack(code, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(code, auth_info, session_info, resp_msg);
 
     code = cci_msg_new(ccmsg_ACK, resp_msg);
     if (code != ccNoError) 
@@ -969,26 +977,26 @@ ccop_CCACHE_SET_PRINCIPAL(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_set_principal_t))
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
     code = cci_msg_retrieve_blob(msg, header->principal_offset, header->principal_len, &principal);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg);
 
-    code = cci_ccache_set_principal(ccache, header->version, principal);
+    code = ccs_ccache_set_principal(ccache, header->version, principal);
     if (code != ccNoError)
-        return cci_serv_make_nack(code, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(code, auth_info, session_info, resp_msg);
 
-    return cci_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
 }       
 
 cc_int32 
-ccop_CCACHE_CREDS_ITERATOR(cc_server_context_t* ctx,
-                            cc_auth_info_t* auth_info,
-                            cc_session_info_t* session_info,
-                            cc_msg_t *msg, cc_msg_t **resp_msg) 
+ccop_CCACHE_NEW_CREDS_ITERATOR( cc_server_context_t* ctx,
+                               cc_auth_info_t* auth_info,
+                               cc_session_info_t* session_info,
+                               cc_msg_t *msg, cc_msg_t **resp_msg) 
 {
     cc_server_ccache_t* ccache;
     cc_credentials_iterate_t* creds_iterator;
@@ -1001,11 +1009,11 @@ ccop_CCACHE_CREDS_ITERATOR(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_creds_iterator_t)) 
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
-    code = cci_ccache_new_iterator(ccache, &creds_iterator);
+    code = ccs_ccache_new_iterator(ccache, &creds_iterator);
     if (code != ccNoError)
         return code;
 
@@ -1013,13 +1021,13 @@ ccop_CCACHE_CREDS_ITERATOR(cc_server_context_t* ctx,
     if (resp_header == NULL)
         return ccErrNoMem;
 
-    resp_header->iterator = creds_iterator;
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ccache_creds_iterator_resp_t), auth_info, session_info, resp_msg);
+    resp_header->iterator = (cc_handle) creds_iterator;
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_creds_iterator_resp_t), auth_info, session_info, resp_msg);
 }       
 
 
 static cc_int32
-cci_credentials_union_release( cc_credentials_union * creds )
+ccs_credentials_union_release( cc_credentials_union * creds )
 {
     int i;
 
@@ -1076,9 +1084,9 @@ ccop_CCACHE_STORE_CREDS(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_store_creds_t))
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError) 
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
     // TODO: This code is too simplistic.  cc_credential_unions are not flat
     // structures and must be flattened.  That means that although we can 
@@ -1086,7 +1094,7 @@ ccop_CCACHE_STORE_CREDS(cc_server_context_t* ctx,
     // into the actual object.  
     code = cci_msg_retrieve_blob(msg, header->creds_offset, header->creds_len, &flat_creds);
     if (code != ccNoError) 
-        return cci_serv_make_nack(code, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(code, auth_info, session_info, resp_msg);
 
     creds = (cc_credentials_union *)malloc(sizeof(cc_credentials_union));
     if ( creds == NULL )
@@ -1100,18 +1108,18 @@ ccop_CCACHE_STORE_CREDS(cc_server_context_t* ctx,
         code = cci_creds_v5_unmarshall(flat_creds, header->creds_len, creds);
         break;
     default:
-        return cci_serv_make_nack(ccErrBadCredentialsVersion, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrBadCredentialsVersion, auth_info, session_info, resp_msg);
     }
     if (code != ccNoError)
-        return cci_serv_make_nack(code, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(code, auth_info, session_info, resp_msg);
 
-    code = cci_ccache_store_creds(ccache, creds);
-    cci_credentials_union_release(creds);
+    code = ccs_ccache_store_creds(ccache, creds);
+    ccs_credentials_union_release(creds);
     if (code != ccNoError) {
-        return cci_serv_make_nack(code, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(code, auth_info, session_info, resp_msg);
     }
 
-    return cci_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
 }       
 
 cc_int32 
@@ -1129,15 +1137,15 @@ ccop_CCACHE_REM_CREDS(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_rem_creds_t))
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError) 
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
-    code = cci_ccache_rem_creds(ccache, header->creds);
+    code = ccs_ccache_rem_creds(ccache, (const cc_credentials_union *)header->creds);
     if (code != ccNoError)
-        return cci_serv_make_nack(code, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(code, auth_info, session_info, resp_msg);
 
-    return cci_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
 }               
 
 cc_int32
@@ -1147,7 +1155,7 @@ ccop_CCACHE_LOCK( cc_server_context_t* ctx,
                   cc_msg_t *msg, cc_msg_t **resp_msg) 
 {
     // TODO
-    return cci_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
+    return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
 }
 
 cc_int32
@@ -1157,7 +1165,7 @@ ccop_CCACHE_UNLOCK( cc_server_context_t* ctx,
                     cc_msg_t *msg, cc_msg_t **resp_msg) 
 {
     // TODO
-    return cci_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
+    return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
 }
 
 cc_int32
@@ -1167,7 +1175,7 @@ ccop_CCACHE_MOVE( cc_server_context_t* ctx,
                   cc_msg_t *msg, cc_msg_t **resp_msg) 
 {
     // TODO
-    return cci_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
+    return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
 }
 
 
@@ -1187,16 +1195,16 @@ ccop_CCACHE_GET_LAST_DEFAULT_TIME(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_get_last_default_time_t))
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
     resp_header = (ccmsg_ccache_get_last_default_time_resp_t*)malloc(sizeof(ccmsg_ccache_get_last_default_time_resp_t));
     if (resp_header == NULL)
         return ccErrNoMem;
 
     resp_header->last_default_time = ccache->last_default;
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ccache_get_last_default_time_resp_t), auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_get_last_default_time_resp_t), auth_info, session_info, resp_msg);
 }       
 
 cc_int32 
@@ -1221,7 +1229,7 @@ ccop_CCACHE_GET_CHANGE_TIME( cc_server_context_t* ctx,
     }
 
     resp_header->time = ccache->changed;
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ccache_get_change_time_resp_t), auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_get_change_time_resp_t), auth_info, session_info, resp_msg);
 }       
 
 cc_int32 
@@ -1240,20 +1248,20 @@ ccop_CCACHE_COMPARE(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_compare_t))
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache1, &ccache1);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache1, &ccache1);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache2, &ccache2);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache2, &ccache2);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
     resp_header = (ccmsg_ccache_compare_resp_t*)malloc(sizeof(ccmsg_ccache_compare_resp_t));   
     if (resp_header == NULL)
         return ccErrNoMem;
 
-    cci_ccache_compare(ccache1, ccache2, &resp_header->is_equal);
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ccache_compare_resp_t), auth_info, session_info, resp_msg);
+    ccs_ccache_compare(ccache1, ccache2, &resp_header->is_equal);
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_compare_resp_t), auth_info, session_info, resp_msg);
 }       
 
 cc_int32 
@@ -1265,7 +1273,7 @@ ccop_CCACHE_GET_KDC_TIME_OFFSET(cc_server_context_t* ctx,
     ccmsg_ccache_get_kdc_time_offset_t* header = (ccmsg_ccache_get_kdc_time_offset_t*)msg->header;
     ccmsg_ccache_get_kdc_time_offset_resp_t* resp_header;
     cc_server_ccache_t* ccache;
-    cc_time_t offset;
+    cc_time64 offset;
     cc_int32 code;
 
     *resp_msg = 0;
@@ -1273,22 +1281,22 @@ ccop_CCACHE_GET_KDC_TIME_OFFSET(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_get_kdc_time_offset_t))
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
     // TODO How is the header->creds_version supposed to be used?
 
-    code = cci_ccache_get_kdc_time_offset(ccache, &offset);
+    code = ccs_ccache_get_kdc_time_offset(ccache, &offset);
     if (code != ccNoError)
-        return cci_serv_make_nack(code, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(code, auth_info, session_info, resp_msg);
 
     resp_header = (ccmsg_ccache_get_kdc_time_offset_resp_t*)malloc(sizeof(ccmsg_ccache_get_kdc_time_offset_resp_t));
     if (resp_header == NULL)
         return ccErrNoMem;
 
     resp_header->offset = offset;
-    return cci_serv_make_ack(resp_header, sizeof(ccmsg_ccache_get_kdc_time_offset_resp_t), auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_get_kdc_time_offset_resp_t), auth_info, session_info, resp_msg);
 }       
 
 cc_int32 
@@ -1306,14 +1314,14 @@ ccop_CCACHE_SET_KDC_TIME_OFFSET(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_set_kdc_time_offset_t))
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
     // TODO How is the header->creds_version supposed to be used?
 
-    cci_ccache_set_kdc_time_offset(ccache, header->offset);
-    return cci_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
+    ccs_ccache_set_kdc_time_offset(ccache, header->offset);
+    return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
 }       
 
 cc_int32 
@@ -1331,14 +1339,14 @@ ccop_CCACHE_CLEAR_KDC_TIME_OFFSET(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_clear_kdc_time_offset_t))
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
     // TODO How is the header->creds_version supposed to be used?
 
-    cci_ccache_clear_kdc_time_offset(ccache);
-    return cci_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
+    ccs_ccache_clear_kdc_time_offset(ccache);
+    return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
 }               
 
 cc_int32 
@@ -1356,17 +1364,27 @@ ccop_CCACHE_ITERATOR_RELEASE(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_iterator_release_t)) 
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_iterator_by_handle(ctx, header->iterator, &gen_node);
+    code = ccs_serv_find_ccache_iterator_by_handle(ctx, header->iterator, &gen_node);
     if (code != ccNoError) 
-        return cci_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg);
 
     code = cci_generic_list_remove_element(ctx->active_iterators, gen_node);
     if (code != ccNoError) 
-        return cci_serv_make_nack(code, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(code, auth_info, session_info, resp_msg);
 
-    return cci_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
 }       
 
+cc_int32
+ccop_CCACHE_ITERATOR_CLONE( cc_server_context_t* ctx,
+                cc_auth_info_t* auth_info,
+                cc_session_info_t* session_info,
+                cc_msg_t *msg, cc_msg_t **resp_msg) 
+{
+    // TODO
+    return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
+}
+
 cc_int32 
 ccop_CCACHE_ITERATOR_NEXT(cc_server_context_t* ctx,
                            cc_auth_info_t* auth_info,
@@ -1385,24 +1403,24 @@ ccop_CCACHE_ITERATOR_NEXT(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_ccache_iterator_next_t)) 
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_iterator_by_handle(ctx, header->iterator, &gen_node);
+    code = ccs_serv_find_ccache_iterator_by_handle(ctx, header->iterator, &gen_node);
     if (code != ccNoError) 
-        return cci_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg);
 
     ccache_iterator = (cc_ccache_iterate_t*)gen_node->data;
-    if (cci_ccache_iterate_has_next(ccache_iterator)) {
+    if (ccs_ccache_iterate_has_next(ccache_iterator)) {
         resp_header = (ccmsg_ccache_iterator_next_resp_t*)malloc(sizeof(ccmsg_ccache_iterator_next_resp_t));
         if (resp_header == NULL)
             return ccErrNoMem;
 
-        code = cci_ccache_iterate_next(ccache_iterator, &ccache_node);
+        code = ccs_ccache_iterate_next(ccache_iterator, &ccache_node);
         if (code != ccNoError) 
-            return cci_serv_make_nack(code, auth_info, session_info, resp_msg);
+            return ccs_serv_make_nack(code, auth_info, session_info, resp_msg);
 
-               resp_header->ccache = ccache_node;
-        return cci_serv_make_ack(resp_header, sizeof(ccmsg_ccache_iterator_next_resp_t), auth_info, session_info, resp_msg);
+       resp_header->ccache = (cc_handle) ccache_node;
+        return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_iterator_next_resp_t), auth_info, session_info, resp_msg);
     } else {
-        return cci_serv_make_nack(ccIteratorEnd, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccIteratorEnd, auth_info, session_info, resp_msg);
     }
 }       
 
@@ -1422,21 +1440,32 @@ ccop_CREDS_ITERATOR_RELEASE(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_creds_iterator_release_t)) 
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
-    code = cci_serv_find_creds_iterator_by_handle(ccache, header->iterator, &gen_node);
+    code = ccs_serv_find_creds_iterator_by_handle(ccache, header->iterator, &gen_node);
     if (code != ccNoError) 
-        return cci_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg);
 
     code = cci_generic_list_remove_element(ccache->active_iterators, gen_node);
     if (code != ccNoError) 
-        return cci_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg);
 
-    return cci_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
+    return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg);
 }       
 
+cc_int32
+ccop_CREDS_ITERATOR_CLONE( cc_server_context_t* ctx,
+                cc_auth_info_t* auth_info,
+                cc_session_info_t* session_info,
+                cc_msg_t *msg, cc_msg_t **resp_msg) 
+{
+    // TODO
+    return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
+}
+
+
 cc_int32 
 ccop_CREDS_ITERATOR_NEXT(cc_server_context_t* ctx,
                           cc_auth_info_t* auth_info,
@@ -1458,16 +1487,16 @@ ccop_CREDS_ITERATOR_NEXT(cc_server_context_t* ctx,
     if (msg->header_len != sizeof(ccmsg_creds_iterator_next_t))
         return ccErrBadParam;
 
-    code = cci_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
+    code = ccs_serv_find_ccache_by_handle(ctx, header->ccache, &ccache);
     if (code != ccNoError)
-        return cci_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg);
 
-    code = cci_serv_find_creds_iterator_by_handle(ccache, header->iterator, &gen_node);
+    code = ccs_serv_find_creds_iterator_by_handle(ccache, header->iterator, &gen_node);
     if (code != ccNoError) 
-        return cci_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg);
+        return ccs_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg);
 
     creds_iterator = (cc_credentials_iterate_t*)gen_node->data;
-    if (cci_credentials_iterate_has_next(creds_iterator)) {
+    if (ccs_credentials_iterate_has_next(creds_iterator)) {
         code = cci_msg_new(ccmsg_ACK, resp_msg);
         if (code != ccNoError)
             return code;
@@ -1476,14 +1505,14 @@ ccop_CREDS_ITERATOR_NEXT(cc_server_context_t* ctx,
         if (resp_header == NULL)
             return ccErrNoMem;
 
-        code = cci_credentials_iterate_next(creds_iterator, &creds_node);
+        code = ccs_credentials_iterate_next(creds_iterator, &creds_node);
         stored_creds = (cc_server_credentials_t*)creds_node->data;
         creds_union = &stored_creds->creds;
 
         code = cci_msg_add_data_blob(*resp_msg, creds_union, sizeof(cc_credentials_union), &resp_header->creds_offset);
         code = cci_msg_add_header(*resp_msg, resp_header, sizeof(ccmsg_creds_iterator_next_resp_t));
     } else {
-        cci_serv_make_nack(ccIteratorEnd, auth_info, session_info, resp_msg);
+        ccs_serv_make_nack(ccIteratorEnd, auth_info, session_info, resp_msg);
     }
     return ccNoError;
 }       
@@ -1495,6 +1524,6 @@ ccop_CREDS_RELEASE( cc_server_context_t* ctx,
                     cc_msg_t *msg, cc_msg_t **resp_msg) 
 {       
         
-    cci_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
+    ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg);
     return ccNoError;
 }       
index f4395668554624d69ed9488a248a138548fbf370..152188636b79c4cf4f5ec5a9d7e64727b8c9818a 100644 (file)
@@ -1,6 +1,6 @@
 /* $Copyright:
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004-2006 by the Massachusetts Institute of Technology.
  * 
  * All rights reserved.
  * 
@@ -63,52 +63,88 @@ struct type_to_op_mapping_t {
 };
 typedef struct type_to_op_mapping_t type_to_op_mapping_t;
 
-cc_int32 cci_serv_initialize(void);
-cc_int32 cci_serv_process_msg(cc_msg_t * msg, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** resp_msg);
-cc_int32 cci_serv_find_ctx(cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_server_context_t** contextp);
-cc_int32 cci_serv_find_ctx_by_handle(cc_handle ctx_handle, cc_auth_info_t *auth, cc_session_info_t* session, cc_server_context_t** contextp);
-cc_int32 cci_serv_find_ccache_by_handle(cc_server_context_t* ctx, cc_handle ccache_handle, cc_server_ccache_t** ccachep) ;
-cc_int32 cci_serv_find_ccache_iterator_by_handle(cc_server_context_t* ctx, cc_handle iterator, cc_generic_list_node_t** nodep);
-cc_int32 cci_serv_find_creds_iterator_by_handle(cc_server_ccache_t* ccache, cc_handle iterator, cc_generic_list_node_t** nodep);
-cc_int32 cci_serv_make_nack(cc_int32 err_code, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** msgp);
-cc_int32 cci_serv_make_ack(void * header, cc_int32 header_len, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** msgp);
-
-cc_int32 ccop_INIT( 
+cc_int32 ccs_serv_initialize(void);
+cc_int32 ccs_serv_process_msg(cc_msg_t * msg, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** resp_msg);
+cc_int32 ccs_serv_find_ctx(cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_server_context_t** contextp);
+cc_int32 ccs_serv_find_ctx_by_handle(cc_handle ctx_handle, cc_auth_info_t *auth, cc_session_info_t* session, cc_server_context_t** contextp);
+cc_int32 ccs_serv_find_ccache_by_handle(cc_server_context_t* ctx, cc_handle ccache_handle, cc_server_ccache_t** ccachep) ;
+cc_int32 ccs_serv_find_ccache_iterator_by_handle(cc_server_context_t* ctx, cc_handle iterator, cc_generic_list_node_t** nodep);
+cc_int32 ccs_serv_find_creds_iterator_by_handle(cc_server_ccache_t* ccache, cc_handle iterator, cc_generic_list_node_t** nodep);
+cc_int32 ccs_serv_make_nack(cc_int32 err_code, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** msgp);
+cc_int32 ccs_serv_make_ack(void * header, cc_int32 header_len, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** msgp);
+
+cc_int32 
+ccop_INIT(
         cc_server_context_t* ctx,
         cc_auth_info_t* auth_info,
         cc_session_info_t* session_info,
         cc_msg_t *msg,
         cc_msg_t **resp_msg);
 
-cc_int32 ccop_CTX_RELEASE(
+cc_int32 
+ccop_CTX_RELEASE(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CTX_GET_CHANGE_TIME(
+cc_int32 
+ccop_CTX_GET_CHANGE_TIME(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CTX_GET_DEFAULT_CCACHE_NAME(
+cc_int32 
+ccop_CTX_GET_DEFAULT_CCACHE_NAME(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CTX_COMPARE(
+cc_int32 
+ccop_CTX_CCACHE_OPEN(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CTX_NEW_CCACHE_ITERATOR(
+cc_int32 
+ccop_CTX_CCACHE_OPEN_DEFAULT(
+       cc_server_context_t* ctx,
+       cc_auth_info_t* auth_info,
+       cc_session_info_t* session_info,
+       cc_msg_t *msg,
+       cc_msg_t **resp_msg);
+
+cc_int32 
+ccop_CTX_CCACHE_CREATE(
+       cc_server_context_t* ctx,
+       cc_auth_info_t* auth_info,
+       cc_session_info_t* session_info,
+       cc_msg_t *msg,
+       cc_msg_t **resp_msg);
+
+cc_int32 
+ccop_CTX_CCACHE_CREATE_DEFAULT( cc_server_context_t* ctx,
+                            cc_auth_info_t* auth_info,
+                            cc_session_info_t* session_info,
+                            cc_msg_t *msg, 
+                            cc_msg_t **resp_msg);
+
+cc_int32 
+ccop_CTX_CCACHE_CREATE_UNIQUE( cc_server_context_t* ctx,
+                           cc_auth_info_t* auth_info,
+                           cc_session_info_t* session_info,
+                           cc_msg_t *msg, 
+                           cc_msg_t **resp_msg);
+
+cc_int32 
+ccop_CTX_NEW_CCACHE_ITERATOR(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
@@ -129,28 +165,24 @@ ccop_CTX_UNLOCK( cc_server_context_t* ctx,
                  cc_msg_t *msg, 
                  cc_msg_t **resp_msg);
 
-cc_int32
-ccop_CTX_CLONE( cc_server_context_t* ctx,
-                cc_auth_info_t* auth_info,
-                cc_session_info_t* session_info,
-                cc_msg_t *msg, 
-                cc_msg_t **resp_msg);
-
-cc_int32 ccop_CCACHE_OPEN(
+cc_int32 
+ccop_CTX_COMPARE(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_OPEN_DEFAULT(
+cc_int32 
+ccop_CCACHE_RELEASE(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_CREATE(
+cc_int32 
+ccop_CCACHE_DESTROY(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
@@ -158,90 +190,95 @@ cc_int32 ccop_CCACHE_CREATE(
        cc_msg_t **resp_msg);
 
 cc_int32 
-ccop_CCACHE_CREATE_DEFAULT( cc_server_context_t* ctx,
-                            cc_auth_info_t* auth_info,
-                            cc_session_info_t* session_info,
-                            cc_msg_t *msg, 
-                            cc_msg_t **resp_msg);
-
-cc_int32 
-ccop_CCACHE_CREATE_UNIQUE( cc_server_context_t* ctx,
-                           cc_auth_info_t* auth_info,
-                           cc_session_info_t* session_info,
-                           cc_msg_t *msg, 
-                           cc_msg_t **resp_msg);
-
-cc_int32 ccop_CCACHE_RELEASE(
+ccop_CCACHE_SET_DEFAULT(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_DESTROY(
+cc_int32 
+ccop_CCACHE_GET_CREDS_VERSION(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_SET_DEFAULT(
+cc_int32 
+ccop_CCACHE_GET_NAME(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_GET_CREDS_VERSION(
+cc_int32 
+ccop_CCACHE_GET_PRINCIPAL(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_GET_NAME(
+cc_int32 
+ccop_CCACHE_SET_PRINCIPAL(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_GET_PRINCIPAL(
+cc_int32 
+ccop_CCACHE_STORE_CREDS(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_SET_PRINCIPAL(
+cc_int32 
+ccop_CCACHE_REM_CREDS(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_CREDS_ITERATOR(
+cc_int32 
+ccop_CCACHE_NEW_CREDS_ITERATOR(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_STORE_CREDS(
+cc_int32 
+ccop_CCACHE_MOVE(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_REM_CREDS(
-       cc_server_context_t* ctx,
-       cc_auth_info_t* auth_info,
-       cc_session_info_t* session_info,
-       cc_msg_t *msg,
-       cc_msg_t **resp_msg);
+cc_int32
+ccop_CCACHE_LOCK( 
+        cc_server_context_t* ctx,
+        cc_auth_info_t* auth_info,
+        cc_session_info_t* session_info,
+        cc_msg_t *msg, 
+        cc_msg_t **resp_msg);
+
+cc_int32
+ccop_CCACHE_UNLOCK( 
+        cc_server_context_t* ctx,
+        cc_auth_info_t* auth_info,
+        cc_session_info_t* session_info,
+        cc_msg_t *msg, 
+        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_GET_LAST_DEFAULT_TIME(
+cc_int32 
+ccop_CCACHE_GET_LAST_DEFAULT_TIME(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
@@ -256,63 +293,80 @@ ccop_CCACHE_GET_CHANGE_TIME(
         cc_msg_t *msg, 
         cc_msg_t **resp_msg) ;
 
-cc_int32 ccop_CCACHE_COMPARE(
+cc_int32 
+ccop_CCACHE_COMPARE(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_GET_KDC_TIME_OFFSET(
+cc_int32 
+ccop_CCACHE_GET_KDC_TIME_OFFSET(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_SET_KDC_TIME_OFFSET(
+cc_int32 
+ccop_CCACHE_SET_KDC_TIME_OFFSET(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_CLEAR_KDC_TIME_OFFSET(
+cc_int32 
+ccop_CCACHE_CLEAR_KDC_TIME_OFFSET(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_ITERATOR_RELEASE(
+cc_int32 
+ccop_CCACHE_ITERATOR_RELEASE(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CCACHE_ITERATOR_NEXT(
+cc_int32 
+ccop_CCACHE_ITERATOR_NEXT(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CREDS_ITERATOR_RELEASE(
+cc_int32 
+ccop_CCACHE_ITERATOR_CLONE(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CREDS_ITERATOR_NEXT(
+cc_int32 
+ccop_CREDS_ITERATOR_RELEASE(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
        cc_msg_t *msg,
        cc_msg_t **resp_msg);
 
-cc_int32 ccop_CREDS_RELEASE(
+cc_int32 
+ccop_CREDS_ITERATOR_NEXT(
+       cc_server_context_t* ctx,
+       cc_auth_info_t* auth_info,
+       cc_session_info_t* session_info,
+       cc_msg_t *msg,
+       cc_msg_t **resp_msg);
+
+cc_int32
+ccop_CREDS_ITERATOR_CLONE(
        cc_server_context_t* ctx,
        cc_auth_info_t* auth_info,
        cc_session_info_t* session_info,
diff --git a/src/lib/ccapi/unit-test/NTMakefile b/src/lib/ccapi/unit-test/NTMakefile
new file mode 100644 (file)
index 0000000..eb2fd53
--- /dev/null
@@ -0,0 +1,30 @@
+# Makefile for the CCAPI Generic Server\r
+\r
+!INCLUDE <WIN32.MAK>\r
+\r
+CFLAGS = -I../include\r
+\r
+CCAPI_LIB = ../lib/ccapi.lib\r
+WINLIBS = user32.lib advapi32.lib\r
+CCSOBJS = context.obj ccache.obj lists.obj rpc_auth.obj serv_ops.obj\r
+\r
+all: t_lists.exe t_msg.exe t_ccache.exe t_context.exe ccapi_server.exe\r
+\r
+t_lists.exe: t_lists.obj $(CCSOBJS) $(CCAPI_LIB)\r
+        link -out:$@ t_lists.obj $(CCSOBJS) $(CCAPI_LIB) $(WINLIBS)\r
+\r
+t_msg.exe: t_msg.obj $(CCSOBJS) $(CCAPI_LIB)\r
+        link -out:$@ t_msg.obj $(CCSOBJS) $(CCAPI_LIB) $(WINLIBS)\r
+\r
+t_ccache.exe: t_ccache.obj $(CCSOBJS) $(CCAPI_LIB)\r
+        link -out:$@ t_ccache.obj $(CCSOBJS) $(CCAPI_LIB) $(WINLIBS)\r
+\r
+t_context.exe: t_context.obj $(CCSOBJS) $(CCAPI_LIB)\r
+        link -out:$@ t_context.obj $(CCSOBJS) $(CCAPI_LIB) $(WINLIBS)\r
+\r
+ccapi_server.exe: main.obj $(CCSOBJS) $(CCAPI_LIB)\r
+        link -out:$@ main.obj $(CCSOBJS) $(CCAPI_LIB) $(WINLIBS)\r
+\r
+clean: \r
+       del *.obj *.exe\r
+\r
diff --git a/src/lib/ccapi/windows/rpcsstest/NTMakefile b/src/lib/ccapi/windows/rpcsstest/NTMakefile
new file mode 100644 (file)
index 0000000..0e23307
--- /dev/null
@@ -0,0 +1,24 @@
+\r
+!include <win32.mak>\r
+\r
+{}.c{}.obj:\r
+       $(CC) $(cdebug) $(cflags) /Fo"$@" /c $**\r
+\r
+EXECONLINK=link /NOLOGO $(conlibsmt) $(ldebug) $(conlflags) /OUT:$@ $**\r
+\r
+CLIENTEXE=csclient.exe\r
+\r
+SERVEREXE=csserver.exe\r
+\r
+SDKLIBS=rpcrt4.lib\r
+\r
+cstest_c.c cstest_s.c cstest.h: cstest.idl cstest.acf\r
+       midl cstest.idl /acf cstest.acf\r
+\r
+$(CLIENTEXE): client.obj cstest_c.obj\r
+       $(EXECONLINK) $(SDKLIBS)\r
+\r
+$(SERVEREXE): server.obj cstest_s.obj\r
+       $(EXECONLINK) $(SDKLIBS)\r
+\r
+all: $(SERVEREXE) $(CLIENTEXE)\r
diff --git a/src/lib/ccapi/windows/rpcsstest/client.c b/src/lib/ccapi/windows/rpcsstest/client.c
new file mode 100644 (file)
index 0000000..a25e8d1
--- /dev/null
@@ -0,0 +1,87 @@
+#include<windows.h>\r
+#include<stdio.h>\r
+#include<stdlib.h>\r
+#include<tchar.h>\r
+#include"cstest.h"\r
+#include<strsafe.h>\r
+\r
+void * __RPC_USER MIDL_user_allocate(size_t s) {\r
+    return malloc(s);\r
+}\r
+\r
+void __RPC_USER MIDL_user_free(void * p) {\r
+    free(p);\r
+}\r
+\r
+int main(int argc, char ** argv) {\r
+    RPC_STATUS status;\r
+    RPC_BINDING_HANDLE h;\r
+    TCHAR * bindstring = NULL;\r
+    RPC_SECURITY_QOS sqos;\r
+    char inbuf[256];\r
+    char outbuf[256];\r
+    long cb_out;\r
+\r
+    status = RpcStringBindingCompose(NULL,\r
+                                     _T("ncalrpc"),\r
+                                     NULL,\r
+                                     NULL,\r
+                                     NULL,\r
+                                     &bindstring);\r
+\r
+    if (status != RPC_S_OK) {\r
+        fprintf(stderr, "RpcStringBindingCompose failed: %d\n",\r
+                status);\r
+        return 1;\r
+    }\r
+\r
+    status = RpcBindingFromStringBinding(bindstring,\r
+                                         &h);\r
+\r
+    if (status != RPC_S_OK) {\r
+        fprintf(stderr, "RpcBindingFromStringBinding failed: %d\n",\r
+                status);\r
+        return 1;\r
+    }\r
+\r
+    ZeroMemory(&sqos, sizeof(sqos));\r
+\r
+    sqos.Version = 1;\r
+    sqos.Capabilities = RPC_C_QOS_CAPABILITIES_DEFAULT;\r
+    sqos.IdentityTracking = RPC_C_QOS_IDENTITY_STATIC;\r
+    sqos.ImpersonationType = RPC_C_IMP_LEVEL_IMPERSONATE;\r
+\r
+    status = RpcBindingSetAuthInfoEx(h,\r
+                                     NULL,\r
+                                     RPC_C_AUTHN_LEVEL_CALL,\r
+                                     RPC_C_AUTHN_WINNT,\r
+                                     NULL,\r
+                                     0,\r
+                                     &sqos);\r
+\r
+    if (status != RPC_S_OK) {\r
+        fprintf(stderr, "RpcBindingSetAuthInfoEx failed: %d\n",\r
+                status);\r
+        return 1;\r
+    }\r
+\r
+    StringCbCopyA(inbuf, sizeof(inbuf), "Echo Test 1");\r
+    StringCbCopyA(outbuf, sizeof(outbuf), "Blank blank blank");\r
+\r
+    printf("Before call: in[%s], out[%s]\n", inbuf, outbuf);\r
+    cb_out = 0;\r
+\r
+    status = EchoString(h, inbuf, sizeof(outbuf), &cb_out, outbuf);\r
+\r
+    if (status) {\r
+        printf("Call failed: status = %d\n", status);\r
+    } else {\r
+        printf("After call: out[%s], outlen[%d]\n", outbuf, cb_out);\r
+    }\r
+\r
+    status = RpcBindingFree(&h);\r
+\r
+    status = RpcStringFree(&bindstring);\r
+\r
+    return 0;\r
+}\r
diff --git a/src/lib/ccapi/windows/rpcsstest/cstest.acf b/src/lib/ccapi/windows/rpcsstest/cstest.acf
new file mode 100644 (file)
index 0000000..3c2ae73
--- /dev/null
@@ -0,0 +1,8 @@
+[\r
+    explicit_handle\r
+]\r
+\r
+interface ccapi_cstest\r
+{\r
+\r
+}
\ No newline at end of file
diff --git a/src/lib/ccapi/windows/rpcsstest/cstest.idl b/src/lib/ccapi/windows/rpcsstest/cstest.idl
new file mode 100644 (file)
index 0000000..c51b8ee
--- /dev/null
@@ -0,0 +1,14 @@
+[\r
+uuid(c8b4a635-e9e4-4650-a073-b25610324950),\r
+    version(1.0),\r
+    pointer_default(unique)\r
+]\r
+\r
+interface ccapi_cstest\r
+{\r
+    long EchoString([in] handle_t h,\r
+                    [in, string] unsigned char * in_str,\r
+                    [in] long cb_buffer,\r
+                    [out] long * cb_len,\r
+                    [out, string, size_is(cb_buffer)] unsigned char buffer[*]);\r
+}\r
diff --git a/src/lib/ccapi/windows/rpcsstest/server.c b/src/lib/ccapi/windows/rpcsstest/server.c
new file mode 100644 (file)
index 0000000..f127434
--- /dev/null
@@ -0,0 +1,537 @@
+#include<windows.h>\r
+#include<stdio.h>\r
+#include<process.h>\r
+#include<tchar.h>\r
+#include<rpc.h>\r
+#include"cstest.h"\r
+#include<strsafe.h>\r
+\r
+#define SVCNAME "CCAPICSTest"\r
+\r
+SERVICE_STATUS_HANDLE h_service_status = NULL;\r
+SERVICE_STATUS service_status;\r
+FILE * logfile = NULL;\r
+\r
+void begin_log(void) {\r
+    char temppath[512];\r
+\r
+    temppath[0] = L'\0';\r
+\r
+    GetTempPathA(sizeof(temppath), temppath);\r
+    StringCbCatA(temppath, sizeof(temppath), "csserverconn.log");\r
+    logfile = fopen(temppath, "w");\r
+}\r
+\r
+void end_log(void) {\r
+    if (logfile) {\r
+        fclose(logfile);\r
+        logfile = NULL;\r
+    }\r
+}\r
+\r
+BOOL report_status(DWORD state,\r
+                   DWORD exit_code,\r
+                   DWORD wait_hint) {\r
+    static DWORD checkpoint = 1;\r
+    BOOL rv = TRUE;\r
+\r
+    if (state == SERVICE_START_PENDING)\r
+        service_status.dwControlsAccepted = 0;\r
+    else\r
+        service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;\r
+\r
+    service_status.dwCurrentState = state;\r
+    service_status.dwWin32ExitCode = exit_code;\r
+    service_status.dwWaitHint = wait_hint;\r
+\r
+    if (state == SERVICE_RUNNING ||\r
+        state == SERVICE_STOPPED)\r
+        service_status.dwCheckPoint = 0;\r
+    else\r
+        service_status.dwCheckPoint = checkpoint++;\r
+\r
+    rv = SetServiceStatus(h_service_status, &service_status);\r
+\r
+    return rv;\r
+}\r
+\r
+void service_start(DWORD argc, LPTSTR * argv) {\r
+    RPC_STATUS status;\r
+    RPC_BINDING_VECTOR * bv;\r
+\r
+    status = RpcServerUseProtseq("ncalrpc",\r
+                                 RPC_C_PROTSEQ_MAX_REQS_DEFAULT,\r
+                                 NULL);\r
+\r
+    if (status != RPC_S_OK) {\r
+        return;\r
+    }\r
+\r
+    report_status(SERVICE_START_PENDING, NO_ERROR, 3000);\r
+\r
+    status = RpcServerRegisterIf(ccapi_cstest_v1_0_s_ifspec,\r
+                                 0, 0);\r
+\r
+    if (status != RPC_S_OK)\r
+        return;\r
+\r
+    report_status(SERVICE_START_PENDING, NO_ERROR, 3000);\r
+\r
+    status = RpcServerInqBindings(&bv);\r
+\r
+    if (status != RPC_S_OK)\r
+        return;\r
+\r
+    status = RpcEpRegister(ccapi_cstest_v1_0_s_ifspec,\r
+                           bv, 0, 0);\r
+\r
+    if (status != RPC_S_OK)\r
+        return;\r
+\r
+    report_status(SERVICE_START_PENDING, NO_ERROR, 3000);\r
+\r
+    status = RpcServerRegisterAuthInfo(NULL,\r
+                                       RPC_C_AUTHN_WINNT,\r
+                                       0, 0);\r
+\r
+    if (status != RPC_S_OK)\r
+        return;\r
+\r
+    report_status(SERVICE_START_PENDING, NO_ERROR, 3000);\r
+\r
+    status = RpcServerListen(1,\r
+                             RPC_C_LISTEN_MAX_CALLS_DEFAULT,\r
+                             TRUE);\r
+\r
+    if (status != RPC_S_OK)\r
+        return;\r
+\r
+    report_status(SERVICE_RUNNING, NO_ERROR, 0);\r
+\r
+    begin_log();\r
+\r
+    status = RpcMgmtWaitServerListen();\r
+\r
+    end_log();\r
+\r
+    RpcEpUnregister(ccapi_cstest_v1_0_s_ifspec, bv, 0);\r
+\r
+    RpcBindingVectorFree(&bv);\r
+}\r
+\r
+void service_stop(void) {\r
+    RpcMgmtStopServerListening(0);\r
+}\r
+\r
+void * __RPC_USER MIDL_user_allocate(size_t s) {\r
+    return malloc(s);\r
+}\r
+\r
+void __RPC_USER MIDL_user_free(void * p) {\r
+    free(p);\r
+}\r
+\r
+typedef struct tag_client_info {\r
+    char client_name[512];\r
+    LUID luid;    \r
+} client_info_t;\r
+\r
+RPC_STATUS check_auth(handle_t h, client_info_t * client_info) {\r
+    RPC_BINDING_HANDLE bh = (RPC_BINDING_HANDLE) h;\r
+    RPC_STATUS status;\r
+    HANDLE htoken = NULL;\r
+    char name[256];\r
+    char domain[256];\r
+    DWORD name_len;\r
+    DWORD domain_len;\r
+    SID_NAME_USE snu = 0;\r
+\r
+    struct {\r
+        TOKEN_ORIGIN origin;\r
+        char pad[512];\r
+    } torigin;\r
+\r
+    struct {\r
+        TOKEN_OWNER owner;\r
+        char pad[4096];\r
+    } towner;\r
+\r
+    DWORD len;\r
+\r
+    status = RpcImpersonateClient(bh);\r
+\r
+    if (status != RPC_S_OK)\r
+        return status;\r
+\r
+    if (!OpenThreadToken(GetCurrentThread(),\r
+                         TOKEN_READ | TOKEN_QUERY_SOURCE,\r
+                         FALSE,\r
+                         &htoken)) {\r
+        status = GetLastError();\r
+        goto _cleanup;\r
+    }\r
+\r
+    len = 0;\r
+\r
+    if (!GetTokenInformation(htoken,\r
+                             TokenOrigin,\r
+                             &torigin.origin,\r
+                             sizeof(torigin),\r
+                             &len)) {\r
+        status = GetLastError();\r
+        goto _cleanup;\r
+    }\r
+\r
+    if (!GetTokenInformation(htoken,\r
+                             TokenOwner,\r
+                             &towner.owner,\r
+                             sizeof(towner),\r
+                             &len)) {\r
+        status = GetLastError();\r
+        goto _cleanup;\r
+    }\r
+\r
+\r
+    name_len = sizeof(name)/sizeof(name[0]);\r
+    domain_len = sizeof(domain)/sizeof(domain[0]);\r
+\r
+    if (!LookupAccountSidA(NULL,\r
+                           towner.owner.Owner,\r
+                           name,\r
+                           &name_len,\r
+                           domain,\r
+                           &domain_len,\r
+                           &snu)) {\r
+        status = GetLastError();\r
+        goto _cleanup;\r
+    }\r
+\r
+    client_info->luid = torigin.origin.OriginatingLogonSession;\r
+    StringCbPrintfA(client_info->client_name,\r
+                    sizeof(client_info->client_name),\r
+                    "%s\\%s", domain, name);\r
+\r
+    status = 0;\r
+\r
+ _cleanup:\r
+\r
+    RpcRevertToSelf();\r
+\r
+    return status;\r
+}\r
+\r
+long EchoString(\r
+    /* [in] */ handle_t h,\r
+    /* [string][in] */ unsigned char *in_str,\r
+    /* [in] */ long cb_buffer,\r
+    /* [out] */ long *cb_len,\r
+    /* [size_is][string][out] */ unsigned char buffer[  ]) {\r
+\r
+    size_t cb;\r
+    long rv = 0;\r
+    client_info_t client_info;\r
+\r
+    rv = check_auth(h, &client_info);\r
+\r
+    if (rv == 0 && logfile) {\r
+        fprintf(logfile,\r
+                "Client name [%s], LUID [%x:%x]\n",\r
+                client_info.client_name,\r
+                (client_info.luid.HighPart),\r
+                (client_info.luid.LowPart));\r
+        fflush(logfile);\r
+    }\r
+\r
+    if (!in_str) {\r
+        rv = 1;\r
+        if (cb_len)\r
+            *cb_len = 0;\r
+        if (buffer)\r
+            buffer[0] = '\0';\r
+    } else {\r
+        if (FAILED(StringCbLengthA(in_str, 256, &cb))) {\r
+            rv = 2;\r
+            goto _exit_f;\r
+        }\r
+\r
+        cb += sizeof(char);\r
+\r
+        if (((long)cb) > cb_buffer) {\r
+            rv = 3;\r
+            goto _exit_f;\r
+        }\r
+\r
+        *cb_len = cb;\r
+\r
+        if (buffer)\r
+            StringCbCopyA(buffer, cb_buffer, in_str);\r
+\r
+        rv = 0;\r
+    }\r
+\r
+ _exit_f:\r
+\r
+    return rv;\r
+}\r
+\r
+void WINAPI service_control(DWORD ctrl_code) {\r
+    switch(ctrl_code) {\r
+    case SERVICE_CONTROL_STOP:\r
+        report_status(SERVICE_STOP_PENDING, NO_ERROR, 0);\r
+        service_stop();\r
+        return;\r
+\r
+        /* everything else falls through */\r
+    }\r
+\r
+    report_status(service_status.dwCurrentState, NO_ERROR, 0);\r
+}\r
+\r
+void WINAPI service_main(DWORD argc, LPTSTR * argv) {\r
+\r
+    h_service_status = RegisterServiceCtrlHandler( _T(SVCNAME), service_control);\r
+\r
+    if (!h_service_status)\r
+        goto cleanup;\r
+\r
+    ZeroMemory(&service_status, sizeof(service_status));\r
+\r
+    service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;\r
+    service_status.dwServiceSpecificExitCode = 0;\r
+\r
+    if (!report_status(SERVICE_START_PENDING,\r
+                       NO_ERROR,\r
+                       3000))\r
+        goto cleanup;\r
+\r
+    service_start(argc, argv);\r
+\r
+ cleanup:\r
+\r
+    if (h_service_status) {\r
+        report_status(SERVICE_STOPPED, NO_ERROR, 0);\r
+    }\r
+}\r
+\r
+\r
+BOOL\r
+IsInstalled()\r
+{\r
+    BOOL bResult = FALSE;\r
+    SC_HANDLE hSCM;\r
+    SC_HANDLE hService;\r
+\r
+    // Open the Service Control Manager\r
+    hSCM = OpenSCManager( NULL, // local machine\r
+                          NULL, // ServicesActive database\r
+                          SC_MANAGER_ALL_ACCESS); // full access\r
+    if (hSCM) {\r
+\r
+        // Try to open the service\r
+        hService = OpenService( hSCM,\r
+                                SVCNAME,\r
+                                SERVICE_QUERY_CONFIG);\r
+        if (hService) {\r
+            bResult = TRUE;\r
+            CloseServiceHandle(hService);\r
+        }\r
+\r
+        CloseServiceHandle(hSCM);\r
+    }\r
+\r
+    return bResult;\r
+}\r
+\r
+BOOL\r
+Install()\r
+{\r
+    char szFilePath[_MAX_PATH];\r
+    SC_HANDLE hSCM;\r
+    SC_HANDLE hService;\r
+    TCHAR szKey[256];\r
+    HKEY hKey = NULL;\r
+    DWORD dwData;\r
+\r
+    // Open the Service Control Manager\r
+    hSCM = OpenSCManager( NULL, // local machine\r
+                          NULL, // ServicesActive database\r
+                          SC_MANAGER_ALL_ACCESS); // full access\r
+    if (!hSCM)\r
+        return FALSE;\r
+\r
+    // Get the executable file path\r
+    GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));\r
+\r
+    // Create the service\r
+    hService = CreateService( hSCM,\r
+                              SVCNAME,\r
+                              SVCNAME,\r
+                              SERVICE_ALL_ACCESS,\r
+                              SERVICE_WIN32_OWN_PROCESS,\r
+                              SERVICE_AUTO_START,        // start condition\r
+                              SERVICE_ERROR_NORMAL,\r
+                              szFilePath,\r
+                              NULL,\r
+                              NULL,\r
+                              NULL,\r
+                              NULL,\r
+                              NULL);\r
+    if (!hService) {\r
+        CloseServiceHandle(hSCM);\r
+        return FALSE;\r
+    }\r
+\r
+    // make registry entries to support logging messages\r
+    // Add the source name as a subkey under the Application\r
+    // key in the EventLog service portion of the registry.\r
+    StringCbCopyA(szKey, 256, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\IKSD");\r
+    if (RegCreateKey(HKEY_LOCAL_MACHINE, szKey, &hKey) != ERROR_SUCCESS) {\r
+        CloseServiceHandle(hService);\r
+        CloseServiceHandle(hSCM);\r
+        return FALSE;\r
+    }\r
+\r
+    // Add the Event ID message-file name to the 'EventMessageFile' subkey.\r
+    RegSetValueEx( hKey,\r
+                   "EventMessageFile",\r
+                    0,\r
+                    REG_EXPAND_SZ,\r
+                    (CONST BYTE*)szFilePath,\r
+                    strlen(szFilePath) + 1);\r
+\r
+    // Set the supported types flags.\r
+    dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;\r
+    RegSetValueEx( hKey,\r
+                   "TypesSupported",\r
+                    0,\r
+                    REG_DWORD,\r
+                    (CONST BYTE*)&dwData,\r
+                     sizeof(DWORD));\r
+    RegCloseKey(hKey);\r
+\r
+    // LogEvent(EVENTLOG_INFORMATION_TYPE, EVMSG_INSTALLED, SVCNAME);\r
+\r
+    // tidy up\r
+    CloseServiceHandle(hService);\r
+    CloseServiceHandle(hSCM);\r
+    return TRUE;\r
+}\r
+\r
+BOOL\r
+Uninstall()\r
+{\r
+    BOOL bResult = FALSE;\r
+    SC_HANDLE hService;\r
+    SC_HANDLE hSCM;\r
+\r
+    // Open the Service Control Manager\r
+    hSCM = OpenSCManager( NULL, // local machine\r
+                          NULL, // ServicesActive database\r
+                          SC_MANAGER_ALL_ACCESS); // full access\r
+    if (!hSCM)\r
+        return FALSE;\r
+\r
+    hService = OpenService( hSCM,\r
+                            SVCNAME,\r
+                            DELETE);\r
+    if (hService) {\r
+        if (DeleteService(hService)) {\r
+            // LogEvent(EVENTLOG_INFORMATION_TYPE, EVMSG_REMOVED, SVCNAME);\r
+            bResult = TRUE;\r
+        } else {\r
+            // LogEvent(EVENTLOG_ERROR_TYPE, EVMSG_NOTREMOVED, SVCNAME);\r
+        }\r
+        CloseServiceHandle(hService);\r
+    }\r
+\r
+    CloseServiceHandle(hSCM);\r
+    return bResult;\r
+}\r
+\r
+\r
+// Returns TRUE if it found an arg it recognised, FALSE if not\r
+// Note: processing some arguments causes output to stdout to be generated.\r
+BOOL\r
+ParseStandardArgs(int argc, char* argv[])\r
+{\r
+    char szFilePath[_MAX_PATH];\r
+\r
+    // See if we have any command line args we recognize\r
+    if (argc <= 1)\r
+        return FALSE;\r
+\r
+    if ( _stricmp(argv[1], "-h") == 0 ||\r
+         _stricmp(argv[1], "-?") == 0 ||\r
+         _stricmp(argv[1], "/h") == 0 ||\r
+         _stricmp(argv[1], "/?") == 0) {\r
+\r
+        //\r
+        GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));\r
+        fprintf(stderr, "usage: %s [-v | -i | -u | -h]\r\n",szFilePath);\r
+        return TRUE;\r
+    } else if (_stricmp(argv[1], "-v") == 0 ||\r
+               _stricmp(argv[1], "/v") == 0 ) {\r
+\r
+        // Spit out version info\r
+        fprintf(stderr, "%s Version 0.1\n",_T(SVCNAME));\r
+        fprintf(stderr, "The service is %s installed\n",\r
+               IsInstalled() ? "currently" : "not");\r
+        return TRUE; // say we processed the argument\r
+\r
+    } else if (_stricmp(argv[1], "-i") == 0 ||\r
+               _stricmp(argv[1], "/i") == 0) {\r
+\r
+        // Request to install.\r
+        if (IsInstalled()) {\r
+            fprintf(stderr, "%s is already installed\n", _T(SVCNAME));\r
+        } else {\r
+            // Try and install the copy that's running\r
+            if (Install()) {\r
+                fprintf(stderr, "%s installed\n", _T(SVCNAME));\r
+            } else {\r
+                fprintf(stderr, "%s failed to install. Error %d\n", _T(SVCNAME), GetLastError());\r
+            }\r
+        }\r
+        return TRUE; // say we processed the argument\r
+\r
+    } else if (_stricmp(argv[1], "-u") == 0 ||\r
+               _stricmp(argv[1], "/u") == 0) {\r
+\r
+        // Request to uninstall.\r
+        if (!IsInstalled()) {\r
+            fprintf(stderr, "%s is not installed\n", _T(SVCNAME));\r
+        } else {\r
+            // Try and remove the copy that's installed\r
+            if (Uninstall()) {\r
+                // Get the executable file path\r
+                GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));\r
+                fprintf(stderr, "%s removed. (You must delete the file (%s) yourself.)\n"\r
+                       _T(SVCNAME), szFilePath);\r
+            } else {\r
+                fprintf(stderr, "Could not remove %s. Error %d\n", _T(SVCNAME), GetLastError());\r
+            }\r
+        }\r
+        return TRUE; // say we processed the argument\r
+\r
+    }\r
+\r
+    // Don't recognise the args\r
+    return FALSE;\r
+}\r
+\r
+int main(int argc, char ** argv) {\r
+\r
+    SERVICE_TABLE_ENTRY dispatch_table[] = {\r
+        { _T(SVCNAME), (LPSERVICE_MAIN_FUNCTION) service_main },\r
+        { NULL, NULL }\r
+    };\r
+\r
+    if ( ParseStandardArgs(argc, argv) )\r
+       return 0;\r
+\r
+    if (!StartServiceCtrlDispatcher(dispatch_table)) {\r
+        fprintf(stderr, "Can't start service control dispatcher\n");\r
+    }\r
+\r
+    return 0;\r
+}\r