1From 7401e682400df87f3258f795bb1d143f64a35a9f Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
3Date: Mon, 9 Dec 2019 00:12:08 +0100
4Subject: [PATCH] musl: add missing fgetspent_r
5
6Stolen from void-linux
7
8Upstream-Status: Inappropriate [musl-specific]
9
10---
11 src/daemon.c | 20 ++++++++++++++++++++
12 1 file changed, 20 insertions(+)
13
14diff --git a/src/daemon.c b/src/daemon.c
15index c52bda3..a7676fe 100644
16--- a/src/daemon.c
17+++ b/src/daemon.c
18@@ -164,6 +164,26 @@ remove_cache_files (const gchar *user_name)
19         g_remove (icon_filename);
20 }
21
22+/* Musl libc does not support fgetspent_r(), write own
23+ * wrapper
24+ */
25+static int fgetspent_r(FILE *fp, struct spwd *spbuf, char *buf, size_t buflen, struct spwd **spbufp) {
26+       struct spwd *shadow_entry = fgetspent(fp);
27+       if(!shadow_entry)
28+               return -1;
29+       size_t namplen = strlen(shadow_entry->sp_namp);
30+       size_t pwdplen = strlen(shadow_entry->sp_pwdp);
31+
32+       if(namplen + pwdplen + 2 > buflen)
33+               return -1;
34+
35+       *spbufp = memcpy(spbuf, shadow_entry, sizeof(struct spwd));
36+       spbuf->sp_namp = strncpy(buf, shadow_entry->sp_namp, namplen + 1);
37+       spbuf->sp_pwdp = strncpy(buf + namplen + 1, shadow_entry->sp_pwdp, pwdplen + 1);
38+
39+       return 0;
40+}
41+
42 static struct passwd *
43 entry_generator_fgetpwent (Daemon       *daemon,
44                            GHashTable   *users,
45