ktf_util.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "krb5.h"
#include "k5-int.h"
#include <stdio.h>
#include "ktfile.h"
#include <sys/byteorder.h>
static void
{
}
/*
* Write the data to disk.
*/
static krb5_error_code
{
krb5_error_code ret = 0;
int fd;
/*
* If the file was not previously opened for writing,
* return an error.
*/
return (EBADF);
if (fd == -1)
return (KRB5_KT_IOERR);
/* If no data, just write the version bytes */
ret = KRB5_KT_IOERR;
else
} else {
ret = KRB5_KT_IOERR;
}
return (ret);
}
static int
{
int fd;
if (writable) {
}
if (fd == -1)
return (errno);
return (errno);
/* If opening a writable buffer, make it large enough to grow */
if (writable) {
} else {
}
/*
* The file was empty, just malloc
* a new buffer. It will get dumped to disk later.
*/
return (errno);
}
} else {
return(errno);
}
return (0);
}
static int
{
return (0);
}
return (length);
}
static int
{
int err = 0;
int fd;
/*
* Because we never know exactly how large
* the intial buffer will need to be there is a
* small chance that the data written will exceed
* our initial estimate. In this case,
* reallocate a larger buffer before continuing.
*/
return(err);
}
/* indicate the larger buffer size. */
/*
* In this situation, we want to continue adding
* to the end of the file, so set the 'offset'.
*/
}
/* grow the filesize if we appended */
return (length);
}
static int
{
return (KRB5_KT_IOERR);
return (0);
}
{
krb5_error_code retval = 0;
char *open_flag;
/* Don't know what state it's in; shut down and start anew. */
}
if (ktf_open_file(kdata, 0))
return (KRB5_KT_IOERR);
return(KRB5_KT_IOERR);
}
return (KRB5_KEYTAB_BADVNO);
}
return (0);
}
{
krb5_error_code retval = 0;
int fd;
/*
* If the file was already opened for writing,
* just reset the offset to skip past the kvno.
*/
return (0);
}
return (KRB5_KT_IOERR);
/* overwrite the version number */
return (KRB5_KT_IOERR);
}
return (0);
}
{
krb5_error_code retval = 0;
return (KRB5_FCC_INTERNAL);
return (retval);
}
{
return (KRB5_KT_END);
}
if (size >= 0) {
/*
* Shift the remainder of the keytab to the delete point. This
* avoids writing holes to the keytab file, as we used to, and
* so is more space efficient. Older versions of this code, as
* well as non-Solaris writers of keytabs may still write holes,
* so we still support reading holes.
*/
return (ktf_update_file_on_disk(kdata));
}
return (0);
}
/*ARGSUSED*/
{
char *realmdata;
int i;
krb5_error_code error = 0;
do {
return (KRB5_KT_END);
}
if (size < 0) {
}
} while (size < 0);
if (size == 0) /* EOF reached */
return (KRB5_KT_END);
malloc(sizeof (krb5_principal_data));
return (KRB5_CC_NOMEM);
}
/*
* Read the number of components
* DCE includes the principal's realm in the count;
* the new format does not
*/
return (KRB5_KT_END);
}
else
length--;
if (length) {
return (KRB5_CC_NOMEM);
}
} else
return (KRB5_KT_END);
/* Read the realm length */
return (KRB5_KT_END);
}
/* Read the realm data */
if (realm_len) {
return (KRB5_CC_NOMEM);
}
} else {
return (KRB5_KT_END);
}
return (KRB5_KT_END);
}
/* Read principal components */
for (i = 0; i < length; i++) {
error = KRB5_KT_END;
goto errout;
}
else
compsize--;
goto errout;
}
} else {
error = KRB5_KT_END;
goto errout;
}
error = KRB5_KT_END;
goto errout;
}
/* Null terminate, just in case..... */
}
/* Read the principal type */
error = KRB5_KT_END;
goto errout;
}
/* Read the timestamp */
error = KRB5_KT_END;
goto errout;
}
/* Read the Version number */
error = KRB5_KT_END;
goto errout;
}
/* Read the key type */
error = KRB5_KT_END;
goto errout;
}
/* Read the key length */
error = KRB5_KT_END;
goto errout;
}
if (length) {
goto errout;
} else {
error = KRB5_KT_END;
goto errout;
}
}
} else {
error = KRB5_KT_END;
goto errout;
}
/* the file position should left at delete_point+N */
return (0);
while (--i >= 0)
return (error);
}
{
entryp, &delete_point));
}
{
krb5_error_code retval = 0;
char *realmdata;
int i;
if (retval)
return (retval);
&size_needed, &commit_point);
if (retval)
return (retval);
/* principal size */
else
length++;
return (KRB5_KT_IOERR);
/* Realm length */
return (KRB5_KT_IOERR);
/* Realm data */
if (realm_len) {
kdata))
return (KRB5_KT_IOERR);
}
/* Princ components */
for (i = 0; i < count; i++) {
else
compsize++;
return (KRB5_KT_IOERR);
}
return (KRB5_KT_IOERR);
}
}
/* principal type */
return (KRB5_KT_IOERR);
/* timestamp */
else
return (KRB5_KT_IOERR);
/* key version */
return (KRB5_KT_IOERR);
/* key type */
return (KRB5_KT_IOERR);
/* key length and contents */
return (KRB5_KT_IOERR);
if (length) {
return (KRB5_KT_IOERR);
}
/* seek to the start of the entry and write size_needed */
return (KRB5_KT_IOERR);
return (ktf_update_file_on_disk(kdata));
}
/*ARGSUSED*/
{
int i;
krb5_int32 size = 0;
/* principal size */
/* realm length */
(sizeof (krb5_int16));
/* length of princ components */
}
/* principal type */
/* timestamp */
/* key version */
/* secret key length */
/* key enc type */
*size_needed = size;
return (0);
}
/*ARGSUSED*/
{
/* check for size_needed for entry */
if (size_needed == 0)
return (errno);
/* read the key version */
return (KRB5_KT_IOERR);
while (!foundslot) {
/* offset of slot */
/* EOF reached */
/*
* reset to the commit_point, just in case if
* bytes read were less than 4
*/
/* append sizeof(krb5_int32) bytes of zeros */
size = 0;
return (KRB5_KT_IOERR);
}
if (size > 0) {
} else if (!foundslot) {
/* empty slot has an entry of -N */
if (nsize >= *size_needed) {
*size_needed = nsize;
} else if (nsize > 0) {
/* current slot is small */
} else {
/*
* Slot with size = 0
*
* If krb5_ktfileint_write_entry fails and the entry
* was being added at the EOF, we have have a slot
* with size = 0. Hence we need to clear every byte
* from here to EOF. A slot with size = 0 will always
* be at the EOF.
* If krb5_ktfileint_write_entry fails and the entry
* was being added to a slot from where previous entry
* was deleted, this slot will have a size of -N.
* This slot will not be at EOF, hence we do not clear
* this slot. This slot will be overwritten by the
* entry that can fit in the slot.
*/
/*
* While loop will zero fill 4 bytes at a time from
* the current file position through EOF
* We must clear the bytes at 4 byte boundary, since
* the previous entry may have failed at an odd
* boundary.
*/
while (!foundslot) {
}
if (!foundslot) {
if (ret)
return (ret);
}
} /* while */
/* reset to start of available slot */
} /* else */
}
} /* while */
return (0);
}