Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions build-scripts/compile-options
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
From 0c15fbcf18c0736149d06957e9058563fec065d3 Mon Sep 17 00:00:00 2001
From: Victor Moene <victor.moene@northern.tech>
Date: Tue, 25 Aug 2026 09:47:54 +0200
Subject: [PATCH] Guard <pwd.h>/<grp.h> 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 <pwd.h> and
<grp.h> 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.
Comment on lines +6 to +23

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This you could probably explain with a few sentences.


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 <stddef.h>
#include <stdio.h>
#include <string.h>
-#include <pwd.h>
-#include <grp.h>
+#if HAVE_PWD_H
+# include <pwd.h>
+#endif
+#if HAVE_GRP_H
+# include <grp.h>
+#endif

#include <unistd.h>

@@ -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 <pwd.h> and <grp.h>. 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 <stdio.h>
#include <sys/types.h>
-#include <pwd.h>
-#include <grp.h>
+#if HAVE_PWD_H
+# include <pwd.h>
+#endif
+#if HAVE_GRP_H
+# include <grp.h>
+#endif

#if HAVE_SYS_PARAM_H
# include <sys/param.h>
@@ -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 <pwd.h> and
+ <grp.h>. 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. */
Comment on lines +95 to +100

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

People reading this in the future will have no context of the fake look-ups that used to be there.

+#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
3 changes: 3 additions & 0 deletions deps-packaging/coreutils/built-sources.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include Makefile
print-built-sources:
@echo $(BUILT_SOURCES)
54 changes: 54 additions & 0 deletions deps-packaging/coreutils/cfbuild-coreutils.spec
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions deps-packaging/coreutils/debian/cfbuild-coreutils.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/var/cfengine/bin/date
1 change: 1 addition & 0 deletions deps-packaging/coreutils/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
12 changes: 12 additions & 0 deletions deps-packaging/coreutils/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Source: cfbuild-coreutils
Section: libs
Priority: optional
Maintainer: CFEngine Packager <packager@cfengine.com>
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)
Empty file.
46 changes: 46 additions & 0 deletions deps-packaging/coreutils/debian/rules
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions deps-packaging/coreutils/distfiles
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
394024eda0a5955217ceda9cd1201e65dc8fa3aa29c2951135a49521d57c3cc3 coreutils-9.11.tar.xz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/var/cfengine/bin/date.exe
1 change: 1 addition & 0 deletions deps-packaging/coreutils/mingw/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
12 changes: 12 additions & 0 deletions deps-packaging/coreutils/mingw/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Source: cfbuild-coreutils
Section: libs
Priority: optional
Maintainer: CFEngine Packager <packager@cfengine.com>
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
Empty file.
52 changes: 52 additions & 0 deletions deps-packaging/coreutils/mingw/debian/rules
Original file line number Diff line number Diff line change
@@ -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 <pwd.h>/<grp.h>. 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
1 change: 1 addition & 0 deletions deps-packaging/coreutils/source
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://ftp.gnu.org/gnu/coreutils/
1 change: 1 addition & 0 deletions deps-packaging/release-monitoring.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"apache": "387502",
"apr": "95",
"apr-util": "96",
"coreutils": "343",
"diffutils": "436",
"git": "20450",
"libacl": "16",
Expand Down
1 change: 1 addition & 0 deletions packaging/cfengine-community/cfengine-community.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ done
%prefix/bin/sdiff
%prefix/bin/cmp
%prefix/bin/diff3
%prefix/bin/date

# diffutils
%prefix/bin/diff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@
/var/cfengine/bin/sdiff
/var/cfengine/bin/cmp
/var/cfengine/bin/diff3
/var/cfengine/bin/date
1 change: 1 addition & 0 deletions packaging/cfengine-nova-hub/cfengine-nova-hub.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packaging/cfengine-nova/cfengine-nova.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packaging/cfengine-nova/cfengine-nova.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
<Component Id='diff3.exe' Guid='73fe2642-63b1-4e98-bd4f-60594049be49' Win64='$(var.isWin64)'>
<File Id='diff3.exe' Name='diff3.exe' KeyPath='yes' DiskId='1' Source='$(var.CfSourceDir)/bin/diff3.exe' />
</Component>
<Component Id='date.exe' Guid='AC22A37B-81D0-451B-BC5F-5CAFA8E607E8' Win64='$(var.isWin64)'>
<File Id='date.exe' Name='date.exe' KeyPath='yes' DiskId='1' Source='$(var.CfSourceDir)/bin/date.exe' />
</Component>
<Component Id='mdb_copy.exe' Guid='E41C3638-9BBE-497D-A5A8-DB2021030113' Win64='$(var.isWin64)'>
<File Id='mdb_copy.exe' Name='mdb_copy.exe' KeyPath='yes' DiskId='1' Source='$(var.CfSourceDir)/bin/mdb_copy.exe' />
</Component>
Expand Down Expand Up @@ -245,6 +248,7 @@
<ComponentRef Id='diff3.exe' />
<ComponentRef Id='cmp.exe' />
<ComponentRef Id='sdiff.exe' />
<ComponentRef Id='date.exe' />

<ComponentRef Id='cf.events.dll' />
<ComponentRef Id='liblber.dll' />
Expand Down
1 change: 1 addition & 0 deletions packaging/cfengine-nova/debian/cfengine-nova.install
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@
/var/cfengine/bin/sdiff
/var/cfengine/bin/cmp
/var/cfengine/bin/diff3
/var/cfengine/bin/date
Loading