diff --git a/src/cmd/diodcli.c b/src/cmd/diodcli.c index 67eaf20b..ab16eb65 100644 --- a/src/cmd/diodcli.c +++ b/src/cmd/diodcli.c @@ -45,6 +45,7 @@ #include #include #include +#include #if HAVE_SYS_XATTR_H #include #else diff --git a/src/cmd/test/flock_single.c b/src/cmd/test/flock_single.c index daa677ea..cbb01b81 100644 --- a/src/cmd/test/flock_single.c +++ b/src/cmd/test/flock_single.c @@ -13,6 +13,9 @@ #if HAVE_CONFIG_H #include "config.h" #endif +#include +#include +#include #include #include #include diff --git a/src/libdiod/diod_sock.c b/src/libdiod/diod_sock.c index 48b0bca7..12a80f8a 100644 --- a/src/libdiod/diod_sock.c +++ b/src/libdiod/diod_sock.c @@ -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); } diff --git a/t/sharness.d/10-sudo.sh b/t/sharness.d/10-sudo.sh index 6f13a233..2e22ce25 100644 --- a/t/sharness.d/10-sudo.sh +++ b/t/sharness.d/10-sudo.sh @@ -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 diff --git a/t/t0001-basic-runasuser.t b/t/t0001-basic-runasuser.t index 3484466e..153f0137 100755 --- a/t/t0001-basic-runasuser.t +++ b/t/t0001-basic-runasuser.t @@ -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' ' @@ -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 diff --git a/t/t0002-basic-allsquash.t b/t/t0002-basic-allsquash.t index 7cd7606c..984d3d3b 100755 --- a/t/t0002-basic-allsquash.t +++ b/t/t0002-basic-allsquash.t @@ -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' ' diff --git a/t/t0003-basic-multiuser.t b/t/t0003-basic-multiuser.t index 226d5408..ed3ea568 100755 --- a/t/t0003-basic-multiuser.t +++ b/t/t0003-basic-multiuser.t @@ -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' ' diff --git a/t/t0010-v9fs-runasuser.t b/t/t0010-v9fs-runasuser.t index b308915d..2e4c5590 100755 --- a/t/t0010-v9fs-runasuser.t +++ b/t/t0010-v9fs-runasuser.t @@ -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)" @@ -83,9 +83,10 @@ test_expect_success 'mount filesystem with access= 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' ' diff --git a/t/t0011-v9fs-allsquash.t b/t/t0011-v9fs-allsquash.t index 73ae2baa..78a42a8e 100755 --- a/t/t0011-v9fs-allsquash.t +++ b/t/t0011-v9fs-allsquash.t @@ -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)" @@ -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)" ' diff --git a/t/t0012-v9fs-multiuser.t b/t/t0012-v9fs-multiuser.t index b2cdb0ce..11dd32e9 100755 --- a/t/t0012-v9fs-multiuser.t +++ b/t/t0012-v9fs-multiuser.t @@ -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)" diff --git a/t/t0013-v9fs-acl.t b/t/t0013-v9fs-acl.t index 3a5d6bd8..c1f97ae5 100755 --- a/t/t0013-v9fs-acl.t +++ b/t/t0013-v9fs-acl.t @@ -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 diff --git a/t/t0020-dbench.t b/t/t0020-dbench.t index a9a549dc..93b03536 100755 --- a/t/t0020-dbench.t +++ b/t/t0020-dbench.t @@ -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)" diff --git a/t/t0021-postmark.t b/t/t0021-postmark.t index f390da95..a13673c2 100755 --- a/t/t0021-postmark.t +++ b/t/t0021-postmark.t @@ -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)" diff --git a/t/t0022-scrub.t b/t/t0022-scrub.t index 5e8c638c..9d8b0f51 100755 --- a/t/t0022-scrub.t +++ b/t/t0022-scrub.t @@ -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)" diff --git a/t/t0023-rsync.t b/t/t0023-rsync.t index c7bea400..6a040e68 100755 --- a/t/t0023-rsync.t +++ b/t/t0023-rsync.t @@ -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 diff --git a/t/t0024-selfhost.t b/t/t0024-selfhost.t index e09cd352..8c20eaf6 100755 --- a/t/t0024-selfhost.t +++ b/t/t0024-selfhost.t @@ -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)" diff --git a/t/t0025-pathwalk.t b/t/t0025-pathwalk.t index 6d2fadf3..0561fc84 100755 --- a/t/t0025-pathwalk.t +++ b/t/t0025-pathwalk.t @@ -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)"