diff --git a/lib/krb5/cache.c b/lib/krb5/cache.c index 75d1ef459..9e86b5cfe 100644 --- a/lib/krb5/cache.c +++ b/lib/krb5/cache.c @@ -141,10 +141,15 @@ krb5_cc_initialize(krb5_context context, fd = open(f, O_RDWR | O_CREAT | O_EXCL, 0600); if(fd == -1) 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); - + return 0; } @@ -185,17 +190,22 @@ krb5_cc_store_cred(krb5_context context, fd = open(f->filename, O_WRONLY | O_APPEND); if(fd < 0) return errno; - krb5_store_principal(fd, creds->client); - krb5_store_principal(fd, creds->server); - krb5_store_keyblock(fd, creds->session); - krb5_store_times(fd, creds->times); - krb5_store_int8(fd, 0); /* s/key */ - krb5_store_int32(fd, 0); /* flags */ - krb5_store_addrs(fd, creds->addresses); - krb5_store_authdata(fd, creds->authdata); - krb5_store_data(fd, creds->ticket); - krb5_store_data(fd, creds->second_ticket); - close(fd); + { + krb5_storage *sp; + sp = krb5_storage_from_fd(fd); + krb5_store_principal(sp, creds->client); + krb5_store_principal(sp, creds->server); + krb5_store_keyblock(sp, creds->session); + krb5_store_times(sp, creds->times); + krb5_store_int8(sp, 0); /* s/key */ + krb5_store_int32(sp, 0); /* flags */ + 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); return 0; /* XXX */ } @@ -206,26 +216,30 @@ krb5_cc_read_cred (int fd, int ret; int8_t dummy8; 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; - ret = krb5_ret_principal (fd, &creds->server); + ret = krb5_ret_principal (sp, &creds->server); if(ret) return ret; - ret = krb5_ret_keyblock (fd, &creds->session); + ret = krb5_ret_keyblock (sp, &creds->session); if(ret) return ret; - ret = krb5_ret_times (fd, &creds->times); + ret = krb5_ret_times (sp, &creds->times); if(ret) return ret; - ret = krb5_ret_int8 (fd, &dummy8); + ret = krb5_ret_int8 (sp, &dummy8); if(ret) return ret; - ret = krb5_ret_int32 (fd, &dummy32); + ret = krb5_ret_int32 (sp, &dummy32); if(ret) return ret; - ret = krb5_ret_addrs (fd, &creds->addresses); + ret = krb5_ret_addrs (sp, &creds->addresses); if(ret) return ret; - ret = krb5_ret_authdata (fd, &creds->authdata); + ret = krb5_ret_authdata (sp, &creds->authdata); if(ret) return ret; - ret = krb5_ret_data (fd, &creds->ticket); + ret = krb5_ret_data (sp, &creds->ticket); 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; } @@ -256,12 +270,15 @@ krb5_cc_get_principal(krb5_context context, { int fd; int16_t tag; + krb5_storage *sp; fd = open(krb5_cc_get_name(context, id), O_RDONLY); if(fd < 0) return errno; - krb5_ret_int16(fd, &tag); - krb5_ret_principal(fd, principal); + sp = krb5_storage_from_fd(fd); + krb5_ret_int16(sp, &tag); + krb5_ret_principal(sp, principal); + krb5_storage_free(sp); close(fd); return 0; } @@ -273,14 +290,17 @@ krb5_cc_start_seq_get (krb5_context context, { int16_t tag; krb5_principal principal; + krb5_storage *sp; if (id->type != 1) abort (); cursor->fd = open (krb5_cc_get_name (context, id), O_RDONLY); if (cursor->fd < 0) return errno; - krb5_ret_int16 (cursor->fd, &tag); - krb5_ret_principal (cursor->fd, &principal); + sp = krb5_storage_from_fd(cursor->fd); + krb5_ret_int16 (sp, &tag); + krb5_ret_principal (sp, &principal); + krb5_storage_free(sp); krb5_free_principal (principal); return 0; } @@ -291,9 +311,14 @@ krb5_cc_next_cred (krb5_context context, krb5_creds *creds, krb5_cc_cursor *cursor) { + krb5_error_code err; + krb5_storage *sp; if (id->type != 1) 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 @@ -314,11 +339,14 @@ krb5_cc_get_first(krb5_context context, int fd; int16_t tag; krb5_principal principal; + krb5_storage *sp; fd = open(krb5_cc_get_name (context, id), O_RDONLY); cursor->fd = fd; - krb5_ret_int16(fd, &tag); - krb5_ret_principal(fd, &principal); + sp = krb5_storage_from_fd(fd); + krb5_ret_int16(sp, &tag); + krb5_ret_principal(sp, &principal); + krb5_storage_free(sp); return 0; } diff --git a/lib/krb5/keytab.c b/lib/krb5/keytab.c index a87987a4f..d57a76922 100644 --- a/lib/krb5/keytab.c +++ b/lib/krb5/keytab.c @@ -1,5 +1,7 @@ #include "krb5_locl.h" +RCSID("$Id$"); + krb5_error_code krb5_kt_resolve(krb5_context context, const char *name, @@ -147,11 +149,13 @@ krb5_kt_start_seq_get(krb5_context context, { int16_t tag; int ret; + krb5_storage *sp; cursor->fd = open (id->filename, O_RDONLY); if (cursor->fd < 0) 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) return ret; if (tag != 0x0502) @@ -160,48 +164,65 @@ krb5_kt_start_seq_get(krb5_context context, } static krb5_error_code -krb5_kt_ret_data(int fd, - krb5_data *data) +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) { int ret; int16_t size; - - ret = krb5_ret_int16(fd, &size); + ret = krb5_ret_int16(sp, &size); if(ret) return ret; data->length = size; data->data = malloc(size); - ret = read(fd, data->data, size); + ret = sp->fetch(sp, data->data, size); if(ret != size) return (ret < 0)? errno : KRB5_CC_END; return 0; } static krb5_error_code -krb5_kt_ret_principal(int fd, +krb5_kt_ret_principal(krb5_storage *sp, krb5_principal *princ) { int i; int ret; krb5_principal p; int16_t tmp; - + p = ALLOC(1, krb5_principal_data); if(p == NULL) return ENOMEM; + p->type = KRB5_NT_SRV_HST; - ret = krb5_ret_int16(fd, &tmp); + ret = krb5_ret_int16(sp, &tmp); if(ret) return ret; p->ncomp = tmp; - ret = krb5_kt_ret_data(fd, &p->realm); + ret = krb5_kt_ret_data(sp, &p->realm); if(ret) return ret; p->comp = ALLOC(p->ncomp, krb5_data); if(p->comp == NULL){ return ENOMEM; } 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; } *princ = p; @@ -209,15 +230,15 @@ krb5_kt_ret_principal(int fd, } 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; int16_t tmp; - ret = krb5_ret_int16(fd, &tmp); /* keytype + etype */ + ret = krb5_ret_int16(sp, &tmp); /* keytype + etype */ if(ret) return ret; p->keytype = tmp; - ret = krb5_kt_ret_data(fd, &p->contents); + ret = krb5_kt_ret_data(sp, &p->contents); return ret; } @@ -232,23 +253,23 @@ krb5_kt_next_entry(krb5_context context, int ret; int8_t tmp; - ret = krb5_ret_int32(cursor->fd, &len); + ret = krb5_ret_int32(cursor->sp, &len); if (ret) return ret; - ret = krb5_kt_ret_principal (cursor->fd, &entry->principal); + ret = krb5_kt_ret_principal (cursor->sp, &entry->principal); if (ret) return ret; - ret = krb5_ret_int32(cursor->fd, &entry->principal->type); + ret = krb5_ret_int32(cursor->sp, &entry->principal->type); if (ret) return ret; - ret = krb5_ret_int32(cursor->fd, ×tamp); + ret = krb5_ret_int32(cursor->sp, ×tamp); if (ret) return ret; - ret = krb5_ret_int8(cursor->fd, &tmp); + ret = krb5_ret_int8(cursor->sp, &tmp); if (ret) return ret; entry->vno = tmp; - ret = krb5_kt_ret_keyblock (cursor->fd, &entry->keyblock); + ret = krb5_kt_ret_keyblock (cursor->sp, &entry->keyblock); if (ret) return ret; return 0; @@ -259,6 +280,7 @@ krb5_kt_end_seq_get(krb5_context context, krb5_keytab id, krb5_kt_cursor *cursor) { - close (cursor->fd); - return 0; + krb5_storage_free(cursor->sp); + close (cursor->fd); + return 0; }