aboutsummaryrefslogtreecommitdiffstats
path: root/meta-gnome/recipes-support/accountsservice/accountsservice/0002-musl-add-missing-fgetspent_r.patch
blob: 2b0924b2e448065bcc446e9833545fddf8996a9f (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
From 7401e682400df87f3258f795bb1d143f64a35a9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
Date: Mon, 9 Dec 2019 00:12:08 +0100
Subject: [PATCH] musl: add missing fgetspent_r

Stolen from void-linux

Upstream-Status: Inappropriate [musl-specific]

---
 src/daemon.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/daemon.c b/src/daemon.c
index c52bda3..a7676fe 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -164,6 +164,26 @@ remove_cache_files (const gchar *user_name)
         g_remove (icon_filename);
 }
 
+/* Musl libc does not support fgetspent_r(), write own
+ * wrapper
+ */
+static int fgetspent_r(FILE *fp, struct spwd *spbuf, char *buf, size_t buflen, struct spwd **spbufp) {
+       struct spwd *shadow_entry = fgetspent(fp);
+       if(!shadow_entry)
+               return -1;
+       size_t namplen = strlen(shadow_entry->sp_namp);
+       size_t pwdplen = strlen(shadow_entry->sp_pwdp);
+
+       if(namplen + pwdplen + 2 > buflen)
+               return -1;
+
+       *spbufp = memcpy(spbuf, shadow_entry, sizeof(struct spwd));
+       spbuf->sp_namp = strncpy(buf, shadow_entry->sp_namp, namplen + 1);
+       spbuf->sp_pwdp = strncpy(buf + namplen + 1, shadow_entry->sp_pwdp, pwdplen + 1);
+
+       return 0;
+}
+
 static struct passwd *
 entry_generator_fgetpwent (Daemon       *daemon,
                            GHashTable   *users,