aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Steffen <andreas.steffen@strongswan.org>2011-02-07 15:35:24 +0100
committerAndreas Steffen <andreas.steffen@strongswan.org>2011-02-07 15:35:24 +0100
commit7a694522c5608a696fb485527acafc1eeaefc6e5 (patch)
treee27c2ce6075e76919070e34fc24f5a6cc610c995
parent5922c484f657ff31c5718df0d7da7c2159e74255 (diff)
downloadstrongswan-7a694522c5608a696fb485527acafc1eeaefc6e5.tar.bz2
strongswan-7a694522c5608a696fb485527acafc1eeaefc6e5.tar.xz
removed atosa.c and satoa.c from libfreeswan
-rw-r--r--src/libfreeswan/Makefile.am6
-rw-r--r--src/libfreeswan/atosa.3217
-rw-r--r--src/libfreeswan/atosa.c198
-rw-r--r--src/libfreeswan/freeswan.h18
-rw-r--r--src/libfreeswan/satoa.c100
5 files changed, 3 insertions, 536 deletions
diff --git a/src/libfreeswan/Makefile.am b/src/libfreeswan/Makefile.am
index 554bc8a03..e3e93ff22 100644
--- a/src/libfreeswan/Makefile.am
+++ b/src/libfreeswan/Makefile.am
@@ -1,10 +1,10 @@
noinst_LIBRARIES = libfreeswan.a
libfreeswan_a_SOURCES = addrtoa.c addrtot.c addrtypeof.c anyaddr.c atoaddr.c atoasr.c \
- atosa.c atosubnet.c atoul.c copyright.c datatot.c freeswan.h \
+ atosubnet.c atoul.c copyright.c datatot.c freeswan.h \
goodmask.c initaddr.c initsaid.c initsubnet.c internal.h ipsec_param.h \
keyblobtoid.c pfkey_v2_build.c pfkey_v2_debug.c \
pfkey_v2_ext_bits.c pfkey_v2_parse.c portof.c rangetoa.c \
- pfkey.h pfkeyv2.h rangetosubnet.c sameaddr.c satoa.c \
+ pfkey.h pfkeyv2.h rangetosubnet.c sameaddr.c \
satot.c subnetof.c subnettoa.c subnettot.c \
subnettypeof.c ttoaddr.c ttodata.c ttoprotoport.c ttosa.c ttosubnet.c ttoul.c \
ultoa.c ultot.c
@@ -14,7 +14,7 @@ INCLUDES = \
-I$(top_srcdir)/src/libhydra \
-I$(top_srcdir)/src/pluto
-dist_man3_MANS = anyaddr.3 atoaddr.3 atoasr.3 atosa.3 atoul.3 goodmask.3 initaddr.3 initsubnet.3 \
+dist_man3_MANS = anyaddr.3 atoaddr.3 atoasr.3 atoul.3 goodmask.3 initaddr.3 initsubnet.3 \
keyblobtoid.3 portof.3 rangetosubnet.3 sameaddr.3 subnetof.3 \
ttoaddr.3 ttodata.3 ttosa.3 ttoul.3
diff --git a/src/libfreeswan/atosa.3 b/src/libfreeswan/atosa.3
deleted file mode 100644
index f57fcf1e9..000000000
--- a/src/libfreeswan/atosa.3
+++ /dev/null
@@ -1,217 +0,0 @@
-.TH IPSEC_ATOSA 3 "11 June 2001"
-.SH NAME
-ipsec atosa, satoa \- convert IPsec Security Association IDs to and from ASCII
-.SH SYNOPSIS
-.B "#include <freeswan.h>
-.sp
-.B "const char *atosa(const char *src, size_t srclen,"
-.ti +1c
-.B "struct sa_id *sa);
-.br
-.B "size_t satoa(struct sa_id sa, int format,"
-.ti +1c
-.B "char *dst, size_t dstlen);"
-.sp
-.B "struct sa_id {"
-.ti +1c
-.B "struct in_addr dst;"
-.ti +1c
-.B "ipsec_spi_t spi;"
-.ti +1c
-.B "int proto;"
-.br
-.B "};"
-.SH DESCRIPTION
-These functions are obsolete; see
-.IR ipsec_ttosa (3)
-for their replacements.
-.PP
-.I Atosa
-converts an ASCII Security Association (SA) specifier into an
-.B sa_id
-structure (containing
-a destination-host address
-in network byte order,
-an SPI number in network byte order, and
-a protocol code).
-.I Satoa
-does the reverse conversion, back to an ASCII SA specifier.
-.PP
-An SA is specified in ASCII with a mail-like syntax, e.g.
-.BR esp507@1.2.3.4 .
-An SA specifier contains
-a protocol prefix (currently
-.BR ah ,
-.BR esp ,
-or
-.BR tun ),
-an unsigned integer SPI number,
-and an IP address.
-The SPI number can be decimal or hexadecimal
-(with
-.B 0x
-prefix), as accepted by
-.IR ipsec_atoul (3).
-The IP address can be any form accepted by
-.IR ipsec_atoaddr (3),
-e.g. dotted-decimal address or DNS name.
-.PP
-As a special case, the SA specifier
-.B %passthrough
-signifies the special SA used to indicate that packets should be
-passed through unaltered.
-(At present, this is a synonym for
-.BR tun0x0@0.0.0.0 ,
-but that is subject to change without notice.)
-This form is known to both
-.I atosa
-and
-.IR satoa ,
-so the internal form of
-.B %passthrough
-is never visible.
-.PP
-The
-.B <freeswan.h>
-header file supplies the
-.B sa_id
-structure, as well as a data type
-.B ipsec_spi_t
-which is an unsigned 32-bit integer.
-(There is no consistency between kernel and user on what such a type
-is called, hence the header hides the differences.)
-.PP
-The protocol code uses the same numbers that IP does.
-For user convenience, given the difficulty in acquiring the exact set of
-protocol names used by the kernel,
-.B <freeswan.h>
-defines the names
-.BR SA_ESP ,
-.BR SA_AH ,
-and
-.B SA_IPIP
-to have the same values as the kernel names
-.BR IPPROTO_ESP ,
-.BR IPPROTO_AH ,
-and
-.BR IPPROTO_IPIP .
-.PP
-The
-.I srclen
-parameter of
-.I atosa
-specifies the length of the ASCII string pointed to by
-.IR src ;
-it is an error for there to be anything else
-(e.g., a terminating NUL) within that length.
-As a convenience for cases where an entire NUL-terminated string is
-to be converted,
-a
-.I srclen
-value of
-.B 0
-is taken to mean
-.BR strlen(src) .
-.PP
-The
-.I dstlen
-parameter of
-.I satoa
-specifies the size of the
-.I dst
-parameter;
-under no circumstances are more than
-.I dstlen
-bytes written to
-.IR dst .
-A result which will not fit is truncated.
-.I Dstlen
-can be zero, in which case
-.I dst
-need not be valid and no result is written,
-but the return value is unaffected;
-in all other cases, the (possibly truncated) result is NUL-terminated.
-The
-.I freeswan.h
-header file defines a constant,
-.BR SATOA_BUF ,
-which is the size of a buffer just large enough for worst-case results.
-.PP
-The
-.I format
-parameter of
-.I satoa
-specifies what format is to be used for the conversion.
-The value
-.B 0
-(not the ASCII character
-.BR '0' ,
-but a zero value)
-specifies a reasonable default
-(currently
-lowercase protocol prefix, lowercase hexadecimal SPI, dotted-decimal address).
-The value
-.B d
-causes the SPI to be generated in decimal instead.
-.PP
-.I Atosa
-returns
-.B NULL
-for success and
-a pointer to a string-literal error message for failure;
-see DIAGNOSTICS.
-.I Satoa
-returns
-.B 0
-for a failure, and otherwise
-always returns the size of buffer which would
-be needed to
-accommodate the full conversion result, including terminating NUL;
-it is the caller's responsibility to check this against the size of
-the provided buffer to determine whether truncation has occurred.
-.SH SEE ALSO
-ipsec_atoul(3), ipsec_atoaddr(3), inet(3)
-.SH DIAGNOSTICS
-Fatal errors in
-.I atosa
-are:
-empty input;
-input too small to be a legal SA specifier;
-no
-.B @
-in input;
-unknown protocol prefix;
-conversion error in
-.I atoul
-or
-.IR atoaddr .
-.PP
-Fatal errors in
-.I satoa
-are:
-unknown format; unknown protocol code.
-.SH HISTORY
-Written for the FreeS/WAN project by Henry Spencer.
-.SH BUGS
-The
-.B tun
-protocol code is a FreeS/WANism which may eventually disappear.
-.PP
-The restriction of ASCII-to-binary error reports to literal strings
-(so that callers don't need to worry about freeing them or copying them)
-does limit the precision of error reporting.
-.PP
-The ASCII-to-binary error-reporting convention lends itself
-to slightly obscure code,
-because many readers will not think of NULL as signifying success.
-A good way to make it clearer is to write something like:
-.PP
-.RS
-.nf
-.B "const char *error;"
-.sp
-.B "error = atoaddr( /* ... */ );"
-.B "if (error != NULL) {"
-.B " /* something went wrong */"
-.fi
-.RE
diff --git a/src/libfreeswan/atosa.c b/src/libfreeswan/atosa.c
deleted file mode 100644
index 7339b4c3e..000000000
--- a/src/libfreeswan/atosa.c
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * convert from ASCII form of SA ID to binary
- * Copyright (C) 1998, 1999 Henry Spencer.
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Library General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version. See <http://www.fsf.org/copyleft/lgpl.txt>.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
- * License for more details.
- */
-#include "internal.h"
-#include "freeswan.h"
-
-static struct satype {
- char *prefix;
- size_t prelen; /* strlen(prefix) */
- int proto;
-} satypes[] = {
- { "ah", 2, SA_AH },
- { "esp", 3, SA_ESP },
- { "tun", 3, SA_IPIP },
- { "comp", 4, SA_COMP },
- { NULL, 0, 0, }
-};
-
-/*
- - atosa - convert ASCII "ah507@10.0.0.1" to SA identifier
- */
-const char * /* NULL for success, else string literal */
-atosa(src, srclen, sa)
-const char *src;
-size_t srclen; /* 0 means "apply strlen" */
-struct sa_id *sa;
-{
- const char *at;
- const char *addr;
- const char *spi = NULL;
- struct satype *sat;
- unsigned long ul;
- const char *oops;
-# define MINLEN 5 /* ah0@0 is as short as it can get */
- static char ptname[] = PASSTHROUGHNAME;
-# define PTNLEN (sizeof(ptname)-1) /* -1 for NUL */
-
- if (srclen == 0)
- srclen = strlen(src);
- if (srclen == 0)
- return "empty string";
- if (srclen < MINLEN)
- return "string too short to be SA specifier";
- if (srclen == PTNLEN && memcmp(src, ptname, PTNLEN) == 0) {
- src = PASSTHROUGHIS;
- srclen = strlen(src);
- }
-
- at = memchr(src, '@', srclen);
- if (at == NULL)
- return "no @ in SA specifier";
-
- for (sat = satypes; sat->prefix != NULL; sat++)
- if (sat->prelen < srclen &&
- strncmp(src, sat->prefix, sat->prelen) == 0) {
- sa->proto = sat->proto;
- spi = src + sat->prelen;
- break; /* NOTE BREAK OUT */
- }
- if (sat->prefix == NULL)
- return "SA specifier lacks valid protocol prefix";
-
- if (spi >= at)
- return "no SPI in SA specifier";
- oops = atoul(spi, at - spi, 13, &ul);
- if (oops != NULL)
- return oops;
- sa->spi = htonl(ul);
-
- addr = at + 1;
- oops = atoaddr(addr, srclen - (addr - src), &sa->dst);
- if (oops != NULL)
- return oops;
-
- return NULL;
-}
-
-
-
-#ifdef ATOSA_MAIN
-
-#include <stdio.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-void regress(void);
-
-int
-main(int argc, char *argv[])
-{
- struct sa_id sa;
- char buf[100];
- const char *oops;
- size_t n;
-
- if (argc < 2) {
- fprintf(stderr, "Usage: %s {ahnnn@aaa|-r}\n", argv[0]);
- exit(2);
- }
-
- if (strcmp(argv[1], "-r") == 0) {
- regress();
- fprintf(stderr, "regress() returned?!?\n");
- exit(1);
- }
-
- oops = atosa(argv[1], 0, &sa);
- if (oops != NULL) {
- fprintf(stderr, "%s: conversion failed: %s\n", argv[0], oops);
- exit(1);
- }
- n = satoa(sa, 0, buf, sizeof(buf));
- if (n > sizeof(buf)) {
- fprintf(stderr, "%s: reverse conv of `%d'", argv[0], sa.proto);
- fprintf(stderr, "%lu@", (long unsigned int)sa.spi);
- fprintf(stderr, "%s", inet_ntoa(sa.dst));
- fprintf(stderr, " failed: need %ld bytes, have only %ld\n",
- (long)n, (long)sizeof(buf));
- exit(1);
- }
- printf("%s\n", buf);
-
- exit(0);
-}
-
-struct rtab {
- char *input;
- char *output; /* NULL means error expected */
-} rtab[] = {
- {"esp257@1.2.3.0", "esp257@1.2.3.0"},
- {"ah0x20@1.2.3.4", "ah32@1.2.3.4"},
- {"tun011@111.2.3.99", "tun11@111.2.3.99"},
- {"", NULL},
- {"_", NULL},
- {"ah2.2", NULL},
- {"goo2@1.2.3.4", NULL},
- {"esp9@1.2.3.4", "esp9@1.2.3.4"},
- {"espp9@1.2.3.4", NULL},
- {"es9@1.2.3.4", NULL},
- {"ah@1.2.3.4", NULL},
- {"esp7x7@1.2.3.4", NULL},
- {"esp77@1.0x2.3.4", NULL},
- {PASSTHROUGHNAME, PASSTHROUGHNAME},
- {NULL, NULL}
-};
-
-void
-regress(void)
-{
- struct rtab *r;
- int status = 0;
- struct sa_id sa;
- char in[100];
- char buf[100];
- const char *oops;
- size_t n;
-
- for (r = rtab; r->input != NULL; r++) {
- strcpy(in, r->input);
- oops = atosa(in, 0, &sa);
- if (oops != NULL && r->output == NULL)
- {} /* okay, error expected */
- else if (oops != NULL) {
- printf("`%s' atosa failed: %s\n", r->input, oops);
- status = 1;
- } else if (r->output == NULL) {
- printf("`%s' atosa succeeded unexpectedly\n",
- r->input);
- status = 1;
- } else {
- n = satoa(sa, 'd', buf, sizeof(buf));
- if (n > sizeof(buf)) {
- printf("`%s' satoa failed: need %ld\n",
- r->input, (long)n);
- status = 1;
- } else if (strcmp(r->output, buf) != 0) {
- printf("`%s' gave `%s', expected `%s'\n",
- r->input, buf, r->output);
- status = 1;
- }
- }
- }
- exit(status);
-}
-
-#endif /* ATOSA_MAIN */
diff --git a/src/libfreeswan/freeswan.h b/src/libfreeswan/freeswan.h
index d931355a3..5a76aea6f 100644
--- a/src/libfreeswan/freeswan.h
+++ b/src/libfreeswan/freeswan.h
@@ -288,24 +288,6 @@ rangetoa(
);
#define RANGETOA_BUF 34 /* large enough for worst case result */
-/* data types for SA conversion functions */
-
-/* SAs */
-const char * /* NULL for success, else string literal */
-atosa(
- const char *src,
- size_t srclen, /* 0 means strlen(src) */
- struct sa_id *sa
-);
-size_t /* space needed for full conversion */
-satoa(
- struct sa_id sa,
- int format, /* character; 0 means default */
- char *dst,
- size_t dstlen
-);
-#define SATOA_BUF (3+ULTOA_BUF+ADDRTOA_BUF)
-
/* generic data, e.g. keys */
const char * /* NULL for success, else string literal */
atobytes(
diff --git a/src/libfreeswan/satoa.c b/src/libfreeswan/satoa.c
deleted file mode 100644
index 09a152727..000000000
--- a/src/libfreeswan/satoa.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * convert from binary form of SA ID to ASCII
- * Copyright (C) 1998, 1999, 2001 Henry Spencer.
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Library General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version. See <http://www.fsf.org/copyleft/lgpl.txt>.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
- * License for more details.
- */
-#include "internal.h"
-#include "freeswan.h"
-
-static struct typename {
- char type;
- char *name;
-} typenames[] = {
- { SA_AH, "ah" },
- { SA_ESP, "esp" },
- { SA_IPIP, "tun" },
- { SA_COMP, "comp" },
- { SA_INT, "int" },
- { 0, NULL }
-};
-
-/*
- - satoa - convert SA to ASCII "ah507@1.2.3.4"
- */
-size_t /* space needed for full conversion */
-satoa(sa, format, dst, dstlen)
-struct sa_id sa;
-int format; /* character */
-char *dst; /* need not be valid if dstlen is 0 */
-size_t dstlen;
-{
- size_t len = 0; /* 0 means not handled yet */
- int base;
- struct typename *tn;
- char buf[30+ADDRTOA_BUF];
-
- switch (format) {
- case 0:
- base = 16; /* temporarily at least */
- break;
- case 'd':
- base = 10;
- break;
- default:
- return 0;
- break;
- }
-
- for (tn = typenames; tn->name != NULL; tn++)
- if (sa.proto == tn->type)
- break;
- if (tn->name == NULL)
- return 0;
-
- if (strcmp(tn->name, PASSTHROUGHTYPE) == 0 &&
- sa.spi == PASSTHROUGHSPI &&
- sa.dst.s_addr == PASSTHROUGHDST) {
- strcpy(buf, PASSTHROUGHNAME);
- len = strlen(buf);
- } else if (sa.proto == SA_INT && sa.dst.s_addr == 0) {
- char *p;
-
- switch (ntohl(sa.spi)) {
- case SPI_PASS: p = "%pass"; break;
- case SPI_DROP: p = "%drop"; break;
- case SPI_REJECT: p = "%reject"; break;
- case SPI_HOLD: p = "%hold"; break;
- case SPI_TRAP: p = "%trap"; break;
- case SPI_TRAPSUBNET: p = "%trapsubnet"; break;
- default: p = NULL; break;
- }
- if (p != NULL) {
- strcpy(buf, p);
- len = strlen(buf);
- }
- }
-
- if (len == 0) {
- strcpy(buf, tn->name);
- len = strlen(buf);
- len += ultoa(ntohl(sa.spi), base, buf+len, sizeof(buf)-len);
- *(buf+len-1) = '@';
- len += addrtoa(sa.dst, 0, buf+len, sizeof(buf)-len);
- }
-
- if (dst != NULL) {
- if (len > dstlen)
- *(buf+dstlen-1) = '\0';
- strcpy(dst, buf);
- }
- return len;
-}