From 20b30d7b5aff5c8f17498684627dc798e0ca9a83 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Fri, 21 Aug 2026 16:45:08 +0200 Subject: [PATCH] Added date binary inside cfengine Added /var/cfengine/bin/date from coreutils, in a similar way to diff, to be able to parse date and time Signed-off-by: Victor Moene --- build-scripts/compile-options | 8 ++ ...-grp.h-includes-in-idcache.c-and-use.patch | 116 ++++++++++++++++++ deps-packaging/coreutils/built-sources.mk | 3 + .../coreutils/cfbuild-coreutils.spec | 54 ++++++++ .../debian/cfbuild-coreutils.install | 1 + deps-packaging/coreutils/debian/compat | 1 + deps-packaging/coreutils/debian/control | 12 ++ deps-packaging/coreutils/debian/copyright | 0 deps-packaging/coreutils/debian/rules | 46 +++++++ deps-packaging/coreutils/distfiles | 1 + .../debian/cfbuild-coreutils-mingw64.install | 1 + deps-packaging/coreutils/mingw/debian/compat | 1 + deps-packaging/coreutils/mingw/debian/control | 12 ++ .../coreutils/mingw/debian/copyright | 0 deps-packaging/coreutils/mingw/debian/rules | 52 ++++++++ deps-packaging/coreutils/source | 1 + deps-packaging/release-monitoring.json | 1 + .../cfengine-community.spec.in | 1 + .../debian/cfengine-community.install | 1 + .../cfengine-nova-hub.spec.in | 1 + .../debian/cfengine-nova-hub.install | 1 + packaging/cfengine-nova/cfengine-nova.spec.in | 1 + packaging/cfengine-nova/cfengine-nova.wxs | 4 + .../debian/cfengine-nova.install | 1 + 24 files changed, 320 insertions(+) create mode 100644 deps-packaging/coreutils/0001-Guard-pwd.h-and-grp.h-includes-in-idcache.c-and-use.patch create mode 100644 deps-packaging/coreutils/built-sources.mk create mode 100644 deps-packaging/coreutils/cfbuild-coreutils.spec create mode 100644 deps-packaging/coreutils/debian/cfbuild-coreutils.install create mode 100644 deps-packaging/coreutils/debian/compat create mode 100644 deps-packaging/coreutils/debian/control create mode 100644 deps-packaging/coreutils/debian/copyright create mode 100755 deps-packaging/coreutils/debian/rules create mode 100644 deps-packaging/coreutils/distfiles create mode 100644 deps-packaging/coreutils/mingw/debian/cfbuild-coreutils-mingw64.install create mode 100644 deps-packaging/coreutils/mingw/debian/compat create mode 100644 deps-packaging/coreutils/mingw/debian/control create mode 100644 deps-packaging/coreutils/mingw/debian/copyright create mode 100755 deps-packaging/coreutils/mingw/debian/rules create mode 100644 deps-packaging/coreutils/source diff --git a/build-scripts/compile-options b/build-scripts/compile-options index 7b0d9936a..ccb38d7e5 100644 --- a/build-scripts/compile-options +++ b/build-scripts/compile-options @@ -142,6 +142,14 @@ var_append DEPS "libyaml" # Library for parsing YAML var_append DEPS "diffutils" # Library for comparing files var_append DEPS "librsync" # Library for synchronization of file +# coreutils is only built for redhat/debian/windows for now +case "$OS_FAMILY" in +hpux | aix | solaris | freebsd) ;; +*) + var_append DEPS "coreutils" # Provides a standalone 'date' binary + ;; +esac + # Enterprise only dependencies case "$PROJECT" in nova) diff --git a/deps-packaging/coreutils/0001-Guard-pwd.h-and-grp.h-includes-in-idcache.c-and-use.patch b/deps-packaging/coreutils/0001-Guard-pwd.h-and-grp.h-includes-in-idcache.c-and-use.patch new file mode 100644 index 000000000..09a005c70 --- /dev/null +++ b/deps-packaging/coreutils/0001-Guard-pwd.h-and-grp.h-includes-in-idcache.c-and-use.patch @@ -0,0 +1,116 @@ +From 0c15fbcf18c0736149d06957e9058563fec065d3 Mon Sep 17 00:00:00 2001 +From: Victor Moene +Date: Tue, 25 Aug 2026 09:47:54 +0200 +Subject: [PATCH] Guard / includes in idcache.c and userspec.c + +We only build the "date" program out of coreutils, but the build compiles +every gnulib lib/*.c file into a single lib/libcoreutils.a used by all +coreutils programs, regardless of whether "date" actually needs them. + +lib/idcache.c and lib/userspec.c unconditionally include and + to resolve uids/gids via the system's user and group databases. +Native Windows (mingw-w64) ships neither header, so compiling +lib/libcoreutils.a for date.exe failed there even though date.exe never +references any symbol from these two files. + +Guard the includes, and the function bodies that depend on them, with +the HAVE_PWD_H/HAVE_GRP_H macros that configure already defines via +AC_CHECK_HEADERS. This way the two files compile down to empty +translation units on platforms lacking these headers. If some other +coreutils program actually needs the passwd/group lookups these files +provide, linking that program will now fail with an undefined +reference, surfacing the problem at build time instead of silently +linking in stub declarations that could never work. + +Ticket: None +Changelog: none +--- + lib/idcache.c | 18 ++++++++++++++++-- + lib/userspec.c | 18 ++++++++++++++++-- + 2 files changed, 32 insertions(+), 4 deletions(-) + +diff --git a/lib/idcache.c b/lib/idcache.c +index 5fd5f2c..327175e 100644 +--- a/lib/idcache.c ++++ b/lib/idcache.c +@@ -22,8 +22,12 @@ + #include + #include + #include +-#include +-#include ++#if HAVE_PWD_H ++# include ++#endif ++#if HAVE_GRP_H ++# include ++#endif + + #include + +@@ -63,6 +67,14 @@ static struct userid *group_alist; + /* Each entry on list is a group name for which the first lookup failed. */ + static struct userid *nogroup_alist; + ++/* The functions below all resolve uids/gids via the system's user and ++ group databases, so they require and . On platforms ++ that lack these headers (e.g. native Windows), omit them entirely ++ rather than fake up the lookups: if some program actually needs them, ++ it will fail to link, which is preferable to silently linking in a ++ passwd/group lookup that can never work. */ ++#if HAVE_PWD_H && HAVE_GRP_H ++ + /* Translate UID to a login name, with cache, or NULL if unresolved. */ + + char * +@@ -220,3 +232,5 @@ getgidbyname (const char *group) + nogroup_alist = tail; + return NULL; + } ++ ++#endif /* HAVE_PWD_H && HAVE_GRP_H */ +diff --git a/lib/userspec.c b/lib/userspec.c +index 57cd023..943257a 100644 +--- a/lib/userspec.c ++++ b/lib/userspec.c +@@ -24,8 +24,12 @@ + + #include + #include +-#include +-#include ++#if HAVE_PWD_H ++# include ++#endif ++#if HAVE_GRP_H ++# include ++#endif + + #if HAVE_SYS_PARAM_H + # include +@@ -97,6 +101,14 @@ is_number (const char *str) + } + #endif + ++/* Resolving a user/group spec requires looking it up via the system's ++ user and group databases, so the code below needs and ++ . On platforms that lack these headers (e.g. native Windows), ++ omit it entirely rather than fake up the lookups: if some program ++ actually needs it, it will fail to link, which is preferable to ++ silently linking in a passwd/group lookup that can never work. */ ++#if HAVE_PWD_H && HAVE_GRP_H ++ + static char const * + parse_with_separator (char const *spec, char const *separator, + uid_t *uid, gid_t *gid, +@@ -289,6 +301,8 @@ parse_user_spec (char const *spec, uid_t *uid, gid_t *gid, + return parse_user_spec_warn (spec, uid, gid, username, groupname, NULL); + } + ++#endif /* HAVE_PWD_H && HAVE_GRP_H */ ++ + #ifdef TEST + + # define NULL_CHECK(s) ((s) == NULL ? "(null)" : (s)) +-- +2.43.0 diff --git a/deps-packaging/coreutils/built-sources.mk b/deps-packaging/coreutils/built-sources.mk new file mode 100644 index 000000000..8e37f71ce --- /dev/null +++ b/deps-packaging/coreutils/built-sources.mk @@ -0,0 +1,3 @@ +include Makefile +print-built-sources: + @echo $(BUILT_SOURCES) diff --git a/deps-packaging/coreutils/cfbuild-coreutils.spec b/deps-packaging/coreutils/cfbuild-coreutils.spec new file mode 100644 index 000000000..b809dfa32 --- /dev/null +++ b/deps-packaging/coreutils/cfbuild-coreutils.spec @@ -0,0 +1,54 @@ +%define coreutils_version 9.11 + +Summary: CFEngine Build Automation -- coreutils (date) +Name: cfbuild-coreutils +Version: %{version} +Release: 1 +Source0: coreutils-%{coreutils_version}.tar.xz +Patch0: 0001-Guard-pwd.h-and-grp.h-includes-in-idcache.c-and-use.patch +License: GPL3 +Group: Other +Url: https://cfengine.com +BuildRoot: %{_topdir}/BUILD/%{name}-%{version}-%{release}-buildroot + +AutoReqProv: no + +%define prefix %{buildprefix} + +%prep +mkdir -p %{_builddir} +%setup -q -n coreutils-%{coreutils_version} + +%patch0 -p1 + +cp %{_sourcedir}/built-sources.mk . + +FORCE_UNSAFE_CONFIGURE=1 ./configure --prefix=%{prefix} + +%build + +# We only need the "date" binary out of the whole coreutils suite, so +# generate the gnulib-derived BUILT_SOURCES (configmake.h, version.h etc) +# and then build just that one target instead of "make all". +BUILT_SOURCES=$(make -s -f built-sources.mk print-built-sources) +make $BUILT_SOURCES +make src/date + +%install +rm -rf ${RPM_BUILD_ROOT} + +mkdir -p ${RPM_BUILD_ROOT}%{prefix}/bin +install -m 755 src/date ${RPM_BUILD_ROOT}%{prefix}/bin/date + +%clean +rm -rf $RPM_BUILD_ROOT + +%description +CFEngine Build Automation -- coreutils (date) + +%files +%defattr(755,root,root) +%dir %prefix/bin +%prefix/bin/date + +%changelog diff --git a/deps-packaging/coreutils/debian/cfbuild-coreutils.install b/deps-packaging/coreutils/debian/cfbuild-coreutils.install new file mode 100644 index 000000000..f06c6cd9e --- /dev/null +++ b/deps-packaging/coreutils/debian/cfbuild-coreutils.install @@ -0,0 +1 @@ +/var/cfengine/bin/date diff --git a/deps-packaging/coreutils/debian/compat b/deps-packaging/coreutils/debian/compat new file mode 100644 index 000000000..f599e28b8 --- /dev/null +++ b/deps-packaging/coreutils/debian/compat @@ -0,0 +1 @@ +10 diff --git a/deps-packaging/coreutils/debian/control b/deps-packaging/coreutils/debian/control new file mode 100644 index 000000000..010c70e81 --- /dev/null +++ b/deps-packaging/coreutils/debian/control @@ -0,0 +1,12 @@ +Source: cfbuild-coreutils +Section: libs +Priority: optional +Maintainer: CFEngine Packager +Build-Depends: debhelper +Standards-Version: 3.8.4 + +Package: cfbuild-coreutils +Section: libs +Architecture: any +Description: CFEngine Build Automation -- coreutils (date) + CFEngine Build Automation -- coreutils (date) diff --git a/deps-packaging/coreutils/debian/copyright b/deps-packaging/coreutils/debian/copyright new file mode 100644 index 000000000..e69de29bb diff --git a/deps-packaging/coreutils/debian/rules b/deps-packaging/coreutils/debian/rules new file mode 100755 index 000000000..651916db7 --- /dev/null +++ b/deps-packaging/coreutils/debian/rules @@ -0,0 +1,46 @@ +#!/usr/bin/make -f + +clean: + dh_testdir + dh_testroot + + dh_clean + +build: build-stamp +build-stamp: + dh_testdir + + patch -p1 < 0001-Guard-pwd.h-and-grp.h-includes-in-idcache.c-and-use.patch + + FORCE_UNSAFE_CONFIGURE=1 ./configure --prefix=/var/cfengine + BUILT_SOURCES=$$(make -s -f built-sources.mk print-built-sources) && make $$BUILT_SOURCES + make src/date + + touch build-stamp + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + mkdir -p $(CURDIR)/debian/tmp/var/cfengine/bin + install -m 755 src/date $(CURDIR)/debian/tmp/var/cfengine/bin/date + +binary-indep: build install + +binary-arch: build install + dh_testdir + dh_testroot + dh_install --sourcedir=debian/tmp + dh_link + dh_strip + dh_compress + dh_fixperms + dh_installdeb + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/deps-packaging/coreutils/distfiles b/deps-packaging/coreutils/distfiles new file mode 100644 index 000000000..0abb9d9f5 --- /dev/null +++ b/deps-packaging/coreutils/distfiles @@ -0,0 +1 @@ +394024eda0a5955217ceda9cd1201e65dc8fa3aa29c2951135a49521d57c3cc3 coreutils-9.11.tar.xz diff --git a/deps-packaging/coreutils/mingw/debian/cfbuild-coreutils-mingw64.install b/deps-packaging/coreutils/mingw/debian/cfbuild-coreutils-mingw64.install new file mode 100644 index 000000000..291859c9b --- /dev/null +++ b/deps-packaging/coreutils/mingw/debian/cfbuild-coreutils-mingw64.install @@ -0,0 +1 @@ +/var/cfengine/bin/date.exe diff --git a/deps-packaging/coreutils/mingw/debian/compat b/deps-packaging/coreutils/mingw/debian/compat new file mode 100644 index 000000000..f599e28b8 --- /dev/null +++ b/deps-packaging/coreutils/mingw/debian/compat @@ -0,0 +1 @@ +10 diff --git a/deps-packaging/coreutils/mingw/debian/control b/deps-packaging/coreutils/mingw/debian/control new file mode 100644 index 000000000..f240ff0a2 --- /dev/null +++ b/deps-packaging/coreutils/mingw/debian/control @@ -0,0 +1,12 @@ +Source: cfbuild-coreutils +Section: libs +Priority: optional +Maintainer: CFEngine Packager +Build-Depends: debhelper +Standards-Version: 3.8.4 + +Package: cfbuild-coreutils-mingw64 +Section: libs +Architecture: all +Description: CFEngine Build Automation -- coreutils (date) -- mingw64 + CFEngine Build Automation -- coreutils (date) -- mingw64 diff --git a/deps-packaging/coreutils/mingw/debian/copyright b/deps-packaging/coreutils/mingw/debian/copyright new file mode 100644 index 000000000..e69de29bb diff --git a/deps-packaging/coreutils/mingw/debian/rules b/deps-packaging/coreutils/mingw/debian/rules new file mode 100755 index 000000000..56d12e204 --- /dev/null +++ b/deps-packaging/coreutils/mingw/debian/rules @@ -0,0 +1,52 @@ +#!/usr/bin/make -f + +PREFIX=$(BUILDPREFIX) + +clean: + dh_testdir + dh_testroot + + dh_clean + +build: build-stamp +build-stamp: + dh_testdir + + # Native Windows (mingw-w64) has no /. A few coreutils + # lib/*.c files unconditionally include them, even though date.exe never + # uses that functionality; patch them to only do so when the headers + # are actually available. + patch -p1 < 0001-Guard-pwd.h-and-grp.h-includes-in-idcache.c-and-use.patch + + FORCE_UNSAFE_CONFIGURE=1 ./configure --host=\$(DEB_HOST_GNU_TYPE) --prefix=\$(PREFIX) + BUILT_SOURCES=$$(make -s -f built-sources.mk print-built-sources) && make $$BUILT_SOURCES + make src/date.exe + + touch build-stamp + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + mkdir -p $(CURDIR)/debian/tmp$(PREFIX)/bin + install -m 755 src/date.exe $(CURDIR)/debian/tmp$(PREFIX)/bin/date.exe + +binary-indep: build install + +binary-arch: build install + dh_testdir + dh_testroot + dh_install --sourcedir=debian/tmp + dh_link + dh_strip + dh_compress + dh_fixperms + dh_installdeb + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/deps-packaging/coreutils/source b/deps-packaging/coreutils/source new file mode 100644 index 000000000..fa5d6010e --- /dev/null +++ b/deps-packaging/coreutils/source @@ -0,0 +1 @@ +https://ftp.gnu.org/gnu/coreutils/ diff --git a/deps-packaging/release-monitoring.json b/deps-packaging/release-monitoring.json index 1490ca6f2..9a2488d35 100644 --- a/deps-packaging/release-monitoring.json +++ b/deps-packaging/release-monitoring.json @@ -2,6 +2,7 @@ "apache": "387502", "apr": "95", "apr-util": "96", + "coreutils": "343", "diffutils": "436", "git": "20450", "libacl": "16", diff --git a/packaging/cfengine-community/cfengine-community.spec.in b/packaging/cfengine-community/cfengine-community.spec.in index 2d558c081..e60f83ba8 100644 --- a/packaging/cfengine-community/cfengine-community.spec.in +++ b/packaging/cfengine-community/cfengine-community.spec.in @@ -134,6 +134,7 @@ done %prefix/bin/sdiff %prefix/bin/cmp %prefix/bin/diff3 +%prefix/bin/date # diffutils %prefix/bin/diff diff --git a/packaging/cfengine-community/debian/cfengine-community.install b/packaging/cfengine-community/debian/cfengine-community.install index 44f734f08..3dbb9dc83 100644 --- a/packaging/cfengine-community/debian/cfengine-community.install +++ b/packaging/cfengine-community/debian/cfengine-community.install @@ -39,3 +39,4 @@ /var/cfengine/bin/sdiff /var/cfengine/bin/cmp /var/cfengine/bin/diff3 +/var/cfengine/bin/date diff --git a/packaging/cfengine-nova-hub/cfengine-nova-hub.spec.in b/packaging/cfengine-nova-hub/cfengine-nova-hub.spec.in index 6f4a76af3..350b039eb 100644 --- a/packaging/cfengine-nova-hub/cfengine-nova-hub.spec.in +++ b/packaging/cfengine-nova-hub/cfengine-nova-hub.spec.in @@ -298,6 +298,7 @@ exit 0 %prefix/bin/cmp %prefix/bin/sdiff %prefix/bin/diff3 +%prefix/bin/date # Auxiliary programs %prefix/bin/rpmvercmp # leech2 CLI diff --git a/packaging/cfengine-nova-hub/debian/cfengine-nova-hub.install b/packaging/cfengine-nova-hub/debian/cfengine-nova-hub.install index 99701ab5c..4b7b62389 100644 --- a/packaging/cfengine-nova-hub/debian/cfengine-nova-hub.install +++ b/packaging/cfengine-nova-hub/debian/cfengine-nova-hub.install @@ -71,6 +71,7 @@ /var/cfengine/bin/sdiff /var/cfengine/bin/cmp /var/cfengine/bin/diff3 +/var/cfengine/bin/date /var/cfengine/bin/clusterdb /var/cfengine/bin/createdb /var/cfengine/bin/createuser diff --git a/packaging/cfengine-nova/cfengine-nova.spec.in b/packaging/cfengine-nova/cfengine-nova.spec.in index 033e08533..d611e13c1 100644 --- a/packaging/cfengine-nova/cfengine-nova.spec.in +++ b/packaging/cfengine-nova/cfengine-nova.spec.in @@ -154,6 +154,7 @@ exit 0 %prefix/bin/sdiff %prefix/bin/cmp %prefix/bin/diff3 +%prefix/bin/date %if %{?rhel}%{!?rhel:0} > 7 # SELinux policy diff --git a/packaging/cfengine-nova/cfengine-nova.wxs b/packaging/cfengine-nova/cfengine-nova.wxs index cc80befbe..dbca730b8 100644 --- a/packaging/cfengine-nova/cfengine-nova.wxs +++ b/packaging/cfengine-nova/cfengine-nova.wxs @@ -127,6 +127,9 @@ + + + @@ -245,6 +248,7 @@ + diff --git a/packaging/cfengine-nova/debian/cfengine-nova.install b/packaging/cfengine-nova/debian/cfengine-nova.install index f0faec9b0..f1a1bb72d 100644 --- a/packaging/cfengine-nova/debian/cfengine-nova.install +++ b/packaging/cfengine-nova/debian/cfengine-nova.install @@ -42,3 +42,4 @@ /var/cfengine/bin/sdiff /var/cfengine/bin/cmp /var/cfengine/bin/diff3 +/var/cfengine/bin/date