Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d974e3e9b | |||
| c53b76cc49 | |||
| ec00428f90 |
@@ -5,21 +5,8 @@ runs:
|
|||||||
steps:
|
steps:
|
||||||
- shell: bash
|
- shell: bash
|
||||||
run: |
|
run: |
|
||||||
if [ -f /etc/apt/sources.list.d/ubuntu.sources ]; then
|
sudo apt-get update -y
|
||||||
echo "Found new-style sources.list.d"
|
sudo apt-get install -y ubuntu-dev-tools libbsd-dev
|
||||||
cat /etc/apt/sources.list.d/ubuntu.sources
|
sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
|
||||||
sudo sed -i 's/^Types: deb/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources
|
sudo apt-get update -y
|
||||||
else
|
|
||||||
echo "Found legacy sources.list"
|
|
||||||
cat /etc/apt/sources.list
|
|
||||||
sudo sed -i '/deb-src/d' /etc/apt/sources.list
|
|
||||||
sudo sed -i '/^deb /p;s/ /-src /' /etc/apt/sources.list
|
|
||||||
fi
|
|
||||||
export DEBIAN_PRIORITY=critical
|
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
|
||||||
# let's try to work around upgrade breakage in a pkg we don't care about
|
|
||||||
sudo apt-mark hold grub-efi-amd64-bin grub-efi-amd64-signed
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get -y dist-upgrade
|
|
||||||
sudo apt-get -y install ubuntu-dev-tools automake autopoint xsltproc gettext expect byacc libtool libbsd-dev libltdl-dev pkgconf
|
|
||||||
sudo apt-get -y build-dep shadow
|
sudo apt-get -y build-dep shadow
|
||||||
|
|||||||
@@ -25,8 +25,18 @@ jobs:
|
|||||||
cat /proc/self/status
|
cat /proc/self/status
|
||||||
systemd-detect-virt
|
systemd-detect-virt
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
id: dependencies
|
run: |
|
||||||
uses: ./.github/actions/install-dependencies
|
sudo cat /etc/apt/sources.list
|
||||||
|
sudo sed -i '/deb-src/d' /etc/apt/sources.list
|
||||||
|
sudo sed -i '/^deb /p;s/ /-src /' /etc/apt/sources.list
|
||||||
|
export DEBIAN_PRIORITY=critical
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
# let's try to work around upgrade breakage in a pkg we don't care about
|
||||||
|
sudo apt-mark hold grub-efi-amd64-bin grub-efi-amd64-signed
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get -y dist-upgrade
|
||||||
|
sudo apt-get -y install ubuntu-dev-tools automake autopoint xsltproc gettext expect byacc libtool libbsd-dev pkgconf libcmocka-dev
|
||||||
|
sudo apt-get -y build-dep shadow
|
||||||
- name: configure
|
- name: configure
|
||||||
run: |
|
run: |
|
||||||
autoreconf -v -f --install
|
autoreconf -v -f --install
|
||||||
@@ -51,8 +61,18 @@ jobs:
|
|||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
id: dependencies
|
run: |
|
||||||
uses: ./.github/actions/install-dependencies
|
sudo cat /etc/apt/sources.list
|
||||||
|
sudo sed -i '/deb-src/d' /etc/apt/sources.list
|
||||||
|
sudo sed -i '/^deb /p;s/ /-src /' /etc/apt/sources.list
|
||||||
|
export DEBIAN_PRIORITY=critical
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
# let's try to work around upgrade breakage in a pkg we don't care about
|
||||||
|
sudo apt-mark hold grub-efi-amd64-bin grub-efi-amd64-signed
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get -y dist-upgrade
|
||||||
|
sudo apt-get -y install ubuntu-dev-tools automake autopoint xsltproc gettext expect byacc libtool libbsd-dev pkgconf
|
||||||
|
sudo apt-get -y build-dep shadow
|
||||||
|
|
||||||
- name: Test make dist
|
- name: Test make dist
|
||||||
run: |
|
run: |
|
||||||
@@ -69,7 +89,6 @@ jobs:
|
|||||||
container-build:
|
container-build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
matrix:
|
||||||
os: [alpine, debian, fedora]
|
os: [alpine, debian, fedora]
|
||||||
|
|
||||||
@@ -77,25 +96,15 @@ jobs:
|
|||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install Ansible
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get -y install ansible
|
|
||||||
|
|
||||||
- name: Build container
|
- name: Build container
|
||||||
run: |
|
run: |
|
||||||
pushd share/ansible/
|
docker buildx build -f ./share/containers/${{ matrix.os }}.dockerfile . --output build-out
|
||||||
ansible-playbook playbook.yml -i inventory.ini -e 'distribution=${{ matrix.os }}'
|
|
||||||
popd
|
|
||||||
|
|
||||||
- name: Store artifacts
|
- name: Store artifacts
|
||||||
if: always()
|
uses: actions/upload-artifact@v3
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
with:
|
||||||
name: ${{ matrix.os }}-build
|
name: ${{ matrix.os }}-build
|
||||||
path: |
|
path: |
|
||||||
./share/ansible/build-out/config.log
|
./build-out/config.log
|
||||||
./share/ansible/build-out/config.h
|
./build-out/config.h
|
||||||
./share/ansible/build-out/build.log
|
|
||||||
./share/ansible/build-out/test-suite.log
|
|
||||||
if-no-files-found: ignore
|
if-no-files-found: ignore
|
||||||
|
|||||||
+3
-12
@@ -1,5 +1,7 @@
|
|||||||
## Process this file with automake to produce Makefile.in
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
|
EXTRA_DIST = NEWS README
|
||||||
|
|
||||||
SUBDIRS = lib
|
SUBDIRS = lib
|
||||||
|
|
||||||
if ENABLE_SUBIDS
|
if ENABLE_SUBIDS
|
||||||
@@ -13,15 +15,4 @@ SUBDIRS += man
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
CLEANFILES = man/8.out man/po/remove-potcdate.* man/*/login.defs.d man/*/*.mo
|
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
|
|
||||||
|
|||||||
+10
-3
@@ -1,10 +1,10 @@
|
|||||||
dnl Process this file with autoconf to produce a configure script.
|
dnl Process this file with autoconf to produce a configure script.
|
||||||
AC_PREREQ([2.69])
|
AC_PREREQ([2.69])
|
||||||
m4_define([libsubid_abi_major], 5)
|
m4_define([libsubid_abi_major], 4)
|
||||||
m4_define([libsubid_abi_minor], 0)
|
m4_define([libsubid_abi_minor], 0)
|
||||||
m4_define([libsubid_abi_micro], 0)
|
m4_define([libsubid_abi_micro], 0)
|
||||||
m4_define([libsubid_abi], [libsubid_abi_major.libsubid_abi_minor.libsubid_abi_micro])
|
m4_define([libsubid_abi], [libsubid_abi_major.libsubid_abi_minor.libsubid_abi_micro])
|
||||||
AC_INIT([shadow], [4.17.2], [pkg-shadow-devel@lists.alioth.debian.org], [],
|
AC_INIT([shadow], [4.15.2], [pkg-shadow-devel@lists.alioth.debian.org], [],
|
||||||
[https://github.com/shadow-maint/shadow])
|
[https://github.com/shadow-maint/shadow])
|
||||||
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects tar-pax])
|
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects tar-pax])
|
||||||
AC_CONFIG_MACRO_DIRS([m4])
|
AC_CONFIG_MACRO_DIRS([m4])
|
||||||
@@ -159,6 +159,13 @@ fi])
|
|||||||
AC_DEFINE_UNQUOTED(PASSWD_PROGRAM, "$shadow_cv_passwd_dir/passwd",
|
AC_DEFINE_UNQUOTED(PASSWD_PROGRAM, "$shadow_cv_passwd_dir/passwd",
|
||||||
[Path to passwd program.])
|
[Path to passwd program.])
|
||||||
|
|
||||||
|
dnl XXX - quick hack, should disappear before anyone notices :).
|
||||||
|
dnl XXX - I just read the above message :).
|
||||||
|
if test "$ac_cv_func_ruserok" = "yes"; then
|
||||||
|
AC_DEFINE(RLOGIN, 1, [Define if login should support the -r flag for rlogind.])
|
||||||
|
AC_DEFINE(RUSEROK, 0, [Define to the ruserok() "success" return value (0 or 1).])
|
||||||
|
fi
|
||||||
|
|
||||||
AC_ARG_ENABLE(shadowgrp,
|
AC_ARG_ENABLE(shadowgrp,
|
||||||
[AS_HELP_STRING([--enable-shadowgrp], [enable shadow group support @<:@default=yes@:>@])],
|
[AS_HELP_STRING([--enable-shadowgrp], [enable shadow group support @<:@default=yes@:>@])],
|
||||||
[case "${enableval}" in
|
[case "${enableval}" in
|
||||||
@@ -689,7 +696,7 @@ AC_SUBST(LIBMD)
|
|||||||
if test "$with_skey" = "yes"; then
|
if test "$with_skey" = "yes"; then
|
||||||
AC_CHECK_LIB(md, MD5Init, [LIBMD=-lmd])
|
AC_CHECK_LIB(md, MD5Init, [LIBMD=-lmd])
|
||||||
AC_CHECK_LIB(skey, skeychallenge, [LIBSKEY=-lskey],
|
AC_CHECK_LIB(skey, skeychallenge, [LIBSKEY=-lskey],
|
||||||
[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_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_DEFINE(SKEY, 1, [Define to support S/Key logins.])
|
AC_DEFINE(SKEY, 1, [Define to support S/Key logins.])
|
||||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|||||||
+10
-11
@@ -118,9 +118,6 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define IMMEDIATE_CHANGE /* Expire newly created password, must be changed
|
#define IMMEDIATE_CHANGE /* Expire newly created password, must be changed
|
||||||
* immediately upon next login */
|
* immediately upon next login */
|
||||||
#define HAVE_QUOTAS /* Obvious */
|
#define HAVE_QUOTAS /* Obvious */
|
||||||
@@ -294,10 +291,12 @@ main (void)
|
|||||||
printf ("Home Directory [%s/%s]: ", DEFAULT_HOME, usrname);
|
printf ("Home Directory [%s/%s]: ", DEFAULT_HOME, usrname);
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
safeget (dir, sizeof (dir));
|
safeget (dir, sizeof (dir));
|
||||||
if (!strlen(dir)) /* hit return */
|
if (!strlen (dir))
|
||||||
sprintf(dir, "%s/%s", DEFAULT_HOME, usrname);
|
{ /* hit return */
|
||||||
|
sprintf (dir, "%s/%s", DEFAULT_HOME, usrname);
|
||||||
|
}
|
||||||
else if (dir[strlen (dir) - 1] == '/')
|
else if (dir[strlen (dir) - 1] == '/')
|
||||||
strcat(dir, usrname);
|
sprintf (dir+strlen(dir), "%s", usrname);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -309,7 +308,7 @@ main (void)
|
|||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
safeget (shell, sizeof (shell));
|
safeget (shell, sizeof (shell));
|
||||||
if (!strlen (shell))
|
if (!strlen (shell))
|
||||||
strcpy(shell, DEFAULT_SHELL);
|
sprintf (shell, "%s", DEFAULT_SHELL);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *sh;
|
char *sh;
|
||||||
@@ -317,7 +316,7 @@ main (void)
|
|||||||
#ifdef HAVE_GETUSERSHELL
|
#ifdef HAVE_GETUSERSHELL
|
||||||
setusershell ();
|
setusershell ();
|
||||||
while ((sh = getusershell ()) != NULL)
|
while ((sh = getusershell ()) != NULL)
|
||||||
if (streq(shell, sh))
|
if (!strcmp (shell, sh))
|
||||||
ok = 1;
|
ok = 1;
|
||||||
endusershell ();
|
endusershell ();
|
||||||
#endif
|
#endif
|
||||||
@@ -328,7 +327,7 @@ main (void)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf ("Shell NOT in /etc/shells, DEFAULT used\n");
|
printf ("Shell NOT in /etc/shells, DEFAULT used\n");
|
||||||
strcpy(shell, DEFAULT_SHELL);
|
sprintf (shell, "%s", DEFAULT_SHELL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -492,12 +491,12 @@ safeget (char *buf, int maxlen)
|
|||||||
bad = (!isalnum (c) && (c != '_') && (c != ' '));
|
bad = (!isalnum (c) && (c != '_') && (c != ' '));
|
||||||
*(buf++) = c;
|
*(buf++) = c;
|
||||||
}
|
}
|
||||||
stpcpy(buf, "");
|
*buf = '\0';
|
||||||
|
|
||||||
if (bad)
|
if (bad)
|
||||||
{
|
{
|
||||||
printf ("\nString contained banned character. Please stick to alphanumerics.\n");
|
printf ("\nString contained banned character. Please stick to alphanumerics.\n");
|
||||||
stpcpy(bstart, "");
|
*bstart = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -471,12 +471,12 @@
|
|||||||
|
|
||||||
The Shadow Suite contains replacement programs for:
|
The Shadow Suite contains replacement programs for:
|
||||||
|
|
||||||
su, login, passwd, newgrp, chfn, chsh
|
su, login, passwd, newgrp, chfn, chsh, and id
|
||||||
|
|
||||||
The package also contains the new programs:
|
The package also contains the new programs:
|
||||||
|
|
||||||
chage, newusers, dpasswd, gpasswd, useradd, userdel, usermod,
|
chage, newusers, dpasswd, gpasswd, useradd, userdel, usermod,
|
||||||
groupadd, groupdel, groupmod, pwck, grpck, lastlog, pwconv,
|
groupadd, groupdel, groupmod, groups, pwck, grpck, lastlog, pwconv,
|
||||||
and pwunconv
|
and pwunconv
|
||||||
|
|
||||||
Additionally, the library: libshadow.a is included for writing and/or
|
Additionally, the library: libshadow.a is included for writing and/or
|
||||||
@@ -586,6 +586,8 @@
|
|||||||
|
|
||||||
· /usr/bin/chsh
|
· /usr/bin/chsh
|
||||||
|
|
||||||
|
· /usr/bin/id
|
||||||
|
|
||||||
The BETA package has a save target in the Makefile, but it's commented
|
The BETA package has a save target in the Makefile, but it's commented
|
||||||
out because different distributions place the programs in different
|
out because different distributions place the programs in different
|
||||||
places.
|
places.
|
||||||
@@ -635,6 +637,8 @@
|
|||||||
|
|
||||||
· /usr/man/man1/chsh.1.gz
|
· /usr/man/man1/chsh.1.gz
|
||||||
|
|
||||||
|
· /usr/man/man1/id.1.gz
|
||||||
|
|
||||||
· /usr/man/man1/login.1.gz
|
· /usr/man/man1/login.1.gz
|
||||||
|
|
||||||
· /usr/man/man1/passwd.1.gz
|
· /usr/man/man1/passwd.1.gz
|
||||||
@@ -1373,7 +1377,7 @@
|
|||||||
users or changing the group password, the /etc/gshadow file will be
|
users or changing the group password, the /etc/gshadow file will be
|
||||||
changed.
|
changed.
|
||||||
|
|
||||||
The programs groupadd, groupmod, and groupdel are provided as
|
The programs groups, groupadd, groupmod, and groupdel are provided as
|
||||||
part of the Shadow Suite to modify groups.
|
part of the Shadow Suite to modify groups.
|
||||||
|
|
||||||
The format of the /etc/group file is as follows:
|
The format of the /etc/group file is as follows:
|
||||||
|
|||||||
@@ -62,11 +62,9 @@ You can either generate a single image by running the following command from
|
|||||||
the root folder of the project (i.e. Alpine):
|
the root folder of the project (i.e. Alpine):
|
||||||
|
|
||||||
```
|
```
|
||||||
ansible-playbook share/ansible/playbook.yml -i share/ansible/inventory.ini -e 'distribution=alpine'
|
docker build -f share/containers/alpine.dockerfile . --output build-out/alpine
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note**: you'll need to install ansible to run this automation.
|
|
||||||
|
|
||||||
Or generate all of the images with the `container-build.sh` script, as if you
|
Or generate all of the images with the `container-build.sh` script, as if you
|
||||||
were running some of the CI checks locally:
|
were running some of the CI checks locally:
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,6 @@ understand the project's development model:
|
|||||||
* [Build & install](build_install.md)
|
* [Build & install](build_install.md)
|
||||||
* [Coding style](coding_style.md)
|
* [Coding style](coding_style.md)
|
||||||
* [Tests](tests.md)
|
* [Tests](tests.md)
|
||||||
* [Continuous Integration](ci.md)
|
* [Continuous Integration](CI.md)
|
||||||
* [Releases](releases.md)
|
* [Releases](releases.md)
|
||||||
* [License](license.md)
|
* [License](license.md)
|
||||||
|
|||||||
+25
-81
@@ -29,48 +29,16 @@ libshadow_la_SOURCES = \
|
|||||||
age.c \
|
age.c \
|
||||||
agetpass.c \
|
agetpass.c \
|
||||||
agetpass.h \
|
agetpass.h \
|
||||||
alloc/calloc.c \
|
alloc.c \
|
||||||
alloc/calloc.h \
|
alloc.h \
|
||||||
alloc/malloc.c \
|
atoi/a2i.c \
|
||||||
alloc/malloc.h \
|
atoi/a2i.h \
|
||||||
alloc/realloc.c \
|
atoi/str2i.c \
|
||||||
alloc/realloc.h \
|
atoi/str2i.h \
|
||||||
alloc/reallocf.c \
|
atoi/strtoi.c \
|
||||||
alloc/reallocf.h \
|
atoi/strtoi.h \
|
||||||
alloc/x/xcalloc.c \
|
atoi/strtou_noneg.c \
|
||||||
alloc/x/xcalloc.h \
|
atoi/strtou_noneg.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 \
|
attr.h \
|
||||||
audit_help.c \
|
audit_help.c \
|
||||||
basename.c \
|
basename.c \
|
||||||
@@ -103,11 +71,9 @@ libshadow_la_SOURCES = \
|
|||||||
find_new_sub_gids.c \
|
find_new_sub_gids.c \
|
||||||
find_new_sub_uids.c \
|
find_new_sub_uids.c \
|
||||||
fputsx.c \
|
fputsx.c \
|
||||||
fs/readlink/areadlink.c \
|
get_gid.c \
|
||||||
fs/readlink/areadlink.h \
|
|
||||||
fs/readlink/readlinknul.c \
|
|
||||||
fs/readlink/readlinknul.h \
|
|
||||||
get_pid.c \
|
get_pid.c \
|
||||||
|
get_uid.c \
|
||||||
getdate.h \
|
getdate.h \
|
||||||
getdate.y \
|
getdate.y \
|
||||||
getdef.c \
|
getdef.c \
|
||||||
@@ -128,6 +94,8 @@ libshadow_la_SOURCES = \
|
|||||||
lockpw.c \
|
lockpw.c \
|
||||||
loginprompt.c \
|
loginprompt.c \
|
||||||
mail.c \
|
mail.c \
|
||||||
|
memzero.c \
|
||||||
|
memzero.h \
|
||||||
motd.c \
|
motd.c \
|
||||||
must_be.h \
|
must_be.h \
|
||||||
myname.c \
|
myname.c \
|
||||||
@@ -151,6 +119,7 @@ libshadow_la_SOURCES = \
|
|||||||
pwdcheck.c \
|
pwdcheck.c \
|
||||||
pwmem.c \
|
pwmem.c \
|
||||||
remove_tree.c \
|
remove_tree.c \
|
||||||
|
rlogin.c \
|
||||||
root_flag.c \
|
root_flag.c \
|
||||||
run_part.h \
|
run_part.h \
|
||||||
run_part.c \
|
run_part.c \
|
||||||
@@ -176,42 +145,18 @@ libshadow_la_SOURCES = \
|
|||||||
spawn.c \
|
spawn.c \
|
||||||
sssd.c \
|
sssd.c \
|
||||||
sssd.h \
|
sssd.h \
|
||||||
string/memset/memzero.c \
|
string/sprintf.c \
|
||||||
string/memset/memzero.h \
|
string/sprintf.h \
|
||||||
string/sprintf/snprintf.c \
|
string/stpecpy.c \
|
||||||
string/sprintf/snprintf.h \
|
string/stpecpy.h \
|
||||||
string/sprintf/stpeprintf.c \
|
string/stpeprintf.c \
|
||||||
string/sprintf/stpeprintf.h \
|
string/stpeprintf.h \
|
||||||
string/sprintf/xasprintf.c \
|
|
||||||
string/sprintf/xasprintf.h \
|
|
||||||
string/strchr/strchrcnt.c \
|
|
||||||
string/strchr/strchrcnt.h \
|
|
||||||
string/strchr/stpspn.c \
|
|
||||||
string/strchr/stpspn.h \
|
|
||||||
string/strchr/strnul.c \
|
|
||||||
string/strchr/strnul.h \
|
|
||||||
string/strchr/strrspn.c \
|
|
||||||
string/strchr/strrspn.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.c \
|
||||||
string/strftime.h \
|
string/strftime.h \
|
||||||
string/strtok/stpsep.c \
|
string/strncpy.h \
|
||||||
string/strtok/stpsep.h \
|
string/strtcpy.c \
|
||||||
|
string/strtcpy.h \
|
||||||
|
string/zustr2stp.h \
|
||||||
strtoday.c \
|
strtoday.c \
|
||||||
sub.c \
|
sub.c \
|
||||||
subordinateio.h \
|
subordinateio.h \
|
||||||
@@ -220,7 +165,6 @@ libshadow_la_SOURCES = \
|
|||||||
time/day_to_str.c \
|
time/day_to_str.c \
|
||||||
time/day_to_str.h \
|
time/day_to_str.h \
|
||||||
ttytype.c \
|
ttytype.c \
|
||||||
typetraits.h \
|
|
||||||
tz.c \
|
tz.c \
|
||||||
ulimit.c \
|
ulimit.c \
|
||||||
user_busy.c \
|
user_busy.c \
|
||||||
|
|||||||
+11
-13
@@ -14,30 +14,28 @@
|
|||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <grp.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <grp.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "alloc/malloc.h"
|
#include "alloc.h"
|
||||||
#include "alloc/reallocf.h"
|
|
||||||
#include "shadowlog.h"
|
#include "shadowlog.h"
|
||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
|
#define SEP ",:"
|
||||||
/*
|
/*
|
||||||
* Add groups with names from LIST (separated by commas or colons)
|
* Add groups with names from LIST (separated by commas or colons)
|
||||||
* to the supplementary group set. Silently ignore groups which are
|
* to the supplementary group set. Silently ignore groups which are
|
||||||
* already there.
|
* already there. Warning: uses strtok().
|
||||||
*/
|
*/
|
||||||
int
|
int add_groups (const char *list)
|
||||||
add_groups(const char *list)
|
|
||||||
{
|
{
|
||||||
GETGROUPS_T *grouplist;
|
GETGROUPS_T *grouplist;
|
||||||
size_t i;
|
size_t i;
|
||||||
int ngroups;
|
int ngroups;
|
||||||
bool added;
|
bool added;
|
||||||
char *g, *p;
|
char *token;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
int ret;
|
int ret;
|
||||||
FILE *shadow_logfd = log_get_logfd();
|
FILE *shadow_logfd = log_get_logfd();
|
||||||
@@ -72,13 +70,13 @@ add_groups(const char *list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
added = false;
|
added = false;
|
||||||
p = buf;
|
for (token = strtok (buf, SEP); NULL != token; token = strtok (NULL, SEP)) {
|
||||||
while (NULL != (g = strsep(&p, ",:"))) {
|
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
|
|
||||||
grp = getgrnam(g); /* local, no need for xgetgrnam */
|
grp = getgrnam (token); /* local, no need for xgetgrnam */
|
||||||
if (NULL == grp) {
|
if (NULL == grp) {
|
||||||
fprintf(shadow_logfd, _("Warning: unknown group %s\n"), g);
|
fprintf (shadow_logfd, _("Warning: unknown group %s\n"),
|
||||||
|
token);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
#include "alloc/malloc.h"
|
#include "alloc.h"
|
||||||
|
|
||||||
#if WITH_LIBBSD == 0
|
#if WITH_LIBBSD == 0
|
||||||
#include "freezero.h"
|
#include "freezero.h"
|
||||||
|
|||||||
+73
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* 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
@@ -0,0 +1,101 @@
|
|||||||
|
// 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
|
||||||
@@ -1,11 +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-2024, Alejandro Colomar <alx@kernel.org>
|
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
#include "alloc/calloc.h"
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,16 +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-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);
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,11 +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-2024, Alejandro Colomar <alx@kernel.org>
|
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
#include "alloc/realloc.h"
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,16 +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-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);
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,36 +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-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);
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,16 +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-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);
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,35 +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-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);
|
|
||||||
}
|
|
||||||
@@ -1,31 +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"
|
|
||||||
|
|
||||||
|
|
||||||
#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
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// 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
@@ -0,0 +1,386 @@
|
|||||||
|
// 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
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
#include "atoi/a2i/a2i.h"
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
#include "atoi/a2i/a2s.h"
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
// 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);
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
// 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);
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
#include "atoi/a2i/a2u.h"
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
// 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);
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
// 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);
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
// 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);
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -5,9 +5,13 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "atoi/str2i/str2u.h"
|
#include "atoi/str2i.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 str2uh(unsigned short *restrict n, const char *restrict s);
|
||||||
extern inline int str2ui(unsigned int *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);
|
extern inline int str2ul(unsigned long *restrict n, const char *restrict s);
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
// 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
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
// 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"
|
|
||||||
@@ -1,31 +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_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
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
// 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);
|
|
||||||
@@ -1,57 +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_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
|
|
||||||
@@ -1,57 +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_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
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// 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);
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
// 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
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
// 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);
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
// 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);
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
// 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-2024, Alejandro Colomar <alx@kernel.org>
|
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "atoi/strtoi/strtou_noneg.h"
|
#include "atoi/strtou_noneg.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
|
||||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_NONEG_H_
|
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOU_NONEG_H_
|
||||||
#define SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_NONEG_H_
|
#define SHADOW_INCLUDE_LIB_ATOI_STRTOU_NONEG_H_
|
||||||
|
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
@@ -12,8 +12,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "atoi/strtoi/strtoi.h"
|
#include "atoi/strtoi.h"
|
||||||
#include "atoi/strtoi/strtou.h"
|
|
||||||
#include "attr.h"
|
#include "attr.h"
|
||||||
|
|
||||||
|
|
||||||
+7
-9
@@ -5,18 +5,16 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
#if (__GNUC__ >= 10)
|
#if defined(__GNUC__)
|
||||||
# define MAYBE_UNUSED [[gnu::unused]]
|
# define MAYBE_UNUSED __attribute__((unused))
|
||||||
# define NORETURN [[gnu::__noreturn__]]
|
# define NORETURN __attribute__((__noreturn__))
|
||||||
# define format_attr(type, fmt, va) [[gnu::format(type, fmt, va)]]
|
# define format_attr(type, fmt, va) __attribute__((format(type, fmt, va)))
|
||||||
# define ATTR_ACCESS(...) [[gnu::access(__VA_ARGS__)]]
|
# define ATTR_ACCESS(...) __attribute__((access(__VA_ARGS__)))
|
||||||
# define ATTR_ALLOC_SIZE(...) [[gnu::alloc_size(__VA_ARGS__)]]
|
|
||||||
#else
|
#else
|
||||||
# define MAYBE_UNUSED
|
# define MAYBE_UNUSED
|
||||||
# define NORETURN
|
# define NORETURN
|
||||||
# define format_attr(type, fmt, va)
|
# define format_attr(type, fmt, va)
|
||||||
# define ATTR_ACCESS(...)
|
# define ATTR_ACCESS(...)
|
||||||
# define ATTR_ALLOC_SIZE(...)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (__GNUC__ >= 11) && !defined(__clang__)
|
#if (__GNUC__ >= 11) && !defined(__clang__)
|
||||||
@@ -26,9 +24,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (__GNUC__ >= 14)
|
#if (__GNUC__ >= 14)
|
||||||
# define ATTR_STRING(i) [[gnu::null_terminated_string_arg(i)]]
|
# define ATTR_STRING(...) [[gnu::null_terminated_string_arg(__VA_ARGS__)]]
|
||||||
#else
|
#else
|
||||||
# define ATTR_STRING(i)
|
# define ATTR_STRING(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+11
-34
@@ -2,7 +2,7 @@
|
|||||||
// SPDX-FileCopyrightText: 1996-2000, Marek Michałkiewicz
|
// SPDX-FileCopyrightText: 1996-2000, Marek Michałkiewicz
|
||||||
// SPDX-FileCopyrightText: 2001-2005, Tomasz Kłoczko
|
// SPDX-FileCopyrightText: 2001-2005, Tomasz Kłoczko
|
||||||
// SPDX-FileCopyrightText: 2005-2008, Nicolas François
|
// SPDX-FileCopyrightText: 2005-2008, Nicolas François
|
||||||
// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <alx@kernel.org>
|
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
|
||||||
@@ -12,9 +12,6 @@
|
|||||||
* return values:
|
* return values:
|
||||||
* true - OK
|
* true - OK
|
||||||
* false - bad name
|
* false - bad name
|
||||||
* errors:
|
|
||||||
* EINVAL Invalid name characters or sequences
|
|
||||||
* EOVERFLOW Name longer than maximum size
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -31,12 +28,6 @@
|
|||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "chkname.h"
|
#include "chkname.h"
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LOGIN_NAME_MAX
|
|
||||||
# define LOGIN_NAME_MAX 256
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
int allow_bad_names = false;
|
int allow_bad_names = false;
|
||||||
@@ -47,16 +38,16 @@ login_name_max_size(void)
|
|||||||
{
|
{
|
||||||
long conf;
|
long conf;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
conf = sysconf(_SC_LOGIN_NAME_MAX);
|
conf = sysconf(_SC_LOGIN_NAME_MAX);
|
||||||
if (conf == -1)
|
if (conf == -1 && errno != 0)
|
||||||
return LOGIN_NAME_MAX;
|
return LOGIN_NAME_MAX;
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool
|
static bool is_valid_name (const char *name)
|
||||||
is_valid_name(const char *name)
|
|
||||||
{
|
{
|
||||||
if (allow_bad_names) {
|
if (allow_bad_names) {
|
||||||
return true;
|
return true;
|
||||||
@@ -80,15 +71,13 @@ is_valid_name(const char *name)
|
|||||||
(*name >= 'A' && *name <= 'Z') ||
|
(*name >= 'A' && *name <= 'Z') ||
|
||||||
(*name >= '0' && *name <= '9') ||
|
(*name >= '0' && *name <= '9') ||
|
||||||
*name == '_' ||
|
*name == '_' ||
|
||||||
*name == '.'))
|
*name == '.')) {
|
||||||
{
|
|
||||||
errno = EINVAL;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
numeric = isdigit(*name);
|
numeric = isdigit(*name);
|
||||||
|
|
||||||
while (!streq(++name, "")) {
|
while ('\0' != *++name) {
|
||||||
if (!((*name >= 'a' && *name <= 'z') ||
|
if (!((*name >= 'a' && *name <= 'z') ||
|
||||||
(*name >= 'A' && *name <= 'Z') ||
|
(*name >= 'A' && *name <= 'Z') ||
|
||||||
(*name >= '0' && *name <= '9') ||
|
(*name >= '0' && *name <= '9') ||
|
||||||
@@ -96,46 +85,34 @@ is_valid_name(const char *name)
|
|||||||
*name == '.' ||
|
*name == '.' ||
|
||||||
*name == '-' ||
|
*name == '-' ||
|
||||||
(*name == '$' && name[1] == '\0')
|
(*name == '$' && name[1] == '\0')
|
||||||
))
|
)) {
|
||||||
{
|
|
||||||
errno = EINVAL;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
numeric &= isdigit(*name);
|
numeric &= isdigit(*name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numeric) {
|
return !numeric;
|
||||||
errno = EINVAL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_valid_user_name(const char *name)
|
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 false;
|
||||||
}
|
|
||||||
|
|
||||||
return is_valid_name(name);
|
return is_valid_name(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool is_valid_group_name (const char *name)
|
||||||
is_valid_group_name(const char *name)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Arbitrary limit for group names.
|
* Arbitrary limit for group names.
|
||||||
* HP-UX 10 limits to 16 characters
|
* HP-UX 10 limits to 16 characters
|
||||||
*/
|
*/
|
||||||
if ( (GROUP_NAME_MAX_LENGTH > 0)
|
if ( (GROUP_NAME_MAX_LENGTH > 0)
|
||||||
&& (strlen (name) > GROUP_NAME_MAX_LENGTH))
|
&& (strlen (name) > GROUP_NAME_MAX_LENGTH)) {
|
||||||
{
|
|
||||||
errno = EOVERFLOW;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-7
@@ -13,15 +13,12 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include "prototypes.h"
|
||||||
|
#include "defines.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "defines.h"
|
|
||||||
#include "prototypes.h"
|
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
|
|
||||||
|
|
||||||
static int chown_tree_at (int at_fd,
|
static int chown_tree_at (int at_fd,
|
||||||
const char *path,
|
const char *path,
|
||||||
uid_t old_uid,
|
uid_t old_uid,
|
||||||
@@ -59,8 +56,8 @@ static int chown_tree_at (int at_fd,
|
|||||||
/*
|
/*
|
||||||
* Skip the "." and ".." entries
|
* Skip the "." and ".." entries
|
||||||
*/
|
*/
|
||||||
if ( streq(ent->d_name, ".")
|
if ( (strcmp (ent->d_name, ".") == 0)
|
||||||
|| streq(ent->d_name, "..")) {
|
|| (strcmp (ent->d_name, "..") == 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ void do_cleanups (void)
|
|||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
/* Make sure there were no overflows */
|
/* Make sure there were no overflow */
|
||||||
assert (NULL == cleanup_functions[CLEANUP_FUNCTIONS-1]);
|
assert (NULL == cleanup_functions[CLEANUP_FUNCTIONS-1]);
|
||||||
|
|
||||||
if (getpid () != cleanup_pid) {
|
if (getpid () != cleanup_pid) {
|
||||||
|
|||||||
+32
-29
@@ -11,33 +11,28 @@
|
|||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
#include <assert.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 <sys/stat.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <utime.h>
|
#include <utime.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include "alloc/malloc.h"
|
#include "alloc.h"
|
||||||
#include "alloc/reallocf.h"
|
#include "memzero.h"
|
||||||
#include "atoi/getnum.h"
|
|
||||||
#include "commonio.h"
|
|
||||||
#include "defines.h"
|
|
||||||
#include "nscd.h"
|
#include "nscd.h"
|
||||||
|
#include "sssd.h"
|
||||||
#ifdef WITH_TCB
|
#ifdef WITH_TCB
|
||||||
#include <tcb.h>
|
#include <tcb.h>
|
||||||
#endif /* WITH_TCB */
|
#endif /* WITH_TCB */
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
#include "commonio.h"
|
||||||
#include "shadowlog_internal.h"
|
#include "shadowlog_internal.h"
|
||||||
#include "sssd.h"
|
#include "string/sprintf.h"
|
||||||
#include "string/memset/memzero.h"
|
|
||||||
#include "string/sprintf/snprintf.h"
|
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
#include "string/strtok/stpsep.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* local function prototypes */
|
/* local function prototypes */
|
||||||
@@ -199,7 +194,7 @@ static int do_lock_file (const char *file, const char *lock, bool log)
|
|||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
stpcpy(&buf[len], "");
|
buf[len] = '\0';
|
||||||
if (get_pid(buf, &pid) == -1) {
|
if (get_pid(buf, &pid) == -1) {
|
||||||
if (log) {
|
if (log) {
|
||||||
(void) fprintf (shadow_logfd,
|
(void) fprintf (shadow_logfd,
|
||||||
@@ -578,7 +573,9 @@ static void add_one_entry_nis (struct commonio_db *db,
|
|||||||
int commonio_open (struct commonio_db *db, int mode)
|
int commonio_open (struct commonio_db *db, int mode)
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
|
char *cp;
|
||||||
char *line;
|
char *line;
|
||||||
|
struct commonio_entry *p;
|
||||||
void *eptr = NULL;
|
void *eptr = NULL;
|
||||||
int flags = mode;
|
int flags = mode;
|
||||||
size_t buflen;
|
size_t buflen;
|
||||||
@@ -639,21 +636,21 @@ int commonio_open (struct commonio_db *db, int mode)
|
|||||||
|
|
||||||
buflen = BUFLEN;
|
buflen = BUFLEN;
|
||||||
buf = MALLOC(buflen, char);
|
buf = MALLOC(buflen, char);
|
||||||
if (NULL == buf)
|
if (NULL == buf) {
|
||||||
goto cleanup_errno;
|
goto cleanup_ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
while (db->ops->fgets (buf, buflen, db->fp) == buf) {
|
while (db->ops->fgets (buf, buflen, db->fp) == buf) {
|
||||||
struct commonio_entry *p;
|
|
||||||
|
|
||||||
while ( (strrchr (buf, '\n') == NULL)
|
while ( (strrchr (buf, '\n') == NULL)
|
||||||
&& (feof (db->fp) == 0)) {
|
&& (feof (db->fp) == 0)) {
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
buflen += BUFLEN;
|
buflen += BUFLEN;
|
||||||
buf = REALLOCF(buf, buflen, char);
|
cp = REALLOC(buf, buflen, char);
|
||||||
if (NULL == buf)
|
if (NULL == cp) {
|
||||||
goto cleanup_errno;
|
goto cleanup_buf;
|
||||||
|
}
|
||||||
|
buf = cp;
|
||||||
len = strlen (buf);
|
len = strlen (buf);
|
||||||
if (db->ops->fgets (buf + len,
|
if (db->ops->fgets (buf + len,
|
||||||
(int) (buflen - len),
|
(int) (buflen - len),
|
||||||
@@ -661,7 +658,10 @@ int commonio_open (struct commonio_db *db, int mode)
|
|||||||
goto cleanup_buf;
|
goto cleanup_buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stpsep(buf, "\n");
|
cp = strrchr (buf, '\n');
|
||||||
|
if (NULL != cp) {
|
||||||
|
*cp = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
line = strdup (buf);
|
line = strdup (buf);
|
||||||
if (NULL == line) {
|
if (NULL == line) {
|
||||||
@@ -713,6 +713,7 @@ int commonio_open (struct commonio_db *db, int mode)
|
|||||||
free (line);
|
free (line);
|
||||||
cleanup_buf:
|
cleanup_buf:
|
||||||
free (buf);
|
free (buf);
|
||||||
|
cleanup_ENOMEM:
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
cleanup_errno:
|
cleanup_errno:
|
||||||
saved_errno = errno;
|
saved_errno = errno;
|
||||||
@@ -831,8 +832,10 @@ int commonio_sort_wrt (struct commonio_db *shadow,
|
|||||||
if (NULL == spw_ptr->eptr) {
|
if (NULL == spw_ptr->eptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (streq(name, shadow->ops->getname(spw_ptr->eptr)))
|
if (strcmp (name, shadow->ops->getname (spw_ptr->eptr))
|
||||||
|
== 0) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (NULL == spw_ptr) {
|
if (NULL == spw_ptr) {
|
||||||
continue;
|
continue;
|
||||||
@@ -1033,7 +1036,7 @@ static /*@dependent@*/ /*@null@*/struct commonio_entry *next_entry_by_name (
|
|||||||
for (p = pos; NULL != p; p = p->next) {
|
for (p = pos; NULL != p; p = p->next) {
|
||||||
ep = p->eptr;
|
ep = p->eptr;
|
||||||
if ( (NULL != ep)
|
if ( (NULL != ep)
|
||||||
&& streq(db->ops->getname(ep), name)) {
|
&& (strcmp (db->ops->getname (ep), name) == 0)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1239,7 +1242,7 @@ int commonio_rewind (struct commonio_db *db)
|
|||||||
|
|
||||||
if (!db->isopen) {
|
if (!db->isopen) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return NULL;
|
return 0;
|
||||||
}
|
}
|
||||||
if (NULL == db->cursor) {
|
if (NULL == db->cursor) {
|
||||||
db->cursor = db->head;
|
db->cursor = db->head;
|
||||||
|
|||||||
+12
-15
@@ -9,25 +9,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
#include <stdio.h>
|
||||||
#include "getdef.h"
|
#include "getdef.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "string/strcmp/streq.h"
|
#include "string/strtcpy.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
|
* This is now rather generic function which decides if "tty" is listed
|
||||||
* under "cfgin" in config (directly or indirectly). Fallback to default if
|
* under "cfgin" in config (directly or indirectly). Fallback to default if
|
||||||
* something is bad.
|
* something is bad.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool is_listed (const char *cfgin, const char *tty, bool def)
|
||||||
is_listed(const char *cfgin, const char *tty, bool def)
|
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char buf[1024], *s;
|
char buf[1024], *s;
|
||||||
@@ -50,13 +45,14 @@ is_listed(const char *cfgin, const char *tty, bool def)
|
|||||||
|
|
||||||
if (*cons != '/') {
|
if (*cons != '/') {
|
||||||
char *pbuf;
|
char *pbuf;
|
||||||
|
|
||||||
STRTCPY(buf, cons);
|
STRTCPY(buf, cons);
|
||||||
pbuf = buf;
|
pbuf = &buf[0];
|
||||||
while (NULL != (s = strsep(&pbuf, ":"))) {
|
while ((s = strtok (pbuf, ":")) != NULL) {
|
||||||
if (streq(s, tty)) {
|
if (strcmp (s, tty) == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pbuf = NULL;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -76,8 +72,9 @@ is_listed(const char *cfgin, const char *tty, bool def)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
while (fgets (buf, sizeof (buf), fp) != NULL) {
|
while (fgets (buf, sizeof (buf), fp) != NULL) {
|
||||||
stpsep(buf, "\n");
|
/* Remove optional trailing '\n'. */
|
||||||
if (streq(buf, tty)) {
|
buf[strcspn (buf, "\n")] = '\0';
|
||||||
|
if (strcmp (buf, tty) == 0) {
|
||||||
(void) fclose (fp);
|
(void) fclose (fp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+44
-9
@@ -17,11 +17,9 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "alloc/x/xmalloc.h"
|
#include "alloc.h"
|
||||||
#include "attr.h"
|
#include "attr.h"
|
||||||
#include "fs/readlink/areadlink.h"
|
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#ifdef WITH_SELINUX
|
#ifdef WITH_SELINUX
|
||||||
@@ -38,8 +36,7 @@
|
|||||||
#include <attr/libattr.h>
|
#include <attr/libattr.h>
|
||||||
#endif /* WITH_ATTR */
|
#endif /* WITH_ATTR */
|
||||||
#include "shadowlog.h"
|
#include "shadowlog.h"
|
||||||
#include "string/sprintf/xasprintf.h"
|
#include "string/sprintf.h"
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
|
|
||||||
|
|
||||||
static /*@null@*/const char *src_orig;
|
static /*@null@*/const char *src_orig;
|
||||||
@@ -69,6 +66,7 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst,
|
|||||||
const struct stat *statp, const struct timespec mt[],
|
const struct stat *statp, const struct timespec mt[],
|
||||||
uid_t old_uid, uid_t new_uid,
|
uid_t old_uid, uid_t new_uid,
|
||||||
gid_t old_gid, gid_t new_gid);
|
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,
|
static int copy_symlink (const struct path_info *src, const struct path_info *dst,
|
||||||
MAYBE_UNUSED bool reset_selinux,
|
MAYBE_UNUSED bool reset_selinux,
|
||||||
const struct stat *statp, const struct timespec mt[],
|
const struct stat *statp, const struct timespec mt[],
|
||||||
@@ -315,8 +313,8 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info *
|
|||||||
/*
|
/*
|
||||||
* Skip the "." and ".." entries
|
* Skip the "." and ".." entries
|
||||||
*/
|
*/
|
||||||
if (streq(ent->d_name, ".") ||
|
if (strcmp(ent->d_name, ".") == 0 ||
|
||||||
streq(ent->d_name, ".."))
|
strcmp(ent->d_name, "..") == 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -538,6 +536,42 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst,
|
|||||||
return err;
|
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
|
* copy_symlink - copy a symlink
|
||||||
*
|
*
|
||||||
@@ -568,9 +602,10 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds
|
|||||||
* destination directory name.
|
* destination directory name.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
oldlink = areadlink(src->full_path);
|
oldlink = readlink_malloc (src->full_path);
|
||||||
if (NULL == oldlink)
|
if (NULL == oldlink) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* If src was a link to an entry of the src_orig directory itself,
|
/* 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
|
* create a link to the corresponding entry in the dst_orig
|
||||||
|
|||||||
+15
-12
@@ -1,19 +1,21 @@
|
|||||||
// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
|
/*
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-FileCopyrightText: Alejandro Colomar <alx@kernel.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#if HAVE_SYS_RANDOM_H
|
#if HAVE_SYS_RANDOM_H
|
||||||
#include <sys/random.h>
|
#include <sys/random.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "bit.h"
|
#include "bit.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
@@ -32,7 +34,7 @@ static unsigned long csrand_uniform_slow(unsigned long n);
|
|||||||
unsigned long
|
unsigned long
|
||||||
csrand(void)
|
csrand(void)
|
||||||
{
|
{
|
||||||
int fd;
|
FILE *fp;
|
||||||
unsigned long r;
|
unsigned long r;
|
||||||
|
|
||||||
#ifdef HAVE_GETENTROPY
|
#ifdef HAVE_GETENTROPY
|
||||||
@@ -54,16 +56,17 @@ csrand(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Use /dev/urandom as a last resort. */
|
/* Use /dev/urandom as a last resort. */
|
||||||
fd = open("/dev/urandom", O_RDONLY);
|
fp = fopen("/dev/urandom", "r");
|
||||||
if (fd == -1)
|
if (NULL == fp) {
|
||||||
goto fail;
|
|
||||||
|
|
||||||
if (read(fd, &r, sizeof(r)) != sizeof(r)) {
|
|
||||||
close(fd);
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
if (fread(&r, sizeof(r), 1, fp) != 1) {
|
||||||
|
fclose(fp);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|||||||
@@ -16,14 +16,11 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "alloc/x/xmalloc.h"
|
#include "alloc.h"
|
||||||
#include "alloc/x/xrealloc.h"
|
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "shadowlog.h"
|
#include "shadowlog.h"
|
||||||
#include "string/sprintf/snprintf.h"
|
#include "string/sprintf.h"
|
||||||
#include "string/sprintf/xasprintf.h"
|
|
||||||
#include "string/strdup/xstrdup.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+6
-4
@@ -18,10 +18,10 @@
|
|||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "faillog.h"
|
#include "faillog.h"
|
||||||
#include "failure.h"
|
#include "failure.h"
|
||||||
|
#include "memzero.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "string/memset/memzero.h"
|
|
||||||
#include "string/strftime.h"
|
#include "string/strftime.h"
|
||||||
#include "string/strcpy/strtcpy.h"
|
#include "string/strtcpy.h"
|
||||||
|
|
||||||
|
|
||||||
#define YEAR (365L*DAY)
|
#define YEAR (365L*DAY)
|
||||||
@@ -82,7 +82,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
STRTCPY(fl->fail_line, tty);
|
STRTCPY(fl->fail_line, tty);
|
||||||
fl->fail_time = time(NULL);
|
(void) time (&fl->fail_time);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Seek back to the correct position in the file and write the
|
* 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 */
|
return true; /* locked until reset manually */
|
||||||
}
|
}
|
||||||
|
|
||||||
now = time(NULL);
|
(void) time (&now);
|
||||||
if ((fl->fail_time + fl->fail_locktime) < now) {
|
if ((fl->fail_time + fl->fail_locktime) < now) {
|
||||||
return false; /* enough time since last failure */
|
return false; /* enough time since last failure */
|
||||||
}
|
}
|
||||||
@@ -242,12 +242,14 @@ void failprint (const struct faillog *fail)
|
|||||||
struct tm *tp;
|
struct tm *tp;
|
||||||
char lasttimeb[256];
|
char lasttimeb[256];
|
||||||
char *lasttime = lasttimeb;
|
char *lasttime = lasttimeb;
|
||||||
|
time_t NOW;
|
||||||
|
|
||||||
if (0 == fail->fail_cnt) {
|
if (0 == fail->fail_cnt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tp = localtime (&(fail->fail_time));
|
tp = localtime (&(fail->fail_time));
|
||||||
|
(void) time (&NOW);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print all information we have.
|
* Print all information we have.
|
||||||
|
|||||||
+18
-13
@@ -14,13 +14,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "string/strchr/stpspn.h"
|
|
||||||
#include "string/strchr/strrspn.h"
|
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
#include "string/strtok/stpsep.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* valid_field - insure that a field contains all legal characters
|
* valid_field - insure that a field contains all legal characters
|
||||||
@@ -48,7 +42,7 @@ int valid_field (const char *field, const char *illegal)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Search if there are non-printable or control characters */
|
/* Search if there are non-printable or control characters */
|
||||||
for (cp = field; !streq(cp, ""); cp++) {
|
for (cp = field; '\0' != *cp; cp++) {
|
||||||
unsigned char c = *cp;
|
unsigned char c = *cp;
|
||||||
if (!isprint (c)) {
|
if (!isprint (c)) {
|
||||||
err = 1;
|
err = 1;
|
||||||
@@ -68,8 +62,7 @@ int valid_field (const char *field, const char *illegal)
|
|||||||
* prompt the user with the name of the field being changed and the
|
* prompt the user with the name of the field being changed and the
|
||||||
* current value.
|
* current value.
|
||||||
*/
|
*/
|
||||||
void
|
void change_field (char *buf, size_t maxsize, const char *prompt)
|
||||||
change_field(char *buf, size_t maxsize, const char *prompt)
|
|
||||||
{
|
{
|
||||||
char newf[200];
|
char newf[200];
|
||||||
char *cp;
|
char *cp;
|
||||||
@@ -84,17 +77,29 @@ change_field(char *buf, size_t maxsize, const char *prompt)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stpsep(newf, "\n") == NULL)
|
cp = strchr (newf, '\n');
|
||||||
|
if (NULL == cp) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
*cp = '\0';
|
||||||
|
|
||||||
if (!streq(newf, "")) {
|
if ('\0' != newf[0]) {
|
||||||
/*
|
/*
|
||||||
* Remove leading and trailing whitespace. This also
|
* Remove leading and trailing whitespace. This also
|
||||||
* makes it possible to change the field to empty, by
|
* makes it possible to change the field to empty, by
|
||||||
* entering a space. --marekm
|
* entering a space. --marekm
|
||||||
*/
|
*/
|
||||||
stpcpy(strrspn(newf, " \t"), "");
|
|
||||||
cp = stpspn(newf, " \t");
|
while (newf < cp && isspace (cp[-1])) {
|
||||||
|
cp--;
|
||||||
|
}
|
||||||
|
*cp = '\0';
|
||||||
|
|
||||||
|
cp = newf;
|
||||||
|
while (isspace (*cp)) {
|
||||||
|
cp++;
|
||||||
|
}
|
||||||
|
|
||||||
strcpy (buf, cp);
|
strcpy (buf, cp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -9,11 +9,10 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "alloc/calloc.h"
|
#include "alloc.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "groupio.h"
|
#include "groupio.h"
|
||||||
#include "getdef.h"
|
#include "getdef.h"
|
||||||
|
|||||||
+5
-6
@@ -9,11 +9,10 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "alloc/calloc.h"
|
#include "alloc.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "pwio.h"
|
#include "pwio.h"
|
||||||
#include "getdef.h"
|
#include "getdef.h"
|
||||||
@@ -305,7 +304,7 @@ int find_new_uid(bool sys_user,
|
|||||||
return 0;
|
return 0;
|
||||||
} else if (result == EEXIST || result == EINVAL) {
|
} else if (result == EEXIST || result == EINVAL) {
|
||||||
/*
|
/*
|
||||||
* This UID is in use or unusable, we'll
|
* This GID is in use or unusable, we'll
|
||||||
* continue to the next.
|
* continue to the next.
|
||||||
*/
|
*/
|
||||||
} else {
|
} else {
|
||||||
@@ -351,7 +350,7 @@ int find_new_uid(bool sys_user,
|
|||||||
return 0;
|
return 0;
|
||||||
} else if (result == EEXIST || result == EINVAL) {
|
} else if (result == EEXIST || result == EINVAL) {
|
||||||
/*
|
/*
|
||||||
* This UID is in use or unusable, we'll
|
* This GID is in use or unusable, we'll
|
||||||
* continue to the next.
|
* continue to the next.
|
||||||
*/
|
*/
|
||||||
} else {
|
} else {
|
||||||
@@ -414,7 +413,7 @@ int find_new_uid(bool sys_user,
|
|||||||
return 0;
|
return 0;
|
||||||
} else if (result == EEXIST || result == EINVAL) {
|
} else if (result == EEXIST || result == EINVAL) {
|
||||||
/*
|
/*
|
||||||
* This UID is in use or unusable, we'll
|
* This GID is in use or unusable, we'll
|
||||||
* continue to the next.
|
* continue to the next.
|
||||||
*/
|
*/
|
||||||
} else {
|
} else {
|
||||||
@@ -460,7 +459,7 @@ int find_new_uid(bool sys_user,
|
|||||||
return 0;
|
return 0;
|
||||||
} else if (result == EEXIST || result == EINVAL) {
|
} else if (result == EEXIST || result == EINVAL) {
|
||||||
/*
|
/*
|
||||||
* This UID is in use or unusable, we'll
|
* This GID is in use or unusable, we'll
|
||||||
* continue to the next.
|
* continue to the next.
|
||||||
*/
|
*/
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+8
-7
@@ -10,11 +10,10 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
|
#ident "$Id$"
|
||||||
|
|
||||||
|
|
||||||
/*@null@*/char *
|
/*@null@*/char *
|
||||||
@@ -26,7 +25,7 @@ fgetsx(/*@returned@*/char *restrict buf, int cnt, FILE *restrict f)
|
|||||||
while (cnt > 0) {
|
while (cnt > 0) {
|
||||||
if (fgets (cp, cnt, f) != cp) {
|
if (fgets (cp, cnt, f) != cp) {
|
||||||
if (cp == buf) {
|
if (cp == buf) {
|
||||||
return NULL;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -34,8 +33,10 @@ fgetsx(/*@returned@*/char *restrict buf, int cnt, FILE *restrict f)
|
|||||||
ep = strrchr (cp, '\\');
|
ep = strrchr (cp, '\\');
|
||||||
if ((NULL != ep) && (*(ep + 1) == '\n')) {
|
if ((NULL != ep) && (*(ep + 1) == '\n')) {
|
||||||
cnt -= ep - cp;
|
cnt -= ep - cp;
|
||||||
if (cnt > 0)
|
if (cnt > 0) {
|
||||||
cp = stpcpy(ep, "");
|
cp = ep;
|
||||||
|
*cp = '\0';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -47,7 +48,7 @@ int fputsx (const char *s, FILE * stream)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; !streq(s, ""); i++, s++) {
|
for (i = 0; '\0' != *s; i++, s++) {
|
||||||
if (putc (*s, stream) == EOF) {
|
if (putc (*s, stream) == EOF) {
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
// 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);
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
// 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);
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
+38
-10
@@ -1,7 +1,8 @@
|
|||||||
// SPDX-FileCopyrightText: 2009, Nicolas François
|
/*
|
||||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
* SPDX-FileCopyrightText: 2009 , Nicolas François
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -13,10 +14,29 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "atoi/getnum.h"
|
#include "string/sprintf.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
|
* If use passed in fd:4 as an argument, then return the
|
||||||
* value '4', the fd to use.
|
* value '4', the fd to use.
|
||||||
@@ -24,12 +44,20 @@
|
|||||||
*/
|
*/
|
||||||
int get_pidfd_from_fd(const char *pidfdstr)
|
int get_pidfd_from_fd(const char *pidfdstr)
|
||||||
{
|
{
|
||||||
int pidfd;
|
char *end;
|
||||||
|
long long val;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
dev_t proc_st_dev, proc_st_rdev;
|
dev_t proc_st_dev, proc_st_rdev;
|
||||||
|
|
||||||
if (get_fd(pidfdstr, &pidfd) == -1)
|
errno = 0;
|
||||||
|
val = strtoll(pidfdstr, &end, 10);
|
||||||
|
if ( ('\0' == *pidfdstr)
|
||||||
|
|| ('\0' != *end)
|
||||||
|
|| (0 != errno)
|
||||||
|
|| (val < 0)
|
||||||
|
|| (/*@+longintegral@*/val != (int)val)/*@=longintegral@*/) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (stat("/proc/self/uid_map", &st) < 0) {
|
if (stat("/proc/self/uid_map", &st) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -38,7 +66,7 @@ int get_pidfd_from_fd(const char *pidfdstr)
|
|||||||
proc_st_dev = st.st_dev;
|
proc_st_dev = st.st_dev;
|
||||||
proc_st_rdev = st.st_rdev;
|
proc_st_rdev = st.st_rdev;
|
||||||
|
|
||||||
if (fstat(pidfd, &st) < 0) {
|
if (fstat(val, &st) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +74,7 @@ int get_pidfd_from_fd(const char *pidfdstr)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pidfd;
|
return (int)val;
|
||||||
}
|
}
|
||||||
|
|
||||||
int open_pidfd(const char *pidstr)
|
int open_pidfd(const char *pidstr)
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
+22
-23
@@ -24,16 +24,14 @@
|
|||||||
# undef static
|
# undef static
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <ctype.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "attr.h"
|
#include "attr.h"
|
||||||
#include "getdate.h"
|
#include "getdate.h"
|
||||||
#include "string/strchr/stpspn.h"
|
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/* Some old versions of bison generate parsers that use bcopy.
|
/* Some old versions of bison generate parsers that use bcopy.
|
||||||
That loses on systems that don't provide the function, so we have
|
That loses on systems that don't provide the function, so we have
|
||||||
@@ -627,16 +625,16 @@ static int LookupWord (char *buff)
|
|||||||
bool abbrev;
|
bool abbrev;
|
||||||
|
|
||||||
/* Make it lowercase. */
|
/* Make it lowercase. */
|
||||||
for (p = buff; !streq(p, ""); p++)
|
for (p = buff; '\0' != *p; p++)
|
||||||
if (isupper (*p))
|
if (isupper (*p))
|
||||||
*p = tolower (*p);
|
*p = tolower (*p);
|
||||||
|
|
||||||
if (streq(buff, "am") || streq(buff, "a.m."))
|
if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0)
|
||||||
{
|
{
|
||||||
yylval.Meridian = MERam;
|
yylval.Meridian = MERam;
|
||||||
return tMERIDIAN;
|
return tMERIDIAN;
|
||||||
}
|
}
|
||||||
if (streq(buff, "pm") || streq(buff, "p.m."))
|
if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0)
|
||||||
{
|
{
|
||||||
yylval.Meridian = MERpm;
|
yylval.Meridian = MERpm;
|
||||||
return tMERIDIAN;
|
return tMERIDIAN;
|
||||||
@@ -648,7 +646,7 @@ static int LookupWord (char *buff)
|
|||||||
else if (strlen (buff) == 4 && buff[3] == '.')
|
else if (strlen (buff) == 4 && buff[3] == '.')
|
||||||
{
|
{
|
||||||
abbrev = true;
|
abbrev = true;
|
||||||
stpcpy(&buff[3], "");
|
buff[3] = '\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
abbrev = false;
|
abbrev = false;
|
||||||
@@ -663,7 +661,7 @@ static int LookupWord (char *buff)
|
|||||||
return tp->type;
|
return tp->type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (streq(buff, tp->name))
|
else if (strcmp (buff, tp->name) == 0)
|
||||||
{
|
{
|
||||||
yylval.Number = tp->value;
|
yylval.Number = tp->value;
|
||||||
return tp->type;
|
return tp->type;
|
||||||
@@ -671,17 +669,17 @@ static int LookupWord (char *buff)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (tp = TimezoneTable; tp->name; tp++)
|
for (tp = TimezoneTable; tp->name; tp++)
|
||||||
if (streq(buff, tp->name))
|
if (strcmp (buff, tp->name) == 0)
|
||||||
{
|
{
|
||||||
yylval.Number = tp->value;
|
yylval.Number = tp->value;
|
||||||
return tp->type;
|
return tp->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (streq(buff, "dst"))
|
if (strcmp (buff, "dst") == 0)
|
||||||
return tDST;
|
return tDST;
|
||||||
|
|
||||||
for (tp = UnitsTable; tp->name; tp++)
|
for (tp = UnitsTable; tp->name; tp++)
|
||||||
if (streq(buff, tp->name))
|
if (strcmp (buff, tp->name) == 0)
|
||||||
{
|
{
|
||||||
yylval.Number = tp->value;
|
yylval.Number = tp->value;
|
||||||
return tp->type;
|
return tp->type;
|
||||||
@@ -691,9 +689,9 @@ static int LookupWord (char *buff)
|
|||||||
i = strlen (buff) - 1;
|
i = strlen (buff) - 1;
|
||||||
if (buff[i] == 's')
|
if (buff[i] == 's')
|
||||||
{
|
{
|
||||||
stpcpy(&buff[i], "");
|
buff[i] = '\0';
|
||||||
for (tp = UnitsTable; tp->name; tp++)
|
for (tp = UnitsTable; tp->name; tp++)
|
||||||
if (streq(buff, tp->name))
|
if (strcmp (buff, tp->name) == 0)
|
||||||
{
|
{
|
||||||
yylval.Number = tp->value;
|
yylval.Number = tp->value;
|
||||||
return tp->type;
|
return tp->type;
|
||||||
@@ -702,7 +700,7 @@ static int LookupWord (char *buff)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (tp = OtherTable; tp->name; tp++)
|
for (tp = OtherTable; tp->name; tp++)
|
||||||
if (streq(buff, tp->name))
|
if (strcmp (buff, tp->name) == 0)
|
||||||
{
|
{
|
||||||
yylval.Number = tp->value;
|
yylval.Number = tp->value;
|
||||||
return tp->type;
|
return tp->type;
|
||||||
@@ -712,7 +710,7 @@ static int LookupWord (char *buff)
|
|||||||
if (buff[1] == '\0' && isalpha (*buff))
|
if (buff[1] == '\0' && isalpha (*buff))
|
||||||
{
|
{
|
||||||
for (tp = MilitaryTable; tp->name; tp++)
|
for (tp = MilitaryTable; tp->name; tp++)
|
||||||
if (streq(buff, tp->name))
|
if (strcmp (buff, tp->name) == 0)
|
||||||
{
|
{
|
||||||
yylval.Number = tp->value;
|
yylval.Number = tp->value;
|
||||||
return tp->type;
|
return tp->type;
|
||||||
@@ -720,15 +718,15 @@ static int LookupWord (char *buff)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Drop out any periods and try the timezone table again. */
|
/* Drop out any periods and try the timezone table again. */
|
||||||
for (i = 0, p = q = buff; !streq(q, ""); q++)
|
for (i = 0, p = q = buff; '\0' != *q; q++)
|
||||||
if (*q != '.')
|
if (*q != '.')
|
||||||
*p++ = *q;
|
*p++ = *q;
|
||||||
else
|
else
|
||||||
i++;
|
i++;
|
||||||
stpcpy(p, "");
|
*p = '\0';
|
||||||
if (0 != i)
|
if (0 != i)
|
||||||
for (tp = TimezoneTable; NULL != tp->name; tp++)
|
for (tp = TimezoneTable; NULL != tp->name; tp++)
|
||||||
if (streq(buff, tp->name))
|
if (strcmp (buff, tp->name) == 0)
|
||||||
{
|
{
|
||||||
yylval.Number = tp->value;
|
yylval.Number = tp->value;
|
||||||
return tp->type;
|
return tp->type;
|
||||||
@@ -748,7 +746,8 @@ yylex (void)
|
|||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
yyInput = stpspn(yyInput, " \t");
|
while (isspace (*yyInput))
|
||||||
|
yyInput++;
|
||||||
|
|
||||||
if (isdigit (c = *yyInput) || c == '-' || c == '+')
|
if (isdigit (c = *yyInput) || c == '-' || c == '+')
|
||||||
{
|
{
|
||||||
@@ -773,7 +772,7 @@ yylex (void)
|
|||||||
for (p = buff; (c = *yyInput++, isalpha (c)) || c == '.';)
|
for (p = buff; (c = *yyInput++, isalpha (c)) || c == '.';)
|
||||||
if (p < &buff[sizeof buff - 1])
|
if (p < &buff[sizeof buff - 1])
|
||||||
*p++ = c;
|
*p++ = c;
|
||||||
stpcpy(p, "");
|
*p = '\0';
|
||||||
yyInput--;
|
yyInput--;
|
||||||
return LookupWord (buff);
|
return LookupWord (buff);
|
||||||
}
|
}
|
||||||
@@ -822,7 +821,7 @@ time_t get_date (const char *p, const time_t *now)
|
|||||||
time_t Start;
|
time_t Start;
|
||||||
|
|
||||||
yyInput = p;
|
yyInput = p;
|
||||||
Start = now ? *now : time(NULL);
|
Start = now ? *now : time ((time_t *) NULL);
|
||||||
tmp = localtime (&Start);
|
tmp = localtime (&Start);
|
||||||
yyYear = tmp->tm_year + TM_YEAR_ORIGIN;
|
yyYear = tmp->tm_year + TM_YEAR_ORIGIN;
|
||||||
yyMonth = tmp->tm_mon + 1;
|
yyMonth = tmp->tm_mon + 1;
|
||||||
@@ -936,7 +935,7 @@ main(void)
|
|||||||
buff[MAX_BUFF_LEN] = 0;
|
buff[MAX_BUFF_LEN] = 0;
|
||||||
while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
|
while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
|
||||||
{
|
{
|
||||||
d = get_date(buff, NULL);
|
d = get_date (buff, (time_t *) NULL);
|
||||||
if (d == -1)
|
if (d == -1)
|
||||||
(void) printf ("Bad format - couldn't convert.\n");
|
(void) printf ("Bad format - couldn't convert.\n");
|
||||||
else
|
else
|
||||||
|
|||||||
+38
-34
@@ -11,29 +11,22 @@
|
|||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include "prototypes.h"
|
||||||
#include <errno.h>
|
#include "defines.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
#ifdef USE_ECONF
|
#ifdef USE_ECONF
|
||||||
#include <libeconf.h>
|
#include <libeconf.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "atoi/a2i/a2s.h"
|
#include "alloc.h"
|
||||||
#include "atoi/a2i/a2u.h"
|
#include "atoi/str2i.h"
|
||||||
#include "atoi/str2i/str2u.h"
|
|
||||||
#include "defines.h"
|
|
||||||
#include "getdef.h"
|
#include "getdef.h"
|
||||||
#include "prototypes.h"
|
|
||||||
#include "shadowlog_internal.h"
|
#include "shadowlog_internal.h"
|
||||||
#include "string/sprintf/xasprintf.h"
|
#include "string/sprintf.h"
|
||||||
#include "string/strchr/stpspn.h"
|
|
||||||
#include "string/strchr/strrspn.h"
|
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
#include "string/strtok/stpsep.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -158,6 +151,7 @@ static struct itemdef def_table[] = {
|
|||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define NUMKNOWNDEFS (sizeof(knowndef_table)/sizeof(knowndef_table[0]))
|
||||||
static struct itemdef knowndef_table[] = {
|
static struct itemdef knowndef_table[] = {
|
||||||
#ifdef USE_PAM
|
#ifdef USE_PAM
|
||||||
PAMDEFS
|
PAMDEFS
|
||||||
@@ -238,11 +232,10 @@ bool getdef_bool (const char *item)
|
|||||||
* values are handled.
|
* values are handled.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int getdef_num (const char *item, int dflt)
|
||||||
getdef_num(const char *item, int dflt)
|
|
||||||
{
|
{
|
||||||
int val;
|
struct itemdef *d;
|
||||||
struct itemdef *d;
|
long val;
|
||||||
|
|
||||||
if (!def_loaded) {
|
if (!def_loaded) {
|
||||||
def_load ();
|
def_load ();
|
||||||
@@ -253,7 +246,9 @@ getdef_num(const char *item, int dflt)
|
|||||||
return dflt;
|
return dflt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a2si(&val, d->value, NULL, 0, -1, INT_MAX) == -1) {
|
if ( (str2sl(&val, d->value) == -1)
|
||||||
|
|| (val > INT_MAX)
|
||||||
|
|| (val < -1)) {
|
||||||
fprintf (shadow_logfd,
|
fprintf (shadow_logfd,
|
||||||
_("configuration error - cannot parse %s value: '%s'"),
|
_("configuration error - cannot parse %s value: '%s'"),
|
||||||
item, d->value);
|
item, d->value);
|
||||||
@@ -272,11 +267,10 @@ getdef_num(const char *item, int dflt)
|
|||||||
* values are handled.
|
* values are handled.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned int
|
unsigned int getdef_unum (const char *item, unsigned int dflt)
|
||||||
getdef_unum(const char *item, unsigned int dflt)
|
|
||||||
{
|
{
|
||||||
unsigned int val;
|
struct itemdef *d;
|
||||||
struct itemdef *d;
|
long val;
|
||||||
|
|
||||||
if (!def_loaded) {
|
if (!def_loaded) {
|
||||||
def_load ();
|
def_load ();
|
||||||
@@ -287,7 +281,9 @@ getdef_unum(const char *item, unsigned int dflt)
|
|||||||
return dflt;
|
return dflt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a2ui(&val, d->value, NULL, 0, 0, UINT_MAX) == -1) {
|
if ( (str2sl(&val, d->value) == -1)
|
||||||
|
|| (val < 0)
|
||||||
|
|| (val > INT_MAX)) {
|
||||||
fprintf (shadow_logfd,
|
fprintf (shadow_logfd,
|
||||||
_("configuration error - cannot parse %s value: '%s'"),
|
_("configuration error - cannot parse %s value: '%s'"),
|
||||||
item, d->value);
|
item, d->value);
|
||||||
@@ -320,7 +316,7 @@ long getdef_long (const char *item, long dflt)
|
|||||||
return dflt;
|
return dflt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a2sl(&val, d->value, NULL, 0, -1, LONG_MAX) == -1) {
|
if (str2sl(&val, d->value) == -1 || val < -1) {
|
||||||
fprintf (shadow_logfd,
|
fprintf (shadow_logfd,
|
||||||
_("configuration error - cannot parse %s value: '%s'"),
|
_("configuration error - cannot parse %s value: '%s'"),
|
||||||
item, d->value);
|
item, d->value);
|
||||||
@@ -420,7 +416,7 @@ static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name, cons
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (ptr = def_table; NULL != ptr->name; ptr++) {
|
for (ptr = def_table; NULL != ptr->name; ptr++) {
|
||||||
if (streq(ptr->name, name)) {
|
if (strcmp (ptr->name, name) == 0) {
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -430,7 +426,7 @@ static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name, cons
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (ptr = knowndef_table; NULL != ptr->name; ptr++) {
|
for (ptr = knowndef_table; NULL != ptr->name; ptr++) {
|
||||||
if (streq(ptr->name, name)) {
|
if (strcmp (ptr->name, name) == 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -530,6 +526,7 @@ static void def_load (void)
|
|||||||
#else /* USE_ECONF */
|
#else /* USE_ECONF */
|
||||||
static void def_load (void)
|
static void def_load (void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char buf[1024], *name, *value, *s;
|
char buf[1024], *name, *value, *s;
|
||||||
|
|
||||||
@@ -561,21 +558,28 @@ static void def_load (void)
|
|||||||
/*
|
/*
|
||||||
* Trim trailing whitespace.
|
* Trim trailing whitespace.
|
||||||
*/
|
*/
|
||||||
stpcpy(strrspn(buf, " \t\n"), "");
|
for (i = (ptrdiff_t) strlen (buf) - 1; i >= 0; --i) {
|
||||||
|
if (!isspace (buf[i])) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
buf[i] = '\0';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Break the line into two fields.
|
* Break the line into two fields.
|
||||||
*/
|
*/
|
||||||
name = stpspn(buf, " \t"); /* first nonwhite */
|
name = buf + strspn (buf, " \t"); /* first nonwhite */
|
||||||
if (streq(name, "") || *name == '#')
|
if (*name == '\0' || *name == '#')
|
||||||
continue; /* comment or empty */
|
continue; /* comment or empty */
|
||||||
|
|
||||||
s = stpsep(name, " \t"); /* next field */
|
s = name + strcspn (name, " \t"); /* end of field */
|
||||||
if (s == NULL)
|
if (*s == '\0')
|
||||||
continue; /* only 1 field?? */
|
continue; /* only 1 field?? */
|
||||||
|
|
||||||
value = stpspn(s, " \"\t"); /* next nonwhite */
|
*s++ = '\0';
|
||||||
stpsep(value, "\"");
|
value = s + strspn (s, " \"\t"); /* next nonwhite */
|
||||||
|
*(value + strcspn (value, "\"")) = '\0';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Store the value in def_table.
|
* Store the value in def_table.
|
||||||
|
|||||||
+22
-18
@@ -1,10 +1,11 @@
|
|||||||
// SPDX-FileCopyrightText: 1991-1994, Julianne Frances Haugh
|
/*
|
||||||
// SPDX-FileCopyrightText: 1996-2000, Marek Michałkiewicz
|
* SPDX-FileCopyrightText: 1991 - 1994, Julianne Frances Haugh
|
||||||
// SPDX-FileCopyrightText: 2000-2006, Tomasz Kłoczko
|
* SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz
|
||||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
* SPDX-FileCopyrightText: 2000 - 2006, Tomasz Kłoczko
|
||||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
* SPDX-FileCopyrightText: 2007 - 2009, Nicolas François
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -13,27 +14,30 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include "atoi/getnum.h"
|
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* getgr_nam_gid - Return a pointer to the group specified by a string.
|
* getgr_nam_gid - Return a pointer to the group specified by a string.
|
||||||
* The string may be a valid GID or a valid groupname.
|
* The string may be a valid GID or a valid groupname.
|
||||||
* If the group does not exist on the system, NULL is returned.
|
* If the group does not exist on the system, NULL is returned.
|
||||||
*/
|
*/
|
||||||
extern /*@only@*//*@null@*/struct group *
|
extern /*@only@*//*@null@*/struct group *getgr_nam_gid (/*@null@*/const char *grname)
|
||||||
getgr_nam_gid(/*@null@*/const char *grname)
|
|
||||||
{
|
{
|
||||||
gid_t gid;
|
char *end;
|
||||||
|
long long gid;
|
||||||
|
|
||||||
if (NULL == grname)
|
if (NULL == grname) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (get_gid(grname, &gid) == 0)
|
errno = 0;
|
||||||
return xgetgrgid(gid);
|
gid = strtoll(grname, &end, 10);
|
||||||
return xgetgrnam(grname);
|
if ( ('\0' != *grname)
|
||||||
|
&& ('\0' == *end)
|
||||||
|
&& (0 == errno)
|
||||||
|
&& (/*@+longintegral@*/gid == (gid_t)gid)/*@=longintegral@*/) {
|
||||||
|
return xgetgrgid (gid);
|
||||||
|
}
|
||||||
|
return xgetgrnam (grname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -10,10 +10,9 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "atoi/a2i/a2u.h"
|
#include "atoi/a2i.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -54,7 +53,7 @@ getrange(const char *range,
|
|||||||
return 0; /* <long> */
|
return 0; /* <long> */
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
if (streq(end, ""))
|
if ('\0' == *end)
|
||||||
return 0; /* <long>- */
|
return 0; /* <long>- */
|
||||||
parse_max:
|
parse_max:
|
||||||
if (!isdigit((unsigned char) *end))
|
if (!isdigit((unsigned char) *end))
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "atoi/a2i/a2i.h"
|
#include "atoi/a2i.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "shadowlog.h"
|
#include "shadowlog.h"
|
||||||
|
|||||||
+7
-9
@@ -15,14 +15,12 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "alloc/calloc.h"
|
#include "alloc.h"
|
||||||
#include "alloc/malloc.h"
|
#include "prototypes.h"
|
||||||
#include "commonio.h"
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
#include "commonio.h"
|
||||||
#include "getdef.h"
|
#include "getdef.h"
|
||||||
#include "groupio.h"
|
#include "groupio.h"
|
||||||
#include "prototypes.h"
|
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
|
|
||||||
|
|
||||||
static /*@null@*/struct commonio_entry *merge_group_entries (
|
static /*@null@*/struct commonio_entry *merge_group_entries (
|
||||||
@@ -264,8 +262,8 @@ static int group_open_hook (void)
|
|||||||
struct group *g2 = gr2->eptr;
|
struct group *g2 = gr2->eptr;
|
||||||
if (NULL != g1 &&
|
if (NULL != g1 &&
|
||||||
NULL != g2 &&
|
NULL != g2 &&
|
||||||
streq(g1->gr_name, g2->gr_name) &&
|
0 == strcmp (g1->gr_name, g2->gr_name) &&
|
||||||
streq(g1->gr_passwd, g2->gr_passwd) &&
|
0 == strcmp (g1->gr_passwd, g2->gr_passwd) &&
|
||||||
g1->gr_gid == g2->gr_gid) {
|
g1->gr_gid == g2->gr_gid) {
|
||||||
/* Both group entries refer to the same
|
/* Both group entries refer to the same
|
||||||
* group. It is a split group. Merge the
|
* group. It is a split group. Merge the
|
||||||
@@ -333,7 +331,7 @@ static /*@null@*/struct commonio_entry *merge_group_entries (
|
|||||||
for (i=0; NULL != gptr2->gr_mem[i]; i++) {
|
for (i=0; NULL != gptr2->gr_mem[i]; i++) {
|
||||||
char **pmember = gptr1->gr_mem;
|
char **pmember = gptr1->gr_mem;
|
||||||
while (NULL != *pmember) {
|
while (NULL != *pmember) {
|
||||||
if (streq(*pmember, gptr2->gr_mem[i])) {
|
if (0 == strcmp(*pmember, gptr2->gr_mem[i])) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pmember++;
|
pmember++;
|
||||||
@@ -356,7 +354,7 @@ static /*@null@*/struct commonio_entry *merge_group_entries (
|
|||||||
for (i=0; NULL != gptr2->gr_mem[i]; i++) {
|
for (i=0; NULL != gptr2->gr_mem[i]; i++) {
|
||||||
char **pmember = new_members;
|
char **pmember = new_members;
|
||||||
while (NULL != *pmember) {
|
while (NULL != *pmember) {
|
||||||
if (streq(*pmember, gptr2->gr_mem[i])) {
|
if (0 == strcmp(*pmember, gptr2->gr_mem[i])) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pmember++;
|
pmember++;
|
||||||
|
|||||||
+6
-7
@@ -12,13 +12,11 @@
|
|||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
#include "alloc/calloc.h"
|
#include "alloc.h"
|
||||||
#include "alloc/malloc.h"
|
#include "memzero.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "groupio.h"
|
#include "groupio.h"
|
||||||
#include "string/memset/memzero.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*@null@*/ /*@only@*/struct group *__gr_dup (const struct group *grent)
|
/*@null@*/ /*@only@*/struct group *__gr_dup (const struct group *grent)
|
||||||
{
|
{
|
||||||
@@ -83,9 +81,10 @@ void
|
|||||||
gr_free(/*@only@*/struct group *grent)
|
gr_free(/*@only@*/struct group *grent)
|
||||||
{
|
{
|
||||||
free (grent->gr_name);
|
free (grent->gr_name);
|
||||||
if (NULL != grent->gr_passwd)
|
if (NULL != grent->gr_passwd) {
|
||||||
free(strzero(grent->gr_passwd));
|
strzero (grent->gr_passwd);
|
||||||
|
free (grent->gr_passwd);
|
||||||
|
}
|
||||||
gr_free_members(grent);
|
gr_free_members(grent);
|
||||||
free (grent);
|
free (grent);
|
||||||
}
|
}
|
||||||
|
|||||||
+100
-66
@@ -14,40 +14,45 @@
|
|||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "alloc/malloc.h"
|
#include "alloc.h"
|
||||||
#include "alloc/realloc.h"
|
|
||||||
#include "alloc/x/xmalloc.h"
|
|
||||||
#include "defines.h"
|
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "string/strchr/strchrcnt.h"
|
#include "defines.h"
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
#include "string/strtok/stpsep.h"
|
|
||||||
|
|
||||||
|
|
||||||
static /*@null@*/FILE *shadow;
|
static /*@null@*/FILE *shadow;
|
||||||
static struct sgrp sgroup = {};
|
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;
|
||||||
|
|
||||||
#define FIELDS 4
|
#define FIELDS 4
|
||||||
|
|
||||||
|
|
||||||
static /*@null@*/char **
|
static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist)
|
||||||
build_list(char *s)
|
|
||||||
{
|
{
|
||||||
char **l;
|
char **ptr = *list;
|
||||||
size_t i;
|
size_t nelem = *nlist, size;
|
||||||
|
|
||||||
l = XMALLOC(strchrcnt(s, ',') + 2, char *);
|
while (s != NULL && *s != '\0') {
|
||||||
|
size = (nelem + 1) * sizeof (ptr);
|
||||||
for (i = 0; s != NULL && !streq(s, ""); i++)
|
ptr = REALLOC(*list, size, char *);
|
||||||
l[i] = strsep(&s, ",");
|
if (NULL != ptr) {
|
||||||
|
ptr[nelem] = strsep(&s, ",");
|
||||||
l[i] = NULL;
|
nelem++;
|
||||||
|
*list = ptr;
|
||||||
return l;
|
*nlist = nelem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
size = (nelem + 1) * sizeof (ptr);
|
||||||
|
ptr = REALLOC(*list, size, char *);
|
||||||
|
if (NULL != ptr) {
|
||||||
|
ptr[nelem] = NULL;
|
||||||
|
*list = ptr;
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setsgent (void)
|
void setsgent (void)
|
||||||
@@ -55,7 +60,7 @@ void setsgent (void)
|
|||||||
if (NULL != shadow) {
|
if (NULL != shadow) {
|
||||||
rewind (shadow);
|
rewind (shadow);
|
||||||
} else {
|
} else {
|
||||||
shadow = fopen (SGROUP_FILE, "re");
|
shadow = fopen (SGROUP_FILE, "r");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,8 +73,7 @@ void endsgent (void)
|
|||||||
shadow = NULL;
|
shadow = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@observer@*//*@null@*/struct sgrp *
|
/*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *string)
|
||||||
sgetsgent(const char *string)
|
|
||||||
{
|
{
|
||||||
static char *sgrbuf = NULL;
|
static char *sgrbuf = NULL;
|
||||||
static size_t sgrbuflen = 0;
|
static size_t sgrbuflen = 0;
|
||||||
@@ -81,15 +85,19 @@ sgetsgent(const char *string)
|
|||||||
|
|
||||||
if (len > sgrbuflen) {
|
if (len > sgrbuflen) {
|
||||||
char *buf = REALLOC(sgrbuf, len, char);
|
char *buf = REALLOC(sgrbuf, len, char);
|
||||||
if (NULL == buf)
|
if (NULL == buf) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
sgrbuf = buf;
|
sgrbuf = buf;
|
||||||
sgrbuflen = len;
|
sgrbuflen = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy (sgrbuf, string);
|
strcpy (sgrbuf, string);
|
||||||
stpsep(sgrbuf, "\n");
|
|
||||||
|
cp = strrchr (sgrbuf, '\n');
|
||||||
|
if (NULL != cp) {
|
||||||
|
*cp = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There should be exactly 4 colon separated fields. Find
|
* There should be exactly 4 colon separated fields. Find
|
||||||
@@ -105,16 +113,22 @@ sgetsgent(const char *string)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (NULL != cp || i != FIELDS)
|
if (NULL != cp || i != FIELDS)
|
||||||
return NULL;
|
return 0;
|
||||||
|
|
||||||
sgroup.sg_name = fields[0];
|
sgroup.sg_name = fields[0];
|
||||||
sgroup.sg_passwd = fields[1];
|
sgroup.sg_passwd = fields[1];
|
||||||
|
if (0 != nadmins) {
|
||||||
free(sgroup.sg_adm);
|
nadmins = 0;
|
||||||
free(sgroup.sg_mem);
|
free (admins);
|
||||||
|
admins = NULL;
|
||||||
sgroup.sg_adm = build_list(fields[2]);
|
}
|
||||||
sgroup.sg_mem = build_list(fields[3]);
|
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);
|
||||||
|
|
||||||
return &sgroup;
|
return &sgroup;
|
||||||
}
|
}
|
||||||
@@ -145,29 +159,32 @@ sgetsgent(const char *string)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fgetsx(buf, buflen, fp) == NULL)
|
if (fgetsx(buf, buflen, fp) == buf) {
|
||||||
return NULL;
|
while ( ((cp = strrchr (buf, '\n')) == NULL)
|
||||||
|
&& (feof (fp) == 0)) {
|
||||||
|
size_t len;
|
||||||
|
|
||||||
while ( (strrchr(buf, '\n') == NULL)
|
cp = REALLOC(buf, buflen * 2, char);
|
||||||
&& (feof (fp) == 0)) {
|
if (NULL == cp) {
|
||||||
size_t len;
|
return NULL;
|
||||||
|
}
|
||||||
|
buf = cp;
|
||||||
|
buflen *= 2;
|
||||||
|
|
||||||
cp = REALLOC(buf, buflen * 2, char);
|
len = strlen (buf);
|
||||||
if (NULL == cp) {
|
if (fgetsx (&buf[len],
|
||||||
return NULL;
|
(int) (buflen - len),
|
||||||
|
fp) != &buf[len]) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buf = cp;
|
cp = strrchr (buf, '\n');
|
||||||
buflen *= 2;
|
if (NULL != cp) {
|
||||||
|
*cp = '\0';
|
||||||
len = strlen (buf);
|
|
||||||
if (fgetsx (&buf[len],
|
|
||||||
(int) (buflen - len),
|
|
||||||
fp) != &buf[len]) {
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
return (sgetsgent (buf));
|
||||||
}
|
}
|
||||||
stpsep(buf, "\n");
|
return NULL;
|
||||||
return (sgetsgent (buf));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -193,7 +210,7 @@ sgetsgent(const char *string)
|
|||||||
setsgent ();
|
setsgent ();
|
||||||
|
|
||||||
while ((sgrp = getsgent ()) != NULL) {
|
while ((sgrp = getsgent ()) != NULL) {
|
||||||
if (streq(name, sgrp->sg_name)) {
|
if (strcmp (name, sgrp->sg_name) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,36 +253,53 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
|
|||||||
/*
|
/*
|
||||||
* Copy the group name and passwd.
|
* Copy the group name and passwd.
|
||||||
*/
|
*/
|
||||||
cp = stpcpy(stpcpy(cp, sgrp->sg_name), ":");
|
|
||||||
cp = stpcpy(stpcpy(cp, sgrp->sg_passwd), ":");
|
strcpy (cp, sgrp->sg_name);
|
||||||
|
cp += strlen (cp);
|
||||||
|
*cp++ = ':';
|
||||||
|
|
||||||
|
strcpy (cp, sgrp->sg_passwd);
|
||||||
|
cp += strlen (cp);
|
||||||
|
*cp++ = ':';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy the administrators, separating each from the other
|
* Copy the administrators, separating each from the other
|
||||||
* with a ",".
|
* with a ",".
|
||||||
*/
|
*/
|
||||||
for (i = 0; NULL != sgrp->sg_adm[i]; i++) {
|
|
||||||
if (i > 0)
|
|
||||||
cp = stpcpy(cp, ",");
|
|
||||||
|
|
||||||
cp = stpcpy(cp, sgrp->sg_adm[i]);
|
for (i = 0; NULL != sgrp->sg_adm[i]; i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
*cp++ = ',';
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy (cp, sgrp->sg_adm[i]);
|
||||||
|
cp += strlen (cp);
|
||||||
}
|
}
|
||||||
cp = stpcpy(cp, ":");
|
*cp = ':';
|
||||||
|
cp++;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now do likewise with the group members.
|
* Now do likewise with the group members.
|
||||||
*/
|
*/
|
||||||
for (i = 0; NULL != sgrp->sg_mem[i]; i++) {
|
|
||||||
if (i > 0)
|
|
||||||
cp = stpcpy(cp, ",");
|
|
||||||
|
|
||||||
cp = stpcpy(cp, sgrp->sg_mem[i]);
|
for (i = 0; NULL != sgrp->sg_mem[i]; i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
*cp = ',';
|
||||||
|
cp++;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy (cp, sgrp->sg_mem[i]);
|
||||||
|
cp += strlen (cp);
|
||||||
}
|
}
|
||||||
stpcpy(cp, "\n");
|
*cp = '\n';
|
||||||
|
cp++;
|
||||||
|
*cp = '\0';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Output using the function which understands the line
|
* Output using the function which understands the line
|
||||||
* continuation conventions.
|
* continuation conventions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (fputsx (buf, fp) == EOF) {
|
if (fputsx (buf, fp) == EOF) {
|
||||||
free (buf);
|
free (buf);
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ struct sgrp {
|
|||||||
|
|
||||||
#include <stdio.h> /* for FILE */
|
#include <stdio.h> /* for FILE */
|
||||||
|
|
||||||
|
#if __STDC__
|
||||||
/*@observer@*//*@null@*/struct sgrp *getsgent (void);
|
/*@observer@*//*@null@*/struct sgrp *getsgent (void);
|
||||||
/*@observer@*//*@null@*/struct sgrp *getsgnam (const char *);
|
/*@observer@*//*@null@*/struct sgrp *getsgnam (const char *);
|
||||||
/*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *);
|
/*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *);
|
||||||
@@ -37,6 +38,15 @@ struct sgrp {
|
|||||||
void setsgent (void);
|
void setsgent (void);
|
||||||
void endsgent (void);
|
void endsgent (void);
|
||||||
int putsgent (const struct sgrp *, FILE *);
|
int putsgent (const struct sgrp *, FILE *);
|
||||||
|
#else
|
||||||
|
/*@observer@*//*@null@*/struct sgrp *getsgent ();
|
||||||
|
/*@observer@*//*@null@*/struct sgrp *getsgnam ();
|
||||||
|
/*@observer@*//*@null@*/struct sgrp *sgetsgent ();
|
||||||
|
/*@observer@*//*@null@*/struct sgrp *fgetsgent ();
|
||||||
|
void setsgent ();
|
||||||
|
void endsgent ();
|
||||||
|
int putsgent ();
|
||||||
|
#endif
|
||||||
|
|
||||||
#define GSHADOW "/etc/gshadow"
|
#define GSHADOW "/etc/gshadow"
|
||||||
#endif /* ifndef _H_GSHADOW */
|
#endif /* ifndef _H_GSHADOW */
|
||||||
|
|||||||
+7
-11
@@ -12,17 +12,13 @@
|
|||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "getdef.h"
|
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "string/sprintf/snprintf.h"
|
#include "getdef.h"
|
||||||
#include "string/strcmp/streq.h"
|
#include "string/sprintf.h"
|
||||||
#include "string/strtok/stpsep.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -74,9 +70,9 @@ bool hushed (const char *username)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (found = false; !found && (fgets (buf, sizeof buf, fp) == buf);) {
|
for (found = false; !found && (fgets (buf, sizeof buf, fp) == buf);) {
|
||||||
stpsep(buf, "\n");
|
buf[strcspn (buf, "\n")] = '\0';
|
||||||
found = streq(buf, pw->pw_shell) ||
|
found = (strcmp (buf, pw->pw_shell) == 0) ||
|
||||||
streq(buf, pw->pw_name);
|
(strcmp (buf, pw->pw_name) == 0);
|
||||||
}
|
}
|
||||||
(void) fclose (fp);
|
(void) fclose (fp);
|
||||||
return found;
|
return found;
|
||||||
|
|||||||
+39
-26
@@ -12,26 +12,24 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
|
#include "alloc.h"
|
||||||
|
#include "atoi/str2i.h"
|
||||||
|
#include "prototypes.h"
|
||||||
|
#include "string/stpeprintf.h"
|
||||||
|
#include "idmapping.h"
|
||||||
#if HAVE_SYS_CAPABILITY_H
|
#if HAVE_SYS_CAPABILITY_H
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
#include <sys/capability.h>
|
#include <sys/capability.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "alloc/calloc.h"
|
|
||||||
#include "alloc/x/xmalloc.h"
|
|
||||||
#include "atoi/a2i/a2u.h"
|
|
||||||
#include "idmapping.h"
|
|
||||||
#include "prototypes.h"
|
|
||||||
#include "shadowlog.h"
|
#include "shadowlog.h"
|
||||||
#include "sizeof.h"
|
#include "sizeof.h"
|
||||||
#include "string/sprintf/stpeprintf.h"
|
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
|
|
||||||
|
|
||||||
struct map_range *
|
struct map_range *get_map_ranges(int ranges, int argc, char **argv)
|
||||||
get_map_ranges(int ranges, int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
struct map_range *mappings, *m;
|
struct map_range *mappings, *mapping;
|
||||||
|
int idx, argidx;
|
||||||
|
|
||||||
if (ranges < 0 || argc < 0) {
|
if (ranges < 0 || argc < 0) {
|
||||||
fprintf(log_get_logfd(), "%s: error calculating number of arguments\n", log_get_progname());
|
fprintf(log_get_logfd(), "%s: error calculating number of arguments\n", log_get_progname());
|
||||||
@@ -47,30 +45,45 @@ get_map_ranges(int ranges, int argc, char **argv)
|
|||||||
if (!mappings) {
|
if (!mappings) {
|
||||||
fprintf(log_get_logfd(), _( "%s: Memory allocation failure\n"),
|
fprintf(log_get_logfd(), _( "%s: Memory allocation failure\n"),
|
||||||
log_get_progname());
|
log_get_progname());
|
||||||
return NULL;
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gather up the ranges from the command line */
|
/* Gather up the ranges from the command line */
|
||||||
m = mappings;
|
mapping = mappings;
|
||||||
for (int i = 0; i < ranges * 3; i+=3, m++) {
|
for (idx = 0, argidx = 0; idx < ranges; idx++, argidx += 3, mapping++) {
|
||||||
if (a2ul(&m->upper, argv[i + 0], NULL, 0, 0, UINT_MAX - 1) == -1) {
|
if (str2ul(&mapping->upper, argv[argidx + 0]) == -1) {
|
||||||
if (errno == ERANGE)
|
|
||||||
fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
|
|
||||||
free(mappings);
|
free(mappings);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (a2ul(&m->lower, argv[i + 1], NULL, 0, 0, UINT_MAX - 1) == -1) {
|
if (str2ul(&mapping->lower, argv[argidx + 1]) == -1) {
|
||||||
if (errno == ERANGE)
|
|
||||||
fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
|
|
||||||
free(mappings);
|
free(mappings);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (a2ul(&m->count, argv[i + 2], NULL, 0, 1, UINT_MAX - MAX(m->lower, m->upper)) == -1) {
|
if (str2ul(&mapping->count, argv[argidx + 2]) == -1) {
|
||||||
if (errno == ERANGE)
|
|
||||||
fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
|
|
||||||
free(mappings);
|
free(mappings);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (ULONG_MAX - mapping->upper <= mapping->count || ULONG_MAX - mapping->lower <= mapping->count) {
|
||||||
|
fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (mapping->upper > UINT_MAX ||
|
||||||
|
mapping->lower > UINT_MAX ||
|
||||||
|
mapping->count > UINT_MAX) {
|
||||||
|
fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (mapping->lower + mapping->count > UINT_MAX ||
|
||||||
|
mapping->upper + mapping->count > UINT_MAX) {
|
||||||
|
fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (mapping->lower + mapping->count < mapping->lower ||
|
||||||
|
mapping->upper + mapping->count < mapping->upper) {
|
||||||
|
/* this one really shouldn't be possible given previous checks */
|
||||||
|
fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return mappings;
|
return mappings;
|
||||||
}
|
}
|
||||||
@@ -134,9 +147,9 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings
|
|||||||
struct __user_cap_header_struct hdr = {_LINUX_CAPABILITY_VERSION_3, 0};
|
struct __user_cap_header_struct hdr = {_LINUX_CAPABILITY_VERSION_3, 0};
|
||||||
struct __user_cap_data_struct data[2] = {{0}};
|
struct __user_cap_data_struct data[2] = {{0}};
|
||||||
|
|
||||||
if (streq(map_file, "uid_map")) {
|
if (strcmp(map_file, "uid_map") == 0) {
|
||||||
cap = CAP_SETUID;
|
cap = CAP_SETUID;
|
||||||
} else if (streq(map_file, "gid_map")) {
|
} else if (strcmp(map_file, "gid_map") == 0) {
|
||||||
cap = CAP_SETGID;
|
cap = CAP_SETGID;
|
||||||
} else {
|
} else {
|
||||||
fprintf(log_get_logfd(), _("%s: Invalid map file %s specified\n"), log_get_progname(), map_file);
|
fprintf(log_get_logfd(), _("%s: Invalid map file %s specified\n"), log_get_progname(), map_file);
|
||||||
@@ -145,7 +158,7 @@ void write_mapping(int proc_dir_fd, int ranges, const struct map_range *mappings
|
|||||||
|
|
||||||
/* Align setuid- and fscaps-based new{g,u}idmap behavior. */
|
/* Align setuid- and fscaps-based new{g,u}idmap behavior. */
|
||||||
if (geteuid() == 0 && geteuid() != ruid) {
|
if (geteuid() == 0 && geteuid() != ruid) {
|
||||||
if (prctl(PR_SET_KEEPCAPS, 1L) == -1) {
|
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0) {
|
||||||
fprintf(log_get_logfd(), _("%s: Could not prctl(PR_SET_KEEPCAPS)\n"), log_get_progname());
|
fprintf(log_get_logfd(), _("%s: Could not prctl(PR_SET_KEEPCAPS)\n"), log_get_progname());
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -21,7 +21,6 @@
|
|||||||
#include "adds.h"
|
#include "adds.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
@@ -68,7 +67,7 @@ int isexpired (const struct passwd *pw, /*@null@*/const struct spwd *sp)
|
|||||||
* returns sp_lstchg==0 (must change password) instead of -1!
|
* returns sp_lstchg==0 (must change password) instead of -1!
|
||||||
*/
|
*/
|
||||||
if ( (0 == sp->sp_lstchg)
|
if ( (0 == sp->sp_lstchg)
|
||||||
&& streq(pw->pw_passwd, SHADOW_PASSWD_STRING)) {
|
&& (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) == 0)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+52
-44
@@ -30,15 +30,8 @@
|
|||||||
#include "shadowlog.h"
|
#include "shadowlog.h"
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
|
||||||
#include "atoi/a2i/a2i.h"
|
#include "atoi/str2i.h"
|
||||||
#include "atoi/a2i/a2s.h"
|
#include "memzero.h"
|
||||||
#include "atoi/str2i/str2i.h"
|
|
||||||
#include "atoi/str2i/str2s.h"
|
|
||||||
#include "atoi/str2i/str2u.h"
|
|
||||||
#include "string/memset/memzero.h"
|
|
||||||
#include "string/strchr/stpspn.h"
|
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
#include "typetraits.h"
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LIMITS_FILE
|
#ifndef LIMITS_FILE
|
||||||
@@ -56,7 +49,9 @@ static int setrlimit_value (unsigned int resource,
|
|||||||
const char *value,
|
const char *value,
|
||||||
unsigned int multiplier)
|
unsigned int multiplier)
|
||||||
{
|
{
|
||||||
rlim_t l, limit;
|
char *end;
|
||||||
|
long l;
|
||||||
|
rlim_t limit;
|
||||||
struct rlimit rlim;
|
struct rlimit rlim;
|
||||||
|
|
||||||
/* The "-" is special, not belonging to a strange negative limit.
|
/* The "-" is special, not belonging to a strange negative limit.
|
||||||
@@ -64,13 +59,18 @@ static int setrlimit_value (unsigned int resource,
|
|||||||
*/
|
*/
|
||||||
if ('-' == value[0]) {
|
if ('-' == value[0]) {
|
||||||
limit = RLIM_INFINITY;
|
limit = RLIM_INFINITY;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* We cannot use str2sl() here because it fails when there
|
||||||
|
* is more to the value than just this number!
|
||||||
|
* Also, we are limited to base 10 here (hex numbers will not
|
||||||
|
* work with the limit string parser as is anyway)
|
||||||
|
*/
|
||||||
|
errno = 0;
|
||||||
|
l = strtol(value, &end, 10);
|
||||||
|
|
||||||
} else {
|
if (value == end || errno != 0)
|
||||||
if (a2i(rlim_t, &l, value, NULL, 10, 0, type_max(rlim_t)) == -1
|
|
||||||
&& errno != ENOTSUP)
|
|
||||||
{
|
|
||||||
return 0; // FIXME: We could instead throw an error, though.
|
return 0; // FIXME: We could instead throw an error, though.
|
||||||
}
|
|
||||||
|
|
||||||
if (__builtin_mul_overflow(l, multiplier, &limit)) {
|
if (__builtin_mul_overflow(l, multiplier, &limit)) {
|
||||||
/* FIXME: Again, silent error handling...
|
/* FIXME: Again, silent error handling...
|
||||||
@@ -89,14 +89,14 @@ static int setrlimit_value (unsigned int resource,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int set_prio (const char *value)
|
||||||
set_prio(const char *value)
|
|
||||||
{
|
{
|
||||||
int prio;
|
long prio;
|
||||||
|
|
||||||
if (str2si(&prio, value) == -1)
|
if ( (str2sl(&prio, value) == -1)
|
||||||
|
|| (prio != (int) prio)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
if (setpriority (PRIO_PROCESS, 0, prio) != 0) {
|
if (setpriority (PRIO_PROCESS, 0, prio) != 0) {
|
||||||
return LOGIN_ERROR_RLIMIT;
|
return LOGIN_ERROR_RLIMIT;
|
||||||
}
|
}
|
||||||
@@ -104,13 +104,14 @@ set_prio(const char *value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int set_umask (const char *value)
|
||||||
set_umask(const char *value)
|
|
||||||
{
|
{
|
||||||
mode_t mask;
|
unsigned long mask;
|
||||||
|
|
||||||
if (str2i(mode_t, &mask, value) == -1)
|
if ( (str2ul(&mask, value) == -1)
|
||||||
|
|| (mask != (mode_t) mask)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
(void) umask (mask);
|
(void) umask (mask);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -123,10 +124,6 @@ static int check_logins (const char *name, const char *maxlogins)
|
|||||||
unsigned long limit, count;
|
unsigned long limit, count;
|
||||||
|
|
||||||
if (str2ul(&limit, maxlogins) == -1) {
|
if (str2ul(&limit, maxlogins) == -1) {
|
||||||
if (errno == ERANGE) {
|
|
||||||
SYSLOG((LOG_WARN, "Invalid maxlogins value\n"));
|
|
||||||
return LOGIN_ERROR_LOGIN;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +184,11 @@ static int do_user_limits (const char *buf, const char *name)
|
|||||||
int retval = 0;
|
int retval = 0;
|
||||||
bool reported = false;
|
bool reported = false;
|
||||||
|
|
||||||
pp = stpspn(buf, " \t");
|
pp = buf;
|
||||||
|
/* Skip leading whitespace. */
|
||||||
|
while ((' ' == *pp) || ('\t' == *pp)) {
|
||||||
|
pp++;
|
||||||
|
}
|
||||||
|
|
||||||
/* The special limit string "-" results in no limit for all known
|
/* The special limit string "-" results in no limit for all known
|
||||||
* limits.
|
* limits.
|
||||||
@@ -195,7 +196,7 @@ static int do_user_limits (const char *buf, const char *name)
|
|||||||
* being ignored if a limit type is not known to the system.
|
* being ignored if a limit type is not known to the system.
|
||||||
* Though, there will be complaining for unknown limit types.
|
* Though, there will be complaining for unknown limit types.
|
||||||
*/
|
*/
|
||||||
if (streq(pp, "-")) {
|
if (strcmp (pp, "-") == 0) {
|
||||||
/* Remember to extend this, too, when adding new limits!
|
/* Remember to extend this, too, when adding new limits!
|
||||||
* Oh... but "unlimited" does not make sense for umask,
|
* Oh... but "unlimited" does not make sense for umask,
|
||||||
* or does it? (K-)
|
* or does it? (K-)
|
||||||
@@ -203,7 +204,7 @@ static int do_user_limits (const char *buf, const char *name)
|
|||||||
pp = "A- C- D- F- I- L- M- N- O- P- R- S- T- U-";
|
pp = "A- C- D- F- I- L- M- N- O- P- R- S- T- U-";
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!streq(pp, "")) {
|
while ('\0' != *pp) {
|
||||||
switch (*pp++) {
|
switch (*pp++) {
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'A':
|
case 'A':
|
||||||
@@ -311,7 +312,12 @@ static int do_user_limits (const char *buf, const char *name)
|
|||||||
* So, let's skip all digits, "-" and our limited set of
|
* So, let's skip all digits, "-" and our limited set of
|
||||||
* whitespace.
|
* whitespace.
|
||||||
*/
|
*/
|
||||||
pp = stpspn(pp, "0123456789- \t");
|
while ( isdigit (*pp)
|
||||||
|
|| ('-' == *pp)
|
||||||
|
|| (' ' == *pp)
|
||||||
|
|| ('\t' ==*pp)) {
|
||||||
|
pp++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -396,10 +402,10 @@ static int setup_user_limits (const char *uname)
|
|||||||
*/
|
*/
|
||||||
if (sscanf (buf, "%s%[ACDFIKLMNOPRSTUacdfiklmnoprstu0-9 \t-]",
|
if (sscanf (buf, "%s%[ACDFIKLMNOPRSTUacdfiklmnoprstu0-9 \t-]",
|
||||||
name, tempbuf) == 2) {
|
name, tempbuf) == 2) {
|
||||||
if (streq(name, uname)) {
|
if (strcmp (name, uname) == 0) {
|
||||||
strcpy (limits, tempbuf);
|
strcpy (limits, tempbuf);
|
||||||
break;
|
break;
|
||||||
} else if (streq(name, "*")) {
|
} else if (strcmp (name, "*") == 0) {
|
||||||
strcpy (deflimits, tempbuf);
|
strcpy (deflimits, tempbuf);
|
||||||
} else if (name[0] == '@') {
|
} else if (name[0] == '@') {
|
||||||
/* If the user is in the group, the group
|
/* If the user is in the group, the group
|
||||||
@@ -413,9 +419,9 @@ static int setup_user_limits (const char *uname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
(void) fclose (fil);
|
(void) fclose (fil);
|
||||||
if (streq(limits, "")) {
|
if (limits[0] == '\0') {
|
||||||
/* no user specific limits */
|
/* no user specific limits */
|
||||||
if (streq(deflimits, "")) { /* no default limits */
|
if (deflimits[0] == '\0') { /* no default limits */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
strcpy (limits, deflimits); /* use the default limits */
|
strcpy (limits, deflimits); /* use the default limits */
|
||||||
@@ -437,7 +443,7 @@ static void setup_usergroups (const struct passwd *info)
|
|||||||
/* local, no need for xgetgrgid */
|
/* local, no need for xgetgrgid */
|
||||||
grp = getgrgid (info->pw_gid);
|
grp = getgrgid (info->pw_gid);
|
||||||
if ( (NULL != grp)
|
if ( (NULL != grp)
|
||||||
&& streq(info->pw_name, grp->gr_name)) {
|
&& (strcmp (info->pw_name, grp->gr_name) == 0)) {
|
||||||
mode_t tmpmask;
|
mode_t tmpmask;
|
||||||
tmpmask = umask (0777);
|
tmpmask = umask (0777);
|
||||||
tmpmask = (tmpmask & ~070) | ((tmpmask >> 3) & 070);
|
tmpmask = (tmpmask & ~070) | ((tmpmask >> 3) & 070);
|
||||||
@@ -478,9 +484,10 @@ void setup_limits (const struct passwd *info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp (cp, "pri=", 4) == 0) {
|
if (strncmp (cp, "pri=", 4) == 0) {
|
||||||
int inc;
|
long inc;
|
||||||
|
|
||||||
if (a2si(&inc, cp + 4, NULL, 0, -20, 20) == 0) {
|
if ( (str2sl(&inc, cp + 4) == 0)
|
||||||
|
&& (inc >= -20) && (inc <= 20)) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if ( (nice (inc) != -1)
|
if ( (nice (inc) != -1)
|
||||||
|| (0 != errno)) {
|
|| (0 != errno)) {
|
||||||
@@ -496,9 +503,9 @@ void setup_limits (const struct passwd *info)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strncmp (cp, "ulimit=", 7) == 0) {
|
if (strncmp (cp, "ulimit=", 7) == 0) {
|
||||||
int blocks;
|
long blocks;
|
||||||
|
if ( (str2sl(&blocks, cp + 7) == -1)
|
||||||
if ( (str2si(&blocks, cp + 7) == -1)
|
|| (blocks != (int) blocks)
|
||||||
|| (set_filesize_limit (blocks) != 0)) {
|
|| (set_filesize_limit (blocks) != 0)) {
|
||||||
SYSLOG ((LOG_WARN,
|
SYSLOG ((LOG_WARN,
|
||||||
"Can't set the ulimit for user %s",
|
"Can't set the ulimit for user %s",
|
||||||
@@ -507,9 +514,10 @@ void setup_limits (const struct passwd *info)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strncmp (cp, "umask=", 6) == 0) {
|
if (strncmp (cp, "umask=", 6) == 0) {
|
||||||
mode_t mask;
|
unsigned long mask;
|
||||||
|
|
||||||
if (str2i(mode_t, &mask, cp + 6) == -1) {
|
if ( (str2ul(&mask, cp + 6) == -1)
|
||||||
|
|| (mask != (mode_t) mask)) {
|
||||||
SYSLOG ((LOG_WARN,
|
SYSLOG ((LOG_WARN,
|
||||||
"Can't set umask value for user %s",
|
"Can't set umask value for user %s",
|
||||||
info->pw_name));
|
info->pw_name));
|
||||||
|
|||||||
+28
-16
@@ -12,14 +12,9 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "alloc/x/xmalloc.h"
|
#include "alloc.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "string/strchr/strchrcnt.h"
|
|
||||||
#include "string/strcmp/streq.h"
|
|
||||||
#include "string/strdup/xstrdup.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* add_list - add a member to a list of group members
|
* add_list - add a member to a list of group members
|
||||||
*
|
*
|
||||||
@@ -42,7 +37,7 @@ add_list(/*@returned@*/ /*@only@*/char **list, const char *member)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (i = 0; list[i] != NULL; i++) {
|
for (i = 0; list[i] != NULL; i++) {
|
||||||
if (streq(list[i], member)) {
|
if (strcmp (list[i], member) == 0) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +88,7 @@ del_list(/*@returned@*/ /*@only@*/char **list, const char *member)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (i = j = 0; list[i] != NULL; i++) {
|
for (i = j = 0; list[i] != NULL; i++) {
|
||||||
if (!streq(list[i], member)) {
|
if (strcmp (list[i], member) != 0) {
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,7 +111,7 @@ del_list(/*@returned@*/ /*@only@*/char **list, const char *member)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (i = j = 0; list[i] != NULL; i++) {
|
for (i = j = 0; list[i] != NULL; i++) {
|
||||||
if (!streq(list[i], member)) {
|
if (strcmp (list[i], member) != 0) {
|
||||||
tmp[j] = list[i];
|
tmp[j] = list[i];
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
@@ -168,7 +163,7 @@ bool is_on_list (char *const *list, const char *member)
|
|||||||
assert (NULL != list);
|
assert (NULL != list);
|
||||||
|
|
||||||
while (NULL != *list) {
|
while (NULL != *list) {
|
||||||
if (streq(*list, member)) {
|
if (strcmp (*list, member) == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
list++;
|
list++;
|
||||||
@@ -181,8 +176,7 @@ bool is_on_list (char *const *list, const char *member)
|
|||||||
* comma_to_list - convert comma-separated list to (char *) array
|
* comma_to_list - convert comma-separated list to (char *) array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*@only@*/char **
|
/*@only@*/char **comma_to_list (const char *comma)
|
||||||
comma_to_list(const char *comma)
|
|
||||||
{
|
{
|
||||||
char *members;
|
char *members;
|
||||||
char **array;
|
char **array;
|
||||||
@@ -199,17 +193,35 @@ comma_to_list(const char *comma)
|
|||||||
members = xstrdup (comma);
|
members = xstrdup (comma);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate the array we're going to store the pointers into.
|
* Count the number of commas in the list
|
||||||
* n: number of delimiters + last element + NULL
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
array = XMALLOC(strchrcnt(members, ',') + 2, char *);
|
for (cp = members, i = 0;; i++) {
|
||||||
|
cp2 = strchr (cp, ',');
|
||||||
|
if (NULL != cp2) {
|
||||||
|
cp = cp2 + 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add 2 - one for the ending NULL, the other for the last item
|
||||||
|
*/
|
||||||
|
|
||||||
|
i += 2;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate the array we're going to store the pointers into.
|
||||||
|
*/
|
||||||
|
|
||||||
|
array = XMALLOC(i, char *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Empty list is special - 0 members, not 1 empty member. --marekm
|
* Empty list is special - 0 members, not 1 empty member. --marekm
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (streq(members, "")) {
|
if ('\0' == *members) {
|
||||||
*array = NULL;
|
*array = NULL;
|
||||||
free (members);
|
free (members);
|
||||||
return array;
|
return array;
|
||||||
|
|||||||
@@ -17,10 +17,10 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include <lastlog.h>
|
#include <lastlog.h>
|
||||||
|
#include "memzero.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "string/memset/memzero.h"
|
#include "string/strncpy.h"
|
||||||
#include "string/strcpy/strncpy.h"
|
#include "string/strtcpy.h"
|
||||||
#include "string/strcpy/strtcpy.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -79,7 +79,7 @@ void dolastlog (
|
|||||||
}
|
}
|
||||||
|
|
||||||
ll_time = newlog.ll_time;
|
ll_time = newlog.ll_time;
|
||||||
ll_time = time(NULL);
|
(void) time (&ll_time);
|
||||||
newlog.ll_time = ll_time;
|
newlog.ll_time = ll_time;
|
||||||
STRTCPY(newlog.ll_line, line);
|
STRTCPY(newlog.ll_line, line);
|
||||||
#if HAVE_LL_HOST
|
#if HAVE_LL_HOST
|
||||||
|
|||||||
+15
-12
@@ -15,15 +15,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "alloc.h"
|
||||||
#include "attr.h"
|
#include "attr.h"
|
||||||
|
#include "memzero.h"
|
||||||
|
#include "prototypes.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "getdef.h"
|
#include "getdef.h"
|
||||||
#include "prototypes.h"
|
|
||||||
#include "string/memset/memzero.h"
|
|
||||||
#include "string/strchr/stpspn.h"
|
|
||||||
#include "string/strcpy/strtcpy.h"
|
|
||||||
#include "string/strtok/stpsep.h"
|
|
||||||
|
|
||||||
|
|
||||||
static void login_exit (MAYBE_UNUSED int sig)
|
static void login_exit (MAYBE_UNUSED int sig)
|
||||||
{
|
{
|
||||||
@@ -36,8 +33,8 @@ static void login_exit (MAYBE_UNUSED int sig)
|
|||||||
* login_prompt() displays the standard login prompt. If ISSUE_FILE
|
* login_prompt() displays the standard login prompt. If ISSUE_FILE
|
||||||
* is set in login.defs, this file is displayed before the prompt.
|
* is set in login.defs, this file is displayed before the prompt.
|
||||||
*/
|
*/
|
||||||
void
|
|
||||||
login_prompt(char *name, int namesize)
|
void login_prompt (char *name, int namesize)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
@@ -87,16 +84,22 @@ login_prompt(char *name, int namesize)
|
|||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stpsep(buf, "\n") == NULL)
|
cp = strchr (buf, '\n');
|
||||||
exit(EXIT_FAILURE);
|
if (NULL == cp) {
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
*cp = '\0'; /* remove \n [ must be there ] */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Skip leading whitespace. This makes " username" work right.
|
* Skip leading whitespace. This makes " username" work right.
|
||||||
* Then copy the rest (up to the end) into the username.
|
* Then copy the rest (up to the end) into the username.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
cp = stpspn(buf, " \t");
|
for (cp = buf; *cp == ' ' || *cp == '\t'; cp++);
|
||||||
strtcpy(name, cp, namesize);
|
|
||||||
|
for (i = 0; i < namesize - 1 && *cp != '\0'; name[i++] = *cp++);
|
||||||
|
|
||||||
|
name[i] = '\0';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the SIGQUIT handler back to its original value
|
* Set the SIGQUIT handler back to its original value
|
||||||
|
|||||||
+2
-1
@@ -15,8 +15,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "alloc.h"
|
||||||
#include "getdef.h"
|
#include "getdef.h"
|
||||||
#include "string/sprintf/xasprintf.h"
|
#include "string/sprintf.h"
|
||||||
|
|
||||||
#ident "$Id$"
|
#ident "$Id$"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#ident "$Id$"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "memzero.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern inline void memzero(void *ptr, size_t size);
|
||||||
|
extern inline void strzero(char *s);
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
// SPDX-FileCopyrightText: 2022-2023, Christian Göttsche <cgzones@googlemail.com>
|
/*
|
||||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
* SPDX-FileCopyrightText: 2022-2023, Christian Göttsche <cgzones@googlemail.com>
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef SHADOW_INCLUDE_LIB_STRING_MEMSET_MEMZERO_H_
|
#ifndef SHADOW_INCLUDE_LIBMISC_MEMZERO_H_
|
||||||
#define SHADOW_INCLUDE_LIB_STRING_MEMSET_MEMZERO_H_
|
#define SHADOW_INCLUDE_LIBMISC_MEMZERO_H_
|
||||||
|
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
@@ -19,11 +21,11 @@
|
|||||||
#define MEMZERO(arr) memzero(arr, SIZEOF_ARRAY(arr))
|
#define MEMZERO(arr) memzero(arr, SIZEOF_ARRAY(arr))
|
||||||
|
|
||||||
|
|
||||||
inline void *memzero(void *ptr, size_t size);
|
inline void memzero(void *ptr, size_t size);
|
||||||
inline char *strzero(char *s);
|
inline void strzero(char *s);
|
||||||
|
|
||||||
|
|
||||||
inline void *
|
inline void
|
||||||
memzero(void *ptr, size_t size)
|
memzero(void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_MEMSET_EXPLICIT)
|
#if defined(HAVE_MEMSET_EXPLICIT)
|
||||||
@@ -34,14 +36,13 @@ memzero(void *ptr, size_t size)
|
|||||||
bzero(ptr, size);
|
bzero(ptr, size);
|
||||||
__asm__ __volatile__ ("" : : "r"(ptr) : "memory");
|
__asm__ __volatile__ ("" : : "r"(ptr) : "memory");
|
||||||
#endif
|
#endif
|
||||||
return ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline char *
|
inline void
|
||||||
strzero(char *s)
|
strzero(char *s)
|
||||||
{
|
{
|
||||||
return memzero(s, strlen(s));
|
memzero(s, strlen(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user