-
Notifications
You must be signed in to change notification settings - Fork 40
CFE-3882: Added date binary inside cfengine #2450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
deps-packaging/coreutils/0001-Guard-pwd.h-and-grp.h-includes-in-idcache.c-and-use.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
|
|
||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| include Makefile | ||
| print-built-sources: | ||
| @echo $(BUILT_SOURCES) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /var/cfengine/bin/date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 394024eda0a5955217ceda9cd1201e65dc8fa3aa29c2951135a49521d57c3cc3 coreutils-9.11.tar.xz |
1 change: 1 addition & 0 deletions
1
deps-packaging/coreutils/mingw/debian/cfbuild-coreutils-mingw64.install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /var/cfengine/bin/date.exe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| https://ftp.gnu.org/gnu/coreutils/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,3 +39,4 @@ | |
| /var/cfengine/bin/sdiff | ||
| /var/cfengine/bin/cmp | ||
| /var/cfengine/bin/diff3 | ||
| /var/cfengine/bin/date | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,3 +42,4 @@ | |
| /var/cfengine/bin/sdiff | ||
| /var/cfengine/bin/cmp | ||
| /var/cfengine/bin/diff3 | ||
| /var/cfengine/bin/date | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.