Skip to content

Commit

Permalink
More corrections to recent changes and from systematic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerhard Rieger committed Jan 3, 2021
1 parent b7a2774 commit 45ad401
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 56 deletions.
4 changes: 2 additions & 2 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@
#endif

/* Define if you have the OPENSSL_init_ssl function */
#undef HAVE_OPENSSL_init_ssl
#undef HAVE_OPENSSL_INIT_SSL

/* Define if you have the SSL_library_init function */
#undef HAVE_SSL_library_init
#undef HAVE_SSL_LIBRARY_INIT

/* Define if you have the SSLv2 client and server method functions. not in new openssl */
#undef HAVE_SSLv2_client_method
Expand Down
37 changes: 27 additions & 10 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ if test -n "$WITH_OPENSSL"; then
fi
fi # end checking for openssl/ssl.h
#

#if test -n "$WITH_OPENSSL"; then
# AC_CHECK_FUNCS(OPENSSL_init_ssl, SSL_library_init)
#fi

if test -n "$WITH_OPENSSL" -a "$sc_cv_have_openssl_ssl_h" = 'yes'; then
# next, we search for the openssl library (libssl.*)
# interesting: Linux only requires -lssl, FreeBSD requires -lssl -lcrypto
Expand All @@ -555,11 +560,12 @@ if test -n "$WITH_OPENSSL" -a "$sc_cv_have_openssl_ssl_h" = 'yes'; then
LIBS="$LIBS -lssl -lcrypto"
fi
AC_TRY_LINK([#include <openssl/ssl.h>],
[OPENSSL_init_ssl(0,NULL)],
[sc_cv_have_libssl='yes'; sc_cv_have_OPENSSL_init_ssl='yes'; AC_DEFINE(HAVE_OPENSSL_init_ssl)],
[AC_TRY_LINK([#include <openssl/ssl.h>],
[SSL_library_init()],
[sc_cv_have_libssl='yes'; sc_cv_have_SSL_library_init='yes'; AC_DEFINE(HAVE_SSL_library_init)],
[SSL_library_init();ERR_error_string()],
[sc_cv_have_libssl='yes'],
[ LIBS="$LIBS -lcrypto"
AC_TRY_LINK([#include <openssl/ssl.h>],
[SSL_library_init()],
[sc_cv_have_libssl='yes'],
[sc_cv_have_libssl='no'])
])
if test "$sc_cv_have_libssl" != 'yes'; then
Expand Down Expand Up @@ -602,6 +608,18 @@ if test -n "$WITH_OPENSSL"; then
fi
fi

AC_CHECK_FUNCS(OPENSSL_init_ssl SSL_library_init)

#; sc_cv_have_SSL_library_init='yes'; AC_DEFINE(HAVE_SSL_library_init)
#if test -n "$WITH_OPENSSL"; then
# AC_CHECK_LIB(crypto, CRYPTO_new_ex_data, [], [AC_MSG_ERROR([library 'crypto' is required for OpenSSL])])
# FOUND_SSL_LIB="no"
# AC_CHECK_LIB(ssl, OPENSSL_init_ssl, [FOUND_SSL_LIB="yes"])
# AC_CHECK_LIB(ssl, SSL_library_init, [FOUND_SSL_LIB="yes"])
# AS_IF([test "x$FOUND_SSL_LIB" = xno], [AC_MSG_ERROR([library 'ssl' is required for OpenSSL; WITH_OPENSSL=])])
# AS_IF([test "x$FOUND_SSL_LIB" = xyes], [LIBS="$LIBS -L$L -lssl -lcrypto"])
#fi

if test -n "$WITH_OPENSSL"; then
AC_MSG_CHECKING(whether to include OpenSSL method option)
AC_ARG_ENABLE(openssl-method, [ --enable-openssl-method enable OpenSSL method option],
Expand Down Expand Up @@ -795,7 +813,6 @@ AC_CHECK_FUNCS(putenv select pselect poll socket strtod strtol)
AC_CHECK_FUNCS(strtoul uname getpgid getsid gethostbyname getaddrinfo)
AC_CHECK_FUNCS(getprotobynumber getprotobynumber_r)
AC_CHECK_FUNCS(setgroups inet_aton)
AC_CHECK_FUNCS()

AC_CHECK_FUNCS(grantpt unlockpt)

Expand Down Expand Up @@ -1151,7 +1168,8 @@ AC_MSG_RESULT($sc_cv_struct_linger)
# struct ip (for IPv4 header info)
AC_MSG_CHECKING(for struct ip)
AC_CACHE_VAL(sc_cv_struct_ip,
[AC_TRY_COMPILE([#include <netinet/ip.h>],[struct ip s;],
[AC_TRY_COMPILE([#include <netinet/in.h>
#include <netinet/ip.h>],[struct ip s;],
[sc_cv_struct_ip=yes],
[sc_cv_struct_ip=no])])
if test $sc_cv_struct_ip = yes; then
Expand All @@ -1177,6 +1195,7 @@ AC_MSG_CHECKING(for struct ip_mreqn)
AC_CACHE_VAL(sc_cv_struct_ip_mreqn,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>],[struct ip_mreqn s;],
[sc_cv_struct_ip_mreqn=yes],
[sc_cv_struct_ip_mreqn=no])])
Expand All @@ -1203,6 +1222,7 @@ AC_MSG_CHECKING(for struct ip_mreq_source)
AC_CACHE_VAL(sc_cv_struct_ip_mreq_source,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>],[struct ip_mreq_source s;],
[sc_cv_struct_ip_mreq_source=yes],
[sc_cv_struct_ip_mreq_source=no])])
Expand Down Expand Up @@ -1486,8 +1506,6 @@ AC_CHECK_FUNC(setenv, AC_DEFINE(HAVE_SETENV),
dnl Search for unsetenv()
AC_CHECK_FUNC(unsetenv, AC_DEFINE(HAVE_UNSETENV))

AC_CHECK_FUNC(SSL_CTX_set_min_proto_version, AC_DEFINE(HAVE_SSL_CTX_set_min_proto_version))
AC_CHECK_FUNC(SSL_CTX_set_max_proto_version, AC_DEFINE(HAVE_SSL_CTX_set_max_proto_version))
AC_CHECK_FUNC(TLS_client_method, AC_DEFINE(HAVE_TLS_client_method) ac_cv_have_tls_client_method=yes, AC_CHECK_LIB(crypt, TLS_client_method, [LIBS=-lcrypt $LIBS]))
AC_CHECK_FUNC(TLS_server_method, AC_DEFINE(HAVE_TLS_server_method) ac_cv_have_tls_server_method=yes, AC_CHECK_LIB(crypt, TLS_server_method, [LIBS=-lcrypt $LIBS]))
AC_CHECK_FUNC(DTLS_client_method, AC_DEFINE(HAVE_DTLS_client_method), AC_CHECK_LIB(crypt, DTLS_client_method, [LIBS=-lcrypt $LIBS]))
Expand Down Expand Up @@ -1911,7 +1929,6 @@ struct rlimit, rlim_max, HAVE_TYPEOF_RLIM_MAX, sc_cv_type_rlimit_rlimmax_basic)
AC_TYPEOF_COMPONENT([#include "sysincludes.h"], struct cmsghdr, cmsg_len, HAVE_TYPEOF_STRUCT_CMSGHDR_CMSG_LEN, sc_cv_typeof_struct_cmsghdr_cmsg_len)
### snprintf, vsnprintf


AC_MSG_CHECKING(for /dev/ptmx)
if test -c /dev/ptmx; then
AC_DEFINE(HAVE_DEV_PTMX, 1)
Expand Down
4 changes: 2 additions & 2 deletions doc/socat.yo
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ label(ADDRESS_TCP_CONNECT)dit(bf(tt(TCP:<host>:<port>)))
link(tos)(OPTION_TOS),
link(mtudiscover)(OPTION_MTUDISCOVER),
link(mss)(OPTION_MSS),
link(nodelay)(OPTION_NODELAY),
link(nodelay)(OPTION_TCP_NODELAY),
link(nonblock)(OPTION_NONBLOCK),
link(sourceport)(OPTION_SOURCEPORT),
link(retry)(OPTION_RETRY),
Expand Down Expand Up @@ -3766,7 +3766,7 @@ standard specifications available on the Internet for free.
label(VERSION)
manpagesection(VERSION)

This man page describes version 1.7.3 of socat().
This man page describes version 1.7.4 of socat().


label(BUGS)
Expand Down
2 changes: 1 addition & 1 deletion fdname.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ int sockname(int fd, FILE *outfile, char style) {
optacceptconn?"(listening)":
#endif
"");
#endif /* WITH_UNIX */
break;
}
break;
#endif /* WITH_UNIX */
#if WITH_IP4
case AF_INET:
switch (style) {
Expand Down
12 changes: 10 additions & 2 deletions socat.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ int main(int argc, const char *argv[]) {
break;
}
}
if ((socat_opts.sniffleft = Open(a, O_CREAT|O_WRONLY|O_APPEND|O_LARGEFILE|O_NONBLOCK, 0664)) < 0)
if ((socat_opts.sniffleft = Open(a, O_CREAT|O_WRONLY|O_APPEND|
#ifdef O_LARGEFILE
O_LARGEFILE|
#endif
O_NONBLOCK, 0664)) < 0)
Error2("option -r \"%s\": %s", a, strerror(errno));
break;
case 'R': if (arg1[0][2]) {
Expand All @@ -199,7 +203,11 @@ int main(int argc, const char *argv[]) {
break;
}
}
if ((socat_opts.sniffright = Open(a, O_CREAT|O_WRONLY|O_APPEND|O_LARGEFILE|O_NONBLOCK, 0664)) < 0)
if ((socat_opts.sniffright = Open(a, O_CREAT|O_WRONLY|O_APPEND|
#ifdef O_LARGEFILE
O_LARGEFILE|
#endif
O_NONBLOCK, 0664)) < 0)
Error2("option -r \"%s\": %s", a, strerror(errno));
break;
case 'b': if (arg1[0][2]) {
Expand Down
2 changes: 2 additions & 0 deletions sslcls.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#if WITH_SYCLS
#if WITH_OPENSSL

#if HAVE_OPENSSL_init_ssl
int sycOPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings);
#endif
void sycSSL_load_error_strings(void);
int sycSSL_library_init(void);
const SSL_METHOD *sycTLS_client_method(void);
Expand Down
2 changes: 1 addition & 1 deletion sycls.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#if HAVE_PROTOTYPE_LIB_posix_memalign
int Posix_memalign(void **memptr, size_t alignment, size_t size) {
int result;
Debug3("posix_memalign(%p, "F_Zu", F_Zu)", memptr, alignment, size);
Debug3("posix_memalign(%p, "F_Zu", "F_Zu")", memptr, alignment, size);
result = posix_memalign(memptr, alignment, size);
Debug1("posix_memalign(...) -> %d", result);
return result;
Expand Down
77 changes: 51 additions & 26 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ ECHO="echo $E"
PRINTF="printf"

case "$TERM" in
vt100|vt320|linux|xterm|cons25|dtterm|aixterm|sun-color|xterm-color|xterm-256color)
vt100|vt320|linux|xterm|cons25|dtterm|aixterm|sun-color|xterm-color|xterm-256color|screen)
# there are different behaviours of printf (and echo)
# on some systems, echo behaves different than printf...
if [ $($PRINTF "\0101") = "A" ]; then
Expand Down Expand Up @@ -461,12 +461,48 @@ vt100|vt320|linux|xterm|cons25|dtterm|aixterm|sun-color|xterm-color|xterm-256col
;;
esac


if [ -x /usr/xpg4/bin/id ]; then
# SunOS has rather useless tools in its default path
PATH="/usr/xpg4/bin:$PATH"
fi

OPENSSL_S_CLIENT_4=
OPENSSL_S_CLIENT_DTLS=
init_openssl_s_client () {
if openssl s_client -help 2>&1 |grep -q ' -4 '; then
OPENSSL_S_CLIENT_4="-4"
else
OPENSSL_S_CLIENT_4=" "
fi
if openssl s_client -help 2>&1 | grep -q ' -dtls '; then
OPENSSL_S_CLIENT_DTLS=-dtls
else
OPENSSL_S_CLIENT_DTLS=-dtls1
fi
}

OPENSSL_S_SERVER_4=
OPENSSL_S_SERVER_DTLS=
OPENSSL_S_SERVER_NO_IGN_EOF=
init_openssl_s_server () {
if openssl s_server -help 2>&1 |grep -q ' -4 '; then
OPENSSL_S_SERVER_4="-4"
else
OPENSSL_S_SERVER_4=" "
fi
if openssl s_server -help 2>&1 | grep -q ' -dtls '; then
OPENSSL_S_SERVER_DTLS="-dtls"
else
OPENSSL_S_SERVER_DTLS="-dtls1"
fi
if openssl s_server -help 2>&1 | grep -q ' -no-ign_eof '; then
OPENSSL_S_SERVER_NO_IGN_EOF="-no-ign_eof"
else
OPENSSL_S_SERVER_NO_IGN_EOF=" "
fi
}


[ -z "$TESTS" ] && TESTS="consistency functions filan"
# use '%' as separation char
TESTS="%$(echo "$TESTS" |tr ' ' '%')%"
Expand Down Expand Up @@ -4265,7 +4301,8 @@ tf="$td/test$N.stdout"
te="$td/test$N.stderr"
tdiff="$td/test$N.diff"
da="test$N $(date) $RANDOM"
CMD2="$TRACE $SOCAT $opts exec:'openssl s_server -accept "$PORT" -quiet -cert testsrv.pem' pipe"
init_openssl_s_server
CMD2="$TRACE $SOCAT $opts exec:'openssl s_server $OPENSSL_S_SERVER_4 -accept "$PORT" -quiet -cert testsrv.pem' pipe"
CMD="$TRACE $SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
printf "test $F_n $TEST... " $N
eval "$CMD2 2>\"${te}1\" &"
Expand Down Expand Up @@ -7172,6 +7209,8 @@ TEST="$NAME: TCP4 mapped into TCP6 address space"
if ! eval $NUMCOND; then :;
elif true; then
$PRINTF "test $F_n $TEST... ${YELLOW}Feature removed${NORMAL}\n" $N
numCANT=$((numCANT+1))
listCANT="$listCANT $N"
elif ! testfeats tcp ip6 >/dev/null || ! runsip6 >/dev/null; then
$PRINTF "test $F_n $TEST... ${YELLOW}TCP6 not available${NORMAL}\n" $N
numCANT=$((numCANT+1))
Expand Down Expand Up @@ -11493,9 +11532,10 @@ tf="$td/test$N.stdout"
te="$td/test$N.stderr"
tdiff="$td/test$N.diff"
da="test$N $(date) $RANDOM"
init_openssl_s_client
CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0 PIPE"
#CMD1="openssl s_client -port $PORT -verify 0" # not with openssl 1.1.0g
CMD1="openssl s_client $OPENSSL_METHOD -port $PORT"
CMD1="openssl s_client $OPENSSL_S_CLIENT_4 $OPENSSL_METHOD -port $PORT"
printf "test $F_n $TEST... " $N
$CMD0 >/dev/null 2>"${te}0" &
pid0=$!
Expand Down Expand Up @@ -11553,9 +11593,10 @@ tf="$td/test$N.stdout"
te="$td/test$N.stderr"
tdiff="$td/test$N.diff"
da="test$N $(date) $RANDOM"
init_openssl_s_client
CMD0="$TRACE $SOCAT $opts OPENSSL-LISTEN:$PORT,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0 SYSTEM:\"sleep 1; echo \\\\\\\"\\\"$da\\\"\\\\\\\"; sleep 1\"!!STDIO"
#CMD1="openssl s_client -port $PORT -verify 0" # not with openssl 1.1.0g
CMD1="openssl s_client $OPENSSL_METHOD -port $PORT"
CMD1="openssl s_client $OPENSSL_S_CLIENT_4 $OPENSSL_METHOD -port $PORT"
printf "test $F_n $TEST... " $N
eval "$CMD0 >/dev/null 2>\"${te}0\" &"
pid0=$!
Expand Down Expand Up @@ -14018,21 +14059,8 @@ te="$td/test$N.stderr"
tdiff="$td/test$N.diff"
#set -vx
da="test$N $(date) $RANDOM"
S_SERVER_4=
if openssl s_server -help 2>&1 | grep -q ' -4 '; then
S_SERVER_4="-4"
fi
if openssl s_server -help 2>&1 | grep -q ' -dtls '; then
S_SERVER_DTLS=-dtls
else
S_SERVER_DTLS=-dtls1
fi
if openssl s_server -help 2>&1 | grep -q ' -no-ign_eof '; then
S_SERVER_NO_IGN_EOF=-no-ign_eof
else
S_SERVER_NO_IGN_EOF=
fi
CMD1="$TRACE openssl s_server $S_SERVER_4 $S_SERVER_DTLS -accept $PORT -quiet $S_SERVER_NO_IGN_EOF -cert testsrv.pem"
init_openssl_s_server
CMD1="$TRACE openssl s_server $OPENSSL_S_SERVER_4 $OPENSSL_S_SERVER_DTLS -accept $PORT -quiet $S_SERVER_NO_IGN_EOF -cert testsrv.pem"
CMD="$TRACE $SOCAT $opts -T 1 - OPENSSL-DTLS-CLIENT:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD"
printf "test $F_n $TEST... " $N
( sleep 2; echo "$da"; sleep 1 ) |$CMD1 2>"${te}1" &
Expand Down Expand Up @@ -14094,13 +14122,9 @@ tf="$td/test$N.stdout"
te="$td/test$N.stderr"
tdiff="$td/test$N.diff"
da="test$N $(date) $RANDOM"
if openssl s_server -help 2>&1 | grep -q ' -dtls '; then
S_SERVER_DTLS=-dtls
else
S_SERVER_DTLS=-dtls1
fi
init_openssl_s_client
CMD1="$TRACE $SOCAT $opts OPENSSL-DTLS-SERVER:$PORT,$REUSEADDR,cert=testsrv.crt,key=testsrv.key,verify=0 PIPE"
CMD="openssl s_client -host $LOCALHOST -port $PORT $S_SERVER_DTLS"
CMD="openssl s_client $OPENSSL_S_CLIENT_4 -host $LOCALHOST -port $PORT $OPENSSL_S_CLIENT_DTLS"
printf "test $F_n $TEST... " $N
$CMD1 >/dev/null 2>"${te}1" &
pid1=$!
Expand Down Expand Up @@ -14503,6 +14527,7 @@ pid0=$!
waitudp4port $PORT 1
echo "$da" |$CMD1 >"${tf}1" 2>"${te}1"
rc1=$?
sleep 0.1
kill $pid0 2>/dev/null; wait
if [ -f ${tf}0 ] && echo "$da" |diff - ${tf}0 >$tdiff; then
$PRINTF "$OK\n"
Expand Down
14 changes: 7 additions & 7 deletions xio-ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,11 @@ int xiotype_ip_add_source_membership(char *token, const struct optname *ent, str
*buffp++ = '\0';
opt->value.u_ip_mreq_source.srcaddr = strdup(buff); /*!!! NULL */

Info4("setting option \"%s\" to {0x%08x,0x%08x,0x08x}",
Info4("setting option \"%s\" to {0x%08x,0x%08x,0x%08x}",
ent->desc->defname,
opt->value.u_ip_mreq_source.mcaddr,
opt->value.u_ip_mreq_source.ifaddr,
opt->value.u_ip_mreq_source.srcaddr);
ntohl(*(unsigned int *)opt->value.u_ip_mreq_source.mcaddr),
ntohl(*(unsigned int *)opt->value.u_ip_mreq_source.ifaddr),
ntohl(*(unsigned int *)opt->value.u_ip_mreq_source.srcaddr));
return 0;
}

Expand Down Expand Up @@ -708,9 +708,9 @@ int xioapply_ip_add_source_membership(struct single *xfd, struct opt *opt) {
&ip4_mreq_src, sizeof(ip4_mreq_src)) < 0) {
Error8("setsockopt(%d, %d, %d, {0x%08x,0x%08x,0x%08x}, "F_Zu"): %s",
xfd->fd, opt->desc->major, opt->desc->minor,
ip4_mreq_src.imr_multiaddr,
ip4_mreq_src.imr_interface,
ip4_mreq_src.imr_sourceaddr,
htonl((uint32_t)ip4_mreq_src.imr_multiaddr.s_addr),
ip4_mreq_src.imr_interface.s_addr,
ip4_mreq_src.imr_sourceaddr.s_addr,
sizeof(struct ip_mreq_source),
strerror(errno));
opt->desc = ODESC_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion xio-listen.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ int _xioopen_listen(struct single *xfd, int xioflags, struct sockaddr *us, sockl
while (1) {
if (Select(xfd->fd+1, &rfd, NULL, NULL, &tmo) < 0) {
if (errno != EINTR) {
Error5("Select(%d, &0x%lx, NULL, NULL, {%ld.%ld}): %s", xfd->fd+1, 1<<(xfd->fd+1),
Error5("Select(%d, &0x%lx, NULL, NULL, {%ld.%06ld}): %s", xfd->fd+1, 1L<<(xfd->fd+1),
xfd->para.socket.accept_timeout.tv_sec, xfd->para.socket.accept_timeout.tv_usec,
strerror(errno));
}
Expand Down
Loading

0 comments on commit 45ad401

Please sign in to comment.