Path: blob/main/crypto/krb5/src/ccapi/lib/ccapi_credentials_iterator.c
39536 views
/* ccapi/lib/ccapi_credentials_iterator.c */1/*2* Copyright 2006 Massachusetts Institute of Technology.3* All Rights Reserved.4*5* Export of this software from the United States of America may6* require a specific license from the United States Government.7* It is the responsibility of any person or organization contemplating8* export to obtain such a license before exporting.9*10* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and11* distribute this software and its documentation for any purpose and12* without fee is hereby granted, provided that the above copyright13* notice appear in all copies and that both that copyright notice and14* this permission notice appear in supporting documentation, and that15* the name of M.I.T. not be used in advertising or publicity pertaining16* to distribution of the software without specific, written prior17* permission. Furthermore if you modify this software you must label18* your software as modified software and not distribute it in such a19* fashion that it might be confused with the original M.I.T. software.20* M.I.T. makes no representations about the suitability of21* this software for any purpose. It is provided "as is" without express22* or implied warranty.23*/2425#include "ccapi_credentials_iterator.h"26#include "ccapi_credentials.h"27#include "ccapi_ipc.h"2829/* ------------------------------------------------------------------------ */3031typedef struct cci_credentials_iterator_d {32cc_credentials_iterator_f *functions;33#if TARGET_OS_MAC34cc_credentials_iterator_f *vector_functions;35#endif36cci_identifier_t identifier;37cc_uint32 compat_version;38} *cci_credentials_iterator_t;3940/* ------------------------------------------------------------------------ */4142struct cci_credentials_iterator_d cci_credentials_iterator_initializer = {43NULL44VECTOR_FUNCTIONS_INITIALIZER,45NULL,46047};4849cc_credentials_iterator_f cci_credentials_iterator_f_initializer = {50ccapi_credentials_iterator_release,51ccapi_credentials_iterator_next,52ccapi_credentials_iterator_clone53};5455/* ------------------------------------------------------------------------ */5657cc_int32 cci_credentials_iterator_new (cc_credentials_iterator_t *out_credentials_iterator,58cci_identifier_t in_identifier)59{60cc_int32 err = ccNoError;61cci_credentials_iterator_t credentials_iterator = NULL;6263if (!out_credentials_iterator) { err = cci_check_error (ccErrBadParam); }64if (!in_identifier ) { err = cci_check_error (ccErrBadParam); }6566if (!err) {67credentials_iterator = malloc (sizeof (*credentials_iterator));68if (credentials_iterator) {69*credentials_iterator = cci_credentials_iterator_initializer;70} else {71err = cci_check_error (ccErrNoMem);72}73}7475if (!err) {76credentials_iterator->functions = malloc (sizeof (*credentials_iterator->functions));77if (credentials_iterator->functions) {78*credentials_iterator->functions = cci_credentials_iterator_f_initializer;79} else {80err = cci_check_error (ccErrNoMem);81}82}8384if (!err) {85err = cci_identifier_copy (&credentials_iterator->identifier, in_identifier);86}8788if (!err) {89*out_credentials_iterator = (cc_credentials_iterator_t) credentials_iterator;90credentials_iterator = NULL; /* take ownership */91}9293if (credentials_iterator) { ccapi_credentials_iterator_release ((cc_credentials_iterator_t) credentials_iterator); }9495return cci_check_error (err);96}9798/* ------------------------------------------------------------------------ */99100cc_int32 cci_credentials_iterator_write (cc_credentials_iterator_t in_credentials_iterator,101k5_ipc_stream in_stream)102{103cc_int32 err = ccNoError;104cci_credentials_iterator_t credentials_iterator = (cci_credentials_iterator_t) in_credentials_iterator;105106if (!in_credentials_iterator) { err = cci_check_error (ccErrBadParam); }107if (!in_stream ) { err = cci_check_error (ccErrBadParam); }108109if (!err) {110err = cci_identifier_write (credentials_iterator->identifier, in_stream);111}112113return cci_check_error (err);114}115116/* ------------------------------------------------------------------------ */117118cc_int32 ccapi_credentials_iterator_release (cc_credentials_iterator_t io_credentials_iterator)119{120cc_int32 err = ccNoError;121cci_credentials_iterator_t credentials_iterator = (cci_credentials_iterator_t) io_credentials_iterator;122123if (!io_credentials_iterator) { err = ccErrBadParam; }124125if (!err) {126err = cci_ipc_send (cci_credentials_iterator_release_msg_id,127credentials_iterator->identifier,128NULL,129NULL);130if (err) {131cci_debug_printf ("%s: cci_ipc_send failed with error %d",132__FUNCTION__, err);133err = ccNoError;134}135}136137if (!err) {138free ((char *) credentials_iterator->functions);139cci_identifier_release (credentials_iterator->identifier);140free (credentials_iterator);141}142143return err;144}145146/* ------------------------------------------------------------------------ */147148cc_int32 ccapi_credentials_iterator_next (cc_credentials_iterator_t in_credentials_iterator,149cc_credentials_t *out_credentials)150{151cc_int32 err = ccNoError;152cci_credentials_iterator_t credentials_iterator = (cci_credentials_iterator_t) in_credentials_iterator;153k5_ipc_stream reply = NULL;154155if (!in_credentials_iterator) { err = cci_check_error (ccErrBadParam); }156if (!out_credentials ) { err = cci_check_error (ccErrBadParam); }157158if (!err) {159err = cci_ipc_send (cci_credentials_iterator_next_msg_id,160credentials_iterator->identifier,161NULL,162&reply);163}164165if (!err) {166err = cci_credentials_read (out_credentials, reply);167}168169krb5int_ipc_stream_release (reply);170171return cci_check_error (err);172}173174/* ------------------------------------------------------------------------ */175176cc_int32 ccapi_credentials_iterator_clone (cc_credentials_iterator_t in_credentials_iterator,177cc_credentials_iterator_t *out_credentials_iterator)178{179cc_int32 err = ccNoError;180cci_credentials_iterator_t credentials_iterator = (cci_credentials_iterator_t) in_credentials_iterator;181k5_ipc_stream reply = NULL;182cci_identifier_t identifier = NULL;183184if (!in_credentials_iterator ) { err = cci_check_error (ccErrBadParam); }185if (!out_credentials_iterator) { err = cci_check_error (ccErrBadParam); }186187if (!err) {188err = cci_ipc_send (cci_credentials_iterator_next_msg_id,189credentials_iterator->identifier,190NULL,191&reply);192}193194if (!err) {195err = cci_identifier_read (&identifier, reply);196}197198if (!err) {199err = cci_credentials_iterator_new (out_credentials_iterator, identifier);200}201202krb5int_ipc_stream_release (reply);203cci_identifier_release (identifier);204205return cci_check_error (err);206}207208#ifdef TARGET_OS_MAC209#pragma mark -210#endif211212/* ------------------------------------------------------------------------ */213214cc_int32 cci_credentials_iterator_get_compat_version (cc_credentials_iterator_t in_credentials_iterator,215cc_uint32 *out_compat_version)216{217cc_int32 err = ccNoError;218cci_credentials_iterator_t credentials_iterator = (cci_credentials_iterator_t) in_credentials_iterator;219220if (!in_credentials_iterator) { err = cci_check_error (ccErrBadParam); }221if (!out_compat_version ) { err = cci_check_error (ccErrBadParam); }222223if (!err) {224*out_compat_version = credentials_iterator->compat_version;225}226227return cci_check_error (err);228}229230/* ------------------------------------------------------------------------ */231232cc_int32 cci_credentials_iterator_set_compat_version (cc_credentials_iterator_t io_credentials_iterator,233cc_uint32 in_compat_version)234{235cc_int32 err = ccNoError;236cci_credentials_iterator_t credentials_iterator = (cci_credentials_iterator_t) io_credentials_iterator;237238if (!io_credentials_iterator) { err = cci_check_error (ccErrBadParam); }239240if (!err) {241credentials_iterator->compat_version = in_compat_version;242}243244return cci_check_error (err);245}246247248