add rcache code
authorJohn Kohl <jtkohl@mit.edu>
Wed, 27 Feb 1991 12:00:19 +0000 (12:00 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Wed, 27 Feb 1991 12:00:19 +0000 (12:00 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1803 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb425/rd_priv.c
src/lib/krb425/rd_safe.c

index 7aef5f69a9bc2efdfd38ba2f8c78c7f7c2f57f7c..85cbcaed744bca4f9f9d92538371b6f2237edc31 100644 (file)
@@ -2,7 +2,8 @@
  * $Source$
  * $Author$
  *
- * Copyright 1990 by the Massachusetts Institute of Technology.
+ * Copyright 1990,1991 by the Massachusetts Institute of Technology.
+ * All Rights Reserved.
  *
  * For copying and distribution information, please see the file
  * <krb5/copyright.h>.
@@ -15,8 +16,8 @@ static char rcsid_rd_priv_c[] =
 "$Id$";
 #endif /* !lint & !SABER */
 
-#include <krb5/copyright.h>
 #include "krb425.h"
+#include <arpa/inet.h>
 
 long
 krb_rd_priv(in, in_length, sched, key, sender, receiver, msg)
@@ -31,10 +32,11 @@ MSG_DAT *msg;
        krb5_data inbuf;
        krb5_data out;
        krb5_keyblock keyb;
-       krb5_address saddr;
+       krb5_address saddr, *saddr2;
        krb5_address raddr;
        krb5_error_code r;
        char sa[4], ra[4];
+       krb5_rcache rcache;
 
        keyb.keytype = KEYTYPE_DES;
        keyb.length = sizeof(des_cblock);
@@ -54,9 +56,51 @@ MSG_DAT *msg;
        inbuf.data = (char *)in;
        inbuf.length = in_length;
 
-       if (r = krb5_rd_priv(&inbuf, &keyb, &saddr, &raddr, 0, 0, 0, &out)) {
+       if (r = krb5_gen_portaddr(&saddr, (krb5_pointer)&sender->sin_port,
+                                 &saddr2)) {
 #ifdef EBUG
-               ERROR(r)
+           ERROR(r);
+#endif
+           return(-1);
+       }
+       if (rcache = (krb5_rcache) malloc(sizeof(*rcache))) {
+           if (!(r = krb5_rc_resolve_type(&rcache, "dfl"))) {
+               char *cachename;
+               extern krb5_deltat krb5_clockskew;
+               char *insender = inet_ntoa(sender->sin_addr);
+
+               if (cachename = calloc(1, strlen(insender)+1+4+5)) {
+                   /* 1 for NUL, 4 for rc_., 5 for digits of port
+                      (unsigned 16bit, no greater than 65535) */
+                   sprintf(cachename, "rc_%s.%u", insender,
+                           ntohs(receiver->sin_port));
+
+                   if (!(r = krb5_rc_resolve(rcache, cachename))) {
+                       if (!((r = krb5_rc_recover(rcache)) &&
+                             (r = krb5_rc_initialize(rcache,
+                                                     krb5_clockskew)))) {
+                           r = krb5_rd_priv(&inbuf, &keyb, saddr2, &raddr,
+                                            0, 0, 0, rcache, &out);
+                           krb5_rc_close(rcache);
+                       }
+                   }
+                   free(cachename);
+               } else
+                   r = ENOMEM;
+           }
+           xfree(rcache);
+       } else {
+           krb5_free_addr(saddr2);
+#ifdef EBUG
+           ERROR(ENOMEM);
+#endif
+           return(-1);
+       }
+       krb5_free_addr(saddr2);
+
+       if (r) {
+#ifdef EBUG
+               ERROR(r);
 #endif
                return(-1);
        }
index 394a11b4f630d57547f1ca0c9f9d03056f3269dc..e2ef829cee330a55b3463d67401c2d498a5f0d90 100644 (file)
@@ -2,7 +2,8 @@
  * $Source$
  * $Author$
  *
- * Copyright 1990 by the Massachusetts Institute of Technology.
+ * Copyright 1990,1991 by the Massachusetts Institute of Technology.
+ * All Rights Reserved.
  *
  * For copying and distribution information, please see the file
  * <krb5/copyright.h>.
@@ -15,8 +16,8 @@ static char rcsid_rd_safe_c[] =
 "$Id$";
 #endif /* !lint & !SABER */
 
-#include <krb5/copyright.h>
 #include "krb425.h"
+#include <arpa/inet.h>
 
 long
 krb_rd_safe(in, in_length, key, sender, receiver, msg)
@@ -30,10 +31,11 @@ MSG_DAT *msg;
        krb5_data inbuf;
        krb5_data out;
        krb5_keyblock keyb;
-       krb5_address saddr;
+       krb5_address saddr, *saddr2;
        krb5_address raddr;
        krb5_error_code r;
        char sa[4], ra[4];
+       krb5_rcache rcache;
 
        keyb.keytype = KEYTYPE_DES;
        keyb.length = sizeof(des_cblock);
@@ -53,9 +55,50 @@ MSG_DAT *msg;
        inbuf.data = (char *)in;
        inbuf.length = in_length;
 
-       if (r = krb5_rd_safe(&inbuf, &keyb, &saddr, &raddr, 0, 0, &out)) {
+       if (r = krb5_gen_portaddr(&saddr, (krb5_pointer)&sender->sin_port,
+                                 &saddr2)) {
 #ifdef EBUG
-               ERROR(r)
+           ERROR(r);
+#endif
+           return(-1);
+       }
+       if (rcache = (krb5_rcache) malloc(sizeof(*rcache))) {
+           if (!(r = krb5_rc_resolve_type(&rcache, "dfl"))) {
+               char *cachename;
+               extern krb5_deltat krb5_clockskew;
+               char *insender = inet_ntoa(sender->sin_addr);
+
+               if (cachename = calloc(1, strlen(insender)+1+4+5)) {
+                   /* 1 for NUL, 4 for rc_., 5 for digits of port
+                      (unsigned 16bit, no greater than 65535) */
+                   sprintf(cachename, "rc_%s.%u", insender,
+                           ntohs(receiver->sin_port));
+
+                   if (!(r = krb5_rc_resolve(rcache, cachename))) {
+                       if (!((r = krb5_rc_recover(rcache)) &&
+                             (r = krb5_rc_initialize(rcache,
+                                                     krb5_clockskew)))) {
+                           r = krb5_rd_safe(&inbuf, &keyb, saddr2, &raddr,
+                                            0, 0, rcache, &out);
+                           krb5_rc_close(rcache);
+                       }
+                   }
+                   free(cachename);
+               } else
+                   r = ENOMEM;
+           }
+           xfree(rcache);
+       } else {
+           krb5_free_addr(saddr2);
+#ifdef EBUG
+           ERROR(ENOMEM);
+#endif
+           return(-1);
+       }
+       krb5_free_addr(saddr2);
+       if (r) {
+#ifdef EBUG
+               ERROR(r);
 #endif
                return(-1);
        }