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.
This commit is contained in:
Craig Comstock 2020-01-24 16:45:01 -06:00 committed by Leonid Pliushch
parent fc1c4c4bd5
commit e3c96a403e
4 changed files with 163 additions and 0 deletions

View File

@ -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"
}

View File

@ -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 <signal.h>
+#ifdef __ANDROID__
+#include <android/log.h>
+#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)

View File

@ -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 <audit.h>
+#ifdef __TERMUX__
+#include <file_lib.h>
+#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)

View File

@ -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);