diff --git a/lib/krb5/cache.c b/lib/krb5/cache.c index ae9d08a4a..75d1ef459 100644 --- a/lib/krb5/cache.c +++ b/lib/krb5/cache.c @@ -2,8 +2,9 @@ /* XXX shouldn't be here */ -void krb5_free_ccache(krb5_context context, - krb5_ccache val) +void +krb5_free_ccache(krb5_context context, + krb5_ccache val) { free(((krb5_fcache*)(val->data.data))->filename); krb5_data_free (&val->data); @@ -98,278 +99,6 @@ krb5_cc_default(krb5_context context, id); } -static krb5_error_code -store_int32(int fd, - int32_t value) -{ - int ret; - - value = htonl(value); - ret = write(fd, &value, sizeof(value)); - if (ret != sizeof(value)) - return (ret<0)?errno:KRB5_CC_END; - return 0; -} - -static krb5_error_code -ret_int32(int fd, - int32_t *value) -{ - int32_t v; - int ret; - ret = read(fd, &v, sizeof(v)); - if(ret != sizeof(v)) - return (ret<0)?errno:KRB5_CC_END; - - *value = ntohl(v); - return 0; -} - -static krb5_error_code -store_int16(int fd, - int16_t value) -{ - int ret; - - value = htons(value); - ret = write(fd, &value, sizeof(value)); - if (ret != sizeof(value)) - return (ret<0)?errno:KRB5_CC_END; - return 0; -} - -static krb5_error_code -ret_int16(int fd, - int16_t *value) -{ - int16_t v; - int ret; - ret = read(fd, &v, sizeof(v)); - if(ret != sizeof(v)) - return (ret<0)?errno:KRB5_CC_END; /* XXX */ - - *value = ntohs(v); - return 0; -} - -static krb5_error_code -store_int8(int fd, - int8_t value) -{ - int ret; - - ret = write(fd, &value, sizeof(value)); - if (ret != sizeof(value)) - return (ret<0)?errno:KRB5_CC_END; - return 0; -} - -static krb5_error_code -ret_int8(int fd, - int8_t *value) -{ - int ret; - - ret = read (fd, value, sizeof(*value)); - if (ret != sizeof(*value)) - return (ret<0)?errno:KRB5_CC_END; - return 0; -} - -static krb5_error_code -store_data(int fd, - krb5_data data) -{ - int ret; - ret = store_int32(fd, data.length); - if(ret < 0) - return ret; - ret = write(fd, data.data, data.length); - if(ret != data.length){ - if(ret < 0) - return errno; - return KRB5_CC_END; - } - return 0; -} - -static krb5_error_code -ret_data(int fd, - krb5_data *data) -{ - int ret; - int size; - ret = ret_int32(fd, &size); - if(ret) - return ret; - data->length = size; - data->data = malloc(size); - ret = read(fd, data->data, size); - if(ret != size) - return (ret < 0)? errno : KRB5_CC_END; - return 0; -} - -static krb5_error_code -store_principal(int fd, - krb5_principal p) -{ - int i; - int ret; - ret = store_int32(fd, p->type); - if(ret) return ret; - ret = store_int32(fd, p->ncomp); - if(ret) return ret; - ret = store_data(fd, p->realm); - if(ret) return ret; - for(i = 0; i < p->ncomp; i++){ - ret = store_data(fd, p->comp[i]); - if(ret) return ret; - } - return 0; -} - -static krb5_error_code -ret_principal(int fd, - krb5_principal *princ) -{ - int i; - int ret; - krb5_principal p; - - p = ALLOC(1, krb5_principal_data); - if(p == NULL) - return ENOMEM; - - if((ret = ret_int32(fd, &p->type))) - return ret; - ret = ret_int32(fd, &p->ncomp); - if(ret) return ret; - ret = ret_data(fd, &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 = ret_data(fd, &p->comp[i]); - if(ret) return ret; - } - *princ = p; - return 0; -} - -static krb5_error_code -store_keyblock(int fd, krb5_keyblock p) -{ - int ret; - ret =store_int32(fd, p.keytype); - if(ret) return ret; - ret = store_data(fd, p.contents); - return ret; -} - -static krb5_error_code -ret_keyblock(int fd, krb5_keyblock *p) -{ - int ret; - ret = ret_int32(fd, (int32_t*)&p->keytype); /* keytype + etype */ - if(ret) return ret; - ret = ret_data(fd, &p->contents); - return ret; -} - -static krb5_error_code -store_times(int fd, krb5_times times) -{ - int ret; - ret = store_int32(fd, times.authtime); - if(ret) return ret; - ret = store_int32(fd, times.starttime); - if(ret) return ret; - ret = store_int32(fd, times.endtime); - if(ret) return ret; - ret = store_int32(fd, times.renew_till); - return ret; -} - -static krb5_error_code -ret_times(int fd, krb5_times *times) -{ - int ret; - ret = ret_int32(fd, ×->authtime); - if(ret) return ret; - ret = ret_int32(fd, ×->starttime); - if(ret) return ret; - ret = ret_int32(fd, ×->endtime); - if(ret) return ret; - ret = ret_int32(fd, ×->renew_till); - return ret; -} - -static krb5_error_code -store_address(int fd, krb5_address p) -{ - int ret; - ret = store_int16(fd, p.type); - if(ret) return ret; - ret = store_data(fd, p.address); - return ret; -} - -static krb5_error_code -ret_address(int fd, krb5_address *adr) -{ - int16_t t; - int ret; - ret = ret_int16(fd, &t); - if(ret) return ret; - adr->type = t; - ret = ret_data(fd, &adr->address); - return ret; -} - -static krb5_error_code -store_addrs(int fd, krb5_addresses p) -{ - int i; - int ret; - ret = store_int32(fd, p.number); - if(ret) return ret; - for(i = 0; i