make the krb5_storage opaque, and add function wrappers for

store/fetch/seek, and also make the eof-code configurable


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10931 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2002-04-18 14:00:44 +00:00
parent fe181a304d
commit ce19f448ae
6 changed files with 103 additions and 34 deletions

View File

@@ -411,14 +411,8 @@ typedef Authenticator krb5_donot_replay;
#define KRB5_STORAGE_BYTEORDER_LE 0x20
#define KRB5_STORAGE_BYTEORDER_HOST 0x40
typedef struct krb5_storage {
void *data;
ssize_t (*fetch)(struct krb5_storage*, void*, size_t);
ssize_t (*store)(struct krb5_storage*, const void*, size_t);
off_t (*seek)(struct krb5_storage*, off_t, int);
void (*free)(struct krb5_storage*);
krb5_flags flags;
} krb5_storage;
struct krb5_storage_data;
typedef struct krb5_storage_data krb5_storage;
typedef struct krb5_keytab_entry {
krb5_principal principal;

47
lib/krb5/store-int.h Normal file
View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2002 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __store_int_h__
#define __store_int_h__
struct krb5_storage_data {
void *data;
ssize_t (*fetch)(struct krb5_storage_data*, void*, size_t);
ssize_t (*store)(struct krb5_storage_data*, const void*, size_t);
off_t (*seek)(struct krb5_storage_data*, off_t, int);
void (*free)(struct krb5_storage_data*);
krb5_flags flags;
int eof_code;
};
#endif /* __store_int_h__ */

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997-2001 Kungliga Tekniska H<>gskolan
* Copyright (c) 1997-2002 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -32,6 +32,7 @@
*/
#include "krb5_locl.h"
#include "store-int.h"
RCSID("$Id$");
@@ -72,6 +73,29 @@ krb5_storage_get_byteorder(krb5_storage *sp, krb5_flags byteorder)
return sp->flags & KRB5_STORAGE_BYTEORDER_MASK;
}
off_t
krb5_storage_seek(krb5_storage *sp, off_t offset, int whence)
{
return (*sp->seek)(sp, offset, whence);
}
ssize_t
krb5_storage_read(krb5_storage *sp, void *buf, size_t len)
{
return sp->fetch(sp, buf, len);
}
ssize_t
krb5_storage_write(krb5_storage *sp, const void *buf, size_t len)
{
return sp->store(sp, buf, len);
}
void
krb5_storage_set_eof_code(krb5_storage *sp, int code)
{
sp->eof_code = code;
}
ssize_t
_krb5_put_int(void *buffer, unsigned long value, size_t size)
@@ -142,7 +166,7 @@ krb5_store_int(krb5_storage *sp,
_krb5_put_int(v, value, len);
ret = sp->store(sp, v, len);
if (ret != len)
return (ret<0)?errno:KRB5_CC_END;
return (ret<0)?errno:sp->eof_code;
return 0;
}
@@ -167,7 +191,7 @@ krb5_ret_int(krb5_storage *sp,
unsigned long w;
ret = sp->fetch(sp, v, len);
if(ret != len)
return (ret<0)?errno:KRB5_CC_END;
return (ret<0)?errno:sp->eof_code;
_krb5_get_int(v, &w, len);
*value = w;
return 0;
@@ -223,7 +247,7 @@ krb5_store_int8(krb5_storage *sp,
ret = sp->store(sp, &value, sizeof(value));
if (ret != sizeof(value))
return (ret<0)?errno:KRB5_CC_END;
return (ret<0)?errno:sp->eof_code;
return 0;
}
@@ -235,7 +259,7 @@ krb5_ret_int8(krb5_storage *sp,
ret = sp->fetch(sp, value, sizeof(*value));
if (ret != sizeof(*value))
return (ret<0)?errno:KRB5_CC_END;
return (ret<0)?errno:sp->eof_code;
return 0;
}
@@ -251,7 +275,7 @@ krb5_store_data(krb5_storage *sp,
if(ret != data.length){
if(ret < 0)
return errno;
return KRB5_CC_END;
return sp->eof_code;
}
return 0;
}
@@ -272,7 +296,7 @@ krb5_ret_data(krb5_storage *sp,
if (size) {
ret = sp->fetch(sp, data->data, size);
if(ret != size)
return (ret < 0)? errno : KRB5_CC_END;
return (ret < 0)? errno : sp->eof_code;
}
return 0;
}
@@ -315,7 +339,7 @@ krb5_store_stringz(krb5_storage *sp, const char *s)
if(ret < 0)
return ret;
else
return KRB5_CC_END;
return sp->eof_code;
}
return 0;
}
@@ -346,7 +370,7 @@ krb5_ret_stringz(krb5_storage *sp,
if(ret != 1){
free(s);
if(ret == 0)
return KRB5_CC_END;
return sp->eof_code;
return ret;
}
*string = s;
@@ -593,37 +617,35 @@ krb5_store_creds(krb5_storage *sp, krb5_creds *creds)
int ret;
ret = krb5_store_principal(sp, creds->client);
if (ret)
if(ret)
return ret;
ret = krb5_store_principal(sp, creds->server);
if (ret)
if(ret)
return ret;
ret = krb5_store_keyblock(sp, creds->session);
if (ret)
if(ret)
return ret;
ret = krb5_store_times(sp, creds->times);
if (ret)
if(ret)
return ret;
ret = krb5_store_int8(sp, 0); /* this is probably the
enc-tkt-in-skey bit from KDCOptions */
if (ret)
if(ret)
return ret;
ret = krb5_store_int32(sp, creds->flags.i);
if (ret)
if(ret)
return ret;
ret = krb5_store_addrs(sp, creds->addresses);
if (ret)
if(ret)
return ret;
ret = krb5_store_authdata(sp, creds->authdata);
if (ret)
if(ret)
return ret;
ret = krb5_store_data(sp, creds->ticket);
if (ret)
if(ret)
return ret;
ret = krb5_store_data(sp, creds->second_ticket);
if (ret)
return ret;
return 0;
return ret;
}
krb5_error_code
@@ -655,10 +677,10 @@ krb5_ret_creds(krb5_storage *sp, krb5_creds *creds)
if(ret) goto cleanup;
ret = krb5_ret_data (sp, &creds->second_ticket);
cleanup:
if(ret)
if(ret) {
#if 0
krb5_free_creds_contents(context, creds) /* XXX */
krb5_free_creds_contents(context, creds); /* XXX */
#endif
;
}
return ret;
}

View File

@@ -32,6 +32,7 @@
*/
#include "krb5_locl.h"
#include "store-int.h"
RCSID("$Id$");
@@ -116,6 +117,7 @@ krb5_storage_emem(void)
emem_storage *s = malloc(sizeof(*s));
sp->data = s;
sp->flags = 0;
sp->eof_code = HEIM_ERR_EOF;
s->size = 1024;
s->base = malloc(s->size);
s->len = 0;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997 - 2001 Kungliga Tekniska H<>gskolan
* Copyright (c) 1997 - 2002 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -32,6 +32,7 @@
*/
#include "krb5_locl.h"
#include "store-int.h"
RCSID("$Id$");
@@ -73,6 +74,7 @@ krb5_storage_from_fd(int fd)
return NULL;
}
sp->flags = 0;
sp->eof_code = HEIM_ERR_EOF;
FD(sp) = fd;
sp->fetch = fd_fetch;
sp->store = fd_store;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997 - 2000 Kungliga Tekniska H<>gskolan
* Copyright (c) 1997 - 2000, 2002 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -32,6 +32,7 @@
*/
#include "krb5_locl.h"
#include "store-int.h"
RCSID("$Id$");
@@ -100,6 +101,7 @@ krb5_storage_from_mem(void *buf, size_t len)
}
sp->data = s;
sp->flags = 0;
sp->eof_code = HEIM_ERR_EOF;
s->base = buf;
s->size = len;
s->ptr = buf;