From faa68ad5ae7d1504b8be9e8a7bedb0b6e533d3cd Mon Sep 17 00:00:00 2001 From: Sam Hartman Date: Sat, 21 Oct 2006 20:20:30 +0000 Subject: Delete src/lib/ccapi. The ccapi shipped in 1.6 will not be based off this code and will live in src/ccapi. It will be copied onto the trunk and branch when ready, but this code is being removed before the branch cut. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@18731 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/ccapi/server/NTMakefile | 21 - src/lib/ccapi/server/ccs_ccache.c | 703 ---------- src/lib/ccapi/server/ccs_context.c | 325 ----- src/lib/ccapi/server/ccs_lists.c | 657 ---------- src/lib/ccapi/server/mac/CCacheServer.plist | 12 - src/lib/ccapi/server/mac/CCacheServerInfo.plist | 38 - src/lib/ccapi/server/mac/main.c | 33 - src/lib/ccapi/server/rpc_auth.c | 67 - src/lib/ccapi/server/serv_ops.c | 1586 ----------------------- 9 files changed, 3442 deletions(-) delete mode 100644 src/lib/ccapi/server/NTMakefile delete mode 100644 src/lib/ccapi/server/ccs_ccache.c delete mode 100644 src/lib/ccapi/server/ccs_context.c delete mode 100644 src/lib/ccapi/server/ccs_lists.c delete mode 100644 src/lib/ccapi/server/mac/CCacheServer.plist delete mode 100644 src/lib/ccapi/server/mac/CCacheServerInfo.plist delete mode 100644 src/lib/ccapi/server/mac/main.c delete mode 100644 src/lib/ccapi/server/rpc_auth.c delete mode 100644 src/lib/ccapi/server/serv_ops.c (limited to 'src/lib/ccapi/server') diff --git a/src/lib/ccapi/server/NTMakefile b/src/lib/ccapi/server/NTMakefile deleted file mode 100644 index 564097c534..0000000000 --- a/src/lib/ccapi/server/NTMakefile +++ /dev/null @@ -1,21 +0,0 @@ -# Makefile for the CCAPI Server Library - -!INCLUDE - -CFLAGS = -I../include $(cdebug) $(cflags) $(cvarsmt) - -CC_SERVER_OBJS = ccs_context.obj ccs_ccache.obj ccs_lists.obj rpc_auth.obj serv_ops.obj - -CC_SERVER_LIB = cc_server.lib - -CC_COMMON_LIB = ../common/cc_common.lib - -$(CC_SERVER_LIB): $(CC_SERVER_OBJS) - $(implib) /NOLOGO /OUT:$@ $** - -all: $(CC_SERVER_LIB) - -clean: - del *.obj *.lib - - \ No newline at end of file diff --git a/src/lib/ccapi/server/ccs_ccache.c b/src/lib/ccapi/server/ccs_ccache.c deleted file mode 100644 index d632ee3494..0000000000 --- a/src/lib/ccapi/server/ccs_ccache.c +++ /dev/null @@ -1,703 +0,0 @@ -/* $Copyright: - * - * Copyright 2004-2006 by the Massachusetts Institute of Technology. - * - * All rights reserved. - * - * Export of this software from the United States of America may require a - * specific license from the United States Government. It is the - * responsibility of any person or organization contemplating export to - * obtain such a license before exporting. - * - * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute - * this software and its documentation for any purpose and without fee is - * hereby granted, provided that the above copyright notice appear in all - * copies and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of M.I.T. not be - * used in advertising or publicity pertaining to distribution of the - * software without specific, written prior permission. Furthermore if you - * modify this software you must label your software as modified software - * and not distribute it in such a fashion that it might be confused with - * the original MIT software. M.I.T. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Individual source code files are copyright MIT, Cygnus Support, - * OpenVision, Oracle, Sun Soft, FundsXpress, and others. - * - * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira, - * and Zephyr are trademarks of the Massachusetts Institute of Technology - * (MIT). No commercial use of these trademarks may be made without prior - * written permission of MIT. - * - * "Commercial use" means use of a name in a product or other for-profit - * manner. It does NOT prevent a commercial firm from referring to the MIT - * trademarks in order to convey information (although in doing so, - * recognition of their trademark status should be given). - * $ - */ - -/* - * Manages ccache objects. - * - */ - -#include -#include -#include -#include -#include "CredentialsCache.h" -#include "datastore.h" - -/** - * ccache_new() - * - * Purpose: Allocate and initialize new credentials cache for the specified principal - * and version - * - * Return: ccNoError - success - * ccErrInvalidString - name or principal is NULL - * ccErrBadCredentialsVersion - unsupported creds type - * ccErrBadParam - outCcachepp is NULL - * ccErrNoMem - malloc failed - */ -cc_int32 -ccs_ccache_new( char *name, char *principal, int cred_vers, - cc_server_ccache_t** outCCachepp) -{ - cc_server_ccache_t* ccache; - - if (name == NULL || principal == NULL) - return ccErrInvalidString; - - if (cred_vers != cc_credentials_v4 && cred_vers != cc_credentials_v5 && - cred_vers != cc_credentials_v4_v5) - return ccErrBadCredentialsVersion; - - if (outCCachepp == NULL) - return ccErrBadParam; - - ccache = (cc_server_ccache_t*)malloc(sizeof(cc_server_ccache_t)); - if (ccache == NULL) - return ccErrNoMem; - - ccache->name = name; - ccache->principal_v4 = NULL; - ccache->principal_v5 = NULL; - ccache->changed = time(NULL); - ccache->kdc_offset = 0; - ccache->last_default = 0; - cci_generic_list_new(&ccache->active_iterators); - ccs_credentials_list_new(&ccache->creds); - ccache->is_default = 0; - ccache->kdc_set = 0; - ccache->versions = cred_vers; - ccache->mycontext = NULL; - - ccs_ccache_set_principal(ccache, cred_vers, principal); - *outCCachepp = ccache; - return ccNoError; -} - -/** - * ccs_ccache_check_version() - * - * Purpose: Check to see if the ccache and the creds have compatible versions. - * - * Return: ccNoError and compat = 1 if they are compatible - * ccNoError and compat = 0 if they are not compatible - * - * Errors: ccErrInvalidCCache - ccache is NULL - * ccErrBadParam - either creds or compat are NULL - */ -cc_int32 -ccs_ccache_check_version( const cc_server_ccache_t *ccache, - const cc_credentials_union* creds, - cc_uint32* compat) -{ - if (ccache == NULL) - return ccErrInvalidCCache; - - if (creds == NULL || compat == NULL) - return ccErrBadParam; - - if (ccache->versions == cc_credentials_v4_v5) - *compat = 1; - else if (ccache->versions == creds->version) - *compat = 1; - else - *compat = 0; - - return ccNoError; -} - -/** -ccs_ccache_check_principal() - -Check to see if the client principal from the credentials matches -the principal associated with the cache. - -* Return: ccNoError and compat = 1 if they are compatible -* ccNoError and compat = 0 if they are not compatible -* -* Errors: ccErrInvalidCCache - ccache is NULL -* ccErrBadParam - either creds or compat are NULL -* ccErrBadCredentialVersion - unsupported credential type -*/ -cc_int32 -ccs_ccache_check_principal( const cc_server_ccache_t *ccache, - const cc_credentials_union* creds, - cc_uint32* compat) -{ - if (ccache == NULL) - return ccErrInvalidCCache; - - if (creds == NULL || compat == NULL) - return ccErrBadParam; - - if (creds->version == cc_credentials_v4) { - if (strcmp(creds->credentials.credentials_v4->principal, ccache->principal_v4) == 0) - *compat = 1; - else - *compat = 0; - } else if (creds->version == cc_credentials_v5) { - if (strcmp(creds->credentials.credentials_v5->client, ccache->principal_v5) == 0) - *compat = 1; - else - *compat = 0; - } else { - return ccErrBadCredentialsVersion; - } - return ccNoError; -} - - -/** - * ccs_ccache_store_creds() - * - * Purpose: Stores the provided credentials into the provided cache. Validates the - * ability of the cache to store credentials of the given version and client - * principal. - * - * Return: 0 on success - * -1 on error - * - * Errors: ccErrNoMem - * ccErrBadCredentialsVersion - * ccErrBadInvalidCredentials - * ccErrInvalidCache - * ccErrBadParam - */ -cc_int32 -ccs_ccache_store_creds(cc_server_ccache_t *ccache, const cc_credentials_union* credentials) -{ - cc_server_credentials_t* stored_cred=NULL; - cc_uint32 valid_version, valid_principal; - cc_int32 code; - - if (ccache == NULL) - return ccErrInvalidCCache; - - if (credentials == NULL) - return ccErrBadParam; - - code = ccs_ccache_check_version(ccache, credentials, &valid_version); - if (code != ccNoError) { - /* pass error on to caller */ - goto bad; - } - code = ccs_ccache_check_principal(ccache, credentials, &valid_principal); - if (code != ccNoError) { - /* pass error on to caller */ - goto bad; - } - if (valid_version && valid_principal) { - stored_cred = (cc_server_credentials_t*)malloc(sizeof(cc_server_credentials_t)); - if (stored_cred == NULL) { - code = ccErrNoMem; - goto bad; - } - memcpy(&stored_cred->creds, credentials, sizeof(cc_credentials_union)); - - if (credentials->version == cc_credentials_v4) { - stored_cred->creds.credentials.credentials_v4 = (cc_credentials_v4_t*)malloc(sizeof(cc_credentials_v4_t)); - if (stored_cred->creds.credentials.credentials_v4 == NULL) { - code = ccErrNoMem; - goto bad; - } - - memcpy(stored_cred->creds.credentials.credentials_v4, credentials->credentials.credentials_v4, sizeof(cc_credentials_v4_t)); - } else if (credentials->version == cc_credentials_v5) { - stored_cred->creds.credentials.credentials_v5 = (cc_credentials_v5_t*)malloc(sizeof(cc_credentials_v5_t)); - if (stored_cred->creds.credentials.credentials_v5 == NULL) { - code = ccErrNoMem; - goto bad; - } - - memcpy(stored_cred->creds.credentials.credentials_v5, credentials->credentials.credentials_v5, sizeof(cc_credentials_v5_t)); - } else { - code = ccErrBadCredentialsVersion; - goto bad; - } - - code = ccs_credentials_list_append(ccache->creds, stored_cred, NULL); - if ( code != ccNoError ) { - /* pass error on to caller */ - goto bad; - } - if (ccache->creds->head->data == (cc_uint8 *)stored_cred) - stored_cred->is_default = 1; /*we're first on the list, so we're default*/ - - ccs_ccache_changed(ccache); - return ccNoError; - } else { -#ifdef DEBUG - printf("vers: %d\tprincipal: %d\n", - valid_version, valid_principal); -#endif /* DEBUG */ - code = ccErrInvalidCredentials; - goto bad; - } - - bad: - if (stored_cred) - free(stored_cred); - return code; /* error */ -} - -/** - * ccs_ccache_changed() - * - * Purpose: Updates the last update time for the ccache and its associated context. - * Provides a location from which interested parties should be notified - * of cache updates. - * - * Return: none - * - * Errors: none - */ -void -ccs_ccache_changed(cc_server_ccache_t* ccache) -{ - ccache->changed = time(NULL); - if (ccache->mycontext != NULL) - ccache->mycontext->changed = time(NULL); - - /* XXX - notify registered listeners when implemented */ -} - -/** - * ccs_ccache_rem_creds() - * - * Purpose: Removes the specified credential object from the specified cache if - * it exists - * - * Return: 0 on success (credential is not in the cache) - * -1 on error - * - * Errors: ccErrBadParam, ccErrNoMem (from cc_credentials_list_iterator) - * - * Verify: does the memory associated with stored_cred->creds need to be freed? - * - */ -cc_int32 -ccs_ccache_rem_creds(cc_server_ccache_t *ccache, const cc_credentials_union* credentials) -{ - cc_credentials_iterate_t* credentials_iterator=NULL, *active; - cc_generic_iterate_t* generic_iterator=NULL; - cc_credentials_list_node_t* credentials_node; - cc_generic_list_node_t* generic_node; - cc_server_credentials_t* stored_cred; - cc_int8 changed = 0; - cc_int32 code = 0; - - if (ccache == NULL) - return ccErrInvalidCCache; - - if (credentials == NULL) - return ccErrBadParam; - - code = ccs_credentials_list_iterator(ccache->creds, &credentials_iterator); - if (code != ccNoError) { - /* pass error to caller */ - goto cleanup; - } - - while (ccs_credentials_iterate_has_next(credentials_iterator)) { - code = ccs_credentials_iterate_next(credentials_iterator, &credentials_node); - stored_cred = (cc_server_credentials_t*)credentials_node->data; - if (memcmp(&stored_cred->creds,credentials,sizeof(cc_credentials_union)) == 0) { - /* XXX - do we need to free(stored_cred->creds) ? */ - free(credentials_node->data); - changed = 1; - - /*If any iterator's next points to the deleted node, make it point to the next node*/ - code = cci_generic_list_iterator(ccache->active_iterators, &generic_iterator); - while (cci_generic_iterate_has_next(generic_iterator)) { - code = cci_generic_iterate_next(generic_iterator, &generic_node); - active = (cc_credentials_iterate_t*)generic_node->data; - if (active->next == credentials_node) - active->next = active->next->next; - } - code = cci_generic_free_iterator(generic_iterator); - generic_iterator = NULL; - - if (credentials_node == ccache->creds->head) { /*removing the default, must make next cred default*/ - code = ccs_credentials_list_remove_element(ccache->creds, credentials_node); - - if (ccache->creds->head != NULL) - ((cc_server_credentials_t*)ccache->creds->head->data)->is_default = 1; - } else { - code = ccs_credentials_list_remove_element(ccache->creds, credentials_node); - } - break; - } - } - - cleanup: - if (changed) - ccs_ccache_changed(ccache); - if (credentials_iterator) - ccs_credentials_free_iterator(credentials_iterator); - if (generic_iterator) - cci_generic_free_iterator(generic_iterator); - return code; -} - -/** - * ccs_ccache_move() - * - * Purpose: Destroys the existing contents of the destination and copies - * all credentials from the source to the destination - * - * Return: 0 on success - * -1 on error - * - * Errors: ccBadNoMem - * - */ - -cc_int32 -ccs_ccache_move(cc_server_ccache_t *source, cc_server_ccache_t* destination) -{ - cc_generic_list_node_t* node; - cc_generic_iterate_t* iterator; - cc_credentials_iterate_t* cur; - cc_int32 code; - - if (source == NULL || destination == NULL) - return ccErrBadParam; - - code = ccs_credentials_list_destroy(destination->creds); - if ( code != ccNoError ) - return code; - - code = ccs_credentials_list_copy(source->creds, &destination->creds); - if ( code != ccNoError ) - return code; - - destination->versions = source->versions; - destination->kdc_offset = source->kdc_offset; - destination->last_default = 0; - - /*reset all active iterators to point to the head of the new creds list*/ - if (destination->active_iterators->head != NULL) { - code = cci_generic_list_iterator(destination->active_iterators, &iterator); - while (cci_generic_iterate_has_next(iterator)) { - code = cci_generic_iterate_next(iterator, &node); - cur = (cc_credentials_iterate_t*)node->data; - cur->next = destination->creds->head; - } - code = cci_generic_free_iterator(iterator); - } - - ccs_ccache_changed(destination); - return code; -} - -/** - * ccs_ccache_get_kdc_time_offset() - * - * Purpose: Retrieves the kdc_time_offset from the ccache if set - * - * Return: 0 on success - * -1 on error - * - * Errors: ccErrBadParam, ccErrTimeOffsetNotSet - * - */ -cc_int32 -ccs_ccache_get_kdc_time_offset(cc_server_ccache_t* ccache, cc_time64* offset) -{ - if (ccache == NULL) - return ccErrInvalidCCache; - - if (offset == NULL) - return ccErrBadParam; - - if (!ccache->kdc_set) - return ccErrTimeOffsetNotSet; - - *offset = ccache->kdc_offset; - return ccNoError; -} - -/** - * ccs_ccache_set_kdc_time_offset() - * - * Purpose: Sets the kdc time offset in the designated ccache - * - * Return: 0 on success - * -1 on error - * - * Errors: ccErrBadParam - * - */ -cc_int32 -ccs_ccache_set_kdc_time_offset(cc_server_ccache_t* ccache, cc_time64 offset) -{ - if (ccache == NULL) - return ccErrInvalidCCache; - - ccache->kdc_offset = offset; - ccache->kdc_set = 1; - ccs_ccache_changed(ccache); - - return ccNoError; -} - -/** - * ccs_ccache_clear_kdc_time_offset() - * - * Purpose: Clear the kdc time offset in the designated ccache - * - * Return: 0 on success - * -1 on error - * - * Errors: ccErrBadParam - */ -cc_int32 -ccs_ccache_clear_kdc_time_offset(cc_server_ccache_t* ccache) -{ - if (ccache == NULL) - return ccErrInvalidCCache; - - ccache->kdc_offset = 0; - ccache->kdc_set = 0; - ccs_ccache_changed(ccache); - - return ccNoError; -} - -/** - * ccs_ccache_new_iterator() - * - * Purpose: Retrieve an iterator for the designated cache - * - * Return: 0 on success - * -1 on error - * - * Errors: ccErrBadParam, ccBadNoMem - */ -cc_int32 -ccs_ccache_new_iterator(cc_server_ccache_t* ccache, cc_credentials_iterate_t** iterator) -{ - cc_int32 code; - - if (ccache == NULL) - return ccErrInvalidCCache; - - if (iterator == NULL) - return ccErrBadParam; - - code = ccs_credentials_list_iterator(ccache->creds, iterator); - if (code != ccNoError) - return code; - - code = cci_generic_list_prepend(ccache->active_iterators, *iterator, sizeof(cc_credentials_iterate_t), NULL); - if (code != ccNoError) - return code; - - return ccNoError; -} - -/** - * ccs_ccache_get_principal() - * - * Purpose: Retrieves the client principal associated with the designated cache. - * The value is returned - * Return: - * - * Errors: - */ -cc_int32 -ccs_ccache_get_principal(cc_server_ccache_t* ccache, cc_int32 version, char ** principal) -{ - char *p = NULL; - - switch ( version ) { - case cc_credentials_v4: - p = ccache->principal_v4; - break; - case cc_credentials_v5: - p = ccache->principal_v5; - break; - default: - return ccErrBadCredentialsVersion; - } - - *principal = (char *)malloc(strlen(p)+1); - if ( *principal == NULL ) - return ccErrNoMem; - - strcpy(*principal, p); - return ccNoError; -} - -/** - * Purpose: Releases the memory associated with a ccache principal - * - * Return: - * - * Errors: - * - */ -cc_int32 -ccs_ccache_free_principal(char * principal) -{ - if ( principal == NULL ) - return ccErrBadParam; - - free(principal); - return ccNoError; -} - -/** - * ccache_set_principal() - * - * Purpose: Assigns a principal to the designated ccache and credential version. - * If the api version is 2, the cache is cleared of all existing - * credentials. - * - * Return: 0 on success - * -1 on error - * - * Errors: ccErrNoMem, ccErrBadCredentialsVersion - */ -cc_int32 -ccs_ccache_set_principal( cc_server_ccache_t* ccache, cc_int32 cred_version, - char* principal) -{ - cc_generic_iterate_t* generic_iterator; - cc_generic_list_node_t* generic_node; - cc_ccache_iterate_t* ccache_iterator; - cc_int32 code = ccNoError; - - if (ccache == NULL) - return ccErrInvalidCCache; - - if (principal == NULL) - return ccErrInvalidString; - - switch (cred_version) { - case cc_credentials_v4: - case cc_credentials_v4_v5: - ccache->principal_v4 = (char *)malloc(strlen(principal) + 1); - if (ccache->principal_v4 == NULL) - return ccErrNoMem; - strcpy(ccache->principal_v4, principal); - if (cred_version != cc_credentials_v4_v5) - break; - /* fall-through if we are v4_v5 */ - case cc_credentials_v5: - ccache->principal_v5 = (char *)malloc(strlen(principal) + 1); - if (ccache->principal_v5 == NULL) { - if (cred_version == cc_credentials_v4_v5) { - free(ccache->principal_v4); - ccache->principal_v4 = NULL; - } - return ccErrNoMem; - } - strcpy(ccache->principal_v5, principal); - break; - default: - return ccErrBadCredentialsVersion; - } - - /*For API version 2 clients set_principal implies a flush of all creds*/ - if (ccache->mycontext != NULL && ccache->mycontext->api_version == ccapi_version_2) { - ccs_credentials_list_destroy(ccache->creds); - ccs_credentials_list_new(&ccache->creds); - - /*clean up active_iterators*/ - code = cci_generic_list_iterator(ccache->active_iterators, &generic_iterator); - if (code == ccNoError) { - while (cci_generic_iterate_has_next(generic_iterator)) { - code = cci_generic_iterate_next(generic_iterator, &generic_node); - ccache_iterator = (cc_ccache_iterate_t*)generic_node->data; - ccache_iterator->next = NULL; - } - } - } - - ccs_ccache_changed(ccache); - - return code; -} - -/** - * ccs_ccache_destroy() - * - * Purpose: Destroys an existing ccache - * - * Return: 0 on success - * -1 on errors - * - * Errors: ccErrBadParam - */ -cc_int32 -ccs_ccache_destroy(cc_server_ccache_t* ccache) -{ - cc_int32 code; - - if ( ccache == NULL ) - return ccErrInvalidCCache; - - code = cci_generic_list_destroy(ccache->active_iterators); - code = ccs_credentials_list_destroy(ccache->creds); - - if (ccache->mycontext != NULL) - code = ccs_context_rem_ccache(ccache->mycontext, ccache); - - return code; -} - -/** - * ccs_ccache_compare() - * - * Purpose: Returns a boolean value indicating if two caches are identical - * Implemented as pointer equivalence. - * - * Return: 1 if TRUE - * 0 if FALSE - * - * Errors: No errors - */ -cc_int32 -ccs_ccache_compare(cc_server_ccache_t* ccache1, cc_server_ccache_t* ccache2, cc_uint32 *result) -{ - if ( ccache1 == NULL || ccache2 == NULL ) - return ccErrInvalidCCache; - - if (ccache1 == ccache2) - *result = 1; - else - *result = 0; - - return ccNoError; -} - diff --git a/src/lib/ccapi/server/ccs_context.c b/src/lib/ccapi/server/ccs_context.c deleted file mode 100644 index a168147940..0000000000 --- a/src/lib/ccapi/server/ccs_context.c +++ /dev/null @@ -1,325 +0,0 @@ -/* $Copyright: - * - * Copyright 2004-2006 by the Massachusetts Institute of Technology. - * - * All rights reserved. - * - * Export of this software from the United States of America may require a - * specific license from the United States Government. It is the - * responsibility of any person or organization contemplating export to - * obtain such a license before exporting. - * - * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute - * this software and its documentation for any purpose and without fee is - * hereby granted, provided that the above copyright notice appear in all - * copies and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of M.I.T. not be - * used in advertising or publicity pertaining to distribution of the - * software without specific, written prior permission. Furthermore if you - * modify this software you must label your software as modified software - * and not distribute it in such a fashion that it might be confused with - * the original MIT software. M.I.T. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Individual source code files are copyright MIT, Cygnus Support, - * OpenVision, Oracle, Sun Soft, FundsXpress, and others. - * - * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira, - * and Zephyr are trademarks of the Massachusetts Institute of Technology - * (MIT). No commercial use of these trademarks may be made without prior - * written permission of MIT. - * - * "Commercial use" means use of a name in a product or other for-profit - * manner. It does NOT prevent a commercial firm from referring to the MIT - * trademarks in order to convey information (although in doing so, - * recognition of their trademark status should be given). - * $ - */ - -/* - * Functions to manipulate datastore layer contexts. - * - */ - -#include -#include -#include -#include - -#include "CredentialsCache.h" -#include "datastore.h" - -int cc_myversion = 5; -char cc_vendor[] = "MIT C lang CCache V5"; -char cc_default_ccache_name[] = "krb5cc"; - - -cc_int32 -ccs_context_new( int api_version, cc_auth_info_t* auth_info, - cc_session_info_t* session_info, cc_server_context_t** outContextpp ) -{ - cc_server_context_t* ctx; - - if ( outContextpp == NULL ) - return ccErrBadParam; - - ctx = (cc_server_context_t*)malloc(sizeof(cc_server_context_t)); - if (ctx == NULL) - return ccErrNoMem; - - ccs_ccache_list_new(&ctx->ccaches); - cci_generic_list_new(&ctx->active_iterators); - ctx->api_version = api_version; - ctx->auth_info = auth_info; - ctx->session_info = session_info; - ctx->changed = time(NULL); - - *outContextpp = ctx; - return ccNoError; -} - -cc_int32 -ccs_context_get_default_ccache_name(cc_server_context_t* ctx, char ** outNamepp) -{ - cc_server_ccache_t* default_ccache; - - if (outNamepp == NULL) - return ccErrBadParam; - - if (ctx == NULL) - return ccErrInvalidContext; - - if (ctx->ccaches->head != NULL) { - default_ccache = (cc_server_ccache_t*)ctx->ccaches->head->data; - *outNamepp = default_ccache->name; - } else { - *outNamepp = cc_default_ccache_name; - } - return ccNoError; -} - - -cc_int32 -ccs_context_find_ccache( cc_server_context_t* ctx, char *name, - cc_server_ccache_t** outCcachepp ) -{ - cc_ccache_iterate_t* ccache_iterator; - cc_ccache_list_node_t* ccache_node; - cc_server_ccache_t* ccache; - cc_int32 code; - - if (ctx == NULL) - return ccErrInvalidContext; - - if (name == NULL) - return ccErrInvalidString; - - if (outCcachepp == NULL) - return ccErrBadParam; - - code = ccs_ccache_list_iterator(ctx->ccaches, &ccache_iterator); - while (ccs_ccache_iterate_has_next(ccache_iterator)) { - code = ccs_ccache_iterate_next(ccache_iterator, &ccache_node); - ccache = (cc_server_ccache_t *)ccache_node->data; - if (strcmp(ccache->name, name) == 0) { - free(ccache_iterator); - *outCcachepp = ccache; - return ccNoError; - } - } - free(ccache_iterator); - return ccErrCCacheNotFound; -} - -cc_int32 -ccs_context_open_ccache( cc_server_context_t* ctx, char *name, - cc_server_ccache_t** outCcachepp ) -{ - return ccs_context_find_ccache(ctx, name, outCcachepp); -} - - -cc_int32 -ccs_context_create_ccache( cc_server_context_t* ctx, char *name, int creds_version, - char *principal, cc_server_ccache_t** outCcachepp ) -{ - cc_server_ccache_t* ccache; - cc_int32 code; - - if (ctx == NULL) - return ccErrInvalidContext; - - if (outCcachepp == NULL) - return ccErrBadParam; - - if (name == NULL || principal == NULL) - return ccErrInvalidString; - - if (creds_version != cc_credentials_v4 && creds_version != cc_credentials_v5 && - creds_version != cc_credentials_v4_v5) - return ccErrBadCredentialsVersion; - - code = ccs_context_find_ccache(ctx, name, &ccache); - if (code == ccNoError) { - code = ccs_ccache_set_principal(ccache, creds_version, principal); - } else { - code = ccs_ccache_new(name, principal, creds_version, &ccache); - if (code != ccNoError) - return code; /*let caller deal with error*/ - - ccache->mycontext = ctx; - ctx->changed = time(NULL); - ccs_ccache_list_append(ctx->ccaches, ccache, NULL); - - if (ctx->ccaches->head->data == (cc_uint8 *)ccache) { - ccache->is_default = 1; - } - } - *outCcachepp = ccache; - return ccNoError; -} - -cc_int32 -ccs_context_create_default_ccache( cc_server_context_t* ctx, int creds_version, - char *principal, cc_server_ccache_t** outCcachepp ) -{ - cc_server_ccache_t* ccache, *old_default; - cc_int32 code; - - if (ctx == NULL) - return ccErrInvalidContext; - - if (outCcachepp == NULL) - return ccErrBadParam; - - if (principal == NULL) - return ccErrInvalidString; - - if (creds_version != cc_credentials_v4 && creds_version != cc_credentials_v5 && - creds_version != cc_credentials_v4_v5) - return ccErrBadCredentialsVersion; - - code = ccs_context_find_ccache(ctx, cc_default_ccache_name, &ccache); - if (code == ccNoError) { - ccs_ccache_set_principal(ccache, creds_version, principal); - } else { - code = ccs_ccache_new(cc_default_ccache_name, principal, creds_version, &ccache); - if (code != ccNoError) - return code; /*let caller deal with error*/ - - ccache->mycontext = ctx; - ccache->is_default = 1; - ctx->changed = time(NULL); - - if (ctx->ccaches->head != NULL) { - old_default = (cc_server_ccache_t *)ctx->ccaches->head->data; - old_default->is_default = 0; - old_default->last_default = time(NULL); - } - - ccs_ccache_list_prepend(ctx->ccaches, ccache, NULL); - } - *outCcachepp = ccache; - return ccNoError; -} - -cc_int32 -ccs_context_ccache_iterator(cc_server_context_t* ctx, cc_ccache_iterate_t** iterpp) -{ - cc_ccache_iterate_t* ccache_iterator; - cc_int32 code; - - if (ctx == NULL) - return ccErrInvalidContext; - - if (iterpp == NULL) - return ccErrBadParam; - - code = ccs_ccache_list_iterator(ctx->ccaches, &ccache_iterator); - if (code != ccNoError) - return code; - cci_generic_list_prepend(ctx->active_iterators, ccache_iterator, sizeof(cc_ccache_iterate_t), NULL); - - *iterpp = ccache_iterator; - return ccNoError; -} - -cc_int32 -ccs_context_compare(cc_server_context_t* a, cc_server_context_t* b) -{ - if (a == b) - return 1; - else - return 0; -} - -cc_int32 -ccs_context_destroy(cc_server_context_t* ctx) -{ - cc_ccache_iterate_t* ccache_iterator; - cc_ccache_list_node_t* ccache_node; - cc_server_ccache_t* ccache; - cc_int32 code; - - if (ctx == NULL) - return ccErrInvalidContext; - - cci_generic_list_destroy(ctx->active_iterators); - - code = ccs_ccache_list_iterator(ctx->ccaches, &ccache_iterator); - while (ccs_ccache_iterate_has_next(ccache_iterator)) { - code = ccs_ccache_iterate_next(ccache_iterator, &ccache_node); - ccache = (cc_server_ccache_t *)ccache_node->data; - ccache_node->data = NULL; - ccs_ccache_destroy(ccache); - } - ccs_ccache_list_destroy(ctx->ccaches); - - return ccNoError; -} - -cc_int32 -ccs_context_rem_ccache(cc_server_context_t* ctx, cc_server_ccache_t* ccache) -{ - cc_ccache_iterate_t* ccache_iterator; - cc_ccache_iterate_t* active_ccache_iterator; - cc_ccache_list_node_t* ccache_node; - cc_server_ccache_t* list_ccache; - cc_generic_list_node_t* gen_node; - cc_generic_iterate_t* gen_iterator; - cc_int32 code; - - if (ctx == NULL) - return ccErrInvalidContext; - - if (ccache == NULL) - return ccErrInvalidCCache; - - code = ccs_ccache_list_iterator(ctx->ccaches, &ccache_iterator); - while (ccs_ccache_iterate_has_next(ccache_iterator)) { - code = ccs_ccache_iterate_next(ccache_iterator, &ccache_node); - list_ccache = (cc_server_ccache_t *)ccache_node->data; - - if (list_ccache == ccache) { - code = cci_generic_list_iterator(ctx->active_iterators, &gen_iterator); - while (cci_generic_iterate_has_next(gen_iterator)) { - code = cci_generic_iterate_next(gen_iterator, &gen_node); - active_ccache_iterator = (cc_ccache_iterate_t *)gen_node->data; - if (active_ccache_iterator->next == ccache_node) { - active_ccache_iterator->next = active_ccache_iterator->next->next; - } - } - free(gen_iterator); - code = ccs_ccache_list_remove_element(ctx->ccaches, ccache_node); - break; - } - } - free(ccache_iterator); - return ccNoError; -} - diff --git a/src/lib/ccapi/server/ccs_lists.c b/src/lib/ccapi/server/ccs_lists.c deleted file mode 100644 index 5a20c10ab2..0000000000 --- a/src/lib/ccapi/server/ccs_lists.c +++ /dev/null @@ -1,657 +0,0 @@ -/* $Copyright: - * - * Copyright 2004-2006 by the Massachusetts Institute of Technology. - * - * All rights reserved. - * - * Export of this software from the United States of America may require a - * specific license from the United States Government. It is the - * responsibility of any person or organization contemplating export to - * obtain such a license before exporting. - * - * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute - * this software and its documentation for any purpose and without fee is - * hereby granted, provided that the above copyright notice appear in all - * copies and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of M.I.T. not be - * used in advertising or publicity pertaining to distribution of the - * software without specific, written prior permission. Furthermore if you - * modify this software you must label your software as modified software - * and not distribute it in such a fashion that it might be confused with - * the original MIT software. M.I.T. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Individual source code files are copyright MIT, Cygnus Support, - * OpenVision, Oracle, Sun Soft, FundsXpress, and others. - * - * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira, - * and Zephyr are trademarks of the Massachusetts Institute of Technology - * (MIT). No commercial use of these trademarks may be made without prior - * written permission of MIT. - * - * "Commercial use" means use of a name in a product or other for-profit - * manner. It does NOT prevent a commercial firm from referring to the MIT - * trademarks in order to convey information (although in doing so, - * recognition of their trademark status should be given). - * $ - */ - - -/* - * Lists implementation. - * - */ - -#include -#include -#include - -#include "CredentialsCache.h" -#include "datastore.h" - -/** - * ccs_context_iterate_has_next() - * - * Purpose: Determine if a context iterator has a next element - * - * Return: 1 if another element exists - * 0 if no additional elements exist - */ -cc_int32 -ccs_context_iterate_has_next(cc_context_iterate_t *iterate) -{ - if ( iterate == NULL ) - return 0; - - return cci_generic_iterate_has_next((cc_generic_iterate_t*)iterate); -} - -/** - * ccs_context_iterate_next() - * - * Purpose: Retrieve the next element from a context iterator and advance - * the iterator - * - * Return: non-NULL, the next element in the iterator - * NULL, the iterator list is empty or iterator is invalid - * - * Errors: ccErrBadParam - * - */ -cc_int32 -ccs_context_iterate_next(cc_context_iterate_t *iterate, cc_context_list_node_t ** nodepp) -{ - if ( iterate == NULL || nodepp == NULL) - return ccErrBadParam; - - return cci_generic_iterate_next((cc_generic_iterate_t*)iterate,(cc_context_list_node_t**)nodepp); -} - -/** - * ccs_ccache_iterate_has_next() - * - * Purpose: Determine if a cache iterator has a next element - * - * Return: 1 if another element exists - * 0 if no additional elements exist - * -1 if error - * - * Errors: ccErrBadParam - * - */ -cc_int32 -ccs_ccache_iterate_has_next(cc_ccache_iterate_t *iterate) -{ - if ( iterate == NULL ) - return 0; - return cci_generic_iterate_has_next((cc_generic_iterate_t*)iterate); -} - -/** - * ccs_ccache_iterate_next() - * - * Purpose: Retrieve the next element from a ccache iterator and advance - * the iterator - * - * Return: non-NULL, the next element in the iterator - * NULL, the iterator list is empty or iterator is invalid - * - * Errors: ccErrBadParam - * - */ -cc_int32 -ccs_ccache_iterate_next(cc_ccache_iterate_t *iterate, cc_ccache_list_node_t ** nodepp) -{ - if ( iterate == NULL || nodepp == NULL) - return ccErrBadParam; - - return cci_generic_iterate_next((cc_generic_iterate_t*)iterate, (cc_ccache_list_node_t**)nodepp); -} - -/** - * ccs_credentials_iterate_has_next() - * - * Purpose: Determine if a credentials iterator has a next element - * - * Return: 1 if another element exists - * 0 if no additional elements exist - * -1 if error - * - * Errors: ccErrBadParam - * - */ -cc_int32 -ccs_credentials_iterate_has_next(cc_credentials_iterate_t *iterate) -{ - if ( iterate == NULL ) - return 0; - - return cci_generic_iterate_has_next((cc_generic_iterate_t*)iterate); -} - -/** - * ccs_credentials_iterate_next() - * - * Purpose: Retrieve the next element from a credentials iterator and advance - * the iterator - * - * Return: non-NULL, the next element in the iterator - * NULL, the iterator list is empty or iterator is invalid - * - * Errors: ccErrBadParam - * - */ -cc_int32 -ccs_credentials_iterate_next(cc_credentials_iterate_t *iterate, cc_credentials_list_node_t** nodepp) -{ - if ( iterate == NULL || nodepp == NULL ) - return ccErrBadParam; - return cci_generic_iterate_next((cc_generic_iterate_t*)iterate, (cc_credentials_list_node_t**)nodepp); -} - -/** - * ccs_context_list_destroy() - * - * Purpose: Deallocate a list and all of its contents - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - */ -cc_int32 -ccs_context_list_destroy(cc_context_list_head_t* head) -{ - return cci_generic_list_destroy((cc_generic_list_head_t*)head); -} - -/** - * ccs_ccache_list_destroy() - * - * Purpose: Deallocate a list and all of its contents - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - */ -cc_int32 -ccs_ccache_list_destroy(cc_ccache_list_head_t* head) -{ - return cci_generic_list_destroy((cc_generic_list_head_t*)head); -} - -/** - * ccs_credentials_list_destroy() - * - * Purpose: Deallocate a list and all of its contents - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - */ -cc_int32 -ccs_credentials_list_destroy(cc_credentials_list_head_t* head) -{ - return cci_generic_list_destroy((cc_generic_list_head_t*)head); -} - -/** - * ccs_context_list_copy() - * - * Purpose: Copy a list - * - * Return: non-NULL, a new list - * NULL, failure - * - * Errors: ccErrBadParam, ccErrNoMem - * - */ -cc_int32 -ccs_context_list_copy(cc_context_list_head_t* head, cc_context_list_head_t** headpp ) -{ - return cci_generic_list_copy((cc_generic_list_head_t*)head, (cc_context_list_head_t **)headpp); -} - -/** - * ccs_ccache_list_copy() - * - * Purpose: Copy a list - * - * Return: non-NULL, a new list - * NULL, failure - * - * Errors: ccErrBadParam, ccErrNoMem - */ -cc_int32 -ccs_ccache_list_copy(cc_ccache_list_head_t* head, cc_ccache_list_head_t** headpp) -{ - return cci_generic_list_copy((cc_generic_list_head_t*)head, (cc_ccache_list_head_t **)headpp); -} - -/** - * ccs_credentials_list_copy() - * - * Purpose: Copy a list - * - * Return: non-NULL, a new list - * NULL, failure - * - * Errors: ccErrBadParam, ccErrNoMem - * - */ -cc_int32 -ccs_credentials_list_copy(cc_credentials_list_head_t* head, cc_credentials_list_head_t** headpp) -{ - return cci_generic_list_copy((cc_generic_list_head_t*)head, (cc_credentials_list_head_t **)headpp); -} - - -/** - * ccs_context_list_new() - * - * Purpose: Allocate a new context list - * - * Return: non-NULL, a new list - * NULL, failure - * - * Errors: ccErrNoMem - * - */ -cc_int32 -ccs_context_list_new(cc_context_list_head_t ** headpp) -{ - cc_context_list_head_t *ret; - - if ( headpp == NULL ) - return ccErrBadParam; - - ret = (cc_context_list_head_t *)malloc(sizeof(cc_context_list_head_t)); - if (ret == NULL) - return ccErrNoMem; - ret->head = ret->tail = NULL; - ret->type = cc_context_list; - *headpp = ret; - return ccNoError; -} - -/** - * ccs_context_list_append() - * - * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' - * - * Return: non-NULL, a pointer to the newly allocated node - * NULL, failure - * - * Errors: ccErrNoMem,ccErrBadParam - * - */ -cc_int32 -ccs_context_list_append(cc_context_list_head_t *head, cc_server_context_t *data, cc_context_list_node_t** nodepp) -{ - return cci_generic_list_append((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_context_t), (cc_context_list_node_t**)nodepp); -} - -/** - * ccs_context_list_prepend() - * - * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data' - * - * Return: non-NULL, a pointer to the newly allocated node - * NULL, failure - * - * Errors: ccErrNoMem,ccErrBadParam - * - */ -cc_int32 -ccs_context_list_prepend(cc_context_list_head_t *head, cc_server_context_t *data, cc_context_list_node_t** nodepp ) -{ - return cci_generic_list_prepend((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_context_t), (cc_context_list_node_t**)nodepp); -} - -/** - * ccs_context_list_remove_element - * - * Purpose: Remove a node from the list - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - */ -cc_int32 -ccs_context_list_remove_element(cc_context_list_head_t* head, cc_context_list_node_t* rem) -{ - return cci_generic_list_remove_element((cc_generic_list_head_t*)head, (cc_generic_list_node_t*)rem); -} - -/** - * ccs_context_list_iterator() - * - * Purpose: Allocate an iterator for the specified list - * - * Return: non-NULL, an iterator - * NULL, failure - * - * Errors: ccErrNoMem - * - */ -cc_int32 -ccs_context_list_iterator(cc_context_list_head_t *head, cc_context_iterate_t** iterpp) -{ - cc_context_iterate_t* iterator; - - if ( head == NULL || iterpp == NULL ) - return ccErrBadParam; - - iterator = (cc_context_iterate_t*)malloc(sizeof(cc_context_iterate_t)); - if (iterator == NULL) - return ccErrNoMem; - - iterator->next = head->head; - *iterpp = iterator; - return ccNoError; -} - -/** - * ccs_context_free_iterator() - * - * Purpose: Deallocate memory associated with an iterator - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - * - */ -cc_int32 -ccs_context_free_iterator(cc_context_iterate_t* iterator) -{ - if ( iterator == NULL ) - return ccErrBadParam; - - iterator->next = NULL; - free(iterator); - return ccNoError; -} - -/** - * ccs_ccache_list_new() - * - * Purpose: Allocate a new ccache list - * - * Return: non-NULL, a new list - * NULL, failure - * - * Errors: ccErrNoMem - */ -cc_int32 -ccs_ccache_list_new(cc_ccache_list_head_t ** listpp) -{ - cc_ccache_list_head_t *ret; - - if ( listpp == NULL ) - return ccErrBadParam; - - ret = (cc_ccache_list_head_t *)malloc(sizeof(cc_ccache_list_head_t)); - if (ret == NULL) - return ccErrNoMem; - - ret->head = ret->tail = NULL; - *listpp = ret; - return ccNoError; -} - -/** - * ccs_ccache_list_append() - * - * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' - * - * Return: non-NULL, a pointer to the newly allocated node - * NULL, failure - * - * Errors: ccErrNoMem,ccErrBadParam - * - */ -cc_int32 -ccs_ccache_list_append(cc_ccache_list_head_t *head, cc_server_ccache_t *data, cc_ccache_list_node_t** nodepp) -{ - return cci_generic_list_append((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_ccache_t), (cc_ccache_list_node_t**)nodepp); -} - -/** - * ccs_ccache_list_prepend() - * - * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data' - * - * Return: non-NULL, a pointer to the newly allocated node - * NULL, failure - * - * Errors: ccErrNoMem,ccErrBadParam - * - */ -cc_int32 -ccs_ccache_list_prepend(cc_ccache_list_head_t *head, cc_server_ccache_t *data, cc_ccache_list_node_t** nodepp) -{ - return cci_generic_list_prepend((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_ccache_t), (cc_ccache_list_node_t**)nodepp); -} - -/** - * ccs_ccache_list_remove_element() - * - * Purpose: Remove a node from the list - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - * - */ -cc_int32 -ccs_ccache_list_remove_element(cc_ccache_list_head_t* head, cc_ccache_list_node_t* rem) -{ - return cci_generic_list_remove_element((cc_generic_list_head_t*)head, (cc_generic_list_node_t*)rem); -} - -/** - * ccs_ccache_list_iterator() - * - * Purpose: Allocate an iterator for the specified list - * - * Return: non-NULL, an iterator - * NULL, failure - * - * Errors: ccErrNoMem - * - */ -cc_int32 -ccs_ccache_list_iterator(cc_ccache_list_head_t *head, cc_ccache_iterate_t** iterpp) -{ - cc_ccache_iterate_t* iterator; - - if ( head == NULL || iterpp == NULL ) - return ccErrBadParam; - - iterator = (cc_ccache_iterate_t*)malloc(sizeof(cc_ccache_iterate_t)); - if (iterator == NULL) - return ccErrNoMem; - - iterator->next = head->head; - *iterpp = iterator; - return ccNoError; -} - -/** - * ccs_ccache_free_iterator() - * - * Purpose: Deallocate memory associated with an iterator - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - * - */ -cc_int32 -ccs_ccache_free_iterator(cc_ccache_iterate_t* iterator) -{ - if ( iterator == NULL ) - return ccErrBadParam; - - iterator->next = NULL; - free(iterator); - return ccNoError; -} - -/** - * ccs_credentials_list_new() - * - * Purpose: Allocate a new ccache list - * - * Return: non-NULL, a new list - * NULL, failure - * - * Errors: ccErrNoMem - * - */ -cc_int32 -ccs_credentials_list_new(cc_credentials_list_head_t ** list) -{ - if ( list == NULL ) - return ccErrBadParam; - - *list = (cc_credentials_list_head_t *)malloc(sizeof(cc_credentials_list_head_t)); - if (*list == NULL) - return ccErrNoMem; - - (*list)->head = (*list)->tail = NULL; - return ccNoError; -} - -/** - * ccs_credentials_list_append() - * - * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' - * - * Return: non-NULL, a pointer to the newly allocated node - * NULL, failure - * - * Errors: ccErrNoMem,ccErrBadParam - * - */ -cc_int32 -ccs_credentials_list_append(cc_credentials_list_head_t *head, cc_server_credentials_t *data, cc_credentials_list_node_t** nodepp ) -{ - return cci_generic_list_append((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_credentials_t), (cc_credentials_list_node_t**)nodepp); -} - -/** - * ccs_credentials_list_prepend() - * - * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data' - * - * Return: non-NULL, a pointer to the newly allocated node - * NULL, failure - * - * Errors: ccErrNoMem,ccErrBadParam - * - */ -cc_int32 -ccs_credentials_list_prepend(cc_credentials_list_head_t *head, cc_server_credentials_t *data, cc_credentials_list_node_t** nodepp) -{ - return cci_generic_list_prepend((cc_generic_list_head_t *)head, (void *)data, sizeof(cc_server_credentials_t), (cc_credentials_list_node_t**)nodepp); -} - -/** - * ccs_credentials_list_remove_element() - * - * Purpose: Remove a node from the list - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - * - */ -cc_int32 -ccs_credentials_list_remove_element(cc_credentials_list_head_t* head, cc_credentials_list_node_t* rem) -{ - return cci_generic_list_remove_element((cc_generic_list_head_t*)head, (cc_generic_list_node_t*)rem); -} - -/** - * ccs_credentials_list_iterator() - * - * Purpose: Allocate an iterator for the specified list - * - * Return: non-NULL, an iterator - * NULL, failure - * - * Errors: ccErrNoMem - * - */ -cc_int32 -ccs_credentials_list_iterator(cc_credentials_list_head_t *head, cc_credentials_iterate_t** iterpp) -{ - cc_credentials_iterate_t* iterator; - - if ( head == NULL || iterpp == NULL ) - return ccErrBadParam; - - iterator = (cc_credentials_iterate_t*)malloc(sizeof(cc_credentials_iterate_t)); - if (iterator == NULL) - return ccErrNoMem; - - iterator->next = head->head; - *iterpp = iterator; - return ccNoError; -} - -/** - * ccs_credentials_free_iterator() - * - * Purpose: Deallocate memory associated with an iterator - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - * - */ -cc_int32 -ccs_credentials_free_iterator(cc_credentials_iterate_t* iterator) -{ - if ( iterator == NULL ) - return ccErrBadParam; - - iterator->next = NULL; - free(iterator); - return ccNoError; -} - diff --git a/src/lib/ccapi/server/mac/CCacheServer.plist b/src/lib/ccapi/server/mac/CCacheServer.plist deleted file mode 100644 index 987cf71102..0000000000 --- a/src/lib/ccapi/server/mac/CCacheServer.plist +++ /dev/null @@ -1,12 +0,0 @@ - - - - - ServiceName - edu.mit.Kerberos.CCacheServer.ipcService - Command - /System/Library/CoreServices/CCacheServer.app/Contents/MacOS/CCacheServer - OnDemand - - - diff --git a/src/lib/ccapi/server/mac/CCacheServerInfo.plist b/src/lib/ccapi/server/mac/CCacheServerInfo.plist deleted file mode 100644 index e03d5f3ffa..0000000000 --- a/src/lib/ccapi/server/mac/CCacheServerInfo.plist +++ /dev/null @@ -1,38 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleExecutable - CCacheServer - CFBundleGetInfoString - 4.1 - CFBundleIconFile - - CFBundleIdentifier - edu.mit.Kerberos.CCacheServer - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - Kerberos Credentials Cache Server - CFBundlePackageType - APPL - CFBundleSignature - CCSa - CFBundleVersion - 0.0.1d1 - CFBundleShortVersionString - 5.5 - CFBundleGetInfoString - 5.5 Copyright MIT - KfMDisplayVersion - 5.5 Copyright MIT - KfMDisplayCopyright - Copyright MIT - NSHumanReadableCopyright - 5.5 Copyright MIT - LSBackgroundOnly - 1 - - diff --git a/src/lib/ccapi/server/mac/main.c b/src/lib/ccapi/server/mac/main.c deleted file mode 100644 index 004e360952..0000000000 --- a/src/lib/ccapi/server/mac/main.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -#include "CredentialsCache.h" -#include "msg.h" -#include "migServer.h" -#include "serv_ops.h" - -#include - -int main (int argc, const char *argv[]) -{ - cc_int32 code = 0; - - openlog (argv[0], LOG_CONS | LOG_PID, LOG_AUTH); - syslog (LOG_INFO, "Starting up."); - - if (!code) { - code = ccs_serv_initialize(); - } - - if (!code) { - code = kipc_server_run_server (ccapi_server); - } - - /* cleanup ccs resources */ - ccs_serv_cleanup(); - - syslog (LOG_NOTICE, "Exiting: %s (%d)", kipc_error_string (code), code); - - /* exit */ - return code ? 1 : 0; -} diff --git a/src/lib/ccapi/server/rpc_auth.c b/src/lib/ccapi/server/rpc_auth.c deleted file mode 100644 index a0af4254f0..0000000000 --- a/src/lib/ccapi/server/rpc_auth.c +++ /dev/null @@ -1,67 +0,0 @@ -/* $Copyright: - * - * Copyright 2004 by the Massachusetts Institute of Technology. - * - * All rights reserved. - * - * Export of this software from the United States of America may require a - * specific license from the United States Government. It is the - * responsibility of any person or organization contemplating export to - * obtain such a license before exporting. - * - * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute - * this software and its documentation for any purpose and without fee is - * hereby granted, provided that the above copyright notice appear in all - * copies and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of M.I.T. not be - * used in advertising or publicity pertaining to distribution of the - * software without specific, written prior permission. Furthermore if you - * modify this software you must label your software as modified software - * and not distribute it in such a fashion that it might be confused with - * the original MIT software. M.I.T. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Individual source code files are copyright MIT, Cygnus Support, - * OpenVision, Oracle, Sun Soft, FundsXpress, and others. - * - * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira, - * and Zephyr are trademarks of the Massachusetts Institute of Technology - * (MIT). No commercial use of these trademarks may be made without prior - * written permission of MIT. - * - * "Commercial use" means use of a name in a product or other for-profit - * manner. It does NOT prevent a commercial firm from referring to the MIT - * trademarks in order to convey information (although in doing so, - * recognition of their trademark status should be given). - * $ - */ - -/* - * Stubs for rpc_auth. - */ - -#include "CredentialsCache.h" -#include "rpc_auth.h" -#include - -cc_int32 -ccs_rpc_is_authorized( cc_auth_info_t* msg_auth, cc_session_info_t* msg_session, cc_auth_info_t* stored_auth, - cc_session_info_t* stored_session, cc_uint32 * authorizedp) -{ - if (msg_auth->len == stored_auth->len && - !memcmp(msg_auth->info, stored_auth->info, msg_auth->len) && - msg_session->len == stored_session->len && - !memcmp(msg_session->info, stored_session->info, msg_session->len)) - *authorizedp = 1; - else - *authorizedp = 0; - - return ccNoError; -} - - diff --git a/src/lib/ccapi/server/serv_ops.c b/src/lib/ccapi/server/serv_ops.c deleted file mode 100644 index 52c62f45cc..0000000000 --- a/src/lib/ccapi/server/serv_ops.c +++ /dev/null @@ -1,1586 +0,0 @@ -/* $Copyright: - * - * Copyright 2004-2006 by the Massachusetts Institute of Technology. - * - * All rights reserved. - * - * Export of this software from the United States of America may require a - * specific license from the United States Government. It is the - * responsibility of any person or organization contemplating export to - * obtain such a license before exporting. - * - * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and distribute - * this software and its documentation for any purpose and without fee is - * hereby granted, provided that the above copyright notice appear in all - * copies and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of M.I.T. not be - * used in advertising or publicity pertaining to distribution of the - * software without specific, written prior permission. Furthermore if you - * modify this software you must label your software as modified software - * and not distribute it in such a fashion that it might be confused with - * the original MIT software. M.I.T. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Individual source code files are copyright MIT, Cygnus Support, - * OpenVision, Oracle, Sun Soft, FundsXpress, and others. - * - * Project Athena, Athena, Athena MUSE, Discuss, Hesiod, Kerberos, Moira, - * and Zephyr are trademarks of the Massachusetts Institute of Technology - * (MIT). No commercial use of these trademarks may be made without prior - * written permission of MIT. - * - * "Commercial use" means use of a name in a product or other for-profit - * manner. It does NOT prevent a commercial firm from referring to the MIT - * trademarks in order to convey information (although in doing so, - * recognition of their trademark status should be given). - * $ - */ - -/* - * Server side implementation of each API function. - */ - -#include "CredentialsCache.h" -#include "serv_ops.h" -#include "datastore.h" -#include "rpc_auth.h" -#include "msg_headers.h" -#include "marshall.h" - -#include -#include - -cc_context_list_head_t* AllContexts = NULL; -type_to_op_mapping_t* TypeToOpMapping = NULL; - -extern int cc_err_code; -extern int cc_myversion; -extern char cc_vendor[]; - -cc_int32 -ccs_serv_initialize(void) -{ - cc_int32 code; - - code = ccs_context_list_new(&AllContexts); - if ( code != ccNoError ) - return code; - TypeToOpMapping = (type_to_op_mapping_t*)malloc(sizeof(type_to_op_mapping_t)); - if (TypeToOpMapping == NULL) { - ccs_context_list_destroy(AllContexts); - return ccErrNoMem; - } - -#if 0 - /* These message types are only generated by the server in response - * to a request. They are never received. - */ - TypeToOpMapping->operations[ccmsg_ACK] = ccop_ACK; - TypeToOpMapping->operations[ccmsg_NACK] = ccop_NACK; -#endif - TypeToOpMapping->operations[ccmsg_INIT] = ccop_INIT; - TypeToOpMapping->operations[ccmsg_CTX_RELEASE] = ccop_CTX_RELEASE; - TypeToOpMapping->operations[ccmsg_CTX_GET_CHANGE_TIME] = ccop_CTX_GET_CHANGE_TIME; - TypeToOpMapping->operations[ccmsg_CTX_GET_DEFAULT_CCACHE_NAME] = ccop_CTX_GET_DEFAULT_CCACHE_NAME; - TypeToOpMapping->operations[ccmsg_CTX_CCACHE_OPEN] = ccop_CTX_CCACHE_OPEN; - TypeToOpMapping->operations[ccmsg_CTX_CCACHE_OPEN_DEFAULT] = ccop_CTX_CCACHE_OPEN_DEFAULT; - TypeToOpMapping->operations[ccmsg_CTX_CCACHE_CREATE] = ccop_CTX_CCACHE_CREATE; - TypeToOpMapping->operations[ccmsg_CTX_CCACHE_CREATE_DEFAULT] = ccop_CTX_CCACHE_CREATE_DEFAULT; - TypeToOpMapping->operations[ccmsg_CTX_CCACHE_CREATE_UNIQUE] = ccop_CTX_CCACHE_CREATE_UNIQUE; - TypeToOpMapping->operations[ccmsg_CTX_NEW_CCACHE_ITERATOR] = ccop_CTX_NEW_CCACHE_ITERATOR; - TypeToOpMapping->operations[ccmsg_CTX_LOCK] = ccop_CTX_LOCK; - TypeToOpMapping->operations[ccmsg_CTX_UNLOCK] = ccop_CTX_UNLOCK; - TypeToOpMapping->operations[ccmsg_CTX_COMPARE] = ccop_CTX_COMPARE; - TypeToOpMapping->operations[ccmsg_CCACHE_RELEASE] = ccop_CCACHE_RELEASE; - TypeToOpMapping->operations[ccmsg_CCACHE_DESTROY] = ccop_CCACHE_DESTROY; - TypeToOpMapping->operations[ccmsg_CCACHE_SET_DEFAULT] = ccop_CCACHE_SET_DEFAULT; - TypeToOpMapping->operations[ccmsg_CCACHE_GET_CREDS_VERSION] = ccop_CCACHE_GET_CREDS_VERSION; - TypeToOpMapping->operations[ccmsg_CCACHE_GET_NAME] = ccop_CCACHE_GET_NAME; - TypeToOpMapping->operations[ccmsg_CCACHE_GET_PRINCIPAL] = ccop_CCACHE_GET_PRINCIPAL; - TypeToOpMapping->operations[ccmsg_CCACHE_SET_PRINCIPAL] = ccop_CCACHE_SET_PRINCIPAL; - TypeToOpMapping->operations[ccmsg_CCACHE_NEW_CREDS_ITERATOR] = ccop_CCACHE_NEW_CREDS_ITERATOR; - TypeToOpMapping->operations[ccmsg_CCACHE_STORE_CREDS] = ccop_CCACHE_STORE_CREDS; - TypeToOpMapping->operations[ccmsg_CCACHE_REM_CREDS] = ccop_CCACHE_REM_CREDS; - TypeToOpMapping->operations[ccmsg_CCACHE_MOVE] = ccop_CCACHE_MOVE; - TypeToOpMapping->operations[ccmsg_CCACHE_LOCK] = ccop_CCACHE_LOCK; - TypeToOpMapping->operations[ccmsg_CCACHE_UNLOCK] = ccop_CCACHE_UNLOCK; - TypeToOpMapping->operations[ccmsg_CCACHE_GET_LAST_DEFAULT_TIME] = ccop_CCACHE_GET_LAST_DEFAULT_TIME; - TypeToOpMapping->operations[ccmsg_CCACHE_GET_CHANGE_TIME] = ccop_CCACHE_GET_CHANGE_TIME; - TypeToOpMapping->operations[ccmsg_CCACHE_COMPARE] = ccop_CCACHE_COMPARE; - TypeToOpMapping->operations[ccmsg_CCACHE_GET_KDC_TIME_OFFSET] = ccop_CCACHE_GET_KDC_TIME_OFFSET; - TypeToOpMapping->operations[ccmsg_CCACHE_SET_KDC_TIME_OFFSET] = ccop_CCACHE_SET_KDC_TIME_OFFSET; - TypeToOpMapping->operations[ccmsg_CCACHE_CLEAR_KDC_TIME_OFFSET] = ccop_CCACHE_CLEAR_KDC_TIME_OFFSET; - TypeToOpMapping->operations[ccmsg_CCACHE_ITERATOR_RELEASE] = ccop_CCACHE_ITERATOR_RELEASE; - TypeToOpMapping->operations[ccmsg_CCACHE_ITERATOR_NEXT] = ccop_CCACHE_ITERATOR_NEXT; - TypeToOpMapping->operations[ccmsg_CCACHE_ITERATOR_CLONE] = ccop_CCACHE_ITERATOR_CLONE; - TypeToOpMapping->operations[ccmsg_CREDS_ITERATOR_RELEASE] = ccop_CREDS_ITERATOR_RELEASE; - TypeToOpMapping->operations[ccmsg_CREDS_ITERATOR_NEXT] = ccop_CREDS_ITERATOR_NEXT; - TypeToOpMapping->operations[ccmsg_CREDS_ITERATOR_CLONE] = ccop_CREDS_ITERATOR_CLONE; - - return ccNoError; -}; - -cc_int32 -ccs_serv_cleanup(void) -{ - return ccNoError; -} - -cc_int32 -ccs_serv_process_msg(cc_msg_t * msg, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** resp_msg) -{ - cc_server_context_t* ctx; - ccmsg_ctx_only_t* header = (ccmsg_ctx_only_t *)msg->header; - cc_uint32 type; - cc_uint32 header_len; - cc_handle handle; - cc_int32 code; - - if (msg == NULL || msg->header == NULL || auth_info == NULL || session_info == NULL) - return ccErrBadParam; - - if (AllContexts == NULL) { - code = ccs_serv_initialize(); - if ( code != ccNoError ) - return code; - } - - type = msg->type; - if (type == ccmsg_INIT) { - return TypeToOpMapping->operations[type] (NULL, auth_info, session_info, msg, resp_msg); - } else { - header_len = msg->header_len; - if (header_len < sizeof(ccmsg_ctx_only_t)) { - return ccErrBadParam; - } - - handle = ntohll(header->ctx); - code = ccs_serv_find_ctx_by_handle(handle, auth_info, session_info, &ctx); - if (code != ccNoError) { - ccs_serv_make_nack(ccErrContextNotFound, auth_info, session_info, resp_msg); - return code; - } - return TypeToOpMapping->operations[type] (ctx, auth_info, session_info, msg, resp_msg); - } -} - -/*deprecated*/ -cc_int32 -ccs_serv_find_ctx(cc_auth_info_t* auth_info, cc_session_info_t* session_info, - cc_server_context_t** ctxpp) -{ - cc_context_iterate_t* ctx_iterator; - cc_context_list_node_t* ctx_node; - cc_server_context_t* ctx; - cc_int32 code; - cc_uint32 authorized; - - code = ccs_context_list_iterator(AllContexts, &ctx_iterator); - if (code != ccNoError) - return code; - - while (ccs_context_iterate_has_next(ctx_iterator)) { - code = ccs_context_iterate_next(ctx_iterator, &ctx_node); - if (code != ccNoError) { - ccs_context_free_iterator(ctx_iterator); - return code; - } - ctx = (cc_server_context_t *)ctx_node->data; - code = ccs_rpc_is_authorized(auth_info, session_info, ctx->auth_info, ctx->session_info, &authorized); - if (code != ccNoError) { - ccs_context_free_iterator(ctx_iterator); - return code; - } - - if (authorized) { - ccs_context_free_iterator(ctx_iterator); - *ctxpp = ctx; - return ccNoError; - } - } - ccs_context_free_iterator(ctx_iterator); - return ccIteratorEnd; -} - -cc_int32 -ccs_serv_find_ctx_by_handle(cc_handle ctx_num, cc_auth_info_t* auth, cc_session_info_t* session, cc_server_context_t** ctxpp) -{ - cc_server_context_t* input_ctx = (cc_server_context_t*)ctx_num; - cc_context_iterate_t* ctx_iterator; - cc_context_list_node_t* ctx_node; - cc_server_context_t* ctx; - cc_uint32 authorized; - cc_int32 code; - - code = ccs_context_list_iterator(AllContexts, &ctx_iterator); - if (code != ccNoError) - return code; - - while (ccs_context_iterate_has_next(ctx_iterator)) { - code = ccs_context_iterate_next(ctx_iterator, &ctx_node); - ctx = (cc_server_context_t *)ctx_node->data; - if (code != ccNoError) { - ccs_context_free_iterator(ctx_iterator); - return code; - } - - code = ccs_rpc_is_authorized(auth, session, ctx->auth_info, ctx->session_info, &authorized); - if (code != ccNoError) { - ccs_context_free_iterator(ctx_iterator); - return code; - } - - if (ctx == input_ctx && authorized) { - ccs_context_free_iterator(ctx_iterator); - *ctxpp = ctx; - return ccNoError; - } - } - ccs_context_free_iterator(ctx_iterator); - return ccIteratorEnd; -} - -cc_int32 -ccs_serv_find_ccache_by_handle(cc_server_context_t* ctx, cc_handle ccache, cc_server_ccache_t** ccachepp ) -{ - cc_ccache_iterate_t* ccache_iterator; - cc_ccache_list_node_t* ccache_node; - cc_server_ccache_t* stored_ccache; - cc_server_ccache_t* target_ccache = (cc_server_ccache_t*)ccache; - cc_int32 code; - - code = ccs_ccache_list_iterator(ctx->ccaches, &ccache_iterator); - if (code != ccNoError) - return code; - - while (ccs_ccache_iterate_has_next(ccache_iterator)) { - code = ccs_ccache_iterate_next(ccache_iterator, &ccache_node); - if (code != ccNoError) { - ccs_ccache_free_iterator(ccache_iterator); - return code; - } - - stored_ccache = (cc_server_ccache_t *)ccache_node->data; - - if (stored_ccache == target_ccache) { - ccs_ccache_free_iterator(ccache_iterator); - *ccachepp = stored_ccache; - return ccNoError; - } - } - ccs_ccache_free_iterator(ccache_iterator); - return ccIteratorEnd; -} - -cc_int32 -ccs_serv_find_ccache_iterator_by_handle(cc_server_context_t* ctx, cc_handle iterator, cc_generic_list_node_t** nodepp ) -{ - cc_generic_iterate_t* gen_iterator; - cc_generic_list_node_t* gen_node; - cc_ccache_iterate_t* stored_iterator; - cc_ccache_iterate_t* target_iterator = (cc_ccache_iterate_t*)iterator; - cc_int32 code; - - code = cci_generic_list_iterator(ctx->active_iterators, &gen_iterator); - if (code != ccNoError) - return code; - - while (cci_generic_iterate_has_next(gen_iterator)) { - code = cci_generic_iterate_next(gen_iterator, &gen_node); - if (code != ccNoError) { - cci_generic_free_iterator(gen_iterator); - return code; - } - - stored_iterator = (cc_ccache_iterate_t *)gen_node->data; - if (stored_iterator == target_iterator) { - cci_generic_free_iterator(gen_iterator); - *nodepp = gen_node; - return ccNoError; - } - } - cci_generic_free_iterator(gen_iterator); - return ccIteratorEnd; -} - -cc_int32 -ccs_serv_find_creds_iterator_by_handle(cc_server_ccache_t* ccache, cc_handle iterator, cc_generic_list_node_t** nodepp) -{ - cc_generic_iterate_t* gen_iterator; - cc_generic_list_node_t* gen_node; - cc_ccache_iterate_t* stored_iterator; - cc_ccache_iterate_t* target_iterator = (cc_ccache_iterate_t*)iterator; - cc_int32 code; - - code = cci_generic_list_iterator(ccache->active_iterators, &gen_iterator); - if (code != ccNoError) - return code; - - while (cci_generic_iterate_has_next(gen_iterator)) { - code = cci_generic_iterate_next(gen_iterator, &gen_node); - if (code != ccNoError) { - cci_generic_free_iterator(gen_iterator); - return code; - } - - stored_iterator = (cc_ccache_iterate_t *)gen_node->data; - if (stored_iterator == target_iterator) { - cci_generic_free_iterator(gen_iterator); - *nodepp = gen_node; - return ccNoError; - } - } - cci_generic_free_iterator(gen_iterator); - return ccIteratorEnd; -} - -cc_int32 -ccs_serv_make_nack(cc_int32 err_code, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** resp_msg) -{ - ccmsg_nack_t* nack_header; - cc_int32 code; - - code = cci_msg_new(ccmsg_NACK, resp_msg); - if (code != ccNoError) - return code; - - nack_header = (ccmsg_nack_t*)malloc(sizeof(ccmsg_nack_t)); - if (nack_header == NULL) { - cci_msg_destroy(*resp_msg); - *resp_msg = 0; - return ccErrNoMem; - } - - nack_header->err_code = htonl(err_code); - code = cci_msg_add_header(*resp_msg, nack_header, sizeof(ccmsg_nack_t)); - if (code != ccNoError) { - cci_msg_destroy(*resp_msg); - *resp_msg = 0; - return code; - } - - return ccNoError; -} - -cc_int32 -ccs_serv_make_ack(void * header, cc_int32 header_len, cc_auth_info_t* auth_info, cc_session_info_t* session_info, cc_msg_t** resp_msg) -{ - cc_int32 code; - - code = cci_msg_new(ccmsg_ACK, resp_msg); - if (code != ccNoError) - return code; - - if (header != NULL) { - code = cci_msg_add_header(*resp_msg, header, header_len); - if (code != ccNoError) { - cci_msg_destroy(*resp_msg); - resp_msg = 0; - return code; - } - } - return ccNoError; -} - -cc_int32 -ccop_INIT( cc_server_context_t* ctx, /* not used */ - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - cc_uint32 blob_pos; - cc_server_context_t *new_ctx; - ccmsg_init_resp_t *resp_header; - ccmsg_init_t *header = (ccmsg_init_t *)msg->header; - cc_context_list_node_t* ctx_node; - cc_uint32 header_len, in_version; - - cc_int32 code; - - *resp_msg = 0; - - header_len = msg->header_len; - if (ctx != NULL || header_len != sizeof(ccmsg_init_t)) { - return ccErrBadParam; - } - - in_version = ntohl(header->in_version); - code = ccs_context_new(in_version, auth_info, session_info, &new_ctx); - if (code != ccNoError) { - return code; - } - - code = ccs_context_list_append(AllContexts, new_ctx, &ctx_node); - if (code != ccNoError) { - ccs_context_destroy(new_ctx); - return code; - } - - resp_header = (ccmsg_init_resp_t*)malloc(sizeof(ccmsg_init_resp_t)); - if (resp_header == NULL) { - ccs_context_destroy(new_ctx); - return ccErrNoMem; - } - - code = cci_msg_new(ccmsg_ACK, resp_msg); - if (code != ccNoError) { - free(resp_header); - ccs_context_destroy(new_ctx); - return code; - } - code = cci_msg_add_data_blob(*resp_msg, cc_vendor, strlen(cc_vendor) + 1, &blob_pos); - if (code != ccNoError) { - free(resp_header); - ccs_context_destroy(new_ctx); - cci_msg_destroy(*resp_msg); - *resp_msg = 0; - return code; - } - - resp_header->out_ctx = htonll((cc_handle) new_ctx); - resp_header->out_version = htonl(cc_myversion); - resp_header->vendor_offset = htonl(blob_pos); - resp_header->vendor_length = htonl(strlen(cc_vendor) + 1); - code = cci_msg_add_header(*resp_msg, resp_header, sizeof(ccmsg_init_resp_t)); - if (code != ccNoError) { - free(resp_header); - ccs_context_destroy(new_ctx); - cci_msg_destroy(*resp_msg); - *resp_msg = 0; - return code; - } - - return ccNoError; -} - -cc_int32 -ccop_CTX_RELEASE( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ctx_release_t* header = (ccmsg_ctx_release_t *)msg->header; - cc_uint32 header_len = msg->header_len; - cc_handle handle = ntohll(header->ctx); - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ctx_release_t)) { - return ccErrBadParam; - } - - code = ccs_context_destroy((cc_server_context_t *)handle); - return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CTX_GET_CHANGE_TIME( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ctx_get_change_time_resp_t* resp_header; - ccmsg_ctx_get_change_time_t *header = (ccmsg_ctx_get_change_time_t *)msg->header; - cc_uint32 header_len = msg->header_len; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ctx_get_change_time_t)) { - return ccErrBadParam; - } - - resp_header = (ccmsg_ctx_get_change_time_resp_t*)malloc(sizeof(ccmsg_ctx_get_change_time_resp_t)); - if (resp_header == NULL) { - return ccErrNoMem; - } - - resp_header->time = htonll(ctx->changed); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ctx_get_change_time_resp_t), auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CTX_GET_DEFAULT_CCACHE_NAME( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - char * name; - ccmsg_ctx_get_default_ccache_name_resp_t* resp_header; - ccmsg_ctx_get_default_ccache_name_t* header = (ccmsg_ctx_get_default_ccache_name_t *)msg->header; - cc_uint32 header_len = htonl(msg->header_len); - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ctx_get_default_ccache_name_t)) { - return ccErrBadParam; - } - - code = ccs_context_get_default_ccache_name(ctx, &name); - if (code != ccNoError) - return code; - - code = cci_msg_new(ccmsg_ACK, resp_msg); - if (code != ccNoError) - return code; - - resp_header = (ccmsg_ctx_get_default_ccache_name_resp_t*)malloc(sizeof(ccmsg_ctx_get_default_ccache_name_resp_t)); - if (resp_header == NULL) { - cci_msg_destroy(*resp_msg); - *resp_msg = 0; - return ccErrNoMem; - } - - code = cci_msg_add_data_blob(*resp_msg, name, strlen(name) + 1, &resp_header->name_offset); - resp_header->name_len = htonl(strlen(name) + 1); - return ccNoError; -} - -cc_int32 -ccop_CTX_COMPARE(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - cc_server_context_t *ctx2; - ccmsg_ctx_compare_resp_t* resp_header; - ccmsg_ctx_compare_t* header = (ccmsg_ctx_compare_t *)msg->header; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ctx_compare_t)) - return ccErrBadParam; - - code = ccs_serv_find_ctx_by_handle(header->ctx2, auth_info, session_info, &ctx2); - - resp_header = (ccmsg_ctx_compare_resp_t*)malloc(sizeof(ccmsg_ctx_compare_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - resp_header->is_equal = htonl(ccs_context_compare(ctx, ctx2)); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ctx_compare_resp_t), auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CTX_NEW_CCACHE_ITERATOR(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - cc_ccache_iterate_t* ccache_iterator; - ccmsg_ctx_new_ccache_iterator_resp_t* resp_header; - ccmsg_ctx_new_ccache_iterator_t* header = (ccmsg_ctx_new_ccache_iterator_t*)msg->header; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ctx_new_ccache_iterator_t)) - return ccErrBadParam; - - code = ccs_context_ccache_iterator(ctx, &ccache_iterator); - - resp_header = (ccmsg_ctx_new_ccache_iterator_resp_t*)malloc(sizeof(ccmsg_ctx_new_ccache_iterator_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - resp_header->iterator = htonll((cc_handle) ccache_iterator); - - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ctx_new_ccache_iterator_resp_t), auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CTX_LOCK( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - // TODO - return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CTX_UNLOCK( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - // TODO - return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CTX_CLONE( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - // TODO - return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CTX_CCACHE_OPEN(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - char *name; - cc_server_ccache_t* ccache; - ccmsg_ccache_open_resp_t* resp_header; - ccmsg_ccache_open_t* header = (ccmsg_ccache_open_t*)msg->header; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_open_t)) - return ccErrBadParam; - - code = cci_msg_retrieve_blob(msg, ntohl(header->name_offset), ntohl(header->name_len), &name); - code = ccs_context_find_ccache(ctx, name, &ccache); - - free(name); - - if (ccache == NULL) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - resp_header = (ccmsg_ccache_open_resp_t*)malloc(sizeof(ccmsg_ccache_open_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - resp_header->ccache = htonll((cc_handle) ccache); - ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_open_resp_t), auth_info, session_info, resp_msg); - return ccNoError; -} - -cc_int32 -ccop_CTX_CCACHE_OPEN_DEFAULT(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_open_default_t* header = (ccmsg_ccache_open_default_t*)msg->header; - ccmsg_ccache_open_resp_t* resp_header; - cc_server_ccache_t* ccache; - cc_uint32 header_len = msg->header_len; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_open_default_t)) - return ccErrBadParam; - - if (ctx->ccaches->head->data == NULL) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - ccache = (cc_server_ccache_t*) ctx->ccaches->head->data; - - resp_header = (ccmsg_ccache_open_resp_t*)malloc(sizeof(ccmsg_ccache_open_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - resp_header->ccache = htonll((cc_handle) ccache); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_open_resp_t), auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CTX_CCACHE_CREATE(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_create_resp_t* resp_header; - ccmsg_ccache_create_t* header = (ccmsg_ccache_create_t*)msg->header; - cc_server_ccache_t* ccache; - char* principal; - char* name; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_create_t)) - return ccErrBadParam; - - code = cci_msg_retrieve_blob(msg, ntohl(header->principal_offset), ntohl(header->principal_len), &principal); - if (code != ccNoError) - return code; - principal[ntohl(header->principal_len)] = '\0'; /*Ensure null termination*/ - - code = cci_msg_retrieve_blob(msg, ntohl(header->name_offset), ntohl(header->name_len), &name); - if (code != ccNoError) - return code; - name[ntohl(header->name_len)] = '\0'; /*Ensure null termination*/ - - code = ccs_context_create_ccache(ctx, name, ntohl(header->version), principal, &ccache); - if (code != ccNoError) - return code; - - resp_header = (ccmsg_ccache_create_resp_t*)malloc(sizeof(ccmsg_ccache_create_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - resp_header->ccache = htonll((cc_handle) ccache); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_create_resp_t), auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CTX_CCACHE_CREATE_DEFAULT( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_create_resp_t* resp_header; - ccmsg_ccache_create_t* header = (ccmsg_ccache_create_t*)msg->header; - cc_server_ccache_t* ccache; - char* principal; - char* name; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_create_t)) - return ccErrBadParam; - - code = cci_msg_retrieve_blob(msg, ntohl(header->principal_offset), ntohl(header->principal_len), &principal); - if (code != ccNoError) - return code; - principal[ntohl(header->principal_len)] = '\0'; /*Ensure null termination*/ - - code = ccs_context_get_default_ccache_name(ctx, &name); - if (code != ccNoError) - return code; - - code = ccs_context_create_ccache(ctx, name, ntohl(header->version), principal, &ccache); - if (code != ccNoError) - return code; - - resp_header = (ccmsg_ccache_create_resp_t*)malloc(sizeof(ccmsg_ccache_create_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - resp_header->ccache = htonll((cc_handle) ccache); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_create_resp_t), auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CTX_CCACHE_CREATE_UNIQUE( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_create_resp_t* resp_header; - ccmsg_ccache_create_t* header = (ccmsg_ccache_create_t*)msg->header; - cc_server_ccache_t* ccache; - char* principal; - char* name; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_create_t)) - return ccErrBadParam; - - code = cci_msg_retrieve_blob(msg, ntohl(header->principal_offset), htonl(header->principal_len), &principal); - if (code != ccNoError) - return code; - principal[ntohl(header->principal_len)] = '\0'; /*Ensure null termination*/ - - // TODO: Generate a unique ccache name - name = "unique"; - - code = ccs_context_create_ccache(ctx, name, ntohl(header->version), principal, &ccache); - if (code != ccNoError) - return code; - - resp_header = (ccmsg_ccache_create_resp_t*)malloc(sizeof(ccmsg_ccache_create_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - resp_header->ccache = htonll((cc_handle) ccache); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_create_resp_t), auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_RELEASE( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - // TODO: This is probably wrong. - return ccop_CCACHE_DESTROY(ctx, auth_info, session_info, msg, resp_msg); -} - -cc_int32 -ccop_CCACHE_DESTROY( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_release_t* header = (ccmsg_ccache_release_t*)msg->header; - cc_server_ccache_t* ccache; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_release_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - ccs_ccache_destroy(ccache); - - return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_SET_DEFAULT(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - cc_server_ccache_t* ccache, *stored_ccache, *old_default; - ccmsg_ccache_set_default_t* header = (ccmsg_ccache_set_default_t*)msg->header; - cc_ccache_iterate_t* ccache_iterator; - cc_ccache_list_node_t* ccache_node; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_set_default_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - if (ccache == (cc_server_ccache_t*)ctx->ccaches->head->data) /*already default*/ - return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg); - - old_default = (cc_server_ccache_t*)ctx->ccaches->head->data; - old_default->last_default = time(NULL); - - code = ccs_ccache_list_iterator(ctx->ccaches, &ccache_iterator); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - while (ccs_ccache_iterate_has_next(ccache_iterator)) { - code = ccs_ccache_iterate_next(ccache_iterator,&ccache_node); - stored_ccache = (cc_server_ccache_t*)ccache_node->data; - - if (stored_ccache == ccache) { - ccache_node->data = NULL; /*don't want list removal code free()ing ccache*/ - ccs_ccache_list_remove_element(ctx->ccaches, ccache_node); - ccs_ccache_list_prepend(ctx->ccaches, ccache, NULL); - break; - } - } - return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_GET_CREDS_VERSION(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_get_creds_version_t* header = (ccmsg_ccache_get_creds_version_t*)msg->header; - ccmsg_ccache_get_creds_version_resp_t* resp_header; - cc_server_ccache_t* ccache; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_get_creds_version_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - resp_header = (ccmsg_ccache_get_creds_version_resp_t*)malloc(sizeof(ccmsg_ccache_get_creds_version_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - resp_header->version = htonl(ccache->versions); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_get_creds_version_resp_t), auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_GET_NAME(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_get_name_t* header = (ccmsg_ccache_get_name_t*)msg->header; - ccmsg_ccache_get_name_resp_t* resp_header; - cc_server_ccache_t* ccache; - cc_uint32 header_len = msg->header_len; - cc_uint32 name_offset; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_get_name_resp_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (ccache == NULL) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - resp_header = (ccmsg_ccache_get_name_resp_t*)malloc(sizeof(ccmsg_ccache_get_name_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - code = cci_msg_new(ccmsg_ACK, resp_msg); - if (code != ccNoError) - return code; - - code = cci_msg_add_data_blob(*resp_msg, ccache->name, strlen(ccache->name) + 1, &name_offset); - if (code == 0) { - resp_header->name_len = htonl(strlen(ccache->name) + 1); - resp_header->name_offset = htonl(name_offset); - } - cci_msg_add_header(*resp_msg, resp_header, sizeof(ccmsg_ccache_get_name_resp_t)); - - return ccNoError; -} - -cc_int32 -ccop_CCACHE_GET_PRINCIPAL(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_get_principal_t* header = (ccmsg_ccache_get_principal_t*)msg->header; - ccmsg_ccache_get_principal_resp_t* resp_header; - cc_server_ccache_t* ccache; - char * principal; - cc_uint32 header_len = msg->header_len; - cc_uint32 principal_offset; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_get_principal_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - code = ccs_ccache_get_principal(ccache, ntohl(header->version), &principal); - if (code != ccNoError) - return ccs_serv_make_nack(code, auth_info, session_info, resp_msg); - - code = cci_msg_new(ccmsg_ACK, resp_msg); - if (code != ccNoError) - return code; - - resp_header = (ccmsg_ccache_get_principal_resp_t*)malloc(sizeof(ccmsg_ccache_get_principal_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - code = cci_msg_add_data_blob(*resp_msg, principal, strlen(principal) + 1, &principal_offset); - if (code == 0) { - resp_header->principal_len = htonl(strlen(principal) + 1); - resp_header->principal_offset = htonl(principal_offset); - } - cci_msg_add_header(*resp_msg, resp_header, sizeof(ccmsg_ccache_get_principal_resp_t)); - - return ccNoError; -} - -cc_int32 -ccop_CCACHE_SET_PRINCIPAL(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_set_principal_t* header = (ccmsg_ccache_set_principal_t*)msg->header; - cc_server_ccache_t* ccache; - char *principal; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_set_principal_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - code = cci_msg_retrieve_blob(msg, ntohl(header->principal_offset), ntohl(header->principal_len), &principal); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg); - - code = ccs_ccache_set_principal(ccache, ntohl(header->version), principal); - if (code != ccNoError) - return ccs_serv_make_nack(code, auth_info, session_info, resp_msg); - - return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_NEW_CREDS_ITERATOR( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - cc_server_ccache_t* ccache; - cc_credentials_iterate_t* creds_iterator; - ccmsg_ccache_creds_iterator_t* header = (ccmsg_ccache_creds_iterator_t*)msg->header; - ccmsg_ccache_creds_iterator_resp_t* resp_header; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_creds_iterator_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - code = ccs_ccache_new_iterator(ccache, &creds_iterator); - if (code != ccNoError) - return code; - - resp_header = (ccmsg_ccache_creds_iterator_resp_t*)malloc(sizeof(ccmsg_ccache_creds_iterator_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - resp_header->iterator = htonll((cc_handle) creds_iterator); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_creds_iterator_resp_t), auth_info, session_info, resp_msg); -} - - -static cc_int32 -ccs_credentials_union_release( cc_credentials_union * creds ) -{ - int i; - - switch (creds->version) { - case cc_credentials_v4: - free(creds->credentials.credentials_v4); - break; - case cc_credentials_v5: - if ( creds->credentials.credentials_v5->client ) - free(creds->credentials.credentials_v5->client); - if ( creds->credentials.credentials_v5->server ) - free(creds->credentials.credentials_v5->server ); - if ( creds->credentials.credentials_v5->keyblock.data ) - free(creds->credentials.credentials_v5->keyblock.data); - if ( creds->credentials.credentials_v5->ticket.data ) - free(creds->credentials.credentials_v5->ticket.data); - if ( creds->credentials.credentials_v5->second_ticket.data ) - free(creds->credentials.credentials_v5->second_ticket.data); - if ( creds->credentials.credentials_v5->addresses ) { - for ( i=0; creds->credentials.credentials_v5->addresses[i]; i++) { - if (creds->credentials.credentials_v5->addresses[i]->data) - free(creds->credentials.credentials_v5->addresses[i]->data); - } - free(creds->credentials.credentials_v5->addresses); - } - if ( creds->credentials.credentials_v5->authdata ) { - for ( i=0; creds->credentials.credentials_v5->authdata[i]; i++) { - if ( creds->credentials.credentials_v5->authdata[i]->data ) - free(creds->credentials.credentials_v5->authdata[i]->data); - } - free(creds->credentials.credentials_v5->authdata); - } - break; - default: - return ccErrBadCredentialsVersion; - } - return ccNoError; -} - -cc_int32 -ccop_CCACHE_STORE_CREDS(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_store_creds_t* header = (ccmsg_ccache_store_creds_t*)msg->header; - cc_server_ccache_t* ccache; - char *flat_creds; - cc_credentials_union *creds; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_store_creds_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - code = cci_msg_retrieve_blob(msg, ntohl(header->creds_offset), ntohl(header->creds_len), &flat_creds); - if (code != ccNoError) - return ccs_serv_make_nack(code, auth_info, session_info, resp_msg); - - creds = (cc_credentials_union *)malloc(sizeof(cc_credentials_union)); - if ( creds == NULL ) - return ccErrNoMem; - - switch ( creds->version ) { - case cc_credentials_v4: - code = cci_creds_v4_unmarshall(flat_creds, ntohl(header->creds_len), creds); - break; - case cc_credentials_v5: - code = cci_creds_v5_unmarshall(flat_creds, ntohl(header->creds_len), creds); - break; - default: - return ccs_serv_make_nack(ccErrBadCredentialsVersion, auth_info, session_info, resp_msg); - } - if (code != ccNoError) - return ccs_serv_make_nack(code, auth_info, session_info, resp_msg); - - code = ccs_ccache_store_creds(ccache, creds); - ccs_credentials_union_release(creds); - if (code != ccNoError) { - return ccs_serv_make_nack(code, auth_info, session_info, resp_msg); - } - - return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_REM_CREDS(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_rem_creds_t* header = (ccmsg_ccache_rem_creds_t*)msg->header; - cc_server_ccache_t* ccache; - cc_credentials_union *creds; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - if (header_len != sizeof(ccmsg_ccache_rem_creds_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - code = ccs_ccache_rem_creds(ccache, (const cc_credentials_union *)(ntohll(header->creds))); - if (code != ccNoError) - return ccs_serv_make_nack(code, auth_info, session_info, resp_msg); - - return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_LOCK( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - // TODO - return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_UNLOCK( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - // TODO - return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_MOVE( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - // TODO - return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg); -} - - -cc_int32 -ccop_CCACHE_GET_LAST_DEFAULT_TIME(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_get_last_default_time_t* header = (ccmsg_ccache_get_last_default_time_t*)msg->header; - ccmsg_ccache_get_last_default_time_resp_t* resp_header; - cc_server_ccache_t* ccache; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_get_last_default_time_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - resp_header = (ccmsg_ccache_get_last_default_time_resp_t*)malloc(sizeof(ccmsg_ccache_get_last_default_time_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - resp_header->last_default_time = htonll(ccache->last_default); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_get_last_default_time_resp_t), auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_GET_CHANGE_TIME( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_get_change_time_resp_t* resp_header; - ccmsg_ccache_get_change_time_t *header = (ccmsg_ccache_get_change_time_t *)msg->header; - cc_server_ccache_t* ccache = (cc_server_ccache_t *)header->ccache; - cc_uint32 header_len = msg->header_len; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_get_change_time_t)) { - return ccErrBadParam; - } - - resp_header = (ccmsg_ccache_get_change_time_resp_t*)malloc(sizeof(ccmsg_ccache_get_change_time_resp_t)); - if (resp_header == NULL) { - return ccErrNoMem; - } - - resp_header->time = htonll(ccache->changed); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_get_change_time_resp_t), auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_COMPARE(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_compare_t* header = (ccmsg_ccache_compare_t*)msg->header; - ccmsg_ccache_compare_resp_t* resp_header; - cc_server_ccache_t* ccache1, *ccache2; - cc_uint32 header_len = msg->header_len; - cc_uint32 is_equal; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_compare_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache1), &ccache1); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache2), &ccache2); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - resp_header = (ccmsg_ccache_compare_resp_t*)malloc(sizeof(ccmsg_ccache_compare_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - ccs_ccache_compare(ccache1, ccache2, &is_equal); - resp_header->is_equal = htonl(is_equal); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_compare_resp_t), auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_GET_KDC_TIME_OFFSET(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_get_kdc_time_offset_t* header = (ccmsg_ccache_get_kdc_time_offset_t*)msg->header; - ccmsg_ccache_get_kdc_time_offset_resp_t* resp_header; - cc_server_ccache_t* ccache; - cc_time64 offset; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_get_kdc_time_offset_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - // TODO How is the header->creds_version supposed to be used? - - code = ccs_ccache_get_kdc_time_offset(ccache, &offset); - if (code != ccNoError) - return ccs_serv_make_nack(code, auth_info, session_info, resp_msg); - - resp_header = (ccmsg_ccache_get_kdc_time_offset_resp_t*)malloc(sizeof(ccmsg_ccache_get_kdc_time_offset_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - resp_header->offset = htonll(offset); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_get_kdc_time_offset_resp_t), auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_SET_KDC_TIME_OFFSET(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_set_kdc_time_offset_t* header = (ccmsg_ccache_set_kdc_time_offset_t*)msg->header; - cc_server_ccache_t* ccache; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_set_kdc_time_offset_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - // TODO How is the header->creds_version supposed to be used? - - ccs_ccache_set_kdc_time_offset(ccache, htonll(header->offset)); - return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_CLEAR_KDC_TIME_OFFSET(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_clear_kdc_time_offset_t* header = (ccmsg_ccache_clear_kdc_time_offset_t*)msg->header; - cc_server_ccache_t* ccache; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_clear_kdc_time_offset_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - // TODO How is the header->creds_version supposed to be used? - - ccs_ccache_clear_kdc_time_offset(ccache); - return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_ITERATOR_RELEASE(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - cc_generic_list_node_t* gen_node; - ccmsg_ccache_iterator_release_t* header = (ccmsg_ccache_iterator_release_t*)msg->header; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_iterator_release_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_iterator_by_handle(ctx, ntohll(header->iterator), &gen_node); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg); - - code = cci_generic_list_remove_element(ctx->active_iterators, gen_node); - if (code != ccNoError) - return ccs_serv_make_nack(code, auth_info, session_info, resp_msg); - - return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_ITERATOR_CLONE( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - // TODO - return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CCACHE_ITERATOR_NEXT(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_ccache_iterator_release_t* header = (ccmsg_ccache_iterator_release_t*)msg->header; - ccmsg_ccache_iterator_next_resp_t* resp_header; - cc_generic_list_node_t* gen_node; - cc_ccache_iterate_t* ccache_iterator; - cc_ccache_list_node_t *ccache_node; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_ccache_iterator_next_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_iterator_by_handle(ctx, ntohll(header->iterator), &gen_node); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg); - - ccache_iterator = (cc_ccache_iterate_t*)gen_node->data; - if (ccs_ccache_iterate_has_next(ccache_iterator)) { - resp_header = (ccmsg_ccache_iterator_next_resp_t*)malloc(sizeof(ccmsg_ccache_iterator_next_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - code = ccs_ccache_iterate_next(ccache_iterator, &ccache_node); - if (code != ccNoError) - return ccs_serv_make_nack(code, auth_info, session_info, resp_msg); - - resp_header->ccache = htonll((cc_handle) ccache_node); - return ccs_serv_make_ack(resp_header, sizeof(ccmsg_ccache_iterator_next_resp_t), auth_info, session_info, resp_msg); - } else { - return ccs_serv_make_nack(ccIteratorEnd, auth_info, session_info, resp_msg); - } -} - -cc_int32 -ccop_CREDS_ITERATOR_RELEASE(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - cc_generic_list_node_t* gen_node; - cc_server_ccache_t* ccache; - ccmsg_creds_iterator_release_t* header = (ccmsg_creds_iterator_release_t*)msg->header; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_creds_iterator_release_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - code = ccs_serv_find_creds_iterator_by_handle(ccache, ntohll(header->iterator), &gen_node); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg); - - code = cci_generic_list_remove_element(ccache->active_iterators, gen_node); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg); - - return ccs_serv_make_ack(NULL, 0, auth_info, session_info, resp_msg); -} - -cc_int32 -ccop_CREDS_ITERATOR_CLONE( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - // TODO - return ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg); -} - - -cc_int32 -ccop_CREDS_ITERATOR_NEXT(cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - ccmsg_creds_iterator_next_t* header = (ccmsg_creds_iterator_next_t*)msg->header; - ccmsg_creds_iterator_next_resp_t* resp_header; - cc_credentials_iterate_t* creds_iterator; - cc_generic_list_node_t* gen_node; - cc_credentials_list_node_t* creds_node; - cc_server_ccache_t* ccache; - cc_server_credentials_t* stored_creds; - cc_credentials_union *creds_union; - cc_uint32 header_len = msg->header_len; - cc_int32 code; - - *resp_msg = 0; - - if (header_len != sizeof(ccmsg_creds_iterator_next_t)) - return ccErrBadParam; - - code = ccs_serv_find_ccache_by_handle(ctx, ntohll(header->ccache), &ccache); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrCCacheNotFound, auth_info, session_info, resp_msg); - - code = ccs_serv_find_creds_iterator_by_handle(ccache, ntohll(header->iterator), &gen_node); - if (code != ccNoError) - return ccs_serv_make_nack(ccErrBadParam, auth_info, session_info, resp_msg); - - creds_iterator = (cc_credentials_iterate_t*)gen_node->data; - if (ccs_credentials_iterate_has_next(creds_iterator)) { - code = cci_msg_new(ccmsg_ACK, resp_msg); - if (code != ccNoError) - return code; - - resp_header = (ccmsg_creds_iterator_next_resp_t*)malloc(sizeof(ccmsg_creds_iterator_next_resp_t)); - if (resp_header == NULL) - return ccErrNoMem; - - code = ccs_credentials_iterate_next(creds_iterator, &creds_node); - stored_creds = (cc_server_credentials_t*)creds_node->data; - creds_union = &stored_creds->creds; - - code = cci_msg_add_data_blob(*resp_msg, creds_union, sizeof(cc_credentials_union), &resp_header->creds_offset); - code = cci_msg_add_header(*resp_msg, resp_header, sizeof(ccmsg_creds_iterator_next_resp_t)); - } else { - ccs_serv_make_nack(ccIteratorEnd, auth_info, session_info, resp_msg); - } - return ccNoError; -} - -cc_int32 -ccop_CREDS_RELEASE( cc_server_context_t* ctx, - cc_auth_info_t* auth_info, - cc_session_info_t* session_info, - cc_msg_t *msg, cc_msg_t **resp_msg) -{ - - ccs_serv_make_nack(ccErrNotImplemented, auth_info, session_info, resp_msg); - return ccNoError; -} -- cgit