diff options
author | Jeffrey Altman <jaltman@secure-endpoints.com> | 2006-06-05 17:49:34 +0000 |
---|---|---|
committer | Jeffrey Altman <jaltman@secure-endpoints.com> | 2006-06-05 17:49:34 +0000 |
commit | f42fa33b985c230736ad5d9080055916de33be8c (patch) | |
tree | 0f6cc37148d66dc13ca10bb268679ea4c99677bf /src | |
parent | 3d6591dd63c23bcc0ae68e94a960c85fd53daad0 (diff) | |
download | krb5-f42fa33b985c230736ad5d9080055916de33be8c.tar.gz krb5-f42fa33b985c230736ad5d9080055916de33be8c.tar.xz krb5-f42fa33b985c230736ad5d9080055916de33be8c.zip |
improved error handling
git-svn-id: svn://anonsvn.mit.edu/krb5/branches/ccapi@18083 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/ccapi/client/cacheapi.c | 26 | ||||
-rw-r--r-- | src/lib/ccapi/client/ccache.c | 544 | ||||
-rw-r--r-- | src/lib/ccapi/client/ccache_iterator.c | 91 | ||||
-rw-r--r-- | src/lib/ccapi/client/context.c | 402 | ||||
-rw-r--r-- | src/lib/ccapi/client/credentials_iterator.c | 81 | ||||
-rw-r--r-- | src/lib/ccapi/common/msg.c | 24 | ||||
-rw-r--r-- | src/lib/ccapi/unit-test/NTMakefile | 7 | ||||
-rw-r--r-- | src/lib/ccapi/windows/client.c | 33 | ||||
-rw-r--r-- | src/lib/ccapi/windows/server.c | 77 |
9 files changed, 840 insertions, 445 deletions
diff --git a/src/lib/ccapi/client/cacheapi.c b/src/lib/ccapi/client/cacheapi.c index 14a1eb476..c76ebe457 100644 --- a/src/lib/ccapi/client/cacheapi.c +++ b/src/lib/ccapi/client/cacheapi.c @@ -64,9 +64,9 @@ cc_initialize ( cc_context_t* outContext, char const** outVendor) { static char vendor[128] = ""; - cc_msg_t *request; + cc_msg_t *request = NULL; ccmsg_init_t *request_header; - cc_msg_t *response; + cc_msg_t *response = NULL; cc_uint32 type; ccmsg_init_resp_t *response_header; cc_int32 code; @@ -100,14 +100,17 @@ cc_initialize ( cc_context_t* outContext, request_header->in_version = htonl(inVersion); code = cci_msg_new(ccmsg_INIT, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_init_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -131,8 +134,15 @@ cc_initialize ( cc_context_t* outContext, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } diff --git a/src/lib/ccapi/client/ccache.c b/src/lib/ccapi/client/ccache.c index 790ff6f67..e4b9673c7 100644 --- a/src/lib/ccapi/client/ccache.c +++ b/src/lib/ccapi/client/ccache.c @@ -107,9 +107,9 @@ 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_msg_t *request = NULL; + ccmsg_ccache_release_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -128,14 +128,17 @@ cc_int_ccache_release( cc_ccache_t ccache ) request_header->ccache = htonll(int_ccache->handle); code = cci_msg_new(ccmsg_CCACHE_RELEASE, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_release_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -146,9 +149,16 @@ cc_int_ccache_release( cc_ccache_t ccache ) } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); - free(int_ccache->functions); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); + if (int_ccache->functions) + free(int_ccache->functions); free(int_ccache); return code; } @@ -158,9 +168,9 @@ 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_msg_t *request = NULL; + ccmsg_ccache_destroy_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -179,14 +189,17 @@ cc_int_ccache_destroy( cc_ccache_t ccache ) request_header->ccache = htonll(int_ccache->handle); code = cci_msg_new(ccmsg_CCACHE_DESTROY, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_destroy_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -197,8 +210,14 @@ cc_int_ccache_destroy( cc_ccache_t ccache ) } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); free(ccache); return code; } @@ -208,9 +227,9 @@ 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_msg_t *request = NULL; + ccmsg_ccache_set_default_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -229,14 +248,17 @@ cc_int_ccache_set_default( cc_ccache_t ccache ) request_header->ccache = htonll(int_ccache->handle); code = cci_msg_new(ccmsg_CCACHE_SET_DEFAULT, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_set_default_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -247,8 +269,14 @@ cc_int_ccache_set_default( cc_ccache_t ccache ) } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -257,9 +285,9 @@ cc_int_ccache_get_credentials_version( cc_ccache_t ccache, cc_uint32* credentials_version) { cc_int_ccache_t int_ccache; - cc_msg_t *request; - ccmsg_ccache_get_creds_version_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_get_creds_version_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -278,14 +306,17 @@ cc_int_ccache_get_credentials_version( cc_ccache_t ccache, request_header->ccache = htonll(int_ccache->handle); code = cci_msg_new(ccmsg_CCACHE_GET_CREDS_VERSION, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_get_creds_version_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -298,8 +329,14 @@ cc_int_ccache_get_credentials_version( cc_ccache_t ccache, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -307,9 +344,9 @@ cc_int32 cc_int_ccache_get_name( cc_ccache_t ccache, cc_string_t* name ) { cc_int_ccache_t int_ccache; - cc_msg_t *request; - ccmsg_ccache_get_name_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_get_name_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -328,14 +365,17 @@ cc_int_ccache_get_name( cc_ccache_t ccache, cc_string_t* name ) request_header->ccache = htonll(int_ccache->handle); code = cci_msg_new(ccmsg_CCACHE_GET_NAME, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_get_name_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -353,8 +393,14 @@ cc_int_ccache_get_name( cc_ccache_t ccache, cc_string_t* name ) } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -364,9 +410,9 @@ cc_int_ccache_get_principal( cc_ccache_t ccache, cc_string_t* principal ) { cc_int_ccache_t int_ccache; - cc_msg_t *request; - ccmsg_ccache_get_principal_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_get_principal_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -386,14 +432,17 @@ cc_int_ccache_get_principal( cc_ccache_t ccache, request_header->version = htonl(credentials_version); code = cci_msg_new(ccmsg_CCACHE_GET_PRINCIPAL, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_get_principal_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -411,8 +460,14 @@ cc_int_ccache_get_principal( cc_ccache_t ccache, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -423,9 +478,9 @@ cc_int_ccache_set_principal( cc_ccache_t ccache, { 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_msg_t *request = NULL; + ccmsg_ccache_set_principal_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -445,24 +500,24 @@ cc_int_ccache_set_principal( cc_ccache_t ccache, request_header->version = htonl(credentials_version); code = cci_msg_new(ccmsg_CCACHE_GET_PRINCIPAL, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_data_blob(request, (void*)principal, strlen(principal) + 1, &blob_pos); - if (code != ccNoError) { - cci_msg_destroy(request); - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; 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)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -473,8 +528,14 @@ cc_int_ccache_set_principal( cc_ccache_t ccache, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -483,9 +544,9 @@ 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; - ccmsg_ccache_creds_iterator_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_creds_iterator_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -504,14 +565,17 @@ cc_int_ccache_new_credentials_iterator( cc_ccache_t ccache, request_header->ccache = htonll(int_ccache->handle); code = cci_msg_new(ccmsg_CCACHE_NEW_CREDS_ITERATOR, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_creds_iterator_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -524,8 +588,14 @@ cc_int_ccache_new_credentials_iterator( cc_ccache_t ccache, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -534,9 +604,9 @@ cc_int_ccache_store_credentials( cc_ccache_t ccache, const cc_credentials_union* credentials ) { cc_int_ccache_t int_ccache; - cc_msg_t *request; - ccmsg_ccache_store_creds_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_store_creds_t *request_header = NULL; + cc_msg_t *response = NULL; char *flat_cred = 0; cc_uint32 flat_cred_len = 0; cc_uint32 blob_pos; @@ -558,10 +628,8 @@ cc_int_ccache_store_credentials( cc_ccache_t ccache, request_header->ccache = htonll(int_ccache->handle); code = cci_msg_new(ccmsg_CCACHE_STORE_CREDS, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; switch ( credentials->version ) { case cc_credentials_v4: @@ -571,30 +639,27 @@ cc_int_ccache_store_credentials( cc_ccache_t ccache, code = cci_creds_v5_marshall(credentials->credentials.credentials_v5, &flat_cred, &flat_cred_len); break; default: - cci_msg_destroy(request); - free(request_header); - return ccErrBadCredentialsVersion; - } - if (code != ccNoError) { - cci_msg_destroy(request); - free(request_header); - return code; + code = ccErrBadCredentialsVersion; } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_data_blob(request, (void*)flat_cred, flat_cred_len, &blob_pos); - if (code != ccNoError) { - cci_msg_destroy(request); - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; 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)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -605,9 +670,16 @@ cc_int_ccache_store_credentials( cc_ccache_t ccache, } else { code = ccErrBadInternalMessage; } - free(flat_cred); - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (flat_cred) + free(flat_cred); + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -617,9 +689,9 @@ cc_int_ccache_remove_credentials( cc_ccache_t ccache, { 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_msg_t *request = NULL; + ccmsg_ccache_rem_creds_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -644,14 +716,17 @@ cc_int_ccache_remove_credentials( cc_ccache_t ccache, request_header->creds = htonll(int_creds->handle); code = cci_msg_new(ccmsg_CCACHE_REM_CREDS, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_rem_creds_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -662,8 +737,14 @@ cc_int_ccache_remove_credentials( cc_ccache_t ccache, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -674,9 +755,9 @@ cc_int_ccache_move( cc_ccache_t source, { 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_msg_t *request = NULL; + ccmsg_ccache_move_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -698,18 +779,21 @@ cc_int_ccache_move( cc_ccache_t source, return ccErrNoMem; code = cci_msg_new(ccmsg_CCACHE_MOVE, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; 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)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -720,8 +804,14 @@ cc_int_ccache_move( cc_ccache_t source, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -730,9 +820,9 @@ cc_int_ccache_lock( cc_ccache_t ccache, cc_uint32 block ) { cc_int_ccache_t int_ccache; - cc_msg_t *request; - ccmsg_ccache_lock_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_lock_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -752,18 +842,21 @@ cc_int_ccache_lock( cc_ccache_t ccache, return ccErrNoMem; code = cci_msg_new(ccmsg_CCACHE_LOCK, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; 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)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -776,8 +869,14 @@ cc_int_ccache_lock( cc_ccache_t ccache, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -785,9 +884,9 @@ 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_msg_t *request = NULL; + ccmsg_ccache_unlock_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -804,17 +903,20 @@ cc_int_ccache_unlock( cc_ccache_t ccache ) return ccErrNoMem; code = cci_msg_new(ccmsg_CCACHE_UNLOCK, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; 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)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = htonl(response->type); if (type == ccmsg_NACK) { @@ -825,8 +927,14 @@ cc_int_ccache_unlock( cc_ccache_t ccache ) } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -836,9 +944,9 @@ cc_int_ccache_get_last_default_time( cc_ccache_t ccache, cc_time* time_offset ) { cc_int_ccache_t int_ccache; - cc_msg_t *request; - ccmsg_ccache_get_last_default_time_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_get_last_default_time_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_time64 t64; cc_int32 code; @@ -858,14 +966,17 @@ cc_int_ccache_get_last_default_time( cc_ccache_t ccache, request_header->ccache = htonll(int_ccache->handle); code = cci_msg_new(ccmsg_CCACHE_GET_LAST_DEFAULT_TIME, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_get_last_default_time_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -880,8 +991,14 @@ cc_int_ccache_get_last_default_time( cc_ccache_t ccache, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -889,9 +1006,9 @@ cc_int32 cc_int_ccache_get_change_time( cc_ccache_t ccache, cc_time* time ) { cc_int_ccache_t int_ccache; - cc_msg_t *request; - ccmsg_ccache_get_change_time_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_get_change_time_t *request_header = NULL; + cc_msg_t *response = NULL; cc_time64 t64; cc_uint32 type; cc_int32 code; @@ -911,14 +1028,17 @@ cc_int_ccache_get_change_time( cc_ccache_t ccache, cc_time* time ) request_header->ccache = htonll(int_ccache->handle); code = cci_msg_new(ccmsg_CCACHE_GET_CHANGE_TIME, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_get_change_time_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -933,8 +1053,14 @@ cc_int_ccache_get_change_time( cc_ccache_t ccache, cc_time* time ) } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -945,9 +1071,9 @@ cc_int_ccache_compare( cc_ccache_t ccache, { 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_msg_t *request = NULL; + ccmsg_ccache_compare_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -969,14 +1095,17 @@ cc_int_ccache_compare( cc_ccache_t ccache, request_header->ccache2 = htonll(int_compare_to->handle); code = cci_msg_new(ccmsg_CCACHE_COMPARE, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_compare_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -989,8 +1118,14 @@ cc_int_ccache_compare( cc_ccache_t ccache, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -1000,9 +1135,9 @@ cc_int_ccache_get_kdc_time_offset( cc_ccache_t ccache, cc_time* time_offset ) { cc_int_ccache_t int_ccache; - cc_msg_t *request; - ccmsg_ccache_get_kdc_time_offset_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_get_kdc_time_offset_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -1022,14 +1157,17 @@ cc_int_ccache_get_kdc_time_offset( cc_ccache_t ccache, request_header->creds_version = htonl(credentials_version); code = cci_msg_new(ccmsg_CCACHE_GET_KDC_TIME_OFFSET, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_get_kdc_time_offset_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -1042,8 +1180,14 @@ cc_int_ccache_get_kdc_time_offset( cc_ccache_t ccache, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -1053,9 +1197,9 @@ cc_int_ccache_set_kdc_time_offset( cc_ccache_t ccache, cc_time time_offset ) { cc_int_ccache_t int_ccache; - cc_msg_t *request; - ccmsg_ccache_set_kdc_time_offset_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_set_kdc_time_offset_t *request_header = NULL; + cc_msg_t *response = NULL; cc_int64 t64; cc_uint32 type; cc_int32 code; @@ -1078,14 +1222,17 @@ cc_int_ccache_set_kdc_time_offset( cc_ccache_t ccache, request_header->offset = htonll(t64); code = cci_msg_new(ccmsg_CCACHE_SET_KDC_TIME_OFFSET, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_set_kdc_time_offset_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -1096,8 +1243,14 @@ cc_int_ccache_set_kdc_time_offset( cc_ccache_t ccache, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -1106,9 +1259,9 @@ 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; - ccmsg_ccache_clear_kdc_time_offset_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_clear_kdc_time_offset_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -1128,14 +1281,17 @@ cc_int_ccache_clear_kdc_time_offset( cc_ccache_t ccache, request_header->creds_version = htonl(credentials_version); code = cci_msg_new(ccmsg_CCACHE_CLEAR_KDC_TIME_OFFSET, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_clear_kdc_time_offset_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -1146,7 +1302,13 @@ cc_int_ccache_clear_kdc_time_offset( cc_ccache_t ccache, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } diff --git a/src/lib/ccapi/client/ccache_iterator.c b/src/lib/ccapi/client/ccache_iterator.c index b0ccbe610..3da9b3547 100644 --- a/src/lib/ccapi/client/ccache_iterator.c +++ b/src/lib/ccapi/client/ccache_iterator.c @@ -58,7 +58,7 @@ cc_int_ccache_iterator_new( cc_ccache_iterator_t * piter, cc_handle ctx, cc_handle handle ) { - cc_int_ccache_iterator_t iter; + cc_int_ccache_iterator_t iter = NULL; if ( piter == NULL ) return ccErrBadParam; @@ -68,7 +68,7 @@ cc_int_ccache_iterator_new( cc_ccache_iterator_t * piter, return ccErrNoMem; iter->functions = (cc_ccache_iterator_f*)malloc( sizeof(cc_ccache_iterator_f)); - if ( iter->functions ) { + if ( iter->functions == NULL ) { free(iter); return ccErrNoMem; } @@ -87,9 +87,9 @@ cc_int32 cc_int_ccache_iterator_release( cc_ccache_iterator_t iter ) { cc_int_ccache_iterator_t int_iter; - cc_msg_t *request; - ccmsg_ccache_iterator_release_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_iterator_release_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -108,14 +108,17 @@ cc_int_ccache_iterator_release( cc_ccache_iterator_t iter ) 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); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_iterator_release_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -126,11 +129,19 @@ cc_int_ccache_iterator_release( cc_ccache_iterator_t iter ) } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); - free(int_iter->functions); - free(int_iter); + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); + + if (int_iter->functions) + free(int_iter->functions); + if (iter) + free(int_iter); return ccNoError; } @@ -139,9 +150,9 @@ 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; - ccmsg_ccache_iterator_next_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_iterator_next_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -160,14 +171,17 @@ cc_int_ccache_iterator_next( cc_ccache_iterator_t iter, request_header->iterator = htonll(int_iter->handle); code = cci_msg_new(ccmsg_CCACHE_ITERATOR_NEXT, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_iterator_next_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -179,8 +193,14 @@ cc_int_ccache_iterator_next( cc_ccache_iterator_t iter, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -189,9 +209,9 @@ 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_msg_t *request = NULL; + ccmsg_ccache_iterator_clone_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -210,14 +230,17 @@ cc_int_ccache_iterator_clone( cc_ccache_iterator_t iter, request_header->iterator = htonll(int_iter->handle); code = cci_msg_new(ccmsg_CCACHE_ITERATOR_CLONE, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_iterator_clone_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -229,7 +252,13 @@ cc_int_ccache_iterator_clone( cc_ccache_iterator_t iter, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } diff --git a/src/lib/ccapi/client/context.c b/src/lib/ccapi/client/context.c index 8515f695b..8a79fcede 100644 --- a/src/lib/ccapi/client/context.c +++ b/src/lib/ccapi/client/context.c @@ -97,9 +97,9 @@ cc_int32 cc_int_context_release( cc_context_t context ) { cc_int_context_t int_context; - cc_msg_t *request; - ccmsg_ctx_release_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ctx_release_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -117,14 +117,17 @@ cc_int_context_release( cc_context_t context ) request_header->ctx = htonll(int_context->handle); code = cci_msg_new(ccmsg_CTX_RELEASE, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_release_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -135,8 +138,14 @@ cc_int_context_release( cc_context_t context ) } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + request_header = NULL; + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); free(int_context->functions); free(int_context); return code; @@ -147,9 +156,9 @@ cc_int_context_get_change_time( cc_context_t context, cc_time* time) { 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 *request = NULL; + ccmsg_ctx_get_change_time_t *request_header = NULL; + cc_msg_t *response = NULL; ccmsg_ctx_get_change_time_resp_t *response_header; cc_time64 t64; cc_uint32 type; @@ -169,14 +178,17 @@ cc_int_context_get_change_time( cc_context_t context, request_header->ctx = htonll(int_context->handle); code = cci_msg_new(ccmsg_CTX_GET_CHANGE_TIME, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_get_change_time_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -191,8 +203,14 @@ cc_int_context_get_change_time( cc_context_t context, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -201,10 +219,11 @@ 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; - ccmsg_ctx_get_default_ccache_name_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ctx_get_default_ccache_name_t *request_header = NULL; + cc_msg_t *response = NULL; ccmsg_ctx_get_default_ccache_name_resp_t *response_header; + char *string = NULL; cc_uint32 type; cc_int32 code; @@ -222,33 +241,41 @@ cc_int_context_get_default_ccache_name( cc_context_t context, request_header->ctx = htonll(int_context->handle); code = cci_msg_new(ccmsg_CTX_GET_DEFAULT_CCACHE_NAME, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_get_default_ccache_name_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; 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) { - char * string; response_header = (ccmsg_ctx_get_default_ccache_name_resp_t*)response->header; code = cci_msg_retrieve_blob(response, response_header->name_offset, response_header->name_len, &string); - if (code == ccNoError) { + if (code == ccNoError) code = cci_string_new(name, string); - free(string); - } } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (string) + free(string); + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -258,9 +285,9 @@ cc_int_context_compare( cc_context_t context, cc_uint32* equal ) { cc_int_context_t int_context, int_compare_to; - cc_msg_t *request; - ccmsg_ctx_compare_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ctx_compare_t *request_header = NULL; + cc_msg_t *response = NULL; ccmsg_ctx_compare_resp_t *response_header; cc_uint32 type; cc_int32 code; @@ -283,14 +310,17 @@ cc_int_context_compare( cc_context_t context, request_header->ctx2 = htonll(int_compare_to->handle); code = cci_msg_new(ccmsg_CTX_COMPARE, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_compare_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -303,8 +333,14 @@ cc_int_context_compare( cc_context_t context, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -314,9 +350,9 @@ 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; - ccmsg_ctx_new_ccache_iterator_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ctx_new_ccache_iterator_t *request_header = NULL; + cc_msg_t *response = NULL; ccmsg_ctx_new_ccache_iterator_resp_t *response_header; cc_uint32 type; cc_int32 code; @@ -335,14 +371,17 @@ cc_int_context_new_ccache_iterator( cc_context_t context, request_header->ctx = htonll(int_context->handle); code = cci_msg_new(ccmsg_CTX_NEW_CCACHE_ITERATOR, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_new_ccache_iterator_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -355,8 +394,14 @@ cc_int_context_new_ccache_iterator( cc_context_t context, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -367,9 +412,9 @@ cc_int_context_open_ccache( cc_context_t context, { 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 *request = NULL; + ccmsg_ccache_open_t *request_header = NULL; + cc_msg_t *response = NULL; ccmsg_ccache_open_resp_t *response_header; cc_uint32 type; cc_int32 code; @@ -387,25 +432,25 @@ cc_int_context_open_ccache( cc_context_t context, return ccErrNoMem; code = cci_msg_new(ccmsg_CTX_CCACHE_OPEN, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_data_blob(request, (void *)name, strlen(name) + 1, &blob_pos); - if (code != ccNoError) { - cci_msg_destroy(request); - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; 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)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -417,8 +462,14 @@ cc_int_context_open_ccache( cc_context_t context, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -427,9 +478,9 @@ cc_int_context_open_default_ccache( cc_context_t context, cc_ccache_t* ccache) { cc_int_context_t int_context; - cc_msg_t *request; - ccmsg_ccache_open_default_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ccache_open_default_t *request_header = NULL; + cc_msg_t *response = NULL; ccmsg_ccache_open_resp_t *response_header; cc_uint32 type; cc_int32 code; @@ -447,16 +498,19 @@ cc_int_context_open_default_ccache( cc_context_t context, return ccErrNoMem; code = cci_msg_new(ccmsg_CTX_CCACHE_OPEN_DEFAULT, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; request_header->ctx = htonll(int_context->handle); code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ccache_open_default_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -468,8 +522,14 @@ cc_int_context_open_default_ccache( cc_context_t context, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -482,9 +542,9 @@ cc_int_context_create_ccache( cc_context_t context, { 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 *request = NULL; + ccmsg_ccache_create_t *request_header = NULL; + cc_msg_t *response = NULL; ccmsg_ccache_create_resp_t *response_header; cc_uint32 type; cc_int32 code; @@ -504,17 +564,12 @@ cc_int_context_create_ccache( cc_context_t context, return ccErrNoMem; code = cci_msg_new(ccmsg_CTX_CCACHE_CREATE, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_data_blob(request, (void *)name, strlen(name) + 1, &blob_pos); - if (code != ccNoError) { - cci_msg_destroy(request); - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; request_header->ctx = htonll(int_context->handle); request_header->version = htonl(cred_vers); @@ -522,17 +577,20 @@ cc_int_context_create_ccache( cc_context_t context, 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) { - cci_msg_destroy(request); - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; + 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)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -544,8 +602,14 @@ cc_int_context_create_ccache( cc_context_t context, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -557,9 +621,9 @@ cc_int_context_create_default_ccache( cc_context_t context, { 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 *request = NULL; + ccmsg_ccache_create_default_t *request_header = NULL; + cc_msg_t *response = NULL; ccmsg_ccache_create_resp_t *response_header; cc_uint32 type; cc_int32 code; @@ -579,26 +643,27 @@ cc_int_context_create_default_ccache( cc_context_t context, return ccErrNoMem; code = cci_msg_new(ccmsg_CTX_CCACHE_CREATE_DEFAULT, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; 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) { - cci_msg_destroy(request); - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; + 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)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -610,8 +675,14 @@ cc_int_context_create_default_ccache( cc_context_t context, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -623,9 +694,9 @@ cc_int_context_create_new_ccache( cc_context_t context, { 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 *request = NULL; + ccmsg_ccache_create_unique_t *request_header = NULL; + cc_msg_t *response = NULL; ccmsg_ccache_create_resp_t *response_header; cc_uint32 type; cc_int32 code; @@ -645,26 +716,27 @@ cc_int_context_create_new_ccache( cc_context_t context, return ccErrNoMem; code = cci_msg_new(ccmsg_CTX_CCACHE_CREATE_UNIQUE, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; 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) { - cci_msg_destroy(request); - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; + 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)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = htonl(response->type); if (type == ccmsg_NACK) { @@ -676,8 +748,14 @@ cc_int_context_create_new_ccache( cc_context_t context, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -687,9 +765,9 @@ cc_int_context_lock( cc_context_t context, cc_uint32 block ) { cc_int_context_t int_context; - cc_msg_t *request; - ccmsg_ctx_lock_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ctx_lock_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -709,17 +787,20 @@ cc_int_context_lock( cc_context_t context, return ccErrNoMem; code = cci_msg_new(ccmsg_CTX_LOCK, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; 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)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -732,8 +813,14 @@ cc_int_context_lock( cc_context_t context, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -741,9 +828,9 @@ cc_int32 cc_int_context_unlock( cc_context_t context ) { cc_int_context_t int_context; - cc_msg_t *request; - ccmsg_ctx_unlock_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ctx_unlock_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -760,16 +847,19 @@ cc_int_context_unlock( cc_context_t context ) return ccErrNoMem; code = cci_msg_new(ccmsg_CTX_UNLOCK, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; request_header->ctx = htonll(int_context->handle); code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_unlock_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -780,8 +870,14 @@ cc_int_context_unlock( cc_context_t context ) } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -794,10 +890,11 @@ cc_int_context_clone( cc_context_t inContext, { cc_int_context_t int_context; static char vendor_st[128] = ""; - cc_msg_t *request; - ccmsg_ctx_clone_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_ctx_clone_t *request_header = NULL; + cc_msg_t *response = NULL; ccmsg_ctx_clone_resp_t *response_header; + char *string = NULL; cc_uint32 type; cc_int32 code; @@ -831,14 +928,17 @@ cc_int_context_clone( cc_context_t inContext, request_header->in_version = htonl(requestedVersion); code = cci_msg_new(ccmsg_INIT, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_ctx_clone_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -850,11 +950,9 @@ cc_int_context_clone( cc_context_t inContext, code = cc_int_context_new(outContext, ntohll(response_header->out_ctx), ntohl(response_header->out_version)); if (!vendor_st[0]) { - char * 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); } *vendor = vendor_st; @@ -862,8 +960,16 @@ cc_int_context_clone( cc_context_t inContext, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (string) + free(string); + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } diff --git a/src/lib/ccapi/client/credentials_iterator.c b/src/lib/ccapi/client/credentials_iterator.c index f61d0ade8..3cdab875a 100644 --- a/src/lib/ccapi/client/credentials_iterator.c +++ b/src/lib/ccapi/client/credentials_iterator.c @@ -90,9 +90,9 @@ cc_int32 cc_int_credentials_iterator_release( cc_credentials_iterator_t iter ) { cc_int_credentials_iterator_t int_iter; - cc_msg_t *request; - ccmsg_creds_iterator_release_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_creds_iterator_release_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -112,14 +112,17 @@ cc_int_credentials_iterator_release( cc_credentials_iterator_t iter ) request_header->iterator = htonll(int_iter->handle); code = cci_msg_new(ccmsg_CREDS_ITERATOR_RELEASE, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_creds_iterator_release_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = htonl(response->type); if (type == ccmsg_NACK) { @@ -130,8 +133,14 @@ cc_int_credentials_iterator_release( cc_credentials_iterator_t iter ) } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); free(int_iter->functions); free(int_iter); @@ -143,9 +152,9 @@ 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; - ccmsg_creds_iterator_next_t *request_header; - cc_msg_t *response; + cc_msg_t *request = NULL; + ccmsg_creds_iterator_next_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -165,14 +174,17 @@ cc_int_credentials_iterator_next( cc_credentials_iterator_t iter, request_header->iterator = htonll(int_iter->handle); code = cci_msg_new(ccmsg_CREDS_ITERATOR_NEXT, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_creds_iterator_next_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -189,8 +201,14 @@ cc_int_credentials_iterator_next( cc_credentials_iterator_t iter, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } @@ -199,9 +217,9 @@ 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_msg_t *request = NULL; + ccmsg_creds_iterator_clone_t *request_header = NULL; + cc_msg_t *response = NULL; cc_uint32 type; cc_int32 code; @@ -220,14 +238,17 @@ cc_int_credentials_iterator_clone( cc_credentials_iterator_t iter, request_header->iterator = htonll(int_iter->handle); code = cci_msg_new(ccmsg_CREDS_ITERATOR_CLONE, &request); - if (code != ccNoError) { - free(request_header); - return code; - } + if (code != ccNoError) + goto cleanup; code = cci_msg_add_header(request, request_header, sizeof(ccmsg_creds_iterator_clone_t)); + if (code != ccNoError) + goto cleanup; + request_header = NULL; code = cci_perform_rpc(request, &response); + if (code != ccNoError) + goto cleanup; type = ntohl(response->type); if (type == ccmsg_NACK) { @@ -239,8 +260,14 @@ cc_int_credentials_iterator_clone( cc_credentials_iterator_t iter, } else { code = ccErrBadInternalMessage; } - cci_msg_destroy(request); - cci_msg_destroy(response); + + cleanup: + if (request_header) + free(request_header); + if (request) + cci_msg_destroy(request); + if (response) + cci_msg_destroy(response); return code; } diff --git a/src/lib/ccapi/common/msg.c b/src/lib/ccapi/common/msg.c index b7f60dd07..ed053ada5 100644 --- a/src/lib/ccapi/common/msg.c +++ b/src/lib/ccapi/common/msg.c @@ -289,7 +289,7 @@ cci_msg_flatten(cc_msg_t* msg, void **flatpp) cc_uint32 u32;
cc_int32 code;
- if (msg == NULL || flatpp == NULL)
+ if (msg == NULL)
return ccErrBadParam;
code = cci_msg_calc_size(msg,&msg->flat_len);
@@ -305,18 +305,15 @@ cci_msg_flatten(cc_msg_t* msg, void **flatpp) cur_pos = msg->flat;
- u32 = msg->header_len;
- htonl(u32);
+ u32 = htonl(msg->header_len);
memcpy(cur_pos,&u32,sizeof(cc_uint32));
cur_pos+=sizeof(cc_uint32);
- u32 = msg->flat_len;
- htonl(u32);
+ u32 = htonl(msg->flat_len);
memcpy(cur_pos,&u32,sizeof(cc_uint32));
cur_pos+=sizeof(cc_uint32);
- u32 = msg->type;
- htonl(u32);
+ u32 = htonl(msg->type);
memcpy(cur_pos,&u32,sizeof(cc_uint32));
cur_pos+=sizeof(cc_uint32);
@@ -324,8 +321,7 @@ cci_msg_flatten(cc_msg_t* msg, void **flatpp) memcpy(cur_pos, msg->header, msg->header_len);
cur_pos += msg->header_len;
- u32 = zero;
- htonl(zero);
+ u32 = htonl(zero);
memcpy(cur_pos, &u32, sizeof(cc_uint32)); /*will be magic number later*/
cur_pos += sizeof(cc_uint32);
@@ -342,9 +338,8 @@ cci_msg_flatten(cc_msg_t* msg, void **flatpp) free(msg->flat);
return code;
}
- u32 = gen_node->len;
- htonl(u32);
- memcpy(cur_pos, &u32, sizeof(cc_uint32));
+ u32 = htonl(gen_node->len);
+ memcpy(cur_pos, &u32, sizeof(cc_uint32));
cur_pos+=sizeof(cc_uint32);
/* data already in network order */
@@ -353,8 +348,7 @@ cci_msg_flatten(cc_msg_t* msg, void **flatpp) }
free(gen_iterator);
- u32 = zero;
- htonl(zero);
+ u32 = htonl(zero);
memcpy(cur_pos, &u32, sizeof(cc_uint32)); /*magic number will go here later*/
cur_pos += sizeof(cc_uint32);
@@ -620,7 +614,7 @@ cci_msg_destroy(cc_msg_t* msg) if (msg->flat != NULL)
free(msg->flat);
if (msg->header != NULL)
- free(msg->flat);
+ free(msg->header);
cci_generic_list_destroy(msg->data_blobs);
free(msg);
return ccNoError;
diff --git a/src/lib/ccapi/unit-test/NTMakefile b/src/lib/ccapi/unit-test/NTMakefile index 9bb486b6d..73f53f2e4 100644 --- a/src/lib/ccapi/unit-test/NTMakefile +++ b/src/lib/ccapi/unit-test/NTMakefile @@ -14,7 +14,9 @@ T_MSG = t_msg.exe T_SERVER = t_server.exe
-all: $(T_CCACHE) $(T_CONTEXT) $(T_LISTS) $(T_MSG) $(T_SERVER)
+T_CCAPI = t_ccapi.exe
+
+all: $(T_CCAPI) $(T_CCACHE) $(T_CONTEXT) $(T_LISTS) $(T_MSG) $(T_SERVER)
ntccrpc_c.c ntccrpc_s.c ntccrpc.h: ntccrpc.idl ntccrpc.acf
midl ntccrpc.idl /acf ntccrpc.acf
@@ -42,6 +44,9 @@ $(T_MSG): t_msg.obj $(CC_SERVER_LIB) $(CC_COMMON_LIB) $(T_SERVER): t_server.obj $(CC_SERVER_LIB) $(CC_COMMON_LIB)
$(link) /NOLOGO $(conlibsmt) $(ldebug) $(conlflags) /OUT:$@ $** $(WINLIBS)
+$(T_CCAPI): t_ccapi.obj $(CC_API_LIB)
+ $(link) /NOLOGO $(conlibsmt) $(ldebug) $(conlflags) /OUT:$@ $** $(WINLIBS)
+
clean:
del *.exe *.dll *.lib *.exp *.obj ntccrpc_c.c ntccrpc_s.c ntccrpc.h
diff --git a/src/lib/ccapi/windows/client.c b/src/lib/ccapi/windows/client.c index db0b63aec..e30801dab 100644 --- a/src/lib/ccapi/windows/client.c +++ b/src/lib/ccapi/windows/client.c @@ -78,11 +78,13 @@ int cc_rpc_cleanup(void) { }
cc_int32 cci_set_thread_session_id(unsigned char * client_name, LUID luid) {
-
+ return 0;
}
void cci_get_thread_session_id(unsigned char * client_name, int len, LUID *pluid) {
-
+ client_name[0] = '\0';
+ pluid->HighPart = 0;
+ pluid->LowPart = 0;
}
@@ -97,14 +99,14 @@ void cci_get_thread_session_id(unsigned char * client_name, int len, LUID *pluid cc_int32 cci_perform_rpc(cc_msg_t *request, cc_msg_t **response)
{
- __int32 rpc_code;
+ cc_int32 code;
unsigned char client_name[256];
LUID luid;
struct __LUID __luid;
unsigned char out_buf[MAXMSGLEN];
__int32 out_len = MAXMSGLEN;
- if (!cc_rpc_init())
+ if (cc_rpc_init())
return -1;
cci_get_thread_session_id(client_name, sizeof(client_name), &luid);
@@ -112,9 +114,28 @@ cc_int32 cci_perform_rpc(cc_msg_t *request, cc_msg_t **response) __luid.HighPart = luid.HighPart;
__luid.LowPart = luid.LowPart;
- rpc_code = ccapi_Message(hRpcBinding, client_name, __luid,
+ /* flatten response */
+ code = cci_msg_flatten(request, NULL);
+ if (code)
+ goto cleanup;
+
+ RpcTryExcept {
+ code = ccapi_Message(hRpcBinding, client_name, __luid,
request->flat, request->flat_len,
out_buf, &out_len);
+ }
+ RpcExcept(1) {
+ code = RpcExceptionCode();
+ }
+ RpcEndExcept;
+ if (code)
+ goto cleanup;
+
+ /* unflatten message */
+ code = cci_msg_unflatten(out_buf, out_len, response);
+ if (code)
+ goto cleanup;
- return rpc_code;
+ cleanup:
+ return code;
}
diff --git a/src/lib/ccapi/windows/server.c b/src/lib/ccapi/windows/server.c index 5ce8e6ebe..34d329902 100644 --- a/src/lib/ccapi/windows/server.c +++ b/src/lib/ccapi/windows/server.c @@ -1,5 +1,4 @@ -
#include <windows.h>
#include "msg.h"
#include "marshall.h"
@@ -15,6 +14,9 @@ #define SVCNAME "MIT_CCAPI_NT_Service"
+HANDLE hMainThread = 0;
+HANDLE WaitToTerminate = 0;
+
SERVICE_STATUS_HANDLE h_service_status = NULL;
SERVICE_STATUS service_status;
FILE * logfile = NULL;
@@ -72,7 +74,8 @@ void service_start(DWORD argc, LPTSTR * argv) { NULL);
if (status != RPC_S_OK) {
- return;
+ if (logfile) fprintf(logfile, "service_start RpcServerUseProtseq = 0x%x\n", status);
+ goto cleanup;
}
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);
@@ -80,21 +83,27 @@ void service_start(DWORD argc, LPTSTR * argv) { status = RpcServerRegisterIf(portable_ccapi_v1_0_s_ifspec,
0, 0);
- if (status != RPC_S_OK)
- return;
+ if (status != RPC_S_OK) {
+ if (logfile) fprintf(logfile, "service_start RpcServerRegisterIf = 0x%x\n", status);
+ goto cleanup;
+ }
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);
status = RpcServerInqBindings(&bv);
- if (status != RPC_S_OK)
- return;
+ if (status != RPC_S_OK) {
+ if (logfile) fprintf(logfile, "service_start RpcServerInqBindings = 0x%x\n", status);
+ goto cleanup;
+ }
status = RpcEpRegister(portable_ccapi_v1_0_s_ifspec,
bv, 0, 0);
- if (status != RPC_S_OK)
- return;
+ if (status != RPC_S_OK) {
+ if (logfile) fprintf(logfile, "service_start RpcEpRegister = 0x%x\n", status);
+ goto cleanup;
+ }
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);
@@ -102,32 +111,37 @@ void service_start(DWORD argc, LPTSTR * argv) { RPC_C_AUTHN_WINNT,
0, 0);
- if (status != RPC_S_OK)
- return;
+ if (status != RPC_S_OK) {
+ if (logfile) fprintf(logfile, "service_start RpcServerRegisterAuthInfo = 0x%x\n", status);
+ goto cleanup;
+ }
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);
- status = RpcServerListen(1,
+ status = RpcServerListen(2,
RPC_C_LISTEN_MAX_CALLS_DEFAULT,
TRUE);
- if (status != RPC_S_OK)
- return;
+ if (status != RPC_S_OK) {
+ if (logfile) fprintf(logfile, "service_start RpcServerListen = 0x%x\n", status);
+ goto cleanup;
+ }
report_status(SERVICE_RUNNING, NO_ERROR, 0);
- begin_log();
+ if (logfile) fprintf(logfile, "service_start calling RpcMgmtWaitServerListen\n");
status = RpcMgmtWaitServerListen();
+ if (logfile) fprintf(logfile, "service_start RpcMgmtWaitServerListen = 0x%x\n", status);
- end_log();
-
+ cleanup:
RpcEpUnregister(portable_ccapi_v1_0_s_ifspec, bv, 0);
RpcBindingVectorFree(&bv);
}
void service_stop(void) {
+ if (logfile) fprintf(logfile, "service_stop\n");
RpcMgmtStopServerListening(0);
}
@@ -292,6 +306,8 @@ __int32 ccapi_Message( cc_session_info_t * session_info;
cc_int32 code;
+ if (logfile) fprintf(logfile, "ccapi_Message\n");
+
if ( ccs_serv_initialize() != ccNoError ) {
code = ccErrServerUnavailable;
goto done;
@@ -390,6 +406,8 @@ void WINAPI service_control(DWORD ctrl_code) { void WINAPI service_main(DWORD argc, LPTSTR * argv) {
+ begin_log();
+
h_service_status = RegisterServiceCtrlHandler( _T(SVCNAME), service_control);
if (!h_service_status)
@@ -412,6 +430,8 @@ void WINAPI service_main(DWORD argc, LPTSTR * argv) { if (h_service_status) {
report_status(SERVICE_STOPPED, NO_ERROR, 0);
}
+
+ end_log();
}
@@ -620,8 +640,16 @@ ParseStandardArgs(int argc, char* argv[]) return FALSE;
}
-int main(int argc, char ** argv) {
+DWORD __stdcall Main_thread(void* notUsed)
+{
+ char * argv[2] = {SVCNAME, NULL};
+ begin_log();
+ service_start(1, (LPTSTR*)argv);
+ end_log();
+ return(0);
+}
+int main(int argc, char ** argv) {
SERVICE_TABLE_ENTRY dispatch_table[] = {
{ _T(SVCNAME), (LPSERVICE_MAIN_FUNCTION) service_main },
{ NULL, NULL }
@@ -631,8 +659,21 @@ int main(int argc, char ** argv) { return 0;
if (!StartServiceCtrlDispatcher(dispatch_table)) {
- fprintf(stderr, "Can't start service control dispatcher\n");
+ LONG status = GetLastError();
+ if (status == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
+ {
+ DWORD tid;
+ hMainThread = CreateThread(NULL, 0, Main_thread, 0, 0, &tid);
+
+ printf("Hit <Enter> to terminate MIT CCAPI Server\n");
+ getchar();
+ service_stop();
+ }
}
+ if ( hMainThread ) {
+ WaitForSingleObject( hMainThread, INFINITE );
+ CloseHandle( hMainThread );
+ }
return 0;
}
|