commit b382f5b41823362d5640f1637eeaa4e214a89488
parent 2267e4266bb683d88de37a92967b9807c8a70439
Author: Michael Savage <mikejsavage@gmail.com>
Date: Thu, 9 Jul 2020 17:08:07 +0300
Cleanup
Diffstat:
15 files changed, 103 insertions(+), 272 deletions(-)
diff --git a/Makefile.mess b/Makefile.mess
@@ -23,7 +23,7 @@ ifneq ($(uname),OpenBSD)
# GCC whines without this. Assume everyone has strndup anyway
CFLAGS += -DHAVE_STRNDUP
- CFLAGS += -Iinclude
+ CFLAGS += -Icompat/include
SRCS += compat/safebfuns.c
SRCS += compat/bcrypt/bcrypt.c
@@ -34,7 +34,6 @@ ifneq ($(uname),OpenBSD)
endif
ifeq ($(uname),Linux)
- SRCS += compat/strlcpy.c
SRCS += compat/sha/sha512.c
SRCS += compat/getentropy/getentropy_linux.c
LDFLAGS += -lrt
diff --git a/compat/bcrypt/bcrypt.c b/compat/bcrypt/bcrypt.c
@@ -325,30 +325,3 @@ encode_base64(char *b64buffer, const u_int8_t *data, size_t len)
*bp = '\0';
return 0;
}
-
-/*
- * classic interface
- */
-char *
-bcrypt_gensalt(u_int8_t log_rounds)
-{
- static char gsalt[BCRYPT_SALTSPACE];
-
- bcrypt_initsalt(log_rounds, gsalt, sizeof(gsalt));
-
- return gsalt;
-}
-
-char *
-bcrypt(const char *pass, const char *salt)
-{
- static char gencrypted[BCRYPT_HASHSPACE];
- static char gerror[2];
-
- /* How do I handle errors ? Return ':' */
- strlcpy(gerror, ":", sizeof(gerror));
- if (bcrypt_hashpass(pass, salt, gencrypted, sizeof(gencrypted)) != 0)
- return gerror;
-
- return gencrypted;
-}
diff --git a/include/blf.h b/compat/include/blf.h
diff --git a/include/machine/endian.h b/compat/include/machine/endian.h
diff --git a/compat/include/pwd.h b/compat/include/pwd.h
@@ -0,0 +1,52 @@
+/* $OpenBSD: pwd.h,v 1.23 2014/05/16 21:28:15 tedu Exp $ */
+/* $NetBSD: pwd.h,v 1.9 1996/05/15 21:36:45 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ * Portions Copyright(C) 1995, 1996, Jason Downs. 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.
+ *
+ * @(#)pwd.h 8.2 (Berkeley) 1/21/94
+ */
+
+#ifndef _PWD_H_
+#define _PWD_H_
+
+#include <stddef.h>
+#include <sys/types.h>
+
+#define _PASSWORD_LEN 128 /* max length, not counting NUL */
+
+int bcrypt_newhash(const char *, int, char *, size_t);
+int bcrypt_checkpass(const char *, const char *);
+
+#endif /* !_PWD_H_ */
diff --git a/compat/include/stdlib.h b/compat/include/stdlib.h
@@ -0,0 +1,16 @@
+/*
+ * stdlib.h compatibility shim
+ * Public domain
+ */
+
+#include_next <stdlib.h>
+
+#ifndef LIBCRYPTOCOMPAT_STDLIB_H
+#define LIBCRYPTOCOMPAT_STDLIB_H
+
+#include <stdint.h>
+
+uint32_t arc4random(void);
+void arc4random_buf(void *_buf, size_t n);
+
+#endif
diff --git a/compat/include/string.h b/compat/include/string.h
@@ -0,0 +1,14 @@
+/*
+ * Public domain
+ * string.h compatibility shim
+ */
+
+#include_next <string.h>
+
+#ifndef LIBCRYPTOCOMPAT_STRING_H
+#define LIBCRYPTOCOMPAT_STRING_H
+
+void explicit_bzero(void *, size_t);
+int timingsafe_bcmp(const void *b1, const void *b2, size_t n);
+
+#endif
diff --git a/compat/include/sys/types.h b/compat/include/sys/types.h
@@ -0,0 +1,7 @@
+/*
+ * Public domain
+ * sys/types.h compatibility shim
+ */
+
+#include_next <sys/types.h>
+#include <stdint.h>
diff --git a/compat/include/unistd.h b/compat/include/unistd.h
@@ -0,0 +1,13 @@
+/*
+ * Public domain
+ * unistd.h compatibility shim
+ */
+
+#include_next <unistd.h>
+
+#ifndef LIBCRYPTOCOMPAT_UNISTD_H
+#define LIBCRYPTOCOMPAT_UNISTD_H
+
+int getentropy(void *buf, size_t buflen);
+
+#endif
diff --git a/compat/strlcpy.c b/compat/strlcpy.c
@@ -1,51 +0,0 @@
-/* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */
-
-/*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/types.h>
-#include <string.h>
-
-/*
- * 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 */
-}
diff --git a/include/pwd.h b/include/pwd.h
@@ -1,54 +0,0 @@
-/* $OpenBSD: pwd.h,v 1.23 2014/05/16 21:28:15 tedu Exp $ */
-/* $NetBSD: pwd.h,v 1.9 1996/05/15 21:36:45 jtc Exp $ */
-
-/*-
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- * (c) UNIX System Laboratories, Inc.
- * All or some portions of this file are derived from material licensed
- * to the University of California by American Telephone and Telegraph
- * Co. or Unix System Laboratories, Inc. and are reproduced herein with
- * the permission of UNIX System Laboratories, Inc.
- * Portions Copyright(C) 1995, 1996, Jason Downs. 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.
- *
- * @(#)pwd.h 8.2 (Berkeley) 1/21/94
- */
-
-#ifndef _PWD_H_
-#define _PWD_H_
-
-#include <stddef.h>
-#include <sys/types.h>
-
-#define _PASSWORD_LEN 128 /* max length, not counting NUL */
-
-char *bcrypt_gensalt(u_int8_t);
-char *bcrypt(const char *, const char *);
-int bcrypt_newhash(const char *, int, char *, size_t);
-int bcrypt_checkpass(const char *, const char *);
-
-#endif /* !_PWD_H_ */
diff --git a/include/stdlib.h b/include/stdlib.h
@@ -1,29 +0,0 @@
-/*
- * stdlib.h compatibility shim
- * Public domain
- */
-
-#include_next <stdlib.h>
-
-#ifndef LIBCRYPTOCOMPAT_STDLIB_H
-#define LIBCRYPTOCOMPAT_STDLIB_H
-
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <stdint.h>
-
-#ifndef HAVE_ARC4RANDOM_BUF
-uint32_t arc4random(void);
-void arc4random_buf(void *_buf, size_t n);
-#endif
-
-#ifndef HAVE_REALLOCARRAY
-void *reallocarray(void *, size_t, size_t);
-#endif
-
-#ifndef HAVE_STRTONUM
-long long strtonum(const char *nptr, long long minval,
- long long maxval, const char **errstr);
-#endif
-
-#endif
diff --git a/include/string.h b/include/string.h
@@ -1,69 +0,0 @@
-/*
- * Public domain
- * string.h compatibility shim
- */
-
-#include_next <string.h>
-
-#ifndef LIBCRYPTOCOMPAT_STRING_H
-#define LIBCRYPTOCOMPAT_STRING_H
-
-#include <sys/types.h>
-
-#if defined(__sun) || defined(__hpux)
-/* Some functions historically defined in string.h were placed in strings.h by
- * SUS. Use the same hack as OS X and FreeBSD use to work around on Solaris and HPUX.
- */
-#include <strings.h>
-#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
-
-#ifndef HAVE_STRNDUP
-char * strndup(const char *str, size_t maxlen);
-/* the only user of strnlen is strndup, so only build it if needed */
-#ifndef HAVE_STRNLEN
-size_t strnlen(const char *str, size_t maxlen);
-#endif
-#endif
-
-#ifndef HAVE_EXPLICIT_BZERO
-void explicit_bzero(void *, size_t);
-#endif
-
-#ifndef HAVE_TIMINGSAFE_BCMP
-int timingsafe_bcmp(const void *b1, const void *b2, size_t n);
-#endif
-
-#ifndef HAVE_TIMINGSAFE_MEMCMP
-int timingsafe_memcmp(const void *b1, const void *b2, size_t len);
-#endif
-
-#ifndef HAVE_MEMMEM
-void * memmem(const void *big, size_t big_len, const void *little,
- size_t little_len);
-#endif
-
-#ifdef _WIN32
-#include <errno.h>
-
-static inline char *
-posix_strerror(int errnum)
-{
- if (errnum == ECONNREFUSED) {
- return "Connection refused";
- }
- return strerror(errnum);
-}
-
-#define strerror(errnum) posix_strerror(errnum)
-
-#endif
-
-#endif
diff --git a/include/sys/types.h b/include/sys/types.h
@@ -1,21 +0,0 @@
-/*
- * Public domain
- * sys/types.h compatibility shim
- */
-
-#include_next <sys/types.h>
-
-#ifndef LIBCRYPTOCOMPAT_SYS_TYPES_H
-#define LIBCRYPTOCOMPAT_SYS_TYPES_H
-
-#include <stdint.h>
-
-#ifdef __MINGW32__
-#include <_bsd_types.h>
-#endif
-
-#if !defined(HAVE_ATTRIBUTE__BOUNDED__) && !defined(__bounded__)
-# define __bounded__(x, y, z)
-#endif
-
-#endif
diff --git a/include/unistd.h b/include/unistd.h
@@ -1,19 +0,0 @@
-/*
- * Public domain
- * unistd.h compatibility shim
- */
-
-#include_next <unistd.h>
-
-#ifndef LIBCRYPTOCOMPAT_UNISTD_H
-#define LIBCRYPTOCOMPAT_UNISTD_H
-
-#ifndef HAVE_GETENTROPY
-int getentropy(void *buf, size_t buflen);
-#endif
-
-#ifndef HAVE_ISSETUGID
-int issetugid(void);
-#endif
-
-#endif