krb5_error_code krb5_fcc_read_keyblock PROTOTYPE((krb5_ccache id , krb5_keyblock *keyblock ));
krb5_error_code krb5_fcc_read_data PROTOTYPE((krb5_ccache id , krb5_data *data ));
krb5_error_code krb5_fcc_read_int32 PROTOTYPE((krb5_ccache id , krb5_int32 *i ));
+krb5_error_code krb5_fcc_read_int16 PROTOTYPE((krb5_ccache id , krb5_int16 *i ));
krb5_error_code krb5_fcc_read_keytype PROTOTYPE((krb5_ccache id , krb5_keytype *k ));
krb5_error_code krb5_fcc_read_int PROTOTYPE((krb5_ccache id , int *i ));
krb5_error_code krb5_fcc_read_bool PROTOTYPE((krb5_ccache id , krb5_boolean *b ));
krb5_error_code krb5_fcc_read_times PROTOTYPE((krb5_ccache id , krb5_ticket_times *t ));
krb5_error_code krb5_fcc_read_flags PROTOTYPE((krb5_ccache id , krb5_flags *f ));
+krb5_error_code krb5_fcc_read_addrs PROTOTYPE((krb5_ccache, krb5_address ***));
+krb5_error_code krb5_fcc_read_addr PROTOTYPE((krb5_ccache, krb5_address *));
/* fcc_reslv.c */
krb5_error_code krb5_fcc_resolve PROTOTYPE((krb5_ccache *id , char *residual ));
krb5_error_code krb5_fcc_store_keyblock PROTOTYPE((krb5_ccache id , krb5_keyblock *keyblock ));
krb5_error_code krb5_fcc_store_data PROTOTYPE((krb5_ccache id , krb5_data *data ));
krb5_error_code krb5_fcc_store_int32 PROTOTYPE((krb5_ccache id , krb5_int32 *i ));
+krb5_error_code krb5_fcc_store_int16 PROTOTYPE((krb5_ccache id , krb5_int16 *i ));
krb5_error_code krb5_fcc_store_keytype PROTOTYPE((krb5_ccache id , krb5_keytype *k ));
krb5_error_code krb5_fcc_store_int PROTOTYPE((krb5_ccache id , int *i ));
krb5_error_code krb5_fcc_store_bool PROTOTYPE((krb5_ccache id , krb5_boolean *b ));
krb5_error_code krb5_fcc_store_times PROTOTYPE((krb5_ccache id , krb5_ticket_times *t ));
krb5_error_code krb5_fcc_store_flags PROTOTYPE((krb5_ccache id , krb5_flags *f ));
+krb5_error_code krb5_fcc_store_addrs PROTOTYPE((krb5_ccache id , krb5_addresses ** ));
+krb5_error_code krb5_fcc_store_addr PROTOTYPE((krb5_ccache id , krb5_address * ));
/* fcc_test.c */
void init_test_cred PROTOTYPE((void ));
krb5_error_code kret;
krb5_fcc_cursor *fcursor;
+ bzero((char *)creds, sizeof(*creds));
+
if (OPENCLOSE(id)) {
ret = open(((krb5_fcc_data *) id->data)->filename, O_RDONLY, 0);
if (ret < 0)
TCHECK(kret);
kret = krb5_fcc_read_flags(id, &creds->ticket_flags);
TCHECK(kret);
+ kret = krb5_fcc_read_addrs(id, &creds->addresses);
+ TCHECK(kret);
kret = krb5_fcc_read_data(id, &creds->ticket);
TCHECK(kret);
kret = krb5_fcc_read_data(id, &creds->second_ticket);
((krb5_fcc_data *) id->data)->fd = -1;
}
lose:
-
+ if (kret != KRB5_OK)
+ krb5_free_creds(creds);
return kret;
}
#include <krb5/copyright.h>
#include "fcc.h"
-#define CHECK(ret) if (ret != KRB5_OK) return ret;
+#define CHECK(ret) if (ret != KRB5_OK) goto errout;
/*
* Effects:
krb5_int32 length;
int i;
+ *princ = 0;
+
/* Read the number of components */
kret = krb5_fcc_read_int32(id, &length);
CHECK(kret);
if (*princ == NULL)
return KRB5_NOMEM;
- /* XXX Memory leak XXX */
for (i=0; i < length; i++) {
(*princ)[i] = (krb5_data *) malloc(sizeof(krb5_data));
- if ((*princ)[i] == NULL)
- return KRB5_NOMEM;
-
+ if ((*princ)[i] == NULL) {
+ krb5_free_principal(*princ);
+ return KRB5_NOMEM;
+ }
kret = krb5_fcc_read_data(id, (*princ)[i]);
CHECK(kret);
}
+ return kret;
+ errout:
+ if (*princ)
+ krb5_free_principal(*princ);
+ return kret;
+}
+
+krb5_error_code
+krb5_fcc_read_addrs(id, addrs)
+ krb5_ccache id;
+ krb5_address ***addrs;
+{
+ krb5_error_code kret;
+ krb5_int32 length;
+ int i;
+
+ *addrs = 0;
+
+ /* Read the number of components */
+ kret = krb5_fcc_read_int32(id, &length);
+ CHECK(kret);
+
+ /* Make *addrs able to hold length pointers to krb5_address structs
+ * Add one extra for a null-terminated list
+ */
+ *addrs = (krb5_address **) calloc(length+1, sizeof(krb5_address *));
+ if (*addrs == NULL)
+ return KRB5_NOMEM;
+
+ for (i=0; i < length; i++) {
+ (*addrs)[i] = (krb5_address *) malloc(sizeof(krb5_address));
+ if ((*addrs)[i] == NULL) {
+ krb5_free_address(*addrs);
+ return KRB5_NOMEM;
+ }
+ kret = krb5_fcc_read_addr(id, (*addrs)[i]);
+ CHECK(kret);
+ }
+
return KRB5_OK;
+ errout:
+ if (*addrs)
+ krb5_free_address(*addrs);
+ return kret;
}
krb5_error_code
krb5_error_code kret;
int ret;
+ keyblock->contents = 0;
+
kret = krb5_fcc_read_keytype(id, &keyblock->keytype);
CHECK(kret);
kret = krb5_fcc_read_int(id, &keyblock->length);
ret = read(((krb5_fcc_data *) id->data)->fd, (char *)keyblock->contents,
(keyblock->length)*sizeof(krb5_octet));
- if (ret < 0)
- return errno;
- else
- return KRB5_OK;
+ if (ret < 0) {
+ xfree(keyblock->contents);
+ return errno;
+ }
+ if (ret != (keyblock->length)*sizeof(krb5_octet)) {
+ xfree(keyblock->contents);
+ return KRB5_EOF;
+ }
+
+ return KRB5_OK;
+ errout:
+ if (keyblock->contents)
+ xfree(keyblock->contents);
+ return kret;
}
krb5_error_code
krb5_error_code kret;
int ret;
+ data->data = 0;
+
kret = krb5_fcc_read_int32(id, &data->length);
CHECK(kret);
if (data->data == NULL)
return KRB5_NOMEM;
- ret = read(((krb5_fcc_data *) id->data)->fd, data->data, data->length);
- if (ret == -1)
- return errno;
+ ret = read(((krb5_fcc_data *) id->data)->fd, (char *)data->data,
+ data->length);
+ if (ret == -1) {
+ xfree(data->data);
+ return errno;
+ }
+ if (ret != data->length) {
+ xfree(data->data);
+ return KRB5_EOF;
+ }
+ return KRB5_OK;
+ errout:
+ if (data->data)
+ xfree(data->data);
+ return kret;
+}
+
+krb5_error_code
+krb5_fcc_read_addr(id, addr)
+ krb5_ccache id;
+ krb5_address *addr;
+{
+ krb5_error_code kret;
+ int ret;
+
+ addr->contents = 0;
+ kret = krb5_fcc_read_int16(id, &addr->addrtype);
+ CHECK(kret);
+
+ kret = krb5_fcc_read_int(id, &addr->length);
+ CHECK(kret);
+
+ addr->contents = (krb5_octet *) malloc(addr->length);
+ if (addr->contents == NULL)
+ return KRB5_NOMEM;
+
+ ret = read(((krb5_fcc_data *) id->data)->fd, (char *)addr->contents,
+ (addr->length)*sizeof(krb5_octet));
+ if (ret == -1) {
+ xfree(addr->contents);
+ return errno;
+ }
+ if (ret != (addr->length)*sizeof(krb5_octet)) {
+ xfree(addr->contents);
+ return KRB5_EOF;
+ }
return KRB5_OK;
+ errout:
+ if (addr->contents)
+ xfree(addr->contents);
+ return kret;
}
krb5_error_code
return krb5_fcc_read(id, (krb5_pointer) i, sizeof(krb5_int32));
}
+krb5_error_code
+krb5_fcc_read_int16(id, i)
+ krb5_ccache id;
+ krb5_int16 *i;
+{
+ return krb5_fcc_read(id, (krb5_pointer) i, sizeof(krb5_int16));
+}
+
krb5_error_code
krb5_fcc_read_keytype(id, k)
krb5_ccache id;
TCHECK(ret);
ret = krb5_fcc_store_flags(id, &creds->ticket_flags);
TCHECK(ret);
+ ret = krb5_fcc_store_addrs(id, creds->addresses);
+ TCHECK(ret);
ret = krb5_fcc_store_data(id, &creds->ticket);
TCHECK(ret);
ret = krb5_fcc_store_data(id, &creds->second_ticket);
return KRB5_OK;
}
+krb5_error_code
+krb5_fcc_store_addrs(id, addrs)
+ krb5_ccache id;
+ krb5_address ** addrs;
+{
+ krb5_error_code ret;
+ krb5_address **temp;
+ krb5_int32 i, length = 0;
+
+ /* Count the number of components */
+ temp = addrs;
+ while (*temp++)
+ length += 1;
+
+ ret = krb5_fcc_store_int32(id, &length);
+ CHECK(ret);
+ for (i=0; i < length; i++) {
+ ret = krb5_fcc_store_addr(id, addrs[i]);
+ CHECK(ret);
+ }
+
+ return KRB5_OK;
+}
+
krb5_error_code
krb5_fcc_store_keyblock(id, keyblock)
krb5_ccache id;
(keyblock->length)*sizeof(krb5_octet));
if (ret < 0)
return errno;
+ if (ret != (keyblock->length)*sizeof(krb5_octet))
+ return KRB5_EOF;
return KRB5_OK;
}
+krb5_error_code
+krb5_fcc_store_addr(id, addr)
+ krb5_ccache id;
+ krb5_address *addr;
+{
+ krb5_error_code ret;
+
+ ret = krb5_fcc_store_int16(id, &addr->addrtype);
+ CHECK(ret);
+ ret = krb5_fcc_store_int(id, &addr->length);
+ CHECK(ret);
+ ret = write(((krb5_fcc_data *) id->data)->fd, (char *)addr->contents,
+ (addr->length)*sizeof(krb5_octet));
+ if (ret < 0)
+ return errno;
+ if (ret != (addr->length)*sizeof(krb5_octet))
+ return KRB5_EOF;
+ return KRB5_OK;
+}
+
krb5_error_code
krb5_fcc_store_data(id, data)
{
return krb5_fcc_write(id, (char *) i, sizeof(krb5_int32));
}
+
+krb5_error_code
+krb5_fcc_store_int16(id, i)
+ krb5_ccache id;
+ krb5_int16 *i;
+{
+ return krb5_fcc_write(id, (char *) i, sizeof(krb5_int16));
+}
krb5_error_code
krb5_fcc_store_keytype(id, k)