aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorJohn Kohl <jtkohl@mit.edu>1990-05-04 17:46:00 +0000
committerJohn Kohl <jtkohl@mit.edu>1990-05-04 17:46:00 +0000
commitbe773340f439e993c1ff0cd534b85e59e4d6adb9 (patch)
tree405c7849584b74130f113cb8fe27e22089c89558 /src/lib
parent231f6f5e12248513a527464b64f31ede072c0c42 (diff)
downloadkrb5-be773340f439e993c1ff0cd534b85e59e4d6adb9.zip
krb5-be773340f439e993c1ff0cd534b85e59e4d6adb9.tar.gz
krb5-be773340f439e993c1ff0cd534b85e59e4d6adb9.tar.bz2
add address support
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@742 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/krb5/ccache/file/fcc-proto.h6
-rw-r--r--src/lib/krb5/ccache/file/fcc_nseq.c7
-rw-r--r--src/lib/krb5/ccache/file/fcc_read.c138
-rw-r--r--src/lib/krb5/ccache/file/fcc_store.c2
-rw-r--r--src/lib/krb5/ccache/file/fcc_write.c54
5 files changed, 194 insertions, 13 deletions
diff --git a/src/lib/krb5/ccache/file/fcc-proto.h b/src/lib/krb5/ccache/file/fcc-proto.h
index a59a35a..9202224 100644
--- a/src/lib/krb5/ccache/file/fcc-proto.h
+++ b/src/lib/krb5/ccache/file/fcc-proto.h
@@ -48,11 +48,14 @@ krb5_error_code krb5_fcc_read_principal PROTOTYPE((krb5_ccache id , krb5_princip
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 ));
@@ -80,11 +83,14 @@ krb5_error_code krb5_fcc_store_principal PROTOTYPE((krb5_ccache id , krb5_princi
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 ));
diff --git a/src/lib/krb5/ccache/file/fcc_nseq.c b/src/lib/krb5/ccache/file/fcc_nseq.c
index a6dc1b7..8038ba6 100644
--- a/src/lib/krb5/ccache/file/fcc_nseq.c
+++ b/src/lib/krb5/ccache/file/fcc_nseq.c
@@ -51,6 +51,8 @@ krb5_fcc_next_cred(id, cursor, creds)
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)
@@ -76,6 +78,8 @@ krb5_fcc_next_cred(id, cursor, creds)
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);
@@ -89,6 +93,7 @@ krb5_fcc_next_cred(id, cursor, creds)
((krb5_fcc_data *) id->data)->fd = -1;
}
lose:
-
+ if (kret != KRB5_OK)
+ krb5_free_creds(creds);
return kret;
}
diff --git a/src/lib/krb5/ccache/file/fcc_read.c b/src/lib/krb5/ccache/file/fcc_read.c
index c3a94ab..3886062 100644
--- a/src/lib/krb5/ccache/file/fcc_read.c
+++ b/src/lib/krb5/ccache/file/fcc_read.c
@@ -18,7 +18,7 @@ static char fcc_read_c[] = "$Id$";
#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:
@@ -71,6 +71,8 @@ krb5_fcc_read_principal(id, princ)
krb5_int32 length;
int i;
+ *princ = 0;
+
/* Read the number of components */
kret = krb5_fcc_read_int32(id, &length);
CHECK(kret);
@@ -89,17 +91,60 @@ krb5_fcc_read_principal(id, princ)
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
@@ -110,6 +155,8 @@ krb5_fcc_read_keyblock(id, keyblock)
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);
@@ -122,10 +169,20 @@ krb5_fcc_read_keyblock(id, keyblock)
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
@@ -136,6 +193,8 @@ krb5_fcc_read_data(id, data)
krb5_error_code kret;
int ret;
+ data->data = 0;
+
kret = krb5_fcc_read_int32(id, &data->length);
CHECK(kret);
@@ -143,11 +202,58 @@ krb5_fcc_read_data(id, data)
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
@@ -159,6 +265,14 @@ krb5_fcc_read_int32(id, i)
}
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;
krb5_keytype *k;
diff --git a/src/lib/krb5/ccache/file/fcc_store.c b/src/lib/krb5/ccache/file/fcc_store.c
index af5d3cf..26f350c 100644
--- a/src/lib/krb5/ccache/file/fcc_store.c
+++ b/src/lib/krb5/ccache/file/fcc_store.c
@@ -64,6 +64,8 @@ krb5_fcc_store(id, creds)
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);
diff --git a/src/lib/krb5/ccache/file/fcc_write.c b/src/lib/krb5/ccache/file/fcc_write.c
index afff300..827d92b 100644
--- a/src/lib/krb5/ccache/file/fcc_write.c
+++ b/src/lib/krb5/ccache/file/fcc_write.c
@@ -83,6 +83,30 @@ krb5_fcc_store_principal(id, princ)
}
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;
krb5_keyblock *keyblock;
@@ -97,10 +121,32 @@ krb5_fcc_store_keyblock(id, keyblock)
(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)
@@ -125,6 +171,14 @@ krb5_fcc_store_int32(id, i)
{
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)