From c34cfe06520d106e66b2c7da62b3dce8757bfdd6 Mon Sep 17 00:00:00 2001 From: Craig Comstock Date: Fri, 24 Jan 2020 16:45:01 -0600 Subject: [PATCH] Added CFEngine (core + masterfiles) package Bootstrapping from a policy server (or self) doesn't work yet. There may be other issues but the basics work and this is useful as a way to test out policy on-the-go. --- packages/cfengine/build.sh | 22 +++++++ packages/cfengine/fixup-for-termux.patch | 66 +++++++++++++++++++ .../libpromises-patches-copy-not-link.patch | 24 +++++++ packages/cfengine/unix_iface.patch | 51 ++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 packages/cfengine/build.sh create mode 100644 packages/cfengine/fixup-for-termux.patch create mode 100644 packages/cfengine/libpromises-patches-copy-not-link.patch create mode 100644 packages/cfengine/unix_iface.patch diff --git a/packages/cfengine/build.sh b/packages/cfengine/build.sh new file mode 100644 index 000000000..62aabb2c7 --- /dev/null +++ b/packages/cfengine/build.sh @@ -0,0 +1,22 @@ +TERMUX_PKG_HOMEPAGE=https://cfengine.com/ +TERMUX_PKG_DESCRIPTION="CFEngine is a configuration management technology." +TERMUX_PKG_LICENSE="GPL-3.0" +TERMUX_PKG_VERSION=3.15.1 +TERMUX_PKG_SRCURL=(https://cfengine-package-repos.s3.amazonaws.com/tarballs/cfengine-$TERMUX_PKG_VERSION.tar.gz + https://github.com/cfengine/masterfiles/archive/$TERMUX_PKG_VERSION.tar.gz) +TERMUX_PKG_SHA256=(ab597456f9d44d907bb5a2e82b8ce2af01e9c59641dc828457cd768ef05a831d + 1da37b8af293f5c072ed6991f4bb910cc2b387038e4dc7c34ae1763515b558e1) +TERMUX_PKG_DEPENDS="liblmdb, openssl, libandroid-glob, pcre" +# core doesn't work with out-of-tree builds +TERMUX_PKG_BUILD_IN_SRC=true +TERMUX_PKG_EXTRA_CONFIGURE_ARGS="--with-workdir=$TERMUX_PREFIX/var/lib/cfengine --without-pam --without-selinux-policy --without-systemd-service --with-lmdb=$TERMUX_PREFIX --with-openssl=$TERMUX_PREFIX --with-pcre=$TERMUX_PREFIX" + +termux_step_post_extract_package() { + cd masterfiles-${TERMUX_PKG_VERSION} + EXPLICIT_VERSION=${TERMUX_PKG_VERSION} ./autogen.sh --prefix=$TERMUX_PREFIX/var/lib/cfengine --bindir=$TERMUX_PREFIX/bin + make install +} + +termux_step_pre_configure() { + LDFLAGS+=" -landroid-glob" +} diff --git a/packages/cfengine/fixup-for-termux.patch b/packages/cfengine/fixup-for-termux.patch new file mode 100644 index 000000000..e5f2e742b --- /dev/null +++ b/packages/cfengine/fixup-for-termux.patch @@ -0,0 +1,66 @@ +diff --git a/cf-agent/cf-agent.c b/cf-agent/cf-agent.c +index 8c6341059..1b454325b 100644 +--- a/cf-agent/cf-agent.c ++++ b/cf-agent/cf-agent.c +@@ -365,8 +365,7 @@ static void ConfigureBootstrap(GenericAgentConfig *config, const char *argument) + + if(IsLoopbackAddress(argument)) + { +- Log(LOG_LEVEL_ERR, "Cannot bootstrap to a loopback address"); +- DoCleanupAndExit(EXIT_FAILURE); ++ Log(LOG_LEVEL_WARNING, "Bootstrapping to loopback interface (localhost), other hosts will not be able to bootstrap to this server"); + } + + // temporary assure that network functions are working + +diff --git a/libutils/file_lib.c b/libutils/file_lib.c +index 816d719..d96a27e 100644 +--- a/libntech/libutils/file_lib.c ++++ b/libntech/libutils/file_lib.c +@@ -564,6 +540,9 @@ int safe_open_create_perms( + return open(pathname, flags, create_perms); + #else // !__MINGW32__ + ++#ifdef __TERMUX__ ++ return open(pathname, flags, create_perms); ++#endif + const size_t path_bufsize = strlen(pathname) + 1; + char path[path_bufsize]; + const size_t res_len = StringCopy(pathname, path, path_bufsize); + +diff --git a/libutils/platform.h b/libutils/platform.h +index 964adaa..af6e8d7 100644 +--- a/libntech/libutils/platform.h ++++ b/libntech/libutils/platform.h +@@ -178,6 +178,9 @@ struct utsname + #endif + + #include ++#ifdef __ANDROID__ ++#include ++#endif + + #ifdef __MINGW32__ + # define LOG_LOCAL0 (16<<3) + +diff --git a/libutils/known_dirs.c b/libutils/known_dirs.c +index 386f6ec..6d0955b 100644 +--- a/libntech/libutils/known_dirs.c ++++ b/libntech/libutils/known_dirs.c +@@ -89,7 +89,6 @@ const char *GetDefaultDir_helper(char *dir, const char *root_dir, + } + } + +-#endif + + #define GET_DEFAULT_DIRECTORY_DEFINE(FUNC, STATIC, GLOBAL, FOLDER) \ + const char *GetDefault##FUNC##Dir(void) \ +@@ -106,6 +105,8 @@ GET_DEFAULT_DIRECTORY_DEFINE(Master, master, MASTERDIR, "masterfiles") + GET_DEFAULT_DIRECTORY_DEFINE(Input, input, INPUTDIR, "inputs") + GET_DEFAULT_DIRECTORY_DEFINE(State, state, STATEDIR, "state") + ++#endif ++ + /*******************************************************************/ + + const char *GetWorkDir(void) diff --git a/packages/cfengine/libpromises-patches-copy-not-link.patch b/packages/cfengine/libpromises-patches-copy-not-link.patch new file mode 100644 index 000000000..621fa9d56 --- /dev/null +++ b/packages/cfengine/libpromises-patches-copy-not-link.patch @@ -0,0 +1,24 @@ +diff --git a/libpromises/patches.c b/libpromises/patches.c +index 40407eb1f..9bc1fadbd 100644 +--- a/libpromises/patches.c ++++ b/libpromises/patches.c +@@ -34,6 +34,10 @@ + + #include + ++#ifdef __TERMUX__ ++#include ++#endif ++ + static char *cf_format_strtimestamp(struct tm *tm, char *buf); + + /*********************************************************/ +@@ -193,6 +197,8 @@ bool LinkOrCopy(const char *from, const char *to, int sym) + return false; + } + ++#elif __TERMUX__ // link() not supported on android/termux so use rename() instead ++ return File_Copy(from, to); + #else /* !__MINGW32__ */ + + if (sym) diff --git a/packages/cfengine/unix_iface.patch b/packages/cfengine/unix_iface.patch new file mode 100644 index 000000000..0544cc58d --- /dev/null +++ b/packages/cfengine/unix_iface.patch @@ -0,0 +1,51 @@ +diff --git a/libenv/unix_iface.c b/libenv/unix_iface.c +index 65e359921..905e13c84 100644 +--- a/libenv/unix_iface.c ++++ b/libenv/unix_iface.c +@@ -147,7 +147,7 @@ static void GetMacAddress(EvalContext *ctx, ARG_UNUSED int fd, struct ifreq *ifr + return; + } + +-# if defined(SIOCGIFHWADDR) && defined(HAVE_STRUCT_IFREQ_IFR_HWADDR) ++# if defined(SIOCGIFHWADDR) && defined(HAVE_STRUCT_IFREQ_IFR_HWADDR) && !defined(__TERMUX__) + char hw_mac[CF_MAXVARSIZE]; + + if ((ioctl(fd, SIOCGIFHWADDR, ifr) == -1)) +@@ -173,9 +173,8 @@ static void GetMacAddress(EvalContext *ctx, ARG_UNUSED int fd, struct ifreq *ifr + + # elif defined(HAVE_GETIFADDRS) && !defined(__sun) + char hw_mac[CF_MAXVARSIZE]; +- char *m; + struct ifaddrs *ifaddr, *ifa; +- struct sockaddr_dl *sdl; ++ struct sockaddr_ll *sdl; + + if (getifaddrs(&ifaddr) == -1) + { +@@ -190,18 +189,16 @@ static void GetMacAddress(EvalContext *ctx, ARG_UNUSED int fd, struct ifreq *ifr + { + if ( strcmp(ifa->ifa_name, ifp->ifr_name) == 0) + { +- if (ifa->ifa_addr->sa_family == AF_LINK) ++ if (ifa->ifa_addr->sa_family == AF_PACKET) + { +- sdl = (struct sockaddr_dl *)ifa->ifa_addr; +- m = (char *) LLADDR(sdl); +- ++ sdl = (struct sockaddr_ll*)ifa->ifa_addr; + snprintf(hw_mac, sizeof(hw_mac), "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", +- (unsigned char) m[0], +- (unsigned char) m[1], +- (unsigned char) m[2], +- (unsigned char) m[3], +- (unsigned char) m[4], +- (unsigned char) m[5]); ++ sdl->sll_addr[0], ++ sdl->sll_addr[1], ++ sdl->sll_addr[2], ++ sdl->sll_addr[3], ++ sdl->sll_addr[4], ++ sdl->sll_addr[5]); + + EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS, name, hw_mac, CF_DATA_TYPE_STRING, "source=agent"); + RlistAppend(hardware, hw_mac, RVAL_TYPE_SCALAR);