summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd/0014-Handle-missing-gshadow.patch
blob: a751e1ba6fd9584563144e14d16fd6d97255b571 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
From b7c827bb44edbb6251c9fcdb80aa03982c0e7bf3 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 14/22] 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>
[Rebased for v247]
Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
---
 src/shared/user-record-nss.c | 20 ++++++++++++++++++++
 src/shared/user-record-nss.h |  4 ++++
 src/shared/userdb.c          |  7 ++++++-
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/shared/user-record-nss.c b/src/shared/user-record-nss.c
index 414a49331b..1a4e1b628c 100644
--- a/src/shared/user-record-nss.c
+++ b/src/shared/user-record-nss.c
@@ -329,8 +329,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)
@@ -346,6 +348,7 @@ int nss_group_to_group_record(
 
         g->gid = grp->gr_gid;
 
+#if ENABLE_GSHADOW
         if (sgrp) {
                 if (looks_like_hashed_password(utf8_only(sgrp->sg_passwd))) {
                         g->hashed_password = strv_new(sgrp->sg_passwd);
@@ -361,6 +364,7 @@ int nss_group_to_group_record(
                 if (r < 0)
                         return r;
         }
+#endif
 
         r = json_build(&g->json, JSON_BUILD_OBJECT(
                                        JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(g->group_name)),
@@ -387,6 +391,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;
@@ -415,6 +420,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(
@@ -426,7 +434,9 @@ int nss_group_record_by_name(
         struct group grp, *result;
         bool incomplete = false;
         size_t buflen = 4096;
+#if ENABLE_GSHADOW
         struct sgrp sgrp, *sresult = NULL;
+#endif
         int r;
 
         assert(name);
@@ -455,6 +465,7 @@ int nss_group_record_by_name(
                 buf = mfree(buf);
         }
 
+#if ENABLE_GSHADOW
         if (with_shadow) {
                 r = nss_sgrp_for_group(result, &sgrp, &sbuf);
                 if (r < 0) {
@@ -466,6 +477,9 @@ int nss_group_record_by_name(
                 incomplete = true;
 
         r = nss_group_to_group_record(result, sresult, ret);
+#else
+        r = nss_group_to_group_record(result, NULL, ret);
+#endif
         if (r < 0)
                 return r;
 
@@ -483,7 +497,9 @@ int nss_group_record_by_gid(
         struct group grp, *result;
         bool incomplete = false;
         size_t buflen = 4096;
+#if ENABLE_GSHADOW
         struct sgrp sgrp, *sresult = NULL;
+#endif
         int r;
 
         for (;;) {
@@ -509,6 +525,7 @@ int nss_group_record_by_gid(
                 buf = mfree(buf);
         }
 
+#if ENABLE_GSHADOW
         if (with_shadow) {
                 r = nss_sgrp_for_group(result, &sgrp, &sbuf);
                 if (r < 0) {
@@ -520,6 +537,9 @@ int nss_group_record_by_gid(
                 incomplete = true;
 
         r = nss_group_to_group_record(result, sresult, ret);
+#else
+        r = nss_group_to_group_record(result, NULL, ret);
+#endif
         if (r < 0)
                 return r;
 
diff --git a/src/shared/user-record-nss.h b/src/shared/user-record-nss.h
index 22ab04d6ee..4e52e7a911 100644
--- a/src/shared/user-record-nss.h
+++ b/src/shared/user-record-nss.h
@@ -2,7 +2,11 @@
 #pragma once
 
 #include <grp.h>
+#if ENABLE_GSHADOW
 #include <gshadow.h>
+#else
+struct sgrp;
+#endif
 #include <pwd.h>
 #include <shadow.h>
 
diff --git a/src/shared/userdb.c b/src/shared/userdb.c
index f60d48ace4..e878199a28 100644
--- a/src/shared/userdb.c
+++ b/src/shared/userdb.c
@@ -1038,13 +1038,15 @@ 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
                         if (!FLAGS_SET(iterator->flags, USERDB_SUPPRESS_SHADOW)) {
                                 r = nss_sgrp_for_group(gr, &sgrp, &buffer);
                                 if (r < 0) {
@@ -1057,6 +1059,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.34.1