aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2017-03-06 19:26:08 +0100
committerDuncaen <mail@duncano.de>2017-03-06 20:34:37 +0100
commitb43c7485a22fdeb10355b441650503e1461d9ae0 (patch)
tree77bf47b7928159ae6f8790c599cc3e938a03a59e
parent9b83fa671caf8c9825b3d8b5ee900161060445b4 (diff)
downloadlobase-b43c7485a22fdeb10355b441650503e1461d9ae0.tar.gz
lib/libopenbsd: moved into lib subdir
-rw-r--r--Makefile2
-rw-r--r--README1
-rw-r--r--lib/Makefile2
-rw-r--r--lib/libopenbsd/Makefile70
-rw-r--r--lib/libopenbsd/base64.c (renamed from libopenbsd/base64.c)0
-rw-r--r--lib/libopenbsd/chacha.h (renamed from libopenbsd/chacha.h)0
-rw-r--r--lib/libopenbsd/closefrom.c (renamed from libopenbsd/closefrom.c)0
-rw-r--r--lib/libopenbsd/config.mk.in (renamed from libopenbsd/config.mk.in)0
-rw-r--r--lib/libopenbsd/crypt/arc4random.c (renamed from libopenbsd/crypt/arc4random.c)0
-rw-r--r--lib/libopenbsd/crypt/arc4random.h (renamed from libopenbsd/crypt/arc4random.h)0
-rw-r--r--lib/libopenbsd/crypt/arc4random_linux.h (renamed from libopenbsd/crypt/arc4random_linux.h)0
-rw-r--r--lib/libopenbsd/crypt/arc4random_uniform.c (renamed from libopenbsd/crypt/arc4random_uniform.c)0
-rw-r--r--lib/libopenbsd/crypt/blowfish.3 (renamed from libopenbsd/crypt/blowfish.3)0
-rw-r--r--lib/libopenbsd/crypt/blowfish.c (renamed from libopenbsd/crypt/blowfish.c)0
-rw-r--r--lib/libopenbsd/crypt/chacha-merged.c (renamed from libopenbsd/crypt/chacha-merged.c)0
-rw-r--r--lib/libopenbsd/crypt/chacha.c (renamed from libopenbsd/crypt/chacha.c)0
-rw-r--r--lib/libopenbsd/crypt/chacha_private.h (renamed from libopenbsd/crypt/chacha_private.h)0
-rw-r--r--lib/libopenbsd/gen/errc.c (renamed from libopenbsd/errc.c)0
-rw-r--r--lib/libopenbsd/gen/fts.3 (renamed from libopenbsd/fts.3)0
-rw-r--r--lib/libopenbsd/gen/fts.c (renamed from libopenbsd/fts.c)0
-rw-r--r--lib/libopenbsd/gen/fts.h (renamed from libopenbsd/fts.h)0
-rw-r--r--lib/libopenbsd/gen/setmode.3 (renamed from libopenbsd/setmode.3)0
-rw-r--r--lib/libopenbsd/gen/setmode.c (renamed from libopenbsd/setmode.c)0
-rw-r--r--lib/libopenbsd/gen/verrc.c (renamed from libopenbsd/verrc.c)0
-rw-r--r--lib/libopenbsd/gen/vwarnc.c (renamed from libopenbsd/vwarnc.c)0
-rw-r--r--lib/libopenbsd/gen/warnc.c (renamed from libopenbsd/warnc.c)0
-rw-r--r--lib/libopenbsd/getbsize.3 (renamed from libopenbsd/getbsize.3)0
-rw-r--r--lib/libopenbsd/getbsize.c (renamed from libopenbsd/getbsize.c)0
-rw-r--r--lib/libopenbsd/getentropy_linux.c (renamed from libopenbsd/getentropy_linux.c)0
-rwxr-xr-xlib/libopenbsd/getfsstat (renamed from libopenbsd/getfsstat)bin11024 -> 11024 bytes
-rw-r--r--lib/libopenbsd/getfsstat.2 (renamed from libopenbsd/getfsstat.2)0
-rw-r--r--lib/libopenbsd/getfsstat.c (renamed from libopenbsd/getfsstat.c)0
-rw-r--r--lib/libopenbsd/getmntinfo.3 (renamed from libopenbsd/getmntinfo.3)0
-rw-r--r--lib/libopenbsd/getmntinfo.c (renamed from libopenbsd/getmntinfo.c)0
-rw-r--r--lib/libopenbsd/hash/helper.c (renamed from libopenbsd/hash/helper.c)0
-rw-r--r--lib/libopenbsd/hash/md5.3 (renamed from libopenbsd/hash/md5.3)0
-rw-r--r--lib/libopenbsd/hash/md5.c (renamed from libopenbsd/hash/md5.c)0
-rw-r--r--lib/libopenbsd/hash/md5hl.c113
-rw-r--r--lib/libopenbsd/hash/rmd160.3 (renamed from libopenbsd/hash/rmd160.3)0
-rw-r--r--lib/libopenbsd/hash/rmd160.c (renamed from libopenbsd/hash/rmd160.c)0
-rw-r--r--lib/libopenbsd/hash/rmd160hl.c113
-rw-r--r--lib/libopenbsd/hash/sha1.3 (renamed from libopenbsd/hash/sha1.3)0
-rw-r--r--lib/libopenbsd/hash/sha1.c (renamed from libopenbsd/hash/sha1.c)0
-rw-r--r--lib/libopenbsd/hash/sha1hl.c113
-rw-r--r--lib/libopenbsd/hash/sha2.3 (renamed from libopenbsd/hash/sha2.3)0
-rw-r--r--lib/libopenbsd/hash/sha2.c (renamed from libopenbsd/hash/sha2.c)0
-rw-r--r--lib/libopenbsd/hash/sha224hl.c113
-rw-r--r--lib/libopenbsd/hash/sha256hl.c113
-rw-r--r--lib/libopenbsd/hash/sha384hl.c113
-rw-r--r--lib/libopenbsd/hash/sha512hl.c113
-rw-r--r--lib/libopenbsd/heapsort.c (renamed from libopenbsd/heapsort.c)0
-rw-r--r--lib/libopenbsd/hidden/blf.h (renamed from libopenbsd/hidden/blf.h)0
-rw-r--r--lib/libopenbsd/include/mpool.h (renamed from libopenbsd/include/mpool.h)0
-rw-r--r--lib/libopenbsd/issetugid.c (renamed from libopenbsd/issetugid.c)0
-rw-r--r--lib/libopenbsd/libopenbsd.mk (renamed from libopenbsd/libopenbsd.mk)0
-rw-r--r--lib/libopenbsd/logwtmp.c (renamed from libopenbsd/logwtmp.c)0
-rw-r--r--lib/libopenbsd/md5.h (renamed from libopenbsd/md5.h)0
-rw-r--r--lib/libopenbsd/merge.c (renamed from libopenbsd/merge.c)0
-rw-r--r--lib/libopenbsd/mkfile (renamed from libopenbsd/mkfile)0
-rw-r--r--lib/libopenbsd/openbsd-queue.h (renamed from libopenbsd/openbsd-queue.h)0
-rw-r--r--lib/libopenbsd/openbsd-tree.h (renamed from libopenbsd/openbsd-tree.h)0
-rw-r--r--lib/libopenbsd/openbsd.h (renamed from libopenbsd/openbsd.h)0
-rw-r--r--lib/libopenbsd/pledge-noop.c (renamed from libopenbsd/pledge-noop.c)0
-rw-r--r--lib/libopenbsd/progname.c (renamed from libopenbsd/progname.c)0
-rw-r--r--lib/libopenbsd/pw_dup.3 (renamed from libopenbsd/pw_dup.3)0
-rw-r--r--lib/libopenbsd/pw_dup.c (renamed from libopenbsd/pw_dup.c)0
-rw-r--r--lib/libopenbsd/pwcache.3 (renamed from libopenbsd/pwcache.3)0
-rw-r--r--lib/libopenbsd/pwcache.c (renamed from libopenbsd/pwcache.c)0
-rw-r--r--lib/libopenbsd/qsort.c (renamed from libopenbsd/qsort.c)0
-rw-r--r--lib/libopenbsd/radixsort.c (renamed from libopenbsd/radixsort.c)0
-rw-r--r--lib/libopenbsd/random.3 (renamed from libopenbsd/random.3)0
-rw-r--r--lib/libopenbsd/random.c (renamed from libopenbsd/random.c)0
-rw-r--r--lib/libopenbsd/readpassphrase.c (renamed from libopenbsd/readpassphrase.c)0
-rw-r--r--lib/libopenbsd/readpassphrase.h (renamed from libopenbsd/readpassphrase.h)0
-rw-r--r--lib/libopenbsd/rmd160.h (renamed from libopenbsd/rmd160.h)0
-rw-r--r--lib/libopenbsd/setproctitle.3 (renamed from libopenbsd/setproctitle.3)0
-rw-r--r--lib/libopenbsd/setproctitle.c (renamed from libopenbsd/setproctitle.c)0
-rw-r--r--lib/libopenbsd/sha1.h (renamed from libopenbsd/sha1.h)0
-rw-r--r--lib/libopenbsd/sha2.h (renamed from libopenbsd/sha2.h)0
-rw-r--r--lib/libopenbsd/statfs.c (renamed from libopenbsd/statfs.c)0
-rw-r--r--lib/libopenbsd/stdio/fgetln.c (renamed from libopenbsd/fgetln.c)0
-rw-r--r--lib/libopenbsd/stdio/fgetwln.3 (renamed from libopenbsd/fgetwln.3)0
-rw-r--r--lib/libopenbsd/stdio/fgetwln.c (renamed from libopenbsd/fgetwln.c)0
-rw-r--r--lib/libopenbsd/stdio/fgetwln.s (renamed from libopenbsd/fgetwln.s)0
-rw-r--r--lib/libopenbsd/stdlib/reallocarray.c (renamed from libopenbsd/reallocarray.c)3
-rw-r--r--lib/libopenbsd/string/explicit_bzero.c (renamed from libopenbsd/explicit_bzero.c)7
-rw-r--r--lib/libopenbsd/string/strlcat.c (renamed from libopenbsd/strlcat.c)0
-rw-r--r--lib/libopenbsd/string/strlcpy.c (renamed from libopenbsd/strlcpy.c)0
-rw-r--r--lib/libopenbsd/strmode.3 (renamed from libopenbsd/strmode.3)0
-rw-r--r--lib/libopenbsd/strmode.c (renamed from libopenbsd/strmode.c)0
-rw-r--r--lib/libopenbsd/strtod.3 (renamed from libopenbsd/strtod.3)0
-rw-r--r--lib/libopenbsd/strtoimax.c (renamed from libopenbsd/strtoimax.c)0
-rw-r--r--lib/libopenbsd/strtonum.3 (renamed from libopenbsd/strtonum.3)0
-rw-r--r--lib/libopenbsd/strtonum.c (renamed from libopenbsd/strtonum.c)0
-rw-r--r--lib/libopenbsd/strtoq.c (renamed from libopenbsd/strtoq.c)0
-rw-r--r--lib/libopenbsd/strtoumax.c (renamed from libopenbsd/strtoumax.c)0
-rw-r--r--lib/libopenbsd/unvis.3 (renamed from libopenbsd/unvis.3)0
-rw-r--r--lib/libopenbsd/unvis.c (renamed from libopenbsd/unvis.c)0
-rw-r--r--lib/libopenbsd/util.h (renamed from libopenbsd/util.h)0
-rw-r--r--lib/libopenbsd/vis.3 (renamed from libopenbsd/vis.3)0
-rw-r--r--lib/libopenbsd/vis.c (renamed from libopenbsd/vis.c)0
-rw-r--r--lib/libopenbsd/vis.h (renamed from libopenbsd/vis.h)0
-rw-r--r--libopenbsd/Makefile83
-rw-r--r--libopenbsd/execvpe.c157
104 files changed, 868 insertions, 248 deletions
diff --git a/Makefile b/Makefile
index 932997d..c87251c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
export TOPDIR := $(shell pwd)
-SUBDIR = libopenbsd lib bin sbin usr.bin usr.sbin
+SUBDIR = lib bin sbin usr.bin usr.sbin
ifeq (clean,$(filter clean,$(MAKECMDGOALS)))
SUBDIR += regress
diff --git a/README b/README
index 4e362f9..039aa19 100644
--- a/README
+++ b/README
@@ -39,7 +39,6 @@ TODO
- build shared libraries?
- libopenbsd
- - move into lib/ directory
- use the same directory structure as src/lib/libc to make diffs/merges simpler
- import libc/regexp?
- add getmntinfo(3) and getfsstat(2)
diff --git a/lib/Makefile b/lib/Makefile
index aae5a1a..021466b 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,2 +1,2 @@
-SUBDIR = libutil
+SUBDIR = libopenbsd libutil
include bsd.subdir.mk
diff --git a/lib/libopenbsd/Makefile b/lib/libopenbsd/Makefile
new file mode 100644
index 0000000..cef2808
--- /dev/null
+++ b/lib/libopenbsd/Makefile
@@ -0,0 +1,70 @@
+LIB=openbsd
+CPPFLAGS += -I. -Ihidden -include openbsd.h -I.. -include config.h
+
+GEN_SRCS = hash/md5hl.c hash/rmd160hl.c hash/sha1hl.c hash/sha224hl.c \
+ hash/sha256hl.c hash/sha384hl.c hash/sha512hl.c
+
+CLEANFILES+=$(GEN_SRCS)
+
+SRCS = base64.c closefrom.c \
+ heapsort.c merge.c pledge-noop.c progname.c \
+ qsort.c radixsort.c random.c readpassphrase.c \
+ setproctitle.c strtoimax.c strtonum.c strtoumax.c \
+ vis.c unvis.c pwcache.c pw_dup.c getbsize.c \
+ strmode.c logwtmp.c crypt/arc4random.c crypt/arc4random_uniform.c \
+ crypt/chacha.c crypt/blowfish.c hash/md5.c hash/rmd160.c hash/sha1.c \
+ hash/sha2.c $(GEN_SRCS)
+
+SRCS += gen/errc.c gen/fts.c gen/warnc.c gen/verrc.c gen/vwarnc.c gen/setmode.c\
+SRCS += stdio/fgetwln.c
+
+ifndef HAVE_EXPLICIT_BZERO
+ SRCS += string/explicit_bzero.c
+endif
+
+ifndef HAVE_REALLOCARRAY
+ SRCS += stdlib/reallocarray.c
+endif
+
+ifndef HAVE_STRLCPY
+ SRCS += string/strlcpy.c
+endif
+
+ifndef HAVE_STRLCAT
+ SRCS += string/strlcat.c
+endif
+
+ifndef HAVE_ISSETUGID
+ SRCS += issetugid.c
+endif
+
+ifndef HAVE_FGETLN
+ SRCS += stdio/fgetln.c
+endif
+
+ifndef HAVE_GETENTROPY
+ SRCS += getentropy_linux.c
+getentropy_linux.o : CPPFLAGS += -D_GNU_SOURCE
+endif
+
+ifndef HAVE_GETDTABLECOUNT
+ SRCS += sys/getdtablecount.c
+endif
+
+$(GEN_SRCS) : % : hash/helper.c
+
+hash/sha1hl.c:
+ sed -e 's/hashinc/sha1.h/g;s/HASH/SHA1/g' hash/helper.c > $@
+
+hash/sha%hl.c:
+ sed -e 's/hashinc/sha2.h/g;s/HASH_CTX/SHA2_CTX/g' \
+ -e 's/HASH/SHA$*/g' hash/helper.c > $@
+
+hash/md5hl.c:
+ sed -e "s/hashinc/md5.h/g;s/HASH/MD5/g" hash/helper.c > $@
+
+hash/rmd160hl.c:
+ sed -e "s/hashinc/rmd160.h/g;s/HASH/RMD160/g" hash/helper.c > $@
+
+
+include bsd.lib.mk
diff --git a/libopenbsd/base64.c b/lib/libopenbsd/base64.c
index e90696d..e90696d 100644
--- a/libopenbsd/base64.c
+++ b/lib/libopenbsd/base64.c
diff --git a/libopenbsd/chacha.h b/lib/libopenbsd/chacha.h
index 01388b7..01388b7 100644
--- a/libopenbsd/chacha.h
+++ b/lib/libopenbsd/chacha.h
diff --git a/libopenbsd/closefrom.c b/lib/libopenbsd/closefrom.c
index 07fa03c..07fa03c 100644
--- a/libopenbsd/closefrom.c
+++ b/lib/libopenbsd/closefrom.c
diff --git a/libopenbsd/config.mk.in b/lib/libopenbsd/config.mk.in
index 257bdc9..257bdc9 100644
--- a/libopenbsd/config.mk.in
+++ b/lib/libopenbsd/config.mk.in
diff --git a/libopenbsd/crypt/arc4random.c b/lib/libopenbsd/crypt/arc4random.c
index e659a6e..e659a6e 100644
--- a/libopenbsd/crypt/arc4random.c
+++ b/lib/libopenbsd/crypt/arc4random.c
diff --git a/libopenbsd/crypt/arc4random.h b/lib/libopenbsd/crypt/arc4random.h
index 0bd0a7c..0bd0a7c 100644
--- a/libopenbsd/crypt/arc4random.h
+++ b/lib/libopenbsd/crypt/arc4random.h
diff --git a/libopenbsd/crypt/arc4random_linux.h b/lib/libopenbsd/crypt/arc4random_linux.h
index c542f41..c542f41 100644
--- a/libopenbsd/crypt/arc4random_linux.h
+++ b/lib/libopenbsd/crypt/arc4random_linux.h
diff --git a/libopenbsd/crypt/arc4random_uniform.c b/lib/libopenbsd/crypt/arc4random_uniform.c
index cbf01a2..cbf01a2 100644
--- a/libopenbsd/crypt/arc4random_uniform.c
+++ b/lib/libopenbsd/crypt/arc4random_uniform.c
diff --git a/libopenbsd/crypt/blowfish.3 b/lib/libopenbsd/crypt/blowfish.3
index 88a6233..88a6233 100644
--- a/libopenbsd/crypt/blowfish.3
+++ b/lib/libopenbsd/crypt/blowfish.3
diff --git a/libopenbsd/crypt/blowfish.c b/lib/libopenbsd/crypt/blowfish.c
index a658e60..a658e60 100644
--- a/libopenbsd/crypt/blowfish.c
+++ b/lib/libopenbsd/crypt/blowfish.c
diff --git a/libopenbsd/crypt/chacha-merged.c b/lib/libopenbsd/crypt/chacha-merged.c
index b6eaf85..b6eaf85 100644
--- a/libopenbsd/crypt/chacha-merged.c
+++ b/lib/libopenbsd/crypt/chacha-merged.c
diff --git a/libopenbsd/crypt/chacha.c b/lib/libopenbsd/crypt/chacha.c
index e79435f..e79435f 100644
--- a/libopenbsd/crypt/chacha.c
+++ b/lib/libopenbsd/crypt/chacha.c
diff --git a/libopenbsd/crypt/chacha_private.h b/lib/libopenbsd/crypt/chacha_private.h
index b720d93..b720d93 100644
--- a/libopenbsd/crypt/chacha_private.h
+++ b/lib/libopenbsd/crypt/chacha_private.h
diff --git a/libopenbsd/errc.c b/lib/libopenbsd/gen/errc.c
index b556aa1..b556aa1 100644
--- a/libopenbsd/errc.c
+++ b/lib/libopenbsd/gen/errc.c
diff --git a/libopenbsd/fts.3 b/lib/libopenbsd/gen/fts.3
index 2c7d806..2c7d806 100644
--- a/libopenbsd/fts.3
+++ b/lib/libopenbsd/gen/fts.3
diff --git a/libopenbsd/fts.c b/lib/libopenbsd/gen/fts.c
index 3a5b55c..3a5b55c 100644
--- a/libopenbsd/fts.c
+++ b/lib/libopenbsd/gen/fts.c
diff --git a/libopenbsd/fts.h b/lib/libopenbsd/gen/fts.h
index 4415def..4415def 100644
--- a/libopenbsd/fts.h
+++ b/lib/libopenbsd/gen/fts.h
diff --git a/libopenbsd/setmode.3 b/lib/libopenbsd/gen/setmode.3
index d54ca2e..d54ca2e 100644
--- a/libopenbsd/setmode.3
+++ b/lib/libopenbsd/gen/setmode.3
diff --git a/libopenbsd/setmode.c b/lib/libopenbsd/gen/setmode.c
index ce241d2..ce241d2 100644
--- a/libopenbsd/setmode.c
+++ b/lib/libopenbsd/gen/setmode.c
diff --git a/libopenbsd/verrc.c b/lib/libopenbsd/gen/verrc.c
index 51dd47d..51dd47d 100644
--- a/libopenbsd/verrc.c
+++ b/lib/libopenbsd/gen/verrc.c
diff --git a/libopenbsd/vwarnc.c b/lib/libopenbsd/gen/vwarnc.c
index 4ef7810..4ef7810 100644
--- a/libopenbsd/vwarnc.c
+++ b/lib/libopenbsd/gen/vwarnc.c
diff --git a/libopenbsd/warnc.c b/lib/libopenbsd/gen/warnc.c
index bbda54b..bbda54b 100644
--- a/libopenbsd/warnc.c
+++ b/lib/libopenbsd/gen/warnc.c
diff --git a/libopenbsd/getbsize.3 b/lib/libopenbsd/getbsize.3
index a740ae4..a740ae4 100644
--- a/libopenbsd/getbsize.3
+++ b/lib/libopenbsd/getbsize.3
diff --git a/libopenbsd/getbsize.c b/lib/libopenbsd/getbsize.c
index 8b6e4f0..8b6e4f0 100644
--- a/libopenbsd/getbsize.c
+++ b/lib/libopenbsd/getbsize.c
diff --git a/libopenbsd/getentropy_linux.c b/lib/libopenbsd/getentropy_linux.c
index 7e74798..7e74798 100644
--- a/libopenbsd/getentropy_linux.c
+++ b/lib/libopenbsd/getentropy_linux.c
diff --git a/libopenbsd/getfsstat b/lib/libopenbsd/getfsstat
index 58bce77..58bce77 100755
--- a/libopenbsd/getfsstat
+++ b/lib/libopenbsd/getfsstat
Binary files differ
diff --git a/libopenbsd/getfsstat.2 b/lib/libopenbsd/getfsstat.2
index ff79c94..ff79c94 100644
--- a/libopenbsd/getfsstat.2
+++ b/lib/libopenbsd/getfsstat.2
diff --git a/libopenbsd/getfsstat.c b/lib/libopenbsd/getfsstat.c
index ad32f04..ad32f04 100644
--- a/libopenbsd/getfsstat.c
+++ b/lib/libopenbsd/getfsstat.c
diff --git a/libopenbsd/getmntinfo.3 b/lib/libopenbsd/getmntinfo.3
index 0138b6a..0138b6a 100644
--- a/libopenbsd/getmntinfo.3
+++ b/lib/libopenbsd/getmntinfo.3
diff --git a/libopenbsd/getmntinfo.c b/lib/libopenbsd/getmntinfo.c
index 5781340..5781340 100644
--- a/libopenbsd/getmntinfo.c
+++ b/lib/libopenbsd/getmntinfo.c
diff --git a/libopenbsd/hash/helper.c b/lib/libopenbsd/hash/helper.c
index 38008ae..38008ae 100644
--- a/libopenbsd/hash/helper.c
+++ b/lib/libopenbsd/hash/helper.c
diff --git a/libopenbsd/hash/md5.3 b/lib/libopenbsd/hash/md5.3
index 547f5f7..547f5f7 100644
--- a/libopenbsd/hash/md5.3
+++ b/lib/libopenbsd/hash/md5.3
diff --git a/libopenbsd/hash/md5.c b/lib/libopenbsd/hash/md5.c
index 435e5ac..435e5ac 100644
--- a/libopenbsd/hash/md5.c
+++ b/lib/libopenbsd/hash/md5.c
diff --git a/lib/libopenbsd/hash/md5hl.c b/lib/libopenbsd/hash/md5hl.c
new file mode 100644
index 0000000..941b12b
--- /dev/null
+++ b/lib/libopenbsd/hash/md5hl.c
@@ -0,0 +1,113 @@
+/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */
+
+/*
+ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
+ *
+ * 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.
+ */
+
+/*
+ * If we meet some day, and you think this stuff is worth it, you
+ * can buy me a beer in return. Poul-Henning Kamp
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <md5.h>
+
+#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
+
+char *
+MD5End(MD5_CTX *ctx, char *buf)
+{
+ int i;
+ u_int8_t digest[MD5_DIGEST_LENGTH];
+ static const char hex[] = "0123456789abcdef";
+
+ if (buf == NULL && (buf = malloc(MD5_DIGEST_STRING_LENGTH)) == NULL)
+ return (NULL);
+
+ 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';
+ explicit_bzero(digest, sizeof(digest));
+ return (buf);
+}
+DEF_WEAK(MD5End);
+
+char *
+MD5FileChunk(const char *filename, char *buf, off_t off, off_t len)
+{
+ struct stat sb;
+ u_char buffer[BUFSIZ];
+ MD5_CTX ctx;
+ int fd, save_errno;
+ ssize_t nr;
+
+ MD5Init(&ctx);
+
+ if ((fd = open(filename, O_RDONLY)) < 0)
+ return (NULL);
+ if (len == 0) {
+ if (fstat(fd, &sb) == -1) {
+ close(fd);
+ return (NULL);
+ }
+ len = sb.st_size;
+ }
+ if (off > 0 && lseek(fd, off, SEEK_SET) < 0) {
+ close(fd);
+ return (NULL);
+ }
+
+ while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) {
+ MD5Update(&ctx, buffer, (size_t)nr);
+ if (len > 0 && (len -= nr) == 0)
+ break;
+ }
+
+ save_errno = errno;
+ close(fd);
+ errno = save_errno;
+ return (nr < 0 ? NULL : MD5End(&ctx, buf));
+}
+DEF_WEAK(MD5FileChunk);
+
+char *
+MD5File(const char *filename, char *buf)
+{
+ return (MD5FileChunk(filename, buf, (off_t)0, (off_t)0));
+}
+DEF_WEAK(MD5File);
+
+char *
+MD5Data(const u_char *data, size_t len, char *buf)
+{
+ MD5_CTX ctx;
+
+ MD5Init(&ctx);
+ MD5Update(&ctx, data, len);
+ return (MD5End(&ctx, buf));
+}
+DEF_WEAK(MD5Data);
diff --git a/libopenbsd/hash/rmd160.3 b/lib/libopenbsd/hash/rmd160.3
index ac4251d..ac4251d 100644
--- a/libopenbsd/hash/rmd160.3
+++ b/lib/libopenbsd/hash/rmd160.3
diff --git a/libopenbsd/hash/rmd160.c b/lib/libopenbsd/hash/rmd160.c
index 3bf5801..3bf5801 100644
--- a/libopenbsd/hash/rmd160.c
+++ b/lib/libopenbsd/hash/rmd160.c
diff --git a/lib/libopenbsd/hash/rmd160hl.c b/lib/libopenbsd/hash/rmd160hl.c
new file mode 100644
index 0000000..fbb4cd3
--- /dev/null
+++ b/lib/libopenbsd/hash/rmd160hl.c
@@ -0,0 +1,113 @@
+/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */
+
+/*
+ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
+ *
+ * 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.
+ */
+
+/*
+ * If we meet some day, and you think this stuff is worth it, you
+ * can buy me a beer in return. Poul-Henning Kamp
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <rmd160.h>
+
+#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
+
+char *
+RMD160End(RMD160_CTX *ctx, char *buf)
+{
+ int i;
+ u_int8_t digest[RMD160_DIGEST_LENGTH];
+ static const char hex[] = "0123456789abcdef";
+
+ if (buf == NULL && (buf = malloc(RMD160_DIGEST_STRING_LENGTH)) == NULL)
+ return (NULL);
+
+ RMD160Final(digest, ctx);
+ for (i = 0; i < RMD160_DIGEST_LENGTH; i++) {
+ buf[i + i] = hex[digest[i] >> 4];
+ buf[i + i + 1] = hex[digest[i] & 0x0f];
+ }
+ buf[i + i] = '\0';
+ explicit_bzero(digest, sizeof(digest));
+ return (buf);
+}
+DEF_WEAK(RMD160End);
+
+char *
+RMD160FileChunk(const char *filename, char *buf, off_t off, off_t len)
+{
+ struct stat sb;
+ u_char buffer[BUFSIZ];
+ RMD160_CTX ctx;
+ int fd, save_errno;
+ ssize_t nr;
+
+ RMD160Init(&ctx);
+
+ if ((fd = open(filename, O_RDONLY)) < 0)
+ return (NULL);
+ if (len == 0) {
+ if (fstat(fd, &sb) == -1) {
+ close(fd);
+ return (NULL);
+ }
+ len = sb.st_size;
+ }
+ if (off > 0 && lseek(fd, off, SEEK_SET) < 0) {
+ close(fd);
+ return (NULL);
+ }
+
+ while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) {
+ RMD160Update(&ctx, buffer, (size_t)nr);
+ if (len > 0 && (len -= nr) == 0)
+ break;
+ }
+
+ save_errno = errno;
+ close(fd);
+ errno = save_errno;
+ return (nr < 0 ? NULL : RMD160End(&ctx, buf));
+}
+DEF_WEAK(RMD160FileChunk);
+
+char *
+RMD160File(const char *filename, char *buf)
+{
+ return (RMD160FileChunk(filename, buf, (off_t)0, (off_t)0));
+}
+DEF_WEAK(RMD160File);
+
+char *
+RMD160Data(const u_char *data, size_t len, char *buf)
+{
+ RMD160_CTX ctx;
+
+ RMD160Init(&ctx);
+ RMD160Update(&ctx, data, len);
+ return (RMD160End(&ctx, buf));
+}
+DEF_WEAK(RMD160Data);
diff --git a/libopenbsd/hash/sha1.3 b/lib/libopenbsd/hash/sha1.3
index 4154879..4154879 100644
--- a/libopenbsd/hash/sha1.3
+++ b/lib/libopenbsd/hash/sha1.3
diff --git a/libopenbsd/hash/sha1.c b/lib/libopenbsd/hash/sha1.c
index 4a6cc32..4a6cc32 100644
--- a/libopenbsd/hash/sha1.c
+++ b/lib/libopenbsd/hash/sha1.c
diff --git a/lib/libopenbsd/hash/sha1hl.c b/lib/libopenbsd/hash/sha1hl.c
new file mode 100644
index 0000000..437a560
--- /dev/null
+++ b/lib/libopenbsd/hash/sha1hl.c
@@ -0,0 +1,113 @@
+/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */
+
+/*
+ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
+ *
+ * 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.
+ */
+
+/*
+ * If we meet some day, and you think this stuff is worth it, you
+ * can buy me a beer in return. Poul-Henning Kamp
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sha1.h>
+
+#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
+
+char *
+SHA1End(SHA1_CTX *ctx, char *buf)
+{
+ int i;
+ u_int8_t digest[SHA1_DIGEST_LENGTH];
+ static const char hex[] = "0123456789abcdef";
+
+ if (buf == NULL && (buf = malloc(SHA1_DIGEST_STRING_LENGTH)) == NULL)
+ return (NULL);
+
+ SHA1Final(digest, ctx);
+ for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
+ buf[i + i] = hex[digest[i] >> 4];
+ buf[i + i + 1] = hex[digest[i] & 0x0f];
+ }
+ buf[i + i] = '\0';
+ explicit_bzero(digest, sizeof(digest));
+ return (buf);
+}
+DEF_WEAK(SHA1End);
+
+char *
+SHA1FileChunk(const char *filename, char *buf, off_t off, off_t len)
+{
+ struct stat sb;
+ u_char buffer[BUFSIZ];
+ SHA1_CTX ctx;
+ int fd, save_errno;
+ ssize_t nr;
+
+ SHA1Init(&ctx);
+
+ if ((fd = open(filename, O_RDONLY)) < 0)
+ return (NULL);
+ if (len == 0) {
+ if (fstat(fd, &sb) == -1) {
+ close(fd);
+ return (NULL);
+ }
+ len = sb.st_size;
+ }
+ if (off > 0 && lseek(fd, off, SEEK_SET) < 0) {
+ close(fd);
+ return (NULL);
+ }
+
+ while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) {
+ SHA1Update(&ctx, buffer, (size_t)nr);
+ if (len > 0 && (len -= nr) == 0)
+ break;
+ }
+
+ save_errno = errno;
+ close(fd);
+ errno = save_errno;
+ return (nr < 0 ? NULL : SHA1End(&ctx, buf));
+}
+DEF_WEAK(SHA1FileChunk);
+
+char *
+SHA1File(const char *filename, char *buf)
+{
+ return (SHA1FileChunk(filename, buf, (off_t)0, (off_t)0));
+}
+DEF_WEAK(SHA1File);
+
+char *
+SHA1Data(const u_char *data, size_t len, char *buf)
+{
+ SHA1_CTX ctx;
+
+ SHA1Init(&ctx);
+ SHA1Update(&ctx, data, len);
+ return (SHA1End(&ctx, buf));
+}
+DEF_WEAK(SHA1Data);
diff --git a/libopenbsd/hash/sha2.3 b/lib/libopenbsd/hash/sha2.3
index ae85a72..ae85a72 100644
--- a/libopenbsd/hash/sha2.3
+++ b/lib/libopenbsd/hash/sha2.3
diff --git a/libopenbsd/hash/sha2.c b/lib/libopenbsd/hash/sha2.c
index 16486bc..16486bc 100644
--- a/libopenbsd/hash/sha2.c
+++ b/lib/libopenbsd/hash/sha2.c
diff --git a/lib/libopenbsd/hash/sha224hl.c b/lib/libopenbsd/hash/sha224hl.c
new file mode 100644
index 0000000..2f97183
--- /dev/null
+++ b/lib/libopenbsd/hash/sha224hl.c
@@ -0,0 +1,113 @@
+/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */
+
+/*
+ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
+ *
+ * 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.
+ */
+
+/*
+ * If we meet some day, and you think this stuff is worth it, you
+ * can buy me a beer in return. Poul-Henning Kamp
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sha2.h>
+
+#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
+
+char *
+SHA224End(SHA2_CTX *ctx, char *buf)
+{
+ int i;
+ u_int8_t digest[SHA224_DIGEST_LENGTH];
+ static const char hex[] = "0123456789abcdef";
+
+ if (buf == NULL && (buf = malloc(SHA224_DIGEST_STRING_LENGTH)) == NULL)
+ return (NULL);
+
+ SHA224Final(digest, ctx);
+ for (i = 0; i < SHA224_DIGEST_LENGTH; i++) {
+ buf[i + i] = hex[digest[i] >> 4];
+ buf[i + i + 1] = hex[digest[i] & 0x0f];
+ }
+ buf[i + i] = '\0';
+ explicit_bzero(digest, sizeof(digest));
+ return (buf);
+}
+DEF_WEAK(SHA224End);
+
+char *
+SHA224FileChunk(const char *filename, char *buf, off_t off, off_t len)
+{
+ struct stat sb;
+ u_char buffer[BUFSIZ];
+ SHA2_CTX ctx;
+ int fd, save_errno;
+ ssize_t nr;
+
+ SHA224Init(&ctx);
+
+ if ((fd = open(filename, O_RDONLY)) < 0)
+ return (NULL);
+ if (len == 0) {
+ if (fstat(fd, &sb) == -1) {
+ close(fd);
+ return (NULL);
+ }
+ len = sb.st_size;
+ }
+ if (off > 0 && lseek(fd, off, SEEK_SET) < 0) {
+ close(fd);
+ return (NULL);
+ }
+
+ while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) {
+ SHA224Update(&ctx, buffer, (size_t)nr);
+ if (len > 0 && (len -= nr) == 0)
+ break;
+ }
+
+ save_errno = errno;
+ close(fd);
+ errno = save_errno;
+ return (nr < 0 ? NULL : SHA224End(&ctx, buf));
+}
+DEF_WEAK(SHA224FileChunk);
+
+char *
+SHA224File(const char *filename, char *buf)
+{
+ return (SHA224FileChunk(filename, buf, (off_t)0, (off_t)0));
+}
+DEF_WEAK(SHA224File);
+
+char *
+SHA224Data(const u_char *data, size_t len, char *buf)
+{
+ SHA2_CTX ctx;
+
+ SHA224Init(&ctx);
+ SHA224Update(&ctx, data, len);
+ return (SHA224End(&ctx, buf));
+}
+DEF_WEAK(SHA224Data);
diff --git a/lib/libopenbsd/hash/sha256hl.c b/lib/libopenbsd/hash/sha256hl.c
new file mode 100644
index 0000000..7fb8faa
--- /dev/null
+++ b/lib/libopenbsd/hash/sha256hl.c
@@ -0,0 +1,113 @@
+/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */
+
+/*
+ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
+ *
+ * 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.
+ */
+
+/*
+ * If we meet some day, and you think this stuff is worth it, you
+ * can buy me a beer in return. Poul-Henning Kamp
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sha2.h>
+
+#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
+
+char *
+SHA256End(SHA2_CTX *ctx, char *buf)
+{
+ int i;
+ u_int8_t digest[SHA256_DIGEST_LENGTH];
+ static const char hex[] = "0123456789abcdef";
+
+ if (buf == NULL && (buf = malloc(SHA256_DIGEST_STRING_LENGTH)) == NULL)
+ return (NULL);
+
+ SHA256Final(digest, ctx);
+ for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
+ buf[i + i] = hex[digest[i] >> 4];
+ buf[i + i + 1] = hex[digest[i] & 0x0f];
+ }
+ buf[i + i] = '\0';
+ explicit_bzero(digest, sizeof(digest));
+ return (buf);
+}
+DEF_WEAK(SHA256End);
+
+char *
+SHA256FileChunk(const char *filename, char *buf, off_t off, off_t len)
+{
+ struct stat sb;
+ u_char buffer[BUFSIZ];
+ SHA2_CTX ctx;
+ int fd, save_errno;
+ ssize_t nr;
+
+ SHA256Init(&ctx);
+
+ if ((fd = open(filename, O_RDONLY)) < 0)
+ return (NULL);
+ if (len == 0) {
+ if (fstat(fd, &sb) == -1) {
+ close(fd);
+ return (NULL);
+ }
+ len = sb.st_size;
+ }
+ if (off > 0 && lseek(fd, off, SEEK_SET) < 0) {
+ close(fd);
+ return (NULL);
+ }
+
+ while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) {
+ SHA256Update(&ctx, buffer, (size_t)nr);
+ if (len > 0 && (len -= nr) == 0)
+ break;
+ }
+
+ save_errno = errno;
+ close(fd);
+ errno = save_errno;
+ return (nr < 0 ? NULL : SHA256End(&ctx, buf));
+}
+DEF_WEAK(SHA256FileChunk);
+
+char *
+SHA256File(const char *filename, char *buf)
+{
+ return (SHA256FileChunk(filename, buf, (off_t)0, (off_t)0));
+}
+DEF_WEAK(SHA256File);
+
+char *
+SHA256Data(const u_char *data, size_t len, char *buf)
+{
+ SHA2_CTX ctx;
+
+ SHA256Init(&ctx);
+ SHA256Update(&ctx, data, len);
+ return (SHA256End(&ctx, buf));
+}
+DEF_WEAK(SHA256Data);
diff --git a/lib/libopenbsd/hash/sha384hl.c b/lib/libopenbsd/hash/sha384hl.c
new file mode 100644
index 0000000..fc4cf14
--- /dev/null
+++ b/lib/libopenbsd/hash/sha384hl.c
@@ -0,0 +1,113 @@
+/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */
+
+/*
+ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
+ *
+ * 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.
+ */
+
+/*
+ * If we meet some day, and you think this stuff is worth it, you
+ * can buy me a beer in return. Poul-Henning Kamp
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sha2.h>
+
+#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
+
+char *
+SHA384End(SHA2_CTX *ctx, char *buf)
+{
+ int i;
+ u_int8_t digest[SHA384_DIGEST_LENGTH];
+ static const char hex[] = "0123456789abcdef";
+
+ if (buf == NULL && (buf = malloc(SHA384_DIGEST_STRING_LENGTH)) == NULL)
+ return (NULL);
+
+ SHA384Final(digest, ctx);
+ for (i = 0; i < SHA384_DIGEST_LENGTH; i++) {
+ buf[i + i] = hex[digest[i] >> 4];
+ buf[i + i + 1] = hex[digest[i] & 0x0f];
+ }
+ buf[i + i] = '\0';
+ explicit_bzero(digest, sizeof(digest));
+ return (buf);
+}
+DEF_WEAK(SHA384End);
+
+char *
+SHA384FileChunk(const char *filename, char *buf, off_t off, off_t len)
+{
+ struct stat sb;
+ u_char buffer[BUFSIZ];
+ SHA2_CTX ctx;
+ int fd, save_errno;
+ ssize_t nr;
+
+ SHA384Init(&ctx);
+
+ if ((fd = open(filename, O_RDONLY)) < 0)
+ return (NULL);
+ if (len == 0) {
+ if (fstat(fd, &sb) == -1) {
+ close(fd);
+ return (NULL);
+ }
+ len = sb.st_size;
+ }
+ if (off > 0 && lseek(fd, off, SEEK_SET) < 0) {
+ close(fd);
+ return (NULL);
+ }
+
+ while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) {
+ SHA384Update(&ctx, buffer, (size_t)nr);
+ if (len > 0 && (len -= nr) == 0)
+ break;
+ }
+
+ save_errno = errno;
+ close(fd);
+ errno = save_errno;
+ return (nr < 0 ? NULL : SHA384End(&ctx, buf));
+}
+DEF_WEAK(SHA384FileChunk);
+
+char *
+SHA384File(const char *filename, char *buf)
+{
+ return (SHA384FileChunk(filename, buf, (off_t)0, (off_t)0));
+}
+DEF_WEAK(SHA384File);
+
+char *
+SHA384Data(const u_char *data, size_t len, char *buf)
+{
+ SHA2_CTX ctx;
+
+ SHA384Init(&ctx);
+ SHA384Update(&ctx, data, len);
+ return (SHA384End(&ctx, buf));
+}
+DEF_WEAK(SHA384Data);
diff --git a/lib/libopenbsd/hash/sha512hl.c b/lib/libopenbsd/hash/sha512hl.c
new file mode 100644
index 0000000..4a8742f
--- /dev/null
+++ b/lib/libopenbsd/hash/sha512hl.c
@@ -0,0 +1,113 @@
+/* $OpenBSD: helper.c,v 1.15 2015/11/01 03:45:29 guenther Exp $ */
+
+/*
+ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
+ *
+ * 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.
+ */
+
+/*
+ * If we meet some day, and you think this stuff is worth it, you
+ * can buy me a beer in return. Poul-Henning Kamp
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sha2.h>
+
+#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
+
+char *
+SHA512End(SHA2_CTX *ctx, char *buf)
+{
+ int i;
+ u_int8_t digest[SHA512_DIGEST_LENGTH];
+ static const char hex[] = "0123456789abcdef";
+
+ if (buf == NULL && (buf = malloc(SHA512_DIGEST_STRING_LENGTH)) == NULL)
+ return (NULL);
+
+ SHA512Final(digest, ctx);
+ for (i = 0; i < SHA512_DIGEST_LENGTH; i++) {
+ buf[i + i] = hex[digest[i] >> 4];
+ buf[i + i + 1] = hex[digest[i] & 0x0f];
+ }
+ buf[i + i] = '\0';
+ explicit_bzero(digest, sizeof(digest));
+ return (buf);
+}
+DEF_WEAK(SHA512End);
+
+char *
+SHA512FileChunk(const char *filename, char *buf, off_t off, off_t len)
+{
+ struct stat sb;
+ u_char buffer[BUFSIZ];
+ SHA2_CTX ctx;
+ int fd, save_errno;
+ ssize_t nr;
+
+ SHA512Init(&ctx);
+
+ if ((fd = open(filename, O_RDONLY)) < 0)
+ return (NULL);
+ if (len == 0) {
+ if (fstat(fd, &sb) == -1) {
+ close(fd);
+ return (NULL);
+ }
+ len = sb.st_size;
+ }
+ if (off > 0 && lseek(fd, off, SEEK_SET) < 0) {
+ close(fd);
+ return (NULL);
+ }
+
+ while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) {
+ SHA512Update(&ctx, buffer, (size_t)nr);
+ if (len > 0 && (len -= nr) == 0)
+ break;
+ }
+
+ save_errno = errno;
+ close(fd);
+ errno = save_errno;
+ return (nr < 0 ? NULL : SHA512End(&ctx, buf));
+}
+DEF_WEAK(SHA512FileChunk);
+
+char *
+SHA512File(const char *filename, char *buf)
+{
+ return (SHA512FileChunk(filename, buf, (off_t)0, (off_t)0));
+}
+DEF_WEAK(SHA512File);
+
+char *
+SHA512Data(const u_char *data, size_t len, char *buf)
+{
+ SHA2_CTX ctx;
+
+ SHA512Init(&ctx);
+ SHA512Update(&ctx, data, len);
+ return (SHA512End(&ctx, buf));
+}
+DEF_WEAK(SHA512Data);
diff --git a/libopenbsd/heapsort.c b/lib/libopenbsd/heapsort.c
index ad3fffb..ad3fffb 100644
--- a/libopenbsd/heapsort.c
+++ b/lib/libopenbsd/heapsort.c
diff --git a/libopenbsd/hidden/blf.h b/lib/libopenbsd/hidden/blf.h
index 66bc66a..66bc66a 100644
--- a/libopenbsd/hidden/blf.h
+++ b/lib/libopenbsd/hidden/blf.h
diff --git a/libopenbsd/include/mpool.h b/lib/libopenbsd/include/mpool.h
index 26e9b89..26e9b89 100644
--- a/libopenbsd/include/mpool.h
+++ b/lib/libopenbsd/include/mpool.h
diff --git a/libopenbsd/issetugid.c b/lib/libopenbsd/issetugid.c
index 59b9d31..59b9d31 100644
--- a/libopenbsd/issetugid.c
+++ b/lib/libopenbsd/issetugid.c
diff --git a/libopenbsd/libopenbsd.mk b/lib/libopenbsd/libopenbsd.mk
index e4929fc..e4929fc 100644
--- a/libopenbsd/libopenbsd.mk
+++ b/lib/libopenbsd/libopenbsd.mk
diff --git a/libopenbsd/logwtmp.c b/lib/libopenbsd/logwtmp.c
index 5f71f00..5f71f00 100644
--- a/libopenbsd/logwtmp.c
+++ b/lib/libopenbsd/logwtmp.c
diff --git a/libopenbsd/md5.h b/lib/libopenbsd/md5.h
index d69b1a5..d69b1a5 100644
--- a/libopenbsd/md5.h
+++ b/lib/libopenbsd/md5.h
diff --git a/libopenbsd/merge.c b/lib/libopenbsd/merge.c
index d60317c..d60317c 100644
--- a/libopenbsd/merge.c
+++ b/lib/libopenbsd/merge.c
diff --git a/libopenbsd/mkfile b/lib/libopenbsd/mkfile
index 28f86e8..28f86e8 100644
--- a/libopenbsd/mkfile
+++ b/lib/libopenbsd/mkfile
diff --git a/libopenbsd/openbsd-queue.h b/lib/libopenbsd/openbsd-queue.h
index 5e81fdd..5e81fdd 100644
--- a/libopenbsd/openbsd-queue.h
+++ b/lib/libopenbsd/openbsd-queue.h
diff --git a/libopenbsd/openbsd-tree.h b/lib/libopenbsd/openbsd-tree.h
index e6502b1..e6502b1 100644
--- a/libopenbsd/openbsd-tree.h
+++ b/lib/libopenbsd/openbsd-tree.h
diff --git a/libopenbsd/openbsd.h b/lib/libopenbsd/openbsd.h
index e394e67..e394e67 100644
--- a/libopenbsd/openbsd.h
+++ b/lib/libopenbsd/openbsd.h
diff --git a/libopenbsd/pledge-noop.c b/lib/libopenbsd/pledge-noop.c
index 0a1b610..0a1b610 100644
--- a/libopenbsd/pledge-noop.c
+++ b/lib/libopenbsd/pledge-noop.c
diff --git a/libopenbsd/progname.c b/lib/libopenbsd/progname.c
index 6fd455d..6fd455d 100644
--- a/libopenbsd/progname.c
+++ b/lib/libopenbsd/progname.c
diff --git a/libopenbsd/pw_dup.3 b/lib/libopenbsd/pw_dup.3
index afd5d98..afd5d98 100644
--- a/libopenbsd/pw_dup.3
+++ b/lib/libopenbsd/pw_dup.3
diff --git a/libopenbsd/pw_dup.c b/lib/libopenbsd/pw_dup.c
index 45502b6..45502b6 100644
--- a/libopenbsd/pw_dup.c
+++ b/lib/libopenbsd/pw_dup.c
diff --git a/libopenbsd/pwcache.3 b/lib/libopenbsd/pwcache.3
index a0283ed..a0283ed 100644
--- a/libopenbsd/pwcache.3
+++ b/lib/libopenbsd/pwcache.3
diff --git a/libopenbsd/pwcache.c b/lib/libopenbsd/pwcache.c
index 743cad4..743cad4 100644
--- a/libopenbsd/pwcache.c
+++ b/lib/libopenbsd/pwcache.c
diff --git a/libopenbsd/qsort.c b/lib/libopenbsd/qsort.c
index 1d9b1e9..1d9b1e9 100644
--- a/libopenbsd/qsort.c
+++ b/lib/libopenbsd/qsort.c
diff --git a/libopenbsd/radixsort.c b/lib/libopenbsd/radixsort.c
index 49d03b5..49d03b5 100644
--- a/libopenbsd/radixsort.c
+++ b/lib/libopenbsd/radixsort.c
diff --git a/libopenbsd/random.3 b/lib/libopenbsd/random.3
index 020c728..020c728 100644
--- a/libopenbsd/random.3
+++ b/lib/libopenbsd/random.3
diff --git a/libopenbsd/random.c b/lib/libopenbsd/random.c
index e16afc3..e16afc3 100644
--- a/libopenbsd/random.c
+++ b/lib/libopenbsd/random.c
diff --git a/libopenbsd/readpassphrase.c b/lib/libopenbsd/readpassphrase.c
index 3b99bd8..3b99bd8 100644
--- a/libopenbsd/readpassphrase.c
+++ b/lib/libopenbsd/readpassphrase.c
diff --git a/libopenbsd/readpassphrase.h b/lib/libopenbsd/readpassphrase.h
index 5444597..5444597 100644
--- a/libopenbsd/readpassphrase.h
+++ b/lib/libopenbsd/readpassphrase.h
diff --git a/libopenbsd/rmd160.h b/lib/libopenbsd/rmd160.h
index 5137c59..5137c59 100644
--- a/libopenbsd/rmd160.h
+++ b/lib/libopenbsd/rmd160.h
diff --git a/libopenbsd/setproctitle.3 b/lib/libopenbsd/setproctitle.3
index 1eef7d0..1eef7d0 100644
--- a/libopenbsd/setproctitle.3
+++ b/lib/libopenbsd/setproctitle.3
diff --git a/libopenbsd/setproctitle.c b/lib/libopenbsd/setproctitle.c
index dd6733c..dd6733c 100644
--- a/libopenbsd/setproctitle.c
+++ b/lib/libopenbsd/setproctitle.c
diff --git a/libopenbsd/sha1.h b/lib/libopenbsd/sha1.h
index f596be6..f596be6 100644
--- a/libopenbsd/sha1.h
+++ b/lib/libopenbsd/sha1.h
diff --git a/libopenbsd/sha2.h b/lib/libopenbsd/sha2.h
index 065c30d..065c30d 100644
--- a/libopenbsd/sha2.h
+++ b/lib/libopenbsd/sha2.h
diff --git a/libopenbsd/statfs.c b/lib/libopenbsd/statfs.c
index 6f5ae38..6f5ae38 100644
--- a/libopenbsd/statfs.c
+++ b/lib/libopenbsd/statfs.c
diff --git a/libopenbsd/fgetln.c b/lib/libopenbsd/stdio/fgetln.c
index b79584c..b79584c 100644
--- a/libopenbsd/fgetln.c
+++ b/lib/libopenbsd/stdio/fgetln.c
diff --git a/libopenbsd/fgetwln.3 b/lib/libopenbsd/stdio/fgetwln.3
index a8a1d36..a8a1d36 100644
--- a/libopenbsd/fgetwln.3
+++ b/lib/libopenbsd/stdio/fgetwln.3
diff --git a/libopenbsd/fgetwln.c b/lib/libopenbsd/stdio/fgetwln.c
index 166c93d..166c93d 100644
--- a/libopenbsd/fgetwln.c
+++ b/lib/libopenbsd/stdio/fgetwln.c
diff --git a/libopenbsd/fgetwln.s b/lib/libopenbsd/stdio/fgetwln.s
index 0fc118d..0fc118d 100644
--- a/libopenbsd/fgetwln.s
+++ b/lib/libopenbsd/stdio/fgetwln.s
diff --git a/libopenbsd/reallocarray.c b/lib/libopenbsd/stdlib/reallocarray.c
index aa70686..baea252 100644
--- a/libopenbsd/reallocarray.c
+++ b/lib/libopenbsd/stdlib/reallocarray.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $ */
+/* $OpenBSD: reallocarray.c,v 1.3 2015/09/13 08:31:47 guenther Exp $ */
/*
* Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
*
@@ -36,3 +36,4 @@ reallocarray(void *optr, size_t nmemb, size_t size)
}
return realloc(optr, size * nmemb);
}
+DEF_WEAK(reallocarray);
diff --git a/libopenbsd/explicit_bzero.c b/lib/libopenbsd/string/explicit_bzero.c
index 9a646c6..003ea7c 100644
--- a/libopenbsd/explicit_bzero.c
+++ b/lib/libopenbsd/string/explicit_bzero.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: explicit_bzero.c,v 1.2 2014/06/10 04:17:37 deraadt Exp $ */
+/* $OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */
/*
* Public domain.
* Written by Matthew Dempsky.
@@ -6,10 +6,8 @@
#include <string.h>
-#define __UNUSED __attribute__ ((unused))
-
__attribute__((weak)) void
-__explicit_bzero_hook(__UNUSED void *buf, __UNUSED size_t len)
+__explicit_bzero_hook(void *buf, size_t len)
{
}
@@ -19,3 +17,4 @@ explicit_bzero(void *buf, size_t len)
memset(buf, 0, len);
__explicit_bzero_hook(buf, len);
}
+DEF_WEAK(explicit_bzero);
diff --git a/libopenbsd/strlcat.c b/lib/libopenbsd/string/strlcat.c
index 6bf2a41..6bf2a41 100644
--- a/libopenbsd/strlcat.c
+++ b/lib/libopenbsd/string/strlcat.c
diff --git a/libopenbsd/strlcpy.c b/lib/libopenbsd/string/strlcpy.c
index 3677689..3677689 100644
--- a/libopenbsd/strlcpy.c
+++ b/lib/libopenbsd/string/strlcpy.c
diff --git a/libopenbsd/strmode.3 b/lib/libopenbsd/strmode.3
index bebda2c..bebda2c 100644
--- a/libopenbsd/strmode.3
+++ b/lib/libopenbsd/strmode.3
diff --git a/libopenbsd/strmode.c b/lib/libopenbsd/strmode.c
index 609b893..609b893 100644
--- a/libopenbsd/strmode.c
+++ b/lib/libopenbsd/strmode.c
diff --git a/libopenbsd/strtod.3 b/lib/libopenbsd/strtod.3
index baca4b2..baca4b2 100644
--- a/libopenbsd/strtod.3
+++ b/lib/libopenbsd/strtod.3
diff --git a/libopenbsd/strtoimax.c b/lib/libopenbsd/strtoimax.c
index 52403a7..52403a7 100644
--- a/libopenbsd/strtoimax.c
+++ b/lib/libopenbsd/strtoimax.c
diff --git a/libopenbsd/strtonum.3 b/lib/libopenbsd/strtonum.3
index 43df0ed..43df0ed 100644
--- a/libopenbsd/strtonum.3
+++ b/lib/libopenbsd/strtonum.3
diff --git a/libopenbsd/strtonum.c b/lib/libopenbsd/strtonum.c
index ad22d1c..ad22d1c 100644
--- a/libopenbsd/strtonum.c
+++ b/lib/libopenbsd/strtonum.c
diff --git a/libopenbsd/strtoq.c b/lib/libopenbsd/strtoq.c
index b9f7f42..b9f7f42 100644
--- a/libopenbsd/strtoq.c
+++ b/lib/libopenbsd/strtoq.c
diff --git a/libopenbsd/strtoumax.c b/lib/libopenbsd/strtoumax.c
index 4c5e334..4c5e334 100644
--- a/libopenbsd/strtoumax.c
+++ b/lib/libopenbsd/strtoumax.c
diff --git a/libopenbsd/unvis.3 b/lib/libopenbsd/unvis.3
index 11ea34f..11ea34f 100644
--- a/libopenbsd/unvis.3
+++ b/lib/libopenbsd/unvis.3
diff --git a/libopenbsd/unvis.c b/lib/libopenbsd/unvis.c
index 05749aa..05749aa 100644
--- a/libopenbsd/unvis.c
+++ b/lib/libopenbsd/unvis.c
diff --git a/libopenbsd/util.h b/lib/libopenbsd/util.h
index 75c1545..75c1545 100644
--- a/libopenbsd/util.h
+++ b/lib/libopenbsd/util.h
diff --git a/libopenbsd/vis.3 b/lib/libopenbsd/vis.3
index 08ee3b5..08ee3b5 100644
--- a/libopenbsd/vis.3
+++ b/lib/libopenbsd/vis.3
diff --git a/libopenbsd/vis.c b/lib/libopenbsd/vis.c
index 4400c7b..4400c7b 100644
--- a/libopenbsd/vis.c
+++ b/lib/libopenbsd/vis.c
diff --git a/libopenbsd/vis.h b/lib/libopenbsd/vis.h
index ad05b07..ad05b07 100644
--- a/libopenbsd/vis.h
+++ b/lib/libopenbsd/vis.h
diff --git a/libopenbsd/Makefile b/libopenbsd/Makefile
deleted file mode 100644
index 459e606..0000000
--- a/libopenbsd/Makefile
+++ /dev/null
@@ -1,83 +0,0 @@
-include config.mk
-
-CFLAGS += -Wno-attributes -Wno-implicit-int
-CPPFLAGS += -I. -Ihidden -include openbsd.h -I.. -include config.h
-
-LIB=libopenbsd.a
-
-SRCS = base64.c closefrom.c errc.c warnc.c execvpe.c explicit_bzero.c fts.c \
- fgetwln.c heapsort.c merge.c pledge-noop.c progname.c \
- qsort.c radixsort.c random.c readpassphrase.c reallocarray.c setmode.c \
- setproctitle.c strlcat.c strlcpy.c strtoimax.c strtonum.c strtoumax.c verrc.c\
- vwarnc.c vis.c unvis.c pwcache.c pw_dup.c getbsize.c \
- strmode.c logwtmp.c crypt/arc4random.c crypt/arc4random_uniform.c \
- crypt/chacha.c crypt/blowfish.c hash/md5.c hash/rmd160.c hash/sha1.c \
- hash/sha2.c
-
-GEN_SRC = hash/md5hl.c hash/rmd160hl.c hash/sha1hl.c hash/sha224hl.c \
- hash/sha256hl.c hash/sha384hl.c hash/sha512hl.c
-
-OBJS = $(SRCS:.c=.o) $(GEN_SRC:.c=.o)
-
-ifndef HAVE_STRLCPY
- SRCS += strlcpy.c
-endif
-
-ifndef HAVE_STRLCAT
- SRCS += strlcat.c
-endif
-
-ifndef HAVE_ISSETUGID
- SRCS += issetugid.c
-endif
-
-ifndef HAVE_FGETLN
- SRCS += fgetln.c
-endif
-
-ifndef HAVE_GETENTROPY
- SRCS += getentropy_linux.c
-endif
-
-# getentropy_linux.c
-
-all: $(LIB)
-
-clean:
- rm -f $(GEN_SRC) $(OBJS)
-
-install:
-
-.PHONY: all clean install
-
-
-$(LIB) : $(OBJS)
-
-getentropy_linux.o : CPPFLAGS += -D_GNU_SOURCE
-
-
-%.a:
- ar rc $@ $^
-
-%.o: %.c
- $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
-
-
-$(GEN_SRC) : % : hash/helper.c
-$(GEN_SRC:.c=.o) : %.o :
-
-hash/md5hl.c:
- sed -e 's/hashinc/md5.h/g' -e 's/HASH/MD5/g' hash/helper.c > $@
-
-hash/rmd160hl.c:
- sed -e 's/hashinc/rmd160.h/g' -e 's/HASH/RMD160/g' hash/helper.c > $@
-
-hash/sha1hl.c:
- sed -e 's/hashinc/sha1.h/g' -e 's/HASH/SHA1/g' hash/helper.c > $@
-
-hash/sha224hl.c hash/sha256hl.c hash/sha384hl.c hash/sha512hl.c:
- stem=$@; stem=$${stem#*/sha}; stem=$${stem%hl.c}; \
- sed -e 's/hashinc/sha2.h/g' \
- -e "s/HASH/SHA$$stem/g" \
- -e 's/SHA[0-9][0-9][0-9]_CTX/SHA2_CTX/g' \
- hash/helper.c > $@
diff --git a/libopenbsd/execvpe.c b/libopenbsd/execvpe.c
deleted file mode 100644
index 38e4826..0000000
--- a/libopenbsd/execvpe.c
+++ /dev/null
@@ -1,157 +0,0 @@
-/* $OpenBSD: exec.c,v 1.20 2013/01/08 02:26:09 deraadt Exp $ */
-/*-
- * Copyright (c) 1991, 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 <sys/types.h>
-#include <sys/uio.h>
-
-#include <errno.h>
-#include <limits.h>
-#include <paths.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-
-int
-execvpe(const char *name, char *const *argv, char *const *envp)
-{
- char **memp;
- int cnt;
- size_t lp, ln, len;
- char *p;
- int eacces = 0;
- char *bp, *cur, *path, buf[PATH_MAX];
-
- /*
- * Do not allow null name
- */
- if (name == NULL || *name == '\0') {
- errno = ENOENT;
- return (-1);
- }
-
- /* If it's an absolute or relative path name, it's easy. */
- if (strchr(name, '/')) {
- bp = (char *)name;
- cur = path = NULL;
- goto retry;
- }
- bp = buf;
-
- /* Get the path we're searching. */
- if (!(path = getenv("PATH")))
- path = _PATH_DEFPATH;
- len = strlen(path) + 1;
- cur = alloca(len);
- if (cur == NULL) {
- errno = ENOMEM;
- return (-1);
- }
- strlcpy(cur, path, len);
- path = cur;
- while ((p = strsep(&cur, ":"))) {
- /*
- * It's a SHELL path -- double, leading and trailing colons
- * mean the current directory.
- */
- if (!*p) {
- p = ".";
- lp = 1;
- } else
- lp = strlen(p);
- ln = strlen(name);
-
- /*
- * If the path is too long complain. This is a possible
- * security issue; given a way to make the path too long
- * the user may execute the wrong program.
- */
- if (lp + ln + 2 > sizeof(buf)) {
- struct iovec iov[3];
-
- iov[0].iov_base = "execvp: ";
- iov[0].iov_len = 8;
- iov[1].iov_base = p;
- iov[1].iov_len = lp;
- iov[2].iov_base = ": path too long\n";
- iov[2].iov_len = 16;
- (void)writev(STDERR_FILENO, iov, 3);
- continue;
- }
- bcopy(p, buf, lp);
- buf[lp] = '/';
- bcopy(name, buf + lp + 1, ln);
- buf[lp + ln + 1] = '\0';
-
-retry: (void)execve(bp, argv, envp);
- switch(errno) {
- case E2BIG:
- goto done;
- case EISDIR:
- case ELOOP:
- case ENAMETOOLONG:
- case ENOENT:
- break;
- case ENOEXEC:
- for (cnt = 0; argv[cnt]; ++cnt)
- ;
- memp = alloca((cnt + 2) * sizeof(char *));
- if (memp == NULL)
- goto done;
- memp[0] = "sh";
- memp[1] = bp;
- bcopy(argv + 1, memp + 2, cnt * sizeof(char *));
- (void)execve(_PATH_BSHELL, memp, envp);
- goto done;
- case ENOMEM:
- goto done;
- case ENOTDIR:
- break;
- case ETXTBSY:
- /*
- * We used to retry here, but sh(1) doesn't.
- */
- goto done;
- case EACCES:
- eacces = 1;
- break;
- default:
- goto done;
- }
- }
- if (eacces)
- errno = EACCES;
- else if (!errno)
- errno = ENOENT;
-done:
- return (-1);
-}