/*
*
* Copyright 1995 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
*/
/*
* ser_ctx.c - Routines to deal with serializing the krb5_context and
* krb5_os_context structures.
*/
#include "k5-int.h"
/*
* Routines to deal with externalizing the krb5_context:
* krb5_context_size();
* krb5_context_externalize();
* krb5_context_internalize();
*
* Routines to deal with externalizing the krb5_os_context:
* krb5_oscontext_size();
* krb5_oscontext_externalize();
* krb5_oscontext_internalize();
*
* Routines to deal with externalizing the profile.
* profile_ser_size();
* profile_ser_externalize();
* profile_ser_internalize();
*
* Interface to initialize serializing of krb5_context and krb5_os_context:
* krb5_ser_context_init();
*/
static krb5_error_code krb5_context_size
#ifndef _KERNEL
#endif
/* Local data */
KV5M_CONTEXT, /* Type */
krb5_context_size, /* Sizer routine */
krb5_context_externalize, /* Externalize routine */
krb5_context_internalize /* Internalize routine */
};
KV5M_OS_CONTEXT, /* Type */
krb5_oscontext_size, /* Sizer routine */
krb5_oscontext_externalize, /* Externalize routine */
krb5_oscontext_internalize /* Internalize routine */
};
#ifndef _KERNEL
PROF_MAGIC_PROFILE, /* Type */
profile_ser_size, /* Sizer routine */
profile_ser_externalize, /* Externalize routine */
profile_ser_internalize /* Internalize routine */
};
#endif
/*
* krb5_context_size() - Determine the size required to externalize the
* krb5_context.
*/
static krb5_error_code
{
/*
* The KRB5 context itself requires:
* krb5_int32 for KV5M_CONTEXT
* krb5_int32 for sizeof(default_realm)
* strlen(default_realm) for default_realm.
* krb5_int32 for n_in_tkt_ktypes*sizeof(krb5_int32)
* nktypes*sizeof(krb5_int32) for in_tkt_ktypes.
* krb5_int32 for n_tgs_ktypes*sizeof(krb5_int32)
* nktypes*sizeof(krb5_int32) for tgs_ktypes.
* krb5_int32 for clockskew
* krb5_int32 for kdc_req_sumtype
* krb5_int32 for ap_req_sumtype
* krb5_int32 for safe_sumtype
* krb5_int32 for kdc_default_options
* krb5_int32 for library_options
* krb5_int32 for profile_secure
* krb5_int32 for fcc_default_format
* krb5_int32 for scc_default_format
* <> for os_context
* <> for db_context
* <> for profile
* krb5_int32 for trailer.
*/
/* Calculate base length */
if (context->default_realm)
/* Calculate size required by os_context, if appropriate */
if (context->os_context)
&required);
/* Calculate size required by db_context, if appropriate */
&required);
/* Finally, calculate size required by profile, if appropriate */
&required);
}
if (!kret)
return(kret);
}
/*
* krb5_context_externalize() - Externalize the krb5_context.
*/
static krb5_error_code
krb5_context_externalize(krb5_context kcontext, krb5_pointer arg, krb5_octet **buffer, size_t *lenremain)
{
int i;
required = 0;
if (!context)
return (EINVAL);
return (kret);
return (ENOMEM);
/* First write our magic number */
if (kret)
return (kret);
/* Now sizeof default realm */
if (kret)
return (kret);
/* Now default_realm bytes */
if (context->default_realm) {
if (kret)
return (kret);
}
/* Now number of initial ticket ktypes */
if (kret)
return (kret);
/* Now serialize ktypes */
for (i=0; i<context->in_tkt_ktype_count; i++) {
if (kret)
return (kret);
}
/* Now number of default ktypes */
if (kret)
return (kret);
/* Now serialize ktypes */
for (i=0; i<context->tgs_ktype_count; i++) {
if (kret)
return (kret);
}
/* Now allowable clockskew */
if (kret)
return (kret);
/* Now kdc_req_sumtype */
if (kret)
return (kret);
/* Now default ap_req_sumtype */
if (kret)
return (kret);
/* Now default safe_sumtype */
if (kret)
return (kret);
/* Now kdc_default_options */
if (kret)
return (kret);
/* Now library_options */
if (kret)
return (kret);
/* Now profile_secure */
if (kret)
return (kret);
/* Now fcc_default_format */
if (kret)
return (kret);
/* Now scc_default_format */
if (kret)
return (kret);
/* Now handle os_context, if appropriate */
if (context->os_context) {
if (kret)
return (kret);
}
/* Now handle database context, if appropriate */
if (context->db_context) {
if (kret)
return (kret);
}
/* Finally, handle profile, if appropriate */
if (kret)
return (kret);
}
/*
* If we were successful, write trailer then update the pointer and
* remaining length;
*/
if (kret)
return (kret);
return (0);
}
/*
* krb5_context_internalize() - Internalize the krb5_context.
*/
static krb5_error_code
krb5_context_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain)
{
int i;
/* Read our magic number */
return (EINVAL);
if (ibuf != KV5M_CONTEXT)
return (EINVAL);
/* Get memory for the context */
if (!context)
return (ENOMEM);
/* Get the size of the default realm */
goto cleanup;
if (ibuf) {
if (!context->default_realm) {
goto cleanup;
}
if (kret)
goto cleanup;
}
/* Get the number of in_tkt_ktypes */
goto cleanup;
if (!context->in_tkt_ktypes) {
goto cleanup;
}
for (i=0; i<context->in_tkt_ktype_count; i++) {
goto cleanup;
}
/* Get the number of tgs_ktypes */
goto cleanup;
if (!context->tgs_ktypes) {
goto cleanup;
}
for (i=0; i<context->tgs_ktype_count; i++) {
goto cleanup;
}
/* Allowable checksum */
goto cleanup;
/* kdc_req_sumtype */
goto cleanup;
/* default ap_req_sumtype */
goto cleanup;
/* default_safe_sumtype */
goto cleanup;
/* kdc_default_options */
goto cleanup;
/* library_options */
goto cleanup;
/* profile_secure */
goto cleanup;
/* fcc_default_format */
goto cleanup;
/* scc_default_format */
goto cleanup;
/* Attempt to read in the os_context. It's an array now, but
we still treat it in most places as a separate object with
a pointer. */
{
(krb5_pointer *) &osp,
goto cleanup;
/* Put the newly allocated data into the krb5_context
structure where we're really keeping it these days. */
if (osp)
}
/* Attempt to read in the db_context */
goto cleanup;
#ifndef _KERNEL
/* Attempt to read in the profile */
#endif
goto cleanup;
/* Finally, find the trailer */
goto cleanup;
if (ibuf != KV5M_CONTEXT) {
goto cleanup;
}
return 0;
if (context)
return(kret);
}
/*
* krb5_oscontext_size() - Determine the size required to externalize
* the krb5_os_context.
*/
/*ARGSUSED*/
static krb5_error_code
{
/*
* We need five 32-bit integers:
* two for header and trailer
* one each for time_offset, usec_offset and os_flags
*/
return(0);
}
/*
* krb5_oscontext_externalize() - Externalize the krb5_os_context.
*/
static krb5_error_code
krb5_oscontext_externalize(krb5_context kcontext, krb5_pointer arg, krb5_octet **buffer, size_t *lenremain)
{
required = 0;
/* Handle any other OS context here */
kret = 0;
if (!kret) {
}
}
}
return(kret);
}
/*
* krb5_oscontext_internalize() - Internalize the krb5_os_context.
*/
/*ARGSUSED*/
static krb5_error_code
krb5_oscontext_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain)
{
/* Read our magic number */
ibuf = 0;
if (ibuf == KV5M_OS_CONTEXT) {
/* Get memory for the context */
if ((os_ctx = (krb5_os_context)
MALLOC(sizeof(struct _krb5_os_context))) &&
/* Read out our context */
if (ibuf == KV5M_OS_CONTEXT) {
kret = 0;
} else
}
}
if (!kret) {
}
else {
if (os_ctx)
}
return(kret);
}
/*
* Register the context serializers.
*/
{
if (!kret)
/* Profile nformation need not be serialzied when we are importing the
* context into kernel. Besides the function pointers to file access
* routines can't be used in the kernel.
* Any info needed from the profile is already a part of the
* exported context obviating the need for importer to know about
* profile config files.
*/
#ifndef _KERNEL
if (!kret)
#endif
return(kret);
}