libbsd: Branch 'master' - 6 commits
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Feb 7 00:53:24 UTC 2021
COPYING | 20 --
README | 3
configure.ac | 15 +
include/Makefile.am | 2
include/bsd/grp.h | 51 +++++
include/bsd/md5.h | 75 ++------
include/bsd/pwd.h | 51 +++++
man/Makefile.am | 5
man/gid_from_group.3bsd | 1
man/group_from_gid.3bsd | 1
man/libbsd.7 | 5
man/pwcache.3bsd | 143 +++++++++++++++
man/reallocarray.3bsd | 1
man/uid_from_user.3bsd | 1
man/user_from_uid.3bsd | 1
src/Makefile.am | 16 -
src/funopen.c | 2
src/getentropy_aix.c | 8
src/getentropy_hpux.c | 8
src/getentropy_hurd.c | 10 -
src/getentropy_linux.c | 10 -
src/getentropy_osx.c | 6
src/getentropy_solaris.c | 8
src/hash/.gitignore | 1
src/hash/helper.c | 105 -----------
src/hash/md5.c | 248 --------------------------
src/hash/sha512.h | 53 -----
src/hash/sha512c.c | 318 ----------------------------------
src/libbsd.map | 7
src/md5.c | 91 +++++++++
src/progname.c | 72 +++++++
src/pwcache.c | 437 +++++++++++++++++++++++++++++++++++++++++++++++
test/.gitignore | 1
test/Makefile.am | 3
test/fgetln.c | 2
test/overlay.c | 3
test/pwcache.c | 49 +++++
test/setmode.c | 2
38 files changed, 996 insertions(+), 839 deletions(-)
New commits:
commit 2462cd88889a79f50017d23eaa376de67affc59c
Author: Guillem Jover <guillem at hadrons.org>
Date: Sun Feb 7 00:23:43 2021 +0100
Release libbsd 0.11.0
diff --git a/configure.ac b/configure.ac
index df05b0e..1944c16 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,7 +12,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
LIBBSD_ABI_MAJOR=0
-LIBBSD_ABI_MINOR=10
+LIBBSD_ABI_MINOR=11
LIBBSD_ABI_PATCH=0
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
commit d54ceb37ce9d7c04fa450a6638eaee31375bbde1
Author: Guillem Jover <guillem at hadrons.org>
Date: Sun Feb 7 00:09:45 2021 +0100
Update copyright claims
diff --git a/COPYING b/COPYING
index b51db0e..8a99303 100644
--- a/COPYING
+++ b/COPYING
@@ -3,7 +3,7 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Files:
*
Copyright:
- Copyright © 2004-2006, 2008-2018 Guillem Jover <guillem at hadrons.org>
+ Copyright © 2004-2006, 2008-2021 Guillem Jover <guillem at hadrons.org>
License: BSD-3-clause
Files:
diff --git a/src/funopen.c b/src/funopen.c
index 1d908bc..1e6f43a 100644
--- a/src/funopen.c
+++ b/src/funopen.c
@@ -1,5 +1,5 @@
/*
- * Copyright © 2011, 2013, 2017 Guillem Jover
+ * Copyright © 2011, 2013, 2017, 2020 Guillem Jover
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/test/fgetln.c b/test/fgetln.c
index 5e04281..d08fb3b 100644
--- a/test/fgetln.c
+++ b/test/fgetln.c
@@ -1,5 +1,5 @@
/*
- * Copyright © 2013 Guillem Jover <guillem at hadrons.org>
+ * Copyright © 2013-2015, 2020 Guillem Jover <guillem at hadrons.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/test/setmode.c b/test/setmode.c
index c72deb8..3164db2 100644
--- a/test/setmode.c
+++ b/test/setmode.c
@@ -1,5 +1,5 @@
/*
- * Copyright © 2017 Guillem Jover <guillem at hadrons.org>
+ * Copyright © 2017, 2020 Guillem Jover <guillem at hadrons.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
commit 847e682f8de452d5f0038458f06ae68ae3959b3a
Author: Guillem Jover <guillem at hadrons.org>
Date: Sun Feb 7 00:09:30 2021 +0100
Use libmd hashing function implementations instead of embedding our own
This splits the implementation responsibilities, and reduces embedded
code copies, which was one of the driving points with this project to
start with, so it's nice to give a good example.
diff --git a/COPYING b/COPYING
index 34ec432..b51db0e 100644
--- a/COPYING
+++ b/COPYING
@@ -278,8 +278,6 @@ Files:
man/getpeereid.3bsd
man/pidfile.3bsd
src/expand_number.c
- src/hash/sha512.h
- src/hash/sha512c.c
src/pidfile.c
src/reallocf.c
src/timeconv.c
@@ -458,17 +456,6 @@ License: Expat
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
-Files:
- include/bsd/md5.h
- src/hash/md5.c
-Copyright:
- None
-License: public-domain-Colin-Plumb
- 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.
-
Files:
src/explicit_bzero.c
src/chacha_private.h
@@ -479,8 +466,6 @@ License: public-domain
Files:
man/mdX.3bsd
- src/hash/md5hl.c
- src/hash/helper.c
Copyright:
None
License: Beerware
diff --git a/README b/README
index d516db0..9b2bbdb 100644
--- a/README
+++ b/README
@@ -5,6 +5,9 @@ and lacking on others like GNU systems, thus making it easier to port
projects with strong BSD origins, without needing to embed the same
code over and over again on each project.
+A BSD compatible message-digest library is required, on systems where
+this is not provided by its libc or libmd libraries, the canonical
+implementation to use is <https://www.hadrons.org/software/libmd/>.
Releases
--------
diff --git a/configure.ac b/configure.ac
index cf064bb..df05b0e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -63,6 +63,17 @@ AC_SUBST([TESTU01_LIBS])
AM_CONDITIONAL([HAVE_LIBTESTU01],
[test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
+saved_LIBS="$LIBS"
+AC_SEARCH_LIBS([MD5Update], [md], [
+ AC_SEARCH_LIBS([SHA512Update], [md], [
+ MD_LIBS="-lmd"
+ ])
+], [
+ AC_MSG_ERROR([cannot find required message digest functions in libc or libmd])
+])
+AC_SUBST([MD_LIBS])
+LIBS="$saved_LIBS"
+
is_windows=no
AS_CASE([$host_os],
[*-gnu*], [
diff --git a/include/bsd/md5.h b/include/bsd/md5.h
index bf36a30..5bd58d8 100644
--- a/include/bsd/md5.h
+++ b/include/bsd/md5.h
@@ -1,58 +1,31 @@
-/* $OpenBSD: md5.h,v 1.16 2004/06/22 01:57:30 jfb Exp $ */
-
/*
- * 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.
+ * Copyright © 2021 Guillem Jover <guillem at hadrons.org>
+ *
+ * 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.
*
- * 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.
+ * 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.
*/
-#ifndef LIBBSD_MD5_H
-#define LIBBSD_MD5_H
-
-#include <stdint.h>
-
-#define MD5_BLOCK_LENGTH 64
-#define MD5_DIGEST_LENGTH 16
-#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
-
-typedef struct MD5Context {
- uint32_t state[4]; /* state */
- uint64_t count; /* number of bits, mod 2^64 */
- uint8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */
-} MD5_CTX;
-
#ifdef LIBBSD_OVERLAY
-#include <sys/cdefs.h>
+#include_next <md5.h>
#else
-#include <bsd/sys/cdefs.h>
+#include <md5.h>
#endif
-#include <sys/types.h>
-
-__BEGIN_DECLS
-void MD5Init(MD5_CTX *);
-void MD5Update(MD5_CTX *, const uint8_t *, size_t)
- __attribute__((__bounded__(__string__,2,3)));
-void MD5Pad(MD5_CTX *);
-void MD5Final(uint8_t [MD5_DIGEST_LENGTH], MD5_CTX *)
- __attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH)));
-void MD5Transform(uint32_t [4], const uint8_t [MD5_BLOCK_LENGTH])
- __attribute__((__bounded__(__minbytes__,1,4)))
- __attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH)));
-char *MD5End(MD5_CTX *, char *)
- __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
-char *MD5File(const char *, char *)
- __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
-char *MD5FileChunk(const char *, char *, off_t, off_t)
- __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
-char *MD5Data(const uint8_t *, size_t, char *)
- __attribute__((__bounded__(__string__,1,2)))
- __attribute__((__bounded__(__minbytes__,3,MD5_DIGEST_STRING_LENGTH)));
-__END_DECLS
-
-#endif /* LIBBSD_MD5_H */
diff --git a/man/libbsd.7 b/man/libbsd.7
index 407b3e4..bfaa3ce 100644
--- a/man/libbsd.7
+++ b/man/libbsd.7
@@ -180,9 +180,10 @@ for example.
.It Fn MD5File 3
.It Fn MD5FileChunk 3
.It Fn MD5Data 3
-The set of MD5 digest functions are now provided by the
+The set of MD5 digest functions are now proxies for the implementations
+provided by the
.Nm libmd
-companion library, so it is advised to use that instead.
+companion library, so it is advised to switch to use that directly instead.
.It Fn explicit_bzero 3
This function is provided by
.Nm glibc
diff --git a/src/Makefile.am b/src/Makefile.am
index c13d385..48fb1fa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,7 +15,6 @@ AM_CPPFLAGS += \
endif
libbsd_la_included_sources = \
- hash/helper.c \
getentropy_aix.c \
getentropy_bsd.c \
getentropy_hpux.c \
@@ -34,10 +33,6 @@ EXTRA_DIST = \
$(libbsd_la_included_sources) \
$(nil)
-CLEANFILES = \
- hash/md5hl.c \
- $(nil)
-
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = \
libbsd.pc \
@@ -53,14 +48,11 @@ pkgconfig_DATA += libbsd-ctor.pc
lib_LIBRARIES += libbsd-ctor.a
endif
-hash/md5hl.c: $(srcdir)/hash/helper.c
- $(AM_V_at) $(MKDIR_P) hash
- $(AM_V_GEN) sed -e 's:hashinc:md5.h:g' -e 's:HASH:MD5:g' $< > $@
-
libbsd_la_DEPENDENCIES = \
$(libbsd_la_included_sources) \
libbsd.map
libbsd_la_LIBADD = \
+ $(MD_LIBS) \
$(CLOCK_GETTIME_LIBS) \
$(ARC4RANDOM_ATFORK_LIBS) \
$(nil)
@@ -95,15 +87,12 @@ libbsd_la_SOURCES = \
funopen.c \
getbsize.c \
getpeereid.c \
- hash/md5.c \
- hash/md5hl.c \
- hash/sha512.h \
- hash/sha512c.c \
heapsort.c \
humanize_number.c \
inet_net_pton.c \
local-elf.h \
local-link.h \
+ md5.c \
merge.c \
nlist.c \
pidfile.c \
diff --git a/src/getentropy_aix.c b/src/getentropy_aix.c
index d759fe0..a963071 100644
--- a/src/getentropy_aix.c
+++ b/src/getentropy_aix.c
@@ -39,7 +39,7 @@
#include <string.h>
#include <termios.h>
-#include "hash/sha512.h"
+#include <sha512.h>
#include <libperfstat.h>
@@ -54,9 +54,9 @@
HD(b); \
} while (0)
-#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
-#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
-#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
+#define HR(x, l) (SHA512_Update(&ctx, (uint8_t *)(x), (l)))
+#define HD(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (x)))
+#define HF(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (void*)))
int getentropy(void *buf, size_t len);
diff --git a/src/getentropy_hpux.c b/src/getentropy_hpux.c
index 5be096a..b21ff4f 100644
--- a/src/getentropy_hpux.c
+++ b/src/getentropy_hpux.c
@@ -42,7 +42,7 @@
#include <unistd.h>
#include <time.h>
-#include "hash/sha512.h"
+#include <sha512.h>
#include <sys/vfs.h>
@@ -59,9 +59,9 @@
HD(b); \
} while (0)
-#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
-#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
-#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
+#define HR(x, l) (SHA512_Update(&ctx, (uint8_t *)(x), (l)))
+#define HD(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (x)))
+#define HF(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (void*)))
int getentropy(void *buf, size_t len);
diff --git a/src/getentropy_hurd.c b/src/getentropy_hurd.c
index 738dc3b..2f76baa 100644
--- a/src/getentropy_hurd.c
+++ b/src/getentropy_hurd.c
@@ -44,7 +44,7 @@
#include <unistd.h>
#include <time.h>
-#include "hash/sha512.h"
+#include <sha512.h>
#ifdef HAVE_GETAUXVAL
#include <sys/auxv.h>
@@ -62,9 +62,9 @@
HD(b); \
} while (0)
-#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
-#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
-#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
+#define HR(x, l) (SHA512_Update(&ctx, (uint8_t *)(x), (l)))
+#define HD(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (x)))
+#define HF(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (void*)))
int getentropy(void *buf, size_t len);
@@ -228,7 +228,7 @@ getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data)
{
SHA512_CTX *ctx = data;
- SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr));
+ SHA512_Update(ctx, (uint8_t *)&info->dlpi_addr, sizeof (info->dlpi_addr));
return (0);
}
diff --git a/src/getentropy_linux.c b/src/getentropy_linux.c
index 74d965e..25c986e 100644
--- a/src/getentropy_linux.c
+++ b/src/getentropy_linux.c
@@ -48,7 +48,7 @@
#include <unistd.h>
#include <time.h>
-#include "hash/sha512.h"
+#include <sha512.h>
#include <linux/types.h>
#include <linux/random.h>
@@ -68,9 +68,9 @@
HD(b); \
} while (0)
-#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
-#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
-#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
+#define HR(x, l) (SHA512_Update(&ctx, (uint8_t *)(x), (l)))
+#define HD(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (x)))
+#define HF(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (void*)))
int getentropy(void *buf, size_t len);
@@ -333,7 +333,7 @@ getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data)
{
SHA512_CTX *ctx = data;
- SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr));
+ SHA512_Update(ctx, (uint8_t *)&info->dlpi_addr, sizeof (info->dlpi_addr));
return (0);
}
diff --git a/src/getentropy_osx.c b/src/getentropy_osx.c
index bcdbce5..d67f33d 100644
--- a/src/getentropy_osx.c
+++ b/src/getentropy_osx.c
@@ -76,9 +76,9 @@
HD(b); \
} while (0)
-#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
-#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
-#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
+#define HR(x, l) (SHA512_Update(&ctx, (uint8_t *)(x), (l)))
+#define HD(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (x)))
+#define HF(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (void*)))
int getentropy(void *buf, size_t len);
diff --git a/src/getentropy_solaris.c b/src/getentropy_solaris.c
index f0fcdcf..05d3e23 100644
--- a/src/getentropy_solaris.c
+++ b/src/getentropy_solaris.c
@@ -62,9 +62,9 @@
HD(b); \
} while (0)
-#define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
-#define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
-#define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
+#define HR(x, l) (SHA512_Update(&ctx, (uint8_t *)(x), (l)))
+#define HD(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (x)))
+#define HF(x) (SHA512_Update(&ctx, (uint8_t *)&(x), sizeof (void*)))
int getentropy(void *buf, size_t len);
@@ -249,7 +249,7 @@ getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data)
{
SHA512_CTX *ctx = data;
- SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr));
+ SHA512_Update(ctx, (uint8_t *)&info->dlpi_addr, sizeof (info->dlpi_addr));
return (0);
}
diff --git a/src/hash/.gitignore b/src/hash/.gitignore
deleted file mode 100644
index bfdcb6a..0000000
--- a/src/hash/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-md5hl.c
diff --git a/src/hash/helper.c b/src/hash/helper.c
deleted file mode 100644
index 352f978..0000000
--- a/src/hash/helper.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/** $MirOS: src/lib/libc/hash/helper.c,v 1.5 2007/05/07 15:21:18 tg Exp $ */
-/* $OpenBSD: helper.c,v 1.8 2005/08/08 08:05:35 espie Exp $ */
-
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk at login.dkuug.dk> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. 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/param.h>
-#include <sys/stat.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#ifdef _WIN32
-#include <io.h>
-#endif
-
-#include <hashinc>
-
-/* ARGSUSED */
-char *
-HASHEnd(HASH_CTX *ctx, char *buf)
-{
- int i;
- uint8_t digest[HASH_DIGEST_LENGTH];
-#ifdef HASH_DIGEST_UPPERCASE
- static const char hex[] = "0123456789ABCDEF";
-#else
- static const char hex[] = "0123456789abcdef";
-#endif
-
- if (buf == NULL && (buf = malloc(HASH_DIGEST_STRING_LENGTH)) == NULL)
- return (NULL);
-
- HASHFinal(digest, ctx);
- for (i = 0; i < HASH_DIGEST_LENGTH; i++) {
- buf[i + i] = hex[digest[i] >> 4];
- buf[i + i + 1] = hex[digest[i] & 0x0f];
- }
- buf[i + i] = '\0';
- memset(digest, 0, sizeof(digest));
- return (buf);
-}
-
-char *
-HASHFileChunk(const char *filename, char *buf, off_t off, off_t len)
-{
- struct stat sb;
- unsigned char buffer[BUFSIZ];
- HASH_CTX ctx;
- int fd, save_errno;
- ssize_t nr;
-
- HASHInit(&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 ((len < 0) || (off > 0 && lseek(fd, off, SEEK_SET) < 0)) {
- close(fd);
- return (NULL);
- }
-
- while ((nr = read(fd, buffer,
- (size_t)(len ? MIN(BUFSIZ, len) : BUFSIZ))) > 0) {
- HASHUpdate(&ctx, buffer, (size_t)nr);
- if (len > 0 && (len -= nr) == 0)
- break;
- }
-
- save_errno = errno;
- close(fd);
- errno = save_errno;
- return (nr < 0 ? NULL : HASHEnd(&ctx, buf));
-}
-
-char *
-HASHFile(const char *filename, char *buf)
-{
- return (HASHFileChunk(filename, buf, (off_t)0, (off_t)0));
-}
-
-char *
-HASHData(const unsigned char *data, size_t len, char *buf)
-{
- HASH_CTX ctx;
-
- HASHInit(&ctx);
- HASHUpdate(&ctx, data, len);
- return (HASHEnd(&ctx, buf));
-}
diff --git a/src/hash/md5.c b/src/hash/md5.c
deleted file mode 100644
index 7e9672e..0000000
--- a/src/hash/md5.c
+++ /dev/null
@@ -1,248 +0,0 @@
-/* $OpenBSD: md5.c,v 1.8 2005/08/08 08:05:35 espie Exp $ */
-
-/*
- * 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 <sys/types.h>
-#include <string.h>
-#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 uint8_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 += (uint64_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)
-{
- uint8_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);
- if (digest != NULL) {
- 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<<s | 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(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
-{
- uint32_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] = (uint32_t)(
- (uint32_t)(block[a * 4 + 0]) |
- (uint32_t)(block[a * 4 + 1]) << 8 |
- (uint32_t)(block[a * 4 + 2]) << 16 |
- (uint32_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/src/hash/sha512.h b/src/hash/sha512.h
deleted file mode 100644
index 4f368a1..0000000
--- a/src/hash/sha512.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*-
- * Copyright 2005 Colin Percival
- * 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.
- *
- * 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.
- *
- * $FreeBSD$
- */
-
-#ifndef _SHA512_H_
-#define _SHA512_H_
-
-#include <sys/types.h>
-
-#define SHA512_DIGEST_LENGTH 64
-
-typedef struct SHA512Context {
- uint64_t state[8];
- uint64_t count[2];
- unsigned char buf[128];
-} SHA512_CTX;
-
-__BEGIN_DECLS
-
-void SHA512_Init(SHA512_CTX *);
-void SHA512_Update(SHA512_CTX *, const void *, size_t);
-void SHA512_Final(unsigned char [64], SHA512_CTX *);
-char *SHA512_End(SHA512_CTX *, char *);
-char *SHA512_File(const char *, char *);
-char *SHA512_FileChunk(const char *, char *, off_t, off_t);
-char *SHA512_Data(const void *, unsigned int, char *);
-__END_DECLS
-
-#endif /* !_SHA512_H_ */
diff --git a/src/hash/sha512c.c b/src/hash/sha512c.c
deleted file mode 100644
index b3c8d5e..0000000
--- a/src/hash/sha512c.c
+++ /dev/null
@@ -1,318 +0,0 @@
-/*-
- * Copyright 2005 Colin Percival
- * 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.
- *
- * 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.
- */
-
-#include <sys/cdefs.h>
-#include <sys/endian.h>
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "sha512.h"
-
-#if BYTE_ORDER == BIG_ENDIAN
-
-/* Copy a vector of big-endian uint64_t into a vector of bytes */
-#define be64enc_vect(dst, src, len) \
- memcpy((void *)dst, (const void *)src, (size_t)len)
-
-/* Copy a vector of bytes into a vector of big-endian uint64_t */
-#define be64dec_vect(dst, src, len) \
- memcpy((void *)dst, (const void *)src, (size_t)len)
-
-#else /* BYTE_ORDER != BIG_ENDIAN */
-
-/*
- * Encode a length len/4 vector of (uint64_t) into a length len vector of
- * (unsigned char) in big-endian form. Assumes len is a multiple of 8.
- */
-static void
-be64enc_vect(unsigned char *dst, const uint64_t *src, size_t len)
-{
- size_t i;
-
- for (i = 0; i < len / 8; i++)
- be64enc(dst + i * 8, src[i]);
-}
-
-/*
- * Decode a big-endian length len vector of (unsigned char) into a length
- * len/4 vector of (uint64_t). Assumes len is a multiple of 8.
- */
-static void
-be64dec_vect(uint64_t *dst, const unsigned char *src, size_t len)
-{
- size_t i;
-
- for (i = 0; i < len / 8; i++)
- dst[i] = be64dec(src + i * 8);
-}
-
-#endif /* BYTE_ORDER != BIG_ENDIAN */
-
-/* Elementary functions used by SHA512 */
-#define Ch(x, y, z) ((x & (y ^ z)) ^ z)
-#define Maj(x, y, z) ((x & (y | z)) | (y & z))
-#define SHR(x, n) (x >> n)
-#define ROTR(x, n) ((x >> n) | (x << (64 - n)))
-#define S0(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39))
-#define S1(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41))
-#define s0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHR(x, 7))
-#define s1(x) (ROTR(x, 19) ^ ROTR(x, 61) ^ SHR(x, 6))
-
-/* SHA512 round function */
-#define RND(a, b, c, d, e, f, g, h, k) \
- t0 = h + S1(e) + Ch(e, f, g) + k; \
- t1 = S0(a) + Maj(a, b, c); \
- d += t0; \
- h = t0 + t1;
-
-/* Adjusted round function for rotating state */
-#define RNDr(S, W, i, k) \
- RND(S[(80 - i) % 8], S[(81 - i) % 8], \
- S[(82 - i) % 8], S[(83 - i) % 8], \
- S[(84 - i) % 8], S[(85 - i) % 8], \
- S[(86 - i) % 8], S[(87 - i) % 8], \
- W[i] + k)
-
-/*
- * SHA512 block compression function. The 512-bit state is transformed via
- * the 512-bit input block to produce a new state.
- */
-static void
-SHA512_Transform(uint64_t * state, const unsigned char block[128])
-{
- uint64_t W[80];
- uint64_t S[8];
- uint64_t t0, t1;
- int i;
-
- /* 1. Prepare message schedule W. */
- be64dec_vect(W, block, 128);
- for (i = 16; i < 80; i++)
- W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16];
-
- /* 2. Initialize working variables. */
- memcpy(S, state, 64);
-
- /* 3. Mix. */
- RNDr(S, W, 0, 0x428a2f98d728ae22ULL);
- RNDr(S, W, 1, 0x7137449123ef65cdULL);
- RNDr(S, W, 2, 0xb5c0fbcfec4d3b2fULL);
- RNDr(S, W, 3, 0xe9b5dba58189dbbcULL);
- RNDr(S, W, 4, 0x3956c25bf348b538ULL);
- RNDr(S, W, 5, 0x59f111f1b605d019ULL);
- RNDr(S, W, 6, 0x923f82a4af194f9bULL);
- RNDr(S, W, 7, 0xab1c5ed5da6d8118ULL);
- RNDr(S, W, 8, 0xd807aa98a3030242ULL);
- RNDr(S, W, 9, 0x12835b0145706fbeULL);
- RNDr(S, W, 10, 0x243185be4ee4b28cULL);
- RNDr(S, W, 11, 0x550c7dc3d5ffb4e2ULL);
- RNDr(S, W, 12, 0x72be5d74f27b896fULL);
- RNDr(S, W, 13, 0x80deb1fe3b1696b1ULL);
- RNDr(S, W, 14, 0x9bdc06a725c71235ULL);
- RNDr(S, W, 15, 0xc19bf174cf692694ULL);
- RNDr(S, W, 16, 0xe49b69c19ef14ad2ULL);
- RNDr(S, W, 17, 0xefbe4786384f25e3ULL);
- RNDr(S, W, 18, 0x0fc19dc68b8cd5b5ULL);
- RNDr(S, W, 19, 0x240ca1cc77ac9c65ULL);
- RNDr(S, W, 20, 0x2de92c6f592b0275ULL);
- RNDr(S, W, 21, 0x4a7484aa6ea6e483ULL);
- RNDr(S, W, 22, 0x5cb0a9dcbd41fbd4ULL);
- RNDr(S, W, 23, 0x76f988da831153b5ULL);
- RNDr(S, W, 24, 0x983e5152ee66dfabULL);
- RNDr(S, W, 25, 0xa831c66d2db43210ULL);
- RNDr(S, W, 26, 0xb00327c898fb213fULL);
- RNDr(S, W, 27, 0xbf597fc7beef0ee4ULL);
- RNDr(S, W, 28, 0xc6e00bf33da88fc2ULL);
- RNDr(S, W, 29, 0xd5a79147930aa725ULL);
- RNDr(S, W, 30, 0x06ca6351e003826fULL);
- RNDr(S, W, 31, 0x142929670a0e6e70ULL);
- RNDr(S, W, 32, 0x27b70a8546d22ffcULL);
- RNDr(S, W, 33, 0x2e1b21385c26c926ULL);
- RNDr(S, W, 34, 0x4d2c6dfc5ac42aedULL);
- RNDr(S, W, 35, 0x53380d139d95b3dfULL);
- RNDr(S, W, 36, 0x650a73548baf63deULL);
- RNDr(S, W, 37, 0x766a0abb3c77b2a8ULL);
- RNDr(S, W, 38, 0x81c2c92e47edaee6ULL);
- RNDr(S, W, 39, 0x92722c851482353bULL);
- RNDr(S, W, 40, 0xa2bfe8a14cf10364ULL);
- RNDr(S, W, 41, 0xa81a664bbc423001ULL);
- RNDr(S, W, 42, 0xc24b8b70d0f89791ULL);
- RNDr(S, W, 43, 0xc76c51a30654be30ULL);
- RNDr(S, W, 44, 0xd192e819d6ef5218ULL);
- RNDr(S, W, 45, 0xd69906245565a910ULL);
- RNDr(S, W, 46, 0xf40e35855771202aULL);
- RNDr(S, W, 47, 0x106aa07032bbd1b8ULL);
- RNDr(S, W, 48, 0x19a4c116b8d2d0c8ULL);
- RNDr(S, W, 49, 0x1e376c085141ab53ULL);
- RNDr(S, W, 50, 0x2748774cdf8eeb99ULL);
- RNDr(S, W, 51, 0x34b0bcb5e19b48a8ULL);
- RNDr(S, W, 52, 0x391c0cb3c5c95a63ULL);
- RNDr(S, W, 53, 0x4ed8aa4ae3418acbULL);
- RNDr(S, W, 54, 0x5b9cca4f7763e373ULL);
- RNDr(S, W, 55, 0x682e6ff3d6b2b8a3ULL);
- RNDr(S, W, 56, 0x748f82ee5defb2fcULL);
- RNDr(S, W, 57, 0x78a5636f43172f60ULL);
- RNDr(S, W, 58, 0x84c87814a1f0ab72ULL);
- RNDr(S, W, 59, 0x8cc702081a6439ecULL);
- RNDr(S, W, 60, 0x90befffa23631e28ULL);
- RNDr(S, W, 61, 0xa4506cebde82bde9ULL);
- RNDr(S, W, 62, 0xbef9a3f7b2c67915ULL);
- RNDr(S, W, 63, 0xc67178f2e372532bULL);
- RNDr(S, W, 64, 0xca273eceea26619cULL);
- RNDr(S, W, 65, 0xd186b8c721c0c207ULL);
- RNDr(S, W, 66, 0xeada7dd6cde0eb1eULL);
- RNDr(S, W, 67, 0xf57d4f7fee6ed178ULL);
- RNDr(S, W, 68, 0x06f067aa72176fbaULL);
- RNDr(S, W, 69, 0x0a637dc5a2c898a6ULL);
- RNDr(S, W, 70, 0x113f9804bef90daeULL);
- RNDr(S, W, 71, 0x1b710b35131c471bULL);
- RNDr(S, W, 72, 0x28db77f523047d84ULL);
- RNDr(S, W, 73, 0x32caab7b40c72493ULL);
- RNDr(S, W, 74, 0x3c9ebe0a15c9bebcULL);
- RNDr(S, W, 75, 0x431d67c49c100d4cULL);
- RNDr(S, W, 76, 0x4cc5d4becb3e42b6ULL);
- RNDr(S, W, 77, 0x597f299cfc657e2aULL);
- RNDr(S, W, 78, 0x5fcb6fab3ad6faecULL);
- RNDr(S, W, 79, 0x6c44198c4a475817ULL);
-
- /* 4. Mix local working variables into global state */
- for (i = 0; i < 8; i++)
- state[i] += S[i];
-}
-
-static unsigned char PAD[128] = {
- 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,
- 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, 0
-};
-
-/* Add padding and terminating bit-count. */
-static void
-SHA512_Pad(SHA512_CTX * ctx)
-{
- unsigned char len[16];
- uint64_t r, plen;
-
- /*
- * Convert length to a vector of bytes -- we do this now rather
- * than later because the length will change after we pad.
- */
- be64enc_vect(len, ctx->count, 16);
-
- /* Add 1--128 bytes so that the resulting length is 112 mod 128 */
- r = (ctx->count[1] >> 3) & 0x7f;
- plen = (r < 112) ? (112 - r) : (240 - r);
- SHA512_Update(ctx, PAD, (size_t)plen);
-
- /* Add the terminating bit-count */
- SHA512_Update(ctx, len, 16);
-}
-
-/* SHA-512 initialization. Begins a SHA-512 operation. */
-void
-SHA512_Init(SHA512_CTX * ctx)
-{
-
- /* Zero bits processed so far */
- ctx->count[0] = ctx->count[1] = 0;
-
- /* Magic initialization constants */
- ctx->state[0] = 0x6a09e667f3bcc908ULL;
- ctx->state[1] = 0xbb67ae8584caa73bULL;
- ctx->state[2] = 0x3c6ef372fe94f82bULL;
- ctx->state[3] = 0xa54ff53a5f1d36f1ULL;
- ctx->state[4] = 0x510e527fade682d1ULL;
- ctx->state[5] = 0x9b05688c2b3e6c1fULL;
- ctx->state[6] = 0x1f83d9abfb41bd6bULL;
- ctx->state[7] = 0x5be0cd19137e2179ULL;
-}
-
-/* Add bytes into the hash */
-void
-SHA512_Update(SHA512_CTX * ctx, const void *in, size_t len)
-{
- uint64_t bitlen[2];
- uint64_t r;
- const unsigned char *src = in;
-
- /* Number of bytes left in the buffer from previous updates */
- r = (ctx->count[1] >> 3) & 0x7f;
-
- /* Convert the length into a number of bits */
- bitlen[1] = ((uint64_t)len) << 3;
- bitlen[0] = ((uint64_t)len) >> 61;
-
- /* Update number of bits */
- if ((ctx->count[1] += bitlen[1]) < bitlen[1])
- ctx->count[0]++;
- ctx->count[0] += bitlen[0];
-
- /* Handle the case where we don't need to perform any transforms */
- if (len < 128 - r) {
- memcpy(&ctx->buf[r], src, len);
- return;
- }
-
- /* Finish the current block */
- memcpy(&ctx->buf[r], src, 128 - r);
- SHA512_Transform(ctx->state, ctx->buf);
- src += 128 - r;
- len -= 128 - r;
-
- /* Perform complete blocks */
- while (len >= 128) {
- SHA512_Transform(ctx->state, src);
- src += 128;
- len -= 128;
- }
-
- /* Copy left over data into buffer */
- memcpy(ctx->buf, src, len);
-}
-
-/*
- * SHA-512 finalization. Pads the input data, exports the hash value,
- * and clears the context state.
- */
-void
-SHA512_Final(unsigned char digest[64], SHA512_CTX * ctx)
-{
-
- /* Add padding */
- SHA512_Pad(ctx);
-
- /* Write the hash */
- be64enc_vect(digest, ctx->state, 64);
-
- /* Clear the context state */
- memset((void *)ctx, 0, sizeof(*ctx));
-}
diff --git a/src/libbsd.map b/src/libbsd.map
index 34e709b..fb2888f 100644
--- a/src/libbsd.map
+++ b/src/libbsd.map
@@ -35,6 +35,8 @@ LIBBSD_0.0 {
strunvis;
strunvisx;
+ /* The following functions are provided via the system libc or libmd
+ * implementations. */
MD5Init;
MD5Update;
MD5Pad;
diff --git a/src/md5.c b/src/md5.c
new file mode 100644
index 0000000..b74ce7d
--- /dev/null
+++ b/src/md5.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright © 2021 Guillem Jover <guillem at hadrons.org>
+ *
+ * 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 <md5.h>
+#include "local-link.h"
+
+void
+bsd_MD5Init(MD5_CTX *context)
+{
+ MD5Init(context);
+}
+libbsd_symver_variant(MD5Init, bsd_MD5Init, LIBBSD_0.0);
+
+void
+bsd_MD5Update(MD5_CTX *context, const uint8_t *data, size_t len)
+{
+ MD5Update(context, data, len);
+}
+libbsd_symver_variant(MD5Update, bsd_MD5Update, LIBBSD_0.0);
+
+void
+bsd_MD5Pad(MD5_CTX *context)
+{
+ MD5Pad(context);
+}
+libbsd_symver_variant(MD5Pad, bsd_MD5Pad, LIBBSD_0.0);
+
+void
+bsd_MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context)
+{
+ MD5Final(digest, context);
+}
+libbsd_symver_variant(MD5Final, bsd_MD5Final, LIBBSD_0.0);
+
+void
+bsd_MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
+{
+ MD5Transform(state, block);
+}
+libbsd_symver_variant(MD5Transform, bsd_MD5Transform, LIBBSD_0.0);
+
+char *
+bsd_MD5End(MD5_CTX *context, char *buf)
+{
+ return MD5End(context, buf);
+}
+libbsd_symver_variant(MD5End, bsd_MD5End, LIBBSD_0.0);
+
+char *
+bsd_MD5File(const char *filename, char *buf)
+{
+ return MD5File(filename, buf);
+}
+libbsd_symver_variant(MD5File, bsd_MD5File, LIBBSD_0.0);
+
+char *
+bsd_MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length)
+{
+ return MD5FileChunk(filename, buf, offset, length);
+}
+libbsd_symver_variant(MD5FileChunk, bsd_MD5FileChunk, LIBBSD_0.0);
+
+char *
+bsd_MD5Data(const uint8_t *data, size_t len, char *buf)
+{
+ return MD5Data(data, len, buf);
+}
+libbsd_symver_variant(MD5Data, bsd_MD5Data, LIBBSD_0.0);
diff --git a/test/Makefile.am b/test/Makefile.am
index 90fe384..a1c8e68 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -52,6 +52,8 @@ check_PROGRAMS = \
vis-openbsd \
$(nil)
+md5_LDADD = $(LDADD) $(MD_LIBS)
+
if HAVE_LIBTESTU01
arc4random_LDADD = $(LDADD) $(TESTU01_LIBS)
commit 68f980c90d914e5fd6f7512e00dec334dbb71bed
Author: Aaron Dierking <aarond at fb.com>
Date: Thu Jul 5 14:47:47 2018 -0700
Provide a default progname on Windows
[guillem at hadrons.org:
- Remove .exe extension from default program name.
- Call reallocarray() once by switching to a «do {} while» loop.
- Minor coding style fixes. ]
Signed-off-by: Guillem Jover <guillem at hadrons.org>
diff --git a/src/progname.c b/src/progname.c
index 3edbf24..bebf714 100644
--- a/src/progname.c
+++ b/src/progname.c
@@ -1,6 +1,7 @@
/*
* Copyright © 2006 Robert Millan
* Copyright © 2010-2012 Guillem Jover <guillem at hadrons.org>
+ * Copyright © 2018 Facebook, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,11 +31,16 @@
* <https://sourceware.org/ml/libc-alpha/2006-03/msg00125.html>.
*/
+#include <sys/param.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
+#ifdef _WIN32
+#include <Windows.h>
+#include <shlwapi.h>
+#endif
-#if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)
+#ifdef _WIN32
#define LIBBSD_IS_PATHNAME_SEPARATOR(c) ((c) == '/' || (c) == '\\')
#else
#define LIBBSD_IS_PATHNAME_SEPARATOR(c) ((c) == '/')
@@ -56,6 +62,70 @@ getprogname(void)
/* getexecname(3) returns an absolute pathname, normalize it. */
if (__progname == NULL)
setprogname(getexecname());
+#elif defined(_WIN32)
+ if (__progname == NULL) {
+ WCHAR *wpath = NULL;
+ WCHAR *wname = NULL;
+ WCHAR *wext = NULL;
+ DWORD wpathsiz = MAX_PATH / 2;
+ DWORD len, i;
+ char *mbname = NULL;
+ int mbnamesiz;
+
+ /* Use the Unicode version of this function to support long
+ * paths. MAX_PATH isn't actually the maximum length of a
+ * path in this case. */
+ do {
+ WCHAR *wpathnew;
+
+ wpathsiz *= 2;
+ wpathsiz = MIN(wpathsiz, UNICODE_STRING_MAX_CHARS);
+ wpathnew = reallocarray(wpath, wpathsiz, sizeof(*wpath));
+ if (wpathnew == NULL)
+ goto done;
+ wpath = wpathnew;
+
+ len = GetModuleFileNameW(NULL, wpath, wpathsiz);
+ if (wpathsiz == UNICODE_STRING_MAX_CHARS)
+ goto done;
+ } while (wpathsiz == len);
+ if (len == 0)
+ goto done;
+
+ /* GetModuleFileNameW() retrieves an absolute path. Locate the
+ * filename now to only convert necessary characters and save
+ * memory. */
+ wname = wpath;
+ for (i = len; i > 0; i--) {
+ if (LIBBSD_IS_PATHNAME_SEPARATOR(wpath[i - 1])) {
+ wname = wpath + i;
+ break;
+ }
+ }
+
+ /* Remove any trailing extension, such as '.exe', to make the
+ * behavior mach the non-Windows systems. */
+ wext = PathFindExtensionW(wname);
+ wext[0] = '\0';
+
+ mbnamesiz = WideCharToMultiByte(CP_UTF8, 0, wname, -1, NULL,
+ 0, NULL, NULL);
+ if (mbnamesiz == 0)
+ goto done;
+ mbname = malloc(mbnamesiz);
+ if (mbname == NULL)
+ goto done;
+ mbnamesiz = WideCharToMultiByte(CP_UTF8, 0, wname, -1, mbname,
+ mbnamesiz, NULL, NULL);
+ if (mbnamesiz == 0)
+ goto done;
+ __progname = mbname;
+ mbname = NULL;
+
+done:
+ free(wpath);
+ free(mbname);
+ }
#endif
return __progname;
commit 37a9b56c05339301510213c41fc507ea31cc2464
Author: Guillem Jover <guillem at hadrons.org>
Date: Sat Feb 6 23:43:12 2021 +0100
Import pwcache module from OpenBSD
diff --git a/COPYING b/COPYING
index d3899a9..34ec432 100644
--- a/COPYING
+++ b/COPYING
@@ -105,6 +105,7 @@ Files:
man/getbsize.3bsd
man/heapsort.3bsd
man/nlist.3bsd
+ man/pwcache.3bsd
man/queue.3bsd
man/radixsort.3bsd
man/reallocarray.3bsd
@@ -121,6 +122,7 @@ Files:
src/heapsort.c
src/merge.c
src/nlist.c
+ src/pwcache.c
src/radixsort.c
src/setmode.c
src/strmode.c
@@ -131,6 +133,7 @@ Files:
Copyright:
Copyright © 1980, 1982, 1986, 1989-1994
The Regents of the University of California. All rights reserved.
+ Copyright © 1992 Keith Muller.
Copyright © 2001 Mike Barcroft <mike at FreeBSD.org>
.
Some code is derived from software contributed to Berkeley by
diff --git a/configure.ac b/configure.ac
index e8d4c5f..cf064bb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,7 +87,7 @@ AS_CASE([$host_os],
AM_CONDITIONAL([OS_WINDOWS], [test "x$is_windows" = "xyes"])
# Checks for header files.
-AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h grp.h])
+AC_CHECK_HEADERS([sys/ndir.h sys/dir.h ndir.h dirent.h pwd.h grp.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_INLINE
diff --git a/include/Makefile.am b/include/Makefile.am
index 949ea80..e6f66bd 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -14,10 +14,12 @@ nobase_include_HEADERS = \
bsd/bsd.h \
bsd/err.h \
bsd/getopt.h \
+ bsd/grp.h \
bsd/inttypes.h \
bsd/libutil.h \
bsd/md5.h \
bsd/nlist.h \
+ bsd/pwd.h \
bsd/readpassphrase.h \
bsd/stdio.h \
bsd/stdlib.h \
diff --git a/include/bsd/grp.h b/include/bsd/grp.h
new file mode 100644
index 0000000..b2705e5
--- /dev/null
+++ b/include/bsd/grp.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2021 Guillem Jover <guillem at hadrons.org>
+ *
+ * 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.
+ */
+
+#ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<grp.h>)
+#include_next <grp.h>
+#endif
+#else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<grp.h>)
+#include <grp.h>
+#endif
+#endif
+
+#ifndef LIBBSD_GRP_H
+#define LIBBSD_GRP_H
+
+#define _GR_BUF_LEN (1024 + 200 * sizeof(char *))
+
+__BEGIN_DECLS
+int
+gid_from_group(const char *, gid_t *);
+const char *
+group_from_gid(gid_t, int);
+__END_DECLS
+
+#endif
diff --git a/include/bsd/pwd.h b/include/bsd/pwd.h
new file mode 100644
index 0000000..798af4b
--- /dev/null
+++ b/include/bsd/pwd.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2021 Guillem Jover <guillem at hadrons.org>
+ *
+ * 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.
+ */
+
+#ifdef LIBBSD_OVERLAY
+#include <sys/cdefs.h>
+#if __has_include_next(<pwd.h>)
+#include_next <pwd.h>
+#endif
+#else
+#include <bsd/sys/cdefs.h>
+#if __has_include(<pwd.h>)
+#include <pwd.h>
+#endif
+#endif
+
+#ifndef LIBBSD_PWD_H
+#define LIBBSD_PWD_H
+
+#define _PW_BUF_LEN 1024 /* length of getpw*_r buffer */
+
+__BEGIN_DECLS
+int
+uid_from_user(const char *, uid_t *);
+const char *
+user_from_uid(uid_t, int);
+__END_DECLS
+
+#endif
diff --git a/man/Makefile.am b/man/Makefile.am
index 4c7ed05..25e9566 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -174,6 +174,8 @@ dist_man_MANS = \
getmode.3bsd \
getpeereid.3bsd \
getprogname.3bsd \
+ gid_from_group.3bsd \
+ group_from_gid.3bsd \
heapsort.3bsd \
humanize_number.3bsd \
le16dec.3bsd \
@@ -191,6 +193,7 @@ dist_man_MANS = \
pidfile_open.3bsd \
pidfile_remove.3bsd \
pidfile_write.3bsd \
+ pwcache.3bsd \
queue.3bsd \
radixsort.3bsd \
readpassphrase.3bsd \
@@ -233,7 +236,9 @@ dist_man_MANS = \
timespecsub.3bsd \
timeval.3bsd \
tree.3bsd \
+ uid_from_user.3bsd \
unvis.3bsd \
+ user_from_uid.3bsd \
vis.3bsd \
wcslcat.3bsd \
wcslcpy.3bsd \
diff --git a/man/gid_from_group.3bsd b/man/gid_from_group.3bsd
new file mode 100644
index 0000000..6ddd88c
--- /dev/null
+++ b/man/gid_from_group.3bsd
@@ -0,0 +1 @@
+.so man3/pwcache.3bsd
diff --git a/man/group_from_gid.3bsd b/man/group_from_gid.3bsd
new file mode 100644
index 0000000..6ddd88c
--- /dev/null
+++ b/man/group_from_gid.3bsd
@@ -0,0 +1 @@
+.so man3/pwcache.3bsd
diff --git a/man/pwcache.3bsd b/man/pwcache.3bsd
new file mode 100644
index 0000000..dac9bcd
--- /dev/null
+++ b/man/pwcache.3bsd
@@ -0,0 +1,143 @@
+.\" $OpenBSD: pwcache.3,v 1.15 2018/09/13 16:50:54 jmc Exp $
+.\"
+.\" Copyright (c) 1989, 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.
+.\"
+.Dd $Mdocdate: September 13 2018 $
+.Dt USER_FROM_UID 3
+.Os
+.Sh NAME
+.Nm user_from_uid ,
+.Nm uid_from_user ,
+.Nm group_from_gid ,
+.Nm gid_from_group
+.Nd cache password and group entries
+.Sh LIBRARY
+.ds str-Lb-libbsd Utility functions from BSD systems (libbsd, \-lbsd)
+.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
+.Lb libbsd
+.Sh SYNOPSIS
+.In pwd.h
+(See
+.Xr libbsd 7
+for include usage.)
+.Ft int
+.Fn uid_from_user "const char *name" "uid_t *uid"
+.Ft const char *
+.Fn user_from_uid "uid_t uid" "int nouser"
+.In grp.h
+.Ft int
+.Fn gid_from_group "const char *name" "gid_t *gid"
+.Ft const char *
+.Fn group_from_gid "gid_t gid" "int nogroup"
+.Sh DESCRIPTION
+The
+.Fn user_from_uid
+function returns the user name associated with the argument
+.Fa uid .
+The user name is cached so that multiple calls with the same
+.Fa uid
+do not require additional calls to
+.Xr getpwuid 3 .
+If there is no user associated with the
+.Fa uid ,
+a pointer is returned
+to a string representation of the
+.Fa uid ,
+unless the argument
+.Fa nouser
+is non-zero, in which case a null pointer is returned.
+.Pp
+The
+.Fn uid_from_user
+function returns the user ID associated with the argument
+.Fa name .
+The user ID is cached so that multiple calls with the same
+.Fa name
+do not require additional calls to
+.Xr getpwnam 3 .
+If there is no user ID associated with the
+.Fa name ,
+the
+.Fn uid_from_user
+function returns -1;
+otherwise it stores the user ID at the location pointed to by
+.Fa uid
+and returns 0.
+.Pp
+The
+.Fn group_from_gid
+function returns the group name associated with the argument
+.Fa gid .
+The group name is cached so that multiple calls with the same
+.Fa gid
+do not require additional calls to
+.Xr getgrgid 3 .
+If there is no group associated with the
+.Fa gid ,
+a pointer is returned
+to a string representation of the
+.Fa gid ,
+unless the argument
+.Fa nogroup
+is non-zero, in which case a null pointer is returned.
+.Pp
+The
+.Fn gid_from_group
+function returns the group ID associated with the argument
+.Fa name .
+The group ID is cached so that multiple calls with the same
+.Fa name
+do not require additional calls to
+.Xr getgrnam 3 .
+If there is no group ID associated with the
+.Fa name ,
+the
+.Fn gid_from_group
+function returns -1;
+otherwise it stores the group ID at the location pointed to by
+.Fa gid
+and returns 0.
+.Sh SEE ALSO
+.Xr getgrgid 3 ,
+.Xr getpwuid 3
+.Sh HISTORY
+The
+.Fn user_from_uid
+and
+.Fn group_from_gid
+functions first appeared in
+.Bx 4.4 .
+.Pp
+The
+.Fn uid_from_user
+and
+.Fn gid_from_group
+functions were ported from
+.Nx
+and first appeared in
+.Ox 6.4 .
diff --git a/man/uid_from_user.3bsd b/man/uid_from_user.3bsd
new file mode 100644
index 0000000..6ddd88c
--- /dev/null
+++ b/man/uid_from_user.3bsd
@@ -0,0 +1 @@
+.so man3/pwcache.3bsd
diff --git a/man/user_from_uid.3bsd b/man/user_from_uid.3bsd
new file mode 100644
index 0000000..6ddd88c
--- /dev/null
+++ b/man/user_from_uid.3bsd
@@ -0,0 +1 @@
+.so man3/pwcache.3bsd
diff --git a/src/Makefile.am b/src/Makefile.am
index 75cdecd..c13d385 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -108,6 +108,7 @@ libbsd_la_SOURCES = \
nlist.c \
pidfile.c \
progname.c \
+ pwcache.c \
radixsort.c \
readpassphrase.c \
reallocarray.c \
diff --git a/src/libbsd.map b/src/libbsd.map
index f499f8e..34e709b 100644
--- a/src/libbsd.map
+++ b/src/libbsd.map
@@ -187,4 +187,9 @@ LIBBSD_0.11.0 {
recallocarray;
freezero;
+
+ gid_from_group;
+ group_from_gid;
+ uid_from_user;
+ user_from_uid;
} LIBBSD_0.10.0;
diff --git a/src/pwcache.c b/src/pwcache.c
new file mode 100644
index 0000000..d54daa0
--- /dev/null
+++ b/src/pwcache.c
@@ -0,0 +1,437 @@
+/* $OpenBSD: pwcache.c,v 1.15 2018/09/22 02:47:23 millert Exp $ */
+
+/*-
+ * Copyright (c) 1992 Keith Muller.
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Keith Muller of the University of California, San Diego.
+ *
+ * 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 <assert.h>
+#include <grp.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+ * Constants and data structures used to implement group and password file
+ * caches. Name lengths have been chosen to be as large as those supported
+ * by the passwd and group files as well as the standard archive formats.
+ * CACHE SIZES MUST BE PRIME
+ */
+#define UNMLEN 32 /* >= user name found in any protocol */
+#define GNMLEN 32 /* >= group name found in any protocol */
+#define UID_SZ 317 /* size of uid to user_name cache */
+#define UNM_SZ 317 /* size of user_name to uid cache */
+#define GID_SZ 251 /* size of gid to group_name cache */
+#define GNM_SZ 251 /* size of group_name to gid cache */
+#define VALID 1 /* entry and name are valid */
+#define INVALID 2 /* entry valid, name NOT valid */
+
+/*
+ * Node structures used in the user, group, uid, and gid caches.
+ */
+
+typedef struct uidc {
+ int valid; /* is this a valid or a miss entry */
+ char name[UNMLEN]; /* uid name */
+ uid_t uid; /* cached uid */
+} UIDC;
+
+typedef struct gidc {
+ int valid; /* is this a valid or a miss entry */
+ char name[GNMLEN]; /* gid name */
+ gid_t gid; /* cached gid */
+} GIDC;
+
+/*
+ * Routines that control user, group, uid and gid caches.
+ * Traditional passwd/group cache routines perform quite poorly with
+ * archives. The chances of hitting a valid lookup with an archive is quite a
+ * bit worse than with files already resident on the file system. These misses
+ * create a MAJOR performance cost. To adress this problem, these routines
+ * cache both hits and misses.
+ */
+
+static UIDC **uidtb; /* uid to name cache */
+static GIDC **gidtb; /* gid to name cache */
+static UIDC **usrtb; /* user name to uid cache */
+static GIDC **grptb; /* group name to gid cache */
+
+static u_int
+st_hash(const char *name, size_t len, int tabsz)
+{
+ u_int key = 0;
+
+ assert(name != NULL);
+
+ while (len--) {
+ key += *name++;
+ key = (key << 8) | (key >> 24);
+ }
+
+ return key % tabsz;
+}
+
+/*
+ * uidtb_start
+ * creates an an empty uidtb
+ * Return:
+ * 0 if ok, -1 otherwise
+ */
+static int
+uidtb_start(void)
+{
+ static int fail = 0;
+
+ if (uidtb != NULL)
+ return 0;
+ if (fail)
+ return -1;
+ if ((uidtb = calloc(UID_SZ, sizeof(UIDC *))) == NULL) {
+ ++fail;
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * gidtb_start
+ * creates an an empty gidtb
+ * Return:
+ * 0 if ok, -1 otherwise
+ */
+static int
+gidtb_start(void)
+{
+ static int fail = 0;
+
+ if (gidtb != NULL)
+ return 0;
+ if (fail)
+ return -1;
+ if ((gidtb = calloc(GID_SZ, sizeof(GIDC *))) == NULL) {
+ ++fail;
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * usrtb_start
+ * creates an an empty usrtb
+ * Return:
+ * 0 if ok, -1 otherwise
+ */
+static int
+usrtb_start(void)
+{
+ static int fail = 0;
+
+ if (usrtb != NULL)
+ return 0;
+ if (fail)
+ return -1;
+ if ((usrtb = calloc(UNM_SZ, sizeof(UIDC *))) == NULL) {
+ ++fail;
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * grptb_start
+ * creates an an empty grptb
+ * Return:
+ * 0 if ok, -1 otherwise
+ */
+static int
+grptb_start(void)
+{
+ static int fail = 0;
+
+ if (grptb != NULL)
+ return 0;
+ if (fail)
+ return -1;
+ if ((grptb = calloc(GNM_SZ, sizeof(GIDC *))) == NULL) {
+ ++fail;
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * user_from_uid()
+ * caches the name (if any) for the uid. If noname clear, we always
+ * return the stored name (if valid or invalid match).
+ * We use a simple hash table.
+ * Return:
+ * Pointer to stored name (or a empty string)
+ */
+const char *
+user_from_uid(uid_t uid, int noname)
+{
+ struct passwd pwstore, *pw = NULL;
+ char pwbuf[_PW_BUF_LEN];
+ UIDC **pptr, *ptr = NULL;
+
+ if ((uidtb != NULL) || (uidtb_start() == 0)) {
+ /*
+ * see if we have this uid cached
+ */
+ pptr = uidtb + (uid % UID_SZ);
+ ptr = *pptr;
+
+ if ((ptr != NULL) && (ptr->valid > 0) && (ptr->uid == uid)) {
+ /*
+ * have an entry for this uid
+ */
+ if (!noname || (ptr->valid == VALID))
+ return ptr->name;
+ return NULL;
+ }
+
+ if (ptr == NULL)
+ *pptr = ptr = malloc(sizeof(UIDC));
+ }
+
+ getpwuid_r(uid, &pwstore, pwbuf, sizeof(pwbuf), &pw);
+ if (pw == NULL) {
+ /*
+ * no match for this uid in the local password file
+ * a string that is the uid in numeric format
+ */
+ if (ptr == NULL)
+ return NULL;
+ ptr->uid = uid;
+ (void)snprintf(ptr->name, UNMLEN, "%u", uid);
+ ptr->valid = INVALID;
+ if (noname)
+ return NULL;
+ } else {
+ /*
+ * there is an entry for this uid in the password file
+ */
+ if (ptr == NULL)
+ return pw->pw_name;
+ ptr->uid = uid;
+ (void)strlcpy(ptr->name, pw->pw_name, sizeof(ptr->name));
+ ptr->valid = VALID;
+ }
+ return ptr->name;
+}
+
+/*
+ * group_from_gid()
+ * caches the name (if any) for the gid. If noname clear, we always
+ * return the stored name (if valid or invalid match).
+ * We use a simple hash table.
+ * Return:
+ * Pointer to stored name (or a empty string)
+ */
+const char *
+group_from_gid(gid_t gid, int noname)
+{
+ struct group grstore, *gr = NULL;
+ char grbuf[_GR_BUF_LEN];
+ GIDC **pptr, *ptr = NULL;
+
+ if ((gidtb != NULL) || (gidtb_start() == 0)) {
+ /*
+ * see if we have this gid cached
+ */
+ pptr = gidtb + (gid % GID_SZ);
+ ptr = *pptr;
+
+ if ((ptr != NULL) && (ptr->valid > 0) && (ptr->gid == gid)) {
+ /*
+ * have an entry for this gid
+ */
+ if (!noname || (ptr->valid == VALID))
+ return ptr->name;
+ return NULL;
+ }
+
+ if (ptr == NULL)
+ *pptr = ptr = malloc(sizeof(GIDC));
+ }
+
+ getgrgid_r(gid, &grstore, grbuf, sizeof(grbuf), &gr);
+ if (gr == NULL) {
+ /*
+ * no match for this gid in the local group file, put in
+ * a string that is the gid in numeric format
+ */
+ if (ptr == NULL)
+ return NULL;
+ ptr->gid = gid;
+ (void)snprintf(ptr->name, GNMLEN, "%u", gid);
+ ptr->valid = INVALID;
+ if (noname)
+ return NULL;
+ } else {
+ /*
+ * there is an entry for this group in the group file
+ */
+ if (ptr == NULL)
+ return gr->gr_name;
+ ptr->gid = gid;
+ (void)strlcpy(ptr->name, gr->gr_name, sizeof(ptr->name));
+ ptr->valid = VALID;
+ }
+ return ptr->name;
+}
+
+/*
+ * uid_from_user()
+ * caches the uid for a given user name. We use a simple hash table.
+ * Return:
+ * 0 if the user name is found (filling in uid), -1 otherwise
+ */
+int
+uid_from_user(const char *name, uid_t *uid)
+{
+ struct passwd pwstore, *pw = NULL;
+ char pwbuf[_PW_BUF_LEN];
+ UIDC **pptr, *ptr = NULL;
+ size_t namelen;
+
+ /*
+ * return -1 for mangled names
+ */
+ if (name == NULL || ((namelen = strlen(name)) == 0))
+ return -1;
+
+ if ((usrtb != NULL) || (usrtb_start() == 0)) {
+ /*
+ * look up in hash table, if found and valid return the uid,
+ * if found and invalid, return a -1
+ */
+ pptr = usrtb + st_hash(name, namelen, UNM_SZ);
+ ptr = *pptr;
+
+ if ((ptr != NULL) && (ptr->valid > 0) &&
+ strcmp(name, ptr->name) == 0) {
+ if (ptr->valid == INVALID)
+ return -1;
+ *uid = ptr->uid;
+ return 0;
+ }
+
+ if (ptr == NULL)
+ *pptr = ptr = malloc(sizeof(UIDC));
+ }
+
+ /*
+ * no match, look it up, if no match store it as an invalid entry,
+ * or store the matching uid
+ */
+ getpwnam_r(name, &pwstore, pwbuf, sizeof(pwbuf), &pw);
+ if (ptr == NULL) {
+ if (pw == NULL)
+ return -1;
+ *uid = pw->pw_uid;
+ return 0;
+ }
+ (void)strlcpy(ptr->name, name, sizeof(ptr->name));
+ if (pw == NULL) {
+ ptr->valid = INVALID;
+ return -1;
+ }
+ ptr->valid = VALID;
+ *uid = ptr->uid = pw->pw_uid;
+ return 0;
+}
+
+/*
+ * gid_from_group()
+ * caches the gid for a given group name. We use a simple hash table.
+ * Return:
+ * 0 if the group name is found (filling in gid), -1 otherwise
+ */
+int
+gid_from_group(const char *name, gid_t *gid)
+{
+ struct group grstore, *gr = NULL;
+ char grbuf[_GR_BUF_LEN];
+ GIDC **pptr, *ptr = NULL;
+ size_t namelen;
+
+ /*
+ * return -1 for mangled names
+ */
+ if (name == NULL || ((namelen = strlen(name)) == 0))
+ return -1;
+
+ if ((grptb != NULL) || (grptb_start() == 0)) {
+ /*
+ * look up in hash table, if found and valid return the uid,
+ * if found and invalid, return a -1
+ */
+ pptr = grptb + st_hash(name, namelen, GID_SZ);
+ ptr = *pptr;
+
+ if ((ptr != NULL) && (ptr->valid > 0) &&
+ strcmp(name, ptr->name) == 0) {
+ if (ptr->valid == INVALID)
+ return -1;
+ *gid = ptr->gid;
+ return 0;
+ }
+
+ if (ptr == NULL)
+ *pptr = ptr = malloc(sizeof(GIDC));
+ }
+
+ /*
+ * no match, look it up, if no match store it as an invalid entry,
+ * or store the matching gid
+ */
+ getgrnam_r(name, &grstore, grbuf, sizeof(grbuf), &gr);
+ if (ptr == NULL) {
+ if (gr == NULL)
+ return -1;
+ *gid = gr->gr_gid;
+ return 0;
+ }
+
+ (void)strlcpy(ptr->name, name, sizeof(ptr->name));
+ if (gr == NULL) {
+ ptr->valid = INVALID;
+ return -1;
+ }
+ ptr->valid = VALID;
+ *gid = ptr->gid = gr->gr_gid;
+ return 0;
+}
diff --git a/test/.gitignore b/test/.gitignore
index 47063b9..2c39751 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -15,6 +15,7 @@ overlay
proctitle-init
proctitle
progname
+pwcache
setmode
strl
strmode
diff --git a/test/Makefile.am b/test/Makefile.am
index 452558d..90fe384 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -43,6 +43,7 @@ check_PROGRAMS = \
nlist \
proctitle-init \
progname \
+ pwcache \
setmode \
strl \
strmode \
diff --git a/test/overlay.c b/test/overlay.c
index a17904f..0ec6d7c 100644
--- a/test/overlay.c
+++ b/test/overlay.c
@@ -28,6 +28,9 @@
* other headers through magic macros, to check that the overlay is working
* properly. */
#include <errno.h>
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
#ifdef HAVE_GRP_H
#include <grp.h>
#endif
diff --git a/test/pwcache.c b/test/pwcache.c
new file mode 100644
index 0000000..d68ea4c
--- /dev/null
+++ b/test/pwcache.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2021 Guillem Jover <guillem at hadrons.org>
+ *
+ * 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 <assert.h>
+#include <string.h>
+#include <pwd.h>
+#include <grp.h>
+
+int
+main(int argc, char **argv)
+{
+ uid_t uid;
+ gid_t gid;
+
+ assert(uid_from_user("root", &uid) == 0);
+ assert(uid == 0);
+
+ assert(strcmp(user_from_uid(0, 0), "root") == 0);
+
+ assert(gid_from_group("root", &gid) == 0);
+ assert(gid == 0);
+
+ assert(strcmp(group_from_gid(0, 0), "root") == 0);
+
+ return 0;
+}
commit 45dd5229ea5f3c62877f5f66f80ab8e52d40a281
Author: Guillem Jover <guillem at hadrons.org>
Date: Sun Feb 7 01:27:51 2021 +0100
man: Remove empty line in reallocarray(3bsd)
Warned-by: lintian
Fixes: commit 01f0d1ea1e71f1018a009ebd9203dd48e6d90c45
diff --git a/man/reallocarray.3bsd b/man/reallocarray.3bsd
index 704466c..b4e5cbe 100644
--- a/man/reallocarray.3bsd
+++ b/man/reallocarray.3bsd
@@ -274,7 +274,6 @@ To avoid leaking information,
it guarantees memory is cleared before placing it on the internal free list.
Deallocation of such an object should be done by calling
.Fn freezero .
-
.Sh SEE ALSO
.Xr malloc 3 ,
.Xr calloc 3 ,
More information about the libbsd
mailing list