diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 05890a266a08..32620e849df2 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -1,1142 +1,1144 @@ # $FreeBSD$ # # Please see the file src/etc/mtree/README before making changes to this file. # /set type=dir uname=root gname=wheel mode=0755 tags=package=tests . bin cat .. chflags .. chmod .. cp .. date .. dd .. echo .. expr .. ln .. ls .. mkdir .. mv .. pax .. pkill .. pwait .. rm .. rmdir .. sh builtins .. errors .. execution .. expansion .. invocation .. parameters .. parser .. set-e .. .. sleep .. test .. .. cddl lib .. sbin .. usr.bin ctfconvert .. ztest .. .. usr.sbin dtrace common aggs .. arithmetic .. arrays .. assocs .. begin .. bitfields .. buffering .. builtinvar .. cg .. clauses .. cpc .. decls .. drops .. dtraceUtil .. end .. env .. enum .. error .. exit .. fbtprovider .. funcs .. grammar .. include .. inline .. io .. ip .. java_api .. json .. lexer .. llquantize .. mdb .. mib .. misc .. multiaggs .. offsetof .. operators .. pid .. plockstat .. pointers .. pragma .. predicates .. preprocessor .. print .. printa .. printf .. privs .. probes .. proc .. profile-n .. providers .. raise .. rates .. safety .. scalars .. sched .. scripting .. sdt .. sizeof .. speculation .. stability .. stack .. stackdepth .. stop .. strlen .. strtoll .. struct .. sugar .. syscall .. sysevent .. tick-n .. trace .. tracemem .. translators .. typedef .. types .. uctf .. union .. usdt .. ustack .. vars .. version .. .. i386 arrays .. funcs .. pid .. ustack .. .. amd64 arrays .. .. .. zfsd .. .. .. etc rc.d .. .. games .. gnu lib .. usr.bin diff .. .. .. lib atf libatf-c detail .. .. libatf-c++ detail .. .. test-programs .. .. csu dynamic .. dynamiclib .. static .. .. googletest gmock .. gmock_main .. gtest .. gtest_main .. .. libarchive .. libbe .. libc c063 .. db .. gen execve .. posix_spawn .. .. hash data .. .. iconv .. inet .. locale .. net getaddrinfo data .. .. .. nss .. regex data .. .. resolv .. rpc .. ssp .. setjmp .. stdio .. stdlib .. string .. sys .. time .. tls dso .. .. termios .. ttyio .. .. libcam .. libcasper services cap_dns .. cap_grp .. cap_pwd .. cap_sysctl .. .. .. libcrypt .. libdevdctl .. libexecinfo .. libkvm .. libmp .. libnv .. libproc .. libregex data .. .. librt .. libsbuf .. + libsysdecode + .. libthr dlopen .. .. libutil .. libxo .. msun .. .. libexec atf atf-check .. atf-sh .. .. rtld-elf .. tftpd .. .. sbin bectl .. dhclient .. devd .. growfs .. ifconfig .. md5 .. mdconfig .. newfs_msdos .. nvmecontrol .. pfctl files .. .. ping .. route .. .. secure lib .. libexec .. usr.bin .. usr.sbin .. .. share examples tests atf .. googletest .. plain .. tap .. .. .. zoneinfo .. .. sys acl .. aio .. audit .. auditpipe .. capsicum .. cddl zfs bin .. include .. tests acl cifs .. nontrivial .. trivial .. .. atime .. bootfs .. cache .. cachefile .. clean_mirror .. cli_root zfs_upgrade .. zfs_promote .. zfs_clone .. zfs_property .. zfs_destroy .. zpool_create .. zpool_history .. zpool_expand .. zpool_remove .. zfs_mount .. zfs_unshare .. zdb .. zpool_online .. zpool_get .. zpool_export .. zfs_copies .. zfs_get .. zfs .. zpool_clear .. zpool_import blockfiles .. .. zpool .. zpool_offline .. zpool_replace .. zfs_rollback .. zpool_set .. zfs_send .. zfs_set .. zpool_detach .. zfs_diff .. zpool_scrub .. zfs_inherit .. zfs_snapshot .. zfs_share .. zpool_destroy .. zpool_status .. zfs_unmount .. zfs_receive .. zfs_create .. zpool_upgrade blockfiles .. .. zpool_add .. zfs_rename .. zpool_attach .. zfs_reservation .. .. cli_user misc .. zfs_list .. zpool_iostat .. zpool_list .. .. compression .. ctime .. delegate .. devices .. exec .. grow_pool .. grow_replicas .. history .. hotplug .. hotspare .. inheritance .. interop .. inuse .. iscsi .. large_files .. largest_pool .. link_count .. migration .. mmap .. mount .. mv_files .. nestedfs .. no_space .. online_offline .. pool_names .. poolversion .. quota .. redundancy .. refquota .. refreserv .. rename_dirs .. replacement .. reservation .. rootpool .. rsend .. scrub_mirror .. slog .. snapshot .. snapused .. sparse .. threadsappend .. truncate .. txg_integrity .. userquota .. utils_test .. write_dirs .. xattr .. zfsd .. zil .. zinject .. zones .. zvol zvol_ENOSPC .. zvol_cli .. zvol_misc .. zvol_swap .. .. zvol_thrash .. .. .. .. devrandom .. dtrace .. fifo .. file .. fs fusefs .. tmpfs .. .. geom class concat .. eli .. gate .. gpt .. mirror .. multipath .. nop .. part .. raid3 .. shsec .. stripe .. uzip etalon .. .. .. .. kern acct .. execve .. pipe .. .. kqueue libkqueue .. .. mac bsdextended .. portacl .. .. mqueue .. net .. netgraph .. netinet .. netinet6 frag6 .. .. netipsec tunnel .. .. netmap .. netpfil common .. pf ioctl .. .. .. opencrypto .. pjdfstest chflags .. chmod .. chown .. ftruncate .. granular .. link .. mkdir .. mkfifo .. mknod .. open .. rename .. rmdir .. symlink .. truncate .. unlink .. utimensat .. .. posixshm .. sys .. vfs .. vm .. vmm .. .. usr.bin apply .. awk bugs-fixed .. netbsd .. .. basename .. bmake archives fmt_44bsd .. fmt_44bsd_mod .. fmt_oldbsd .. .. basic t0 .. t1 .. t2 .. t3 .. .. execution ellipsis .. empty .. joberr .. plus .. .. shell builtin .. meta .. path .. path_select .. replace .. select .. .. suffixes basic .. src_wild1 .. src_wild2 .. .. syntax directive-t0 .. enl .. funny-targets .. semi .. .. sysmk t0 2 1 .. .. mk .. .. t1 2 1 .. .. mk .. .. t2 2 1 .. .. mk .. .. .. variables modifier_M .. modifier_t .. opt_V .. t0 .. .. .. bsdcat .. calendar .. cmp .. compress .. cpio .. col .. comm .. csplit .. cut .. dc .. diff .. diff3 .. dirname .. du .. file2c .. file .. find .. fold .. getconf .. gh-bc .. grep .. gzip .. head .. hexdump .. ident .. indent .. join .. jot .. lastcomm .. limits .. locale .. m4 .. mkimg .. ncal .. opensm .. patch .. pr .. printf .. procstat .. rs .. sdiff .. sed regress.multitest.out .. .. seq .. soelim .. sort .. stat .. tail .. tar .. timeout .. tr .. truncate .. units .. uudecode .. uuencode .. unifdef .. uniq .. vmstat .. xargs .. xinstall .. xo .. yacc yacc .. .. .. usr.sbin chown .. daemon .. etcupdate .. extattr .. fstyp .. jail .. makefs .. mixer .. newsyslog .. nmtree .. praudit .. pw .. rpcbind .. sa .. .. .. # vim: set expandtab ts=4 sw=4: diff --git a/lib/libsysdecode/Makefile b/lib/libsysdecode/Makefile index d58858086bc9..671c23d95a70 100644 --- a/lib/libsysdecode/Makefile +++ b/lib/libsysdecode/Makefile @@ -1,144 +1,147 @@ # $FreeBSD$ .include LIB= sysdecode SRCS= errno.c flags.c ioctl.c signal.c syscallnames.c utrace.c INCS= sysdecode.h CFLAGS+= -I${.OBJDIR} CFLAGS+= -I${SRCTOP}/sys CFLAGS+= -I${SRCTOP}/libexec/rtld-elf MAN= sysdecode.3 \ sysdecode_abi_to_freebsd_errno.3 \ sysdecode_cap_rights.3 \ sysdecode_cmsg_type.3 \ sysdecode_enum.3 \ sysdecode_fcntl_arg.3 \ sysdecode_kevent.3 \ sysdecode_ioctlname.3 \ sysdecode_mask.3 \ sysdecode_quotactl_cmd.3 \ sysdecode_sctp_sinfo_flags.3 \ sysdecode_sigcode.3 \ sysdecode_sockopt_name.3 \ sysdecode_socket_protocol.3 \ sysdecode_syscallnames.3 \ sysdecode_utrace.3 MLINKS= sysdecode_abi_to_freebsd_errno.3 sysdecode_freebsd_to_abi_errno.3 MLINKS+=sysdecode_enum.3 sysdecode_acltype.3 \ sysdecode_enum.3 sysdecode_atfd.3 \ sysdecode_enum.3 sysdecode_extattrnamespace.3 \ sysdecode_enum.3 sysdecode_fadvice.3 \ sysdecode_enum.3 sysdecode_fcntl_cmd.3 \ sysdecode_enum.3 sysdecode_getfsstat_mode.3 \ sysdecode_enum.3 sysdecode_getrusage_who.3 \ sysdecode_enum.3 sysdecode_idtype.3 \ sysdecode_enum.3 sysdecode_ipproto.3 \ sysdecode_enum.3 sysdecode_kldsym_cmd.3 \ sysdecode_enum.3 sysdecode_kldunload_flags.3 \ sysdecode_enum.3 sysdecode_lio_listio_mode.3 \ sysdecode_enum.3 sysdecode_madvice.3 \ sysdecode_enum.3 sysdecode_minherit_flags.3 \ sysdecode_enum.3 sysdecode_msgctl_cmd.3 \ sysdecode_enum.3 sysdecode_nfssvc_flags.3 \ sysdecode_enum.3 sysdecode_pathconf_name.3 \ sysdecode_enum.3 sysdecode_prio_which.3 \ sysdecode_enum.3 sysdecode_procctl_cmd.3 \ sysdecode_enum.3 sysdecode_ptrace_request.3 \ sysdecode_enum.3 sysdecode_rlimit.3 \ sysdecode_enum.3 sysdecode_rtprio_function.3 \ sysdecode_enum.3 sysdecode_scheduler_policy.3 \ sysdecode_enum.3 sysdecode_sctp_pr_policy.3 \ sysdecode_enum.3 sysdecode_semctl_cmd.3 \ sysdecode_enum.3 sysdecode_shmctl_cmd.3 \ sysdecode_enum.3 sysdecode_shutdown_how.3 \ sysdecode_enum.3 sysdecode_sigbus_code.3 \ sysdecode_enum.3 sysdecode_sigchld_code.3 \ sysdecode_enum.3 sysdecode_sigfpe_code.3 \ sysdecode_enum.3 sysdecode_sigill_code.3 \ sysdecode_enum.3 sysdecode_signal.3 \ sysdecode_enum.3 sysdecode_sigprocmask_how.3 \ sysdecode_enum.3 sysdecode_sigsegv_code.3 \ sysdecode_enum.3 sysdecode_sigtrap_code.3 \ sysdecode_enum.3 sysdecode_sockaddr_family.3 \ sysdecode_enum.3 sysdecode_socketdomain.3 \ sysdecode_enum.3 sysdecode_sockettype.3 \ sysdecode_enum.3 sysdecode_sockopt_level.3 \ sysdecode_enum.3 sysdecode_sysarch_number.3 \ sysdecode_enum.3 sysdecode_umtx_op.3 \ sysdecode_enum.3 sysdecode_vmresult.3 \ sysdecode_enum.3 sysdecode_whence.3 MLINKS+=sysdecode_fcntl_arg.3 sysdecode_fcntl_arg_p.3 MLINKS+=sysdecode_kevent.3 sysdecode_kevent_fflags.3 \ sysdecode_kevent.3 sysdecode_kevent_filter.3 \ sysdecode_kevent.3 sysdecode_kevent_flags.3 MLINKS+=sysdecode_mask.3 sysdecode_accessmode.3 \ sysdecode_mask.3 sysdecode_atflags.3 \ sysdecode_mask.3 sysdecode_capfcntlrights.3 \ sysdecode_mask.3 sysdecode_fcntl_fileflags.3 \ sysdecode_mask.3 sysdecode_fileflags.3 \ sysdecode_mask.3 sysdecode_filemode.3 \ sysdecode_mask.3 sysdecode_flock_operation.3 \ sysdecode_mask.3 sysdecode_mlockall_flags.3 \ sysdecode_mask.3 sysdecode_mmap_flags.3 \ sysdecode_mask.3 sysdecode_mmap_prot.3 \ sysdecode_mask.3 sysdecode_mount_flags.3 \ sysdecode_mask.3 sysdecode_msg_flags.3 \ sysdecode_mask.3 sysdecode_msync_flags.3 \ sysdecode_mask.3 sysdecode_open_flags.3 \ sysdecode_mask.3 sysdecode_pipe2_flags.3 \ sysdecode_mask.3 sysdecode_reboot_howto.3 \ sysdecode_mask.3 sysdecode_rfork_flags.3 \ sysdecode_mask.3 sysdecode_semget_flags.3 \ sysdecode_mask.3 sysdecode_sendfile_flags.3 \ sysdecode_mask.3 sysdecode_shmat_flags.3 \ sysdecode_mask.3 sysdecode_sctp_nxt_flags.3 \ sysdecode_mask.3 sysdecode_sctp_rcv_flags.3 \ sysdecode_mask.3 sysdecode_sctp_snd_flags.3 \ sysdecode_mask.3 sysdecode_socket_type.3 \ sysdecode_mask.3 sysdecode_thr_create_flags.3 \ sysdecode_mask.3 sysdecode_umtx_cvwait_flags.3 \ sysdecode_mask.3 sysdecode_umtx_rwlock_flags.3 \ sysdecode_mask.3 sysdecode_vmprot.3 \ sysdecode_mask.3 sysdecode_wait4_options.3 \ sysdecode_mask.3 sysdecode_wait6_options.3 CLEANFILES= ioctl.c ioctl.c.tmp tables.h .if defined(COMPAT_32BIT) CPP+= -m32 .endif .if ${MK_PF} != "no" CFLAGS+=-DPF .endif # Workaround duplicate declarations in CFLAGS.gcc.ioctl.c+= -Wno-redundant-decls CFLAGS.gcc+= ${CFLAGS.gcc.${.IMPSRC}} DEPENDOBJS+= tables.h tables.h: mktables sh ${.CURDIR}/mktables ${SYSROOT:U${DESTDIR}}${INCLUDEDIR} ${.TARGET} # mkioctls runs find(1) for headers so needs to rebuild every time. This used # to be a hack only done in buildworld. .if !defined(_SKIP_BUILD) ioctl.c.tmp: .PHONY .endif ioctl.c.tmp: mkioctls .META env CPP="${CPP}" MK_PF="${MK_PF}" \ /bin/sh ${.CURDIR}/mkioctls ${SYSROOT:U${DESTDIR}}${INCLUDEDIR} > ${.TARGET} ioctl.c: ioctl.c.tmp if [ ! -e ${.TARGET} ] || ! cmp -s ${.TARGET} ${.TARGET}.tmp; then \ mv -f ${.TARGET}.tmp ${.TARGET}; \ fi beforedepend: ioctl.c tables.h +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include diff --git a/lib/libsysdecode/tests/Makefile b/lib/libsysdecode/tests/Makefile new file mode 100644 index 000000000000..3d75b9b32ba7 --- /dev/null +++ b/lib/libsysdecode/tests/Makefile @@ -0,0 +1,5 @@ +ATF_TESTS_C+= sysdecode_test + +LIBADD= sysdecode + +.include diff --git a/lib/libsysdecode/tests/sysdecode_test.c b/lib/libsysdecode/tests/sysdecode_test.c new file mode 100644 index 000000000000..c41fdae68927 --- /dev/null +++ b/lib/libsysdecode/tests/sysdecode_test.c @@ -0,0 +1,152 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2022 The FreeBSD Foundation + * + * This software was developed by Mark Johnston under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +#include +#include + +/* + * Take a comma-separated list of capability rights and verify that all rights + * are present in the specified table, and that all rights in the table are + * present in the list. + */ +static void +check_sysdecode_cap_rights(FILE *fp, char **bufp, size_t *szp, + cap_rights_t *rightsp, const char *tab[]) +{ + const char *next, *tok; + char *buf; + int i; + + sysdecode_cap_rights(fp, rightsp); + + ATF_REQUIRE(fflush(fp) == 0); + (*bufp)[*szp] = '\0'; + + buf = strdup(*bufp); + for (tok = buf; (next = strsep(&buf, ",")), tok != NULL; tok = next) { + for (i = 0; tab[i] != NULL; i++) { + if (strcmp(tok, tab[i]) == 0) + break; + } + ATF_REQUIRE_MSG(tab[i] != NULL, + "did not find '%s' in table", tok); + } + free(buf); + + for (i = 0; tab[i] != NULL; i++) { + buf = strdup(*bufp); + for (tok = buf; (next = strsep(&buf, ",")), tok != NULL; + tok = next) { + if (strcmp(tok, tab[i]) == 0) + break; + } + free(buf); + ATF_REQUIRE_MSG(tok != NULL, + "did not find '%s' in output stream", tab[i]); + } + + ATF_REQUIRE(fseek(fp, 0, SEEK_SET) == 0); +} + +/* + * Regression tests for sysdecode_cap_rights(3). + */ +ATF_TC_WITHOUT_HEAD(cap_rights); +ATF_TC_BODY(cap_rights, tc) +{ + char *buf; + FILE *fp; + size_t sz; + cap_rights_t rights; + + fp = open_memstream(&buf, &sz); + ATF_REQUIRE(fp != NULL); + + /* + * libsysdecode emits a pseudo-right, CAP_NONE, when no rights are + * present. + */ + check_sysdecode_cap_rights(fp, &buf, &sz, + cap_rights_init(&rights), + (const char *[]){ "CAP_NONE", NULL, }); + + check_sysdecode_cap_rights(fp, &buf, &sz, + cap_rights_init(&rights, CAP_READ, CAP_SEEK), + (const char *[]){ "CAP_PREAD", NULL, }); + + check_sysdecode_cap_rights(fp, &buf, &sz, + cap_rights_init(&rights, CAP_READ, CAP_MMAP, CAP_SEEK_TELL), + (const char *[]){ "CAP_READ", "CAP_MMAP", "CAP_SEEK_TELL", NULL, }); + + check_sysdecode_cap_rights(fp, &buf, &sz, + cap_rights_init(&rights, CAP_MMAP, CAP_READ, CAP_WRITE, CAP_SEEK), + (const char *[]){ "CAP_MMAP_RW", NULL, }); + + check_sysdecode_cap_rights(fp, &buf, &sz, + cap_rights_init(&rights, CAP_READ, CAP_MMAP_X), + (const char *[]){ "CAP_MMAP_RX", NULL, }); + + /* Aliases map back to the main definition. */ + check_sysdecode_cap_rights(fp, &buf, &sz, + cap_rights_init(&rights, CAP_RECV, CAP_SEND), + (const char *[]){ "CAP_READ", "CAP_WRITE", NULL, }); + + /* This set straddles both indices. */ + check_sysdecode_cap_rights(fp, &buf, &sz, + cap_rights_init(&rights, CAP_READ, CAP_KQUEUE), + (const char *[]){ "CAP_READ", "CAP_KQUEUE", NULL, }); + + /* Create a rights set with an unnamed flag. */ + cap_rights_init(&rights, CAP_SEEK); + cap_rights_clear(&rights, CAP_SEEK_TELL); + check_sysdecode_cap_rights(fp, &buf, &sz, + &rights, + (const char *[]){ "CAP_NONE", "unknown rights", NULL, }); + + cap_rights_init(&rights, CAP_SEEK, CAP_KQUEUE_CHANGE); + cap_rights_clear(&rights, CAP_SEEK_TELL); + check_sysdecode_cap_rights(fp, &buf, &sz, + &rights, + (const char *[]){ "CAP_KQUEUE_CHANGE", "unknown rights", NULL, }); + + ATF_REQUIRE(fclose(fp) == 0); + free(buf); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, cap_rights); + + return (atf_no_error()); +}