1From b7c827bb44edbb6251c9fcdb80aa03982c0e7bf3 Mon Sep 17 00:00:00 2001 2From: Alex Kiernan <alex.kiernan@gmail.com> 3Date: Tue, 10 Mar 2020 11:05:20 +0000 4Subject: [PATCH 14/22] Handle missing gshadow 5 6gshadow usage is now present in the userdb code. Mask all uses of it to 7allow compilation on musl 8 9Upstream-Status: Inappropriate [musl specific] 10Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com> 11[Rebased for v247] 12Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com> 13--- 14 src/shared/user-record-nss.c | 20 ++++++++++++++++++++ 15 src/shared/user-record-nss.h | 4 ++++ 16 src/shared/userdb.c | 7 ++++++- 17 3 files changed, 30 insertions(+), 1 deletion(-) 18 19diff --git a/src/shared/user-record-nss.c b/src/shared/user-record-nss.c 20index 414a49331b..1a4e1b628c 100644 21--- a/src/shared/user-record-nss.c 22+++ b/src/shared/user-record-nss.c 23@@ -329,8 +329,10 @@ int nss_group_to_group_record( 24 if (isempty(grp->gr_name)) 25 return -EINVAL; 26 27+#if ENABLE_GSHADOW 28 if (sgrp && !streq_ptr(sgrp->sg_namp, grp->gr_name)) 29 return -EINVAL; 30+#endif 31 32 g = group_record_new(); 33 if (!g) 34@@ -346,6 +348,7 @@ int nss_group_to_group_record( 35 36 g->gid = grp->gr_gid; 37 38+#if ENABLE_GSHADOW 39 if (sgrp) { 40 if (looks_like_hashed_password(utf8_only(sgrp->sg_passwd))) { 41 g->hashed_password = strv_new(sgrp->sg_passwd); 42@@ -361,6 +364,7 @@ int nss_group_to_group_record( 43 if (r < 0) 44 return r; 45 } 46+#endif 47 48 r = json_build(&g->json, JSON_BUILD_OBJECT( 49 JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(g->group_name)), 50@@ -387,6 +391,7 @@ int nss_sgrp_for_group(const struct group *grp, struct sgrp *ret_sgrp, char **re 51 assert(ret_sgrp); 52 assert(ret_buffer); 53 54+#if ENABLE_GSHADOW 55 for (;;) { 56 _cleanup_free_ char *buf = NULL; 57 struct sgrp sgrp, *result; 58@@ -415,6 +420,9 @@ int nss_sgrp_for_group(const struct group *grp, struct sgrp *ret_sgrp, char **re 59 buflen *= 2; 60 buf = mfree(buf); 61 } 62+#else 63+ return -ESRCH; 64+#endif 65 } 66 67 int nss_group_record_by_name( 68@@ -426,7 +434,9 @@ int nss_group_record_by_name( 69 struct group grp, *result; 70 bool incomplete = false; 71 size_t buflen = 4096; 72+#if ENABLE_GSHADOW 73 struct sgrp sgrp, *sresult = NULL; 74+#endif 75 int r; 76 77 assert(name); 78@@ -455,6 +465,7 @@ int nss_group_record_by_name( 79 buf = mfree(buf); 80 } 81 82+#if ENABLE_GSHADOW 83 if (with_shadow) { 84 r = nss_sgrp_for_group(result, &sgrp, &sbuf); 85 if (r < 0) { 86@@ -466,6 +477,9 @@ int nss_group_record_by_name( 87 incomplete = true; 88 89 r = nss_group_to_group_record(result, sresult, ret); 90+#else 91+ r = nss_group_to_group_record(result, NULL, ret); 92+#endif 93 if (r < 0) 94 return r; 95 96@@ -483,7 +497,9 @@ int nss_group_record_by_gid( 97 struct group grp, *result; 98 bool incomplete = false; 99 size_t buflen = 4096; 100+#if ENABLE_GSHADOW 101 struct sgrp sgrp, *sresult = NULL; 102+#endif 103 int r; 104 105 for (;;) { 106@@ -509,6 +525,7 @@ int nss_group_record_by_gid( 107 buf = mfree(buf); 108 } 109 110+#if ENABLE_GSHADOW 111 if (with_shadow) { 112 r = nss_sgrp_for_group(result, &sgrp, &sbuf); 113 if (r < 0) { 114@@ -520,6 +537,9 @@ int nss_group_record_by_gid( 115 incomplete = true; 116 117 r = nss_group_to_group_record(result, sresult, ret); 118+#else 119+ r = nss_group_to_group_record(result, NULL, ret); 120+#endif 121 if (r < 0) 122 return r; 123 124diff --git a/src/shared/user-record-nss.h b/src/shared/user-record-nss.h 125index 22ab04d6ee..4e52e7a911 100644 126--- a/src/shared/user-record-nss.h 127+++ b/src/shared/user-record-nss.h 128@@ -2,7 +2,11 @@ 129 #pragma once 130 131 #include <grp.h> 132+#if ENABLE_GSHADOW 133 #include <gshadow.h> 134+#else 135+struct sgrp; 136+#endif 137 #include <pwd.h> 138 #include <shadow.h> 139 140diff --git a/src/shared/userdb.c b/src/shared/userdb.c 141index f60d48ace4..e878199a28 100644 142--- a/src/shared/userdb.c 143+++ b/src/shared/userdb.c 144@@ -1038,13 +1038,15 @@ int groupdb_iterator_get(UserDBIterator *iterator, GroupRecord **ret) { 145 if (gr) { 146 _cleanup_free_ char *buffer = NULL; 147 bool incomplete = false; 148+#if ENABLE_GSHADOW 149 struct sgrp sgrp; 150- 151+#endif 152 if (streq_ptr(gr->gr_name, "root")) 153 iterator->synthesize_root = false; 154 if (gr->gr_gid == GID_NOBODY) 155 iterator->synthesize_nobody = false; 156 157+#if ENABLE_GSHADOW 158 if (!FLAGS_SET(iterator->flags, USERDB_SUPPRESS_SHADOW)) { 159 r = nss_sgrp_for_group(gr, &sgrp, &buffer); 160 if (r < 0) { 161@@ -1057,6 +1059,9 @@ int groupdb_iterator_get(UserDBIterator *iterator, GroupRecord **ret) { 162 } 163 164 r = nss_group_to_group_record(gr, r >= 0 ? &sgrp : NULL, ret); 165+#else 166+ r = nss_group_to_group_record(gr, NULL, ret); 167+#endif 168 if (r < 0) 169 return r; 170 171-- 1722.34.1 173 174