summaryrefslogtreecommitdiffhomepage
path: root/patches/libbsd-0.8.7.local.patch
blob: 56f024ea2fbd6ad46063a65d8450df76c1d67956 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
diff -Nru libbsd-0.8.7.orig/include/bsd/stdlib.h libbsd-0.8.7/include/bsd/stdlib.h
--- libbsd-0.8.7.orig/include/bsd/stdlib.h	2017-08-05 13:20:00.000000000 +0200
+++ libbsd-0.8.7/include/bsd/stdlib.h	2018-04-27 21:18:23.074047191 +0200
@@ -67,7 +67,7 @@
                const unsigned char *table, unsigned endbyte);
 
 void *reallocf(void *ptr, size_t size);
-#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 26)
+#if defined(_GNU_SOURCE)
 void *reallocarray(void *ptr, size_t nmemb, size_t size);
 #endif
 
diff -Nru libbsd-0.8.7.orig/include/bsd/string.h libbsd-0.8.7/include/bsd/string.h
--- libbsd-0.8.7.orig/include/bsd/string.h	2017-08-05 13:20:54.000000000 +0200
+++ libbsd-0.8.7/include/bsd/string.h	2018-04-27 21:18:02.670455792 +0200
@@ -42,7 +42,7 @@
 char *strnstr(const char *str, const char *find, size_t str_len);
 void strmode(mode_t mode, char *str);
 
-#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 25)
+#if defined(_GNU_SOURCE)
 void explicit_bzero(void *buf, size_t len);
 #endif
 __END_DECLS
diff -Nru libbsd-0.8.7.orig/src/getentropy.c libbsd-0.8.7/src/getentropy.c
--- libbsd-0.8.7.orig/src/getentropy.c	2017-06-06 04:21:24.000000000 +0200
+++ libbsd-0.8.7/src/getentropy.c	2018-04-27 21:09:29.121945744 +0200
@@ -40,6 +40,8 @@
 #include "getentropy_aix.c"
 #elif defined(__hpux)
 #include "getentropy_hpux.c"
+#elif defined(__midipix__) /* temporary - no native getentropy() yet */
+#include "getentropy_midipix.c"
 #else
 #error "No getentropy hooks defined for this platform."
 #endif
diff -Nru libbsd-0.8.7.orig/src/getentropy_midipix.c libbsd-0.8.7/src/getentropy_midipix.c
--- libbsd-0.8.7.orig/src/getentropy_midipix.c	1970-01-01 01:00:00.000000000 +0100
+++ libbsd-0.8.7/src/getentropy_midipix.c	2018-04-27 21:11:22.917696342 +0200
@@ -0,0 +1,118 @@
+/* Temporary copy-paste from getentropy_linux.c until we get a native getentropy() implementation */
+
+
+#define _POSIX_C_SOURCE 199309L
+#define _GNU_SOURCE     1
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/resource.h>
+#include <sys/syscall.h>
+#include <sys/statvfs.h>
+#include <sys/socket.h>
+#include <sys/mount.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <link.h>
+#include <termios.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <time.h>
+
+int     getentropy(void *buf, size_t len);
+
+static int gotdata(char *buf, size_t len);
+static int getentropy_urandom(void *buf, size_t len);
+
+int
+getentropy(void *buf, size_t len)
+{
+        int ret = -1;
+
+        if (len > 256) {
+                errno = EIO;
+                return (-1);
+        }
+
+        ret = getentropy_urandom(buf, len);
+        if (ret != -1)
+                return (ret);
+
+	/* Oh well! */
+	raise(SIGKILL);
+	return -1;
+}
+
+static int
+gotdata(char *buf, size_t len)
+{
+        char    any_set = 0;
+        size_t  i;
+
+        for (i = 0; i < len; ++i)
+                any_set |= buf[i];
+        if (any_set == 0)
+                return (-1);
+        return (0);
+}
+
+static int
+getentropy_urandom(void *buf, size_t len)
+{
+        struct stat st;
+        size_t i;
+        int fd, cnt, flags;
+        int save_errno = errno;
+
+start:
+
+        flags = O_RDONLY;
+#ifdef O_NOFOLLOW
+        flags |= O_NOFOLLOW;
+#endif
+#ifdef O_CLOEXEC
+        flags |= O_CLOEXEC;
+#endif
+        fd = open("/dev/urandom", flags, 0);
+        if (fd == -1) {
+                if (errno == EINTR)
+                        goto start;
+                goto nodevrandom;
+        }
+#ifndef O_CLOEXEC
+        fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+#endif
+
+        /* Lightly verify that the device node looks sane */
+        if (fstat(fd, &st) == -1 || !S_ISCHR(st.st_mode)) {
+                close(fd);
+                goto nodevrandom;
+        }
+        for (i = 0; i < len; ) {
+                size_t wanted = len - i;
+                ssize_t ret = read(fd, (char *)buf + i, wanted);
+
+                if (ret == -1) {
+                        if (errno == EAGAIN || errno == EINTR)
+                                continue;
+                        close(fd);
+                        goto nodevrandom;
+                }
+                i += ret;
+        }
+        close(fd);
+        if (gotdata(buf, len) == 0) {
+                errno = save_errno;
+                return (0);             /* satisfied */
+        }
+nodevrandom:
+        errno = EIO;
+        return (-1);
+}
diff -Nru libbsd-0.8.7.orig/src/getpeereid.c libbsd-0.8.7/src/getpeereid.c
--- libbsd-0.8.7.orig/src/getpeereid.c	2017-06-06 04:06:45.000000000 +0200
+++ libbsd-0.8.7/src/getpeereid.c	2018-04-27 21:11:49.277638606 +0200
@@ -40,7 +40,7 @@
 getpeereid(int s, uid_t *euid, gid_t *egid)
 {
 /* XXX: This should be autodetected at build time instead. */
-#if defined(__linux__)
+#if defined(__linux__) || defined(__midipix__)
 	struct ucred cred;
 #elif defined(__OpenBSD__)
 	struct sockpeercred cred;
diff -Nru libbsd-0.8.7.orig/src/setproctitle.c libbsd-0.8.7/src/setproctitle.c
--- libbsd-0.8.7.orig/src/setproctitle.c	2017-07-17 00:47:19.000000000 +0200
+++ libbsd-0.8.7/src/setproctitle.c	2018-04-27 21:12:24.521561430 +0200
@@ -280,6 +280,7 @@
 		*++nul = '\0';
 	}
 }
+#ifndef __midipix__
 __asm__(".symver setproctitle_impl,setproctitle@@LIBBSD_0.5");
 
 /* The original function introduced in 0.2 was a stub, it only got implemented
@@ -293,3 +294,4 @@
 	__attribute__((alias("setproctitle_impl")));
 #endif
 __asm__(".symver setproctitle_stub,setproctitle@LIBBSD_0.2");
+#endif