From a376e445770bc2ec1afda646cfd9faba58348e86 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Fri, 17 Apr 2009 16:41:26 +0000 Subject: [PATCH] pluto and scepclient now use chunk_t from libstrongswan --- src/libstrongswan/chunk.h | 2 +- src/pluto/Makefile.am | 8 +++++- src/pluto/defs.c | 36 --------------------------- src/pluto/defs.h | 50 ++------------------------------------ src/scepclient/Makefile.am | 12 ++++++++- 5 files changed, 21 insertions(+), 87 deletions(-) diff --git a/src/libstrongswan/chunk.h b/src/libstrongswan/chunk.h index 0d1348c85..37cbebfc5 100644 --- a/src/libstrongswan/chunk.h +++ b/src/libstrongswan/chunk.h @@ -41,7 +41,7 @@ struct chunk_t { size_t len; }; -#include +#include /** * A { NULL, 0 }-chunk handy for initialization. diff --git a/src/pluto/Makefile.am b/src/pluto/Makefile.am index 400b794b3..2194cda2b 100644 --- a/src/pluto/Makefile.am +++ b/src/pluto/Makefile.am @@ -90,7 +90,7 @@ AM_CFLAGS = \ -DPLUTO -DKLIPS -DDEBUG pluto_LDADD = \ -oid.o debug.o linked_list.o enumerator.o settings.o \ +oid.o debug.o linked_list.o enumerator.o settings.o utils.o chunk.o \ $(LIBFREESWANDIR)/libfreeswan.a \ $(LIBCRYPTODIR)/libcrypto.a \ -lgmp -lresolv -lpthread -ldl @@ -128,6 +128,12 @@ enumerator.o : $(LIBSTRONGSWANDIR)/utils/enumerator.c $(LIBSTRONGSWANDIR)/utils/ settings.o : $(LIBSTRONGSWANDIR)/settings.c $(LIBSTRONGSWANDIR)/settings.h $(COMPILE) -c -o $@ $< +utils.o : $(LIBSTRONGSWANDIR)/utils.c $(LIBSTRONGSWANDIR)/utils.h + $(COMPILE) -c -o $@ $< + +chunk.o : $(LIBSTRONGSWANDIR)/chunk.c $(LIBSTRONGSWANDIR)/chunk.h + $(COMPILE) -c -o $@ $< + # This compile option activates the sending of a strongSwan VID if USE_VENDORID AM_CFLAGS += -DVENDORID diff --git a/src/pluto/defs.c b/src/pluto/defs.c index c6dde5a62..79c81924a 100644 --- a/src/pluto/defs.c +++ b/src/pluto/defs.c @@ -29,27 +29,6 @@ #include "log.h" #include "whack.h" /* for RC_LOG_SERIOUS */ -/** - * Empty chunk. - */ -const chunk_t chunk_empty = { NULL, 0 }; - -/** - * Create a clone of a chunk pointing to "ptr" - */ -chunk_t chunk_create_clone(u_char *ptr, chunk_t chunk) -{ - chunk_t clone = chunk_empty; - - if (chunk.ptr && chunk.len > 0) - { - clone.ptr = ptr; - clone.len = chunk.len; - memcpy(clone.ptr, chunk.ptr, chunk.len); - } - return clone; -} - bool all_zero(const unsigned char *m, size_t len) { @@ -102,21 +81,6 @@ concatenate_paths(const char *a, const char *b) return c; } -/* compare two chunks, returns zero if a equals b - * negative/positive if a is earlier/later in the alphabet than b - */ -int chunk_compare(chunk_t a, chunk_t b) -{ - int compare_len = a.len - b.len; - int len = (compare_len < 0)? a.len : b.len; - - if (compare_len != 0 || len == 0) - { - return compare_len; - } - return memcmp(a.ptr, b.ptr, len); -} - /* moves a chunk to a memory position, chunk is freed afterwards * position pointer is advanced after the insertion point */ diff --git a/src/pluto/defs.h b/src/pluto/defs.h index 145634e6e..2d19d7300 100644 --- a/src/pluto/defs.h +++ b/src/pluto/defs.h @@ -21,6 +21,8 @@ #include #include +#include + #ifdef KLIPS # define USED_BY_KLIPS /* ignore */ #else @@ -52,60 +54,12 @@ extern void *clone_bytes(const void *orig, size_t size); #define replace(p, q) \ { free(p); (p) = (q); } - -/* chunk is a simple pointer-and-size abstraction */ - -struct chunk { - u_char *ptr; - size_t len; - }; -typedef struct chunk chunk_t; - -extern const chunk_t chunk_empty; - -static inline chunk_t chunk_create(u_char *ptr, size_t len) -{ - chunk_t chunk = {ptr, len}; - return chunk; -} - -static inline void chunk_free(chunk_t *chunk) -{ - free(chunk->ptr); - *chunk = chunk_empty; -} - -static inline void chunk_clear(chunk_t *chunk) -{ - if (chunk->ptr) - { - memset(chunk->ptr, 0, chunk->len); - chunk_free(chunk); - } -} - -static inline bool chunk_equals(chunk_t a, chunk_t b) -{ - return a.ptr != NULL && b.ptr != NULL && - a.len == b.len && memeq(a.ptr, b.ptr, a.len); -} - -extern chunk_t chunk_create_clone(u_char *ptr, chunk_t chunk); - -#define chunk_clone(chunk) \ - chunk_create_clone((chunk).len ? malloc((chunk).len) : NULL, chunk) - -#define chunk_from_buf(str) { str, sizeof(str) } - #define chunkcpy(dst, chunk) \ { memcpy(dst, chunk.ptr, chunk.len); dst += chunk.len;} extern char* temporary_cyclic_buffer(void); extern const char* concatenate_paths(const char *a, const char *b); -/* compare two chunks */ -extern int chunk_compare(chunk_t a, chunk_t b); - /* move a chunk to a memory position and free it after insertion */ extern void mv_chunk(u_char **pos, chunk_t content); diff --git a/src/scepclient/Makefile.am b/src/scepclient/Makefile.am index 86220d71b..76d7f1a58 100644 --- a/src/scepclient/Makefile.am +++ b/src/scepclient/Makefile.am @@ -20,7 +20,8 @@ AM_CFLAGS = -DDEBUG -DNO_PLUTO -DIPSEC_CONFDIR=\"${confdir}\" LIBFREESWANBUILDDIR=$(top_builddir)/src/libfreeswan LIBCRYPTOBUILDDIR=$(top_builddir)/src/libcrypto -scepclient_LDADD = asn1.o ca.o crl.o certs.o constants.o defs.o fetch.o id.o \ +scepclient_LDADD = debug.o utils.o chunk.o \ + asn1.o ca.o crl.o certs.o constants.o defs.o fetch.o id.o \ keys.o lex.o md2.o md5.o mp_defs.o ocsp.o oid.o pem.o pgp.o \ pkcs1.o pkcs7.o rnd.o sha1.o smartcard.o x509.o \ $(LIBFREESWANBUILDDIR)/libfreeswan.a $(LIBCRYPTOBUILDDIR)/libcrypto.a \ @@ -40,6 +41,15 @@ endif dist_man_MANS = scepclient.8 +debug.o : $(LIBSTRONGSWANDIR)/debug.c $(LIBSTRONGSWANDIR)/debug.h + $(COMPILE) -c -o $@ $< + +utils.o : $(LIBSTRONGSWANDIR)/utils.c $(LIBSTRONGSWANDIR)/utils.h + $(COMPILE) -c -o $@ $< + +chunk.o : $(LIBSTRONGSWANDIR)/chunk.c $(LIBSTRONGSWANDIR)/chunk.h + $(COMPILE) -c -o $@ $< + asn1.o : $(PLUTODIR)/asn1.c $(PLUTODIR)/asn1.h $(COMPILE) $(INCLUDES) -c -o $@ $<