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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
{
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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:
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) {
} 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;
}
{
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;
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) {
} 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;
}
{
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
{
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
cc_handle ctx,
cc_handle handle )
{
- cc_int_ccache_iterator_t iter;
+ cc_int_ccache_iterator_t iter = NULL;
if ( piter == NULL )
return ccErrBadParam;
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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
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;
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) {
} 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;
}
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;
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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
{
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;
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) {
} 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;
}
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;
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) {
} 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;
}
{
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;
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);
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) {
} 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;
}
{
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;
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) {
} 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;
}
{
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;
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) {
} 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;
}
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;
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) {
} 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;
}
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;
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) {
} 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;
}
{
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;
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) {
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;
} 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;
}
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;
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) {
} 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);
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;
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) {
} 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;
}
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;
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) {
} 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;
}
cc_uint32 u32;\r
cc_int32 code;\r
\r
- if (msg == NULL || flatpp == NULL)\r
+ if (msg == NULL)\r
return ccErrBadParam;\r
\r
code = cci_msg_calc_size(msg,&msg->flat_len);\r
\r
cur_pos = msg->flat;\r
\r
- u32 = msg->header_len;\r
- htonl(u32);\r
+ u32 = htonl(msg->header_len);\r
memcpy(cur_pos,&u32,sizeof(cc_uint32));\r
cur_pos+=sizeof(cc_uint32);\r
\r
- u32 = msg->flat_len;\r
- htonl(u32);\r
+ u32 = htonl(msg->flat_len);\r
memcpy(cur_pos,&u32,sizeof(cc_uint32));\r
cur_pos+=sizeof(cc_uint32);\r
\r
- u32 = msg->type;\r
- htonl(u32);\r
+ u32 = htonl(msg->type);\r
memcpy(cur_pos,&u32,sizeof(cc_uint32));\r
cur_pos+=sizeof(cc_uint32);\r
\r
memcpy(cur_pos, msg->header, msg->header_len);\r
cur_pos += msg->header_len;\r
\r
- u32 = zero;\r
- htonl(zero);\r
+ u32 = htonl(zero);\r
memcpy(cur_pos, &u32, sizeof(cc_uint32)); /*will be magic number later*/\r
cur_pos += sizeof(cc_uint32);\r
\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
+ u32 = htonl(gen_node->len);\r
+ memcpy(cur_pos, &u32, sizeof(cc_uint32));\r
cur_pos+=sizeof(cc_uint32);\r
\r
/* data already in network order */\r
}\r
free(gen_iterator);\r
\r
- u32 = zero;\r
- htonl(zero);\r
+ u32 = 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 (msg->flat != NULL) \r
free(msg->flat);\r
if (msg->header != NULL)\r
- free(msg->flat);\r
+ free(msg->header);\r
cci_generic_list_destroy(msg->data_blobs);\r
free(msg);\r
return ccNoError;\r
\r
T_SERVER = t_server.exe\r
\r
-all: $(T_CCACHE) $(T_CONTEXT) $(T_LISTS) $(T_MSG) $(T_SERVER)\r
+T_CCAPI = t_ccapi.exe\r
+\r
+all: $(T_CCAPI) $(T_CCACHE) $(T_CONTEXT) $(T_LISTS) $(T_MSG) $(T_SERVER)\r
\r
ntccrpc_c.c ntccrpc_s.c ntccrpc.h: ntccrpc.idl ntccrpc.acf\r
midl ntccrpc.idl /acf ntccrpc.acf\r
$(T_SERVER): t_server.obj $(CC_SERVER_LIB) $(CC_COMMON_LIB)\r
$(link) /NOLOGO $(conlibsmt) $(ldebug) $(conlflags) /OUT:$@ $** $(WINLIBS)\r
\r
+$(T_CCAPI): t_ccapi.obj $(CC_API_LIB)\r
+ $(link) /NOLOGO $(conlibsmt) $(ldebug) $(conlflags) /OUT:$@ $** $(WINLIBS)\r
+\r
clean:\r
del *.exe *.dll *.lib *.exp *.obj ntccrpc_c.c ntccrpc_s.c ntccrpc.h\r
\r
}\r
\r
cc_int32 cci_set_thread_session_id(unsigned char * client_name, LUID luid) {\r
-\r
+ return 0;\r
}\r
\r
void cci_get_thread_session_id(unsigned char * client_name, int len, LUID *pluid) {\r
-\r
+ client_name[0] = '\0';\r
+ pluid->HighPart = 0;\r
+ pluid->LowPart = 0;\r
}\r
\r
\r
\r
cc_int32 cci_perform_rpc(cc_msg_t *request, cc_msg_t **response)\r
{\r
- __int32 rpc_code;\r
+ cc_int32 code;\r
unsigned char client_name[256];\r
LUID luid;\r
struct __LUID __luid;\r
unsigned char out_buf[MAXMSGLEN];\r
__int32 out_len = MAXMSGLEN;\r
\r
- if (!cc_rpc_init())\r
+ if (cc_rpc_init())\r
return -1;\r
\r
cci_get_thread_session_id(client_name, sizeof(client_name), &luid);\r
__luid.HighPart = luid.HighPart;\r
__luid.LowPart = luid.LowPart;\r
\r
- rpc_code = ccapi_Message(hRpcBinding, client_name, __luid, \r
+ /* flatten response */\r
+ code = cci_msg_flatten(request, NULL);\r
+ if (code)\r
+ goto cleanup;\r
+\r
+ RpcTryExcept {\r
+ code = ccapi_Message(hRpcBinding, client_name, __luid, \r
request->flat, request->flat_len, \r
out_buf, &out_len);\r
+ } \r
+ RpcExcept(1) {\r
+ code = RpcExceptionCode();\r
+ }\r
+ RpcEndExcept;\r
+ if (code)\r
+ goto cleanup;\r
+\r
+ /* unflatten message */\r
+ code = cci_msg_unflatten(out_buf, out_len, response);\r
+ if (code)\r
+ goto cleanup;\r
\r
- return rpc_code;\r
+ cleanup:\r
+ return code;\r
}\r
\r
-\r
#include <windows.h>\r
#include "msg.h"\r
#include "marshall.h"\r
\r
#define SVCNAME "MIT_CCAPI_NT_Service"\r
\r
+HANDLE hMainThread = 0;\r
+HANDLE WaitToTerminate = 0;\r
+\r
SERVICE_STATUS_HANDLE h_service_status = NULL;\r
SERVICE_STATUS service_status;\r
FILE * logfile = NULL;\r
NULL);\r
\r
if (status != RPC_S_OK) {\r
- return;\r
+ if (logfile) fprintf(logfile, "service_start RpcServerUseProtseq = 0x%x\n", status);\r
+ goto cleanup;\r
}\r
\r
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);\r
status = RpcServerRegisterIf(portable_ccapi_v1_0_s_ifspec,\r
0, 0);\r
\r
- if (status != RPC_S_OK)\r
- return;\r
+ if (status != RPC_S_OK) {\r
+ if (logfile) fprintf(logfile, "service_start RpcServerRegisterIf = 0x%x\n", status);\r
+ goto cleanup;\r
+ }\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
+ if (status != RPC_S_OK) {\r
+ if (logfile) fprintf(logfile, "service_start RpcServerInqBindings = 0x%x\n", status);\r
+ goto cleanup;\r
+ }\r
\r
status = RpcEpRegister(portable_ccapi_v1_0_s_ifspec,\r
bv, 0, 0);\r
\r
- if (status != RPC_S_OK)\r
- return;\r
+ if (status != RPC_S_OK) {\r
+ if (logfile) fprintf(logfile, "service_start RpcEpRegister = 0x%x\n", status);\r
+ goto cleanup;\r
+ }\r
\r
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);\r
\r
RPC_C_AUTHN_WINNT,\r
0, 0);\r
\r
- if (status != RPC_S_OK)\r
- return;\r
+ if (status != RPC_S_OK) {\r
+ if (logfile) fprintf(logfile, "service_start RpcServerRegisterAuthInfo = 0x%x\n", status);\r
+ goto cleanup;\r
+ }\r
\r
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);\r
\r
- status = RpcServerListen(1,\r
+ status = RpcServerListen(2,\r
RPC_C_LISTEN_MAX_CALLS_DEFAULT,\r
TRUE);\r
\r
- if (status != RPC_S_OK)\r
- return;\r
+ if (status != RPC_S_OK) {\r
+ if (logfile) fprintf(logfile, "service_start RpcServerListen = 0x%x\n", status);\r
+ goto cleanup;\r
+ }\r
\r
report_status(SERVICE_RUNNING, NO_ERROR, 0);\r
\r
- begin_log();\r
\r
+ if (logfile) fprintf(logfile, "service_start calling RpcMgmtWaitServerListen\n");\r
status = RpcMgmtWaitServerListen();\r
+ if (logfile) fprintf(logfile, "service_start RpcMgmtWaitServerListen = 0x%x\n", status);\r
\r
- end_log();\r
-\r
+ cleanup:\r
RpcEpUnregister(portable_ccapi_v1_0_s_ifspec, bv, 0);\r
\r
RpcBindingVectorFree(&bv);\r
}\r
\r
void service_stop(void) {\r
+ if (logfile) fprintf(logfile, "service_stop\n");\r
RpcMgmtStopServerListening(0);\r
}\r
\r
cc_session_info_t * session_info;\r
cc_int32 code;\r
\r
+ if (logfile) fprintf(logfile, "ccapi_Message\n");\r
+\r
if ( ccs_serv_initialize() != ccNoError ) {\r
code = ccErrServerUnavailable;\r
goto done;\r
\r
void WINAPI service_main(DWORD argc, LPTSTR * argv) {\r
\r
+ begin_log();\r
+\r
h_service_status = RegisterServiceCtrlHandler( _T(SVCNAME), service_control);\r
\r
if (!h_service_status)\r
if (h_service_status) {\r
report_status(SERVICE_STOPPED, NO_ERROR, 0);\r
}\r
+\r
+ end_log();\r
}\r
\r
\r
return FALSE;\r
}\r
\r
-int main(int argc, char ** argv) {\r
+DWORD __stdcall Main_thread(void* notUsed)\r
+{\r
+ char * argv[2] = {SVCNAME, NULL};\r
+ begin_log();\r
+ service_start(1, (LPTSTR*)argv);\r
+ end_log();\r
+ return(0);\r
+}\r
\r
+int main(int argc, char ** argv) {\r
SERVICE_TABLE_ENTRY dispatch_table[] = {\r
{ _T(SVCNAME), (LPSERVICE_MAIN_FUNCTION) service_main },\r
{ NULL, NULL }\r
return 0;\r
\r
if (!StartServiceCtrlDispatcher(dispatch_table)) {\r
- fprintf(stderr, "Can't start service control dispatcher\n");\r
+ LONG status = GetLastError();\r
+ if (status == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)\r
+ {\r
+ DWORD tid;\r
+ hMainThread = CreateThread(NULL, 0, Main_thread, 0, 0, &tid);\r
+\r
+ printf("Hit <Enter> to terminate MIT CCAPI Server\n");\r
+ getchar();\r
+ service_stop();\r
+ }\r
}\r
\r
+ if ( hMainThread ) {\r
+ WaitForSingleObject( hMainThread, INFINITE );\r
+ CloseHandle( hMainThread );\r
+ }\r
return 0;\r
}\r