accountsservice: write new musl patch that does more than just compile

This commit is contained in:
Enno Boland 2018-03-26 13:14:51 +02:00
parent 1e066864f2
commit 106b948b01
No known key found for this signature in database
GPG Key ID: D09964719BDE9971

View File

@ -1,34 +1,32 @@
Musl libc does not support fgetspent_r(), so fall back
to using the non-thread-safe fgetspent() function.
--- src/daemon.c 2016-09-06 21:48:50.000000000 +0200
+++ src/daemon.c 2016-11-25 10:41:01.614534302 +0100
@@ -174,7 +174,7 @@
int ret = 0;
diff --git a/src/daemon.c b/src/daemon.c
index 312394a..e7b3c58 100644
--- src/daemon.c
+++ src/daemon.c
@@ -140,6 +140,26 @@ error_get_type (void)
#define MAX_LOCAL_USERS 50
#endif
shadow_entry_buffers = g_malloc0 (sizeof (*shadow_entry_buffers));
-
+#if defined(__GLIBC__)
ret = fgetspent_r (fp, &shadow_entry_buffers->spbuf, shadow_entry_buffers->buf, sizeof (shadow_entry_buffers->buf), &shadow_entry);
if (ret == 0) {
g_hash_table_insert (shadow_users, g_strdup (shadow_entry->sp_namp), shadow_entry_buffers);
@@ -185,6 +185,19 @@
break;
}
}
+#else
+ /* Musl libc does not support fgetspent_r(), so fall back
+ * to using the non-thread-safe fgetspent() function.
+ */
+ shadow_entry = fgetspent(fp);
+ if (shadow_entry == NULL) {
+ g_free (shadow_entry_buffers);
+#ifndef __GLIBC__
+ /* 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);
+ size_t namplen = strlen(shadow_entry->sp_namp);
+ size_t pwdplen = strlen(shadow_entry->sp_pwdp);
+
+ if (errno != EINTR) {
+ break;
+ }
+ }
+ 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;
+}
+#endif
} while (shadow_entry != NULL);
fclose (fp);
+
static struct passwd *
entry_generator_fgetpwent (Daemon *daemon,
GHashTable *users,