summaryrefslogtreecommitdiffhomepage
path: root/patches/libbsd-0.9.1.local.patch
blob: 9de2d3fd73912e4d7df6f5d53973e6747a6c2bba (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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
diff -Nru libbsd-0.9.1.orig/include/bsd/sys/cdefs.h libbsd-0.9.1/include/bsd/sys/cdefs.h
--- libbsd-0.9.1.orig/include/bsd/sys/cdefs.h	2018-05-22 15:56:14.000000000 +0200
+++ libbsd-0.9.1/include/bsd/sys/cdefs.h	2018-05-30 15:27:07.067975364 +0200
@@ -93,7 +93,7 @@
 #define LIBBSD_DEPRECATED(x)
 #endif
 
-#if LIBBSD_GCC_VERSION >= 0x0200
+#if 0
 #define LIBBSD_REDIRECT(name, proto, alias) name proto __asm__(LIBBSD_ASMNAME(#alias))
 #endif
 #define LIBBSD_ASMNAME(cname) LIBBSD_ASMNAME_PREFIX(__USER_LABEL_PREFIX__, cname)
diff -Nru libbsd-0.9.1.orig/include/bsd/vis.h libbsd-0.9.1/include/bsd/vis.h
--- libbsd-0.9.1.orig/include/bsd/vis.h	2018-05-22 16:07:42.000000000 +0200
+++ libbsd-0.9.1/include/bsd/vis.h	2018-05-30 15:37:23.466013504 +0200
@@ -113,14 +113,9 @@
 
 int	strvis(char *, const char *, int);
 int	stravis(char **, const char *, int);
-#ifdef LIBBSD_NETBSD_VIS
-/* NetBSD prototype. */
-int	LIBBSD_REDIRECT(strnvis, (char *, size_t, const char *, int),
-                        strnvis_netbsd);
-#else
-/* OpenBSD prototype (current default). */
-int	strnvis(char *, const char *, size_t, int);
-#endif
+
+/* NetBSD prototype */
+int	strnvis(char *, size_t, const char *, int);
 
 int	strsvis(char *, const char *, int, const char *);
 int	strsnvis(char *, size_t, const char *, int, const char *);
@@ -135,14 +130,9 @@
     int *);
 
 int	strunvis(char *, const char *);
-#ifdef LIBBSD_NETBSD_VIS
-/* NetBSD prototype. */
-int	LIBBSD_REDIRECT(strnunvis, (char *, size_t, const char *),
-                        strnunvis_netbsd);
-#else
-/* OpenBSD prototype (current default). */
-ssize_t	strnunvis(char *, const char *, size_t);
-#endif
+
+/* NetBSD prototype */
+int	strnunvis(char *, size_t, const char *);
 
 int	strunvisx(char *, const char *, int);
 int	strnunvisx(char *, size_t, const char *, int);
diff -Nru libbsd-0.9.1.orig/src/flopen.c libbsd-0.9.1/src/flopen.c
--- libbsd-0.9.1.orig/src/flopen.c	2018-05-21 04:33:33.000000000 +0200
+++ libbsd-0.9.1/src/flopen.c	2018-05-30 15:09:48.789934331 +0200
@@ -32,6 +32,7 @@
 #include <sys/stat.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <stdarg.h>
 #include <unistd.h>
 
diff -Nru libbsd-0.9.1.orig/src/getentropy.c libbsd-0.9.1/src/getentropy.c
--- libbsd-0.9.1.orig/src/getentropy.c	2018-05-21 04:48:37.000000000 +0200
+++ libbsd-0.9.1/src/getentropy.c	2018-05-30 15:44:15.596626881 +0200
@@ -26,6 +26,8 @@
 
 #if defined(__linux__)
 #include "getentropy_linux.c"
+#elif defined(__midipix__)
+#include "getentropy_midipix.c"
 #elif defined(__GNU__)
 #include "getentropy_hurd.c"
 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
diff -Nru libbsd-0.9.1.orig/src/getentropy_midipix.c libbsd-0.9.1/src/getentropy_midipix.c
--- libbsd-0.9.1.orig/src/getentropy_midipix.c	1970-01-01 01:00:00.000000000 +0100
+++ libbsd-0.9.1/src/getentropy_midipix.c	2018-05-30 15:43:30.744779217 +0200
@@ -0,0 +1,153 @@
+/*	$OpenBSD: getentropy_linux.c,v 1.45 2018/03/13 22:53:28 bcook Exp $	*/
+
+/*
+ * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
+ * Copyright (c) 2014 Bob Beck <beck@obtuse.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Emulation of getentropy(2) as documented at:
+ * http://man.openbsd.org/getentropy.2
+ */
+
+#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>
+
+#include "hash/sha512.h"
+
+#ifdef HAVE_GETAUXVAL
+#include <sys/auxv.h>
+#endif
+#include <sys/vfs.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);
+	}
+
+	/*
+	 * Try to get entropy with /dev/urandom
+	 *
+	 * This can fail if the process is inside a chroot or if file
+	 * descriptors are exhausted.
+	 */
+	ret = getentropy_urandom(buf, len);
+	if (ret != -1)
+		return (ret);
+
+	errno = EIO;
+	return (ret);
+}
+
+/*
+ * Basic sanity checking; wish we could do better.
+ */
+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.9.1.orig/src/getpeereid.c libbsd-0.9.1/src/getpeereid.c
--- libbsd-0.9.1.orig/src/getpeereid.c	2017-06-06 04:06:45.000000000 +0200
+++ libbsd-0.9.1/src/getpeereid.c	2018-05-30 15:10:23.777937764 +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.9.1.orig/src/setproctitle.c libbsd-0.9.1/src/setproctitle.c
--- libbsd-0.9.1.orig/src/setproctitle.c	2018-04-21 23:30:22.000000000 +0200
+++ libbsd-0.9.1/src/setproctitle.c	2018-05-30 15:13:25.245835004 +0200
@@ -221,8 +221,13 @@
 #define SPT_MAXTITLE 255
 #endif
 
+#ifdef __midipix__
+void
+setproctitle(const char *fmt, ...)
+#else
 void
 setproctitle_impl(const char *fmt, ...)
+#endif
 {
 	/* Use buffer in case argv[0] is passed. */
 	char buf[SPT_MAXTITLE + 1];
@@ -280,6 +285,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 +299,4 @@
 	__attribute__((alias("setproctitle_impl")));
 #endif
 __asm__(".symver setproctitle_stub,setproctitle@LIBBSD_0.2");
+#endif /* !__midipix__ */
diff -Nru libbsd-0.9.1.orig/src/unvis.c libbsd-0.9.1/src/unvis.c
--- libbsd-0.9.1.orig/src/unvis.c	2018-05-22 16:07:42.000000000 +0200
+++ libbsd-0.9.1/src/unvis.c	2018-05-30 15:20:12.613101869 +0200
@@ -560,6 +560,8 @@
  * OpenBSD, 2001: strnunvis(char *dst, const char *src, size_t dlen);
  * NetBSD: 2012,  strnunvis(char *dst, size_t dlen, const char *src);
  */
+#ifndef __midipix__ /* Temporary fix until upstream resolves this in a later version, */
+		    /* do not upstream */
 ssize_t
 strnunvis_openbsd(char *dst, const char *src, size_t dlen)
 {
@@ -573,3 +575,9 @@
 	return strnunvisx(dst, dlen, src, 0);
 }
 __asm__(".symver strnunvis_netbsd,strnunvis@LIBBSD_0.9.1");
+#else
+int strnunvis(char *dst, size_t dlen, const char *src)
+{
+	return strnunvisx(dst, dlen, src, 0);
+}
+#endif /* __midipix__ */
diff -Nru libbsd-0.9.1.orig/src/vis.c libbsd-0.9.1/src/vis.c
--- libbsd-0.9.1.orig/src/vis.c	2018-05-22 16:07:42.000000000 +0200
+++ libbsd-0.9.1/src/vis.c	2018-05-30 15:34:26.362596310 +0200
@@ -718,6 +718,7 @@
  * OpenBSD, 2001: strnvis(char *dst, const char *src, size_t dlen, int flag);
  * NetBSD: 2012,  strnvis(char *dst, size_t dlen, const char *src, int flag);
  */
+#ifndef __midipix__ /* see src/unvis.c */
 int
 strnvis_openbsd(char *mbdst, const char *mbsrc, size_t dlen, int flags)
 {
@@ -731,6 +732,13 @@
 	return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL);
 }
 __asm__(".symver strnvis_netbsd,strnvis@LIBBSD_0.9.1");
+#else
+int
+strnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags)
+{
+	return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL);
+}
+#endif
 
 int
 stravis(char **mbdstp, const char *mbsrc, int flags)