Use new storage functions.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1283 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1997-03-08 06:01:01 +00:00
parent 2a5a99b401
commit d99672295c
2 changed files with 103 additions and 53 deletions

View File

@@ -141,8 +141,13 @@ krb5_cc_initialize(krb5_context context,
fd = open(f, O_RDWR | O_CREAT | O_EXCL, 0600); fd = open(f, O_RDWR | O_CREAT | O_EXCL, 0600);
if(fd == -1) if(fd == -1)
return errno; return errno;
krb5_store_int16(fd, 0x503); {
krb5_store_principal(fd, primary_principal); krb5_storage *sp;
sp = krb5_storage_from_fd(fd);
krb5_store_int16(sp, 0x503);
krb5_store_principal(sp, primary_principal);
krb5_storage_free(sp);
}
close(fd); close(fd);
return 0; return 0;
@@ -185,16 +190,21 @@ krb5_cc_store_cred(krb5_context context,
fd = open(f->filename, O_WRONLY | O_APPEND); fd = open(f->filename, O_WRONLY | O_APPEND);
if(fd < 0) if(fd < 0)
return errno; return errno;
krb5_store_principal(fd, creds->client); {
krb5_store_principal(fd, creds->server); krb5_storage *sp;
krb5_store_keyblock(fd, creds->session); sp = krb5_storage_from_fd(fd);
krb5_store_times(fd, creds->times); krb5_store_principal(sp, creds->client);
krb5_store_int8(fd, 0); /* s/key */ krb5_store_principal(sp, creds->server);
krb5_store_int32(fd, 0); /* flags */ krb5_store_keyblock(sp, creds->session);
krb5_store_addrs(fd, creds->addresses); krb5_store_times(sp, creds->times);
krb5_store_authdata(fd, creds->authdata); krb5_store_int8(sp, 0); /* s/key */
krb5_store_data(fd, creds->ticket); krb5_store_int32(sp, 0); /* flags */
krb5_store_data(fd, creds->second_ticket); krb5_store_addrs(sp, creds->addresses);
krb5_store_authdata(sp, creds->authdata);
krb5_store_data(sp, creds->ticket);
krb5_store_data(sp, creds->second_ticket);
krb5_storage_free(sp);
}
close(fd); close(fd);
return 0; /* XXX */ return 0; /* XXX */
} }
@@ -206,26 +216,30 @@ krb5_cc_read_cred (int fd,
int ret; int ret;
int8_t dummy8; int8_t dummy8;
int32_t dummy32; int32_t dummy32;
krb5_storage *sp;
ret = krb5_ret_principal (fd, &creds->client); sp = krb5_storage_from_fd(fd);
ret = krb5_ret_principal (sp, &creds->client);
if(ret) return ret; if(ret) return ret;
ret = krb5_ret_principal (fd, &creds->server); ret = krb5_ret_principal (sp, &creds->server);
if(ret) return ret; if(ret) return ret;
ret = krb5_ret_keyblock (fd, &creds->session); ret = krb5_ret_keyblock (sp, &creds->session);
if(ret) return ret; if(ret) return ret;
ret = krb5_ret_times (fd, &creds->times); ret = krb5_ret_times (sp, &creds->times);
if(ret) return ret; if(ret) return ret;
ret = krb5_ret_int8 (fd, &dummy8); ret = krb5_ret_int8 (sp, &dummy8);
if(ret) return ret; if(ret) return ret;
ret = krb5_ret_int32 (fd, &dummy32); ret = krb5_ret_int32 (sp, &dummy32);
if(ret) return ret; if(ret) return ret;
ret = krb5_ret_addrs (fd, &creds->addresses); ret = krb5_ret_addrs (sp, &creds->addresses);
if(ret) return ret; if(ret) return ret;
ret = krb5_ret_authdata (fd, &creds->authdata); ret = krb5_ret_authdata (sp, &creds->authdata);
if(ret) return ret; if(ret) return ret;
ret = krb5_ret_data (fd, &creds->ticket); ret = krb5_ret_data (sp, &creds->ticket);
if(ret) return ret; if(ret) return ret;
ret = krb5_ret_data (fd, &creds->second_ticket); ret = krb5_ret_data (sp, &creds->second_ticket);
krb5_storage_free(sp);
return ret; return ret;
} }
@@ -256,12 +270,15 @@ krb5_cc_get_principal(krb5_context context,
{ {
int fd; int fd;
int16_t tag; int16_t tag;
krb5_storage *sp;
fd = open(krb5_cc_get_name(context, id), O_RDONLY); fd = open(krb5_cc_get_name(context, id), O_RDONLY);
if(fd < 0) if(fd < 0)
return errno; return errno;
krb5_ret_int16(fd, &tag); sp = krb5_storage_from_fd(fd);
krb5_ret_principal(fd, principal); krb5_ret_int16(sp, &tag);
krb5_ret_principal(sp, principal);
krb5_storage_free(sp);
close(fd); close(fd);
return 0; return 0;
} }
@@ -273,14 +290,17 @@ krb5_cc_start_seq_get (krb5_context context,
{ {
int16_t tag; int16_t tag;
krb5_principal principal; krb5_principal principal;
krb5_storage *sp;
if (id->type != 1) if (id->type != 1)
abort (); abort ();
cursor->fd = open (krb5_cc_get_name (context, id), O_RDONLY); cursor->fd = open (krb5_cc_get_name (context, id), O_RDONLY);
if (cursor->fd < 0) if (cursor->fd < 0)
return errno; return errno;
krb5_ret_int16 (cursor->fd, &tag); sp = krb5_storage_from_fd(cursor->fd);
krb5_ret_principal (cursor->fd, &principal); krb5_ret_int16 (sp, &tag);
krb5_ret_principal (sp, &principal);
krb5_storage_free(sp);
krb5_free_principal (principal); krb5_free_principal (principal);
return 0; return 0;
} }
@@ -291,9 +311,14 @@ krb5_cc_next_cred (krb5_context context,
krb5_creds *creds, krb5_creds *creds,
krb5_cc_cursor *cursor) krb5_cc_cursor *cursor)
{ {
krb5_error_code err;
krb5_storage *sp;
if (id->type != 1) if (id->type != 1)
abort (); abort ();
return krb5_cc_read_cred (cursor->fd, creds);
krb5_storage_from_fd(cursor->fd);
err = krb5_cc_read_cred (sp, creds);
krb5_storage_free(sp);
} }
krb5_error_code krb5_error_code
@@ -314,11 +339,14 @@ krb5_cc_get_first(krb5_context context,
int fd; int fd;
int16_t tag; int16_t tag;
krb5_principal principal; krb5_principal principal;
krb5_storage *sp;
fd = open(krb5_cc_get_name (context, id), O_RDONLY); fd = open(krb5_cc_get_name (context, id), O_RDONLY);
cursor->fd = fd; cursor->fd = fd;
krb5_ret_int16(fd, &tag); sp = krb5_storage_from_fd(fd);
krb5_ret_principal(fd, &principal); krb5_ret_int16(sp, &tag);
krb5_ret_principal(sp, &principal);
krb5_storage_free(sp);
return 0; return 0;
} }

View File

@@ -1,5 +1,7 @@
#include "krb5_locl.h" #include "krb5_locl.h"
RCSID("$Id$");
krb5_error_code krb5_error_code
krb5_kt_resolve(krb5_context context, krb5_kt_resolve(krb5_context context,
const char *name, const char *name,
@@ -147,11 +149,13 @@ krb5_kt_start_seq_get(krb5_context context,
{ {
int16_t tag; int16_t tag;
int ret; int ret;
krb5_storage *sp;
cursor->fd = open (id->filename, O_RDONLY); cursor->fd = open (id->filename, O_RDONLY);
if (cursor->fd < 0) if (cursor->fd < 0)
return -1; return -1;
ret = krb5_ret_int16(cursor->fd, &tag); cursor->sp = krb5_storage_from_fd(cursor->fd);
ret = krb5_ret_int16(cursor->sp, &tag);
if (ret) if (ret)
return ret; return ret;
if (tag != 0x0502) if (tag != 0x0502)
@@ -160,25 +164,41 @@ krb5_kt_start_seq_get(krb5_context context,
} }
static krb5_error_code static krb5_error_code
krb5_kt_ret_data(int fd, krb5_kt_store_data(krb5_storage *sp,
krb5_data data)
{
int ret;
ret = krb5_store_int16(sp, data.length);
if(ret < 0)
return ret;
ret = sp->store(sp, data.data, data.length);
if(ret != data.length){
if(ret < 0)
return errno;
return KRB5_CC_END;
}
return 0;
}
static krb5_error_code
krb5_kt_ret_data(krb5_storage *sp,
krb5_data *data) krb5_data *data)
{ {
int ret; int ret;
int16_t size; int16_t size;
ret = krb5_ret_int16(sp, &size);
ret = krb5_ret_int16(fd, &size);
if(ret) if(ret)
return ret; return ret;
data->length = size; data->length = size;
data->data = malloc(size); data->data = malloc(size);
ret = read(fd, data->data, size); ret = sp->fetch(sp, data->data, size);
if(ret != size) if(ret != size)
return (ret < 0)? errno : KRB5_CC_END; return (ret < 0)? errno : KRB5_CC_END;
return 0; return 0;
} }
static krb5_error_code static krb5_error_code
krb5_kt_ret_principal(int fd, krb5_kt_ret_principal(krb5_storage *sp,
krb5_principal *princ) krb5_principal *princ)
{ {
int i; int i;
@@ -190,18 +210,19 @@ krb5_kt_ret_principal(int fd,
if(p == NULL) if(p == NULL)
return ENOMEM; return ENOMEM;
p->type = KRB5_NT_SRV_HST; p->type = KRB5_NT_SRV_HST;
ret = krb5_ret_int16(fd, &tmp); ret = krb5_ret_int16(sp, &tmp);
if(ret) return ret; if(ret) return ret;
p->ncomp = tmp; p->ncomp = tmp;
ret = krb5_kt_ret_data(fd, &p->realm); ret = krb5_kt_ret_data(sp, &p->realm);
if(ret) return ret; if(ret) return ret;
p->comp = ALLOC(p->ncomp, krb5_data); p->comp = ALLOC(p->ncomp, krb5_data);
if(p->comp == NULL){ if(p->comp == NULL){
return ENOMEM; return ENOMEM;
} }
for(i = 0; i < p->ncomp; i++){ for(i = 0; i < p->ncomp; i++){
ret = krb5_kt_ret_data(fd, &p->comp[i]); ret = krb5_kt_ret_data(sp, &p->comp[i]);
if(ret) return ret; if(ret) return ret;
} }
*princ = p; *princ = p;
@@ -209,15 +230,15 @@ krb5_kt_ret_principal(int fd,
} }
static krb5_error_code static krb5_error_code
krb5_kt_ret_keyblock(int fd, krb5_keyblock *p) krb5_kt_ret_keyblock(krb5_storage *sp, krb5_keyblock *p)
{ {
int ret; int ret;
int16_t tmp; int16_t tmp;
ret = krb5_ret_int16(fd, &tmp); /* keytype + etype */ ret = krb5_ret_int16(sp, &tmp); /* keytype + etype */
if(ret) return ret; if(ret) return ret;
p->keytype = tmp; p->keytype = tmp;
ret = krb5_kt_ret_data(fd, &p->contents); ret = krb5_kt_ret_data(sp, &p->contents);
return ret; return ret;
} }
@@ -232,23 +253,23 @@ krb5_kt_next_entry(krb5_context context,
int ret; int ret;
int8_t tmp; int8_t tmp;
ret = krb5_ret_int32(cursor->fd, &len); ret = krb5_ret_int32(cursor->sp, &len);
if (ret) if (ret)
return ret; return ret;
ret = krb5_kt_ret_principal (cursor->fd, &entry->principal); ret = krb5_kt_ret_principal (cursor->sp, &entry->principal);
if (ret) if (ret)
return ret; return ret;
ret = krb5_ret_int32(cursor->fd, &entry->principal->type); ret = krb5_ret_int32(cursor->sp, &entry->principal->type);
if (ret) if (ret)
return ret; return ret;
ret = krb5_ret_int32(cursor->fd, &timestamp); ret = krb5_ret_int32(cursor->sp, &timestamp);
if (ret) if (ret)
return ret; return ret;
ret = krb5_ret_int8(cursor->fd, &tmp); ret = krb5_ret_int8(cursor->sp, &tmp);
if (ret) if (ret)
return ret; return ret;
entry->vno = tmp; entry->vno = tmp;
ret = krb5_kt_ret_keyblock (cursor->fd, &entry->keyblock); ret = krb5_kt_ret_keyblock (cursor->sp, &entry->keyblock);
if (ret) if (ret)
return ret; return ret;
return 0; return 0;
@@ -259,6 +280,7 @@ krb5_kt_end_seq_get(krb5_context context,
krb5_keytab id, krb5_keytab id,
krb5_kt_cursor *cursor) krb5_kt_cursor *cursor)
{ {
krb5_storage_free(cursor->sp);
close (cursor->fd); close (cursor->fd);
return 0; return 0;
} }