diff --git a/CHANGES b/CHANGES index 8f1d27f..c6cb959 100644 --- a/CHANGES +++ b/CHANGES @@ -102,6 +102,9 @@ porting: on some 64bit systems a compiler warning "cast from pointer to integer of different size" was issued on some option definitions + Cedril Priscal ported socat to Android (using Googles cross compiler). + The port includes the socat_buildscript_for_android.sh script + ####################### V 2.0.0-b7: security: diff --git a/config.h.in b/config.h.in index 6b92a90..f299dff 100644 --- a/config.h.in +++ b/config.h.in @@ -477,6 +477,10 @@ /* Define if you have the /proc/$$/fd directories */ #undef HAVE_PROC_DIR_FD +#undef HAVE_SETGRENT +#undef HAVE_GETGRENT +#undef HAVE_ENDGRENT + #undef WITH_HELP #undef WITH_NOP #undef WITH_TEST diff --git a/configure.in b/configure.in index 043f151..b15dcf3 100644 --- a/configure.in +++ b/configure.in @@ -80,6 +80,8 @@ AC_CHECK_HEADERS(sys/utsname.h sys/select.h sys/file.h) AC_CHECK_HEADERS(util.h libutil.h sys/stropts.h regex.h) AC_CHECK_HEADERS(linux/fs.h linux/ext2_fs.h) +dnl Checks for setgrent, getgrent and endgrent. +AC_CHECK_FUNCS(setgrent getgrent endgrent) dnl Link libresolv if necessary (for Mac OS X) AC_SEARCH_LIBS([res_9_init], [resolv]) diff --git a/socat_buildscript_for_android.sh b/socat_buildscript_for_android.sh new file mode 100755 index 0000000..31448a8 --- /dev/null +++ b/socat_buildscript_for_android.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +# Customize these parameters according to your environment +ANDROID_NDK="${HOME}/bin/android-ndk-r6b" + +# Check for parameters +if [ ! -d "${ANDROID_NDK}" ]; then + echo "Android NDK not found in ${ANDROID_NDK}, please edit $0 to fix it." + exit 1 +fi + +if [ ! -e "${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh" ]; then + echo "Your Android NDK is not compatible (make-standalone-toolchain.sh not found)." + echo "Android NDK r6b is known to work." + exit 1 +fi + +# Extract the Android toolchain from NDK +ANDROID_PLATFORM="android-3" +ROOT="`pwd`" +OUT="${ROOT}/out" +${ANDROID_NDK}/build/tools/make-standalone-toolchain.sh \ + --ndk-dir="${ANDROID_NDK}" \ + --platform="${ANDROID_PLATFORM}" \ + --install-dir="${OUT}/toolchain" \ + || exit 1 +# Remove resolv.h because it is quite unusable as is +rm ${OUT}/toolchain/sysroot/usr/include/resolv.h + +# Create configure script +cd ${ROOT} +autoconf || exit 1 + +# Create config.h and Makefile +cd ${OUT} +${ROOT}/configure \ + --host \ + --disable-openssl \ + --disable-unix \ + CC="${OUT}/toolchain/bin/arm-linux-androideabi-gcc" \ + || exit 1 + +# Replace misconfigured values in config.h +mv config.h config.old +cat config.old \ + | sed 's/CRDLY_SHIFT/CRDLY_SHIFT 9/' \ + | sed 's/TABDLY_SHIFT/TABDLY_SHIFT 11/' \ + | sed 's/CSIZE_SHIFT/CSIZE_SHIFT 4/' \ + > config.h + +# Compile +make socat || exit 1 + +# Done +echo "Build finished, socat has been generated successfuly in out/socat" + diff --git a/sysutils.c b/sysutils.c index 1adfd9e..c5cd9a8 100644 --- a/sysutils.c +++ b/sysutils.c @@ -412,6 +412,7 @@ char *sockaddr_inet6_info(const struct sockaddr_in6 *sa, char *buff, size_t blen } #endif /* WITH_IP6 */ +#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT) /* fill the list with the supplementary group ids of user. caller passes size of list in ngroups, function returns number of groups in ngroups. @@ -438,6 +439,7 @@ int getusergroups(const char *user, gid_t *list, size_t *ngroups) { *ngroups = i; return 0; } +#endif #if !HAVE_HSTRERROR const char *hstrerror(int err) { diff --git a/sysutils.h b/sysutils.h index dc1dd44..5541e9e 100644 --- a/sysutils.h +++ b/sysutils.h @@ -74,7 +74,9 @@ extern const char *inet_ntop(int pf, const void *binaddr, char *addrtext, socklen_t textlen); #endif +#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT) extern int getusergroups(const char *user, gid_t *list, size_t *ngroups); +#endif #if !HAVE_HSTRERROR extern const char *hstrerror(int err); diff --git a/xio-process.c b/xio-process.c index 5ee3506..bbc0bd5 100644 --- a/xio-process.c +++ b/xio-process.c @@ -1,5 +1,5 @@ /* source: xio-process.c */ -/* Copyright Gerhard Rieger 2001-2009 */ +/* Copyright Gerhard Rieger 2001-2012 */ /* Published under the GNU General Public License V.2, see file COPYING */ /* this file handles process related addresses options */ @@ -16,7 +16,9 @@ const struct optdesc opt_setuid_early= { "setuid-early",NULL, OPT_SETUID_EARLY, const struct optdesc opt_setuid = { "setuid", NULL, OPT_SETUID, GROUP_PROCESS, PH_LATE2, TYPE_UIDT, OFUNC_SPEC }; const struct optdesc opt_substuser_early = { "substuser-early", "su-e", OPT_SUBSTUSER_EARLY, GROUP_PROCESS, PH_EARLY, TYPE_UIDT, OFUNC_SPEC }; const struct optdesc opt_substuser = { "substuser", "su", OPT_SUBSTUSER, GROUP_PROCESS, PH_LATE2, TYPE_UIDT, OFUNC_SPEC }; +#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT) const struct optdesc opt_substuser_delayed = { "substuser-delayed", "su-d", OPT_SUBSTUSER_DELAYED, GROUP_PROCESS, PH_INIT, TYPE_UIDT, OFUNC_SPEC }; +#endif const struct optdesc opt_chroot_early = { "chroot-early", NULL, OPT_CHROOT_EARLY, GROUP_PROCESS, PH_EARLY, TYPE_STRING, OFUNC_SPEC }; const struct optdesc opt_chroot = { "chroot", NULL, OPT_CHROOT, GROUP_PROCESS, PH_LATE, TYPE_STRING, OFUNC_SPEC }; const struct optdesc opt_setsid = { "setsid", "sid", OPT_SETSID, GROUP_PROCESS, PH_LATE, TYPE_BOOL, OFUNC_SPEC }; diff --git a/xio-process.h b/xio-process.h index 09ddc8c..ce053d0 100644 --- a/xio-process.h +++ b/xio-process.h @@ -1,5 +1,5 @@ /* source: xio-process.h */ -/* Copyright Gerhard Rieger 2001-2009 */ +/* Copyright Gerhard Rieger 2001-2012 */ /* Published under the GNU General Public License V.2, see file COPYING */ #ifndef __xio_process_h_included @@ -11,7 +11,9 @@ extern const struct optdesc opt_setuid_early; extern const struct optdesc opt_setuid; extern const struct optdesc opt_substuser_early; extern const struct optdesc opt_substuser; +#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT) extern const struct optdesc opt_substuser_delayed; +#endif extern const struct optdesc opt_chroot_early; extern const struct optdesc opt_chroot; extern const struct optdesc opt_setsid; diff --git a/xio-pty.c b/xio-pty.c index 367e738..27c8de4 100644 --- a/xio-pty.c +++ b/xio-pty.c @@ -91,7 +91,9 @@ static int xioopen_pty(const char *linkname, struct opt *opts, int xioflags, xio useptmx = true; # endif /* !HAVE_OPENPTY */ #else - useopenpty = true; +# if HAVE_OPENPTY + useopenpty = true; +#endif /* HAVE_OPENPTY */ #endif /* ! (defined(HAVE_DEV_PTMX) || defined(HAVE_DEV_PTC)) */ #if HAVE_POLL diff --git a/xioopts.c b/xioopts.c index b038112..5995776 100644 --- a/xioopts.c +++ b/xioopts.c @@ -1430,10 +1430,14 @@ const struct optname optionnames[] = { IF_ANY ("streams-i-push", &opt_streams_i_push) #endif IF_ANY ("su", &opt_substuser) +#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT) IF_ANY ("su-d", &opt_substuser_delayed) +#endif IF_ANY ("su-e", &opt_substuser_early) IF_ANY ("substuser", &opt_substuser) +#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT) IF_ANY ("substuser-delayed", &opt_substuser_delayed) +#endif IF_ANY ("substuser-early", &opt_substuser_early) IF_TERMIOS("susp", &opt_vsusp) #ifdef VSWTC @@ -3323,6 +3327,7 @@ int applyopts(int fd, struct opt *opts, enum e_phase phase) { #endif } break; +#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT) case OPT_SUBSTUSER_DELAYED: { struct passwd *pwd; @@ -3356,6 +3361,7 @@ int applyopts(int fd, struct opt *opts, enum e_phase phase) { delayeduser = true; } break; +#endif case OPT_CHROOT_EARLY: case OPT_CHROOT: if (Chroot(opt->value.u_string) < 0) {