From 626d558bcf11cbafc8f78ae5e5f38d1274fb862e Mon Sep 17 00:00:00 2001 From: John Kohl Date: Wed, 27 Feb 1991 12:00:19 +0000 Subject: [PATCH] add rcache code git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1803 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb425/rd_priv.c | 54 ++++++++++++++++++++++++++++++++++++---- src/lib/krb425/rd_safe.c | 53 +++++++++++++++++++++++++++++++++++---- 2 files changed, 97 insertions(+), 10 deletions(-) diff --git a/src/lib/krb425/rd_priv.c b/src/lib/krb425/rd_priv.c index 7aef5f69a..85cbcaed7 100644 --- a/src/lib/krb425/rd_priv.c +++ b/src/lib/krb425/rd_priv.c @@ -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 * . @@ -15,8 +16,8 @@ static char rcsid_rd_priv_c[] = "$Id$"; #endif /* !lint & !SABER */ -#include #include "krb425.h" +#include 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); } diff --git a/src/lib/krb425/rd_safe.c b/src/lib/krb425/rd_safe.c index 394a11b4f..e2ef829ce 100644 --- a/src/lib/krb425/rd_safe.c +++ b/src/lib/krb425/rd_safe.c @@ -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 * . @@ -15,8 +16,8 @@ static char rcsid_rd_safe_c[] = "$Id$"; #endif /* !lint & !SABER */ -#include #include "krb425.h" +#include 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); } -- 2.26.2