aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--Makefile.inc1185
-rw-r--r--bin/cat/Makefile1
-rw-r--r--bin/cat/tests/Makefile4
-rw-r--r--bin/chflags/Makefile1
-rw-r--r--bin/chio/Makefile1
-rw-r--r--bin/chmod/Makefile1
-rw-r--r--bin/cp/Makefile1
-rw-r--r--bin/csh/Makefile1
-rw-r--r--bin/date/Makefile1
-rw-r--r--bin/date/tests/Makefile4
-rw-r--r--bin/dd/Makefile1
-rw-r--r--bin/dd/tests/Makefile4
-rw-r--r--bin/df/Makefile1
-rw-r--r--bin/domainname/Makefile1
-rw-r--r--bin/echo/Makefile1
-rw-r--r--bin/ed/Makefile1
-rw-r--r--bin/expr/Makefile1
-rw-r--r--bin/expr/tests/Makefile4
-rw-r--r--bin/freebsd-version/Makefile1
-rw-r--r--bin/getfacl/Makefile1
-rw-r--r--bin/hostname/Makefile1
-rw-r--r--bin/kenv/Makefile1
-rw-r--r--bin/kill/Makefile1
-rw-r--r--bin/ln/Makefile1
-rw-r--r--bin/ls/Makefile1
-rw-r--r--bin/ls/tests/Makefile4
-rw-r--r--bin/mkdir/Makefile1
-rw-r--r--bin/mv/Makefile1
-rw-r--r--bin/mv/tests/Makefile4
-rw-r--r--bin/pax/Makefile1
-rw-r--r--bin/pax/tests/Makefile4
-rw-r--r--bin/pkill/Makefile1
-rw-r--r--bin/pkill/tests/Makefile4
-rw-r--r--bin/ps/Makefile1
-rw-r--r--bin/pwait/Makefile1
-rw-r--r--bin/pwd/Makefile1
-rw-r--r--bin/rcp/Makefile3
-rw-r--r--bin/realpath/Makefile1
-rw-r--r--bin/rm/Makefile1
-rw-r--r--bin/rmail/Makefile1
-rw-r--r--bin/rmdir/Makefile1
-rw-r--r--bin/setfacl/Makefile1
-rw-r--r--bin/sh/Makefile1
-rw-r--r--bin/sh/tests/Makefile4
-rw-r--r--bin/sh/tests/builtins/Makefile3
-rw-r--r--bin/sh/tests/errors/Makefile3
-rw-r--r--bin/sh/tests/execution/Makefile3
-rw-r--r--bin/sh/tests/expansion/Makefile3
-rw-r--r--bin/sh/tests/parameters/Makefile3
-rw-r--r--bin/sh/tests/parser/Makefile3
-rw-r--r--bin/sh/tests/set-e/Makefile3
-rw-r--r--bin/sleep/Makefile1
-rw-r--r--bin/sleep/tests/Makefile4
-rw-r--r--bin/stty/Makefile1
-rw-r--r--bin/sync/Makefile1
-rw-r--r--bin/test/Makefile1
-rw-r--r--bin/test/tests/Makefile4
-rw-r--r--bin/tests/Makefile5
-rw-r--r--bin/uuidgen/Makefile1
-rw-r--r--cddl/lib/tests/Makefile5
-rw-r--r--cddl/sbin/tests/Makefile5
-rw-r--r--cddl/tests/Makefile5
-rw-r--r--cddl/usr.bin/tests/Makefile5
-rw-r--r--cddl/usr.sbin/tests/Makefile5
-rw-r--r--contrib/ntp/ntpd/ntp_control.c4
-rw-r--r--etc/Makefile15
-rw-r--r--etc/devd/Makefile9
-rw-r--r--etc/mtree/BSD.var.dist8
-rw-r--r--etc/pam.d/Makefile17
-rw-r--r--etc/periodic/daily/Makefile14
-rw-r--r--etc/periodic/monthly/Makefile8
-rw-r--r--etc/rc.d/Makefile84
-rw-r--r--gnu/lib/libgcc/Makefile1
-rw-r--r--gnu/lib/tests/Makefile5
-rw-r--r--gnu/tests/Makefile5
-rw-r--r--gnu/usr.bin/binutils/Makefile.inc1
-rw-r--r--gnu/usr.bin/diff/tests/Makefile4
-rw-r--r--gnu/usr.bin/gdb/Makefile.inc2
-rw-r--r--gnu/usr.bin/groff/Makefile.inc1
-rw-r--r--gnu/usr.bin/tests/Makefile5
-rw-r--r--include/Makefile84
-rw-r--r--lib/Makefile1
-rw-r--r--lib/atf/libatf-c++/tests/Makefile4
-rw-r--r--lib/atf/libatf-c++/tests/detail/Makefile3
-rw-r--r--lib/atf/libatf-c/tests/Makefile4
-rw-r--r--lib/atf/libatf-c/tests/detail/Makefile5
-rw-r--r--lib/atf/tests/Makefile5
-rw-r--r--lib/atf/tests/test-programs/Makefile4
-rw-r--r--lib/lib80211/Makefile1
-rw-r--r--lib/libalias/libalias/Makefile1
-rw-r--r--lib/libarchive/Makefile1
-rw-r--r--lib/libarchive/tests/Makefile4
-rw-r--r--lib/libauditd/Makefile1
-rw-r--r--lib/libbegemot/Makefile1
-rw-r--r--lib/libblocksruntime/Makefile1
-rw-r--r--lib/libbluetooth/Makefile1
-rw-r--r--lib/libbsdstat/Makefile1
-rw-r--r--lib/libbsm/Makefile1
-rw-r--r--lib/libbsnmp/Makefile.inc1
-rw-r--r--lib/libbz2/Makefile1
-rw-r--r--lib/libc++/Makefile1
-rw-r--r--lib/libc/Makefile1
-rw-r--r--lib/libc/tests/Makefile4
-rw-r--r--lib/libc/tests/c063/Makefile4
-rw-r--r--lib/libc/tests/db/Makefile4
-rw-r--r--lib/libc/tests/gen/Makefile4
-rw-r--r--lib/libc/tests/gen/execve/Makefile4
-rw-r--r--lib/libc/tests/gen/posix_spawn/Makefile4
-rw-r--r--lib/libc/tests/hash/Makefile4
-rw-r--r--lib/libc/tests/inet/Makefile4
-rw-r--r--lib/libc/tests/locale/Makefile4
-rw-r--r--lib/libc/tests/net/Makefile4
-rw-r--r--lib/libc/tests/nss/Makefile4
-rw-r--r--lib/libc/tests/regex/Makefile4
-rw-r--r--lib/libc/tests/resolv/Makefile4
-rw-r--r--lib/libc/tests/rpc/Makefile4
-rw-r--r--lib/libc/tests/setjmp/Makefile4
-rw-r--r--lib/libc/tests/ssp/Makefile4
-rw-r--r--lib/libc/tests/stdio/Makefile4
-rw-r--r--lib/libc/tests/stdlib/Makefile4
-rw-r--r--lib/libc/tests/string/Makefile4
-rw-r--r--lib/libc/tests/sys/Makefile8
-rw-r--r--lib/libc/tests/termios/Makefile4
-rw-r--r--lib/libc/tests/time/Makefile4
-rw-r--r--lib/libc/tests/tls/Makefile4
-rw-r--r--lib/libc/tests/tls/dso/Makefile4
-rw-r--r--lib/libc/tests/tls_dso/Makefile4
-rw-r--r--lib/libc/tests/ttyio/Makefile4
-rw-r--r--lib/libcalendar/Makefile1
-rw-r--r--lib/libcam/Makefile1
-rw-r--r--lib/libcapsicum/Makefile47
-rw-r--r--lib/libcapsicum/Makefile.depend19
-rw-r--r--lib/libcapsicum/libcapsicum.3300
-rw-r--r--lib/libcapsicum/libcapsicum.c266
-rw-r--r--lib/libcapsicum/libcapsicum.h115
-rw-r--r--lib/libcapsicum/libcapsicum_dns.c365
-rw-r--r--lib/libcapsicum/libcapsicum_dns.h57
-rw-r--r--lib/libcapsicum/libcapsicum_grp.c438
-rw-r--r--lib/libcapsicum/libcapsicum_grp.h57
-rw-r--r--lib/libcapsicum/libcapsicum_impl.h39
-rw-r--r--lib/libcapsicum/libcapsicum_pwd.c391
-rw-r--r--lib/libcapsicum/libcapsicum_pwd.h57
-rw-r--r--lib/libcapsicum/libcapsicum_random.c80
-rw-r--r--lib/libcapsicum/libcapsicum_random.h37
-rw-r--r--lib/libcapsicum/libcapsicum_service.c97
-rw-r--r--lib/libcapsicum/libcapsicum_service.h40
-rw-r--r--lib/libcapsicum/libcapsicum_sysctl.c86
-rw-r--r--lib/libcapsicum/libcapsicum_sysctl.h43
-rw-r--r--lib/libcasper/libcasper/Makefile1
-rw-r--r--lib/libcasper/services/cap_dns/Makefile1
-rw-r--r--lib/libcasper/services/cap_grp/Makefile1
-rw-r--r--lib/libcasper/services/cap_pwd/Makefile1
-rw-r--r--lib/libcasper/services/cap_random/Makefile1
-rw-r--r--lib/libcasper/services/cap_sysctl/Makefile1
-rw-r--r--lib/libcom_err/Makefile1
-rw-r--r--lib/libcompat/Makefile1
-rw-r--r--lib/libcompiler_rt/Makefile1
-rw-r--r--lib/libcrypt/Makefile1
-rw-r--r--lib/libcrypt/tests/Makefile4
-rw-r--r--lib/libcuse/Makefile1
-rw-r--r--lib/libcxxrt/Makefile1
-rw-r--r--lib/libdevctl/Makefile1
-rw-r--r--lib/libdevinfo/Makefile1
-rw-r--r--lib/libdevstat/Makefile1
-rw-r--r--lib/libdpv/Makefile1
-rw-r--r--lib/libdwarf/Makefile1
-rw-r--r--lib/libedit/Makefile1
-rw-r--r--lib/libefi/Makefile1
-rw-r--r--lib/libelf/Makefile1
-rw-r--r--lib/libelftc/Makefile1
-rw-r--r--lib/libevent/Makefile1
-rw-r--r--lib/libexecinfo/Makefile1
-rw-r--r--lib/libexpat/Makefile1
-rw-r--r--lib/libfetch/Makefile1
-rw-r--r--lib/libfigpar/Makefile1
-rw-r--r--lib/libgeom/Makefile1
-rw-r--r--lib/libgpio/Makefile1
-rw-r--r--lib/libgssapi/Makefile1
-rw-r--r--lib/libipsec/Makefile1
-rw-r--r--lib/libjail/Makefile3
-rw-r--r--lib/libkiconv/Makefile1
-rw-r--r--lib/libkvm/Makefile1
-rw-r--r--lib/libldns/Makefile1
-rw-r--r--lib/liblzma/Makefile1
-rw-r--r--lib/libmagic/Makefile1
-rw-r--r--lib/libmd/Makefile1
-rw-r--r--lib/libmemstat/Makefile1
-rw-r--r--lib/libmilter/Makefile1
-rw-r--r--lib/libmp/Makefile1
-rw-r--r--lib/libmp/tests/Makefile4
-rw-r--r--lib/libmt/Makefile1
-rw-r--r--lib/libnandfs/Makefile1
-rw-r--r--lib/libnetbsd/Makefile1
-rw-r--r--lib/libnetgraph/Makefile1
-rw-r--r--lib/libngatm/Makefile1
-rw-r--r--lib/libnv/Makefile1
-rw-r--r--lib/libnv/tests/Makefile4
-rw-r--r--lib/libopenbsd/Makefile1
-rw-r--r--lib/libopie/Makefile1
-rw-r--r--lib/libpam/libpam/Makefile1
-rw-r--r--lib/libpam/libpam/tests/Makefile4
-rw-r--r--lib/libpam/modules/pam_ssh/Makefile1
-rw-r--r--lib/libpcap/Makefile1
-rw-r--r--lib/libpjdlog/Makefile1
-rw-r--r--lib/libpmc/Makefile1
-rw-r--r--lib/libproc/Makefile1
-rw-r--r--lib/libproc/tests/Makefile4
-rw-r--r--lib/libprocstat/Makefile1
-rw-r--r--lib/libradius/Makefile1
-rw-r--r--lib/librpcsec_gss/Makefile1
-rw-r--r--lib/librpcsvc/Makefile1
-rw-r--r--lib/librt/Makefile1
-rw-r--r--lib/librt/tests/Makefile4
-rw-r--r--lib/librtld_db/Makefile1
-rw-r--r--lib/libsbuf/Makefile1
-rw-r--r--lib/libsdp/Makefile1
-rw-r--r--lib/libsm/Makefile1
-rw-r--r--lib/libsmb/Makefile1
-rw-r--r--lib/libsmdb/Makefile1
-rw-r--r--lib/libsmutil/Makefile1
-rw-r--r--lib/libsqlite3/Makefile1
-rw-r--r--lib/libstand/Makefile1
-rw-r--r--lib/libstdbuf/Makefile1
-rw-r--r--lib/libstdthreads/Makefile1
-rw-r--r--lib/libsysdecode/Makefile1
-rw-r--r--lib/libtacplus/Makefile1
-rw-r--r--lib/libtelnet/Makefile1
-rw-r--r--lib/libthr/Makefile1
-rw-r--r--lib/libthr/tests/Makefile3
-rw-r--r--lib/libthr/tests/dlopen/Makefile3
-rw-r--r--lib/libthr/tests/dlopen/dso/Makefile4
-rw-r--r--lib/libthread_db/Makefile1
-rw-r--r--lib/libucl/Makefile1
-rw-r--r--lib/libufs/Makefile1
-rw-r--r--lib/libugidfw/Makefile1
-rw-r--r--lib/libulog/Makefile1
-rw-r--r--lib/libunbound/Makefile2
-rw-r--r--lib/libusb/Makefile1
-rw-r--r--lib/libusbhid/Makefile1
-rw-r--r--lib/libutil/Makefile1
-rw-r--r--lib/libutil/tests/Makefile4
-rw-r--r--lib/libvgl/Makefile1
-rw-r--r--lib/libvmmapi/Makefile1
-rw-r--r--lib/libwrap/Makefile1
-rw-r--r--lib/libxo/Makefile1
-rw-r--r--lib/libxo/tests/Makefile4
-rw-r--r--lib/libxo/tests/encoder/Makefile4
-rw-r--r--lib/liby/Makefile1
-rw-r--r--lib/libypclnt/Makefile1
-rw-r--r--lib/libz/Makefile1
-rw-r--r--lib/msun/Makefile1
-rw-r--r--lib/msun/tests/Makefile3
-rw-r--r--lib/ncurses/ncurses/Makefile1
-rw-r--r--lib/tests/Makefile5
-rw-r--r--libexec/atf/atf-check/tests/Makefile4
-rw-r--r--libexec/atf/atf-sh/tests/Makefile5
-rw-r--r--libexec/atf/tests/Makefile5
-rw-r--r--libexec/atrun/Makefile1
-rw-r--r--libexec/casper/Makefile12
-rw-r--r--libexec/casper/dns/Makefile22
-rw-r--r--libexec/casper/dns/Makefile.depend23
-rw-r--r--libexec/casper/dns/dns.c436
-rw-r--r--libexec/casper/grp/Makefile22
-rw-r--r--libexec/casper/grp/Makefile.depend23
-rw-r--r--libexec/casper/grp/grp.c390
-rw-r--r--libexec/casper/pwd/Makefile22
-rw-r--r--libexec/casper/pwd/Makefile.depend23
-rw-r--r--libexec/casper/pwd/pwd.c430
-rw-r--r--libexec/casper/random/Makefile22
-rw-r--r--libexec/casper/random/Makefile.depend23
-rw-r--r--libexec/casper/random/random.c82
-rw-r--r--libexec/casper/sysctl/Makefile22
-rw-r--r--libexec/casper/sysctl/Makefile.depend23
-rw-r--r--libexec/casper/sysctl/sysctl.c249
-rw-r--r--libexec/dma/Makefile.inc1
-rw-r--r--libexec/mail.local/Makefile1
-rw-r--r--libexec/rlogind/Makefile2
-rw-r--r--libexec/rshd/Makefile3
-rw-r--r--libexec/rtld-elf/Makefile4
-rw-r--r--libexec/rtld-elf/tests/Makefile3
-rw-r--r--libexec/rtld-elf/tests/libpythagoras/Makefile4
-rw-r--r--libexec/rtld-elf/tests/target/Makefile4
-rw-r--r--libexec/smrsh/Makefile1
-rw-r--r--libexec/tests/Makefile5
-rw-r--r--release/packages/Makefile.package73
-rw-r--r--release/packages/acct.ucl24
-rw-r--r--release/packages/acpi.ucl24
-rw-r--r--release/packages/amd.ucl24
-rw-r--r--release/packages/apm.ucl24
-rw-r--r--release/packages/at.ucl24
-rw-r--r--release/packages/autofs.ucl24
-rw-r--r--release/packages/bhyve.ucl24
-rw-r--r--release/packages/binutils.ucl24
-rw-r--r--release/packages/bsdinstall.ucl24
-rw-r--r--release/packages/bsnmp.ucl24
-rw-r--r--release/packages/clang.ucl24
-rw-r--r--release/packages/clibs.ucl17
-rw-r--r--release/packages/dma.ucl24
-rw-r--r--release/packages/docs.ucl17
-rw-r--r--release/packages/ee.ucl24
-rw-r--r--release/packages/gdb.ucl24
-rwxr-xr-xrelease/packages/generate-ucl.sh141
-rw-r--r--release/packages/groff.ucl24
-rw-r--r--release/packages/jail.ucl24
-rw-r--r--release/packages/kernel.ucl22
-rw-r--r--release/packages/rcmds.ucl24
-rw-r--r--release/packages/runtime-debug.ucl24
-rw-r--r--release/packages/runtime-development.ucl24
-rw-r--r--release/packages/runtime-lib32.ucl24
-rw-r--r--release/packages/runtime-manuals.ucl24
-rw-r--r--release/packages/runtime-profile.ucl24
-rw-r--r--release/packages/runtime.ucl29
-rw-r--r--release/packages/ssh.ucl24
-rw-r--r--release/packages/svn.ucl24
-rw-r--r--release/packages/syscons.ucl24
-rw-r--r--release/packages/template.ucl17
-rw-r--r--release/packages/tests.ucl24
-rw-r--r--release/packages/unbound.ucl24
-rw-r--r--release/packages/vi.ucl24
-rwxr-xr-xrelease/scripts/make-pkg-package.sh25
-rw-r--r--release/scripts/mtree-to-plist.awk80
-rw-r--r--rescue/librescue/Makefile1
-rw-r--r--rescue/rescue/Makefile1
-rw-r--r--sbin/adjkerntz/Makefile1
-rw-r--r--sbin/atm/atmconfig/Makefile1
-rw-r--r--sbin/badsect/Makefile1
-rw-r--r--sbin/bsdlabel/Makefile1
-rw-r--r--sbin/camcontrol/Makefile1
-rw-r--r--sbin/casperd/Makefile18
-rw-r--r--sbin/ccdconfig/Makefile1
-rw-r--r--sbin/clri/Makefile1
-rw-r--r--sbin/comcontrol/Makefile1
-rw-r--r--sbin/conscontrol/Makefile1
-rw-r--r--sbin/ddb/Makefile1
-rw-r--r--sbin/devd/Makefile1
-rw-r--r--sbin/devd/tests/Makefile4
-rw-r--r--sbin/devfs/Makefile1
-rw-r--r--sbin/dhclient/Makefile1
-rw-r--r--sbin/dhclient/tests/Makefile4
-rw-r--r--sbin/dmesg/Makefile1
-rw-r--r--sbin/dump/Makefile1
-rw-r--r--sbin/dumpfs/Makefile1
-rw-r--r--sbin/dumpon/Makefile1
-rw-r--r--sbin/etherswitchcfg/Makefile1
-rw-r--r--sbin/fdisk/Makefile1
-rw-r--r--sbin/fdisk_pc98/Makefile1
-rw-r--r--sbin/ffsinfo/Makefile1
-rw-r--r--sbin/fsck/Makefile1
-rw-r--r--sbin/fsck_ffs/Makefile1
-rw-r--r--sbin/fsck_msdosfs/Makefile1
-rw-r--r--sbin/fsdb/Makefile1
-rw-r--r--sbin/fsirand/Makefile1
-rw-r--r--sbin/gbde/Makefile1
-rw-r--r--sbin/geom/Makefile1
-rw-r--r--sbin/geom/class/cache/Makefile1
-rw-r--r--sbin/geom/class/concat/Makefile1
-rw-r--r--sbin/geom/class/eli/Makefile1
-rw-r--r--sbin/geom/class/journal/Makefile1
-rw-r--r--sbin/geom/class/label/Makefile1
-rw-r--r--sbin/geom/class/mirror/Makefile1
-rw-r--r--sbin/geom/class/mountver/Makefile1
-rw-r--r--sbin/geom/class/multipath/Makefile1
-rw-r--r--sbin/geom/class/nop/Makefile1
-rw-r--r--sbin/geom/class/part/Makefile1
-rw-r--r--sbin/geom/class/raid/Makefile1
-rw-r--r--sbin/geom/class/raid3/Makefile1
-rw-r--r--sbin/geom/class/sched/Makefile1
-rw-r--r--sbin/geom/class/shsec/Makefile1
-rw-r--r--sbin/geom/class/stripe/Makefile1
-rw-r--r--sbin/geom/class/virstor/Makefile1
-rw-r--r--sbin/geom/core/Makefile1
-rw-r--r--sbin/growfs/Makefile1
-rw-r--r--sbin/growfs/tests/Makefile4
-rw-r--r--sbin/gvinum/Makefile1
-rw-r--r--sbin/hastctl/Makefile1
-rw-r--r--sbin/hastd/Makefile1
-rw-r--r--sbin/ifconfig/Makefile1
-rw-r--r--sbin/ifconfig/tests/Makefile4
-rw-r--r--sbin/init/Makefile1
-rw-r--r--sbin/ipf/ipf/Makefile1
-rw-r--r--sbin/ipf/ipfs/Makefile1
-rw-r--r--sbin/ipf/ipfstat/Makefile1
-rw-r--r--sbin/ipf/ipftest/Makefile1
-rw-r--r--sbin/ipf/ipmon/Makefile1
-rw-r--r--sbin/ipf/ipnat/Makefile1
-rw-r--r--sbin/ipf/ippool/Makefile1
-rw-r--r--sbin/ipf/ipresend/Makefile1
-rw-r--r--sbin/ipf/libipf/Makefile1
-rw-r--r--sbin/ipfw/Makefile1
-rw-r--r--sbin/iscontrol/Makefile1
-rw-r--r--sbin/kldconfig/Makefile1
-rw-r--r--sbin/kldload/Makefile1
-rw-r--r--sbin/kldstat/Makefile1
-rw-r--r--sbin/kldunload/Makefile1
-rw-r--r--sbin/ldconfig/Makefile1
-rw-r--r--sbin/md5/Makefile1
-rw-r--r--sbin/mdconfig/Makefile1
-rw-r--r--sbin/mdconfig/tests/Makefile4
-rw-r--r--sbin/mdmfs/Makefile1
-rw-r--r--sbin/mknod/Makefile1
-rw-r--r--sbin/mksnap_ffs/Makefile1
-rw-r--r--sbin/mount/Makefile1
-rw-r--r--sbin/mount_cd9660/Makefile1
-rw-r--r--sbin/mount_fusefs/Makefile1
-rw-r--r--sbin/mount_msdosfs/Makefile1
-rw-r--r--sbin/mount_nfs/Makefile1
-rw-r--r--sbin/mount_nullfs/Makefile1
-rw-r--r--sbin/mount_udf/Makefile1
-rw-r--r--sbin/mount_unionfs/Makefile1
-rw-r--r--sbin/nandfs/Makefile1
-rw-r--r--sbin/natd/Makefile1
-rw-r--r--sbin/newfs_msdos/Makefile1
-rw-r--r--sbin/newfs_nandfs/Makefile1
-rw-r--r--sbin/nfsiod/Makefile1
-rw-r--r--sbin/nos-tun/Makefile1
-rw-r--r--sbin/nvmecontrol/Makefile1
-rw-r--r--sbin/pfctl/Makefile1
-rw-r--r--sbin/pflogd/Makefile1
-rw-r--r--sbin/ping/Makefile1
-rw-r--r--sbin/ping6/Makefile1
-rw-r--r--sbin/quotacheck/Makefile1
-rw-r--r--sbin/rcorder/Makefile1
-rw-r--r--sbin/reboot/Makefile1
-rw-r--r--sbin/recoverdisk/Makefile1
-rw-r--r--sbin/resolvconf/Makefile1
-rw-r--r--sbin/restore/Makefile1
-rw-r--r--sbin/route/Makefile1
-rw-r--r--sbin/routed/Makefile1
-rw-r--r--sbin/routed/rtquery/Makefile1
-rw-r--r--sbin/rtsol/Makefile1
-rw-r--r--sbin/savecore/Makefile1
-rw-r--r--sbin/sconfig/Makefile1
-rw-r--r--sbin/setkey/Makefile1
-rw-r--r--sbin/shutdown/Makefile1
-rw-r--r--sbin/swapon/Makefile1
-rw-r--r--sbin/sysctl/Makefile1
-rw-r--r--sbin/tests/Makefile5
-rw-r--r--sbin/tunefs/Makefile1
-rw-r--r--sbin/umount/Makefile1
-rw-r--r--secure/lib/libssh/Makefile1
-rw-r--r--secure/lib/tests/Makefile5
-rw-r--r--secure/libexec/Makefile.inc1
-rw-r--r--secure/libexec/tests/Makefile5
-rw-r--r--secure/tests/Makefile5
-rw-r--r--secure/usr.bin/scp/Makefile1
-rw-r--r--secure/usr.bin/sftp/Makefile1
-rw-r--r--secure/usr.bin/ssh-add/Makefile1
-rw-r--r--secure/usr.bin/ssh-agent/Makefile1
-rw-r--r--secure/usr.bin/ssh-keygen/Makefile1
-rw-r--r--secure/usr.bin/ssh-keyscan/Makefile1
-rw-r--r--secure/usr.bin/ssh/Makefile1
-rw-r--r--secure/usr.bin/tests/Makefile5
-rw-r--r--secure/usr.sbin/sshd/Makefile1
-rw-r--r--secure/usr.sbin/tests/Makefile5
-rw-r--r--share/examples/Makefile3
-rw-r--r--share/examples/tests/Makefile5
-rw-r--r--share/examples/tests/tests/Makefile4
-rw-r--r--share/examples/tests/tests/atf/Makefile5
-rw-r--r--share/examples/tests/tests/plain/Makefile5
-rw-r--r--share/man/man1/Makefile2
-rw-r--r--share/man/man3/Makefile2
-rw-r--r--share/man/man4/Makefile2
-rw-r--r--share/man/man4/man4.arm/Makefile2
-rw-r--r--share/man/man4/man4.i386/Makefile2
-rw-r--r--share/man/man4/man4.powerpc/Makefile2
-rw-r--r--share/man/man4/man4.sparc64/Makefile2
-rw-r--r--share/man/man5/Makefile2
-rw-r--r--share/man/man6/Makefile2
-rw-r--r--share/man/man7/Makefile2
-rw-r--r--share/man/man8/Makefile2
-rw-r--r--share/man/man9/Makefile2
-rw-r--r--share/mk/bsd.doc.mk11
-rw-r--r--share/mk/bsd.files.mk14
-rw-r--r--share/mk/bsd.incs.mk14
-rw-r--r--share/mk/bsd.lib.mk43
-rw-r--r--share/mk/bsd.links.mk13
-rw-r--r--share/mk/bsd.man.mk5
-rw-r--r--share/mk/bsd.prog.mk15
-rw-r--r--share/mk/bsd.test.mk1
-rw-r--r--share/sendmail/Makefile1
-rw-r--r--share/syscons/Makefile.inc3
-rw-r--r--share/tests/Makefile4
-rw-r--r--sys/conf/kmod.mk4
-rw-r--r--sys/modules/tests/callout_test/Makefile4
-rw-r--r--sys/modules/tests/framework/Makefile4
-rw-r--r--tests/Makefile5
-rw-r--r--tests/etc/Makefile5
-rw-r--r--tests/etc/rc.d/Makefile3
-rw-r--r--tests/sys/Makefile3
-rw-r--r--tests/sys/acl/Makefile3
-rw-r--r--tests/sys/aio/Makefile3
-rw-r--r--tests/sys/fifo/Makefile3
-rw-r--r--tests/sys/file/Makefile3
-rw-r--r--tests/sys/geom/Makefile3
-rw-r--r--tests/sys/geom/class/Makefile3
-rw-r--r--tests/sys/geom/class/concat/Makefile4
-rw-r--r--tests/sys/geom/class/eli/Makefile4
-rw-r--r--tests/sys/geom/class/gate/Makefile4
-rw-r--r--tests/sys/geom/class/mirror/Makefile4
-rw-r--r--tests/sys/geom/class/nop/Makefile4
-rw-r--r--tests/sys/geom/class/raid3/Makefile4
-rw-r--r--tests/sys/geom/class/shsec/Makefile4
-rw-r--r--tests/sys/geom/class/stripe/Makefile4
-rw-r--r--tests/sys/geom/class/uzip/Makefile7
-rw-r--r--tests/sys/kern/Makefile3
-rw-r--r--tests/sys/kern/acct/Makefile3
-rw-r--r--tests/sys/kern/execve/Makefile3
-rw-r--r--tests/sys/kern/pipe/Makefile3
-rw-r--r--tests/sys/kqueue/Makefile3
-rw-r--r--tests/sys/mac/Makefile3
-rw-r--r--tests/sys/mac/bsdextended/Makefile3
-rw-r--r--tests/sys/mac/portacl/Makefile3
-rw-r--r--tests/sys/mqueue/Makefile3
-rw-r--r--tests/sys/netinet/Makefile3
-rw-r--r--tests/sys/opencrypto/Makefile3
-rw-r--r--tests/sys/pjdfstest/Makefile3
-rw-r--r--tests/sys/pjdfstest/pjdfstest/Makefile3
-rw-r--r--tests/sys/pjdfstest/tests/Makefile3
-rw-r--r--tests/sys/pjdfstest/tests/chflags/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/chmod/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/chown/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/ftruncate/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/granular/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/link/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/mkdir/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/mkfifo/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/mknod/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/open/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/rename/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/rmdir/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/symlink/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/truncate/Makefile4
-rw-r--r--tests/sys/pjdfstest/tests/unlink/Makefile4
-rw-r--r--tests/sys/posixshm/Makefile3
-rw-r--r--tests/sys/vfs/Makefile3
-rw-r--r--tests/sys/vm/Makefile3
-rw-r--r--usr.bin/apply/tests/Makefile4
-rw-r--r--usr.bin/at/Makefile.inc1
-rw-r--r--usr.bin/basename/tests/Makefile4
-rw-r--r--usr.bin/bmake/tests/Makefile3
-rw-r--r--usr.bin/bmake/tests/archives/Makefile3
-rw-r--r--usr.bin/bmake/tests/archives/fmt_44bsd/Makefile3
-rw-r--r--usr.bin/bmake/tests/archives/fmt_44bsd_mod/Makefile3
-rw-r--r--usr.bin/bmake/tests/archives/fmt_oldbsd/Makefile3
-rw-r--r--usr.bin/bmake/tests/basic/Makefile3
-rw-r--r--usr.bin/bmake/tests/basic/t0/Makefile3
-rw-r--r--usr.bin/bmake/tests/basic/t1/Makefile3
-rw-r--r--usr.bin/bmake/tests/basic/t2/Makefile3
-rw-r--r--usr.bin/bmake/tests/basic/t3/Makefile3
-rw-r--r--usr.bin/bmake/tests/execution/Makefile3
-rw-r--r--usr.bin/bmake/tests/execution/ellipsis/Makefile3
-rw-r--r--usr.bin/bmake/tests/execution/empty/Makefile3
-rw-r--r--usr.bin/bmake/tests/execution/joberr/Makefile3
-rw-r--r--usr.bin/bmake/tests/execution/plus/Makefile3
-rw-r--r--usr.bin/bmake/tests/shell/Makefile3
-rw-r--r--usr.bin/bmake/tests/shell/builtin/Makefile3
-rw-r--r--usr.bin/bmake/tests/shell/meta/Makefile3
-rw-r--r--usr.bin/bmake/tests/shell/path/Makefile3
-rw-r--r--usr.bin/bmake/tests/shell/path_select/Makefile3
-rw-r--r--usr.bin/bmake/tests/shell/replace/Makefile3
-rw-r--r--usr.bin/bmake/tests/shell/select/Makefile3
-rw-r--r--usr.bin/bmake/tests/suffixes/Makefile3
-rw-r--r--usr.bin/bmake/tests/suffixes/basic/Makefile3
-rw-r--r--usr.bin/bmake/tests/suffixes/src_wild1/Makefile3
-rw-r--r--usr.bin/bmake/tests/suffixes/src_wild2/Makefile3
-rw-r--r--usr.bin/bmake/tests/syntax/Makefile3
-rw-r--r--usr.bin/bmake/tests/syntax/directive-t0/Makefile3
-rw-r--r--usr.bin/bmake/tests/syntax/enl/Makefile3
-rw-r--r--usr.bin/bmake/tests/syntax/funny-targets/Makefile3
-rw-r--r--usr.bin/bmake/tests/syntax/semi/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/t0/2/1/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/t0/2/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/t0/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/t0/mk/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/t1/2/1/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/t1/2/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/t1/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/t1/mk/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/t2/2/1/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/t2/2/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/t2/Makefile3
-rw-r--r--usr.bin/bmake/tests/sysmk/t2/mk/Makefile3
-rw-r--r--usr.bin/bmake/tests/variables/Makefile3
-rw-r--r--usr.bin/bmake/tests/variables/modifier_M/Makefile3
-rw-r--r--usr.bin/bmake/tests/variables/modifier_t/Makefile3
-rw-r--r--usr.bin/bmake/tests/variables/opt_V/Makefile3
-rw-r--r--usr.bin/bmake/tests/variables/t0/Makefile3
-rw-r--r--usr.bin/calendar/tests/Makefile3
-rw-r--r--usr.bin/chpass/Makefile16
-rw-r--r--usr.bin/clang/clang.prog.mk2
-rw-r--r--usr.bin/cmp/tests/Makefile4
-rw-r--r--usr.bin/col/tests/Makefile4
-rw-r--r--usr.bin/comm/tests/Makefile4
-rw-r--r--usr.bin/cpio/tests/Makefile4
-rw-r--r--usr.bin/cut/tests/Makefile4
-rw-r--r--usr.bin/dirname/tests/Makefile4
-rw-r--r--usr.bin/ee/Makefile1
-rw-r--r--usr.bin/file2c/tests/Makefile4
-rw-r--r--usr.bin/grep/tests/Makefile4
-rw-r--r--usr.bin/gzip/tests/Makefile4
-rw-r--r--usr.bin/ident/tests/Makefile4
-rw-r--r--usr.bin/iscsictl/Makefile1
-rw-r--r--usr.bin/join/tests/Makefile4
-rw-r--r--usr.bin/jot/tests/Makefile4
-rw-r--r--usr.bin/lastcomm/Makefile2
-rw-r--r--usr.bin/lastcomm/tests/Makefile4
-rw-r--r--usr.bin/limits/tests/Makefile4
-rw-r--r--usr.bin/m4/tests/Makefile4
-rw-r--r--usr.bin/mkimg/tests/Makefile4
-rw-r--r--usr.bin/ncal/tests/Makefile4
-rw-r--r--usr.bin/passwd/Makefile8
-rw-r--r--usr.bin/printf/tests/Makefile4
-rw-r--r--usr.bin/rlogin/Makefile2
-rw-r--r--usr.bin/rsh/Makefile2
-rw-r--r--usr.bin/ruptime/Makefile2
-rw-r--r--usr.bin/rwho/Makefile2
-rw-r--r--usr.bin/sed/tests/Makefile4
-rw-r--r--usr.bin/sed/tests/regress.multitest.out/Makefile3
-rw-r--r--usr.bin/soelim/tests/Makefile4
-rw-r--r--usr.bin/ssh-copy-id/Makefile1
-rw-r--r--usr.bin/svn/Makefile.inc2
-rw-r--r--usr.bin/tar/tests/Makefile4
-rw-r--r--usr.bin/tests/Makefile5
-rw-r--r--usr.bin/timeout/tests/Makefile3
-rw-r--r--usr.bin/tr/tests/Makefile3
-rw-r--r--usr.bin/truncate/tests/Makefile4
-rw-r--r--usr.bin/units/tests/Makefile4
-rw-r--r--usr.bin/uudecode/tests/Makefile4
-rw-r--r--usr.bin/uuencode/tests/Makefile4
-rw-r--r--usr.bin/vi/Makefile1
-rw-r--r--usr.bin/vi/catalog/Makefile5
-rw-r--r--usr.bin/xargs/tests/Makefile4
-rw-r--r--usr.bin/xo/tests/Makefile4
-rw-r--r--usr.bin/yacc/tests/Makefile10
-rw-r--r--usr.sbin/accton/Makefile2
-rw-r--r--usr.sbin/acpi/Makefile.inc2
-rw-r--r--usr.sbin/amd/Makefile.inc2
-rw-r--r--usr.sbin/apm/Makefile2
-rw-r--r--usr.sbin/apmd/Makefile2
-rw-r--r--usr.sbin/autofs/Makefile1
-rw-r--r--usr.sbin/bhyve/Makefile1
-rw-r--r--usr.sbin/bhyvectl/Makefile1
-rw-r--r--usr.sbin/bhyveload/Makefile1
-rw-r--r--usr.sbin/bsdinstall/Makefile1
-rw-r--r--usr.sbin/bsdinstall/Makefile.inc1
-rw-r--r--usr.sbin/bsnmpd/Makefile.inc1
-rw-r--r--usr.sbin/bsnmpd/modules/Makefile.inc1
-rw-r--r--usr.sbin/bsnmpd/tools/Makefile.inc1
-rw-r--r--usr.sbin/chown/tests/Makefile4
-rw-r--r--usr.sbin/etcupdate/tests/Makefile4
-rw-r--r--usr.sbin/fstyp/tests/Makefile4
-rw-r--r--usr.sbin/iscsid/Makefile1
-rw-r--r--usr.sbin/jail/Makefile2
-rw-r--r--usr.sbin/jexec/Makefile2
-rw-r--r--usr.sbin/jls/Makefile2
-rw-r--r--usr.sbin/makefs/tests/Makefile4
-rw-r--r--usr.sbin/newsyslog/tests/Makefile4
-rw-r--r--usr.sbin/nmtree/tests/Makefile4
-rw-r--r--usr.sbin/pw/tests/Makefile4
-rw-r--r--usr.sbin/rpcbind/tests/Makefile4
-rw-r--r--usr.sbin/rwhod/Makefile2
-rw-r--r--usr.sbin/sa/Makefile2
-rw-r--r--usr.sbin/sa/tests/Makefile4
-rw-r--r--usr.sbin/sendmail/Makefile1
-rw-r--r--usr.sbin/tests/Makefile5
-rw-r--r--usr.sbin/unbound/Makefile.inc1
668 files changed, 7225 insertions, 129 deletions
diff --git a/Makefile b/Makefile
index a80dec9b3470..d18eedef01b4 100644
--- a/Makefile
+++ b/Makefile
@@ -126,7 +126,9 @@ TGTS= all all-man buildenv buildenvvars buildkernel buildworld \
_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
_build-tools _cross-tools _includes _libraries _depend \
build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
- xdev-links native-xtools installconfig \
+ xdev-links native-xtools stageworld stagekernel stage-packages \
+ create-world-packages create-kernel-packages create-packages \
+ packages installconfig real-packages sign-packages package-pkg
TGTS+= ${SUBDIR_TARGETS}
diff --git a/Makefile.inc1 b/Makefile.inc1
index 85e1a60876c3..40bc9fe5b1a9 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -188,6 +188,21 @@ VERSION= FreeBSD ${REVISION}-${BRANCH:C/-p[0-9]+$//} ${TARGET_ARCH} ${SRCRELDATE
.export VERSION
.endif
+.if !defined(PKG_VERSION)
+REVISION!= ${MAKE} -C ${SRCDIR}/release -V REVISION
+BRANCH!= ${MAKE} -C ${SRCDIR}/release -V BRANCH
+SRCRELDATE!= awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \
+ ${SRCDIR}/sys/sys/param.h
+.if ${BRANCH:MSTABLE*} || ${BRANCH:MCURRENT*}
+TIMENOW= %Y%m%d%H%M%S
+EXTRA_REVISION= .s${TIMENOW:gmtime}
+.endif
+.if ${BRANCH:M*-p*}
+EXTRA_REVISION= _${BRANCH:C/.*-p([0-9]+$)/\1/}
+.endif
+PKG_VERSION= ${REVISION}${EXTRA_REVISION}
+.endif
+
KNOWN_ARCHES?= aarch64/arm64 \
amd64 \
arm \
@@ -256,10 +271,15 @@ TMPPATH= ${STRICTTMPPATH}:${PATH}
# It may not be functional, e.g., due to new ABI
# when in the middle of installing over this system.
#
-.if make(distributeworld) || make(installworld)
+.if make(distributeworld) || make(installworld) || make(stageworld)
INSTALLTMP!= /usr/bin/mktemp -d -u -t install
.endif
+.if make(stagekernel) || make(distributekernel)
+TAGS+= kernel
+PACKAGE= kernel
+.endif
+
#
# Building a world goes through the following stages
#
@@ -542,6 +562,9 @@ IMAKE+= -DNO_ROOT METALOG=${METALOG}
INSTALLFLAGS+= -U -M ${METALOG} -D ${INSTALL_DDIR}
MTREEFLAGS+= -W
.endif
+.if defined(BUILD_PKGS)
+INSTALLFLAGS+= -h sha256
+.endif
.if defined(DB_FROM_SRC) || defined(NO_ROOT)
IMAKE_INSTALL= INSTALL="install ${INSTALLFLAGS}"
IMAKE_MTREE= MTREE_CMD="mtree ${MTREEFLAGS}"
@@ -933,7 +956,7 @@ DEBUG_DISTRIBUTIONS+= base ${EXTRA_DISTRIBUTIONS:S,doc,,:S,tests,,}
MTREE_MAGIC?= mtree 2.0
-distributeworld installworld: _installcheck_world
+distributeworld installworld stageworld: _installcheck_world
mkdir -p ${INSTALLTMP}
progs=$$(for prog in ${ITOOLS}; do \
if progpath=`which $$prog`; then \
@@ -1086,6 +1109,21 @@ reinstall: .MAKE .PHONY
${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
.endif
+restage: .MAKE .PHONY
+ @echo "--------------------------------------------------------------"
+ @echo ">>> Making hierarchy"
+ @echo "--------------------------------------------------------------"
+ ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 \
+ LOCAL_MTREE=${LOCAL_MTREE:Q} hierarchy distribution
+ @echo
+ @echo "--------------------------------------------------------------"
+ @echo ">>> Installing everything"
+ @echo "--------------------------------------------------------------"
+ ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install
+.if defined(LIB32TMP) && ${MK_LIB32} != "no"
+ ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32
+.endif
+
redistribute: .MAKE .PHONY
@echo "--------------------------------------------------------------"
@echo ">>> Distributing everything"
@@ -1259,7 +1297,7 @@ distributekernel distributekernel.debug:
.endif
mkdir -p ${DESTDIR}/${DISTDIR}
.if defined(NO_ROOT)
- echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
+ @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.premeta
.endif
cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \
${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.premeta/} \
@@ -1267,14 +1305,14 @@ distributekernel distributekernel.debug:
DESTDIR=${INSTALL_DDIR}/kernel \
${.TARGET:S/distributekernel/install/}
.if defined(NO_ROOT)
- sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
+ @sed -e 's|^./kernel|.|' ${DESTDIR}/${DISTDIR}/kernel.premeta > \
${DESTDIR}/${DISTDIR}/kernel.meta
.endif
.endif
.if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS)
.for _kernel in ${BUILDKERNELS:[2..-1]}
.if defined(NO_ROOT)
- echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
+ @echo "#${MTREE_MAGIC}" > ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta
.endif
cd ${KRNLOBJDIR}/${_kernel}; \
${IMAKEENV} ${IMAKE_INSTALL:S/METALOG/kernel.${_kernel}.premeta/} \
@@ -1283,7 +1321,7 @@ distributekernel distributekernel.debug:
DESTDIR=${INSTALL_DDIR}/kernel.${_kernel} \
${.TARGET:S/distributekernel/install/}
.if defined(NO_ROOT)
- sed -e 's|^./kernel|.|' \
+ @sed -e "s|^./kernel.${_kernel}|.|" \
${DESTDIR}/${DISTDIR}/kernel.${_kernel}.premeta > \
${DESTDIR}/${DISTDIR}/kernel.${_kernel}.meta
.endif
@@ -1335,6 +1373,141 @@ packagekernel:
.endif
.endif
+stagekernel:
+ ${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} distributekernel
+
+PORTSDIR?= /usr/ports
+WSTAGEDIR= ${MAKEOBJDIRPREFIX}${.CURDIR}/${TARGET}.${TARGET_ARCH}/worldstage
+KSTAGEDIR= ${MAKEOBJDIRPREFIX}${.CURDIR}/${TARGET}.${TARGET_ARCH}/kernelstage
+REPODIR= ${MAKEOBJDIRPREFIX}${.CURDIR}/repo
+PKGSIGNKEY?= # empty
+
+_pkgbootstrap:
+.if !exists(${LOCALBASE}/sbin/pkg)
+ @env ASSUME_ALWAYS_YES=YES pkg bootstrap
+.endif
+
+packages:
+ ${MAKE} -C ${.CURDIR} PKG_VERSION=${PKG_VERSION} real-packages
+
+package-pkg:
+ rm -rf /tmp/ports.${TARGET} || :
+ env ${WMAKEENV:Q} SRCDIR=${.CURDIR} PORTSDIR=${PORTSDIR} REVISION=${REVISION} \
+ PKG_VERSION=${PKG_VERSION} REPODIR=${REPODIR} WSTAGEDIR=${WSTAGEDIR} \
+ sh ${.CURDIR}/release/scripts/make-pkg-package.sh
+
+real-packages: stage-packages create-packages sign-packages
+
+stage-packages:
+ @mkdir -p ${WSTAGEDIR} ${KSTAGEDIR}
+ ${_+_}@cd ${.CURDIR}; \
+ ${MAKE} DESTDIR=${DESTDIR:U${WSTAGEDIR}} -DNO_ROOT -B stageworld ; \
+ ${MAKE} DESTDIR=${DESTDIR:U${KSTAGEDIR}} -DNO_ROOT -B stagekernel
+
+create-packages: _pkgbootstrap
+ @mkdir -p ${REPODIR}
+ ${_+_}@cd ${.CURDIR}; \
+ ${MAKE} DESTDIR=${DESTDIR:U${WSTAGEDIR}} \
+ PKG_VERSION=${PKG_VERSION} create-world-packages ; \
+ ${MAKE} DESTDIR=${DESTDIR:U${KSTAGEDIR}} \
+ PKG_VERSION=${PKG_VERSION} DISTDIR=kernel \
+ create-kernel-packages
+
+create-world-packages: _pkgbootstrap
+ @rm -f ${DESTDIR}/*.plist 2>/dev/null || :
+ @cd ${DESTDIR} ; \
+ awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
+ ${DESTDIR}/METALOG
+ @for plist in ${DESTDIR}/*.plist; do \
+ plist=$${plist##*/} ; \
+ pkgname=$${plist%.plist} ; \
+ sh ${SRCDIR}/release/packages/generate-ucl.sh -o $${pkgname} \
+ -s ${SRCDIR} -u ${DESTDIR}/$${pkgname}.ucl ; \
+ done
+ @for plist in ${DESTDIR}/*.plist; do \
+ plist=$${plist##*/} ; \
+ pkgname=$${plist%.plist} ; \
+ awk -F\" ' \
+ /^name/ { printf("===> Creating %s-", $$2); next } \
+ /^version/ { print $$2; next } \
+ ' ${DESTDIR}/$${pkgname}.ucl ; \
+ pkg -o ABI_FILE=${DESTDIR}/bin/sh -o ALLOW_BASE_SHLIBS=yes \
+ create -M ${DESTDIR}/$${pkgname}.ucl \
+ -p ${DESTDIR}/$${pkgname}.plist \
+ -r ${DESTDIR} \
+ -o ${REPODIR}/$$(pkg -o ABI_FILE=${DESTDIR}/bin/sh config ABI)/${PKG_VERSION} ; \
+ done
+
+create-kernel-packages: _pkgbootstrap
+.if exists(${DESTDIR}/kernel.meta)
+.for flavor in "" -debug
+ @cd ${DESTDIR}/${DISTDIR} ; \
+ awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
+ -v kernel=yes -v _kernconf=${INSTALLKERNEL} \
+ ${DESTDIR}/kernel.meta ; \
+ cap_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VCAP_MKDB_ENDIAN` ; \
+ pwd_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VPWD_MKDB_ENDIAN` ; \
+ sed -e "s/%VERSION%/${PKG_VERSION}/" \
+ -e "s/%PKGNAME%/kernel-${INSTALLKERNEL:tl}${flavor}/" \
+ -e "s/%COMMENT%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
+ -e "s/%DESC%/FreeBSD ${INSTALLKERNEL} kernel ${flavor}/" \
+ -e "s/%CAP_MKDB_ENDIAN%/$${cap_arg}/g" \
+ -e "s/%PWD_MKDB_ENDIAN%/$${pwd_arg}/g" \
+ ${SRCDIR}/release/packages/kernel.ucl \
+ > ${DESTDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
+ awk -F\" ' \
+ /name/ { printf("===> Creating %s-", $$2); next } \
+ /version/ {print $$2; next } ' \
+ ${DESTDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl ; \
+ pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh -o ALLOW_BASE_SHLIBS=yes \
+ create -M ${DESTDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.ucl \
+ -p ${DESTDIR}/${DISTDIR}/kernel.${INSTALLKERNEL}${flavor}.plist \
+ -r ${DESTDIR}/${DISTDIR} \
+ -o ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION}
+.endfor
+.endif
+.if ${BUILDKERNELS:[#]} > 1 && !defined(NO_INSTALLEXTRAKERNELS)
+.for _kernel in ${BUILDKERNELS:[2..-1]}
+.if exists(${DESTDIR}/kernel.${_kernel}.meta)
+.for flavor in "" -debug
+ @cd ${DESTDIR}/kernel.${_kernel} ; \
+ awk -f ${SRCDIR}/release/scripts/mtree-to-plist.awk \
+ -v kernel=yes -v _kernconf=${_kernel} \
+ ${DESTDIR}/kernel.${_kernel}.meta ; \
+ cap_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VCAP_MKDB_ENDIAN` ; \
+ pwd_arg=`cd ${SRCDIR}/etc ; ${MAKE} -VPWD_MKDB_ENDIAN` ; \
+ sed -e "s/%VERSION%/${PKG_VERSION}/" \
+ -e "s/%PKGNAME%/kernel-${_kernel:tl}${flavor}/" \
+ -e "s/%COMMENT%/FreeBSD ${_kernel} kernel ${flavor}/" \
+ -e "s/%DESC%/FreeBSD ${_kernel} kernel ${flavor}/" \
+ -e "s/%CAP_MKDB_ENDIAN%/$${cap_arg}/g" \
+ -e "s/%PWD_MKDB_ENDIAN%/$${pwd_arg}/g" \
+ ${SRCDIR}/release/packages/kernel.ucl \
+ > ${DESTDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
+ awk -F\" ' \
+ /name/ { printf("===> Creating %s-", $$2); next } \
+ /version/ {print $$2; next } ' \
+ ${DESTDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl ; \
+ pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh -o ALLOW_BASE_SHLIBS=yes \
+ create -M ${DESTDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.ucl \
+ -p ${DESTDIR}/kernel.${_kernel}/kernel.${_kernel}${flavor}.plist \
+ -r ${DESTDIR}/kernel.${_kernel} \
+ -o ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION}
+.endfor
+.endif
+.endfor
+.endif
+
+sign-packages: _pkgbootstrap
+ @[ -L "${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/latest" ] && \
+ unlink ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/latest ; \
+ pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh repo \
+ -o ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} \
+ ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} \
+ ${PKGSIGNKEY} ; \
+ ln -s ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION} \
+ ${REPODIR}/$$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/latest
+
#
#
# checkworld
diff --git a/bin/cat/Makefile b/bin/cat/Makefile
index 97e5812e4bf2..39aaeeb4a50f 100644
--- a/bin/cat/Makefile
+++ b/bin/cat/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= cat
.if ${MK_TESTS} != "no"
diff --git a/bin/cat/tests/Makefile b/bin/cat/tests/Makefile
index f68513ce683b..effd8393d889 100644
--- a/bin/cat/tests/Makefile
+++ b/bin/cat/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_SH= cat_test
FILESDIR= ${TESTSDIR}
diff --git a/bin/chflags/Makefile b/bin/chflags/Makefile
index 4457505380f3..db9defdcded3 100644
--- a/bin/chflags/Makefile
+++ b/bin/chflags/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
# $FreeBSD$
+PACKAGE=runtime
PROG= chflags
.include <bsd.prog.mk>
diff --git a/bin/chio/Makefile b/bin/chio/Makefile
index 5157f6568a6c..ddb07d968129 100644
--- a/bin/chio/Makefile
+++ b/bin/chio/Makefile
@@ -1,6 +1,7 @@
# $FreeBSD$
# @(#)Makefile 8.1 (Berkeley) 6/6/93
+PACKAGE=runtime
PROG= chio
.include <bsd.prog.mk>
diff --git a/bin/chmod/Makefile b/bin/chmod/Makefile
index 71006d00a523..58b1afc0aff1 100644
--- a/bin/chmod/Makefile
+++ b/bin/chmod/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=runtime
PROG= chmod
.include <bsd.prog.mk>
diff --git a/bin/cp/Makefile b/bin/cp/Makefile
index 5a5e1a457d16..d20f60e537d3 100644
--- a/bin/cp/Makefile
+++ b/bin/cp/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=runtime
PROG= cp
SRCS= cp.c utils.c
CFLAGS+= -DVM_AND_BUFFER_CACHE_SYNCHRONIZED -D_ACL_PRIVATE
diff --git a/bin/csh/Makefile b/bin/csh/Makefile
index deb63478727d..0c364c176f64 100644
--- a/bin/csh/Makefile
+++ b/bin/csh/Makefile
@@ -8,6 +8,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
TCSHDIR= ${.CURDIR}/../../contrib/tcsh
.PATH: ${TCSHDIR}
diff --git a/bin/date/Makefile b/bin/date/Makefile
index 56ce33afb456..fd7e401aeb58 100644
--- a/bin/date/Makefile
+++ b/bin/date/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= date
SRCS= date.c netdate.c vary.c
diff --git a/bin/date/tests/Makefile b/bin/date/tests/Makefile
index ecce803e247d..cffb43f30efe 100644
--- a/bin/date/tests/Makefile
+++ b/bin/date/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_SH= format_string_test
.include <bsd.test.mk>
diff --git a/bin/dd/Makefile b/bin/dd/Makefile
index 6b17d290c6ee..df877c854f0f 100644
--- a/bin/dd/Makefile
+++ b/bin/dd/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= dd
SRCS= args.c conv.c conv_tab.c dd.c misc.c position.c
diff --git a/bin/dd/tests/Makefile b/bin/dd/tests/Makefile
index dd04af915887..ad976718ecf9 100644
--- a/bin/dd/tests/Makefile
+++ b/bin/dd/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_SH= dd_test
.include <netbsd-tests.test.mk>
diff --git a/bin/df/Makefile b/bin/df/Makefile
index 5cdae9ed7d2b..8f9f5284d94e 100644
--- a/bin/df/Makefile
+++ b/bin/df/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.3 (Berkeley) 5/8/95
# $FreeBSD$
+PACKAGE=runtime
MOUNT= ${.CURDIR}/../../sbin/mount
.PATH: ${MOUNT}
diff --git a/bin/domainname/Makefile b/bin/domainname/Makefile
index 724bd06f6a39..d3bace8feef3 100644
--- a/bin/domainname/Makefile
+++ b/bin/domainname/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= domainname
.include <bsd.prog.mk>
diff --git a/bin/echo/Makefile b/bin/echo/Makefile
index d00d4679d7ac..5d48e2146d98 100644
--- a/bin/echo/Makefile
+++ b/bin/echo/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=runtime
PROG= echo
.include <bsd.prog.mk>
diff --git a/bin/ed/Makefile b/bin/ed/Makefile
index bef3ff1ad5ef..40e06134e87d 100644
--- a/bin/ed/Makefile
+++ b/bin/ed/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= ed
SRCS= buf.c cbc.c glbl.c io.c main.c re.c sub.c undo.c
LINKS= ${BINDIR}/ed ${BINDIR}/red
diff --git a/bin/expr/Makefile b/bin/expr/Makefile
index 1d741b7e0b6d..471c1c099479 100644
--- a/bin/expr/Makefile
+++ b/bin/expr/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= expr
SRCS= expr.y
YFLAGS=
diff --git a/bin/expr/tests/Makefile b/bin/expr/tests/Makefile
index 21b0e993fedc..90331d0c9a9b 100644
--- a/bin/expr/tests/Makefile
+++ b/bin/expr/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_SH= expr_test
ATF_TESTS_SH_SED_expr_test+= -e 's/eval expr/eval expr --/g'
diff --git a/bin/freebsd-version/Makefile b/bin/freebsd-version/Makefile
index 91945acc894f..c49f66143b46 100644
--- a/bin/freebsd-version/Makefile
+++ b/bin/freebsd-version/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
SCRIPTS = freebsd-version
MAN = freebsd-version.1
CLEANFILES = freebsd-version freebsd-version.sh
diff --git a/bin/getfacl/Makefile b/bin/getfacl/Makefile
index b7b5e983a530..7b3f057fecca 100644
--- a/bin/getfacl/Makefile
+++ b/bin/getfacl/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= getfacl
.include <bsd.prog.mk>
diff --git a/bin/hostname/Makefile b/bin/hostname/Makefile
index 3c7997f862fc..9b0ecd7e4c4a 100644
--- a/bin/hostname/Makefile
+++ b/bin/hostname/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=runtime
PROG= hostname
.include <bsd.prog.mk>
diff --git a/bin/kenv/Makefile b/bin/kenv/Makefile
index 33a6dfc3bff5..9c1924ad4b32 100644
--- a/bin/kenv/Makefile
+++ b/bin/kenv/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= kenv
.include <bsd.prog.mk>
diff --git a/bin/kill/Makefile b/bin/kill/Makefile
index 55ef16dfce2c..4c9cddacd9a4 100644
--- a/bin/kill/Makefile
+++ b/bin/kill/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=runtime
PROG= kill
.include <bsd.prog.mk>
diff --git a/bin/ln/Makefile b/bin/ln/Makefile
index b541f8bd3be0..d7c8b46fb0a0 100644
--- a/bin/ln/Makefile
+++ b/bin/ln/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.2 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=runtime
PROG= ln
MAN= ln.1 symlink.7
diff --git a/bin/ls/Makefile b/bin/ls/Makefile
index e57bf35a1652..db3fae7eb232 100644
--- a/bin/ls/Makefile
+++ b/bin/ls/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= ls
SRCS= cmp.c ls.c print.c util.c
LIBADD= xo util
diff --git a/bin/ls/tests/Makefile b/bin/ls/tests/Makefile
index 89a2e8cf1dca..2c3045b5cc10 100644
--- a/bin/ls/tests/Makefile
+++ b/bin/ls/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_SH+= ls_tests
# This seems like overkill, but the idea in mind is that all of the testcases
# should be runnable as !root
diff --git a/bin/mkdir/Makefile b/bin/mkdir/Makefile
index fadc6b294ef7..45876288fc40 100644
--- a/bin/mkdir/Makefile
+++ b/bin/mkdir/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=runtime
PROG= mkdir
.include <bsd.prog.mk>
diff --git a/bin/mv/Makefile b/bin/mv/Makefile
index 02a5a4805800..e82466be296c 100644
--- a/bin/mv/Makefile
+++ b/bin/mv/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= mv
.if ${MK_TESTS} != "no"
diff --git a/bin/mv/tests/Makefile b/bin/mv/tests/Makefile
index 229d96e5766a..62bc207bfe05 100644
--- a/bin/mv/tests/Makefile
+++ b/bin/mv/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= legacy_test
.include <bsd.test.mk>
diff --git a/bin/pax/Makefile b/bin/pax/Makefile
index c00d52c70811..210137ba1abf 100644
--- a/bin/pax/Makefile
+++ b/bin/pax/Makefile
@@ -27,6 +27,7 @@
# regex routines and must define NET2_REGEX.
# Pax may not compile if this not (un)defined properly.
+PACKAGE=runtime
PROG= pax
SRCS= ar_io.c ar_subs.c buf_subs.c cache.c cpio.c file_subs.c ftree.c \
gen_subs.c getoldopt.c options.c pat_rep.c pax.c sel_subs.c \
diff --git a/bin/pax/tests/Makefile b/bin/pax/tests/Makefile
index 8334fea3c747..6e2208715dc6 100644
--- a/bin/pax/tests/Makefile
+++ b/bin/pax/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_PERL= legacy_test
.include <bsd.test.mk>
diff --git a/bin/pkill/Makefile b/bin/pkill/Makefile
index 2985b37dbff1..2eb3edea4cb2 100644
--- a/bin/pkill/Makefile
+++ b/bin/pkill/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= pkill
LIBADD= kvm jail
diff --git a/bin/pkill/tests/Makefile b/bin/pkill/tests/Makefile
index be467074651f..d6edfae4cd4b 100644
--- a/bin/pkill/tests/Makefile
+++ b/bin/pkill/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= pgrep-F_test
TAP_TESTS_SH+= pgrep-LF_test
TAP_TESTS_SH+= pgrep-P_test
diff --git a/bin/ps/Makefile b/bin/ps/Makefile
index 79e9fc6cf0ec..596aa57fd2df 100644
--- a/bin/ps/Makefile
+++ b/bin/ps/Makefile
@@ -1,6 +1,7 @@
# $FreeBSD$
# @(#)Makefile 8.1 (Berkeley) 6/2/93
+PACKAGE=runtime
PROG= ps
SRCS= fmt.c keyword.c nlist.c print.c ps.c
diff --git a/bin/pwait/Makefile b/bin/pwait/Makefile
index cdf322e27a8f..a282c18a4f35 100644
--- a/bin/pwait/Makefile
+++ b/bin/pwait/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= pwait
.include <bsd.prog.mk>
diff --git a/bin/pwd/Makefile b/bin/pwd/Makefile
index 4a8e66ac8320..2a623a16b3ae 100644
--- a/bin/pwd/Makefile
+++ b/bin/pwd/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=runtime
PROG= pwd
.include <bsd.prog.mk>
diff --git a/bin/rcp/Makefile b/bin/rcp/Makefile
index 886ec01ca0d0..6c1cfb18a8c5 100644
--- a/bin/rcp/Makefile
+++ b/bin/rcp/Makefile
@@ -1,10 +1,13 @@
# @(#)Makefile 8.1 (Berkeley) 7/19/93
# $FreeBSD$
+PACKAGE=rcmds
PROG= rcp
SRCS= rcp.c util.c
CFLAGS+=-DBINDIR=${BINDIR}
+PACKAGE=rcmds
+
BINOWN= root
BINMODE=4555
diff --git a/bin/realpath/Makefile b/bin/realpath/Makefile
index acf62c76cb3a..71381f3359d0 100644
--- a/bin/realpath/Makefile
+++ b/bin/realpath/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= realpath
.include <bsd.prog.mk>
diff --git a/bin/rm/Makefile b/bin/rm/Makefile
index 7058fa06c98d..e0d27134825a 100644
--- a/bin/rm/Makefile
+++ b/bin/rm/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=runtime
PROG= rm
LINKS= ${BINDIR}/rm ${BINDIR}/unlink
diff --git a/bin/rmail/Makefile b/bin/rmail/Makefile
index 421a6ffa6d8d..53d0ca4f554f 100644
--- a/bin/rmail/Makefile
+++ b/bin/rmail/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=sendmail
SENDMAIL_DIR=${.CURDIR}/../../contrib/sendmail
.PATH: ${SENDMAIL_DIR}/rmail
diff --git a/bin/rmdir/Makefile b/bin/rmdir/Makefile
index c2c7f301ce49..a40686dba51a 100644
--- a/bin/rmdir/Makefile
+++ b/bin/rmdir/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=runtime
PROG= rmdir
.include <bsd.prog.mk>
diff --git a/bin/setfacl/Makefile b/bin/setfacl/Makefile
index 3f6b78e54e11..378541398e5b 100644
--- a/bin/setfacl/Makefile
+++ b/bin/setfacl/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= setfacl
SRCS= file.c mask.c merge.c remove.c setfacl.c util.c
diff --git a/bin/sh/Makefile b/bin/sh/Makefile
index 3f28a1231fd3..419ff7915bf6 100644
--- a/bin/sh/Makefile
+++ b/bin/sh/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= sh
INSTALLFLAGS= -S
SHSRCS= alias.c arith_yacc.c arith_yylex.c cd.c echo.c error.c eval.c \
diff --git a/bin/sh/tests/Makefile b/bin/sh/tests/Makefile
index d93e19aea7e1..58834a433e31 100644
--- a/bin/sh/tests/Makefile
+++ b/bin/sh/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TESTS_SUBDIRS+= builtins
TESTS_SUBDIRS+= errors
TESTS_SUBDIRS+= execution
diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile
index 82926658e045..11cea5f10af9 100644
--- a/bin/sh/tests/builtins/Makefile
+++ b/bin/sh/tests/builtins/Makefile
@@ -2,6 +2,9 @@
.include <src.opts.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T}
.PATH: ${.CURDIR:H}
diff --git a/bin/sh/tests/errors/Makefile b/bin/sh/tests/errors/Makefile
index 51a766f6f4e9..f7c7e267ae5b 100644
--- a/bin/sh/tests/errors/Makefile
+++ b/bin/sh/tests/errors/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T}
.PATH: ${.CURDIR:H}
diff --git a/bin/sh/tests/execution/Makefile b/bin/sh/tests/execution/Makefile
index 638492bb96ad..64d12deda965 100644
--- a/bin/sh/tests/execution/Makefile
+++ b/bin/sh/tests/execution/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T}
.PATH: ${.CURDIR:H}
diff --git a/bin/sh/tests/expansion/Makefile b/bin/sh/tests/expansion/Makefile
index fb672dae15a0..351babdf84d5 100644
--- a/bin/sh/tests/expansion/Makefile
+++ b/bin/sh/tests/expansion/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T}
.PATH: ${.CURDIR:H}
diff --git a/bin/sh/tests/parameters/Makefile b/bin/sh/tests/parameters/Makefile
index 528697df4378..d510779d049a 100644
--- a/bin/sh/tests/parameters/Makefile
+++ b/bin/sh/tests/parameters/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T}
.PATH: ${.CURDIR:H}
diff --git a/bin/sh/tests/parser/Makefile b/bin/sh/tests/parser/Makefile
index dd126ee7ea90..4f823b05f4cd 100644
--- a/bin/sh/tests/parser/Makefile
+++ b/bin/sh/tests/parser/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T}
.PATH: ${.CURDIR:H}
diff --git a/bin/sh/tests/set-e/Makefile b/bin/sh/tests/set-e/Makefile
index f733b60b1e18..3d7481dc643e 100644
--- a/bin/sh/tests/set-e/Makefile
+++ b/bin/sh/tests/set-e/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/bin/sh/${.CURDIR:T}
.PATH: ${.CURDIR:H}
diff --git a/bin/sleep/Makefile b/bin/sleep/Makefile
index 0ec3080476a5..9575adf62a71 100644
--- a/bin/sleep/Makefile
+++ b/bin/sleep/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= sleep
.if ${MK_TESTS} != "no"
diff --git a/bin/sleep/tests/Makefile b/bin/sleep/tests/Makefile
index 6fc95f39ccb1..615d80a95cfc 100644
--- a/bin/sleep/tests/Makefile
+++ b/bin/sleep/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_SH= sleep_test
.include <bsd.test.mk>
diff --git a/bin/stty/Makefile b/bin/stty/Makefile
index 82b15eb7fcae..b10b8951b487 100644
--- a/bin/stty/Makefile
+++ b/bin/stty/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=runtime
PROG= stty
SRCS= cchar.c gfmt.c key.c modes.c print.c stty.c util.c
diff --git a/bin/sync/Makefile b/bin/sync/Makefile
index 72c664f4afdd..8b56d6af4b88 100644
--- a/bin/sync/Makefile
+++ b/bin/sync/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+PACKAGE=runtime
PROG= sync
MAN= sync.8
diff --git a/bin/test/Makefile b/bin/test/Makefile
index 8e3121b3167f..5cd91ebb288d 100644
--- a/bin/test/Makefile
+++ b/bin/test/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= test
LINKS= ${BINDIR}/test ${BINDIR}/[
MLINKS= test.1 [.1
diff --git a/bin/test/tests/Makefile b/bin/test/tests/Makefile
index a1a5d4f02fa7..aff93d83aaf7 100644
--- a/bin/test/tests/Makefile
+++ b/bin/test/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= legacy_test
# Some tests in here are silently not run when the tests are executed as
# root. Explicitly tell Kyua to drop privileges.
diff --git a/bin/tests/Makefile b/bin/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/bin/tests/Makefile
+++ b/bin/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/bin/uuidgen/Makefile b/bin/uuidgen/Makefile
index 0b27d20e9805..8cd15982405d 100644
--- a/bin/uuidgen/Makefile
+++ b/bin/uuidgen/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= uuidgen
.include <bsd.prog.mk>
diff --git a/cddl/lib/tests/Makefile b/cddl/lib/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/cddl/lib/tests/Makefile
+++ b/cddl/lib/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/cddl/sbin/tests/Makefile b/cddl/sbin/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/cddl/sbin/tests/Makefile
+++ b/cddl/sbin/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/cddl/tests/Makefile b/cddl/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/cddl/tests/Makefile
+++ b/cddl/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/cddl/usr.bin/tests/Makefile b/cddl/usr.bin/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/cddl/usr.bin/tests/Makefile
+++ b/cddl/usr.bin/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/cddl/usr.sbin/tests/Makefile b/cddl/usr.sbin/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/cddl/usr.sbin/tests/Makefile
+++ b/cddl/usr.sbin/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/contrib/ntp/ntpd/ntp_control.c b/contrib/ntp/ntpd/ntp_control.c
index e5a567e789d6..3c022185b5d6 100644
--- a/contrib/ntp/ntpd/ntp_control.c
+++ b/contrib/ntp/ntpd/ntp_control.c
@@ -3,6 +3,10 @@
* traps. Provides service to ntpq and others.
*/
+/*
+ * $FreeBSD: projects/release-pkg/contrib/ntp/ntpd/ntp_control.c 277386 2015-01-19 16:15:12Z gjb $
+ */
+
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
diff --git a/etc/Makefile b/etc/Makefile
index 27d1ba447b9e..3de8f974ba98 100644
--- a/etc/Makefile
+++ b/etc/Makefile
@@ -3,6 +3,8 @@
.include <src.opts.mk>
+FILESGROUPS= FILES
+
SUBDIR= \
newsyslog.conf.d
@@ -79,8 +81,13 @@ BIN1+= apmd.conf
.endif
.if ${MK_AUTOFS} != "no"
-BIN1+= auto_master
+FILESGROUPS+= AUTOFS
+AUTOFS+= auto_master
.endif
+AUTOFSDIR= /etc
+AUTOFSMODE= ${BINMODE}
+AUTOFSPACKAGE= autofs
+AUTOFSTAGS= config
.if ${MK_FREEBSD_UPDATE} != "no"
BIN1+= freebsd-update.conf
@@ -132,8 +139,12 @@ BIN1+= pf.os
.endif
.if ${MK_SENDMAIL} != "no"
-BIN1+= rc.sendmail
+FILESGROUPS+= SENDMAILRC
+SENDMAILRC= rc.sendmail
.endif
+SENDMAILRCDIR= /etc
+SENDMAILRCMODE= ${BINMODE}
+SENDMAILRCPACKAGE=sendmail
.if ${MK_TCSH} != "no"
BIN1+= csh.cshrc csh.login csh.logout
diff --git a/etc/devd/Makefile b/etc/devd/Makefile
index a0909af08918..d031f1930a77 100644
--- a/etc/devd/Makefile
+++ b/etc/devd/Makefile
@@ -2,7 +2,7 @@
.include <src.opts.mk>
-FILES=
+FILEGROUPS= FILES
.if ${MACHINE} == "powerpc"
FILES+= apple.conf
@@ -10,7 +10,12 @@ FILES+= apple.conf
.if ${MACHINE} == "amd64" || ${MACHINE} == "i386"
.if ${MK_ACPI} != "no"
-FILES+= asus.conf
+FILESGROUPS+= ACPI
+ACPI= asus.conf
+ACPIPACKAGE= acpi
+ACPIDIR= /etc/devd
+ACPITAGS= config
+ACPIMODE= 644
.endif
.if ${MK_HYPERV} != "no"
FILES+= hyperv.conf
diff --git a/etc/mtree/BSD.var.dist b/etc/mtree/BSD.var.dist
index 3a5852905f32..46b8dcddb67c 100644
--- a/etc/mtree/BSD.var.dist
+++ b/etc/mtree/BSD.var.dist
@@ -9,9 +9,9 @@
..
at
/set uname=daemon
- jobs
+ jobs tags=package=at
..
- spool
+ spool tags=package=at
..
/set uname=root
..
@@ -99,8 +99,8 @@
vi.recover mode=01777
..
..
- unbound uname=unbound gname=unbound mode=0755
- conf.d uname=unbound gname=unbound mode=0755
+ unbound uname=unbound gname=unbound mode=0755 tags=package=unbound
+ conf.d uname=unbound gname=unbound mode=0755 tags=package=unbound
..
..
yp
diff --git a/etc/pam.d/Makefile b/etc/pam.d/Makefile
index ac7db6cafd2c..a9aea19fee51 100644
--- a/etc/pam.d/Makefile
+++ b/etc/pam.d/Makefile
@@ -4,6 +4,8 @@
NO_OBJ=
+FILESGROUPS= FILES
+
FILES= README \
cron \
ftpd \
@@ -11,13 +13,24 @@ FILES= README \
login \
other \
passwd pop3 \
- rsh \
sshd su system \
telnetd \
xdm
.if ${MK_AT} != "no"
-FILES+= atrun
+FILESGROUPS+= AT
+AT+= atrun
+ATPACKAGE+= at
+ATDIR= /etc/pam.d
+ATMODE= 644
+.endif
+
+.if ${MK_RCMDS} != "no"
+FILESGROUPS+= RCMDS
+RCMDS+= rsh
+RCMDSPACKAGE+= rcmds
+RCMDSDIR= /etc/pam.d
+RCMDSMODE= 644
.endif
FILESDIR= /etc/pam.d
diff --git a/etc/periodic/daily/Makefile b/etc/periodic/daily/Makefile
index de0f8f2a907c..d2052f22c734 100644
--- a/etc/periodic/daily/Makefile
+++ b/etc/periodic/daily/Makefile
@@ -2,6 +2,8 @@
.include <src.opts.mk>
+FILESGROUPS=FILES
+
FILES= 100.clean-disks \
110.clean-tmps \
120.clean-preserve \
@@ -23,8 +25,12 @@ FILES= 100.clean-disks \
# NB: keep these sorted by MK_* knobs
.if ${MK_ACCT} != "no"
-FILES+= 310.accounting
+FILESGROUPS+= ACCT
+ACCT+= 310.accounting
.endif
+ACCTDIR= /etc/periodic/daily
+ACCTMODE= ${BINMODE}
+ACCTPACKAGE= acct
.if ${MK_CALENDAR} != "no"
FILES+= 300.calendar
@@ -40,8 +46,12 @@ FILES+= 480.status-ntpd \
.endif
.if ${MK_RCMDS} != "no"
-FILES+= 140.clean-rwho
+FILESGROUPS+= RCMDS
+RCMDS+= 140.clean-rwho
.endif
+RCMDSDIR= /etc/periodic/daily
+RCMDSMODE= ${BINMODE}
+RCMDSPACKAGE= rcmds
.if ${MK_SENDMAIL} != "no"
FILES+= 150.clean-hoststat \
diff --git a/etc/periodic/monthly/Makefile b/etc/periodic/monthly/Makefile
index ea2bd9f0b057..64642193c577 100644
--- a/etc/periodic/monthly/Makefile
+++ b/etc/periodic/monthly/Makefile
@@ -2,13 +2,19 @@
.include <src.opts.mk>
+FILESGROUPS=FILES
+
FILES= 450.status-security \
999.local
# NB: keep these sorted by MK_* knobs
.if ${MK_UTMPX} != "no"
-FILES+= 200.accounting
+FILESGROUPS+= ACCT
+ACCT+= 200.accounting
.endif
+ACCTDIR= /etc/periodic/monthly
+ACCTMODE= ${BINMODE}
+ACCTPACKAGE= acct
.include <bsd.prog.mk>
diff --git a/etc/rc.d/Makefile b/etc/rc.d/Makefile
index 6cc860bff108..cd9405f768f8 100644
--- a/etc/rc.d/Makefile
+++ b/etc/rc.d/Makefile
@@ -2,13 +2,16 @@
.include <src.opts.mk>
+FILESGROUPS= FILES
+FILESDIR= /etc/rc.d
+FILESMODE= ${BINMODE}
+
FILES= DAEMON \
FILESYSTEMS \
LOGIN \
NETWORKING \
SERVERS \
abi \
- accounting \
addswap \
adjkerntz \
archdep \
@@ -108,7 +111,6 @@ FILES= DAEMON \
securelevel \
serial \
sppp \
- ${_sshd} \
statd \
static_arp \
static_ndp \
@@ -120,7 +122,6 @@ FILES= DAEMON \
tmp \
${_ubthidhci} \
ugidfw \
- ${_unbound} \
${_utx} \
var \
watchdogd \
@@ -134,25 +135,41 @@ FILES= DAEMON \
zvol
.if ${MK_ACCT} != "no"
-FILES+= accounting
+FILESGROUPS+= ACCT
+ACCT+= accounting
.endif
+ACCTDIR= /etc/rc.d
+ACCTMODE= ${BINMODE}
+ACCTPACKAGE= acct
.if ${MK_ACPI} != "no"
-FILES+= power_profile
+FILESGROUPS+= ACPI
+ACPI= power_profile
.endif
+ACPIDIR= /etc/rc.d
+ACPIMODE= ${BINMODE}
+ACPIPACKAGE= acpi
.if ${MK_ACPI} != "no" || ${MK_APM} != "no"
FILES+= powerd
.endif
.if ${MK_AMD} != "no"
-FILES+= amd
+FILESGROUPS+= AMD
+AMD+= amd
.endif
+AMDDIR= /etc/rc.d
+AMDMODE= ${BINMODE}
+AMDPACKAGE= amd
.if ${MK_APM} != "no"
-FILES+= apm
-FILES+= apmd
+FILESGROUPS+= APM
+APM+= apm
+APM+= apmd
.endif
+APMDIR= /etc/rc.d
+APMMODE= ${BINMODE}
+APMPACKAGE= apm
.if ${MK_AUTOFS} != "no"
FILES+= automount
@@ -172,8 +189,12 @@ FILES+= bootparams
.endif
.if ${MK_BSNMP} != "no"
-FILES+= bsnmpd
+FILESGROUPS+= BSNMP
+BSNMP+= bsnmpd
.endif
+BSNMPDIR= /etc/rc.d
+BSNMPMODE= ${BINMODE}
+BSNMPPACKAGE= bsnmp
.if ${MK_CCD} != "no"
FILES+= ccd
@@ -184,8 +205,12 @@ FILES+= ftpd
.endif
.if ${MK_HAST} != "no"
-FILES+= hastd
+FILESGROUPS+= HAST
+HAST= hastd
.endif
+HASTDIR= /etc/rc.d
+HASTMODE= ${BINMODE}
+HASTPACKAGE= hast
.if ${MK_INETD} != "no"
FILES+= inetd
@@ -197,8 +222,12 @@ FILES+= iscsid
.endif
.if ${MK_JAIL} != "no"
-FILES+= jail
+FILESGROUPS+= JAIL
+JAIL+= jail
.endif
+JAILDIR= /etc/rc.d
+JAILMODE= ${BINMODE}
+JAILPACKAGE= jail
.if ${MK_LEGACY_CONSOLE} != "no"
FILES+= moused
@@ -239,47 +268,64 @@ FILES+= keyserv
.endif
.if ${MK_OPENSSH} != "no"
-_sshd= sshd
+FILESGROUPS+= SSH
+SSH= sshd
.endif
+SSHDIR= /etc/rc.d
+SSHMODE= ${BINMODE}
+SSHPACKAGE= ssh
.if ${MK_PF} != "no"
FILES+= ftp-proxy
.endif
.if ${MK_RCMDS} != "no"
-FILES+= rwho
+FILESGROUPS+= RCMDS
+RCMDS+= rwho
.endif
+RCMDSDIR= /etc/rc.d
+RCMDSMODE= ${BINMODE}
+RCMDSPACKAGE= rcmds
.if ${MK_ROUTED} != "no"
FILES+= routed
.endif
.if ${MK_SENDMAIL} != "no"
-FILES+= sendmail
+FILESGROUPS+= SMRCD
+SMRCD= sendmail
.endif
+SMRCDDIR= /etc/rc.d
+SMRCDDIRMODE= ${BINMODE}
+SMRCDPACKAGE= sendmail
.if ${MK_TIMED} != "no"
FILES+= timed
.endif
.if ${MK_UNBOUND} != "no"
-_unbound= local_unbound
+FILESGROUPS+= UNBOUND
+UNBOUND+= local_unbound
.endif
+UNBOUNDDIR= /etc/rc.d
+UNBOUNDMODE= ${BINMODE}
+UNBOUNDPACKAGE= unbound
.if ${MK_UTMPX} != "no"
_utx= utx
.endif
.if ${MK_VI} != "no"
-FILES+= virecover
+FILESGROUPS+= VI
+VI+= virecover
.endif
+VIDIR= /etc/rc.d
+VIMODE= ${BINMODE}
+VIPACKAGE= vi
.if ${MK_WIRELESS} != "no"
FILES+= hostapd
FILES+= wpa_supplicant
.endif
-FILESDIR= /etc/rc.d
-FILESMODE= ${BINMODE}
-
.include <bsd.prog.mk>
diff --git a/gnu/lib/libgcc/Makefile b/gnu/lib/libgcc/Makefile
index f824bbc6112c..4944acf6c42e 100644
--- a/gnu/lib/libgcc/Makefile
+++ b/gnu/lib/libgcc/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= clibs
GCCDIR= ${.CURDIR}/../../../contrib/gcc
GCCLIB= ${.CURDIR}/../../../contrib/gcclibs
COMPILERRTDIR= ${.CURDIR}/../../../contrib/compiler-rt
diff --git a/gnu/lib/tests/Makefile b/gnu/lib/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/gnu/lib/tests/Makefile
+++ b/gnu/lib/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/gnu/tests/Makefile b/gnu/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/gnu/tests/Makefile
+++ b/gnu/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/gnu/usr.bin/binutils/Makefile.inc b/gnu/usr.bin/binutils/Makefile.inc
index 1e2665f97d9b..aba3cc7fa5eb 100644
--- a/gnu/usr.bin/binutils/Makefile.inc
+++ b/gnu/usr.bin/binutils/Makefile.inc
@@ -1,5 +1,6 @@
# $FreeBSD$
WARNS?= 3
+PACKAGE= binutils
.include "../Makefile.inc"
diff --git a/gnu/usr.bin/diff/tests/Makefile b/gnu/usr.bin/diff/tests/Makefile
index 16439b3b61fe..0b4ca2e157de 100644
--- a/gnu/usr.bin/diff/tests/Makefile
+++ b/gnu/usr.bin/diff/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TESTSRC= ${SRCTOP}/contrib/netbsd-tests/usr.bin/diff
NETBSD_ATF_TESTS_SH= diff_test
diff --git a/gnu/usr.bin/gdb/Makefile.inc b/gnu/usr.bin/gdb/Makefile.inc
index 40ea69b99efd..a27051c3ca26 100644
--- a/gnu/usr.bin/gdb/Makefile.inc
+++ b/gnu/usr.bin/gdb/Makefile.inc
@@ -3,6 +3,8 @@
VERSION= "6.1.1 [FreeBSD]"
VENDOR= marcel
+PACKAGE= gdb
+
BMAKE_GDB= ${.CURDIR}/..
BMAKE_ROOT= ${BMAKE_GDB}/..
BMAKE_BU= ${BMAKE_ROOT}/binutils
diff --git a/gnu/usr.bin/groff/Makefile.inc b/gnu/usr.bin/groff/Makefile.inc
index 67b61a875687..24bcd9868796 100644
--- a/gnu/usr.bin/groff/Makefile.inc
+++ b/gnu/usr.bin/groff/Makefile.inc
@@ -2,6 +2,7 @@
BINDIR?= /usr/bin
SHELL= /bin/sh
+PACKAGE= groff
# Define `page' to be letter if your PostScript printer uses 8.5x11
# paper (USA) and define it to be A4, if it uses A4 paper (rest of the
diff --git a/gnu/usr.bin/tests/Makefile b/gnu/usr.bin/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/gnu/usr.bin/tests/Makefile
+++ b/gnu/usr.bin/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/include/Makefile b/include/Makefile
index 8033de1cbc06..d8213ef8bf50 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -5,6 +5,8 @@
.include <src.opts.mk>
+PACKAGE=runtime
+TAGS+= development
CLEANFILES= osreldate.h version
SUBDIR= arpa protocols rpcsvc rpc xlocale
SUBDIR_PARALLEL=
@@ -181,78 +183,78 @@ copies:
.endfor
.for i in ${LDIRS} ${LSUBDIRS:Ndev/agp:Ndev/acpica:Ndev/bktr:Ndev/nand:Ndev/pci} ${LSUBSUBDIRS}
cd ${.CURDIR}/../sys; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 $i/*.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 $i/*.h \
${DESTDIR}${INCLUDEDIR}/$i
.endfor
cd ${.CURDIR}/../sys/dev/acpica; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 acpiio.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 acpiio.h \
${DESTDIR}${INCLUDEDIR}/dev/acpica; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 acpi_hpet.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 acpi_hpet.h \
${DESTDIR}${INCLUDEDIR}/dev/acpica
cd ${.CURDIR}/../sys/dev/agp; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 agpreg.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 agpreg.h \
${DESTDIR}${INCLUDEDIR}/dev/agp
cd ${.CURDIR}/../sys/dev/bktr; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 ioctl_*.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 ioctl_*.h \
${DESTDIR}${INCLUDEDIR}/dev/bktr
.if ${MK_NAND} != "no"
cd ${.CURDIR}/../sys/dev/nand; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 nandsim.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 nandsim.h \
${DESTDIR}${INCLUDEDIR}/dev/nand; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 nand_dev.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 nand_dev.h \
${DESTDIR}${INCLUDEDIR}/dev/nand
.endif
cd ${.CURDIR}/../sys/dev/pci; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 pcireg.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 pcireg.h \
${DESTDIR}${INCLUDEDIR}/dev/pci
cd ${.CURDIR}/../sys/fs/cd9660/; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
${DESTDIR}${INCLUDEDIR}/isofs/cd9660
.if ${MK_IPFILTER} != "no"
cd ${.CURDIR}/../sys/contrib/ipfilter/netinet; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
${DESTDIR}${INCLUDEDIR}/netinet
.endif
.if ${MK_PF} != "no"
cd ${.CURDIR}/../sys/netpfil/pf; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
${DESTDIR}${INCLUDEDIR}/netpfil/pf
.endif
cd ${.CURDIR}/../sys/crypto; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 rijndael/rijndael.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 rijndael/rijndael.h \
${DESTDIR}${INCLUDEDIR}/crypto
cd ${.CURDIR}/../sys/opencrypto; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
${DESTDIR}${INCLUDEDIR}/crypto
cd ${.CURDIR}/../sys/${MACHINE}/include; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
${DESTDIR}${INCLUDEDIR}/machine
.if exists(${.CURDIR}/../sys/${MACHINE}/include/pc)
cd ${.CURDIR}/../sys/${MACHINE}/include/pc; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
${DESTDIR}${INCLUDEDIR}/machine/pc
.endif
.for _MARCH in ${_MARCHS}
.if exists(${.CURDIR}/../sys/${_MARCH}/include)
- ${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m 755 \
+ ${INSTALL} -d ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 755 \
${DESTDIR}${INCLUDEDIR}/${_MARCH}; \
cd ${.CURDIR}/../sys/${_MARCH}/include; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
${DESTDIR}${INCLUDEDIR}/${_MARCH}
.if exists(${.CURDIR}/../sys/${_MARCH}/include/pc)
- ${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m 755 \
+ ${INSTALL} -d ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 755 \
${DESTDIR}${INCLUDEDIR}/${_MARCH}/pc; \
cd ${.CURDIR}/../sys/${_MARCH}/include/pc; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 *.h \
${DESTDIR}${INCLUDEDIR}/${_MARCH}/pc
.endif
.endif
.endfor
cd ${.CURDIR}/../sys/rpc; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 types.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 types.h \
${DESTDIR}${INCLUDEDIR}/rpc
cd ${.CURDIR}/../sys/teken; \
- ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 teken.h \
+ ${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 teken.h \
${DESTDIR}${INCLUDEDIR}/teken
.if ${MK_DIRDEPS_BUILD} == "yes"
@touch ${.OBJDIR}/${.TARGET}
@@ -263,99 +265,99 @@ symlinks:
.for i in ${LDIRS}
cd ${.CURDIR}/../sys/$i; \
for h in *.h; do \
- ${INSTALL_SYMLINK} ../../../sys/$i/$$h ${DESTDIR}${INCLUDEDIR}/$i; \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../sys/$i/$$h ${DESTDIR}${INCLUDEDIR}/$i; \
done
.endfor
.for i in ${LSUBDIRS:Ndev/agp:Ndev/acpica:Ndev/bktr:Ndev/nand:Ndev/pci}
cd ${.CURDIR}/../sys/$i; \
for h in *.h; do \
- ${INSTALL_SYMLINK} ../../../../sys/$i/$$h ${DESTDIR}${INCLUDEDIR}/$i; \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../../sys/$i/$$h ${DESTDIR}${INCLUDEDIR}/$i; \
done
.endfor
cd ${.CURDIR}/../sys/dev/acpica; \
for h in acpiio.h acpi_hpet.h; do \
- ${INSTALL_SYMLINK} ../../../../sys/dev/acpica/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../../sys/dev/acpica/$$h \
${DESTDIR}${INCLUDEDIR}/dev/acpica; \
done
cd ${.CURDIR}/../sys/dev/agp; \
for h in agpreg.h; do \
- ${INSTALL_SYMLINK} ../../../../sys/dev/agp/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../../sys/dev/agp/$$h \
${DESTDIR}${INCLUDEDIR}/dev/agp; \
done
cd ${.CURDIR}/../sys/dev/bktr; \
for h in ioctl_*.h; do \
- ${INSTALL_SYMLINK} ../../../../sys/dev/bktr/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../../sys/dev/bktr/$$h \
${DESTDIR}${INCLUDEDIR}/dev/bktr; \
done
.if ${MK_NAND} != "no"
cd ${.CURDIR}/../sys/dev/nand; \
for h in nandsim.h nand_dev.h; do \
- ${INSTALL_SYMLINK} ../../../../sys/dev/nand/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../../sys/dev/nand/$$h \
${DESTDIR}${INCLUDEDIR}/dev/nand; \
done
.endif
cd ${.CURDIR}/../sys/dev/pci; \
for h in pcireg.h; do \
- ${INSTALL_SYMLINK} ../../../../sys/dev/pci/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../../sys/dev/pci/$$h \
${DESTDIR}${INCLUDEDIR}/dev/pci; \
done
.for i in ${LSUBSUBDIRS}
cd ${.CURDIR}/../sys/$i; \
for h in *.h; do \
- ${INSTALL_SYMLINK} ../../../../../sys/$i/$$h ${DESTDIR}${INCLUDEDIR}/$i; \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../../../sys/$i/$$h ${DESTDIR}${INCLUDEDIR}/$i; \
done
.endfor
.if ${MK_IPFILTER} != "no"
cd ${.CURDIR}/../sys/contrib/ipfilter/netinet; \
for h in *.h; do \
- ${INSTALL_SYMLINK} ../../../sys/contrib/ipfilter/netinet/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../sys/contrib/ipfilter/netinet/$$h \
${DESTDIR}${INCLUDEDIR}/netinet; \
done
.endif
.if ${MK_PF} != "no"
cd ${.CURDIR}/../sys/netpfil/pf; \
for h in *.h; do \
- ${INSTALL_SYMLINK} ../../../../sys/netpfil/pf/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../../sys/netpfil/pf/$$h \
${DESTDIR}${INCLUDEDIR}/netpfil/pf; \
done
.endif
cd ${.CURDIR}/../sys/crypto; \
for h in rijndael/rijndael.h; do \
- ${INSTALL_SYMLINK} ../../../sys/crypto/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../sys/crypto/$$h \
${DESTDIR}${INCLUDEDIR}/crypto; \
done
cd ${.CURDIR}/../sys/opencrypto; \
for h in *.h; do \
- ${INSTALL_SYMLINK} ../../../sys/opencrypto/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../sys/opencrypto/$$h \
${DESTDIR}${INCLUDEDIR}/crypto; \
done
cd ${.CURDIR}/../sys/${MACHINE}/include; \
for h in *.h; do \
- ${INSTALL_SYMLINK} ../../../sys/${MACHINE}/include/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../sys/${MACHINE}/include/$$h \
${DESTDIR}${INCLUDEDIR}/machine; \
done
.if exists(${.CURDIR}/../sys/${MACHINE}/include/pc)
cd ${.CURDIR}/../sys/${MACHINE}/include/pc; \
for h in *.h; do \
- ${INSTALL_SYMLINK} ../../../../sys/${MACHINE}/include/pc/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../../sys/${MACHINE}/include/pc/$$h \
${DESTDIR}${INCLUDEDIR}/machine/pc; \
done
.endif
.for _MARCH in ${_MARCHS}
.if exists(${.CURDIR}/../sys/${_MARCH}/include)
- ${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m 755 \
+ ${INSTALL} -d ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 755 \
${DESTDIR}${INCLUDEDIR}/${_MARCH}; \
cd ${.CURDIR}/../sys/${_MARCH}/include; \
for h in *.h; do \
- ${INSTALL_SYMLINK} ../../../sys/${_MARCH}/include/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../sys/${_MARCH}/include/$$h \
${DESTDIR}${INCLUDEDIR}/${_MARCH}; \
done
.if exists(${.CURDIR}/../sys/${_MARCH}/include/pc)
- ${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m 755 \
+ ${INSTALL} -d ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 755 \
${DESTDIR}${INCLUDEDIR}/${_MARCH}/pc; \
cd ${.CURDIR}/../sys/${_MARCH}/include/pc; \
for h in *.h; do \
- ${INSTALL_SYMLINK} ../../../../sys/${_MARCH}/include/pc/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../../sys/${_MARCH}/include/pc/$$h \
${DESTDIR}${INCLUDEDIR}/${_MARCH}/pc; \
done
.endif
@@ -363,12 +365,12 @@ symlinks:
.endfor
cd ${.CURDIR}/../sys/fs/cd9660; \
for h in *.h; do \
- ${INSTALL_SYMLINK} ../../../../sys/fs/cd9660/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../../sys/fs/cd9660/$$h \
${DESTDIR}${INCLUDEDIR}/isofs/cd9660; \
done
cd ${.CURDIR}/../sys/rpc; \
for h in types.h; do \
- ${INSTALL_SYMLINK} ../../../sys/rpc/$$h \
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ../../../sys/rpc/$$h \
${DESTDIR}${INCLUDEDIR}/rpc; \
done
.if ${MK_DIRDEPS_BUILD} == "yes"
diff --git a/lib/Makefile b/lib/Makefile
index cfa0ea9d2b70..cdcce9091a0c 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -148,6 +148,7 @@ SUBDIR_DEPEND_libpjdlog= libutil
SUBDIR_DEPEND_libprocstat= libkvm libutil
SUBDIR_DEPEND_libradius= libmd
SUBDIR_DEPEND_libsmb= libkiconv
+SUBDIR_DEPEND_libstdc++:= msun
SUBDIR_DEPEND_libtacplus= libmd
SUBDIR_DEPEND_libulog= libmd
SUBDIR_DEPEND_libunbound= ${_libldns}
diff --git a/lib/atf/libatf-c++/tests/Makefile b/lib/atf/libatf-c++/tests/Makefile
index a069bb19d1e6..bebc7efc8175 100644
--- a/lib/atf/libatf-c++/tests/Makefile
+++ b/lib/atf/libatf-c++/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.init.mk>
+PACKAGE=tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TESTS_SUBDIRS= detail
ATF= ${SRCTOP}/contrib/atf
diff --git a/lib/atf/libatf-c++/tests/detail/Makefile b/lib/atf/libatf-c++/tests/detail/Makefile
index f7d672e792fb..f194abf9041d 100644
--- a/lib/atf/libatf-c++/tests/detail/Makefile
+++ b/lib/atf/libatf-c++/tests/detail/Makefile
@@ -2,6 +2,9 @@
.include <bsd.init.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/lib/atf/libatf-c++/detail
ATF= ${SRCTOP}/contrib/atf
diff --git a/lib/atf/libatf-c/tests/Makefile b/lib/atf/libatf-c/tests/Makefile
index e864c2e8bafc..82d6db427110 100644
--- a/lib/atf/libatf-c/tests/Makefile
+++ b/lib/atf/libatf-c/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.init.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TESTS_SUBDIRS= detail
ATF= ${SRCTOP}/contrib/atf
diff --git a/lib/atf/libatf-c/tests/detail/Makefile b/lib/atf/libatf-c/tests/detail/Makefile
index e47fd566ec01..296d2dd0a31f 100644
--- a/lib/atf/libatf-c/tests/detail/Makefile
+++ b/lib/atf/libatf-c/tests/detail/Makefile
@@ -2,6 +2,11 @@
.include <bsd.init.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
TESTSDIR= ${TESTSBASE}/lib/atf/libatf-c/detail
ATF= ${SRCTOP}/contrib/atf
diff --git a/lib/atf/tests/Makefile b/lib/atf/tests/Makefile
index dc79bb3491f5..ee998049e845 100644
--- a/lib/atf/tests/Makefile
+++ b/lib/atf/tests/Makefile
@@ -2,7 +2,12 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/lib/atf
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/lib/atf/tests/test-programs/Makefile b/lib/atf/tests/test-programs/Makefile
index aa308268a043..24f7b799880f 100644
--- a/lib/atf/tests/test-programs/Makefile
+++ b/lib/atf/tests/test-programs/Makefile
@@ -2,7 +2,11 @@
.include <bsd.init.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/lib/atf/test-programs
+TESTS+= Kyuafile
KYUAFILE= yes
ATF= ${SRCTOP}/contrib/atf
diff --git a/lib/lib80211/Makefile b/lib/lib80211/Makefile
index e00017e7e43e..fe103ce81cbd 100644
--- a/lib/lib80211/Makefile
+++ b/lib/lib80211/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= 80211
SHLIBDIR?= /lib
SHLIB_MAJOR= 1
diff --git a/lib/libalias/libalias/Makefile b/lib/libalias/libalias/Makefile
index 00b4ed8fe20a..feed9a852c20 100644
--- a/lib/libalias/libalias/Makefile
+++ b/lib/libalias/libalias/Makefile
@@ -2,6 +2,7 @@
.PATH: ${.CURDIR}/../../../sys/netinet/libalias
+PACKAGE=lib${LIB}
LIB= alias
SHLIBDIR?= /lib
SHLIB_MAJOR= 7
diff --git a/lib/libarchive/Makefile b/lib/libarchive/Makefile
index 93749b9df1a2..6f0ccd1f9c9e 100644
--- a/lib/libarchive/Makefile
+++ b/lib/libarchive/Makefile
@@ -1,6 +1,7 @@
# $FreeBSD$
.include <src.opts.mk>
+PACKAGE=lib${LIB}
_LIBARCHIVEDIR= ${.CURDIR}/../../contrib/libarchive
LIB= archive
diff --git a/lib/libarchive/tests/Makefile b/lib/libarchive/tests/Makefile
index 73ded3dc5556..160ebb4f9499 100644
--- a/lib/libarchive/tests/Makefile
+++ b/lib/libarchive/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
_LIBARCHIVEDIR= ${SRCTOP}/contrib/libarchive
ATF_TESTS_SH+= functional_test
diff --git a/lib/libauditd/Makefile b/lib/libauditd/Makefile
index 10039e9914ec..f8ed80a30fe3 100644
--- a/lib/libauditd/Makefile
+++ b/lib/libauditd/Makefile
@@ -2,6 +2,7 @@
# $FreeBSD$
#
+PACKAGE=lib${LIB}
OPENBSMDIR= ${.CURDIR}/../../contrib/openbsm
_LIBAUDITDDIR= ${OPENBSMDIR}/libauditd
_LIBBSMDIR= ${OPENBSMDIR}/libbsm
diff --git a/lib/libbegemot/Makefile b/lib/libbegemot/Makefile
index 27baf563cff6..d2783859254d 100644
--- a/lib/libbegemot/Makefile
+++ b/lib/libbegemot/Makefile
@@ -2,6 +2,7 @@
LIBBEGEMOT_DIR=${.CURDIR}/../../contrib/libbegemot
+PACKAGE=lib${LIB}
.PATH: ${LIBBEGEMOT_DIR}
LIB= begemot
diff --git a/lib/libblocksruntime/Makefile b/lib/libblocksruntime/Makefile
index f95393311142..5933fb5253d2 100644
--- a/lib/libblocksruntime/Makefile
+++ b/lib/libblocksruntime/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB:tl}
LIB= BlocksRuntime
SHLIB_MAJOR=0
CFLAGS+=-I${.CURDIR}
diff --git a/lib/libbluetooth/Makefile b/lib/libbluetooth/Makefile
index 7e2189221b8e..a8573ec2fffa 100644
--- a/lib/libbluetooth/Makefile
+++ b/lib/libbluetooth/Makefile
@@ -1,6 +1,7 @@
# $Id: Makefile,v 1.5 2003/07/22 18:38:04 max Exp $
# $FreeBSD$
+PACKAGE= lib${LIB}
LIB= bluetooth
MAN= bluetooth.3
diff --git a/lib/libbsdstat/Makefile b/lib/libbsdstat/Makefile
index aef0ec241923..dea45f52b92b 100644
--- a/lib/libbsdstat/Makefile
+++ b/lib/libbsdstat/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= lib${LIB}
LIB= bsdstat
SHLIB_MAJOR= 1
PRIVATELIB=
diff --git a/lib/libbsm/Makefile b/lib/libbsm/Makefile
index 037def718bcd..4416227da066 100644
--- a/lib/libbsm/Makefile
+++ b/lib/libbsm/Makefile
@@ -2,6 +2,7 @@
# $FreeBSD$
#
+PACKAGE= lib${LIB}
OPENBSMDIR= ${.CURDIR}/../../contrib/openbsm
_LIBBSMDIR= ${OPENBSMDIR}/libbsm
diff --git a/lib/libbsnmp/Makefile.inc b/lib/libbsnmp/Makefile.inc
index 82f48accf146..5c3fdade33e7 100644
--- a/lib/libbsnmp/Makefile.inc
+++ b/lib/libbsnmp/Makefile.inc
@@ -2,5 +2,6 @@
NO_WERROR=
INCSDIR= ${INCLUDEDIR}/bsnmp
+PACKAGE= bsnmp
.include "../Makefile.inc"
diff --git a/lib/libbz2/Makefile b/lib/libbz2/Makefile
index b505927b4fb7..93c724ee0954 100644
--- a/lib/libbz2/Makefile
+++ b/lib/libbz2/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= lib${LIB}
BZ2DIR= ${.CURDIR}/../../contrib/bzip2
.PATH: ${BZ2DIR}
diff --git a/lib/libc++/Makefile b/lib/libc++/Makefile
index 94e91b94b003..7794928bc328 100644
--- a/lib/libc++/Makefile
+++ b/lib/libc++/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE= clibs
_LIBCXXRTDIR= ${.CURDIR}/../../contrib/libcxxrt
HDRDIR= ${.CURDIR}/../../contrib/libc++/include
SRCDIR= ${.CURDIR}/../../contrib/libc++/src
diff --git a/lib/libc/Makefile b/lib/libc/Makefile
index 707fc1a46a18..17b9720f3605 100644
--- a/lib/libc/Makefile
+++ b/lib/libc/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.2 (Berkeley) 2/3/94
# $FreeBSD$
+PACKAGE= clibs
SHLIBDIR?= /lib
.include <src.opts.mk>
diff --git a/lib/libc/tests/Makefile b/lib/libc/tests/Makefile
index ff1af5514501..8276422cc7f4 100644
--- a/lib/libc/tests/Makefile
+++ b/lib/libc/tests/Makefile
@@ -2,6 +2,10 @@
.include <src.opts.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
SUBDIR= tls_dso
TESTS_SUBDIRS= c063
diff --git a/lib/libc/tests/c063/Makefile b/lib/libc/tests/c063/Makefile
index 05da6ea212a9..779062881249 100644
--- a/lib/libc/tests/c063/Makefile
+++ b/lib/libc/tests/c063/Makefile
@@ -2,6 +2,10 @@
#TODO: t_o_search
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_C= faccessat_test
NETBSD_ATF_TESTS_C+= fchmodat_test
NETBSD_ATF_TESTS_C+= fchownat_test
diff --git a/lib/libc/tests/db/Makefile b/lib/libc/tests/db/Makefile
index eb0ce395e28a..ffe90d0b7a77 100644
--- a/lib/libc/tests/db/Makefile
+++ b/lib/libc/tests/db/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
BINDIR= ${TESTSDIR}
PROGS= h_db
diff --git a/lib/libc/tests/gen/Makefile b/lib/libc/tests/gen/Makefile
index 083097730cc0..b4e14d97151c 100644
--- a/lib/libc/tests/gen/Makefile
+++ b/lib/libc/tests/gen/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_C+= arc4random_test
ATF_TESTS_C+= fmtcheck2_test
ATF_TESTS_C+= fmtmsg_test
diff --git a/lib/libc/tests/gen/execve/Makefile b/lib/libc/tests/gen/execve/Makefile
index 5e8bc6fb7640..a9800db5fcf9 100644
--- a/lib/libc/tests/gen/execve/Makefile
+++ b/lib/libc/tests/gen/execve/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_C= execve_test
.include "../../Makefile.netbsd-tests"
diff --git a/lib/libc/tests/gen/posix_spawn/Makefile b/lib/libc/tests/gen/posix_spawn/Makefile
index 9b687c6d5fed..659f73bad2c7 100644
--- a/lib/libc/tests/gen/posix_spawn/Makefile
+++ b/lib/libc/tests/gen/posix_spawn/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
BINDIR= ${TESTSDIR}
NETBSD_ATF_TESTS_C= fileactions_test
diff --git a/lib/libc/tests/hash/Makefile b/lib/libc/tests/hash/Makefile
index 6facb5a1bdf0..188ba7f1400e 100644
--- a/lib/libc/tests/hash/Makefile
+++ b/lib/libc/tests/hash/Makefile
@@ -2,6 +2,10 @@
.include <src.opts.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_C=
.if ${MK_OPENSSL} != "no"
diff --git a/lib/libc/tests/inet/Makefile b/lib/libc/tests/inet/Makefile
index ee6f98e2f71f..f06150834cb2 100644
--- a/lib/libc/tests/inet/Makefile
+++ b/lib/libc/tests/inet/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_C= inet_network_test
.include "../Makefile.netbsd-tests"
diff --git a/lib/libc/tests/locale/Makefile b/lib/libc/tests/locale/Makefile
index e05cbae3ac9f..5a5954ac7db9 100644
--- a/lib/libc/tests/locale/Makefile
+++ b/lib/libc/tests/locale/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_C+= btowc_test
ATF_TESTS_C+= c16rtomb_test
ATF_TESTS_C+= iswctype_test
diff --git a/lib/libc/tests/net/Makefile b/lib/libc/tests/net/Makefile
index e126848f9727..56710c150aa8 100644
--- a/lib/libc/tests/net/Makefile
+++ b/lib/libc/tests/net/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_C+= ether_test
ATF_TESTS_C+= eui64_aton_test
ATF_TESTS_C+= eui64_ntoa_test
diff --git a/lib/libc/tests/nss/Makefile b/lib/libc/tests/nss/Makefile
index 1b777c2b26d3..da676a732e9e 100644
--- a/lib/libc/tests/nss/Makefile
+++ b/lib/libc/tests/nss/Makefile
@@ -1,6 +1,10 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/lib/libc/nss
+
BINDIR= ${TESTSDIR}
.PATH: ${.CURDIR:H}/resolv
diff --git a/lib/libc/tests/regex/Makefile b/lib/libc/tests/regex/Makefile
index 946bc445846b..f60d512dc09b 100644
--- a/lib/libc/tests/regex/Makefile
+++ b/lib/libc/tests/regex/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
BINDIR= ${TESTSDIR}
IMPLEMENTATION?= -DREGEX_SPENCER
diff --git a/lib/libc/tests/resolv/Makefile b/lib/libc/tests/resolv/Makefile
index 4fb43d8955ed..cc17ef59afac 100644
--- a/lib/libc/tests/resolv/Makefile
+++ b/lib/libc/tests/resolv/Makefile
@@ -1,6 +1,10 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/lib/libc/resolv
+
BINDIR= ${TESTSDIR}
FILES+= mach
diff --git a/lib/libc/tests/rpc/Makefile b/lib/libc/tests/rpc/Makefile
index d7780ef4b86c..6a6ae7b1c639 100644
--- a/lib/libc/tests/rpc/Makefile
+++ b/lib/libc/tests/rpc/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
SRCS.xdr_test= ${RPCSRC:.x=_xdr.c} t_xdr.c ${RPCSRC:.x=.h} \
h_testbits.h
diff --git a/lib/libc/tests/setjmp/Makefile b/lib/libc/tests/setjmp/Makefile
index 39b0a96295f4..b645b4d8eb07 100644
--- a/lib/libc/tests/setjmp/Makefile
+++ b/lib/libc/tests/setjmp/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_C= setjmp_test
NETBSD_ATF_TESTS_C+= threadjmp_test
diff --git a/lib/libc/tests/ssp/Makefile b/lib/libc/tests/ssp/Makefile
index 61cacedfb3a6..09adf97d5560 100644
--- a/lib/libc/tests/ssp/Makefile
+++ b/lib/libc/tests/ssp/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NO_WERROR=
WARNS?= 2
diff --git a/lib/libc/tests/stdio/Makefile b/lib/libc/tests/stdio/Makefile
index 72685e078e72..50484fd54b44 100644
--- a/lib/libc/tests/stdio/Makefile
+++ b/lib/libc/tests/stdio/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_C+= fdopen_test
ATF_TESTS_C+= fmemopen2_test
ATF_TESTS_C+= fopen2_test
diff --git a/lib/libc/tests/stdlib/Makefile b/lib/libc/tests/stdlib/Makefile
index 87e84c5df51c..08f34b0a0e28 100644
--- a/lib/libc/tests/stdlib/Makefile
+++ b/lib/libc/tests/stdlib/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_C+= heapsort_test
ATF_TESTS_C+= mergesort_test
ATF_TESTS_C+= qsort_test
diff --git a/lib/libc/tests/string/Makefile b/lib/libc/tests/string/Makefile
index ea2dfcff20f0..a8db9c33b760 100644
--- a/lib/libc/tests/string/Makefile
+++ b/lib/libc/tests/string/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_C+= memcmp_test
ATF_TESTS_C+= stpncpy_test
ATF_TESTS_C+= strerror2_test
diff --git a/lib/libc/tests/sys/Makefile b/lib/libc/tests/sys/Makefile
index c7b005301527..e79204a38a6e 100644
--- a/lib/libc/tests/sys/Makefile
+++ b/lib/libc/tests/sys/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_C+= queue_test
# TODO: clone, lwp_create, lwp_ctl, posix_fadvise, recvmmsg,
@@ -68,13 +72,15 @@ WARNS?= 3
WARNS?= 4
.endif
-FILESGROUPS= FILES truncate_test_FILES
+FILESGROUPS+= FILES truncate_test_FILES
truncate_test_FILES= truncate_test.root_owned
truncate_test_FILESDIR= ${TESTSDIR}
truncate_test_FILESMODE= 0600
truncate_test_FILESOWNER= root
truncate_test_FILESGRP= wheel
+truncate_test_FILESPACKAGE= ${PACKAGE}
+FILESPACKAGE= ${PACKAGE}
CLEANFILES= truncate_test.root_owned
truncate_test.root_owned:
diff --git a/lib/libc/tests/termios/Makefile b/lib/libc/tests/termios/Makefile
index 0495d684b505..81b0ff1d8ba6 100644
--- a/lib/libc/tests/termios/Makefile
+++ b/lib/libc/tests/termios/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_C= tcsetpgrp_test
.include "../Makefile.netbsd-tests"
diff --git a/lib/libc/tests/time/Makefile b/lib/libc/tests/time/Makefile
index feb543dad243..49745e2331ec 100644
--- a/lib/libc/tests/time/Makefile
+++ b/lib/libc/tests/time/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_C= mktime_test
NETBSD_ATF_TESTS_C+= strptime_test
diff --git a/lib/libc/tests/tls/Makefile b/lib/libc/tests/tls/Makefile
index cbf441d6e1b1..0e98fed0ba18 100644
--- a/lib/libc/tests/tls/Makefile
+++ b/lib/libc/tests/tls/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
.if !defined(NO_PIC)
SUBDIR+= dso
.endif
diff --git a/lib/libc/tests/tls/dso/Makefile b/lib/libc/tests/tls/dso/Makefile
index 9b698cd5f5c2..74f826aeaaf5 100644
--- a/lib/libc/tests/tls/dso/Makefile
+++ b/lib/libc/tests/tls/dso/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
OBJTOP= ${.OBJDIR:H:H:H:H:H}
TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libc/tls/${.CURDIR:T}
diff --git a/lib/libc/tests/tls_dso/Makefile b/lib/libc/tests/tls_dso/Makefile
index 5449799de96c..79b05f89e3c9 100644
--- a/lib/libc/tests/tls_dso/Makefile
+++ b/lib/libc/tests/tls_dso/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
LIB= h_tls_dynamic
SRCS= h_tls_dynamic.c
diff --git a/lib/libc/tests/ttyio/Makefile b/lib/libc/tests/ttyio/Makefile
index d5b8f0168558..c9520fbdb318 100644
--- a/lib/libc/tests/ttyio/Makefile
+++ b/lib/libc/tests/ttyio/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
# TODO: ptm_test
NETBSD_ATF_TESTS_C= ttyio_test
diff --git a/lib/libcalendar/Makefile b/lib/libcalendar/Makefile
index b0ae002fd5e9..d217a10a7f5c 100644
--- a/lib/libcalendar/Makefile
+++ b/lib/libcalendar/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= lib${LIB}
LIB= calendar
SRCS= calendar.c easter.c
diff --git a/lib/libcam/Makefile b/lib/libcam/Makefile
index c44836947d51..a4cae7aa8a6c 100644
--- a/lib/libcam/Makefile
+++ b/lib/libcam/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= lib${LIB}
LIB= cam
SHLIBDIR?= /lib
SRCS= camlib.c scsi_cmdparse.c scsi_all.c scsi_da.c scsi_sa.c cam.c \
diff --git a/lib/libcapsicum/Makefile b/lib/libcapsicum/Makefile
new file mode 100644
index 000000000000..bf34f6f4ffc1
--- /dev/null
+++ b/lib/libcapsicum/Makefile
@@ -0,0 +1,47 @@
+# $FreeBSD$
+
+PACKAGE= lib${LIB}
+LIB= capsicum
+
+SHLIB_MAJOR= 0
+SHLIBDIR?= /lib
+
+SRCS= libcapsicum.c
+SRCS+= libcapsicum_dns.c
+SRCS+= libcapsicum_grp.c
+SRCS+= libcapsicum_pwd.c
+SRCS+= libcapsicum_random.c
+SRCS+= libcapsicum_service.c
+SRCS+= libcapsicum_sysctl.c
+
+INCS= libcapsicum.h
+INCS+= libcapsicum_dns.h
+INCS+= libcapsicum_grp.h
+INCS+= libcapsicum_pwd.h
+INCS+= libcapsicum_random.h
+INCS+= libcapsicum_service.h
+INCS+= libcapsicum_sysctl.h
+
+LIBADD= nv
+
+CFLAGS+=-I${.CURDIR}
+CFLAGS+=-I${.CURDIR}/../libnv
+
+WARNS?= 6
+
+MAN+= libcapsicum.3
+
+MLINKS+=libcapsicum.3 cap_init.3
+MLINKS+=libcapsicum.3 cap_wrap.3
+MLINKS+=libcapsicum.3 cap_unwrap.3
+MLINKS+=libcapsicum.3 cap_sock.3
+MLINKS+=libcapsicum.3 cap_clone.3
+MLINKS+=libcapsicum.3 cap_close.3
+MLINKS+=libcapsicum.3 cap_limit_get.3
+MLINKS+=libcapsicum.3 cap_limit_set.3
+MLINKS+=libcapsicum.3 cap_send_nvlist.3
+MLINKS+=libcapsicum.3 cap_recv_nvlist.3
+MLINKS+=libcapsicum.3 cap_xfer_nvlist.3
+MLINKS+=libcapsicum.3 cap_service_open.3
+
+.include <bsd.lib.mk>
diff --git a/lib/libcapsicum/Makefile.depend b/lib/libcapsicum/Makefile.depend
new file mode 100644
index 000000000000..4f7989bd2e64
--- /dev/null
+++ b/lib/libcapsicum/Makefile.depend
@@ -0,0 +1,19 @@
+# $FreeBSD$
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcompiler_rt \
+ lib/libnv \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/lib/libcapsicum/libcapsicum.3 b/lib/libcapsicum/libcapsicum.3
new file mode 100644
index 000000000000..cbfd214a3bc5
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum.3
@@ -0,0 +1,300 @@
+.\" Copyright (c) 2013 The FreeBSD Foundation
+.\" All rights reserved.
+.\"
+.\" This documentation was written by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd May 2, 2015
+.Dt LIBCAPSICUM 3
+.Os
+.Sh NAME
+.Nm cap_init ,
+.Nm cap_wrap ,
+.Nm cap_unwrap ,
+.Nm cap_sock ,
+.Nm cap_clone ,
+.Nm cap_close ,
+.Nm cap_limit_get ,
+.Nm cap_limit_set ,
+.Nm cap_send_nvlist ,
+.Nm cap_recv_nvlist ,
+.Nm cap_xfer_nvlist ,
+.Nm cap_service_open
+.Nd "library for handling application capabilities"
+.Sh LIBRARY
+.Lb libcapsicum
+.Sh SYNOPSIS
+.In libcapsicum.h
+.In nv.h
+.Ft "cap_channel_t *"
+.Fn cap_init "void"
+.Ft "cap_channel_t *"
+.Fn cap_wrap "int sock"
+.Ft "int"
+.Fn cap_unwrap "cap_channel_t *chan"
+.Ft "int"
+.Fn cap_sock "const cap_channel_t *chan"
+.Ft "cap_channel_t *"
+.Fn cap_clone "const cap_channel_t *chan"
+.Ft "void"
+.Fn cap_close "cap_channel_t *chan"
+.Ft "int"
+.Fn cap_limit_get "const cap_channel_t *chan" "nvlist_t **limitsp"
+.Ft "int"
+.Fn cap_limit_set "const cap_channel_t *chan" "nvlist_t *limits"
+.Ft "int"
+.Fn cap_send_nvlist "const cap_channel_t *chan" "const nvlist_t *nvl"
+.Ft "nvlist_t *"
+.Fn cap_recv_nvlist "const cap_channel_t *chan" "int flags"
+.Ft "nvlist_t *"
+.Fn cap_xfer_nvlist "const cap_channel_t *chan" "nvlist_t *nvl" "int flags"
+.In libcapsicum_service.h
+.Ft "cap_channel_t *"
+.Fn cap_service_open "const cap_channel_t *chan" "const char *name"
+.Sh DESCRIPTION
+The
+.Nm libcapsicum
+library allows to manage application capabilities through the
+.Xr casperd 8
+daemon.
+.Pp
+The application capability (represented by the
+.Vt cap_channel_t
+type) is a communication channel between the caller and the
+.Xr casperd 8
+daemon or an instance of one of its services.
+A capability to the
+.Xr casperd 8
+daemon obtained with the
+.Fn cap_init
+function allows to create capabilities to casper's services via the
+.Fn cap_service_open
+function.
+.Pp
+The
+.Fn cap_init
+function opens capability to the
+.Xr casperd 8
+daemon.
+.Pp
+The
+.Fn cap_wrap
+function creates
+.Vt cap_channel_t
+based on the given socket.
+The function is used when capability is inherited through
+.Xr execve 2
+or send over
+.Xr unix 4
+domain socket as a regular file descriptor and has to be represented as
+.Vt cap_channel_t
+again.
+.Pp
+The
+.Fn cap_unwrap
+function is the opposite of the
+.Fn cap_wrap
+function.
+It frees the
+.Vt cap_channel_t
+structure and returns
+.Xr unix 4
+domain socket associated with it.
+.Pp
+The
+.Fn cap_clone
+function clones the given capability.
+.Pp
+The
+.Fn cap_close
+function closes the given capability.
+.Pp
+The
+.Fn cap_sock
+function returns
+.Xr unix 4
+domain socket descriptor associated with the given capability for use with
+system calls like
+.Xr kevent 2 ,
+.Xr poll 2
+and
+.Xr select 2 .
+.Pp
+The
+.Fn cap_limit_get
+function stores current limits of the given capability in the
+.Fa limitsp
+argument.
+If the function return
+.Va 0
+and
+.Dv NULL
+is stored in
+.Fa limitsp
+it means there are no limits set.
+.Pp
+The
+.Fn cap_limit_set
+function sets limits for the given capability.
+The limits are provided as nvlist.
+The exact format depends on the service the capability represents.
+.Pp
+The
+.Fn cap_send_nvlist
+function sends the given nvlist over the given capability.
+This is low level interface to communicate with casper services.
+Most services should provide higher level API.
+.Pp
+The
+.Fn cap_recv_nvlist
+function receives the given nvlist over the given capability.
+The
+.Fa flags
+argument defines what type the top nvlist is expected to be.
+If the nvlist flags do not match the flags passed to
+.Fn cap_recv_nvlist ,
+the nvlist will not be returned.
+.Pp
+The
+.Fn cap_xfer_nvlist
+function sends the given nvlist, destroys it and receives new nvlist in
+response over the given capability.
+The
+.Fa flags
+argument defines what type the top nvlist is expected to be.
+If the nvlist flags do not match the flags passed to
+.Fn cap_xfer_nvlist ,
+the nvlist will not be returned.
+It does not matter if the function succeeds or fails, the nvlist given
+for sending will always be destroyed once the function returns.
+.Pp
+The
+.Fn cap_service_open
+function opens casper service of the given name through casper capability
+obtained via the
+.Fn cap_init
+function.
+The function returns capability that provides access to opened service.
+.Sh RETURN VALUES
+The
+.Fn cap_clone ,
+.Fn cap_init ,
+.Fn cap_recv_nvlist ,
+.Fn cap_service_open ,
+.Fn cap_wrap
+and
+.Fn cap_xfer_nvlist
+functions return
+.Dv NULL
+and set the
+.Va errno
+variable on failure.
+.Pp
+The
+.Fn cap_limit_get ,
+.Fn cap_limit_set
+and
+.Fn cap_send_nvlist
+functions return
+.Dv -1
+and set the
+.Va errno
+variable on failure.
+.Pp
+The
+.Fn cap_close ,
+.Fn cap_sock
+and
+.Fn cap_unwrap
+functions always succeed.
+.Sh EXAMPLES
+The following example first opens capability to the
+.Xr casperd 8
+daemon, then using this capability creates new capability to the
+.Nm system.dns
+casper service and uses the latter capability to resolve IP address.
+.Bd -literal
+cap_channel_t *capcas, *capdns;
+nvlist_t *limits;
+const char *ipstr = "127.0.0.1";
+struct in_addr ip;
+struct hostent *hp;
+
+/* Open capability to the Casper daemon. */
+capcas = cap_init();
+if (capcas == NULL)
+ err(1, "Unable to contact Casper daemon");
+
+/* Enter capability mode sandbox. */
+if (cap_enter() < 0 && errno != ENOSYS)
+ err(1, "Unable to enter capability mode");
+
+/* Use Casper capability to create capability to the system.dns service. */
+capdns = cap_service_open(capcas, "system.dns");
+if (capdns == NULL)
+ err(1, "Unable to open system.dns service");
+
+/* Close Casper capability, we don't need it anymore. */
+cap_close(capcas);
+
+/* Limit system.dns to reverse DNS lookups and IPv4 addresses. */
+limits = nvlist_create(0);
+nvlist_add_string(limits, "type", "ADDR");
+nvlist_add_number(limits, "family", (uint64_t)AF_INET);
+if (cap_limit_set(capdns, limits) < 0)
+ err(1, "Unable to limit access to the system.dns service");
+
+/* Convert IP address in C-string to in_addr. */
+if (!inet_aton(ipstr, &ip))
+ errx(1, "Unable to parse IP address %s.", ipstr);
+
+/* Find hostname for the given IP address. */
+hp = cap_gethostbyaddr(capdns, (const void *)&ip, sizeof(ip), AF_INET);
+if (hp == NULL)
+ errx(1, "No name associated with %s.", ipstr);
+
+printf("Name associated with %s is %s.\\n", ipstr, hp->h_name);
+.Ed
+.Sh SEE ALSO
+.Xr cap_enter 2 ,
+.Xr execve 2 ,
+.Xr kevent 2 ,
+.Xr poll 2 ,
+.Xr select 2 ,
+.Xr cap_gethostbyaddr 3 ,
+.Xr err 3 ,
+.Xr gethostbyaddr 3 ,
+.Xr inet_aton 3 ,
+.Xr nv 3 ,
+.Xr capsicum 4 ,
+.Xr unix 4 ,
+.Xr casperd 8
+.Sh AUTHORS
+The
+.Nm libcapsicum
+library was implemented by
+.An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net
+under sponsorship from the FreeBSD Foundation.
diff --git a/lib/libcapsicum/libcapsicum.c b/lib/libcapsicum/libcapsicum.c
new file mode 100644
index 000000000000..8c4d04da157e
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum.c
@@ -0,0 +1,266 @@
+/*-
+ * Copyright (c) 2012-2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/nv.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "libcapsicum.h"
+#include "libcapsicum_impl.h"
+
+/*
+ * Structure describing communication channel between two separated processes.
+ */
+#define CAP_CHANNEL_MAGIC 0xcac8a31
+struct cap_channel {
+ /*
+ * Magic value helps to ensure that a pointer to the right structure is
+ * passed to our functions.
+ */
+ int cch_magic;
+ /* Socket descriptor for IPC. */
+ int cch_sock;
+};
+
+bool
+fd_is_valid(int fd)
+{
+
+ return (fcntl(fd, F_GETFL) != -1 || errno != EBADF);
+}
+
+cap_channel_t *
+cap_init(void)
+{
+ cap_channel_t *chan;
+ struct sockaddr_un sun;
+ int serrno, sock;
+
+ bzero(&sun, sizeof(sun));
+ sun.sun_family = AF_UNIX;
+ strlcpy(sun.sun_path, CASPER_SOCKPATH, sizeof(sun.sun_path));
+ sun.sun_len = SUN_LEN(&sun);
+
+ sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sock == -1)
+ return (NULL);
+ if (connect(sock, (struct sockaddr *)&sun, sizeof(sun)) < 0) {
+ serrno = errno;
+ close(sock);
+ errno = serrno;
+ return (NULL);
+ }
+ chan = cap_wrap(sock);
+ if (chan == NULL) {
+ serrno = errno;
+ close(sock);
+ errno = serrno;
+ return (NULL);
+ }
+ return (chan);
+}
+
+cap_channel_t *
+cap_wrap(int sock)
+{
+ cap_channel_t *chan;
+
+ if (!fd_is_valid(sock))
+ return (NULL);
+
+ chan = malloc(sizeof(*chan));
+ if (chan != NULL) {
+ chan->cch_sock = sock;
+ chan->cch_magic = CAP_CHANNEL_MAGIC;
+ }
+
+ return (chan);
+}
+
+int
+cap_unwrap(cap_channel_t *chan)
+{
+ int sock;
+
+ assert(chan != NULL);
+ assert(chan->cch_magic == CAP_CHANNEL_MAGIC);
+
+ sock = chan->cch_sock;
+ chan->cch_magic = 0;
+ free(chan);
+
+ return (sock);
+}
+
+cap_channel_t *
+cap_clone(const cap_channel_t *chan)
+{
+ cap_channel_t *newchan;
+ nvlist_t *nvl;
+ int newsock;
+
+ assert(chan != NULL);
+ assert(chan->cch_magic == CAP_CHANNEL_MAGIC);
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", "clone");
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL)
+ return (NULL);
+ if (nvlist_get_number(nvl, "error") != 0) {
+ errno = (int)nvlist_get_number(nvl, "error");
+ nvlist_destroy(nvl);
+ return (NULL);
+ }
+ newsock = nvlist_take_descriptor(nvl, "sock");
+ nvlist_destroy(nvl);
+ newchan = cap_wrap(newsock);
+ if (newchan == NULL) {
+ int serrno;
+
+ serrno = errno;
+ close(newsock);
+ errno = serrno;
+ }
+
+ return (newchan);
+}
+
+void
+cap_close(cap_channel_t *chan)
+{
+
+ assert(chan != NULL);
+ assert(chan->cch_magic == CAP_CHANNEL_MAGIC);
+
+ chan->cch_magic = 0;
+ close(chan->cch_sock);
+ free(chan);
+}
+
+int
+cap_sock(const cap_channel_t *chan)
+{
+
+ assert(chan != NULL);
+ assert(chan->cch_magic == CAP_CHANNEL_MAGIC);
+
+ return (chan->cch_sock);
+}
+
+int
+cap_limit_set(const cap_channel_t *chan, nvlist_t *limits)
+{
+ nvlist_t *nvlmsg;
+ int error;
+
+ nvlmsg = nvlist_create(0);
+ nvlist_add_string(nvlmsg, "cmd", "limit_set");
+ nvlist_add_nvlist(nvlmsg, "limits", limits);
+ nvlmsg = cap_xfer_nvlist(chan, nvlmsg, 0);
+ if (nvlmsg == NULL) {
+ nvlist_destroy(limits);
+ return (-1);
+ }
+ error = (int)nvlist_get_number(nvlmsg, "error");
+ nvlist_destroy(nvlmsg);
+ nvlist_destroy(limits);
+ if (error != 0) {
+ errno = error;
+ return (-1);
+ }
+ return (0);
+}
+
+int
+cap_limit_get(const cap_channel_t *chan, nvlist_t **limitsp)
+{
+ nvlist_t *nvlmsg;
+ int error;
+
+ nvlmsg = nvlist_create(0);
+ nvlist_add_string(nvlmsg, "cmd", "limit_get");
+ nvlmsg = cap_xfer_nvlist(chan, nvlmsg, 0);
+ if (nvlmsg == NULL)
+ return (-1);
+ error = (int)nvlist_get_number(nvlmsg, "error");
+ if (error != 0) {
+ nvlist_destroy(nvlmsg);
+ errno = error;
+ return (-1);
+ }
+ if (nvlist_exists_null(nvlmsg, "limits"))
+ *limitsp = NULL;
+ else
+ *limitsp = nvlist_take_nvlist(nvlmsg, "limits");
+ nvlist_destroy(nvlmsg);
+ return (0);
+}
+
+int
+cap_send_nvlist(const cap_channel_t *chan, const nvlist_t *nvl)
+{
+
+ assert(chan != NULL);
+ assert(chan->cch_magic == CAP_CHANNEL_MAGIC);
+
+ return (nvlist_send(chan->cch_sock, nvl));
+}
+
+nvlist_t *
+cap_recv_nvlist(const cap_channel_t *chan, int flags)
+{
+
+ assert(chan != NULL);
+ assert(chan->cch_magic == CAP_CHANNEL_MAGIC);
+
+ return (nvlist_recv(chan->cch_sock, flags));
+}
+
+nvlist_t *
+cap_xfer_nvlist(const cap_channel_t *chan, nvlist_t *nvl, int flags)
+{
+
+ assert(chan != NULL);
+ assert(chan->cch_magic == CAP_CHANNEL_MAGIC);
+
+ return (nvlist_xfer(chan->cch_sock, nvl, flags));
+}
diff --git a/lib/libcapsicum/libcapsicum.h b/lib/libcapsicum/libcapsicum.h
new file mode 100644
index 000000000000..c7110d86c9ed
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum.h
@@ -0,0 +1,115 @@
+/*-
+ * Copyright (c) 2012-2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LIBCAPSICUM_H_
+#define _LIBCAPSICUM_H_
+
+#ifndef _NVLIST_T_DECLARED
+#define _NVLIST_T_DECLARED
+struct nvlist;
+
+typedef struct nvlist nvlist_t;
+#endif
+
+#ifndef _CAP_CHANNEL_T_DECLARED
+#define _CAP_CHANNEL_T_DECLARED
+struct cap_channel;
+
+typedef struct cap_channel cap_channel_t;
+#endif
+
+/*
+ * The function opens unrestricted communication channel to Casper.
+ */
+cap_channel_t *cap_init(void);
+
+/*
+ * The function creates cap_channel_t based on the given socket.
+ */
+cap_channel_t *cap_wrap(int sock);
+
+/*
+ * The function returns communication socket and frees cap_channel_t.
+ */
+int cap_unwrap(cap_channel_t *chan);
+
+/*
+ * The function clones the given capability.
+ */
+cap_channel_t *cap_clone(const cap_channel_t *chan);
+
+/*
+ * The function closes the given capability.
+ */
+void cap_close(cap_channel_t *chan);
+
+/*
+ * The function returns socket descriptor associated with the given
+ * cap_channel_t for use with select(2)/kqueue(2)/etc.
+ */
+int cap_sock(const cap_channel_t *chan);
+
+/*
+ * The function limits the given capability.
+ * It always destroys 'limits' on return.
+ */
+int cap_limit_set(const cap_channel_t *chan, nvlist_t *limits);
+
+/*
+ * The function returns current limits of the given capability.
+ */
+int cap_limit_get(const cap_channel_t *chan, nvlist_t **limitsp);
+
+#ifdef TODO
+/*
+ * The function registers a service within provided Casper's capability.
+ * It will run with the same privileges the process has at the time of
+ * calling this function.
+ */
+int cap_service_register(cap_channel_t *chan, const char *name,
+ cap_func_t *func);
+#endif
+
+/*
+ * Function sends nvlist over the given capability.
+ */
+int cap_send_nvlist(const cap_channel_t *chan, const nvlist_t *nvl);
+/*
+ * Function receives nvlist over the given capability.
+ */
+nvlist_t *cap_recv_nvlist(const cap_channel_t *chan, int flags);
+/*
+ * Function sends the given nvlist, destroys it and receives new nvlist in
+ * response over the given capability.
+ */
+nvlist_t *cap_xfer_nvlist(const cap_channel_t *chan, nvlist_t *nvl, int flags);
+
+#endif /* !_LIBCAPSICUM_H_ */
diff --git a/lib/libcapsicum/libcapsicum_dns.c b/lib/libcapsicum/libcapsicum_dns.c
new file mode 100644
index 000000000000..5f54283a460c
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_dns.c
@@ -0,0 +1,365 @@
+/*-
+ * Copyright (c) 2012-2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/nv.h>
+
+#include <assert.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "libcapsicum.h"
+#include "libcapsicum_dns.h"
+
+static struct hostent hent;
+
+static void
+hostent_free(struct hostent *hp)
+{
+ unsigned int ii;
+
+ free(hp->h_name);
+ hp->h_name = NULL;
+ if (hp->h_aliases != NULL) {
+ for (ii = 0; hp->h_aliases[ii] != NULL; ii++)
+ free(hp->h_aliases[ii]);
+ free(hp->h_aliases);
+ hp->h_aliases = NULL;
+ }
+ if (hp->h_addr_list != NULL) {
+ for (ii = 0; hp->h_addr_list[ii] != NULL; ii++)
+ free(hp->h_addr_list[ii]);
+ free(hp->h_addr_list);
+ hp->h_addr_list = NULL;
+ }
+}
+
+static struct hostent *
+hostent_unpack(const nvlist_t *nvl, struct hostent *hp)
+{
+ unsigned int ii, nitems;
+ char nvlname[64];
+ int n;
+
+ hostent_free(hp);
+
+ hp->h_name = strdup(nvlist_get_string(nvl, "name"));
+ if (hp->h_name == NULL)
+ goto fail;
+ hp->h_addrtype = (int)nvlist_get_number(nvl, "addrtype");
+ hp->h_length = (int)nvlist_get_number(nvl, "length");
+
+ nitems = (unsigned int)nvlist_get_number(nvl, "naliases");
+ hp->h_aliases = calloc(sizeof(hp->h_aliases[0]), nitems + 1);
+ if (hp->h_aliases == NULL)
+ goto fail;
+ for (ii = 0; ii < nitems; ii++) {
+ n = snprintf(nvlname, sizeof(nvlname), "alias%u", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ hp->h_aliases[ii] =
+ strdup(nvlist_get_string(nvl, nvlname));
+ if (hp->h_aliases[ii] == NULL)
+ goto fail;
+ }
+ hp->h_aliases[ii] = NULL;
+
+ nitems = (unsigned int)nvlist_get_number(nvl, "naddrs");
+ hp->h_addr_list = calloc(sizeof(hp->h_addr_list[0]), nitems + 1);
+ if (hp->h_addr_list == NULL)
+ goto fail;
+ for (ii = 0; ii < nitems; ii++) {
+ hp->h_addr_list[ii] = malloc(hp->h_length);
+ if (hp->h_addr_list[ii] == NULL)
+ goto fail;
+ n = snprintf(nvlname, sizeof(nvlname), "addr%u", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ bcopy(nvlist_get_binary(nvl, nvlname, NULL),
+ hp->h_addr_list[ii], hp->h_length);
+ }
+ hp->h_addr_list[ii] = NULL;
+
+ return (hp);
+fail:
+ hostent_free(hp);
+ h_errno = NO_RECOVERY;
+ return (NULL);
+}
+
+struct hostent *
+cap_gethostbyname(cap_channel_t *chan, const char *name)
+{
+
+ return (cap_gethostbyname2(chan, name, AF_INET));
+}
+
+struct hostent *
+cap_gethostbyname2(cap_channel_t *chan, const char *name, int type)
+{
+ struct hostent *hp;
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", "gethostbyname");
+ nvlist_add_number(nvl, "family", (uint64_t)type);
+ nvlist_add_string(nvl, "name", name);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ if (nvlist_get_number(nvl, "error") != 0) {
+ h_errno = (int)nvlist_get_number(nvl, "error");
+ nvlist_destroy(nvl);
+ return (NULL);
+ }
+
+ hp = hostent_unpack(nvl, &hent);
+ nvlist_destroy(nvl);
+ return (hp);
+}
+
+struct hostent *
+cap_gethostbyaddr(cap_channel_t *chan, const void *addr, socklen_t len,
+ int type)
+{
+ struct hostent *hp;
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", "gethostbyaddr");
+ nvlist_add_binary(nvl, "addr", addr, (size_t)len);
+ nvlist_add_number(nvl, "family", (uint64_t)type);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL) {
+ h_errno = NO_RECOVERY;
+ return (NULL);
+ }
+ if (nvlist_get_number(nvl, "error") != 0) {
+ h_errno = (int)nvlist_get_number(nvl, "error");
+ nvlist_destroy(nvl);
+ return (NULL);
+ }
+ hp = hostent_unpack(nvl, &hent);
+ nvlist_destroy(nvl);
+ return (hp);
+}
+
+static struct addrinfo *
+addrinfo_unpack(const nvlist_t *nvl)
+{
+ struct addrinfo *ai;
+ const void *addr;
+ size_t addrlen;
+ const char *canonname;
+
+ addr = nvlist_get_binary(nvl, "ai_addr", &addrlen);
+ ai = malloc(sizeof(*ai) + addrlen);
+ if (ai == NULL)
+ return (NULL);
+ ai->ai_flags = (int)nvlist_get_number(nvl, "ai_flags");
+ ai->ai_family = (int)nvlist_get_number(nvl, "ai_family");
+ ai->ai_socktype = (int)nvlist_get_number(nvl, "ai_socktype");
+ ai->ai_protocol = (int)nvlist_get_number(nvl, "ai_protocol");
+ ai->ai_addrlen = (socklen_t)addrlen;
+ canonname = nvlist_get_string(nvl, "ai_canonname");
+ if (canonname != NULL) {
+ ai->ai_canonname = strdup(canonname);
+ if (ai->ai_canonname == NULL) {
+ free(ai);
+ return (NULL);
+ }
+ } else {
+ ai->ai_canonname = NULL;
+ }
+ ai->ai_addr = (void *)(ai + 1);
+ bcopy(addr, ai->ai_addr, addrlen);
+ ai->ai_next = NULL;
+
+ return (ai);
+}
+
+int
+cap_getaddrinfo(cap_channel_t *chan, const char *hostname, const char *servname,
+ const struct addrinfo *hints, struct addrinfo **res)
+{
+ struct addrinfo *firstai, *prevai, *curai;
+ unsigned int ii;
+ const nvlist_t *nvlai;
+ char nvlname[64];
+ nvlist_t *nvl;
+ int error, n;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", "getaddrinfo");
+ nvlist_add_string(nvl, "hostname", hostname);
+ nvlist_add_string(nvl, "servname", servname);
+ if (hints != NULL) {
+ nvlist_add_number(nvl, "hints.ai_flags",
+ (uint64_t)hints->ai_flags);
+ nvlist_add_number(nvl, "hints.ai_family",
+ (uint64_t)hints->ai_family);
+ nvlist_add_number(nvl, "hints.ai_socktype",
+ (uint64_t)hints->ai_socktype);
+ nvlist_add_number(nvl, "hints.ai_protocol",
+ (uint64_t)hints->ai_protocol);
+ }
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL)
+ return (EAI_MEMORY);
+ if (nvlist_get_number(nvl, "error") != 0) {
+ error = (int)nvlist_get_number(nvl, "error");
+ nvlist_destroy(nvl);
+ return (error);
+ }
+
+ nvlai = NULL;
+ firstai = prevai = curai = NULL;
+ for (ii = 0; ; ii++) {
+ n = snprintf(nvlname, sizeof(nvlname), "res%u", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ if (!nvlist_exists_nvlist(nvl, nvlname))
+ break;
+ nvlai = nvlist_get_nvlist(nvl, nvlname);
+ curai = addrinfo_unpack(nvlai);
+ if (curai == NULL)
+ break;
+ if (prevai != NULL)
+ prevai->ai_next = curai;
+ else if (firstai == NULL)
+ firstai = curai;
+ prevai = curai;
+ }
+ nvlist_destroy(nvl);
+ if (curai == NULL && nvlai != NULL) {
+ if (firstai == NULL)
+ freeaddrinfo(firstai);
+ return (EAI_MEMORY);
+ }
+
+ *res = firstai;
+ return (0);
+}
+
+int
+cap_getnameinfo(cap_channel_t *chan, const struct sockaddr *sa, socklen_t salen,
+ char *host, size_t hostlen, char *serv, size_t servlen, int flags)
+{
+ nvlist_t *nvl;
+ int error;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", "getnameinfo");
+ nvlist_add_number(nvl, "hostlen", (uint64_t)hostlen);
+ nvlist_add_number(nvl, "servlen", (uint64_t)servlen);
+ nvlist_add_binary(nvl, "sa", sa, (size_t)salen);
+ nvlist_add_number(nvl, "flags", (uint64_t)flags);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL)
+ return (EAI_MEMORY);
+ if (nvlist_get_number(nvl, "error") != 0) {
+ error = (int)nvlist_get_number(nvl, "error");
+ nvlist_destroy(nvl);
+ return (error);
+ }
+
+ if (host != NULL)
+ strlcpy(host, nvlist_get_string(nvl, "host"), hostlen + 1);
+ if (serv != NULL)
+ strlcpy(serv, nvlist_get_string(nvl, "serv"), servlen + 1);
+ nvlist_destroy(nvl);
+ return (0);
+}
+
+static void
+limit_remove(nvlist_t *limits, const char *prefix)
+{
+ const char *name;
+ size_t prefixlen;
+ void *cookie;
+
+ prefixlen = strlen(prefix);
+again:
+ cookie = NULL;
+ while ((name = nvlist_next(limits, NULL, &cookie)) != NULL) {
+ if (strncmp(name, prefix, prefixlen) == 0) {
+ nvlist_free(limits, name);
+ goto again;
+ }
+ }
+}
+
+int
+cap_dns_type_limit(cap_channel_t *chan, const char * const *types,
+ size_t ntypes)
+{
+ nvlist_t *limits;
+ unsigned int i;
+ char nvlname[64];
+ int n;
+
+ if (cap_limit_get(chan, &limits) < 0)
+ return (-1);
+ if (limits == NULL)
+ limits = nvlist_create(0);
+ else
+ limit_remove(limits, "type");
+ for (i = 0; i < ntypes; i++) {
+ n = snprintf(nvlname, sizeof(nvlname), "type%u", i);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_string(limits, nvlname, types[i]);
+ }
+ return (cap_limit_set(chan, limits));
+}
+
+int
+cap_dns_family_limit(cap_channel_t *chan, const int *families,
+ size_t nfamilies)
+{
+ nvlist_t *limits;
+ unsigned int i;
+ char nvlname[64];
+ int n;
+
+ if (cap_limit_get(chan, &limits) < 0)
+ return (-1);
+ if (limits == NULL)
+ limits = nvlist_create(0);
+ else
+ limit_remove(limits, "family");
+ for (i = 0; i < nfamilies; i++) {
+ n = snprintf(nvlname, sizeof(nvlname), "family%u", i);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_number(limits, nvlname, (uint64_t)families[i]);
+ }
+ return (cap_limit_set(chan, limits));
+}
diff --git a/lib/libcapsicum/libcapsicum_dns.h b/lib/libcapsicum/libcapsicum_dns.h
new file mode 100644
index 000000000000..02235107cec4
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_dns.h
@@ -0,0 +1,57 @@
+/*-
+ * Copyright (c) 2012 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LIBCAPSICUM_DNS_H_
+#define _LIBCAPSICUM_DNS_H_
+
+#include <sys/socket.h> /* socklen_t */
+
+struct addrinfo;
+struct hostent;
+
+struct hostent *cap_gethostbyname(cap_channel_t *chan, const char *name);
+struct hostent *cap_gethostbyname2(cap_channel_t *chan, const char *name,
+ int type);
+struct hostent *cap_gethostbyaddr(cap_channel_t *chan, const void *addr,
+ socklen_t len, int type);
+
+int cap_getaddrinfo(cap_channel_t *chan, const char *hostname,
+ const char *servname, const struct addrinfo *hints, struct addrinfo **res);
+int cap_getnameinfo(cap_channel_t *chan, const struct sockaddr *sa,
+ socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen,
+ int flags);
+
+int cap_dns_type_limit(cap_channel_t *chan, const char * const *types,
+ size_t ntypes);
+int cap_dns_family_limit(cap_channel_t *chan, const int *families,
+ size_t nfamilies);
+
+#endif /* !_LIBCAPSICUM_DNS_H_ */
diff --git a/lib/libcapsicum/libcapsicum_grp.c b/lib/libcapsicum/libcapsicum_grp.c
new file mode 100644
index 000000000000..44d573e77b82
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_grp.c
@@ -0,0 +1,438 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/dnv.h>
+#include <sys/nv.h>
+#include <sys/param.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <grp.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "libcapsicum.h"
+#include "libcapsicum_grp.h"
+
+static struct group ggrp;
+static char *gbuffer;
+static size_t gbufsize;
+
+static int
+group_resize(void)
+{
+ char *buf;
+
+ if (gbufsize == 0)
+ gbufsize = 1024;
+ else
+ gbufsize *= 2;
+
+ buf = gbuffer;
+ gbuffer = realloc(buf, gbufsize);
+ if (gbuffer == NULL) {
+ free(buf);
+ gbufsize = 0;
+ return (ENOMEM);
+ }
+ memset(gbuffer, 0, gbufsize);
+
+ return (0);
+}
+
+static int
+group_unpack_string(const nvlist_t *nvl, const char *fieldname, char **fieldp,
+ char **bufferp, size_t *bufsizep)
+{
+ const char *str;
+ size_t len;
+
+ str = nvlist_get_string(nvl, fieldname);
+ len = strlcpy(*bufferp, str, *bufsizep);
+ if (len >= *bufsizep)
+ return (ERANGE);
+ *fieldp = *bufferp;
+ *bufferp += len + 1;
+ *bufsizep -= len + 1;
+
+ return (0);
+}
+
+static int
+group_unpack_members(const nvlist_t *nvl, char ***fieldp, char **bufferp,
+ size_t *bufsizep)
+{
+ const char *mem;
+ char **outstrs, *str, nvlname[64];
+ size_t nmem, datasize, strsize;
+ unsigned int ii;
+ int n;
+
+ if (!nvlist_exists_number(nvl, "gr_nmem")) {
+ datasize = _ALIGNBYTES + sizeof(char *);
+ if (datasize >= *bufsizep)
+ return (ERANGE);
+ outstrs = (char **)_ALIGN(*bufferp);
+ outstrs[0] = NULL;
+ *fieldp = outstrs;
+ *bufferp += datasize;
+ *bufsizep -= datasize;
+ return (0);
+ }
+
+ nmem = (size_t)nvlist_get_number(nvl, "gr_nmem");
+ datasize = _ALIGNBYTES + sizeof(char *) * (nmem + 1);
+ for (ii = 0; ii < nmem; ii++) {
+ n = snprintf(nvlname, sizeof(nvlname), "gr_mem[%u]", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ mem = dnvlist_get_string(nvl, nvlname, NULL);
+ if (mem == NULL)
+ return (EINVAL);
+ datasize += strlen(mem) + 1;
+ }
+
+ if (datasize >= *bufsizep)
+ return (ERANGE);
+
+ outstrs = (char **)_ALIGN(*bufferp);
+ str = (char *)outstrs + sizeof(char *) * (nmem + 1);
+ for (ii = 0; ii < nmem; ii++) {
+ n = snprintf(nvlname, sizeof(nvlname), "gr_mem[%u]", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ mem = nvlist_get_string(nvl, nvlname);
+ strsize = strlen(mem) + 1;
+ memcpy(str, mem, strsize);
+ outstrs[ii] = str;
+ str += strsize;
+ }
+ assert(ii == nmem);
+ outstrs[ii] = NULL;
+
+ *fieldp = outstrs;
+ *bufferp += datasize;
+ *bufsizep -= datasize;
+
+ return (0);
+}
+
+static int
+group_unpack(const nvlist_t *nvl, struct group *grp, char *buffer,
+ size_t bufsize)
+{
+ int error;
+
+ if (!nvlist_exists_string(nvl, "gr_name"))
+ return (EINVAL);
+
+ memset(grp, 0, sizeof(*grp));
+
+ error = group_unpack_string(nvl, "gr_name", &grp->gr_name, &buffer,
+ &bufsize);
+ if (error != 0)
+ return (error);
+ error = group_unpack_string(nvl, "gr_passwd", &grp->gr_passwd, &buffer,
+ &bufsize);
+ if (error != 0)
+ return (error);
+ grp->gr_gid = (gid_t)nvlist_get_number(nvl, "gr_gid");
+ error = group_unpack_members(nvl, &grp->gr_mem, &buffer, &bufsize);
+ if (error != 0)
+ return (error);
+
+ return (0);
+}
+
+static int
+cap_getgrcommon_r(cap_channel_t *chan, const char *cmd, const char *name,
+ gid_t gid, struct group *grp, char *buffer, size_t bufsize,
+ struct group **result)
+{
+ nvlist_t *nvl;
+ bool getgr_r;
+ int error;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", cmd);
+ if (strcmp(cmd, "getgrent") == 0 || strcmp(cmd, "getgrent_r") == 0) {
+ /* Add nothing. */
+ } else if (strcmp(cmd, "getgrnam") == 0 ||
+ strcmp(cmd, "getgrnam_r") == 0) {
+ nvlist_add_string(nvl, "name", name);
+ } else if (strcmp(cmd, "getgrgid") == 0 ||
+ strcmp(cmd, "getgrgid_r") == 0) {
+ nvlist_add_number(nvl, "gid", (uint64_t)gid);
+ } else {
+ abort();
+ }
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL) {
+ assert(errno != 0);
+ *result = NULL;
+ return (errno);
+ }
+ error = (int)nvlist_get_number(nvl, "error");
+ if (error != 0) {
+ nvlist_destroy(nvl);
+ *result = NULL;
+ return (error);
+ }
+
+ if (!nvlist_exists_string(nvl, "gr_name")) {
+ /* Not found. */
+ nvlist_destroy(nvl);
+ *result = NULL;
+ return (0);
+ }
+
+ getgr_r = (strcmp(cmd, "getgrent_r") == 0 ||
+ strcmp(cmd, "getgrnam_r") == 0 || strcmp(cmd, "getgrgid_r") == 0);
+
+ for (;;) {
+ error = group_unpack(nvl, grp, buffer, bufsize);
+ if (getgr_r || error != ERANGE)
+ break;
+ assert(buffer == gbuffer);
+ assert(bufsize == gbufsize);
+ error = group_resize();
+ if (error != 0)
+ break;
+ /* Update pointers after resize. */
+ buffer = gbuffer;
+ bufsize = gbufsize;
+ }
+
+ nvlist_destroy(nvl);
+
+ if (error == 0)
+ *result = grp;
+ else
+ *result = NULL;
+
+ return (error);
+}
+
+static struct group *
+cap_getgrcommon(cap_channel_t *chan, const char *cmd, const char *name,
+ gid_t gid)
+{
+ struct group *result;
+ int error, serrno;
+
+ serrno = errno;
+
+ error = cap_getgrcommon_r(chan, cmd, name, gid, &ggrp, gbuffer,
+ gbufsize, &result);
+ if (error != 0) {
+ errno = error;
+ return (NULL);
+ }
+
+ errno = serrno;
+
+ return (result);
+}
+
+struct group *
+cap_getgrent(cap_channel_t *chan)
+{
+
+ return (cap_getgrcommon(chan, "getgrent", NULL, 0));
+}
+
+struct group *
+cap_getgrnam(cap_channel_t *chan, const char *name)
+{
+
+ return (cap_getgrcommon(chan, "getgrnam", name, 0));
+}
+
+struct group *
+cap_getgrgid(cap_channel_t *chan, gid_t gid)
+{
+
+ return (cap_getgrcommon(chan, "getgrgid", NULL, gid));
+}
+
+int
+cap_getgrent_r(cap_channel_t *chan, struct group *grp, char *buffer,
+ size_t bufsize, struct group **result)
+{
+
+ return (cap_getgrcommon_r(chan, "getgrent_r", NULL, 0, grp, buffer,
+ bufsize, result));
+}
+
+int
+cap_getgrnam_r(cap_channel_t *chan, const char *name, struct group *grp,
+ char *buffer, size_t bufsize, struct group **result)
+{
+
+ return (cap_getgrcommon_r(chan, "getgrnam_r", name, 0, grp, buffer,
+ bufsize, result));
+}
+
+int
+cap_getgrgid_r(cap_channel_t *chan, gid_t gid, struct group *grp, char *buffer,
+ size_t bufsize, struct group **result)
+{
+
+ return (cap_getgrcommon_r(chan, "getgrgid_r", NULL, gid, grp, buffer,
+ bufsize, result));
+}
+
+int
+cap_setgroupent(cap_channel_t *chan, int stayopen)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", "setgroupent");
+ nvlist_add_bool(nvl, "stayopen", stayopen != 0);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL)
+ return (0);
+ if (nvlist_get_number(nvl, "error") != 0) {
+ errno = nvlist_get_number(nvl, "error");
+ nvlist_destroy(nvl);
+ return (0);
+ }
+ nvlist_destroy(nvl);
+
+ return (1);
+}
+
+int
+cap_setgrent(cap_channel_t *chan)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", "setgrent");
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL)
+ return (0);
+ if (nvlist_get_number(nvl, "error") != 0) {
+ errno = nvlist_get_number(nvl, "error");
+ nvlist_destroy(nvl);
+ return (0);
+ }
+ nvlist_destroy(nvl);
+
+ return (1);
+}
+
+void
+cap_endgrent(cap_channel_t *chan)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", "endgrent");
+ /* Ignore any errors, we have no way to report them. */
+ nvlist_destroy(cap_xfer_nvlist(chan, nvl, 0));
+}
+
+int
+cap_grp_limit_cmds(cap_channel_t *chan, const char * const *cmds, size_t ncmds)
+{
+ nvlist_t *limits, *nvl;
+ unsigned int i;
+
+ if (cap_limit_get(chan, &limits) < 0)
+ return (-1);
+ if (limits == NULL) {
+ limits = nvlist_create(0);
+ } else {
+ if (nvlist_exists_nvlist(limits, "cmds"))
+ nvlist_free_nvlist(limits, "cmds");
+ }
+ nvl = nvlist_create(0);
+ for (i = 0; i < ncmds; i++)
+ nvlist_add_null(nvl, cmds[i]);
+ nvlist_move_nvlist(limits, "cmds", nvl);
+ return (cap_limit_set(chan, limits));
+}
+
+int
+cap_grp_limit_fields(cap_channel_t *chan, const char * const *fields,
+ size_t nfields)
+{
+ nvlist_t *limits, *nvl;
+ unsigned int i;
+
+ if (cap_limit_get(chan, &limits) < 0)
+ return (-1);
+ if (limits == NULL) {
+ limits = nvlist_create(0);
+ } else {
+ if (nvlist_exists_nvlist(limits, "fields"))
+ nvlist_free_nvlist(limits, "fields");
+ }
+ nvl = nvlist_create(0);
+ for (i = 0; i < nfields; i++)
+ nvlist_add_null(nvl, fields[i]);
+ nvlist_move_nvlist(limits, "fields", nvl);
+ return (cap_limit_set(chan, limits));
+}
+
+int
+cap_grp_limit_groups(cap_channel_t *chan, const char * const *names,
+ size_t nnames, gid_t *gids, size_t ngids)
+{
+ nvlist_t *limits, *groups;
+ unsigned int i;
+ char nvlname[64];
+ int n;
+
+ if (cap_limit_get(chan, &limits) < 0)
+ return (-1);
+ if (limits == NULL) {
+ limits = nvlist_create(0);
+ } else {
+ if (nvlist_exists_nvlist(limits, "groups"))
+ nvlist_free_nvlist(limits, "groups");
+ }
+ groups = nvlist_create(0);
+ for (i = 0; i < ngids; i++) {
+ n = snprintf(nvlname, sizeof(nvlname), "gid%u", i);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_number(groups, nvlname, (uint64_t)gids[i]);
+ }
+ for (i = 0; i < nnames; i++) {
+ n = snprintf(nvlname, sizeof(nvlname), "gid%u", i);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_string(groups, nvlname, names[i]);
+ }
+ nvlist_move_nvlist(limits, "groups", groups);
+ return (cap_limit_set(chan, limits));
+}
diff --git a/lib/libcapsicum/libcapsicum_grp.h b/lib/libcapsicum/libcapsicum_grp.h
new file mode 100644
index 000000000000..e0b44f0e1996
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_grp.h
@@ -0,0 +1,57 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LIBCAPSICUM_GRP_H_
+#define _LIBCAPSICUM_GRP_H_
+
+struct group *cap_getgrent(cap_channel_t *chan);
+struct group *cap_getgrnam(cap_channel_t *chan, const char *name);
+struct group *cap_getgrgid(cap_channel_t *chan, gid_t gid);
+
+int cap_getgrent_r(cap_channel_t *chan, struct group *grp, char *buffer,
+ size_t bufsize, struct group **result);
+int cap_getgrnam_r(cap_channel_t *chan, const char *name, struct group *grp,
+ char *buffer, size_t bufsize, struct group **result);
+int cap_getgrgid_r(cap_channel_t *chan, gid_t gid, struct group *grp,
+ char *buffer, size_t bufsize, struct group **result);
+
+int cap_setgroupent(cap_channel_t *chan, int stayopen);
+int cap_setgrent(cap_channel_t *chan);
+void cap_endgrent(cap_channel_t *chan);
+
+int cap_grp_limit_cmds(cap_channel_t *chan, const char * const *cmds,
+ size_t ncmds);
+int cap_grp_limit_fields(cap_channel_t *chan, const char * const *fields,
+ size_t nfields);
+int cap_grp_limit_groups(cap_channel_t *chan, const char * const *names,
+ size_t nnames, gid_t *gids, size_t ngids);
+
+#endif /* !_LIBCAPSICUM_GRP_H_ */
diff --git a/lib/libcapsicum/libcapsicum_impl.h b/lib/libcapsicum/libcapsicum_impl.h
new file mode 100644
index 000000000000..ce6f49fdfcda
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_impl.h
@@ -0,0 +1,39 @@
+/*-
+ * Copyright (c) 2012-2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LIBCAPSICUM_IMPL_H_
+#define _LIBCAPSICUM_IMPL_H_
+
+#define CASPER_SOCKPATH "/var/run/casper"
+
+bool fd_is_valid(int fd);
+
+#endif /* !_LIBCAPSICUM_IMPL_H_ */
diff --git a/lib/libcapsicum/libcapsicum_pwd.c b/lib/libcapsicum/libcapsicum_pwd.c
new file mode 100644
index 000000000000..5b44c3463def
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_pwd.c
@@ -0,0 +1,391 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/nv.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "libcapsicum.h"
+#include "libcapsicum_pwd.h"
+
+static struct passwd gpwd;
+static char *gbuffer;
+static size_t gbufsize;
+
+static int
+passwd_resize(void)
+{
+ char *buf;
+
+ if (gbufsize == 0)
+ gbufsize = 1024;
+ else
+ gbufsize *= 2;
+
+ buf = gbuffer;
+ gbuffer = realloc(buf, gbufsize);
+ if (gbuffer == NULL) {
+ free(buf);
+ gbufsize = 0;
+ return (ENOMEM);
+ }
+ memset(gbuffer, 0, gbufsize);
+
+ return (0);
+}
+
+static int
+passwd_unpack_string(const nvlist_t *nvl, const char *fieldname, char **fieldp,
+ char **bufferp, size_t *bufsizep)
+{
+ const char *str;
+ size_t len;
+
+ str = nvlist_get_string(nvl, fieldname);
+ len = strlcpy(*bufferp, str, *bufsizep);
+ if (len >= *bufsizep)
+ return (ERANGE);
+ *fieldp = *bufferp;
+ *bufferp += len + 1;
+ *bufsizep -= len + 1;
+
+ return (0);
+}
+
+static int
+passwd_unpack(const nvlist_t *nvl, struct passwd *pwd, char *buffer,
+ size_t bufsize)
+{
+ int error;
+
+ if (!nvlist_exists_string(nvl, "pw_name"))
+ return (EINVAL);
+
+ memset(pwd, 0, sizeof(*pwd));
+
+ error = passwd_unpack_string(nvl, "pw_name", &pwd->pw_name, &buffer,
+ &bufsize);
+ if (error != 0)
+ return (error);
+ pwd->pw_uid = (uid_t)nvlist_get_number(nvl, "pw_uid");
+ pwd->pw_gid = (gid_t)nvlist_get_number(nvl, "pw_gid");
+ pwd->pw_change = (time_t)nvlist_get_number(nvl, "pw_change");
+ error = passwd_unpack_string(nvl, "pw_passwd", &pwd->pw_passwd, &buffer,
+ &bufsize);
+ if (error != 0)
+ return (error);
+ error = passwd_unpack_string(nvl, "pw_class", &pwd->pw_class, &buffer,
+ &bufsize);
+ if (error != 0)
+ return (error);
+ error = passwd_unpack_string(nvl, "pw_gecos", &pwd->pw_gecos, &buffer,
+ &bufsize);
+ if (error != 0)
+ return (error);
+ error = passwd_unpack_string(nvl, "pw_dir", &pwd->pw_dir, &buffer,
+ &bufsize);
+ if (error != 0)
+ return (error);
+ error = passwd_unpack_string(nvl, "pw_shell", &pwd->pw_shell, &buffer,
+ &bufsize);
+ if (error != 0)
+ return (error);
+ pwd->pw_expire = (time_t)nvlist_get_number(nvl, "pw_expire");
+ pwd->pw_fields = (int)nvlist_get_number(nvl, "pw_fields");
+
+ return (0);
+}
+
+static int
+cap_getpwcommon_r(cap_channel_t *chan, const char *cmd, const char *login,
+ uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize,
+ struct passwd **result)
+{
+ nvlist_t *nvl;
+ bool getpw_r;
+ int error;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", cmd);
+ if (strcmp(cmd, "getpwent") == 0 || strcmp(cmd, "getpwent_r") == 0) {
+ /* Add nothing. */
+ } else if (strcmp(cmd, "getpwnam") == 0 ||
+ strcmp(cmd, "getpwnam_r") == 0) {
+ nvlist_add_string(nvl, "name", login);
+ } else if (strcmp(cmd, "getpwuid") == 0 ||
+ strcmp(cmd, "getpwuid_r") == 0) {
+ nvlist_add_number(nvl, "uid", (uint64_t)uid);
+ } else {
+ abort();
+ }
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL) {
+ assert(errno != 0);
+ *result = NULL;
+ return (errno);
+ }
+ error = (int)nvlist_get_number(nvl, "error");
+ if (error != 0) {
+ nvlist_destroy(nvl);
+ *result = NULL;
+ return (error);
+ }
+
+ if (!nvlist_exists_string(nvl, "pw_name")) {
+ /* Not found. */
+ nvlist_destroy(nvl);
+ *result = NULL;
+ return (0);
+ }
+
+ getpw_r = (strcmp(cmd, "getpwent_r") == 0 ||
+ strcmp(cmd, "getpwnam_r") == 0 || strcmp(cmd, "getpwuid_r") == 0);
+
+ for (;;) {
+ error = passwd_unpack(nvl, pwd, buffer, bufsize);
+ if (getpw_r || error != ERANGE)
+ break;
+ assert(buffer == gbuffer);
+ assert(bufsize == gbufsize);
+ error = passwd_resize();
+ if (error != 0)
+ break;
+ /* Update pointers after resize. */
+ buffer = gbuffer;
+ bufsize = gbufsize;
+ }
+
+ nvlist_destroy(nvl);
+
+ if (error == 0)
+ *result = pwd;
+ else
+ *result = NULL;
+
+ return (error);
+}
+
+static struct passwd *
+cap_getpwcommon(cap_channel_t *chan, const char *cmd, const char *login,
+ uid_t uid)
+{
+ struct passwd *result;
+ int error, serrno;
+
+ serrno = errno;
+
+ error = cap_getpwcommon_r(chan, cmd, login, uid, &gpwd, gbuffer,
+ gbufsize, &result);
+ if (error != 0) {
+ errno = error;
+ return (NULL);
+ }
+
+ errno = serrno;
+
+ return (result);
+}
+
+struct passwd *
+cap_getpwent(cap_channel_t *chan)
+{
+
+ return (cap_getpwcommon(chan, "getpwent", NULL, 0));
+}
+
+struct passwd *
+cap_getpwnam(cap_channel_t *chan, const char *login)
+{
+
+ return (cap_getpwcommon(chan, "getpwnam", login, 0));
+}
+
+struct passwd *
+cap_getpwuid(cap_channel_t *chan, uid_t uid)
+{
+
+ return (cap_getpwcommon(chan, "getpwuid", NULL, uid));
+}
+
+int
+cap_getpwent_r(cap_channel_t *chan, struct passwd *pwd, char *buffer,
+ size_t bufsize, struct passwd **result)
+{
+
+ return (cap_getpwcommon_r(chan, "getpwent_r", NULL, 0, pwd, buffer,
+ bufsize, result));
+}
+
+int
+cap_getpwnam_r(cap_channel_t *chan, const char *name, struct passwd *pwd,
+ char *buffer, size_t bufsize, struct passwd **result)
+{
+
+ return (cap_getpwcommon_r(chan, "getpwnam_r", name, 0, pwd, buffer,
+ bufsize, result));
+}
+
+int
+cap_getpwuid_r(cap_channel_t *chan, uid_t uid, struct passwd *pwd, char *buffer,
+ size_t bufsize, struct passwd **result)
+{
+
+ return (cap_getpwcommon_r(chan, "getpwuid_r", NULL, uid, pwd, buffer,
+ bufsize, result));
+}
+
+int
+cap_setpassent(cap_channel_t *chan, int stayopen)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", "setpassent");
+ nvlist_add_bool(nvl, "stayopen", stayopen != 0);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL)
+ return (0);
+ if (nvlist_get_number(nvl, "error") != 0) {
+ errno = nvlist_get_number(nvl, "error");
+ nvlist_destroy(nvl);
+ return (0);
+ }
+ nvlist_destroy(nvl);
+
+ return (1);
+}
+
+static void
+cap_set_end_pwent(cap_channel_t *chan, const char *cmd)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", cmd);
+ /* Ignore any errors, we have no way to report them. */
+ nvlist_destroy(cap_xfer_nvlist(chan, nvl, 0));
+}
+
+void
+cap_setpwent(cap_channel_t *chan)
+{
+
+ cap_set_end_pwent(chan, "setpwent");
+}
+
+void
+cap_endpwent(cap_channel_t *chan)
+{
+
+ cap_set_end_pwent(chan, "endpwent");
+}
+
+int
+cap_pwd_limit_cmds(cap_channel_t *chan, const char * const *cmds, size_t ncmds)
+{
+ nvlist_t *limits, *nvl;
+ unsigned int i;
+
+ if (cap_limit_get(chan, &limits) < 0)
+ return (-1);
+ if (limits == NULL) {
+ limits = nvlist_create(0);
+ } else {
+ if (nvlist_exists_nvlist(limits, "cmds"))
+ nvlist_free_nvlist(limits, "cmds");
+ }
+ nvl = nvlist_create(0);
+ for (i = 0; i < ncmds; i++)
+ nvlist_add_null(nvl, cmds[i]);
+ nvlist_move_nvlist(limits, "cmds", nvl);
+ return (cap_limit_set(chan, limits));
+}
+
+int
+cap_pwd_limit_fields(cap_channel_t *chan, const char * const *fields,
+ size_t nfields)
+{
+ nvlist_t *limits, *nvl;
+ unsigned int i;
+
+ if (cap_limit_get(chan, &limits) < 0)
+ return (-1);
+ if (limits == NULL) {
+ limits = nvlist_create(0);
+ } else {
+ if (nvlist_exists_nvlist(limits, "fields"))
+ nvlist_free_nvlist(limits, "fields");
+ }
+ nvl = nvlist_create(0);
+ for (i = 0; i < nfields; i++)
+ nvlist_add_null(nvl, fields[i]);
+ nvlist_move_nvlist(limits, "fields", nvl);
+ return (cap_limit_set(chan, limits));
+}
+
+int
+cap_pwd_limit_users(cap_channel_t *chan, const char * const *names,
+ size_t nnames, uid_t *uids, size_t nuids)
+{
+ nvlist_t *limits, *users;
+ char nvlname[64];
+ unsigned int i;
+ int n;
+
+ if (cap_limit_get(chan, &limits) < 0)
+ return (-1);
+ if (limits == NULL) {
+ limits = nvlist_create(0);
+ } else {
+ if (nvlist_exists_nvlist(limits, "users"))
+ nvlist_free_nvlist(limits, "users");
+ }
+ users = nvlist_create(0);
+ for (i = 0; i < nuids; i++) {
+ n = snprintf(nvlname, sizeof(nvlname), "uid%u", i);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_number(users, nvlname, (uint64_t)uids[i]);
+ }
+ for (i = 0; i < nnames; i++) {
+ n = snprintf(nvlname, sizeof(nvlname), "name%u", i);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_string(users, nvlname, names[i]);
+ }
+ nvlist_move_nvlist(limits, "users", users);
+ return (cap_limit_set(chan, limits));
+}
diff --git a/lib/libcapsicum/libcapsicum_pwd.h b/lib/libcapsicum/libcapsicum_pwd.h
new file mode 100644
index 000000000000..960a490faf86
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_pwd.h
@@ -0,0 +1,57 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LIBCAPSICUM_PWD_H_
+#define _LIBCAPSICUM_PWD_H_
+
+struct passwd *cap_getpwent(cap_channel_t *chan);
+struct passwd *cap_getpwnam(cap_channel_t *chan, const char *login);
+struct passwd *cap_getpwuid(cap_channel_t *chan, uid_t uid);
+
+int cap_getpwent_r(cap_channel_t *chan, struct passwd *pwd, char *buffer,
+ size_t bufsize, struct passwd **result);
+int cap_getpwnam_r(cap_channel_t *chan, const char *name, struct passwd *pwd,
+ char *buffer, size_t bufsize, struct passwd **result);
+int cap_getpwuid_r(cap_channel_t *chan, uid_t uid, struct passwd *pwd,
+ char *buffer, size_t bufsize, struct passwd **result);
+
+int cap_setpassent(cap_channel_t *chan, int stayopen);
+void cap_setpwent(cap_channel_t *chan);
+void cap_endpwent(cap_channel_t *chan);
+
+int cap_pwd_limit_cmds(cap_channel_t *chan, const char * const *cmds,
+ size_t ncmds);
+int cap_pwd_limit_fields(cap_channel_t *chan, const char * const *fields,
+ size_t nfields);
+int cap_pwd_limit_users(cap_channel_t *chan, const char * const *names,
+ size_t nnames, uid_t *uids, size_t nuids);
+
+#endif /* !_LIBCAPSICUM_PWD_H_ */
diff --git a/lib/libcapsicum/libcapsicum_random.c b/lib/libcapsicum/libcapsicum_random.c
new file mode 100644
index 000000000000..2a7b109cd47a
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_random.c
@@ -0,0 +1,80 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/nv.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+
+#include "libcapsicum.h"
+#include "libcapsicum_random.h"
+
+#define MAXSIZE (1024 * 1024)
+
+int
+cap_random_buf(cap_channel_t *chan, void *buf, size_t nbytes)
+{
+ nvlist_t *nvl;
+ const void *randbuf;
+ uint8_t *ptr;
+ size_t left, randbufsize;
+
+ left = nbytes;
+ ptr = buf;
+
+ while (left > 0) {
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", "generate");
+ nvlist_add_number(nvl, "size",
+ (uint64_t)(left > MAXSIZE ? MAXSIZE : left));
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL)
+ return (-1);
+ if (nvlist_get_number(nvl, "error") != 0) {
+ errno = (int)nvlist_get_number(nvl, "error");
+ nvlist_destroy(nvl);
+ return (-1);
+ }
+
+ randbuf = nvlist_get_binary(nvl, "data", &randbufsize);
+ memcpy(ptr, randbuf, randbufsize);
+
+ nvlist_destroy(nvl);
+
+ ptr += randbufsize;
+ assert(left >= randbufsize);
+ left -= randbufsize;
+ }
+
+ return (0);
+}
diff --git a/lib/libcapsicum/libcapsicum_random.h b/lib/libcapsicum/libcapsicum_random.h
new file mode 100644
index 000000000000..672afa04f293
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_random.h
@@ -0,0 +1,37 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LIBCAPSICUM_RANDOM_H_
+#define _LIBCAPSICUM_RANDOM_H_
+
+int cap_random_buf(cap_channel_t *chan, void *buf, size_t nbytes);
+
+#endif /* !_LIBCAPSICUM_RANDOM_H_ */
diff --git a/lib/libcapsicum/libcapsicum_service.c b/lib/libcapsicum/libcapsicum_service.c
new file mode 100644
index 000000000000..6b6ceeac08de
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_service.c
@@ -0,0 +1,97 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/nv.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "msgio.h"
+
+#include "libcapsicum.h"
+#include "libcapsicum_impl.h"
+#include "libcapsicum_service.h"
+
+cap_channel_t *
+cap_service_open(const cap_channel_t *chan, const char *name)
+{
+ cap_channel_t *newchan;
+ nvlist_t *nvl;
+ int sock, error;
+
+ sock = -1;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", "open");
+ nvlist_add_string(nvl, "service", name);
+ if (fd_is_valid(STDERR_FILENO))
+ nvlist_add_descriptor(nvl, "stderrfd", STDERR_FILENO);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL)
+ return (NULL);
+ error = (int)nvlist_get_number(nvl, "error");
+ if (error != 0) {
+ nvlist_destroy(nvl);
+ errno = error;
+ return (NULL);
+ }
+ sock = nvlist_take_descriptor(nvl, "chanfd");
+ assert(sock >= 0);
+ nvlist_destroy(nvl);
+ nvl = NULL;
+ if (cred_send(sock) == -1)
+ goto fail;
+ newchan = cap_wrap(sock);
+ if (newchan == NULL)
+ goto fail;
+ return (newchan);
+fail:
+ error = errno;
+ close(sock);
+ errno = error;
+ return (NULL);
+}
+
+int
+cap_service_limit(const cap_channel_t *chan, const char * const *names,
+ size_t nnames)
+{
+ nvlist_t *limits;
+ unsigned int i;
+
+ limits = nvlist_create(0);
+ for (i = 0; i < nnames; i++)
+ nvlist_add_null(limits, names[i]);
+ return (cap_limit_set(chan, limits));
+}
diff --git a/lib/libcapsicum/libcapsicum_service.h b/lib/libcapsicum/libcapsicum_service.h
new file mode 100644
index 000000000000..05c654f7bf10
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_service.h
@@ -0,0 +1,40 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LIBCAPSICUM_SERVICE_H_
+#define _LIBCAPSICUM_SERVICE_H_
+
+cap_channel_t *cap_service_open(const cap_channel_t *chan, const char *name);
+
+int cap_service_limit(const cap_channel_t *chan, const char * const *names,
+ size_t nnames);
+
+#endif /* !_LIBCAPSICUM_SERVICE_H_ */
diff --git a/lib/libcapsicum/libcapsicum_sysctl.c b/lib/libcapsicum/libcapsicum_sysctl.c
new file mode 100644
index 000000000000..3f1ccd9116c0
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_sysctl.c
@@ -0,0 +1,86 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/nv.h>
+
+#include <errno.h>
+#include <string.h>
+
+#include "libcapsicum.h"
+#include "libcapsicum_sysctl.h"
+
+int
+cap_sysctlbyname(cap_channel_t *chan, const char *name, void *oldp,
+ size_t *oldlenp, const void *newp, size_t newlen)
+{
+ nvlist_t *nvl;
+ const uint8_t *retoldp;
+ uint8_t operation;
+ size_t oldlen;
+
+ operation = 0;
+ if (oldp != NULL)
+ operation |= CAP_SYSCTL_READ;
+ if (newp != NULL)
+ operation |= CAP_SYSCTL_WRITE;
+
+ nvl = nvlist_create(0);
+ nvlist_add_string(nvl, "cmd", "sysctl");
+ nvlist_add_string(nvl, "name", name);
+ nvlist_add_number(nvl, "operation", (uint64_t)operation);
+ if (oldp == NULL && oldlenp != NULL)
+ nvlist_add_null(nvl, "justsize");
+ else if (oldlenp != NULL)
+ nvlist_add_number(nvl, "oldlen", (uint64_t)*oldlenp);
+ if (newp != NULL)
+ nvlist_add_binary(nvl, "newp", newp, newlen);
+ nvl = cap_xfer_nvlist(chan, nvl, 0);
+ if (nvl == NULL)
+ return (-1);
+ if (nvlist_get_number(nvl, "error") != 0) {
+ errno = (int)nvlist_get_number(nvl, "error");
+ nvlist_destroy(nvl);
+ return (-1);
+ }
+
+ if (oldp == NULL && oldlenp != NULL) {
+ *oldlenp = (size_t)nvlist_get_number(nvl, "oldlen");
+ } else if (oldp != NULL) {
+ retoldp = nvlist_get_binary(nvl, "oldp", &oldlen);
+ memcpy(oldp, retoldp, oldlen);
+ if (oldlenp != NULL)
+ *oldlenp = oldlen;
+ }
+ nvlist_destroy(nvl);
+
+ return (0);
+}
diff --git a/lib/libcapsicum/libcapsicum_sysctl.h b/lib/libcapsicum/libcapsicum_sysctl.h
new file mode 100644
index 000000000000..d0df1437cec5
--- /dev/null
+++ b/lib/libcapsicum/libcapsicum_sysctl.h
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _LIBCAPSICUM_SYSCTL_H_
+#define _LIBCAPSICUM_SYSCTL_H_
+
+#define CAP_SYSCTL_READ 0x01
+#define CAP_SYSCTL_WRITE 0x02
+#define CAP_SYSCTL_RDWR (CAP_SYSCTL_READ | CAP_SYSCTL_WRITE)
+#define CAP_SYSCTL_RECURSIVE 0x04
+
+int cap_sysctlbyname(cap_channel_t *chan, const char *name, void *oldp,
+ size_t *oldlenp, const void *newp, size_t newlen);
+
+#endif /* !_LIBCAPSICUM_SYSCTL_H_ */
diff --git a/lib/libcasper/libcasper/Makefile b/lib/libcasper/libcasper/Makefile
index 6fbdffbb12d7..c8eface43627 100644
--- a/lib/libcasper/libcasper/Makefile
+++ b/lib/libcasper/libcasper/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=${LIB}
LIB= casper
SHLIB_MAJOR= 0
diff --git a/lib/libcasper/services/cap_dns/Makefile b/lib/libcasper/services/cap_dns/Makefile
index c52f6bf7a52d..2582fe89b14c 100644
--- a/lib/libcasper/services/cap_dns/Makefile
+++ b/lib/libcasper/services/cap_dns/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=libcasper
LIB= cap_dns
SHLIB_MAJOR= 0
diff --git a/lib/libcasper/services/cap_grp/Makefile b/lib/libcasper/services/cap_grp/Makefile
index 8a552d26bcd7..195b08d25777 100644
--- a/lib/libcasper/services/cap_grp/Makefile
+++ b/lib/libcasper/services/cap_grp/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=libcasper
LIB= cap_grp
SHLIB_MAJOR= 0
diff --git a/lib/libcasper/services/cap_pwd/Makefile b/lib/libcasper/services/cap_pwd/Makefile
index 294ce7e2f05b..3e604bd54c53 100644
--- a/lib/libcasper/services/cap_pwd/Makefile
+++ b/lib/libcasper/services/cap_pwd/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=libcasper
LIB= cap_pwd
SHLIB_MAJOR= 0
diff --git a/lib/libcasper/services/cap_random/Makefile b/lib/libcasper/services/cap_random/Makefile
index 61dcc6ceba2e..97a27beb134a 100644
--- a/lib/libcasper/services/cap_random/Makefile
+++ b/lib/libcasper/services/cap_random/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=libcasper
LIB= cap_random
SHLIB_MAJOR= 0
diff --git a/lib/libcasper/services/cap_sysctl/Makefile b/lib/libcasper/services/cap_sysctl/Makefile
index ba3a4b3c5ca4..7501f37ab4e0 100644
--- a/lib/libcasper/services/cap_sysctl/Makefile
+++ b/lib/libcasper/services/cap_sysctl/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=libcasper
LIB= cap_sysctl
SHLIB_MAJOR= 0
diff --git a/lib/libcom_err/Makefile b/lib/libcom_err/Makefile
index 72260fee077a..b6f389f7bb80 100644
--- a/lib/libcom_err/Makefile
+++ b/lib/libcom_err/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= com_err
SRCS= com_err.c error.c
INCS= ${COM_ERRDIR}/com_err.h ${COM_ERRDIR}/com_right.h
diff --git a/lib/libcompat/Makefile b/lib/libcompat/Makefile
index fca86c7b157e..0bd47dfce0b2 100644
--- a/lib/libcompat/Makefile
+++ b/lib/libcompat/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/4/93
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= compat
CFLAGS+=-DLIBC_SCCS -DSYSLIBC_SCCS -I${.CURDIR}/../libc/locale
NO_PIC=
diff --git a/lib/libcompiler_rt/Makefile b/lib/libcompiler_rt/Makefile
index 3c7896df4bb8..8959225e409f 100644
--- a/lib/libcompiler_rt/Makefile
+++ b/lib/libcompiler_rt/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=lib${LIB}
LIB= compiler_rt
NO_PIC=
WARNS?= 2
diff --git a/lib/libcrypt/Makefile b/lib/libcrypt/Makefile
index d5d03477570a..c1f8542bc7b8 100644
--- a/lib/libcrypt/Makefile
+++ b/lib/libcrypt/Makefile
@@ -2,6 +2,7 @@
# $FreeBSD$
#
+PACKAGE=lib${LIB}
SHLIBDIR?= /lib
.include <src.opts.mk>
diff --git a/lib/libcrypt/tests/Makefile b/lib/libcrypt/tests/Makefile
index 15798b215d17..0c831ad6044a 100644
--- a/lib/libcrypt/tests/Makefile
+++ b/lib/libcrypt/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE=tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_C+= crypt_tests
NETBSD_ATF_TESTS_C+= crypt_test
diff --git a/lib/libcuse/Makefile b/lib/libcuse/Makefile
index a232fa241c62..607d36b3374e 100644
--- a/lib/libcuse/Makefile
+++ b/lib/libcuse/Makefile
@@ -24,6 +24,7 @@
# SUCH DAMAGE.
#
+PACKAGE=lib${LIB}
LIB= cuse
SHLIB_MAJOR= 1
SHLIB_MINOR= 0
diff --git a/lib/libcxxrt/Makefile b/lib/libcxxrt/Makefile
index d197361a9a66..8f3d9c54c3b7 100644
--- a/lib/libcxxrt/Makefile
+++ b/lib/libcxxrt/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= clibs
SRCDIR= ${.CURDIR}/../../contrib/libcxxrt
SHLIB_MAJOR= 1
diff --git a/lib/libdevctl/Makefile b/lib/libdevctl/Makefile
index 74687ecc2bd2..ed56b25dc374 100644
--- a/lib/libdevctl/Makefile
+++ b/lib/libdevctl/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= devctl
SRCS= devctl.c
INCS= devctl.h
diff --git a/lib/libdevinfo/Makefile b/lib/libdevinfo/Makefile
index 9e755d73b0d4..6c0927ee0b41 100644
--- a/lib/libdevinfo/Makefile
+++ b/lib/libdevinfo/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= devinfo
SRCS= devinfo.c
INCS= devinfo.h
diff --git a/lib/libdevstat/Makefile b/lib/libdevstat/Makefile
index dcda3c2bdac8..df5d44ec30db 100644
--- a/lib/libdevstat/Makefile
+++ b/lib/libdevstat/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= devstat
SHLIBDIR?= /lib
# Bump DEVSTAT_USER_API_VER in devstat.h every time this is incremented.
diff --git a/lib/libdpv/Makefile b/lib/libdpv/Makefile
index 3a9921c92cdb..d9bef05888a5 100644
--- a/lib/libdpv/Makefile
+++ b/lib/libdpv/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= dpv
SHLIB_MAJOR= 1
INCS= dpv.h
diff --git a/lib/libdwarf/Makefile b/lib/libdwarf/Makefile
index bd98d8f4e040..1e2506d23e36 100644
--- a/lib/libdwarf/Makefile
+++ b/lib/libdwarf/Makefile
@@ -1,6 +1,7 @@
# $FreeBSD$
.include <bsd.own.mk>
+PACKAGE=lib${LIB}
TOP= ${.CURDIR}/../../contrib/elftoolchain
SRCDIR= ${TOP}/libdwarf
diff --git a/lib/libedit/Makefile b/lib/libedit/Makefile
index 8a97ce0f341b..14c9cbbcc175 100644
--- a/lib/libedit/Makefile
+++ b/lib/libedit/Makefile
@@ -2,6 +2,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/4/93
# $FreeBSD$
+PACKAGE=clibs
LIB= edit
SHLIB_MAJOR= 7
SHLIBDIR?= /lib
diff --git a/lib/libefi/Makefile b/lib/libefi/Makefile
index 16aa3e7e224b..d9862f061899 100644
--- a/lib/libefi/Makefile
+++ b/lib/libefi/Makefile
@@ -2,6 +2,7 @@
.include <bsd.own.mk>
+PACKAGE=lib${LIB}
LIB= efi
SHLIB_MAJOR= 1
diff --git a/lib/libelf/Makefile b/lib/libelf/Makefile
index f6229213851c..70d9e9bc423a 100644
--- a/lib/libelf/Makefile
+++ b/lib/libelf/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
SHLIBDIR?= /lib
.include <bsd.own.mk>
diff --git a/lib/libelftc/Makefile b/lib/libelftc/Makefile
index ed5c02a93cb0..e2269b41fcb4 100644
--- a/lib/libelftc/Makefile
+++ b/lib/libelftc/Makefile
@@ -1,6 +1,7 @@
# $FreeBSD$
.include <bsd.own.mk>
+PACKAGE=lib${LIB}
INTERNALLIB=
ELFTCDIR= ${.CURDIR}/../../contrib/elftoolchain
diff --git a/lib/libevent/Makefile b/lib/libevent/Makefile
index 1d20bcdc9478..d8cc57216cde 100644
--- a/lib/libevent/Makefile
+++ b/lib/libevent/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
.PATH: ${.CURDIR}/../../contrib/pf/libevent
.include <src.opts.mk>
diff --git a/lib/libexecinfo/Makefile b/lib/libexecinfo/Makefile
index 5f9aac5e5c21..c444f7fc6855 100644
--- a/lib/libexecinfo/Makefile
+++ b/lib/libexecinfo/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIBEXECINFO= ${.CURDIR}/../../contrib/libexecinfo
LIB= execinfo
diff --git a/lib/libexpat/Makefile b/lib/libexpat/Makefile
index 0d4bef55e2f3..d0de3e0089c4 100644
--- a/lib/libexpat/Makefile
+++ b/lib/libexpat/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
EXPAT= ${.CURDIR}/../../contrib/expat
LIB= bsdxml
diff --git a/lib/libfetch/Makefile b/lib/libfetch/Makefile
index 4f56552801cf..abd5f8de23f6 100644
--- a/lib/libfetch/Makefile
+++ b/lib/libfetch/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=lib${LIB}
LIB= fetch
CFLAGS+= -I.
SRCS= fetch.c common.c ftp.c http.c file.c \
diff --git a/lib/libfigpar/Makefile b/lib/libfigpar/Makefile
index bb24da356360..6d495462b086 100644
--- a/lib/libfigpar/Makefile
+++ b/lib/libfigpar/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= figpar
SHLIB_MAJOR= 0
INCS= figpar.h string_m.h
diff --git a/lib/libgeom/Makefile b/lib/libgeom/Makefile
index 20b7a4c7c3b8..ea1f6c83a961 100644
--- a/lib/libgeom/Makefile
+++ b/lib/libgeom/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= geom
SHLIBDIR?= /lib
SRCS+= geom_getxml.c
diff --git a/lib/libgpio/Makefile b/lib/libgpio/Makefile
index 94118d6eb00d..fc163e90efd0 100644
--- a/lib/libgpio/Makefile
+++ b/lib/libgpio/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= gpio
SHLIB_MAJOR= 0
diff --git a/lib/libgssapi/Makefile b/lib/libgssapi/Makefile
index 3f016b49bb73..a48610114b4c 100644
--- a/lib/libgssapi/Makefile
+++ b/lib/libgssapi/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= gssapi
SHLIB_MAJOR= 10
VERSION_DEF= ${.CURDIR}/../libc/Versions.def
diff --git a/lib/libipsec/Makefile b/lib/libipsec/Makefile
index 7d3e94a7db5a..460a5d79b0b4 100644
--- a/lib/libipsec/Makefile
+++ b/lib/libipsec/Makefile
@@ -27,6 +27,7 @@
#
# $FreeBSD$
+PACKAGE=lib${LIB}
SHLIBDIR?= /lib
.include <src.opts.mk>
diff --git a/lib/libjail/Makefile b/lib/libjail/Makefile
index 442274ae35dd..74eb8e1091b2 100644
--- a/lib/libjail/Makefile
+++ b/lib/libjail/Makefile
@@ -1,11 +1,14 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= jail
SHLIBDIR?= /lib
SHLIB_MAJOR= 1
SRCS= jail.c jail_getid.c
INCS= jail.h
+PACKAGE=jail
+
MAN= jail.3
MLINKS+=jail.3 jail_getid.3
diff --git a/lib/libkiconv/Makefile b/lib/libkiconv/Makefile
index c7b2179c1943..5ada7db0b06b 100644
--- a/lib/libkiconv/Makefile
+++ b/lib/libkiconv/Makefile
@@ -4,6 +4,7 @@ SHLIBDIR?= /lib
.include <src.opts.mk>
+PACKAGE=lib${LIB}
LIB= kiconv
SRCS= kiconv_sysctl.c xlat16_iconv.c xlat16_sysctl.c
SRCS+= quirks.c
diff --git a/lib/libkvm/Makefile b/lib/libkvm/Makefile
index 33f8e5b8137c..0fdeec905d9f 100644
--- a/lib/libkvm/Makefile
+++ b/lib/libkvm/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/4/93
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= kvm
SHLIBDIR?= /lib
diff --git a/lib/libldns/Makefile b/lib/libldns/Makefile
index 9a436cdb4b9d..14dc9f9da1ac 100644
--- a/lib/libldns/Makefile
+++ b/lib/libldns/Makefile
@@ -3,6 +3,7 @@
# Vendor sources and generated files
LDNSDIR = ${.CURDIR}/../../contrib/ldns
+PACKAGE=lib${LIB}
.PATH: ${LDNSDIR} ${LDNSDIR}/compat
LIB= ldns
diff --git a/lib/liblzma/Makefile b/lib/liblzma/Makefile
index 8a6c23d84d1d..62c2994febad 100644
--- a/lib/liblzma/Makefile
+++ b/lib/liblzma/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= lzma
LZMADIR= ${.CURDIR}/../../contrib/xz/src/liblzma
diff --git a/lib/libmagic/Makefile b/lib/libmagic/Makefile
index 2add1d3c27b5..d77de6c42caa 100644
--- a/lib/libmagic/Makefile
+++ b/lib/libmagic/Makefile
@@ -1,6 +1,7 @@
# $FreeBSD$
# Copyright (c) David E. O'Brien, 2000-2004, 2006, 2009
+PACKAGE=lib${LIB}
CONTRDIR= ${.CURDIR}/../../contrib/file
.PATH: ${CONTRDIR}/src
.PATH: ${CONTRDIR}/doc
diff --git a/lib/libmd/Makefile b/lib/libmd/Makefile
index 43b8a5a84fa4..bde4fb5c0a9e 100644
--- a/lib/libmd/Makefile
+++ b/lib/libmd/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= md
SHLIB_MAJOR= 6
SHLIBDIR?= /lib
diff --git a/lib/libmemstat/Makefile b/lib/libmemstat/Makefile
index 597dc6db1606..8554eb0482e8 100644
--- a/lib/libmemstat/Makefile
+++ b/lib/libmemstat/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
WARNS?= 3
LIB= memstat
SHLIB_MAJOR= 3
diff --git a/lib/libmilter/Makefile b/lib/libmilter/Makefile
index 81172ec5b31c..88a80b7e0684 100644
--- a/lib/libmilter/Makefile
+++ b/lib/libmilter/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=sendmail
SENDMAIL_DIR=${.CURDIR}/../../contrib/sendmail
.PATH: ${SENDMAIL_DIR}/libmilter ${SENDMAIL_DIR}/libsm
diff --git a/lib/libmp/Makefile b/lib/libmp/Makefile
index 6a73658103e5..8d8c5278e573 100644
--- a/lib/libmp/Makefile
+++ b/lib/libmp/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=lib${LIB}
LIB= mp
SHLIB_MAJOR= 7
LIBADD= crypto
diff --git a/lib/libmp/tests/Makefile b/lib/libmp/tests/Makefile
index 42749d00a039..86f0985da34a 100644
--- a/lib/libmp/tests/Makefile
+++ b/lib/libmp/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE=tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_C+= legacy_test
LIBADD+= mp
diff --git a/lib/libmt/Makefile b/lib/libmt/Makefile
index 6fe59201a87f..c67130ecc57e 100644
--- a/lib/libmt/Makefile
+++ b/lib/libmt/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= mt
SHLIBDIR?= /lib
SRCS= mtlib.c
diff --git a/lib/libnandfs/Makefile b/lib/libnandfs/Makefile
index d87573e2f343..e900c3c6eab4 100644
--- a/lib/libnandfs/Makefile
+++ b/lib/libnandfs/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= nandfs
SRCS+= nandfs.c
INCS= libnandfs.h
diff --git a/lib/libnetbsd/Makefile b/lib/libnetbsd/Makefile
index 09c6985e6c83..92ad745dc58c 100644
--- a/lib/libnetbsd/Makefile
+++ b/lib/libnetbsd/Makefile
@@ -2,6 +2,7 @@
.include <bsd.own.mk>
+PACKAGE=lib${LIB}
LIB= netbsd
CFLAGS+= -I${.CURDIR}
diff --git a/lib/libnetgraph/Makefile b/lib/libnetgraph/Makefile
index d0c444eb3095..d3c7c3fa64a4 100644
--- a/lib/libnetgraph/Makefile
+++ b/lib/libnetgraph/Makefile
@@ -1,6 +1,7 @@
# $FreeBSD$
# $Whistle: Makefile,v 1.4 1999/01/17 03:41:02 julian Exp $
+PACKAGE=lib${LIB}
LIB= netgraph
WARNS?= 3
MAN= netgraph.3
diff --git a/lib/libngatm/Makefile b/lib/libngatm/Makefile
index 85294b0471df..71f21d5d0111 100644
--- a/lib/libngatm/Makefile
+++ b/lib/libngatm/Makefile
@@ -2,6 +2,7 @@
#
# Author: Harti Brandt <harti@freebsd.org>
#
+PACKAGE=lib${LIB}
LIB= ngatm
SHLIB_MAJOR= 4
MAN= libngatm.3 uniaddr.3 unifunc.3 unimsg.3 unisap.3 unistruct.3
diff --git a/lib/libnv/Makefile b/lib/libnv/Makefile
index f0ed8c4fa52c..4b2125b07175 100644
--- a/lib/libnv/Makefile
+++ b/lib/libnv/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
SHLIBDIR?= /lib
.include <src.opts.mk>
diff --git a/lib/libnv/tests/Makefile b/lib/libnv/tests/Makefile
index cce0b5e8f1a7..d815af48b5cb 100644
--- a/lib/libnv/tests/Makefile
+++ b/lib/libnv/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE=tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_CXX= \
dnv_tests \
nv_array_tests \
diff --git a/lib/libopenbsd/Makefile b/lib/libopenbsd/Makefile
index 3eb6b743d186..afb41b393fbd 100644
--- a/lib/libopenbsd/Makefile
+++ b/lib/libopenbsd/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= openbsd
SRCS= getdtablecount.c \
imsg-buffer.c \
diff --git a/lib/libopie/Makefile b/lib/libopie/Makefile
index e66e67a4f9e8..367bbc6ac7be 100644
--- a/lib/libopie/Makefile
+++ b/lib/libopie/Makefile
@@ -2,6 +2,7 @@
#
# $FreeBSD$
#
+PACKAGE=lib${LIB}
OPIE_DIST?= ${.CURDIR}/../../contrib/opie
DIST_DIR= ${OPIE_DIST}/${.CURDIR:T}
SHLIB_MAJOR= 8
diff --git a/lib/libpam/libpam/Makefile b/lib/libpam/libpam/Makefile
index 1dc977f610d3..c7122c72abda 100644
--- a/lib/libpam/libpam/Makefile
+++ b/lib/libpam/libpam/Makefile
@@ -35,6 +35,7 @@
#
# $FreeBSD$
+PACKAGE=lib${LIB}
OPENPAM= ${.CURDIR}/../../../contrib/openpam
.PATH: ${OPENPAM}/include ${OPENPAM}/lib/libpam ${OPENPAM}/doc/man
diff --git a/lib/libpam/libpam/tests/Makefile b/lib/libpam/libpam/tests/Makefile
index e40936a883db..ec32229781e2 100644
--- a/lib/libpam/libpam/tests/Makefile
+++ b/lib/libpam/libpam/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
OPENPAM= ${SRCTOP}/contrib/openpam
.PATH: ${OPENPAM}/t
diff --git a/lib/libpam/modules/pam_ssh/Makefile b/lib/libpam/modules/pam_ssh/Makefile
index 21991dc9f1c7..8965018e32b2 100644
--- a/lib/libpam/modules/pam_ssh/Makefile
+++ b/lib/libpam/modules/pam_ssh/Makefile
@@ -6,6 +6,7 @@ SSHDIR= ${.CURDIR}/../../../../crypto/openssh
LIB= pam_ssh
MAN= pam_ssh.8
SRCS= pam_ssh.c
+PACKAGE= ssh
# required when linking with a dynamic libssh
SRCS+= roaming_dummy.c
diff --git a/lib/libpcap/Makefile b/lib/libpcap/Makefile
index cdc02287988a..e7512e659121 100644
--- a/lib/libpcap/Makefile
+++ b/lib/libpcap/Makefile
@@ -5,6 +5,7 @@ SHLIBDIR?= /lib
.include <src.opts.mk>
+PACKAGE=lib${LIB}
LIB= pcap
SRCS= grammar.y tokdefs.h version.h pcap-bpf.c \
pcap-netmap.c \
diff --git a/lib/libpjdlog/Makefile b/lib/libpjdlog/Makefile
index ead5619afb67..4fcfe028d9f7 100644
--- a/lib/libpjdlog/Makefile
+++ b/lib/libpjdlog/Makefile
@@ -2,6 +2,7 @@
# $FreeBSD$
#
+PACKAGE=lib${LIB}
SHLIBDIR?= /lib
.include <bsd.own.mk>
diff --git a/lib/libpmc/Makefile b/lib/libpmc/Makefile
index b240070eceb9..30510f6144b0 100644
--- a/lib/libpmc/Makefile
+++ b/lib/libpmc/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= pmc
SRCS= libpmc.c pmclog.c
diff --git a/lib/libproc/Makefile b/lib/libproc/Makefile
index 8c4f4848354e..0372377d8b64 100644
--- a/lib/libproc/Makefile
+++ b/lib/libproc/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=lib${LIB}
LIB= proc
SRCS= proc_bkpt.c \
diff --git a/lib/libproc/tests/Makefile b/lib/libproc/tests/Makefile
index d48250e3bb67..768078ecb3f8 100644
--- a/lib/libproc/tests/Makefile
+++ b/lib/libproc/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE=tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_C+= proc_test
PROGS= target_prog
diff --git a/lib/libprocstat/Makefile b/lib/libprocstat/Makefile
index fc71dbcb666d..240718dd9cd6 100644
--- a/lib/libprocstat/Makefile
+++ b/lib/libprocstat/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=lib${LIB}
LIB= procstat
SRCS= cd9660.c \
diff --git a/lib/libradius/Makefile b/lib/libradius/Makefile
index 42f5def20ef1..3ce1435aa2d9 100644
--- a/lib/libradius/Makefile
+++ b/lib/libradius/Makefile
@@ -26,6 +26,7 @@
.include <src.opts.mk>
+PACKAGE=lib${LIB}
LIB= radius
SRCS= radlib.c
INCS= radlib.h radlib_vs.h
diff --git a/lib/librpcsec_gss/Makefile b/lib/librpcsec_gss/Makefile
index c3e768445004..e59f1e5cfa52 100644
--- a/lib/librpcsec_gss/Makefile
+++ b/lib/librpcsec_gss/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= rpcsec_gss
SHLIB_MAJOR= 1
SRCS+= rpcsec_gss.c rpcsec_gss_prot.c rpcsec_gss_conf.c rpcsec_gss_misc.c \
diff --git a/lib/librpcsvc/Makefile b/lib/librpcsvc/Makefile
index ba972ac3e8eb..1deda175c6a5 100644
--- a/lib/librpcsvc/Makefile
+++ b/lib/librpcsvc/Makefile
@@ -5,6 +5,7 @@
.PATH: ${.CURDIR}/../../include/rpcsvc
+PACKAGE=lib${LIB}
LIB= rpcsvc
RPCSRCS= klm_prot.x mount.x nfs_prot.x nlm_prot.x rex.x rnusers.x \
diff --git a/lib/librt/Makefile b/lib/librt/Makefile
index 3c16976690d0..560f2af36855 100644
--- a/lib/librt/Makefile
+++ b/lib/librt/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=lib${LIB}
LIB=rt
SHLIB_MAJOR= 1
CFLAGS+=-I${.CURDIR}/../libc/include -I${.CURDIR}
diff --git a/lib/librt/tests/Makefile b/lib/librt/tests/Makefile
index c4817ecfad76..7f788aef98e5 100644
--- a/lib/librt/tests/Makefile
+++ b/lib/librt/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE=tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
LIBADD= rt
NETBSD_ATF_TESTS_C= sched_test
diff --git a/lib/librtld_db/Makefile b/lib/librtld_db/Makefile
index 9f9b6039d5b4..eec7970eaaa9 100644
--- a/lib/librtld_db/Makefile
+++ b/lib/librtld_db/Makefile
@@ -2,6 +2,7 @@
.include <bsd.own.mk>
+PACKAGE=lib${LIB}
LIB= rtld_db
SHLIB_MAJOR= 2
MAN= librtld_db.3
diff --git a/lib/libsbuf/Makefile b/lib/libsbuf/Makefile
index 98ceeb6b373d..ebf4a8d4a99d 100644
--- a/lib/libsbuf/Makefile
+++ b/lib/libsbuf/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= sbuf
SHLIBDIR?= /lib
SRCS= subr_prf.c subr_sbuf.c
diff --git a/lib/libsdp/Makefile b/lib/libsdp/Makefile
index fcedb5028cec..0037252ccc6b 100644
--- a/lib/libsdp/Makefile
+++ b/lib/libsdp/Makefile
@@ -1,6 +1,7 @@
# $Id: Makefile,v 1.2 2003/09/07 20:34:19 max Exp $
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= sdp
MAN= sdp.3
diff --git a/lib/libsm/Makefile b/lib/libsm/Makefile
index 1ec2dc1ef3e6..984009259fc3 100644
--- a/lib/libsm/Makefile
+++ b/lib/libsm/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=sendmail
SENDMAIL_DIR=${.CURDIR}/../../contrib/sendmail
.PATH: ${SENDMAIL_DIR}/libsm
diff --git a/lib/libsmb/Makefile b/lib/libsmb/Makefile
index b63754bd982a..6236a2e00fba 100644
--- a/lib/libsmb/Makefile
+++ b/lib/libsmb/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=lib${LIB}
CONTRIBDIR= ${.CURDIR}/../../contrib/smbfs
.PATH: ${CONTRIBDIR}/lib/smb
diff --git a/lib/libsmdb/Makefile b/lib/libsmdb/Makefile
index f1f51997244e..3fbd11648869 100644
--- a/lib/libsmdb/Makefile
+++ b/lib/libsmdb/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
SENDMAIL_DIR=${.CURDIR}/../../contrib/sendmail
.PATH: ${SENDMAIL_DIR}/libsmdb
diff --git a/lib/libsmutil/Makefile b/lib/libsmutil/Makefile
index e7919eab9f25..e1d908e9fea5 100644
--- a/lib/libsmutil/Makefile
+++ b/lib/libsmutil/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
SENDMAIL_DIR=${.CURDIR}/../../contrib/sendmail
.PATH: ${SENDMAIL_DIR}/libsmutil
diff --git a/lib/libsqlite3/Makefile b/lib/libsqlite3/Makefile
index d44615162878..37a3a6ef1227 100644
--- a/lib/libsqlite3/Makefile
+++ b/lib/libsqlite3/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
PRIVATELIB= yes
LIB= sqlite3
SHLIB_MAJOR?= 0
diff --git a/lib/libstand/Makefile b/lib/libstand/Makefile
index 82e65f272076..835b535d327b 100644
--- a/lib/libstand/Makefile
+++ b/lib/libstand/Makefile
@@ -6,6 +6,7 @@
# quite large.
#
+PACKAGE=lib${LIB}
MK_PROFILE= no
MK_SSP= no
diff --git a/lib/libstdbuf/Makefile b/lib/libstdbuf/Makefile
index ea233a8ad19b..7d8c3ca3a1d2 100644
--- a/lib/libstdbuf/Makefile
+++ b/lib/libstdbuf/Makefile
@@ -2,6 +2,7 @@
.include <bsd.own.mk>
+PACKAGE=lib${LIB}
LIB= stdbuf
SRCS= stdbuf.c
SHLIB_MAJOR= 1
diff --git a/lib/libstdthreads/Makefile b/lib/libstdthreads/Makefile
index 8daee58b0e87..3200d4e36ba6 100644
--- a/lib/libstdthreads/Makefile
+++ b/lib/libstdthreads/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= stdthreads
SHLIB_MAJOR= 0
diff --git a/lib/libsysdecode/Makefile b/lib/libsysdecode/Makefile
index 405cab8c7847..742c513469fe 100644
--- a/lib/libsysdecode/Makefile
+++ b/lib/libsysdecode/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=lib${LIB}
LIB= sysdecode
SRCS= errno.c ioctl.c syscallnames.c utrace.c
diff --git a/lib/libtacplus/Makefile b/lib/libtacplus/Makefile
index 01345e175a6b..73d8e766da0d 100644
--- a/lib/libtacplus/Makefile
+++ b/lib/libtacplus/Makefile
@@ -24,6 +24,7 @@
#
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= tacplus
SRCS= taclib.c
INCS= taclib.h
diff --git a/lib/libtelnet/Makefile b/lib/libtelnet/Makefile
index 7f737332673a..b5bba12bebe1 100644
--- a/lib/libtelnet/Makefile
+++ b/lib/libtelnet/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=lib${LIB}
TELNETDIR= ${.CURDIR}/../../contrib/telnet
.PATH: ${TELNETDIR}/libtelnet
diff --git a/lib/libthr/Makefile b/lib/libthr/Makefile
index 17176729b2e5..7a080e0f2580 100644
--- a/lib/libthr/Makefile
+++ b/lib/libthr/Makefile
@@ -8,6 +8,7 @@
# (for system call stubs) to CFLAGS below. -DSYSLIBC_SCCS affects just the
# system call stubs.
+PACKAGE= clibs
SHLIBDIR?= /lib
.include <src.opts.mk>
diff --git a/lib/libthr/tests/Makefile b/lib/libthr/tests/Makefile
index aeb1ef89fb5b..6c2139a5d5b3 100644
--- a/lib/libthr/tests/Makefile
+++ b/lib/libthr/tests/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libpthread
# TODO: t_name (missing pthread_getname_np support in FreeBSD)
diff --git a/lib/libthr/tests/dlopen/Makefile b/lib/libthr/tests/dlopen/Makefile
index bea70ec7cbd5..1f587a5af73b 100644
--- a/lib/libthr/tests/dlopen/Makefile
+++ b/lib/libthr/tests/dlopen/Makefile
@@ -4,6 +4,9 @@ TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libpthread/dlopen
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/lib/libthr/dlopen
CFLAGS+= -DTESTDIR=\"${TESTSDIR:Q}/\"
diff --git a/lib/libthr/tests/dlopen/dso/Makefile b/lib/libthr/tests/dlopen/dso/Makefile
index 23d4cd60813d..a7f685f5a917 100644
--- a/lib/libthr/tests/dlopen/dso/Makefile
+++ b/lib/libthr/tests/dlopen/dso/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
OBJTOP= ${.OBJDIR:H:H:H:H:H}
TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libpthread/dlopen/dso
diff --git a/lib/libthread_db/Makefile b/lib/libthread_db/Makefile
index b612f4f8d789..dfd451639501 100644
--- a/lib/libthread_db/Makefile
+++ b/lib/libthread_db/Makefile
@@ -2,6 +2,7 @@
.PATH: ${.CURDIR}/arch/${MACHINE_CPUARCH}
+PACKAGE=lib${LIB}
LIB= thread_db
SHLIB_MAJOR= 3
SRCS= thread_db.c
diff --git a/lib/libucl/Makefile b/lib/libucl/Makefile
index 09a0bf2cc2a3..802048f65afd 100644
--- a/lib/libucl/Makefile
+++ b/lib/libucl/Makefile
@@ -2,6 +2,7 @@
LIBUCL= ${.CURDIR}/../../contrib/libucl
+PACKAGE=lib${LIB}
LIB= ucl
PRIVATELIB= true
SHLIB_MAJOR= 1
diff --git a/lib/libufs/Makefile b/lib/libufs/Makefile
index 24efd0ccc5fa..86fa4c9c47be 100644
--- a/lib/libufs/Makefile
+++ b/lib/libufs/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= ufs
SHLIBDIR?= /lib
SHLIB_MAJOR= 6
diff --git a/lib/libugidfw/Makefile b/lib/libugidfw/Makefile
index f11200d234cb..2df6a24df479 100644
--- a/lib/libugidfw/Makefile
+++ b/lib/libugidfw/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= ugidfw
SHLIB_MAJOR= 5
SRCS= ugidfw.c
diff --git a/lib/libulog/Makefile b/lib/libulog/Makefile
index fedd114efb9e..434f3f6ce199 100644
--- a/lib/libulog/Makefile
+++ b/lib/libulog/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
SHLIBDIR?=/lib
.include <src.opts.mk>
diff --git a/lib/libunbound/Makefile b/lib/libunbound/Makefile
index e348c665041a..f16824485399 100644
--- a/lib/libunbound/Makefile
+++ b/lib/libunbound/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
# Vendor sources and generated files
LDNSDIR= ${.CURDIR}/../../contrib/ldns
UNBOUNDDIR= ${.CURDIR}/../../contrib/unbound
@@ -9,6 +10,7 @@ UNBOUNDDIR= ${.CURDIR}/../../contrib/unbound
LIB= unbound
PRIVATELIB=
+PACKAGE= unbound
CFLAGS= -I${UNBOUNDDIR} -I${LDNSDIR} -I${.OBJDIR}
diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile
index be55aa65a6d8..fe54d2aeb2b6 100644
--- a/lib/libusb/Makefile
+++ b/lib/libusb/Makefile
@@ -4,6 +4,7 @@
# Makefile for the FreeBSD specific LibUSB 2.0
#
+PACKAGE=lib${LIB}
LIB= usb
SHLIB_MAJOR= 3
SHLIB_MINOR= 0
diff --git a/lib/libusbhid/Makefile b/lib/libusbhid/Makefile
index 7dba7ffc9113..6efe9ccbe613 100644
--- a/lib/libusbhid/Makefile
+++ b/lib/libusbhid/Makefile
@@ -1,6 +1,7 @@
# $NetBSD: Makefile,v 1.5 1999/07/23 09:44:38 mrg Exp $
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= usbhid
MAN= usbhid.3
diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile
index 35d146af720f..07412e0ece41 100644
--- a/lib/libutil/Makefile
+++ b/lib/libutil/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/4/93
# $FreeBSD$
+PACKAGE=lib${LIB}
SHLIBDIR?= /lib
.include <src.opts.mk>
diff --git a/lib/libutil/tests/Makefile b/lib/libutil/tests/Makefile
index 81b2a494eaae..2f46850fd51a 100644
--- a/lib/libutil/tests/Makefile
+++ b/lib/libutil/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE=tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_C+= flopen_test
TAP_TESTS_C+= grp_test
TAP_TESTS_C+= humanize_number_test
diff --git a/lib/libvgl/Makefile b/lib/libvgl/Makefile
index dfc4e81f33b8..5505d373bc12 100644
--- a/lib/libvgl/Makefile
+++ b/lib/libvgl/Makefile
@@ -1,4 +1,5 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= vgl
SHLIB_MAJOR= 6
CFLAGS+=-Wall -I${.CURDIR}
diff --git a/lib/libvmmapi/Makefile b/lib/libvmmapi/Makefile
index 26cf86fbe4c0..bf17566a0d7d 100644
--- a/lib/libvmmapi/Makefile
+++ b/lib/libvmmapi/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= vmmapi
SRCS= vmmapi.c vmmapi_freebsd.c
INCS= vmmapi.h
diff --git a/lib/libwrap/Makefile b/lib/libwrap/Makefile
index 0acb0c4c8da7..b2253d888635 100644
--- a/lib/libwrap/Makefile
+++ b/lib/libwrap/Makefile
@@ -4,6 +4,7 @@
.include <src.opts.mk>
+PACKAGE=lib${LIB}
LIB= wrap
SHLIB_MAJOR= 6
INCS= tcpd.h
diff --git a/lib/libxo/Makefile b/lib/libxo/Makefile
index f8453f405282..2f3f1673d2cd 100644
--- a/lib/libxo/Makefile
+++ b/lib/libxo/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
SHLIBDIR?= /lib
.include <src.opts.mk>
diff --git a/lib/libxo/tests/Makefile b/lib/libxo/tests/Makefile
index 1a0f7c69cfee..43f2e9dfa1a5 100644
--- a/lib/libxo/tests/Makefile
+++ b/lib/libxo/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
LIBXOSRC= ${SRCTOP}/contrib/libxo
# Override the default suffix transformation rules for .c/.o -> .out
diff --git a/lib/libxo/tests/encoder/Makefile b/lib/libxo/tests/encoder/Makefile
index 2fe42457f2e8..491af0cb1d9a 100644
--- a/lib/libxo/tests/encoder/Makefile
+++ b/lib/libxo/tests/encoder/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
LIBXOSRC= ${SRCTOP}/contrib/libxo
.PATH: ${LIBXOSRC}/encoder/test
diff --git a/lib/liby/Makefile b/lib/liby/Makefile
index 34939452dd75..2f357f3c7617 100644
--- a/lib/liby/Makefile
+++ b/lib/liby/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= y
SRCS= main.c yyerror.c
NO_PIC=
diff --git a/lib/libypclnt/Makefile b/lib/libypclnt/Makefile
index 2e302f124289..113a3cc83218 100644
--- a/lib/libypclnt/Makefile
+++ b/lib/libypclnt/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=lib${LIB}
LIB= ypclnt
SHLIB_MAJOR= 4
SRCS= ypclnt_connect.c \
diff --git a/lib/libz/Makefile b/lib/libz/Makefile
index 7a80fcbab520..6a372bb3a10f 100644
--- a/lib/libz/Makefile
+++ b/lib/libz/Makefile
@@ -2,6 +2,7 @@
# $FreeBSD$
#
+PACKAGE=lib${LIB}
LIB= z
SHLIBDIR?= /lib
SHLIB_MAJOR= 6
diff --git a/lib/msun/Makefile b/lib/msun/Makefile
index e731a9876b9a..820855c86a75 100644
--- a/lib/msun/Makefile
+++ b/lib/msun/Makefile
@@ -12,6 +12,7 @@
#
#
+PACKAGE= clibs
.if ${MACHINE_CPUARCH} == "i386"
ARCH_SUBDIR= i387
.else
diff --git a/lib/msun/tests/Makefile b/lib/msun/tests/Makefile
index 8b114fde1c7c..92ebc0b2eba2 100644
--- a/lib/msun/tests/Makefile
+++ b/lib/msun/tests/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE=tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libm
# All architectures on FreeBSD have fenv.h
diff --git a/lib/ncurses/ncurses/Makefile b/lib/ncurses/ncurses/Makefile
index 94fb03a9b278..cf9053ca94c8 100644
--- a/lib/ncurses/ncurses/Makefile
+++ b/lib/ncurses/ncurses/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= clibs
SHLIBDIR?= /lib
.if !defined(ENABLE_WIDEC)
diff --git a/lib/tests/Makefile b/lib/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/lib/tests/Makefile
+++ b/lib/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/libexec/atf/atf-check/tests/Makefile b/libexec/atf/atf-check/tests/Makefile
index 87b26cb4a823..d17f8b42326e 100644
--- a/libexec/atf/atf-check/tests/Makefile
+++ b/libexec/atf/atf-check/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.init.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF= ${SRCTOP}/contrib/atf
.PATH: ${ATF}/atf-sh
diff --git a/libexec/atf/atf-sh/tests/Makefile b/libexec/atf/atf-sh/tests/Makefile
index 9ccd6a7a44f1..db2200b49019 100644
--- a/libexec/atf/atf-sh/tests/Makefile
+++ b/libexec/atf/atf-sh/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.init.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
ATF= ${SRCTOP}/contrib/atf
.PATH: ${ATF}/atf-sh
diff --git a/libexec/atf/tests/Makefile b/libexec/atf/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/libexec/atf/tests/Makefile
+++ b/libexec/atf/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/libexec/atrun/Makefile b/libexec/atrun/Makefile
index 39952fc430ea..b11e2e92dcbf 100644
--- a/libexec/atrun/Makefile
+++ b/libexec/atrun/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=at
MAINSRC=${.CURDIR}/../../usr.bin/at
.include "${MAINSRC}/Makefile.inc"
diff --git a/libexec/casper/Makefile b/libexec/casper/Makefile
new file mode 100644
index 000000000000..c66edd6b8cdf
--- /dev/null
+++ b/libexec/casper/Makefile
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+PACKAGE=casper
+SUBDIR= dns
+SUBDIR+=grp
+SUBDIR+=pwd
+SUBDIR+=random
+SUBDIR+=sysctl
+
+.include <bsd.subdir.mk>
diff --git a/libexec/casper/dns/Makefile b/libexec/casper/dns/Makefile
new file mode 100644
index 000000000000..065977fd966c
--- /dev/null
+++ b/libexec/casper/dns/Makefile
@@ -0,0 +1,22 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR} ${.CURDIR}/../../../sbin/casper
+
+PACKAGE=casper
+PROG= dns
+
+SRCS= dns.c
+
+LIBADD= casper nv
+
+BINDIR= /libexec/casper
+
+CFLAGS+=-I${.CURDIR}
+CFLAGS+=-I${.CURDIR}/../../../lib/libcapsicum
+CFLAGS+=-I${.CURDIR}/../../../lib/libcasper
+CFLAGS+=-I${.CURDIR}/../../../lib/libpjdlog
+CFLAGS+=-I${.CURDIR}/../../../sbin/casper
+
+MAN=
+
+.include <bsd.prog.mk>
diff --git a/libexec/casper/dns/Makefile.depend b/libexec/casper/dns/Makefile.depend
new file mode 100644
index 000000000000..aa79c093cb61
--- /dev/null
+++ b/libexec/casper/dns/Makefile.depend
@@ -0,0 +1,23 @@
+# $FreeBSD$
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcapsicum \
+ lib/libcasper \
+ lib/libcompiler_rt \
+ lib/libnv \
+ lib/libpjdlog \
+ lib/libutil \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/libexec/casper/dns/dns.c b/libexec/casper/dns/dns.c
new file mode 100644
index 000000000000..dbdb2a27d83b
--- /dev/null
+++ b/libexec/casper/dns/dns.c
@@ -0,0 +1,436 @@
+/*-
+ * Copyright (c) 2012-2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/nv.h>
+#include <netinet/in.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libcapsicum.h>
+#include <libcapsicum_dns.h>
+#include <libcasper.h>
+#include <pjdlog.h>
+
+static bool
+dns_allowed_type(const nvlist_t *limits, const char *type)
+{
+ const char *name;
+ bool notypes;
+ void *cookie;
+
+ if (limits == NULL)
+ return (true);
+
+ notypes = true;
+ cookie = NULL;
+ while ((name = nvlist_next(limits, NULL, &cookie)) != NULL) {
+ if (strncmp(name, "type", sizeof("type") - 1) != 0)
+ continue;
+ notypes = false;
+ if (strcmp(nvlist_get_string(limits, name), type) == 0)
+ return (true);
+ }
+
+ /* If there are no types at all, allow any type. */
+ if (notypes)
+ return (true);
+
+ return (false);
+}
+
+static bool
+dns_allowed_family(const nvlist_t *limits, int family)
+{
+ const char *name;
+ bool nofamilies;
+ void *cookie;
+
+ if (limits == NULL)
+ return (true);
+
+ nofamilies = true;
+ cookie = NULL;
+ while ((name = nvlist_next(limits, NULL, &cookie)) != NULL) {
+ if (strncmp(name, "family", sizeof("family") - 1) != 0)
+ continue;
+ nofamilies = false;
+ if (family == AF_UNSPEC)
+ continue;
+ if (nvlist_get_number(limits, name) == (uint64_t)family)
+ return (true);
+ }
+
+ /* If there are no families at all, allow any family. */
+ if (nofamilies)
+ return (true);
+
+ return (false);
+}
+
+static void
+hostent_pack(const struct hostent *hp, nvlist_t *nvl)
+{
+ unsigned int ii;
+ char nvlname[64];
+ int n;
+
+ nvlist_add_string(nvl, "name", hp->h_name);
+ nvlist_add_number(nvl, "addrtype", (uint64_t)hp->h_addrtype);
+ nvlist_add_number(nvl, "length", (uint64_t)hp->h_length);
+
+ if (hp->h_aliases == NULL) {
+ nvlist_add_number(nvl, "naliases", 0);
+ } else {
+ for (ii = 0; hp->h_aliases[ii] != NULL; ii++) {
+ n = snprintf(nvlname, sizeof(nvlname), "alias%u", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_string(nvl, nvlname, hp->h_aliases[ii]);
+ }
+ nvlist_add_number(nvl, "naliases", (uint64_t)ii);
+ }
+
+ if (hp->h_addr_list == NULL) {
+ nvlist_add_number(nvl, "naddrs", 0);
+ } else {
+ for (ii = 0; hp->h_addr_list[ii] != NULL; ii++) {
+ n = snprintf(nvlname, sizeof(nvlname), "addr%u", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_add_binary(nvl, nvlname, hp->h_addr_list[ii],
+ (size_t)hp->h_length);
+ }
+ nvlist_add_number(nvl, "naddrs", (uint64_t)ii);
+ }
+}
+
+static int
+dns_gethostbyname(const nvlist_t *limits, const nvlist_t *nvlin,
+ nvlist_t *nvlout)
+{
+ struct hostent *hp;
+ int family;
+
+ if (!dns_allowed_type(limits, "NAME"))
+ return (NO_RECOVERY);
+
+ family = (int)nvlist_get_number(nvlin, "family");
+
+ if (!dns_allowed_family(limits, family))
+ return (NO_RECOVERY);
+
+ hp = gethostbyname2(nvlist_get_string(nvlin, "name"), family);
+ if (hp == NULL)
+ return (h_errno);
+ hostent_pack(hp, nvlout);
+ return (0);
+}
+
+static int
+dns_gethostbyaddr(const nvlist_t *limits, const nvlist_t *nvlin,
+ nvlist_t *nvlout)
+{
+ struct hostent *hp;
+ const void *addr;
+ size_t addrsize;
+ int family;
+
+ if (!dns_allowed_type(limits, "ADDR"))
+ return (NO_RECOVERY);
+
+ family = (int)nvlist_get_number(nvlin, "family");
+
+ if (!dns_allowed_family(limits, family))
+ return (NO_RECOVERY);
+
+ addr = nvlist_get_binary(nvlin, "addr", &addrsize);
+ hp = gethostbyaddr(addr, (socklen_t)addrsize, family);
+ if (hp == NULL)
+ return (h_errno);
+ hostent_pack(hp, nvlout);
+ return (0);
+}
+
+static int
+dns_getnameinfo(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+ struct sockaddr_storage sast;
+ const void *sabin;
+ char *host, *serv;
+ size_t sabinsize, hostlen, servlen;
+ socklen_t salen;
+ int error, flags;
+
+ if (!dns_allowed_type(limits, "NAME"))
+ return (NO_RECOVERY);
+
+ error = 0;
+ host = serv = NULL;
+ memset(&sast, 0, sizeof(sast));
+
+ hostlen = (size_t)nvlist_get_number(nvlin, "hostlen");
+ servlen = (size_t)nvlist_get_number(nvlin, "servlen");
+
+ if (hostlen > 0) {
+ host = calloc(1, hostlen + 1);
+ if (host == NULL) {
+ error = EAI_MEMORY;
+ goto out;
+ }
+ }
+ if (servlen > 0) {
+ serv = calloc(1, servlen + 1);
+ if (serv == NULL) {
+ error = EAI_MEMORY;
+ goto out;
+ }
+ }
+
+ sabin = nvlist_get_binary(nvlin, "sa", &sabinsize);
+ if (sabinsize > sizeof(sast)) {
+ error = EAI_FAIL;
+ goto out;
+ }
+
+ memcpy(&sast, sabin, sabinsize);
+ salen = (socklen_t)sabinsize;
+
+ if ((sast.ss_family != AF_INET ||
+ salen != sizeof(struct sockaddr_in)) &&
+ (sast.ss_family != AF_INET6 ||
+ salen != sizeof(struct sockaddr_in6))) {
+ error = EAI_FAIL;
+ goto out;
+ }
+
+ if (!dns_allowed_family(limits, (int)sast.ss_family)) {
+ error = NO_RECOVERY;
+ goto out;
+ }
+
+ flags = (int)nvlist_get_number(nvlin, "flags");
+
+ error = getnameinfo((struct sockaddr *)&sast, salen, host, hostlen,
+ serv, servlen, flags);
+ if (error != 0)
+ goto out;
+
+ nvlist_move_string(nvlout, "host", host);
+ nvlist_move_string(nvlout, "serv", serv);
+out:
+ if (error != 0) {
+ free(host);
+ free(serv);
+ }
+ return (error);
+}
+
+static nvlist_t *
+addrinfo_pack(const struct addrinfo *ai)
+{
+ nvlist_t *nvl;
+
+ nvl = nvlist_create(0);
+ nvlist_add_number(nvl, "ai_flags", (uint64_t)ai->ai_flags);
+ nvlist_add_number(nvl, "ai_family", (uint64_t)ai->ai_family);
+ nvlist_add_number(nvl, "ai_socktype", (uint64_t)ai->ai_socktype);
+ nvlist_add_number(nvl, "ai_protocol", (uint64_t)ai->ai_protocol);
+ nvlist_add_binary(nvl, "ai_addr", ai->ai_addr, (size_t)ai->ai_addrlen);
+ nvlist_add_string(nvl, "ai_canonname", ai->ai_canonname);
+
+ return (nvl);
+}
+
+static int
+dns_getaddrinfo(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+ struct addrinfo hints, *hintsp, *res, *cur;
+ const char *hostname, *servname;
+ char nvlname[64];
+ nvlist_t *elem;
+ unsigned int ii;
+ int error, family, n;
+
+ if (!dns_allowed_type(limits, "ADDR"))
+ return (NO_RECOVERY);
+
+ hostname = nvlist_get_string(nvlin, "hostname");
+ servname = nvlist_get_string(nvlin, "servname");
+ if (nvlist_exists_number(nvlin, "hints.ai_flags")) {
+ size_t addrlen;
+
+ hints.ai_flags = (int)nvlist_get_number(nvlin,
+ "hints.ai_flags");
+ hints.ai_family = (int)nvlist_get_number(nvlin,
+ "hints.ai_family");
+ hints.ai_socktype = (int)nvlist_get_number(nvlin,
+ "hints.ai_socktype");
+ hints.ai_protocol = (int)nvlist_get_number(nvlin,
+ "hints.ai_protocol");
+ hints.ai_addrlen = 0;
+ hints.ai_addr = NULL;
+ hints.ai_canonname = NULL;
+ hintsp = &hints;
+ family = hints.ai_family;
+ } else {
+ hintsp = NULL;
+ family = AF_UNSPEC;
+ }
+
+ if (!dns_allowed_family(limits, family))
+ return (NO_RECOVERY);
+
+ error = getaddrinfo(hostname, servname, hintsp, &res);
+ if (error != 0)
+ goto out;
+
+ for (cur = res, ii = 0; cur != NULL; cur = cur->ai_next, ii++) {
+ elem = addrinfo_pack(cur);
+ n = snprintf(nvlname, sizeof(nvlname), "res%u", ii);
+ assert(n > 0 && n < (int)sizeof(nvlname));
+ nvlist_move_nvlist(nvlout, nvlname, elem);
+ }
+
+ freeaddrinfo(res);
+ error = 0;
+out:
+ return (error);
+}
+
+static bool
+limit_has_entry(const nvlist_t *limits, const char *prefix)
+{
+ const char *name;
+ size_t prefixlen;
+ void *cookie;
+
+ if (limits == NULL)
+ return (false);
+
+ prefixlen = strlen(prefix);
+
+ cookie = NULL;
+ while ((name = nvlist_next(limits, NULL, &cookie)) != NULL) {
+ if (strncmp(name, prefix, prefixlen) == 0)
+ return (true);
+ }
+
+ return (false);
+}
+
+static int
+dns_limit(const nvlist_t *oldlimits, const nvlist_t *newlimits)
+{
+ const char *name;
+ void *cookie;
+ int nvtype;
+ bool hastype, hasfamily;
+
+ hastype = false;
+ hasfamily = false;
+
+ cookie = NULL;
+ while ((name = nvlist_next(newlimits, &nvtype, &cookie)) != NULL) {
+ if (nvtype == NV_TYPE_STRING) {
+ const char *type;
+
+ if (strncmp(name, "type", sizeof("type") - 1) != 0)
+ return (EINVAL);
+ type = nvlist_get_string(newlimits, name);
+ if (strcmp(type, "ADDR") != 0 &&
+ strcmp(type, "NAME") != 0) {
+ return (EINVAL);
+ }
+ if (!dns_allowed_type(oldlimits, type))
+ return (ENOTCAPABLE);
+ hastype = true;
+ } else if (nvtype == NV_TYPE_NUMBER) {
+ int family;
+
+ if (strncmp(name, "family", sizeof("family") - 1) != 0)
+ return (EINVAL);
+ family = (int)nvlist_get_number(newlimits, name);
+ if (!dns_allowed_family(oldlimits, family))
+ return (ENOTCAPABLE);
+ hasfamily = true;
+ } else {
+ return (EINVAL);
+ }
+ }
+
+ /*
+ * If the new limit doesn't mention type or family we have to
+ * check if the current limit does have those. Missing type or
+ * family in the limit means that all types or families are
+ * allowed.
+ */
+ if (!hastype) {
+ if (limit_has_entry(oldlimits, "type"))
+ return (ENOTCAPABLE);
+ }
+ if (!hasfamily) {
+ if (limit_has_entry(oldlimits, "family"))
+ return (ENOTCAPABLE);
+ }
+
+ return (0);
+}
+
+static int
+dns_command(const char *cmd, const nvlist_t *limits, nvlist_t *nvlin,
+ nvlist_t *nvlout)
+{
+ int error;
+
+ if (strcmp(cmd, "gethostbyname") == 0)
+ error = dns_gethostbyname(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "gethostbyaddr") == 0)
+ error = dns_gethostbyaddr(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "getnameinfo") == 0)
+ error = dns_getnameinfo(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "getaddrinfo") == 0)
+ error = dns_getaddrinfo(limits, nvlin, nvlout);
+ else
+ error = NO_RECOVERY;
+
+ return (error);
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ return (service_start("system.dns", PARENT_FILENO, dns_limit,
+ dns_command, argc, argv));
+}
diff --git a/libexec/casper/grp/Makefile b/libexec/casper/grp/Makefile
new file mode 100644
index 000000000000..454212e586cd
--- /dev/null
+++ b/libexec/casper/grp/Makefile
@@ -0,0 +1,22 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR} ${.CURDIR}/../../../sbin/casper
+
+PACKAGE=casper
+PROG= grp
+
+SRCS= grp.c
+
+LIBADD= casper nv pjdlog
+
+BINDIR= /libexec/casper
+
+CFLAGS+=-I${.CURDIR}
+CFLAGS+=-I${.CURDIR}/../../../lib/libcapsicum
+CFLAGS+=-I${.CURDIR}/../../../lib/libcasper
+CFLAGS+=-I${.CURDIR}/../../../lib/libpjdlog
+CFLAGS+=-I${.CURDIR}/../../../sbin/casper
+
+MAN=
+
+.include <bsd.prog.mk>
diff --git a/libexec/casper/grp/Makefile.depend b/libexec/casper/grp/Makefile.depend
new file mode 100644
index 000000000000..aa79c093cb61
--- /dev/null
+++ b/libexec/casper/grp/Makefile.depend
@@ -0,0 +1,23 @@
+# $FreeBSD$
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcapsicum \
+ lib/libcasper \
+ lib/libcompiler_rt \
+ lib/libnv \
+ lib/libpjdlog \
+ lib/libutil \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/libexec/casper/grp/grp.c b/libexec/casper/grp/grp.c
new file mode 100644
index 000000000000..5b3e13d9415d
--- /dev/null
+++ b/libexec/casper/grp/grp.c
@@ -0,0 +1,390 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/nv.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <grp.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libcapsicum.h>
+#include <libcasper.h>
+#include <pjdlog.h>
+
+static bool
+grp_allowed_cmd(const nvlist_t *limits, const char *cmd)
+{
+
+ if (limits == NULL)
+ return (true);
+
+ /*
+ * If no limit was set on allowed commands, then all commands
+ * are allowed.
+ */
+ if (!nvlist_exists_nvlist(limits, "cmds"))
+ return (true);
+
+ limits = nvlist_get_nvlist(limits, "cmds");
+ return (nvlist_exists_null(limits, cmd));
+}
+
+static int
+grp_allowed_cmds(const nvlist_t *oldlimits, const nvlist_t *newlimits)
+{
+ const char *name;
+ void *cookie;
+ int type;
+
+ cookie = NULL;
+ while ((name = nvlist_next(newlimits, &type, &cookie)) != NULL) {
+ if (type != NV_TYPE_NULL)
+ return (EINVAL);
+ if (!grp_allowed_cmd(oldlimits, name))
+ return (ENOTCAPABLE);
+ }
+
+ return (0);
+}
+
+static bool
+grp_allowed_group(const nvlist_t *limits, const char *gname, gid_t gid)
+{
+ const char *name;
+ void *cookie;
+ int type;
+
+ if (limits == NULL)
+ return (true);
+
+ /*
+ * If no limit was set on allowed groups, then all groups are allowed.
+ */
+ if (!nvlist_exists_nvlist(limits, "groups"))
+ return (true);
+
+ limits = nvlist_get_nvlist(limits, "groups");
+ cookie = NULL;
+ while ((name = nvlist_next(limits, &type, &cookie)) != NULL) {
+ switch (type) {
+ case NV_TYPE_NUMBER:
+ if (gid != (gid_t)-1 &&
+ nvlist_get_number(limits, name) == (uint64_t)gid) {
+ return (true);
+ }
+ break;
+ case NV_TYPE_STRING:
+ if (gname != NULL &&
+ strcmp(nvlist_get_string(limits, name),
+ gname) == 0) {
+ return (true);
+ }
+ break;
+ default:
+ PJDLOG_ABORT("Unexpected type %d.", type);
+ }
+ }
+
+ return (false);
+}
+
+static int
+grp_allowed_groups(const nvlist_t *oldlimits, const nvlist_t *newlimits)
+{
+ const char *name, *gname;
+ void *cookie;
+ gid_t gid;
+ int type;
+
+ cookie = NULL;
+ while ((name = nvlist_next(newlimits, &type, &cookie)) != NULL) {
+ switch (type) {
+ case NV_TYPE_NUMBER:
+ gid = (gid_t)nvlist_get_number(newlimits, name);
+ gname = NULL;
+ break;
+ case NV_TYPE_STRING:
+ gid = (gid_t)-1;
+ gname = nvlist_get_string(newlimits, name);
+ break;
+ default:
+ return (EINVAL);
+ }
+ if (!grp_allowed_group(oldlimits, gname, gid))
+ return (ENOTCAPABLE);
+ }
+
+ return (0);
+}
+
+static bool
+grp_allowed_field(const nvlist_t *limits, const char *field)
+{
+
+ if (limits == NULL)
+ return (true);
+
+ /*
+ * If no limit was set on allowed fields, then all fields are allowed.
+ */
+ if (!nvlist_exists_nvlist(limits, "fields"))
+ return (true);
+
+ limits = nvlist_get_nvlist(limits, "fields");
+ return (nvlist_exists_null(limits, field));
+}
+
+static int
+grp_allowed_fields(const nvlist_t *oldlimits, const nvlist_t *newlimits)
+{
+ const char *name;
+ void *cookie;
+ int type;
+
+ cookie = NULL;
+ while ((name = nvlist_next(newlimits, &type, &cookie)) != NULL) {
+ if (type != NV_TYPE_NULL)
+ return (EINVAL);
+ if (!grp_allowed_field(oldlimits, name))
+ return (ENOTCAPABLE);
+ }
+
+ return (0);
+}
+
+static bool
+grp_pack(const nvlist_t *limits, const struct group *grp, nvlist_t *nvl)
+{
+ char nvlname[64];
+ int n;
+
+ if (grp == NULL)
+ return (true);
+
+ /*
+ * If either name or GID is allowed, we allow it.
+ */
+ if (!grp_allowed_group(limits, grp->gr_name, grp->gr_gid))
+ return (false);
+
+ if (grp_allowed_field(limits, "gr_name"))
+ nvlist_add_string(nvl, "gr_name", grp->gr_name);
+ else
+ nvlist_add_string(nvl, "gr_name", "");
+ if (grp_allowed_field(limits, "gr_passwd"))
+ nvlist_add_string(nvl, "gr_passwd", grp->gr_passwd);
+ else
+ nvlist_add_string(nvl, "gr_passwd", "");
+ if (grp_allowed_field(limits, "gr_gid"))
+ nvlist_add_number(nvl, "gr_gid", (uint64_t)grp->gr_gid);
+ else
+ nvlist_add_number(nvl, "gr_gid", (uint64_t)-1);
+ if (grp_allowed_field(limits, "gr_mem") && grp->gr_mem[0] != NULL) {
+ unsigned int ngroups;
+
+ for (ngroups = 0; grp->gr_mem[ngroups] != NULL; ngroups++) {
+ n = snprintf(nvlname, sizeof(nvlname), "gr_mem[%u]",
+ ngroups);
+ assert(n > 0 && n < sizeof(nvlname));
+ nvlist_add_string(nvl, nvlname, grp->gr_mem[ngroups]);
+ }
+ nvlist_add_number(nvl, "gr_nmem", (uint64_t)ngroups);
+ }
+
+ return (true);
+}
+
+static int
+grp_getgrent(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+ struct group *grp;
+
+ for (;;) {
+ errno = 0;
+ grp = getgrent();
+ if (errno != 0)
+ return (errno);
+ if (grp_pack(limits, grp, nvlout))
+ return (0);
+ }
+
+ /* NOTREACHED */
+}
+
+static int
+grp_getgrnam(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+ struct group *grp;
+ const char *name;
+
+ if (!nvlist_exists_string(nvlin, "name"))
+ return (EINVAL);
+ name = nvlist_get_string(nvlin, "name");
+ PJDLOG_ASSERT(name != NULL);
+
+ errno = 0;
+ grp = getgrnam(name);
+ if (errno != 0)
+ return (errno);
+
+ (void)grp_pack(limits, grp, nvlout);
+
+ return (0);
+}
+
+static int
+grp_getgrgid(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+ struct group *grp;
+ gid_t gid;
+
+ if (!nvlist_exists_number(nvlin, "gid"))
+ return (EINVAL);
+
+ gid = (gid_t)nvlist_get_number(nvlin, "gid");
+
+ errno = 0;
+ grp = getgrgid(gid);
+ if (errno != 0)
+ return (errno);
+
+ (void)grp_pack(limits, grp, nvlout);
+
+ return (0);
+}
+
+static int
+grp_setgroupent(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+ int stayopen;
+
+ if (!nvlist_exists_bool(nvlin, "stayopen"))
+ return (EINVAL);
+
+ stayopen = nvlist_get_bool(nvlin, "stayopen") ? 1 : 0;
+
+ return (setgroupent(stayopen) == 0 ? EFAULT : 0);
+}
+
+static int
+grp_setgrent(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+
+ return (setgrent() == 0 ? EFAULT : 0);
+}
+
+static int
+grp_endgrent(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+
+ endgrent();
+
+ return (0);
+}
+
+static int
+grp_limit(const nvlist_t *oldlimits, const nvlist_t *newlimits)
+{
+ const nvlist_t *limits;
+ const char *name;
+ void *cookie;
+ int error, type;
+
+ if (oldlimits != NULL && nvlist_exists_nvlist(oldlimits, "cmds") &&
+ !nvlist_exists_nvlist(newlimits, "cmds")) {
+ return (ENOTCAPABLE);
+ }
+ if (oldlimits != NULL && nvlist_exists_nvlist(oldlimits, "fields") &&
+ !nvlist_exists_nvlist(newlimits, "fields")) {
+ return (ENOTCAPABLE);
+ }
+ if (oldlimits != NULL && nvlist_exists_nvlist(oldlimits, "groups") &&
+ !nvlist_exists_nvlist(newlimits, "groups")) {
+ return (ENOTCAPABLE);
+ }
+
+ cookie = NULL;
+ while ((name = nvlist_next(newlimits, &type, &cookie)) != NULL) {
+ if (type != NV_TYPE_NVLIST)
+ return (EINVAL);
+ limits = nvlist_get_nvlist(newlimits, name);
+ if (strcmp(name, "cmds") == 0)
+ error = grp_allowed_cmds(oldlimits, limits);
+ else if (strcmp(name, "fields") == 0)
+ error = grp_allowed_fields(oldlimits, limits);
+ else if (strcmp(name, "groups") == 0)
+ error = grp_allowed_groups(oldlimits, limits);
+ else
+ error = EINVAL;
+ if (error != 0)
+ return (error);
+ }
+
+ return (0);
+}
+
+static int
+grp_command(const char *cmd, const nvlist_t *limits, nvlist_t *nvlin,
+ nvlist_t *nvlout)
+{
+ int error;
+
+ if (!grp_allowed_cmd(limits, cmd))
+ return (ENOTCAPABLE);
+
+ if (strcmp(cmd, "getgrent") == 0 || strcmp(cmd, "getgrent_r") == 0)
+ error = grp_getgrent(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "getgrnam") == 0 || strcmp(cmd, "getgrnam_r") == 0)
+ error = grp_getgrnam(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "getgrgid") == 0 || strcmp(cmd, "getgrgid_r") == 0)
+ error = grp_getgrgid(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "setgroupent") == 0)
+ error = grp_setgroupent(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "setgrent") == 0)
+ error = grp_setgrent(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "endgrent") == 0)
+ error = grp_endgrent(limits, nvlin, nvlout);
+ else
+ error = EINVAL;
+
+ return (error);
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ return (service_start("system.grp", PARENT_FILENO, grp_limit,
+ grp_command, argc, argv));
+}
diff --git a/libexec/casper/pwd/Makefile b/libexec/casper/pwd/Makefile
new file mode 100644
index 000000000000..91dd60975297
--- /dev/null
+++ b/libexec/casper/pwd/Makefile
@@ -0,0 +1,22 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR} ${.CURDIR}/../../../sbin/casper
+
+PACKAGE=casper
+PROG= pwd
+
+SRCS= pwd.c
+
+LIBADD= casper nv pjdlog
+
+BINDIR= /libexec/casper
+
+CFLAGS+=-I${.CURDIR}
+CFLAGS+=-I${.CURDIR}/../../../lib/libcapsicum
+CFLAGS+=-I${.CURDIR}/../../../lib/libcasper
+CFLAGS+=-I${.CURDIR}/../../../lib/libpjdlog
+CFLAGS+=-I${.CURDIR}/../../../sbin/casper
+
+MAN=
+
+.include <bsd.prog.mk>
diff --git a/libexec/casper/pwd/Makefile.depend b/libexec/casper/pwd/Makefile.depend
new file mode 100644
index 000000000000..aa79c093cb61
--- /dev/null
+++ b/libexec/casper/pwd/Makefile.depend
@@ -0,0 +1,23 @@
+# $FreeBSD$
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcapsicum \
+ lib/libcasper \
+ lib/libcompiler_rt \
+ lib/libnv \
+ lib/libpjdlog \
+ lib/libutil \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/libexec/casper/pwd/pwd.c b/libexec/casper/pwd/pwd.c
new file mode 100644
index 000000000000..0a06c5f6bfd7
--- /dev/null
+++ b/libexec/casper/pwd/pwd.c
@@ -0,0 +1,430 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/nv.h>
+
+#include <errno.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libcapsicum.h>
+#include <libcasper.h>
+#include <pjdlog.h>
+
+static bool
+pwd_allowed_cmd(const nvlist_t *limits, const char *cmd)
+{
+
+ if (limits == NULL)
+ return (true);
+
+ /*
+ * If no limit was set on allowed commands, then all commands
+ * are allowed.
+ */
+ if (!nvlist_exists_nvlist(limits, "cmds"))
+ return (true);
+
+ limits = nvlist_get_nvlist(limits, "cmds");
+ return (nvlist_exists_null(limits, cmd));
+}
+
+static int
+pwd_allowed_cmds(const nvlist_t *oldlimits, const nvlist_t *newlimits)
+{
+ const char *name;
+ void *cookie;
+ int type;
+
+ cookie = NULL;
+ while ((name = nvlist_next(newlimits, &type, &cookie)) != NULL) {
+ if (type != NV_TYPE_NULL)
+ return (EINVAL);
+ if (!pwd_allowed_cmd(oldlimits, name))
+ return (ENOTCAPABLE);
+ }
+
+ return (0);
+}
+
+static bool
+pwd_allowed_user(const nvlist_t *limits, const char *uname, uid_t uid)
+{
+ const char *name;
+ void *cookie;
+ int type;
+
+ if (limits == NULL)
+ return (true);
+
+ /*
+ * If no limit was set on allowed users, then all users are allowed.
+ */
+ if (!nvlist_exists_nvlist(limits, "users"))
+ return (true);
+
+ limits = nvlist_get_nvlist(limits, "users");
+ cookie = NULL;
+ while ((name = nvlist_next(limits, &type, &cookie)) != NULL) {
+ switch (type) {
+ case NV_TYPE_NUMBER:
+ if (uid != (uid_t)-1 &&
+ nvlist_get_number(limits, name) == (uint64_t)uid) {
+ return (true);
+ }
+ break;
+ case NV_TYPE_STRING:
+ if (uname != NULL &&
+ strcmp(nvlist_get_string(limits, name),
+ uname) == 0) {
+ return (true);
+ }
+ break;
+ default:
+ PJDLOG_ABORT("Unexpected type %d.", type);
+ }
+ }
+
+ return (false);
+}
+
+static int
+pwd_allowed_users(const nvlist_t *oldlimits, const nvlist_t *newlimits)
+{
+ const char *name, *uname;
+ void *cookie;
+ uid_t uid;
+ int type;
+
+ cookie = NULL;
+ while ((name = nvlist_next(newlimits, &type, &cookie)) != NULL) {
+ switch (type) {
+ case NV_TYPE_NUMBER:
+ uid = (uid_t)nvlist_get_number(newlimits, name);
+ uname = NULL;
+ break;
+ case NV_TYPE_STRING:
+ uid = (uid_t)-1;
+ uname = nvlist_get_string(newlimits, name);
+ break;
+ default:
+ return (EINVAL);
+ }
+ if (!pwd_allowed_user(oldlimits, uname, uid))
+ return (ENOTCAPABLE);
+ }
+
+ return (0);
+}
+
+static bool
+pwd_allowed_field(const nvlist_t *limits, const char *field)
+{
+
+ if (limits == NULL)
+ return (true);
+
+ /*
+ * If no limit was set on allowed fields, then all fields are allowed.
+ */
+ if (!nvlist_exists_nvlist(limits, "fields"))
+ return (true);
+
+ limits = nvlist_get_nvlist(limits, "fields");
+ return (nvlist_exists_null(limits, field));
+}
+
+static int
+pwd_allowed_fields(const nvlist_t *oldlimits, const nvlist_t *newlimits)
+{
+ const char *name;
+ void *cookie;
+ int type;
+
+ cookie = NULL;
+ while ((name = nvlist_next(newlimits, &type, &cookie)) != NULL) {
+ if (type != NV_TYPE_NULL)
+ return (EINVAL);
+ if (!pwd_allowed_field(oldlimits, name))
+ return (ENOTCAPABLE);
+ }
+
+ return (0);
+}
+
+static bool
+pwd_pack(const nvlist_t *limits, const struct passwd *pwd, nvlist_t *nvl)
+{
+ int fields;
+
+ if (pwd == NULL)
+ return (true);
+
+ /*
+ * If either name or UID is allowed, we allow it.
+ */
+ if (!pwd_allowed_user(limits, pwd->pw_name, pwd->pw_uid))
+ return (false);
+
+ fields = pwd->pw_fields;
+
+ if (pwd_allowed_field(limits, "pw_name")) {
+ nvlist_add_string(nvl, "pw_name", pwd->pw_name);
+ } else {
+ nvlist_add_string(nvl, "pw_name", "");
+ fields &= ~_PWF_NAME;
+ }
+ if (pwd_allowed_field(limits, "pw_uid")) {
+ nvlist_add_number(nvl, "pw_uid", (uint64_t)pwd->pw_uid);
+ } else {
+ nvlist_add_number(nvl, "pw_uid", (uint64_t)-1);
+ fields &= ~_PWF_UID;
+ }
+ if (pwd_allowed_field(limits, "pw_gid")) {
+ nvlist_add_number(nvl, "pw_gid", (uint64_t)pwd->pw_gid);
+ } else {
+ nvlist_add_number(nvl, "pw_gid", (uint64_t)-1);
+ fields &= ~_PWF_GID;
+ }
+ if (pwd_allowed_field(limits, "pw_change")) {
+ nvlist_add_number(nvl, "pw_change", (uint64_t)pwd->pw_change);
+ } else {
+ nvlist_add_number(nvl, "pw_change", (uint64_t)0);
+ fields &= ~_PWF_CHANGE;
+ }
+ if (pwd_allowed_field(limits, "pw_passwd")) {
+ nvlist_add_string(nvl, "pw_passwd", pwd->pw_passwd);
+ } else {
+ nvlist_add_string(nvl, "pw_passwd", "");
+ fields &= ~_PWF_PASSWD;
+ }
+ if (pwd_allowed_field(limits, "pw_class")) {
+ nvlist_add_string(nvl, "pw_class", pwd->pw_class);
+ } else {
+ nvlist_add_string(nvl, "pw_class", "");
+ fields &= ~_PWF_CLASS;
+ }
+ if (pwd_allowed_field(limits, "pw_gecos")) {
+ nvlist_add_string(nvl, "pw_gecos", pwd->pw_gecos);
+ } else {
+ nvlist_add_string(nvl, "pw_gecos", "");
+ fields &= ~_PWF_GECOS;
+ }
+ if (pwd_allowed_field(limits, "pw_dir")) {
+ nvlist_add_string(nvl, "pw_dir", pwd->pw_dir);
+ } else {
+ nvlist_add_string(nvl, "pw_dir", "");
+ fields &= ~_PWF_DIR;
+ }
+ if (pwd_allowed_field(limits, "pw_shell")) {
+ nvlist_add_string(nvl, "pw_shell", pwd->pw_shell);
+ } else {
+ nvlist_add_string(nvl, "pw_shell", "");
+ fields &= ~_PWF_SHELL;
+ }
+ if (pwd_allowed_field(limits, "pw_expire")) {
+ nvlist_add_number(nvl, "pw_expire", (uint64_t)pwd->pw_expire);
+ } else {
+ nvlist_add_number(nvl, "pw_expire", (uint64_t)0);
+ fields &= ~_PWF_EXPIRE;
+ }
+ nvlist_add_number(nvl, "pw_fields", (uint64_t)fields);
+
+ return (true);
+}
+
+static int
+pwd_getpwent(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+ struct passwd *pwd;
+
+ for (;;) {
+ errno = 0;
+ pwd = getpwent();
+ if (errno != 0)
+ return (errno);
+ if (pwd_pack(limits, pwd, nvlout))
+ return (0);
+ }
+
+ /* NOTREACHED */
+}
+
+static int
+pwd_getpwnam(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+ struct passwd *pwd;
+ const char *name;
+
+ if (!nvlist_exists_string(nvlin, "name"))
+ return (EINVAL);
+ name = nvlist_get_string(nvlin, "name");
+ PJDLOG_ASSERT(name != NULL);
+
+ errno = 0;
+ pwd = getpwnam(name);
+ if (errno != 0)
+ return (errno);
+
+ (void)pwd_pack(limits, pwd, nvlout);
+
+ return (0);
+}
+
+static int
+pwd_getpwuid(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+ struct passwd *pwd;
+ uid_t uid;
+
+ if (!nvlist_exists_number(nvlin, "uid"))
+ return (EINVAL);
+
+ uid = (uid_t)nvlist_get_number(nvlin, "uid");
+
+ errno = 0;
+ pwd = getpwuid(uid);
+ if (errno != 0)
+ return (errno);
+
+ (void)pwd_pack(limits, pwd, nvlout);
+
+ return (0);
+}
+
+static int
+pwd_setpassent(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+ int stayopen;
+
+ if (!nvlist_exists_bool(nvlin, "stayopen"))
+ return (EINVAL);
+
+ stayopen = nvlist_get_bool(nvlin, "stayopen") ? 1 : 0;
+
+ return (setpassent(stayopen) == 0 ? EFAULT : 0);
+}
+
+static int
+pwd_setpwent(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+
+ setpwent();
+
+ return (0);
+}
+
+static int
+pwd_endpwent(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
+{
+
+ endpwent();
+
+ return (0);
+}
+
+static int
+pwd_limit(const nvlist_t *oldlimits, const nvlist_t *newlimits)
+{
+ const nvlist_t *limits;
+ const char *name;
+ void *cookie;
+ int error, type;
+
+ if (oldlimits != NULL && nvlist_exists_nvlist(oldlimits, "cmds") &&
+ !nvlist_exists_nvlist(newlimits, "cmds")) {
+ return (ENOTCAPABLE);
+ }
+ if (oldlimits != NULL && nvlist_exists_nvlist(oldlimits, "fields") &&
+ !nvlist_exists_nvlist(newlimits, "fields")) {
+ return (ENOTCAPABLE);
+ }
+ if (oldlimits != NULL && nvlist_exists_nvlist(oldlimits, "users") &&
+ !nvlist_exists_nvlist(newlimits, "users")) {
+ return (ENOTCAPABLE);
+ }
+
+ cookie = NULL;
+ while ((name = nvlist_next(newlimits, &type, &cookie)) != NULL) {
+ if (type != NV_TYPE_NVLIST)
+ return (EINVAL);
+ limits = nvlist_get_nvlist(newlimits, name);
+ if (strcmp(name, "cmds") == 0)
+ error = pwd_allowed_cmds(oldlimits, limits);
+ else if (strcmp(name, "fields") == 0)
+ error = pwd_allowed_fields(oldlimits, limits);
+ else if (strcmp(name, "users") == 0)
+ error = pwd_allowed_users(oldlimits, limits);
+ else
+ error = EINVAL;
+ if (error != 0)
+ return (error);
+ }
+
+ return (0);
+}
+
+static int
+pwd_command(const char *cmd, const nvlist_t *limits, nvlist_t *nvlin,
+ nvlist_t *nvlout)
+{
+ int error;
+
+ if (!pwd_allowed_cmd(limits, cmd))
+ return (ENOTCAPABLE);
+
+ if (strcmp(cmd, "getpwent") == 0 || strcmp(cmd, "getpwent_r") == 0)
+ error = pwd_getpwent(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "getpwnam") == 0 || strcmp(cmd, "getpwnam_r") == 0)
+ error = pwd_getpwnam(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "getpwuid") == 0 || strcmp(cmd, "getpwuid_r") == 0)
+ error = pwd_getpwuid(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "setpassent") == 0)
+ error = pwd_setpassent(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "setpwent") == 0)
+ error = pwd_setpwent(limits, nvlin, nvlout);
+ else if (strcmp(cmd, "endpwent") == 0)
+ error = pwd_endpwent(limits, nvlin, nvlout);
+ else
+ error = EINVAL;
+
+ return (error);
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ return (service_start("system.pwd", PARENT_FILENO, pwd_limit,
+ pwd_command, argc, argv));
+}
diff --git a/libexec/casper/random/Makefile b/libexec/casper/random/Makefile
new file mode 100644
index 000000000000..208f299b5ddd
--- /dev/null
+++ b/libexec/casper/random/Makefile
@@ -0,0 +1,22 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR} ${.CURDIR}/../../../sbin/casper
+
+PACKAGE=casper
+PROG= random
+
+SRCS= random.c
+
+LIBADD= casper nv
+
+BINDIR= /libexec/casper
+
+CFLAGS+=-I${.CURDIR}
+CFLAGS+=-I${.CURDIR}/../../../lib/libcapsicum
+CFLAGS+=-I${.CURDIR}/../../../lib/libcasper
+CFLAGS+=-I${.CURDIR}/../../../lib/libpjdlog
+CFLAGS+=-I${.CURDIR}/../../../sbin/casper
+
+MAN=
+
+.include <bsd.prog.mk>
diff --git a/libexec/casper/random/Makefile.depend b/libexec/casper/random/Makefile.depend
new file mode 100644
index 000000000000..aa79c093cb61
--- /dev/null
+++ b/libexec/casper/random/Makefile.depend
@@ -0,0 +1,23 @@
+# $FreeBSD$
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcapsicum \
+ lib/libcasper \
+ lib/libcompiler_rt \
+ lib/libnv \
+ lib/libpjdlog \
+ lib/libutil \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/libexec/casper/random/random.c b/libexec/casper/random/random.c
new file mode 100644
index 000000000000..db91685a0eaa
--- /dev/null
+++ b/libexec/casper/random/random.c
@@ -0,0 +1,82 @@
+/*-
+ * Copyright (c) 2012-2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/nv.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libcapsicum.h>
+#include <libcasper.h>
+#include <pjdlog.h>
+
+#define MAXSIZE (1024 * 1024)
+
+static int
+random_command(const char *cmd, const nvlist_t *limits, nvlist_t *nvlin,
+ nvlist_t *nvlout)
+{
+ void *data;
+ size_t size;
+
+ if (strcmp(cmd, "generate") != 0)
+ return (EINVAL);
+ if (!nvlist_exists_number(nvlin, "size"))
+ return (EINVAL);
+
+ size = (size_t)nvlist_get_number(nvlin, "size");
+ if (size == 0 || size > MAXSIZE)
+ return (EINVAL);
+
+ data = malloc(size);
+ if (data == NULL)
+ return (ENOMEM);
+
+ arc4random_buf(data, size);
+
+ nvlist_move_binary(nvlout, "data", data, size);
+
+ return (0);
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ /*
+ * TODO: Sandbox this.
+ */
+
+ return (service_start("system.random", PARENT_FILENO, NULL,
+ random_command, argc, argv));
+}
diff --git a/libexec/casper/sysctl/Makefile b/libexec/casper/sysctl/Makefile
new file mode 100644
index 000000000000..e9b4bf66ce7d
--- /dev/null
+++ b/libexec/casper/sysctl/Makefile
@@ -0,0 +1,22 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR} ${.CURDIR}/../../../sbin/casper
+
+PACKAGE=casper
+PROG= sysctl
+
+SRCS= sysctl.c
+
+LIBADD= casper nv pjdlog
+
+BINDIR= /libexec/casper
+
+CFLAGS+=-I${.CURDIR}
+CFLAGS+=-I${.CURDIR}/../../../lib/libcapsicum
+CFLAGS+=-I${.CURDIR}/../../../lib/libcasper
+CFLAGS+=-I${.CURDIR}/../../../lib/libpjdlog
+CFLAGS+=-I${.CURDIR}/../../../sbin/casper
+
+MAN=
+
+.include <bsd.prog.mk>
diff --git a/libexec/casper/sysctl/Makefile.depend b/libexec/casper/sysctl/Makefile.depend
new file mode 100644
index 000000000000..aa79c093cb61
--- /dev/null
+++ b/libexec/casper/sysctl/Makefile.depend
@@ -0,0 +1,23 @@
+# $FreeBSD$
+# Autogenerated - do NOT edit!
+
+DIRDEPS = \
+ gnu/lib/csu \
+ gnu/lib/libgcc \
+ include \
+ include/xlocale \
+ lib/${CSU_DIR} \
+ lib/libc \
+ lib/libcapsicum \
+ lib/libcasper \
+ lib/libcompiler_rt \
+ lib/libnv \
+ lib/libpjdlog \
+ lib/libutil \
+
+
+.include <dirdeps.mk>
+
+.if ${DEP_RELDIR} == ${_DEP_RELDIR}
+# local dependencies - needed for -jN in clean tree
+.endif
diff --git a/libexec/casper/sysctl/sysctl.c b/libexec/casper/sysctl/sysctl.c
new file mode 100644
index 000000000000..4cbc505630a7
--- /dev/null
+++ b/libexec/casper/sysctl/sysctl.c
@@ -0,0 +1,249 @@
+/*-
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Pawel Jakub Dawidek 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 AUTHORS 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 AUTHORS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/nv.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libcapsicum.h>
+#include <libcapsicum_sysctl.h>
+#include <libcasper.h>
+#include <pjdlog.h>
+
+static int
+sysctl_check_one(const nvlist_t *nvl, bool islimit)
+{
+ const char *name;
+ void *cookie;
+ int type;
+ unsigned int fields;
+
+ /* NULL nvl is of course invalid. */
+ if (nvl == NULL)
+ return (EINVAL);
+ if (nvlist_error(nvl) != 0)
+ return (nvlist_error(nvl));
+
+#define HAS_NAME 0x01
+#define HAS_OPERATION 0x02
+
+ fields = 0;
+ cookie = NULL;
+ while ((name = nvlist_next(nvl, &type, &cookie)) != NULL) {
+ /* We accept only one 'name' and one 'operation' in nvl. */
+ if (strcmp(name, "name") == 0) {
+ if (type != NV_TYPE_STRING)
+ return (EINVAL);
+ /* Only one 'name' can be present. */
+ if ((fields & HAS_NAME) != 0)
+ return (EINVAL);
+ fields |= HAS_NAME;
+ } else if (strcmp(name, "operation") == 0) {
+ uint64_t operation;
+
+ if (type != NV_TYPE_NUMBER)
+ return (EINVAL);
+ /*
+ * We accept only CAP_SYSCTL_READ and
+ * CAP_SYSCTL_WRITE flags.
+ */
+ operation = nvlist_get_number(nvl, name);
+ if ((operation & ~(CAP_SYSCTL_RDWR)) != 0)
+ return (EINVAL);
+ /* ...but there has to be at least one of them. */
+ if ((operation & (CAP_SYSCTL_RDWR)) == 0)
+ return (EINVAL);
+ /* Only one 'operation' can be present. */
+ if ((fields & HAS_OPERATION) != 0)
+ return (EINVAL);
+ fields |= HAS_OPERATION;
+ } else if (islimit) {
+ /* If this is limit, there can be no other fields. */
+ return (EINVAL);
+ }
+ }
+
+ /* Both fields has to be there. */
+ if (fields != (HAS_NAME | HAS_OPERATION))
+ return (EINVAL);
+
+#undef HAS_OPERATION
+#undef HAS_NAME
+
+ return (0);
+}
+
+static bool
+sysctl_allowed(const nvlist_t *limits, const char *chname, uint64_t choperation)
+{
+ uint64_t operation;
+ const char *name;
+ void *cookie;
+ int type;
+
+ if (limits == NULL)
+ return (true);
+
+ cookie = NULL;
+ while ((name = nvlist_next(limits, &type, &cookie)) != NULL) {
+ PJDLOG_ASSERT(type == NV_TYPE_NUMBER);
+
+ operation = nvlist_get_number(limits, name);
+ if ((operation & choperation) != choperation)
+ continue;
+
+ if ((operation & CAP_SYSCTL_RECURSIVE) == 0) {
+ if (strcmp(name, chname) != 0)
+ continue;
+ } else {
+ size_t namelen;
+
+ namelen = strlen(name);
+ if (strncmp(name, chname, namelen) != 0)
+ continue;
+ if (chname[namelen] != '.' && chname[namelen] != '\0')
+ continue;
+ }
+
+ return (true);
+ }
+
+ return (false);
+}
+
+static int
+sysctl_limit(const nvlist_t *oldlimits, const nvlist_t *newlimits)
+{
+ const nvlist_t *nvl;
+ const char *name;
+ void *cookie;
+ uint64_t operation;
+ int error, type;
+
+ cookie = NULL;
+ while ((name = nvlist_next(newlimits, &type, &cookie)) != NULL) {
+ if (type != NV_TYPE_NUMBER)
+ return (EINVAL);
+ operation = nvlist_get_number(newlimits, name);
+ if ((operation & ~(CAP_SYSCTL_RDWR | CAP_SYSCTL_RECURSIVE)) != 0)
+ return (EINVAL);
+ if ((operation & (CAP_SYSCTL_RDWR | CAP_SYSCTL_RECURSIVE)) == 0)
+ return (EINVAL);
+ if (!sysctl_allowed(oldlimits, name, operation))
+ return (ENOTCAPABLE);
+ }
+
+ return (0);
+}
+
+static int
+sysctl_command(const char *cmd, const nvlist_t *limits, nvlist_t *nvlin,
+ nvlist_t *nvlout)
+{
+ const char *name;
+ const void *newp;
+ void *oldp;
+ uint64_t operation;
+ size_t oldlen, newlen;
+ size_t *oldlenp;
+ int error;
+
+ if (strcmp(cmd, "sysctl") != 0)
+ return (EINVAL);
+ error = sysctl_check_one(nvlin, false);
+ if (error != 0)
+ return (error);
+
+ name = nvlist_get_string(nvlin, "name");
+ operation = nvlist_get_number(nvlin, "operation");
+ if (!sysctl_allowed(limits, name, operation))
+ return (ENOTCAPABLE);
+
+ if ((operation & CAP_SYSCTL_WRITE) != 0) {
+ if (!nvlist_exists_binary(nvlin, "newp"))
+ return (EINVAL);
+ newp = nvlist_get_binary(nvlin, "newp", &newlen);
+ PJDLOG_ASSERT(newp != NULL && newlen > 0);
+ } else {
+ newp = NULL;
+ newlen = 0;
+ }
+
+ if ((operation & CAP_SYSCTL_READ) != 0) {
+ if (nvlist_exists_null(nvlin, "justsize")) {
+ oldp = NULL;
+ oldlen = 0;
+ oldlenp = &oldlen;
+ } else {
+ if (!nvlist_exists_number(nvlin, "oldlen"))
+ return (EINVAL);
+ oldlen = (size_t)nvlist_get_number(nvlin, "oldlen");
+ if (oldlen == 0)
+ return (EINVAL);
+ oldp = calloc(1, oldlen);
+ if (oldp == NULL)
+ return (ENOMEM);
+ oldlenp = &oldlen;
+ }
+ } else {
+ oldp = NULL;
+ oldlen = 0;
+ oldlenp = NULL;
+ }
+
+ if (sysctlbyname(name, oldp, oldlenp, newp, newlen) == -1) {
+ error = errno;
+ free(oldp);
+ return (error);
+ }
+
+ if ((operation & CAP_SYSCTL_READ) != 0) {
+ if (nvlist_exists_null(nvlin, "justsize"))
+ nvlist_add_number(nvlout, "oldlen", (uint64_t)oldlen);
+ else
+ nvlist_move_binary(nvlout, "oldp", oldp, oldlen);
+ }
+
+ return (0);
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ return (service_start("system.sysctl", PARENT_FILENO, sysctl_limit,
+ sysctl_command, argc, argv));
+}
diff --git a/libexec/dma/Makefile.inc b/libexec/dma/Makefile.inc
index e9a0d0a1c614..4db4bf106b4f 100644
--- a/libexec/dma/Makefile.inc
+++ b/libexec/dma/Makefile.inc
@@ -11,3 +11,4 @@ CFLAGS= -I${DMA_SOURCES} \
-DDMA_ROOT_USER='"mailnull"' \
-DDMA_GROUP='"mail"'
BINGRP= mail
+PACKAGE= dma
diff --git a/libexec/mail.local/Makefile b/libexec/mail.local/Makefile
index 79844e8972dd..6b4256f8a091 100644
--- a/libexec/mail.local/Makefile
+++ b/libexec/mail.local/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 7/19/93
# $FreeBSD$
+PACKAGE=sendmail
SENDMAIL_DIR=${.CURDIR}/../../contrib/sendmail
.PATH: ${SENDMAIL_DIR}/mail.local
diff --git a/libexec/rlogind/Makefile b/libexec/rlogind/Makefile
index 282ec6389611..b9327024b792 100644
--- a/libexec/rlogind/Makefile
+++ b/libexec/rlogind/Makefile
@@ -3,8 +3,10 @@
.include <src.opts.mk>
+PACKAGE=rcmds
PROG= rlogind
MAN= rlogind.8
+PACKAGE=rcmds
LIBADD= util
WARNS?= 2
diff --git a/libexec/rshd/Makefile b/libexec/rshd/Makefile
index c856995c5248..498b6995810b 100644
--- a/libexec/rshd/Makefile
+++ b/libexec/rshd/Makefile
@@ -1,9 +1,12 @@
# From: @(#)Makefile 8.1 (Berkeley) 6/4/93
# $FreeBSD$
+PACKAGE=rcmds
PROG= rshd
MAN= rshd.8
+PACKAGE=rcmds
+
WARNS?= 3
WFORMAT=0
diff --git a/libexec/rtld-elf/Makefile b/libexec/rtld-elf/Makefile
index ae49e9bd75a3..e2ebcce5f857 100644
--- a/libexec/rtld-elf/Makefile
+++ b/libexec/rtld-elf/Makefile
@@ -5,9 +5,13 @@
# make DEBUG_FLAGS=-g DEBUG=-DDEBUG MK_TESTS=no all
.include <src.opts.mk>
+PACKAGE= clibs
MK_SSP= no
PROG?= ld-elf.so.1
+.if (${PROG:M*ld-elf32*} != "")
+TAGS+= lib32
+.endif
SRCS= rtld_start.S \
reloc.c rtld.c rtld_lock.c rtld_printf.c map_object.c \
malloc.c xmalloc.c debug.c libmap.c
diff --git a/libexec/rtld-elf/tests/Makefile b/libexec/rtld-elf/tests/Makefile
index 3aecba085ba3..f6ca6054ddb5 100644
--- a/libexec/rtld-elf/tests/Makefile
+++ b/libexec/rtld-elf/tests/Makefile
@@ -2,6 +2,9 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
SUBDIR+= libpythagoras target
SUBDIR_DEPEND_target= libpythagoras
diff --git a/libexec/rtld-elf/tests/libpythagoras/Makefile b/libexec/rtld-elf/tests/libpythagoras/Makefile
index 9ad4b883015c..0e52dbd67d00 100644
--- a/libexec/rtld-elf/tests/libpythagoras/Makefile
+++ b/libexec/rtld-elf/tests/libpythagoras/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
LIB= pythagoras
SHLIB_MAJOR= 0
diff --git a/libexec/rtld-elf/tests/target/Makefile b/libexec/rtld-elf/tests/target/Makefile
index d5305f9b0501..7d80057ebd96 100644
--- a/libexec/rtld-elf/tests/target/Makefile
+++ b/libexec/rtld-elf/tests/target/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
PROG= target
BINDIR= ${TESTSBASE}/libexec/rtld-elf
diff --git a/libexec/smrsh/Makefile b/libexec/smrsh/Makefile
index e2e9c3b33d2a..02590ae61ed5 100644
--- a/libexec/smrsh/Makefile
+++ b/libexec/smrsh/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 7/2/95
# $FreeBSD$
+PACKAGE=sendmail
SENDMAIL_DIR=${.CURDIR}/../../contrib/sendmail
.PATH: ${SENDMAIL_DIR}/smrsh
diff --git a/libexec/tests/Makefile b/libexec/tests/Makefile
index a0e63e5da42a..04afe9ae889a 100644
--- a/libexec/tests/Makefile
+++ b/libexec/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TEST+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/release/packages/Makefile.package b/release/packages/Makefile.package
new file mode 100644
index 000000000000..40faed84ea03
--- /dev/null
+++ b/release/packages/Makefile.package
@@ -0,0 +1,73 @@
+#
+# $FreeBSD$
+#
+
+acct_COMMENT= Accounting Utilties
+acct_DESC= Accounting Utilties
+acpi_COMMENT= ACPI Utilities
+acpi_DESC= ACPI Utilities
+amd_COMMENT= AMD Utilities
+amd_DESC= AMD Utilities
+apm_COMMENT= APM Utilities
+apm_DESC= APM Utilities
+at_COMMENT= AT Utilities
+at_DESC= AT Utilities
+autofs_COMMENT= Autofs Utilities
+autofs_DESC= Autofs Utilities
+bhyve_COMMENT= Bhyve Utilities
+bhyve_DESC= Bhyve Utilities
+binutils_COMMENT= Binutils
+binutils_DESC= Binutils
+bsdinstall_COMMENT= BSDInstall Utilities
+bsdinstall_DESC= BSDInstall Utilities
+bsnmp_COMMENT= BSNMP Utilities
+bsnmp_DESC= BSNMP Utilities
+clang_COMMENT= Clang Utilities
+clang_DESC= Clang Utilities
+clibs_COMMENT= Core C Libraries
+clibs_DESC= Core C Libraries
+dma_COMMENT= DMA Mail Agent Utilities
+dma_DESC= DMA Mail Agent Utilities
+docs_COMMENT= Documentation
+docs_DESC= Documentation
+ee_COMMENT= Easy Editor Utilities
+ee_DESC= Easy Editor Utilities
+gdb_COMMENT= GDB Utilities
+gdb_DESC= GDB Utilities
+groff_COMMENT= Groff Utilities
+groff_DESC= Groff Utilities
+hast_COMMENT= Highly Available Storage daemon
+hast_DESC= Highly Available Storage daemon
+jail_COMMENT= Jail Utilities
+jail_DESC= Jail Utilities
+kernel_COMMENT= FreeBSD Kernel
+kernel_DESC= FreeBSD Kernel
+manuals_COMMENT= Manual Pages
+manuals_DESC= Manual Pages
+rcmds_COMMENT= Remote Command Utilities
+rcmds_DESC= Remote Command Utilities
+rescue_COMMENT= Rescue Utilities
+rescue_DESC= Rescue Utilities
+runtime_COMMENT= FreeBSD Base System
+runtime_DESC= FreeBSD Base System
+runtime-debug_DESCR= Debugging Symbols
+runtime-development_DESCR=Development Files
+runtime-profile_DESCR= Profiling Libraries
+runtime-lib32_DESCR= 32-bit Libraries
+runtime-lib32-debug_DESCR=32-bit Debugging Symbols
+runtime-lib32-development_DESCR=32-bit Development Files
+runtime-lib32-profile_DESCR=32-bit Profiling Libraries
+sendmail_COMMENT= Sendmail Utilities
+sendmail_DESC= Sendmail Utilities
+ssh_COMMENT= Secure Shell Utilities
+ssh_DESC= Secure Shell Utilities
+svn_COMMENT= Subversion Version Control System
+svn_DESC= Subversion Version Control System
+syscons_COMMENT= Syscons Console
+syscons_DESC= Syscons Console
+tests_COMMENT= Test Suite
+tests_DESC= Test Suite
+unbound_COMMENT= Unbound DNS Resolver
+unbound_DESC= Unbound DNS Resolver
+vi_COMMENT= Vi Editor
+vi_DESC= Vi Editor
diff --git a/release/packages/acct.ucl b/release/packages/acct.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/acct.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/acpi.ucl b/release/packages/acpi.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/acpi.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/amd.ucl b/release/packages/amd.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/amd.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/apm.ucl b/release/packages/apm.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/apm.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/at.ucl b/release/packages/at.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/at.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/autofs.ucl b/release/packages/autofs.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/autofs.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/bhyve.ucl b/release/packages/bhyve.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/bhyve.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/binutils.ucl b/release/packages/binutils.ucl
new file mode 100644
index 000000000000..281d2a593492
--- /dev/null
+++ b/release/packages/binutils.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ GPLv2 ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/bsdinstall.ucl b/release/packages/bsdinstall.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/bsdinstall.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/bsnmp.ucl b/release/packages/bsnmp.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/bsnmp.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/clang.ucl b/release/packages/clang.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/clang.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/clibs.ucl b/release/packages/clibs.ucl
new file mode 100644
index 000000000000..38844f0f0898
--- /dev/null
+++ b/release/packages/clibs.ucl
@@ -0,0 +1,17 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
diff --git a/release/packages/dma.ucl b/release/packages/dma.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/dma.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/docs.ucl b/release/packages/docs.ucl
new file mode 100644
index 000000000000..38844f0f0898
--- /dev/null
+++ b/release/packages/docs.ucl
@@ -0,0 +1,17 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
diff --git a/release/packages/ee.ucl b/release/packages/ee.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/ee.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/gdb.ucl b/release/packages/gdb.ucl
new file mode 100644
index 000000000000..281d2a593492
--- /dev/null
+++ b/release/packages/gdb.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ GPLv2 ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/generate-ucl.sh b/release/packages/generate-ucl.sh
new file mode 100755
index 000000000000..9a963f00125b
--- /dev/null
+++ b/release/packages/generate-ucl.sh
@@ -0,0 +1,141 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+main() {
+ desc=
+ comment=
+ debug=
+ uclsource=
+ while getopts "do:s:u:" arg; do
+ case ${arg} in
+ d)
+ debug=1
+ ;;
+ o)
+ outname="${OPTARG}"
+ origname="${OPTARG}"
+ ;;
+ s)
+ srctree="${OPTARG}"
+ ;;
+ u)
+ uclfile="${OPTARG}"
+ ;;
+ *)
+ echo "Unknown argument"
+ ;;
+ esac
+ done
+
+ shift $(( ${OPTIND} - 1 ))
+
+ outname="$(echo ${outname} | tr '-' '_')"
+
+ case "${outname}" in
+ runtime)
+ outname="runtime"
+ uclfile="${uclfile}"
+ ;;
+ runtime_manuals)
+ outname="${origname}"
+ pkgdeps="runtime"
+ ;;
+ runtime_*)
+ outname="${origname}"
+ uclfile="${outname##*}${uclfile}"
+ pkgdeps="runtime"
+ _descr="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_DESCR)"
+ ;;
+ *_lib32_development)
+ outname="${outname%%_lib32_development}"
+ _descr="32-bit Libraries, Development Files"
+ pkgdeps="${outname}"
+ ;;
+ *_lib32_debug)
+ outname="${outname%%_lib32_debug}"
+ _descr="32-bit Libraries, Debugging Symbols"
+ pkgdeps="${outname}"
+ ;;
+ *_lib32_profile)
+ outname="${outname%%_lib32_profile}"
+ _descr="32-bit Libraries, Profiling"
+ pkgdeps="${outname}"
+ ;;
+ *_lib32)
+ outname="${outname%%_lib32}"
+ _descr="32-bit Libraries"
+ pkgdeps="${outname}"
+ ;;
+ *_development)
+ outname="${outname%%_development}"
+ _descr="Development Files"
+ pkgdeps="${outname}"
+ ;;
+ *_profile)
+ outname="${outname%%_profile}"
+ _descr="Profiling Libraries"
+ pkgdeps="${outname}"
+ ;;
+ *_debug)
+ outname="${outname%%_debug}"
+ _descr="Debugging Symbols"
+ pkgdeps="${outname}"
+ ;;
+ ${origname})
+ pkgdeps="runtime"
+ ;;
+ *)
+ uclfile="${outname##*}${origname}"
+ outname="${outname##*}${origname}"
+ ;;
+ esac
+
+ outname="${outname%%_*}"
+
+ desc="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_DESC)"
+ comment="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_COMMENT)"
+
+ uclsource="${srctree}/release/packages/${outname}.ucl"
+ if [ ! -e "${uclsource}" ]; then
+ uclsource="${srctree}/release/packages/template.ucl"
+ fi
+
+ if [ ! -z "${debug}" ]; then
+ echo ""
+ echo "==============================================================="
+ echo "DEBUG:"
+ echo "_descr=${_descr}"
+ echo "outname=${outname}"
+ echo "origname=${origname}"
+ echo "srctree=${srctree}"
+ echo "uclfile=${uclfile}"
+ echo "desc=${desc}"
+ echo "comment=${comment}"
+ echo "cp ${uclsource} -> ${uclfile}"
+ echo "==============================================================="
+ echo ""
+ echo ""
+ echo ""
+ fi
+
+ [ -z "${comment}" ] && comment="${outname} package"
+ [ ! -z "${_descr}" ] && comment="${comment} (${_descr})"
+ [ -z "${desc}" ] && desc="${outname} package"
+
+ cp "${uclsource}" "${uclfile}"
+ cap_arg="$(make -C ${srctree}/etc -VCAP_MKDB_ENDIAN)"
+ pwd_arg="$(make -C ${srctree}/etc -VPWD_MKDB_ENDIAN)"
+ sed -i '' -e "s/%VERSION%/${PKG_VERSION}/" \
+ -e "s/%PKGNAME%/${origname}/" \
+ -e "s/%COMMENT%/${comment}/" \
+ -e "s/%DESC%/${desc}/" \
+ -e "s/%CAP_MKDB_ENDIAN%/${cap_arg}/g" \
+ -e "s/%PWD_MKDB_ENDIAN%/${pwd_arg}/g" \
+ -e "s/%PKGDEPS%/${pkgdeps}/" \
+ ${uclfile}
+ return 0
+}
+
+main "${@}"
diff --git a/release/packages/groff.ucl b/release/packages/groff.ucl
new file mode 100644
index 000000000000..281d2a593492
--- /dev/null
+++ b/release/packages/groff.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ GPLv2 ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/jail.ucl b/release/packages/jail.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/jail.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/kernel.ucl b/release/packages/kernel.ucl
new file mode 100644
index 000000000000..c89cea6d3f59
--- /dev/null
+++ b/release/packages/kernel.ucl
@@ -0,0 +1,22 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+scripts: {
+ post-install = <<EOD
+ /usr/sbin/kldxref ${PKG_ROOTDIR}/boot/kernel
+EOD
+}
diff --git a/release/packages/rcmds.ucl b/release/packages/rcmds.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/rcmds.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/runtime-debug.ucl b/release/packages/runtime-debug.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/runtime-debug.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/runtime-development.ucl b/release/packages/runtime-development.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/runtime-development.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/runtime-lib32.ucl b/release/packages/runtime-lib32.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/runtime-lib32.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/runtime-manuals.ucl b/release/packages/runtime-manuals.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/runtime-manuals.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/runtime-profile.ucl b/release/packages/runtime-profile.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/runtime-profile.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/runtime.ucl b/release/packages/runtime.ucl
new file mode 100644
index 000000000000..be45369f1450
--- /dev/null
+++ b/release/packages/runtime.ucl
@@ -0,0 +1,29 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+scripts: {
+ post-install = <<EOD
+ cap_mkdb %CAP_MKDB_ENDIAN% ${PKG_ROOTDIR}/etc/login.conf
+ pwd_mkdb %PWD_MKDB_ENDIAN% -i -p -d ${PKG_ROOTDIR}/etc ${PKG_ROOTDIR}/etc/master.passwd
+EOD
+}
+deps: {
+ "FreeBSD-clibs": {
+ origin: "base"
+ version: "%VERSION%"
+ }
+}
diff --git a/release/packages/ssh.ucl b/release/packages/ssh.ucl
new file mode 100644
index 000000000000..aa934645d245
--- /dev/null
+++ b/release/packages/ssh.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ ISCL ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/svn.ucl b/release/packages/svn.ucl
new file mode 100644
index 000000000000..4fd345e57138
--- /dev/null
+++ b/release/packages/svn.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ APACHE20 ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/syscons.ucl b/release/packages/syscons.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/syscons.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/template.ucl b/release/packages/template.ucl
new file mode 100644
index 000000000000..38844f0f0898
--- /dev/null
+++ b/release/packages/template.ucl
@@ -0,0 +1,17 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
diff --git a/release/packages/tests.ucl b/release/packages/tests.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/tests.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/unbound.ucl b/release/packages/unbound.ucl
new file mode 100644
index 000000000000..9b953750ba25
--- /dev/null
+++ b/release/packages/unbound.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD4CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/packages/vi.ucl b/release/packages/vi.ucl
new file mode 100644
index 000000000000..753c26bc5021
--- /dev/null
+++ b/release/packages/vi.ucl
@@ -0,0 +1,24 @@
+#
+# $FreeBSD$
+#
+
+name = "FreeBSD-%PKGNAME%"
+origin = "base"
+version = "%VERSION%"
+comment = "%COMMENT%"
+categories = [ base ]
+maintainer = "re@FreeBSD.org"
+www = "https://www.FreeBSD.org"
+prefix = "/"
+licenselogic = "single"
+licenses = [ BSD2CLAUSE ]
+desc = <<EOD
+%DESC%
+EOD
+deps: {
+ FreeBSD-%PKGDEPS%: {
+ origin: "base",
+ version: "%VERSION%"
+ }
+}
+
diff --git a/release/scripts/make-pkg-package.sh b/release/scripts/make-pkg-package.sh
new file mode 100755
index 000000000000..ab9418bab803
--- /dev/null
+++ b/release/scripts/make-pkg-package.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+# Simulate the build environment.
+eval $(make -C ${SRCDIR} TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} buildenvvars)
+export WRKDIRPREFIX=/tmp/ports.${TARGET}
+export WSTAGEDIR=${WSTAGEDIR}
+export REPODIR=${REPODIR}
+export PKG_VERSION=${PKG_VERSION}
+export WRKDIR=$(make -C ${PORTSDIR}/ports-mgmt/pkg -V WRKDIR)
+
+make -C ${PORTSDIR}/ports-mgmt/pkg TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
+ CONFIGURE_ARGS="--host=$(uname -m)-portbld-freebsd${REVISION}" \
+ stage create-manifest
+
+pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh \
+ create -v -m ${WRKDIR}/.metadir/ \
+ -r ${WRKDIR}/stage \
+ -p ${WRKDIR}/.PLIST.mktmp \
+ -o ${REPODIR}/$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION}
+mkdir -p ${REPODIR}/$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION}/Latest/
+cd ${REPODIR}/$(pkg -o ABI_FILE=${WSTAGEDIR}/bin/sh config ABI)/${PKG_VERSION}/Latest/ && \
+ ln -s ../pkg-*.txz
diff --git a/release/scripts/mtree-to-plist.awk b/release/scripts/mtree-to-plist.awk
new file mode 100644
index 000000000000..d3157ecad0c2
--- /dev/null
+++ b/release/scripts/mtree-to-plist.awk
@@ -0,0 +1,80 @@
+#!/usr/bin/awk
+/^[^#]/ {
+ gsub(/^\./,"", $1)
+ uname = gname = mode = flags = tags = type = ""
+ for (i=2; i<=NF; i++) {
+ if ($i ~ /^uname=/) {
+ uname=$i
+ gsub(/uname=/, "", uname)
+ } else if ($i ~ /^gname=/) {
+ gname=$i
+ gsub(/gname=/, "", gname)
+ } else if ($i ~ /^mode=/) {
+ mode=$i
+ gsub(/mode=/,"", mode)
+ } else if ($i ~ /^flags=/) {
+ flags=$i
+ gsub(/flags=/, "", flags)
+ } else if ($i ~ /^tags=/) {
+ tags=$i
+ gsub(/tags=/, "", tags)
+ } else if ($i ~ /^type=dir/) {
+ type="dir"
+ }
+ }
+ if (kernel != "") {
+ tags="package=kernel"
+ if (_kernconf != "") {
+ tags=tags""_kernconf
+ }
+ }
+ if (length(tags) == 0)
+ next
+ if (tags ~ /package=/) {
+ ext = pkgname = pkgend = ""
+ split(tags, a, ",");
+ for (i in a) {
+ if (a[i] ~ /^package=/) {
+ pkgname=a[i]
+ gsub(/package=/, "", pkgname)
+ } else if (a[i] == "config") {
+ type="config"
+ } else if (a[i] == "development" || a[i] == "profile" || a[i] == "debug" || a[i] == "docs") {
+ pkgend=a[i]
+ } else {
+ if (ext != "")
+ ext=ext"-"a[i]
+ else
+ ext=a[i]
+ }
+ }
+ if (ext != "") {
+ pkgname=pkgname"-"ext
+ }
+ if (pkgend != "") {
+ if (pkgend == "docs") {
+ pkgname=pkgend
+ } else {
+ pkgname=pkgname"-"pkgend
+ }
+ }
+ } else {
+ print "No packages specified in line: $0"
+ next
+ }
+ if (kernel != "") {
+ output="kernel"
+ if (_kernconf != "") {
+ output=output"."_kernconf
+ }
+ if ($1 ~ /^\/usr\/lib\/debug\/boot/) {
+ output=output"-debug.plist"
+ } else {
+ output=output".plist"
+ }
+ } else {
+ output=pkgname".plist"
+ }
+
+ print "@"type"("uname","gname","mode","flags") " $1 > output
+}
diff --git a/rescue/librescue/Makefile b/rescue/librescue/Makefile
index ad4931e52c66..4ca6db923c88 100644
--- a/rescue/librescue/Makefile
+++ b/rescue/librescue/Makefile
@@ -3,6 +3,7 @@
#
.include <src.opts.mk>
+PACKAGE= rescue
MK_SSP= no
# Certain library entries have hard-coded references to
diff --git a/rescue/rescue/Makefile b/rescue/rescue/Makefile
index de314df36ff4..70d3a3724a08 100644
--- a/rescue/rescue/Makefile
+++ b/rescue/rescue/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=rescue
MAN=
MK_SSP= no
diff --git a/sbin/adjkerntz/Makefile b/sbin/adjkerntz/Makefile
index 27c128916f9b..e30841e3ae2d 100644
--- a/sbin/adjkerntz/Makefile
+++ b/sbin/adjkerntz/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= adjkerntz
MAN= adjkerntz.8
diff --git a/sbin/atm/atmconfig/Makefile b/sbin/atm/atmconfig/Makefile
index a77eb25549e8..75a2ede8d7ff 100644
--- a/sbin/atm/atmconfig/Makefile
+++ b/sbin/atm/atmconfig/Makefile
@@ -7,6 +7,7 @@
.include <src.opts.mk>
+PACKAGE=atm
PROG= atmconfig
SRCS= main.c diag.c natm.c
MAN= atmconfig.8
diff --git a/sbin/badsect/Makefile b/sbin/badsect/Makefile
index 68e29645a512..c344e6c63552 100644
--- a/sbin/badsect/Makefile
+++ b/sbin/badsect/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $FreeBSD$
+PACKAGE=runtime
PROG= badsect
LIBADD= ufs
MAN= badsect.8
diff --git a/sbin/bsdlabel/Makefile b/sbin/bsdlabel/Makefile
index 42f0f1c3861a..d2e34d36e3ea 100644
--- a/sbin/bsdlabel/Makefile
+++ b/sbin/bsdlabel/Makefile
@@ -3,6 +3,7 @@
.PATH: ${.CURDIR}/../../sys/geom
+PACKAGE=runtime
PROG= bsdlabel
SRCS= bsdlabel.c geom_bsd_enc.c
MAN+= bsdlabel.8
diff --git a/sbin/camcontrol/Makefile b/sbin/camcontrol/Makefile
index cbc545236b81..f1101d3d9ea2 100644
--- a/sbin/camcontrol/Makefile
+++ b/sbin/camcontrol/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= camcontrol
SRCS= camcontrol.c util.c
.if !defined(RELEASE_CRUNCH)
diff --git a/sbin/casperd/Makefile b/sbin/casperd/Makefile
new file mode 100644
index 000000000000..698263c1836e
--- /dev/null
+++ b/sbin/casperd/Makefile
@@ -0,0 +1,18 @@
+# $FreeBSD$
+
+PACKAGE=casper
+PROG= casperd
+
+SRCS= casperd.c zygote.c
+
+LIBADD= casper nv pjdlog util
+
+MAN= casperd.8
+
+CFLAGS+=-I${.CURDIR}
+CFLAGS+=-I${.CURDIR}/../../lib/libcapsicum
+CFLAGS+=-I${.CURDIR}/../../lib/libcasper
+CFLAGS+=-I${.CURDIR}/../../lib/libnv
+CFLAGS+=-I${.CURDIR}/../../lib/libpjdlog
+
+.include <bsd.prog.mk>
diff --git a/sbin/ccdconfig/Makefile b/sbin/ccdconfig/Makefile
index 3b64dafb5c83..c01b0c55b178 100644
--- a/sbin/ccdconfig/Makefile
+++ b/sbin/ccdconfig/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=ccdconfig
PROG= ccdconfig
MAN= ccdconfig.8
diff --git a/sbin/clri/Makefile b/sbin/clri/Makefile
index 1ae0cf45e731..114f56382a18 100644
--- a/sbin/clri/Makefile
+++ b/sbin/clri/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $FreeBSD$
+PACKAGE=runtime
PROG= clri
MAN= clri.8
WARNS?= 2
diff --git a/sbin/comcontrol/Makefile b/sbin/comcontrol/Makefile
index d8757565b1a0..9bfc4684dd6a 100644
--- a/sbin/comcontrol/Makefile
+++ b/sbin/comcontrol/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 5.4 (Berkeley) 6/5/91
# $FreeBSD$
+PACKAGE=runtime
PROG= comcontrol
MAN= comcontrol.8
diff --git a/sbin/conscontrol/Makefile b/sbin/conscontrol/Makefile
index 9014d80ad556..0bd82e695c31 100644
--- a/sbin/conscontrol/Makefile
+++ b/sbin/conscontrol/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= conscontrol
MAN= conscontrol.8
WARNS?= 2
diff --git a/sbin/ddb/Makefile b/sbin/ddb/Makefile
index 72abbed337ae..914942e34f67 100644
--- a/sbin/ddb/Makefile
+++ b/sbin/ddb/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= ddb
SRCS= ddb.c ddb_capture.c ddb_script.c
MAN= ddb.8
diff --git a/sbin/devd/Makefile b/sbin/devd/Makefile
index fc0021656beb..4e5fa4710e03 100644
--- a/sbin/devd/Makefile
+++ b/sbin/devd/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG_CXX=devd
SRCS= devd.cc token.l parse.y y.tab.h
MAN= devd.8 devd.conf.5
diff --git a/sbin/devd/tests/Makefile b/sbin/devd/tests/Makefile
index e06928c5571c..bdec4c454a57 100644
--- a/sbin/devd/tests/Makefile
+++ b/sbin/devd/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_C= client_test
TEST_METADATA.client_test= required_programs="devd"
TEST_METADATA.client_test+= required_user="root"
diff --git a/sbin/devfs/Makefile b/sbin/devfs/Makefile
index 29b0f54fbc5f..eee24e02e71e 100644
--- a/sbin/devfs/Makefile
+++ b/sbin/devfs/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= devfs
SRCS= devfs.c rule.c
MAN= devfs.8
diff --git a/sbin/dhclient/Makefile b/sbin/dhclient/Makefile
index 868df6d6ba65..2e9881f191cd 100644
--- a/sbin/dhclient/Makefile
+++ b/sbin/dhclient/Makefile
@@ -33,6 +33,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
SRCS= dhclient.c clparse.c alloc.c dispatch.c hash.c bpf.c options.c \
tree.c conflex.c errwarn.c inet.c packet.c convert.c tables.c \
parse.c privsep.c
diff --git a/sbin/dhclient/tests/Makefile b/sbin/dhclient/tests/Makefile
index fd3df4e17e68..88516d920725 100644
--- a/sbin/dhclient/tests/Makefile
+++ b/sbin/dhclient/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
.PATH: ${.CURDIR}/..
PLAIN_TESTS_C= option-domain-search_test
diff --git a/sbin/dmesg/Makefile b/sbin/dmesg/Makefile
index 64a0155917be..a443225242d8 100644
--- a/sbin/dmesg/Makefile
+++ b/sbin/dmesg/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $FreeBSD$
+PACKAGE=runtime
PROG= dmesg
MAN= dmesg.8
diff --git a/sbin/dump/Makefile b/sbin/dump/Makefile
index e3d9aef61518..7c89570292db 100644
--- a/sbin/dump/Makefile
+++ b/sbin/dump/Makefile
@@ -13,6 +13,7 @@
# DEBUG use local directory to find ddate and dumpdates
# TDEBUG trace out the process forking
+PACKAGE=runtime
PROG= dump
LINKS= ${BINDIR}/dump ${BINDIR}/rdump
CFLAGS+=-DRDUMP
diff --git a/sbin/dumpfs/Makefile b/sbin/dumpfs/Makefile
index 87eb89b1782e..03e1aae03b87 100644
--- a/sbin/dumpfs/Makefile
+++ b/sbin/dumpfs/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $FreeBSD$
+PACKAGE=runtime
PROG= dumpfs
WARNS?= 2
LIBADD= ufs
diff --git a/sbin/dumpon/Makefile b/sbin/dumpon/Makefile
index d11ccc761127..782117c16ff0 100644
--- a/sbin/dumpon/Makefile
+++ b/sbin/dumpon/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= dumpon
MAN= dumpon.8
diff --git a/sbin/etherswitchcfg/Makefile b/sbin/etherswitchcfg/Makefile
index b5cf39ab8da1..547a27296bd9 100644
--- a/sbin/etherswitchcfg/Makefile
+++ b/sbin/etherswitchcfg/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 5.4 (Berkeley) 6/5/91
# $FreeBSD$
+PACKAGE=runtime
PROG= etherswitchcfg
MAN= etherswitchcfg.8
SRCS= etherswitchcfg.c ifmedia.c
diff --git a/sbin/fdisk/Makefile b/sbin/fdisk/Makefile
index a49c69954d0f..fc4bcbabc329 100644
--- a/sbin/fdisk/Makefile
+++ b/sbin/fdisk/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= fdisk
SRCS= fdisk.c geom_mbr_enc.c
WARNS?= 4
diff --git a/sbin/fdisk_pc98/Makefile b/sbin/fdisk_pc98/Makefile
index 9915267e6d7c..7bfa0632612d 100644
--- a/sbin/fdisk_pc98/Makefile
+++ b/sbin/fdisk_pc98/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= fdisk
SRCS= fdisk.c geom_pc98_enc.c
WARNS?= 4
diff --git a/sbin/ffsinfo/Makefile b/sbin/ffsinfo/Makefile
index 7fd033d3475a..cdc9e7b3a765 100644
--- a/sbin/ffsinfo/Makefile
+++ b/sbin/ffsinfo/Makefile
@@ -7,6 +7,7 @@
GROWFS= ${.CURDIR}/../growfs
.PATH: ${GROWFS}
+PACKAGE=runtime
PROG= ffsinfo
SRCS= ffsinfo.c debug.c
MAN= ffsinfo.8
diff --git a/sbin/fsck/Makefile b/sbin/fsck/Makefile
index 22de03c4da78..8d3dd214857e 100644
--- a/sbin/fsck/Makefile
+++ b/sbin/fsck/Makefile
@@ -1,6 +1,7 @@
# $NetBSD: Makefile,v 1.14 1996/09/27 22:38:37 christos Exp $
# $FreeBSD$
+PACKAGE=runtime
PROG= fsck
SRCS= fsck.c fsutil.c preen.c
MAN= fsck.8
diff --git a/sbin/fsck_ffs/Makefile b/sbin/fsck_ffs/Makefile
index 02754697dfa5..b00aee5d162c 100644
--- a/sbin/fsck_ffs/Makefile
+++ b/sbin/fsck_ffs/Makefile
@@ -1,6 +1,7 @@
# $FreeBSD$
# @(#)Makefile 8.2 (Berkeley) 4/27/95
+PACKAGE=runtime
PROG= fsck_ffs
LINKS+= ${BINDIR}/fsck_ffs ${BINDIR}/fsck_ufs
LINKS+= ${BINDIR}/fsck_ffs ${BINDIR}/fsck_4.2bsd
diff --git a/sbin/fsck_msdosfs/Makefile b/sbin/fsck_msdosfs/Makefile
index f9dd9fae401b..0de68f18a01d 100644
--- a/sbin/fsck_msdosfs/Makefile
+++ b/sbin/fsck_msdosfs/Makefile
@@ -4,6 +4,7 @@
FSCK= ${.CURDIR}/../fsck
.PATH: ${FSCK}
+PACKAGE=runtime
PROG= fsck_msdosfs
MAN= fsck_msdosfs.8
SRCS= main.c check.c boot.c fat.c dir.c fsutil.c
diff --git a/sbin/fsdb/Makefile b/sbin/fsdb/Makefile
index e0a9cc3cb382..729f9cde2d35 100644
--- a/sbin/fsdb/Makefile
+++ b/sbin/fsdb/Makefile
@@ -2,6 +2,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $FreeBSD$
+PACKAGE=runtime
PROG= fsdb
MAN= fsdb.8
SRCS= fsdb.c fsdbutil.c \
diff --git a/sbin/fsirand/Makefile b/sbin/fsirand/Makefile
index 2ae820a84783..c415b11983f1 100644
--- a/sbin/fsirand/Makefile
+++ b/sbin/fsirand/Makefile
@@ -1,6 +1,7 @@
# $OpenBSD: Makefile,v 1.1 1997/01/26 02:23:20 millert Exp $
# $FreeBSD$
+PACKAGE=runtime
PROG= fsirand
MAN= fsirand.8
WARNS?= 3
diff --git a/sbin/gbde/Makefile b/sbin/gbde/Makefile
index f80f8cd8f70e..2e5dc81bf010 100644
--- a/sbin/gbde/Makefile
+++ b/sbin/gbde/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= gbde
SRCS= gbde.c template.c
SRCS+= rijndael-alg-fst.c
diff --git a/sbin/geom/Makefile b/sbin/geom/Makefile
index 19a56360ccce..5ef8fb847dd8 100644
--- a/sbin/geom/Makefile
+++ b/sbin/geom/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.if defined(RESCUE) || defined(RELEASE_CRUNCH)
.PATH: ${.CURDIR}/class/part \
diff --git a/sbin/geom/class/cache/Makefile b/sbin/geom/class/cache/Makefile
index 35f81d81b76f..63b740b5e98d 100644
--- a/sbin/geom/class/cache/Makefile
+++ b/sbin/geom/class/cache/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= cache
diff --git a/sbin/geom/class/concat/Makefile b/sbin/geom/class/concat/Makefile
index 34e2c28fdecc..133805605cdb 100644
--- a/sbin/geom/class/concat/Makefile
+++ b/sbin/geom/class/concat/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= concat
diff --git a/sbin/geom/class/eli/Makefile b/sbin/geom/class/eli/Makefile
index 5eff32c50689..74749d2df763 100644
--- a/sbin/geom/class/eli/Makefile
+++ b/sbin/geom/class/eli/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc ${.CURDIR}/../../../../sys/geom/eli ${.CURDIR}/../../../../sys/crypto/sha2
GEOM_CLASS= eli
diff --git a/sbin/geom/class/journal/Makefile b/sbin/geom/class/journal/Makefile
index 0e1a38ea6dc4..14fff151b62a 100644
--- a/sbin/geom/class/journal/Makefile
+++ b/sbin/geom/class/journal/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= journal
diff --git a/sbin/geom/class/label/Makefile b/sbin/geom/class/label/Makefile
index 0b609a1dd3a0..2a51c5bf288d 100644
--- a/sbin/geom/class/label/Makefile
+++ b/sbin/geom/class/label/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= label
diff --git a/sbin/geom/class/mirror/Makefile b/sbin/geom/class/mirror/Makefile
index ce7ee6466326..195c9d580842 100644
--- a/sbin/geom/class/mirror/Makefile
+++ b/sbin/geom/class/mirror/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= mirror
diff --git a/sbin/geom/class/mountver/Makefile b/sbin/geom/class/mountver/Makefile
index 750d1a557e5e..3dba58909d32 100644
--- a/sbin/geom/class/mountver/Makefile
+++ b/sbin/geom/class/mountver/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= mountver
diff --git a/sbin/geom/class/multipath/Makefile b/sbin/geom/class/multipath/Makefile
index ff40fe9faa32..2a6b7cc84ba2 100644
--- a/sbin/geom/class/multipath/Makefile
+++ b/sbin/geom/class/multipath/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= multipath
diff --git a/sbin/geom/class/nop/Makefile b/sbin/geom/class/nop/Makefile
index d9a6ca6f845e..903cfcf04984 100644
--- a/sbin/geom/class/nop/Makefile
+++ b/sbin/geom/class/nop/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= nop
diff --git a/sbin/geom/class/part/Makefile b/sbin/geom/class/part/Makefile
index 4b67de4ef415..b67d11f3cb01 100644
--- a/sbin/geom/class/part/Makefile
+++ b/sbin/geom/class/part/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= part
diff --git a/sbin/geom/class/raid/Makefile b/sbin/geom/class/raid/Makefile
index 07d71403d48f..79c05a21b9f8 100644
--- a/sbin/geom/class/raid/Makefile
+++ b/sbin/geom/class/raid/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= raid
diff --git a/sbin/geom/class/raid3/Makefile b/sbin/geom/class/raid3/Makefile
index 74e12455a432..b8bc5ea9195a 100644
--- a/sbin/geom/class/raid3/Makefile
+++ b/sbin/geom/class/raid3/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= raid3
diff --git a/sbin/geom/class/sched/Makefile b/sbin/geom/class/sched/Makefile
index 6f54d3f36f9f..17e4523a7224 100644
--- a/sbin/geom/class/sched/Makefile
+++ b/sbin/geom/class/sched/Makefile
@@ -1,6 +1,7 @@
# GEOM_LIBRARY_PATH
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= sched
diff --git a/sbin/geom/class/shsec/Makefile b/sbin/geom/class/shsec/Makefile
index 6b5c835551b2..51cee346969a 100644
--- a/sbin/geom/class/shsec/Makefile
+++ b/sbin/geom/class/shsec/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= shsec
diff --git a/sbin/geom/class/stripe/Makefile b/sbin/geom/class/stripe/Makefile
index 8ee5f6e2f871..c0fdef1ca8b6 100644
--- a/sbin/geom/class/stripe/Makefile
+++ b/sbin/geom/class/stripe/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc
GEOM_CLASS= stripe
diff --git a/sbin/geom/class/virstor/Makefile b/sbin/geom/class/virstor/Makefile
index 0924f0d2fd21..0fe24e67a548 100644
--- a/sbin/geom/class/virstor/Makefile
+++ b/sbin/geom/class/virstor/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
.PATH: ${.CURDIR}/../../misc ${.CURDIR}/../../../../sys/geom/virstor
GEOM_CLASS= virstor
diff --git a/sbin/geom/core/Makefile b/sbin/geom/core/Makefile
index 0636d037a358..8b69b72e9ee1 100644
--- a/sbin/geom/core/Makefile
+++ b/sbin/geom/core/Makefile
@@ -2,6 +2,7 @@
.PATH: ${.CURDIR}/../misc
+PACKAGE=runtime
PROG= geom
MAN= geom.8
SRCS= geom.c subr.c
diff --git a/sbin/growfs/Makefile b/sbin/growfs/Makefile
index e7017a71f938..a75c644a4f98 100644
--- a/sbin/growfs/Makefile
+++ b/sbin/growfs/Makefile
@@ -8,6 +8,7 @@
.PATH: ${.CURDIR}/../mount
+PACKAGE=runtime
PROG= growfs
SRCS= growfs.c getmntopts.c
MAN= growfs.8
diff --git a/sbin/growfs/tests/Makefile b/sbin/growfs/tests/Makefile
index 6a3208d9c441..5fdceb755cef 100644
--- a/sbin/growfs/tests/Makefile
+++ b/sbin/growfs/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_PERL= legacy_test
.include <bsd.test.mk>
diff --git a/sbin/gvinum/Makefile b/sbin/gvinum/Makefile
index 0e56920d9cee..5bb40eacf72e 100644
--- a/sbin/gvinum/Makefile
+++ b/sbin/gvinum/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= gvinum
SRCS= gvinum.c gvinum.h geom_vinum_share.c
MAN= gvinum.8
diff --git a/sbin/hastctl/Makefile b/sbin/hastctl/Makefile
index 41d443d32783..a24b55e87f52 100644
--- a/sbin/hastctl/Makefile
+++ b/sbin/hastctl/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=hast
.PATH: ${.CURDIR}/../hastd
PROG= hastctl
diff --git a/sbin/hastd/Makefile b/sbin/hastd/Makefile
index e3fed8d0b522..7ffebf9a4fa6 100644
--- a/sbin/hastd/Makefile
+++ b/sbin/hastd/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=hast
PROG= hastd
SRCS= activemap.c
SRCS+= control.c crc32.c
diff --git a/sbin/ifconfig/Makefile b/sbin/ifconfig/Makefile
index b5616a4626a5..a3623d507b77 100644
--- a/sbin/ifconfig/Makefile
+++ b/sbin/ifconfig/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= ifconfig
SRCS= ifconfig.c # base support
diff --git a/sbin/ifconfig/tests/Makefile b/sbin/ifconfig/tests/Makefile
index 93967c705175..8a551917d709 100644
--- a/sbin/ifconfig/tests/Makefile
+++ b/sbin/ifconfig/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_SH= nonexistent_test
.include <netbsd-tests.test.mk>
diff --git a/sbin/init/Makefile b/sbin/init/Makefile
index 29ad63ddc65f..cf6de6c12abe 100644
--- a/sbin/init/Makefile
+++ b/sbin/init/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 7/19/93
# $FreeBSD$
+PACKAGE=runtime
PROG= init
SRCS= init.c getmntopts.c
MAN= init.8
diff --git a/sbin/ipf/ipf/Makefile b/sbin/ipf/ipf/Makefile
index 2ff340f68c0a..1f825783b37f 100644
--- a/sbin/ipf/ipf/Makefile
+++ b/sbin/ipf/ipf/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= ipf
PROG= ipf
SRCS= ${GENHDRS} ipf.c ipfcomp.c ipf_y.c ipf_l.c bpf_filter.c
MAN= ipfilter.4 ipfilter.5 ipf.8 ipf.4 ipf.5 ipl.4
diff --git a/sbin/ipf/ipfs/Makefile b/sbin/ipf/ipfs/Makefile
index a64f805b2ab3..6f76f9db5d76 100644
--- a/sbin/ipf/ipfs/Makefile
+++ b/sbin/ipf/ipfs/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=ipf
PROG= ipfs
MAN= ipfs.8
diff --git a/sbin/ipf/ipfstat/Makefile b/sbin/ipf/ipfstat/Makefile
index 14823cf5110c..4714f2c0394e 100644
--- a/sbin/ipf/ipfstat/Makefile
+++ b/sbin/ipf/ipfstat/Makefile
@@ -2,6 +2,7 @@
NOGCCERROR= # defined
+PACKAGE= ipf
PROG= ipfstat
SRCS= ipfstat.c
MAN= ipfstat.8
diff --git a/sbin/ipf/ipftest/Makefile b/sbin/ipf/ipftest/Makefile
index a74599f3cd15..63cafabd109a 100644
--- a/sbin/ipf/ipftest/Makefile
+++ b/sbin/ipf/ipftest/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= ipf
PROG= ipftest
SRCS= ${GENHDRS} ipftest.c fil.c ip_frag.c ip_state.c ip_nat.c \
ip_nat6.c \
diff --git a/sbin/ipf/ipmon/Makefile b/sbin/ipf/ipmon/Makefile
index 031f929067b4..5d76a05ae44a 100644
--- a/sbin/ipf/ipmon/Makefile
+++ b/sbin/ipf/ipmon/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= ipf
PROG= ipmon
SRCS= ${GENHDRS} ipmon.c ipmon_y.c ipmon_l.c
MAN= ipmon.8
diff --git a/sbin/ipf/ipnat/Makefile b/sbin/ipf/ipnat/Makefile
index 74be486ec557..ba9c50ee70e3 100644
--- a/sbin/ipf/ipnat/Makefile
+++ b/sbin/ipf/ipnat/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= ipf
PROG= ipnat
SRCS= ${GENHDRS} ipnat.c ipnat_y.c ipnat_l.c
MAN= ipnat.8 ipnat.4 ipnat.5
diff --git a/sbin/ipf/ippool/Makefile b/sbin/ipf/ippool/Makefile
index eedebef90ba3..ab350f223f53 100644
--- a/sbin/ipf/ippool/Makefile
+++ b/sbin/ipf/ippool/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= ipf
PROG= ippool
SRCS= ${GENHDRS} ippool_y.c ippool_l.c kmem.c ippool.c
MAN= ippool.5 ippool.8
diff --git a/sbin/ipf/ipresend/Makefile b/sbin/ipf/ipresend/Makefile
index 5e0ac15cbb1f..da1879b83175 100644
--- a/sbin/ipf/ipresend/Makefile
+++ b/sbin/ipf/ipresend/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= ipf
PROG= ipresend
SRCS= ipresend.c ip.c resend.c sbpf.c sock.c 44arp.c
MAN= ipresend.1
diff --git a/sbin/ipf/libipf/Makefile b/sbin/ipf/libipf/Makefile
index 7a7a011d043c..a8f43e24fb74 100644
--- a/sbin/ipf/libipf/Makefile
+++ b/sbin/ipf/libipf/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= ipf
LIB= ipf
INTERNALLIB=
diff --git a/sbin/ipfw/Makefile b/sbin/ipfw/Makefile
index efd99fcdf316..668f22a67a8e 100644
--- a/sbin/ipfw/Makefile
+++ b/sbin/ipfw/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=ipfw
PROG= ipfw
SRCS= ipfw2.c dummynet.c ipv6.c main.c nat.c tables.c
WARNS?= 2
diff --git a/sbin/iscontrol/Makefile b/sbin/iscontrol/Makefile
index 9c4d9f4fff58..6b0fe3a4bfd6 100644
--- a/sbin/iscontrol/Makefile
+++ b/sbin/iscontrol/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=iscsi_legacy
SRCS= iscontrol.c pdu.c fsm.c config.c login.c auth_subr.c misc.c
PROG= iscontrol
LIBADD= cam md
diff --git a/sbin/kldconfig/Makefile b/sbin/kldconfig/Makefile
index a478c4b619d0..3efb34f8a252 100644
--- a/sbin/kldconfig/Makefile
+++ b/sbin/kldconfig/Makefile
@@ -26,6 +26,7 @@
# $FreeBSD$
#
+PACKAGE=runtime
PROG= kldconfig
MAN= kldconfig.8
diff --git a/sbin/kldload/Makefile b/sbin/kldload/Makefile
index 05ad5bab82c0..13c0f0ec5abf 100644
--- a/sbin/kldload/Makefile
+++ b/sbin/kldload/Makefile
@@ -26,6 +26,7 @@
# $FreeBSD$
#
+PACKAGE=runtime
PROG= kldload
MAN= kldload.8
diff --git a/sbin/kldstat/Makefile b/sbin/kldstat/Makefile
index 4bf022eb94d4..2d0c4437dc05 100644
--- a/sbin/kldstat/Makefile
+++ b/sbin/kldstat/Makefile
@@ -26,6 +26,7 @@
# $FreeBSD$
#
+PACKAGE=runtime
PROG= kldstat
MAN= kldstat.8
diff --git a/sbin/kldunload/Makefile b/sbin/kldunload/Makefile
index 1a25a02351be..5688f790941e 100644
--- a/sbin/kldunload/Makefile
+++ b/sbin/kldunload/Makefile
@@ -26,6 +26,7 @@
# $FreeBSD$
#
+PACKAGE=runtime
PROG= kldunload
MAN= kldunload.8
diff --git a/sbin/ldconfig/Makefile b/sbin/ldconfig/Makefile
index 15c3808520ba..6589dbc9c6ec 100644
--- a/sbin/ldconfig/Makefile
+++ b/sbin/ldconfig/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= ldconfig
SRCS= elfhints.c ldconfig.c shlib.c support.c
LDDIR?= ${.CURDIR}/../../libexec/rtld-aout
diff --git a/sbin/md5/Makefile b/sbin/md5/Makefile
index 5f927c43a9fe..6b651725f7c9 100644
--- a/sbin/md5/Makefile
+++ b/sbin/md5/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/9/93
# $FreeBSD$
+PACKAGE=runtime
PROG= md5
LINKS= ${BINDIR}/md5 ${BINDIR}/rmd160 \
diff --git a/sbin/mdconfig/Makefile b/sbin/mdconfig/Makefile
index 6be9129144e7..21db48a5ef1e 100644
--- a/sbin/mdconfig/Makefile
+++ b/sbin/mdconfig/Makefile
@@ -2,6 +2,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= mdconfig
MAN= mdconfig.8
diff --git a/sbin/mdconfig/tests/Makefile b/sbin/mdconfig/tests/Makefile
index 6c179fcf59ad..58507d39799b 100644
--- a/sbin/mdconfig/tests/Makefile
+++ b/sbin/mdconfig/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
ATF_TESTS_SH= mdconfig_test
TEST_METADATA.mdconfig_test+= required_user="root"
diff --git a/sbin/mdmfs/Makefile b/sbin/mdmfs/Makefile
index 999793f0e103..e8d2d7b46f3f 100644
--- a/sbin/mdmfs/Makefile
+++ b/sbin/mdmfs/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= mdmfs
LINKS= ${BINDIR}/${PROG} ${BINDIR}/mount_mfs
MAN= mdmfs.8
diff --git a/sbin/mknod/Makefile b/sbin/mknod/Makefile
index 63235b2ce6e4..610d2a4f399a 100644
--- a/sbin/mknod/Makefile
+++ b/sbin/mknod/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $FreeBSD$
+PACKAGE=runtime
PROG= mknod
MAN= mknod.8
diff --git a/sbin/mksnap_ffs/Makefile b/sbin/mksnap_ffs/Makefile
index de96fa03e0f5..33040ecaf3db 100644
--- a/sbin/mksnap_ffs/Makefile
+++ b/sbin/mksnap_ffs/Makefile
@@ -2,6 +2,7 @@
.PATH: ${.CURDIR}/../mount
+PACKAGE=runtime
PROG= mksnap_ffs
SRCS= mksnap_ffs.c getmntopts.c
MAN= mksnap_ffs.8
diff --git a/sbin/mount/Makefile b/sbin/mount/Makefile
index f95085a6cae7..80d40234e792 100644
--- a/sbin/mount/Makefile
+++ b/sbin/mount/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.6 (Berkeley) 5/8/95
# $FreeBSD$
+PACKAGE=runtime
PROG= mount
SRCS= mount.c mount_fs.c getmntopts.c vfslist.c
MAN= mount.8 mount.conf.8
diff --git a/sbin/mount_cd9660/Makefile b/sbin/mount_cd9660/Makefile
index c70892c3309e..83d58a2ab5f1 100644
--- a/sbin/mount_cd9660/Makefile
+++ b/sbin/mount_cd9660/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.3 (Berkeley) 3/27/94
# $FreeBSD$
+PACKAGE=runtime
PROG= mount_cd9660
SRCS= mount_cd9660.c getmntopts.c
MAN= mount_cd9660.8
diff --git a/sbin/mount_fusefs/Makefile b/sbin/mount_fusefs/Makefile
index 9c84fa685192..21975800481f 100644
--- a/sbin/mount_fusefs/Makefile
+++ b/sbin/mount_fusefs/Makefile
@@ -20,6 +20,7 @@ DEBUG_FLAGS+= -D_DEBUG_MSG
DEBUG_FLAGS+= -DFUSE4BSD_VERSION="\"${F4BVERS}\""
.endif
+PACKAGE=runtime
PROG= mount_fusefs
SRCS= mount_fusefs.c getmntopts.c
MAN8= mount_fusefs.8
diff --git a/sbin/mount_msdosfs/Makefile b/sbin/mount_msdosfs/Makefile
index ede86b4d8674..abbad5e186f0 100644
--- a/sbin/mount_msdosfs/Makefile
+++ b/sbin/mount_msdosfs/Makefile
@@ -2,6 +2,7 @@
# $FreeBSD$
#
+PACKAGE=runtime
PROG= mount_msdosfs
SRCS= mount_msdosfs.c getmntopts.c
MAN= mount_msdosfs.8
diff --git a/sbin/mount_nfs/Makefile b/sbin/mount_nfs/Makefile
index 75f781798ab7..76c2bfb55ce5 100644
--- a/sbin/mount_nfs/Makefile
+++ b/sbin/mount_nfs/Makefile
@@ -2,6 +2,7 @@
#
# $FreeBSD$
+PACKAGE=runtime
PROG= mount_nfs
SRCS= mount_nfs.c getmntopts.c mounttab.c
MAN= mount_nfs.8
diff --git a/sbin/mount_nullfs/Makefile b/sbin/mount_nullfs/Makefile
index 0b2ecc5834c0..c9b52796a1a8 100644
--- a/sbin/mount_nullfs/Makefile
+++ b/sbin/mount_nullfs/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.3 (Berkeley) 3/27/94
# $FreeBSD$
+PACKAGE=runtime
PROG= mount_nullfs
SRCS= mount_nullfs.c getmntopts.c
MAN= mount_nullfs.8
diff --git a/sbin/mount_udf/Makefile b/sbin/mount_udf/Makefile
index 12d5d5822424..f0f50ab4b1b7 100644
--- a/sbin/mount_udf/Makefile
+++ b/sbin/mount_udf/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= mount_udf
SRCS= mount_udf.c getmntopts.c
MAN= mount_udf.8
diff --git a/sbin/mount_unionfs/Makefile b/sbin/mount_unionfs/Makefile
index 276fc7467d13..cca1ea06222f 100644
--- a/sbin/mount_unionfs/Makefile
+++ b/sbin/mount_unionfs/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.3 (Berkeley) 3/27/94
# $FreeBSD$
+PACKAGE=runtime
PROG= mount_unionfs
SRCS= mount_unionfs.c getmntopts.c
MAN= mount_unionfs.8
diff --git a/sbin/nandfs/Makefile b/sbin/nandfs/Makefile
index 5757f8c16886..40af5775c510 100644
--- a/sbin/nandfs/Makefile
+++ b/sbin/nandfs/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=nandfs
PROG= nandfs
SRCS= nandfs.c lssnap.c mksnap.c rmsnap.c
MAN= nandfs.8
diff --git a/sbin/natd/Makefile b/sbin/natd/Makefile
index 44e5b6f3b0f6..aef193b3f1d0 100644
--- a/sbin/natd/Makefile
+++ b/sbin/natd/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE= natd
PROG = natd
SRCS = natd.c icmp.c
WARNS?= 3
diff --git a/sbin/newfs_msdos/Makefile b/sbin/newfs_msdos/Makefile
index ec5e84878aec..3a2c49fed0db 100644
--- a/sbin/newfs_msdos/Makefile
+++ b/sbin/newfs_msdos/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= newfs_msdos
MAN= newfs_msdos.8
SRCS= newfs_msdos.c mkfs_msdos.c
diff --git a/sbin/newfs_nandfs/Makefile b/sbin/newfs_nandfs/Makefile
index 7a39fbb088e6..9b1b3009c400 100644
--- a/sbin/newfs_nandfs/Makefile
+++ b/sbin/newfs_nandfs/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=nandfs
PROG= newfs_nandfs
MAN= newfs_nandfs.8
diff --git a/sbin/nfsiod/Makefile b/sbin/nfsiod/Makefile
index 47cd290ec78e..ea66a6dfb1e5 100644
--- a/sbin/nfsiod/Makefile
+++ b/sbin/nfsiod/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $FreeBSD$
+PACKAGE=runtime
PROG= nfsiod
MAN= nfsiod.8
diff --git a/sbin/nos-tun/Makefile b/sbin/nos-tun/Makefile
index 9f1024f41e8e..480141ec6b6f 100644
--- a/sbin/nos-tun/Makefile
+++ b/sbin/nos-tun/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= nos-tun
MAN= nos-tun.8
WARNS?= 3
diff --git a/sbin/nvmecontrol/Makefile b/sbin/nvmecontrol/Makefile
index e8a23719a2a7..42dd5916fc59 100644
--- a/sbin/nvmecontrol/Makefile
+++ b/sbin/nvmecontrol/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= nvmecontrol
SRCS= nvmecontrol.c devlist.c firmware.c identify.c logpage.c \
perftest.c reset.c nvme_util.c power.c
diff --git a/sbin/pfctl/Makefile b/sbin/pfctl/Makefile
index de3b7ec5012c..91ebf5567d61 100644
--- a/sbin/pfctl/Makefile
+++ b/sbin/pfctl/Makefile
@@ -5,6 +5,7 @@
# pf_ruleset.c is shared between kernel and pfctl
.PATH: ${.CURDIR}/../../sys/netpfil/pf
+PACKAGE=pf
PROG= pfctl
MAN= pfctl.8
diff --git a/sbin/pflogd/Makefile b/sbin/pflogd/Makefile
index 49a311e11bb7..bb74500dcf53 100644
--- a/sbin/pflogd/Makefile
+++ b/sbin/pflogd/Makefile
@@ -2,6 +2,7 @@
.PATH: ${.CURDIR}/../../contrib/pf/pflogd
+PACKAGE=pf
PROG= pflogd
SRCS= pflogd.c pidfile.c privsep.c privsep_fdpass.c
MAN= pflogd.8
diff --git a/sbin/ping/Makefile b/sbin/ping/Makefile
index 31e6153871bd..21a4dccc01d9 100644
--- a/sbin/ping/Makefile
+++ b/sbin/ping/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= ping
MAN= ping.8
BINOWN= root
diff --git a/sbin/ping6/Makefile b/sbin/ping6/Makefile
index 707bff4cc657..78874f5d2391 100644
--- a/sbin/ping6/Makefile
+++ b/sbin/ping6/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= ping6
MAN= ping6.8
diff --git a/sbin/quotacheck/Makefile b/sbin/quotacheck/Makefile
index 7be3e3510503..601c19e98a7d 100644
--- a/sbin/quotacheck/Makefile
+++ b/sbin/quotacheck/Makefile
@@ -1,6 +1,7 @@
# $FreeBSD$
# @(#)Makefile 8.1 (Berkeley) 6/5/93
+PACKAGE=quotacheck
PROG= quotacheck
SRCS= quotacheck.c preen.c fsutil.c utilities.c
WARNS?= 2
diff --git a/sbin/rcorder/Makefile b/sbin/rcorder/Makefile
index 2f1bbac1fa8f..71bc82c60b33 100644
--- a/sbin/rcorder/Makefile
+++ b/sbin/rcorder/Makefile
@@ -1,6 +1,7 @@
# $NetBSD: Makefile,v 1.1 1999/11/23 05:28:20 mrg Exp $
# $FreeBSD$
+PACKAGE=runtime
PROG= rcorder
SRCS= ealloc.c hash.c rcorder.c
MAN= rcorder.8
diff --git a/sbin/reboot/Makefile b/sbin/reboot/Makefile
index aa41e30438a6..87c47307d59c 100644
--- a/sbin/reboot/Makefile
+++ b/sbin/reboot/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $FreeBSD$
+PACKAGE=runtime
PROG= reboot
MAN= reboot.8 nextboot.8
MLINKS= reboot.8 halt.8 reboot.8 fastboot.8 reboot.8 fasthalt.8
diff --git a/sbin/recoverdisk/Makefile b/sbin/recoverdisk/Makefile
index 136e570eb5a3..41ef1f3e4912 100644
--- a/sbin/recoverdisk/Makefile
+++ b/sbin/recoverdisk/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= recoverdisk
.include <bsd.prog.mk>
diff --git a/sbin/resolvconf/Makefile b/sbin/resolvconf/Makefile
index 2d4701eade42..783d8b67fb3e 100644
--- a/sbin/resolvconf/Makefile
+++ b/sbin/resolvconf/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
DIST= ${.CURDIR}/../../contrib/openresolv
.PATH: ${DIST}
diff --git a/sbin/restore/Makefile b/sbin/restore/Makefile
index c462f51a8dd3..58fed3e89c4f 100644
--- a/sbin/restore/Makefile
+++ b/sbin/restore/Makefile
@@ -3,6 +3,7 @@
.PATH: ${.CURDIR}/../dump
+PACKAGE=runtime
PROG= restore
LINKS= ${BINDIR}/restore ${BINDIR}/rrestore
MAN= restore.8
diff --git a/sbin/route/Makefile b/sbin/route/Makefile
index 25134e473b66..a1db0b6528dd 100644
--- a/sbin/route/Makefile
+++ b/sbin/route/Makefile
@@ -3,6 +3,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= route
MAN= route.8
SRCS= route.c keywords.h
diff --git a/sbin/routed/Makefile b/sbin/routed/Makefile
index 2308722c7191..c01ab4178443 100644
--- a/sbin/routed/Makefile
+++ b/sbin/routed/Makefile
@@ -1,6 +1,7 @@
# Make `routed` for FreeBSD
# $FreeBSD$
+PACKAGE=runtime
PROG= routed
MAN= routed.8
SRCS= if.c input.c main.c output.c parms.c radix.c rdisc.c table.c trace.c
diff --git a/sbin/routed/rtquery/Makefile b/sbin/routed/rtquery/Makefile
index 4df7dc29ace3..a9893a988537 100644
--- a/sbin/routed/rtquery/Makefile
+++ b/sbin/routed/rtquery/Makefile
@@ -2,6 +2,7 @@
# $Revision: 1.6 $
# $FreeBSD$
+PACKAGE=runtime
PROG= rtquery
MAN= rtquery.8
LIBADD= md
diff --git a/sbin/rtsol/Makefile b/sbin/rtsol/Makefile
index 8356ea465c5e..f12107a1e45f 100644
--- a/sbin/rtsol/Makefile
+++ b/sbin/rtsol/Makefile
@@ -16,6 +16,7 @@
.PATH: ${.CURDIR}/../../usr.sbin/rtsold
+PACKAGE=runtime
PROG= rtsol
SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
MAN=
diff --git a/sbin/savecore/Makefile b/sbin/savecore/Makefile
index 5134e4c546a7..f5eeb77ee5e7 100644
--- a/sbin/savecore/Makefile
+++ b/sbin/savecore/Makefile
@@ -1,5 +1,6 @@
# $FreeBSD$
+PACKAGE=runtime
PROG= savecore
LIBADD= z xo
MAN= savecore.8
diff --git a/sbin/sconfig/Makefile b/sbin/sconfig/Makefile
index 9698c04ddbad..bce914f40868 100644
--- a/sbin/sconfig/Makefile
+++ b/sbin/sconfig/Makefile
@@ -1,6 +1,7 @@
# Cronyx Id: sbin.sconfig.Makefile,v 1.1.4.1 2003/02/17 12:51:24 rik Exp $
# $FreeBSD$
+PACKAGE=runtime
PROG= sconfig
MAN= sconfig.8
MANSUBDIR= /i386
diff --git a/sbin/setkey/Makefile b/sbin/setkey/Makefile
index e974af5f0b15..0777fff9fa67 100644
--- a/sbin/setkey/Makefile
+++ b/sbin/setkey/Makefile
@@ -29,6 +29,7 @@
.include <src.opts.mk>
+PACKAGE=runtime
PROG= setkey
MAN= setkey.8
SRCS= setkey.c parse.y token.l
diff --git a/sbin/shutdown/Makefile b/sbin/shutdown/Makefile
index 905d1bc9a04e..fc7e38be03cd 100644
--- a/sbin/shutdown/Makefile
+++ b/sbin/shutdown/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $FreeBSD$
+PACKAGE=runtime
PROG= shutdown
MAN= shutdown.8
LINKS= ${BINDIR}/shutdown ${BINDIR}/poweroff
diff --git a/sbin/swapon/Makefile b/sbin/swapon/Makefile
index e9074be9c433..c832be3dc96a 100644
--- a/sbin/swapon/Makefile
+++ b/sbin/swapon/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $FreeBSD$
+PACKAGE=runtime
PROG= swapon
MAN= swapon.8
LINKS= ${BINDIR}/swapon ${BINDIR}/swapoff
diff --git a/sbin/sysctl/Makefile b/sbin/sysctl/Makefile
index 06ff9b482d69..30099aedb34c 100644
--- a/sbin/sysctl/Makefile
+++ b/sbin/sysctl/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
# $FreeBSD$
+PACKAGE=runtime
PROG= sysctl
WARNS?= 3
MAN= sysctl.8
diff --git a/sbin/tests/Makefile b/sbin/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/sbin/tests/Makefile
+++ b/sbin/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/sbin/tunefs/Makefile b/sbin/tunefs/Makefile
index 07fe3b1ccaa1..a62d2f428e79 100644
--- a/sbin/tunefs/Makefile
+++ b/sbin/tunefs/Makefile
@@ -1,6 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $FreeBSD$
+PACKAGE=runtime
PROG= tunefs
LIBADD= ufs
MAN= tunefs.8
diff --git a/sbin/umount/Makefile b/sbin/umount/Makefile
index e472b41de493..cdc66b9ed808 100644
--- a/sbin/umount/Makefile
+++ b/sbin/umount/Makefile
@@ -2,6 +2,7 @@
#
# $FreeBSD$
+PACKAGE=runtime
PROG= umount
SRCS= umount.c vfslist.c mounttab.c
MAN= umount.8
diff --git a/secure/lib/libssh/Makefile b/secure/lib/libssh/Makefile
index 2eae203cb83f..35e291b37327 100644
--- a/secure/lib/libssh/Makefile
+++ b/secure/lib/libssh/Makefile
@@ -23,6 +23,7 @@ SRCS+= authfd.c authfile.c bufaux.c bufbn.c bufec.c buffer.c \
kex.c kexdh.c kexgex.c kexecdh.c kexc25519.c \
kexdhc.c kexgexc.c kexecdhc.c kexc25519c.c \
kexdhs.c kexgexs.c kexecdhs.c kexc25519s.c
+PACKAGE= ssh
# gss-genr.c should be in $SRCS but causes linking problems, so it is
# compiled directly into sshd instead.
diff --git a/secure/lib/tests/Makefile b/secure/lib/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/secure/lib/tests/Makefile
+++ b/secure/lib/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/secure/libexec/Makefile.inc b/secure/libexec/Makefile.inc
index 6d620e245bff..084a71910243 100644
--- a/secure/libexec/Makefile.inc
+++ b/secure/libexec/Makefile.inc
@@ -1,5 +1,6 @@
# $FreeBSD$
BINDIR?= /usr/libexec
+PACKAGE= ssh
.include "../Makefile.inc"
diff --git a/secure/libexec/tests/Makefile b/secure/libexec/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/secure/libexec/tests/Makefile
+++ b/secure/libexec/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/secure/tests/Makefile b/secure/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/secure/tests/Makefile
+++ b/secure/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/secure/usr.bin/scp/Makefile b/secure/usr.bin/scp/Makefile
index 18cfbaf38f54..ca00921f5e62 100644
--- a/secure/usr.bin/scp/Makefile
+++ b/secure/usr.bin/scp/Makefile
@@ -4,6 +4,7 @@
PROG= scp
SRCS= scp.c
+PACKAGE= ssh
CFLAGS+=-I${SSHDIR} -include ssh_namespace.h
SRCS+= ssh_namespace.h
diff --git a/secure/usr.bin/sftp/Makefile b/secure/usr.bin/sftp/Makefile
index 9cea9fe3f08e..4b1f24ebd9ca 100644
--- a/secure/usr.bin/sftp/Makefile
+++ b/secure/usr.bin/sftp/Makefile
@@ -4,6 +4,7 @@
PROG= sftp
SRCS= sftp.c sftp-client.c sftp-common.c sftp-glob.c progressmeter.c
+PACKAGE= ssh
CFLAGS+=-I${SSHDIR} -include ssh_namespace.h
SRCS+= ssh_namespace.h
diff --git a/secure/usr.bin/ssh-add/Makefile b/secure/usr.bin/ssh-add/Makefile
index 2f5d76e0d79c..70feb8b00865 100644
--- a/secure/usr.bin/ssh-add/Makefile
+++ b/secure/usr.bin/ssh-add/Makefile
@@ -4,6 +4,7 @@
PROG= ssh-add
SRCS+= ssh-add.c
+PACKAGE= ssh
CFLAGS+=-I${SSHDIR} -include ssh_namespace.h
SRCS+= ssh_namespace.h
diff --git a/secure/usr.bin/ssh-agent/Makefile b/secure/usr.bin/ssh-agent/Makefile
index e79a02e1f6b5..1e77d96ff020 100644
--- a/secure/usr.bin/ssh-agent/Makefile
+++ b/secure/usr.bin/ssh-agent/Makefile
@@ -4,6 +4,7 @@
PROG= ssh-agent
SRCS= ssh-agent.c
+PACKAGE= ssh
CFLAGS+=-I${SSHDIR} -include ssh_namespace.h
SRCS+= ssh_namespace.h
diff --git a/secure/usr.bin/ssh-keygen/Makefile b/secure/usr.bin/ssh-keygen/Makefile
index c3d6b2fd6b61..5cd6e2f9cc90 100644
--- a/secure/usr.bin/ssh-keygen/Makefile
+++ b/secure/usr.bin/ssh-keygen/Makefile
@@ -4,6 +4,7 @@
PROG= ssh-keygen
SRCS= ssh-keygen.c
+PACKAGE= ssh
CFLAGS+=-I${SSHDIR} -include ssh_namespace.h
SRCS+= ssh_namespace.h
diff --git a/secure/usr.bin/ssh-keyscan/Makefile b/secure/usr.bin/ssh-keyscan/Makefile
index a2237a4fabf7..95b85e45b82e 100644
--- a/secure/usr.bin/ssh-keyscan/Makefile
+++ b/secure/usr.bin/ssh-keyscan/Makefile
@@ -4,6 +4,7 @@
PROG= ssh-keyscan
SRCS= ssh-keyscan.c roaming_dummy.c
+PACKAGE= ssh
CFLAGS+=-I${SSHDIR} -include ssh_namespace.h
SRCS+= ssh_namespace.h
diff --git a/secure/usr.bin/ssh/Makefile b/secure/usr.bin/ssh/Makefile
index cad6b30335b6..38eab11e3d6c 100644
--- a/secure/usr.bin/ssh/Makefile
+++ b/secure/usr.bin/ssh/Makefile
@@ -6,6 +6,7 @@ PROG= ssh
LINKS= ${BINDIR}/ssh ${BINDIR}/slogin
MAN= ssh.1 ssh_config.5
MLINKS= ssh.1 slogin.1
+PACKAGE= ssh
SRCS= ssh.c readconf.c clientloop.c sshtty.c \
sshconnect.c sshconnect1.c sshconnect2.c mux.c \
diff --git a/secure/usr.bin/tests/Makefile b/secure/usr.bin/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/secure/usr.bin/tests/Makefile
+++ b/secure/usr.bin/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/secure/usr.sbin/sshd/Makefile b/secure/usr.sbin/sshd/Makefile
index debe2566bf47..c9fd159ee658 100644
--- a/secure/usr.sbin/sshd/Makefile
+++ b/secure/usr.sbin/sshd/Makefile
@@ -17,6 +17,7 @@ SRCS= sshd.c auth-rhosts.c auth-passwd.c auth-rsa.c auth-rh-rsa.c \
roaming_common.c roaming_serv.c \
sandbox-null.c sandbox-rlimit.c sandbox-systrace.c sandbox-darwin.c \
sandbox-seccomp-filter.c sandbox-capsicum.c
+PACKAGE= ssh
# gss-genr.c really belongs in libssh; see src/secure/lib/libssh/Makefile
SRCS+= gss-genr.c
diff --git a/secure/usr.sbin/tests/Makefile b/secure/usr.sbin/tests/Makefile
index a0e63e5da42a..609357e57d33 100644
--- a/secure/usr.sbin/tests/Makefile
+++ b/secure/usr.sbin/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
.PATH: ${SRCTOP}/tests
KYUAFILE= yes
diff --git a/share/examples/Makefile b/share/examples/Makefile
index 2484aff89007..c71604e827b3 100644
--- a/share/examples/Makefile
+++ b/share/examples/Makefile
@@ -210,6 +210,7 @@ XFILES+= libusb20/Makefile \
.if ${MK_BHYVE} != "no"
LDIRS+= bhyve
XFILES+= bhyve/vmrun.sh
+PACKAGE_bhyve/vmrun.sh= bhyve
.endif
.endif
@@ -230,7 +231,7 @@ copies:
mtree -deU ${MTREE_FOLLOWS_SYMLINKS} \
-f ${.CURDIR}/../../etc/mtree/BSD.usr.dist -p ${DESTDIR}/usr
.for file in ${XFILES}
- ${INSTALL} -o ${SHAREOWN} -g ${SHAREGRP} -m ${SHAREMODE} \
+ ${INSTALL} -T package=${PACKAGE_${file}:Uruntime} -o ${SHAREOWN} -g ${SHAREGRP} -m ${SHAREMODE} \
${.CURDIR}/${file} ${DESTDIR}${BINDIR}/${file}
.endfor
diff --git a/share/examples/tests/Makefile b/share/examples/tests/Makefile
index a091b2d2f68e..c543aa3957b1 100644
--- a/share/examples/tests/Makefile
+++ b/share/examples/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
SUBDIR= tests
.PATH: ${SRCTOP}/tests
diff --git a/share/examples/tests/tests/Makefile b/share/examples/tests/tests/Makefile
index 9f7b5a4729c4..c41753143bbd 100644
--- a/share/examples/tests/tests/Makefile
+++ b/share/examples/tests/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
# Directory into which the Kyuafile provided by this directory will be
# installed.
#
diff --git a/share/examples/tests/tests/atf/Makefile b/share/examples/tests/tests/atf/Makefile
index c7bd46fef7b1..ef96dcb14aba 100644
--- a/share/examples/tests/tests/atf/Makefile
+++ b/share/examples/tests/tests/atf/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
# Directory into which the Kyuafile provided by this directory will be
# installed.
#
diff --git a/share/examples/tests/tests/plain/Makefile b/share/examples/tests/tests/plain/Makefile
index 7348c5a970e5..0b82397a438d 100644
--- a/share/examples/tests/tests/plain/Makefile
+++ b/share/examples/tests/tests/plain/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
# Directory into which the Kyuafile provided by this directory will be
# installed.
#
diff --git a/share/man/man1/Makefile b/share/man/man1/Makefile
index 1b37c4b34e33..ed75177189a3 100644
--- a/share/man/man1/Makefile
+++ b/share/man/man1/Makefile
@@ -5,6 +5,8 @@
MAN= builtin.1 intro.1
+PACKAGE=runtime-manuals
+
.if ${MK_TESTS} != "no"
ATF= ${.CURDIR}/../../../contrib/atf
.PATH: ${ATF}/doc
diff --git a/share/man/man3/Makefile b/share/man/man3/Makefile
index 373587085035..2a3c12a4136c 100644
--- a/share/man/man3/Makefile
+++ b/share/man/man3/Makefile
@@ -3,6 +3,8 @@
.include <src.opts.mk>
+PACKAGE=runtime-manuals
+
MAN= assert.3 \
ATOMIC_VAR_INIT.3 \
bitstring.3 \
diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile
index 2508da085d2d..3d87773b01a9 100644
--- a/share/man/man4/Makefile
+++ b/share/man/man4/Makefile
@@ -3,6 +3,8 @@
.include <src.opts.mk>
+PACKAGE=runtime-manuals
+
MAN= aac.4 \
aacraid.4 \
acpi.4 \
diff --git a/share/man/man4/man4.arm/Makefile b/share/man/man4/man4.arm/Makefile
index 0e5b576f4c44..696d2c16e099 100644
--- a/share/man/man4/man4.arm/Makefile
+++ b/share/man/man4/man4.arm/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+PACKAGE=runtime-manuals
+
MAN= cgem.4 \
devcfg.4 \
mge.4 \
diff --git a/share/man/man4/man4.i386/Makefile b/share/man/man4/man4.i386/Makefile
index 974eec02df73..7b25eca28c62 100644
--- a/share/man/man4/man4.i386/Makefile
+++ b/share/man/man4/man4.i386/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+PACKAGE=runtime-manuals
+
MAN= aic.4 \
apm.4 \
ce.4 \
diff --git a/share/man/man4/man4.powerpc/Makefile b/share/man/man4/man4.powerpc/Makefile
index 2b5ec8ea1fee..01d5a46dbb83 100644
--- a/share/man/man4/man4.powerpc/Makefile
+++ b/share/man/man4/man4.powerpc/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+PACKAGE=runtime-manuals
+
MAN= adb.4 \
akbd.4 \
abtn.4 \
diff --git a/share/man/man4/man4.sparc64/Makefile b/share/man/man4/man4.sparc64/Makefile
index 06d99c00a293..39ae51527850 100644
--- a/share/man/man4/man4.sparc64/Makefile
+++ b/share/man/man4/man4.sparc64/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+PACKAGE=runtime-manuals
+
MAN= auxio.4 \
central.4 \
clkbrd.4 \
diff --git a/share/man/man5/Makefile b/share/man/man5/Makefile
index 1ead7c62eab1..108397ddb46d 100644
--- a/share/man/man5/Makefile
+++ b/share/man/man5/Makefile
@@ -3,6 +3,8 @@
.include <src.opts.mk>
+PACKAGE=runtime-manuals
+
#MISSING: dump.5 plot.5
MAN= acct.5 \
ar.5 \
diff --git a/share/man/man6/Makefile b/share/man/man6/Makefile
index be6547e592b5..dbf4b14a596e 100644
--- a/share/man/man6/Makefile
+++ b/share/man/man6/Makefile
@@ -2,4 +2,6 @@
MAN= intro.6
+PACKAGE=runtime-manuals
+
.include <bsd.prog.mk>
diff --git a/share/man/man7/Makefile b/share/man/man7/Makefile
index 22d29aec376c..54f14f51e1d9 100644
--- a/share/man/man7/Makefile
+++ b/share/man/man7/Makefile
@@ -3,6 +3,8 @@
.include <src.opts.mk>
+PACKAGE=runtime-manuals
+
#MISSING: eqnchar.7 ms.7 term.7
MAN= adding_user.7 \
ascii.7 \
diff --git a/share/man/man8/Makefile b/share/man/man8/Makefile
index dc119b556c0f..54b13142886f 100644
--- a/share/man/man8/Makefile
+++ b/share/man/man8/Makefile
@@ -1,6 +1,8 @@
# @(#)Makefile 8.1 (Berkeley) 6/5/93
# $FreeBSD$
+PACKAGE=runtime-manuals
+
MAN= crash.8 \
diskless.8 \
intro.8 \
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
index 66c16d726ef4..fa768f531019 100644
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -2,6 +2,8 @@
.include <src.opts.mk>
+PACKAGE=runtime-manuals
+
MAN= accept_filter.9 \
accf_data.9 \
accf_dns.9 \
diff --git a/share/mk/bsd.doc.mk b/share/mk/bsd.doc.mk
index ddf71308c985..5b88ae5d9f0b 100644
--- a/share/mk/bsd.doc.mk
+++ b/share/mk/bsd.doc.mk
@@ -81,6 +81,13 @@ TRFLAGS+= -I${.CURDIR}
TRFLAGS+= -t
.endif
+.if defined(NO_ROOT)
+.if !defined(TAGS) || ! ${TAGS:Mpackage=*}
+TAGS+= package=${PACKAGE:Uruntime}
+.endif
+TAG_ARGS= -T ${TAGS:[*]:S/ /,/g}
+.endif
+
DCOMPRESS_EXT?= ${COMPRESS_EXT}
DCOMPRESS_CMD?= ${COMPRESS_CMD}
.for _dev in ${PRINTERDEVICE:Mhtml}
@@ -137,11 +144,11 @@ CLEANFILES+= ${DOC}.ascii ${DOC}.ascii${DCOMPRESS_EXT} \
realinstall:
.if ${PRINTERDEVICE:Mhtml}
cd ${SRCDIR}; \
- ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},docs} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
${DOC}*.html ${DESTDIR}${BINDIR}/${VOLUME}/
.endif
.for _dev in ${PRINTERDEVICE:Nhtml}
- ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},docs} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
${DFILE.${_dev}} ${DESTDIR}${BINDIR}/${VOLUME}/
.endfor
diff --git a/share/mk/bsd.files.mk b/share/mk/bsd.files.mk
index d22f19694d13..d4fd5095c0d4 100644
--- a/share/mk/bsd.files.mk
+++ b/share/mk/bsd.files.mk
@@ -35,6 +35,14 @@ STAGE_SETS+= ${group}
.endif
STAGE_DIR.${group}= ${STAGE_OBJTOP}${${group}DIR}
+.if defined(NO_ROOT)
+.if !defined(${group}TAGS) || ! ${${group}TAGS:Mpackage=*}
+${group}TAGS+= package=${${group}PACKAGE:Uruntime}
+.endif
+${group}TAG_ARGS= -T ${${group}TAGS:[*]:S/ /,/g}
+.endif
+
+
_${group}FILES=
.for file in ${${group}}
.if defined(${group}OWN_${file:T}) || defined(${group}GRP_${file:T}) || \
@@ -59,7 +67,7 @@ stage_as.${file:T}: ${file}
installfiles-${group}: _${group}INS_${file:T}
_${group}INS_${file:T}: ${file}
- ${INSTALL} -o ${${group}OWN_${.ALLSRC:T}} \
+ ${INSTALL} ${${group}TAG_ARGS} -o ${${group}OWN_${.ALLSRC:T}} \
-g ${${group}GRP_${.ALLSRC:T}} -m ${${group}MODE_${.ALLSRC:T}} \
${.ALLSRC} \
${DESTDIR}${${group}DIR_${.ALLSRC:T}}/${${group}NAME_${.ALLSRC:T}}
@@ -73,11 +81,11 @@ stage_files.${group}: ${_${group}FILES}
installfiles-${group}: _${group}INS
_${group}INS: ${_${group}FILES}
.if defined(${group}NAME)
- ${INSTALL} -o ${${group}OWN} -g ${${group}GRP} \
+ ${INSTALL} ${${group}TAG_ARGS} -o ${${group}OWN} -g ${${group}GRP} \
-m ${${group}MODE} ${.ALLSRC} \
${DESTDIR}${${group}DIR}/${${group}NAME}
.else
- ${INSTALL} -o ${${group}OWN} -g ${${group}GRP} \
+ ${INSTALL} ${${group}TAG_ARGS} -o ${${group}OWN} -g ${${group}GRP} \
-m ${${group}MODE} ${.ALLSRC} ${DESTDIR}${${group}DIR}/
.endif
.endif
diff --git a/share/mk/bsd.incs.mk b/share/mk/bsd.incs.mk
index 42b9e42f4b45..c5c852ac5a15 100644
--- a/share/mk/bsd.incs.mk
+++ b/share/mk/bsd.incs.mk
@@ -10,6 +10,13 @@ INCSGROUPS?= INCS
_INCSGROUPS= ${INCSGROUPS:C,[/*],_,g}
+.if defined(NO_ROOT)
+.if !defined(TAGS) || ! ${TAGS:Mpackage=*}
+TAGS+= package=${PACKAGE:Uruntime}
+.endif
+TAG_ARGS= -T ${TAGS:[*]:S/ /,/g}
+.endif
+
.if !target(buildincludes)
.for group in ${_INCSGROUPS}
buildincludes: ${${group}}
@@ -70,10 +77,10 @@ stage_includes: stage_files.${group}
installincludes: _${group}INS
_${group}INS: ${_${group}INCS}
.if defined(${group}NAME)
- ${INSTALL} -C -o ${${group}OWN} -g ${${group}GRP} -m ${${group}MODE} \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -C -o ${${group}OWN} -g ${${group}GRP} -m ${${group}MODE} \
${.ALLSRC} ${DESTDIR}${${group}DIR}/${${group}NAME}
.else
- ${INSTALL} -C -o ${${group}OWN} -g ${${group}GRP} -m ${${group}MODE} \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -C -o ${${group}OWN} -g ${${group}GRP} -m ${${group}MODE} \
${.ALLSRC} ${DESTDIR}${${group}DIR}/
.endif
.endif
@@ -84,7 +91,8 @@ _${group}INS: ${_${group}INCS}
.if defined(INCSLINKS) && !empty(INCSLINKS)
installincludes:
.for s t in ${INCSLINKS}
- ${INSTALL_SYMLINK} ${s} ${DESTDIR}${t}
+ @${ECHO} "${DESTDIR}${t} -> ${s}" ; \
+ ${INSTALL_SYMLINK} ${TAG_ARGS:D${TAG_ARGS},development} ${s} ${DESTDIR}${t}
.endfor
.endif
.endif # !target(installincludes)
diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk
index 51fb828400a2..29a95e5a7df1 100644
--- a/share/mk/bsd.lib.mk
+++ b/share/mk/bsd.lib.mk
@@ -51,6 +51,17 @@ CTFFLAGS+= -g
STRIP?= -s
.endif
+.if ${SHLIBDIR:M*lib32*}
+TAGS+= lib32
+.endif
+
+.if defined(NO_ROOT)
+.if !defined(TAGS) || ! ${TAGS:Mpackage=*}
+TAGS+= package=${PACKAGE:Uruntime}
+.endif
+TAG_ARGS= -T ${TAGS:[*]:S/ /,/g}
+.endif
+
.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
empty(DEBUG_FLAGS:M-gdwarf*)
SHARED_CFLAGS+= -g
@@ -248,7 +259,7 @@ ${SHLIB_NAME_FULL}: ${SOBJS}
@${ECHO} building shared library ${SHLIB_NAME}
@rm -f ${SHLIB_NAME} ${SHLIB_LINK}
.if defined(SHLIB_LINK) && !commands(${SHLIB_LINK:R}.ld)
- @${INSTALL_SYMLINK} ${SHLIB_NAME} ${SHLIB_LINK}
+ @${INSTALL_SYMLINK} ${TAG_ARGS:D${TAG_ARGS},development} ${SHLIB_NAME} ${SHLIB_LINK}
.endif
${_LD:N${CCACHE_BIN}} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
-o ${.TARGET} -Wl,-soname,${SONAME} \
@@ -341,28 +352,28 @@ realinstall: _libinstall
.ORDER: beforeinstall _libinstall
_libinstall:
.if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no"
- ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}.a ${DESTDIR}${_LIBDIR}/
.endif
.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
- ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},profile} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}_p.a ${DESTDIR}${_LIBDIR}/
.endif
.if defined(SHLIB_NAME)
- ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${INSTALL} ${TAG_ARGS} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
${SHLIB_NAME} ${DESTDIR}${_SHLIBDIR}/
.if ${MK_DEBUG_FILES} != "no"
.if defined(DEBUGMKDIR)
- ${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}/
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -d ${DESTDIR}${DEBUGFILEDIR}/
.endif
- ${INSTALL} -T debug -o ${LIBOWN} -g ${LIBGRP} -m ${DEBUGMODE} \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -o ${LIBOWN} -g ${LIBGRP} -m ${DEBUGMODE} \
${_INSTALLFLAGS} \
${SHLIB_NAME}.debug ${DESTDIR}${DEBUGFILEDIR}/
.endif
.if defined(SHLIB_LINK)
.if commands(${SHLIB_LINK:R}.ld)
- ${INSTALL} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${_INSTALLFLAGS} ${SHLIB_LINK:R}.ld \
${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
.for _SHLIB_LINK_LINK in ${SHLIB_LDSCRIPT_LINKS}
@@ -370,10 +381,20 @@ _libinstall:
.endfor
.else
.if ${_SHLIBDIR} == ${_LIBDIR}
- ${INSTALL_SYMLINK} ${SHLIB_NAME} ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
+.if ${SHLIB_LINK:Mlib*}
+ ${INSTALL_RSYMLINK} ${TAG_ARGS:D${TAG_ARGS},development} ${SHLIB_NAME} ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
.else
- ${INSTALL_RSYMLINK} ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} \
+ ${INSTALL_RSYMLINK} ${TAG_ARGS} ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} \
${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
+.endif
+.else
+.if ${SHLIB_LINK:Mlib*}
+ ${INSTALL_RSYMLINK} ${TAG_ARGS:D${TAG_ARGS},development} ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} \
+ ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
+.else
+ ${INSTALL_RSYMLINK} ${TAG_ARGS} ${DESTDIR}${_SHLIBDIR}/${SHLIB_NAME} \
+ ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
+.endif
.if exists(${DESTDIR}${_LIBDIR}/${SHLIB_NAME})
-chflags noschg ${DESTDIR}${_LIBDIR}/${SHLIB_NAME}
rm -f ${DESTDIR}${_LIBDIR}/${SHLIB_NAME}
@@ -383,11 +404,11 @@ _libinstall:
.endif # SHLIB_LINK
.endif # SHIB_NAME
.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
- ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${_LIBDIR}/
.endif
.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
- ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},development} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR}/
.endif
.endif # !defined(INTERNALLIB)
diff --git a/share/mk/bsd.links.mk b/share/mk/bsd.links.mk
index 9e24af86624f..e69f3a0369f9 100644
--- a/share/mk/bsd.links.mk
+++ b/share/mk/bsd.links.mk
@@ -4,12 +4,21 @@
.error bsd.links.mk cannot be included directly.
.endif
+.if defined(NO_ROOT)
+.if !defined(TAGS) || ! ${TAGS:Mpackage=*}
+TAGS+= package=${PACKAGE}
+.endif
+TAG_ARGS= -T ${TAGS:[*]:S/ /,/g}
+.endif
+
afterinstall: _installlinks
.ORDER: realinstall _installlinks
_installlinks:
.for s t in ${LINKS}
- ${INSTALL_LINK} ${DESTDIR}${s} ${DESTDIR}${t}
+ @${ECHO} "${t} -> ${s}" ;\
+ ${INSTALL_LINK} ${TAG_ARGS} ${DESTDIR}${s} ${DESTDIR}${t}
.endfor
.for s t in ${SYMLINKS}
- ${INSTALL_SYMLINK} ${s} ${DESTDIR}${t}
+ @${ECHO} "${t} -> ${s}" ;\
+ ${INSTALL_SYMLINK} ${TAG_ARGS} ${s} ${DESTDIR}/${t}
.endfor
diff --git a/share/mk/bsd.man.mk b/share/mk/bsd.man.mk
index 6d915451699c..eca01391b6f9 100644
--- a/share/mk/bsd.man.mk
+++ b/share/mk/bsd.man.mk
@@ -50,7 +50,7 @@
.error bsd.man.mk cannot be included directly.
.endif
-MINSTALL?= ${INSTALL} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
+MINSTALL?= ${INSTALL} ${TAG_ARGS} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
CATDIR= ${MANDIR:H:S/$/\/cat/}
CATEXT= .cat
@@ -62,6 +62,7 @@ MCOMPRESS_EXT?= ${COMPRESS_EXT}
SECTIONS= 1 2 3 4 5 6 7 8 9
.SUFFIXES: ${SECTIONS:S/^/./g}
+
# Backwards compatibility.
.if !defined(MAN)
.for __sect in ${SECTIONS}
@@ -226,7 +227,7 @@ maninstall: ${MAN}
.endif
.for l t in ${_MANLINKS}
rm -f ${DESTDIR}${t} ${DESTDIR}${t}${MCOMPRESS_EXT}; \
- ${INSTALL_LINK} ${DESTDIR}${l}${ZEXT} ${DESTDIR}${t}${ZEXT}
+ ${INSTALL_LINK} ${TAG_ARGS} ${DESTDIR}${l}${ZEXT} ${DESTDIR}${t}${ZEXT}
.endfor
manlint:
diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk
index 4287ff37a943..30c37cad88fc 100644
--- a/share/mk/bsd.prog.mk
+++ b/share/mk/bsd.prog.mk
@@ -47,6 +47,13 @@ CTFFLAGS+= -g
STRIP?= -s
.endif
+.if defined(NO_ROOT)
+.if !defined(TAGS) || ! ${TAGS:Mpackage=*}
+TAGS+= package=${PACKAGE:Uruntime}
+.endif
+TAG_ARGS= -T ${TAGS:[*]:S/ /,/g}
+.endif
+
.if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
LDFLAGS+= -static
.endif
@@ -206,13 +213,13 @@ realinstall: _proginstall
.ORDER: beforeinstall _proginstall
_proginstall:
.if defined(PROG)
- ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
+ ${INSTALL} ${TAG_ARGS} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
.if ${MK_DEBUG_FILES} != "no"
.if defined(DEBUGMKDIR)
- ${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}/
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -d ${DESTDIR}${DEBUGFILEDIR}/
.endif
- ${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
+ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug
.endif
.endif
@@ -244,7 +251,7 @@ SCRIPTSMODE_${script:T}?= ${SCRIPTSMODE}
STAGE_AS_${script:T}= ${SCRIPTSDIR_${script:T}}/${SCRIPTSNAME_${script:T}}
_scriptsinstall: _SCRIPTSINS_${script:T}
_SCRIPTSINS_${script:T}: ${script}
- ${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
+ ${INSTALL} ${TAG_ARGS} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
-g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
${.ALLSRC} \
${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
diff --git a/share/mk/bsd.test.mk b/share/mk/bsd.test.mk
index f87f5dc4a23c..97240ccbd11e 100644
--- a/share/mk/bsd.test.mk
+++ b/share/mk/bsd.test.mk
@@ -15,6 +15,7 @@ LOCALBASE?= /usr/local
# Tests install directory
TESTSDIR?= ${TESTSBASE}/${RELDIR:H}
+PACKAGE= tests
# List of subdirectories containing tests into which to recurse. This has the
# same semantics as SUBDIR at build-time. However, the directories listed here
diff --git a/share/sendmail/Makefile b/share/sendmail/Makefile
index a548b63144e5..0e1a27dd3018 100644
--- a/share/sendmail/Makefile
+++ b/share/sendmail/Makefile
@@ -4,6 +4,7 @@
SENDMAIL_DIR=${.CURDIR}/../../contrib/sendmail
CFDIR= cf
+CFPACKAGE= sendmail
CFDIRS!= (cd ${SENDMAIL_DIR}; find -L ${CFDIR} \( \( -name CVS -o -name .svn \) -prune \) -o -type d -print)
CFFILES!= (cd ${SENDMAIL_DIR}; find -L ${CFDIR} \( \( -name CVS -o -name .svn \) -prune \) -o -type f -print)
diff --git a/share/syscons/Makefile.inc b/share/syscons/Makefile.inc
new file mode 100644
index 000000000000..59bf625149dd
--- /dev/null
+++ b/share/syscons/Makefile.inc
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+FILESPACKAGE= syscons
diff --git a/share/tests/Makefile b/share/tests/Makefile
index e070571ecb4b..6448a415f9b3 100644
--- a/share/tests/Makefile
+++ b/share/tests/Makefile
@@ -2,6 +2,10 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
TESTSDIR= ${TESTSBASE}/share
.PATH: ${SRCTOP}/tests
diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk
index 03ccc60eb9ac..10b7dedc7772 100644
--- a/sys/conf/kmod.mk
+++ b/sys/conf/kmod.mk
@@ -307,10 +307,10 @@ KERN_DEBUGDIR?= ${DEBUGDIR}
realinstall: _kmodinstall
.ORDER: beforeinstall _kmodinstall
_kmodinstall:
- ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
+ ${INSTALL} -T release -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
${_INSTALLFLAGS} ${PROG} ${DESTDIR}${KMODDIR}/
.if defined(DEBUG_FLAGS) && !defined(INSTALL_NODEBUG) && ${MK_KERNEL_SYMBOLS} != "no"
- ${INSTALL} -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
+ ${INSTALL} -T debug -o ${KMODOWN} -g ${KMODGRP} -m ${KMODMODE} \
${_INSTALLFLAGS} ${PROG}.debug ${DESTDIR}${KERN_DEBUGDIR}${KMODDIR}/
.endif
diff --git a/sys/modules/tests/callout_test/Makefile b/sys/modules/tests/callout_test/Makefile
index 4781488af3b8..eadcadc5026a 100644
--- a/sys/modules/tests/callout_test/Makefile
+++ b/sys/modules/tests/callout_test/Makefile
@@ -2,6 +2,10 @@
# $FreeBSD$
#
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
.PATH: ${.CURDIR}/../../../tests/callout_test
KMOD= callout_test
diff --git a/sys/modules/tests/framework/Makefile b/sys/modules/tests/framework/Makefile
index f5f608fb0465..c56838dd92d2 100644
--- a/sys/modules/tests/framework/Makefile
+++ b/sys/modules/tests/framework/Makefile
@@ -2,6 +2,10 @@
# $FreeBSD$
#
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
.PATH: ${.CURDIR}/../../../tests/framework
KMOD= kern_testfrwk
diff --git a/tests/Makefile b/tests/Makefile
index 30b9692c1f49..ba743ee31df5 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
SUBDIR+= etc
SUBDIR+= sys
SUBDIR_PARALLEL=
diff --git a/tests/etc/Makefile b/tests/etc/Makefile
index 1e49666767c0..7e73a48f35c5 100644
--- a/tests/etc/Makefile
+++ b/tests/etc/Makefile
@@ -2,6 +2,11 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+TESTS+= Kyuafile
+
TESTSDIR= ${TESTSBASE}/etc
.PATH: ${SRCTOP}/tests
diff --git a/tests/etc/rc.d/Makefile b/tests/etc/rc.d/Makefile
index 368e8f4fc875..3b946a3b5a90 100644
--- a/tests/etc/rc.d/Makefile
+++ b/tests/etc/rc.d/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/etc/rc.d
ATF_TESTS_SH+= routing_test
diff --git a/tests/sys/Makefile b/tests/sys/Makefile
index 36bdde067e8d..40a5e648f211 100644
--- a/tests/sys/Makefile
+++ b/tests/sys/Makefile
@@ -2,6 +2,9 @@
.include <bsd.own.mk>
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys
TESTS_SUBDIRS+= acl
diff --git a/tests/sys/acl/Makefile b/tests/sys/acl/Makefile
index d101088dcd3f..7db6682de41c 100644
--- a/tests/sys/acl/Makefile
+++ b/tests/sys/acl/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/acl
BINDIR= ${TESTSDIR}
diff --git a/tests/sys/aio/Makefile b/tests/sys/aio/Makefile
index 766d9b00f38c..0003b844cc9b 100644
--- a/tests/sys/aio/Makefile
+++ b/tests/sys/aio/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/aio
PLAIN_TESTS_C+= aio_kqueue_test
diff --git a/tests/sys/fifo/Makefile b/tests/sys/fifo/Makefile
index 602bf1ed2940..750d5db2a91d 100644
--- a/tests/sys/fifo/Makefile
+++ b/tests/sys/fifo/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/fifo
PLAIN_TESTS_C+= fifo_create
diff --git a/tests/sys/file/Makefile b/tests/sys/file/Makefile
index ed2d2c4fbe2e..0b3c0fc5da61 100644
--- a/tests/sys/file/Makefile
+++ b/tests/sys/file/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/file
BINDIR= ${TESTSDIR}
diff --git a/tests/sys/geom/Makefile b/tests/sys/geom/Makefile
index bf8604dcabc3..e6ecc836da84 100644
--- a/tests/sys/geom/Makefile
+++ b/tests/sys/geom/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/geom
TESTS_SUBDIRS+= class
diff --git a/tests/sys/geom/class/Makefile b/tests/sys/geom/class/Makefile
index c70561691420..d4f6168cd8c6 100644
--- a/tests/sys/geom/class/Makefile
+++ b/tests/sys/geom/class/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/geom/class
TESTS_SUBDIRS+= concat
diff --git a/tests/sys/geom/class/concat/Makefile b/tests/sys/geom/class/concat/Makefile
index 5659b5d38215..cd1eb6174a10 100644
--- a/tests/sys/geom/class/concat/Makefile
+++ b/tests/sys/geom/class/concat/Makefile
@@ -1,6 +1,10 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/geom/class/${.CURDIR:T}
+TESTS+= ${FILES}
TAP_TESTS_SH+= 1_test
TAP_TESTS_SH+= 2_test
diff --git a/tests/sys/geom/class/eli/Makefile b/tests/sys/geom/class/eli/Makefile
index 8f4ca60d03c3..65ee1923e975 100644
--- a/tests/sys/geom/class/eli/Makefile
+++ b/tests/sys/geom/class/eli/Makefile
@@ -1,6 +1,10 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/geom/class/${.CURDIR:T}
+TESTS+= ${FILES}
TAP_TESTS_SH+= attach_d_test
TAP_TESTS_SH+= configure_b_B_test
diff --git a/tests/sys/geom/class/gate/Makefile b/tests/sys/geom/class/gate/Makefile
index 11ceb944cfdf..25bcc2a1e7ea 100644
--- a/tests/sys/geom/class/gate/Makefile
+++ b/tests/sys/geom/class/gate/Makefile
@@ -1,6 +1,10 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/geom/class/${.CURDIR:T}
+TESTS+= ${FILES}
TAP_TESTS_SH+= 1_test
TAP_TESTS_SH+= 2_test
diff --git a/tests/sys/geom/class/mirror/Makefile b/tests/sys/geom/class/mirror/Makefile
index 931f7d0dcb57..c2f732c83b60 100644
--- a/tests/sys/geom/class/mirror/Makefile
+++ b/tests/sys/geom/class/mirror/Makefile
@@ -1,6 +1,10 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/geom/class/${.CURDIR:T}
+TESTS+= ${FILES}
TAP_TESTS_SH+= 1_test
TAP_TESTS_SH+= 2_test
diff --git a/tests/sys/geom/class/nop/Makefile b/tests/sys/geom/class/nop/Makefile
index 5659b5d38215..cd1eb6174a10 100644
--- a/tests/sys/geom/class/nop/Makefile
+++ b/tests/sys/geom/class/nop/Makefile
@@ -1,6 +1,10 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/geom/class/${.CURDIR:T}
+TESTS+= ${FILES}
TAP_TESTS_SH+= 1_test
TAP_TESTS_SH+= 2_test
diff --git a/tests/sys/geom/class/raid3/Makefile b/tests/sys/geom/class/raid3/Makefile
index 526c175e9976..3981ec7de2ac 100644
--- a/tests/sys/geom/class/raid3/Makefile
+++ b/tests/sys/geom/class/raid3/Makefile
@@ -1,6 +1,10 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/geom/class/${.CURDIR:T}
+TESTS+= ${FILES}
TAP_TESTS_SH+= 1_test
TAP_TESTS_SH+= 2_test
diff --git a/tests/sys/geom/class/shsec/Makefile b/tests/sys/geom/class/shsec/Makefile
index 5659b5d38215..cd1eb6174a10 100644
--- a/tests/sys/geom/class/shsec/Makefile
+++ b/tests/sys/geom/class/shsec/Makefile
@@ -1,6 +1,10 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/geom/class/${.CURDIR:T}
+TESTS+= ${FILES}
TAP_TESTS_SH+= 1_test
TAP_TESTS_SH+= 2_test
diff --git a/tests/sys/geom/class/stripe/Makefile b/tests/sys/geom/class/stripe/Makefile
index 5659b5d38215..cd1eb6174a10 100644
--- a/tests/sys/geom/class/stripe/Makefile
+++ b/tests/sys/geom/class/stripe/Makefile
@@ -1,6 +1,10 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/geom/class/${.CURDIR:T}
+TESTS+= ${FILES}
TAP_TESTS_SH+= 1_test
TAP_TESTS_SH+= 2_test
diff --git a/tests/sys/geom/class/uzip/Makefile b/tests/sys/geom/class/uzip/Makefile
index b9624068739f..91c874e30c30 100644
--- a/tests/sys/geom/class/uzip/Makefile
+++ b/tests/sys/geom/class/uzip/Makefile
@@ -4,6 +4,9 @@
# Regression test for geom_uzip.
#
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/geom/class/${.CURDIR:T}
IMAGE= 1.img
@@ -29,9 +32,11 @@ FILESNAME_conf.sh= conf.sh
FILES+= ${UZIMAGE}
FILESDIR= ${TESTSDIR}
-FILESGROUPS= FILES etalon
+FILESGROUPS+= FILES etalon
etalon+= etalon/etalon.txt
etalonDIR= ${TESTSDIR}/etalon
+FILESPACKAGE= ${PACKAGE}
+etalonPACKAGE= ${PACKAGE}
TAP_TESTS_SH+= 1_test
diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile
index c9a7cfd46bc8..f38cc5850c5c 100644
--- a/tests/sys/kern/Makefile
+++ b/tests/sys/kern/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSRC= ${SRCTOP}/contrib/netbsd-tests/kernel
TESTSDIR= ${TESTSBASE}/sys/kern
diff --git a/tests/sys/kern/acct/Makefile b/tests/sys/kern/acct/Makefile
index ca3df4c6c703..3a9a7ecdf1a5 100644
--- a/tests/sys/kern/acct/Makefile
+++ b/tests/sys/kern/acct/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/kern/acct
ATF_TESTS_C= acct_test
diff --git a/tests/sys/kern/execve/Makefile b/tests/sys/kern/execve/Makefile
index 82c5d4b85b10..a029b8f88bc0 100644
--- a/tests/sys/kern/execve/Makefile
+++ b/tests/sys/kern/execve/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/kern/execve
BINDIR= ${TESTSDIR}
diff --git a/tests/sys/kern/pipe/Makefile b/tests/sys/kern/pipe/Makefile
index bcd2d070cc8b..bcc61b4a0e5b 100644
--- a/tests/sys/kern/pipe/Makefile
+++ b/tests/sys/kern/pipe/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/kern/pipe
PLAIN_TESTS_C+= big_pipe_test
diff --git a/tests/sys/kqueue/Makefile b/tests/sys/kqueue/Makefile
index 43277ca0c86b..2ec462a625e9 100644
--- a/tests/sys/kqueue/Makefile
+++ b/tests/sys/kqueue/Makefile
@@ -6,6 +6,9 @@
# libkqueue and test suite by Mark Heily <mark@heily.com>
#
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TAP_TESTS_SH= kqueue_test
TESTSDIR= ${TESTSBASE}/sys/kqueue
diff --git a/tests/sys/mac/Makefile b/tests/sys/mac/Makefile
index ae2c4917b0d1..db9189560242 100644
--- a/tests/sys/mac/Makefile
+++ b/tests/sys/mac/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/mac
TESTS_SUBDIRS+= bsdextended
diff --git a/tests/sys/mac/bsdextended/Makefile b/tests/sys/mac/bsdextended/Makefile
index 9d0b6f6907ca..8fdee52c2fc4 100644
--- a/tests/sys/mac/bsdextended/Makefile
+++ b/tests/sys/mac/bsdextended/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/mac/bsdextended
TAP_TESTS_C+= ugidfw_test
diff --git a/tests/sys/mac/portacl/Makefile b/tests/sys/mac/portacl/Makefile
index 129d4867cc99..b894c8c517df 100644
--- a/tests/sys/mac/portacl/Makefile
+++ b/tests/sys/mac/portacl/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/mac/portacl
BINDIR= ${TESTSDIR}
diff --git a/tests/sys/mqueue/Makefile b/tests/sys/mqueue/Makefile
index ce5033c6a683..6ccd2758916d 100644
--- a/tests/sys/mqueue/Makefile
+++ b/tests/sys/mqueue/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/mqueue
ATF_TESTS_SH= mqueue_test
diff --git a/tests/sys/netinet/Makefile b/tests/sys/netinet/Makefile
index 3f65fb6b3e98..4fe29224ee0e 100644
--- a/tests/sys/netinet/Makefile
+++ b/tests/sys/netinet/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/netinet
BINDIR= ${TESTSDIR}
diff --git a/tests/sys/opencrypto/Makefile b/tests/sys/opencrypto/Makefile
index 1696920ac35f..96cc86b44ffd 100644
--- a/tests/sys/opencrypto/Makefile
+++ b/tests/sys/opencrypto/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/opencrypto
BINDIR= ${TESTSDIR}
diff --git a/tests/sys/pjdfstest/Makefile b/tests/sys/pjdfstest/Makefile
index a398d394ea2d..65f562a27013 100644
--- a/tests/sys/pjdfstest/Makefile
+++ b/tests/sys/pjdfstest/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
SUBDIR+= pjdfstest
SUBDIR+= tests
SUBDIR_PARALLEL=
diff --git a/tests/sys/pjdfstest/pjdfstest/Makefile b/tests/sys/pjdfstest/pjdfstest/Makefile
index 29bee82e8ba3..8ae74e7959b9 100644
--- a/tests/sys/pjdfstest/pjdfstest/Makefile
+++ b/tests/sys/pjdfstest/pjdfstest/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TOP= ${.CURDIR:H:H:H:H}
.PATH: ${TOP}/contrib/pjdfstest
diff --git a/tests/sys/pjdfstest/tests/Makefile b/tests/sys/pjdfstest/tests/Makefile
index 95b4bbe29b41..951ac9a7c031 100644
--- a/tests/sys/pjdfstest/tests/Makefile
+++ b/tests/sys/pjdfstest/tests/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
PJDFSTEST_SRCDIR= ${SRCTOP}/contrib/pjdfstest
TESTSDIR= ${TESTSBASE}/sys/pjdfstest
diff --git a/tests/sys/pjdfstest/tests/chflags/Makefile b/tests/sys/pjdfstest/tests/chflags/Makefile
index 3b6a5265fdd4..2865f9da704e 100644
--- a/tests/sys/pjdfstest/tests/chflags/Makefile
+++ b/tests/sys/pjdfstest/tests/chflags/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/chmod/Makefile b/tests/sys/pjdfstest/tests/chmod/Makefile
index cc0a3bbf1af4..10227c14012d 100644
--- a/tests/sys/pjdfstest/tests/chmod/Makefile
+++ b/tests/sys/pjdfstest/tests/chmod/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/chown/Makefile b/tests/sys/pjdfstest/tests/chown/Makefile
index 665b6538d19e..f8fa004908c1 100644
--- a/tests/sys/pjdfstest/tests/chown/Makefile
+++ b/tests/sys/pjdfstest/tests/chown/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/ftruncate/Makefile b/tests/sys/pjdfstest/tests/ftruncate/Makefile
index da2ce584d3af..67570a831e31 100644
--- a/tests/sys/pjdfstest/tests/ftruncate/Makefile
+++ b/tests/sys/pjdfstest/tests/ftruncate/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/granular/Makefile b/tests/sys/pjdfstest/tests/granular/Makefile
index 3f935e4e99ce..4f0d071622e8 100644
--- a/tests/sys/pjdfstest/tests/granular/Makefile
+++ b/tests/sys/pjdfstest/tests/granular/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/link/Makefile b/tests/sys/pjdfstest/tests/link/Makefile
index 14c7525689b0..af74c4a0fa2f 100644
--- a/tests/sys/pjdfstest/tests/link/Makefile
+++ b/tests/sys/pjdfstest/tests/link/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/mkdir/Makefile b/tests/sys/pjdfstest/tests/mkdir/Makefile
index cc0a3bbf1af4..10227c14012d 100644
--- a/tests/sys/pjdfstest/tests/mkdir/Makefile
+++ b/tests/sys/pjdfstest/tests/mkdir/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/mkfifo/Makefile b/tests/sys/pjdfstest/tests/mkfifo/Makefile
index cc0a3bbf1af4..10227c14012d 100644
--- a/tests/sys/pjdfstest/tests/mkfifo/Makefile
+++ b/tests/sys/pjdfstest/tests/mkfifo/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/mknod/Makefile b/tests/sys/pjdfstest/tests/mknod/Makefile
index 1eaeaa09818e..fd4152222c80 100644
--- a/tests/sys/pjdfstest/tests/mknod/Makefile
+++ b/tests/sys/pjdfstest/tests/mknod/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/open/Makefile b/tests/sys/pjdfstest/tests/open/Makefile
index bd2f7b5a985d..c66cc3e3d301 100644
--- a/tests/sys/pjdfstest/tests/open/Makefile
+++ b/tests/sys/pjdfstest/tests/open/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/rename/Makefile b/tests/sys/pjdfstest/tests/rename/Makefile
index 7eada047ef15..86984d99b1cb 100644
--- a/tests/sys/pjdfstest/tests/rename/Makefile
+++ b/tests/sys/pjdfstest/tests/rename/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/rmdir/Makefile b/tests/sys/pjdfstest/tests/rmdir/Makefile
index 301e4e5c33d1..31fd8ba8d0ff 100644
--- a/tests/sys/pjdfstest/tests/rmdir/Makefile
+++ b/tests/sys/pjdfstest/tests/rmdir/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/symlink/Makefile b/tests/sys/pjdfstest/tests/symlink/Makefile
index cc0a3bbf1af4..10227c14012d 100644
--- a/tests/sys/pjdfstest/tests/symlink/Makefile
+++ b/tests/sys/pjdfstest/tests/symlink/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/truncate/Makefile b/tests/sys/pjdfstest/tests/truncate/Makefile
index da2ce584d3af..67570a831e31 100644
--- a/tests/sys/pjdfstest/tests/truncate/Makefile
+++ b/tests/sys/pjdfstest/tests/truncate/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/pjdfstest/tests/unlink/Makefile b/tests/sys/pjdfstest/tests/unlink/Makefile
index 3b6a5265fdd4..2865f9da704e 100644
--- a/tests/sys/pjdfstest/tests/unlink/Makefile
+++ b/tests/sys/pjdfstest/tests/unlink/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= 00
TAP_TESTS_SH+= 01
TAP_TESTS_SH+= 02
diff --git a/tests/sys/posixshm/Makefile b/tests/sys/posixshm/Makefile
index 2acdfa4f64b5..aab71d1adddc 100644
--- a/tests/sys/posixshm/Makefile
+++ b/tests/sys/posixshm/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/posixshm
ATF_TESTS_C+= posixshm_test
diff --git a/tests/sys/vfs/Makefile b/tests/sys/vfs/Makefile
index 48f522634bfa..09e451871783 100644
--- a/tests/sys/vfs/Makefile
+++ b/tests/sys/vfs/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/vfs
PLAIN_TESTS_SH+= trailing_slash
diff --git a/tests/sys/vm/Makefile b/tests/sys/vm/Makefile
index 08fbb2159c63..9d1be8b389a4 100644
--- a/tests/sys/vm/Makefile
+++ b/tests/sys/vm/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/sys/vm
ATF_TESTS_C+= mmap_test
diff --git a/usr.bin/apply/tests/Makefile b/usr.bin/apply/tests/Makefile
index 5ff6c28e968e..6348f89c19a9 100644
--- a/usr.bin/apply/tests/Makefile
+++ b/usr.bin/apply/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
TAP_TESTS_SH= legacy_test
FILESDIR= ${TESTSDIR}
diff --git a/usr.bin/at/Makefile.inc b/usr.bin/at/Makefile.inc
index 2dab559532f7..3bd437374fa6 100644
--- a/usr.bin/at/Makefile.inc
+++ b/usr.bin/at/Makefile.inc
@@ -10,6 +10,7 @@ DAEMON_UID=1
DEFAULT_BATCH_QUEUE=E
DEFAULT_AT_QUEUE=c
PERM_PATH=/var/at
+PACKAGE= at
CFLAGS += -DATJOB_DIR=\"$(ATJOB_DIR)/\" \
-DLFILE=\"$(ATJOB_DIR)/$(LOCKFILE)\" \
diff --git a/usr.bin/basename/tests/Makefile b/usr.bin/basename/tests/Makefile
index bad7b2890432..cada2f7c3c03 100644
--- a/usr.bin/basename/tests/Makefile
+++ b/usr.bin/basename/tests/Makefile
@@ -1,5 +1,9 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
+
NETBSD_ATF_TESTS_SH= basename_test
.include <netbsd-tests.test.mk>
diff --git a/usr.bin/bmake/tests/Makefile b/usr.bin/bmake/tests/Makefile
index e22503467aa0..ee3dcf2f3968 100644
--- a/usr.bin/bmake/tests/Makefile
+++ b/usr.bin/bmake/tests/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake
FILESDIR= ${TESTSDIR}
diff --git a/usr.bin/bmake/tests/archives/Makefile b/usr.bin/bmake/tests/archives/Makefile
index f80ffc2e8989..c8914b94942f 100644
--- a/usr.bin/bmake/tests/archives/Makefile
+++ b/usr.bin/bmake/tests/archives/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/archives
TESTS_SUBDIRS= fmt_44bsd fmt_44bsd_mod fmt_oldbsd
diff --git a/usr.bin/bmake/tests/archives/fmt_44bsd/Makefile b/usr.bin/bmake/tests/archives/fmt_44bsd/Makefile
index 15389c802772..5ef093f61708 100644
--- a/usr.bin/bmake/tests/archives/fmt_44bsd/Makefile
+++ b/usr.bin/bmake/tests/archives/fmt_44bsd/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/archives/fmt_44bsd
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/archives/fmt_44bsd_mod/Makefile b/usr.bin/bmake/tests/archives/fmt_44bsd_mod/Makefile
index 1d2f6e272cdc..0b9db19071fd 100644
--- a/usr.bin/bmake/tests/archives/fmt_44bsd_mod/Makefile
+++ b/usr.bin/bmake/tests/archives/fmt_44bsd_mod/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/archives/fmt_44bsd_mod
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/archives/fmt_oldbsd/Makefile b/usr.bin/bmake/tests/archives/fmt_oldbsd/Makefile
index 2a96124193ca..b76bdc19164e 100644
--- a/usr.bin/bmake/tests/archives/fmt_oldbsd/Makefile
+++ b/usr.bin/bmake/tests/archives/fmt_oldbsd/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/archives/fmt_oldbsd
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/basic/Makefile b/usr.bin/bmake/tests/basic/Makefile
index 56dfb33901c0..1164a44674bd 100644
--- a/usr.bin/bmake/tests/basic/Makefile
+++ b/usr.bin/bmake/tests/basic/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/basic
TESTS_SUBDIRS= t0 t1 t2 t3
diff --git a/usr.bin/bmake/tests/basic/t0/Makefile b/usr.bin/bmake/tests/basic/t0/Makefile
index 12356596e374..d1ee84d9a5b3 100644
--- a/usr.bin/bmake/tests/basic/t0/Makefile
+++ b/usr.bin/bmake/tests/basic/t0/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/basic/t0
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/basic/t1/Makefile b/usr.bin/bmake/tests/basic/t1/Makefile
index 732dc65d91af..3faeffab7764 100644
--- a/usr.bin/bmake/tests/basic/t1/Makefile
+++ b/usr.bin/bmake/tests/basic/t1/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/basic/t1
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/basic/t2/Makefile b/usr.bin/bmake/tests/basic/t2/Makefile
index 58c36ff96f8d..6d7b6b494c43 100644
--- a/usr.bin/bmake/tests/basic/t2/Makefile
+++ b/usr.bin/bmake/tests/basic/t2/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/basic/t2
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/basic/t3/Makefile b/usr.bin/bmake/tests/basic/t3/Makefile
index a173414588cb..2b268e92f506 100644
--- a/usr.bin/bmake/tests/basic/t3/Makefile
+++ b/usr.bin/bmake/tests/basic/t3/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/basic/t3
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/execution/Makefile b/usr.bin/bmake/tests/execution/Makefile
index 2c91bbba23ea..5b3bab7b76fd 100644
--- a/usr.bin/bmake/tests/execution/Makefile
+++ b/usr.bin/bmake/tests/execution/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/execution
TESTS_SUBDIRS= ellipsis empty joberr plus
diff --git a/usr.bin/bmake/tests/execution/ellipsis/Makefile b/usr.bin/bmake/tests/execution/ellipsis/Makefile
index 5629b4bb0018..abc8b9e496e9 100644
--- a/usr.bin/bmake/tests/execution/ellipsis/Makefile
+++ b/usr.bin/bmake/tests/execution/ellipsis/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/execution/ellipsis
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/execution/empty/Makefile b/usr.bin/bmake/tests/execution/empty/Makefile
index 6421b9620e9e..282814036f20 100644
--- a/usr.bin/bmake/tests/execution/empty/Makefile
+++ b/usr.bin/bmake/tests/execution/empty/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/execution/empty
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/execution/joberr/Makefile b/usr.bin/bmake/tests/execution/joberr/Makefile
index d183eb1347d4..7056afdb1653 100644
--- a/usr.bin/bmake/tests/execution/joberr/Makefile
+++ b/usr.bin/bmake/tests/execution/joberr/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/execution/joberr
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/execution/plus/Makefile b/usr.bin/bmake/tests/execution/plus/Makefile
index 8b489d56c6cf..c5e42bd385a4 100644
--- a/usr.bin/bmake/tests/execution/plus/Makefile
+++ b/usr.bin/bmake/tests/execution/plus/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/execution/plus
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/shell/Makefile b/usr.bin/bmake/tests/shell/Makefile
index 13b570ea64db..ca0c99f1aa4c 100644
--- a/usr.bin/bmake/tests/shell/Makefile
+++ b/usr.bin/bmake/tests/shell/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/shell
TESTS_SUBDIRS= builtin meta path path_select replace select
diff --git a/usr.bin/bmake/tests/shell/builtin/Makefile b/usr.bin/bmake/tests/shell/builtin/Makefile
index cd458a973e50..713e8256315d 100644
--- a/usr.bin/bmake/tests/shell/builtin/Makefile
+++ b/usr.bin/bmake/tests/shell/builtin/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/shell/builtin
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/shell/meta/Makefile b/usr.bin/bmake/tests/shell/meta/Makefile
index b342e79e3cf3..4b14289a9b1b 100644
--- a/usr.bin/bmake/tests/shell/meta/Makefile
+++ b/usr.bin/bmake/tests/shell/meta/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/shell/meta
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/shell/path/Makefile b/usr.bin/bmake/tests/shell/path/Makefile
index 5a83a1ff6adc..8b1ce86794b2 100644
--- a/usr.bin/bmake/tests/shell/path/Makefile
+++ b/usr.bin/bmake/tests/shell/path/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/shell/path
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/shell/path_select/Makefile b/usr.bin/bmake/tests/shell/path_select/Makefile
index 1819f910a12a..acc63395abc5 100644
--- a/usr.bin/bmake/tests/shell/path_select/Makefile
+++ b/usr.bin/bmake/tests/shell/path_select/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/shell/path_select
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/shell/replace/Makefile b/usr.bin/bmake/tests/shell/replace/Makefile
index 0dae9154bf33..b0f21ab5e747 100644
--- a/usr.bin/bmake/tests/shell/replace/Makefile
+++ b/usr.bin/bmake/tests/shell/replace/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/shell/replace
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/shell/select/Makefile b/usr.bin/bmake/tests/shell/select/Makefile
index 45e6d72b6cde..e62701000031 100644
--- a/usr.bin/bmake/tests/shell/select/Makefile
+++ b/usr.bin/bmake/tests/shell/select/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/shell/select
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/suffixes/Makefile b/usr.bin/bmake/tests/suffixes/Makefile
index 60ec86e7e5ee..0839dfab3742 100644
--- a/usr.bin/bmake/tests/suffixes/Makefile
+++ b/usr.bin/bmake/tests/suffixes/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/suffixes
TESTS_SUBDIRS= basic src_wild1 src_wild2
diff --git a/usr.bin/bmake/tests/suffixes/basic/Makefile b/usr.bin/bmake/tests/suffixes/basic/Makefile
index 9ae720ee8275..d917de0c0f21 100644
--- a/usr.bin/bmake/tests/suffixes/basic/Makefile
+++ b/usr.bin/bmake/tests/suffixes/basic/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/suffixes/basic
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/suffixes/src_wild1/Makefile b/usr.bin/bmake/tests/suffixes/src_wild1/Makefile
index 00be930047c1..621ec60ce75d 100644
--- a/usr.bin/bmake/tests/suffixes/src_wild1/Makefile
+++ b/usr.bin/bmake/tests/suffixes/src_wild1/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/suffixes/src_wild1
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/suffixes/src_wild2/Makefile b/usr.bin/bmake/tests/suffixes/src_wild2/Makefile
index 34aad07fcdc1..a1c65351933b 100644
--- a/usr.bin/bmake/tests/suffixes/src_wild2/Makefile
+++ b/usr.bin/bmake/tests/suffixes/src_wild2/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/suffixes/src_wild2
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/syntax/Makefile b/usr.bin/bmake/tests/syntax/Makefile
index 3cd89f84428f..2dd0df5995ce 100644
--- a/usr.bin/bmake/tests/syntax/Makefile
+++ b/usr.bin/bmake/tests/syntax/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/syntax
TESTS_SUBDIRS= directive-t0 enl funny-targets semi
diff --git a/usr.bin/bmake/tests/syntax/directive-t0/Makefile b/usr.bin/bmake/tests/syntax/directive-t0/Makefile
index 66e1f3253a02..e790b942f6d2 100644
--- a/usr.bin/bmake/tests/syntax/directive-t0/Makefile
+++ b/usr.bin/bmake/tests/syntax/directive-t0/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/syntax/directive-t0
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/syntax/enl/Makefile b/usr.bin/bmake/tests/syntax/enl/Makefile
index 743e88fb49fc..0ba16a788c12 100644
--- a/usr.bin/bmake/tests/syntax/enl/Makefile
+++ b/usr.bin/bmake/tests/syntax/enl/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/syntax/enl
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/syntax/funny-targets/Makefile b/usr.bin/bmake/tests/syntax/funny-targets/Makefile
index 53a3e4d762db..3e56b2b76a8e 100644
--- a/usr.bin/bmake/tests/syntax/funny-targets/Makefile
+++ b/usr.bin/bmake/tests/syntax/funny-targets/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/syntax/funny-targets
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/syntax/semi/Makefile b/usr.bin/bmake/tests/syntax/semi/Makefile
index 00a7f1e94e34..cb57bbc71efe 100644
--- a/usr.bin/bmake/tests/syntax/semi/Makefile
+++ b/usr.bin/bmake/tests/syntax/semi/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/syntax/semi
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/sysmk/Makefile b/usr.bin/bmake/tests/sysmk/Makefile
index 90d90f1ddbd4..8dccb0359d7c 100644
--- a/usr.bin/bmake/tests/sysmk/Makefile
+++ b/usr.bin/bmake/tests/sysmk/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/sysmk
TESTS_SUBDIRS= t0 t1 t2
diff --git a/usr.bin/bmake/tests/sysmk/t0/2/1/Makefile b/usr.bin/bmake/tests/sysmk/t0/2/1/Makefile
index 5578a9b90d23..87e6827d57fd 100644
--- a/usr.bin/bmake/tests/sysmk/t0/2/1/Makefile
+++ b/usr.bin/bmake/tests/sysmk/t0/2/1/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/sysmk/t0/2/1
TAP_TESTS_SH= legacy_test
diff --git a/usr.bin/bmake/tests/sysmk/t0/2/Makefile b/usr.bin/bmake/tests/sysmk/t0/2/Makefile
index 22048078844b..2a6fc75df7e8 100644
--- a/usr.bin/bmake/tests/sysmk/t0/2/Makefile
+++ b/usr.bin/bmake/tests/sysmk/t0/2/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/sysmk/t0/2
TESTS_SUBDIRS= 1
diff --git a/usr.bin/bmake/tests/sysmk/t0/Makefile b/usr.bin/bmake/tests/sysmk/t0/Makefile
index f38383c4e893..d31d5619f65e 100644
--- a/usr.bin/bmake/tests/sysmk/t0/Makefile
+++ b/usr.bin/bmake/tests/sysmk/t0/Makefile
@@ -1,5 +1,8 @@
# $FreeBSD$
+PACKAGE= tests
+FILESGROUPS= TESTS
+TESTSPACKAGE= ${PACKAGE}
TESTSDIR= ${TESTSBASE}/usr.bin/bmake/sysmk/t0
TESTS_SUBDIRS= 2
diff --git a/usr.bin/bmake/tests/sysmk/t0/mk/Makefile b/usr.bin/bmake/tests/sysmk/t0/mk/Makefile
index be1bd5a2ff46