Compare commits
6 Commits
upstream/4
...
upstream/4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a475f464e0 | ||
|
|
65261e28f4 | ||
|
|
bd724b34e0 | ||
|
|
c2a3ebed18 | ||
|
|
f78a468368 | ||
|
|
9f68246a01 |
15
Makefile.am
15
Makefile.am
@@ -1,7 +1,5 @@
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
EXTRA_DIST = NEWS README
|
||||
|
||||
SUBDIRS = lib
|
||||
|
||||
if ENABLE_SUBIDS
|
||||
@@ -15,4 +13,15 @@ SUBDIRS += man
|
||||
endif
|
||||
|
||||
CLEANFILES = man/8.out man/po/remove-potcdate.* man/*/login.defs.d man/*/*.mo
|
||||
EXTRA_DIST = tests/
|
||||
|
||||
EXTRA_DIST = NEWS README tests/
|
||||
|
||||
dist-hook:
|
||||
chmod -R u+w $(distdir)/tests
|
||||
chmod u+w $(distdir)
|
||||
mv $(distdir)/tests/unit $(distdir)/realunittest
|
||||
mv $(distdir)/tests/tests $(distdir)/realtests
|
||||
rm -rf $(distdir)/tests
|
||||
mv $(distdir)/realtests $(distdir)/tests
|
||||
rm -rf $(distdir)/tests/unit $(distdir)/tests/Makefile*
|
||||
mv $(distdir)/realunittest $(distdir)/tests/unit
|
||||
|
||||
19
Makefile.in
19
Makefile.in
@@ -389,10 +389,10 @@ target_alias = @target_alias@
|
||||
top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
EXTRA_DIST = tests/
|
||||
SUBDIRS = lib $(am__append_1) src po contrib doc etc tests/unit \
|
||||
$(am__append_2)
|
||||
CLEANFILES = man/8.out man/po/remove-potcdate.* man/*/login.defs.d man/*/*.mo
|
||||
EXTRA_DIST = NEWS README tests/
|
||||
all: config.h
|
||||
$(MAKE) $(AM_MAKEFLAGS) all-recursive
|
||||
|
||||
@@ -622,6 +622,9 @@ distdir-am: $(DISTFILES)
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
$(MAKE) $(AM_MAKEFLAGS) \
|
||||
top_distdir="$(top_distdir)" distdir="$(distdir)" \
|
||||
dist-hook
|
||||
-test -n "$(am__skip_mode_fix)" \
|
||||
|| find "$(distdir)" -type d ! -perm -755 \
|
||||
-exec chmod u+rwx,go+rx {} \; -o \
|
||||
@@ -869,8 +872,8 @@ uninstall-am:
|
||||
.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \
|
||||
am--refresh check check-am clean clean-cscope clean-generic \
|
||||
clean-libtool cscope cscopelist-am ctags ctags-am dist \
|
||||
dist-all dist-bzip2 dist-gzip dist-lzip dist-shar dist-tarZ \
|
||||
dist-xz dist-zip dist-zstd distcheck distclean \
|
||||
dist-all dist-bzip2 dist-gzip dist-hook dist-lzip dist-shar \
|
||||
dist-tarZ dist-xz dist-zip dist-zstd distcheck distclean \
|
||||
distclean-generic distclean-hdr distclean-libtool \
|
||||
distclean-tags distcleancheck distdir distuninstallcheck dvi \
|
||||
dvi-am html html-am info info-am install install-am \
|
||||
@@ -886,6 +889,16 @@ uninstall-am:
|
||||
.PRECIOUS: Makefile
|
||||
|
||||
|
||||
dist-hook:
|
||||
chmod -R u+w $(distdir)/tests
|
||||
chmod u+w $(distdir)
|
||||
mv $(distdir)/tests/unit $(distdir)/realunittest
|
||||
mv $(distdir)/tests/tests $(distdir)/realtests
|
||||
rm -rf $(distdir)/tests
|
||||
mv $(distdir)/realtests $(distdir)/tests
|
||||
rm -rf $(distdir)/tests/unit $(distdir)/tests/Makefile*
|
||||
mv $(distdir)/realunittest $(distdir)/tests/unit
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
|
||||
80
aclocal.m4
vendored
80
aclocal.m4
vendored
@@ -931,7 +931,7 @@ dnl aclocal-1.4 backwards compatibility:
|
||||
dnl AC_DEFUN([AC_LTDL_DLSYM_USCORE], [])
|
||||
|
||||
# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
|
||||
# serial 12 (pkg-config-0.29.2)
|
||||
# serial 11 (pkg-config-0.29.1)
|
||||
|
||||
dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
|
||||
dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
|
||||
@@ -973,7 +973,7 @@ dnl
|
||||
dnl See the "Since" comment for each macro you use to see what version
|
||||
dnl of the macros you require.
|
||||
m4_defun([PKG_PREREQ],
|
||||
[m4_define([PKG_MACROS_VERSION], [0.29.2])
|
||||
[m4_define([PKG_MACROS_VERSION], [0.29.1])
|
||||
m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
|
||||
[m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
|
||||
])dnl PKG_PREREQ
|
||||
@@ -1074,7 +1074,7 @@ AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
|
||||
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
|
||||
|
||||
pkg_failed=no
|
||||
AC_MSG_CHECKING([for $2])
|
||||
AC_MSG_CHECKING([for $1])
|
||||
|
||||
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
|
||||
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
|
||||
@@ -1084,11 +1084,11 @@ and $1[]_LIBS to avoid the need to call pkg-config.
|
||||
See the pkg-config man page for more details.])
|
||||
|
||||
if test $pkg_failed = yes; then
|
||||
AC_MSG_RESULT([no])
|
||||
AC_MSG_RESULT([no])
|
||||
_PKG_SHORT_ERRORS_SUPPORTED
|
||||
if test $_pkg_short_errors_supported = yes; then
|
||||
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
|
||||
else
|
||||
else
|
||||
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
|
||||
fi
|
||||
# Put the nasty error message in config.log where it belongs
|
||||
@@ -1105,7 +1105,7 @@ installed software in a non-standard prefix.
|
||||
_PKG_TEXT])[]dnl
|
||||
])
|
||||
elif test $pkg_failed = untried; then
|
||||
AC_MSG_RESULT([no])
|
||||
AC_MSG_RESULT([no])
|
||||
m4_default([$4], [AC_MSG_FAILURE(
|
||||
[The pkg-config script could not be found or is too old. Make sure it
|
||||
is in your PATH or set the PKG_CONFIG environment variable to the full
|
||||
@@ -1206,6 +1206,74 @@ AS_VAR_COPY([$1], [pkg_cv_][$1])
|
||||
AS_VAR_IF([$1], [""], [$5], [$4])dnl
|
||||
])dnl PKG_CHECK_VAR
|
||||
|
||||
dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES,
|
||||
dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],
|
||||
dnl [DESCRIPTION], [DEFAULT])
|
||||
dnl ------------------------------------------
|
||||
dnl
|
||||
dnl Prepare a "--with-" configure option using the lowercase
|
||||
dnl [VARIABLE-PREFIX] name, merging the behaviour of AC_ARG_WITH and
|
||||
dnl PKG_CHECK_MODULES in a single macro.
|
||||
AC_DEFUN([PKG_WITH_MODULES],
|
||||
[
|
||||
m4_pushdef([with_arg], m4_tolower([$1]))
|
||||
|
||||
m4_pushdef([description],
|
||||
[m4_default([$5], [build with ]with_arg[ support])])
|
||||
|
||||
m4_pushdef([def_arg], [m4_default([$6], [auto])])
|
||||
m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes])
|
||||
m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no])
|
||||
|
||||
m4_case(def_arg,
|
||||
[yes],[m4_pushdef([with_without], [--without-]with_arg)],
|
||||
[m4_pushdef([with_without],[--with-]with_arg)])
|
||||
|
||||
AC_ARG_WITH(with_arg,
|
||||
AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),,
|
||||
[AS_TR_SH([with_]with_arg)=def_arg])
|
||||
|
||||
AS_CASE([$AS_TR_SH([with_]with_arg)],
|
||||
[yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)],
|
||||
[auto],[PKG_CHECK_MODULES([$1],[$2],
|
||||
[m4_n([def_action_if_found]) $3],
|
||||
[m4_n([def_action_if_not_found]) $4])])
|
||||
|
||||
m4_popdef([with_arg])
|
||||
m4_popdef([description])
|
||||
m4_popdef([def_arg])
|
||||
|
||||
])dnl PKG_WITH_MODULES
|
||||
|
||||
dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
|
||||
dnl [DESCRIPTION], [DEFAULT])
|
||||
dnl -----------------------------------------------
|
||||
dnl
|
||||
dnl Convenience macro to trigger AM_CONDITIONAL after PKG_WITH_MODULES
|
||||
dnl check._[VARIABLE-PREFIX] is exported as make variable.
|
||||
AC_DEFUN([PKG_HAVE_WITH_MODULES],
|
||||
[
|
||||
PKG_WITH_MODULES([$1],[$2],,,[$3],[$4])
|
||||
|
||||
AM_CONDITIONAL([HAVE_][$1],
|
||||
[test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"])
|
||||
])dnl PKG_HAVE_WITH_MODULES
|
||||
|
||||
dnl PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
|
||||
dnl [DESCRIPTION], [DEFAULT])
|
||||
dnl ------------------------------------------------------
|
||||
dnl
|
||||
dnl Convenience macro to run AM_CONDITIONAL and AC_DEFINE after
|
||||
dnl PKG_WITH_MODULES check. HAVE_[VARIABLE-PREFIX] is exported as make
|
||||
dnl and preprocessor variable.
|
||||
AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES],
|
||||
[
|
||||
PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4])
|
||||
|
||||
AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"],
|
||||
[AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])])
|
||||
])dnl PKG_HAVE_DEFINE_WITH_MODULES
|
||||
|
||||
# Copyright (C) 2002-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
|
||||
52
config.h.in
52
config.h.in
@@ -20,10 +20,6 @@
|
||||
/* Path for faillog file. */
|
||||
#undef FAILLOG_FILE
|
||||
|
||||
/* Define to the type of elements in the array set by `getgroups'. Usually
|
||||
this is either `int' or `gid_t'. */
|
||||
#undef GETGROUPS_T
|
||||
|
||||
/* max group name length */
|
||||
#undef GROUP_NAME_MAX_LENGTH
|
||||
|
||||
@@ -53,9 +49,6 @@
|
||||
the CoreFoundation framework. */
|
||||
#undef HAVE_CFPREFERENCESCOPYAPPVALUE
|
||||
|
||||
/* Define to 1 if you have the <crypt.h> header file. */
|
||||
#undef HAVE_CRYPT_H
|
||||
|
||||
/* Define if the GNU dcgettext() function is already present or preinstalled.
|
||||
*/
|
||||
#undef HAVE_DCGETTEXT
|
||||
@@ -119,24 +112,15 @@
|
||||
/* Define to 1 if you have the `getusershell' function. */
|
||||
#undef HAVE_GETUSERSHELL
|
||||
|
||||
/* Define to 1 if you have the <gshadow.h> header file. */
|
||||
#undef HAVE_GSHADOW_H
|
||||
|
||||
/* Define if you have the iconv() function and it works. */
|
||||
#undef HAVE_ICONV
|
||||
|
||||
/* Define to 1 if you have the `initgroups' function. */
|
||||
#undef HAVE_INITGROUPS
|
||||
|
||||
/* Define to 1 if you have the `innetgr' function. */
|
||||
#undef HAVE_INNETGR
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the <lastlog.h> header file. */
|
||||
#undef HAVE_LASTLOG_H
|
||||
|
||||
/* Define to 1 if you have the `lckpwdf' function. */
|
||||
#undef HAVE_LCKPWDF
|
||||
|
||||
@@ -164,9 +148,6 @@
|
||||
/* Define to 1 if you have the <minix/config.h> header file. */
|
||||
#undef HAVE_MINIX_CONFIG_H
|
||||
|
||||
/* Define to 1 if you have the <paths.h> header file. */
|
||||
#undef HAVE_PATHS_H
|
||||
|
||||
/* Define to 1 if you have the `putgrent' function. */
|
||||
#undef HAVE_PUTGRENT
|
||||
|
||||
@@ -179,9 +160,6 @@
|
||||
/* Define to 1 if you have the <readpassphrase.h> header file. */
|
||||
#undef HAVE_READPASSPHRASE_H
|
||||
|
||||
/* Define to 1 if you have the <rpc/key_prot.h> header file. */
|
||||
#undef HAVE_RPC_KEY_PROT_H
|
||||
|
||||
/* Define to 1 if you have the `rpmatch' function. */
|
||||
#undef HAVE_RPMATCH
|
||||
|
||||
@@ -197,9 +175,6 @@
|
||||
/* Define to 1 if you have the <semanage/semanage.h> header file. */
|
||||
#undef HAVE_SEMANAGE_SEMANAGE_H
|
||||
|
||||
/* Define to 1 if you have the `setgroups' function. */
|
||||
#undef HAVE_SETGROUPS
|
||||
|
||||
/* Define to 1 if you have the `sgetgrent' function. */
|
||||
#undef HAVE_SGETGRENT
|
||||
|
||||
@@ -209,12 +184,6 @@
|
||||
/* Define to 1 if you have the `sgetspent' function. */
|
||||
#undef HAVE_SGETSPENT
|
||||
|
||||
/* Define to 1 if you have the <sgtty.h> header file. */
|
||||
#undef HAVE_SGTTY_H
|
||||
|
||||
/* Have working shadow group support in libc */
|
||||
#undef HAVE_SHADOWGRP
|
||||
|
||||
/* Define if you have the shl_load function. */
|
||||
#undef HAVE_SHL_LOAD
|
||||
|
||||
@@ -260,15 +229,6 @@
|
||||
/* Define to 1 if `ut_xtime' is a member of `struct utmpx'. */
|
||||
#undef HAVE_STRUCT_UTMPX_UT_XTIME
|
||||
|
||||
/* Define to 1 if you have the <sys/capability.h> header file. */
|
||||
#undef HAVE_SYS_CAPABILITY_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ioctl.h> header file. */
|
||||
#undef HAVE_SYS_IOCTL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/random.h> header file. */
|
||||
#undef HAVE_SYS_RANDOM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/statfs.h> header file. */
|
||||
#undef HAVE_SYS_STATFS_H
|
||||
|
||||
@@ -281,9 +241,6 @@
|
||||
/* Define to 1 if you have the <tcb.h> header file. */
|
||||
#undef HAVE_TCB_H
|
||||
|
||||
/* Define to 1 if you have the <termio.h> header file. */
|
||||
#undef HAVE_TERMIO_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
@@ -296,9 +253,6 @@
|
||||
/* Define to 1 if `utime(file, NULL)' sets file's timestamp to the present. */
|
||||
#undef HAVE_UTIME_NULL
|
||||
|
||||
/* Define to 1 if you have the <utmp.h> header file. */
|
||||
#undef HAVE_UTMP_H
|
||||
|
||||
/* Define to support vendor settings. */
|
||||
#undef HAVE_VENDORDIR
|
||||
|
||||
@@ -517,9 +471,3 @@
|
||||
|
||||
/* Path for wtmp file. */
|
||||
#undef _WTMP_FILE
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef gid_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
#undef uid_t
|
||||
|
||||
637
configure
vendored
637
configure
vendored
@@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.71 for shadow 4.16.0.
|
||||
# Generated by GNU Autoconf 2.71 for shadow 4.17.3.
|
||||
#
|
||||
# Report bugs to <pkg-shadow-devel@lists.alioth.debian.org>.
|
||||
#
|
||||
@@ -621,8 +621,8 @@ MAKEFLAGS=
|
||||
# Identity of this package.
|
||||
PACKAGE_NAME='shadow'
|
||||
PACKAGE_TARNAME='shadow'
|
||||
PACKAGE_VERSION='4.16.0'
|
||||
PACKAGE_STRING='shadow 4.16.0'
|
||||
PACKAGE_VERSION='4.17.3'
|
||||
PACKAGE_STRING='shadow 4.17.3'
|
||||
PACKAGE_BUGREPORT='pkg-shadow-devel@lists.alioth.debian.org'
|
||||
PACKAGE_URL='https://github.com/shadow-maint/shadow'
|
||||
|
||||
@@ -671,6 +671,7 @@ INTLLIBS
|
||||
LTLIBICONV
|
||||
LIBICONV
|
||||
INTL_MACOSX_LIBS
|
||||
CPP
|
||||
XGETTEXT_EXTRA_OPTIONS
|
||||
MSGMERGE
|
||||
XGETTEXT_015
|
||||
@@ -744,7 +745,6 @@ USE_SHA_CRYPT_FALSE
|
||||
USE_SHA_CRYPT_TRUE
|
||||
GROUP_NAME_MAX_LENGTH
|
||||
LIBOBJS
|
||||
CPP
|
||||
LIBADD_DL
|
||||
LT_DLPREOPEN
|
||||
LIBADD_DLD_LINK
|
||||
@@ -932,14 +932,14 @@ CPPFLAGS
|
||||
YACC
|
||||
YFLAGS
|
||||
LT_SYS_LIBRARY_PATH
|
||||
CPP
|
||||
PKG_CONFIG
|
||||
PKG_CONFIG_PATH
|
||||
PKG_CONFIG_LIBDIR
|
||||
CMOCKA_CFLAGS
|
||||
CMOCKA_LIBS
|
||||
LIBBSD_CFLAGS
|
||||
LIBBSD_LIBS'
|
||||
LIBBSD_LIBS
|
||||
CPP'
|
||||
|
||||
|
||||
# Initialize some variables set by options.
|
||||
@@ -1488,7 +1488,7 @@ if test "$ac_init_help" = "long"; then
|
||||
# Omit some internal or obsolete options to make the list less imposing.
|
||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||
cat <<_ACEOF
|
||||
\`configure' configures shadow 4.16.0 to adapt to many kinds of systems.
|
||||
\`configure' configures shadow 4.17.3 to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@@ -1559,7 +1559,7 @@ fi
|
||||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of shadow 4.16.0:";;
|
||||
short | recursive ) echo "Configuration of shadow 4.17.3:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
@@ -1657,7 +1657,6 @@ Some influential environment variables:
|
||||
default value of `-d' given by some make applications.
|
||||
LT_SYS_LIBRARY_PATH
|
||||
User-defined run-time library search path.
|
||||
CPP C preprocessor
|
||||
PKG_CONFIG path to pkg-config utility
|
||||
PKG_CONFIG_PATH
|
||||
directories to add to pkg-config's search path
|
||||
@@ -1669,6 +1668,7 @@ Some influential environment variables:
|
||||
LIBBSD_CFLAGS
|
||||
C compiler flags for LIBBSD, overriding pkg-config
|
||||
LIBBSD_LIBS linker flags for LIBBSD, overriding pkg-config
|
||||
CPP C preprocessor
|
||||
|
||||
Use these variables to override the choices made by `configure' or to help
|
||||
it to find libraries and programs with nonstandard names/locations.
|
||||
@@ -1738,7 +1738,7 @@ fi
|
||||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
shadow configure 4.16.0
|
||||
shadow configure 4.17.3
|
||||
generated by GNU Autoconf 2.71
|
||||
|
||||
Copyright (C) 2021 Free Software Foundation, Inc.
|
||||
@@ -2045,44 +2045,6 @@ printf "%s\n" "$ac_res" >&6; }
|
||||
|
||||
} # ac_fn_c_check_member
|
||||
|
||||
# ac_fn_c_try_cpp LINENO
|
||||
# ----------------------
|
||||
# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
|
||||
ac_fn_c_try_cpp ()
|
||||
{
|
||||
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
|
||||
if { { ac_try="$ac_cpp conftest.$ac_ext"
|
||||
case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
|
||||
printf "%s\n" "$ac_try_echo"; } >&5
|
||||
(eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
|
||||
ac_status=$?
|
||||
if test -s conftest.err; then
|
||||
grep -v '^ *+' conftest.err >conftest.er1
|
||||
cat conftest.er1 >&5
|
||||
mv -f conftest.er1 conftest.err
|
||||
fi
|
||||
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; } > conftest.i && {
|
||||
test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
|
||||
test ! -s conftest.err
|
||||
}
|
||||
then :
|
||||
ac_retval=0
|
||||
else $as_nop
|
||||
printf "%s\n" "$as_me: failed program was:" >&5
|
||||
sed 's/^/| /' conftest.$ac_ext >&5
|
||||
|
||||
ac_retval=1
|
||||
fi
|
||||
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
|
||||
as_fn_set_status $ac_retval
|
||||
|
||||
} # ac_fn_c_try_cpp
|
||||
|
||||
# ac_fn_c_try_run LINENO
|
||||
# ----------------------
|
||||
# Try to run conftest.$ac_ext, and return whether this succeeded. Assumes that
|
||||
@@ -2314,6 +2276,44 @@ rm -f conftest.val
|
||||
as_fn_set_status $ac_retval
|
||||
|
||||
} # ac_fn_c_compute_int
|
||||
|
||||
# ac_fn_c_try_cpp LINENO
|
||||
# ----------------------
|
||||
# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
|
||||
ac_fn_c_try_cpp ()
|
||||
{
|
||||
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
|
||||
if { { ac_try="$ac_cpp conftest.$ac_ext"
|
||||
case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
|
||||
printf "%s\n" "$ac_try_echo"; } >&5
|
||||
(eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
|
||||
ac_status=$?
|
||||
if test -s conftest.err; then
|
||||
grep -v '^ *+' conftest.err >conftest.er1
|
||||
cat conftest.er1 >&5
|
||||
mv -f conftest.er1 conftest.err
|
||||
fi
|
||||
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; } > conftest.i && {
|
||||
test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
|
||||
test ! -s conftest.err
|
||||
}
|
||||
then :
|
||||
ac_retval=0
|
||||
else $as_nop
|
||||
printf "%s\n" "$as_me: failed program was:" >&5
|
||||
sed 's/^/| /' conftest.$ac_ext >&5
|
||||
|
||||
ac_retval=1
|
||||
fi
|
||||
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
|
||||
as_fn_set_status $ac_retval
|
||||
|
||||
} # ac_fn_c_try_cpp
|
||||
ac_configure_args_raw=
|
||||
for ac_arg
|
||||
do
|
||||
@@ -2338,7 +2338,7 @@ cat >config.log <<_ACEOF
|
||||
This file contains any messages produced by compilers while
|
||||
running configure, to aid debugging if configure makes a mistake.
|
||||
|
||||
It was created by shadow $as_me 4.16.0, which was
|
||||
It was created by shadow $as_me 4.17.3, which was
|
||||
generated by GNU Autoconf 2.71. Invocation command line was
|
||||
|
||||
$ $0$ac_configure_args_raw
|
||||
@@ -3611,7 +3611,7 @@ fi
|
||||
|
||||
# Define the identity of the package.
|
||||
PACKAGE='shadow'
|
||||
VERSION='4.16.0'
|
||||
VERSION='4.17.3'
|
||||
|
||||
|
||||
printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h
|
||||
@@ -14700,92 +14700,6 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
|
||||
|
||||
ac_fn_c_check_header_compile "$LINENO" "crypt.h" "ac_cv_header_crypt_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_crypt_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_CRYPT_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "utmp.h" "ac_cv_header_utmp_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_utmp_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_UTMP_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "termio.h" "ac_cv_header_termio_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_termio_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_TERMIO_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "sgtty.h" "ac_cv_header_sgtty_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_sgtty_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_SGTTY_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "sys/ioctl.h" "ac_cv_header_sys_ioctl_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_sys_ioctl_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_SYS_IOCTL_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "paths.h" "ac_cv_header_paths_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_paths_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_PATHS_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "sys/capability.h" "ac_cv_header_sys_capability_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_sys_capability_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_SYS_CAPABILITY_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "sys/random.h" "ac_cv_header_sys_random_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_sys_random_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_SYS_RANDOM_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "gshadow.h" "ac_cv_header_gshadow_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_gshadow_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_GSHADOW_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "lastlog.h" "ac_cv_header_lastlog_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_lastlog_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_LASTLOG_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "rpc/key_prot.h" "ac_cv_header_rpc_key_prot_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_rpc_key_prot_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_RPC_KEY_PROT_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "acl/libacl.h" "ac_cv_header_acl_libacl_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_acl_libacl_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_ACL_LIBACL_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "attr/libattr.h" "ac_cv_header_attr_libattr_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_attr_libattr_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_ATTR_LIBATTR_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_header_compile "$LINENO" "attr/error_context.h" "ac_cv_header_attr_error_context_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_attr_error_context_h" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_ATTR_ERROR_CONTEXT_H 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
|
||||
|
||||
ac_fn_c_check_header_compile "$LINENO" "shadow.h" "ac_cv_header_shadow_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_shadow_h" = xyes
|
||||
then :
|
||||
@@ -14830,12 +14744,6 @@ if test "x$ac_cv_func_getusershell" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_GETUSERSHELL 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_func "$LINENO" "initgroups" "ac_cv_func_initgroups"
|
||||
if test "x$ac_cv_func_initgroups" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_INITGROUPS 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_func "$LINENO" "lckpwdf" "ac_cv_func_lckpwdf"
|
||||
if test "x$ac_cv_func_lckpwdf" = xyes
|
||||
@@ -14848,12 +14756,6 @@ if test "x$ac_cv_func_lutimes" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_LUTIMES 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_func "$LINENO" "setgroups" "ac_cv_func_setgroups"
|
||||
if test "x$ac_cv_func_setgroups" = xyes
|
||||
then :
|
||||
printf "%s\n" "#define HAVE_SETGROUPS 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
ac_fn_c_check_func "$LINENO" "updwtmpx" "ac_cv_func_updwtmpx"
|
||||
if test "x$ac_cv_func_updwtmpx" = xyes
|
||||
@@ -15175,240 +15077,6 @@ printf "%s\n" "#define HAVE_STRUCT_UTMPX_UT_XTIME 1" >>confdefs.h
|
||||
fi
|
||||
|
||||
|
||||
ac_ext=c
|
||||
ac_cpp='$CPP $CPPFLAGS'
|
||||
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
||||
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
||||
ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
|
||||
printf %s "checking how to run the C preprocessor... " >&6; }
|
||||
# On Suns, sometimes $CPP names a directory.
|
||||
if test -n "$CPP" && test -d "$CPP"; then
|
||||
CPP=
|
||||
fi
|
||||
if test -z "$CPP"; then
|
||||
if test ${ac_cv_prog_CPP+y}
|
||||
then :
|
||||
printf %s "(cached) " >&6
|
||||
else $as_nop
|
||||
# Double quotes because $CC needs to be expanded
|
||||
for CPP in "$CC -E" "$CC -E -traditional-cpp" cpp /lib/cpp
|
||||
do
|
||||
ac_preproc_ok=false
|
||||
for ac_c_preproc_warn_flag in '' yes
|
||||
do
|
||||
# Use a header file that comes with gcc, so configuring glibc
|
||||
# with a fresh cross-compiler works.
|
||||
# On the NeXT, cc -E runs the code through the compiler's parser,
|
||||
# not just through cpp. "Syntax error" is here to catch this case.
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <limits.h>
|
||||
Syntax error
|
||||
_ACEOF
|
||||
if ac_fn_c_try_cpp "$LINENO"
|
||||
then :
|
||||
|
||||
else $as_nop
|
||||
# Broken: fails on valid input.
|
||||
continue
|
||||
fi
|
||||
rm -f conftest.err conftest.i conftest.$ac_ext
|
||||
|
||||
# OK, works on sane cases. Now check whether nonexistent headers
|
||||
# can be detected and how.
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <ac_nonexistent.h>
|
||||
_ACEOF
|
||||
if ac_fn_c_try_cpp "$LINENO"
|
||||
then :
|
||||
# Broken: success on invalid input.
|
||||
continue
|
||||
else $as_nop
|
||||
# Passes both tests.
|
||||
ac_preproc_ok=:
|
||||
break
|
||||
fi
|
||||
rm -f conftest.err conftest.i conftest.$ac_ext
|
||||
|
||||
done
|
||||
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
|
||||
rm -f conftest.i conftest.err conftest.$ac_ext
|
||||
if $ac_preproc_ok
|
||||
then :
|
||||
break
|
||||
fi
|
||||
|
||||
done
|
||||
ac_cv_prog_CPP=$CPP
|
||||
|
||||
fi
|
||||
CPP=$ac_cv_prog_CPP
|
||||
else
|
||||
ac_cv_prog_CPP=$CPP
|
||||
fi
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
|
||||
printf "%s\n" "$CPP" >&6; }
|
||||
ac_preproc_ok=false
|
||||
for ac_c_preproc_warn_flag in '' yes
|
||||
do
|
||||
# Use a header file that comes with gcc, so configuring glibc
|
||||
# with a fresh cross-compiler works.
|
||||
# On the NeXT, cc -E runs the code through the compiler's parser,
|
||||
# not just through cpp. "Syntax error" is here to catch this case.
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <limits.h>
|
||||
Syntax error
|
||||
_ACEOF
|
||||
if ac_fn_c_try_cpp "$LINENO"
|
||||
then :
|
||||
|
||||
else $as_nop
|
||||
# Broken: fails on valid input.
|
||||
continue
|
||||
fi
|
||||
rm -f conftest.err conftest.i conftest.$ac_ext
|
||||
|
||||
# OK, works on sane cases. Now check whether nonexistent headers
|
||||
# can be detected and how.
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <ac_nonexistent.h>
|
||||
_ACEOF
|
||||
if ac_fn_c_try_cpp "$LINENO"
|
||||
then :
|
||||
# Broken: success on invalid input.
|
||||
continue
|
||||
else $as_nop
|
||||
# Passes both tests.
|
||||
ac_preproc_ok=:
|
||||
break
|
||||
fi
|
||||
rm -f conftest.err conftest.i conftest.$ac_ext
|
||||
|
||||
done
|
||||
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
|
||||
rm -f conftest.i conftest.err conftest.$ac_ext
|
||||
if $ac_preproc_ok
|
||||
then :
|
||||
|
||||
else $as_nop
|
||||
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
|
||||
printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;}
|
||||
as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
|
||||
See \`config.log' for more details" "$LINENO" 5; }
|
||||
fi
|
||||
|
||||
ac_ext=c
|
||||
ac_cpp='$CPP $CPPFLAGS'
|
||||
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
||||
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
||||
ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for uid_t in sys/types.h" >&5
|
||||
printf %s "checking for uid_t in sys/types.h... " >&6; }
|
||||
if test ${ac_cv_type_uid_t+y}
|
||||
then :
|
||||
printf %s "(cached) " >&6
|
||||
else $as_nop
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <sys/types.h>
|
||||
|
||||
_ACEOF
|
||||
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
||||
$EGREP "uid_t" >/dev/null 2>&1
|
||||
then :
|
||||
ac_cv_type_uid_t=yes
|
||||
else $as_nop
|
||||
ac_cv_type_uid_t=no
|
||||
fi
|
||||
rm -rf conftest*
|
||||
|
||||
fi
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_uid_t" >&5
|
||||
printf "%s\n" "$ac_cv_type_uid_t" >&6; }
|
||||
if test $ac_cv_type_uid_t = no; then
|
||||
|
||||
printf "%s\n" "#define uid_t int" >>confdefs.h
|
||||
|
||||
|
||||
printf "%s\n" "#define gid_t int" >>confdefs.h
|
||||
|
||||
fi
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking type of array argument to getgroups" >&5
|
||||
printf %s "checking type of array argument to getgroups... " >&6; }
|
||||
if test ${ac_cv_type_getgroups+y}
|
||||
then :
|
||||
printf %s "(cached) " >&6
|
||||
else $as_nop
|
||||
if test "$cross_compiling" = yes
|
||||
then :
|
||||
ac_cv_type_getgroups=cross
|
||||
else $as_nop
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
/* Thanks to Mike Rendell for this test. */
|
||||
$ac_includes_default
|
||||
#define NGID 256
|
||||
#undef MAX
|
||||
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
gid_t gidset[NGID];
|
||||
int i, n;
|
||||
union { gid_t gval; long int lval; } val;
|
||||
|
||||
val.lval = -1;
|
||||
for (i = 0; i < NGID; i++)
|
||||
gidset[i] = val.gval;
|
||||
n = getgroups (sizeof (gidset) / MAX (sizeof (int), sizeof (gid_t)) - 1,
|
||||
gidset);
|
||||
/* Exit non-zero if getgroups seems to require an array of ints. This
|
||||
happens when gid_t is short int but getgroups modifies an array
|
||||
of ints. */
|
||||
return n > 0 && gidset[n] != val.gval;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_run "$LINENO"
|
||||
then :
|
||||
ac_cv_type_getgroups=gid_t
|
||||
else $as_nop
|
||||
ac_cv_type_getgroups=int
|
||||
fi
|
||||
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
|
||||
conftest.$ac_objext conftest.beam conftest.$ac_ext
|
||||
fi
|
||||
|
||||
if test $ac_cv_type_getgroups = cross; then
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <unistd.h>
|
||||
|
||||
_ACEOF
|
||||
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
||||
$EGREP "getgroups.*int.*gid_t" >/dev/null 2>&1
|
||||
then :
|
||||
ac_cv_type_getgroups=gid_t
|
||||
else $as_nop
|
||||
ac_cv_type_getgroups=int
|
||||
fi
|
||||
rm -rf conftest*
|
||||
|
||||
fi
|
||||
fi
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_getgroups" >&5
|
||||
printf "%s\n" "$ac_cv_type_getgroups" >&6; }
|
||||
|
||||
printf "%s\n" "#define GETGROUPS_T $ac_cv_type_getgroups" >>confdefs.h
|
||||
|
||||
|
||||
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether utime accepts a null argument" >&5
|
||||
@@ -15559,56 +15227,6 @@ printf "%s\n" "#define HAS_SECURE_GETENV 1" >>confdefs.h
|
||||
fi
|
||||
|
||||
|
||||
if test "$ac_cv_header_shadow_h" = "yes"; then
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for working shadow group support" >&5
|
||||
printf %s "checking for working shadow group support... " >&6; }
|
||||
if test ${ac_cv_libc_shadowgrp+y}
|
||||
then :
|
||||
printf %s "(cached) " >&6
|
||||
else $as_nop
|
||||
if test "$cross_compiling" = yes
|
||||
then :
|
||||
ac_cv_libc_shadowgrp=no
|
||||
|
||||
else $as_nop
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
#include <shadow.h>
|
||||
#ifdef HAVE_GSHADOW_H
|
||||
#include <gshadow.h>
|
||||
#endif
|
||||
int
|
||||
main()
|
||||
{
|
||||
struct sgrp *sg = sgetsgent("test:x::");
|
||||
/* NYS libc on Red Hat 3.0.3 has broken shadow group support */
|
||||
return !sg || !sg->sg_adm || !sg->sg_mem;
|
||||
}
|
||||
|
||||
_ACEOF
|
||||
if ac_fn_c_try_run "$LINENO"
|
||||
then :
|
||||
ac_cv_libc_shadowgrp=yes
|
||||
else $as_nop
|
||||
ac_cv_libc_shadowgrp=no
|
||||
fi
|
||||
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
|
||||
conftest.$ac_objext conftest.beam conftest.$ac_ext
|
||||
fi
|
||||
|
||||
|
||||
fi
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_libc_shadowgrp" >&5
|
||||
printf "%s\n" "$ac_cv_libc_shadowgrp" >&6; }
|
||||
|
||||
if test "$ac_cv_libc_shadowgrp" = "yes"; then
|
||||
|
||||
printf "%s\n" "#define HAVE_SHADOWGRP 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking location of shared mail directory" >&5
|
||||
printf %s "checking location of shared mail directory... " >&6; }
|
||||
if test ${shadow_cv_maildir+y}
|
||||
@@ -16215,8 +15833,8 @@ printf "%s\n" "no" >&6; }
|
||||
fi
|
||||
|
||||
pkg_failed=no
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for cmocka" >&5
|
||||
printf %s "checking for cmocka... " >&6; }
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for CMOCKA" >&5
|
||||
printf %s "checking for CMOCKA... " >&6; }
|
||||
|
||||
if test -n "$CMOCKA_CFLAGS"; then
|
||||
pkg_cv_CMOCKA_CFLAGS="$CMOCKA_CFLAGS"
|
||||
@@ -16256,7 +15874,7 @@ fi
|
||||
|
||||
|
||||
if test $pkg_failed = yes; then
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
printf "%s\n" "no" >&6; }
|
||||
|
||||
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
|
||||
@@ -16275,7 +15893,7 @@ fi
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: libcmocka not found, cmocka tests will not be built" >&5
|
||||
printf "%s\n" "$as_me: WARNING: libcmocka not found, cmocka tests will not be built" >&2;}
|
||||
elif test $pkg_failed = untried; then
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
printf "%s\n" "no" >&6; }
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: libcmocka not found, cmocka tests will not be built" >&5
|
||||
printf "%s\n" "$as_me: WARNING: libcmocka not found, cmocka tests will not be built" >&2;}
|
||||
@@ -16918,8 +16536,8 @@ then :
|
||||
|
||||
|
||||
pkg_failed=no
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libbsd-overlay" >&5
|
||||
printf %s "checking for libbsd-overlay... " >&6; }
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for LIBBSD" >&5
|
||||
printf %s "checking for LIBBSD... " >&6; }
|
||||
|
||||
if test -n "$LIBBSD_CFLAGS"; then
|
||||
pkg_cv_LIBBSD_CFLAGS="$LIBBSD_CFLAGS"
|
||||
@@ -16959,7 +16577,7 @@ fi
|
||||
|
||||
|
||||
if test $pkg_failed = yes; then
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
printf "%s\n" "no" >&6; }
|
||||
|
||||
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
|
||||
@@ -16986,7 +16604,7 @@ Alternatively, you may set the environment variables LIBBSD_CFLAGS
|
||||
and LIBBSD_LIBS to avoid the need to call pkg-config.
|
||||
See the pkg-config man page for more details." "$LINENO" 5
|
||||
elif test $pkg_failed = untried; then
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
printf "%s\n" "no" >&6; }
|
||||
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
|
||||
printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;}
|
||||
@@ -18086,7 +17704,7 @@ if test "x$ac_cv_lib_skey_skeychallenge" = xyes
|
||||
then :
|
||||
LIBSKEY=-lskey
|
||||
else $as_nop
|
||||
as_fn_error $? "liskey missing. You can download S/Key source code from http://rsync1.it.gentoo.org/gentoo/distfiles/skey-1.1.5.tar.bz2" "$LINENO" 5
|
||||
as_fn_error $? "libskey missing. You can download S/Key source code from http://rsync1.it.gentoo.org/gentoo/distfiles/skey-1.1.5.tar.bz2" "$LINENO" 5
|
||||
fi
|
||||
|
||||
|
||||
@@ -18612,6 +18230,139 @@ else $as_nop
|
||||
fi
|
||||
|
||||
|
||||
ac_ext=c
|
||||
ac_cpp='$CPP $CPPFLAGS'
|
||||
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
||||
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
||||
ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
|
||||
printf %s "checking how to run the C preprocessor... " >&6; }
|
||||
# On Suns, sometimes $CPP names a directory.
|
||||
if test -n "$CPP" && test -d "$CPP"; then
|
||||
CPP=
|
||||
fi
|
||||
if test -z "$CPP"; then
|
||||
if test ${ac_cv_prog_CPP+y}
|
||||
then :
|
||||
printf %s "(cached) " >&6
|
||||
else $as_nop
|
||||
# Double quotes because $CC needs to be expanded
|
||||
for CPP in "$CC -E" "$CC -E -traditional-cpp" cpp /lib/cpp
|
||||
do
|
||||
ac_preproc_ok=false
|
||||
for ac_c_preproc_warn_flag in '' yes
|
||||
do
|
||||
# Use a header file that comes with gcc, so configuring glibc
|
||||
# with a fresh cross-compiler works.
|
||||
# On the NeXT, cc -E runs the code through the compiler's parser,
|
||||
# not just through cpp. "Syntax error" is here to catch this case.
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <limits.h>
|
||||
Syntax error
|
||||
_ACEOF
|
||||
if ac_fn_c_try_cpp "$LINENO"
|
||||
then :
|
||||
|
||||
else $as_nop
|
||||
# Broken: fails on valid input.
|
||||
continue
|
||||
fi
|
||||
rm -f conftest.err conftest.i conftest.$ac_ext
|
||||
|
||||
# OK, works on sane cases. Now check whether nonexistent headers
|
||||
# can be detected and how.
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <ac_nonexistent.h>
|
||||
_ACEOF
|
||||
if ac_fn_c_try_cpp "$LINENO"
|
||||
then :
|
||||
# Broken: success on invalid input.
|
||||
continue
|
||||
else $as_nop
|
||||
# Passes both tests.
|
||||
ac_preproc_ok=:
|
||||
break
|
||||
fi
|
||||
rm -f conftest.err conftest.i conftest.$ac_ext
|
||||
|
||||
done
|
||||
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
|
||||
rm -f conftest.i conftest.err conftest.$ac_ext
|
||||
if $ac_preproc_ok
|
||||
then :
|
||||
break
|
||||
fi
|
||||
|
||||
done
|
||||
ac_cv_prog_CPP=$CPP
|
||||
|
||||
fi
|
||||
CPP=$ac_cv_prog_CPP
|
||||
else
|
||||
ac_cv_prog_CPP=$CPP
|
||||
fi
|
||||
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
|
||||
printf "%s\n" "$CPP" >&6; }
|
||||
ac_preproc_ok=false
|
||||
for ac_c_preproc_warn_flag in '' yes
|
||||
do
|
||||
# Use a header file that comes with gcc, so configuring glibc
|
||||
# with a fresh cross-compiler works.
|
||||
# On the NeXT, cc -E runs the code through the compiler's parser,
|
||||
# not just through cpp. "Syntax error" is here to catch this case.
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <limits.h>
|
||||
Syntax error
|
||||
_ACEOF
|
||||
if ac_fn_c_try_cpp "$LINENO"
|
||||
then :
|
||||
|
||||
else $as_nop
|
||||
# Broken: fails on valid input.
|
||||
continue
|
||||
fi
|
||||
rm -f conftest.err conftest.i conftest.$ac_ext
|
||||
|
||||
# OK, works on sane cases. Now check whether nonexistent headers
|
||||
# can be detected and how.
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <ac_nonexistent.h>
|
||||
_ACEOF
|
||||
if ac_fn_c_try_cpp "$LINENO"
|
||||
then :
|
||||
# Broken: success on invalid input.
|
||||
continue
|
||||
else $as_nop
|
||||
# Passes both tests.
|
||||
ac_preproc_ok=:
|
||||
break
|
||||
fi
|
||||
rm -f conftest.err conftest.i conftest.$ac_ext
|
||||
|
||||
done
|
||||
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
|
||||
rm -f conftest.i conftest.err conftest.$ac_ext
|
||||
if $ac_preproc_ok
|
||||
then :
|
||||
|
||||
else $as_nop
|
||||
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
|
||||
printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;}
|
||||
as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
|
||||
See \`config.log' for more details" "$LINENO" 5; }
|
||||
fi
|
||||
|
||||
ac_ext=c
|
||||
ac_cpp='$CPP $CPPFLAGS'
|
||||
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
||||
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
||||
ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
|
||||
|
||||
|
||||
acl_libdirstem=lib
|
||||
@@ -20846,7 +20597,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
||||
# report actual input values of CONFIG_FILES etc. instead of their
|
||||
# values after options handling.
|
||||
ac_log="
|
||||
This file was extended by shadow $as_me 4.16.0, which was
|
||||
This file was extended by shadow $as_me 4.17.3, which was
|
||||
generated by GNU Autoconf 2.71. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
@@ -20915,7 +20666,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
|
||||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||
ac_cs_config='$ac_cs_config_escaped'
|
||||
ac_cs_version="\\
|
||||
shadow config.status 4.16.0
|
||||
shadow config.status 4.17.3
|
||||
configured by $0, generated by GNU Autoconf 2.71,
|
||||
with options \\"\$ac_cs_config\\"
|
||||
|
||||
|
||||
43
configure.ac
43
configure.ac
@@ -4,7 +4,7 @@ m4_define([libsubid_abi_major], 5)
|
||||
m4_define([libsubid_abi_minor], 0)
|
||||
m4_define([libsubid_abi_micro], 0)
|
||||
m4_define([libsubid_abi], [libsubid_abi_major.libsubid_abi_minor.libsubid_abi_micro])
|
||||
AC_INIT([shadow], [4.16.0], [pkg-shadow-devel@lists.alioth.debian.org], [],
|
||||
AC_INIT([shadow], [4.17.3], [pkg-shadow-devel@lists.alioth.debian.org], [],
|
||||
[https://github.com/shadow-maint/shadow])
|
||||
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects tar-pax])
|
||||
AC_CONFIG_MACRO_DIRS([m4])
|
||||
@@ -36,20 +36,13 @@ LT_LIB_DLLOAD
|
||||
|
||||
dnl Checks for libraries.
|
||||
|
||||
dnl Checks for header files.
|
||||
AC_CHECK_HEADERS(crypt.h utmp.h \
|
||||
termio.h sgtty.h sys/ioctl.h paths.h \
|
||||
sys/capability.h sys/random.h \
|
||||
gshadow.h lastlog.h rpc/key_prot.h acl/libacl.h \
|
||||
attr/libattr.h attr/error_context.h)
|
||||
|
||||
dnl shadow now uses the libc's shadow implementation
|
||||
AC_CHECK_HEADER([shadow.h],,[AC_MSG_ERROR([You need a libc with shadow.h])])
|
||||
|
||||
AC_CHECK_FUNCS(arc4random_buf futimes \
|
||||
getentropy getrandom getspnam getusershell \
|
||||
initgroups lckpwdf lutimes \
|
||||
setgroups updwtmpx innetgr \
|
||||
lckpwdf lutimes \
|
||||
updwtmpx innetgr \
|
||||
getspnam_r \
|
||||
rpmatch \
|
||||
memset_explicit explicit_bzero stpecpy stpeprintf)
|
||||
@@ -66,7 +59,6 @@ AC_CHECK_MEMBERS([struct utmpx.ut_name,
|
||||
struct utmpx.ut_xtime],,,[[#include <utmpx.h>]])
|
||||
|
||||
dnl Checks for library functions.
|
||||
AC_TYPE_GETGROUPS
|
||||
AC_FUNC_UTIME_NULL
|
||||
AC_REPLACE_FUNCS(putgrent putpwent putspent)
|
||||
AC_REPLACE_FUNCS(sgetgrent sgetpwent sgetspent)
|
||||
@@ -76,33 +68,6 @@ AC_CHECK_FUNC(secure_getenv, [AC_DEFINE(HAS_SECURE_GETENV,
|
||||
1,
|
||||
[Defined to 1 if you have the declaration of 'secure_getenv'])])
|
||||
|
||||
if test "$ac_cv_header_shadow_h" = "yes"; then
|
||||
AC_CACHE_CHECK(for working shadow group support,
|
||||
ac_cv_libc_shadowgrp,
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE([
|
||||
#include <shadow.h>
|
||||
#ifdef HAVE_GSHADOW_H
|
||||
#include <gshadow.h>
|
||||
#endif
|
||||
int
|
||||
main()
|
||||
{
|
||||
struct sgrp *sg = sgetsgent("test:x::");
|
||||
/* NYS libc on Red Hat 3.0.3 has broken shadow group support */
|
||||
return !sg || !sg->sg_adm || !sg->sg_mem;
|
||||
}]
|
||||
)],
|
||||
[ac_cv_libc_shadowgrp=yes],
|
||||
[ac_cv_libc_shadowgrp=no],
|
||||
[ac_cv_libc_shadowgrp=no]
|
||||
)
|
||||
)
|
||||
|
||||
if test "$ac_cv_libc_shadowgrp" = "yes"; then
|
||||
AC_DEFINE(HAVE_SHADOWGRP, 1, [Have working shadow group support in libc])
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([location of shared mail directory], shadow_cv_maildir,
|
||||
[for shadow_cv_maildir in /var/mail /var/spool/mail /usr/spool/mail /usr/mail none; do
|
||||
if test -d $shadow_cv_maildir; then
|
||||
@@ -689,7 +654,7 @@ AC_SUBST(LIBMD)
|
||||
if test "$with_skey" = "yes"; then
|
||||
AC_CHECK_LIB(md, MD5Init, [LIBMD=-lmd])
|
||||
AC_CHECK_LIB(skey, skeychallenge, [LIBSKEY=-lskey],
|
||||
[AC_MSG_ERROR([liskey missing. You can download S/Key source code from http://rsync1.it.gentoo.org/gentoo/distfiles/skey-1.1.5.tar.bz2])])
|
||||
[AC_MSG_ERROR([libskey missing. You can download S/Key source code from http://rsync1.it.gentoo.org/gentoo/distfiles/skey-1.1.5.tar.bz2])])
|
||||
AC_DEFINE(SKEY, 1, [Define to support S/Key logins.])
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -118,6 +118,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
#define IMMEDIATE_CHANGE /* Expire newly created password, must be changed
|
||||
* immediately upon next login */
|
||||
#define HAVE_QUOTAS /* Obvious */
|
||||
@@ -291,12 +294,10 @@ main (void)
|
||||
printf ("Home Directory [%s/%s]: ", DEFAULT_HOME, usrname);
|
||||
fflush (stdout);
|
||||
safeget (dir, sizeof (dir));
|
||||
if (!strlen (dir))
|
||||
{ /* hit return */
|
||||
sprintf (dir, "%s/%s", DEFAULT_HOME, usrname);
|
||||
}
|
||||
if (!strlen(dir)) /* hit return */
|
||||
sprintf(dir, "%s/%s", DEFAULT_HOME, usrname);
|
||||
else if (dir[strlen (dir) - 1] == '/')
|
||||
sprintf (dir+strlen(dir), "%s", usrname);
|
||||
strcat(dir, usrname);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -308,7 +309,7 @@ main (void)
|
||||
fflush (stdout);
|
||||
safeget (shell, sizeof (shell));
|
||||
if (!strlen (shell))
|
||||
sprintf (shell, "%s", DEFAULT_SHELL);
|
||||
strcpy(shell, DEFAULT_SHELL);
|
||||
else
|
||||
{
|
||||
char *sh;
|
||||
@@ -316,7 +317,7 @@ main (void)
|
||||
#ifdef HAVE_GETUSERSHELL
|
||||
setusershell ();
|
||||
while ((sh = getusershell ()) != NULL)
|
||||
if (!strcmp (shell, sh))
|
||||
if (streq(shell, sh))
|
||||
ok = 1;
|
||||
endusershell ();
|
||||
#endif
|
||||
@@ -327,7 +328,7 @@ main (void)
|
||||
else
|
||||
{
|
||||
printf ("Shell NOT in /etc/shells, DEFAULT used\n");
|
||||
sprintf (shell, "%s", DEFAULT_SHELL);
|
||||
strcpy(shell, DEFAULT_SHELL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -491,12 +492,12 @@ safeget (char *buf, int maxlen)
|
||||
bad = (!isalnum (c) && (c != '_') && (c != ' '));
|
||||
*(buf++) = c;
|
||||
}
|
||||
*buf = '\0';
|
||||
stpcpy(buf, "");
|
||||
|
||||
if (bad)
|
||||
{
|
||||
printf ("\nString contained banned character. Please stick to alphanumerics.\n");
|
||||
*bstart = '\0';
|
||||
stpcpy(bstart, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
12
doc/HOWTO
12
doc/HOWTO
@@ -471,12 +471,12 @@
|
||||
|
||||
The Shadow Suite contains replacement programs for:
|
||||
|
||||
su, login, passwd, newgrp, chfn, chsh, and id
|
||||
su, login, passwd, newgrp, chfn, chsh
|
||||
|
||||
The package also contains the new programs:
|
||||
|
||||
chage, newusers, dpasswd, gpasswd, useradd, userdel, usermod,
|
||||
groupadd, groupdel, groupmod, groups, pwck, grpck, lastlog, pwconv,
|
||||
groupadd, groupdel, groupmod, pwck, grpck, lastlog, pwconv,
|
||||
and pwunconv
|
||||
|
||||
Additionally, the library: libshadow.a is included for writing and/or
|
||||
@@ -586,8 +586,6 @@
|
||||
|
||||
· /usr/bin/chsh
|
||||
|
||||
· /usr/bin/id
|
||||
|
||||
The BETA package has a save target in the Makefile, but it's commented
|
||||
out because different distributions place the programs in different
|
||||
places.
|
||||
@@ -637,8 +635,6 @@
|
||||
|
||||
· /usr/man/man1/chsh.1.gz
|
||||
|
||||
· /usr/man/man1/id.1.gz
|
||||
|
||||
· /usr/man/man1/login.1.gz
|
||||
|
||||
· /usr/man/man1/passwd.1.gz
|
||||
@@ -1377,7 +1373,7 @@
|
||||
users or changing the group password, the /etc/gshadow file will be
|
||||
changed.
|
||||
|
||||
The programs groups, groupadd, groupmod, and groupdel are provided as
|
||||
The programs groupadd, groupmod, and groupdel are provided as
|
||||
part of the Shadow Suite to modify groups.
|
||||
|
||||
The format of the /etc/group file is as follows:
|
||||
@@ -1755,7 +1751,7 @@
|
||||
}
|
||||
#ifdef HAS_SHADOW
|
||||
if ((pw->pw_passwd && pw->pw_passwd[0] == '@'
|
||||
&& pw_auth (pw->pw_passwd+1, pw->pw_name, PW_LOGIN, NULL))
|
||||
&& pw_auth(pw->pw_passwd+1, pw->pw_name))
|
||||
|| !valid (passwd, pw)) {
|
||||
return (UPAP_AUTHNAK);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ pamd_files = \
|
||||
passwd
|
||||
|
||||
pamd_acct_tools_files = \
|
||||
chage \
|
||||
chgpasswd \
|
||||
groupadd \
|
||||
groupdel \
|
||||
|
||||
@@ -342,7 +342,6 @@ top_srcdir = @top_srcdir@
|
||||
pamd_files = chpasswd chfn chsh groupmems login newusers passwd \
|
||||
$(am__append_2)
|
||||
pamd_acct_tools_files = \
|
||||
chage \
|
||||
chgpasswd \
|
||||
groupadd \
|
||||
groupdel \
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
#%PAM-1.0
|
||||
auth sufficient pam_rootok.so
|
||||
account required pam_permit.so
|
||||
password include system-auth
|
||||
127
lib/Makefile.am
127
lib/Makefile.am
@@ -29,16 +29,48 @@ libshadow_la_SOURCES = \
|
||||
age.c \
|
||||
agetpass.c \
|
||||
agetpass.h \
|
||||
alloc.c \
|
||||
alloc.h \
|
||||
atoi/a2i.c \
|
||||
atoi/a2i.h \
|
||||
atoi/str2i.c \
|
||||
atoi/str2i.h \
|
||||
atoi/strtoi.c \
|
||||
atoi/strtoi.h \
|
||||
atoi/strtou_noneg.c \
|
||||
atoi/strtou_noneg.h \
|
||||
alloc/calloc.c \
|
||||
alloc/calloc.h \
|
||||
alloc/malloc.c \
|
||||
alloc/malloc.h \
|
||||
alloc/realloc.c \
|
||||
alloc/realloc.h \
|
||||
alloc/reallocf.c \
|
||||
alloc/reallocf.h \
|
||||
alloc/x/xcalloc.c \
|
||||
alloc/x/xcalloc.h \
|
||||
alloc/x/xmalloc.c \
|
||||
alloc/x/xmalloc.h \
|
||||
alloc/x/xrealloc.c \
|
||||
alloc/x/xrealloc.h \
|
||||
atoi/a2i/a2i.c \
|
||||
atoi/a2i/a2i.h \
|
||||
atoi/a2i/a2s.c \
|
||||
atoi/a2i/a2s.h \
|
||||
atoi/a2i/a2s_c.c \
|
||||
atoi/a2i/a2s_c.h \
|
||||
atoi/a2i/a2s_nc.c \
|
||||
atoi/a2i/a2s_nc.h \
|
||||
atoi/a2i/a2u.c \
|
||||
atoi/a2i/a2u.h \
|
||||
atoi/a2i/a2u_c.c \
|
||||
atoi/a2i/a2u_c.h \
|
||||
atoi/a2i/a2u_nc.c \
|
||||
atoi/a2i/a2u_nc.h \
|
||||
atoi/getnum.c \
|
||||
atoi/getnum.h \
|
||||
atoi/str2i/str2i.c \
|
||||
atoi/str2i/str2i.h \
|
||||
atoi/str2i/str2s.c \
|
||||
atoi/str2i/str2s.h \
|
||||
atoi/str2i/str2u.c \
|
||||
atoi/str2i/str2u.h \
|
||||
atoi/strtoi/strtoi.c \
|
||||
atoi/strtoi/strtoi.h \
|
||||
atoi/strtoi/strtou.c \
|
||||
atoi/strtoi/strtou.h \
|
||||
atoi/strtoi/strtou_noneg.c \
|
||||
atoi/strtoi/strtou_noneg.h \
|
||||
attr.h \
|
||||
audit_help.c \
|
||||
basename.c \
|
||||
@@ -71,9 +103,11 @@ libshadow_la_SOURCES = \
|
||||
find_new_sub_gids.c \
|
||||
find_new_sub_uids.c \
|
||||
fputsx.c \
|
||||
get_gid.c \
|
||||
fs/readlink/areadlink.c \
|
||||
fs/readlink/areadlink.h \
|
||||
fs/readlink/readlinknul.c \
|
||||
fs/readlink/readlinknul.h \
|
||||
get_pid.c \
|
||||
get_uid.c \
|
||||
getdate.h \
|
||||
getdate.y \
|
||||
getdef.c \
|
||||
@@ -94,8 +128,6 @@ libshadow_la_SOURCES = \
|
||||
lockpw.c \
|
||||
loginprompt.c \
|
||||
mail.c \
|
||||
memzero.c \
|
||||
memzero.h \
|
||||
motd.c \
|
||||
must_be.h \
|
||||
myname.c \
|
||||
@@ -123,6 +155,14 @@ libshadow_la_SOURCES = \
|
||||
run_part.h \
|
||||
run_part.c \
|
||||
salt.c \
|
||||
search/cmp/cmp.c \
|
||||
search/cmp/cmp.h \
|
||||
search/l/lfind.c \
|
||||
search/l/lfind.h \
|
||||
search/l/lsearch.c \
|
||||
search/l/lsearch.h \
|
||||
search/sort/qsort.c \
|
||||
search/sort/qsort.h \
|
||||
selinux.c \
|
||||
semanage.c \
|
||||
setugid.c \
|
||||
@@ -133,6 +173,8 @@ libshadow_la_SOURCES = \
|
||||
sgroupio.c \
|
||||
sgroupio.h\
|
||||
shadow.c \
|
||||
shadow/grp/agetgroups.c \
|
||||
shadow/grp/agetgroups.h \
|
||||
shadowio.c \
|
||||
shadowio.h \
|
||||
shadowlog.c \
|
||||
@@ -144,18 +186,54 @@ libshadow_la_SOURCES = \
|
||||
spawn.c \
|
||||
sssd.c \
|
||||
sssd.h \
|
||||
string/sprintf.c \
|
||||
string/sprintf.h \
|
||||
string/stpecpy.c \
|
||||
string/stpecpy.h \
|
||||
string/stpeprintf.c \
|
||||
string/stpeprintf.h \
|
||||
string/ctype/strisascii/strisdigit.c \
|
||||
string/ctype/strisascii/strisdigit.h \
|
||||
string/memset/memzero.c \
|
||||
string/memset/memzero.h \
|
||||
string/sprintf/snprintf.c \
|
||||
string/sprintf/snprintf.h \
|
||||
string/sprintf/stpeprintf.c \
|
||||
string/sprintf/stpeprintf.h \
|
||||
string/sprintf/xasprintf.c \
|
||||
string/sprintf/xasprintf.h \
|
||||
string/strchr/strchrcnt.c \
|
||||
string/strchr/strchrcnt.h \
|
||||
string/strchr/strchrscnt.c \
|
||||
string/strchr/strchrscnt.h \
|
||||
string/strchr/strnul.c \
|
||||
string/strchr/strnul.h \
|
||||
string/strcmp/strcaseeq.c \
|
||||
string/strcmp/strcaseeq.h \
|
||||
string/strcmp/streq.c \
|
||||
string/strcmp/streq.h \
|
||||
string/strcpy/stpecpy.c \
|
||||
string/strcpy/stpecpy.h \
|
||||
string/strcpy/strncat.c \
|
||||
string/strcpy/strncat.h \
|
||||
string/strcpy/strncpy.c \
|
||||
string/strcpy/strncpy.h \
|
||||
string/strcpy/strtcpy.c \
|
||||
string/strcpy/strtcpy.h \
|
||||
string/strdup/strndupa.c \
|
||||
string/strdup/strndupa.h \
|
||||
string/strdup/xstrdup.c \
|
||||
string/strdup/xstrdup.h \
|
||||
string/strdup/xstrndup.c \
|
||||
string/strdup/xstrndup.h \
|
||||
string/strftime.c \
|
||||
string/strftime.h \
|
||||
string/strncpy.h \
|
||||
string/strtcpy.c \
|
||||
string/strtcpy.h \
|
||||
string/zustr2stp.h \
|
||||
string/strspn/stpspn.c \
|
||||
string/strspn/stpspn.h \
|
||||
string/strspn/stprcspn.c \
|
||||
string/strspn/stprcspn.h \
|
||||
string/strspn/stprspn.c \
|
||||
string/strspn/stprspn.h \
|
||||
string/strspn/strrcspn.c \
|
||||
string/strspn/strrcspn.h \
|
||||
string/strspn/strrspn.c \
|
||||
string/strspn/strrspn.h \
|
||||
string/strtok/stpsep.c \
|
||||
string/strtok/stpsep.h \
|
||||
strtoday.c \
|
||||
sub.c \
|
||||
subordinateio.h \
|
||||
@@ -164,6 +242,7 @@ libshadow_la_SOURCES = \
|
||||
time/day_to_str.c \
|
||||
time/day_to_str.h \
|
||||
ttytype.c \
|
||||
typetraits.h \
|
||||
tz.c \
|
||||
ulimit.c \
|
||||
user_busy.c \
|
||||
|
||||
1280
lib/Makefile.in
1280
lib/Makefile.in
File diff suppressed because it is too large
Load Diff
129
lib/addgrps.c
129
lib/addgrps.c
@@ -1,114 +1,81 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 1989 - 1994, Julianne Frances Haugh
|
||||
* SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz
|
||||
* SPDX-FileCopyrightText: 2001 - 2006, Tomasz Kłoczko
|
||||
* SPDX-FileCopyrightText: 2007 - 2009, Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 1989-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2001-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_SETGROUPS) && ! defined (USE_PAM)
|
||||
#if !defined(USE_PAM)
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
#include <errno.h>
|
||||
#include <grp.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "alloc/reallocf.h"
|
||||
#include "search/l/lsearch.h"
|
||||
#include "shadow/grp/agetgroups.h"
|
||||
#include "shadowlog.h"
|
||||
#include "string/strchr/strchrscnt.h"
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#define SEP ",:"
|
||||
/*
|
||||
* Add groups with names from LIST (separated by commas or colons)
|
||||
* to the supplementary group set. Silently ignore groups which are
|
||||
* already there. Warning: uses strtok().
|
||||
* already there.
|
||||
*/
|
||||
int add_groups (const char *list)
|
||||
int
|
||||
add_groups(const char *list)
|
||||
{
|
||||
GETGROUPS_T *grouplist;
|
||||
size_t i;
|
||||
int ngroups;
|
||||
bool added;
|
||||
char *token;
|
||||
char buf[1024];
|
||||
int ret;
|
||||
char *g, *p, *dup;
|
||||
FILE *shadow_logfd = log_get_logfd();
|
||||
gid_t *gids;
|
||||
size_t n;
|
||||
|
||||
if (strlen (list) >= sizeof (buf)) {
|
||||
errno = EINVAL;
|
||||
gids = agetgroups(&n);
|
||||
if (gids == NULL)
|
||||
return -1;
|
||||
}
|
||||
strcpy (buf, list);
|
||||
|
||||
i = 16;
|
||||
for (;;) {
|
||||
grouplist = MALLOC(i, GETGROUPS_T);
|
||||
if (NULL == grouplist) {
|
||||
return -1;
|
||||
}
|
||||
ngroups = getgroups (i, grouplist);
|
||||
if ( ( (-1 == ngroups)
|
||||
&& (EINVAL != errno))
|
||||
|| (i > (size_t)ngroups)) {
|
||||
/* Unexpected failure of getgroups or successful
|
||||
* reception of the groups */
|
||||
break;
|
||||
}
|
||||
/* not enough room, so try allocating a larger buffer */
|
||||
free (grouplist);
|
||||
i *= 2;
|
||||
}
|
||||
if (ngroups < 0) {
|
||||
free (grouplist);
|
||||
gids = REALLOCF(gids, n + strchrscnt(list, ",:") + 1, gid_t);
|
||||
if (gids == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
added = false;
|
||||
for (token = strtok (buf, SEP); NULL != token; token = strtok (NULL, SEP)) {
|
||||
struct group *grp;
|
||||
p = dup = strdup(list);
|
||||
if (dup == NULL)
|
||||
goto free_gids;
|
||||
|
||||
grp = getgrnam (token); /* local, no need for xgetgrnam */
|
||||
while (NULL != (g = strsep(&p, ",:"))) {
|
||||
struct group *grp;
|
||||
|
||||
grp = getgrnam(g); /* local, no need for xgetgrnam */
|
||||
if (NULL == grp) {
|
||||
fprintf (shadow_logfd, _("Warning: unknown group %s\n"),
|
||||
token);
|
||||
fprintf(shadow_logfd, _("Warning: unknown group %s\n"), g);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i = 0; i < (size_t)ngroups && grouplist[i] != grp->gr_gid; i++);
|
||||
LSEARCH(&grp->gr_gid, gids, &n);
|
||||
}
|
||||
free(dup);
|
||||
|
||||
if (i < (size_t)ngroups) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngroups >= sysconf (_SC_NGROUPS_MAX)) {
|
||||
fputs (_("Warning: too many groups\n"), shadow_logfd);
|
||||
break;
|
||||
}
|
||||
grouplist = REALLOCF(grouplist, (size_t) ngroups + 1, GETGROUPS_T);
|
||||
if (grouplist == NULL) {
|
||||
return -1;
|
||||
}
|
||||
grouplist[ngroups] = grp->gr_gid;
|
||||
ngroups++;
|
||||
added = true;
|
||||
if (setgroups(n, gids) == -1) {
|
||||
fprintf(shadow_logfd, "setgroups: %s\n", strerror(errno));
|
||||
goto free_gids;
|
||||
}
|
||||
|
||||
if (added) {
|
||||
ret = setgroups (ngroups, grouplist);
|
||||
free (grouplist);
|
||||
return ret;
|
||||
}
|
||||
|
||||
free (grouplist);
|
||||
free(gids);
|
||||
return 0;
|
||||
}
|
||||
#else /* HAVE_SETGROUPS && !USE_PAM */
|
||||
extern int ISO_C_forbids_an_empty_translation_unit;
|
||||
#endif /* HAVE_SETGROUPS && !USE_PAM */
|
||||
|
||||
free_gids:
|
||||
free(gids);
|
||||
return -1;
|
||||
}
|
||||
#else /* !USE_PAM */
|
||||
extern int ISO_C_forbids_an_empty_translation_unit;
|
||||
#endif /* !USE_PAM */
|
||||
|
||||
@@ -11,5 +11,3 @@
|
||||
|
||||
extern inline long addsl2(long a, long b);
|
||||
extern inline long addslN(size_t n, long addend[n]);
|
||||
|
||||
extern inline int cmpl(const void *p1, const void *p2);
|
||||
|
||||
22
lib/adds.h
22
lib/adds.h
@@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "search/sort/qsort.h"
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
inline long addsl2(long a, long b);
|
||||
inline long addslN(size_t n, long addend[n]);
|
||||
|
||||
inline int cmpl(const void *p1, const void *p2);
|
||||
|
||||
|
||||
inline long
|
||||
addsl2(long a, long b)
|
||||
@@ -57,7 +55,7 @@ addslN(size_t n, long addend[n])
|
||||
|
||||
e = errno;
|
||||
while (n > 1) {
|
||||
qsort(addend, n, sizeof(addend[0]), cmpl);
|
||||
QSORT(addend, n);
|
||||
|
||||
errno = 0;
|
||||
addend[0] = addsl2(addend[0], addend[--n]);
|
||||
@@ -69,18 +67,4 @@ addslN(size_t n, long addend[n])
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
cmpl(const void *p1, const void *p2)
|
||||
{
|
||||
const long *l1 = p1;
|
||||
const long *l2 = p2;
|
||||
|
||||
if (*l1 < *l2)
|
||||
return -1;
|
||||
if (*l1 > *l2)
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
|
||||
@@ -106,7 +106,7 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp)
|
||||
* passwd to work just like it would had they executed
|
||||
* it from the command line while logged in.
|
||||
*/
|
||||
#if defined(HAVE_INITGROUPS) && ! defined(USE_PAM)
|
||||
#if !defined(USE_PAM)
|
||||
if (setup_uid_gid (pw, false) != 0)
|
||||
#else
|
||||
if (setup_uid_gid (pw) != 0)
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "alloc.h"
|
||||
#include "alloc/malloc.h"
|
||||
|
||||
#if WITH_LIBBSD == 0
|
||||
#include "freezero.h"
|
||||
|
||||
73
lib/alloc.c
73
lib/alloc.c
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh
|
||||
* SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz
|
||||
* SPDX-FileCopyrightText: 2003 - 2006, Tomasz Kłoczko
|
||||
* SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
* SPDX-FileCopyrightText: 2023 , Alejandro Colomar <alx@kernel.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/* Replacements for malloc and strdup with error checking. Too trivial
|
||||
to be worth copyrighting :-). I did that because a lot of code used
|
||||
malloc and strdup without checking for NULL pointer, and I like some
|
||||
message better than a core dump... --marekm
|
||||
|
||||
Yeh, but. Remember that bailing out might leave the system in some
|
||||
bizarre state. You really want to put in error checking, then add
|
||||
some back-out failure recovery code. -- jfh */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "alloc.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "shadowlog.h"
|
||||
|
||||
|
||||
extern inline void *xmalloc(size_t size);
|
||||
extern inline void *xmallocarray(size_t nmemb, size_t size);
|
||||
extern inline void *mallocarray(size_t nmemb, size_t size);
|
||||
extern inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
|
||||
extern inline char *xstrdup(const char *str);
|
||||
|
||||
|
||||
void *
|
||||
xcalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = calloc(nmemb, size);
|
||||
if (p == NULL)
|
||||
goto x;
|
||||
|
||||
return p;
|
||||
|
||||
x:
|
||||
fprintf(log_get_logfd(), _("%s: %s\n"),
|
||||
log_get_progname(), strerror(errno));
|
||||
exit(13);
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
xreallocarray(void *p, size_t nmemb, size_t size)
|
||||
{
|
||||
p = reallocarrayf(p, nmemb, size);
|
||||
if (p == NULL)
|
||||
goto x;
|
||||
|
||||
return p;
|
||||
|
||||
x:
|
||||
fprintf(log_get_logfd(), _("%s: %s\n"),
|
||||
log_get_progname(), strerror(errno));
|
||||
exit(13);
|
||||
}
|
||||
101
lib/alloc.h
101
lib/alloc.h
@@ -1,101 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_MALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_MALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "defines.h"
|
||||
|
||||
|
||||
#define CALLOC(n, type) ((type *) calloc(n, sizeof(type)))
|
||||
#define XCALLOC(n, type) ((type *) xcalloc(n, sizeof(type)))
|
||||
#define MALLOC(n, type) ((type *) mallocarray(n, sizeof(type)))
|
||||
#define XMALLOC(n, type) ((type *) xmallocarray(n, sizeof(type)))
|
||||
|
||||
#define REALLOC(ptr, n, type) \
|
||||
( \
|
||||
_Generic(ptr, type *: (type *) reallocarray(ptr, n, sizeof(type))) \
|
||||
)
|
||||
|
||||
#define REALLOCF(ptr, n, type) \
|
||||
( \
|
||||
_Generic(ptr, type *: (type *) reallocarrayf(ptr, n, sizeof(type))) \
|
||||
)
|
||||
|
||||
#define XREALLOC(ptr, n, type) \
|
||||
( \
|
||||
_Generic(ptr, type *: (type *) xreallocarray(ptr, n, sizeof(type))) \
|
||||
)
|
||||
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
inline void *xmalloc(size_t size);
|
||||
ATTR_MALLOC(free)
|
||||
inline void *xmallocarray(size_t nmemb, size_t size);
|
||||
ATTR_MALLOC(free)
|
||||
inline void *mallocarray(size_t nmemb, size_t size);
|
||||
ATTR_MALLOC(free)
|
||||
inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
|
||||
ATTR_MALLOC(free)
|
||||
inline char *xstrdup(const char *str);
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
void *xcalloc(size_t nmemb, size_t size);
|
||||
ATTR_MALLOC(free)
|
||||
void *xreallocarray(void *p, size_t nmemb, size_t size);
|
||||
|
||||
|
||||
inline void *
|
||||
xmalloc(size_t size)
|
||||
{
|
||||
return xmallocarray(1, size);
|
||||
}
|
||||
|
||||
|
||||
inline void *
|
||||
xmallocarray(size_t nmemb, size_t size)
|
||||
{
|
||||
return xreallocarray(NULL, nmemb, size);
|
||||
}
|
||||
|
||||
|
||||
inline void *
|
||||
mallocarray(size_t nmemb, size_t size)
|
||||
{
|
||||
return reallocarray(NULL, nmemb, size);
|
||||
}
|
||||
|
||||
|
||||
inline void *
|
||||
reallocarrayf(void *p, size_t nmemb, size_t size)
|
||||
{
|
||||
void *q;
|
||||
|
||||
q = reallocarray(p, nmemb, size);
|
||||
|
||||
/* realloc(p, 0) is equivalent to free(p); avoid double free. */
|
||||
if (q == NULL && nmemb != 0 && size != 0)
|
||||
free(p);
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
inline char *
|
||||
xstrdup(const char *str)
|
||||
{
|
||||
return strcpy(XMALLOC(strlen(str) + 1, char), str);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
11
lib/alloc/calloc.c
Normal file
11
lib/alloc/calloc.c
Normal file
@@ -0,0 +1,11 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/calloc.h"
|
||||
20
lib/alloc/calloc.h
Normal file
20
lib/alloc/calloc.h
Normal file
@@ -0,0 +1,20 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ALLOC_CALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ALLOC_CALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define CALLOC(n, type) \
|
||||
( \
|
||||
(type *) calloc(n, sizeof(type)) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
16
lib/alloc/malloc.c
Normal file
16
lib/alloc/malloc.c
Normal file
@@ -0,0 +1,16 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/malloc.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern inline void *mallocarray(size_t nmemb, size_t size);
|
||||
34
lib/alloc/malloc.h
Normal file
34
lib/alloc/malloc.h
Normal file
@@ -0,0 +1,34 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ALLOC_MALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ALLOC_MALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define MALLOC(n, type) \
|
||||
( \
|
||||
(type *) mallocarray(n, sizeof(type)) \
|
||||
)
|
||||
|
||||
|
||||
ATTR_ALLOC_SIZE(1, 2)
|
||||
ATTR_MALLOC(free)
|
||||
inline void *mallocarray(size_t nmemb, size_t size);
|
||||
|
||||
|
||||
inline void *
|
||||
mallocarray(size_t nmemb, size_t size)
|
||||
{
|
||||
return reallocarray(NULL, nmemb, size);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
11
lib/alloc/realloc.c
Normal file
11
lib/alloc/realloc.c
Normal file
@@ -0,0 +1,11 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/realloc.h"
|
||||
20
lib/alloc/realloc.h
Normal file
20
lib/alloc/realloc.h
Normal file
@@ -0,0 +1,20 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ALLOC_REALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ALLOC_REALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define REALLOC(p, n, type) \
|
||||
( \
|
||||
_Generic(p, type *: (type *) reallocarray(p, (n) ?: 1, sizeof(type))) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
16
lib/alloc/reallocf.c
Normal file
16
lib/alloc/reallocf.c
Normal file
@@ -0,0 +1,16 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/reallocf.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
|
||||
41
lib/alloc/reallocf.h
Normal file
41
lib/alloc/reallocf.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ALLOC_REALLOCF_H_
|
||||
#define SHADOW_INCLUDE_LIB_ALLOC_REALLOCF_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define REALLOCF(p, n, type) \
|
||||
( \
|
||||
_Generic(p, type *: (type *) reallocarrayf(p, (n) ?: 1, sizeof(type)))\
|
||||
)
|
||||
|
||||
|
||||
ATTR_ALLOC_SIZE(2, 3)
|
||||
ATTR_MALLOC(free)
|
||||
inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
|
||||
|
||||
|
||||
inline void *
|
||||
reallocarrayf(void *p, size_t nmemb, size_t size)
|
||||
{
|
||||
void *q;
|
||||
|
||||
q = reallocarray(p, nmemb ?: 1, size ?: 1);
|
||||
|
||||
if (q == NULL)
|
||||
free(p);
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
36
lib/alloc/x/xcalloc.c
Normal file
36
lib/alloc/x/xcalloc.c
Normal file
@@ -0,0 +1,36 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/x/xcalloc.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "shadowlog.h"
|
||||
|
||||
|
||||
void *
|
||||
xcalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = calloc(nmemb, size);
|
||||
if (p == NULL)
|
||||
goto x;
|
||||
|
||||
return p;
|
||||
|
||||
x:
|
||||
fprintf(log_get_logfd(), _("%s: %s\n"),
|
||||
log_get_progname(), strerror(errno));
|
||||
exit(13);
|
||||
}
|
||||
28
lib/alloc/x/xcalloc.h
Normal file
28
lib/alloc/x/xcalloc.h
Normal file
@@ -0,0 +1,28 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ALLOC_X_XCALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ALLOC_X_XCALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define XCALLOC(n, type) \
|
||||
( \
|
||||
(type *) xcalloc(n, sizeof(type)) \
|
||||
)
|
||||
|
||||
|
||||
ATTR_ALLOC_SIZE(1, 2)
|
||||
ATTR_MALLOC(free)
|
||||
void *xcalloc(size_t nmemb, size_t size);
|
||||
|
||||
|
||||
#endif // include guard
|
||||
16
lib/alloc/x/xmalloc.c
Normal file
16
lib/alloc/x/xmalloc.c
Normal file
@@ -0,0 +1,16 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/x/xmalloc.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern inline void *xmallocarray(size_t nmemb, size_t size);
|
||||
35
lib/alloc/x/xmalloc.h
Normal file
35
lib/alloc/x/xmalloc.h
Normal file
@@ -0,0 +1,35 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ALLOC_X_XMALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ALLOC_X_XMALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "alloc/x/xrealloc.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define XMALLOC(n, type) \
|
||||
( \
|
||||
(type *) xmallocarray(n, sizeof(type)) \
|
||||
)
|
||||
|
||||
|
||||
ATTR_ALLOC_SIZE(1, 2)
|
||||
ATTR_MALLOC(free)
|
||||
inline void *xmallocarray(size_t nmemb, size_t size);
|
||||
|
||||
|
||||
inline void *
|
||||
xmallocarray(size_t nmemb, size_t size)
|
||||
{
|
||||
return xreallocarray(NULL, nmemb, size);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
35
lib/alloc/x/xrealloc.c
Normal file
35
lib/alloc/x/xrealloc.c
Normal file
@@ -0,0 +1,35 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/x/xrealloc.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc/reallocf.h"
|
||||
#include "defines.h"
|
||||
#include "shadowlog.h"
|
||||
|
||||
|
||||
void *
|
||||
xreallocarray(void *p, size_t nmemb, size_t size)
|
||||
{
|
||||
p = reallocarrayf(p, nmemb, size);
|
||||
if (p == NULL)
|
||||
goto x;
|
||||
|
||||
return p;
|
||||
|
||||
x:
|
||||
fprintf(log_get_logfd(), _("%s: %s\n"),
|
||||
log_get_progname(), strerror(errno));
|
||||
exit(13);
|
||||
}
|
||||
31
lib/alloc/x/xrealloc.h
Normal file
31
lib/alloc/x/xrealloc.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_MALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_MALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define XREALLOC(ptr, n, type) \
|
||||
( \
|
||||
_Generic(ptr, type *: (type *) xreallocarray(ptr, n, sizeof(type))) \
|
||||
)
|
||||
|
||||
|
||||
ATTR_ALLOC_SIZE(2, 3)
|
||||
ATTR_MALLOC(free)
|
||||
void *xreallocarray(void *p, size_t nmemb, size_t size);
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -1,46 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i.h"
|
||||
|
||||
|
||||
extern inline int a2sh_c(short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, short min, short max);
|
||||
extern inline int a2si_c(int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, int min, int max);
|
||||
extern inline int a2sl_c(long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long min, long max);
|
||||
extern inline int a2sll_c(long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long long min, long long max);
|
||||
extern inline int a2uh_c(unsigned short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned short min,
|
||||
unsigned short max);
|
||||
extern inline int a2ui_c(unsigned int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned int min, unsigned int max);
|
||||
extern inline int a2ul_c(unsigned long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long min, unsigned long max);
|
||||
extern inline int a2ull_c(unsigned long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max);
|
||||
|
||||
|
||||
extern inline int a2sh_nc(short *restrict n, char *s,
|
||||
char **restrict endp, int base, short min, short max);
|
||||
extern inline int a2si_nc(int *restrict n, char *s,
|
||||
char **restrict endp, int base, int min, int max);
|
||||
extern inline int a2sl_nc(long *restrict n, char *s,
|
||||
char **restrict endp, int base, long min, long max);
|
||||
extern inline int a2sll_nc(long long *restrict n, char *s,
|
||||
char **restrict endp, int base, long long min, long long max);
|
||||
extern inline int a2uh_nc(unsigned short *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned short min, unsigned short max);
|
||||
extern inline int a2ui_nc(unsigned int *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned int min, unsigned int max);
|
||||
extern inline int a2ul_nc(unsigned long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long min, unsigned long max);
|
||||
extern inline int a2ull_nc(unsigned long long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max);
|
||||
386
lib/atoi/a2i.h
386
lib/atoi/a2i.h
@@ -1,386 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "atoi/strtoi.h"
|
||||
#include "atoi/strtou_noneg.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
/*
|
||||
* See the manual of these macros in liba2i's documentation:
|
||||
* <http://www.alejandro-colomar.es/share/dist/liba2i/git/HEAD/liba2i-HEAD.pdf>
|
||||
*/
|
||||
|
||||
|
||||
#define a2i(TYPE, n, s, ...) \
|
||||
( \
|
||||
_Generic((void (*)(TYPE, typeof(s))) 0, \
|
||||
void (*)(short, const char *): a2sh_c, \
|
||||
void (*)(short, const void *): a2sh_c, \
|
||||
void (*)(short, char *): a2sh_nc, \
|
||||
void (*)(short, void *): a2sh_nc, \
|
||||
void (*)(int, const char *): a2si_c, \
|
||||
void (*)(int, const void *): a2si_c, \
|
||||
void (*)(int, char *): a2si_nc, \
|
||||
void (*)(int, void *): a2si_nc, \
|
||||
void (*)(long, const char *): a2sl_c, \
|
||||
void (*)(long, const void *): a2sl_c, \
|
||||
void (*)(long, char *): a2sl_nc, \
|
||||
void (*)(long, void *): a2sl_nc, \
|
||||
void (*)(long long, const char *): a2sll_c, \
|
||||
void (*)(long long, const void *): a2sll_c, \
|
||||
void (*)(long long, char *): a2sll_nc, \
|
||||
void (*)(long long, void *): a2sll_nc, \
|
||||
void (*)(unsigned short, const char *): a2uh_c, \
|
||||
void (*)(unsigned short, const void *): a2uh_c, \
|
||||
void (*)(unsigned short, char *): a2uh_nc, \
|
||||
void (*)(unsigned short, void *): a2uh_nc, \
|
||||
void (*)(unsigned int, const char *): a2ui_c, \
|
||||
void (*)(unsigned int, const void *): a2ui_c, \
|
||||
void (*)(unsigned int, char *): a2ui_nc, \
|
||||
void (*)(unsigned int, void *): a2ui_nc, \
|
||||
void (*)(unsigned long, const char *): a2ul_c, \
|
||||
void (*)(unsigned long, const void *): a2ul_c, \
|
||||
void (*)(unsigned long, char *): a2ul_nc, \
|
||||
void (*)(unsigned long, void *): a2ul_nc, \
|
||||
void (*)(unsigned long long, const char *): a2ull_c, \
|
||||
void (*)(unsigned long long, const void *): a2ull_c, \
|
||||
void (*)(unsigned long long, char *): a2ull_nc, \
|
||||
void (*)(unsigned long long, void *): a2ull_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
#define a2sh(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2sh_c, \
|
||||
const void *: a2sh_c, \
|
||||
char *: a2sh_nc, \
|
||||
void *: a2sh_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2si(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2si_c, \
|
||||
const void *: a2si_c, \
|
||||
char *: a2si_nc, \
|
||||
void *: a2si_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2sl(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2sl_c, \
|
||||
const void *: a2sl_c, \
|
||||
char *: a2sl_nc, \
|
||||
void *: a2sl_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2sll(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2sll_c, \
|
||||
const void *: a2sll_c, \
|
||||
char *: a2sll_nc, \
|
||||
void *: a2sll_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2uh(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2uh_c, \
|
||||
const void *: a2uh_c, \
|
||||
char *: a2uh_nc, \
|
||||
void *: a2uh_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2ui(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2ui_c, \
|
||||
const void *: a2ui_c, \
|
||||
char *: a2ui_nc, \
|
||||
void *: a2ui_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2ul(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2ul_c, \
|
||||
const void *: a2ul_c, \
|
||||
char *: a2ul_nc, \
|
||||
void *: a2ul_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2ull(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2ull_c, \
|
||||
const void *: a2ull_c, \
|
||||
char *: a2ull_nc, \
|
||||
void *: a2ull_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sh_c(short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, short min, short max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2si_c(int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, int min, int max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sl_c(long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long min, long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sll_c(long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long long min, long long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2uh_c(unsigned short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned short min,
|
||||
unsigned short max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ui_c(unsigned int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned int min, unsigned int max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ul_c(unsigned long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long min, unsigned long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ull_c(unsigned long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max);
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sh_nc(short *restrict n, char *s,
|
||||
char **restrict endp, int base, short min, short max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2si_nc(int *restrict n, char *s,
|
||||
char **restrict endp, int base, int min, int max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sl_nc(long *restrict n, char *s,
|
||||
char **restrict endp, int base, long min, long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sll_nc(long long *restrict n, char *s,
|
||||
char **restrict endp, int base, long long min, long long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2uh_nc(unsigned short *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned short min, unsigned short max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ui_nc(unsigned int *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned int min, unsigned int max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ul_nc(unsigned long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long min, unsigned long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ull_nc(unsigned long long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max);
|
||||
|
||||
|
||||
inline int
|
||||
a2sh_c(short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, short min, short max)
|
||||
{
|
||||
return a2sh(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2si_c(int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, int min, int max)
|
||||
{
|
||||
return a2si(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sl_c(long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long min, long max)
|
||||
{
|
||||
return a2sl(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sll_c(long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long long min, long long max)
|
||||
{
|
||||
return a2sll(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2uh_c(unsigned short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned short min,
|
||||
unsigned short max)
|
||||
{
|
||||
return a2uh(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ui_c(unsigned int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned int min, unsigned int max)
|
||||
{
|
||||
return a2ui(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ul_c(unsigned long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long min, unsigned long max)
|
||||
{
|
||||
return a2ul(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ull_c(unsigned long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max)
|
||||
{
|
||||
return a2ull(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sh_nc(short *restrict n, char *s,
|
||||
char **restrict endp, int base, short min, short max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtoi_(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2si_nc(int *restrict n, char *s,
|
||||
char **restrict endp, int base, int min, int max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtoi_(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sl_nc(long *restrict n, char *s,
|
||||
char **restrict endp, int base, long min, long max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtoi_(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sll_nc(long long *restrict n, char *s,
|
||||
char **restrict endp, int base, long long min, long long max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtoi_(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2uh_nc(unsigned short *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned short min,
|
||||
unsigned short max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtou_noneg(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ui_nc(unsigned int *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned int min, unsigned int max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtou_noneg(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ul_nc(unsigned long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long min, unsigned long max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtou_noneg(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ull_nc(unsigned long long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtou_noneg(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
7
lib/atoi/a2i/a2i.c
Normal file
7
lib/atoi/a2i/a2i.c
Normal file
@@ -0,0 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2i.h"
|
||||
62
lib/atoi/a2i/a2i.h
Normal file
62
lib/atoi/a2i/a2i.h
Normal file
@@ -0,0 +1,62 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2I_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2I_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2s_c.h"
|
||||
#include "atoi/a2i/a2s_nc.h"
|
||||
#include "atoi/a2i/a2u_c.h"
|
||||
#include "atoi/a2i/a2u_nc.h"
|
||||
|
||||
|
||||
/*
|
||||
* See the manual of these macros in liba2i's documentation:
|
||||
* <http://www.alejandro-colomar.es/share/dist/liba2i/git/HEAD/liba2i-HEAD.pdf>
|
||||
*/
|
||||
|
||||
|
||||
#define a2i(TYPE, n, s, ...) \
|
||||
( \
|
||||
_Generic((void (*)(TYPE, typeof(s))) 0, \
|
||||
void (*)(short, const char *): a2sh_c, \
|
||||
void (*)(short, const void *): a2sh_c, \
|
||||
void (*)(short, char *): a2sh_nc, \
|
||||
void (*)(short, void *): a2sh_nc, \
|
||||
void (*)(int, const char *): a2si_c, \
|
||||
void (*)(int, const void *): a2si_c, \
|
||||
void (*)(int, char *): a2si_nc, \
|
||||
void (*)(int, void *): a2si_nc, \
|
||||
void (*)(long, const char *): a2sl_c, \
|
||||
void (*)(long, const void *): a2sl_c, \
|
||||
void (*)(long, char *): a2sl_nc, \
|
||||
void (*)(long, void *): a2sl_nc, \
|
||||
void (*)(long long, const char *): a2sll_c, \
|
||||
void (*)(long long, const void *): a2sll_c, \
|
||||
void (*)(long long, char *): a2sll_nc, \
|
||||
void (*)(long long, void *): a2sll_nc, \
|
||||
void (*)(unsigned short, const char *): a2uh_c, \
|
||||
void (*)(unsigned short, const void *): a2uh_c, \
|
||||
void (*)(unsigned short, char *): a2uh_nc, \
|
||||
void (*)(unsigned short, void *): a2uh_nc, \
|
||||
void (*)(unsigned int, const char *): a2ui_c, \
|
||||
void (*)(unsigned int, const void *): a2ui_c, \
|
||||
void (*)(unsigned int, char *): a2ui_nc, \
|
||||
void (*)(unsigned int, void *): a2ui_nc, \
|
||||
void (*)(unsigned long, const char *): a2ul_c, \
|
||||
void (*)(unsigned long, const void *): a2ul_c, \
|
||||
void (*)(unsigned long, char *): a2ul_nc, \
|
||||
void (*)(unsigned long, void *): a2ul_nc, \
|
||||
void (*)(unsigned long long, const char *): a2ull_c, \
|
||||
void (*)(unsigned long long, const void *): a2ull_c, \
|
||||
void (*)(unsigned long long, char *): a2ull_nc, \
|
||||
void (*)(unsigned long long, void *): a2ull_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
7
lib/atoi/a2i/a2s.c
Normal file
7
lib/atoi/a2i/a2s.c
Normal file
@@ -0,0 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2s.h"
|
||||
56
lib/atoi/a2i/a2s.h
Normal file
56
lib/atoi/a2i/a2s.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2s_c.h"
|
||||
#include "atoi/a2i/a2s_nc.h"
|
||||
|
||||
|
||||
#define a2sh(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2sh_c, \
|
||||
const void *: a2sh_c, \
|
||||
char *: a2sh_nc, \
|
||||
void *: a2sh_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2si(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2si_c, \
|
||||
const void *: a2si_c, \
|
||||
char *: a2si_nc, \
|
||||
void *: a2si_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2sl(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2sl_c, \
|
||||
const void *: a2sl_c, \
|
||||
char *: a2sl_nc, \
|
||||
void *: a2sl_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2sll(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2sll_c, \
|
||||
const void *: a2sll_c, \
|
||||
char *: a2sll_nc, \
|
||||
void *: a2sll_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
17
lib/atoi/a2i/a2s_c.c
Normal file
17
lib/atoi/a2i/a2s_c.c
Normal file
@@ -0,0 +1,17 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2s_c.h"
|
||||
|
||||
|
||||
extern inline int a2sh_c(short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, short min, short max);
|
||||
extern inline int a2si_c(int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, int min, int max);
|
||||
extern inline int a2sl_c(long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long min, long max);
|
||||
extern inline int a2sll_c(long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long long min, long long max);
|
||||
64
lib/atoi/a2i/a2s_c.h
Normal file
64
lib/atoi/a2i/a2s_c.h
Normal file
@@ -0,0 +1,64 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_C_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_C_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "atoi/a2i/a2s_nc.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sh_c(short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, short min, short max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2si_c(int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, int min, int max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sl_c(long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long min, long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sll_c(long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long long min, long long max);
|
||||
|
||||
|
||||
inline int
|
||||
a2sh_c(short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, short min, short max)
|
||||
{
|
||||
return a2sh_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2si_c(int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, int min, int max)
|
||||
{
|
||||
return a2si_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sl_c(long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long min, long max)
|
||||
{
|
||||
return a2sl_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sll_c(long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long long min, long long max)
|
||||
{
|
||||
return a2sll_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
17
lib/atoi/a2i/a2s_nc.c
Normal file
17
lib/atoi/a2i/a2s_nc.c
Normal file
@@ -0,0 +1,17 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2s_nc.h"
|
||||
|
||||
|
||||
extern inline int a2sh_nc(short *restrict n, char *s,
|
||||
char **restrict endp, int base, short min, short max);
|
||||
extern inline int a2si_nc(int *restrict n, char *s,
|
||||
char **restrict endp, int base, int min, int max);
|
||||
extern inline int a2sl_nc(long *restrict n, char *s,
|
||||
char **restrict endp, int base, long min, long max);
|
||||
extern inline int a2sll_nc(long long *restrict n, char *s,
|
||||
char **restrict endp, int base, long long min, long long max);
|
||||
91
lib/atoi/a2i/a2s_nc.h
Normal file
91
lib/atoi/a2i/a2s_nc.h
Normal file
@@ -0,0 +1,91 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_NC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_NC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "atoi/strtoi/strtoi.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sh_nc(short *restrict n, char *s,
|
||||
char **restrict endp, int base, short min, short max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2si_nc(int *restrict n, char *s,
|
||||
char **restrict endp, int base, int min, int max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sl_nc(long *restrict n, char *s,
|
||||
char **restrict endp, int base, long min, long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sll_nc(long long *restrict n, char *s,
|
||||
char **restrict endp, int base, long long min, long long max);
|
||||
|
||||
|
||||
inline int
|
||||
a2sh_nc(short *restrict n, char *s,
|
||||
char **restrict endp, int base, short min, short max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtoi_(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2si_nc(int *restrict n, char *s,
|
||||
char **restrict endp, int base, int min, int max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtoi_(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sl_nc(long *restrict n, char *s,
|
||||
char **restrict endp, int base, long min, long max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtoi_(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sll_nc(long long *restrict n, char *s,
|
||||
char **restrict endp, int base, long long min, long long max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtoi_(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
7
lib/atoi/a2i/a2u.c
Normal file
7
lib/atoi/a2i/a2u.c
Normal file
@@ -0,0 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2u.h"
|
||||
56
lib/atoi/a2i/a2u.h
Normal file
56
lib/atoi/a2i/a2u.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2u_c.h"
|
||||
#include "atoi/a2i/a2u_nc.h"
|
||||
|
||||
|
||||
#define a2uh(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2uh_c, \
|
||||
const void *: a2uh_c, \
|
||||
char *: a2uh_nc, \
|
||||
void *: a2uh_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2ui(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2ui_c, \
|
||||
const void *: a2ui_c, \
|
||||
char *: a2ui_nc, \
|
||||
void *: a2ui_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2ul(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2ul_c, \
|
||||
const void *: a2ul_c, \
|
||||
char *: a2ul_nc, \
|
||||
void *: a2ul_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2ull(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2ull_c, \
|
||||
const void *: a2ull_c, \
|
||||
char *: a2ull_nc, \
|
||||
void *: a2ull_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
19
lib/atoi/a2i/a2u_c.c
Normal file
19
lib/atoi/a2i/a2u_c.c
Normal file
@@ -0,0 +1,19 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2u_c.h"
|
||||
|
||||
|
||||
extern inline int a2uh_c(unsigned short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned short min,
|
||||
unsigned short max);
|
||||
extern inline int a2ui_c(unsigned int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned int min, unsigned int max);
|
||||
extern inline int a2ul_c(unsigned long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long min, unsigned long max);
|
||||
extern inline int a2ull_c(unsigned long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max);
|
||||
65
lib/atoi/a2i/a2u_c.h
Normal file
65
lib/atoi/a2i/a2u_c.h
Normal file
@@ -0,0 +1,65 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_C_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_C_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2u_nc.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2uh_c(unsigned short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned short min,
|
||||
unsigned short max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ui_c(unsigned int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned int min, unsigned int max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ul_c(unsigned long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long min, unsigned long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ull_c(unsigned long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max);
|
||||
|
||||
|
||||
inline int
|
||||
a2uh_c(unsigned short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned short min,
|
||||
unsigned short max)
|
||||
{
|
||||
return a2uh_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ui_c(unsigned int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned int min, unsigned int max)
|
||||
{
|
||||
return a2ui_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ul_c(unsigned long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long min, unsigned long max)
|
||||
{
|
||||
return a2ul_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ull_c(unsigned long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max)
|
||||
{
|
||||
return a2ull_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
18
lib/atoi/a2i/a2u_nc.c
Normal file
18
lib/atoi/a2i/a2u_nc.c
Normal file
@@ -0,0 +1,18 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2u_nc.h"
|
||||
|
||||
|
||||
extern inline int a2uh_nc(unsigned short *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned short min, unsigned short max);
|
||||
extern inline int a2ui_nc(unsigned int *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned int min, unsigned int max);
|
||||
extern inline int a2ul_nc(unsigned long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long min, unsigned long max);
|
||||
extern inline int a2ull_nc(unsigned long long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max);
|
||||
94
lib/atoi/a2i/a2u_nc.h
Normal file
94
lib/atoi/a2i/a2u_nc.h
Normal file
@@ -0,0 +1,94 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_NC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_NC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "atoi/strtoi/strtou_noneg.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2uh_nc(unsigned short *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned short min, unsigned short max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ui_nc(unsigned int *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned int min, unsigned int max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ul_nc(unsigned long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long min, unsigned long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ull_nc(unsigned long long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max);
|
||||
|
||||
|
||||
inline int
|
||||
a2uh_nc(unsigned short *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned short min,
|
||||
unsigned short max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtou_noneg(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ui_nc(unsigned int *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned int min, unsigned int max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtou_noneg(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ul_nc(unsigned long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long min, unsigned long max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtou_noneg(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ull_nc(unsigned long long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtou_noneg(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
16
lib/atoi/getnum.c
Normal file
16
lib/atoi/getnum.c
Normal file
@@ -0,0 +1,16 @@
|
||||
// SPDX-FileCopyrightText: 2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "atoi/getnum.h"
|
||||
|
||||
|
||||
extern inline int get_fd(const char *restrict fdstr, int *restrict fd);
|
||||
extern inline int get_gid(const char *restrict gidstr, gid_t *restrict gid);
|
||||
extern inline int get_pid(const char *restrict pidstr, pid_t *restrict pid);
|
||||
extern inline int get_uid(const char *restrict uidstr, uid_t *restrict uid);
|
||||
60
lib/atoi/getnum.h
Normal file
60
lib/atoi/getnum.h
Normal file
@@ -0,0 +1,60 @@
|
||||
// SPDX-FileCopyrightText: 2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_GETNUM_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_GETNUM_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "atoi/a2i/a2i.h"
|
||||
#include "atoi/a2i/a2s.h"
|
||||
#include "attr.h"
|
||||
#include "typetraits.h"
|
||||
|
||||
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
|
||||
inline int get_fd(const char *restrict fdstr, int *restrict fd);
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
|
||||
inline int get_gid(const char *restrict gidstr, gid_t *restrict gid);
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
|
||||
inline int get_pid(const char *restrict pidstr, pid_t *restrict pid);
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
|
||||
inline int get_uid(const char *restrict uidstr, uid_t *restrict uid);
|
||||
|
||||
|
||||
inline int
|
||||
get_fd(const char *restrict fdstr, int *restrict fd)
|
||||
{
|
||||
return a2si(fd, fdstr, NULL, 10, 0, INT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
get_gid(const char *restrict gidstr, gid_t *restrict gid)
|
||||
{
|
||||
return a2i(gid_t, gid, gidstr, NULL, 10, type_min(gid_t), type_max(gid_t));
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
get_pid(const char *restrict pidstr, pid_t *restrict pid)
|
||||
{
|
||||
return a2i(pid_t, pid, pidstr, NULL, 10, 1, type_max(pid_t));
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
get_uid(const char *restrict uidstr, uid_t *restrict uid)
|
||||
{
|
||||
return a2i(uid_t, uid, uidstr, NULL, 10, type_min(uid_t), type_max(uid_t));
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
108
lib/atoi/str2i.h
108
lib/atoi/str2i.h
@@ -1,108 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STR2I_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STR2I_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "atoi/a2i.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define str2i(TYPE, ...) \
|
||||
( \
|
||||
_Generic((TYPE) 0, \
|
||||
short: str2sh, \
|
||||
int: str2si, \
|
||||
long: str2sl, \
|
||||
long long: str2sll, \
|
||||
unsigned short: str2uh, \
|
||||
unsigned int: str2ui, \
|
||||
unsigned long: str2ul, \
|
||||
unsigned long long: str2ull \
|
||||
)(__VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2sh(short *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2si(int *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2sl(long *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2sll(long long *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2uh(unsigned short *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2ui(unsigned int *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2ul(unsigned long *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2ull(unsigned long long *restrict n, const char *restrict s);
|
||||
|
||||
|
||||
inline int
|
||||
str2sh(short *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2sh(n, s, NULL, 0, SHRT_MIN, SHRT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2si(int *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2si(n, s, NULL, 0, INT_MIN, INT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2sl(long *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2sl(n, s, NULL, 0, LONG_MIN, LONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2sll(long long *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2sll(n, s, NULL, 0, LLONG_MIN, LLONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2uh(unsigned short *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2uh(n, s, NULL, 0, 0, USHRT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2ui(unsigned int *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2ui(n, s, NULL, 0, 0, UINT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2ul(unsigned long *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2ul(n, s, NULL, 0, 0, ULONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2ull(unsigned long long *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2ull(n, s, NULL, 0, 0, ULLONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
8
lib/atoi/str2i/str2i.c
Normal file
8
lib/atoi/str2i/str2i.c
Normal file
@@ -0,0 +1,8 @@
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/str2i/str2i.h"
|
||||
31
lib/atoi/str2i/str2i.h
Normal file
31
lib/atoi/str2i/str2i.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2I_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2I_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/str2i/str2s.h"
|
||||
#include "atoi/str2i/str2u.h"
|
||||
|
||||
|
||||
#define str2i(TYPE, ...) \
|
||||
( \
|
||||
_Generic((TYPE) 0, \
|
||||
short: str2sh, \
|
||||
int: str2si, \
|
||||
long: str2sl, \
|
||||
long long: str2sll, \
|
||||
unsigned short: str2uh, \
|
||||
unsigned int: str2ui, \
|
||||
unsigned long: str2ul, \
|
||||
unsigned long long: str2ull \
|
||||
)(__VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
14
lib/atoi/str2i/str2s.c
Normal file
14
lib/atoi/str2i/str2s.c
Normal file
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/str2i/str2s.h"
|
||||
|
||||
|
||||
extern inline int str2sh(short *restrict n, const char *restrict s);
|
||||
extern inline int str2si(int *restrict n, const char *restrict s);
|
||||
extern inline int str2sl(long *restrict n, const char *restrict s);
|
||||
extern inline int str2sll(long long *restrict n, const char *restrict s);
|
||||
57
lib/atoi/str2i/str2s.h
Normal file
57
lib/atoi/str2i/str2s.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2S_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2S_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "atoi/a2i/a2s.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2sh(short *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2si(int *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2sl(long *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2sll(long long *restrict n, const char *restrict s);
|
||||
|
||||
|
||||
inline int
|
||||
str2sh(short *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2sh(n, s, NULL, 0, SHRT_MIN, SHRT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2si(int *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2si(n, s, NULL, 0, INT_MIN, INT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2sl(long *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2sl(n, s, NULL, 0, LONG_MIN, LONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2sll(long long *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2sll(n, s, NULL, 0, LLONG_MIN, LLONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -5,13 +5,9 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/str2i.h"
|
||||
#include "atoi/str2i/str2u.h"
|
||||
|
||||
|
||||
extern inline int str2sh(short *restrict n, const char *restrict s);
|
||||
extern inline int str2si(int *restrict n, const char *restrict s);
|
||||
extern inline int str2sl(long *restrict n, const char *restrict s);
|
||||
extern inline int str2sll(long long *restrict n, const char *restrict s);
|
||||
extern inline int str2uh(unsigned short *restrict n, const char *restrict s);
|
||||
extern inline int str2ui(unsigned int *restrict n, const char *restrict s);
|
||||
extern inline int str2ul(unsigned long *restrict n, const char *restrict s);
|
||||
57
lib/atoi/str2i/str2u.h
Normal file
57
lib/atoi/str2i/str2u.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2U_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2U_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "atoi/a2i/a2u.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2uh(unsigned short *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2ui(unsigned int *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2ul(unsigned long *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2ull(unsigned long long *restrict n, const char *restrict s);
|
||||
|
||||
|
||||
inline int
|
||||
str2uh(unsigned short *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2uh(n, s, NULL, 0, 0, USHRT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2ui(unsigned int *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2ui(n, s, NULL, 0, 0, UINT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2ul(unsigned long *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2ul(n, s, NULL, 0, 0, ULONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2ull(unsigned long long *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2ull(n, s, NULL, 0, 0, ULLONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -1,15 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/strtoi.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern inline intmax_t strtoi_(const char *s, char **restrict endp, int base,
|
||||
intmax_t min, intmax_t max, int *restrict status);
|
||||
extern inline uintmax_t strtou_(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status);
|
||||
@@ -1,96 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOI_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STRTOI_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define strtoNmax(TYPE, ...) \
|
||||
( \
|
||||
_Generic((TYPE) 0, \
|
||||
intmax_t: strtoimax, \
|
||||
uintmax_t: strtoumax \
|
||||
)(__VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
#define strtoN(s, endp, base, min, max, status, TYPE) \
|
||||
({ \
|
||||
const char *s_ = s; \
|
||||
char **endp_ = endp; \
|
||||
int base_ = base; \
|
||||
TYPE min_ = min; \
|
||||
TYPE max_ = max; \
|
||||
int *status_ = status; \
|
||||
\
|
||||
int e_, st_; \
|
||||
char *end_; \
|
||||
TYPE n_; \
|
||||
\
|
||||
if (endp_ == NULL) \
|
||||
endp_ = &end_; \
|
||||
if (status_ == NULL) \
|
||||
status_ = &st_; \
|
||||
\
|
||||
if (base_ != 0 && (base_ < 0 || base_ > 36)) { \
|
||||
*status_ = EINVAL; \
|
||||
n_ = 0; \
|
||||
\
|
||||
} else { \
|
||||
e_ = errno; \
|
||||
errno = 0; \
|
||||
n_ = strtoNmax(TYPE, s_, endp_, base_); \
|
||||
\
|
||||
if (*endp_ == s_) \
|
||||
*status_ = ECANCELED; \
|
||||
else if (errno == ERANGE || n_ < min_ || n_ > max_) \
|
||||
*status_ = ERANGE; \
|
||||
else if (**endp_ != '\0') \
|
||||
*status_ = ENOTSUP; \
|
||||
else \
|
||||
*status_ = 0; \
|
||||
\
|
||||
errno = e_; \
|
||||
} \
|
||||
MAX(min_, MIN(max_, n_)); \
|
||||
})
|
||||
|
||||
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
|
||||
inline intmax_t strtoi_(const char *s, char **restrict endp, int base,
|
||||
intmax_t min, intmax_t max, int *restrict status);
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
|
||||
inline uintmax_t strtou_(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status);
|
||||
|
||||
|
||||
inline intmax_t
|
||||
strtoi_(const char *s, char **restrict endp, int base,
|
||||
intmax_t min, intmax_t max, int *restrict status)
|
||||
{
|
||||
return strtoN(s, endp, base, min, max, status, intmax_t);
|
||||
}
|
||||
|
||||
|
||||
inline uintmax_t
|
||||
strtou_(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status)
|
||||
{
|
||||
return strtoN(s, endp, base, min, max, status, uintmax_t);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
13
lib/atoi/strtoi/strtoi.c
Normal file
13
lib/atoi/strtoi/strtoi.c
Normal file
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/strtoi/strtoi.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern inline intmax_t strtoi_(const char *s, char **restrict endp, int base,
|
||||
intmax_t min, intmax_t max, int *restrict status);
|
||||
64
lib/atoi/strtoi/strtoi.h
Normal file
64
lib/atoi/strtoi/strtoi.h
Normal file
@@ -0,0 +1,64 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOI_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOI_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
|
||||
inline intmax_t strtoi_(const char *s, char **restrict endp, int base,
|
||||
intmax_t min, intmax_t max, int *restrict status);
|
||||
|
||||
|
||||
inline intmax_t
|
||||
strtoi_(const char *s, char **restrict endp, int base,
|
||||
intmax_t min, intmax_t max, int *restrict status)
|
||||
{
|
||||
int e, st;
|
||||
char *end;
|
||||
intmax_t n;
|
||||
|
||||
if (endp == NULL)
|
||||
endp = &end;
|
||||
if (status == NULL)
|
||||
status = &st;
|
||||
|
||||
if (base != 0 && (base < 2 || base > 36)) {
|
||||
*status = EINVAL;
|
||||
return MAX(min, MIN(max, 0));
|
||||
}
|
||||
|
||||
e = errno;
|
||||
errno = 0;
|
||||
|
||||
n = strtoimax(s, endp, base);
|
||||
|
||||
if (*endp == s)
|
||||
*status = ECANCELED;
|
||||
else if (errno == ERANGE || n < min || n > max)
|
||||
*status = ERANGE;
|
||||
else if (**endp != '\0')
|
||||
*status = ENOTSUP;
|
||||
else
|
||||
*status = 0;
|
||||
|
||||
errno = e;
|
||||
|
||||
return MAX(min, MIN(max, n));
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
13
lib/atoi/strtoi/strtou.c
Normal file
13
lib/atoi/strtoi/strtou.c
Normal file
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/strtoi/strtou.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern inline uintmax_t strtou_(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status);
|
||||
64
lib/atoi/strtoi/strtou.h
Normal file
64
lib/atoi/strtoi/strtou.h
Normal file
@@ -0,0 +1,64 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
|
||||
inline uintmax_t strtou_(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status);
|
||||
|
||||
|
||||
inline uintmax_t
|
||||
strtou_(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status)
|
||||
{
|
||||
int e, st;
|
||||
char *end;
|
||||
uintmax_t n;
|
||||
|
||||
if (endp == NULL)
|
||||
endp = &end;
|
||||
if (status == NULL)
|
||||
status = &st;
|
||||
|
||||
if (base != 0 && (base < 2 || base > 36)) {
|
||||
*status = EINVAL;
|
||||
return MAX(min, 0);
|
||||
}
|
||||
|
||||
e = errno;
|
||||
errno = 0;
|
||||
|
||||
n = strtoumax(s, endp, base);
|
||||
|
||||
if (*endp == s)
|
||||
*status = ECANCELED;
|
||||
else if (errno == ERANGE || n < min || n > max)
|
||||
*status = ERANGE;
|
||||
else if (**endp != '\0')
|
||||
*status = ENOTSUP;
|
||||
else
|
||||
*status = 0;
|
||||
|
||||
errno = e;
|
||||
|
||||
return MAX(min, MIN(max, n));
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -1,10 +1,10 @@
|
||||
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/strtou_noneg.h"
|
||||
#include "atoi/strtoi/strtou_noneg.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOU_NONEG_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STRTOU_NONEG_H_
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_NONEG_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_NONEG_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
@@ -12,7 +12,8 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "atoi/strtoi.h"
|
||||
#include "atoi/strtoi/strtoi.h"
|
||||
#include "atoi/strtoi/strtou.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
16
lib/attr.h
16
lib/attr.h
@@ -5,16 +5,18 @@
|
||||
#include "config.h"
|
||||
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# define MAYBE_UNUSED __attribute__((unused))
|
||||
# define NORETURN __attribute__((__noreturn__))
|
||||
# define format_attr(type, fmt, va) __attribute__((format(type, fmt, va)))
|
||||
# define ATTR_ACCESS(...) __attribute__((access(__VA_ARGS__)))
|
||||
#if (__GNUC__ >= 10)
|
||||
# define MAYBE_UNUSED [[gnu::unused]]
|
||||
# define NORETURN [[gnu::__noreturn__]]
|
||||
# define format_attr(type, fmt, va) [[gnu::format(type, fmt, va)]]
|
||||
# define ATTR_ACCESS(...) [[gnu::access(__VA_ARGS__)]]
|
||||
# define ATTR_ALLOC_SIZE(...) [[gnu::alloc_size(__VA_ARGS__)]]
|
||||
#else
|
||||
# define MAYBE_UNUSED
|
||||
# define NORETURN
|
||||
# define format_attr(type, fmt, va)
|
||||
# define ATTR_ACCESS(...)
|
||||
# define ATTR_ALLOC_SIZE(...)
|
||||
#endif
|
||||
|
||||
#if (__GNUC__ >= 11) && !defined(__clang__)
|
||||
@@ -24,9 +26,9 @@
|
||||
#endif
|
||||
|
||||
#if (__GNUC__ >= 14)
|
||||
# define ATTR_STRING(...) [[gnu::null_terminated_string_arg(__VA_ARGS__)]]
|
||||
# define ATTR_STRING(i) [[gnu::null_terminated_string_arg(i)]]
|
||||
#else
|
||||
# define ATTR_STRING(...)
|
||||
# define ATTR_STRING(i)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh
|
||||
* SPDX-FileCopyrightText: 1996 - 1997, Marek Michałkiewicz
|
||||
* SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1997, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
/*
|
||||
* basename.c - not worth copyrighting :-). Some versions of Linux libc
|
||||
@@ -15,17 +13,19 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
/*@observer@*/const char *Basename (const char *str)
|
||||
#include "string/strspn/stprcspn.h"
|
||||
|
||||
|
||||
/*@observer@*/const char *
|
||||
Basename(const char *str)
|
||||
{
|
||||
if (str == NULL) {
|
||||
abort ();
|
||||
}
|
||||
|
||||
char *cp = strrchr (str, '/');
|
||||
|
||||
return (NULL != cp) ? cp + 1 : str;
|
||||
return stprcspn(str, "/");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-FileCopyrightText: 1996-2000, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2001-2005, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2005-2008, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
* return values:
|
||||
* true - OK
|
||||
* false - bad name
|
||||
* errors:
|
||||
* EINVAL Invalid name characters or sequences
|
||||
* EOVERFLOW Name longer than maximum size
|
||||
*/
|
||||
|
||||
|
||||
@@ -28,6 +31,13 @@
|
||||
|
||||
#include "defines.h"
|
||||
#include "chkname.h"
|
||||
#include "string/ctype/strisascii/strisdigit.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
#ifndef LOGIN_NAME_MAX
|
||||
# define LOGIN_NAME_MAX 256
|
||||
#endif
|
||||
|
||||
|
||||
int allow_bad_names = false;
|
||||
@@ -38,16 +48,16 @@ login_name_max_size(void)
|
||||
{
|
||||
long conf;
|
||||
|
||||
errno = 0;
|
||||
conf = sysconf(_SC_LOGIN_NAME_MAX);
|
||||
if (conf == -1 && errno != 0)
|
||||
if (conf == -1)
|
||||
return LOGIN_NAME_MAX;
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
|
||||
static bool is_valid_name (const char *name)
|
||||
static bool
|
||||
is_valid_name(const char *name)
|
||||
{
|
||||
if (allow_bad_names) {
|
||||
return true;
|
||||
@@ -62,57 +72,67 @@ static bool is_valid_name (const char *name)
|
||||
*
|
||||
* Also do not allow fully numeric names or just "." or "..".
|
||||
*/
|
||||
int numeric;
|
||||
|
||||
if ('\0' == *name ||
|
||||
('.' == *name && (('.' == name[1] && '\0' == name[2]) ||
|
||||
'\0' == name[1])) ||
|
||||
if (strisdigit(name)) {
|
||||
errno = EINVAL;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (streq(name, "") ||
|
||||
streq(name, ".") ||
|
||||
streq(name, "..") ||
|
||||
!((*name >= 'a' && *name <= 'z') ||
|
||||
(*name >= 'A' && *name <= 'Z') ||
|
||||
(*name >= '0' && *name <= '9') ||
|
||||
*name == '_' ||
|
||||
*name == '.')) {
|
||||
*name == '.'))
|
||||
{
|
||||
errno = EINVAL;
|
||||
return false;
|
||||
}
|
||||
|
||||
numeric = isdigit(*name);
|
||||
|
||||
while ('\0' != *++name) {
|
||||
while (!streq(++name, "")) {
|
||||
if (!((*name >= 'a' && *name <= 'z') ||
|
||||
(*name >= 'A' && *name <= 'Z') ||
|
||||
(*name >= '0' && *name <= '9') ||
|
||||
*name == '_' ||
|
||||
*name == '.' ||
|
||||
*name == '-' ||
|
||||
(*name == '$' && name[1] == '\0')
|
||||
)) {
|
||||
streq(name, "$")
|
||||
))
|
||||
{
|
||||
errno = EINVAL;
|
||||
return false;
|
||||
}
|
||||
numeric &= isdigit(*name);
|
||||
}
|
||||
|
||||
return !numeric;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
is_valid_user_name(const char *name)
|
||||
{
|
||||
if (strlen(name) >= login_name_max_size())
|
||||
if (strlen(name) >= login_name_max_size()) {
|
||||
errno = EOVERFLOW;
|
||||
return false;
|
||||
}
|
||||
|
||||
return is_valid_name(name);
|
||||
}
|
||||
|
||||
|
||||
bool is_valid_group_name (const char *name)
|
||||
bool
|
||||
is_valid_group_name(const char *name)
|
||||
{
|
||||
/*
|
||||
* Arbitrary limit for group names.
|
||||
* HP-UX 10 limits to 16 characters
|
||||
*/
|
||||
if ( (GROUP_NAME_MAX_LENGTH > 0)
|
||||
&& (strlen (name) > GROUP_NAME_MAX_LENGTH)) {
|
||||
&& (strlen (name) > GROUP_NAME_MAX_LENGTH))
|
||||
{
|
||||
errno = EOVERFLOW;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,15 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
static int chown_tree_at (int at_fd,
|
||||
const char *path,
|
||||
uid_t old_uid,
|
||||
@@ -56,8 +59,8 @@ static int chown_tree_at (int at_fd,
|
||||
/*
|
||||
* Skip the "." and ".." entries
|
||||
*/
|
||||
if ( (strcmp (ent->d_name, ".") == 0)
|
||||
|| (strcmp (ent->d_name, "..") == 0)) {
|
||||
if ( streq(ent->d_name, ".")
|
||||
|| streq(ent->d_name, "..")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ void do_cleanups (void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
/* Make sure there were no overflow */
|
||||
/* Make sure there were no overflows */
|
||||
assert (NULL == cleanup_functions[CLEANUP_FUNCTIONS-1]);
|
||||
|
||||
if (getpid () != cleanup_pid) {
|
||||
|
||||
@@ -11,28 +11,33 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "defines.h"
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <utime.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "memzero.h"
|
||||
#include "alloc/malloc.h"
|
||||
#include "alloc/reallocf.h"
|
||||
#include "atoi/getnum.h"
|
||||
#include "commonio.h"
|
||||
#include "defines.h"
|
||||
#include "nscd.h"
|
||||
#include "sssd.h"
|
||||
#ifdef WITH_TCB
|
||||
#include <tcb.h>
|
||||
#endif /* WITH_TCB */
|
||||
#include "prototypes.h"
|
||||
#include "commonio.h"
|
||||
#include "shadowlog_internal.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "sssd.h"
|
||||
#include "string/memset/memzero.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strtok/stpsep.h"
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
@@ -194,7 +199,7 @@ static int do_lock_file (const char *file, const char *lock, bool log)
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
buf[len] = '\0';
|
||||
stpcpy(&buf[len], "");
|
||||
if (get_pid(buf, &pid) == -1) {
|
||||
if (log) {
|
||||
(void) fprintf (shadow_logfd,
|
||||
@@ -573,9 +578,7 @@ static void add_one_entry_nis (struct commonio_db *db,
|
||||
int commonio_open (struct commonio_db *db, int mode)
|
||||
{
|
||||
char *buf;
|
||||
char *cp;
|
||||
char *line;
|
||||
struct commonio_entry *p;
|
||||
void *eptr = NULL;
|
||||
int flags = mode;
|
||||
size_t buflen;
|
||||
@@ -636,21 +639,21 @@ int commonio_open (struct commonio_db *db, int mode)
|
||||
|
||||
buflen = BUFLEN;
|
||||
buf = MALLOC(buflen, char);
|
||||
if (NULL == buf) {
|
||||
goto cleanup_ENOMEM;
|
||||
}
|
||||
if (NULL == buf)
|
||||
goto cleanup_errno;
|
||||
|
||||
while (db->ops->fgets (buf, buflen, db->fp) == buf) {
|
||||
struct commonio_entry *p;
|
||||
|
||||
while ( (strrchr (buf, '\n') == NULL)
|
||||
&& (feof (db->fp) == 0)) {
|
||||
size_t len;
|
||||
|
||||
buflen += BUFLEN;
|
||||
cp = REALLOC(buf, buflen, char);
|
||||
if (NULL == cp) {
|
||||
goto cleanup_buf;
|
||||
}
|
||||
buf = cp;
|
||||
buf = REALLOCF(buf, buflen, char);
|
||||
if (NULL == buf)
|
||||
goto cleanup_errno;
|
||||
|
||||
len = strlen (buf);
|
||||
if (db->ops->fgets (buf + len,
|
||||
(int) (buflen - len),
|
||||
@@ -658,10 +661,7 @@ int commonio_open (struct commonio_db *db, int mode)
|
||||
goto cleanup_buf;
|
||||
}
|
||||
}
|
||||
cp = strrchr (buf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
stpsep(buf, "\n");
|
||||
|
||||
line = strdup (buf);
|
||||
if (NULL == line) {
|
||||
@@ -713,7 +713,6 @@ int commonio_open (struct commonio_db *db, int mode)
|
||||
free (line);
|
||||
cleanup_buf:
|
||||
free (buf);
|
||||
cleanup_ENOMEM:
|
||||
errno = ENOMEM;
|
||||
cleanup_errno:
|
||||
saved_errno = errno;
|
||||
@@ -832,10 +831,8 @@ int commonio_sort_wrt (struct commonio_db *shadow,
|
||||
if (NULL == spw_ptr->eptr) {
|
||||
continue;
|
||||
}
|
||||
if (strcmp (name, shadow->ops->getname (spw_ptr->eptr))
|
||||
== 0) {
|
||||
if (streq(name, shadow->ops->getname(spw_ptr->eptr)))
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (NULL == spw_ptr) {
|
||||
continue;
|
||||
@@ -894,7 +891,7 @@ static int write_all (const struct commonio_db *db)
|
||||
|
||||
int commonio_close (struct commonio_db *db)
|
||||
{
|
||||
int errors = 0;
|
||||
bool errors = false;
|
||||
char buf[1024];
|
||||
struct stat sb;
|
||||
|
||||
@@ -935,25 +932,25 @@ int commonio_close (struct commonio_db *db)
|
||||
|
||||
#ifdef WITH_SELINUX
|
||||
if (set_selinux_file_context (db->filename, S_IFREG) != 0) {
|
||||
errors++;
|
||||
errors = true;
|
||||
}
|
||||
#endif
|
||||
if (create_backup (buf, db->fp) != 0) {
|
||||
errors++;
|
||||
errors = true;
|
||||
}
|
||||
|
||||
if (fclose (db->fp) != 0) {
|
||||
errors++;
|
||||
errors = true;
|
||||
}
|
||||
|
||||
db->fp = NULL;
|
||||
|
||||
#ifdef WITH_SELINUX
|
||||
if (reset_selinux_file_context () != 0) {
|
||||
errors++;
|
||||
errors = true;
|
||||
}
|
||||
#endif
|
||||
if (errors != 0)
|
||||
if (errors)
|
||||
goto fail;
|
||||
} else {
|
||||
/*
|
||||
@@ -969,7 +966,7 @@ int commonio_close (struct commonio_db *db)
|
||||
|
||||
#ifdef WITH_SELINUX
|
||||
if (set_selinux_file_context (db->filename, S_IFREG) != 0) {
|
||||
errors++;
|
||||
errors = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -979,24 +976,24 @@ int commonio_close (struct commonio_db *db)
|
||||
}
|
||||
|
||||
if (write_all (db) != 0) {
|
||||
errors++;
|
||||
errors = true;
|
||||
}
|
||||
|
||||
if (fflush (db->fp) != 0) {
|
||||
errors++;
|
||||
errors = true;
|
||||
}
|
||||
|
||||
if (fsync (fileno (db->fp)) != 0) {
|
||||
errors++;
|
||||
errors = true;
|
||||
}
|
||||
|
||||
if (fclose (db->fp) != 0) {
|
||||
errors++;
|
||||
errors = true;
|
||||
}
|
||||
|
||||
db->fp = NULL;
|
||||
|
||||
if (errors != 0) {
|
||||
if (errors) {
|
||||
unlink (buf);
|
||||
goto fail;
|
||||
}
|
||||
@@ -1014,11 +1011,11 @@ int commonio_close (struct commonio_db *db)
|
||||
nscd_need_reload = true;
|
||||
goto success;
|
||||
fail:
|
||||
errors++;
|
||||
errors = true;
|
||||
success:
|
||||
|
||||
free_linked_list (db);
|
||||
return errors == 0;
|
||||
return !errors;
|
||||
}
|
||||
|
||||
static /*@dependent@*/ /*@null@*/struct commonio_entry *next_entry_by_name (
|
||||
@@ -1036,7 +1033,7 @@ static /*@dependent@*/ /*@null@*/struct commonio_entry *next_entry_by_name (
|
||||
for (p = pos; NULL != p; p = p->next) {
|
||||
ep = p->eptr;
|
||||
if ( (NULL != ep)
|
||||
&& (strcmp (db->ops->getname (ep), name) == 0)) {
|
||||
&& streq(db->ops->getname(ep), name)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1242,7 +1239,7 @@ int commonio_rewind (struct commonio_db *db)
|
||||
|
||||
if (!db->isopen) {
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
if (NULL == db->cursor) {
|
||||
db->cursor = db->head;
|
||||
|
||||
@@ -9,20 +9,25 @@
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include "defines.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strtcpy.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
#include "string/strtok/stpsep.h"
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
/*
|
||||
* This is now rather generic function which decides if "tty" is listed
|
||||
* under "cfgin" in config (directly or indirectly). Fallback to default if
|
||||
* something is bad.
|
||||
*/
|
||||
static bool is_listed (const char *cfgin, const char *tty, bool def)
|
||||
static bool
|
||||
is_listed(const char *cfgin, const char *tty, bool def)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[1024], *s;
|
||||
@@ -45,14 +50,13 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
|
||||
|
||||
if (*cons != '/') {
|
||||
char *pbuf;
|
||||
|
||||
STRTCPY(buf, cons);
|
||||
pbuf = &buf[0];
|
||||
while ((s = strtok (pbuf, ":")) != NULL) {
|
||||
if (strcmp (s, tty) == 0) {
|
||||
pbuf = buf;
|
||||
while (NULL != (s = strsep(&pbuf, ":"))) {
|
||||
if (streq(s, tty)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
pbuf = NULL;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -72,9 +76,8 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
|
||||
*/
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp) != NULL) {
|
||||
/* Remove optional trailing '\n'. */
|
||||
buf[strcspn (buf, "\n")] = '\0';
|
||||
if (strcmp (buf, tty) == 0) {
|
||||
stpsep(buf, "\n");
|
||||
if (streq(buf, tty)) {
|
||||
(void) fclose (fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
#include <sys/time.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "alloc/x/xmalloc.h"
|
||||
#include "attr.h"
|
||||
#include "fs/readlink/areadlink.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#ifdef WITH_SELINUX
|
||||
@@ -36,7 +38,8 @@
|
||||
#include <attr/libattr.h>
|
||||
#endif /* WITH_ATTR */
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
static /*@null@*/const char *src_orig;
|
||||
@@ -66,7 +69,6 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst,
|
||||
const struct stat *statp, const struct timespec mt[],
|
||||
uid_t old_uid, uid_t new_uid,
|
||||
gid_t old_gid, gid_t new_gid);
|
||||
static /*@null@*/char *readlink_malloc (const char *filename);
|
||||
static int copy_symlink (const struct path_info *src, const struct path_info *dst,
|
||||
MAYBE_UNUSED bool reset_selinux,
|
||||
const struct stat *statp, const struct timespec mt[],
|
||||
@@ -313,8 +315,8 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info *
|
||||
/*
|
||||
* Skip the "." and ".." entries
|
||||
*/
|
||||
if (strcmp(ent->d_name, ".") == 0 ||
|
||||
strcmp(ent->d_name, "..") == 0)
|
||||
if (streq(ent->d_name, ".") ||
|
||||
streq(ent->d_name, ".."))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -536,42 +538,6 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst,
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* readlink_malloc - wrapper for readlink
|
||||
*
|
||||
* return NULL on error.
|
||||
* The return string shall be freed by the caller.
|
||||
*/
|
||||
static /*@null@*/char *readlink_malloc (const char *filename)
|
||||
{
|
||||
size_t size = 1024;
|
||||
|
||||
while (true) {
|
||||
ssize_t nchars;
|
||||
char *buffer = MALLOC(size, char);
|
||||
if (NULL == buffer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nchars = readlink (filename, buffer, size);
|
||||
|
||||
if (nchars < 0) {
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((size_t) nchars < size) { /* The buffer was large enough */
|
||||
/* readlink does not nul-terminate */
|
||||
buffer[nchars] = '\0';
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/* Try again with a bigger buffer */
|
||||
free (buffer);
|
||||
size *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* copy_symlink - copy a symlink
|
||||
*
|
||||
@@ -602,10 +568,9 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds
|
||||
* destination directory name.
|
||||
*/
|
||||
|
||||
oldlink = readlink_malloc (src->full_path);
|
||||
if (NULL == oldlink) {
|
||||
oldlink = areadlink(src->full_path);
|
||||
if (NULL == oldlink)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If src was a link to an entry of the src_orig directory itself,
|
||||
* create a link to the corresponding entry in the dst_orig
|
||||
|
||||
43
lib/csrand.c
43
lib/csrand.c
@@ -1,21 +1,19 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Alejandro Colomar <alx@kernel.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#if HAVE_SYS_RANDOM_H
|
||||
#include <sys/random.h>
|
||||
#if __has_include(<sys/random.h>)
|
||||
# include <sys/random.h>
|
||||
#endif
|
||||
|
||||
#include "bit.h"
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
@@ -23,6 +21,7 @@
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
static uint32_t csrand32(void);
|
||||
static uint32_t csrand_uniform32(uint32_t n);
|
||||
static unsigned long csrand_uniform_slow(unsigned long n);
|
||||
|
||||
@@ -33,7 +32,7 @@ static unsigned long csrand_uniform_slow(unsigned long n);
|
||||
unsigned long
|
||||
csrand(void)
|
||||
{
|
||||
FILE *fp;
|
||||
int fd;
|
||||
unsigned long r;
|
||||
|
||||
#ifdef HAVE_GETENTROPY
|
||||
@@ -55,17 +54,16 @@ csrand(void)
|
||||
#endif
|
||||
|
||||
/* Use /dev/urandom as a last resort. */
|
||||
fp = fopen("/dev/urandom", "r");
|
||||
if (NULL == fp) {
|
||||
fd = open("/dev/urandom", O_RDONLY);
|
||||
if (fd == -1)
|
||||
goto fail;
|
||||
|
||||
if (read(fd, &r, sizeof(r)) != sizeof(r)) {
|
||||
close(fd);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (fread(&r, sizeof(r), 1, fp) != 1) {
|
||||
fclose(fp);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
close(fd);
|
||||
return r;
|
||||
|
||||
fail:
|
||||
@@ -97,6 +95,13 @@ csrand_interval(unsigned long min, unsigned long max)
|
||||
}
|
||||
|
||||
|
||||
static uint32_t
|
||||
csrand32(void)
|
||||
{
|
||||
return csrand();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Fast Random Integer Generation in an Interval
|
||||
* ACM Transactions on Modeling and Computer Simulation 29 (1), 2019
|
||||
@@ -109,12 +114,12 @@ csrand_uniform32(uint32_t n)
|
||||
uint64_t r, mult;
|
||||
|
||||
if (n == 0)
|
||||
return csrand();
|
||||
return csrand32();
|
||||
|
||||
bound = -n % n; // analogous to `2^32 % n`, since `x % y == (x-y) % y`
|
||||
|
||||
do {
|
||||
r = csrand();
|
||||
r = csrand32();
|
||||
mult = r * n;
|
||||
rem = mult; // analogous to `mult % 2^32`
|
||||
} while (rem < bound); // p = (2^32 % n) / 2^32; W.C.: n=2^31+1, p=0.5
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
* crypt(3), crypt_gensalt(3), and their
|
||||
* feature test macros may be defined in here.
|
||||
*/
|
||||
#if HAVE_CRYPT_H
|
||||
#if __has_include(<crypt.h>)
|
||||
# include <crypt.h>
|
||||
#endif
|
||||
|
||||
@@ -50,13 +50,8 @@
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
/*
|
||||
* Possible cases:
|
||||
* - /usr/include/shadow.h exists and includes the shadow group stuff.
|
||||
* - /usr/include/shadow.h exists, but we use our own gshadow.h.
|
||||
*/
|
||||
#include <shadow.h>
|
||||
#if defined(SHADOWGRP) && !defined(GSHADOW)
|
||||
#if defined(SHADOWGRP)
|
||||
#include "gshadow_.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -65,7 +65,8 @@
|
||||
(void) fprintf (shadow_logfd,
|
||||
_("crypt method not supported by libcrypt? (%s)\n"),
|
||||
method);
|
||||
exit (EXIT_FAILURE);
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strlen (cp) != 13) {
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "alloc/x/xmalloc.h"
|
||||
#include "alloc/x/xrealloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
#include "defines.h"
|
||||
#include "faillog.h"
|
||||
#include "failure.h"
|
||||
#include "memzero.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/memset/memzero.h"
|
||||
#include "string/strftime.h"
|
||||
#include "string/strtcpy.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
|
||||
|
||||
#define YEAR (365L*DAY)
|
||||
@@ -82,7 +82,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl)
|
||||
}
|
||||
|
||||
STRTCPY(fl->fail_line, tty);
|
||||
(void) time (&fl->fail_time);
|
||||
fl->fail_time = time(NULL);
|
||||
|
||||
/*
|
||||
* Seek back to the correct position in the file and write the
|
||||
@@ -126,7 +126,7 @@ static bool too_many_failures (const struct faillog *fl)
|
||||
return true; /* locked until reset manually */
|
||||
}
|
||||
|
||||
(void) time (&now);
|
||||
now = time(NULL);
|
||||
if ((fl->fail_time + fl->fail_locktime) < now) {
|
||||
return false; /* enough time since last failure */
|
||||
}
|
||||
@@ -242,14 +242,12 @@ void failprint (const struct faillog *fail)
|
||||
struct tm *tp;
|
||||
char lasttimeb[256];
|
||||
char *lasttime = lasttimeb;
|
||||
time_t NOW;
|
||||
|
||||
if (0 == fail->fail_cnt) {
|
||||
return;
|
||||
}
|
||||
|
||||
tp = localtime (&(fail->fail_time));
|
||||
(void) time (&NOW);
|
||||
|
||||
/*
|
||||
* Print all information we have.
|
||||
|
||||
31
lib/fields.c
31
lib/fields.c
@@ -14,7 +14,13 @@
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strspn/stpspn.h"
|
||||
#include "string/strspn/stprspn.h"
|
||||
#include "string/strtok/stpsep.h"
|
||||
|
||||
|
||||
/*
|
||||
* valid_field - insure that a field contains all legal characters
|
||||
@@ -42,7 +48,7 @@ int valid_field (const char *field, const char *illegal)
|
||||
}
|
||||
|
||||
/* Search if there are non-printable or control characters */
|
||||
for (cp = field; '\0' != *cp; cp++) {
|
||||
for (cp = field; !streq(cp, ""); cp++) {
|
||||
unsigned char c = *cp;
|
||||
if (!isprint (c)) {
|
||||
err = 1;
|
||||
@@ -62,7 +68,8 @@ int valid_field (const char *field, const char *illegal)
|
||||
* prompt the user with the name of the field being changed and the
|
||||
* current value.
|
||||
*/
|
||||
void change_field (char *buf, size_t maxsize, const char *prompt)
|
||||
void
|
||||
change_field(char *buf, size_t maxsize, const char *prompt)
|
||||
{
|
||||
char newf[200];
|
||||
char *cp;
|
||||
@@ -77,29 +84,17 @@ void change_field (char *buf, size_t maxsize, const char *prompt)
|
||||
return;
|
||||
}
|
||||
|
||||
cp = strchr (newf, '\n');
|
||||
if (NULL == cp) {
|
||||
if (stpsep(newf, "\n") == NULL)
|
||||
return;
|
||||
}
|
||||
*cp = '\0';
|
||||
|
||||
if ('\0' != newf[0]) {
|
||||
if (!streq(newf, "")) {
|
||||
/*
|
||||
* Remove leading and trailing whitespace. This also
|
||||
* makes it possible to change the field to empty, by
|
||||
* entering a space. --marekm
|
||||
*/
|
||||
|
||||
while (newf < cp && isspace (cp[-1])) {
|
||||
cp--;
|
||||
}
|
||||
*cp = '\0';
|
||||
|
||||
cp = newf;
|
||||
while (isspace (*cp)) {
|
||||
cp++;
|
||||
}
|
||||
|
||||
stpcpy(stprspn(newf, " \t"), "");
|
||||
cp = stpspn(newf, " \t");
|
||||
strcpy (buf, cp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "alloc/calloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "groupio.h"
|
||||
#include "getdef.h"
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "alloc/calloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "pwio.h"
|
||||
#include "getdef.h"
|
||||
@@ -304,7 +305,7 @@ int find_new_uid(bool sys_user,
|
||||
return 0;
|
||||
} else if (result == EEXIST || result == EINVAL) {
|
||||
/*
|
||||
* This GID is in use or unusable, we'll
|
||||
* This UID is in use or unusable, we'll
|
||||
* continue to the next.
|
||||
*/
|
||||
} else {
|
||||
@@ -350,7 +351,7 @@ int find_new_uid(bool sys_user,
|
||||
return 0;
|
||||
} else if (result == EEXIST || result == EINVAL) {
|
||||
/*
|
||||
* This GID is in use or unusable, we'll
|
||||
* This UID is in use or unusable, we'll
|
||||
* continue to the next.
|
||||
*/
|
||||
} else {
|
||||
@@ -413,7 +414,7 @@ int find_new_uid(bool sys_user,
|
||||
return 0;
|
||||
} else if (result == EEXIST || result == EINVAL) {
|
||||
/*
|
||||
* This GID is in use or unusable, we'll
|
||||
* This UID is in use or unusable, we'll
|
||||
* continue to the next.
|
||||
*/
|
||||
} else {
|
||||
@@ -459,7 +460,7 @@ int find_new_uid(bool sys_user,
|
||||
return 0;
|
||||
} else if (result == EEXIST || result == EINVAL) {
|
||||
/*
|
||||
* This GID is in use or unusable, we'll
|
||||
* This UID is in use or unusable, we'll
|
||||
* continue to the next.
|
||||
*/
|
||||
} else {
|
||||
|
||||
15
lib/fputsx.c
15
lib/fputsx.c
@@ -10,10 +10,11 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
#ident "$Id$"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
/*@null@*/char *
|
||||
@@ -25,7 +26,7 @@ fgetsx(/*@returned@*/char *restrict buf, int cnt, FILE *restrict f)
|
||||
while (cnt > 0) {
|
||||
if (fgets (cp, cnt, f) != cp) {
|
||||
if (cp == buf) {
|
||||
return 0;
|
||||
return NULL;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@@ -33,10 +34,8 @@ fgetsx(/*@returned@*/char *restrict buf, int cnt, FILE *restrict f)
|
||||
ep = strrchr (cp, '\\');
|
||||
if ((NULL != ep) && (*(ep + 1) == '\n')) {
|
||||
cnt -= ep - cp;
|
||||
if (cnt > 0) {
|
||||
cp = ep;
|
||||
*cp = '\0';
|
||||
}
|
||||
if (cnt > 0)
|
||||
cp = stpcpy(ep, "");
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@@ -48,7 +47,7 @@ int fputsx (const char *s, FILE * stream)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; '\0' != *s; i++, s++) {
|
||||
for (i = 0; !streq(s, ""); i++, s++) {
|
||||
if (putc (*s, stream) == EOF) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
10
lib/fs/readlink/areadlink.c
Normal file
10
lib/fs/readlink/areadlink.c
Normal file
@@ -0,0 +1,10 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "fs/readlink/areadlink.h"
|
||||
|
||||
|
||||
extern inline char *areadlink(const char *link);
|
||||
53
lib/fs/readlink/areadlink.h
Normal file
53
lib/fs/readlink/areadlink.h
Normal file
@@ -0,0 +1,53 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_FS_READLINK_AREADLINK_H_
|
||||
#define SHADOW_INCLUDE_LIB_FS_READLINK_AREADLINK_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "alloc/malloc.h"
|
||||
#include "attr.h"
|
||||
#include "fs/readlink/readlinknul.h"
|
||||
|
||||
|
||||
ATTR_STRING(1)
|
||||
inline char *areadlink(const char *link);
|
||||
|
||||
|
||||
// Similar to readlink(2), but allocate and terminate the string.
|
||||
inline char *
|
||||
areadlink(const char *link)
|
||||
{
|
||||
size_t size = PATH_MAX;
|
||||
|
||||
while (true) {
|
||||
int len;
|
||||
char *buf;
|
||||
|
||||
buf = MALLOC(size, char);
|
||||
if (NULL == buf)
|
||||
return NULL;
|
||||
|
||||
len = readlinknul(link, buf, size);
|
||||
if (len != -1)
|
||||
return buf;
|
||||
|
||||
free(buf);
|
||||
if (errno != E2BIG)
|
||||
return NULL;
|
||||
|
||||
size *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
14
lib/fs/readlink/readlinknul.c
Normal file
14
lib/fs/readlink/readlinknul.c
Normal file
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "fs/readlink/readlinknul.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
extern inline ssize_t readlinknul(const char *restrict link, char *restrict buf,
|
||||
size_t size);
|
||||
53
lib/fs/readlink/readlinknul.h
Normal file
53
lib/fs/readlink/readlinknul.h
Normal file
@@ -0,0 +1,53 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_FS_READLINK_READLINKNUL_H_
|
||||
#define SHADOW_INCLUDE_LIB_FS_READLINK_READLINKNUL_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
#define READLINKNUL(link, buf) readlinknul(link, buf, NITEMS(buf))
|
||||
|
||||
|
||||
ATTR_STRING(1)
|
||||
inline ssize_t readlinknul(const char *restrict link, char *restrict buf,
|
||||
size_t size);
|
||||
|
||||
|
||||
// Similar to readlink(2), but terminate the string.
|
||||
inline ssize_t
|
||||
readlinknul(const char *restrict link, char *restrict buf, size_t size)
|
||||
{
|
||||
size_t ulen;
|
||||
ssize_t slen;
|
||||
|
||||
slen = readlink(link, buf, size);
|
||||
if (slen == -1)
|
||||
return -1;
|
||||
|
||||
ulen = slen;
|
||||
if (ulen == size) {
|
||||
stpcpy(&buf[size-1], "");
|
||||
errno = E2BIG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
stpcpy(&buf[ulen], "");
|
||||
|
||||
return slen;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2009 , Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
|
||||
int
|
||||
get_gid(const char *gidstr, gid_t *gid)
|
||||
{
|
||||
char *end;
|
||||
long long val;
|
||||
|
||||
errno = 0;
|
||||
val = strtoll(gidstr, &end, 10);
|
||||
if ( ('\0' == *gidstr)
|
||||
|| ('\0' != *end)
|
||||
|| (0 != errno)
|
||||
|| (/*@+longintegral@*/val != (gid_t)val)/*@=longintegral@*/) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*gid = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2009 , Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -14,29 +13,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "string/sprintf.h"
|
||||
#include "atoi/getnum.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
|
||||
|
||||
int
|
||||
get_pid(const char *pidstr, pid_t *pid)
|
||||
{
|
||||
char *end;
|
||||
long long val;
|
||||
|
||||
errno = 0;
|
||||
val = strtoll(pidstr, &end, 10);
|
||||
if ( ('\0' == *pidstr)
|
||||
|| ('\0' != *end)
|
||||
|| (0 != errno)
|
||||
|| (val < 1)
|
||||
|| (/*@+longintegral@*/val != (pid_t)val)/*@=longintegral@*/) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*pid = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* If use passed in fd:4 as an argument, then return the
|
||||
* value '4', the fd to use.
|
||||
@@ -44,20 +24,12 @@ get_pid(const char *pidstr, pid_t *pid)
|
||||
*/
|
||||
int get_pidfd_from_fd(const char *pidfdstr)
|
||||
{
|
||||
char *end;
|
||||
long long val;
|
||||
int pidfd;
|
||||
struct stat st;
|
||||
dev_t proc_st_dev, proc_st_rdev;
|
||||
|
||||
errno = 0;
|
||||
val = strtoll(pidfdstr, &end, 10);
|
||||
if ( ('\0' == *pidfdstr)
|
||||
|| ('\0' != *end)
|
||||
|| (0 != errno)
|
||||
|| (val < 0)
|
||||
|| (/*@+longintegral@*/val != (int)val)/*@=longintegral@*/) {
|
||||
if (get_fd(pidfdstr, &pidfd) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (stat("/proc/self/uid_map", &st) < 0) {
|
||||
return -1;
|
||||
@@ -66,7 +38,7 @@ int get_pidfd_from_fd(const char *pidfdstr)
|
||||
proc_st_dev = st.st_dev;
|
||||
proc_st_rdev = st.st_rdev;
|
||||
|
||||
if (fstat(val, &st) < 0) {
|
||||
if (fstat(pidfd, &st) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -74,7 +46,7 @@ int get_pidfd_from_fd(const char *pidfdstr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (int)val;
|
||||
return pidfd;
|
||||
}
|
||||
|
||||
int open_pidfd(const char *pidstr)
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2009 , Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
|
||||
int
|
||||
get_uid(const char *uidstr, uid_t *uid)
|
||||
{
|
||||
char *end;
|
||||
long long val;
|
||||
|
||||
errno = 0;
|
||||
val = strtoll(uidstr, &end, 10);
|
||||
if ( ('\0' == *uidstr)
|
||||
|| ('\0' != *end)
|
||||
|| (0 != errno)
|
||||
|| (/*@+longintegral@*/val != (uid_t)val)/*@=longintegral@*/) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*uid = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
251
lib/getdate.c
251
lib/getdate.c
@@ -94,14 +94,16 @@
|
||||
# undef static
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "getdate.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strspn/stpspn.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* Some old versions of bison generate parsers that use bcopy.
|
||||
That loses on systems that don't provide the function, so we have
|
||||
@@ -213,7 +215,7 @@ static int yyRelSeconds;
|
||||
static int yyRelYear;
|
||||
|
||||
|
||||
#line 217 "getdate.c"
|
||||
#line 219 "getdate.c"
|
||||
|
||||
# ifndef YY_CAST
|
||||
# ifdef __cplusplus
|
||||
@@ -299,12 +301,12 @@ extern int yydebug;
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
union YYSTYPE
|
||||
{
|
||||
#line 147 "getdate.y"
|
||||
#line 149 "getdate.y"
|
||||
|
||||
int Number;
|
||||
enum _MERIDIAN Meridian;
|
||||
|
||||
#line 308 "getdate.c"
|
||||
#line 310 "getdate.c"
|
||||
|
||||
};
|
||||
typedef union YYSTYPE YYSTYPE;
|
||||
@@ -744,12 +746,12 @@ static const yytype_int8 yytranslate[] =
|
||||
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
|
||||
static const yytype_int16 yyrline[] =
|
||||
{
|
||||
0, 163, 163, 164, 167, 170, 173, 176, 179, 182,
|
||||
185, 191, 197, 206, 212, 224, 227, 231, 236, 240,
|
||||
244, 250, 254, 272, 278, 284, 288, 293, 297, 304,
|
||||
312, 315, 318, 321, 324, 327, 330, 333, 336, 339,
|
||||
342, 345, 348, 351, 354, 357, 360, 363, 366, 371,
|
||||
405, 408
|
||||
0, 165, 165, 166, 169, 172, 175, 178, 181, 184,
|
||||
187, 193, 199, 208, 214, 226, 229, 233, 238, 242,
|
||||
246, 252, 256, 274, 280, 286, 290, 295, 299, 306,
|
||||
314, 317, 320, 323, 326, 329, 332, 335, 338, 341,
|
||||
344, 347, 350, 353, 356, 359, 362, 365, 368, 373,
|
||||
407, 410
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1350,69 +1352,69 @@ yyreduce:
|
||||
switch (yyn)
|
||||
{
|
||||
case 4: /* item: time */
|
||||
#line 167 "getdate.y"
|
||||
#line 169 "getdate.y"
|
||||
{
|
||||
yyHaveTime++;
|
||||
}
|
||||
#line 1358 "getdate.c"
|
||||
#line 1360 "getdate.c"
|
||||
break;
|
||||
|
||||
case 5: /* item: zone */
|
||||
#line 170 "getdate.y"
|
||||
#line 172 "getdate.y"
|
||||
{
|
||||
yyHaveZone++;
|
||||
}
|
||||
#line 1366 "getdate.c"
|
||||
#line 1368 "getdate.c"
|
||||
break;
|
||||
|
||||
case 6: /* item: date */
|
||||
#line 173 "getdate.y"
|
||||
#line 175 "getdate.y"
|
||||
{
|
||||
yyHaveDate++;
|
||||
}
|
||||
#line 1374 "getdate.c"
|
||||
#line 1376 "getdate.c"
|
||||
break;
|
||||
|
||||
case 7: /* item: day */
|
||||
#line 176 "getdate.y"
|
||||
#line 178 "getdate.y"
|
||||
{
|
||||
yyHaveDay++;
|
||||
}
|
||||
#line 1382 "getdate.c"
|
||||
#line 1384 "getdate.c"
|
||||
break;
|
||||
|
||||
case 8: /* item: rel */
|
||||
#line 179 "getdate.y"
|
||||
#line 181 "getdate.y"
|
||||
{
|
||||
yyHaveRel++;
|
||||
}
|
||||
#line 1390 "getdate.c"
|
||||
#line 1392 "getdate.c"
|
||||
break;
|
||||
|
||||
case 10: /* time: tUNUMBER tMERIDIAN */
|
||||
#line 185 "getdate.y"
|
||||
#line 187 "getdate.y"
|
||||
{
|
||||
yyHour = (yyvsp[-1].Number);
|
||||
yyMinutes = 0;
|
||||
yySeconds = 0;
|
||||
yyMeridian = (yyvsp[0].Meridian);
|
||||
}
|
||||
#line 1401 "getdate.c"
|
||||
#line 1403 "getdate.c"
|
||||
break;
|
||||
|
||||
case 11: /* time: tUNUMBER ':' tUNUMBER o_merid */
|
||||
#line 191 "getdate.y"
|
||||
#line 193 "getdate.y"
|
||||
{
|
||||
yyHour = (yyvsp[-3].Number);
|
||||
yyMinutes = (yyvsp[-1].Number);
|
||||
yySeconds = 0;
|
||||
yyMeridian = (yyvsp[0].Meridian);
|
||||
}
|
||||
#line 1412 "getdate.c"
|
||||
#line 1414 "getdate.c"
|
||||
break;
|
||||
|
||||
case 12: /* time: tUNUMBER ':' tUNUMBER tSNUMBER */
|
||||
#line 197 "getdate.y"
|
||||
#line 199 "getdate.y"
|
||||
{
|
||||
yyHour = (yyvsp[-3].Number);
|
||||
yyMinutes = (yyvsp[-1].Number);
|
||||
@@ -1422,22 +1424,22 @@ yyreduce:
|
||||
? -(yyvsp[0].Number) % 100 + (-(yyvsp[0].Number) / 100) * 60
|
||||
: - ((yyvsp[0].Number) % 100 + ((yyvsp[0].Number) / 100) * 60));
|
||||
}
|
||||
#line 1426 "getdate.c"
|
||||
#line 1428 "getdate.c"
|
||||
break;
|
||||
|
||||
case 13: /* time: tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid */
|
||||
#line 206 "getdate.y"
|
||||
#line 208 "getdate.y"
|
||||
{
|
||||
yyHour = (yyvsp[-5].Number);
|
||||
yyMinutes = (yyvsp[-3].Number);
|
||||
yySeconds = (yyvsp[-1].Number);
|
||||
yyMeridian = (yyvsp[0].Meridian);
|
||||
}
|
||||
#line 1437 "getdate.c"
|
||||
#line 1439 "getdate.c"
|
||||
break;
|
||||
|
||||
case 14: /* time: tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER */
|
||||
#line 212 "getdate.y"
|
||||
#line 214 "getdate.y"
|
||||
{
|
||||
yyHour = (yyvsp[-5].Number);
|
||||
yyMinutes = (yyvsp[-3].Number);
|
||||
@@ -1448,71 +1450,71 @@ yyreduce:
|
||||
? -(yyvsp[0].Number) % 100 + (-(yyvsp[0].Number) / 100) * 60
|
||||
: - ((yyvsp[0].Number) % 100 + ((yyvsp[0].Number) / 100) * 60));
|
||||
}
|
||||
#line 1452 "getdate.c"
|
||||
#line 1454 "getdate.c"
|
||||
break;
|
||||
|
||||
case 15: /* zone: tZONE */
|
||||
#line 224 "getdate.y"
|
||||
#line 226 "getdate.y"
|
||||
{
|
||||
yyTimezone = (yyvsp[0].Number);
|
||||
}
|
||||
#line 1460 "getdate.c"
|
||||
#line 1462 "getdate.c"
|
||||
break;
|
||||
|
||||
case 16: /* zone: tDAYZONE */
|
||||
#line 227 "getdate.y"
|
||||
#line 229 "getdate.y"
|
||||
{
|
||||
yyTimezone = (yyvsp[0].Number) - 60;
|
||||
}
|
||||
#line 1468 "getdate.c"
|
||||
#line 1470 "getdate.c"
|
||||
break;
|
||||
|
||||
case 17: /* zone: tZONE tDST */
|
||||
#line 231 "getdate.y"
|
||||
#line 233 "getdate.y"
|
||||
{
|
||||
yyTimezone = (yyvsp[-1].Number) - 60;
|
||||
}
|
||||
#line 1476 "getdate.c"
|
||||
#line 1478 "getdate.c"
|
||||
break;
|
||||
|
||||
case 18: /* day: tDAY */
|
||||
#line 236 "getdate.y"
|
||||
#line 238 "getdate.y"
|
||||
{
|
||||
yyDayOrdinal = 1;
|
||||
yyDayNumber = (yyvsp[0].Number);
|
||||
}
|
||||
#line 1485 "getdate.c"
|
||||
#line 1487 "getdate.c"
|
||||
break;
|
||||
|
||||
case 19: /* day: tDAY ',' */
|
||||
#line 240 "getdate.y"
|
||||
#line 242 "getdate.y"
|
||||
{
|
||||
yyDayOrdinal = 1;
|
||||
yyDayNumber = (yyvsp[-1].Number);
|
||||
}
|
||||
#line 1494 "getdate.c"
|
||||
#line 1496 "getdate.c"
|
||||
break;
|
||||
|
||||
case 20: /* day: tUNUMBER tDAY */
|
||||
#line 244 "getdate.y"
|
||||
#line 246 "getdate.y"
|
||||
{
|
||||
yyDayOrdinal = (yyvsp[-1].Number);
|
||||
yyDayNumber = (yyvsp[0].Number);
|
||||
}
|
||||
#line 1503 "getdate.c"
|
||||
#line 1505 "getdate.c"
|
||||
break;
|
||||
|
||||
case 21: /* date: tUNUMBER '/' tUNUMBER */
|
||||
#line 250 "getdate.y"
|
||||
#line 252 "getdate.y"
|
||||
{
|
||||
yyMonth = (yyvsp[-2].Number);
|
||||
yyDay = (yyvsp[0].Number);
|
||||
}
|
||||
#line 1512 "getdate.c"
|
||||
#line 1514 "getdate.c"
|
||||
break;
|
||||
|
||||
case 22: /* date: tUNUMBER '/' tUNUMBER '/' tUNUMBER */
|
||||
#line 254 "getdate.y"
|
||||
#line 256 "getdate.y"
|
||||
{
|
||||
/* Interpret as YYYY/MM/DD if $1 >= 1000, otherwise as MM/DD/YY.
|
||||
The goal in recognizing YYYY/MM/DD is solely to support legacy
|
||||
@@ -1531,71 +1533,71 @@ yyreduce:
|
||||
yyYear = (yyvsp[0].Number);
|
||||
}
|
||||
}
|
||||
#line 1535 "getdate.c"
|
||||
#line 1537 "getdate.c"
|
||||
break;
|
||||
|
||||
case 23: /* date: tUNUMBER tSNUMBER tSNUMBER */
|
||||
#line 272 "getdate.y"
|
||||
#line 274 "getdate.y"
|
||||
{
|
||||
/* ISO 8601 format. yyyy-mm-dd. */
|
||||
yyYear = (yyvsp[-2].Number);
|
||||
yyMonth = -(yyvsp[-1].Number);
|
||||
yyDay = -(yyvsp[0].Number);
|
||||
}
|
||||
#line 1546 "getdate.c"
|
||||
#line 1548 "getdate.c"
|
||||
break;
|
||||
|
||||
case 24: /* date: tUNUMBER tMONTH tSNUMBER */
|
||||
#line 278 "getdate.y"
|
||||
#line 280 "getdate.y"
|
||||
{
|
||||
/* e.g. 17-JUN-1992. */
|
||||
yyDay = (yyvsp[-2].Number);
|
||||
yyMonth = (yyvsp[-1].Number);
|
||||
yyYear = -(yyvsp[0].Number);
|
||||
}
|
||||
#line 1557 "getdate.c"
|
||||
#line 1559 "getdate.c"
|
||||
break;
|
||||
|
||||
case 25: /* date: tMONTH tUNUMBER */
|
||||
#line 284 "getdate.y"
|
||||
#line 286 "getdate.y"
|
||||
{
|
||||
yyMonth = (yyvsp[-1].Number);
|
||||
yyDay = (yyvsp[0].Number);
|
||||
}
|
||||
#line 1566 "getdate.c"
|
||||
#line 1568 "getdate.c"
|
||||
break;
|
||||
|
||||
case 26: /* date: tMONTH tUNUMBER ',' tUNUMBER */
|
||||
#line 288 "getdate.y"
|
||||
#line 290 "getdate.y"
|
||||
{
|
||||
yyMonth = (yyvsp[-3].Number);
|
||||
yyDay = (yyvsp[-2].Number);
|
||||
yyYear = (yyvsp[0].Number);
|
||||
}
|
||||
#line 1576 "getdate.c"
|
||||
#line 1578 "getdate.c"
|
||||
break;
|
||||
|
||||
case 27: /* date: tUNUMBER tMONTH */
|
||||
#line 293 "getdate.y"
|
||||
#line 295 "getdate.y"
|
||||
{
|
||||
yyMonth = (yyvsp[0].Number);
|
||||
yyDay = (yyvsp[-1].Number);
|
||||
}
|
||||
#line 1585 "getdate.c"
|
||||
#line 1587 "getdate.c"
|
||||
break;
|
||||
|
||||
case 28: /* date: tUNUMBER tMONTH tUNUMBER */
|
||||
#line 297 "getdate.y"
|
||||
#line 299 "getdate.y"
|
||||
{
|
||||
yyMonth = (yyvsp[-1].Number);
|
||||
yyDay = (yyvsp[-2].Number);
|
||||
yyYear = (yyvsp[0].Number);
|
||||
}
|
||||
#line 1595 "getdate.c"
|
||||
#line 1597 "getdate.c"
|
||||
break;
|
||||
|
||||
case 29: /* rel: relunit tAGO */
|
||||
#line 304 "getdate.y"
|
||||
#line 306 "getdate.y"
|
||||
{
|
||||
yyRelSeconds = -yyRelSeconds;
|
||||
yyRelMinutes = -yyRelMinutes;
|
||||
@@ -1604,155 +1606,155 @@ yyreduce:
|
||||
yyRelMonth = -yyRelMonth;
|
||||
yyRelYear = -yyRelYear;
|
||||
}
|
||||
#line 1608 "getdate.c"
|
||||
#line 1610 "getdate.c"
|
||||
break;
|
||||
|
||||
case 31: /* relunit: tUNUMBER tYEAR_UNIT */
|
||||
#line 315 "getdate.y"
|
||||
#line 317 "getdate.y"
|
||||
{
|
||||
yyRelYear += (yyvsp[-1].Number) * (yyvsp[0].Number);
|
||||
}
|
||||
#line 1616 "getdate.c"
|
||||
#line 1618 "getdate.c"
|
||||
break;
|
||||
|
||||
case 32: /* relunit: tSNUMBER tYEAR_UNIT */
|
||||
#line 318 "getdate.y"
|
||||
#line 320 "getdate.y"
|
||||
{
|
||||
yyRelYear += (yyvsp[-1].Number) * (yyvsp[0].Number);
|
||||
}
|
||||
#line 1624 "getdate.c"
|
||||
#line 1626 "getdate.c"
|
||||
break;
|
||||
|
||||
case 33: /* relunit: tYEAR_UNIT */
|
||||
#line 321 "getdate.y"
|
||||
#line 323 "getdate.y"
|
||||
{
|
||||
yyRelYear += (yyvsp[0].Number);
|
||||
}
|
||||
#line 1632 "getdate.c"
|
||||
#line 1634 "getdate.c"
|
||||
break;
|
||||
|
||||
case 34: /* relunit: tUNUMBER tMONTH_UNIT */
|
||||
#line 324 "getdate.y"
|
||||
#line 326 "getdate.y"
|
||||
{
|
||||
yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number);
|
||||
}
|
||||
#line 1640 "getdate.c"
|
||||
#line 1642 "getdate.c"
|
||||
break;
|
||||
|
||||
case 35: /* relunit: tSNUMBER tMONTH_UNIT */
|
||||
#line 327 "getdate.y"
|
||||
#line 329 "getdate.y"
|
||||
{
|
||||
yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number);
|
||||
}
|
||||
#line 1648 "getdate.c"
|
||||
#line 1650 "getdate.c"
|
||||
break;
|
||||
|
||||
case 36: /* relunit: tMONTH_UNIT */
|
||||
#line 330 "getdate.y"
|
||||
#line 332 "getdate.y"
|
||||
{
|
||||
yyRelMonth += (yyvsp[0].Number);
|
||||
}
|
||||
#line 1656 "getdate.c"
|
||||
#line 1658 "getdate.c"
|
||||
break;
|
||||
|
||||
case 37: /* relunit: tUNUMBER tDAY_UNIT */
|
||||
#line 333 "getdate.y"
|
||||
#line 335 "getdate.y"
|
||||
{
|
||||
yyRelDay += (yyvsp[-1].Number) * (yyvsp[0].Number);
|
||||
}
|
||||
#line 1664 "getdate.c"
|
||||
#line 1666 "getdate.c"
|
||||
break;
|
||||
|
||||
case 38: /* relunit: tSNUMBER tDAY_UNIT */
|
||||
#line 336 "getdate.y"
|
||||
#line 338 "getdate.y"
|
||||
{
|
||||
yyRelDay += (yyvsp[-1].Number) * (yyvsp[0].Number);
|
||||
}
|
||||
#line 1672 "getdate.c"
|
||||
#line 1674 "getdate.c"
|
||||
break;
|
||||
|
||||
case 39: /* relunit: tDAY_UNIT */
|
||||
#line 339 "getdate.y"
|
||||
#line 341 "getdate.y"
|
||||
{
|
||||
yyRelDay += (yyvsp[0].Number);
|
||||
}
|
||||
#line 1680 "getdate.c"
|
||||
#line 1682 "getdate.c"
|
||||
break;
|
||||
|
||||
case 40: /* relunit: tUNUMBER tHOUR_UNIT */
|
||||
#line 342 "getdate.y"
|
||||
#line 344 "getdate.y"
|
||||
{
|
||||
yyRelHour += (yyvsp[-1].Number) * (yyvsp[0].Number);
|
||||
}
|
||||
#line 1688 "getdate.c"
|
||||
#line 1690 "getdate.c"
|
||||
break;
|
||||
|
||||
case 41: /* relunit: tSNUMBER tHOUR_UNIT */
|
||||
#line 345 "getdate.y"
|
||||
#line 347 "getdate.y"
|
||||
{
|
||||
yyRelHour += (yyvsp[-1].Number) * (yyvsp[0].Number);
|
||||
}
|
||||
#line 1696 "getdate.c"
|
||||
#line 1698 "getdate.c"
|
||||
break;
|
||||
|
||||
case 42: /* relunit: tHOUR_UNIT */
|
||||
#line 348 "getdate.y"
|
||||
#line 350 "getdate.y"
|
||||
{
|
||||
yyRelHour += (yyvsp[0].Number);
|
||||
}
|
||||
#line 1704 "getdate.c"
|
||||
#line 1706 "getdate.c"
|
||||
break;
|
||||
|
||||
case 43: /* relunit: tUNUMBER tMINUTE_UNIT */
|
||||
#line 351 "getdate.y"
|
||||
#line 353 "getdate.y"
|
||||
{
|
||||
yyRelMinutes += (yyvsp[-1].Number) * (yyvsp[0].Number);
|
||||
}
|
||||
#line 1712 "getdate.c"
|
||||
#line 1714 "getdate.c"
|
||||
break;
|
||||
|
||||
case 44: /* relunit: tSNUMBER tMINUTE_UNIT */
|
||||
#line 354 "getdate.y"
|
||||
#line 356 "getdate.y"
|
||||
{
|
||||
yyRelMinutes += (yyvsp[-1].Number) * (yyvsp[0].Number);
|
||||
}
|
||||
#line 1720 "getdate.c"
|
||||
#line 1722 "getdate.c"
|
||||
break;
|
||||
|
||||
case 45: /* relunit: tMINUTE_UNIT */
|
||||
#line 357 "getdate.y"
|
||||
#line 359 "getdate.y"
|
||||
{
|
||||
yyRelMinutes += (yyvsp[0].Number);
|
||||
}
|
||||
#line 1728 "getdate.c"
|
||||
#line 1730 "getdate.c"
|
||||
break;
|
||||
|
||||
case 46: /* relunit: tUNUMBER tSEC_UNIT */
|
||||
#line 360 "getdate.y"
|
||||
#line 362 "getdate.y"
|
||||
{
|
||||
yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number);
|
||||
}
|
||||
#line 1736 "getdate.c"
|
||||
#line 1738 "getdate.c"
|
||||
break;
|
||||
|
||||
case 47: /* relunit: tSNUMBER tSEC_UNIT */
|
||||
#line 363 "getdate.y"
|
||||
#line 365 "getdate.y"
|
||||
{
|
||||
yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number);
|
||||
}
|
||||
#line 1744 "getdate.c"
|
||||
#line 1746 "getdate.c"
|
||||
break;
|
||||
|
||||
case 48: /* relunit: tSEC_UNIT */
|
||||
#line 366 "getdate.y"
|
||||
#line 368 "getdate.y"
|
||||
{
|
||||
yyRelSeconds += (yyvsp[0].Number);
|
||||
}
|
||||
#line 1752 "getdate.c"
|
||||
#line 1754 "getdate.c"
|
||||
break;
|
||||
|
||||
case 49: /* number: tUNUMBER */
|
||||
#line 372 "getdate.y"
|
||||
#line 374 "getdate.y"
|
||||
{
|
||||
if ((yyHaveTime != 0) && (yyHaveDate != 0) && (yyHaveRel == 0))
|
||||
yyYear = (yyvsp[0].Number);
|
||||
@@ -1783,27 +1785,27 @@ yyreduce:
|
||||
}
|
||||
}
|
||||
}
|
||||
#line 1787 "getdate.c"
|
||||
#line 1789 "getdate.c"
|
||||
break;
|
||||
|
||||
case 50: /* o_merid: %empty */
|
||||
#line 405 "getdate.y"
|
||||
#line 407 "getdate.y"
|
||||
{
|
||||
(yyval.Meridian) = MER24;
|
||||
}
|
||||
#line 1795 "getdate.c"
|
||||
#line 1797 "getdate.c"
|
||||
break;
|
||||
|
||||
case 51: /* o_merid: tMERIDIAN */
|
||||
#line 409 "getdate.y"
|
||||
#line 411 "getdate.y"
|
||||
{
|
||||
(yyval.Meridian) = (yyvsp[0].Meridian);
|
||||
}
|
||||
#line 1803 "getdate.c"
|
||||
#line 1805 "getdate.c"
|
||||
break;
|
||||
|
||||
|
||||
#line 1807 "getdate.c"
|
||||
#line 1809 "getdate.c"
|
||||
|
||||
default: break;
|
||||
}
|
||||
@@ -1996,7 +1998,7 @@ yyreturnlab:
|
||||
return yyresult;
|
||||
}
|
||||
|
||||
#line 414 "getdate.y"
|
||||
#line 416 "getdate.y"
|
||||
|
||||
|
||||
/* Month and day table. */
|
||||
@@ -2211,16 +2213,16 @@ static int LookupWord (char *buff)
|
||||
bool abbrev;
|
||||
|
||||
/* Make it lowercase. */
|
||||
for (p = buff; '\0' != *p; p++)
|
||||
for (p = buff; !streq(p, ""); p++)
|
||||
if (isupper (*p))
|
||||
*p = tolower (*p);
|
||||
|
||||
if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0)
|
||||
if (streq(buff, "am") || streq(buff, "a.m."))
|
||||
{
|
||||
yylval.Meridian = MERam;
|
||||
return tMERIDIAN;
|
||||
}
|
||||
if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0)
|
||||
if (streq(buff, "pm") || streq(buff, "p.m."))
|
||||
{
|
||||
yylval.Meridian = MERpm;
|
||||
return tMERIDIAN;
|
||||
@@ -2232,7 +2234,7 @@ static int LookupWord (char *buff)
|
||||
else if (strlen (buff) == 4 && buff[3] == '.')
|
||||
{
|
||||
abbrev = true;
|
||||
buff[3] = '\0';
|
||||
stpcpy(&buff[3], "");
|
||||
}
|
||||
else
|
||||
abbrev = false;
|
||||
@@ -2247,7 +2249,7 @@ static int LookupWord (char *buff)
|
||||
return tp->type;
|
||||
}
|
||||
}
|
||||
else if (strcmp (buff, tp->name) == 0)
|
||||
else if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -2255,17 +2257,17 @@ static int LookupWord (char *buff)
|
||||
}
|
||||
|
||||
for (tp = TimezoneTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
}
|
||||
|
||||
if (strcmp (buff, "dst") == 0)
|
||||
if (streq(buff, "dst"))
|
||||
return tDST;
|
||||
|
||||
for (tp = UnitsTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -2275,9 +2277,9 @@ static int LookupWord (char *buff)
|
||||
i = strlen (buff) - 1;
|
||||
if (buff[i] == 's')
|
||||
{
|
||||
buff[i] = '\0';
|
||||
stpcpy(&buff[i], "");
|
||||
for (tp = UnitsTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -2286,7 +2288,7 @@ static int LookupWord (char *buff)
|
||||
}
|
||||
|
||||
for (tp = OtherTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -2296,7 +2298,7 @@ static int LookupWord (char *buff)
|
||||
if (buff[1] == '\0' && isalpha (*buff))
|
||||
{
|
||||
for (tp = MilitaryTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -2304,15 +2306,15 @@ static int LookupWord (char *buff)
|
||||
}
|
||||
|
||||
/* Drop out any periods and try the timezone table again. */
|
||||
for (i = 0, p = q = buff; '\0' != *q; q++)
|
||||
for (i = 0, p = q = buff; !streq(q, ""); q++)
|
||||
if (*q != '.')
|
||||
*p++ = *q;
|
||||
else
|
||||
i++;
|
||||
*p = '\0';
|
||||
stpcpy(p, "");
|
||||
if (0 != i)
|
||||
for (tp = TimezoneTable; NULL != tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -2332,8 +2334,7 @@ yylex (void)
|
||||
|
||||
for (;;)
|
||||
{
|
||||
while (isspace (*yyInput))
|
||||
yyInput++;
|
||||
yyInput = stpspn(yyInput, " \t");
|
||||
|
||||
if (isdigit (c = *yyInput) || c == '-' || c == '+')
|
||||
{
|
||||
@@ -2358,7 +2359,7 @@ yylex (void)
|
||||
for (p = buff; (c = *yyInput++, isalpha (c)) || c == '.';)
|
||||
if (p < &buff[sizeof buff - 1])
|
||||
*p++ = c;
|
||||
*p = '\0';
|
||||
stpcpy(p, "");
|
||||
yyInput--;
|
||||
return LookupWord (buff);
|
||||
}
|
||||
@@ -2407,7 +2408,7 @@ time_t get_date (const char *p, const time_t *now)
|
||||
time_t Start;
|
||||
|
||||
yyInput = p;
|
||||
Start = now ? *now : time ((time_t *) NULL);
|
||||
Start = now ? *now : time(NULL);
|
||||
tmp = localtime (&Start);
|
||||
yyYear = tmp->tm_year + TM_YEAR_ORIGIN;
|
||||
yyMonth = tmp->tm_mon + 1;
|
||||
@@ -2521,7 +2522,7 @@ main(void)
|
||||
buff[MAX_BUFF_LEN] = 0;
|
||||
while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
|
||||
{
|
||||
d = get_date (buff, (time_t *) NULL);
|
||||
d = get_date(buff, NULL);
|
||||
if (d == -1)
|
||||
(void) printf ("Bad format - couldn't convert.\n");
|
||||
else
|
||||
|
||||
@@ -24,14 +24,16 @@
|
||||
# undef static
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "getdate.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strspn/stpspn.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* Some old versions of bison generate parsers that use bcopy.
|
||||
That loses on systems that don't provide the function, so we have
|
||||
@@ -625,16 +627,16 @@ static int LookupWord (char *buff)
|
||||
bool abbrev;
|
||||
|
||||
/* Make it lowercase. */
|
||||
for (p = buff; '\0' != *p; p++)
|
||||
for (p = buff; !streq(p, ""); p++)
|
||||
if (isupper (*p))
|
||||
*p = tolower (*p);
|
||||
|
||||
if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0)
|
||||
if (streq(buff, "am") || streq(buff, "a.m."))
|
||||
{
|
||||
yylval.Meridian = MERam;
|
||||
return tMERIDIAN;
|
||||
}
|
||||
if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0)
|
||||
if (streq(buff, "pm") || streq(buff, "p.m."))
|
||||
{
|
||||
yylval.Meridian = MERpm;
|
||||
return tMERIDIAN;
|
||||
@@ -646,7 +648,7 @@ static int LookupWord (char *buff)
|
||||
else if (strlen (buff) == 4 && buff[3] == '.')
|
||||
{
|
||||
abbrev = true;
|
||||
buff[3] = '\0';
|
||||
stpcpy(&buff[3], "");
|
||||
}
|
||||
else
|
||||
abbrev = false;
|
||||
@@ -661,7 +663,7 @@ static int LookupWord (char *buff)
|
||||
return tp->type;
|
||||
}
|
||||
}
|
||||
else if (strcmp (buff, tp->name) == 0)
|
||||
else if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -669,17 +671,17 @@ static int LookupWord (char *buff)
|
||||
}
|
||||
|
||||
for (tp = TimezoneTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
}
|
||||
|
||||
if (strcmp (buff, "dst") == 0)
|
||||
if (streq(buff, "dst"))
|
||||
return tDST;
|
||||
|
||||
for (tp = UnitsTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -689,9 +691,9 @@ static int LookupWord (char *buff)
|
||||
i = strlen (buff) - 1;
|
||||
if (buff[i] == 's')
|
||||
{
|
||||
buff[i] = '\0';
|
||||
stpcpy(&buff[i], "");
|
||||
for (tp = UnitsTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -700,7 +702,7 @@ static int LookupWord (char *buff)
|
||||
}
|
||||
|
||||
for (tp = OtherTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -710,7 +712,7 @@ static int LookupWord (char *buff)
|
||||
if (buff[1] == '\0' && isalpha (*buff))
|
||||
{
|
||||
for (tp = MilitaryTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -718,15 +720,15 @@ static int LookupWord (char *buff)
|
||||
}
|
||||
|
||||
/* Drop out any periods and try the timezone table again. */
|
||||
for (i = 0, p = q = buff; '\0' != *q; q++)
|
||||
for (i = 0, p = q = buff; !streq(q, ""); q++)
|
||||
if (*q != '.')
|
||||
*p++ = *q;
|
||||
else
|
||||
i++;
|
||||
*p = '\0';
|
||||
stpcpy(p, "");
|
||||
if (0 != i)
|
||||
for (tp = TimezoneTable; NULL != tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -746,8 +748,7 @@ yylex (void)
|
||||
|
||||
for (;;)
|
||||
{
|
||||
while (isspace (*yyInput))
|
||||
yyInput++;
|
||||
yyInput = stpspn(yyInput, " \t");
|
||||
|
||||
if (isdigit (c = *yyInput) || c == '-' || c == '+')
|
||||
{
|
||||
@@ -772,7 +773,7 @@ yylex (void)
|
||||
for (p = buff; (c = *yyInput++, isalpha (c)) || c == '.';)
|
||||
if (p < &buff[sizeof buff - 1])
|
||||
*p++ = c;
|
||||
*p = '\0';
|
||||
stpcpy(p, "");
|
||||
yyInput--;
|
||||
return LookupWord (buff);
|
||||
}
|
||||
@@ -821,7 +822,7 @@ time_t get_date (const char *p, const time_t *now)
|
||||
time_t Start;
|
||||
|
||||
yyInput = p;
|
||||
Start = now ? *now : time ((time_t *) NULL);
|
||||
Start = now ? *now : time(NULL);
|
||||
tmp = localtime (&Start);
|
||||
yyYear = tmp->tm_year + TM_YEAR_ORIGIN;
|
||||
yyMonth = tmp->tm_mon + 1;
|
||||
@@ -935,7 +936,7 @@ main(void)
|
||||
buff[MAX_BUFF_LEN] = 0;
|
||||
while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
|
||||
{
|
||||
d = get_date (buff, (time_t *) NULL);
|
||||
d = get_date(buff, NULL);
|
||||
if (d == -1)
|
||||
(void) printf ("Bad format - couldn't convert.\n");
|
||||
else
|
||||
|
||||
75
lib/getdef.c
75
lib/getdef.c
@@ -11,22 +11,30 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef USE_ECONF
|
||||
#include <libeconf.h>
|
||||
#endif
|
||||
|
||||
#include "alloc.h"
|
||||
#include "atoi/str2i.h"
|
||||
#include "atoi/a2i/a2s.h"
|
||||
#include "atoi/a2i/a2u.h"
|
||||
#include "atoi/str2i/str2u.h"
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "prototypes.h"
|
||||
#include "shadowlog_internal.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strcmp/strcaseeq.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strspn/stpspn.h"
|
||||
#include "string/strspn/stprspn.h"
|
||||
#include "string/strtok/stpsep.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -151,7 +159,6 @@ static struct itemdef def_table[] = {
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
#define NUMKNOWNDEFS (sizeof(knowndef_table)/sizeof(knowndef_table[0]))
|
||||
static struct itemdef knowndef_table[] = {
|
||||
#ifdef USE_PAM
|
||||
PAMDEFS
|
||||
@@ -220,7 +227,7 @@ bool getdef_bool (const char *item)
|
||||
return false;
|
||||
}
|
||||
|
||||
return (strcasecmp (d->value, "yes") == 0);
|
||||
return strcaseeq(d->value, "yes");
|
||||
}
|
||||
|
||||
|
||||
@@ -232,10 +239,11 @@ bool getdef_bool (const char *item)
|
||||
* values are handled.
|
||||
*/
|
||||
|
||||
int getdef_num (const char *item, int dflt)
|
||||
int
|
||||
getdef_num(const char *item, int dflt)
|
||||
{
|
||||
struct itemdef *d;
|
||||
long val;
|
||||
int val;
|
||||
struct itemdef *d;
|
||||
|
||||
if (!def_loaded) {
|
||||
def_load ();
|
||||
@@ -246,9 +254,7 @@ int getdef_num (const char *item, int dflt)
|
||||
return dflt;
|
||||
}
|
||||
|
||||
if ( (str2sl(&val, d->value) == -1)
|
||||
|| (val > INT_MAX)
|
||||
|| (val < -1)) {
|
||||
if (a2si(&val, d->value, NULL, 0, -1, INT_MAX) == -1) {
|
||||
fprintf (shadow_logfd,
|
||||
_("configuration error - cannot parse %s value: '%s'"),
|
||||
item, d->value);
|
||||
@@ -267,10 +273,11 @@ int getdef_num (const char *item, int dflt)
|
||||
* values are handled.
|
||||
*/
|
||||
|
||||
unsigned int getdef_unum (const char *item, unsigned int dflt)
|
||||
unsigned int
|
||||
getdef_unum(const char *item, unsigned int dflt)
|
||||
{
|
||||
struct itemdef *d;
|
||||
long val;
|
||||
unsigned int val;
|
||||
struct itemdef *d;
|
||||
|
||||
if (!def_loaded) {
|
||||
def_load ();
|
||||
@@ -281,9 +288,7 @@ unsigned int getdef_unum (const char *item, unsigned int dflt)
|
||||
return dflt;
|
||||
}
|
||||
|
||||
if ( (str2sl(&val, d->value) == -1)
|
||||
|| (val < 0)
|
||||
|| (val > INT_MAX)) {
|
||||
if (a2ui(&val, d->value, NULL, 0, 0, UINT_MAX) == -1) {
|
||||
fprintf (shadow_logfd,
|
||||
_("configuration error - cannot parse %s value: '%s'"),
|
||||
item, d->value);
|
||||
@@ -316,7 +321,7 @@ long getdef_long (const char *item, long dflt)
|
||||
return dflt;
|
||||
}
|
||||
|
||||
if (str2sl(&val, d->value) == -1 || val < -1) {
|
||||
if (a2sl(&val, d->value, NULL, 0, -1, LONG_MAX) == -1) {
|
||||
fprintf (shadow_logfd,
|
||||
_("configuration error - cannot parse %s value: '%s'"),
|
||||
item, d->value);
|
||||
@@ -416,7 +421,7 @@ static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name, cons
|
||||
*/
|
||||
|
||||
for (ptr = def_table; NULL != ptr->name; ptr++) {
|
||||
if (strcmp (ptr->name, name) == 0) {
|
||||
if (streq(ptr->name, name)) {
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
@@ -426,7 +431,7 @@ static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name, cons
|
||||
*/
|
||||
|
||||
for (ptr = knowndef_table; NULL != ptr->name; ptr++) {
|
||||
if (strcmp (ptr->name, name) == 0) {
|
||||
if (streq(ptr->name, name)) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@@ -526,7 +531,6 @@ static void def_load (void)
|
||||
#else /* USE_ECONF */
|
||||
static void def_load (void)
|
||||
{
|
||||
int i;
|
||||
FILE *fp;
|
||||
char buf[1024], *name, *value, *s;
|
||||
|
||||
@@ -558,28 +562,21 @@ static void def_load (void)
|
||||
/*
|
||||
* Trim trailing whitespace.
|
||||
*/
|
||||
for (i = (ptrdiff_t) strlen (buf) - 1; i >= 0; --i) {
|
||||
if (!isspace (buf[i])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
buf[i] = '\0';
|
||||
stpcpy(stprspn(buf, " \t\n"), "");
|
||||
|
||||
/*
|
||||
* Break the line into two fields.
|
||||
*/
|
||||
name = buf + strspn (buf, " \t"); /* first nonwhite */
|
||||
if (*name == '\0' || *name == '#')
|
||||
name = stpspn(buf, " \t"); /* first nonwhite */
|
||||
if (streq(name, "") || *name == '#')
|
||||
continue; /* comment or empty */
|
||||
|
||||
s = name + strcspn (name, " \t"); /* end of field */
|
||||
if (*s == '\0')
|
||||
s = stpsep(name, " \t"); /* next field */
|
||||
if (s == NULL)
|
||||
continue; /* only 1 field?? */
|
||||
|
||||
*s++ = '\0';
|
||||
value = s + strspn (s, " \"\t"); /* next nonwhite */
|
||||
*(value + strcspn (value, "\"")) = '\0';
|
||||
value = stpspn(s, " \"\t"); /* next nonwhite */
|
||||
stpsep(value, "\"");
|
||||
|
||||
/*
|
||||
* Store the value in def_table.
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 1991 - 1994, Julianne Frances Haugh
|
||||
* SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz
|
||||
* SPDX-FileCopyrightText: 2000 - 2006, Tomasz Kłoczko
|
||||
* SPDX-FileCopyrightText: 2007 - 2009, Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 1991-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-2000, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2000-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -14,30 +13,27 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <grp.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "atoi/getnum.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
|
||||
/*
|
||||
* getgr_nam_gid - Return a pointer to the group specified by a string.
|
||||
* The string may be a valid GID or a valid groupname.
|
||||
* If the group does not exist on the system, NULL is returned.
|
||||
*/
|
||||
extern /*@only@*//*@null@*/struct group *getgr_nam_gid (/*@null@*/const char *grname)
|
||||
extern /*@only@*//*@null@*/struct group *
|
||||
getgr_nam_gid(/*@null@*/const char *grname)
|
||||
{
|
||||
char *end;
|
||||
long long gid;
|
||||
gid_t gid;
|
||||
|
||||
if (NULL == grname) {
|
||||
if (NULL == grname)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
gid = strtoll(grname, &end, 10);
|
||||
if ( ('\0' != *grname)
|
||||
&& ('\0' == *end)
|
||||
&& (0 == errno)
|
||||
&& (/*@+longintegral@*/gid == (gid_t)gid)/*@=longintegral@*/) {
|
||||
return xgetgrgid (gid);
|
||||
}
|
||||
return xgetgrnam (grname);
|
||||
if (get_gid(grname, &gid) == 0)
|
||||
return xgetgrgid(gid);
|
||||
return xgetgrnam(grname);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,10 @@
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "atoi/a2i.h"
|
||||
#include "atoi/a2i/a2u.h"
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -53,7 +54,7 @@ getrange(const char *range,
|
||||
return 0; /* <long> */
|
||||
|
||||
case '-':
|
||||
if ('\0' == *end)
|
||||
if (streq(end, ""))
|
||||
return 0; /* <long>- */
|
||||
parse_max:
|
||||
if (!isdigit((unsigned char) *end))
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "atoi/a2i.h"
|
||||
#include "atoi/a2i/a2i.h"
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "shadowlog.h"
|
||||
|
||||
@@ -15,12 +15,14 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "alloc/calloc.h"
|
||||
#include "alloc/malloc.h"
|
||||
#include "commonio.h"
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "groupio.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
static /*@null@*/struct commonio_entry *merge_group_entries (
|
||||
@@ -262,8 +264,8 @@ static int group_open_hook (void)
|
||||
struct group *g2 = gr2->eptr;
|
||||
if (NULL != g1 &&
|
||||
NULL != g2 &&
|
||||
0 == strcmp (g1->gr_name, g2->gr_name) &&
|
||||
0 == strcmp (g1->gr_passwd, g2->gr_passwd) &&
|
||||
streq(g1->gr_name, g2->gr_name) &&
|
||||
streq(g1->gr_passwd, g2->gr_passwd) &&
|
||||
g1->gr_gid == g2->gr_gid) {
|
||||
/* Both group entries refer to the same
|
||||
* group. It is a split group. Merge the
|
||||
@@ -331,7 +333,7 @@ static /*@null@*/struct commonio_entry *merge_group_entries (
|
||||
for (i=0; NULL != gptr2->gr_mem[i]; i++) {
|
||||
char **pmember = gptr1->gr_mem;
|
||||
while (NULL != *pmember) {
|
||||
if (0 == strcmp(*pmember, gptr2->gr_mem[i])) {
|
||||
if (streq(*pmember, gptr2->gr_mem[i])) {
|
||||
break;
|
||||
}
|
||||
pmember++;
|
||||
@@ -354,7 +356,7 @@ static /*@null@*/struct commonio_entry *merge_group_entries (
|
||||
for (i=0; NULL != gptr2->gr_mem[i]; i++) {
|
||||
char **pmember = new_members;
|
||||
while (NULL != *pmember) {
|
||||
if (0 == strcmp(*pmember, gptr2->gr_mem[i])) {
|
||||
if (streq(*pmember, gptr2->gr_mem[i])) {
|
||||
break;
|
||||
}
|
||||
pmember++;
|
||||
|
||||
@@ -12,11 +12,13 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "alloc.h"
|
||||
#include "memzero.h"
|
||||
#include "alloc/calloc.h"
|
||||
#include "alloc/malloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "groupio.h"
|
||||
#include "string/memset/memzero.h"
|
||||
|
||||
|
||||
/*@null@*/ /*@only@*/struct group *__gr_dup (const struct group *grent)
|
||||
{
|
||||
@@ -81,10 +83,9 @@ void
|
||||
gr_free(/*@only@*/struct group *grent)
|
||||
{
|
||||
free (grent->gr_name);
|
||||
if (NULL != grent->gr_passwd) {
|
||||
strzero (grent->gr_passwd);
|
||||
free (grent->gr_passwd);
|
||||
}
|
||||
if (NULL != grent->gr_passwd)
|
||||
free(strzero(grent->gr_passwd));
|
||||
|
||||
gr_free_members(grent);
|
||||
free (grent);
|
||||
}
|
||||
|
||||
171
lib/gshadow.c
171
lib/gshadow.c
@@ -9,50 +9,44 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Newer versions of Linux libc already have shadow support. */
|
||||
#if defined(SHADOWGRP) && !defined(HAVE_SHADOWGRP) /*{ */
|
||||
#if defined(SHADOWGRP) && !__has_include(<gshadow.h>)
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "alloc/malloc.h"
|
||||
#include "alloc/realloc.h"
|
||||
#include "alloc/x/xmalloc.h"
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strchr/strchrcnt.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strtok/stpsep.h"
|
||||
|
||||
|
||||
static /*@null@*/FILE *shadow;
|
||||
static /*@null@*//*@only@*/char **members = NULL;
|
||||
static size_t nmembers = 0;
|
||||
static /*@null@*//*@only@*/char **admins = NULL;
|
||||
static size_t nadmins = 0;
|
||||
static struct sgrp sgroup;
|
||||
static struct sgrp sgroup = {};
|
||||
|
||||
#define FIELDS 4
|
||||
|
||||
|
||||
static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist)
|
||||
static /*@null@*/char **
|
||||
build_list(char *s)
|
||||
{
|
||||
char **ptr = *list;
|
||||
size_t nelem = *nlist, size;
|
||||
char **l;
|
||||
size_t i;
|
||||
|
||||
while (s != NULL && *s != '\0') {
|
||||
size = (nelem + 1) * sizeof (ptr);
|
||||
ptr = REALLOC(*list, size, char *);
|
||||
if (NULL != ptr) {
|
||||
ptr[nelem] = strsep(&s, ",");
|
||||
nelem++;
|
||||
*list = ptr;
|
||||
*nlist = nelem;
|
||||
}
|
||||
}
|
||||
size = (nelem + 1) * sizeof (ptr);
|
||||
ptr = REALLOC(*list, size, char *);
|
||||
if (NULL != ptr) {
|
||||
ptr[nelem] = NULL;
|
||||
*list = ptr;
|
||||
}
|
||||
return ptr;
|
||||
l = XMALLOC(strchrcnt(s, ',') + 2, char *);
|
||||
|
||||
for (i = 0; s != NULL && !streq(s, ""); i++)
|
||||
l[i] = strsep(&s, ",");
|
||||
|
||||
l[i] = NULL;
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
void setsgent (void)
|
||||
@@ -60,7 +54,7 @@ void setsgent (void)
|
||||
if (NULL != shadow) {
|
||||
rewind (shadow);
|
||||
} else {
|
||||
shadow = fopen (SGROUP_FILE, "r");
|
||||
shadow = fopen (SGROUP_FILE, "re");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +67,8 @@ void endsgent (void)
|
||||
shadow = NULL;
|
||||
}
|
||||
|
||||
/*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *string)
|
||||
/*@observer@*//*@null@*/struct sgrp *
|
||||
sgetsgent(const char *string)
|
||||
{
|
||||
static char *sgrbuf = NULL;
|
||||
static size_t sgrbuflen = 0;
|
||||
@@ -85,19 +80,15 @@ void endsgent (void)
|
||||
|
||||
if (len > sgrbuflen) {
|
||||
char *buf = REALLOC(sgrbuf, len, char);
|
||||
if (NULL == buf) {
|
||||
if (NULL == buf)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sgrbuf = buf;
|
||||
sgrbuflen = len;
|
||||
}
|
||||
|
||||
strcpy (sgrbuf, string);
|
||||
|
||||
cp = strrchr (sgrbuf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
stpsep(sgrbuf, "\n");
|
||||
|
||||
/*
|
||||
* There should be exactly 4 colon separated fields. Find
|
||||
@@ -113,22 +104,16 @@ void endsgent (void)
|
||||
*/
|
||||
|
||||
if (NULL != cp || i != FIELDS)
|
||||
return 0;
|
||||
return NULL;
|
||||
|
||||
sgroup.sg_name = fields[0];
|
||||
sgroup.sg_namp = fields[0];
|
||||
sgroup.sg_passwd = fields[1];
|
||||
if (0 != nadmins) {
|
||||
nadmins = 0;
|
||||
free (admins);
|
||||
admins = NULL;
|
||||
}
|
||||
if (0 != nmembers) {
|
||||
nmembers = 0;
|
||||
free (members);
|
||||
members = NULL;
|
||||
}
|
||||
sgroup.sg_adm = build_list (fields[2], &admins, &nadmins);
|
||||
sgroup.sg_mem = build_list (fields[3], &members, &nmembers);
|
||||
|
||||
free(sgroup.sg_adm);
|
||||
free(sgroup.sg_mem);
|
||||
|
||||
sgroup.sg_adm = build_list(fields[2]);
|
||||
sgroup.sg_mem = build_list(fields[3]);
|
||||
|
||||
return &sgroup;
|
||||
}
|
||||
@@ -159,32 +144,29 @@ void endsgent (void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fgetsx(buf, buflen, fp) == buf) {
|
||||
while ( ((cp = strrchr (buf, '\n')) == NULL)
|
||||
&& (feof (fp) == 0)) {
|
||||
size_t len;
|
||||
if (fgetsx(buf, buflen, fp) == NULL)
|
||||
return NULL;
|
||||
|
||||
cp = REALLOC(buf, buflen * 2, char);
|
||||
if (NULL == cp) {
|
||||
return NULL;
|
||||
}
|
||||
buf = cp;
|
||||
buflen *= 2;
|
||||
while ( (strrchr(buf, '\n') == NULL)
|
||||
&& (feof (fp) == 0)) {
|
||||
size_t len;
|
||||
|
||||
len = strlen (buf);
|
||||
if (fgetsx (&buf[len],
|
||||
(int) (buflen - len),
|
||||
fp) != &buf[len]) {
|
||||
return NULL;
|
||||
}
|
||||
cp = REALLOC(buf, buflen * 2, char);
|
||||
if (NULL == cp) {
|
||||
return NULL;
|
||||
}
|
||||
cp = strrchr (buf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
buf = cp;
|
||||
buflen *= 2;
|
||||
|
||||
len = strlen (buf);
|
||||
if (fgetsx (&buf[len],
|
||||
(int) (buflen - len),
|
||||
fp) != &buf[len]) {
|
||||
return NULL;
|
||||
}
|
||||
return (sgetsgent (buf));
|
||||
}
|
||||
return NULL;
|
||||
stpsep(buf, "\n");
|
||||
return (sgetsgent (buf));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -210,7 +192,7 @@ void endsgent (void)
|
||||
setsgent ();
|
||||
|
||||
while ((sgrp = getsgent ()) != NULL) {
|
||||
if (strcmp (name, sgrp->sg_name) == 0) {
|
||||
if (streq(name, sgrp->sg_namp)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -236,7 +218,7 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
|
||||
}
|
||||
|
||||
/* calculate the required buffer size */
|
||||
size = strlen (sgrp->sg_name) + strlen (sgrp->sg_passwd) + 10;
|
||||
size = strlen (sgrp->sg_namp) + strlen (sgrp->sg_passwd) + 10;
|
||||
for (i = 0; (NULL != sgrp->sg_adm) && (NULL != sgrp->sg_adm[i]); i++) {
|
||||
size += strlen (sgrp->sg_adm[i]) + 1;
|
||||
}
|
||||
@@ -253,53 +235,36 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
|
||||
/*
|
||||
* Copy the group name and passwd.
|
||||
*/
|
||||
|
||||
strcpy (cp, sgrp->sg_name);
|
||||
cp += strlen (cp);
|
||||
*cp++ = ':';
|
||||
|
||||
strcpy (cp, sgrp->sg_passwd);
|
||||
cp += strlen (cp);
|
||||
*cp++ = ':';
|
||||
cp = stpcpy(stpcpy(cp, sgrp->sg_namp), ":");
|
||||
cp = stpcpy(stpcpy(cp, sgrp->sg_passwd), ":");
|
||||
|
||||
/*
|
||||
* Copy the administrators, separating each from the other
|
||||
* with a ",".
|
||||
*/
|
||||
|
||||
for (i = 0; NULL != sgrp->sg_adm[i]; i++) {
|
||||
if (i > 0) {
|
||||
*cp++ = ',';
|
||||
}
|
||||
if (i > 0)
|
||||
cp = stpcpy(cp, ",");
|
||||
|
||||
strcpy (cp, sgrp->sg_adm[i]);
|
||||
cp += strlen (cp);
|
||||
cp = stpcpy(cp, sgrp->sg_adm[i]);
|
||||
}
|
||||
*cp = ':';
|
||||
cp++;
|
||||
cp = stpcpy(cp, ":");
|
||||
|
||||
/*
|
||||
* Now do likewise with the group members.
|
||||
*/
|
||||
|
||||
for (i = 0; NULL != sgrp->sg_mem[i]; i++) {
|
||||
if (i > 0) {
|
||||
*cp = ',';
|
||||
cp++;
|
||||
}
|
||||
if (i > 0)
|
||||
cp = stpcpy(cp, ",");
|
||||
|
||||
strcpy (cp, sgrp->sg_mem[i]);
|
||||
cp += strlen (cp);
|
||||
cp = stpcpy(cp, sgrp->sg_mem[i]);
|
||||
}
|
||||
*cp = '\n';
|
||||
cp++;
|
||||
*cp = '\0';
|
||||
stpcpy(cp, "\n");
|
||||
|
||||
/*
|
||||
* Output using the function which understands the line
|
||||
* continuation conventions.
|
||||
*/
|
||||
|
||||
if (fputsx (buf, fp) == EOF) {
|
||||
free (buf);
|
||||
return -1;
|
||||
@@ -310,4 +275,4 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
|
||||
}
|
||||
#else
|
||||
extern int ISO_C_forbids_an_empty_translation_unit;
|
||||
#endif /*} SHADOWGRP */
|
||||
#endif // !SHADOWGRP
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user