pluto and scepclient now use chunk_t from libstrongswan
This commit is contained in:
parent
9b91b81870
commit
a376e44577
|
@ -41,7 +41,7 @@ struct chunk_t {
|
|||
size_t len;
|
||||
};
|
||||
|
||||
#include <library.h>
|
||||
#include <utils.h>
|
||||
|
||||
/**
|
||||
* A { NULL, 0 }-chunk handy for initialization.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <chunk.h>
|
||||
|
||||
#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);
|
||||
|
||||
|
|
|
@ -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 $@ $<
|
||||
|
||||
|
|
Loading…
Reference in New Issue