From 26801266f2bca0c7b946ceaa21f45eae1b2ff04e Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Tue, 22 Nov 2011 10:58:15 +0100 Subject: [PATCH] port to Android --- CHANGES | 4 +++ config.h.in | 4 +++ configure.in | 2 ++ socat_buildscript_for_android.sh | 56 ++++++++++++++++++++++++++++++++ sysutils.c | 2 ++ sysutils.h | 2 ++ xio-process.c | 2 ++ xio-process.h | 2 ++ xio-pty.c | 2 ++ xioopts.c | 6 ++++ xioopts.h | 2 ++ 11 files changed, 84 insertions(+) create mode 100644 socat_buildscript_for_android.sh diff --git a/CHANGES b/CHANGES index 0fa0a9c..30490fb 100644 --- a/CHANGES +++ b/CHANGES @@ -53,6 +53,10 @@ corrections: Fixed by providing temporary DH parameters. Thanks to Philip Rowlands for drawing my attention to this issue. +porting: + Cedril Priscal ported socat to Android (using Googles cross compiler). + The port includes the socat_buildscript_for_android.sh script + ####################### V 1.7.1.3: security: diff --git a/config.h.in b/config.h.in index becd07b..a9d0f18 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_STDIO #undef WITH_FDNUM diff --git a/configure.in b/configure.in index b28e4ac..de9b791 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 100644 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 139d551..00fd6f1 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 171b65a..f55f676 100644 --- a/sysutils.h +++ b/sysutils.h @@ -73,7 +73,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..96d93dc 100644 --- a/xio-process.c +++ b/xio-process.c @@ -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..d67594c 100644 --- a/xio-process.h +++ b/xio-process.h @@ -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 dff08a5..3ca8226 100644 --- a/xio-pty.c +++ b/xio-pty.c @@ -78,7 +78,9 @@ static int xioopen_pty(int argc, const char *argv[], struct opt *opts, int xiofl useptmx = true; # endif /* !HAVE_OPENPTY */ #else +# 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 2826d2c..98a397d 100644 --- a/xioopts.c +++ b/xioopts.c @@ -1458,10 +1458,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 @@ -3330,6 +3334,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; @@ -3363,6 +3368,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) { diff --git a/xioopts.h b/xioopts.h index 38e8a70..005e617 100644 --- a/xioopts.h +++ b/xioopts.h @@ -703,7 +703,9 @@ enum e_optcode { # undef ENABLE_OPTCODE OPT_SUBSTUSER_EARLY, OPT_SUBSTUSER, +#if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT) OPT_SUBSTUSER_DELAYED, +#endif OPT_SYMBOLIC_LINK, /* with pty */ #ifdef TABDLY # ifdef TAB0