Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cmd/diodcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <inttypes.h>
#include <string.h>
#include <getopt.h>
#include <libgen.h>
#if HAVE_SYS_XATTR_H
#include <sys/xattr.h>
#else
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/test/flock_single.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/file.h>
#include <stdlib.h>
Expand Down
41 changes: 24 additions & 17 deletions src/libdiod/diod_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,27 +333,34 @@ diod_sock_accept_one (Npsrv *srv, int fd, int lookup)
err ("accept");
return;
}
if ((res = getnameinfo ((struct sockaddr *)&addr, addr_size,
ip, sizeof(ip), svc, sizeof(svc),
NI_NUMERICHOST | NI_NUMERICSERV))) {
msg ("getnameinfo: %s", gai_strerror(res));
close (fd);
return;
/* N.B. although glibc getnameinfo() sets ip to "localhost" for
* AF_UNIX, musl libc fails with EAI_FAMILY. Hence, getnameinfo() is
* only attempted for non-AF_UNIX. See also chaos/diod#160
*/
if (addr.ss_family == AF_UNIX) {
if (!lookup || gethostname (host, sizeof (host)) < 0)
snprintf (host, sizeof (host), "localhost");
}
if (addr.ss_family != AF_UNIX) {
else {
if ((res = getnameinfo ((struct sockaddr *)&addr, addr_size,
ip, sizeof(ip), svc, sizeof(svc),
NI_NUMERICHOST | NI_NUMERICSERV))) {
msg ("getnameinfo: %s", gai_strerror(res));
close (fd);
return;
}
if (lookup && (res = getnameinfo ((struct sockaddr *)&addr, addr_size,
host, sizeof(host), NULL, 0, 0))) {
msg ("getnameinfo: %s", gai_strerror(res));
close (fd);
return;
}
port = strtoul (svc, NULL, 10);
if (port < IPPORT_RESERVED && port >= IPPORT_RESERVED / 2)
flags |= CONN_FLAGS_PRIVPORT;
(void)_disable_nagle (fd);
(void)_enable_keepalive (fd);
}
host[0] = '\0';
if (lookup && (res = getnameinfo ((struct sockaddr *)&addr, addr_size,
host, sizeof(host), NULL, 0, 0))) {
msg ("getnameinfo: %s", gai_strerror(res));
close (fd);
return;
}
port = strtoul (svc, NULL, 10);
if (port < IPPORT_RESERVED && port >= IPPORT_RESERVED / 2)
flags |= CONN_FLAGS_PRIVPORT;
diod_sock_startfd (srv, fd, fd, strlen(host) > 0 ? host : ip, flags);
}

Expand Down
7 changes: 5 additions & 2 deletions t/sharness.d/10-sudo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
##
if sudo --non-interactive true >/dev/null 2>&1; then
test_set_prereq SUDO
SUDO="sudo -E"
elif _probeenv=xyz doas -n printenv _probeenv >/dev/null 2>&1; then
test_set_prereq SUDO
SUDO="doas"
fi
##
# Fixup sudo commandline if sanitizers are enabled.
# LSan doesn't work under setuid or program run under sudo
##
SUDO=sudo
if test_have_prereq ASAN; then
SUDO="sudo -E ASAN_OPTIONS=$ASAN_OPTIONS:detect_leaks=0"
SUDO="ASAN_OPTIONS=$ASAN_OPTIONS:detect_leaks=0 $SUDO"
fi
8 changes: 4 additions & 4 deletions t/t0001-basic-runasuser.t
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ test_expect_success 'copy ctl:/zero to ctl:null' '
# implemented directly in libnpfs, bypassing diod_ops.c, where op_attach()
# gates access to all other exports.
test_expect_success SUDO 'the root user can access ctl:/version' '
$SUDO -E $PATH_DIODCLI --aname=ctl read version
$SUDO $PATH_DIODCLI --aname=ctl read version
'

test_expect_success NOBODY 'the nobody user can access ctl:/version' '
$SUDO -E -u nobody $PATH_DIODCLI --aname=ctl read version
$SUDO -u nobody $PATH_DIODCLI --aname=ctl read version
'

test_expect_success 'ls net:/ shows test files' '
Expand Down Expand Up @@ -87,13 +87,13 @@ test_expect_success 'cat net:/1/c produced test file content' '
'

test_expect_success SUDO 'cat net:/1/c fails as root' '
test_must_fail $SUDO -E \
test_must_fail $SUDO \
$PATH_DIODCLI --aname=$exportdir read /1/c 2>rootcat.err &&
grep "Operation not permitted" rootcat.err
'

test_expect_success NOBODY 'cat net:/1/c fails as nobody' '
test_must_fail $SUDO -E -u nobody \
test_must_fail $SUDO -u nobody \
$PATH_DIODCLI --aname=$exportdir read /1/c \
2>nobodycat.err &&
grep "Operation not permitted" nobodycat.err
Expand Down
8 changes: 4 additions & 4 deletions t/t0002-basic-allsquash.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ test_expect_success 'the squash user can access ctl:/version' '
'

test_expect_success SUDO 'the root user can access ctl:/version' '
$SUDO -E $PATH_DIODCLI --aname=ctl read version
$SUDO $PATH_DIODCLI --aname=ctl read version
'

test_expect_success NOBODY 'the nobody user can access ctl:/version' '
$SUDO -E -u nobody $PATH_DIODCLI --aname=ctl read version
$SUDO -u nobody $PATH_DIODCLI --aname=ctl read version
'

test_expect_success 'the squash user can access net:/a' '
$PATH_DIODCLI --aname=$exportdir read /a
'
test_expect_success SUDO 'the root user can access net:/a' '
$SUDO -E $PATH_DIODCLI --aname=$exportdir read /a
$SUDO $PATH_DIODCLI --aname=$exportdir read /a
'
test_expect_success NOBODY 'the nobody user can access net:/a' '
$SUDO -E -u nobody $PATH_DIODCLI --aname=$exportdir read /a
$SUDO -u nobody $PATH_DIODCLI --aname=$exportdir read /a
'

test_expect_success 'stop diod' '
Expand Down
16 changes: 8 additions & 8 deletions t/t0003-basic-multiuser.t
Original file line number Diff line number Diff line change
Expand Up @@ -47,43 +47,43 @@ test_expect_success 'the squash user can access ctl:/version' '
$PATH_DIODCLI --aname=ctl read version
'
test_expect_success 'the root user can access ctl:/version' '
$SUDO -E $PATH_DIODCLI --aname=ctl read version
$SUDO $PATH_DIODCLI --aname=ctl read version
'
test_expect_success 'the nobody user can access ctl:/version' '
$SUDO -E -u nobody $PATH_DIODCLI --aname=ctl read version
$SUDO -u nobody $PATH_DIODCLI --aname=ctl read version
'

test_expect_success 'user can access net:/user' '
$PATH_DIODCLI --aname=$exportdir read /user
'
test_expect_success 'nobody cannot access net:/user' '
test_must_fail $SUDO -E -u nobody \
test_must_fail $SUDO -u nobody \
$PATH_DIODCLI --aname=$exportdir read /user
'
test_expect_success 'root can access net:/user' '
$SUDO -E $PATH_DIODCLI --aname=$exportdir read /user
$SUDO $PATH_DIODCLI --aname=$exportdir read /user
'

test_expect_success 'user cannot access net:/nobody' '
test_must_fail $PATH_DIODCLI --aname=$exportdir read /nobody
'
test_expect_success 'nobody can access net:/nobody' '
$SUDO -E -u nobody \
$SUDO -u nobody \
$PATH_DIODCLI --aname=$exportdir read /nobody
'
test_expect_success 'root can access net:/nobody' '
$SUDO -E $PATH_DIODCLI --aname=$exportdir read /nobody
$SUDO $PATH_DIODCLI --aname=$exportdir read /nobody
'

test_expect_success 'user cannot access net:/root' '
test_must_fail $PATH_DIODCLI --aname=$exportdir read /root
'
test_expect_success 'nobody cannot access net:/root' '
test_must_fail $SUDO -E -u nobody \
test_must_fail $SUDO -u nobody \
$PATH_DIODCLI --aname=$exportdir read /root
'
test_expect_success 'root can access net:/root' '
$SUDO -E $PATH_DIODCLI --aname=$exportdir read /root
$SUDO $PATH_DIODCLI --aname=$exportdir read /root
'

test_expect_success 'stop diod' '
Expand Down
7 changes: 4 additions & 3 deletions t/t0010-v9fs-runasuser.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test_under_diod unixsocket \

# gnome probes for .Trash, autorun.inf, etc asynchronously on new mounts,
# causing umount to fail with EBUSY if still in progress. Therefore --lazy.
umountcmd="$SUDO umount --lazy"
umountcmd="$SUDO umount -l"
mountcmd="$SUDO mount -n -t 9p"
mountopts="trans=unix,uname=$(id -un)"

Expand Down Expand Up @@ -83,9 +83,10 @@ test_expect_success 'mount filesystem with access=<uid> on mnt' '
$mountcmd -oaname=$exportdir,$mountopts,access=$(id -u) \
$DIOD_SOCKET mnt
'
# On alpine/busybox, %T decodes as type=UNKNOWN. Use %t instead.
test_expect_success STAT 'file system type is v9fs' '
echo v9fs >type.exp &&
stat -f -c "%T" mnt >type.out &&
echo 1021997 >type.exp &&
stat -f -c "%t" mnt >type.out &&
test_cmp type.exp type.out
'
test_expect_success STAT 'client/server mount point stats match' '
Expand Down
8 changes: 6 additions & 2 deletions t/t0011-v9fs-allsquash.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test_under_diod unixsocket \

# gnome probes for .Trash, autorun.inf, etc asynchronously on new mounts,
# causing umount to fail with EBUSY if still in progress. Therefore --lazy.
umountcmd="$SUDO umount --lazy"
umountcmd="$SUDO umount -l"
mountcmd="$SUDO mount -n -t 9p"
mountopts="trans=unix,uname=$(id -un)"

Expand All @@ -50,8 +50,12 @@ test_expect_success SUDO,STAT 'root can create a directory, mode 755' '
$SUDO mkdir -m 755 mnt/rootdir &&
test "$($PATH_STAT -c "%u:%g" exp/rootdir)" = "$(id -u):$(id -g)"
'
# N.B. fails on alpine/busybox when mkdir -m 755 is used because alpine
# calls mkdir and chmod separately, so the chmod isn't allowed.
# Do the chmod as the squashuser instead.
test_expect_success NOBODY,STAT 'nobody can create a directory, mode 755' '
$SUDO -u nobody mkdir -m 755 mnt/nobodydir &&
$SUDO -u nobody mkdir mnt/nobodydir &&
chmod 755 mnt/nobodydir &&
test "$($PATH_STAT -c "%u:%g" exp/nobodydir)" = "$(id -u):$(id -g)"
'

Expand Down
2 changes: 1 addition & 1 deletion t/t0012-v9fs-multiuser.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fi

# gnome probes for .Trash, autorun.inf, etc asynchronously on new mounts,
# causing umount to fail with EBUSY if still in progress. Therefore --lazy.
umountcmd="$SUDO umount --lazy"
umountcmd="$SUDO umount -l"
mountcmd="$SUDO mount -n -t 9p"
mountopts="trans=unix,uname=$(id -un)"

Expand Down
2 changes: 1 addition & 1 deletion t/t0013-v9fs-acl.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test_under_diod unixsocketroot \

# gnome probes for .Trash, autorun.inf, etc asynchronously on new mounts,
# causing umount to fail with EBUSY if still in progress. Therefore --lazy.
umountcmd="$SUDO umount --lazy"
umountcmd="$SUDO umount -l"

test_expect_success 'create export/mount directories' '
mkdir -p exp mnt
Expand Down
2 changes: 1 addition & 1 deletion t/t0020-dbench.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test_under_diod unixsocket \

# gnome probes for .Trash, autorun.inf, etc asynchronously on new mounts,
# causing umount to fail with EBUSY if still in progress. Therefore --lazy.
umountcmd="$SUDO umount --lazy"
umountcmd="$SUDO umount -l"
mountcmd="$SUDO mount -n -t 9p"
mountopts="trans=unix,uname=$(id -un)"

Expand Down
2 changes: 1 addition & 1 deletion t/t0021-postmark.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test_under_diod unixsocket \

# gnome probes for .Trash, autorun.inf, etc asynchronously on new mounts,
# causing umount to fail with EBUSY if still in progress. Therefore --lazy.
umountcmd="$SUDO umount --lazy"
umountcmd="$SUDO umount -l"
mountcmd="$SUDO mount -n -t 9p"
mountopts="trans=unix,uname=$(id -un)"

Expand Down
2 changes: 1 addition & 1 deletion t/t0022-scrub.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test_under_diod unixsocket \

# gnome probes for .Trash, autorun.inf, etc asynchronously on new mounts,
# causing umount to fail with EBUSY if still in progress. Therefore --lazy.
umountcmd="$SUDO umount --lazy"
umountcmd="$SUDO umount -l"
mountcmd="$SUDO mount -n -t 9p"
mountopts="trans=unix,uname=$(id -un)"

Expand Down
2 changes: 1 addition & 1 deletion t/t0023-rsync.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test_under_diod unixsocketroot \

# gnome probes for .Trash, autorun.inf, etc asynchronously on new mounts,
# causing umount to fail with EBUSY if still in progress. Therefore --lazy.
umountcmd="$SUDO umount --lazy"
umountcmd="$SUDO umount -l"

test_expect_success 'create export/mount directories' '
mkdir -p exp mnt
Expand Down
2 changes: 1 addition & 1 deletion t/t0024-selfhost.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test_under_diod unixsocket \

# gnome probes for .Trash, autorun.inf, etc asynchronously on new mounts,
# causing umount to fail with EBUSY if still in progress. Therefore --lazy.
umountcmd="$SUDO umount --lazy"
umountcmd="$SUDO umount -l"
mountcmd="$SUDO mount -n -t 9p"
mountopts="trans=unix,uname=$(id -un)"

Expand Down
2 changes: 1 addition & 1 deletion t/t0025-pathwalk.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test_under_diod unixsocket \

# gnome probes for .Trash, autorun.inf, etc asynchronously on new mounts,
# causing umount to fail with EBUSY if still in progress. Therefore --lazy.
umountcmd="$SUDO umount --lazy"
umountcmd="$SUDO umount -l"
mountcmd="$SUDO mount -n -t 9p"
mountopts="trans=unix,uname=$(id -un)"

Expand Down