Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/dist/kame/racoon KAME racoon as of 2001/2/22



details:   https://anonhg.NetBSD.org/src/rev/54b81adfa054
branches:  trunk
changeset: 504110:54b81adfa054
user:      itojun <itojun%NetBSD.org@localhost>
date:      Thu Feb 22 02:21:12 2001 +0000

description:
KAME racoon as of 2001/2/22

diffstat:

 crypto/dist/kame/racoon/Makefile.in      |    4 +-
 crypto/dist/kame/racoon/backupsa.c       |  473 +++++++++++++++++++++++++++++++
 crypto/dist/kame/racoon/backupsa.h       |   37 ++
 crypto/dist/kame/racoon/cfparse.h        |   15 +-
 crypto/dist/kame/racoon/cftoken.l        |   35 +-
 crypto/dist/kame/racoon/crypto_openssl.c |   27 +-
 crypto/dist/kame/racoon/handler.c        |   26 +-
 crypto/dist/kame/racoon/handler.h        |    3 +-
 crypto/dist/kame/racoon/isakmp_inf.c     |   18 +-
 crypto/dist/kame/racoon/isakmp_quick.c   |  103 +------
 crypto/dist/kame/racoon/localconf.c      |    3 +-
 crypto/dist/kame/racoon/localconf.h      |   16 +-
 crypto/dist/kame/racoon/pfkey.c          |  191 +++++-------
 crypto/dist/kame/racoon/proposal.c       |  140 ++++++++-
 crypto/dist/kame/racoon/proposal.h       |    6 +-
 crypto/dist/kame/racoon/session.c        |    4 +-
 16 files changed, 779 insertions(+), 322 deletions(-)

diffs (truncated from 1535 to 300 lines):

diff -r 6867dc3ca126 -r 54b81adfa054 crypto/dist/kame/racoon/Makefile.in
--- a/crypto/dist/kame/racoon/Makefile.in       Thu Feb 22 01:40:25 2001 +0000
+++ b/crypto/dist/kame/racoon/Makefile.in       Thu Feb 22 02:21:12 2001 +0000
@@ -1,4 +1,4 @@
-#      $KAME: Makefile.in,v 1.30 2000/12/12 16:59:32 thorpej Exp $
+#      $KAME: Makefile.in,v 1.31 2001/01/31 05:32:55 sakane Exp $
 
 @SET_MAKE@
 srcdir=        @srcdir@
@@ -31,7 +31,7 @@
        policy.o localconf.o remoteconf.o crypto_openssl.o algorithm.o \
        proposal.o sainfo.o cfparse.o cftoken.o strnames.o \
        vmbuf.o plog.o logger.o schedule.o str2val.o misc.o sockmisc.o \
-       safefile.o @LIBOBJS@
+       safefile.o backupsa.o @LIBOBJS@
 # under samples
 CONF=  psk.txt racoon.conf
 
diff -r 6867dc3ca126 -r 54b81adfa054 crypto/dist/kame/racoon/backupsa.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/dist/kame/racoon/backupsa.c        Thu Feb 22 02:21:12 2001 +0000
@@ -0,0 +1,473 @@
+/*     $KAME: backupsa.c,v 1.7 2001/02/01 15:51:16 sakane Exp $        */
+
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <netinet/in.h>
+#ifdef IPV6_INRIA_VERSION
+#include <netinet/ipsec.h>
+#else
+#include <netinet6/ipsec.h>
+#endif
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include "var.h"
+#include "misc.h"
+#include "vmbuf.h"
+#include "str2val.h"
+#include "plog.h"
+#include "debug.h"
+
+#include "localconf.h"
+#include "sockmisc.h"
+#include "safefile.h"
+#include "backupsa.h"
+#include "libpfkey.h"
+
+/*
+ * (time string)%(sa parameter)
+ * (time string) := ex. Nov 24 18:22:48 1986
+ * (sa parameter) :=
+ *    src dst satype spi mode reqid wsize \
+ *    e_type e_keylen a_type a_keylen flags \
+ *    l_alloc l_bytes l_addtime l_usetime seq keymat
+ */
+static char *format = "%b %d %T %Y";   /* time format */
+static char *strmon[12] = {
+        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+static char *str2tmx __P((char *, struct tm *));
+static int str2num __P((char *, int));
+
+/*
+ * output the sa parameter.
+ */
+int
+backupsa_to_file(satype, mode, src, dst, spi, reqid, wsize,
+                keymat, e_type, e_keylen, a_type, a_keylen, flags,
+                l_alloc, l_bytes, l_addtime, l_usetime, seq)
+        u_int satype, mode, wsize;
+        struct sockaddr *src, *dst;
+        u_int32_t spi, reqid;
+        caddr_t keymat;
+        u_int e_type, e_keylen, a_type, a_keylen, flags;
+        u_int32_t l_alloc;
+        u_int64_t l_bytes, l_addtime, l_usetime;
+        u_int32_t seq;
+{
+       char buf[1024];
+       struct tm *tm;
+       time_t t;
+       char *p, *k;
+       int len, l, i;
+       FILE *fp;
+
+       p = buf;
+       len = sizeof(buf);
+
+       t = time(NULL);
+       tm = localtime(&t);
+       l = strftime(p, len, format, tm);
+       p += l;
+       len -= l;
+       if (len < 0)
+               goto err;
+
+       l = snprintf(p, len, "%%");
+       p += l;
+       len -= l;
+       if (len < 0)
+               goto err;
+
+        i = getnameinfo(src, src->sa_len, p, len, NULL, 0, NIFLAGS);
+       if (i != 0)
+               goto err;
+       l = strlen(p);
+       p += l;
+       len -= l;
+       if (len < 0)
+               goto err;
+
+       l = snprintf(p, len, " ");
+       p += l;
+       len -= l;
+       if (len < 0)
+               goto err;
+
+        i = getnameinfo(dst, dst->sa_len, p, len, NULL, 0, NIFLAGS);
+       if (i != 0)
+               goto err;
+       l = strlen(p);
+       p += l;
+       len -= l;
+       if (len < 0)
+               goto err;
+
+       l = snprintf(p, len,
+               " %u %lu %u %u %u "
+               "%u %u %u %u %u "
+               "%u %llu %llu %llu %u",
+               satype, (unsigned long)ntohl(spi), mode, reqid, wsize,
+               e_type, e_keylen, a_type, a_keylen, flags,
+               l_alloc, (unsigned long long)l_bytes,
+               (unsigned long long)l_addtime, (unsigned long long)l_usetime,
+               seq);
+       p += l;
+       len -= l;
+       if (len < 0)
+               goto err;
+
+       k = val2str(keymat, e_keylen + a_keylen);
+       l = snprintf(p, len, " %s", k);
+       free(k);
+       p += l;
+       len -= l;
+       if (len < 0)
+               goto err;
+
+       /* open the file and write the SA parameter */
+       if (safefile(lcconf->pathinfo[LC_PATHTYPE_BACKUPSA], 1) != 0 ||
+           (fp = fopen(lcconf->pathinfo[LC_PATHTYPE_BACKUPSA], "a")) == NULL) {
+               plog(LLV_ERROR, LOCATION, NULL,
+                       "failed to open the backup file %s.\n",
+                       lcconf->pathinfo[LC_PATHTYPE_BACKUPSA]);
+               return -1;
+       }
+       fprintf(fp, "%s\n", buf);
+       fclose(fp);
+
+       return 0;
+
+err:
+       plog(LLV_ERROR, LOCATION, NULL,
+               "SA cannot be saved to a file.\n");
+       return -1;
+}
+
+int
+backupsa_from_file()
+{
+       FILE *fp;
+       char buf[512];
+       struct tm tm;
+       time_t created, current;
+       char *p, *q;
+        u_int satype, mode;
+        struct sockaddr *src, *dst;
+        u_int32_t spi, reqid;
+        caddr_t keymat;
+       int keymatlen;
+        u_int wsize, e_type, e_keylen, a_type, a_keylen, flags;
+        u_int32_t l_alloc;
+        u_int64_t l_bytes, l_addtime, l_usetime;
+        u_int32_t seq;
+       int line;
+
+       if (safefile(lcconf->pathinfo[LC_PATHTYPE_BACKUPSA], 1) == 0)
+               fp = fopen(lcconf->pathinfo[LC_PATHTYPE_BACKUPSA], "r");
+       else
+               fp = NULL;
+       if (fp == NULL) {
+               plog(LLV_ERROR, LOCATION, NULL,
+                       "failed to open the backup file %s.\n",
+                       lcconf->pathinfo[LC_PATHTYPE_BACKUPSA]);
+               return -1;
+       }
+
+       current = time(NULL);
+
+       for(line = 1; fgets(buf, sizeof(buf), fp) != NULL; line++) {
+               /* comment line */
+               if (buf[0] == '#')
+                       continue;
+
+               memset(&tm, 0, sizeof(tm));
+               p = str2tmx(buf, &tm);
+               if (*p != '%') {
+       err:
+                       plog(LLV_ERROR, LOCATION, NULL,
+                               "illegal format line#%d in %s: %s\n",
+                               line, lcconf->pathinfo[LC_PATHTYPE_BACKUPSA], buf);
+                       continue;
+               }
+               created = mktime(&tm);
+               p++;
+
+               for (q = p; *q != '\0' && !isspace(*q); q++)
+                       ;
+               *q = '\0';
+               src = str2saddr(p, NULL);
+               if (src == NULL)
+                       goto err;
+               p = q + 1;
+
+               for (q = p; *q != '\0' && !isspace(*q); q++)
+                       ;
+               *q = '\0';
+               dst = str2saddr(p, NULL);
+               if (dst == NULL) {
+                       free(src);
+                       goto err;
+               }
+               p = q + 1;
+
+#define GETNEXTNUM(value, function) \
+do { \
+       char *y; \
+       for (q = p; *q != '\0' && !isspace(*q); q++) \
+               ; \
+       *q = '\0'; \
+       (value) = function(p, &y, 10); \
+       if ((value) == 0 && *y != '\0') \
+               goto err; \
+       p = q + 1; \
+} while (0);
+
+               GETNEXTNUM(satype, strtoul);
+               GETNEXTNUM(spi, strtoul);
+               spi = ntohl(spi);
+               GETNEXTNUM(mode, strtoul);
+               GETNEXTNUM(reqid, strtoul);
+               GETNEXTNUM(wsize, strtoul);
+               GETNEXTNUM(e_type, strtoul);



Home | Main Index | Thread Index | Old Index