Path: blob/main/crypto/krb5/src/ccapi/lib/ccapi_credentials.c
39536 views
/* ccapi/lib/ccapi_credentials.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.h"2627#include "ccapi_string.h"2829/* ------------------------------------------------------------------------ */3031typedef struct cci_credentials_d {32cc_credentials_union *data;33cc_credentials_f *functions;34#if TARGET_OS_MAC35cc_credentials_f *vector_functions;36#endif37cci_identifier_t identifier;38} *cci_credentials_t;3940/* ------------------------------------------------------------------------ */4142struct cci_credentials_d cci_credentials_initializer = {43NULL,44NULL45VECTOR_FUNCTIONS_INITIALIZER,46NULL47};4849cc_credentials_f cci_credentials_f_initializer = {50ccapi_credentials_release,51ccapi_credentials_compare52};5354cc_credentials_union cci_credentials_union_initializer = {550,56{ NULL }57};5859/* ------------------------------------------------------------------------ */6061cc_int32 cci_credentials_read (cc_credentials_t *out_credentials,62k5_ipc_stream in_stream)63{64cc_int32 err = ccNoError;65cci_credentials_t credentials = NULL;6667if (!out_credentials) { err = cci_check_error (ccErrBadParam); }68if (!in_stream ) { err = cci_check_error (ccErrBadParam); }6970if (!err) {71credentials = malloc (sizeof (*credentials));72if (credentials) {73*credentials = cci_credentials_initializer;74} else {75err = cci_check_error (ccErrNoMem);76}77}7879if (!err) {80credentials->functions = malloc (sizeof (*credentials->functions));81if (credentials->functions) {82*credentials->functions = cci_credentials_f_initializer;83} else {84err = cci_check_error (ccErrNoMem);85}86}8788if (!err) {89err = cci_identifier_read (&credentials->identifier, in_stream);90}9192if (!err) {93err = cci_credentials_union_read (&credentials->data, in_stream);94}9596if (!err) {97*out_credentials = (cc_credentials_t) credentials;98credentials = NULL; /* take ownership */99}100101if (credentials) { ccapi_credentials_release ((cc_credentials_t) credentials); }102103return cci_check_error (err);104}105106/* ------------------------------------------------------------------------ */107108cc_int32 cci_credentials_write (cc_credentials_t in_credentials,109k5_ipc_stream in_stream)110{111cc_int32 err = ccNoError;112cci_credentials_t credentials = (cci_credentials_t) in_credentials;113114if (!in_credentials) { err = cci_check_error (ccErrBadParam); }115if (!in_stream ) { err = cci_check_error (ccErrBadParam); }116117if (!err) {118err = cci_identifier_write (credentials->identifier, in_stream);119}120121return cci_check_error (err);122}123124/* ------------------------------------------------------------------------ */125126cc_int32 ccapi_credentials_compare (cc_credentials_t in_credentials,127cc_credentials_t in_compare_to_credentials,128cc_uint32 *out_equal)129{130cc_int32 err = ccNoError;131cci_credentials_t credentials = (cci_credentials_t) in_credentials;132cci_credentials_t compare_to_credentials = (cci_credentials_t) in_compare_to_credentials;133134if (!in_credentials ) { err = cci_check_error (ccErrBadParam); }135if (!in_compare_to_credentials) { err = cci_check_error (ccErrBadParam); }136if (!out_equal ) { err = cci_check_error (ccErrBadParam); }137138if (!err) {139err = cci_identifier_compare (credentials->identifier,140compare_to_credentials->identifier,141out_equal);142}143144return cci_check_error (err);145}146147/* ------------------------------------------------------------------------ */148149cc_int32 ccapi_credentials_release (cc_credentials_t io_credentials)150{151cc_int32 err = ccNoError;152cci_credentials_t credentials = (cci_credentials_t) io_credentials;153154if (!io_credentials) { err = ccErrBadParam; }155156if (!err) {157cci_credentials_union_release (credentials->data);158free ((char *) credentials->functions);159cci_identifier_release (credentials->identifier);160free (credentials);161}162163return err;164}165166167