|
Packit |
fd8b60 |
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
Packit |
fd8b60 |
/* util/support/ipc_stream.c */
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Copyright 2006, 2007, 2009 Massachusetts Institute of Technology.
|
|
Packit |
fd8b60 |
* All Rights Reserved.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* Export of this software from the United States of America may
|
|
Packit |
fd8b60 |
* require a specific license from the United States Government.
|
|
Packit |
fd8b60 |
* It is the responsibility of any person or organization contemplating
|
|
Packit |
fd8b60 |
* export to obtain such a license before exporting.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
|
|
Packit |
fd8b60 |
* distribute this software and its documentation for any purpose and
|
|
Packit |
fd8b60 |
* without fee is hereby granted, provided that the above copyright
|
|
Packit |
fd8b60 |
* notice appear in all copies and that both that copyright notice and
|
|
Packit |
fd8b60 |
* this permission notice appear in supporting documentation, and that
|
|
Packit |
fd8b60 |
* the name of M.I.T. not be used in advertising or publicity pertaining
|
|
Packit |
fd8b60 |
* to distribution of the software without specific, written prior
|
|
Packit |
fd8b60 |
* permission. Furthermore if you modify this software you must label
|
|
Packit |
fd8b60 |
* your software as modified software and not distribute it in such a
|
|
Packit |
fd8b60 |
* fashion that it might be confused with the original M.I.T. software.
|
|
Packit |
fd8b60 |
* M.I.T. makes no representations about the suitability of
|
|
Packit |
fd8b60 |
* this software for any purpose. It is provided "as is" without express
|
|
Packit |
fd8b60 |
* or implied warranty.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#ifdef _WIN32
|
|
Packit |
fd8b60 |
#include <winsock2.h>
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
#include "k5-ipc_stream.h"
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#if !defined(htonll)
|
|
Packit |
fd8b60 |
#define htonll(x) k5_htonll(x)
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#if !defined(ntohll)
|
|
Packit |
fd8b60 |
#define ntohll(x) k5_ntohll(x)
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Add debugging later */
|
|
Packit |
fd8b60 |
#define k5_check_error(x) (x)
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
struct k5_ipc_stream_s {
|
|
Packit |
fd8b60 |
char *data;
|
|
Packit |
fd8b60 |
uint64_t size;
|
|
Packit |
fd8b60 |
uint64_t max_size;
|
|
Packit |
fd8b60 |
};
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static const struct k5_ipc_stream_s k5_ipc_stream_initializer = { NULL, 0, 0 };
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#define K5_IPC_STREAM_SIZE_INCREMENT 128
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
static uint32_t krb5int_ipc_stream_reallocate (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
uint64_t in_new_size)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
uint64_t new_max_size = 0;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
uint64_t old_max_size = io_stream->max_size;
|
|
Packit |
fd8b60 |
new_max_size = io_stream->max_size;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (in_new_size > old_max_size) {
|
|
Packit |
fd8b60 |
/* Expand the stream */
|
|
Packit |
fd8b60 |
while (in_new_size > new_max_size) {
|
|
Packit |
fd8b60 |
new_max_size += K5_IPC_STREAM_SIZE_INCREMENT;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
} else if ((in_new_size + K5_IPC_STREAM_SIZE_INCREMENT) < old_max_size) {
|
|
Packit |
fd8b60 |
/* Shrink the array, but never drop below K5_IPC_STREAM_SIZE_INCREMENT */
|
|
Packit |
fd8b60 |
while ((in_new_size + K5_IPC_STREAM_SIZE_INCREMENT) < new_max_size &&
|
|
Packit |
fd8b60 |
(new_max_size > K5_IPC_STREAM_SIZE_INCREMENT)) {
|
|
Packit |
fd8b60 |
new_max_size -= K5_IPC_STREAM_SIZE_INCREMENT;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err && new_max_size != io_stream->max_size) {
|
|
Packit |
fd8b60 |
char *data = io_stream->data;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!data) {
|
|
Packit |
fd8b60 |
data = malloc (new_max_size * sizeof (*data));
|
|
Packit |
fd8b60 |
} else {
|
|
Packit |
fd8b60 |
data = realloc (data, new_max_size * sizeof (*data));
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (data) {
|
|
Packit |
fd8b60 |
io_stream->data = data;
|
|
Packit |
fd8b60 |
io_stream->max_size = new_max_size;
|
|
Packit |
fd8b60 |
} else {
|
|
Packit |
fd8b60 |
err = k5_check_error (ENOMEM);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
int32_t krb5int_ipc_stream_new (k5_ipc_stream *out_stream)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
k5_ipc_stream stream = NULL;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!out_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
stream = malloc (sizeof (*stream));
|
|
Packit |
fd8b60 |
if (stream) {
|
|
Packit |
fd8b60 |
*stream = k5_ipc_stream_initializer;
|
|
Packit |
fd8b60 |
} else {
|
|
Packit |
fd8b60 |
err = k5_check_error (ENOMEM);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
*out_stream = stream;
|
|
Packit |
fd8b60 |
stream = NULL;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
krb5int_ipc_stream_release (stream);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_release (k5_ipc_stream io_stream)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err && io_stream) {
|
|
Packit |
fd8b60 |
free (io_stream->data);
|
|
Packit |
fd8b60 |
free (io_stream);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return err;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint64_t krb5int_ipc_stream_size (k5_ipc_stream in_stream)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
return in_stream ? in_stream->size : 0;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
const char *krb5int_ipc_stream_data (k5_ipc_stream in_stream)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
return in_stream ? in_stream->data : NULL;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#ifdef TARGET_OS_MAC
|
|
Packit |
fd8b60 |
#pragma mark -
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_read (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
void *io_data,
|
|
Packit |
fd8b60 |
uint64_t in_size)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
if (!io_data ) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
if (in_size > io_stream->size) {
|
|
Packit |
fd8b60 |
err = k5_check_error (EINVAL);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
memcpy (io_data, io_stream->data, in_size);
|
|
Packit |
fd8b60 |
memmove (io_stream->data, &io_stream->data[in_size],
|
|
Packit |
fd8b60 |
io_stream->size - in_size);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_reallocate (io_stream, io_stream->size - in_size);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
io_stream->size -= in_size;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_write (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
const void *in_data,
|
|
Packit |
fd8b60 |
uint64_t in_size)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
if (!in_data ) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
/* Security check: Do not let the caller overflow the length */
|
|
Packit |
fd8b60 |
if (in_size > (UINT64_MAX - io_stream->size)) {
|
|
Packit |
fd8b60 |
err = k5_check_error (EINVAL);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_reallocate (io_stream, io_stream->size + in_size);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
memcpy (&io_stream->data[io_stream->size], in_data, in_size);
|
|
Packit |
fd8b60 |
io_stream->size += in_size;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#ifdef TARGET_OS_MAC
|
|
Packit |
fd8b60 |
#pragma mark -
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
void krb5int_ipc_stream_free_string (char *in_string)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
free (in_string);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_read_string (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
char **out_string)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
uint32_t length = 0;
|
|
Packit |
fd8b60 |
char *string = NULL;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream ) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
if (!out_string) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_read_uint32 (io_stream, &length);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
string = malloc (length);
|
|
Packit |
fd8b60 |
if (!string) { err = k5_check_error (ENOMEM); }
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_read (io_stream, string, length);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
*out_string = string;
|
|
Packit |
fd8b60 |
string = NULL;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
free (string);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_write_string (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
const char *in_string)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
uint32_t length = 0;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
if (!in_string) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
length = strlen (in_string) + 1;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_write_uint32 (io_stream, length);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_write (io_stream, in_string, length);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#ifdef TARGET_OS_MAC
|
|
Packit |
fd8b60 |
#pragma mark -
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_read_int32 (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
int32_t *out_int32)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
int32_t int32 = 0;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
if (!out_int32) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_read (io_stream, &int32, sizeof (int32));
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
*out_int32 = ntohl (int32);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_write_int32 (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
int32_t in_int32)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
int32_t int32 = htonl (in_int32);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_write (io_stream, &int32, sizeof (int32));
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#ifdef TARGET_OS_MAC
|
|
Packit |
fd8b60 |
#pragma mark -
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_read_uint32 (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
uint32_t *out_uint32)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
uint32_t uint32 = 0;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
if (!out_uint32) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_read (io_stream, &uint32, sizeof (uint32));
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
*out_uint32 = ntohl (uint32);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_write_uint32 (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
uint32_t in_uint32)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
int32_t uint32 = htonl (in_uint32);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_write (io_stream, &uint32, sizeof (uint32));
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#ifdef TARGET_OS_MAC
|
|
Packit |
fd8b60 |
#pragma mark -
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_read_int64 (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
int64_t *out_int64)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
uint64_t int64 = 0;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
if (!out_int64) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_read (io_stream, &int64, sizeof (int64));
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
*out_int64 = ntohll (int64);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_write_int64 (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
int64_t in_int64)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
int64_t int64 = htonll (in_int64);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_write (io_stream, &int64, sizeof (int64));
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#ifdef TARGET_OS_MAC
|
|
Packit |
fd8b60 |
#pragma mark -
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_read_uint64 (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
uint64_t *out_uint64)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
uint64_t uint64 = 0;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
if (!out_uint64) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_read (io_stream, &uint64, sizeof (uint64));
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
*out_uint64 = ntohll (uint64);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* ------------------------------------------------------------------------ */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
uint32_t krb5int_ipc_stream_write_uint64 (k5_ipc_stream io_stream,
|
|
Packit |
fd8b60 |
uint64_t in_uint64)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
int32_t err = 0;
|
|
Packit |
fd8b60 |
int64_t uint64 = htonll (in_uint64);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!io_stream) { err = k5_check_error (EINVAL); }
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (!err) {
|
|
Packit |
fd8b60 |
err = krb5int_ipc_stream_write (io_stream, &uint64, sizeof (uint64));
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
return k5_check_error (err);
|
|
Packit |
fd8b60 |
}
|