gentoo-overlay/sys-apps/systemd/files/0001-Handle-missing-gshadow...

172 lines
5.6 KiB
Diff

From ef9580ea1e2f1e57af3c7dcb0ec392ba8dbb5c8d Mon Sep 17 00:00:00 2001
From: Alex Kiernan <alex.kiernan@gmail.com>
Date: Tue, 10 Mar 2020 11:05:20 +0000
Subject: [PATCH] Handle missing gshadow
gshadow usage is now present in the userdb code. Mask all uses of it to
allow compilation on musl
Upstream-Status: Inappropriate [musl specific]
Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---
src/shared/group-record-nss.c | 20 ++++++++++++++++++++
src/shared/group-record-nss.h | 4 ++++
src/shared/userdb.c | 6 ++++++
3 files changed, 30 insertions(+)
diff --git a/src/shared/group-record-nss.c b/src/shared/group-record-nss.c
index 77924f1c4067..c64490253ff3 100644
--- a/src/shared/group-record-nss.c
+++ b/src/shared/group-record-nss.c
@@ -19,8 +19,10 @@ int nss_group_to_group_record(
if (isempty(grp->gr_name))
return -EINVAL;
+#if ENABLE_GSHADOW
if (sgrp && !streq_ptr(sgrp->sg_namp, grp->gr_name))
return -EINVAL;
+#endif
g = group_record_new();
if (!g)
@@ -36,6 +38,7 @@ int nss_group_to_group_record(
g->gid = grp->gr_gid;
+#if ENABLE_GSHADOW
if (sgrp) {
if (hashed_password_valid(sgrp->sg_passwd)) {
g->hashed_password = strv_new(sgrp->sg_passwd);
@@ -51,6 +54,7 @@ int nss_group_to_group_record(
if (!g->administrators)
return -ENOMEM;
}
+#endif
r = json_build(&g->json, JSON_BUILD_OBJECT(
JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(g->group_name)),
@@ -76,6 +80,7 @@ int nss_sgrp_for_group(const struct group *grp, struct sgrp *ret_sgrp, char **re
assert(ret_sgrp);
assert(ret_buffer);
+#if ENABLE_GSHADOW
for (;;) {
_cleanup_free_ char *buf = NULL;
struct sgrp sgrp, *result;
@@ -104,6 +109,9 @@ int nss_sgrp_for_group(const struct group *grp, struct sgrp *ret_sgrp, char **re
buflen *= 2;
buf = mfree(buf);
}
+#else
+ return -ESRCH;
+#endif
}
int nss_group_record_by_name(const char *name, GroupRecord **ret) {
@@ -111,7 +119,9 @@ int nss_group_record_by_name(const char *name, GroupRecord **ret) {
struct group grp, *result;
bool incomplete = false;
size_t buflen = 4096;
+#if ENABLE_GSHADOW
struct sgrp sgrp;
+#endif
int r;
assert(name);
@@ -141,6 +151,7 @@ int nss_group_record_by_name(const char *name, GroupRecord **ret) {
buf = mfree(buf);
}
+#if ENABLE_GSHADOW
r = nss_sgrp_for_group(result, &sgrp, &sbuf);
if (r < 0) {
log_debug_errno(r, "Failed to do shadow lookup for group %s, ignoring: %m", result->gr_name);
@@ -148,6 +159,9 @@ int nss_group_record_by_name(const char *name, GroupRecord **ret) {
}
r = nss_group_to_group_record(result, r >= 0 ? &sgrp : NULL, ret);
+#else
+ r = nss_group_to_group_record(result, NULL, ret);
+#endif
if (r < 0)
return r;
@@ -160,7 +174,9 @@ int nss_group_record_by_gid(gid_t gid, GroupRecord **ret) {
struct group grp, *result;
bool incomplete = false;
size_t buflen = 4096;
+#if ENABLE_GSHADOW
struct sgrp sgrp;
+#endif
int r;
assert(ret);
@@ -188,6 +204,7 @@ int nss_group_record_by_gid(gid_t gid, GroupRecord **ret) {
buf = mfree(buf);
}
+#if ENABLE_GSHADOW
r = nss_sgrp_for_group(result, &sgrp, &sbuf);
if (r < 0) {
log_debug_errno(r, "Failed to do shadow lookup for group %s, ignoring: %m", result->gr_name);
@@ -195,6 +212,9 @@ int nss_group_record_by_gid(gid_t gid, GroupRecord **ret) {
}
r = nss_group_to_group_record(result, r >= 0 ? &sgrp : NULL, ret);
+#else
+ r = nss_group_to_group_record(result, NULL, ret);
+#endif
if (r < 0)
return r;
diff --git a/src/shared/group-record-nss.h b/src/shared/group-record-nss.h
index 38b2995178ff..d7d95c44cf11 100644
--- a/src/shared/group-record-nss.h
+++ b/src/shared/group-record-nss.h
@@ -2,7 +2,11 @@
#pragma once
#include <grp.h>
+#if ENABLE_GSHADOW
#include <gshadow.h>
+#else
+struct sgrp;
+#endif
#include "group-record.h"
diff --git a/src/shared/userdb.c b/src/shared/userdb.c
index 92f8796768d7..5d912862f85c 100644
--- a/src/shared/userdb.c
+++ b/src/shared/userdb.c
@@ -924,13 +924,16 @@ int groupdb_iterator_get(UserDBIterator *iterator, GroupRecord **ret) {
if (gr) {
_cleanup_free_ char *buffer = NULL;
bool incomplete = false;
+#if ENABLE_GSHADOW
struct sgrp sgrp;
+#endif
if (streq_ptr(gr->gr_name, "root"))
iterator->synthesize_root = false;
if (gr->gr_gid == GID_NOBODY)
iterator->synthesize_nobody = false;
+#if ENABLE_GSHADOW
r = nss_sgrp_for_group(gr, &sgrp, &buffer);
if (r < 0) {
log_debug_errno(r, "Failed to acquire shadow entry for group %s, ignoring: %m", gr->gr_name);
@@ -938,6 +941,9 @@ int groupdb_iterator_get(UserDBIterator *iterator, GroupRecord **ret) {
}
r = nss_group_to_group_record(gr, r >= 0 ? &sgrp : NULL, ret);
+#else
+ r = nss_group_to_group_record(gr, NULL, ret);
+#endif
if (r < 0)
return r;
--
2.17.1