From b853b4c82252cd8ef1767e5c1b79440181956716 Mon Sep 17 00:00:00 2001 From: John Kohl Date: Tue, 5 Mar 1991 17:36:03 +0000 Subject: [PATCH] pull common code into library function git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1858 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb425/mk_priv.c | 50 ++++++++++++---------------------------- src/lib/krb425/mk_safe.c | 48 +++++++++++--------------------------- src/lib/krb425/rd_priv.c | 48 +++++++++++++++++--------------------- src/lib/krb425/rd_safe.c | 49 ++++++++++++++++++--------------------- 4 files changed, 72 insertions(+), 123 deletions(-) diff --git a/src/lib/krb425/mk_priv.c b/src/lib/krb425/mk_priv.c index 6aa5b3765..973a9b667 100644 --- a/src/lib/krb425/mk_priv.c +++ b/src/lib/krb425/mk_priv.c @@ -65,47 +65,27 @@ struct sockaddr_in *receiver; } - if (rcache = (krb5_rcache) malloc(sizeof(*rcache))) { - if (!(r = krb5_rc_resolve_type(&rcache, "dfl"))) { - char *cachename; - extern krb5_deltat krb5_clockskew; - char *insender; - - insender = inet_ntoa(sender->sin_addr); - - if (cachename = calloc(1, strlen(insender)+1+3)) { - strcpy(cachename, "rc_"); - strcat(cachename, insender); - - if (!(r = krb5_rc_resolve(rcache, cachename))) { - if (!((r = krb5_rc_recover(rcache)) && - (r = krb5_rc_initialize(rcache, - krb5_clockskew)))) { - r = krb5_mk_priv(&inbuf, - KEYTYPE_DES, - &keyb, - saddr2, &raddr, - 0, /* no sequence number */ - 0, /* default flags (none) */ - rcache, - 0, /* ignore ivec */ - &out5); - krb5_rc_close(rcache); - } - } - free(cachename); - } else - r = ENOMEM; - } - xfree(rcache); - } else { + if (r = krb5_get_server_rcache(inet_ntoa(sender->sin_addr), + &rcache)) { krb5_free_addr(saddr2); #ifdef EBUG - ERROR(ENOMEM); + ERROR(r); #endif return(-1); } + r = krb5_mk_priv(&inbuf, + KEYTYPE_DES, + &keyb, + saddr2, &raddr, + 0, /* no sequence number */ + 0, /* default flags (none) */ + rcache, + 0, /* ignore ivec */ + &out5); + krb5_rc_close(rcache); + xfree(rcache); krb5_free_addr(saddr2); + if (r) { #ifdef EBUG ERROR(r); diff --git a/src/lib/krb425/mk_safe.c b/src/lib/krb425/mk_safe.c index 8d0b39c7a..ddfea2acc 100644 --- a/src/lib/krb425/mk_safe.c +++ b/src/lib/krb425/mk_safe.c @@ -63,46 +63,26 @@ struct sockaddr_in *receiver; 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; - - insender = inet_ntoa(sender->sin_addr); - - if (cachename = calloc(1, strlen(insender)+1+3)) { - strcpy(cachename, "rc_"); - strcat(cachename, insender); - - if (!(r = krb5_rc_resolve(rcache, cachename))) { - if (!((r = krb5_rc_recover(rcache)) && - (r = krb5_rc_initialize(rcache, - krb5_clockskew)))) { - r = krb5_mk_safe(&inbuf, - CKSUMTYPE_RSA_MD4_DES, - &keyb, - saddr2, &raddr, - 0, /* no sequence number */ - 0, /* default flags (none) */ - rcache, - &out5); - krb5_rc_close(rcache); - } - } - free(cachename); - } else - r = ENOMEM; - } - xfree(rcache); - } else { + if (r = krb5_get_server_rcache(inet_ntoa(sender->sin_addr), + &rcache)) { krb5_free_addr(saddr2); #ifdef EBUG - ERROR(ENOMEM); + ERROR(r); #endif return(-1); } + r = krb5_mk_safe(&inbuf, + CKSUMTYPE_RSA_MD4_DES, + &keyb, + saddr2, &raddr, + 0, /* no sequence number */ + 0, /* default flags (none) */ + rcache, + &out5); + krb5_rc_close(rcache); + xfree(rcache); krb5_free_addr(saddr2); + if (r) { #ifdef EBUG ERROR(r); diff --git a/src/lib/krb425/rd_priv.c b/src/lib/krb425/rd_priv.c index b4742fe72..07bb68d6b 100644 --- a/src/lib/krb425/rd_priv.c +++ b/src/lib/krb425/rd_priv.c @@ -37,6 +37,7 @@ MSG_DAT *msg; krb5_error_code r; char sa[4], ra[4]; krb5_rcache rcache; + char *cachename; keyb.keytype = KEYTYPE_DES; keyb.length = sizeof(des_cblock); @@ -63,39 +64,32 @@ MSG_DAT *msg; #endif return(krb425error(r)); } - 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 + if (cachename = calloc(1, strlen(inet_ntoa(sender->sin_addr)+1+1+5))) + /* 1 for NUL, 1 for ., 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); + sprintf(cachename, "%s.%u", inet_ntoa(sender->sin_addr), + ntohs(receiver->sin_port)); + else { #ifdef EBUG ERROR(ENOMEM); #endif return(krb425error(ENOMEM)); } + + if (r = krb5_get_server_rcache(cachename, + &rcache)) { + krb5_free_addr(saddr2); +#ifdef EBUG + ERROR(r); +#endif + return(-1); + } + free(cachename); + r = krb5_rd_priv(&inbuf, &keyb, saddr2, &raddr, + 0, 0, 0, rcache, &out); + krb5_rc_close(rcache); + xfree(rcache); + krb5_free_addr(saddr2); if (r) { diff --git a/src/lib/krb425/rd_safe.c b/src/lib/krb425/rd_safe.c index 077b9ec46..23cb9fc4d 100644 --- a/src/lib/krb425/rd_safe.c +++ b/src/lib/krb425/rd_safe.c @@ -36,6 +36,7 @@ MSG_DAT *msg; krb5_error_code r; char sa[4], ra[4]; krb5_rcache rcache; + char *cachename; keyb.keytype = KEYTYPE_DES; keyb.length = sizeof(des_cblock); @@ -62,40 +63,34 @@ MSG_DAT *msg; #endif return(krb425error(r)); } - 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 + if (cachename = calloc(1, strlen(inet_ntoa(sender->sin_addr)+1+1+5))) + /* 1 for NUL, 1 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); + sprintf(cachename, "%s.%u", inet_ntoa(sender->sin_addr), + ntohs(receiver->sin_port)); + else { #ifdef EBUG ERROR(ENOMEM); #endif return(krb425error(ENOMEM)); } + + if (r = krb5_get_server_rcache(cachename, + &rcache)) { + krb5_free_addr(saddr2); +#ifdef EBUG + ERROR(r); +#endif + return(-1); + } + free(cachename); + r = krb5_rd_safe(&inbuf, &keyb, saddr2, &raddr, + 0, 0, rcache, &out); + krb5_rc_close(rcache); + xfree(rcache); + krb5_free_addr(saddr2); + if (r) { #ifdef EBUG ERROR(r); -- 2.26.2