Path: blob/main/crypto/krb5/src/ccapi/common/cci_message.c
39537 views
/* ccapi/common/cci_message.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 "cci_common.h"2627/* ------------------------------------------------------------------------ */2829cc_int32 cci_message_invalid_object_err (enum cci_msg_id_t in_request_name)30{31cc_int32 err = ccNoError;3233if (in_request_name > cci_context_first_msg_id &&34in_request_name < cci_context_last_msg_id) {35err = ccErrInvalidContext;3637} else if (in_request_name > cci_ccache_first_msg_id &&38in_request_name < cci_ccache_last_msg_id) {39err = ccErrInvalidCCache;4041} else if (in_request_name > cci_ccache_iterator_first_msg_id &&42in_request_name < cci_ccache_iterator_last_msg_id) {43err = ccErrInvalidCCacheIterator;4445} else if (in_request_name > cci_credentials_iterator_first_msg_id &&46in_request_name < cci_credentials_iterator_last_msg_id) {47err = ccErrInvalidCredentialsIterator;4849} else {50err = ccErrBadInternalMessage;51}5253return cci_check_error (err);54}5556/* ------------------------------------------------------------------------ */5758cc_int32 cci_message_new_request_header (k5_ipc_stream *out_request,59enum cci_msg_id_t in_request_name,60cci_identifier_t in_identifier)61{62cc_int32 err = ccNoError;63k5_ipc_stream request = NULL;6465if (!out_request) { err = cci_check_error (ccErrBadParam); }6667if (!err) {68err = krb5int_ipc_stream_new (&request);69}7071if (!err) {72err = krb5int_ipc_stream_write_uint32 (request, in_request_name);73}7475if (!err) {76err = cci_identifier_write (in_identifier, request);77}7879if (!err) {80*out_request = request;81request = NULL;82}8384krb5int_ipc_stream_release (request);8586return cci_check_error (err);87}8889/* ------------------------------------------------------------------------ */9091cc_int32 cci_message_read_request_header (k5_ipc_stream in_request,92enum cci_msg_id_t *out_request_name,93cci_identifier_t *out_identifier)94{95cc_int32 err = ccNoError;96cc_uint32 request_name;97cci_identifier_t identifier = NULL;9899if (!in_request ) { err = cci_check_error (ccErrBadParam); }100if (!out_request_name) { err = cci_check_error (ccErrBadParam); }101if (!out_identifier ) { err = cci_check_error (ccErrBadParam); }102103if (!err) {104err = krb5int_ipc_stream_read_uint32 (in_request, &request_name);105}106107if (!err) {108err = cci_identifier_read (&identifier, in_request);109}110111if (!err) {112*out_request_name = request_name;113*out_identifier = identifier;114identifier = NULL; /* take ownership */115}116117cci_identifier_release (identifier);118119return cci_check_error (err);120}121122/* ------------------------------------------------------------------------ */123124cc_int32 cci_message_new_reply_header (k5_ipc_stream *out_reply,125cc_int32 in_error)126{127cc_int32 err = ccNoError;128k5_ipc_stream reply = NULL;129130if (!out_reply) { err = cci_check_error (ccErrBadParam); }131132if (!err) {133err = krb5int_ipc_stream_new (&reply);134}135136if (!err) {137err = krb5int_ipc_stream_write_int32 (reply, in_error);138}139140if (!err) {141*out_reply = reply;142reply = NULL;143}144145krb5int_ipc_stream_release (reply);146147return cci_check_error (err);148}149150/* ------------------------------------------------------------------------ */151152cc_int32 cci_message_read_reply_header (k5_ipc_stream in_reply,153cc_int32 *out_reply_error)154{155cc_int32 err = ccNoError;156cc_int32 reply_err = 0;157158if (!in_reply ) { err = cci_check_error (ccErrBadParam); }159if (!out_reply_error) { err = cci_check_error (ccErrBadParam); }160161if (!err) {162err = krb5int_ipc_stream_read_int32 (in_reply, &reply_err);163}164165if (!err) {166*out_reply_error = reply_err;167}168169return cci_check_error (err);170}171172#ifdef TARGET_OS_MAC173#pragma mark -174#endif175176/* ------------------------------------------------------------------------ */177178uint32_t krb5int_ipc_stream_read_time (k5_ipc_stream io_stream,179cc_time_t *out_time)180{181int32_t err = 0;182int64_t t = 0;183184if (!io_stream) { err = cci_check_error (ccErrBadParam); }185if (!out_time ) { err = cci_check_error (ccErrBadParam); }186187if (!err) {188err = krb5int_ipc_stream_read_int64 (io_stream, &t);189}190191if (!err) {192*out_time = t;193}194195return cci_check_error (err);196}197198/* ------------------------------------------------------------------------ */199200uint32_t krb5int_ipc_stream_write_time (k5_ipc_stream io_stream,201cc_time_t in_time)202{203int32_t err = 0;204205if (!io_stream) { err = cci_check_error (ccErrBadParam); }206207if (!err) {208err = krb5int_ipc_stream_write_int64 (io_stream, in_time);209}210211return cci_check_error (err);212}213214215