mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-19 21:16:55 +02:00
Compare commits
72 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
edddd806df | ||
![]() |
dd0bdb58e0 | ||
![]() |
0813f3786f | ||
![]() |
df116b5597 | ||
![]() |
ecb44e1655 | ||
![]() |
459b7f7d24 | ||
![]() |
a44f885cd4 | ||
![]() |
3f5ca0aae4 | ||
![]() |
9d3e59a01d | ||
![]() |
f02562d64a | ||
![]() |
b7367c9ced | ||
![]() |
6777eb62b8 | ||
![]() |
d4e0cdc916 | ||
![]() |
f41d6c12aa | ||
![]() |
30b48ed9ea | ||
![]() |
d0d8d0197f | ||
![]() |
cf61ebb845 | ||
![]() |
73b25a8f87 | ||
![]() |
5434ba169b | ||
![]() |
dc1bd1a2cb | ||
![]() |
edc746ea7b | ||
![]() |
8f998d1d20 | ||
![]() |
d08163b4fe | ||
![]() |
1186cf8822 | ||
![]() |
6385ccc977 | ||
![]() |
c12068179c | ||
![]() |
9fa06763a1 | ||
![]() |
92337b15a2 | ||
![]() |
90b7f3aeba | ||
![]() |
426bf45278 | ||
![]() |
21d12b0211 | ||
![]() |
bc65806ce2 | ||
![]() |
8b7a4d9d3b | ||
![]() |
ccbfd1c241 | ||
![]() |
e0976d7e90 | ||
![]() |
49c7dd1ca4 | ||
![]() |
8622767a8a | ||
![]() |
8f61036467 | ||
![]() |
ae7942ba6d | ||
![]() |
a5faf17090 | ||
![]() |
06e8a1b29b | ||
![]() |
44824aca3c | ||
![]() |
1fb6c3f4ce | ||
![]() |
fe16f3863e | ||
![]() |
7c652a94ea | ||
![]() |
ed2eb31da9 | ||
![]() |
0f8bcdfd92 | ||
![]() |
07192b31e3 | ||
![]() |
ca3db5e134 | ||
![]() |
ff46386fcb | ||
![]() |
4c6da577a1 | ||
![]() |
830dd88a98 | ||
![]() |
257800a03c | ||
![]() |
536a7d42fd | ||
![]() |
7ed5de0158 | ||
![]() |
05a802a2c1 | ||
![]() |
5962e03c2d | ||
![]() |
59a21c7fb8 | ||
![]() |
7b4ebd6521 | ||
![]() |
0dfbe7699e | ||
![]() |
dec783dce5 | ||
![]() |
fe21244b05 | ||
![]() |
ec88b7bbbc | ||
![]() |
23377191e8 | ||
![]() |
5dea9da38d | ||
![]() |
b9bf42ddc3 | ||
![]() |
e57c07875c | ||
![]() |
80f1927dcd | ||
![]() |
b7a8bc22c9 | ||
![]() |
e50896286c | ||
![]() |
00b538ffa3 | ||
![]() |
5cfa39e5cd |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,6 +10,7 @@ ChangeLog
|
||||
*.trs
|
||||
*.gcda
|
||||
*.gcno
|
||||
*.sym
|
||||
.dirstamp
|
||||
.deps/
|
||||
.libs/
|
||||
|
@@ -1,16 +1,30 @@
|
||||
.vpath-tests:
|
||||
script:
|
||||
- ./autogen
|
||||
- mkdir -p build-tree
|
||||
- cd build-tree
|
||||
- ../configure
|
||||
- make check
|
||||
|
||||
.unit-tests:
|
||||
script:
|
||||
- ./autogen && ./configure
|
||||
- make check
|
||||
|
||||
.unit-tests-asan:
|
||||
script:
|
||||
- ./autogen && ./configure --enable-sanitize
|
||||
- make check
|
||||
|
||||
.coverage:
|
||||
script:
|
||||
- ./autogen && ./configure --disable-static
|
||||
- make check CFLAGS="--coverage -O0 -ggdb" LDFLAGS="--coverage -O0 -ggdb"
|
||||
- gcovr -s -e test/
|
||||
coverage: /^TOTAL.*\s+(\d+\%)$/
|
||||
|
||||
.debian:
|
||||
image: debian:buster
|
||||
image: debian:latest
|
||||
stage: test
|
||||
before_script:
|
||||
- apt-get update -qq
|
||||
@@ -24,8 +38,11 @@
|
||||
- apk add --no-cache git gcc make autoconf automake libtool
|
||||
bsd-compat-headers linux-headers libmd-dev musl-dev gcovr
|
||||
|
||||
vpath-tests:debian:
|
||||
extends: [.debian, .vpath-tests]
|
||||
|
||||
unit-tests:debian:
|
||||
extends: [.debian, .unit-tests]
|
||||
extends: [.debian, .unit-tests-asan]
|
||||
|
||||
coverage:debian:
|
||||
extends: [.debian, .coverage]
|
||||
|
39
COPYING
39
COPYING
@@ -6,37 +6,6 @@ Copyright:
|
||||
Copyright © 2004-2006, 2008-2022 Guillem Jover <guillem@hadrons.org>
|
||||
License: BSD-3-clause
|
||||
|
||||
Files:
|
||||
man/arc4random.3bsd
|
||||
Copyright:
|
||||
Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
||||
All rights reserved.
|
||||
License: BSD-4-clause-Niels-Provos
|
||||
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. All advertising materials mentioning features or use of this software
|
||||
must display the following acknowledgement:
|
||||
This product includes software developed by Niels Provos.
|
||||
4. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
.
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
|
||||
|
||||
Files:
|
||||
include/bsd/err.h
|
||||
include/bsd/stdlib.h
|
||||
@@ -202,6 +171,7 @@ License: BSD-5-clause-Peter-Wemm
|
||||
|
||||
Files:
|
||||
include/bsd/stringlist.h
|
||||
man/arc4random.3bsd
|
||||
man/fmtcheck.3bsd
|
||||
man/humanize_number.3bsd
|
||||
man/stringlist.3bsd
|
||||
@@ -216,6 +186,12 @@ Copyright:
|
||||
Copyright © 2013 John-Mark Gurney <jmg@FreeBSD.org>
|
||||
All rights reserved.
|
||||
.
|
||||
Copyright © 2014 The NetBSD Foundation, Inc.
|
||||
All rights reserved.
|
||||
.
|
||||
Some code was derived from software contributed to The NetBSD Foundation
|
||||
by Taylor R. Campbell.
|
||||
.
|
||||
Some code was contributed to The NetBSD Foundation by Allen Briggs.
|
||||
.
|
||||
Some code was contributed to The NetBSD Foundation by Luke Mewburn.
|
||||
@@ -277,7 +253,6 @@ Copyright:
|
||||
All rights reserved.
|
||||
.
|
||||
Copyright © 2009 Advanced Computing Technologies LLC
|
||||
Written by: John H. Baldwin <jhb@FreeBSD.org>
|
||||
All rights reserved.
|
||||
.
|
||||
Copyright © 2011 Guillem Jover <guillem@hadrons.org>
|
||||
|
@@ -1,13 +1,18 @@
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
SUBDIRS = include man src test
|
||||
SUBDIRS = \
|
||||
include \
|
||||
man \
|
||||
src \
|
||||
test \
|
||||
# EOL
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
EXTRA_DIST = \
|
||||
autogen \
|
||||
get-version \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
dist-hook:
|
||||
echo $(VERSION) >$(distdir)/.dist-version
|
||||
|
326
configure.ac
326
configure.ac
@@ -6,14 +6,19 @@ AC_CONFIG_SRCDIR([src/strlcpy.c])
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
AM_INIT_AUTOMAKE([1.9 foreign nostdinc subdir-objects no-dist-gzip dist-xz])
|
||||
|
||||
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
|
||||
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
|
||||
AM_INIT_AUTOMAKE(
|
||||
[1.11]
|
||||
[-Wall]
|
||||
[foreign]
|
||||
[nostdinc]
|
||||
[subdir-objects]
|
||||
[no-dist-gzip dist-xz]
|
||||
)
|
||||
AM_SILENT_RULES([yes])
|
||||
|
||||
LIBBSD_ABI_MAJOR=0
|
||||
LIBBSD_ABI_MINOR=11
|
||||
LIBBSD_ABI_PATCH=7
|
||||
LIBBSD_ABI_PATCH=8
|
||||
|
||||
LIBBSD_ABI="$LIBBSD_ABI_MAJOR:$LIBBSD_ABI_MINOR:$LIBBSD_ABI_PATCH"
|
||||
AC_SUBST([LIBBSD_ABI])
|
||||
@@ -25,26 +30,17 @@ user_CFLAGS=${CFLAGS-unset}
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
AC_SYS_LARGEFILE
|
||||
|
||||
AM_PROG_AR
|
||||
LT_INIT
|
||||
LIBBSD_LINKER_VERSION_SCRIPT
|
||||
|
||||
AC_CACHE_CHECK([if ld supports --version-script flag],
|
||||
[libbsd_cv_version_script], [
|
||||
echo "{ global: symbol; local: *; };" >conftest.map
|
||||
save_LDFLAGS=$LDFLAGS
|
||||
LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
|
||||
AC_LINK_IFELSE([
|
||||
AC_LANG_PROGRAM([], [])
|
||||
], [
|
||||
libbsd_cv_version_script=yes
|
||||
], [
|
||||
libbsd_cv_version_script=no
|
||||
])
|
||||
LDFLAGS="$save_LDFLAGS"
|
||||
rm -f conftest.map
|
||||
]
|
||||
is_windows=no
|
||||
AS_CASE([$host_os],
|
||||
[mingw*], [
|
||||
is_windows=yes
|
||||
],
|
||||
)
|
||||
AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
|
||||
[test "x$libbsd_cv_version_script" = "xyes"])
|
||||
AM_CONDITIONAL([OS_WINDOWS], [test "x$is_windows" = "xyes"])
|
||||
|
||||
# Checks for programs.
|
||||
AC_CHECK_TOOL([OBJDUMP], [objdump])
|
||||
@@ -92,14 +88,26 @@ AS_IF([test "$user_CFLAGS" = unset], [
|
||||
LIBBSD_CHECK_COMPILER_FLAG([-Wwrite-strings])
|
||||
|
||||
CFLAGS="$CFLAGS $LIBBSD_COMPILER_FLAGS"
|
||||
|
||||
AC_ARG_ENABLE([sanitize],
|
||||
[AS_HELP_STRING([--enable-sanitize], [enable compiler sanitizer support])],
|
||||
[
|
||||
LIBBSD_COMPILER_FLAGS=''
|
||||
LIBBSD_CHECK_COMPILER_FLAG([-fsanitize=address])
|
||||
LIBBSD_CHECK_COMPILER_FLAG([-fsanitize=leak])
|
||||
LIBBSD_CHECK_COMPILER_FLAG([-fsanitize=undefined])
|
||||
|
||||
CFLAGS="$CFLAGS $LIBBSD_COMPILER_FLAGS"
|
||||
LDFLAGS="$LDFLAGS $LIBBSD_COMPILER_FLAGS"
|
||||
])
|
||||
])
|
||||
|
||||
# Checks for libraries.
|
||||
AC_CHECK_LIB([testu01], [unif01_CreateExternGenBits],
|
||||
[TESTU01_LIBS="-ltestu01"])
|
||||
[TESTU01_LIBS="-ltestu01"])
|
||||
AC_SUBST([TESTU01_LIBS])
|
||||
AM_CONDITIONAL([HAVE_LIBTESTU01],
|
||||
[test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
|
||||
[test "x$ac_cv_lib_testu01_unif01_CreateExternGenBits" = "xyes"])
|
||||
|
||||
saved_LIBS="$LIBS"
|
||||
AC_SEARCH_LIBS([MD5Update], [md], [
|
||||
@@ -119,10 +127,6 @@ AC_SEARCH_LIBS([SHA512Update], [md], [
|
||||
])
|
||||
LIBS="$saved_LIBS"
|
||||
|
||||
AM_CONDITIONAL([NEED_TRANSPARENT_LIBMD],
|
||||
[test "x$need_transparent_libmd" = "xyes"])
|
||||
|
||||
is_windows=no
|
||||
AS_CASE([$host_os],
|
||||
[*-gnu*], [
|
||||
# In old glibc versions (< 2.17) clock_gettime() is in librt.
|
||||
@@ -134,18 +138,28 @@ AS_CASE([$host_os],
|
||||
])
|
||||
LIBS="$saved_LIBS"
|
||||
],
|
||||
[*-musl*], [
|
||||
# Upstream refuses to define this, we will do it ourselves then.
|
||||
AC_DEFINE([__MUSL__], [1], [Define to 1 if we are building for musl])
|
||||
],
|
||||
[mingw*], [
|
||||
is_windows=yes
|
||||
[aix*], [
|
||||
saved_LIBS="$LIBS"
|
||||
AC_SEARCH_LIBS([perfstat_cpu_total], [perfstat], [
|
||||
AS_IF([test "x$ac_cv_search_perfstat_cpu_total" != "xnone required"], [
|
||||
LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_perfstat_cpu_total"
|
||||
])
|
||||
])
|
||||
LIBS="$saved_LIBS"
|
||||
],
|
||||
)
|
||||
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 pwd.h grp.h])
|
||||
AC_CHECK_HEADERS([\
|
||||
sys/ndir.h \
|
||||
sys/dir.h \
|
||||
ndir.h \
|
||||
dirent.h \
|
||||
pwd.h \
|
||||
grp.h \
|
||||
stdio_ext.h \
|
||||
procinfo.h \
|
||||
])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_INLINE
|
||||
@@ -158,108 +172,172 @@ AC_TYPE_UID_T
|
||||
AC_TYPE_SIZE_T
|
||||
AC_TYPE_SSIZE_T
|
||||
|
||||
AC_CHECK_DECL([F_CLOSEM],
|
||||
[AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
|
||||
[Define to 1 if you have fcntl(F_CLOSEM)])],
|
||||
[],
|
||||
[#include <limits.h>
|
||||
#include <fcntl.h>])
|
||||
AC_CHECK_DECL([F_CLOSEM], [
|
||||
AC_DEFINE([HAVE_FCNTL_CLOSEM], [1],
|
||||
[Define to 1 if you have fcntl(F_CLOSEM)])
|
||||
], [], [[
|
||||
#include <limits.h>
|
||||
#include <fcntl.h>
|
||||
]])
|
||||
|
||||
AC_CACHE_CHECK(
|
||||
[for GNU .init_array section support],
|
||||
[libbsd_cv_gnu_init_array_support],
|
||||
[AC_RUN_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[
|
||||
static int rc = 1;
|
||||
static void init(int argc) { if (argc == 1) rc = 0; }
|
||||
void (*init_func)(int argc) __attribute__((__section__(".init_array"), __used__)) = init;
|
||||
int main() { return rc; }
|
||||
]]
|
||||
)],
|
||||
[libbsd_cv_gnu_init_array_support=yes],
|
||||
[libbsd_cv_gnu_init_array_support=no],
|
||||
[AC_PREPROC_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[
|
||||
/* Look for a known libc that supports .init_array with the GNU extension
|
||||
* to pass main() arguments to the init functions. */
|
||||
#include <stdlib.h>
|
||||
#if defined __GLIBC_PREREQ
|
||||
# if __GLIBC_PREREQ(2, 4)
|
||||
/* glibc supports GNU .init_array since 2.4. */
|
||||
# else
|
||||
# error glibc does not support GNU .init_array
|
||||
# endif
|
||||
#else
|
||||
/*
|
||||
* Basic SysV ABI .init_array support, init functions do not get arguments:
|
||||
* - Bionic since its inception.
|
||||
* - uClibc since 0.9.29.
|
||||
*/
|
||||
# error unknown whether libc supports GNU .init_array
|
||||
#endif
|
||||
]]
|
||||
)],
|
||||
[libbsd_cv_gnu_init_array_support=yes],
|
||||
[libbsd_cv_gnu_init_array_support=no])
|
||||
]
|
||||
)]
|
||||
)
|
||||
AM_CONDITIONAL([BUILD_LIBBSD_CTOR],
|
||||
[test "$libbsd_cv_gnu_init_array_support" = yes])
|
||||
AC_CHECK_DECLS([environ], [], [], [[
|
||||
#include <unistd.h>
|
||||
]])
|
||||
|
||||
LIBBSD_HAS_GNU_INIT_ARRAY
|
||||
|
||||
# Checks for library functions.
|
||||
AC_MSG_CHECKING([for program_invocation_short_name])
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM([[#include <errno.h>]],
|
||||
[[const char *p = program_invocation_short_name;]])],
|
||||
[AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
|
||||
[Define to 1 if you have program_invocation_short_name])
|
||||
AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_RESULT([no])])
|
||||
AC_LINK_IFELSE([
|
||||
AC_LANG_PROGRAM([[
|
||||
#include <errno.h>
|
||||
]], [[
|
||||
const char *p = program_invocation_short_name;
|
||||
]])
|
||||
], [
|
||||
AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
|
||||
[Define to 1 if you have program_invocation_short_name])
|
||||
AC_MSG_RESULT([yes])
|
||||
], [
|
||||
AC_MSG_RESULT([no])
|
||||
])
|
||||
|
||||
AC_MSG_CHECKING([for __progname])
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM([[extern char *__progname;]],
|
||||
[[printf("%s", __progname);]])],
|
||||
[AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
|
||||
AC_MSG_RESULT([yes])],
|
||||
[AC_MSG_RESULT([no])])
|
||||
AC_LINK_IFELSE([
|
||||
AC_LANG_PROGRAM([[
|
||||
#include <stdio.h>
|
||||
extern char *__progname;
|
||||
]], [[
|
||||
printf("%s", __progname);
|
||||
]])
|
||||
], [
|
||||
AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
|
||||
AC_MSG_RESULT([yes])
|
||||
], [
|
||||
AC_MSG_RESULT([no])
|
||||
])
|
||||
|
||||
AC_MSG_CHECKING([for __register_atfork])
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM([[
|
||||
#include <stddef.h>
|
||||
extern void *__dso_handle;
|
||||
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
|
||||
]], [[
|
||||
__register_atfork(NULL, NULL, NULL, __dso_handle);
|
||||
]])],
|
||||
[AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
|
||||
[Define to 1 if you have __register_atfork])
|
||||
AC_MSG_RESULT([yes])],
|
||||
[LIBBSD_LIBS="$LIBBSD_LIBS -pthread"
|
||||
AC_MSG_RESULT([no])
|
||||
])
|
||||
AC_LINK_IFELSE([
|
||||
AC_LANG_PROGRAM([[
|
||||
#include <stddef.h>
|
||||
extern void *__dso_handle;
|
||||
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
|
||||
]], [[
|
||||
__register_atfork(NULL, NULL, NULL, __dso_handle);
|
||||
]])
|
||||
], [
|
||||
AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
|
||||
[Define to 1 if you have __register_atfork])
|
||||
AC_MSG_RESULT([yes])
|
||||
], [
|
||||
LIBBSD_LIBS="$LIBBSD_LIBS -pthread"
|
||||
AC_MSG_RESULT([no])
|
||||
])
|
||||
|
||||
AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
|
||||
getauxval getentropy getexecname getline \
|
||||
pstat_getproc sysconf])
|
||||
AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xtrue"])
|
||||
AC_CHECK_FUNCS([\
|
||||
clearenv \
|
||||
dirfd \
|
||||
flock \
|
||||
fopencookie \
|
||||
__fpurge \
|
||||
funopen \
|
||||
getauxval \
|
||||
getentropy \
|
||||
getexecname \
|
||||
getline \
|
||||
open_memstream \
|
||||
pstat_getproc \
|
||||
sysconf \
|
||||
uid_from_user \
|
||||
gid_from_group \
|
||||
user_from_uid \
|
||||
group_from_gid \
|
||||
])
|
||||
|
||||
need_arc4random=yes
|
||||
need_bsd_getopt=yes
|
||||
need_progname=yes
|
||||
need_md5=yes
|
||||
need_nlist=yes
|
||||
need_strl=yes
|
||||
need_wcsl=yes
|
||||
need_strmode=yes
|
||||
need_id_from_name=yes
|
||||
need_fpurge=yes
|
||||
need_funopen=yes
|
||||
AS_CASE([$host_os],
|
||||
[*-gnu*], [
|
||||
# On glibc >= 2.38, strlcpy() and strlcat() got added,
|
||||
# so these could then be dropped on the next SOVERSION bump.
|
||||
#need_strl=no
|
||||
],
|
||||
[*-musl*], [
|
||||
# On musl >= 0.5.0, strlcpy() and strlcat() were already implemented,
|
||||
# so these can then be dropped on the next SOVERSION bump.
|
||||
#need_strl=no
|
||||
# On musl >= 0.9.7, optreset got implemented, so bsd_getopt() can then
|
||||
# be dropped on the next SOVERSION bump.
|
||||
#need_bsd_getopt=no
|
||||
# On musl >= 1.1.19, fopencookie() got implemented, and because we were
|
||||
# checking for its presence to decide whether to build funopen(), it got
|
||||
# included in builds even when previously it had not been included, which
|
||||
# is partially an ABI issue, but given that disabling it now would be
|
||||
# worse, we'll ignore this as this is only a problem with downgrades. And
|
||||
# enable it explicitly
|
||||
need_funopen=yes
|
||||
],
|
||||
[darwin*], [
|
||||
# On macOS these are provided by the system, and libbsd has never built
|
||||
# there, so we can avoid providing these with no ABI breakage.
|
||||
need_arc4random=no
|
||||
need_bsd_getopt=no
|
||||
need_progname=no
|
||||
need_transparent_libmd=no
|
||||
need_md5=no
|
||||
need_nlist=no
|
||||
need_strl=no
|
||||
need_wcsl=no
|
||||
need_strmode=no
|
||||
need_id_from_name=no
|
||||
need_fpurge=no
|
||||
# On macOS we do not have fopencookie(), and cannot implement it.
|
||||
need_funopen=no
|
||||
],
|
||||
)
|
||||
|
||||
AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xyes"])
|
||||
|
||||
AM_CONDITIONAL([NEED_ARC4RANDOM], [test "x$need_arc4random" = "xyes"])
|
||||
AM_CONDITIONAL([NEED_BSD_GETOPT], [test "x$need_bsd_getopt" = "xyes"])
|
||||
AM_CONDITIONAL([NEED_PROGNAME], [test "x$need_progname" = "xyes"])
|
||||
AM_CONDITIONAL([NEED_TRANSPARENT_LIBMD], [test "x$need_transparent_libmd" = "xyes"])
|
||||
AM_CONDITIONAL([NEED_MD5], [test "x$need_md5" = "xyes"])
|
||||
AM_CONDITIONAL([NEED_NLIST], [test "x$need_nlist" = "xyes"])
|
||||
AM_CONDITIONAL([NEED_STRL], [test "x$need_strl" = "xyes"])
|
||||
AM_CONDITIONAL([NEED_WCSL], [test "x$need_wcsl" = "xyes"])
|
||||
AM_CONDITIONAL([NEED_STRMODE], [test "x$need_strmode" = "xyes"])
|
||||
AM_CONDITIONAL([NEED_ID_FROM_NAME], [test "x$need_id_from_name" = "xyes"])
|
||||
AM_CONDITIONAL([NEED_FPURGE], [test "x$need_fpurge" = "xyes"])
|
||||
AM_CONDITIONAL([NEED_FUNOPEN], [test "x$need_funopen" = "xyes"])
|
||||
AS_IF([test "x$need_funopen" = "xno" && \
|
||||
test "x$ac_cv_func_funopen" != "xyes" && \
|
||||
test "x$ac_cv_func_fopencookie" = "xyes"], [
|
||||
AC_MSG_WARN([[can implement funopen() now based on newly added fopencooke(), report upstream]])
|
||||
])
|
||||
|
||||
AC_SUBST([MD5_LIBS])
|
||||
AC_SUBST([LIBBSD_LIBS])
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
include/Makefile
|
||||
man/Makefile
|
||||
src/Makefile
|
||||
src/libbsd.pc
|
||||
src/libbsd-ctor.pc
|
||||
src/libbsd-overlay.pc
|
||||
test/Makefile
|
||||
Makefile
|
||||
include/Makefile
|
||||
man/Makefile
|
||||
src/Makefile
|
||||
src/libbsd.pc
|
||||
src/libbsd-ctor.pc
|
||||
src/libbsd-overlay.pc
|
||||
test/Makefile
|
||||
])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AC_OUTPUT
|
||||
|
@@ -17,8 +17,6 @@ nobase_include_HEADERS = \
|
||||
bsd/grp.h \
|
||||
bsd/inttypes.h \
|
||||
bsd/libutil.h \
|
||||
bsd/md5.h \
|
||||
bsd/nlist.h \
|
||||
bsd/pwd.h \
|
||||
bsd/readpassphrase.h \
|
||||
bsd/stdio.h \
|
||||
@@ -29,4 +27,16 @@ nobase_include_HEADERS = \
|
||||
bsd/unistd.h \
|
||||
bsd/vis.h \
|
||||
bsd/wchar.h \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
if NEED_MD5
|
||||
nobase_include_HEADERS += \
|
||||
bsd/md5.h \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_NLIST
|
||||
nobase_include_HEADERS += \
|
||||
bsd/nlist.h \
|
||||
# EOL
|
||||
endif
|
||||
|
@@ -44,8 +44,10 @@
|
||||
__BEGIN_DECLS
|
||||
int
|
||||
gid_from_group(const char *, gid_t *);
|
||||
#ifndef __APPLE__
|
||||
const char *
|
||||
group_from_gid(gid_t, int);
|
||||
#endif
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
@@ -44,8 +44,10 @@
|
||||
__BEGIN_DECLS
|
||||
int
|
||||
uid_from_user(const char *, uid_t *);
|
||||
#ifndef __APPLE__
|
||||
const char *
|
||||
user_from_uid(uid_t, int);
|
||||
#endif
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
@@ -51,6 +51,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
#if !defined(__APPLE__) && !defined(__sun)
|
||||
#if !defined(__GLIBC__) || \
|
||||
!__GLIBC_PREREQ(2, 36) || \
|
||||
!defined(_DEFAULT_SOURCE)
|
||||
@@ -60,11 +61,14 @@ uint32_t arc4random_uniform(uint32_t upper_bound);
|
||||
#endif
|
||||
void arc4random_stir(void);
|
||||
void arc4random_addrandom(unsigned char *dat, int datlen);
|
||||
#endif
|
||||
|
||||
int dehumanize_number(const char *str, int64_t *size);
|
||||
|
||||
#if !defined(__APPLE__)
|
||||
const char *getprogname(void);
|
||||
void setprogname(const char *);
|
||||
#endif
|
||||
|
||||
int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
|
||||
int mergesort(void *base, size_t nmemb, size_t size,
|
||||
|
@@ -41,10 +41,15 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
#if !defined(__APPLE__) && \
|
||||
(!defined(__GLIBC__) || !__GLIBC_PREREQ(2, 38) || !defined(_DEFAULT_SOURCE))
|
||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
#endif
|
||||
char *strnstr(const char *str, const char *find, size_t str_len);
|
||||
#ifndef __APPLE__
|
||||
void strmode(mode_t mode, char *str);
|
||||
#endif
|
||||
|
||||
#if !defined(__GLIBC__) || \
|
||||
!__GLIBC_PREREQ(2, 25) || \
|
||||
|
@@ -37,6 +37,9 @@
|
||||
#ifndef __is_identifier
|
||||
#define __is_identifier(x) 1
|
||||
#endif
|
||||
#ifndef __has_builtin
|
||||
#define __has_builtin(x) !__is_identifier(x)
|
||||
#endif
|
||||
|
||||
#ifdef LIBBSD_OVERLAY
|
||||
/*
|
||||
@@ -182,7 +185,7 @@
|
||||
* require it.
|
||||
*/
|
||||
#ifndef __offsetof
|
||||
# if LIBBSD_GCC_VERSION >= 0x0401 || !__is_identifier(__builtin_offsetof)
|
||||
# if LIBBSD_GCC_VERSION >= 0x0401 || __has_builtin(__builtin_offsetof)
|
||||
# define __offsetof(type, field) __builtin_offsetof(type, field)
|
||||
# else
|
||||
# ifndef __cplusplus
|
||||
|
@@ -47,6 +47,7 @@
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
#if !defined(__APPLE__)
|
||||
extern int optreset;
|
||||
|
||||
#ifdef LIBBSD_OVERLAY
|
||||
@@ -55,11 +56,16 @@ extern int optreset;
|
||||
#endif
|
||||
|
||||
int bsd_getopt(int argc, char * const argv[], const char *shortopts);
|
||||
#endif
|
||||
|
||||
mode_t getmode(const void *set, mode_t mode);
|
||||
void *setmode(const char *mode_str);
|
||||
|
||||
#if !defined(__GLIBC__) || \
|
||||
!__GLIBC_PREREQ(2, 34) || \
|
||||
!defined(_DEFAULT_SOURCE)
|
||||
void closefrom(int lowfd);
|
||||
#endif
|
||||
|
||||
/* Compatibility with sendmail implementations. */
|
||||
#define initsetproctitle(c, a, e) setproctitle_init((c), (a), (e))
|
||||
|
@@ -50,8 +50,10 @@
|
||||
__BEGIN_DECLS
|
||||
wchar_t *fgetwln(FILE *stream, size_t *len);
|
||||
|
||||
#if !defined(__APPLE__)
|
||||
size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
|
||||
size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
|
||||
#endif
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
@@ -1,7 +1,7 @@
|
||||
# Copyright © 2021 Guillem Jover <guillem@hadrons.org>
|
||||
|
||||
# LIBBSD_CHECK_COMPILER_FLAG
|
||||
# -------------------------
|
||||
# --------------------------
|
||||
AC_DEFUN([LIBBSD_CHECK_COMPILER_FLAG], [
|
||||
AS_VAR_PUSHDEF([libbsd_varname_cache], [libbsd_cv_cflags_$1])
|
||||
AC_CACHE_CHECK([whether $CC accepts $1], [libbsd_varname_cache], [
|
||||
@@ -22,3 +22,51 @@ AC_DEFUN([LIBBSD_CHECK_COMPILER_FLAG], [
|
||||
])
|
||||
AS_VAR_POPDEF([libbsd_varname_cache])
|
||||
])
|
||||
|
||||
# LIBBSD_HAS_GNU_INIT_ARRAY
|
||||
# -------------------------
|
||||
AC_DEFUN([LIBBSD_HAS_GNU_INIT_ARRAY], [
|
||||
AC_CACHE_CHECK([for GNU .init_array section support],
|
||||
[libbsd_cv_gnu_init_array_support], [
|
||||
AC_RUN_IFELSE([
|
||||
AC_LANG_SOURCE([[
|
||||
static int rc = 1;
|
||||
static void init(int argc) { if (argc == 1) rc = 0; }
|
||||
void (*init_func)(int argc) __attribute__((__section__(".init_array"), __used__)) = init;
|
||||
int main() { return rc; }
|
||||
]])
|
||||
], [
|
||||
libbsd_cv_gnu_init_array_support=yes
|
||||
], [
|
||||
libbsd_cv_gnu_init_array_support=no
|
||||
], [
|
||||
AC_PREPROC_IFELSE([
|
||||
AC_LANG_SOURCE([[
|
||||
/* Look for a known libc that supports .init_array with the GNU extension
|
||||
* to pass main() arguments to the init functions. */
|
||||
#include <stdlib.h>
|
||||
#if defined __GLIBC_PREREQ
|
||||
# if __GLIBC_PREREQ(2, 4)
|
||||
/* glibc supports GNU .init_array since 2.4. */
|
||||
# else
|
||||
# error glibc does not support GNU .init_array
|
||||
# endif
|
||||
#else
|
||||
/*
|
||||
* Basic SysV ABI .init_array support, init functions do not get arguments:
|
||||
* - Bionic since its inception.
|
||||
* - uClibc since 0.9.29.
|
||||
*/
|
||||
# error unknown whether libc supports GNU .init_array
|
||||
#endif
|
||||
]])
|
||||
], [
|
||||
libbsd_cv_gnu_init_array_support=yes
|
||||
], [
|
||||
libbsd_cv_gnu_init_array_support=no
|
||||
])
|
||||
])
|
||||
])
|
||||
AM_CONDITIONAL([BUILD_LIBBSD_CTOR],
|
||||
[test "$libbsd_cv_gnu_init_array_support" = yes])
|
||||
])
|
||||
|
27
m4/libbsd-linker.m4
Normal file
27
m4/libbsd-linker.m4
Normal file
@@ -0,0 +1,27 @@
|
||||
# Copyright © 2019, 2022 Guillem Jover <guillem@hadrons.org>
|
||||
|
||||
# LIBBSD_LINKER_VERSION_SCRIPT
|
||||
# ----------------------------
|
||||
AC_DEFUN([LIBBSD_LINKER_VERSION_SCRIPT], [
|
||||
AC_CACHE_CHECK([if ld supports --version-script flag],
|
||||
[libbsd_cv_version_script], [
|
||||
echo "{ global: symbol; local: *; };" >conftest.map
|
||||
save_LDFLAGS=$LDFLAGS
|
||||
LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
|
||||
AC_LINK_IFELSE([
|
||||
AC_LANG_PROGRAM([[
|
||||
extern int symbol(void);
|
||||
int symbol(void) { return 0; }
|
||||
]], [[
|
||||
]])
|
||||
], [
|
||||
libbsd_cv_version_script=yes
|
||||
], [
|
||||
libbsd_cv_version_script=no
|
||||
])
|
||||
LDFLAGS="$save_LDFLAGS"
|
||||
rm -f conftest.map
|
||||
])
|
||||
AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
|
||||
[test "x$libbsd_cv_version_script" = "xyes"])
|
||||
])
|
@@ -2,11 +2,11 @@
|
||||
|
||||
EXTRA_DIST = \
|
||||
mdX.3bsd \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
CLEANFILES = \
|
||||
md5.3bsd \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
SED_MD5_SUBST = -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g'
|
||||
|
||||
@@ -174,16 +174,12 @@ dist_man_MANS = \
|
||||
fgetln.3bsd \
|
||||
fgetwln.3bsd \
|
||||
flopen.3bsd \
|
||||
freezero.3bsd \
|
||||
fmtcheck.3bsd \
|
||||
fparseln.3bsd \
|
||||
fpurge.3bsd \
|
||||
funopen.3bsd \
|
||||
freezero.3bsd \
|
||||
getbsize.3bsd \
|
||||
getmode.3bsd \
|
||||
getpeereid.3bsd \
|
||||
getprogname.3bsd \
|
||||
gid_from_group.3bsd \
|
||||
group_from_gid.3bsd \
|
||||
heapsort.3bsd \
|
||||
humanize_number.3bsd \
|
||||
@@ -194,9 +190,7 @@ dist_man_MANS = \
|
||||
le64dec.3bsd \
|
||||
le64enc.3bsd \
|
||||
libbsd.7 \
|
||||
md5.3bsd \
|
||||
mergesort.3bsd \
|
||||
nlist.3bsd \
|
||||
pidfile.3bsd \
|
||||
pidfile_close.3bsd \
|
||||
pidfile_open.3bsd \
|
||||
@@ -212,7 +206,6 @@ dist_man_MANS = \
|
||||
setmode.3bsd \
|
||||
setproctitle.3bsd \
|
||||
setproctitle_init.3bsd \
|
||||
setprogname.3bsd \
|
||||
sl_add.3bsd \
|
||||
sl_delete.3bsd \
|
||||
sl_find.3bsd \
|
||||
@@ -220,9 +213,6 @@ dist_man_MANS = \
|
||||
sl_init.3bsd \
|
||||
sradixsort.3bsd \
|
||||
stringlist.3bsd \
|
||||
strlcat.3bsd \
|
||||
strlcpy.3bsd \
|
||||
strmode.3bsd \
|
||||
strnstr.3bsd \
|
||||
strnunvis.3bsd \
|
||||
strnvis.3bsd \
|
||||
@@ -245,10 +235,65 @@ dist_man_MANS = \
|
||||
timespecsub.3bsd \
|
||||
timeval.3bsd \
|
||||
tree.3bsd \
|
||||
uid_from_user.3bsd \
|
||||
unvis.3bsd \
|
||||
user_from_uid.3bsd \
|
||||
vis.3bsd \
|
||||
# EOL
|
||||
|
||||
if NEED_PROGNAME
|
||||
dist_man_MANS += \
|
||||
getprogname.3bsd \
|
||||
setprogname.3bsd \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_MD5
|
||||
dist_man_MANS += \
|
||||
md5.3bsd \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_NLIST
|
||||
dist_man_MANS += \
|
||||
nlist.3bsd \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_STRL
|
||||
dist_man_MANS += \
|
||||
strlcat.3bsd \
|
||||
strlcpy.3bsd \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_WCSL
|
||||
dist_man_MANS += \
|
||||
wcslcat.3bsd \
|
||||
wcslcpy.3bsd \
|
||||
$(nil)
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_STRMODE
|
||||
dist_man_MANS += \
|
||||
strmode.3bsd \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_ID_FROM_NAME
|
||||
dist_man_MANS += \
|
||||
uid_from_user.3bsd \
|
||||
gid_from_group.3bsd \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_FPURGE
|
||||
dist_man_MANS += \
|
||||
fpurge.3bsd \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_FUNOPEN
|
||||
dist_man_MANS += \
|
||||
funopen.3bsd \
|
||||
# EOL
|
||||
endif
|
||||
|
@@ -1,8 +1,11 @@
|
||||
.\" $OpenBSD: arc4random.3,v 1.37 2019/09/29 16:30:35 jmc Exp $
|
||||
.\" $NetBSD: arc4random.3,v 1.21 2016/07/15 21:19:19 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
||||
.\" Copyright (c) 2014 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||
.\" by Taylor R. Campbell.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
@@ -11,32 +14,26 @@
|
||||
.\" 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. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by Niels Provos.
|
||||
.\" 4. The name of the author may not be used to endorse or promote products
|
||||
.\" derived from this software without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
||||
.\"
|
||||
.\" Manual page, using -mandoc macros
|
||||
.\"
|
||||
.Dd $Mdocdate: September 29 2019 $
|
||||
.Dd November 16, 2014
|
||||
.Dt arc4random 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm arc4random ,
|
||||
.Nm arc4random_buf ,
|
||||
.Nm arc4random_uniform ,
|
||||
.Nm arc4random_buf ,
|
||||
.Nm arc4random_stir ,
|
||||
.Nm arc4random_addrandom
|
||||
.Nd random number generator
|
||||
@@ -51,83 +48,208 @@
|
||||
for include usage.)
|
||||
.Ft uint32_t
|
||||
.Fn arc4random "void"
|
||||
.Ft void
|
||||
.Fn arc4random_buf "void *buf" "size_t nbytes"
|
||||
.Ft uint32_t
|
||||
.Fn arc4random_uniform "uint32_t upper_bound"
|
||||
.Fn arc4random_uniform "uint32_t bound"
|
||||
.Ft void
|
||||
.Fn arc4random_buf "void *buf" "size_t len"
|
||||
.Ft void
|
||||
.Fn arc4random_stir "void"
|
||||
.Ft void
|
||||
.Fn arc4random_addrandom "unsigned char *dat" "int datlen"
|
||||
.Fn arc4random_addrandom "unsigned char *buf" "int len"
|
||||
.Sh DESCRIPTION
|
||||
This family of functions provides higher quality data than those
|
||||
described in
|
||||
.Xr rand 3 ,
|
||||
The
|
||||
.Nm
|
||||
family of functions provides a cryptographic pseudorandom number
|
||||
generator automatically seeded from the system entropy pool and safe to
|
||||
use from multiple threads.
|
||||
.Nm
|
||||
is designed to prevent an adversary from guessing outputs,
|
||||
unlike
|
||||
.Xr rand 3
|
||||
and
|
||||
.Xr random 3 ,
|
||||
and
|
||||
.Xr rand48 3 .
|
||||
and is faster and more convenient than reading from
|
||||
.Pa /dev/urandom
|
||||
directly.
|
||||
.Pp
|
||||
Use of these functions is encouraged for almost all random number
|
||||
consumption because the other interfaces are deficient in either
|
||||
quality, portability, standardization, or availability.
|
||||
These functions can be called in almost all coding environments,
|
||||
including
|
||||
.Xr pthreads 3
|
||||
and
|
||||
.Xr chroot 2 .
|
||||
.Pp
|
||||
High quality 32-bit pseudo-random numbers are generated very quickly.
|
||||
On each call, a cryptographic pseudo-random number generator is used
|
||||
to generate a new result.
|
||||
One data pool is used for all consumers in a process, so that consumption
|
||||
under program flow can act as additional stirring.
|
||||
The subsystem is re-seeded from the kernel random number subsystem using
|
||||
.Xr getentropy 2
|
||||
on a regular basis, and also upon
|
||||
.Xr fork 2 .
|
||||
.Pp
|
||||
The
|
||||
.Fn arc4random
|
||||
function returns a single 32-bit value.
|
||||
.Pp
|
||||
The
|
||||
.Fn arc4random_buf
|
||||
function fills the region
|
||||
.Fa buf
|
||||
of length
|
||||
.Fa nbytes
|
||||
with random data.
|
||||
returns an integer in [0, 2^32) chosen independently with uniform
|
||||
distribution.
|
||||
.Pp
|
||||
.Fn arc4random_uniform
|
||||
will return a single 32-bit value, uniformly distributed but less than
|
||||
.Fa upper_bound .
|
||||
This is recommended over constructions like
|
||||
.Dq Li arc4random() % upper_bound
|
||||
as it avoids "modulo bias" when the upper bound is not a power of two.
|
||||
In the worst case, this function may consume multiple iterations
|
||||
to ensure uniformity; see the source code to understand the problem
|
||||
and solution.
|
||||
returns an integer in [0,
|
||||
.Fa bound )
|
||||
chosen independently with uniform distribution.
|
||||
.Pp
|
||||
.Fn arc4random_buf
|
||||
stores
|
||||
.Fa len
|
||||
bytes into the memory pointed to by
|
||||
.Fa buf ,
|
||||
each byte chosen independently from [0, 256) with uniform
|
||||
distribution.
|
||||
.Pp
|
||||
.Fn arc4random_stir
|
||||
draws entropy from the operating system and incorporates it into the
|
||||
library's PRNG state to influence future outputs.
|
||||
.Pp
|
||||
.Fn arc4random_addrandom
|
||||
incorporates
|
||||
.Fa len
|
||||
bytes, which must be nonnegative, from the buffer
|
||||
.Fa buf ,
|
||||
into the library's PRNG state to influence future outputs.
|
||||
.Pp
|
||||
It is not necessary for an application to call
|
||||
.Fn arc4random_stir
|
||||
or
|
||||
.Fn arc4random_addrandom
|
||||
before calling other
|
||||
.Nm
|
||||
functions.
|
||||
The first call to any
|
||||
.Nm
|
||||
function will initialize the PRNG state unpredictably from the system
|
||||
entropy pool.
|
||||
.Sh SECURITY MODEL
|
||||
The
|
||||
.Fn arc4random_stir
|
||||
function reads data from
|
||||
.Xr getentropy 2
|
||||
and uses it to re-seed the subsystem via
|
||||
.Fn arc4random_addrandom .
|
||||
.Nm
|
||||
functions provide the following security properties against three
|
||||
different classes of attackers, assuming enough entropy is provided by
|
||||
the operating system:
|
||||
.Bl -enum -offset abcd
|
||||
.It
|
||||
An attacker who has seen some outputs of any of the
|
||||
.Nm
|
||||
functions cannot predict past or future unseen outputs.
|
||||
.It
|
||||
An attacker who has seen the library's PRNG state in memory cannot
|
||||
predict past outputs.
|
||||
.It
|
||||
An attacker who has seen one process's PRNG state cannot predict past
|
||||
or future outputs in other processes, particularly its parent or
|
||||
siblings.
|
||||
.El
|
||||
.Pp
|
||||
One
|
||||
.Sq output
|
||||
means the result of any single request to an
|
||||
.Nm
|
||||
function, no matter how short it is.
|
||||
.Pp
|
||||
The second property is sometimes called
|
||||
.Sq forward secrecy ,
|
||||
.Sq backtracking resistance ,
|
||||
or
|
||||
.Sq key erasure after each output .
|
||||
.Sh IMPLEMENTATION NOTES
|
||||
The
|
||||
.Nm
|
||||
functions are currently implemented using the ChaCha20 pseudorandom
|
||||
function family.
|
||||
For any 32-byte string
|
||||
.Fa s ,
|
||||
.Pf ChaCha20_ Fa s
|
||||
is a function from 16-byte strings to 64-byte strings.
|
||||
It is conjectured that if
|
||||
.Fa s
|
||||
is chosen with uniform distribution, then the distribution on
|
||||
.Pf ChaCha20_ Fa s
|
||||
is indistinguishable to a computationally bounded adversary from a
|
||||
uniform distribution on all functions from 16-byte strings to 64-byte
|
||||
strings.
|
||||
.Pp
|
||||
The PRNG state is a 32-byte ChaCha20 key
|
||||
.Fa s .
|
||||
Each request to
|
||||
an
|
||||
.Nm
|
||||
function
|
||||
.Bl -bullet -offset abcd -compact
|
||||
.It
|
||||
computes the 64-byte quantity
|
||||
.Fa x
|
||||
=
|
||||
.Pf ChaCha20_ Fa s Ns Pq 0 ,
|
||||
.It
|
||||
splits
|
||||
.Fa x
|
||||
into two 32-byte quantities
|
||||
.Fa s'
|
||||
and
|
||||
.Fa k ,
|
||||
.It
|
||||
replaces
|
||||
.Fa s
|
||||
by
|
||||
.Fa s' ,
|
||||
and
|
||||
.It
|
||||
uses
|
||||
.Fa k
|
||||
as output.
|
||||
.El
|
||||
.Pp
|
||||
There is no need to call
|
||||
.Fn arc4random_stir
|
||||
before using
|
||||
.Fn arc4random
|
||||
functions family, since
|
||||
they automatically initialize themselves.
|
||||
.Sh RETURN VALUES
|
||||
These functions are always successful, and no return value is
|
||||
reserved to indicate an error.
|
||||
yields the first four bytes of
|
||||
.Fa k
|
||||
as output directly.
|
||||
.Fn arc4random_buf
|
||||
either yields up to 32 bytes of
|
||||
.Fa k
|
||||
as output directly, or, for longer
|
||||
requests, uses
|
||||
.Fa k
|
||||
as a ChaCha20 key and yields the concatenation
|
||||
.Pf ChaCha20_ Fa k Ns Pq 0
|
||||
||
|
||||
.Pf ChaCha20_ Fa k Ns Pq 1
|
||||
|| ... as output.
|
||||
.Fn arc4random_uniform
|
||||
repeats
|
||||
.Fn arc4random
|
||||
until it obtains an integer in [2^32 %
|
||||
.Fa bound ,
|
||||
2^32), and reduces that modulo
|
||||
.Fa bound .
|
||||
.Pp
|
||||
The PRNG state is per-thread, unless memory allocation fails inside the
|
||||
library, in which case some threads may share global PRNG state with a
|
||||
mutex.
|
||||
The global PRNG state is zeroed on fork in the parent via
|
||||
.Xr pthread_atfork 3 ,
|
||||
and the per-thread PRNG state is zeroed on fork in the child via
|
||||
.Xr minherit 2
|
||||
with
|
||||
.Dv MAP_INHERIT_ZERO ,
|
||||
so that the child cannot reuse or see the parent's PRNG state.
|
||||
The PRNG state is reseeded automatically from the system entropy pool
|
||||
on the first use of an
|
||||
.Nm
|
||||
function after zeroing.
|
||||
.Pp
|
||||
The first use of an
|
||||
.Nm
|
||||
function may abort the process in the highly unlikely event that
|
||||
library initialization necessary to implement the security model fails.
|
||||
Additionally,
|
||||
.Fn arc4random_stir
|
||||
and
|
||||
.Fn arc4random_addrandom
|
||||
may abort the process in the highly unlikely event that the operating
|
||||
system fails to provide entropy.
|
||||
.Sh SEE ALSO
|
||||
.Xr rand 3 ,
|
||||
.Xr rand48 3 ,
|
||||
.Xr random 3
|
||||
.Xr random 3 ,
|
||||
.Xr rnd 4 ,
|
||||
.Xr cprng 9
|
||||
.Rs
|
||||
.%A Daniel J. Bernstein
|
||||
.%T ChaCha, a variant of Salsa20
|
||||
.%D 2008-01-28
|
||||
.%O Document ID: 4027b5256e17b9796842e6d0f68b0b5e
|
||||
.%U http://cr.yp.to/papers.html#chacha
|
||||
.Re
|
||||
.Sh HISTORY
|
||||
These functions first appeared in
|
||||
.Ox 2.1 ,
|
||||
@@ -135,12 +257,85 @@ These functions first appeared in
|
||||
.Nx 1.6 ,
|
||||
and
|
||||
.Dx 1.0 .
|
||||
The functions
|
||||
.Fn arc4random ,
|
||||
.Fn arc4random_buf
|
||||
and
|
||||
.Fn arc4random_uniform
|
||||
appeared in glibc 2.36.
|
||||
.Sh BUGS
|
||||
There is no way to get deterministic, reproducible results out of
|
||||
.Nm
|
||||
for testing purposes.
|
||||
.Pp
|
||||
The original version of this random number generator used the
|
||||
RC4 (also known as ARC4) algorithm.
|
||||
In
|
||||
.Ox 5.5
|
||||
it was replaced with the ChaCha20 cipher, and it may be replaced
|
||||
again in the future as cryptographic techniques advance.
|
||||
A good mnemonic is
|
||||
.Dq A Replacement Call for Random .
|
||||
The name
|
||||
.Sq arc4random
|
||||
was chosen for hysterical raisins -- it was originally implemented
|
||||
using the RC4 stream cipher, which has been known since shortly after
|
||||
it was published in 1994 to have observable biases in the output, and
|
||||
is now known to be broken badly enough to admit practical attacks in
|
||||
the real world.
|
||||
.\" Bob Jenkins, sci.crypt post dated 1994-09-16, message-id
|
||||
.\" <359qjg$55v$1@mhadg.production.compuserve.com>,
|
||||
.\" https://groups.google.com/d/msg/sci.crypt/JsO3xEATGFA/-wO4ttv7BCYJ
|
||||
.\"
|
||||
.\" Andrew Roos, `A Class of Weak Keys in the RC4 Stream Cipher',
|
||||
.\" sci.crypt posts dated 1995-09-22, message-ids
|
||||
.\" <43u1eh$1j3@hermes.is.co.za> and <44ebge$llf@hermes.is.co.za>.
|
||||
.\"
|
||||
.\" Paul Crowley, `Small bias in RC4 experimentally verified', March
|
||||
.\" 1998, http://www.ciphergoth.org/crypto/rc4/
|
||||
Unfortunately, the library found widespread adoption and the name stuck
|
||||
before anyone recognized that it was silly.
|
||||
.Pp
|
||||
The signature of
|
||||
.Fn arc4random_addrandom
|
||||
is silly.
|
||||
There is no reason to require casts or accept negative lengths:
|
||||
it should take a
|
||||
.Vt void *
|
||||
buffer and a
|
||||
.Vt size_t
|
||||
length.
|
||||
But it's too late to change that now.
|
||||
.Pp
|
||||
.Fn arc4random_uniform
|
||||
does not help to choose integers in [0,
|
||||
.Fa n )
|
||||
uniformly at random when
|
||||
.Fa n
|
||||
> 2^32.
|
||||
.Pp
|
||||
The security model of
|
||||
.Nm
|
||||
is stronger than many applications need, and stronger than other
|
||||
operating systems provide.
|
||||
For example, applications encrypting messages with random, but not
|
||||
secret, initialization vectors need only prevent an adversary from
|
||||
guessing future outputs, since past outputs will have been published
|
||||
already.
|
||||
.Pp
|
||||
On the one hand,
|
||||
.Nm
|
||||
could be marginally faster if it were not necessary to prevent an
|
||||
adversary who sees the state from predicting past outputs.
|
||||
On the other hand, there are applications in the wild that use
|
||||
.Nm
|
||||
to generate key material, such as OpenSSH, so for the sake of
|
||||
.Nx
|
||||
users it would be imprudent to weaken the security model.
|
||||
On the third hand, relying on the security model of
|
||||
.Nm
|
||||
in
|
||||
.Nx
|
||||
may lead you to an unpleasant surprise on another operating system
|
||||
whose implementation of
|
||||
.Nm
|
||||
has a weaker security model.
|
||||
.Pp
|
||||
One may be tempted to create new APIs to accommodate different
|
||||
security models and performance constraints without unpleasant
|
||||
surprises on different operating systems.
|
||||
This should not be done lightly, though, because there are already too
|
||||
many different choices, and too many opportunities for programmers to
|
||||
reach for one and pick the wrong one.
|
||||
|
@@ -51,8 +51,17 @@ from the per-process object reference table.
|
||||
Any errors encountered while closing file descriptors are ignored.
|
||||
.Sh SEE ALSO
|
||||
.Xr close 2
|
||||
.Sh STANDARDS
|
||||
.Fn closefrom
|
||||
is a
|
||||
.Bx
|
||||
and Solaris extension.
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn closefrom
|
||||
function first appeared in
|
||||
.Fx 8.0 .
|
||||
function first appeared in Solaris 9,
|
||||
.Ox 3.5 ,
|
||||
.Dx 1.2 ,
|
||||
.Nx 3.0 ,
|
||||
.Fx 8.0
|
||||
and glibc 2.34.
|
||||
|
@@ -150,4 +150,6 @@ if it runs out of memory.
|
||||
The
|
||||
.Fn fparseln
|
||||
function first appeared in
|
||||
.Nx 1.4 .
|
||||
.Nx 1.4
|
||||
and
|
||||
.Fx 4.0 .
|
||||
|
@@ -170,7 +170,11 @@ The
|
||||
.Fn funopen
|
||||
function
|
||||
may not be portable to systems other than
|
||||
.Bx .
|
||||
.Bx
|
||||
and glibc-based (as the libbsd implementation is only provided when the
|
||||
system has
|
||||
.Fn fopencookie
|
||||
available).
|
||||
.Pp
|
||||
On
|
||||
.Fx ,
|
||||
|
@@ -139,4 +139,7 @@ or the kernel returned invalid data.
|
||||
The
|
||||
.Fn getpeereid
|
||||
function appeared in
|
||||
.Fx 4.6 .
|
||||
.Fx 4.6 ,
|
||||
.Nx 5.0
|
||||
and
|
||||
.Ox 3.0 .
|
||||
|
@@ -166,7 +166,9 @@ represented a number that does not fit in
|
||||
.Sh HISTORY
|
||||
.Fn humanize_number
|
||||
first appeared in
|
||||
.Nx 2.0 .
|
||||
.Nx 2.0
|
||||
and
|
||||
.Fx 5.3 .
|
||||
.Pp
|
||||
.Fn dehumanize_number
|
||||
first appeared in
|
||||
|
24
man/libbsd.7
24
man/libbsd.7
@@ -76,7 +76,7 @@ The package also provides a
|
||||
.Nm libbsd-ctor
|
||||
static library that can be used to inject automatic constructors into a
|
||||
program so that the
|
||||
.Fn setproctitle_init 3
|
||||
.Xr setproctitle_init 3
|
||||
function gets invoked automatically at startup time.
|
||||
This can be done with the
|
||||
.Xr pkgconf 1
|
||||
@@ -128,7 +128,7 @@ It only works in non-overlay mode.
|
||||
.Bl -tag -width 4m -compact
|
||||
.It In bsd/bsd.h
|
||||
.El
|
||||
.Sh ALTERNATIVES
|
||||
.Sh VARIANTS
|
||||
Some functions have different prototypes depending on the BSD where they
|
||||
originated from, and these various implementations provided are selectable
|
||||
at build-time.
|
||||
@@ -140,9 +140,9 @@ This is the list of functions that provide multiple implementations:
|
||||
.It Fn strnunvis 3
|
||||
.Nx
|
||||
added
|
||||
.Fn strnvis 3
|
||||
.Xr strnvis 3
|
||||
and
|
||||
.Fn strnunvis 3
|
||||
.Xr strnunvis 3
|
||||
but unfortunately made it incompatible with the existing one in
|
||||
.Ox
|
||||
and Freedesktop's libbsd (the former having existed for over ten years).
|
||||
@@ -184,7 +184,7 @@ An implementation has to choose between leaking buffers or being reentrant
|
||||
for a limited amount of streams (this implementation chose the latter with
|
||||
a limit of 32).
|
||||
Use
|
||||
.Fn getline 3
|
||||
.Xr getline 3
|
||||
instead, which is available in many systems and required by
|
||||
.St -p1003.1-2008 .
|
||||
.It Fn fgetwln 3
|
||||
@@ -193,7 +193,7 @@ An implementation has to choose between leaking buffers or being reentrant
|
||||
for a limited amount of streams (this implementation chose the latter with
|
||||
a limit of 32).
|
||||
Use
|
||||
.Fn fgetwc 3
|
||||
.Xr fgetwc 3
|
||||
instead, which is available in many systems and required by
|
||||
.St -isoC-99
|
||||
and
|
||||
@@ -201,7 +201,7 @@ and
|
||||
.It Fn funopen 3
|
||||
Unportable, requires assistance from the stdio layer or some hook framework.
|
||||
On GNU systems the
|
||||
.Fn fopencookie 3
|
||||
.Xr fopencookie 3
|
||||
function can be used.
|
||||
Otherwise the code needs to be prepared for neither of these functions being
|
||||
available.
|
||||
@@ -240,16 +240,16 @@ This function is provided by
|
||||
2.26, and
|
||||
.Nm musl
|
||||
1.2.2.
|
||||
.It Fn arc4random 3
|
||||
.It Fn arc4random_buf 3
|
||||
.It Fn arc4random_uniform 3
|
||||
.It Xr arc4random 3
|
||||
.It Xr arc4random_buf 3
|
||||
.It Xr arc4random_uniform 3
|
||||
These functions are provided by
|
||||
.Nm glibc
|
||||
2.36.
|
||||
Note that it does not provide the
|
||||
.Fn arc4random_stir 3
|
||||
.Xr arc4random_stir 3
|
||||
and
|
||||
.Fn arc4random_addrandom 3
|
||||
.Xr arc4random_addrandom 3
|
||||
functions.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
|
@@ -292,6 +292,20 @@ Probably called not from the process which used
|
||||
.Xr open 2 ,
|
||||
.Xr daemon 3 ,
|
||||
.Xr flopen 3bsd
|
||||
.Sh HISTORY
|
||||
The functions
|
||||
.Fn pidfile_open ,
|
||||
.Fn pidfile_write ,
|
||||
.Fn pidfile_close
|
||||
and
|
||||
.Fn pidfile_remove
|
||||
first appeared in
|
||||
.Fx 5.5 .
|
||||
.Pp
|
||||
The function
|
||||
.Fn pidfile_fileno
|
||||
first appeared in
|
||||
.Fx 10.0 .
|
||||
.Sh AUTHORS
|
||||
.An -nosplit
|
||||
The
|
||||
|
@@ -137,7 +137,7 @@ The
|
||||
.Fn uid_from_user
|
||||
and
|
||||
.Fn gid_from_group
|
||||
functions were ported from
|
||||
.Nx
|
||||
and first appeared in
|
||||
functions first appeared in
|
||||
.Nx 1.4
|
||||
and
|
||||
.Ox 6.4 .
|
||||
|
@@ -165,10 +165,12 @@ will reprint the prompt and the user may then enter a passphrase.
|
||||
The
|
||||
.Fn readpassphrase
|
||||
function is an
|
||||
.Ox
|
||||
.Bx
|
||||
extension and should not be used if portability is desired.
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn readpassphrase
|
||||
function first appeared in
|
||||
.Ox 2.9 .
|
||||
.Ox 2.9
|
||||
and
|
||||
.Fx 4.6 .
|
||||
|
@@ -283,12 +283,18 @@ The
|
||||
.Fn reallocarray
|
||||
function appeared in
|
||||
.Ox 5.6 ,
|
||||
.Dx 5.5
|
||||
and glibc 2.26.
|
||||
.Pp
|
||||
The
|
||||
.Fn recallocarray
|
||||
function appeared in
|
||||
.Ox 6.1 .
|
||||
.Ox 6.1
|
||||
and
|
||||
.Dx 5.5 .
|
||||
The
|
||||
.Fn freezero
|
||||
function appeared in
|
||||
.Ox 6.2 .
|
||||
.Ox 6.2
|
||||
and
|
||||
.Dx 5.5 .
|
||||
|
@@ -20,7 +20,7 @@
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.\" The following requests are required for all man pages.
|
||||
.Dd December 16, 1995
|
||||
.Dd December 7, 2022
|
||||
.Dt setproctitle 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
@@ -31,7 +31,6 @@
|
||||
.ds doc-str-Lb-libbsd \*[str-Lb-libbsd]
|
||||
.Lb libbsd
|
||||
.Sh SYNOPSIS
|
||||
.In sys/types.h
|
||||
.In unistd.h
|
||||
(See
|
||||
.Xr libbsd 7
|
||||
@@ -113,6 +112,8 @@ The
|
||||
.Fn setproctitle
|
||||
function
|
||||
first appeared in
|
||||
.Nx 1.0
|
||||
and
|
||||
.Fx 2.2 .
|
||||
Other operating systems have
|
||||
similar functions.
|
||||
|
@@ -14,7 +14,7 @@
|
||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.Dd $Mdocdate: May 31 2007 $
|
||||
.Dd $Mdocdate: January 7 2024 $
|
||||
.Dt strlcpy 3bsd
|
||||
.Os
|
||||
.Sh NAME
|
||||
@@ -192,4 +192,7 @@ and
|
||||
functions first appeared in
|
||||
.Ox 2.4 ,
|
||||
and made their appearance in
|
||||
.Fx 3.3 .
|
||||
.Nx 1.4.3 ,
|
||||
.Fx 3.3
|
||||
and
|
||||
glibc 2.38.
|
||||
|
@@ -112,3 +112,8 @@ ptr = strnstr(largestring, smallstring, 4);
|
||||
.Xr strspn 3 ,
|
||||
.Xr strtok 3 ,
|
||||
.Xr wcsstr 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn strnstr
|
||||
function originated in
|
||||
.Fx .
|
||||
|
@@ -233,7 +233,7 @@ function first appeared in
|
||||
.Nx 7.0 .
|
||||
.Ox
|
||||
introduced the
|
||||
.Fn strtonum 3bsd
|
||||
.Xr strtonum 3bsd
|
||||
function for the same purpose, but the interface makes it impossible to
|
||||
properly differentiate illegal returns.
|
||||
.Sh BUGS
|
||||
|
@@ -141,8 +141,8 @@ The string did not consist solely of digit characters.
|
||||
.Xr strtoull 3
|
||||
.Sh STANDARDS
|
||||
.Fn strtonum
|
||||
is an
|
||||
.Ox
|
||||
is a
|
||||
.Bx
|
||||
extension.
|
||||
.Sh HISTORY
|
||||
.ds doc-operating-system-NetBSD-8.0 8.0
|
||||
@@ -154,9 +154,9 @@ function first appeared in
|
||||
was redesigned in
|
||||
.Nx 8.0
|
||||
as
|
||||
.Fn strtoi 3bsd
|
||||
.Xr strtoi 3bsd
|
||||
and
|
||||
.Fn strtou 3bsd .
|
||||
.Xr strtou 3bsd .
|
||||
.Sh CAVEATS
|
||||
The
|
||||
.Fn strtonum
|
||||
@@ -186,6 +186,6 @@ To overcome the shortcomings of
|
||||
.Fn strtonum
|
||||
.Nx
|
||||
provides
|
||||
.Fn strtou 3bsd
|
||||
.Xr strtou 3bsd
|
||||
and
|
||||
.Fn strtoi 3bsd .
|
||||
.Xr strtoi 3bsd .
|
||||
|
@@ -233,7 +233,7 @@ function first appeared in
|
||||
.Nx 7.0 .
|
||||
.Ox
|
||||
introduced the
|
||||
.Fn strtonum 3bsd
|
||||
.Xr strtonum 3bsd
|
||||
function for the same purpose, but the interface makes it impossible to
|
||||
properly differentiate illegal returns.
|
||||
.Sh BUGS
|
||||
|
@@ -562,6 +562,9 @@ main(void)
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr queue 3bsd
|
||||
.Sh HISTORY
|
||||
The tree macros first appeared in
|
||||
.Fx 4.6 .
|
||||
.Sh NOTES
|
||||
Trying to free a tree in the following way is a common error:
|
||||
.Bd -literal -offset indent
|
||||
|
@@ -69,3 +69,14 @@ counterpart, such as
|
||||
and
|
||||
.Fn wcslcpy ,
|
||||
which are BSD extensions.
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn wcslcpy
|
||||
and
|
||||
.Fn wcslcat
|
||||
functions first appeared in
|
||||
.Ox 3.8 ,
|
||||
.Nx 1.6 ,
|
||||
.Fx 5.0
|
||||
and
|
||||
.Dx 2.1 .
|
||||
|
134
src/Makefile.am
134
src/Makefile.am
@@ -5,13 +5,14 @@ AM_CPPFLAGS = \
|
||||
-isystem $(top_srcdir)/include/bsd/ \
|
||||
-include $(top_builddir)/config.h \
|
||||
-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
|
||||
-D__REENTRANT
|
||||
-D__REENTRANT \
|
||||
# EOL
|
||||
|
||||
if OS_WINDOWS
|
||||
AM_CPPFLAGS += \
|
||||
-D_CRT_SECURE_NO_WARNINGS \
|
||||
-D_CRT_NONSTDC_NO_WARNINGS \
|
||||
$(nil)
|
||||
# EOL
|
||||
endif
|
||||
|
||||
libbsd_la_included_sources = \
|
||||
@@ -23,7 +24,7 @@ libbsd_la_included_sources = \
|
||||
getentropy_osx.c \
|
||||
getentropy_solaris.c \
|
||||
getentropy_win.c \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
CLEANFILES =
|
||||
EXTRA_DIST = \
|
||||
@@ -32,13 +33,13 @@ EXTRA_DIST = \
|
||||
libbsd-ctor.pc.in \
|
||||
libbsd-overlay.pc.in \
|
||||
$(libbsd_la_included_sources) \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = \
|
||||
libbsd.pc \
|
||||
libbsd-overlay.pc \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
lib_LTLIBRARIES = libbsd.la
|
||||
lib_LIBRARIES =
|
||||
@@ -49,41 +50,42 @@ pkgconfig_DATA += libbsd-ctor.pc
|
||||
lib_LIBRARIES += libbsd-ctor.a
|
||||
endif
|
||||
|
||||
libbsd_la_DEPENDENCIES = \
|
||||
EXTRA_libbsd_la_DEPENDENCIES = \
|
||||
$(libbsd_la_included_sources) \
|
||||
libbsd.map
|
||||
libbsd.map \
|
||||
# EOL
|
||||
libbsd_la_LIBADD = \
|
||||
$(MD5_LIBS) \
|
||||
$(LIBBSD_LIBS) \
|
||||
$(nil)
|
||||
# EOL
|
||||
libbsd_la_LDFLAGS = \
|
||||
-version-number $(LIBBSD_ABI)
|
||||
-no-undefined \
|
||||
-version-number $(LIBBSD_ABI) \
|
||||
# EOL
|
||||
if HAVE_LINKER_VERSION_SCRIPT
|
||||
libbsd_la_LDFLAGS += \
|
||||
-Wl,--version-script=$(srcdir)/libbsd.map
|
||||
-Wl,--version-script=$(srcdir)/libbsd.map \
|
||||
# EOL
|
||||
else
|
||||
libbsd_la_LDFLAGS += \
|
||||
-export-symbols libbsd.sym \
|
||||
# EOL
|
||||
EXTRA_libbsd_la_DEPENDENCIES += \
|
||||
libbsd.sym \
|
||||
# EOL
|
||||
endif
|
||||
libbsd_la_SOURCES = \
|
||||
arc4random.c \
|
||||
arc4random.h \
|
||||
arc4random_linux.h \
|
||||
arc4random_uniform.c \
|
||||
arc4random_unix.h \
|
||||
arc4random_win.h \
|
||||
bsd_getopt.c \
|
||||
chacha_private.h \
|
||||
closefrom.c \
|
||||
dehumanize_number.c \
|
||||
err.c \
|
||||
expand_number.c \
|
||||
explicit_bzero.c \
|
||||
fgetln.c \
|
||||
freezero.c \
|
||||
fgetwln.c \
|
||||
flopen.c \
|
||||
fmtcheck.c \
|
||||
fparseln.c \
|
||||
fpurge.c \
|
||||
funopen.c \
|
||||
freezero.c \
|
||||
getbsize.c \
|
||||
getpeereid.c \
|
||||
heapsort.c \
|
||||
@@ -91,11 +93,8 @@ libbsd_la_SOURCES = \
|
||||
inet_net_pton.c \
|
||||
local-elf.h \
|
||||
local-link.h \
|
||||
md5.c \
|
||||
merge.c \
|
||||
nlist.c \
|
||||
pidfile.c \
|
||||
progname.c \
|
||||
pwcache.c \
|
||||
radixsort.c \
|
||||
readpassphrase.c \
|
||||
@@ -104,10 +103,7 @@ libbsd_la_SOURCES = \
|
||||
recallocarray.c \
|
||||
setmode.c \
|
||||
setproctitle.c \
|
||||
strlcat.c \
|
||||
strlcpy.c \
|
||||
stringlist.c \
|
||||
strmode.c \
|
||||
strnstr.c \
|
||||
strtoi.c \
|
||||
strtonum.c \
|
||||
@@ -115,14 +111,79 @@ libbsd_la_SOURCES = \
|
||||
timeconv.c \
|
||||
unvis.c \
|
||||
vis.c \
|
||||
wcslcat.c \
|
||||
wcslcpy.c \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
if NEED_PROGNAME
|
||||
libbsd_la_SOURCES += \
|
||||
progname.c \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_BSD_GETOPT
|
||||
libbsd_la_SOURCES += \
|
||||
bsd_getopt.c \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_ARC4RANDOM
|
||||
if !HAVE_GETENTROPY
|
||||
libbsd_la_SOURCES += \
|
||||
getentropy.c \
|
||||
$(nil)
|
||||
# EOL
|
||||
endif
|
||||
libbsd_la_SOURCES += \
|
||||
arc4random.c \
|
||||
arc4random.h \
|
||||
arc4random_linux.h \
|
||||
arc4random_uniform.c \
|
||||
arc4random_unix.h \
|
||||
arc4random_win.h \
|
||||
chacha_private.h \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_MD5
|
||||
libbsd_la_SOURCES += \
|
||||
md5.c \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_NLIST
|
||||
libbsd_la_SOURCES += \
|
||||
nlist.c \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_STRL
|
||||
libbsd_la_SOURCES += \
|
||||
strlcat.c \
|
||||
strlcpy.c \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_WCSL
|
||||
libbsd_la_SOURCES += \
|
||||
wcslcat.c \
|
||||
wcslcpy.c \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_STRMODE
|
||||
libbsd_la_SOURCES += \
|
||||
strmode.c \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_FPURGE
|
||||
libbsd_la_SOURCES += \
|
||||
fpurge.c \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_FUNOPEN
|
||||
libbsd_la_SOURCES += \
|
||||
funopen.c \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
if NEED_TRANSPARENT_LIBMD
|
||||
@@ -131,9 +192,18 @@ CLEANFILES += \
|
||||
# EOL
|
||||
endif
|
||||
|
||||
DISTCLEANFILES = \
|
||||
libbsd.sym \
|
||||
# EOL
|
||||
|
||||
libbsd_ctor_a_SOURCES = \
|
||||
setproctitle_ctor.c \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
# Generate a simple libtool symbol export list to be used as a fallback if
|
||||
# there is no version script support.
|
||||
libbsd.sym: libbsd.map
|
||||
$(AM_V_GEN) $(SED) -ne 's/^[[:space:]]\{1,\}\([A-Za-z0-9_]\{1,\}\);/\1/p' libbsd.map > $@
|
||||
|
||||
if NEED_TRANSPARENT_LIBMD
|
||||
TRANSPARENT_LIBMD_DEPENDS = format.ld
|
||||
|
@@ -25,10 +25,11 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "local-link.h"
|
||||
|
||||
|
29
src/flopen.c
29
src/flopen.c
@@ -38,6 +38,27 @@
|
||||
|
||||
#include <libutil.h>
|
||||
|
||||
static int
|
||||
lock_file(int fd, int flags)
|
||||
{
|
||||
int operation;
|
||||
|
||||
#if HAVE_FLOCK
|
||||
operation = LOCK_EX;
|
||||
if (flags & O_NONBLOCK)
|
||||
operation |= LOCK_NB;
|
||||
|
||||
return flock(fd, operation);
|
||||
#else
|
||||
if (flags & O_NONBLOCK)
|
||||
operation = F_TLOCK;
|
||||
else
|
||||
operation = F_LOCK;
|
||||
|
||||
return lockf(fd, operation, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Reliably open and lock a file.
|
||||
*
|
||||
@@ -49,7 +70,7 @@
|
||||
static int
|
||||
vflopenat(int dirfd, const char *path, int flags, va_list ap)
|
||||
{
|
||||
int fd, operation, serrno, trunc;
|
||||
int fd, serrno, trunc;
|
||||
struct stat sb, fsb;
|
||||
mode_t mode;
|
||||
|
||||
@@ -62,10 +83,6 @@ vflopenat(int dirfd, const char *path, int flags, va_list ap)
|
||||
mode = (mode_t)va_arg(ap, int); /* mode_t promoted to int */
|
||||
}
|
||||
|
||||
operation = LOCK_EX;
|
||||
if (flags & O_NONBLOCK)
|
||||
operation |= LOCK_NB;
|
||||
|
||||
trunc = (flags & O_TRUNC);
|
||||
flags &= ~O_TRUNC;
|
||||
|
||||
@@ -73,7 +90,7 @@ vflopenat(int dirfd, const char *path, int flags, va_list ap)
|
||||
if ((fd = openat(dirfd, path, flags, mode)) == -1)
|
||||
/* non-existent or no access */
|
||||
return (-1);
|
||||
if (flock(fd, operation) == -1) {
|
||||
if (lock_file(fd, flags) == -1) {
|
||||
/* unsupported or interrupted */
|
||||
serrno = errno;
|
||||
(void)close(fd);
|
||||
|
@@ -26,7 +26,9 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#if HAVE_STDIO_EXT_H
|
||||
#include <stdio_ext.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE___FPURGE
|
||||
int
|
||||
|
@@ -65,7 +65,7 @@ funopen_write(void *cookie, const char *buf, size_t size)
|
||||
}
|
||||
|
||||
static int
|
||||
funopen_seek(void *cookie, off64_t *offset, int whence)
|
||||
funopen_seek(void *cookie, off_t *offset, int whence)
|
||||
{
|
||||
struct funopen_cookie *cookiewrap = cookie;
|
||||
off_t soff = *offset;
|
||||
@@ -137,12 +137,6 @@ funopen(const void *cookie,
|
||||
|
||||
return fopencookie(cookiewrap, mode, funcswrap);
|
||||
}
|
||||
#elif defined(__MUSL__)
|
||||
/*
|
||||
* This is unimplementable on musl based systems, and upstream has stated
|
||||
* they will not add the needed support to implement it. Just ignore this
|
||||
* interface there, as it has never been provided anyway.
|
||||
*/
|
||||
#else
|
||||
#error "Function funopen() needs to be ported or disabled."
|
||||
#error "Function funopen() needs to be ported."
|
||||
#endif
|
||||
|
@@ -17,7 +17,8 @@ LIBBSD_0.0 {
|
||||
heapsort;
|
||||
humanize_number;
|
||||
|
||||
inet_net_pton; /* XXX: Already provided by glibc, remove. */
|
||||
/* XXX: Already provided by glibc, remove. */
|
||||
inet_net_pton;
|
||||
|
||||
getprogname;
|
||||
setprogname;
|
||||
@@ -54,7 +55,8 @@ LIBBSD_0.0 {
|
||||
LIBBSD_0.1 {
|
||||
strmode;
|
||||
|
||||
__fdnlist; /* Private symbol, but libkvm uses it. */
|
||||
/* Private symbol, but libkvm uses it. */
|
||||
__fdnlist;
|
||||
nlist;
|
||||
} LIBBSD_0.0;
|
||||
|
||||
|
@@ -29,9 +29,23 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#ifdef __ELF__
|
||||
#define libbsd_link_warning(symbol, msg) \
|
||||
static const char libbsd_emit_link_warning_##symbol[] \
|
||||
__attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg
|
||||
#else
|
||||
#define libbsd_link_warning(symbol, msg)
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define libbsd_strong_alias(alias, symbol) \
|
||||
__asm__(".globl _" #alias); \
|
||||
__asm__(".set _" #alias ", _" #symbol); \
|
||||
extern __typeof(symbol) alias
|
||||
#elif !defined(_MSC_VER)
|
||||
#define libbsd_strong_alias(alias, symbol) \
|
||||
extern __typeof__(symbol) alias __attribute__((__alias__(#symbol)))
|
||||
#endif
|
||||
|
||||
#ifdef __ELF__
|
||||
# if __has_attribute(symver)
|
||||
@@ -60,7 +74,7 @@
|
||||
# endif
|
||||
#else
|
||||
#define libbsd_symver_default(alias, symbol, version) \
|
||||
extern __typeof__(symbol) alias __attribute__((__alias__(#symbol)))
|
||||
libbsd_strong_alias(alias, symbol)
|
||||
|
||||
#define libbsd_symver_variant(alias, symbol, version)
|
||||
|
||||
|
@@ -84,9 +84,8 @@ static void insertionsort(unsigned char *, size_t, size_t,
|
||||
*/
|
||||
/* Assumption: PSIZE is a power of 2. */
|
||||
#define EVAL(p) (unsigned char **) \
|
||||
((unsigned char *)0 + \
|
||||
(((unsigned char *)p + PSIZE - 1 - \
|
||||
(unsigned char *)0) & ~(PSIZE - 1)))
|
||||
(unsigned char *)0) & ~(PSIZE - 1))
|
||||
|
||||
/*
|
||||
* Arguments are as for qsort.
|
||||
|
@@ -35,6 +35,9 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_PROCINFO_H
|
||||
#include <procinfo.h>
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#include <shlwapi.h>
|
||||
@@ -62,6 +65,14 @@ getprogname(void)
|
||||
/* getexecname(3) returns an absolute pathname, normalize it. */
|
||||
if (__progname == NULL)
|
||||
setprogname(getexecname());
|
||||
#elif defined(_AIX)
|
||||
if (__progname == NULL) {
|
||||
struct procentry64 procs;
|
||||
pid_t pid = getpid ();
|
||||
|
||||
if (getprocs64(&procs, sizeof procs, NULL, 0, &pid, 1) > 0)
|
||||
__progname = strdup(procs.pi_comm);
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
if (__progname == NULL) {
|
||||
WCHAR *wpath = NULL;
|
||||
@@ -126,6 +137,8 @@ done:
|
||||
free(wpath);
|
||||
free(mbname);
|
||||
}
|
||||
#else
|
||||
#error "Function getprogname() needs to be ported."
|
||||
#endif
|
||||
|
||||
return __progname;
|
||||
|
@@ -83,8 +83,12 @@ typedef struct gidc {
|
||||
* cache both hits and misses.
|
||||
*/
|
||||
|
||||
#ifndef HAVE_USER_FROM_UID
|
||||
static UIDC **uidtb; /* uid to name cache */
|
||||
#endif
|
||||
#ifndef HAVE_GROUP_FROM_GID
|
||||
static GIDC **gidtb; /* gid to name cache */
|
||||
#endif
|
||||
static UIDC **usrtb; /* user name to uid cache */
|
||||
static GIDC **grptb; /* group name to gid cache */
|
||||
|
||||
@@ -103,6 +107,7 @@ st_hash(const char *name, size_t len, int tabsz)
|
||||
return key % tabsz;
|
||||
}
|
||||
|
||||
#ifndef HAVE_USER_FROM_UID
|
||||
/*
|
||||
* uidtb_start
|
||||
* creates an an empty uidtb
|
||||
@@ -124,7 +129,9 @@ uidtb_start(void)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GROUP_FROM_GID
|
||||
/*
|
||||
* gidtb_start
|
||||
* creates an an empty gidtb
|
||||
@@ -146,6 +153,7 @@ gidtb_start(void)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* usrtb_start
|
||||
@@ -191,6 +199,7 @@ grptb_start(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef HAVE_USER_FROM_UID
|
||||
/*
|
||||
* user_from_uid()
|
||||
* caches the name (if any) for the uid. If noname clear, we always
|
||||
@@ -251,7 +260,9 @@ user_from_uid(uid_t uid, int noname)
|
||||
}
|
||||
return ptr->name;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GROUP_FROM_GID
|
||||
/*
|
||||
* group_from_gid()
|
||||
* caches the name (if any) for the gid. If noname clear, we always
|
||||
@@ -312,6 +323,7 @@ group_from_gid(gid_t gid, int noname)
|
||||
}
|
||||
return ptr->name;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* uid_from_user()
|
||||
|
@@ -36,6 +36,15 @@
|
||||
#define TCSASOFT 0
|
||||
#endif
|
||||
|
||||
#ifndef _NSIG
|
||||
#if defined(NSIG)
|
||||
#define _NSIG NSIG
|
||||
#else
|
||||
/* The SIGRTMAX define might be set to a function such as sysconf(). */
|
||||
#define _NSIG (SIGRTMAX + 1)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static volatile sig_atomic_t signo[_NSIG];
|
||||
|
||||
static void handler(int);
|
||||
|
@@ -33,6 +33,10 @@
|
||||
#include <string.h>
|
||||
#include "local-link.h"
|
||||
|
||||
#if !HAVE_DECL_ENVIRON
|
||||
extern char **environ;
|
||||
#endif
|
||||
|
||||
static struct {
|
||||
/* Original value. */
|
||||
const char *arg0;
|
||||
@@ -280,7 +284,7 @@ setproctitle_impl(const char *fmt, ...)
|
||||
|
||||
if (nul < SPT.nul) {
|
||||
*SPT.nul = '.';
|
||||
} else if (nul == SPT.nul && &nul[1] < SPT.end) {
|
||||
} else if (nul == SPT.nul && (nul + 1) < SPT.end) {
|
||||
*SPT.nul = ' ';
|
||||
*++nul = '\0';
|
||||
}
|
||||
@@ -291,10 +295,8 @@ libbsd_symver_default(setproctitle, setproctitle_impl, LIBBSD_0.5);
|
||||
* in 0.5, make the implementation available in the old version as an alias
|
||||
* for code linking against that version, and change the default to use the
|
||||
* new version, so that new code depends on the implemented version. */
|
||||
#ifdef HAVE_TYPEOF
|
||||
extern __typeof__(setproctitle_impl)
|
||||
setproctitle_stub
|
||||
__attribute__((__alias__("setproctitle_impl")));
|
||||
#if defined(libbsd_strong_alias)
|
||||
libbsd_strong_alias(setproctitle_stub, setproctitle_impl);
|
||||
#else
|
||||
void
|
||||
setproctitle_stub(const char *fmt, ...)
|
||||
|
@@ -4,30 +4,32 @@ HEADERS_CPPFLAGS = \
|
||||
-I$(top_builddir) \
|
||||
-include $(top_builddir)/config.h \
|
||||
-DLIBBSD_DISABLE_DEPRECATED \
|
||||
-D__REENTRANT
|
||||
-D__REENTRANT \
|
||||
# EOL
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-isystem $(top_srcdir)/include/bsd/ \
|
||||
$(HEADERS_CPPFLAGS) \
|
||||
-DLIBBSD_OVERLAY
|
||||
-DLIBBSD_OVERLAY \
|
||||
# EOL
|
||||
|
||||
AM_TESTS_ENVIRONMENT = \
|
||||
export CC="$(CC)"; \
|
||||
export CPPFLAGS="$(HEADERS_CPPFLAGS)"; \
|
||||
export top_srcdir="$(top_srcdir)"; \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
LDADD = $(top_builddir)/src/libbsd.la
|
||||
|
||||
EXTRA_DIST = \
|
||||
headers-overlay.sh \
|
||||
headers-system.sh \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
check_SCRIPTS = \
|
||||
headers-overlay.sh \
|
||||
headers-system.sh \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
check_PROGRAMS = \
|
||||
overlay \
|
||||
@@ -37,43 +39,66 @@ check_PROGRAMS = \
|
||||
explicit_bzero \
|
||||
humanize \
|
||||
fgetln \
|
||||
funopen \
|
||||
fparseln \
|
||||
fpurge \
|
||||
md5 \
|
||||
nlist \
|
||||
proctitle-init \
|
||||
progname \
|
||||
pwcache \
|
||||
setmode \
|
||||
strl \
|
||||
strmode \
|
||||
strnstr \
|
||||
strtonum \
|
||||
vis \
|
||||
vis-openbsd \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
if NEED_PROGNAME
|
||||
check_PROGRAMS += progname
|
||||
endif
|
||||
|
||||
if NEED_NLIST
|
||||
check_PROGRAMS += nlist
|
||||
endif
|
||||
|
||||
if NEED_STRL
|
||||
check_PROGRAMS += strl
|
||||
endif
|
||||
|
||||
if NEED_STRMODE
|
||||
check_PROGRAMS += strmode
|
||||
endif
|
||||
|
||||
if NEED_FPURGE
|
||||
check_PROGRAMS += fpurge
|
||||
endif
|
||||
|
||||
if NEED_FUNOPEN
|
||||
check_PROGRAMS += funopen
|
||||
endif
|
||||
|
||||
if NEED_ARC4RANDOM
|
||||
if HAVE_LIBTESTU01
|
||||
arc4random_LDADD = $(LDADD) $(TESTU01_LIBS)
|
||||
|
||||
check_PROGRAMS += arc4random
|
||||
endif
|
||||
endif
|
||||
|
||||
if BUILD_LIBBSD_CTOR
|
||||
proctitle_LDFLAGS = \
|
||||
-Wl,-u,libbsd_init_func \
|
||||
$(top_builddir)/src/libbsd-ctor.a \
|
||||
$(top_builddir)/src/libbsd.la \
|
||||
$(nil)
|
||||
# EOL
|
||||
|
||||
check_PROGRAMS += proctitle
|
||||
endif
|
||||
|
||||
if NEED_MD5
|
||||
check_PROGRAMS += md5
|
||||
|
||||
if NEED_TRANSPARENT_LIBMD
|
||||
# On the installed system this is handled via the ld script.
|
||||
md5_LDADD = $(LDADD) $(MD5_LIBS)
|
||||
endif
|
||||
endif
|
||||
|
||||
fgetln_SOURCES = test-stream.c test-stream.h fgetln.c
|
||||
fgetln_CFLAGS = -Wno-deprecated-declarations
|
||||
|
@@ -35,18 +35,46 @@ main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int fd;
|
||||
int fd_max;
|
||||
|
||||
fd = open("/dev/null", O_RDONLY);
|
||||
|
||||
for (i = 4; i < 1024; i *= 2)
|
||||
assert(dup2(fd, i) == i);
|
||||
fd_max = 1024;
|
||||
|
||||
/* First make sure we have a clean fd list. */
|
||||
for (i = 4; i < fd_max; i++)
|
||||
close(i);
|
||||
|
||||
/* Then initialize each even fd. */
|
||||
for (i = 4; i < fd_max; i *= 2) {
|
||||
int fd_new = dup2(fd, i);
|
||||
|
||||
if (fd_new < 0 && (errno == EMFILE || errno == EBADF)) {
|
||||
fd_max = i - 1;
|
||||
break;
|
||||
}
|
||||
assert(fd_new == i);
|
||||
}
|
||||
|
||||
if (fd < 4)
|
||||
close(fd);
|
||||
closefrom(4);
|
||||
|
||||
for (i = 4; i < 1024; i++)
|
||||
assert(fcntl(i, F_GETFL) == -1 && errno == EBADF);
|
||||
for (i = 4; i < fd_max; i++) {
|
||||
int rc;
|
||||
|
||||
errno = 0;
|
||||
rc = fcntl(i, F_GETFD);
|
||||
#ifdef __APPLE__
|
||||
/* On macOS we only set close-on-exec. */
|
||||
if ((i & (i - 1)) == 0)
|
||||
assert(rc == FD_CLOEXEC);
|
||||
else
|
||||
assert(rc == -1 && errno == EBADF);
|
||||
#else
|
||||
assert(rc == -1 && errno == EBADF);
|
||||
#endif
|
||||
}
|
||||
assert(fcntl(fd, F_GETFL) == -1 && errno == EBADF);
|
||||
|
||||
return 0;
|
||||
|
@@ -27,6 +27,17 @@
|
||||
#define ASSERT_NE(a, b) assert((a) != (b))
|
||||
#define ASSERT_GE(a, b) assert((a) >= (b))
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(address_sanitizer)
|
||||
#define __SANITIZE_ADDRESS__
|
||||
#endif
|
||||
#endif
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
#define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
|
||||
#else
|
||||
#define ATTRIBUTE_NO_SANITIZE_ADDRESS
|
||||
#endif
|
||||
|
||||
/* 128 bits of random data. */
|
||||
static const char secret[16] = {
|
||||
0xa0, 0x6c, 0x0c, 0x81, 0xba, 0xd8, 0x5b, 0x0c,
|
||||
@@ -127,6 +138,7 @@ populate_secret(char *buf, ssize_t len)
|
||||
static void __attribute__((__noinline__))
|
||||
blank_stack_side_effects(char *buf, size_t len)
|
||||
{
|
||||
#if defined(__GNU__) && !defined(__SANITIZE_ADDRESS__)
|
||||
char scratch[SECRETBYTES * 4];
|
||||
|
||||
/* If the read(3) in populate_secret() wrote into the stack, as it
|
||||
@@ -134,6 +146,7 @@ blank_stack_side_effects(char *buf, size_t len)
|
||||
* detect the wrong secret on the stack. */
|
||||
memset(scratch, 0xFF, sizeof(scratch));
|
||||
ASSERT_EQ(NULL, memmem(scratch, sizeof(scratch), buf, len));
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -149,7 +162,7 @@ count_secrets(const char *buf)
|
||||
return (res);
|
||||
}
|
||||
|
||||
static char *
|
||||
ATTRIBUTE_NO_SANITIZE_ADDRESS static char *
|
||||
test_without_bzero(void)
|
||||
{
|
||||
char buf[SECRETBYTES];
|
||||
@@ -162,7 +175,7 @@ test_without_bzero(void)
|
||||
return (res);
|
||||
}
|
||||
|
||||
static char *
|
||||
ATTRIBUTE_NO_SANITIZE_ADDRESS static char *
|
||||
test_with_bzero(void)
|
||||
{
|
||||
char buf[SECRETBYTES];
|
||||
|
@@ -28,12 +28,38 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static int
|
||||
test_memstream(void)
|
||||
{
|
||||
int rc = 0;
|
||||
#if HAVE_OPEN_MEMSTREAM
|
||||
FILE *fp;
|
||||
char *buf = NULL;
|
||||
size_t bufsz = 0;
|
||||
|
||||
fp = open_memstream(&buf, &bufsz);
|
||||
if (fp == NULL)
|
||||
return 1;
|
||||
|
||||
fputs("World", fp);
|
||||
if (fpurge(fp) < 0)
|
||||
rc = 1;
|
||||
fflush(fp);
|
||||
if (bufsz != 0)
|
||||
rc = 1;
|
||||
|
||||
fclose(fp);
|
||||
free(buf);
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
FILE *fp;
|
||||
char *buf = NULL;
|
||||
size_t bufsz = 0;
|
||||
int rc;
|
||||
|
||||
if (fpurge(NULL) == 0)
|
||||
return 1;
|
||||
@@ -41,17 +67,9 @@ main(int argc, char *argv[])
|
||||
fp = fopen("/dev/zero", "r");
|
||||
if (fpurge(fp) < 0)
|
||||
return 1;
|
||||
|
||||
fclose(fp);
|
||||
|
||||
fp = open_memstream(&buf, &bufsz);
|
||||
fputs("World", fp);
|
||||
if (fpurge(fp) < 0)
|
||||
return 1;
|
||||
fflush(fp);
|
||||
if (bufsz != 0)
|
||||
return 1;
|
||||
free(buf);
|
||||
rc = test_memstream();
|
||||
|
||||
return 0;
|
||||
return rc;
|
||||
}
|
||||
|
@@ -18,8 +18,9 @@ int main() { return 0; }
|
||||
SOURCE
|
||||
|
||||
echo "testing header $inc"
|
||||
run $CC -isystem "$incdir" $CPPFLAGS headers-overlay-gen.c -o /dev/null
|
||||
run $CC -isystem "$incdir" $CPPFLAGS headers-overlay-gen.c -o headers-overlay
|
||||
echo
|
||||
|
||||
rm -f headers-overlay
|
||||
rm -f headers-overlay-gen*
|
||||
done
|
||||
|
@@ -17,8 +17,9 @@ int main() { return 0; }
|
||||
SOURCE
|
||||
|
||||
echo "testing header $inc"
|
||||
run $CC -isystem "$incdir" $CPPFLAGS headers-system-gen.c -o /dev/null
|
||||
run $CC -isystem "$incdir" $CPPFLAGS headers-system-gen.c -o headers-system
|
||||
echo
|
||||
|
||||
rm -f headers-system
|
||||
rm -f headers-system-gen.*
|
||||
done
|
||||
|
@@ -28,12 +28,14 @@
|
||||
* other headers through magic macros, to check that the overlay is working
|
||||
* properly. */
|
||||
#include <errno.h>
|
||||
#ifndef __APPLE__
|
||||
#ifdef HAVE_PWD_H
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
#ifdef HAVE_GRP_H
|
||||
#include <grp.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
|
||||
/* Include libbsd overlayed headers that might get partially included. */
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2021 Guillem Jover <guillem@hadrons.org>
|
||||
* Copyright © 2021, 2023 Guillem Jover <guillem@hadrons.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -26,24 +26,50 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
#define TEST_SKIP 77
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct group *gr;
|
||||
struct passwd *pw;
|
||||
char *uname;
|
||||
char *gname;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
|
||||
assert(uid_from_user("root", &uid) == 0);
|
||||
/* Do not hardcode user or group names. */
|
||||
pw = getpwuid(0);
|
||||
if (pw == NULL)
|
||||
return TEST_SKIP;
|
||||
uname = strdup(pw->pw_name);
|
||||
assert(uname != NULL);
|
||||
|
||||
gr = getgrgid(0);
|
||||
if (gr == NULL) {
|
||||
free(uname);
|
||||
return TEST_SKIP;
|
||||
}
|
||||
gname = strdup(gr->gr_name);
|
||||
assert(gname != NULL);
|
||||
|
||||
/* Test the functions. */
|
||||
assert(uid_from_user(uname, &uid) == 0);
|
||||
assert(uid == 0);
|
||||
|
||||
assert(strcmp(user_from_uid(0, 0), "root") == 0);
|
||||
assert(strcmp(user_from_uid(0, 0), uname) == 0);
|
||||
|
||||
assert(gid_from_group("root", &gid) == 0);
|
||||
assert(gid_from_group(gname, &gid) == 0);
|
||||
assert(gid == 0);
|
||||
|
||||
assert(strcmp(group_from_gid(0, 0), "root") == 0);
|
||||
assert(strcmp(group_from_gid(0, 0), gname) == 0);
|
||||
|
||||
free(uname);
|
||||
free(gname);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user