Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d63956d640 | ||
|
|
d5ecf56f23 | ||
|
|
514beca807 | ||
|
|
610b079510 | ||
|
|
118f9b53e3 | ||
|
|
babbfd2ffb | ||
|
|
d5616f4c4e | ||
|
|
79ce7adda3 | ||
|
|
7d974e3e9b | ||
|
|
c53b76cc49 | ||
|
|
ec00428f90 |
11
Makefile.am
11
Makefile.am
@@ -15,4 +15,15 @@ SUBDIRS += man
|
||||
endif
|
||||
|
||||
CLEANFILES = man/8.out man/po/remove-potcdate.* man/*/login.defs.d man/*/*.mo
|
||||
|
||||
EXTRA_DIST = 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
|
||||
|
||||
@@ -4,9 +4,9 @@ m4_define([libsubid_abi_major], 4)
|
||||
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.1], [pkg-shadow-devel@lists.alioth.debian.org], [],
|
||||
AC_INIT([shadow], [4.15.3], [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])
|
||||
|
||||
12
lib/csrand.c
12
lib/csrand.c
@@ -23,6 +23,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);
|
||||
|
||||
@@ -97,6 +98,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 +117,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
|
||||
|
||||
@@ -274,40 +274,8 @@ static const struct subordinate_range *find_range(struct commonio_db *db,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* have_range: check whether @owner is authorized to use the range
|
||||
* (@start .. @start+@count-1).
|
||||
* @db: database to check
|
||||
* @owner: owning uid being queried
|
||||
* @start: start of range
|
||||
* @count: number of uids in range
|
||||
*
|
||||
* Returns true if @owner is authorized to use the range, false otherwise.
|
||||
*/
|
||||
static bool have_range(struct commonio_db *db,
|
||||
const char *owner, unsigned long start, unsigned long count)
|
||||
{
|
||||
const struct subordinate_range *range;
|
||||
unsigned long end;
|
||||
|
||||
if (count == 0)
|
||||
return false;
|
||||
|
||||
end = start + count - 1;
|
||||
range = find_range (db, owner, start);
|
||||
while (range) {
|
||||
unsigned long last;
|
||||
|
||||
last = range->start + range->count - 1;
|
||||
if (last >= (start + count - 1))
|
||||
return true;
|
||||
|
||||
count = end - last;
|
||||
start = last + 1;
|
||||
range = find_range(db, owner, start);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const char *owner, unsigned long start, unsigned long count);
|
||||
|
||||
static bool append_range(struct subid_range **ranges, const struct subordinate_range *new, int n)
|
||||
{
|
||||
@@ -574,6 +542,64 @@ static struct commonio_db subordinate_uid_db = {
|
||||
false /* setname */
|
||||
};
|
||||
|
||||
/*
|
||||
* have_range: check whether @owner is authorized to use the range
|
||||
* (@start .. @start+@count-1).
|
||||
* @db: database to check
|
||||
* @owner: owning uid being queried
|
||||
* @start: start of range
|
||||
* @count: number of uids in range
|
||||
*
|
||||
* Returns true if @owner is authorized to use the range, false otherwise.
|
||||
*/
|
||||
static bool have_range(struct commonio_db *db,
|
||||
const char *owner, unsigned long start, unsigned long count)
|
||||
{
|
||||
const struct subordinate_range *range;
|
||||
unsigned long end;
|
||||
bool doclose = false;
|
||||
bool ret = false;
|
||||
int rc;
|
||||
|
||||
if (count == 0)
|
||||
return false;
|
||||
|
||||
if (!db->isopen) {
|
||||
doclose = true;
|
||||
if (db == &subordinate_uid_db)
|
||||
rc = sub_uid_open(O_RDONLY);
|
||||
else
|
||||
rc = sub_gid_open(O_RDONLY);
|
||||
if (rc < 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
end = start + count - 1;
|
||||
range = find_range (db, owner, start);
|
||||
while (range) {
|
||||
unsigned long last;
|
||||
|
||||
last = range->start + range->count - 1;
|
||||
if (last >= (start + count - 1)) {
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
|
||||
count = end - last;
|
||||
start = last + 1;
|
||||
range = find_range(db, owner, start);
|
||||
}
|
||||
|
||||
if (doclose) {
|
||||
if (db == &subordinate_uid_db)
|
||||
sub_uid_close();
|
||||
else
|
||||
sub_gid_close();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sub_uid_setdbname (const char *filename)
|
||||
{
|
||||
return commonio_setname (&subordinate_uid_db, filename);
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
|
||||
set -e
|
||||
|
||||
build_path=$(pwd)
|
||||
while [ "${build_path}" != "/" -a ! -e "${build_path}/.git" ]; do
|
||||
build_path=$(dirname ${build_path})
|
||||
done
|
||||
if [ ! -e "${build_path}/.git" ]; then
|
||||
echo "Not inside git directory" 1>&2
|
||||
exit 1
|
||||
if [ -n "${BUILD_BASE_DIR}" ]; then
|
||||
build_path="${BUILD_BASE_DIR}"
|
||||
else
|
||||
build_path=$(git rev-parse --show-toplevel)
|
||||
fi
|
||||
if [ -z "${build_path}" ]; then
|
||||
echo "Failed to find build base path"
|
||||
exit 1
|
||||
fi
|
||||
export build_path
|
||||
|
||||
# Save the configuration files in tmp.
|
||||
save_config ()
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
all: test_nss libsubid_zzz.so
|
||||
|
||||
test_nss: test_nss.c ../../../lib/nss.c
|
||||
gcc -c -I../../../lib/ -I../../.. -o test_nss.o test_nss.c
|
||||
gcc -o test_nss test_nss.o ../../../lib/.libs/libshadow.a -ldl
|
||||
BASE_TEST_DIR ?= $(shell git rev-parse --show-toplevel)
|
||||
basedir := $(BASE_TEST_DIR)
|
||||
|
||||
test_nss: test_nss.c $(basedir)/lib/nss.c
|
||||
gcc -c -I$(basedir)/lib/ -I$(basedir) -o test_nss.o test_nss.c
|
||||
gcc -o test_nss test_nss.o $(basedir)/lib/.libs/libshadow.a -ldl
|
||||
|
||||
libsubid_zzz.so: libsubid_zzz.c
|
||||
gcc -c -I../../../lib/ -I../../.. -I../../../libsubid libsubid_zzz.c
|
||||
gcc -L../../../libsubid -shared -o libsubid_zzz.so libsubid_zzz.o ../../../lib/.libs/libshadow.a -ldl
|
||||
gcc -c -I$(basedir)/lib/ -I$(basedir) -I$(basedir)/libsubid libsubid_zzz.c
|
||||
gcc -L$(basedir)/libsubid -shared -o libsubid_zzz.so libsubid_zzz.o $(basedir)/lib/.libs/libshadow.a -ldl
|
||||
|
||||
clean:
|
||||
rm -f *.o *.so test_nss
|
||||
|
||||
@@ -9,7 +9,7 @@ cd $(dirname $0)
|
||||
|
||||
make
|
||||
|
||||
export LD_LIBRARY_PATH=.:../../../lib/.libs:$LD_LIBRARY_PATH
|
||||
export LD_LIBRARY_PATH=.:${build_path}/lib/.libs:$LD_LIBRARY_PATH
|
||||
|
||||
./test_nss 1
|
||||
./test_nss 2
|
||||
|
||||
@@ -11,23 +11,23 @@ cleanup1() {
|
||||
umount /etc/nsswitch.conf
|
||||
}
|
||||
trap cleanup1 EXIT HUP INT TERM
|
||||
../../../src/check_subid_range user1 u 100000 65535
|
||||
${build_path}/src/check_subid_range user1 u 100000 65535
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
../../../src/check_subid_range user2 u 100000 65535
|
||||
${build_path}/src/check_subid_range user2 u 100000 65535
|
||||
if [ $? -eq 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
../../../src/check_subid_range unknown u 100000 65535
|
||||
${build_path}/src/check_subid_range unknown u 100000 65535
|
||||
if [ $? -eq 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
../../../src/check_subid_range error u 100000 65535
|
||||
${build_path}/src/check_subid_range error u 100000 65535
|
||||
if [ $? -eq 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
../../../src/check_subid_range user1 u 1000 65535
|
||||
${build_path}/src/check_subid_range user1 u 1000 65535
|
||||
if [ $? -eq 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
@@ -43,7 +43,7 @@ cleanup2() {
|
||||
umount /etc/nsswitch.conf
|
||||
}
|
||||
trap cleanup2 EXIT HUP INT TERM
|
||||
../../../src/check_subid_range user1 u 100000 65535
|
||||
${build_path}/src/check_subid_range user1 u 100000 65535
|
||||
if [ $? -eq 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -7,6 +7,22 @@ unset LANG
|
||||
unset LANGUAGE
|
||||
. common/config.sh
|
||||
|
||||
# When we unshare -Ur, we must be able to descend the build path.
|
||||
# But $HOME might not be world x. Fix that.
|
||||
fixup_home_perms() {
|
||||
p="${build_path}"
|
||||
d=""
|
||||
echo "$p" | tr '/' '\n' | while read f; do
|
||||
if [ -z "$f" ]; then
|
||||
continue
|
||||
fi
|
||||
d="$d/$f"
|
||||
chmod ugo+x "$d"
|
||||
done
|
||||
}
|
||||
|
||||
fixup_home_perms
|
||||
|
||||
USE_PAM="yes"
|
||||
FAILURE_TESTS="yes"
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -28,13 +29,29 @@
|
||||
static jmp_buf jmpb;
|
||||
|
||||
|
||||
/**********************
|
||||
* WRAPPERS
|
||||
**********************/
|
||||
int __real_vasprintf(char **restrict p, const char *restrict fmt, va_list ap);
|
||||
int __wrap_vasprintf(char **restrict p, const char *restrict fmt, va_list ap);
|
||||
void __wrap_exit(int status);
|
||||
|
||||
[[gnu::noipa]]
|
||||
static int xasprintf_volatile(char *volatile *restrict s,
|
||||
const char *restrict fmt, ...);
|
||||
|
||||
static void test_xasprintf_exit(void **state);
|
||||
static void test_xasprintf_ok(void **state);
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_xasprintf_exit),
|
||||
cmocka_unit_test(test_xasprintf_ok),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
__wrap_vasprintf(char **restrict p, const char *restrict fmt, va_list ap)
|
||||
@@ -50,11 +67,16 @@ __wrap_exit(int status)
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* TEST
|
||||
**********************/
|
||||
static void test_xasprintf_exit(void **state);
|
||||
static void test_xasprintf_ok(void **state);
|
||||
static int
|
||||
xasprintf_volatile(char *volatile *restrict s, const char *restrict fmt, ...)
|
||||
{
|
||||
int len;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
len = xvasprintf((char **) s, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
@@ -70,7 +92,7 @@ test_xasprintf_exit(void **state)
|
||||
switch (setjmp(jmpb)) {
|
||||
case 0:
|
||||
len = XASPRINTF_CALLED;
|
||||
len = xasprintf(&p, "foo%s", "bar");
|
||||
len = xasprintf_volatile(&p, "foo%s", "bar");
|
||||
assert_unreachable();
|
||||
break;
|
||||
case EXIT_CALLED:
|
||||
@@ -100,15 +122,3 @@ test_xasprintf_ok(void **state)
|
||||
assert_string_equal(p, "foo1bar");
|
||||
free(p);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_xasprintf_exit),
|
||||
cmocka_unit_test(test_xasprintf_ok),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user