kdb_xdr.c revision 56a424cca6b3f91f31bdab72a4626c48c779fe8b
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* 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.
*
*/
#include "k5-int.h"
#include <string.h>
#include <stdio.h>
#include <errno.h>
{
(sizeof(krb5_key_data)*
return(ENOMEM);
entry->n_key_data++;
return 0;
}
{
krb5_octet * tmp;
/* copy the new data first, so we can fail cleanly if malloc()
fails */
return(ENOMEM);
/* Find an existing entry of the specified type and point at
it, or NULL if not found */
break;
/* if necessary, chain a new record in the beginning and point at it */
if (!tl_data) {
== NULL) {
return(ENOMEM);
}
}
/* fill in the record */
if (tl_data->tl_data_contents)
return(0);
}
{
*ret_tl_data = *tl_data;
return(0);
}
}
/* if the requested record isn't found, return zero bytes.
if it ever means something to have a zero-length tl_data,
this code and its callers will have to be changed */
ret_tl_data->tl_data_length = 0;
return(0);
}
{
}
{
return(code);
*stamp = 0;
return(0);
}
return(0);
}
/* it seems odd that there's no function to remove a tl_data, but if
I need one, I'll add one */
{
krb5_error_code retval = 0;
krb5_octet * nextloc = 0;
char * unparse_mod_princ = 0;
unsigned int unparse_mod_princ_size;
return(retval);
== NULL) {
return(ENOMEM);
}
/* Mod Date */
/* Mod Princ */
return(retval);
}
{
return(code);
return(KRB5_KDB_TRUNCATED_RECORD);
/* Mod Date */
/* Mod Princ */
mod_princ)))
return(code);
return(0);
}
{
char *princ_name;
/* need to store the NULL for decoding */
}
return(retval);
}
void
{
}
{
int i, j;
unsigned int unparse_princ_size;
char * unparse_princ;
char * nextloc;
/*
* Generate one lump of data from the krb5_db_entry.
* This data must be independent of byte order of the machine,
* compact and extensible.
*/
/*
* First allocate enough space for all the data.
* Need 2 bytes for the length of the base structure
* then 36 [ 8 * 4 + 2 * 2] bytes for the base information
* [ attributes, max_life, max_renewable_life, expiration,
* pw_expiration, last_success, last_failed, fail_auth_count ]
* [ n_key_data, n_tl_data ]
* then XX bytes [ e_length ] for the extra data [ e_data ]
* then XX bytes [ 2 for length + length for string ] for the principal,
* then (4 [type + length] + tl_data_length) bytes per tl_data
* then (4 + (4 + key_data_length) per key_data_contents) bytes per key_data
*/
return(retval);
i = 0;
/* tl_data is a linked list */
i++;
}
goto epc_error;
}
/* key_data is an array */
for (i = 0; i < entry->n_key_data; i++) {
}
}
goto epc_error;
}
/*
* Now we go through entry again, this time copying data
* These first entries are always saved regardless of version
*/
/* Base Length */
nextloc += 2;
/* Attributes */
nextloc += 4;
/* Max Life */
nextloc += 4;
/* Max Renewable Life */
nextloc += 4;
/* When the client expires */
nextloc += 4;
/* When its passwd expires */
nextloc += 4;
/* Last successful passwd */
nextloc += 4;
/* Last failed passwd attempt */
nextloc += 4;
/* # of failed passwd attempt */
nextloc += 4;
/* # tl_data strutures */
nextloc += 2;
/* # key_data strutures */
nextloc += 2;
/* Put extended fields here */
abort();
/* Any extra data that this version doesn't understand. */
}
/*
* Now we get to the principal.
* To squeze a few extra bytes out it is always assumed to come
* after the base type.
*/
nextloc += 2;
/* tl_data is a linked list, of type, legth, contents */
nextloc += 2;
nextloc += 2;
}
/* key_data is an array */
for (i = 0; i < entry->n_key_data; i++) {
nextloc += 2;
nextloc += 2;
nextloc += 2;
nextloc += 2;
if (length) {
}
}
}
return retval;
}
void
{
return;
}
{
int sizeleft, i;
char * nextloc;
krb5_tl_data ** tl_data;
/* Zero out entry and NULL pointers */
/*
* undo the effects of encode_princ_contents.
*
* The first part is decoding the base type. If the base type is
* bigger than the original base type then the additional fields
* need to be filled in. If the base type is larger than any
* known base type the additional data goes in e_data.
*/
/* First do the easy stuff */
if ((sizeleft -= KRB5_KDB_V1_BASE_LENGTH) < 0)
return KRB5_KDB_TRUNCATED_RECORD;
/* Base Length */
nextloc += 2;
/* Attributes */
nextloc += 4;
/* Max Life */
nextloc += 4;
/* Max Renewable Life */
nextloc += 4;
/* When the client expires */
nextloc += 4;
/* When its passwd expires */
nextloc += 4;
/* Last successful passwd */
nextloc += 4;
/* Last failed passwd attempt */
nextloc += 4;
/* # of failed passwd attempt */
nextloc += 4;
/* # tl_data strutures */
nextloc += 2;
return KRB5_KDB_TRUNCATED_RECORD;
/* # key_data strutures */
nextloc += 2;
if (entry->n_key_data < 0)
return KRB5_KDB_TRUNCATED_RECORD;
/* Check for extra data */
} else {
return ENOMEM;
}
}
/*
* Get the principal name for the entry
* (stored as a string which gets unparsed.)
*/
if ((sizeleft -= 2) < 0) {
goto error_out;
}
i = 0;
i = (int) i16;
nextloc += 2;
goto error_out;
goto error_out;
}
sizeleft -= i;
nextloc += i;
/* tl_data is a linked list */
if ((sizeleft -= 4) < 0) {
goto error_out;
}
if ((*tl_data = (krb5_tl_data *)
goto error_out;
}
nextloc += 2;
nextloc += 2;
goto error_out;
}
goto error_out;
}
}
/* key_data is an array */
goto error_out;
}
for (i = 0; i < entry->n_key_data; i++) {
int j;
if ((sizeleft -= 4) < 0) {
goto error_out;
}
nextloc += 2;
nextloc += 2;
/* key_data_ver determins number of elements and how to unparse them. */
for (j = 0; j < key_data->key_data_ver; j++) {
if ((sizeleft -= 4) < 0) {
goto error_out;
}
nextloc += 2;
nextloc += 2;
goto error_out;
}
if (key_data->key_data_length[j]) {
goto error_out;
}
key_data->key_data_length[j]);
}
}
} else {
/* This isn't right. I'll fix it later */
abort();
}
}
return 0;
return retval;
}
void
{
int i, j;
if (tl_data->tl_data_contents)
}
for (i = 0; i < entry->n_key_data; i++) {
0,
}
}
}
}
}
return;
}
/*
* Given a particular enctype and optional salttype and kvno, find the
* most appropriate krb5_key_data entry of the database entry.
*
* If stype or kvno is negative, it is ignored.
* If kvno is 0 get the key which is maxkvno for the princ and matches
* the other attributes.
*/
{
int i, idx;
int maxkvno;
ret = 0;
kvno = 0;
if (kvno == 0) {
/* Get the max key version */
for (i = 0; i < dbentp->n_key_data; i++) {
}
}
}
maxkvno = -1;
ret = 0;
} else {
}
/*
* Filter out non-permitted enctypes.
*/
continue;
}
if (ktype > 0) {
&similar)))
return(ret);
}
if (kvno >= 0) {
idx = i;
break;
}
} else {
idx = i;
}
}
}
}
if (maxkvno < 0)
return 0;
}
{
krb5_int32 start = 0;
}