add address support
authorJohn Kohl <jtkohl@mit.edu>
Fri, 4 May 1990 17:46:00 +0000 (17:46 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Fri, 4 May 1990 17:46:00 +0000 (17:46 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@742 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/ccache/file/fcc-proto.h
src/lib/krb5/ccache/file/fcc_nseq.c
src/lib/krb5/ccache/file/fcc_read.c
src/lib/krb5/ccache/file/fcc_store.c
src/lib/krb5/ccache/file/fcc_write.c

index a59a35a11d02bbd82658e7d18b756b46105a0d84..920222422c6ff9e2d0fcf384ec49387784a38f2a 100644 (file)
@@ -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 ));
index a6dc1b7f4623325b538e4052860eda709f7d0f4c..8038ba6de9bd59c0d4739daebf42ceafb500632a 100644 (file)
@@ -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;
 }
index c3a94ab71b0e17c66d13316a9d514a812c3c14d2..3886062b76a9c24451ffb072275470fae514e30e 100644 (file)
@@ -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
@@ -158,6 +264,14 @@ krb5_fcc_read_int32(id, i)
      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;
index af5d3cf3834c8702378700454bd879fa29ba87b7..26f350c8bee06e66534f1d5931debd6fdabff21a 100644 (file)
@@ -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);
index afff300de9d6f100365aa557ce222369c57698e1..827d92b3587cf27beb85dd3f0f6978915d257148 100644 (file)
@@ -82,6 +82,30 @@ krb5_fcc_store_principal(id, princ)
      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;
@@ -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)