Skip to content

Commit 7adbae2

Browse files
authored
Merge pull request #2450 from victormlg/parsedate
CFE-3882: Added date binary inside cfengine
2 parents c44ae8e + 20b30d7 commit 7adbae2

24 files changed

Lines changed: 320 additions & 0 deletions

‎build-scripts/compile-options‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ var_append DEPS "libyaml" # Library for parsing YAML
142142
var_append DEPS "diffutils" # Library for comparing files
143143
var_append DEPS "librsync" # Library for synchronization of file
144144

145+
# coreutils is only built for redhat/debian/windows for now
146+
case "$OS_FAMILY" in
147+
hpux | aix | solaris | freebsd) ;;
148+
*)
149+
var_append DEPS "coreutils" # Provides a standalone 'date' binary
150+
;;
151+
esac
152+
145153
# Enterprise only dependencies
146154
case "$PROJECT" in
147155
nova)
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
From 0c15fbcf18c0736149d06957e9058563fec065d3 Mon Sep 17 00:00:00 2001
2+
From: Victor Moene <victor.moene@northern.tech>
3+
Date: Tue, 25 Aug 2026 09:47:54 +0200
4+
Subject: [PATCH] Guard <pwd.h>/<grp.h> includes in idcache.c and userspec.c
5+
6+
We only build the "date" program out of coreutils, but the build compiles
7+
every gnulib lib/*.c file into a single lib/libcoreutils.a used by all
8+
coreutils programs, regardless of whether "date" actually needs them.
9+
10+
lib/idcache.c and lib/userspec.c unconditionally include <pwd.h> and
11+
<grp.h> to resolve uids/gids via the system's user and group databases.
12+
Native Windows (mingw-w64) ships neither header, so compiling
13+
lib/libcoreutils.a for date.exe failed there even though date.exe never
14+
references any symbol from these two files.
15+
16+
Guard the includes, and the function bodies that depend on them, with
17+
the HAVE_PWD_H/HAVE_GRP_H macros that configure already defines via
18+
AC_CHECK_HEADERS. This way the two files compile down to empty
19+
translation units on platforms lacking these headers. If some other
20+
coreutils program actually needs the passwd/group lookups these files
21+
provide, linking that program will now fail with an undefined
22+
reference, surfacing the problem at build time instead of silently
23+
linking in stub declarations that could never work.
24+
25+
Ticket: None
26+
Changelog: none
27+
---
28+
lib/idcache.c | 18 ++++++++++++++++--
29+
lib/userspec.c | 18 ++++++++++++++++--
30+
2 files changed, 32 insertions(+), 4 deletions(-)
31+
32+
diff --git a/lib/idcache.c b/lib/idcache.c
33+
index 5fd5f2c..327175e 100644
34+
--- a/lib/idcache.c
35+
+++ b/lib/idcache.c
36+
@@ -22,8 +22,12 @@
37+
#include <stddef.h>
38+
#include <stdio.h>
39+
#include <string.h>
40+
-#include <pwd.h>
41+
-#include <grp.h>
42+
+#if HAVE_PWD_H
43+
+# include <pwd.h>
44+
+#endif
45+
+#if HAVE_GRP_H
46+
+# include <grp.h>
47+
+#endif
48+
49+
#include <unistd.h>
50+
51+
@@ -63,6 +67,14 @@ static struct userid *group_alist;
52+
/* Each entry on list is a group name for which the first lookup failed. */
53+
static struct userid *nogroup_alist;
54+
55+
+/* The functions below all resolve uids/gids via the system's user and
56+
+ group databases, so they require <pwd.h> and <grp.h>. On platforms
57+
+ that lack these headers (e.g. native Windows), omit them entirely
58+
+ rather than fake up the lookups: if some program actually needs them,
59+
+ it will fail to link, which is preferable to silently linking in a
60+
+ passwd/group lookup that can never work. */
61+
+#if HAVE_PWD_H && HAVE_GRP_H
62+
+
63+
/* Translate UID to a login name, with cache, or NULL if unresolved. */
64+
65+
char *
66+
@@ -220,3 +232,5 @@ getgidbyname (const char *group)
67+
nogroup_alist = tail;
68+
return NULL;
69+
}
70+
+
71+
+#endif /* HAVE_PWD_H && HAVE_GRP_H */
72+
diff --git a/lib/userspec.c b/lib/userspec.c
73+
index 57cd023..943257a 100644
74+
--- a/lib/userspec.c
75+
+++ b/lib/userspec.c
76+
@@ -24,8 +24,12 @@
77+
78+
#include <stdio.h>
79+
#include <sys/types.h>
80+
-#include <pwd.h>
81+
-#include <grp.h>
82+
+#if HAVE_PWD_H
83+
+# include <pwd.h>
84+
+#endif
85+
+#if HAVE_GRP_H
86+
+# include <grp.h>
87+
+#endif
88+
89+
#if HAVE_SYS_PARAM_H
90+
# include <sys/param.h>
91+
@@ -97,6 +101,14 @@ is_number (const char *str)
92+
}
93+
#endif
94+
95+
+/* Resolving a user/group spec requires looking it up via the system's
96+
+ user and group databases, so the code below needs <pwd.h> and
97+
+ <grp.h>. On platforms that lack these headers (e.g. native Windows),
98+
+ omit it entirely rather than fake up the lookups: if some program
99+
+ actually needs it, it will fail to link, which is preferable to
100+
+ silently linking in a passwd/group lookup that can never work. */
101+
+#if HAVE_PWD_H && HAVE_GRP_H
102+
+
103+
static char const *
104+
parse_with_separator (char const *spec, char const *separator,
105+
uid_t *uid, gid_t *gid,
106+
@@ -289,6 +301,8 @@ parse_user_spec (char const *spec, uid_t *uid, gid_t *gid,
107+
return parse_user_spec_warn (spec, uid, gid, username, groupname, NULL);
108+
}
109+
110+
+#endif /* HAVE_PWD_H && HAVE_GRP_H */
111+
+
112+
#ifdef TEST
113+
114+
# define NULL_CHECK(s) ((s) == NULL ? "(null)" : (s))
115+
--
116+
2.43.0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include Makefile
2+
print-built-sources:
3+
@echo $(BUILT_SOURCES)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
%define coreutils_version 9.11
2+
3+
Summary: CFEngine Build Automation -- coreutils (date)
4+
Name: cfbuild-coreutils
5+
Version: %{version}
6+
Release: 1
7+
Source0: coreutils-%{coreutils_version}.tar.xz
8+
Patch0: 0001-Guard-pwd.h-and-grp.h-includes-in-idcache.c-and-use.patch
9+
License: GPL3
10+
Group: Other
11+
Url: https://cfengine.com
12+
BuildRoot: %{_topdir}/BUILD/%{name}-%{version}-%{release}-buildroot
13+
14+
AutoReqProv: no
15+
16+
%define prefix %{buildprefix}
17+
18+
%prep
19+
mkdir -p %{_builddir}
20+
%setup -q -n coreutils-%{coreutils_version}
21+
22+
%patch0 -p1
23+
24+
cp %{_sourcedir}/built-sources.mk .
25+
26+
FORCE_UNSAFE_CONFIGURE=1 ./configure --prefix=%{prefix}
27+
28+
%build
29+
30+
# We only need the "date" binary out of the whole coreutils suite, so
31+
# generate the gnulib-derived BUILT_SOURCES (configmake.h, version.h etc)
32+
# and then build just that one target instead of "make all".
33+
BUILT_SOURCES=$(make -s -f built-sources.mk print-built-sources)
34+
make $BUILT_SOURCES
35+
make src/date
36+
37+
%install
38+
rm -rf ${RPM_BUILD_ROOT}
39+
40+
mkdir -p ${RPM_BUILD_ROOT}%{prefix}/bin
41+
install -m 755 src/date ${RPM_BUILD_ROOT}%{prefix}/bin/date
42+
43+
%clean
44+
rm -rf $RPM_BUILD_ROOT
45+
46+
%description
47+
CFEngine Build Automation -- coreutils (date)
48+
49+
%files
50+
%defattr(755,root,root)
51+
%dir %prefix/bin
52+
%prefix/bin/date
53+
54+
%changelog
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/var/cfengine/bin/date
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Source: cfbuild-coreutils
2+
Section: libs
3+
Priority: optional
4+
Maintainer: CFEngine Packager <packager@cfengine.com>
5+
Build-Depends: debhelper
6+
Standards-Version: 3.8.4
7+
8+
Package: cfbuild-coreutils
9+
Section: libs
10+
Architecture: any
11+
Description: CFEngine Build Automation -- coreutils (date)
12+
CFEngine Build Automation -- coreutils (date)

‎deps-packaging/coreutils/debian/copyright‎

Whitespace-only changes.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/make -f
2+
3+
clean:
4+
dh_testdir
5+
dh_testroot
6+
7+
dh_clean
8+
9+
build: build-stamp
10+
build-stamp:
11+
dh_testdir
12+
13+
patch -p1 < 0001-Guard-pwd.h-and-grp.h-includes-in-idcache.c-and-use.patch
14+
15+
FORCE_UNSAFE_CONFIGURE=1 ./configure --prefix=/var/cfengine
16+
BUILT_SOURCES=$$(make -s -f built-sources.mk print-built-sources) && make $$BUILT_SOURCES
17+
make src/date
18+
19+
touch build-stamp
20+
21+
install: build
22+
dh_testdir
23+
dh_testroot
24+
dh_clean -k
25+
dh_installdirs
26+
27+
mkdir -p $(CURDIR)/debian/tmp/var/cfengine/bin
28+
install -m 755 src/date $(CURDIR)/debian/tmp/var/cfengine/bin/date
29+
30+
binary-indep: build install
31+
32+
binary-arch: build install
33+
dh_testdir
34+
dh_testroot
35+
dh_install --sourcedir=debian/tmp
36+
dh_link
37+
dh_strip
38+
dh_compress
39+
dh_fixperms
40+
dh_installdeb
41+
dh_gencontrol
42+
dh_md5sums
43+
dh_builddeb
44+
45+
binary: binary-indep binary-arch
46+
.PHONY: build clean binary-indep binary-arch binary install configure

‎deps-packaging/coreutils/distfiles‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
394024eda0a5955217ceda9cd1201e65dc8fa3aa29c2951135a49521d57c3cc3 coreutils-9.11.tar.xz

0 commit comments

Comments
 (0)