Compare commits
343 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2512d5741 | ||
|
|
881a506ce4 | ||
|
|
8821d3ff2d | ||
|
|
b9d00b64a1 | ||
|
|
205c23bff2 | ||
|
|
c39305569b | ||
|
|
7182d6402f | ||
|
|
8424d7c494 | ||
|
|
b75ea29821 | ||
|
|
2f74389334 | ||
|
|
512deecca5 | ||
|
|
2f4b5f5d80 | ||
|
|
5ba62265b3 | ||
|
|
c1d597acbb | ||
|
|
64ab7221fb | ||
|
|
3feff7ae5b | ||
|
|
30bcd185c3 | ||
|
|
ecce8f098d | ||
|
|
712278add1 | ||
|
|
de4715d978 | ||
|
|
f3464103fb | ||
|
|
93887b4de6 | ||
|
|
960947135c | ||
|
|
c8c1059384 | ||
|
|
90afe61003 | ||
|
|
bdb5e2b79f | ||
|
|
f220407144 | ||
|
|
9f129146ff | ||
|
|
5581e74188 | ||
|
|
212ef97449 | ||
|
|
1d6456542c | ||
|
|
627b7364b5 | ||
|
|
a65fccf199 | ||
|
|
365279ea95 | ||
|
|
742a230e30 | ||
|
|
929e61d604 | ||
|
|
0b8c0c893c | ||
|
|
8296e62957 | ||
|
|
19ce8b0abc | ||
|
|
9d8145acfc | ||
|
|
99a3ca17df | ||
|
|
9efce1ac85 | ||
|
|
67c42427a0 | ||
|
|
73e58adc6b | ||
|
|
a0771fc01a | ||
|
|
86451e374b | ||
|
|
ed569088cc | ||
|
|
32f10c3dec | ||
|
|
f8c7955bbb | ||
|
|
5d5ab18890 | ||
|
|
d78d1c2fd7 | ||
|
|
419ce14b6f | ||
|
|
c8c3731e05 | ||
|
|
cd8a8da7de | ||
|
|
6266a916c2 | ||
|
|
3daf3f0cc4 | ||
|
|
0589cbc135 | ||
|
|
feead2f639 | ||
|
|
326889ca81 | ||
|
|
afc4b574b7 | ||
|
|
12aa29b576 | ||
|
|
30ab822cf3 | ||
|
|
0d1faafd3c | ||
|
|
c8600f1359 | ||
|
|
339a596374 | ||
|
|
99c4f445c7 | ||
|
|
4a15739408 | ||
|
|
fb731369fd | ||
|
|
276f3fde26 | ||
|
|
02d4af7f6f | ||
|
|
f45adadd28 | ||
|
|
9035932496 | ||
|
|
6c9e80165b | ||
|
|
7a796897e5 | ||
|
|
af66ffea33 | ||
|
|
e7a970a189 | ||
|
|
759d2373e4 | ||
|
|
e6a5484ced | ||
|
|
dd6cddd481 | ||
|
|
76c97ed7ec | ||
|
|
62bd261fbe | ||
|
|
6b4487e173 | ||
|
|
db395130d1 | ||
|
|
3ac50e1d02 | ||
|
|
81078c57fb | ||
|
|
8903b94c86 | ||
|
|
b2b37863a6 | ||
|
|
1f11a5ce5a | ||
|
|
0663c91f80 | ||
|
|
1c127bd173 | ||
|
|
56d52997c3 | ||
|
|
f5806e0511 | ||
|
|
dab8de8a72 | ||
|
|
87a5145719 | ||
|
|
5c0b99c77e | ||
|
|
3dc840a56a | ||
|
|
60da937c2f | ||
|
|
6a2e298a5b | ||
|
|
683b3caa62 | ||
|
|
04592e4cc7 | ||
|
|
e04e493234 | ||
|
|
3f5b4b5626 | ||
|
|
f3f501c81c | ||
|
|
fffa4d3e27 | ||
|
|
28ffa634d8 | ||
|
|
4bc0c5b0b8 | ||
|
|
f56e79a2b7 | ||
|
|
d8fb10f7b7 | ||
|
|
80c4e70da0 | ||
|
|
1d6f578f3e | ||
|
|
9a53a8aebd | ||
|
|
36e8015e2b | ||
|
|
df50348a28 | ||
|
|
9a0cd7a231 | ||
|
|
dfbc0db895 | ||
|
|
11e9627658 | ||
|
|
34f213211f | ||
|
|
48b36a03e8 | ||
|
|
9176206a7c | ||
|
|
8a93576ff9 | ||
|
|
63297e836d | ||
|
|
745281f295 | ||
|
|
2dda45a390 | ||
|
|
cfb8df4a91 | ||
|
|
b73c78581c | ||
|
|
c46c6a6e5a | ||
|
|
a184c2b555 | ||
|
|
7c43eb2c4e | ||
|
|
57aa813c73 | ||
|
|
5586f43d48 | ||
|
|
f89925c219 | ||
|
|
c2ebd210e7 | ||
|
|
568d26d7ed | ||
|
|
a7b169be18 | ||
|
|
d95b899bfc | ||
|
|
8714ac0cd6 | ||
|
|
64409c28b7 | ||
|
|
a33d7430ed | ||
|
|
d91b22cc2f | ||
|
|
39da15614e | ||
|
|
843c151f2c | ||
|
|
cee79c215a | ||
|
|
882db57f24 | ||
|
|
b4b4ff633a | ||
|
|
d9d0117e80 | ||
|
|
a198054456 | ||
|
|
c3f97e251e | ||
|
|
f1f82c2105 | ||
|
|
e790993c5d | ||
|
|
bf84b3a855 | ||
|
|
a4b91048e9 | ||
|
|
53ea42e67f | ||
|
|
59e5eef38f | ||
|
|
c6018240f8 | ||
|
|
7c9da42db0 | ||
|
|
813c3ec6c5 | ||
|
|
9174697469 | ||
|
|
2fcf520184 | ||
|
|
b38ee0c6d0 | ||
|
|
ab9f4da83f | ||
|
|
0464c1abf1 | ||
|
|
e341291f99 | ||
|
|
b178fed180 | ||
|
|
ebdeb8f22a | ||
|
|
a11ae5cf29 | ||
|
|
7e754cc447 | ||
|
|
e9cc053df7 | ||
|
|
326bdfe70b | ||
|
|
03521bccce | ||
|
|
3fd1d62e29 | ||
|
|
312c3b1389 | ||
|
|
169cbe1f56 | ||
|
|
dba5600cef | ||
|
|
5f2055c395 | ||
|
|
45d4472c92 | ||
|
|
9415ce4a14 | ||
|
|
866d911655 | ||
|
|
c7981fdd00 | ||
|
|
379e9c32f7 | ||
|
|
060b0849a6 | ||
|
|
4eed3e84a1 | ||
|
|
53e1eb4045 | ||
|
|
ba3a51e90f | ||
|
|
5111e5ed1b | ||
|
|
3049bef9c3 | ||
|
|
883bf71fc8 | ||
|
|
29f4f03def | ||
|
|
2cf73c99a6 | ||
|
|
85a2f36992 | ||
|
|
cb3e2fbdcf | ||
|
|
ac591763fe | ||
|
|
103ffc5b1d | ||
|
|
3c09e40a1f | ||
|
|
2a0c0dd24b | ||
|
|
9a9faf86f0 | ||
|
|
d9923431eb | ||
|
|
44ba094766 | ||
|
|
c287317075 | ||
|
|
056f1d03ee | ||
|
|
16cb664865 | ||
|
|
8176e309ed | ||
|
|
964df6ed6e | ||
|
|
077f7b6ade | ||
|
|
d611d1a947 | ||
|
|
23663a1607 | ||
|
|
bdf00dca44 | ||
|
|
bfb6aad7cb | ||
|
|
761eb07016 | ||
|
|
2cb3deec72 | ||
|
|
5e11e89fd9 | ||
|
|
847a19e7a3 | ||
|
|
e5d40a1863 | ||
|
|
89402f5171 | ||
|
|
40ab806066 | ||
|
|
22272347b6 | ||
|
|
89e4be3957 | ||
|
|
1f7c00b8f7 | ||
|
|
7f3ab84714 | ||
|
|
7f86f893ab | ||
|
|
6093c93e81 | ||
|
|
8ad2768472 | ||
|
|
b198c1e782 | ||
|
|
a80715448b | ||
|
|
1557fac0a5 | ||
|
|
6fd56468c3 | ||
|
|
509e3bcbf8 | ||
|
|
f85a07f140 | ||
|
|
74a2ed4537 | ||
|
|
678c2a23ee | ||
|
|
24695e6f38 | ||
|
|
500ec3f8f3 | ||
|
|
2457fc7c6b | ||
|
|
488bf4a519 | ||
|
|
75ea679799 | ||
|
|
81b5b26925 | ||
|
|
6e57238bf9 | ||
|
|
3307a8f4f0 | ||
|
|
d55367bb16 | ||
|
|
47edcd3045 | ||
|
|
cde08e422d | ||
|
|
2df2c35bad | ||
|
|
9b7d786b6f | ||
|
|
ca046af5d9 | ||
|
|
df59088641 | ||
|
|
b620b5d0d1 | ||
|
|
29dbcfbabd | ||
|
|
0217516349 | ||
|
|
18f113cc46 | ||
|
|
10429edc14 | ||
|
|
8acec35d1d | ||
|
|
69f74dbf8a | ||
|
|
4e2453fa9f | ||
|
|
d0fef040ed | ||
|
|
71e28359d1 | ||
|
|
f3a1e1cf09 | ||
|
|
fb49de61b7 | ||
|
|
895dfd77d2 | ||
|
|
9dddcd29f1 | ||
|
|
a6eb312f60 | ||
|
|
99df9d746e | ||
|
|
27e467a61a | ||
|
|
d8e6a8b99b | ||
|
|
adf37cccd0 | ||
|
|
da77a82ecb | ||
|
|
68d42a8fbe | ||
|
|
71a3238b79 | ||
|
|
61964aa06b | ||
|
|
81bc78ec5c | ||
|
|
b089a63ab3 | ||
|
|
151f14ad69 | ||
|
|
1ee066ae1e | ||
|
|
e7d1508e07 | ||
|
|
a74c4b6ae1 | ||
|
|
701fe4cf1a | ||
|
|
37ae8827a0 | ||
|
|
f8fc6371f6 | ||
|
|
4c16416ebc | ||
|
|
0066743c49 | ||
|
|
29f135777e | ||
|
|
34f431f607 | ||
|
|
040ba6a853 | ||
|
|
b0498564b2 | ||
|
|
26c9dd3715 | ||
|
|
18ecf3987e | ||
|
|
9b3889696b | ||
|
|
03c31bef87 | ||
|
|
98aefe8772 | ||
|
|
f40bd94856 | ||
|
|
7af7361fd6 | ||
|
|
bbb2735cc0 | ||
|
|
d7ab811a36 | ||
|
|
62a4daa2cd | ||
|
|
8d8062c770 | ||
|
|
38a0b0a610 | ||
|
|
6bf5d6d4f3 | ||
|
|
dbd3527c03 | ||
|
|
dbf3b1ad51 | ||
|
|
b8f17f9c29 | ||
|
|
2e01b9d7d2 | ||
|
|
5f5b21fd5c | ||
|
|
f7fe4c5978 | ||
|
|
f39ac101ff | ||
|
|
b085c3f612 | ||
|
|
27e236ca79 | ||
|
|
dc12e87fe7 | ||
|
|
4827da0a2f | ||
|
|
0460dac019 | ||
|
|
b3affb29cf | ||
|
|
0b3d017276 | ||
|
|
e08db2de4c | ||
|
|
55c107617e | ||
|
|
673ff74fd4 | ||
|
|
ead55e9ba8 | ||
|
|
000619344d | ||
|
|
51a0d94a08 | ||
|
|
e44a9e631d | ||
|
|
2b67dc7765 | ||
|
|
fce1d88479 | ||
|
|
46fd68c37e | ||
|
|
fb01e07e83 | ||
|
|
08ae38e394 | ||
|
|
34b113baba | ||
|
|
93151689c0 | ||
|
|
ae17e0291d | ||
|
|
03677d9acf | ||
|
|
5f8f19f267 | ||
|
|
bed18501b1 | ||
|
|
8fcf6cccff | ||
|
|
8fee869e9a | ||
|
|
82e28ad534 | ||
|
|
19edb06fd2 | ||
|
|
be05c62bd7 | ||
|
|
88760598f0 | ||
|
|
efd169e010 | ||
|
|
da440b536c | ||
|
|
33825ab57d | ||
|
|
ae3d71fb94 | ||
|
|
4959cd10ae | ||
|
|
a3cae72faa | ||
|
|
26deef6945 | ||
|
|
d2f2c1877a | ||
|
|
b76fc2947f | ||
|
|
ffb3992467 |
21
.github/actions/install-dependencies/action.yml
vendored
21
.github/actions/install-dependencies/action.yml
vendored
@@ -5,8 +5,21 @@ runs:
|
||||
steps:
|
||||
- shell: bash
|
||||
run: |
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y ubuntu-dev-tools libbsd-dev
|
||||
sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
|
||||
sudo apt-get update -y
|
||||
if [ -f /etc/apt/sources.list.d/ubuntu.sources ]; then
|
||||
echo "Found new-style sources.list.d"
|
||||
cat /etc/apt/sources.list.d/ubuntu.sources
|
||||
sudo sed -i 's/^Types: deb/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources
|
||||
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
|
||||
|
||||
47
.github/workflows/runner.yml
vendored
47
.github/workflows/runner.yml
vendored
@@ -25,18 +25,8 @@ jobs:
|
||||
cat /proc/self/status
|
||||
systemd-detect-virt
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
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
|
||||
id: dependencies
|
||||
uses: ./.github/actions/install-dependencies
|
||||
- name: configure
|
||||
run: |
|
||||
autoreconf -v -f --install
|
||||
@@ -61,18 +51,8 @@ jobs:
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
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
|
||||
id: dependencies
|
||||
uses: ./.github/actions/install-dependencies
|
||||
|
||||
- name: Test make dist
|
||||
run: |
|
||||
@@ -89,6 +69,7 @@ jobs:
|
||||
container-build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [alpine, debian, fedora]
|
||||
|
||||
@@ -96,15 +77,25 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Ansible
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install ansible
|
||||
|
||||
- name: Build container
|
||||
run: |
|
||||
docker buildx build -f ./share/containers/${{ matrix.os }}.dockerfile . --output build-out
|
||||
pushd share/ansible/
|
||||
ansible-playbook playbook.yml -i inventory.ini -e 'distribution=${{ matrix.os }}'
|
||||
popd
|
||||
|
||||
- name: Store artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ matrix.os }}-build
|
||||
path: |
|
||||
./build-out/config.log
|
||||
./build-out/config.h
|
||||
./share/ansible/build-out/config.log
|
||||
./share/ansible/build-out/config.h
|
||||
./share/ansible/build-out/build.log
|
||||
./share/ansible/build-out/test-suite.log
|
||||
if-no-files-found: ignore
|
||||
|
||||
5
.github/workflows/static-code-analysis.yml
vendored
5
.github/workflows/static-code-analysis.yml
vendored
@@ -32,10 +32,7 @@ jobs:
|
||||
- name: Build shadow-utils
|
||||
run: |
|
||||
PROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN)
|
||||
make -kj$PROCESSORS || true
|
||||
|
||||
- name: Check build errors
|
||||
run: make
|
||||
make -Orecurse -j$PROCESSORS
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -3,9 +3,11 @@ lib*.a
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
*.mo
|
||||
*.gmo
|
||||
.deps
|
||||
.libs
|
||||
.dirstamp
|
||||
|
||||
*.patch
|
||||
*.rej
|
||||
@@ -14,6 +16,8 @@ lib*.a
|
||||
Makefile
|
||||
Makefile.in
|
||||
|
||||
test-driver
|
||||
|
||||
/ABOUT-NLS
|
||||
/aclocal.m4
|
||||
/autom4te.cache
|
||||
@@ -34,6 +38,7 @@ Makefile.in
|
||||
/m4
|
||||
/missing
|
||||
/stamp-h1
|
||||
/test-driver
|
||||
/ylwrap
|
||||
|
||||
/po/*.header
|
||||
|
||||
16
Makefile.am
16
Makefile.am
@@ -1,7 +1,5 @@
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
EXTRA_DIST = NEWS README
|
||||
|
||||
SUBDIRS = lib
|
||||
|
||||
if ENABLE_SUBIDS
|
||||
@@ -13,3 +11,17 @@ SUBDIRS += src po contrib doc etc tests/unit
|
||||
if ENABLE_REGENERATE_MAN
|
||||
SUBDIRS += man
|
||||
endif
|
||||
|
||||
CLEANFILES = man/8.out man/po/remove-potcdate.* man/*/login.defs.d man/*/*.mo
|
||||
|
||||
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
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
The following stable branches are kindly maintained by trusted volunteers:
|
||||
|
||||
- 4.14.x
|
||||
- 4.15.x
|
||||
- git
|
||||
- [main](https://www.alejandro-colomar.es/src/alx/shadow/stable/shadow.git/log/?h=4.14.x)
|
||||
- [mirror](https://github.com/shadow-maint/shadow/tree/4.14.x)
|
||||
- [main](https://www.alejandro-colomar.es/src/alx/shadow/stable/shadow.git/log/?h=4.15.x)
|
||||
- [mirror](https://github.com/shadow-maint/shadow/tree/4.15.x)
|
||||
- tarballs
|
||||
- [main](https://www.alejandro-colomar.es/share/dist/shadow/4/4.14/)
|
||||
- [main](https://www.alejandro-colomar.es/share/dist/shadow/4/4.15/)
|
||||
- [mirror](https://github.com/shadow-maint/shadow/releases/)
|
||||
|
||||
24
configure.ac
24
configure.ac
@@ -1,12 +1,12 @@
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
AC_PREREQ([2.69])
|
||||
m4_define([libsubid_abi_major], 4)
|
||||
m4_define([libsubid_abi_major], 5)
|
||||
m4_define([libsubid_abi_minor], 0)
|
||||
m4_define([libsubid_abi_micro], 0)
|
||||
m4_define([libsubid_abi], [libsubid_abi_major.libsubid_abi_minor.libsubid_abi_micro])
|
||||
AC_INIT([shadow], [4.15.0], [pkg-shadow-devel@lists.alioth.debian.org], [],
|
||||
AC_INIT([shadow], [4.17.0], [pkg-shadow-devel@lists.alioth.debian.org], [],
|
||||
[https://github.com/shadow-maint/shadow])
|
||||
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects])
|
||||
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects tar-pax])
|
||||
AC_CONFIG_MACRO_DIRS([m4])
|
||||
AM_SILENT_RULES([yes])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
@@ -159,13 +159,6 @@ fi])
|
||||
AC_DEFINE_UNQUOTED(PASSWD_PROGRAM, "$shadow_cv_passwd_dir/passwd",
|
||||
[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,
|
||||
[AS_HELP_STRING([--enable-shadowgrp], [enable shadow group support @<:@default=yes@:>@])],
|
||||
[case "${enableval}" in
|
||||
@@ -274,6 +267,7 @@ AC_DEFINE_UNQUOTED(GROUP_NAME_MAX_LENGTH, $with_group_name_max_length, [max grou
|
||||
AC_SUBST(GROUP_NAME_MAX_LENGTH)
|
||||
GROUP_NAME_MAX_LENGTH="$with_group_name_max_length"
|
||||
|
||||
|
||||
AM_CONDITIONAL(USE_SHA_CRYPT, test "x$with_sha_crypt" = "xyes")
|
||||
if test "$with_sha_crypt" = "yes"; then
|
||||
AC_DEFINE(USE_SHA_CRYPT, 1, [Define to allow the SHA256 and SHA512 password encryption algorithms])
|
||||
@@ -310,6 +304,10 @@ dnl needed (Linux glibc, Irix), but still link it if needed (Solaris).
|
||||
|
||||
AC_SEARCH_LIBS(gethostbyname, nsl)
|
||||
|
||||
PKG_CHECK_MODULES([CMOCKA], [cmocka], [have_cmocka="yes"],
|
||||
[AC_MSG_WARN([libcmocka not found, cmocka tests will not be built])])
|
||||
AM_CONDITIONAL([HAVE_CMOCKA], [test x$have_cmocka = xyes])
|
||||
|
||||
AC_CHECK_LIB([econf],[econf_readDirs],[LIBECONF="-leconf"],[LIBECONF=""])
|
||||
if test -n "$LIBECONF"; then
|
||||
AC_DEFINE_UNQUOTED([VENDORDIR], ["$enable_vendordir"],
|
||||
@@ -691,7 +689,7 @@ AC_SUBST(LIBMD)
|
||||
if test "$with_skey" = "yes"; then
|
||||
AC_CHECK_LIB(md, MD5Init, [LIBMD=-lmd])
|
||||
AC_CHECK_LIB(skey, skeychallenge, [LIBSKEY=-lskey],
|
||||
[AC_MSG_ERROR([liskey missing. You can download S/Key source code from http://rsync1.it.gentoo.org/gentoo/distfiles/skey-1.1.5.tar.bz2])])
|
||||
[AC_MSG_ERROR([libskey missing. You can download S/Key source code from http://rsync1.it.gentoo.org/gentoo/distfiles/skey-1.1.5.tar.bz2])])
|
||||
AC_DEFINE(SKEY, 1, [Define to support S/Key logins.])
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include <stdio.h>
|
||||
@@ -701,10 +699,6 @@ if test "$with_skey" = "yes"; then
|
||||
]])],[AC_DEFINE(SKEY_BSD_STYLE, 1, [Define to support newer BSD S/Key API])],[])
|
||||
fi
|
||||
|
||||
PKG_CHECK_MODULES([CMOCKA], [cmocka], [have_cmocka="yes"],
|
||||
[AC_MSG_WARN([libcmocka not found, cmocka tests will not be built])])
|
||||
AM_CONDITIONAL([HAVE_CMOCKA], [test x$have_cmocka = xyes])
|
||||
|
||||
AC_CHECK_FUNC(fgetpwent_r, [AC_DEFINE(HAVE_FGETPWENT_R, 1, [Defined to 1 if you have the declaration of 'fgetpwent_r'])])
|
||||
|
||||
AC_DEFINE_UNQUOTED(SHELL, ["$SHELL"], [The default shell.])
|
||||
|
||||
@@ -118,6 +118,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
#define IMMEDIATE_CHANGE /* Expire newly created password, must be changed
|
||||
* immediately upon next login */
|
||||
#define HAVE_QUOTAS /* Obvious */
|
||||
@@ -291,12 +294,10 @@ main (void)
|
||||
printf ("Home Directory [%s/%s]: ", DEFAULT_HOME, usrname);
|
||||
fflush (stdout);
|
||||
safeget (dir, sizeof (dir));
|
||||
if (!strlen (dir))
|
||||
{ /* hit return */
|
||||
sprintf (dir, "%s/%s", DEFAULT_HOME, usrname);
|
||||
}
|
||||
if (!strlen(dir)) /* hit return */
|
||||
sprintf(dir, "%s/%s", DEFAULT_HOME, usrname);
|
||||
else if (dir[strlen (dir) - 1] == '/')
|
||||
sprintf (dir+strlen(dir), "%s", usrname);
|
||||
strcat(dir, usrname);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -308,7 +309,7 @@ main (void)
|
||||
fflush (stdout);
|
||||
safeget (shell, sizeof (shell));
|
||||
if (!strlen (shell))
|
||||
sprintf (shell, "%s", DEFAULT_SHELL);
|
||||
strcpy(shell, DEFAULT_SHELL);
|
||||
else
|
||||
{
|
||||
char *sh;
|
||||
@@ -316,7 +317,7 @@ main (void)
|
||||
#ifdef HAVE_GETUSERSHELL
|
||||
setusershell ();
|
||||
while ((sh = getusershell ()) != NULL)
|
||||
if (!strcmp (shell, sh))
|
||||
if (streq(shell, sh))
|
||||
ok = 1;
|
||||
endusershell ();
|
||||
#endif
|
||||
@@ -327,7 +328,7 @@ main (void)
|
||||
else
|
||||
{
|
||||
printf ("Shell NOT in /etc/shells, DEFAULT used\n");
|
||||
sprintf (shell, "%s", DEFAULT_SHELL);
|
||||
strcpy(shell, DEFAULT_SHELL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -491,12 +492,12 @@ safeget (char *buf, int maxlen)
|
||||
bad = (!isalnum (c) && (c != '_') && (c != ' '));
|
||||
*(buf++) = c;
|
||||
}
|
||||
*buf = '\0';
|
||||
stpcpy(buf, "");
|
||||
|
||||
if (bad)
|
||||
{
|
||||
printf ("\nString contained banned character. Please stick to alphanumerics.\n");
|
||||
*bstart = '\0';
|
||||
stpcpy(bstart, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
10
doc/HOWTO
10
doc/HOWTO
@@ -471,12 +471,12 @@
|
||||
|
||||
The Shadow Suite contains replacement programs for:
|
||||
|
||||
su, login, passwd, newgrp, chfn, chsh, and id
|
||||
su, login, passwd, newgrp, chfn, chsh
|
||||
|
||||
The package also contains the new programs:
|
||||
|
||||
chage, newusers, dpasswd, gpasswd, useradd, userdel, usermod,
|
||||
groupadd, groupdel, groupmod, groups, pwck, grpck, lastlog, pwconv,
|
||||
groupadd, groupdel, groupmod, pwck, grpck, lastlog, pwconv,
|
||||
and pwunconv
|
||||
|
||||
Additionally, the library: libshadow.a is included for writing and/or
|
||||
@@ -586,8 +586,6 @@
|
||||
|
||||
· /usr/bin/chsh
|
||||
|
||||
· /usr/bin/id
|
||||
|
||||
The BETA package has a save target in the Makefile, but it's commented
|
||||
out because different distributions place the programs in different
|
||||
places.
|
||||
@@ -637,8 +635,6 @@
|
||||
|
||||
· /usr/man/man1/chsh.1.gz
|
||||
|
||||
· /usr/man/man1/id.1.gz
|
||||
|
||||
· /usr/man/man1/login.1.gz
|
||||
|
||||
· /usr/man/man1/passwd.1.gz
|
||||
@@ -1377,7 +1373,7 @@
|
||||
users or changing the group password, the /etc/gshadow file will be
|
||||
changed.
|
||||
|
||||
The programs groups, groupadd, groupmod, and groupdel are provided as
|
||||
The programs groupadd, groupmod, and groupdel are provided as
|
||||
part of the Shadow Suite to modify groups.
|
||||
|
||||
The format of the /etc/group file is as follows:
|
||||
|
||||
@@ -62,9 +62,11 @@ You can either generate a single image by running the following command from
|
||||
the root folder of the project (i.e. Alpine):
|
||||
|
||||
```
|
||||
docker build -f share/containers/alpine.dockerfile . --output build-out/alpine
|
||||
ansible-playbook share/ansible/playbook.yml -i share/ansible/inventory.ini -e 'distribution=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
|
||||
were running some of the CI checks locally:
|
||||
|
||||
|
||||
@@ -72,6 +72,6 @@ understand the project's development model:
|
||||
* [Build & install](build_install.md)
|
||||
* [Coding style](coding_style.md)
|
||||
* [Tests](tests.md)
|
||||
* [Continuous Integration](CI.md)
|
||||
* [Continuous Integration](ci.md)
|
||||
* [Releases](releases.md)
|
||||
* [License](license.md)
|
||||
|
||||
111
lib/Makefile.am
111
lib/Makefile.am
@@ -29,12 +29,48 @@ libshadow_la_SOURCES = \
|
||||
age.c \
|
||||
agetpass.c \
|
||||
agetpass.h \
|
||||
alloc.c \
|
||||
alloc.h \
|
||||
atoi/strtoi.c \
|
||||
atoi/strtoi.h \
|
||||
atoi/strtou_noneg.c \
|
||||
atoi/strtou_noneg.h \
|
||||
alloc/calloc.c \
|
||||
alloc/calloc.h \
|
||||
alloc/malloc.c \
|
||||
alloc/malloc.h \
|
||||
alloc/realloc.c \
|
||||
alloc/realloc.h \
|
||||
alloc/reallocf.c \
|
||||
alloc/reallocf.h \
|
||||
alloc/x/xcalloc.c \
|
||||
alloc/x/xcalloc.h \
|
||||
alloc/x/xmalloc.c \
|
||||
alloc/x/xmalloc.h \
|
||||
alloc/x/xrealloc.c \
|
||||
alloc/x/xrealloc.h \
|
||||
atoi/a2i/a2i.c \
|
||||
atoi/a2i/a2i.h \
|
||||
atoi/a2i/a2s.c \
|
||||
atoi/a2i/a2s.h \
|
||||
atoi/a2i/a2s_c.c \
|
||||
atoi/a2i/a2s_c.h \
|
||||
atoi/a2i/a2s_nc.c \
|
||||
atoi/a2i/a2s_nc.h \
|
||||
atoi/a2i/a2u.c \
|
||||
atoi/a2i/a2u.h \
|
||||
atoi/a2i/a2u_c.c \
|
||||
atoi/a2i/a2u_c.h \
|
||||
atoi/a2i/a2u_nc.c \
|
||||
atoi/a2i/a2u_nc.h \
|
||||
atoi/getnum.c \
|
||||
atoi/getnum.h \
|
||||
atoi/str2i/str2i.c \
|
||||
atoi/str2i/str2i.h \
|
||||
atoi/str2i/str2s.c \
|
||||
atoi/str2i/str2s.h \
|
||||
atoi/str2i/str2u.c \
|
||||
atoi/str2i/str2u.h \
|
||||
atoi/strtoi/strtoi.c \
|
||||
atoi/strtoi/strtoi.h \
|
||||
atoi/strtoi/strtou.c \
|
||||
atoi/strtoi/strtou.h \
|
||||
atoi/strtoi/strtou_noneg.c \
|
||||
atoi/strtoi/strtou_noneg.h \
|
||||
attr.h \
|
||||
audit_help.c \
|
||||
basename.c \
|
||||
@@ -53,7 +89,6 @@ libshadow_la_SOURCES = \
|
||||
console.c \
|
||||
copydir.c \
|
||||
csrand.c \
|
||||
date_to_str.c \
|
||||
defines.h \
|
||||
encrypt.c \
|
||||
env.c \
|
||||
@@ -61,24 +96,25 @@ libshadow_la_SOURCES = \
|
||||
faillog.h \
|
||||
failure.c \
|
||||
failure.h \
|
||||
fd.c \
|
||||
fields.c \
|
||||
find_new_gid.c \
|
||||
find_new_uid.c \
|
||||
find_new_sub_gids.c \
|
||||
find_new_sub_uids.c \
|
||||
fputsx.c \
|
||||
get_gid.c \
|
||||
fs/readlink/areadlink.c \
|
||||
fs/readlink/areadlink.h \
|
||||
fs/readlink/readlinknul.c \
|
||||
fs/readlink/readlinknul.h \
|
||||
get_pid.c \
|
||||
get_uid.c \
|
||||
getdate.h \
|
||||
getdate.y \
|
||||
getdef.c \
|
||||
getdef.h \
|
||||
getlong.c \
|
||||
getgr_nam_gid.c \
|
||||
getrange.c \
|
||||
gettime.c \
|
||||
getulong.c \
|
||||
groupio.c \
|
||||
groupmem.c \
|
||||
groupio.h \
|
||||
@@ -92,8 +128,6 @@ libshadow_la_SOURCES = \
|
||||
lockpw.c \
|
||||
loginprompt.c \
|
||||
mail.c \
|
||||
memzero.c \
|
||||
memzero.h \
|
||||
motd.c \
|
||||
must_be.h \
|
||||
myname.c \
|
||||
@@ -117,7 +151,6 @@ libshadow_la_SOURCES = \
|
||||
pwdcheck.c \
|
||||
pwmem.c \
|
||||
remove_tree.c \
|
||||
rlogin.c \
|
||||
root_flag.c \
|
||||
run_part.h \
|
||||
run_part.c \
|
||||
@@ -143,23 +176,51 @@ libshadow_la_SOURCES = \
|
||||
spawn.c \
|
||||
sssd.c \
|
||||
sssd.h \
|
||||
string/sprintf.c \
|
||||
string/sprintf.h \
|
||||
string/stpecpy.c \
|
||||
string/stpecpy.h \
|
||||
string/stpeprintf.c \
|
||||
string/stpeprintf.h \
|
||||
string/strncpy.h \
|
||||
string/strtcpy.c \
|
||||
string/strtcpy.h \
|
||||
string/zustr2stp.c \
|
||||
string/zustr2stp.h \
|
||||
string/memset/memzero.c \
|
||||
string/memset/memzero.h \
|
||||
string/sprintf/snprintf.c \
|
||||
string/sprintf/snprintf.h \
|
||||
string/sprintf/stpeprintf.c \
|
||||
string/sprintf/stpeprintf.h \
|
||||
string/sprintf/xasprintf.c \
|
||||
string/sprintf/xasprintf.h \
|
||||
string/strchr/strchrcnt.c \
|
||||
string/strchr/strchrcnt.h \
|
||||
string/strchr/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.h \
|
||||
string/strtok/stpsep.c \
|
||||
string/strtok/stpsep.h \
|
||||
strtoday.c \
|
||||
sub.c \
|
||||
subordinateio.h \
|
||||
subordinateio.c \
|
||||
sulog.c \
|
||||
time/day_to_str.c \
|
||||
time/day_to_str.h \
|
||||
ttytype.c \
|
||||
typetraits.h \
|
||||
tz.c \
|
||||
ulimit.c \
|
||||
user_busy.c \
|
||||
|
||||
@@ -14,28 +14,30 @@
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
#include <errno.h>
|
||||
#include <grp.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "alloc/malloc.h"
|
||||
#include "alloc/reallocf.h"
|
||||
#include "shadowlog.h"
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#define SEP ",:"
|
||||
/*
|
||||
* Add groups with names from LIST (separated by commas or colons)
|
||||
* to the supplementary group set. Silently ignore groups which are
|
||||
* already there. Warning: uses strtok().
|
||||
* already there.
|
||||
*/
|
||||
int add_groups (const char *list)
|
||||
int
|
||||
add_groups(const char *list)
|
||||
{
|
||||
GETGROUPS_T *grouplist;
|
||||
size_t i;
|
||||
int ngroups;
|
||||
bool added;
|
||||
char *token;
|
||||
char *g, *p;
|
||||
char buf[1024];
|
||||
int ret;
|
||||
FILE *shadow_logfd = log_get_logfd();
|
||||
@@ -70,13 +72,13 @@ int add_groups (const char *list)
|
||||
}
|
||||
|
||||
added = false;
|
||||
for (token = strtok (buf, SEP); NULL != token; token = strtok (NULL, SEP)) {
|
||||
p = buf;
|
||||
while (NULL != (g = strsep(&p, ",:"))) {
|
||||
struct group *grp;
|
||||
|
||||
grp = getgrnam (token); /* local, no need for xgetgrnam */
|
||||
grp = getgrnam(g); /* local, no need for xgetgrnam */
|
||||
if (NULL == grp) {
|
||||
fprintf (shadow_logfd, _("Warning: unknown group %s\n"),
|
||||
token);
|
||||
fprintf(shadow_logfd, _("Warning: unknown group %s\n"), g);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "alloc.h"
|
||||
#include "alloc/malloc.h"
|
||||
|
||||
#if WITH_LIBBSD == 0
|
||||
#include "freezero.h"
|
||||
|
||||
73
lib/alloc.c
73
lib/alloc.c
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh
|
||||
* SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz
|
||||
* SPDX-FileCopyrightText: 2003 - 2006, Tomasz Kłoczko
|
||||
* SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
* SPDX-FileCopyrightText: 2023 , Alejandro Colomar <alx@kernel.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/* Replacements for malloc and strdup with error checking. Too trivial
|
||||
to be worth copyrighting :-). I did that because a lot of code used
|
||||
malloc and strdup without checking for NULL pointer, and I like some
|
||||
message better than a core dump... --marekm
|
||||
|
||||
Yeh, but. Remember that bailing out might leave the system in some
|
||||
bizarre state. You really want to put in error checking, then add
|
||||
some back-out failure recovery code. -- jfh */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "alloc.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "shadowlog.h"
|
||||
|
||||
|
||||
extern inline void *xmalloc(size_t size);
|
||||
extern inline void *xmallocarray(size_t nmemb, size_t size);
|
||||
extern inline void *mallocarray(size_t nmemb, size_t size);
|
||||
extern inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
|
||||
extern inline char *xstrdup(const char *str);
|
||||
|
||||
|
||||
void *
|
||||
xcalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = calloc(nmemb, size);
|
||||
if (p == NULL)
|
||||
goto x;
|
||||
|
||||
return p;
|
||||
|
||||
x:
|
||||
fprintf(log_get_logfd(), _("%s: %s\n"),
|
||||
log_get_progname(), strerror(errno));
|
||||
exit(13);
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
xreallocarray(void *p, size_t nmemb, size_t size)
|
||||
{
|
||||
p = reallocarrayf(p, nmemb, size);
|
||||
if (p == NULL)
|
||||
goto x;
|
||||
|
||||
return p;
|
||||
|
||||
x:
|
||||
fprintf(log_get_logfd(), _("%s: %s\n"),
|
||||
log_get_progname(), strerror(errno));
|
||||
exit(13);
|
||||
}
|
||||
116
lib/alloc.h
116
lib/alloc.h
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023, 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) \
|
||||
({ \
|
||||
__auto_type p_ = (ptr); \
|
||||
\
|
||||
static_assert(__builtin_types_compatible_p(typeof(p_), type *), ""); \
|
||||
\
|
||||
(type *) reallocarray(p_, n, sizeof(type)); \
|
||||
})
|
||||
|
||||
#define REALLOCF(ptr, n, type) \
|
||||
({ \
|
||||
__auto_type p_ = (ptr); \
|
||||
\
|
||||
static_assert(__builtin_types_compatible_p(typeof(p_), type *), ""); \
|
||||
\
|
||||
(type *) reallocarrayf(p_, n, sizeof(type)); \
|
||||
})
|
||||
|
||||
#define XREALLOC(ptr, n, type) \
|
||||
({ \
|
||||
__auto_type p_ = (ptr); \
|
||||
\
|
||||
static_assert(__builtin_types_compatible_p(typeof(p_), type *), ""); \
|
||||
\
|
||||
(type *) xreallocarray(p_, n, sizeof(type)); \
|
||||
})
|
||||
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
inline void *xmalloc(size_t size);
|
||||
ATTR_MALLOC(free)
|
||||
inline void *xmallocarray(size_t nmemb, size_t size);
|
||||
ATTR_MALLOC(free)
|
||||
inline void *mallocarray(size_t nmemb, size_t size);
|
||||
ATTR_MALLOC(free)
|
||||
inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
|
||||
ATTR_MALLOC(free)
|
||||
inline char *xstrdup(const char *str);
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
void *xcalloc(size_t nmemb, size_t size);
|
||||
ATTR_MALLOC(free)
|
||||
void *xreallocarray(void *p, size_t nmemb, size_t size);
|
||||
|
||||
|
||||
inline void *
|
||||
xmalloc(size_t size)
|
||||
{
|
||||
return xmallocarray(1, size);
|
||||
}
|
||||
|
||||
|
||||
inline void *
|
||||
xmallocarray(size_t nmemb, size_t size)
|
||||
{
|
||||
return xreallocarray(NULL, nmemb, size);
|
||||
}
|
||||
|
||||
|
||||
inline void *
|
||||
mallocarray(size_t nmemb, size_t size)
|
||||
{
|
||||
return reallocarray(NULL, nmemb, size);
|
||||
}
|
||||
|
||||
|
||||
inline void *
|
||||
reallocarrayf(void *p, size_t nmemb, size_t size)
|
||||
{
|
||||
void *q;
|
||||
|
||||
q = reallocarray(p, nmemb, size);
|
||||
|
||||
/* realloc(p, 0) is equivalent to free(p); avoid double free. */
|
||||
if (q == NULL && nmemb != 0 && size != 0)
|
||||
free(p);
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
inline char *
|
||||
xstrdup(const char *str)
|
||||
{
|
||||
return strcpy(XMALLOC(strlen(str) + 1, char), str);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
11
lib/alloc/calloc.c
Normal file
11
lib/alloc/calloc.c
Normal file
@@ -0,0 +1,11 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/calloc.h"
|
||||
20
lib/alloc/calloc.h
Normal file
20
lib/alloc/calloc.h
Normal file
@@ -0,0 +1,20 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ALLOC_CALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ALLOC_CALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define CALLOC(n, type) \
|
||||
( \
|
||||
(type *) calloc(n, sizeof(type)) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
16
lib/alloc/malloc.c
Normal file
16
lib/alloc/malloc.c
Normal file
@@ -0,0 +1,16 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/malloc.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern inline void *mallocarray(size_t nmemb, size_t size);
|
||||
34
lib/alloc/malloc.h
Normal file
34
lib/alloc/malloc.h
Normal file
@@ -0,0 +1,34 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ALLOC_MALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ALLOC_MALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define MALLOC(n, type) \
|
||||
( \
|
||||
(type *) mallocarray(n, sizeof(type)) \
|
||||
)
|
||||
|
||||
|
||||
ATTR_ALLOC_SIZE(1, 2)
|
||||
ATTR_MALLOC(free)
|
||||
inline void *mallocarray(size_t nmemb, size_t size);
|
||||
|
||||
|
||||
inline void *
|
||||
mallocarray(size_t nmemb, size_t size)
|
||||
{
|
||||
return reallocarray(NULL, nmemb, size);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
11
lib/alloc/realloc.c
Normal file
11
lib/alloc/realloc.c
Normal file
@@ -0,0 +1,11 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/realloc.h"
|
||||
20
lib/alloc/realloc.h
Normal file
20
lib/alloc/realloc.h
Normal file
@@ -0,0 +1,20 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ALLOC_REALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ALLOC_REALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define REALLOC(p, n, type) \
|
||||
( \
|
||||
_Generic(p, type *: (type *) reallocarray(p, (n) ?: 1, sizeof(type))) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
16
lib/alloc/reallocf.c
Normal file
16
lib/alloc/reallocf.c
Normal file
@@ -0,0 +1,16 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/reallocf.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
|
||||
41
lib/alloc/reallocf.h
Normal file
41
lib/alloc/reallocf.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ALLOC_REALLOCF_H_
|
||||
#define SHADOW_INCLUDE_LIB_ALLOC_REALLOCF_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define REALLOCF(p, n, type) \
|
||||
( \
|
||||
_Generic(p, type *: (type *) reallocarrayf(p, (n) ?: 1, sizeof(type)))\
|
||||
)
|
||||
|
||||
|
||||
ATTR_ALLOC_SIZE(2, 3)
|
||||
ATTR_MALLOC(free)
|
||||
inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
|
||||
|
||||
|
||||
inline void *
|
||||
reallocarrayf(void *p, size_t nmemb, size_t size)
|
||||
{
|
||||
void *q;
|
||||
|
||||
q = reallocarray(p, nmemb ?: 1, size ?: 1);
|
||||
|
||||
if (q == NULL)
|
||||
free(p);
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
36
lib/alloc/x/xcalloc.c
Normal file
36
lib/alloc/x/xcalloc.c
Normal file
@@ -0,0 +1,36 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/x/xcalloc.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "shadowlog.h"
|
||||
|
||||
|
||||
void *
|
||||
xcalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = calloc(nmemb, size);
|
||||
if (p == NULL)
|
||||
goto x;
|
||||
|
||||
return p;
|
||||
|
||||
x:
|
||||
fprintf(log_get_logfd(), _("%s: %s\n"),
|
||||
log_get_progname(), strerror(errno));
|
||||
exit(13);
|
||||
}
|
||||
28
lib/alloc/x/xcalloc.h
Normal file
28
lib/alloc/x/xcalloc.h
Normal file
@@ -0,0 +1,28 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ALLOC_X_XCALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ALLOC_X_XCALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define XCALLOC(n, type) \
|
||||
( \
|
||||
(type *) xcalloc(n, sizeof(type)) \
|
||||
)
|
||||
|
||||
|
||||
ATTR_ALLOC_SIZE(1, 2)
|
||||
ATTR_MALLOC(free)
|
||||
void *xcalloc(size_t nmemb, size_t size);
|
||||
|
||||
|
||||
#endif // include guard
|
||||
16
lib/alloc/x/xmalloc.c
Normal file
16
lib/alloc/x/xmalloc.c
Normal file
@@ -0,0 +1,16 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/x/xmalloc.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern inline void *xmallocarray(size_t nmemb, size_t size);
|
||||
35
lib/alloc/x/xmalloc.h
Normal file
35
lib/alloc/x/xmalloc.h
Normal file
@@ -0,0 +1,35 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ALLOC_X_XMALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ALLOC_X_XMALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "alloc/x/xrealloc.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define XMALLOC(n, type) \
|
||||
( \
|
||||
(type *) xmallocarray(n, sizeof(type)) \
|
||||
)
|
||||
|
||||
|
||||
ATTR_ALLOC_SIZE(1, 2)
|
||||
ATTR_MALLOC(free)
|
||||
inline void *xmallocarray(size_t nmemb, size_t size);
|
||||
|
||||
|
||||
inline void *
|
||||
xmallocarray(size_t nmemb, size_t size)
|
||||
{
|
||||
return xreallocarray(NULL, nmemb, size);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
35
lib/alloc/x/xrealloc.c
Normal file
35
lib/alloc/x/xrealloc.c
Normal file
@@ -0,0 +1,35 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "alloc/x/xrealloc.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc/reallocf.h"
|
||||
#include "defines.h"
|
||||
#include "shadowlog.h"
|
||||
|
||||
|
||||
void *
|
||||
xreallocarray(void *p, size_t nmemb, size_t size)
|
||||
{
|
||||
p = reallocarrayf(p, nmemb, size);
|
||||
if (p == NULL)
|
||||
goto x;
|
||||
|
||||
return p;
|
||||
|
||||
x:
|
||||
fprintf(log_get_logfd(), _("%s: %s\n"),
|
||||
log_get_progname(), strerror(errno));
|
||||
exit(13);
|
||||
}
|
||||
31
lib/alloc/x/xrealloc.h
Normal file
31
lib/alloc/x/xrealloc.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_MALLOC_H_
|
||||
#define SHADOW_INCLUDE_LIB_MALLOC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define XREALLOC(ptr, n, type) \
|
||||
( \
|
||||
_Generic(ptr, type *: (type *) xreallocarray(ptr, n, sizeof(type))) \
|
||||
)
|
||||
|
||||
|
||||
ATTR_ALLOC_SIZE(2, 3)
|
||||
ATTR_MALLOC(free)
|
||||
void *xreallocarray(void *p, size_t nmemb, size_t size);
|
||||
|
||||
|
||||
#endif // include guard
|
||||
7
lib/atoi/a2i/a2i.c
Normal file
7
lib/atoi/a2i/a2i.c
Normal file
@@ -0,0 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2i.h"
|
||||
62
lib/atoi/a2i/a2i.h
Normal file
62
lib/atoi/a2i/a2i.h
Normal file
@@ -0,0 +1,62 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2I_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2I_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2s_c.h"
|
||||
#include "atoi/a2i/a2s_nc.h"
|
||||
#include "atoi/a2i/a2u_c.h"
|
||||
#include "atoi/a2i/a2u_nc.h"
|
||||
|
||||
|
||||
/*
|
||||
* See the manual of these macros in liba2i's documentation:
|
||||
* <http://www.alejandro-colomar.es/share/dist/liba2i/git/HEAD/liba2i-HEAD.pdf>
|
||||
*/
|
||||
|
||||
|
||||
#define a2i(TYPE, n, s, ...) \
|
||||
( \
|
||||
_Generic((void (*)(TYPE, typeof(s))) 0, \
|
||||
void (*)(short, const char *): a2sh_c, \
|
||||
void (*)(short, const void *): a2sh_c, \
|
||||
void (*)(short, char *): a2sh_nc, \
|
||||
void (*)(short, void *): a2sh_nc, \
|
||||
void (*)(int, const char *): a2si_c, \
|
||||
void (*)(int, const void *): a2si_c, \
|
||||
void (*)(int, char *): a2si_nc, \
|
||||
void (*)(int, void *): a2si_nc, \
|
||||
void (*)(long, const char *): a2sl_c, \
|
||||
void (*)(long, const void *): a2sl_c, \
|
||||
void (*)(long, char *): a2sl_nc, \
|
||||
void (*)(long, void *): a2sl_nc, \
|
||||
void (*)(long long, const char *): a2sll_c, \
|
||||
void (*)(long long, const void *): a2sll_c, \
|
||||
void (*)(long long, char *): a2sll_nc, \
|
||||
void (*)(long long, void *): a2sll_nc, \
|
||||
void (*)(unsigned short, const char *): a2uh_c, \
|
||||
void (*)(unsigned short, const void *): a2uh_c, \
|
||||
void (*)(unsigned short, char *): a2uh_nc, \
|
||||
void (*)(unsigned short, void *): a2uh_nc, \
|
||||
void (*)(unsigned int, const char *): a2ui_c, \
|
||||
void (*)(unsigned int, const void *): a2ui_c, \
|
||||
void (*)(unsigned int, char *): a2ui_nc, \
|
||||
void (*)(unsigned int, void *): a2ui_nc, \
|
||||
void (*)(unsigned long, const char *): a2ul_c, \
|
||||
void (*)(unsigned long, const void *): a2ul_c, \
|
||||
void (*)(unsigned long, char *): a2ul_nc, \
|
||||
void (*)(unsigned long, void *): a2ul_nc, \
|
||||
void (*)(unsigned long long, const char *): a2ull_c, \
|
||||
void (*)(unsigned long long, const void *): a2ull_c, \
|
||||
void (*)(unsigned long long, char *): a2ull_nc, \
|
||||
void (*)(unsigned long long, void *): a2ull_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
7
lib/atoi/a2i/a2s.c
Normal file
7
lib/atoi/a2i/a2s.c
Normal file
@@ -0,0 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2s.h"
|
||||
56
lib/atoi/a2i/a2s.h
Normal file
56
lib/atoi/a2i/a2s.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2s_c.h"
|
||||
#include "atoi/a2i/a2s_nc.h"
|
||||
|
||||
|
||||
#define a2sh(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2sh_c, \
|
||||
const void *: a2sh_c, \
|
||||
char *: a2sh_nc, \
|
||||
void *: a2sh_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2si(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2si_c, \
|
||||
const void *: a2si_c, \
|
||||
char *: a2si_nc, \
|
||||
void *: a2si_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2sl(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2sl_c, \
|
||||
const void *: a2sl_c, \
|
||||
char *: a2sl_nc, \
|
||||
void *: a2sl_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2sll(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2sll_c, \
|
||||
const void *: a2sll_c, \
|
||||
char *: a2sll_nc, \
|
||||
void *: a2sll_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
17
lib/atoi/a2i/a2s_c.c
Normal file
17
lib/atoi/a2i/a2s_c.c
Normal file
@@ -0,0 +1,17 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2s_c.h"
|
||||
|
||||
|
||||
extern inline int a2sh_c(short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, short min, short max);
|
||||
extern inline int a2si_c(int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, int min, int max);
|
||||
extern inline int a2sl_c(long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long min, long max);
|
||||
extern inline int a2sll_c(long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long long min, long long max);
|
||||
64
lib/atoi/a2i/a2s_c.h
Normal file
64
lib/atoi/a2i/a2s_c.h
Normal file
@@ -0,0 +1,64 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_C_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_C_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "atoi/a2i/a2s_nc.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sh_c(short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, short min, short max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2si_c(int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, int min, int max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sl_c(long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long min, long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sll_c(long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long long min, long long max);
|
||||
|
||||
|
||||
inline int
|
||||
a2sh_c(short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, short min, short max)
|
||||
{
|
||||
return a2sh_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2si_c(int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, int min, int max)
|
||||
{
|
||||
return a2si_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sl_c(long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long min, long max)
|
||||
{
|
||||
return a2sl_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sll_c(long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, long long min, long long max)
|
||||
{
|
||||
return a2sll_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
17
lib/atoi/a2i/a2s_nc.c
Normal file
17
lib/atoi/a2i/a2s_nc.c
Normal file
@@ -0,0 +1,17 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2s_nc.h"
|
||||
|
||||
|
||||
extern inline int a2sh_nc(short *restrict n, char *s,
|
||||
char **restrict endp, int base, short min, short max);
|
||||
extern inline int a2si_nc(int *restrict n, char *s,
|
||||
char **restrict endp, int base, int min, int max);
|
||||
extern inline int a2sl_nc(long *restrict n, char *s,
|
||||
char **restrict endp, int base, long min, long max);
|
||||
extern inline int a2sll_nc(long long *restrict n, char *s,
|
||||
char **restrict endp, int base, long long min, long long max);
|
||||
91
lib/atoi/a2i/a2s_nc.h
Normal file
91
lib/atoi/a2i/a2s_nc.h
Normal file
@@ -0,0 +1,91 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_NC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_NC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "atoi/strtoi/strtoi.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sh_nc(short *restrict n, char *s,
|
||||
char **restrict endp, int base, short min, short max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2si_nc(int *restrict n, char *s,
|
||||
char **restrict endp, int base, int min, int max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sl_nc(long *restrict n, char *s,
|
||||
char **restrict endp, int base, long min, long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2sll_nc(long long *restrict n, char *s,
|
||||
char **restrict endp, int base, long long min, long long max);
|
||||
|
||||
|
||||
inline int
|
||||
a2sh_nc(short *restrict n, char *s,
|
||||
char **restrict endp, int base, short min, short max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtoi_(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2si_nc(int *restrict n, char *s,
|
||||
char **restrict endp, int base, int min, int max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtoi_(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sl_nc(long *restrict n, char *s,
|
||||
char **restrict endp, int base, long min, long max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtoi_(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2sll_nc(long long *restrict n, char *s,
|
||||
char **restrict endp, int base, long long min, long long max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtoi_(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
7
lib/atoi/a2i/a2u.c
Normal file
7
lib/atoi/a2i/a2u.c
Normal file
@@ -0,0 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2u.h"
|
||||
56
lib/atoi/a2i/a2u.h
Normal file
56
lib/atoi/a2i/a2u.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2u_c.h"
|
||||
#include "atoi/a2i/a2u_nc.h"
|
||||
|
||||
|
||||
#define a2uh(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2uh_c, \
|
||||
const void *: a2uh_c, \
|
||||
char *: a2uh_nc, \
|
||||
void *: a2uh_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2ui(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2ui_c, \
|
||||
const void *: a2ui_c, \
|
||||
char *: a2ui_nc, \
|
||||
void *: a2ui_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2ul(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2ul_c, \
|
||||
const void *: a2ul_c, \
|
||||
char *: a2ul_nc, \
|
||||
void *: a2ul_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
#define a2ull(n, s, ...) \
|
||||
( \
|
||||
_Generic(s, \
|
||||
const char *: a2ull_c, \
|
||||
const void *: a2ull_c, \
|
||||
char *: a2ull_nc, \
|
||||
void *: a2ull_nc \
|
||||
)(n, s, __VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
19
lib/atoi/a2i/a2u_c.c
Normal file
19
lib/atoi/a2i/a2u_c.c
Normal file
@@ -0,0 +1,19 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2u_c.h"
|
||||
|
||||
|
||||
extern inline int a2uh_c(unsigned short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned short min,
|
||||
unsigned short max);
|
||||
extern inline int a2ui_c(unsigned int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned int min, unsigned int max);
|
||||
extern inline int a2ul_c(unsigned long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long min, unsigned long max);
|
||||
extern inline int a2ull_c(unsigned long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max);
|
||||
65
lib/atoi/a2i/a2u_c.h
Normal file
65
lib/atoi/a2i/a2u_c.h
Normal file
@@ -0,0 +1,65 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_C_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_C_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2u_nc.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2uh_c(unsigned short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned short min,
|
||||
unsigned short max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ui_c(unsigned int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned int min, unsigned int max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ul_c(unsigned long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long min, unsigned long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ull_c(unsigned long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max);
|
||||
|
||||
|
||||
inline int
|
||||
a2uh_c(unsigned short *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned short min,
|
||||
unsigned short max)
|
||||
{
|
||||
return a2uh_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ui_c(unsigned int *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned int min, unsigned int max)
|
||||
{
|
||||
return a2ui_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ul_c(unsigned long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long min, unsigned long max)
|
||||
{
|
||||
return a2ul_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ull_c(unsigned long long *restrict n, const char *s,
|
||||
const char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max)
|
||||
{
|
||||
return a2ull_nc(n, (char *) s, (char **) endp, base, min, max);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
18
lib/atoi/a2i/a2u_nc.c
Normal file
18
lib/atoi/a2i/a2u_nc.c
Normal file
@@ -0,0 +1,18 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/a2i/a2u_nc.h"
|
||||
|
||||
|
||||
extern inline int a2uh_nc(unsigned short *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned short min, unsigned short max);
|
||||
extern inline int a2ui_nc(unsigned int *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned int min, unsigned int max);
|
||||
extern inline int a2ul_nc(unsigned long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long min, unsigned long max);
|
||||
extern inline int a2ull_nc(unsigned long long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max);
|
||||
94
lib/atoi/a2i/a2u_nc.h
Normal file
94
lib/atoi/a2i/a2u_nc.h
Normal file
@@ -0,0 +1,94 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_NC_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_NC_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "atoi/strtoi/strtou_noneg.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2uh_nc(unsigned short *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned short min, unsigned short max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ui_nc(unsigned int *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned int min, unsigned int max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ul_nc(unsigned long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long min, unsigned long max);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
|
||||
inline int a2ull_nc(unsigned long long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max);
|
||||
|
||||
|
||||
inline int
|
||||
a2uh_nc(unsigned short *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned short min,
|
||||
unsigned short max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtou_noneg(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ui_nc(unsigned int *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned int min, unsigned int max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtou_noneg(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ul_nc(unsigned long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long min, unsigned long max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtou_noneg(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
a2ull_nc(unsigned long long *restrict n, char *s,
|
||||
char **restrict endp, int base, unsigned long long min,
|
||||
unsigned long long max)
|
||||
{
|
||||
int status;
|
||||
|
||||
*n = strtou_noneg(s, endp, base, min, max, &status);
|
||||
if (status != 0) {
|
||||
errno = status;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
16
lib/atoi/getnum.c
Normal file
16
lib/atoi/getnum.c
Normal file
@@ -0,0 +1,16 @@
|
||||
// SPDX-FileCopyrightText: 2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "atoi/getnum.h"
|
||||
|
||||
|
||||
extern inline int get_fd(const char *restrict fdstr, int *restrict fd);
|
||||
extern inline int get_gid(const char *restrict gidstr, gid_t *restrict gid);
|
||||
extern inline int get_pid(const char *restrict pidstr, pid_t *restrict pid);
|
||||
extern inline int get_uid(const char *restrict uidstr, uid_t *restrict uid);
|
||||
60
lib/atoi/getnum.h
Normal file
60
lib/atoi/getnum.h
Normal file
@@ -0,0 +1,60 @@
|
||||
// SPDX-FileCopyrightText: 2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_GETNUM_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_GETNUM_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "atoi/a2i/a2i.h"
|
||||
#include "atoi/a2i/a2s.h"
|
||||
#include "attr.h"
|
||||
#include "typetraits.h"
|
||||
|
||||
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
|
||||
inline int get_fd(const char *restrict fdstr, int *restrict fd);
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
|
||||
inline int get_gid(const char *restrict gidstr, gid_t *restrict gid);
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
|
||||
inline int get_pid(const char *restrict pidstr, pid_t *restrict pid);
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
|
||||
inline int get_uid(const char *restrict uidstr, uid_t *restrict uid);
|
||||
|
||||
|
||||
inline int
|
||||
get_fd(const char *restrict fdstr, int *restrict fd)
|
||||
{
|
||||
return a2si(fd, fdstr, NULL, 10, 0, INT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
get_gid(const char *restrict gidstr, gid_t *restrict gid)
|
||||
{
|
||||
return a2i(gid_t, gid, gidstr, NULL, 10, type_min(gid_t), type_max(gid_t));
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
get_pid(const char *restrict pidstr, pid_t *restrict pid)
|
||||
{
|
||||
return a2i(pid_t, pid, pidstr, NULL, 10, 1, type_max(pid_t));
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
get_uid(const char *restrict uidstr, uid_t *restrict uid)
|
||||
{
|
||||
return a2i(uid_t, uid, uidstr, NULL, 10, type_min(uid_t), type_max(uid_t));
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
8
lib/atoi/str2i/str2i.c
Normal file
8
lib/atoi/str2i/str2i.c
Normal file
@@ -0,0 +1,8 @@
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/str2i/str2i.h"
|
||||
31
lib/atoi/str2i/str2i.h
Normal file
31
lib/atoi/str2i/str2i.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2I_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2I_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/str2i/str2s.h"
|
||||
#include "atoi/str2i/str2u.h"
|
||||
|
||||
|
||||
#define str2i(TYPE, ...) \
|
||||
( \
|
||||
_Generic((TYPE) 0, \
|
||||
short: str2sh, \
|
||||
int: str2si, \
|
||||
long: str2sl, \
|
||||
long long: str2sll, \
|
||||
unsigned short: str2uh, \
|
||||
unsigned int: str2ui, \
|
||||
unsigned long: str2ul, \
|
||||
unsigned long long: str2ull \
|
||||
)(__VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
14
lib/atoi/str2i/str2s.c
Normal file
14
lib/atoi/str2i/str2s.c
Normal file
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/str2i/str2s.h"
|
||||
|
||||
|
||||
extern inline int str2sh(short *restrict n, const char *restrict s);
|
||||
extern inline int str2si(int *restrict n, const char *restrict s);
|
||||
extern inline int str2sl(long *restrict n, const char *restrict s);
|
||||
extern inline int str2sll(long long *restrict n, const char *restrict s);
|
||||
57
lib/atoi/str2i/str2s.h
Normal file
57
lib/atoi/str2i/str2s.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2S_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2S_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "atoi/a2i/a2s.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2sh(short *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2si(int *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2sl(long *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2sll(long long *restrict n, const char *restrict s);
|
||||
|
||||
|
||||
inline int
|
||||
str2sh(short *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2sh(n, s, NULL, 0, SHRT_MIN, SHRT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2si(int *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2si(n, s, NULL, 0, INT_MIN, INT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2sl(long *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2sl(n, s, NULL, 0, LONG_MIN, LONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2sll(long long *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2sll(n, s, NULL, 0, LLONG_MIN, LLONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
14
lib/atoi/str2i/str2u.c
Normal file
14
lib/atoi/str2i/str2u.c
Normal file
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/str2i/str2u.h"
|
||||
|
||||
|
||||
extern inline int str2uh(unsigned short *restrict n, const char *restrict s);
|
||||
extern inline int str2ui(unsigned int *restrict n, const char *restrict s);
|
||||
extern inline int str2ul(unsigned long *restrict n, const char *restrict s);
|
||||
extern inline int str2ull(unsigned long long *restrict n, const char *restrict s);
|
||||
57
lib/atoi/str2i/str2u.h
Normal file
57
lib/atoi/str2i/str2u.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2U_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2U_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "atoi/a2i/a2u.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2uh(unsigned short *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2ui(unsigned int *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2ul(unsigned long *restrict n, const char *restrict s);
|
||||
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
|
||||
inline int str2ull(unsigned long long *restrict n, const char *restrict s);
|
||||
|
||||
|
||||
inline int
|
||||
str2uh(unsigned short *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2uh(n, s, NULL, 0, 0, USHRT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2ui(unsigned int *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2ui(n, s, NULL, 0, 0, UINT_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2ul(unsigned long *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2ul(n, s, NULL, 0, 0, ULONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
str2ull(unsigned long long *restrict n, const char *restrict s)
|
||||
{
|
||||
return a2ull(n, s, NULL, 0, 0, ULLONG_MAX);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -1,15 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/strtoi.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern inline intmax_t strtoi_(const char *s, char **restrict endp, int base,
|
||||
intmax_t min, intmax_t max, int *restrict status);
|
||||
extern inline uintmax_t strtou_(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status);
|
||||
@@ -1,96 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOI_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STRTOI_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
#define strtoNmax(TYPE, ...) \
|
||||
( \
|
||||
_Generic((TYPE) 0, \
|
||||
intmax_t: strtoimax, \
|
||||
uintmax_t: strtoumax \
|
||||
)(__VA_ARGS__) \
|
||||
)
|
||||
|
||||
|
||||
#define strtoN(s, endp, base, min, max, status, TYPE) \
|
||||
({ \
|
||||
const char *s_ = s; \
|
||||
char **endp_ = endp; \
|
||||
int base_ = base; \
|
||||
TYPE min_ = min; \
|
||||
TYPE max_ = max; \
|
||||
int *status_ = status; \
|
||||
\
|
||||
int e_, st_; \
|
||||
char *end_; \
|
||||
TYPE n_; \
|
||||
\
|
||||
if (endp_ == NULL) \
|
||||
endp_ = &end_; \
|
||||
if (status_ == NULL) \
|
||||
status_ = &st_; \
|
||||
\
|
||||
if (base_ != 0 && (base_ < 0 || base_ > 36)) { \
|
||||
*status_ = EINVAL; \
|
||||
n_ = 0; \
|
||||
\
|
||||
} else { \
|
||||
e_ = errno; \
|
||||
errno = 0; \
|
||||
n_ = strtoNmax(TYPE, s_, endp_, base_); \
|
||||
\
|
||||
if (*endp_ == s_) \
|
||||
*status_ = ECANCELED; \
|
||||
else if (errno == ERANGE || n_ < min_ || n_ > max_) \
|
||||
*status_ = ERANGE; \
|
||||
else if (**endp_ != '\0') \
|
||||
*status_ = ENOTSUP; \
|
||||
else \
|
||||
*status_ = 0; \
|
||||
\
|
||||
errno = e_; \
|
||||
} \
|
||||
MAX(min_, MIN(max_, n_)); \
|
||||
})
|
||||
|
||||
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
|
||||
inline intmax_t strtoi_(const char *s, char **restrict endp, int base,
|
||||
intmax_t min, intmax_t max, int *restrict status);
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
|
||||
inline uintmax_t strtou_(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status);
|
||||
|
||||
|
||||
inline intmax_t
|
||||
strtoi_(const char *s, char **restrict endp, int base,
|
||||
intmax_t min, intmax_t max, int *restrict status)
|
||||
{
|
||||
return strtoN(s, endp, base, min, max, status, intmax_t);
|
||||
}
|
||||
|
||||
|
||||
inline uintmax_t
|
||||
strtou_(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status)
|
||||
{
|
||||
return strtoN(s, endp, base, min, max, status, uintmax_t);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
13
lib/atoi/strtoi/strtoi.c
Normal file
13
lib/atoi/strtoi/strtoi.c
Normal file
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/strtoi/strtoi.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern inline intmax_t strtoi_(const char *s, char **restrict endp, int base,
|
||||
intmax_t min, intmax_t max, int *restrict status);
|
||||
64
lib/atoi/strtoi/strtoi.h
Normal file
64
lib/atoi/strtoi/strtoi.h
Normal file
@@ -0,0 +1,64 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOI_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOI_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
|
||||
inline intmax_t strtoi_(const char *s, char **restrict endp, int base,
|
||||
intmax_t min, intmax_t max, int *restrict status);
|
||||
|
||||
|
||||
inline intmax_t
|
||||
strtoi_(const char *s, char **restrict endp, int base,
|
||||
intmax_t min, intmax_t max, int *restrict status)
|
||||
{
|
||||
int e, st;
|
||||
char *end;
|
||||
intmax_t n;
|
||||
|
||||
if (endp == NULL)
|
||||
endp = &end;
|
||||
if (status == NULL)
|
||||
status = &st;
|
||||
|
||||
if (base != 0 && (base < 2 || base > 36)) {
|
||||
*status = EINVAL;
|
||||
return MAX(min, MIN(max, 0));
|
||||
}
|
||||
|
||||
e = errno;
|
||||
errno = 0;
|
||||
|
||||
n = strtoimax(s, endp, base);
|
||||
|
||||
if (*endp == s)
|
||||
*status = ECANCELED;
|
||||
else if (errno == ERANGE || n < min || n > max)
|
||||
*status = ERANGE;
|
||||
else if (**endp != '\0')
|
||||
*status = ENOTSUP;
|
||||
else
|
||||
*status = 0;
|
||||
|
||||
errno = e;
|
||||
|
||||
return MAX(min, MIN(max, n));
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
13
lib/atoi/strtoi/strtou.c
Normal file
13
lib/atoi/strtoi/strtou.c
Normal file
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/strtoi/strtou.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern inline uintmax_t strtou_(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status);
|
||||
64
lib/atoi/strtoi/strtou.h
Normal file
64
lib/atoi/strtoi/strtou.h
Normal file
@@ -0,0 +1,64 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
|
||||
inline uintmax_t strtou_(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status);
|
||||
|
||||
|
||||
inline uintmax_t
|
||||
strtou_(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status)
|
||||
{
|
||||
int e, st;
|
||||
char *end;
|
||||
uintmax_t n;
|
||||
|
||||
if (endp == NULL)
|
||||
endp = &end;
|
||||
if (status == NULL)
|
||||
status = &st;
|
||||
|
||||
if (base != 0 && (base < 2 || base > 36)) {
|
||||
*status = EINVAL;
|
||||
return MAX(min, 0);
|
||||
}
|
||||
|
||||
e = errno;
|
||||
errno = 0;
|
||||
|
||||
n = strtoumax(s, endp, base);
|
||||
|
||||
if (*endp == s)
|
||||
*status = ECANCELED;
|
||||
else if (errno == ERANGE || n < min || n > max)
|
||||
*status = ERANGE;
|
||||
else if (**endp != '\0')
|
||||
*status = ENOTSUP;
|
||||
else
|
||||
*status = 0;
|
||||
|
||||
errno = e;
|
||||
|
||||
return MAX(min, MIN(max, n));
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
13
lib/atoi/strtoi/strtou_noneg.c
Normal file
13
lib/atoi/strtoi/strtou_noneg.c
Normal file
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/strtoi/strtou_noneg.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern inline uintmax_t strtou_noneg(const char *s, char **restrict endp,
|
||||
int base, uintmax_t min, uintmax_t max, int *restrict status);
|
||||
40
lib/atoi/strtoi/strtou_noneg.h
Normal file
40
lib/atoi/strtoi/strtou_noneg.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_NONEG_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_NONEG_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "atoi/strtoi/strtoi.h"
|
||||
#include "atoi/strtoi/strtou.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
|
||||
inline uintmax_t strtou_noneg(const char *s, char **restrict endp,
|
||||
int base, uintmax_t min, uintmax_t max, int *restrict status);
|
||||
|
||||
|
||||
inline uintmax_t
|
||||
strtou_noneg(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status)
|
||||
{
|
||||
int st;
|
||||
|
||||
if (status == NULL)
|
||||
status = &st;
|
||||
if (strtoi_(s, endp, base, 0, 1, status) == 0 && *status == ERANGE)
|
||||
return min;
|
||||
|
||||
return strtou_(s, endp, base, min, max, status);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -1,18 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "atoi/strtou_noneg.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern inline uintmax_t strtou_noneg(const char *s, char **restrict endp,
|
||||
int base, uintmax_t min, uintmax_t max, int *restrict status);
|
||||
|
||||
extern inline unsigned long strtoul_noneg(const char *s,
|
||||
char **restrict endp, int base);
|
||||
extern inline unsigned long long strtoull_noneg(const char *s,
|
||||
char **restrict endp, int base);
|
||||
@@ -1,68 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOU_NONEG_H_
|
||||
#define SHADOW_INCLUDE_LIB_ATOI_STRTOU_NONEG_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "atoi/strtoi.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
|
||||
inline uintmax_t strtou_noneg(const char *s, char **restrict endp,
|
||||
int base, uintmax_t min, uintmax_t max, int *restrict status);
|
||||
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
|
||||
inline unsigned long strtoul_noneg(const char *s,
|
||||
char **restrict endp, int base);
|
||||
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
|
||||
inline unsigned long long strtoull_noneg(const char *s,
|
||||
char **restrict endp, int base);
|
||||
|
||||
|
||||
inline uintmax_t
|
||||
strtou_noneg(const char *s, char **restrict endp, int base,
|
||||
uintmax_t min, uintmax_t max, int *restrict status)
|
||||
{
|
||||
int st;
|
||||
|
||||
if (status == NULL)
|
||||
status = &st;
|
||||
if (strtoi_(s, endp, base, 0, 1, status) == 0 && *status == ERANGE)
|
||||
return min;
|
||||
|
||||
return strtou_(s, endp, base, min, max, status);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned long
|
||||
strtoul_noneg(const char *s, char **restrict endp, int base)
|
||||
{
|
||||
if (strtol(s, endp, base) < 0) {
|
||||
errno = ERANGE;
|
||||
return 0;
|
||||
}
|
||||
return strtoul(s, endp, base);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned long long
|
||||
strtoull_noneg(const char *s, char **restrict endp, int base)
|
||||
{
|
||||
if (strtol(s, endp, base) < 0) {
|
||||
errno = ERANGE;
|
||||
return 0;
|
||||
}
|
||||
return strtoull(s, endp, base);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
14
lib/attr.h
14
lib/attr.h
@@ -6,15 +6,17 @@
|
||||
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# define MAYBE_UNUSED __attribute__((unused))
|
||||
# define NORETURN __attribute__((__noreturn__))
|
||||
# define format_attr(type, fmt, va) __attribute__((format(type, fmt, va)))
|
||||
# define ATTR_ACCESS(...) __attribute__((access(__VA_ARGS__)))
|
||||
# define MAYBE_UNUSED [[gnu::unused]]
|
||||
# define NORETURN [[gnu::__noreturn__]]
|
||||
# define format_attr(type, fmt, va) [[gnu::format(type, fmt, va)]]
|
||||
# define ATTR_ACCESS(...) [[gnu::access(__VA_ARGS__)]]
|
||||
# define ATTR_ALLOC_SIZE(...) [[gnu::alloc_size(__VA_ARGS__)]]
|
||||
#else
|
||||
# define MAYBE_UNUSED
|
||||
# define NORETURN
|
||||
# define format_attr(type, fmt, va)
|
||||
# define ATTR_ACCESS(...)
|
||||
# define ATTR_ALLOC_SIZE(...)
|
||||
#endif
|
||||
|
||||
#if (__GNUC__ >= 11) && !defined(__clang__)
|
||||
@@ -24,9 +26,9 @@
|
||||
#endif
|
||||
|
||||
#if (__GNUC__ >= 14)
|
||||
# define ATTR_STRING(...) [[gnu::null_terminated_string_arg(__VA_ARGS__)]]
|
||||
# define ATTR_STRING(i) [[gnu::null_terminated_string_arg(i)]]
|
||||
#else
|
||||
# define ATTR_STRING(...)
|
||||
# define ATTR_STRING(i)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -8,14 +8,8 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "must_be.h"
|
||||
|
||||
|
||||
#define const_cast(T, p) \
|
||||
({ \
|
||||
static_assert(is_same_type(typeof(&*(p)), const T), ""); \
|
||||
(T) (p); \
|
||||
})
|
||||
#define const_cast(T, p) _Generic(p, const T: (T) (p))
|
||||
|
||||
|
||||
#endif // include guard
|
||||
|
||||
@@ -5,14 +5,19 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
/*
|
||||
* is_valid_user_name(), is_valid_group_name() - check the new user/group
|
||||
* name for validity;
|
||||
* return values:
|
||||
* true - OK
|
||||
* false - bad name
|
||||
* errors:
|
||||
* EINVAL Invalid name characters or sequences
|
||||
* EOVERFLOW Name longer than maximum size
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
@@ -20,12 +25,36 @@
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "chkname.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
int allow_bad_names = false;
|
||||
|
||||
static bool is_valid_name (const char *name)
|
||||
|
||||
size_t
|
||||
login_name_max_size(void)
|
||||
{
|
||||
long conf;
|
||||
|
||||
errno = 0;
|
||||
conf = sysconf(_SC_LOGIN_NAME_MAX);
|
||||
if (conf == -1 && errno != 0)
|
||||
return LOGIN_NAME_MAX;
|
||||
|
||||
return MIN(conf, PTRDIFF_MAX);
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
is_valid_name(const char *name)
|
||||
{
|
||||
if (allow_bad_names) {
|
||||
return true;
|
||||
@@ -49,13 +78,15 @@ static bool is_valid_name (const char *name)
|
||||
(*name >= 'A' && *name <= 'Z') ||
|
||||
(*name >= '0' && *name <= '9') ||
|
||||
*name == '_' ||
|
||||
*name == '.')) {
|
||||
*name == '.'))
|
||||
{
|
||||
errno = EINVAL;
|
||||
return false;
|
||||
}
|
||||
|
||||
numeric = isdigit(*name);
|
||||
|
||||
while ('\0' != *++name) {
|
||||
while (!streq(++name, "")) {
|
||||
if (!((*name >= 'a' && *name <= 'z') ||
|
||||
(*name >= 'A' && *name <= 'Z') ||
|
||||
(*name >= '0' && *name <= '9') ||
|
||||
@@ -63,45 +94,46 @@ static bool is_valid_name (const char *name)
|
||||
*name == '.' ||
|
||||
*name == '-' ||
|
||||
(*name == '$' && name[1] == '\0')
|
||||
)) {
|
||||
))
|
||||
{
|
||||
errno = EINVAL;
|
||||
return false;
|
||||
}
|
||||
numeric &= isdigit(*name);
|
||||
}
|
||||
|
||||
return !numeric;
|
||||
if (numeric) {
|
||||
errno = EINVAL;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
is_valid_user_name(const char *name)
|
||||
{
|
||||
long conf;
|
||||
size_t maxsize;
|
||||
|
||||
errno = 0;
|
||||
conf = sysconf(_SC_LOGIN_NAME_MAX);
|
||||
|
||||
if (conf == -1 && errno != 0)
|
||||
maxsize = LOGIN_NAME_MAX;
|
||||
else
|
||||
maxsize = conf;
|
||||
|
||||
if (strlen(name) >= maxsize)
|
||||
if (strlen(name) >= login_name_max_size()) {
|
||||
errno = EOVERFLOW;
|
||||
return false;
|
||||
}
|
||||
|
||||
return is_valid_name(name);
|
||||
}
|
||||
|
||||
|
||||
bool is_valid_group_name (const char *name)
|
||||
bool
|
||||
is_valid_group_name(const char *name)
|
||||
{
|
||||
/*
|
||||
* Arbitrary limit for group names.
|
||||
* HP-UX 10 limits to 16 characters
|
||||
*/
|
||||
if ( (GROUP_NAME_MAX_LENGTH > 0)
|
||||
&& (strlen (name) > GROUP_NAME_MAX_LENGTH)) {
|
||||
&& (strlen (name) > GROUP_NAME_MAX_LENGTH))
|
||||
{
|
||||
errno = EOVERFLOW;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#ifndef _CHKNAME_H_
|
||||
#define _CHKNAME_H_
|
||||
|
||||
|
||||
/*
|
||||
* is_valid_user_name(), is_valid_group_name() - check the new user/group
|
||||
* name for validity;
|
||||
@@ -19,8 +20,14 @@
|
||||
* false - bad name
|
||||
*/
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern size_t login_name_max_size(void);
|
||||
extern bool is_valid_user_name (const char *name);
|
||||
extern bool is_valid_group_name (const char *name);
|
||||
|
||||
|
||||
@@ -13,12 +13,15 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
static int chown_tree_at (int at_fd,
|
||||
const char *path,
|
||||
uid_t old_uid,
|
||||
@@ -56,8 +59,8 @@ static int chown_tree_at (int at_fd,
|
||||
/*
|
||||
* Skip the "." and ".." entries
|
||||
*/
|
||||
if ( (strcmp (ent->d_name, ".") == 0)
|
||||
|| (strcmp (ent->d_name, "..") == 0)) {
|
||||
if ( streq(ent->d_name, ".")
|
||||
|| streq(ent->d_name, "..")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ void do_cleanups (void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
/* Make sure there were no overflow */
|
||||
/* Make sure there were no overflows */
|
||||
assert (NULL == cleanup_functions[CLEANUP_FUNCTIONS-1]);
|
||||
|
||||
if (getpid () != cleanup_pid) {
|
||||
|
||||
@@ -11,28 +11,33 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "defines.h"
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <utime.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "memzero.h"
|
||||
#include "alloc/malloc.h"
|
||||
#include "alloc/reallocf.h"
|
||||
#include "atoi/getnum.h"
|
||||
#include "commonio.h"
|
||||
#include "defines.h"
|
||||
#include "nscd.h"
|
||||
#include "sssd.h"
|
||||
#ifdef WITH_TCB
|
||||
#include <tcb.h>
|
||||
#endif /* WITH_TCB */
|
||||
#include "prototypes.h"
|
||||
#include "commonio.h"
|
||||
#include "shadowlog_internal.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "sssd.h"
|
||||
#include "string/memset/memzero.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strtok/stpsep.h"
|
||||
|
||||
|
||||
/* local function prototypes */
|
||||
@@ -194,7 +199,7 @@ static int do_lock_file (const char *file, const char *lock, bool log)
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
buf[len] = '\0';
|
||||
stpcpy(&buf[len], "");
|
||||
if (get_pid(buf, &pid) == -1) {
|
||||
if (log) {
|
||||
(void) fprintf (shadow_logfd,
|
||||
@@ -573,9 +578,7 @@ static void add_one_entry_nis (struct commonio_db *db,
|
||||
int commonio_open (struct commonio_db *db, int mode)
|
||||
{
|
||||
char *buf;
|
||||
char *cp;
|
||||
char *line;
|
||||
struct commonio_entry *p;
|
||||
void *eptr = NULL;
|
||||
int flags = mode;
|
||||
size_t buflen;
|
||||
@@ -636,21 +639,21 @@ int commonio_open (struct commonio_db *db, int mode)
|
||||
|
||||
buflen = BUFLEN;
|
||||
buf = MALLOC(buflen, char);
|
||||
if (NULL == buf) {
|
||||
goto cleanup_ENOMEM;
|
||||
}
|
||||
if (NULL == buf)
|
||||
goto cleanup_errno;
|
||||
|
||||
while (db->ops->fgets (buf, buflen, db->fp) == buf) {
|
||||
struct commonio_entry *p;
|
||||
|
||||
while ( (strrchr (buf, '\n') == NULL)
|
||||
&& (feof (db->fp) == 0)) {
|
||||
size_t len;
|
||||
|
||||
buflen += BUFLEN;
|
||||
cp = REALLOC(buf, buflen, char);
|
||||
if (NULL == cp) {
|
||||
goto cleanup_buf;
|
||||
}
|
||||
buf = cp;
|
||||
buf = REALLOCF(buf, buflen, char);
|
||||
if (NULL == buf)
|
||||
goto cleanup_errno;
|
||||
|
||||
len = strlen (buf);
|
||||
if (db->ops->fgets (buf + len,
|
||||
(int) (buflen - len),
|
||||
@@ -658,10 +661,7 @@ int commonio_open (struct commonio_db *db, int mode)
|
||||
goto cleanup_buf;
|
||||
}
|
||||
}
|
||||
cp = strrchr (buf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
stpsep(buf, "\n");
|
||||
|
||||
line = strdup (buf);
|
||||
if (NULL == line) {
|
||||
@@ -713,7 +713,6 @@ int commonio_open (struct commonio_db *db, int mode)
|
||||
free (line);
|
||||
cleanup_buf:
|
||||
free (buf);
|
||||
cleanup_ENOMEM:
|
||||
errno = ENOMEM;
|
||||
cleanup_errno:
|
||||
saved_errno = errno;
|
||||
@@ -832,10 +831,8 @@ int commonio_sort_wrt (struct commonio_db *shadow,
|
||||
if (NULL == spw_ptr->eptr) {
|
||||
continue;
|
||||
}
|
||||
if (strcmp (name, shadow->ops->getname (spw_ptr->eptr))
|
||||
== 0) {
|
||||
if (streq(name, shadow->ops->getname(spw_ptr->eptr)))
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (NULL == spw_ptr) {
|
||||
continue;
|
||||
@@ -1036,7 +1033,7 @@ static /*@dependent@*/ /*@null@*/struct commonio_entry *next_entry_by_name (
|
||||
for (p = pos; NULL != p; p = p->next) {
|
||||
ep = p->eptr;
|
||||
if ( (NULL != ep)
|
||||
&& (strcmp (db->ops->getname (ep), name) == 0)) {
|
||||
&& streq(db->ops->getname(ep), name)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1242,7 +1239,7 @@ int commonio_rewind (struct commonio_db *db)
|
||||
|
||||
if (!db->isopen) {
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
if (NULL == db->cursor) {
|
||||
db->cursor = db->head;
|
||||
|
||||
@@ -9,20 +9,25 @@
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include "defines.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strtcpy.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
#include "string/strtok/stpsep.h"
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
/*
|
||||
* This is now rather generic function which decides if "tty" is listed
|
||||
* under "cfgin" in config (directly or indirectly). Fallback to default if
|
||||
* something is bad.
|
||||
*/
|
||||
static bool is_listed (const char *cfgin, const char *tty, bool def)
|
||||
static bool
|
||||
is_listed(const char *cfgin, const char *tty, bool def)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[1024], *s;
|
||||
@@ -45,14 +50,13 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
|
||||
|
||||
if (*cons != '/') {
|
||||
char *pbuf;
|
||||
|
||||
STRTCPY(buf, cons);
|
||||
pbuf = &buf[0];
|
||||
while ((s = strtok (pbuf, ":")) != NULL) {
|
||||
if (strcmp (s, tty) == 0) {
|
||||
pbuf = buf;
|
||||
while (NULL != (s = strsep(&pbuf, ":"))) {
|
||||
if (streq(s, tty)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
pbuf = NULL;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -72,9 +76,8 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
|
||||
*/
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp) != NULL) {
|
||||
/* Remove optional trailing '\n'. */
|
||||
buf[strcspn (buf, "\n")] = '\0';
|
||||
if (strcmp (buf, tty) == 0) {
|
||||
stpsep(buf, "\n");
|
||||
if (streq(buf, tty)) {
|
||||
(void) fclose (fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
#include <sys/time.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "alloc/x/xmalloc.h"
|
||||
#include "attr.h"
|
||||
#include "fs/readlink/areadlink.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#ifdef WITH_SELINUX
|
||||
@@ -36,7 +38,8 @@
|
||||
#include <attr/libattr.h>
|
||||
#endif /* WITH_ATTR */
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
static /*@null@*/const char *src_orig;
|
||||
@@ -66,7 +69,6 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst,
|
||||
const struct stat *statp, const struct timespec mt[],
|
||||
uid_t old_uid, uid_t new_uid,
|
||||
gid_t old_gid, gid_t new_gid);
|
||||
static /*@null@*/char *readlink_malloc (const char *filename);
|
||||
static int copy_symlink (const struct path_info *src, const struct path_info *dst,
|
||||
MAYBE_UNUSED bool reset_selinux,
|
||||
const struct stat *statp, const struct timespec mt[],
|
||||
@@ -313,8 +315,8 @@ static int copy_tree_impl (const struct path_info *src, const struct path_info *
|
||||
/*
|
||||
* Skip the "." and ".." entries
|
||||
*/
|
||||
if (strcmp(ent->d_name, ".") == 0 ||
|
||||
strcmp(ent->d_name, "..") == 0)
|
||||
if (streq(ent->d_name, ".") ||
|
||||
streq(ent->d_name, ".."))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -400,6 +402,7 @@ static int copy_entry (const struct path_info *src, const struct path_info *dst,
|
||||
{
|
||||
int err = 0;
|
||||
struct stat sb;
|
||||
struct stat tmp_sb;
|
||||
struct link_name *lp;
|
||||
struct timespec mt[2];
|
||||
|
||||
@@ -423,7 +426,7 @@ static int copy_entry (const struct path_info *src, const struct path_info *dst,
|
||||
* If the destination already exists do nothing.
|
||||
* This is after the copy_dir above to still iterate into subdirectories.
|
||||
*/
|
||||
if (fstatat(dst->dirfd, dst->name, &sb, AT_SYMLINK_NOFOLLOW) != -1) {
|
||||
if (fstatat(dst->dirfd, dst->name, &tmp_sb, AT_SYMLINK_NOFOLLOW) != -1) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -535,42 +538,6 @@ static int copy_dir (const struct path_info *src, const struct path_info *dst,
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* readlink_malloc - wrapper for readlink
|
||||
*
|
||||
* return NULL on error.
|
||||
* The return string shall be freed by the caller.
|
||||
*/
|
||||
static /*@null@*/char *readlink_malloc (const char *filename)
|
||||
{
|
||||
size_t size = 1024;
|
||||
|
||||
while (true) {
|
||||
ssize_t nchars;
|
||||
char *buffer = MALLOC(size, char);
|
||||
if (NULL == buffer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nchars = readlink (filename, buffer, size);
|
||||
|
||||
if (nchars < 0) {
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((size_t) nchars < size) { /* The buffer was large enough */
|
||||
/* readlink does not nul-terminate */
|
||||
buffer[nchars] = '\0';
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/* Try again with a bigger buffer */
|
||||
free (buffer);
|
||||
size *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* copy_symlink - copy a symlink
|
||||
*
|
||||
@@ -601,10 +568,9 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds
|
||||
* destination directory name.
|
||||
*/
|
||||
|
||||
oldlink = readlink_malloc (src->full_path);
|
||||
if (NULL == oldlink) {
|
||||
oldlink = areadlink(src->full_path);
|
||||
if (NULL == oldlink)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If src was a link to an entry of the src_orig directory itself,
|
||||
* create a link to the corresponding entry in the dst_orig
|
||||
|
||||
39
lib/csrand.c
39
lib/csrand.c
@@ -1,21 +1,19 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Alejandro Colomar <alx@kernel.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#if HAVE_SYS_RANDOM_H
|
||||
#include <sys/random.h>
|
||||
#endif
|
||||
|
||||
#include "bit.h"
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
@@ -23,6 +21,7 @@
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
static uint32_t csrand32(void);
|
||||
static uint32_t csrand_uniform32(uint32_t n);
|
||||
static unsigned long csrand_uniform_slow(unsigned long n);
|
||||
|
||||
@@ -33,7 +32,7 @@ static unsigned long csrand_uniform_slow(unsigned long n);
|
||||
unsigned long
|
||||
csrand(void)
|
||||
{
|
||||
FILE *fp;
|
||||
int fd;
|
||||
unsigned long r;
|
||||
|
||||
#ifdef HAVE_GETENTROPY
|
||||
@@ -55,17 +54,16 @@ csrand(void)
|
||||
#endif
|
||||
|
||||
/* Use /dev/urandom as a last resort. */
|
||||
fp = fopen("/dev/urandom", "r");
|
||||
if (NULL == fp) {
|
||||
fd = open("/dev/urandom", O_RDONLY);
|
||||
if (fd == -1)
|
||||
goto fail;
|
||||
|
||||
if (read(fd, &r, sizeof(r)) != sizeof(r)) {
|
||||
close(fd);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (fread(&r, sizeof(r), 1, fp) != 1) {
|
||||
fclose(fp);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
close(fd);
|
||||
return r;
|
||||
|
||||
fail:
|
||||
@@ -97,6 +95,13 @@ csrand_interval(unsigned long min, unsigned long max)
|
||||
}
|
||||
|
||||
|
||||
static uint32_t
|
||||
csrand32(void)
|
||||
{
|
||||
return csrand();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Fast Random Integer Generation in an Interval
|
||||
* ACM Transactions on Modeling and Computer Simulation 29 (1), 2019
|
||||
@@ -109,12 +114,12 @@ csrand_uniform32(uint32_t n)
|
||||
uint64_t r, mult;
|
||||
|
||||
if (n == 0)
|
||||
return csrand();
|
||||
return csrand32();
|
||||
|
||||
bound = -n % n; // analogous to `2^32 % n`, since `x % y == (x-y) % y`
|
||||
|
||||
do {
|
||||
r = csrand();
|
||||
r = csrand32();
|
||||
mult = r * n;
|
||||
rem = mult; // analogous to `mult % 2^32`
|
||||
} while (rem < bound); // p = (2^32 % n) / 2^32; W.C.: n=2^31+1, p=0.5
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2023, Alejandro Colomar <alx@kernel.org>
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "string/strtcpy.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
|
||||
void
|
||||
date_to_str(size_t size, char buf[size], long date)
|
||||
{
|
||||
time_t t;
|
||||
const struct tm *tm;
|
||||
|
||||
t = date;
|
||||
if (date < 0) {
|
||||
(void) strtcpy(buf, "never", size);
|
||||
return;
|
||||
}
|
||||
|
||||
tm = gmtime(&t);
|
||||
if (tm == NULL) {
|
||||
(void) strtcpy(buf, "future", size);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strftime(buf, size, "%Y-%m-%d", tm) == 0)
|
||||
(void) strtcpy(buf, "future", size);
|
||||
}
|
||||
35
lib/env.c
35
lib/env.c
@@ -16,11 +16,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "alloc/x/xmalloc.h"
|
||||
#include "alloc/x/xrealloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -127,30 +130,18 @@ void addenv (const char *string, /*@null@*/const char *value)
|
||||
|
||||
if ((newenvc & (NEWENVP_STEP - 1)) == 0) {
|
||||
bool update_environ;
|
||||
char **__newenvp;
|
||||
|
||||
/*
|
||||
* If the resize operation succeeds we can
|
||||
* happily go on, else print a message.
|
||||
*/
|
||||
update_environ = (environ == newenvp);
|
||||
|
||||
__newenvp = REALLOC(newenvp, newenvc + NEWENVP_STEP, char *);
|
||||
newenvp = XREALLOC(newenvp, newenvc + NEWENVP_STEP, char *);
|
||||
|
||||
if (NULL != __newenvp) {
|
||||
/*
|
||||
* If this is our current environment, update
|
||||
* environ so that it doesn't point to some
|
||||
* free memory area (realloc() could move it).
|
||||
*/
|
||||
if (update_environ)
|
||||
environ = __newenvp;
|
||||
newenvp = __newenvp;
|
||||
} else {
|
||||
(void) fputs (_("Environment overflow\n"), log_get_logfd());
|
||||
newenvc--;
|
||||
free (newenvp[newenvc]);
|
||||
}
|
||||
/*
|
||||
* If this is our current environment, update
|
||||
* environ so that it doesn't point to some
|
||||
* free memory area (realloc() could move it).
|
||||
*/
|
||||
if (update_environ)
|
||||
environ = newenvp;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -14,12 +14,14 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "faillog.h"
|
||||
#include "failure.h"
|
||||
#include "memzero.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strtcpy.h"
|
||||
#include "string/memset/memzero.h"
|
||||
#include "string/strftime.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
|
||||
|
||||
#define YEAR (365L*DAY)
|
||||
@@ -80,7 +82,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl)
|
||||
}
|
||||
|
||||
STRTCPY(fl->fail_line, tty);
|
||||
(void) time (&fl->fail_time);
|
||||
fl->fail_time = time(NULL);
|
||||
|
||||
/*
|
||||
* Seek back to the correct position in the file and write the
|
||||
@@ -124,7 +126,7 @@ static bool too_many_failures (const struct faillog *fl)
|
||||
return true; /* locked until reset manually */
|
||||
}
|
||||
|
||||
(void) time (&now);
|
||||
now = time(NULL);
|
||||
if ((fl->fail_time + fl->fail_locktime) < now) {
|
||||
return false; /* enough time since last failure */
|
||||
}
|
||||
@@ -240,19 +242,17 @@ void failprint (const struct faillog *fail)
|
||||
struct tm *tp;
|
||||
char lasttimeb[256];
|
||||
char *lasttime = lasttimeb;
|
||||
time_t NOW;
|
||||
|
||||
if (0 == fail->fail_cnt) {
|
||||
return;
|
||||
}
|
||||
|
||||
tp = localtime (&(fail->fail_time));
|
||||
(void) time (&NOW);
|
||||
|
||||
/*
|
||||
* Print all information we have.
|
||||
*/
|
||||
(void) strftime (lasttimeb, sizeof lasttimeb, "%c", tp);
|
||||
STRFTIME(lasttimeb, "%c", tp);
|
||||
|
||||
/*@-formatconst@*/
|
||||
(void) printf (ngettext ("%d failure since last login.\n"
|
||||
|
||||
41
lib/fd.c
Normal file
41
lib/fd.c
Normal file
@@ -0,0 +1,41 @@
|
||||
// SPDX-FileCopyrightText: 2024, Skyler Ferrante <sjf5462@rit.edu>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
/**
|
||||
* To protect against file descriptor omission attacks, we open the std file
|
||||
* descriptors with /dev/null if they are not already open. Code is based on
|
||||
* fix_fds from sudo.c.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "prototypes.h"
|
||||
|
||||
static void check_fd(int fd);
|
||||
|
||||
void
|
||||
check_fds(void)
|
||||
{
|
||||
/**
|
||||
* Make sure stdin, stdout, stderr are open
|
||||
* If they are closed, set them to /dev/null
|
||||
*/
|
||||
check_fd(STDIN_FILENO);
|
||||
check_fd(STDOUT_FILENO);
|
||||
check_fd(STDERR_FILENO);
|
||||
}
|
||||
|
||||
static void
|
||||
check_fd(int fd)
|
||||
{
|
||||
int devnull;
|
||||
|
||||
if (fcntl(fd, F_GETFL, 0) != -1)
|
||||
return;
|
||||
|
||||
devnull = open("/dev/null", O_RDWR);
|
||||
if (devnull != fd)
|
||||
abort();
|
||||
}
|
||||
31
lib/fields.c
31
lib/fields.c
@@ -14,7 +14,13 @@
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "string/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
|
||||
@@ -42,7 +48,7 @@ int valid_field (const char *field, const char *illegal)
|
||||
}
|
||||
|
||||
/* Search if there are non-printable or control characters */
|
||||
for (cp = field; '\0' != *cp; cp++) {
|
||||
for (cp = field; !streq(cp, ""); cp++) {
|
||||
unsigned char c = *cp;
|
||||
if (!isprint (c)) {
|
||||
err = 1;
|
||||
@@ -62,7 +68,8 @@ int valid_field (const char *field, const char *illegal)
|
||||
* prompt the user with the name of the field being changed and the
|
||||
* current value.
|
||||
*/
|
||||
void change_field (char *buf, size_t maxsize, const char *prompt)
|
||||
void
|
||||
change_field(char *buf, size_t maxsize, const char *prompt)
|
||||
{
|
||||
char newf[200];
|
||||
char *cp;
|
||||
@@ -77,29 +84,17 @@ void change_field (char *buf, size_t maxsize, const char *prompt)
|
||||
return;
|
||||
}
|
||||
|
||||
cp = strchr (newf, '\n');
|
||||
if (NULL == cp) {
|
||||
if (stpsep(newf, "\n") == NULL)
|
||||
return;
|
||||
}
|
||||
*cp = '\0';
|
||||
|
||||
if ('\0' != newf[0]) {
|
||||
if (!streq(newf, "")) {
|
||||
/*
|
||||
* Remove leading and trailing whitespace. This also
|
||||
* makes it possible to change the field to empty, by
|
||||
* entering a space. --marekm
|
||||
*/
|
||||
|
||||
while (newf < cp && isspace (cp[-1])) {
|
||||
cp--;
|
||||
}
|
||||
*cp = '\0';
|
||||
|
||||
cp = newf;
|
||||
while (isspace (*cp)) {
|
||||
cp++;
|
||||
}
|
||||
|
||||
stpcpy(strrspn(newf, " \t"), "");
|
||||
cp = stpspn(newf, " \t");
|
||||
strcpy (buf, cp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "alloc/calloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "groupio.h"
|
||||
#include "getdef.h"
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "alloc/calloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "pwio.h"
|
||||
#include "getdef.h"
|
||||
@@ -304,7 +305,7 @@ int find_new_uid(bool sys_user,
|
||||
return 0;
|
||||
} else if (result == EEXIST || result == EINVAL) {
|
||||
/*
|
||||
* This GID is in use or unusable, we'll
|
||||
* This UID is in use or unusable, we'll
|
||||
* continue to the next.
|
||||
*/
|
||||
} else {
|
||||
@@ -350,7 +351,7 @@ int find_new_uid(bool sys_user,
|
||||
return 0;
|
||||
} else if (result == EEXIST || result == EINVAL) {
|
||||
/*
|
||||
* This GID is in use or unusable, we'll
|
||||
* This UID is in use or unusable, we'll
|
||||
* continue to the next.
|
||||
*/
|
||||
} else {
|
||||
@@ -413,7 +414,7 @@ int find_new_uid(bool sys_user,
|
||||
return 0;
|
||||
} else if (result == EEXIST || result == EINVAL) {
|
||||
/*
|
||||
* This GID is in use or unusable, we'll
|
||||
* This UID is in use or unusable, we'll
|
||||
* continue to the next.
|
||||
*/
|
||||
} else {
|
||||
@@ -459,7 +460,7 @@ int find_new_uid(bool sys_user,
|
||||
return 0;
|
||||
} else if (result == EEXIST || result == EINVAL) {
|
||||
/*
|
||||
* This GID is in use or unusable, we'll
|
||||
* This UID is in use or unusable, we'll
|
||||
* continue to the next.
|
||||
*/
|
||||
} else {
|
||||
|
||||
15
lib/fputsx.c
15
lib/fputsx.c
@@ -10,10 +10,11 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
#ident "$Id$"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
/*@null@*/char *
|
||||
@@ -25,7 +26,7 @@ fgetsx(/*@returned@*/char *restrict buf, int cnt, FILE *restrict f)
|
||||
while (cnt > 0) {
|
||||
if (fgets (cp, cnt, f) != cp) {
|
||||
if (cp == buf) {
|
||||
return 0;
|
||||
return NULL;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@@ -33,10 +34,8 @@ fgetsx(/*@returned@*/char *restrict buf, int cnt, FILE *restrict f)
|
||||
ep = strrchr (cp, '\\');
|
||||
if ((NULL != ep) && (*(ep + 1) == '\n')) {
|
||||
cnt -= ep - cp;
|
||||
if (cnt > 0) {
|
||||
cp = ep;
|
||||
*cp = '\0';
|
||||
}
|
||||
if (cnt > 0)
|
||||
cp = stpcpy(ep, "");
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@@ -48,7 +47,7 @@ int fputsx (const char *s, FILE * stream)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; '\0' != *s; i++, s++) {
|
||||
for (i = 0; !streq(s, ""); i++, s++) {
|
||||
if (putc (*s, stream) == EOF) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
10
lib/fs/readlink/areadlink.c
Normal file
10
lib/fs/readlink/areadlink.c
Normal file
@@ -0,0 +1,10 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "fs/readlink/areadlink.h"
|
||||
|
||||
|
||||
extern inline char *areadlink(const char *link);
|
||||
53
lib/fs/readlink/areadlink.h
Normal file
53
lib/fs/readlink/areadlink.h
Normal file
@@ -0,0 +1,53 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_FS_READLINK_AREADLINK_H_
|
||||
#define SHADOW_INCLUDE_LIB_FS_READLINK_AREADLINK_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "alloc/malloc.h"
|
||||
#include "attr.h"
|
||||
#include "fs/readlink/readlinknul.h"
|
||||
|
||||
|
||||
ATTR_STRING(1)
|
||||
inline char *areadlink(const char *link);
|
||||
|
||||
|
||||
// Similar to readlink(2), but allocate and terminate the string.
|
||||
inline char *
|
||||
areadlink(const char *link)
|
||||
{
|
||||
size_t size = PATH_MAX;
|
||||
|
||||
while (true) {
|
||||
int len;
|
||||
char *buf;
|
||||
|
||||
buf = MALLOC(size, char);
|
||||
if (NULL == buf)
|
||||
return NULL;
|
||||
|
||||
len = readlinknul(link, buf, size);
|
||||
if (len != -1)
|
||||
return buf;
|
||||
|
||||
free(buf);
|
||||
if (errno != E2BIG)
|
||||
return NULL;
|
||||
|
||||
size *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
14
lib/fs/readlink/readlinknul.c
Normal file
14
lib/fs/readlink/readlinknul.c
Normal file
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "fs/readlink/readlinknul.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
extern inline ssize_t readlinknul(const char *restrict link, char *restrict buf,
|
||||
size_t size);
|
||||
53
lib/fs/readlink/readlinknul.h
Normal file
53
lib/fs/readlink/readlinknul.h
Normal file
@@ -0,0 +1,53 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_FS_READLINK_READLINKNUL_H_
|
||||
#define SHADOW_INCLUDE_LIB_FS_READLINK_READLINKNUL_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
#define READLINKNUL(link, buf) readlinknul(link, buf, NITEMS(buf))
|
||||
|
||||
|
||||
ATTR_STRING(1)
|
||||
inline ssize_t readlinknul(const char *restrict link, char *restrict buf,
|
||||
size_t size);
|
||||
|
||||
|
||||
// Similar to readlink(2), but terminate the string.
|
||||
inline ssize_t
|
||||
readlinknul(const char *restrict link, char *restrict buf, size_t size)
|
||||
{
|
||||
size_t ulen;
|
||||
ssize_t slen;
|
||||
|
||||
slen = readlink(link, buf, size);
|
||||
if (slen == -1)
|
||||
return -1;
|
||||
|
||||
ulen = slen;
|
||||
if (ulen == size) {
|
||||
stpcpy(&buf[size-1], "");
|
||||
errno = E2BIG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
stpcpy(&buf[ulen], "");
|
||||
|
||||
return slen;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2009 , Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
|
||||
int
|
||||
get_gid(const char *gidstr, gid_t *gid)
|
||||
{
|
||||
long long val;
|
||||
char *endptr;
|
||||
|
||||
errno = 0;
|
||||
val = strtoll(gidstr, &endptr, 10);
|
||||
if ( ('\0' == *gidstr)
|
||||
|| ('\0' != *endptr)
|
||||
|| (0 != errno)
|
||||
|| (/*@+longintegral@*/val != (gid_t)val)/*@=longintegral@*/) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*gid = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2009 , Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -14,28 +13,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "string/sprintf.h"
|
||||
#include "atoi/getnum.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
|
||||
|
||||
int get_pid (const char *pidstr, pid_t *pid)
|
||||
{
|
||||
long long val;
|
||||
char *endptr;
|
||||
|
||||
errno = 0;
|
||||
val = strtoll(pidstr, &endptr, 10);
|
||||
if ( ('\0' == *pidstr)
|
||||
|| ('\0' != *endptr)
|
||||
|| (0 != errno)
|
||||
|| (val < 1)
|
||||
|| (/*@+longintegral@*/val != (pid_t)val)/*@=longintegral@*/) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*pid = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* If use passed in fd:4 as an argument, then return the
|
||||
* value '4', the fd to use.
|
||||
@@ -43,20 +24,12 @@ int get_pid (const char *pidstr, pid_t *pid)
|
||||
*/
|
||||
int get_pidfd_from_fd(const char *pidfdstr)
|
||||
{
|
||||
long long val;
|
||||
char *endptr;
|
||||
struct stat st;
|
||||
int pidfd;
|
||||
struct stat st;
|
||||
dev_t proc_st_dev, proc_st_rdev;
|
||||
|
||||
errno = 0;
|
||||
val = strtoll(pidfdstr, &endptr, 10);
|
||||
if ( ('\0' == *pidfdstr)
|
||||
|| ('\0' != *endptr)
|
||||
|| (0 != errno)
|
||||
|| (val < 0)
|
||||
|| (/*@+longintegral@*/val != (int)val)/*@=longintegral@*/) {
|
||||
if (get_fd(pidfdstr, &pidfd) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (stat("/proc/self/uid_map", &st) < 0) {
|
||||
return -1;
|
||||
@@ -65,7 +38,7 @@ int get_pidfd_from_fd(const char *pidfdstr)
|
||||
proc_st_dev = st.st_dev;
|
||||
proc_st_rdev = st.st_rdev;
|
||||
|
||||
if (fstat(val, &st) < 0) {
|
||||
if (fstat(pidfd, &st) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -73,7 +46,7 @@ int get_pidfd_from_fd(const char *pidfdstr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (int)val;
|
||||
return pidfd;
|
||||
}
|
||||
|
||||
int open_pidfd(const char *pidstr)
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2009 , Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
|
||||
int
|
||||
get_uid(const char *uidstr, uid_t *uid)
|
||||
{
|
||||
long long val;
|
||||
char *endptr;
|
||||
|
||||
errno = 0;
|
||||
val = strtoll(uidstr, &endptr, 10);
|
||||
if ( ('\0' == *uidstr)
|
||||
|| ('\0' != *endptr)
|
||||
|| (0 != errno)
|
||||
|| (/*@+longintegral@*/val != (uid_t)val)/*@=longintegral@*/) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*uid = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -24,14 +24,16 @@
|
||||
# undef static
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "getdate.h"
|
||||
#include "string/strchr/stpspn.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* Some old versions of bison generate parsers that use bcopy.
|
||||
That loses on systems that don't provide the function, so we have
|
||||
@@ -625,16 +627,16 @@ static int LookupWord (char *buff)
|
||||
bool abbrev;
|
||||
|
||||
/* Make it lowercase. */
|
||||
for (p = buff; '\0' != *p; p++)
|
||||
for (p = buff; !streq(p, ""); p++)
|
||||
if (isupper (*p))
|
||||
*p = tolower (*p);
|
||||
|
||||
if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0)
|
||||
if (streq(buff, "am") || streq(buff, "a.m."))
|
||||
{
|
||||
yylval.Meridian = MERam;
|
||||
return tMERIDIAN;
|
||||
}
|
||||
if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0)
|
||||
if (streq(buff, "pm") || streq(buff, "p.m."))
|
||||
{
|
||||
yylval.Meridian = MERpm;
|
||||
return tMERIDIAN;
|
||||
@@ -646,7 +648,7 @@ static int LookupWord (char *buff)
|
||||
else if (strlen (buff) == 4 && buff[3] == '.')
|
||||
{
|
||||
abbrev = true;
|
||||
buff[3] = '\0';
|
||||
stpcpy(&buff[3], "");
|
||||
}
|
||||
else
|
||||
abbrev = false;
|
||||
@@ -661,7 +663,7 @@ static int LookupWord (char *buff)
|
||||
return tp->type;
|
||||
}
|
||||
}
|
||||
else if (strcmp (buff, tp->name) == 0)
|
||||
else if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -669,17 +671,17 @@ static int LookupWord (char *buff)
|
||||
}
|
||||
|
||||
for (tp = TimezoneTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
}
|
||||
|
||||
if (strcmp (buff, "dst") == 0)
|
||||
if (streq(buff, "dst"))
|
||||
return tDST;
|
||||
|
||||
for (tp = UnitsTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -689,9 +691,9 @@ static int LookupWord (char *buff)
|
||||
i = strlen (buff) - 1;
|
||||
if (buff[i] == 's')
|
||||
{
|
||||
buff[i] = '\0';
|
||||
stpcpy(&buff[i], "");
|
||||
for (tp = UnitsTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -700,7 +702,7 @@ static int LookupWord (char *buff)
|
||||
}
|
||||
|
||||
for (tp = OtherTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -710,7 +712,7 @@ static int LookupWord (char *buff)
|
||||
if (buff[1] == '\0' && isalpha (*buff))
|
||||
{
|
||||
for (tp = MilitaryTable; tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -718,15 +720,15 @@ static int LookupWord (char *buff)
|
||||
}
|
||||
|
||||
/* Drop out any periods and try the timezone table again. */
|
||||
for (i = 0, p = q = buff; '\0' != *q; q++)
|
||||
for (i = 0, p = q = buff; !streq(q, ""); q++)
|
||||
if (*q != '.')
|
||||
*p++ = *q;
|
||||
else
|
||||
i++;
|
||||
*p = '\0';
|
||||
stpcpy(p, "");
|
||||
if (0 != i)
|
||||
for (tp = TimezoneTable; NULL != tp->name; tp++)
|
||||
if (strcmp (buff, tp->name) == 0)
|
||||
if (streq(buff, tp->name))
|
||||
{
|
||||
yylval.Number = tp->value;
|
||||
return tp->type;
|
||||
@@ -746,8 +748,7 @@ yylex (void)
|
||||
|
||||
for (;;)
|
||||
{
|
||||
while (isspace (*yyInput))
|
||||
yyInput++;
|
||||
yyInput = stpspn(yyInput, " \t");
|
||||
|
||||
if (isdigit (c = *yyInput) || c == '-' || c == '+')
|
||||
{
|
||||
@@ -772,7 +773,7 @@ yylex (void)
|
||||
for (p = buff; (c = *yyInput++, isalpha (c)) || c == '.';)
|
||||
if (p < &buff[sizeof buff - 1])
|
||||
*p++ = c;
|
||||
*p = '\0';
|
||||
stpcpy(p, "");
|
||||
yyInput--;
|
||||
return LookupWord (buff);
|
||||
}
|
||||
@@ -821,7 +822,7 @@ time_t get_date (const char *p, const time_t *now)
|
||||
time_t Start;
|
||||
|
||||
yyInput = p;
|
||||
Start = now ? *now : time ((time_t *) NULL);
|
||||
Start = now ? *now : time(NULL);
|
||||
tmp = localtime (&Start);
|
||||
yyYear = tmp->tm_year + TM_YEAR_ORIGIN;
|
||||
yyMonth = tmp->tm_mon + 1;
|
||||
@@ -923,11 +924,8 @@ time_t get_date (const char *p, const time_t *now)
|
||||
|
||||
#if defined (TEST)
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
main (ac, av)
|
||||
int ac;
|
||||
char *av[];
|
||||
main(void)
|
||||
{
|
||||
char buff[MAX_BUFF_LEN + 1];
|
||||
time_t d;
|
||||
@@ -938,7 +936,7 @@ main (ac, av)
|
||||
buff[MAX_BUFF_LEN] = 0;
|
||||
while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
|
||||
{
|
||||
d = get_date (buff, (time_t *) NULL);
|
||||
d = get_date(buff, NULL);
|
||||
if (d == -1)
|
||||
(void) printf ("Bad format - couldn't convert.\n");
|
||||
else
|
||||
|
||||
103
lib/getdef.c
103
lib/getdef.c
@@ -11,21 +11,29 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef USE_ECONF
|
||||
#include <libeconf.h>
|
||||
#endif
|
||||
|
||||
#include "alloc.h"
|
||||
#include "atoi/a2i/a2s.h"
|
||||
#include "atoi/a2i/a2u.h"
|
||||
#include "atoi/str2i/str2u.h"
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "prototypes.h"
|
||||
#include "shadowlog_internal.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strchr/stpspn.h"
|
||||
#include "string/strchr/strrspn.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strtok/stpsep.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -150,7 +158,6 @@ static struct itemdef def_table[] = {
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
#define NUMKNOWNDEFS (sizeof(knowndef_table)/sizeof(knowndef_table[0]))
|
||||
static struct itemdef knowndef_table[] = {
|
||||
#ifdef USE_PAM
|
||||
PAMDEFS
|
||||
@@ -176,7 +183,7 @@ static const char* def_fname = LOGINDEFS; /* login config defs file */
|
||||
static bool def_loaded = false; /* are defs already loaded? */
|
||||
|
||||
/* local function prototypes */
|
||||
static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *);
|
||||
static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *, const char *);
|
||||
static void def_load (void);
|
||||
|
||||
|
||||
@@ -195,7 +202,7 @@ static void def_load (void);
|
||||
def_load ();
|
||||
}
|
||||
|
||||
d = def_find (item);
|
||||
d = def_find (item, NULL);
|
||||
return (NULL == d) ? NULL : d->value;
|
||||
}
|
||||
|
||||
@@ -214,7 +221,7 @@ bool getdef_bool (const char *item)
|
||||
def_load ();
|
||||
}
|
||||
|
||||
d = def_find (item);
|
||||
d = def_find (item, NULL);
|
||||
if ((NULL == d) || (NULL == d->value)) {
|
||||
return false;
|
||||
}
|
||||
@@ -231,23 +238,22 @@ bool getdef_bool (const char *item)
|
||||
* values are handled.
|
||||
*/
|
||||
|
||||
int getdef_num (const char *item, int dflt)
|
||||
int
|
||||
getdef_num(const char *item, int dflt)
|
||||
{
|
||||
struct itemdef *d;
|
||||
long val;
|
||||
int val;
|
||||
struct itemdef *d;
|
||||
|
||||
if (!def_loaded) {
|
||||
def_load ();
|
||||
}
|
||||
|
||||
d = def_find (item);
|
||||
d = def_find (item, NULL);
|
||||
if ((NULL == d) || (NULL == d->value)) {
|
||||
return dflt;
|
||||
}
|
||||
|
||||
if ( (getlong(d->value, &val) == -1)
|
||||
|| (val > INT_MAX)
|
||||
|| (val < -1)) {
|
||||
if (a2si(&val, d->value, NULL, 0, -1, INT_MAX) == -1) {
|
||||
fprintf (shadow_logfd,
|
||||
_("configuration error - cannot parse %s value: '%s'"),
|
||||
item, d->value);
|
||||
@@ -266,23 +272,22 @@ int getdef_num (const char *item, int dflt)
|
||||
* values are handled.
|
||||
*/
|
||||
|
||||
unsigned int getdef_unum (const char *item, unsigned int dflt)
|
||||
unsigned int
|
||||
getdef_unum(const char *item, unsigned int dflt)
|
||||
{
|
||||
struct itemdef *d;
|
||||
long val;
|
||||
unsigned int val;
|
||||
struct itemdef *d;
|
||||
|
||||
if (!def_loaded) {
|
||||
def_load ();
|
||||
}
|
||||
|
||||
d = def_find (item);
|
||||
d = def_find (item, NULL);
|
||||
if ((NULL == d) || (NULL == d->value)) {
|
||||
return dflt;
|
||||
}
|
||||
|
||||
if ( (getlong(d->value, &val) == -1)
|
||||
|| (val < 0)
|
||||
|| (val > INT_MAX)) {
|
||||
if (a2ui(&val, d->value, NULL, 0, 0, UINT_MAX) == -1) {
|
||||
fprintf (shadow_logfd,
|
||||
_("configuration error - cannot parse %s value: '%s'"),
|
||||
item, d->value);
|
||||
@@ -310,12 +315,12 @@ long getdef_long (const char *item, long dflt)
|
||||
def_load ();
|
||||
}
|
||||
|
||||
d = def_find (item);
|
||||
d = def_find (item, NULL);
|
||||
if ((NULL == d) || (NULL == d->value)) {
|
||||
return dflt;
|
||||
}
|
||||
|
||||
if (getlong(d->value, &val) == -1 || val < -1) {
|
||||
if (a2sl(&val, d->value, NULL, 0, -1, LONG_MAX) == -1) {
|
||||
fprintf (shadow_logfd,
|
||||
_("configuration error - cannot parse %s value: '%s'"),
|
||||
item, d->value);
|
||||
@@ -342,12 +347,12 @@ unsigned long getdef_ulong (const char *item, unsigned long dflt)
|
||||
def_load ();
|
||||
}
|
||||
|
||||
d = def_find (item);
|
||||
d = def_find (item, NULL);
|
||||
if ((NULL == d) || (NULL == d->value)) {
|
||||
return dflt;
|
||||
}
|
||||
|
||||
if (getulong(d->value, &val) == -1) {
|
||||
if (str2ul(&val, d->value) == -1) {
|
||||
fprintf (shadow_logfd,
|
||||
_("configuration error - cannot parse %s value: '%s'"),
|
||||
item, d->value);
|
||||
@@ -375,12 +380,9 @@ int putdef_str (const char *name, const char *value, const char *srcfile)
|
||||
* Locate the slot to save the value. If this parameter
|
||||
* is unknown then "def_find" will print an err message.
|
||||
*/
|
||||
d = def_find (name);
|
||||
if (NULL == d) {
|
||||
if (NULL != srcfile)
|
||||
SYSLOG ((LOG_CRIT, "shadow: unknown configuration item '%s' in '%s'", name, srcfile));
|
||||
d = def_find (name, srcfile);
|
||||
if (NULL == d)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Save off the value.
|
||||
@@ -404,9 +406,12 @@ int putdef_str (const char *name, const char *value, const char *srcfile)
|
||||
*
|
||||
* Search through a table of configurable items to locate the
|
||||
* specified configuration option.
|
||||
*
|
||||
* If srcfile is not NULL, and the item is not found, then report an error saying
|
||||
* the unknown item was used in this file.
|
||||
*/
|
||||
|
||||
static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name)
|
||||
static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name, const char *srcfile)
|
||||
{
|
||||
struct itemdef *ptr;
|
||||
|
||||
@@ -415,7 +420,7 @@ static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name)
|
||||
*/
|
||||
|
||||
for (ptr = def_table; NULL != ptr->name; ptr++) {
|
||||
if (strcmp (ptr->name, name) == 0) {
|
||||
if (streq(ptr->name, name)) {
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
@@ -425,13 +430,15 @@ static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name)
|
||||
*/
|
||||
|
||||
for (ptr = knowndef_table; NULL != ptr->name; ptr++) {
|
||||
if (strcmp (ptr->name, name) == 0) {
|
||||
if (streq(ptr->name, name)) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
fprintf (shadow_logfd,
|
||||
_("configuration error - unknown item '%s' (notify administrator)\n"),
|
||||
name);
|
||||
if (srcfile != NULL)
|
||||
SYSLOG ((LOG_CRIT, "shadow: unknown configuration item '%s' in '%s'", name, srcfile));
|
||||
|
||||
out:
|
||||
return NULL;
|
||||
@@ -523,7 +530,6 @@ static void def_load (void)
|
||||
#else /* USE_ECONF */
|
||||
static void def_load (void)
|
||||
{
|
||||
int i;
|
||||
FILE *fp;
|
||||
char buf[1024], *name, *value, *s;
|
||||
|
||||
@@ -555,28 +561,21 @@ static void def_load (void)
|
||||
/*
|
||||
* Trim trailing whitespace.
|
||||
*/
|
||||
for (i = (ptrdiff_t) strlen (buf) - 1; i >= 0; --i) {
|
||||
if (!isspace (buf[i])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
buf[i] = '\0';
|
||||
stpcpy(strrspn(buf, " \t\n"), "");
|
||||
|
||||
/*
|
||||
* Break the line into two fields.
|
||||
*/
|
||||
name = buf + strspn (buf, " \t"); /* first nonwhite */
|
||||
if (*name == '\0' || *name == '#')
|
||||
name = stpspn(buf, " \t"); /* first nonwhite */
|
||||
if (streq(name, "") || *name == '#')
|
||||
continue; /* comment or empty */
|
||||
|
||||
s = name + strcspn (name, " \t"); /* end of field */
|
||||
if (*s == '\0')
|
||||
s = stpsep(name, " \t"); /* next field */
|
||||
if (s == NULL)
|
||||
continue; /* only 1 field?? */
|
||||
|
||||
*s++ = '\0';
|
||||
value = s + strspn (s, " \"\t"); /* next nonwhite */
|
||||
*(value + strcspn (value, "\"")) = '\0';
|
||||
value = stpspn(s, " \"\t"); /* next nonwhite */
|
||||
stpsep(value, "\"");
|
||||
|
||||
/*
|
||||
* Store the value in def_table.
|
||||
@@ -610,7 +609,7 @@ int main (int argc, char **argv)
|
||||
def_load ();
|
||||
|
||||
for (i = 0; i < NUMDEFS; ++i) {
|
||||
d = def_find (def_table[i].name);
|
||||
d = def_find (def_table[i].name, NULL);
|
||||
if (NULL == d) {
|
||||
printf ("error - lookup '%s' failed\n",
|
||||
def_table[i].name);
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 1991 - 1994, Julianne Frances Haugh
|
||||
* SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz
|
||||
* SPDX-FileCopyrightText: 2000 - 2006, Tomasz Kłoczko
|
||||
* SPDX-FileCopyrightText: 2007 - 2009, Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 1991-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-2000, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2000-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -14,30 +13,27 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <grp.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "atoi/getnum.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
|
||||
/*
|
||||
* getgr_nam_gid - Return a pointer to the group specified by a string.
|
||||
* The string may be a valid GID or a valid groupname.
|
||||
* If the group does not exist on the system, NULL is returned.
|
||||
*/
|
||||
extern /*@only@*//*@null@*/struct group *getgr_nam_gid (/*@null@*/const char *grname)
|
||||
extern /*@only@*//*@null@*/struct group *
|
||||
getgr_nam_gid(/*@null@*/const char *grname)
|
||||
{
|
||||
long long gid;
|
||||
char *endptr;
|
||||
gid_t gid;
|
||||
|
||||
if (NULL == grname) {
|
||||
if (NULL == grname)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
gid = strtoll(grname, &endptr, 10);
|
||||
if ( ('\0' != *grname)
|
||||
&& ('\0' == *endptr)
|
||||
&& (0 == errno)
|
||||
&& (/*@+longintegral@*/gid == (gid_t)gid)/*@=longintegral@*/) {
|
||||
return xgetgrgid (gid);
|
||||
}
|
||||
return xgetgrnam (grname);
|
||||
if (get_gid(grname, &gid) == 0)
|
||||
return xgetgrgid(gid);
|
||||
return xgetgrnam(grname);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2007 - 2009, Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "prototypes.h"
|
||||
|
||||
|
||||
/*
|
||||
* getlong - extract a long integer provided by the numstr string in *result
|
||||
*
|
||||
* It supports decimal, hexadecimal or octal representations.
|
||||
*/
|
||||
int
|
||||
getlong(const char *restrict numstr, long *restrict result)
|
||||
{
|
||||
char *endptr;
|
||||
long val;
|
||||
|
||||
errno = 0;
|
||||
val = strtol(numstr, &endptr, 0);
|
||||
if (('\0' == *numstr) || ('\0' != *endptr) || (0 != errno))
|
||||
return -1;
|
||||
|
||||
*result = val;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 2008, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
@@ -12,9 +10,10 @@
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "atoi/strtou_noneg.h"
|
||||
#include "atoi/a2i/a2u.h"
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -30,65 +29,44 @@ getrange(const char *range,
|
||||
unsigned long *min, bool *has_min,
|
||||
unsigned long *max, bool *has_max)
|
||||
{
|
||||
char *endptr;
|
||||
unsigned long n;
|
||||
const char *end;
|
||||
|
||||
if (NULL == range)
|
||||
return -1;
|
||||
|
||||
*min = 0;
|
||||
*has_min = false;
|
||||
*has_max = false;
|
||||
|
||||
if ('-' == range[0]) {
|
||||
if (!isdigit(range[1]))
|
||||
return -1;
|
||||
|
||||
errno = 0;
|
||||
n = strtoul_noneg(&range[1], &endptr, 10);
|
||||
if (('\0' != *endptr) || (0 != errno))
|
||||
return -1;
|
||||
|
||||
/* -<long> */
|
||||
*has_min = false;
|
||||
*has_max = true;
|
||||
*max = n;
|
||||
} else {
|
||||
errno = 0;
|
||||
n = strtoul_noneg(range, &endptr, 10);
|
||||
if (endptr == range || 0 != errno)
|
||||
return -1;
|
||||
|
||||
switch (*endptr) {
|
||||
case '\0':
|
||||
/* <long> */
|
||||
*has_min = true;
|
||||
*has_max = true;
|
||||
*min = n;
|
||||
*max = n;
|
||||
break;
|
||||
case '-':
|
||||
endptr++;
|
||||
if ('\0' == *endptr) {
|
||||
/* <long>- */
|
||||
*has_min = true;
|
||||
*has_max = false;
|
||||
*min = n;
|
||||
} else if (!isdigit (*endptr)) {
|
||||
return -1;
|
||||
} else {
|
||||
*has_min = true;
|
||||
*min = n;
|
||||
errno = 0;
|
||||
n = strtoul_noneg(endptr, &endptr, 10);
|
||||
if ('\0' != *endptr || 0 != errno)
|
||||
return -1;
|
||||
|
||||
/* <long>-<long> */
|
||||
*has_max = true;
|
||||
*max = n;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
end = range + 1;
|
||||
goto parse_max;
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (a2ul(min, range, &end, 10, 0, ULONG_MAX) == -1 && errno != ENOTSUP)
|
||||
return -1;
|
||||
*has_min = true;
|
||||
|
||||
switch (*end++) {
|
||||
case '\0':
|
||||
*has_max = true;
|
||||
*max = *min;
|
||||
return 0; /* <long> */
|
||||
|
||||
case '-':
|
||||
if (streq(end, ""))
|
||||
return 0; /* <long>- */
|
||||
parse_max:
|
||||
if (!isdigit((unsigned char) *end))
|
||||
return -1;
|
||||
|
||||
if (a2ul(max, end, NULL, 10, *min, ULONG_MAX) == -1)
|
||||
return -1;
|
||||
*has_max = true;
|
||||
|
||||
return 0; /* <long>-<long>, or -<long> */
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017, Chris Lamb
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 2017, Chris Lamb
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -12,11 +11,12 @@
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "atoi/strtou_noneg.h"
|
||||
#include "atoi/a2i/a2i.h"
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "shadowlog.h"
|
||||
|
||||
|
||||
/*
|
||||
* gettime() returns the time as the number of seconds since the Epoch
|
||||
*
|
||||
@@ -24,13 +24,12 @@
|
||||
* Epoch, 1970-01-01 00:00:00 +0000 (UTC), except that if the SOURCE_DATE_EPOCH
|
||||
* environment variable is exported it will use that instead.
|
||||
*/
|
||||
/*@observer@*/time_t gettime (void)
|
||||
/*@observer@*/time_t
|
||||
gettime(void)
|
||||
{
|
||||
char *endptr;
|
||||
char *source_date_epoch;
|
||||
time_t fallback;
|
||||
unsigned long long epoch;
|
||||
FILE *shadow_logfd = log_get_logfd();
|
||||
char *source_date_epoch;
|
||||
FILE *shadow_logfd = log_get_logfd();
|
||||
time_t fallback, epoch;
|
||||
|
||||
fallback = time (NULL);
|
||||
source_date_epoch = shadow_getenv ("SOURCE_DATE_EPOCH");
|
||||
@@ -38,32 +37,11 @@
|
||||
if (!source_date_epoch)
|
||||
return fallback;
|
||||
|
||||
errno = 0;
|
||||
epoch = strtoull_noneg(source_date_epoch, &endptr, 10);
|
||||
if (errno != 0) {
|
||||
fprintf (shadow_logfd,
|
||||
_("Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n"),
|
||||
strerror(errno));
|
||||
} else if (endptr == source_date_epoch) {
|
||||
fprintf (shadow_logfd,
|
||||
_("Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n"),
|
||||
endptr);
|
||||
} else if (*endptr != '\0') {
|
||||
fprintf (shadow_logfd,
|
||||
_("Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n"),
|
||||
endptr);
|
||||
} else if (epoch > ULONG_MAX) {
|
||||
fprintf (shadow_logfd,
|
||||
_("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to %lu but was found to be: %llu\n"),
|
||||
ULONG_MAX, epoch);
|
||||
} else if ((time_t)epoch > fallback) {
|
||||
fprintf (shadow_logfd,
|
||||
_("Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to the current time (%lu) but was found to be: %llu\n"),
|
||||
fallback, epoch);
|
||||
} else {
|
||||
/* Valid */
|
||||
return epoch;
|
||||
if (a2i(time_t, &epoch, source_date_epoch, NULL, 10, 0, fallback) == -1) {
|
||||
fprintf(shadow_logfd,
|
||||
_("Environment variable $SOURCE_DATE_EPOCH: a2i(\"%s\"): %s"),
|
||||
source_date_epoch, strerror(errno));
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return fallback;
|
||||
return epoch;
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2007 - 2009, Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id: getlong.c 2763 2009-04-23 09:57:03Z nekral-guest $"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "atoi/strtou_noneg.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
|
||||
/*
|
||||
* getulong - extract an unsigned long integer provided by the numstr string in *result
|
||||
*
|
||||
* It supports decimal, hexadecimal or octal representations.
|
||||
*/
|
||||
int
|
||||
getulong(const char *restrict numstr, unsigned long *restrict result)
|
||||
{
|
||||
char *endptr;
|
||||
unsigned long val;
|
||||
|
||||
errno = 0;
|
||||
val = strtoul_noneg(numstr, &endptr, 0);
|
||||
if (('\0' == *numstr) || ('\0' != *endptr) || (0 != errno))
|
||||
return -1;
|
||||
|
||||
*result = val;
|
||||
return 0;
|
||||
}
|
||||
@@ -15,12 +15,14 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "alloc/calloc.h"
|
||||
#include "alloc/malloc.h"
|
||||
#include "commonio.h"
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "groupio.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
static /*@null@*/struct commonio_entry *merge_group_entries (
|
||||
@@ -262,8 +264,8 @@ static int group_open_hook (void)
|
||||
struct group *g2 = gr2->eptr;
|
||||
if (NULL != g1 &&
|
||||
NULL != g2 &&
|
||||
0 == strcmp (g1->gr_name, g2->gr_name) &&
|
||||
0 == strcmp (g1->gr_passwd, g2->gr_passwd) &&
|
||||
streq(g1->gr_name, g2->gr_name) &&
|
||||
streq(g1->gr_passwd, g2->gr_passwd) &&
|
||||
g1->gr_gid == g2->gr_gid) {
|
||||
/* Both group entries refer to the same
|
||||
* group. It is a split group. Merge the
|
||||
@@ -331,7 +333,7 @@ static /*@null@*/struct commonio_entry *merge_group_entries (
|
||||
for (i=0; NULL != gptr2->gr_mem[i]; i++) {
|
||||
char **pmember = gptr1->gr_mem;
|
||||
while (NULL != *pmember) {
|
||||
if (0 == strcmp(*pmember, gptr2->gr_mem[i])) {
|
||||
if (streq(*pmember, gptr2->gr_mem[i])) {
|
||||
break;
|
||||
}
|
||||
pmember++;
|
||||
@@ -354,7 +356,7 @@ static /*@null@*/struct commonio_entry *merge_group_entries (
|
||||
for (i=0; NULL != gptr2->gr_mem[i]; i++) {
|
||||
char **pmember = new_members;
|
||||
while (NULL != *pmember) {
|
||||
if (0 == strcmp(*pmember, gptr2->gr_mem[i])) {
|
||||
if (streq(*pmember, gptr2->gr_mem[i])) {
|
||||
break;
|
||||
}
|
||||
pmember++;
|
||||
|
||||
@@ -12,11 +12,13 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "alloc.h"
|
||||
#include "memzero.h"
|
||||
#include "alloc/calloc.h"
|
||||
#include "alloc/malloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "groupio.h"
|
||||
#include "string/memset/memzero.h"
|
||||
|
||||
|
||||
/*@null@*/ /*@only@*/struct group *__gr_dup (const struct group *grent)
|
||||
{
|
||||
@@ -81,10 +83,9 @@ void
|
||||
gr_free(/*@only@*/struct group *grent)
|
||||
{
|
||||
free (grent->gr_name);
|
||||
if (NULL != grent->gr_passwd) {
|
||||
strzero (grent->gr_passwd);
|
||||
free (grent->gr_passwd);
|
||||
}
|
||||
if (NULL != grent->gr_passwd)
|
||||
free(strzero(grent->gr_passwd));
|
||||
|
||||
gr_free_members(grent);
|
||||
free (grent);
|
||||
}
|
||||
|
||||
358
lib/gshadow.c
358
lib/gshadow.c
@@ -14,85 +14,44 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "alloc/malloc.h"
|
||||
#include "alloc/realloc.h"
|
||||
#include "alloc/x/xmalloc.h"
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strchr/strchrcnt.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strtok/stpsep.h"
|
||||
|
||||
|
||||
static /*@null@*/FILE *shadow;
|
||||
static /*@null@*//*@only@*/char **members = NULL;
|
||||
static size_t nmembers = 0;
|
||||
static /*@null@*//*@only@*/char **admins = NULL;
|
||||
static size_t nadmins = 0;
|
||||
static struct sgrp sgroup;
|
||||
static struct sgrp sgroup = {};
|
||||
|
||||
#define FIELDS 4
|
||||
|
||||
#ifdef USE_NIS
|
||||
static bool nis_used;
|
||||
static bool nis_ignore;
|
||||
static enum { native, start, middle, native2 } nis_state;
|
||||
static bool nis_bound;
|
||||
static char *nis_domain;
|
||||
static char *nis_key;
|
||||
static int nis_keylen;
|
||||
static char *nis_val;
|
||||
static int nis_vallen;
|
||||
|
||||
#define IS_NISCHAR(c) ((c)=='+')
|
||||
#endif
|
||||
|
||||
#ifdef USE_NIS
|
||||
/*
|
||||
* bind_nis - bind to NIS server
|
||||
*/
|
||||
|
||||
static int bind_nis (void)
|
||||
static /*@null@*/char **
|
||||
build_list(char *s)
|
||||
{
|
||||
if (yp_get_default_domain (&nis_domain))
|
||||
return -1;
|
||||
char **l;
|
||||
size_t i;
|
||||
|
||||
nis_bound = true;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
l = XMALLOC(strchrcnt(s, ',') + 2, char *);
|
||||
|
||||
static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist)
|
||||
{
|
||||
char **ptr = *list;
|
||||
size_t nelem = *nlist, size;
|
||||
for (i = 0; s != NULL && !streq(s, ""); i++)
|
||||
l[i] = strsep(&s, ",");
|
||||
|
||||
while (s != NULL && *s != '\0') {
|
||||
size = (nelem + 1) * sizeof (ptr);
|
||||
ptr = REALLOC(*list, size, char *);
|
||||
if (NULL != ptr) {
|
||||
ptr[nelem] = s;
|
||||
nelem++;
|
||||
*list = ptr;
|
||||
*nlist = nelem;
|
||||
s = strchr (s, ',');
|
||||
if (NULL != s) {
|
||||
*s = '\0';
|
||||
s++;
|
||||
}
|
||||
}
|
||||
}
|
||||
size = (nelem + 1) * sizeof (ptr);
|
||||
ptr = REALLOC(*list, size, char *);
|
||||
if (NULL != ptr) {
|
||||
ptr[nelem] = NULL;
|
||||
*list = ptr;
|
||||
}
|
||||
return ptr;
|
||||
l[i] = NULL;
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
void setsgent (void)
|
||||
{
|
||||
#ifdef USE_NIS
|
||||
nis_state = native;
|
||||
#endif
|
||||
if (NULL != shadow) {
|
||||
rewind (shadow);
|
||||
} else {
|
||||
@@ -109,7 +68,8 @@ void endsgent (void)
|
||||
shadow = NULL;
|
||||
}
|
||||
|
||||
/*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *string)
|
||||
/*@observer@*//*@null@*/struct sgrp *
|
||||
sgetsgent(const char *string)
|
||||
{
|
||||
static char *sgrbuf = NULL;
|
||||
static size_t sgrbuflen = 0;
|
||||
@@ -121,64 +81,40 @@ void endsgent (void)
|
||||
|
||||
if (len > sgrbuflen) {
|
||||
char *buf = REALLOC(sgrbuf, len, char);
|
||||
if (NULL == buf) {
|
||||
if (NULL == buf)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sgrbuf = buf;
|
||||
sgrbuflen = len;
|
||||
}
|
||||
|
||||
strcpy (sgrbuf, string);
|
||||
|
||||
cp = strrchr (sgrbuf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
stpsep(sgrbuf, "\n");
|
||||
|
||||
/*
|
||||
* There should be exactly 4 colon separated fields. Find
|
||||
* all 4 of them and save the starting addresses in fields[].
|
||||
*/
|
||||
|
||||
for (cp = sgrbuf, i = 0; (i < FIELDS) && (NULL != cp); i++) {
|
||||
fields[i] = cp;
|
||||
cp = strchr (cp, ':');
|
||||
if (NULL != cp) {
|
||||
*cp++ = '\0';
|
||||
}
|
||||
}
|
||||
for (cp = sgrbuf, i = 0; (i < FIELDS) && (NULL != cp); i++)
|
||||
fields[i] = strsep(&cp, ":");
|
||||
|
||||
/*
|
||||
* If there was an extra field somehow, or perhaps not enough,
|
||||
* the line is invalid.
|
||||
*/
|
||||
|
||||
if ((NULL != cp) || (i != FIELDS)) {
|
||||
#ifdef USE_NIS
|
||||
if (!IS_NISCHAR (fields[0][0])) {
|
||||
return 0;
|
||||
} else {
|
||||
nis_used = true;
|
||||
}
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
if (NULL != cp || i != FIELDS)
|
||||
return NULL;
|
||||
|
||||
sgroup.sg_name = fields[0];
|
||||
sgroup.sg_passwd = fields[1];
|
||||
if (0 != nadmins) {
|
||||
nadmins = 0;
|
||||
free (admins);
|
||||
admins = NULL;
|
||||
}
|
||||
if (0 != nmembers) {
|
||||
nmembers = 0;
|
||||
free (members);
|
||||
members = NULL;
|
||||
}
|
||||
sgroup.sg_adm = build_list (fields[2], &admins, &nadmins);
|
||||
sgroup.sg_mem = build_list (fields[3], &members, &nmembers);
|
||||
|
||||
free(sgroup.sg_adm);
|
||||
free(sgroup.sg_mem);
|
||||
|
||||
sgroup.sg_adm = build_list(fields[2]);
|
||||
sgroup.sg_mem = build_list(fields[3]);
|
||||
|
||||
return &sgroup;
|
||||
}
|
||||
@@ -209,42 +145,29 @@ void endsgent (void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef USE_NIS
|
||||
while (fgetsx (buf, buflen, fp) == buf)
|
||||
#else
|
||||
if (fgetsx (buf, buflen, fp) == buf)
|
||||
#endif
|
||||
{
|
||||
while ( ((cp = strrchr (buf, '\n')) == NULL)
|
||||
&& (feof (fp) == 0)) {
|
||||
size_t len;
|
||||
if (fgetsx(buf, buflen, fp) == NULL)
|
||||
return NULL;
|
||||
|
||||
cp = REALLOC(buf, buflen * 2, char);
|
||||
if (NULL == cp) {
|
||||
return NULL;
|
||||
}
|
||||
buf = cp;
|
||||
buflen *= 2;
|
||||
while ( (strrchr(buf, '\n') == NULL)
|
||||
&& (feof (fp) == 0)) {
|
||||
size_t len;
|
||||
|
||||
len = strlen (buf);
|
||||
if (fgetsx (&buf[len],
|
||||
(int) (buflen - len),
|
||||
fp) != &buf[len]) {
|
||||
return NULL;
|
||||
}
|
||||
cp = REALLOC(buf, buflen * 2, char);
|
||||
if (NULL == cp) {
|
||||
return NULL;
|
||||
}
|
||||
cp = strrchr (buf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
buf = cp;
|
||||
buflen *= 2;
|
||||
|
||||
len = strlen (buf);
|
||||
if (fgetsx (&buf[len],
|
||||
(int) (buflen - len),
|
||||
fp) != &buf[len]) {
|
||||
return NULL;
|
||||
}
|
||||
#ifdef USE_NIS
|
||||
if (nis_ignore && IS_NISCHAR (buf[0])) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
return (sgetsgent (buf));
|
||||
}
|
||||
return NULL;
|
||||
stpsep(buf, "\n");
|
||||
return (sgetsgent (buf));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -253,96 +176,10 @@ void endsgent (void)
|
||||
|
||||
/*@observer@*//*@null@*/struct sgrp *getsgent (void)
|
||||
{
|
||||
#ifdef USE_NIS
|
||||
bool nis_1_group = false;
|
||||
struct sgrp *val;
|
||||
#endif
|
||||
if (NULL == shadow) {
|
||||
setsgent ();
|
||||
}
|
||||
|
||||
#ifdef USE_NIS
|
||||
again:
|
||||
/*
|
||||
* See if we are reading from the local file.
|
||||
*/
|
||||
|
||||
if (nis_state == native || nis_state == native2) {
|
||||
|
||||
/*
|
||||
* Get the next entry from the shadow group file. Return
|
||||
* NULL right away if there is none.
|
||||
*/
|
||||
|
||||
val = fgetsgent (shadow);
|
||||
if (NULL == val) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* If this entry began with a NIS escape character, we have
|
||||
* to see if this is just a single group, or if the entire
|
||||
* map is being asked for.
|
||||
*/
|
||||
|
||||
if (IS_NISCHAR (val->sg_name[0])) {
|
||||
if ('\0' != val->sg_name[1]) {
|
||||
nis_1_group = true;
|
||||
} else {
|
||||
nis_state = start;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If this isn't a NIS group and this isn't an escape to go
|
||||
* use a NIS map, it must be a regular local group.
|
||||
*/
|
||||
|
||||
if (!nis_1_group && (nis_state != start)) {
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* If this is an escape to use an NIS map, switch over to
|
||||
* that bunch of code.
|
||||
*/
|
||||
|
||||
if (nis_state == start) {
|
||||
goto again;
|
||||
}
|
||||
|
||||
/*
|
||||
* NEEDSWORK. Here we substitute pieces-parts of this entry.
|
||||
*/
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
if (!nis_bound) {
|
||||
if (bind_nis ()) {
|
||||
nis_state = native2;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
if (nis_state == start) {
|
||||
if (yp_first (nis_domain, "gshadow.byname", &nis_key,
|
||||
&nis_keylen, &nis_val, &nis_vallen)) {
|
||||
nis_state = native2;
|
||||
goto again;
|
||||
}
|
||||
nis_state = middle;
|
||||
} else if (nis_state == middle) {
|
||||
if (yp_next (nis_domain, "gshadow.byname", nis_key,
|
||||
nis_keylen, &nis_key, &nis_keylen,
|
||||
&nis_val, &nis_vallen)) {
|
||||
nis_state = native2;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
return sgetsgent (nis_val);
|
||||
}
|
||||
#else
|
||||
return (fgetsgent (shadow));
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -353,63 +190,13 @@ void endsgent (void)
|
||||
{
|
||||
struct sgrp *sgrp;
|
||||
|
||||
#ifdef USE_NIS
|
||||
static char save_name[16];
|
||||
int nis_disabled = 0;
|
||||
#endif
|
||||
|
||||
setsgent ();
|
||||
|
||||
#ifdef USE_NIS
|
||||
if (nis_used) {
|
||||
again:
|
||||
|
||||
/*
|
||||
* Search the gshadow.byname map for this group.
|
||||
*/
|
||||
|
||||
if (!nis_bound) {
|
||||
bind_nis ();
|
||||
}
|
||||
|
||||
if (nis_bound) {
|
||||
char *cp;
|
||||
|
||||
if (yp_match (nis_domain, "gshadow.byname", name,
|
||||
strlen (name), &nis_val,
|
||||
&nis_vallen) == 0) {
|
||||
cp = strchr (nis_val, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
|
||||
nis_state = middle;
|
||||
sgrp = sgetsgent (nis_val);
|
||||
if (NULL != sgrp) {
|
||||
strcpy (save_name, sgrp->sg_name);
|
||||
nis_key = save_name;
|
||||
nis_keylen = strlen (save_name);
|
||||
}
|
||||
return sgrp;
|
||||
}
|
||||
}
|
||||
nis_state = native2;
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_NIS
|
||||
if (nis_used) {
|
||||
nis_ignore = true;
|
||||
nis_disabled = true;
|
||||
}
|
||||
#endif
|
||||
while ((sgrp = getsgent ()) != NULL) {
|
||||
if (strcmp (name, sgrp->sg_name) == 0) {
|
||||
if (streq(name, sgrp->sg_name)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#ifdef USE_NIS
|
||||
nis_ignore = false;
|
||||
#endif
|
||||
return sgrp;
|
||||
}
|
||||
|
||||
@@ -449,53 +236,36 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
|
||||
/*
|
||||
* Copy the group name and passwd.
|
||||
*/
|
||||
|
||||
strcpy (cp, sgrp->sg_name);
|
||||
cp += strlen (cp);
|
||||
*cp++ = ':';
|
||||
|
||||
strcpy (cp, sgrp->sg_passwd);
|
||||
cp += strlen (cp);
|
||||
*cp++ = ':';
|
||||
cp = stpcpy(stpcpy(cp, sgrp->sg_name), ":");
|
||||
cp = stpcpy(stpcpy(cp, sgrp->sg_passwd), ":");
|
||||
|
||||
/*
|
||||
* Copy the administrators, separating each from the other
|
||||
* with a ",".
|
||||
*/
|
||||
|
||||
for (i = 0; NULL != sgrp->sg_adm[i]; i++) {
|
||||
if (i > 0) {
|
||||
*cp++ = ',';
|
||||
}
|
||||
if (i > 0)
|
||||
cp = stpcpy(cp, ",");
|
||||
|
||||
strcpy (cp, sgrp->sg_adm[i]);
|
||||
cp += strlen (cp);
|
||||
cp = stpcpy(cp, sgrp->sg_adm[i]);
|
||||
}
|
||||
*cp = ':';
|
||||
cp++;
|
||||
cp = stpcpy(cp, ":");
|
||||
|
||||
/*
|
||||
* Now do likewise with the group members.
|
||||
*/
|
||||
|
||||
for (i = 0; NULL != sgrp->sg_mem[i]; i++) {
|
||||
if (i > 0) {
|
||||
*cp = ',';
|
||||
cp++;
|
||||
}
|
||||
if (i > 0)
|
||||
cp = stpcpy(cp, ",");
|
||||
|
||||
strcpy (cp, sgrp->sg_mem[i]);
|
||||
cp += strlen (cp);
|
||||
cp = stpcpy(cp, sgrp->sg_mem[i]);
|
||||
}
|
||||
*cp = '\n';
|
||||
cp++;
|
||||
*cp = '\0';
|
||||
stpcpy(cp, "\n");
|
||||
|
||||
/*
|
||||
* Output using the function which understands the line
|
||||
* continuation conventions.
|
||||
*/
|
||||
|
||||
if (fputsx (buf, fp) == EOF) {
|
||||
free (buf);
|
||||
return -1;
|
||||
|
||||
@@ -30,7 +30,6 @@ struct sgrp {
|
||||
|
||||
#include <stdio.h> /* for FILE */
|
||||
|
||||
#if __STDC__
|
||||
/*@observer@*//*@null@*/struct sgrp *getsgent (void);
|
||||
/*@observer@*//*@null@*/struct sgrp *getsgnam (const char *);
|
||||
/*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *);
|
||||
@@ -38,15 +37,6 @@ struct sgrp {
|
||||
void setsgent (void);
|
||||
void endsgent (void);
|
||||
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"
|
||||
#endif /* ifndef _H_GSHADOW */
|
||||
|
||||
18
lib/hushed.c
18
lib/hushed.c
@@ -12,13 +12,17 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "getdef.h"
|
||||
#include "string/sprintf.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strtok/stpsep.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -70,9 +74,9 @@ bool hushed (const char *username)
|
||||
return false;
|
||||
}
|
||||
for (found = false; !found && (fgets (buf, sizeof buf, fp) == buf);) {
|
||||
buf[strcspn (buf, "\n")] = '\0';
|
||||
found = (strcmp (buf, pw->pw_shell) == 0) ||
|
||||
(strcmp (buf, pw->pw_name) == 0);
|
||||
stpsep(buf, "\n");
|
||||
found = streq(buf, pw->pw_shell) ||
|
||||
streq(buf, pw->pw_name);
|
||||
}
|
||||
(void) fclose (fp);
|
||||
return found;
|
||||
|
||||
@@ -12,85 +12,65 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/stpeprintf.h"
|
||||
#include "idmapping.h"
|
||||
#if HAVE_SYS_CAPABILITY_H
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/capability.h>
|
||||
#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 "sizeof.h"
|
||||
#include "string/sprintf/stpeprintf.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
struct map_range *get_map_ranges(int ranges, int argc, char **argv)
|
||||
|
||||
struct map_range *
|
||||
get_map_ranges(int ranges, int argc, char **argv)
|
||||
{
|
||||
struct map_range *mappings, *mapping;
|
||||
int idx, argidx;
|
||||
struct map_range *mappings, *m;
|
||||
|
||||
if (ranges < 0 || argc < 0) {
|
||||
fprintf(log_get_logfd(), "%s: error calculating number of arguments\n", log_get_progname());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ranges != ((argc + 2) / 3)) {
|
||||
if (ranges * 3 != argc) {
|
||||
fprintf(log_get_logfd(), "%s: ranges: %u is wrong for argc: %d\n", log_get_progname(), ranges, argc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((ranges * 3) > argc) {
|
||||
fprintf(log_get_logfd(), "ranges: %u argc: %d\n",
|
||||
ranges, argc);
|
||||
fprintf(log_get_logfd(),
|
||||
_( "%s: Not enough arguments to form %u mappings\n"),
|
||||
log_get_progname(), ranges);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mappings = CALLOC(ranges, struct map_range);
|
||||
if (!mappings) {
|
||||
fprintf(log_get_logfd(), _( "%s: Memory allocation failure\n"),
|
||||
log_get_progname());
|
||||
exit(EXIT_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Gather up the ranges from the command line */
|
||||
mapping = mappings;
|
||||
for (idx = 0, argidx = 0; idx < ranges; idx++, argidx += 3, mapping++) {
|
||||
if (getulong(argv[argidx + 0], &mapping->upper) == -1) {
|
||||
m = mappings;
|
||||
for (int i = 0; i < ranges * 3; i+=3, m++) {
|
||||
if (a2ul(&m->upper, argv[i + 0], NULL, 0, 0, UINT_MAX - 1) == -1) {
|
||||
if (errno == ERANGE)
|
||||
fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
|
||||
free(mappings);
|
||||
return NULL;
|
||||
}
|
||||
if (getulong(argv[argidx + 1], &mapping->lower) == -1) {
|
||||
if (a2ul(&m->lower, argv[i + 1], NULL, 0, 0, UINT_MAX - 1) == -1) {
|
||||
if (errno == ERANGE)
|
||||
fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
|
||||
free(mappings);
|
||||
return NULL;
|
||||
}
|
||||
if (getulong(argv[argidx + 2], &mapping->count) == -1) {
|
||||
if (a2ul(&m->count, argv[i + 2], NULL, 0, 1, UINT_MAX - MAX(m->lower, m->upper)) == -1) {
|
||||
if (errno == ERANGE)
|
||||
fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
|
||||
free(mappings);
|
||||
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;
|
||||
}
|
||||
@@ -154,9 +134,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_data_struct data[2] = {{0}};
|
||||
|
||||
if (strcmp(map_file, "uid_map") == 0) {
|
||||
if (streq(map_file, "uid_map")) {
|
||||
cap = CAP_SETUID;
|
||||
} else if (strcmp(map_file, "gid_map") == 0) {
|
||||
} else if (streq(map_file, "gid_map")) {
|
||||
cap = CAP_SETGID;
|
||||
} else {
|
||||
fprintf(log_get_logfd(), _("%s: Invalid map file %s specified\n"), log_get_progname(), map_file);
|
||||
@@ -165,7 +145,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. */
|
||||
if (geteuid() == 0 && geteuid() != ruid) {
|
||||
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0) {
|
||||
if (prctl(PR_SET_KEEPCAPS, 1L) == -1) {
|
||||
fprintf(log_get_logfd(), _("%s: Could not prctl(PR_SET_KEEPCAPS)\n"), log_get_progname());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user