1From ec519727bb1ceda6e7787ccf86237a6aad07137c 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] 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--- 15 src/shared/user-record-nss.c | 20 ++++++++++++++++++++ 16 src/shared/user-record-nss.h | 4 ++++ 17 src/shared/userdb.c | 7 ++++++- 18 3 files changed, 30 insertions(+), 1 deletion(-) 19 20diff --git a/src/shared/user-record-nss.c b/src/shared/user-record-nss.c 21index 88b8fc2f8f..a819d41bac 100644 22--- a/src/shared/user-record-nss.c 23+++ b/src/shared/user-record-nss.c 24@@ -331,8 +331,10 @@ int nss_group_to_group_record( 25 if (isempty(grp->gr_name)) 26 return -EINVAL; 27 28+#if ENABLE_GSHADOW 29 if (sgrp && !streq_ptr(sgrp->sg_namp, grp->gr_name)) 30 return -EINVAL; 31+#endif 32 33 g = group_record_new(); 34 if (!g) 35@@ -348,6 +350,7 @@ int nss_group_to_group_record( 36 37 g->gid = grp->gr_gid; 38 39+#if ENABLE_GSHADOW 40 if (sgrp) { 41 if (looks_like_hashed_password(utf8_only(sgrp->sg_passwd))) { 42 g->hashed_password = strv_new(sgrp->sg_passwd); 43@@ -363,6 +366,7 @@ int nss_group_to_group_record( 44 if (r < 0) 45 return r; 46 } 47+#endif 48 49 r = json_build(&g->json, JSON_BUILD_OBJECT( 50 JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(g->group_name)), 51@@ -388,6 +392,7 @@ int nss_sgrp_for_group(const struct group *grp, struct sgrp *ret_sgrp, char **re 52 assert(ret_sgrp); 53 assert(ret_buffer); 54 55+#if ENABLE_GSHADOW 56 for (;;) { 57 _cleanup_free_ char *buf = NULL; 58 struct sgrp sgrp, *result; 59@@ -416,6 +421,9 @@ int nss_sgrp_for_group(const struct group *grp, struct sgrp *ret_sgrp, char **re 60 buflen *= 2; 61 buf = mfree(buf); 62 } 63+#else 64+ return -ESRCH; 65+#endif 66 } 67 68 int nss_group_record_by_name( 69@@ -427,7 +435,9 @@ int nss_group_record_by_name( 70 struct group grp, *result; 71 bool incomplete = false; 72 size_t buflen = 4096; 73+#if ENABLE_GSHADOW 74 struct sgrp sgrp, *sresult = NULL; 75+#endif 76 int r; 77 78 assert(name); 79@@ -457,6 +467,7 @@ int nss_group_record_by_name( 80 buf = mfree(buf); 81 } 82 83+#if ENABLE_GSHADOW 84 if (with_shadow) { 85 r = nss_sgrp_for_group(result, &sgrp, &sbuf); 86 if (r < 0) { 87@@ -468,6 +479,9 @@ int nss_group_record_by_name( 88 incomplete = true; 89 90 r = nss_group_to_group_record(result, sresult, ret); 91+#else 92+ r = nss_group_to_group_record(result, NULL, ret); 93+#endif 94 if (r < 0) 95 return r; 96 97@@ -484,7 +498,9 @@ int nss_group_record_by_gid( 98 struct group grp, *result; 99 bool incomplete = false; 100 size_t buflen = 4096; 101+#if ENABLE_GSHADOW 102 struct sgrp sgrp, *sresult = NULL; 103+#endif 104 int r; 105 106 assert(ret); 107@@ -512,6 +528,7 @@ int nss_group_record_by_gid( 108 buf = mfree(buf); 109 } 110 111+#if ENABLE_GSHADOW 112 if (with_shadow) { 113 r = nss_sgrp_for_group(result, &sgrp, &sbuf); 114 if (r < 0) { 115@@ -523,6 +540,9 @@ int nss_group_record_by_gid( 116 incomplete = true; 117 118 r = nss_group_to_group_record(result, sresult, ret); 119+#else 120+ r = nss_group_to_group_record(result, NULL, ret); 121+#endif 122 if (r < 0) 123 return r; 124 125diff --git a/src/shared/user-record-nss.h b/src/shared/user-record-nss.h 126index 22ab04d6ee..4e52e7a911 100644 127--- a/src/shared/user-record-nss.h 128+++ b/src/shared/user-record-nss.h 129@@ -2,7 +2,11 @@ 130 #pragma once 131 132 #include <grp.h> 133+#if ENABLE_GSHADOW 134 #include <gshadow.h> 135+#else 136+struct sgrp; 137+#endif 138 #include <pwd.h> 139 #include <shadow.h> 140 141diff --git a/src/shared/userdb.c b/src/shared/userdb.c 142index 0eddd382e6..d506b8e263 100644 143--- a/src/shared/userdb.c 144+++ b/src/shared/userdb.c 145@@ -1046,13 +1046,15 @@ int groupdb_iterator_get(UserDBIterator *iterator, GroupRecord **ret) { 146 if (gr) { 147 _cleanup_free_ char *buffer = NULL; 148 bool incomplete = false; 149+#if ENABLE_GSHADOW 150 struct sgrp sgrp; 151- 152+#endif 153 if (streq_ptr(gr->gr_name, "root")) 154 iterator->synthesize_root = false; 155 if (gr->gr_gid == GID_NOBODY) 156 iterator->synthesize_nobody = false; 157 158+#if ENABLE_GSHADOW 159 if (!FLAGS_SET(iterator->flags, USERDB_SUPPRESS_SHADOW)) { 160 r = nss_sgrp_for_group(gr, &sgrp, &buffer); 161 if (r < 0) { 162@@ -1065,6 +1067,9 @@ int groupdb_iterator_get(UserDBIterator *iterator, GroupRecord **ret) { 163 } 164 165 r = nss_group_to_group_record(gr, r >= 0 ? &sgrp : NULL, ret); 166+#else 167+ r = nss_group_to_group_record(gr, NULL, ret); 168+#endif 169 if (r < 0) 170 return r; 171 172