Add better error checking some useful return values.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1135 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1996-12-17 23:55:36 +00:00
parent b28882bc5d
commit 866a8e6f87

View File

@@ -20,7 +20,7 @@ krb5_cc_resolve(krb5_context context,
krb5_fcache *f; krb5_fcache *f;
if(strncmp(residual, "FILE:", 5)){ if(strncmp(residual, "FILE:", 5)){
return -1; return KRB5_CC_UNKNOWN_TYPE;
} }
p = ALLOC(1, krb5_ccache_data); p = ALLOC(1, krb5_ccache_data);
@@ -107,7 +107,7 @@ store_int32(int fd,
value = htonl(value); value = htonl(value);
ret = write(fd, &value, sizeof(value)); ret = write(fd, &value, sizeof(value));
if (ret != sizeof(value)) if (ret != sizeof(value))
return (ret<0)?errno:-1; return (ret<0)?errno:KRB5_CC_END;
return 0; return 0;
} }
@@ -119,7 +119,7 @@ ret_int32(int fd,
int ret; int ret;
ret = read(fd, &v, sizeof(v)); ret = read(fd, &v, sizeof(v));
if(ret != sizeof(v)) if(ret != sizeof(v))
return (ret<0)?errno:-1; /* XXX */ return (ret<0)?errno:KRB5_CC_END;
*value = ntohl(v); *value = ntohl(v);
return 0; return 0;
@@ -134,7 +134,7 @@ store_int16(int fd,
value = htons(value); value = htons(value);
ret = write(fd, &value, sizeof(value)); ret = write(fd, &value, sizeof(value));
if (ret != sizeof(value)) if (ret != sizeof(value))
return (ret<0)?errno:-1; return (ret<0)?errno:KRB5_CC_END;
return 0; return 0;
} }
@@ -146,7 +146,7 @@ ret_int16(int fd,
int ret; int ret;
ret = read(fd, &v, sizeof(v)); ret = read(fd, &v, sizeof(v));
if(ret != sizeof(v)) if(ret != sizeof(v))
return (ret<0)?errno:-1; /* XXX */ return (ret<0)?errno:KRB5_CC_END; /* XXX */
*value = ntohs(v); *value = ntohs(v);
return 0; return 0;
@@ -160,7 +160,7 @@ store_int8(int fd,
ret = write(fd, &value, sizeof(value)); ret = write(fd, &value, sizeof(value));
if (ret != sizeof(value)) if (ret != sizeof(value))
return (ret<0)?errno:-1; return (ret<0)?errno:KRB5_CC_END;
return 0; return 0;
} }
@@ -172,7 +172,7 @@ ret_int8(int fd,
ret = read (fd, value, sizeof(*value)); ret = read (fd, value, sizeof(*value));
if (ret != sizeof(*value)) if (ret != sizeof(*value))
return (ret<0)?errno:-1; return (ret<0)?errno:KRB5_CC_END;
return 0; return 0;
} }
@@ -184,7 +184,13 @@ store_data(int fd,
ret = store_int32(fd, data.length); ret = store_int32(fd, data.length);
if(ret < 0) if(ret < 0)
return ret; return ret;
return write(fd, data.data, data.length); 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 static krb5_error_code
@@ -194,11 +200,13 @@ ret_data(int fd,
int ret; int ret;
int size; int size;
ret = ret_int32(fd, &size); ret = ret_int32(fd, &size);
if(ret)
return ret;
data->length = size; data->length = size;
data->data = malloc(size); data->data = malloc(size);
ret = read(fd, data->data, size); ret = read(fd, data->data, size);
if(ret != size) if(ret != size)
return (ret < 0)? errno : -1; /* XXX */ return (ret < 0)? errno : KRB5_CC_END;
return 0; return 0;
} }
@@ -207,11 +215,17 @@ store_principal(int fd,
krb5_principal p) krb5_principal p)
{ {
int i; int i;
store_int32(fd, p->type); int ret;
store_int32(fd, p->ncomp); ret = store_int32(fd, p->type);
store_data(fd, p->realm); if(ret) return ret;
for(i = 0; i < p->ncomp; i++) ret = store_int32(fd, p->ncomp);
store_data(fd, p->comp[i]); 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; return 0;
} }
@@ -220,17 +234,27 @@ ret_principal(int fd,
krb5_principal *princ) krb5_principal *princ)
{ {
int i; int i;
int ret;
krb5_principal p; krb5_principal p;
p = ALLOC(1, krb5_principal_data); p = ALLOC(1, krb5_principal_data);
if(p == NULL)
return ENOMEM;
if(ret_int32(fd, &p->type)) if((ret = ret_int32(fd, &p->type)))
return -1; return ret;
ret_int32(fd, &p->ncomp); ret = ret_int32(fd, &p->ncomp);
ret_data(fd, &p->realm); if(ret) return ret;
ret = ret_data(fd, &p->realm);
if(ret) return ret;
p->comp = ALLOC(p->ncomp, krb5_data); p->comp = ALLOC(p->ncomp, krb5_data);
for(i = 0; i < p->ncomp; i++) if(p->comp == NULL){
ret_data(fd, &p->comp[i]); return ENOMEM;
}
for(i = 0; i < p->ncomp; i++){
ret = ret_data(fd, &p->comp[i]);
if(ret) return ret;
}
*princ = p; *princ = p;
return 0; return 0;
} }
@@ -238,90 +262,112 @@ ret_principal(int fd,
static krb5_error_code static krb5_error_code
store_keyblock(int fd, krb5_keyblock p) store_keyblock(int fd, krb5_keyblock p)
{ {
store_int32(fd, p.keytype); int ret;
store_data(fd, p.contents); ret =store_int32(fd, p.keytype);
return 0; if(ret) return ret;
ret = store_data(fd, p.contents);
return ret;
} }
static krb5_error_code static krb5_error_code
ret_keyblock(int fd, krb5_keyblock *p) ret_keyblock(int fd, krb5_keyblock *p)
{ {
ret_int32(fd, (int32_t*)&p->keytype); /* keytype + etype */ int ret;
ret_data(fd, &p->contents); ret = ret_int32(fd, (int32_t*)&p->keytype); /* keytype + etype */
return 0; if(ret) return ret;
ret = ret_data(fd, &p->contents);
return ret;
} }
static krb5_error_code static krb5_error_code
store_times(int fd, krb5_times times) store_times(int fd, krb5_times times)
{ {
store_int32(fd, times.authtime); int ret;
store_int32(fd, times.starttime); ret = store_int32(fd, times.authtime);
store_int32(fd, times.endtime); if(ret) return ret;
store_int32(fd, times.renew_till); ret = store_int32(fd, times.starttime);
return 0; 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 static krb5_error_code
ret_times(int fd, krb5_times *times) ret_times(int fd, krb5_times *times)
{ {
ret_int32(fd, &times->authtime); int ret;
ret_int32(fd, &times->starttime); ret = ret_int32(fd, &times->authtime);
ret_int32(fd, &times->endtime); if(ret) return ret;
ret_int32(fd, &times->renew_till); ret = ret_int32(fd, &times->starttime);
return 0; if(ret) return ret;
ret = ret_int32(fd, &times->endtime);
if(ret) return ret;
ret = ret_int32(fd, &times->renew_till);
return ret;
} }
static krb5_error_code static krb5_error_code
store_address(int fd, krb5_address p) store_address(int fd, krb5_address p)
{ {
store_int16(fd, p.type); int ret;
store_data(fd, p.address); ret = store_int16(fd, p.type);
return 0; if(ret) return ret;
ret = store_data(fd, p.address);
return ret;
} }
static krb5_error_code static krb5_error_code
ret_address(int fd, krb5_address *adr) ret_address(int fd, krb5_address *adr)
{ {
int16_t t; int16_t t;
ret_int16(fd, &t); int ret;
ret = ret_int16(fd, &t);
if(ret) return ret;
adr->type = t; adr->type = t;
ret_data(fd, &adr->address); ret = ret_data(fd, &adr->address);
return 0; return ret;
} }
static krb5_error_code static krb5_error_code
store_addrs(int fd, krb5_addresses p) store_addrs(int fd, krb5_addresses p)
{ {
int i; int i;
store_int32(fd, p.number); int ret;
for(i = 0; i<p.number; i++) ret = store_int32(fd, p.number);
store_address(fd, p.addrs[i]); if(ret) return ret;
return 0; for(i = 0; i<p.number; i++){
ret = store_address(fd, p.addrs[i]);
if(ret) break;
}
return ret;
} }
static krb5_error_code static krb5_error_code
ret_addrs(int fd, krb5_addresses *adr) ret_addrs(int fd, krb5_addresses *adr)
{ {
int i; int i;
ret_int32(fd, &adr->number); int ret;
ret = ret_int32(fd, &adr->number);
if(ret) return ret;
adr->addrs = ALLOC(adr->number, krb5_address); adr->addrs = ALLOC(adr->number, krb5_address);
for(i = 0; i < adr->number; i++) for(i = 0; i < adr->number; i++){
ret_address(fd, &adr->addrs[i]); ret = ret_address(fd, &adr->addrs[i]);
return 0; if(ret) break;
}
return ret;
} }
static krb5_error_code static krb5_error_code
store_authdata(int fd, krb5_data p) store_authdata(int fd, krb5_data p)
{ {
store_data(fd, p); return store_data(fd, p);
return 0;
} }
static krb5_error_code static krb5_error_code
ret_authdata(int fd, krb5_data *auth) ret_authdata(int fd, krb5_data *auth)
{ {
ret_data(fd, auth); return ret_data(fd, auth);
return 0;
} }
krb5_error_code krb5_error_code