From 685abdeced9e802e3036aaa02cf70d202a147f23 Mon Sep 17 00:00:00 2001 From: kristapsdz Date: Wed, 18 Oct 2017 21:36:59 +0000 Subject: [PATCH] Full switch to oconfigure instead of current system, so remove all of the test and compat files. These are now in tests.c and compats.c, and driven by the configure script. Also remove the MD5 code, which is part of compats.c. Lastly, move ifdefs to ifs, remove defined (same), and also remove HAVE_CONFIG_H. --- GNUmakefile | 59 +- afl/afl-multipart.c | 3 +- afl/afl-plain.c | 3 +- afl/afl-template.c | 3 +- afl/afl-urlencoded.c | 3 +- archive.css | 9 +- archive.xml | 2 +- auth.c | 7 +- child.c | 8 +- compat-memmem.c | 68 --- compat-reallocarray.c | 26 - compat-strlcat.c | 75 --- compat-strlcpy.c | 70 --- compat-strtonum.c | 72 --- compats.c | 855 ++++++++++++++++++++++++++++ config.h.post | 37 -- config.h.pre | 10 - configure | 479 ++++++++++++++-- datetime.c | 2 - fcgi.c | 2 - functions.xml | 2 +- httpauth.c | 2 - index.css | 15 +- index.xml | 2 +- kcgi.c | 4 +- kcgihtml.c | 2 - kcgijson.c | 2 - kcgiregress.c | 3 +- kcgixml.c | 2 - kfcgi.c | 2 - logging.c | 2 - md5.c | 248 -------- md5.h | 43 -- output.c | 7 +- parent.c | 7 +- regress/regress.c | 2 - regress/test-abort-validator.c | 2 - regress/test-basic.c | 2 - regress/test-bigfile.c | 2 - regress/test-datetime.c | 2 - regress/test-digest.c | 2 - regress/test-fcgi-abort-validator.c | 2 - regress/test-fcgi-bigfile.c | 2 - regress/test-fcgi-file-get.c | 2 - regress/test-fcgi-header-bad.c | 2 - regress/test-fcgi-header.c | 2 - regress/test-fcgi-path-check.c | 2 - regress/test-fcgi-ping.c | 2 - regress/test-fcgi-upload.c | 2 - regress/test-file-get.c | 2 - regress/test-fork.c | 2 - regress/test-gzip-bigfile.c | 2 - regress/test-gzip.c | 2 - regress/test-header-bad.c | 2 - regress/test-header.c | 2 - regress/test-httpdate.c | 2 - regress/test-nogzip.c | 2 - regress/test-path-check.c | 2 - regress/test-ping.c | 2 - regress/test-post.c | 2 - regress/test-returncode.c | 2 - regress/test-template.c | 2 - regress/test-upload.c | 2 - sandbox-capsicum.c | 4 +- sandbox-darwin.c | 4 +- sandbox-pledge.c | 4 +- sandbox-seccomp-filter.c | 4 +- sandbox-systrace.c | 4 +- sandbox.c | 42 +- test-arc4random.c | 12 - test-capsicum.c | 8 - test-memmem.c | 8 - test-pledge.c | 13 - test-reallocarray.c | 8 - test-sandbox_init.c | 11 - test-seccomp-filter.c | 11 - test-strlcat.c | 11 - test-strlcpy.c | 11 - test-strtonum.c | 9 - test-systrace.c | 11 - test-zlib.c | 14 - tests.c | 354 ++++++++++++ tutorial.css | 11 +- tutorial.xml | 2 +- wrappers.c | 3 +- 85 files changed, 1738 insertions(+), 1013 deletions(-) delete mode 100644 compat-memmem.c delete mode 100644 compat-reallocarray.c delete mode 100644 compat-strlcat.c delete mode 100644 compat-strlcpy.c delete mode 100644 compat-strtonum.c create mode 100644 compats.c delete mode 100644 config.h.post delete mode 100644 config.h.pre delete mode 100644 md5.c delete mode 100644 md5.h delete mode 100644 test-arc4random.c delete mode 100644 test-capsicum.c delete mode 100644 test-memmem.c delete mode 100644 test-pledge.c delete mode 100644 test-reallocarray.c delete mode 100644 test-sandbox_init.c delete mode 100644 test-seccomp-filter.c delete mode 100644 test-strlcat.c delete mode 100644 test-strlcpy.c delete mode 100644 test-strtonum.c delete mode 100644 test-systrace.c delete mode 100644 test-zlib.c create mode 100644 tests.c diff --git a/GNUmakefile b/GNUmakefile index 3974fdb..729be62 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,6 +1,8 @@ .SUFFIXES: .3 .3.html .8 .8.html .dot .svg .gnuplot .png .xml .html .PHONY: regress +include Makefile.configure + # Comment if you don't need statically linked. # This is only for the sample program! STATIC = -static @@ -41,11 +43,6 @@ SBINDIR = $(PREFIX)/sbin LIBDIR = $(PREFIX)/lib INCLUDEDIR = $(PREFIX)/include VERSION = 0.9.8 -LIBCONFIGOBJS = compat-memmem.o \ - compat-reallocarray.o \ - compat-strlcat.o \ - compat-strlcpy.o \ - compat-strtonum.o LIBOBJS = auth.o \ child.o \ datetime.o \ @@ -53,7 +50,6 @@ LIBOBJS = auth.o \ httpauth.o \ kcgi.o \ logging.o \ - md5.o \ output.o \ parent.o \ sandbox.o \ @@ -65,20 +61,6 @@ LIBOBJS = auth.o \ wrappers.o HTMLS = $(addsuffix .html, $(MANS)) \ functions.html -TESTOBJS = $(addsuffix .o, $(TESTS)) -TESTSRCS = $(addsuffix .c, $(TESTS)) -TESTS = test-arc4random \ - test-memmem \ - test-reallocarray \ - test-sandbox_init \ - test-capsicum \ - test-pledge \ - test-strlcat \ - test-strlcpy \ - test-strtonum \ - test-seccomp-filter \ - test-systrace \ - test-zlib MAN3S = man/kcgi.3 \ man/kcgihtml.3 \ man/kcgijson.3 \ @@ -106,18 +88,12 @@ MANS = $(MAN3S) \ $(MAN8S) SRCS = auth.c \ child.c \ - compat-memmem.c \ - compat-reallocarray.c \ - compat-strlcat.c \ - compat-strlcpy.c \ - compat-strtonum.c \ + compats.c \ extern.h \ datetime.c \ fcgi.c \ httpauth.c \ logging.c \ - md5.c \ - md5.h \ kcgi.c \ kcgihtml.c \ kcgijson.c \ @@ -140,9 +116,9 @@ SRCS = auth.c \ sandbox-pledge.c \ sandbox-seccomp-filter.c \ sandbox-systrace.c \ + tests.c \ wrappers.c \ - $(MANS) \ - $(TESTSRCS) + $(MANS) AFL = afl/afl-multipart \ afl/afl-plain \ afl/afl-template \ @@ -216,8 +192,8 @@ regresslog: $(REGRESS) ./$$f >/dev/null || exit 1 ; \ done -libconfig.a: config.h $(LIBCONFIGOBJS) - $(AR) rs $@ $(LIBCONFIGOBJS) +libconfig.a: config.h compats.o + $(AR) rs $@ compats.o kfcgi: kfcgi.o libconfig.a $(CC) $(CFLAGS) -o $@ kfcgi.o libconfig.a @@ -235,8 +211,8 @@ afl/%: afl/%.c libkcgi.a .PRECIOUS: $(REGRESS_OBJS) -libkcgi.a: $(LIBOBJS) $(LIBCONFIGOBJS) $(LIBSANDBOXOBJS) - $(AR) rs $@ $(LIBOBJS) $(LIBCONFIGOBJS) $(LIBSANDBOXOBJS) +libkcgi.a: $(LIBOBJS) compats.o $(LIBSANDBOXOBJS) + $(AR) rs $@ $(LIBOBJS) compats.o $(LIBSANDBOXOBJS) kcgihtml.o: kcgihtml.h @@ -262,13 +238,7 @@ $(LIBOBJS) sample.o sample-fcgi.o kcgihtml.o kcgijson.o kcgixml.o: kcgi.h $(LIBOBJS) kcgihtml.o kcgijson.o kcgixml.o kcgiregress.o: config.h extern.h -auth.o child.o md5.o parent.o: md5.h - -$(LIBCONFIGOBJS): config.h - -config.h: config.h.pre config.h.post configure $(TESTSRCS) - rm -f config.log - CC="$(CC)" CFLAGS="$(CFLAGS)" ./configure +compats.o: config.h installcgi: sample sample-fcgi sample-cgi install -m 0755 sample $(PREFIX)/sample.cgi @@ -354,7 +324,7 @@ kcgi.tgz: cp $(AFL_SRCS) .dist/kcgi-$(VERSION)/afl cp GNUmakefile template.xml .dist/kcgi-$(VERSION) cp $(MANS) .dist/kcgi-$(VERSION)/man - cp configure config.h.pre config.h.post .dist/kcgi-$(VERSION) + cp configure .dist/kcgi-$(VERSION) (cd .dist && tar zcf ../$@ kcgi-$(VERSION)) rm -rf .dist @@ -371,10 +341,11 @@ clean: rm -f kcgi.tgz kcgi.tgz.sha512 $(SVGS) $(HTMLS) sample sample-fcgi sample.o sample-fcgi.o kfcgi kfcgi.o sample-cgi sample-cgi.o rm -f $(SBLGS) $(TUTORIALHTMLS) extending01.html rm -f libconfig.a - rm -f $(LIBOBJS) $(LIBCONFIGOBJS) + rm -f $(LIBOBJS) compats.o rm -f $(LIBS) kcgihtml.o kcgijson.o kcgixml.o kcgiregress.o - rm -f config.log config.h - rm -f $(TESTS) $(TESTOBJS) rm -f test-abort-valid.core core rm -f $(REGRESS) $(AFL) $(REGRESS_OBJS) rm -rf *.dSYM regress/*.dSYM afl/*.dSYM + +distclean: clean + rm -f config.h config.log Makefile.configure diff --git a/afl/afl-multipart.c b/afl/afl-multipart.c index 5d2b10a..edc830f 100644 --- a/afl/afl-multipart.c +++ b/afl/afl-multipart.c @@ -14,9 +14,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif + #include #include diff --git a/afl/afl-plain.c b/afl/afl-plain.c index 1ca8b4a..deaeab3 100644 --- a/afl/afl-plain.c +++ b/afl/afl-plain.c @@ -14,9 +14,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif + #include #include diff --git a/afl/afl-template.c b/afl/afl-template.c index 15a21b6..7829fc7 100644 --- a/afl/afl-template.c +++ b/afl/afl-template.c @@ -14,9 +14,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif + #include #include diff --git a/afl/afl-urlencoded.c b/afl/afl-urlencoded.c index 50abe52..e5df9b1 100644 --- a/afl/afl-urlencoded.c +++ b/afl/afl-urlencoded.c @@ -14,9 +14,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif + #include #include diff --git a/archive.css b/archive.css index 653e23c..082dd96 100644 --- a/archive.css +++ b/archive.css @@ -2,10 +2,11 @@ html, body { margin: 0; padding: 0; } body { color: #333; font-family: "Alegreya sans", Calibri, Candara, Segoe, Segoe UI, Optima, Arial, sans-serif; - font-weight: 300; + font-weight: 400; font-size: 13pt; line-height: 17pt; } a { text-decoration: none; } +strong, b { font-weight: 700; } code, pre { font-size: 11pt; } body > header { box-shadow: 0 1px 4px #888; background-color: #333; @@ -25,7 +26,7 @@ body > header nav .version { border-right: thin solid silver; h1 { font-size: 24pt; margin: 0; margin-bottom: 8pt; - font-weight: normal; } + font-weight: 400; } .nm, .file { font-style: italic; } h1 .nm { text-shadow: 1px 1px #666; font-style: inherit; } @@ -40,7 +41,7 @@ footer span { border-left: thin solid #ccc; footer { padding: 1ex; margin-top: 1em; margin-bottom: 1em; } -.flag { font-weight: 400; } +.flag { font-weight: 500; } #functions, #archive { width: 60%; margin-left: auto; margin-right: auto; } @@ -53,7 +54,7 @@ footer { padding: 1ex; #archive .title { display: flex; border-bottom: thin solid #eee; margin-bottom: 0.25em; } -#archive .title > :first-child { font-weight: 400; } +#archive .title > :first-child { font-weight: 500; } #archive .title > :last-child { flex: 1; font-size: 11pt; text-align: right; } diff --git a/archive.xml b/archive.xml index 40beb0f..6cc30a0 100644 --- a/archive.xml +++ b/archive.xml @@ -5,7 +5,7 @@ kcgi | minimal CGI and FastCGI library for C - + diff --git a/auth.c b/auth.c index 73ff4b5..d0676a0 100644 --- a/auth.c +++ b/auth.c @@ -14,11 +14,13 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include +#if HAVE_MD5 +# include +# include +#endif #include #include #include @@ -26,7 +28,6 @@ #include #include "kcgi.h" -#include "md5.h" #include "extern.h" static const char b64[] = diff --git a/child.c b/child.c index 001cdbb..e39ce78 100644 --- a/child.c +++ b/child.c @@ -14,9 +14,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif + #include #include @@ -24,6 +23,10 @@ #include #include #include +#if HAVE_MD5 +# include +# include +#endif #include #include #include @@ -35,7 +38,6 @@ #include "kcgi.h" #include "extern.h" -#include "md5.h" /* * For handling HTTP multipart forms. diff --git a/compat-memmem.c b/compat-memmem.c deleted file mode 100644 index 6912b0e..0000000 --- a/compat-memmem.c +++ /dev/null @@ -1,68 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#ifndef HAVE_MEMMEM -/* $OpenBSD$ */ -/*- - * Copyright (c) 2005 Pascal Gloor - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. The name of the author may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/* - * Find the first occurrence of the byte string s in byte string l. - */ -void * -memmem(const void *l, size_t l_len, const void *s, size_t s_len) -{ - const char *cur, *last; - const char *cl = l; - const char *cs = s; - - /* a zero length needle should just return the haystack */ - if (l_len == 0) - return (void *)cl; - - /* "s" must be smaller or equal to "l" */ - if (l_len < s_len) - return NULL; - - /* special case where s_len == 1 */ - if (s_len == 1) - return memchr(l, *cs, l_len); - - /* the last position where its possible to find "s" in "l" */ - last = cl + l_len - s_len; - - for (cur = cl; cur <= last; cur++) - if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0) - return (void *)cur; - - return NULL; -} -#endif diff --git a/compat-reallocarray.c b/compat-reallocarray.c deleted file mode 100644 index 0741516..0000000 --- a/compat-reallocarray.c +++ /dev/null @@ -1,26 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifndef HAVE_REALLOCARRAY -#include -#include -#include -#include - -/* this is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX - * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW - */ -#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) - -void * -reallocarray(void *optr, size_t nmemb, size_t size) -{ - if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && - nmemb > 0 && SIZE_MAX / nmemb < size) { - errno = ENOMEM; - return NULL; - } - return realloc(optr, size * nmemb); -} -#endif /*HAVE_REALLOCARRAY */ diff --git a/compat-strlcat.c b/compat-strlcat.c deleted file mode 100644 index ab8e23c..0000000 --- a/compat-strlcat.c +++ /dev/null @@ -1,75 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifndef HAVE_STRLCAT -/* $OpenBSD$ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include - -/* - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -size_t strlcat(dst, src, siz) - char *dst; - const char *src; - size_t siz; -{ - register char *d = dst; - register const char *s = src; - register size_t n = siz; - size_t dlen; - - /* Find the end of dst and adjust bytes left but don't go past end */ - while (*d != '\0' && n-- != 0) - d++; - dlen = d - dst; - n = siz - dlen; - - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; - - return(dlen + (s - src)); /* count does not include NUL */ -} - -#endif /* !HAVE_STRLCAT */ - - diff --git a/compat-strlcpy.c b/compat-strlcpy.c deleted file mode 100644 index a85d8b4..0000000 --- a/compat-strlcpy.c +++ /dev/null @@ -1,70 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifndef HAVE_STRLCPY -/* $OpenBSD$ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include - -/* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -size_t strlcpy(dst, src, siz) - char *dst; - const char *src; - size_t siz; -{ - register char *d = dst; - register const char *s = src; - register size_t n = siz; - - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) { - do { - if ((*d++ = *s++) == 0) - break; - } while (--n != 0); - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} - -#endif /* !HAVE_STRLCPY */ diff --git a/compat-strtonum.c b/compat-strtonum.c deleted file mode 100644 index fb40a3b..0000000 --- a/compat-strtonum.c +++ /dev/null @@ -1,72 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifndef HAVE_STRTONUM -/* OPENBSD ORIGINAL: lib/libc/stdlib/strtonum.c */ - -/* $OpenBSD$ */ - -/* - * Copyright (c) 2004 Ted Unangst and Todd Miller - * All rights reserved. - * - * 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. - */ -#include -#include -#include - -#define INVALID 1 -#define TOOSMALL 2 -#define TOOLARGE 3 - -long long -strtonum(const char *numstr, long long minval, long long maxval, - const char **errstrp) -{ - long long ll = 0; - char *ep; - int error = 0; - struct errval { - const char *errstr; - int err; - } ev[4] = { - { NULL, 0 }, - { "invalid", EINVAL }, - { "too small", ERANGE }, - { "too large", ERANGE }, - }; - - ev[0].err = errno; - errno = 0; - if (minval > maxval) - error = INVALID; - else { - ll = strtoll(numstr, &ep, 10); - if (numstr == ep || *ep != '\0') - error = INVALID; - else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) - error = TOOSMALL; - else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) - error = TOOLARGE; - } - if (errstrp != NULL) - *errstrp = ev[error].errstr; - errno = ev[error].err; - if (error) - ll = 0; - - return (ll); -} -#endif /* HAVE_STRTONUM */ diff --git a/compats.c b/compats.c new file mode 100644 index 0000000..8c8d325 --- /dev/null +++ b/compats.c @@ -0,0 +1,855 @@ +#include "config.h" +#if !HAVE_ERR +/* + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +static void vwarni(const char *, va_list); +static void vwarnxi(const char *, va_list); + +static void +vwarnxi(const char *fmt, va_list ap) +{ + fprintf(stderr, "%s: ", getprogname()); + if (fmt != NULL) + vfprintf(stderr, fmt, ap); +} + +static void +vwarni(const char *fmt, va_list ap) +{ + int sverrno; + + sverrno = errno; + vwarnxi(fmt, ap); + if (fmt != NULL) + fputs(": ", stderr); + fprintf(stderr, "%s\n", strerror(sverrno)); +} + +void +err(int eval, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vwarni(fmt, ap); + va_end(ap); + exit(eval); +} + +void +errx(int eval, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vwarnxi(fmt, ap); + va_end(ap); + fputc('\n', stderr); + exit(eval); +} + +void +warn(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vwarni(fmt, ap); + va_end(ap); +} + +void +warnx(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vwarnxi(fmt, ap); + va_end(ap); + fputc('\n', stderr); +} +#endif /* !HAVE_ERR */ +#if !HAVE_EXPLICIT_BZERO +/* OPENBSD ORIGINAL: lib/libc/string/explicit_bzero.c */ +/* + * Public domain. + * Written by Ted Unangst + */ + +#include + +/* + * explicit_bzero - don't let the compiler optimize away bzero + */ + +#if HAVE_MEMSET_S + +void +explicit_bzero(void *p, size_t n) +{ + if (n == 0) + return; + (void)memset_s(p, n, 0, n); +} + +#else /* HAVE_MEMSET_S */ + +/* + * Indirect bzero through a volatile pointer to hopefully avoid + * dead-store optimisation eliminating the call. + */ +static void (* volatile ssh_bzero)(void *, size_t) = bzero; + +void +explicit_bzero(void *p, size_t n) +{ + if (n == 0) + return; + /* + * clang -fsanitize=memory needs to intercept memset-like functions + * to correctly detect memory initialisation. Make sure one is called + * directly since our indirection trick above sucessfully confuses it. + */ +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + memset(p, 0, n); +# endif +#endif + + ssh_bzero(p, n); +} + +#endif /* HAVE_MEMSET_S */ +#endif /* !HAVE_EXPLICIT_BZERO */ +#if !HAVE_GETPROGNAME +/* + * Copyright (c) 2016 Nicholas Marriott + * Copyright (c) 2017 Kristaps Dzonsons + * + * 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 MIND, 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. + */ + +#include + +#include + +#if HAVE_PROGRAM_INVOCATION_SHORT_NAME +const char * +getprogname(void) +{ + return (program_invocation_short_name); +} +#elif HAVE___PROGNAME +const char * +getprogname(void) +{ + extern char *__progname; + + return (__progname); +} +#else +#error No getprogname available. +#endif +#endif /* !HAVE_GETPROGNAME */ +#if !HAVE_MD5 +/* + * This code implements the MD5 message-digest algorithm. + * The algorithm is due to Ron Rivest. This code was + * written by Colin Plumb in 1993, no copyright is claimed. + * This code is in the public domain; do with it what you wish. + * + * Equivalent code is available from RSA Data Security, Inc. + * This code has been tested against that, and is equivalent, + * except that you don't need to include two pages of legalese + * with every copy. + * + * To compute the message digest of a chunk of bytes, declare an + * MD5Context structure, pass it to MD5Init, call MD5Update as + * needed on buffers full of bytes, and then call MD5Final, which + * will fill a supplied 16-byte array with the digest. + */ + +#include +#include +#include + +#define PUT_64BIT_LE(cp, value) do { \ + (cp)[7] = (value) >> 56; \ + (cp)[6] = (value) >> 48; \ + (cp)[5] = (value) >> 40; \ + (cp)[4] = (value) >> 32; \ + (cp)[3] = (value) >> 24; \ + (cp)[2] = (value) >> 16; \ + (cp)[1] = (value) >> 8; \ + (cp)[0] = (value); } while (0) + +#define PUT_32BIT_LE(cp, value) do { \ + (cp)[3] = (value) >> 24; \ + (cp)[2] = (value) >> 16; \ + (cp)[1] = (value) >> 8; \ + (cp)[0] = (value); } while (0) + +static u_int8_t PADDING[MD5_BLOCK_LENGTH] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* + * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious + * initialization constants. + */ +void +MD5Init(MD5_CTX *ctx) +{ + ctx->count = 0; + ctx->state[0] = 0x67452301; + ctx->state[1] = 0xefcdab89; + ctx->state[2] = 0x98badcfe; + ctx->state[3] = 0x10325476; +} + +/* + * Update context to reflect the concatenation of another buffer full + * of bytes. + */ +void +MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len) +{ + size_t have, need; + + /* Check how many bytes we already have and how many more we need. */ + have = (size_t)((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1)); + need = MD5_BLOCK_LENGTH - have; + + /* Update bitcount */ + ctx->count += (u_int64_t)len << 3; + + if (len >= need) { + if (have != 0) { + memcpy(ctx->buffer + have, input, need); + MD5Transform(ctx->state, ctx->buffer); + input += need; + len -= need; + have = 0; + } + + /* Process data in MD5_BLOCK_LENGTH-byte chunks. */ + while (len >= MD5_BLOCK_LENGTH) { + MD5Transform(ctx->state, input); + input += MD5_BLOCK_LENGTH; + len -= MD5_BLOCK_LENGTH; + } + } + + /* Handle any remaining bytes of data. */ + if (len != 0) + memcpy(ctx->buffer + have, input, len); +} + +/* + * Pad pad to 64-byte boundary with the bit pattern + * 1 0* (64-bit count of bits processed, MSB-first) + */ +void +MD5Pad(MD5_CTX *ctx) +{ + u_int8_t count[8]; + size_t padlen; + + /* Convert count to 8 bytes in little endian order. */ + PUT_64BIT_LE(count, ctx->count); + + /* Pad out to 56 mod 64. */ + padlen = MD5_BLOCK_LENGTH - + ((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1)); + if (padlen < 1 + 8) + padlen += MD5_BLOCK_LENGTH; + MD5Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */ + MD5Update(ctx, count, 8); +} + +/* + * Final wrapup--call MD5Pad, fill in digest and zero out ctx. + */ +void +MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx) +{ + int i; + + MD5Pad(ctx); + for (i = 0; i < 4; i++) + PUT_32BIT_LE(digest + i * 4, ctx->state[i]); + memset(ctx, 0, sizeof(*ctx)); +} + + +/* The four core functions - F1 is optimized somewhat */ + +/* #define F1(x, y, z) (x & y | ~x & z) */ +#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F2(x, y, z) F1(z, x, y) +#define F3(x, y, z) (x ^ y ^ z) +#define F4(x, y, z) (y ^ (x | ~z)) + +/* This is the central step in the MD5 algorithm. */ +#define MD5STEP(f, w, x, y, z, data, s) \ + ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) + +/* + * The core of the MD5 algorithm, this alters an existing MD5 hash to + * reflect the addition of 16 longwords of new data. MD5Update blocks + * the data and converts bytes into longwords for this routine. + */ +void +MD5Transform(u_int32_t state[4], const u_int8_t block[MD5_BLOCK_LENGTH]) +{ + u_int32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4]; + +#if BYTE_ORDER == LITTLE_ENDIAN + memcpy(in, block, sizeof(in)); +#else + for (a = 0; a < MD5_BLOCK_LENGTH / 4; a++) { + in[a] = (u_int32_t)( + (u_int32_t)(block[a * 4 + 0]) | + (u_int32_t)(block[a * 4 + 1]) << 8 | + (u_int32_t)(block[a * 4 + 2]) << 16 | + (u_int32_t)(block[a * 4 + 3]) << 24); + } +#endif + + a = state[0]; + b = state[1]; + c = state[2]; + d = state[3]; + + MD5STEP(F1, a, b, c, d, in[ 0] + 0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, in[ 1] + 0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, in[ 2] + 0x242070db, 17); + MD5STEP(F1, b, c, d, a, in[ 3] + 0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, in[ 4] + 0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, in[ 5] + 0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, in[ 6] + 0xa8304613, 17); + MD5STEP(F1, b, c, d, a, in[ 7] + 0xfd469501, 22); + MD5STEP(F1, a, b, c, d, in[ 8] + 0x698098d8, 7); + MD5STEP(F1, d, a, b, c, in[ 9] + 0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); + MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); + MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); + MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, in[ 1] + 0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, in[ 6] + 0xc040b340, 9); + MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, in[ 0] + 0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, in[ 5] + 0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); + MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, in[ 4] + 0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, in[ 9] + 0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, in[ 3] + 0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, in[ 8] + 0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, in[ 2] + 0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, in[ 7] + 0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, in[ 5] + 0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, in[ 8] + 0x8771f681, 11); + MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, in[ 1] + 0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, in[ 4] + 0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, in[ 7] + 0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, in[ 0] + 0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, in[ 3] + 0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, in[ 6] + 0x04881d05, 23); + MD5STEP(F3, a, b, c, d, in[ 9] + 0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, in[2 ] + 0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, in[ 0] + 0xf4292244, 6); + MD5STEP(F4, d, a, b, c, in[7 ] + 0x432aff97, 10); + MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, in[5 ] + 0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, in[3 ] + 0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, in[1 ] + 0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, in[8 ] + 0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, in[6 ] + 0xa3014314, 15); + MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, in[4 ] + 0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, in[2 ] + 0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, in[9 ] + 0xeb86d391, 21); + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; +} + +char * +MD5End(MD5_CTX *ctx, char *buf) +{ + int i; + unsigned char digest[MD5_DIGEST_LENGTH]; + static const char hex[]="0123456789abcdef"; + + if (!buf) + buf = malloc(2*MD5_DIGEST_LENGTH + 1); + if (!buf) + return 0; + MD5Final(digest, ctx); + for (i = 0; i < MD5_DIGEST_LENGTH; i++) { + buf[i+i] = hex[digest[i] >> 4]; + buf[i+i+1] = hex[digest[i] & 0x0f]; + } + buf[i+i] = '\0'; + return buf; +} +#endif /* !HAVE_MD5 */ +#if !HAVE_MEMMEM +/*- + * Copyright (c) 2005 Pascal Gloor + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Find the first occurrence of the byte string s in byte string l. + */ +void * +memmem(const void *l, size_t l_len, const void *s, size_t s_len) +{ + const char *cur, *last; + const char *cl = l; + const char *cs = s; + + /* a zero length needle should just return the haystack */ + if (l_len == 0) + return (void *)cl; + + /* "s" must be smaller or equal to "l" */ + if (l_len < s_len) + return NULL; + + /* special case where s_len == 1 */ + if (s_len == 1) + return memchr(l, *cs, l_len); + + /* the last position where its possible to find "s" in "l" */ + last = cl + l_len - s_len; + + for (cur = cl; cur <= last; cur++) + if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0) + return (void *)cur; + + return NULL; +} +#endif /* !HAVE_MEMMEM */ +#if !HAVE_MEMRCHR +/* + * Copyright (c) 2007 Todd C. Miller + * + * 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. + * + */ + +#include + +/* + * Reverse memchr() + * Find the last occurrence of 'c' in the buffer 's' of size 'n'. + */ +void * +memrchr(const void *s, int c, size_t n) +{ + const unsigned char *cp; + + if (n != 0) { + cp = (unsigned char *)s + n; + do { + if (*(--cp) == (unsigned char)c) + return((void *)cp); + } while (--n != 0); + } + return(NULL); +} +#endif /* !HAVE_MEMRCHR */ +#if !HAVE_REALLOCARRAY +/* + * Copyright (c) 2008 Otto Moerbeek + * + * 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. + */ + +#include +#include +#include +#include + +/* + * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX + * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW + */ +#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) + +void * +reallocarray(void *optr, size_t nmemb, size_t size) +{ + if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && + nmemb > 0 && SIZE_MAX / nmemb < size) { + errno = ENOMEM; + return NULL; + } + return realloc(optr, size * nmemb); +} +#endif /* !HAVE_REALLOCARRAY */ +#if !HAVE_RECALLOCARRAY +/* + * Copyright (c) 2008, 2017 Otto Moerbeek + * + * 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. + */ + +/* OPENBSD ORIGINAL: lib/libc/stdlib/recallocarray.c */ + +#include +#include +#include +#include +#include + +/* + * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX + * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW + */ +#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) + +void * +recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size) +{ + size_t oldsize, newsize; + void *newptr; + + if (ptr == NULL) + return calloc(newnmemb, size); + + if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && + newnmemb > 0 && SIZE_MAX / newnmemb < size) { + errno = ENOMEM; + return NULL; + } + newsize = newnmemb * size; + + if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && + oldnmemb > 0 && SIZE_MAX / oldnmemb < size) { + errno = EINVAL; + return NULL; + } + oldsize = oldnmemb * size; + + /* + * Don't bother too much if we're shrinking just a bit, + * we do not shrink for series of small steps, oh well. + */ + if (newsize <= oldsize) { + size_t d = oldsize - newsize; + + if (d < oldsize / 2 && d < (size_t)getpagesize()) { + memset((char *)ptr + newsize, 0, d); + return ptr; + } + } + + newptr = malloc(newsize); + if (newptr == NULL) + return NULL; + + if (newsize > oldsize) { + memcpy(newptr, ptr, oldsize); + memset((char *)newptr + oldsize, 0, newsize - oldsize); + } else + memcpy(newptr, ptr, newsize); + + explicit_bzero(ptr, oldsize); + free(ptr); + + return newptr; +} +#endif /* !HAVE_RECALLOCARRAY */ +#if !HAVE_STRLCAT +/* + * Copyright (c) 1998 Todd C. Miller + * + * 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. + */ + +#include +#include + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +strlcat(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} +#endif /* !HAVE_STRLCAT */ +#if !HAVE_STRLCPY +/* + * Copyright (c) 1998 Todd C. Miller + * + * 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. + */ + +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0) { + while (--n != 0) { + if ((*d++ = *s++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} +#endif /* !HAVE_STRLCPY */ +#if !HAVE_STRTONUM +/* + * Copyright (c) 2004 Ted Unangst and Todd Miller + * All rights reserved. + * + * 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. + */ + +#include +#include +#include + +#define INVALID 1 +#define TOOSMALL 2 +#define TOOLARGE 3 + +long long +strtonum(const char *numstr, long long minval, long long maxval, + const char **errstrp) +{ + long long ll = 0; + int error = 0; + char *ep; + struct errval { + const char *errstr; + int err; + } ev[4] = { + { NULL, 0 }, + { "invalid", EINVAL }, + { "too small", ERANGE }, + { "too large", ERANGE }, + }; + + ev[0].err = errno; + errno = 0; + if (minval > maxval) { + error = INVALID; + } else { + ll = strtoll(numstr, &ep, 10); + if (numstr == ep || *ep != '\0') + error = INVALID; + else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) + error = TOOSMALL; + else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) + error = TOOLARGE; + } + if (errstrp != NULL) + *errstrp = ev[error].errstr; + errno = ev[error].err; + if (error) + ll = 0; + + return (ll); +} +#endif /* !HAVE_STRTONUM */ diff --git a/config.h.post b/config.h.post deleted file mode 100644 index 3eddfef..0000000 --- a/config.h.post +++ /dev/null @@ -1,37 +0,0 @@ -#if !defined(__BEGIN_DECLS) -# ifdef __cplusplus -# define __BEGIN_DECLS extern "C" { -# else -# define __BEGIN_DECLS -# endif -#endif -#if !defined(__END_DECLS) -# ifdef __cplusplus -# define __END_DECLS } -# else -# define __END_DECLS -# endif -#endif - -#ifndef HAVE_STRTONUM -extern long long strtonum - (const char *numstr, long long minval, - long long maxval, const char **errstrp); -#endif -#ifndef HAVE_MEMMEM -extern void *memmem - (const void *l, size_t l_len, - const void *s, size_t s_len); -#endif -#ifndef HAVE_REALLOCARRAY -extern void *reallocarray - (void *optr, size_t nmemb, size_t size); -#endif -#ifndef HAVE_STRLCPY -size_t strlcpy(char *dst, const char *src, size_t siz); -#endif -#ifndef HAVE_STRLCAT -size_t strlcat(char *dst, const char *src, size_t siz); -#endif - -#endif /* CONFIG_H */ diff --git a/config.h.pre b/config.h.pre deleted file mode 100644 index 14beb28..0000000 --- a/config.h.pre +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -#if defined(__linux__) || defined(__MINT__) -# define _GNU_SOURCE /* vasprintf */ -#endif - -#include - -/* #define SANDBOX_SECCOMP_DEBUG */ diff --git a/configure b/configure index c2db3df..35264dd 100755 --- a/configure +++ b/configure @@ -1,6 +1,9 @@ -#!/bin/sh +#! /bin/sh # -# Copyright (c) 2014 Ingo Schwarze +# $Id$ +# +# Copyright (c) 2014, 2015, 2016 Ingo Schwarze +# Copyright (c) 2017 Kristaps Dzonsons # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -14,44 +17,448 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# This script outputs two files: config.h and Makefile.configure. +# It tries to read from configure.local, which contains predefined +# values we won't autoconfigure. +# +# If you want to use configure with your project, have your GNUmakefile +# or BSDmakefile---whichever---try to import/include Makefile.configure +# at the beginning of the file. +# +# Like so (note no quotes, no period, etc.): +# +# include Makefile.configure +# +# If it exists, configure was run; otherwise, it wasn't. +# +# You'll probably want to change parts of this file. I've noted the +# parts that you'll probably change in the section documentation. + set -e -exec > config.h 2> config.log -CFLAGS="${CFLAGS} -Wno-unused -Werror" +#---------------------------------------------------------------------- +# Prepare for running: move aside previous configure runs. +# Output file descriptor usage: +# 1 (stdout): config.h or Makefile.configure +# 2 (stderr): original stderr, usually to the console +# 3: config.log +# You DO NOT want to change this. +#---------------------------------------------------------------------- -runtest() { - echo ${CC} ${CFLAGS} -o test-${1} test-${1}.c 1>&2 - ${CC} ${CFLAGS} -o "test-${1}" "test-${1}.c" $3 1>&2 || return 0 - "./test-${1}" && echo "#define HAVE_${2}" \ - || echo FAILURE: test-${1} returned $? 1>&2 - rm "test-${1}" +[ -w config.log ] && mv config.log config.log.old +[ -w config.h ] && mv config.h config.h.old + +exec 3> config.log +echo "config.log: writing..." + +#---------------------------------------------------------------------- +# Initialize all variables here such that nothing can leak in from the +# environment. +# You MIGHT want to change this. +#---------------------------------------------------------------------- + +CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | env -i make -sf -` +CFLAGS=`printf "all:\\n\\t@echo \\\$(CFLAGS)\\n" | env -i make -sf -` +CFLAGS="${CFLAGS} -g -W -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes" +CFLAGS="${CFLAGS} -Wwrite-strings -Wno-unused-parameter" +LDADD= +CPPFLAGS= +LDFLAGS= +PREFIX="/usr/local" +BINDIR= +SBINDIR= +INCLUDEDIR= +LIBDIR= +MANDIR= +INSTALL="install" +INSTALL_PROGRAM= +INSTALL_LIB= +INSTALL_MAN= +INSTALL_DATA= + +#---------------------------------------------------------------------- +# Allow certain variables to be overriden on the command line. +#---------------------------------------------------------------------- + +for keyvals in $@ +do + key=`echo $keyvals | cut -s -d '=' -f 1` + if [ -z "$key" ] + then + echo "$0: invalid key-value: $keyvals" 1>&2 + exit 1 + fi + val=`echo $keyvals | cut -d '=' -f 2-` + case "$key" in + LDFLAGS) + LDFLAGS="$val" ;; + CPPFLAGS) + CPPFLAGS="$val" ;; + PREFIX) + PREFIX="$val" ;; + MANDIR) + MANDIR="$val" ;; + LIBDIR) + LIBDIR="$val" ;; + BINDIR) + BINDIR="$val" ;; + SBINDIR) + SBINDIR="$val" ;; + INCLUDEDIR) + INCLUDEDIR="$val" ;; + *) + echo "$0: invalid key: $key" 1>&2 + exit 1 + esac +done + + +#---------------------------------------------------------------------- +# These are the values that will be pushed into config.h after we test +# for whether they're supported or not. +# Each of these must have a runtest(), below. +# Please sort by alpha, for clarity. +# You WANT to change this. +#---------------------------------------------------------------------- + +HAVE_ARC4RANDOM= +HAVE_CAPSICUM= +HAVE_ERR= +HAVE_EXPLICIT_BZERO= +HAVE_GETPROGNAME= +HAVE_INFTIM= +HAVE_MD5= +HAVE_MEMMEM= +HAVE_MEMRCHR= +HAVE_MEMSET_S= +HAVE_PATH_MAX= +HAVE_PLEDGE= +HAVE_PROGRAM_INVOCATION_SHORT_NAME= +HAVE_REALLOCARRAY= +HAVE_RECALLOCARRAY= +HAVE_SANDBOX_INIT= +HAVE_SECCOMP_FILTER= +HAVE_SOCK_NONBLOCK= +HAVE_STRLCAT= +HAVE_STRLCPY= +HAVE_STRTONUM= +HAVE_SYSTRACE= +HAVE___PROGNAME= + +#---------------------------------------------------------------------- +# Allow configure.local to override all variables, default settings, +# command-line arguments, and tested features, above. +# You PROBABLY DO NOT want to change this. +#---------------------------------------------------------------------- + +if [ -r ./configure.local ]; then + echo "configure.local: reading..." 1>&2 + echo "configure.local: reading..." 1>&3 + cat ./configure.local 1>&3 + . ./configure.local +else + echo "configure.local: no (fully automatic configuration)" 1>&2 + echo "configure.local: no (fully automatic configuration)" 1>&3 +fi + +echo 1>&3 + +#---------------------------------------------------------------------- +# Infrastructure for running tests. +# These consists of a series of functions that will attempt to run the +# given test file and record its exit into a HAVE_xxx variable. +# You DO NOT want to change this. +#---------------------------------------------------------------------- + +COMP="${CC} ${CFLAGS} ${CPPFLAGS} -Wno-unused -Werror" + +# Check whether this HAVE_ setting is manually overridden. +# If yes, use the override, if no, do not decide anything yet. +# Arguments: lower-case test name, manual value + +ismanual() { + [ -z "${3}" ] && return 1 + echo "${1}: manual (HAVE_${2}=${3})" 1>&2 + echo "${1}: manual (HAVE_${2}=${3})" 1>&3 + echo 1>&3 + return 0 } -cat config.h.pre -runtest arc4random ARC4RANDOM "" -runtest capsicum CAPSICUM "" -runtest memmem MEMMEM "" -runtest pledge PLEDGE "" -runtest reallocarray REALLOCARRAY "" -runtest sandbox_init SANDBOX_INIT "" -runtest seccomp-filter SECCOMP_FILTER "" -runtest strlcat STRLCAT "" -runtest strlcpy STRLCPY "" -runtest strtonum STRTONUM "" -runtest systrace SYSTRACE "" -runtest zlib ZLIB "-lz" -arch=`uname -m 2>/dev/null || echo unknown` -case "$arch" in -x86_64) - echo "#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_X86_64" - ;; -i*86) - echo "#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_I386" - ;; -arm*) - echo "#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARM" - ;; -esac -cat config.h.post +# Run a single autoconfiguration test. +# In case of success, enable the feature. +# In case of failure, do not decide anything yet. +# Arguments: lower-case test name, upper-case test name, additional +# CFLAGS, additional LIBS. + +singletest() { + cat 1>&3 << __HEREDOC__ +${1}: testing... +${COMP} -DTEST_${2} ${3} -o test-${1} tests.c ${4} +__HEREDOC__ + + if ${COMP} -DTEST_${2} ${3} -o "test-${1}" tests.c ${4} 1>&3 2>&3; then + echo "${1}: ${CC} succeeded" 1>&3 + else + echo "${1}: ${CC} failed with $?" 1>&3 + echo 1>&3 + return 1 + fi + + if ./test-${1} 1>&3 2>&3; then + echo "${1}: yes" 1>&2 + echo "${1}: yes" 1>&3 + echo 1>&3 + eval HAVE_${2}=1 + rm "test-${1}" + return 0 + else + echo "${1}: execution failed with $?" 1>&3 + echo 1>&3 + rm "test-${1}" + return 1 + fi +} + +# Run a complete autoconfiguration test, including the check for +# a manual override and disabling the feature on failure. +# Arguments: lower case name, upper case name, additional CFLAGS + +runtest() { + eval _manual=\${HAVE_${2}} + ismanual "${1}" "${2}" "${_manual}" && return 0 + singletest "${1}" "${2}" "${3}" "${4}" "${test}" && return 0 + echo "${1}: no" 1>&2 + eval HAVE_${2}=0 + return 1 +} + +#---------------------------------------------------------------------- +# Begin running the tests themselves. +# All of your tests must be defined here. +# Please sort as the HAVE_xxxx values were defined. +# You WANT to change this. +#---------------------------------------------------------------------- + +runtest arc4random ARC4RANDOM || true +runtest capsicum CAPSICUM || true +runtest err ERR || true +runtest explicit_bzero EXPLICIT_BZERO || true +runtest getprogname GETPROGNAME || true +runtest INFTIM INFTIM || true +runtest md5 MD5 || true +runtest memmem MEMMEM || true +runtest memrchr MEMRCHR || true +runtest memset_s MEMSET_S || true +runtest PATH_MAX PATH_MAX || true +runtest pledge PLEDGE || true +runtest program_invocation_short_name PROGRAM_INVOCATION_SHORT_NAME || true +runtest reallocarray REALLOCARRAY || true +runtest recallocarray RECALLOCARRAY || true +runtest sandbox_init SANDBOX_INIT "-Wno-deprecated" || true +runtest seccomp-filter SECCOMP_FILTER || true +runtest SOCK_NONBLOCK SOCK_NONBLOCK || true +runtest strlcat STRLCAT || true +runtest strlcpy STRLCPY || true +runtest strtonum STRTONUM || true +runtest systrace SYSTRACE || true +runtest zlib ZLIB "" "-lz" || true +runtest __progname __PROGNAME || true + +#---------------------------------------------------------------------- +# Output writing: generate the config.h file. +# This file contains all of the HAVE_xxxx variables necessary for +# compiling your source. +# You must include "config.h" BEFORE any other variables. +# You WANT to change this. +#---------------------------------------------------------------------- + +exec > config.h + +# Start with prologue. + +cat << __HEREDOC__ +#ifdef __cplusplus +#error "Do not use C++: this is a C application." +#endif +#if !defined(__GNUC__) || (__GNUC__ < 4) +#define __attribute__(x) +#endif +#if defined(__linux__) || defined(__MINT__) +#define _GNU_SOURCE /* See test-*.c what needs this. */ +#endif +#if !defined(__BEGIN_DECLS) +# define __BEGIN_DECLS +#endif +#if !defined(__END_DECLS) +# define __END_DECLS +#endif +__HEREDOC__ + +# For the function declaration variables... + +[ ${HAVE_MD5} -eq 0 -o \ + ${HAVE_REALLOCARRAY} -eq 0 -o \ + ${HAVE_RECALLOCARRAY} -eq 0 -o \ + ${HAVE_STRLCAT} -eq 0 -o \ + ${HAVE_STRLCPY} -eq 0 ] \ + && echo "#include " + +# Now we handle our HAVE_xxxx values. +# Most will just be defined as 0 or 1. + +[ ${HAVE_PATH_MAX} -eq 0 ] \ + && echo "#define PATH_MAX 4096" + +cat << __HEREDOC__ +#define HAVE_ARC4RANDOM ${HAVE_ARC4RANDOM} +#define HAVE_CAPSICUM ${HAVE_CAPSICUM} +#define HAVE_ERR ${HAVE_ERR} +#define HAVE_EXPLICIT_BZERO ${HAVE_EXPLICIT_BZERO} +#define HAVE_GETPROGNAME ${HAVE_GETPROGNAME} +#define HAVE_INFTIM ${HAVE_INFTIM} +#define HAVE_MD5 ${HAVE_MD5} +#define HAVE_MEMMEM ${HAVE_MEMMEM} +#define HAVE_MEMRCHR ${HAVE_MEMRCHR} +#define HAVE_MEMSET_S ${HAVE_MEMSET_S} +#define HAVE_PATH_MAX ${HAVE_PATH_MAX} +#define HAVE_PLEDGE ${HAVE_PLEDGE} +#define HAVE_PROGRAM_INVOCATION_SHORT_NAME ${HAVE_PROGRAM_INVOCATION_SHORT_NAME} +#define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY} +#define HAVE_RECALLOCARRAY ${HAVE_RECALLOCARRAY} +#define HAVE_SANDBOX_INIT ${HAVE_SANDBOX_INIT} +#define HAVE_SECCOMP_FILTER ${HAVE_SECCOMP_FILTER} +#define HAVE_SOCK_NONBLOCK ${HAVE_SOCK_NONBLOCK} +#define HAVE_STRLCAT ${HAVE_STRLCAT} +#define HAVE_STRLCPY ${HAVE_STRLCPY} +#define HAVE_STRTONUM ${HAVE_STRTONUM} +#define HAVE_SYSTRACE ${HAVE_SYSTRACE} +#define HAVE___PROGNAME ${HAVE___PROGNAME} +__HEREDOC__ + +# Now we do our function declarations for missing functions. + +if [ ${HAVE_ERR} -eq 0 ]; then + echo "extern void err(int, const char *, ...);" + echo "extern void errx(int, const char *, ...);" + echo "extern void warn(const char *, ...);" + echo "extern void warnx(const char *, ...);" +fi + +if [ ${HAVE_MD5} -eq 0 ]; then + echo "#define MD5_BLOCK_LENGTH 64" + echo "#define MD5_DIGEST_LENGTH 16" + echo "#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)" + cat </dev/null || echo unknown` + case "$arch" in + x86_64) + echo "#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_X86_64" + ;; + i*86) + echo "#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_I386" + ;; + arm*) + echo "#define SECCOMP_AUDIT_ARCH AUDIT_ARCH_ARM" + ;; + esac +fi + +if [ ${HAVE_EXPLICIT_BZERO} -eq 0 ]; then + echo "extern void explicit_bzero(void *, size_t);" +fi + +if [ ${HAVE_MEMMEM} -eq 0 ]; then + echo "void *memmem(const void *, size_t, const void *, size_t);" +fi + +if [ ${HAVE_MEMRCHR} -eq 0 ]; then + echo "void *memrchr(const void *b, int, size_t);" +fi + +if [ ${HAVE_GETPROGNAME} -eq 0 ]; then + echo "extern const char *getprogname(void);" +fi + +if [ ${HAVE_REALLOCARRAY} -eq 0 ]; then + echo "extern void *reallocarray(void *, size_t, size_t);" +fi + +if [ ${HAVE_RECALLOCARRAY} -eq 0 ]; then + echo "extern void *recallocarray(void *, size_t, size_t, size_t);" +fi + +if [ ${HAVE_STRLCAT} -eq 0 ]; then + echo "extern size_t strlcat(char *, const char *, size_t);" +fi + +if [ ${HAVE_STRLCPY} -eq 0 ]; then + echo "extern size_t strlcpy(char *, const char *, size_t);" +fi + +if [ ${HAVE_STRTONUM} -eq 0 ]; then + echo "extern long long strtonum(const char *, long long, long long, const char **);" +fi + +echo "config.h: written" 1>&2 +echo "config.h: written" 1>&3 + +#---------------------------------------------------------------------- +# Now we go to generate our Makefile.configure. +# This file is simply a bunch of Makefile variables. +# They'll work in both GNUmakefile and BSDmakefile. +# You MIGHT want to change this. +#---------------------------------------------------------------------- + +exec > Makefile.configure + +[ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin" +[ -z "${SBINDIR}" ] && SBINDIR="${PREFIX}/sbin" +[ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include" +[ -z "${LIBDIR}" ] && LIBDIR="${PREFIX}/lib" +[ -z "${MANDIR}" ] && MANDIR="${PREFIX}/man" + +[ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555" +[ -z "${INSTALL_LIB}" ] && INSTALL_LIB="${INSTALL} -m 0444" +[ -z "${INSTALL_MAN}" ] && INSTALL_MAN="${INSTALL} -m 0444" +[ -z "${INSTALL_DATA}" ] && INSTALL_DATA="${INSTALL} -m 0444" + +cat << __HEREDOC__ +CC = ${CC} +CFLAGS = ${CFLAGS} +CPPFLAGS = ${CPPFLAGS} +LDADD = ${LDADD} +LDFLAGS = ${LDFLAGS} +STATIC = ${STATIC} +PREFIX = ${PREFIX} +BINDIR = ${BINDIR} +SBINDIR = ${SBINDIR} +INCLUDEDIR = ${INCLUDEDIR} +LIBDIR = ${LIBDIR} +MANDIR = ${MANDIR} +INSTALL = ${INSTALL} +INSTALL_PROGRAM = ${INSTALL_PROGRAM} +INSTALL_LIB = ${INSTALL_LIB} +INSTALL_MAN = ${INSTALL_MAN} +INSTALL_DATA = ${INSTALL_DATA} +__HEREDOC__ + +echo "Makefile.configure: written" 1>&2 +echo "Makefile.configure: written" 1>&3 exit 0 diff --git a/datetime.c b/datetime.c index 783b9e0..99bcb4d 100644 --- a/datetime.c +++ b/datetime.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include #include diff --git a/fcgi.c b/fcgi.c index e083491..cf98c4a 100644 --- a/fcgi.c +++ b/fcgi.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include #include diff --git a/functions.xml b/functions.xml index f1fd332..878d7e2 100644 --- a/functions.xml +++ b/functions.xml @@ -5,7 +5,7 @@ kcgi | minimal CGI and FastCGI library for C - + diff --git a/httpauth.c b/httpauth.c index 64d26ef..3d24124 100644 --- a/httpauth.c +++ b/httpauth.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include #include diff --git a/index.css b/index.css index 2ccb28c..64207ed 100644 --- a/index.css +++ b/index.css @@ -2,12 +2,13 @@ html, body { margin: 0; padding: 0; } body { color: #333; font-family: "Alegreya sans", Calibri, Candara, Segoe, Segoe UI, Optima, Arial, sans-serif; - font-weight: 300; + font-weight: 400; font-size: 13pt; line-height: 17pt; } code, pre { font-size: 11pt; } a { text-decoration: none; color: blue; } +strong, b { font-weight: 700; } body > header { box-shadow: 0 1px 4px #888; background-color: #333; padding: 5em 20% 1ex 20%; @@ -32,12 +33,12 @@ body > header nav .version { border-right: thin solid silver; #version time, #version span.version { font-style: normal; } #version .content > div + div { margin-top: 0.5em; } -#version nav .title { font-weight: 400; +#version nav .title { font-weight: 500; margin-bottom: 1em; } h1 { font-size: 28pt; margin: 0; line-height: 34pt; - font-weight: normal; } + font-weight: 400; } #breadcrumbs { font-size: 14pt; } .nm, .file { font-style: italic; } h1 .nm { text-shadow: 1px 1px #666; @@ -70,10 +71,10 @@ footer a { color: #000; } footer span { border-left: thin solid #ccc; padding-left: 1ex; } body > section h2 { font-size: x-large; - font-weight: 400; + font-weight: 500; color: #333; } body > section h3 { font-size: large; - font-weight: bolder; + font-weight: 500; margin-bottom: 0.25ex; color: #333; } body > section { padding: 0.5em 20%; @@ -82,7 +83,7 @@ figure figcaption { margin: 0; } figure { margin: 0; text-align: center; color: #444; } -figcaption span { font-weight: 400; } +figcaption span { font-weight: 500; } dd { margin: 0 0 1em 0; } body > header nav { overflow: hidden; } body > header nav li + li { margin-top: 1.5em; } @@ -97,7 +98,7 @@ pre.prettyprint ol.linenums > li { list-style-type: decimal; } footer { padding: 1ex; margin-top: 1em; margin-bottom: 1em; } -.flag { font-weight: 400; } +.flag { font-weight: 500; } @media only screen and (max-width: 768px), only screen and (max-device-width: 768px) { h1 { font-size: 15pt; } diff --git a/index.xml b/index.xml index 706ce5c..c0c805f 100644 --- a/index.xml +++ b/index.xml @@ -6,7 +6,7 @@ kcgi | minimal CGI and FastCGI library for C - + diff --git a/kcgi.c b/kcgi.c index 10ae585..8627ae4 100644 --- a/kcgi.c +++ b/kcgi.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include #include @@ -900,7 +898,7 @@ khttp_body_compress(struct kreq *req, int comp) } /* Only work with compression if we support it... */ -#ifdef HAVE_ZLIB +#if HAVE_ZLIB /* * Enable compression if the function argument is zero or if * it's >0 and the request headers have been set for it. diff --git a/kcgihtml.c b/kcgihtml.c index dfbb636..8aa14ed 100644 --- a/kcgihtml.c +++ b/kcgihtml.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include #include diff --git a/kcgijson.c b/kcgijson.c index af588d3..d43a1d4 100644 --- a/kcgijson.c +++ b/kcgijson.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include #include diff --git a/kcgiregress.c b/kcgiregress.c index 2cfbdd3..6e3d91f 100644 --- a/kcgiregress.c +++ b/kcgiregress.c @@ -14,9 +14,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif + #include #include #include diff --git a/kcgixml.c b/kcgixml.c index b841387..d08a5d4 100644 --- a/kcgixml.c +++ b/kcgixml.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include #include diff --git a/kfcgi.c b/kfcgi.c index 4a9e3be..be59218 100644 --- a/kfcgi.c +++ b/kfcgi.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include #include diff --git a/logging.c b/logging.c index 86cd53e..6cf4bdb 100644 --- a/logging.c +++ b/logging.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include #include diff --git a/md5.c b/md5.c deleted file mode 100644 index 40af54c..0000000 --- a/md5.c +++ /dev/null @@ -1,248 +0,0 @@ -/* $OpenBSD$ */ - -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include - -#include "md5.h" - -#define PUT_64BIT_LE(cp, value) do { \ - (cp)[7] = (value) >> 56; \ - (cp)[6] = (value) >> 48; \ - (cp)[5] = (value) >> 40; \ - (cp)[4] = (value) >> 32; \ - (cp)[3] = (value) >> 24; \ - (cp)[2] = (value) >> 16; \ - (cp)[1] = (value) >> 8; \ - (cp)[0] = (value); } while (0) - -#define PUT_32BIT_LE(cp, value) do { \ - (cp)[3] = (value) >> 24; \ - (cp)[2] = (value) >> 16; \ - (cp)[1] = (value) >> 8; \ - (cp)[0] = (value); } while (0) - -static u_int8_t PADDING[MD5_BLOCK_LENGTH] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/* - * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious - * initialization constants. - */ -void -MD5Init(MD5_CTX *ctx) -{ - ctx->count = 0; - ctx->state[0] = 0x67452301; - ctx->state[1] = 0xefcdab89; - ctx->state[2] = 0x98badcfe; - ctx->state[3] = 0x10325476; -} - -/* - * Update context to reflect the concatenation of another buffer full - * of bytes. - */ -void -MD5Update(MD5_CTX *ctx, const void *inputptr, size_t len) -{ - const uint8_t *input = inputptr; - size_t have, need; - - /* Check how many bytes we already have and how many more we need. */ - have = (size_t)((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1)); - need = MD5_BLOCK_LENGTH - have; - - /* Update bitcount */ - ctx->count += (u_int64_t)len << 3; - - if (len >= need) { - if (have != 0) { - memcpy(ctx->buffer + have, input, need); - MD5Transform(ctx->state, ctx->buffer); - input += need; - len -= need; - have = 0; - } - - /* Process data in MD5_BLOCK_LENGTH-byte chunks. */ - while (len >= MD5_BLOCK_LENGTH) { - MD5Transform(ctx->state, input); - input += MD5_BLOCK_LENGTH; - len -= MD5_BLOCK_LENGTH; - } - } - - /* Handle any remaining bytes of data. */ - if (len != 0) - memcpy(ctx->buffer + have, input, len); -} - -/* - * Final wrapup - pad to 64-byte boundary with the bit pattern - * 1 0* (64-bit count of bits processed, MSB-first) - */ -void -MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx) -{ - u_int8_t count[8]; - size_t padlen; - int i; - - /* Convert count to 8 bytes in little endian order. */ - PUT_64BIT_LE(count, ctx->count); - - /* Pad out to 56 mod 64. */ - padlen = MD5_BLOCK_LENGTH - - ((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1)); - if (padlen < 1 + 8) - padlen += MD5_BLOCK_LENGTH; - MD5Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */ - MD5Update(ctx, count, 8); - - for (i = 0; i < 4; i++) - PUT_32BIT_LE(digest + i * 4, ctx->state[i]); -#ifdef __OpenBSD__ - explicit_bzero(ctx, sizeof(*ctx)); /* in case it's sensitive */ -#else - memset(ctx, 0, sizeof(*ctx)); /* in case it's sensitive */ -#endif -} - - -/* The four core functions - F1 is optimized somewhat */ - -/* #define F1(x, y, z) (x & y | ~x & z) */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -/* This is the central step in the MD5 algorithm. */ -#define MD5STEP(f, w, x, y, z, data, s) \ - ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) - -/* - * The core of the MD5 algorithm, this alters an existing MD5 hash to - * reflect the addition of 16 longwords of new data. MD5Update blocks - * the data and converts bytes into longwords for this routine. - */ -void -MD5Transform(u_int32_t state[4], const u_int8_t block[MD5_BLOCK_LENGTH]) -{ - u_int32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4]; - -#if BYTE_ORDER == LITTLE_ENDIAN - memcpy(in, block, sizeof(in)); -#else - for (a = 0; a < MD5_BLOCK_LENGTH / 4; a++) { - in[a] = (u_int32_t)( - (u_int32_t)(block[a * 4 + 0]) | - (u_int32_t)(block[a * 4 + 1]) << 8 | - (u_int32_t)(block[a * 4 + 2]) << 16 | - (u_int32_t)(block[a * 4 + 3]) << 24); - } -#endif - - a = state[0]; - b = state[1]; - c = state[2]; - d = state[3]; - - MD5STEP(F1, a, b, c, d, in[ 0] + 0xd76aa478, 7); - MD5STEP(F1, d, a, b, c, in[ 1] + 0xe8c7b756, 12); - MD5STEP(F1, c, d, a, b, in[ 2] + 0x242070db, 17); - MD5STEP(F1, b, c, d, a, in[ 3] + 0xc1bdceee, 22); - MD5STEP(F1, a, b, c, d, in[ 4] + 0xf57c0faf, 7); - MD5STEP(F1, d, a, b, c, in[ 5] + 0x4787c62a, 12); - MD5STEP(F1, c, d, a, b, in[ 6] + 0xa8304613, 17); - MD5STEP(F1, b, c, d, a, in[ 7] + 0xfd469501, 22); - MD5STEP(F1, a, b, c, d, in[ 8] + 0x698098d8, 7); - MD5STEP(F1, d, a, b, c, in[ 9] + 0x8b44f7af, 12); - MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); - MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); - MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); - MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); - MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); - MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); - - MD5STEP(F2, a, b, c, d, in[ 1] + 0xf61e2562, 5); - MD5STEP(F2, d, a, b, c, in[ 6] + 0xc040b340, 9); - MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); - MD5STEP(F2, b, c, d, a, in[ 0] + 0xe9b6c7aa, 20); - MD5STEP(F2, a, b, c, d, in[ 5] + 0xd62f105d, 5); - MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); - MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); - MD5STEP(F2, b, c, d, a, in[ 4] + 0xe7d3fbc8, 20); - MD5STEP(F2, a, b, c, d, in[ 9] + 0x21e1cde6, 5); - MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); - MD5STEP(F2, c, d, a, b, in[ 3] + 0xf4d50d87, 14); - MD5STEP(F2, b, c, d, a, in[ 8] + 0x455a14ed, 20); - MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); - MD5STEP(F2, d, a, b, c, in[ 2] + 0xfcefa3f8, 9); - MD5STEP(F2, c, d, a, b, in[ 7] + 0x676f02d9, 14); - MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - MD5STEP(F3, a, b, c, d, in[ 5] + 0xfffa3942, 4); - MD5STEP(F3, d, a, b, c, in[ 8] + 0x8771f681, 11); - MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); - MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); - MD5STEP(F3, a, b, c, d, in[ 1] + 0xa4beea44, 4); - MD5STEP(F3, d, a, b, c, in[ 4] + 0x4bdecfa9, 11); - MD5STEP(F3, c, d, a, b, in[ 7] + 0xf6bb4b60, 16); - MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); - MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); - MD5STEP(F3, d, a, b, c, in[ 0] + 0xeaa127fa, 11); - MD5STEP(F3, c, d, a, b, in[ 3] + 0xd4ef3085, 16); - MD5STEP(F3, b, c, d, a, in[ 6] + 0x04881d05, 23); - MD5STEP(F3, a, b, c, d, in[ 9] + 0xd9d4d039, 4); - MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); - MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); - MD5STEP(F3, b, c, d, a, in[2 ] + 0xc4ac5665, 23); - - MD5STEP(F4, a, b, c, d, in[ 0] + 0xf4292244, 6); - MD5STEP(F4, d, a, b, c, in[7 ] + 0x432aff97, 10); - MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); - MD5STEP(F4, b, c, d, a, in[5 ] + 0xfc93a039, 21); - MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); - MD5STEP(F4, d, a, b, c, in[3 ] + 0x8f0ccc92, 10); - MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); - MD5STEP(F4, b, c, d, a, in[1 ] + 0x85845dd1, 21); - MD5STEP(F4, a, b, c, d, in[8 ] + 0x6fa87e4f, 6); - MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); - MD5STEP(F4, c, d, a, b, in[6 ] + 0xa3014314, 15); - MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); - MD5STEP(F4, a, b, c, d, in[4 ] + 0xf7537e82, 6); - MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); - MD5STEP(F4, c, d, a, b, in[2 ] + 0x2ad7d2bb, 15); - MD5STEP(F4, b, c, d, a, in[9 ] + 0xeb86d391, 21); - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; -} diff --git a/md5.h b/md5.h deleted file mode 100644 index aa69ca5..0000000 --- a/md5.h +++ /dev/null @@ -1,43 +0,0 @@ -/* $OpenBSD$ */ - -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - */ - -#ifndef _MD5_H_ -#define _MD5_H_ - -#define MD5_BLOCK_LENGTH 64 -#define MD5_DIGEST_LENGTH 16 - -/* Silence compiler warnings. */ -#ifndef __OpenBSD__ -#define __bounded__(a, b, c) /* Nothing */ -#endif - -typedef struct MD5Context { - u_int32_t state[4]; /* state */ - u_int64_t count; /* number of bits, mod 2^64 */ - u_int8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */ -} MD5_CTX; - -__BEGIN_DECLS -void MD5Init(MD5_CTX *); -void MD5Update(MD5_CTX *, const void *, size_t) - __attribute__((__bounded__(__string__,2,3))); -void MD5Final(u_int8_t [MD5_DIGEST_LENGTH], MD5_CTX *) - __attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH))); -void MD5Transform(u_int32_t [4], const u_int8_t [MD5_BLOCK_LENGTH]) - __attribute__((__bounded__(__minbytes__,1,4))) - __attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH))); -__END_DECLS - -#endif /* _MD5_H_ */ diff --git a/output.c b/output.c index 78b7f78..51da668 100644 --- a/output.c +++ b/output.c @@ -14,9 +14,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif + #include #include @@ -28,8 +27,8 @@ #include #include #include -#ifdef HAVE_ZLIB -#include +#if HAVE_ZLIB +# include #endif #include "kcgi.h" diff --git a/parent.c b/parent.c index 3dd4aa5..517436f 100644 --- a/parent.c +++ b/parent.c @@ -14,11 +14,13 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include +#if HAVE_MD5 +# include +# include +#endif #include #include #include @@ -27,7 +29,6 @@ #include #include "kcgi.h" -#include "md5.h" #include "extern.h" /* diff --git a/regress/regress.c b/regress/regress.c index 70ff55c..54a565a 100644 --- a/regress/regress.c +++ b/regress/regress.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-abort-validator.c b/regress/test-abort-validator.c index 440b361..986cc75 100644 --- a/regress/test-abort-validator.c +++ b/regress/test-abort-validator.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-basic.c b/regress/test-basic.c index 6c7076f..3b5fbf6 100644 --- a/regress/test-basic.c +++ b/regress/test-basic.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-bigfile.c b/regress/test-bigfile.c index 0181026..268072e 100644 --- a/regress/test-bigfile.c +++ b/regress/test-bigfile.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-datetime.c b/regress/test-datetime.c index ed39f73..9903044 100644 --- a/regress/test-datetime.c +++ b/regress/test-datetime.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include diff --git a/regress/test-digest.c b/regress/test-digest.c index 1e965d3..6a1bb41 100644 --- a/regress/test-digest.c +++ b/regress/test-digest.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-fcgi-abort-validator.c b/regress/test-fcgi-abort-validator.c index 6eb355c..3265f47 100644 --- a/regress/test-fcgi-abort-validator.c +++ b/regress/test-fcgi-abort-validator.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-fcgi-bigfile.c b/regress/test-fcgi-bigfile.c index 9b9186f..30fa85d 100644 --- a/regress/test-fcgi-bigfile.c +++ b/regress/test-fcgi-bigfile.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-fcgi-file-get.c b/regress/test-fcgi-file-get.c index c21576f..88ad5bf 100644 --- a/regress/test-fcgi-file-get.c +++ b/regress/test-fcgi-file-get.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-fcgi-header-bad.c b/regress/test-fcgi-header-bad.c index d487291..b8819fa 100644 --- a/regress/test-fcgi-header-bad.c +++ b/regress/test-fcgi-header-bad.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-fcgi-header.c b/regress/test-fcgi-header.c index 48343a8..85fd4c4 100644 --- a/regress/test-fcgi-header.c +++ b/regress/test-fcgi-header.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-fcgi-path-check.c b/regress/test-fcgi-path-check.c index a59b532..c8fc611 100644 --- a/regress/test-fcgi-path-check.c +++ b/regress/test-fcgi-path-check.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-fcgi-ping.c b/regress/test-fcgi-ping.c index 791c013..fb7a0b0 100644 --- a/regress/test-fcgi-ping.c +++ b/regress/test-fcgi-ping.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-fcgi-upload.c b/regress/test-fcgi-upload.c index 3914386..9a9530a 100644 --- a/regress/test-fcgi-upload.c +++ b/regress/test-fcgi-upload.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include diff --git a/regress/test-file-get.c b/regress/test-file-get.c index 3b34d65..e3d958f 100644 --- a/regress/test-file-get.c +++ b/regress/test-file-get.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-fork.c b/regress/test-fork.c index 7706ea6..78058e7 100644 --- a/regress/test-fork.c +++ b/regress/test-fork.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include diff --git a/regress/test-gzip-bigfile.c b/regress/test-gzip-bigfile.c index ff2894d..d702ac0 100644 --- a/regress/test-gzip-bigfile.c +++ b/regress/test-gzip-bigfile.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-gzip.c b/regress/test-gzip.c index 6501ab7..07e8d30 100644 --- a/regress/test-gzip.c +++ b/regress/test-gzip.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-header-bad.c b/regress/test-header-bad.c index 7f07e90..5103f2e 100644 --- a/regress/test-header-bad.c +++ b/regress/test-header-bad.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-header.c b/regress/test-header.c index db51fd3..3141af4 100644 --- a/regress/test-header.c +++ b/regress/test-header.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-httpdate.c b/regress/test-httpdate.c index 47cfdc0..330e659 100644 --- a/regress/test-httpdate.c +++ b/regress/test-httpdate.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-nogzip.c b/regress/test-nogzip.c index 4242a57..0867397 100644 --- a/regress/test-nogzip.c +++ b/regress/test-nogzip.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-path-check.c b/regress/test-path-check.c index 347efcc..f9bc24e 100644 --- a/regress/test-path-check.c +++ b/regress/test-path-check.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-ping.c b/regress/test-ping.c index 75d985e..992c91b 100644 --- a/regress/test-ping.c +++ b/regress/test-ping.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-post.c b/regress/test-post.c index 8d9c68e..2d3e1fd 100644 --- a/regress/test-post.c +++ b/regress/test-post.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-returncode.c b/regress/test-returncode.c index 9f158ed..89e3fd2 100644 --- a/regress/test-returncode.c +++ b/regress/test-returncode.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-template.c b/regress/test-template.c index b76b3e9..670064e 100644 --- a/regress/test-template.c +++ b/regress/test-template.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include #include diff --git a/regress/test-upload.c b/regress/test-upload.c index d8743db..c361275 100644 --- a/regress/test-upload.c +++ b/regress/test-upload.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "../config.h" -#endif #include diff --git a/sandbox-capsicum.c b/sandbox-capsicum.c index 70f97f1..fc82631 100644 --- a/sandbox-capsicum.c +++ b/sandbox-capsicum.c @@ -15,11 +15,9 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif -#ifdef HAVE_CAPSICUM +#if HAVE_CAPSICUM #include #include diff --git a/sandbox-darwin.c b/sandbox-darwin.c index 504a793..f7a3bc7 100644 --- a/sandbox-darwin.c +++ b/sandbox-darwin.c @@ -14,11 +14,9 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif -#ifdef HAVE_SANDBOX_INIT +#if HAVE_SANDBOX_INIT #include diff --git a/sandbox-pledge.c b/sandbox-pledge.c index df61f5e..e256c49 100644 --- a/sandbox-pledge.c +++ b/sandbox-pledge.c @@ -14,11 +14,9 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif -#ifdef HAVE_PLEDGE +#if HAVE_PLEDGE #include diff --git a/sandbox-seccomp-filter.c b/sandbox-seccomp-filter.c index c6168da..9d4857f 100644 --- a/sandbox-seccomp-filter.c +++ b/sandbox-seccomp-filter.c @@ -14,11 +14,9 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif -#ifdef HAVE_SECCOMP_FILTER +#if HAVE_SECCOMP_FILTER #ifndef SECCOMP_AUDIT_ARCH #error Unknown seccomp arch: please contact us with your uname -m diff --git a/sandbox-systrace.c b/sandbox-systrace.c index d4b4356..cff83ff 100644 --- a/sandbox-systrace.c +++ b/sandbox-systrace.c @@ -14,11 +14,9 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif -#ifdef HAVE_SYSTRACE +#if HAVE_SYSTRACE #warning This feature is deprecated! diff --git a/sandbox.c b/sandbox.c index 4b60ca9..0606ef2 100644 --- a/sandbox.c +++ b/sandbox.c @@ -14,9 +14,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #ifndef HAVE_PLEDGE #ifndef HAVE_SYSTRACE @@ -55,18 +53,18 @@ int ksandbox_init_parent(void *arg, enum sandtype type, pid_t child) { -#if defined(HAVE_CAPSICUM) +#if HAVE_CAPSICUM return(1); -#elif defined(HAVE_SANDBOX_INIT) +#elif HAVE_SANDBOX_INIT return(1); -#elif defined(HAVE_PLEDGE) +#elif HAVE_PLEDGE return(1); -#elif defined(HAVE_SYSTRACE) +#elif HAVE_SYSTRACE if ( ! ksandbox_systrace_init_parent(arg, type, child)) { XWARNX("ksandbox_systrace_init_child"); return(0); } -#elif defined(HAVE_SECCOMP_FILTER) +#elif HAVE_SECCOMP_FILTER return(1); #endif return(1); @@ -83,18 +81,18 @@ ksandbox_alloc(void **pp) *pp = NULL; -#if defined(HAVE_CAPSICUM) +#if HAVE_CAPSICUM return(1); -#elif defined(HAVE_SANDBOX_INIT) +#elif HAVE_SANDBOX_INIT return(1); -#elif defined(HAVE_PLEDGE) +#elif HAVE_PLEDGE return(1); -#elif defined(HAVE_SYSTRACE) +#elif HAVE_SYSTRACE if (NULL == (*pp = (ksandbox_systrace_alloc()))) { XWARNX("ksandbox_systrace_alloc"); return(0); } -#elif defined(HAVE_SECCOMP_FILTER) +#elif HAVE_SECCOMP_FILTER return(1); #endif return(1); @@ -115,15 +113,15 @@ void ksandbox_close(void *arg) { -#if defined(HAVE_CAPSICUM) +#if HAVE_CAPSICUM return; -#elif defined(HAVE_SANDBOX_INIT) +#elif HAVE_SANDBOX_INIT return; -#elif defined(HAVE_PLEDGE) +#elif HAVE_PLEDGE return; -#elif defined(HAVE_SYSTRACE) +#elif HAVE_SYSTRACE ksandbox_systrace_close(arg); -#elif defined(HAVE_SECCOMP_FILTER) +#elif HAVE_SECCOMP_FILTER return; #endif } @@ -148,28 +146,28 @@ ksandbox_init_child(void *arg, int fdfiled, int fdaccept) { -#if defined(HAVE_CAPSICUM) +#if HAVE_CAPSICUM if ( ! ksandbox_capsicum_init_child(arg, type, fd1, fd2, fdfiled, fdaccept)) { XWARNX("ksandbox_capsicum_init_child"); return(0); } -#elif defined(HAVE_SANDBOX_INIT) +#elif HAVE_SANDBOX_INIT if ( ! ksandbox_darwin_init_child(arg, type)) { XWARNX("ksandbox_darwin_init_child"); return(0); } -#elif defined(HAVE_PLEDGE) +#elif HAVE_PLEDGE if ( ! ksandbox_pledge_init_child(arg, type)) { XWARNX("ksandbox_pledge_init_child"); return(0); } -#elif defined(HAVE_SYSTRACE) +#elif HAVE_SYSTRACE if ( ! ksandbox_systrace_init_child(arg, type)) { XWARNX("ksandbox_systrace_init_child"); return(0); } -#elif defined(HAVE_SECCOMP_FILTER) +#elif HAVE_SECCOMP_FILTER if ( ! ksandbox_seccomp_init_child(arg, type)) { XWARNX("ksandbox_seccomp_init_child"); return(0); diff --git a/test-arc4random.c b/test-arc4random.c deleted file mode 100644 index 10b6e0b..0000000 --- a/test-arc4random.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -int -main(void) -{ - volatile int foo = arc4random() % 2; - - if (foo > 0) - return(0); - - return(foo); -} diff --git a/test-capsicum.c b/test-capsicum.c deleted file mode 100644 index 478b63c..0000000 --- a/test-capsicum.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int -main(void) -{ - cap_enter(); - return(0); -} diff --git a/test-memmem.c b/test-memmem.c deleted file mode 100644 index 3dbea3c..0000000 --- a/test-memmem.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int -main(void) -{ - char *a = memmem("hello, world", strlen("hello, world"), "world", strlen("world")); - return(NULL == a); -} diff --git a/test-pledge.c b/test-pledge.c deleted file mode 100644 index 23459f0..0000000 --- a/test-pledge.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include - -int -main(void) -{ - if (-1 == pledge("stdio", NULL)) { - perror("pledge"); - return(1); - } - return(0); -} diff --git a/test-reallocarray.c b/test-reallocarray.c deleted file mode 100644 index d30e0ae..0000000 --- a/test-reallocarray.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int -main(void) -{ - char *a = reallocarray(NULL, 0, 0); - return(NULL == a); -} diff --git a/test-sandbox_init.c b/test-sandbox_init.c deleted file mode 100644 index 1caada6..0000000 --- a/test-sandbox_init.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -int -main(void) -{ - char *er; - - sandbox_init("kSBXProfilePureComputation", SANDBOX_NAMED, &er); - sandbox_free_error(er); - return(0); -} diff --git a/test-seccomp-filter.c b/test-seccomp-filter.c deleted file mode 100644 index 84beda5..0000000 --- a/test-seccomp-filter.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include - -int -main(void) -{ - - prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, 0); - return(EFAULT == errno ? 0 : 1); -} diff --git a/test-strlcat.c b/test-strlcat.c deleted file mode 100644 index 9171b35..0000000 --- a/test-strlcat.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -int -main(void) -{ - char a[] = "foo"; - char b[1024]; - b[0] = '\0'; - strlcat(b, a, sizeof(b)); - return(0); -} diff --git a/test-strlcpy.c b/test-strlcpy.c deleted file mode 100644 index 6f50078..0000000 --- a/test-strlcpy.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -int -main(void) -{ - char a[] = "foo"; - char b[1024]; - b[0] = '\0'; - strlcpy(b, a, sizeof(b)); - return(0); -} diff --git a/test-strtonum.c b/test-strtonum.c deleted file mode 100644 index 9880766..0000000 --- a/test-strtonum.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int -main(void) -{ - const char *ep; - int a = strtonum("20", 0, 30, &ep); - return(a != 20); -} diff --git a/test-systrace.c b/test-systrace.c deleted file mode 100644 index c723bca..0000000 --- a/test-systrace.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -#include - -int -main(void) -{ - - return(0); -} diff --git a/test-zlib.c b/test-zlib.c deleted file mode 100644 index fafe2dc..0000000 --- a/test-zlib.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -int -main(void) -{ - gzFile gz; - - if (NULL == (gz = gzopen("/dev/null", "w"))) - return(1); - gzputs(gz, "foo"); - gzclose(gz); - return(0); -} diff --git a/tests.c b/tests.c new file mode 100644 index 0000000..b3fbb87 --- /dev/null +++ b/tests.c @@ -0,0 +1,354 @@ +#if TEST___PROGNAME +int +main(void) +{ + extern char *__progname; + + return !__progname; +} +#endif /* TEST___PROGNAME */ +#if TEST_ARC4RANDOM +#include + +int +main(void) +{ + return (arc4random() + 1) ? 0 : 1; +} +#endif /* TEST_ARC4RANDOM */ +#if TEST_CAPSICUM +#include + +int +main(void) +{ + cap_enter(); + return(0); +} +#endif /* TEST_CAPSICUM */ +#if TEST_ERR +/* + * Copyright (c) 2015 Ingo Schwarze + * + * 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. + */ + +#include + +int +main(void) +{ + warnx("%d. warnx", 1); + warn("%d. warn", 2); + err(0, "%d. err", 3); + /* NOTREACHED */ + return 1; +} +#endif /* TEST_ERR */ +#if TEST_EXPLICIT_BZERO +#include + +int +main(void) +{ + char foo[10]; + + explicit_bzero(foo, sizeof(foo)); + return(0); +} +#endif /* TEST_EXPLICIT_BZERO */ +#if TEST_GETPROGNAME +#include + +int +main(void) +{ + const char * progname; + + progname = getprogname(); + return progname == NULL; +} +#endif /* TEST_GETPROGNAME */ +#if TEST_INFTIM +/* + * Linux doesn't (always?) have this. + */ + +#include +#include + +int +main(void) +{ + printf("INFTIM is defined to be %ld\n", (long)INFTIM); + return 0; +} +#endif /* TEST_INFTIM */ +#if TEST_MD5 +#include +#include + +int main(void) +{ + MD5_CTX ctx; + + MD5Init(&ctx); + MD5Update(&ctx, "abcd", 4); + + return 0; +} +#endif /* TEST_MD5 */ +#if TEST_MEMMEM +#define _GNU_SOURCE +#include + +int +main(void) +{ + char *a = memmem("hello, world", strlen("hello, world"), "world", strlen("world")); + return(NULL == a); +} +#endif /* TEST_MEMMEM */ +#if TEST_MEMRCHR +#if defined(__linux__) || defined(__MINT__) +#define _GNU_SOURCE /* See test-*.c what needs this. */ +#endif +#include + +int +main(void) +{ + const char *buf = "abcdef"; + void *res; + + res = memrchr(buf, 'a', strlen(buf)); + return(NULL == res ? 1 : 0); +} +#endif /* TEST_MEMRCHR */ +#if TEST_MEMSET_S +#include + +int main(void) +{ + char buf[10]; + memset_s(buf, 0, 'c', sizeof(buf)); + return 0; +} +#endif /* TEST_MEMSET_S */ +#if TEST_PATH_MAX +/* + * POSIX allows PATH_MAX to not be defined, see + * http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html; + * the GNU Hurd is an example of a system not having it. + * + * Arguably, it would be better to test sysconf(_SC_PATH_MAX), + * but since the individual *.c files include "config.h" before + * , overriding an excessive value of PATH_MAX from + * "config.h" is impossible anyway, so for now, the simplest + * fix is to provide a value only on systems not having any. + * So far, we encountered no system defining PATH_MAX to an + * impractically large value, even though POSIX explicitly + * allows that. + * + * The real fix would be to replace all static buffers of size + * PATH_MAX by dynamically allocated buffers. But that is + * somewhat intrusive because it touches several files and + * because it requires changing struct mlink in mandocdb.c. + * So i'm postponing that for now. + */ + +#include +#include + +int +main(void) +{ + printf("PATH_MAX is defined to be %ld\n", (long)PATH_MAX); + return 0; +} +#endif /* TEST_PATH_MAX */ +#if TEST_PLEDGE +#include + +int +main(void) +{ + return !!pledge("stdio", NULL); +} +#endif /* TEST_PLEDGE */ +#if TEST_PROGRAM_INVOCATION_SHORT_NAME +#define _GNU_SOURCE /* See feature_test_macros(7) */ +#include + +int +main(void) +{ + + return !program_invocation_short_name; +} +#endif /* TEST_PROGRAM_INVOCATION_SHORT_NAME */ +#if TEST_REALLOCARRAY +#include + +int +main(void) +{ + return !reallocarray(NULL, 2, 2); +} +#endif /* TEST_REALLOCARRAY */ +#if TEST_RECALLOCARRAY +#include + +int +main(void) +{ + return !recallocarray(NULL, 0, 2, 2); +} +#endif /* TEST_RECALLOCARRAY */ +#if TEST_SANDBOX_INIT +#include + +int +main(void) +{ + char *ep; + int rc; + + rc = sandbox_init(kSBXProfileNoInternet, SANDBOX_NAMED, &ep); + if (-1 == rc) + sandbox_free_error(ep); + return(-1 == rc); +} +#endif /* TEST_SANDBOX_INIT */ +#if TEST_SECCOMP_FILTER +#include +#include +#include + +int +main(void) +{ + + prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, 0); + return(EFAULT == errno ? 0 : 1); +} +#endif /* TEST_SECCOMP_FILTER */ +#if TEST_SOCK_NONBLOCK +/* + * Linux doesn't (always?) have this. + */ + +#include + +int +main(void) +{ + int fd[2]; + socketpair(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0, fd); + return 0; +} +#endif /* TEST_SOCK_NONBLOCK */ +#if TEST_STRLCAT +#include + +int +main(void) +{ + char buf[3] = "a"; + return ! (strlcat(buf, "b", sizeof(buf)) == 2 && + buf[0] == 'a' && buf[1] == 'b' && buf[2] == '\0'); +} +#endif /* TEST_STRLCAT */ +#if TEST_STRLCPY +#include + +int +main(void) +{ + char buf[2] = ""; + return ! (strlcpy(buf, "a", sizeof(buf)) == 1 && + buf[0] == 'a' && buf[1] == '\0'); +} +#endif /* TEST_STRLCPY */ +#if TEST_STRTONUM +/* + * Copyright (c) 2015 Ingo Schwarze + * + * 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. + */ + +#include + +int +main(void) +{ + const char *errstr; + + if (strtonum("1", 0, 2, &errstr) != 1) + return 1; + if (errstr != NULL) + return 2; + if (strtonum("1x", 0, 2, &errstr) != 0) + return 3; + if (errstr == NULL) + return 4; + if (strtonum("2", 0, 1, &errstr) != 0) + return 5; + if (errstr == NULL) + return 6; + if (strtonum("0", 1, 2, &errstr) != 0) + return 7; + if (errstr == NULL) + return 8; + return 0; +} +#endif /* TEST_STRTONUM */ +#if TEST_SYSTRACE +#include +#include + +#include + +int +main(void) +{ + + return(0); +} +#endif /* TEST_SYSTRACE */ +#if TEST_ZLIB +#include +#include + +int +main(void) +{ + gzFile gz; + + if (NULL == (gz = gzopen("/dev/null", "w"))) + return(1); + gzputs(gz, "foo"); + gzclose(gz); + return(0); +} +#endif /* TEST_ZLIB */ diff --git a/tutorial.css b/tutorial.css index 652238b..74ea026 100644 --- a/tutorial.css +++ b/tutorial.css @@ -2,12 +2,13 @@ html, body { margin: 0; padding: 0; } body { color: #333; font-family: "Alegreya sans", Calibri, Candara, Segoe, Segoe UI, Optima, Arial, sans-serif; - font-weight: 300; + font-weight: 400; font-size: 13pt; line-height: 17pt; } code, pre { font-size: 11pt; } a { text-decoration: none; color: blue; } +strong, b { font-weight: 700; } body > header { box-shadow: 0 1px 4px #888; background-color: #333; padding: 2em 20% 1ex 20%; @@ -26,7 +27,7 @@ body > header nav .version { border-right: thin solid silver; h1 { font-size: 24pt; margin: 0; margin-bottom: 8pt; - font-weight: normal; } + font-weight: 400; } .nm, .file { font-style: italic; } h1 .nm { text-shadow: 1px 1px #666; font-style: inherit; } @@ -39,7 +40,7 @@ footer a { color: #000; } footer span { border-left: thin solid #ccc; padding-left: 1ex; } article h2 { font-size: x-large; - font-weight: 400; + font-weight: 500; color: #333; } article h3 { font-size: large; color: #333; } @@ -57,13 +58,13 @@ article[data-sblg-article] img { width: 100%; figure { margin: 0; text-align: center; color: #444; } -figcaption span { font-weight: 400; } +figcaption span { font-weight: 500; } dd { margin: 0 0 1em 0; } #permlink { color: #888; margin-top: 1em; } .sample { text-align: left; } body > header nav { overflow: hidden; } -body > header nav .title { font-weight: 400; +body > header nav .title { font-weight: 500; margin-bottom: 0.5em; } body > header nav li + li { margin-top: 1.5em; } pre.prettyprint { border: none; diff --git a/tutorial.xml b/tutorial.xml index 46e343f..7bb329f 100644 --- a/tutorial.xml +++ b/tutorial.xml @@ -6,7 +6,7 @@ kcgi | ${sblg-titletext} - + diff --git a/wrappers.c b/wrappers.c index 4f92c2f..5bea2c1 100644 --- a/wrappers.c +++ b/wrappers.c @@ -14,9 +14,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif + #include #include #include