pull common code into library function
authorJohn Kohl <jtkohl@mit.edu>
Tue, 5 Mar 1991 17:36:03 +0000 (17:36 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Tue, 5 Mar 1991 17:36:03 +0000 (17:36 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1858 dc483132-0cff-0310-8789-dd5450dbe970

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

index 6aa5b3765115ff5975e6b7ab64e098c0f4a9b002..973a9b6678114836f572f35e26817b5bd6431e31 100644 (file)
@@ -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);
index 8d0b39c7aca25b08b8fe68cff12b2a0c40e3a214..ddfea2acc09b028dec07771ea32ad59daa96fe5f 100644 (file)
@@ -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);
index b4742fe729baa2d1259f443bdec23f308c0b81df..07bb68d6b2a3d67376c2f3d9ecda307ca0b1c7cf 100644 (file)
@@ -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) {
index 077b9ec46845ffcee82ec318895962d5cbe82aec..23cb9fc4d8194137fe8f2197196134522e0f7d66 100644 (file)
@@ -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);