diff --git a/configure.ac b/configure.ac index 6cd2ae9a..7c24abe2 100644 --- a/configure.ac +++ b/configure.ac @@ -31,7 +31,7 @@ AC_PROG_LIBTOOL # Checks for header files. # AC_HEADER_STDC -AC_CHECK_HEADERS([ctype.h netinet/in.h stdlib.h string.h strings.h sys/time.h termios.h unistd.h]) +AC_CHECK_HEADERS([ctype.h endian.h netinet/in.h stdlib.h string.h strings.h sys/endian.h sys/socket.h sys/time.h termios.h unistd.h]) # Type checks. # @@ -55,8 +55,97 @@ AC_FUNC_REALLOC AC_FUNC_STAT AC_CHECK_FUNCS([bzero gettimeofday memmove memset socket strchr strcspn strdup strncasecmp strndup strrchr strspn]) -# Check for gpgme -#AM_PATH_GPGME +dnl For finding and checking gpgme (taken from the gpgme.m4 file that +dnl comes with gpgme) +dnl +AC_DEFUN([_AM_PATH_GPGME_CONFIG], +[ AC_ARG_WITH(gpgme-prefix, + AC_HELP_STRING([--with-gpgme-prefix=PFX], + [prefix where GPGME is installed (optional)]), + gpgme_config_prefix="$withval", gpgme_config_prefix="") + if test "x$gpgme_config_prefix" != x ; then + GPGME_CONFIG="$gpgme_config_prefix/bin/gpgme-config" + fi + AC_PATH_PROG(GPGME_CONFIG, gpgme-config, no) + + if test "$GPGME_CONFIG" != "no" ; then + gpgme_version=`$GPGME_CONFIG --version` + fi + gpgme_version_major=`echo $gpgme_version | \ + sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'` + gpgme_version_minor=`echo $gpgme_version | \ + sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'` + gpgme_version_micro=`echo $gpgme_version | \ + sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'` +]) + +dnl AM_PATH_GPGME([MINIMUM-VERSION, +dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]]) +dnl Test for libgpgme and define GPGME_CFLAGS and GPGME_LIBS. +dnl +AC_DEFUN([AM_PATH_GPGME], +[ AC_REQUIRE([_AM_PATH_GPGME_CONFIG])dnl + tmp=ifelse([$1], ,1:0.4.2,$1) + if echo "$tmp" | grep ':' >/dev/null 2>/dev/null ; then + req_gpgme_api=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\1/'` + min_gpgme_version=`echo "$tmp" | sed 's/\(.*\):\(.*\)/\2/'` + else + req_gpgme_api=0 + min_gpgme_version="$tmp" + fi + + AC_MSG_CHECKING(for GPGME - version >= $min_gpgme_version) + ok=no + if test "$GPGME_CONFIG" != "no" ; then + req_major=`echo $min_gpgme_version | \ + sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'` + req_minor=`echo $min_gpgme_version | \ + sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'` + req_micro=`echo $min_gpgme_version | \ + sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'` + if test "$gpgme_version_major" -gt "$req_major"; then + ok=yes + else + if test "$gpgme_version_major" -eq "$req_major"; then + if test "$gpgme_version_minor" -gt "$req_minor"; then + ok=yes + else + if test "$gpgme_version_minor" -eq "$req_minor"; then + if test "$gpgme_version_micro" -ge "$req_micro"; then + ok=yes + fi + fi + fi + fi + fi + fi + if test $ok = yes; then + # If we have a recent GPGME, we should also check that the + # API is compatible. + if test "$req_gpgme_api" -gt 0 ; then + tmp=`$GPGME_CONFIG --api-version 2>/dev/null || echo 0` + if test "$tmp" -gt 0 ; then + if test "$req_gpgme_api" -ne "$tmp" ; then + ok=no + fi + fi + fi + fi + if test $ok = yes; then + GPGME_CFLAGS=`$GPGME_CONFIG --cflags` + GPGME_LIBS=`$GPGME_CONFIG --libs` + AC_MSG_RESULT(yes) + ifelse([$2], , :, [$2]) + else + GPGME_CFLAGS="" + GPGME_LIBS="" + AC_MSG_RESULT(no) + ifelse([$3], , :, [$3]) + fi + AC_SUBST(GPGME_CFLAGS) + AC_SUBST(GPGME_LIBS) +]) + AC_ARG_WITH([gpgme], [AS_HELP_STRING([--with-gpgme], [support for gpg encryption using libgpgme @<:@default=check@:>@])], @@ -65,15 +154,16 @@ AC_ARG_WITH([gpgme], have_gpgme=yes AS_IF([test "x$with_gpgme" != xno], - [AC_CHECK_LIB([gpgme], [gpgme_check_version], - [], + [AM_PATH_GPGME([], + [AC_DEFINE([HAVE_LIBGPGME], [1], [Define if you have libgpgme])], [if test "x$with_gpgme" != xcheck; then AC_MSG_FAILURE( [--with-gpgme was given, but test for gpgme failed]) else have_gpgme=no fi - ])], [have_gpgme=no]) + ], [have_gpgme=no])], [have_gpgme=no]) + AC_CONFIG_FILES([Makefile fko/Makefile diff --git a/fko/Makefile.am b/fko/Makefile.am index 1590bbc6..082a8020 100644 --- a/fko/Makefile.am +++ b/fko/Makefile.am @@ -10,5 +10,9 @@ libfko_source_files = \ strlcpy.c fko_state.h fko_context.h gpgme_funcs.c gpgme_funcs.h libfko_la_SOURCES = $(libfko_source_files) -libfko_la_LDFLAGS = -version-info 0:1:0 +libfko_la_LDFLAGS = -version-info 0:1:0 $(GPGME_LIBS) + +AM_CPPFLAGS = $(GPGME_CFLAGS) + include_HEADERS = fko.h + diff --git a/fko/digest.h b/fko/digest.h index 2195b652..e482e793 100644 --- a/fko/digest.h +++ b/fko/digest.h @@ -24,14 +24,8 @@ #ifndef DIGEST_H #define DIGEST_H 1 -#include #include "fko_common.h" -/* This should be fine for most linux systems (hopefully). - * TODO: We should look into the portability of this. --DSS -*/ -#define BYTEORDER __BYTE_ORDER - #include "md5.h" #include "sha.h" diff --git a/fko/fko_common.h b/fko/fko_common.h index 947373e1..5003aa14 100644 --- a/fko/fko_common.h +++ b/fko/fko_common.h @@ -51,6 +51,16 @@ #define isdigit(c) (c >= 48 && c <= 57) #endif +/* Work out endianess (sp?) +*/ +#if HAVE_ENDIAN_H /* Should cover most Linux systems */ + #include + #define BYTEORDER __BYTE_ORDER +#elif HAVE_SYS_ENDIAN_H /* FreeBSD has a sys/endian.h */ + #include + #define BYTEORDER _BYTE_ORDER +#endif + /* Convenient macros for wrapping sections in 'extern "C" {' constructs. */ #ifdef __cplusplus diff --git a/fko/fko_decode.c b/fko/fko_decode.c index c1e25be8..74b64da4 100644 --- a/fko/fko_decode.c +++ b/fko/fko_decode.c @@ -131,12 +131,13 @@ fko_decode_spa_data(fko_ctx_t ctx) return(FKO_ERROR_INVALID_DATA); } - ctx->rand_val = strndup(ndx, FKO_RAND_VAL_SIZE); + ctx->rand_val = calloc(1, FKO_RAND_VAL_SIZE+1); if(ctx->rand_val == NULL) { free(tbuf); return(FKO_ERROR_MEMORY_ALLOCATION); } + ctx->rand_val = strncpy(ctx->rand_val, ndx, FKO_RAND_VAL_SIZE); /* Jump to the next field (username). We need to use the temp buffer * for the base64 decode step. diff --git a/fko/md5.c b/fko/md5.c index 9c586022..36c58032 100644 --- a/fko/md5.c +++ b/fko/md5.c @@ -36,21 +36,23 @@ */ #include "md5.h" -#ifndef HIGHFIRST - #define byteReverse(buf, len) /* Nothing */ +#if BYTEORDER == 1234 + #define byteReverse(buf, len) /* Nothing */ +#elif BYTEORDER == 4321 + /* Note: this code is harmless on little-endian machines. + */ + void byteReverse(unsigned char *buf, unsigned longs) + { + uint32 t; + do { + t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | + ((unsigned) buf[1] << 8 | buf[0]); + *(uint32 *) buf = t; + buf += 4; + } while (--longs); + } #else - /* Note: this code is harmless on little-endian machines. - */ - void byteReverse(unsigned char *buf, unsigned longs) - { - uint32 t; - do { - t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | - ((unsigned) buf[1] << 8 | buf[0]); - *(uint32 *) buf = t; - buf += 4; - } while (--longs); - } + #error "Unsupported Byte Order..." #endif /* diff --git a/fko/md5.h b/fko/md5.h index 08fc88ee..bc637462 100644 --- a/fko/md5.h +++ b/fko/md5.h @@ -34,27 +34,6 @@ #define MD5_DIGESTSIZE 16 -/* The following tests optimise behaviour on little-endian - * machines, where there is no need to reverse the byte order - * of 32 bit words in the MD5 computation. By default, - * HIGHFIRST is defined, which indicates we're running on a - * big-endian (most significant byte first) machine, on which - * the byteReverse function in md5.c must be invoked. However, - * byteReverse is coded in such a way that it is an identity - * function when run on a little-endian machine, so calling it - * on such a platform causes no harm apart from wasting time. - * If the platform is known to be little-endian, we speed - * things up by undefining HIGHFIRST, which defines - * byteReverse as a null macro. Doing things in this manner - * insures we work on new platforms regardless of their byte - * order. -*/ -#define HIGHFIRST - -#ifdef __i386__ -#undef HIGHFIRST -#endif - typedef struct _MD5Context { uint32 buf[4]; uint32 bits[2]; diff --git a/fko/sha.h b/fko/sha.h index 83ba8b3f..efb76a7e 100644 --- a/fko/sha.h +++ b/fko/sha.h @@ -28,7 +28,6 @@ #ifndef SHA_H #define SHA_H 1 -#include #include "fko_common.h" /* Truncate to 32 bits -- should be a null op on 32-bit machines @@ -37,10 +36,6 @@ #define TRUNC32(x) ((x) & 0xffffffffL) #endif -/* This should be fine for most systems (hopefully). -*/ -#define BYTEORDER __BYTE_ORDER - #define SHA_BLOCKSIZE 64 #define SHA1_DIGESTSIZE 20 #define SHA256_DIGESTSIZE 32 diff --git a/src/spa_comm.c b/src/spa_comm.c index 50c6f471..14a06400 100644 --- a/src/spa_comm.c +++ b/src/spa_comm.c @@ -25,6 +25,9 @@ ***************************************************************************** */ #include "spa_comm.h" +#if HAVE_SYS_SOCKET_H + #include +#endif /* Send the SPA data via UDP packet. */