static cc_int32 test_obj_new (ccs_object_t *out_object, char *in_string) { cc_int32 err = 0; test_object_t object = NULL; if (!out_object) { err = ccErrBadParam; } if (!err) { object = malloc (sizeof (*object)); if (object) { *object = test_object_initializer; } else { err = ccErrNoMem; } } if (!err) { err = ccs_server_new_identifier (&object->identifier); } if (!err) { object->string = strdup (in_string); if (!object->string) { err = ccErrNoMem; } } if (!err) { *out_object = (ccs_object_t) object; object = NULL; } test_obj_release ((ccs_object_t) object); return err; }
static cc_int32 ccs_list_iterator_new (ccs_list_iterator_t *out_list_iterator, ccs_list_t io_list, ccs_pipe_t in_client_pipe) { cc_int32 err = ccNoError; ccs_list_iterator_t list_iterator = NULL; if (!out_list_iterator) { err = cci_check_error (ccErrBadParam); } if (!io_list ) { err = cci_check_error (ccErrBadParam); } /* client_pipe may be NULL if the iterator exists for internal server use */ if (!err) { list_iterator = malloc (sizeof (*list_iterator)); if (list_iterator) { *list_iterator = ccs_list_iterator_initializer; } else { err = cci_check_error (ccErrNoMem); } } if (!err) { err = ccs_server_new_identifier (&list_iterator->identifier); } if (!err) { list_iterator->list = io_list; list_iterator->current = 0; err = cci_array_insert (io_list->iterators, (cci_array_object_t) list_iterator, cci_array_count (io_list->iterators)); } if (!err && ccs_pipe_valid (in_client_pipe)) { ccs_client_t client = NULL; err = ccs_pipe_copy (&list_iterator->client_pipe, in_client_pipe); if (!err) { err = ccs_server_client_for_pipe (in_client_pipe, &client); } if (!err) { err = ccs_client_add_iterator (client, list_iterator); } } if (!err) { *out_list_iterator = list_iterator; list_iterator = NULL; } ccs_list_iterator_release (list_iterator); return cci_check_error (err); }
cc_int32 ccs_credentials_new (ccs_credentials_t *out_credentials, k5_ipc_stream in_stream, cc_uint32 in_ccache_version, ccs_credentials_list_t io_credentials_list) { cc_int32 err = ccNoError; ccs_credentials_t credentials = NULL; if (!out_credentials) { err = cci_check_error (ccErrBadParam); } if (!in_stream ) { err = cci_check_error (ccErrBadParam); } if (!err) { credentials = malloc (sizeof (*credentials)); if (credentials) { *credentials = ccs_credentials_initializer; } else { err = cci_check_error (ccErrNoMem); } } if (!err) { err = cci_credentials_union_read (&credentials->cred_union, in_stream); } if (!err && !(credentials->cred_union->version & in_ccache_version)) { /* ccache does not have a principal set for this credentials version */ err = cci_check_error (ccErrBadCredentialsVersion); } if (!err) { err = ccs_server_new_identifier (&credentials->identifier); } if (!err) { err = ccs_credentials_list_add (io_credentials_list, credentials); } if (!err) { /* XXX maybe this should be a Kerberos Plugin instead ? */ cc_uint64 num; if (ccs_credentials_list_count(io_credentials_list, &num) == ccNoError && num == 1) system("launchctl start com.apple.Kerberos.renew.plist"); *out_credentials = credentials; credentials = NULL; } ccs_credentials_release (credentials); return cci_check_error (err); }
cc_int32 ccs_cache_collection_new (ccs_cache_collection_t *out_cache_collection) { cc_int32 err = ccNoError; ccs_cache_collection_t cache_collection = NULL; if (!out_cache_collection) { err = cci_check_error (ccErrBadParam); } if (!err) { cache_collection = malloc (sizeof (*cache_collection)); if (cache_collection) { *cache_collection = ccs_cache_collection_initializer; } else { err = cci_check_error (ccErrNoMem); } } if (!err) { err = ccs_server_new_identifier (&cache_collection->identifier); } if (!err) { err = ccs_lock_state_new (&cache_collection->lock_state, ccErrInvalidContext, ccErrContextLocked, ccErrContextUnlocked); } if (!err) { err = ccs_ccache_list_new (&cache_collection->ccaches); } if (!err) { err = ccs_callback_array_new (&cache_collection->change_callbacks); } if (!err) { err = ccs_cache_collection_changed (cache_collection); } if (!err) { *out_cache_collection = cache_collection; cache_collection = NULL; } ccs_cache_collection_release (cache_collection); return cci_check_error (err); }
static cc_int32 ccs_list_iterator_new (ccs_list_iterator_t *out_list_iterator, ccs_list_t io_list) { cc_int32 err = ccNoError; ccs_list_iterator_t list_iterator = NULL; if (!out_list_iterator) { err = cci_check_error (ccErrBadParam); } if (!io_list ) { err = cci_check_error (ccErrBadParam); } if (!err) { list_iterator = malloc (sizeof (*list_iterator)); if (list_iterator) { *list_iterator = ccs_list_iterator_initializer; } else { err = cci_check_error (ccErrNoMem); } } if (!err) { err = ccs_server_new_identifier (&list_iterator->identifier); } if (!err) { list_iterator->list = io_list; list_iterator->current = 0; err = cci_array_insert (io_list->iterators, list_iterator, cci_array_count (io_list->iterators)); } if (!err) { *out_list_iterator = list_iterator; list_iterator = NULL; } ccs_list_iterator_release (list_iterator); return cci_check_error (err); }
cc_int32 ccs_ccache_new (ccs_ccache_t *out_ccache, cc_uint32 in_creds_version, const char *in_name, const char *in_principal, ccs_ccache_list_t io_ccache_list) { cc_int32 err = ccNoError; ccs_ccache_t ccache = NULL; if (!out_ccache ) { err = cci_check_error (ccErrBadParam); } if (!in_name ) { err = cci_check_error (ccErrBadParam); } if (!in_principal) { err = cci_check_error (ccErrBadParam); } if (!err) { ccache = malloc (sizeof (*ccache)); if (ccache) { *ccache = ccs_ccache_initializer; } else { err = cci_check_error (ccErrNoMem); } } if (!err) { err = ccs_server_new_identifier (&ccache->identifier); } if (!err) { err = ccs_lock_state_new (&ccache->lock_state, ccErrInvalidCCache, ccErrCCacheLocked, ccErrCCacheUnlocked); } if (!err) { ccache->name = strdup (in_name); if (!ccache->name) { err = cci_check_error (ccErrNoMem); } } if (!err) { ccache->creds_version = in_creds_version; if (ccache->creds_version == cc_credentials_v5) { ccache->v5_principal = strdup (in_principal); if (!ccache->v5_principal) { err = cci_check_error (ccErrNoMem); } } else { err = cci_check_error (ccErrBadCredentialsVersion); } } if (!err) { err = ccs_credentials_list_new (&ccache->credentials); } if (!err) { err = ccs_callback_array_new (&ccache->change_callbacks); } if (!err) { cc_uint64 now = time (NULL); cc_uint64 count = 0; err = ccs_ccache_list_count (io_ccache_list, &count); if (!err) { /* first cache is default */ ccache->last_default_time = (count == 0) ? now : 0; cci_debug_printf ("%s ccache->last_default_time is %d.", __FUNCTION__, ccache->last_default_time); ccache->last_changed_time = now; } } if (!err) { /* Add self to the list of ccaches */ err = ccs_ccache_list_add (io_ccache_list, ccache); } if (!err) { *out_ccache = ccache; ccache = NULL; } ccs_ccache_release (ccache); return cci_check_error (err); }