summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2013-09-05 20:18:59 +0000
committersjg <sjg@FreeBSD.org>2013-09-05 20:18:59 +0000
commit62bb1062226d3ce6a2350808256a25508978352d (patch)
tree22b131dceb13c3df96da594fbaadb693504797c7 /usr.sbin
parent72ab90509b3a51ab361bf710338f2ef44a4e360d (diff)
parent04932445481c2cb89ff69a83b961bdef3d64757e (diff)
downloadFreeBSD-src-62bb1062226d3ce6a2350808256a25508978352d.zip
FreeBSD-src-62bb1062226d3ce6a2350808256a25508978352d.tar.gz
Merge from head
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/Makefile8
-rw-r--r--usr.sbin/Makefile.amd641
-rw-r--r--usr.sbin/Makefile.i3861
-rw-r--r--usr.sbin/Makefile.ia641
-rw-r--r--usr.sbin/Makefile.powerpc1
-rw-r--r--usr.sbin/Makefile.sparc641
-rw-r--r--usr.sbin/acpi/acpidb/Makefile27
-rw-r--r--usr.sbin/acpi/acpidb/acpidb.c17
-rw-r--r--usr.sbin/acpi/acpidump/acpi.c16
-rw-r--r--usr.sbin/acpi/acpidump/acpi_user.c2
-rw-r--r--usr.sbin/acpi/iasl/Makefile35
-rw-r--r--usr.sbin/apmd/apmdlex.l8
-rw-r--r--usr.sbin/arp/arp.46
-rw-r--r--usr.sbin/auditdistd/Makefile1
-rw-r--r--usr.sbin/authpf/Makefile3
-rw-r--r--usr.sbin/bhyve/Makefile2
-rw-r--r--usr.sbin/bhyve/atpic.c17
-rw-r--r--usr.sbin/bhyve/bhyverun.c36
-rw-r--r--usr.sbin/bhyve/pci_emul.c177
-rw-r--r--usr.sbin/bhyve/pci_emul.h4
-rw-r--r--usr.sbin/bhyve/pci_virtio_block.c475
-rw-r--r--usr.sbin/bhyve/pci_virtio_net.c850
-rw-r--r--usr.sbin/bhyve/rtc.c90
-rw-r--r--usr.sbin/bhyve/rtc.h34
-rw-r--r--usr.sbin/bhyve/virtio.c745
-rw-r--r--usr.sbin/bhyve/virtio.h398
-rw-r--r--usr.sbin/bluetooth/bthidd/Makefile2
-rw-r--r--usr.sbin/bluetooth/bthidd/lexer.l2
-rw-r--r--usr.sbin/bluetooth/hccontrol/link_control.c2
-rw-r--r--usr.sbin/boot98cfg/boot98cfg.c2
-rw-r--r--usr.sbin/bootparamd/bootparamd/bootparamd.82
-rw-r--r--usr.sbin/bsdconfig/Makefile1
-rw-r--r--usr.sbin/bsdconfig/USAGE12
-rwxr-xr-xusr.sbin/bsdconfig/bsdconfig195
-rw-r--r--usr.sbin/bsdconfig/bsdconfig.8109
-rw-r--r--usr.sbin/bsdconfig/console/INDEX38
-rw-r--r--usr.sbin/bsdconfig/console/USAGE14
-rwxr-xr-xusr.sbin/bsdconfig/console/console82
-rwxr-xr-xusr.sbin/bsdconfig/console/font191
-rw-r--r--usr.sbin/bsdconfig/console/include/messages.subr10
-rwxr-xr-xusr.sbin/bsdconfig/console/keymap371
-rwxr-xr-xusr.sbin/bsdconfig/console/repeat93
-rwxr-xr-xusr.sbin/bsdconfig/console/saver191
-rwxr-xr-xusr.sbin/bsdconfig/console/screenmap107
-rwxr-xr-xusr.sbin/bsdconfig/console/ttys108
-rw-r--r--usr.sbin/bsdconfig/diskmgmt/INDEX38
-rw-r--r--usr.sbin/bsdconfig/diskmgmt/USAGE14
-rwxr-xr-xusr.sbin/bsdconfig/diskmgmt/diskmgmt16
-rw-r--r--usr.sbin/bsdconfig/docsinstall/INDEX38
-rw-r--r--usr.sbin/bsdconfig/docsinstall/USAGE14
-rwxr-xr-xusr.sbin/bsdconfig/docsinstall/docsinstall12
-rw-r--r--usr.sbin/bsdconfig/dot/INDEX38
-rw-r--r--usr.sbin/bsdconfig/dot/USAGE10
-rwxr-xr-xusr.sbin/bsdconfig/dot/dot78
-rw-r--r--usr.sbin/bsdconfig/examples/Makefile2
-rwxr-xr-xusr.sbin/bsdconfig/examples/browse_packages.sh26
-rw-r--r--usr.sbin/bsdconfig/examples/bsdconfigrc14
-rw-r--r--usr.sbin/bsdconfig/include/media.hlp16
-rw-r--r--usr.sbin/bsdconfig/include/messages.subr188
-rw-r--r--usr.sbin/bsdconfig/include/options.hlp17
-rw-r--r--usr.sbin/bsdconfig/mouse/INDEX38
-rw-r--r--usr.sbin/bsdconfig/mouse/USAGE14
-rwxr-xr-xusr.sbin/bsdconfig/mouse/disable25
-rwxr-xr-xusr.sbin/bsdconfig/mouse/enable12
-rwxr-xr-xusr.sbin/bsdconfig/mouse/flags17
-rw-r--r--usr.sbin/bsdconfig/mouse/include/messages.subr5
-rwxr-xr-xusr.sbin/bsdconfig/mouse/mouse83
-rwxr-xr-xusr.sbin/bsdconfig/mouse/port108
-rwxr-xr-xusr.sbin/bsdconfig/mouse/type132
-rw-r--r--usr.sbin/bsdconfig/networking/INDEX38
-rw-r--r--usr.sbin/bsdconfig/networking/USAGE14
-rwxr-xr-xusr.sbin/bsdconfig/networking/defaultrouter12
-rwxr-xr-xusr.sbin/bsdconfig/networking/devices69
-rwxr-xr-xusr.sbin/bsdconfig/networking/hostname15
-rw-r--r--usr.sbin/bsdconfig/networking/include/messages.subr3
-rwxr-xr-xusr.sbin/bsdconfig/networking/nameservers15
-rwxr-xr-xusr.sbin/bsdconfig/networking/networking104
-rw-r--r--usr.sbin/bsdconfig/networking/share/Makefile2
-rw-r--r--usr.sbin/bsdconfig/networking/share/common.subr6
-rw-r--r--usr.sbin/bsdconfig/networking/share/device.subr105
-rw-r--r--usr.sbin/bsdconfig/networking/share/hostname.subr24
-rw-r--r--usr.sbin/bsdconfig/networking/share/ipaddr.subr33
-rw-r--r--usr.sbin/bsdconfig/networking/share/media.subr54
-rw-r--r--usr.sbin/bsdconfig/networking/share/netmask.subr27
-rw-r--r--usr.sbin/bsdconfig/networking/share/resolv.subr72
-rw-r--r--usr.sbin/bsdconfig/networking/share/routing.subr19
-rw-r--r--usr.sbin/bsdconfig/networking/share/services.subr54
-rw-r--r--usr.sbin/bsdconfig/packages/INDEX56
-rw-r--r--usr.sbin/bsdconfig/packages/Makefile16
-rw-r--r--usr.sbin/bsdconfig/packages/USAGE37
-rw-r--r--usr.sbin/bsdconfig/packages/include/Makefile11
-rwxr-xr-xusr.sbin/bsdconfig/packages/include/messages.subr27
-rwxr-xr-xusr.sbin/bsdconfig/packages/packages80
-rw-r--r--usr.sbin/bsdconfig/password/INDEX38
-rw-r--r--usr.sbin/bsdconfig/password/USAGE14
-rw-r--r--usr.sbin/bsdconfig/password/include/messages.subr4
-rwxr-xr-xusr.sbin/bsdconfig/password/password17
-rw-r--r--usr.sbin/bsdconfig/password/share/password.subr100
-rw-r--r--usr.sbin/bsdconfig/security/INDEX38
-rw-r--r--usr.sbin/bsdconfig/security/USAGE14
-rw-r--r--usr.sbin/bsdconfig/security/include/messages.subr4
-rwxr-xr-xusr.sbin/bsdconfig/security/kern_securelevel62
-rwxr-xr-xusr.sbin/bsdconfig/security/security119
-rw-r--r--usr.sbin/bsdconfig/share/Makefile2
-rw-r--r--usr.sbin/bsdconfig/share/common.subr181
-rw-r--r--usr.sbin/bsdconfig/share/device.subr53
-rw-r--r--usr.sbin/bsdconfig/share/dialog.subr2159
-rw-r--r--usr.sbin/bsdconfig/share/media/Makefile4
-rw-r--r--usr.sbin/bsdconfig/share/media/any.subr74
-rw-r--r--usr.sbin/bsdconfig/share/media/cdrom.subr28
-rw-r--r--usr.sbin/bsdconfig/share/media/common.subr64
-rw-r--r--usr.sbin/bsdconfig/share/media/directory.subr25
-rw-r--r--usr.sbin/bsdconfig/share/media/dos.subr26
-rw-r--r--usr.sbin/bsdconfig/share/media/floppy.subr38
-rw-r--r--usr.sbin/bsdconfig/share/media/ftp.subr211
-rw-r--r--usr.sbin/bsdconfig/share/media/http.subr646
-rw-r--r--usr.sbin/bsdconfig/share/media/httpproxy.subr74
-rw-r--r--usr.sbin/bsdconfig/share/media/network.subr10
-rw-r--r--usr.sbin/bsdconfig/share/media/nfs.subr35
-rw-r--r--usr.sbin/bsdconfig/share/media/options.subr116
-rw-r--r--usr.sbin/bsdconfig/share/media/tcpip.subr83
-rw-r--r--usr.sbin/bsdconfig/share/media/ufs.subr24
-rw-r--r--usr.sbin/bsdconfig/share/media/usb.subr28
-rw-r--r--usr.sbin/bsdconfig/share/mustberoot.subr110
-rw-r--r--usr.sbin/bsdconfig/share/packages/Makefile11
-rwxr-xr-xusr.sbin/bsdconfig/share/packages/categories.subr207
-rwxr-xr-xusr.sbin/bsdconfig/share/packages/index.subr287
-rwxr-xr-xusr.sbin/bsdconfig/share/packages/packages.subr1202
-rw-r--r--usr.sbin/bsdconfig/share/script.subr70
-rw-r--r--usr.sbin/bsdconfig/share/strings.subr160
-rw-r--r--usr.sbin/bsdconfig/share/struct.subr6
-rw-r--r--usr.sbin/bsdconfig/share/sysrc.subr8
-rw-r--r--usr.sbin/bsdconfig/share/variable.subr48
-rw-r--r--usr.sbin/bsdconfig/startup/INDEX38
-rw-r--r--usr.sbin/bsdconfig/startup/USAGE14
-rw-r--r--usr.sbin/bsdconfig/startup/include/messages.subr12
-rwxr-xr-xusr.sbin/bsdconfig/startup/misc372
-rwxr-xr-xusr.sbin/bsdconfig/startup/rcadd85
-rwxr-xr-xusr.sbin/bsdconfig/startup/rcconf79
-rwxr-xr-xusr.sbin/bsdconfig/startup/rcdelete234
-rwxr-xr-xusr.sbin/bsdconfig/startup/rcedit9
-rwxr-xr-xusr.sbin/bsdconfig/startup/rcvar105
-rw-r--r--usr.sbin/bsdconfig/startup/share/rcconf.subr183
-rw-r--r--usr.sbin/bsdconfig/startup/share/rcedit.subr5
-rw-r--r--usr.sbin/bsdconfig/startup/share/rcvar.subr82
-rwxr-xr-xusr.sbin/bsdconfig/startup/startup77
-rw-r--r--usr.sbin/bsdconfig/timezone/INDEX38
-rw-r--r--usr.sbin/bsdconfig/timezone/USAGE14
-rw-r--r--usr.sbin/bsdconfig/timezone/share/continents.subr6
-rw-r--r--usr.sbin/bsdconfig/timezone/share/countries.subr6
-rw-r--r--usr.sbin/bsdconfig/timezone/share/iso3166.subr6
-rw-r--r--usr.sbin/bsdconfig/timezone/share/menus.subr6
-rw-r--r--usr.sbin/bsdconfig/timezone/share/zones.subr308
-rwxr-xr-xusr.sbin/bsdconfig/timezone/timezone156
-rw-r--r--usr.sbin/bsdconfig/ttys/INDEX38
-rw-r--r--usr.sbin/bsdconfig/ttys/USAGE14
-rwxr-xr-xusr.sbin/bsdconfig/ttys/ttys12
-rw-r--r--usr.sbin/bsdconfig/usermgmt/INDEX38
-rw-r--r--usr.sbin/bsdconfig/usermgmt/USAGE14
-rwxr-xr-xusr.sbin/bsdconfig/usermgmt/groupadd6
-rwxr-xr-xusr.sbin/bsdconfig/usermgmt/groupdel23
-rwxr-xr-xusr.sbin/bsdconfig/usermgmt/groupedit23
-rwxr-xr-xusr.sbin/bsdconfig/usermgmt/groupinput72
-rw-r--r--usr.sbin/bsdconfig/usermgmt/include/messages.subr5
-rw-r--r--usr.sbin/bsdconfig/usermgmt/share/group_input.subr247
-rw-r--r--usr.sbin/bsdconfig/usermgmt/share/user_input.subr514
-rwxr-xr-xusr.sbin/bsdconfig/usermgmt/useradd6
-rwxr-xr-xusr.sbin/bsdconfig/usermgmt/userdel23
-rwxr-xr-xusr.sbin/bsdconfig/usermgmt/useredit23
-rwxr-xr-xusr.sbin/bsdconfig/usermgmt/userinput136
-rwxr-xr-xusr.sbin/bsdconfig/usermgmt/usermgmt105
-rw-r--r--usr.sbin/bsdinstall/distextract/Makefile1
-rw-r--r--usr.sbin/bsdinstall/distfetch/Makefile1
-rw-r--r--usr.sbin/bsdinstall/partedit/Makefile1
-rw-r--r--usr.sbin/bsdinstall/partedit/diskeditor.c18
-rwxr-xr-xusr.sbin/bsdinstall/scripts/mirrorselect48
-rw-r--r--usr.sbin/bsnmpd/modules/Makefile1
-rw-r--r--usr.sbin/bsnmpd/modules/Makefile.inc2
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_hast/BEGEMOT-HAST-MIB.txt310
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_hast/Makefile43
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_hast/hast_snmp.c511
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_hast/hast_tree.def71
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_hast/snmp_hast.369
-rw-r--r--usr.sbin/config/Makefile2
-rw-r--r--usr.sbin/config/lang.l8
-rw-r--r--usr.sbin/config/main.c14
-rwxr-xr-xusr.sbin/crashinfo/crashinfo.sh4
-rw-r--r--usr.sbin/ctladm/ctladm.c6
-rw-r--r--usr.sbin/dnssec-verify/Makefile25
-rw-r--r--usr.sbin/dumpcis/printcis.c2
-rw-r--r--usr.sbin/fifolog/lib/Makefile2
-rw-r--r--usr.sbin/freebsd-update/freebsd-update.84
-rw-r--r--usr.sbin/gssd/gssd.832
-rw-r--r--usr.sbin/gssd/gssd.c393
-rw-r--r--usr.sbin/jail/Makefile2
-rw-r--r--usr.sbin/jail/jail.810
-rw-r--r--usr.sbin/jail/jaillex.l8
-rw-r--r--usr.sbin/jls/jls.88
-rw-r--r--usr.sbin/jls/jls.c32
-rw-r--r--usr.sbin/kbdcontrol/lex.l5
-rw-r--r--usr.sbin/kldxref/ef.c1
-rw-r--r--usr.sbin/kldxref/ef_amd64.c1
-rw-r--r--usr.sbin/kldxref/ef_i386.c1
-rw-r--r--usr.sbin/kldxref/ef_obj.c4
-rw-r--r--usr.sbin/kldxref/kldxref.c1
-rw-r--r--usr.sbin/lpr/common_source/common.c20
-rw-r--r--usr.sbin/lpr/common_source/lp.cdefs.h17
-rw-r--r--usr.sbin/makefs/Makefile22
-rw-r--r--usr.sbin/makefs/cd9660.c5
-rw-r--r--usr.sbin/makefs/cd9660/iso9660_rrip.c8
-rw-r--r--usr.sbin/makefs/compat/Makefile.inc8
-rw-r--r--usr.sbin/makefs/compat/pwcache.c616
-rw-r--r--usr.sbin/makefs/compat/pwcache.h73
-rw-r--r--usr.sbin/makefs/compat/strsuftoll.c222
-rw-r--r--usr.sbin/makefs/ffs/ufs_bswap.h2
-rw-r--r--usr.sbin/makefs/getid.c429
-rw-r--r--usr.sbin/makefs/makefs.811
-rw-r--r--usr.sbin/makefs/makefs.c10
-rw-r--r--usr.sbin/makefs/makefs.h18
-rw-r--r--usr.sbin/makefs/mtree.c1
-rw-r--r--usr.sbin/makefs/walk.c29
-rw-r--r--usr.sbin/mergemaster/mergemaster.88
-rwxr-xr-xusr.sbin/mergemaster/mergemaster.sh10
-rw-r--r--usr.sbin/mfiutil/Makefile2
-rw-r--r--usr.sbin/mfiutil/mfi_config.c44
-rw-r--r--usr.sbin/mfiutil/mfi_drive.c14
-rw-r--r--usr.sbin/mfiutil/mfi_foreign.c364
-rw-r--r--usr.sbin/mfiutil/mfi_show.c30
-rw-r--r--usr.sbin/mfiutil/mfiutil.869
-rw-r--r--usr.sbin/mfiutil/mfiutil.c11
-rw-r--r--usr.sbin/mfiutil/mfiutil.h17
-rw-r--r--usr.sbin/named/Makefile5
-rw-r--r--usr.sbin/nandsim/nandsim_cfgparse.c4
-rw-r--r--usr.sbin/ndiscvt/inf-token.l5
-rw-r--r--usr.sbin/ndp/ndp.830
-rw-r--r--usr.sbin/ndp/ndp.c49
-rw-r--r--usr.sbin/newsyslog/newsyslog.c43
-rw-r--r--usr.sbin/nfsd/nfsv4.423
-rw-r--r--usr.sbin/nvram/nvram.c2
-rw-r--r--usr.sbin/pciconf/cap.c70
-rw-r--r--usr.sbin/periodic/periodic.sh11
-rw-r--r--usr.sbin/pkg/config.c22
-rw-r--r--usr.sbin/pkg/dns_utils.c2
-rw-r--r--usr.sbin/pkg_install/add/extract.c3
-rw-r--r--usr.sbin/pkg_install/add/main.c1
-rw-r--r--usr.sbin/pkg_install/create/pl.c3
-rw-r--r--usr.sbin/pkg_install/lib/exec.c5
-rw-r--r--usr.sbin/pkg_install/version/pkg_version.112
-rw-r--r--usr.sbin/pmcannotate/pmcannotate.c2
-rw-r--r--usr.sbin/portsnap/portsnap/portsnap.810
-rw-r--r--usr.sbin/portsnap/portsnap/portsnap.sh6
-rw-r--r--usr.sbin/powerd/powerd.850
-rw-r--r--usr.sbin/powerd/powerd.c16
-rw-r--r--usr.sbin/ppp/Makefile7
-rw-r--r--usr.sbin/ppp/command.c2
-rw-r--r--usr.sbin/ppp/defs.c13
-rw-r--r--usr.sbin/ppp/defs.h2
-rw-r--r--usr.sbin/ppp/ppp.8 (renamed from usr.sbin/ppp/ppp.8.m4)38
-rw-r--r--usr.sbin/pw/pw.conf.52
-rw-r--r--usr.sbin/pw/pw_user.c8
-rw-r--r--usr.sbin/rrenumd/lexer.l4
-rw-r--r--usr.sbin/rtadvctl/rtadvctl.c32
-rw-r--r--usr.sbin/rtadvd/config.c30
-rw-r--r--usr.sbin/rtadvd/if.c4
-rw-r--r--usr.sbin/rtadvd/rrenum.c11
-rw-r--r--usr.sbin/rtadvd/rtadvd.c50
-rw-r--r--usr.sbin/rtadvd/rtadvd.h4
-rw-r--r--usr.sbin/rtadvd/timer.c44
-rw-r--r--usr.sbin/rtadvd/timer.h10
-rw-r--r--usr.sbin/rtadvd/timer_subr.c49
-rw-r--r--usr.sbin/rtadvd/timer_subr.h44
-rw-r--r--usr.sbin/rtsold/dump.c21
-rw-r--r--usr.sbin/rtsold/if.c7
-rw-r--r--usr.sbin/rtsold/probe.c69
-rw-r--r--usr.sbin/rtsold/rtsock.c10
-rw-r--r--usr.sbin/rtsold/rtsol.c30
-rw-r--r--usr.sbin/rtsold/rtsold.815
-rw-r--r--usr.sbin/rtsold/rtsold.c51
-rw-r--r--usr.sbin/rtsold/rtsold.h34
-rw-r--r--usr.sbin/rwhod/rwhod.c638
-rw-r--r--usr.sbin/syslogd/syslogd.c5
-rw-r--r--usr.sbin/sysrc/sysrc12
-rw-r--r--usr.sbin/sysrc/sysrc.816
-rw-r--r--usr.sbin/tcpdump/tcpdump/Makefile168
-rw-r--r--usr.sbin/tcpdump/tcpdump/config.h4
-rw-r--r--usr.sbin/tcpdump/tcpdump/tcpdump.148
-rw-r--r--usr.sbin/timed/timed/timed.82
-rw-r--r--usr.sbin/uhsoctl/uhsoctl.111
-rw-r--r--usr.sbin/vidcontrol/vidcontrol.c2
-rw-r--r--usr.sbin/wake/wake.82
-rw-r--r--usr.sbin/watchdogd/watchdogd.894
-rw-r--r--usr.sbin/watchdogd/watchdogd.c209
-rw-r--r--usr.sbin/wpa/Makefile.crypto20
-rw-r--r--usr.sbin/wpa/Makefile.inc4
-rw-r--r--usr.sbin/wpa/hostapd/Makefile82
-rw-r--r--usr.sbin/wpa/hostapd/driver_freebsd.c787
-rw-r--r--usr.sbin/wpa/hostapd_cli/Makefile2
-rw-r--r--usr.sbin/wpa/wpa_cli/Makefile2
-rw-r--r--usr.sbin/wpa/wpa_passphrase/Makefile4
-rw-r--r--usr.sbin/wpa/wpa_priv/Makefile17
-rw-r--r--usr.sbin/wpa/wpa_supplicant/Makefile65
-rw-r--r--usr.sbin/wpa/wpa_supplicant/driver_freebsd.c929
-rw-r--r--usr.sbin/ypserv/yp_access.c4
-rw-r--r--usr.sbin/ypserv/yp_dnslookup.c4
-rw-r--r--usr.sbin/ypserv/yp_main.c5
305 files changed, 14136 insertions, 9536 deletions
diff --git a/usr.sbin/Makefile b/usr.sbin/Makefile
index 02e590e..f76988f 100644
--- a/usr.sbin/Makefile
+++ b/usr.sbin/Makefile
@@ -6,6 +6,7 @@
SUBDIR= adduser \
arp \
bootparamd \
+ bsdconfig \
bsdinstall \
cdcontrol \
chkgrp \
@@ -80,6 +81,7 @@ SUBDIR= adduser \
snapinfo \
spray \
syslogd \
+ sysrc \
tcpdchk \
tcpdmatch \
tcpdrop \
@@ -127,6 +129,7 @@ SUBDIR+= dnssec-keygen
SUBDIR+= dnssec-revoke
SUBDIR+= dnssec-settime
SUBDIR+= dnssec-signzone
+SUBDIR+= dnssec-verify
.endif
.if ${MK_BIND_NAMED} != "no"
SUBDIR+= arpaname
@@ -146,11 +149,6 @@ SUBDIR+= rndc-confgen
SUBDIR+= bluetooth
.endif
-.if ${MK_BSDCONFIG} != "no"
-SUBDIR+= bsdconfig
-SUBDIR+= sysrc
-.endif
-
.if ${MK_BSNMP} != "no"
SUBDIR+= bsnmpd
.endif
diff --git a/usr.sbin/Makefile.amd64 b/usr.sbin/Makefile.amd64
index 5ee2165..b821625 100644
--- a/usr.sbin/Makefile.amd64
+++ b/usr.sbin/Makefile.amd64
@@ -20,6 +20,7 @@ SUBDIR+= btxld
SUBDIR+= cpucontrol
SUBDIR+= kgmon
SUBDIR+= lptcontrol
+SUBDIR+= mount_smbfs
SUBDIR+= mptable
.if ${MK_NDIS} != "no"
SUBDIR+= ndiscvt
diff --git a/usr.sbin/Makefile.i386 b/usr.sbin/Makefile.i386
index 901c2d9..7d66f78 100644
--- a/usr.sbin/Makefile.i386
+++ b/usr.sbin/Makefile.i386
@@ -12,6 +12,7 @@ SUBDIR+= cpucontrol
SUBDIR+= kgmon
SUBDIR+= kgzip
SUBDIR+= lptcontrol
+SUBDIR+= mount_smbfs
SUBDIR+= mptable
.if ${MK_NDIS} != "no"
SUBDIR+= ndiscvt
diff --git a/usr.sbin/Makefile.ia64 b/usr.sbin/Makefile.ia64
index d047b33..0a897b4 100644
--- a/usr.sbin/Makefile.ia64
+++ b/usr.sbin/Makefile.ia64
@@ -4,5 +4,6 @@
SUBDIR+= acpi
.endif
SUBDIR+= kgmon
+SUBDIR+= mount_smbfs
SUBDIR:= ${SUBDIR:Nuathload}
SUBDIR+= zzz
diff --git a/usr.sbin/Makefile.powerpc b/usr.sbin/Makefile.powerpc
index 131eb57..8833a27 100644
--- a/usr.sbin/Makefile.powerpc
+++ b/usr.sbin/Makefile.powerpc
@@ -1,4 +1,5 @@
# $FreeBSD$
+SUBDIR+= mount_smbfs
SUBDIR+= nvram
SUBDIR+= ofwdump
diff --git a/usr.sbin/Makefile.sparc64 b/usr.sbin/Makefile.sparc64
index 81f7a9b..632b3a8 100644
--- a/usr.sbin/Makefile.sparc64
+++ b/usr.sbin/Makefile.sparc64
@@ -1,4 +1,5 @@
# $FreeBSD$
SUBDIR+= eeprom
+SUBDIR+= mount_smbfs
SUBDIR+= ofwdump
diff --git a/usr.sbin/acpi/acpidb/Makefile b/usr.sbin/acpi/acpidb/Makefile
index 5ee3d47..c08c70b 100644
--- a/usr.sbin/acpi/acpidb/Makefile
+++ b/usr.sbin/acpi/acpidb/Makefile
@@ -35,10 +35,11 @@ SRCS+= hwacpi.c hwesleep.c hwgpe.c hwpci.c hwregs.c hwsleep.c \
hwvalid.c hwxface.c hwxfsleep.c
# components/namespace
-SRCS+= nsaccess.c nsalloc.c nsconvert.c nsdump.c nseval.c \
- nsinit.c nsload.c nsnames.c nsobject.c nsparse.c \
- nspredef.c nsprepkg.c nsrepair.c nsrepair2.c nssearch.c \
- nsutils.c nswalk.c nsxfeval.c nsxfname.c nsxfobj.c
+SRCS+= nsaccess.c nsalloc.c nsarguments.c nsconvert.c nsdump.c \
+ nseval.c nsinit.c nsload.c nsnames.c nsobject.c \
+ nsparse.c nspredef.c nsprepkg.c nsrepair.c nsrepair2.c \
+ nssearch.c nsutils.c nswalk.c nsxfeval.c nsxfname.c \
+ nsxfobj.c
# components/parser
SRCS+= psargs.c psloop.c psobject.c psopcode.c psopinfo.c \
@@ -54,19 +55,19 @@ SRCS+= rsaddr.c rscalc.c rscreate.c rsdump.c rsdumpinfo.c \
rsserial.c rsutils.c rsxface.c
# components/tables
-SRCS+= tbfadt.c tbfind.c tbinstal.c tbutils.c tbxface.c \
- tbxfload.c
+SRCS+= tbfadt.c tbfind.c tbinstal.c tbprint.c tbutils.c \
+ tbxface.c tbxfload.c
# components/utilities
-SRCS+= utaddress.c utalloc.c utcache.c utcopy.c utdebug.c \
- utdecode.c utdelete.c uteval.c utexcep.c utglobal.c \
- utids.c utinit.c utlock.c utmath.c utmisc.c utmutex.c \
- utobject.c utosi.c utownerid.c utpredef.c utresrc.c \
- utstate.c utstring.c uttrack.c utxface.c utxferror.c \
- utxfinit.c
+SRCS+= utaddress.c utalloc.c utbuffer.c utcache.c utcopy.c \
+ utdebug.c utdecode.c utdelete.c uterror.c uteval.c \
+ utexcep.c utglobal.c utids.c utinit.c utlock.c utmath.c \
+ utmisc.c utmutex.c utobject.c utosi.c utownerid.c \
+ utpredef.c utresrc.c utstate.c utstring.c uttrack.c \
+ utxface.c utxferror.c utxfinit.c
MAN= acpidb.8
-WARNS?= 2
+WARNS?= 3
CFLAGS+= -DACPI_EXEC_APP -fno-strict-aliasing
DPADD= ${LIBPTHREAD}
diff --git a/usr.sbin/acpi/acpidb/acpidb.c b/usr.sbin/acpi/acpidb/acpidb.c
index 4095252..3cd8d3f 100644
--- a/usr.sbin/acpi/acpidb/acpidb.c
+++ b/usr.sbin/acpi/acpidb/acpidb.c
@@ -50,7 +50,7 @@
* Dummy DSDT Table Header
*/
-ACPI_TABLE_HEADER dummy_dsdt_table = {
+static ACPI_TABLE_HEADER dummy_dsdt_table = {
"DSDT", 123, 1, 123, "OEMID", "OEMTBLID", 1, "CRID", 1
};
@@ -58,7 +58,7 @@ ACPI_TABLE_HEADER dummy_dsdt_table = {
* Region space I/O routines on virtual machine
*/
-int aml_debug_prompt = 1;
+static int aml_debug_prompt = 1;
struct ACPIRegionContent {
TAILQ_ENTRY(ACPIRegionContent) links;
@@ -68,10 +68,13 @@ struct ACPIRegionContent {
};
TAILQ_HEAD(ACPIRegionContentList, ACPIRegionContent);
-struct ACPIRegionContentList RegionContentList;
+static struct ACPIRegionContentList RegionContentList;
static int aml_simulation_initialized = 0;
+ACPI_PHYSICAL_ADDRESS AeLocalGetRootPointer(void);
+void AeTableOverride(ACPI_TABLE_HEADER *, ACPI_TABLE_HEADER **);
+
static void aml_simulation_init(void);
static int aml_simulate_regcontent_add(int regtype,
ACPI_PHYSICAL_ADDRESS addr,
@@ -87,11 +90,11 @@ static void aml_simulation_regload(const char *dumpfile);
static void aml_simulation_regdump(const char *dumpfile);
/* Stubs to simplify linkage to the ACPI CA core subsystem. */
-ACPI_STATUS
+ACPI_PHYSICAL_ADDRESS
AeLocalGetRootPointer(void)
{
- return (AE_ERROR);
+ return (0);
}
void
@@ -173,8 +176,8 @@ aml_simulate_prompt(char *msg, UINT64 def_val)
if (msg != NULL) {
printf("%s", msg);
}
- printf("(default: 0x%jx ", val);
- printf(" / %ju) >>", val);
+ printf("(default: 0x%jx ", (uintmax_t)val);
+ printf(" / %ju) >>", (uintmax_t)val);
fflush(stdout);
bzero(buf, sizeof buf);
diff --git a/usr.sbin/acpi/acpidump/acpi.c b/usr.sbin/acpi/acpidump/acpi.c
index c7f5bd8..d3f9685 100644
--- a/usr.sbin/acpi/acpidump/acpi.c
+++ b/usr.sbin/acpi/acpidump/acpi.c
@@ -537,7 +537,7 @@ acpi_handle_mcfg(ACPI_TABLE_HEADER *sdp)
alloc = (ACPI_MCFG_ALLOCATION *)(mcfg + 1);
for (i = 0; i < entries; i++, alloc++) {
printf("\n");
- printf("\tBase Address=0x%016jx\n", alloc->Address);
+ printf("\tBase Address=0x%016jx\n", (uintmax_t)alloc->Address);
printf("\tSegment Group=0x%04x\n", alloc->PciSegment);
printf("\tStart Bus=%d\n", alloc->StartBusNumber);
printf("\tEnd Bus=%d\n", alloc->EndBusNumber);
@@ -554,16 +554,16 @@ acpi_handle_slit(ACPI_TABLE_HEADER *sdp)
printf(BEGIN_COMMENT);
acpi_print_sdt(sdp);
slit = (ACPI_TABLE_SLIT *)sdp;
- printf("\tLocality Count=%jd\n", slit->LocalityCount);
+ printf("\tLocality Count=%ju\n", (uintmax_t)slit->LocalityCount);
printf("\n\t ");
for (i = 0; i < slit->LocalityCount; i++)
- printf(" %3jd", i);
+ printf(" %3ju", (uintmax_t)i);
printf("\n\t +");
for (i = 0; i < slit->LocalityCount; i++)
printf("----");
printf("\n");
for (i = 0; i < slit->LocalityCount; i++) {
- printf("\t %3jd |", i);
+ printf("\t %3ju |", (uintmax_t)i);
for (j = 0; j < slit->LocalityCount; j++)
printf(" %3d",
slit->Entry[i * slit->LocalityCount + j]);
@@ -830,7 +830,7 @@ acpi_handle_dmar_drhd(ACPI_DMAR_HARDWARE_UNIT *drhd)
#undef PRINTFLAG
printf("\tSegment=%d\n", drhd->Segment);
- printf("\tAddress=0x%0jx\n", drhd->Address);
+ printf("\tAddress=0x%0jx\n", (uintmax_t)drhd->Address);
remaining = drhd->Header.Length - sizeof(ACPI_DMAR_HARDWARE_UNIT);
if (remaining > 0)
@@ -855,8 +855,8 @@ acpi_handle_dmar_rmrr(ACPI_DMAR_RESERVED_MEMORY *rmrr)
printf("\tType=RMRR\n");
printf("\tLength=%d\n", rmrr->Header.Length);
printf("\tSegment=%d\n", rmrr->Segment);
- printf("\tBaseAddress=0x%0jx\n", rmrr->BaseAddress);
- printf("\tLimitAddress=0x%0jx\n", rmrr->EndAddress);
+ printf("\tBaseAddress=0x%0jx\n", (uintmax_t)rmrr->BaseAddress);
+ printf("\tLimitAddress=0x%0jx\n", (uintmax_t)rmrr->EndAddress);
remaining = rmrr->Header.Length - sizeof(ACPI_DMAR_RESERVED_MEMORY);
if (remaining > 0)
@@ -911,7 +911,7 @@ acpi_handle_dmar_rhsa(ACPI_DMAR_RHSA *rhsa)
printf("\n");
printf("\tType=RHSA\n");
printf("\tLength=%d\n", rhsa->Header.Length);
- printf("\tBaseAddress=0x%0jx\n", rhsa->BaseAddress);
+ printf("\tBaseAddress=0x%0jx\n", (uintmax_t)rhsa->BaseAddress);
printf("\tProximityDomain=0x%08x\n", rhsa->ProximityDomain);
}
diff --git a/usr.sbin/acpi/acpidump/acpi_user.c b/usr.sbin/acpi/acpidump/acpi_user.c
index 0b2beb2..d759ea7 100644
--- a/usr.sbin/acpi/acpidump/acpi_user.c
+++ b/usr.sbin/acpi/acpidump/acpi_user.c
@@ -172,7 +172,7 @@ acpi_find_rsd_ptr(void)
addr = 0;
/* Attempt to use kenv or sysctl to find RSD PTR record. */
- if (kenv(KENV_GET, hint_acpi_0_rsdp, buf, 20) == 0)
+ if (kenv(KENV_GET, hint_acpi_0_rsdp, buf, 20) > 0)
addr = strtoul(buf, NULL, 0);
if (addr == 0) {
len = sizeof(addr);
diff --git a/usr.sbin/acpi/iasl/Makefile b/usr.sbin/acpi/iasl/Makefile
index 973b63d..161b2f4 100644
--- a/usr.sbin/acpi/iasl/Makefile
+++ b/usr.sbin/acpi/iasl/Makefile
@@ -14,16 +14,16 @@ SRCS+= aslanalyze.c aslbtypes.c aslcodegen.c aslcompile.c \
asllength.c asllisting.c asllistsup.c aslload.c \
asllookup.c aslmain.c aslmap.c aslmethod.c aslnamesp.c \
asloffset.c aslopcodes.c asloperands.c aslopt.c \
- aslpredef.c aslprepkg.c aslresource.c aslrestype1.c \
- aslrestype1i.c aslrestype2.c aslrestype2d.c \
- aslrestype2e.c aslrestype2q.c aslrestype2s.c \
- aslrestype2w.c aslstartup.c aslstubs.c asltransform.c \
- asltree.c aslutils.c asluuid.c aslwalks.c aslxref.c \
- dtcompile.c dtexpress.c dtfield.c dtio.c dtparser.y.h \
- dtparserlex.c dtparserparse.c dtsubtable.c dttable.c \
- dttemplate.c dtutils.c prexpress.c prmacros.c \
- prparser.y.h prparserlex.c prparserparse.c prscan.c \
- prutils.c
+ asloptions.c aslpredef.c aslprepkg.c aslresource.c \
+ aslrestype1.c aslrestype1i.c aslrestype2.c \
+ aslrestype2d.c aslrestype2e.c aslrestype2q.c \
+ aslrestype2s.c aslrestype2w.c aslstartup.c aslstubs.c \
+ asltransform.c asltree.c aslutils.c asluuid.c \
+ aslwalks.c aslxref.c dtcompile.c dtexpress.c dtfield.c \
+ dtio.c dtparser.y.h dtparserlex.c dtparserparse.c \
+ dtsubtable.c dttable.c dttemplate.c dtutils.c \
+ prexpress.c prmacros.c prparser.y.h prparserlex.c \
+ prparserparse.c prscan.c prutils.c
# components/debugger
SRCS+= dbfileio.c
@@ -52,14 +52,14 @@ SRCS+= nsaccess.c nsalloc.c nsdump.c nsnames.c nsobject.c \
nsparse.c nssearch.c nsutils.c nswalk.c
# components/tables
-SRCS+= tbfadt.c tbinstal.c tbutils.c tbxface.c
+SRCS+= tbfadt.c tbinstal.c tbprint.c tbutils.c tbxface.c
# components/utilities
-SRCS+= utaddress.c utalloc.c utcache.c utcopy.c utdebug.c \
- utdecode.c utdelete.c utexcep.c utglobal.c utinit.c \
- utlock.c utmath.c utmisc.c utmutex.c utobject.c \
- utownerid.c utpredef.c utresrc.c utstate.c utstring.c \
- utxface.c utxferror.c
+SRCS+= utaddress.c utalloc.c utbuffer.c utcache.c utcopy.c \
+ utdebug.c utdecode.c utdelete.c uterror.c utexcep.c \
+ utglobal.c utinit.c utlock.c utmath.c utmisc.c \
+ utmutex.c utobject.c utownerid.c utpredef.c utresrc.c \
+ utstate.c utstring.c utxface.c utxferror.c
# os_specific/service_layers
SRCS+= osunixxf.c
@@ -74,7 +74,8 @@ YFLAGS= -d
CLEANFILES= aslcompiler.y.h aslcompilerlex.c aslcompilerparse.c \
aslcompilerparse.h dtparser.y.h dtparserlex.c \
- dtparserparse.c dtparserparse.h
+ dtparserparse.c dtparserparse.h prparser.y.h \
+ prparserlex.c prparserparse.c prparserparse.h
aslcompilerlex.c: aslcompiler.l aslsupport.l
${LEX} ${LFLAGS} -PAslCompiler -o${.TARGET} \
diff --git a/usr.sbin/apmd/apmdlex.l b/usr.sbin/apmd/apmdlex.l
index dc7664d..b002feb 100644
--- a/usr.sbin/apmd/apmdlex.l
+++ b/usr.sbin/apmd/apmdlex.l
@@ -36,14 +36,14 @@
#include "apmd.h"
#include "y.tab.h"
-/* We don't need it, avoid the warning. */
-#define YY_NO_UNPUT
-#define YY_NO_INPUT
-
int lineno;
int first_time;
%}
+/* We don't need it, avoid the warning. */
+%option nounput
+%option noinput
+
%s TOP
%%
diff --git a/usr.sbin/arp/arp.4 b/usr.sbin/arp/arp.4
index 0ff0f2c..93cfd07 100644
--- a/usr.sbin/arp/arp.4
+++ b/usr.sbin/arp/arp.4
@@ -28,7 +28,7 @@
.\" @(#)arp4.4 6.5 (Berkeley) 4/18/94
.\" $FreeBSD$
.\"
-.Dd September 3, 2012
+.Dd May 11, 2013
.Dt ARP 4
.Os
.Sh NAME
@@ -148,6 +148,10 @@ See
.Sx DIAGNOSTICS
below.
Turned on by default.
+.It Va max_log_per_second
+Limit number of remotely triggered logging events to a configured value
+per second.
+Default is 1 log message per second.
.It Va max_age
How long an ARP entry is held in the cache until it needs to be refreshed.
Default is 1200 seconds.
diff --git a/usr.sbin/auditdistd/Makefile b/usr.sbin/auditdistd/Makefile
index 468290b..ee18bca 100644
--- a/usr.sbin/auditdistd/Makefile
+++ b/usr.sbin/auditdistd/Makefile
@@ -10,6 +10,7 @@ OPENBSMDIR=${.CURDIR}/../../contrib/openbsm
CFLAGS+=-I${OPENBSMDIR} -I${OPENBSMDIR}/bin/auditdistd
NO_WFORMAT=
+NO_WMISSING_VARIABLE_DECLARATIONS=
PROG= auditdistd
SRCS= auditdistd.c
diff --git a/usr.sbin/authpf/Makefile b/usr.sbin/authpf/Makefile
index 1d15beb..744df61 100644
--- a/usr.sbin/authpf/Makefile
+++ b/usr.sbin/authpf/Makefile
@@ -18,4 +18,7 @@ DPADD+= ${LIBM} ${LIBMD} ${LIBUTIL}
WARNS?= 3
+LINKS= ${BINDIR}/authpf ${BINDIR}/authpf-noip
+MLINKS= authpf.8 authpf-noip.8
+
.include <bsd.prog.mk>
diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile
index e6aa8b2..17355c3 100644
--- a/usr.sbin/bhyve/Makefile
+++ b/usr.sbin/bhyve/Makefile
@@ -10,7 +10,7 @@ SRCS= acpi.c atpic.c bhyverun.c consport.c dbgport.c elcr.c inout.c
SRCS+= ioapic.c mem.c mevent.c mptbl.c
SRCS+= pci_emul.c pci_hostbridge.c pci_passthru.c pci_virtio_block.c
SRCS+= pci_virtio_net.c pci_uart.c pit_8254.c pmtmr.c post.c rtc.c
-SRCS+= xmsr.c spinup_ap.c
+SRCS+= virtio.c xmsr.c spinup_ap.c
.PATH: ${.CURDIR}/../../sys/amd64/vmm
SRCS+= vmm_instruction_emul.c
diff --git a/usr.sbin/bhyve/atpic.c b/usr.sbin/bhyve/atpic.c
index a9fb084..5b4dd79 100644
--- a/usr.sbin/bhyve/atpic.c
+++ b/usr.sbin/bhyve/atpic.c
@@ -37,13 +37,6 @@ __FBSDID("$FreeBSD$");
#include "inout.h"
-/*
- * FreeBSD only writes to the 8259 interrupt controllers to put them in a
- * shutdown state.
- *
- * So, we just ignore the writes.
- */
-
#define IO_ICU1 0x20
#define IO_ICU2 0xA0
#define ICU_IMR_OFFSET 1
@@ -55,8 +48,14 @@ atpic_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
if (bytes != 1)
return (-1);
- if (in)
- return (-1);
+ if (in) {
+ if (port & ICU_IMR_OFFSET) {
+ /* all interrupts masked */
+ *eax = 0xff;
+ } else {
+ *eax = 0x00;
+ }
+ }
/* Pretend all writes to the 8259 are alright */
return (0);
diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
index 3218ca4..43eea98 100644
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
#include "xmsr.h"
#include "ioapic.h"
#include "spinup_ap.h"
+#include "rtc.h"
#define DEFAULT_GUEST_HZ 100
#define DEFAULT_GUEST_TSLICE 200
@@ -508,6 +509,7 @@ vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip)
{
cpuset_t mask;
int error, rc, prevcpu;
+ enum vm_exitcode exitcode;
if (guest_vcpu_mux)
setup_timeslice();
@@ -537,8 +539,16 @@ vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip)
}
prevcpu = vcpu;
- rc = (*handler[vmexit[vcpu].exitcode])(ctx, &vmexit[vcpu],
- &vcpu);
+
+ exitcode = vmexit[vcpu].exitcode;
+ if (exitcode >= VM_EXITCODE_MAX || handler[exitcode] == NULL) {
+ fprintf(stderr, "vm_loop: unexpected exitcode 0x%x\n",
+ exitcode);
+ exit(1);
+ }
+
+ rc = (*handler[exitcode])(ctx, &vmexit[vcpu], &vcpu);
+
switch (rc) {
case VMEXIT_SWITCH:
assert(guest_vcpu_mux);
@@ -631,11 +641,15 @@ main(int argc, char *argv[])
guest_tslice = atoi(optarg);
break;
case 's':
- pci_parse_slot(optarg, 0);
- break;
+ if (pci_parse_slot(optarg, 0) != 0)
+ exit(1);
+ else
+ break;
case 'S':
- pci_parse_slot(optarg, 1);
- break;
+ if (pci_parse_slot(optarg, 1) != 0)
+ exit(1);
+ else
+ break;
case 'm':
memsize = strtoul(optarg, NULL, 0) * MB;
break;
@@ -730,7 +744,15 @@ main(int argc, char *argv[])
init_mem();
init_inout();
- init_pci(ctx);
+
+ rtc_init(ctx);
+
+ /*
+ * Exit if a device emulation finds an error in it's initilization
+ */
+ if (init_pci(ctx) != 0)
+ exit(1);
+
if (ioapic)
ioapic_init(0);
diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c
index 713e197..626dfdf 100644
--- a/usr.sbin/bhyve/pci_emul.c
+++ b/usr.sbin/bhyve/pci_emul.c
@@ -47,13 +47,14 @@ __FBSDID("$FreeBSD$");
#include "bhyverun.h"
#include "inout.h"
#include "mem.h"
-#include "mptbl.h"
#include "pci_emul.h"
#include "ioapic.h"
#define CONF1_ADDR_PORT 0x0cf8
#define CONF1_DATA_PORT 0x0cfc
+#define CONF1_ENABLE 0x80000000ul
+
#define CFGWRITE(pi,off,val,b) \
do { \
if ((b) == 1) { \
@@ -88,8 +89,6 @@ static struct lirqinfo {
SET_DECLARE(pci_devemu_set, struct pci_devemu);
-static uint32_t pci_hole_startaddr;
-
static uint64_t pci_emul_iobase;
static uint64_t pci_emul_membase32;
static uint64_t pci_emul_membase64;
@@ -102,6 +101,8 @@ static uint64_t pci_emul_membase64;
#define PCI_EMUL_MEMBASE64 0xD000000000UL
#define PCI_EMUL_MEMLIMIT64 0xFD00000000UL
+static struct pci_devemu *pci_emul_finddev(char *name);
+
static int pci_emul_devices;
/*
@@ -125,48 +126,65 @@ static int pci_emul_devices;
static void
pci_parse_slot_usage(char *aopt)
{
- printf("Invalid PCI slot info field \"%s\"\n", aopt);
- free(aopt);
+
+ fprintf(stderr, "Invalid PCI slot info field \"%s\"\n", aopt);
}
-void
+int
pci_parse_slot(char *opt, int legacy)
{
char *slot, *func, *emul, *config;
char *str, *cpy;
- int snum, fnum;
+ int error, snum, fnum;
+ error = -1;
str = cpy = strdup(opt);
- config = NULL;
-
- if (strchr(str, ':') != NULL) {
- slot = strsep(&str, ":");
- func = strsep(&str, ",");
- } else {
- slot = strsep(&str, ",");
- func = NULL;
- }
-
+ slot = strsep(&str, ",");
+ func = NULL;
+ if (strchr(slot, ':') != NULL) {
+ func = cpy;
+ (void) strsep(&func, ":");
+ }
+
emul = strsep(&str, ",");
- if (str != NULL) {
- config = strsep(&str, ",");
- }
+ config = str;
if (emul == NULL) {
- pci_parse_slot_usage(cpy);
- return;
+ pci_parse_slot_usage(opt);
+ goto done;
}
snum = atoi(slot);
fnum = func ? atoi(func) : 0;
+
if (snum < 0 || snum >= MAXSLOTS || fnum < 0 || fnum >= MAXFUNCS) {
- pci_parse_slot_usage(cpy);
- } else {
- pci_slotinfo[snum][fnum].si_name = emul;
- pci_slotinfo[snum][fnum].si_param = config;
- pci_slotinfo[snum][fnum].si_legacy = legacy;
+ pci_parse_slot_usage(opt);
+ goto done;
+ }
+
+ if (pci_slotinfo[snum][fnum].si_name != NULL) {
+ fprintf(stderr, "pci slot %d:%d already occupied!\n",
+ snum, fnum);
+ goto done;
}
+
+ if (pci_emul_finddev(emul) == NULL) {
+ fprintf(stderr, "pci slot %d:%d: unknown device \"%s\"\n",
+ snum, fnum, emul);
+ goto done;
+ }
+
+ error = 0;
+ pci_slotinfo[snum][fnum].si_name = emul;
+ pci_slotinfo[snum][fnum].si_param = config;
+ pci_slotinfo[snum][fnum].si_legacy = legacy;
+
+done:
+ if (error)
+ free(cpy);
+
+ return (error);
}
static int
@@ -227,8 +245,12 @@ pci_emul_msix_tread(struct pci_devinst *pi, uint64_t offset, int size)
int tab_index;
uint64_t retval = ~0;
- /* support only 4 or 8 byte reads */
- if (size != 4 && size != 8)
+ /*
+ * The PCI standard only allows 4 and 8 byte accesses to the MSI-X
+ * table but we also allow 1 byte access to accomodate reads from
+ * ddb.
+ */
+ if (size != 1 && size != 4 && size != 8)
return (retval);
msix_entry_offset = offset % MSIX_TABLE_ENTRY_SIZE;
@@ -245,7 +267,9 @@ pci_emul_msix_tread(struct pci_devinst *pi, uint64_t offset, int size)
dest = (char *)(pi->pi_msix.table + tab_index);
dest += msix_entry_offset;
- if (size == 4)
+ if (size == 1)
+ retval = *((uint8_t *)dest);
+ else if (size == 4)
retval = *((uint32_t *)dest);
else
retval = *((uint64_t *)dest);
@@ -644,11 +668,13 @@ pci_emul_finddev(char *name)
return (NULL);
}
-static void
+static int
pci_emul_init(struct vmctx *ctx, struct pci_devemu *pde, int slot, int func,
char *params)
{
struct pci_devinst *pdi;
+ int err;
+
pdi = malloc(sizeof(struct pci_devinst));
bzero(pdi, sizeof(*pdi));
@@ -666,12 +692,15 @@ pci_emul_init(struct vmctx *ctx, struct pci_devemu *pde, int slot, int func,
pci_set_cfgdata8(pdi, PCIR_COMMAND,
PCIM_CMD_PORTEN | PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN);
- if ((*pde->pe_init)(ctx, pdi, params) != 0) {
+ err = (*pde->pe_init)(ctx, pdi, params);
+ if (err != 0) {
free(pdi);
} else {
pci_emul_devices++;
pci_slotinfo[slot][func].si_devi = pdi;
- }
+ }
+
+ return (err);
}
void
@@ -971,34 +1000,20 @@ pci_emul_fallback_handler(struct vmctx *ctx, int vcpu, int dir, uint64_t addr,
return (0);
}
-void
+int
init_pci(struct vmctx *ctx)
{
struct mem_range memp;
struct pci_devemu *pde;
struct slotinfo *si;
+ size_t lowmem;
int slot, func;
int error;
- pci_hole_startaddr = vm_get_lowmem_limit(ctx);
-
pci_emul_iobase = PCI_EMUL_IOBASE;
- pci_emul_membase32 = pci_hole_startaddr;
+ pci_emul_membase32 = vm_get_lowmem_limit(ctx);
pci_emul_membase64 = PCI_EMUL_MEMBASE64;
- for (slot = 0; slot < MAXSLOTS; slot++) {
- for (func = 0; func < MAXFUNCS; func++) {
- si = &pci_slotinfo[slot][func];
- if (si->si_name != NULL) {
- pde = pci_emul_finddev(si->si_name);
- if (pde != NULL) {
- pci_emul_init(ctx, pde, slot, func,
- si->si_param);
- }
- }
- }
- }
-
/*
* Allow ISA IRQs 5,10,11,12, and 15 to be available for
* generic use
@@ -1009,19 +1024,44 @@ init_pci(struct vmctx *ctx)
lirq[12].li_generic = 1;
lirq[15].li_generic = 1;
+ for (slot = 0; slot < MAXSLOTS; slot++) {
+ for (func = 0; func < MAXFUNCS; func++) {
+ si = &pci_slotinfo[slot][func];
+ if (si->si_name != NULL) {
+ pde = pci_emul_finddev(si->si_name);
+ assert(pde != NULL);
+ error = pci_emul_init(ctx, pde, slot, func,
+ si->si_param);
+ if (error)
+ return (error);
+ }
+ }
+ }
+
/*
- * Setup the PCI hole to return 0xff's when accessed in a region
- * with no devices
+ * The guest physical memory map looks like the following:
+ * [0, lowmem) guest system memory
+ * [lowmem, lowmem_limit) memory hole (may be absent)
+ * [lowmem_limit, 4GB) PCI hole (32-bit BAR allocation)
+ * [4GB, 4GB + highmem)
+ *
+ * Accesses to memory addresses that are not allocated to system
+ * memory or PCI devices return 0xff's.
*/
+ error = vm_get_memory_seg(ctx, 0, &lowmem);
+ assert(error == 0);
+
memset(&memp, 0, sizeof(struct mem_range));
memp.name = "PCI hole";
memp.flags = MEM_F_RW;
- memp.base = pci_hole_startaddr;
- memp.size = (4ULL * 1024 * 1024 * 1024) - pci_hole_startaddr;
+ memp.base = lowmem;
+ memp.size = (4ULL * 1024 * 1024 * 1024) - lowmem;
memp.handler = pci_emul_fallback_handler;
error = register_mem_fallback(&memp);
assert(error == 0);
+
+ return (0);
}
int
@@ -1195,20 +1235,29 @@ pci_emul_cfgaddr(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
{
uint32_t x;
- assert(!in);
-
- if (bytes != 4)
- return (-1);
+ if (bytes != 4) {
+ if (in)
+ *eax = (bytes == 2) ? 0xffff : 0xff;
+ return (0);
+ }
- x = *eax;
- cfgoff = x & PCI_REGMAX;
- cfgfunc = (x >> 8) & PCI_FUNCMAX;
- cfgslot = (x >> 11) & PCI_SLOTMAX;
- cfgbus = (x >> 16) & PCI_BUSMAX;
+ if (in) {
+ x = (cfgbus << 16) |
+ (cfgslot << 11) |
+ (cfgfunc << 8) |
+ cfgoff;
+ *eax = x | CONF1_ENABLE;
+ } else {
+ x = *eax;
+ cfgoff = x & PCI_REGMAX;
+ cfgfunc = (x >> 8) & PCI_FUNCMAX;
+ cfgslot = (x >> 11) & PCI_SLOTMAX;
+ cfgbus = (x >> 16) & PCI_BUSMAX;
+ }
return (0);
}
-INOUT_PORT(pci_cfgaddr, CONF1_ADDR_PORT, IOPORT_F_OUT, pci_emul_cfgaddr);
+INOUT_PORT(pci_cfgaddr, CONF1_ADDR_PORT, IOPORT_F_INOUT, pci_emul_cfgaddr);
static uint32_t
bits_changed(uint32_t old, uint32_t new, uint32_t mask)
diff --git a/usr.sbin/bhyve/pci_emul.h b/usr.sbin/bhyve/pci_emul.h
index db218bb..4e04a1e 100644
--- a/usr.sbin/bhyve/pci_emul.h
+++ b/usr.sbin/bhyve/pci_emul.h
@@ -183,7 +183,7 @@ struct pciecap {
uint16_t slot_status2;
} __packed;
-void init_pci(struct vmctx *ctx);
+int init_pci(struct vmctx *ctx);
void msicap_cfgwrite(struct pci_devinst *pi, int capoff, int offset,
int bytes, uint32_t val);
void msixcap_cfgwrite(struct pci_devinst *pi, int capoff, int offset,
@@ -206,7 +206,7 @@ int pci_msix_enabled(struct pci_devinst *pi);
int pci_msix_table_bar(struct pci_devinst *pi);
int pci_msix_pba_bar(struct pci_devinst *pi);
int pci_msi_msgnum(struct pci_devinst *pi);
-void pci_parse_slot(char *opt, int legacy);
+int pci_parse_slot(char *opt, int legacy);
void pci_populate_msicap(struct msicap *cap, int msgs, int nextptr);
int pci_emul_add_msixcap(struct pci_devinst *pi, int msgnum, int barnum);
int pci_emul_msix_twrite(struct pci_devinst *pi, uint64_t offset, int size,
diff --git a/usr.sbin/bhyve/pci_virtio_block.c b/usr.sbin/bhyve/pci_virtio_block.c
index a325e97..76f681b 100644
--- a/usr.sbin/bhyve/pci_virtio_block.c
+++ b/usr.sbin/bhyve/pci_virtio_block.c
@@ -53,14 +53,6 @@ __FBSDID("$FreeBSD$");
#define VTBLK_RINGSZ 64
-#define VTBLK_CFGSZ 28
-
-#define VTBLK_R_CFG VTCFG_R_CFG1
-#define VTBLK_R_CFG_END VTBLK_R_CFG + VTBLK_CFGSZ -1
-#define VTBLK_R_MAX VTBLK_R_CFG_END
-
-#define VTBLK_REGSZ VTBLK_R_MAX+1
-
#define VTBLK_MAXSEGS 32
#define VTBLK_S_OK 0
@@ -71,28 +63,10 @@ __FBSDID("$FreeBSD$");
*/
#define VTBLK_S_HOSTCAPS \
( 0x00000004 | /* host maximum request segments */ \
- 0x10000000 ) /* supports indirect descriptors */
-
-static int use_msix = 1;
-
-struct vring_hqueue {
- /* Internal state */
- uint16_t hq_size;
- uint16_t hq_cur_aidx; /* trails behind 'avail_idx' */
-
- /* Host-context pointers to the queue */
- struct virtio_desc *hq_dtable;
- uint16_t *hq_avail_flags;
- uint16_t *hq_avail_idx; /* monotonically increasing */
- uint16_t *hq_avail_ring;
-
- uint16_t *hq_used_flags;
- uint16_t *hq_used_idx; /* monotonically increasing */
- struct virtio_used *hq_used_ring;
-};
+ VIRTIO_RING_F_INDIRECT_DESC ) /* indirect descriptors */
/*
- * Config space
+ * Config space "registers"
*/
struct vtblk_config {
uint64_t vbc_capacity;
@@ -104,7 +78,6 @@ struct vtblk_config {
uint32_t vbc_blk_size;
uint32_t vbc_sectors_max;
} __packed;
-CTASSERT(sizeof(struct vtblk_config) == VTBLK_CFGSZ);
/*
* Fixed-size block header
@@ -129,116 +102,69 @@ static int pci_vtblk_debug;
* Per-device softc
*/
struct pci_vtblk_softc {
- struct pci_devinst *vbsc_pi;
+ struct virtio_softc vbsc_vs;
+ struct vqueue_info vbsc_vq;
int vbsc_fd;
- int vbsc_status;
- int vbsc_isr;
- int vbsc_lastq;
- uint32_t vbsc_features;
- uint64_t vbsc_pfn;
- struct vring_hqueue vbsc_q;
struct vtblk_config vbsc_cfg;
- uint16_t msix_table_idx_req;
- uint16_t msix_table_idx_cfg;
};
-#define vtblk_ctx(sc) ((sc)->vbsc_pi->pi_vmctx)
-
-/*
- * Return the size of IO BAR that maps virtio header and device specific
- * region. The size would vary depending on whether MSI-X is enabled or
- * not
- */
-static uint64_t
-pci_vtblk_iosize(struct pci_devinst *pi)
-{
-
- if (pci_msix_enabled(pi))
- return (VTBLK_REGSZ);
- else
- return (VTBLK_REGSZ - (VTCFG_R_CFG1 - VTCFG_R_MSIX));
-}
-/*
- * Return the number of available descriptors in the vring taking care
- * of the 16-bit index wraparound.
- */
-static int
-hq_num_avail(struct vring_hqueue *hq)
-{
- uint16_t ndesc;
-
- /*
- * We're just computing (a-b) in GF(216).
- *
- * The only glitch here is that in standard C,
- * uint16_t promotes to (signed) int when int has
- * more than 16 bits (pretty much always now), so
- * we have to force it back to unsigned.
- */
- ndesc = (unsigned)*hq->hq_avail_idx - (unsigned)hq->hq_cur_aidx;
-
- assert(ndesc <= hq->hq_size);
-
- return (ndesc);
-}
+static void pci_vtblk_reset(void *);
+static void pci_vtblk_notify(void *, struct vqueue_info *);
+static int pci_vtblk_cfgread(void *, int, int, uint32_t *);
+static int pci_vtblk_cfgwrite(void *, int, int, uint32_t);
+
+static struct virtio_consts vtblk_vi_consts = {
+ "vtblk", /* our name */
+ 1, /* we support 1 virtqueue */
+ sizeof(struct vtblk_config), /* config reg size */
+ pci_vtblk_reset, /* reset */
+ pci_vtblk_notify, /* device-wide qnotify */
+ pci_vtblk_cfgread, /* read PCI config */
+ pci_vtblk_cfgwrite, /* write PCI config */
+ VTBLK_S_HOSTCAPS, /* our capabilities */
+};
static void
-pci_vtblk_update_status(struct pci_vtblk_softc *sc, uint32_t value)
+pci_vtblk_reset(void *vsc)
{
- if (value == 0) {
- DPRINTF(("vtblk: device reset requested !\n"));
- }
+ struct pci_vtblk_softc *sc = vsc;
- sc->vbsc_status = value;
+ DPRINTF(("vtblk: device reset requested !\n"));
+ vi_reset_dev(&sc->vbsc_vs);
}
static void
-pci_vtblk_proc(struct pci_vtblk_softc *sc, struct vring_hqueue *hq)
+pci_vtblk_proc(struct pci_vtblk_softc *sc, struct vqueue_info *vq)
{
- struct iovec iov[VTBLK_MAXSEGS];
struct virtio_blk_hdr *vbh;
- struct virtio_desc *vd, *vid;
- struct virtio_used *vu;
uint8_t *status;
- int i;
+ int i, n;
int err;
int iolen;
- int nsegs;
- int uidx, aidx, didx;
int writeop, type;
off_t offset;
+ struct iovec iov[VTBLK_MAXSEGS + 2];
+ uint16_t flags[VTBLK_MAXSEGS + 2];
- uidx = *hq->hq_used_idx;
- aidx = hq->hq_cur_aidx;
- didx = hq->hq_avail_ring[aidx % hq->hq_size];
- assert(didx >= 0 && didx < hq->hq_size);
-
- vd = &hq->hq_dtable[didx];
+ n = vq_getchain(vq, iov, VTBLK_MAXSEGS + 2, flags);
/*
- * Verify that the descriptor is indirect, and obtain
- * the pointer to the indirect descriptor.
- * There has to be space for at least 3 descriptors
- * in the indirect descriptor array: the block header,
- * 1 or more data descriptors, and a status byte.
+ * The first descriptor will be the read-only fixed header,
+ * and the last is for status (hence +2 above and below).
+ * The remaining iov's are the actual data I/O vectors.
+ *
+ * XXX - note - this fails on crash dump, which does a
+ * VIRTIO_BLK_T_FLUSH with a zero transfer length
*/
- assert(vd->vd_flags & VRING_DESC_F_INDIRECT);
+ assert (n >= 3 && n <= VTBLK_MAXSEGS + 2);
- nsegs = vd->vd_len / sizeof(struct virtio_desc);
- assert(nsegs >= 3);
- assert(nsegs < VTBLK_MAXSEGS + 2);
+ assert((flags[0] & VRING_DESC_F_WRITE) == 0);
+ assert(iov[0].iov_len == sizeof(struct virtio_blk_hdr));
+ vbh = iov[0].iov_base;
- vid = paddr_guest2host(vtblk_ctx(sc), vd->vd_addr, vd->vd_len);
- assert((vid->vd_flags & VRING_DESC_F_INDIRECT) == 0);
-
- /*
- * The first descriptor will be the read-only fixed header
- */
- vbh = paddr_guest2host(vtblk_ctx(sc), vid[0].vd_addr,
- sizeof(struct virtio_blk_hdr));
- assert(vid[0].vd_len == sizeof(struct virtio_blk_hdr));
- assert(vid[0].vd_flags & VRING_DESC_F_NEXT);
- assert((vid[0].vd_flags & VRING_DESC_F_WRITE) == 0);
+ status = iov[--n].iov_base;
+ assert(iov[n].iov_len == 1);
+ assert(flags[n] & VRING_DESC_F_WRITE);
/*
* XXX
@@ -250,119 +176,44 @@ pci_vtblk_proc(struct pci_vtblk_softc *sc, struct vring_hqueue *hq)
offset = vbh->vbh_sector * DEV_BSIZE;
- /*
- * Build up the iovec based on the guest's data descriptors
- */
- for (i = 1, iolen = 0; i < nsegs - 1; i++) {
- iov[i-1].iov_base = paddr_guest2host(vtblk_ctx(sc),
- vid[i].vd_addr, vid[i].vd_len);
- iov[i-1].iov_len = vid[i].vd_len;
- iolen += vid[i].vd_len;
-
- assert(vid[i].vd_flags & VRING_DESC_F_NEXT);
- assert((vid[i].vd_flags & VRING_DESC_F_INDIRECT) == 0);
-
+ iolen = 0;
+ for (i = 1; i < n; i++) {
/*
* - write op implies read-only descriptor,
* - read op implies write-only descriptor,
* therefore test the inverse of the descriptor bit
* to the op.
*/
- assert(((vid[i].vd_flags & VRING_DESC_F_WRITE) == 0) ==
- writeop);
+ assert(((flags[i] & VRING_DESC_F_WRITE) == 0) == writeop);
+ iolen += iov[i].iov_len;
}
- /* Lastly, get the address of the status byte */
- status = paddr_guest2host(vtblk_ctx(sc), vid[nsegs - 1].vd_addr, 1);
- assert(vid[nsegs - 1].vd_len == 1);
- assert((vid[nsegs - 1].vd_flags & VRING_DESC_F_NEXT) == 0);
- assert(vid[nsegs - 1].vd_flags & VRING_DESC_F_WRITE);
-
DPRINTF(("virtio-block: %s op, %d bytes, %d segs, offset %ld\n\r",
- writeop ? "write" : "read", iolen, nsegs - 2, offset));
+ writeop ? "write" : "read", iolen, i - 1, offset));
- if (writeop){
- err = pwritev(sc->vbsc_fd, iov, nsegs - 2, offset);
- } else {
- err = preadv(sc->vbsc_fd, iov, nsegs - 2, offset);
- }
+ if (writeop)
+ err = pwritev(sc->vbsc_fd, iov + 1, i - 1, offset);
+ else
+ err = preadv(sc->vbsc_fd, iov + 1, i - 1, offset);
*status = err < 0 ? VTBLK_S_IOERR : VTBLK_S_OK;
/*
- * Return the single indirect descriptor back to the host
- */
- vu = &hq->hq_used_ring[uidx % hq->hq_size];
- vu->vu_idx = didx;
- vu->vu_tlen = 1;
- hq->hq_cur_aidx++;
- *hq->hq_used_idx += 1;
-}
-
-static void
-pci_vtblk_qnotify(struct pci_vtblk_softc *sc)
-{
- struct vring_hqueue *hq = &sc->vbsc_q;
- int i;
- int ndescs;
-
- /*
- * Calculate number of ring entries to process
- */
- ndescs = hq_num_avail(hq);
-
- if (ndescs == 0)
- return;
-
- /*
- * Run through all the entries, placing them into iovecs and
- * sending when an end-of-packet is found
- */
- for (i = 0; i < ndescs; i++)
- pci_vtblk_proc(sc, hq);
-
- /*
- * Generate an interrupt if able
+ * Return the descriptor back to the host.
+ * We wrote 1 byte (our status) to host.
*/
- if ((*hq->hq_avail_flags & VRING_AVAIL_F_NO_INTERRUPT) == 0) {
- if (use_msix) {
- pci_generate_msix(sc->vbsc_pi, sc->msix_table_idx_req);
- } else if (sc->vbsc_isr == 0) {
- sc->vbsc_isr = 1;
- pci_generate_msi(sc->vbsc_pi, 0);
- }
- }
-
+ vq_relchain(vq, 1);
}
static void
-pci_vtblk_ring_init(struct pci_vtblk_softc *sc, uint64_t pfn)
+pci_vtblk_notify(void *vsc, struct vqueue_info *vq)
{
- struct vring_hqueue *hq;
-
- sc->vbsc_pfn = pfn << VRING_PFN;
-
- /*
- * Set up host pointers to the various parts of the
- * queue
- */
- hq = &sc->vbsc_q;
- hq->hq_size = VTBLK_RINGSZ;
-
- hq->hq_dtable = paddr_guest2host(vtblk_ctx(sc), pfn << VRING_PFN,
- vring_size(VTBLK_RINGSZ));
- hq->hq_avail_flags = (uint16_t *)(hq->hq_dtable + hq->hq_size);
- hq->hq_avail_idx = hq->hq_avail_flags + 1;
- hq->hq_avail_ring = hq->hq_avail_flags + 2;
- hq->hq_used_flags = (uint16_t *)roundup2((uintptr_t)hq->hq_avail_ring,
- VRING_ALIGN);
- hq->hq_used_idx = hq->hq_used_flags + 1;
- hq->hq_used_ring = (struct virtio_used *)(hq->hq_used_flags + 2);
+ struct pci_vtblk_softc *sc = vsc;
- /*
- * Initialize queue indexes
- */
- hq->hq_cur_aidx = 0;
+ vq_startchains(vq);
+ while (vq_has_descs(vq))
+ pci_vtblk_proc(sc, vq);
+ vq_endchains(vq, 1); /* Generate interrupt if appropriate. */
}
static int
@@ -373,6 +224,7 @@ pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
off_t size;
int fd;
int sectsz;
+ int use_msix;
const char *env_msi;
if (opts == NULL) {
@@ -414,10 +266,14 @@ pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
sc = malloc(sizeof(struct pci_vtblk_softc));
memset(sc, 0, sizeof(struct pci_vtblk_softc));
- pi->pi_arg = sc;
- sc->vbsc_pi = pi;
+ /* record fd of storage device/file */
sc->vbsc_fd = fd;
+ /* init virtio softc and virtqueues */
+ vi_softc_linkup(&sc->vbsc_vs, &vtblk_vi_consts, sc, pi, &sc->vbsc_vq);
+ sc->vbsc_vq.vq_qsize = VTBLK_RINGSZ;
+ /* sc->vbsc_vq.vq_notify = we have no per-queue notify */
+
/* setup virtio block config space */
sc->vbsc_cfg.vbc_capacity = size / sectsz;
sc->vbsc_cfg.vbc_seg_max = VTBLK_MAXSEGS;
@@ -428,206 +284,51 @@ pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
sc->vbsc_cfg.vbc_geom_s = 0;
sc->vbsc_cfg.vbc_sectors_max = 0;
- /* initialize config space */
+ /*
+ * Should we move some of this into virtio.c? Could
+ * have the device, class, and subdev_0 as fields in
+ * the virtio constants structure.
+ */
pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_BLOCK);
pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR);
pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_STORAGE);
pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_BLOCK);
+ use_msix = 1;
if ((env_msi = getenv("BHYVE_USE_MSI"))) {
if (strcasecmp(env_msi, "yes") == 0)
use_msix = 0;
}
-
- if (use_msix) {
- /* MSI-X Support */
- sc->msix_table_idx_req = VIRTIO_MSI_NO_VECTOR;
- sc->msix_table_idx_cfg = VIRTIO_MSI_NO_VECTOR;
-
- if (pci_emul_add_msixcap(pi, 2, 1))
- return (1);
- } else {
- /* MSI Support */
- pci_emul_add_msicap(pi, 1);
- }
-
- pci_emul_alloc_bar(pi, 0, PCIBAR_IO, VTBLK_REGSZ);
-
+ if (vi_intr_init(&sc->vbsc_vs, 1, use_msix))
+ return (1);
+ vi_set_io_bar(&sc->vbsc_vs, 0);
return (0);
}
-static uint64_t
-vtblk_adjust_offset(struct pci_devinst *pi, uint64_t offset)
-{
- /*
- * Device specific offsets used by guest would change
- * based on whether MSI-X capability is enabled or not
- */
- if (!pci_msix_enabled(pi)) {
- if (offset >= VTCFG_R_MSIX)
- return (offset + (VTCFG_R_CFG1 - VTCFG_R_MSIX));
- }
-
- return (offset);
-}
-
-static void
-pci_vtblk_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi,
- int baridx, uint64_t offset, int size, uint64_t value)
+static int
+pci_vtblk_cfgwrite(void *vsc, int offset, int size, uint32_t value)
{
- struct pci_vtblk_softc *sc = pi->pi_arg;
- if (use_msix) {
- if (baridx == pci_msix_table_bar(pi) ||
- baridx == pci_msix_pba_bar(pi)) {
- pci_emul_msix_twrite(pi, offset, size, value);
- return;
- }
- }
-
- assert(baridx == 0);
-
- if (offset + size > pci_vtblk_iosize(pi)) {
- DPRINTF(("vtblk_write: 2big, offset %ld size %d\n",
- offset, size));
- return;
- }
-
- offset = vtblk_adjust_offset(pi, offset);
-
- switch (offset) {
- case VTCFG_R_GUESTCAP:
- assert(size == 4);
- sc->vbsc_features = value & VTBLK_S_HOSTCAPS;
- break;
- case VTCFG_R_PFN:
- assert(size == 4);
- pci_vtblk_ring_init(sc, value);
- break;
- case VTCFG_R_QSEL:
- assert(size == 2);
- sc->vbsc_lastq = value;
- break;
- case VTCFG_R_QNOTIFY:
- assert(size == 2);
- assert(value == 0);
- pci_vtblk_qnotify(sc);
- break;
- case VTCFG_R_STATUS:
- assert(size == 1);
- pci_vtblk_update_status(sc, value);
- break;
- case VTCFG_R_CFGVEC:
- assert(size == 2);
- sc->msix_table_idx_cfg = value;
- break;
- case VTCFG_R_QVEC:
- assert(size == 2);
- sc->msix_table_idx_req = value;
- break;
- case VTCFG_R_HOSTCAP:
- case VTCFG_R_QNUM:
- case VTCFG_R_ISR:
- case VTBLK_R_CFG ... VTBLK_R_CFG_END:
- DPRINTF(("vtblk: write to readonly reg %ld\n\r", offset));
- break;
- default:
- DPRINTF(("vtblk: unknown i/o write offset %ld\n\r", offset));
- value = 0;
- break;
- }
+ DPRINTF(("vtblk: write to readonly reg %d\n\r", offset));
+ return (1);
}
-uint64_t
-pci_vtblk_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi,
- int baridx, uint64_t offset, int size)
+static int
+pci_vtblk_cfgread(void *vsc, int offset, int size, uint32_t *retval)
{
- struct pci_vtblk_softc *sc = pi->pi_arg;
+ struct pci_vtblk_softc *sc = vsc;
void *ptr;
- uint32_t value;
-
- if (use_msix) {
- if (baridx == pci_msix_table_bar(pi) ||
- baridx == pci_msix_pba_bar(pi)) {
- return (pci_emul_msix_tread(pi, offset, size));
- }
- }
-
- assert(baridx == 0);
- if (offset + size > pci_vtblk_iosize(pi)) {
- DPRINTF(("vtblk_read: 2big, offset %ld size %d\n",
- offset, size));
- return (0);
- }
-
- offset = vtblk_adjust_offset(pi, offset);
-
- switch (offset) {
- case VTCFG_R_HOSTCAP:
- assert(size == 4);
- value = VTBLK_S_HOSTCAPS;
- break;
- case VTCFG_R_GUESTCAP:
- assert(size == 4);
- value = sc->vbsc_features; /* XXX never read ? */
- break;
- case VTCFG_R_PFN:
- assert(size == 4);
- value = sc->vbsc_pfn >> VRING_PFN;
- break;
- case VTCFG_R_QNUM:
- value = (sc->vbsc_lastq == 0) ? VTBLK_RINGSZ: 0;
- break;
- case VTCFG_R_QSEL:
- assert(size == 2);
- value = sc->vbsc_lastq; /* XXX never read ? */
- break;
- case VTCFG_R_QNOTIFY:
- assert(size == 2);
- value = 0; /* XXX never read ? */
- break;
- case VTCFG_R_STATUS:
- assert(size == 1);
- value = sc->vbsc_status;
- break;
- case VTCFG_R_ISR:
- assert(size == 1);
- value = sc->vbsc_isr;
- sc->vbsc_isr = 0; /* a read clears this flag */
- break;
- case VTCFG_R_CFGVEC:
- assert(size == 2);
- value = sc->msix_table_idx_cfg;
- break;
- case VTCFG_R_QVEC:
- assert(size == 2);
- value = sc->msix_table_idx_req;
- break;
- case VTBLK_R_CFG ... VTBLK_R_CFG_END:
- assert(size + offset <= (VTBLK_R_CFG_END + 1));
- ptr = (uint8_t *)&sc->vbsc_cfg + offset - VTBLK_R_CFG;
- if (size == 1) {
- value = *(uint8_t *) ptr;
- } else if (size == 2) {
- value = *(uint16_t *) ptr;
- } else {
- value = *(uint32_t *) ptr;
- }
- break;
- default:
- DPRINTF(("vtblk: unknown i/o read offset %ld\n\r", offset));
- value = 0;
- break;
- }
-
- return (value);
+ /* our caller has already verified offset and size */
+ ptr = (uint8_t *)&sc->vbsc_cfg + offset;
+ memcpy(retval, ptr, size);
+ return (0);
}
struct pci_devemu pci_de_vblk = {
.pe_emu = "virtio-blk",
.pe_init = pci_vtblk_init,
- .pe_barwrite = pci_vtblk_write,
- .pe_barread = pci_vtblk_read
+ .pe_barwrite = vi_pci_write,
+ .pe_barread = vi_pci_read
};
PCI_EMUL_SET(pci_de_vblk);
diff --git a/usr.sbin/bhyve/pci_virtio_net.c b/usr.sbin/bhyve/pci_virtio_net.c
index 783c45e..2939949 100644
--- a/usr.sbin/bhyve/pci_virtio_net.c
+++ b/usr.sbin/bhyve/pci_virtio_net.c
@@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
#include <sys/select.h>
#include <sys/uio.h>
#include <sys/ioctl.h>
+#include <net/ethernet.h>
#include <errno.h>
#include <fcntl.h>
@@ -46,66 +47,61 @@ __FBSDID("$FreeBSD$");
#include <assert.h>
#include <md5.h>
#include <pthread.h>
+#include <pthread_np.h>
#include "bhyverun.h"
#include "pci_emul.h"
#include "mevent.h"
#include "virtio.h"
-#define VTNET_RINGSZ 256
+#define VTNET_RINGSZ 1024
#define VTNET_MAXSEGS 32
/*
- * PCI config-space register offsets
+ * Host capabilities. Note that we only offer a few of these.
*/
-#define VTNET_R_CFG0 24
-#define VTNET_R_CFG1 25
-#define VTNET_R_CFG2 26
-#define VTNET_R_CFG3 27
-#define VTNET_R_CFG4 28
-#define VTNET_R_CFG5 29
-#define VTNET_R_CFG6 30
-#define VTNET_R_CFG7 31
-#define VTNET_R_MAX 31
-
-#define VTNET_REGSZ VTNET_R_MAX+1
+#define VIRTIO_NET_F_CSUM (1 << 0) /* host handles partial cksum */
+#define VIRTIO_NET_F_GUEST_CSUM (1 << 1) /* guest handles partial cksum */
+#define VIRTIO_NET_F_MAC (1 << 5) /* host supplies MAC */
+#define VIRTIO_NET_F_GSO_DEPREC (1 << 6) /* deprecated: host handles GSO */
+#define VIRTIO_NET_F_GUEST_TSO4 (1 << 7) /* guest can rcv TSOv4 */
+#define VIRTIO_NET_F_GUEST_TSO6 (1 << 8) /* guest can rcv TSOv6 */
+#define VIRTIO_NET_F_GUEST_ECN (1 << 9) /* guest can rcv TSO with ECN */
+#define VIRTIO_NET_F_GUEST_UFO (1 << 10) /* guest can rcv UFO */
+#define VIRTIO_NET_F_HOST_TSO4 (1 << 11) /* host can rcv TSOv4 */
+#define VIRTIO_NET_F_HOST_TSO6 (1 << 12) /* host can rcv TSOv6 */
+#define VIRTIO_NET_F_HOST_ECN (1 << 13) /* host can rcv TSO with ECN */
+#define VIRTIO_NET_F_HOST_UFO (1 << 14) /* host can rcv UFO */
+#define VIRTIO_NET_F_MRG_RXBUF (1 << 15) /* host can merge RX buffers */
+#define VIRTIO_NET_F_STATUS (1 << 16) /* config status field available */
+#define VIRTIO_NET_F_CTRL_VQ (1 << 17) /* control channel available */
+#define VIRTIO_NET_F_CTRL_RX (1 << 18) /* control channel RX mode support */
+#define VIRTIO_NET_F_CTRL_VLAN (1 << 19) /* control channel VLAN filtering */
+#define VIRTIO_NET_F_GUEST_ANNOUNCE \
+ (1 << 21) /* guest can send gratuitous pkts */
+
+#define VTNET_S_HOSTCAPS \
+ ( VIRTIO_NET_F_MAC | VIRTIO_NET_F_MRG_RXBUF | VIRTIO_NET_F_STATUS | \
+ VIRTIO_F_NOTIFY_ON_EMPTY)
/*
- * Host capabilities
+ * PCI config-space "registers"
*/
-#define VTNET_S_HOSTCAPS \
- ( 0x00000020 | /* host supplies MAC */ \
- 0x00008000 | /* host can merge Rx buffers */ \
- 0x00010000 ) /* config status available */
+struct virtio_net_config {
+ uint8_t mac[6];
+ uint16_t status;
+} __packed;
/*
* Queue definitions.
*/
#define VTNET_RXQ 0
#define VTNET_TXQ 1
-#define VTNET_CTLQ 2
+#define VTNET_CTLQ 2 /* NB: not yet supported */
#define VTNET_MAXQ 3
-static int use_msix = 1;
-
-struct vring_hqueue {
- /* Internal state */
- uint16_t hq_size;
- uint16_t hq_cur_aidx; /* trails behind 'avail_idx' */
-
- /* Host-context pointers to the queue */
- struct virtio_desc *hq_dtable;
- uint16_t *hq_avail_flags;
- uint16_t *hq_avail_idx; /* monotonically increasing */
- uint16_t *hq_avail_ring;
-
- uint16_t *hq_used_flags;
- uint16_t *hq_used_idx; /* monotonically increasing */
- struct virtio_used *hq_used_ring;
-};
-
/*
* Fixed network header size
*/
@@ -130,103 +126,97 @@ static int pci_vtnet_debug;
* Per-device softc
*/
struct pci_vtnet_softc {
- struct pci_devinst *vsc_pi;
+ struct virtio_softc vsc_vs;
+ struct vqueue_info vsc_queues[VTNET_MAXQ - 1];
pthread_mutex_t vsc_mtx;
struct mevent *vsc_mevp;
- int vsc_curq;
- int vsc_status;
- int vsc_isr;
int vsc_tapfd;
int vsc_rx_ready;
- int vsc_rxpend;
+ volatile int resetting; /* set and checked outside lock */
uint32_t vsc_features;
- uint8_t vsc_macaddr[6];
+ struct virtio_net_config vsc_config;
- uint64_t vsc_pfn[VTNET_MAXQ];
- struct vring_hqueue vsc_hq[VTNET_MAXQ];
- uint16_t vsc_msix_table_idx[VTNET_MAXQ];
+ pthread_mutex_t rx_mtx;
+ int rx_in_progress;
+
+ pthread_t tx_tid;
+ pthread_mutex_t tx_mtx;
+ pthread_cond_t tx_cond;
+ int tx_in_progress;
+};
+
+static void pci_vtnet_reset(void *);
+/* static void pci_vtnet_notify(void *, struct vqueue_info *); */
+static int pci_vtnet_cfgread(void *, int, int, uint32_t *);
+static int pci_vtnet_cfgwrite(void *, int, int, uint32_t);
+
+static struct virtio_consts vtnet_vi_consts = {
+ "vtnet", /* our name */
+ VTNET_MAXQ - 1, /* we currently support 2 virtqueues */
+ sizeof(struct virtio_net_config), /* config reg size */
+ pci_vtnet_reset, /* reset */
+ NULL, /* device-wide qnotify -- not used */
+ pci_vtnet_cfgread, /* read PCI config */
+ pci_vtnet_cfgwrite, /* write PCI config */
+ VTNET_S_HOSTCAPS, /* our capabilities */
};
-#define vtnet_ctx(sc) ((sc)->vsc_pi->pi_vmctx)
/*
- * Return the size of IO BAR that maps virtio header and device specific
- * region. The size would vary depending on whether MSI-X is enabled or
- * not.
+ * If the transmit thread is active then stall until it is done.
*/
-static uint64_t
-pci_vtnet_iosize(struct pci_devinst *pi)
+static void
+pci_vtnet_txwait(struct pci_vtnet_softc *sc)
{
- if (pci_msix_enabled(pi))
- return (VTNET_REGSZ);
- else
- return (VTNET_REGSZ - (VTCFG_R_CFG1 - VTCFG_R_MSIX));
+
+ pthread_mutex_lock(&sc->tx_mtx);
+ while (sc->tx_in_progress) {
+ pthread_mutex_unlock(&sc->tx_mtx);
+ usleep(10000);
+ pthread_mutex_lock(&sc->tx_mtx);
+ }
+ pthread_mutex_unlock(&sc->tx_mtx);
}
/*
- * Return the number of available descriptors in the vring taking care
- * of the 16-bit index wraparound.
+ * If the receive thread is active then stall until it is done.
*/
-static int
-hq_num_avail(struct vring_hqueue *hq)
+static void
+pci_vtnet_rxwait(struct pci_vtnet_softc *sc)
{
- uint16_t ndesc;
-
- /*
- * We're just computing (a-b) in GF(216).
- *
- * The only glitch here is that in standard C,
- * uint16_t promotes to (signed) int when int has
- * more than 16 bits (pretty much always now), so
- * we have to force it back to unsigned.
- */
- ndesc = (unsigned)*hq->hq_avail_idx - (unsigned)hq->hq_cur_aidx;
-
- assert(ndesc <= hq->hq_size);
-
- return (ndesc);
-}
-static uint16_t
-pci_vtnet_qsize(int qnum)
-{
- /* XXX no ctl queue currently */
- if (qnum == VTNET_CTLQ) {
- return (0);
+ pthread_mutex_lock(&sc->rx_mtx);
+ while (sc->rx_in_progress) {
+ pthread_mutex_unlock(&sc->rx_mtx);
+ usleep(10000);
+ pthread_mutex_lock(&sc->rx_mtx);
}
-
- /* XXX fixed currently. Maybe different for tx/rx/ctl */
- return (VTNET_RINGSZ);
+ pthread_mutex_unlock(&sc->rx_mtx);
}
static void
-pci_vtnet_ring_reset(struct pci_vtnet_softc *sc, int ring)
+pci_vtnet_reset(void *vsc)
{
- struct vring_hqueue *hq;
+ struct pci_vtnet_softc *sc = vsc;
- assert(ring < VTNET_MAXQ);
+ DPRINTF(("vtnet: device reset requested !\n"));
- hq = &sc->vsc_hq[ring];
+ sc->resetting = 1;
/*
- * Reset all soft state
+ * Wait for the transmit and receive threads to finish their
+ * processing.
*/
- hq->hq_cur_aidx = 0;
-}
+ pci_vtnet_txwait(sc);
+ pci_vtnet_rxwait(sc);
-static void
-pci_vtnet_update_status(struct pci_vtnet_softc *sc, uint32_t value)
-{
+ sc->vsc_rx_ready = 0;
- if (value == 0) {
- DPRINTF(("vtnet: device reset requested !\n"));
- pci_vtnet_ring_reset(sc, VTNET_RXQ);
- pci_vtnet_ring_reset(sc, VTNET_TXQ);
- sc->vsc_rx_ready = 0;
- }
+ /* now reset rings, MSI-X vectors, and negotiated capabilities */
+ vi_reset_dev(&sc->vsc_vs);
- sc->vsc_status = value;
+ sc->resetting = 0;
}
/*
@@ -236,7 +226,7 @@ static void
pci_vtnet_tap_tx(struct pci_vtnet_softc *sc, struct iovec *iov, int iovcnt,
int len)
{
- char pad[60];
+ static char pad[60]; /* all zero bytes */
if (sc->vsc_tapfd == -1)
return;
@@ -247,7 +237,6 @@ pci_vtnet_tap_tx(struct pci_vtnet_softc *sc, struct iovec *iov, int iovcnt,
* there is always an extra iov available by the caller.
*/
if (len < 60) {
- memset(pad, 0, 60 - len);
iov[iovcnt].iov_base = pad;
iov[iovcnt].iov_len = 60 - len;
iovcnt++;
@@ -267,15 +256,11 @@ static uint8_t dummybuf[2048];
static void
pci_vtnet_tap_rx(struct pci_vtnet_softc *sc)
{
- struct virtio_desc *vd;
- struct virtio_used *vu;
- struct vring_hqueue *hq;
+ struct vqueue_info *vq;
struct virtio_net_rxhdr *vrx;
uint8_t *buf;
- int i;
int len;
- int ndescs;
- int didx, uidx, aidx; /* descriptor, avail and used index */
+ struct iovec iov;
/*
* Should never be called without a valid tap fd
@@ -284,9 +269,9 @@ pci_vtnet_tap_rx(struct pci_vtnet_softc *sc)
/*
* But, will be called when the rx ring hasn't yet
- * been set up.
+ * been set up or the guest is resetting the device.
*/
- if (sc->vsc_rx_ready == 0) {
+ if (!sc->vsc_rx_ready || sc->resetting) {
/*
* Drop the packet and try later.
*/
@@ -295,51 +280,45 @@ pci_vtnet_tap_rx(struct pci_vtnet_softc *sc)
}
/*
- * Calculate the number of available rx buffers
+ * Check for available rx buffers
*/
- hq = &sc->vsc_hq[VTNET_RXQ];
-
- ndescs = hq_num_avail(hq);
-
- if (ndescs == 0) {
- /*
- * Need to wait for host notification to read
- */
- if (sc->vsc_rxpend == 0) {
- WPRINTF(("vtnet: no rx descriptors !\n"));
- sc->vsc_rxpend = 1;
- }
-
+ vq = &sc->vsc_queues[VTNET_RXQ];
+ vq_startchains(vq);
+ if (!vq_has_descs(vq)) {
/*
- * Drop the packet and try later
+ * Drop the packet and try later. Interrupt on
+ * empty, if that's negotiated.
*/
(void) read(sc->vsc_tapfd, dummybuf, sizeof(dummybuf));
+ vq_endchains(vq, 1);
return;
}
- aidx = hq->hq_cur_aidx;
- uidx = *hq->hq_used_idx;
- for (i = 0; i < ndescs; i++) {
+ do {
/*
- * 'aidx' indexes into the an array of descriptor indexes
+ * Get descriptor chain, which should have just
+ * one descriptor in it.
+ * ??? allow guests to use multiple descs?
*/
- didx = hq->hq_avail_ring[aidx % hq->hq_size];
- assert(didx >= 0 && didx < hq->hq_size);
-
- vd = &hq->hq_dtable[didx];
+ assert(vq_getchain(vq, &iov, 1, NULL) == 1);
/*
* Get a pointer to the rx header, and use the
* data immediately following it for the packet buffer.
*/
- vrx = paddr_guest2host(vtnet_ctx(sc), vd->vd_addr, vd->vd_len);
+ vrx = iov.iov_base;
buf = (uint8_t *)(vrx + 1);
len = read(sc->vsc_tapfd, buf,
- vd->vd_len - sizeof(struct virtio_net_rxhdr));
+ iov.iov_len - sizeof(struct virtio_net_rxhdr));
if (len < 0 && errno == EWOULDBLOCK) {
- break;
+ /*
+ * No more packets, but still some avail ring
+ * entries. Interrupt if needed/appropriate.
+ */
+ vq_endchains(vq, 0);
+ return;
}
/*
@@ -351,30 +330,13 @@ pci_vtnet_tap_rx(struct pci_vtnet_softc *sc)
vrx->vrh_bufs = 1;
/*
- * Write this descriptor into the used ring
+ * Release this chain and handle more chains.
*/
- vu = &hq->hq_used_ring[uidx % hq->hq_size];
- vu->vu_idx = didx;
- vu->vu_tlen = len + sizeof(struct virtio_net_rxhdr);
- uidx++;
- aidx++;
- }
+ vq_relchain(vq, len + sizeof(struct virtio_net_rxhdr));
+ } while (vq_has_descs(vq));
- /*
- * Update the used pointer, and signal an interrupt if allowed
- */
- *hq->hq_used_idx = uidx;
- hq->hq_cur_aidx = aidx;
-
- if ((*hq->hq_avail_flags & VRING_AVAIL_F_NO_INTERRUPT) == 0) {
- if (use_msix) {
- pci_generate_msix(sc->vsc_pi,
- sc->vsc_msix_table_idx[VTNET_RXQ]);
- } else {
- sc->vsc_isr |= 1;
- pci_generate_msi(sc->vsc_pi, 0);
- }
- }
+ /* Interrupt if needed, including for NOTIFY_ON_EMPTY. */
+ vq_endchains(vq, 1);
}
static void
@@ -382,198 +344,227 @@ pci_vtnet_tap_callback(int fd, enum ev_type type, void *param)
{
struct pci_vtnet_softc *sc = param;
- pthread_mutex_lock(&sc->vsc_mtx);
+ pthread_mutex_lock(&sc->rx_mtx);
+ sc->rx_in_progress = 1;
pci_vtnet_tap_rx(sc);
- pthread_mutex_unlock(&sc->vsc_mtx);
+ sc->rx_in_progress = 0;
+ pthread_mutex_unlock(&sc->rx_mtx);
}
static void
-pci_vtnet_ping_rxq(struct pci_vtnet_softc *sc)
+pci_vtnet_ping_rxq(void *vsc, struct vqueue_info *vq)
{
+ struct pci_vtnet_softc *sc = vsc;
+
/*
* A qnotify means that the rx process can now begin
*/
if (sc->vsc_rx_ready == 0) {
sc->vsc_rx_ready = 1;
}
-
- /*
- * If the rx queue was empty, attempt to receive a
- * packet that was previously blocked due to no rx bufs
- * available
- */
- if (sc->vsc_rxpend) {
- WPRINTF(("vtnet: rx resumed\n\r"));
- sc->vsc_rxpend = 0;
- pci_vtnet_tap_rx(sc);
- }
}
static void
-pci_vtnet_proctx(struct pci_vtnet_softc *sc, struct vring_hqueue *hq)
+pci_vtnet_proctx(struct pci_vtnet_softc *sc, struct vqueue_info *vq)
{
struct iovec iov[VTNET_MAXSEGS + 1];
- struct virtio_desc *vd;
- struct virtio_used *vu;
- int i;
- int plen;
- int tlen;
- int uidx, aidx, didx;
-
- uidx = *hq->hq_used_idx;
- aidx = hq->hq_cur_aidx;
- didx = hq->hq_avail_ring[aidx % hq->hq_size];
- assert(didx >= 0 && didx < hq->hq_size);
-
- vd = &hq->hq_dtable[didx];
+ int i, n;
+ int plen, tlen;
/*
- * Run through the chain of descriptors, ignoring the
- * first header descriptor. However, include the header
- * length in the total length that will be put into the
- * used queue.
+ * Obtain chain of descriptors. The first one is
+ * really the header descriptor, so we need to sum
+ * up two lengths: packet length and transfer length.
*/
- tlen = vd->vd_len;
- vd = &hq->hq_dtable[vd->vd_next];
-
- for (i = 0, plen = 0;
- i < VTNET_MAXSEGS;
- i++, vd = &hq->hq_dtable[vd->vd_next]) {
- iov[i].iov_base = paddr_guest2host(vtnet_ctx(sc),
- vd->vd_addr, vd->vd_len);
- iov[i].iov_len = vd->vd_len;
- plen += vd->vd_len;
- tlen += vd->vd_len;
-
- if ((vd->vd_flags & VRING_DESC_F_NEXT) == 0)
- break;
+ n = vq_getchain(vq, iov, VTNET_MAXSEGS, NULL);
+ assert(n >= 1 && n <= VTNET_MAXSEGS);
+ plen = 0;
+ tlen = iov[0].iov_len;
+ for (i = 1; i < n; i++) {
+ plen += iov[i].iov_len;
+ tlen += iov[i].iov_len;
}
- assert(i < VTNET_MAXSEGS);
- DPRINTF(("virtio: packet send, %d bytes, %d segs\n\r", plen, i + 1));
- pci_vtnet_tap_tx(sc, iov, i + 1, plen);
+ DPRINTF(("virtio: packet send, %d bytes, %d segs\n\r", plen, n));
+ pci_vtnet_tap_tx(sc, &iov[1], n - 1, plen);
- /*
- * Return this chain back to the host
- */
- vu = &hq->hq_used_ring[uidx % hq->hq_size];
- vu->vu_idx = didx;
- vu->vu_tlen = tlen;
- hq->hq_cur_aidx = aidx + 1;
- *hq->hq_used_idx = uidx + 1;
-
- /*
- * Generate an interrupt if able
- */
- if ((*hq->hq_avail_flags & VRING_AVAIL_F_NO_INTERRUPT) == 0) {
- if (use_msix) {
- pci_generate_msix(sc->vsc_pi,
- sc->vsc_msix_table_idx[VTNET_TXQ]);
- } else {
- sc->vsc_isr |= 1;
- pci_generate_msi(sc->vsc_pi, 0);
- }
- }
+ /* chain is processed, release it and set tlen */
+ vq_relchain(vq, tlen);
}
static void
-pci_vtnet_ping_txq(struct pci_vtnet_softc *sc)
+pci_vtnet_ping_txq(void *vsc, struct vqueue_info *vq)
{
- struct vring_hqueue *hq = &sc->vsc_hq[VTNET_TXQ];
- int i;
- int ndescs;
+ struct pci_vtnet_softc *sc = vsc;
/*
- * Calculate number of ring entries to process
+ * Any ring entries to process?
*/
- ndescs = hq_num_avail(hq);
-
- if (ndescs == 0)
+ if (!vq_has_descs(vq))
return;
- /*
- * Run through all the entries, placing them into iovecs and
- * sending when an end-of-packet is found
- */
- for (i = 0; i < ndescs; i++)
- pci_vtnet_proctx(sc, hq);
+ /* Signal the tx thread for processing */
+ pthread_mutex_lock(&sc->tx_mtx);
+ if (sc->tx_in_progress == 0)
+ pthread_cond_signal(&sc->tx_cond);
+ pthread_mutex_unlock(&sc->tx_mtx);
}
-static void
-pci_vtnet_ping_ctlq(struct pci_vtnet_softc *sc)
+/*
+ * Thread which will handle processing of TX desc
+ */
+static void *
+pci_vtnet_tx_thread(void *param)
{
+ struct pci_vtnet_softc *sc = param;
+ struct vqueue_info *vq;
+ int have_work, error;
+
+ vq = &sc->vsc_queues[VTNET_TXQ];
+
+ /*
+ * Let us wait till the tx queue pointers get initialised &
+ * first tx signaled
+ */
+ pthread_mutex_lock(&sc->tx_mtx);
+ error = pthread_cond_wait(&sc->tx_cond, &sc->tx_mtx);
+ assert(error == 0);
+
+ for (;;) {
+ /* note - tx mutex is locked here */
+ do {
+ if (sc->resetting)
+ have_work = 0;
+ else
+ have_work = vq_has_descs(vq);
+
+ if (!have_work) {
+ sc->tx_in_progress = 0;
+ error = pthread_cond_wait(&sc->tx_cond,
+ &sc->tx_mtx);
+ assert(error == 0);
+ }
+ } while (!have_work);
+ sc->tx_in_progress = 1;
+ pthread_mutex_unlock(&sc->tx_mtx);
- DPRINTF(("vtnet: control qnotify!\n\r"));
+ vq_startchains(vq);
+ do {
+ /*
+ * Run through entries, placing them into
+ * iovecs and sending when an end-of-packet
+ * is found
+ */
+ pci_vtnet_proctx(sc, vq);
+ } while (vq_has_descs(vq));
+
+ /*
+ * Generate an interrupt if needed.
+ */
+ vq_endchains(vq, 1);
+
+ pthread_mutex_lock(&sc->tx_mtx);
+ }
}
+#ifdef notyet
static void
-pci_vtnet_ring_init(struct pci_vtnet_softc *sc, uint64_t pfn)
+pci_vtnet_ping_ctlq(void *vsc, struct vqueue_info *vq)
{
- struct vring_hqueue *hq;
- int qnum = sc->vsc_curq;
-
- assert(qnum < VTNET_MAXQ);
- sc->vsc_pfn[qnum] = pfn << VRING_PFN;
-
- /*
- * Set up host pointers to the various parts of the
- * queue
- */
- hq = &sc->vsc_hq[qnum];
- hq->hq_size = pci_vtnet_qsize(qnum);
-
- hq->hq_dtable = paddr_guest2host(vtnet_ctx(sc), pfn << VRING_PFN,
- vring_size(hq->hq_size));
- hq->hq_avail_flags = (uint16_t *)(hq->hq_dtable + hq->hq_size);
- hq->hq_avail_idx = hq->hq_avail_flags + 1;
- hq->hq_avail_ring = hq->hq_avail_flags + 2;
- hq->hq_used_flags = (uint16_t *)roundup2((uintptr_t)hq->hq_avail_ring,
- VRING_ALIGN);
- hq->hq_used_idx = hq->hq_used_flags + 1;
- hq->hq_used_ring = (struct virtio_used *)(hq->hq_used_flags + 2);
+ DPRINTF(("vtnet: control qnotify!\n\r"));
+}
+#endif
- /*
- * Initialize queue indexes
- */
- hq->hq_cur_aidx = 0;
+static int
+pci_vtnet_parsemac(char *mac_str, uint8_t *mac_addr)
+{
+ struct ether_addr *ea;
+ char *tmpstr;
+ char zero_addr[ETHER_ADDR_LEN] = { 0, 0, 0, 0, 0, 0 };
+
+ tmpstr = strsep(&mac_str,"=");
+
+ if ((mac_str != NULL) && (!strcmp(tmpstr,"mac"))) {
+ ea = ether_aton(mac_str);
+
+ if (ea == NULL || ETHER_IS_MULTICAST(ea->octet) ||
+ memcmp(ea->octet, zero_addr, ETHER_ADDR_LEN) == 0) {
+ fprintf(stderr, "Invalid MAC %s\n", mac_str);
+ return (EINVAL);
+ } else
+ memcpy(mac_addr, ea->octet, ETHER_ADDR_LEN);
+ }
+
+ return (0);
}
+
static int
pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
{
MD5_CTX mdctx;
unsigned char digest[16];
char nstr[80];
+ char tname[MAXCOMLEN + 1];
struct pci_vtnet_softc *sc;
const char *env_msi;
+ char *devname;
+ char *vtopts;
+ int mac_provided;
+ int use_msix;
sc = malloc(sizeof(struct pci_vtnet_softc));
memset(sc, 0, sizeof(struct pci_vtnet_softc));
- pi->pi_arg = sc;
- sc->vsc_pi = pi;
-
pthread_mutex_init(&sc->vsc_mtx, NULL);
+
+ vi_softc_linkup(&sc->vsc_vs, &vtnet_vi_consts, sc, pi, sc->vsc_queues);
+ sc->vsc_queues[VTNET_RXQ].vq_qsize = VTNET_RINGSZ;
+ sc->vsc_queues[VTNET_RXQ].vq_notify = pci_vtnet_ping_rxq;
+ sc->vsc_queues[VTNET_TXQ].vq_qsize = VTNET_RINGSZ;
+ sc->vsc_queues[VTNET_TXQ].vq_notify = pci_vtnet_ping_txq;
+#ifdef notyet
+ sc->vsc_queues[VTNET_CTLQ].vq_qsize = VTNET_RINGSZ;
+ sc->vsc_queues[VTNET_CTLQ].vq_notify = pci_vtnet_ping_ctlq;
+#endif
/*
* Use MSI if set by user
*/
+ use_msix = 1;
if ((env_msi = getenv("BHYVE_USE_MSI")) != NULL) {
if (strcasecmp(env_msi, "yes") == 0)
use_msix = 0;
}
/*
- * Attempt to open the tap device
+ * Attempt to open the tap device and read the MAC address
+ * if specified
*/
+ mac_provided = 0;
sc->vsc_tapfd = -1;
if (opts != NULL) {
char tbuf[80];
+ int err;
+
+ devname = vtopts = strdup(opts);
+ (void) strsep(&vtopts, ",");
+
+ if (vtopts != NULL) {
+ err = pci_vtnet_parsemac(vtopts, sc->vsc_config.mac);
+ if (err != 0) {
+ free(devname);
+ return (err);
+ }
+ mac_provided = 1;
+ }
strcpy(tbuf, "/dev/");
- strlcat(tbuf, opts, sizeof(tbuf));
+ strlcat(tbuf, devname, sizeof(tbuf));
+
+ free(devname);
sc->vsc_tapfd = open(tbuf, O_RDWR);
if (sc->vsc_tapfd == -1) {
@@ -603,285 +594,96 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
}
/*
- * The MAC address is the standard NetApp OUI of 00-a0-98,
- * followed by an MD5 of the vm name. The slot/func number is
- * prepended to this for slots other than 1:0, so that
- * a bootloader can netboot from the equivalent of slot 1.
+ * The default MAC address is the standard NetApp OUI of 00-a0-98,
+ * followed by an MD5 of the PCI slot/func number and dev name
*/
- if (pi->pi_slot == 1 && pi->pi_func == 0) {
- strncpy(nstr, vmname, sizeof(nstr));
- } else {
+ if (!mac_provided) {
snprintf(nstr, sizeof(nstr), "%d-%d-%s", pi->pi_slot,
- pi->pi_func, vmname);
+ pi->pi_func, vmname);
+
+ MD5Init(&mdctx);
+ MD5Update(&mdctx, nstr, strlen(nstr));
+ MD5Final(digest, &mdctx);
+
+ sc->vsc_config.mac[0] = 0x00;
+ sc->vsc_config.mac[1] = 0xa0;
+ sc->vsc_config.mac[2] = 0x98;
+ sc->vsc_config.mac[3] = digest[0];
+ sc->vsc_config.mac[4] = digest[1];
+ sc->vsc_config.mac[5] = digest[2];
}
- MD5Init(&mdctx);
- MD5Update(&mdctx, nstr, strlen(nstr));
- MD5Final(digest, &mdctx);
-
- sc->vsc_macaddr[0] = 0x00;
- sc->vsc_macaddr[1] = 0xa0;
- sc->vsc_macaddr[2] = 0x98;
- sc->vsc_macaddr[3] = digest[0];
- sc->vsc_macaddr[4] = digest[1];
- sc->vsc_macaddr[5] = digest[2];
-
/* initialize config space */
pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_NET);
pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR);
pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_NETWORK);
pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_NET);
-
- if (use_msix) {
- /* MSI-X support */
- int i;
-
- for (i = 0; i < VTNET_MAXQ; i++)
- sc->vsc_msix_table_idx[i] = VIRTIO_MSI_NO_VECTOR;
- /*
- * BAR 1 used to map MSI-X table and PBA
- */
- if (pci_emul_add_msixcap(pi, VTNET_MAXQ, 1))
- return (1);
- } else {
- /* MSI support */
- pci_emul_add_msicap(pi, 1);
- }
+ /* link always up */
+ sc->vsc_config.status = 1;
- pci_emul_alloc_bar(pi, 0, PCIBAR_IO, VTNET_REGSZ);
+ /* use BAR 1 to map MSI-X table and PBA, if we're using MSI-X */
+ if (vi_intr_init(&sc->vsc_vs, 1, use_msix))
+ return (1);
- return (0);
-}
+ /* use BAR 0 to map config regs in IO space */
+ vi_set_io_bar(&sc->vsc_vs, 0);
-/*
- * Function pointer array to handle queue notifications
- */
-static void (*pci_vtnet_qnotify[VTNET_MAXQ])(struct pci_vtnet_softc *) = {
- pci_vtnet_ping_rxq,
- pci_vtnet_ping_txq,
- pci_vtnet_ping_ctlq
-};
+ sc->resetting = 0;
-static uint64_t
-vtnet_adjust_offset(struct pci_devinst *pi, uint64_t offset)
-{
- /*
- * Device specific offsets used by guest would change based on
- * whether MSI-X capability is enabled or not
+ sc->rx_in_progress = 0;
+ pthread_mutex_init(&sc->rx_mtx, NULL);
+
+ /*
+ * Initialize tx semaphore & spawn TX processing thread.
+ * As of now, only one thread for TX desc processing is
+ * spawned.
*/
- if (!pci_msix_enabled(pi)) {
- if (offset >= VTCFG_R_MSIX)
- return (offset + (VTCFG_R_CFG1 - VTCFG_R_MSIX));
- }
+ sc->tx_in_progress = 0;
+ pthread_mutex_init(&sc->tx_mtx, NULL);
+ pthread_cond_init(&sc->tx_cond, NULL);
+ pthread_create(&sc->tx_tid, NULL, pci_vtnet_tx_thread, (void *)sc);
+ snprintf(tname, sizeof(tname), "%s vtnet%d tx", vmname, pi->pi_slot);
+ pthread_set_name_np(sc->tx_tid, tname);
- return (offset);
+ return (0);
}
-static void
-pci_vtnet_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi,
- int baridx, uint64_t offset, int size, uint64_t value)
+static int
+pci_vtnet_cfgwrite(void *vsc, int offset, int size, uint32_t value)
{
- struct pci_vtnet_softc *sc = pi->pi_arg;
+ struct pci_vtnet_softc *sc = vsc;
void *ptr;
- if (use_msix) {
- if (baridx == pci_msix_table_bar(pi) ||
- baridx == pci_msix_pba_bar(pi)) {
- pci_emul_msix_twrite(pi, offset, size, value);
- return;
- }
- }
-
- assert(baridx == 0);
-
- if (offset + size > pci_vtnet_iosize(pi)) {
- DPRINTF(("vtnet_write: 2big, offset %ld size %d\n",
- offset, size));
- return;
- }
-
- pthread_mutex_lock(&sc->vsc_mtx);
-
- offset = vtnet_adjust_offset(pi, offset);
-
- switch (offset) {
- case VTCFG_R_GUESTCAP:
- assert(size == 4);
- sc->vsc_features = value & VTNET_S_HOSTCAPS;
- break;
- case VTCFG_R_PFN:
- assert(size == 4);
- pci_vtnet_ring_init(sc, value);
- break;
- case VTCFG_R_QSEL:
- assert(size == 2);
- assert(value < VTNET_MAXQ);
- sc->vsc_curq = value;
- break;
- case VTCFG_R_QNOTIFY:
- assert(size == 2);
- assert(value < VTNET_MAXQ);
- (*pci_vtnet_qnotify[value])(sc);
- break;
- case VTCFG_R_STATUS:
- assert(size == 1);
- pci_vtnet_update_status(sc, value);
- break;
- case VTCFG_R_CFGVEC:
- assert(size == 2);
- sc->vsc_msix_table_idx[VTNET_CTLQ] = value;
- break;
- case VTCFG_R_QVEC:
- assert(size == 2);
- assert(sc->vsc_curq != VTNET_CTLQ);
- sc->vsc_msix_table_idx[sc->vsc_curq] = value;
- break;
- case VTNET_R_CFG0:
- case VTNET_R_CFG1:
- case VTNET_R_CFG2:
- case VTNET_R_CFG3:
- case VTNET_R_CFG4:
- case VTNET_R_CFG5:
- assert((size + offset) <= (VTNET_R_CFG5 + 1));
- ptr = &sc->vsc_macaddr[offset - VTNET_R_CFG0];
+ if (offset < 6) {
+ assert(offset + size <= 6);
/*
* The driver is allowed to change the MAC address
*/
- sc->vsc_macaddr[offset - VTNET_R_CFG0] = value;
- if (size == 1) {
- *(uint8_t *) ptr = value;
- } else if (size == 2) {
- *(uint16_t *) ptr = value;
- } else {
- *(uint32_t *) ptr = value;
- }
- break;
- case VTCFG_R_HOSTCAP:
- case VTCFG_R_QNUM:
- case VTCFG_R_ISR:
- case VTNET_R_CFG6:
- case VTNET_R_CFG7:
- DPRINTF(("vtnet: write to readonly reg %ld\n\r", offset));
- break;
- default:
- DPRINTF(("vtnet: unknown i/o write offset %ld\n\r", offset));
- value = 0;
- break;
+ ptr = &sc->vsc_config.mac[offset];
+ memcpy(ptr, &value, size);
+ } else {
+ DPRINTF(("vtnet: write to readonly reg %d\n\r", offset));
+ return (1);
}
-
- pthread_mutex_unlock(&sc->vsc_mtx);
+ return (0);
}
-uint64_t
-pci_vtnet_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi,
- int baridx, uint64_t offset, int size)
+static int
+pci_vtnet_cfgread(void *vsc, int offset, int size, uint32_t *retval)
{
- struct pci_vtnet_softc *sc = pi->pi_arg;
+ struct pci_vtnet_softc *sc = vsc;
void *ptr;
- uint64_t value;
-
- if (use_msix) {
- if (baridx == pci_msix_table_bar(pi) ||
- baridx == pci_msix_pba_bar(pi)) {
- return (pci_emul_msix_tread(pi, offset, size));
- }
- }
- assert(baridx == 0);
-
- if (offset + size > pci_vtnet_iosize(pi)) {
- DPRINTF(("vtnet_read: 2big, offset %ld size %d\n",
- offset, size));
- return (0);
- }
-
- pthread_mutex_lock(&sc->vsc_mtx);
-
- offset = vtnet_adjust_offset(pi, offset);
-
- switch (offset) {
- case VTCFG_R_HOSTCAP:
- assert(size == 4);
- value = VTNET_S_HOSTCAPS;
- break;
- case VTCFG_R_GUESTCAP:
- assert(size == 4);
- value = sc->vsc_features; /* XXX never read ? */
- break;
- case VTCFG_R_PFN:
- assert(size == 4);
- value = sc->vsc_pfn[sc->vsc_curq] >> VRING_PFN;
- break;
- case VTCFG_R_QNUM:
- assert(size == 2);
- value = pci_vtnet_qsize(sc->vsc_curq);
- break;
- case VTCFG_R_QSEL:
- assert(size == 2);
- value = sc->vsc_curq; /* XXX never read ? */
- break;
- case VTCFG_R_QNOTIFY:
- assert(size == 2);
- value = sc->vsc_curq; /* XXX never read ? */
- break;
- case VTCFG_R_STATUS:
- assert(size == 1);
- value = sc->vsc_status;
- break;
- case VTCFG_R_ISR:
- assert(size == 1);
- value = sc->vsc_isr;
- sc->vsc_isr = 0; /* a read clears this flag */
- break;
- case VTCFG_R_CFGVEC:
- assert(size == 2);
- value = sc->vsc_msix_table_idx[VTNET_CTLQ];
- break;
- case VTCFG_R_QVEC:
- assert(size == 2);
- assert(sc->vsc_curq != VTNET_CTLQ);
- value = sc->vsc_msix_table_idx[sc->vsc_curq];
- break;
- case VTNET_R_CFG0:
- case VTNET_R_CFG1:
- case VTNET_R_CFG2:
- case VTNET_R_CFG3:
- case VTNET_R_CFG4:
- case VTNET_R_CFG5:
- assert((size + offset) <= (VTNET_R_CFG5 + 1));
- ptr = &sc->vsc_macaddr[offset - VTNET_R_CFG0];
- if (size == 1) {
- value = *(uint8_t *) ptr;
- } else if (size == 2) {
- value = *(uint16_t *) ptr;
- } else {
- value = *(uint32_t *) ptr;
- }
- break;
- case VTNET_R_CFG6:
- assert(size != 4);
- value = 0x01; /* XXX link always up */
- break;
- case VTNET_R_CFG7:
- assert(size == 1);
- value = 0; /* XXX link status in LSB */
- break;
- default:
- DPRINTF(("vtnet: unknown i/o read offset %ld\n\r", offset));
- value = 0;
- break;
- }
-
- pthread_mutex_unlock(&sc->vsc_mtx);
-
- return (value);
+ ptr = (uint8_t *)&sc->vsc_config + offset;
+ memcpy(retval, ptr, size);
+ return (0);
}
struct pci_devemu pci_de_vnet = {
.pe_emu = "virtio-net",
.pe_init = pci_vtnet_init,
- .pe_barwrite = pci_vtnet_write,
- .pe_barread = pci_vtnet_read
+ .pe_barwrite = vi_pci_write,
+ .pe_barread = vi_pci_read
};
PCI_EMUL_SET(pci_de_vnet);
diff --git a/usr.sbin/bhyve/rtc.c b/usr.sbin/bhyve/rtc.c
index df21ac8..a0e2c6a 100644
--- a/usr.sbin/bhyve/rtc.c
+++ b/usr.sbin/bhyve/rtc.c
@@ -33,10 +33,15 @@ __FBSDID("$FreeBSD$");
#include <sys/time.h>
#include <stdio.h>
+#include <string.h>
#include <time.h>
#include <assert.h>
+#include <machine/vmm.h>
+#include <vmmapi.h>
+
#include "inout.h"
+#include "rtc.h"
#define IO_RTC 0x70
@@ -64,16 +69,30 @@ __FBSDID("$FreeBSD$");
#define RTC_STATUSD 0x0d /* status register D (R) Lost Power */
#define RTCSD_PWR 0x80 /* clock power OK */
-#define RTC_DIAG 0x0e
+#define RTC_NVRAM_START 0x0e
+#define RTC_NVRAM_END 0x7f
+#define RTC_NVRAM_SZ (128 - RTC_NVRAM_START)
+#define nvoff(x) ((x) - RTC_NVRAM_START)
+#define RTC_DIAG 0x0e
#define RTC_RSTCODE 0x0f
-
#define RTC_EQUIPMENT 0x14
+#define RTC_LMEM_LSB 0x34
+#define RTC_LMEM_MSB 0x35
+#define RTC_HMEM_LSB 0x5b
+#define RTC_HMEM_SB 0x5c
+#define RTC_HMEM_MSB 0x5d
+
+#define m_64KB (64*1024)
+#define m_16MB (16*1024*1024)
+#define m_4GB (4ULL*1024*1024*1024)
static int addr;
+static uint8_t rtc_nvram[RTC_NVRAM_SZ];
+
/* XXX initialize these to default values as they would be from BIOS */
-static uint8_t status_a, status_b, rstcode;
+static uint8_t status_a, status_b;
static u_char const bin2bcd_data[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
@@ -135,14 +154,11 @@ rtc_addr_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
case RTC_DAY:
case RTC_MONTH:
case RTC_YEAR:
- case RTC_CENTURY:
case RTC_STATUSA:
case RTC_STATUSB:
case RTC_INTR:
case RTC_STATUSD:
- case RTC_DIAG:
- case RTC_RSTCODE:
- case RTC_EQUIPMENT:
+ case RTC_NVRAM_START ... RTC_NVRAM_END:
break;
default:
return (-1);
@@ -217,9 +233,6 @@ rtc_data_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
case RTC_YEAR:
*eax = rtcout(tm.tm_year % 100);
return (0);
- case RTC_CENTURY:
- *eax = rtcout(tm.tm_year / 100);
- break;
case RTC_STATUSA:
*eax = status_a;
return (0);
@@ -232,14 +245,8 @@ rtc_data_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
case RTC_STATUSD:
*eax = RTCSD_PWR;
return (0);
- case RTC_DIAG:
- *eax = 0;
- return (0);
- case RTC_RSTCODE:
- *eax = rstcode;
- return (0);
- case RTC_EQUIPMENT:
- *eax = 0;
+ case RTC_NVRAM_START ... RTC_NVRAM_END:
+ *eax = rtc_nvram[addr - RTC_NVRAM_START];
return (0);
default:
return (-1);
@@ -259,9 +266,6 @@ rtc_data_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
case RTC_STATUSD:
/* ignore write */
break;
- case RTC_RSTCODE:
- rstcode = *eax;
- break;
case RTC_SEC:
case RTC_MIN:
case RTC_HRS:
@@ -269,16 +273,58 @@ rtc_data_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
case RTC_DAY:
case RTC_MONTH:
case RTC_YEAR:
- case RTC_CENTURY:
/*
* Ignore writes to the time of day registers
*/
break;
+ case RTC_NVRAM_START ... RTC_NVRAM_END:
+ rtc_nvram[addr - RTC_NVRAM_START] = *eax;
+ break;
default:
return (-1);
}
return (0);
}
+void
+rtc_init(struct vmctx *ctx)
+{
+ struct timeval cur;
+ struct tm tm;
+ size_t himem;
+ size_t lomem;
+ int err;
+
+ err = gettimeofday(&cur, NULL);
+ assert(err == 0);
+ (void) localtime_r(&cur.tv_sec, &tm);
+
+ memset(rtc_nvram, 0, sizeof(rtc_nvram));
+
+ rtc_nvram[nvoff(RTC_CENTURY)] = rtcout(tm.tm_year / 100);
+
+ /* XXX init diag/reset code/equipment/checksum ? */
+
+ /*
+ * Report guest memory size in nvram cells as required by UEFI.
+ * Little-endian encoding.
+ * 0x34/0x35 - 64KB chunks above 16MB, below 4GB
+ * 0x5b/0x5c/0x5d - 64KB chunks above 4GB
+ */
+ err = vm_get_memory_seg(ctx, 0, &lomem);
+ assert(err == 0);
+
+ lomem = (lomem - m_16MB) / m_64KB;
+ rtc_nvram[nvoff(RTC_LMEM_LSB)] = lomem;
+ rtc_nvram[nvoff(RTC_LMEM_MSB)] = lomem >> 8;
+
+ if (vm_get_memory_seg(ctx, m_4GB, &himem) == 0) {
+ himem /= m_64KB;
+ rtc_nvram[nvoff(RTC_HMEM_LSB)] = himem;
+ rtc_nvram[nvoff(RTC_HMEM_SB)] = himem >> 8;
+ rtc_nvram[nvoff(RTC_NVRAM_START)] = himem >> 16;
+ }
+}
+
INOUT_PORT(rtc, IO_RTC, IOPORT_F_INOUT, rtc_addr_handler);
INOUT_PORT(rtc, IO_RTC + 1, IOPORT_F_INOUT, rtc_data_handler);
diff --git a/usr.sbin/bhyve/rtc.h b/usr.sbin/bhyve/rtc.h
new file mode 100644
index 0000000..72cffb3
--- /dev/null
+++ b/usr.sbin/bhyve/rtc.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Peter Grehan <grehan@freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _RTC_H_
+#define _RTC_H_
+
+void rtc_init(struct vmctx *ctx);
+
+#endif /* _RTC_H_ */
diff --git a/usr.sbin/bhyve/virtio.c b/usr.sbin/bhyve/virtio.c
new file mode 100644
index 0000000..cdc9228
--- /dev/null
+++ b/usr.sbin/bhyve/virtio.c
@@ -0,0 +1,745 @@
+/*-
+ * Copyright (c) 2013 Chris Torek <torek @ torek net>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/uio.h>
+
+#include <stdio.h>
+#include <stdint.h>
+#include <pthread.h>
+
+#include "bhyverun.h"
+#include "pci_emul.h"
+#include "virtio.h"
+
+/*
+ * Functions for dealing with generalized "virtual devices" as
+ * defined by <https://www.google.com/#output=search&q=virtio+spec>
+ */
+
+/*
+ * In case we decide to relax the "virtio softc comes at the
+ * front of virtio-based device softc" constraint, let's use
+ * this to convert.
+ */
+#define DEV_SOFTC(vs) ((void *)(vs))
+
+/*
+ * Link a virtio_softc to its constants, the device softc, and
+ * the PCI emulation.
+ */
+void
+vi_softc_linkup(struct virtio_softc *vs, struct virtio_consts *vc,
+ void *dev_softc, struct pci_devinst *pi,
+ struct vqueue_info *queues)
+{
+ int i;
+
+ /* vs and dev_softc addresses must match */
+ assert((void *)vs == dev_softc);
+ vs->vs_vc = vc;
+ vs->vs_pi = pi;
+ pi->pi_arg = vs;
+
+ vs->vs_queues = queues;
+ for (i = 0; i < vc->vc_nvq; i++) {
+ queues[i].vq_vs = vs;
+ queues[i].vq_num = i;
+ }
+}
+
+/*
+ * Reset device (device-wide). This erases all queues, i.e.,
+ * all the queues become invalid (though we don't wipe out the
+ * internal pointers, we just clear the VQ_ALLOC flag).
+ *
+ * It resets negotiated features to "none".
+ *
+ * If MSI-X is enabled, this also resets all the vectors to NO_VECTOR.
+ */
+void
+vi_reset_dev(struct virtio_softc *vs)
+{
+ struct vqueue_info *vq;
+ int i, nvq;
+
+ nvq = vs->vs_vc->vc_nvq;
+ for (vq = vs->vs_queues, i = 0; i < nvq; vq++, i++) {
+ vq->vq_flags = 0;
+ vq->vq_last_avail = 0;
+ vq->vq_pfn = 0;
+ vq->vq_msix_idx = VIRTIO_MSI_NO_VECTOR;
+ }
+ vs->vs_negotiated_caps = 0;
+ vs->vs_curq = 0;
+ /* vs->vs_status = 0; -- redundant */
+ vs->vs_isr = 0;
+ vs->vs_msix_cfg_idx = VIRTIO_MSI_NO_VECTOR;
+}
+
+/*
+ * Set I/O BAR (usually 0) to map PCI config registers.
+ */
+void
+vi_set_io_bar(struct virtio_softc *vs, int barnum)
+{
+ size_t size;
+
+ /*
+ * ??? should we use CFG0 if MSI-X is disabled?
+ * Existing code did not...
+ */
+ size = VTCFG_R_CFG1 + vs->vs_vc->vc_cfgsize;
+ pci_emul_alloc_bar(vs->vs_pi, barnum, PCIBAR_IO, size);
+}
+
+/*
+ * Initialize MSI-X vector capabilities if we're to use MSI-X,
+ * or MSI capabilities if not.
+ *
+ * We assume we want one MSI-X vector per queue, here, plus one
+ * for the config vec.
+ */
+int
+vi_intr_init(struct virtio_softc *vs, int barnum, int use_msix)
+{
+ int nvec;
+
+ if (use_msix) {
+ vs->vs_flags |= VIRTIO_USE_MSIX;
+ vi_reset_dev(vs); /* set all vectors to NO_VECTOR */
+ nvec = vs->vs_vc->vc_nvq + 1;
+ if (pci_emul_add_msixcap(vs->vs_pi, nvec, barnum))
+ return (1);
+ } else {
+ vs->vs_flags &= ~VIRTIO_USE_MSIX;
+ pci_emul_add_msicap(vs->vs_pi, barnum);
+ }
+ return (0);
+}
+
+/*
+ * Initialize the currently-selected virtio queue (vs->vs_curq).
+ * The guest just gave us a page frame number, from which we can
+ * calculate the addresses of the queue.
+ */
+void
+vi_vq_init(struct virtio_softc *vs, uint32_t pfn)
+{
+ struct vqueue_info *vq;
+ uint64_t phys;
+ size_t size;
+ char *base;
+
+ vq = &vs->vs_queues[vs->vs_curq];
+ vq->vq_pfn = pfn;
+ phys = pfn << VRING_PFN;
+ size = vring_size(vq->vq_qsize);
+ base = paddr_guest2host(vs->vs_pi->pi_vmctx, phys, size);
+
+ /* First page(s) are descriptors... */
+ vq->vq_desc = (struct virtio_desc *)base;
+ base += vq->vq_qsize * sizeof(struct virtio_desc);
+
+ /* ... immediately followed by "avail" ring (entirely uint16_t's) */
+ vq->vq_avail = (struct vring_avail *)base;
+ base += (2 + vq->vq_qsize + 1) * sizeof(uint16_t);
+
+ /* Then it's rounded up to the next page... */
+ base = (char *)roundup2((uintptr_t)base, VRING_ALIGN);
+
+ /* ... and the last page(s) are the used ring. */
+ vq->vq_used = (struct vring_used *)base;
+
+ /* Mark queue as allocated, and start at 0 when we use it. */
+ vq->vq_flags = VQ_ALLOC;
+ vq->vq_last_avail = 0;
+}
+
+/*
+ * Helper inline for vq_getchain(): record the i'th "real"
+ * descriptor.
+ */
+static inline void
+_vq_record(int i, volatile struct virtio_desc *vd, struct vmctx *ctx,
+ struct iovec *iov, int n_iov, uint16_t *flags) {
+
+ if (i >= n_iov)
+ return;
+ iov[i].iov_base = paddr_guest2host(ctx, vd->vd_addr, vd->vd_len);
+ iov[i].iov_len = vd->vd_len;
+ if (flags != NULL)
+ flags[i] = vd->vd_flags;
+}
+#define VQ_MAX_DESCRIPTORS 512 /* see below */
+
+/*
+ * Examine the chain of descriptors starting at the "next one" to
+ * make sure that they describe a sensible request. If so, return
+ * the number of "real" descriptors that would be needed/used in
+ * acting on this request. This may be smaller than the number of
+ * available descriptors, e.g., if there are two available but
+ * they are two separate requests, this just returns 1. Or, it
+ * may be larger: if there are indirect descriptors involved,
+ * there may only be one descriptor available but it may be an
+ * indirect pointing to eight more. We return 8 in this case,
+ * i.e., we do not count the indirect descriptors, only the "real"
+ * ones.
+ *
+ * Basically, this vets the vd_flags and vd_next field of each
+ * descriptor and tells you how many are involved. Since some may
+ * be indirect, this also needs the vmctx (in the pci_devinst
+ * at vs->vs_pi) so that it can find indirect descriptors.
+ *
+ * As we process each descriptor, we copy and adjust it (guest to
+ * host address wise, also using the vmtctx) into the given iov[]
+ * array (of the given size). If the array overflows, we stop
+ * placing values into the array but keep processing descriptors,
+ * up to VQ_MAX_DESCRIPTORS, before giving up and returning -1.
+ * So you, the caller, must not assume that iov[] is as big as the
+ * return value (you can process the same thing twice to allocate
+ * a larger iov array if needed, or supply a zero length to find
+ * out how much space is needed).
+ *
+ * If you want to verify the WRITE flag on each descriptor, pass a
+ * non-NULL "flags" pointer to an array of "uint16_t" of the same size
+ * as n_iov and we'll copy each vd_flags field after unwinding any
+ * indirects.
+ *
+ * If some descriptor(s) are invalid, this prints a diagnostic message
+ * and returns -1. If no descriptors are ready now it simply returns 0.
+ *
+ * You are assumed to have done a vq_ring_ready() if needed (note
+ * that vq_has_descs() does one).
+ */
+int
+vq_getchain(struct vqueue_info *vq,
+ struct iovec *iov, int n_iov, uint16_t *flags)
+{
+ int i;
+ u_int ndesc, n_indir;
+ u_int idx, head, next;
+ volatile struct virtio_desc *vdir, *vindir, *vp;
+ struct vmctx *ctx;
+ struct virtio_softc *vs;
+ const char *name;
+
+ vs = vq->vq_vs;
+ name = vs->vs_vc->vc_name;
+
+ /*
+ * Note: it's the responsibility of the guest not to
+ * update vq->vq_avail->va_idx until all of the descriptors
+ * the guest has written are valid (including all their
+ * vd_next fields and vd_flags).
+ *
+ * Compute (last_avail - va_idx) in integers mod 2**16. This is
+ * the number of descriptors the device has made available
+ * since the last time we updated vq->vq_last_avail.
+ *
+ * We just need to do the subtraction as an unsigned int,
+ * then trim off excess bits.
+ */
+ idx = vq->vq_last_avail;
+ ndesc = (uint16_t)((u_int)vq->vq_avail->va_idx - idx);
+ if (ndesc == 0)
+ return (0);
+ if (ndesc > vq->vq_qsize) {
+ /* XXX need better way to diagnose issues */
+ fprintf(stderr,
+ "%s: ndesc (%u) out of range, driver confused?\r\n",
+ name, (u_int)ndesc);
+ return (-1);
+ }
+
+ /*
+ * Now count/parse "involved" descriptors starting from
+ * the head of the chain.
+ *
+ * To prevent loops, we could be more complicated and
+ * check whether we're re-visiting a previously visited
+ * index, but we just abort if the count gets excessive.
+ */
+ ctx = vs->vs_pi->pi_vmctx;
+ head = vq->vq_avail->va_ring[idx & (vq->vq_qsize - 1)];
+ next = head;
+ for (i = 0; i < VQ_MAX_DESCRIPTORS; next = vdir->vd_next) {
+ if (next >= vq->vq_qsize) {
+ fprintf(stderr,
+ "%s: descriptor index %u out of range, "
+ "driver confused?\r\n",
+ name, next);
+ return (-1);
+ }
+ vdir = &vq->vq_desc[next];
+ if ((vdir->vd_flags & VRING_DESC_F_INDIRECT) == 0) {
+ _vq_record(i, vdir, ctx, iov, n_iov, flags);
+ i++;
+ } else if ((vs->vs_negotiated_caps &
+ VIRTIO_RING_F_INDIRECT_DESC) == 0) {
+ fprintf(stderr,
+ "%s: descriptor has forbidden INDIRECT flag, "
+ "driver confused?\r\n",
+ name);
+ return (-1);
+ } else {
+ n_indir = vdir->vd_len / 16;
+ if ((vdir->vd_len & 0xf) || n_indir == 0) {
+ fprintf(stderr,
+ "%s: invalid indir len 0x%x, "
+ "driver confused?\r\n",
+ name, (u_int)vdir->vd_len);
+ return (-1);
+ }
+ vindir = paddr_guest2host(ctx,
+ vdir->vd_addr, vdir->vd_len);
+ /*
+ * Indirects start at the 0th, then follow
+ * their own embedded "next"s until those run
+ * out. Each one's indirect flag must be off
+ * (we don't really have to check, could just
+ * ignore errors...).
+ */
+ next = 0;
+ for (;;) {
+ vp = &vindir[next];
+ if (vp->vd_flags & VRING_DESC_F_INDIRECT) {
+ fprintf(stderr,
+ "%s: indirect desc has INDIR flag,"
+ " driver confused?\r\n",
+ name);
+ return (-1);
+ }
+ _vq_record(i, vp, ctx, iov, n_iov, flags);
+ if (++i > VQ_MAX_DESCRIPTORS)
+ goto loopy;
+ if ((vp->vd_flags & VRING_DESC_F_NEXT) == 0)
+ break;
+ next = vp->vd_next;
+ if (next >= n_indir) {
+ fprintf(stderr,
+ "%s: invalid next %u > %u, "
+ "driver confused?\r\n",
+ name, (u_int)next, n_indir);
+ return (-1);
+ }
+ }
+ }
+ if ((vdir->vd_flags & VRING_DESC_F_NEXT) == 0)
+ return (i);
+ }
+loopy:
+ fprintf(stderr,
+ "%s: descriptor loop? count > %d - driver confused?\r\n",
+ name, i);
+ return (-1);
+}
+
+/*
+ * Return the currently-first request chain to the guest, setting
+ * its I/O length to the provided value.
+ *
+ * (This chain is the one you handled when you called vq_getchain()
+ * and used its positive return value.)
+ */
+void
+vq_relchain(struct vqueue_info *vq, uint32_t iolen)
+{
+ uint16_t head, uidx, mask;
+ volatile struct vring_used *vuh;
+ volatile struct virtio_used *vue;
+
+ /*
+ * Notes:
+ * - mask is N-1 where N is a power of 2 so computes x % N
+ * - vuh points to the "used" data shared with guest
+ * - vue points to the "used" ring entry we want to update
+ * - head is the same value we compute in vq_iovecs().
+ *
+ * (I apologize for the two fields named vu_idx; the
+ * virtio spec calls the one that vue points to, "id"...)
+ */
+ mask = vq->vq_qsize - 1;
+ vuh = vq->vq_used;
+ head = vq->vq_avail->va_ring[vq->vq_last_avail++ & mask];
+
+ uidx = vuh->vu_idx;
+ vue = &vuh->vu_ring[uidx++ & mask];
+ vue->vu_idx = head; /* ie, vue->id = head */
+ vue->vu_tlen = iolen;
+ vuh->vu_idx = uidx;
+}
+
+/*
+ * Driver has finished processing "available" chains and calling
+ * vq_relchain on each one. If driver used all the available
+ * chains, used_all should be set.
+ *
+ * If the "used" index moved we may need to inform the guest, i.e.,
+ * deliver an interrupt. Even if the used index did NOT move we
+ * may need to deliver an interrupt, if the avail ring is empty and
+ * we are supposed to interrupt on empty.
+ *
+ * Note that used_all_avail is provided by the caller because it's
+ * a snapshot of the ring state when he decided to finish interrupt
+ * processing -- it's possible that descriptors became available after
+ * that point. (It's also typically a constant 1/True as well.)
+ */
+void
+vq_endchains(struct vqueue_info *vq, int used_all_avail)
+{
+ struct virtio_softc *vs;
+ uint16_t event_idx, new_idx, old_idx;
+ int intr;
+
+ /*
+ * Interrupt generation: if we're using EVENT_IDX,
+ * interrupt if we've crossed the event threshold.
+ * Otherwise interrupt is generated if we added "used" entries,
+ * but suppressed by VRING_AVAIL_F_NO_INTERRUPT.
+ *
+ * In any case, though, if NOTIFY_ON_EMPTY is set and the
+ * entire avail was processed, we need to interrupt always.
+ */
+ vs = vq->vq_vs;
+ new_idx = vq->vq_used->vu_idx;
+ old_idx = vq->vq_save_used;
+ if (used_all_avail &&
+ (vs->vs_negotiated_caps & VIRTIO_F_NOTIFY_ON_EMPTY))
+ intr = 1;
+ else if (vs->vs_flags & VIRTIO_EVENT_IDX) {
+ event_idx = VQ_USED_EVENT_IDX(vq);
+ /*
+ * This calculation is per docs and the kernel
+ * (see src/sys/dev/virtio/virtio_ring.h).
+ */
+ intr = (uint16_t)(new_idx - event_idx - 1) <
+ (uint16_t)(new_idx - old_idx);
+ } else {
+ intr = new_idx != old_idx &&
+ !(vq->vq_avail->va_flags & VRING_AVAIL_F_NO_INTERRUPT);
+ }
+ if (intr)
+ vq_interrupt(vs, vq);
+}
+
+/* Note: these are in sorted order to make for a fast search */
+static struct config_reg {
+ uint16_t cr_offset; /* register offset */
+ uint8_t cr_size; /* size (bytes) */
+ uint8_t cr_ro; /* true => reg is read only */
+ const char *cr_name; /* name of reg */
+} config_regs[] = {
+ { VTCFG_R_HOSTCAP, 4, 1, "HOSTCAP" },
+ { VTCFG_R_GUESTCAP, 4, 0, "GUESTCAP" },
+ { VTCFG_R_PFN, 4, 0, "PFN" },
+ { VTCFG_R_QNUM, 2, 1, "QNUM" },
+ { VTCFG_R_QSEL, 2, 0, "QSEL" },
+ { VTCFG_R_QNOTIFY, 2, 0, "QNOTIFY" },
+ { VTCFG_R_STATUS, 1, 0, "STATUS" },
+ { VTCFG_R_ISR, 1, 0, "ISR" },
+ { VTCFG_R_CFGVEC, 2, 0, "CFGVEC" },
+ { VTCFG_R_QVEC, 2, 0, "QVEC" },
+};
+
+static inline struct config_reg *
+vi_find_cr(int offset) {
+ u_int hi, lo, mid;
+ struct config_reg *cr;
+
+ lo = 0;
+ hi = sizeof(config_regs) / sizeof(*config_regs) - 1;
+ while (hi >= lo) {
+ mid = (hi + lo) >> 1;
+ cr = &config_regs[mid];
+ if (cr->cr_offset == offset)
+ return (cr);
+ if (cr->cr_offset < offset)
+ lo = mid + 1;
+ else
+ hi = mid - 1;
+ }
+ return (NULL);
+}
+
+/*
+ * Handle pci config space reads.
+ * If it's to the MSI-X info, do that.
+ * If it's part of the virtio standard stuff, do that.
+ * Otherwise dispatch to the actual driver.
+ */
+uint64_t
+vi_pci_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi,
+ int baridx, uint64_t offset, int size)
+{
+ struct virtio_softc *vs = pi->pi_arg;
+ struct virtio_consts *vc;
+ struct config_reg *cr;
+ uint64_t virtio_config_size, max;
+ const char *name;
+ uint32_t newoff;
+ uint32_t value;
+ int error;
+
+ if (vs->vs_flags & VIRTIO_USE_MSIX) {
+ if (baridx == pci_msix_table_bar(pi) ||
+ baridx == pci_msix_pba_bar(pi)) {
+ return (pci_emul_msix_tread(pi, offset, size));
+ }
+ }
+
+ /* XXX probably should do something better than just assert() */
+ assert(baridx == 0);
+
+ if (vs->vs_mtx)
+ pthread_mutex_lock(vs->vs_mtx);
+
+ vc = vs->vs_vc;
+ name = vc->vc_name;
+ value = size == 1 ? 0xff : size == 2 ? 0xffff : 0xffffffff;
+
+ if (size != 1 && size != 2 && size != 4)
+ goto bad;
+
+ if (pci_msix_enabled(pi))
+ virtio_config_size = VTCFG_R_CFG1;
+ else
+ virtio_config_size = VTCFG_R_CFG0;
+
+ if (offset >= virtio_config_size) {
+ /*
+ * Subtract off the standard size (including MSI-X
+ * registers if enabled) and dispatch to underlying driver.
+ * If that fails, fall into general code.
+ */
+ newoff = offset - virtio_config_size;
+ max = vc->vc_cfgsize ? vc->vc_cfgsize : 0x100000000;
+ if (newoff + size > max)
+ goto bad;
+ error = (*vc->vc_cfgread)(DEV_SOFTC(vs), newoff, size, &value);
+ if (!error)
+ goto done;
+ }
+
+bad:
+ cr = vi_find_cr(offset);
+ if (cr == NULL || cr->cr_size != size) {
+ if (cr != NULL) {
+ /* offset must be OK, so size must be bad */
+ fprintf(stderr,
+ "%s: read from %s: bad size %d\r\n",
+ name, cr->cr_name, size);
+ } else {
+ fprintf(stderr,
+ "%s: read from bad offset/size %jd/%d\r\n",
+ name, (uintmax_t)offset, size);
+ }
+ goto done;
+ }
+
+ switch (offset) {
+ case VTCFG_R_HOSTCAP:
+ value = vc->vc_hv_caps;
+ break;
+ case VTCFG_R_GUESTCAP:
+ value = vs->vs_negotiated_caps;
+ break;
+ case VTCFG_R_PFN:
+ if (vs->vs_curq < vc->vc_nvq)
+ value = vs->vs_queues[vs->vs_curq].vq_pfn;
+ break;
+ case VTCFG_R_QNUM:
+ value = vs->vs_curq < vc->vc_nvq ?
+ vs->vs_queues[vs->vs_curq].vq_qsize : 0;
+ break;
+ case VTCFG_R_QSEL:
+ value = vs->vs_curq;
+ break;
+ case VTCFG_R_QNOTIFY:
+ value = 0; /* XXX */
+ break;
+ case VTCFG_R_STATUS:
+ value = vs->vs_status;
+ break;
+ case VTCFG_R_ISR:
+ value = vs->vs_isr;
+ vs->vs_isr = 0; /* a read clears this flag */
+ break;
+ case VTCFG_R_CFGVEC:
+ value = vs->vs_msix_cfg_idx;
+ break;
+ case VTCFG_R_QVEC:
+ value = vs->vs_curq < vc->vc_nvq ?
+ vs->vs_queues[vs->vs_curq].vq_msix_idx :
+ VIRTIO_MSI_NO_VECTOR;
+ break;
+ }
+done:
+ if (vs->vs_mtx)
+ pthread_mutex_unlock(vs->vs_mtx);
+ return (value);
+}
+
+/*
+ * Handle pci config space writes.
+ * If it's to the MSI-X info, do that.
+ * If it's part of the virtio standard stuff, do that.
+ * Otherwise dispatch to the actual driver.
+ */
+void
+vi_pci_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi,
+ int baridx, uint64_t offset, int size, uint64_t value)
+{
+ struct virtio_softc *vs = pi->pi_arg;
+ struct vqueue_info *vq;
+ struct virtio_consts *vc;
+ struct config_reg *cr;
+ uint64_t virtio_config_size, max;
+ const char *name;
+ uint32_t newoff;
+ int error;
+
+ if (vs->vs_flags & VIRTIO_USE_MSIX) {
+ if (baridx == pci_msix_table_bar(pi) ||
+ baridx == pci_msix_pba_bar(pi)) {
+ pci_emul_msix_twrite(pi, offset, size, value);
+ return;
+ }
+ }
+
+ /* XXX probably should do something better than just assert() */
+ assert(baridx == 0);
+
+ if (vs->vs_mtx)
+ pthread_mutex_lock(vs->vs_mtx);
+
+ vc = vs->vs_vc;
+ name = vc->vc_name;
+
+ if (size != 1 && size != 2 && size != 4)
+ goto bad;
+
+ if (pci_msix_enabled(pi))
+ virtio_config_size = VTCFG_R_CFG1;
+ else
+ virtio_config_size = VTCFG_R_CFG0;
+
+ if (offset >= virtio_config_size) {
+ /*
+ * Subtract off the standard size (including MSI-X
+ * registers if enabled) and dispatch to underlying driver.
+ */
+ newoff = offset - virtio_config_size;
+ max = vc->vc_cfgsize ? vc->vc_cfgsize : 0x100000000;
+ if (newoff + size > max)
+ goto bad;
+ error = (*vc->vc_cfgwrite)(DEV_SOFTC(vs), newoff, size, value);
+ if (!error)
+ goto done;
+ }
+
+bad:
+ cr = vi_find_cr(offset);
+ if (cr == NULL || cr->cr_size != size || cr->cr_ro) {
+ if (cr != NULL) {
+ /* offset must be OK, wrong size and/or reg is R/O */
+ if (cr->cr_size != size)
+ fprintf(stderr,
+ "%s: write to %s: bad size %d\r\n",
+ name, cr->cr_name, size);
+ if (cr->cr_ro)
+ fprintf(stderr,
+ "%s: write to read-only reg %s\r\n",
+ name, cr->cr_name);
+ } else {
+ fprintf(stderr,
+ "%s: write to bad offset/size %jd/%d\r\n",
+ name, (uintmax_t)offset, size);
+ }
+ goto done;
+ }
+
+ switch (offset) {
+ case VTCFG_R_GUESTCAP:
+ vs->vs_negotiated_caps = value & vc->vc_hv_caps;
+ break;
+ case VTCFG_R_PFN:
+ if (vs->vs_curq >= vc->vc_nvq)
+ goto bad_qindex;
+ vi_vq_init(vs, value);
+ break;
+ case VTCFG_R_QSEL:
+ /*
+ * Note that the guest is allowed to select an
+ * invalid queue; we just need to return a QNUM
+ * of 0 while the bad queue is selected.
+ */
+ vs->vs_curq = value;
+ break;
+ case VTCFG_R_QNOTIFY:
+ if (value >= vc->vc_nvq) {
+ fprintf(stderr, "%s: queue %d notify out of range\r\n",
+ name, (int)value);
+ goto done;
+ }
+ vq = &vs->vs_queues[value];
+ if (vq->vq_notify)
+ (*vq->vq_notify)(DEV_SOFTC(vs), vq);
+ else if (vc->vc_qnotify)
+ (*vc->vc_qnotify)(DEV_SOFTC(vs), vq);
+ else
+ fprintf(stderr,
+ "%s: qnotify queue %d: missing vq/vc notify\r\n",
+ name, (int)value);
+ break;
+ case VTCFG_R_STATUS:
+ vs->vs_status = value;
+ if (value == 0)
+ (*vc->vc_reset)(DEV_SOFTC(vs));
+ break;
+ case VTCFG_R_CFGVEC:
+ vs->vs_msix_cfg_idx = value;
+ break;
+ case VTCFG_R_QVEC:
+ if (vs->vs_curq >= vc->vc_nvq)
+ goto bad_qindex;
+ vq = &vs->vs_queues[vs->vs_curq];
+ vq->vq_msix_idx = value;
+ break;
+ }
+ goto done;
+
+bad_qindex:
+ fprintf(stderr,
+ "%s: write config reg %s: curq %d >= max %d\r\n",
+ name, cr->cr_name, vs->vs_curq, vc->vc_nvq);
+done:
+ if (vs->vs_mtx)
+ pthread_mutex_unlock(vs->vs_mtx);
+}
diff --git a/usr.sbin/bhyve/virtio.h b/usr.sbin/bhyve/virtio.h
index fe6fb1a..8975bf7 100644
--- a/usr.sbin/bhyve/virtio.h
+++ b/usr.sbin/bhyve/virtio.h
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2011 NetApp, Inc.
+ * Copyright (c) 2013 Chris Torek <torek @ torek net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -11,10 +11,10 @@
* 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 NETAPP, INC ``AS IS'' AND
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -29,47 +29,195 @@
#ifndef _VIRTIO_H_
#define _VIRTIO_H_
+/*
+ * These are derived from several virtio specifications.
+ *
+ * Some useful links:
+ * https://github.com/rustyrussel/virtio-spec
+ * http://people.redhat.com/pbonzini/virtio-spec.pdf
+ */
+
+/*
+ * A virtual device has zero or more "virtual queues" (virtqueue).
+ * Each virtqueue uses at least two 4096-byte pages, laid out thus:
+ *
+ * +-----------------------------------------------+
+ * | "desc": <N> descriptors, 16 bytes each |
+ * | ----------------------------------------- |
+ * | "avail": 2 uint16; <N> uint16; 1 uint16 |
+ * | ----------------------------------------- |
+ * | pad to 4k boundary |
+ * +-----------------------------------------------+
+ * | "used": 2 x uint16; <N> elems; 1 uint16 |
+ * | ----------------------------------------- |
+ * | pad to 4k boundary |
+ * +-----------------------------------------------+
+ *
+ * The number <N> that appears here is always a power of two and is
+ * limited to no more than 32768 (as it must fit in a 16-bit field).
+ * If <N> is sufficiently large, the above will occupy more than
+ * two pages. In any case, all pages must be physically contiguous
+ * within the guest's physical address space.
+ *
+ * The <N> 16-byte "desc" descriptors consist of a 64-bit guest
+ * physical address <addr>, a 32-bit length <len>, a 16-bit
+ * <flags>, and a 16-bit <next> field (all in guest byte order).
+ *
+ * There are three flags that may be set :
+ * NEXT descriptor is chained, so use its "next" field
+ * WRITE descriptor is for host to write into guest RAM
+ * (else host is to read from guest RAM)
+ * INDIRECT descriptor address field is (guest physical)
+ * address of a linear array of descriptors
+ *
+ * Unless INDIRECT is set, <len> is the number of bytes that may
+ * be read/written from guest physical address <addr>. If
+ * INDIRECT is set, WRITE is ignored and <len> provides the length
+ * of the indirect descriptors (and <len> must be a multiple of
+ * 16). Note that NEXT may still be set in the main descriptor
+ * pointing to the indirect, and should be set in each indirect
+ * descriptor that uses the next descriptor (these should generally
+ * be numbered sequentially). However, INDIRECT must not be set
+ * in the indirect descriptors. Upon reaching an indirect descriptor
+ * without a NEXT bit, control returns to the direct descriptors.
+ *
+ * Except inside an indirect, each <next> value must be in the
+ * range [0 .. N) (i.e., the half-open interval). (Inside an
+ * indirect, each <next> must be in the range [0 .. <len>/16).)
+ *
+ * The "avail" data structures reside in the same pages as the
+ * "desc" structures since both together are used by the device to
+ * pass information to the hypervisor's virtual driver. These
+ * begin with a 16-bit <flags> field and 16-bit index <idx>, then
+ * have <N> 16-bit <ring> values, followed by one final 16-bit
+ * field <used_event>. The <N> <ring> entries are simply indices
+ * indices into the descriptor ring (and thus must meet the same
+ * constraints as each <next> value). However, <idx> is counted
+ * up from 0 (initially) and simply wraps around after 65535; it
+ * is taken mod <N> to find the next available entry.
+ *
+ * The "used" ring occupies a separate page or pages, and contains
+ * values written from the virtual driver back to the guest OS.
+ * This begins with a 16-bit <flags> and 16-bit <idx>, then there
+ * are <N> "vring_used" elements, followed by a 16-bit <avail_event>.
+ * The <N> "vring_used" elements consist of a 32-bit <id> and a
+ * 32-bit <len> (vu_tlen below). The <id> is simply the index of
+ * the head of a descriptor chain the guest made available
+ * earlier, and the <len> is the number of bytes actually written,
+ * e.g., in the case of a network driver that provided a large
+ * receive buffer but received only a small amount of data.
+ *
+ * The two event fields, <used_event> and <avail_event>, in the
+ * avail and used rings (respectively -- note the reversal!), are
+ * always provided, but are used only if the virtual device
+ * negotiates the VIRTIO_RING_F_EVENT_IDX feature during feature
+ * negotiation. Similarly, both rings provide a flag --
+ * VRING_AVAIL_F_NO_INTERRUPT and VRING_USED_F_NO_NOTIFY -- in
+ * their <flags> field, indicating that the guest does not need an
+ * interrupt, or that the hypervisor driver does not need a
+ * notify, when descriptors are added to the corresponding ring.
+ * (These are provided only for interrupt optimization and need
+ * not be implemented.)
+ */
#define VRING_ALIGN 4096
#define VRING_DESC_F_NEXT (1 << 0)
#define VRING_DESC_F_WRITE (1 << 1)
#define VRING_DESC_F_INDIRECT (1 << 2)
+struct virtio_desc { /* AKA vring_desc */
+ uint64_t vd_addr; /* guest physical address */
+ uint32_t vd_len; /* length of scatter/gather seg */
+ uint16_t vd_flags; /* VRING_F_DESC_* */
+ uint16_t vd_next; /* next desc if F_NEXT */
+} __packed;
+
+struct virtio_used { /* AKA vring_used_elem */
+ uint32_t vu_idx; /* head of used descriptor chain */
+ uint32_t vu_tlen; /* length written-to */
+} __packed;
+
#define VRING_AVAIL_F_NO_INTERRUPT 1
-#define VIRTIO_MSI_NO_VECTOR 0xFFFF
-struct virtio_desc {
- uint64_t vd_addr;
- uint32_t vd_len;
- uint16_t vd_flags;
- uint16_t vd_next;
+struct vring_avail {
+ uint16_t va_flags; /* VRING_AVAIL_F_* */
+ uint16_t va_idx; /* counts to 65535, then cycles */
+ uint16_t va_ring[]; /* size N, reported in QNUM value */
+/* uint16_t va_used_event; -- after N ring entries */
} __packed;
-struct virtio_used {
- uint32_t vu_idx;
- uint32_t vu_tlen;
+#define VRING_USED_F_NO_NOTIFY 1
+struct vring_used {
+ uint16_t vu_flags; /* VRING_USED_F_* */
+ uint16_t vu_idx; /* counts to 65535, then cycles */
+ struct virtio_used vu_ring[]; /* size N */
+/* uint16_t vu_avail_event; -- after N ring entries */
} __packed;
/*
+ * The address of any given virtual queue is determined by a single
+ * Page Frame Number register. The guest writes the PFN into the
+ * PCI config space. However, a device that has two or more
+ * virtqueues can have a different PFN, and size, for each queue.
+ * The number of queues is determinable via the PCI config space
+ * VTCFG_R_QSEL register. Writes to QSEL select the queue: 0 means
+ * queue #0, 1 means queue#1, etc. Once a queue is selected, the
+ * remaining PFN and QNUM registers refer to that queue.
+ *
+ * QNUM is a read-only register containing a nonzero power of two
+ * that indicates the (hypervisor's) queue size. Or, if reading it
+ * produces zero, the hypervisor does not have a corresponding
+ * queue. (The number of possible queues depends on the virtual
+ * device. The block device has just one; the network device
+ * provides either two -- 0 = receive, 1 = transmit -- or three,
+ * with 2 = control.)
+ *
+ * PFN is a read/write register giving the physical page address of
+ * the virtqueue in guest memory (the guest must allocate enough space
+ * based on the hypervisor's provided QNUM).
+ *
+ * QNOTIFY is effectively write-only: when the guest writes a queue
+ * number to the register, the hypervisor should scan the specified
+ * virtqueue. (Reading QNOTIFY currently always gets 0).
+ */
+
+/*
* PFN register shift amount
*/
-#define VRING_PFN 12
+#define VRING_PFN 12
/*
* Virtio device types
+ *
+ * XXX Should really be merged with <dev/virtio/virtio.h> defines
*/
-#define VIRTIO_TYPE_NET 1
-#define VIRTIO_TYPE_BLOCK 2
+#define VIRTIO_TYPE_NET 1
+#define VIRTIO_TYPE_BLOCK 2
+#define VIRTIO_TYPE_CONSOLE 3
+#define VIRTIO_TYPE_ENTROPY 4
+#define VIRTIO_TYPE_BALLOON 5
+#define VIRTIO_TYPE_IOMEMORY 6
+#define VIRTIO_TYPE_RPMSG 7
+#define VIRTIO_TYPE_SCSI 8
+#define VIRTIO_TYPE_9P 9
+
+/* experimental IDs start at 65535 and work down */
/*
* PCI vendor/device IDs
*/
-#define VIRTIO_VENDOR 0x1AF4
-#define VIRTIO_DEV_NET 0x1000
-#define VIRTIO_DEV_BLOCK 0x1001
+#define VIRTIO_VENDOR 0x1AF4
+#define VIRTIO_DEV_NET 0x1000
+#define VIRTIO_DEV_BLOCK 0x1001
/*
- * PCI config space constants
+ * PCI config space constants.
+ *
+ * If MSI-X is enabled, the ISR register is generally not used,
+ * and the configuration vector and queue vector appear at offsets
+ * 20 and 22 with the remaining configuration registers at 24.
+ * If MSI-X is not enabled, those two registers disappear and
+ * the remaining configuration registers start at offset 20.
*/
#define VTCFG_R_HOSTCAP 0
#define VTCFG_R_GUESTCAP 4
@@ -85,19 +233,227 @@ struct virtio_used {
#define VTCFG_R_CFG1 24 /* With MSI-X */
#define VTCFG_R_MSIX 20
+/*
+ * Bits in VTCFG_R_STATUS. Guests need not actually set any of these,
+ * but a guest writing 0 to this register means "please reset".
+ */
+#define VTCFG_STATUS_ACK 0x01 /* guest OS has acknowledged dev */
+#define VTCFG_STATUS_DRIVER 0x02 /* guest OS driver is loaded */
+#define VTCFG_STATUS_DRIVER_OK 0x04 /* guest OS driver ready */
+#define VTCFG_STATUS_FAILED 0x80 /* guest has given up on this dev */
+
+/*
+ * Bits in VTCFG_R_ISR. These apply only if not using MSI-X.
+ *
+ * (We don't [yet?] ever use CONF_CHANGED.)
+ */
+#define VTCFG_ISR_QUEUES 0x01 /* re-scan queues */
+#define VTCFG_ISR_CONF_CHANGED 0x80 /* configuration changed */
+
+#define VIRTIO_MSI_NO_VECTOR 0xFFFF
+
+/*
+ * Feature flags.
+ * Note: bits 0 through 23 are reserved to each device type.
+ */
+#define VIRTIO_F_NOTIFY_ON_EMPTY (1 << 24)
+#define VIRTIO_RING_F_INDIRECT_DESC (1 << 28)
+#define VIRTIO_RING_F_EVENT_IDX (1 << 29)
+
/* From section 2.3, "Virtqueue Configuration", of the virtio specification */
-static inline u_int
+static inline size_t
vring_size(u_int qsz)
{
- u_int size;
+ size_t size;
+ /* constant 3 below = va_flags, va_idx, va_used_event */
size = sizeof(struct virtio_desc) * qsz + sizeof(uint16_t) * (3 + qsz);
size = roundup2(size, VRING_ALIGN);
+ /* constant 3 below = vu_flags, vu_idx, vu_avail_event */
size += sizeof(uint16_t) * 3 + sizeof(struct virtio_used) * qsz;
size = roundup2(size, VRING_ALIGN);
return (size);
}
+struct vmctx;
+struct pci_devinst;
+struct vqueue_info;
+
+/*
+ * A virtual device, with some number (possibly 0) of virtual
+ * queues and some size (possibly 0) of configuration-space
+ * registers private to the device. The virtio_softc should come
+ * at the front of each "derived class", so that a pointer to the
+ * virtio_softc is also a pointer to the more specific, derived-
+ * from-virtio driver's softc.
+ *
+ * Note: inside each hypervisor virtio driver, changes to these
+ * data structures must be locked against other threads, if any.
+ * Except for PCI config space register read/write, we assume each
+ * driver does the required locking, but we need a pointer to the
+ * lock (if there is one) for PCI config space read/write ops.
+ *
+ * When the guest reads or writes the device's config space, the
+ * generic layer checks for operations on the special registers
+ * described above. If the offset of the register(s) being read
+ * or written is past the CFG area (CFG0 or CFG1), the request is
+ * passed on to the virtual device, after subtracting off the
+ * generic-layer size. (So, drivers can just use the offset as
+ * an offset into "struct config", for instance.)
+ *
+ * (The virtio layer also makes sure that the read or write is to/
+ * from a "good" config offset, hence vc_cfgsize, and on BAR #0.
+ * However, the driver must verify the read or write size and offset
+ * and that no one is writing a readonly register.)
+ *
+ * The BROKED flag ("this thing done gone and broked") is for future
+ * use.
+ */
+#define VIRTIO_USE_MSIX 0x01
+#define VIRTIO_EVENT_IDX 0x02 /* use the event-index values */
+#define VIRTIO_BROKED 0x08 /* ??? */
+
+struct virtio_softc {
+ struct virtio_consts *vs_vc; /* constants (see below) */
+ int vs_flags; /* VIRTIO_* flags from above */
+ pthread_mutex_t *vs_mtx; /* POSIX mutex, if any */
+ struct pci_devinst *vs_pi; /* PCI device instance */
+ uint32_t vs_negotiated_caps; /* negotiated capabilities */
+ struct vqueue_info *vs_queues; /* one per vc_nvq */
+ int vs_curq; /* current queue */
+ uint8_t vs_status; /* value from last status write */
+ uint8_t vs_isr; /* ISR flags, if not MSI-X */
+ uint16_t vs_msix_cfg_idx; /* MSI-X vector for config event */
+};
+
+struct virtio_consts {
+ const char *vc_name; /* name of driver (for diagnostics) */
+ int vc_nvq; /* number of virtual queues */
+ size_t vc_cfgsize; /* size of dev-specific config regs */
+ void (*vc_reset)(void *); /* called on virtual device reset */
+ void (*vc_qnotify)(void *, struct vqueue_info *);
+ /* called on QNOTIFY if no VQ notify */
+ int (*vc_cfgread)(void *, int, int, uint32_t *);
+ /* called to read config regs */
+ int (*vc_cfgwrite)(void *, int, int, uint32_t);
+ /* called to write config regs */
+ uint32_t vc_hv_caps; /* hypervisor-provided capabilities */
+};
+
+/*
+ * Data structure allocated (statically) per virtual queue.
+ *
+ * Drivers may change vq_qsize after a reset. When the guest OS
+ * requests a device reset, the hypervisor first calls
+ * vs->vs_vc->vc_reset(); then the data structure below is
+ * reinitialized (for each virtqueue: vs->vs_vc->vc_nvq).
+ *
+ * The remaining fields should only be fussed-with by the generic
+ * code.
+ *
+ * Note: the addresses of vq_desc, vq_avail, and vq_used are all
+ * computable from each other, but it's a lot simpler if we just
+ * keep a pointer to each one. The event indices are similarly
+ * (but more easily) computable, and this time we'll compute them:
+ * they're just XX_ring[N].
+ */
+#define VQ_ALLOC 0x01 /* set once we have a pfn */
+#define VQ_BROKED 0x02 /* ??? */
+struct vqueue_info {
+ uint16_t vq_qsize; /* size of this queue (a power of 2) */
+ void (*vq_notify)(void *, struct vqueue_info *);
+ /* called instead of vc_notify, if not NULL */
+
+ struct virtio_softc *vq_vs; /* backpointer to softc */
+ uint16_t vq_num; /* we're the num'th queue in the softc */
+
+ uint16_t vq_flags; /* flags (see above) */
+ uint16_t vq_last_avail; /* a recent value of vq_avail->va_idx */
+ uint16_t vq_save_used; /* saved vq_used->vu_idx; see vq_endchains */
+ uint16_t vq_msix_idx; /* MSI-X index, or VIRTIO_MSI_NO_VECTOR */
+
+ uint32_t vq_pfn; /* PFN of virt queue (not shifted!) */
+
+ volatile struct virtio_desc *vq_desc; /* descriptor array */
+ volatile struct vring_avail *vq_avail; /* the "avail" ring */
+ volatile struct vring_used *vq_used; /* the "used" ring */
+
+};
+/* as noted above, these are sort of backwards, name-wise */
+#define VQ_AVAIL_EVENT_IDX(vq) \
+ (*(volatile uint16_t *)&(vq)->vq_used->vu_ring[(vq)->vq_qsize])
+#define VQ_USED_EVENT_IDX(vq) \
+ ((vq)->vq_avail->va_ring[(vq)->vq_qsize])
+
+/*
+ * Is this ring ready for I/O?
+ */
+static inline int
+vq_ring_ready(struct vqueue_info *vq)
+{
+
+ return (vq->vq_flags & VQ_ALLOC);
+}
+
+/*
+ * Are there "available" descriptors? (This does not count
+ * how many, just returns True if there are some.)
+ */
+static inline int
+vq_has_descs(struct vqueue_info *vq)
+{
+
+ return (vq_ring_ready(vq) && vq->vq_last_avail !=
+ vq->vq_avail->va_idx);
+}
+
+/*
+ * Called by virtio driver as it starts processing chains. Each
+ * completed chain (obtained from vq_getchain()) is released by
+ * calling vq_relchain(), then when all are done, vq_endchains()
+ * can tell if / how-many chains were processed and know whether
+ * and how to generate an interrupt.
+ */
+static inline void
+vq_startchains(struct vqueue_info *vq)
+{
+
+ vq->vq_save_used = vq->vq_used->vu_idx;
+}
+
+/*
+ * Deliver an interrupt to guest on the given virtual queue
+ * (if possible, or a generic MSI interrupt if not using MSI-X).
+ */
+static inline void
+vq_interrupt(struct virtio_softc *vs, struct vqueue_info *vq)
+{
+
+ if (vs->vs_flags & VIRTIO_USE_MSIX)
+ pci_generate_msix(vs->vs_pi, vq->vq_msix_idx);
+ else {
+ vs->vs_isr |= VTCFG_ISR_QUEUES;
+ pci_generate_msi(vs->vs_pi, 0);
+ }
+}
+
+struct iovec;
+void vi_softc_linkup(struct virtio_softc *vs, struct virtio_consts *vc,
+ void *dev_softc, struct pci_devinst *pi,
+ struct vqueue_info *queues);
+int vi_intr_init(struct virtio_softc *vs, int barnum, int use_msix);
+void vi_reset_dev(struct virtio_softc *);
+void vi_set_io_bar(struct virtio_softc *, int);
+
+int vq_getchain(struct vqueue_info *vq,
+ struct iovec *iov, int n_iov, uint16_t *flags);
+void vq_relchain(struct vqueue_info *vq, uint32_t iolen);
+void vq_endchains(struct vqueue_info *vq, int used_all_avail);
+
+uint64_t vi_pci_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi,
+ int baridx, uint64_t offset, int size);
+void vi_pci_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi,
+ int baridx, uint64_t offset, int size, uint64_t value);
#endif /* _VIRTIO_H_ */
diff --git a/usr.sbin/bluetooth/bthidd/Makefile b/usr.sbin/bluetooth/bthidd/Makefile
index dd0754d..fe6ef33 100644
--- a/usr.sbin/bluetooth/bthidd/Makefile
+++ b/usr.sbin/bluetooth/bthidd/Makefile
@@ -13,4 +13,6 @@ DEBUG_FLAGS= -g
DPADD= ${LIBBLUETOOTH} ${LIBUSBHID}
LDADD= -lbluetooth -lusbhid
+NO_WMISSING_VARIABLE_DECLARATIONS=
+
.include <bsd.prog.mk>
diff --git a/usr.sbin/bluetooth/bthidd/lexer.l b/usr.sbin/bluetooth/bthidd/lexer.l
index 54821da..b9f62a1 100644
--- a/usr.sbin/bluetooth/bthidd/lexer.l
+++ b/usr.sbin/bluetooth/bthidd/lexer.l
@@ -37,6 +37,8 @@
#include "parser.h"
int yylex (void);
+
+#define YY_DECL int yylex(void)
%}
%option yylineno noyywrap nounput noinput
diff --git a/usr.sbin/bluetooth/hccontrol/link_control.c b/usr.sbin/bluetooth/hccontrol/link_control.c
index ea880cd..536520a 100644
--- a/usr.sbin/bluetooth/hccontrol/link_control.c
+++ b/usr.sbin/bluetooth/hccontrol/link_control.c
@@ -357,7 +357,7 @@ again:
goto again;
return (OK);
-} /* hci_diconnect */
+} /* hci_disconnect */
/* Send Add_SCO_Connection command to the unit */
static int
diff --git a/usr.sbin/boot98cfg/boot98cfg.c b/usr.sbin/boot98cfg/boot98cfg.c
index f1ae8329..0ed1b17 100644
--- a/usr.sbin/boot98cfg/boot98cfg.c
+++ b/usr.sbin/boot98cfg/boot98cfg.c
@@ -271,7 +271,7 @@ write_boot(const char *disk, u_char *boot)
warnx("%s: %s", disk, q);
gctl_free(grq);
- for (i = 0; i < NDOSPART; i++) {
+ for (i = 0; i < PC98_NPARTS; i++) {
snprintf(buf, sizeof(buf), "%ss%d", disk, i + 1);
fd = open(buf, O_RDONLY);
if (fd < 0)
diff --git a/usr.sbin/bootparamd/bootparamd/bootparamd.8 b/usr.sbin/bootparamd/bootparamd/bootparamd.8
index 3b49822..4d97cb5 100644
--- a/usr.sbin/bootparamd/bootparamd/bootparamd.8
+++ b/usr.sbin/bootparamd/bootparamd/bootparamd.8
@@ -48,7 +48,7 @@ The file to use as boot parameter file instead of
.El
.Sh FILES
.Bl -tag -width /etc/bootparams -compact
-.It /etc/bootparams
+.It Pa /etc/bootparams
default boot parameter file
.El
.Sh EXAMPLES
diff --git a/usr.sbin/bsdconfig/Makefile b/usr.sbin/bsdconfig/Makefile
index 4faad0b..13cc1c7 100644
--- a/usr.sbin/bsdconfig/Makefile
+++ b/usr.sbin/bsdconfig/Makefile
@@ -8,6 +8,7 @@ SUBDIR= console \
include \
mouse \
networking \
+ packages \
password \
security \
share \
diff --git a/usr.sbin/bsdconfig/USAGE b/usr.sbin/bsdconfig/USAGE
index eac7dbe..6b70bd6 100644
--- a/usr.sbin/bsdconfig/USAGE
+++ b/usr.sbin/bsdconfig/USAGE
@@ -1,6 +1,6 @@
# Copyright (c) 2012 Ron McDowell
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -12,11 +12,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,10 +31,14 @@ Usage:
@PROGRAM_NAME@ [OPTIONS] [command [OPTIONS]]
OPTIONS:
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
-f file Load file as script and then exit. If multiple occurrences,
program will only exit after last occurrence. If file is a
single dash (`-'), @PROGRAM_NAME@ reads from standard input.
- -h Print usage statement and exit.
+ -h Print this usage statement and exit.
-S Secure X11 mode (implies `-X'). As root, always prompt-for
and validate sudo(8) username/password before starting.
-X Use Xdialog(1) in place of dialog(1).
diff --git a/usr.sbin/bsdconfig/bsdconfig b/usr.sbin/bsdconfig/bsdconfig
index 07b73fe..b23e083 100755
--- a/usr.sbin/bsdconfig/bsdconfig
+++ b/usr.sbin/bsdconfig/bsdconfig
@@ -29,6 +29,21 @@
#
############################################################ INCLUDES
+# When common.subr is included, it automatically scans "$@" for `-d' and/or
+# `-D file' arguments to conditionally enable debugging. Similarly, when
+# dialog.subr is included, it automatically scans "$@" for `-X' and/or `-S'.
+# To prevent this scanning from becoming confused by extra options, define
+# any/all extra arguments to use in the optstring to getopts when scanning
+# for dedicated options such as those described.
+#
+# NOTE: This needs to be declared before including `common.subr'.
+# NOTE: You really only need to list flags that require an argument as unknown
+# flags are silently accepted unless they take an argument (in which case
+# the following argument will terminate option processing unless it looks
+# like a flag).
+#
+GETOPTS_EXTRA="f:"
+
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." "$0"
@@ -42,6 +57,13 @@ f_include_lang $BSDCFG_LIBE/include/messages.subr
BSDCONFIG_HELPFILE=$BSDCFG_LIBE/include/bsdconfig.hlp
USAGE_HELPFILE=$BSDCFG_LIBE/include/usage.hlp
+############################################################ CONFIGURATION
+
+#
+# Alternate `local' libexec directory for add-on modules (e.g., from ports)
+#
+BSDCFG_LOCAL_LIBE="/usr/local/libexec/bsdconfig"
+
############################################################ FUNCTIONS
# usage
@@ -50,9 +72,11 @@ USAGE_HELPFILE=$BSDCFG_LIBE/include/usage.hlp
#
usage()
{
- local index="INDEX" cmd_list=""
+ local index="INDEX"
+ local cmd_list # Calculated below
cd $BSDCFG_LIBE
+ # No need to preserve CWD (headed toward exit)
# Test for language-specific indices
f_quietly ls */"$index.${LANG:-$LC_ALL}" &&
@@ -66,6 +90,27 @@ usage()
}' */$index | sort
)
+ local alt_cmd_list # Calculated below (if $BSDCFG_LOCAL_LIBE exists)
+ if f_quietly cd $BSDCFG_LOCAL_LIBE; then
+ # No need to preserve CWD (headed toward exit)
+
+ # Test for language-specific indices
+ f_quietly ls */"$index.${LANG:-$LC_ALL}" &&
+ index="$index.${LANG:-$LC_ALL}"
+
+ alt_cmd_list=$(
+ awk '/^menu_selection="/ {
+ sub(/\|.*/, "")
+ sub(/^menu_selection="/, "")
+ print
+ }' */$index 2> /dev/null | sort
+ )
+
+ # Conflate lists, removing duplicates
+ cmd_list=$( printf "%s\n%s\n" \
+ "$cmd_list" "$alt_cmd_list" | sort -u )
+ fi
+
#
# Determine the longest command-length (in characters)
#
@@ -76,10 +121,9 @@ usage()
#
# Determine the maximum width of terminal/console
#
- local max_size max_width
- max_size=$( stty size 2> /dev/null )
+ local max_size="$( stty size 2> /dev/null )"
: ${max_size:="24 80"}
- max_width="${max_size#*[$IFS]}"
+ local max_width="${max_size#*[$IFS]}"
f_dprintf "max_width=[%s]" "$max_width"
#
@@ -131,6 +175,8 @@ usage()
f_usage $BSDCFG_LIBE/USAGE \
"PROGRAM_NAME" "$pgm" \
"COMMAND_LIST" "$cmd_list"
+
+ # Never reached
}
# dialog_menu_main
@@ -142,63 +188,120 @@ dialog_menu_main()
local title="$DIALOG_TITLE"
local btitle="$DIALOG_BACKTITLE"
local prompt="$msg_menu_text"
- local menu_list size
-
- menu_list="
+ local menu_list="
'X' '$msg_exit' '$msg_exit_bsdconfig'
'1' '$msg_usage' '$msg_quick_start_how_to_use_this_menu_system'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline=
- local sanitize_awk="{ gsub(/'/, \"'\\\\''\"); print }"
-
+ #
+ # Pick up the base modules (directories named `[0-9][0-9][0-9].*')
+ #
local menuitem menu_title menu_help menu_selection index=2
- for menuitem in $( ls -d [0-9][0-9][0-9].* ); do
+ for menuitem in $( cd $BSDCFG_LIBE && ls -d [0-9][0-9][0-9].* ); do
+ [ -f "$BSDCFG_LIBE/$menuitem/INDEX" ] || continue
[ $index -lt ${#DIALOG_MENU_TAGS} ] || break
+
+ menu_program= menu_title= menu_help=
+ f_include_lang $BSDCFG_LIBE/$menuitem/INDEX
+ [ "$menu_program" ] || continue
+
+ case "$menu_program" in
+ /*) : already fully qualified ;;
+ *) menu_program="$menuitem/$menu_program"
+ esac
+
tag=$( f_substr "$DIALOG_MENU_TAGS" $index 1 )
+ setvar "menu_program$tag" "$menu_program"
- menu_program=
- menu_title=
- menu_help=
- f_include_lang $menuitem/INDEX
+ f_shell_escape "$menu_title" menu_title
+ f_shell_escape "$menu_help" menu_help
+ menu_list="$menu_list '$tag' '$menu_title' '$menu_help'"
+
+ index=$(( $index + 1 ))
+ done
+
+ #
+ # Process the `local' libexec sources.
+ #
+ # Whereas modules in $BSDCFG_LIBE must be named [0-9][0-9][0-9].*
+ # modules in $BSDCFG_LOCAL_LIBE should NOT be named this way (making it
+ # more practical for port-maintainers).
+ #
+ # This also has the fortunate side-effect of making the de-duplication
+ # effort rather simple (because so-called `base' modules must be named
+ # differently than add-on modules).
+ #
+ local separator_added=
+ for menuitem in $( cd "$BSDCFG_LOCAL_LIBE" 2> /dev/null && ls -d * )
+ do
+ # Skip the module if it looks like a `base' module
+ case "$menuitem" in [0-9][0-9][0-9].*) continue;; esac
+
+ [ -f "$BSDCFG_LOCAL_LIBE/$menuitem/INDEX" ] || continue
+ [ $index -lt ${#DIALOG_MENU_TAGS} ] || break
+
+ menu_program= menu_title= menu_help=
+ f_include_lang $BSDCFG_LOCAL_LIBE/$menuitem/INDEX || continue
[ "$menu_program" ] || continue
+ if [ ! "$separator_added" ]; then
+ menu_list="$menu_list '-' '-' ''"
+ separator_added=1
+ fi
+
case "$menu_program" in
/*) : already fully qualified ;;
- *)
- menu_program="$menuitem/$menu_program"
+ *) menu_program="$BSDCFG_LOCAL_LIBE/$menuitem/$menu_program"
esac
- menu_title=$( echo "$menu_title" | awk "$sanitize_awk" )
- menu_help=$( echo "$menu_help" | awk "$sanitize_awk" )
+ tag=$( f_substr "$DIALOG_MENU_TAGS" $index 1 )
setvar "menu_program$tag" "$menu_program"
+
+ f_shell_escape "$menu_title" menu_title
+ f_shell_escape "$menu_help" menu_help
menu_list="$menu_list '$tag' '$menu_title' '$menu_help'"
index=$(( $index + 1 ))
done
- size=$( eval f_dialog_menu_with_help_size \
- \"\$title\" \
- \"\$btitle\" \
- \"\$prompt\" \
- \"\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_with_help_size height width rows \
+ \"\$title\" \
+ \"\$btitle\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ # Obtain default-item from previously stored selection
+ f_dialog_default_fetch defaultitem
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
--clear \
--title \"\$title\" \
--backtitle \"\$btitle\" \
+ --hline \"\$hline\" \
--item-help \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_exit_bsdconfig\" \
--help-button \
--help-label \"\$msg_help\" \
${USE_XDIALOG:+--help \"\"} \
- --menu \"\$prompt\" $size $menu_list \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+
+ # Only update default-item on success
+ [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice"
+
return $retval
}
@@ -231,12 +334,12 @@ fi
# Process command-line arguments
#
scripts_loaded=0
-while getopts f:hSX flag; do
+while getopts f:h$GETOPTS_STDARGS flag; do
case "$flag" in
f) [ $scripts_loaded -eq 0 ] && f_include $BSDCFG_SHARE/script.subr
f_script_load "$OPTARG"
- scripts_loaded=$(( $scripts_loaded + 1 ));;
- h|\?) usage;;
+ scripts_loaded=$(( $scripts_loaded + 1 )) ;;
+ h|\?) usage ;;
esac
done
shift $(( $OPTIND -1 ))
@@ -254,8 +357,6 @@ f_dialog_title "$msg_main_menu"
# Incorporate rc-file if it exists
[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
-cd $BSDCFG_LIBE || f_die 1 "$msg_directory_not_found" "$BSDCFG_LIBE"
-
#
# If a non-option argument was passed, process it as a menuitem selection...
#
@@ -263,8 +364,9 @@ if [ "$1" ]; then
#
# ...unless it's a long-option for usage.
#
- case "$1" in
- -help|--help|-\?) usage;;
+ case "$1" in -help|--help|-\?)
+ usage
+ # Not reached
esac
#
@@ -277,10 +379,12 @@ if [ "$1" ]; then
# no matches, display usage (which shows valid keywords)
f_err "%s: %s: $msg_not_found\n" "$pgm" "$1"
usage
+ # Not reached
fi
shift
exec $cmd ${USE_XDIALOG:+-X} "$@" || exit 1
+ # Not reached
fi
#
@@ -289,7 +393,7 @@ fi
while :; do
dialog_menu_main
retval=$?
- mtag=$( f_dialog_menutag )
+ f_dialog_menutag_fetch mtag
f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
if [ $retval -eq 2 ]; then
@@ -301,22 +405,21 @@ while :; do
fi
case "$mtag" in
- X) # Exit
- break
- ;;
-
+ X) break ;;
1) # Usage
f_show_help "$USAGE_HELPFILE"
continue
- ;;
+ esac
- *) # Dynamically loaded menuitem
- cmd=$( eval echo \"\$menu_program$mtag\" )
- f_dprintf "cmd=[%s]" "$cmd"
- $cmd ${USE_XDIALOG:+-X}
- ;;
+ # Anything else is a dynamically loaded menuitem
+ f_getvar menu_program$mtag menu_program
+ case "$menu_program" in
+ /*) cmd="$menu_program" ;;
+ *) cmd="$BSDCFG_LIBE/$menu_program"
esac
+ f_dprintf "cmd=[%s]" "$cmd"
+ $cmd ${USE_XDIALOG:+-X}
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/bsdconfig.8 b/usr.sbin/bsdconfig/bsdconfig.8
index 1c1150b..b99cac2 100644
--- a/usr.sbin/bsdconfig/bsdconfig.8
+++ b/usr.sbin/bsdconfig/bsdconfig.8
@@ -23,43 +23,9 @@
.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" docsinstall
-.\" password
-.\" diskmgmt
-.\" usermgmt
-.\" useradd
-.\" useredit
-.\" userdel
-.\" groupmgmt
-.\" groupadd
-.\" groupedit
-.\" groupdel
-.\" console
-.\" syscons_font
-.\" syscons_keymap
-.\" syscons_repeat
-.\" syscons_saver
-.\" syscons_screenmap
-.\" syscons_ttys
-.\" timezone
-.\" mouse
-.\" mouse_enable
-.\" mouse_type
-.\" mouse_port
-.\" mouse_flags
-.\" mouse_disable
-.\" networking
-.\" defaultrouter
-.\" hostname
-.\" nameservers
-.\" netdev
-.\" security
-.\" ttys
-.\" [dot]
-.\"
.\" $FreeBSD$
.\"
-.Dd Jan 5, 2013
+.Dd Jun 5, 2013
.Dt BSDCONFIG 8
.Os
.Sh NAME
@@ -80,11 +46,18 @@ is used to set up many system configuration settings, both for new systems, as
well as changing configuration settings of existing systems.
.Pp
.Nm
-takes a command as an argument. If invoked with no arguments, it will bring up
-a master menu listing the available commands.
+optionally takes a command as an argument.
+If invoked with no arguments, it will bring up an interactive menu listing the
+available modules.
.Pp
The following options are available:
.Bl -tag -width indent+
+.It Fl d
+Provide lots of debugging info on standard-out when running.
+.It Fl D Ar file
+Send debugging info to file.
+If file begins with a plus-sign debug info is sent to both standard-out and
+file (minus the leading plus).
.It Fl f Ar file
Load
.Ar file
@@ -115,8 +88,8 @@ The following commands
.Pq sorted alphabetically
are currently included in the base
.Nm
-program, with more to be added soon. Other commands can be added, as detailed
-below in the
+program, with more to be added soon.
+Other commands can be added, as detailed below in the
.Cm ADDING COMMANDS
section, and once added, will appear in the master menu as well as in the
.Cm -h
@@ -127,7 +100,8 @@ Utilities to customize the behavior of the system console.
.It Cm defaultrouter
Shortcut to the Default Router/Gateway menu under networking.
.It Cm diskmgmt
-Manage disk partitions and/or labels. Executes
+Manage disk partitions and/or labels.
+Executes
.Xr sade 8 .
.It Cm docsinstall
Executes the
@@ -141,7 +115,8 @@ language file
.Pq printed on stdout
visualizing the
.Nm
-menu, include, and shortcut structure and relationships. See
+menu, include, and shortcut structure relationships.
+See
.Dq bsdconfig dot -h
for more details.
.It Cm groupadd
@@ -154,6 +129,8 @@ Shortcut to the Edit/View Groups menu under groupmgmt.
Utilities to Add/Change/View/Delete Group Accounts.
.It Cm hostname
Shortcut to the Hostname/Domain menu under networking.
+.It Cm kern_securelevel
+Shortcut to the kern.securelevel menu under security.
.It Cm mouse
Utilities for configuring, exploring, and enabling console mouse support.
.It Cm mouse_disable
@@ -173,12 +150,28 @@ Shortcut to the Network Interfaces menu under networking.
.It Cm networking
Utilities to set/change Hostname/Domain, Network Interfaces, Default
Router/Gateway, and DNS Nameservers.
+.It Cm packages
+Browse, install, uninstall, or re-install packaged software.
.It Cm password
Set the system administrator
.Pq root
password.
.It Cm security
Configure various system security settings.
+.It Cm startup
+Configure various aspects of system startup.
+.It Cm startup_misc
+Shortcut to the Miscellaneous Startup Services menu under startup.
+.It Cm startup_rcadd
+Shortcut to the Add New menu under the View/Edit Startup Configuration menu
+(startup_rcconf) of startup.
+.It Cm startup_rcconf
+Shortcut to the View/Edit Startup Configuration menu under startup.
+.It Cm startup_rcdelete
+Shortcut to the Delete menu under the View/Edit Startup Configuration menu
+(startup_rcconf) of startup.
+.It Cm startup_rcvar
+Shortcut to the Toggle Startup Services menu under startup.
.It Cm syscons_font
Shortcut to the Font menu under console.
.It Cm syscons_keymap
@@ -193,6 +186,10 @@ Shortcut to the Screenmap menu under console.
Shortcut to the Ttys menu under console.
.It Cm timezone
Set the regional timezone of the local machine.
+.It Cm ttys
+Edit the
+.Xr ttys 5
+database with your favorite editor.
.It Cm useradd
Shortcut to the Add Users menu under usermgmt.
.It Cm userdel
@@ -210,35 +207,37 @@ In the absence of language-specific translation files, the default
.Pq en_US.ISO8859-1
files will be used.
.Sh ADDING COMMANDS
-To be documented later. Document menu_selection="command|*" syntax of INDEX
-files.
+To be documented later.
+Document menu_selection="command|*" syntax of INDEX files.
.Sh ENVIRONMENT VARIABLES
The following environment variables affect the execution of
.Nm :
.Bl -tag -width ".Ev LC_ALL"
.It Ev LANG
If LANG is set, messages and index information will be read from files named
-messages.$LANG and INDEX.$LANG and fall back to files named messages and INDEX if
-messages.$LANG and INDEX.$LANG do not exist. LANG takes precedence over LC_ALL.
+messages.$LANG and INDEX.$LANG and fall back to files named messages and INDEX
+if messages.$LANG and INDEX.$LANG do not exist.
+LANG takes precedence over LC_ALL.
.It Ev LC_ALL
If LC_ALL is set, messages and index information will be read from files named
-messages.$LC_ALL and INDEX.$LC_ALL and fall back to files named messages and INDEX if
-messages.$LC_ALL and INDEX.$LC_ALL do not exist.
+messages.$LC_ALL and INDEX.$LC_ALL and fall back to files named messages and
+INDEX if messages.$LC_ALL and INDEX.$LC_ALL do not exist.
.El
.Sh FILES
-/usr/share/examples/bsdconfig/bsdconfigrc can be copied to $HOME/.bsdconfigrc and
-customized as needed.
+/usr/share/examples/bsdconfig/bsdconfigrc can be copied to $HOME/.bsdconfigrc
+and customized as needed.
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO
-.Xr host-setup 8 ,
-.Xr sade 8
+.Xr bsdinstall 8
.Sh HISTORY
.Nm
first appeared in
-.Fx 10.0 .
+.Fx 9.2 .
.Sh AUTHORS
-.An Ron McDowell Aq rcm@FuzzWad.ORG
-.An Devin Teske Aq devinteske@hotmail.com
+.An Ron McDowell
+.An Devin Teske Aq dteske@FreeBSD.org
.Sh BUGS
-Undoubtedly.
+The docsinstall and diskmgmt modules call bsdinstall.
+Bugs found in these modules should be considered those of bsdinstall, not
+.Nm .
diff --git a/usr.sbin/bsdconfig/console/INDEX b/usr.sbin/bsdconfig/console/INDEX
index 30ebcf8..18763fd 100644
--- a/usr.sbin/bsdconfig/console/INDEX
+++ b/usr.sbin/bsdconfig/console/INDEX
@@ -26,22 +26,25 @@
# $FreeBSD$
#
-# Title that will be shown on the bsdconfig menu
+# Title that will be shown in the bsdconfig menu.
+#
menu_title="Console"
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
#
-# a short descriptive line shown at the bottom of the bsdconfig menu.
-# keep it short because any line longer than the terminal width will
-# be truncated.
menu_help="Customize system console behavior"
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
#
-# two-part variable that defines an action to take when 'keyword'
-# is passed on a bsdconfig command line. variable takes the form
-# "keyword|command" and multiple occurrences of the variable
-# (with different 'keyword's, or different 'keyword's AND 'command's)
-# are allowed. If 'command' begins with a '/' then the full
-# path to the program is needed. If 'command' begins with anything
-# else it is a path relative to the directory this INDEX file is in.
-# 'keyword' can be i18n'ed but 'command' is the name of a script.
menu_selection="console|console"
menu_selection="syscons_font|font"
menu_selection="syscons_keymap|keymap"
@@ -49,11 +52,12 @@ menu_selection="syscons_repeat|repeat"
menu_selection="syscons_saver|saver"
menu_selection="syscons_screenmap|screenmap"
menu_selection="syscons_ttys|ttys"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
#
-# Items below this line do NOT need i18n translation----------------------
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
#
-# Name of the program to be run when this menu choice is selected.
-# if it begins with a '/' then the full path to the program is needed.
-# if it begins with anything else it is a path relative to the directory
-# this INDEX file is in.
menu_program="console"
diff --git a/usr.sbin/bsdconfig/console/USAGE b/usr.sbin/bsdconfig/console/USAGE
index 9aa4dca..a06d8af 100644
--- a/usr.sbin/bsdconfig/console/USAGE
+++ b/usr.sbin/bsdconfig/console/USAGE
@@ -1,5 +1,5 @@
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -11,11 +11,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -27,7 +27,11 @@
Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS]
OPTIONS:
- -h Print usage statement and exit.
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
+ -h Print this usage statement and exit.
-S Secure X11 mode (implies `-X'). As root, always prompt-for
and validate sudo(8) username/password before starting.
-X Use Xdialog(1) in place of dialog(1).
diff --git a/usr.sbin/bsdconfig/console/console b/usr.sbin/bsdconfig/console/console
index 5f3b7af..ce3d014 100755
--- a/usr.sbin/bsdconfig/console/console
+++ b/usr.sbin/bsdconfig/console/console
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -48,11 +48,8 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline="$hline_configure_system_console_settings"
local prompt="$msg_console_menu_text"
-
- menu_list="
+ local menu_list="
'X $msg_exit' '$msg_exit_this_menu'
'2 $msg_font' '$msg_choose_alternate_screen_font'
'3 $msg_keymap' '$msg_choose_alternate_keyboard_map'
@@ -61,27 +58,37 @@ dialog_menu_main()
'6 $msg_screenmap' '$msg_choose_alternate_screenmap'
'7 $msg_ttys' '$msg_choose_console_terminal_type'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_configure_system_console_settings"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ # Obtain default-item from previously stored selection
+ f_dialog_default_fetch defaultitem
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+ f_dialog_default_store "$menu_choice"
return $retval
}
@@ -93,9 +100,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -111,28 +118,25 @@ f_mustberoot_init
# Launch application main menu
#
while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
+ dialog_menu_main || f_die
+ f_dialog_menutag_fetch mtag
+ command=
case "$mtag" in
- "X $msg_exit") break ;;
- "2 $msg_font") # Choose an alternate screen font
- $BSDCFG_LIBE/$APP_DIR/font ${USE_XDIALOG:+-X} ;;
- "3 $msg_keymap") # Choose an alternate keyboard map
- $BSDCFG_LIBE/$APP_DIR/keymap ${USE_XDIALOG:+-X} ;;
- "4 $msg_repeat") # Set the rate at which keys repeat
- $BSDCFG_LIBE/$APP_DIR/repeat ${USE_XDIALOG:+-X} ;;
- "5 $msg_saver") # Configure the screen saver
- $BSDCFG_LIBE/$APP_DIR/saver ${USE_XDIALOG:+-X} ;;
- "6 $msg_screenmap") # Choose an alternate screenmap
- $BSDCFG_LIBE/$APP_DIR/screenmap ${USE_XDIALOG:+-X} ;;
- "7 $msg_ttys") # Choose console terminal type
- $BSDCFG_LIBE/$APP_DIR/ttys ${USE_XDIALOG:+-X} ;;
+ "X $msg_exit") break ;;
+ "2 $msg_font") command=font ;; # Choose alternate screen font
+ "3 $msg_keymap") command=keymap ;; # Choose alt. keyboard map
+ "4 $msg_repeat") command=repeat ;; # Set key repeat rate
+ "5 $msg_saver") command=saver ;; # Configure the screen saver
+ "6 $msg_screenmap") command=screenmap ;; # Choose alternate screenmap
+ "7 $msg_ttys") command=ttys ;; # Choose console terminal type
esac
+ if [ "$command" ]; then
+ $BSDCFG_LIBE/$APP_DIR/$command ${USE_XDIALOG:+-X}
+ else
+ f_die 1 "$msg_unknown_console_menu_selection"
+ fi
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/console/font b/usr.sbin/bsdconfig/console/font
index 022952f..1ffa696 100755
--- a/usr.sbin/bsdconfig/console/font
+++ b/usr.sbin/bsdconfig/console/font
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -49,11 +49,8 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline="$hline_choose_a_font"
local prompt="$msg_font_menu_text"
-
- menu_list="
+ local menu_list="
'1 $msg_none' '$msg_use_hardware_default_font'
'2 $msg_ibm_437' '$msg_ibm_437_desc'
'3 $msg_ibm_850' '$msg_ibm_850_desc'
@@ -69,27 +66,49 @@ dialog_menu_main()
'd $msg_iso_8859_15' '$msg_iso_8859_15_desc'
'e $msg_swiss' '$msg_swiss_desc'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_choose_a_font"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ case "$( f_sysrc_get font8x8 )" in
+ [Nn][Oo]|'') defaultitem="1 $msg_none" ;;
+ cp437-8x8) defaultitem="2 $msg_ibm_437" ;;
+ cp850-8x8) defaultitem="3 $msg_ibm_850" ;;
+ cp865-8x8) defaultitem="4 $msg_ibm_865" ;;
+ cp866-8x8) defaultitem="5 $msg_ibm_866" ;;
+ cp866u-8x8) defaultitem="6 $msg_ibm_866u" ;;
+ cp1251-8x8) defaultitem="7 $msg_ibm_1251" ;;
+ iso-8x8) defaultitem="8 $msg_iso_8859_1" ;;
+ iso02-8x8) defaultitem="9 $msg_iso_8859_2" ;;
+ iso04-8x8) defaultitem="a $msg_iso_8859_4" ;;
+ iso07-8x8) defaultitem="b $msg_iso_8859_7" ;;
+ iso08-8x8) defaultitem="c $msg_iso_8859_8" ;;
+ iso15-8x8) defaultitem="d $msg_iso_8859_15" ;;
+ swiss-8x8) defaultitem="e $msg_swiss" ;;
+ esac
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -101,9 +120,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -118,90 +137,52 @@ f_mustberoot_init
#
# Launch application main menu
#
-while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
-
- case "$mtag" in
- "1 $msg_none") # Use hardware default font
- f_sysrc_set font8x8 "NO" || f_die
- f_sysrc_set font8x14 "NO" || f_die
- f_sysrc_set font8x16 "NO" || f_die
- break ;;
- "2 $msg_ibm_437") # English and others, VGA default
- f_sysrc_set font8x8 "cp437-8x8" || f_die
- f_sysrc_set font8x14 "cp437-8x14" || f_die
- f_sysrc_set font8x16 "cp437-8x16" || f_die
- break ;;
- "3 $msg_ibm_850") # Western Europe, IBM encoding
- f_sysrc_set font8x8 "cp850-8x8" || f_die
- f_sysrc_set font8x14 "cp850-8x14" || f_die
- f_sysrc_set font8x16 "cp850-8x16" || f_die
- break ;;
- "4 $msg_ibm_865") # Norwegian, IBM encoding
- f_sysrc_set font8x8 "cp865-8x8" || f_die
- f_sysrc_set font8x14 "cp865-8x14" || f_die
- f_sysrc_set font8x16 "cp865-8x16" || f_die
- break ;;
- "5 $msg_ibm_866") # Russian, IBM encoding (use with KOI8-R screenmap)
- f_sysrc_set font8x8 "cp866-8x8" || f_die
- f_sysrc_set font8x14 "cp866-8x14" || f_die
- f_sysrc_set font8x16 "cp866b-8x16" || f_die
- f_sysrc_set mousechar_start 3 || f_die
- break ;;
- "6 $msg_ibm_866u") # Ukrainian, IBM encoding (use w/ KOI8-U screenmap)
- f_sysrc_set font8x8 "cp866u-8x8" || f_die
- f_sysrc_set font8x14 "cp866u-8x14" || f_die
- f_sysrc_set font8x16 "cp866u-8x16" || f_die
- f_sysrc_set mousechar_start 3 || f_die
- break ;;
- "7 $msg_ibm_1251") # Cyrillic, MS Windows encoding
- f_sysrc_set font8x8 "cp1251-8x8" || f_die
- f_sysrc_set font8x14 "cp1251-8x14" || f_die
- f_sysrc_set font8x16 "cp1251-8x16" || f_die
- f_sysrc_set mousechar_start 3 || f_die
- break ;;
- "8 $msg_iso_8859_1") # Western Europe, ISO encoding
- f_sysrc_set font8x8 "iso-8x8" || f_die
- f_sysrc_set font8x14 "iso-8x14" || f_die
- f_sysrc_set font8x16 "iso-8x16" || f_die
- break ;;
- "9 $msg_iso_8859_2") # Eastern Europe, ISO encoding
- f_sysrc_set font8x8 "iso02-8x8" || f_die
- f_sysrc_set font8x14 "iso02-8x14" || f_die
- f_sysrc_set font8x16 "iso02-8x16" || f_die
- break ;;
- "a $msg_iso_8859_4") # Baltic, ISO encoding
- f_sysrc_set font8x8 "iso04-8x8" || f_die
- f_sysrc_set font8x14 "iso04-8x14" || f_die
- f_sysrc_set font8x16 "iso04-8x16" || f_die
- break ;;
- "b $msg_iso_8859_7") # Greek, ISO encoding
- f_sysrc_set font8x8 "iso07-8x8" || f_die
- f_sysrc_set font8x14 "iso07-8x14" || f_die
- f_sysrc_set font8x16 "iso07-8x16" || f_die
- break ;;
- "c $msg_iso_8859_8") # Hebrew, ISO encoding
- f_sysrc_set font8x8 "iso08-8x8" || f_die
- f_sysrc_set font8x14 "iso08-8x14" || f_die
- f_sysrc_set font8x16 "iso08-8x16" || f_die
- break ;;
- "d $msg_iso_8859_15") # Europe, ISO encoding
- f_sysrc_set font8x8 "iso15-8x8" || f_die
- f_sysrc_set font8x14 "iso15-8x14" || f_die
- f_sysrc_set font8x16 "iso15-8x16" || f_die
- break ;;
- "e $msg_swiss") # English, better resolution
- f_sysrc_set font8x8 "swiss-8x8" || f_die
- f_sysrc_set font8x14 "NO" || f_die
- f_sysrc_set font8x16 "swiss-8x16" || f_die
- break ;;
- esac
-
-done
+dialog_menu_main || f_die
+f_dialog_menutag_fetch mtag
+
+f8= f14= f16= mc_start=
+case "$mtag" in
+"1 $msg_none") # Use hardware default font
+ f8="NO" f14="NO" f16="NO" ;;
+"2 $msg_ibm_437") # English and others, VGA default
+ f8="cp437-8x8" f14="cp437-8x14" f16="cp437-8x16" ;;
+"3 $msg_ibm_850") # Western Europe, IBM encoding
+ f8="cp850-8x8" f14="cp850-8x14" f16="cp850-8x16" ;;
+"4 $msg_ibm_865") # Norwegian, IBM encoding
+ f8="cp865-8x8" f14="cp865-8x14" f16="cp865-8x16" ;;
+"5 $msg_ibm_866") # Russian, IBM encoding (use with KOI8-R screenmap)
+ f8="cp866-8x8" f14="cp866-8x14" f16="cp866b-8x16" mc_start="3" ;;
+"6 $msg_ibm_866u") # Ukrainian, IBM encoding (use w/ KOI8-U screenmap)
+ f8="cp866u-8x8" f14="cp866u-8x14" f16="cp866u-8x16" mc_start="3" ;;
+"7 $msg_ibm_1251") # Cyrillic, MS Windows encoding
+ f8="cp1251-8x8" f14="cp1251-8x14" f16="cp1251-8x16" mc_start="3" ;;
+"8 $msg_iso_8859_1") # Western Europe, ISO encoding
+ f8="iso-8x8" f14="iso-8x14" f16="iso-8x16" ;;
+"9 $msg_iso_8859_2") # Eastern Europe, ISO encoding
+ f8="iso02-8x8" f14="iso02-8x14" f16="iso02-8x16" ;;
+"a $msg_iso_8859_4") # Baltic, ISO encoding
+ f8="iso04-8x8" f14="iso04-8x14" f16="iso04-8x16" ;;
+"b $msg_iso_8859_7") # Greek, ISO encoding
+ f8="iso07-8x8" f14="iso07-8x14" f16="iso07-8x16" ;;
+"c $msg_iso_8859_8") # Hebrew, ISO encoding
+ f8="iso08-8x8" f14="iso08-8x14" f16="iso08-8x16" ;;
+"d $msg_iso_8859_15") # Europe, ISO encoding
+ f8="iso15-8x8" f14="iso15-8x14" f16="iso15-8x16" ;;
+"e $msg_swiss") # English, better resolution
+ f8="swiss-8x8" f14="NO" f16="swiss-8x16" ;;
+esac
+
+[ "$f8" -a "$f14" -a "$f16" ] || f_die 1 "$msg_unknown_font_selection"
+
+f_sysrc_set font8x8 "$f8" || f_die
+f_sysrc_set font8x14 "$f14" || f_die
+f_sysrc_set font8x16 "$f16" || f_die
+
+if [ "$mc_start" ]; then
+ f_sysrc_set mousechar_start "$mc_start" || f_die
+else
+ f_sysrc_delete mousechar_start || f_die
+fi
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/console/include/messages.subr b/usr.sbin/bsdconfig/console/include/messages.subr
index ffc9084..11e3022 100644
--- a/usr.sbin/bsdconfig/console/include/messages.subr
+++ b/usr.sbin/bsdconfig/console/include/messages.subr
@@ -36,7 +36,7 @@ msg_beastie_desc="\"BSD Daemon\" animated screen saver (graphics)"
msg_belgian="Belgian"
msg_belgian_desc="Belgian ISO keymap"
msg_blank="Blank"
-msg_blank_desc="Simply blank the screen"
+msg_blank_desc="Blank screen"
msg_brazil_cp850="Brazil CP850"
msg_brazil_cp850_desc="Brazil CP850 keymap"
msg_brazil_iso="Brazil ISO"
@@ -78,7 +78,7 @@ msg_estonian_iso_desc="Estonian ISO keymap"
msg_estonian_iso_15="Estonian ISO 15"
msg_estonian_iso_15_desc="Estonian ISO 8859-15 keymap"
msg_exit="Exit"
-msg_exit_this_menu="Exit this menu (returning to previous)"
+msg_exit_this_menu="Exit this menu"
msg_fade="Fade"
msg_fade_desc="Fade out effect screen saver"
msg_fast="Fast"
@@ -241,6 +241,12 @@ msg_ukrainian_koi8_u="Ukranian KOI8-U"
msg_ukrainian_koi8_u_desc="Ukranian KOI8-U keymap"
msg_ukrainian_koi8_u_koi8_r="Ukranian KOI8-U+KOI8-R"
msg_ukrainian_koi8_u_koi8_r_desc="Ukranian KOI8-U+KOI8-R keymap (alter)"
+msg_unknown_console_menu_selection="Unknown console menu selection"
+msg_unknown_font_selection="Unknown font selection"
+msg_unknown_keymap="Unknown keymap"
+msg_unknown_repeat_rate="Unknown repeat rate"
+msg_unknown_saver="Unknown saver"
+msg_unknown_screenmap_selection="Unknown screenmap selection"
msg_us_ascii="US-ASCII"
msg_us_ascii_to_ibm327="US-ASCII to IBM437"
msg_us_ascii_to_ibm327_desc="US-ASCII to IBM 437 screenmap"
diff --git a/usr.sbin/bsdconfig/console/keymap b/usr.sbin/bsdconfig/console/keymap
index 5518140..99072b5 100755
--- a/usr.sbin/bsdconfig/console/keymap
+++ b/usr.sbin/bsdconfig/console/keymap
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -77,9 +77,9 @@ KEYMAP_NAMES="
#
dialog_menu_main()
{
- local menu_list size
- local hline="$hline_choose_a_keyboard_map"
local prompt="$msg_keymap_menu_text"
+ local menu_list defaultitem= # Calculated below
+ local hline="$hline_choose_a_keyboard_map"
#
# Export variables for awk(1) ENVIRON visibility
@@ -110,26 +110,104 @@ dialog_menu_main()
}'
)
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ case "$( f_sysrc_get keymap )" in
+ be.iso) defaultitem="$msg_belgian" ;;
+ br275.cp850) defaultitem="$msg_brazil_cp850" ;;
+ br275.iso) defaultitem="$msg_brazil_iso" ;;
+ br275.iso.acc) defaultitem="$msg_brazil_iso_accent" ;;
+ bg.bds.ctrlcaps) defaultitem="$msg_bulgarian_bds" ;;
+ bg.phonetic.ctrlcaps) defaultitem="$msg_bulgarian_phonetic" ;;
+ ce.iso2) defaultitem="$msg_central_european_iso" ;;
+ hr.iso) defaultitem="$msg_croatian_iso" ;;
+ cs.latin2.qwertz) defaultitem="$msg_czech_iso_accent" ;;
+ danish.cp865) defaultitem="$msg_danish_cp865" ;;
+ danish.iso) defaultitem="$msg_danish_iso" ;;
+ estonian.cp850) defaultitem="$msg_estonian_cp850" ;;
+ estonian.iso) defaultitem="$msg_estonian_iso" ;;
+ estonian.iso15) defaultitem="$msg_estonian_iso_15" ;;
+ finnish.cp850) defaultitem="$msg_finnish_cp850" ;;
+ finnish.iso) defaultitem="$msg_finnish_iso" ;;
+ fr.iso) defaultitem="$msg_french_iso" ;;
+ fr.iso.acc) defaultitem="$msg_french_iso_accent" ;;
+ fr.macbook.acc) defaultitem="$msg_french_iso_macbook" ;;
+ german.cp850) defaultitem="$msg_german_cp850" ;;
+ german.iso) defaultitem="$msg_german_iso" ;;
+ gr.us101.acc) defaultitem="$msg_greek_101" ;;
+ el.iso07) defaultitem="$msg_greek_104" ;;
+ gr.elot.acc) defaultitem="$msg_greek_elot" ;;
+ hu.iso2.101keys) defaultitem="$msg_hungarian_101" ;;
+ hu.iso2.102keys) defaultitem="$msg_hungarian_102" ;;
+ icelandic.iso) defaultitem="$msg_icelandic" ;;
+ icelandic.iso.acc) defaultitem="$msg_icelandic_accent" ;;
+ it.iso) defaultitem="$msg_italian" ;;
+ jp.106) defaultitem="$msg_japanese_106" ;;
+ latinamerican) defaultitem="$msg_latin_american" ;;
+ latinamerican.iso.acc) defaultitem="$msg_latin_american_accent" ;;
+ norwegian.iso) defaultitem="$msg_norway_iso" ;;
+ pl_PL.ISO8859-2) defaultitem="$msg_polish_iso" ;;
+ pt.iso) defaultitem="$msg_portuguese" ;;
+ pt.iso.acc) defaultitem="$msg_portuguese_accent" ;;
+ ru.koi8-r) defaultitem="$msg_russia_koi8_r" ;;
+ sk.iso2) defaultitem="$msg_slovak" ;;
+ si.iso) defaultitem="$msg_slovenian" ;;
+ spanish.iso) defaultitem="$msg_spanish" ;;
+ spanish.iso.acc) defaultitem="$msg_spanish_accent" ;;
+ swedish.cp850) defaultitem="$msg_swedish_cp850" ;;
+ swedish.iso) defaultitem="$msg_swedish_iso" ;;
+ swissfrench.cp850) defaultitem="$msg_swiss_french_cp850" ;;
+ swissfrench.iso) defaultitem="$msg_swiss_french_iso" ;;
+ swissfrench.iso.acc) defaultitem="$msg_swiss_french_iso_accent" ;;
+ swissgerman.cp850) defaultitem="$msg_swiss_german_cp850" ;;
+ swissgerman.iso) defaultitem="$msg_swiss_german_iso" ;;
+ swissgerman.iso.acc) defaultitem="$msg_swiss_german_iso_accent" ;;
+ uk.cp850) defaultitem="$msg_uk_cp850" ;;
+ uk.iso) defaultitem="$msg_uk_iso" ;;
+ ua.koi8-u) defaultitem="$msg_ukrainian_koi8_u" ;;
+ ua.koi8-u.shift.alt) defaultitem="$msg_ukrainian_koi8_u_koi8_r" ;;
+ us.pc-ctrl) defaultitem="$msg_usa_capslock_ctrl" ;;
+ us.dvorak) defaultitem="$msg_usa_dvorak" ;;
+ us.dvorakl) defaultitem="$msg_usa_dvorak_left" ;;
+ us.dvorakr) defaultitem="$msg_usa_dvorak_right" ;;
+ us.emacs) defaultitem="$msg_usa_emacs" ;;
+ us.iso) defaultitem="$msg_usa_iso" ;;
+ us.unix) defaultitem="$msg_usa_unix" ;;
+ esac
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ # The defaultitem may have to be indented to match the menu_list
+ if [ "$defaultitem" ]; then
+ ( eval set -- $menu_list
+ while [ $# -gt 0 ]; do
+ [ "$defaultitem" = "$1" ] && break
+ [ " $defaultitem" = "$1" ] && exit 0
+ shift 2 # tag/item
+ done
+ exit 1 # No modification needed
+ ) && defaultitem=" $defaultitem"
+ fi
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -141,9 +219,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -159,11 +237,8 @@ f_mustberoot_init
# Launch application main menu
#
while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
+ dialog_menu_main || f_die
+ f_dialog_menutag_fetch mtag
#
# Reverse the users choice into the variable name
@@ -179,188 +254,76 @@ while :; do
[ "$keymap_name" ] || continue
+ keymap_to_set=
case "$keymap_name" in
- belgian)
- f_sysrc_set keymap "be.iso" || f_die
- break ;;
- brazil_cp850)
- f_sysrc_set keymap "br275.cp850" || f_die
- break ;;
- brazil_iso)
- f_sysrc_set keymap "br275.iso" || f_die
- break ;;
- brazil_iso_accent)
- f_sysrc_set keymap "br275.iso.acc" || f_die
- break ;;
- bulgarian_bds)
- f_sysrc_set keymap "bg.bds.ctrlcaps" || f_die
- break ;;
- bulgarian_phonetic)
- f_sysrc_set keymap "bg.phonetic.ctrlcaps" || f_die
- break ;;
- central_european_iso)
- f_sysrc_set keymap "ce.iso2" || f_die
- break ;;
- croatian_iso)
- f_sysrc_set keymap "hr.iso" || f_die
- break ;;
- czech_iso_accent)
- f_sysrc_set keymap "cs.latin2.qwertz" || f_die
- break ;;
- danish_cp865)
- f_sysrc_set keymap "danish.cp865" || f_die
- break ;;
- danish_iso)
- f_sysrc_set keymap "danish.iso" || f_die
- break ;;
- estonian_cp850)
- f_sysrc_set keymap "estonian.cp850" || f_die
- break ;;
- estonian_iso)
- f_sysrc_set keymap "estonian.iso" || f_die
- break ;;
- estonian_iso_15)
- f_sysrc_set keymap "estonian.iso15" || f_die
- break ;;
- finnish_cp850)
- f_sysrc_set keymap "finnish.cp850" || f_die
- break ;;
- finnish_iso)
- f_sysrc_set keymap "finnish.iso" || f_die
- break ;;
- french_iso)
- f_sysrc_set keymap "fr.iso" || f_die
- break ;;
- french_iso_accent)
- f_sysrc_set keymap "fr.iso.acc" || f_die
- break ;;
- french_iso_macbook)
- f_sysrc_set keymap "fr.macbook.acc" || f_die
- break ;;
- german_cp850)
- f_sysrc_set keymap "german.cp850" || f_die
- break ;;
- german_iso)
- f_sysrc_set keymap "german.iso" || f_die
- break ;;
- greek_101)
- f_sysrc_set keymap "gr.us101.acc" || f_die
- break ;;
- greek_104)
- f_sysrc_set keymap "el.iso07" || f_die
- break ;;
- greek_elot)
- f_sysrc_set keymap "gr.elot.acc" || f_die
- break ;;
- hungarian_101)
- f_sysrc_set keymap "hu.iso2.101keys" || f_die
- break ;;
- hungarian_102)
- f_sysrc_set keymap "hu.iso2.102keys" || f_die
- break ;;
- icelandic)
- f_sysrc_set keymap "icelandic.iso" || f_die
- break ;;
- icelandic_accent)
- f_sysrc_set keymap "icelandic.iso.acc" || f_die
- break ;;
- italian)
- f_sysrc_set keymap "it.iso" || f_die
- break ;;
- japanese_106)
- f_sysrc_set keymap "jp.106" || f_die
- break ;;
- latin_american)
- f_sysrc_set keymap "latinamerican" || f_die
- break ;;
- latin_american_accent)
- f_sysrc_set keymap "latinamerican.iso.acc" || f_die
- break ;;
- norway_iso)
- f_sysrc_set keymap "norwegian.iso" || f_die
- break ;;
- polish_iso)
- f_sysrc_set keymap "pl_PL.ISO8859-2" || f_die
- break ;;
- portuguese)
- f_sysrc_set keymap "pt.iso" || f_die
- break ;;
- portuguese_accent)
- f_sysrc_set keymap "pt.iso.acc" || f_die
- break ;;
- russia_koi8_r)
- f_sysrc_set keymap "ru.koi8-r" || f_die
- break ;;
- slovak)
- f_sysrc_set keymap "sk.iso2" || f_die
- break ;;
- slovenian)
- f_sysrc_set keymap "si.iso" || f_die
- break ;;
- spanish)
- f_sysrc_set keymap "spanish.iso" || f_die
- break ;;
- spanish_accent)
- f_sysrc_set keymap "spanish.iso.acc" || f_die
- break ;;
- swedish_cp850)
- f_sysrc_set keymap "swedish.cp850" || f_die
- break ;;
- swedish_iso)
- f_sysrc_set keymap "swedish.iso" || f_die
- break ;;
- swiss_french_cp850)
- f_sysrc_set keymap "swissfrench.cp850" || f_die
- break ;;
- swiss_french_iso)
- f_sysrc_set keymap "swissfrench.iso" || f_die
- break ;;
- swiss_french_iso_accent)
- f_sysrc_set keymap "swissfrench.iso.acc" || f_die
- break ;;
- swiss_german_cp850)
- f_sysrc_set keymap "swissgerman.cp850" || f_die
- break ;;
- swiss_german_iso)
- f_sysrc_set keymap "swissgerman.iso" || f_die
- break ;;
- swiss_german_iso_accent)
- f_sysrc_set keymap "swissgerman.iso.acc" || f_die
- break ;;
- uk_cp850)
- f_sysrc_set keymap "uk.cp850" || f_die
- break ;;
- uk_iso)
- f_sysrc_set keymap "uk.iso" || f_die
- break ;;
- ukrainian_koi8_u)
- f_sysrc_set keymap "ua.koi8-u" || f_die
- break ;;
- ukrainian_koi8_u_koi8_r)
- f_sysrc_set keymap "ua.koi8-u.shift.alt" || f_die
- break ;;
- usa_capslock_ctrl)
- f_sysrc_set keymap "us.pc-ctrl" || f_die
- break ;;
- usa_dvorak)
- f_sysrc_set keymap "us.dvorak" || f_die
- break ;;
- usa_dvorak_left)
- f_sysrc_set keymap "us.dvorakl" || f_die
- break ;;
- usa_dvorak_right)
- f_sysrc_set keymap "us.dvorakr" || f_die
- break ;;
- usa_emacs)
- f_sysrc_set keymap "us.emacs" || f_die
- break ;;
- usa_iso)
- f_sysrc_set keymap "us.iso" || f_die
- break ;;
- usa_unix)
- f_sysrc_set keymap "us.unix" || f_die
- break ;;
+ belgian) keymap_to_set="be.iso" ;;
+ brazil_cp850) keymap_to_set="br275.cp850" ;;
+ brazil_iso) keymap_to_set="br275.iso" ;;
+ brazil_iso_accent) keymap_to_set="br275.iso.acc" ;;
+ bulgarian_bds) keymap_to_set="bg.bds.ctrlcaps" ;;
+ bulgarian_phonetic) keymap_to_set="bg.phonetic.ctrlcaps" ;;
+ central_european_iso) keymap_to_set="ce.iso2" ;;
+ croatian_iso) keymap_to_set="hr.iso" ;;
+ czech_iso_accent) keymap_to_set="cs.latin2.qwertz" ;;
+ danish_cp865) keymap_to_set="danish.cp865" ;;
+ danish_iso) keymap_to_set="danish.iso" ;;
+ estonian_cp850) keymap_to_set="estonian.cp850" ;;
+ estonian_iso) keymap_to_set="estonian.iso" ;;
+ estonian_iso_15) keymap_to_set="estonian.iso15" ;;
+ finnish_cp850) keymap_to_set="finnish.cp850" ;;
+ finnish_iso) keymap_to_set="finnish.iso" ;;
+ french_iso) keymap_to_set="fr.iso" ;;
+ french_iso_accent) keymap_to_set="fr.iso.acc" ;;
+ french_iso_macbook) keymap_to_set="fr.macbook.acc" ;;
+ german_cp850) keymap_to_set="german.cp850" ;;
+ german_iso) keymap_to_set="german.iso" ;;
+ greek_101) keymap_to_set="gr.us101.acc" ;;
+ greek_104) keymap_to_set="el.iso07" ;;
+ greek_elot) keymap_to_set="gr.elot.acc" ;;
+ hungarian_101) keymap_to_set="hu.iso2.101keys" ;;
+ hungarian_102) keymap_to_set="hu.iso2.102keys" ;;
+ icelandic) keymap_to_set="icelandic.iso" ;;
+ icelandic_accent) keymap_to_set="icelandic.iso.acc" ;;
+ italian) keymap_to_set="it.iso" ;;
+ japanese_106) keymap_to_set="jp.106" ;;
+ latin_american) keymap_to_set="latinamerican" ;;
+ latin_american_accent) keymap_to_set="latinamerican.iso.acc" ;;
+ norway_iso) keymap_to_set="norwegian.iso" ;;
+ polish_iso) keymap_to_set="pl_PL.ISO8859-2" ;;
+ portuguese) keymap_to_set="pt.iso" ;;
+ portuguese_accent) keymap_to_set="pt.iso.acc" ;;
+ russia_koi8_r) keymap_to_set="ru.koi8-r" ;;
+ slovak) keymap_to_set="sk.iso2" ;;
+ slovenian) keymap_to_set="si.iso" ;;
+ spanish) keymap_to_set="spanish.iso" ;;
+ spanish_accent) keymap_to_set="spanish.iso.acc" ;;
+ swedish_cp850) keymap_to_set="swedish.cp850" ;;
+ swedish_iso) keymap_to_set="swedish.iso" ;;
+ swiss_french_cp850) keymap_to_set="swissfrench.cp850" ;;
+ swiss_french_iso) keymap_to_set="swissfrench.iso" ;;
+ swiss_french_iso_accent) keymap_to_set="swissfrench.iso.acc" ;;
+ swiss_german_cp850) keymap_to_set="swissgerman.cp850" ;;
+ swiss_german_iso) keymap_to_set="swissgerman.iso" ;;
+ swiss_german_iso_accent) keymap_to_set="swissgerman.iso.acc" ;;
+ uk_cp850) keymap_to_set="uk.cp850" ;;
+ uk_iso) keymap_to_set="uk.iso" ;;
+ ukrainian_koi8_u) keymap_to_set="ua.koi8-u" ;;
+ ukrainian_koi8_u_koi8_r) keymap_to_set="ua.koi8-u.shift.alt" ;;
+ usa_capslock_ctrl) keymap_to_set="us.pc-ctrl" ;;
+ usa_dvorak) keymap_to_set="us.dvorak" ;;
+ usa_dvorak_left) keymap_to_set="us.dvorakl" ;;
+ usa_dvorak_right) keymap_to_set="us.dvorakr" ;;
+ usa_emacs) keymap_to_set="us.emacs" ;;
+ usa_iso) keymap_to_set="us.iso" ;;
+ usa_unix) keymap_to_set="us.unix" ;;
esac
+
+ if [ "$keymap_to_set" ]; then
+ f_sysrc_set keymap "$keymap_to_set" || f_die
+ break
+ else
+ f_die 1 "$msg_unknown_keymap"
+ fi
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/console/repeat b/usr.sbin/bsdconfig/console/repeat
index 93357e8..54134c6 100755
--- a/usr.sbin/bsdconfig/console/repeat
+++ b/usr.sbin/bsdconfig/console/repeat
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -49,37 +49,46 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline="$hline_choose_a_keyboard_repeat_rate"
local prompt="$msg_repeat_menu_text"
-
- menu_list="
+ local menu_list="
+ '$msg_default' '$msg_default_desc'
'$msg_slow' '$msg_slow_desc'
'$msg_normal' '$msg_normal_desc'
'$msg_fast' '$msg_fast_desc'
- '$msg_default' '$msg_default_desc'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_choose_a_keyboard_repeat_rate"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ case "$( f_sysrc_get keyrate )" in
+ [Nn][Oo]|'') defaultitem="$msg_default" ;;
+ slow) defaultitem="$msg_slow" ;;
+ normal) defaultitem="$msg_normal" ;;
+ fast) defaultitem="$msg_fast" ;;
+ esac
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -91,9 +100,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -108,29 +117,23 @@ f_mustberoot_init
#
# Launch application main menu
#
-while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
-
- case "$mtag" in
- "$msg_slow") # Slow keyboard repeat rate
- f_sysrc_set keyrate "slow" || f_die
- break ;;
- "$msg_normal") # "Normal" keyboard repeat rate
- f_sysrc_set keyrate "normal" || f_die
- break ;;
- "$msg_fast") # Fast keyboard repeat rate
- f_sysrc_set keyrate "fast" || f_die
- break ;;
- "$msg_default") # Use default keyboard repeat rate
- f_sysrc_set keyrate "NO" || f_die
- break ;;
- esac
-
-done
+dialog_menu_main || f_die
+f_dialog_menutag_fetch mtag
+
+repeat_rate_to_set=
+case "$mtag" in
+"$msg_default") repeat_rate_to_set="NO" ;; # Use default repeat rate
+"$msg_slow") repeat_rate_to_set="slow" ;; # Slow keyboard repeat rate
+"$msg_normal") repeat_rate_to_set="normal" ;; # "Normal" keyboard repeat rate
+"$msg_fast") repeat_rate_to_set="fast" ;; # Fast keyboard repeat rate
+esac
+
+if [ "$repeat_rate_to_set" ]; then
+ f_sysrc_set keyrate "$repeat_rate_to_set" || f_die
+ break
+else
+ f_die 1 "$msg_unknown_repeat_rate"
+fi
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/console/saver b/usr.sbin/bsdconfig/console/saver
index 4f6729b..00d9e94 100755
--- a/usr.sbin/bsdconfig/console/saver
+++ b/usr.sbin/bsdconfig/console/saver
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -49,47 +49,65 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline="$hline_choose_a_screen_saver"
local prompt="$msg_saver_menu_text"
-
- menu_list="
- '1 $msg_blank' '$msg_blank_desc'
- '2 $msg_beastie' '$msg_beastie_desc'
- '3 $msg_daemon' '$msg_daemon_desc'
- '4 $msg_dragon' '$msg_dragon_desc'
- '5 $msg_fade' '$msg_fade_desc'
- '6 $msg_fire' '$msg_fire_desc'
- '7 $msg_green' '$msg_green_desc'
- '8 $msg_logo' '$msg_logo_desc'
- '9 $msg_rain' '$msg_rain_desc'
- 'a $msg_snake' '$msg_snake_desc'
- 'b $msg_star' '$msg_star_desc'
- 'c $msg_warp' '$msg_warp_desc'
- 'd $msg_none' '$msg_none_saver_desc'
+ local menu_list="
+ '1 $msg_none' '$msg_none_saver_desc'
+ '2 $msg_blank' '$msg_blank_desc'
+ '3 $msg_beastie' '$msg_beastie_desc'
+ '4 $msg_daemon' '$msg_daemon_desc'
+ '5 $msg_dragon' '$msg_dragon_desc'
+ '6 $msg_fade' '$msg_fade_desc'
+ '7 $msg_fire' '$msg_fire_desc'
+ '8 $msg_green' '$msg_green_desc'
+ '9 $msg_logo' '$msg_logo_desc'
+ 'a $msg_rain' '$msg_rain_desc'
+ 'b $msg_snake' '$msg_snake_desc'
+ 'c $msg_star' '$msg_star_desc'
+ 'd $msg_warp' '$msg_warp_desc'
'$msg_timeout' '$msg_timeout_desc'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_choose_a_screen_saver"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ case "$( f_sysrc_get saver )" in
+ [Nn][Oo]|'') defaultitem="1 $msg_none" ;;
+ blank) defaultitem="2 $msg_blank" ;;
+ beastie) defaultitem="3 $msg_beastie" ;;
+ daemon) defaultitem="4 $msg_daemon" ;;
+ dragon) defaultitem="5 $msg_dragon" ;;
+ fade) defaultitem="6 $msg_fade" ;;
+ fire) defaultitem="7 $msg_fire" ;;
+ green) defaultitem="8 $msg_green" ;;
+ logo) defaultitem="9 $msg_logo" ;;
+ rain) defaultitem="a $msg_rain" ;;
+ snake) defaultitem="b $msg_snake" ;;
+ star) defaultitem="c $msg_star" ;;
+ warp) defaultitem="d $msg_warp" ;;
+ esac
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -101,9 +119,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -118,62 +136,55 @@ f_mustberoot_init
#
# Launch application main menu
#
-while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
-
- case "$mtag" in
- "1 $msg_blank") # Simply blank the screen
- f_sysrc_set saver "blank" || f_die
- break ;;
- "2 $msg_beastie") # "BSD Daemon" animated screen saver (graphics)
- f_sysrc_set saver "beastie" || f_die
- break ;;
- "3 $msg_daemon") # "BSD Daemon" animated screen saver (text)
- f_sysrc_set saver "daemon" || f_die
- break ;;
- "4 $msg_dragon") # Dragon screensaver (graphics)
- f_sysrc_set saver "dragon" || f_die
- break ;;
- "5 $msg_fade") # Fade out effect screen saver
- f_sysrc_set saver "fade" || f_die
- break ;;
- "6 $msg_fire") # Flames effect screen saver
- f_sysrc_set saver "fire" || f_die
- break ;;
- "7 $msg_green") # "Green" power saving mode (if supported by monitor)
- f_sysrc_set saver "green" || f_die
- break ;;
- "8 $msg_logo") # FreeBSD "logo" animated screen saver (graphics)
- f_sysrc_set saver "logo" || f_die
- break ;;
- "9 $msg_rain") # Rain drops screen saver
- f_sysrc_set saver "rain" || f_die
- break ;;
- "a $msg_snake") # Draw a FreeBSD "snake" on your screen
- f_sysrc_set saver "snake" || f_die
- break ;;
- "b $msg_star") # A "twinkling stars" effect
- f_sysrc_set saver "star" || f_die
- break ;;
- "c $msg_warp") # A "stars warping" effect
- f_sysrc_set saver "warp" || f_die
- break ;;
- "d $msg_none") # Disable the screensaver
- f_sysrc_set saver "NO" || f_die
- break ;;
- "$msg_timeout") # Set the screen saver timeout interval
- f_dialog_title "$msg_value_required"
- blanktime=$( f_dialog_input "$msg_enter_timeout_period" \
- "$( f_sysrc_get blanktime )"
- ) && f_sysrc_set blanktime "$blanktime"
- f_dialog_title_restore
- ;;
- esac
-done
+dialog_menu_main || f_die
+f_dialog_menutag_fetch mtag
+
+case "$mtag" in
+"$msg_timeout") # Set the screen saver timeout interval
+ f_dialog_title "$msg_value_required"
+ f_dialog_input blanktime "$msg_enter_timeout_period" \
+ "$( f_sysrc_get blanktime )" &&
+ f_sysrc_set blanktime "$blanktime" || f_die
+ f_dialog_title_restore
+ exit $SUCCESS
+esac
+
+saver_to_set=
+case "$mtag" in
+"1 $msg_none") # Disable the screensaver
+ saver_to_set="NO" ;;
+"2 $msg_blank") # Simply blank the screen
+ saver_to_set="blank" ;;
+"3 $msg_beastie") # "BSD Daemon" animated screen saver (graphics)
+ saver_to_set="beastie" ;;
+"4 $msg_daemon") # "BSD Daemon" animated screen saver (text)
+ saver_to_set="daemon" ;;
+"5 $msg_dragon") # Dragon screensaver (graphics)
+ saver_to_set="dragon" ;;
+"6 $msg_fade") # Fade out effect screen saver
+ saver_to_set="fade" ;;
+"7 $msg_fire") # Flames effect screen saver
+ saver_to_set="fire" ;;
+"8 $msg_green") # "Green" power saving mode (if supported by monitor)
+ saver_to_set="green" ;;
+"9 $msg_logo") # FreeBSD "logo" animated screen saver (graphics)
+ saver_to_set="logo" ;;
+"a $msg_rain") # Rain drops screen saver
+ saver_to_set="rain" ;;
+"b $msg_snake") # Draw a FreeBSD "snake" on your screen
+ saver_to_set="snake" ;;
+"c $msg_star") # A "twinkling stars" effect
+ saver_to_set="star" ;;
+"d $msg_warp") # A "stars warping" effect
+ saver_to_set="warp" ;;
+esac
+
+if [ "$saver_to_set" ]; then
+ f_sysrc_set saver "$saver_to_set" || f_die
+ break
+else
+ f_die 1 "$msg_unknown_saver"
+fi
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/console/screenmap b/usr.sbin/bsdconfig/console/screenmap
index 5c5e29e..f9bbcd8 100755
--- a/usr.sbin/bsdconfig/console/screenmap
+++ b/usr.sbin/bsdconfig/console/screenmap
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -49,11 +49,8 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline="$hline_choose_a_screen_map"
local prompt="$msg_screenmap_menu_text"
-
- menu_list="
+ local menu_list="
'1 $msg_none' '$msg_none_screenmap_desc'
'2 $msg_iso_8859_1_to_ibm437' '$msg_iso_8859_1_to_ibm437_desc'
'3 $msg_iso_8859_7_to_ibm437' '$msg_iso_8859_7_to_ibm437_desc'
@@ -61,27 +58,41 @@ dialog_menu_main()
'5 $msg_koi8_r_to_ibm866' '$msg_koi8_r_to_ibm866_desc'
'6 $msg_koi8_u_to_ibm866u' '$msg_koi8_u_to_ibm866u_desc'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_choose_a_screen_map"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ case "$( f_sysrc_get scrnmap )" in
+ [Nn][Oo]|'') defaultitem="1 $msg_none" ;;
+ iso-8859-1_to_cp437) defaultitem="2 $msg_iso_8859_1_to_ibm437" ;;
+ iso-8859-7_to_cp437) defaultitem="3 $msg_iso_8859_7_to_ibm437" ;;
+ us-ascii_to_cp437) defaultitem="4 $msg_us_ascii_to_ibm327" ;;
+ koi8-r2cp866) defaultitem="5 $msg_koi8_r_to_ibm866" ;;
+ koi8-u2cp866u) defaultitem="6 $msg_koi8_u_to_ibm866u" ;;
+ esac
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -93,9 +104,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -110,35 +121,31 @@ f_mustberoot_init
#
# Launch application main menu
#
-while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
-
- case "$mtag" in
- "1 $msg_none") # No screenmap, don't touch font
- f_sysrc_set scrnmap "NO" || f_die
- break ;;
- "2 $msg_iso_8859_1_to_ibm437") # W-Europe ISO 8859-1 to IBM 437 scrnmap
- f_sysrc_set scrnmap "iso-8859-1_to_cp437" || f_die
- break ;;
- "3 $msg_iso_8859_7_to_ibm437") # Greek ISO 8859-7 to IBM 437 screenmap
- f_sysrc_set scrnmap "iso-8859-7_to_cp437" || f_die
- break ;;
- "4 $msg_us_ascii_to_ibm327") # US-ASCII to IBM 437 screenmap
- f_sysrc_set scrnmap "us-ascii_to_cp437" || f_die
- break ;;
- "5 $msg_koi8_r_to_ibm866") # Russian KOI8-R to IBM 866 screenmap
- f_sysrc_set scrnmap "koi8-r2cp866" || f_die
- break ;;
- "6 $msg_koi8_u_to_ibm866u") # Ukrainian KOI8-U to IBM 866u screenmap
- f_sysrc_set scrnmap "koi8-u2cp866u" || f_die
- break ;;
- esac
-
-done
+dialog_menu_main || f_die
+f_dialog_menutag_fetch mtag
+
+scrnmap_to_set=
+case "$mtag" in
+"1 $msg_none") # No screenmap, don't touch font
+ scrnmap_to_set="NO" ;;
+"2 $msg_iso_8859_1_to_ibm437") # W-Europe ISO 8859-1 to IBM 437 scrnmap
+ scrnmap_to_set="iso-8859-1_to_cp437" ;;
+"3 $msg_iso_8859_7_to_ibm437") # Greek ISO 8859-7 to IBM 437 screenmap
+ scrnmap_to_set="iso-8859-7_to_cp437" ;;
+"4 $msg_us_ascii_to_ibm327") # US-ASCII to IBM 437 screenmap
+ scrnmap_to_set="us-ascii_to_cp437" ;;
+"5 $msg_koi8_r_to_ibm866") # Russian KOI8-R to IBM 866 screenmap
+ scrnmap_to_set="koi8-r2cp866" ;;
+"6 $msg_koi8_u_to_ibm866u") # Ukrainian KOI8-U to IBM 866u screenmap
+ scrnmap_to_set="koi8-u2cp866u" ;;
+esac
+
+if [ "$scrnmap_to_set" ]; then
+ f_sysrc_set scrnmap "$scrnmap_to_set" || f_die
+ break
+else
+ f_die 1 "$msg_unknown_screenmap_selection"
+fi
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/console/ttys b/usr.sbin/bsdconfig/console/ttys
index 3f9945e..c0f3ee8 100755
--- a/usr.sbin/bsdconfig/console/ttys
+++ b/usr.sbin/bsdconfig/console/ttys
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -48,22 +48,6 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
ETC_TTYS=/etc/ttys
-############################################################ GLOBALS
-
-#
-# Terminal-type map/menu-item list
-#
-TTY_MENU_LIST="
- '1 $msg_none' '$msg_none_ttys_desc'
- '2 $msg_ibm_437_vga_default' 'cons25'
- '3 $msg_iso_8859_1' 'cons25l1'
- '4 $msg_iso_8859_2' 'cons25l2'
- '5 $msg_iso_8859_7' 'cons25l7'
- '6 $msg_koi8_r' 'cons25r'
- '7 $msg_koi8_u' 'cons25u'
- '8 $msg_us_ascii' 'cons25w'
-" # END-QUOTE
-
############################################################ FUNCTIONS
# dialog_menu_main
@@ -72,30 +56,49 @@ TTY_MENU_LIST="
#
dialog_menu_main()
{
- local size
- local hline="$hline_choose_a_terminal_type"
local prompt="$msg_ttys_menu_text"
+ local menu_list="
+ '1 $msg_none' '$msg_none_ttys_desc'
+ '2 $msg_ibm_437_vga_default' 'cons25'
+ '3 $msg_iso_8859_1' 'cons25l1'
+ '4 $msg_iso_8859_2' 'cons25l2'
+ '5 $msg_iso_8859_7' 'cons25l7'
+ '6 $msg_koi8_r' 'cons25r'
+ '7 $msg_koi8_u' 'cons25u'
+ '8 $msg_us_ascii' 'cons25w'
+ " # END-QUOTE
+ local hline="$hline_choose_a_terminal_type"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $TTY_MENU_LIST )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
- $TTY_MENU_LIST \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
+
+ if [ $retval -eq $SUCCESS ]; then
+ local item
+ item=$( eval f_dialog_menutag2item \
+ \"\$menu_choice\" $menu_list )
+ f_dialog_menuitem_store "$item"
+ fi
+
return $retval
}
@@ -105,7 +108,7 @@ dialog_menu_main()
#
ttys_set_type()
{
- local consterm="$1"
+ local consterm="$1" err
#
# Create new temporary file to write our ttys(5) update with new types.
@@ -127,7 +130,7 @@ ttys_set_type()
# Operate on ttys(5), replacing only the types of `ttyv*' and
# `cons[0-9]' terminals with the new type.
#
- awk -v consterm="$consterm" '
+ if ! err=$( awk -v consterm="$consterm" '
BEGIN {
}
{
@@ -149,8 +152,14 @@ ttys_set_type()
right = substr($0, RSTART)
printf "%s%s%s\n", left, consterm, right
}
- ' "$ETC_TTYS" > "$tmpfile" || return $FAILURE
- f_quietly mv "$tmpfile" "$ETC_TTYS" || return $FAILURE
+ ' "$ETC_TTYS" > "$tmpfile" 2>&1 ); then
+ f_dialog_msgbox "$err"
+ return $FAILURE
+ fi
+ if ! err=$( mv -f "$tmpfile" "$ETC_TTYS" 2>&1 ); then
+ f_dialog_msgbox "$err"
+ return $FAILURE
+ fi
return $SUCCESS
}
@@ -163,9 +172,9 @@ ttys_set_type()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -180,20 +189,13 @@ f_mustberoot_init
#
# Launch application main menu
#
-while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
+dialog_menu_main || f_die
+f_dialog_menutag_fetch mtag
- [ $retval -eq 0 ] || f_die
- [ "$mtag" = "1 $msg_none" ] && break
+[ "$mtag" = "1 $msg_none" ] && exit $SUCCESS
- consterm=$( eval f_dialog_menutag2item \"\$mtag\" $TTY_MENU_LIST )
- err=$( ttys_set_type "$consterm" 2>&1 )
- [ "$err" ] || break
-
- f_dialog_msgbox "$err"
-done
+f_dialog_menuitem_fetch consterm
+ttys_set_type "$consterm" || f_die
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/diskmgmt/INDEX b/usr.sbin/bsdconfig/diskmgmt/INDEX
index 2d03af8..e04bb79 100644
--- a/usr.sbin/bsdconfig/diskmgmt/INDEX
+++ b/usr.sbin/bsdconfig/diskmgmt/INDEX
@@ -26,28 +26,32 @@
# $FreeBSD$
#
-# Title that will be shown on the bsdconfig menu
+# Title that will be shown in the bsdconfig menu.
+#
menu_title="Disk Management"
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
#
-# a short descriptive line shown at the bottom of the bsdconfig menu.
-# keep it short because any line longer than the terminal width will
-# be truncated.
menu_help="Manage disk partitions and/or labels"
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
#
-# two-part variable that defines an action to take when 'keyword'
-# is passed on a bsdconfig command line. variable takes the form
-# "keyword|command" and multiple occurrences of the variable
-# (with different 'keyword's, or different 'keyword's AND 'command's)
-# are allowed. If 'command' begins with a '/' then the full
-# path to the program is needed. If 'command' begins with anything
-# else it is a path relative to the directory this INDEX file is in.
-# 'keyword' can be i18n'ed but 'command' is the name of a script.
menu_selection="diskmgmt|diskmgmt"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
#
-# Items below this line do NOT need i18n translation----------------------
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
#
-# Name of the program to be run when this menu choice is selected.
-# if it begins with a '/' then the full path to the program is needed.
-# if it begins with anything else it is a path relative to the directory
-# this INDEX file is in.
menu_program="diskmgmt"
diff --git a/usr.sbin/bsdconfig/diskmgmt/USAGE b/usr.sbin/bsdconfig/diskmgmt/USAGE
index 9aa4dca..a06d8af 100644
--- a/usr.sbin/bsdconfig/diskmgmt/USAGE
+++ b/usr.sbin/bsdconfig/diskmgmt/USAGE
@@ -1,5 +1,5 @@
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -11,11 +11,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -27,7 +27,11 @@
Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS]
OPTIONS:
- -h Print usage statement and exit.
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
+ -h Print this usage statement and exit.
-S Secure X11 mode (implies `-X'). As root, always prompt-for
and validate sudo(8) username/password before starting.
-X Use Xdialog(1) in place of dialog(1).
diff --git a/usr.sbin/bsdconfig/diskmgmt/diskmgmt b/usr.sbin/bsdconfig/diskmgmt/diskmgmt
index 27852fb..8c3435d 100755
--- a/usr.sbin/bsdconfig/diskmgmt/diskmgmt
+++ b/usr.sbin/bsdconfig/diskmgmt/diskmgmt
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -56,9 +56,9 @@ X11TERM_OPTS=
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -75,9 +75,9 @@ if [ "$USE_XDIALOG" ]; then
f_have "$X11TERM" || f_die 1 \
"$msg_no_such_file_or_directory" "$pgm" "$X11TERM"
- exec $X11TERM $X11TERM_OPTS -e /usr/sbin/sade
+ exec $X11TERM $X11TERM_OPTS -e /usr/sbin/bsdinstall partedit
else
- exec /usr/sbin/sade
+ exec /usr/sbin/bsdinstall partedit
fi
################################################################################
diff --git a/usr.sbin/bsdconfig/docsinstall/INDEX b/usr.sbin/bsdconfig/docsinstall/INDEX
index c61e221..6308f30 100644
--- a/usr.sbin/bsdconfig/docsinstall/INDEX
+++ b/usr.sbin/bsdconfig/docsinstall/INDEX
@@ -26,28 +26,32 @@
# $FreeBSD$
#
-# Title that will be shown on the bsdconfig menu
+# Title that will be shown in the bsdconfig menu.
+#
menu_title="Documentation installation"
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
#
-# a short descriptive line shown at the bottom of the bsdconfig menu.
-# keep it short because any line longer than the terminal width will
-# be truncated.
menu_help="Install FreeBSD Documentation set"
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
#
-# two-part variable that defines an action to take when 'keyword'
-# is passed on a bsdconfig command line. variable takes the form
-# "keyword|command" and multiple occurrences of the variable
-# (with different 'keyword's, or different 'keyword's AND 'command's)
-# are allowed. If 'command' begins with a '/' then the full
-# path to the program is needed. If 'command' begins with anything
-# else it is a path relative to the directory this INDEX file is in.
-# 'keyword' can be i18n'ed but 'command' is the name of a script.
menu_selection="docsinstall|docsinstall"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
#
-# Items below this line do NOT need i18n translation----------------------
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
#
-# Name of the program to be run when this menu choice is selected.
-# if it begins with a '/' then the full path to the program is needed.
-# if it begins with anything else it is a path relative to the directory
-# this INDEX file is in.
menu_program="docsinstall"
diff --git a/usr.sbin/bsdconfig/docsinstall/USAGE b/usr.sbin/bsdconfig/docsinstall/USAGE
index 9aa4dca..a06d8af 100644
--- a/usr.sbin/bsdconfig/docsinstall/USAGE
+++ b/usr.sbin/bsdconfig/docsinstall/USAGE
@@ -1,5 +1,5 @@
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -11,11 +11,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -27,7 +27,11 @@
Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS]
OPTIONS:
- -h Print usage statement and exit.
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
+ -h Print this usage statement and exit.
-S Secure X11 mode (implies `-X'). As root, always prompt-for
and validate sudo(8) username/password before starting.
-X Use Xdialog(1) in place of dialog(1).
diff --git a/usr.sbin/bsdconfig/docsinstall/docsinstall b/usr.sbin/bsdconfig/docsinstall/docsinstall
index 52e0479..5e3a0d3 100755
--- a/usr.sbin/bsdconfig/docsinstall/docsinstall
+++ b/usr.sbin/bsdconfig/docsinstall/docsinstall
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -56,9 +56,9 @@ X11TERM_OPTS=
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
diff --git a/usr.sbin/bsdconfig/dot/INDEX b/usr.sbin/bsdconfig/dot/INDEX
index 96b0c87..fa641e0 100644
--- a/usr.sbin/bsdconfig/dot/INDEX
+++ b/usr.sbin/bsdconfig/dot/INDEX
@@ -26,28 +26,32 @@
# $FreeBSD$
#
-# Title that will be shown on the bsdconfig menu
+# Title that will be shown in the bsdconfig menu.
+#
menu_title=""
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
#
-# a short descriptive line shown at the bottom of the bsdconfig menu.
-# keep it short because any line longer than the terminal width will
-# be truncated.
menu_help=""
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
#
-# two-part variable that defines an action to take when 'keyword'
-# is passed on a bsdconfig command line. variable takes the form
-# "keyword|command" and multiple occurrences of the variable
-# (with different 'keyword's, or different 'keyword's AND 'command's)
-# are allowed. If 'command' begins with a '/' then the full
-# path to the program is needed. If 'command' begins with anything
-# else it is a path relative to the directory this INDEX file is in.
-# 'keyword' can be i18n'ed but 'command' is the name of a script.
menu_selection="dot|dot"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
#
-# Items below this line do NOT need i18n translation----------------------
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
#
-# Name of the program to be run when this menu choice is selected.
-# if it begins with a '/' then the full path to the program is needed.
-# if it begins with anything else it is a path relative to the directory
-# this INDEX file is in.
menu_program=""
diff --git a/usr.sbin/bsdconfig/dot/USAGE b/usr.sbin/bsdconfig/dot/USAGE
index c1c0dc3..5bc38cc 100644
--- a/usr.sbin/bsdconfig/dot/USAGE
+++ b/usr.sbin/bsdconfig/dot/USAGE
@@ -1,5 +1,5 @@
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -11,11 +11,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -27,7 +27,7 @@
Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS]
OPTIONS:
- -h Print usage statement and exit.
+ -h Print this usage statement and exit.
-c Don't show command-line shortcut relationships.
-d Don't show the date in the graph label.
-i Don't show include relationships.
diff --git a/usr.sbin/bsdconfig/dot/dot b/usr.sbin/bsdconfig/dot/dot
index 2cc659c..e13a269 100755
--- a/usr.sbin/bsdconfig/dot/dot
+++ b/usr.sbin/bsdconfig/dot/dot
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -28,6 +28,11 @@
#
############################################################ INCLUDES
+# Prevent common.subr from auto initializing debugging (this is not an inter-
+# active utility that requires debugging; also `-d' has been repurposed).
+#
+DEBUG_SELF_INITIALIZE=NO
+
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." "$0"
@@ -42,7 +47,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
############################################################ CONFIGURATION
#
-# Locataion of bsdconfig(8)
+# Location of bsdconfig(8)
#
BSDCONFIG=/usr/sbin/bsdconfig
@@ -89,8 +94,8 @@ print_node()
shift 1 # node
case "$node" in
- edge) printf '\t\t%s' "$node";;
- *) printf '\t\t"%s"' "$node";;
+ edge) printf '\t\t%s' "$node" ;;
+ *) printf '\t\t"%s"' "$node" ;;
esac
if [ $# -gt 0 ]; then
@@ -150,10 +155,10 @@ end_nodelist()
#
while getopts cdhi flag; do
case "$flag" in
- i) SHOW_INCLUDES=;;
- d) SHOW_GRAPH_LABEL_DATE=;;
- c) SHOW_CMDLINE=;;
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ i) SHOW_INCLUDES= ;;
+ d) SHOW_GRAPH_LABEL_DATE= ;;
+ c) SHOW_CMDLINE= ;;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -255,8 +260,7 @@ if [ "$SHOW_INCLUDES" ]; then
include_file_list=
for file in $file_list; do
include_file_list="$include_file_list $(
- awk -v file="$file" -v item="${file%%/*}" \
- "$print_includes_awk" $file
+ awk "$print_includes_awk" $file
)"
done
@@ -272,24 +276,35 @@ if [ "$SHOW_INCLUDES" ]; then
#
# Search previously-discovered include files for further includes
#
- for file in $include_file_list; do
- include_file_list="$include_file_list $(
- awk -v file="$file" -v item="${file%%/*}" \
- "$print_includes_awk" $BSDCFG_SHARE/$file
- )"
- done
+ before="$include_file_list"
+ while :; do
+ for file in $include_file_list; do
+ include_file_list="$include_file_list $(
+ awk "$print_includes_awk" $BSDCFG_SHARE/$file
+ )"
+ done
- #
- # Sort the list of includes and remove duplicate entries [again]
- #
- include_file_list=$(
- for include_file in $include_file_list; do
- echo "$include_file"
- done | sort -u
- )
+ #
+ # Sort list of includes and remove duplicate entries [again]
+ #
+ include_file_list=$(
+ for include_file in $include_file_list; do
+ echo "$include_file"
+ done | sort -u
+ )
+
+ [ "$include_file_list" = "$before" ] && break
+ before="$include_file_list"
+ done
fi
#
+# Add script.subr to includes if it exists
+#
+[ -f $BSDCFG_SHARE/script.subr ] &&
+ include_file_list="$include_file_list script.subr"
+
+#
# Start the directional-graph (digraph) output
#
printf 'strict digraph "" { // Empty name to prevent SVG Auto-Tooltip\n'
@@ -314,8 +329,8 @@ printf '\tcenter = 1;\t\t// center drawing on page\n'
#
# Perform edge-concentration when displaying a lot of information
#
-# NOTE: This is disabled because dot version 2.28.0 (current) and older have a
-# bug that causes a crash when rankdir = LR and concentrate = true
+# NOTE: This is disabled because dot(1) version 2.28.0 (current) and older have
+# a bug that causes a crash when rankdir = LR and concentrate = true
#
# NOTE: Do not re-enable until said bug is fixed in some future revision.
#
@@ -432,7 +447,8 @@ if [ "$SHOW_INCLUDES" ]; then
shape=oval color=black fillcolor=white style=filled edge_color=grey
begin_nodelist "$shape" "$color" "$fillcolor" "$style"
print_node edge "style = dashed" "color = $edge_color"
- print_node edge "label = \"\\T\"" "fontsize = 9"
+ #print_node edge "label = \"\\T\"" "fontsize = 9"
+ # NOTE: Edge labels are buggy on large graphs
file_list=$(
for file in \
$BSDCONFIG \
@@ -595,7 +611,7 @@ for INDEX in */INDEX; do
printf '\tsubgraph "cluster_%s" {\n' "$item"
case "$item" in
- [0-9][0-9][0-9].*) bgcolor="$bgcolor_menuitem";;
+ [0-9][0-9][0-9].*) bgcolor="$bgcolor_menuitem" ;;
*) bgcolor="$bgcolor_shortcuts"
esac
printf '\t\tbgcolor = "%s";\n' "$bgcolor"
diff --git a/usr.sbin/bsdconfig/examples/Makefile b/usr.sbin/bsdconfig/examples/Makefile
index f072350..78711d2 100644
--- a/usr.sbin/bsdconfig/examples/Makefile
+++ b/usr.sbin/bsdconfig/examples/Makefile
@@ -3,7 +3,7 @@
NO_OBJ=
FILESDIR= ${SHAREDIR}/examples/bsdconfig
-FILES= bsdconfigrc
+FILES= browse_packages.sh bsdconfigrc
beforeinstall:
mkdir -p ${DESTDIR}${FILESDIR}
diff --git a/usr.sbin/bsdconfig/examples/browse_packages.sh b/usr.sbin/bsdconfig/examples/browse_packages.sh
new file mode 100755
index 0000000..6396f46
--- /dev/null
+++ b/usr.sbin/bsdconfig/examples/browse_packages.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+# $FreeBSD$
+#
+# This sample downloads the package INDEX file from FTP to /tmp (if it doesn't
+# already exist) and then displays the package configuration/management screen
+# using the local INDEX file (results in faster browsing of packages from-start
+# since the INDEX can be loaded from local media).
+#
+# NOTE: Packages cannot be installed unless staged to /tmp/packages/All
+#
+. /usr/share/bsdconfig/script.subr
+nonInteractive=1
+TMPDIR=/tmp
+if [ ! -e "$TMPDIR/packages/INDEX" ]; then
+ [ -d "$TMPDIR/packages" ] || mkdir -p "$TMPDIR/packages" || exit 1
+ _ftpPath=ftp://ftp.freebsd.org
+ # For older releases, use ftp://ftp-archive.freebsd.org
+ mediaSetFTP
+ mediaOpen
+ f_show_info "Downloading packages/INDEX from %s" "$_ftpPath"
+ f_device_get media packages/INDEX > $TMPDIR/packages/INDEX
+ mediaClose
+fi
+_directoryPath=$TMPDIR
+mediaSetDirectory
+configPackages
diff --git a/usr.sbin/bsdconfig/examples/bsdconfigrc b/usr.sbin/bsdconfig/examples/bsdconfigrc
index 21d4264..2e3155f 100644
--- a/usr.sbin/bsdconfig/examples/bsdconfigrc
+++ b/usr.sbin/bsdconfig/examples/bsdconfigrc
@@ -27,10 +27,16 @@
# This file allows you to customize the behavior of bsdconfig.
# Copy it to your $HOME/.bsdconfigrc and edit to suit.
-# defaults are shown.
-# debugging aid for development
+# Debugging aids for development
+#
+#debug=1
+#debugFile=$HOME/out
+#debugFile=+$HOME/out # includes debug to stdout
+
+# Optionally override functions to be more verbose (like including the date)
+#
# f_dprintf() {
-# local format="$1"; shift
-# printf "$(date):$pgm:$format\n" "$@" >> $HOME/out
+# local format="$1"; shift
+# printf "$(date):$pgm:$format\n" "$@" >> $HOME/out
# }
diff --git a/usr.sbin/bsdconfig/include/media.hlp b/usr.sbin/bsdconfig/include/media.hlp
index 6df5b03..6fd6094 100644
--- a/usr.sbin/bsdconfig/include/media.hlp
+++ b/usr.sbin/bsdconfig/include/media.hlp
@@ -25,13 +25,11 @@ You can install from the following types of media:
FTP Get the distribution files from an anonymous ftp server
(you will be presented with a list). Please note that
- you may invoke FTP in "Active" mode, "Passive" mode, or
+ you may invoke FTP in "Active"/"Passive" auto-mode, or
via an HTTP proxy.
- Active mode is the standard way of fetching files and
- Passive mode is for use when you're behind a firewall or
- some other security mechanism that blocks active FTP
- connections. Using an HTTP proxy is sometimes necessary
+ By default, ftp(1) will automatically use the best mode
+ for the server. Using an HTTP proxy is sometimes necessary
for firewalls which block all FTP connections.
If you chose to enter your own URL in the FTP menu, please
@@ -41,6 +39,14 @@ You can install from the following types of media:
Options screen.
+ HTTP Direct
+ Get the distribution files directly from an HTTP server.
+
+ If you chose to enter your own URL in the HTTP Direct menu,
+ please note that all paths are *relative* to the root
+ directory of the web server.
+
+
NFS Get the distribution files from an NFS server somewhere
(make sure that permissions on the server allow this!).
If this install method hangs on you or refuses to work
diff --git a/usr.sbin/bsdconfig/include/messages.subr b/usr.sbin/bsdconfig/include/messages.subr
index 82afb6d..1c558f2 100644
--- a/usr.sbin/bsdconfig/include/messages.subr
+++ b/usr.sbin/bsdconfig/include/messages.subr
@@ -25,22 +25,40 @@
#
# $FreeBSD$
-field_username="Username:"
field_password="Password:"
+field_username="Username:"
hline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER"
hline_alnum_punc_tab_enter="Use alpha-numeric, punctuation, TAB or ENTER"
hline_arrows_tab_enter="Press arrows, TAB or ENTER"
+hline_arrows_tab_punc_enter="Use arrows, TAB, punctuation, ENTER"
hline_choose_help_for_more_information_on_media_types="Choose Help for more information on the various media types"
msg_accept_continue="Accept/Continue"
+msg_accessibility_desc="Ports to help disabled users."
+msg_adding_package_as_a_dependency_from_media="Adding %s (as a dependency) from %s"
+msg_adding_package_from_media="Adding %s from %s"
+msg_afterstep_desc="Ports to support the AfterStep window manager."
+msg_all="All"
+msg_all_desc="All available packages in all categories."
msg_always_try_sudo_when_run_as="Always try sudo(8) when run as %s"
-msg_argentina="Argentina"
+msg_arabic_desc="Ported software for Arab countries."
+msg_archivers_desc="Utilities for archiving and unarchiving data."
+msg_armenia="Armenia"
msg_assume_network_is_already_configured="Running multi-user, assume that the network is already configured?"
+msg_assume_yes_to_all_non_critical_dialogs="Assume \"Yes\" answers to all non-critical dialogs"
+msg_astro_desc="Applications related to astronomy."
msg_attempt_automatic_dhcp_configuration="Attempt automatic DHCP configuration of interfaces"
msg_attempt_ipv6_configuration_of_interfaces="Attempt IPv6 configuration of interfaces"
+msg_attempting_to_fetch_file_from_selected_media="Attempting to fetch %s file from selected media."
+msg_audio_desc="Audio utilities - most require a supported sound card."
msg_australia="Australia"
msg_austria="Austria"
+msg_back="Back"
msg_becoming_root_via_sudo="Becoming root via sudo(8)..."
+msg_benchmarks_desc="Utilities for measuring system performance."
+msg_biology_desc="Software related to biology."
msg_brazil="Brazil"
+msg_building_package_menus="Building package menu(s)..."
+msg_cad_desc="Computer Aided Design utilities."
msg_canada="Canada"
msg_cancel="Cancel"
msg_cancel_exit="Cancel/Exit"
@@ -52,37 +70,50 @@ msg_cd_dvd="CD/DVD"
msg_cdrom="CDROM"
msg_checking_access_to="Checking access to\n %s"
msg_china="China"
+msg_chinese_desc="Ported software for the Chinese market."
msg_choose_a_cd_dvd_type="Choose a CD/DVD type"
msg_choose_a_dos_partition="Choose a DOS partition"
msg_choose_a_floppy_drive="Choose a Floppy drive"
msg_choose_a_ufs_partition="Choose a UFS partition"
-msg_choose_a_usb_partition="Choose a USB drive"
+msg_choose_a_usb_drive="Choose a USB drive"
msg_choose_installation_media="Choose Installation Media"
msg_choose_installation_media_description="FreeBSD can be installed from a variety of different installation\nmedia, ranging from floppies to an Internet FTP server. If you're\ninstalling FreeBSD from a supported CD/DVD drive then this is generally\nthe best media to use if you have no overriding reason for using other\nmedia."
msg_client_error="Client error, you could try an other server"
msg_command_failed_rest_of_script_aborted="Command \`%s' failed - rest of script aborted."
+msg_comms_desc="Communications utilities."
msg_configuration_for_interface="Configuration for Interface"
+msg_converters_desc="Format conversion utilities."
msg_could_not_unmount_the_cdrom_dvd="Could not unmount the CDROM/DVD from %s: %s"
msg_could_not_unmount_the_dos_partition="Could not unmount the DOS partition from %s: %s"
msg_could_not_unmount_the_nfs_partition="Could not unmount the NFS partition from %s: %s"
msg_could_not_unmount_the_ufs_partition="Could not unmount the UFS partition from %s: %s"
-msg_couldnt_connect_to_proxy="Couldn't connect to proxy"
msg_couldnt_connect_to_ftp_server="Couldn't connect to FTP server"
+msg_couldnt_connect_to_proxy="Couldn't connect to proxy"
+msg_couldnt_connect_to_server="Couldn't connect to server"
msg_couldnt_open_ftp_connection="Couldn't open FTP connection to %s:\n %s."
msg_created_path="Created %s"
-msg_croatia="Croatia"
msg_czech_republic="Czech Republic"
+msg_databases_desc="Database software."
msg_debugging="Debugging"
msg_denmark="Denmark"
+msg_deskutils_desc="Various Desktop utilities."
+msg_devel_desc="Software development utilities and libraries."
msg_device_is_not_configured="The %s device is not configured. You will need to do so\nin the Networking configuration menu before proceeding."
msg_dhcp="DHCP"
msg_dialog_mixedform_navigation_help="Use <up>/<down> arrows to navigate between fields, TAB to focus buttons, and Enter for OK/Cancel."
msg_directory="Directory"
msg_directory_not_found="%s: Directory not found."
+msg_directory_where_package_temporary_files_go="The directory where package temporary files should go"
+msg_dns_desc="Domain Name Service tools."
+msg_docs_desc="Meta-ports for FreeBSD documentation."
msg_done="Done"
msg_dos="DOS"
msg_editor="Editor"
+msg_editors_desc="Editors."
+msg_elisp_desc="Things related to Emacs Lisp."
msg_emit_extra_debugging_output="Emit extra debugging output"
+msg_emulators_desc="Utilities for emulating other operating systems."
+msg_enlightenment_desc="Software for the Enlightenment Desktop Environment."
msg_enter_a_fully_qualified_pathname_for_the_directory="Enter a fully qualified pathname for the directory\ncontaining the FreeBSD distribution files:"
msg_enter_the_device_name_of_a_ufs_formatted_partition="Enter the device-name of a UFS formatted partition"
msg_error="Error"
@@ -96,64 +127,107 @@ msg_exit_bsdconfig="Exit bsdconfig"
msg_extra_options_to_ifconfig="Extra options to ifconfig (usually empty):"
msg_failed_to_add_default_route="Failed to add a default route; please check your network configuration"
msg_file_system="File System"
+msg_finance_desc="Monetary, financial and related applications."
msg_finland="Finland"
msg_floppy="Floppy"
msg_france="France"
+msg_french_desc="Ported software for French countries."
msg_ftp="FTP"
+msg_ftp_desc="FTP client and server utilities."
msg_ftp_passive="FTP Passive"
msg_ftp_username="FTP username"
+msg_games_desc="Various games and sundry amusements."
+msg_geography_desc="Geography-related software."
+msg_german_desc="Ported software for Germanic countries."
msg_germany="Germany"
+msg_gnome_desc="Components of the Gnome Desktop environment."
+msg_gnustep_desc="Software for GNUstep desktop environment."
+msg_graphics_desc="Graphics libraries and utilities."
msg_greece="Greece"
+msg_hamradio_desc="Software for amateur radio."
+msg_haskell_desc="Software related to the Haskell language."
+msg_hebrew_desc="Ported software for Hebrew language."
msg_help="Help"
msg_host_name_including_domain="Host name (including domain)"
msg_hostname_variable_not_set="WARNING: hostname variable not set and is a non-optional\nparameter. Please add this to your installation script\nor set the netInteractive variable (see bsdconfig man page)"
-msg_http="HTTP"
+msg_http_direct="HTTP Direct"
msg_http_proxy="HTTP Proxy"
-msg_hungary="Hungary"
+msg_hungarian_desc="Ported software for the Hungarian market."
msg_iceland="Iceland"
msg_install_from_a_dos_partition="Install from a DOS partition"
msg_install_from_a_floppy_disk_set="Install from a floppy disk set"
msg_install_from_a_freebsd_cd_dvd="Install from a FreeBSD CD/DVD"
-msg_install_from_a_usb_drive="Install from a USB drive"
msg_install_from_a_ufs_partition="Install from a UFS partition"
+msg_install_from_a_usb_drive="Install from a USB drive"
msg_install_from_an_ftp_server="Install from an FTP server"
msg_install_from_an_ftp_server_thru_firewall="Install from an FTP server through a firewall"
msg_install_from_an_ftp_server_thru_proxy="Install from an FTP server through an HTTP proxy"
+msg_install_from_an_http_server="Install from an HTTP server"
msg_install_from_the_existing_filesystem="Install from the existing filesystem"
msg_install_over_nfs="Install over NFS"
+msg_installed="Installed"
+msg_installed_lc="installed"
+msg_installed_desc="Leave package as-is, installed"
msg_invalid_gateway_ipv4_address_specified="Invalid gateway IPv4 address specified"
msg_invalid_hostname_value="Invalid hostname value"
msg_invalid_ipv4_address="Invalid IPv4 address"
msg_invalid_name_server_ip_address_specified="Invalid name server IP address specified"
msg_invalid_netmask_value="Invalid netmask value"
msg_invalid_nfs_path_specification="Invalid NFS path specification. Must be of the form:\nhost:/full/pathname/to/FreeBSD/distdir"
+msg_io_error_while_reading_in_the_package="I/O error while reading in the %s package."
+msg_io_or_format_error_on_index_file="I/O or format error on %s file.\nPlease verify media (or path to media) and try again."
msg_ipv4_address="IPv4 Address"
msg_ipv4_gateway="IPv4 Gateway"
msg_ipv6="IPv6"
+msg_ipv6_desc="IPv6-related software."
msg_ipv6_ready="IPv6 ready"
+msg_irc_desc="Internet Relay Chat utilities."
msg_ireland="Ireland"
msg_israel="Israel"
msg_italy="Italy"
msg_japan="Japan"
+msg_japanese_desc="Ported software for the Japanese market."
+msg_java_desc="Java language support."
+msg_kde_desc="Software for the K Desktop Environment."
+msg_kld_desc="Kernel loadable modules."
msg_korea="Korea"
-msg_lithuania="Lithuania"
+msg_korean_desc="Ported software for the Korean market."
+msg_lang_desc="Computer languages."
+msg_latvia="Latvia"
msg_length_of_specified_url_is_too_long="Length of specified URL is %u characters. Allowable maximum is %u."
+msg_linux_desc="Linux programs that can run under binary compatibility."
+msg_lisp_desc="Software related to the Lisp language."
+msg_lithuania="Lithuania"
+msg_loading_of_dependent_package_failed="Loading of dependent package %s failed"
+msg_located_index_now_reading_package_data_from_it="Located INDEX, now reading package data from it..."
msg_logging_in_to_user_at_host="Logging in to %s@%s.."
msg_looking_up_host="Looking up host %s"
+msg_mail_desc="Electronic mail packages and utilities."
msg_main_menu="Main Menu"
msg_main_site="Main Site"
+msg_math_desc="Mathematical computation software."
+msg_mbone_desc="Applications and utilities for the MBONE."
msg_media_timeout="Media Timeout"
msg_media_type="Media Type"
msg_menu_text="If you've already installed FreeBSD, you may use\nthis menu to customize it somewhat to suit your\nparticular configuration. Most importantly, you\ncan use the Packages utility to load extra '3rd\nparty' software not provided in the base\ndistributions."
+msg_misc_desc="Miscellaneous utilities."
msg_missing_ftp_host_or_directory="Missing FTP host or directory specification. FTP media not initialized."
+msg_multimedia_desc="Multimedia software."
msg_must_be_root_to_execute="%s: must be root to execute"
msg_must_specify_a_host_name_of_some_sort="Must specify a host name of some sort!"
msg_name_server="Name server"
+msg_net_desc="Networking utilities."
msg_net_device_init_failed="Net device init failed."
-msg_netmask="Netmask"
+msg_net_im_desc="Instant messaging software."
+msg_net_mgmt_desc="Network management tools."
+msg_net_p2p_desc="Peer to peer network applications."
msg_netherlands="Netherlands"
+msg_netmask="Netmask"
msg_network_configuration="Network Configuration"
msg_network_interface_information_required="Network interface information required"
+msg_new_zealand="New Zealand"
+msg_news_desc="USENET News support software."
+msg_next_page="Next page"
msg_nfailed_attempts="%u incorrect password attempts"
msg_nfs="NFS"
msg_nfs_secure="NFS Secure"
@@ -163,10 +237,13 @@ msg_nfs_tcp="NFS TCP"
msg_nfs_version_3="NFS version 3"
msg_no="No"
msg_no_cd_dvd_devices_found="No CD/DVD devices found! Please check that your system's\nconfiguration is correct and that the CD/DVD drive is of a\nsupported type. For more information, consult the hardware\nguide in the Doc menu."
+msg_no_description_provided="No description provided"
msg_no_dos_primary_partitions_found="No DOS primary partitions found! This installation method is unavailable"
msg_no_floppy_devices_found="No floppy devices found! Please check that your system's configuration\nis correct. For more information, consult the hardware guide in the Doc\nmenu."
msg_no_gateway_has_been_set="No gateway has been set. You will be unable to access hosts\nnot on your local network"
msg_no_network_devices="No network devices available!"
+msg_no_package_name_passed_in_package_variable="No package name passed in package variable"
+msg_no_packages_were_selected_for_extraction="No packages were selected for extraction."
msg_no_such_file_or_directory="%s: %s: No such file or directory"
msg_no_usb_devices_found="No USB devices found (try Options/Re-scan Devices)"
msg_no_username="No username provided!"
@@ -178,74 +255,125 @@ msg_ok="OK"
msg_options="Options"
msg_options_editor="Options Editor"
msg_other="other"
+msg_pkg_delete_failed="Warning: pkg_delete of %s failed.\n Run with debugging for details."
+msg_package_is_needed_by_other_installed_packages="Warning: Package %s is needed by\n %d other installed package%s."
+msg_package_not_installed_cannot_delete="Warning: package %s not installed\n No package can be deleted."
+msg_package_read_successfully_waiting_for_pkg_add="Package %s read successfully - waiting for pkg_add(1)"
+msg_package_temp="Package Temp"
+msg_package_was_added_successfully="Package %s was added successfully"
+msg_packages="packages"
+msg_page_of_npages="(Page %s of %s)"
+msg_palm_desc="Software support for the Palm(tm) series."
+msg_parallel_desc="Applications dealing with parallelism in computing."
+msg_pear_desc="Software related to the Pear PHP framework."
+msg_perl5_desc="Utilities/modules for the PERL5 language."
msg_permission_denied="%s: %s: Permission denied"
-msg_please_check_the_url_and_try_again="No such directory: %s\nplease check the URL and try again."
+msg_pkg_add_apparently_did_not_like_the_package="pkg_add(1) apparently did not like the %s package."
+msg_plan9_desc="Software from the Plan9 operating system."
+msg_please_check_the_url_and_try_again="No such directory: %s\nplease check the URL and try again.\n"
msg_please_enter_password="Please enter your password for sudo(8):"
-msg_please_enter_username_password="Please enter a username and password for sudo(8):"
msg_please_enter_the_address_of_the_http_proxy="Please enter the address of the HTTP proxy in this format:\n hostname:port (the ':port' is optional, default is 3128)"
msg_please_enter_the_full_nfs_file_specification="Please enter the full NFS file specification for the remote\nhost and directory containing the FreeBSD distribution files.\nThis should be in the format: hostname:/some/freebsd/dir"
msg_please_enter_the_password_for_this_user="Please enter the password for this user:"
msg_please_enter_the_username_you_wish_to_login_as="Please enter the username you wish to login as:"
-msg_please_insert_floppy_in_drive="Please insert floppy in %s"
+msg_please_enter_username_password="Please enter a username and password for sudo(8):"
msg_please_insert_floppy_containing="Please insert floppy containing %s in %s"
+msg_please_insert_floppy_in_drive="Please insert floppy in %s"
+msg_please_select_a_category_to_display="Please select a category to display."
msg_please_select_a_cd_dvd_drive="FreeBSD can be installed directly from a CD/DVD containing a valid\nFreeBSD distribution. If you are seeing this menu it is because\nmore than one CD/DVD drive was found on your system. Please select\none of the following CD/DVD drives as your installation drive."
msg_please_select_a_floppy_drive="You have more than one floppy drive. Please choose which drive\nyou would like to use."
msg_please_select_a_freebsd_ftp_distribution_site="Please select a FreeBSD FTP distribution site"
-msg_please_select_dos_partition="FreeBSD can be installed directly from a DOS partition assuming,\nof course, that you have copied the relevant distributions into\nyour DOS partition before starting this installation. If this is\nnot the case then you should reboot DOS at this time and copy the\ndistributions you wish to install into a \"FREEBSD\" subdirectory\non one of your DOS partitions. Otherwise, please select the DOS\npartition containing the FreeBSD distribution files."
-msg_please_select_ufs_partition="FreeBSD can be installed directly from another FreeBSD partition\nthat is UFS formatted assuming, of course, that you have copied\nthe relevant distributions into said partition before starting\ninstallation."
+msg_please_select_a_freebsd_http_distribution_site="Please select a FreeBSD HTTP distribution site"
msg_please_select_a_usb_drive="You have more than one USB drive. Please choose which drive\nyou would like to use."
+msg_please_select_dos_partition="FreeBSD can be installed directly from a DOS partition assuming,\nof course, that you have copied the relevant distributions into\nyour DOS partition before starting this installation. If this is\nnot the case then you should reboot DOS at this time and copy the\ndistributions you wish to install into a \"FREEBSD\" subdirectory\non one of your DOS partitions. Otherwise, please select the DOS\npartition containing the FreeBSD distribution files."
msg_please_select_ethernet_device_to_configure="Please select the ethernet or PLIP device to configure."
msg_please_select_the_site_closest_to_you_or_other="Please select the site closest to you or \"other\" if you'd like to\nspecify a different choice. Also note that not every site listed here\ncarries more than the base distribution kits. Only Primary sites are\nguaranteed to carry the full range of possible distributions."
+msg_please_select_ufs_partition="FreeBSD can be installed directly from another FreeBSD partition\nthat is UFS formatted assuming, of course, that you have copied\nthe relevant distributions into said partition before starting\ninstallation."
+msg_please_specify_a_temporary_directory="Please specify a temporary directory with lots of free space:"
msg_please_specify_the_name_of_the_text_editor="Please specify the name of the text editor you wish to use:"
msg_please_specify_the_number_of_seconds_to_wait="Please specify the number of seconds to wait for slow media:"
msg_please_specify_the_release_you_wish_to_load="Please specify the release you wish to load or\n\"any\" for a generic release install:"
msg_please_specify_url_of_a_freebsd_distribution="Please specify the URL of a FreeBSD distribution on a\nremote ftp site. This site must accept either anonymous\nftp or you should have set an ftp username and password\nin the Options screen.\n\nA URL looks like this: ftp://<hostname>/<path>\nWhere <path> is relative to the anonymous ftp directory or the\nhome directory of the user being logged in as."
+msg_please_specify_url_of_freebsd_http_distribution="Please specify the URL of a FreeBSD distribution on a\nremote http site.\nA URL looks like this: http://<hostname>/<path>"
msg_poland="Poland"
-msg_portugal="Portugal"
+msg_polish_desc="Ported software for the Polish market."
+msg_ports_mgmt_desc="Utilities for managing ports and packages."
+msg_portuguese_desc="Ported software for the Portuguese market."
+msg_previous_page="Previous page"
msg_previous_syntax_errors="%s: Not overwriting \`%s' due to previous syntax errors"
msg_primary="Primary"
+msg_print_desc="Utilities for dealing with printing."
msg_probing_devices_please_wait_this_can_take_a_while="Probing devices, please wait (this can take a while)..."
+msg_proceed="Proceed"
+msg_processing_selection="Processing selection..."
+msg_python_desc="Software related to the Python language."
msg_quick_start_how_to_use_this_menu_system="Quick start - How to use this menu system"
+msg_reinstall="Reinstall"
+msg_reinstall_desc="Mark this package for reinstall"
msg_release_name="Release Name"
+msg_required_package_not_found="Warning: %s is a required package but was not found."
msg_rerun_bsdconfig_initial_device_probe="Re-run bsdconfig initial device probe"
msg_rescan_devices="Re-scan Devices"
msg_reset="RESET!"
msg_reset_all_values_to_startup_defaults="Reset all values to startup defaults"
msg_reuse_old_ftp_site_selection_values="Re-use old FTP site selection values?"
-msg_romania="Romania"
+msg_reuse_old_http_site_settings="Re-use old HTTP site settings?"
+msg_review="Review"
+msg_review_desc="Review/perform pending actions"
+msg_review_help="Install, Re-Install, or Un-install selected packages and dependencies"
+msg_reviewing_selected_packages="Reviewing %u selected packages:"
+msg_ruby_desc="Software related to the Ruby language."
+msg_rubygems_desc="Ports of RubyGems packages."
msg_russia="Russia"
+msg_russian_desc="Ported software for the Russian market."
msg_scanning_for_dhcp_servers="Scanning for DHCP servers..."
msg_scanning_for_ra_servers="Scanning for RA servers..."
-msg_secure_mode_requires_x11="Secure-mode requires X11 (use \`-X')!"
+msg_scheme_desc="Software related to the Scheme language."
+msg_science_desc="Scientific software."
msg_secure_mode_requires_root="Secure-mode requires root-access!"
+msg_secure_mode_requires_x11="Secure-mode requires X11 (use \`-X')!"
+msg_security_desc="System security software."
+msg_select="Select"
msg_select_a_site_thats_close="Select a site that's close!"
+msg_selected="selected"
msg_server_error_when_requesting_url="Server error when requesting %s, you could try an other server"
-msg_singapore="Singapore"
+msg_shells_desc="Various shells (tcsh, bash, etc)."
msg_slovak_republic="Slovak Republic"
msg_slovenia="Slovenia"
-msg_snapshots_server_japan="Snapshots Server Japan"
-msg_snapshots_server_sweden="Snapshots Server Sweden"
msg_sorry_invalid_url="Sorry, %s is an invalid URL!"
+msg_sorry_package_was_not_found_in_the_index="Sorry, package %s was not found in the INDEX."
msg_sorry_try_again="Sorry, try again."
msg_south_africa="South Africa"
msg_spain="Spain"
+msg_spanish_desc="Ported software for the Spanish market."
msg_specify_some_other_ftp_site="Specify some other ftp site by URL"
+msg_specify_some_other_http_site="Specify some other http site by URL"
msg_sweden="Sweden"
msg_switzerland="Switzerland"
+msg_sysutils_desc="Various system utilities."
msg_taiwan="Taiwan"
+msg_tcl_desc="TCL and packages that depend on it."
+msg_textproc_desc="Text processing/search utilities."
msg_the_current_installation_media_type="The current installation media type."
msg_timeout_value_in_seconds_for_slow_media="Timeout value in seconds for slow media."
+msg_tk_desc="Tk and packages that depend on it."
msg_try_dhcp_configuration="Do you want to try DHCP configuration of the interface?"
msg_try_ipv6_configuration="Do you want to try IPv6 configuration of the interface?"
msg_try_sudo_only_this_once="Try sudo(8) only this once"
-msg_turkey="Turkey"
msg_ufs="UFS"
msg_uk="UK"
msg_ukraine="Ukraine"
+msg_ukrainian_desc="Ported software for the Ukrainian market."
msg_unable_to_configure_device="Unable to configure the %s interface!\nThis installation method cannot be used."
+msg_unable_to_fetch_package_from_selected_media="Unable to fetch package %s from selected media.\nNo package add will be done."
+msg_unable_to_get_file_from_selected_media="Unable to get %s file from selected media.\n\nThis may be because the packages collection is not available\non the distribution media you've chosen, most likely an FTP site\nwithout the packages collection mirrored. Please verify that\nyour media, or your path to the media, is correct and try again."
msg_unable_to_get_proper_ftp_path="Unable to get proper FTP path. FTP media not initialized."
+msg_unable_to_initialize_media_type_for_package_extract="Unable to initialize media type for package extract."
msg_unable_to_make_directory_mountpoint="Unable to make %s directory mountpoint for %s!"
msg_unable_to_open="Unable to open %s"
+msg_uninstall="Uninstall"
+msg_uninstall_desc="Mark this package for deletion"
+msg_uninstalling_package_waiting_for_pkg_delete="Uninstalling %s package - waiting for pkg_delete(1)"
msg_unknown="unknown"
msg_unknown_user="Unknown user: %s"
msg_url_was_not_found="%s was not found, maybe directory or release-version are wrong?"
@@ -260,14 +388,30 @@ msg_user_is_using_a_slow_pc_or_ethernet_card="User is using a slow PC or Etherne
msg_username_and_password_to_use="Username and password to use instead of anonymous"
msg_using_interface="Using interface %s"
msg_using_usb_device="Using USB device: %s"
+msg_vietnamese_desc="Ported software for the Vietnamese market."
msg_view_set_various_media_options="View/Set various media options"
+msg_what_would_you_like_to_do_with="What would you like to do with %s?"
msg_which_release_to_attempt_to_load="Which release to attempt to load from installation media"
msg_which_text_editor_to_use="Which text editor to use during installation"
+msg_windowmaker_desc="Ports to support the WindowMaker window manager."
msg_would_you_like_to_bring_interface_up="Would you like to bring the %s interface up right now?"
+msg_www_desc="Web utilities (browsers, HTTP servers, etc)."
+msg_x11_clocks_desc="X Window System based clocks."
+msg_x11_desc="X Window System based utilities."
+msg_x11_drivers_desc="X Window System drivers."
+msg_x11_fm_desc="X Window System based file managers."
+msg_x11_fonts_desc="X Window System fonts and font utilties."
+msg_x11_servers_desc="X Window System servers."
+msg_x11_themes_desc="X Window System themes."
+msg_x11_toolkits_desc="X Window System based development toolkits."
+msg_x11_wm_desc="X Window System window managers."
+msg_xfce_desc="Software related to the Xfce Desktop Environment."
msg_yes="Yes"
+msg_yes_to_all="Yes to All"
msg_you_are_not_root_but="You are not root but %s can use sudo(8).\nWhat would you like to do?"
msg_you_may_remove_the_floppy="You may remove the floppy from %s"
msg_youve_already_done_the_network_configuration="You've already done the network configuration once,\nwould you like to skip over it now?"
+msg_zope_desc="Software related to the Zope platform."
tcplayout_extras_help="Any interface-specific options to ifconfig you would like to add"
tcplayout_extras_help_for_plip="For PLIP configuration, you must enter the peer's IP address here."
tcplayout_gateway_help="IPv4 address of host forwarding packets to non-local destinations"
diff --git a/usr.sbin/bsdconfig/include/options.hlp b/usr.sbin/bsdconfig/include/options.hlp
index 674e48d..f47df27 100644
--- a/usr.sbin/bsdconfig/include/options.hlp
+++ b/usr.sbin/bsdconfig/include/options.hlp
@@ -40,6 +40,15 @@ Debugging: Turn on the extra debugging flag
to the developers in tracking such problems down!
+Yes To All: Assume "Yes" answers to all non-critical dialogs
+
+ This flag should be used with caution. It will essentially
+ decide NOT to ask the user about any "boundary" conditions that
+ might not constitute actual errors but may be warnings indicative
+ of other problems. It's most useful to those who are doing unattended
+ installs.
+
+
DHCP: Enable DHCP configuration of interfaces
This option specifies whether DHCP configuration of interfaces
@@ -88,6 +97,14 @@ Media Type: Which media type is being used.
to the media menu itself.
+Package Temp: Where package temporary files should go
+
+ Some packages, like emacs, can use a LOT of temporary space - up to
+ 20 or 30MB. If you are going to configure a small / directory and no
+ separate /var (and hence a small /var/tmp), then you may wish to set
+ this to point at another location (say, /usr/tmp).
+
+
Re-scan Devices:
Reprobe the system for devices.
diff --git a/usr.sbin/bsdconfig/mouse/INDEX b/usr.sbin/bsdconfig/mouse/INDEX
index cf7224c..4a33a79 100644
--- a/usr.sbin/bsdconfig/mouse/INDEX
+++ b/usr.sbin/bsdconfig/mouse/INDEX
@@ -26,33 +26,37 @@
# $FreeBSD$
#
-# Title that will be shown on the bsdconfig menu
+# Title that will be shown in the bsdconfig menu.
+#
menu_title="Mouse"
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
#
-# a short descriptive line shown at the bottom of the bsdconfig menu.
-# keep it short because any line longer than the terminal width will
-# be truncated.
menu_help="Configure the Mouse"
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
#
-# two-part variable that defines an action to take when 'keyword'
-# is passed on a bsdconfig command line. variable takes the form
-# "keyword|command" and multiple occurrences of the variable
-# (with different 'keyword's, or different 'keyword's AND 'command's)
-# are allowed. If 'command' begins with a '/' then the full
-# path to the program is needed. If 'command' begins with anything
-# else it is a path relative to the directory this INDEX file is in.
-# 'keyword' can be i18n'ed but 'command' is the name of a script.
menu_selection="mouse|mouse"
menu_selection="mouse_enable|enable"
menu_selection="mouse_type|type"
menu_selection="mouse_port|port"
menu_selection="mouse_flags|flags"
menu_selection="mouse_disable|disable"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
#
-# Items below this line do NOT need i18n translation----------------------
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
#
-# Name of the program to be run when this menu choice is selected.
-# if it begins with a '/' then the full path to the program is needed.
-# if it begins with anything else it is a path relative to the directory
-# this INDEX file is in.
menu_program="mouse"
diff --git a/usr.sbin/bsdconfig/mouse/USAGE b/usr.sbin/bsdconfig/mouse/USAGE
index 9aa4dca..a06d8af 100644
--- a/usr.sbin/bsdconfig/mouse/USAGE
+++ b/usr.sbin/bsdconfig/mouse/USAGE
@@ -1,5 +1,5 @@
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -11,11 +11,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -27,7 +27,11 @@
Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS]
OPTIONS:
- -h Print usage statement and exit.
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
+ -h Print this usage statement and exit.
-S Secure X11 mode (implies `-X'). As root, always prompt-for
and validate sudo(8) username/password before starting.
-X Use Xdialog(1) in place of dialog(1).
diff --git a/usr.sbin/bsdconfig/mouse/disable b/usr.sbin/bsdconfig/mouse/disable
index 0f41d73..6807abd 100755
--- a/usr.sbin/bsdconfig/mouse/disable
+++ b/usr.sbin/bsdconfig/mouse/disable
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -56,9 +56,9 @@ MOUSED_PIDFILE=/var/run/moused.pid
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -84,18 +84,7 @@ f_sysrc_delete moused_flags || f_die
# Message box
#
f_dialog_title "$msg_message"
-hline="$hline_press_enter_or_space"
-prompt="$msg_mouse_daemon_is_disabled"
-size=$( f_dialog_buttonbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$prompt" )
-eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$prompt\" $size
+f_dialog_msgbox "$msg_mouse_daemon_is_disabled" "$hline_press_enter_or_space"
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/mouse/enable b/usr.sbin/bsdconfig/mouse/enable
index f401461..695eac0 100755
--- a/usr.sbin/bsdconfig/mouse/enable
+++ b/usr.sbin/bsdconfig/mouse/enable
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -56,9 +56,9 @@ MOUSED_PIDFILE=/var/run/moused.pid
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
diff --git a/usr.sbin/bsdconfig/mouse/flags b/usr.sbin/bsdconfig/mouse/flags
index 06218ac..de2ca76 100755
--- a/usr.sbin/bsdconfig/mouse/flags
+++ b/usr.sbin/bsdconfig/mouse/flags
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -56,9 +56,9 @@ MOUSED_PIDFILE=/var/run/moused.pid
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -79,9 +79,8 @@ flags=$( f_sysrc_get moused_flags )
# Prompt the user with the current value
#
f_dialog_title "$msg_value_required"
-flags=$( f_dialog_input "$msg_please_specify_the_mouse_daemon_flags" \
- "$flags"
- ) || f_die
+f_dialog_input flags "$msg_please_specify_the_mouse_daemon_flags" \
+ "$flags" || f_die
f_dialog_title_restore
#
diff --git a/usr.sbin/bsdconfig/mouse/include/messages.subr b/usr.sbin/bsdconfig/mouse/include/messages.subr
index c6f4969..74d9980 100644
--- a/usr.sbin/bsdconfig/mouse/include/messages.subr
+++ b/usr.sbin/bsdconfig/mouse/include/messages.subr
@@ -42,7 +42,7 @@ msg_disable="Disable"
msg_disable_the_mouse_daemon="Disable the mouse daemon"
msg_enable="Enable"
msg_exit="Exit"
-msg_exit_this_menu="Exit this menu (returning to previous)"
+msg_exit_this_menu="Exit this menu"
msg_flags="Flags"
msg_glidepoint="GlidePoint"
msg_glidepoint_desc="ALPS GlidePoint pad (serial)"
@@ -86,5 +86,8 @@ msg_thinkingmouse="ThinkingMouse"
msg_thinkingmouse_desc="Kensington ThinkingMouse (serial)"
msg_trying_to_start_the_mouse_daemon="Trying to start the mouse daemon..."
msg_type="Type"
+msg_unknown_mouse_menu_selection="Unknown mouse menu selection"
+msg_unknown_mouse_port_selection="Unknown mouse port selection"
+msg_unknown_mouse_protocol_selection="Unknown mouse protocol selection"
msg_user_confirmation_requested="User Confirmation Requested"
msg_value_required="Value Required"
diff --git a/usr.sbin/bsdconfig/mouse/mouse b/usr.sbin/bsdconfig/mouse/mouse
index 95d7677..bafed04 100755
--- a/usr.sbin/bsdconfig/mouse/mouse
+++ b/usr.sbin/bsdconfig/mouse/mouse
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -48,11 +48,8 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline=""
local prompt="$msg_menu_text"
-
- menu_list="
+ local menu_list="
'X $msg_exit' '$msg_exit_this_menu'
'2 $msg_enable' '$msg_test_and_run_the_mouse_daemon'
'3 $msg_type' '$msg_select_mouse_protocol_type'
@@ -60,27 +57,37 @@ dialog_menu_main()
'5 $msg_flags' '$msg_set_additional_flags'
'6 $msg_disable' '$msg_disable_the_mouse_daemon'
" # END-QUOTE
-
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local defaultitem= # Calculated below
+ local hline=
+
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ # Obtain default-item from previously stored selection
+ f_dialog_default_fetch defaultitem
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+ f_dialog_default_store "$menu_choice"
return $retval
}
@@ -92,9 +99,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -110,26 +117,24 @@ f_mustberoot_init
# Launch application main menu
#
while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
+ dialog_menu_main || f_die
+ f_dialog_menutag_fetch mtag
+ command=
case "$mtag" in
- "X $msg_exit") break ;;
- "2 $msg_enable") # Test and run the mouse daemon
- $BSDCFG_LIBE/$APP_DIR/enable ${USE_XDIALOG:+-X} ;;
- "3 $msg_type") # Select mouse protocol type
- $BSDCFG_LIBE/$APP_DIR/type ${USE_XDIALOG:+-X} ;;
- "4 $msg_port") # Select mouse port
- $BSDCFG_LIBE/$APP_DIR/port ${USE_XDIALOG:+-X} ;;
- "5 $msg_flags") # Set additional flags
- $BSDCFG_LIBE/$APP_DIR/flags ${USE_XDIALOG:+-X} ;;
- "6 $msg_disable") # Disable the mouse daemon
- $BSDCFG_LIBE/$APP_DIR/disable ${USE_XDIALOG:+-X} ;;
+ "X $msg_exit") break ;;
+ "2 $msg_enable") command=enable ;; # Test and run the mouse daemon
+ "3 $msg_type") command=type ;; # Select mouse protocol type
+ "4 $msg_port") command=port ;; # Select mouse port
+ "5 $msg_flags") command=flags ;; # Set additional flags
+ "6 $msg_disable") command=disable ;; # Disable the mouse daemon
esac
+ if [ "$command" ]; then
+ $BSDCFG_LIBE/$APP_DIR/$command ${USE_XDIALOG:+-X}
+ else
+ f_die 1 "$msg_unknown_mouse_menu_selection"
+ fi
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/mouse/port b/usr.sbin/bsdconfig/mouse/port
index 87d4a0b..41dd481 100755
--- a/usr.sbin/bsdconfig/mouse/port
+++ b/usr.sbin/bsdconfig/mouse/port
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -49,11 +49,8 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline=""
local prompt="$msg_port_menu_text"
-
- menu_list="
+ local menu_list="
'1 $msg_ps2' '$msg_ps2_desc'
'2 $msg_com1' '$msg_com1_desc'
'3 $msg_com2' '$msg_com2_desc'
@@ -61,27 +58,41 @@ dialog_menu_main()
'5 $msg_com4' '$msg_com4_desc'
'6 $msg_busmouse' '$msg_busmouse_desc'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline=
+
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ case "$( f_sysrc_get moused_port )" in
+ /dev/psm0) defaultitem="1 $msg_ps2" ;;
+ /dev/cuau0) defaultitem="2 $msg_com1" ;;
+ /dev/cuau1) defaultitem="3 $msg_com2" ;;
+ /dev/cuau2) defaultitem="4 $msg_com3" ;;
+ /dev/cuau3) defaultitem="5 $msg_com4" ;;
+ /dev/mse0) defaultitem="6 $msg_busmouse" ;;
+ esac
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -93,9 +104,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -110,35 +121,30 @@ f_mustberoot_init
#
# Launch application main menu
#
-while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
-
- case "$mtag" in
- "1 $msg_ps2") # PS/2 style mouse (/dev/psm0)
- f_sysrc_set moused_port "/dev/psm0" || f_die
- break ;;
- "2 $msg_com1") # Serial mouse on COM1 (/dev/cuau0)
- f_sysrc_set moused_port "/dev/cuau0" || f_die
- break ;;
- "3 $msg_com2") # Serial mouse on COM2 (/dev/cuau1)
- f_sysrc_set moused_port "/dev/cuau1" || f_die
- break ;;
- "4 $msg_com3") # Serial mouse on COM3 (/dev/cuau2)
- f_sysrc_set moused_port "/dev/cuau2" || f_die
- break ;;
- "5 $msg_com4") # Serial mouse on COM4 (/dev/cuau3)
- f_sysrc_set moused_port "/dev/cuau3" || f_die
- break ;;
- "6 $msg_busmouse") # Logitech, ATI or MS bus mouse (/dev/mse0)
- f_sysrc_set moused_port "/dev/mse0" || f_die
- break ;;
- esac
-
-done
+dialog_menu_main || f_die
+f_dialog_menutag_fetch mtag
+
+moused_port_to_set=
+case "$mtag" in
+"1 $msg_ps2") # PS/2 style mouse (/dev/psm0)
+ moused_port_to_set="/dev/psm0" ;;
+"2 $msg_com1") # Serial mouse on COM1 (/dev/cuau0)
+ moused_port_to_set="/dev/cuau0" ;;
+"3 $msg_com2") # Serial mouse on COM2 (/dev/cuau1)
+ moused_port_to_set="/dev/cuau1" ;;
+"4 $msg_com3") # Serial mouse on COM3 (/dev/cuau2)
+ moused_port_to_set="/dev/cuau2" ;;
+"5 $msg_com4") # Serial mouse on COM4 (/dev/cuau3)
+ moused_port_to_set="/dev/cuau3" ;;
+"6 $msg_busmouse") # Logitech, ATI or MS bus mouse (/dev/mse0)
+ moused_port_to_set="/dev/mse0" ;;
+esac
+
+if [ "$moused_port_to_set" ]; then
+ f_sysrc_set moused_port "$moused_port_to_set" || f_die
+else
+ f_die 1 "$msg_unknown_mouse_port_selection"
+fi
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/mouse/type b/usr.sbin/bsdconfig/mouse/type
index ee9c4ed..30d2022 100755
--- a/usr.sbin/bsdconfig/mouse/type
+++ b/usr.sbin/bsdconfig/mouse/type
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -49,11 +49,8 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline=""
local prompt="$msg_protocol_menu_text"
-
- menu_list="
+ local menu_list="
'1 $msg_auto' '$msg_auto_desc'
'2 $msg_glidepoint' '$msg_glidepoint_desc'
'3 $msg_hitachi' '$msg_hitachi_desc'
@@ -65,27 +62,45 @@ dialog_menu_main()
'9 $msg_mousesystems' '$msg_mousesystems_desc'
'A $msg_thinkingmouse' '$msg_thinkingmouse_desc'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline=
+
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ case "$( f_sysrc_get moused_type )" in
+ auto) defaultitem="1 $msg_auto" ;;
+ glidepoint) defaultitem="2 $msg_glidepoint" ;;
+ mmhittab) defaultitem="3 $msg_hitachi" ;;
+ intellimouse) defaultitem="4 $msg_intellimouse" ;;
+ logitech) defaultitem="5 $msg_logitech" ;;
+ microsoft) defaultitem="6 $msg_microsoft" ;;
+ mmseries) defaultitem="7 $msg_mm_series" ;;
+ mouseman) defaultitem="8 $msg_mouseman" ;;
+ mousesystems) defaultitem="9 $msg_mousesystems" ;;
+ thinkingmouse) defaultitem="A $msg_thinkingmouse" ;;
+ esac
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -97,9 +112,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -114,47 +129,38 @@ f_mustberoot_init
#
# Launch application main menu
#
-while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
-
- case "$mtag" in
- "1 $msg_auto") # Bus mouse, PS/2 style mouse or PnP serial mouse
- f_sysrc_set moused_type "auto" || f_die
- break ;;
- "2 $msg_glidepoint") # ALPS GlidePoint pad (serial)
- f_sysrc_set moused_type "glidepoint" || f_die
- break ;;
- "3 $msg_hitachi") # Hitachi tablet (serial)
- f_sysrc_set moused_type "mmhittab" || f_die
- break ;;
- "4 $msg_intellimouse") # Microsoft Intellimouse (serial)
- f_sysrc_set moused_type "intellimouse" || f_die
- break ;;
- "5 $msg_logitech") # Logitech protocol (old models) (serial)
- f_sysrc_set moused_type "logitech" || f_die
- break ;;
- "6 $msg_microsoft") # Microsoft protocol (serial)
- f_sysrc_set moused_type "microsoft" || f_die
- break ;;
- "7 $msg_mm_series") # MM Series protocol (serial)
- f_sysrc_set moused_type "mmseries" || f_die
- break ;;
- "8 $msg_mouseman") # Logitech MouseMan/TrackMan models (serial)
- f_sysrc_set moused_type "mouseman" || f_die
- break ;;
- "9 $msg_mousesystems") # MouseSystems protocol (serial)
- f_sysrc_set moused_type "mousesystems" || f_die
- break ;;
- "A $msg_thinkingmouse") # Kensignton ThinkingMouse (serial)
- f_sysrc_set moused_type "thinkingmouse" || f_die
- break ;;
- esac
-
-done
+dialog_menu_main || f_die
+f_dialog_menutag_fetch mtag
+
+moused_type_to_set=
+case "$mtag" in
+"1 $msg_auto") # Bus mouse, PS/2 style mouse or PnP serial mouse
+ moused_type_to_set="auto" ;;
+"2 $msg_glidepoint") # ALPS GlidePoint pad (serial)
+ moused_type_to_set="glidepoint" ;;
+"3 $msg_hitachi") # Hitachi tablet (serial)
+ moused_type_to_set="mmhittab" ;;
+"4 $msg_intellimouse") # Microsoft Intellimouse (serial)
+ moused_type_to_set="intellimouse" ;;
+"5 $msg_logitech") # Logitech protocol (old models) (serial)
+ moused_type_to_set="logitech" ;;
+"6 $msg_microsoft") # Microsoft protocol (serial)
+ moused_type_to_set="microsoft" ;;
+"7 $msg_mm_series") # MM Series protocol (serial)
+ moused_type_to_set="mmseries" ;;
+"8 $msg_mouseman") # Logitech MouseMan/TrackMan models (serial)
+ moused_type_to_set="mouseman" ;;
+"9 $msg_mousesystems") # MouseSystems protocol (serial)
+ moused_type_to_set="mousesystems" ;;
+"A $msg_thinkingmouse") # Kensignton ThinkingMouse (serial)
+ moused_type_to_set="thinkingmouse" ;;
+esac
+
+if [ "$moused_type_to_set" ]; then
+ f_sysrc_set moused_type "$moused_type_to_set" || f_die
+else
+ f_die 1 "$msg_unknown_mouse_protocol_selection"
+fi
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/networking/INDEX b/usr.sbin/bsdconfig/networking/INDEX
index 1d23911..8527124 100644
--- a/usr.sbin/bsdconfig/networking/INDEX
+++ b/usr.sbin/bsdconfig/networking/INDEX
@@ -26,32 +26,36 @@
# $FreeBSD$
#
-# Title that will be shown on the bsdconfig menu
+# Title that will be shown in the bsdconfig menu.
+#
menu_title="Networking Management"
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
#
-# a short descriptive line shown at the bottom of the bsdconfig menu.
-# keep it short because any line longer than the terminal width will
-# be truncated.
menu_help="Setup Networking interfaces, services, etc."
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
#
-# two-part variable that defines an action to take when 'keyword'
-# is passed on a bsdconfig command line. variable takes the form
-# "keyword|command" and multiple occurrences of the variable
-# (with different 'keyword's, or different 'keyword's AND 'command's)
-# are allowed. If 'command' begins with a '/' then the full
-# path to the program is needed. If 'command' begins with anything
-# else it is a path relative to the directory this INDEX file is in.
-# 'keyword' can be i18n'ed but 'command' is the name of a script.
menu_selection="networking|networking"
menu_selection="defaultrouter|defaultrouter"
menu_selection="hostname|hostname"
menu_selection="nameservers|nameservers"
menu_selection="netdev|devices"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
#
-# Items below this line do NOT need i18n translation----------------------
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
#
-# Name of the program to be run when this menu choice is selected.
-# if it begins with a '/' then the full path to the program is needed.
-# if it begins with anything else it is a path relative to the directory
-# this INDEX file is in.
menu_program="networking"
diff --git a/usr.sbin/bsdconfig/networking/USAGE b/usr.sbin/bsdconfig/networking/USAGE
index a4dd74c..8720946 100644
--- a/usr.sbin/bsdconfig/networking/USAGE
+++ b/usr.sbin/bsdconfig/networking/USAGE
@@ -1,5 +1,5 @@
-# Copyright (c) 2006-2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2006-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -11,11 +11,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -27,7 +27,11 @@
Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS]
OPTIONS:
- -h Print usage statement and exit.
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
+ -h Print this usage statement and exit.
-S Secure X11 mode (implies `-X'). As root, always prompt-for
and validate sudo(8) username/password before starting.
-X Use Xdialog(1) in place of dialog(1).
diff --git a/usr.sbin/bsdconfig/networking/defaultrouter b/usr.sbin/bsdconfig/networking/defaultrouter
index 44e522e..4719e45 100755
--- a/usr.sbin/bsdconfig/networking/defaultrouter
+++ b/usr.sbin/bsdconfig/networking/defaultrouter
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2006-2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2006-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -49,9 +49,9 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
diff --git a/usr.sbin/bsdconfig/networking/devices b/usr.sbin/bsdconfig/networking/devices
index f9c27b4..00a50c5 100755
--- a/usr.sbin/bsdconfig/networking/devices
+++ b/usr.sbin/bsdconfig/networking/devices
@@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2006-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -54,9 +54,9 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line options
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -71,12 +71,11 @@ f_mustberoot_init
#
# Launch application main menu
#
+defaultitem=
while :; do
- f_dialog_menu_netdev
- retval=$?
- interface=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || break
+ f_dialog_menu_netdev "$defaultitem" || break
+ f_dialog_menutag_fetch interface
+ defaultitem="$interface"
#
# dialog_menu_netdev adds an asterisk (*) to the right of the
@@ -84,7 +83,7 @@ while :; do
# from the device name if present.
#
case "$interface" in
- *\*) interface="${interface%?}";;
+ *\*) interface="${interface%?}" ;;
esac
#
@@ -97,38 +96,39 @@ while :; do
# fallback to reading the active configuration if not configured in
# the rc.conf(5) file(s).
#
+ dhcp=
_ipaddr=
_netmask=
_ifconfig=$( f_sysrc_get ifconfig_$interface )
if [ "$_ifconfig" ]; then
- # If DHCP get IP address/netmask later from ifconfig(8)
+ # If DHCP, get IP address/netmask later from ifconfig(8)
glob="[Dd][Hh][Cc][Pp]"
case "$_ifconfig" in
- $glob) dhcp=1;;
- [Ss][Yy][Nn][Cc]$glob) dhcp=1;;
- [Nn][Oo][Ss][Yy][Nn][Cc]$glob) dhcp=1;;
+ $glob) dhcp=1 ;;
+ [Ss][Yy][Nn][Cc]$glob) dhcp=1 ;;
+ [Nn][Oo][Ss][Yy][Nn][Cc]$glob) dhcp=1 ;;
*)
#
- # Get IP address/netmask from rc.conf(5)
- # configuration
+ # Get IP address/netmask from rc.conf(5) configuration
#
dhcp=
- eval "$( exec 2> /dev/null
- set -- $_ifconfig
- while [ $# -gt 0 ]; do
- case "$1" in
- inet)
- shift 1
- echo "_ipaddr='$1'"
- ;;
- netmask)
- shift 1
- echo "_netmask='$1'"
- ;;
- esac
- shift 1
- done
- )"
+ eval "$(
+ exec 2> /dev/null
+ set -- $_ifconfig
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ inet)
+ shift 1
+ echo "_ipaddr='$1'"
+ ;;
+ netmask)
+ shift 1
+ echo "_netmask='$1'"
+ ;;
+ esac
+ shift 1
+ done
+ )"
;;
esac
fi
@@ -145,11 +145,10 @@ while :; do
# Block on user-configuration of the probed settings
f_dialog_menu_netdev_edit \
- $interface $_ipaddr $_netmask "$_options" $dhcp
+ "$interface" "$_ipaddr" "$_netmask" "$_options" $dhcp
# Return to root menu if above returns success
[ $? -eq $SUCCESS ] && break
-
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/networking/hostname b/usr.sbin/bsdconfig/networking/hostname
index 231320e..23cf804 100755
--- a/usr.sbin/bsdconfig/networking/hostname
+++ b/usr.sbin/bsdconfig/networking/hostname
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2006-2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2006-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -28,6 +28,9 @@
#
############################################################ INCLUDES
+# Prevent device.subr (included indirectly) from auto scanning on load
+DEVICE_SELF_SCAN_ALL=NO
+
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." "$0"
@@ -49,9 +52,9 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
diff --git a/usr.sbin/bsdconfig/networking/include/messages.subr b/usr.sbin/bsdconfig/networking/include/messages.subr
index 3a3d1bc..ad5461c 100644
--- a/usr.sbin/bsdconfig/networking/include/messages.subr
+++ b/usr.sbin/bsdconfig/networking/include/messages.subr
@@ -73,7 +73,7 @@ msg_network_configuration="%s Network Configuration:\nChoose Save/Exit when fini
msg_network_interfaces="Network Interfaces"
msg_network_management="Network Management"
msg_networking_devices="Networking Devices"
-msg_nfs_mounts_may_cause_hang="WARNING! Changing this setting while NFS directories are\nmounted may cause the system to hang. Please exit this\nutility and dismount any/all remaining NFS-mounts before\nattempting to change this setting.\n\n%s"
+msg_nfs_mounts_may_cause_hang="WARNING! Changing this setting while NFS directories are\nmounted may cause the system to hang. Are you sure you\nwant to proceed?\n\n%s"
msg_no_network_interfaces="No network interfaces detected."
msg_no_options="No options (Default)"
msg_ok="OK"
@@ -99,6 +99,7 @@ msg_saving_network_interface="Saving %s network interface settings..."
msg_scanning_for_dhcp="Scanning for DHCP servers on %s interface..."
msg_select_network_interface="Select a network interface to configure.\n\n* Interface is marked as \"active\""
msg_supported_media_options="Below is a list of supported media options for the %s interface. Please select the options that you would like to set for the %s network interface"
+msg_unknown_networking_menu_selection="Unknown networking menu selection"
xmsg_please_enter_fqhn="Please enter your fully qualified hostname (e.g. foo.bar.com).\n The domain portion of the hostname will be configured in resolv.conf(5)."
xmsg_please_enter_nameserver_existing="Please enter the new IP address of the DNS nameserver\n(set to the NULL string to remove entry):"
xmsg_supported_media_options="Below is a list of supported media options for the %s interface. Please\nselect the options that you would like to set for the %s network interface"
diff --git a/usr.sbin/bsdconfig/networking/nameservers b/usr.sbin/bsdconfig/networking/nameservers
index 9ebebc8..108c567 100755
--- a/usr.sbin/bsdconfig/networking/nameservers
+++ b/usr.sbin/bsdconfig/networking/nameservers
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2006-2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2006-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -28,6 +28,9 @@
#
############################################################ INCLUDES
+# Prevent device.subr (included indirectly) from auto scanning on load
+DEVICE_SELF_SCAN_ALL=NO
+
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." "$0"
@@ -49,9 +52,9 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
diff --git a/usr.sbin/bsdconfig/networking/networking b/usr.sbin/bsdconfig/networking/networking
index 8acfbde..b320e5d 100755
--- a/usr.sbin/bsdconfig/networking/networking
+++ b/usr.sbin/bsdconfig/networking/networking
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2006-2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2006-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -48,36 +48,45 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline="$hline_arrows_tab_enter"
-
- menu_list="
+ local prompt=
+ local menu_list="
'X' '$msg_exit'
'1' '$msg_hostname_domain'
'2' '$msg_network_interfaces'
'3' '$msg_default_router'
'4' '$msg_dns_nameservers'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_arrows_tab_enter"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ # Obtain default-item from previously stored selection
+ f_dialog_default_fetch defaultitem
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\" $size $menu_list \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+ f_dialog_default_store "$menu_choice"
return $retval
}
@@ -89,9 +98,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -107,41 +116,32 @@ f_mustberoot_init
# Launch application main menu
#
while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
+ dialog_menu_main || f_die
+ f_dialog_menutag_fetch mtag
+ command=
case "$mtag" in
- X) # Exit
- break
- ;;
-
- 1) # Hostname/Domain
- $BSDCFG_LIBE/$APP_DIR/hostname ${USE_XDIALOG:+-X}
- ;;
-
- 2) # Network Interfaces
- $BSDCFG_LIBE/$APP_DIR/devices ${USE_XDIALOG:+-X}
-
- # Make subsequent uses of this menu faster by not performing
- # "ifconfig up" (limiting the pain one must endure). See also
- # `$BSDCFG_SHARE/networking/device.subr'.
- #
- export DIALOG_MENU_NETDEV_KICK_INTERFACES=
- ;;
-
- 3) # Default Router/Gateway
- $BSDCFG_LIBE/$APP_DIR/defaultrouter ${USE_XDIALOG:+-X}
- ;;
-
- 4) # DNS nameservers
- $BSDCFG_LIBE/$APP_DIR/nameservers ${USE_XDIALOG:+-X}
- ;;
-
+ X) break ;;
+ 1) command=hostname ;; # Hostname/Domain
+ 2) command=devices ;; # Network Interfaces
+ 3) command=defaultrouter ;; # Default Router/Gateway
+ 4) command=nameservers ;; # DNS nameservers
esac
+ if [ "$command" ]; then
+ $BSDCFG_LIBE/$APP_DIR/$command ${USE_XDIALOG:+-X}
+ else
+ f_die 1 "$msg_unknown_networking_menu_selection"
+ fi
+
+ if [ "$mtag" = "devices" ]; then
+ #
+ # Make subsequent uses of this menu faster by not performing
+ # "ifconfig up" (limiting the pain one must endure). See also
+ # `$BSDCFG_SHARE/networking/device.subr'.
+ #
+ export DIALOG_MENU_NETDEV_KICK_INTERFACES=
+ fi
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/networking/share/Makefile b/usr.sbin/bsdconfig/networking/share/Makefile
index 6bd594c..cf1119d 100644
--- a/usr.sbin/bsdconfig/networking/share/Makefile
+++ b/usr.sbin/bsdconfig/networking/share/Makefile
@@ -4,7 +4,7 @@ NO_OBJ=
FILESDIR= ${SHAREDIR}/bsdconfig/networking
FILES= common.subr device.subr hostname.subr ipaddr.subr media.subr \
- netmask.subr resolv.subr routing.subr
+ netmask.subr resolv.subr routing.subr services.subr
beforeinstall:
mkdir -p ${DESTDIR}${FILESDIR}
diff --git a/usr.sbin/bsdconfig/networking/share/common.subr b/usr.sbin/bsdconfig/networking/share/common.subr
index 1a37a9c..152d1ac 100644
--- a/usr.sbin/bsdconfig/networking/share/common.subr
+++ b/usr.sbin/bsdconfig/networking/share/common.subr
@@ -1,7 +1,7 @@
if [ ! "$_NETWORKING_COMMON_SUBR" ]; then _NETWORKING_COMMON_SUBR=1
#
# Copyright (c) 2006-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_NETWORKING_COMMON_SUBR" ]; then _NETWORKING_COMMON_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
diff --git a/usr.sbin/bsdconfig/networking/share/device.subr b/usr.sbin/bsdconfig/networking/share/device.subr
index cac8ef5..a0ca5cc 100644
--- a/usr.sbin/bsdconfig/networking/share/device.subr
+++ b/usr.sbin/bsdconfig/networking/share/device.subr
@@ -1,7 +1,7 @@
if [ ! "$_NETWORKING_DEVICE_SUBR" ]; then _NETWORKING_DEVICE_SUBR=1
#
# Copyright (c) 2006-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_NETWORKING_DEVICE_SUBR" ]; then _NETWORKING_DEVICE_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -33,7 +33,6 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
f_dprintf "%s: loading includes..." networking/device.subr
f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/sysrc.subr
f_include $BSDCFG_SHARE/media/tcpip.subr
f_include $BSDCFG_SHARE/networking/common.subr
f_include $BSDCFG_SHARE/networking/ipaddr.subr
@@ -41,6 +40,7 @@ f_include $BSDCFG_SHARE/networking/media.subr
f_include $BSDCFG_SHARE/networking/netmask.subr
f_include $BSDCFG_SHARE/networking/resolv.subr
f_include $BSDCFG_SHARE/networking/routing.subr
+f_include $BSDCFG_SHARE/sysrc.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
@@ -55,12 +55,15 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
############################################################ FUNCTIONS
-# f_dialog_menu_netdev
+# f_dialog_menu_netdev [$default]
#
-# Display a list of network devices with descriptions.
+# Display a list of network devices with descriptions. Optionally, if present
+# and non-NULL, initially highlight $default interface.
#
f_dialog_menu_netdev()
{
+ local defaultitem="${1%\*}" # Tim trailing asterisk if present
+
#
# Display a message to let the user know we're working...
# (message will remain until we throw up the next dialog)
@@ -121,36 +124,47 @@ f_dialog_menu_netdev()
done
)
if [ ! "$interfaces" ]; then
- f_dialog_msgbox "$msg_no_network_interfaces"
+ f_show_msg "$msg_no_network_interfaces"
return $FAILURE
fi
+ #
+ # Maybe the default item was marked as active
+ #
+ if [ "$defaultitem" ]; then
+ ifconfig "$defaultitem" 2> /dev/null | awk \
+ '( $1 == "status:" && $2 != "active" ) { exit 0 }' ||
+ defaultitem="$defaultitem*"
+ fi
+
local hline="$hline_arrows_tab_enter"
#
# Ask user to select an interface
#
- local prompt size
- prompt="$msg_select_network_interface"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $interfaces )
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local prompt="$msg_select_network_interface"
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $interfaces
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$interfaces \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -162,7 +176,7 @@ f_dialog_menu_netdev()
f_dialog_menu_netdev_edit()
{
local interface="$1" ipaddr="$2" netmask="$3" options="$4" dhcp="$5"
- local prompt menu_list size
+ local prompt menu_list height width rows
#
# Create a duplicate set of variables for change-tracking...
@@ -188,6 +202,7 @@ f_dialog_menu_netdev_edit()
# changes effective because all three options must be specified at-once
# to ifconfig(8).
#
+ local defaultitem=
while :; do
local dhcp_status="$msg_disabled"
[ "$dhcp" ] && dhcp_status="$msg_enabled"
@@ -202,15 +217,15 @@ f_dialog_menu_netdev_edit()
'4 $msg_netmask' '$netmask'
'5 $msg_options' '$options'
"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+ local tag
+ tag=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
@@ -218,14 +233,14 @@ f_dialog_menu_netdev_edit()
--help-button \
--help-label \"\$msg_help\" \
${USE_XDIALOG:+--help \"\"} \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
-
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- local tag="$( f_dialog_menutag )"
+ f_dialog_data_sanitize tag
if [ $retval -eq 2 ]; then
# The Help button was pressed
@@ -234,6 +249,9 @@ f_dialog_menu_netdev_edit()
elif [ $retval -ne $SUCCESS ]; then
# "Cancel" was chosen (-1) or ESC was pressed (255)
return $retval
+ else
+ # Only update default-item on success
+ defaultitem="$tag"
fi
#
@@ -243,18 +261,17 @@ f_dialog_menu_netdev_edit()
# read and display in the summary dialog.
#
case "$tag" in
- X\ *) break;;
+ X\ *) break ;;
2\ *) #
- # Do not proceed if/when there are NFS-mounts currently
- # active. If the network is changed while NFS-exported
- # directories are mounted, the system may hang (if any
- # NFS mounts are using that interface).
+ # Proceed cautiously (confirm with the user) if/when NFS-
+ # mounts are active. If the network on which these mounts
+ # are made is changed parts of the system may hang.
#
if f_nfs_mounted && ! f_jailed; then
local setting="$( printf "$msg_current_dhcp_status" \
"$interface" "$dhcp_status" )"
- f_show_msg "$msg_nfs_mounts_may_cause_hang" "$setting"
- continue
+ f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" ||
+ continue
fi
#
@@ -295,11 +312,11 @@ f_dialog_menu_netdev_edit()
fi
;;
3\ *) f_dialog_input_ipaddr "$interface" "$ipaddr"
- [ $? -eq $SUCCESS ] && dhcp=;;
+ [ $? -eq $SUCCESS ] && dhcp= ;;
4\ *) f_dialog_input_netmask "$interface" "$netmask"
- [ $? -eq $SUCCESS -a "$_netmask" ] && dhcp=;;
+ [ $? -eq $SUCCESS -a "$_netmask" ] && dhcp= ;;
5\ *) f_dialog_menu_media_options "$interface" "$options"
- [ $? -eq $SUCCESS ] && dhcp=;;
+ [ $? -eq $SUCCESS ] && dhcp= ;;
esac
done
diff --git a/usr.sbin/bsdconfig/networking/share/hostname.subr b/usr.sbin/bsdconfig/networking/share/hostname.subr
index 61df2b4..05f0315 100644
--- a/usr.sbin/bsdconfig/networking/share/hostname.subr
+++ b/usr.sbin/bsdconfig/networking/share/hostname.subr
@@ -1,7 +1,7 @@
if [ ! "$_NETWORKING_HOSTNAME_SUBR" ]; then _NETWORKING_HOSTNAME_SUBR=1
#
# Copyright (c) 2006-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_NETWORKING_HOSTNAME_SUBR" ]; then _NETWORKING_HOSTNAME_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,10 +31,10 @@ if [ ! "$_NETWORKING_HOSTNAME_SUBR" ]; then _NETWORKING_HOSTNAME_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." networking/hostname.subr
-f_include $BSDCFG_SHARE/sysrc.subr
f_include $BSDCFG_SHARE/dialog.subr
f_include $BSDCFG_SHARE/networking/common.subr
f_include $BSDCFG_SHARE/networking/resolv.subr
+f_include $BSDCFG_SHARE/sysrc.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
@@ -53,11 +53,12 @@ f_dialog_hnerror()
[ ${error:-0} -ne 0 ] || return $SUCCESS
case "$error" in
- 1) f_show_msg "$msg_hostname_label_contains_invalid_chars" "$fqhn";;
- 2) f_show_msg "$msg_hostname_label_starts_or_ends_with_hyphen" "$fqhn";;
- 3) f_show_msg "$msg_hostname_label_is_null" "$fqhn";;
- 63) f_show_msg "$msg_hostname_label_exceeds_max_length" "$fqhn";;
- 255) f_show_msg "$msg_hostname_exceeds_max_length" "$fqhn";;
+ 1) f_show_msg "$msg_hostname_label_contains_invalid_chars" "$fqhn" ;;
+ 2) f_show_msg \
+ "$msg_hostname_label_starts_or_ends_with_hyphen" "$fqhn" ;;
+ 3) f_show_msg "$msg_hostname_label_is_null" "$fqhn" ;;
+ 63) f_show_msg "$msg_hostname_label_exceeds_max_length" "$fqhn" ;;
+ 255) f_show_msg "$msg_hostname_exceeds_max_length" "$fqhn" ;;
esac
}
@@ -108,9 +109,8 @@ f_dialog_input_hostname()
# Loop until the user provides taint-free input.
#
while :; do
- hostname=$( f_dialog_input "$msg" "$hostname" \
- "$hline_alnum_punc_tab_enter"
- ) || return
+ f_dialog_input hostname "$msg" "$hostname" \
+ "$hline_alnum_punc_tab_enter" || return
# Taint-check the user's input
f_dialog_validate_hostname "$hostname" && break
done
diff --git a/usr.sbin/bsdconfig/networking/share/ipaddr.subr b/usr.sbin/bsdconfig/networking/share/ipaddr.subr
index 4b39dd2..9c51f59 100644
--- a/usr.sbin/bsdconfig/networking/share/ipaddr.subr
+++ b/usr.sbin/bsdconfig/networking/share/ipaddr.subr
@@ -1,7 +1,7 @@
if [ ! "$_NETWORKING_IPADDR_SUBR" ]; then _NETWORKING_IPADDR_SUBR=1
#
# Copyright (c) 2006-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_NETWORKING_IPADDR_SUBR" ]; then _NETWORKING_IPADDR_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -32,8 +32,8 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." networking/ipaddr.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/strings.subr
f_include $BSDCFG_SHARE/networking/common.subr
+f_include $BSDCFG_SHARE/strings.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
@@ -52,10 +52,10 @@ f_dialog_iperror()
[ ${error:-0} -ne 0 ] || return $SUCCESS
case "$error" in
- 1) f_show_msg "$msg_ipv4_addr_octet_contains_invalid_chars" "$ip";;
- 2) f_show_msg "$msg_ipv4_addr_octet_is_null" "$ip";;
- 3) f_show_msg "$msg_ipv4_addr_octet_exceeds_max_value" "$ip";;
- 4) f_show_msg "$msg_ipv4_addr_octet_missing_or_extra" "$ip";;
+ 1) f_show_msg "$msg_ipv4_addr_octet_contains_invalid_chars" "$ip" ;;
+ 2) f_show_msg "$msg_ipv4_addr_octet_is_null" "$ip" ;;
+ 3) f_show_msg "$msg_ipv4_addr_octet_exceeds_max_value" "$ip" ;;
+ 4) f_show_msg "$msg_ipv4_addr_octet_missing_or_extra" "$ip" ;;
esac
}
@@ -91,10 +91,10 @@ f_dialog_ip6error()
[ ${error:-0} -ne 0 ] || return $SUCCESS
case "$error" in
- 1) f_show_msg "$msg_ipv6_addr_segment_contains_invalid_chars" "$ip";;
- 2) f_show_msg "$msg_ipv6_addr_too_many_null_segments" "$ip";;
- 3) f_show_msg "$msg_ipv6_addr_segment_contains_too_many_chars" "$ip";;
- 4) f_show_msg "$msg_ipv6_addr_too_few_or_extra_segments" "$ip";;
+ 1) f_show_msg "$msg_ipv6_addr_segment_contains_invalid_chars" "$ip" ;;
+ 2) f_show_msg "$msg_ipv6_addr_too_many_null_segments" "$ip" ;;
+ 3) f_show_msg "$msg_ipv6_addr_segment_contains_too_many_chars" "$ip" ;;
+ 4) f_show_msg "$msg_ipv6_addr_too_few_or_extra_segments" "$ip" ;;
*)
if [ $(( $error & 0xF )) -eq 5 ]; then
# IPv4 at the end of IPv6 address is invalid
@@ -146,8 +146,8 @@ f_dialog_input_ipaddr()
if f_nfs_mounted && ! f_jailed; then
local setting="$( printf "$msg_current_ipaddr" \
"$interface" "$_ipaddr" )"
- f_show_msg "$msg_nfs_mounts_may_cause_hang" "$setting"
- return $FAILURE
+ f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" ||
+ return $FAILURE
fi
local msg="$( printf "$msg_please_enter_new_ip_addr" "$interface" )"
@@ -162,9 +162,8 @@ f_dialog_input_ipaddr()
# - User has either pressed ESC or chosen Cancel/No
# - User has not made any changes to the given value
#
- _input=$( f_dialog_input "$msg" "$_ipaddr" \
- "$hline_num_punc_tab_enter"
- ) || return
+ f_dialog_input _input "$msg" "$_ipaddr" \
+ "$hline_num_punc_tab_enter" || return
[ "$_ipaddr" = "$_input" ] && return $FAILURE
# Return success if NULL value was entered
diff --git a/usr.sbin/bsdconfig/networking/share/media.subr b/usr.sbin/bsdconfig/networking/share/media.subr
index eed8364a..c6efa57 100644
--- a/usr.sbin/bsdconfig/networking/share/media.subr
+++ b/usr.sbin/bsdconfig/networking/share/media.subr
@@ -1,7 +1,7 @@
if [ ! "$_NETWORKING_MEDIA_SUBR" ]; then _NETWORKING_MEDIA_SUBR=1
#
-# Copyright (c) 2006-2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2006-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_NETWORKING_MEDIA_SUBR" ]; then _NETWORKING_MEDIA_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -32,9 +32,9 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." networking/media.subr
f_include $BSDCFG_SHARE/dialog.subr
+f_include $BSDCFG_SHARE/networking/common.subr
f_include $BSDCFG_SHARE/strings.subr
f_include $BSDCFG_SHARE/sysrc.subr
-f_include $BSDCFG_SHARE/networking/common.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
@@ -68,7 +68,7 @@ f_ifconfig_options()
output=
while [ $# -gt 0 ]; do
case "$1" in
- inet|netmask) shift 1;;
+ inet|netmask) shift 1 ;;
*) output="$output${output:+ }$1"
esac
shift 1
@@ -101,7 +101,9 @@ f_ifconfig_media()
# f_dialog_input_options $interface
#
-# Input custom interface options.
+# Input custom interface options. If the user does not press ESC or choose
+# Cancel/No, $options will hold the user's input. Default input is taken from
+# the same variable ($options).
#
f_dialog_input_options()
{
@@ -115,15 +117,15 @@ f_dialog_input_options()
if f_nfs_mounted && ! f_jailed; then
local setting="$( printf "$msg_current_options" \
"$interface" "$options" )"
- f_show_msg "$msg_nfs_mounts_may_cause_hang" "$setting"
- return $FAILURE
+ f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" ||
+ return $FAILURE
fi
local msg="$( printf "$msg_please_enter_mediaopts" "$interface" )"
local hline="$hline_alnum_punc_tab_enter"
- local dialog_inputbox
- dialog_inputbox=$( $DIALOG \
+ local _options
+ _options=$( $DIALOG \
--title "$DIALOG_TITLE" \
--backtitle "$DIALOG_BACKTITLE" \
--hline "$hline" \
@@ -133,10 +135,8 @@ f_dialog_input_options()
"$options" \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
-
local retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- local _options="$( f_dialog_inputstr )"
+ f_dialog_line_sanitize _options
[ $retval -eq $SUCCESS ] && options="$_options"
@@ -164,8 +164,8 @@ f_dialog_menu_media_options()
if f_nfs_mounted && ! f_jailed; then
local setting="$( printf "$msg_current_options" \
"$interface" "$_options" )"
- f_show_msg "$msg_nfs_mounts_may_cause_hang" "$setting"
- return $FAILURE
+ f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" ||
+ return $FAILURE
fi
#
@@ -205,9 +205,9 @@ f_dialog_menu_media_options()
local hline="$hline_arrows_tab_enter"
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local tag
+ tag=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
@@ -216,20 +216,22 @@ f_dialog_menu_media_options()
$supported_media \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
-
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize tag
+
if [ $retval -eq $SUCCESS ]; then
- local tag="$( f_dialog_menutag )"
options=$( eval f_dialog_menutag2item \"\$tag\" \
$supported_media )
- [ "$options" = "$opt_none" ] && options=
-
- if [ "$options" = "$opt_cust" ]; then
+ case "$options" in
+ "$opt_none")
+ options=
+ ;;
+ "$opt_cust")
options="$_options"
f_dialog_input_options "$interface"
retval=$?
- fi
+ ;;
+ esac
fi
return $retval
diff --git a/usr.sbin/bsdconfig/networking/share/netmask.subr b/usr.sbin/bsdconfig/networking/share/netmask.subr
index e6838e5..845bf7e 100644
--- a/usr.sbin/bsdconfig/networking/share/netmask.subr
+++ b/usr.sbin/bsdconfig/networking/share/netmask.subr
@@ -1,7 +1,7 @@
if [ ! "$_NETWORKING_NETMASK_SUBR" ]; then _NETWORKING_NETMASK_SUBR=1
#
# Copyright (c) 2006-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_NETWORKING_NETMASK_SUBR" ]; then _NETWORKING_NETMASK_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -32,8 +32,8 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." networking/netmask.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/strings.subr
f_include $BSDCFG_SHARE/networking/common.subr
+f_include $BSDCFG_SHARE/strings.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
@@ -52,11 +52,11 @@ f_dialog_maskerror()
[ ${error:-0} -ne 0 ] || return $SUCCESS
case "$error" in
- 1) f_show_msg "$msg_ipv4_mask_field_contains_invalid_chars" "$mask";;
- 2) f_show_msg "$msg_ipv4_mask_field_is_null" "$mask";;
- 3) f_show_msg "$msg_ipv4_mask_field_exceeds_max_value" "$mask";;
- 4) f_show_msg "$msg_ipv4_mask_field_missing_or_extra" "$mask";;
- 5) f_show_msg "$msg_ipv4_mask_field_invalid_value" "$mask";;
+ 1) f_show_msg "$msg_ipv4_mask_field_contains_invalid_chars" "$mask" ;;
+ 2) f_show_msg "$msg_ipv4_mask_field_is_null" "$mask" ;;
+ 3) f_show_msg "$msg_ipv4_mask_field_exceeds_max_value" "$mask" ;;
+ 4) f_show_msg "$msg_ipv4_mask_field_missing_or_extra" "$mask" ;;
+ 5) f_show_msg "$msg_ipv4_mask_field_invalid_value" "$mask" ;;
esac
}
@@ -96,8 +96,8 @@ f_dialog_input_netmask()
if f_nfs_mounted && ! f_jailed; then
local setting="$( printf "$msg_current_subnet" \
"$interface" "$_netmask" )"
- f_show_msg "$msg_nfs_mounts_may_cause_hang" "$setting"
- return $FAILURE
+ f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" ||
+ return $FAILURE
fi
#
@@ -110,9 +110,8 @@ f_dialog_input_netmask()
# - User has either pressed ESC or chosen Cancel/No
# - User has not made any changes to the given value
#
- _input=$( f_dialog_input "$msg" "$_netmask" \
- "$hline_num_punc_tab_enter"
- ) || return
+ f_dialog_input _input "$msg" "$_netmask" \
+ "$hline_num_punc_tab_enter" || return
[ "$_netmask" = "$_input" ] && return $FAILURE
# Return success if NULL value was entered
diff --git a/usr.sbin/bsdconfig/networking/share/resolv.subr b/usr.sbin/bsdconfig/networking/share/resolv.subr
index b525a4d..ac281fc 100644
--- a/usr.sbin/bsdconfig/networking/share/resolv.subr
+++ b/usr.sbin/bsdconfig/networking/share/resolv.subr
@@ -1,7 +1,7 @@
if [ ! "$_NETWORKING_RESOLV_SUBR" ]; then _NETWORKING_RESOLV_SUBR=1
#
# Copyright (c) 2006-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_NETWORKING_RESOLV_SUBR" ]; then _NETWORKING_RESOLV_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -32,10 +32,10 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." networking/resolv.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/strings.subr
f_include $BSDCFG_SHARE/media/tcpip.subr
f_include $BSDCFG_SHARE/networking/common.subr
f_include $BSDCFG_SHARE/networking/ipaddr.subr
+f_include $BSDCFG_SHARE/strings.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
@@ -311,9 +311,8 @@ f_dialog_input_nameserver()
# Loop until the user provides taint-free input.
#
while :; do
- new_ns=$( f_dialog_input "$msg" "$ns" \
- "$hline_num_punc_tab_enter"
- ) || return
+ f_dialog_input new_ns "$msg" "$ns" \
+ "$hline_num_punc_tab_enter" || return
# Take only the first "word" of the user's input
new_ns="${new_ns%%[$IFS]*}"
@@ -371,11 +370,11 @@ f_dialog_input_nameserver()
#
local retval=$?
case $retval in
- 1) f_die 1 "$msg_internal_error_nsindex_value" "$nsindex";;
- 2) f_dialog_msgbox "$msg_resolv_conf_changed_while_editing"
- return $retval;;
- 3) f_dialog_msgbox "$msg_resolv_conf_entry_no_longer_exists"
- return $retval;;
+ 1) f_die 1 "$msg_internal_error_nsindex_value" "$nsindex" ;;
+ 2) f_show_msg "$msg_resolv_conf_changed_while_editing"
+ return $retval ;;
+ 3) f_show_msg "$msg_resolv_conf_entry_no_longer_exists"
+ return $retval ;;
esac
#
@@ -393,21 +392,24 @@ f_dialog_input_nameserver()
#
f_dialog_menu_nameservers()
{
+ local prompt="$msg_dns_configuration"
+ local menu_list # Calculated below
+ local hline="$hline_arrows_tab_enter"
+ local defaultitem=
+
+ local height width rows
local opt_exit="$msg_return_to_previous_menu"
local opt_add="$msg_add_nameserver"
- local hline="$hline_arrows_tab_enter"
- local prompt size
#
# Loop forever until the user has finished configuring nameservers
#
- prompt="$msg_dns_configuration"
while :; do
#
# Re/Build list of nameservers
#
local nameservers="$( f_resolv_conf_nameservers )"
- local menu_list="$(
+ menu_list=$(
index=1
echo "'X $msg_exit' '$opt_exit'"
@@ -422,42 +424,48 @@ f_dialog_menu_nameservers()
echo "'$tag nameserver' '$ns'"
index=$(( $index + 1 ))
done
- )"
+ )
#
# Display configuration-edit menu
#
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+ local tag
+ tag=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
-
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- local tag="$( f_dialog_menutag )" ns=""
+ f_dialog_data_sanitize tag
# Return if "Cancel" was chosen (-1) or ESC was pressed (255)
- [ $retval -eq $SUCCESS ] || return $retval
+ if [ $retval -ne $SUCCESS ]; then
+ return $retval
+ else
+ # Only update default-item on success
+ defaultitem="$tag"
+ fi
case "$tag" in
- "X $msg_exit") break;;
+ "X $msg_exit") break ;;
"A $msg_add")
f_dialog_input_nameserver
;;
*)
+ local n ns
n=$( eval f_dialog_menutag2index \"\$tag\" $menu_list )
ns=$( eval f_dialog_menutag2item \"\$tag\" $menu_list )
f_dialog_input_nameserver $(( $n - 2 )) "$ns"
diff --git a/usr.sbin/bsdconfig/networking/share/routing.subr b/usr.sbin/bsdconfig/networking/share/routing.subr
index 2d8cafc..3af9f36 100644
--- a/usr.sbin/bsdconfig/networking/share/routing.subr
+++ b/usr.sbin/bsdconfig/networking/share/routing.subr
@@ -1,7 +1,7 @@
if [ ! "$_NETWORKING_ROUTING_SUBR" ]; then _NETWORKING_ROUTING_SUBR=1
#
# Copyright (c) 2006-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_NETWORKING_ROUTING_SUBR" ]; then _NETWORKING_ROUTING_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,11 +31,11 @@ if [ ! "$_NETWORKING_ROUTING_SUBR" ]; then _NETWORKING_ROUTING_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." networking/routing.subr
-f_include $BSDCFG_SHARE/sysrc.subr
f_include $BSDCFG_SHARE/dialog.subr
f_include $BSDCFG_SHARE/media/tcpip.subr
f_include $BSDCFG_SHARE/networking/common.subr
f_include $BSDCFG_SHARE/networking/ipaddr.subr
+f_include $BSDCFG_SHARE/sysrc.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="120.networking"
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
@@ -74,8 +74,8 @@ f_dialog_input_defaultrouter()
if f_nfs_mounted && ! f_jailed; then
local setting="$( printf "$msg_current_default_router" \
"$defaultrouter" )"
- f_show_msg "$msg_nfs_mounts_may_cause_hang" "$setting"
- return $FAILURE
+ f_noyes "$msg_nfs_mounts_may_cause_hang" "$setting" ||
+ return $FAILURE
fi
#
@@ -83,10 +83,9 @@ f_dialog_input_defaultrouter()
#
local retval
while :; do
- defaultrouter=$( f_dialog_input \
- "$msg_please_enter_default_router" \
- "$defaultrouter" "$hline_num_punc_tab_enter"
- )
+ f_dialog_input defaultrouter \
+ "$msg_please_enter_default_router" \
+ "$defaultrouter" "$hline_num_punc_tab_enter"
retval=$?
[ "$defaultrouter" ] || return $SUCCESS
[ $retval -eq $SUCCESS ] || return $retval
diff --git a/usr.sbin/bsdconfig/networking/share/services.subr b/usr.sbin/bsdconfig/networking/share/services.subr
new file mode 100644
index 0000000..b0cf95b
--- /dev/null
+++ b/usr.sbin/bsdconfig/networking/share/services.subr
@@ -0,0 +1,54 @@
+if [ ! "$_NETWORKING_SERVICES_SUBR" ]; then _NETWORKING_SERVICES_SUBR=1
+#
+# Copyright (c) 2013 Devin Teske
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+############################################################ INCLUDES
+
+BSDCFG_SHARE="/usr/share/bsdconfig"
+. $BSDCFG_SHARE/common.subr || exit 1
+f_dprintf "%s: loading includes..." networking/services.subr
+f_include $BSDCFG_SHARE/packages/packages.subr
+f_include $BSDCFG_SHARE/sysrc.subr
+
+############################################################ FUNCTIONS
+
+# f_config_pcnfsd
+#
+# Load pcnfsd package and adjust mountd_flags in rc.conf(5).
+#
+f_config_pcnfsd()
+{
+ f_package_add "pcnfsd" || return $?
+ f_sysrc_set mountd_flags "-n"
+ return $SUCCESS
+}
+
+############################################################ MAIN
+
+f_dprintf "%s: Successfully loaded." networking/services.subr
+
+fi # ! $_NETWORKING_SERVICES_SUBR
diff --git a/usr.sbin/bsdconfig/packages/INDEX b/usr.sbin/bsdconfig/packages/INDEX
new file mode 100644
index 0000000..8043477
--- /dev/null
+++ b/usr.sbin/bsdconfig/packages/INDEX
@@ -0,0 +1,56 @@
+# Copyright (c) 2013 Devin Teske
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+
+#
+# Title that will be shown in the bsdconfig menu.
+#
+menu_title="Packages"
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
+#
+menu_help="Install pre-packaged software for FreeBSD"
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
+#
+menu_selection="packages|packages"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
+#
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
+#
+menu_program="packages"
diff --git a/usr.sbin/bsdconfig/packages/Makefile b/usr.sbin/bsdconfig/packages/Makefile
new file mode 100644
index 0000000..fd96757
--- /dev/null
+++ b/usr.sbin/bsdconfig/packages/Makefile
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+NO_OBJ=
+
+SUBDIR= include
+
+FILESDIR= ${LIBEXECDIR}/bsdconfig/030.packages
+FILES= INDEX USAGE
+
+SCRIPTSDIR= ${FILESDIR}
+SCRIPTS= packages
+
+beforeinstall:
+ mkdir -p ${DESTDIR}${FILESDIR}
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/bsdconfig/packages/USAGE b/usr.sbin/bsdconfig/packages/USAGE
new file mode 100644
index 0000000..5f99b38
--- /dev/null
+++ b/usr.sbin/bsdconfig/packages/USAGE
@@ -0,0 +1,37 @@
+# Copyright (c) 2013 Devin Teske
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+
+Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS]
+
+OPTIONS:
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
+ -h Print this usage statement and exit.
+ -S Secure X11 mode (implies `-X'). As root, always prompt-for
+ and validate sudo(8) username/password before starting.
+ -X Use Xdialog(1) in place of dialog(1).
diff --git a/usr.sbin/bsdconfig/packages/include/Makefile b/usr.sbin/bsdconfig/packages/include/Makefile
new file mode 100644
index 0000000..ed2a1f3
--- /dev/null
+++ b/usr.sbin/bsdconfig/packages/include/Makefile
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+NO_OBJ=
+
+FILESDIR= ${LIBEXECDIR}/bsdconfig/030.packages/include
+FILES= messages.subr
+
+beforeinstall:
+ mkdir -p ${DESTDIR}${FILESDIR}
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/bsdconfig/packages/include/messages.subr b/usr.sbin/bsdconfig/packages/include/messages.subr
new file mode 100755
index 0000000..8e945ac
--- /dev/null
+++ b/usr.sbin/bsdconfig/packages/include/messages.subr
@@ -0,0 +1,27 @@
+# Copyright (c) 2013 Devin Teske
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+
+msg_package_selection="Package Selection"
diff --git a/usr.sbin/bsdconfig/packages/packages b/usr.sbin/bsdconfig/packages/packages
new file mode 100755
index 0000000..5b01c3e
--- /dev/null
+++ b/usr.sbin/bsdconfig/packages/packages
@@ -0,0 +1,80 @@
+#!/bin/sh
+#-
+# Copyright (c) 2013 Devin Teske
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+############################################################ INCLUDES
+
+# Prevent device.subr (included indirectly via media/*.subr below) from auto
+# scanning; we'll perform this manually using f_device_get_all() during init
+# but only after we've successfully completed f_mustberoot_init().
+#
+DEVICE_SELF_SCAN_ALL=NO
+
+BSDCFG_SHARE="/usr/share/bsdconfig"
+. $BSDCFG_SHARE/common.subr || exit 1
+f_dprintf "%s: loading includes..." "$0"
+f_include $BSDCFG_SHARE/dialog.subr
+f_include $BSDCFG_SHARE/mustberoot.subr
+f_include $BSDCFG_SHARE/packages/packages.subr
+
+BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="030.packages"
+f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
+
+ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
+[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
+
+############################################################ MAIN
+
+# Incorporate rc-file if it exists
+[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
+
+#
+# Process command-line arguments
+#
+while getopts h$GETOPTS_STDARGS flag; do
+ case "$flag" in
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
+ esac
+done
+shift $(( $OPTIND - 1 ))
+
+#
+# Initialize
+#
+f_dialog_title "$msg_package_selection"
+f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
+f_mustberoot_init
+f_device_get_all
+
+#
+# Display the package configuration menu and exit
+#
+f_package_config
+
+################################################################################
+# END
+################################################################################
diff --git a/usr.sbin/bsdconfig/password/INDEX b/usr.sbin/bsdconfig/password/INDEX
index 224897b..10f23db 100644
--- a/usr.sbin/bsdconfig/password/INDEX
+++ b/usr.sbin/bsdconfig/password/INDEX
@@ -26,28 +26,32 @@
# $FreeBSD$
#
-# Title that will be shown on the bsdconfig menu
+# Title that will be shown in the bsdconfig menu.
+#
menu_title="Root Password"
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
#
-# a short descriptive line shown at the bottom of the bsdconfig menu.
-# keep it short because any line longer than the terminal width will
-# be truncated.
menu_help="Set the system manager's password"
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
#
-# two-part variable that defines an action to take when 'keyword'
-# is passed on a bsdconfig command line. variable takes the form
-# "keyword|command" and multiple occurrences of the variable
-# (with different 'keyword's, or different 'keyword's AND 'command's)
-# are allowed. If 'command' begins with a '/' then the full
-# path to the program is needed. If 'command' begins with anything
-# else it is a path relative to the directory this INDEX file is in.
-# 'keyword' can be i18n'ed but 'command' is the name of a script.
menu_selection="password|password"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
#
-# Items below this line do NOT need i18n translation----------------------
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
#
-# Name of the program to be run when this menu choice is selected.
-# if it begins with a '/' then the full path to the program is needed.
-# if it begins with anything else it is a path relative to the directory
-# this INDEX file is in.
menu_program="password"
diff --git a/usr.sbin/bsdconfig/password/USAGE b/usr.sbin/bsdconfig/password/USAGE
index 9aa4dca..a06d8af 100644
--- a/usr.sbin/bsdconfig/password/USAGE
+++ b/usr.sbin/bsdconfig/password/USAGE
@@ -1,5 +1,5 @@
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -11,11 +11,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -27,7 +27,11 @@
Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS]
OPTIONS:
- -h Print usage statement and exit.
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
+ -h Print this usage statement and exit.
-S Secure X11 mode (implies `-X'). As root, always prompt-for
and validate sudo(8) username/password before starting.
-X Use Xdialog(1) in place of dialog(1).
diff --git a/usr.sbin/bsdconfig/password/include/messages.subr b/usr.sbin/bsdconfig/password/include/messages.subr
index ac01ccc..655160d 100644
--- a/usr.sbin/bsdconfig/password/include/messages.subr
+++ b/usr.sbin/bsdconfig/password/include/messages.subr
@@ -1,4 +1,4 @@
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -26,8 +26,8 @@
hline_alnum_punc_tab_enter="Use alpha-numeric, punctuation, TAB or ENTER"
msg_cancel="Cancel"
+msg_enter_new_password="Enter New Password"
msg_ok="OK"
-msg_password="Password"
msg_password_changed="Password successfully changed."
msg_password_is_empty="Password is empty."
msg_passwords_do_not_match="Passwords do not match."
diff --git a/usr.sbin/bsdconfig/password/password b/usr.sbin/bsdconfig/password/password
index 50d963d..662a536 100755
--- a/usr.sbin/bsdconfig/password/password
+++ b/usr.sbin/bsdconfig/password/password
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -55,9 +55,9 @@ USER_ROOT=root
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -69,10 +69,13 @@ f_dialog_title "$msg_root_password"
f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
f_mustberoot_init
+#
+# Prompt the user to input a new password (and change it if they don't cancel)
+#
if f_dialog_input_password; then
err=$( echo "$pw_password" | pw usermod $USER_ROOT -h 0 2>&1 ) ||
f_die $? "%s" "$err"
- f_dialog_msgbox "$msg_password_changed"
+ f_show_msg "$msg_password_changed"
fi
return $SUCCESS
diff --git a/usr.sbin/bsdconfig/password/share/password.subr b/usr.sbin/bsdconfig/password/share/password.subr
index f4ebaab9..05db7f1 100644
--- a/usr.sbin/bsdconfig/password/share/password.subr
+++ b/usr.sbin/bsdconfig/password/share/password.subr
@@ -1,6 +1,6 @@
if [ ! "$_PASSWORD_PASSWORD_SUBR" ]; then _PASSWORD_PASSWORD_SUBR=1
#
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -45,76 +45,68 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
#
f_dialog_input_password()
{
+ local prompt1="$msg_enter_new_password"
+ local prompt2="$msg_reenter_password"
local hline="$hline_alnum_punc_tab_enter"
- local msg size rmsg rsize
- msg=$( printf "$msg_password" )
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "" \
- "$hline" )
-
- rmsg=$( printf "$msg_reenter_password" )
- rsize=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$rmsg" \
- "" \
- "$hline" )
+ local height1 width1
+ f_dialog_inputbox_size height1 width1 \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$prompt1" \
+ "" \
+ "$hline"
+
+ local height2 width2
+ f_dialog_inputbox_size height2 width2 \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$prompt2" \
+ "" \
+ "$hline"
#
# Loop until the user provides taint-free/valid input
#
- local retval _password1 _password2
+ local _password1 _password2
while :; do
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --insecure \
- --passwordbox \"\$msg\" $size \
+ _password1=$( $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$hline" \
+ --ok-label "$msg_ok" \
+ --cancel-label "$msg_cancel" \
+ --insecure \
+ --passwordbox "$prompt1" \
+ $height1 $width1 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _password1=$( f_dialog_inputstr )
-
- # Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
-
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --insecure \
- --passwordbox \"\$rmsg\" $rsize \
+ ) || return $?
+ # Return if user either pressed ESC or chose Cancel/No
+ debug= f_dialog_line_sanitize _password1
+
+ _password2=$( $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$hline" \
+ --ok-label "$msg_ok" \
+ --cancel-label "$msg_cancel" \
+ --insecure \
+ --passwordbox "$prompt2" \
+ $height2 $width2 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _password2=$( f_dialog_inputstr )
-
- # Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ ) || return $?
+ # Return if user either pressed ESC or chose Cancel/No
+ debug= f_dialog_line_sanitize _password2
# Check for NULL entry
if ! [ "$_password1" -o "$_password2" ]; then
- f_dialog_msgbox "$msg_password_is_empty"
+ f_show_msg "$msg_password_is_empty"
continue
fi
# Check for password mismatch
if [ "$_password1" != "$_password2" ]; then
- f_dialog_msgbox "$msg_passwords_do_not_match"
+ f_show_msg "$msg_passwords_do_not_match"
continue
fi
diff --git a/usr.sbin/bsdconfig/security/INDEX b/usr.sbin/bsdconfig/security/INDEX
index 1a271ec..9e77186 100644
--- a/usr.sbin/bsdconfig/security/INDEX
+++ b/usr.sbin/bsdconfig/security/INDEX
@@ -26,29 +26,33 @@
# $FreeBSD$
#
-# Title that will be shown on the bsdconfig menu
+# Title that will be shown in the bsdconfig menu.
+#
menu_title="Security"
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
#
-# a short descriptive line shown at the bottom of the bsdconfig menu.
-# keep it short because any line longer than the terminal width will
-# be truncated.
menu_help="Set Security Parameters"
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
#
-# two-part variable that defines an action to take when 'keyword'
-# is passed on a bsdconfig command line. variable takes the form
-# "keyword|command" and multiple occurrences of the variable
-# (with different 'keyword's, or different 'keyword's AND 'command's)
-# are allowed. If 'command' begins with a '/' then the full
-# path to the program is needed. If 'command' begins with anything
-# else it is a path relative to the directory this INDEX file is in.
-# 'keyword' can be i18n'ed but 'command' is the name of a script.
menu_selection="security|security"
menu_selection="kern_securelevel|kern_securelevel"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
#
-# Items below this line do NOT need i18n translation----------------------
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
#
-# Name of the program to be run when this menu choice is selected.
-# if it begins with a '/' then the full path to the program is needed.
-# if it begins with anything else it is a path relative to the directory
-# this INDEX file is in.
menu_program="security"
diff --git a/usr.sbin/bsdconfig/security/USAGE b/usr.sbin/bsdconfig/security/USAGE
index 9aa4dca..a06d8af 100644
--- a/usr.sbin/bsdconfig/security/USAGE
+++ b/usr.sbin/bsdconfig/security/USAGE
@@ -1,5 +1,5 @@
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -11,11 +11,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -27,7 +27,11 @@
Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS]
OPTIONS:
- -h Print usage statement and exit.
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
+ -h Print this usage statement and exit.
-S Secure X11 mode (implies `-X'). As root, always prompt-for
and validate sudo(8) username/password before starting.
-X Use Xdialog(1) in place of dialog(1).
diff --git a/usr.sbin/bsdconfig/security/include/messages.subr b/usr.sbin/bsdconfig/security/include/messages.subr
index 162cebd..f6df667 100644
--- a/usr.sbin/bsdconfig/security/include/messages.subr
+++ b/usr.sbin/bsdconfig/security/include/messages.subr
@@ -30,7 +30,7 @@ msg_cancel="Cancel"
msg_disable_securelevels="Disable securelevels"
msg_disabled="Disabled"
msg_exit="Exit"
-msg_exit_this_menu="Exit this menu (returning to previous)"
+msg_exit_this_menu="Exit this menu"
msg_highly_secure="Highly Secure"
msg_highly_secure_mode="Highly secure mode"
msg_menu_text="This menu allows you to configure aspects of the operating system security\npolicy. Please read the system documentation carefully before modifying\nthese settings, as they may cause service disruption if used improperly.\n\nMost settings will take affect only following a system reboot."
@@ -46,3 +46,5 @@ msg_securelevel_desc="Configure securelevels for the system"
msg_securelevels_menu_text="This menu allows you to select the securelevel your system runs with.\nWhen operating at a securelevel, certain root privileges are disabled,\nwhich may increase resistance to exploits and protect system integrity.\nIn secure mode system flags may not be overridden by the root user,\naccess to direct kernel memory is limited, and kernel modules may not\nbe changed. In highly secure mode, mounted file systems may not be\nmodified on-disk, tampering with the system clock is prohibited. In\nnetwork secure mode configuration changes to firewalling are prohibited.\n "
msg_securelevels_menu_title="Securelevel Configuration Menu"
msg_system_security_options_menu="System Security Options Menu"
+msg_unknown_kern_securelevel_selection="Unknown kern.securelevel selection"
+msg_unknown_security_menu_selection="Unknown security menu selection"
diff --git a/usr.sbin/bsdconfig/security/kern_securelevel b/usr.sbin/bsdconfig/security/kern_securelevel
index 42594c6..fd1c91c 100755
--- a/usr.sbin/bsdconfig/security/kern_securelevel
+++ b/usr.sbin/bsdconfig/security/kern_securelevel
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -51,28 +51,38 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline="$hline_select_securelevel_to_operate_at"
local prompt="$msg_securelevels_menu_text"
-
- menu_list="
- 'X $msg_exit' '$msg_exit_this_menu'
+ local menu_list="
'$msg_disabled' '$msg_disable_securelevels'
'$msg_secure' '$msg_secure_mode'
'$msg_highly_secure' '$msg_highly_secure_mode'
'$msg_network_secure' '$msg_network_secure_mode'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_select_securelevel_to_operate_at"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ case "$( f_sysrc_get kern_securelevel_enable )" in
+ [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+ case "$( f_sysrc_get kern_securelevel )" in
+ 1) defaultitem="$msg_secure" ;;
+ 2) defaultitem="$msg_highly_secure" ;;
+ 3) defaultitem="$msg_network_secure" ;;
+ esac ;;
+ *)
+ defaultitem="$msg_disabled"
+ esac
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
@@ -80,12 +90,14 @@ dialog_menu_main()
--help-button \
--help-label \"\$msg_help\" \
${USE_XDIALOG:+--help \"\"} \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -97,9 +109,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -112,12 +124,12 @@ f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
f_mustberoot_init
#
-# Launch application main menu
+# Launch application main menu (loop for additional `Help' button)
#
while :; do
dialog_menu_main
retval=$?
- mtag=$( f_dialog_menutag )
+ f_dialog_menutag_fetch mtag
if [ $retval -eq 2 ]; then
# The Help button was pressed
@@ -146,6 +158,8 @@ case "$mtag" in
f_sysrc_set kern_securelevel_enable "YES"
f_sysrc_set kern_securelevel "3"
;;
+*)
+ f_die 1 "$msg_unknown_kern_securelevel_selection"
esac
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/security/security b/usr.sbin/bsdconfig/security/security
index f503e51..ca19a26 100755
--- a/usr.sbin/bsdconfig/security/security
+++ b/usr.sbin/bsdconfig/security/security
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -49,57 +49,82 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline="$hline_arrows_tab_enter"
local prompt="$msg_menu_text"
-
- menu_list="
- 'X <<< $msg_exit' '$msg_exit_this_menu'
+ local menu_list="
+ 'X $msg_exit' '$msg_exit_this_menu'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_arrows_tab_enter"
+ # Obtain default-item (adjusted below for dynamic tags)
+ f_dialog_default_fetch defaultitem
+ local ditem="${defaultitem%%[$IFS]*}"
+
+ #
+ # Add dynamically tagged entry for kern_securelevels
+ #
+ local mark=" "
case "$( f_sysrc_get kern_securelevel_enable )" in
[Yy][Ee][Ss])
local kern_securelevel="$( f_sysrc_get kern_securelevel )"
if [ ${#kern_securelevel} -eq 1 ] &&
- f_isinteger "$kern_securelevel"
- then menu_list="$menu_list
- '2 [$kern_securelevel] $msg_securelevel'"
- else menu_list="$menu_list
- '2 [X] $msg_securelevel'"
- fi
- menu_list="$menu_list '$msg_securelevel_desc'"
- ;;
- *) menu_list="$menu_list
- '2 [ ] $msg_securelevel' '$msg_securelevel_desc'"
+ f_isinteger "$kern_securelevel" &&
+ [ $kern_securelevel -lt 9 ]
+ then
+ mark="$kern_securelevel"
+ else
+ mark="X"
+ fi ;;
+ *)
+ mark=" "
esac
+ menu_list="$menu_list
+ '2 [$mark] $msg_securelevel' '$msg_securelevel_desc'"
+
+ # Update default-item if appropriate
+ [ "$ditem" = 2 ] && defaultitem="2 [$mark] $msg_securelevel"
+ #
+ # Add dynamically tagged entry for nfs_reserved_port_only
+ #
case "$( f_sysrc_get nfs_reserved_port_only )" in
- [Yy][Ee][Ss]) menu_list="$menu_list
- '3 [X] $msg_nfs_port' '$msg_nfs_port_desc'";;
- *) menu_list="$menu_list
- '3 [ ] $msg_nfs_port' '$msg_nfs_port_desc'";;
+ [Yy][Ee][Ss]) mark="X" ;;
+ *) mark=" " ;;
esac
-
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ menu_list="$menu_list
+ '3 [$mark] $msg_nfs_port' '$msg_nfs_port_desc'"
+
+ # Update default-item if appropriate
+ [ "$ditem" = 3 ] && defaultitem="3 [$mark] $msg_nfs_port"
+
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+
+ # Only update default-item on success
+ [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice"
+
return $retval
}
@@ -111,9 +136,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -126,25 +151,23 @@ f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
f_mustberoot_init
#
-# Launch application main menu
+# Launch application main menu (loop for menu update after selection)
#
while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
+ dialog_menu_main || f_die
+ f_dialog_menutag_fetch mtag
case "$mtag" in
- "X <<< $msg_exit") break ;;
+ "X $msg_exit") break ;;
"2 ["?"] $msg_securelevel") # Configure securelevels for the system
$BSDCFG_LIBE/$APP_DIR/kern_securelevel ${USE_XDIALOG:+-X} ;;
"3 [X] $msg_nfs_port") # Require that NFS clients use reserved ports
- f_sysrc_set nfs_reserved_port_only "NO";;
+ f_sysrc_set nfs_reserved_port_only "NO" ;;
"3 [ ] $msg_nfs_port") # Same; Toggle value
- f_sysrc_set nfs_reserved_port_only "YES";;
+ f_sysrc_set nfs_reserved_port_only "YES" ;;
+ *)
+ f_die 1 "$msg_unknown_security_menu_selection"
esac
-
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/share/Makefile b/usr.sbin/bsdconfig/share/Makefile
index 4c20c2b..3392e2a 100644
--- a/usr.sbin/bsdconfig/share/Makefile
+++ b/usr.sbin/bsdconfig/share/Makefile
@@ -2,7 +2,7 @@
NO_OBJ=
-SUBDIR= media
+SUBDIR= media packages
FILESDIR= ${SHAREDIR}/bsdconfig
FILES= common.subr device.subr dialog.subr mustberoot.subr \
diff --git a/usr.sbin/bsdconfig/share/common.subr b/usr.sbin/bsdconfig/share/common.subr
index cb9096f..985bf6b 100644
--- a/usr.sbin/bsdconfig/share/common.subr
+++ b/usr.sbin/bsdconfig/share/common.subr
@@ -62,6 +62,48 @@ export UNAME_S="$(uname -s)" # Operating System (i.e. FreeBSD)
export UNAME_P="$(uname -p)" # Processor Architecture (i.e. i386)
export UNAME_R="$(uname -r)" # Release Level (i.e. X.Y-RELEASE)
+#
+# Default behavior is to call f_debug_init() automatically when loaded.
+#
+: ${DEBUG_SELF_INITIALIZE=1}
+
+#
+# Define standard optstring arguments that should be supported by all programs
+# using this include (unless DEBUG_SELF_INITIALIZE is set to NULL to prevent
+# f_debug_init() from autamatically processing "$@" for the below arguments):
+#
+# d Sets $debug to 1
+# D: Sets $debugFile to $OPTARG
+#
+GETOPTS_STDARGS="dD:"
+
+#
+# The getopts builtin will return 1 either when the end of "$@" or the first
+# invalid flag is reached. This makes it impossible to determine if you've
+# processed all the arguments or simply have hit an invalid flag. In the cases
+# where we want to tolerate invalid flags (f_debug_init() for example), the
+# following variable can be appended to your optstring argument to getopts,
+# preventing it from prematurely returning 1 before the end of the arguments.
+#
+# NOTE: This assumes that all unknown flags are argument-less.
+#
+GETOPTS_ALLFLAGS="abcdefghijklmnopqrstuvwxyz"
+GETOPTS_ALLFLAGS="${GETOPTS_ALLFLAGS}ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+GETOPTS_ALLFLAGS="${GETOPTS_ALLFLAGS}0123456789"
+
+#
+# When we get included, f_debug_init() will fire (unless $DEBUG_SELF_INITIALIZE
+# is set to disable automatic initialization) and process "$@" for a few global
+# options such as `-d' and/or `-D file'. However, if your program takes custom
+# flags that take arguments, this automatic processing may fail unexpectedly.
+#
+# The solution to this problem is to pre-define (before including this file)
+# the following variable (which defaults to NULL) to indicate that there are
+# extra flags that should be considered when performing automatic processing of
+# globally persistent flags.
+#
+: ${GETOPTS_EXTRA:=}
+
############################################################ FUNCTIONS
# f_dprintf $fmt [ $opts ... ]
@@ -86,6 +128,62 @@ f_dprintf()
return $SUCCESS
}
+# f_debug_init
+#
+# Initialize debugging. Truncates $debugFile to zero bytes if set.
+#
+f_debug_init()
+{
+ #
+ # Process stored command-line arguments
+ #
+ set -- $ARGV
+ local OPTIND
+ f_dprintf "f_debug_init: ARGV=[%s] GETOPTS_STDARGS=[%s]" \
+ "$ARGV" "$GETOPTS_STDARGS"
+ while getopts "$GETOPTS_STDARGS$GETOPTS_EXTRA$GETOPTS_ALLFLAGS" flag \
+ > /dev/null; do
+ case "$flag" in
+ d) debug=1 ;;
+ D) debugFile="$OPTARG" ;;
+ esac
+ done
+ shift $(( $OPTIND - 1 ))
+ f_dprintf "f_debug_init: debug=[%s] debugFile=[%s]" \
+ "$debug" "$debugFile"
+
+ #
+ # Automagically enable debugging if debugFile is set (and non-NULL)
+ #
+ [ "$debugFile" ] && { [ "${debug+set}" ] || debug=1; }
+
+ #
+ # Make debugging persistant if set
+ #
+ [ "$debug" ] && export debug
+ [ "$debugFile" ] && export debugFile
+
+ #
+ # Truncate the debug file upon. Note that we will trim a leading plus
+ # (`+') from the value of debugFile to support persistant meaning that
+ # f_dprintf() should print both to standard output and $debugFile
+ # (minus the leading plus, of course).
+ #
+ local _debug_file="${debugFile#+}"
+ if [ "$_debug_file" ]; then
+ if ( umask 022 && :> "$_debug_file" ); then
+ f_dprintf "Successfully initialized debugFile \`%s'" \
+ "$_debug_file"
+ [ "${debug+set}" ] ||
+ debug=1 # turn debugging on if not set
+ else
+ unset debugFile
+ f_dprintf "Unable to initialize debugFile \`%s'" \
+ "$_debug_file"
+ fi
+ fi
+}
+
# f_err $fmt [ $opts ... ]
#
# Print a message to stderr (fd=2).
@@ -114,6 +212,35 @@ f_have()
f_quietly type "$@"
}
+# f_which $anything [$var_to_set]
+#
+# A fast built-in replacement for syntaxes such as foo=$( which bar ). In a
+# comparison of 10,000 runs of this function versus which, this function
+# completed in under 3 seconds, while `which' took almost a full minute.
+#
+# If $var_to_set is missing or NULL, output is (like which) to standard out.
+# Returns success if a match was found, failure otherwise.
+#
+f_which()
+{
+ local __name="$1" __var_to_set="$2"
+ case "$__name" in */*|'') return $FAILURE; esac
+ local __p IFS=":" __found=
+ for __p in $PATH; do
+ local __exec="$__p/$__name"
+ [ -f "$__exec" -a -x "$__exec" ] && __found=1 && break
+ done
+ if [ "$__found" ]; then
+ if [ "$__var_to_set" ]; then
+ setvar "$__var_to_set" "$__exec"
+ else
+ echo "$__exec"
+ fi
+ return $SUCCESS
+ fi
+ return $FAILURE
+}
+
# f_getvar $var_to_get [$var_to_set]
#
# Utility function designed to go along with the already-builtin setvar.
@@ -138,6 +265,16 @@ f_getvar()
return $__retval
}
+# f_isset $var
+#
+# Check if variable $var is set. Returns success if variable is set, otherwise
+# returns failure.
+#
+f_isset()
+{
+ eval [ \"\${${1%%[$IFS]*}+set}\" ]
+}
+
# f_die [ $status [ $fmt [ $opts ... ]]]
#
# Abruptly terminate due to an error optionally displaying a message in a
@@ -423,12 +560,22 @@ f_index_file()
if [ "$lang" ]; then
awk -v keyword="$keyword" "$f_index_file_awk" \
- $BSDCFG_LIBE${BSDCFG_LIBE:+/}*/INDEX.$lang &&
- return
+ $BSDCFG_LIBE${BSDCFG_LIBE:+/}*/INDEX.$lang && return
+ # No match, fall-thru to non-i18n sources
+ fi
+ awk -v keyword="$keyword" "$f_index_file_awk" \
+ $BSDCFG_LIBE${BSDCFG_LIBE:+/}*/INDEX && return
+
+ # No match? Fall-thru to `local' libexec sources (add-on modules)
+
+ [ "$BSDCFG_LOCAL_LIBE" ] || return $FAILURE
+ if [ "$lang" ]; then
+ awk -v keyword="$keyword" "$f_index_file_awk" \
+ $BSDCFG_LOCAL_LIBE/*/INDEX.$lang && return
# No match, fall-thru to non-i18n sources
fi
awk -v keyword="$keyword" "$f_index_file_awk" \
- $BSDCFG_LIBE${BSDCFG_LIBE:+/}*/INDEX
+ $BSDCFG_LOCAL_LIBE/*/INDEX
}
# f_index_menusel_keyword $indexfile $pgm
@@ -615,28 +762,14 @@ eval exec $TERMINAL_STDOUT_PASSTHRU\>\&1
eval exec $TERMINAL_STDERR_PASSTHRU\>\&2
#
-# Make debugging persistant if set
-#
-[ "$debug" ] && export debug
-
+# Self-initialize unless requested otherwise
#
-# Truncate the debug file upon initialization (now). Note that we will trim a
-# leading plus (`+') from the value of debugFile to support persistant meaning
-# that f_dprintf() should print both to standard output and $debugFile (minus
-# the leading plus, of course).
-#
-_debug_file="${debugFile#+}"
-if [ "$_debug_file" ]; then
- if ( umask 022 && :> "$_debug_file" ); then
- f_dprintf "Successfully initialized debugFile \`%s'" \
- "$_debug_file"
- else
- unset debugFile
- f_dprintf "Unable to initialize debugFile \`%s'" \
- "$_debug_file"
- fi
-fi
-unset _debug_file
+f_dprintf "%s: DEBUG_SELF_INITIALIZE=[%s]" \
+ dialog.subr "$DEBUG_SELF_INITIALIZE"
+case "$DEBUG_SELF_INITIALIZE" in
+""|0|[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee]) : do nothing ;;
+*) f_debug_init
+esac
#
# Log our operating environment for debugging purposes
diff --git a/usr.sbin/bsdconfig/share/device.subr b/usr.sbin/bsdconfig/share/device.subr
index 07b3f87..bbd3a10 100644
--- a/usr.sbin/bsdconfig/share/device.subr
+++ b/usr.sbin/bsdconfig/share/device.subr
@@ -1,7 +1,7 @@
if [ ! "$_DEVICE_SUBR" ]; then _DEVICE_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_DEVICE_SUBR" ]; then _DEVICE_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -73,6 +73,7 @@ setvar DEVICE_TYPE_UFS 9
setvar DEVICE_TYPE_NFS 10
setvar DEVICE_TYPE_ANY 11
setvar DEVICE_TYPE_HTTP_PROXY 12
+setvar DEVICE_TYPE_HTTP 13
#
# Default behavior is to call f_device_get_all() automatically when loaded.
@@ -393,9 +394,9 @@ f_device_name_get()
# f_device_name_set $type $name $desc [$max]
#
# Store a description (desc) and [optionally] maximum number of devices to scan
-# for (max) in-association with device $type and $name. Returns success. Use
-# the f_device_name_get() routine with the same $name and [optionally] $type to
-# retrieve one of type, desc, or max properties.
+# for (max) in-association with device $type and $name. Returns success unless
+# $name is NULL or missing. Use the f_device_name_get() routine with the same
+# $name and optionally $type to retrieve one of type, desc, or max properties.
#
f_device_name_set()
{
@@ -485,11 +486,11 @@ f_device_desc()
# Sensible fall-backs for specific types
#
case "$__type" in
- $DEVICE_TYPE_CDROM) __cp="<unknown cdrom device type>";;
- $DEVICE_TYPE_DISK) __cp="<unknown disk device type>";;
- $DEVICE_TYPE_FLOPPY) __cp="<unknown floppy device type>";;
- $DEVICE_TYPE_USB) __cp="<unknown usb storage device type>";;
- $DEVICE_TYPE_NETWORK) __cp="<unknown network interface type>";;
+ $DEVICE_TYPE_CDROM) __cp="<unknown cdrom device type>" ;;
+ $DEVICE_TYPE_DISK) __cp="<unknown disk device type>" ;;
+ $DEVICE_TYPE_FLOPPY) __cp="<unknown floppy device type>" ;;
+ $DEVICE_TYPE_USB) __cp="<unknown usb storage device type>" ;;
+ $DEVICE_TYPE_NETWORK) __cp="<unknown network interface type>" ;;
*)
__cp="<unknown device type>"
esac
@@ -598,27 +599,26 @@ f_device_menu()
done
[ "$devs" ] || return $FAILURE
- local sanitize_awk="{ gsub(/'/, \"'\\\\''\"); print }"
-
local desc menu_list=
for dev in $devs; do
device_$dev get desc desc
- desc=$( echo "$desc" | awk "$sanitize_awk" )
+ f_shell_escape "$desc" desc
menu_list="$menu_list '$dev' '$desc'"
done
- local size mtag
- size=$( eval f_dialog_menu_size \
- \"\$title\" \
- \"\$btitle\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$title\" \
+ \"\$btitle\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
local errexit=
case $- in *e*) errexit=1; esac
set +e
+ local mtag
while :; do
mtag=$( eval $DIALOG \
--title \"\$title\" \
@@ -630,7 +630,8 @@ f_device_menu()
--help-label \"\$msg_help\" \
${USE_XDIALOG:+--help \"\"} \
} \
- --menu \"\$prompt\" $size \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
@@ -639,13 +640,17 @@ f_device_menu()
[ $retval -ne 2 ] && break
# Otherwise, the Help button was pressed
f_show_help "$helpfile"
- # Loop back to menu
+ # ...then loop back to menu
done
f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
[ "$errexit" ] && set -e
- [ $retval -eq 0 ] && echo "$mtag" >&2
+ if [ $retval -eq 0 ]; then
+ # Clean up the output of [X]dialog(1) and return it
+ f_dialog_data_sanitize mtag
+ echo "$mtag" >&2
+ fi
return $retval
}
diff --git a/usr.sbin/bsdconfig/share/dialog.subr b/usr.sbin/bsdconfig/share/dialog.subr
index 78286267..bde3753 100644
--- a/usr.sbin/bsdconfig/share/dialog.subr
+++ b/usr.sbin/bsdconfig/share/dialog.subr
@@ -1,7 +1,7 @@
if [ ! "$_DIALOG_SUBR" ]; then _DIALOG_SUBR=1
#
# Copyright (c) 2006-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_DIALOG_SUBR" ]; then _DIALOG_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -83,8 +83,111 @@ unset XDIALOG_INFOBOX_TIMEOUT
#
: ${DEFAULT_TERMINAL_SIZE:=24 80}
+#
+# Minimum width(s) for various dialog(1) implementations (sensible global
+# default(s) for all widgets of a given variant)
+#
+: ${DIALOG_MIN_WIDTH:=24}
+: ${XDIALOG_MIN_WIDTH:=35}
+
+#
+# When manually sizing Xdialog(1) widgets such as calendar and timebox, you'll
+# need to know the size of the embedded GUI objects because the height passed
+# to Xdialog(1) for these widgets has to be tall enough to accomodate them.
+#
+# These values are helpful when manually sizing with dialog(1) too, but in a
+# different way. dialog(1) does not make you accomodate the custom items in the
+# height (but does for width) -- a height of 3 will display three lines and a
+# full calendar, for example (whereas Xdialog will truncate the calendar if
+# given a height of 3). For dialog(1), use these values for making sure that
+# the height does not exceed max_height (obtained by f_dialog_max_size()).
+#
+DIALOG_CALENDAR_HEIGHT=15
+DIALOG_TIMEBOX_HEIGHT=6
+
############################################################ GENERIC FUNCTIONS
+# f_dialog_data_sanitize $var_to_edit ...
+#
+# When using dialog(1) or Xdialog(1) sometimes unintended warnings or errors
+# are generated from underlying libraries. For example, if $LANG is set to an
+# invalid or unknown locale, the warnings from the Xdialog(1) libraries will
+# clutter the output. This function helps by providing a centralied function
+# that removes spurious warnings from the dialog(1) (or Xdialog(1)) response.
+#
+# Simply pass the name of one or more variables that need to be sanitized.
+# After execution, the variables will hold their newly-sanitized data.
+#
+f_dialog_data_sanitize()
+{
+ if [ "$#" -eq 0 ]; then
+ f_dprintf "%s: called with zero arguments" \
+ f_dialog_response_sanitize
+ return $FAILURE
+ fi
+
+ local __var_to_edit
+ for __var_to_edit in $*; do
+ # Skip warnings and trim leading/trailing whitespace
+ setvar $__var_to_edit "$( f_getvar $__var_to_edit | awk '
+ BEGIN { data = 0 }
+ {
+ if ( ! data )
+ {
+ if ( $0 ~ /^$/ ) next
+ if ( $0 ~ /^Gdk-WARNING \*\*:/ ) next
+ data = 1
+ }
+ print
+ }
+ ' )"
+ done
+}
+
+# f_dialog_line_sanitize $var_to_edit ...
+#
+# When using dialog(1) or Xdialog(1) sometimes unintended warnings or errors
+# are generated from underlying libraries. For example, if $LANG is set to an
+# invalid or unknown locale, the warnings from the Xdialog(1) libraries will
+# clutter the output. This function helps by providing a centralied function
+# that removes spurious warnings from the dialog(1) (or Xdialog(1)) response.
+#
+# Simply pass the name of one or more variables that need to be sanitized.
+# After execution, the variables will hold their newly-sanitized data.
+#
+# This function, unlike f_dialog_data_sanitize(), also removes leading/trailing
+# whitespace from each line.
+#
+f_dialog_line_sanitize()
+{
+ if [ "$#" -eq 0 ]; then
+ f_dprintf "%s: called with zero arguments" \
+ f_dialog_response_sanitize
+ return $FAILURE
+ fi
+
+ local __var_to_edit
+ for __var_to_edit in $*; do
+ # Skip warnings and trim leading/trailing whitespace
+ setvar $__var_to_edit "$( f_getvar $__var_to_edit | awk '
+ BEGIN { data = 0 }
+ {
+ if ( ! data )
+ {
+ if ( $0 ~ /^$/ ) next
+ if ( $0 ~ /^Gdk-WARNING \*\*:/ ) next
+ data = 1
+ }
+ sub(/^[[:space:]]*/, "")
+ sub(/[[:space:]]*$/, "")
+ print
+ }
+ ' )"
+ done
+}
+
+############################################################ TITLE FUNCTIONS
+
# f_dialog_title [$new_title]
#
# Set the title of future dialog(1) ($DIALOG_TITLE) or backtitle of Xdialog(1)
@@ -92,8 +195,8 @@ unset XDIALOG_INFOBOX_TIMEOUT
# argument is NULL, the current title is returned.
#
# Each time this function is called, a backup of the current values is made
-# allowing a one-time (single-level) restoration of the previous title using the
-# f_dialog_title_restore() function (below).
+# allowing a one-time (single-level) restoration of the previous title using
+# the f_dialog_title_restore() function (below).
#
f_dialog_title()
{
@@ -174,753 +277,1200 @@ f_dialog_backtitle_restore()
############################################################ SIZE FUNCTIONS
-# f_dialog_infobox_size $title $backtitle $prompt [$hline]
-#
-# Not all versions of dialog(1) perform auto-sizing of the width and height of
-# `--infobox' boxes sensibly.
+# f_dialog_max_size $var_height $var_width
#
-# This function helps solve this issue by taking as arguments (in order of
-# appearance) the title, backtitle, prompt, and [optionally] hline returning
-# the optimal width and height for the box (not exceeding the actual terminal
-# width or height).
+# Get the maximum height and width for a dialog widget and store the values in
+# $var_height and $var_width (respectively).
#
-# Newline character sequences (``\n'') in $prompt are expanded as-is done by
-# dialog(1).
-#
-# Output is in the format of "height width".
-#
-f_dialog_infobox_size()
+f_dialog_max_size()
{
- local title="$1" btitle="$2" prompt="$3" hline="$4" n=0
- local min_width max_size
-
+ local __var_height="$1" __var_width="$2" __max_size
+ [ "$__var_height" -o "$__var_width" ] || return $FAILURE
if [ "$USE_XDIALOG" ]; then
- min_width=35
- max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
+ __max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
else
- min_width=24
- max_size=$( stty size 2> /dev/null ) # usually "24 80"
- : ${max_size:=$DEFAULT_TERMINAL_SIZE}
+ __max_size=$( stty size 2> /dev/null ) # usually "24 80"
+ : ${__max_size:=$DEFAULT_TERMINAL_SIZE}
fi
+ if [ "$__var_height" ]; then
+ local __height="${__max_size%%[$IFS]*}"
+ #
+ # If we're not using Xdialog(1), we should assume that $DIALOG
+ # will render --backtitle behind the widget. In such a case, we
+ # should prevent a widget from obscuring the backtitle (unless
+ # $NO_BACKTITLE is set and non-NULL, allowing a trap-door).
+ #
+ if [ ! "$USE_XDIALOG" ] && [ ! "$NO_BACKTITLE" ]; then
+ #
+ # If use_shadow (in ~/.dialogrc) is OFF, we need to
+ # subtract 4, otherwise 5. However, don't check this
+ # every time, rely on an initialization variable set
+ # by f_dialog_init().
+ #
+ local __adjust=5
+ [ "$NO_SHADOW" ] && __adjust=4
+
+ # Don't adjust height if already too small (allowing
+ # obscured backtitle for small values of __height).
+ [ ${__height:-0} -gt 11 ] &&
+ __height=$(( $__height - $__adjust ))
+ fi
+ setvar "$__var_height" "$__height"
+ fi
+ [ "$__var_width" ] && setvar "$__var_width" "${__max_size##*[$IFS]}"
+}
- local max_height="${max_size%%[$IFS]*}"
- local max_width="${max_size##*[$IFS]}"
- local height width=$min_width
+# f_dialog_size_constrain $var_height $var_width [$min_height [$min_width]]
+#
+# Modify $var_height to be no-less-than $min_height (if given; zero otherwise)
+# and no-greater-than terminal height (or screen height if $USE_XDIALOG is
+# set).
+#
+# Also modify $var_width to be no-less-than $XDIALOG_MIN_WIDTH (or
+# $XDIALOG_MIN_WIDTH if $_USE_XDIALOG is set) and no-greater-than terminal
+# or screen width. The use of $[X]DIALOG_MIN_WIDTH can be overridden by
+# passing $min_width.
+#
+# Return status is success unless one of the passed arguments is invalid
+# or all of the $var_* arguments are either NULL or missing.
+#
+f_dialog_size_constrain()
+{
+ local __var_height="$1" __var_width="$2"
+ local __min_height="$3" __min_width="$4"
+ local __retval=$SUCCESS
+
+ # Return failure unless at least one var_* argument is passed
+ [ "$__var_height" -o "$__var_width" ] || return $FAILURE
+
+ #
+ # Print debug warnings if any given (non-NULL) argument are invalid
+ # NOTE: Don't change the name of $__{var,min,}{height,width}
+ #
+ local __height __width
+ local __arg __cp __fname=f_dialog_size_constrain
+ for __arg in height width; do
+ debug= f_getvar __var_$__arg __cp
+ [ "$__cp" ] || continue
+ if ! debug= f_getvar "$__cp" __$__arg; then
+ f_dprintf "%s: var_%s variable \`%s' not set" \
+ $__fname $__arg "$__cp"
+ __retval=$FAILURE
+ elif ! eval f_isinteger \$__$__arg; then
+ f_dprintf "%s: var_%s variable value not a number" \
+ $__fname $__arg
+ __retval=$FAILURE
+ fi
+ done
+ for __arg in height width; do
+ debug= f_getvar __min_$__arg __cp
+ [ "$__cp" ] || continue
+ f_isinteger "$__cp" && continue
+ f_dprintf "%s: min_%s value not a number" $__fname $__arg
+ __retval=$FAILURE
+ setvar __min_$__arg ""
+ done
- #
- # Bump width for long titles (but don't exceed terminal width).
- #
- n=$(( ${#title} + 4 ))
- if [ $n -gt $width -a $n -gt $min_width ]; then
- # Add 16.6% width for Xdialog(1)
- [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 ))
+ # Obtain maximum height and width values
+ # NOTE: Function name appended to prevent __var_{height,width} values
+ # from becoming local (and thus preventing setvar from working).
+ local __max_height_size_constain __max_width_size_constrain
+ f_dialog_max_size \
+ __max_height_size_constrain __max_width_size_constrain
+
+ # Adjust height if desired
+ if [ "$__var_height" ]; then
+ if [ $__height -lt ${__min_height:-0} ]; then
+ setvar "$__var_height" $__min_height
+ elif [ $__height -gt $__max_height_size_constrain ]; then
+ setvar "$__var_height" $__max_height_size_constrain
+ fi
+ fi
- if [ $n -lt $max_width ]; then
- width=$n
+ # Adjust width if desired
+ if [ "$__var_width" ]; then
+ if [ "$USE_XDIALOG" ]; then
+ : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}}
else
- width=$max_width
+ : ${__min_width:=${DIALOG_MIN_WIDTH:-24}}
+ fi
+ if [ $__width -lt $__min_width ]; then
+ setvar "$__var_width" $__min_width
+ elif [ $__width -gt $__max_width_size_constrain ]; then
+ setvar "$__var_width" $__max_width_size_constrain
fi
fi
- #
- # For Xdialog(1), bump width for long backtitles (which appear within
- # the window; don't exceed maximum width).
- #
- if [ "$USE_XDIALOG" ]; then
- n=$(( ${#btitle} + 4 ))
- n=$(( $n + $n / 6 ))
- if [ $n -gt $width -a $n -gt $min_width ]; then
- if [ $n -lt $max_width ]; then
- width=$n
- else
- width=$max_width
- fi
- fi
+ if [ "$debug" ]; then
+ # Print final constrained values to debugging
+ f_quietly f_getvar "$__var_height"
+ f_quietly f_getvar "$__var_width"
fi
- #
- # Bump width for long prompts (if not already at maximum width).
- #
- if [ $width -lt $max_width ]; then
- n=$( echo "$prompt" | f_longest_line_length )
- n=$(( $n + 4 ))
-
- # Add 16.6% width for Xdialog(1)
- [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 ))
-
- if [ $n -gt $width -a $n -gt $min_width ]; then
- if [ $n -lt $max_width ]; then
- width=$n
- else
- width=$max_width
- fi
+ return $__retval # success if no debug warnings were printed
+}
+
+# f_dialog_menu_constrain $var_height $var_width $var_rows "$prompt" \
+# [$min_height [$min_width [$min_rows]]]
+#
+# Modify $var_height to be no-less-than $min_height (if given; zero otherwise)
+# and no-greater-than terminal height (or screen height if $USE_XDIALOG is
+# set).
+#
+# Also modify $var_width to be no-less-than $XDIALOG_MIN_WIDTH (or
+# $XDIALOG_MIN_WIDTH if $_USE_XDIALOG is set) and no-greater-than terminal
+# or screen width. The use of $[X]DIALOG_MIN_WIDTH can be overridden by
+# passing $min_width.
+#
+# Last, modify $var_rows to be no-less-than $min_rows (if specified; zero
+# otherwise) and no-greater-than (max_height - 8) where max_height is the
+# terminal height (or screen height if $USE_XDIALOG is set). If $prompt is NULL
+# or missing, dialog(1) allows $var_rows to be (max_height - 7), maximizing the
+# number of visible rows.
+#
+# Return status is success unless one of the passed arguments is invalid
+# or all of the $var_* arguments are either NULL or missing.
+#
+f_dialog_menu_constrain()
+{
+ local __var_height="$1" __var_width="$2" __var_rows="$3" __prompt="$4"
+ local __min_height="$5" __min_width="$6" __min_rows="$7"
+
+ # Return failure unless at least one var_* argument is passed
+ [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] ||
+ return $FAILURE
+
+ #
+ # Print debug warnings if any given (non-NULL) argument are invalid
+ # NOTE: Don't change the name of $__{var,min,}{height,width,rows}
+ #
+ local __height __width __rows
+ local __arg __cp __fname=f_dialog_menu_constrain
+ for __arg in height width rows; do
+ debug= f_getvar __var_$__arg __cp
+ [ "$__cp" ] || continue
+ if ! debug= f_getvar "$__cp" __$__arg; then
+ f_dprintf "%s: var_%s variable \`%s' not set" \
+ $__fname $__arg "$__cp"
+ __retval=$FAILURE
+ elif ! eval f_isinteger \$__$__arg; then
+ f_dprintf "%s: var_%s variable value not a number" \
+ $__fname $__arg
+ __retval=$FAILURE
+ fi
+ done
+ for __arg in height width rows; do
+ debug= f_getvar __min_$__arg __cp
+ [ "$__cp" ] || continue
+ f_isinteger "$__cp" && continue
+ f_dprintf "%s: min_%s value not a number" $__fname $__arg
+ __retval=$FAILURE
+ setvar __min_$__arg ""
+ done
+
+ # Obtain maximum height and width values
+ # NOTE: Function name appended to prevent __var_{height,width} values
+ # from becoming local (and thus preventing setvar from working).
+ local __max_height_menu_constrain __max_width_menu_constrain
+ f_dialog_max_size \
+ __max_height_menu_constrain __max_width_menu_constrain
+
+ # Adjust height if desired
+ if [ "$__var_height" ]; then
+ if [ $__height -lt ${__min_height:-0} ]; then
+ setvar "$__var_height" $__min_height
+ elif [ $__height -gt $__max_height_menu_constrain ]; then
+ setvar "$__var_height" $__max_height_menu_constrain
fi
fi
- #
- # Bump width for long hlines (if not already at maximum width).
- # NOTE: Though Xdialog(1) supports `--hline', it's not currently used.
- #
- if [ ! "$USE_XDIALOG" ]; then
- if [ $width -lt $max_width ]; then
- n=$(( ${#hline} + 10 ))
- if [ $n -gt $width -a $n -gt $min_width ]; then
- if [ $n -lt $max_width ]; then
- width=$n
- else
- width=$max_width
- fi
- fi
+ # Adjust width if desired
+ if [ "$__var_width" ]; then
+ if [ "$USE_XDIALOG" ]; then
+ : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}}
+ else
+ : ${__min_width:=${DIALOG_MIN_WIDTH:-24}}
+ fi
+ if [ $__width -lt $__min_width ]; then
+ setvar "$__var_width" $__min_width
+ elif [ $__width -gt $__max_width_menu_constrain ]; then
+ setvar "$__var_width" $__max_width_menu_constrain
fi
fi
- #
- # Set height based on number of rows in prompt
- #
- height=$( echo -n "$prompt" | f_number_of_lines )
- height=$(( $height + 2 ))
+ # Adjust rows if desired
+ if [ "$__var_rows" ]; then
+ if [ "$USE_XDIALOG" ]; then
+ : ${__min_rows:=1}
+ else
+ : ${__min_rows:=0}
+ fi
- #
- # For Xdialog(1) bump height if backtitle is enabled (displayed in the
- # X11 window with a separator line between the backtitle and msg text)
- #
- if [ "$USE_XDIALOG" -a "$btitle" ]; then
- n=$( echo "$btitle" | f_number_of_lines )
- height=$(( $height + $n + 2 ))
+ local __max_rows=$(( $__max_height_menu_constrain - 8 ))
+ # If prompt_len is zero (no prompt), bump the max-rows by 1
+ # Default assumption is (if no argument) that there's no prompt
+ [ ${__prompt_len:-0} -gt 0 ] ||
+ __max_rows=$(( $__max_rows + 1 ))
+
+ if [ $__rows -lt $__min_rows ]; then
+ setvar "$__var_rows" $__min_rows
+ elif [ $__rows -gt $__max_rows ]; then
+ setvar "$__var_rows" $__max_rows
+ fi
fi
- # Make sure height is less than maximum screen size
- [ $height -le $max_height ] || height=$max_height
+ if [ "$debug" ]; then
+ # Print final constrained values to debuggin
+ f_quietly f_getvar "$__var_height"
+ f_quietly f_getvar "$__var_width"
+ f_quietly f_getvar "$__var_rows"
+ fi
- # Return both
- echo "$height $width"
+ return $__retval # success if no debug warnings were printed
}
-# f_dialog_buttonbox_size $title $backtitle $prompt [$hline]
+# f_dialog_infobox_size [-n] $var_height $var_width \
+# $title $backtitle $prompt [$hline]
#
# Not all versions of dialog(1) perform auto-sizing of the width and height of
-# `--msgbox' and `--yesno' boxes sensibly.
+# `--infobox' boxes sensibly.
+#
+# This function helps solve this issue by taking two sets of sequential
+# arguments. The first set of arguments are the variable names to use when
+# storing the calculated height and width. The second set of arguments are the
+# title, backtitle, prompt, and [optionally] hline. The optimal height and
+# width for the described widget (not exceeding the actual terminal height or
+# width) is stored in $var_height and $var_width (respectively).
#
-# This function helps solve this issue by taking as arguments (in order of
-# appearance) the title, backtitle, prompt, and [optionally] hline returning
-# the optimal width and height for the box (not exceeding the actual terminal
-# width or height).
+# If the first argument is `-n', the calculated sizes ($var_height and
+# $var_width) are not constrained to minimum/maximum values.
#
# Newline character sequences (``\n'') in $prompt are expanded as-is done by
# dialog(1).
#
-# Output is in the format of "height width".
-#
-f_dialog_buttonbox_size()
+f_dialog_infobox_size()
{
- local title="$1" btitle="$2" prompt="$3" hline="$4"
- local size="$( f_dialog_infobox_size \
- "$title" "$btitle" "$prompt" "$hline" )"
- local height="${size%%[$IFS]*}"
- local width="${size##*[$IFS]}"
+ local __constrain=1
+ [ "$1" = "-n" ] && __constrain= && shift 1 # -n
+ local __var_height="$1" __var_width="$2"
+ local __title="$3" __btitle="$4" __prompt="$5" __hline="$6"
+
+ # Return unless at least one size aspect has been requested
+ [ "$__var_height" -o "$__var_width" ] || return $FAILURE
+
+ # Default height/width of zero for auto-sizing
+ local __height=0 __width=0 __n
+
+ # Adjust height if desired
+ if [ "$__var_height" ]; then
+ #
+ # Set height based on number of rows in prompt
+ #
+ __n=$( echo -n "$__prompt" | f_number_of_lines )
+ __n=$(( $__n + 2 ))
+ [ $__n -gt $__height ] && __height=$__n
+
+ #
+ # For Xdialog(1) bump height if backtitle is enabled (displayed
+ # in the X11 window with a separator line between the backtitle
+ # and msg text).
+ #
+ if [ "$USE_XDIALOG" -a "$__btitle" ]; then
+ __n=$( echo "$__btitle" | f_number_of_lines )
+ __height=$(( $__height + $__n + 2 ))
+ fi
- # Add height to accomodate the buttons
- height=$(( $height + 2 ))
+ setvar "$__var_height" $__height
+ fi
- # Adjust for clipping with Xdialog(1) on Linux/GTK2
- [ "$USE_XDIALOG" ] && height=$(( $height + 3 ))
+ # Adjust width if desired
+ if [ "$__var_width" ]; then
+ #
+ # Bump width for long titles
+ #
+ __n=$(( ${#__title} + 4 ))
+ [ $__n -gt $__width ] && __width=$__n
+
+ #
+ # If using Xdialog(1), bump width for long backtitles (which
+ # appear within the window).
+ #
+ if [ "$USE_XDIALOG" ]; then
+ __n=$(( ${#__btitle} + 4 ))
+ [ $__n -gt $__width ] && __width=$__n
+ fi
- #
- # Enforce maximum height regardless
- #
- local max_size
- if [ "$USE_XDIALOG" ]; then
- max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
- else
- max_size=$( stty size 2> /dev/null ) # usually "24 80"
- : ${max_size:=$DEFAULT_TERMINAL_SIZE}
+ #
+ # Bump width for long prompts
+ #
+ __n=$( echo "$__prompt" | f_longest_line_length )
+ __n=$(( $__n + 4 )) # add width for border
+ [ $__n -gt $__width ] && __width=$__n
+
+ #
+ # Bump width for long hlines. Xdialog(1) supports `--hline' but
+ # it's currently not used (so don't do anything here if using
+ # Xdialog(1)).
+ #
+ if [ ! "$USE_XDIALOG" ]; then
+ __n=$(( ${#__hline} + 10 ))
+ [ $__n -gt $__width ] && __width=$__n
+ fi
+
+ # Bump width by 16.6% if using Xdialog(1)
+ [ "$USE_XDIALOG" ] && __width=$(( $__width + $__width / 6 ))
+
+ setvar "$__var_width" $__width
fi
- local max_height="${max_size%%[$IFS]*}"
- [ $height -le $max_height ] || height=$max_height
- # Return both
- echo "$height $width"
+ # Constrain values to sensible minimums/maximums unless `-n' was passed
+ # Return success if no-constrain, else return status from constrain
+ [ ! "$__constrain" ] ||
+ f_dialog_size_constrain "$__var_height" "$__var_width"
}
-# f_dialog_inputbox_size $title $backtitle $prompt $init [$hline]
+# f_dialog_buttonbox_size [-n] $var_height $var_width \
+# $title $backtitle $prompt [$hline]
#
# Not all versions of dialog(1) perform auto-sizing of the width and height of
-# `--inputbox' boxes sensibly.
+# `--msgbox' and `--yesno' boxes sensibly.
#
-# This function helps solve this issue by taking as arguments (in order of
-# appearance) the title, backtitle, prompt, initial text, and [optionally]
-# hline returning the optimal width and height for the box (not exceeding the
-# actual terminal width and height).
+# This function helps solve this issue by taking two sets of sequential
+# arguments. The first set of arguments are the variable names to use when
+# storing the calculated height and width. The second set of arguments are the
+# title, backtitle, prompt, and [optionally] hline. The optimal height and
+# width for the described widget (not exceeding the actual terminal height or
+# width) is stored in $var_height and $var_width (respectively).
+#
+# If the first argument is `-n', the calculated sizes ($var_height and
+# $var_width) are not constrained to minimum/maximum values.
#
# Newline character sequences (``\n'') in $prompt are expanded as-is done by
# dialog(1).
#
-# Output is in the format of "height width".
-#
-f_dialog_inputbox_size()
+f_dialog_buttonbox_size()
{
- local title="$1" btitle="$2" prompt="$3" init="$4" hline="$5" n
- local size="$( f_dialog_buttonbox_size \
- "$title" "$btitle" "$prompt" "$hline" )"
- local height="${size%%[$IFS]*}"
- local width="${size##*[$IFS]}"
+ local __constrain=1
+ [ "$1" = "-n" ] && __constrain= && shift 1 # -n
+ local __var_height="$1" __var_width="$2"
+ local __title="$3" __btitle="$4" __prompt="$5" __hline="$6"
+
+ # Return unless at least one size aspect has been requested
+ [ "$__var_height" -o "$__var_width" ] || return $FAILURE
+
+ # Calculate height/width of infobox (adjusted/constrained below)
+ # NOTE: Function name appended to prevent __var_{height,width} values
+ # from becoming local (and thus preventing setvar from working).
+ local __height_bbox_size __width_bbox_size
+ f_dialog_infobox_size -n \
+ "${__var_height:+__height_bbox_size}" \
+ "${__var_width:+__width_bbox_size}" \
+ "$__title" "$__btitle" "$__prompt" "$__hline"
+
+ # Adjust height if desired
+ if [ "$__var_height" ]; then
+ # Add height to accomodate the buttons
+ __height_bbox_size=$(( $__height_bbox_size + 2 ))
+
+ # Adjust for clipping with Xdialog(1) on Linux/GTK2
+ [ "$USE_XDIALOG" ] &&
+ __height_bbox_size=$(( $__height_bbox_size + 3 ))
+
+ setvar "$__var_height" $__height_bbox_size
+ fi
- local min_width max_size
- if [ "$USE_XDIALOG" ]; then
- min_width=35
- max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
- else
- min_width=24
- max_size=$( stty size 2> /dev/null ) # usually "24 80"
- : ${max_size:=$DEFAULT_TERMINAL_SIZE}
+ # No adjustemnts to width, just pass-thru the infobox width
+ if [ "$__var_width" ]; then
+ setvar "$__var_width" $__width_bbox_size
fi
- local max_height="${max_size%%[$IFS]*}"
- local max_width="${max_size##*[$IFS]}"
- #
- # Add height to accomodate the input box
- #
- [ ! "$USE_XDIALOG" ] && height=$(( $height + 3 ))
- [ $height -le $max_height ] || height=$max_height
+ # Constrain values to sensible minimums/maximums unless `-n' was passed
+ # Return success if no-constrain, else return status from constrain
+ [ ! "$__constrain" ] ||
+ f_dialog_size_constrain "$__var_height" "$__var_width"
+}
- #
- # Bump width for initial text (if not already at maximum width).
- # NOTE: Something neither dialog(1)/Xdialog(1) do, but worth it!
- #
- if [ $width -lt $max_width ]; then
- n=$(( ${#init} + 7 ))
+# f_dialog_inputbox_size [-n] $var_height $var_width \
+# $title $backtitle $prompt $init [$hline]
+#
+# Not all versions of dialog(1) perform auto-sizing of the width and height of
+# `--inputbox' boxes sensibly.
+#
+# This function helps solve this issue by taking two sets of sequential
+# arguments. The first set of arguments are the variable names to use when
+# storing the calculated height and width. The second set of arguments are the
+# title, backtitle, prompt, and [optionally] hline. The optimal height and
+# width for the described widget (not exceeding the actual terminal height or
+# width) is stored in $var_height and $var_width (respectively).
+#
+# If the first argument is `-n', the calculated sizes ($var_height and
+# $var_width) are not constrained to minimum/maximum values.
+#
+# Newline character sequences (``\n'') in $prompt are expanded as-is done by
+# dialog(1).
+#
+f_dialog_inputbox_size()
+{
+ local __constrain=1
+ [ "$1" = "-n" ] && __constrain= && shift 1 # -n
+ local __var_height="$1" __var_width="$2"
+ local __title="$3" __btitle="$4" __prompt="$5" __init="$6" __hline="$7"
+
+ # Return unless at least one size aspect has been requested
+ [ "$__var_height" -o "$__var_width" ] || return $FAILURE
+
+ # Calculate height/width of buttonbox (adjusted/constrained below)
+ # NOTE: Function name appended to prevent __var_{height,width} values
+ # from becoming local (and thus preventing setvar from working).
+ local __height_ibox_size __width_ibox_size
+ f_dialog_buttonbox_size -n \
+ "${__var_height:+__height_ibox_size}" \
+ "${__var_width:+__width_ibox_size}" \
+ "$__title" "$__btitle" "$__prompt" "$__hline"
+
+ # Adjust height if desired
+ if [ "$__var_height" ]; then
+ # Add height for input box (not needed for Xdialog(1))
+ [ ! "$USE_XDIALOG" ] &&
+ __height_ibox_size=$(( $__height_ibox_size + 3 ))
+
+ setvar "$__var_height" $__height_ibox_size
+ fi
- # Add 16.6% width for Xdialog(1)
- [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 ))
+ # Adjust width if desired
+ if [ "$__var_width" ]; then
+ # Bump width for initial text (something neither dialog(1) nor
+ # Xdialog(1) do, but worth it!; add 16.6% if using Xdialog(1))
+ local __n=$(( ${#__init} + 7 ))
+ [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 ))
+ [ $__n -gt $__width_ibox_size ] && __width_ibox_size=$__n
- if [ $n -gt $width -a $n -gt $min_width ]; then
- if [ $n -lt $max_width ]; then
- width=$n
- else
- width=$max_width
- fi
- fi
+ setvar "$__var_width" $__width_ibox_size
fi
- # Return both
- echo "$height $width"
+ # Constrain values to sensible minimums/maximums unless `-n' was passed
+ # Return success if no-constrain, else return status from constrain
+ [ ! "$__constrain" ] ||
+ f_dialog_size_constrain "$__var_height" "$__var_width"
}
-# f_xdialog_2inputsbox_size $title $backtitle $prompt \
+# f_xdialog_2inputsbox_size [-n] $var_height $var_width \
+# $title $backtitle $prompt \
# $label1 $init1 $label2 $init2
#
# Xdialog(1) does not perform auto-sizing of the width and height of
# `--2inputsbox' boxes sensibly.
#
-# This function helps solve this issue by taking as arguments (in order of
-# appearance) the title, backtitle, prompt, label for the first field, initial
-# text for said field, label for the second field, and initial text for said
-# field returning the optimal width and height for the box (not exceeding the
-# actual terminal width and height).
+# This function helps solve this issue by taking two sets of sequential
+# arguments. The first set of arguments are the variable names to use when
+# storing the calculated height and width. The second set of arguments are the
+# title, backtitle, prompt, label for the first field, initial text for said
+# field, label for the second field, and initial text for said field. The
+# optimal height and width for the described widget (not exceeding the actual
+# terminal height or width) is stored in $var_height and $var_width
+# (respectively).
+#
+# If the first argument is `-n', the calculated sizes ($var_height and
+# $var_width) are not constrained to minimum/maximum values.
#
# Newline character sequences (``\n'') in $prompt are expanded as-is done by
# Xdialog(1).
#
-# Output is in the format of "height width".
-#
f_xdialog_2inputsbox_size()
{
- local title="$1" btitle="$2" prompt="$3"
- local label1="$4" init1="$5" label2="$6" init2="$7" n
- local size="$( f_dialog_inputbox_size \
- "$title" "$btitle" "$prompt" "$init1" )"
- local height="${size%%[$IFS]*}"
- local width="${size##*[$IFS]}"
-
- local min_width=35
- local max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
- local max_height="${max_size%%[$IFS]*}"
- local max_width="${max_size##*[$IFS]}"
-
- # Add height for first label
- height=$(( $height + 2 ))
-
- #
- # Bump width for first label text (if not already at maximum width).
- #
- if [ $width -lt $max_width ]; then
- n=$(( ${#label1} + 7 ))
-
- # Add 16.6% width for Xdialog(1)
- n=$(( $n + $n / 6 ))
-
- if [ $n -gt $width -a $n -gt $min_width ]; then
- if [ $n -lt $max_width ]; then
- width=$n
- else
- width=$max_width
- fi
- fi
+ local __constrain=1
+ [ "$1" = "-n" ] && __constrain= && shift 1 # -n
+ local __var_height="$1" __var_width="$2"
+ local __title="$3" __btitle="$4" __prompt="$5"
+ local __label1="$6" __init1="$7" __label2="$8" __init2="$9"
+
+ # Return unless at least one size aspect has been requested
+ [ "$__var_height" -o "$__var_width" ] || return $FAILURE
+
+ # Calculate height/width of inputbox (adjusted/constrained below)
+ # NOTE: Function name appended to prevent __var_{height,width} values
+ # from becoming local (and thus preventing setvar from working).
+ local __height_2ibox_size __width_2ibox_size
+ f_dialog_inputbox_size -n \
+ "${__var_height:+__height_2ibox_size}" \
+ "${__var_width:+__width_2ibox_size}" \
+ "$__title" "$__btitle" "$__prompt" "$__hline" "$__init1"
+
+ # Adjust height if desired
+ if [ "$__var_height" ]; then
+ # Add height for 1st label, 2nd label, and 2nd input box
+ __height_2ibox_size=$(( $__height_2ibox_size + 2 + 2 + 2 ))
+ setvar "$__var_height" $__height_2ibox_size
fi
- # Add height for second label
- height=$(( $height + 2 ))
+ # Adjust width if desired
+ if [ "$__var_width" ]; then
+ local __n
- #
- # Bump width for second label text (if not already at maximum width).
- #
- if [ $width -lt $max_width ]; then
- n=$(( ${#label2} + 7 ))
-
- # Add 16.6% width for Xdialog(1)
- n=$(( $n + $n / 6 ))
+ # Bump width for first label text (+16.6% since Xdialog(1))
+ __n=$(( ${#__label1} + 7 ))
+ __n=$(( $__n + $__n / 6 ))
+ [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n
- if [ $n -gt $width -a $n -gt $min_width ]; then
- if [ $n -lt $max_width ]; then
- width=$n
- else
- width=$max_width
- fi
- fi
- fi
+ # Bump width for second label text (+16.6% since Xdialog(1))
+ __n=$(( ${#__label2} + 7 ))
+ __n=$(( $__n + $__n / 6 ))
+ [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n
- # Add height for a second inputbox
- height=$(( $height + 2 ))
- [ $height -le $max_height ] || height=$max_height
+ # Bump width for 2nd initial text (something neither dialog(1)
+ # nor Xdialog(1) do, but worth it!; +16.6% since Xdialog(1))
+ __n=$(( ${#__init2} + 7 ))
+ __n=$(( $__n + $__n / 6 ))
+ [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n
- #
- # Bump width for second initial text (if not already at maximum width).
- # NOTE: Something neither dialog(1)/Xdialog(1) do, but worth it!
- #
- if [ $width -lt $max_width ]; then
- n=$(( ${#init2} + 7 ))
-
- # Add 16.6% width for Xdialog(1)
- n=$(( $n + $n / 6 ))
-
- if [ $n -gt $width -a $n -gt $min_width ]; then
- if [ $n -lt $max_width ]; then
- width=$n
- else
- width=$max_width
- fi
- fi
+ setvar "$__var_width" $__width_2ibox_size
fi
- # Return both
- echo "$height $width"
+ # Constrain values to sensible minimums/maximums unless `-n' was passed
+ # Return success if no-constrain, else return status from constrain
+ [ ! "$__constrain" ] ||
+ f_dialog_size_constrain "$__var_height" "$__var_width"
}
-# f_dialog_menu_size $title $backtitle $prompt $hline \
+# f_dialog_menu_size [-n] $var_height $var_width $var_rows \
+# $title $backtitle $prompt $hline \
# $tag1 $item1 $tag2 $item2 ...
#
# Not all versions of dialog(1) perform auto-sizing of the width and height of
# `--menu' boxes sensibly.
#
-# This function helps solve this issue by taking as arguments (in order of
-# appearance) the title, backtitle, prompt, hline and list of tag/item pairs,
-# returning the optimal width and height for the menu (not exceeding the actual
-# terminal width or height).
+# This function helps solve this issue by taking three sets of sequential
+# arguments. The first set of arguments are the variable names to use when
+# storing the calculated height, width, and rows. The second set of arguments
+# are the title, backtitle, prompt, and hline. The [optional] third set of
+# arguments are the menu list itself (comprised of tag/item couplets). The
+# optimal height, width, and rows for the described widget (not exceeding the
+# actual terminal height or width) is stored in $var_height, $var_width, and
+# $var_rows (respectively).
#
-# Output is in the format of "height width rows".
+# If the first argument is `-n', the calculated sizes ($var_height, $var_width,
+# and $var_rows) are not constrained to minimum/maximum values.
#
f_dialog_menu_size()
{
- local title="$1" btitle="$2" prompt="$3" hline="$4" n=0
- local min_width min_rows max_size
-
- if [ "$USE_XDIALOG" ]; then
- min_width=35
- min_rows=1
- max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
- else
- min_width=24
- min_rows=0
- max_size=$( stty size 2> /dev/null ) # usually "24 80"
- : ${max_size:=$DEFAULT_TERMINAL_SIZE}
- fi
-
- local max_width="${max_size##*[$IFS]}"
- local max_height="${max_size%%[$IFS]*}"
- local box_size="$( f_dialog_infobox_size \
- "$title" "$btitle" "$prompt" "$hline" )"
- local box_height="${box_size%%[$IFS]*}"
- local box_width="${box_size##*[$IFS]}"
- local max_rows=$(( $max_height - 8 ))
- local height width=$box_width rows=$min_rows
-
- shift 4 # title/btitle/prompt/hline
-
- # If there's no prompt, bump the max-rows by 1
- [ "$prompt" ] || max_rows=$(( $max_rows + 1 ))
-
- #
- # The sum total between the longest tag-length and longest item-length
- # should be used for the menu width (not to exceed terminal width).
- #
- # Also, calculate the number of rows (not to exceed terminal height).
- #
- local longest_tag=0 longest_item=0
+ local __constrain=1
+ [ "$1" = "-n" ] && __constrain= && shift 1 # -n
+ local __var_height="$1" __var_width="$2" __var_rows="$3"
+ local __title="$4" __btitle="$5" __prompt="$6" __hline="$7"
+ shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline
+
+ # Return unless at least one size aspect has been requested
+ [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] ||
+ return $FAILURE
+
+ # Calculate height/width of infobox (adjusted/constrained below)
+ # NOTE: Function name appended to prevent __var_{height,width} values
+ # from becoming local (and thus preventing setvar from working).
+ local __height_menu_size __width_menu_size
+ f_dialog_infobox_size -n \
+ "${__var_height:+__height_menu_size}" \
+ "${__var_width:+__width_menu_size}" \
+ "$__title" "$__btitle" "$__prompt" "$__hline"
+
+ #
+ # Always process the menu-item arguments to get the longest tag-length,
+ # longest item-length (both used to bump the width), and the number of
+ # rows (used to bump the height).
+ #
+ local __longest_tag=0 __longest_item=0 __rows=0
while [ $# -ge 2 ]; do
- local tag="$1" item="$2"
+ local __tag="$1" __item="$2"
shift 2 # tag/item
-
- [ ${#tag} -gt $longest_tag ] && longest_tag=${#tag}
- [ ${#item} -gt $longest_item ] && longest_item=${#item}
- [ $rows -lt $max_rows ] && rows=$(( $rows + 1 ))
+ [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag}
+ [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item}
+ __rows=$(( $__rows + 1 ))
done
- # Update width
- n=$(( $longest_tag + $longest_item + 10 ))
- [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) # Add 16.6% for Xdialog(1)
- if [ $n -gt $width -a $n -gt $min_width ]; then
- if [ $n -lt $max_width ]; then
- width=$n
+ # Adjust rows early (for up-comning height calculation)
+ if [ "$__var_height" -o "$__var_rows" ]; then
+ # Add a row for visual aid if using Xdialog(1)
+ [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 ))
+ fi
+
+ # Adjust height if desired
+ if [ "$__var_height" ]; then
+ # Add rows to height
+ if [ "$USE_XDIALOG" ]; then
+ __height_menu_size=$((
+ $__height_menu_size + $__rows + 7 ))
else
- width=$max_width
+ __height_menu_size=$((
+ $__height_menu_size + $__rows + 4 ))
fi
+ setvar "$__var_height" $__height_menu_size
fi
- # Fix rows and set height
- [ $rows -gt 0 ] || rows=1
- if [ "$USE_XDIALOG" ]; then
- height=$(( $rows + $box_height + 7 ))
- else
- height=$(( $rows + $box_height + 4 ))
+ # Adjust width if desired
+ if [ "$__var_width" ]; then
+ # The sum total between the longest tag-length and the
+ # longest item-length should be used to bump menu width
+ local __n=$(( $__longest_tag + $__longest_item + 10 ))
+ [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6%
+ [ $__n -gt $__width_menu_size ] && __width_menu_size=$__n
+
+ setvar "$__var_width" $__width_menu_size
fi
- [ $height -le $max_height ] || height=$max_height
- # Return all three
- echo "$height $width $rows"
+ # Store adjusted rows if desired
+ [ "$__var_rows" ] && setvar "$__var_rows" $__rows
+
+ # Constrain height, width, and rows to sensible minimum/maximum values
+ # Return success if no-constrain, else return status from constrain
+ [ ! "$__constrain" ] || f_dialog_menu_constrain \
+ "$__var_height" "$__var_width" "$__var_rows" "$__prompt"
}
-# f_dialog_menu_with_help_size $title $backtitle $prompt $hline \
+# f_dialog_menu_with_help_size [-n] $var_height $var_width $var_rows \
+# $title $backtitle $prompt $hline \
# $tag1 $item1 $help1 $tag2 $item2 $help2 ...
#
# Not all versions of dialog(1) perform auto-sizing of the width and height of
# `--menu' boxes sensibly.
#
-# This function helps solve this issue by taking as arguments (in order of
-# appearance) the title, backtitle, prompt, hline and list of tag/item/help
-# triplets, returning the optimal width and height for the menu (not exceeding
-# the actual terminal width or height).
+# This function helps solve this issue by taking three sets of sequential
+# arguments. The first set of arguments are the variable names to use when
+# storing the calculated height, width, and rows. The second set of arguments
+# are the title, backtitle, prompt, and hline. The [optional] third set of
+# arguments are the menu list itself (comprised of tag/item/help triplets). The
+# optimal height, width, and rows for the described widget (not exceeding the
+# actual terminal height or width) is stored in $var_height, $var_width, and
+# $var_rows (respectively).
#
-# Output is in the format of "height width rows".
+# If the first argument is `-n', the calculated sizes ($var_height, $var_width,
+# and $var_rows) are not constrained to minimum/maximum values.
#
f_dialog_menu_with_help_size()
{
- local title="$1" btitle="$2" prompt="$3" hline="$4" n=0
- local min_width min_rows max_size
-
- if [ "$USE_XDIALOG" ]; then
- min_width=35
- min_rows=1
- max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
- else
- min_width=24
- min_rows=0
- max_size=$( stty size 2> /dev/null ) # usually "24 80"
- : ${max_size:=$DEFAULT_TERMINAL_SIZE}
- fi
-
- local max_width="${max_size##*[$IFS]}"
- local max_height="${max_size%%[$IFS]*}"
- local box_size="$( f_dialog_infobox_size \
- "$title" "$btitle" "$prompt" "$hline" )"
- local box_height="${box_size%%[$IFS]*}"
- local box_width="${box_size##*[$IFS]}"
- local max_rows=$(( $max_height - 8 ))
- local height width=$box_width rows=$min_rows
-
- shift 4 # title/btitle/prompt/hline
-
- # If there's no prompt, bump the max-rows by 1
- [ "$prompt" ] || max_rows=$(( $max_rows + 1 ))
-
- #
- # The sum total between the longest tag-length and longest item-length
- # should be used for the menu width (not to exceed terminal width).
- #
- # Also, calculate the number of rows (not to exceed terminal height).
- #
- # Also, calculate the longest help while we're here. This will be used
- # to influence the width of the menu if (and only-if) using Xdialog(1).
- #
- local longest_tag=0 longest_item=0 longest_help=0
+ local __constrain=1
+ [ "$1" = "-n" ] && __constrain= && shift 1 # -n
+ local __var_height="$1" __var_width="$2" __var_rows="$3"
+ local __title="$4" __btitle="$5" __prompt="$6" __hline="$7"
+ shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline
+
+ # Return unless at least one size aspect has been requested
+ [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] ||
+ return $FAILURE
+
+ # Calculate height/width of infobox (adjusted/constrained below)
+ # NOTE: Function name appended to prevent __var_{height,width} values
+ # from becoming local (and thus preventing setvar from working).
+ local __height_menu_with_help_size __width_menu_with_help_size
+ f_dialog_infobox_size -n \
+ "${__var_height:+__height_menu_with_help_size}" \
+ "${__var_width:+__width_menu_with_help_size}" \
+ "$__title" "$__btitle" "$__prompt" "$__hline"
+
+ #
+ # Always process the menu-item arguments to get the longest tag-length,
+ # longest item-length, longest help-length (help-length only considered
+ # if using Xdialog(1), as it places the help string in the widget) --
+ # all used to bump the width -- and the number of rows (used to bump
+ # the height).
+ #
+ local __longest_tag=0 __longest_item=0 __longest_help=0 __rows=0
while [ $# -ge 3 ]; do
- local tag="$1" item="$2" help="$3"
+ local __tag="$1" __item="$2" __help="$3"
shift 3 # tag/item/help
-
- [ ${#tag} -gt $longest_tag ] && longest_tag=${#tag}
- [ ${#item} -gt $longest_item ] && longest_item=${#item}
- [ ${#help} -gt $longest_help ] && longest_help=${#help}
- [ $rows -lt $max_rows ] && rows=$(( $rows + 1 ))
+ [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag}
+ [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item}
+ [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help}
+ __rows=$(( $__rows + 1 ))
done
- # Update width
- n=$(( $longest_tag + $longest_item + 10 ))
- [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) # Add 16.6% for Xdialog(1)
- if [ $n -gt $width -a $n -gt $min_width ]; then
- if [ $n -lt $max_width ]; then
- width=$n
+ # Adjust rows early (for up-coming height calculation)
+ if [ "$__var_height" -o "$__var_rows" ]; then
+ # Add a row for visual aid if using Xdialog(1)
+ [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 ))
+ fi
+
+ # Adjust height if desired
+ if [ "$__var_height" ]; then
+ # Add rows to height
+ if [ "$USE_XDIALOG" ]; then
+ __height_menu_with_help_size=$((
+ $__height_menu_with_help_size + $__rows + 8 ))
else
- width=$max_width
+ __height_menu_with_help_size=$((
+ $__height_menu_with_help_size + $__rows + 4 ))
fi
+ setvar "$__var_height" $__height_menu_with_help_size
fi
- # Update width for help text if using Xdialog(1)
- if [ "$USE_XDIALOG" ]; then
- n=$(( $longest_help + 10 ))
- n=$(( $n + $n / 6 )) # +16.6%
- if [ $n -gt $width -a $n -gt $min_width ]; then
- if [ $n -lt $max_width ]; then
- width=$n
- else
- width=$max_width
- fi
+ # Adjust width if desired
+ if [ "$__var_width" ]; then
+ # The sum total between the longest tag-length and the
+ # longest item-length should be used to bump menu width
+ local __n=$(( $__longest_tag + $__longest_item + 10 ))
+ [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6%
+ [ $__n -gt $__width_menu_with_help_size ] &&
+ __width_menu_with_help_size=$__n
+
+ # Update width for help text if using Xdialog(1)
+ if [ "$USE_XDIALOG" ]; then
+ __n=$(( $__longest_help + 10 ))
+ __n=$(( $__n + $__n / 6 )) # plus 16.6%
+ [ $__n -gt $__width_menu_with_help_size ] &&
+ __width_menu_with_help_size=$__n
fi
- fi
- # Fix rows and set height
- [ $rows -gt 0 ] || rows=1
- if [ "$USE_XDIALOG" ]; then
- height=$(( $rows + $box_height + 8 ))
- else
- height=$(( $rows + $box_height + 4 ))
+ setvar "$__var_width" $__width_menu_with_help_size
fi
- [ $height -le $max_height ] || height=$max_height
- # Return all three
- echo "$height $width $rows"
+ # Store adjusted rows if desired
+ [ "$__var_rows" ] && setvar "$__var_rows" $__rows
+
+ # Constrain height, width, and rows to sensible minimum/maximum values
+ # Return success if no-constrain, else return status from constrain
+ [ ! "$__constrain" ] || f_dialog_menu_constrain \
+ "$__var_height" "$__var_width" "$__var_rows" "$__prompt"
}
-# f_dialog_radiolist_size $title $backtitle $prompt $hline \
+# f_dialog_radiolist_size [-n] $var_height $var_width $var_rows \
+# $title $backtitle $prompt $hline \
# $tag1 $item1 $status1 $tag2 $item2 $status2 ...
#
# Not all versions of dialog(1) perform auto-sizing of the width and height of
# `--radiolist' boxes sensibly.
#
-# This function helps solve this issue by taking as arguments (in order of
-# appearance) the title, backtitle, prompt, hline and list of tag/item/status
-# triplets, returning the optimal width and height for the radiolist (not
-# exceeding the actual terminal width or height).
+# This function helps solve this issue by taking three sets of sequential
+# arguments. The first set of arguments are the variable names to use when
+# storing the calculated height, width, and rows. The second set of arguments
+# are the title, backtitle, prompt, and hline. The [optional] third set of
+# arguments are the radio list itself (comprised of tag/item/status triplets).
+# The optimal height, width, and rows for the described widget (not exceeding
+# the actual terminal height or width) is stored in $var_height, $var_width,
+# and $var_rows (respectively).
#
-# Output is in the format of "height width rows".
+# If the first argument is `-n', the calculated sizes ($var_height, $var_width,
+# and $var_rows) are not constrained to minimum/maximum values.
#
f_dialog_radiolist_size()
{
- local title="$1" btitle="$2" prompt="$3" hline="$4" n=0
- local min_width min_rows max_size
+ local __constrain=1
+ [ "$1" = "-n" ] && __constrain= && shift 1 # -n
+ local __var_height="$1" __var_width="$2" __var_rows="$3"
+ local __title="$4" __btitle="$5" __prompt="$6" __hline="$7"
+ shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline
+
+ # Return unless at least one size aspect has been requested
+ [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] ||
+ return $FAILURE
+
+ # Calculate height/width of infobox (adjusted/constrained below)
+ # NOTE: Function name appended to prevent __var_{height,width} values
+ # from becoming local (and thus preventing setvar from working).
+ local __height_rlist_size __width_rlist_size
+ f_dialog_infobox_size -n \
+ "${__var_height:+__height_rlist_size}" \
+ "${__var_width:+__width_rlist_size}" \
+ "$__title" "$__btitle" "$__prompt" "$__hline"
+
+ #
+ # Always process the menu-item arguments to get the longest tag-length,
+ # longest item-length (both used to bump the width), and the number of
+ # rows (used to bump the height).
+ #
+ local __longest_tag=0 __longest_item=0 __rows=0
+ while [ $# -ge 3 ]; do
+ local __tag="$1" __item="$2"
+ shift 3 # tag/item/status
+ [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag}
+ [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item}
+ __rows=$(( $__rows + 1 ))
+ done
- if [ "$USE_XDIALOG" ]; then
- min_width=35
- min_rows=1
- max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
- else
- min_width=24
- min_rows=0
- max_size=$( stty size 2> /dev/null ) # usually "24 80"
- : ${max_size:=$DEFAULT_TERMINAL_SIZE}
+ # Adjust rows early (for up-coming height calculation)
+ if [ "$__var_height" -o "$__var_rows" ]; then
+ # Add a row for visual aid if using Xdialog(1)
+ [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 ))
fi
- local max_width="${max_size##*[$IFS]}"
- local max_height="${max_size%%[$IFS]*}"
- local box_size="$( f_dialog_infobox_size \
- "$title" "$btitle" "$prompt" "$hline" )"
- local box_height="${box_size%%[$IFS]*}"
- local box_width="${box_size##*[$IFS]}"
- local max_rows=$(( $max_height - 8 ))
- local height width=$box_width rows=$min_rows
+ # Adjust height if desired
+ if [ "$__var_height" ]; then
+ # Add rows to height
+ if [ "$USE_XDIALOG" ]; then
+ __height_rlist_size=$((
+ $__height_rlist_size + $__rows + 7 ))
+ else
+ __height_rlist_size=$((
+ $__height_rlist_size + $__rows + 4 ))
+ fi
+ setvar "$__var_height" $__height_rlist_size
+ fi
- shift 4 # title/btitle/prompt/hline
+ # Adjust width if desired
+ if [ "$__var_width" ]; then
+ # Sum total between longest tag-length, longest item-length,
+ # and radio-button width should be used to bump menu width
+ local __n=$(( $__longest_tag + $__longest_item + 13 ))
+ [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6%
+ [ $__n -gt $__width_rlist_size ] && __width_rlist_size=$__n
- #
- # The sum total between the longest tag-length, longest item-length,
- # and radio-button width should be used for the menu width (not to
- # exceed terminal width).
- #
- # Also, calculate the number of rows (not to exceed terminal height).
- #
- local longest_tag=0 longest_item=0
- while [ $# -ge 2 ]; do
- local tag="$1" item="$2" help="$3"
- shift 3 # tag/item/status
+ setvar "$__var_width" $__width_rlist_size
+ fi
- [ ${#tag} -gt $longest_tag ] && longest_tag=${#tag}
- [ ${#item} -gt $longest_item ] && longest_item=${#item}
- [ $rows -lt $max_rows ] && rows=$(( $rows + 1 ))
+ # Store adjusted rows if desired
+ [ "$__var_rows" ] && setvar "$__var_rows" $__rows
+
+ # Constrain height, width, and rows to sensible minimum/maximum values
+ # Return success if no-constrain, else return status from constrain
+ [ ! "$__constrain" ] || f_dialog_menu_constrain \
+ "$__var_height" "$__var_width" "$__var_rows" "$__prompt"
+}
+
+# f_dialog_checklist_size [-n] $var_height $var_width $var_rows \
+# $title $backtitle $prompt $hline \
+# $tag1 $item1 $status1 $tag2 $item2 $status2 ...
+#
+# Not all versions of dialog(1) perform auto-sizing of the width and height of
+# `--checklist' boxes sensibly.
+#
+# This function helps solve this issue by taking three sets of sequential
+# arguments. The first set of arguments are the variable names to use when
+# storing the calculated height, width, and rows. The second set of arguments
+# are the title, backtitle, prompt, and hline. The [optional] third set of
+# arguments are the check list itself (comprised of tag/item/status triplets).
+# The optimal height, width, and rows for the described widget (not exceeding
+# the actual terminal height or width) is stored in $var_height, $var_width,
+# and $var_rows (respectively).
+#
+# If the first argument is `-n', the calculated sizes ($var_height, $var_width,
+# and $var_rows) are not constrained to minimum/maximum values.
+#
+f_dialog_checklist_size()
+{
+ f_dialog_radiolist_size "$@"
+}
+
+# f_dialog_radiolist_with_help_size [-n] $var_height $var_width $var_rows \
+# $title $backtitle $prompt $hline \
+# $tag1 $item1 $status1 $help1 \
+# $tag2 $item2 $status2 $help2 ...
+#
+# Not all versions of dialog(1) perform auto-sizing of the width and height of
+# `--radiolist' boxes sensibly.
+#
+# This function helps solve this issue by taking three sets of sequential
+# arguments. The first set of arguments are the variable names to use when
+# storing the calculated height, width, and rows. The second set of arguments
+# are the title, backtitle, prompt, and hline. The [optional] third set of
+# arguments are the radio list itself (comprised of tag/item/status/help
+# quadruplets). The optimal height, width, and rows for the described widget
+# (not exceeding the actual terminal height or width) is stored in $var_height,
+# $var_width, and $var_rows (respectively).
+#
+# If the first argument is `-n', the calculated sizes ($var_height, $var_width,
+# and $var_rows) are not constrained to minimum/maximum values.
+#
+f_dialog_radiolist_with_help_size()
+{
+ local __constrain=1
+ [ "$1" = "-n" ] && __constrain= && shift 1 # -n
+ local __var_height="$1" __var_width="$2" __var_rows="$3"
+ local __title="$4" __btitle="$5" __prompt="$6" __hline="$7"
+ shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline
+
+ # Return unless at least one size aspect has been requested
+ [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] ||
+ return $FAILURE
+
+ # Calculate height/width of infobox (adjusted/constrained below)
+ # NOTE: Function name appended to prevent __var_{height,width} values
+ # from becoming local (and thus preventing setvar from working).
+ local __height_rlist_with_help_size __width_rlist_with_help_size
+ f_dialog_infobox_size -n \
+ "${__var_height:+__height_rlist_with_help_size}" \
+ "${__var_width:+__width_rlist_with_help_size}" \
+ "$__title" "$__btitle" "$__prompt" "$__hline"
+
+ #
+ # Always process the menu-item arguments to get the longest tag-length,
+ # longest item-length, longest help-length (help-length only considered
+ # if using Xdialog(1), as it places the help string in the widget) --
+ # all used to bump the width -- and the number of rows (used to bump
+ # the height).
+ #
+ local __longest_tag=0 __longest_item=0 __longest_help=0 __rows=0
+ while [ $# -ge 4 ]; do
+ local __tag="$1" __item="$2" __status="$3" __help="$4"
+ shift 4 # tag/item/status/help
+ [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag}
+ [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item}
+ [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help}
+ __rows=$(( $__rows + 1 ))
done
- # Update width
- n=$(( $longest_tag + $longest_item + 13 ))
- [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) # Add 16.6% for Xdialog(1)
- if [ $n -gt $width -a $n -gt $min_width ]; then
- if [ $n -lt $max_width ]; then
- width=$n
+ # Adjust rows early (for up-coming height calculation)
+ if [ "$__var_height" -o "$__var_rows" ]; then
+ # Add a row for visual aid if using Xdialog(1)
+ [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 ))
+ fi
+
+ # Adjust height if desired
+ if [ "$__var_height" ]; then
+ # Add rows to height
+ if [ "$USE_XDIALOG" ]; then
+ __height_rlist_with_help_size=$((
+ $__height_rlist_with_help_size + $__rows + 7 ))
else
- width=$max_width
+ __height_rlist_with_help_size=$((
+ $__height_rlist_with_help_size + $__rows + 4 ))
fi
+ setvar "$__var_height" $__height
fi
- # Fix rows and set height
- [ $rows -gt 0 ] || rows=1
- if [ "$USE_XDIALOG" ]; then
- height=$(( $rows + $box_height + 7 ))
- else
- height=$(( $rows + $box_height + 4 ))
+ # Adjust width if desired
+ if [ "$__var_width" ]; then
+ # Sum total between longest tag-length, longest item-length,
+ # and radio-button width should be used to bump menu width
+ local __n=$(( $__longest_tag + $__longest_item + 13 ))
+ [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6%
+ [ $__n -gt $__width_rlist_with_help_size ] &&
+ __width_rlist_with_help_size=$__n
+
+ # Update width for help text if using Xdialog(1)
+ if [ "$USE_XDIALOG" ]; then
+ __n=$(( $__longest_help + 10 ))
+ __n=$(( $__n + $__n / 6 )) # plus 16.6%
+ [ $__n -gt $__width_rlist_with_help_size ] &&
+ __width_rlist_with_help_size=$__n
+ fi
+
+ setvar "$__var_width" $__width_rlist_with_help_size
fi
- [ $height -le $max_height ] || height=$max_height
- # Return all three
- echo "$height $width $rows"
+ # Store adjusted rows if desired
+ [ "$__var_rows" ] && setvar "$__var_rows" $__rows
+
+ # Constrain height, width, and rows to sensible minimum/maximum values
+ # Return success if no-constrain, else return status from constrain
+ [ ! "$__constrain" ] || f_dialog_menu_constrain \
+ "$__var_height" "$__var_width" "$__var_rows" "$__prompt"
+}
+
+# f_dialog_checklist_with_help_size [-n] $var_height $var_width $var_rows \
+# $title $backtitle $prompt $hline \
+# $tag1 $item1 $status1 $help1 \
+# $tag2 $item2 $status2 $help2 ...
+#
+# Not all versions of dialog(1) perform auto-sizing of the width and height of
+# `--checklist' boxes sensibly.
+#
+# This function helps solve this issue by taking three sets of sequential
+# arguments. The first set of arguments are the variable names to use when
+# storing the calculated height, width, and rows. The second set of arguments
+# are the title, backtitle, prompt, and hline. The [optional] third set of
+# arguments are the check list itself (comprised of tag/item/status/help
+# quadruplets). The optimal height, width, and rows for the described widget
+# (not exceeding the actual terminal height or width) is stored in $var_height,
+# $var_width, and $var_rows (respectively).
+#
+# If the first argument is `-n', the calculated sizes ($var_height, $var_width,
+# and $var_rows) are not constrained to minimum/maximum values.
+#
+f_dialog_checklist_with_help_size()
+{
+ f_dialog_radiolist_with_help_size "$@"
}
-# f_dialog_calendar_size $title $backtitle $prompt [$hline]
+# f_dialog_calendar_size [-n] $var_height $var_width \
+# $title $backtitle $prompt [$hline]
#
# Not all versions of dialog(1) perform auto-sizing of the width and height of
# `--calendar' boxes sensibly.
#
-# This function helps solve this issue by taking as arguments (in order of
-# appearance) the title, backtitle, prompt, and [optionally] hline returning
-# the optimal width and height for the box (not exceeding the actual terminal
-# width and height).
+# This function helps solve this issue by taking two sets of sequential
+# arguments. The first set of arguments are the variable names to use when
+# storing the calculated height and width. The second set of arguments are the
+# title, backtitle, prompt, and [optionally] hline. The optimal height and
+# width for the described widget (not exceeding the actual terminal height or
+# width) is stored in $var_height and $var_width (respectively).
+#
+# If the first argument is `-n', the calculated sizes ($var_height and
+# $var_width) are not constrained to minimum/maximum values.
#
# Newline character sequences (``\n'') in $prompt are expanded as-is done by
# dialog(1).
#
-# Output is in the format of "height width".
-#
f_dialog_calendar_size()
{
- local title="$1" btitle="$2" prompt="$3" hline="$4" n
- local size="$( f_dialog_infobox_size \
- "$title" "$btitle" "$prompt" "$hline" )"
- local height="${size%%[$IFS]*}"
- local width="${size##*[$IFS]}"
-
- local min_width min_height max_size
- if [ "$USE_XDIALOG" ]; then
- min_height=15
- min_width=55
- max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
- else
- min_height=0
- min_width=40
- max_size=$( stty size 2> /dev/null ) # usually "24 80"
- : ${max_size:=$DEFAULT_TERMINAL_SIZE}
- fi
- local max_height="${max_size%%[$IFS]*}"
- local max_width="${max_size##*[$IFS]}"
+ local __constrain=1
+ [ "$1" = "-n" ] && __constrain= && shift 1 # -n
+ local __var_height="$1" __var_width="$2"
+ local __title="$3" __btitle="$4" __prompt="$5" __hline="$6"
- #
- # Enforce the minimum width for displaying the calendar
- #
- [ $width -ge $min_width ] || width=$min_width
+ # Return unless at least one size aspect has been requested
+ [ "$__var_height" -o "$__var_width" ] || return $FAILURE
#
- # When using dialog(1), the calendar box is unique from other dialog(1)
- # boxes in-that the height passed should not accomodate the 15-lines
- # required to display the calendar. This does not apply to Xdialog(1).
- #
- # When using Xdialog(1), the height must accomodate the 15-lines
- # required to display the calendar.
+ # Obtain/Adjust minimum and maximum thresholds
+ # NOTE: Function name appended to prevent __var_{height,width} values
+ # from becoming local (and thus preventing setvar from working).
#
- # NOTE: Also under dialog(1), because we can't predict whether the user
- # has disabled shadow's in their `$HOME/.dialogrc' file, we'll subtract
- # 16 rather than 15. This does not apply to Xdialog(1).
- #
- max_height=$(( $max_height - 16 ))
- height=$( echo "$prompt" | f_number_of_lines )
+ local __max_height_cal_size __max_width_cal_size
+ f_dialog_max_size __max_height_cal_size __max_width_cal_size
+ __max_width_cal_size=$(( $__max_width_cal_size - 2 ))
+ # the calendar box will refuse to display if too wide
+ local __min_width
if [ "$USE_XDIALOG" ]; then
- # Add height to accomodate for the embedded calendar widget
- height=$(( $height + $min_height - 1 ))
+ __min_width=55
+ else
+ __min_width=40
+ __max_height_cal_size=$((
+ $__max_height_cal_size - $DIALOG_CALENDAR_HEIGHT ))
+ # When using dialog(1), we can't predict whether the user has
+ # disabled shadow's in their `$HOME/.dialogrc' file, so we'll
+ # subtract one for the potential shadow around the widget
+ __max_height_cal_size=$(( $__max_height_cal_size - 1 ))
+ fi
- # Also, bump height if backtitle is enabled
- if [ "$btitle" ]; then
- local n="$( echo "$btitle" | f_number_of_lines )"
- height=$(( $height + $n + 2 ))
+ # Calculate height if desired
+ if [ "$__var_height" ]; then
+ local __height
+ __height=$( echo "$__prompt" | f_number_of_lines )
+
+ if [ "$USE_XDIALOG" ]; then
+ # Add height to accomodate for embedded calendar widget
+ __height=$(( $__height + $DIALOG_CALENDAR_HEIGHT - 1 ))
+
+ # Also, bump height if backtitle is enabled
+ if [ "$__btitle" ]; then
+ local __n
+ __n=$( echo "$__btitle" | f_number_of_lines )
+ __height=$(( $__height + $__n + 2 ))
+ fi
+ else
+ [ "$__prompt" ] && __height=$(( $__height + 1 ))
fi
- else
- [ "$prompt" ] && height=$(( $height + 1 ))
+
+ # Enforce maximum height, unless `-n' was passed
+ [ "$__constrain" -a $__height -gt $__max_height_cal_size ] &&
+ __height=$__max_height_cal_size
+
+ setvar "$__var_height" $__height
fi
- [ $height -le $max_height ] || height=$max_height
- #
- # The calendar box refuses to display if too large.
- #
- max_width=$(( $max_width - 2 ))
- [ $width -le $max_width ] || width=$max_width
+ # Calculate width if desired
+ if [ "$__var_width" ]; then
+ # NOTE: Function name appended to prevent __var_{height,width}
+ # values from becoming local (and thus preventing setvar
+ # from working).
+ local __width_cal_size
+ f_dialog_infobox_size -n "" __width_cal_size \
+ "$__title" "$__btitle" "$__prompt" "$__hline"
+
+ # Enforce minimum/maximum width, unless `-n' was passed
+ if [ "$__constrain" ]; then
+ if [ $__width_cal_size -lt $__min_width ]; then
+ __width_cal_size=$__min_width
+ elif [ $__width_cal_size -gt $__max_width_cal_size ]
+ then
+ __width_cal_size=$__max_width_size
+ fi
+ fi
- # Return both
- echo "$height $width"
+ setvar "$__var_width" $__width_cal_size
+ fi
+
+ return $SUCCESS
}
-# f_dialog_timebox_size $title $backtitle $prompt [$hline]
+# f_dialog_timebox_size [-n] $var_height $var_width \
+# $title $backtitle $prompt [$hline]
#
# Not all versions of dialog(1) perform auto-sizing of the width and height of
# `--timebox' boxes sensibly.
#
-# This function helps solve this issue by taking as arguments (in order of
-# appearance) the title, backtitle, prompt, and [optionally] hline returning
-# the optimal width and height for the box (not exceeding the actual terminal
-# width and height).
+# This function helps solve this issue by taking two sets of sequential
+# arguments. The first set of arguments are the variable names to use when
+# storing the calculated height and width. The second set of arguments are the
+# title, backtitle, prompt, and [optionally] hline. The optional height and
+# width for the described widget (not exceeding the actual terminal height or
+# width) is stored in $var_height and $var_width (respectively).
+#
+# If the first argument is `-n', the calculated sizes ($var_height and
+# $var_width) are not constrained to minimum/maximum values.
#
# Newline character sequences (``\n'') in $prompt are expanded as-is done by
# dialog(1).
#
-# Output is in the format of "height width".
-#
f_dialog_timebox_size()
{
- local title="$1" btitle="$2" prompt="$3" hline="$4" n
- local size="$( f_dialog_infobox_size \
- "$title" "$btitle" "$prompt" "$hline" )"
- local height="${size%%[$IFS]*}"
- local width="${size##*[$IFS]}"
+ local __constrain=1
+ [ "$1" = "-n" ] && __constrain= && shift 1 # -n
+ local __var_height="$1" __var_width="$2"
+ local __title="$3" __btitle="$4" __prompt="$5" __hline="$6"
- local min_width min_height max_size
- if [ "$USE_XDIALOG" ]; then
- min_width=40
- max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
- else
- min_height=0
- min_width=20
- max_size=$( stty size 2> /dev/null ) # usually "24 80"
- : ${max_size:=$DEFAULT_TERMINAL_SIZE}
- fi
- local max_height="${max_size%%[$IFS]*}"
- local max_width="${max_size##*[$IFS]}"
+ # Return unless at least one size aspect has been requested
+ [ "$__var_height" -o "$__var_width" ] || return $FAILURE
#
- # Enforce the minimum width for displaying the timebox
- #
- [ $width -ge $min_width ] || width=$min_width
-
- #
- # When using dialog(1), the timebox box is unique from other dialog(1)
- # boxes in-that the height passed should not accomodate the 6-lines
- # required to display the timebox. This does not apply to Xdialog(1).
- #
- # When using Xdialog(1), the height seems to have no effect. All values
- # provide the same results.
- #
- # NOTE: Also under dialog(1), because we can't predict whether the user
- # has disabled shadow's in their `$HOME/.dialogrc' file, we'll subtract
- # 7 rather than 6. This does not apply to Xdialog(1).
+ # Obtain/Adjust minimum and maximum thresholds
+ # NOTE: Function name appended to prevent __var_{height,width} values
+ # from becoming local (and thus preventing setvar from working).
#
+ local __max_height_tbox_size __max_width_tbox_size
+ f_dialog_max_size __max_height_tbox_size __max_width_tbox_size
+ __max_width_tbox_size=$(( $__max_width_tbox_size - 2 ))
+ # the timebox widget refuses to display if too wide
+ local __min_width
if [ "$USE_XDIALOG" ]; then
- height=0 # Autosize; all values produce same results
+ __min_width=40
else
- max_height=$(( $max_height - 7 ))
- height=$( echo "$prompt" | f_number_of_lines )
- height=$(( $height + 1 ))
- [ $height -le $max_height ] || height=$max_height
- [ "$prompt" ] && height=$(( $height + 1 ))
+ __min_width=20
+ __max_height_tbox_size=$(( \
+ $__max_height_tbox_size - $DIALOG_TIMEBOX_HEIGHT ))
+ # When using dialog(1), we can't predict whether the user has
+ # disabled shadow's in their `$HOME/.dialogrc' file, so we'll
+ # subtract one for the potential shadow around the widget
+ __max_height_tbox_size=$(( $__max_height_tbox_size - 1 ))
fi
- #
- # The timebox box refuses to display if too large.
- #
- max_width=$(( $max_width - 2 ))
- [ $width -le $max_width ] || width=$max_width
+ # Calculate height if desired
+ if [ "$__var_height" -a "$USE_XDIALOG" ]; then
+ # When using Xdialog(1), the height seems to have
+ # no effect. All values provide the same results.
+ setvar "$__var_height" 0 # autosize
+ elif [ "$__var_height" ]; then
+ local __height
+ __height=$( echo "$__prompt" | f_number_of_lines )
+ __height=$(( $__height ${__prompt:++1} + 1 ))
+
+ # Enforce maximum height, unless `-n' was passed
+ [ "$__constrain" -a $__height -gt $__max_height_tbox_size ] &&
+ __height=$__max_height_tbox_size
+
+ setvar "$__var_height" $__height
+ fi
+
+ # Calculate width if desired
+ if [ "$__var_width" ]; then
+ # NOTE: Function name appended to prevent __var_{height,width}
+ # values from becoming local (and thus preventing setvar
+ # from working).
+ local __width_tbox_size
+ f_dialog_infobox_size -n "" __width_tbox_size \
+ "$__title" "$__btitle" "$__prompt" "$__hline"
+
+ # Enforce the minimum width for displaying the timebox
+ if [ "$__constrain" ]; then
+ if [ $__width_tbox_size -lt $__min_width ]; then
+ __width_tbox_size=$__min_width
+ elif [ $__width_tbox_size -ge $__max_width_tbox_size ]
+ then
+ __width_tbox_size=$__max_width_tbox_size
+ fi
+ fi
+
+ setvar "$__var_width" $__width_tbox_size
+ fi
- # Return both
- echo "$height $width"
+ return $SUCCESS
}
############################################################ CLEAR FUNCTIONS
@@ -943,18 +1493,15 @@ f_dialog_clear()
#
f_dialog_info()
{
- local info_text="$*"
- local size="$( f_dialog_infobox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$info_text" )"
-
- eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- ${USE_XDIALOG:+--ignore-eof} \
- ${USE_XDIALOG:+--no-buttons} \
- --infobox \"\$info_text\" $size
+ local info_text="$*" height width
+ f_dialog_infobox_size height width \
+ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$info_text"
+ $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ ${USE_XDIALOG:+--ignore-eof} \
+ ${USE_XDIALOG:+--no-buttons} \
+ --infobox "$info_text" $height $width
}
# f_xdialog_info $info_text ...
@@ -965,23 +1512,20 @@ f_dialog_info()
#
f_xdialog_info()
{
- local info_text="$*"
- local size="$( f_dialog_infobox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$info_text" )"
-
- eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --no-close --no-buttons \
- --infobox \"\$info_text\" $size \
+ local info_text="$*" height width
+ f_dialog_infobox_size height width \
+ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$info_text"
+ $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --no-close --no-buttons \
+ --infobox "$info_text" $height $width \
-1 # timeout of -1 means abort when EOF on stdin
}
############################################################ MSGBOX FUNCTIONS
-# f_dialog_msgbox $msg_text ...
+# f_dialog_msgbox $msg_text [$hline]
#
# Throw up a dialog(1) msgbox. The msgbox remains until the user presses ENTER
# or ESC, acknowledging the modal dialog.
@@ -991,17 +1535,15 @@ f_xdialog_info()
#
f_dialog_msgbox()
{
- local msg_text="$*"
- local size="$( f_dialog_buttonbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg_text" )"
-
- eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$msg_text\" $size
+ local msg_text="$1" hline="$2" height width
+ f_dialog_buttonbox_size height width \
+ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" "$hline"
+ $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$hline" \
+ --ok-label "$msg_ok" \
+ --msgbox "$msg_text" $height $width
}
############################################################ TEXTBOX FUNCTIONS
@@ -1018,35 +1560,33 @@ f_dialog_msgbox()
f_dialog_textbox()
{
local file="$1"
- local contents retval size
+ local contents height width retval
contents=$( cat "$file" 2>&1 )
retval=$?
- size=$( f_dialog_buttonbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$contents" )
+ f_dialog_buttonbox_size height width \
+ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$contents"
if [ $retval -eq $SUCCESS ]; then
- eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --exit-label \"\$msg_ok\" \
- --no-cancel \
- --textbox \"\$file\" $size
+ $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --exit-label "$msg_ok" \
+ --no-cancel \
+ --textbox "$file" $height $width
else
- eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$contents\" $size
+ $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --ok-label "$msg_ok" \
+ --msgbox "$contents" $height $width
fi
}
############################################################ YESNO FUNCTIONS
-# f_dialog_yesno $msg_text ...
+# f_dialog_yesno $msg_text [$hline]
#
# Display a dialog(1) Yes/No prompt to allow the user to make some decision.
# The yesno prompt remains until the user presses ENTER or ESC, acknowledging
@@ -1057,37 +1597,34 @@ f_dialog_textbox()
#
f_dialog_yesno()
{
- local msg_text="$*"
- local hline="$hline_arrows_tab_enter"
+ local msg_text="$1" height width
+ local hline="${2-$hline_arrows_tab_enter}"
f_interactive || return 0 # If non-interactive, return YES all the time
- local size="$( f_dialog_buttonbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg_text" \
- "$hline" )"
+ f_dialog_buttonbox_size height width \
+ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" "$hline"
if [ "$USE_XDIALOG" ]; then
- eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_yes\" \
- --cancel-label \"\$msg_no\" \
- --yesno \"\$msg_text\" $size
+ $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$hline" \
+ --ok-label "$msg_yes" \
+ --cancel-label "$msg_no" \
+ --yesno "$msg_text" $height $width
else
- eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --yes-label \"\$msg_yes\" \
- --no-label \"\$msg_no\" \
- --yesno \"\$msg_text\" $size
+ $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$hline" \
+ --yes-label "$msg_yes" \
+ --no-label "$msg_no" \
+ --yesno "$msg_text" $height $width
fi
}
-# f_dialog_noyes $msg_text ...
+# f_dialog_noyes $msg_text [$hline]
#
# Display a dialog(1) No/Yes prompt to allow the user to make some decision.
# The noyes prompt remains until the user presses ENTER or ESC, acknowledging
@@ -1100,71 +1637,80 @@ f_dialog_yesno()
#
f_dialog_noyes()
{
- local msg_text="$*"
- local hline="$hline_arrows_tab_enter"
+ local msg_text="$1" height width
+ local hline="${2-$hline_arrows_tab_enter}"
f_interactive || return 1 # If non-interactive, return NO all the time
- local size="$( f_dialog_buttonbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg_text" \
- "$hline" )"
+ f_dialog_buttonbox_size height width \
+ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" "$hline"
if [ "$USE_XDIALOG" ]; then
- eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --default-no \
- --ok-label \"\$msg_yes\" \
- --cancel-label \"\$msg_no\" \
- --yesno \"\$msg_text\" $size
+ $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$hline" \
+ --default-no \
+ --ok-label "$msg_yes" \
+ --cancel-label "$msg_no" \
+ --yesno "$msg_text" $height $width
else
- eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --defaultno \
- --yes-label \"\$msg_yes\" \
- --no-label \"\$msg_no\" \
- --yesno \"\$msg_text\" $size
+ $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$hline" \
+ --defaultno \
+ --yes-label "$msg_yes" \
+ --no-label "$msg_no" \
+ --yesno "$msg_text" $height $width
fi
}
############################################################ INPUT FUNCTIONS
-# f_dialog_inputstr
+# f_dialog_inputstr_store [-s] $text
+#
+# Store some text from a dialog(1) inputbox to be retrieved later by
+# f_dialog_inputstr_fetch(). If the first argument is `-s', the text is
+# sanitized before being stored.
+#
+f_dialog_inputstr_store()
+{
+ local sanitize=
+ [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s
+ local text="$1"
+
+ # Sanitize the line before storing it if desired
+ [ "$sanitize" ] && f_dialog_line_sanitize text
+
+ setvar DIALOG_INPUTBOX_$$ "$text"
+}
+
+# f_dialog_inputstr_fetch [$var_to_set]
#
# Obtain the inputstr entered by the user from the most recently displayed
-# dialog(1) inputbox and clean up any temporary files/variables.
+# dialog(1) inputbox (previously stored with f_dialog_inputstr_store() above).
+# If $var_to_set is NULL or missing, output is printed to stdout (which is less
+# recommended due to performance degradation; in a loop for example).
#
-f_dialog_inputstr()
+f_dialog_inputstr_fetch()
{
- # Skip warnings and trim leading/trailing whitespace from user input
- eval echo \"\$DIALOG_INPUTBOX_$$\" | awk '
- BEGIN { found = 0 }
- {
- if ( ! found )
- {
- if ( $0 ~ /^$/ ) next
- if ( $0 ~ /^Gdk-WARNING \*\*:/ ) next
- found = 1
- }
- sub(/^[[:space:]]*/, "")
- sub(/[[:space:]]*$/, "")
- print
- }
- '
+ local __var_to_set="$1" __cp
+
+ debug= f_getvar DIALOG_INPUTBOX_$$ "${__var_to_set:-__cp}" # get data
setvar DIALOG_INPUTBOX_$$ "" # scrub memory in case data was sensitive
+
+ # Return the line on standard-out if desired
+ [ "$__var_to_set" ] || echo "$__cp"
+
return $SUCCESS
}
-# f_dialog_input $prompt [$init [$hline]]
+# f_dialog_input $var_to_set $prompt [$init [$hline]]
#
# Prompt the user with a dialog(1) inputbox to enter some value. The inputbox
# remains until the the user presses ENTER or ESC, or otherwise ends the
-# editing session, by selecting `Cancel' for example.
+# editing session (by selecting `Cancel' for example).
#
# If the user presses ENTER, the exit status is zero (success), otherwise if
# the user presses ESC the exit status is 255, or if the user chose Cancel, the
@@ -1175,62 +1721,154 @@ f_dialog_inputstr()
#
f_dialog_input()
{
- local prompt="$1" init="$2" hline="$3"
- local size="$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$prompt" \
- "$init" \
- "$hline" )"
-
- local opterm="--"
- [ "$USE_XDIALOG" ] && opterm=
-
- local dialog_input
- dialog_input=$(
- eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --inputbox \"\$prompt\" $size \
- $opterm \"\$init\" \
+ local __var_to_set="$1" __prompt="$2" __init="$3" __hline="$4"
+
+ # NOTE: Function name appended to prevent __var_{height,width} values
+ # from becoming local (and thus preventing setvar from working).
+ local __height_input __width_input
+ f_dialog_inputbox_size __height_input __width_input \
+ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" \
+ "$__prompt" "$__init" "$__hline"
+
+ local __opterm="--"
+ [ "$USE_XDIALOG" ] && __opterm=
+
+ local __dialog_input
+ __dialog_input=$(
+ $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$__hline" \
+ --ok-label "$msg_ok" \
+ --cancel-label "$msg_cancel" \
+ --inputbox "$__prompt" \
+ $__height_input $__width_input \
+ $__opterm "$__init" \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
- local retval=$?
+ local __retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_input"
- f_dialog_inputstr
+ # Remove warnings and leading/trailing whitespace from user input
+ f_dialog_line_sanitize __dialog_input
- return $retval
+ setvar "$__var_to_set" "$__dialog_input"
+ return $__retval
}
############################################################ MENU FUNCTIONS
-# f_dialog_menutag
+# f_dialog_menutag_store [-s] $text
+#
+# Store some text from a dialog(1) menu to be retrieved later by
+# f_dialog_menutag_fetch(). If the first argument is `-s', the text is
+# sanitized before being stored.
+#
+f_dialog_menutag_store()
+{
+ local sanitize=
+ [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s
+ local text="$1"
+
+ # Sanitize the menutag before storing it if desired
+ [ "$sanitize" ] && f_dialog_data_sanitize text
+
+ setvar DIALOG_MENU_$$ "$text"
+}
+
+# f_dialog_menutag_fetch [$var_to_set]
#
# Obtain the menutag chosen by the user from the most recently displayed
-# dialog(1) menu and clean up any temporary files/variables.
+# dialog(1) menu (previously stored with f_dialog_menutag_store() above). If
+# $var_to_set is NULL or missing, output is printed to stdout (which is less
+# recommended due to performance degradation; in a loop for example).
#
-f_dialog_menutag()
+f_dialog_menutag_fetch()
{
- # Skip warnings
- eval echo \"\$DIALOG_MENU_$$\" | awk '
- BEGIN { found = 0 }
- {
- if ( found ) # ... just spew
- {
- print
- next
- }
- if ( $0 ~ /^$/ ) next
- if ( $0 ~ /^Gdk-WARNING \*\*:/ ) next
- found = 1
- print
- }
- '
+ local __var_to_set="$1" __cp
+
+ debug= f_getvar DIALOG_MENU_$$ "${__var_to_set:-__cp}" # get the data
setvar DIALOG_MENU_$$ "" # scrub memory in case data was sensitive
+
+ # Return the data on standard-out if desired
+ [ "$__var_to_set" ] || echo "$__cp"
+
+ return $SUCCESS
+}
+
+# f_dialog_menuitem_store [-s] $text
+#
+# Store the item from a dialog(1) menu (see f_dialog_menutag2item()) to be
+# retrieved later by f_dialog_menuitem_fetch(). If the first argument is `-s',
+# the text is sanitized before being stored.
+#
+f_dialog_menuitem_store()
+{
+ local sanitize=
+ [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s
+ local text="$1"
+
+ # Sanitize the menuitem before storing it if desired
+ [ "$sanitize" ] && f_dialog_data_sanitize text
+
+ setvar DIALOG_MENUITEM_$$ "$text"
+}
+
+# f_dialog_menuitem_fetch [$var_to_set]
+#
+# Obtain the menuitem chosen by the user from the most recently displayed
+# dialog(1) menu (previously stored with f_dialog_menuitem_store() above). If
+# $var_to_set is NULL or missing, output is printed to stdout (which is less
+# recommended due to performance degradation; in a loop for example).
+#
+f_dialog_menuitem_fetch()
+{
+ local __var_to_set="$1" __cp
+
+ debug= f_getvar DIALOG_MENUITEM_$$ "${__var_to_set:-__cp}" # get data
+ setvar DIALOG_MENUITEM_$$ "" # scrub memory in case data was sensitive
+
+ # Return the data on standard-out if desired
+ [ "$__var_to_set" ] || echo "$__cp"
+
+ return $SUCCESS
+}
+
+# f_dialog_default_store [-s] $text
+#
+# Store some text to be used later as the --default-item argument to dialog(1)
+# (or Xdialog(1)) for --menu, --checklist, and --radiolist widgets. Retrieve
+# the text later with f_dialog_menutag_fetch(). If the first argument is `-s',
+# the text is sanitized before being stored.
+#
+f_dialog_default_store()
+{
+ local sanitize=
+ [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s
+ local text="$1"
+
+ # Sanitize the defaulitem before storing it if desired
+ [ "$sanitize" ] && f_dialog_data_sanitize text
+
+ setvar DEFAULTITEM_$$ "$text"
+}
+
+# f_dialog_default_fetch [$var_to_set]
+#
+# Obtain text to be used with the --default-item argument of dialog(1) (or
+# Xdialog(1)) (previously stored with f_dialog_default_store() above). If
+# $var_to_set is NULL or missing, output is printed to stdout (which is less
+# recommended due to performance degradation; in a loop for example).
+#
+f_dialog_default_fetch()
+{
+ local __var_to_set="$1" __cp
+
+ debug= f_getvar DEFAULTITEM_$$ "${__var_to_set:-__cp}" # get the data
+ setvar DEFAULTITEM_$$ "" # scrub memory in case data was sensitive
+
+ # Return the data on standard-out if desired
+ [ "$__var_to_set" ] || echo "$__cp"
+
return $SUCCESS
}
@@ -1385,6 +2023,12 @@ f_dialog_menutag2index_with_help()
# that (while running as root) sudo(8) authentication is
# required to proceed.
#
+# Also reads ~/.dialogrc for the following information:
+#
+# NO_SHADOW Either NULL or Non-NULL. If use_shadow is OFF (case-
+# insensitive) in ~/.dialogrc this is set to "1" (otherwise
+# unset).
+#
f_dialog_init()
{
DIALOG_SELF_INITIALIZE=
@@ -1395,24 +2039,38 @@ f_dialog_init()
eval exec $DIALOG_TERMINAL_PASSTHRU_FD\>\&1
#
+ # Add `-S' and `-X' to the list of standard arguments supported by all
+ #
+ case "$GETOPTS_STDARGS" in
+ *SX*) : good ;; # already present
+ *) GETOPTS_STDARGS="${GETOPTS_STDARGS}SX"
+ esac
+
+ #
# Process stored command-line arguments
#
- SECURE=$( set -- "$ARGV"
- while getopts S flag > /dev/null; do
+ f_dprintf "f_dialog_init: ARGV=[%s] GETOPTS_STDARGS=[%s]" \
+ "$ARGV" "$GETOPTS_STDARGS"
+ SECURE=$( set -- $ARGV
+ while getopts \
+ "$GETOPTS_STDARGS$GETOPTS_EXTRA$GETOPTS_ALLFLAGS" \
+ flag > /dev/null; do
case "$flag" in
- S) echo 1;;
- \?) continue;;
+ S) echo 1 ;;
esac
done
)
- USE_XDIALOG=$( set -- "$ARGV"
- while getopts SX flag > /dev/null; do
+ USE_XDIALOG=$( set -- $ARGV
+ while getopts \
+ "$GETOPTS_STDARGS$GETOPTS_EXTRA$GETOPTS_ALLFLAGS" \
+ flag > /dev/null; do
case "$flag" in
- S|X) echo 1;;
- \?) continue;;
+ S|X) echo 1 ;;
esac
done
)
+ f_dprintf "f_dialog_init: SECURE=[%s] USE_XDIALOG=[%s]" \
+ "$SECURE" "$USE_XDIALOG"
#
# Process `-X' command-line option
@@ -1424,12 +2082,28 @@ f_dialog_init()
#
if ! f_have $DIALOG; then
unset USE_XDIALOG
- failed_dialog="$DIALOG"
+ local failed_dialog="$DIALOG"
DIALOG=dialog
f_die 1 "$msg_no_such_file_or_directory" "$pgm" "$failed_dialog"
fi
#
+ # Read ~/.dialogrc (unless using Xdialog(1)) for properties
+ #
+ if [ -f ~/.dialogrc -a ! "$USE_XDIALOG" ]; then
+ eval "$(
+ awk -v param=use_shadow -v expect=OFF \
+ -v set="NO_SHADOW=1" '
+ !/^[[:space:]]*(#|$)/ && \
+ tolower($1) ~ "^"param"(=|$)" && \
+ /[^#]*=/ {
+ sub(/^[^=]*=[[:space:]]*/, "")
+ if ( toupper($1) == expect ) print set";"
+ }' ~/.dialogrc
+ )"
+ fi
+
+ #
# If we're already running as root but we got there by way of sudo(8)
# and we have X11, we should merge the xauth(1) credentials from our
# original user.
@@ -1445,7 +2119,7 @@ f_dialog_init()
f_die 1 "$msg_no_such_file_or_directory" "$pgm" "xauth"
fi
HOSTNAME=$(hostname)
- displaynum="${DISPLAY#*:}"
+ local displaynum="${DISPLAY#*:}"
eval xauth -if \~$SUDO_USER/.Xauthority extract - \
\"\$HOSTNAME/unix:\$displaynum\" \
\"\$HOSTNAME:\$displaynum\" | sudo sh -c 'xauth -ivf \
@@ -1457,18 +2131,21 @@ f_dialog_init()
# gracefully
#
if [ "$USE_XDIALOG" ]; then
+ local maxsize
if ! maxsize=$( LANG= LC_ALL= $DIALOG --print-maxsize 2>&1 )
then
# Xdialog(1) failed, fall back to dialog(1)
unset USE_XDIALOG
- size=$( f_dialog_buttonbox_size "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$maxsize" "" )
- eval dialog \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$maxsize\" $size
+
+ # Display the error message produced by Xdialog(1)
+ local height width
+ f_dialog_buttonbox_size height width \
+ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$maxsize"
+ dialog \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --ok-label "$msg_ok" \
+ --msgbox "$maxsize" $height $width
exit $FAILURE
fi
@@ -1480,7 +2157,6 @@ f_dialog_init()
echo $height $width
)
- unset maxsize
fi
#
@@ -1490,10 +2166,9 @@ f_dialog_init()
# --title with Xdialog(1)).
#
if [ "$USE_XDIALOG" ]; then
- _DIALOG_TITLE="$DIALOG_TITLE"
+ local _DIALOG_TITLE="$DIALOG_TITLE"
DIALOG_TITLE="$DIALOG_BACKTITLE"
DIALOG_BACKTITLE="$_DIALOG_TITLE"
- unset _DIALOG_TITLE
fi
f_dprintf "f_dialog_init: dialog(1) API initialized."
diff --git a/usr.sbin/bsdconfig/share/media/Makefile b/usr.sbin/bsdconfig/share/media/Makefile
index ebd7c96..6436749 100644
--- a/usr.sbin/bsdconfig/share/media/Makefile
+++ b/usr.sbin/bsdconfig/share/media/Makefile
@@ -4,8 +4,8 @@ NO_OBJ=
FILESDIR= ${SHAREDIR}/bsdconfig/media
FILES= any.subr cdrom.subr common.subr directory.subr dos.subr \
- floppy.subr ftp.subr httpproxy.subr network.subr nfs.subr \
- options.subr tcpip.subr ufs.subr usb.subr
+ floppy.subr ftp.subr http.subr httpproxy.subr network.subr \
+ nfs.subr options.subr tcpip.subr ufs.subr usb.subr
beforeinstall:
mkdir -p ${DESTDIR}${FILESDIR}
diff --git a/usr.sbin/bsdconfig/share/media/any.subr b/usr.sbin/bsdconfig/share/media/any.subr
index f64710f..3675713 100644
--- a/usr.sbin/bsdconfig/share/media/any.subr
+++ b/usr.sbin/bsdconfig/share/media/any.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_ANY_SUBR" ]; then _MEDIA_ANY_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_ANY_SUBR" ]; then _MEDIA_ANY_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -32,17 +32,18 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/any.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/struct.subr
f_include $BSDCFG_SHARE/media/cdrom.subr
f_include $BSDCFG_SHARE/media/directory.subr
f_include $BSDCFG_SHARE/media/dos.subr
f_include $BSDCFG_SHARE/media/floppy.subr
f_include $BSDCFG_SHARE/media/ftp.subr
+f_include $BSDCFG_SHARE/media/http.subr
f_include $BSDCFG_SHARE/media/httpproxy.subr
f_include $BSDCFG_SHARE/media/nfs.subr
f_include $BSDCFG_SHARE/media/options.subr
f_include $BSDCFG_SHARE/media/ufs.subr
f_include $BSDCFG_SHARE/media/usb.subr
+f_include $BSDCFG_SHARE/struct.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr
@@ -68,15 +69,12 @@ f_media_get_type()
local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
f_dialog_title_restore
local prompt="$msg_choose_installation_media_description"
- local hline="$hline_choose_help_for_more_information_on_media_types"
- local menu_list size
-
- menu_list="
- '1 $msg_cd_dvd' '$msg_install_from_a_freebsd_cd_dvd'
- '2 $msg_ftp' '$msg_install_from_an_ftp_server'
- '3 $msg_ftp_passive'
- '$msg_install_from_an_ftp_server_thru_firewall'
- '4 $msg_http' '$msg_install_from_an_ftp_server_thru_proxy'
+ local menu_list="
+ '1 $msg_cd_dvd' '$msg_install_from_a_freebsd_cd_dvd'
+ '2 $msg_ftp' '$msg_install_from_an_ftp_server'
+ '3 $msg_http_proxy'
+ '$msg_install_from_an_ftp_server_thru_proxy'
+ '4 $msg_http_direct' '$msg_install_from_an_http_server'
'5 $msg_directory' '$msg_install_from_the_existing_filesystem'
'6 $msg_nfs' '$msg_install_over_nfs'
'7 $msg_dos' '$msg_install_from_a_dos_partition'
@@ -85,34 +83,34 @@ f_media_get_type()
'A $msg_usb' '$msg_install_from_a_usb_drive'
'X $msg_options' '$msg_view_set_various_media_options'
" # END-QUOTE
+ local hline="$hline_choose_help_for_more_information_on_media_types"
- size=$( eval f_dialog_menu_size \
- \"\$title\" \
- \"\$btitle\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$title\" \
+ \"\$btitle\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+ local mtag
while :; do
- dialog_menu=$( eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --help-button \
- --help-label \"\$msg_help\" \
- ${USE_XDIALOG:+--help \"\"} \
- --menu \"\$prompt\" $size $menu_list \
+ mtag=$( eval $DIALOG \
+ --title \"\$title\" \
+ --backtitle \"\$btitle\" \
+ --hline \"\$hline\" \
+ --ok-label \"\$msg_ok\" \
+ --cancel-label \"\$msg_cancel\" \
+ --help-button \
+ --help-label \"\$msg_help\" \
+ ${USE_XDIALOG:+--help \"\"} \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
-
- local mtag
- mtag=$( f_dialog_menutag )
+ f_dialog_data_sanitize mtag
f_dprintf "retval=%s mtag=[%s]" $retval "$mtag"
if [ $retval -eq 2 ]; then
@@ -125,9 +123,9 @@ f_media_get_type()
case "$mtag" in
?" $msg_cd_dvd") f_media_set_cdrom ;;
- ?" $msg_ftp") f_media_set_ftp_active ;;
- ?" $msg_ftp_passive") f_media_set_ftp_passive ;;
- ?" $msg_http") f_media_set_http_proxy ;;
+ ?" $msg_ftp") f_media_set_ftp ;;
+ ?" $msg_http_proxy") f_media_set_http_proxy ;;
+ ?" $msg_http_direct") f_media_set_http ;;
?" $msg_directory") f_media_set_directory ;;
?" $msg_dos") f_media_set_dos ;;
?" $msg_nfs") f_media_set_nfs ;;
diff --git a/usr.sbin/bsdconfig/share/media/cdrom.subr b/usr.sbin/bsdconfig/share/media/cdrom.subr
index f22ebd2..cd68029 100644
--- a/usr.sbin/bsdconfig/share/media/cdrom.subr
+++ b/usr.sbin/bsdconfig/share/media/cdrom.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_CDROM_SUBR" ]; then _MEDIA_CDROM_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_CDROM_SUBR" ]; then _MEDIA_CDROM_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,11 +31,11 @@ if [ ! "$_MEDIA_CDROM_SUBR" ]; then _MEDIA_CDROM_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/cdrom.subr
-f_include $BSDCFG_SHARE/struct.subr
f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/variable.subr
f_include $BSDCFG_SHARE/media/common.subr
+f_include $BSDCFG_SHARE/struct.subr
+f_include $BSDCFG_SHARE/variable.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr
@@ -61,7 +61,7 @@ f_media_set_cdrom()
ndevs=$( set -- $devs; echo $# )
if [ ${ndevs:=0} -eq 0 ]; then
- f_interactive && f_dialog_msgbox "$msg_no_cd_dvd_devices_found"
+ f_interactive && f_show_msg "$msg_no_cd_dvd_devices_found"
return $FAILURE
elif [ $ndevs -gt 1 ]; then
local title="$msg_choose_a_cd_dvd_type"
@@ -144,19 +144,21 @@ f_media_init_cdrom()
return $SUCCESS
}
-# f_media_get_cdrom $device $file [$probe_only]
+# f_media_get_cdrom $device $file [$probe_type]
#
-# Returns data from $file on a mounted CDROM device. Similar to cat(1).
-# $probe_only is currently unused by this media type.
+# Returns data from $file on a mounted CDROM device. Similar to cat(1). If
+# $probe_type is present and non-NULL, returns success if $file exists. If
+# $probe_type is equal to $PROBE_SIZE, prints the size of $file in bytes to
+# standard-out.
#
f_media_get_cdrom()
{
- local dev="$1" file="$2" probe_only="$3"
+ local dev="$1" file="$2" probe_type="$3"
- f_dprintf "f_media_get_cdrom: dev=[%s] file=[%s] probe_only=%s" \
- "$dev" "$file" "$probe_only"
+ f_dprintf "f_media_get_cdrom: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
- f_media_generic_get "$MOUNTPOINT" "$file"
+ f_media_generic_get "$MOUNTPOINT" "$file" "$probe_type"
}
# f_media_shutdown_cdrom $device
diff --git a/usr.sbin/bsdconfig/share/media/common.subr b/usr.sbin/bsdconfig/share/media/common.subr
index 589bbdc..495aca7 100644
--- a/usr.sbin/bsdconfig/share/media/common.subr
+++ b/usr.sbin/bsdconfig/share/media/common.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_COMMON_SUBR" ]; then _MEDIA_COMMON_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_COMMON_SUBR" ]; then _MEDIA_COMMON_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,8 +31,9 @@ if [ ! "$_MEDIA_COMMON_SUBR" ]; then _MEDIA_COMMON_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/common.subr
-f_include $BSDCFG_SHARE/struct.subr
f_include $BSDCFG_SHARE/device.subr
+f_include $BSDCFG_SHARE/media/any.subr
+f_include $BSDCFG_SHARE/struct.subr
############################################################ GLOBALS
@@ -41,6 +42,13 @@ f_include $BSDCFG_SHARE/device.subr
#
MOUNTPOINT=/dist
+#
+# Media probe values to use for `f_media_get_TYPE media $file $PROBE' or
+# `f_device_get media $file $PROBE' (where $PROBE is one of the below values).
+#
+PROBE_EXIST=1
+PROBE_SIZE=2
+
############################################################ FUNCTIONS
# f_media_open
@@ -49,6 +57,7 @@ MOUNTPOINT=/dist
#
f_media_open()
{
+ f_dprintf "f_media_open: Verifying and initiliazing media device"
{ # Verify and initialize device media if-defined
f_struct device_media &&
f_media_verify &&
@@ -63,6 +72,7 @@ f_media_open()
#
f_media_close()
{
+ f_dprintf "f_media_close: Shutting down media device"
f_struct device_media &&
f_device_shutdown media
f_struct_free device_media
@@ -76,17 +86,26 @@ f_media_close()
#
f_media_verify()
{
+ f_dprintf "f_media_verify: Verifying media device"
f_struct device_media || f_media_get_type
}
-# f_media_generic_get $base $file
+# f_media_generic_get $base $file [$probe_type]
#
-# A generic open which follows a well-known "path" of places to look.
+# A generic open which follows a well-known "path" of places to look. If
+# $probe_type is present and non-NULL, returns success if $file exists. If
+# $probe_type is equal to $PROBE_SIZE, prints the size of $file in bytes to
+# standard-out.
#
f_media_generic_get()
{
- local base="$1" file="$2" rel path
+ local base="$1" file="$2" probe_type="$3"
+
+ local fname=f_media_generic_get
+ f_dprintf "%s: base=[%s] files=[%s] probe_type=%s" \
+ $fname "$base" "$file" "$probe_type"
+ local rel path
f_getvar $VAR_RELNAME rel
for path in \
"$base/$file" \
@@ -95,10 +114,41 @@ f_media_generic_get()
"$base/$rel/$file" \
; do
if [ -f "$path" -a -r "$path" ]; then
+ f_dprintf "%s: file exists path=[%s]" $fname "$path"
+ if [ "$probe_type" = "$PROBE_SIZE" ]; then
+ local size
+ if ! size=$( stat -f %z "$path" 2>&1 ); then
+ f_dprintf "stat: %s" "$size"
+ echo "-1"
+ else
+ f_isinteger "$size" || size=-1
+ echo $size
+ fi
+ fi
+ [ "$probe_type" ] && return $SUCCESS
cat "$path"
return
fi
done
+
+ path="$base/releases/$rel/$file" # Final path to try
+ if [ -f "$path" -a -r "$path" ]; then
+ f_dprintf "%s: file exists path=[%s]" $fname "$path"
+ if [ "$probe_type" = "$PROBE_SIZE" ]; then
+ local size
+ if ! size=$( stat -f %z "$path" 2>&1 ); then
+ f_dprintf "stat: %s" "$size"
+ echo "-1"
+ else
+ f_isinteger "$size" || size=-1
+ echo $size
+ fi
+ fi
+ [ "$probe_type" ] && return $SUCCESS
+ elif [ "$probe_type" ]; then
+ [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1"
+ return $FAILURE
+ fi
cat "$base/releases/$rel/$file" # Final path to try
}
diff --git a/usr.sbin/bsdconfig/share/media/directory.subr b/usr.sbin/bsdconfig/share/media/directory.subr
index 3831140..3f46293 100644
--- a/usr.sbin/bsdconfig/share/media/directory.subr
+++ b/usr.sbin/bsdconfig/share/media/directory.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_DIRECTORY_SUBR" ]; then _MEDIA_DIRECTORY_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_DIRECTORY_SUBR" ]; then _MEDIA_DIRECTORY_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,11 +31,11 @@ if [ ! "$_MEDIA_DIRECTORY_SUBR" ]; then _MEDIA_DIRECTORY_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/directory.subr
-f_include $BSDCFG_SHARE/struct.subr
f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/variable.subr
f_include $BSDCFG_SHARE/media/common.subr
+f_include $BSDCFG_SHARE/struct.subr
+f_include $BSDCFG_SHARE/variable.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr
@@ -69,6 +69,7 @@ f_media_set_directory()
[ "$path" ] || return $FAILURE
f_struct_new DEVICE device_directory
+ device_directory set name "$path"
device_directory set get f_media_get_directory
device_directory set init f_media_init_directory
device_directory set shutdown f_media_shutdown_directory
@@ -114,20 +115,22 @@ f_media_init_directory()
return $SUCCESS
}
-# f_media_get_directory $device $file [$probe_only]
+# f_media_get_directory $device $file [$probe_type]
#
# Returns data from $file in the existing/current filesystem. Similar to
-# cat(1). $probe_only is currently unused by this media type.
+# cat(1). If $probe_type is present and non-NULL, returns success if $file
+# exists. If $probe_type is equal to $PROBE_SIZE, prints the size of $file in
+# bytes to standard-out.
#
f_media_get_directory()
{
- local dev="$1" file="$2" probe_only="$3" path
+ local dev="$1" file="$2" probe_type="$3" path
- f_dprintf "f_media_get_directory: dev=[%s] file=[%s] probe_only=%s" \
- "$dev" "$file" "$probe_only"
+ f_dprintf "f_media_get_directory: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
device_$dev get private path
- f_media_generic_get "$path" "$file"
+ f_media_generic_get "$path" "$file" "$probe_type"
}
# f_media_shutdown_directory $device
diff --git a/usr.sbin/bsdconfig/share/media/dos.subr b/usr.sbin/bsdconfig/share/media/dos.subr
index 3e59fb6..440c5c9 100644
--- a/usr.sbin/bsdconfig/share/media/dos.subr
+++ b/usr.sbin/bsdconfig/share/media/dos.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_DOS_SUBR" ]; then _MEDIA_DOS_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_DOS_SUBR" ]; then _MEDIA_DOS_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,11 +31,11 @@ if [ ! "$_MEDIA_DOS_SUBR" ]; then _MEDIA_DOS_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/dos.subr
-f_include $BSDCFG_SHARE/struct.subr
f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/variable.subr
f_include $BSDCFG_SHARE/media/common.subr
+f_include $BSDCFG_SHARE/struct.subr
+f_include $BSDCFG_SHARE/variable.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr
@@ -59,7 +59,7 @@ f_media_set_dos()
ndevs=$( set -- $devs; echo $# )
if [ ${ndevs:=0} -eq 0 ]; then
- f_dialog_msgbox "$msg_no_dos_primary_partitions_found"
+ f_show_msg "$msg_no_dos_primary_partitions_found"
return $FAILURE
elif [ $ndevs -gt 1 ]; then
local title="$msg_choose_a_dos_partition"
@@ -122,19 +122,21 @@ f_media_init_dos()
return $SUCCESS
}
-# f_media_get_dos $device $file [$probe_only]
+# f_media_get_dos $device $file [$probe_type]
#
# Returns data from $file on a mounted DOS partition device. Similar to cat(1).
-# $probe_only is currently unused by this media type.
+# If $probe_type is present and non-NULL, returns success if $file exists. If
+# $probe_type is equal to $PROBE_SIZE, prints the size of $file in bytes to
+# standard-out.
#
f_media_get_dos()
{
- local dev="$1" file="$2" probe_only="$3"
+ local dev="$1" file="$2" probe_type="$3"
- f_dprintf "f_media_get_dos: dev=[%s] file=[%s] probe_only=%s" \
- "$dev" "$file" "$probe_only"
+ f_dprintf "f_media_get_dos: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
- f_media_generic_get "$MOUNTPOINT" "$file"
+ f_media_generic_get "$MOUNTPOINT" "$file" "$probe_type"
}
# f_media_shutdown_dos $device
diff --git a/usr.sbin/bsdconfig/share/media/floppy.subr b/usr.sbin/bsdconfig/share/media/floppy.subr
index c874c61..eb6bc5e 100644
--- a/usr.sbin/bsdconfig/share/media/floppy.subr
+++ b/usr.sbin/bsdconfig/share/media/floppy.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_FLOPPY_SUBR" ]; then _MEDIA_FLOPPY_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_FLOPPY_SUBR" ]; then _MEDIA_FLOPPY_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,11 +31,11 @@ if [ ! "$_MEDIA_FLOPPY_SUBR" ]; then _MEDIA_FLOPPY_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/floppy.subr
-f_include $BSDCFG_SHARE/struct.subr
f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/variable.subr
f_include $BSDCFG_SHARE/media/common.subr
+f_include $BSDCFG_SHARE/struct.subr
+f_include $BSDCFG_SHARE/variable.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr
@@ -60,7 +60,7 @@ f_media_set_floppy()
ndevs=$( set -- $devs; echo $# )
if [ ${ndevs:=0} -eq 0 ]; then
- f_interactive && f_dialog_msgbox "$msg_no_floppy_devices_found"
+ f_interactive && f_show_msg "$msg_no_floppy_devices_found"
return $FAILURE
elif [ $ndevs -gt 1 ]; then
local title="$msg_choose_a_floppy_drive"
@@ -144,17 +144,19 @@ f_media_init_floppy()
return $SUCCESS
}
-# f_media_get_floppy $device $file [$probe_only]
+# f_media_get_floppy $device $file [$probe_type]
#
# Returns data from $file on a mounted Floppy disk device. Similar to cat(1).
-# If $probe_only is present and non-null, limits retries to zero.
+# If $probe_type is present and non-NULL, limits retries to zero and returns
+# success if $file exists. If $probe_type is equal to $PROBE_SIZE, prints the
+# size of $file in bytes to standard-out.
#
f_media_get_floppy()
{
- local dev="$1" file="$2" probe_only="$3"
+ local dev="$1" file="$2" probe_type="$3"
- f_dprintf "f_media_get_floppy: dev=[%s] file=[%s] probe_only=%s" \
- "$dev" "$file" "$probe_only"
+ f_dprintf "f_media_get_floppy: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
#
# floppies don't use f_media_generic_get() because it's too expensive
@@ -166,11 +168,13 @@ f_media_get_floppy()
local fp="${mp:=$MOUNTPOINT}/$file"
if ! [ -f "$fp" -a -r "$fp" ]; then
local nretries=4
- [ "$probe_only" ] && return $FAILURE
+ [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1"
+ [ "$probe_type" ] && return $FAILURE
while ! [ -f "$fp" -a -r "$fp" ]; do
if [ $nretries -eq 0 ]; then
f_show_msg "$msg_failed_to_get_floppy_file" \
"$fp"
+ [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1"
return $FAILURE
fi
FLOPPY_DISTWANTED="$fp"
@@ -179,6 +183,16 @@ f_media_get_floppy()
nretries=$(( $nretries - 1 ))
done
fi
+ #
+ # If we reach here, $file exists
+ #
+ if [ "$probe_type" = "$PROBE_SIZE" ]; then
+ local size
+ size=$( stat -f %z "$fp" 2>&1 ) || f_dprintf "stat: %s" "$size"
+ f_isinteger "$size" || size=-1
+ echo "$size"
+ fi
+ [ "$probe_type" ] && return $SUCCESS
cat "$fp"
}
diff --git a/usr.sbin/bsdconfig/share/media/ftp.subr b/usr.sbin/bsdconfig/share/media/ftp.subr
index ecc7724..dfdff26 100644
--- a/usr.sbin/bsdconfig/share/media/ftp.subr
+++ b/usr.sbin/bsdconfig/share/media/ftp.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_FTP_SUBR" ]; then _MEDIA_FTP_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_FTP_SUBR" ]; then _MEDIA_FTP_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,14 +31,13 @@ if [ ! "$_MEDIA_FTP_SUBR" ]; then _MEDIA_FTP_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/ftp.subr
-f_include $BSDCFG_SHARE/struct.subr
f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/strings.subr
-f_include $BSDCFG_SHARE/variable.subr
f_include $BSDCFG_SHARE/media/common.subr
f_include $BSDCFG_SHARE/media/tcpip.subr
-f_include $BSDCFG_SHARE/media/network.subr
+f_include $BSDCFG_SHARE/strings.subr
+f_include $BSDCFG_SHARE/struct.subr
+f_include $BSDCFG_SHARE/variable.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr
@@ -72,20 +71,16 @@ f_dialog_menu_media_ftp()
f_dialog_title "$msg_please_select_a_freebsd_ftp_distribution_site"
local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
f_dialog_title_restore
-
local prompt="$msg_please_select_the_site_closest_to_you_or_other"
- local hline="$msg_select_a_site_thats_close"
local menu_list="
'$msg_main_site' 'ftp.freebsd.org'
'URL' '$msg_specify_some_other_ftp_site'
- '$msg_snapshots_server_japan'
- 'snapshots.jp.freebsd.org'
- '$msg_snapshots_server_sweden'
- 'snapshots.se.freebsd.org'
'IPv6 $msg_main_site' 'ftp.freebsd.org'
+ ' IPv6 $msg_france' 'ftp4.fr.freebsd.org'
+ ' IPv6 $msg_france #8' 'ftp8.fr.freebsd.org'
' IPv6 $msg_ireland' 'ftp3.ie.freebsd.org'
- ' IPv6 $msg_israel' 'ftp.il.freebsd.org'
' IPv6 $msg_japan' 'ftp2.jp.freebsd.org'
+ ' IPv6 $msg_sweden' 'ftp4.se.freebsd.org'
' IPv6 $msg_usa' 'ftp4.us.freebsd.org'
' IPv6 $msg_turkey' 'ftp2.tr.freebsd.org'
'$msg_primary' 'ftp1.freebsd.org'
@@ -95,44 +90,34 @@ f_dialog_menu_media_ftp()
' $msg_primary #5' 'ftp5.freebsd.org'
' $msg_primary #6' 'ftp6.freebsd.org'
' $msg_primary #7' 'ftp7.freebsd.org'
- ' $msg_primary #8' 'ftp8.freebsd.org'
- ' $msg_primary #9' 'ftp9.freebsd.org'
' $msg_primary #10' 'ftp10.freebsd.org'
' $msg_primary #11' 'ftp11.freebsd.org'
' $msg_primary #12' 'ftp12.freebsd.org'
' $msg_primary #13' 'ftp13.freebsd.org'
' $msg_primary #14' 'ftp14.freebsd.org'
- '$msg_argentina' 'ftp.ar.freebsd.org'
+ '$msg_armenia' 'ftp1.am.freebsd.org'
'$msg_australia' 'ftp.au.freebsd.org'
' $msg_australia #2' 'ftp2.au.freebsd.org'
' $msg_australia #3' 'ftp3.au.freebsd.org'
'$msg_austria' 'ftp.at.freebsd.org'
- ' $msg_austria #2' 'ftp2.at.freebsd.org'
- '$msg_brazil' 'ftp.br.freebsd.org'
- ' $msg_brazil #2' 'ftp2.br.freebsd.org'
+ '$msg_brazil' 'ftp2.br.freebsd.org'
' $msg_brazil #3' 'ftp3.br.freebsd.org'
' $msg_brazil #4' 'ftp4.br.freebsd.org'
- ' $msg_brazil #5' 'ftp5.br.freebsd.org'
- ' $msg_brazil #6' 'ftp6.br.freebsd.org'
- ' $msg_brazil #7' 'ftp7.br.freebsd.org'
'$msg_canada' 'ftp.ca.freebsd.org'
'$msg_china' 'ftp.cn.freebsd.org'
- ' $msg_china #2' 'ftp2.cn.freebsd.org'
- '$msg_croatia' 'ftp.hr.freebsd.org'
'$msg_czech_republic' 'ftp.cz.freebsd.org'
'$msg_denmark' 'ftp.dk.freebsd.org'
- ' $msg_denmark #2' 'ftp2.dk.freebsd.org'
'$msg_estonia' 'ftp.ee.freebsd.org'
'$msg_finland' 'ftp.fi.freebsd.org'
'$msg_france' 'ftp.fr.freebsd.org'
- ' $msg_france #2' 'ftp2.fr.freebsd.org'
' $msg_france #3' 'ftp3.fr.freebsd.org'
+ ' $msg_france #4' 'ftp4.fr.freebsd.org'
' $msg_france #5' 'ftp5.fr.freebsd.org'
' $msg_france #6' 'ftp6.fr.freebsd.org'
+ ' $msg_france #7' 'ftp7.fr.freebsd.org'
' $msg_france #8' 'ftp8.fr.freebsd.org'
'$msg_germany' 'ftp.de.freebsd.org'
' $msg_germany #2' 'ftp2.de.freebsd.org'
- ' $msg_germany #3' 'ftp3.de.freebsd.org'
' $msg_germany #4' 'ftp4.de.freebsd.org'
' $msg_germany #5' 'ftp5.de.freebsd.org'
' $msg_germany #6' 'ftp6.de.freebsd.org'
@@ -140,11 +125,8 @@ f_dialog_menu_media_ftp()
' $msg_germany #8' 'ftp8.de.freebsd.org'
'$msg_greece' 'ftp.gr.freebsd.org'
' $msg_greece #2' 'ftp2.gr.freebsd.org'
- '$msg_hungary' 'ftp.hu.freebsd.org'
'$msg_iceland' 'ftp.is.freebsd.org'
- '$msg_ireland' 'ftp.ie.freebsd.org'
- ' $msg_ireland #2' 'ftp2.ie.freebsd.org'
- ' $msg_ireland #3' 'ftp3.ie.freebsd.org'
+ '$msg_ireland' 'ftp3.ie.freebsd.org'
'$msg_israel' 'ftp.il.freebsd.org'
'$msg_italy' 'ftp.it.freebsd.org'
'$msg_japan' 'ftp.jp.freebsd.org'
@@ -158,105 +140,88 @@ f_dialog_menu_media_ftp()
' $msg_japan #9' 'ftp9.jp.freebsd.org'
'$msg_korea' 'ftp.kr.freebsd.org'
' $msg_korea #2' 'ftp2.kr.freebsd.org'
+ '$msg_latvia' 'ftp.lv.freebsd.org'
'$msg_lithuania' 'ftp.lt.freebsd.org'
'$msg_netherlands' 'ftp.nl.freebsd.org'
' $msg_netherlands #2' 'ftp2.nl.freebsd.org'
+ '$msg_new_zealand' 'ftp.nz.freebsd.org'
'$msg_norway' 'ftp.no.freebsd.org'
- ' $msg_norway #3' 'ftp3.no.freebsd.org'
'$msg_poland' 'ftp.pl.freebsd.org'
' $msg_poland #2' 'ftp2.pl.freebsd.org'
- ' $msg_poland #5' 'ftp5.pl.freebsd.org'
- '$msg_portugal' 'ftp.pt.freebsd.org'
- ' $msg_portugal #2' 'ftp2.pt.freebsd.org'
- ' $msg_portugal #4' 'ftp4.pt.freebsd.org'
- '$msg_romania' 'ftp.ro.freebsd.org'
'$msg_russia' 'ftp.ru.freebsd.org'
' $msg_russia #2' 'ftp2.ru.freebsd.org'
- ' $msg_russia #3' 'ftp3.ru.freebsd.org'
' $msg_russia #4' 'ftp4.ru.freebsd.org'
- '$msg_singapore' 'ftp.sg.freebsd.org'
+ ' $msg_russia #5' 'ftp5.ru.freebsd.org'
+ ' $msg_russia #6' 'ftp6.ru.freebsd.org'
'$msg_slovak_republic' 'ftp.sk.freebsd.org'
+ ' $msg_slovak_republic #2' 'ftp2.sk.freebsd.org'
'$msg_slovenia' 'ftp.si.freebsd.org'
- ' $msg_slovenia #2' 'ftp2.si.freebsd.org'
'$msg_south_africa' 'ftp.za.freebsd.org'
' $msg_south_africa #2' 'ftp2.za.freebsd.org'
- ' $msg_south_africa #3' 'ftp3.za.freebsd.org'
' $msg_south_africa #4' 'ftp4.za.freebsd.org'
'$msg_spain' 'ftp.es.freebsd.org'
- ' $msg_spain #2' 'ftp2.es.freebsd.org'
' $msg_spain #3' 'ftp3.es.freebsd.org'
'$msg_sweden' 'ftp.se.freebsd.org'
' $msg_sweden #2' 'ftp2.se.freebsd.org'
' $msg_sweden #3' 'ftp3.se.freebsd.org'
' $msg_sweden #4' 'ftp4.se.freebsd.org'
' $msg_sweden #5' 'ftp5.se.freebsd.org'
+ ' $msg_sweden #6' 'ftp6.se.freebsd.org'
'$msg_switzerland' 'ftp.ch.freebsd.org'
- ' $msg_switzerland #2' 'ftp2.ch.freebsd.org'
'$msg_taiwan' 'ftp.tw.freebsd.org'
' $msg_taiwan #2' 'ftp2.tw.freebsd.org'
' $msg_taiwan #3' 'ftp3.tw.freebsd.org'
' $msg_taiwan #4' 'ftp4.tw.freebsd.org'
' $msg_taiwan #6' 'ftp6.tw.freebsd.org'
' $msg_taiwan #11' 'ftp11.tw.freebsd.org'
- '$msg_turkey' 'ftp.tr.freebsd.org'
- ' $msg_turkey #2' 'ftp2.tr.freebsd.org'
'$msg_uk' 'ftp.uk.freebsd.org'
' $msg_uk #2' 'ftp2.uk.freebsd.org'
' $msg_uk #3' 'ftp3.uk.freebsd.org'
' $msg_uk #4' 'ftp4.uk.freebsd.org'
' $msg_uk #5' 'ftp5.uk.freebsd.org'
- ' $msg_uk #6' 'ftp6.uk.freebsd.org'
'$msg_ukraine' 'ftp.ua.freebsd.org'
- ' $msg_ukraine #2' 'ftp2.ua.freebsd.org'
- ' $msg_ukraine #5' 'ftp5.ua.freebsd.org'
- ' $msg_ukraine #6' 'ftp6.ua.freebsd.org'
' $msg_ukraine #7' 'ftp7.ua.freebsd.org'
- ' $msg_ukraine #8' 'ftp8.ua.freebsd.org'
'$msg_usa #1' 'ftp1.us.freebsd.org'
' $msg_usa #2' 'ftp2.us.freebsd.org'
' $msg_usa #3' 'ftp3.us.freebsd.org'
' $msg_usa #4' 'ftp4.us.freebsd.org'
' $msg_usa #5' 'ftp5.us.freebsd.org'
' $msg_usa #6' 'ftp6.us.freebsd.org'
- ' $msg_usa #7' 'ftp7.us.freebsd.org'
' $msg_usa #8' 'ftp8.us.freebsd.org'
- ' $msg_usa #9' 'ftp9.us.freebsd.org'
' $msg_usa #10' 'ftp10.us.freebsd.org'
' $msg_usa #11' 'ftp11.us.freebsd.org'
- ' $msg_usa #12' 'ftp12.us.freebsd.org'
' $msg_usa #13' 'ftp13.us.freebsd.org'
' $msg_usa #14' 'ftp14.us.freebsd.org'
' $msg_usa #15' 'ftp15.us.freebsd.org'
" # END-QUOTE
+ local hline="$msg_select_a_site_thats_close"
- local size
- size=$( eval f_dialog_menu_size \
- \"\$title\" \
- \"\$btitle\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$title\" \
+ \"\$btitle\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
- local dialog_menu retval mtag value
- dialog_menu=$( eval $DIALOG \
+ local mtag
+ mtag=$( eval $DIALOG \
--title \"\$title\" \
--backtitle \"\$btitle\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
- retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || return $FAILURE
+ ) || return $FAILURE
+ f_dialog_data_sanitize mtag
case "$mtag" in
URL) setvar $VAR_FTP_PATH "other" ;;
*)
+ local value
value=$( eval f_dialog_menutag2item \"\$mtag\" $menu_list )
setvar $VAR_FTP_PATH "ftp://$value"
esac
@@ -290,7 +255,7 @@ f_dialog_menu_media_ftp()
#
# VAR_FTP_HOST
# The FTP host to connect to, parsed from VAR_FTP_PATH. In the
-# example case of IPv6 where VAR_FTP_PATH is a "ftp://[::1]" this
+# example case of IPv6 where VAR_FTP_PATH is "ftp://[::1]", this
# variable will be set to "::1" (the outer brackets are removed).
# VAR_FTP_PORT
# The TCP port to connect to, parsed from VAR_FTP_PATH. Usually
@@ -382,27 +347,62 @@ f_media_set_ftp()
local hostname="${url#*://}" port=21 dir=/
case "$hostname" in
- "["*"]")
+ #
+ # The order in-which the below individual cases appear is important!
+ #
+ "["*"]":*/*) # IPv6 address with port and directory
+ f_dprintf "Looks like an IPv6 addr with port/dir: %s" \
+ "$hostname"
hostname="${hostname#\[}"
- hostname="${hostname%%\]*}"
+ port="${hostname#*\]:}"
+ port="${port%%[!0-9]*}"
+ dir="/${hostname#*/}"
+ hostname="${hostname%%\]:*}"
;;
- "["*"]/"*)
+ "["*"]":*) # IPv6 address with port
+ f_dprintf "Looks like an IPv6 addr with port: %s" "$hostname"
hostname="${hostname#\[}"
- dir="/${hostname#*/}"
- hostname="${hostname%%\]*}"
+ port="${hostname#*\]:}"
+ port="${port%%[!0-9]*}"
+ hostname="${hostname%%\]:*}"
;;
- *"/"*)
+ "["*"]"/*) # IPv6 address with directory
+ f_dprintf "Looks like an IPv6 addr with dir: %s" "$hostname"
+ hostname="${hostname#\[}"
dir="/${hostname#*/}"
- hostname="${hostname%%/*}"
+ hostname="${hostname%%\]*}"
;;
- "["*"]:"*)
+ "["*"]") # IPv6 address
+ f_dprintf "Looks like an IPv6 addr: %s" "$hostname"
hostname="${hostname#\[}"
- port="${hostname#*\]:}"
+ hostname="${hostname%\]}"
+ ;;
+ #
+ # ^^^ IPv6 above / DNS Name or IPv4 below vvv
+ #
+ *:*/*) # DNS name or IPv4 address with port and directory
+ f_dprintf "Looks like a %s with port/dir: %s" \
+ "DNS name or IPv4 addr" "$hostname"
+ port="${hostname#*:}"
port="${port%%[!0-9]*}"
- hostname="${hostname%%\]:*}"
+ dir="/${hostname#*/}"
+ hostname="${hostname%%:*}"
;;
- *)
+ *:*) # DNS name or IPv4 address with port
+ f_dprintf "Looks like a DNS name or IPv4 addr with port: %s" \
+ "$hostname"
+ port="${hostname#*:}"
+ hostname="${hostname%%:*}"
+ ;;
+ */*) # DNS name or IPv4 address with directory
+ f_dprintf "Looks like a DNS name or IPv4 addr with dir: %s" \
+ "$hostname"
+ dir="/${hostname#*/}"
hostname="${hostname%%/*}"
+ ;;
+ *) # DNS name or IPv4 address
+ f_dprintf "Looks like a DNS name or IPv4 addr: %s" "$hostname"
+ : leave hostname as-is
esac
f_dprintf "hostname = \`%s'" "$hostname"
@@ -505,6 +505,7 @@ f_media_set_ftp_userpass()
f_device_network_up()
{
local dev="$1" netDev
+ f_struct device_$dev || return $FAILURE
device_$dev get private netDev || return $SUCCESS # No net == happy net
f_device_init $netDev
}
@@ -516,6 +517,7 @@ f_device_network_up()
f_device_network_down()
{
local dev="$1" netDev
+ f_struct device_$dev || return $FAILURE
device_$dev get private netDev || return $SUCCESS
f_device_shutdown $netDev
}
@@ -597,8 +599,7 @@ f_media_init_ftp()
! f_getvar $VAR_FTP_PATH cp ||
[ ! "$cp" ]
then
- f_dialog_msgbox \
- "$msg_unable_to_get_proper_ftp_path"
+ f_show_msg "$msg_unable_to_get_proper_ftp_path"
f_device_network_down $dev
return $FAILURE
fi
@@ -609,7 +610,7 @@ f_media_init_ftp()
f_getvar $VAR_FTP_HOST ftp_host &&
f_getvar $VAR_FTP_DIR ftp_dir
}; then
- f_dialog_msgbox "$msg_missing_ftp_host_or_directory"
+ f_show_msg "$msg_missing_ftp_host_or_directory"
f_device_network_down $dev
return $FAILURE
fi
@@ -619,7 +620,7 @@ f_media_init_ftp()
local host="$ftp_host" port="${ftp_port:+:$ftp_port}"
case "$host" in *:*) host="[$host]"; esac
- local user pass use_anon=""
+ local user pass use_anon=
f_getvar $VAR_FTP_USER user
if [ ! "$user" ]; then
user="anonymous"
@@ -661,7 +662,10 @@ f_media_init_ftp()
break # to failure
fi
if echo "$rx" | awk -v dir="/${ftp_dir#/}" '
- BEGIN { found = 0 }
+ BEGIN {
+ found = 0
+ if ( dir != "/" ) sub("/$", "", dir)
+ }
/^Remote directory: / {
sub(/^[^:]*:[[:space:]]*/, "")
if ($0 != dir) next
@@ -752,12 +756,13 @@ f_media_init_ftp()
return $FAILURE
}
-# f_media_get_ftp $device $file [$probe_only]
+# f_media_get_ftp $device $file [$probe_type]
#
# Returns data from $file on an FTP server using ftp(1). Please note that
# $device is unused but must be present (even if null). Information is instead
-# gathered from the environment. $probe_only is currently unused by this media
-# type.
+# gathered from the environment. If $probe_type is present and non-NULL,
+# returns success if $file exists. If $probe_type is equal to $PROBE_SIZE,
+# prints the size of $file in bytes to standard-out.
#
# Variables from variable.subr used to configure the connection are as follows
# (all of which are configured by f_media_set_ftp above):
@@ -791,10 +796,10 @@ f_media_init_ftp()
#
f_media_get_ftp()
{
- local dev="$1" file="$2" probe_only="$3"
+ local dev="$1" file="$2" probe_type="$3" hosts=
- f_dprintf "f_media_get_ftp: dev=[%s] file=[%s] probe_only=%s" \
- "$dev" "$file" "$probe_only"
+ f_dprintf "f_media_get_ftp: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
local ftp_host ftp_port
f_getvar $VAR_FTP_HOST ftp_host
@@ -833,7 +838,7 @@ f_media_get_ftp()
return $FAILURE
fi
- local user pass use_anon=""
+ local user pass use_anon=
f_getvar $VAR_FTP_USER user
if [ ! "$user" ]; then
user="anonymous"
@@ -855,16 +860,28 @@ f_media_get_ftp()
userpass="$userpass${userpass:+@}"
fi
- local ftp_dir mode rx
- f_getvar $VAR_FTP_DIR ftp_dir
+ local dir mode rx
+ f_getvar $VAR_FTP_DIR\#/ dir
f_getvar $VAR_FTP_STATE mode
- local dir="${ftp_dir#/}"
local port="${ftp_port:+:$ftp_port}"
case "$host" in *:*) host="[$host]"; esac
f_dprintf "sending ftp request for: %s" "ftp://$host$port/$dir/$file"
+ if [ "$probe_type" ]; then
+ local url="ftp://$userpass$host$port/$dir/$file" size
+ [ "$use_anon" ] && url="ftp://$host$port/$dir/$file"
+ if ! size=$( fetch -s "$url" 2>&1 ) || ! f_isinteger "$size"
+ then
+ f_dprintf "request failed! size response=[%s]" "$size"
+ [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1"
+ return $FAILURE
+ fi
+ [ "$probe_type" = "$PROBE_SIZE" ] && echo "$size"
+ return $SUCCESS
+ fi
+
eval FTPMODE=\"\$mode\" ${use_anon:+FTPANONPASS=\"\$pass\"} \
ftp -V ${use_anon:+-a} -o - \
\"ftp://\$userpass\$host\$port/\$dir/\$file\" 2> /dev/null
diff --git a/usr.sbin/bsdconfig/share/media/http.subr b/usr.sbin/bsdconfig/share/media/http.subr
new file mode 100644
index 0000000..1236c99
--- /dev/null
+++ b/usr.sbin/bsdconfig/share/media/http.subr
@@ -0,0 +1,646 @@
+if [ ! "$_MEDIA_HTTP_SUBR" ]; then _MEDIA_HTTP_SUBR=1
+#
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+############################################################ INCLUDES
+
+BSDCFG_SHARE="/usr/share/bsdconfig"
+. $BSDCFG_SHARE/common.subr || exit 1
+f_dprintf "%s: loading includes..." media/http.subr
+f_include $BSDCFG_SHARE/device.subr
+f_include $BSDCFG_SHARE/dialog.subr
+f_include $BSDCFG_SHARE/media/common.subr
+f_include $BSDCFG_SHARE/media/tcpip.subr
+f_include $BSDCFG_SHARE/strings.subr
+f_include $BSDCFG_SHARE/struct.subr
+f_include $BSDCFG_SHARE/variable.subr
+
+BSDCFG_LIBE="/usr/libexec/bsdconfig"
+f_include_lang $BSDCFG_LIBE/include/messages.subr
+
+############################################################ GLOBALS
+
+HTTP_SKIP_RESOLV=
+
+URL_MAX=261261
+ # NOTE: This is according to actual fetch(1) test-results. We actually
+ # use nc(1) to retrieve files, but it's still a good idea to keep the
+ # URLs short enough that fetch(1) won't complain.
+
+HTTP_DIRS="
+ .
+ releases/$UNAME_P
+ snapshots/$UNAME_P
+ pub/FreeBSD
+ pub/FreeBSD/releases/$UNAME_P
+ pub/FreeBSD/snapshots/$UNAME_P
+ pub/FreeBSD-Archive/old-releases/$UNAME_P
+" # END-QUOTE
+
+############################################################ FUNCTIONS
+
+# f_dialog_menu_media_http
+#
+# Prompt the user to select from a range of ``built-in'' HTTP servers or
+# specify their own. If the user makes a choice and doesn't cancel or press
+# Esc, stores the user's choice in VAR_FTP_PATH (see variable.subr) and returns
+# success.
+#
+f_dialog_menu_media_http()
+{
+ f_dialog_title "$msg_please_select_a_freebsd_http_distribution_site"
+ local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
+ f_dialog_title_restore
+ local prompt="$msg_please_select_the_site_closest_to_you_or_other"
+ local menu_list="
+ 'URL' '$msg_specify_some_other_http_site'
+ " # END-QUOTE
+ local hline="$msg_select_a_site_thats_close"
+
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$title\" \
+ \"\$btitle\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ local mtag
+ mtag=$( eval $DIALOG \
+ --title \"\$title\" \
+ --backtitle \"\$btitle\" \
+ --hline \"\$hline\" \
+ --ok-label \"\$msg_ok\" \
+ --cancel-label \"\$msg_cancel\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
+ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+ ) || return $FAILURE
+ f_dialog_data_sanitize mtag
+
+ case "$mtag" in
+ URL) setvar $VAR_HTTP_PATH "other" ;;
+ *)
+ local value
+ value=$( eval f_dialog_menutag2item \"\$mtag\" $menu_list )
+ setvar $VAR_HTTP_PATH "http://$value"
+ esac
+
+ return $SUCCESS
+}
+
+# f_media_set_http
+#
+# Return success if we both found and set the media type to be an HTTP server.
+#
+# Variables from variable.subr that can be used to script user input:
+#
+# VAR_HTTP_PATH
+# URL containing host and optionally a target path to the release
+# repository on the HTTP server. Valid examples include:
+# http://myhost
+# http://somename:80/pub/
+# http://192.168.2.3/pub/
+# http://[::1]:8000/
+# The default port if not specified is 80.
+# VAR_NAMESERVER [Optional]
+# If set, overrides resolv.conf(5) and sets the nameserver that
+# is used to convert names into addresses (when a name converts
+# into multiple addresses, the first address to successfully
+# connect is used).
+#
+# Meanwhile, the following variables from variable.subr are set after
+# successful execution:
+#
+# VAR_HTTP_HOST
+# The HTTP host to connect to, parsed from VAR_HTTP_PATH. In the
+# example case of IPv6 where VAR_HTTP_PATH is "http://[::1]" this
+# variable will be set to "::1" (the outer brackets are removed).
+# VAR_HTTP_PORT
+# The TCP port to connect to, parsed from VAR_HTTP_PATH. Usually
+# 80 unless VAR_HTTP_PATH was one of the following forms:
+# http://hostname:OTHER_PORT
+# http://hostname:OTHER_PORT/*
+# http://ip:OTHER_PORT
+# http://ip:OTHER_PORT/*
+# http://[ip6]:OTHER_PORT
+# http://[ip6]:OTHER_PORT/*
+# VAR_HTTP_DIR
+# If VAR_HTTP_PATH contained a directory element (e.g.,
+# "http://localhost/pub") this variable contains only the
+# directory element (e.g., "/pub").
+#
+f_media_set_http()
+{
+ f_media_close
+
+ local url
+ f_getvar $VAR_HTTP_PATH url
+
+ # If we've been through here before ...
+ if f_struct device_network && [ "${url#$msg_other}" ]; then
+ f_dialog_yesno "$msg_reuse_old_http_site_settings" || url=
+ fi
+
+ if [ ! "$url" ]; then
+ f_dialog_menu_media_http || return $FAILURE
+ f_getvar $VAR_HTTP_PATH url
+ fi
+ [ "$url" ] || return $FAILURE
+
+ case "$url" in
+ other)
+ setvar $VAR_HTTP_PATH "http://"
+ f_variable_get_value $VAR_HTTP_PATH \
+ "$msg_please_specify_url_of_freebsd_http_distribution"
+ f_getvar $VAR_HTTP_PATH url
+ if [ ! "${url#http://}" ]; then
+ unset $VAR_HTTP_PATH
+ return $FAILURE
+ fi
+ if [ ${#url} -gt ${URL_MAX:-261261} ]; then
+ f_show_msg "$msg_length_of_specified_url_is_too_long" \
+ ${#url} ${URL_MAX:-261261}
+ unset $VAR_HTTP_PATH
+ return $FAILURE
+ fi
+ case "$url" in
+ http://*) : valid URL ;;
+ *)
+ f_show_msg "$msg_sorry_invalid_url" "$url"
+ unset $VAR_HTTP_PATH
+ return $FAILURE
+ esac
+ esac
+ case "$url" in
+ http://*) : valid URL ;;
+ *)
+ f_show_msg "$msg_sorry_invalid_url" "$url"
+ unset $VAR_HTTP_PATH
+ return $FAILURE
+ esac
+
+ # Set the name of the HTTP device to the URL
+ f_struct_new DEVICE device_http
+ device_http set name "$url"
+
+ if ! f_struct device_network ||
+ ! f_dialog_yesno "$msg_youve_already_done_the_network_configuration"
+ then
+ f_struct device_network &&
+ f_device_shutdown network
+ if ! f_device_select_tcp; then
+ unset $VAR_HTTP_PATH
+ return $FAILURE
+ fi
+ local dev
+ f_getvar $VAR_NETWORK_DEVICE dev
+ f_struct_copy "device_$dev" device_network
+ fi
+ if ! f_device_init network; then
+ f_dprintf "f_media_set_http: %s" "$msg_net_device_init_failed"
+ unset $VAR_HTTP_PATH
+ return $FAILURE
+ fi
+
+ local hostname="${url#*://}" port=80 dir=/
+ case "$hostname" in
+ #
+ # The order in-which the below individual cases appear is important!
+ #
+ "["*"]":*/*) # IPv6 address with port and directory
+ f_dprintf "Looks like an IPv6 addr with port/dir: %s" \
+ "$hostname"
+ hostname="${hostname#\[}"
+ port="${hostname#*\]:}"
+ port="${port%%[!0-9]*}"
+ dir="/${hostname#*/}"
+ hostname="${hostname%%\]:*}"
+ ;;
+ "["*"]":*) # IPv6 address with port
+ f_dprintf "Looks like an IPv6 addr with port: %s" "$hostname"
+ hostname="${hostname#\[}"
+ port="${hostname#*\]:}"
+ port="${port%%[!0-9]*}"
+ hostname="${hostname%%\]:*}"
+ ;;
+ "["*"]"/*) # IPv6 address with directory
+ f_dprintf "Looks like an IPv6 addr with dir: %s" "$hostname"
+ hostname="${hostname#\[}"
+ dir="/${hostname#*/}"
+ hostname="${hostname%%\]*}"
+ ;;
+ "["*"]") # IPv6 address
+ f_dprintf "Looks like an IPv6 addr: %s" "$hostname"
+ hostname="${hostname#\[}"
+ hostname="${hostname%\]}"
+ ;;
+ #
+ # ^^^ IPv6 above / DNS Name or IPv4 below vvv
+ #
+ *:*/*) # DNS name or IPv4 address with port and directory
+ f_dprintf "Looks like a %s with port/dir: %s" \
+ "DNS name or IPv4 addr" "$hostname"
+ port="${hostname#*:}"
+ port="${port%%[!0-9]*}"
+ dir="/${hostname#*/}"
+ hostname="${hostname%%:*}"
+ ;;
+ *:*) # DNS name or IPv4 address with port
+ f_dprintf "Looks like a DNS name or IPv4 addr with port: %s" \
+ "$hostname"
+ port="${hostname#*:}"
+ hostname="${hostname%%:*}"
+ ;;
+ */*) # DNS name or IPv4 address with directory
+ f_dprintf "Looks like a DNS name or IPv4 addr with dir: %s" \
+ "$hostname"
+ dir="/${hostname#*/}"
+ hostname="${hostname%%/*}"
+ ;;
+ *) # DNS name or IPv4 address
+ f_dprintf "Looks like a DNS name or IPv4 addr: %s" "$hostname"
+ : leave hostname as-is
+ esac
+
+ f_dprintf "hostname = \`%s'" "$hostname"
+ f_dprintf "dir = \`%s'" "$dir"
+ f_dprintf "port \# = \`%d'" "$port"
+
+ local ns
+ f_getvar $VAR_NAMESERVER ns
+ [ "$ns" ] || f_resolv_conf_nameservers ns
+ if [ "$ns" -a ! "$HTTP_SKIP_RESOLV" ] && ! {
+ f_validate_ipaddr "$hostname" ||
+ f_validate_ipaddr6 "$hostname"
+ }; then
+ f_show_info "$msg_looking_up_host" "$hostname"
+ f_dprintf "%s: Looking up hostname, %s, using host(1)" \
+ "f_media_set_http" "$hostname"
+ if ! f_quietly f_host_lookup "$hostname"; then
+ f_show_msg "$msg_cannot_resolve_hostname" "$hostname"
+ f_struct device_network &&
+ f_device_shutdown network
+ f_struct_free device_network
+ unset $VAR_HTTP_PATH
+ return $FAILURE
+ fi
+ f_dprintf "Found DNS entry for %s successfully." "$hostname"
+ fi
+
+ setvar $VAR_HTTP_HOST "$hostname"
+ setvar $VAR_HTTP_PORT "$port"
+ setvar $VAR_HTTP_DIR "$dir"
+
+ device_http set type $DEVICE_TYPE_HTTP
+ device_http set init f_media_init_http
+ device_http set get f_media_get_http
+ device_http set shutdown f_media_shutdown_http
+ device_http set private network
+ f_struct_copy device_http device_media
+ f_struct_free device_http
+
+ return $SUCCESS
+}
+
+# f_http_check_access [$connect_only]
+#
+# Return success if able list a remote HTTP directory. If $connect_only is
+# present and non-null, then returns success if a connection can be made.
+# Variables from variable.subr that can be used to script user input:
+#
+# VAR_HTTP_HOST
+# The HTTP server host name, IPv4 address or IPv6 address.
+# Valid examples include:
+# myhost
+# 192.168.2.3
+# ::1
+# VAR_HTTP_PORT
+# The TCP port to connect to when communicating with the server.
+# VAR_HTTP_PATH
+# The HTTP path sent to the server. Unused if $connect_only is
+# present and non-NULL.
+#
+f_http_check_access()
+{
+ local connect_only="$1" hosts=
+
+ local http_host http_port
+ f_getvar $VAR_HTTP_HOST http_host
+ f_getvar $VAR_HTTP_PORT http_port
+
+ if ! {
+ f_validate_ipaddr "$http_host" ||
+ f_validate_ipaddr6 "$http_host" ||
+ {
+ f_dprintf "%s: Looking up hostname, %s, using host(1)" \
+ "f_http_check_access" "$http_host"
+ f_host_lookup "$http_host" hosts
+ }
+ }; then
+ # All the above validations failed
+ [ "$hosts" ] && f_dialog_msgbox "$hosts"
+ unset $VAR_HTTP_HOST
+ return $FAILURE
+ elif [ ! "$hosts" ]; then
+ # One of the first two validations passed
+ hosts="$http_host"
+ fi
+
+ local host connected=
+ for host in $hosts; do
+ f_quietly nc -nz "$host" "$http_port" || continue
+ connected=1; break
+ done
+ if [ ! "$connected" ]; then
+ f_show_msg "$msg_couldnt_connect_to_server http://%s:%s/" \
+ "$http_host" "$http_port"
+ unset $VAR_HTTP_HOST
+ return $FAILURE
+ fi
+ [ "$connect_only" ] && return $SUCCESS
+
+ local http_path
+ f_getvar $VAR_HTTP_PATH http_path
+ f_show_info "$msg_checking_access_to" "$http_path"
+
+ local rx
+ if ! rx=$(
+ printf "GET /%s/ HTTP/1.0\r\n\r\n" "${http_path%/}" |
+ nc -n "$host" "$http_port"
+ ); then
+ f_show_msg "$msg_couldnt_connect_to_server http://%s:%s/" \
+ "$http_host" "$http_port"
+ unset $VAR_HTTP_HOST
+ return $FAILURE
+ fi
+
+ local hdr
+ hdr=$( echo "$rx" | awk '/^\r$/{exit}{print}' )
+
+ local http_found=$FAILURE
+ if echo "$hdr" | awk '
+ BEGIN { found = 0 }
+ /^HTTP.... 200 / {
+ found = 1
+ exit
+ }
+ END { exit ! found }
+ '; then
+ http_found=$SUCCESS
+ fi
+
+ return $http_found
+}
+
+# f_media_init_http $device
+#
+# Initializes the HTTP media device. Returns success if able to confirm the
+# existence of at least one known HTTP server release path directly via HTTP
+# using f_http_check_access(), above.
+#
+# Variables from variable.subr that can be used to script user input:
+#
+# VAR_HTTP_HOST
+# The HTTP server to connect to. Must be set. Also see
+# f_http_check_access() for additional variables.
+# VAR_RELNAME
+# Usually set to `uname -r' but can be overridden.
+# VAR_HTTP_PATH
+# The HTTP path sent to the server. Usually set by calling
+# f_media_set_http().
+#
+# Meanwhile, after successful execution, the following variables (also from
+# variable.subr) are set:
+#
+# VAR_HTTP_PATH
+# The [possibly] adjusted VAR_HTTP_PATH that was found to contain
+# a valid FreeBSD repository.
+#
+f_media_init_http()
+{
+ local dev="$1"
+ f_dprintf "Init routine called for HTTP device. dev=[%s]" "$dev"
+
+ #
+ # First verify access
+ #
+ local connect_only=1
+ f_http_check_access $connect_only
+
+ local http_host
+ f_getvar $VAR_HTTP_HOST http_host
+ while [ ! "$http_host" ]; do
+ f_media_set_http || return $FAILURE
+ f_http_check_access $connect_only
+ f_getvar $VAR_HTTP_HOST http_host
+ done
+
+ local http_path http_found=$FAILURE
+ while :; do
+ #
+ # Now that we've verified that the path we're given is ok,
+ # let's try to be a bit intelligent in locating the release we
+ # are looking for. First off, if the release is specified as
+ # "__RELEASE" or "any", then just assume that the current
+ # directory is the one we want and give up.
+ #
+ local rel
+ f_getvar $VAR_RELNAME rel
+ f_dprintf "f_media_init_http: rel=[%s]" "$rel"
+
+ case "$rel" in
+ __RELEASE|any)
+ setvar $VAR_HTTP_PATH "$VAR_HTTP_DIR"
+ f_http_check_access
+ http_found=$?
+ ;;
+ *)
+ #
+ # Ok, since we have a release variable, let's walk
+ # through the list of directories looking for a release
+ # directory. First successful path wins.
+ #
+ local fdir hp
+ f_getvar $VAR_HTTP_PATH%/ hp
+ for fdir in $HTTP_DIRS; do
+ setvar $VAR_HTTP_PATH "$hp/$fdir/$rel"
+ if f_http_check_access; then
+ http_found=$SUCCESS
+ break
+ fi
+ done
+ esac
+
+ [ $http_found -eq $SUCCESS ] && break
+
+ f_getvar $VAR_HTTP_PATH http_path
+ f_show_msg "$msg_please_check_the_url_and_try_again" \
+ "$http_path"
+
+ unset $VAR_HTTP_PATH
+ f_media_set_http || break
+ done
+
+ return $http_found
+}
+
+# f_media_get_http $device $file [$probe_type]
+#
+# Returns data from $file on an HTTP server using nc(1). Please note that
+# $device is unused but must be present (even if null). Information is instead
+# gathered from the environment. If $probe_type is both present and non-NULL,
+# this function exits after receiving the HTTP header response from the server
+# (if the HTTP response code is 200, success is returned; otherwise failure).
+# If $probe_type is equal to $PROBE_SIZE, prints the content-length in bytes
+# from the response (or -1 if not found) to standard-out.
+#
+# The variables used to configure the connection are as follows (all of which
+# are configured by f_media_set_http above):
+#
+# VAR_HTTP_HOST
+# HTTP server which to connect. Can be an IPv4 address, IPv6
+# address, or DNS hostname of your choice.
+# VAR_HTTP_PORT
+# TCP port to connect on; see f_media_set_http above.
+# VAR_HTTP_PATH
+# Directory prefix to use when requesting $file. Default is `/'
+# unless f_media_init_http was able to use f_http_check_access
+# to validate one of the defaults in $HTTP_DIRS (see GLOBALS at
+# the top of this file); assuming VAR_RELNAME was not set to
+# either `__RELEASE' or `any' (indicating that the global set of
+# $HTTP_DIRS should be ignored).
+#
+# See variable.subr for additional information.
+#
+# Example usage:
+# f_media_set_http
+# f_media_get_http media $file
+#
+f_media_get_http()
+{
+ local dev="$1" file="$2" probe_type="$3" hosts=
+
+ f_dprintf "f_media_get_http: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
+
+ local http_host http_port
+ f_getvar $VAR_HTTP_HOST http_host
+ f_getvar $VAR_HTTP_PORT http_port
+
+ if ! {
+ f_validate_ipaddr "$http_host" ||
+ f_validate_ipaddr6 "$http_host" ||
+ {
+ f_dprintf "%s: Looking up hostname, %s, using host(1)" \
+ "f_media_get_http" "$http_host"
+ f_host_lookup "$http_host" hosts
+ }
+ }; then
+ # All the above validations failed
+ [ "$hosts" ] && f_dialog_msgbox "$hosts"
+ return $FAILURE
+ elif [ ! "$hosts" ]; then
+ # One of the first two validations passed
+ hosts="$http_host"
+ fi
+
+ local host connected=
+ for host in $hosts; do
+ f_quietly nc -nz "$host" "$http_port" || continue
+ connected=1; break
+ done
+ if [ ! "$connected" ]; then
+ f_show_msg "$msg_couldnt_connect_to_server http://%s:%s/" \
+ "$http_host" "$http_port"
+ return $FAILURE
+ fi
+
+ local http_path
+ f_getvar $VAR_HTTP_PATH%/ http_path
+ local url="/$http_path/$file" rx
+
+ f_dprintf "sending http request for: %s" "$url"
+ printf "GET %s HTTP/1.0\r\n\r\n" "$url" | nc -n "$host" "$http_port" |
+ (
+ #
+ # scan the headers of the response
+ # this is extremely quick'n dirty
+ #
+
+ rv=0 length=-1
+ while read LINE; do
+ case "$LINE" in
+ HTTP*)
+ f_dprintf "received response: %s" "$LINE"
+ set -- $LINE; rv=$2
+ f_isinteger "$rv" || rv=0
+ ;;
+ "Content-Length: "*)
+ length="${LINE% }"
+ length="${length#Content-Length: }"
+ f_dprintf "received content-length: %s" \
+ "$length"
+ ;;
+ *)
+ [ "${LINE% }" ] || break # End of headers
+ esac
+ done
+
+ [ $rv -ge 500 ] && exit 5
+ [ $rv -eq 404 ] && exit 44
+ [ $rv -ge 400 ] && exit 4
+ [ $rv -ge 300 ] && exit 3
+ [ $rv -eq 200 ] || exit $FAILURE
+
+ if [ ! "$probe_type" ]; then
+ cat # output the rest ``as-is''
+ elif [ "$probe_type" = "$PROBE_SIZE" ]; then
+ f_isinteger "$length" || length=-1
+ echo "$length"
+ fi
+ exit 200
+ )
+ local retval=$?
+ [ $retval -eq 200 ] && return $SUCCESS
+ [ "$probe_type" ] && return $FAILURE
+
+ case "$retval" in
+ 5) f_show_msg "$msg_server_error_when_requesting_url" "$url" ;;
+ 44) f_show_msg "$msg_url_was_not_found" "$url" ;;
+ 4) f_show_msg "$msg_client_error" ;;
+ *) f_show_msg "$msg_error_when_requesting_url" "$url" ;;
+ esac
+ return $FAILURE
+}
+
+############################################################ MAIN
+
+f_dprintf "%s: Successfully loaded." media/http.subr
+
+fi # ! $_MEDIA_HTTP_SUBR
diff --git a/usr.sbin/bsdconfig/share/media/httpproxy.subr b/usr.sbin/bsdconfig/share/media/httpproxy.subr
index fad1007..66e5be4 100644
--- a/usr.sbin/bsdconfig/share/media/httpproxy.subr
+++ b/usr.sbin/bsdconfig/share/media/httpproxy.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_HTTPPROXY_SUBR" ]; then _MEDIA_HTTPPROXY_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_HTTPPROXY_SUBR" ]; then _MEDIA_HTTPPROXY_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -32,9 +32,9 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/httpproxy.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/variable.subr
f_include $BSDCFG_SHARE/media/ftp.subr
f_include $BSDCFG_SHARE/media/tcpip.subr
+f_include $BSDCFG_SHARE/variable.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr
@@ -77,19 +77,33 @@ f_media_set_http_proxy()
local hostname="$proxy" port=3128
case "$hostname" in
- "["*"]")
- hostname="${hostname#\[}"
- hostname="${hostname%\]}"
- ;;
- "["*"]:")
+ #
+ # The order in-which the below individual cases appear is important!
+ #
+ "["*"]":*) # IPv6 address with port
+ f_dprintf "Looks like an IPv6 addr with port: %s" "$hostname"
hostname="${hostname#\[}"
port="${hostname#*\]:}"
port="${port%%[!0-9]*}"
hostname="${hostname%%\]:*}"
;;
- *":"*)
+ "["*"]") # IPv6 address
+ f_dprintf "Looks like an IPv6 addr: %s" "$hostname"
+ hostname="${hostname#\[}"
+ hostname="${hostname%\]}"
+ ;;
+ #
+ # ^^^ IPv6 above / DNS Name or IPv4 below vvv
+ #
+ *:*) # DNS name or IPv4 address with port
+ f_dprintf "Looks like a DNS name or IPv4 addr with port: %s" \
+ "$hostname"
port="${hostname#*:}"
hostname="${hostname%%:*}"
+ ;;
+ *) # DNS name or IPv4 address
+ f_dprintf "Looks like a DNS name or IPv4 addr: %s" "$hostname"
+ : leave hostname as-is
esac
setvar $VAR_HTTP_PROXY_HOST "$hostname"
@@ -133,7 +147,7 @@ f_media_set_http_proxy()
#
f_http_proxy_check_access()
{
- local connect_only="$1" hosts=""
+ local connect_only="$1" hosts=
local proxy_host proxy_port
f_getvar $VAR_HTTP_PROXY_HOST proxy_host
@@ -292,7 +306,7 @@ f_media_init_http_proxy()
;;
*)
local fdir fp
- f_getvar $VAR_FTP_PATH fp
+ f_getvar $VAR_FTP_PATH%/ fp
for fdir in $FTP_DIRS; do
setvar $VAR_HTTP_PROXY_PATH "$fp/$fdir/$rel"
if f_http_proxy_check_access; then
@@ -315,12 +329,16 @@ f_media_init_http_proxy()
return $http_found
}
-# f_media_get_http_proxy $device $file [$probe_only]
+# f_media_get_http_proxy $device $file [$probe_type]
#
# Returns data from $file on an FTP server via HTTP proxy using nc(1). Please
# note that $device is unused but must be present (even if null). Information
-# is instead gathered from the environment. $probe_only is currently unused by
-# this media type.
+# is instead gathered from the environment. If $probe_type is both present and
+# non-NULL, this function exits after receiving the HTTP header response from
+# the proxy server (if the HTTP response code is 200, success is returned;
+# otherwise failure). If $probe_type is equal to $PROBE_SIZE, prints the
+# content-length in bytes from the response (or -1 if not found) to standard-
+# out.
#
# The variables used to configure the connection are as follows (all of which
# are configured by f_media_set_http_proxy above):
@@ -342,10 +360,10 @@ f_media_init_http_proxy()
#
f_media_get_http_proxy()
{
- local dev="$1" file="$2" probe_only="$3" hosts=
+ local dev="$1" file="$2" probe_type="$3" hosts=
- f_dprintf "f_media_get_http_proxy: dev=[%s] file=[%s] probe_only=%s" \
- "$dev" "$file" "$probe_only"
+ f_dprintf "f_media_get_http_proxy: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
local proxy_host proxy_port
f_getvar $VAR_HTTP_PROXY_HOST proxy_host
@@ -380,9 +398,9 @@ f_media_get_http_proxy()
fi
local proxy_path mode
- f_getvar $VAR_HTTP_PROXY_PATH proxy_path
+ f_getvar $VAR_HTTP_PROXY_PATH%/ proxy_path
f_getvar $VAR_HTTP_FTP_MODE mode
- local url="${proxy_path%/}/$file$mode" rx
+ local url="$proxy_path/$file$mode" rx
f_dprintf "sending http request for: %s" "$url"
printf "GET %s HTTP/1.0\r\n\r\n" "$url" | nc -n "$host" "$proxy_port" |
@@ -392,7 +410,7 @@ f_media_get_http_proxy()
# this is extremely quick'n dirty
#
- rv=0
+ rv=0 length=-1
while read LINE; do
case "$LINE" in
HTTP*)
@@ -400,6 +418,12 @@ f_media_get_http_proxy()
set -- $LINE; rv=$2
f_isinteger "$rv" || rv=0
;;
+ "Content-Length: "*)
+ length="${LINE% }"
+ length="${length#Content-Length: }"
+ f_dprintf "received content-length: %s" \
+ "$length"
+ ;;
*)
[ "${LINE% }" ] || break # End of headers
esac
@@ -411,11 +435,17 @@ f_media_get_http_proxy()
[ $rv -ge 300 ] && exit 3
[ $rv -eq 200 ] || exit $FAILURE
- cat # output the rest ``as-is''
+ if [ ! "$probe_type" ]; then
+ cat # output the rest ``as-is''
+ elif [ "$probe_type" = "$PROBE_SIZE" ]; then
+ f_isinteger "$length" || length=-1
+ echo "$length"
+ fi
exit 200
)
local retval=$?
[ $retval -eq 200 ] && return $SUCCESS
+ [ "$probe_type" ] && return $FAILURE
case "$retval" in
5) f_show_msg "$msg_server_error_when_requesting_url" "$url" ;;
diff --git a/usr.sbin/bsdconfig/share/media/network.subr b/usr.sbin/bsdconfig/share/media/network.subr
index d9fe8e6..6e17200 100644
--- a/usr.sbin/bsdconfig/share/media/network.subr
+++ b/usr.sbin/bsdconfig/share/media/network.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_NETWORK_SUBR" ]; then _MEDIA_NETWORK_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_NETWORK_SUBR" ]; then _MEDIA_NETWORK_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -110,7 +110,7 @@ f_media_init_network()
local rp
f_getvar $VAR_GATEWAY rp
if [ ! "$rp" ]; then
- f_dialog_msgbox "$msg_no_gateway_has_been_set"
+ f_show_msg "$msg_no_gateway_has_been_set"
else
#
# Explicitly flush all routes to get back to a
@@ -121,7 +121,7 @@ f_media_init_network()
f_quietly route -n flush
f_dprintf "Adding default route to %s." "$rp"
if ! f_quietly route -n add default "$rp"; then
- f_dialog_msgbox \
+ f_show_msg \
"$msg_failed_to_add_default_route"
return $FAILURE
fi
diff --git a/usr.sbin/bsdconfig/share/media/nfs.subr b/usr.sbin/bsdconfig/share/media/nfs.subr
index 461db1c..9ce0467 100644
--- a/usr.sbin/bsdconfig/share/media/nfs.subr
+++ b/usr.sbin/bsdconfig/share/media/nfs.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_NFS_SUBR" ]; then _MEDIA_NFS_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_NFS_SUBR" ]; then _MEDIA_NFS_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,13 +31,13 @@ if [ ! "$_MEDIA_NFS_SUBR" ]; then _MEDIA_NFS_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/nfs.subr
-f_include $BSDCFG_SHARE/struct.subr
f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/variable.subr
f_include $BSDCFG_SHARE/media/common.subr
-f_include $BSDCFG_SHARE/media/tcpip.subr
f_include $BSDCFG_SHARE/media/network.subr
+f_include $BSDCFG_SHARE/media/tcpip.subr
+f_include $BSDCFG_SHARE/struct.subr
+f_include $BSDCFG_SHARE/variable.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr
@@ -82,7 +82,7 @@ f_media_set_nfs()
case "$nfs" in
*:*) : valid NFS path ;;
*)
- f_dialog_msgbox "$msg_invalid_nfs_path_specification"
+ f_show_msg "$msg_invalid_nfs_path_specification"
return $FAILURE
esac
@@ -103,9 +103,8 @@ f_media_set_nfs()
f_dprintf "%s: $msg_net_device_init_failed\n" f_media_set_nfs
local hostname="${nfs%%:*}"
- if f_quietly f_getvar $VAR_NAMESERVER && ! {
- f_validate_ipaddr "$hostname" ||
- f_validate_ipaddr6 "$hostname"
+ if f_isset $VAR_NAMESERVER && ! {
+ f_validate_ipaddr "$hostname" || f_validate_ipaddr6 "$hostname"
}; then
f_show_info "$msg_looking_up_host" "$hostname"
f_dprintf "%s Looking up hostname, %s, using host(1)" \
@@ -209,19 +208,21 @@ f_media_init_nfs()
return $SUCCESS
}
-# f_media_get_nfs $device $file [$probe_only]
+# f_media_get_nfs $device $file [$probe_type]
#
-# Returns data from $file on a mounted NFS device. Similar to cat(1).
-# $probe_only is currently unused by this media type.
+# Returns data from $file on a mounted NFS device. Similar to cat(1). If
+# $probe_type is present and non-NULL, returns success if $file exists. If
+# $probe_type is equal to $PROBE_SIZE, prints the size of $file in bytes to
+# standard-out.
#
f_media_get_nfs()
{
- local dev="$1" file="$2" probe_only="$3"
+ local dev="$1" file="$2" probe_type="$3"
- f_dprintf "f_media_get_nfs: dev=[%s] file=[%s] probe_only=%s" \
- "$dev" "$file" "$probe_only"
+ f_dprintf "f_media_get_nfs: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
- f_media_generic_get "$MOUNTPOINT" "$file"
+ f_media_generic_get "$MOUNTPOINT" "$file" "$probe_type"
}
# f_media_shutdown_nfs $device
diff --git a/usr.sbin/bsdconfig/share/media/options.subr b/usr.sbin/bsdconfig/share/media/options.subr
index c32bec5..3f71a96 100644
--- a/usr.sbin/bsdconfig/share/media/options.subr
+++ b/usr.sbin/bsdconfig/share/media/options.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_OPTIONS_SUBR" ]; then _MEDIA_OPTIONS_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_OPTIONS_SUBR" ]; then _MEDIA_OPTIONS_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -32,10 +32,10 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/options.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/struct.subr
-f_include $BSDCFG_SHARE/variable.subr
f_include $BSDCFG_SHARE/media/any.subr
f_include $BSDCFG_SHARE/media/ftp.subr
+f_include $BSDCFG_SHARE/struct.subr
+f_include $BSDCFG_SHARE/variable.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr
@@ -53,9 +53,10 @@ f_media_options_menu()
f_dialog_title "$msg_options_editor"
local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
f_dialog_title_restore
- local prompt=""
+ local prompt=
+ local menu_list # Calculated below
+ local defaultitem=
local hline="$hline_arrows_tab_enter"
- local menu_list size cp
#
# A hack so that the dialogs below are always interactive in a script
@@ -66,8 +67,9 @@ f_media_options_menu()
unset $VAR_NONINTERACTIVE
fi
+ local cp
while :; do
- menu_list=""
+ menu_list=
f_getvar $VAR_NFS_SECURE cp
if [ "$cp" = "YES" ]; then menu_list="$menu_list
@@ -110,6 +112,15 @@ f_media_options_menu()
'$msg_emit_extra_debugging_output'"
fi
+ f_getvar $VAR_NO_CONFIRM cp
+ if [ "$cp" ]; then menu_list="$menu_list
+ ' $msg_yes_to_all' 'YES'
+ '$msg_assume_yes_to_all_non_critical_dialogs'"
+ else menu_list="$menu_list
+ ' $msg_yes_to_all' 'NO'
+ '$msg_assume_yes_to_all_non_critical_dialogs'"
+ fi
+
f_getvar $VAR_TRY_DHCP cp
if [ "$cp" = "YES" ]; then menu_list="$menu_list
' $msg_dhcp' 'YES'
@@ -146,23 +157,16 @@ f_media_options_menu()
device_media get type cp
case "$cp" in
$DEVICE_TYPE_UFS|$DEVICE_TYPE_DISK)
- cp="$msg_file_system";;
- $DEVICE_TYPE_DIRECTORY)
- cp="$msg_directory";;
- $DEVICE_TYPE_FLOPPY)
- cp="$msg_floppy";;
- $DEVICE_TYPE_FTP)
- cp="$msg_ftp";;
- $DEVICE_TYPE_HTTP_PROXY)
- cp="$msg_http_proxy";;
- $DEVICE_TYPE_CDROM)
- cp="$msg_cdrom";;
- $DEVICE_TYPE_USB)
- cp="$msg_usb";;
- $DEVICE_TYPE_DOS)
- cp="$msg_dos";;
- $DEVICE_TYPE_NFS)
- cp="$msg_nfs";;
+ cp="$msg_file_system" ;;
+ $DEVICE_TYPE_DIRECTORY) cp="$msg_directory" ;;
+ $DEVICE_TYPE_FLOPPY) cp="$msg_floppy" ;;
+ $DEVICE_TYPE_FTP) cp="$msg_ftp" ;;
+ $DEVICE_TYPE_HTTP_PROXY) cp="$msg_http_proxy" ;;
+ $DEVICE_TYPE_HTTP) cp="$msg_http_direct" ;;
+ $DEVICE_TYPE_CDROM) cp="$msg_cdrom" ;;
+ $DEVICE_TYPE_USB) cp="$msg_usb" ;;
+ $DEVICE_TYPE_DOS) cp="$msg_dos" ;;
+ $DEVICE_TYPE_NFS) cp="$msg_nfs" ;;
*)
cp="<$msg_unknown>"
esac
@@ -178,6 +182,11 @@ f_media_options_menu()
' $msg_media_timeout' '$cp'
'$msg_timeout_value_in_seconds_for_slow_media'"
+ f_getvar $VAR_PKG_TMPDIR cp
+ menu_list="$menu_list
+ ' $msg_package_temp' '$cp'
+ '$msg_directory_where_package_temporary_files_go'"
+
menu_list="$menu_list
' $msg_rescan_devices' '<*>'
'$msg_rerun_bsdconfig_initial_device_probe'
@@ -185,33 +194,34 @@ f_media_options_menu()
'$msg_reset_all_values_to_startup_defaults'
" # END-QUOTE
- size=$( eval f_dialog_menu_with_help_size \
- \"\$title\" \
- \"\$btitle\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu
+ local height width rows
+ eval f_dialog_menu_with_help_size height width rows \
+ \"\$title\" \
+ \"\$btitle\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
- dialog_menu=$( eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --hline \"\$hline\" \
- --item-help \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_done\" \
- --help-button \
- --help-label \"\$msg_help\" \
- ${USE_XDIALOG:+--help \"\"} \
- --menu \"\$prompt\" $size $menu_list \
+ local mtag
+ mtag=$( eval $DIALOG \
+ --title \"\$title\" \
+ --backtitle \"\$btitle\" \
+ --hline \"\$hline\" \
+ --item-help \
+ --ok-label \"\$msg_ok\" \
+ --cancel-label \"\$msg_done\" \
+ --help-button \
+ --help-label \"\$msg_help\" \
+ --default-item \"\$defaultitem\" \
+ ${USE_XDIALOG:+--help \"\"} \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
-
- local mtag
- mtag=$( f_dialog_menutag )
+ f_dialog_data_sanitize mtag
+ defaultitem="$mtag"
f_dprintf "retval=%s mtag=[%s]" $retval "$mtag"
if [ $retval -eq 2 ]; then
@@ -257,6 +267,12 @@ f_media_options_menu()
else
export $VAR_DEBUG=1
fi ;;
+ " $msg_yes_to_all")
+ if f_getvar $VAR_NO_CONFIRM cp && [ "$cp" ]; then
+ unset $VAR_NO_CONFIRM
+ else
+ export $VAR_NO_CONFIRM=1
+ fi ;;
" $msg_dhcp")
f_getvar $VAR_TRY_DHCP cp
if [ "$cp" = "YES" ]; then
@@ -287,6 +303,10 @@ f_media_options_menu()
f_variable_get_value $VAR_MEDIA_TIMEOUT \
"$msg_please_specify_the_number_of_seconds_to_wait"
;;
+ " $msg_package_temp")
+ f_variable_get_value $VAR_PKG_TMPDIR \
+ "$msg_please_specify_a_temporary_directory"
+ ;;
" $msg_rescan_devices")
f_device_rescan ;;
" $msg_use_defaults")
diff --git a/usr.sbin/bsdconfig/share/media/tcpip.subr b/usr.sbin/bsdconfig/share/media/tcpip.subr
index 0bf0487..6b4791e 100644
--- a/usr.sbin/bsdconfig/share/media/tcpip.subr
+++ b/usr.sbin/bsdconfig/share/media/tcpip.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_TCPIP_SUBR" ]; then _MEDIA_TCPIP_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_TCPIP_SUBR" ]; then _MEDIA_TCPIP_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,9 +31,9 @@ if [ ! "$_MEDIA_TCPIP_SUBR" ]; then _MEDIA_TCPIP_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/tcpip.subr
-f_include $BSDCFG_SHARE/struct.subr
f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/dialog.subr
+f_include $BSDCFG_SHARE/struct.subr
f_include $BSDCFG_SHARE/variable.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
@@ -411,8 +411,8 @@ f_validate_netmask()
# Return error if the field is an invalid integer
case "$field" in
- 0|128|192|224|240|248|252|254|255) :;;
- *) return 5;;
+ 0|128|192|224|240|248|252|254|255) : ;;
+ *) return 5 ;;
esac
nfields=$(( $nfields + 1 ))
@@ -456,20 +456,20 @@ f_dialog_validate_tcpip()
local ipnum masknum
if [ ! "$hostname" ]; then
- f_dialog_msgbox "$msg_must_specify_a_host_name_of_some_sort"
+ f_show_msg "$msg_must_specify_a_host_name_of_some_sort"
elif ! f_validate_hostname "$hostname"; then
- f_dialog_msgbox "$msg_invalid_hostname_value"
+ f_show_msg "$msg_invalid_hostname_value"
elif [ "$netmask" ] && ! f_validate_netmask "$netmask"; then
- f_dialog_msgbox "$msg_invalid_netmask_value"
+ f_show_msg "$msg_invalid_netmask_value"
elif [ "$nameserver" ] &&
- ! f_validate_ipaddr "$nameserver" &&
- ! f_validate_ipaddr6 "$nameserver"; then
- f_dialog_msgbox "$msg_invalid_name_server_ip_address_specified"
+ ! f_validate_ipaddr "$nameserver" &&
+ ! f_validate_ipaddr6 "$nameserver"; then
+ f_show_msg "$msg_invalid_name_server_ip_address_specified"
elif [ "$ipaddr" ] && ! f_validate_ipaddr "$ipaddr" "$netmask"; then
- f_dialog_msgbox "$msg_invalid_ipv4_address"
+ f_show_msg "$msg_invalid_ipv4_address"
elif [ "$gateway" -a "$gateway" != "NO" ] &&
- ! f_validate_gateway "$gateway" "$ipaddr" "$netmask"; then
- f_dialog_msgbox "$msg_invalid_gateway_ipv4_address_specified"
+ ! f_validate_gateway "$gateway" "$ipaddr" "$netmask"; then
+ f_show_msg "$msg_invalid_gateway_ipv4_address_specified"
else
return $SUCCESS
fi
@@ -593,7 +593,7 @@ f_ifconfig_netmask()
# This function is a two-parter. Below is the awk(1) portion of the function,
# afterward is the sh(1) function which utilizes the below awk script.
#
-f_route_get_default='
+f_route_get_default_awk='
BEGIN { found = 0 }
( $1 == "gateway:" ) \
{
@@ -1133,11 +1133,12 @@ f_device_dialog_tcp()
# Otherwise, ask the question interactively.
#
local try6
- if ! f_quietly f_getvar $VAR_NO_INET6 && {
+ if ! f_isset $VAR_NO_INET6 && {
{ f_getvar $VAR_TRY_RTSOL try6 && [ "$try6" = "YES" ]; } ||
{
- ! f_quietly f_getvar $VAR_TRY_RTSOL &&
- f_dialog_noyes "$msg_try_ipv6_configuration"
+ # Only prompt the user when VAR_TRY_RTSOL is unset
+ ! f_isset $VAR_TRY_RTSOL &&
+ f_dialog_noyes "$msg_try_ipv6_configuration"
}
}; then
local i
@@ -1169,8 +1170,9 @@ f_device_dialog_tcp()
#
local try4
if { f_getvar $VAR_TRY_DHCP try4 && [ "$try4" = "YES" ]; } || {
- ! f_quietly f_getvar $VAR_TRY_DHCP &&
- f_dialog_noyes "$msg_try_dhcp_configuration"
+ # Only prompt the user when VAR_TRY_DHCP is unset
+ ! f_isset $VAR_TRY_DHCP &&
+ f_dialog_noyes "$msg_try_dhcp_configuration"
}; then
f_quietly ifconfig $dev delete
f_quietly mkdir -p /var/db
@@ -1262,7 +1264,7 @@ f_device_dialog_tcp()
if f_netinteractive || f_interactive || [ ! "$_hostname" ]
then
[ ! "$_hostname" ] && f_interactive &&
- f_dialog_msgbox "$msg_hostname_variable_not_set"
+ f_show_msg "$msg_hostname_variable_not_set"
local title=" $msg_network_configuration "
local hline="$hline_alnum_arrows_punc_tab_enter"
@@ -1369,7 +1371,7 @@ f_device_dialog_tcp()
# Create a persistent menu instead
f_dialog_title "$msg_network_configuration"
- local prompt=""
+ local prompt=
while :; do
cp=$( $DIALOG \
@@ -1399,6 +1401,7 @@ f_device_dialog_tcp()
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
+ f_dialog_data_sanitize cp
f_dprintf "retval=%u mtag=[%s]" $retval "$cp"
if [ $retval -eq 2 ]; then
@@ -1421,29 +1424,23 @@ f_device_dialog_tcp()
"$_netmask" \
&& break ;;
"$msg_host_name_including_domain:")
- cp=$( f_dialog_input "$cp" \
- "$_hostname"
- ) && _hostname="$cp" ;;
+ f_dialog_input cp "$cp" "$_hostname" \
+ && _hostname="$cp" ;;
"$msg_ipv4_gateway:")
- cp=$( f_dialog_input "$cp" \
- "$_gateway"
- ) && _gateway="$cp" ;;
+ f_dialog_input cp "$cp" "$_gateway" \
+ && _gateway="$cp" ;;
"$msg_name_server:")
- cp=$( f_dialog_input "$cp" \
- "$_nameserver"
- ) && _nameserver="$cp" ;;
+ f_dialog_input cp "$cp" "$_nameserver" \
+ && _nameserver="$cp" ;;
"$msg_ipv4_address:")
- cp=$( f_dialog_input "$cp" \
- "$_ipaddr"
- ) && _ipaddr="$cp" ;;
+ f_dialog_input cp "$cp" "$_ipaddr" \
+ && _ipaddr="$cp" ;;
"$msg_netmask:")
- cp=$( f_dialog_input "$cp" \
- "$_netmask"
- ) && _netmask="$cp" ;;
+ f_dialog_input cp "$cp" "$_netmask" \
+ && _netmask="$cp" ;;
"$msg_extra_options_to_ifconfig")
- cp=$( f_dialog_input "$cp" \
- "$_extras"
- ) && _extras="$cp" ;;
+ f_dialog_input cp "$cp" "$_extras" \
+ && _extras="$cp" ;;
esac
done
@@ -1596,7 +1593,7 @@ f_device_select_tcp()
fi
done
- f_interactive && f_dialog_msgbox "$msg_no_network_devices"
+ f_interactive && f_show_msg "$msg_no_network_devices"
return $FAILURE
fi # $network_dev
@@ -1619,7 +1616,7 @@ f_device_select_tcp()
local retval=$SUCCESS
if [ ${cnt:=0} -eq 0 ]; then
- f_dialog_msgbox "$msg_no_network_devices"
+ f_show_msg "$msg_no_network_devices"
retval=$FAILURE
elif [ $cnt -eq 1 ]; then
f_device_dialog_tcp $dev
diff --git a/usr.sbin/bsdconfig/share/media/ufs.subr b/usr.sbin/bsdconfig/share/media/ufs.subr
index 0b70f09..cc63475 100644
--- a/usr.sbin/bsdconfig/share/media/ufs.subr
+++ b/usr.sbin/bsdconfig/share/media/ufs.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_UFS_SUBR" ]; then _MEDIA_UFS_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_UFS_SUBR" ]; then _MEDIA_UFS_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,11 +31,11 @@ if [ ! "$_MEDIA_UFS_SUBR" ]; then _MEDIA_UFS_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/ufs.subr
-f_include $BSDCFG_SHARE/struct.subr
f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/variable.subr
f_include $BSDCFG_SHARE/media/common.subr
+f_include $BSDCFG_SHARE/struct.subr
+f_include $BSDCFG_SHARE/variable.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr
@@ -152,19 +152,21 @@ f_media_init_ufs()
return $SUCCESS
}
-# f_media_get_ufs $device $file [$probe_only]
+# f_media_get_ufs $device $file [$probe_type]
#
# Returns data from $file on a mounted UFS partition device. Similar to cat(1).
-# $probe_only is currently unused by this media type.
+# If $probe_type is present and non-NULL, returns success if $file exists. If
+# $probe_type is equal to $PROBE_SIZE, prints the size of $file in bytes to
+# standard-out.
#
f_media_get_ufs()
{
- local dev="$1" file="$2" probe_only="$3"
+ local dev="$1" file="$2" probe_type="$3"
- f_dprintf "f_media_get_ufs: dev=[%s] file=[%s] probe_only=%s" \
- "$dev" "$file" "$probe_only"
+ f_dprintf "f_media_get_ufs: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
- f_media_generic_get "$MOUNTPOINT" "$file"
+ f_media_generic_get "$MOUNTPOINT" "$file" "$probe_type"
}
# f_media_shutdown_ufs $device
diff --git a/usr.sbin/bsdconfig/share/media/usb.subr b/usr.sbin/bsdconfig/share/media/usb.subr
index c7fc973..e345ae0 100644
--- a/usr.sbin/bsdconfig/share/media/usb.subr
+++ b/usr.sbin/bsdconfig/share/media/usb.subr
@@ -1,7 +1,7 @@
if [ ! "$_MEDIA_USB_SUBR" ]; then _MEDIA_USB_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MEDIA_USB_SUBR" ]; then _MEDIA_USB_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -31,11 +31,11 @@ if [ ! "$_MEDIA_USB_SUBR" ]; then _MEDIA_USB_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." media/usb.subr
-f_include $BSDCFG_SHARE/struct.subr
f_include $BSDCFG_SHARE/device.subr
f_include $BSDCFG_SHARE/dialog.subr
-f_include $BSDCFG_SHARE/variable.subr
f_include $BSDCFG_SHARE/media/common.subr
+f_include $BSDCFG_SHARE/struct.subr
+f_include $BSDCFG_SHARE/variable.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
f_include_lang $BSDCFG_LIBE/include/messages.subr
@@ -60,7 +60,7 @@ f_media_set_usb()
ndevs=$( set -- $devs; echo $# )
if [ ${ndevs:=0} -eq 0 ]; then
- f_dialog_msgbox "$msg_no_usb_devices_found"
+ f_show_msg "$msg_no_usb_devices_found"
return $FAILURE
elif [ $ndevs -gt 1 ]; then
local title="$msg_choose_a_usb_drive"
@@ -132,19 +132,21 @@ f_media_init_usb()
return $FAILURE
}
-# f_media_get_usb $device $file [$probe_only]
+# f_media_get_usb $device $file [$probe_type]
#
-# Returns data from $file on a mounted USB disk device. Similar to cat(1).
-# $probe_only is currently unused by this media type.
+# Returns data from $file on a mounted USB disk device. Similar to cat(1). If
+# $probe_type is present and non-NULL, returns success if $file exists. If
+# $probe_type is equal to $PROBE_SIZE, prints the size of $file in bytes to
+# standard-out.
#
f_media_get_usb()
{
- local dev="$1" file="$2" probe_only="$3"
+ local dev="$1" file="$2" probe_type="$3"
- f_dprintf "f_media_get_usb: dev=[%s] file=[%s] probe_only=%s" \
- "$dev" "$file" "$probe_only"
+ f_dprintf "f_media_get_usb: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
- f_media_generic_get "$MOUNTPOINT" "$file"
+ f_media_generic_get "$MOUNTPOINT" "$file" "$probe_type"
}
# f_media_shutdown_usb $device
diff --git a/usr.sbin/bsdconfig/share/mustberoot.subr b/usr.sbin/bsdconfig/share/mustberoot.subr
index 2ead592..765487d 100644
--- a/usr.sbin/bsdconfig/share/mustberoot.subr
+++ b/usr.sbin/bsdconfig/share/mustberoot.subr
@@ -1,7 +1,7 @@
if [ ! "$_MUSTBEROOT_SUBR" ]; then _MUSTBEROOT_SUBR=1
#
-# Copyright (c) 2006-2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2006-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_MUSTBEROOT_SUBR" ]; then _MUSTBEROOT_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -77,7 +77,7 @@ SECURE_DIVULGE_UNKNOWN_USER=
#
f_become_root_via_sudo()
{
- local msg hline size
+ local prompt hline height width rows msg
[ "$( id -u )" = "0" ] && return $SUCCESS
@@ -90,37 +90,35 @@ f_become_root_via_sudo()
#
local checkpath="${HOME%/}/.bsdconfig_uses_sudo"
if [ ! -e "$checkpath" ]; then
+ prompt=$( printf "$msg_you_are_not_root_but" bsdconfig )
msg=$( printf "$msg_always_try_sudo_when_run_as" "$USER" )
local menu_list="
'X' '$msg_cancel_exit'
'1' '$msg'
'2' '$msg_try_sudo_only_this_once'
" # END-QUOTE
- msg=$( printf "$msg_you_are_not_root_but" bsdconfig )
hline="$hline_arrows_tab_enter"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$msg\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu mtag retval
- dialog_menu=$( eval $DIALOG \
+
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ local mtag
+ mtag=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$msg\" $size \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
- retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
+ ) || f_die
+ f_dialog_data_sanitize mtag
case "$mtag" in
X) # Cancel/Exit
@@ -150,13 +148,13 @@ f_become_root_via_sudo()
#
# sudo(8) access denied. Prompt for their password.
#
- msg="$msg_please_enter_password"
+ prompt="$msg_please_enter_password"
hline="$hline_alnum_punc_tab_enter"
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$hline" )
+ f_dialog_inputbox_size height width \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$prompt" \
+ "$hline"
#
# Continue prompting until they either Cancel, succeed
@@ -166,37 +164,38 @@ f_become_root_via_sudo()
while [ $nfailures -lt $PASSWD_TRIES ]; do
if [ "$USE_XDIALOG" ]; then
password=$( $DIALOG \
- --title "$DIALOG_TITLE" \
- --backtitle "$DIALOG_BACKTITLE" \
- --hline "$hline" \
- --ok-label "$msg_ok" \
- --cancel-label "$msg_cancel" \
- --password --inputbox "$msg" $size \
- 2>&1 > /dev/null )
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$hline" \
+ --ok-label "$msg_ok" \
+ --cancel-label "$msg_cancel" \
+ --password --inputbox "$prompt" \
+ $height $width \
+ 2>&1 > /dev/null
+ )
retval=$?
# Catch X11-related errors
- [ $retval -eq 255 ] &&
+ if [ $retval -eq 255 ]; then
f_die $retval "$password"
+ elif [ $retval -ne 0 ]; then
+ # User cancelled
+ exit $retval
+ fi
else
- local dialog_inputbox
- dialog_inputbox=$( $DIALOG \
+ password=$( $DIALOG \
--title "$DIALOG_TITLE" \
--backtitle "$DIALOG_BACKTITLE" \
--hline "$hline" \
--ok-label "$msg_ok" \
--cancel-label "$msg_cancel" \
--insecure \
- --passwordbox "$msg" $size \
+ --passwordbox "$prompt" \
+ $height $width \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- password=$( f_dialog_inputstr )
+ ) || exit $?
fi
-
- # Exit if the user cancelled.
- [ $retval -eq $SUCCESS ] || exit $retval
+ debug= f_dialog_line_sanitize password
#
# Validate sudo(8) credentials
@@ -250,6 +249,7 @@ f_become_root_via_sudo()
fi
# Re-execute ourselves with sudo(8)
+ f_dprintf "%s: Becoming root via sudo(8)..." mustberoot.subr
if [ $ARGC -gt 0 ]; then
exec sudo "$0" $ARGV
else
@@ -271,7 +271,7 @@ f_become_root_via_sudo()
#
f_authenticate_some_user()
{
- local msg hline size width height
+ local msg hline height width
f_have sudo || f_die 1 "$msg_must_be_root_to_execute" "$pgm"
@@ -288,14 +288,12 @@ f_authenticate_some_user()
msg="$msg_please_enter_username_password"
hline="$hline_alnum_punc_tab_enter"
- size=$( f_xdialog_2inputsbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$field_username" "" \
- "$field_password" "" )
- width="${size##*[$IFS]}"
- height="${size%%[$IFS]*}"
+ f_xdialog_2inputsbox_size height width \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$msg" \
+ "$field_username" "" \
+ "$field_password" ""
height=$(( $height + 2 )) # Add height for --password
#
@@ -332,7 +330,7 @@ f_authenticate_some_user()
unset user_pass # scrub memory
if [ ! "$user" ]; then
nfailures=$(( $nfailures + 1 ))
- f_dialog_msgbox "$msg_no_username"
+ f_show_msg "$msg_no_username"
continue
fi
if [ ! "$SECURE_ALLOW_ROOT" ]; then
diff --git a/usr.sbin/bsdconfig/share/packages/Makefile b/usr.sbin/bsdconfig/share/packages/Makefile
new file mode 100644
index 0000000..2a02353
--- /dev/null
+++ b/usr.sbin/bsdconfig/share/packages/Makefile
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+NO_OBJ=
+
+FILESDIR= ${SHAREDIR}/bsdconfig/packages
+FILES= categories.subr index.subr packages.subr
+
+beforeinstall:
+ mkdir -p ${DESTDIR}${FILESDIR}
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/bsdconfig/share/packages/categories.subr b/usr.sbin/bsdconfig/share/packages/categories.subr
new file mode 100755
index 0000000..dd2fa8f
--- /dev/null
+++ b/usr.sbin/bsdconfig/share/packages/categories.subr
@@ -0,0 +1,207 @@
+if [ ! "$_PACKAGES_CATEGORIES_SUBR" ]; then _PACKAGES_CATEGORIES_SUBR=1
+#
+# Copyright (c) 2013 Devin Teske
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+############################################################ INCLUDES
+
+BSDCFG_SHARE="/usr/share/bsdconfig"
+. $BSDCFG_SHARE/common.subr || exit 1
+f_dprintf "%s: loading includes..." packages/categories.subr
+f_include $BSDCFG_SHARE/strings.subr
+
+BSDCFG_LIBE="/usr/libexec/bsdconfig"
+f_include_lang $BSDCFG_LIBE/include/messages.subr
+
+############################################################ GLOBALS
+
+CATEGORIES=
+
+############################################################ FUNCTIONS
+
+# f_category_desc_get $category [$var_to_set]
+#
+# Fetch the description of a given category. Returns success if a match was
+# found, otherwise failure.
+#
+# If $var_to_set is missing or NULL, the category description is printed to
+# standard out for capturing in a sub-shell (which is less-recommended because
+# of performance degredation; for example, when called in a loop).
+#
+f_category_desc_get()
+{
+ local __category="$1" __var_to_set="$2" __cat __varcat
+
+ # Return failure if $category
+ [ "$__category" ] || return $FAILURE
+
+ for __cat in $CATEGORIES; do
+ [ "$__cat" = "$__category" ] || continue
+ f_str2varname $__cat __varcat
+ f_getvar _category_$__varcat $__var_to_set
+ return $?
+ done
+ return $FAILURE
+}
+
+# f_category_desc_set $category $desc
+#
+# Store a description in-association with a category. $category should be
+# alphanumeric and can include the underscore [_] but should not contain
+# whitespace. Returns success unless $category is NULL or no arguments. Use the
+# f_category_desc_get() routine with the same $category to retrieve the stored
+# description.
+#
+f_category_desc_set()
+{
+ local category="$1" desc="$2"
+ local cat varcat found=
+ [ "$category" ] || return $FAILURE
+ for cat in $CATEGORIES; do
+ [ "$cat" = "$category" ] || continue
+ f_str2varname $cat varcat
+ f_isset _category_$varcat || continue
+ found=1 && break
+ done
+ if [ ! "$found" ]; then
+ CATEGORIES="$CATEGORIES $category"
+ fi
+ f_str2varname $category varcat
+ setvar "_category_$varcat" "$desc"
+ # Export the variable for awk(1) ENVIRON visibility
+ export "_category_$varcat"
+ return $SUCCESS
+}
+
+############################################################ MAIN
+
+#
+# Load descriptions for package categories. Note that we don't internationalize
+# category names because this would be confusing for people used to browsing
+# the FTP mirrors or are otherwise familiar with an interface that does not
+# provide internationalized names. The descriptions can be used to provide i18n
+# users a description of the non-i18n category name.
+#
+f_category() { f_category_desc_set "$1" "$2"; }
+f_category All "$msg_all_desc"
+f_category accessibility "$msg_accessibility_desc"
+f_category afterstep "$msg_afterstep_desc"
+f_category arabic "$msg_arabic_desc"
+f_category archivers "$msg_archivers_desc"
+f_category astro "$msg_astro_desc"
+f_category audio "$msg_audio_desc"
+f_category benchmarks "$msg_benchmarks_desc"
+f_category biology "$msg_biology_desc"
+f_category cad "$msg_cad_desc"
+f_category chinese "$msg_chinese_desc"
+f_category comms "$msg_comms_desc"
+f_category converters "$msg_converters_desc"
+f_category databases "$msg_databases_desc"
+f_category deskutils "$msg_deskutils_desc"
+f_category devel "$msg_devel_desc"
+f_category dns "$msg_dns_desc"
+f_category docs "$msg_docs_desc"
+f_category editors "$msg_editors_desc"
+f_category elisp "$msg_elisp_desc"
+f_category emulators "$msg_emulators_desc"
+f_category enlightenment "$msg_enlightenment_desc"
+f_category finance "$msg_finance_desc"
+f_category french "$msg_french_desc"
+f_category ftp "$msg_ftp_desc"
+f_category games "$msg_games_desc"
+f_category geography "$msg_geography_desc"
+f_category german "$msg_german_desc"
+f_category gnome "$msg_gnome_desc"
+f_category gnustep "$msg_gnustep_desc"
+f_category graphics "$msg_graphics_desc"
+f_category hamradio "$msg_hamradio_desc"
+f_category haskell "$msg_haskell_desc"
+f_category hebrew "$msg_hebrew_desc"
+f_category hungarian "$msg_hungarian_desc"
+f_category ipv6 "$msg_ipv6_desc"
+f_category irc "$msg_irc_desc"
+f_category japanese "$msg_japanese_desc"
+f_category java "$msg_java_desc"
+f_category kde "$msg_kde_desc"
+f_category kld "$msg_kld_desc"
+f_category korean "$msg_korean_desc"
+f_category lang "$msg_lang_desc"
+f_category linux "$msg_linux_desc"
+f_category lisp "$msg_lisp_desc"
+f_category mail "$msg_mail_desc"
+f_category math "$msg_math_desc"
+f_category mbone "$msg_mbone_desc"
+f_category misc "$msg_misc_desc"
+f_category multimedia "$msg_multimedia_desc"
+f_category net "$msg_net_desc"
+f_category net-im "$msg_net_im_desc"
+f_category net-mgmt "$msg_net_mgmt_desc"
+f_category net-p2p "$msg_net_p2p_desc"
+f_category news "$msg_news_desc"
+f_category palm "$msg_palm_desc"
+f_category parallel "$msg_parallel_desc"
+f_category pear "$msg_pear_desc"
+f_category perl5 "$msg_perl5_desc"
+f_category plan9 "$msg_plan9_desc"
+f_category polish "$msg_polish_desc"
+f_category ports-mgmt "$msg_ports_mgmt_desc"
+f_category portuguese "$msg_portuguese_desc"
+f_category print "$msg_print_desc"
+f_category python "$msg_python_desc"
+f_category ruby "$msg_ruby_desc"
+f_category rubygems "$msg_rubygems_desc"
+f_category russian "$msg_russian_desc"
+f_category scheme "$msg_scheme_desc"
+f_category science "$msg_science_desc"
+f_category security "$msg_security_desc"
+f_category shells "$msg_shells_desc"
+f_category spanish "$msg_spanish_desc"
+f_category sysutils "$msg_sysutils_desc"
+f_category tcl "$msg_tcl_desc"
+f_category textproc "$msg_textproc_desc"
+f_category tk "$msg_tk_desc"
+f_category ukrainian "$msg_ukrainian_desc"
+f_category vietnamese "$msg_vietnamese_desc"
+f_category windowmaker "$msg_windowmaker_desc"
+f_category www "$msg_www_desc"
+f_category x11 "$msg_x11_desc"
+f_category x11-clocks "$msg_x11_clocks_desc"
+f_category x11-drivers "$msg_x11_drivers_desc"
+f_category x11-fm "$msg_x11_fm_desc"
+f_category x11-fonts "$msg_x11_fonts_desc"
+f_category x11-servers "$msg_x11_servers_desc"
+f_category x11-themes "$msg_x11_themes_desc"
+f_category x11-toolkits "$msg_x11_toolkits_desc"
+f_category x11-wm "$msg_x11_wm_desc"
+f_category xfce "$msg_xfce_desc"
+f_category zope "$msg_zope_desc"
+
+f_dprintf "%s: Initialized %u package category descriptions." \
+ packages/categories.subr "$( set -- $CATEGORIES; echo $# )"
+
+f_dprintf "%s: Successfully loaded." packages/categories.subr
+
+fi # ! $_PACKAGES_CATEGORIES_SUBR
diff --git a/usr.sbin/bsdconfig/share/packages/index.subr b/usr.sbin/bsdconfig/share/packages/index.subr
new file mode 100755
index 0000000..863249c
--- /dev/null
+++ b/usr.sbin/bsdconfig/share/packages/index.subr
@@ -0,0 +1,287 @@
+if [ ! "$_PACKAGES_INDEX_SUBR" ]; then _PACKAGES_INDEX_SUBR=1
+#
+# Copyright (c) 2013 Devin Teske
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+############################################################ INCLUDES
+
+BSDCFG_SHARE="/usr/share/bsdconfig"
+. $BSDCFG_SHARE/common.subr || exit 1
+f_dprintf "%s: loading includes..." packages/index.subr
+f_include $BSDCFG_SHARE/device.subr
+f_include $BSDCFG_SHARE/media/common.subr
+f_include $BSDCFG_SHARE/strings.subr
+
+BSDCFG_LIBE="/usr/libexec/bsdconfig"
+f_include_lang $BSDCFG_LIBE/include/messages.subr
+
+############################################################ GLOBALS
+
+PACKAGE_INDEX=
+_INDEX_INITTED=
+
+############################################################ FUNCTIONS
+
+# f_index_initialize $path [$var_to_set]
+#
+# Read and initialize the global index. $path is to be relative to the chosen
+# media (not necessarily the filesystem; e.g. FTP) -- this is usually going to
+# be `packages/INDEX'. Returns success unless media cannot be initialized for
+# any reason (e.g. user cancels media selection dialog) or an error occurs. The
+# index is sorted before being loaded into $var_to_set.
+#
+# NOTE: The index is processed with f_index_read() [below] after being loaded.
+#
+f_index_initialize()
+{
+ local __path="$1" __var_to_set="${2:-PACKAGE_INDEX}"
+
+ [ "$_INDEX_INITTED" ] && return $SUCCESS
+ [ "$__path" ] || return $FAILURE
+
+ # Got any media?
+ f_media_verify || return $FAILURE
+
+ # Does it move when you kick it?
+ f_device_init media || return $FAILURE
+
+ f_show_info "$msg_attempting_to_fetch_file_from_selected_media" \
+ "$__path"
+ eval "$__var_to_set"='$( f_device_get media "$__path" )'
+ if [ $? -ne $SUCCESS ]; then
+ f_show_msg "$msg_unable_to_get_file_from_selected_media" \
+ "$__path"
+ f_device_shutdown media
+ return $FAILURE
+ fi
+ eval "$__var_to_set"='$( debug= f_getvar "$__var_to_set" | sort )'
+
+ f_show_info "$msg_located_index_now_reading_package_data_from_it"
+ if ! f_index_read "$__var_to_set"; then
+ f_show_msg "$msg_io_or_format_error_on_index_file" "$__path"
+ return $FAILURE
+ fi
+
+ _INDEX_INITTED=1
+ return $SUCCESS
+}
+
+# f_index_read [$var_to_get]
+#
+# Process the INDEX file (contents contained in $var_to_get) and...
+#
+# 1. create a list ($CATEGORY_MENU_LIST) of categories with package counts
+# 2. For convenience, create $_npkgs holding the total number of all packages
+# 3. extract associative categories for each package into $_categories_$varpkg
+# 4. extract runtime dependencies for each package into $_rundeps_$varpkg
+# 5. extract a [sorted] list of categories into $PACKAGE_CATEGORIES
+# 6. create $_npkgs_$varcat holding the total number of packages in category
+#
+# NOTE: $varpkg is the product of f_str2varname $package varpkg
+# NOTE: $package is the name as it appears in the INDEX (no archive suffix)
+# NOTE: We only show categories for which there are at least one package.
+# NOTE: $varcat is the product of f_str2varname $category varcat
+#
+f_index_read()
+{
+ local var_to_get="${1:-PACKAGE_INDEX}"
+
+ # Export variables required by awk(1) below
+ export msg_no_description_provided
+ export msg_all msg_all_desc
+ export VALID_VARNAME_CHARS
+ export msg_packages
+
+ eval "$( debug= f_getvar "$var_to_get" | awk -F'|' '
+ function asorti(src, dest)
+ {
+ # Copy src indices to dest and calculate array length
+ nitems = 0; for (i in src) dest[++nitems] = i
+
+ # Sort the array of indices (dest) using insertion sort method
+ for (i = 1; i <= nitems; k = i++)
+ {
+ idx = dest[i]
+ while ((k > 0) && (dest[k] > idx))
+ {
+ dest[k+1] = dest[k]
+ k--
+ }
+ dest[k+1] = idx
+ }
+
+ return nitems
+ }
+ function print_category(category, npkgs, desc)
+ {
+ cat = category
+ # Accent the category if the first page has been
+ # cached (also acting as a visitation indicator)
+ if ( ENVIRON["_index_page_" varcat "_1"] )
+ cat = cat "*"
+ printf "'\''%s'\'' '\''%s " packages "'\'' '\''%s'\''\n",
+ cat, npkgs, desc
+ }
+ BEGIN {
+ valid_chars = ENVIRON["VALID_VARNAME_CHARS"]
+ default_desc = ENVIRON["msg_no_description_provided"]
+ packages = ENVIRON["msg_packages"]
+ tpkgs = 0
+ prefix = ""
+ }
+ {
+ tpkgs++
+ varpkg = $1
+ gsub("[^" valid_chars "]", "_", varpkg)
+ print "_categories_" varpkg "=\"" $7 "\""
+ split($7, pkg_categories, /[[:space:]]+/)
+ for (pkg_category in pkg_categories)
+ categories[pkg_categories[pkg_category]]++
+ print "_rundeps_" varpkg "=\"" $9 "\""
+ }
+ END {
+ print "_npkgs=" tpkgs # For convenience, total package count
+
+ n = asorti(categories, categories_sorted)
+
+ # Produce package counts for each category
+ for (i = 1; i <= n; i++)
+ {
+ cat = varcat = categories_sorted[i]
+ npkgs = categories[cat]
+ gsub("[^" valid_chars "]", "_", varcat)
+ print "_npkgs_" varcat "=\"" npkgs "\""
+ }
+
+ # Create menu list and generate list of categories at same time
+ print "CATEGORY_MENU_LIST=\""
+ print_category(ENVIRON["msg_all"], tpkgs,
+ ENVIRON["msg_all_desc"])
+ category_list = ""
+ for (i = 1; i <= n; i++)
+ {
+ cat = varcat = categories_sorted[i]
+ npkgs = categories[cat]
+ cur_prefix = tolower(substr(cat, 1, 1))
+ if ( prefix != cur_prefix )
+ prefix = cur_prefix
+ else
+ cat = " " cat
+ gsub("[^" valid_chars "]", "_", varcat)
+ desc = ENVIRON["_category_" varcat]
+ if ( ! desc ) desc = default_desc
+ print_category(cat, npkgs, desc)
+ category_list = category_list " " cat
+ }
+ print "\""
+
+ # Produce the list of categories (calculated in above block)
+ sub(/^ /, "", category_list)
+ print "PACKAGE_CATEGORIES=\"" category_list "\""
+
+ }' )" # End-Quote
+}
+
+# f_index_extract_pages $var_to_get $var_basename $pagesize [$category]
+#
+# Extracts the package INDEX ($PACKAGE_INDEX by default if/when $var_to_get is
+# NULL; but should not be missing) into a series of sequential variables
+# corresponding to "pages" containing up to $pagesize packages. The package
+# INDEX data must be contained in the variable $var_to_get. The extracted pages
+# are stored in variables ${var_basename}_# -- where "#" is a the page number.
+# If $category is set, only packages for that category are extracted.
+# Otherwise, if $category is "All", missing, or NULL, all packages are
+# extracted and no filtering is done.
+#
+f_index_extract_pages()
+{
+ local var_to_get="${1:-PACKAGE_INDEX}" var_basename="$2" pagesize="$3"
+ local category="$4" # Optional
+
+ eval "$(
+ debug= f_getvar "$var_to_get" | awk -F'|' \
+ -v cat="$category" \
+ -v pagesize="$pagesize" \
+ -v var_basename="$var_basename" \
+ -v i18n_all="$msg_all" '
+ BEGIN { n = page = 0 }
+ /'\''/{ gsub(/'\''/, "'\''\\'\'\''") }
+ {
+ if ( cat !~ "(^$|^" i18n_all "$)" && $7 !~ \
+ "(^|[[:space:]])" cat "([[:space:]]|$)" ) next
+ starting_new_page = (n++ == (pagesize * page))
+ if ( starting_new_page )
+ printf "%s%s", ( n > 1 ? "'\''\n" : "" ),
+ var_basename "_" ++page "='\''"
+ printf "%s%s", ( starting_new_page ? "" : "\n" ), $0
+ }
+ END { if ( n > 0 ) print "'\''" }'
+ )"
+}
+
+# f_index_search $var_to_get $name [$var_to_set]
+#
+# Search the package INDEX ($PACKAGE_INDEX by default if/when $var_to_get is
+# NULL; but should not be missing) for $name, returning the first match.
+# Matches are strict (not regular expressions) and must match the beginning
+# portion of the package name to be considered a match. If $var_to_set is
+# missing or NULL, output is sent to standard output. If a match is found,
+# returns success; otherwise failure.
+#
+f_index_search()
+{
+ local __var_to_get="${1:-PACKAGE_INDEX}" __pkg_basename="$2"
+ local __var_to_set="$3"
+
+ f_dprintf "f_index_search: Searching package data (in %s) for %s" \
+ "$__var_to_get" "$__pkg_basename"
+
+ local __pkg=
+ __pkg=$( debug= f_getvar "$__var_to_get" |
+ awk -F'|' -v basename="$__pkg_basename" '
+ BEGIN { n = length(basename) }
+ substr($1, 0, n) == basename { print $1; exit }
+ ' )
+ if [ ! "$__pkg" ]; then
+ f_dprintf "f_index_search: No packages matching %s found" \
+ "$__pkg_basename"
+ return $FAILURE
+ fi
+
+ f_dprintf "f_index_search: Found package %s" "$__pkg"
+ if [ "$__var_to_set" ]; then
+ setvar "$__var_to_set" "$__pkg"
+ else
+ echo "$__pkg"
+ fi
+ return $SUCCESS
+}
+
+############################################################ MAIN
+
+f_dprintf "%s: Successfully loaded." packages/index.subr
+
+fi # ! $_PACKAGES_INDEX_SUBR
diff --git a/usr.sbin/bsdconfig/share/packages/packages.subr b/usr.sbin/bsdconfig/share/packages/packages.subr
new file mode 100755
index 0000000..e447b2e
--- /dev/null
+++ b/usr.sbin/bsdconfig/share/packages/packages.subr
@@ -0,0 +1,1202 @@
+if [ ! "$_PACKAGES_PACKAGES_SUBR" ]; then _PACKAGES_PACKAGES_SUBR=1
+#
+# Copyright (c) 2013 Devin Teske
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+#
+############################################################ INCLUDES
+
+BSDCFG_SHARE="/usr/share/bsdconfig"
+. $BSDCFG_SHARE/common.subr || exit 1
+f_dprintf "%s: loading includes..." "$0"
+f_include $BSDCFG_SHARE/dialog.subr
+f_include $BSDCFG_SHARE/device.subr
+f_include $BSDCFG_SHARE/media/common.subr
+f_include $BSDCFG_SHARE/packages/categories.subr
+f_include $BSDCFG_SHARE/packages/index.subr
+f_include $BSDCFG_SHARE/strings.subr
+
+BSDCFG_LIBE="/usr/libexec/bsdconfig"
+f_include_lang $BSDCFG_LIBE/include/messages.subr
+
+############################################################ CONFIGURATION
+
+#
+# How many packages to display (maximum) per dialog menubox.
+#
+: ${PACKAGE_MENU_PAGESIZE:=2000}
+
+############################################################ GLOBALS
+
+#
+# Package extensions to try
+#
+PACKAGE_EXTENSIONS=".tbz .tbz2 .tgz"
+
+#
+# Variables used to track runtime states
+#
+PACKAGES_DETECTED= # Boolean (NULL/non-NULL); detected installed packages?
+PACKAGE_CATEGORIES= # List of package categories parsed from INDEX
+SELECTED_PACKAGES= # Packages selected by user in [X]dialog(1) interface
+
+#
+# Options
+#
+[ "${SHOW_DESC+set}" ] || SHOW_DESC=1
+
+############################################################ FUNCTIONS
+
+# eval f_package_accent_category_menu $var_to_set $CATEGORY_MENU_LIST
+#
+# Accent the CATEGORY_MENU_LIST produced by f_index_read() (see
+# packages/index.subr). Accented information includes adding an asterisk to the
+# category name if its index has been cached, adding the number of installed
+# packages for each category, and adding the number _selected_ packages for
+# each category.
+#
+# NOTE: The reason `eval' is recommended/shown for the syntax above is because
+# the $CATEGORY_MENU_LIST generated by f_index_read() is meant to be expanded
+# prior to execution (it contains a series of pre-quoted strings which act as
+# the interpolated command arguments).
+#
+f_package_accent_category_menu()
+{
+ local var_to_set="$1" category cat desc help varcat menu_buf n
+ shift 1 # var_to_set
+ while [ $# -gt 0 ]; do
+ category="${1%\*}" desc="${2%%; *}" help="$3"
+ shift 3 # cat/desc/help
+
+ cat="${category# }" # Trim lead space inserted by sort-method
+ f_str2varname "$cat" varcat
+
+ # Add number of installed packages for this category (if any)
+ n=0
+ case "$cat" in
+ "$msg_all") debug= f_getvar "_All_ninstalled" n ;;
+ *) debug= f_getvar "_${varcat}_ninstalled" n ;;
+ esac &&
+ [ $n -ge 1 ] && desc="$desc; $n $msg_installed_lc"
+
+ # Add number of selected packages for this category (if any)
+ n=0
+ case "$cat" in
+ "$msg_all") debug= f_getvar "_All_nselected" n ;;
+ *) debug= f_getvar "_${varcat}_nselected" n ;;
+ esac &&
+ [ $n -ge 1 ] && desc="$desc; $n $msg_selected"
+
+ # Re-Add asterisk to the category if its index has been cached
+ f_isset _index_page_${varcat}_1 && category="$category*"
+
+ # Update buffer with modified elements
+ menu_buf="$menu_buf
+ '$category' '$desc' '$help'" # End-Quote
+ done
+ setvar "$var_to_set" "$menu_buf" # return our buffer
+}
+
+# f_package_select $package ...
+#
+# Add $package to the list of tracked/selected packages. If $package is already
+# being tracked (already apears in $SELECTED_PACKAGES), this function amounts
+# to having no effect.
+#
+f_package_select()
+{
+ local package pkgsel
+ while [ $# -gt 0 ]; do
+ package="$1"
+ shift 1 # package
+ for pkgsel in $SELECTED_PACKAGES; do
+ [ "$package" = "$pkgsel" ] && return
+ done
+ SELECTED_PACKAGES="$SELECTED_PACKAGES $package"
+ f_dprintf "Added %s to selection list" "$package"
+ done
+ SELECTED_PACKAGES="${SELECTED_PACKAGES# }" # Trim leading space
+}
+
+# f_package_deselect $package ...
+#
+# Remove $package from teh list of tracked/selected packages. If $package is
+# not being tracked (doesn't appear in $SELECTED_PACKAGES), this function
+# amounts to having no effet.
+#
+f_package_deselect()
+{
+ local package pkgsel
+ while [ $# -gt 1 ]; do
+ local new_list=""
+ package="$1"
+ shift 1 # package
+ for pkgsel in $SELECTED_PACKAGES; do
+ [ "$pkgsel" = "$package" ] && continue
+ new_list="$new_list${new_list:+ }$pkgsel"
+ done
+ SELECTED_PACKAGES="$new_list"
+ f_dprintf "Removed %s from selection list" "$package"
+ done
+}
+
+# f_package_detect_installed
+#
+# Detect installed packages. Currently this searches /var/db/pkg for directory
+# entries and marks each entry as an installed/selected package.
+#
+f_package_detect_installed()
+{
+ local installed package varpkg
+ #
+ # XXX KLUDGE ALERT! This makes evil assumptions about how XXX
+ # packages register themselves and should *really* be done with
+ # `pkg_info -e <name>' except that this is too slow for an
+ # item check routine.. :-(
+ #
+ # NOTE: When transitioning to pkgng, make a single fork to `pkg' to
+ # produce a list of all installed packages and parse _that_
+ #
+ installed=$( find -s /var/db/pkg -mindepth 1 -maxdepth 1 -type d |
+ sed -e 's:/var/db/pkg/::' )
+ for package in $installed; do
+ f_str2varname $package varpkg
+ export _mark_$varpkg=X # exported for awk(1) ENVIRON[]
+ f_package_select $package
+ done
+}
+
+# f_package_calculate_totals
+#
+# Calculate number of installed/selected packages for each category listed in
+# $PACKAGE_CATEGORIES (the number of installed packages for $category is stored
+# as $_${varcat}_ninstalled -- where $varcat is the product of `f_str2varname
+# $category varcat' -- and number selected packages as $_${varcat}_nselected).
+# Also calculates the total number of installed/selected packages stored as
+# $_All_ninstalled and $_All_nselected.
+#
+# Calculations are peformed by checking "marks". A "mark" is stored as
+# $_mark_$varpkg -- where $varpkg is the product of `f_str2varname $package
+# varpkg'. A mark can be "X" for an installed package, `I' for a package that
+# is marked for installation, "R" for a package that is marked for re-install,
+# and "U" for a package that is marked for uninstallation. If a package mark is
+# NULL or a single space (e.g., " "), the package is considered to be NOT
+# selected (and therefore does not increment the counts calculated herein).
+#
+f_package_calculate_totals()
+{
+ local pkg varpkg mark cat varcat pkgcat n tselected=0 tinstalled=0
+ for cat in $PACKAGE_CATEGORIES; do
+ f_str2varname $cat varcat
+ setvar _${varcat}_ninstalled=0
+ setvar _${varcat}_nselected=0
+ done
+ for pkg in $SELECTED_PACKAGES; do
+ f_str2varname $pkg varpkg
+ mark=
+ f_getvar _mark_$varpkg mark
+ case "$mark" in
+ ""|" ") : ;;
+ X) tinstalled=$(( $tinstalled + 1 )) ;;
+ *) tselected=$(( $tselected + 1 ))
+ esac
+ f_getvar _categories_$varpkg pkgcat
+ for cat in $pkgcat; do
+ f_str2varname $cat varcat
+ case "$mark" in
+ ""|" ") : ;;
+ X) debug= f_getvar _${varcat}_ninstalled n
+ setvar _${varcat}_ninstalled $(( $n + 1 )) ;;
+ *) debug= f_getvar _${varcat}_nselected n
+ setvar _${varcat}_nselected $(( $n + 1 ))
+ esac
+ done
+ done
+ _All_nselected=$tselected
+ _All_ninstalled=$tinstalled
+}
+
+# f_package_calculate_rundeps
+#
+# Update package dependencies by first unmarking all dependencies and then
+# re-marking all dependencies of packages marked for either install ("I") or
+# re-install ("R").
+#
+f_package_calculate_rundeps()
+{
+ local pkg varpkg mark rundeps dep vardep
+
+ #
+ # First unmark all the existing run-dependencies
+ #
+ f_dprintf "Unselecting package run-dependencies..."
+ for pkg in $SELECTED_PACKAGES; do
+ f_str2varname $pkg varpkg
+ mark=
+ debug= f_getvar _mark_$varpkg mark
+ # Only unmark if it's marked as a Dependency
+ if [ "$mark" = "D" ]; then
+ f_dprintf "%s unselected" $pkg
+ unset _mark_$varpkg
+ f_package_deselect $pkg
+ fi
+ done
+
+ #
+ # Processes selected packages, adding dependencies
+ #
+ f_dprintf "Re-selecting package run-dependencies..."
+ for pkg in $SELECTED_PACKAGES; do
+ f_str2varname $pkg varpkg
+ mark=
+ debug= f_getvar _mark_$varpkg mark
+ # Skip pkg unless marked for [Re-]Install
+ [ "$mark" = "I" -o "$mark" = "R" ] || continue
+ f_getvar _rundeps_$varpkg rundeps
+ for dep in $rundeps; do
+ f_str2varname $dep vardep
+ mark=
+ debug= f_getvar _mark_$vardep mark
+ # Skip dep if already marked
+ [ "${mark:- }" = " " ] || continue
+ export _mark_$vardep="D"
+ f_package_select $dep
+ done
+ done
+
+ f_dprintf "Finished recalculating dependencies."
+}
+
+# f_package_menu_categories $var_to_set $defaultitem
+#
+# Dislay the menu of package categories, complete with package counts for each
+# category, accents, and other miscellany. If $defaultitem is non-NULL and
+# matches one of the existing menu-items, it will be pre-highlighted in the
+# menu dialog (HINT: Use f_dialog_menutag_fetch() to populate a local variable
+# that is passed as $defaultitem to highlight the user's last selection).
+#
+f_package_menu_categories()
+{
+ local var_to_get="$1" defaultitem="$2"
+ local prompt="$msg_please_select_a_category_to_display"
+ local menu_list="
+ '> $msg_review' '$msg_review_desc' '$msg_review_help'
+ " # End-Quote
+ local hline=
+
+ f_package_calculate_rundeps
+ # updates package mark variables and SELECTED_PACKAGES
+ f_package_calculate_totals
+ # creates _{varcat}_ninstalled and _{varcat}_nselected
+
+ local category_list
+ debug= f_getvar "$var_to_get" category_list || return $FAILURE
+
+ # Accent the category menu list with ninstalled/nselected
+ eval f_package_accent_category_menu category_list $category_list
+
+ # Add list of categories to menu list
+ menu_list="$menu_list $category_list"
+
+ local height width rows
+ eval f_dialog_menu_with_help_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
+ --backtitle \"\$DIALOG_BACKTITLE\" \
+ --hline \"\$hline\" \
+ --item-help \
+ --default-item \"\$defaultitem\" \
+ --ok-label \"$msg_select\" \
+ --cancel-label \"$msg_cancel\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
+ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+ )
+ local retval=$?
+ f_dialog_menutag_store -s "$menu_choice"
+ return $retval
+}
+
+# f_package_index_get_page $category $page [$var_to_set [$var_to_get]]
+#
+# Obtain a [potentially cached] page of the INDEX file for a given $category.
+# If $page is 1 and the cache has not yet been generated, the cache-generating
+# function f_index_extract_pages() (above) is called to generate all pages
+# (not just the requested page) in cache before returning the requested page.
+# If $page is not 1 and there is no cached page, failure status is returned.
+#
+f_package_index_get_page()
+{
+ local category="$1" page="$2" var_to_set="$3" var_to_get="$4" varcat
+ f_str2varname "$category" varcat
+ if ! debug= f_getvar "_index_page_${varcat}_$page" $var_to_set &&
+ [ "$page" = "1" ]
+ then
+ f_show_info "$msg_building_package_menus"
+ local pagesize="$PACKAGE_MENU_PAGESIZE"
+ f_index_extract_pages "${var_to_get:-PACKAGE_INDEX}" \
+ _index_page_${varcat} "$pagesize" "$category"
+ debug= f_getvar _index_page_${varcat}_$page $var_to_set
+
+ # Update category default-item because now we're cached
+ [ $page -eq 1 ] &&
+ category_defaultitem="${category_defaultitem%\*}*"
+ else
+ return $FAILURE
+ fi
+}
+
+# f_package_menu_select $category [$page [$defaultitem]]
+#
+# Display list of packages for $category, optionally $page N and with a default
+# item selected. If $page is omitted, the first page is displayed (but this
+# only matters if there are multiple pages; which is determined by the global
+# maximum $PACKAGE_MENU_PAGESIZE).
+#
+# On success, if the user doesn't press ESC or choose Cancel, use
+# f_dialog_menuitem_fetch() to populate a local variable with the item (not
+# tag) corresponding to the user's selection. The tag portion of the user's
+# selection is available through f_dialog_menutag_fetch().
+#
+f_package_menu_select()
+{
+ local category="$1" page="${2:-1}"
+ local prompt= # Calculated below
+ local menu_list # Calculated below
+ local defaultitem="$3"
+ local hline="$hline_arrows_tab_punc_enter"
+
+ f_isinteger "$page" || return $FAILURE
+
+ local varcat
+ f_str2varname "$category" varcat
+
+ # Get number of packages for this category
+ local npkgs=0
+ case "$category" in
+ "$msg_all"|"") npkgs="${_npkgs:-0}" ;;
+ *) f_getvar _npkgs_$varcat npkgs
+ esac
+
+ # Calculate number of pages
+ local npages=$(( ${npkgs:=0} / $PACKAGE_MENU_PAGESIZE ))
+
+ # Add a page to the pagecount if not evenly divisible
+ [ $(( $npages * $PACKAGE_MENU_PAGESIZE )) -lt $npkgs ] &&
+ npages=$(( $npages + 1 ))
+
+ # Print some debugging information
+ f_dprintf "f_package_menu_select: category=[%s] npkgs=%u npages=%u" \
+ "$category" "$npkgs" "$npages"
+
+ local add_prev="" add_next=""
+ local previous_page="$msg_previous_page" next_page="$msg_next_page"
+ if [ $page -gt 1 ]; then
+ add_prev=1
+ # Accent the `Previous Page' item with an asterisk
+ # if the page-before-previous is loaded/cached
+ f_isset _index_page_${varcat}_$(( $page - 1 )) &&
+ previous_page="$previous_page*"
+ fi
+ if [ $page -lt $npages ]; then
+ add_next=1
+ # Accent the `Next Page' item with an asterisk
+ # if the page-after-next is loaded/cached
+ f_isset _index_page_${varcat}_$(( $page + 1 )) &&
+ next_page="$next_page*"
+ fi
+
+ local index_page
+ f_package_index_get_page "$category" $page index_page
+
+ menu_list="
+ ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}}
+ ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}}
+ $(
+ export SHOW_DESC
+ export VALID_VARNAME_CHARS
+ echo "$index_page" | awk -F'|' -v view="port" '
+ BEGIN {
+ valid_chars = ENVIRON["VALID_VARNAME_CHARS"]
+ prefix = ""
+ }
+ {
+ cur_prefix = tolower(substr($1, 1, 1))
+ printf "'\''"
+ if ( prefix != cur_prefix )
+ prefix = cur_prefix
+ else
+ printf " "
+ package = $1
+ if ( view == "port" )
+ desc = $2
+ varpkg = package
+ gsub("[^" valid_chars "]", "_", varpkg)
+ mark = ENVIRON["_mark_" varpkg]
+ if ( ! mark ) mark = " "
+ printf "%s'\'' '\''[%c] %s'\''",
+ package, mark, desc
+ if ( ENVIRON["SHOW_DESC"] ) {
+ help = $4
+ gsub(/'\''/, "'\''\\'\'\''", help)
+ printf " '\''%s'\''", help
+ }
+ printf "\n"
+ }'
+ )
+ ${add_prev:+'> $previous_page' '' ${SHOW_DESC:+''}}
+ ${add_next:+'> $next_page' '' ${SHOW_DESC:+''}}
+ " # End-Quote
+
+ # Accept/Translate i18n "All" but other category names must
+ # match tree definitions from INDEX, ports, FTP, etc.
+ case "$category" in
+ "$msg_all"|"") f_category_desc_get "All" prompt ;;
+ *) f_category_desc_get "$category" prompt ;;
+ esac
+ prompt="$prompt $( printf "$msg_page_of_npages" \
+ "$page" "$npages" )"
+
+ local mheight mwidth mrows
+ eval f_dialog_menu${SHOW_DESC:+_with_help}_size mheight mwidth mrows \
+ \"\$DIALOG_TITLE\" \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \"\$hline\" $menu_list
+ local iheight iwidth
+ f_dialog_infobox_size iheight iwidth \
+ "$DIALOG_TITLE" "$DIALOG_BACKTITLE" \
+ "$msg_processing_selection"
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
+ --backtitle \"\$DIALOG_BACKTITLE\" \
+ --hline \"\$hline\" \
+ --keep-tite \
+ --ok-label \"$msg_select\" \
+ --cancel-label \"$msg_back\" \
+ ${SHOW_DESC:+--item-help} \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $mheight $mwidth $mrows \
+ $menu_list \
+ --and-widget \
+ ${USE_XDIALOG:+--no-buttons} \
+ --infobox \"\$msg_processing_selection\" \
+ $iheight $iwidth \
+ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+ )
+ local retval=$?
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+
+ if [ $retval -eq $SUCCESS ]; then
+ local item
+ item=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \
+ \"\$menu_choice\" $menu_list )
+ f_dialog_menuitem_store "$item"
+ fi
+
+ return $retval
+}
+
+# f_package_menu_deselect $package
+#
+# Display a menu, asking the user what they would like to do with $package
+# with regard to "deselecting" an already installed package. Choices include
+# uninstall, re-install, or cancel (leave $package marked as installed).
+# Returns success if the user does not press ESC or choose Cnacel. Use the
+# f_dialog_menutag_fetch() function upon success to retrieve the user's choice.
+#
+f_package_menu_deselect()
+{
+ local package="$1"
+ local prompt # Calculated below
+ local menu_list="
+ 'X $msg_installed' '$msg_installed_desc'
+ 'R $msg_reinstall' '$msg_reinstall_desc'
+ 'U $msg_uninstall' '$msg_uninstall_desc'
+ " # End-Quote
+ local hline="$hline_alnum_arrows_punc_tab_enter"
+
+ prompt=$( printf "$msg_what_would_you_like_to_do_with" "$package" )
+
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
+ --backtitle \"\$DIALOG_BACKTITLE\" \
+ --hline \"\$hline\" \
+ --ok-label \"$msg_select\" \
+ --cancel-label \"$msg_cancel\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
+ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+ )
+ local retval=$?
+ f_dialog_menutag_store -s "$menu_choice"
+ return $retval
+}
+
+# f_package_review
+#
+# Display a review screen, showing selected packages and what they are marked
+# for, before proceeding (if the user does not press ESC or choose Cancel) to
+# operate on each selection. Returns error if no packages have been selected,
+# or the user has pressed ESC, or if they have chosen Cancel.
+#
+f_package_review()
+{
+ local prompt # Calculated below
+ local menu_list # Calculated below
+ local hline="$hline_alnum_arrows_punc_tab_enter"
+
+ local fname=f_package_review
+ f_dprintf "%s: SELECTED_PACKAGES=[%s]" $fname "$SELECTED_PACKAGES"
+
+ prompt=$( printf "$msg_reviewing_selected_packages" "$_All_nselected" )
+
+ local package varpkg mark
+ for package in $SELECTED_PACKAGES; do
+ mark=
+ f_str2varname "$package" varpkg
+ f_getvar _mark_$varpkg mark
+ [ "$mark" -a ! "${mark#[IRUD]}" ] || continue
+ menu_list="$menu_list
+ '$mark' '$package'
+ " # End-Quote
+ done
+ if [ ! "$menu_list" ]; then
+ f_show_msg "$msg_no_packages_were_selected_for_extraction"
+ return $FAILURE # They might have selected this by accident
+ fi
+ menu_list=$( echo "$menu_list" | sort )
+
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ # Show the review menu (ignore menu choice)
+ eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
+ --backtitle \"\$DIALOG_BACKTITLE\" \
+ --hline \"\$hline\" \
+ --ok-label \"\$msg_proceed\" \
+ --cancel-label \"\$msg_cancel\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
+ 2> /dev/null || return $?
+ # Return if the user pressed ESC or chose Cancel/No
+
+ #
+ # Process each of the selected packages:
+ # + First, process packages marked for Install.
+ # + Second, process packages marked for Re-install.
+ # + Finally, process packages marked for Uninstall.
+ #
+ for package in $SELECTED_PACKAGES; do
+ mark=
+ f_str2varname "$package" varpkg
+ debug= f_getvar _mark_$varpkg mark
+ [ "$mark" = "I" ] || continue
+ f_dprintf "%s: Installing %s package" $fname "$package"
+ f_package_add "$package"
+ done
+ for package in $SELECTED_PACKAGES; do
+ mark=
+ f_str2varname "$package" varpkg
+ debug= f_getvar _mark_$varpkg mark
+ [ "$mark" = "R" ] || continue
+ f_dprintf "%s: Reinstalling %s package" $fname "$package"
+ f_package_reinstall "$package"
+ done
+ for package in $SELECTED_PACKAGES; do
+ mark=
+ f_str2varname "$package" varpkg
+ debug= f_getvar _mark_$varpkg mark
+ [ "$mark" = "U" ] || continue
+ f_dprintf "%s: Uninstalling %s package" $fname "$package"
+ f_package_delete "$package" || continue
+ f_package_deselect "$package"
+ done
+
+ return $SUCCESS
+}
+
+# f_package_config
+#
+# Allow the user to configure packages and install them. Initially, a list of
+# package categories is loaded/displayed. When the user selects a category,
+# the menus for that category are built (unlike sysinstall which built all
+# category menus up-front -- which also took forever, despite the fact that
+# few people visit more than a couple of categories each time).
+#
+f_package_config()
+{
+ # Did we get an INDEX?
+ f_index_initialize packages/INDEX || return $FAILURE
+ # Creates following variables (indirectly via f_index_read())
+ # CATEGORY_MENU_LIST _categories_{varpkg} _rundeps_{varpkg}
+ # PACKAGE_CATEGORIES _npkgs
+
+ # Detect installed packages (updates marks/SELECTED_PACKAGES)
+ f_package_detect_installed
+ export PACKAGES_DETECTED=1 # exported for awk(1) ENVIRON[]
+
+ local retval category varcat defaultitem category_defaultitem=""
+ while :; do
+ # Display the list of package categories
+ f_package_menu_categories \
+ CATEGORY_MENU_LIST "$category_defaultitem"
+ retval=$?
+ f_dialog_menutag_fetch category
+ f_dprintf "retval=%u mtag=[%s]" $retval "$category"
+ category_defaultitem="$category"
+
+ [ $retval -eq $SUCCESS ] || break
+
+ # Maybe the user chose an action (like `Review')
+ case "$category" in
+ "> $msg_review")
+ f_package_review && break
+ continue ;;
+ "> "*)
+ continue
+ esac
+
+ # Anything else is a package category
+
+ category=${category# } # Trim leading space if present
+ category=${category%\*} # Trim trailing asterisk if present
+
+ f_str2varname "$category" varcat
+
+ local page package varpkg mark menu_choice
+ while :; do
+ # Display the list of packages for selected category
+ page=1 defaultitem=""
+ f_getvar _defaultitem_$varcat defaultitem
+ f_getvar _defaultpage_$varcat page
+ f_package_menu_select \
+ "$category" "${page:=1}" "$defaultitem"
+ retval=$?
+ f_dialog_menutag_fetch menu_choice
+ f_dprintf "retval=%u mtag=[%s]" $retval "$menu_choice"
+
+ # NOTE: When --and-widget is used only ESC will cause
+ # dialog(1) to return without going to the next widget.
+ # This is alright in our case as we can still detect
+ # the Cancel button because stdout will be NULL.
+ # Alternatively, Xdialog(1) will terminate with 1
+ # if/when Cancel is chosen on any widget.
+ if [ $retval -eq 255 -o ! "$menu_choice" ]; then
+ # User pressed ESC or chose Cancel
+ break
+ elif [ $retval -eq 1 ]; then
+ # Using X11, Xdialog(1) returned 1 for Cancel
+ f_show_msg "%s" "$menu_choice"
+ break
+ elif [ $retval -ne $SUCCESS ]; then
+ # X11-related error occurred using Xdialog(1)
+ f_show_msg "%s" "$menu_choice"
+ break
+ fi
+
+ defaultitem="$menu_choice"
+
+ # NOTE: f_package_menu_select() does not show the
+ # `Previous Page' or `Next Page' items unless needed
+ case "$menu_choice" in
+ "> $msg_previous_page"|"> $msg_previous_page*")
+ page=$(( $page - 1 ))
+ setvar _defaultpage_$varcat $page
+ # Update default-item to match accent that will
+ # be applied by f_package_menu_select(); if the
+ # page-before-prev is cached, add an asterisk.
+ if f_isset \
+ _index_page_${varcat}_$(( $page - 1 ))
+ then
+ defaultitem="${defaultitem%\*}*"
+ else
+ defaultitem="${defaultitem%\*}"
+ fi
+ setvar _defaultitem_$varcat "$defaultitem"
+ continue ;;
+ "> $msg_next_page"|"> $msg_next_page*")
+ page=$(( $page + 1 ))
+ setvar _defaultpage_$varcat $page
+ # Update default-item to match accent that will
+ # be applied by f_package_menu_select(); if the
+ # page-after-next is cached, add an asterisk.
+ if f_isset \
+ _index_page_${varcat}_$(( $page + 1 ))
+ then
+ defaultitem="${defaultitem%\*}*"
+ else
+ defaultitem="${defaultitem%\*}"
+ fi
+ setvar _defaultitem_$varcat "$defaultitem"
+ continue ;;
+ "> "*) # Unknown navigation/action item
+ setvar _defaultpage_$varcat $page
+ continue ;; # Do not treat as a package
+ *)
+ setvar _defaultitem_$varcat "$defaultitem"
+ esac
+
+ # Treat any other selection as a package
+ package="${menu_choice# }" # Trim leading space
+ f_str2varname $package varpkg
+ f_dialog_menuitem_fetch mark
+ mark="${mark#?}"
+ mark="${mark%%\] *}"
+ case "$mark" in
+ "I")
+ mark=" "
+ f_package_deselect $package
+ ;;
+ " "|"D")
+ mark="I"
+ f_package_select $package
+ ;;
+ "X"|"R"|"U")
+ f_package_menu_deselect $package || continue
+ f_dialog_menutag_fetch menu_choice
+ case "$menu_choice" in
+ "X $msg_installed")
+ f_package_deselect "$package"
+ mark="X"
+ ;;
+ "R $msg_reinstall")
+ f_package_select "$package"
+ mark="R"
+ ;;
+ "U $msg_uninstall")
+ f_package_select "$package"
+ mark="U"
+ ;;
+ esac
+ ;;
+ esac
+ export _mark_$varpkg="$mark"
+ # NOTE: exported for awk(1) ENVIRON[]
+ done
+ done
+}
+
+# f_package_add $package_name [$depended]
+#
+# Like f_package_extract(), but assumes current media device and chases deps.
+# Note that $package_name should not contain the archive suffix (e.g., `.tbz').
+# If $depended is present and non-NULL, the package is treated as a dependency
+# (in this function, dependencies are not handled any differently, but the
+# f_package_extract() function is passed this value and it displays a different
+# message when installing a dependency versus non-dependency).
+#
+f_package_add()
+{
+ local name="$1" depended="$2" status=$SUCCESS retval
+
+ local alert=f_show_msg no_confirm=
+ f_getvar $VAR_NO_CONFIRM no_confirm
+ [ "$no_confirm" ] && alert=f_show_info
+
+ if ! { [ "$name" ] || { f_getvar $VAR_PACKAGE name && [ "$name" ]; }; }
+ then
+ f_dprintf "packageAdd: %s" \
+ "$msg_no_package_name_passed_in_package_variable"
+ return $FAILURE
+ fi
+
+ { # Verify and initialize device media if-defined
+ f_media_verify &&
+ f_device_init media &&
+ f_index_initialize packages/INDEX
+ } || return $FAILURE
+
+ # Now we have (indirectly via f_index_read()):
+ # CATEGORY_MENU_LIST _categories_{varpkg} _rundeps_{varpkg}
+ # PACKAGE_CATEGORIES _npkgs
+
+ local varpkg
+ f_str2varname "$name" varpkg
+
+ # Just as-in the user-interface (opposed to scripted-use), only allow
+ # packages with at least one category to be recognized.
+ #
+ local pkgcat=
+ if ! f_getvar _categories_$varpkg pkgcat || [ ! "$pkgcat" ]; then
+ # $pkg may be a partial name, search the index (this is slow)
+ f_index_search PACKAGE_INDEX $name name
+ if [ ! "$name" ]; then
+ f_show_msg \
+ "$msg_sorry_package_was_not_found_in_the_index" \
+ "$name"
+ return $FAILURE
+ fi
+ f_str2varname "$name" varpkg
+ fi
+
+ # If invoked through the scripted interface, we likely have not yet
+ # detected the installed packages -- something we should do only once.
+ #
+ if [ ! "$PACKAGES_DETECTED" ]; then
+ f_dprintf "f_package_add: Detecting installed packages"
+ f_package_detect_installed
+ export PACKAGES_DETECTED=1 # exported for awk(1) ENVIRON[]
+ fi
+ # Now we have: _mark_{varpkg}=X for all installed packages
+
+ #
+ # Since we're maintaining data structures for installed packages,
+ # short-circuit the package dependency checks if the package is already
+ # installed. This prevents wasted cycles, minor delays between package
+ # extractions, and worst-case an infinite loop with a certain faulty
+ # INDEX file.
+ #
+ local mark=
+ f_getvar _mark_$varpkg mark && [ "$mark" = "X" ] && return $SUCCESS
+
+ local dep vardep rundeps=
+ f_getvar _rundeps_$varpkg rundeps
+ for dep in $rundeps; do
+ f_str2varname "$dep" vardep
+
+ # Skip dependency if already installed
+ mark=
+ f_getvar _mark_$vardep mark && [ "$mark" = "X" ] && continue
+
+ # Just as-in the user-interface (opposed to scripted-use), only
+ # allow packages with at least one category to be recognized.
+ #
+ local depcat=
+ if ! f_getvar _categories_$vardep depcat || [ ! "$depcat" ]
+ then
+ $alert "$msg_required_package_not_found" "$dep"
+ [ "$no_confirm" ] && sleep 2
+ fi
+
+ f_package_add "$dep"
+ retval=$?
+ if [ $retval -ne $SUCCESS ]; then
+ status=$(( $status | $retval ))
+
+ # XXX package could be on a future disc volume
+ # XXX (not supporting multiple disc volumes yet)
+
+ $alert "$msg_loading_of_dependent_package_failed" \
+ "$dep"
+ [ "$no_confirm" ] && sleep 2
+ fi
+ done
+ [ $status -eq $SUCCESS ] || return $status
+
+ #
+ # Done with the deps? Try to load the real m'coy.
+ #
+
+ f_package_extract media "$name" "$depended"
+ retval=$?
+ if [ $retval -ne $SUCCESS ]; then
+ status=$(( $status | $retval ))
+ else
+ setvar _mark_$varpkg X
+ fi
+
+ return $status
+}
+
+# f_package_extract $device $name [$depended]
+#
+# Extract a package based on a namespec and media device. If $depended is
+# present and non-NULL, the notification displayed while installing the package
+# has "as a dependency" appended.
+#
+f_package_extract()
+{
+ local device="$1" name="$2" depended="$3"
+
+ local fname=f_package_extract
+ f_dprintf "%s: device=[%s] name=[%s] depended=[%s]" \
+ $fname "$device" "$name" "$depended"
+
+ # Check to make sure it's not already there
+ local varpkg mark=
+ f_str2varname "$name" varpkg
+ f_getvar _mark_$varpkg mark
+ [ "$mark" = "X" ] && return $SUCCESS
+
+ if ! f_device_init $device; then
+ f_show_msg \
+ "$msg_unable_to_initialize_media_type_for_package_extract"
+ return $FAILURE
+ fi
+
+ # If necessary, initialize the ldconfig hints
+ [ -f "/var/run/ld-elf.so.hints" ] ||
+ f_quietly ldconfig /usr/lib /usr/lib/compat /usr/local/lib
+
+ # Make a couple paranoid locations for temp
+ # files to live if user specified none
+ local tmpdir
+ f_getvar $VAR_PKG_TMPDIR:-/var/tmp tmpdir
+ f_quietly mkdir -p -m 1777 "$tmpdir"
+
+ local path
+ case "$name" in
+ */*) path="$name" ;;
+ *)
+ case "$name" in
+ *-*|*_*) path="packages/All/$name" ;;
+ *) path="packages/Latest/$name"
+ esac
+ esac
+
+ # We have a path, call the device strategy routine to get the file
+ local pkg_ext found=
+ for pkg_ext in "" $PACKAGE_EXTENSIONS; do
+ if f_device_get $device "$path$pkg_ext" $PROBE_EXIST; then
+ path="$path$pkg_ext"
+ f_dprintf "%s: found path=[%s] dev=[%s]" \
+ $fname "$path" "$device"
+ found=1
+ break
+ fi
+ done
+
+ local alert=f_show_msg no_confirm=
+ f_getvar $VAR_NO_CONFIRM no_confirm
+ [ "$no_confirm" ] && alert=f_show_info
+
+ if [ ! "$found" ]; then
+ f_dprintf "%s: No such %s file on %s device" \
+ $fname "$path" "$device"
+ $alert "$msg_unable_to_fetch_package_from_selected_media" \
+ "$name"
+ [ "$no_confirm" ] && sleep 2
+ return $FAILURE
+ fi
+
+ local devname=
+ f_struct device_$device get name devname
+ if [ "$depended" ]; then
+ f_show_info "$msg_adding_package_as_a_dependency_from_media" \
+ "$name" "$devname"
+ else
+ f_show_info "$msg_adding_package_from_media" "$name" "$devname"
+ fi
+
+ # Get package data and pipe into pkg_add(1) while providing feedback
+ {
+ if ! f_device_get $device "$path"; then
+ $alert "$msg_io_error_while_reading_in_the_package" \
+ "$name" \
+ >&$DIALOG_TERMINAL_PASSTHRU_FD 2> /dev/null
+ [ "$no_confirm" ] && sleep 2
+ else
+ f_show_info \
+ "$msg_package_read_successfully_waiting_for_pkg_add" \
+ "$name" >&$DIALOG_TERMINAL_PASSTHRU_FD 2> /dev/null
+ fi
+ } | {
+ if f_debugging; then
+ /usr/sbin/pkg_add -v -
+ else
+ f_quietly /usr/sbin/pkg_add -
+ fi
+ }
+ if [ $? -ne $SUCCESS ]; then
+ $alert "$msg_pkg_add_apparently_did_not_like_the_package" \
+ "$name"
+ [ "$no_confirm" ] && sleep 2
+ else
+ f_show_info "$msg_package_was_added_successfully" "$name"
+ sleep 1
+ fi
+
+ return $SUCCESS
+}
+
+# f_package_delete $name
+#
+# Delete package by full $name (lacks archive suffix; e.g., `.tbz').
+#
+f_package_delete()
+{
+ local name="$1"
+ local fname=f_package_delete
+
+ if ! { [ "$name" ] || { f_getvar $VAR_PACKAGE name && [ "$name" ]; }; }
+ then
+ f_dprintf "packageDelete: %s" \
+ "$msg_no_package_name_passed_in_package_variable"
+ return $FAILURE
+ fi
+
+ f_dprintf "%s: name=[%s]" $fname "$name"
+
+ [ "$name" ] || return $FAILURE
+
+ { # Verify and initialize device media if-defined
+ f_media_verify &&
+ f_device_init media &&
+ f_index_initialize packages/INDEX
+ } || return $FAILURE
+
+ # Now we have (indirectly via f_index_read()):
+ # CATEGORY_MENU_LIST _categories_{varpkg} _rundeps_{varpkg}
+ # PACKAGE_CATEGORIES _npkgs
+
+ local varpkg
+ f_str2varname "$name" varpkg
+
+ # Just as-in the user-interface (opposed to scripted-use), only allow
+ # packages with at least one category to be recognized.
+ #
+ local pkgcat=
+ if ! f_getvar _categories_$varpkg pkgcat || [ ! "$pkgcat" ]; then
+ # $pkg may be a partial name, search the index (this is slow)
+ f_index_search PACKAGE_INDEX "$name" name
+ if [ ! "$name" ]; then
+ f_show_msg \
+ "$msg_sorry_package_was_not_found_in_the_index" \
+ "$name"
+ return $FAILURE
+ fi
+ f_str2varname "$name" varpkg
+ fi
+
+ # If invoked through the scripted interface, we likely have not yet
+ # detected the installed packages -- something we should do only once.
+ #
+ if [ ! "$PACKAGES_DETECTED" ]; then
+ f_dprintf "%s: Detecting installed packages" $fname
+ f_package_detect_installed
+ export PACKAGES_DETECTED=1 # exported for awk(1) ENVIRON[]
+ fi
+ # Now we have: _mark_{varpkg}=X for all installed packages
+
+ #
+ # Return failure if the package is not already installed.
+ #
+ local pkgmark=
+ f_getvar _mark_$varpkg pkgmark
+ if ! [ "$pkgmark" -a ! "${pkgmark#[XUR]}" ]; then
+ f_show_msg "$msg_package_not_installed_cannot_delete" "$name"
+ return $FAILURE
+ fi
+
+ #
+ # Check for dependencies
+ #
+ local pkgsel depc=0 udeps=
+ for pkgsel in $SELECTED_PACKAGES; do
+ local mark=
+ f_str2varname $pkgsel varpkg
+ debug= f_getvar _mark_$varpkg mark
+ [ "$mark" -a ! "${mark#[XUR]}" ] || continue
+ local dep rundeps=
+ debug= f_getvar _rundeps_$varpkg rundeps
+ for dep in $rundeps; do
+ if [ "$dep" = "$name" ]; then
+ # Maybe this package is marked for deletion too
+ if [ "$mark" = "U" ]; then
+ udeps="$udeps $pkgsel"
+ else
+ depc=$(( $depc + 1 ))
+ fi
+ break
+ fi
+ done
+ done
+ if [ $depc -gt 0 ]; then
+ local grammatical_s=
+ [ $depc -gt 1 ] && grammatical_s=s
+ f_show_msg \
+ "$msg_package_is_needed_by_other_installed_packages" \
+ "$name" "$depc" "$grammatical_s"
+ return $FAILURE
+ fi
+
+ #
+ # Chase dependencies that are marked for uninstallation
+ #
+ for pkgsel in $udeps; do
+ f_dprintf "%s: Uninstalling dependecy %s (marked for delete)" \
+ $fname "$pkgsel"
+ f_package_delete "$pkgsel"
+ done
+
+ #
+ # OK to perform the delete (no other packages depend on it)...
+ #
+ f_show_info "$msg_uninstalling_package_waiting_for_pkg_delete" "$name"
+ if f_debugging; then
+ pkg_delete -v "$name"
+ else
+ f_quietly pkg_delete "$name"
+ fi
+ if [ $? -ne $SUCCESS ]; then
+ f_show_msg "$msg_pkg_delete_failed" "$name"
+ return $FAILURE
+ else
+ f_dprintf "%s: pkg_delete(1) of %s successful" $fname "$name"
+ f_str2varname "$name" varpkg
+ setvar _mark_$varpkg ""
+ fi
+}
+
+# f_package_reinstall $name
+#
+# A simple wrapper to f_package_delete() + f_package_add()
+#
+f_package_reinstall()
+{
+ f_package_delete "$1" && f_package_add "$1"
+}
+
+############################################################ MAIN
+
+f_dprintf "%s: Successfully loaded." packages/packages.subr
+
+fi # ! $_PACKAGES_PACKAGES_SUBR
diff --git a/usr.sbin/bsdconfig/share/script.subr b/usr.sbin/bsdconfig/share/script.subr
index 3ea5dd5..a227419 100644
--- a/usr.sbin/bsdconfig/share/script.subr
+++ b/usr.sbin/bsdconfig/share/script.subr
@@ -1,7 +1,7 @@
if [ ! "$_SCRIPT_SUBR" ]; then _SCRIPT_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_SCRIPT_SUBR" ]; then _SCRIPT_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -32,9 +32,12 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." script.subr
f_include $BSDCFG_SHARE/device.subr
-f_include $BSDCFG_SHARE/variable.subr
f_include $BSDCFG_SHARE/media/any.subr
f_include $BSDCFG_SHARE/media/tcpip.subr
+f_include $BSDCFG_SHARE/mustberoot.subr
+f_include $BSDCFG_SHARE/networking/services.subr
+f_include $BSDCFG_SHARE/packages/packages.subr
+f_include $BSDCFG_SHARE/variable.subr
############################################################ GLOBALS
@@ -151,26 +154,53 @@ f_script_load()
#
# Reserved words meant for scripting
#
-f_resword_new deviceRescan f_device_rescan
-f_resword_new dumpVariables f_dump_variables
-f_resword_new loadConfig f_script_load
-f_resword_new mediaClose f_media_close
-f_resword_new mediaGetType f_media_get_type
-f_resword_new mediaOpen f_media_open
-f_resword_new mediaSetCDROM f_media_set_cdrom
-f_resword_new mediaSetDOS f_media_set_dos
+
+# this file
+f_resword_new loadConfig f_script_load
+
+# device.subr
+f_resword_new deviceRescan f_device_rescan
+
+# media/common.subr
+f_resword_new mediaOpen f_media_open
+f_resword_new mediaClose f_media_close
+
+# media includes
+f_resword_new mediaGetType f_media_get_type # media/any.subr
+f_resword_new mediaSetCDROM f_media_set_cdrom # media/cdrom.subr
+f_resword_new mediaSetDOS f_media_set_dos # media/dos.subr
+f_resword_new mediaSetDirectory f_media_set_directory # media/directory.subr
+f_resword_new mediaSetFloppy f_media_set_floppy # media/floppy.subr
+f_resword_new mediaSetNFS f_media_set_nfs # media/nfs.subr
+f_resword_new mediaSetUFS f_media_set_ufs # media/ufs.subr
+f_resword_new mediaSetUSB f_media_set_usb # media/usb.subr
+f_resword_new optionsEditor f_media_options_menu # media/options.subr
+f_resword_new tcpMenuSelect f_dialog_menu_select_tcp # media/tcp.subr
+
+# media/ftp.subr
f_resword_new mediaSetFTP f_media_set_ftp
f_resword_new mediaSetFTPActive f_media_set_ftp_active
f_resword_new mediaSetFTPPassive f_media_set_ftp_passive
f_resword_new mediaSetFTPUserPass f_media_set_ftp_userpass
-f_resword_new mediaSetFloppy f_media_set_floppy
-f_resword_new mediaSetHTTP f_media_set_http_proxy
-f_resword_new mediaSetHTTPProxy f_media_set_http_proxy
-f_resword_new mediaSetNFS f_media_set_nfs
-f_resword_new mediaSetUFS f_media_set_ufs
-f_resword_new mediaSetUSB f_media_set_usb
-f_resword_new optionsEditor f_media_options_menu
-f_resword_new tcpMenuSelect f_dialog_menu_select_tcp
+
+# media/http.subr
+f_resword_new mediaSetHTTP f_media_set_http
+
+# media/httpproxy.subr
+f_resword_new mediaSetHTTPProxy f_media_set_http_proxy
+
+# networking/services.subr
+f_resword_new configPCNFSD f_config_pcnfsd
+
+# packages/packages.subr
+f_resword_new configPackages f_package_config
+f_resword_new packageAdd f_package_add
+f_resword_new packageDelete f_package_delete
+f_resword_new packageReinstall f_package_reinstall
+
+# variable.subr
+f_resword_new installVarDefaults f_variable_set_defaults
+f_resword_new dumpVariables f_dump_variables
f_dprintf "%s: Successfully loaded." script.subr
diff --git a/usr.sbin/bsdconfig/share/strings.subr b/usr.sbin/bsdconfig/share/strings.subr
index 5b9f51e..0a77048 100644
--- a/usr.sbin/bsdconfig/share/strings.subr
+++ b/usr.sbin/bsdconfig/share/strings.subr
@@ -1,7 +1,7 @@
if [ ! "$_STRINGS_SUBR" ]; then _STRINGS_SUBR=1
#
# Copyright (c) 2006-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_STRINGS_SUBR" ]; then _STRINGS_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -25,6 +25,21 @@ if [ ! "$_STRINGS_SUBR" ]; then _STRINGS_SUBR=1
# SUCH DAMAGE.
#
# $FreeBSD$
+#
+############################################################ GLOBALS
+
+#
+# Valid characters that can appear in an sh(1) variable name
+#
+# Please note that the character ranges A-Z and a-z should be avoided because
+# these can include accent characters (which are not valid in a variable name).
+# For example, A-Z matches any character that sorts after A but before Z,
+# including A and Z. Although ASCII order would make more sense, that is not
+# how it works.
+#
+VALID_VARNAME_CHARS="0-9ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"
+
+############################################################ FUNCTIONS
# f_substr "$string" $start [ $length ]
#
@@ -36,6 +51,61 @@ f_substr()
echo "$string" | awk "{ print substr(\$0, $start, $len) }"
}
+# f_snprintf $var_to_set $size $format ...
+#
+# Similar to snprintf(3), write at most $size number of bytes into $var_to_set
+# using printf(1) syntax (`$format ...'). The value of $var_to_set is NULL
+# unless at-least one byte is stored from the output.
+#
+f_snprintf()
+{
+ local __var_to_set="$1" __size="$2"
+ shift 2 # var_to_set/size
+ eval "$__var_to_set"=\$\( printf \"\$@\" \| awk -v max=\"\$__size\" \''
+ {
+ len = length($0)
+ max -= len
+ print substr($0,0,(max > 0 ? len : max + len))
+ if ( max < 0 ) exit
+ max--
+ }'\' \)
+}
+
+# f_vsnprintf $var_to_set $size $format $format_args
+#
+# Similar to vsnprintf(3), write at most $size number of bytes into $var_to_set
+# using printf(1) syntax (`$format $format_args'). The value of $var_to_set is
+# NULL unless at-least one byte is stored from the output.
+#
+# Example 1:
+#
+# limit=7 format="%s"
+# format_args="'abc 123'" # 3-spaces between abc and 123
+# f_vsnprintf foo $limit "$format" "$format_args" # foo=[abc 1]
+#
+# Example 2:
+#
+# limit=12 format="%s %s"
+# format_args=" 'doghouse' 'foxhound' "
+# # even more spaces added to illustrate escape-method
+# f_vsnprintf foo $limit "$format" "$format_args" # foo=[doghouse fox]
+#
+# Example 3:
+#
+# limit=13 format="%s %s"
+# f_shell_escape arg1 'aaa"aaa' # arg1=[aaa"aaa] (no change)
+# f_shell_escape arg2 "aaa'aaa" # arg2=[aaa'\''aaa] (escaped s-quote)
+# format_args="'$arg1' '$arg2'" # use single-quotes to surround args
+# f_vsnprintf foo $limit "$format" "$format_args" # foo=[aaa"aaa aaa'a]
+#
+# In all of the above examples, the call to f_vsnprintf() does not change. Only
+# the contents of $limit, $format, and $format_args changes in each example.
+#
+f_vsnprintf()
+{
+ eval f_snprintf \"\$1\" \"\$2\" \"\$3\" $4
+}
+
# f_longest_line_length
#
# Simple wrapper to an awk(1) script to print the length of the longest line of
@@ -167,6 +237,90 @@ f_uridecode()
fi
}
+# f_replaceall $string $find $replace [$var_to_set]
+#
+# Replace all occurrences of $find in $string with $replace. If $var_to_set is
+# either missing or NULL, the variable name is produced on standard out for
+# capturing in a sub-shell (which is less recommended due to performance
+# degradation).
+#
+f_replaceall()
+{
+ local __left="" __right="$1"
+ local __find="$2" __replace="$3" __var_to_set="$4"
+ while :; do
+ case "$__right" in *$__find*)
+ __left="$__left${__right%%$__find*}$__replace"
+ __right="${__right#*$__find}"
+ continue
+ esac
+ break
+ done
+ __left="$__left${__right#*$__find}"
+ if [ "$__var_to_set" ]; then
+ setvar "$__var_to_set" "$__left"
+ else
+ echo "$__left"
+ fi
+}
+
+# f_str2varname $string [$var_to_set]
+#
+# Convert a string into a suitable value to be used as a variable name
+# by converting unsuitable characters into the underscrore [_]. If $var_to_set
+# is either missing or NULL, the variable name is produced on standard out for
+# capturing in a sub-shell (which is less recommended due to performance
+# degradation).
+#
+f_str2varname()
+{
+ local __string="$1" __var_to_set="$2"
+ f_replaceall "$__string" "[!$VALID_VARNAME_CHARS]" "_" "$__var_to_set"
+}
+
+# f_shell_escape $string [$var_to_set]
+#
+# Escape $string for shell eval statement(s) by replacing all single-quotes
+# with a special sequence that creates a compound string when interpolated
+# by eval with surrounding single-quotes.
+#
+# For example:
+#
+# foo="abc'123"
+# f_shell_escape "$foo" bar # bar=[abc'\''123]
+# eval echo \'$bar\' # produces abc'123
+#
+# This is helpful when processing an argument list that has to retain its
+# escaped structure for later evaluations.
+#
+# WARNING: Surrounding single-quotes are not added; this is the responsibility
+# of the code passing the escaped values to eval (which also aids readability).
+#
+f_shell_escape()
+{
+ local __string="$1" __var_to_set="$2"
+ f_replaceall "$__string" "'" "'\\''" "$__var_to_set"
+}
+
+# f_shell_unescape $string [$var_to_set]
+#
+# The antithesis of f_shell_escape(), this function takes an escaped $string
+# and expands it.
+#
+# For example:
+#
+# foo="abc'123"
+# f_shell_escape "$foo" bar # bar=[abc'\''123]
+# f_shell_unescape "$bar" # produces abc'123
+#
+f_shell_unescape()
+{
+ local __string="$1" __var_to_set="$2"
+ f_replaceall "$__string" "'\\''" "'" "$__var_to_set"
+}
+
+############################################################ MAIN
+
f_dprintf "%s: Successfully loaded." strings.subr
fi # ! $_STRINGS_SUBR
diff --git a/usr.sbin/bsdconfig/share/struct.subr b/usr.sbin/bsdconfig/share/struct.subr
index 3c6f90f..fc4f711 100644
--- a/usr.sbin/bsdconfig/share/struct.subr
+++ b/usr.sbin/bsdconfig/share/struct.subr
@@ -1,7 +1,7 @@
if [ ! "$_STRUCT_SUBR" ]; then _STRUCT_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_STRUCT_SUBR" ]; then _STRUCT_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
diff --git a/usr.sbin/bsdconfig/share/sysrc.subr b/usr.sbin/bsdconfig/share/sysrc.subr
index 36a550e..66a4cf3 100644
--- a/usr.sbin/bsdconfig/share/sysrc.subr
+++ b/usr.sbin/bsdconfig/share/sysrc.subr
@@ -1,7 +1,7 @@
if [ ! "$_SYSRC_SUBR" ]; then _SYSRC_SUBR=1
#
# Copyright (c) 2006-2012 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,7 +13,7 @@ if [ ! "$_SYSRC_SUBR" ]; then _SYSRC_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
@@ -135,7 +135,7 @@ f_sysrc_get()
case "$1" in
[0-9]*)
# Don't expand possible positional parameters
- return $FAILURE;;
+ return $FAILURE ;;
*)
[ "$1" ] || return $FAILURE
esac
@@ -218,7 +218,7 @@ f_sysrc_get_default()
case "$1" in
[0-9]*)
# Don't expand possible positional parameters
- return $FAILURE;;
+ return $FAILURE ;;
*)
[ "$1" ] || return $FAILURE
esac
diff --git a/usr.sbin/bsdconfig/share/variable.subr b/usr.sbin/bsdconfig/share/variable.subr
index 7a066421..86523d6 100644
--- a/usr.sbin/bsdconfig/share/variable.subr
+++ b/usr.sbin/bsdconfig/share/variable.subr
@@ -1,7 +1,7 @@
if [ ! "$_VARIABLE_SUBR" ]; then _VARIABLE_SUBR=1
#
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_VARIABLE_SUBR" ]; then _VARIABLE_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -32,6 +32,7 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." variable.subr
f_include $BSDCFG_SHARE/dialog.subr
+f_include $BSDCFG_SHARE/strings.subr
############################################################ GLOBALS
@@ -93,8 +94,7 @@ f_variable_get_value()
if ! { f_getvar $var cp && ! f_interactive; }; then
shift 1 # var
- cp=$( f_dialog_input "$( printf "$@" )" "$cp" ) &&
- setvar $var "$cp"
+ f_dialog_input cp "$( printf "$@" )" "$cp" && setvar $var "$cp"
fi
return $SUCCESS
@@ -106,19 +106,43 @@ f_variable_get_value()
#
f_variable_set_defaults()
{
+ f_dprintf "f_variable_set_defaults: Initializing defaults..."
+
#
# Initialize various user-edittable values to their defaults
#
setvar $VAR_EDITOR "${EDITOR:-/usr/bin/ee}"
- setvar $VAR_FTP_STATE "passive"
+ setvar $VAR_FTP_STATE "auto"
setvar $VAR_FTP_USER "ftp"
setvar $VAR_HOSTNAME "$( hostname )"
setvar $VAR_MEDIA_TIMEOUT "300"
setvar $VAR_NFS_SECURE "NO"
setvar $VAR_NFS_TCP "NO"
setvar $VAR_NFS_V3 "YES"
+ setvar $VAR_PKG_TMPDIR "/var/tmp"
setvar $VAR_RELNAME "$UNAME_R"
+ #
+ # Debugging
+ #
+ if f_debugging; then
+ local var
+ for var in \
+ $VAR_EDITOR \
+ $VAR_FTP_STATE \
+ $VAR_FTP_USER \
+ $VAR_HOSTNAME \
+ $VAR_MEDIA_TIMEOUT \
+ $VAR_NFS_SECURE \
+ $VAR_NFS_TCP \
+ $VAR_NFS_V3 \
+ $VAR_PKG_TMPDIR \
+ $VAR_RELNAME \
+ ; do
+ f_quietly f_getvar $var
+ done
+ fi
+
f_dprintf "f_variable_set_defaults: Defaults initialized."
}
@@ -130,12 +154,12 @@ f_variable_set_defaults()
#
f_dump_variables()
{
- local err sanitize_awk="{ gsub(/'/, \"'\\\\''\"); print }"
+ local err
if ! err=$(
( for handle in $VARIABLES; do
f_getvar $handle var || continue
f_getvar $var value || continue
- value=$( echo "$value" | awk "$sanitize_awk" )
+ f_shell_escape "$value" value
printf "%s='%s'\n" "$var" "$value"
done > "$VARIABLE_DUMPFILE" ) 2>&1
); then
@@ -203,7 +227,11 @@ f_variable_new VAR_FTP_STATE ftpState
f_variable_new VAR_FTP_USER ftpUser
f_variable_new VAR_GATEWAY defaultrouter
f_variable_new VAR_HOSTNAME hostname
+f_variable_new VAR_HTTP_DIR httpDirectory
f_variable_new VAR_HTTP_FTP_MODE httpFtpMode
+f_variable_new VAR_HTTP_HOST httpHost
+f_variable_new VAR_HTTP_PATH _httpPath
+f_variable_new VAR_HTTP_PORT httpPort
f_variable_new VAR_HTTP_PROXY httpProxy
f_variable_new VAR_HTTP_PROXY_HOST httpProxyHost
f_variable_new VAR_HTTP_PROXY_PATH _httpProxyPath
@@ -224,8 +252,12 @@ f_variable_new VAR_NFS_SECURE nfs_reserved_port_only
f_variable_new VAR_NFS_TCP nfs_use_tcp
f_variable_new VAR_NFS_V3 nfs_use_v3
f_variable_new VAR_NONINTERACTIVE nonInteractive
+f_variable_new VAR_NO_CONFIRM noConfirm
f_variable_new VAR_NO_ERROR noError
f_variable_new VAR_NO_INET6 noInet6
+f_variable_new VAR_PACKAGE package
+f_variable_new VAR_PKG_TMPDIR PKG_TMPDIR
+f_variable_new VAR_PORTS_PATH ports
f_variable_new VAR_RELNAME releaseName
f_variable_new VAR_SLOW_ETHER slowEthernetCard
f_variable_new VAR_TRY_DHCP tryDHCP
diff --git a/usr.sbin/bsdconfig/startup/INDEX b/usr.sbin/bsdconfig/startup/INDEX
index 1b6f5cd..afad348 100644
--- a/usr.sbin/bsdconfig/startup/INDEX
+++ b/usr.sbin/bsdconfig/startup/INDEX
@@ -26,33 +26,37 @@
# $FreeBSD$
#
-# Title that will be shown on the bsdconfig menu
+# Title that will be shown in the bsdconfig menu.
+#
menu_title="Startup"
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
#
-# a short descriptive line shown at the bottom of the bsdconfig menu.
-# keep it short because any line longer than the terminal width will
-# be truncated.
menu_help="Set Startup Parameters"
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
#
-# two-part variable that defines an action to take when 'keyword'
-# is passed on a bsdconfig command line. variable takes the form
-# "keyword|command" and multiple occurrences of the variable
-# (with different 'keyword's, or different 'keyword's AND 'command's)
-# are allowed. If 'command' begins with a '/' then the full
-# path to the program is needed. If 'command' begins with anything
-# else it is a path relative to the directory this INDEX file is in.
-# 'keyword' can be i18n'ed but 'command' is the name of a script.
menu_selection="startup|startup"
menu_selection="startup_misc|misc"
menu_selection="startup_rcadd|rcadd"
menu_selection="startup_rcconf|rcconf"
menu_selection="startup_rcdelete|rcdelete"
menu_selection="startup_rcvar|rcvar"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
#
-# Items below this line do NOT need i18n translation----------------------
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
#
-# Name of the program to be run when this menu choice is selected.
-# if it begins with a '/' then the full path to the program is needed.
-# if it begins with anything else it is a path relative to the directory
-# this INDEX file is in.
menu_program="startup"
diff --git a/usr.sbin/bsdconfig/startup/USAGE b/usr.sbin/bsdconfig/startup/USAGE
index 9aa4dca..a06d8af 100644
--- a/usr.sbin/bsdconfig/startup/USAGE
+++ b/usr.sbin/bsdconfig/startup/USAGE
@@ -1,5 +1,5 @@
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -11,11 +11,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -27,7 +27,11 @@
Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS]
OPTIONS:
- -h Print usage statement and exit.
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
+ -h Print this usage statement and exit.
-S Secure X11 mode (implies `-X'). As root, always prompt-for
and validate sudo(8) username/password before starting.
-X Use Xdialog(1) in place of dialog(1).
diff --git a/usr.sbin/bsdconfig/startup/include/messages.subr b/usr.sbin/bsdconfig/startup/include/messages.subr
index b3cb57f..87bde26 100644
--- a/usr.sbin/bsdconfig/startup/include/messages.subr
+++ b/usr.sbin/bsdconfig/startup/include/messages.subr
@@ -1,4 +1,4 @@
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -63,8 +63,7 @@ msg_exit_cancel="Exit/Cancel"
msg_exit_cancel_desc="Return to previous menu"
msg_exit_cancel_help="Return to the previous menu (selected items are untouched)"
msg_exit_desc="Return to previous menu"
-msg_exit_help="Exit this menu (returning to previous)"
-msg_exit_this_menu="Exit this menu (returning to previous)"
+msg_exit_this_menu="Exit this menu"
msg_info="Info"
msg_lpd="lpd"
msg_lpd_desc="This host has a printer and wants to run lpd."
@@ -94,17 +93,18 @@ msg_reset_desc="Reset to default view settings"
msg_sco="SCO"
msg_sco_desc="This host wants to be able to run IBCS2 binaries."
msg_show_configured="Show Configured"
-msg_show_configured_desc="Calculate rc.conf(5) locations (slow)"
+msg_show_configured_desc="Calculate rc.conf(5) locations (slowest)"
msg_show_default_value="Show Default/Value"
-msg_show_default_value_desc="Show default/configured values"
+msg_show_default_value_desc="Show default/configured values (slow)"
msg_show_value="Show Value"
-msg_show_value_desc="Show configured startup value"
+msg_show_value_desc="Show configured startup value (fast)"
msg_startup="Startup"
msg_startup_dirs="Startup dirs"
msg_startup_dirs_desc="Set the list of dirs to look for startup scripts"
msg_svr4="SVR4"
msg_svr4_desc="This host wants to be able to run SVR4 binaries."
msg_toggle_startup_services="Toggle Startup Services"
+msg_unknown_startup_menu_selection="Unknown startup menu selection"
msg_value_required="Value Required"
msg_view_details="View Details"
msg_view_details_desc="Choose view details"
diff --git a/usr.sbin/bsdconfig/startup/misc b/usr.sbin/bsdconfig/startup/misc
index 37bb80f..edfc1ac 100755
--- a/usr.sbin/bsdconfig/startup/misc
+++ b/usr.sbin/bsdconfig/startup/misc
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -56,15 +56,15 @@ UNAME_P=$( uname -p ) # Processor Architecture (i.e. i386)
#
dialog_menu_main()
{
- local menu_list var_list size
- local hline="$hline_arrows_tab_enter"
local prompt="$msg_miscellaneous_menu_text"
-
- menu_list="
- 'X <<< $msg_exit' '$msg_exit_this_menu'
+ local menu_list="
+ 'X $msg_exit' '$msg_exit_this_menu'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_arrows_tab_enter"
- var_list="
+ # List of variables we'll need from rc.conf(5)
+ local var_list="
accounting_enable
local_startup
lpd_enable
@@ -76,6 +76,7 @@ dialog_menu_main()
startup_dirs
" # END-QUOTE
+ # Add i386-specific variables if appropriate
if [ "$UNAME_P" = "i386" ]; then
var_list="$var_list
apm_enable
@@ -84,7 +85,11 @@ dialog_menu_main()
" # END-QUOTE
fi
- menu_list="$menu_list $(
+ # Obtain default-item (adjusted below for dynamic tags)
+ f_dialog_default_fetch defaultitem
+ local ditem="${defaultitem%%[$IFS]*}"
+
+ eval "$(
. "$RC_DEFAULTS"
source_rc_confs
export $var_list
@@ -100,104 +105,132 @@ dialog_menu_main()
export msg_sco msg_sco_desc
export msg_svr4 msg_svr4_desc
:| awk \
- -v uname_p="$UNAME_P" \
- -v menu_tags="$DIALOG_MENU_TAGS" \
- -v menu_fmt="'%c [%c] %s' '%s'\n" \
- -v sep_fmt="' ' ' -- '\n" \
- 'END {
+ -v uname_p="$UNAME_P" \
+ -v menu_tags="$DIALOG_MENU_TAGS" \
+ -v menu_fmt="'%s' '%s'\n" \
+ -v mtag_fmt="%c [%c] %s" \
+ -v separator="' ' ' -- '\n" \
+ -v ditem="$ditem" \
+ '
+ function mprint(tag,item)
+ {
+ printf menu_fmt, tag, item
+ }
+ END {
i = 1
+ defaultitem = ""
+
+ printf "menu_list=\"$menu_list\n"
+
if ( uname_p == "i386" )
{
#
# APM: Auto-power management services
# (typically laptops)
#
- printf menu_fmt, substr(menu_tags, i++, 1),
- ( ENVIRON["apm_enable"] ~ \
- /^[Yy][Ee][Ss]$/ ? "X" : " " ),
- ENVIRON["msg_apm"],
- ENVIRON["msg_apm_desc"]
+ char = substr(menu_tags, i++, 1)
+ mark = ( ENVIRON["apm_enable"] ~ \
+ /^[Yy][Ee][Ss]$/ ? "X" : " " )
+ subtag = ENVIRON["msg_apm"]
+ tag = sprintf(mtag_fmt, char, mark, subtag)
+ mprint(tag, ENVIRON["msg_apm_desc"])
+ if (ditem == char) defaultitem = tag
}
- # Separator
- printf sep_fmt
+ printf separator
#
# Startup dirs: Set the list of dirs to look for
# startup scripts
#
- printf menu_fmt, substr(menu_tags, i++, 1),
- ( length(ENVIRON["local_startup"]) > 0 \
- ? "X" : " " ),
- ENVIRON["msg_startup_dirs"],
- ENVIRON["msg_startup_dirs_desc"]
+ char = substr(menu_tags, i++, 1)
+ mark = ( length(ENVIRON["local_startup"]) > 0 \
+ ? "X" : " " )
+ subtag = ENVIRON["msg_startup_dirs"]
+ tag = sprintf(mtag_fmt, char, mark, subtag)
+ mprint(tag, ENVIRON["msg_startup_dirs_desc"])
+ if (ditem == char) defaultitem = tag
#
# named: Run a local name server on this host
#
- printf menu_fmt, substr(menu_tags, i++, 1),
- ( ENVIRON["named_enable"] ~ \
- /^[Yy][Ee][Ss]$/ ? "X" : " " ),
- ENVIRON["msg_named"],
- ENVIRON["msg_named_desc"]
+ char = substr(menu_tags, i++, 1)
+ mark = ( ENVIRON["named_enable"] ~ \
+ /^[Yy][Ee][Ss]$/ ? "X" : " " )
+ subtag = ENVIRON["msg_named"]
+ tag = sprintf(mtag_fmt, char, mark, subtag)
+ mprint(tag, ENVIRON["msg_named_desc"])
+ if (ditem == char) defaultitem = tag
#
# named flags: Set default flags to named (if enabled)
#
- printf menu_fmt, substr(menu_tags, i++, 1),
- ( length(ENVIRON["named_flags"]) > 0 \
- ? "X" : " " ),
- ENVIRON["msg_named_flags"],
- ENVIRON["msg_named_flags_desc"]
+ char = substr(menu_tags, i++, 1)
+ mark = ( length(ENVIRON["named_flags"]) > 0 \
+ ? "X" : " " )
+ subtag = ENVIRON["msg_named_flags"]
+ tag = sprintf(mtag_fmt, char, mark, subtag)
+ mprint(tag, ENVIRON["msg_named_flags_desc"])
+ if (ditem == char) defaultitem = tag
#
# NIS client: This host wishes to be an NIS client.
#
- printf menu_fmt, substr(menu_tags, i++, 1),
- ( ENVIRON["nis_client_enable"] ~ \
- /^[Yy][Ee][Ss]$/ ? "X" : " " ),
- ENVIRON["msg_nis_client"],
- ENVIRON["msg_nis_client_desc"]
+ char = substr(menu_tags, i++, 1)
+ mark = ( ENVIRON["nis_client_enable"] ~ \
+ /^[Yy][Ee][Ss]$/ ? "X" : " " )
+ subtag = ENVIRON["msg_nis_client"]
+ tag = sprintf(mtag_fmt, char, mark, subtag)
+ mprint(tag, ENVIRON["msg_nis_client_desc"])
+ if (ditem == char) defaultitem = tag
#
# NIS domainname: Set NIS domainname (if enabled)
#
- printf menu_fmt, substr(menu_tags, i++, 1),
- ( length(ENVIRON["nisdomainname"]) > 0 \
- ? "X" : " " ),
- ENVIRON["msg_nis_domainname"],
- ENVIRON["msg_nis_domainname_desc"]
+ char = substr(menu_tags, i++, 1)
+ mark = ( length(ENVIRON["nisdomainname"]) > 0 && \
+ ENVIRON["nisdomainname"] != "NO" \
+ ? "X" : " " )
+ subtag = ENVIRON["msg_nis_domainname"]
+ tag = sprintf(mtag_fmt, char, mark, subtag)
+ mprint(tag, ENVIRON["msg_nis_domainname_desc"])
+ if (ditem == char) defaultitem = tag
#
# NIS server: This host wishes to be an NIS server.
#
- printf menu_fmt, substr(menu_tags, i++, 1),
- ( ENVIRON["nis_server_enable"] ~ \
- /^[Yy][Ee][Ss]$/ ? "X" : " " ),
- ENVIRON["msg_nis_server"],
- ENVIRON["msg_nis_server_desc"]
+ char = substr(menu_tags, i++, 1)
+ mark = ( ENVIRON["nis_server_enable"] ~ \
+ /^[Yy][Ee][Ss]$/ ? "X" : " " )
+ subtag = ENVIRON["msg_nis_server"]
+ tag = sprintf(mtag_fmt, char, mark, subtag)
+ mprint(tag, ENVIRON["msg_nis_server_desc"])
+ if (ditem == char) defaultitem = tag
- # Separator
- printf sep_fmt
+ printf separator
#
# Accounting: This host wishes to run process
# accounting.
#
- printf menu_fmt, substr(menu_tags, i++, 1),
- ( ENVIRON["accounting_enable"] ~ \
- /^[Yy][Ee][Ss]$/ ? "X" : " " ),
- ENVIRON["msg_accounting"],
- ENVIRON["msg_accounting_desc"]
+ char = substr(menu_tags, i++, 1)
+ mark = ( ENVIRON["accounting_enable"] ~ \
+ /^[Yy][Ee][Ss]$/ ? "X" : " " )
+ subtag = ENVIRON["msg_accounting"]
+ tag = sprintf(mtag_fmt, char, mark, subtag)
+ mprint(tag, ENVIRON["msg_accounting_desc"])
+ if (ditem == char) defaultitem = tag
#
# lpd: This host has a printer and wants to run lpd.
#
- printf menu_fmt, substr(menu_tags, i++, 1),
- ( ENVIRON["lpd_enable"] ~ \
- /^[Yy][Ee][Ss]$/ ? "X" : " " ),
- ENVIRON["msg_lpd"],
- ENVIRON["msg_lpd_desc"]
+ char = substr(menu_tags, i++, 1)
+ mark = ( ENVIRON["lpd_enable"] ~ \
+ /^[Yy][Ee][Ss]$/ ? "X" : " " )
+ subtag = ENVIRON["msg_lpd"]
+ tag = sprintf(mtag_fmt, char, mark, subtag)
+ mprint(tag, ENVIRON["msg_lpd_desc"])
+ if (ditem == char) defaultitem = tag
if ( uname_p == "i386" )
{
@@ -205,45 +238,59 @@ dialog_menu_main()
# SCO: This host wants to be able to run IBCS2
# binaries.
#
- printf menu_fmt, substr(menu_tags, i++, 1),
- ( ENVIRON["ibcs2_enable"] ~ \
- /^[Yy][Ee][Ss]$/ ? "X" : " " ),
- ENVIRON["msg_sco"],
- ENVIRON["msg_sco_desc"]
+ char = substr(menu_tags, i++, 1)
+ mark = ( ENVIRON["ibcs2_enable"] ~ \
+ /^[Yy][Ee][Ss]$/ ? "X" : " " )
+ subtag = ENVIRON["msg_sco"]
+ tag = sprintf(mtag_fmt, char, mark, subtag)
+ mprint(tag, ENVIRON["msg_sco_desc"])
+ if (ditem == char) defaultitem = tag
#
# SVR4: This host wants to be able to run SVR4
# binaries.
#
- printf menu_fmt, substr(menu_tags, i++, 1),
- ( ENVIRON["svr4_enable"] ~ \
- /^[Yy][Ee][Ss]$/ ? "X" : " " ),
- ENVIRON["msg_svr4"],
- ENVIRON["msg_svr4_desc"]
+ char = substr(menu_tags, i++, 1)
+ mark = ( ENVIRON["svr4_enable"] ~ \
+ /^[Yy][Ee][Ss]$/ ? "X" : " " )
+ subtag = ENVIRON["msg_svr4"]
+ tag = sprintf(mtag_fmt, char, mark, subtag)
+ mprint(tag, ENVIRON["msg_svr4_desc"])
+ if (ditem == char) defaultitem = tag
}
+
+ printf "\"\n"
+
+ if ( defaultitem )
+ printf "defaultitem=\"%s\"\n", defaultitem
}'
)"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+ f_dialog_default_store "$menu_choice"
return $retval
}
@@ -257,7 +304,7 @@ dialog_input_value()
local prompt="$1" _input="$2"
f_dialog_title "$msg_value_required"
- _input=$( f_dialog_input "$prompt" "$_input" "$hline_alnum_tab_enter" )
+ f_dialog_input _input "$prompt" "$_input" "$hline_alnum_tab_enter"
local retval=$?
f_dialog_title_restore
@@ -276,9 +323,9 @@ dialog_input_value()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -294,94 +341,95 @@ f_mustberoot_init
# Launch application main menu
#
while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
+ dialog_menu_main || f_die
+ f_dialog_menutag_fetch mtag
- [ $retval -eq 0 ] || f_die
+ case "$mtag" in
+ "X $msg_exit") break ;;
+ ?" [X] "*) toggled=1 ;;
+ *) toggled=
+ esac
case "$mtag" in
- "X <<< $msg_exit") break ;;
+ # Simple On/Off toggle bits
?" ["?"] $msg_apm")
- case "$mtag" in
- ?" [X] "*) err=$( f_sysrc_set apm_enable NO 2>&1 ) ;;
- ?" [ ] "*) err=$( f_sysrc_set apm_enable YES 2>&1 ) ;;
- esac
- [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;;
- ?" ["?"] $msg_startup_dirs")
- dialog_input_value \
- "$msg_startup_dirs_desc" \
- "$( f_sysrc_get local_startup )"
- if [ $? -eq $SUCCESS ]; then
- err=$( f_sysrc_set local_startup "$value" ) ||
- f_dialog_msgbox "$err\n"
+ if [ "$toggled" ]; then
+ err=$( f_sysrc_set apm_enable NO 2>&1 )
+ else
+ err=$( f_sysrc_set apm_enable YES 2>&1 )
fi
;;
?" ["?"] $msg_named")
- case "$mtag" in
- ?" [X] "*) err=$( f_sysrc_set named_enable NO 2>&1 ) ;;
- ?" [ ] "*) err=$( f_sysrc_set named_enable YES 2>&1 ) ;;
- esac
- [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;;
- ?" ["?"] $msg_named_flags")
- dialog_input_value \
- "$msg_named_flags_desc" \
- "$( f_sysrc_get named_flags )"
- if [ $? -eq $SUCCESS ]; then
- err=$( f_sysrc_set named_flags "$value" ) ||
- f_dialog_msgbox "$err\n"
+ if [ "$toggled" ]; then
+ err=$( f_sysrc_set named_enable NO 2>&1 )
+ else
+ err=$( f_sysrc_set named_enable YES 2>&1 )
+ fi
+ ;;
+ ?" ["?"] $msg_accounting")
+ if [ "$toggled" ]; then
+ err=$( f_sysrc_set accounting_enable NO 2>&1 )
+ else
+ err=$( f_sysrc_set accounting_enable YES 2>&1 )
fi
;;
+ ?" ["?"] $msg_lpd")
+ if [ "$toggled" ]; then
+ err=$( f_sysrc_set lpd_enable NO 2>&1 )
+ else
+ err=$( f_sysrc_set lpd_enable YES 2>&1 )
+ fi
+ ;;
+ ?" ["?"] $msg_sco")
+ if [ "$toggled" ]; then
+ err=$( f_sysrc_set ibcs2_enable NO 2>&1 )
+ else
+ err=$( f_sysrc_set ibcs2_enable YES 2>&1 )
+ fi
+ ;;
+ ?" ["?"] $msg_svr4")
+ if [ "$toggled" ]; then
+ err=$( f_sysrc_set svr4_enable NO 2>&1 )
+ else
+ err=$( f_sysrc_set svr4_enable YES 2>&1 )
+ fi
+ ;;
+ # Multi-variable On/Off toggle bits
?" ["?"] $msg_nis_client")
- case "$mtag" in
- ?" [X] "*) err=$( f_sysrc_set nis_client_enable NO 2>&1 ) ;;
- ?" [ ] "*)
+ if [ "$toggled" ]; then
+ err=$( f_sysrc_set nis_client_enable NO 2>&1 )
+ else
err=$( f_sysrc_set nis_client_enable YES 2>&1 ) \
- && err=$( f_sysrc_set rpcbind_enable YES 2>&1 ) ;;
- esac
- [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;;
- ?" ["?"] $msg_nis_domainname")
- dialog_input_value \
- "$msg_nis_domainname_desc" \
- "$( f_sysrc_get nisdomainname )"
- if [ $? -eq $SUCCESS ]; then
- err=$( f_sysrc_set nisdomainname "$value" ) ||
- f_dialog_msgbox "$err\n"
+ && err=$( f_sysrc_set rpcbind_enable YES 2>&1 )
fi
;;
?" ["?"] $msg_nis_server")
- case "$mtag" in
- ?" [X] "*) err=$( f_sysrc_set nis_server_enable NO 2>&1 ) ;;
- ?" [ ] "*)
+ if [ "$toggled" ]; then
+ err=$( f_sysrc_set nis_server_enable NO 2>&1 )
+ else
err=$( f_sysrc_set nis_server_enable YES 2>&1 ) \
- && err=$( f_sysrc_set rpcbind_enable YES 2>&1 ) ;;
- esac
- [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;;
- ?" ["?"] $msg_accounting")
- case "$mtag" in
- ?" [X] "*) err=$( f_sysrc_set accounting_enable NO 2>&1 ) ;;
- ?" [ ] "*) err=$( f_sysrc_set accounting_enable YES 2>&1 ) ;;
- esac
- [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;;
- ?" ["?"] $msg_lpd")
- case "$mtag" in
- ?" [X] "*) err=$( f_sysrc_set lpd_enable NO 2>&1 ) ;;
- ?" [ ] "*) err=$( f_sysrc_set lpd_enable YES 2>&1 ) ;;
- esac
- [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;;
- ?" ["?"] $msg_sco")
- case "$mtag" in
- ?" [X] "*) err=$( f_sysrc_set ibcs2_enable NO 2>&1 ) ;;
- ?" [ ] "*) err=$( f_sysrc_set ibcs2_enable YES 2>&1 ) ;;
- esac
- [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;;
- ?" ["?"] $msg_svr4")
- case "$mtag" in
- ?" [X] "*) err=$( f_sysrc_set svr4_enable NO 2>&1 ) ;;
- ?" [ ] "*) err=$( f_sysrc_set svr4_enable YES 2>&1 ) ;;
- esac
- [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n" ;;
+ && err=$( f_sysrc_set rpcbind_enable YES 2>&1 )
+ fi
+ ;;
+ # Checkboxes for non-boolean options
+ ?" ["?"] $msg_nis_domainname")
+ dialog_input_value "$msg_nis_domainname_desc" \
+ "$( f_sysrc_get nisdomainname )" || continue
+ err=$( f_sysrc_set nisdomainname "$value" 2>&1 )
+ ;;
+ ?" ["?"] $msg_startup_dirs")
+ dialog_input_value "$msg_startup_dirs_desc" \
+ "$( f_sysrc_get local_startup )" || continue
+ err=$( f_sysrc_set local_startup "$value" 2>&1 )
+ ;;
+ ?" ["?"] $msg_named_flags")
+ dialog_input_value "$msg_named_flags_desc" \
+ "$( f_sysrc_get named_flags )" || continue
+ err=$( f_sysrc_set named_flags "$value" 2>&1 )
+ ;;
esac
+
+ [ $? -eq $SUCCESS ] || f_dialog_msgbox "$err\n"
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/startup/rcadd b/usr.sbin/bsdconfig/startup/rcadd
index 3bea670..9fd3bdd 100755
--- a/usr.sbin/bsdconfig/startup/rcadd
+++ b/usr.sbin/bsdconfig/startup/rcadd
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -57,35 +57,35 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline="$hline_arrows_tab_enter"
- local prompt=""
-
- menu_list="
+ local prompt=
+ local menu_list="
'1' '$msg_add_from_list'
'2' '$msg_add_custom'
" # END-QUOTE
+ local hline="$hline_arrows_tab_enter"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -97,9 +97,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -115,38 +115,29 @@ f_mustberoot_init
# Launch application main menu
#
while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
+ dialog_menu_main || f_die
+ f_dialog_menutag_fetch mtag
case "$mtag" in
1) # Add From List
- # Loop for easy return
+ # Loop to allow adding multiple variables quickly
+ defaultitem=
while :; do
- f_dialog_input_rclist
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || break
-
- case "$mtag" in
- "X $msg_exit" ) break ;;
- *) # Anything else is a directive
- rcvar="${mtag# }"
- $BSDCFG_LIBE/$APP_DIR/rcedit \
- ${USE_XDIALOG:+-X} \
- "$rcvar" || continue
- esac
- break
+ f_dialog_input_rclist "$defaultitem" || f_die
+ f_dialog_menutag_fetch mtag
+ defaultitem="$mtag"
+
+ [ "$mtag" = "X $msg_exit" ] && break
+
+ # Anything else is a directive
+
+ $BSDCFG_LIBE/$APP_DIR/rcedit ${USE_XDIALOG:+-X} \
+ "${mtag# }"
done
- [ $retval -eq 0 ] || continue
;;
2) # Add Custom
f_dialog_input_rcvar || continue
- $BSDCFG_LIBE/$APP_DIR/rcedit ${USE_XDIALOG:+-X} "$rcvar" ||
- continue
+ $BSDCFG_LIBE/$APP_DIR/rcedit ${USE_XDIALOG:+-X} "$rcvar"
;;
esac
done
diff --git a/usr.sbin/bsdconfig/startup/rcconf b/usr.sbin/bsdconfig/startup/rcconf
index d09874b..d064224 100755
--- a/usr.sbin/bsdconfig/startup/rcconf
+++ b/usr.sbin/bsdconfig/startup/rcconf
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -49,7 +49,6 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
RCCONF_MAP=
_RCCONF_MAP=
-RCCONF_MENU_LIST=
#
# Options
@@ -79,13 +78,10 @@ fi
#
dialog_menu_main()
{
- local size
- local hline="$hline_arrows_tab_enter"
- local prompt=""
-
- RCCONF_MENU_LIST="
+ local prompt=
+ local menu_list="
'X $msg_exit' '$msg_exit_desc'
- ${SHOW_DESC:+'$msg_exit_help'}
+ ${SHOW_DESC:+'$msg_exit_this_menu'}
'> $msg_add_new' '$msg_add_new_desc'
${SHOW_DESC:+'$msg_add_new_help'}
'> $msg_delete' '$msg_delete_desc'
@@ -95,14 +91,16 @@ dialog_menu_main()
${SHOW_DESC:+'$msg_view_details_help'}
}
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_arrows_tab_enter"
if [ ! "$_RCCONF_MAP" ]; then
# Genreate RCCONF_MAP of `var desc ...' per-line
f_dialog_info "$msg_creating_rcconf_map"
- RCCONF_MAP=$( f_startup_rcconf_map )
+ f_startup_rcconf_map RCCONF_MAP
export RCCONF_MAP
# Generate _${var}_desc variables from $RCCONF_MAP
- f_startup_rcconf_map_expand
+ f_startup_rcconf_map_expand RCCONF_MAP
export _RCCONF_MAP=1
fi
@@ -110,7 +108,7 @@ dialog_menu_main()
[ "$SHOW_DEFAULT_VALUE" -o "$SHOW_CONFIGURED" ] &&
f_dialog_info "$msg_creating_menu_list"
- RCCONF_MENU_LIST="$RCCONF_MENU_LIST $(
+ menu_list="$menu_list $(
. "$RC_DEFAULTS" > /dev/null
source_rc_confs > /dev/null
var_list=$( f_startup_rcconf_list )
@@ -160,18 +158,25 @@ dialog_menu_main()
}'
)"
- set -f # noglob
+ set -f # set noglob because descriptions in the $menu_list may contain
+ # `*' and get expanded by dialog(1) (doesn't affect Xdialog(1)).
+ # This prevents dialog(1) from expanding wildcards in help line.
- size=$( eval f_dialog_menu_${SHOW_DESC:+with_help_}size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $RCCONF_MENU_LIST )
+ local height width rows
+ eval f_dialog_menu${SHOW_DESC:+_with_help}_size \
+ height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ # Obtain default-item from previously stored selection
+ f_dialog_default_fetch defaultitem
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
@@ -179,12 +184,19 @@ dialog_menu_main()
--help-button \
--help-label \"\$msg_details\" \
${SHOW_DESC:+--item-help} \
- --menu \"\$prompt\" $size \
- $RCCONF_MENU_LIST \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+
+ # Only update default-item on success
+ [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice"
+
return $retval
}
@@ -196,9 +208,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -210,10 +222,13 @@ f_dialog_title "$msg_view_edit_startup_configuration"
f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
f_mustberoot_init
+#
+# Launch application main menu
+#
while :; do
dialog_menu_main
retval=$?
- mtag=$( f_dialog_menutag )
+ f_dialog_menutag_fetch mtag
if [ "$USE_XDIALOG" ]; then
case "$mtag" in
@@ -231,9 +246,7 @@ while :; do
case "$mtag" in
"X $msg_exit") break ;;
- "> $msg_add_new")
- $BSDCFG_LIBE/$APP_DIR/rcadd ${USE_XDIALOG:+-X}
- ;;
+ "> $msg_add_new") $BSDCFG_LIBE/$APP_DIR/rcadd ${USE_XDIALOG:+-X} ;;
"> $msg_delete")
# rcdelete has a similar interface that can inherit the below:
export SHOW_VALUE SHOW_DESC SHOW_DEFAULT_VALUE SHOW_CONFIGURED
diff --git a/usr.sbin/bsdconfig/startup/rcdelete b/usr.sbin/bsdconfig/startup/rcdelete
index 578b13e..b6eeba4 100755
--- a/usr.sbin/bsdconfig/startup/rcdelete
+++ b/usr.sbin/bsdconfig/startup/rcdelete
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -48,7 +48,6 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
# Global map/menu-list for the main menu
#
RCCONF_MAP=
-_RCCONF_MAP=
RCCONF_MENU_LIST=
#
@@ -73,46 +72,19 @@ fi
############################################################ FUNCTIONS
-# dialog_menu_main
+# dialog_create_main
#
-# Display the dialog(1)-based application main menu.
+# Create the dialog(1) main menu. Separated from dialog_menu_main (used to
+# display the menu) to speed up execution (we only call this function when
+# initializing or changing the view details).
#
-dialog_menu_main()
+dialog_create_main()
{
- local size
- local hline="$hline_arrows_tab_enter"
- local prompt=""
-
- RCCONF_MENU_LIST="
- 'X $msg_exit_cancel' '$msg_exit_cancel_desc'
- ${SHOW_DESC:+'$msg_exit_cancel_help'}
- '> $msg_delete_selected' '$msg_delete_selected_desc'
- ${SHOW_DESC:+'$msg_delete_selected_help'}
- '> $msg_all' '$msg_all_desc'
- ${SHOW_DESC:+'$msg_all_help'}
- '> $msg_none' '$msg_none_desc'
- ${SHOW_DESC:+'$msg_none_help'}
- ${USE_XDIALOG:+
- '> $msg_view_details' '$msg_view_details_desc'
- ${SHOW_DESC:+'$msg_view_details_help'}
- }
- " # END-QUOTE
-
- if [ ! "$_RCCONF_MAP" ]; then
- # Genreate RCCONF_MAP of `var desc ...' per-line
- f_dialog_info "$msg_creating_rcconf_map"
- RCCONF_MAP=$( f_startup_rcconf_map )
- export RCCONF_MAP
- # Generate _${var}_desc variables from $RCCONF_MAP
- f_startup_rcconf_map_expand
- export _RCCONF_MAP=1
- fi
-
# Show infobox for modes that take a while to calculate/display
[ "$SHOW_DEFAULT_VALUE" -o "$SHOW_CONFIGURED" ] &&
f_dialog_info "$msg_creating_menu_list"
- RCCONF_MENU_LIST="$RCCONF_MENU_LIST $(
+ RCCONF_MENU_LIST=$(
. "$RC_DEFAULTS" > /dev/null
source_rc_confs > /dev/null
var_list=$( f_startup_rcconf_list )
@@ -165,55 +137,129 @@ dialog_menu_main()
}
printf "\n"
}'
- )"
+ )
+}
- set -f # noglob
+# dialog_menu_main
+#
+# Display the dialog(1)-based application main menu.
+#
+dialog_menu_main()
+{
+ local prompt=
+ local menu_list="
+ 'X $msg_exit_cancel' '$msg_exit_cancel_desc'
+ ${SHOW_DESC:+'$msg_exit_cancel_help'}
+ '> $msg_delete_selected' '$msg_delete_selected_desc'
+ ${SHOW_DESC:+'$msg_delete_selected_help'}
+ '> $msg_all' '$msg_all_desc'
+ ${SHOW_DESC:+'$msg_all_help'}
+ '> $msg_none' '$msg_none_desc'
+ ${SHOW_DESC:+'$msg_none_help'}
+ ${USE_XDIALOG:+
+ '> $msg_view_details' '$msg_view_details_desc'
+ ${SHOW_DESC:+'$msg_view_details_help'}
+ }
+ " # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_arrows_tab_enter"
- size=$( eval f_dialog_menu_${SHOW_DESC:+with_help_}size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $RCCONF_MENU_LIST )
+ #
+ # [Re-]Accent the menu list before incorporating it
+ #
+ local rcconf_var details help menu_buf delete
+ eval set -- $RCCONF_MENU_LIST
+ while [ $# -gt 0 ]; do
+ rcconf_var="$1" details="$2" delete=
+ f_shell_escape "$details" details
+ if [ "$SHOW_DESC" ]; then
+ help="$3"
+ f_shell_escape "$help" help
+ shift 3 # rcconf_var/details/help
+ else
+ shift 2 # rcconf_var/details
+ fi
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ # Update mark
+ f_getvar _${rcconf_var# }_delete delete
+ if [ "$delete" ]; then
+ details="[X]${details#???}"
+ else
+ details="[ ]${details#???}"
+ fi
+
+ # Update buffer with modified elements
+ menu_buf="$menu_buf
+ '$rcconf_var' '$details' ${SHOW_DESC:+'$help'}" # End-Quote
+ done
+ menu_list="$menu_list $menu_buf"
+
+ set -f # set noglob because descriptions in the $menu_list may contain
+ # `*' and get expanded by dialog(1) (doesn't affect Xdialog(1)).
+ # This prevents dialog(1) from expanding wildcards in help line.
+
+ local height width rows
+ eval f_dialog_menu${SHOW_DESC:+_with_help}_size \
+ height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ # Obtain default-item from previously stored selection
+ f_dialog_default_fetch defaultitem
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
+ --keep-tite \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
--help-button \
--help-label \"\$msg_details\" \
${SHOW_DESC:+--item-help} \
- --menu \"\$prompt\" $size \
- $RCCONF_MENU_LIST \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+
+ # Only update default-item on success
+ [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice"
+
return $retval
}
-# dialog_menu_delete $var1 [$var2 ...]
+# dialog_menu_confirm_delete $var1 [$var2 ...]
#
-# Get the user's blessing to delete one or more variables.
-# if (and only-if) the user confirms (does not press ESC or Cancel/NO).
+# Get the user's blessing to delete one or more variables. Returns success if
+# (and only-if) the user confirms (does not press ESC or Cancel/NO). Does NOT
+# return the user's menu-choice.
#
-dialog_menu_delete()
+dialog_menu_confirm_delete()
{
- local size
- local hline="$hline_arrows_tab_enter"
local prompt="$msg_are_you_sure_you_want_delete_the_following"
- local var_list menu_list
+ local menu_list # Calculated below
+ local hline="$hline_arrows_tab_enter"
[ $# -ge 1 ] || return $FAILURE
+ # If asked to delete only one variable, simply ask and return
if [ $# -eq 1 ]; then
- f_noyes "$msg_are_you_sure_you_want_to_delete" "$delete_vars"
+ f_noyes "$msg_are_you_sure_you_want_to_delete" "$1"
return $?
fi
+ # Not reached unless requested to delete multiple variables
+ # Generate a menu to cleanly display the variables to be deleted
+ local var_list
var_list=$( for var in $*; do echo "$var"; done | sort -u )
menu_list=$(
. "$RC_DEFAULTS"
@@ -234,31 +280,30 @@ dialog_menu_delete()
}'
)
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
local defaultno="defaultno"
[ "$USE_XDIALOG" ] && defaultno="default-no"
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--$defaultno \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
- 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
- local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- return $retval
+ 2> /dev/null
+
+ # Menu choice ignored; status of above command returned
}
############################################################ MAIN
@@ -269,9 +314,9 @@ dialog_menu_delete()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -283,20 +328,32 @@ f_dialog_title "$msg_delete_startup_directives"
f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
f_mustberoot_init
+# Genreate $RCCONF_MAP of `var desc ...' per-line (see share/rcconf.subr)
+f_dialog_info "$msg_creating_rcconf_map"
+f_startup_rcconf_map RCCONF_MAP
+
+# Generate _${var}_desc variables from $RCCONF_MAP
+f_startup_rcconf_map_expand RCCONF_MAP
+
+# Generate RCCONF_MENU_LIST from $RCCONF_MAP
+dialog_create_main
+
+#
+# Launch application main menu
+#
while :; do
dialog_menu_main
retval=$?
- mtag=$( f_dialog_menutag )
+ f_dialog_menutag_fetch mtag
if [ "$USE_XDIALOG" ]; then
- case "$mtag" in
- "> $msg_view_details")
- f_dialog_input_view_details
+ case "$mtag" in "> $msg_view_details")
+ f_dialog_input_view_details && dialog_create_main
continue
esac
elif [ $retval -eq 2 ]; then
# The ``Help'' button (labeled "Details") was pressed
- f_dialog_input_view_details
+ f_dialog_input_view_details && dialog_create_main
continue
fi
@@ -310,19 +367,17 @@ while :; do
[ "$( eval echo \$_${var}_delete )" ] || continue
delete_vars="$delete_vars${delete_vars:+ }$var"
done
- unset var # no longer needed
- if dialog_menu_delete $delete_vars; then
+ if dialog_menu_confirm_delete $delete_vars; then
f_dialog_title "$msg_info"
f_dialog_info "$msg_deleting_selected_directives"
f_dialog_title_restore
for var in $delete_vars; do
- err=$( f_sysrc_delete $var 2>&1 )
- if [ $? -ne $SUCCESS ]; then
+ if ! err=$( f_sysrc_delete $var 2>&1 ); then
f_dialog_msgbox "$err\n"
break
fi
done
- unset var # no longer needed
+ dialog_create_main
fi
;;
"> $msg_all")
@@ -330,7 +385,6 @@ while :; do
setvar _${var}_delete 1
export _${var}_delete
done
- unset var # no longer needed
;;
"> $msg_none")
var_list=$( set | awk -F= "
@@ -340,19 +394,17 @@ while :; do
}"
)
[ "$var_list" ] && unset $var_list
- unset var_list # no longer needed
;;
*) # Anything else is a variable to edit
var="${mtag# }"
# Toggle the state-variable and loop back to menu
- if eval [ \"\${_${var}_delete+set}\" ]; then
+ if f_isset _${var}_delete; then
unset _${var}_delete
else
setvar _${var}_delete 1
export _${var}_delete
fi
- unset var # no longer needed
esac
done
diff --git a/usr.sbin/bsdconfig/startup/rcedit b/usr.sbin/bsdconfig/startup/rcedit
index 0114368..de7f321 100755
--- a/usr.sbin/bsdconfig/startup/rcedit
+++ b/usr.sbin/bsdconfig/startup/rcedit
@@ -1,6 +1,6 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -49,9 +49,9 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -62,6 +62,9 @@ shift $(( $OPTIND - 1 ))
f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
f_mustberoot_init
+#
+# Edit the rc.conf(5) variable(s) passed as argument(s)
+#
f_dialog_rcedit "$@"
################################################################################
diff --git a/usr.sbin/bsdconfig/startup/rcvar b/usr.sbin/bsdconfig/startup/rcvar
index d655e61..7d29bfc 100755
--- a/usr.sbin/bsdconfig/startup/rcvar
+++ b/usr.sbin/bsdconfig/startup/rcvar
@@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012-2013 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -49,7 +49,6 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
RCVAR_MAP=
_RCVAR_MAP=
-RCVAR_MENU_LIST=
#
# Options
@@ -65,14 +64,13 @@ RCVAR_MENU_LIST=
#
dialog_menu_main()
{
- local size
- local hline="$hline_arrows_tab_enter"
- local prompt=""
-
- RCVAR_MENU_LIST="
+ local prompt=
+ local menu_list="
'X $msg_exit' '$msg_exit_this_menu'
${SHOW_DESC:+'$msg_exit_this_menu'}
" # END-QUOTE
+ local hline="$hline_arrows_tab_enter"
+ local defaultitem= # Calculated below
if [ ! "$_RCVAR_MAP" ]; then
# Generate RCVAR_MAP of `rcvar dflt script desc ...' per-line
@@ -82,7 +80,7 @@ dialog_menu_main()
export _RCVAR_MAP=1
fi
- RCVAR_MENU_LIST="$RCVAR_MENU_LIST $(
+ menu_list="$menu_list $(
. "$RC_DEFAULTS" > /dev/null
source_rc_confs > /dev/null
for rcvar in $( echo "$RCVAR_MAP" | awk '{print $1}' ); do
@@ -124,29 +122,49 @@ dialog_menu_main()
}'
)"
- set -f # noglob
-
- size=$( eval f_dialog_menu_${SHOW_DESC:+with_help_}size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $RCVAR_MENU_LIST )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ set -f # set noglob because descriptions in the $menu_list may
+ # contain `*' and get expanded by dialog(1). This prevents
+ # dialog(1) from expanding wildcards in the help line.
+
+ local height width rows
+ eval f_dialog_menu${SHOW_DESC:+_with_help}_size \
+ height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ # Obtain default-item from previously stored selection
+ f_dialog_default_fetch defaultitem
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
+ --keep-tite \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
${SHOW_DESC:+--item-help} \
- --menu \"\$prompt\" $size \
- $RCVAR_MENU_LIST \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+ f_dialog_default_store "$menu_choice"
+
+ if [ $retval -eq $SUCCESS ]; then
+ local item
+ item=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \
+ \"\$menu_choice\" $menu_list )
+ f_dialog_menuitem_store "$item"
+ fi
+
return $retval
}
@@ -158,9 +176,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -172,30 +190,27 @@ f_dialog_title "$msg_toggle_startup_services"
f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
f_mustberoot_init
+#
+# Launch application main menu
+#
while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
+ dialog_menu_main || f_die
+ f_dialog_menutag_fetch mtag
- [ $retval -eq 0 ] || f_die
+ [ "$mtag" = "X $msg_exit" ] && break
- case "$mtag" in
- "X $msg_exit") break ;;
- *) # Anything else is an rcvar to toggle
+ # Anything else is an rcvar to toggle
- rcvar="${mtag# }"
- value=$( eval f_dialog_menutag2item${SHOW_DESC:+_with_help} \
- \"\$mtag\" $RCVAR_MENU_LIST )
+ rcvar="${mtag# }"
+ f_dialog_menuitem_fetch value
- # Determine the new [toggled] value to use
- case "$value" in
- "[X]"*) value="NO";;
- *) value="YES";;
- esac
-
- err=$( f_sysrc_set "$rcvar" "$value" 2>&1 ) ||
- f_dialog_msgbox "$err"
+ # Determine the new [toggled] value to use
+ case "$value" in
+ "[X]"*) value="NO" ;;
+ *) value="YES"
esac
+
+ err=$( f_sysrc_set "$rcvar" "$value" 2>&1 ) || f_dialog_msgbox "$err"
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/startup/share/rcconf.subr b/usr.sbin/bsdconfig/startup/share/rcconf.subr
index 12eafd9..4c3e0d6 100644
--- a/usr.sbin/bsdconfig/startup/share/rcconf.subr
+++ b/usr.sbin/bsdconfig/startup/share/rcconf.subr
@@ -1,7 +1,7 @@
if [ ! "$_STARTUP_RCCONF_SUBR" ]; then _STARTUP_RCCONF_SUBR=1
#
-# Copyright (c) 2006-2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2006-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_STARTUP_RCCONF_SUBR" ]; then _STARTUP_RCCONF_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -88,7 +88,7 @@ f_startup_rcconf_list()
)
}
-# f_startup_rcconf_map
+# f_startup_rcconf_map [$var_to_set]
#
# Produce a map (beit from in-memory cache or on-disk cache) of rc.conf(5)
# variables and their descriptions. The map returned has the following format:
@@ -100,11 +100,21 @@ f_startup_rcconf_list()
# var the rc.conf(5) variable
# description description of the variable
#
+# If $var_to_set is missing or NULL, the map is printed to standard output for
+# capturing in a sub-shell (which is less-recommended because of performance
+# degredation; for example, when called in a loop).
+#
f_startup_rcconf_map()
{
+ local __var_to_set="$1"
+
# If the in-memory cached value is available, return it immediately
if [ "$_STARTUP_RCCONF_MAP" ]; then
- echo "$STARTUP_RCCONF_MAP"
+ if [ "$__var_to_set" ]; then
+ setvar "$__var_to_set" "$STARTUP_RCCONF_MAP"
+ else
+ echo "$STARTUP_RCCONF_MAP"
+ fi
return $SUCCESS
fi
@@ -117,8 +127,8 @@ f_startup_rcconf_map()
# cache file (containing this digest on the first line) is valid and
# can be used to quickly populate the cache value for immediate return.
#
- local rc_defaults_digest
- rc_defaults_digest=$( md5 < "$RC_DEFAULTS" )
+ local __rc_defaults_digest
+ __rc_defaults_digest=$( md5 < "$RC_DEFAULTS" )
#
# Check to see if the global persistant cache file exists
@@ -126,7 +136,7 @@ f_startup_rcconf_map()
if [ -f "$STARTUP_RCCONF_MAP_CACHEFILE" ]; then
#
# Attempt to populate the in-memory cache with the (soon to be)
- # be validated on-disk cache. If validation fails, fall-back to
+ # validated on-disk cache. If validation fails, fall-back to
# the current value and provide error exit status.
#
STARTUP_RCCONF_MAP=$(
@@ -138,7 +148,8 @@ f_startup_rcconf_map()
# one populate the in-memory cache from the on-
# disk cache and provide success exit status.
#
- if [ "$digest" = "$rc_defaults_digest" ]; then
+ if [ "$digest" = "$__rc_defaults_digest" ]
+ then
cat
exit $SUCCESS
else
@@ -148,10 +159,15 @@ f_startup_rcconf_map()
fi
) < "$STARTUP_RCCONF_MAP_CACHEFILE"
)
- export STARTUP_RCCONF_MAP
- if [ $? -eq $SUCCESS ]; then
+ local __retval=$?
+ export STARTUP_RCCONF_MAP # Make children faster (export cache)
+ if [ $__retval -eq $SUCCESS ]; then
export _STARTUP_RCCONF_MAP=1
- echo "$STARTUP_RCCONF_MAP"
+ if [ "$__var_to_set" ]; then
+ setvar "$__var_to_set" "$STARTUP_RCCONF_MAP"
+ else
+ echo "$STARTUP_RCCONF_MAP"
+ fi
return $SUCCESS
fi
# Otherwise, fall-thru to create in-memory cache from scratch
@@ -191,30 +207,34 @@ f_startup_rcconf_map()
)
export STARTUP_RCCONF_MAP
export _STARTUP_RCCONF_MAP=1
- echo "$STARTUP_RCCONF_MAP"
+ if [ "$__var_to_set" ]; then
+ setvar "$__var_to_set" "$STARTUP_RCCONF_MAP"
+ else
+ echo "$STARTUP_RCCONF_MAP"
+ fi
#
# Attempt to create the persistant global cache
#
# Create a new temporary file to write to
- local tmpfile="$( mktemp -t "$pgm" )"
- [ "$tmpfile" ] || return $FAILURE
+ local __tmpfile="$( mktemp -t "$pgm" )"
+ [ "$__tmpfile" ] || return $FAILURE
# Write the temporary file contents
- echo "$rc_defaults_digest" > "$tmpfile"
- echo "$STARTUP_RCCONF_MAP" >> "$tmpfile"
+ echo "$__rc_defaults_digest" > "$__tmpfile"
+ echo "$STARTUP_RCCONF_MAP" >> "$__tmpfile"
# Finally, move the temporary file into place
case "$STARTUP_RCCONF_MAP_CACHEFILE" in
*/*) f_quietly mkdir -p "${STARTUP_RCCONF_MAP_CACHEFILE%/*}"
esac
- mv "$tmpfile" "$STARTUP_RCCONF_MAP_CACHEFILE"
+ mv "$__tmpfile" "$STARTUP_RCCONF_MAP_CACHEFILE"
}
-# f_startup_rcconf_map_expand
+# f_startup_rcconf_map_expand $var_to_get
#
-# Expands the map ($RCCONF_MAP) into the shell environment namespace by
+# Expands the map ($var_to_get) into the shell environment namespace by
# creating _${var}_desc variables containing the description of each variable
# encountered.
#
@@ -222,7 +242,8 @@ f_startup_rcconf_map()
#
f_startup_rcconf_map_expand()
{
- eval "$( echo "$RCCONF_MAP" | awk '
+ local var_to_get="$1"
+ eval "$( f_getvar "$var_to_get" | awk '
BEGIN {
rword = "^[[:space:]]*[^[:space:]]*[[:space:]]*"
}
@@ -246,27 +267,40 @@ f_startup_rcconf_map_expand()
# Mutually exclusive options:
#
# SHOW_VALUE Show the value (default; override only)
-# SHOW_VALUE_DEFAULT Show both value and default
+# SHOW_DEFAULT_VALUE Show both value and default
# SHOW_CONFIGURED Show rc.conf(5) file variable is configured in
#
# Each variable is treated as a boolean (NULL for false, non-NULL for true).
#
-# Variables are exported for later-required awk(1) ENVIRON visibility.
+# Variables are exported for later-required awk(1) ENVIRON visibility. Returns
+# success unless the user chose `Cancel' or pressed Escape.
#
f_dialog_input_view_details()
{
- local menu_list size
+ local prompt=
+ local menu_list # calculated below
+ local defaultitem= # calculated below
local hline="$hline_arrows_tab_enter"
- local prompt=""
- local md=" " m1=" " m2=" " m3=" "
- [ "$SHOW_DESC" ] && md="X"
- [ "$SHOW_VALUE" ] && m1="*"
- [ "$SHOW_DEFAULT_VALUE" ] && m2="*"
- [ "$SHOW_CONFIGURED" ] && m3="*"
+ # Calculate marks for checkboxes and radio buttons
+ local md=" "
+ if [ "$SHOW_DESC" ]; then
+ md="X"
+ fi
+ local m1=" " m2=" " m3=" "
+ if [ "$SHOW_VALUE" ]; then
+ m1="*"
+ defaultitem="1 ($m1) $msg_show_value"
+ elif [ "$SHOW_DEFAULT_VALUE" ]; then
+ m2="*"
+ defaultitem="2 ($m2) $msg_show_default_value"
+ elif [ "$SHOW_CONFIGURED" ]; then
+ m3="*"
+ defaultitem="3 ($m3) $msg_show_configured"
+ fi
+ # Create the menu list with the above-calculated marks
menu_list="
- 'X $msg_exit' '$msg_exit_this_menu'
'R $msg_reset' '$msg_reset_desc'
'D [$md] $msg_desc' '$msg_desc_desc'
'1 ($m1) $msg_show_value' '$msg_show_value_desc'
@@ -274,35 +308,35 @@ f_dialog_input_view_details()
'3 ($m3) $msg_show_configured' '$msg_show_configured_desc'
" # END-QUOTE
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
f_dialog_title "$msg_choose_view_details"
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
+ local mtag
+ mtag=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
-
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- local mtag="$( f_dialog_menutag )"
+ f_dialog_data_sanitize mtag
f_dialog_title_restore
- [ $retval -eq 0 ] || return $SUCCESS
- [ "$mtag" = "X $msg_exit" ] && return $SUCCESS
+ [ $retval -eq 0 ] || return $FAILURE
case "$mtag" in
"R $msg_reset")
@@ -331,23 +365,21 @@ f_dialog_input_view_details()
esac
}
-# f_dialog_input_rclist
+# f_dialog_input_rclist [$default]
#
# Presents a menu of rc.conf(5) defaults (with, or without descriptions). This
# function should be treated like a call to dialog(1) (the exit status should
-# be captured and f_dialog_menutag() should be used to clean-up and get the
-# user's response).
+# be captured and f_dialog_menutag_fetch() should be used to get the user's
+# response). Optionally if present and non-null, highlight $default rcvar.
#
f_dialog_input_rclist()
{
- local size
- local hline="$hline_arrows_tab_enter"
local prompt="$msg_please_select_an_rcconf_directive"
- local menu_list
-
- menu_list="
- 'X $msg_exit' '' ${SHOW_DESC:+'$msg_exit_help'}
+ local menu_list="
+ 'X $msg_exit' '' ${SHOW_DESC:+'$msg_exit_this_menu'}
" # END-QUOTE
+ local defaultitem="$1"
+ local hline="$hline_arrows_tab_enter"
if [ ! "$_RCCONF_MAP" ]; then
# Generate RCCONF_MAP of `var desc ...' per-line
@@ -385,29 +417,35 @@ f_dialog_input_rclist()
}'
)"
- set -f # noglob
-
- size=$( eval f_dialog_menu_${SHOW_DESC:+with_help_}size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
+ set -f # set noglob because descriptions in the $menu_list may contain
+ # `*' and get expanded by dialog(1) (doesn't affect Xdialog(1)).
+ # This prevents dialog(1) from expanding wildcards in help line.
+
+ local height width rows
+ eval f_dialog_menu${SHOW_DESC:+_with_help}_size \
+ height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
+ --default-item \"\$defaultitem\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
${SHOW_DESC:+--item-help} \
- --menu \"\$prompt\" $size \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -426,20 +464,19 @@ f_dialog_input_rcvar()
while :; do
# Return if user either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_please_enter_rcvar_name" \
- "$_input" "$hline_alnum_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_please_enter_rcvar_name" \
+ "$_input" "$hline_alnum_tab_enter" || return
# Check for invalid entry (1of2)
if ! echo "$_input" | grep -q "^[[:alpha:]_]"; then
- f_dialog_msgbox "$msg_rcvar_must_start_with"
+ f_show_msg "$msg_rcvar_must_start_with"
continue
fi
# Check for invalid entry (2of2)
if ! echo "$_input" | grep -q "^[[:alpha:]_][[:alnum:]_]*$"
then
- f_dialog_msgbox "$msg_rcvar_contains_invalid_chars"
+ f_show_msg "$msg_rcvar_contains_invalid_chars"
continue
fi
diff --git a/usr.sbin/bsdconfig/startup/share/rcedit.subr b/usr.sbin/bsdconfig/startup/share/rcedit.subr
index cb4a411..64ee1cc 100644
--- a/usr.sbin/bsdconfig/startup/share/rcedit.subr
+++ b/usr.sbin/bsdconfig/startup/share/rcedit.subr
@@ -68,9 +68,8 @@ f_dialog_rcedit()
fi
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg" "$_input" \
- "$hline_alnum_punc_tab_enter"
- ) || return
+ f_dialog_input _input "$msg" "$_input" \
+ "$hline_alnum_punc_tab_enter" || return
# Return if the value has not changed from current
local cur_val="$( f_sysrc_get "$var" )"
diff --git a/usr.sbin/bsdconfig/startup/share/rcvar.subr b/usr.sbin/bsdconfig/startup/share/rcvar.subr
index 702c5e9..0986895 100644
--- a/usr.sbin/bsdconfig/startup/share/rcvar.subr
+++ b/usr.sbin/bsdconfig/startup/share/rcvar.subr
@@ -1,7 +1,7 @@
if [ ! "$_STARTUP_RCVAR_SUBR" ]; then _STARTUP_RCVAR_SUBR=1
#
-# Copyright (c) 2006-2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2006-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_STARTUP_RCVAR_SUBR" ]; then _STARTUP_RCVAR_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -65,7 +65,7 @@ STARTUP_RCVAR_MAP_CACHEFILE="/var/run/bsdconfig/startup_rcvar_map.cache"
############################################################ FUNCTIONS
-# f_startup_rcvar_map
+# f_startup_rcvar_map [$var_to_set]
#
# Produce a map (beit from in-memory cache or on-disk cache) of rc.d scripts
# and their associated rcvar's. The map returned has the following format:
@@ -79,11 +79,21 @@ STARTUP_RCVAR_MAP_CACHEFILE="/var/run/bsdconfig/startup_rcvar_map.cache"
# script the rc.d script in-question
# description description of the variable from rc.conf(5) defaults
#
+# If $var_to_set is missing or NULL, the map is printed to standard output for
+# capturing in a sub-shell (which is less-recommended because of performance
+# degredation; for example, when called in a loop).
+#
f_startup_rcvar_map()
{
+ local __var_to_set="$1"
+
# If the in-memory cached value is available, return it immediately
if [ "$_STARTUP_RCVAR_MAP" ]; then
- echo "$STARTUP_RCVAR_MAP"
+ if [ "$__var_to_set" ]; then
+ setvar "$__var_to_set" "$STARTUP_RCVAR_MAP"
+ else
+ echo "$STARTUP_RCVAR_MAP"
+ fi
return $SUCCESS
fi
@@ -92,19 +102,20 @@ f_startup_rcvar_map()
#
# Get a list of /etc/rc.d scripts ...
- local file rc_script_list=
- for file in "$ETC_RC_D"/*; do
- [ -f "$file" ] || continue
- [ -x "$file" ] || continue
- rc_script_list="$rc_script_list${rc_script_list:+ }$file"
+ local __file __rc_script_list=
+ for __file in "$ETC_RC_D"/*; do
+ [ -f "$__file" ] || continue
+ [ -x "$__file" ] || continue
+ __rc_script_list="$__rc_script_list $__file"
done
# ... and /usr/local/etc/rc.d scripts
- rc_script_list="$rc_script_list${rc_script_list:+ }$(
+ __rc_script_list="$__rc_script_list $(
local_startup=$( f_sysrc_get local_startup )
f_include "$ETC_RC_SUBR"
find_local_scripts_new
echo $local_rc
)"
+ __rc_script_list="${__rc_script_list# }" # Trim leading space
#
# Calculate a digest given the checksums of all dependencies (scripts
@@ -113,9 +124,9 @@ f_startup_rcvar_map()
# first line) is valid and can be used to quickly populate the cache
# value for immediate return.
#
- local rc_script_list_digest
- rc_script_list_digest=$( cd "$ETC_RC_D" &&
- cksum "$RC_DEFAULTS" $rc_script_list | md5 )
+ local __rc_script_list_digest
+ __rc_script_list_digest=$( cd "$ETC_RC_D" &&
+ cksum "$RC_DEFAULTS" $__rc_script_list | md5 )
#
# Check to see if the global persistant cache file exists
@@ -123,19 +134,19 @@ f_startup_rcvar_map()
if [ -f "$STARTUP_RCVAR_MAP_CACHEFILE" ]; then
#
# Attempt to populate the in-memory cache with the (soon to be)
- # be validated on-disk cache. If validation fails, fall-back to
- # the current value and provide error exit status.
+ # validated on-disk cache. If validation fails, fall-back to
+ # the current value and return error.
#
STARTUP_RCVAR_MAP=$(
- ( # Get digest as the first word on the first line
+ ( # Get digest as first word on first line
read digest rest_ignored
#
# If the stored digest matches the calculated-
# one populate the in-memory cache from the on-
- # disk cache and provide success exit status.
+ # disk cache and return success.
#
- if [ "$digest" = "$rc_script_list_digest" ]
+ if [ "$digest" = "$__rc_script_list_digest" ]
then
cat
exit $SUCCESS
@@ -146,10 +157,15 @@ f_startup_rcvar_map()
fi
) < "$STARTUP_RCVAR_MAP_CACHEFILE"
)
- export STARTUP_RCVAR_MAP
- if [ $? -eq $SUCCESS ]; then
+ local __retval=$?
+ export STARTUP_RCVAR_MAP # Make children faster (export cache)
+ if [ $__retval -eq $SUCCESS ]; then
export _STARTUP_RCVAR_MAP=1
- echo "$STARTUP_RCVAR_MAP"
+ if [ "$__var_to_set" ]; then
+ setvar "$__var_to_set" "$STARTUP_RCVAR_MAP"
+ else
+ echo "$STARTUP_RCVAR_MAP"
+ fi
return $SUCCESS
fi
# Otherwise, fall-thru to create in-memory cache from scratch
@@ -162,7 +178,7 @@ f_startup_rcvar_map()
#
STARTUP_RCVAR_MAP=$(
- for script in $rc_script_list; do
+ for script in $__rc_script_list; do
rcvar_list=$( $script rcvar | awk -F= \
-v script="$script" '
/^'"$STARTUP_RCVAR_REGEX"'/ {
@@ -184,25 +200,29 @@ f_startup_rcvar_map()
)
export STARTUP_RCVAR_MAP
export _STARTUP_RCVAR_MAP=1
- echo "$STARTUP_RCVAR_MAP"
+ if [ "$__var_to_set" ]; then
+ setvar "$__var_to_set" "$STARTUP_RCVAR_MAP"
+ else
+ echo "$STARTUP_RCVAR_MAP"
+ fi
#
- # Attempt to create the persistant global cache
+ # Attempt to create/update the persistant global cache
#
# Create a new temporary file to write to
- local tmpfile="$( mktemp -t "$pgm" )"
- [ "$tmpfile" ] || return $FAILURE
+ local __tmpfile="$( mktemp -t "$pgm" )"
+ [ "$__tmpfile" ] || return $FAILURE
# Write the temporary file contents
- echo "$rc_script_list_digest" > "$tmpfile"
- echo "$STARTUP_RCVAR_MAP" >> "$tmpfile"
+ echo "$__rc_script_list_digest" > "$__tmpfile"
+ echo "$STARTUP_RCVAR_MAP" >> "$__tmpfile"
# Finally, move the temporary file into place
case "$STARTUP_RCVAR_MAP_CACHEFILE" in
*/*) f_quietly mkdir -p "${STARTUP_RCVAR_MAP_CACHEFILE%/*}"
esac
- mv "$tmpfile" "$STARTUP_RCVAR_MAP_CACHEFILE"
+ mv "$__tmpfile" "$STARTUP_RCVAR_MAP_CACHEFILE"
}
############################################################ MAIN
diff --git a/usr.sbin/bsdconfig/startup/startup b/usr.sbin/bsdconfig/startup/startup
index c9229b7..6b02cb4 100755
--- a/usr.sbin/bsdconfig/startup/startup
+++ b/usr.sbin/bsdconfig/startup/startup
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -48,37 +48,44 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline="$hline_arrows_tab_enter"
- local prompt=""
-
- menu_list="
+ local prompt=
+ local menu_list="
'X' '$msg_exit'
'1' '$msg_toggle_startup_services'
'2' '$msg_view_edit_startup_configuration'
'3' '$msg_miscellaneous_startup_services'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_arrows_tab_enter"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ # Obtain default-item from previously stored selection
+ f_dialog_default_fetch defaultitem
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+ f_dialog_default_store "$menu_choice"
return $retval
}
@@ -90,9 +97,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -108,22 +115,22 @@ f_mustberoot_init
# Launch application main menu
#
while :; do
- dialog_menu_main
- retval=$?
- mtag=$( f_dialog_menutag )
-
- [ $retval -eq 0 ] || f_die
+ dialog_menu_main || f_die
+ f_dialog_menutag_fetch mtag
+ command=
case "$mtag" in
- X) # Exit
- break ;;
- 1) # Toggle Startup Services
- $BSDCFG_LIBE/$APP_DIR/rcvar ${USE_XDIALOG:+-X} ;;
- 2) # View/Edit Startup Configuration
- $BSDCFG_LIBE/$APP_DIR/rcconf ${USE_XDIALOG:+-X} ;;
- 3) # Miscellaneous Startup Services
- $BSDCFG_LIBE/$APP_DIR/misc ${USE_XDIALOG:+-X} ;;
+ X) break ;;
+ 1) command=rcvar ;; # Toggle Startup Services
+ 2) command=rcconf ;; # View/Edit Startup Configuration
+ 3) command=misc ;; # Miscellaneous Startup Services
esac
+
+ if [ "$command" ]; then
+ $BSDCFG_LIBE/$APP_DIR/$command ${USE_XDIALOG:+-X}
+ else
+ f_die 1 "$msg_unknown_startup_menu_selection"
+ fi
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/timezone/INDEX b/usr.sbin/bsdconfig/timezone/INDEX
index af17594..67fc50b 100644
--- a/usr.sbin/bsdconfig/timezone/INDEX
+++ b/usr.sbin/bsdconfig/timezone/INDEX
@@ -26,28 +26,32 @@
# $FreeBSD$
#
-# Title that will be shown on the bsdconfig menu
+# Title that will be shown in the bsdconfig menu.
+#
menu_title="Timezone"
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
#
-# a short descriptive line shown at the bottom of the bsdconfig menu.
-# keep it short because any line longer than the terminal width will
-# be truncated.
menu_help="Set up Time Zone"
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
#
-# two-part variable that defines an action to take when 'keyword'
-# is passed on a bsdconfig command line. variable takes the form
-# "keyword|command" and multiple occurrences of the variable
-# (with different 'keyword's, or different 'keyword's AND 'command's)
-# are allowed. If 'command' begins with a '/' then the full
-# path to the program is needed. If 'command' begins with anything
-# else it is a path relative to the directory this INDEX file is in.
-# 'keyword' can be i18n'ed but 'command' is the name of a script.
menu_selection="timezone|timezone"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
#
-# Items below this line do NOT need i18n translation----------------------
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
#
-# Name of the program to be run when this menu choice is selected.
-# if it begins with a '/' then the full path to the program is needed.
-# if it begins with anything else it is a path relative to the directory
-# this INDEX file is in.
menu_program="timezone"
diff --git a/usr.sbin/bsdconfig/timezone/USAGE b/usr.sbin/bsdconfig/timezone/USAGE
index a88369c..6dbe96d 100644
--- a/usr.sbin/bsdconfig/timezone/USAGE
+++ b/usr.sbin/bsdconfig/timezone/USAGE
@@ -1,5 +1,5 @@
-# Copyright (c) 2011-2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2011-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -11,11 +11,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -26,11 +26,15 @@
Usage: bsdconfig @PROGRAM_NAME@ [-ehnrSsvX] [-C chroot_dir] [zinfo_file | zinfo_name]
OPTIONS:
- -h Print usage statement and exit.
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
-e Only return success on exit if user selects a timezone AND
the selected timezone was successfully installed. By default
(without this flag), success is always returned unless an
error has occurred.
+ -h Print this usage statement and exit.
-n Do not create or copy files.
-r Reinstall the zoneinfo file installed last time. The name is
obtained from /var/db/zoneinfo.
diff --git a/usr.sbin/bsdconfig/timezone/share/continents.subr b/usr.sbin/bsdconfig/timezone/share/continents.subr
index 9a66ec7..02c4071 100644
--- a/usr.sbin/bsdconfig/timezone/share/continents.subr
+++ b/usr.sbin/bsdconfig/timezone/share/continents.subr
@@ -1,7 +1,7 @@
if [ ! "$_TIMEZONE_CONTINENTS_SUBR" ]; then _TIMEZONE_CONTINENTS_SUBR=1
#
# Copyright (c) 2011-2012 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_TIMEZONE_CONTINENTS_SUBR" ]; then _TIMEZONE_CONTINENTS_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
diff --git a/usr.sbin/bsdconfig/timezone/share/countries.subr b/usr.sbin/bsdconfig/timezone/share/countries.subr
index 6a39dc7..ff05766 100644
--- a/usr.sbin/bsdconfig/timezone/share/countries.subr
+++ b/usr.sbin/bsdconfig/timezone/share/countries.subr
@@ -1,7 +1,7 @@
if [ ! "$_TIMEZONE_COUNTRIES_SUBR" ]; then _TIMEZONE_COUNTRIES_SUBR=1
#
# Copyright (c) 2011-2012 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_TIMEZONE_COUNTRIES_SUBR" ]; then _TIMEZONE_COUNTRIES_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
diff --git a/usr.sbin/bsdconfig/timezone/share/iso3166.subr b/usr.sbin/bsdconfig/timezone/share/iso3166.subr
index 9af6393..205d5f5 100644
--- a/usr.sbin/bsdconfig/timezone/share/iso3166.subr
+++ b/usr.sbin/bsdconfig/timezone/share/iso3166.subr
@@ -1,7 +1,7 @@
if [ ! "$_TIMEZONE_ISO3166_SUBR" ]; then _TIMEZONE_ISO3166_SUBR=1
#
# Copyright (c) 2011-2012 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_TIMEZONE_ISO3166_SUBR" ]; then _TIMEZONE_ISO3166_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
diff --git a/usr.sbin/bsdconfig/timezone/share/menus.subr b/usr.sbin/bsdconfig/timezone/share/menus.subr
index 687e102..2028bf3 100644
--- a/usr.sbin/bsdconfig/timezone/share/menus.subr
+++ b/usr.sbin/bsdconfig/timezone/share/menus.subr
@@ -1,7 +1,7 @@
if [ ! "$_TIMEZONE_MENUS_SUBR" ]; then _TIMEZONE_MENUS_SUBR=1
#
# Copyright (c) 2011-2012 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_TIMEZONE_MENUS_SUBR" ]; then _TIMEZONE_MENUS_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
diff --git a/usr.sbin/bsdconfig/timezone/share/zones.subr b/usr.sbin/bsdconfig/timezone/share/zones.subr
index 3ba1d7a..b356323 100644
--- a/usr.sbin/bsdconfig/timezone/share/zones.subr
+++ b/usr.sbin/bsdconfig/timezone/share/zones.subr
@@ -1,7 +1,7 @@
if [ ! "$_TIMEZONE_ZONES_SUBR" ]; then _TIMEZONE_ZONES_SUBR=1
#
# Copyright (c) 2011-2012 Devin Teske
-# All Rights Reserved.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@ if [ ! "$_TIMEZONE_ZONES_SUBR" ]; then _TIMEZONE_ZONES_SUBR=1
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -348,7 +348,7 @@ f_read_zones()
f_install_zoneinfo_file()
{
local zoneinfo_file="$1"
- local copymode title msg err size
+ local copymode title msg err height width
if [ -L "$_PATH_LOCALTIME" ]; then
copymode=
@@ -371,227 +371,149 @@ f_install_zoneinfo_file()
fi
if [ "$USEDIALOG" ]; then
f_dialog_title "$msg_info"
- title="$DIALOG_TITLE"
- btitle="$DIALOG_BACKTITLE"
+ f_dialog_msgbox "$msg"
f_dialog_title_restore
- size=$( f_dialog_buttonbox_size "$title" \
- "$btitle" "$msg" )
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$msg\" $size
else
printf "%s\n" "$msg"
fi
fi
- if [ "$REALLYDOIT" ]; then
- f_dialog_title "$msg_error"
- title="$DIALOG_TITLE"
- btitle="$DIALOG_BACKTITLE"
- f_dialog_title_restore
+ [ "$REALLYDOIT" ] || return $SUCCESS
- if [ ! "$zoneinfo_file" ]; then
-
- err=$( rm -f "$_PATH_LOCALTIME" 2>&1 )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- size=$( f_dialog_buttonbox_size \
- "$title" \
- "$btitle" \
- "$err" )
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$err\" $size
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
+ if [ ! "$zoneinfo_file" ]; then
+ err=$( rm -f "$_PATH_LOCALTIME" 2>&1 )
+ if [ "$err" ]; then
+ if [ "$USEDIALOG" ]; then
+ f_dialog_title "$msg_error"
+ f_dialog_msgbox "$err"
+ f_dialog_title_restore
+ else
+ f_err "%s\n" "$err"
fi
+ return $FAILURE
+ fi
- err=$( rm -f "$_PATH_DB" 2>&1 )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- size=$( f_dialog_buttonbox_size \
- "$title" \
- "$btitle" \
- "$err" )
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$err\" $size
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
+ err=$( rm -f "$_PATH_DB" 2>&1 )
+ if [ "$err" ]; then
+ if [ "$USEDIALOG" ]; then
+ f_dialog_title "$msg_error"
+ f_dialog_msgbox "$err"
+ f_dialog_title_restore
+ else
+ f_err "%s\n" "$err"
fi
+ return $FAILURE
+ fi
- if [ "$VERBOSE" ]; then
- title="$msg_done"
- msg=$( printf "$msg_removed_file" \
- "$_PATH_LOCALTIME" )
- if [ "$USEDIALOG" ]; then
- size=$( f_dialog_buttonbox_size \
- "$title" \
- "$btitle" \
- "$msg" )
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$msg\" $size
- else
- printf "%s\n" "$msg"
- fi
+ if [ "$VERBOSE" ]; then
+ msg=$( printf "$msg_removed_file" "$_PATH_LOCALTIME" )
+ if [ "$USEDIALOG" ]; then
+ f_dialog_title "$msg_done"
+ f_dialog_msgbox "$msg"
+ f_dialog_title_restore
+ else
+ printf "%s\n" "$msg"
fi
+ fi
- return $SUCCESS
-
- fi # ! zoneinfo_file
+ return $SUCCESS
- if [ "$copymode" ]; then
+ fi # ! zoneinfo_file
- err=$( rm -f "$_PATH_LOCALTIME" 2>&1 )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- size=$( f_dialog_buttonbox_size \
- "$title" \
- "$btitle" \
- "$err" )
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$err\" $size
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
- fi
+ if [ "$copymode" ]; then
- err=$( umask 222 && : 2>&1 > "$_PATH_LOCALTIME" )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- size=$( f_dialog_buttonbox_size \
- "$title" \
- "$btitle" \
- "$err" )
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$err\" $size
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
+ err=$( rm -f "$_PATH_LOCALTIME" 2>&1 )
+ if [ "$err" ]; then
+ if [ "$USEDIALOG" ]; then
+ f_dialog_title "$msg_error"
+ f_dialog_msgbox "$err"
+ f_dialog_title_restore
+ else
+ f_err "%s\n" "$err"
fi
+ return $FAILURE
+ fi
- err=$( cat "$zoneinfo_file" 2>&1 > "$_PATH_LOCALTIME" )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- size=$( f_dialog_buttonbox_size \
- "$title" \
- "$btitle" \
- "$err" )
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$err\" $size
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
+ err=$( umask 222 && : 2>&1 > "$_PATH_LOCALTIME" )
+ if [ "$err" ]; then
+ if [ "$USEDIALOG" ]; then
+ f_dialog_title "$msg_error"
+ f_dialog_msgbox "$err"
+ f_dialog_title_restore
+ else
+ f_err "%s\n" "$err"
fi
+ return $FAILURE
+ fi
- else # ! copymode
-
- err=$( ( :< "$zoneinfo_file" ) 2>&1 )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- size=$( f_dialog_buttonbox_size \
- "$title" \
- "$btitle" \
- "$err" )
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$err\" $size
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
+ err=$( cat "$zoneinfo_file" 2>&1 > "$_PATH_LOCALTIME" )
+ if [ "$err" ]; then
+ if [ "$USEDIALOG" ]; then
+ f_dialog_title "$msg_error"
+ f_dialog_msgbox "$err"
+ f_dialog_title_restore
+ else
+ f_err "%s\n" "$err"
fi
+ return $FAILURE
+ fi
- err=$( rm -f "$_PATH_LOCALTIME" 2>&1 )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- size=$( f_dialog_buttonbox_size \
- "$title" \
- "$btitle" \
- "$err" )
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$err\" $size
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
- fi
+ else # ! copymode
- err=$( ln -s "$zoneinfo_file" "$_PATH_LOCALTIME" 2>&1 )
- if [ "$err" ]; then
- if [ "$USEDIALOG" ]; then
- size=$( f_dialog_buttonbox_size \
- "$title" \
- "$btitle" \
- "$err" )
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$err\" $size
- else
- f_err "%s\n" "$err"
- fi
- return $FAILURE
+ err=$( ( :< "$zoneinfo_file" ) 2>&1 )
+ if [ "$err" ]; then
+ if [ "$USEDIALOG" ]; then
+ f_dialog_title "$msg_error"
+ f_dialog_msgbox "$err"
+ f_dialog_title_restore
+ else
+ f_err "%s\n" "$err"
fi
+ return $FAILURE
+ fi
- fi # copymode
-
- if [ "$VERBOSE" ]; then
- title="$msg_done"
- if [ "$copymode" ]; then
- msg=$( printf "$msg_copied_timezone_file" \
- "$zoneinfo_file" \
- "$_PATH_LOCALTIME" )
+ err=$( rm -f "$_PATH_LOCALTIME" 2>&1 )
+ if [ "$err" ]; then
+ if [ "$USEDIALOG" ]; then
+ f_dialog_title "$msg_error"
+ f_dialog_msgbox "$err"
+ f_dialog_title_restore
else
- msg=$( printf "$msg_created_symlink" \
- "$_PATH_LOCALTIME" \
- "$zoneinfo_file" )
+ f_err "%s\n" "$err"
fi
+ return $FAILURE
+ fi
+
+ err=$( ln -s "$zoneinfo_file" "$_PATH_LOCALTIME" 2>&1 )
+ if [ "$err" ]; then
if [ "$USEDIALOG" ]; then
- size=$( f_dialog_buttonbox_size \
- "$title" "$btitle" "$msg" )
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --msgbox \"\$msg\" $size
+ f_dialog_title "$msg_error"
+ f_dialog_msgbox "$err"
+ f_dialog_title_restore
else
- printf "%s\n" "$msg"
+ f_err "%s\n" "$err"
fi
+ return $FAILURE
fi
- fi # REALLYDOIT
+ fi # copymode
+
+ if [ "$VERBOSE" ]; then
+ if [ "$copymode" ]; then
+ msg=$( printf "$msg_copied_timezone_file" \
+ "$zoneinfo_file" "$_PATH_LOCALTIME" )
+ else
+ msg=$( printf "$msg_created_symlink" \
+ "$_PATH_LOCALTIME" "$zoneinfo_file" )
+ fi
+ if [ "$USEDIALOG" ]; then
+ f_dialog_title "$msg_done"
+ f_dialog_msgbox "$msg"
+ f_dialog_title_restore
+ else
+ printf "%s\n" "$msg"
+ fi
+ fi
return $SUCCESS
}
diff --git a/usr.sbin/bsdconfig/timezone/timezone b/usr.sbin/bsdconfig/timezone/timezone
index 5649b60..709c8a8 100755
--- a/usr.sbin/bsdconfig/timezone/timezone
+++ b/usr.sbin/bsdconfig/timezone/timezone
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2011-2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2011-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -83,27 +83,37 @@ dialog_menu_main()
local title="$DIALOG_TITLE"
local btitle="$DIALOG_BACKTITLE"
local prompt="$msg_select_region"
- local size
-
- size=$( eval f_dialog_menu_size \
- \"\$title\" \
- \"\$btitle\" \
- \"\$prompt\" \
- \"\" \
- $continent_menu_list )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
- $continent_menu_list \
+ local defaultitem= # Calculated below
+ local hline=
+
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$title\" \
+ \"\$btitle\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $continent_menu_list
+
+ # Obtain default-item from previously stored selection
+ f_dialog_default_fetch defaultitem
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$title\" \
+ --backtitle \"\$btitle\" \
+ --hline \"\$hline\" \
+ --ok-label \"\$msg_ok\" \
+ --cancel-label \"\$msg_cancel\" \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $continent_menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+ f_dialog_default_store "$menu_choice"
return $retval
}
@@ -115,16 +125,16 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts C:ehnrsSvX flag; do
+while getopts C:ehnrsv$GETOPTS_STDARGS flag; do
case "$flag" in
- C) CHROOTENV="$OPTARG";;
- e) TZ_OR_FAIL=1;;
- n) REALLYDOIT=;;
+ C) CHROOTENV="$OPTARG" ;;
+ e) TZ_OR_FAIL=1 ;;
+ n) REALLYDOIT= ;;
r) REINSTALL=1
- USEDIALOG=;;
- s) SKIPUTC=1;;
- v) VERBOSE=1;;
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ USEDIALOG= ;;
+ s) SKIPUTC=1 ;;
+ v) VERBOSE=1 ;;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -234,29 +244,11 @@ if [ $# -ge 1 ]; then
default="$1"
f_dialog_title "$msg_default_zone_provided"
- title="$DIALOG_TITLE"
- btitle="$DIALOG_BACKTITLE"
- f_dialog_title_restore
msg=$( printf "\n$msg_use_default_zone" "$default" )
- size=$( f_dialog_buttonbox_size "$title" "$btitle" "$msg" )
-
- if [ "$USE_XDIALOG" ]; then
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_yes\" \
- --cancel-label \"\$msg_no\" \
- --yesno \"\$msg\" $size
- result=$?
- else
- eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --yes-label \"\$msg_yes\" \
- --no-label \"\$msg_no\" \
- --yesno \"\$msg\" $size
- result=$?
- fi
+ hline=
+ f_dialog_yesno "$msg" "$hline"
+ result=$?
+ f_dialog_title_restore
if [ $result -eq 0 ]; then
# User chose YES
@@ -285,13 +277,15 @@ f_make_menus # creates $continent_menu_list and $continent_*_menu_list
#
# Launch application main menu
#
+defaultctry=""
+defaultzone=""
NEED_CONTINENT=1
NEED_COUNTRY=1
while :; do
if [ "$NEED_CONTINENT" ]; then
dialog_menu_main # prompt the user to select a continent/ocean
retval=$?
- mtag=$( f_dialog_menutag )
+ f_dialog_menutag_fetch mtag
if [ $retval -ne 0 ]; then
[ "$TZ_OR_FAIL" ] && f_die
@@ -349,28 +343,30 @@ while :; do
# Calculate size of menu
#
menu_list=$( f_continent $cont menu_list )
- size=$( eval f_dialog_menu_size \
- \"\$title\" \
- \"\$btitle\" \
- \"\$prompt\" \
- \"\" \
- $menu_list )
+ eval f_dialog_menu_size height width rows \
+ \"\$title\" \
+ \"\$btitle\" \
+ \"\$prompt\" \
+ \"\" \
+ $menu_list
#
# Launch the country selection menu
#
- dialog_menu=$( eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
- $menu_list \
+ tag=$( eval $DIALOG \
+ --title \"\$title\" \
+ --backtitle \"\$btitle\" \
+ --ok-label \"\$msg_ok\" \
+ --cancel-label \"\$msg_cancel\" \
+ --default-item \"\$defaultctry\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- tag=$( f_dialog_menutag )
+ f_dialog_data_sanitize tag
+ defaultctry="$tag"
if [ $retval -ne 0 ]; then
NEED_CONTINENT=1
@@ -409,25 +405,27 @@ while :; do
f_dialog_title_restore
prompt="$msg_select_zone"
menu_list=$( f_country $tlc menu_list )
- size=$( eval f_dialog_menu_size \"\$title\" \"\$btitle\" \
- \"\$prompt\" \"\" $menu_list )
+ eval f_dialog_menu_size height width rows \
+ \"\$title\" \"\$btitle\" \"\$prompt\" \"\" $menu_list
#
# Launch the zone selection menu
# NOTE: This is as deep as we go
#
- dialog_menu=$( eval $DIALOG \
- --title \"\$title\" \
- --backtitle \"\$btitle\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --menu \"\$prompt\" $size \
- $menu_list \
+ n=$( eval $DIALOG \
+ --title \"\$title\" \
+ --backtitle \"\$btitle\" \
+ --ok-label \"\$msg_ok\" \
+ --cancel-label \"\$msg_cancel\" \
+ --default-item \"\$defaultzone\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- n=$( f_dialog_menutag )
+ f_dialog_data_sanitize n
+ defaultzone="$n"
if [ $retval -ne 0 ]; then
[ $nitems -eq 1 ] && NEED_CONTINENT=1
diff --git a/usr.sbin/bsdconfig/ttys/INDEX b/usr.sbin/bsdconfig/ttys/INDEX
index 4ecc68e..83ca021 100644
--- a/usr.sbin/bsdconfig/ttys/INDEX
+++ b/usr.sbin/bsdconfig/ttys/INDEX
@@ -26,28 +26,32 @@
# $FreeBSD$
#
-# Title that will be shown on the bsdconfig menu
+# Title that will be shown in the bsdconfig menu.
+#
menu_title="Ttys"
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
#
-# a short descriptive line shown at the bottom of the bsdconfig menu.
-# keep it short because any line longer than the terminal width will
-# be truncated.
menu_help="Configure Ttys"
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
#
-# two-part variable that defines an action to take when 'keyword'
-# is passed on a bsdconfig command line. variable takes the form
-# "keyword|command" and multiple occurrences of the variable
-# (with different 'keyword's, or different 'keyword's AND 'command's)
-# are allowed. If 'command' begins with a '/' then the full
-# path to the program is needed. If 'command' begins with anything
-# else it is a path relative to the directory this INDEX file is in.
-# 'keyword' can be i18n'ed but 'command' is the name of a script.
menu_selection="ttys|ttys"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
#
-# Items below this line do NOT need i18n translation----------------------
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
#
-# Name of the program to be run when this menu choice is selected.
-# if it begins with a '/' then the full path to the program is needed.
-# if it begins with anything else it is a path relative to the directory
-# this INDEX file is in.
menu_program="ttys"
diff --git a/usr.sbin/bsdconfig/ttys/USAGE b/usr.sbin/bsdconfig/ttys/USAGE
index 9aa4dca..a06d8af 100644
--- a/usr.sbin/bsdconfig/ttys/USAGE
+++ b/usr.sbin/bsdconfig/ttys/USAGE
@@ -1,5 +1,5 @@
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -11,11 +11,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -27,7 +27,11 @@
Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS]
OPTIONS:
- -h Print usage statement and exit.
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
+ -h Print this usage statement and exit.
-S Secure X11 mode (implies `-X'). As root, always prompt-for
and validate sudo(8) username/password before starting.
-X Use Xdialog(1) in place of dialog(1).
diff --git a/usr.sbin/bsdconfig/ttys/ttys b/usr.sbin/bsdconfig/ttys/ttys
index db7cb20..999ce76 100755
--- a/usr.sbin/bsdconfig/ttys/ttys
+++ b/usr.sbin/bsdconfig/ttys/ttys
@@ -1,7 +1,7 @@
#!/bin/sh
#-
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -13,11 +13,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -67,9 +67,9 @@ ETC_TTYS=/etc/ttys
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
diff --git a/usr.sbin/bsdconfig/usermgmt/INDEX b/usr.sbin/bsdconfig/usermgmt/INDEX
index 81e43aa..6fc61ea 100644
--- a/usr.sbin/bsdconfig/usermgmt/INDEX
+++ b/usr.sbin/bsdconfig/usermgmt/INDEX
@@ -26,22 +26,25 @@
# $FreeBSD$
#
-# Title that will be shown on the bsdconfig menu
+# Title that will be shown in the bsdconfig menu.
+#
menu_title="Login/Group Management"
+
+#
+# A short descriptive line shown at the bottom of the bsdconfig menu. keep it
+# short because any line longer than the terminal width will be truncated.
#
-# a short descriptive line shown at the bottom of the bsdconfig menu.
-# keep it short because any line longer than the terminal width will
-# be truncated.
menu_help="Manage system user and/or group information"
+
+#
+# Two-part variable that defines an action to take when `keyword' is passed on
+# a bsdconfig command line. Variable takes the form "keyword|command" and
+# multiple occurrences of the variable (with different `keyword's, or different
+# `keyword's AND `command's) are allowed. If `command' begins with a '/' then
+# the full path to the program is needed. If `command' begins with anything
+# else it is a path relative to the directory this INDEX file is in. `keyword'
+# can be i18n'ed but `command' is the name of a script.
#
-# two-part variable that defines an action to take when 'keyword'
-# is passed on a bsdconfig command line. variable takes the form
-# "keyword|command" and multiple occurrences of the variable
-# (with different 'keyword's, or different 'keyword's AND 'command's)
-# are allowed. If 'command' begins with a '/' then the full
-# path to the program is needed. If 'command' begins with anything
-# else it is a path relative to the directory this INDEX file is in.
-# 'keyword' can be i18n'ed but 'command' is the name of a script.
menu_selection="usermgmt|usermgmt"
menu_selection="useradd|useradd"
menu_selection="useredit|useredit"
@@ -50,11 +53,12 @@ menu_selection="groupmgmt|usermgmt"
menu_selection="groupadd|groupadd"
menu_selection="groupedit|groupedit"
menu_selection="groupdel|groupdel"
+
+#
+# ------------ Items below this line do NOT need i18n translation ------------
#
-# Items below this line do NOT need i18n translation----------------------
+# Name of the program to be run when this menu choice is selected. If it begins
+# with a '/' then the full path to the program is needed. If it begins with
+# anything else it is a path relative to the directory this INDEX file is in.
#
-# Name of the program to be run when this menu choice is selected.
-# if it begins with a '/' then the full path to the program is needed.
-# if it begins with anything else it is a path relative to the directory
-# this INDEX file is in.
menu_program="usermgmt"
diff --git a/usr.sbin/bsdconfig/usermgmt/USAGE b/usr.sbin/bsdconfig/usermgmt/USAGE
index 9aa4dca..a06d8af 100644
--- a/usr.sbin/bsdconfig/usermgmt/USAGE
+++ b/usr.sbin/bsdconfig/usermgmt/USAGE
@@ -1,5 +1,5 @@
-# Copyright (c) 2012 Devin Teske
-# All Rights Reserved.
+# Copyright (c) 2012-2013 Devin Teske
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -11,11 +11,11 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# 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
@@ -27,7 +27,11 @@
Usage: bsdconfig @PROGRAM_NAME@ [OPTIONS]
OPTIONS:
- -h Print usage statement and exit.
+ -d Provide lots of debugging info on standard-out when running.
+ -D file Send debugging info to file. If file begins with a plus-sign
+ debug info is sent to both standard-out and file (minus the
+ leading plus).
+ -h Print this usage statement and exit.
-S Secure X11 mode (implies `-X'). As root, always prompt-for
and validate sudo(8) username/password before starting.
-X Use Xdialog(1) in place of dialog(1).
diff --git a/usr.sbin/bsdconfig/usermgmt/groupadd b/usr.sbin/bsdconfig/usermgmt/groupadd
index 34962a9..6f806a6 100755
--- a/usr.sbin/bsdconfig/usermgmt/groupadd
+++ b/usr.sbin/bsdconfig/usermgmt/groupadd
@@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -47,9 +47,9 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
diff --git a/usr.sbin/bsdconfig/usermgmt/groupdel b/usr.sbin/bsdconfig/usermgmt/groupdel
index b51f002..3076216 100755
--- a/usr.sbin/bsdconfig/usermgmt/groupdel
+++ b/usr.sbin/bsdconfig/usermgmt/groupdel
@@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -50,9 +50,9 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -67,23 +67,22 @@ f_mustberoot_init
#
# Loop until the user Exits, Cancels or presses ESC
#
+defaultitem=""
while :; do
- f_dialog_menu_group_list
+ f_dialog_menu_group_list "$defaultitem"
retval=$?
- mtag=$( f_dialog_menutag )
+ f_dialog_menutag_fetch mtag
f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
+ defaultitem="$mtag"
[ $retval -eq 0 ] || f_die
- case "$mtag" in
- "X $msg_exit") break ;;
+ [ "$mtag" = "X $msg_exit" ] && break
- *) # anything else is a group name
- $BSDCFG_LIBE/$APP_DIR/groupinput \
- ${USE_XDIALOG:+-X} mode="Delete" group="$mtag"
- ;;
+ # Anything else is a group name
- esac
+ $BSDCFG_LIBE/$APP_DIR/groupinput \
+ ${USE_XDIALOG:+-X} mode="Delete" group="$mtag"
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/usermgmt/groupedit b/usr.sbin/bsdconfig/usermgmt/groupedit
index c192c0f..1f1c744 100755
--- a/usr.sbin/bsdconfig/usermgmt/groupedit
+++ b/usr.sbin/bsdconfig/usermgmt/groupedit
@@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -50,9 +50,9 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -67,23 +67,22 @@ f_mustberoot_init
#
# Loop until the user Exits, Cancels or presses ESC
#
+defaultitem=""
while :; do
- f_dialog_menu_group_list
+ f_dialog_menu_group_list "$defaultitem"
retval=$?
- mtag=$( f_dialog_menutag )
+ f_dialog_menutag_fetch mtag
f_dprintf "retval=%s mtag=[%s]" $retval "$mtag"
+ defaultitem="$mtag"
[ $retval -eq 0 ] || f_die
- case "$mtag" in
- "X $msg_exit") break ;;
+ [ "$mtag" = "X $msg_exit" ] && break
- *) # anything else is a group name
- $BSDCFG_LIBE/$APP_DIR/groupinput \
- ${USE_XDIALOG:+-X} mode="Edit/View" group="$mtag"
- ;;
+ # Anything else is a group name
- esac
+ $BSDCFG_LIBE/$APP_DIR/groupinput \
+ ${USE_XDIALOG:+-X} mode="Edit/View" group="$mtag"
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/usermgmt/groupinput b/usr.sbin/bsdconfig/usermgmt/groupinput
index c459224..6fff40f 100755
--- a/usr.sbin/bsdconfig/usermgmt/groupinput
+++ b/usr.sbin/bsdconfig/usermgmt/groupinput
@@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -66,7 +66,7 @@ save_changes()
f_dialog_msgbox "$msg_error $err\n"
return $retval
fi
- f_dialog_msgbox "$msg_group_deleted"
+ f_show_msg "$msg_group_deleted"
;;
Add)
local cmd="pw groupadd -n '$group_name'"
@@ -85,7 +85,7 @@ save_changes()
f_dialog_msgbox "$msg_error $err\n"
return $retval
fi
- f_dialog_msgbox "$msg_group_added"
+ f_show_msg "$msg_group_added"
;;
Edit/View)
local cmd="pw groupmod -n '$group_name'"
@@ -104,7 +104,7 @@ save_changes()
f_dialog_msgbox "$msg_error $err\n"
return $retval
fi
- f_dialog_msgbox "$msg_group_updated"
+ f_show_msg "$msg_group_updated"
;;
esac
@@ -139,8 +139,8 @@ while [ $# -gt 0 ]; do
value="${1#*=}"
f_dprintf "key=[%s] value=[%s]" "$key" "$value"
case "$key" in
- mode) mode="$value";;
- group) group="$value";;
+ mode) mode="$value" ;;
+ group) group="$value" ;;
esac
shift
done
@@ -157,19 +157,27 @@ save_flag=
hline="$hline_arrows_tab_enter"
if [ "$mode" = "Add" ]; then
- #
- # Ask a series of questions to pre-fill the editor screen.
- #
- # The defaults used in each dialog should allow the user to simply
- # hit ENTER to proceed, because cancelling a single dialog will
- # cause them to be returned to the main groupmenu.
- #
-
f_dialog_input_group_name || exit 0
- [ "$passwdtype" = "yes" ] &&
- { f_dialog_input_group_password || exit 0; }
- f_dialog_input_group_gid || exit 0
- f_dialog_input_group_members || exit 0
+
+ f_dialog_noyes "$msg_use_default_values_for_all_account_details"
+ retval=$?
+
+ if [ $retval -eq 255 ]; then # User pressed ESC
+ exit $SUCCESS
+ elif [ $retval -ne $SUCCESS ]; then
+ #
+ # Ask a series of questions to pre-fill the editor screen.
+ #
+ # The defaults used in each dialog should allow the user to
+ # simply hit ENTER to proceed, because cancelling a single
+ # dialog will cause them to be returned to the main groupmenu.
+ #
+
+ [ "$passwdtype" = "yes" ] &&
+ { f_dialog_input_group_password || exit 0; }
+ f_dialog_input_group_gid || exit 0
+ f_dialog_input_group_members || exit 0
+ fi
fi
if [ "$mode" = "Edit/View" -o "$mode" = "Delete" ]; then
@@ -221,27 +229,29 @@ while :; do
" # END-QUOTE
esac
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$menu_text\" \
- \"\$hline\" \
- $menu_items )
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$menu_text\" \
+ \"\$hline\" \
+ $menu_items
- dialog_menu=$( eval $DIALOG \
+ f_dialog_default_fetch defaultitem
+ mtag=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$menu_text\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$menu_text\" \
+ $height $width $rows \
$menu_items \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
-
retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- mtag=$( f_dialog_menutag )
+ f_dialog_data_sanitize mtag
+ f_dialog_default_store "$mtag"
f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
# Exit if user has either pressed ESC or chosen Cancel/No
@@ -258,9 +268,9 @@ while :; do
case "$mode" in
Add) f_dialog_input_group_name "$group_name" ;;
Edit/View|Delete)
- f_dialog_menu_group_list
+ f_dialog_menu_group_list "$group_name"
retval=$?
- mtag=$( f_dialog_menutag )
+ f_dialog_menutag_fetch mtag
f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
# Loop if user has either pressed ESC or chosen Cancel/No
diff --git a/usr.sbin/bsdconfig/usermgmt/include/messages.subr b/usr.sbin/bsdconfig/usermgmt/include/messages.subr
index e2e7bf3..71cc51d 100644
--- a/usr.sbin/bsdconfig/usermgmt/include/messages.subr
+++ b/usr.sbin/bsdconfig/usermgmt/include/messages.subr
@@ -1,5 +1,5 @@
# Copyright (c) 2012 Ron McDowell
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -26,6 +26,7 @@
# $FreeBSD$
hline_alnum_punc_tab_enter="Use alpha-numeric, punctuation, TAB or ENTER"
+hline_alnum_space_tab_enter="Use alpha-numeric, SPACE, TAB or ENTER"
hline_alnum_tab_enter="Use alpha-numeric, TAB or ENTER"
hline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER"
hline_arrows_tab_enter="Press arrows, TAB or ENTER"
@@ -104,6 +105,8 @@ msg_separated_by_commas="Separated by commas"
msg_select_group_members_from_list="Select Group Members from a list"
msg_select_login_shell="Select Login Shell"
msg_shell="Shell"
+msg_unknown_user_management_menu_selection="Unknown user management menu selection"
+msg_use_default_values_for_all_account_details="Use default values for all account details?"
msg_user="User"
msg_user_id="UID"
msg_user_id_leave_empty_for_default="UID (Leave empty for default)"
diff --git a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr
index 278e0a4..93d981a 100644
--- a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr
+++ b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr
@@ -1,7 +1,7 @@
if [ ! "$_USERMGMT_GROUP_INPUT_SUBR" ]; then _USERMGMT_GROUP_INPUT_SUBR=1
#
# Copyright (c) 2012 Ron McDowell
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -58,18 +58,19 @@ f_input_group()
}' )
}
-# f_dialog_menu_group_list
+# f_dialog_menu_group_list [$default]
#
-# Allows the user to select a group from a list.
+# Allows the user to select a group from a list. Optionally, if present and
+# non-NULL, initially highlight $default group.
#
f_dialog_menu_group_list()
{
- local menu_list size
- local hline="$hline_alnum_punc_tab_enter"
-
- menu_list="
+ local prompt=
+ local menu_list="
'X $msg_exit' ''
" # END-QUOTE
+ local defaultitem="$1"
+ local hline="$hline_alnum_punc_tab_enter"
# Add groups from group(5)
menu_list="$menu_list $( pw groupshow -a | awk -F: '
@@ -78,25 +79,29 @@ f_dialog_menu_group_list()
}'
)"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\" $size $menu_list \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -119,9 +124,8 @@ f_dialog_input_group_name()
while :; do
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_group" "$_input" \
- "$hline_alnum_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_group" "$_input" \
+ "$hline_alnum_tab_enter" || return
# Check for no-change
[ "$_input" = "$_name" ] && return $SUCCESS
@@ -134,13 +138,13 @@ f_dialog_input_group_name()
# Check for NULL entry
if [ ! "$_input" ]; then
- f_dialog_msgbox "$msg_group_is_empty"
+ f_show_msg "$msg_group_is_empty"
continue
fi
# Check for invalid entry
if ! echo "$_input" | grep -q "^[[:alpha:]]"; then
- f_dialog_msgbox "$msg_group_must_start_with_letter"
+ f_show_msg "$msg_group_must_start_with_letter"
continue
fi
@@ -166,79 +170,82 @@ f_dialog_input_group_name()
#
f_dialog_input_group_password()
{
+ local prompt1="$msg_group_password"
+ local prompt2="$msg_reenter_group_password"
local hline="$hline_alnum_punc_tab_enter"
- local msg size rmsg rsize
- msg=$( printf "$msg_group_password" )
- size=$( f_dialog_inputbox_size \
+ local height1 width1
+ f_dialog_inputbox_size height1 width1 \
"$DIALOG_TITLE" \
"$DIALOG_BACKTITLE" \
- "$msg" \
+ "$prompt1" \
"" \
- "$hline" )
+ "$hline"
- rmsg=$( printf "$msg_reenter_group_password" )
- rsize=$( f_dialog_inputbox_size \
+ local height2 width2
+ f_dialog_inputbox_size height2 width2 \
"$DIALOG_TITLE" \
"$DIALOG_BACKTITLE" \
- "$rmsg" \
+ "$prompt2" \
"" \
- "$hline" )
+ "$hline"
#
# Loop until the user provides taint-free/valid input
#
local retval _password1 _password2
while :; do
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --insecure \
- --passwordbox \"\$msg\" $size \
+ _password1=$( $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$hline" \
+ --ok-label "$msg_ok" \
+ --cancel-label "$msg_cancel" \
+ --insecure \
+ --passwordbox "$prompt1" \
+ $height1 $width1 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
-
retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _password1=$( f_dialog_inputstr )
+ debug= f_dialog_line_sanitize _password1
# Return if user has either pressed ESC or chosen Cancel/No
[ $retval -eq $SUCCESS ] || return $retval
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --insecure \
- --passwordbox \"\$rmsg\" $rsize \
+ _password2=$( $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$hline" \
+ --ok-label "$msg_ok" \
+ --cancel-label "$msg_cancel" \
+ --insecure \
+ --passwordbox "$prompt2" \
+ $height2 $width2 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
-
retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _password2=$( f_dialog_inputstr )
+ debug= f_dialog_line_sanitize _password2
# Return if user has either pressed ESC or chosen Cancel/No
[ $retval -eq $SUCCESS ] || return $retval
# Check for password mismatch
if [ "$_password1" != "$_password2" ]; then
- f_dialog_msgbox "$msg_group_passwords_do_not_match"
+ f_show_msg "$msg_group_passwords_do_not_match"
continue
fi
# Check for NULL entry
if [ ! "$_password1" ]; then
- f_dialog_yesno \
- "$msg_disable_password_auth_for_group" ||
- continue
- pw_group_password_disable=1
+ f_dialog_yesno "$msg_disable_password_auth_for_group"
+ local retval=$?
+ if [ $retval -eq 255 ]; then # ESC was pressed
+ return $retval
+ elif [ $retval -eq $SUCCESS ]; then
+ pw_group_password_disable=1
+ else
+ continue # back to password prompt
+ fi
else
pw_group_password_disable=
fi
@@ -265,9 +272,8 @@ f_dialog_input_group_gid()
local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_group_id_leave_empty_for_default" \
- "$_input" "$hline_num_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_group_id_leave_empty_for_default" \
+ "$_input" "$hline_num_tab_enter" || return
group_gid="$_input"
save_flag=1
@@ -279,106 +285,109 @@ f_dialog_input_group_gid()
# f_dialog_input_group_members [$group_members]
#
-# Allow the user to modify a list of members for a given group. If the user does
-# not cancel or press ESC, the $group_members variable will hold the newly-
-# configured value upon return.
+# Allow the user to modify a list of members for a given group. If the user
+# does not cancel or press ESC, the $group_members variable will hold the
+# newly-configured value upon return.
#
f_dialog_input_group_members()
{
- local menu_choice msg size retval _input="$1"
- local hline="$hline_num_arrows_tab_enter"
- local user
- local menu_list
- local all_users_valid
- local _group_members
- local checklist_users
-
- menu_list="
+ local _input="$1"
+ local prompt="$msg_group_members:"
+ local menu_list="
'X' '$msg_continue'
'1' '$msg_select_group_members_from_list'
'2' '$msg_enter_group_members_manually'
" # END-QUOTE
+ local defaultitem=
+ local hline="$hline_num_arrows_tab_enter"
- local dialog_menu
+ local mheight mwidth mrows
+ eval f_dialog_menu_size mheight mwidth mrows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ local menu_choice retval
while :; do
- msg="$msg_group_members:"
- menu_size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$msg\" \
- \"\$hline\" \
- $menu_list )
- dialog_menu=$( eval $DIALOG \
+ menu_choice=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$msg\" $menu_size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $mheight $mwidth $mrows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- menu_choice=$( f_dialog_menutag )
+ f_dialog_data_sanitize menu_choice
+ defaultitem="$menu_choice"
f_dprintf "retval=%u menu_choice=[%s]" $retval "$menu_choice"
# Return if user has either pressed ESC or chosen Cancel/No
[ $retval -eq $SUCCESS ] || return $retval
+ local _group_members
case "$menu_choice" in
X) # Exit
break ;;
1) # Select Group Members from a list
- user_list=$( pw usershow -a | awk -F: '
- !/^[[:space:]]*(#|$)/ { printf "%s\n", $1 }' )
- checklist_users=
- for user in $user_list; do
- checklist_users="$checklist_users $user \"\""
+ local user check_list=
+ for user in $( pw usershow -a |
+ awk -F: '!/^[[:space:]]*(#|$)/{print $1}'
+ ); do
+ # Format of a checklist entry: tag item status
if echo "$_input" | grep -q "\<$user\>"; then
- checklist_users="$checklist_users on"
+ check_list="$check_list $user '' on"
else
- checklist_users="$checklist_users off"
+ check_list="$check_list $user '' off"
fi
done
- size=$( eval f_dialog_radiolist_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\" \
- \"\$hline\" \
- $checklist_users )
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
+ local cheight cwidth crows
+ eval f_dialog_checklist_size cheight cwidth crows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $check_list
+ _group_members=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--separate-output \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --checklist \"\$msg\" $size \
- $checklist_users \
+ --checklist \"\$prompt\" \
+ $cheight $cwidth $crows \
+ $check_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+ ) || continue
+ # Return to previous menu if user either
+ # pressed ESC or chose Cancel/No
+ f_dialog_data_sanitize _group_members
+
+ # Convert the newline separated list into a comma-
+ # separated one so that if the user switches over to
+ # manual editing, list reflects checklist selections
+ _group_members=$( echo "$_group_members" |
+ tr '\n' ' ' |
+ sed -e 's/[[:space:]]\{1,\}/,/g;s/^,//;s/,$//'
)
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _group_members=$( f_dialog_inputstr | tr '\n' ' ' |
- sed -e 's/[[:space:]]\{1,\}/,/g;s/^,//;s/,$//' )
-
- # Return to previous menu if user has either
- # pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || continue
_input="$_group_members"
;;
2) # Enter Group Members manually
- msg="$msg_group_members ($msg_separated_by_commas)"
+ local p="$msg_group_members ($msg_separated_by_commas)"
- # Return to previous menu if user has either
- # pressed ESC or chosen Cancel/No
- _group_members=$( f_dialog_input "$msg" "$_input" \
- "$hline_num_tab_enter"
- ) || continue
+ f_dialog_input _group_members "$p" "$_input" \
+ "$hline_num_tab_enter" || continue
+ # Return to previous menu if user either
+ # pressed ESC or chose Cancel/No
_input="$_group_members"
;;
diff --git a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
index e0281ed..21bfbd3 100644
--- a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
+++ b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
@@ -1,7 +1,7 @@
if [ ! "$_USERMGMT_USER_INPUT_SUBR" ]; then _USERMGMT_USER_INPUT_SUBR=1
#
# Copyright (c) 2012 Ron McDowell
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -83,18 +83,19 @@ f_input_user()
pw_member_groups=$( f_get_member_groups "$user" )
}
-# f_dialog_menu_user_list
+# f_dialog_menu_user_list [$default]
#
-# Allows the user to select a login from a list.
+# Allows the user to select a login from a list. Optionally, if present and
+# non-NULL, initially highlight $default user.
#
f_dialog_menu_user_list()
{
- local menu_list size
- local hline="$hline_alnum_punc_tab_enter"
-
- menu_list="
+ local prompt=
+ local menu_list="
'X $msg_exit' ''
" # END-QUOTE
+ local defaultitem="$1"
+ local hline="$hline_alnum_punc_tab_enter"
# Add users from passwd(5)
menu_list="$menu_list $( pw usershow -a | awk -F: '
@@ -103,25 +104,29 @@ f_dialog_menu_user_list()
}'
)"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\" \
- \"\$hline\" \
- $menu_list )
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\" $size $menu_list \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_menutag_store -s "$menu_choice"
return $retval
}
@@ -133,58 +138,57 @@ f_dialog_menu_user_list()
#
f_dialog_input_member_groups()
{
- local msg="$( printf "$msg_member_of_groups" )"
- local hline="$hline_alnum_tab_enter"
+ local _member_groups="$1"
+ local prompt="$msg_member_of_groups"
+ local check_list= # Calculated below
+ local hline="$hline_alnum_space_tab_enter"
+ local group
#
- # Loop until the user provides taint-free/valid input
+ # Generate the checklist menu
#
- local size retval all_groups checklist_groups="" _member_groups="$1"
- all_groups=$( pw groupshow -a | awk -F: '
- !/^[[:space:]]*(#|$)/ {
- printf "%s\n", $1
- }'
- )
- for grp in $all_groups; do
- checklist_groups="$checklist_groups $grp $grp"
- if echo "$_member_groups" | grep -q "\<$grp\>"; then
- checklist_groups="$checklist_groups on"
+ for group in $(
+ pw groupshow -a | awk -F: '!/^[[:space:]]*(#|$)/{print $1}'
+ ); do
+ # Format of a checklist menu entry is "tag item status"
+ # (setting both tag and item to the group name below).
+ if echo "$_member_groups" | grep -q "\<$group\>"; then
+ check_list="$check_list $group $group on"
else
- checklist_groups="$checklist_groups off"
+ check_list="$check_list $group $group off"
fi
done
+ #
+ # Loop until the user provides taint-free/valid input
+ #
+ local height width rows
while :; do
- size=$( eval f_dialog_radiolist_size \
+ eval f_dialog_checklist_size height width rows \
\"\$DIALOG_TITLE\" \
\"\$DIALOG_BACKTITLE\" \
- \"\" \
+ \"\$prompt\" \
\"\$hline\" \
- $checklist_groups )
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
+ $check_list
+ _member_groups=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--separate-output \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --checklist \"\$msg\" $size \
- $checklist_groups \
+ --checklist \"\$prompt\" \
+ $height $width $rows \
+ $check_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _member_groups=$( f_dialog_inputstr )
-
- # Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ ) || return $?
+ # Return if user either pressed ESC or chose Cancel/No
+ f_dialog_data_sanitize _member_groups
#
# Validate each of the groups the user has entered
#
- local group all_groups_valid=1
+ local all_groups_valid=1
for group in $_member_groups; do
if ! f_quietly pw groupshow -n "$group"; then
f_show_msg "$msg_group_not_found" "$group"
@@ -224,9 +228,8 @@ f_dialog_input_name()
while :; do
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_login" "$_input" \
- "$hline_alnum_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_login" "$_input" \
+ "$hline_alnum_tab_enter" || return
# Check for no-change
[ "$_input" = "$_name" ] && return $SUCCESS
@@ -239,13 +242,13 @@ f_dialog_input_name()
# Check for NULL entry
if [ ! "$_input" ]; then
- f_dialog_msgbox "$msg_login_is_empty"
+ f_show_msg "$msg_login_is_empty"
continue
fi
# Check for invalid entry
if ! echo "$_input" | grep -q "^[[:alpha:]]"; then
- f_dialog_msgbox "$msg_login_must_start_with_letter"
+ f_show_msg "$msg_login_must_start_with_letter"
continue
fi
@@ -271,79 +274,75 @@ f_dialog_input_name()
#
f_dialog_input_password()
{
+ local prompt1="$msg_password"
+ local prompt2="$msg_reenter_password"
local hline="$hline_alnum_punc_tab_enter"
- local msg size rmsg rsize
-
- msg=$( printf "$msg_password" )
- size=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "" \
- "$hline" )
-
- rmsg=$( printf "$msg_reenter_password" )
- rsize=$( f_dialog_inputbox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$rmsg" \
- "" \
- "$hline" )
+
+ local height1 width1
+ f_dialog_inputbox_size height1 width1 \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$prompt1" \
+ "" \
+ "$hline"
+ local height2 width2
+ f_dialog_inputbox_size height2 width2 \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$prompt2" \
+ "" \
+ "$hline"
#
# Loop until the user provides taint-free/valid input
#
- local retval _password1 _password2
+ local _password1 _password2
while :; do
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --insecure \
- --passwordbox \"\$msg\" $size \
+ _password1=$( $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$hline" \
+ --ok-label "$msg_ok" \
+ --cancel-label "$msg_cancel" \
+ --insecure \
+ --passwordbox "$prompt1" \
+ $height1 $width1 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _password1=$( f_dialog_inputstr )
-
- # Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
-
- dialog_inputbox=$( eval $DIALOG \
- --title \"\$DIALOG_TITLE\" \
- --backtitle \"\$DIALOG_BACKTITLE\" \
- --hline \"\$hline\" \
- --ok-label \"\$msg_ok\" \
- --cancel-label \"\$msg_cancel\" \
- --insecure \
- --passwordbox \"\$rmsg\" $rsize \
+ ) || return $?
+ # Return if user either pressed ESC or chose Cancel/No
+ debug= f_dialog_line_sanitize _password1
+
+ _password2=$( $DIALOG \
+ --title "$DIALOG_TITLE" \
+ --backtitle "$DIALOG_BACKTITLE" \
+ --hline "$hline" \
+ --ok-label "$msg_ok" \
+ --cancel-label "$msg_cancel" \
+ --insecure \
+ --passwordbox "$prompt2" \
+ $height2 $width2 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _password2=$( f_dialog_inputstr )
-
- # Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ ) || return $?
+ # Return if user either pressed ESC or chose Cancel/No
+ debug= f_dialog_line_sanitize _password2
# Check for password mismatch
if [ "$_password1" != "$_password2" ]; then
- f_dialog_msgbox "$msg_passwords_do_not_match"
+ f_show_msg "$msg_passwords_do_not_match"
continue
fi
# Check for NULL entry
if [ ! "$_password1" ]; then
- f_dialog_yesno \
- "$msg_disable_password_auth_for_account" ||
- continue
- pw_password_disable=1
+ f_dialog_yesno "$msg_disable_password_auth_for_account"
+ local retval=$?
+ if [ $retval -eq 255 ]; then # ESC was pressed
+ return $retval
+ elif [ $retval -eq $SUCCESS ]; then
+ pw_password_disable=1
+ else
+ continue # back to password prompt
+ fi
else
pw_password_disable=
fi
@@ -370,9 +369,8 @@ f_dialog_input_gecos()
local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_full_name" "$_input" \
- "$hline_alnum_punc_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_full_name" "$_input" \
+ "$hline_alnum_punc_tab_enter" || return
pw_gecos="$_input"
save_flag=1
@@ -393,9 +391,8 @@ f_dialog_input_uid()
local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_user_id_leave_empty_for_default" \
- "$_input" "$hline_num_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_user_id_leave_empty_for_default" \
+ "$_input" "$hline_num_tab_enter" || return
pw_uid="$_input"
save_flag=1
@@ -416,9 +413,8 @@ f_dialog_input_gid()
local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_group_id_leave_empty_for_default" \
- "$_input" "$hline_num_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_group_id_leave_empty_for_default" \
+ "$_input" "$hline_num_tab_enter" || return
pw_gid="$_input"
save_flag=1
@@ -439,9 +435,8 @@ f_dialog_input_class()
local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_login_class" "$_input" \
- "$hline_alnum_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_login_class" "$_input" \
+ "$hline_alnum_tab_enter" || return
pw_class="$_input"
save_flag=1
@@ -451,53 +446,66 @@ f_dialog_input_class()
return $SUCCESS
}
-# f_dialog_input_change [$seconds]
+# f_dialog_input_expire_password [$seconds]
#
# Allow the user to enter a date/time (in number-of-seconds since the `epoch')
# for when a given user's password must be changed. If the user does not cancel
# or press ESC, the $pw_password_expire variable will hold the newly-
# configured value upon return.
#
-f_dialog_input_change()
+f_dialog_input_expire_password()
{
- local calendar_size timebox_size
- local msg menu_size size retval _input="$1"
- local hline="$hline_num_arrows_tab_enter"
-
+ local prompt="$msg_password_expires_on"
local menu_list="
'1' '$msg_password_does_not_expire'
'2' '$msg_edit_date_time_with_a_calendar'
'3' '$msg_enter_number_of_days_into_the_future'
'4' '$msg_enter_value_manually'
" # END-QUOTE
+ local hline="$hline_num_arrows_tab_enter"
+ local retval _input="$1"
+
+ local mheight mwidth mrows
+ eval f_dialog_menu_size mheight mwidth mrows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+ local cheight cwidth
+ f_dialog_calendar_size cheight cwidth \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$prompt" \
+ "$hline"
+ local theight twidth
+ f_dialog_timebox_size theight twidth \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$prompt" \
+ "$hline"
#
# Loop until the user provides taint-free/cancellation-free input
#
+ local date_type defaultitem=
while :; do
- msg="$msg_password_expires_on"
- menu_size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$msg\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
+ date_type=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
+ --default-item \"\$defaultitem\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$msg\" $menu_size \
+ --menu \"\$prompt\" \
+ $mheight $mwidth $mrows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
- retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- date_type=$( f_dialog_menutag )
- f_dprintf "retval=%u date_type=[%s]" $retval "$date_type"
+ retval=$?
+ f_dialog_data_sanitize date_type
+ defaultitem="$date_type"
+ f_dprintf "retval=%u date_type=[%s]" $retval "$date_type"
# Return if user has either pressed ESC or chosen Cancel/No
[ $retval -eq $SUCCESS ] || return $retval
@@ -514,25 +522,19 @@ f_dialog_input_change()
{ f_isinteger "$secs" && [ $secs -gt 0 ]; } || secs=
_input_date=$( date -j -f "%s" -- "$secs" \
"+%d %m %Y" 2> /dev/null )
- calendar_size=$( f_dialog_calendar_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$hline" )
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
+ ret_date=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --calendar \"\$msg\" $calendar_size \
+ --calendar \"\$prompt\" \
+ $cheight $cwidth \
$_input_date \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- ret_date=$( f_dialog_inputstr )
+ f_dialog_data_sanitize ret_date
f_dprintf "retval=%u ret_date=[%s]" $retval "$ret_date"
# Return to menu if either ESC or Cancel/No
@@ -541,25 +543,19 @@ f_dialog_input_change()
_input_time=
[ "$secs" ] && _input_time=$( date -j \
-f %s -- "$_input" "+%H %M %S" 2> /dev/null )
- timebox_size=$( f_dialog_timebox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$hline" )
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
+ ret_time=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --timebox \"\$msg\" $timebox_size \
+ --timebox \"\$prompt\" \
+ $theight $twidth \
$_input_time \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- ret_time=$( f_dialog_inputstr )
+ f_dialog_data_sanitize ret_time
f_dprintf "retval=%u ret_time=[%s]" $retval "$ret_time"
# Return to menu if either ESC or Cancel/No
@@ -582,42 +578,39 @@ f_dialog_input_change()
ret_days=$(( $ret_days + 1 ))
# Return to menu if either ESC or Cancel/No
- ret_days=$( f_dialog_input \
+ f_dialog_input ret_days \
"$msg_password_expires_in_how_many_days" \
- "$ret_days" "$hline"
- ) || continue
+ "$ret_days" "$hline" || continue
# Taint-check the user's input
if ! f_isinteger "$ret_days"; then
- f_dialog_msgbox "$msg_invalid_number_of_days"
+ f_show_msg "$msg_invalid_number_of_days"
continue
fi
f_dprintf "ret_days=[%s]" "$ret_days"
case "$ret_days" in
- [-+]*) _input=$( date -v${ret_days}d +%s );;
- 0) _input=$( date +%s );;
- *) _input=$( date -v+${ret_days}d +%s );;
+ [-+]*) _input=$( date -v${ret_days}d +%s ) ;;
+ 0) _input=$( date +%s ) ;;
+ *) _input=$( date -v+${ret_days}d +%s ) ;;
esac
f_dprintf "_input=[%s]" "$_input"
break ;;
4) # Enter value manually
- local ret_secs
-
+ local msg ret_secs
msg=$( printf "$msg_number_of_seconds_since_epoch" \
"$( date -r 1 "+%c %Z" )" )
# Return to menu if either ESC or Cancel/No
- ret_secs=$( f_dialog_input \
- "$msg" "$_input" "$hline" ) || continue
+ f_dialog_input ret_secs \
+ "$msg" "$_input" "$hline" || continue
_input="$ret_secs"
# Taint-check the user's input
if ! f_isinteger "${_input:-0}"; then
- f_dialog_msgbox \
- "$msg_invalid_number_of_seconds"
+ f_show_msg "$msg_invalid_number_of_seconds"
continue
fi
@@ -637,53 +630,66 @@ f_dialog_input_change()
return $SUCCESS
}
-# f_dialog_input_expire [$seconds]
+# f_dialog_input_expire_account [$seconds]
#
# Allow the user to enter a date/time (in number-of-seconds since the `epoch')
# for when a given user's account should become expired. If the user does not
# cancel or press ESC, the $pw_account_expire variable will hold the newly-
# configured value upon return.
#
-f_dialog_input_expire()
+f_dialog_input_expire_account()
{
- local calendar_size timebox_size
- local msg menu_size size retval _input="$1"
- local hline="$hline_num_arrows_tab_enter"
-
+ local prompt="$msg_account_expires_on"
local menu_list="
'1' '$msg_account_does_not_expire'
'2' '$msg_edit_date_time_with_a_calendar'
'3' '$msg_enter_number_of_days_into_the_future'
'4' '$msg_enter_value_manually'
" # END-QUOTE
+ local hline="$hline_num_arrows_tab_enter"
+ local retval _input="$1"
+
+ local mheight mwidth mrows
+ eval f_dialog_menu_size mheight mwidth mrows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+ local cheight cwidth
+ f_dialog_calendar_size cheight cwidth \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$prompt" \
+ "$hline"
+ local theight twidth
+ f_dialog_timebox_size theight twidth \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$prompt" \
+ "$hline"
#
# Loop until the user provides taint-free/cancellation-free input
#
+ local date_type defaultitem=
while :; do
- msg="$msg_account_expires_on"
- menu_size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$msg\" \
- \"\$hline\" \
- $menu_list )
-
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
+ date_type=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
+ --default-item \"\$defaultitem\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$msg\" $menu_size \
+ --menu \"\$prompt\" \
+ $mheight $mwidth $mrows \
$menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
- retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- date_type=$( f_dialog_menutag )
- f_dprintf "retval=%u date_type=[%s]" $retval "$date_type"
+ retval=$?
+ f_dialog_data_sanitize date_type
+ defaultitem="$date_type"
+ f_dprintf "retval=%u date_type=[%s]" $retval "$date_type"
# Return if user has either pressed ESC or chosen Cancel/No
[ $retval -eq $SUCCESS ] || return $retval
@@ -700,25 +706,19 @@ f_dialog_input_expire()
{ f_isinteger "$secs" && [ $secs -gt 0 ]; } || secs=
_input_date=$( date -j -f "%s" -- "$secs" \
"+%d %m %Y" 2> /dev/null )
- calendar_size=$( f_dialog_calendar_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$hline" )
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
+ ret_date=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --calendar \"\$msg\" $calendar_size \
+ --calendar \"\$prompt\" \
+ $cheight $cwidth \
$_input_date \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- ret_date=$( f_dialog_inputstr )
+ f_dialog_data_sanitize ret_date
f_dprintf "retval=%u ret_date=[%s]" $retval "$ret_date"
# Return to menu if either ESC or Cancel/No
@@ -727,24 +727,19 @@ f_dialog_input_expire()
_input_time=
[ "$secs" ] && _input_time=$( date -j \
-f %s -- "$_input" "+%H %M %S" 2> /dev/null )
- timebox_size=$( f_dialog_timebox_size \
- "$DIALOG_TITLE" \
- "$DIALOG_BACKTITLE" \
- "$msg" \
- "$hline" )
- dialog_inputbox=$( eval $DIALOG \
+ ret_time=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --timebox \"\$msg\" $timebox_size \
+ --timebox \"\$prompt\" \
+ $theight $twidth \
$_input_time \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- ret_time=$( f_dialog_inputstr )
+ f_dialog_data_sanitize ret_time
f_dprintf "retval=%u ret_time=[%s]" $retval "$ret_time"
# Return to menu if either ESC or Cancel/No
@@ -767,42 +762,39 @@ f_dialog_input_expire()
ret_days=$(( $ret_days + 1 ))
# Return to menu if either ESC or Cancel/No
- ret_days=$( f_dialog_input \
+ f_dialog_input ret_days \
"$msg_account_expires_in_how_many_days" \
- "$ret_days" "$hline"
- ) || continue
+ "$ret_days" "$hline" || continue
# Taint-check the user's input
if ! f_isinteger "$ret_days"; then
- f_dialog_msgbox "$msg_invalid_number_of_days"
+ f_show_msg "$msg_invalid_number_of_days"
continue
fi
f_dprintf "ret_days=[%s]" "$ret_days"
case "$ret_days" in
- [-+]*) _input=$( date -v${ret_days}d +%s );;
- 0) _input=$( date +%s );;
- *) _input=$( date -v+${ret_days}d +%s );;
+ [-+]*) _input=$( date -v${ret_days}d +%s ) ;;
+ 0) _input=$( date +%s ) ;;
+ *) _input=$( date -v+${ret_days}d +%s ) ;;
esac
f_dprintf "_input=[%s]" "$_input"
break ;;
4) # Enter value manually
- local ret_secs
-
+ local msg ret_secs
msg=$( printf "$msg_number_of_seconds_since_epoch" \
"$( date -r 1 "+%c %Z" )" )
# Return to menu if either ESC or Cancel/No
- ret_secs=$( f_dialog_input \
- "$msg" "$_input" "$hline" ) || continue
+ f_dialog_input ret_secs "$msg" \
+ "$_input" "$hline" || continue
_input="$ret_secs"
# Taint-check the user's input
if ! f_isinteger "${_input:-0}"; then
- f_dialog_msgbox \
- "$msg_invalid_number_of_seconds"
+ f_show_msg "$msg_invalid_number_of_seconds"
continue
fi
@@ -833,9 +825,8 @@ f_dialog_input_home_dir()
local _input="$1"
# Return if user has either pressed ESC or chosen Cancel/No
- _input=$( f_dialog_input "$msg_home_directory" "$_input" \
- "$hline_alnum_punc_tab_enter"
- ) || return
+ f_dialog_input _input "$msg_home_directory" "$_input" \
+ "$hline_alnum_punc_tab_enter" || return
pw_home_dir="$_input"
save_flag=1
@@ -979,46 +970,45 @@ f_dialog_input_dotfiles_create()
#
f_dialog_input_shell()
{
- local size retval shells shell_list _input="$1"
- local hline="$hline_arrows_space_tab_enter"
+ local _input="$1"
local prompt="$msg_select_login_shell"
+ local radio_list= # Calculated below
+ local hline="$hline_arrows_space_tab_enter"
- shells=$( awk '!/^[[:space:]]*(#|$)/{print}' "$ETC_SHELLS" )
- shell_list=$(
- for shell in $shells; do
- if [ "$shell" = "$_input" ]; then
- echo "'$shell' '' 'on'"
- else
- echo "'$shell' '' 'off'"
- fi
- done
- )
+ #
+ # Generate the radiolist of shells
+ #
+ local shell
+ for shell in $( awk '!/^[[:space:]]*(#|$)/{print}' "$ETC_SHELLS" ); do
+ # Format of a radiolist menu entry is "tag item status"
+ if [ "$shell" = "$_input" ]; then
+ radio_list="$radio_list '$shell' '' 'on'"
+ else
+ radio_list="$radio_list '$shell' '' 'off'"
+ fi
+ done
- size=$( eval f_dialog_radiolist_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$prompt\" \
- \"\$hline\" \
- $shell_list )
+ local height width rows
+ eval f_dialog_radiolist_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $radio_list
- local dialog_inputbox
- dialog_inputbox=$( eval $DIALOG \
+ _input=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --radiolist \"\$prompt\" $size \
- $shell_list \
+ --radiolist \"\$prompt\" \
+ $height $width $rows \
+ $radio_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
- )
-
- retval=$?
- setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox"
- _input=$( f_dialog_inputstr )
-
- # Return if user has either pressed ESC or chosen Cancel/No
- [ $retval -eq $SUCCESS ] || return $retval
+ ) || return $?
+ # Return if user either pressed ESC or chose Cancel/No
+ f_dialog_data_sanitize _input
pw_shell="$_input"
save_flag=1
diff --git a/usr.sbin/bsdconfig/usermgmt/useradd b/usr.sbin/bsdconfig/usermgmt/useradd
index 8a69729..b8cac27 100755
--- a/usr.sbin/bsdconfig/usermgmt/useradd
+++ b/usr.sbin/bsdconfig/usermgmt/useradd
@@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -47,9 +47,9 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
diff --git a/usr.sbin/bsdconfig/usermgmt/userdel b/usr.sbin/bsdconfig/usermgmt/userdel
index 4a7e2be..f266497 100755
--- a/usr.sbin/bsdconfig/usermgmt/userdel
+++ b/usr.sbin/bsdconfig/usermgmt/userdel
@@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -50,9 +50,9 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -67,23 +67,22 @@ f_mustberoot_init
#
# Loop until the user Exits, Cancels or presses ESC
#
+defaultitem=""
while :; do
- f_dialog_menu_user_list
+ f_dialog_menu_user_list "$defaultitem"
retval=$?
- mtag=$( f_dialog_menutag )
+ f_dialog_menutag_fetch mtag
f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
+ defaultitem="$mtag"
[ $retval -eq 0 ] || f_die
- case "$mtag" in
- "X $msg_exit") break ;;
+ [ "$mtag" = "X $msg_exit" ] && break
- *) # anything else is a userid
- $BSDCFG_LIBE/$APP_DIR/userinput \
- ${USE_XDIALOG:+-X} mode="Delete" user="$mtag"
- ;;
+ # Anything else is a userid
- esac
+ $BSDCFG_LIBE/$APP_DIR/userinput \
+ ${USE_XDIALOG:+-X} mode="Delete" user="$mtag"
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/usermgmt/useredit b/usr.sbin/bsdconfig/usermgmt/useredit
index 67aba07..64b7b8e 100755
--- a/usr.sbin/bsdconfig/usermgmt/useredit
+++ b/usr.sbin/bsdconfig/usermgmt/useredit
@@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -50,9 +50,9 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -67,23 +67,22 @@ f_mustberoot_init
#
# Loop until the user Exits, Cancels or presses ESC
#
+defaultitem=""
while :; do
- f_dialog_menu_user_list
+ f_dialog_menu_user_list "$defaultitem"
retval=$?
- mtag=$( f_dialog_menutag )
+ f_dialog_menutag_fetch mtag
f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
+ defaultitem="$mtag"
[ $retval -eq 0 ] || f_die
- case "$mtag" in
- "X $msg_exit") break ;;
+ [ "$mtag" = "X $msg_exit" ] && break
- *) # anything else is a userid
- $BSDCFG_LIBE/$APP_DIR/userinput \
- ${USE_XDIALOG:+-X} mode="Edit/View" user="$mtag"
- ;;
+ # Anything else is a userid
- esac
+ $BSDCFG_LIBE/$APP_DIR/userinput \
+ ${USE_XDIALOG:+-X} mode="Edit/View" user="$mtag"
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/usermgmt/userinput b/usr.sbin/bsdconfig/usermgmt/userinput
index ad62a09..196262b 100755
--- a/usr.sbin/bsdconfig/usermgmt/userinput
+++ b/usr.sbin/bsdconfig/usermgmt/userinput
@@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -84,7 +84,7 @@ save_changes()
f_dialog_msgbox "$msg_error $err\n"
return $retval
fi
- f_dialog_msgbox "$msg_login_deleted"
+ f_show_msg "$msg_login_deleted"
if [ "$pw_group_delete" = "$msg_yes" ] &&
f_quietly pw groupshow -g "$pw_gid"
@@ -122,7 +122,7 @@ save_changes()
f_dialog_msgbox "$msg_error $err\n"
return $retval
fi
- f_dialog_msgbox "$msg_login_added"
+ f_show_msg "$msg_login_added"
if [ "$pw_home_create" = "$msg_yes" ]; then
err=$( mkdir -p "$pw_home_dir" 2>&1 )
@@ -168,7 +168,7 @@ save_changes()
f_dialog_msgbox "$msg_error $err\n"
return $retval
fi
- f_dialog_msgbox "$msg_login_updated"
+ f_show_msg "$msg_login_updated"
if [ "$pw_home_create" = "$msg_yes" ]; then
err=$( mkdir -p "$pw_home_dir" )
@@ -220,8 +220,8 @@ while [ $# -gt 0 ]; do
value="${1#*=}"
f_dprintf "key=[%s] value=[%s]" "$key" "$value"
case "$key" in
- mode) mode="$value";;
- user) user="$value";;
+ mode) mode="$value" ;;
+ user) user="$value" ;;
esac
shift
done
@@ -238,32 +238,53 @@ save_flag=
hline="$hline_arrows_tab_enter"
if [ "$mode" = "Add" ]; then
+ f_dialog_input_name || exit 0
+
#
- # Ask a series of questions to pre-fill the editor screen.
- #
- # The defaults used in each dialog should allow the user to simply
- # hit ENTER to proceed, because cancelling a single dialog will
- # cause them to be returned to the main usermenu.
+ # Set some sensible defaults for account attributes
#
+ pw_gecos="${pw_gecos-$pw_name}"
+ pw_home_dir="${pw_home_dir:-$homeprefix/$pw_name}"
+ if [ -d "$pw_home_dir" ]; then
+ pw_home_create="${pw_home_create:-$msg_no}"
+ pw_dotfiles_create="${pw_dotfiles_create:-$msg_no}"
+ else
+ pw_home_create="${pw_home_create:-$msg_yes}"
+ pw_dotfiles_create="${pw_dotfiles_create:-$msg_yes}"
+ fi
+ pw_shell="${pw_shell:-$defaultshell}"
- f_dialog_input_name || exit 0
- f_dialog_input_gecos "$pw_name" || exit 0
- [ "$passwdtype" = "yes" ] &&
- { f_dialog_input_password || exit 0; }
- f_dialog_input_uid || exit 0
- f_dialog_input_gid || exit 0
- f_dialog_input_member_groups || exit 0
- f_dialog_input_class || exit 0
- f_dialog_input_change || exit 0
- f_dialog_input_expire || exit 0
- f_dialog_input_home_dir "$homeprefix/$pw_name" || exit 0
- pw_dotfiles_create="$msg_no"
- if [ ! -d "$homeprefix/$pw_name" ]; then
- f_dialog_input_home_create || exit 0
- [ "$pw_home_create" = "$msg_yes" ] &&
- { f_dialog_input_dotfiles_create || exit 0; }
+ f_dialog_noyes "$msg_use_default_values_for_all_account_details"
+ retval=$?
+
+ if [ $retval -eq 255 ]; then # User pressed ESC
+ exit $SUCCESS
+ elif [ $retval -ne $SUCCESS ]; then
+ #
+ # Ask a series of questions to pre-fill the editor screen.
+ #
+ # The defaults used in each dialog should allow the user to
+ # simply hit ENTER to proceed, because cancelling a single
+ # dialog will cause them to be returned to the main usermenu.
+ #
+
+ f_dialog_input_gecos "$pw_gecos" || exit 0
+ [ "$passwdtype" = "yes" ] &&
+ { f_dialog_input_password || exit 0; }
+ f_dialog_input_uid || exit 0
+ f_dialog_input_gid || exit 0
+ f_dialog_input_member_groups || exit 0
+ f_dialog_input_class || exit 0
+ f_dialog_input_expire_password || exit 0
+ f_dialog_input_expire_account || exit 0
+ f_dialog_input_home_dir "$pw_home_dir" || exit 0
+ if [ ! -d "$pw_home_dir" ]; then
+ f_dialog_input_home_create || exit 0
+ [ "$pw_home_create" = "$msg_yes" ] &&
+ { f_dialog_input_dotfiles_create || exit 0; }
+ fi
+ f_dialog_input_shell "$pw_shell" || exit 0
fi
- f_dialog_input_shell "$defaultshell" || exit 0
fi
if [ "$mode" = "Edit/View" -o "$mode" = "Delete" ]; then
@@ -384,27 +405,29 @@ while :; do
;;
esac
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\$menu_text\" \
- \"\$hline\" \
- $menu_items )
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$menu_text\" \
+ \"\$hline\" \
+ $menu_items
- dialog_menu=$( eval $DIALOG \
+ f_dialog_default_fetch defaultitem
+ mtag=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
- --menu \"\$menu_text\" $size \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$menu_text\" \
+ $height $width $rows \
$menu_items \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
-
retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
- mtag=$( f_dialog_menutag )
+ f_dialog_data_sanitize mtag
+ f_dialog_default_store "$mtag"
f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
# Exit if user has either pressed ESC or chosen Cancel/No
@@ -421,9 +444,9 @@ while :; do
case "$mode" in
Add) f_dialog_input_name "$pw_name" ;;
Edit/View|Delete)
- f_dialog_menu_user_list
+ f_dialog_menu_user_list "$pw_name"
retval=$?
- mtag=$( f_dialog_menutag )
+ f_dialog_menutag_fetch mtag
f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
# Loop if user has either pressed ESC or chosen Cancel/No
@@ -452,35 +475,25 @@ while :; do
esac
;;
2) # Full Name
- f_dialog_input_gecos "$pw_gecos"
- ;;
+ f_dialog_input_gecos "$pw_gecos" ;;
3) # Password
- f_dialog_input_password
- ;;
+ f_dialog_input_password ;;
4) # UID
- f_dialog_input_uid "$pw_uid"
- ;;
+ f_dialog_input_uid "$pw_uid" ;;
5) # Default Group
- f_dialog_input_gid "$pw_gid"
- ;;
+ f_dialog_input_gid "$pw_gid" ;;
6) # Member of Groups
- f_dialog_input_member_groups "$pw_member_groups"
- ;;
+ f_dialog_input_member_groups "$pw_member_groups" ;;
7) # Login Class
- f_dialog_input_class "$pw_class"
- ;;
+ f_dialog_input_class "$pw_class" ;;
8) # Password Expire on
- f_dialog_input_change "$pw_password_expire"
- ;;
+ f_dialog_input_expire_password "$pw_password_expire" ;;
9) # Account Expire on
- f_dialog_input_expire "$pw_account_expire"
- ;;
+ f_dialog_input_expire_account "$pw_account_expire" ;;
A) # Home Directory
- f_dialog_input_home_dir "$pw_home_dir"
- ;;
+ f_dialog_input_home_dir "$pw_home_dir" ;;
B) # Shell
- f_dialog_input_shell "$pw_shell"
- ;;
+ f_dialog_input_shell "$pw_shell" ;;
esac
case "$mode" in
@@ -507,7 +520,6 @@ while :; do
esac
;;
esac
-
done
exit $SUCCESS
diff --git a/usr.sbin/bsdconfig/usermgmt/usermgmt b/usr.sbin/bsdconfig/usermgmt/usermgmt
index 5376bde..0a4c160 100755
--- a/usr.sbin/bsdconfig/usermgmt/usermgmt
+++ b/usr.sbin/bsdconfig/usermgmt/usermgmt
@@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
-# Copyright (c) 2012 Devin Teske
+# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -51,10 +51,8 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
dialog_menu_main()
{
- local menu_list size
- local hline="$hline_arrows_tab_enter"
-
- menu_list="
+ local prompt=
+ local menu_list="
'X' '$msg_exit'
'1' '$msg_add_login'
'2' '$msg_edit_login'
@@ -64,25 +62,26 @@ dialog_menu_main()
'5' '$msg_edit_group'
'6' '$msg_delete_group'
" # END-QUOTE
+ local defaultitem= # Calculated below
+ local hline="$hline_arrows_tab_enter"
- size=$( eval f_dialog_menu_size \
- \"\$DIALOG_TITLE\" \
- \"\$DIALOG_BACKTITLE\" \
- \"\" \
- \"\$hline\" \
- $menu_list )
-
- if [ "$USE_XDIALOG" ]; then
- # need to bump the width for the buttons
- local height menu_height
- height="${size%%[$IFS]*}" # first word
- menu_height="${size##*[$IFS]}" # last word
- size="$height 40 $menu_height"
- fi
+ local height width rows
+ eval f_dialog_menu_size height width rows \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$prompt\" \
+ \"\$hline\" \
+ $menu_list
+
+ # When using Xdialog(1) we need to bump the width for the buttons
+ [ "$USE_XDIALOG" ] && width=40
- local dialog_menu
- dialog_menu=$( eval $DIALOG \
- --clear --title \"\$DIALOG_TITLE\" \
+ # Obtain default-item from previously stored selection
+ f_dialog_default_fetch defaultitem
+
+ local menu_choice
+ menu_choice=$( eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
@@ -90,11 +89,19 @@ dialog_menu_main()
--help-button \
--help-label \"\$msg_help\" \
${USE_XDIALOG:+--help \"\"} \
- --menu \"\" $size $menu_list \
+ --default-item \"\$defaultitem\" \
+ --menu \"\$prompt\" \
+ $height $width $rows \
+ $menu_list \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
local retval=$?
- setvar DIALOG_MENU_$$ "$dialog_menu"
+ f_dialog_data_sanitize menu_choice
+ f_dialog_menutag_store "$menu_choice"
+
+ # Only update default-item on success
+ [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice"
+
return $retval
}
@@ -106,9 +113,9 @@ dialog_menu_main()
#
# Process command-line arguments
#
-while getopts hSX flag; do
+while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
- h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
+ h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
esac
done
shift $(( $OPTIND - 1 ))
@@ -126,7 +133,7 @@ f_mustberoot_init
while :; do
dialog_menu_main
retval=$?
- mtag=$( f_dialog_menutag )
+ f_dialog_menutag_fetch mtag
f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
if [ $retval -eq 2 ]; then
@@ -137,38 +144,26 @@ while :; do
f_die
fi
+ command=
case "$mtag" in
- X) # Exit
- exit 0
- ;;
-
- 1) # Add User
- $BSDCFG_LIBE/$APP_DIR/useradd ${USE_XDIALOG:+-X}
- ;;
-
- 2) # Edit/View User
- $BSDCFG_LIBE/$APP_DIR/useredit ${USE_XDIALOG:+-X}
- ;;
-
- 3) # Delete User
- $BSDCFG_LIBE/$APP_DIR/userdel ${USE_XDIALOG:+-X}
- ;;
-
- 4) # Add Group
- $BSDCFG_LIBE/$APP_DIR/groupadd ${USE_XDIALOG:+-X}
- ;;
-
- 5) # Edit/View Group
- $BSDCFG_LIBE/$APP_DIR/groupedit ${USE_XDIALOG:+-X}
- ;;
-
- 6) # Delete Group
- $BSDCFG_LIBE/$APP_DIR/groupdel ${USE_XDIALOG:+-X}
- ;;
-
+ X) break ;;
+ 1) command=useradd ;; # Add User
+ 2) command=useredit ;; # Edit/View User
+ 3) command=userdel ;; # Delete User
+ 4) command=groupadd ;; # Add Group
+ 5) command=groupedit ;; # Edit/View Group
+ 6) command=groupdel ;; # Delete Group
esac
+
+ if [ "$command" ]; then
+ $BSDCFG_LIBE/$APP_DIR/$command ${USE_XDIALOG:+-X}
+ else
+ f_die 1 "$msg_unknown_user_management_menu_selection"
+ fi
done
+exit $SUCCESS
+
################################################################################
# END
################################################################################
diff --git a/usr.sbin/bsdinstall/distextract/Makefile b/usr.sbin/bsdinstall/distextract/Makefile
index 3ad1f98..a76e764 100644
--- a/usr.sbin/bsdinstall/distextract/Makefile
+++ b/usr.sbin/bsdinstall/distextract/Makefile
@@ -2,6 +2,7 @@
BINDIR= /usr/libexec/bsdinstall
PROG= distextract
+DPADD= ${LIBARCHIVE} ${LIBNCURSESW} ${LIBDIALOG} ${LIBM}
LDADD= -larchive -lncursesw -ldialog -lm
WARNS?= 6
diff --git a/usr.sbin/bsdinstall/distfetch/Makefile b/usr.sbin/bsdinstall/distfetch/Makefile
index 5a449ac1..bb82908 100644
--- a/usr.sbin/bsdinstall/distfetch/Makefile
+++ b/usr.sbin/bsdinstall/distfetch/Makefile
@@ -2,6 +2,7 @@
BINDIR= /usr/libexec/bsdinstall
PROG= distfetch
+DPADD= ${LIBFETCH} ${LIBNCURSESW} ${LIBDIALOG} ${LIBM}
LDADD= -lfetch -lncursesw -ldialog -lm
WARNS?= 6
diff --git a/usr.sbin/bsdinstall/partedit/Makefile b/usr.sbin/bsdinstall/partedit/Makefile
index b7f5097..fb75888 100644
--- a/usr.sbin/bsdinstall/partedit/Makefile
+++ b/usr.sbin/bsdinstall/partedit/Makefile
@@ -5,6 +5,7 @@ PROG= partedit
LINKS= ${BINDIR}/partedit ${BINDIR}/autopart \
${BINDIR}/partedit ${BINDIR}/scriptedpart
SYMLINKS= ${BINDIR}/partedit /usr/sbin/sade
+DPADD= ${LIBGEOM} ${LIBNCURSESW} ${LIBUTIL} ${LIBDIALOG} ${LIBM}
LDADD= -lgeom -lncursesw -lutil -ldialog -lm
PARTEDIT_ARCH= ${MACHINE}
diff --git a/usr.sbin/bsdinstall/partedit/diskeditor.c b/usr.sbin/bsdinstall/partedit/diskeditor.c
index 9149c2b..4840ae7 100644
--- a/usr.sbin/bsdinstall/partedit/diskeditor.c
+++ b/usr.sbin/bsdinstall/partedit/diskeditor.c
@@ -94,6 +94,22 @@ diskeditor_show(const char *title, const char *cprompt,
END_KEYS_BINDING
};
+ static DLG_KEYS_BINDING binding2[] = {
+ INPUTSTR_BINDINGS,
+ ENTERKEY_BINDINGS,
+ DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ),
+ DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ),
+ DLG_KEYS_DATA( DLGK_ITEM_NEXT, CHR_NEXT ),
+ DLG_KEYS_DATA( DLGK_ITEM_NEXT, KEY_DOWN ),
+ DLG_KEYS_DATA( DLGK_ITEM_NEXT, KEY_NEXT ),
+ DLG_KEYS_DATA( DLGK_ITEM_PREV, CHR_PREVIOUS ),
+ DLG_KEYS_DATA( DLGK_ITEM_PREV, KEY_PREVIOUS ),
+ DLG_KEYS_DATA( DLGK_ITEM_PREV, KEY_UP ),
+ DLG_KEYS_DATA( DLGK_PAGE_NEXT, KEY_NPAGE ),
+ DLG_KEYS_DATA( DLGK_PAGE_PREV, KEY_PPAGE ),
+ END_KEYS_BINDING
+ };
+
/*
* Set up editor window.
*/
@@ -125,7 +141,7 @@ diskeditor_show(const char *title, const char *cprompt,
/* Partition list sub-window */
partitions = dlg_sub_window(dialog, partlist_height, partlist_width,
y + 3, x + 1);
- dlg_register_window(partitions, "partlist", binding);
+ dlg_register_window(partitions, "partlist", binding2);
dlg_register_buttons(partitions, "partlist", buttons);
wattrset(partitions, menubox_attr);
diff --git a/usr.sbin/bsdinstall/scripts/mirrorselect b/usr.sbin/bsdinstall/scripts/mirrorselect
index 30df830..0776a4d 100755
--- a/usr.sbin/bsdinstall/scripts/mirrorselect
+++ b/usr.sbin/bsdinstall/scripts/mirrorselect
@@ -41,7 +41,6 @@ MIRROR=`dialog --backtitle "FreeBSD Installer" \
ftp://ftp.freebsd.org "Main Site"\
ftp://ftp.freebsd.org "IPv6 Main Site"\
ftp://ftp3.ie.freebsd.org "IPv6 Ireland"\
- ftp://ftp.il.freebsd.org "IPv6 Israel"\
ftp://ftp2.jp.freebsd.org "IPv6 Japan"\
ftp://ftp4.se.freebsd.org "IPv6 Sweden"\
ftp://ftp4.us.freebsd.org "IPv6 USA"\
@@ -53,45 +52,34 @@ MIRROR=`dialog --backtitle "FreeBSD Installer" \
ftp://ftp5.freebsd.org "Primary #5"\
ftp://ftp6.freebsd.org "Primary #6"\
ftp://ftp7.freebsd.org "Primary #7"\
- ftp://ftp8.freebsd.org "Primary #8"\
- ftp://ftp9.freebsd.org "Primary #9"\
ftp://ftp10.freebsd.org "Primary #10"\
ftp://ftp11.freebsd.org "Primary #11"\
ftp://ftp12.freebsd.org "Primary #12"\
ftp://ftp13.freebsd.org "Primary #13"\
ftp://ftp14.freebsd.org "Primary #14"\
- ftp://ftp.ar.freebsd.org "Argentina"\
+ ftp://ftp1.am.freebsd.org "Armenia"\
ftp://ftp.au.freebsd.org "Australia"\
ftp://ftp2.au.freebsd.org "Australia #2"\
ftp://ftp3.au.freebsd.org "Australia #3"\
ftp://ftp.at.freebsd.org "Austria"\
- ftp://ftp2.at.freebsd.org "Austria #2"\
- ftp://ftp.br.freebsd.org "Brazil"\
ftp://ftp2.br.freebsd.org "Brazil #2"\
ftp://ftp3.br.freebsd.org "Brazil #3"\
ftp://ftp4.br.freebsd.org "Brazil #4"\
- ftp://ftp5.br.freebsd.org "Brazil #5"\
- ftp://ftp6.br.freebsd.org "Brazil #6"\
- ftp://ftp7.br.freebsd.org "Brazil #7"\
ftp://ftp.ca.freebsd.org "Canada"\
ftp://ftp.cn.freebsd.org "China"\
- ftp://ftp2.cn.freebsd.org "China #2"\
- ftp://ftp.hr.freebsd.org "Croatia"\
ftp://ftp.cz.freebsd.org "Czech Republic"\
ftp://ftp.dk.freebsd.org "Denmark"\
- ftp://ftp2.dk.freebsd.org "Denmark #2"\
ftp://ftp.ee.freebsd.org "Estonia"\
ftp://ftp.fi.freebsd.org "Finland"\
ftp://ftp.fr.freebsd.org "France"\
- ftp://ftp2.fr.freebsd.org "IPv6 France #2"\
ftp://ftp3.fr.freebsd.org "France #3"\
ftp://ftp4.fr.freebsd.org "IPv6 France #4"\
ftp://ftp5.fr.freebsd.org "France #5"\
ftp://ftp6.fr.freebsd.org "France #6"\
+ ftp://ftp7.fr.freebsd.org "France #7"\
ftp://ftp8.fr.freebsd.org "IPv6 France #8"\
ftp://ftp.de.freebsd.org "Germany"\
ftp://ftp2.de.freebsd.org "Germany #2"\
- ftp://ftp3.de.freebsd.org "Germany #3"\
ftp://ftp4.de.freebsd.org "Germany #4"\
ftp://ftp5.de.freebsd.org "Germany #5"\
ftp://ftp6.de.freebsd.org "Germany #6"\
@@ -99,10 +87,7 @@ MIRROR=`dialog --backtitle "FreeBSD Installer" \
ftp://ftp8.de.freebsd.org "Germany #8"\
ftp://ftp.gr.freebsd.org "Greece"\
ftp://ftp2.gr.freebsd.org "Greece #2"\
- ftp://ftp.hu.freebsd.org "Hungary"\
ftp://ftp.is.freebsd.org "Iceland"\
- ftp://ftp.ie.freebsd.org "Ireland"\
- ftp://ftp2.ie.freebsd.org "Ireland #2"\
ftp://ftp3.ie.freebsd.org "Ireland #3"\
ftp://ftp.il.freebsd.org "Israel"\
ftp://ftp.it.freebsd.org "Italy"\
@@ -117,32 +102,26 @@ MIRROR=`dialog --backtitle "FreeBSD Installer" \
ftp://ftp9.jp.freebsd.org "Japan #9"\
ftp://ftp.kr.freebsd.org "Korea"\
ftp://ftp2.kr.freebsd.org "Korea #2"\
+ ftp://ftp.lv.freebsd.org "Latvia"\
ftp://ftp.lt.freebsd.org "Lithuania"\
ftp://ftp.nl.freebsd.org "Netherlands"\
ftp://ftp2.nl.freebsd.org "Netherlands #2"\
+ ftp://ftp.nz.freebsd.org "New Zealand"\
ftp://ftp.no.freebsd.org "Norway"\
- ftp://ftp3.no.freebsd.org "Norway #3"\
ftp://ftp.pl.freebsd.org "Poland"\
ftp://ftp2.pl.freebsd.org "Poland #2"\
- ftp://ftp5.pl.freebsd.org "Poland #5"\
- ftp://ftp.pt.freebsd.org "Portugal"\
- ftp://ftp2.pt.freebsd.org "Portugal #2"\
- ftp://ftp4.pt.freebsd.org "Portugal #4"\
- ftp://ftp.ro.freebsd.org "Romania"\
ftp://ftp.ru.freebsd.org "Russia"\
ftp://ftp2.ru.freebsd.org "Russia #2"\
- ftp://ftp3.ru.freebsd.org "Russia #3"\
ftp://ftp4.ru.freebsd.org "Russia #4"\
- ftp://ftp.sg.freebsd.org "Singapore"\
+ ftp://ftp5.ru.freebsd.org "Russia #5"\
+ ftp://ftp6.ru.freebsd.org "Russia #6"\
ftp://ftp.sk.freebsd.org "Slovak Republic"\
+ ftp://ftp2.sk.freebsd.org "Slovak Republic #2"\
ftp://ftp.si.freebsd.org "Slovenia"\
- ftp://ftp2.si.freebsd.org "Slovenia #2"\
ftp://ftp.za.freebsd.org "South Africa"\
ftp://ftp2.za.freebsd.org "South Africa #2"\
- ftp://ftp3.za.freebsd.org "South Africa #3"\
ftp://ftp4.za.freebsd.org "South Africa #4"\
ftp://ftp.es.freebsd.org "Spain"\
- ftp://ftp2.es.freebsd.org "Spain #2"\
ftp://ftp3.es.freebsd.org "Spain #3"\
ftp://ftp.se.freebsd.org "Sweden"\
ftp://ftp2.se.freebsd.org "Sweden #2"\
@@ -151,39 +130,28 @@ MIRROR=`dialog --backtitle "FreeBSD Installer" \
ftp://ftp5.se.freebsd.org "Sweden #5"\
ftp://ftp6.se.freebsd.org "Sweden #6"\
ftp://ftp.ch.freebsd.org "Switzerland"\
- ftp://ftp2.ch.freebsd.org "Switzerland #2"\
ftp://ftp.tw.freebsd.org "Taiwan"\
ftp://ftp2.tw.freebsd.org "Taiwan #2"\
ftp://ftp3.tw.freebsd.org "Taiwan #3"\
ftp://ftp4.tw.freebsd.org "Taiwan #4"\
ftp://ftp6.tw.freebsd.org "Taiwan #6"\
ftp://ftp11.tw.freebsd.org "Taiwan #11"\
- ftp://ftp.tr.freebsd.org "Turkey"\
- ftp://ftp2.tr.freebsd.org "Turkey #2"\
ftp://ftp.uk.freebsd.org "UK"\
ftp://ftp2.uk.freebsd.org "UK #2"\
ftp://ftp3.uk.freebsd.org "UK #3"\
ftp://ftp4.uk.freebsd.org "UK #4"\
ftp://ftp5.uk.freebsd.org "UK #5"\
- ftp://ftp6.uk.freebsd.org "UK #6"\
ftp://ftp.ua.freebsd.org "Ukraine"\
- ftp://ftp2.ua.freebsd.org "Ukraine #2"\
- ftp://ftp5.ua.freebsd.org "Ukraine #5"\
- ftp://ftp6.ua.freebsd.org "Ukraine #6"\
ftp://ftp7.ua.freebsd.org "Ukraine #7"\
- ftp://ftp8.ua.freebsd.org "Ukraine #8"\
ftp://ftp1.us.freebsd.org "USA #1"\
ftp://ftp2.us.freebsd.org "USA #2"\
ftp://ftp3.us.freebsd.org "USA #3"\
ftp://ftp4.us.freebsd.org "USA #4"\
ftp://ftp5.us.freebsd.org "USA #5"\
ftp://ftp6.us.freebsd.org "USA #6"\
- ftp://ftp7.us.freebsd.org "USA #7"\
ftp://ftp8.us.freebsd.org "USA #8"\
- ftp://ftp9.us.freebsd.org "USA #9"\
ftp://ftp10.us.freebsd.org "USA #10"\
ftp://ftp11.us.freebsd.org "USA #11"\
- ftp://ftp12.us.freebsd.org "USA #12"\
ftp://ftp13.us.freebsd.org "USA #13"\
ftp://ftp14.us.freebsd.org "USA #14"\
ftp://ftp15.us.freebsd.org "USA #15"\
@@ -194,7 +162,7 @@ exec 3>&-
_UNAME_R=`uname -r`
case ${_UNAME_R} in
- *-CURRENT|*-STABLE|*-BETA*|*-PRERELEASE|*-RC*)
+ *-CURRENT|*-STABLE|*-PRERELEASE)
RELDIR="snapshots"
;;
*)
diff --git a/usr.sbin/bsnmpd/modules/Makefile b/usr.sbin/bsnmpd/modules/Makefile
index ab378f0..d5706fe 100644
--- a/usr.sbin/bsnmpd/modules/Makefile
+++ b/usr.sbin/bsnmpd/modules/Makefile
@@ -10,6 +10,7 @@ _snmp_atm= snmp_atm
SUBDIR= ${_snmp_atm} \
snmp_bridge \
+ snmp_hast \
snmp_hostres \
snmp_mibII \
snmp_pf \
diff --git a/usr.sbin/bsnmpd/modules/Makefile.inc b/usr.sbin/bsnmpd/modules/Makefile.inc
index b5dad56..357b441 100644
--- a/usr.sbin/bsnmpd/modules/Makefile.inc
+++ b/usr.sbin/bsnmpd/modules/Makefile.inc
@@ -6,4 +6,6 @@ MANFILTER= sed -e 's%@MODPATH@%${LIBDIR}/%g' \
-e 's%@DEFPATH@%${DEFSDIR}/%g' \
-e 's%@MIBSPATH@%${BMIBSDIR}/%g'
+NO_WMISSING_VARIABLE_DECLARATIONS=
+
.include "../Makefile.inc"
diff --git a/usr.sbin/bsnmpd/modules/snmp_hast/BEGEMOT-HAST-MIB.txt b/usr.sbin/bsnmpd/modules/snmp_hast/BEGEMOT-HAST-MIB.txt
new file mode 100644
index 0000000..6e20bdd
--- /dev/null
+++ b/usr.sbin/bsnmpd/modules/snmp_hast/BEGEMOT-HAST-MIB.txt
@@ -0,0 +1,310 @@
+--
+-- Copyright (c) 2013 Mikolaj Golub <trociny@FreeBSD.org>
+-- All rights reserved.
+--
+-- 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 REGENTS 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 REGENTS 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$
+--
+
+BEGEMOT-HAST-MIB DEFINITIONS ::= BEGIN
+
+IMPORTS
+ MODULE-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE,
+ Counter64, Integer32
+ FROM SNMPv2-SMI
+ TEXTUAL-CONVENTION, RowStatus
+ FROM SNMPv2-TC
+ InterfaceIndex, ifIndex
+ FROM IF-MIB
+ begemot
+ FROM BEGEMOT-MIB;
+
+begemotHast MODULE-IDENTITY
+ LAST-UPDATED "201304130000Z"
+ ORGANIZATION "FreeBSD"
+ CONTACT-INFO
+ " Mikolaj Golub
+
+ Postal: Bluhera 27v 11
+ 61146 Kharkiv
+ Ukraine
+
+ Fax: N/A
+
+ E-Mail: trociny@FreeBSD.org"
+ DESCRIPTION
+ "The Begemot MIB for managing HAST."
+ REVISION "201304130000Z"
+ DESCRIPTION
+ "Initial revision."
+ REVISION "201307010000Z"
+ DESCRIPTION
+ "Added hastResourceWorkerPid."
+ ::= { begemot 220 }
+
+begemotHastObjects OBJECT IDENTIFIER ::= { begemotHast 1 }
+
+-- ---------------------------------------------------------- --
+-- Configuration parameters
+-- ---------------------------------------------------------- --
+
+hastConfig OBJECT IDENTIFIER ::= { begemotHastObjects 1 }
+
+hastConfigFile OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "HAST configuration file location."
+ ::= { hastConfig 1 }
+
+-- ---------------------------------------------------------- --
+-- Resource Table
+-- ---------------------------------------------------------- --
+hastResourceTable OBJECT-TYPE
+ SYNTAX SEQUENCE OF HastResourceEntry
+ MAX-ACCESS not-accessible
+ STATUS current
+ DESCRIPTION
+ "A table containing information about all HAST resources."
+ ::= { begemotHastObjects 2 }
+
+hastResourceEntry OBJECT-TYPE
+ SYNTAX HastResourceEntry
+ MAX-ACCESS not-accessible
+ STATUS current
+ DESCRIPTION
+ "Table entry that describes one HAST resource."
+ INDEX { hastResourceIndex }
+ ::= { hastResourceTable 1 }
+
+HastResourceEntry ::= SEQUENCE {
+ hastResourceIndex Integer32,
+ hastResourceName OCTET STRING,
+ hastResourceRole INTEGER,
+ hastResourceProvName OCTET STRING,
+ hastResourceLocalPath OCTET STRING,
+ hastResourceExtentSize Integer32,
+ hastResourceKeepDirty Integer32,
+ hastResourceRemoteAddr OCTET STRING,
+ hastResourceSourceAddr OCTET STRING,
+ hastResourceReplication INTEGER,
+ hastResourceStatus INTEGER,
+ hastResourceDirty Counter64,
+ hastResourceReads Counter64,
+ hastResourceWrites Counter64,
+ hastResourceDeletes Counter64,
+ hastResourceFlushes Counter64,
+ hastResourceActivemapUpdates Counter64,
+ hastResourceReadErrors Counter64,
+ hastResourceWriteErrors Counter64,
+ hastResourceDeleteErrors Counter64,
+ hastResourceFlushErrors Counter64,
+ hastResourceWorkerPid INTEGER
+}
+
+hastResourceIndex OBJECT-TYPE
+ SYNTAX Integer32
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Resource index."
+ ::= { hastResourceEntry 1 }
+
+hastResourceName OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Resource name."
+ ::= { hastResourceEntry 2 }
+
+hastResourceRole OBJECT-TYPE
+ SYNTAX INTEGER { undef(0), init(1), primary(2), secondary(3) }
+ MAX-ACCESS read-write
+ STATUS current
+ DESCRIPTION
+ "Resource role."
+ ::= { hastResourceEntry 3 }
+
+hastResourceProvName OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Resource GEOM provider name that appears as /dev/hast/<name>."
+ ::= { hastResourceEntry 4 }
+
+hastResourceLocalPath OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Path to the local component which is used as a backend
+ provider for the resource."
+ ::= { hastResourceEntry 5 }
+
+hastResourceExtentSize OBJECT-TYPE
+ SYNTAX Integer32
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Size of an extent. Extent is a block which is
+ used for synchronization. hastd(8) maintains a
+ map of dirty extents and extent is the smallest
+ region that can be marked as dirty. If any part
+ of an extent is modified, entire extent will be
+ synchronized when nodes connect."
+ ::= { hastResourceEntry 6 }
+
+hastResourceKeepDirty OBJECT-TYPE
+ SYNTAX Integer32
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Maximum number of dirty extents to keep dirty all
+ the time. Most recently used extents are kept
+ dirty to reduce number of metadata updates."
+ ::= { hastResourceEntry 7 }
+
+hastResourceRemoteAddr OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Address of the remote hastd(8) daemon for the resource."
+ ::= { hastResourceEntry 8 }
+
+hastResourceSourceAddr OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Local address the resource is bound to."
+ ::= { hastResourceEntry 9 }
+
+hastResourceReplication OBJECT-TYPE
+ SYNTAX INTEGER { fullsync(0), memsync(1), async(2) }
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Resource replication mode."
+ ::= { hastResourceEntry 10 }
+
+hastResourceStatus OBJECT-TYPE
+ SYNTAX INTEGER { complete(0), degraded(1) }
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Resource replication status."
+ ::= { hastResourceEntry 11 }
+
+hastResourceDirty OBJECT-TYPE
+ SYNTAX Counter64
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Current number of dirty extents for the resource."
+ ::= { hastResourceEntry 12 }
+
+hastResourceReads OBJECT-TYPE
+ SYNTAX Counter64
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Count of resource local read operations."
+ ::= { hastResourceEntry 13 }
+
+hastResourceWrites OBJECT-TYPE
+ SYNTAX Counter64
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Count of resource local write operations."
+ ::= { hastResourceEntry 14 }
+
+hastResourceDeletes OBJECT-TYPE
+ SYNTAX Counter64
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Count of resource local delete operations."
+ ::= { hastResourceEntry 15 }
+
+hastResourceFlushes OBJECT-TYPE
+ SYNTAX Counter64
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Count of resource local flush operations."
+ ::= { hastResourceEntry 16 }
+
+hastResourceActivemapUpdates OBJECT-TYPE
+ SYNTAX Counter64
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Count of resource local activemap updates."
+ ::= { hastResourceEntry 17 }
+
+hastResourceReadErrors OBJECT-TYPE
+ SYNTAX Counter64
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Count of resource local read operations that failed."
+ ::= { hastResourceEntry 18 }
+
+hastResourceWriteErrors OBJECT-TYPE
+ SYNTAX Counter64
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Count of resource local write operations that failed."
+ ::= { hastResourceEntry 19 }
+
+hastResourceDeleteErrors OBJECT-TYPE
+ SYNTAX Counter64
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Count of resource local delete operations that failed."
+ ::= { hastResourceEntry 20 }
+
+hastResourceFlushErrors OBJECT-TYPE
+ SYNTAX Counter64
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Count of resource local flush operations that failed."
+ ::= { hastResourceEntry 21 }
+
+hastResourceWorkerPid OBJECT-TYPE
+ SYNTAX INTEGER
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Worker process ID."
+ ::= { hastResourceEntry 22 }
+
+END
diff --git a/usr.sbin/bsnmpd/modules/snmp_hast/Makefile b/usr.sbin/bsnmpd/modules/snmp_hast/Makefile
new file mode 100644
index 0000000..6369918
--- /dev/null
+++ b/usr.sbin/bsnmpd/modules/snmp_hast/Makefile
@@ -0,0 +1,43 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+.PATH: ${.CURDIR}/../../../../sbin/hastd
+
+MOD= hast
+SRCS= ebuf.c
+SRCS+= hast_compression.c hast_proto.c hast_snmp.c
+SRCS+= lzf.c
+SRCS+= nv.c
+SRCS+= parse.y pjdlog.c
+SRCS+= proto.c proto_common.c proto_uds.c
+SRCS+= token.l
+SRCS+= y.tab.h
+MAN= snmp_hast.3
+
+NO_WFORMAT=
+NO_WCAST_ALIGN=
+NO_WMISSING_VARIABLE_DECLARATIONS=
+CFLAGS+=-I${.CURDIR}/../../../../sbin/hastd
+CFLAGS+=-DHAVE_CAPSICUM
+CFLAGS+=-DINET
+.if ${MK_INET6_SUPPORT} != "no"
+CFLAGS+=-DINET6
+.endif
+# This is needed to have WARNS > 1.
+CFLAGS+=-DYY_NO_UNPUT
+CFLAGS+=-DYY_NO_INPUT
+CFLAGS+= -DSNMPTREE_TYPES
+
+DPADD= ${LIBUTIL}
+LDADD= -lutil
+
+XSYM= begemotHast
+DEFS= ${MOD}_tree.def
+BMIBS= BEGEMOT-HAST-MIB.txt
+
+YFLAGS+=-v
+
+CLEANFILES=y.tab.c y.tab.h y.output
+
+.include <bsd.snmpmod.mk>
diff --git a/usr.sbin/bsnmpd/modules/snmp_hast/hast_snmp.c b/usr.sbin/bsnmpd/modules/snmp_hast/hast_snmp.c
new file mode 100644
index 0000000..ef8832a
--- /dev/null
+++ b/usr.sbin/bsnmpd/modules/snmp_hast/hast_snmp.c
@@ -0,0 +1,511 @@
+/*-
+ * Copyright (c) 2013 Mikolaj Golub <trociny@FreeBSD.org>
+ * All rights reserved.
+ *
+ * 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 REGENTS 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 REGENTS 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/param.h>
+#include <sys/queue.h>
+
+#include <bsnmp/snmpmod.h>
+
+#include <string.h>
+
+#include "hast.h"
+#include "hast_oid.h"
+#include "hast_proto.h"
+#include "hast_tree.h"
+#include "nv.h"
+#include "pjdlog.h"
+#include "proto.h"
+
+#define UPDATE_INTERVAL 500 /* update interval in ticks */
+
+static struct lmodule *module;
+
+static const struct asn_oid oid_hast = OIDX_begemotHast;
+
+/* the Object Resource registration index */
+static u_int hast_index = 0;
+
+/*
+ * Structure that describes single resource.
+ */
+struct hast_snmp_resource {
+ TAILQ_ENTRY(hast_snmp_resource) link;
+ int32_t index;
+ char name[NAME_MAX];
+ int error;
+ int role;
+ char provname[NAME_MAX];
+ char localpath[PATH_MAX];
+ int32_t extentsize;
+ int32_t keepdirty;
+ char remoteaddr[HAST_ADDRSIZE];
+ char sourceaddr[HAST_ADDRSIZE];
+ int replication;
+ int status;
+ uint64_t dirty;
+ uint64_t reads;
+ uint64_t writes;
+ uint64_t deletes;
+ uint64_t flushes;
+ uint64_t activemap_updates;
+ uint64_t read_errors;
+ uint64_t write_errors;
+ uint64_t delete_errors;
+ uint64_t flush_errors;
+ pid_t workerpid;
+};
+
+static TAILQ_HEAD(, hast_snmp_resource) resources =
+ TAILQ_HEAD_INITIALIZER(resources);
+
+/* Path to configuration file. */
+static u_char *cfgpath;
+/* Ticks of the last hast resources update. */
+static uint64_t last_resources_update;
+
+static void free_resources(void);
+static int hastctl(struct nv *nvin, struct nv **nvout);
+static int hast_fini(void);
+static int hast_init(struct lmodule *mod, int argc, char *argv[]);
+static void hast_start(void);
+static int set_role(const char *resource, int role);
+static int str2role(const char *str);
+static int str2replication(const char *str);
+static int str2status(const char *str);
+static int update_resources(void);
+
+const struct snmp_module config = {
+ .comment = "This module implements the BEGEMOT MIB for HAST.",
+ .init = hast_init,
+ .start = hast_start,
+ .fini = hast_fini,
+ .tree = hast_ctree,
+ .tree_size = hast_CTREE_SIZE,
+};
+
+static int
+hast_init(struct lmodule *mod, int argc __unused, char *argv[] __unused)
+{
+
+ module = mod;
+
+ pjdlog_init(PJDLOG_MODE_SYSLOG);
+ pjdlog_debug_set(0);
+
+ cfgpath = malloc(sizeof(HAST_CONFIG));
+ if (cfgpath == NULL) {
+ pjdlog_error("Unable to allocate %zu bytes for cfgpath",
+ sizeof(HAST_CONFIG));
+ return (-1);
+ }
+ strcpy(cfgpath, HAST_CONFIG);
+ return(0);
+}
+
+static void
+hast_start(void)
+{
+ hast_index = or_register(&oid_hast,
+ "The MIB module for BEGEMOT-HAST-MIB.", module);
+}
+
+static int
+hast_fini(void)
+{
+
+ or_unregister(hast_index);
+ free_resources();
+ free(cfgpath);
+ return (0);
+}
+
+static void
+free_resources(void)
+{
+ struct hast_snmp_resource *res;
+
+ while ((res = TAILQ_FIRST(&resources)) != NULL) {
+ TAILQ_REMOVE(&resources, res, link);
+ free(res);
+ }
+}
+
+static int
+str2role(const char *str)
+{
+
+ if (strcmp(str, "init") == 0)
+ return (HAST_ROLE_INIT);
+ if (strcmp(str, "primary") == 0)
+ return (HAST_ROLE_PRIMARY);
+ if (strcmp(str, "secondary") == 0)
+ return (HAST_ROLE_SECONDARY);
+ return (HAST_ROLE_UNDEF);
+}
+
+static int
+str2replication(const char *str)
+{
+
+ if (strcmp(str, "fullsync") == 0)
+ return (HAST_REPLICATION_FULLSYNC);
+ if (strcmp(str, "memsync") == 0)
+ return (HAST_REPLICATION_MEMSYNC);
+ if (strcmp(str, "async") == 0)
+ return (HAST_REPLICATION_ASYNC);
+ return (-1);
+}
+
+static int
+str2status(const char *str)
+{
+
+ if (strcmp(str, "complete") == 0)
+ return (0);
+ if (strcmp(str, "degraded") == 0)
+ return (1);
+ return (-1);
+}
+
+static int
+hastctl(struct nv *nvin, struct nv **nvout)
+{
+ struct hastd_config *cfg;
+ struct proto_conn *conn;
+ struct nv *nv;
+ int error;
+
+ cfg = yy_config_parse(cfgpath, true);
+ if (cfg == NULL)
+ return (-1);
+
+ /* Setup control connection... */
+ if (proto_client(NULL, cfg->hc_controladdr, &conn) == -1) {
+ pjdlog_error("Unable to setup control connection to %s",
+ cfg->hc_controladdr);
+ return (-1);
+ }
+ /* ...and connect to hastd. */
+ if (proto_connect(conn, HAST_TIMEOUT) == -1) {
+ pjdlog_error("Unable to connect to hastd via %s",
+ cfg->hc_controladdr);
+ proto_close(conn);
+ return (-1);
+ }
+ /* Send the command to the server... */
+ if (hast_proto_send(NULL, conn, nvin, NULL, 0) == -1) {
+ pjdlog_error("Unable to send command to hastd via %s",
+ cfg->hc_controladdr);
+ proto_close(conn);
+ return (-1);
+ }
+ /* ...and receive reply. */
+ if (hast_proto_recv_hdr(conn, &nv) == -1) {
+ pjdlog_error("cannot receive reply from hastd via %s",
+ cfg->hc_controladdr);
+ proto_close(conn);
+ return (-1);
+ }
+ proto_close(conn);
+ error = nv_get_int16(nv, "error");
+ if (error != 0) {
+ pjdlog_error("Error %d received from hastd.", error);
+ nv_free(nv);
+ return (-1);
+ }
+ nv_set_error(nv, 0);
+ *nvout = nv;
+ return (0);
+}
+
+static int
+set_role(const char *resource, int role)
+{
+ struct nv *nvin, *nvout;
+ int error;
+
+ nvin = nv_alloc();
+ nv_add_string(nvin, resource, "resource%d", 0);
+ nv_add_uint8(nvin, HASTCTL_CMD_SETROLE, "cmd");
+ nv_add_uint8(nvin, role, "role");
+ error = hastctl(nvin, &nvout);
+ nv_free(nvin);
+ if (error != 0)
+ return (-1);
+ nv_free(nvout);
+ return (SNMP_ERR_NOERROR);
+}
+
+static int
+update_resources(void)
+{
+ struct hast_snmp_resource *res;
+ struct nv *nvin, *nvout;
+ static uint64_t now;
+ unsigned int i;
+ const char *str;
+ int error;
+
+ now = get_ticks();
+ if (now - last_resources_update < UPDATE_INTERVAL)
+ return (0);
+
+ last_resources_update = now;
+
+ free_resources();
+
+ nvin = nv_alloc();
+ nv_add_uint8(nvin, HASTCTL_CMD_STATUS, "cmd");
+ nv_add_string(nvin, "all", "resource%d", 0);
+ error = hastctl(nvin, &nvout);
+ nv_free(nvin);
+ if (error != 0)
+ return (-1);
+
+ for (i = 0; ; i++) {
+ str = nv_get_string(nvout, "resource%u", i);
+ if (str == NULL)
+ break;
+ res = calloc(1, sizeof(*res));
+ if (res == NULL) {
+ pjdlog_error("Unable to allocate %zu bytes for "
+ "resource", sizeof(*res));
+ return (-1);
+ }
+ res->index = i + 1;
+ strncpy(res->name, str, sizeof(res->name) - 1);
+ error = nv_get_int16(nvout, "error%u", i);
+ if (error != 0)
+ continue;
+ str = nv_get_string(nvout, "role%u", i);
+ res->role = str != NULL ? str2role(str) : HAST_ROLE_UNDEF;
+ str = nv_get_string(nvout, "provname%u", i);
+ if (str != NULL)
+ strncpy(res->provname, str, sizeof(res->provname) - 1);
+ str = nv_get_string(nvout, "localpath%u", i);
+ if (str != NULL) {
+ strncpy(res->localpath, str,
+ sizeof(res->localpath) - 1);
+ }
+ res->extentsize = nv_get_uint32(nvout, "extentsize%u", i);
+ res->keepdirty = nv_get_uint32(nvout, "keepdirty%u", i);
+ str = nv_get_string(nvout, "remoteaddr%u", i);
+ if (str != NULL) {
+ strncpy(res->remoteaddr, str,
+ sizeof(res->remoteaddr) - 1);
+ }
+ str = nv_get_string(nvout, "sourceaddr%u", i);
+ if (str != NULL) {
+ strncpy(res->sourceaddr, str,
+ sizeof(res->sourceaddr) - 1);
+ }
+ str = nv_get_string(nvout, "replication%u", i);
+ res->replication = str != NULL ? str2replication(str) : -1;
+ str = nv_get_string(nvout, "status%u", i);
+ res->status = str != NULL ? str2status(str) : -1;
+ res->dirty = nv_get_uint64(nvout, "dirty%u", i);
+ res->reads = nv_get_uint64(nvout, "stat_read%u", i);
+ res->writes = nv_get_uint64(nvout, "stat_write%u", i);
+ res->deletes = nv_get_uint64(nvout, "stat_delete%u", i);
+ res->flushes = nv_get_uint64(nvout, "stat_flush%u", i);
+ res->activemap_updates =
+ nv_get_uint64(nvout, "stat_activemap_update%u", i);
+ res->read_errors =
+ nv_get_uint64(nvout, "stat_read_error%u", i);
+ res->write_errors =
+ nv_get_uint64(nvout, "stat_write_error%u", i);
+ res->delete_errors =
+ nv_get_uint64(nvout, "stat_delete_error%u", i);
+ res->flush_errors =
+ nv_get_uint64(nvout, "stat_flush_error%u", i);
+ res->workerpid = nv_get_int32(nvout, "workerpid%u", i);
+ TAILQ_INSERT_TAIL(&resources, res, link);
+ }
+ nv_free(nvout);
+ return (0);
+}
+
+int
+op_hastConfig(struct snmp_context *context, struct snmp_value *value,
+ u_int sub, u_int iidx __unused, enum snmp_op op)
+{
+ asn_subid_t which;
+
+ which = value->var.subs[sub - 1];
+
+ switch (op) {
+ case SNMP_OP_GET:
+ switch (which) {
+ case LEAF_hastConfigFile:
+ return (string_get(value, cfgpath, -1));
+ default:
+ return (SNMP_ERR_RES_UNAVAIL);
+ }
+ case SNMP_OP_SET:
+ switch (which) {
+ case LEAF_hastConfigFile:
+ return (string_save(value, context, -1,
+ (u_char **)&cfgpath));
+ default:
+ return (SNMP_ERR_RES_UNAVAIL);
+ }
+ case SNMP_OP_GETNEXT:
+ case SNMP_OP_ROLLBACK:
+ case SNMP_OP_COMMIT:
+ return (SNMP_ERR_NOERROR);
+ default:
+ return (SNMP_ERR_RES_UNAVAIL);
+ }
+}
+
+int
+op_hastResourceTable(struct snmp_context *context __unused,
+ struct snmp_value *value, u_int sub, u_int iidx __unused, enum snmp_op op)
+{
+ struct hast_snmp_resource *res;
+ asn_subid_t which;
+ int ret;
+
+ if (update_resources() == -1)
+ return (SNMP_ERR_RES_UNAVAIL);
+
+ which = value->var.subs[sub - 1];
+
+ switch (op) {
+ case SNMP_OP_GETNEXT:
+ res = NEXT_OBJECT_INT(&resources, &value->var, sub);
+ if (res == NULL)
+ return (SNMP_ERR_NOSUCHNAME);
+ value->var.len = sub + 1;
+ value->var.subs[sub] = res->index;
+ break;
+ case SNMP_OP_GET:
+ if (value->var.len - sub != 1)
+ return (SNMP_ERR_NOSUCHNAME);
+ res = FIND_OBJECT_INT(&resources, &value->var, sub);
+ if (res == NULL)
+ return (SNMP_ERR_NOSUCHNAME);
+ break;
+ case SNMP_OP_SET:
+ res = FIND_OBJECT_INT(&resources, &value->var, sub);
+ if (res == NULL)
+ return (SNMP_ERR_NOSUCHNAME);
+ switch (which) {
+ case LEAF_hastResourceRole:
+ ret = set_role(res->name, value->v.integer);
+ /* force update on next run */
+ last_resources_update = 0;
+ break;
+ default:
+ ret = SNMP_ERR_NOT_WRITEABLE;
+ break;
+ }
+ return ret;
+ case SNMP_OP_ROLLBACK:
+ case SNMP_OP_COMMIT:
+ return (SNMP_ERR_NOERROR);
+ default:
+ return (SNMP_ERR_RES_UNAVAIL);
+ }
+
+ ret = SNMP_ERR_NOERROR;
+
+ switch (which) {
+ case LEAF_hastResourceIndex:
+ value->v.integer = res->index;
+ break;
+ case LEAF_hastResourceName:
+ ret = string_get(value, res->name, -1);
+ break;
+ case LEAF_hastResourceRole:
+ value->v.integer = res->role;
+ break;
+ case LEAF_hastResourceProvName:
+ ret = string_get(value, res->provname, -1);
+ break;
+ case LEAF_hastResourceLocalPath:
+ ret = string_get(value, res->localpath, -1);
+ break;
+ case LEAF_hastResourceExtentSize:
+ value->v.integer = res->extentsize;
+ break;
+ case LEAF_hastResourceKeepDirty:
+ value->v.integer = res->keepdirty;
+ break;
+ case LEAF_hastResourceRemoteAddr:
+ ret = string_get(value, res->remoteaddr, -1);
+ break;
+ case LEAF_hastResourceSourceAddr:
+ ret = string_get(value, res->sourceaddr, -1);
+ break;
+ case LEAF_hastResourceReplication:
+ value->v.integer = res->replication;
+ break;
+ case LEAF_hastResourceStatus:
+ value->v.integer = res->status;
+ break;
+ case LEAF_hastResourceDirty:
+ value->v.counter64 = res->dirty;
+ break;
+ case LEAF_hastResourceReads:
+ value->v.counter64 = res->reads;
+ break;
+ case LEAF_hastResourceWrites:
+ value->v.counter64 = res->writes;
+ break;
+ case LEAF_hastResourceDeletes:
+ value->v.counter64 = res->deletes;
+ break;
+ case LEAF_hastResourceFlushes:
+ value->v.counter64 = res->flushes;
+ break;
+ case LEAF_hastResourceActivemapUpdates:
+ value->v.counter64 = res->activemap_updates;
+ break;
+ case LEAF_hastResourceReadErrors:
+ value->v.counter64 = res->read_errors;
+ break;
+ case LEAF_hastResourceWriteErrors:
+ value->v.counter64 = res->write_errors;
+ break;
+ case LEAF_hastResourceDeleteErrors:
+ value->v.counter64 = res->delete_errors;
+ break;
+ case LEAF_hastResourceFlushErrors:
+ value->v.counter64 = res->flush_errors;
+ break;
+ case LEAF_hastResourceWorkerPid:
+ value->v.integer = res->workerpid;
+ break;
+ default:
+ ret = SNMP_ERR_RES_UNAVAIL;
+ break;
+ }
+ return (ret);
+}
diff --git a/usr.sbin/bsnmpd/modules/snmp_hast/hast_tree.def b/usr.sbin/bsnmpd/modules/snmp_hast/hast_tree.def
new file mode 100644
index 0000000..3769bd2
--- /dev/null
+++ b/usr.sbin/bsnmpd/modules/snmp_hast/hast_tree.def
@@ -0,0 +1,71 @@
+#-
+# Copyright (c) 2013 Mikolaj Golub <trociny@FreeBSD.org>
+# All rights reserved.
+#
+# 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 REGENTS 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 REGENTS 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$
+#
+
+(1 internet
+ (4 private
+ (1 enterprises
+ (12325 fokus
+ (1 begemot
+ (220 begemotHast
+ (1 begemotHastObjects
+ (1 hastConfig
+ (1 hastConfigFile OCTETSTRING op_hastConfig GET)
+ )
+ (2 hastResourceTable
+ (1 hastResourceEntry : OCTETSTRING op_hastResourceTable
+ (1 hastResourceIndex INTEGER32 GET)
+ (2 hastResourceName OCTETSTRING GET)
+ (3 hastResourceRole INTEGER GET SET)
+ (4 hastResourceProvName OCTETSTRING GET)
+ (5 hastResourceLocalPath OCTETSTRING GET)
+ (6 hastResourceExtentSize INTEGER32 GET)
+ (7 hastResourceKeepDirty INTEGER32 GET)
+ (8 hastResourceRemoteAddr OCTETSTRING GET)
+ (9 hastResourceSourceAddr OCTETSTRING GET)
+ (10 hastResourceReplication INTEGER GET)
+ (11 hastResourceStatus INTEGER GET)
+ (12 hastResourceDirty COUNTER64 GET)
+ (13 hastResourceReads COUNTER64 GET)
+ (14 hastResourceWrites COUNTER64 GET)
+ (15 hastResourceDeletes COUNTER64 GET)
+ (16 hastResourceFlushes COUNTER64 GET)
+ (17 hastResourceActivemapUpdates COUNTER64 GET)
+ (18 hastResourceReadErrors COUNTER64 GET)
+ (19 hastResourceWriteErrors COUNTER64 GET)
+ (20 hastResourceDeleteErrors COUNTER64 GET)
+ (21 hastResourceFlushErrors COUNTER64 GET)
+ (22 hastResourceWorkerPid INTEGER GET)
+ )
+ )
+ )
+ )
+ )
+ )
+ )
+ )
+)
diff --git a/usr.sbin/bsnmpd/modules/snmp_hast/snmp_hast.3 b/usr.sbin/bsnmpd/modules/snmp_hast/snmp_hast.3
new file mode 100644
index 0000000..2b966d7
--- /dev/null
+++ b/usr.sbin/bsnmpd/modules/snmp_hast/snmp_hast.3
@@ -0,0 +1,69 @@
+.\"-
+.\" Copyright (c) 2013 Mikolaj Golub <trociny@FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" 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 REGENTS 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 REGENTS 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 9, 2013
+.Dt SNMP_HAST 3
+.Os
+.Sh NAME
+.Nm snmp_hast
+.Nd "HAST module for"
+.Xr bsnmpd 1
+.Sh LIBRARY
+.Pq begemotSnmpdModulePath."hast" = "/usr/lib/snmp_hast.so"
+.Sh DESCRIPTION
+The
+.Nm snmp_hast
+module implements a private BEGEMOT-HAST-MIB, which allows
+management of HAST resources.
+.Pp
+The module uses
+.Xr hastd 8
+control socket to communicate with the daemon.
+.Va hastConfigFile
+variable can be used to specify the location of
+.Xr hast.conf 5
+file to find the address of the control connection.
+.Sh FILES
+.Bl -tag -width "XXXXXXXXX"
+.It Pa /usr/share/snmp/defs/hast_tree.def
+The description of the MIB tree implemented by
+.Nm .
+.It Pa /usr/share/snmp/mibs/BEGEMOT-HAST-MIB.txt
+The private BEGEMOT-HAST-MIB that is implemented by this module.
+.It Pa /etc/hast.conf
+The default
+.Xr hastd 8
+configuration file.
+.El
+.Sh SEE ALSO
+.Xr bsnmpd 1 ,
+.Xr gensnmptree 1 ,
+.Xr hastctl 8 ,
+.Xr hastd 8 ,
+.Xr snmpmod 3
+.Sh AUTHORS
+.An Mikolaj Golub Aq trociny@FreeBSD.org
diff --git a/usr.sbin/config/Makefile b/usr.sbin/config/Makefile
index 6faf847..6561989 100644
--- a/usr.sbin/config/Makefile
+++ b/usr.sbin/config/Makefile
@@ -11,6 +11,8 @@ kernconf.c: kernconf.tmpl
CFLAGS+= -I. -I${.CURDIR}
+NO_WMISSING_VARIABLE_DECLARATIONS=
+
DPADD= ${LIBL} ${LIBSBUF}
LDADD= -ll -lsbuf
diff --git a/usr.sbin/config/lang.l b/usr.sbin/config/lang.l
index 81f820f..3e4e115 100644
--- a/usr.sbin/config/lang.l
+++ b/usr.sbin/config/lang.l
@@ -38,9 +38,6 @@
#include "y.tab.h"
#include "config.h"
-#define YY_NO_UNPUT
-#define YY_NO_INPUT
-
/*
* Data for returning to previous files from include files.
*/
@@ -96,7 +93,12 @@ unsigned int octal(const char *);
unsigned int hex(const char *);
int yyerror(const char *);
+#define YY_DECL int yylex(void)
%}
+
+%option nounput
+%option noinput
+
ID [A-Za-z_][-A-Za-z_0-9]*
PATH [./][-/.%^A-Za-z_0-9]+
%START TOEOL
diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c
index 3ed5495..78bb13d 100644
--- a/usr.sbin/config/main.c
+++ b/usr.sbin/config/main.c
@@ -706,17 +706,11 @@ kernconfdump(const char *file)
r = fgetc(fp);
if (r == EOF)
break;
- /*
- * If '\0' is present in the middle of the configuration
- * string, this means something very weird is happening.
- * Make such case very visible. However, some architectures
- * pad the length of the section with NULs to a multiple of
- * sh_addralign, allow a NUL in that part of the section.
- */
- if (r == '\0' && (size - i) < align)
+ if (r == '\0') {
+ assert(i == size - 1 &&
+ ("\\0 found in the middle of a file"));
break;
- assert(r != '\0' && ("Char present in the configuration "
- "string mustn't be equal to 0"));
+ }
fputc(r, stdout);
}
fclose(fp);
diff --git a/usr.sbin/crashinfo/crashinfo.sh b/usr.sbin/crashinfo/crashinfo.sh
index b1bfc06..cf60a62 100755
--- a/usr.sbin/crashinfo/crashinfo.sh
+++ b/usr.sbin/crashinfo/crashinfo.sh
@@ -268,9 +268,9 @@ netstat -M $VMCORE -N $KERNEL -m
echo
echo "------------------------------------------------------------------------"
-echo "netstat -id"
+echo "netstat -idW"
echo
-netstat -M $VMCORE -N $KERNEL -id
+netstat -M $VMCORE -N $KERNEL -idW
echo
echo "------------------------------------------------------------------------"
diff --git a/usr.sbin/ctladm/ctladm.c b/usr.sbin/ctladm/ctladm.c
index bfbedc7..17c1148 100644
--- a/usr.sbin/ctladm/ctladm.c
+++ b/usr.sbin/ctladm/ctladm.c
@@ -546,7 +546,8 @@ retry:
}
if (xml != 0) {
sbuf_printf(sb, "</ctlfelist>\n");
- sbuf_finish(sb);
+ if (sbuf_finish(sb) != 0)
+ err(1, "%s: sbuf_finish", __func__);
printf("%s", sbuf_data(sb));
sbuf_delete(sb);
}
@@ -3493,7 +3494,8 @@ cctl_end_element(void *user_data, const char *name)
errx(1, "%s: no valid sbuf at level %d (name %s)", __func__,
devlist->level, name);
- sbuf_finish(devlist->cur_sb[devlist->level]);
+ if (sbuf_finish(devlist->cur_sb[devlist->level]) != 0)
+ err(1, "%s: sbuf_finish", __func__);
str = strdup(sbuf_data(devlist->cur_sb[devlist->level]));
if (str == NULL)
err(1, "%s can't allocate %zd bytes for string", __func__,
diff --git a/usr.sbin/dnssec-verify/Makefile b/usr.sbin/dnssec-verify/Makefile
new file mode 100644
index 0000000..1d1dc9d
--- /dev/null
+++ b/usr.sbin/dnssec-verify/Makefile
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+BIND_DIR= ${.CURDIR}/../../contrib/bind9
+LIB_BIND_REL= ../../lib/bind
+LIB_BIND_DIR= ${.CURDIR}/${LIB_BIND_REL}
+SRCDIR= ${BIND_DIR}/bin/dnssec
+
+.include "${LIB_BIND_DIR}/config.mk"
+
+PROG= dnssec-verify
+
+.PATH: ${SRCDIR}
+SRCS+= dnssec-verify.c dnssectool.c
+
+CFLAGS+= -I${SRCDIR}/unix/include -I${SRCDIR}/include
+CFLAGS+= -fsigned-char
+
+DPADD+= ${BIND_DPADD} ${CRYPTO_DPADD} ${PTHREAD_DPADD}
+LDADD+= ${BIND_LDADD} ${CRYPTO_LDADD} ${PTHREAD_LDADD}
+
+WARNS?= 3
+
+MAN= dnssec-verify.8
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/dumpcis/printcis.c b/usr.sbin/dumpcis/printcis.c
index 74221e8..ff2ac90 100644
--- a/usr.sbin/dumpcis/printcis.c
+++ b/usr.sbin/dumpcis/printcis.c
@@ -969,7 +969,7 @@ dump_network_ext(u_char *p, int len)
printf(" %02x", p[i + 2]);
putchar('\n');
break;
- case 5: /* Connecter type */
+ case 5: /* Connector type */
if (len < 2)
goto err;
printf("\tNetwork connector: %s connector standard\n",
diff --git a/usr.sbin/fifolog/lib/Makefile b/usr.sbin/fifolog/lib/Makefile
index c10126f..fc8e6d2 100644
--- a/usr.sbin/fifolog/lib/Makefile
+++ b/usr.sbin/fifolog/lib/Makefile
@@ -8,4 +8,6 @@ SRCS+= getdate.y
CFLAGS+= -I${.CURDIR}
+NO_WMISSING_VARIABLE_DECLARATIONS=
+
.include <bsd.lib.mk>
diff --git a/usr.sbin/freebsd-update/freebsd-update.8 b/usr.sbin/freebsd-update/freebsd-update.8
index 472a5f7..f372587 100644
--- a/usr.sbin/freebsd-update/freebsd-update.8
+++ b/usr.sbin/freebsd-update/freebsd-update.8
@@ -162,11 +162,11 @@ purposes, make sure you boot from a secure disk (e.g., a CD).
.El
.Sh FILES
.Bl -tag -width "/etc/freebsd-update.conf"
-.It /etc/freebsd-update.conf
+.It Pa /etc/freebsd-update.conf
Default location of the
.Nm
configuration file.
-.It /var/db/freebsd-update/
+.It Pa /var/db/freebsd-update/
Default location where
.Nm
stores temporary files and downloaded updates.
diff --git a/usr.sbin/gssd/gssd.8 b/usr.sbin/gssd/gssd.8
index 73eb6e3..82c5317 100644
--- a/usr.sbin/gssd/gssd.8
+++ b/usr.sbin/gssd/gssd.8
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd December 30, 2012
+.Dd July 7, 2013
.Dt GSSD 8
.Os
.Sh NAME
@@ -34,6 +34,9 @@
.Sh SYNOPSIS
.Nm
.Op Fl d
+.Op Fl h
+.Op Fl o
+.Op Fl v
.Op Fl s Ar dir-list
.Op Fl c Ar file-substring
.Op Fl r Ar preferred-realm
@@ -49,6 +52,29 @@ Run in debug mode.
In this mode,
.Nm
will not fork when it starts.
+.It Fl h
+Enable support for host-based initiator credentials.
+This permits a kerberized NFS mount to use a service principal in
+the default Kerberos 5 keytab file for access.
+Such access is enabled via the
+gssname
+option for the
+.Xr mount_nfs 8
+command.
+.It Fl o
+Force use of DES and the associated old style GSS-API initialization token.
+This may be required to make kerberized NFS mounts work against some
+non-FreeBSD NFS servers.
+.It Fl v
+Run in verbose mode.
+In this mode,
+.Nm
+will log activity messages to syslog using LOG_INFO | LOG_DAEMON or to
+stderr, if the
+.Fl d
+option has also been specified.
+The minor status is logged as a decimal number, since it is actually a
+Kerberos return status, which is signed.
.It Fl s Ar dir-list
Look for an appropriate credential cache file in this list of directories.
The list should be full pathnames from root, separated by ':' characters.
@@ -79,7 +105,9 @@ by kernel GSS-API services.
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO
-.Xr gssapi 3
+.Xr gssapi 3 ,
+.Xr mount_nfs 8 ,
+.Xr syslog 3
.Sh HISTORY
The
.Nm
diff --git a/usr.sbin/gssd/gssd.c b/usr.sbin/gssd/gssd.c
index 9777943..9548b8c 100644
--- a/usr.sbin/gssd/gssd.c
+++ b/usr.sbin/gssd/gssd.c
@@ -37,10 +37,13 @@ __FBSDID("$FreeBSD$");
#include <ctype.h>
#include <dirent.h>
#include <err.h>
+#include <errno.h>
#ifndef WITHOUT_KERBEROS
#include <krb5.h>
#endif
#include <pwd.h>
+#include <signal.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -57,6 +60,7 @@ __FBSDID("$FreeBSD$");
#ifndef _PATH_GSSDSOCK
#define _PATH_GSSDSOCK "/var/run/gssd.sock"
#endif
+#define GSSD_CREDENTIAL_CACHE_FILE "/tmp/krb5cc_gssd"
struct gss_resource {
LIST_ENTRY(gss_resource) gr_link;
@@ -70,10 +74,30 @@ uint32_t gss_start_time;
int debug_level;
static char ccfile_dirlist[PATH_MAX + 1], ccfile_substring[NAME_MAX + 1];
static char pref_realm[1024];
+static int verbose;
+static int use_old_des;
+static int hostbased_initiator_cred;
+#ifndef WITHOUT_KERBEROS
+/* 1.2.752.43.13.14 */
+static gss_OID_desc gss_krb5_set_allowable_enctypes_x_desc =
+{6, (void *) "\x2a\x85\x70\x2b\x0d\x0e"};
+static gss_OID GSS_KRB5_SET_ALLOWABLE_ENCTYPES_X =
+ &gss_krb5_set_allowable_enctypes_x_desc;
+static gss_OID_desc gss_krb5_mech_oid_x_desc =
+{9, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02" };
+static gss_OID GSS_KRB5_MECH_OID_X =
+ &gss_krb5_mech_oid_x_desc;
+#endif
static void gssd_load_mech(void);
static int find_ccache_file(const char *, uid_t, char *);
static int is_a_valid_tgt_cache(const char *, uid_t, int *, time_t *);
+static void gssd_verbose_out(const char *, ...);
+#ifndef WITHOUT_KERBEROS
+static krb5_error_code gssd_get_cc_from_keytab(const char *);
+static OM_uint32 gssd_get_user_cred(OM_uint32 *, uid_t, gss_cred_id_t *);
+#endif
+void gssd_terminate(int);
extern void gssd_1(struct svc_req *rqstp, SVCXPRT *transp);
extern int gssd_syscall(char *path);
@@ -98,11 +122,38 @@ main(int argc, char **argv)
ccfile_dirlist[0] = '\0';
pref_realm[0] = '\0';
debug = 0;
- while ((ch = getopt(argc, argv, "ds:c:r:")) != -1) {
+ verbose = 0;
+ while ((ch = getopt(argc, argv, "dhovs:c:r:")) != -1) {
switch (ch) {
case 'd':
debug_level++;
break;
+ case 'h':
+#ifndef WITHOUT_KERBEROS
+ /*
+ * Enable use of a host based initiator credential
+ * in the default keytab file.
+ */
+ hostbased_initiator_cred = 1;
+#else
+ errx(1, "This option not available when built"
+ " without MK_KERBEROS\n");
+#endif
+ break;
+ case 'o':
+#ifndef WITHOUT_KERBEROS
+ /*
+ * Force use of DES and the old type of GSSAPI token.
+ */
+ use_old_des = 1;
+#else
+ errx(1, "This option not available when built"
+ " without MK_KERBEROS\n");
+#endif
+ break;
+ case 'v':
+ verbose = 1;
+ break;
case 's':
#ifndef WITHOUT_KERBEROS
/*
@@ -141,8 +192,13 @@ main(int argc, char **argv)
gssd_load_mech();
- if (!debug_level)
+ if (!debug_level) {
daemon(0, 0);
+ signal(SIGINT, SIG_IGN);
+ signal(SIGQUIT, SIG_IGN);
+ signal(SIGHUP, SIG_IGN);
+ }
+ signal(SIGTERM, gssd_terminate);
memset(&sun, 0, sizeof sun);
sun.sun_family = AF_LOCAL;
@@ -298,10 +354,26 @@ gssd_delete_resource(uint64_t id)
}
}
+static void
+gssd_verbose_out(const char *fmt, ...)
+{
+ va_list ap;
+
+ if (verbose != 0) {
+ va_start(ap, fmt);
+ if (debug_level == 0)
+ vsyslog(LOG_INFO | LOG_DAEMON, fmt, ap);
+ else
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ }
+}
+
bool_t
gssd_null_1_svc(void *argp, void *result, struct svc_req *rqstp)
{
+ gssd_verbose_out("gssd_null: done\n");
return (TRUE);
}
@@ -312,10 +384,27 @@ gssd_init_sec_context_1_svc(init_sec_context_args *argp, init_sec_context_res *r
gss_ctx_id_t ctx = GSS_C_NO_CONTEXT;
gss_name_t name = GSS_C_NO_NAME;
char ccname[PATH_MAX + 5 + 1], *cp, *cp2;
- int gotone;
+ int gotone, gotcred;
+ OM_uint32 min_stat;
+#ifndef WITHOUT_KERBEROS
+ gss_buffer_desc principal_desc;
+ char enctype[sizeof(uint32_t)];
+ int key_enctype;
+ OM_uint32 maj_stat;
+#endif
memset(result, 0, sizeof(*result));
- if (ccfile_dirlist[0] != '\0' && argp->cred == 0) {
+ if (hostbased_initiator_cred != 0 && argp->cred != 0 &&
+ argp->uid == 0) {
+ /*
+ * These credentials are for a host based initiator name
+ * in a keytab file, which should now have credentials
+ * in /tmp/krb5cc_gssd, because gss_acquire_cred() did
+ * the equivalent of "kinit -k".
+ */
+ snprintf(ccname, sizeof(ccname), "FILE:%s",
+ GSSD_CREDENTIAL_CACHE_FILE);
+ } else if (ccfile_dirlist[0] != '\0' && argp->cred == 0) {
/*
* For the "-s" case and no credentials provided as an
* argument, search the directory list for an appropriate
@@ -336,6 +425,9 @@ gssd_init_sec_context_1_svc(init_sec_context_args *argp, init_sec_context_res *r
} while (cp != NULL && *cp != '\0');
if (gotone == 0) {
result->major_status = GSS_S_CREDENTIALS_EXPIRED;
+ gssd_verbose_out("gssd_init_sec_context: -s no"
+ " credential cache file found for uid=%d\n",
+ (int)argp->uid);
return (TRUE);
}
} else {
@@ -361,6 +453,8 @@ gssd_init_sec_context_1_svc(init_sec_context_args *argp, init_sec_context_res *r
cred = gssd_find_resource(argp->cred);
if (!cred) {
result->major_status = GSS_S_CREDENTIALS_EXPIRED;
+ gssd_verbose_out("gssd_init_sec_context: cred"
+ " resource not found\n");
return (TRUE);
}
}
@@ -368,6 +462,8 @@ gssd_init_sec_context_1_svc(init_sec_context_args *argp, init_sec_context_res *r
ctx = gssd_find_resource(argp->ctx);
if (!ctx) {
result->major_status = GSS_S_CONTEXT_EXPIRED;
+ gssd_verbose_out("gssd_init_sec_context: context"
+ " resource not found\n");
return (TRUE);
}
}
@@ -375,15 +471,61 @@ gssd_init_sec_context_1_svc(init_sec_context_args *argp, init_sec_context_res *r
name = gssd_find_resource(argp->name);
if (!name) {
result->major_status = GSS_S_BAD_NAME;
+ gssd_verbose_out("gssd_init_sec_context: name"
+ " resource not found\n");
return (TRUE);
}
}
+ gotcred = 0;
+#ifndef WITHOUT_KERBEROS
+ if (use_old_des != 0) {
+ if (cred == GSS_C_NO_CREDENTIAL) {
+ /* Acquire a credential for the uid. */
+ maj_stat = gssd_get_user_cred(&min_stat, argp->uid,
+ &cred);
+ if (maj_stat == GSS_S_COMPLETE)
+ gotcred = 1;
+ else
+ gssd_verbose_out("gssd_init_sec_context: "
+ "get user cred failed uid=%d major=0x%x "
+ "minor=%d\n", (int)argp->uid,
+ (unsigned int)maj_stat, (int)min_stat);
+ }
+ if (cred != GSS_C_NO_CREDENTIAL) {
+ key_enctype = ETYPE_DES_CBC_CRC;
+ enctype[0] = (key_enctype >> 24) & 0xff;
+ enctype[1] = (key_enctype >> 16) & 0xff;
+ enctype[2] = (key_enctype >> 8) & 0xff;
+ enctype[3] = key_enctype & 0xff;
+ principal_desc.length = sizeof(enctype);
+ principal_desc.value = enctype;
+ result->major_status = gss_set_cred_option(
+ &result->minor_status, &cred,
+ GSS_KRB5_SET_ALLOWABLE_ENCTYPES_X,
+ &principal_desc);
+ gssd_verbose_out("gssd_init_sec_context: set allowable "
+ "enctype major=0x%x minor=%d\n",
+ (unsigned int)result->major_status,
+ (int)result->minor_status);
+ if (result->major_status != GSS_S_COMPLETE) {
+ if (gotcred != 0)
+ gss_release_cred(&min_stat, &cred);
+ return (TRUE);
+ }
+ }
+ }
+#endif
result->major_status = gss_init_sec_context(&result->minor_status,
cred, &ctx, name, argp->mech_type,
argp->req_flags, argp->time_req, argp->input_chan_bindings,
&argp->input_token, &result->actual_mech_type,
&result->output_token, &result->ret_flags, &result->time_rec);
+ gssd_verbose_out("gssd_init_sec_context: done major=0x%x minor=%d"
+ " uid=%d\n", (unsigned int)result->major_status,
+ (int)result->minor_status, (int)argp->uid);
+ if (gotcred != 0)
+ gss_release_cred(&min_stat, &cred);
if (result->major_status == GSS_S_COMPLETE
|| result->major_status == GSS_S_CONTINUE_NEEDED) {
@@ -409,6 +551,8 @@ gssd_accept_sec_context_1_svc(accept_sec_context_args *argp, accept_sec_context_
ctx = gssd_find_resource(argp->ctx);
if (!ctx) {
result->major_status = GSS_S_CONTEXT_EXPIRED;
+ gssd_verbose_out("gssd_accept_sec_context: ctx"
+ " resource not found\n");
return (TRUE);
}
}
@@ -416,6 +560,8 @@ gssd_accept_sec_context_1_svc(accept_sec_context_args *argp, accept_sec_context_
cred = gssd_find_resource(argp->cred);
if (!cred) {
result->major_status = GSS_S_CREDENTIALS_EXPIRED;
+ gssd_verbose_out("gssd_accept_sec_context: cred"
+ " resource not found\n");
return (TRUE);
}
}
@@ -426,6 +572,8 @@ gssd_accept_sec_context_1_svc(accept_sec_context_args *argp, accept_sec_context_
&src_name, &result->mech_type, &result->output_token,
&result->ret_flags, &result->time_rec,
&delegated_cred_handle);
+ gssd_verbose_out("gssd_accept_sec_context: done major=0x%x minor=%d\n",
+ (unsigned int)result->major_status, (int)result->minor_status);
if (result->major_status == GSS_S_COMPLETE
|| result->major_status == GSS_S_CONTINUE_NEEDED) {
@@ -454,6 +602,8 @@ gssd_delete_sec_context_1_svc(delete_sec_context_args *argp, delete_sec_context_
result->major_status = GSS_S_COMPLETE;
result->minor_status = 0;
}
+ gssd_verbose_out("gssd_delete_sec_context: done major=0x%x minor=%d\n",
+ (unsigned int)result->major_status, (int)result->minor_status);
return (TRUE);
}
@@ -475,6 +625,8 @@ gssd_export_sec_context_1_svc(export_sec_context_args *argp, export_sec_context_
result->interprocess_token.length = 0;
result->interprocess_token.value = NULL;
}
+ gssd_verbose_out("gssd_export_sec_context: done major=0x%x minor=%d\n",
+ (unsigned int)result->major_status, (int)result->minor_status);
return (TRUE);
}
@@ -486,6 +638,8 @@ gssd_import_name_1_svc(import_name_args *argp, import_name_res *result, struct s
result->major_status = gss_import_name(&result->minor_status,
&argp->input_name_buffer, argp->input_name_type, &name);
+ gssd_verbose_out("gssd_import_name: done major=0x%x minor=%d\n",
+ (unsigned int)result->major_status, (int)result->minor_status);
if (result->major_status == GSS_S_COMPLETE)
result->output_name = gssd_make_resource(name);
@@ -509,6 +663,8 @@ gssd_canonicalize_name_1_svc(canonicalize_name_args *argp, canonicalize_name_res
result->major_status = gss_canonicalize_name(&result->minor_status,
name, argp->mech_type, &output_name);
+ gssd_verbose_out("gssd_canonicalize_name: done major=0x%x minor=%d\n",
+ (unsigned int)result->major_status, (int)result->minor_status);
if (result->major_status == GSS_S_COMPLETE)
result->output_name = gssd_make_resource(output_name);
@@ -526,11 +682,14 @@ gssd_export_name_1_svc(export_name_args *argp, export_name_res *result, struct s
memset(result, 0, sizeof(*result));
if (!name) {
result->major_status = GSS_S_BAD_NAME;
+ gssd_verbose_out("gssd_export_name: name resource not found\n");
return (TRUE);
}
result->major_status = gss_export_name(&result->minor_status,
name, &result->exported_name);
+ gssd_verbose_out("gssd_export_name: done major=0x%x minor=%d\n",
+ (unsigned int)result->major_status, (int)result->minor_status);
return (TRUE);
}
@@ -548,6 +707,8 @@ gssd_release_name_1_svc(release_name_args *argp, release_name_res *result, struc
result->major_status = GSS_S_COMPLETE;
result->minor_status = 0;
}
+ gssd_verbose_out("gssd_release_name: done major=0x%x minor=%d\n",
+ (unsigned int)result->major_status, (int)result->minor_status);
return (TRUE);
}
@@ -557,8 +718,11 @@ gssd_pname_to_uid_1_svc(pname_to_uid_args *argp, pname_to_uid_res *result, struc
{
gss_name_t name = gssd_find_resource(argp->pname);
uid_t uid;
- char buf[128];
+ char buf[1024], *bufp;
struct passwd pwd, *pw;
+ size_t buflen;
+ int error;
+ static size_t buflen_hint = 1024;
memset(result, 0, sizeof(*result));
if (name) {
@@ -567,7 +731,24 @@ gssd_pname_to_uid_1_svc(pname_to_uid_args *argp, pname_to_uid_res *result, struc
name, argp->mech, &uid);
if (result->major_status == GSS_S_COMPLETE) {
result->uid = uid;
- getpwuid_r(uid, &pwd, buf, sizeof(buf), &pw);
+ buflen = buflen_hint;
+ for (;;) {
+ pw = NULL;
+ bufp = buf;
+ if (buflen > sizeof(buf))
+ bufp = malloc(buflen);
+ if (bufp == NULL)
+ break;
+ error = getpwuid_r(uid, &pwd, bufp, buflen,
+ &pw);
+ if (error != ERANGE)
+ break;
+ if (buflen > sizeof(buf))
+ free(bufp);
+ buflen += 1024;
+ if (buflen > buflen_hint)
+ buflen_hint = buflen;
+ }
if (pw) {
int len = NGRPS;
int groups[NGRPS];
@@ -579,15 +760,27 @@ gssd_pname_to_uid_1_svc(pname_to_uid_args *argp, pname_to_uid_res *result, struc
mem_alloc(len * sizeof(int));
memcpy(result->gidlist.gidlist_val, groups,
len * sizeof(int));
+ gssd_verbose_out("gssd_pname_to_uid: mapped"
+ " to uid=%d, gid=%d\n", (int)result->uid,
+ (int)result->gid);
} else {
result->gid = 65534;
result->gidlist.gidlist_len = 0;
result->gidlist.gidlist_val = NULL;
+ gssd_verbose_out("gssd_pname_to_uid: mapped"
+ " to uid=%d, but no groups\n",
+ (int)result->uid);
}
- }
+ if (bufp != NULL && buflen > sizeof(buf))
+ free(bufp);
+ } else
+ gssd_verbose_out("gssd_pname_to_uid: failed major=0x%x"
+ " minor=%d\n", (unsigned int)result->major_status,
+ (int)result->minor_status);
} else {
result->major_status = GSS_S_BAD_NAME;
result->minor_status = 0;
+ gssd_verbose_out("gssd_pname_to_uid: no name\n");
}
return (TRUE);
@@ -600,8 +793,58 @@ gssd_acquire_cred_1_svc(acquire_cred_args *argp, acquire_cred_res *result, struc
gss_cred_id_t cred;
char ccname[PATH_MAX + 5 + 1], *cp, *cp2;
int gotone;
+#ifndef WITHOUT_KERBEROS
+ gss_buffer_desc namebuf;
+ uint32_t minstat;
+ krb5_error_code kret;
+#endif
memset(result, 0, sizeof(*result));
+ if (argp->desired_name) {
+ desired_name = gssd_find_resource(argp->desired_name);
+ if (!desired_name) {
+ result->major_status = GSS_S_BAD_NAME;
+ gssd_verbose_out("gssd_acquire_cred: no desired name"
+ " found\n");
+ return (TRUE);
+ }
+ }
+
+#ifndef WITHOUT_KERBEROS
+ if (hostbased_initiator_cred != 0 && argp->desired_name != 0 &&
+ argp->uid == 0 && argp->cred_usage == GSS_C_INITIATE) {
+ /* This is a host based initiator name in the keytab file. */
+ snprintf(ccname, sizeof(ccname), "FILE:%s",
+ GSSD_CREDENTIAL_CACHE_FILE);
+ setenv("KRB5CCNAME", ccname, TRUE);
+ result->major_status = gss_display_name(&result->minor_status,
+ desired_name, &namebuf, NULL);
+ gssd_verbose_out("gssd_acquire_cred: desired name for host "
+ "based initiator cred major=0x%x minor=%d\n",
+ (unsigned int)result->major_status,
+ (int)result->minor_status);
+ if (result->major_status != GSS_S_COMPLETE)
+ return (TRUE);
+ if (namebuf.length > PATH_MAX + 5) {
+ result->minor_status = 0;
+ result->major_status = GSS_S_FAILURE;
+ return (TRUE);
+ }
+ memcpy(ccname, namebuf.value, namebuf.length);
+ ccname[namebuf.length] = '\0';
+ if ((cp = strchr(ccname, '@')) != NULL)
+ *cp = '/';
+ kret = gssd_get_cc_from_keytab(ccname);
+ gssd_verbose_out("gssd_acquire_cred: using keytab entry for "
+ "%s, kerberos ret=%d\n", ccname, (int)kret);
+ gss_release_buffer(&minstat, &namebuf);
+ if (kret != 0) {
+ result->minor_status = kret;
+ result->major_status = GSS_S_FAILURE;
+ return (TRUE);
+ }
+ } else
+#endif /* !WITHOUT_KERBEROS */
if (ccfile_dirlist[0] != '\0' && argp->desired_name == 0) {
/*
* For the "-s" case and no name provided as an
@@ -623,8 +866,11 @@ gssd_acquire_cred_1_svc(acquire_cred_args *argp, acquire_cred_res *result, struc
} while (cp != NULL && *cp != '\0');
if (gotone == 0) {
result->major_status = GSS_S_CREDENTIALS_EXPIRED;
+ gssd_verbose_out("gssd_acquire_cred: no cred cache"
+ " file found\n");
return (TRUE);
}
+ setenv("KRB5CCNAME", ccname, TRUE);
} else {
/*
* If there wasn't a "-s" option or the name has
@@ -642,20 +888,14 @@ gssd_acquire_cred_1_svc(acquire_cred_args *argp, acquire_cred_res *result, struc
}
snprintf(ccname, sizeof(ccname), "FILE:/tmp/krb5cc_%d",
(int) argp->uid);
- }
- setenv("KRB5CCNAME", ccname, TRUE);
-
- if (argp->desired_name) {
- desired_name = gssd_find_resource(argp->desired_name);
- if (!desired_name) {
- result->major_status = GSS_S_BAD_NAME;
- return (TRUE);
- }
+ setenv("KRB5CCNAME", ccname, TRUE);
}
result->major_status = gss_acquire_cred(&result->minor_status,
desired_name, argp->time_req, argp->desired_mechs,
argp->cred_usage, &cred, &result->actual_mechs, &result->time_rec);
+ gssd_verbose_out("gssd_acquire_cred: done major=0x%x minor=%d\n",
+ (unsigned int)result->major_status, (int)result->minor_status);
if (result->major_status == GSS_S_COMPLETE)
result->output_cred = gssd_make_resource(cred);
@@ -673,11 +913,14 @@ gssd_set_cred_option_1_svc(set_cred_option_args *argp, set_cred_option_res *resu
memset(result, 0, sizeof(*result));
if (!cred) {
result->major_status = GSS_S_CREDENTIALS_EXPIRED;
+ gssd_verbose_out("gssd_set_cred: no credentials\n");
return (TRUE);
}
result->major_status = gss_set_cred_option(&result->minor_status,
&cred, argp->option_name, &argp->option_value);
+ gssd_verbose_out("gssd_set_cred: done major=0x%x minor=%d\n",
+ (unsigned int)result->major_status, (int)result->minor_status);
return (TRUE);
}
@@ -695,6 +938,8 @@ gssd_release_cred_1_svc(release_cred_args *argp, release_cred_res *result, struc
result->major_status = GSS_S_COMPLETE;
result->minor_status = 0;
}
+ gssd_verbose_out("gssd_release_cred: done major=0x%x minor=%d\n",
+ (unsigned int)result->major_status, (int)result->minor_status);
return (TRUE);
}
@@ -707,6 +952,8 @@ gssd_display_status_1_svc(display_status_args *argp, display_status_res *result,
result->major_status = gss_display_status(&result->minor_status,
argp->status_value, argp->status_type, argp->mech_type,
&result->message_context, &result->status_string);
+ gssd_verbose_out("gssd_display_status: done major=0x%x minor=%d\n",
+ (unsigned int)result->major_status, (int)result->minor_status);
return (TRUE);
}
@@ -780,6 +1027,8 @@ find_ccache_file(const char *dirpath, uid_t uid, char *rpath)
len = snprintf(namepath, sizeof(namepath), "%s/%s", dirpath,
dp->d_name);
if (len < sizeof(namepath) &&
+ (hostbased_initiator_cred == 0 || strcmp(namepath,
+ GSSD_CREDENTIAL_CACHE_FILE) != 0) &&
strstr(dp->d_name, ccfile_substring) != NULL &&
lstat(namepath, &sb) >= 0 &&
sb.st_uid == uid &&
@@ -926,3 +1175,115 @@ is_a_valid_tgt_cache(const char *filepath, uid_t uid, int *retrating,
#endif /* !WITHOUT_KERBEROS */
}
+#ifndef WITHOUT_KERBEROS
+/*
+ * This function attempts to do essentially a "kinit -k" for the principal
+ * name provided as the argument, so that there will be a TGT in the
+ * credential cache.
+ */
+static krb5_error_code
+gssd_get_cc_from_keytab(const char *name)
+{
+ krb5_error_code ret, opt_ret, princ_ret, cc_ret, kt_ret, cred_ret;
+ krb5_context context;
+ krb5_principal principal;
+ krb5_keytab kt;
+ krb5_creds cred;
+ krb5_get_init_creds_opt *opt;
+ krb5_deltat start_time = 0;
+ krb5_ccache ccache;
+
+ ret = krb5_init_context(&context);
+ if (ret != 0)
+ return (ret);
+ opt_ret = cc_ret = kt_ret = cred_ret = 1; /* anything non-zero */
+ princ_ret = ret = krb5_parse_name(context, name, &principal);
+ if (ret == 0)
+ opt_ret = ret = krb5_get_init_creds_opt_alloc(context, &opt);
+ if (ret == 0)
+ cc_ret = ret = krb5_cc_default(context, &ccache);
+ if (ret == 0)
+ ret = krb5_cc_initialize(context, ccache, principal);
+ if (ret == 0) {
+ krb5_get_init_creds_opt_set_default_flags(context, "gssd",
+ krb5_principal_get_realm(context, principal), opt);
+ kt_ret = ret = krb5_kt_default(context, &kt);
+ }
+ if (ret == 0)
+ cred_ret = ret = krb5_get_init_creds_keytab(context, &cred,
+ principal, kt, start_time, NULL, opt);
+ if (ret == 0)
+ ret = krb5_cc_store_cred(context, ccache, &cred);
+ if (kt_ret == 0)
+ krb5_kt_close(context, kt);
+ if (cc_ret == 0)
+ krb5_cc_close(context, ccache);
+ if (opt_ret == 0)
+ krb5_get_init_creds_opt_free(context, opt);
+ if (princ_ret == 0)
+ krb5_free_principal(context, principal);
+ if (cred_ret == 0)
+ krb5_free_cred_contents(context, &cred);
+ krb5_free_context(context);
+ return (ret);
+}
+
+/*
+ * Acquire a gss credential for a uid.
+ */
+static OM_uint32
+gssd_get_user_cred(OM_uint32 *min_statp, uid_t uid, gss_cred_id_t *credp)
+{
+ gss_buffer_desc principal_desc;
+ gss_name_t name;
+ OM_uint32 maj_stat, min_stat;
+ gss_OID_set mechlist;
+ struct passwd *pw;
+
+ pw = getpwuid(uid);
+ if (pw == NULL) {
+ *min_statp = 0;
+ return (GSS_S_FAILURE);
+ }
+
+ /*
+ * The mechanism must be set to KerberosV for acquisition
+ * of credentials to work reliably.
+ */
+ maj_stat = gss_create_empty_oid_set(min_statp, &mechlist);
+ if (maj_stat != GSS_S_COMPLETE)
+ return (maj_stat);
+ maj_stat = gss_add_oid_set_member(min_statp, GSS_KRB5_MECH_OID_X,
+ &mechlist);
+ if (maj_stat != GSS_S_COMPLETE) {
+ gss_release_oid_set(&min_stat, &mechlist);
+ return (maj_stat);
+ }
+
+ principal_desc.value = (void *)pw->pw_name;
+ principal_desc.length = strlen(pw->pw_name);
+ maj_stat = gss_import_name(min_statp, &principal_desc,
+ GSS_C_NT_USER_NAME, &name);
+ if (maj_stat != GSS_S_COMPLETE) {
+ gss_release_oid_set(&min_stat, &mechlist);
+ return (maj_stat);
+ }
+ /* Acquire the credentials. */
+ maj_stat = gss_acquire_cred(min_statp, name, 0, mechlist,
+ GSS_C_INITIATE, credp, NULL, NULL);
+ gss_release_name(&min_stat, &name);
+ gss_release_oid_set(&min_stat, &mechlist);
+ return (maj_stat);
+}
+#endif /* !WITHOUT_KERBEROS */
+
+void gssd_terminate(int sig __unused)
+{
+
+#ifndef WITHOUT_KERBEROS
+ if (hostbased_initiator_cred != 0)
+ unlink(GSSD_CREDENTIAL_CACHE_FILE);
+#endif
+ exit(0);
+}
+
diff --git a/usr.sbin/jail/Makefile b/usr.sbin/jail/Makefile
index 00d7ff5..fb36def 100644
--- a/usr.sbin/jail/Makefile
+++ b/usr.sbin/jail/Makefile
@@ -9,6 +9,8 @@ SRCS= jail.c command.c config.c state.c jailp.h jaillex.l jailparse.y y.tab.h
DPADD= ${LIBJAIL} ${LIBKVM} ${LIBUTIL} ${LIBL}
LDADD= -ljail -lkvm -lutil -ll
+NO_WMISSING_VARIABLE_DECLARATIONS=
+
YFLAGS+=-v
CFLAGS+=-I. -I${.CURDIR}
diff --git a/usr.sbin/jail/jail.8 b/usr.sbin/jail/jail.8
index b96cfef..88d69f9 100644
--- a/usr.sbin/jail/jail.8
+++ b/usr.sbin/jail/jail.8
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd September 15, 2012
+.Dd August 23, 2013
.Dt JAIL 8
.Os
.Sh NAME
@@ -545,6 +545,14 @@ This permission is effective only together with
and if
.Va enforce_statfs
is set to a value lower than 2.
+.It Va allow.mount.tmpfs
+privileged users inside the jail will be able to mount and unmount the
+tmpfs file system.
+This permission is effective only together with
+.Va allow.mount
+and if
+.Va enforce_statfs
+is set to a value lower than 2.
.It Va allow.mount.zfs
privileged users inside the jail will be able to mount and unmount the
ZFS file system.
diff --git a/usr.sbin/jail/jaillex.l b/usr.sbin/jail/jaillex.l
index 0a2fcd7..04de85f 100644
--- a/usr.sbin/jail/jaillex.l
+++ b/usr.sbin/jail/jaillex.l
@@ -36,17 +36,19 @@ __FBSDID("$FreeBSD$");
#include "jailp.h"
#include "y.tab.h"
-#define YY_NO_INPUT
-#define YY_NO_UNPUT
-
extern int yynerrs;
static ssize_t text2lval(size_t triml, size_t trimr, int tovar);
static int instr;
static int lineno = 1;
+
+#define YY_DECL int yylex(void)
%}
+%option noinput
+%option nounput
+
%start _ DQ
%%
diff --git a/usr.sbin/jls/jls.8 b/usr.sbin/jls/jls.8
index 2107405..3137654 100644
--- a/usr.sbin/jls/jls.8
+++ b/usr.sbin/jls/jls.8
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 8, 2009
+.Dd July 20, 2012
.Dt JLS 8
.Os
.Sh NAME
@@ -33,7 +33,7 @@
.Nd "list jails"
.Sh SYNOPSIS
.Nm
-.Op Fl dhnqsv
+.Op Fl dhNnqsv
.Op Fl j Ar jail
.Op Ar parameter ...
.Sh DESCRIPTION
@@ -71,6 +71,10 @@ Print a header line containing the parameters listed.
If no parameters are given on the command line,
.Va all
is assumed.
+.It Fl N
+In the standard display mode, print each jail's name instead of its
+numeric ID.
+If the jail does not have a name, the numeric ID is printed instead.
.It Fl n
Print parameters in
.Dq name=value
diff --git a/usr.sbin/jls/jls.c b/usr.sbin/jls/jls.c
index f16972c..ce07100 100644
--- a/usr.sbin/jls/jls.c
+++ b/usr.sbin/jls/jls.c
@@ -55,6 +55,7 @@ __FBSDID("$FreeBSD$");
#define PRINT_QUOTED 0x08
#define PRINT_SKIP 0x10
#define PRINT_VERBOSE 0x20
+#define PRINT_JAIL_NAME 0x40
static struct jailparam *params;
static int *param_parent;
@@ -82,7 +83,7 @@ main(int argc, char **argv)
jname = NULL;
pflags = jflags = jid = 0;
- while ((c = getopt(argc, argv, "adj:hnqsv")) >= 0)
+ while ((c = getopt(argc, argv, "adj:hNnqsv")) >= 0)
switch (c) {
case 'a':
case 'd':
@@ -99,6 +100,9 @@ main(int argc, char **argv)
pflags = (pflags & ~(PRINT_SKIP | PRINT_VERBOSE)) |
PRINT_HEADER;
break;
+ case 'N':
+ pflags |= PRINT_JAIL_NAME;
+ break;
case 'n':
pflags = (pflags & ~PRINT_VERBOSE) | PRINT_NAMEVAL;
break;
@@ -115,7 +119,7 @@ main(int argc, char **argv)
PRINT_VERBOSE;
break;
default:
- errx(1, "usage: jls [-dhnqv] [-j jail] [param ...]");
+ errx(1, "usage: jls [-dhNnqv] [-j jail] [param ...]");
}
#ifdef INET6
@@ -149,7 +153,10 @@ main(int argc, char **argv)
#endif
} else {
pflags |= PRINT_DEFAULT;
- add_param("jid", NULL, (size_t)0, NULL, JP_USER);
+ if (pflags & PRINT_JAIL_NAME)
+ add_param("name", NULL, (size_t)0, NULL, JP_USER);
+ else
+ add_param("jid", NULL, (size_t)0, NULL, JP_USER);
#ifdef INET
if (ip4_ok)
add_param("ip4.addr", NULL, (size_t)0, NULL,
@@ -192,8 +199,12 @@ main(int argc, char **argv)
" CPUSetID\n"
" IP Address(es)\n");
else if (pflags & PRINT_DEFAULT)
- printf(" JID IP Address "
- "Hostname Path\n");
+ if (pflags & PRINT_JAIL_NAME)
+ printf(" JID IP Address "
+ "Hostname Path\n");
+ else
+ printf(" JID IP Address "
+ "Hostname Path\n");
else if (pflags & PRINT_HEADER) {
for (i = spc = 0; i < nparams; i++)
if (params[i].jp_flags & JP_USER) {
@@ -397,9 +408,12 @@ print_jail(int pflags, int jflags)
n++;
}
#endif
- } else if (pflags & PRINT_DEFAULT)
- printf("%6d %-15.15s %-29.29s %.74s\n",
- *(int *)params[0].jp_value,
+ } else if (pflags & PRINT_DEFAULT) {
+ if (pflags & PRINT_JAIL_NAME)
+ printf(" %-15s ", (char *)params[0].jp_value);
+ else
+ printf("%6d ", *(int *)params[0].jp_value);
+ printf("%-15.15s %-29.29s %.74s\n",
#ifdef INET
(!ip4_ok || params[1].jp_valuelen == 0) ? "-"
: inet_ntoa(*(struct in_addr *)params[1].jp_value),
@@ -410,7 +424,7 @@ print_jail(int pflags, int jflags)
(char *)params[1].jp_value,
(char *)params[2].jp_value);
#endif
- else {
+ } else {
param_values = alloca(nparams * sizeof(*param_values));
for (i = 0; i < nparams; i++) {
if (!(params[i].jp_flags & JP_USER))
diff --git a/usr.sbin/kbdcontrol/lex.l b/usr.sbin/kbdcontrol/lex.l
index ea165ef..d4c6508 100644
--- a/usr.sbin/kbdcontrol/lex.l
+++ b/usr.sbin/kbdcontrol/lex.l
@@ -31,11 +31,12 @@
%{
#include "lex.h"
-#define YY_NO_UNPUT
-#define YY_NO_INPUT
%}
+%option nounput
+%option noinput
+
D [0-9]
X [0-9a-fA-F]
A .
diff --git a/usr.sbin/kldxref/ef.c b/usr.sbin/kldxref/ef.c
index b1b00cc..b683898 100644
--- a/usr.sbin/kldxref/ef.c
+++ b/usr.sbin/kldxref/ef.c
@@ -42,7 +42,6 @@
#include <fcntl.h>
#include <machine/elf.h>
#define FREEBSD_ELF
-#include <link.h>
#include <err.h>
diff --git a/usr.sbin/kldxref/ef_amd64.c b/usr.sbin/kldxref/ef_amd64.c
index 5a1d192..b90882d 100644
--- a/usr.sbin/kldxref/ef_amd64.c
+++ b/usr.sbin/kldxref/ef_amd64.c
@@ -32,7 +32,6 @@
#include <err.h>
#include <errno.h>
-#include <string.h>
#include "ef.h"
diff --git a/usr.sbin/kldxref/ef_i386.c b/usr.sbin/kldxref/ef_i386.c
index 9b10c7d..b953f4a 100644
--- a/usr.sbin/kldxref/ef_i386.c
+++ b/usr.sbin/kldxref/ef_i386.c
@@ -32,7 +32,6 @@
#include <err.h>
#include <errno.h>
-#include <string.h>
#include "ef.h"
diff --git a/usr.sbin/kldxref/ef_obj.c b/usr.sbin/kldxref/ef_obj.c
index 5a4ae22..e6099f2 100644
--- a/usr.sbin/kldxref/ef_obj.c
+++ b/usr.sbin/kldxref/ef_obj.c
@@ -44,7 +44,6 @@
#include <fcntl.h>
#include <machine/elf.h>
#define FREEBSD_ELF
-#include <link.h>
#include <err.h>
@@ -344,7 +343,7 @@ ef_obj_open(const char *filename, struct elf_file *efile, int verbose)
if ((fd = open(filename, O_RDONLY)) == -1)
return errno;
- ef = malloc(sizeof(*ef));
+ ef = calloc(1, sizeof(*ef));
if (ef == NULL) {
close(fd);
return (ENOMEM);
@@ -353,7 +352,6 @@ ef_obj_open(const char *filename, struct elf_file *efile, int verbose)
efile->ef_ef = ef;
efile->ef_ops = &ef_obj_file_ops;
- bzero(ef, sizeof(*ef));
ef->ef_verbose = verbose;
ef->ef_fd = fd;
ef->ef_name = strdup(filename);
diff --git a/usr.sbin/kldxref/kldxref.c b/usr.sbin/kldxref/kldxref.c
index b4de191..16b9058 100644
--- a/usr.sbin/kldxref/kldxref.c
+++ b/usr.sbin/kldxref/kldxref.c
@@ -42,7 +42,6 @@
#include <sys/stat.h>
#include <sys/module.h>
#define FREEBSD_ELF
-#include <link.h>
#include <err.h>
#include <fts.h>
#include <string.h>
diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c
index 93657d9..52d6c9f 100644
--- a/usr.sbin/lpr/common_source/common.c
+++ b/usr.sbin/lpr/common_source/common.c
@@ -757,16 +757,22 @@ fatal(const struct printer *pp, const char *msg, ...)
/*
* Close all file descriptors from START on up.
- * This is a horrific kluge, since getdtablesize() might return
- * ``infinity'', in which case we will be spending a long time
- * closing ``files'' which were never open. Perhaps it would
- * be better to close the first N fds, for some small value of N.
*/
void
closeallfds(int start)
{
- int stop = getdtablesize();
- for (; start < stop; start++)
- close(start);
+ int stop;
+
+ if (USE_CLOSEFROM) /* The faster, modern solution */
+ closefrom(start);
+ else {
+ /* This older logic can be pretty awful on some OS's. The
+ * getdtablesize() might return ``infinity'', and then this
+ * will waste a lot of time closing file descriptors which
+ * had never been open()-ed. */
+ stop = getdtablesize();
+ for (; start < stop; start++)
+ close(start);
+ }
}
diff --git a/usr.sbin/lpr/common_source/lp.cdefs.h b/usr.sbin/lpr/common_source/lp.cdefs.h
index 19b1331..5806f39 100644
--- a/usr.sbin/lpr/common_source/lp.cdefs.h
+++ b/usr.sbin/lpr/common_source/lp.cdefs.h
@@ -1,6 +1,6 @@
/*-
* ------+---------+---------+---------+---------+---------+---------+---------*
- * Copyright (c) 2003 - Garance Alistair Drosehn <gad@FreeBSD.org>.
+ * Copyright (c) 2003,2013 - Garance Alistair Drosehn <gad@FreeBSD.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,6 +56,21 @@
#endif
/*
+ * FreeBSD added a closefrom() routine in release 8.0. When compiling
+ * `lpr' on other platforms you might want to include bsd-closefrom.c
+ * from the portable-openssh project.
+ */
+#ifndef USE_CLOSEFROM
+# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# define USE_CLOSEFROM 1
+# endif
+#endif
+/* The macro USE_CLOSEFROM must be defined with a value of 0 or 1. */
+#ifndef USE_CLOSEFROM
+# define USE_CLOSEFROM 0
+#endif
+
+/*
* __unused is a compiler-specific trick which can be used to avoid
* warnings about a variable which is defined but never referenced.
* Some lpr files use this, so define a null version if it was not
diff --git a/usr.sbin/makefs/Makefile b/usr.sbin/makefs/Makefile
index 6fa0679..6253148 100644
--- a/usr.sbin/makefs/Makefile
+++ b/usr.sbin/makefs/Makefile
@@ -5,7 +5,6 @@ PROG= makefs
CFLAGS+=-I${.CURDIR}
SRCS= cd9660.c ffs.c \
- getid.c \
makefs.c \
mtree.c \
walk.c
@@ -15,19 +14,28 @@ WARNS?= 2
.include "${.CURDIR}/cd9660/Makefile.inc"
.include "${.CURDIR}/ffs/Makefile.inc"
-.include "${.CURDIR}/compat/Makefile.inc"
CFLAGS+=-DHAVE_STRUCT_STAT_ST_FLAGS=1
CFLAGS+=-DHAVE_STRUCT_STAT_ST_GEN=1
-.PATH: ${.CURDIR}/../mtree
-CFLAGS+=-I${.CURDIR}/../mtree
-SRCS+= misc.c spec.c
+.PATH: ${.CURDIR}/../../contrib/mtree
+CFLAGS+=-I${.CURDIR}/../../contrib/mtree
+SRCS+= getid.c misc.c spec.c
+
+.PATH: ${.CURDIR}/../../contrib/mknod
+CFLAGS+=-I${.CURDIR}/../../contrib/mknod
+SRCS+= pack_dev.c
.PATH: ${.CURDIR}/../../sys/ufs/ffs
SRCS+= ffs_tables.c
-DPADD= ${LIBSBUF}
-LDADD= -lsbuf
+CFLAGS+= -I${.CURDIR}/../../lib/libnetbsd
+LIBNETBSDDIR= ${.OBJDIR}/../../lib/libnetbsd
+LIBNETBSD= ${LIBNETBSDDIR}/libnetbsd.a
+DPADD+= ${LIBNETBSD}
+LDADD+= ${LIBNETBSD}
+
+DPADD+= ${LIBSBUF} ${LIBUTIL}
+LDADD+= -lsbuf -lutil
.include <bsd.prog.mk>
diff --git a/usr.sbin/makefs/cd9660.c b/usr.sbin/makefs/cd9660.c
index 2b33446..f0e2f38 100644
--- a/usr.sbin/makefs/cd9660.c
+++ b/usr.sbin/makefs/cd9660.c
@@ -230,7 +230,7 @@ cd9660_set_defaults(void)
memset(diskStructure.primaryDescriptor.abstract_file_id, 0x20,37);
memset(diskStructure.primaryDescriptor.bibliographic_file_id, 0x20,37);
- strcpy(diskStructure.primaryDescriptor.system_id,"NetBSD");
+ strcpy(diskStructure.primaryDescriptor.system_id, "FreeBSD");
cd9660_defaults_set = 1;
@@ -681,7 +681,8 @@ cd9660_finalize_PVD(void)
cd9660_set_date(diskStructure.primaryDescriptor.expiration_date, now);
*/
- memset(diskStructure.primaryDescriptor.expiration_date, '0' ,17);
+ memset(diskStructure.primaryDescriptor.expiration_date, '0', 16);
+ diskStructure.primaryDescriptor.expiration_date[16] = 0;
cd9660_time_8426(
(unsigned char *)diskStructure.primaryDescriptor.effective_date,
tim);
diff --git a/usr.sbin/makefs/cd9660/iso9660_rrip.c b/usr.sbin/makefs/cd9660/iso9660_rrip.c
index 39e0acf..40acf40 100644
--- a/usr.sbin/makefs/cd9660/iso9660_rrip.c
+++ b/usr.sbin/makefs/cd9660/iso9660_rrip.c
@@ -1,4 +1,4 @@
-/* $NetBSD: iso9660_rrip.c,v 1.10 2011/05/29 17:07:58 tsutsui Exp $ */
+/* $NetBSD: iso9660_rrip.c,v 1.11 2012/04/29 13:32:21 joerg Exp $ */
/*
* Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
@@ -419,9 +419,9 @@ cd9660_rrip_initialize_node(cd9660node *node, cd9660node *parent,
}
else if ((node->node != NULL) &&
((strlen(node->node->name) !=
- (int)node->isoDirRecord->name_len[0]) ||
+ (uint8_t)node->isoDirRecord->name_len[0]) ||
(memcmp(node->node->name,node->isoDirRecord->name,
- (int) node->isoDirRecord->name_len[0]) != 0))) {
+ (uint8_t)node->isoDirRecord->name_len[0]) != 0))) {
cd9660_rrip_NM(node);
}
@@ -685,7 +685,7 @@ int
cd9660node_rrip_tf(struct ISO_SUSP_ATTRIBUTES *p, fsnode *_node)
{
p->attr.rr_entry.TF.flags[0] = TF_MODIFY | TF_ACCESS | TF_ATTRIBUTES;
- p->attr.rr_entry.TF.h.length[0] = 4;
+ p->attr.rr_entry.TF.h.length[0] = 5;
p->attr.rr_entry.TF.h.version[0] = 1;
/*
diff --git a/usr.sbin/makefs/compat/Makefile.inc b/usr.sbin/makefs/compat/Makefile.inc
deleted file mode 100644
index 5fdffa1..0000000
--- a/usr.sbin/makefs/compat/Makefile.inc
+++ /dev/null
@@ -1,8 +0,0 @@
-# $FreeBSD$
-#
-
-.PATH: ${.CURDIR}/compat
-
-CFLAGS+= -I${.CURDIR}/compat
-
-SRCS+= pwcache.c strsuftoll.c
diff --git a/usr.sbin/makefs/compat/pwcache.c b/usr.sbin/makefs/compat/pwcache.c
deleted file mode 100644
index d0c45c2..0000000
--- a/usr.sbin/makefs/compat/pwcache.c
+++ /dev/null
@@ -1,616 +0,0 @@
-/* $NetBSD: pwcache.c,v 1.29 2004/06/20 22:20:14 jmc Exp $ */
-
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-/*-
- * Copyright (c) 2002 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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/param.h>
-
-#include <assert.h>
-#include <grp.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef __weak_alias
-__weak_alias(user_from_uid,_user_from_uid)
-__weak_alias(group_from_gid,_group_from_gid)
-__weak_alias(pwcache_userdb,_pwcache_userdb)
-__weak_alias(pwcache_groupdb,_pwcache_groupdb)
-#endif
-
-#include "pwcache.h"
-
-/*
- * routines that control user, group, uid and gid caches (for the archive
- * member print routine).
- * IMPORTANT:
- * these routines cache BOTH hits and misses, a major performance improvement
- */
-
-/*
- * function pointers to various name lookup routines.
- * these may be changed as necessary.
- */
-static int (*_pwcache_setgroupent)(int) = setgroupent;
-static void (*_pwcache_endgrent)(void) = endgrent;
-static struct group * (*_pwcache_getgrnam)(const char *) = getgrnam;
-static struct group * (*_pwcache_getgrgid)(gid_t) = getgrgid;
-static int (*_pwcache_setpassent)(int) = setpassent;
-static void (*_pwcache_endpwent)(void) = endpwent;
-static struct passwd * (*_pwcache_getpwnam)(const char *) = getpwnam;
-static struct passwd * (*_pwcache_getpwuid)(uid_t) = getpwuid;
-
-/*
- * internal state
- */
-static int pwopn; /* is password file open */
-static int gropn; /* is group file open */
-static UIDC **uidtb; /* uid to name cache */
-static GIDC **gidtb; /* gid to name cache */
-static UIDC **usrtb; /* user name to uid cache */
-static GIDC **grptb; /* group name to gid cache */
-
-static int uidtb_fail; /* uidtb_start() failed ? */
-static int gidtb_fail; /* gidtb_start() failed ? */
-static int usrtb_fail; /* usrtb_start() failed ? */
-static int grptb_fail; /* grptb_start() failed ? */
-
-
-static u_int st_hash(const char *, size_t, int);
-static int uidtb_start(void);
-static int gidtb_start(void);
-static int usrtb_start(void);
-static int grptb_start(void);
-
-
-static u_int
-st_hash(const char *name, size_t len, int tabsz)
-{
- u_int key = 0;
-
- while (len--) {
- key += *name++;
- key = (key << 8) | (key >> 24);
- }
-
- return (key % tabsz);
-}
-
-/*
- * uidtb_start
- * creates an an empty uidtb
- * Return:
- * 0 if ok, -1 otherwise
- */
-static int
-uidtb_start(void)
-{
-
- if (uidtb != NULL)
- return (0);
- if (uidtb_fail)
- return (-1);
- if ((uidtb = (UIDC **)calloc(UID_SZ, sizeof(UIDC *))) == NULL) {
- ++uidtb_fail;
- return (-1);
- }
- return (0);
-}
-
-/*
- * gidtb_start
- * creates an an empty gidtb
- * Return:
- * 0 if ok, -1 otherwise
- */
-static int
-gidtb_start(void)
-{
-
- if (gidtb != NULL)
- return (0);
- if (gidtb_fail)
- return (-1);
- if ((gidtb = (GIDC **)calloc(GID_SZ, sizeof(GIDC *))) == NULL) {
- ++gidtb_fail;
- return (-1);
- }
- return (0);
-}
-
-/*
- * usrtb_start
- * creates an an empty usrtb
- * Return:
- * 0 if ok, -1 otherwise
- */
-static int
-usrtb_start(void)
-{
-
- if (usrtb != NULL)
- return (0);
- if (usrtb_fail)
- return (-1);
- if ((usrtb = (UIDC **)calloc(UNM_SZ, sizeof(UIDC *))) == NULL) {
- ++usrtb_fail;
- return (-1);
- }
- return (0);
-}
-
-/*
- * grptb_start
- * creates an an empty grptb
- * Return:
- * 0 if ok, -1 otherwise
- */
-static int
-grptb_start(void)
-{
-
- if (grptb != NULL)
- return (0);
- if (grptb_fail)
- return (-1);
- if ((grptb = (GIDC **)calloc(GNM_SZ, sizeof(GIDC *))) == NULL) {
- ++grptb_fail;
- return (-1);
- }
- return (0);
-}
-
-/*
- * user_from_uid()
- * caches the name (if any) for the uid. If noname clear, we always
- * return the stored name (if valid or invalid match).
- * We use a simple hash table.
- * Return
- * Pointer to stored name (or a empty string)
- */
-const char *
-user_from_uid(uid_t uid, int noname)
-{
- struct passwd *pw;
- UIDC *ptr, **pptr;
-
- if ((uidtb == NULL) && (uidtb_start() < 0))
- return (NULL);
-
- /*
- * see if we have this uid cached
- */
- pptr = uidtb + (uid % UID_SZ);
- ptr = *pptr;
-
- if ((ptr != NULL) && (ptr->valid > 0) && (ptr->uid == uid)) {
- /*
- * have an entry for this uid
- */
- if (!noname || (ptr->valid == VALID))
- return (ptr->name);
- return (NULL);
- }
-
- /*
- * No entry for this uid, we will add it
- */
- if (!pwopn) {
- if (_pwcache_setpassent != NULL)
- (*_pwcache_setpassent)(1);
- ++pwopn;
- }
-
- if (ptr == NULL)
- *pptr = ptr = (UIDC *)malloc(sizeof(UIDC));
-
- if ((pw = (*_pwcache_getpwuid)(uid)) == NULL) {
- /*
- * no match for this uid in the local password file
- * a string that is the uid in numeric format
- */
- if (ptr == NULL)
- return (NULL);
- ptr->uid = uid;
- (void)snprintf(ptr->name, UNMLEN, "%lu", (long) uid);
- ptr->valid = INVALID;
- if (noname)
- return (NULL);
- } else {
- /*
- * there is an entry for this uid in the password file
- */
- if (ptr == NULL)
- return (pw->pw_name);
- ptr->uid = uid;
- (void)strlcpy(ptr->name, pw->pw_name, UNMLEN);
- ptr->valid = VALID;
- }
- return (ptr->name);
-}
-
-/*
- * group_from_gid()
- * caches the name (if any) for the gid. If noname clear, we always
- * return the stored name (if valid or invalid match).
- * We use a simple hash table.
- * Return
- * Pointer to stored name (or a empty string)
- */
-const char *
-group_from_gid(gid_t gid, int noname)
-{
- struct group *gr;
- GIDC *ptr, **pptr;
-
- if ((gidtb == NULL) && (gidtb_start() < 0))
- return (NULL);
-
- /*
- * see if we have this gid cached
- */
- pptr = gidtb + (gid % GID_SZ);
- ptr = *pptr;
-
- if ((ptr != NULL) && (ptr->valid > 0) && (ptr->gid == gid)) {
- /*
- * have an entry for this gid
- */
- if (!noname || (ptr->valid == VALID))
- return (ptr->name);
- return (NULL);
- }
-
- /*
- * No entry for this gid, we will add it
- */
- if (!gropn) {
- if (_pwcache_setgroupent != NULL)
- (*_pwcache_setgroupent)(1);
- ++gropn;
- }
-
- if (ptr == NULL)
- *pptr = ptr = (GIDC *)malloc(sizeof(GIDC));
-
- if ((gr = (*_pwcache_getgrgid)(gid)) == NULL) {
- /*
- * no match for this gid in the local group file, put in
- * a string that is the gid in numberic format
- */
- if (ptr == NULL)
- return (NULL);
- ptr->gid = gid;
- (void)snprintf(ptr->name, GNMLEN, "%lu", (long) gid);
- ptr->valid = INVALID;
- if (noname)
- return (NULL);
- } else {
- /*
- * there is an entry for this group in the group file
- */
- if (ptr == NULL)
- return (gr->gr_name);
- ptr->gid = gid;
- (void)strlcpy(ptr->name, gr->gr_name, GNMLEN);
- ptr->valid = VALID;
- }
- return (ptr->name);
-}
-
-/*
- * uid_from_user()
- * caches the uid for a given user name. We use a simple hash table.
- * Return
- * the uid (if any) for a user name, or a -1 if no match can be found
- */
-int
-uid_from_user(const char *name, uid_t *uid)
-{
- struct passwd *pw;
- UIDC *ptr, **pptr;
- size_t namelen;
-
- /*
- * return -1 for mangled names
- */
- if (name == NULL || ((namelen = strlen(name)) == 0))
- return (-1);
- if ((usrtb == NULL) && (usrtb_start() < 0))
- return (-1);
-
- /*
- * look up in hash table, if found and valid return the uid,
- * if found and invalid, return a -1
- */
- pptr = usrtb + st_hash(name, namelen, UNM_SZ);
- ptr = *pptr;
-
- if ((ptr != NULL) && (ptr->valid > 0) && !strcmp(name, ptr->name)) {
- if (ptr->valid == INVALID)
- return (-1);
- *uid = ptr->uid;
- return (0);
- }
-
- if (!pwopn) {
- if (_pwcache_setpassent != NULL)
- (*_pwcache_setpassent)(1);
- ++pwopn;
- }
-
- if (ptr == NULL)
- *pptr = ptr = (UIDC *)malloc(sizeof(UIDC));
-
- /*
- * no match, look it up, if no match store it as an invalid entry,
- * or store the matching uid
- */
- if (ptr == NULL) {
- if ((pw = (*_pwcache_getpwnam)(name)) == NULL)
- return (-1);
- *uid = pw->pw_uid;
- return (0);
- }
- (void)strlcpy(ptr->name, name, UNMLEN);
- if ((pw = (*_pwcache_getpwnam)(name)) == NULL) {
- ptr->valid = INVALID;
- return (-1);
- }
- ptr->valid = VALID;
- *uid = ptr->uid = pw->pw_uid;
- return (0);
-}
-
-/*
- * gid_from_group()
- * caches the gid for a given group name. We use a simple hash table.
- * Return
- * the gid (if any) for a group name, or a -1 if no match can be found
- */
-int
-gid_from_group(const char *name, gid_t *gid)
-{
- struct group *gr;
- GIDC *ptr, **pptr;
- size_t namelen;
-
- /*
- * return -1 for mangled names
- */
- if (name == NULL || ((namelen = strlen(name)) == 0))
- return (-1);
- if ((grptb == NULL) && (grptb_start() < 0))
- return (-1);
-
- /*
- * look up in hash table, if found and valid return the uid,
- * if found and invalid, return a -1
- */
- pptr = grptb + st_hash(name, namelen, GID_SZ);
- ptr = *pptr;
-
- if ((ptr != NULL) && (ptr->valid > 0) && !strcmp(name, ptr->name)) {
- if (ptr->valid == INVALID)
- return (-1);
- *gid = ptr->gid;
- return (0);
- }
-
- if (!gropn) {
- if (_pwcache_setgroupent != NULL)
- (*_pwcache_setgroupent)(1);
- ++gropn;
- }
-
- if (ptr == NULL)
- *pptr = ptr = (GIDC *)malloc(sizeof(GIDC));
-
- /*
- * no match, look it up, if no match store it as an invalid entry,
- * or store the matching gid
- */
- if (ptr == NULL) {
- if ((gr = (*_pwcache_getgrnam)(name)) == NULL)
- return (-1);
- *gid = gr->gr_gid;
- return (0);
- }
-
- (void)strlcpy(ptr->name, name, GNMLEN);
- if ((gr = (*_pwcache_getgrnam)(name)) == NULL) {
- ptr->valid = INVALID;
- return (-1);
- }
- ptr->valid = VALID;
- *gid = ptr->gid = gr->gr_gid;
- return (0);
-}
-
-#define FLUSHTB(arr, len, fail) \
- do { \
- if (arr != NULL) { \
- for (i = 0; i < len; i++) \
- if (arr[i] != NULL) \
- free(arr[i]); \
- arr = NULL; \
- } \
- fail = 0; \
- } while (/* CONSTCOND */0);
-
-int
-pwcache_userdb(
- int (*a_setpassent)(int),
- void (*a_endpwent)(void),
- struct passwd * (*a_getpwnam)(const char *),
- struct passwd * (*a_getpwuid)(uid_t))
-{
- int i;
-
- /* a_setpassent and a_endpwent may be NULL */
- if (a_getpwnam == NULL || a_getpwuid == NULL)
- return (-1);
-
- if (_pwcache_endpwent != NULL)
- (*_pwcache_endpwent)();
- FLUSHTB(uidtb, UID_SZ, uidtb_fail);
- FLUSHTB(usrtb, UNM_SZ, usrtb_fail);
- pwopn = 0;
- _pwcache_setpassent = a_setpassent;
- _pwcache_endpwent = a_endpwent;
- _pwcache_getpwnam = a_getpwnam;
- _pwcache_getpwuid = a_getpwuid;
-
- return (0);
-}
-
-int
-pwcache_groupdb(
- int (*a_setgroupent)(int),
- void (*a_endgrent)(void),
- struct group * (*a_getgrnam)(const char *),
- struct group * (*a_getgrgid)(gid_t))
-{
- int i;
-
- /* a_setgroupent and a_endgrent may be NULL */
- if (a_getgrnam == NULL || a_getgrgid == NULL)
- return (-1);
-
- if (_pwcache_endgrent != NULL)
- (*_pwcache_endgrent)();
- FLUSHTB(gidtb, GID_SZ, gidtb_fail);
- FLUSHTB(grptb, GNM_SZ, grptb_fail);
- gropn = 0;
- _pwcache_setgroupent = a_setgroupent;
- _pwcache_endgrent = a_endgrent;
- _pwcache_getgrnam = a_getgrnam;
- _pwcache_getgrgid = a_getgrgid;
-
- return (0);
-}
-
-
-#ifdef TEST_PWCACHE
-
-struct passwd *
-test_getpwnam(const char *name)
-{
- static struct passwd foo;
-
- memset(&foo, 0, sizeof(foo));
- if (strcmp(name, "toor") == 0) {
- foo.pw_uid = 666;
- return &foo;
- }
- return (getpwnam(name));
-}
-
-int
-main(int argc, char *argv[])
-{
- uid_t u;
- int r, i;
-
- printf("pass 1 (default userdb)\n");
- for (i = 1; i < argc; i++) {
- printf("i: %d, pwopn %d usrtb_fail %d usrtb %p\n",
- i, pwopn, usrtb_fail, usrtb);
- r = uid_from_user(argv[i], &u);
- if (r == -1)
- printf(" uid_from_user %s: failed\n", argv[i]);
- else
- printf(" uid_from_user %s: %d\n", argv[i], u);
- }
- printf("pass 1 finish: pwopn %d usrtb_fail %d usrtb %p\n",
- pwopn, usrtb_fail, usrtb);
-
- puts("");
- printf("pass 2 (replacement userdb)\n");
- printf("pwcache_userdb returned %d\n",
- pwcache_userdb(setpassent, test_getpwnam, getpwuid));
- printf("pwopn %d usrtb_fail %d usrtb %p\n", pwopn, usrtb_fail, usrtb);
-
- for (i = 1; i < argc; i++) {
- printf("i: %d, pwopn %d usrtb_fail %d usrtb %p\n",
- i, pwopn, usrtb_fail, usrtb);
- u = -1;
- r = uid_from_user(argv[i], &u);
- if (r == -1)
- printf(" uid_from_user %s: failed\n", argv[i]);
- else
- printf(" uid_from_user %s: %d\n", argv[i], u);
- }
- printf("pass 2 finish: pwopn %d usrtb_fail %d usrtb %p\n",
- pwopn, usrtb_fail, usrtb);
-
- puts("");
- printf("pass 3 (null pointers)\n");
- printf("pwcache_userdb returned %d\n",
- pwcache_userdb(NULL, NULL, NULL));
-
- return (0);
-}
-#endif /* TEST_PWCACHE */
diff --git a/usr.sbin/makefs/compat/pwcache.h b/usr.sbin/makefs/compat/pwcache.h
deleted file mode 100644
index 1708951..0000000
--- a/usr.sbin/makefs/compat/pwcache.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/* $NetBSD: pwcache.h,v 1.5 2003/11/10 08:51:51 wiz Exp $ */
-
-/*-
- * Copyright (c) 1992 Keith Muller.
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego.
- *
- * 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.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- *
- * @(#)cache.h 8.1 (Berkeley) 5/31/93
- * $FreeBSD$
- */
-
-/*
- * Constants and data structures used to implement group and password file
- * caches. Traditional passwd/group cache routines perform quite poorly with
- * archives. The chances of hitting a valid lookup with an archive is quite a
- * bit worse than with files already resident on the file system. These misses
- * create a MAJOR performance cost. To address this problem, these routines
- * cache both hits and misses.
- *
- * NOTE: name lengths must be as large as those stored in ANY PROTOCOL and
- * as stored in the passwd and group files. CACHE SIZES MUST BE PRIME
- */
-#define UNMLEN 32 /* >= user name found in any protocol */
-#define GNMLEN 32 /* >= group name found in any protocol */
-#define UID_SZ 317 /* size of uid to user_name cache */
-#define UNM_SZ 317 /* size of user_name to uid cache */
-#define GID_SZ 251 /* size of gid to group_name cache */
-#define GNM_SZ 251 /* size of group_name to gid cache */
-#define VALID 1 /* entry and name are valid */
-#define INVALID 2 /* entry valid, name NOT valid */
-
-/*
- * Node structures used in the user, group, uid, and gid caches.
- */
-
-typedef struct uidc {
- int valid; /* is this a valid or a miss entry */
- char name[UNMLEN]; /* uid name */
- uid_t uid; /* cached uid */
-} UIDC;
-
-typedef struct gidc {
- int valid; /* is this a valid or a miss entry */
- char name[GNMLEN]; /* gid name */
- gid_t gid; /* cached gid */
-} GIDC;
diff --git a/usr.sbin/makefs/compat/strsuftoll.c b/usr.sbin/makefs/compat/strsuftoll.c
deleted file mode 100644
index 657e525..0000000
--- a/usr.sbin/makefs/compat/strsuftoll.c
+++ /dev/null
@@ -1,222 +0,0 @@
-/* $NetBSD: strsuftoll.c,v 1.6 2004/03/05 05:58:29 lukem Exp $ */
-/*-
- * Copyright (c) 2001-2002,2004 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Luke Mewburn.
- *
- * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
- */
-/*-
- * Copyright (c) 1991, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Keith Muller of the University of California, San Diego and Lance
- * Visser of Convex Computer Corporation.
- *
- * 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.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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/time.h>
-
-#include <assert.h>
-#include <ctype.h>
-#include <err.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef _LIBC
-# ifdef __weak_alias
-__weak_alias(strsuftoll, _strsuftoll)
-__weak_alias(strsuftollx, _strsuftollx)
-# endif
-#endif /* LIBC */
-
-/*
- * Convert an expression of the following forms to a (u)int64_t.
- * 1) A positive decimal number.
- * 2) A positive decimal number followed by a b (mult by 512).
- * 3) A positive decimal number followed by a k (mult by 1024).
- * 4) A positive decimal number followed by a m (mult by 1048576).
- * 5) A positive decimal number followed by a g (mult by 1073741824).
- * 6) A positive decimal number followed by a t (mult by 1099511627776).
- * 7) A positive decimal number followed by a w (mult by sizeof int)
- * 8) Two or more positive decimal numbers (with/without k,b or w).
- * separated by x (also * for backwards compatibility), specifying
- * the product of the indicated values.
- * Returns the result upon successful conversion, or exits with an
- * appropriate error.
- *
- */
-
-/*
- * As strsuftoll(), but returns the error message into the provided buffer
- * rather than exiting with it.
- */
-/* LONGLONG */
-long long
-strsuftollx(const char *desc, const char *val,
- long long min, long long max, char *ebuf, size_t ebuflen)
-{
- long long num, t;
- char *expr;
-
- errno = 0;
- ebuf[0] = '\0';
-
- while (isspace((unsigned char)*val)) /* Skip leading space */
- val++;
-
- num = strtoll(val, &expr, 10);
- if (errno == ERANGE)
- goto erange; /* Overflow */
-
- if (expr == val) /* No digits */
- goto badnum;
-
- switch (*expr) {
- case 'b':
- t = num;
- num *= 512; /* 1 block */
- if (t > num)
- goto erange;
- ++expr;
- break;
- case 'k':
- t = num;
- num *= 1024; /* 1 kilobyte */
- if (t > num)
- goto erange;
- ++expr;
- break;
- case 'm':
- t = num;
- num *= 1048576; /* 1 megabyte */
- if (t > num)
- goto erange;
- ++expr;
- break;
- case 'g':
- t = num;
- num *= 1073741824; /* 1 gigabyte */
- if (t > num)
- goto erange;
- ++expr;
- break;
- case 't':
- t = num;
- num *= 1099511627776LL; /* 1 terabyte */
- if (t > num)
- goto erange;
- ++expr;
- break;
- case 'w':
- t = num;
- num *= sizeof(int); /* 1 word */
- if (t > num)
- goto erange;
- ++expr;
- break;
- }
-
- switch (*expr) {
- case '\0':
- break;
- case '*': /* Backward compatible */
- case 'x':
- t = num;
- num *= strsuftollx(desc, expr + 1, min, max, ebuf, ebuflen);
- if (*ebuf != '\0')
- return (0);
- if (t > num) {
- erange:
- snprintf(ebuf, ebuflen,
- "%s: %s", desc, strerror(ERANGE));
- return (0);
- }
- break;
- default:
- badnum: snprintf(ebuf, ebuflen,
- "%s `%s': illegal number", desc, val);
- return (0);
- }
- if (num < min) {
- /* LONGLONG */
- snprintf(ebuf, ebuflen, "%s %lld is less than %lld.",
- desc, (long long)num, (long long)min);
- return (0);
- }
- if (num > max) {
- /* LONGLONG */
- snprintf(ebuf, ebuflen,
- "%s %lld is greater than %lld.",
- desc, (long long)num, (long long)max);
- return (0);
- }
- *ebuf = '\0';
- return (num);
-}
-
-/* LONGLONG */
-long long
-strsuftoll(const char *desc, const char *val,
- long long min, long long max)
-{
- long long result;
- char errbuf[100];
-
- result = strsuftollx(desc, val, min, max, errbuf, sizeof(errbuf));
- if (*errbuf != '\0')
- errx(1, "%s", errbuf);
- return (result);
-}
diff --git a/usr.sbin/makefs/ffs/ufs_bswap.h b/usr.sbin/makefs/ffs/ufs_bswap.h
index c368255..6e7cc42 100644
--- a/usr.sbin/makefs/ffs/ufs_bswap.h
+++ b/usr.sbin/makefs/ffs/ufs_bswap.h
@@ -40,6 +40,8 @@
#include <sys/endian.h>
+#include "makefs.h"
+
/* Macros to access UFS flags */
#ifdef FFS_EI
#define UFS_MPNEEDSWAP(mp) (VFSTOUFS(mp)->um_flags & UFS_NEEDSWAP)
diff --git a/usr.sbin/makefs/getid.c b/usr.sbin/makefs/getid.c
deleted file mode 100644
index 939d943..0000000
--- a/usr.sbin/makefs/getid.c
+++ /dev/null
@@ -1,429 +0,0 @@
-/* $NetBSD: getid.c,v 1.5 2004/06/20 22:20:18 jmc Exp $ */
-/* from: NetBSD: getpwent.c,v 1.48 2000/10/03 03:22:26 enami Exp */
-/* from: NetBSD: getgrent.c,v 1.41 2002/01/12 23:51:30 lukem Exp */
-
-/*
- * Copyright (c) 1987, 1988, 1989, 1993, 1994, 1995
- * The Regents of the University of California. All rights reserved.
- *
- * 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.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-/*-
- * Copyright (c) 2002 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Luke Mewburn of Wasabi Systems.
- *
- * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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/param.h>
-
-#include <grp.h>
-#include <limits.h>
-#include <pwd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "makefs.h"
-
-#include "mtree.h"
-#include "extern.h"
-
-static struct group * gi_getgrnam(const char *);
-static struct group * gi_getgrgid(gid_t);
-static int gi_setgroupent(int);
-static void gi_endgrent(void);
-static int grstart(void);
-static int grscan(int, gid_t, const char *);
-static int grmatchline(int, gid_t, const char *);
-
-static struct passwd * gi_getpwnam(const char *);
-static struct passwd * gi_getpwuid(uid_t);
-static int gi_setpassent(int);
-static void gi_endpwent(void);
-static int pwstart(void);
-static int pwscan(int, uid_t, const char *);
-static int pwmatchline(int, uid_t, const char *);
-
-#define MAXGRP 200
-#define MAXLINELENGTH 1024
-
-static FILE *_gr_fp;
-static struct group _gr_group;
-static int _gr_stayopen;
-static int _gr_filesdone;
-static FILE *_pw_fp;
-static struct passwd _pw_passwd; /* password structure */
-static int _pw_stayopen; /* keep fd's open */
-static int _pw_filesdone;
-
-static char grfile[MAXPATHLEN];
-static char pwfile[MAXPATHLEN];
-
-static char *members[MAXGRP];
-static char grline[MAXLINELENGTH];
-static char pwline[MAXLINELENGTH];
-
-int
-setup_getid(const char *dir)
-{
- if (dir == NULL)
- return (0);
-
- /* close existing databases */
- gi_endgrent();
- gi_endpwent();
-
- /* build paths to new databases */
- snprintf(grfile, sizeof(grfile), "%s/group", dir);
- snprintf(pwfile, sizeof(pwfile), "%s/master.passwd", dir);
-
- /* try to open new databases */
- if (!grstart() || !pwstart())
- return (0);
-
- /* switch pwcache(3) lookup functions */
- if (pwcache_groupdb(gi_setgroupent, gi_endgrent,
- gi_getgrnam, gi_getgrgid) == -1
- || pwcache_userdb(gi_setpassent, gi_endpwent,
- gi_getpwnam, gi_getpwuid) == -1)
- return (0);
-
- return (1);
-}
-
-
-/*
- * group lookup functions
- */
-
-static struct group *
-gi_getgrnam(const char *name)
-{
- int rval;
-
- if (!grstart())
- return NULL;
- rval = grscan(1, 0, name);
- if (!_gr_stayopen)
- endgrent();
- return (rval) ? &_gr_group : NULL;
-}
-
-static struct group *
-gi_getgrgid(gid_t gid)
-{
- int rval;
-
- if (!grstart())
- return NULL;
- rval = grscan(1, gid, NULL);
- if (!_gr_stayopen)
- endgrent();
- return (rval) ? &_gr_group : NULL;
-}
-
-static int
-gi_setgroupent(int stayopen)
-{
-
- if (!grstart())
- return 0;
- _gr_stayopen = stayopen;
- return 1;
-}
-
-static void
-gi_endgrent(void)
-{
-
- _gr_filesdone = 0;
- if (_gr_fp) {
- (void)fclose(_gr_fp);
- _gr_fp = NULL;
- }
-}
-
-static int
-grstart(void)
-{
-
- _gr_filesdone = 0;
- if (_gr_fp) {
- rewind(_gr_fp);
- return 1;
- }
- if (grfile[0] == '\0') /* sanity check */
- return 0;
- return (_gr_fp = fopen(grfile, "r")) ? 1 : 0;
-}
-
-
-static int
-grscan(int search, gid_t gid, const char *name)
-{
-
- if (_gr_filesdone)
- return 0;
- for (;;) {
- if (!fgets(grline, sizeof(grline), _gr_fp)) {
- if (!search)
- _gr_filesdone = 1;
- return 0;
- }
- /* skip lines that are too big */
- if (!strchr(grline, '\n')) {
- int ch;
-
- while ((ch = getc(_gr_fp)) != '\n' && ch != EOF)
- ;
- continue;
- }
- if (grmatchline(search, gid, name))
- return 1;
- }
- /* NOTREACHED */
-}
-
-static int
-grmatchline(int search, gid_t gid, const char *name)
-{
- unsigned long id;
- char **m;
- char *cp, *bp, *ep;
-
- /* name may be NULL if search is nonzero */
-
- bp = grline;
- memset(&_gr_group, 0, sizeof(_gr_group));
- _gr_group.gr_name = strsep(&bp, ":\n");
- if (search && name && strcmp(_gr_group.gr_name, name))
- return 0;
- _gr_group.gr_passwd = strsep(&bp, ":\n");
- if (!(cp = strsep(&bp, ":\n")))
- return 0;
- id = strtoul(cp, &ep, 10);
- if (id > GID_MAX || *ep != '\0')
- return 0;
- _gr_group.gr_gid = (gid_t)id;
- if (search && name == NULL && _gr_group.gr_gid != gid)
- return 0;
- cp = NULL;
- if (bp == NULL)
- return 0;
- for (_gr_group.gr_mem = m = members;; bp++) {
- if (m == &members[MAXGRP - 1])
- break;
- if (*bp == ',') {
- if (cp) {
- *bp = '\0';
- *m++ = cp;
- cp = NULL;
- }
- } else if (*bp == '\0' || *bp == '\n' || *bp == ' ') {
- if (cp) {
- *bp = '\0';
- *m++ = cp;
- }
- break;
- } else if (cp == NULL)
- cp = bp;
- }
- *m = NULL;
- return 1;
-}
-
-
-/*
- * user lookup functions
- */
-
-static struct passwd *
-gi_getpwnam(const char *name)
-{
- int rval;
-
- if (!pwstart())
- return NULL;
- rval = pwscan(1, 0, name);
- if (!_pw_stayopen)
- endpwent();
- return (rval) ? &_pw_passwd : NULL;
-}
-
-static struct passwd *
-gi_getpwuid(uid_t uid)
-{
- int rval;
-
- if (!pwstart())
- return NULL;
- rval = pwscan(1, uid, NULL);
- if (!_pw_stayopen)
- endpwent();
- return (rval) ? &_pw_passwd : NULL;
-}
-
-static int
-gi_setpassent(int stayopen)
-{
-
- if (!pwstart())
- return 0;
- _pw_stayopen = stayopen;
- return 1;
-}
-
-static void
-gi_endpwent(void)
-{
-
- _pw_filesdone = 0;
- if (_pw_fp) {
- (void)fclose(_pw_fp);
- _pw_fp = NULL;
- }
-}
-
-static int
-pwstart(void)
-{
-
- _pw_filesdone = 0;
- if (_pw_fp) {
- rewind(_pw_fp);
- return 1;
- }
- if (pwfile[0] == '\0') /* sanity check */
- return 0;
- return (_pw_fp = fopen(pwfile, "r")) ? 1 : 0;
-}
-
-
-static int
-pwscan(int search, uid_t uid, const char *name)
-{
-
- if (_pw_filesdone)
- return 0;
- for (;;) {
- if (!fgets(pwline, sizeof(pwline), _pw_fp)) {
- if (!search)
- _pw_filesdone = 1;
- return 0;
- }
- /* skip lines that are too big */
- if (!strchr(pwline, '\n')) {
- int ch;
-
- while ((ch = getc(_pw_fp)) != '\n' && ch != EOF)
- ;
- continue;
- }
- if (pwmatchline(search, uid, name))
- return 1;
- }
- /* NOTREACHED */
-}
-
-static int
-pwmatchline(int search, uid_t uid, const char *name)
-{
- unsigned long id;
- char *cp, *bp, *ep;
-
- /* name may be NULL if search is nonzero */
-
- bp = pwline;
- memset(&_pw_passwd, 0, sizeof(_pw_passwd));
- _pw_passwd.pw_name = strsep(&bp, ":\n"); /* name */
- if (search && name && strcmp(_pw_passwd.pw_name, name))
- return 0;
-
- _pw_passwd.pw_passwd = strsep(&bp, ":\n"); /* passwd */
-
- if (!(cp = strsep(&bp, ":\n"))) /* uid */
- return 0;
- id = strtoul(cp, &ep, 10);
- if (id > UID_MAX || *ep != '\0')
- return 0;
- _pw_passwd.pw_uid = (uid_t)id;
- if (search && name == NULL && _pw_passwd.pw_uid != uid)
- return 0;
-
- if (!(cp = strsep(&bp, ":\n"))) /* gid */
- return 0;
- id = strtoul(cp, &ep, 10);
- if (id > GID_MAX || *ep != '\0')
- return 0;
- _pw_passwd.pw_gid = (gid_t)id;
-
- if (!(ep = strsep(&bp, ":"))) /* class */
- return 0;
- if (!(ep = strsep(&bp, ":"))) /* change */
- return 0;
- if (!(ep = strsep(&bp, ":"))) /* expire */
- return 0;
-
- if (!(_pw_passwd.pw_gecos = strsep(&bp, ":\n"))) /* gecos */
- return 0;
- if (!(_pw_passwd.pw_dir = strsep(&bp, ":\n"))) /* directory */
- return 0;
- if (!(_pw_passwd.pw_shell = strsep(&bp, ":\n"))) /* shell */
- return 0;
-
- if (strchr(bp, ':') != NULL)
- return 0;
-
- return 1;
-}
diff --git a/usr.sbin/makefs/makefs.8 b/usr.sbin/makefs/makefs.8
index 4d81e45..51e536f 100644
--- a/usr.sbin/makefs/makefs.8
+++ b/usr.sbin/makefs/makefs.8
@@ -35,7 +35,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd August 22, 2012
+.Dd August 16, 2013
.Dt MAKEFS 8
.Os
.Sh NAME
@@ -43,7 +43,7 @@
.Nd create a file system image from a directory tree or a mtree manifest
.Sh SYNOPSIS
.Nm
-.Op Fl Dpx
+.Op Fl DxZ
.Op Fl B Ar byte-order
.Op Fl b Ar free-blocks
.Op Fl d Ar debug-mask
@@ -191,7 +191,10 @@ Set file system specific options.
is a comma separated list of options.
Valid file system specific options are detailed below.
.It Fl p
-Create the image as a sparse file.
+Deprecated.
+See the
+.Fl Z
+flag.
.It Fl S Ar sector-size
Set the file system sector size to
.Ar sector-size .
@@ -213,6 +216,8 @@ ISO 9660 file system.
.El
.It Fl x
Exclude file system nodes not explicitly listed in the specfile.
+.It Fl Z
+Create the image as a sparse file.
.El
.Pp
Where sizes are specified, a decimal number of bytes is expected.
diff --git a/usr.sbin/makefs/makefs.c b/usr.sbin/makefs/makefs.c
index 03ff1ac..bf10034 100644
--- a/usr.sbin/makefs/makefs.c
+++ b/usr.sbin/makefs/makefs.c
@@ -113,7 +113,7 @@ main(int argc, char *argv[])
start_time.tv_sec = start.tv_sec;
start_time.tv_nsec = start.tv_usec * 1000;
- while ((ch = getopt(argc, argv, "B:b:Dd:f:F:M:m:N:o:ps:S:t:x")) != -1) {
+ while ((ch = getopt(argc, argv, "B:b:Dd:f:F:M:m:N:o:ps:S:t:xZ")) != -1) {
switch (ch) {
case 'B':
@@ -205,6 +205,7 @@ main(int argc, char *argv[])
break;
}
case 'p':
+ /* Deprecated in favor of 'Z' */
fsoptions.sparse = 1;
break;
@@ -233,6 +234,11 @@ main(int argc, char *argv[])
fsoptions.onlyspec = 1;
break;
+ case 'Z':
+ /* Superscedes 'p' for compatibility with NetBSD makefs(8) */
+ fsoptions.sparse = 1;
+ break;
+
case '?':
default:
usage();
@@ -354,7 +360,7 @@ usage(void)
fprintf(stderr,
"usage: %s [-t fs-type] [-o fs-options] [-d debug-mask] [-B endian]\n"
"\t[-S sector-size] [-M minimum-size] [-m maximum-size] [-s image-size]\n"
-"\t[-b free-blocks] [-f free-files] [-F mtree-specfile] [-px]\n"
+"\t[-b free-blocks] [-f free-files] [-F mtree-specfile] [-xZ]\n"
"\t[-N userdb-dir] image-file directory | manifest [extra-directory ...]\n",
prog);
exit(1);
diff --git a/usr.sbin/makefs/makefs.h b/usr.sbin/makefs/makefs.h
index c6707d9..5ab0444 100644
--- a/usr.sbin/makefs/makefs.h
+++ b/usr.sbin/makefs/makefs.h
@@ -282,22 +282,4 @@ void ffs_fragacct_swap(struct fs *, int, int32_t [], int, int);
fsinode *link_check(fsinode *);
-/*
- * Declarations for compat routines.
- */
-long long strsuftoll(const char *, const char *, long long, long long);
-long long strsuftollx(const char *, const char *,
- long long, long long, char *, size_t);
-
-struct passwd;
-int uid_from_user(const char *, uid_t *);
-int pwcache_userdb(int (*)(int), void (*)(void),
- struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
-struct group;
-int gid_from_group(const char *, gid_t *);
-int pwcache_groupdb(int (*)(int), void (*)(void),
- struct group * (*)(const char *), struct group * (*)(gid_t));
-
-int setup_getid(const char *dir);
-
#endif /* _MAKEFS_H */
diff --git a/usr.sbin/makefs/mtree.c b/usr.sbin/makefs/mtree.c
index c90c974..d772bc1 100644
--- a/usr.sbin/makefs/mtree.c
+++ b/usr.sbin/makefs/mtree.c
@@ -1050,6 +1050,7 @@ read_mtree(const char *fname, fsnode *node)
bzero(&mtree_global_inode, sizeof(mtree_global_inode));
mtree_global.inode = &mtree_global_inode;
mtree_global_inode.nlink = 1;
+ mtree_global_inode.st.st_nlink = 1;
mtree_global_inode.st.st_atime = mtree_global_inode.st.st_ctime =
mtree_global_inode.st.st_mtime = time(NULL);
errors = warnings = 0;
diff --git a/usr.sbin/makefs/walk.c b/usr.sbin/makefs/walk.c
index 7af92bb..2fc964a 100644
--- a/usr.sbin/makefs/walk.c
+++ b/usr.sbin/makefs/walk.c
@@ -304,7 +304,7 @@ apply_specfile(const char *specfile, const char *dir, fsnode *parent, int specon
if ((fp = fopen(specfile, "r")) == NULL)
err(1, "Can't open `%s'", specfile);
TIMER_START(start);
- root = mtree_readspec(fp);
+ root = spec(fp);
TIMER_RESULTS(start, "spec");
if (fclose(fp) == EOF)
err(1, "Can't close `%s'", specfile);
@@ -320,33 +320,6 @@ apply_specfile(const char *specfile, const char *dir, fsnode *parent, int specon
}
-static u_int
-nodetoino(u_int type)
-{
-
- switch (type) {
- case F_BLOCK:
- return S_IFBLK;
- case F_CHAR:
- return S_IFCHR;
- case F_DIR:
- return S_IFDIR;
- case F_FIFO:
- return S_IFIFO;
- case F_FILE:
- return S_IFREG;
- case F_LINK:
- return S_IFLNK;
- case F_SOCK:
- return S_IFSOCK;
- default:
- printf("unknown type %d", type);
- abort();
- }
- /* NOTREACHED */
-}
-
-
static void
apply_specdir(const char *dir, NODE *specnode, fsnode *dirnode, int speconly)
{
diff --git a/usr.sbin/mergemaster/mergemaster.8 b/usr.sbin/mergemaster/mergemaster.8
index 36eba1b..1cff984 100644
--- a/usr.sbin/mergemaster/mergemaster.8
+++ b/usr.sbin/mergemaster/mergemaster.8
@@ -474,11 +474,3 @@ make world tutorial which is referenced above.
.Sh AUTHORS
This manual page and the script itself were written by
.An Douglas Barton Aq dougb@FreeBSD.org .
-.Sh BUGS
-There are no known bugs.
-Please report any problems,
-comments or suggestions to the author.
-Several of the
-improvements to this program have come from user
-suggestions.
-Thank you.
diff --git a/usr.sbin/mergemaster/mergemaster.sh b/usr.sbin/mergemaster/mergemaster.sh
index 48b58f3..629d44f 100755
--- a/usr.sbin/mergemaster/mergemaster.sh
+++ b/usr.sbin/mergemaster/mergemaster.sh
@@ -483,6 +483,7 @@ if [ ! -f ${SOURCEDIR}/Makefile.inc1 -a \
sleep 3
SOURCEDIR=${SOURCEDIR}/..
fi
+SOURCEDIR=$(realpath "$SOURCEDIR")
# Setup make to use system files from SOURCEDIR
MM_MAKE="make ${ARCHSTRING} -m ${SOURCEDIR}/share/mk"
@@ -629,11 +630,10 @@ case "${RERUN}" in
${MM_MAKE} DESTDIR=${DESTDIR} distrib-dirs >/dev/null
;;
esac
- od=${TEMPROOT}/usr/obj
${MM_MAKE} DESTDIR=${TEMPROOT} distrib-dirs >/dev/null &&
- MAKEOBJDIRPREFIX=$od ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc >/dev/null &&
- MAKEOBJDIRPREFIX=$od ${MM_MAKE} everything SUBDIR_OVERRIDE=etc >/dev/null &&
- MAKEOBJDIRPREFIX=$od ${MM_MAKE} DESTDIR=${TEMPROOT} distribution >/dev/null;} ||
+ ${MM_MAKE} _obj SUBDIR_OVERRIDE=etc >/dev/null &&
+ ${MM_MAKE} everything SUBDIR_OVERRIDE=etc >/dev/null &&
+ ${MM_MAKE} DESTDIR=${TEMPROOT} distribution >/dev/null;} ||
{ echo '';
echo " *** FATAL ERROR: Cannot 'cd' to ${SOURCEDIR} and install files to";
echo " the temproot environment";
@@ -1327,7 +1327,7 @@ case "${NEED_PWD_MKDB}" in
;;
esac
-if [ -e "${DESTDIR}/etc/localtime" -a -z "${PRE_WORLD}" ]; then # Ignore if TZ == UTC
+if [ -e "${DESTDIR}/etc/localtime" -a ! -L "${DESTDIR}/etc/localtime" -a -z "${PRE_WORLD}" ]; then # Ignore if TZ == UTC
echo ''
[ -n "${DESTDIR}" ] && tzs_args="-C ${DESTDIR}"
if [ -f "${DESTDIR}/var/db/zoneinfo" ]; then
diff --git a/usr.sbin/mfiutil/Makefile b/usr.sbin/mfiutil/Makefile
index c460b3f..f6e358a 100644
--- a/usr.sbin/mfiutil/Makefile
+++ b/usr.sbin/mfiutil/Makefile
@@ -2,7 +2,7 @@
PROG= mfiutil
SRCS= mfiutil.c mfi_bbu.c mfi_cmd.c mfi_config.c mfi_drive.c mfi_evt.c \
- mfi_flash.c mfi_patrol.c mfi_show.c mfi_volume.c
+ mfi_flash.c mfi_patrol.c mfi_show.c mfi_volume.c mfi_foreign.c
MAN8= mfiutil.8
CFLAGS+= -fno-builtin-strftime
diff --git a/usr.sbin/mfiutil/mfi_config.c b/usr.sbin/mfiutil/mfi_config.c
index 8576bc3..a919214 100644
--- a/usr.sbin/mfiutil/mfi_config.c
+++ b/usr.sbin/mfiutil/mfi_config.c
@@ -37,19 +37,13 @@
#include <errno.h>
#include <fcntl.h>
#include <libutil.h>
-#ifdef DEBUG
#include <stdint.h>
-#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "mfiutil.h"
-#ifdef DEBUG
-static void dump_config(int fd, struct mfi_config_data *config);
-#endif
-
static int add_spare(int ac, char **av);
static int remove_spare(int ac, char **av);
@@ -81,9 +75,17 @@ dehumanize(const char *value)
}
return (iv);
}
+
int
mfi_config_read(int fd, struct mfi_config_data **configp)
{
+ return mfi_config_read_opcode(fd, MFI_DCMD_CFG_READ, configp, NULL, 0);
+}
+
+int
+mfi_config_read_opcode(int fd, uint32_t opcode, struct mfi_config_data **configp,
+ uint8_t *mbox, size_t mboxlen)
+{
struct mfi_config_data *config;
uint32_t config_size;
int error;
@@ -98,8 +100,8 @@ fetch:
config = reallocf(config, config_size);
if (config == NULL)
return (-1);
- if (mfi_dcmd_command(fd, MFI_DCMD_CFG_READ, config,
- config_size, NULL, 0, NULL) < 0) {
+ if (mfi_dcmd_command(fd, opcode, config,
+ config_size, mbox, mboxlen, NULL) < 0) {
error = errno;
free(config);
errno = error;
@@ -366,6 +368,13 @@ parse_array(int fd, int raid_type, char *array_str, struct array_info *info)
info->drives = NULL;
return (EINVAL);
}
+
+ if (pinfo->state.ddf.v.pd_type.is_foreign) {
+ warnx("Drive %u is foreign", device_id);
+ free(info->drives);
+ info->drives = NULL;
+ return (EINVAL);
+ }
}
return (0);
@@ -804,7 +813,7 @@ create_volume(int ac, char **av)
#ifdef DEBUG
if (dump)
- dump_config(fd, config);
+ dump_config(fd, config, NULL);
#endif
/* Send the new config to the controller. */
@@ -1093,10 +1102,9 @@ remove_spare(int ac, char **av)
}
MFI_COMMAND(top, remove, remove_spare);
-#ifdef DEBUG
/* Display raw data about a config. */
-static void
-dump_config(int fd, struct mfi_config_data *config)
+void
+dump_config(int fd, struct mfi_config_data *config, const char *msg_prefix)
{
struct mfi_array *ar;
struct mfi_ld_config *ld;
@@ -1106,9 +1114,12 @@ dump_config(int fd, struct mfi_config_data *config)
char *p;
int i, j;
+ if (NULL == msg_prefix)
+ msg_prefix = "Configuration (Debug)";
+
printf(
- "mfi%d Configuration (Debug): %d arrays, %d volumes, %d spares\n",
- mfi_unit, config->array_count, config->log_drv_count,
+ "mfi%d %s: %d arrays, %d volumes, %d spares\n", mfi_unit,
+ msg_prefix, config->array_count, config->log_drv_count,
config->spares_count);
printf(" array size: %u\n", config->array_size);
printf(" volume size: %u\n", config->log_drv_size);
@@ -1186,6 +1197,7 @@ dump_config(int fd, struct mfi_config_data *config)
}
}
+#ifdef DEBUG
static int
debug_config(int ac, char **av)
{
@@ -1213,7 +1225,7 @@ debug_config(int ac, char **av)
}
/* Dump out the configuration. */
- dump_config(fd, config);
+ dump_config(fd, config, NULL);
free(config);
close(fd);
@@ -1265,7 +1277,7 @@ dump(int ac, char **av)
close(fd);
return (error);
}
- dump_config(fd, config);
+ dump_config(fd, config, NULL);
free(config);
close(fd);
diff --git a/usr.sbin/mfiutil/mfi_drive.c b/usr.sbin/mfiutil/mfi_drive.c
index 1927fac..2bc902e 100644
--- a/usr.sbin/mfiutil/mfi_drive.c
+++ b/usr.sbin/mfiutil/mfi_drive.c
@@ -474,6 +474,20 @@ rebuild_drive(int ac, char **av)
MFI_COMMAND(top, rebuild, rebuild_drive);
static int
+syspd_drive(int ac, char **av)
+{
+
+ if (ac != 2) {
+ warnx("syspd: %s", ac > 2 ? "extra arguments" :
+ "drive required");
+ return (EINVAL);
+ }
+
+ return (drive_set_state(av[1], MFI_PD_STATE_SYSTEM));
+}
+MFI_COMMAND(top, syspd, syspd_drive);
+
+static int
start_rebuild(int ac, char **av)
{
struct mfi_pd_info info;
diff --git a/usr.sbin/mfiutil/mfi_foreign.c b/usr.sbin/mfiutil/mfi_foreign.c
new file mode 100644
index 0000000..8c6183d
--- /dev/null
+++ b/usr.sbin/mfiutil/mfi_foreign.c
@@ -0,0 +1,364 @@
+/*
+ * Copyright (c) 2013 smh@freebsd.org
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libutil.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "mfiutil.h"
+
+MFI_TABLE(top, foreign);
+
+static int
+foreign_clear(__unused int ac, __unused char **av)
+{
+ int ch, error, fd;
+
+ fd = mfi_open(mfi_unit, O_RDWR);
+ if (fd < 0) {
+ error = errno;
+ warn("mfi_open");
+ return (error);
+ }
+
+ printf(
+ "Are you sure you wish to clear ALL foreign configurations"
+ " on mfi%u? [y/N] ", mfi_unit);
+
+ ch = getchar();
+ if (ch != 'y' && ch != 'Y') {
+ printf("\nAborting\n");
+ close(fd);
+ return (0);
+ }
+
+ if (mfi_dcmd_command(fd, MFI_DCMD_CFG_FOREIGN_CLEAR, NULL, 0, NULL,
+ 0, NULL) < 0) {
+ error = errno;
+ warn("Failed to clear foreign configuration");
+ close(fd);
+ return (error);
+ }
+
+ printf("mfi%d: Foreign configuration cleared\n", mfi_unit);
+ close(fd);
+ return (0);
+}
+MFI_COMMAND(foreign, clear, foreign_clear);
+
+static int
+foreign_scan(__unused int ac, __unused char **av)
+{
+ struct mfi_foreign_scan_info info;
+ int error, fd;
+
+ fd = mfi_open(mfi_unit, O_RDONLY);
+ if (fd < 0) {
+ error = errno;
+ warn("mfi_open");
+ return (error);
+ }
+
+ if (mfi_dcmd_command(fd, MFI_DCMD_CFG_FOREIGN_SCAN, &info,
+ sizeof(info), NULL, 0, NULL) < 0) {
+ error = errno;
+ warn("Failed to scan foreign configuration");
+ close(fd);
+ return (error);
+ }
+
+ printf("mfi%d: Found %d foreign configurations\n", mfi_unit,
+ info.count);
+ close(fd);
+ return (0);
+}
+MFI_COMMAND(foreign, scan, foreign_scan);
+
+static int
+foreign_show_cfg(int fd, uint32_t opcode, uint8_t cfgidx, int diagnostic)
+{
+ struct mfi_config_data *config;
+ char prefix[26];
+ int error;
+ uint8_t mbox[4];
+
+ bzero(mbox, sizeof(mbox));
+ mbox[0] = cfgidx;
+ if (mfi_config_read_opcode(fd, opcode, &config, mbox, sizeof(mbox)) < 0) {
+ error = errno;
+ warn("Failed to get foreign config %d", error);
+ close(fd);
+ return (error);
+ }
+
+ if (opcode == MFI_DCMD_CFG_FOREIGN_PREVIEW)
+ sprintf(prefix, "Foreign configuration preview %d", cfgidx);
+ else
+ sprintf(prefix, "Foreign configuration %d", cfgidx);
+ /*
+ * MegaCli uses DCMD opcodes: 0x03100200 (which fails) followed by
+ * 0x1a721880 which returns what looks to be drive / volume info
+ * but we have no real information on what these are or what they do
+ * so we're currently relying solely on the config returned above
+ */
+ if (diagnostic)
+ dump_config(fd, config, prefix);
+ else {
+ char *ld_list;
+ int i;
+
+ ld_list = (char *)(config->array);
+
+ printf("%s: %d arrays, %d volumes, %d spares\n", prefix,
+ config->array_count, config->log_drv_count,
+ config->spares_count);
+
+
+ for (i = 0; i < config->array_count; i++)
+ ld_list += config->array_size;
+
+ for (i = 0; i < config->log_drv_count; i++) {
+ const char *level;
+ char size[6], stripe[5];
+ struct mfi_ld_config *ld;
+
+ ld = (struct mfi_ld_config *)ld_list;
+
+ format_stripe(stripe, sizeof(stripe),
+ ld->params.stripe_size);
+ /*
+ * foreign configs don't seem to have a secondary raid level
+ * but, we can use span depth here as if a LD spans multiple
+ * arrays of disks (2 raid 1 sets for example), we will have an
+ * indication based on the spam depth. swb
+ */
+ level = mfi_raid_level(ld->params.primary_raid_level,
+ (ld->params.span_depth - 1));
+
+ humanize_number(size, sizeof(size), ld->span[0].num_blocks * 512,
+ "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
+
+ printf(" ID%d ", i);
+ printf("(%6s) %-8s |",
+ size, level);
+ printf("volume spans %d %s\n", ld->params.span_depth,
+ (ld->params.span_depth > 1) ? "arrays" : "array");
+ for (int j = 0; j < ld->params.span_depth; j++) {
+ char *ar_list;
+ struct mfi_array *ar;
+ uint16_t device_id;
+
+ printf(" array %u @ ", ld->span[j].array_ref);
+ humanize_number(size, sizeof(size), ld->span[j].num_blocks * 512,
+ "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
+
+ printf("(%6s)\n",size);
+ ar_list = (char *)config->array + (ld->span[j].array_ref * config->array_size);
+
+ ar = (struct mfi_array *)ar_list;
+ for (int k = 0; k < ar->num_drives; k++) {
+ device_id = ar->pd[k].ref.v.device_id;
+ if (device_id == 0xffff)
+ printf(" drive MISSING\n");
+ else {
+ printf(" drive %u %s\n", device_id,
+ mfi_pdstate(ar->pd[k].fw_state));
+ }
+ }
+
+ }
+ ld_list += config->log_drv_size;
+ }
+ }
+
+ free(config);
+
+ return (0);
+}
+
+int
+display_format(int ac, char **av, int diagnostic, mfi_dcmd_t display_cmd)
+{
+ struct mfi_foreign_scan_info info;
+ uint8_t i;
+ int error, fd;
+
+ if (ac > 2) {
+ warnx("foreign display: extra arguments");
+ return (EINVAL);
+ }
+
+ fd = mfi_open(mfi_unit, O_RDONLY);
+ if (fd < 0) {
+ error = errno;
+ warn("mfi_open");
+ return (error);
+ }
+
+ if (mfi_dcmd_command(fd, MFI_DCMD_CFG_FOREIGN_SCAN, &info,
+ sizeof(info), NULL, 0, NULL) < 0) {
+ error = errno;
+ warn("Failed to scan foreign configuration");
+ close(fd);
+ return (error);
+ }
+
+ if (info.count == 0) {
+ warnx("foreign display: no foreign configs found");
+ close(fd);
+ return (EINVAL);
+ }
+
+ if (ac == 1) {
+ for (i = 0; i < info.count; i++) {
+ error = foreign_show_cfg(fd,
+ display_cmd, i, diagnostic);
+ if(error != 0) {
+ close(fd);
+ return (error);
+ }
+ if (i < info.count - 1)
+ printf("\n");
+ }
+ } else if (ac == 2) {
+ error = foreign_show_cfg(fd,
+ display_cmd, atoi(av[1]), diagnostic);
+ if (error != 0) {
+ close(fd);
+ return (error);
+ }
+ }
+
+ close(fd);
+ return (0);
+}
+
+static int
+foreign_display(int ac, char **av)
+{
+ return(display_format(ac, av, 1/*diagnostic output*/, MFI_DCMD_CFG_FOREIGN_DISPLAY));
+}
+MFI_COMMAND(foreign, diag, foreign_display);
+
+static int
+foreign_preview(int ac, char **av)
+{
+ return(display_format(ac, av, 1/*diagnostic output*/, MFI_DCMD_CFG_FOREIGN_PREVIEW));
+}
+MFI_COMMAND(foreign, preview, foreign_preview);
+
+static int
+foreign_import(int ac, char **av)
+{
+ struct mfi_foreign_scan_info info;
+ int ch, error, fd;
+ uint8_t cfgidx;
+ uint8_t mbox[4];
+
+ if (ac > 2) {
+ warnx("foreign preview: extra arguments");
+ return (EINVAL);
+ }
+
+ fd = mfi_open(mfi_unit, O_RDWR);
+ if (fd < 0) {
+ error = errno;
+ warn("mfi_open");
+ return (error);
+ }
+
+ if (mfi_dcmd_command(fd, MFI_DCMD_CFG_FOREIGN_SCAN, &info,
+ sizeof(info), NULL, 0, NULL) < 0) {
+ error = errno;
+ warn("Failed to scan foreign configuration");
+ close(fd);
+ return (error);
+ }
+
+ if (info.count == 0) {
+ warnx("foreign import: no foreign configs found");
+ close(fd);
+ return (EINVAL);
+ }
+
+ if (ac == 1) {
+ cfgidx = 0xff;
+ printf("Are you sure you wish to import ALL foreign "
+ "configurations on mfi%u? [y/N] ", mfi_unit);
+ } else {
+ /*
+ * While this is docmmented for MegaCli this failed with
+ * exit code 0x03 on the test controller which was a Supermicro
+ * SMC2108 with firmware 12.12.0-0095 which is a LSI 2108 based
+ * controller.
+ */
+ cfgidx = atoi(av[1]);
+ if (cfgidx >= info.count) {
+ warnx("Invalid foreign config %d specified max is %d",
+ cfgidx, info.count - 1);
+ close(fd);
+ return (EINVAL);
+ }
+ printf("Are you sure you wish to import the foreign "
+ "configuration %d on mfi%u? [y/N] ", cfgidx, mfi_unit);
+ }
+
+ ch = getchar();
+ if (ch != 'y' && ch != 'Y') {
+ printf("\nAborting\n");
+ close(fd);
+ return (0);
+ }
+
+ bzero(mbox, sizeof(mbox));
+ mbox[0] = cfgidx;
+ if (mfi_dcmd_command(fd, MFI_DCMD_CFG_FOREIGN_IMPORT, NULL, 0, mbox,
+ sizeof(mbox), NULL) < 0) {
+ error = errno;
+ warn("Failed to import foreign configuration");
+ close(fd);
+ return (error);
+ }
+
+ if (ac == 1)
+ printf("mfi%d: All foreign configurations imported\n",
+ mfi_unit);
+ else
+ printf("mfi%d: Foreign configuration %d imported\n", mfi_unit,
+ cfgidx);
+ close(fd);
+ return (0);
+}
+MFI_COMMAND(foreign, import, foreign_import);
diff --git a/usr.sbin/mfiutil/mfi_show.c b/usr.sbin/mfiutil/mfi_show.c
index 06721c2..6bb8612 100644
--- a/usr.sbin/mfiutil/mfi_show.c
+++ b/usr.sbin/mfiutil/mfi_show.c
@@ -40,9 +40,11 @@
#include <unistd.h>
#include "mfiutil.h"
+static const char* foreign_state = " (FOREIGN)";
+
MFI_TABLE(top, show);
-static void
+void
format_stripe(char *buf, size_t buflen, uint8_t stripe)
{
@@ -291,7 +293,7 @@ show_battery(int ac, char **av __unused)
}
MFI_COMMAND(show, battery, show_battery);
-static void
+void
print_ld(struct mfi_ld_info *info, int state_len)
{
struct mfi_ld_params *params = &info->ld_config.params;
@@ -312,19 +314,24 @@ print_ld(struct mfi_ld_info *info, int state_len)
mfi_ldstate(params->state));
}
-static void
+void
print_pd(struct mfi_pd_info *info, int state_len)
{
const char *s;
- char buf[6];
+ char buf[256];
humanize_number(buf, sizeof(buf), info->raw_size * 512, "",
HN_AUTOSCALE, HN_B | HN_NOSPACE |HN_DECIMAL);
printf("(%6s) ", buf);
+ if (info->state.ddf.v.pd_type.is_foreign) {
+ sprintf(buf, "%s%s", mfi_pdstate(info->fw_state), foreign_state);
+ s = buf;
+ } else
+ s = mfi_pdstate(info->fw_state);
if (state_len > 0)
- printf("%-*s", state_len, mfi_pdstate(info->fw_state));
+ printf("%-*s", state_len, s);
else
- printf("%s", mfi_pdstate(info->fw_state));
+ printf("%s",s);
s = mfi_pd_inq_string(info);
if (s != NULL)
printf(" %s", s);
@@ -560,6 +567,8 @@ show_drives(int ac, char **av __unused)
goto error;
}
len = strlen(mfi_pdstate(info.fw_state));
+ if (info.state.ddf.v.pd_type.is_foreign)
+ len += strlen(foreign_state);
if (len > state_len)
state_len = len;
}
@@ -757,7 +766,7 @@ show_progress(int ac, char **av __unused)
printf("drive %s ", mfi_drive_name(NULL, device_id,
MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
mfi_display_progress("Clear", &pinfo.prog_info.clear);
- busy = 1;
+
}
}
@@ -770,3 +779,10 @@ show_progress(int ac, char **av __unused)
return (0);
}
MFI_COMMAND(show, progress, show_progress);
+
+static int
+show_foreign(int ac, char **av)
+{
+ return(display_format(ac, av, 0/*normal display*/, MFI_DCMD_CFG_FOREIGN_DISPLAY));
+}
+MFI_COMMAND(show, foreign, show_foreign);
diff --git a/usr.sbin/mfiutil/mfiutil.8 b/usr.sbin/mfiutil/mfiutil.8
index 5468617..8346922 100644
--- a/usr.sbin/mfiutil/mfiutil.8
+++ b/usr.sbin/mfiutil/mfiutil.8
@@ -63,6 +63,9 @@
.Cm show firmware
.Nm
.Op Fl u Ar unit
+.Cm show foreign Op Ar volume
+.Nm
+.Op Fl u Ar unit
.Cm show logstate
.Nm
.Op Fl d
@@ -88,6 +91,9 @@
.Cm rebuild Ar drive
.Nm
.Op Fl u Ar unit
+.Cm syspd Ar drive
+.Nm
+.Op Fl u Ar unit
.Cm drive progress Ar drive
.Nm
.Op Fl u Ar unit
@@ -140,6 +146,21 @@
.Cm patrol Ar command Op Ar interval Op Ar start
.Nm
.Op Fl u Ar unit
+.Cm foreign scan
+.Nm
+.Op Fl u Ar unit
+.Cm foreign clear Op Ar config
+.Nm
+.Op Fl u Ar unit
+.Cm foreign diag Op Ar config
+.Nm
+.Op Fl u Ar unit
+.Cm foreign preview Op Ar config
+.Nm
+.Op Fl u Ar unit
+.Cm foreign import Op Ar config
+.Nm
+.Op Fl u Ar unit
.Cm flash Ar file
.Nm
.Op Fl u Ar unit
@@ -321,6 +342,8 @@ The entry in the event log corresponding to the most recent boot.
.El
.It Cm show firmware
Lists all of the firmware images present on the controller.
+.It Cm show foreign
+Displays detected foreign configurations on disks for importation or removal.
.It Cm show logstate
Display the various sequence numbers associated with the event log.
.It Cm show patrol
@@ -352,6 +375,11 @@ Mark a failed
that is still part of an array as a good drive suitable for a rebuild.
The firmware should kick off an array rebuild on its own if a failed drive
is marked as a rebuild drive.
+.It Cm syspd Ar drive
+Present the drive to the host operating system as a disk SYSPD block device in
+the format /dev/mfisyspdX. Clear this flag with
+.Cm good
+.Ar drive
.It Cm drive progress Ar drive
Report the current progress and estimated completion time of drive operations
such as rebuilds or patrol reads.
@@ -567,12 +595,45 @@ Enable manual patrol reads that are only initiated by the user.
Start a patrol read operation.
.It Cm stop patrol
Stop a currently running patrol read operation.
+.It Cm foreign scan
+Scan for foreign configurations and display the number found. The
+.Ar config
+argument for the commands below takes the form of a number from 0 to the total
+configurations found.
+.It Cm foreign clear Op config
+Clear the specifed foreign
+.Ar config
+or all if no
+.Ar config
+argument is provided.
+.It Cm foreign diag Op config
+Display a diagnostic display of the specifed foreign
+.Ar config
+or all if no
+.Ar config
+argument is provided.
+.It Cm foreign preview Op config
+Preview the specifed foreign
+.Ar config
+after import or all if no
+.Ar config
+argument is provided.
+.It Cm foreign import Op config
+Import the specifed foreign
+.Ar config
+or all if no
+.Ar config
+argument is provided.
.It Cm flash Ar file
Updates the flash on the controller with the firmware stored in
.Ar file .
A reboot is required for the new firmware to take effect.
.It Cm start learn
Start a battery relearn.
+Note that this seems to always result in the battery being completely drained,
+regardless of the BBU mode.
+In particular, the controller write cache will be disabled during the relearn
+even if transparent learning mode is enabled.
.It Cm bbu Ar setting Ar value
Update battery backup unit (BBU) properties related to battery relearning.
The following settings are configurable:
@@ -626,10 +687,18 @@ Add the drive in slot 2 in the main chassis as a hot spare for volume mfid0:
.Pp
.Dl Nm Cm add s2 mfid0
.Pp
+Reconfigure a disk as a SYSPD block device with no RAID
+.Pp
+.Dl Nm Cm syspd 0
+.Pp
Configure the adapter to run periodic patrol reads once a week with the first
patrol read starting in 5 minutes:
.Pp
.Dl Nm Cm patrol auto 604800 300
+.Pp
+Display the second detected foreign configuration:
+.Pp
+.Dl Nm Cm show foreign 1
.Sh SEE ALSO
.Xr mfi 4
.Sh HISTORY
diff --git a/usr.sbin/mfiutil/mfiutil.c b/usr.sbin/mfiutil/mfiutil.c
index 7488e24..a8d9ef8 100644
--- a/usr.sbin/mfiutil/mfiutil.c
+++ b/usr.sbin/mfiutil/mfiutil.c
@@ -60,13 +60,15 @@ usage(void)
fprintf(stderr, " show drives - list physical drives\n");
fprintf(stderr, " show events - display event log\n");
fprintf(stderr, " show firmware - list firmware images\n");
+ fprintf(stderr, " show foreign - display detected foreign volumes\n");
fprintf(stderr, " show logstate - display event log sequence numbers\n");
fprintf(stderr, " show volumes - list logical volumes\n");
fprintf(stderr, " show patrol - display patrol read status\n");
fprintf(stderr, " show progress - display status of active operations\n");
fprintf(stderr, " fail <drive> - fail a physical drive\n");
- fprintf(stderr, " good <drive> - mark a bad physical drive as good\n");
+ fprintf(stderr, " good <drive> - set a failed/SYSPD drive as UNCONFIGURED\n");
fprintf(stderr, " rebuild <drive> - mark failed drive ready for rebuild\n");
+ fprintf(stderr, " syspd <drive> - set drive into use as SYSPD JBOD\n");
fprintf(stderr, " drive progress <drive> - display status of active operations\n");
fprintf(stderr, " drive clear <drive> <start|stop> - clear a drive with all 0x00\n");
fprintf(stderr, " start rebuild <drive>\n");
@@ -83,6 +85,11 @@ usage(void)
fprintf(stderr, " patrol <disable|auto|manual> [interval [start]]\n");
fprintf(stderr, " start patrol - start a patrol read\n");
fprintf(stderr, " stop patrol - stop a patrol read\n");
+ fprintf(stderr, " foreign scan - scan for foreign configurations\n");
+ fprintf(stderr, " foreign clear [volume] - clear foreign configurations (default all)\n");
+ fprintf(stderr, " foreign diag [volume] - diagnostic display foreign configurations (default all)\n");
+ fprintf(stderr, " foreign preview [volume] - preview foreign configurations (default all)\n");
+ fprintf(stderr, " foreign import [volume] - import foreign configurations (default all)\n");
fprintf(stderr, " flash <firmware>\n");
fprintf(stderr, " start learn - start a BBU relearn\n");
fprintf(stderr, " bbu <setting> <value> - set BBU properties\n");
@@ -97,7 +104,7 @@ static int
version(int ac __unused, char **av __unused)
{
- printf("mfiutil version 1.0.14");
+ printf("mfiutil version 1.0.15");
#ifdef DEBUG
printf(" (DEBUG)");
#endif
diff --git a/usr.sbin/mfiutil/mfiutil.h b/usr.sbin/mfiutil/mfiutil.h
index 8a544c2..251816a 100644
--- a/usr.sbin/mfiutil/mfiutil.h
+++ b/usr.sbin/mfiutil/mfiutil.h
@@ -124,6 +124,16 @@ extern int mfi_unit;
extern u_int mfi_opts;
+/* We currently don't know the full details of the following struct */
+struct mfi_foreign_scan_cfg {
+ char data[24];
+};
+
+struct mfi_foreign_scan_info {
+ uint32_t count; /* Number of foreign configs found */
+ struct mfi_foreign_scan_cfg cfgs[8];
+};
+
void mbox_store_ldref(uint8_t *mbox, union mfi_ld_ref *ref);
void mbox_store_pdref(uint8_t *mbox, union mfi_pd_ref *ref);
void mfi_display_progress(const char *label, struct mfi_progress *prog);
@@ -136,6 +146,8 @@ const char *mfi_pd_inq_string(struct mfi_pd_info *info);
const char *mfi_volume_name(int fd, uint8_t target_id);
int mfi_volume_busy(int fd, uint8_t target_id);
int mfi_config_read(int fd, struct mfi_config_data **configp);
+int mfi_config_read_opcode(int fd, uint32_t opcode,
+ struct mfi_config_data **configp, uint8_t *mbox, size_t mboxlen);
int mfi_lookup_drive(int fd, char *drive, uint16_t *device_id);
int mfi_lookup_volume(int fd, const char *name, uint8_t *target_id);
int mfi_dcmd_command(int fd, uint32_t opcode, void *buf, size_t bufsize,
@@ -152,6 +164,10 @@ int mfi_reconfig_supported(void);
const char *mfi_status(u_int status_code);
const char *mfi_drive_name(struct mfi_pd_info *pinfo, uint16_t device_id,
uint32_t def);
+void format_stripe(char *buf, size_t buflen, uint8_t stripe);
+void print_ld(struct mfi_ld_info *info, int state_len);
+void print_pd(struct mfi_pd_info *info, int state_len);
+void dump_config(int fd, struct mfi_config_data *config, const char *msg_prefix);
int mfi_bbu_get_props(int fd, struct mfi_bbu_properties *props,
uint8_t *statusp);
int mfi_bbu_set_props(int fd, struct mfi_bbu_properties *props,
@@ -163,4 +179,5 @@ void mfi_autolearn_mode(uint8_t, char *, size_t);
void scan_firmware(struct mfi_info_component *comp);
void display_firmware(struct mfi_info_component *comp, const char *tag);
+int display_format(int ac, char **av, int diagnostic, mfi_dcmd_t display_cmd);
#endif /* !__MFIUTIL_H__ */
diff --git a/usr.sbin/named/Makefile b/usr.sbin/named/Makefile
index 4743a7b..f092880 100644
--- a/usr.sbin/named/Makefile
+++ b/usr.sbin/named/Makefile
@@ -42,7 +42,10 @@ SRCS+= builtin.c client.c config.c control.c \
lwaddr.c lwresd.c lwdclient.c lwderror.c lwdgabn.c \
lwdgnba.c lwdgrbn.c lwdnoop.c lwsearch.c
-CFLAGS+= -DCONFIGARGS="\"${CONFIGARGS}\""
+CFLAGS+= -DCONFIGARGS="\"${CONFIGARGS}\"" \
+ -DPRODUCT=\"${PRODUCT}\" \
+ -DDESCRIPTION=\"${DESCRIPTION}\" \
+ -DSRCID=\"${SRCID}\"
CFLAGS+= -I${SRCDIR}/unix/include -I${SRCDIR}/include -I${LIB_BIND_DIR}
CFLAGS+= -I${BIND_DIR}/lib/isc/${ISC_ATOMIC_ARCH}/include
diff --git a/usr.sbin/nandsim/nandsim_cfgparse.c b/usr.sbin/nandsim/nandsim_cfgparse.c
index d6a7cd6..a965034 100644
--- a/usr.sbin/nandsim/nandsim_cfgparse.c
+++ b/usr.sbin/nandsim/nandsim_cfgparse.c
@@ -130,7 +130,7 @@ static struct nandsim_key nandsim_chip_keys[] = {
{NULL, 0, 0, NULL, 0},
};
-struct nandsim_section sections[] = {
+static struct nandsim_section sections[] = {
{"ctrl", (struct nandsim_key *)&nandsim_ctrl_keys},
{"chip", (struct nandsim_key *)&nandsim_chip_keys},
{NULL, NULL},
@@ -575,7 +575,7 @@ parse_config(char *cfgfname, const char *devfname)
/*
* Function tries to get appropriate value for given key, convert it to
- * array of ints (of given size), and perform all the neccesary checks and
+ * array of ints (of given size), and perform all the necessary checks and
* conversions.
*/
static int
diff --git a/usr.sbin/ndiscvt/inf-token.l b/usr.sbin/ndiscvt/inf-token.l
index 1f290e1..3e2a127 100644
--- a/usr.sbin/ndiscvt/inf-token.l
+++ b/usr.sbin/ndiscvt/inf-token.l
@@ -43,8 +43,6 @@ __FBSDID("$FreeBSD$");
#include "y.tab.h"
int lineno = 1;
-#define YY_NO_UNPUT
-#define YY_NO_INPUT
int yylex(void);
void yyerror(const char *);
@@ -59,6 +57,9 @@ update_lineno(const char *cp)
%}
+%option nounput
+%option noinput
+
%%
[ \t]+ ;
diff --git a/usr.sbin/ndp/ndp.8 b/usr.sbin/ndp/ndp.8
index 223cfba..19da8bb 100644
--- a/usr.sbin/ndp/ndp.8
+++ b/usr.sbin/ndp/ndp.8
@@ -222,6 +222,36 @@ Specify the Cur Hop Limit on the interface.
Do not try to resolve numeric addresses to hostnames.
.It Fl p
Show prefix list.
+The following information will be printed:
+.Bl -tag -width indent
+.It Cm if
+The network interface associated with this prefix.
+.It Cm flags
+The status of the prefix, expressed by a combination of the following
+letters:
+.Pp
+.Bl -tag -width indent -compact
+.It Cm A
+This prefix can be used for stateless address autoconfiguration.
+.It Cm L, Cm O
+This prefix can be used for on-link determination; that is, it can be
+used to determine whether a given destination address is on-link.
+.It Cm D
+There are no reachable routers advertising this prefix.
+.El
+.It Cm vltime
+Valid lifetime; the length of time for which the prefix and a stateless
+autoconfigured address generated from this prefix can be used for the
+source or destination address of a packet.
+.It Cm pltime
+Preferred lifetime; the length of time for which the prefix and a stateless
+autoconfigured address generated from this prefix can be used by upper-layer
+protocols unrestrictedly.
+.It Cm expire
+This is the remaining time that the prefix is in the valid state.
+.It Cm ref
+The number of kernel references held for this prefix.
+.El
.It Fl P
Flush all the entries in the prefix list.
.It Fl r
diff --git a/usr.sbin/ndp/ndp.c b/usr.sbin/ndp/ndp.c
index 0449c12..2ff1e31 100644
--- a/usr.sbin/ndp/ndp.c
+++ b/usr.sbin/ndp/ndp.c
@@ -367,7 +367,8 @@ getsocket()
struct sockaddr_in6 so_mask = {sizeof(so_mask), AF_INET6 };
struct sockaddr_in6 blank_sin = {sizeof(blank_sin), AF_INET6 }, sin_m;
struct sockaddr_dl blank_sdl = {sizeof(blank_sdl), AF_LINK }, sdl_m;
-int expire_time, flags, found_entry;
+time_t expire_time;
+int flags, found_entry;
struct {
struct rt_msghdr m_rtm;
char m_space[512];
@@ -412,10 +413,10 @@ set(argc, argv)
flags = expire_time = 0;
while (argc-- > 0) {
if (strncmp(argv[0], "temp", 4) == 0) {
- struct timeval time;
+ struct timeval now;
- gettimeofday(&time, 0);
- expire_time = time.tv_sec + 20 * 60;
+ gettimeofday(&now, 0);
+ expire_time = now.tv_sec + 20 * 60;
} else if (strncmp(argv[0], "proxy", 5) == 0)
flags |= RTF_ANNOUNCE;
argv++;
@@ -566,7 +567,7 @@ dump(addr, cflag)
struct sockaddr_dl *sdl;
extern int h_errno;
struct in6_nbrinfo *nbi;
- struct timeval time;
+ struct timeval now;
int addrwidth;
int llwidth;
int ifwidth;
@@ -653,9 +654,9 @@ again:;
#endif
continue;
}
- gettimeofday(&time, 0);
+ gettimeofday(&now, 0);
if (tflag)
- ts_print(&time);
+ ts_print(&now);
addrwidth = strlen(host_buf);
if (addrwidth < W_ADDR)
@@ -676,9 +677,9 @@ again:;
/* Print neighbor discovery specific informations */
nbi = getnbrinfo(&sin->sin6_addr, sdl->sdl_index, 1);
if (nbi) {
- if (nbi->expire > time.tv_sec) {
+ if (nbi->expire > now.tv_sec) {
printf(" %-9.9s",
- sec2str(nbi->expire - time.tv_sec));
+ sec2str(nbi->expire - now.tv_sec));
} else if (nbi->expire == 0)
printf(" %-9.9s", "permanent");
else
@@ -1075,7 +1076,7 @@ rtrlist()
char *buf;
struct in6_defrouter *p, *ep;
size_t l;
- struct timeval time;
+ struct timeval now;
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) {
err(1, "sysctl(ICMPV6CTL_ND6_DRLIST)");
@@ -1110,18 +1111,18 @@ rtrlist()
rtpref = ((p->flags & ND_RA_FLAG_RTPREF_MASK) >> 3) & 0xff;
printf(", pref=%s", rtpref_str[rtpref]);
- gettimeofday(&time, 0);
+ gettimeofday(&now, 0);
if (p->expire == 0)
printf(", expire=Never\n");
else
printf(", expire=%s\n",
- sec2str(p->expire - time.tv_sec));
+ sec2str(p->expire - now.tv_sec));
}
free(buf);
#else
struct in6_drlist dr;
int s, i;
- struct timeval time;
+ struct timeval now;
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
err(1, "socket");
@@ -1150,12 +1151,12 @@ rtrlist()
printf(", flags=%s%s",
DR.flags & ND_RA_FLAG_MANAGED ? "M" : "",
DR.flags & ND_RA_FLAG_OTHER ? "O" : "");
- gettimeofday(&time, 0);
+ gettimeofday(&now, 0);
if (DR.expire == 0)
printf(", expire=Never\n");
else
printf(", expire=%s\n",
- sec2str(DR.expire - time.tv_sec));
+ sec2str(DR.expire - now.tv_sec));
}
#undef DR
close(s);
@@ -1171,7 +1172,7 @@ plist()
struct in6_prefix *p, *ep, *n;
struct sockaddr_in6 *advrtr;
size_t l;
- struct timeval time;
+ struct timeval now;
const int niflags = NI_NUMERICHOST;
int ninflags = nflag ? NI_NUMERICHOST : 0;
char namebuf[NI_MAXHOST];
@@ -1202,7 +1203,7 @@ plist()
printf("%s/%d if=%s\n", namebuf, p->prefixlen,
if_indextoname(p->if_index, ifix_buf));
- gettimeofday(&time, 0);
+ gettimeofday(&now, 0);
/*
* meaning of fields, especially flags, is very different
* by origin. notify the difference to the users.
@@ -1228,9 +1229,9 @@ plist()
printf(", pltime=%lu", (unsigned long)p->pltime);
if (p->expire == 0)
printf(", expire=Never");
- else if (p->expire >= time.tv_sec)
+ else if (p->expire >= now.tv_sec)
printf(", expire=%s",
- sec2str(p->expire - time.tv_sec));
+ sec2str(p->expire - now.tv_sec));
else
printf(", expired");
printf(", ref=%d", p->refcnt);
@@ -1278,9 +1279,9 @@ plist()
#else
struct in6_prlist pr;
int s, i;
- struct timeval time;
+ struct timeval now;
- gettimeofday(&time, 0);
+ gettimeofday(&now, 0);
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
err(1, "socket");
@@ -1316,7 +1317,7 @@ plist()
printf("%s/%d if=%s\n", namebuf, PR.prefixlen,
if_indextoname(PR.if_index, ifix_buf));
- gettimeofday(&time, 0);
+ gettimeofday(&now, 0);
/*
* meaning of fields, especially flags, is very different
* by origin. notify the difference to the users.
@@ -1352,9 +1353,9 @@ plist()
printf(", pltime=%lu", PR.pltime);
if (PR.expire == 0)
printf(", expire=Never");
- else if (PR.expire >= time.tv_sec)
+ else if (PR.expire >= now.tv_sec)
printf(", expire=%s",
- sec2str(PR.expire - time.tv_sec));
+ sec2str(PR.expire - now.tv_sec));
else
printf(", expired");
#ifdef NDPRF_ONLINK
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c
index 08598ac..69a63c4 100644
--- a/usr.sbin/newsyslog/newsyslog.c
+++ b/usr.sbin/newsyslog/newsyslog.c
@@ -1083,7 +1083,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p,
* at any time, etc).
*/
if (strcasecmp(DEBUG_MARKER, q) == 0) {
- q = parse = missing_field(sob(++parse), errline);
+ q = parse = missing_field(sob(parse + 1), errline);
parse = son(parse);
if (!*parse)
warnx("debug line specifies no option:\n%s",
@@ -1096,7 +1096,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p,
} else if (strcasecmp(INCLUDE_MARKER, q) == 0) {
if (verbose)
printf("Found: %s", errline);
- q = parse = missing_field(sob(++parse), errline);
+ q = parse = missing_field(sob(parse + 1), errline);
parse = son(parse);
if (!*parse) {
warnx("include line missing argument:\n%s",
@@ -1138,7 +1138,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p,
defconf_p = working;
}
- q = parse = missing_field(sob(++parse), errline);
+ q = parse = missing_field(sob(parse + 1), errline);
parse = son(parse);
if (!*parse)
errx(1, "malformed line (missing fields):\n%s",
@@ -1172,7 +1172,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p,
} else
working->gid = (gid_t)-1;
- q = parse = missing_field(sob(++parse), errline);
+ q = parse = missing_field(sob(parse + 1), errline);
parse = son(parse);
if (!*parse)
errx(1, "malformed line (missing fields):\n%s",
@@ -1187,7 +1187,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p,
errx(1, "error in config file; bad permissions:\n%s",
errline);
- q = parse = missing_field(sob(++parse), errline);
+ q = parse = missing_field(sob(parse + 1), errline);
parse = son(parse);
if (!*parse)
errx(1, "malformed line (missing fields):\n%s",
@@ -1197,7 +1197,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p,
errx(1, "error in config file; bad value for count of logs to save:\n%s",
errline);
- q = parse = missing_field(sob(++parse), errline);
+ q = parse = missing_field(sob(parse + 1), errline);
parse = son(parse);
if (!*parse)
errx(1, "malformed line (missing fields):\n%s",
@@ -1215,7 +1215,7 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p,
working->flags = 0;
working->compress = COMPRESS_NONE;
- q = parse = missing_field(sob(++parse), errline);
+ q = parse = missing_field(sob(parse + 1), errline);
parse = son(parse);
eol = !*parse;
*parse = '\0';
@@ -1257,7 +1257,7 @@ no_trimat:
if (eol)
q = NULL;
else {
- q = parse = sob(++parse); /* Optional field */
+ q = parse = sob(parse + 1); /* Optional field */
parse = son(parse);
if (!*parse)
eol = 1;
@@ -1327,7 +1327,7 @@ no_trimat:
if (eol)
q = NULL;
else {
- q = parse = sob(++parse); /* Optional field */
+ q = parse = sob(parse + 1); /* Optional field */
parse = son(parse);
if (!*parse)
eol = 1;
@@ -1348,7 +1348,7 @@ no_trimat:
if (eol)
q = NULL;
else {
- q = parse = sob(++parse); /* Optional field */
+ q = parse = sob(parse + 1); /* Optional field */
*(parse = son(parse)) = '\0';
}
@@ -1452,16 +1452,27 @@ oldlog_entry_compare(const void *a, const void *b)
* tm if this is the case; otherwise return false.
*/
static int
-validate_old_timelog(const struct dirent *dp, const char *logfname, struct tm *tm)
+validate_old_timelog(int fd, const struct dirent *dp, const char *logfname,
+ struct tm *tm)
{
+ struct stat sb;
size_t logfname_len;
char *s;
int c;
logfname_len = strlen(logfname);
- if (dp->d_type != DT_REG)
- return (0);
+ if (dp->d_type != DT_REG) {
+ /*
+ * Some filesystems (e.g. NFS) don't fill out the d_type field
+ * and leave it set to DT_UNKNOWN; in this case we must obtain
+ * the file type ourselves.
+ */
+ if (dp->d_type != DT_UNKNOWN ||
+ fstatat(fd, dp->d_name, &sb, AT_SYMLINK_NOFOLLOW) != 0 ||
+ !S_ISREG(sb.st_mode))
+ return (0);
+ }
/* Ignore everything but files with our logfile prefix. */
if (strncmp(dp->d_name, logfname, logfname_len) != 0)
return (0);
@@ -1547,7 +1558,7 @@ delete_oldest_timelog(const struct conf_entry *ent, const char *archive_dir)
err(1, "Cannot open log directory '%s'", dir);
dir_fd = dirfd(dirp);
while ((dp = readdir(dirp)) != NULL) {
- if (validate_old_timelog(dp, logfname, &tm) == 0)
+ if (validate_old_timelog(dir_fd, dp, logfname, &tm) == 0)
continue;
/*
@@ -2312,10 +2323,10 @@ mtime_old_timelog(const char *file)
dir_fd = dirfd(dirp);
/* Open the archive dir and find the most recent archive of logfname. */
while ((dp = readdir(dirp)) != NULL) {
- if (validate_old_timelog(dp, logfname, &tm) == 0)
+ if (validate_old_timelog(dir_fd, dp, logfname, &tm) == 0)
continue;
- if (fstatat(dir_fd, logfname, &sb, 0) == -1) {
+ if (fstatat(dir_fd, dp->d_name, &sb, AT_SYMLINK_NOFOLLOW) == -1) {
warn("Cannot stat '%s'", file);
continue;
}
diff --git a/usr.sbin/nfsd/nfsv4.4 b/usr.sbin/nfsd/nfsv4.4
index 679bb69..8d9bc80 100644
--- a/usr.sbin/nfsd/nfsv4.4
+++ b/usr.sbin/nfsd/nfsv4.4
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd December 23, 2012
+.Dd July 1, 2013
.Dt NFSV4 4
.Os
.Sh NAME
@@ -233,6 +233,20 @@ plus set ``tcp'' and
The
.Xr nfsuserd 8
must be running, as above.
+Also, since an
+.Nm
+mount uses the host uuid to identify the client uniquely to the server,
+you cannot safely do an
+.Nm
+mount when
+.sp
+.Bd -literal -offset indent -compact
+hostid_enable="NO"
+.Ed
+.sp
+is set in
+.Xr rc.conf 5 .
+.sp
If the
.Nm
server that is being mounted on supports delegations, you can start the
@@ -287,6 +301,13 @@ and
daemons at boot time via the ``nfsuserd_flags'' and ``nfscbd_flags''
.Xr rc.conf 5
variables.
+.Pp
+NFSv4 mount(s) against exported volume(s) on the same host are not recommended,
+since this can result in a hung NFS server.
+It occurs when an nfsd thread tries to do an NFSv4 VOP_RECLAIM()/Close RPC
+as part of acquiring a new vnode.
+If all other nfsd threads are blocked waiting for lock(s) held by this nfsd
+thread, then there isn't an nfsd thread to service the Close RPC.
.Sh FILES
.Bl -tag -width /var/db/nfs-stablerestart.bak -compact
.It Pa /var/db/nfs-stablerestart
diff --git a/usr.sbin/nvram/nvram.c b/usr.sbin/nvram/nvram.c
index a286ee3..52c1e80 100644
--- a/usr.sbin/nvram/nvram.c
+++ b/usr.sbin/nvram/nvram.c
@@ -51,7 +51,7 @@ struct deletelist {
struct deletelist *last;
};
-union {
+static union {
uint8_t buf[sizeof(struct chrp_header)];
struct chrp_header header;
} conv;
diff --git a/usr.sbin/pciconf/cap.c b/usr.sbin/pciconf/cap.c
index 1c2ab4a..d7296a3 100644
--- a/usr.sbin/pciconf/cap.c
+++ b/usr.sbin/pciconf/cap.c
@@ -276,6 +276,18 @@ cap_ht(int fd, struct pci_conf *p, uint8_t ptr)
case PCIM_HTCAP_X86_ENCODING:
printf("X86 encoding");
break;
+ case PCIM_HTCAP_GEN3:
+ printf("Gen3");
+ break;
+ case PCIM_HTCAP_FLE:
+ printf("function-level extension");
+ break;
+ case PCIM_HTCAP_PM:
+ printf("power management");
+ break;
+ case PCIM_HTCAP_HIGH_NODE_COUNT:
+ printf("high node count");
+ break;
default:
printf("unknown %02x", command);
break;
@@ -379,11 +391,27 @@ link_speed_string(uint8_t speed)
}
}
+static const char *
+aspm_string(uint8_t aspm)
+{
+
+ switch (aspm) {
+ case 1:
+ return ("L0s");
+ case 2:
+ return ("L1");
+ case 3:
+ return ("L0s/L1");
+ default:
+ return ("disabled");
+ }
+}
+
static void
cap_express(int fd, struct pci_conf *p, uint8_t ptr)
{
- uint32_t val;
- uint16_t flags;
+ uint32_t cap;
+ uint16_t ctl, flags, sta;
flags = read_config(fd, &p->pc_sel, ptr + PCIER_FLAGS, 2);
printf("PCI-Express %d ", flags & PCIEM_FLAGS_VERSION);
@@ -423,26 +451,28 @@ cap_express(int fd, struct pci_conf *p, uint8_t ptr)
printf(" slot");
if (flags & PCIEM_FLAGS_IRQ)
printf(" IRQ %d", (flags & PCIEM_FLAGS_IRQ) >> 9);
- val = read_config(fd, &p->pc_sel, ptr + PCIER_DEVICE_CAP, 4);
- flags = read_config(fd, &p->pc_sel, ptr + PCIER_DEVICE_CTL, 2);
+ cap = read_config(fd, &p->pc_sel, ptr + PCIER_DEVICE_CAP, 4);
+ ctl = read_config(fd, &p->pc_sel, ptr + PCIER_DEVICE_CTL, 2);
printf(" max data %d(%d)",
- MAX_PAYLOAD((flags & PCIEM_CTL_MAX_PAYLOAD) >> 5),
- MAX_PAYLOAD(val & PCIEM_CAP_MAX_PAYLOAD));
- if (val & PCIEM_CAP_FLR)
+ MAX_PAYLOAD((ctl & PCIEM_CTL_MAX_PAYLOAD) >> 5),
+ MAX_PAYLOAD(cap & PCIEM_CAP_MAX_PAYLOAD));
+ if ((cap & PCIEM_CAP_FLR) != 0)
printf(" FLR");
- val = read_config(fd, &p->pc_sel, ptr + PCIER_LINK_CAP, 4);
- flags = read_config(fd, &p->pc_sel, ptr+ PCIER_LINK_STA, 2);
- printf(" link x%d(x%d)", (flags & PCIEM_LINK_STA_WIDTH) >> 4,
- (val & PCIEM_LINK_CAP_MAX_WIDTH) >> 4);
- /*
- * Only print link speed info if the link's max width is
- * greater than 0.
- */
- if ((val & PCIEM_LINK_CAP_MAX_WIDTH) != 0) {
- printf("\n speed");
- printf(" %s(%s)", (flags & PCIEM_LINK_STA_WIDTH) == 0 ?
- "0.0" : link_speed_string(flags & PCIEM_LINK_STA_SPEED),
- link_speed_string(val & PCIEM_LINK_CAP_MAX_SPEED));
+ cap = read_config(fd, &p->pc_sel, ptr + PCIER_LINK_CAP, 4);
+ sta = read_config(fd, &p->pc_sel, ptr + PCIER_LINK_STA, 2);
+ printf(" link x%d(x%d)", (sta & PCIEM_LINK_STA_WIDTH) >> 4,
+ (cap & PCIEM_LINK_CAP_MAX_WIDTH) >> 4);
+ if ((cap & (PCIEM_LINK_CAP_MAX_WIDTH | PCIEM_LINK_CAP_ASPM)) != 0)
+ printf("\n ");
+ if ((cap & PCIEM_LINK_CAP_MAX_WIDTH) != 0) {
+ printf(" speed %s(%s)", (sta & PCIEM_LINK_STA_WIDTH) == 0 ?
+ "0.0" : link_speed_string(sta & PCIEM_LINK_STA_SPEED),
+ link_speed_string(cap & PCIEM_LINK_CAP_MAX_SPEED));
+ }
+ if ((cap & PCIEM_LINK_CAP_ASPM) != 0) {
+ ctl = read_config(fd, &p->pc_sel, ptr + PCIER_LINK_CTL, 2);
+ printf(" ASPM %s(%s)", aspm_string(ctl & PCIEM_LINK_CTL_ASPMC),
+ aspm_string((cap & PCIEM_LINK_CAP_ASPM) >> 10));
}
}
diff --git a/usr.sbin/periodic/periodic.sh b/usr.sbin/periodic/periodic.sh
index cfe6109..c27aeee 100644
--- a/usr.sbin/periodic/periodic.sh
+++ b/usr.sbin/periodic/periodic.sh
@@ -21,7 +21,7 @@ output_pipe()
case "$output" in
/*) pipe="cat >>$output";;
"") pipe=cat;;
- *) pipe="mail -E -s '$host ${1##*/} run output' $output";;
+ *) pipe="mail -E -s '$host ${2}${2:+ }${1##*/} run output' $output";;
esac
eval $pipe
}
@@ -53,12 +53,13 @@ if [ $1 != "LOCKED" ]; then
case $? in
0) ;;
73) #EX_CANTCREATE
- echo "can't create ${lockfile}" | output_pipe $arg
+ echo "can't create ${lockfile}" | \
+ output_pipe $arg "$PERIODIC"
ret=1
;;
75) #EX_TEMPFAIL
echo "$host ${arg##*/} prior run still in progress" | \
- output_pipe $arg
+ output_pipe $arg "$PERIODIC"
ret=1
;;
*)
@@ -76,6 +77,8 @@ shift
arg=$1
tmp_output=`mktemp ${TMPDIR:-/tmp}/periodic.XXXXXXXXXX`
+context="$PERIODIC"
+export PERIODIC="$arg${PERIODIC:+ }${PERIODIC}"
# Execute each executable file in the directory list. If the x bit is not
# set, assume the user didn't really want us to muck with it (it's a
@@ -135,6 +138,6 @@ esac
echo ""
echo "-- End of $arg output --"
fi
-} | output_pipe ${arg}
+} | output_pipe $arg "$context"
rm -f $tmp_output
diff --git a/usr.sbin/pkg/config.c b/usr.sbin/pkg/config.c
index 5924d57..142fd1b 100644
--- a/usr.sbin/pkg/config.c
+++ b/usr.sbin/pkg/config.c
@@ -108,7 +108,7 @@ pkg_get_myabi(char *dest, size_t sz)
Elf_Note note;
Elf_Scn *scn;
char *src, *osname;
- const char *abi;
+ const char *abi, *fpu;
GElf_Ehdr elfhdr;
GElf_Shdr shdr;
int fd, i, ret;
@@ -187,13 +187,25 @@ pkg_get_myabi(char *dest, size_t sz)
switch (elfhdr.e_machine) {
case EM_ARM:
+ /* FreeBSD doesn't support the hard-float ABI yet */
+ fpu = "softfp";
+ if ((elfhdr.e_flags & 0xFF000000) != 0) {
+ /* This is an EABI file, the conformance level is set */
+ abi = "eabi";
+ } else if (elfhdr.e_ident[EI_OSABI] != ELFOSABI_NONE) {
+ /*
+ * EABI executables all have this field set to
+ * ELFOSABI_NONE, therefore it must be an oabi file.
+ */
+ abi = "oabi";
+ } else {
+ ret = 1;
+ goto cleanup;
+ }
snprintf(dest + strlen(dest), sz - strlen(dest),
":%s:%s:%s", elf_corres_to_string(endian_corres,
(int)elfhdr.e_ident[EI_DATA]),
- (elfhdr.e_flags & EF_ARM_NEW_ABI) > 0 ?
- "eabi" : "oabi",
- (elfhdr.e_flags & EF_ARM_VFP_FLOAT) > 0 ?
- "softfp" : "vfp");
+ abi, fpu);
break;
case EM_MIPS:
/*
diff --git a/usr.sbin/pkg/dns_utils.c b/usr.sbin/pkg/dns_utils.c
index 239be90..cbdb3d5 100644
--- a/usr.sbin/pkg/dns_utils.c
+++ b/usr.sbin/pkg/dns_utils.c
@@ -66,7 +66,7 @@ dns_getsrvinfo(const char *zone)
p += len + NS_QFIXEDSZ;
}
- res = calloc(ancount, sizeof(struct dns_srvinfo));
+ res = calloc(ancount, sizeof(struct dns_srvinfo *));
if (res == NULL)
return (NULL);
diff --git a/usr.sbin/pkg_install/add/extract.c b/usr.sbin/pkg_install/add/extract.c
index 9769464..9913126 100644
--- a/usr.sbin/pkg_install/add/extract.c
+++ b/usr.sbin/pkg_install/add/extract.c
@@ -110,7 +110,8 @@ extract_plist(const char *home, Package *pkg)
PackingList p = pkg->head;
char *last_file, *prefix = NULL;
char *where_args, *perm_args, *last_chdir;
- int maxargs, where_count = 0, perm_count = 0, add_count;
+ long maxargs;
+ int where_count = 0, perm_count = 0, add_count;
Boolean preserve;
maxargs = sysconf(_SC_ARG_MAX) / 2; /* Just use half the argument space */
diff --git a/usr.sbin/pkg_install/add/main.c b/usr.sbin/pkg_install/add/main.c
index c91c8b6..548f92e 100644
--- a/usr.sbin/pkg_install/add/main.c
+++ b/usr.sbin/pkg_install/add/main.c
@@ -90,6 +90,7 @@ struct {
{ 803000, 803499, "/packages-8.3-release" },
{ 900000, 900499, "/packages-9.0-release" },
{ 901000, 901499, "/packages-9.1-release" },
+ { 902000, 902499, "/packages-9.2-release" },
{ 300000, 399000, "/packages-3-stable" },
{ 400000, 499000, "/packages-4-stable" },
{ 502100, 502128, "/packages-5-current" },
diff --git a/usr.sbin/pkg_install/create/pl.c b/usr.sbin/pkg_install/create/pl.c
index 716fd05..1316eda 100644
--- a/usr.sbin/pkg_install/create/pl.c
+++ b/usr.sbin/pkg_install/create/pl.c
@@ -140,7 +140,8 @@ copy_plist(const char *home, Package *plist)
const char *there = NULL, *mythere;
char *where_args, *prefix = NULL;
const char *last_chdir, *root = "/";
- int maxargs, where_count = 0, add_count;
+ long maxargs;
+ int where_count = 0, add_count;
struct stat stb;
dev_t curdir;
diff --git a/usr.sbin/pkg_install/lib/exec.c b/usr.sbin/pkg_install/lib/exec.c
index 0804501..c0b4ac3 100644
--- a/usr.sbin/pkg_install/lib/exec.c
+++ b/usr.sbin/pkg_install/lib/exec.c
@@ -34,7 +34,8 @@ vsystem(const char *fmt, ...)
{
va_list args;
char *cmd;
- int ret, maxargs;
+ long maxargs;
+ int ret;
maxargs = sysconf(_SC_ARG_MAX);
maxargs -= 32; /* some slop for the sh -c */
@@ -64,7 +65,7 @@ vpipe(const char *fmt, ...)
{
FILE *fp;
char *cmd, *rp;
- int maxargs;
+ long maxargs;
va_list args;
rp = malloc(MAXPATHLEN);
diff --git a/usr.sbin/pkg_install/version/pkg_version.1 b/usr.sbin/pkg_install/version/pkg_version.1
index 26caf8c..42f4bfc 100644
--- a/usr.sbin/pkg_install/version/pkg_version.1
+++ b/usr.sbin/pkg_install/version/pkg_version.1
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd November 9, 2012
+.Dd May 18, 2013
.Dt PKG_VERSION 1
.Os
.Sh NAME
@@ -72,7 +72,7 @@ cannot be located,
.Nm
will search for the package in the ports collection index file
(typically
-.Pa /usr/ports/INDEX-8 ) .
+.Pa /usr/ports/INDEX-10 ) .
Any matching version number(s) there will be used to determine whether
the installed package is up-to-date or requires updating.
.Pp
@@ -205,12 +205,12 @@ can be used here.
If no
.Ar index
file is specified on the command line,
-.Pa /usr/ports/INDEX-8
+.Pa /usr/ports/INDEX-10
is used.
.El
.Sh FILES
-.Bl -tag -width /usr/ports/INDEX-8 -compact
-.It Pa /usr/ports/INDEX-8
+.Bl -tag -width /usr/ports/INDEX-10 -compact
+.It Pa /usr/ports/INDEX-10
Default index file.
.El
.Sh EXAMPLES
@@ -224,7 +224,7 @@ index file:
The command below generates a report against
the version numbers in the on-line ports collection:
.Pp
-.Dl % pkg_version http://www.FreeBSD.org/ports/INDEX-8
+.Dl % pkg_version http://www.FreeBSD.org/ports/INDEX-10
.Pp
The following command compares two package version strings:
.Pp
diff --git a/usr.sbin/pmcannotate/pmcannotate.c b/usr.sbin/pmcannotate/pmcannotate.c
index 0a9d0d7..374290f 100644
--- a/usr.sbin/pmcannotate/pmcannotate.c
+++ b/usr.sbin/pmcannotate/pmcannotate.c
@@ -118,8 +118,6 @@ isasminline(const char *str)
void *ptr;
int nbytes;
- if (isxdigit(str[1]) == 0)
- return (0);
if (sscanf(str, " %p%n", &ptr, &nbytes) != 1)
return (0);
if (str[nbytes] != ':' || isspace(str[nbytes + 1]) == 0)
diff --git a/usr.sbin/portsnap/portsnap/portsnap.8 b/usr.sbin/portsnap/portsnap/portsnap.8
index da94efc..baa1a57 100644
--- a/usr.sbin/portsnap/portsnap/portsnap.8
+++ b/usr.sbin/portsnap/portsnap/portsnap.8
@@ -169,7 +169,9 @@ If your clock is set to local time, adding the line
.Pp
.Dl 0 3 * * * root /usr/sbin/portsnap cron
.Pp
-to /etc/crontab is a good way to make sure you always have
+to
+.Pa /etc/crontab
+is a good way to make sure you always have
an up-to-date snapshot of the ports tree available which
can quickly be extracted into
.Pa /usr/ports .
@@ -247,11 +249,11 @@ may be published, but only in aggregate and after anonymizing the
individual systems.
.Sh FILES
.Bl -tag -width "/etc/portsnap.conf"
-.It /etc/portsnap.conf
+.It Pa /etc/portsnap.conf
Default location of the portsnap configuration file.
-.It /var/db/portsnap
+.It Pa /var/db/portsnap
Default location where compressed snapshots are stored.
-.It /usr/ports
+.It Pa /usr/ports
Default location where the ports tree is extracted.
.El
.Sh SEE ALSO
diff --git a/usr.sbin/portsnap/portsnap/portsnap.sh b/usr.sbin/portsnap/portsnap/portsnap.sh
index f9f4716..14e5441 100644
--- a/usr.sbin/portsnap/portsnap/portsnap.sh
+++ b/usr.sbin/portsnap/portsnap/portsnap.sh
@@ -864,8 +864,8 @@ fetch_update() {
echo "done."
# Remove files which are no longer needed
- cut -f 2 -d '|' tINDEX INDEX | sort > oldfiles
- cut -f 2 -d '|' tINDEX.new INDEX.new | sort | comm -13 - oldfiles |
+ cut -f 2 -d '|' tINDEX INDEX | sort -u > oldfiles
+ cut -f 2 -d '|' tINDEX.new INDEX.new | sort -u | comm -13 - oldfiles |
lam -s "files/" - -s ".gz" | xargs rm -f
rm patchlist filelist oldfiles
@@ -1113,7 +1113,7 @@ cmd_alfred() {
else
cmd_cron
fi
- if [ -d ${PORTSDIR} ]; then
+ if [ -r ${PORTSDIR}/.portsnap.INDEX ]; then
cmd_update
else
cmd_extract
diff --git a/usr.sbin/powerd/powerd.8 b/usr.sbin/powerd/powerd.8
index 0991bce..853282c 100644
--- a/usr.sbin/powerd/powerd.8
+++ b/usr.sbin/powerd/powerd.8
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd December 21, 2009
+.Dd July 4, 2013
.Dt POWERD 8
.Os
.Sh NAME
@@ -47,27 +47,43 @@ The
.Nm
utility monitors the system state and sets various power control options
accordingly.
-It offers four modes (maximum, minimum, adaptive and hiadaptive) that can be
-individually selected while on AC power or batteries.
-The modes maximum, minimum, adaptive and hiadaptive may be abbreviated
-max, min, adp, hadp.
-.Pp
-Maximum mode chooses the highest performance values.
-Minimum mode selects the lowest performance values to get the most power
-savings.
-Adaptive mode attempts to strike a balance by degrading performance when
-the system appears idle and increasing it when the system is busy.
+It offers power-saving modes that can be
+individually selected for operation on AC power or batteries.
+.Bl -tag -width ".Ar hiadaptive"
+.It Ar maximum
+Choose the highest performance values.
+May be abbreviated as
+.Ar max .
+.It Ar minimum
+Choose the lowest performance values to get the most power savings.
+May be abbreviated as
+.Ar min .
+.It Ar adaptive
+Attempt to strike a balance by degrading performance when the system
+appears idle and increasing it when the system is busy.
It offers a good balance between a small performance loss for greatly
increased power savings.
-Hiadaptive mode is like adaptive mode, but tuned for systems where
-performance and interactivity are more important than power consumption.
-It increases frequency faster, reduces the frequency less aggressively and
+May be abbreviated as
+.Ar adp .
+.It Ar hiadaptive
+Like
+.Ar adaptive
+mode, but tuned for systems where performance and interactivity are
+more important than power consumption.
+It increases frequency faster, reduces frequency less aggressively, and
will maintain full frequency for longer.
-The default mode is adaptive for battery power and hiadaptive for the rest.
+May be abbreviated as
+.Ar hadp .
+.El
+.Pp
+The default mode is
+.Ar adaptive
+for battery power and
+.Ar hiadaptive
+for the rest.
.Pp
-The
.Nm
-utility recognizes the following runtime options:
+recognizes these runtime options:
.Bl -tag -width ".Fl r Ar percent"
.It Fl a Ar mode
Selects the
diff --git a/usr.sbin/powerd/powerd.c b/usr.sbin/powerd/powerd.c
index 254c237..2c6eac2 100644
--- a/usr.sbin/powerd/powerd.c
+++ b/usr.sbin/powerd/powerd.c
@@ -154,7 +154,7 @@ read_usage_times(int *load)
error = sysctl(cp_times_mib, 2, cp_times, &cp_times_len, NULL, 0);
if (error)
return (error);
-
+
if (load) {
*load = 0;
for (cpu = 0; cpu < ncpus; cpu++) {
@@ -165,7 +165,7 @@ read_usage_times(int *load)
}
if (total == 0)
continue;
- *load += 100 - (cp_times[cpu * CPUSTATES + CP_IDLE] -
+ *load += 100 - (cp_times[cpu * CPUSTATES + CP_IDLE] -
cp_times_old[cpu * CPUSTATES + CP_IDLE]) * 100 / total;
}
}
@@ -236,7 +236,7 @@ get_freq(void)
{
size_t len;
int curfreq;
-
+
len = sizeof(curfreq);
if (sysctl(freq_mib, 4, &curfreq, &len, NULL, 0) != 0) {
if (vflag)
@@ -262,7 +262,7 @@ static int
get_freq_id(int freq, int *freqs, int numfreqs)
{
int i = 1;
-
+
while (i < numfreqs) {
if (freqs[i] < freq)
break;
@@ -717,7 +717,7 @@ main(int argc, char * argv[])
idle = 0;
if (set_freq(freq) != 0) {
warn("error setting CPU freq %d",
- freq);
+ freq);
continue;
}
}
@@ -730,7 +730,7 @@ main(int argc, char * argv[])
warn("read_usage_times() failed");
continue;
}
-
+
if (mode == MODE_ADAPTIVE) {
if (load > cpu_running_mark) {
if (load > 95 || load > cpu_running_mark * 2)
@@ -741,7 +741,7 @@ main(int argc, char * argv[])
freq = freqs[0];
} else if (load < cpu_idle_mark &&
curfreq * load < freqs[get_freq_id(
- freq * 7 / 8, freqs, numfreqs)] *
+ freq * 7 / 8, freqs, numfreqs)] *
cpu_running_mark) {
freq = freq * 7 / 8;
if (freq < freqs[numfreqs - 1])
@@ -757,7 +757,7 @@ main(int argc, char * argv[])
freq = freqs[0] * 2;
} else if (load < cpu_idle_mark / 2 &&
curfreq * load < freqs[get_freq_id(
- freq * 31 / 32, freqs, numfreqs)] *
+ freq * 31 / 32, freqs, numfreqs)] *
cpu_running_mark / 2) {
freq = freq * 31 / 32;
if (freq < freqs[numfreqs - 1])
diff --git a/usr.sbin/ppp/Makefile b/usr.sbin/ppp/Makefile
index 11003d7..9943665 100644
--- a/usr.sbin/ppp/Makefile
+++ b/usr.sbin/ppp/Makefile
@@ -44,13 +44,6 @@ M4FLAGS=
LDADD= -lcrypt -lmd -lutil -lz
DPADD= ${LIBCRYPT} ${LIBMD} ${LIBUTIL} ${LIBZ}
-.SUFFIXES: .8 .8.m4
-
-.8.m4.8:
- m4 ${M4FLAGS} ${.IMPSRC} >${.TARGET}
-
-CLEANFILES= ppp.8
-
.if defined(PPP_CONFDIR) && !empty(PPP_CONFDIR)
CFLAGS+=-DPPP_CONFDIR=\"${PPP_CONFDIR}\"
.endif
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c
index 91fe028..6bdf0c9 100644
--- a/usr.sbin/ppp/command.c
+++ b/usr.sbin/ppp/command.c
@@ -416,7 +416,7 @@ DialCommand(struct cmdargs const *arg)
static char *
strstrword(char *big, const char *little)
{
- /* Get the first occurrance of the word ``little'' in ``big'' */
+ /* Get the first occurrence of the word ``little'' in ``big'' */
char *pos;
int len;
diff --git a/usr.sbin/ppp/defs.c b/usr.sbin/ppp/defs.c
index dcd9e47..856c200 100644
--- a/usr.sbin/ppp/defs.c
+++ b/usr.sbin/ppp/defs.c
@@ -43,7 +43,7 @@
#include <sys/module.h>
#endif
#include <termios.h>
-#if !defined(__FreeBSD__) || __FreeBSD__ < 3
+#ifndef __FreeBSD__
#include <time.h>
#endif
#include <unistd.h>
@@ -56,20 +56,11 @@
#define issep(c) ((c) == '\t' || (c) == ' ')
-#if defined(__NetBSD__) || __FreeBSD__ < 3
+#ifdef __NetBSD__
void
randinit()
{
-#if defined(__FreeBSD__)
- static int initdone; /* srandomdev() call is only required once */
-
- if (!initdone) {
- initdone = 1;
- srandomdev();
- }
-#else
srandom((time(NULL)^getpid())+random());
-#endif
}
#endif
diff --git a/usr.sbin/ppp/defs.h b/usr.sbin/ppp/defs.h
index d7cc799..d320a53 100644
--- a/usr.sbin/ppp/defs.h
+++ b/usr.sbin/ppp/defs.h
@@ -117,7 +117,7 @@
#define ROUNDUP(x) ((x) ? (1 + (((x) - 1) | (sizeof(long) - 1))) : sizeof(long))
-#if defined(__NetBSD__) || __FreeBSD__ < 3
+#ifdef __NetBSD__
extern void randinit(void);
#else
#define random arc4random
diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8
index 91b9c51..7358a48 100644
--- a/usr.sbin/ppp/ppp.8.m4
+++ b/usr.sbin/ppp/ppp.8
@@ -1,5 +1,3 @@
-changequote({,})dnl
-changecom(,)dnl
.\"
.\" Copyright (c) 2001 Brian Somers <brian@Awfulhak.org>
.\" All rights reserved.
@@ -65,10 +63,9 @@ This allows
.Nm
to act as a NAT or masquerading engine for all machines on an internal
LAN.
-ifdef({LOCALNAT},{},{Refer to
+Refer to
.Xr libalias 3
for details on the technical side of the NAT engine.
-})dnl
Refer to the
.Sx NETWORK ADDRESS TRANSLATION (PACKET ALIASING)
section of this manual page for details on how to configure NAT in
@@ -313,14 +310,13 @@ An extension to PAP and CHAP,
allows authentication information to be stored in a central or
distributed database along with various per-user framed connection
characteristics.
-ifdef({LOCALRAD},{},{If
+If
.Xr libradius 3
is available at compile time,
.Nm
will use it to make
.Em RADIUS
requests when configured to do so.
-})dnl
.It Supports Proxy Arp.
.Nm
can be configured to make one or more proxy arp entries on behalf of
@@ -3018,9 +3014,9 @@ The option can only be enabled if network address translation is enabled
With this option enabled,
.Nm
will pass traffic for old interface addresses through the NAT
-ifdef({LOCALNAT},{engine,},{engine
+engine
(see
-.Xr libalias 3 ) ,})
+.Xr libalias 3 ) ,
resulting in the ability (in
.Fl auto
mode) to properly connect the process that caused the PPP link to
@@ -3428,18 +3424,17 @@ you wish to map to specific machines behind your gateway.
.It nat deny_incoming yes|no
If set to yes, this command will refuse all incoming packets where an
aliasing link does not already exist.
-ifdef({LOCALNAT},{},{Refer to the
+Refer to the
.Sx CONCEPTUAL BACKGROUND
section of
.Xr libalias 3
for a description of what an
.Dq aliasing link
is.
-})dnl
.Pp
It should be noted under what circumstances an aliasing link is
-ifdef({LOCALNAT},{created.},{created by
-.Xr libalias 3 .})
+created by
+.Xr libalias 3 .
It may be necessary to further protect your network from outside
connections using the
.Dq set filter
@@ -3524,12 +3519,11 @@ for example:
This command tells
.Nm
to proxy certain connections, redirecting them to a given server.
-ifdef({LOCALNAT},{},{Refer to the description of
+Refer to the description of
.Fn PacketAliasProxyRule
in
.Xr libalias 3
for details of the available commands.
-})dnl
.It nat punch_fw Op Ar base count
This command tells
.Nm
@@ -3567,9 +3561,8 @@ if you want to support protocols such as RPC and LPD which require
connections to come from a well known port.
.It nat target Op Ar address
Set the given target address or clear it if no address is given.
-The target address is used
-ifdef({LOCALNAT},{},{by libalias })dnl
-to specify how to NAT incoming packets by default.
+The target address is used by libalias to specify how to NAT incoming packets
+by default.
If a target address is not set or if
.Dq default
is given, packets are not altered and are allowed to route to the internal
@@ -3577,10 +3570,7 @@ network.
.Pp
The target address may be set to
.Dq MYADDR ,
-in which case
-ifdef({LOCALNAT},{all packets will be redirected},
-{libalias will redirect all packets})
-to the interface address.
+in which case libalias will redirect all packets to the interface address.
.It nat use_sockets yes|no
When enabled, this option tells the network address translation engine to
create a socket so that it can guarantee a correct incoming ftp data or
@@ -6055,10 +6045,8 @@ This socket is used to pass links between different instances of
.Xr kldload 2 ,
.Xr pipe 2 ,
.Xr socketpair 2 ,
-ifdef({LOCALNAT},{},{.Xr libalias 3 ,
-})dnl
-ifdef({LOCALRAD},{},{.Xr libradius 3 ,
-})dnl
+.Xr libalias 3 ,
+.Xr libradius 3 ,
.Xr syslog 3 ,
.Xr uucplock 3 ,
.Xr netgraph 4 ,
diff --git a/usr.sbin/pw/pw.conf.5 b/usr.sbin/pw/pw.conf.5
index 3f023aa..61c40e8 100644
--- a/usr.sbin/pw/pw.conf.5
+++ b/usr.sbin/pw/pw.conf.5
@@ -32,7 +32,7 @@
.Nd format of the pw.conf configuration file
.Sh DESCRIPTION
The file
-.In /etc/pw.conf
+.Pa /etc/pw.conf
contains configuration data for the
.Xr pw 8
utility.
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c
index 5f4d7a9..def238c 100644
--- a/usr.sbin/pw/pw_user.c
+++ b/usr.sbin/pw/pw_user.c
@@ -200,7 +200,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
strlcpy(dbuf, cnf->home, sizeof(dbuf));
p = dbuf;
if (stat(dbuf, &st) == -1) {
- while ((p = strchr(++p, '/')) != NULL) {
+ while ((p = strchr(p + 1, '/')) != NULL) {
*p = '\0';
if (stat(dbuf, &st) == -1) {
if (mkdir(dbuf, _DEF_DIRMODE) == -1)
@@ -513,8 +513,6 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
time_t now = time(NULL);
time_t expire = parse_date(now, arg->val);
- if (now == expire)
- errx(EX_DATAERR, "invalid password change date `%s'", arg->val);
if (pwd->pw_change != expire) {
pwd->pw_change = expire;
edited = 1;
@@ -533,8 +531,6 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
time_t now = time(NULL);
time_t expire = parse_date(now, arg->val);
- if (now == expire)
- errx(EX_DATAERR, "invalid account expiry date `%s'", arg->val);
if (pwd->pw_expire != expire) {
pwd->pw_expire = expire;
edited = 1;
@@ -577,7 +573,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
lc = login_getpwclass(pwd);
if (lc == NULL ||
- login_setcryptfmt(lc, "md5", NULL) == NULL)
+ login_setcryptfmt(lc, "sha512", NULL) == NULL)
warn("setting crypt(3) format");
login_close(lc);
pwd->pw_passwd = pw_password(cnf, args, pwd->pw_name);
diff --git a/usr.sbin/rrenumd/lexer.l b/usr.sbin/rrenumd/lexer.l
index bd0d3c0..6e55f9e 100644
--- a/usr.sbin/rrenumd/lexer.l
+++ b/usr.sbin/rrenumd/lexer.l
@@ -32,8 +32,6 @@
*/
%{
-#define YY_NO_UNPUT
-
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -64,6 +62,8 @@ void yyerror(const char *);
int yylex(void);
%}
+%option nounput
+
/* common section */
nl \n
ws [ \t]+
diff --git a/usr.sbin/rtadvctl/rtadvctl.c b/usr.sbin/rtadvctl/rtadvctl.c
index adc87b5..3f22518 100644
--- a/usr.sbin/rtadvctl/rtadvctl.c
+++ b/usr.sbin/rtadvctl/rtadvctl.c
@@ -55,6 +55,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <syslog.h>
+#include <time.h>
#include <err.h>
#include "pathnames.h"
@@ -416,6 +417,7 @@ action_show(int argc, char **argv)
char argv_dnssl[IFNAMSIZ + sizeof(":dnssl=")];
char ssbuf[SSBUFLEN];
+ struct timespec now, ts0, ts;
struct ctrl_msg_pl cp;
struct ifinfo *ifi;
TAILQ_HEAD(, ifinfo) ifl = TAILQ_HEAD_INITIALIZER(ifl);
@@ -464,6 +466,10 @@ action_show(int argc, char **argv)
}
}
+ clock_gettime(CLOCK_REALTIME_FAST, &now);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &ts);
+ TS_SUB(&now, &ts, &ts0);
+
TAILQ_FOREACH(ifi, &ifl, ifi_next) {
struct ifinfo *ifi_s;
struct rtadvd_timer *rat;
@@ -615,12 +621,20 @@ action_show(int argc, char **argv)
rat = (struct rtadvd_timer *)cp.cp_val;
}
- printf("\tNext RA send: %s",
- (rat == NULL) ? "never\n" :
- ctime((time_t *)&rat->rat_tm.tv_sec));
- printf("\tLast RA sent: %s",
- (ifi_s->ifi_ra_lastsent.tv_sec == 0) ? "never\n" :
- ctime((time_t *)&ifi_s->ifi_ra_lastsent.tv_sec));
+ printf("\tNext RA send: ");
+ if (rat == NULL)
+ printf("never\n");
+ else {
+ ts.tv_sec = rat->rat_tm.tv_sec + ts0.tv_sec;
+ printf("%s", ctime(&ts.tv_sec));
+ }
+ printf("\tLast RA send: ");
+ if (ifi_s->ifi_ra_lastsent.tv_sec == 0)
+ printf("never\n");
+ else {
+ ts.tv_sec = ifi_s->ifi_ra_lastsent.tv_sec + ts0.tv_sec;
+ printf("%s", ctime(&ts.tv_sec));
+ }
if (rai->rai_clockskew)
printf("\tClock skew: %" PRIu16 "sec\n",
rai->rai_clockskew);
@@ -747,9 +761,9 @@ action_show_prefix(struct prefix *pfx)
{
char ntopbuf[INET6_ADDRSTRLEN];
char ssbuf[SSBUFLEN];
- struct timeval now;
+ struct timespec now;
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
printf("\t %s/%d", inet_ntop(AF_INET6, &pfx->pfx_prefix,
ntopbuf, sizeof(ntopbuf)), pfx->pfx_prefixlen);
@@ -800,7 +814,7 @@ action_show_prefix(struct prefix *pfx)
printf("<none>");
if (pfx->pfx_timer) {
- struct timeval *rest;
+ struct timespec *rest;
rest = rtadvd_timer_rest(pfx->pfx_timer);
if (rest) { /* XXX: what if not? */
diff --git a/usr.sbin/rtadvd/config.c b/usr.sbin/rtadvd/config.c
index 605d76b..f0e11a3 100644
--- a/usr.sbin/rtadvd/config.c
+++ b/usr.sbin/rtadvd/config.c
@@ -34,7 +34,6 @@
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
-#include <sys/time.h>
#include <net/if.h>
#include <net/if_var.h>
@@ -58,6 +57,7 @@
#include <string.h>
#include <search.h>
#include <stdlib.h>
+#include <time.h>
#include <unistd.h>
#include <ifaddrs.h>
@@ -296,10 +296,8 @@ rm_rainfo(struct rainfo *rai)
if (rai->rai_ra_data != NULL)
free(rai->rai_ra_data);
- while ((pfx = TAILQ_FIRST(&rai->rai_prefix)) != NULL) {
- TAILQ_REMOVE(&rai->rai_prefix, pfx, pfx_next);
- free(pfx);
- }
+ while ((pfx = TAILQ_FIRST(&rai->rai_prefix)) != NULL)
+ delete_prefix(pfx);
while ((sol = TAILQ_FIRST(&rai->rai_soliciter)) != NULL) {
TAILQ_REMOVE(&rai->rai_soliciter, sol, sol_next);
free(sol);
@@ -563,8 +561,9 @@ getconfig(struct ifinfo *ifi)
makeentry(entbuf, sizeof(entbuf), i, "vltimedecr");
if (agetflag(entbuf)) {
- struct timeval now;
- gettimeofday(&now, 0);
+ struct timespec now;
+
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
pfx->pfx_vltimeexpire =
now.tv_sec + pfx->pfx_validlifetime;
}
@@ -583,8 +582,9 @@ getconfig(struct ifinfo *ifi)
makeentry(entbuf, sizeof(entbuf), i, "pltimedecr");
if (agetflag(entbuf)) {
- struct timeval now;
- gettimeofday(&now, 0);
+ struct timespec now;
+
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
pfx->pfx_pltimeexpire =
now.tv_sec + pfx->pfx_preflifetime;
}
@@ -1123,9 +1123,9 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr)
pfx->pfx_onlinkflg = ipr->ipr_raf_onlink;
pfx->pfx_autoconfflg = ipr->ipr_raf_auto;
pfx->pfx_origin = PREFIX_FROM_DYNAMIC;
+ pfx->pfx_rainfo = rai;
TAILQ_INSERT_TAIL(&rai->rai_prefix, pfx, pfx_next);
- pfx->pfx_rainfo = rai;
syslog(LOG_DEBUG, "<%s> new prefix %s/%d was added on %s",
__func__,
@@ -1164,7 +1164,7 @@ delete_prefix(struct prefix *pfx)
void
invalidate_prefix(struct prefix *pfx)
{
- struct timeval timo;
+ struct timespec timo;
struct rainfo *rai;
struct ifinfo *ifi;
char ntopbuf[INET6_ADDRSTRLEN];
@@ -1191,7 +1191,7 @@ invalidate_prefix(struct prefix *pfx)
delete_prefix(pfx);
}
timo.tv_sec = prefix_timo;
- timo.tv_usec = 0;
+ timo.tv_nsec = 0;
rtadvd_set_timer(&timo, pfx->pfx_timer);
}
@@ -1286,7 +1286,7 @@ make_prefix(struct rainfo *rai, int ifindex, struct in6_addr *addr, int plen)
memset(&ipr, 0, sizeof(ipr));
if (if_indextoname(ifindex, ipr.ipr_name) == NULL) {
- syslog(LOG_ERR, "<%s> Prefix added interface No.%d doesn't"
+ syslog(LOG_ERR, "<%s> Prefix added interface No.%d doesn't "
"exist. This should not happen! %s", __func__,
ifindex, strerror(errno));
exit(1);
@@ -1415,7 +1415,7 @@ make_packet(struct rainfo *rai)
TAILQ_FOREACH(pfx, &rai->rai_prefix, pfx_next) {
uint32_t vltime, pltime;
- struct timeval now;
+ struct timespec now;
ndopt_pi = (struct nd_opt_prefix_info *)buf;
ndopt_pi->nd_opt_pi_type = ND_OPT_PREFIX_INFORMATION;
@@ -1432,7 +1432,7 @@ make_packet(struct rainfo *rai)
vltime = 0;
else {
if (pfx->pfx_vltimeexpire || pfx->pfx_pltimeexpire)
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
if (pfx->pfx_vltimeexpire == 0)
vltime = pfx->pfx_validlifetime;
else
diff --git a/usr.sbin/rtadvd/if.c b/usr.sbin/rtadvd/if.c
index b857356..5413cdf 100644
--- a/usr.sbin/rtadvd/if.c
+++ b/usr.sbin/rtadvd/if.c
@@ -394,8 +394,8 @@ update_ifinfo_nd_flags(struct ifinfo *ifi)
error = ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd);
if (error) {
close(s);
- syslog(LOG_ERR,
- "<%s> ioctl() failed.", __func__);
+ if (errno != EPFNOSUPPORT)
+ syslog(LOG_ERR, "<%s> ioctl() failed.", __func__);
return (1);
}
ifi->ifi_nd_flags = nd.ndi.flags;
diff --git a/usr.sbin/rtadvd/rrenum.c b/usr.sbin/rtadvd/rrenum.c
index 3e36311..0c97d98 100644
--- a/usr.sbin/rtadvd/rrenum.c
+++ b/usr.sbin/rtadvd/rrenum.c
@@ -49,6 +49,7 @@
#include <netdb.h>
#include <string.h>
#include <stdlib.h>
+#include <time.h>
#include <syslog.h>
#include "rtadvd.h"
#include "rrenum.h"
@@ -215,7 +216,7 @@ do_use_prefix(int len, struct rr_pco_match *rpm,
rai = ifi->ifi_rainfo;
TAILQ_FOREACH(pfx, &rai->rai_prefix, pfx_next) {
- struct timeval now;
+ struct timespec now;
if (prefix_match(&pfx->pfx_prefix,
pfx->pfx_prefixlen, &rpm->rpm_prefix,
@@ -226,14 +227,16 @@ do_use_prefix(int len, struct rr_pco_match *rpm,
pfx->pfx_preflifetime =
ntohl(rpu->rpu_pltime);
if (irr->irr_rrf_decrvalid) {
- gettimeofday(&now, 0);
+ clock_gettime(CLOCK_MONOTONIC_FAST,
+ &now);
pfx->pfx_vltimeexpire =
now.tv_sec +
pfx->pfx_validlifetime;
} else
pfx->pfx_vltimeexpire = 0;
if (irr->irr_rrf_decrprefd) {
- gettimeofday(&now, 0);
+ clock_gettime(CLOCK_MONOTONIC_FAST,
+ &now);
pfx->pfx_pltimeexpire =
now.tv_sec +
pfx->pfx_preflifetime;
@@ -325,7 +328,7 @@ do_rr(int len, struct icmp6_router_renum *rr)
if ((size_t)len < sizeof(struct rr_pco_match)) {
tooshort:
syslog(LOG_ERR, "<%s> pkt too short. left len = %d. "
- "gabage at end of pkt?", __func__, len);
+ "garbage at end of pkt?", __func__, len);
return (1);
}
rpmlen = rpm->rpm_len << 3;
diff --git a/usr.sbin/rtadvd/rtadvd.c b/usr.sbin/rtadvd/rtadvd.c
index 880b283..ba71954 100644
--- a/usr.sbin/rtadvd/rtadvd.c
+++ b/usr.sbin/rtadvd/rtadvd.c
@@ -35,7 +35,6 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/uio.h>
-#include <sys/time.h>
#include <sys/queue.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
@@ -95,7 +94,7 @@ struct sockaddr_in6 rcvfrom;
static const char *pidfilename = _PATH_RTADVDPID;
const char *conffile = _PATH_RTADVDCONF;
static struct pidfh *pfh;
-int dflag = 0, sflag = 0;
+static int dflag, sflag;
static int wait_shutdown;
#define PFD_RAWSOCK 0
@@ -139,7 +138,7 @@ union nd_opt {
#define NDOPT_FLAG_RDNSS (1 << 5)
#define NDOPT_FLAG_DNSSL (1 << 6)
-uint32_t ndopt_flags[] = {
+static uint32_t ndopt_flags[] = {
[ND_OPT_SOURCE_LINKADDR] = NDOPT_FLAG_SRCLINKADDR,
[ND_OPT_TARGET_LINKADDR] = NDOPT_FLAG_TGTLINKADDR,
[ND_OPT_PREFIX_INFORMATION] = NDOPT_FLAG_PREFIXINFO,
@@ -179,7 +178,7 @@ int
main(int argc, char *argv[])
{
struct pollfd set[PFD_MAX];
- struct timeval *timeout;
+ struct timespec *timeout;
int i, ch;
int fflag = 0, logopt;
int error;
@@ -331,7 +330,7 @@ main(int argc, char *argv[])
"<%s> set timer to %ld:%ld. waiting for "
"inputs or timeout", __func__,
(long int)timeout->tv_sec,
- (long int)timeout->tv_usec);
+ (long int)timeout->tv_nsec / 1000);
} else {
syslog(LOG_DEBUG,
"<%s> there's no timer. waiting for inputs",
@@ -339,7 +338,7 @@ main(int argc, char *argv[])
}
if ((i = poll(set, sizeof(set)/sizeof(set[0]),
timeout ? (timeout->tv_sec * 1000 +
- timeout->tv_usec / 1000) : INFTIM)) < 0) {
+ timeout->tv_nsec / 1000 / 1000) : INFTIM)) < 0) {
/* EINTR would occur if a signal was delivered */
if (errno != EINTR)
@@ -432,7 +431,7 @@ rtadvd_shutdown(void)
if (ifi->ifi_ra_timer == NULL)
continue;
if (ifi->ifi_ra_lastsent.tv_sec == 0 &&
- ifi->ifi_ra_lastsent.tv_usec == 0 &&
+ ifi->ifi_ra_lastsent.tv_nsec == 0 &&
ifi->ifi_ra_timer != NULL) {
/*
* When RA configured but never sent,
@@ -1006,7 +1005,7 @@ static void
set_short_delay(struct ifinfo *ifi)
{
long delay; /* must not be greater than 1000000 */
- struct timeval interval, now, min_delay, tm_tmp, *rest;
+ struct timespec interval, now, min_delay, tm_tmp, *rest;
if (ifi->ifi_ra_timer == NULL)
return;
@@ -1023,9 +1022,9 @@ set_short_delay(struct ifinfo *ifi)
delay = random() % MAX_RA_DELAY_TIME;
#endif
interval.tv_sec = 0;
- interval.tv_usec = delay;
+ interval.tv_nsec = delay * 1000;
rest = rtadvd_timer_rest(ifi->ifi_ra_timer);
- if (TIMEVAL_LT(rest, &interval)) {
+ if (TS_CMP(rest, &interval, <)) {
syslog(LOG_DEBUG, "<%s> random delay is larger than "
"the rest of the current timer", __func__);
interval = *rest;
@@ -1038,13 +1037,13 @@ set_short_delay(struct ifinfo *ifi)
* MIN_DELAY_BETWEEN_RAS plus the random value after the
* previous advertisement was sent.
*/
- gettimeofday(&now, NULL);
- TIMEVAL_SUB(&now, &ifi->ifi_ra_lastsent, &tm_tmp);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
+ TS_SUB(&now, &ifi->ifi_ra_lastsent, &tm_tmp);
min_delay.tv_sec = MIN_DELAY_BETWEEN_RAS;
- min_delay.tv_usec = 0;
- if (TIMEVAL_LT(&tm_tmp, &min_delay)) {
- TIMEVAL_SUB(&min_delay, &tm_tmp, &min_delay);
- TIMEVAL_ADD(&min_delay, &interval, &interval);
+ min_delay.tv_nsec = 0;
+ if (TS_CMP(&tm_tmp, &min_delay, <)) {
+ TS_SUB(&min_delay, &tm_tmp, &min_delay);
+ TS_ADD(&min_delay, &interval, &interval);
}
rtadvd_set_timer(&interval, ifi->ifi_ra_timer);
}
@@ -1242,7 +1241,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
int inconsistent = 0;
char ntopbuf[INET6_ADDRSTRLEN];
char prefixbuf[INET6_ADDRSTRLEN];
- struct timeval now;
+ struct timespec now;
#if 0 /* impossible */
if (pinfo->nd_opt_pi_type != ND_OPT_PREFIX_INFORMATION)
@@ -1285,7 +1284,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
* XXX: can we really expect that all routers on the link
* have synchronized clocks?
*/
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
preferred_time += now.tv_sec;
if (!pfx->pfx_timer && rai->rai_clockskew &&
@@ -1318,7 +1317,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
valid_time = ntohl(pinfo->nd_opt_pi_valid_time);
if (pfx->pfx_vltimeexpire) {
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
valid_time += now.tv_sec;
if (!pfx->pfx_timer && rai->rai_clockskew &&
@@ -1637,6 +1636,11 @@ struct ifinfo *
if_indextoifinfo(int idx)
{
struct ifinfo *ifi;
+ char *name, name0[IFNAMSIZ];
+
+ /* Check if the interface has a valid name or not. */
+ if (if_indextoname(idx, name0) == NULL)
+ return (NULL);
TAILQ_FOREACH(ifi, &ifilist, ifi_next) {
if (ifi->ifi_ifindex == idx)
@@ -1779,7 +1783,7 @@ ra_output(struct ifinfo *ifi)
}
/* update timestamp */
- gettimeofday(&ifi->ifi_ra_lastsent, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &ifi->ifi_ra_lastsent);
/* update counter */
ifi->ifi_rs_waitcount = 0;
@@ -1861,7 +1865,7 @@ ra_timeout(void *arg)
/* update RA timer */
void
-ra_timer_update(void *arg, struct timeval *tm)
+ra_timer_update(void *arg, struct timespec *tm)
{
uint16_t interval;
struct rainfo *rai;
@@ -1911,12 +1915,12 @@ ra_timer_update(void *arg, struct timeval *tm)
}
tm->tv_sec = interval;
- tm->tv_usec = 0;
+ tm->tv_nsec = 0;
syslog(LOG_DEBUG,
"<%s> RA timer on %s is set to %ld:%ld",
__func__, ifi->ifi_ifname,
- (long int)tm->tv_sec, (long int)tm->tv_usec);
+ (long int)tm->tv_sec, (long int)tm->tv_nsec / 1000);
return;
}
diff --git a/usr.sbin/rtadvd/rtadvd.h b/usr.sbin/rtadvd/rtadvd.h
index ac8ce99..e7ed87f 100644
--- a/usr.sbin/rtadvd/rtadvd.h
+++ b/usr.sbin/rtadvd/rtadvd.h
@@ -270,7 +270,7 @@ struct ifinfo {
uint32_t ifi_burstinterval;
struct rtadvd_timer *ifi_ra_timer;
/* timestamp when the latest RA was sent */
- struct timeval ifi_ra_lastsent;
+ struct timespec ifi_ra_lastsent;
uint16_t ifi_rs_waitcount;
/* statistics */
@@ -286,7 +286,7 @@ extern TAILQ_HEAD(ifilist_head_t, ifinfo) ifilist;
extern char *mcastif;
struct rtadvd_timer *ra_timeout(void *);
-void ra_timer_update(void *, struct timeval *);
+void ra_timer_update(void *, struct timespec *);
void ra_output(struct ifinfo *);
int prefix_match(struct in6_addr *, int,
diff --git a/usr.sbin/rtadvd/timer.c b/usr.sbin/rtadvd/timer.c
index 2ea77b5..452add4 100644
--- a/usr.sbin/rtadvd/timer.c
+++ b/usr.sbin/rtadvd/timer.c
@@ -31,7 +31,6 @@
* SUCH DAMAGE.
*/
-#include <sys/time.h>
#include <sys/queue.h>
#include <sys/socket.h>
@@ -44,6 +43,7 @@
#include <stdlib.h>
#include <string.h>
#include <search.h>
+#include <time.h>
#include <netdb.h>
#include "rtadvd.h"
@@ -52,13 +52,15 @@
struct rtadvd_timer_head_t ra_timer =
TAILQ_HEAD_INITIALIZER(ra_timer);
-static struct timeval tm_limit = {0x7fffffff, 0x7fffffff};
-static struct timeval tm_max;
+static struct timespec tm_limit;
+static struct timespec tm_max;
void
rtadvd_timer_init(void)
{
-
+ /* Generate maximum time in timespec. */
+ tm_limit.tv_sec = (-1) & ~((time_t)1 << ((sizeof(tm_max.tv_sec) * 8) - 1));
+ tm_limit.tv_nsec = (-1) & ~((long)1 << ((sizeof(tm_max.tv_nsec) * 8) - 1));
tm_max = tm_limit;
TAILQ_INIT(&ra_timer);
}
@@ -102,7 +104,7 @@ rtadvd_update_timeout_handler(void)
struct rtadvd_timer *
rtadvd_add_timer(struct rtadvd_timer *(*timeout)(void *),
- void (*update)(void *, struct timeval *),
+ void (*update)(void *, struct timespec *),
void *timeodata, void *updatedata)
{
struct rtadvd_timer *rat;
@@ -149,48 +151,48 @@ rtadvd_remove_timer(struct rtadvd_timer *rat)
* call the expire function for the timer and update the timer.
* Return the next interval for select() call.
*/
-struct timeval *
+struct timespec *
rtadvd_check_timer(void)
{
- static struct timeval returnval;
- struct timeval now;
+ static struct timespec returnval;
+ struct timespec now;
struct rtadvd_timer *rat;
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
tm_max = tm_limit;
TAILQ_FOREACH(rat, &ra_timer, rat_next) {
- if (TIMEVAL_LEQ(&rat->rat_tm, &now)) {
+ if (TS_CMP(&rat->rat_tm, &now, <=)) {
if (((*rat->rat_expire)(rat->rat_expire_data) == NULL))
continue; /* the timer was removed */
if (rat->rat_update)
(*rat->rat_update)(rat->rat_update_data, &rat->rat_tm);
- TIMEVAL_ADD(&rat->rat_tm, &now, &rat->rat_tm);
+ TS_ADD(&rat->rat_tm, &now, &rat->rat_tm);
}
- if (TIMEVAL_LT(&rat->rat_tm, &tm_max))
+ if (TS_CMP(&rat->rat_tm, &tm_max, <))
tm_max = rat->rat_tm;
}
- if (TIMEVAL_EQUAL(&tm_max, &tm_limit)) {
+ if (TS_CMP(&tm_max, &tm_limit, ==)) {
/* no need to timeout */
return (NULL);
- } else if (TIMEVAL_LT(&tm_max, &now)) {
+ } else if (TS_CMP(&tm_max, &now, <)) {
/* this may occur when the interval is too small */
- returnval.tv_sec = returnval.tv_usec = 0;
+ returnval.tv_sec = returnval.tv_nsec = 0;
} else
- TIMEVAL_SUB(&tm_max, &now, &returnval);
+ TS_SUB(&tm_max, &now, &returnval);
return (&returnval);
}
void
-rtadvd_set_timer(struct timeval *tm, struct rtadvd_timer *rat)
+rtadvd_set_timer(struct timespec *tm, struct rtadvd_timer *rat)
{
- struct timeval now;
+ struct timespec now;
/* reset the timer */
- gettimeofday(&now, NULL);
- TIMEVAL_ADD(&now, tm, &rat->rat_tm);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
+ TS_ADD(&now, tm, &rat->rat_tm);
/* update the next expiration time */
- if (TIMEVAL_LT(&rat->rat_tm, &tm_max))
+ if (TS_CMP(&rat->rat_tm, &tm_max, <))
tm_max = rat->rat_tm;
return;
diff --git a/usr.sbin/rtadvd/timer.h b/usr.sbin/rtadvd/timer.h
index f70e0d1..4498aaf 100644
--- a/usr.sbin/rtadvd/timer.h
+++ b/usr.sbin/rtadvd/timer.h
@@ -35,18 +35,18 @@ struct rtadvd_timer {
TAILQ_ENTRY(rtadvd_timer) rat_next;
struct rainfo *rat_rai;
- struct timeval rat_tm;
+ struct timespec rat_tm;
struct rtadvd_timer *(*rat_expire)(void *);
void *rat_expire_data;
- void (*rat_update)(void *, struct timeval *);
+ void (*rat_update)(void *, struct timespec *);
void *rat_update_data;
};
void rtadvd_timer_init(void);
void rtadvd_update_timeout_handler(void);
struct rtadvd_timer *rtadvd_add_timer(struct rtadvd_timer *(*)(void *),
- void (*)(void *, struct timeval *), void *, void *);
-void rtadvd_set_timer(struct timeval *,
+ void (*)(void *, struct timespec *), void *, void *);
+void rtadvd_set_timer(struct timespec *,
struct rtadvd_timer *);
void rtadvd_remove_timer(struct rtadvd_timer *);
-struct timeval *rtadvd_check_timer(void);
+struct timespec *rtadvd_check_timer(void);
diff --git a/usr.sbin/rtadvd/timer_subr.c b/usr.sbin/rtadvd/timer_subr.c
index 2bebdd3..0ddf0a4 100644
--- a/usr.sbin/rtadvd/timer_subr.c
+++ b/usr.sbin/rtadvd/timer_subr.c
@@ -30,69 +30,34 @@
* SUCH DAMAGE.
*/
-#include <sys/time.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <syslog.h>
#include <stdio.h>
#include <inttypes.h>
+#include <time.h>
#include "timer.h"
#include "timer_subr.h"
-struct timeval *
+struct timespec *
rtadvd_timer_rest(struct rtadvd_timer *rat)
{
- static struct timeval returnval, now;
+ static struct timespec returnval, now;
- gettimeofday(&now, NULL);
- if (TIMEVAL_LEQ(&rat->rat_tm, &now)) {
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
+ if (TS_CMP(&rat->rat_tm, &now, <=)) {
syslog(LOG_DEBUG,
"<%s> a timer must be expired, but not yet",
__func__);
- returnval.tv_sec = returnval.tv_usec = 0;
+ returnval.tv_sec = returnval.tv_nsec = 0;
}
else
- TIMEVAL_SUB(&rat->rat_tm, &now, &returnval);
+ TS_SUB(&rat->rat_tm, &now, &returnval);
return (&returnval);
}
-/* result = a + b */
-void
-TIMEVAL_ADD(struct timeval *a, struct timeval *b, struct timeval *result)
-{
- long l;
-
- if ((l = a->tv_usec + b->tv_usec) < MILLION) {
- result->tv_usec = l;
- result->tv_sec = a->tv_sec + b->tv_sec;
- }
- else {
- result->tv_usec = l - MILLION;
- result->tv_sec = a->tv_sec + b->tv_sec + 1;
- }
-}
-
-/*
- * result = a - b
- * XXX: this function assumes that a >= b.
- */
-void
-TIMEVAL_SUB(struct timeval *a, struct timeval *b, struct timeval *result)
-{
- long l;
-
- if ((l = a->tv_usec - b->tv_usec) >= 0) {
- result->tv_usec = l;
- result->tv_sec = a->tv_sec - b->tv_sec;
- }
- else {
- result->tv_usec = MILLION + l;
- result->tv_sec = a->tv_sec - b->tv_sec - 1;
- }
-}
-
char *
sec2str(uint32_t s, char *buf)
{
diff --git a/usr.sbin/rtadvd/timer_subr.h b/usr.sbin/rtadvd/timer_subr.h
index 9ceddad..32e1bb1 100644
--- a/usr.sbin/rtadvd/timer_subr.h
+++ b/usr.sbin/rtadvd/timer_subr.h
@@ -31,27 +31,29 @@
*/
#define SSBUFLEN 1024
-#define MILLION 1000000
-/* a < b */
-#define TIMEVAL_LT(a, b) \
- (((a)->tv_sec < (b)->tv_sec) || \
- (((a)->tv_sec == (b)->tv_sec) && \
- ((a)->tv_usec < (b)->tv_usec)))
+#define TS_CMP(tsp, usp, cmp) \
+ (((tsp)->tv_sec == (usp)->tv_sec) ? \
+ ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
+ ((tsp)->tv_sec cmp (usp)->tv_sec))
+#define TS_ADD(tsp, usp, vsp) \
+ do { \
+ (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
+ (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
+ if ((vsp)->tv_nsec >= 1000000000L) { \
+ (vsp)->tv_sec++; \
+ (vsp)->tv_nsec -= 1000000000L; \
+ } \
+ } while (0)
+#define TS_SUB(tsp, usp, vsp) \
+ do { \
+ (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
+ (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
+ if ((vsp)->tv_nsec < 0) { \
+ (vsp)->tv_sec--; \
+ (vsp)->tv_nsec += 1000000000L; \
+ } \
+ } while (0)
-/* a <= b */
-#define TIMEVAL_LEQ(a, b) \
- (((a)->tv_sec < (b)->tv_sec) || \
- (((a)->tv_sec == (b)->tv_sec) && \
- ((a)->tv_usec <= (b)->tv_usec)))
-
-#define TIMEVAL_EQUAL(a,b) \
- (((a)->tv_sec == (b)->tv_sec) && \
- ((a)->tv_usec == (b)->tv_usec))
-
-struct timeval *rtadvd_timer_rest(struct rtadvd_timer *);
-void TIMEVAL_ADD(struct timeval *, struct timeval *,
- struct timeval *);
-void TIMEVAL_SUB(struct timeval *, struct timeval *,
- struct timeval *);
+struct timespec *rtadvd_timer_rest(struct rtadvd_timer *);
char *sec2str(uint32_t, char *buf);
diff --git a/usr.sbin/rtsold/dump.c b/usr.sbin/rtsold/dump.c
index 52d4b62..a0bf2c2 100644
--- a/usr.sbin/rtsold/dump.c
+++ b/usr.sbin/rtsold/dump.c
@@ -32,7 +32,6 @@
*/
#include <sys/types.h>
-#include <sys/time.h>
#include <sys/socket.h>
#include <sys/queue.h>
@@ -51,8 +50,6 @@
static FILE *fp;
-extern struct ifinfo *iflist;
-
static void dump_interface_status(void);
static const char * const ifstatstr[] = {"IDLE", "DELAY", "PROBE", "DOWN", "TENTATIVE"};
@@ -62,10 +59,10 @@ dump_interface_status(void)
struct ifinfo *ifi;
struct rainfo *rai;
struct ra_opt *rao;
- struct timeval now;
+ struct timespec now;
char ntopbuf[INET6_ADDRSTRLEN];
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
TAILQ_FOREACH(ifi, &ifinfo_head, ifi_next) {
fprintf(fp, "Interface %s\n", ifi->ifname);
@@ -87,12 +84,12 @@ dump_interface_status(void)
fprintf(fp, " probes: %d, dadcount = %d\n",
ifi->probes, ifi->dadcount);
if (ifi->timer.tv_sec == tm_max.tv_sec &&
- ifi->timer.tv_usec == tm_max.tv_usec)
+ ifi->timer.tv_nsec == tm_max.tv_nsec)
fprintf(fp, " no timer\n");
else {
fprintf(fp, " timer: interval=%d:%d, expire=%s\n",
(int)ifi->timer.tv_sec,
- (int)ifi->timer.tv_usec,
+ (int)ifi->timer.tv_nsec / 1000,
(ifi->expire.tv_sec < now.tv_sec) ? "expired"
: sec2str(&ifi->expire));
}
@@ -137,7 +134,7 @@ rtsold_dump_file(const char *dumpfile)
}
const char *
-sec2str(const struct timeval *total)
+sec2str(const struct timespec *total)
{
static char result[256];
int days, hours, mins, secs;
@@ -145,14 +142,14 @@ sec2str(const struct timeval *total)
char *p = result;
char *ep = &result[sizeof(result)];
int n;
- struct timeval now;
+ struct timespec now;
time_t tsec;
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
tsec = total->tv_sec;
- tsec += total->tv_usec / 1000000;
+ tsec += total->tv_nsec / 1000 / 1000000;
tsec -= now.tv_sec;
- tsec -= now.tv_usec / 1000000;
+ tsec -= now.tv_nsec / 1000 / 1000000;
days = tsec / 3600 / 24;
hours = (tsec / 3600) % 24;
diff --git a/usr.sbin/rtsold/if.c b/usr.sbin/rtsold/if.c
index 58ec514..2bf946d 100644
--- a/usr.sbin/rtsold/if.c
+++ b/usr.sbin/rtsold/if.c
@@ -61,7 +61,6 @@
#include <ifaddrs.h>
#include "rtsold.h"
-extern int rssock;
static int ifsock;
static int get_llflag(const char *);
@@ -304,13 +303,13 @@ if_nametosdl(char *name)
lim = buf + len;
for (next = buf; next < lim; next += ifm->ifm_msglen) {
- ifm = (struct if_msghdr *)next;
+ ifm = (struct if_msghdr *)(void *)next;
if (ifm->ifm_type == RTM_IFINFO) {
sa = (struct sockaddr *)(ifm + 1);
get_rtaddrs(ifm->ifm_addrs, sa, rti_info);
if ((sa = rti_info[RTAX_IFP]) != NULL) {
if (sa->sa_family == AF_LINK) {
- sdl = (struct sockaddr_dl *)sa;
+ sdl = (struct sockaddr_dl *)(void *)sa;
if (strlen(name) != sdl->sdl_nlen)
continue; /* not same len */
if (strncmp(&sdl->sdl_data[0],
@@ -397,7 +396,7 @@ get_llflag(const char *name)
continue;
if (ifa->ifa_addr->sa_family != AF_INET6)
continue;
- sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
+ sin6 = (struct sockaddr_in6 *)(void *)ifa->ifa_addr;
if (!IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
continue;
diff --git a/usr.sbin/rtsold/probe.c b/usr.sbin/rtsold/probe.c
index 657ae40..5ec54aa 100644
--- a/usr.sbin/rtsold/probe.c
+++ b/usr.sbin/rtsold/probe.c
@@ -35,6 +35,7 @@
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
+#include <sys/sysctl.h>
#include <sys/uio.h>
#include <sys/queue.h>
@@ -102,41 +103,51 @@ probe_init(void)
void
defrouter_probe(struct ifinfo *ifinfo)
{
- u_char ntopbuf[INET6_ADDRSTRLEN];
- struct in6_drlist dr;
- int s, i;
- int ifindex = ifinfo->sdl->sdl_index;
+ struct in6_defrouter *p, *ep;
+ int ifindex, mib[4];
+ char *buf, ntopbuf[INET6_ADDRSTRLEN];
+ size_t l;
- if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- warnmsg(LOG_ERR, __func__, "socket: %s", strerror(errno));
+ ifindex = ifinfo->sdl->sdl_index;
+ if (ifindex == 0)
+ return;
+ mib[0] = CTL_NET;
+ mib[1] = PF_INET6;
+ mib[2] = IPPROTO_ICMPV6;
+ mib[3] = ICMPV6CTL_ND6_DRLIST;
+ if (sysctl(mib, nitems(mib), NULL, &l, NULL, 0) < 0) {
+ warnmsg(LOG_ERR, __func__, "sysctl(ICMPV6CTL_ND6_DRLIST): %s",
+ strerror(errno));
return;
}
- memset(&dr, 0, sizeof(dr));
- strlcpy(dr.ifname, "lo0", sizeof dr.ifname); /* dummy interface */
- if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {
- warnmsg(LOG_ERR, __func__, "ioctl(SIOCGDRLST_IN6): %s",
+ if (l == 0)
+ return;
+ buf = malloc(l);
+ if (buf == NULL) {
+ warnmsg(LOG_ERR, __func__, "malloc(): %s", strerror(errno));
+ return;
+ }
+ if (sysctl(mib, nitems(mib), buf, &l, NULL, 0) < 0) {
+ warnmsg(LOG_ERR, __func__, "sysctl(ICMPV6CTL_ND6_DRLIST): %s",
strerror(errno));
- goto closeandend;
+ free(buf);
+ return;
}
-
- for (i = 0; i < DRLSTSIZ && dr.defrouter[i].if_index; i++) {
- if (ifindex && dr.defrouter[i].if_index == ifindex) {
- /* sanity check */
- if (!IN6_IS_ADDR_LINKLOCAL(&dr.defrouter[i].rtaddr)) {
- warnmsg(LOG_ERR, __func__,
- "default router list contains a "
- "non-link-local address(%s)",
- inet_ntop(AF_INET6,
- &dr.defrouter[i].rtaddr,
- ntopbuf, INET6_ADDRSTRLEN));
- continue; /* ignore the address */
- }
- sendprobe(&dr.defrouter[i].rtaddr, ifinfo);
+ ep = (struct in6_defrouter *)(void *)(buf + l);
+ for (p = (struct in6_defrouter *)(void *)buf; p < ep; p++) {
+ if (ifindex != p->if_index)
+ continue;
+ if (!IN6_IS_ADDR_LINKLOCAL(&p->rtaddr.sin6_addr)) {
+ warnmsg(LOG_ERR, __func__,
+ "default router list contains a "
+ "non-link-local address(%s)",
+ inet_ntop(AF_INET6, &p->rtaddr.sin6_addr, ntopbuf,
+ INET6_ADDRSTRLEN));
+ continue; /* ignore the address */
}
+ sendprobe(&p->rtaddr.sin6_addr, ifinfo);
}
-
-closeandend:
- close(s);
+ free(buf);
}
static void
@@ -164,7 +175,7 @@ sendprobe(struct in6_addr *addr, struct ifinfo *ifinfo)
cm->cmsg_level = IPPROTO_IPV6;
cm->cmsg_type = IPV6_PKTINFO;
cm->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
- pi = (struct in6_pktinfo *)CMSG_DATA(cm);
+ pi = (struct in6_pktinfo *)(void *)CMSG_DATA(cm);
memset(&pi->ipi6_addr, 0, sizeof(pi->ipi6_addr)); /*XXX*/
pi->ipi6_ifindex = ifindex;
diff --git a/usr.sbin/rtsold/rtsock.c b/usr.sbin/rtsold/rtsock.c
index fe22bc7..702ffe1 100644
--- a/usr.sbin/rtsold/rtsock.c
+++ b/usr.sbin/rtsold/rtsock.c
@@ -103,7 +103,7 @@ rtsock_input(int s)
lim = msg + n;
for (next = msg; next < lim; next += len) {
- rtm = (struct rt_msghdr *)next;
+ rtm = (struct rt_msghdr *)(void *)next;
if (lim - next < lenlim)
break;
len = rtm->rtm_msglen;
@@ -138,7 +138,7 @@ static int
rtsock_input_ifannounce(int s __unused, struct rt_msghdr *rtm, char *lim)
{
struct if_announcemsghdr *ifan;
- struct ifinfo *ifinfo;
+ struct ifinfo *ifi;
ifan = (struct if_announcemsghdr *)rtm;
if ((char *)(ifan + 1) > lim)
@@ -158,14 +158,14 @@ rtsock_input_ifannounce(int s __unused, struct rt_msghdr *rtm, char *lim)
case IFAN_DEPARTURE:
warnmsg(LOG_WARNING, __func__,
"interface %s removed", ifan->ifan_name);
- ifinfo = find_ifinfo(ifan->ifan_index);
- if (ifinfo) {
+ ifi = find_ifinfo(ifan->ifan_index);
+ if (ifi) {
if (dflag > 1) {
warnmsg(LOG_INFO, __func__,
"bring interface %s to DOWN state",
ifan->ifan_name);
}
- ifinfo->state = IFS_DOWN;
+ ifi->state = IFS_DOWN;
}
break;
}
diff --git a/usr.sbin/rtsold/rtsol.c b/usr.sbin/rtsold/rtsol.c
index 850e5d9..c9b3d44 100644
--- a/usr.sbin/rtsold/rtsol.c
+++ b/usr.sbin/rtsold/rtsol.c
@@ -35,7 +35,6 @@
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/uio.h>
-#include <sys/time.h>
#include <sys/queue.h>
#include <sys/wait.h>
#include <sys/stat.h>
@@ -58,6 +57,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
+#include <time.h>
#include <err.h>
#include <errno.h>
#include <string.h>
@@ -205,7 +205,7 @@ sendpacket(struct ifinfo *ifi)
cm->cmsg_level = IPPROTO_IPV6;
cm->cmsg_type = IPV6_PKTINFO;
cm->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
- pi = (struct in6_pktinfo *)CMSG_DATA(cm);
+ pi = (struct in6_pktinfo *)(void *)CMSG_DATA(cm);
memset(&pi->ipi6_addr, 0, sizeof(pi->ipi6_addr)); /*XXX*/
pi->ipi6_ifindex = ifi->sdl->sdl_index;
@@ -237,7 +237,7 @@ sendpacket(struct ifinfo *ifi)
void
rtsol_input(int s)
{
- u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
+ char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
int l, ifindex = 0, *hlimp = NULL;
ssize_t msglen;
struct in6_pktinfo *pi = NULL;
@@ -256,8 +256,8 @@ rtsol_input(int s)
size_t len;
char nsbuf[INET6_ADDRSTRLEN + 1 + IFNAMSIZ + 1];
char dname[NI_MAXHOST];
- struct timeval now;
- struct timeval lifetime;
+ struct timespec now;
+ struct timespec lifetime;
int newent_rai;
int newent_rao;
@@ -275,13 +275,13 @@ rtsol_input(int s)
if (cm->cmsg_level == IPPROTO_IPV6 &&
cm->cmsg_type == IPV6_PKTINFO &&
cm->cmsg_len == CMSG_LEN(sizeof(struct in6_pktinfo))) {
- pi = (struct in6_pktinfo *)(CMSG_DATA(cm));
+ pi = (struct in6_pktinfo *)(void *)(CMSG_DATA(cm));
ifindex = pi->ipi6_ifindex;
}
if (cm->cmsg_level == IPPROTO_IPV6 &&
cm->cmsg_type == IPV6_HOPLIMIT &&
cm->cmsg_len == CMSG_LEN(sizeof(int)))
- hlimp = (int *)CMSG_DATA(cm);
+ hlimp = (int *)(void *)CMSG_DATA(cm);
}
if (ifindex == 0) {
@@ -376,7 +376,7 @@ rtsol_input(int s)
ifi->otherconfig = 1;
CALL_SCRIPT(OTHER, NULL);
}
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
newent_rai = 0;
rai = find_rainfo(ifi, &from);
if (rai == NULL) {
@@ -417,7 +417,7 @@ rtsol_input(int s)
break;
}
- addr = (struct in6_addr *)(raoptp + sizeof(*rdnss));
+ addr = (struct in6_addr *)(void *)(raoptp + sizeof(*rdnss));
while ((char *)addr < (char *)RA_OPT_NEXT_HDR(raoptp)) {
if (inet_ntop(AF_INET6, addr, ntopbuf,
sizeof(ntopbuf)) == NULL) {
@@ -472,7 +472,7 @@ rtsol_input(int s)
memset(&lifetime, 0, sizeof(lifetime));
lifetime.tv_sec =
ntohl(rdnss->nd_opt_rdnss_lifetime);
- timeradd(&now, &lifetime, &rao->rao_expire);
+ TS_ADD(&now, &lifetime, &rao->rao_expire);
if (newent_rao)
TAILQ_INSERT_TAIL(&rai->rai_ra_opt,
@@ -531,7 +531,7 @@ rtsol_input(int s)
memset(&lifetime, 0, sizeof(lifetime));
lifetime.tv_sec =
ntohl(dnssl->nd_opt_dnssl_lifetime);
- timeradd(&now, &lifetime, &rao->rao_expire);
+ TS_ADD(&now, &lifetime, &rao->rao_expire);
if (newent_rao)
TAILQ_INSERT_TAIL(&rai->rai_ra_opt,
@@ -574,7 +574,7 @@ ra_opt_handler(struct ifinfo *ifi)
struct ra_opt *rao;
struct rainfo *rai;
struct script_msg *smp1, *smp2, *smp3;
- struct timeval now;
+ struct timespec now;
struct script_msg_head_t sm_rdnss_head =
TAILQ_HEAD_INITIALIZER(sm_rdnss_head);
struct script_msg_head_t sm_dnssl_head =
@@ -584,7 +584,7 @@ ra_opt_handler(struct ifinfo *ifi)
dcount = 0;
dlen = strlen(resstr_sh_prefix) + strlen(resstr_nl);
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
/*
* All options from multiple RAs with the same or different
@@ -595,7 +595,7 @@ ra_opt_handler(struct ifinfo *ifi)
TAILQ_FOREACH(rao, &rai->rai_ra_opt, rao_next) {
switch (rao->rao_type) {
case ND_OPT_RDNSS:
- if (timercmp(&now, &rao->rao_expire, >)) {
+ if (TS_CMP(&now, &rao->rao_expire, >)) {
warnmsg(LOG_INFO, __func__,
"expired rdnss entry: %s",
(char *)rao->rao_msg);
@@ -617,7 +617,7 @@ ra_opt_handler(struct ifinfo *ifi)
break;
case ND_OPT_DNSSL:
- if (timercmp(&now, &rao->rao_expire, >)) {
+ if (TS_CMP(&now, &rao->rao_expire, >)) {
warnmsg(LOG_INFO, __func__,
"expired dnssl entry: %s",
(char *)rao->rao_msg);
diff --git a/usr.sbin/rtsold/rtsold.8 b/usr.sbin/rtsold/rtsold.8
index 946eca2..a723e9c 100644
--- a/usr.sbin/rtsold/rtsold.8
+++ b/usr.sbin/rtsold/rtsold.8
@@ -161,15 +161,10 @@ will dump the current internal state into
The options are as follows:
.Bl -tag -width indent
.It Fl a
-Autoprobe outgoing interface.
+Autoprobe outgoing interfaces.
.Nm
-will try to find a non-loopback, non-point-to-point, IPv6-capable interface.
-If
-.Nm
-finds multiple interfaces,
-.Nm
-will exit with error.
-.\"
+will try to find any non-loopback, non-point-to-point, IPv6-capable interfaces
+and send router solicitation messages on all of them.
.It Fl d
Enable debugging.
.It Fl D
@@ -261,10 +256,10 @@ If not, it will be
.Sh FILES
.Bl -tag -width /var/run/rtsold.dump -compact
.It Pa /var/run/rtsold.pid
-the pid of the currently running
+The PID of the currently running
.Nm .
.It Pa /var/run/rtsold.dump
-dumps internal state on.
+Internal state dump file.
.El
.\"
.Sh EXIT STATUS
diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c
index d3d1289..a97b884 100644
--- a/usr.sbin/rtsold/rtsold.c
+++ b/usr.sbin/rtsold/rtsold.c
@@ -33,7 +33,6 @@
#include <sys/types.h>
#include <sys/ioctl.h>
-#include <sys/time.h>
#include <sys/socket.h>
#include <sys/param.h>
@@ -54,6 +53,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include <time.h>
#include <errno.h>
#include <err.h>
#include <stdarg.h>
@@ -67,8 +67,7 @@
#define RTSOL_DUMPFILE "/var/run/rtsold.dump";
#define RTSOL_PIDFILE "/var/run/rtsold.pid";
-struct ifinfo *iflist;
-struct timeval tm_max = {0x7fffffff, 0x7fffffff};
+struct timespec tm_max;
static int log_upto = 999;
static int fflag = 0;
@@ -105,7 +104,7 @@ static int ifreconfig(char *);
#endif
static int make_packet(struct ifinfo *);
-static struct timeval *rtsol_check_timer(void);
+static struct timespec *rtsol_check_timer(void);
#ifndef SMALL
static void rtsold_set_dump_file(int);
@@ -116,7 +115,7 @@ int
main(int argc, char **argv)
{
int s, ch, once = 0;
- struct timeval *timeout;
+ struct timespec *timeout;
const char *opts;
#ifdef HAVE_POLL_H
struct pollfd set[2];
@@ -187,6 +186,10 @@ main(int argc, char **argv)
exit(1);
}
+ /* Generate maximum time in timespec. */
+ tm_max.tv_sec = (-1) & ~((time_t)1 << ((sizeof(tm_max.tv_sec) * 8) - 1));
+ tm_max.tv_nsec = (-1) & ~((long)1 << ((sizeof(tm_max.tv_nsec) * 8) - 1));
+
/* set log level */
if (dflag > 1)
log_upto = LOG_DEBUG;
@@ -363,7 +366,7 @@ main(int argc, char **argv)
break;
}
#ifdef HAVE_POLL_H
- e = poll(set, 2, timeout ? (timeout->tv_sec * 1000 + timeout->tv_usec / 1000) : INFTIM);
+ e = poll(set, 2, timeout ? (timeout->tv_sec * 1000 + timeout->tv_nsec / 1000 / 1000) : INFTIM);
#else
e = select(maxfd + 1, selectfdp, NULL, NULL, timeout);
#endif
@@ -603,22 +606,22 @@ make_packet(struct ifinfo *ifi)
return (0);
}
-static struct timeval *
+static struct timespec *
rtsol_check_timer(void)
{
- static struct timeval returnval;
- struct timeval now, rtsol_timer;
+ static struct timespec returnval;
+ struct timespec now, rtsol_timer;
struct ifinfo *ifi;
struct rainfo *rai;
struct ra_opt *rao;
int flags;
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
rtsol_timer = tm_max;
TAILQ_FOREACH(ifi, &ifinfo_head, ifi_next) {
- if (timercmp(&ifi->expire, &now, <=)) {
+ if (TS_CMP(&ifi->expire, &now, <=)) {
warnmsg(LOG_DEBUG, __func__, "timer expiration on %s, "
"state = %d", ifi->ifname, ifi->state);
@@ -711,7 +714,7 @@ rtsol_check_timer(void)
"type=%d, msg=%s, expire=%s",
rao->rao_type, (char *)rao->rao_msg,
sec2str(&rao->rao_expire));
- if (timercmp(&now, &rao->rao_expire,
+ if (TS_CMP(&now, &rao->rao_expire,
>=)) {
warnmsg(LOG_DEBUG, __func__,
"RA expiration timer: "
@@ -728,21 +731,21 @@ rtsol_check_timer(void)
if (expire)
ra_opt_handler(ifi);
}
- if (timercmp(&ifi->expire, &rtsol_timer, <))
+ if (TS_CMP(&ifi->expire, &rtsol_timer, <))
rtsol_timer = ifi->expire;
}
- if (timercmp(&rtsol_timer, &tm_max, ==)) {
+ if (TS_CMP(&rtsol_timer, &tm_max, ==)) {
warnmsg(LOG_DEBUG, __func__, "there is no timer");
return (NULL);
- } else if (timercmp(&rtsol_timer, &now, <))
+ } else if (TS_CMP(&rtsol_timer, &now, <))
/* this may occur when the interval is too small */
- returnval.tv_sec = returnval.tv_usec = 0;
+ returnval.tv_sec = returnval.tv_nsec = 0;
else
- timersub(&rtsol_timer, &now, &returnval);
+ TS_SUB(&rtsol_timer, &now, &returnval);
now.tv_sec += returnval.tv_sec;
- now.tv_usec += returnval.tv_usec;
+ now.tv_nsec += returnval.tv_nsec;
warnmsg(LOG_DEBUG, __func__, "New timer is %s",
sec2str(&now));
@@ -755,7 +758,7 @@ rtsol_timer_update(struct ifinfo *ifi)
#define MILLION 1000000
#define DADRETRY 10 /* XXX: adhoc */
long interval;
- struct timeval now;
+ struct timespec now;
bzero(&ifi->timer, sizeof(ifi->timer));
@@ -783,7 +786,7 @@ rtsol_timer_update(struct ifinfo *ifi)
interval = arc4random_uniform(MAX_RTR_SOLICITATION_DELAY * MILLION);
#endif
ifi->timer.tv_sec = interval / MILLION;
- ifi->timer.tv_usec = interval % MILLION;
+ ifi->timer.tv_nsec = (interval % MILLION) * 1000;
break;
case IFS_PROBE:
if (ifi->probes < MAX_RTR_SOLICITATIONS)
@@ -807,16 +810,16 @@ rtsol_timer_update(struct ifinfo *ifi)
}
/* reset the timer */
- if (timercmp(&ifi->timer, &tm_max, ==)) {
+ if (TS_CMP(&ifi->timer, &tm_max, ==)) {
ifi->expire = tm_max;
warnmsg(LOG_DEBUG, __func__,
"stop timer for %s", ifi->ifname);
} else {
- gettimeofday(&now, NULL);
- timeradd(&now, &ifi->timer, &ifi->expire);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
+ TS_ADD(&now, &ifi->timer, &ifi->expire);
now.tv_sec += ifi->timer.tv_sec;
- now.tv_usec += ifi->timer.tv_usec;
+ now.tv_nsec += ifi->timer.tv_nsec;
warnmsg(LOG_DEBUG, __func__, "set timer for %s to %s",
ifi->ifname, sec2str(&now));
}
diff --git a/usr.sbin/rtsold/rtsold.h b/usr.sbin/rtsold/rtsold.h
index 3ab010f..56b4185 100644
--- a/usr.sbin/rtsold/rtsold.h
+++ b/usr.sbin/rtsold/rtsold.h
@@ -43,7 +43,7 @@ struct ra_opt {
TAILQ_ENTRY(ra_opt) rao_next;
u_int8_t rao_type;
- struct timeval rao_expire;
+ struct timespec rao_expire;
size_t rao_len;
void *rao_msg;
};
@@ -73,8 +73,8 @@ struct ifinfo {
int state;
int probes;
int dadcount;
- struct timeval timer;
- struct timeval expire;
+ struct timespec timer;
+ struct timespec expire;
int errors; /* # of errors we've got - detect wedge */
#define IFI_DNSOPT_STATE_NOINFO 0
#define IFI_DNSOPT_STATE_RECEIVED 1
@@ -124,8 +124,31 @@ extern TAILQ_HEAD(ifinfo_head_t, ifinfo) ifinfo_head;
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
#endif
+#define TS_CMP(tsp, usp, cmp) \
+ (((tsp)->tv_sec == (usp)->tv_sec) ? \
+ ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
+ ((tsp)->tv_sec cmp (usp)->tv_sec))
+#define TS_ADD(tsp, usp, vsp) \
+ do { \
+ (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
+ (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
+ if ((vsp)->tv_nsec >= 1000000000L) { \
+ (vsp)->tv_sec++; \
+ (vsp)->tv_nsec -= 1000000000L; \
+ } \
+ } while (0)
+#define TS_SUB(tsp, usp, vsp) \
+ do { \
+ (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
+ (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
+ if ((vsp)->tv_nsec < 0) { \
+ (vsp)->tv_sec--; \
+ (vsp)->tv_nsec += 1000000000L; \
+ } \
+ } while (0)
+
/* rtsold.c */
-extern struct timeval tm_max;
+extern struct timespec tm_max;
extern int dflag;
extern int aflag;
extern int Fflag;
@@ -153,6 +176,7 @@ extern int getinet6sysctl(int);
extern int setinet6sysctl(int, int);
/* rtsol.c */
+extern int rssock;
extern int sockopen(void);
extern void sendpacket(struct ifinfo *);
extern void rtsol_input(int);
@@ -163,7 +187,7 @@ extern void defrouter_probe(struct ifinfo *);
/* dump.c */
extern void rtsold_dump_file(const char *);
-extern const char *sec2str(const struct timeval *);
+extern const char *sec2str(const struct timespec *);
/* rtsock.c */
extern int rtsock_open(void);
diff --git a/usr.sbin/rwhod/rwhod.c b/usr.sbin/rwhod/rwhod.c
index 16bf948..87a4166 100644
--- a/usr.sbin/rwhod/rwhod.c
+++ b/usr.sbin/rwhod/rwhod.c
@@ -1,6 +1,7 @@
-/*
- * Copyright (c) 1983, 1993
- * The Regents of the University of California. All rights reserved.
+/*-
+ * Copyright (c) 1983, 1993 The Regents of the University of California.
+ * Copyright (c) 2013 Mariusz Zaborski <oshogbo@FreeBSD.org>
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -42,12 +43,15 @@ static char sccsid[] = "@(#)rwhod.c 8.1 (Berkeley) 6/6/93";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/capability.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/signal.h>
#include <sys/ioctl.h>
#include <sys/sysctl.h>
+#include <sys/procdesc.h>
+#include <sys/wait.h>
#include <net/if.h>
#include <net/if_dl.h>
@@ -60,47 +64,17 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <grp.h>
#include <netdb.h>
#include <paths.h>
+#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <timeconv.h>
-#include <unistd.h>
#include <utmpx.h>
-#include <pwd.h>
-#include <grp.h>
-
-/*
- * This version of Berkeley's rwhod has been modified to use IP multicast
- * datagrams, under control of a new command-line option:
- *
- * rwhod -m causes rwhod to use IP multicast (instead of
- * broadcast or unicast) on all interfaces that have
- * the IFF_MULTICAST flag set in their "ifnet" structs
- * (excluding the loopback interface). The multicast
- * reports are sent with a time-to-live of 1, to prevent
- * forwarding beyond the directly-connected subnet(s).
- *
- * rwhod -m <ttl> causes rwhod to send IP multicast datagrams with a
- * time-to-live of <ttl>, via a SINGLE interface rather
- * than all interfaces. <ttl> must be between 0 and
- * MAX_MULTICAST_SCOPE, defined below. Note that "-m 1"
- * is different than "-m", in that "-m 1" specifies
- * transmission on one interface only.
- *
- * When "-m" is used without a <ttl> argument, the program accepts multicast
- * rwhod reports from all multicast-capable interfaces. If a <ttl> argument
- * is given, it accepts multicast reports from only one interface, the one
- * on which reports are sent (which may be controlled via the host's routing
- * table). Regardless of the "-m" option, the program accepts broadcast or
- * unicast reports from all interfaces. Thus, this program will hear the
- * reports of old, non-multicasting rwhods, but, if multicasting is used,
- * those old rwhods won't hear the reports generated by this program.
- *
- * -- Steve Deering, Stanford University, February 1989
- */
+#include <unistd.h>
#define UNPRIV_USER "daemon"
#define UNPRIV_GROUP "daemon"
@@ -112,21 +86,21 @@ __FBSDID("$FreeBSD$");
#define MAX_MULTICAST_SCOPE 32 /* "site-wide", by convention */
#define INADDR_WHOD_GROUP (u_long)0xe0000103 /* 224.0.1.3 */
- /* (belongs in protocols/rwhod.h) */
+ /* (belongs in protocols/rwhod.h) */
-int insecure_mode;
-int quiet_mode;
-int iff_flag = IFF_POINTOPOINT;
-int multicast_mode = NO_MULTICAST;
-int multicast_scope;
-struct sockaddr_in multicast_addr =
- { sizeof multicast_addr, AF_INET, 0, { 0 }, { 0 } };
+int insecure_mode;
+int quiet_mode;
+int iff_flag = IFF_POINTOPOINT;
+int multicast_mode = NO_MULTICAST;
+int multicast_scope;
+struct sockaddr_in multicast_addr =
+ { sizeof(multicast_addr), AF_INET, 0, { 0 }, { 0 } };
/*
- * Alarm interval. Don't forget to change the down time check in ruptime
+ * Sleep interval. Don't forget to change the down time check in ruptime
* if this is changed.
*/
-#define AL_INTERVAL (3 * 60)
+#define SL_INTERVAL (3 * 60)
char myname[MAXHOSTNAMELEN];
@@ -137,72 +111,109 @@ char myname[MAXHOSTNAMELEN];
*/
struct neighbor {
struct neighbor *n_next;
- char *n_name; /* interface name */
+ char *n_name; /* interface name */
struct sockaddr *n_addr; /* who to send to */
- int n_addrlen; /* size of address */
- int n_flags; /* should forward?, interface flags */
+ int n_addrlen; /* size of address */
+ int n_flags; /* should forward?, interface flags */
};
struct neighbor *neighbors;
struct whod mywd;
-struct servent *sp;
+struct servent *sp;
int s;
+int fdp;
+pid_t pid_child_receiver;
#define WHDRSIZE (int)(sizeof(mywd) - sizeof(mywd.wd_we))
-void run_as(uid_t *, gid_t *);
-int configure(int);
-void getboottime(int);
-void onalrm(int);
-void quit(const char *);
-void rt_xaddrs(caddr_t, caddr_t, struct rt_addrinfo *);
-int verify(char *, int);
+int configure(int so);
+void getboottime(int signo __unused);
+void receiver_process(void);
+void rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo);
+void run_as(uid_t *uid, gid_t *gid);
+void quit(const char *msg);
+void sender_process(void);
+int verify(char *name, int maxlen);
static void usage(void);
+
#ifdef DEBUG
-char *interval(int, char *);
-void Sendto(int, const void *, size_t, int, const struct sockaddr *, int);
+char *interval(int time, char *updown);
+void Sendto(int s, const void *buf, size_t cc, int flags,
+ const struct sockaddr *to, int tolen);
#define sendto Sendto
#endif
+/*
+ * This version of Berkeley's rwhod has been modified to use IP multicast
+ * datagrams, under control of a new command-line option:
+ *
+ * rwhod -m causes rwhod to use IP multicast (instead of
+ * broadcast or unicast) on all interfaces that have
+ * the IFF_MULTICAST flag set in their "ifnet" structs
+ * (excluding the loopback interface). The multicast
+ * reports are sent with a time-to-live of 1, to prevent
+ * forwarding beyond the directly-connected subnet(s).
+ *
+ * rwhod -m <ttl> causes rwhod to send IP multicast datagrams with a
+ * time-to-live of <ttl>, via a SINGLE interface rather
+ * than all interfaces. <ttl> must be between 0 and
+ * MAX_MULTICAST_SCOPE, defined below. Note that "-m 1"
+ * is different than "-m", in that "-m 1" specifies
+ * transmission on one interface only.
+ *
+ * When "-m" is used without a <ttl> argument, the program accepts multicast
+ * rwhod reports from all multicast-capable interfaces. If a <ttl> argument
+ * is given, it accepts multicast reports from only one interface, the one
+ * on which reports are sent (which may be controlled via the host's routing
+ * table). Regardless of the "-m" option, the program accepts broadcast or
+ * unicast reports from all interfaces. Thus, this program will hear the
+ * reports of old, non-multicasting rwhods, but, if multicasting is used,
+ * those old rwhods won't hear the reports generated by this program.
+ *
+ * -- Steve Deering, Stanford University, February 1989
+ */
int
main(int argc, char *argv[])
{
- struct sockaddr_in from;
- struct stat st;
- char path[64];
- int on = 1;
+ int on;
char *cp;
struct sockaddr_in soin;
uid_t unpriv_uid;
gid_t unpriv_gid;
+ on = 1;
if (getuid())
errx(1, "not super user");
run_as(&unpriv_uid, &unpriv_gid);
- argv++; argc--;
+ argv++;
+ argc--;
while (argc > 0 && *argv[0] == '-') {
if (strcmp(*argv, "-m") == 0) {
if (argc > 1 && isdigit(*(argv + 1)[0])) {
- argv++, argc--;
+ argv++;
+ argc--;
multicast_mode = SCOPED_MULTICAST;
multicast_scope = atoi(*argv);
- if (multicast_scope > MAX_MULTICAST_SCOPE)
+ if (multicast_scope > MAX_MULTICAST_SCOPE) {
errx(1, "ttl must not exceed %u",
- MAX_MULTICAST_SCOPE);
+ MAX_MULTICAST_SCOPE);
+ }
+ } else {
+ multicast_mode = PER_INTERFACE_MULTICAST;
}
- else multicast_mode = PER_INTERFACE_MULTICAST;
- }
- else if (strcmp(*argv, "-i") == 0)
+ } else if (strcmp(*argv, "-i") == 0) {
insecure_mode = 1;
- else if (strcmp(*argv, "-l") == 0)
+ } else if (strcmp(*argv, "-l") == 0) {
quiet_mode = 1;
- else if (strcmp(*argv, "-p") == 0)
+ } else if (strcmp(*argv, "-p") == 0) {
iff_flag = 0;
- else
+ } else {
usage();
- argv++, argc--;
+ }
+ argv++;
+ argc--;
}
if (argc > 0)
usage();
@@ -210,7 +221,7 @@ main(int argc, char *argv[])
daemon(1, 0);
#endif
(void) signal(SIGHUP, getboottime);
- openlog("rwhod", LOG_PID, LOG_DAEMON);
+ openlog("rwhod", LOG_PID | LOG_NDELAY, LOG_DAEMON);
sp = getservbyname("who", "udp");
if (sp == NULL) {
syslog(LOG_ERR, "who/udp: unknown service");
@@ -229,8 +240,7 @@ main(int argc, char *argv[])
}
if ((cp = strchr(myname, '.')) != NULL)
*cp = '\0';
- strncpy(mywd.wd_hostname, myname, sizeof(mywd.wd_hostname) - 1);
- mywd.wd_hostname[sizeof(mywd.wd_hostname) - 1] = '\0';
+ strlcpy(mywd.wd_hostname, myname, sizeof(mywd.wd_hostname));
getboottime(0);
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
syslog(LOG_ERR, "socket: %m");
@@ -252,7 +262,7 @@ main(int argc, char *argv[])
syslog(LOG_ERR, "setgid: %m");
exit(1);
}
- if (setgroups(1, &unpriv_gid) != 0) { /* XXX BOGUS groups[0] = egid */
+ if (setgroups(1, &unpriv_gid) != 0) { /* XXX BOGUS groups[0] = egid */
syslog(LOG_ERR, "setgroups: %m");
exit(1);
}
@@ -263,17 +273,110 @@ main(int argc, char *argv[])
if (!configure(s))
exit(1);
if (!quiet_mode) {
- signal(SIGALRM, onalrm);
- onalrm(0);
+ pid_child_receiver = pdfork(&fdp, 0);
+ if (pid_child_receiver == 0) {
+ receiver_process();
+ } else if (pid_child_receiver > 0) {
+ sender_process();
+ } else if (pid_child_receiver == -1) {
+ if (errno == ENOSYS) {
+ syslog(LOG_ERR,
+ "The pdfork(2) system call is not available; recompile the kernel with options PROCDESC");
+ } else {
+ syslog(LOG_ERR, "pdfork: %m");
+ }
+ exit(1);
+ }
+ } else {
+ receiver_process();
}
- for (;;) {
- struct whod wd;
- socklen_t len = sizeof(from);
- int cc, whod;
- time_t t;
+}
- cc = recvfrom(s, (char *)&wd, sizeof(struct whod), 0,
- (struct sockaddr *)&from, &len);
+static void
+usage(void)
+{
+
+ fprintf(stderr, "usage: rwhod [-i] [-p] [-l] [-m [ttl]]\n");
+ exit(1);
+}
+
+void
+run_as(uid_t *uid, gid_t *gid)
+{
+ struct passwd *pw;
+ struct group *gr;
+
+ pw = getpwnam(UNPRIV_USER);
+ if (pw == NULL) {
+ syslog(LOG_ERR, "getpwnam(%s): %m", UNPRIV_USER);
+ exit(1);
+ }
+ *uid = pw->pw_uid;
+
+ gr = getgrnam(UNPRIV_GROUP);
+ if (gr == NULL) {
+ syslog(LOG_ERR, "getgrnam(%s): %m", UNPRIV_GROUP);
+ exit(1);
+ }
+ *gid = gr->gr_gid;
+}
+
+/*
+ * Check out host name for unprintables
+ * and other funnies before allowing a file
+ * to be created. Sorry, but blanks aren't allowed.
+ */
+int
+verify(char *name, int maxlen)
+{
+ int size;
+
+ size = 0;
+ while (*name != '\0' && size < maxlen - 1) {
+ if (!isascii((unsigned char)*name) ||
+ !(isalnum((unsigned char)*name) ||
+ ispunct((unsigned char)*name))) {
+ return (0);
+ }
+ name++;
+ size++;
+ }
+ *name = '\0';
+ return (size > 0);
+}
+
+void
+receiver_process(void)
+{
+ struct sockaddr_in from;
+ struct stat st;
+ cap_rights_t rights;
+ char path[64];
+ int dirfd;
+ struct whod wd;
+ socklen_t len;
+ int cc, whod;
+ time_t t;
+
+ len = sizeof(from);
+ dirfd = open(".", O_RDONLY | O_DIRECTORY);
+ if (dirfd < 0) {
+ syslog(LOG_WARNING, "%s: %m", _PATH_RWHODIR);
+ exit(1);
+ }
+ cap_rights_init(&rights, CAP_CREATE, CAP_FSTAT, CAP_FTRUNCATE,
+ CAP_LOOKUP, CAP_SEEK, CAP_WRITE);
+ if (cap_rights_limit(dirfd, &rights) < 0 && errno != ENOSYS) {
+ syslog(LOG_WARNING, "cap_rights_limit: %m");
+ exit(1);
+ }
+ if (cap_enter() < 0 && errno != ENOSYS) {
+ syslog(LOG_ERR, "cap_enter: %m");
+ exit(1);
+ }
+ for (;;) {
+ cc = recvfrom(s, &wd, sizeof(wd), 0, (struct sockaddr *)&from,
+ &len);
if (cc <= 0) {
if (cc < 0 && errno != EINTR)
syslog(LOG_WARNING, "recv: %m");
@@ -293,26 +396,32 @@ main(int argc, char *argv[])
continue;
if (wd.wd_type != WHODTYPE_STATUS)
continue;
- if (!verify(wd.wd_hostname, sizeof wd.wd_hostname)) {
+ if (!verify(wd.wd_hostname, sizeof(wd.wd_hostname))) {
syslog(LOG_WARNING, "malformed host name from %s",
inet_ntoa(from.sin_addr));
continue;
}
- (void) snprintf(path, sizeof path, "whod.%s", wd.wd_hostname);
+ (void) snprintf(path, sizeof(path), "whod.%s", wd.wd_hostname);
/*
* Rather than truncating and growing the file each time,
* use ftruncate if size is less than previous size.
*/
- whod = open(path, O_WRONLY | O_CREAT, 0644);
+ whod = openat(dirfd, path, O_WRONLY | O_CREAT, 0644);
if (whod < 0) {
syslog(LOG_WARNING, "%s: %m", path);
continue;
}
+ cap_rights_init(&rights, CAP_FSTAT, CAP_FTRUNCATE, CAP_WRITE);
+ if (cap_rights_limit(whod, &rights) < 0 && errno != ENOSYS) {
+ syslog(LOG_WARNING, "cap_rights_limit: %m");
+ exit(1);
+ }
#if ENDIAN != BIG_ENDIAN
{
- int i, n = (cc - WHDRSIZE)/sizeof(struct whoent);
struct whoent *we;
+ int i, n;
+ n = (cc - WHDRSIZE) / sizeof(struct whoent);
/* undo header byte swapping before writing to file */
wd.wd_sendtime = ntohl(wd.wd_sendtime);
for (i = 0; i < 3; i++)
@@ -334,141 +443,104 @@ main(int argc, char *argv[])
ftruncate(whod, cc);
(void) close(whod);
}
-}
-
-static void
-usage()
-{
- fprintf(stderr, "usage: rwhod [-i] [-p] [-l] [-m [ttl]]\n");
- exit(1);
-}
-
-void
-run_as(uid, gid)
- uid_t *uid;
- gid_t *gid;
-{
- struct passwd *pw;
- struct group *gr;
-
- pw = getpwnam(UNPRIV_USER);
- if (!pw) {
- syslog(LOG_ERR, "getpwnam(%s): %m", UNPRIV_USER);
- exit(1);
- }
- *uid = pw->pw_uid;
-
- gr = getgrnam(UNPRIV_GROUP);
- if (!gr) {
- syslog(LOG_ERR, "getgrnam(%s): %m", UNPRIV_GROUP);
- exit(1);
- }
- *gid = gr->gr_gid;
-}
-
-/*
- * Check out host name for unprintables
- * and other funnies before allowing a file
- * to be created. Sorry, but blanks aren't allowed.
- */
-int
-verify(name, maxlen)
- register char *name;
- register int maxlen;
-{
- register int size = 0;
-
- while (*name && size < maxlen - 1) {
- if (!isascii(*name) || !(isalnum(*name) || ispunct(*name)))
- return (0);
- name++, size++;
- }
- *name = '\0';
- return (size > 0);
+ (void) close(dirfd);
}
void
-onalrm(int signo __unused)
+sender_process(void)
{
- struct neighbor *np;
- struct whoent *we = mywd.wd_we, *wend;
- struct stat stb;
- struct utmpx *ut;
- static int alarmcount = 0;
+ int sendcount;
double avenrun[3];
time_t now;
- int i, cc;
-
- now = time(NULL);
- if (alarmcount % 10 == 0)
- getboottime(0);
- alarmcount++;
- wend = &mywd.wd_we[1024 / sizeof(struct whoent)];
- setutxent();
- while ((ut = getutxent()) != NULL && we < wend) {
- if (ut->ut_type != USER_PROCESS)
- continue;
- strncpy(we->we_utmp.out_line, ut->ut_line,
- sizeof(we->we_utmp.out_line));
- strncpy(we->we_utmp.out_name, ut->ut_user,
- sizeof(we->we_utmp.out_name));
- we->we_utmp.out_time =
- htonl(_time_to_time32(ut->ut_tv.tv_sec));
- we++;
- }
- endutxent();
+ int i, cc, status;
+ struct utmpx *ut;
+ struct stat stb;
+ struct neighbor *np;
+ struct whoent *we, *wend;
- if (chdir(_PATH_DEV)) {
- syslog(LOG_ERR, "chdir(%s): %m", _PATH_DEV);
- exit(1);
- }
- wend = we;
- for (we = mywd.wd_we; we < wend; we++) {
- if (stat(we->we_utmp.out_line, &stb) >= 0)
- we->we_idle = htonl(now - stb.st_atime);
- we++;
- }
- (void)getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0]));
- for (i = 0; i < 3; i++)
- mywd.wd_loadav[i] = htonl((u_long)(avenrun[i] * 100));
- cc = (char *)wend - (char *)&mywd;
- mywd.wd_sendtime = htonl(_time_to_time32(time(NULL)));
- mywd.wd_vers = WHODVERSION;
- mywd.wd_type = WHODTYPE_STATUS;
- if (multicast_mode == SCOPED_MULTICAST) {
- (void) sendto(s, (char *)&mywd, cc, 0,
- (struct sockaddr *)&multicast_addr,
- sizeof(multicast_addr));
- }
- else for (np = neighbors; np != NULL; np = np->n_next) {
- if (multicast_mode == PER_INTERFACE_MULTICAST &&
- np->n_flags & IFF_MULTICAST) {
- /*
- * Select the outgoing interface for the multicast.
- */
- if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF,
- &(((struct sockaddr_in *)np->n_addr)->sin_addr),
- sizeof(struct in_addr)) < 0) {
- syslog(LOG_ERR,
- "setsockopt IP_MULTICAST_IF: %m");
- exit(1);
- }
+ sendcount = 0;
+ for (;;) {
+ we = mywd.wd_we;
+ now = time(NULL);
+ if (sendcount % 10 == 0)
+ getboottime(0);
+ sendcount++;
+ wend = &mywd.wd_we[1024 / sizeof(struct whoent)];
+ setutxent();
+ while ((ut = getutxent()) != NULL && we < wend) {
+ if (ut->ut_type != USER_PROCESS)
+ continue;
+ strncpy(we->we_utmp.out_line, ut->ut_line,
+ sizeof(we->we_utmp.out_line));
+ strncpy(we->we_utmp.out_name, ut->ut_user,
+ sizeof(we->we_utmp.out_name));
+ we->we_utmp.out_time =
+ htonl(_time_to_time32(ut->ut_tv.tv_sec));
+ we++;
+ }
+ endutxent();
+
+ if (chdir(_PATH_DEV) < 0) {
+ syslog(LOG_ERR, "chdir(%s): %m", _PATH_DEV);
+ exit(1);
+ }
+ wend = we;
+ for (we = mywd.wd_we; we < wend; we++) {
+ if (stat(we->we_utmp.out_line, &stb) >= 0)
+ we->we_idle = htonl(now - stb.st_atime);
+ we++;
+ }
+ (void) getloadavg(avenrun,
+ sizeof(avenrun) / sizeof(avenrun[0]));
+ for (i = 0; i < 3; i++)
+ mywd.wd_loadav[i] = htonl((u_long)(avenrun[i] * 100));
+ cc = (char *)wend - (char *)&mywd;
+ mywd.wd_sendtime = htonl(_time_to_time32(time(NULL)));
+ mywd.wd_vers = WHODVERSION;
+ mywd.wd_type = WHODTYPE_STATUS;
+ if (multicast_mode == SCOPED_MULTICAST) {
(void) sendto(s, (char *)&mywd, cc, 0,
- (struct sockaddr *)&multicast_addr,
- sizeof(multicast_addr));
- } else (void) sendto(s, (char *)&mywd, cc, 0,
- np->n_addr, np->n_addrlen);
- }
- if (chdir(_PATH_RWHODIR)) {
- syslog(LOG_ERR, "chdir(%s): %m", _PATH_RWHODIR);
- exit(1);
+ (struct sockaddr *)&multicast_addr,
+ sizeof(multicast_addr));
+ } else {
+ for (np = neighbors; np != NULL; np = np->n_next) {
+ if (multicast_mode == PER_INTERFACE_MULTICAST &&
+ (np->n_flags & IFF_MULTICAST) != 0) {
+ /*
+ * Select the outgoing interface for the
+ * multicast.
+ */
+ if (setsockopt(s, IPPROTO_IP,
+ IP_MULTICAST_IF,
+ &(((struct sockaddr_in *)np->n_addr)->sin_addr),
+ sizeof(struct in_addr)) < 0) {
+ syslog(LOG_ERR,
+ "setsockopt IP_MULTICAST_IF: %m");
+ exit(1);
+ }
+ (void) sendto(s, (char *)&mywd, cc, 0,
+ (struct sockaddr *)&multicast_addr,
+ sizeof(multicast_addr));
+ } else {
+ (void) sendto(s, (char *)&mywd, cc, 0,
+ np->n_addr, np->n_addrlen);
+ }
+ }
+ }
+ if (chdir(_PATH_RWHODIR) < 0) {
+ syslog(LOG_ERR, "chdir(%s): %m", _PATH_RWHODIR);
+ exit(1);
+ }
+ if (waitpid(pid_child_receiver, &status, WNOHANG) ==
+ pid_child_receiver) {
+ break;
+ }
+ sleep(SL_INTERVAL);
}
- (void) alarm(AL_INTERVAL);
}
void
-getboottime(signo)
- int signo __unused;
+getboottime(int signo __unused)
{
int mib[2];
size_t size;
@@ -485,26 +557,25 @@ getboottime(signo)
}
void
-quit(msg)
- const char *msg;
+quit(const char *msg)
{
+
syslog(LOG_ERR, "%s", msg);
exit(1);
}
void
-rt_xaddrs(cp, cplim, rtinfo)
- register caddr_t cp, cplim;
- register struct rt_addrinfo *rtinfo;
+rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo)
{
- register struct sockaddr *sa;
- register int i;
+ struct sockaddr *sa;
+ int i;
memset(rtinfo->rti_info, 0, sizeof(rtinfo->rti_info));
- for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {
+ for (i = 0; i < RTAX_MAX && cp < cplim; i++) {
if ((rtinfo->rti_addrs & (1 << i)) == 0)
continue;
- rtinfo->rti_info[i] = sa = (struct sockaddr *)cp;
+ sa = (struct sockaddr *)cp;
+ rtinfo->rti_info[i] = sa;
cp += SA_SIZE(sa);
}
}
@@ -514,18 +585,18 @@ rt_xaddrs(cp, cplim, rtinfo)
* networks which deserve status information.
*/
int
-configure(so)
- int so;
+configure(int so)
{
- register struct neighbor *np;
- register struct if_msghdr *ifm;
- register struct ifa_msghdr *ifam;
+ struct neighbor *np;
+ struct if_msghdr *ifm;
+ struct ifa_msghdr *ifam;
struct sockaddr_dl *sdl;
size_t needed;
- int mib[6], flags = 0, len;
+ int mib[6], flags, lflags, len;
char *buf, *lim, *next;
struct rt_addrinfo info;
+ flags = 0;
if (multicast_mode != NO_MULTICAST) {
multicast_addr.sin_addr.s_addr = htonl(INADDR_WHOD_GROUP);
multicast_addr.sin_port = sp->s_port;
@@ -538,19 +609,19 @@ configure(so)
mreq.imr_multiaddr.s_addr = htonl(INADDR_WHOD_GROUP);
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
if (setsockopt(so, IPPROTO_IP, IP_ADD_MEMBERSHIP,
- &mreq, sizeof(mreq)) < 0) {
+ &mreq, sizeof(mreq)) < 0) {
syslog(LOG_ERR,
- "setsockopt IP_ADD_MEMBERSHIP: %m");
- return(0);
+ "setsockopt IP_ADD_MEMBERSHIP: %m");
+ return (0);
}
ttl = multicast_scope;
- if (setsockopt(so, IPPROTO_IP, IP_MULTICAST_TTL,
- &ttl, sizeof(ttl)) < 0) {
+ if (setsockopt(so, IPPROTO_IP, IP_MULTICAST_TTL, &ttl,
+ sizeof(ttl)) < 0) {
syslog(LOG_ERR,
- "setsockopt IP_MULTICAST_TTL: %m");
- return(0);
+ "setsockopt IP_MULTICAST_TTL: %m");
+ return (0);
}
- return(1);
+ return (1);
}
mib[0] = CTL_NET;
@@ -575,34 +646,38 @@ configure(so)
flags = ifm->ifm_flags;
continue;
}
- if ((flags & IFF_UP) == 0 ||
- (flags & (((multicast_mode == PER_INTERFACE_MULTICAST) ?
- IFF_MULTICAST : 0) |
- IFF_BROADCAST|iff_flag)) == 0)
+ if ((flags & IFF_UP) == 0)
+ continue;
+ lflags = IFF_BROADCAST | iff_flag;
+ if (multicast_mode == PER_INTERFACE_MULTICAST)
+ lflags |= IFF_MULTICAST;
+ if ((flags & lflags) == 0)
continue;
if (ifm->ifm_type != RTM_NEWADDR)
quit("out of sync parsing NET_RT_IFLIST");
ifam = (struct ifa_msghdr *)ifm;
info.rti_addrs = ifam->ifam_addrs;
rt_xaddrs((char *)(ifam + 1), ifam->ifam_msglen + (char *)ifam,
- &info);
+ &info);
/* gag, wish we could get rid of Internet dependencies */
-#define dstaddr info.rti_info[RTAX_BRD]
-#define ifaddr info.rti_info[RTAX_IFA]
-#define IPADDR_SA(x) ((struct sockaddr_in *)(x))->sin_addr.s_addr
-#define PORT_SA(x) ((struct sockaddr_in *)(x))->sin_port
+#define dstaddr info.rti_info[RTAX_BRD]
+#define ifaddr info.rti_info[RTAX_IFA]
+#define IPADDR_SA(x) ((struct sockaddr_in *)(x))->sin_addr.s_addr
+#define PORT_SA(x) ((struct sockaddr_in *)(x))->sin_port
if (dstaddr == 0 || dstaddr->sa_family != AF_INET)
continue;
PORT_SA(dstaddr) = sp->s_port;
- for (np = neighbors; np != NULL; np = np->n_next)
+ for (np = neighbors; np != NULL; np = np->n_next) {
if (memcmp(sdl->sdl_data, np->n_name,
- sdl->sdl_nlen) == 0 &&
- IPADDR_SA(np->n_addr) == IPADDR_SA(dstaddr))
+ sdl->sdl_nlen) == 0 &&
+ IPADDR_SA(np->n_addr) == IPADDR_SA(dstaddr)) {
break;
+ }
+ }
if (np != NULL)
continue;
len = sizeof(*np) + dstaddr->sa_len + sdl->sdl_nlen + 1;
- np = (struct neighbor *)malloc(len);
+ np = malloc(len);
if (np == NULL)
quit("malloc of neighbor structure");
memset(np, 0, len);
@@ -613,24 +688,24 @@ configure(so)
memcpy((char *)np->n_addr, (char *)dstaddr, np->n_addrlen);
memcpy(np->n_name, sdl->sdl_data, sdl->sdl_nlen);
if (multicast_mode == PER_INTERFACE_MULTICAST &&
- (flags & IFF_MULTICAST) &&
- !(flags & IFF_LOOPBACK)) {
+ (flags & IFF_MULTICAST) != 0 &&
+ (flags & IFF_LOOPBACK) == 0) {
struct ip_mreq mreq;
memcpy((char *)np->n_addr, (char *)ifaddr,
- np->n_addrlen);
+ np->n_addrlen);
mreq.imr_multiaddr.s_addr = htonl(INADDR_WHOD_GROUP);
mreq.imr_interface.s_addr =
- ((struct sockaddr_in *)np->n_addr)->sin_addr.s_addr;
+ ((struct sockaddr_in *)np->n_addr)->sin_addr.s_addr;
if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP,
- &mreq, sizeof(mreq)) < 0) {
+ &mreq, sizeof(mreq)) < 0) {
syslog(LOG_ERR,
"setsockopt IP_ADD_MEMBERSHIP: %m");
#if 0
/* Fall back to broadcast on this if. */
np->n_flags &= ~IFF_MULTICAST;
#else
- free((char *)np);
+ free(np);
continue;
#endif
}
@@ -644,36 +719,32 @@ configure(so)
#ifdef DEBUG
void
-Sendto(s, buf, cc, flags, to, tolen)
- int s;
- const void *buf;
- size_t cc;
- int flags;
- const struct sockaddr *to;
- int tolen;
+Sendto(int s, const void *buf, size_t cc, int flags, const struct sockaddr *to,
+ int tolen)
{
- register struct whod *w = (struct whod *)buf;
- register struct whoent *we;
- struct sockaddr_in *sin = (struct sockaddr_in *)to;
+ struct whod *w;
+ struct whoent *we;
+ struct sockaddr_in *sin;
+ w = (struct whod *)buf;
+ sin = (struct sockaddr_in *)to;
printf("sendto %x.%d\n", ntohl(sin->sin_addr.s_addr),
- ntohs(sin->sin_port));
+ ntohs(sin->sin_port));
printf("hostname %s %s\n", w->wd_hostname,
- interval(ntohl(w->wd_sendtime) - ntohl(w->wd_boottime), " up"));
+ interval(ntohl(w->wd_sendtime) - ntohl(w->wd_boottime), " up"));
printf("load %4.2f, %4.2f, %4.2f\n",
ntohl(w->wd_loadav[0]) / 100.0, ntohl(w->wd_loadav[1]) / 100.0,
ntohl(w->wd_loadav[2]) / 100.0);
cc -= WHDRSIZE;
for (we = w->wd_we, cc /= sizeof(struct whoent); cc > 0; cc--, we++) {
time_t t = _time32_to_time(ntohl(we->we_utmp.out_time));
- printf("%-8.8s %s:%s %.12s",
- we->we_utmp.out_name,
- w->wd_hostname, we->we_utmp.out_line,
- ctime(&t)+4);
+
+ printf("%-8.8s %s:%s %.12s", we->we_utmp.out_name,
+ w->wd_hostname, we->we_utmp.out_line, ctime(&t) + 4);
we->we_idle = ntohl(we->we_idle) / 60;
- if (we->we_idle) {
- if (we->we_idle >= 100*60)
- we->we_idle = 100*60 - 1;
+ if (we->we_idle != 0) {
+ if (we->we_idle >= 100 * 60)
+ we->we_idle = 100 * 60 - 1;
if (we->we_idle >= 60)
printf(" %2d", we->we_idle / 60);
else
@@ -685,26 +756,27 @@ Sendto(s, buf, cc, flags, to, tolen)
}
char *
-interval(time, updown)
- int time;
- char *updown;
+interval(int time, char *updown)
{
static char resbuf[32];
int days, hours, minutes;
- if (time < 0 || time > 3*30*24*60*60) {
+ if (time < 0 || time > 3 * 30 * 24 * 60 * 60) {
(void) sprintf(resbuf, " %s ??:??", updown);
return (resbuf);
}
minutes = (time + 59) / 60; /* round to minutes */
- hours = minutes / 60; minutes %= 60;
- days = hours / 24; hours %= 24;
- if (days)
+ hours = minutes / 60;
+ minutes %= 60;
+ days = hours / 24;
+ hours %= 24;
+ if (days > 0) {
(void) sprintf(resbuf, "%s %2d+%02d:%02d",
updown, days, hours, minutes);
- else
+ } else {
(void) sprintf(resbuf, "%s %2d:%02d",
updown, hours, minutes);
+ }
return (resbuf);
}
#endif
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index bb56b6b..8fc2678 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -2476,7 +2476,7 @@ validate(struct sockaddr *sa, const char *hname)
static int
p_open(const char *prog, pid_t *rpid)
{
- int pfd[2], nulldesc, i;
+ int pfd[2], nulldesc;
pid_t pid;
sigset_t omask, mask;
char *argv[4]; /* sh -c cmd NULL */
@@ -2526,8 +2526,7 @@ p_open(const char *prog, pid_t *rpid)
dup2(pfd[0], STDIN_FILENO);
dup2(nulldesc, STDOUT_FILENO);
dup2(nulldesc, STDERR_FILENO);
- for (i = getdtablesize(); i > 2; i--)
- (void)close(i);
+ closefrom(3);
(void)execvp(_PATH_BSHELL, argv);
_exit(255);
diff --git a/usr.sbin/sysrc/sysrc b/usr.sbin/sysrc/sysrc
index e1c15d6..7e1ddcb 100644
--- a/usr.sbin/sysrc/sysrc
+++ b/usr.sbin/sysrc/sysrc
@@ -1,6 +1,6 @@
#!/bin/sh
#-
-# Copyright (c) 2010-2012 Devin Teske
+# Copyright (c) 2010-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -13,7 +13,7 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
@@ -32,13 +32,6 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
[ "$_COMMON_SUBR" ] || . $BSDCFG_SHARE/common.subr || exit 1
[ "$_SYSRC_SUBR" ] || f_include $BSDCFG_SHARE/sysrc.subr
-############################################################ CONFIGURATION
-
-#
-# Default verbosity.
-#
-: ${SYSRC_VERBOSE:=}
-
############################################################ GLOBALS
#
@@ -55,6 +48,7 @@ SHOW_EQUALS=
SHOW_FILE=
SHOW_NAME=1
SHOW_VALUE=1
+SYSRC_VERBOSE=
############################################################ FUNCTIONS
diff --git a/usr.sbin/sysrc/sysrc.8 b/usr.sbin/sysrc/sysrc.8
index 43ba885..b5671a0 100644
--- a/usr.sbin/sysrc/sysrc.8
+++ b/usr.sbin/sysrc/sysrc.8
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2011-2012 Devin Teske
+.\" Copyright (c) 2011-2013 Devin Teske
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd Aug 24, 2012
+.Dd Jul 5, 2013
.Dt SYSRC 8
.Os
.Sh NAME
@@ -99,10 +99,9 @@ Show only variable values, not their names.
Show only variable names, not their values.
.It Fl q
Quiet.
-Ignore previous
+Ignore previous occurrences of
.Fl v
-and/or
-.Ev SYSRC_VERBOSE .
+flag.
.It Fl R Ar dir
Operate within the root directory
.Pq Sq Ar dir
@@ -175,7 +174,7 @@ be called repeatedly).
.Sh ENVIRONMENT
The following environment variables are referenced by
.Nm :
-.Bl -tag -width ".Ev SYSRC_VERBOSE"
+.Bl -tag -width ".Ev RC_DEFAULTS"
.It Ev RC_CONFS
Override default
.Ql rc_conf_files
@@ -184,9 +183,6 @@ Override default
Location of
.Ql /etc/defaults/rc.conf
file.
-.It Ev SYSRC_VERBOSE
-Default verbosity.
-Set to non-NULL to enable.
.El
.Sh DEPENDENCIES
The following standard commands are required by
@@ -292,7 +288,7 @@ This will be corrected by a future enhancement.
A
.Nm
utility first appeared in
-.Fx 10.0 .
+.Fx 9.2 .
.Sh AUTHORS
.An Devin Teske Aq dteske@FreeBSD.org
.Sh THANKS TO
diff --git a/usr.sbin/tcpdump/tcpdump/Makefile b/usr.sbin/tcpdump/tcpdump/Makefile
index ca8ec4c..fe2a001 100644
--- a/usr.sbin/tcpdump/tcpdump/Makefile
+++ b/usr.sbin/tcpdump/tcpdump/Makefile
@@ -7,37 +7,136 @@ TCPDUMP_DISTDIR?= ${.CURDIR}/../../../contrib/tcpdump
PROG= tcpdump
-SRCS = addrtoname.c af.c checksum.c cpack.c gmpls.c oui.c gmt2local.c \
- ipproto.c nlpid.c l2vpn.c machdep.c parsenfsfh.c in_cksum.c \
- print-802_11.c print-802_15_4.c print-ap1394.c print-ah.c print-arcnet.c \
- print-aodv.c print-arp.c print-ascii.c print-atalk.c print-atm.c \
- print-beep.c print-bfd.c print-bgp.c print-bootp.c print-bt.c \
- print-carp.c print-cdp.c \
- print-cfm.c print-chdlc.c print-cip.c print-cnfp.c print-dccp.c \
- print-decnet.c print-domain.c print-dtp.c print-dvmrp.c print-enc.c \
- print-egp.c print-eap.c print-eigrp.c \
- print-esp.c print-ether.c print-fddi.c print-forces.c print-fr.c \
- print-gre.c print-hsrp.c print-icmp.c print-igmp.c \
- print-igrp.c print-ip.c print-ipcomp.c print-ipfc.c print-ipnet.c \
- print-ipx.c print-isakmp.c print-isoclns.c print-juniper.c print-krb.c \
- print-l2tp.c print-lane.c print-ldp.c print-lldp.c print-llc.c \
- print-lmp.c print-lspping.c \
- print-lwapp.c print-lwres.c print-mobile.c print-mpls.c print-msdp.c \
+SRCS= addrtoname.c \
+ af.c \
+ checksum.c \
+ cpack.c \
+ gmpls.c \
+ gmt2local.c \
+ in_cksum.c \
+ ipproto.c \
+ l2vpn.c \
+ machdep.c \
+ nlpid.c \
+ oui.c \
+ parsenfsfh.c \
+ print-802_11.c \
+ print-802_15_4.c \
+ print-ah.c \
+ print-aodv.c \
+ print-ap1394.c \
+ print-arcnet.c \
+ print-arp.c \
+ print-ascii.c \
+ print-atalk.c \
+ print-atm.c \
+ print-beep.c \
+ print-bfd.c \
+ print-bgp.c \
+ print-bootp.c \
+ print-bt.c \
+ print-carp.c \
+ print-cdp.c \
+ print-cfm.c \
+ print-chdlc.c \
+ print-cip.c \
+ print-cnfp.c \
+ print-dccp.c \
+ print-decnet.c \
+ print-domain.c \
+ print-dtp.c \
+ print-dvmrp.c \
+ print-eap.c \
+ print-egp.c \
+ print-eigrp.c \
+ print-enc.c \
+ print-esp.c \
+ print-ether.c \
+ print-fddi.c \
+ print-forces.c \
+ print-fr.c \
+ print-gre.c \
+ print-hsrp.c \
+ print-icmp.c \
+ print-igmp.c \
+ print-igrp.c \
+ print-ip.c \
+ print-ipcomp.c \
+ print-ipfc.c \
+ print-ipnet.c \
+ print-ipx.c \
+ print-isakmp.c \
+ print-isoclns.c \
+ print-juniper.c \
+ print-krb.c \
+ print-l2tp.c \
+ print-lane.c \
+ print-ldp.c \
+ print-llc.c \
+ print-lldp.c \
+ print-lmp.c \
+ print-lspping.c \
+ print-lwapp.c \
+ print-lwres.c \
+ print-mobile.c \
print-mpcp.c \
- print-nfs.c print-ntp.c print-null.c print-olsr.c print-ospf.c \
+ print-mpls.c \
+ print-msdp.c \
+ print-msnlb.c \
+ print-nfs.c \
+ print-ntp.c \
+ print-null.c \
+ print-olsr.c \
+ print-ospf.c \
+ print-otv.c \
print-pfsync.c \
- print-pgm.c print-pim.c print-ppi.c print-ppp.c print-pppoe.c \
- print-pptp.c print-radius.c print-raw.c print-rip.c \
+ print-pgm.c \
+ print-pim.c \
+ print-ppi.c \
+ print-ppp.c \
+ print-pppoe.c \
+ print-pptp.c \
+ print-radius.c \
+ print-raw.c \
+ print-rip.c \
print-rpki-rtr.c \
- print-rrcp.c print-rsvp.c print-rx.c print-sctp.c print-sflow.c \
- print-sip.c print-sl.c print-sll.c \
- print-slow.c print-snmp.c print-stp.c print-sunatm.c print-sunrpc.c \
- print-symantec.c print-syslog.c print-tcp.c print-telnet.c print-tftp.c \
- print-timed.c print-tipc.c \
- print-token.c print-udld.c print-udp.c print-vjc.c \
- print-vqp.c print-vrrp.c print-vtp.c \
- print-wb.c print-zephyr.c setsignal.c tcpdump.c util.c \
- print-smb.c signature.c smbutil.c \
+ print-rrcp.c \
+ print-rsvp.c \
+ print-rx.c \
+ print-sctp.c \
+ print-sflow.c \
+ print-sip.c \
+ print-sl.c \
+ print-sll.c \
+ print-slow.c \
+ print-smb.c \
+ print-snmp.c \
+ print-stp.c \
+ print-sunatm.c \
+ print-sunrpc.c \
+ print-symantec.c \
+ print-syslog.c \
+ print-tcp.c \
+ print-telnet.c \
+ print-tftp.c \
+ print-timed.c \
+ print-tipc.c \
+ print-token.c \
+ print-udld.c \
+ print-udp.c \
+ print-vjc.c \
+ print-vqp.c \
+ print-vrrp.c \
+ print-vtp.c \
+ print-vxlan.c \
+ print-wb.c \
+ print-zephyr.c \
+ print-zeromq.c \
+ setsignal.c \
+ signature.c \
+ smbutil.c \
+ tcpdump.c \
+ util.c \
version.c
CLEANFILES+= version.c
@@ -46,9 +145,16 @@ CFLAGS+= -DHAVE_CONFIG_H
CFLAGS+= -D_U_="__attribute__((unused))"
.if ${MK_INET6_SUPPORT} != "no"
-SRCS+= print-ip6.c print-ip6opts.c print-mobility.c print-ripng.c \
- print-icmp6.c print-babel.c print-frag6.c print-rt6.c print-ospf6.c \
- print-dhcp6.c
+SRCS+= print-babel.c \
+ print-dhcp6.c \
+ print-frag6.c \
+ print-icmp6.c \
+ print-ip6.c \
+ print-ip6opts.c \
+ print-mobility.c \
+ print-ospf6.c \
+ print-ripng.c \
+ print-rt6.c
CFLAGS+= -DINET6
.endif
.if ${MACHINE_CPUARCH} != "i386"
diff --git a/usr.sbin/tcpdump/tcpdump/config.h b/usr.sbin/tcpdump/tcpdump/config.h
index b13055d..62fa3cd 100644
--- a/usr.sbin/tcpdump/tcpdump/config.h
+++ b/usr.sbin/tcpdump/tcpdump/config.h
@@ -255,7 +255,7 @@
/* #undef NETINET_ETHER_H_DECLARES_ETHER_NTOHOST */
/* Define to 1 if netinet/if_ether.h declares `ether_ntohost' */
-#define NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST
+#define NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST /**/
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
@@ -276,7 +276,7 @@
#define RETSIGTYPE void
/* return value of signal handlers */
-#define RETSIGVAL
+#define RETSIGVAL /**/
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
diff --git a/usr.sbin/tcpdump/tcpdump/tcpdump.1 b/usr.sbin/tcpdump/tcpdump/tcpdump.1
index 11706e7..ca6d795 100644
--- a/usr.sbin/tcpdump/tcpdump/tcpdump.1
+++ b/usr.sbin/tcpdump/tcpdump/tcpdump.1
@@ -23,7 +23,7 @@
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
.\"
-.TH TCPDUMP 1 "05 March 2009"
+.TH TCPDUMP 1 "12 July 2012"
.SH NAME
tcpdump \- dump traffic on a network
.SH SYNOPSIS
@@ -75,6 +75,10 @@ tcpdump \- dump traffic on a network
.I file
]
[
+.B \-V
+.I file
+]
+[
.B \-s
.I snaplen
]
@@ -128,8 +132,10 @@ flag, which causes it to save the packet data to a file for later
analysis, and/or with the
.B \-r
flag, which causes it to read from a saved packet file rather than to
-read packets from a network interface. In all cases, only packets that
-match
+read packets from a network interface. It can also be run with the
+.B \-V
+flag, which causes it to read a list of saved packet files. In all cases,
+only packets that match
.I expression
will be processed by
.IR tcpdump .
@@ -257,7 +263,9 @@ that lacks the
function.
.TP
.B \-e
-Print the link-level header on each dump line.
+Print the link-level header on each dump line. This can be used, for
+example, to print MAC layer addresses for protocols such as Ethernet and
+IEEE 802.11.
.TP
.B \-E
Use \fIspi@ipaddr algo:secret\fP for decrypting IPsec ESP packets that
@@ -510,15 +518,19 @@ Force packets selected by "\fIexpression\fP" to be interpreted the
specified \fItype\fR.
Currently known types are
\fBaodv\fR (Ad-hoc On-demand Distance Vector protocol),
+\fBcarp\fR (Common Address Redundancy Protocol),
\fBcnfp\fR (Cisco NetFlow protocol),
+\fBradius\fR (RADIUS),
\fBrpc\fR (Remote Procedure Call),
\fBrtp\fR (Real-Time Applications protocol),
\fBrtcp\fR (Real-Time Applications control protocol),
\fBsnmp\fR (Simple Network Management Protocol),
\fBtftp\fR (Trivial File Transfer Protocol),
\fBvat\fR (Visual Audio Tool),
+\fBwb\fR (distributed White Board),
+\fBzmtp1\fR (ZeroMQ Message Transport Protocol 1.0)
and
-\fBwb\fR (distributed White Board).
+\fBvxlan\fR (Virtual eXtensible Local Area Network).
.TP
.B \-t
\fIDon't\fP print a timestamp on each dump line.
@@ -591,6 +603,10 @@ With
.B \-X
Telnet options are printed in hex as well.
.TP
+.B \-V
+Read a list of filenames from \fIfile\fR. Standard input is used
+if \fIfile\fR is ``-''.
+.TP
.B \-w
Write the raw packets to \fIfile\fR rather than parsing and printing
them out.
@@ -603,6 +619,15 @@ amount of time after they are received. Use the
.B \-U
flag to cause packets to be written as soon as they are received.
.IP
+The MIME type \fIapplication/vnd.tcpdump.pcap\fP has been registered
+with IANA for \fIpcap\fP files. The filename extension \fI.pcap\fP
+appears to be the most commonly used along with \fI.cap\fP and
+\fI.dmp\fP. \fITcpdump\fP itself doesn't check the extension when
+reading capture files and doesn't add an extension when writing them
+(it uses magic numbers in the file header instead). However, many
+operating systems and applications will use the extension if it is
+present and adding one (e.g. .pcap) is recommended.
+.IP
See
.BR pcap-savefile (5)
for a description of the file format.
@@ -706,8 +731,10 @@ For the \fIexpression\fP syntax, see
.LP
Expression arguments can be passed to \fItcpdump\fP as either a single
argument or as multiple arguments, whichever is more convenient.
-Generally, if the expression contains Shell metacharacters, it is
-easier to pass it as a single, quoted argument.
+Generally, if the expression contains Shell metacharacters, such as
+backslashes used to escape protocol names, it is easier to pass it as
+a single, quoted argument rather than to escape the Shell
+metacharacters.
Multiple arguments are concatenated with spaces before being parsed.
.SH EXAMPLES
.LP
@@ -1709,6 +1736,11 @@ serviced the `new packet' interrupt.
.SH "SEE ALSO"
stty(1), pcap(3PCAP), bpf(4), nit(4P), pcap-savefile(5),
pcap-filter(7), pcap-tstamp-type(7)
+.LP
+.RS
+.I http://www.iana.org/assignments/media-types/application/vnd.tcpdump.pcap
+.RE
+.LP
.SH AUTHORS
The original authors are:
.LP
@@ -1728,7 +1760,7 @@ The current version is available via http:
The original distribution is available via anonymous ftp:
.LP
.RS
-.I ftp://ftp.ee.lbl.gov/tcpdump.tar.Z
+.I ftp://ftp.ee.lbl.gov/old/tcpdump.tar.Z
.RE
.LP
IPv6/IPsec support is added by WIDE/KAME project.
diff --git a/usr.sbin/timed/timed/timed.8 b/usr.sbin/timed/timed/timed.8
index 8dabd38..9997563 100644
--- a/usr.sbin/timed/timed/timed.8
+++ b/usr.sbin/timed/timed/timed.8
@@ -44,7 +44,7 @@ The
.Nm
utility is a time server daemon
which is normally invoked at boot time from the
-.Xr rc.network 8
+.Xr rc.conf 5
file.
It synchronizes the host's time with the time of other
machines, which are also running
diff --git a/usr.sbin/uhsoctl/uhsoctl.1 b/usr.sbin/uhsoctl/uhsoctl.1
index cd0c5ca..826a1ec 100644
--- a/usr.sbin/uhsoctl/uhsoctl.1
+++ b/usr.sbin/uhsoctl/uhsoctl.1
@@ -50,7 +50,7 @@
is a small connection utility for Option N.V. devices that are based on Options
packet interface and uses proprietary AT_* calls to establish connections.
The utility (tries to) configure both default route and name servers
-(/etc/resolv.conf).
+.Po Pa /etc/resolv.conf Pc .
.Pp
By default
.Nm
@@ -76,8 +76,13 @@ Specify username.
.It Fl k Ar password
Specify username.
.It Fl r Ar path
-Path to resolv.conf, default /etc/resolv.conf.
-Use /dev/null to disable updating of name servers.
+Path to
+.Pa resolv.conf ,
+default
+.Pa /etc/resolv.conf .
+Use
+.Pa /dev/null
+to disable updating of name servers.
.It Fl f Ar path
Explicitly set the serial port to use as controlling terminal.
Might be needed if the automatic detection fails.
diff --git a/usr.sbin/vidcontrol/vidcontrol.c b/usr.sbin/vidcontrol/vidcontrol.c
index d07f892..f4f1f0d 100644
--- a/usr.sbin/vidcontrol/vidcontrol.c
+++ b/usr.sbin/vidcontrol/vidcontrol.c
@@ -959,7 +959,7 @@ show_mode_info(void)
printf("---------------------------------------"
"---------------------------------------\n");
- for (mode = 0; mode < M_VESA_MODE_MAX; ++mode) {
+ for (mode = 0; mode <= M_VESA_MODE_MAX; ++mode) {
_info.vi_mode = mode;
if (ioctl(0, CONS_MODEINFO, &_info))
continue;
diff --git a/usr.sbin/wake/wake.8 b/usr.sbin/wake/wake.8
index ce30abf..5324907 100644
--- a/usr.sbin/wake/wake.8
+++ b/usr.sbin/wake/wake.8
@@ -56,7 +56,7 @@ Link layer addresses can be determined and set using
.Xr ifconfig 8 .
.Sh FILES
.Bl -tag -width "/etc/ethers" -compact
-.It /etc/ethers
+.It Pa /etc/ethers
Ethernet host name data base.
.El
.Sh SEE ALSO
diff --git a/usr.sbin/watchdogd/watchdogd.8 b/usr.sbin/watchdogd/watchdogd.8
index b8a5505..6176a20 100644
--- a/usr.sbin/watchdogd/watchdogd.8
+++ b/usr.sbin/watchdogd/watchdogd.8
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd March 5, 2013
+.Dd July 27, 2013
.Dt WATCHDOGD 8
.Os
.Sh NAME
@@ -115,7 +115,7 @@ will terminate.
The
.Nm
utility recognizes the following runtime options:
-.Bl -tag -width ".Fl -softtimeout-action Ar action "
+.Bl -tag -width 30m
.It Fl I Ar file
Write the process ID of the
.Nm
@@ -208,6 +208,96 @@ device for
.Bl -tag -width ".Pa /var/run/watchdogd.pid" -compact
.It Pa /var/run/watchdogd.pid
.El
+.Sh EXAMPLES
+.Ss Debugging watchdogd and/or your watchdog script.
+This is a useful recipe for debugging
+.Nm
+and your watchdog script.
+.Pp
+(Note that ^C works oddly because
+.Nm
+calls
+.Xr system 3
+so the
+first ^C will terminate the "sleep" command.)
+.Pp
+Explanation of options used:
+.Bl -enum -offset indent -compact
+.It
+Set Debug on (--debug)
+.It
+Set the watchdog to trip at 30 seconds. (-t 30)
+.It
+Use of a softtimeout:
+.Bl -enum -offset indent -compact -nested
+.It
+Use a softtimeout (do not arm the hardware watchdog).
+(--softtimeout)
+.It
+Set the softtimeout action to do both kernel
+.Xr printf 9
+and
+.Xr log 9
+when it trips.
+(--softtimeout-action log,printf)
+.El
+.It
+Use of a pre-timeout:
+.Bl -enum -offset indent -compact -nested
+.It
+Set a pre-timeout of 15 seconds (this will later trigger a panic/dump).
+(--pretimeout 15)
+.It
+Set the action to also kernel
+.Xr printf 9
+and
+.Xr log 9
+when it trips.
+(--pretimeout-action log,printf)
+.El
+.It
+Use of a script:
+.Bl -enum -offset indent -compact -nested
+.It
+Run "sleep 60" as a shell command that acts as the watchdog (-e 'sleep 60')
+.It
+Warn us when the script takes longer than 1 second to run (-w)
+.El
+.El
+.Bd -literal
+watchdogd --debug -t 30 \\
+ --softtimeout --softtimeout-action log,printf \\
+ --pretimeout 15 --pretimeout-action log,printf \\
+ -e 'sleep 60' -w
+.Ed
+.Ss Production use of example
+.Bl -enum -offset indent -compact
+.It
+Set hard timeout to 120 seconds (-t 120)
+.It
+Set a panic to happen at 60 seconds (to trigger a
+.Xr crash 8
+for dump analysis):
+.Bl -enum -offset indent -compact -nested
+.It
+Use of pre-timeout (--pretimeout 60)
+.It
+Specify pre-timeout action (--pretimeout-action log,printf,panic )
+.El
+.It
+Use of a script:
+.Bl -enum -offset indent -compact -nested
+.It
+Run your script (-e '/path/to/your/script 60')
+.It
+Log if your script takes a longer than 15 seconds to run time. (-w -T 15)
+.El
+.El
+.Bd -literal
+watchdogd -t 120 \\
+ --pretimeout 60 --pretimeout-action log,printf,panic \\
+ -e '/path/to/your/script 60' -w -T 15
+.Ed
.Sh SEE ALSO
.Xr watchdog 4 ,
.Xr watchdog 8 ,
diff --git a/usr.sbin/watchdogd/watchdogd.c b/usr.sbin/watchdogd/watchdogd.c
index 5416751..5fd16f5 100644
--- a/usr.sbin/watchdogd/watchdogd.c
+++ b/usr.sbin/watchdogd/watchdogd.c
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include <sys/rtprio.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <sys/sysctl.h>
#include <sys/watchdog.h>
#include <err.h>
@@ -49,6 +50,7 @@ __FBSDID("$FreeBSD$");
#include <paths.h>
#include <signal.h>
#include <stdio.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
@@ -58,19 +60,25 @@ __FBSDID("$FreeBSD$");
#include <getopt.h>
+static long fetchtimeout(int opt,
+ const char *longopt, const char *myoptarg, int zero_ok);
static void parseargs(int, char *[]);
+static int seconds_to_pow2ns(int);
static void sighandler(int);
static void watchdog_loop(void);
static int watchdog_init(void);
static int watchdog_onoff(int onoff);
static int watchdog_patpat(u_int timeout);
static void usage(void);
+static int tstotv(struct timeval *tv, struct timespec *ts);
+static int tvtohz(struct timeval *tv);
static int debugging = 0;
static int end_program = 0;
static const char *pidfile = _PATH_VARRUN "watchdogd.pid";
static u_int timeout = WD_TO_128SEC;
static u_int pretimeout = 0;
+static u_int timeout_sec;
static u_int passive = 0;
static int is_daemon = 0;
static int is_dry_run = 0; /* do not arm the watchdog, only
@@ -183,6 +191,59 @@ main(int argc, char *argv[])
}
}
+static void
+pow2ns_to_ts(int pow2ns, struct timespec *ts)
+{
+ uint64_t ns;
+
+ ns = 1ULL << pow2ns;
+ ts->tv_sec = ns / 1000000000ULL;
+ ts->tv_nsec = ns % 1000000000ULL;
+}
+
+/*
+ * Convert a timeout in seconds to N where 2^N nanoseconds is close to
+ * "seconds".
+ *
+ * The kernel expects the timeouts for watchdogs in "2^N nanosecond format".
+ */
+static u_int
+parse_timeout_to_pow2ns(char opt, const char *longopt, const char *myoptarg)
+{
+ double a;
+ u_int rv;
+ struct timespec ts;
+ struct timeval tv;
+ int ticks;
+ char shortopt[] = "- ";
+
+ if (!longopt)
+ shortopt[1] = opt;
+
+ a = fetchtimeout(opt, longopt, myoptarg, 1);
+
+ if (a == 0)
+ rv = WD_TO_NEVER;
+ else
+ rv = seconds_to_pow2ns(a);
+ pow2ns_to_ts(rv, &ts);
+ tstotv(&tv, &ts);
+ ticks = tvtohz(&tv);
+ if (debugging) {
+ printf("Timeout for %s%s "
+ "is 2^%d nanoseconds "
+ "(in: %s sec -> out: %jd sec %ld ns -> %d ticks)\n",
+ longopt ? "-" : "", longopt ? longopt : shortopt,
+ rv,
+ myoptarg, (intmax_t)ts.tv_sec, ts.tv_nsec, ticks);
+ }
+ if (ticks <= 0) {
+ errx(1, "Timeout for %s%s is too small, please choose a higher timeout.", longopt ? "-" : "", longopt ? longopt : shortopt);
+ }
+
+ return (rv);
+}
+
/*
* Catch signals and begin shutdown process.
*/
@@ -427,7 +488,7 @@ usage(void)
}
static long
-fetchtimeout(int opt, const char *longopt, const char *myoptarg)
+fetchtimeout(int opt, const char *longopt, const char *myoptarg, int zero_ok)
{
const char *errstr;
char *p;
@@ -439,7 +500,7 @@ fetchtimeout(int opt, const char *longopt, const char *myoptarg)
rv = strtol(myoptarg, &p, 0);
if ((p != NULL && *p != '\0') || errno != 0)
errstr = "is not a number";
- if (rv <= 0)
+ if (rv < 0 || (!zero_ok && rv == 0))
errstr = "must be greater than zero";
if (errstr) {
if (longopt)
@@ -513,6 +574,110 @@ timeout_act_str2int(const char *lopt, const char *acts)
return rv;
}
+int
+tstotv(struct timeval *tv, struct timespec *ts)
+{
+
+ tv->tv_sec = ts->tv_sec;
+ tv->tv_usec = ts->tv_nsec / 1000;
+ return 0;
+}
+
+/*
+ * Convert a timeval to a number of ticks.
+ * Mostly copied from the kernel.
+ */
+int
+tvtohz(struct timeval *tv)
+{
+ register unsigned long ticks;
+ register long sec, usec;
+ int hz;
+ size_t hzsize;
+ int error;
+ int tick;
+
+ hzsize = sizeof(hz);
+
+ error = sysctlbyname("kern.hz", &hz, &hzsize, NULL, 0);
+ if (error)
+ err(1, "sysctlbyname kern.hz");
+
+ tick = 1000000 / hz;
+
+ /*
+ * If the number of usecs in the whole seconds part of the time
+ * difference fits in a long, then the total number of usecs will
+ * fit in an unsigned long. Compute the total and convert it to
+ * ticks, rounding up and adding 1 to allow for the current tick
+ * to expire. Rounding also depends on unsigned long arithmetic
+ * to avoid overflow.
+ *
+ * Otherwise, if the number of ticks in the whole seconds part of
+ * the time difference fits in a long, then convert the parts to
+ * ticks separately and add, using similar rounding methods and
+ * overflow avoidance. This method would work in the previous
+ * case but it is slightly slower and assumes that hz is integral.
+ *
+ * Otherwise, round the time difference down to the maximum
+ * representable value.
+ *
+ * If ints have 32 bits, then the maximum value for any timeout in
+ * 10ms ticks is 248 days.
+ */
+ sec = tv->tv_sec;
+ usec = tv->tv_usec;
+ if (usec < 0) {
+ sec--;
+ usec += 1000000;
+ }
+ if (sec < 0) {
+#ifdef DIAGNOSTIC
+ if (usec > 0) {
+ sec++;
+ usec -= 1000000;
+ }
+ printf("tvotohz: negative time difference %ld sec %ld usec\n",
+ sec, usec);
+#endif
+ ticks = 1;
+ } else if (sec <= LONG_MAX / 1000000)
+ ticks = (sec * 1000000 + (unsigned long)usec + (tick - 1))
+ / tick + 1;
+ else if (sec <= LONG_MAX / hz)
+ ticks = sec * hz
+ + ((unsigned long)usec + (tick - 1)) / tick + 1;
+ else
+ ticks = LONG_MAX;
+ if (ticks > INT_MAX)
+ ticks = INT_MAX;
+ return ((int)ticks);
+}
+
+static int
+seconds_to_pow2ns(int seconds)
+{
+ uint64_t power;
+ uint64_t ns;
+ uint64_t shifted;
+
+ if (seconds <= 0)
+ errx(1, "seconds %d < 0", seconds);
+ ns = ((uint64_t)seconds) * 1000000000ULL;
+ power = flsll(ns);
+ shifted = 1ULL << power;
+ if (shifted <= ns) {
+ power++;
+ }
+ if (debugging) {
+ printf("shifted %lld\n", (long long)shifted);
+ printf("seconds_to_pow2ns: seconds: %d, ns %lld, power %d\n",
+ seconds, (long long)ns, (int)power);
+ }
+ return (power);
+}
+
+
/*
* Handle the few command line arguments supported.
*/
@@ -521,9 +686,7 @@ parseargs(int argc, char *argv[])
{
int longindex;
int c;
- char *p;
const char *lopt;
- double a;
/*
* if we end with a 'd' aka 'watchdogd' then we are the daemon program,
@@ -559,30 +722,21 @@ parseargs(int argc, char *argv[])
break;
#endif
case 's':
- nap = fetchtimeout(c, NULL, optarg);
+ nap = fetchtimeout(c, NULL, optarg, 0);
break;
case 'S':
do_syslog = 0;
break;
case 't':
- p = NULL;
- errno = 0;
- a = strtod(optarg, &p);
- if ((p != NULL && *p != '\0') || errno != 0)
- errx(EX_USAGE, "-t argument is not a number");
- if (a < 0)
- errx(EX_USAGE, "-t argument must be positive");
-
- if (a == 0)
- timeout = WD_TO_NEVER;
- else
- timeout = flsll(a * 1e9);
- if (debugging)
- printf("Timeout is 2^%d nanoseconds\n",
- timeout);
+ timeout_sec = atoi(optarg);
+ timeout = parse_timeout_to_pow2ns(c, NULL, optarg);
+ if (debugging)
+ printf("Timeout is 2^%d nanoseconds\n",
+ timeout);
break;
case 'T':
- carp_thresh_seconds = fetchtimeout(c, "NULL", optarg);
+ carp_thresh_seconds =
+ fetchtimeout(c, "NULL", optarg, 0);
break;
case 'w':
do_timedog = 1;
@@ -590,7 +744,7 @@ parseargs(int argc, char *argv[])
case 0:
lopt = longopts[longindex].name;
if (!strcmp(lopt, "pretimeout")) {
- pretimeout = fetchtimeout(0, lopt, optarg);
+ pretimeout = fetchtimeout(0, lopt, optarg, 0);
} else if (!strcmp(lopt, "pretimeout-action")) {
pretimeout_act = timeout_act_str2int(lopt,
optarg);
@@ -618,4 +772,15 @@ parseargs(int argc, char *argv[])
errx(EX_USAGE, "extra arguments.");
if (is_daemon && timeout < WD_TO_1SEC)
errx(EX_USAGE, "-t argument is less than one second.");
+ if (pretimeout_set) {
+ struct timespec ts;
+
+ pow2ns_to_ts(timeout, &ts);
+ if (pretimeout >= (uintmax_t)ts.tv_sec) {
+ errx(EX_USAGE,
+ "pretimeout (%d) >= timeout (%d -> %ld)\n"
+ "see manual section TIMEOUT RESOLUTION",
+ pretimeout, timeout_sec, (long)ts.tv_sec);
+ }
+ }
}
diff --git a/usr.sbin/wpa/Makefile.crypto b/usr.sbin/wpa/Makefile.crypto
index e1ac445..94367bb 100644
--- a/usr.sbin/wpa/Makefile.crypto
+++ b/usr.sbin/wpa/Makefile.crypto
@@ -1,20 +1,24 @@
# $FreeBSD$
.if ${MK_OPENSSL} != "no" && !defined(RELEASE_CRUNCH)
-SRCS+= crypto_openssl.c
+SRCS+= crypto_openssl.c random.c sha1-prf.c sha256-prf.c
DPADD+= ${LIBSSL} ${LIBCRYPTO}
LDADD+= -lssl -lcrypto
+CFLAGS+= -DCONFIG_SHA256
.else
CFLAGS+=-DCONFIG_CRYPTO_INTERNAL
-SRCS+= crypto_internal.c
+SRCS+= crypto_internal.c random.c
CONFIG_INTERNAL_AES=y
CONFIG_INTERNAL_DES=y
CONFIG_INTERNAL_MD4=y
CONFIG_INTERNAL_MD5=y
CONFIG_INTERNAL_RC4=y
CONFIG_INTERNAL_SHA1=y
+NEED_SHA256=y
CONFIG_INTERNAL_SHA256=y
CONFIG_INTERNAL_TLS=y
+CONFIG_INTERNAL_DH5=y
+CONFIG_INTERNAL_DH=y
NEED_AES_ENC=true
.endif
@@ -105,17 +109,25 @@ SRCS+= rc4.c
.endif
.if defined(CONFIG_INTERNAL_SHA1)
-SRCS+= sha1-internal.c
+SRCS+= sha1-internal.c sha1-pbkdf2.c sha1.c sha1-prf.c
.endif
.if defined(NEED_SHA256)
CFLAGS+=-DCONFIG_SHA256
SRCS+= sha256.c
.if defined(CONFIG_INTERNAL_SHA256)
-SRCS+= sha256-internal.c
+SRCS+= sha256-internal.c sha256-prf.c
.endif
.endif
.if defined(NEED_TLS_PRF)
SRCS+= sha1-tlsprf.c
.endif
+
+.if defined(CONFIG_INTERNAL_DH5)
+SRCS+= dh_group5.c
+.endif
+
+.if defined(CONFIG_INTERNAL_DH)
+SRCS+= dh_groups.c
+.endif
diff --git a/usr.sbin/wpa/Makefile.inc b/usr.sbin/wpa/Makefile.inc
index bbd55fc..0b13b97 100644
--- a/usr.sbin/wpa/Makefile.inc
+++ b/usr.sbin/wpa/Makefile.inc
@@ -19,7 +19,8 @@ HOSTAPD_DISTDIR?= ${WPA_DISTDIR}/hostapd
${WPA_DISTDIR}/src/radius \
${WPA_DISTDIR}/src/rsn_supp \
${WPA_DISTDIR}/src/tls \
- ${WPA_DISTDIR}/src/utils
+ ${WPA_DISTDIR}/src/utils \
+ ${WPA_DISTDIR}/src/wps
CFLAGS+=-I${.CURDIR}
CFLAGS+=-I${HOSTAPD_DISTDIR}
@@ -29,6 +30,7 @@ CFLAGS+=-I${WPA_DISTDIR}/src/crypto
CFLAGS+=-I${WPA_DISTDIR}/src/drivers
CFLAGS+=-I${WPA_DISTDIR}/src/l2_packet
CFLAGS+=-I${WPA_DISTDIR}/src/utils
+CFLAGS+=-I${WPA_DISTDIR}/src/wps
CFLAGS+= -DCONFIG_CTRL_IFACE
CFLAGS+= -DCONFIG_CTRL_IFACE_UNIX
diff --git a/usr.sbin/wpa/hostapd/Makefile b/usr.sbin/wpa/hostapd/Makefile
index 273c127..530cf02 100644
--- a/usr.sbin/wpa/hostapd/Makefile
+++ b/usr.sbin/wpa/hostapd/Makefile
@@ -6,55 +6,22 @@
${WPA_DISTDIR}/src/drivers
PROG= hostapd
-SRCS= accounting.c \
- aes-wrap.c \
- ap_config.c \
- ap_drv_ops.c \
- ap_mlme.c \
- authsrv.c \
- base64.c \
- chap.c \
- common.c \
- config_file.c \
- ctrl_iface.c \
- ctrl_iface_ap.c \
- drivers.c \
- drv_callbacks.c \
- eap_common.c \
- eap_peap_common.c \
- eap_register.c \
- eapol_auth_dump.c \
- eapol_auth_sm.c \
- eap_server.c \
- eap_server_methods.c \
- eloop.c \
- hostapd.c \
- ieee802_11_auth.c \
- ieee802_11_common.c \
- ieee802_1x.c \
- ip_addr.c \
- main.c \
- md5.c \
- ms_funcs.c \
- os_unix.c \
- peerkey_auth.c \
- pmksa_cache_auth.c \
- preauth_auth.c \
- radius.c \
- radius_client.c \
- sha1-pbkdf2.c \
- sha1.c \
- sta_info.c \
- tkip_countermeasures.c \
- utils.c \
- vlan_init.c \
- wpa_auth.c \
- wpa_auth_glue.c \
- wpa_auth_ie.c \
- wpa_common.c \
- wpa_debug.c \
- wpabuf.c
-SRCS+= l2_packet_freebsd.c driver_freebsd.c
+SRCS= accounting.c aes-wrap.c ap_config.c ap_drv_ops.c ap_mlme.c authsrv.c \
+ base64.c beacon.c chap.c common.c config_file.c ctrl_iface.c \
+ ctrl_iface_ap.c driver_common.c l2_packet_freebsd.c driver_bsd.c \
+ drivers.c drv_callbacks.c eap_common.c eap_peap_common.c \
+ eap_register.c eap_server.c eap_server_methods.c eap_user_db.c \
+ eapol_auth_dump.c eapol_auth_sm.c eloop.c gas.c gas_serv.c hostapd.c \
+ hs20.c http_client.c http_server.c httpread.c ieee802_11_auth.c \
+ ieee802_11_common.c ieee802_11_shared.c ieee802_1x.c ip_addr.c \
+ main.c md5.c ms_funcs.c os_unix.c peerkey_auth.c pmksa_cache_auth.c \
+ preauth_auth.c radius.c radius_client.c radius_das.c sta_info.c \
+ tkip_countermeasures.c upnp_xml.c utils.c uuid.c vlan_init.c \
+ wpa_auth.c wpa_auth_glue.c wpa_auth_ie.c wpa_common.c wpa_debug.c \
+ wpabuf.c wps.c wps_attr_build.c wps_attr_parse.c wps_attr_process.c \
+ wps_common.c wps_dev_attr.c wps_enrollee.c wps_hostapd.c \
+ wps_registrar.c wps_upnp.c wps_upnp_ap.c wps_upnp_event.c \
+ wps_upnp_ssdp.c wps_upnp_web.c
MAN= hostapd.8 hostapd.conf.5
@@ -68,7 +35,12 @@ CFLAGS+=-DCONFIG_DRIVER_BSD \
-DHOSTAPD \
-DCONFIG_DRIVER_RADIUS_ACL \
-DCONFIG_RSN_PREAUTH \
- -DCONFIG_PEERKEY
+ -DCONFIG_PEERKEY \
+ -DCONFIG_WPS \
+ -DCONFIG_WPS2 \
+ -DCONFIG_WPS_UPNP \
+ -DCONFIG_INTERWORKING \
+ -DCONFIG_HS20
.if ${MK_INET6} != "no"
CFLAGS+= -DCONFIG_IPV6
.endif
@@ -92,6 +64,7 @@ CFLAGS+=-DDPKCS12_FUNCS \
-DEAP_SERVER_TLS \
-DEAP_SERVER_TTLS \
-DEAP_TLS_FUNCS \
+ -DEAP_SERVER_WSC \
-DCONFIG_NO_DUMP_STATE
SRCS+= dump_state.c \
eap_server_gtc.c \
@@ -101,9 +74,14 @@ SRCS+= dump_state.c \
eap_server_peap.c \
eap_server_tls.c \
eap_server_tls_common.c \
- eap_server_ttls.c
+ eap_server_ttls.c \
+ eap_server_wsc.c \
+ eap_wsc_common.c
TLS_FUNCS=y
-NEED_SHA256=y
+
+.if !empty(CFLAGS:M*-DCONFIG_WPS)
+NEED_SIM_COMMON=y
+.endif
.if !empty(CFLAGS:M*-DEAP_SERVER_AKA)
SRCS+= eap_server_aka.c
diff --git a/usr.sbin/wpa/hostapd/driver_freebsd.c b/usr.sbin/wpa/hostapd/driver_freebsd.c
deleted file mode 100644
index 9b9d7d4..0000000
--- a/usr.sbin/wpa/hostapd/driver_freebsd.c
+++ /dev/null
@@ -1,787 +0,0 @@
-/*
- * Host AP - driver interaction with BSD net80211 layer
- * Copyright (c) 2004, Sam Leffler <sam@errno.com>
- * Copyright (c) 2004, 2Wire, Inc
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- *
- * $FreeBSD$
- */
-
-#include "includes.h"
-#include <sys/ioctl.h>
-
-#include "common.h"
-#include "driver.h"
-#include "eloop.h"
-#include "common/ieee802_11_defs.h"
-#include "common/wpa_common.h"
-
-#include <sys/socket.h>
-#include <net/if.h>
-#include <net/route.h>
-#include <netinet/in.h>
-
-#include <net80211/ieee80211_ioctl.h>
-#include <net80211/ieee80211_freebsd.h>
-
-#include "l2_packet/l2_packet.h"
-
-struct bsd_driver_data {
- struct hostapd_data *hapd; /* back pointer */
-
- int sock; /* open socket for 802.11 ioctls */
- struct l2_packet_data *sock_xmit;/* raw packet xmit socket */
- int route; /* routing socket for events */
- char ifname[IFNAMSIZ+1]; /* interface name */
- unsigned int ifindex; /* interface index */
- void *ctx;
- struct wpa_driver_capa capa; /* driver capability */
- int is_ap; /* Access point mode */
- int prev_roaming; /* roaming state to restore on deinit */
- int prev_privacy; /* privacy state to restore on deinit */
- int prev_wpa; /* wpa state to restore on deinit */
-};
-
-static int
-bsd_set80211(void *priv, int op, int val, const void *arg, int arg_len)
-{
- struct bsd_driver_data *drv = priv;
- struct ieee80211req ireq;
-
- os_memset(&ireq, 0, sizeof(ireq));
- os_strlcpy(ireq.i_name, drv->ifname, sizeof(ireq.i_name));
- ireq.i_type = op;
- ireq.i_val = val;
- ireq.i_data = (void *) arg;
- ireq.i_len = arg_len;
-
- if (ioctl(drv->sock, SIOCS80211, &ireq) < 0) {
- wpa_printf(MSG_ERROR, "ioctl[SIOCS80211, op=%u, val=%u, "
- "arg_len=%u]: %s", op, val, arg_len,
- strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static int
-bsd_get80211(void *priv, struct ieee80211req *ireq, int op, void *arg,
- int arg_len)
-{
- struct bsd_driver_data *drv = priv;
-
- os_memset(ireq, 0, sizeof(*ireq));
- os_strlcpy(ireq->i_name, drv->ifname, sizeof(ireq->i_name));
- ireq->i_type = op;
- ireq->i_len = arg_len;
- ireq->i_data = arg;
-
- if (ioctl(drv->sock, SIOCG80211, ireq) < 0) {
- wpa_printf(MSG_ERROR, "ioctl[SIOCS80211, op=%u, "
- "arg_len=%u]: %s", op, arg_len, strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static int
-get80211var(struct bsd_driver_data *drv, int op, void *arg, int arg_len)
-{
- struct ieee80211req ireq;
-
- if (bsd_get80211(drv, &ireq, op, arg, arg_len) < 0)
- return -1;
- return ireq.i_len;
-}
-
-static int
-set80211var(struct bsd_driver_data *drv, int op, const void *arg, int arg_len)
-{
- return bsd_set80211(drv, op, 0, arg, arg_len);
-}
-
-static int
-set80211param(struct bsd_driver_data *drv, int op, int arg)
-{
- return bsd_set80211(drv, op, arg, NULL, 0);
-}
-
-static int
-bsd_get_ssid(void *priv, u8 *ssid, int len)
-{
- struct bsd_driver_data *drv = priv;
-
- return get80211var(drv, IEEE80211_IOC_SSID, ssid, IEEE80211_NWID_LEN);
-}
-
-static int
-bsd_set_ssid(void *priv, const u8 *ssid, int ssid_len)
-{
- struct bsd_driver_data *drv = priv;
-
- return set80211var(drv, IEEE80211_IOC_SSID, ssid, ssid_len);
-}
-
-static int
-bsd_del_key(void *priv, const u8 *addr, int key_idx)
-{
- struct ieee80211req_del_key wk;
-
- os_memset(&wk, 0, sizeof(wk));
- if (addr == NULL) {
- wpa_printf(MSG_DEBUG, "%s: key_idx=%d", __func__, key_idx);
- wk.idk_keyix = key_idx;
- } else {
- wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__,
- MAC2STR(addr));
- os_memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
- wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE; /* XXX */
- }
-
- return set80211var(priv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk));
-}
-
-static int
-bsd_send_mlme_param(void *priv, const u8 op, const u16 reason, const u8 *addr)
-{
- struct ieee80211req_mlme mlme;
-
- os_memset(&mlme, 0, sizeof(mlme));
- mlme.im_op = op;
- mlme.im_reason = reason;
- os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
- return set80211var(priv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
-}
-
-static int
-bsd_ctrl_iface(void *priv, int enable)
-{
- struct bsd_driver_data *drv = priv;
- struct ifreq ifr;
-
- if (drv->sock < 0)
- return -1;
-
- os_memset(&ifr, 0, sizeof(ifr));
- os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name));
-
- if (ioctl(drv->sock, SIOCGIFFLAGS, &ifr) < 0) {
- perror("ioctl[SIOCGIFFLAGS]");
- return -1;
- }
-
- if (enable) {
- if ((ifr.ifr_flags & IFF_UP) == IFF_UP)
- return 0;
- ifr.ifr_flags |= IFF_UP;
- } else {
- if ((ifr.ifr_flags & IFF_UP) == 0)
- return 0;
- ifr.ifr_flags &= ~IFF_UP;
- }
-
- if (ioctl(drv->sock, SIOCSIFFLAGS, &ifr) < 0) {
- perror("ioctl[SIOCSIFFLAGS]");
- return -1;
- }
-
- return 0;
-}
-
-static int
-bsd_commit(void *priv)
-{
- return bsd_ctrl_iface(priv, 1);
-}
-
-static int
-bsd_set_key(const char *ifname, void *priv, enum wpa_alg alg,
- const unsigned char *addr, int key_idx, int set_tx, const u8 *seq,
- size_t seq_len, const u8 *key, size_t key_len)
-{
- struct ieee80211req_key wk;
-
- wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%p key_idx=%d set_tx=%d "
- "seq_len=%zu key_len=%zu", __func__, alg, addr, key_idx,
- set_tx, seq_len, key_len);
-
- if (alg == WPA_ALG_NONE) {
- return bsd_del_key(priv, addr, key_idx);
- }
-
- os_memset(&wk, 0, sizeof(wk));
- switch (alg) {
- case WPA_ALG_WEP:
- wk.ik_type = IEEE80211_CIPHER_WEP;
- break;
- case WPA_ALG_TKIP:
- wk.ik_type = IEEE80211_CIPHER_TKIP;
- break;
- case WPA_ALG_CCMP:
- wk.ik_type = IEEE80211_CIPHER_AES_CCM;
- break;
- default:
- wpa_printf(MSG_ERROR, "%s: unknown alg=%d", __func__, alg);
- return -1;
- }
-
- wk.ik_flags = IEEE80211_KEY_RECV;
- if (set_tx)
- wk.ik_flags |= IEEE80211_KEY_XMIT;
-
- if (addr == NULL) {
- os_memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
- wk.ik_keyix = key_idx;
- } else {
- os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
- /*
- * Deduce whether group/global or unicast key by checking
- * the address (yech). Note also that we can only mark global
- * keys default; doing this for a unicast key is an error.
- */
- if (os_memcmp(addr, "\xff\xff\xff\xff\xff\xff",
- IEEE80211_ADDR_LEN) == 0) {
- wk.ik_flags |= IEEE80211_KEY_GROUP;
- wk.ik_keyix = key_idx;
- } else {
- wk.ik_keyix = key_idx == 0 ? IEEE80211_KEYIX_NONE :
- key_idx;
- }
- }
- if (wk.ik_keyix != IEEE80211_KEYIX_NONE && set_tx)
- wk.ik_flags |= IEEE80211_KEY_DEFAULT;
- wk.ik_keylen = key_len;
- os_memcpy(&wk.ik_keyrsc, seq, seq_len);
- os_memcpy(wk.ik_keydata, key, key_len);
-
- return set80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk));
-}
-
-static int
-bsd_configure_wpa(void *priv, struct wpa_bss_params *params)
-{
- wpa_printf(MSG_DEBUG, "%s: enable WPA= 0x%x", __func__, params->wpa);
- if (set80211param(priv, IEEE80211_IOC_WPA, params->wpa)) {
- printf("Unable to set WPA to %u\n", params->wpa);
- return -1;
- }
- return 0;
-}
-
-static int
-bsd_set_ieee8021x(void *priv, struct wpa_bss_params *params)
-{
- wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, params->enabled);
-
- if (!params->enabled) {
- /* XXX restore state */
- return set80211param(priv, IEEE80211_IOC_AUTHMODE,
- IEEE80211_AUTH_AUTO);
- }
- if (!params->wpa && !params->ieee802_1x) {
- wpa_printf(MSG_ERROR, "%s: No 802.1X or WPA enabled",
- __func__);
- return -1;
- }
- if (params->wpa && bsd_configure_wpa(priv, params) != 0) {
- wpa_printf(MSG_ERROR, "%s: Failed to configure WPA state",
- __func__);
- return -1;
- }
- if (set80211param(priv, IEEE80211_IOC_AUTHMODE,
- (params->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
- wpa_printf(MSG_ERROR, "%s: Failed to enable WPA/802.1X",
- __func__);
- return -1;
- }
- return 0;
-}
-
-static int
-bsd_set_sta_authorized(void *priv, const u8 *addr,
- int total_flags, int flags_or, int flags_and)
-{
- int authorized = -1;
-
- /* For now, only support setting Authorized flag */
- if (flags_or & WPA_STA_AUTHORIZED)
- authorized = 1;
- if (!(flags_and & WPA_STA_AUTHORIZED))
- authorized = 0;
-
- if (authorized < 0)
- return 0;
-
- return bsd_send_mlme_param(priv, authorized ?
- IEEE80211_MLME_AUTHORIZE :
- IEEE80211_MLME_UNAUTHORIZE, 0, addr);
-}
-
-static void
-bsd_new_sta(void *priv, void *ctx, u8 addr[IEEE80211_ADDR_LEN])
-{
- struct ieee80211req_wpaie ie;
- int ielen = 0;
- u8 *iebuf = NULL;
-
- /*
- * Fetch and validate any negotiated WPA/RSN parameters.
- */
- memset(&ie, 0, sizeof(ie));
- memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
- if (get80211var(priv, IEEE80211_IOC_WPAIE, &ie, sizeof(ie)) < 0) {
- printf("Failed to get WPA/RSN information element.\n");
- goto no_ie;
- }
- iebuf = ie.wpa_ie;
- ielen = ie.wpa_ie[1];
- if (ielen == 0)
- iebuf = NULL;
- else
- ielen += 2;
-
-no_ie:
- drv_event_assoc(ctx, addr, iebuf, ielen);
-}
-
-static int
-bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
- int encrypt, const u8 *own_addr)
-{
- struct bsd_driver_data *drv = priv;
-
- wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", data, data_len);
-
- return l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, data,
- data_len);
-}
-
-static int
-bsd_set_opt_ie(void *priv, const u8 *ie, size_t ie_len)
-{
- wpa_printf(MSG_DEBUG, "%s: set WPA+RSN ie (len %lu)", __func__,
- (unsigned long)ie_len);
- return bsd_set80211(priv, IEEE80211_IOC_APPIE, IEEE80211_APPIE_WPA,
- ie, ie_len);
-}
-
-/*
- * Avoid conflicts with hostapd definitions by undefining couple of defines
- * from net80211 header files.
- */
-#undef RSN_VERSION
-#undef WPA_VERSION
-#undef WPA_OUI_TYPE
-
-static int bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
- int reason_code);
-
-static const char *
-ether_sprintf(const u8 *addr)
-{
- static char buf[sizeof(MACSTR)];
-
- if (addr != NULL)
- snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
- else
- snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
- return buf;
-}
-
-static int
-bsd_set_privacy(void *priv, int enabled)
-{
- wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
-
- return set80211param(priv, IEEE80211_IOC_PRIVACY, enabled);
-}
-
-static int
-bsd_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
- u8 *seq)
-{
- struct ieee80211req_key wk;
-
- wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d",
- __func__, ether_sprintf(addr), idx);
-
- memset(&wk, 0, sizeof(wk));
- if (addr == NULL)
- memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
- else
- memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
- wk.ik_keyix = idx;
-
- if (get80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)) < 0) {
- printf("Failed to get encryption.\n");
- return -1;
- }
-
-#ifdef WORDS_BIGENDIAN
- {
- /*
- * wk.ik_keytsc is in host byte order (big endian), need to
- * swap it to match with the byte order used in WPA.
- */
- int i;
- u8 tmp[WPA_KEY_RSC_LEN];
- memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
- for (i = 0; i < WPA_KEY_RSC_LEN; i++) {
- seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1];
- }
- }
-#else /* WORDS_BIGENDIAN */
- memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
-#endif /* WORDS_BIGENDIAN */
- return 0;
-}
-
-
-static int
-bsd_flush(void *priv)
-{
- u8 allsta[IEEE80211_ADDR_LEN];
-
- memset(allsta, 0xff, IEEE80211_ADDR_LEN);
- return bsd_sta_deauth(priv, NULL, allsta, IEEE80211_REASON_AUTH_LEAVE);
-}
-
-
-static int
-bsd_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
- const u8 *addr)
-{
- struct ieee80211req_sta_stats stats;
-
- memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
- if (get80211var(priv, IEEE80211_IOC_STA_STATS, &stats, sizeof(stats))
- > 0) {
- /* XXX? do packets counts include non-data frames? */
- data->rx_packets = stats.is_stats.ns_rx_data;
- data->rx_bytes = stats.is_stats.ns_rx_bytes;
- data->tx_packets = stats.is_stats.ns_tx_data;
- data->tx_bytes = stats.is_stats.ns_tx_bytes;
- }
- return 0;
-}
-
-static int
-bsd_sta_clear_stats(void *priv, const u8 *addr)
-{
- struct ieee80211req_sta_stats stats;
-
- wpa_printf(MSG_DEBUG, "%s: addr=%s", __func__, ether_sprintf(addr));
-
- /* zero station statistics */
- memset(&stats, 0, sizeof(stats));
- memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
- return set80211var(priv, IEEE80211_IOC_STA_STATS, &stats,
- sizeof(stats));
-}
-
-static int
-bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, int reason_code)
-{
- return bsd_send_mlme_param(priv, IEEE80211_MLME_DEAUTH, reason_code,
- addr);
-}
-
-static int
-bsd_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
- int reason_code)
-{
- return bsd_send_mlme_param(priv, IEEE80211_MLME_DISASSOC, reason_code,
- addr);
-}
-
-static void
-bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx)
-{
- struct bsd_driver_data *drv = ctx;
- char buf[2048];
- struct if_announcemsghdr *ifan;
- struct rt_msghdr *rtm;
- struct ieee80211_michael_event *mic;
- struct ieee80211_join_event *join;
- struct ieee80211_leave_event *leave;
-#ifdef CONFIG_DRIVER_RADIUS_ACL
- struct ieee80211_auth_event *auth;
-#endif
- int n;
- union wpa_event_data data;
-
- n = read(sock, buf, sizeof(buf));
- if (n < 0) {
- if (errno != EINTR && errno != EAGAIN)
- perror("read(PF_ROUTE)");
- return;
- }
-
- rtm = (struct rt_msghdr *) buf;
- if (rtm->rtm_version != RTM_VERSION) {
- wpa_printf(MSG_DEBUG, "Routing message version %d not "
- "understood\n", rtm->rtm_version);
- return;
- }
- ifan = (struct if_announcemsghdr *) rtm;
- if (ifan->ifan_index != drv->ifindex) {
- wpa_printf(MSG_DEBUG, "Discard routing message to if#%d "
- "(not for us %d)\n",
- ifan->ifan_index, drv->ifindex);
- return;
- }
- switch (rtm->rtm_type) {
- case RTM_IEEE80211:
- switch (ifan->ifan_what) {
- case RTM_IEEE80211_ASSOC:
- case RTM_IEEE80211_REASSOC:
- case RTM_IEEE80211_DISASSOC:
- case RTM_IEEE80211_SCAN:
- break;
- case RTM_IEEE80211_LEAVE:
- leave = (struct ieee80211_leave_event *) &ifan[1];
- drv_event_disassoc(drv->hapd, leave->iev_addr);
- break;
- case RTM_IEEE80211_JOIN:
-#ifdef RTM_IEEE80211_REJOIN
- case RTM_IEEE80211_REJOIN:
-#endif
- join = (struct ieee80211_join_event *) &ifan[1];
- bsd_new_sta(drv, drv->hapd, join->iev_addr);
- break;
- case RTM_IEEE80211_REPLAY:
- /* ignore */
- break;
- case RTM_IEEE80211_MICHAEL:
- mic = (struct ieee80211_michael_event *) &ifan[1];
- wpa_printf(MSG_DEBUG,
- "Michael MIC failure wireless event: "
- "keyix=%u src_addr=" MACSTR, mic->iev_keyix,
- MAC2STR(mic->iev_src));
- os_memset(&data, 0, sizeof(data));
- data.michael_mic_failure.unicast = 1;
- data.michael_mic_failure.src = mic->iev_src;
- wpa_supplicant_event(drv->hapd,
- EVENT_MICHAEL_MIC_FAILURE, &data);
- break;
-#ifdef CONFIG_DRIVER_RADIUS_ACL_NOT_YET
- case RTM_IEEE80211_AUTH:
- auth = (struct ieee80211_auth_event *) &ifan[1];
- wpa_printf(MSG_DEBUG, "802.11 AUTH, STA = " MACSTR,
- MAC2STR(auth->iev_addr));
- n = hostapd_allowed_address(drv->hapd, auth->iev_addr,
- NULL, 0, NULL, NULL, NULL);
- switch (n) {
- case HOSTAPD_ACL_ACCEPT:
- case HOSTAPD_ACL_REJECT:
- hostapd_set_radius_acl_auth(drv->hapd,
- auth->iev_addr, n, 0);
- wpa_printf(MSG_DEBUG,
- "802.11 AUTH, STA = " MACSTR " hostapd says: %s",
- MAC2STR(auth->iev_addr),
- (n == HOSTAPD_ACL_ACCEPT ?
- "ACCEPT" : "REJECT" ));
- break;
- case HOSTAPD_ACL_PENDING:
- wpa_printf(MSG_DEBUG,
- "802.11 AUTH, STA = " MACSTR " pending",
- MAC2STR(auth->iev_addr));
- break;
- }
- break;
-#endif /* CONFIG_DRIVER_RADIUS_ACL */
- }
- break;
- }
-}
-
-static void
-handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
-{
- struct bsd_driver_data *drv = ctx;
- drv_event_eapol_rx(drv->hapd, src_addr, buf, len);
-}
-
-static int
-bsd_set_countermeasures(void *priv, int enabled)
-{
- wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
- return set80211param(priv, IEEE80211_IOC_COUNTERMEASURES, enabled);
-}
-
-#ifdef CONFIG_DRIVER_RADIUS_ACL_NOT_YET
-static int
-bsd_set_radius_acl_auth(void *priv, const u8 *mac, int accepted,
- u32 session_timeout)
-{
- struct bsd_driver_data *drv = priv;
- struct hostapd_data *hapd = drv->hapd;
- struct ieee80211req_mlme mlme;
-
- switch (accepted) {
- case HOSTAPD_ACL_ACCEPT_TIMEOUT:
- wpa_printf(MSG_DEBUG, "[%s] STA " MACSTR
- " has been accepted by RADIUS ACL with timeout "
- "of %d.\n", hapd->conf->iface, MAC2STR(mac),
- session_timeout);
- mlme.im_reason = IEEE80211_STATUS_SUCCESS;
- break;
- case HOSTAPD_ACL_ACCEPT:
- wpa_printf(MSG_DEBUG, "[%s] STA " MACSTR
- " has been accepted by RADIUS ACL.\n",
- hapd->conf->iface, MAC2STR(mac));
- mlme.im_reason = IEEE80211_STATUS_SUCCESS;
- break;
- case HOSTAPD_ACL_REJECT:
- wpa_printf(MSG_DEBUG, "[%s] STA " MACSTR
- " has been rejected by RADIUS ACL.\n",
- hapd->conf->iface, MAC2STR(mac));
- mlme.im_reason = IEEE80211_STATUS_UNSPECIFIED;
- break;
- default:
- wpa_printf(MSG_ERROR, "[%s] STA " MACSTR
- " has unknown status (%d) by RADIUS ACL. "
- "Nothing to do...\n", hapd->conf->iface,
- MAC2STR(mac), accepted);
- return 0;
- }
- memset(&mlme, 0, sizeof(mlme));
- mlme.im_op = IEEE80211_MLME_AUTH;
- memcpy(mlme.im_macaddr, mac, IEEE80211_ADDR_LEN);
- return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
-}
-
-static int
-bsd_set_radius_acl_expire(void *priv, const u8 *mac)
-{
- struct bsd_driver_data *drv = priv;
- struct hostapd_data *hapd = drv->hapd;
-
- /*
- * The expiry of the MAC address from RADIUS ACL cache doesn't mean
- * that we should kick off the client. Our current approach doesn't
- * require adding/removing entries from an allow/deny list; so this
- * function is likely unnecessary
- */
- wpa_printf(MSG_DEBUG, "[%s] STA " MACSTR " radius acl cache "
- "expired; nothing to do...", hapd->conf->iface,
- MAC2STR(mac));
- return 0;
-}
-#endif /* CONFIG_DRIVER_RADIUS_ACL */
-
-static void *
-bsd_init(struct hostapd_data *hapd, struct wpa_init_params *params)
-{
- struct bsd_driver_data *drv;
-
- drv = os_zalloc(sizeof(struct bsd_driver_data));
- if (drv == NULL) {
- printf("Could not allocate memory for bsd driver data\n");
- goto bad;
- }
-
- drv->hapd = hapd;
- drv->sock = socket(PF_INET, SOCK_DGRAM, 0);
- if (drv->sock < 0) {
- perror("socket[PF_INET,SOCK_DGRAM]");
- goto bad;
- }
- os_strlcpy(drv->ifname, params->ifname, sizeof(drv->ifname));
- /*
- * NB: We require the interface name be mappable to an index.
- * This implies we do not support having wpa_supplicant
- * wait for an interface to appear. This seems ok; that
- * doesn't belong here; it's really the job of devd.
- * XXXSCW: devd is FreeBSD-specific.
- */
- drv->ifindex = if_nametoindex(drv->ifname);
- if (drv->ifindex == 0) {
- printf("%s: interface %s does not exist", __func__,
- drv->ifname);
- goto bad;
- }
-
- drv->sock_xmit = l2_packet_init(drv->ifname, NULL, ETH_P_EAPOL,
- handle_read, drv, 0);
- if (drv->sock_xmit == NULL)
- goto bad;
- if (l2_packet_get_own_addr(drv->sock_xmit, params->own_addr))
- goto bad;
-
- /* mark down during setup */
- if (bsd_ctrl_iface(drv, 0) < 0)
- goto bad;
-
- drv->route = socket(PF_ROUTE, SOCK_RAW, 0);
- if (drv->route < 0) {
- perror("socket(PF_ROUTE,SOCK_RAW)");
- goto bad;
- }
- eloop_register_read_sock(drv->route, bsd_wireless_event_receive, drv,
- NULL);
-
- return drv;
-bad:
- if (drv == NULL)
- return NULL;
- if (drv->sock_xmit != NULL)
- l2_packet_deinit(drv->sock_xmit);
- if (drv->sock >= 0)
- close(drv->sock);
- os_free(drv);
- return NULL;
-}
-
-
-static void
-bsd_deinit(void *priv)
-{
- struct bsd_driver_data *drv = priv;
-
- if (drv->route >= 0) {
- eloop_unregister_read_sock(drv->route);
- close(drv->route);
- }
- bsd_ctrl_iface(drv, 0);
- if (drv->sock >= 0)
- close(drv->sock);
- if (drv->sock_xmit != NULL)
- l2_packet_deinit(drv->sock_xmit);
- os_free(drv);
-}
-
-const struct wpa_driver_ops wpa_driver_bsd_ops = {
- .name = "bsd",
- .desc = "BSD 802.11 support",
- .hapd_init = bsd_init,
- .hapd_deinit = bsd_deinit,
- .set_privacy = bsd_set_privacy,
- .get_seqnum = bsd_get_seqnum,
- .flush = bsd_flush,
- .read_sta_data = bsd_read_sta_driver_data,
- .sta_clear_stats = bsd_sta_clear_stats,
- .sta_disassoc = bsd_sta_disassoc,
- .sta_deauth = bsd_sta_deauth,
- .set_key = bsd_set_key,
- .set_ieee8021x = bsd_set_ieee8021x,
- .hapd_set_ssid = bsd_set_ssid,
- .hapd_get_ssid = bsd_get_ssid,
- .hapd_send_eapol = bsd_send_eapol,
- .sta_set_flags = bsd_set_sta_authorized,
- .set_generic_elem = bsd_set_opt_ie,
- .set_countermeasures = bsd_set_countermeasures,
- .commit = bsd_commit,
-#ifdef CONFIG_DRIVER_RADIUS_ACL_NOT_YET
- .set_radius_acl_auth = bsd_set_radius_acl_auth,
- .set_radius_acl_expire = bsd_set_radius_acl_expire,
-#endif
-};
diff --git a/usr.sbin/wpa/hostapd_cli/Makefile b/usr.sbin/wpa/hostapd_cli/Makefile
index 667134c..8677fbf 100644
--- a/usr.sbin/wpa/hostapd_cli/Makefile
+++ b/usr.sbin/wpa/hostapd_cli/Makefile
@@ -5,7 +5,7 @@
.PATH.c:${HOSTAPD_DISTDIR}
PROG= hostapd_cli
-SRCS= hostapd_cli.c wpa_ctrl.c os_unix.c
+SRCS= common.c edit.c eloop.c hostapd_cli.c os_unix.c wpa_ctrl.c wpa_debug.c
CFLAGS+= -DCONFIG_CTRL_IFACE
CFLAGS+= -DCONFIG_CTRL_IFACE_UNIX
diff --git a/usr.sbin/wpa/wpa_cli/Makefile b/usr.sbin/wpa/wpa_cli/Makefile
index 1721437..da25325 100644
--- a/usr.sbin/wpa/wpa_cli/Makefile
+++ b/usr.sbin/wpa/wpa_cli/Makefile
@@ -5,7 +5,7 @@
.PATH.c:${WPA_SUPPLICANT_DISTDIR}
PROG= wpa_cli
-SRCS= wpa_cli.c wpa_ctrl.c os_unix.c
+SRCS= common.c edit.c eloop.c os_unix.c wpa_cli.c wpa_ctrl.c wpa_debug.c
MAN= wpa_cli.8
diff --git a/usr.sbin/wpa/wpa_passphrase/Makefile b/usr.sbin/wpa/wpa_passphrase/Makefile
index 385e23c..16321c4 100644
--- a/usr.sbin/wpa/wpa_passphrase/Makefile
+++ b/usr.sbin/wpa/wpa_passphrase/Makefile
@@ -5,8 +5,8 @@
.PATH.c:${WPA_SUPPLICANT_DISTDIR}
PROG= wpa_passphrase
-SRCS= wpa_passphrase.c sha1.c sha1-internal.c sha1-pbkdf2.c \
- md5.c md5-internal.c
+SRCS= common.c md5-internal.c md5.c os_unix.c sha1-internal.c sha1-pbkdf2.c sha1.c \
+ wpa_passphrase.c
CFLAGS+= -DINTERNAL_SHA1
CFLAGS+= -DINTERNAL_MD5
diff --git a/usr.sbin/wpa/wpa_priv/Makefile b/usr.sbin/wpa/wpa_priv/Makefile
new file mode 100644
index 0000000..4dbc631
--- /dev/null
+++ b/usr.sbin/wpa/wpa_priv/Makefile
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+.include "${.CURDIR}/../Makefile.inc"
+
+.PATH.c:${WPA_SUPPLICANT_DISTDIR} \
+ ${WPA_DISTDIR}/src/drivers
+
+PROG= wpa_priv
+SRCS= drivers.c os_unix.c eloop.c common.c wpa_debug.c wpabuf.c wpa_priv.c \
+ driver_common.c l2_packet_freebsd.c
+
+DPADD+= ${LIBPCAP}
+LDADD+= -lpcap
+
+.include "${.CURDIR}/../Makefile.crypto"
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/wpa/wpa_supplicant/Makefile b/usr.sbin/wpa/wpa_supplicant/Makefile
index 6c352ab..3424413 100644
--- a/usr.sbin/wpa/wpa_supplicant/Makefile
+++ b/usr.sbin/wpa/wpa_supplicant/Makefile
@@ -6,41 +6,19 @@
${WPA_DISTDIR}/src/drivers
PROG= wpa_supplicant
-SRCS= aes-unwrap.c \
- base64.c \
- blacklist.c \
- bss.c \
- common.c \
- config.c \
- config_file.c \
- ctrl_iface.c \
- ctrl_iface_unix.c \
- driver_ndis.c \
- driver_wired.c \
- drivers.c \
- eap_register.c \
- eloop.c \
- events.c \
- main.c \
- md5.c \
- notify.c \
- os_unix.c \
- peerkey.c \
- pmksa_cache.c \
- preauth.c \
- scan.c \
- sha1-pbkdf2.c \
- sha1.c \
- wpa.c \
- wpa_common.c \
- wpa_debug.c \
- wpa_ie.c \
- wpa_supplicant.c \
- wpabuf.c \
- wpas_glue.c
-SRCS+= driver_freebsd.c \
- l2_packet_freebsd.c \
- Packet32.c
+SRCS= aes-unwrap.c base64.c blacklist.c bss.c common.c config.c \
+ config_file.c ctrl_iface.c ctrl_iface_unix.c driver_bsd.c \
+ driver_common.c driver_ndis.c driver_wired.c drivers.c \
+ eap_register.c eloop.c events.c gas.c gas_query.c hs20.c \
+ hs20_supplicant.c http_client.c http_server.c httpread.c \
+ ieee802_11_common.c interworking.c l2_packet_freebsd.c main.c \
+ md5.c notify.c offchannel.c os_unix.c peerkey.c pmksa_cache.c \
+ preauth.c scan.c upnp_xml.c uuid.c wpa.c wpa_common.c wpa_debug.c \
+ wpa_ft.c wpa_ie.c wpa_supplicant.c wpabuf.c wpas_glue.c wps.c \
+ wps_attr_build.c wps_attr_parse.c wps_attr_process.c \
+ wps_common.c wps_dev_attr.c wps_enrollee.c wps_registrar.c \
+ wps_supplicant.c wps_upnp.c wps_upnp_ap.c wps_upnp_event.c \
+ wps_upnp_ssdp.c wps_upnp_web.c Packet32.c
MAN= wpa_supplicant.8 wpa_supplicant.conf.5
@@ -58,6 +36,15 @@ CFLAGS+=-DCONFIG_BACKEND_FILE \
-DCONFIG_PEERKEY \
-DCONFIG_SMARTCARD \
-DCONFIG_TERMINATE_ONLASTIF \
+ -DCONFIG_WPS \
+ -DCONFIG_WPS2 \
+ -DCONFIG_WPS_UPNP \
+ -DCONFIG_TLS=openssl \
+ -DCONFIG_IEEE80211R \
+ -DCONFIG_INTERWORKING \
+ -DCONFIG_PRIVSEP \
+ -DCONFIG_HS20 \
+ -DCONFIG_GAS \
-DPKCS12_FUNCS
#CFLAGS+= -g
DPADD+= ${LIBPCAP}
@@ -79,6 +66,9 @@ CFLAGS+=-DEAP_GTC \
-DEAP_PSK \
-DEAP_TLS \
-DEAP_TTLS \
+ -DEAP_GTC \
+ -DEAP_OTP \
+ -DEAP_LEAP \
-DIEEE8021X_EAPOL
SRCS+= chap.c \
eap.c \
@@ -103,7 +93,10 @@ TLS_FUNCS=y
NEED_AES_EAX=y
NEED_AES_ENCBLOCK=y
NEED_AES_OMAC1=y
-NEED_SHA256=y
+.endif
+
+.if !empty(CFLAGS:M-DCONFIG_WPS)
+NEED_AES_CBC=y
.endif
.if !empty(CFLAGS:M*-DEAP_AKA)
diff --git a/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c b/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c
deleted file mode 100644
index 0ac3c50..0000000
--- a/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c
+++ /dev/null
@@ -1,929 +0,0 @@
-/*
- * WPA Supplicant - driver interaction with BSD net80211 layer
- * Copyright (c) 2004, Sam Leffler <sam@errno.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- *
- * $FreeBSD$
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-
-#include "common.h"
-#include "driver.h"
-#include "eloop.h"
-#include "l2_packet.h"
-#include "ieee802_11_defs.h"
-
-#include <sys/socket.h>
-#include <net/if.h>
-#include <net/if_media.h>
-#include <net/ethernet.h>
-
-#include <net80211/ieee80211_ioctl.h>
-
-struct wpa_driver_bsd_data {
- int sock; /* open socket for 802.11 ioctls */
- int route; /* routing socket for events */
- char ifname[IFNAMSIZ+1]; /* interface name */
- unsigned int ifindex; /* interface index */
- void *ctx;
- int prev_roaming; /* roaming state to restore on deinit */
- int prev_privacy; /* privacy state to restore on deinit */
- int prev_wpa; /* wpa state to restore on deinit */
- int prev_scanvalid; /* scan valid to restore on deinit */
- uint8_t lastssid[IEEE80211_NWID_LEN];
- int lastssid_len;
- uint32_t drivercaps; /* general driver capabilities */
- uint32_t cryptocaps; /* hardware crypto support */
- enum ieee80211_opmode opmode; /* operation mode */
-};
-
-static enum ieee80211_opmode
-get80211opmode(struct wpa_driver_bsd_data *drv)
-{
- struct ifmediareq ifmr;
-
- (void) memset(&ifmr, 0, sizeof(ifmr));
- (void) strncpy(ifmr.ifm_name, drv->ifname, sizeof(ifmr.ifm_name));
-
- if (ioctl(drv->sock, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) {
- if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) {
- if (ifmr.ifm_current & IFM_FLAG0)
- return IEEE80211_M_AHDEMO;
- else
- return IEEE80211_M_IBSS;
- }
- if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP)
- return IEEE80211_M_HOSTAP;
- if (ifmr.ifm_current & IFM_IEEE80211_MONITOR)
- return IEEE80211_M_MONITOR;
- if (ifmr.ifm_current & IFM_IEEE80211_MBSS)
- return IEEE80211_M_MBSS;
- }
- return IEEE80211_M_STA;
-}
-
-static int
-set80211var(struct wpa_driver_bsd_data *drv, int op, const void *arg, int arg_len)
-{
- struct ieee80211req ireq;
-
- memset(&ireq, 0, sizeof(ireq));
- strncpy(ireq.i_name, drv->ifname, IFNAMSIZ);
- ireq.i_type = op;
- ireq.i_len = arg_len;
- ireq.i_data = (void *) arg;
-
- if (ioctl(drv->sock, SIOCS80211, &ireq) < 0) {
- fprintf(stderr, "ioctl[SIOCS80211, op %u, len %u]: %s\n",
- op, arg_len, strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static int
-get80211var(struct wpa_driver_bsd_data *drv, int op, void *arg, int arg_len)
-{
- struct ieee80211req ireq;
-
- memset(&ireq, 0, sizeof(ireq));
- strncpy(ireq.i_name, drv->ifname, IFNAMSIZ);
- ireq.i_type = op;
- ireq.i_len = arg_len;
- ireq.i_data = arg;
-
- if (ioctl(drv->sock, SIOCG80211, &ireq) < 0) {
- fprintf(stderr, "ioctl[SIOCG80211, op %u, len %u]: %s\n",
- op, arg_len, strerror(errno));
- return -1;
- }
- return ireq.i_len;
-}
-
-static int
-set80211param(struct wpa_driver_bsd_data *drv, int op, int arg)
-{
- struct ieee80211req ireq;
-
- memset(&ireq, 0, sizeof(ireq));
- strncpy(ireq.i_name, drv->ifname, IFNAMSIZ);
- ireq.i_type = op;
- ireq.i_val = arg;
-
- if (ioctl(drv->sock, SIOCS80211, &ireq) < 0) {
- fprintf(stderr, "ioctl[SIOCS80211, op %u, arg 0x%x]: %s\n",
- op, arg, strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static int
-get80211param(struct wpa_driver_bsd_data *drv, int op)
-{
- struct ieee80211req ireq;
-
- memset(&ireq, 0, sizeof(ireq));
- strncpy(ireq.i_name, drv->ifname, IFNAMSIZ);
- ireq.i_type = op;
-
- if (ioctl(drv->sock, SIOCG80211, &ireq) < 0) {
- fprintf(stderr, "ioctl[SIOCG80211, op %u]: %s\n",
- op, strerror(errno));
- return -1;
- }
- return ireq.i_val;
-}
-
-static int
-getifflags(struct wpa_driver_bsd_data *drv, int *flags)
-{
- struct ifreq ifr;
-
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, drv->ifname, sizeof (ifr.ifr_name));
- if (ioctl(drv->sock, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
- perror("SIOCGIFFLAGS");
- return errno;
- }
- *flags = (ifr.ifr_flags & 0xffff) | (ifr.ifr_flagshigh << 16);
- return 0;
-}
-
-static int
-setifflags(struct wpa_driver_bsd_data *drv, int flags)
-{
- struct ifreq ifr;
-
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, drv->ifname, sizeof (ifr.ifr_name));
- ifr.ifr_flags = flags & 0xffff;
- ifr.ifr_flagshigh = flags >> 16;
- if (ioctl(drv->sock, SIOCSIFFLAGS, (caddr_t)&ifr) < 0) {
- perror("SIOCSIFFLAGS");
- return errno;
- }
- return 0;
-}
-
-static int
-wpa_driver_bsd_get_bssid(void *priv, u8 *bssid)
-{
- struct wpa_driver_bsd_data *drv = priv;
-
- return get80211var(drv, IEEE80211_IOC_BSSID,
- bssid, IEEE80211_ADDR_LEN) < 0 ? -1 : 0;
-}
-
-#if 0
-static int
-wpa_driver_bsd_set_bssid(void *priv, const char *bssid)
-{
- struct wpa_driver_bsd_data *drv = priv;
-
- return set80211var(drv, IEEE80211_IOC_BSSID,
- bssid, IEEE80211_ADDR_LEN);
-}
-#endif
-
-static int
-wpa_driver_bsd_get_ssid(void *priv, u8 *ssid)
-{
- struct wpa_driver_bsd_data *drv = priv;
-
- return get80211var(drv, IEEE80211_IOC_SSID,
- ssid, IEEE80211_NWID_LEN);
-}
-
-static int
-wpa_driver_bsd_set_ssid(void *priv, const char *ssid,
- size_t ssid_len)
-{
- struct wpa_driver_bsd_data *drv = priv;
-
- return set80211var(drv, IEEE80211_IOC_SSID, ssid, ssid_len);
-}
-
-static int
-wpa_driver_bsd_set_wpa_ie(struct wpa_driver_bsd_data *drv,
- const u8 *wpa_ie, size_t wpa_ie_len)
-{
- struct ieee80211req ireq;
-
- memset(&ireq, 0, sizeof(ireq));
- strncpy(ireq.i_name, drv->ifname, IFNAMSIZ);
- ireq.i_type = IEEE80211_IOC_APPIE;
- ireq.i_val = IEEE80211_APPIE_WPA;
- ireq.i_len = wpa_ie_len;
- ireq.i_data = (void *) wpa_ie;
- if (ioctl(drv->sock, SIOCS80211, &ireq) < 0) {
- fprintf(stderr,
- "ioctl[IEEE80211_IOC_APPIE:IEEE80211_APPIE_WPA]: %s\n",
- strerror(errno));
- return -1;
- }
- return 0;
-}
-
-static int
-wpa_driver_bsd_set_wpa_internal(void *priv, int wpa, int privacy)
-{
- struct wpa_driver_bsd_data *drv = priv;
- int ret = 0;
-
- wpa_printf(MSG_DEBUG, "%s: wpa=%d privacy=%d",
- __FUNCTION__, wpa, privacy);
-
- if (!wpa && wpa_driver_bsd_set_wpa_ie(drv, NULL, 0) < 0)
- ret = -1;
- if (set80211param(drv, IEEE80211_IOC_PRIVACY, privacy) < 0)
- ret = -1;
- if (set80211param(drv, IEEE80211_IOC_WPA, wpa) < 0)
- ret = -1;
-
- return ret;
-}
-
-static int
-wpa_driver_bsd_del_key(struct wpa_driver_bsd_data *drv, int key_idx,
- const unsigned char *addr)
-{
- struct ieee80211req_del_key wk;
-
- memset(&wk, 0, sizeof(wk));
- if (addr != NULL &&
- bcmp(addr, "\xff\xff\xff\xff\xff\xff", IEEE80211_ADDR_LEN) != 0) {
- struct ether_addr ea;
-
- memcpy(&ea, addr, IEEE80211_ADDR_LEN);
- wpa_printf(MSG_DEBUG, "%s: addr=%s keyidx=%d",
- __func__, ether_ntoa(&ea), key_idx);
- memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
- wk.idk_keyix = (uint8_t) IEEE80211_KEYIX_NONE;
- } else {
- wpa_printf(MSG_DEBUG, "%s: keyidx=%d", __func__, key_idx);
- wk.idk_keyix = key_idx;
- }
- return set80211var(drv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk));
-}
-
-static int
-wpa_driver_bsd_set_key(const char *ifname, void *priv, enum wpa_alg alg,
- const unsigned char *addr, int key_idx, int set_tx,
- const u8 *seq, size_t seq_len,
- const u8 *key, size_t key_len)
-{
- struct wpa_driver_bsd_data *drv = priv;
- struct ieee80211req_key wk;
- struct ether_addr ea;
- char *alg_name;
- u_int8_t cipher;
-
- if (alg == WPA_ALG_NONE)
- return wpa_driver_bsd_del_key(drv, key_idx, addr);
-
- switch (alg) {
- case WPA_ALG_WEP:
- alg_name = "WEP";
- cipher = IEEE80211_CIPHER_WEP;
- break;
- case WPA_ALG_TKIP:
- alg_name = "TKIP";
- cipher = IEEE80211_CIPHER_TKIP;
- break;
- case WPA_ALG_CCMP:
- alg_name = "CCMP";
- cipher = IEEE80211_CIPHER_AES_CCM;
- break;
- default:
- wpa_printf(MSG_DEBUG, "%s: unknown/unsupported algorithm %d",
- __func__, alg);
- return -1;
- }
-
- memcpy(&ea, addr, IEEE80211_ADDR_LEN);
- wpa_printf(MSG_DEBUG,
- "%s: alg=%s addr=%s key_idx=%d set_tx=%d seq_len=%zu key_len=%zu",
- __func__, alg_name, ether_ntoa(&ea), key_idx, set_tx,
- seq_len, key_len);
-
- if (seq_len > sizeof(u_int64_t)) {
- wpa_printf(MSG_DEBUG, "%s: seq_len %zu too big",
- __func__, seq_len);
- return -2;
- }
- if (key_len > sizeof(wk.ik_keydata)) {
- wpa_printf(MSG_DEBUG, "%s: key length %zu too big",
- __func__, key_len);
- return -3;
- }
-
- memset(&wk, 0, sizeof(wk));
- wk.ik_type = cipher;
- wk.ik_flags = IEEE80211_KEY_RECV;
- if (set_tx)
- wk.ik_flags |= IEEE80211_KEY_XMIT;
- memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
- /*
- * Deduce whether group/global or unicast key by checking
- * the address (yech). Note also that we can only mark global
- * keys default; doing this for a unicast key is an error.
- */
- if (bcmp(addr, "\xff\xff\xff\xff\xff\xff", IEEE80211_ADDR_LEN) == 0) {
- wk.ik_flags |= IEEE80211_KEY_GROUP;
- wk.ik_keyix = key_idx;
- } else {
- wk.ik_keyix = (key_idx == 0 ? IEEE80211_KEYIX_NONE : key_idx);
- }
- if (wk.ik_keyix != IEEE80211_KEYIX_NONE && set_tx)
- wk.ik_flags |= IEEE80211_KEY_DEFAULT;
- /*
- * Ignore replay failures in IBSS and AHDEMO mode.
- */
- if (drv->opmode == IEEE80211_M_IBSS ||
- drv->opmode == IEEE80211_M_AHDEMO)
- wk.ik_flags |= IEEE80211_KEY_NOREPLAY;
- wk.ik_keylen = key_len;
- memcpy(&wk.ik_keyrsc, seq, seq_len);
- wk.ik_keyrsc = le64toh(wk.ik_keyrsc);
- memcpy(wk.ik_keydata, key, key_len);
-
- return set80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk));
-}
-
-static int
-wpa_driver_bsd_set_countermeasures(void *priv, int enabled)
-{
- struct wpa_driver_bsd_data *drv = priv;
-
- wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
- return set80211param(drv, IEEE80211_IOC_COUNTERMEASURES, enabled);
-}
-
-
-static int
-wpa_driver_bsd_set_drop_unencrypted(void *priv, int enabled)
-{
- struct wpa_driver_bsd_data *drv = priv;
-
- wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
- return set80211param(drv, IEEE80211_IOC_DROPUNENCRYPTED, enabled);
-}
-
-static int
-wpa_driver_bsd_set_auth_alg(void *priv, int auth_alg)
-{
- struct wpa_driver_bsd_data *drv = priv;
- int authmode;
-
- if ((auth_alg & WPA_AUTH_ALG_OPEN) &&
- (auth_alg & WPA_AUTH_ALG_SHARED))
- authmode = IEEE80211_AUTH_AUTO;
- else if (auth_alg & WPA_AUTH_ALG_SHARED)
- authmode = IEEE80211_AUTH_SHARED;
- else
- authmode = IEEE80211_AUTH_OPEN;
-
- wpa_printf(MSG_DEBUG, "%s alg 0x%x authmode %u",
- __func__, auth_alg, authmode);
-
- return set80211param(drv, IEEE80211_IOC_AUTHMODE, authmode);
-}
-
-static int
-wpa_driver_bsd_deauthenticate(void *priv, const u8 *addr, int reason_code)
-{
- struct wpa_driver_bsd_data *drv = priv;
- struct ieee80211req_mlme mlme;
-
- drv->lastssid_len = 0;
-
- wpa_printf(MSG_DEBUG, "%s", __func__);
- memset(&mlme, 0, sizeof(mlme));
- mlme.im_op = IEEE80211_MLME_DEAUTH;
- mlme.im_reason = reason_code;
- memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
- return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
-}
-
-static int
-wpa_driver_bsd_disassociate(void *priv, const u8 *addr, int reason_code)
-{
- struct wpa_driver_bsd_data *drv = priv;
- struct ieee80211req_mlme mlme;
-
- drv->lastssid_len = 0;
-
- wpa_printf(MSG_DEBUG, "%s", __func__);
- memset(&mlme, 0, sizeof(mlme));
- mlme.im_op = IEEE80211_MLME_DISASSOC;
- mlme.im_reason = reason_code;
- memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
- return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
-}
-
-static int
-wpa_driver_bsd_associate(void *priv, struct wpa_driver_associate_params *params)
-{
- struct wpa_driver_bsd_data *drv = priv;
- struct ieee80211req_mlme mlme;
- int flags, privacy;
-
- wpa_printf(MSG_DEBUG,
- "%s: ssid '%.*s' wpa ie len %u pairwise %u group %u key mgmt %u"
- , __func__
- , params->ssid_len, params->ssid
- , params->wpa_ie_len
- , params->pairwise_suite
- , params->group_suite
- , params->key_mgmt_suite
- );
-
- /* NB: interface must be marked UP to associate */
- if (getifflags(drv, &flags) != 0) {
- wpa_printf(MSG_DEBUG, "%s did not mark interface UP", __func__);
- return -1;
- }
- if ((flags & IFF_UP) == 0 && setifflags(drv, flags | IFF_UP) != 0) {
- wpa_printf(MSG_DEBUG, "%s unable to mark interface UP",
- __func__);
- return -1;
- }
-
- if (wpa_driver_bsd_set_drop_unencrypted(drv, params->drop_unencrypted)
- < 0)
- return -1;
- if (wpa_driver_bsd_set_auth_alg(drv, params->auth_alg) < 0)
- return -1;
- /* XXX error handling is wrong but unclear what to do... */
- if (wpa_driver_bsd_set_wpa_ie(drv, params->wpa_ie, params->wpa_ie_len) < 0)
- return -1;
-
- privacy = !(params->pairwise_suite == CIPHER_NONE &&
- params->group_suite == CIPHER_NONE &&
- params->key_mgmt_suite == KEY_MGMT_NONE &&
- params->wpa_ie_len == 0);
- wpa_printf(MSG_DEBUG, "%s: set PRIVACY %u", __func__, privacy);
-
- if (set80211param(drv, IEEE80211_IOC_PRIVACY, privacy) < 0)
- return -1;
-
- if (params->wpa_ie_len &&
- set80211param(drv, IEEE80211_IOC_WPA,
- params->wpa_ie[0] == WLAN_EID_RSN ? 2 : 1) < 0)
- return -1;
-
- memset(&mlme, 0, sizeof(mlme));
- mlme.im_op = IEEE80211_MLME_ASSOC;
- if (params->ssid != NULL)
- memcpy(mlme.im_ssid, params->ssid, params->ssid_len);
- mlme.im_ssid_len = params->ssid_len;
- if (params->bssid != NULL)
- memcpy(mlme.im_macaddr, params->bssid, IEEE80211_ADDR_LEN);
- if (set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme)) < 0)
- return -1;
- memcpy(drv->lastssid, params->ssid, params->ssid_len);
- drv->lastssid_len = params->ssid_len;
- return 0;
-}
-
-static int
-wpa_driver_bsd_scan(void *priv, struct wpa_driver_scan_params *params)
-{
- struct wpa_driver_bsd_data *drv = priv;
- struct ieee80211_scan_req sr;
- int i;
- int flags;
-
- /* XXX not true but easiest to perpetuate the myth */
- /* NB: interface must be marked UP to do a scan */
- if (getifflags(drv, &flags) != 0) {
- wpa_printf(MSG_DEBUG, "%s did not mark interface UP", __func__);
- return -1;
- }
- if ((flags & IFF_UP) == 0 && setifflags(drv, flags | IFF_UP) != 0) {
- wpa_printf(MSG_DEBUG, "%s unable to mark interface UP",
- __func__);
- return -1;
- }
-
- memset(&sr, 0, sizeof(sr));
- sr.sr_flags = IEEE80211_IOC_SCAN_ACTIVE
- | IEEE80211_IOC_SCAN_ONCE
- | IEEE80211_IOC_SCAN_NOJOIN
- ;
- sr.sr_duration = IEEE80211_IOC_SCAN_FOREVER;
- if (params->num_ssids > 0) {
- sr.sr_nssid = params->num_ssids;
-#if 0
- /* Boundary check is done by upper layer */
- if (sr.sr_nssid > IEEE80211_IOC_SCAN_MAX_SSID)
- sr.sr_nssid = IEEE80211_IOC_SCAN_MAX_SSID;
-#endif
- /* NB: check scan cache first */
- sr.sr_flags |= IEEE80211_IOC_SCAN_CHECK;
-}
- for (i = 0; i < sr.sr_nssid; i++) {
- sr.sr_ssid[i].len = params->ssids[i].ssid_len;
- os_memcpy(sr.sr_ssid[i].ssid, params->ssids[i].ssid,
- sr.sr_ssid[i].len);
- }
- /* NB: net80211 delivers a scan complete event so no need to poll */
- return set80211var(drv, IEEE80211_IOC_SCAN_REQ, &sr, sizeof(sr));
-}
-
-#include <net/route.h>
-#include <net80211/ieee80211_freebsd.h>
-
-static void
-wpa_driver_bsd_event_receive(int sock, void *ctx, void *sock_ctx)
-{
- struct wpa_driver_bsd_data *drv = sock_ctx;
- char buf[2048];
- struct if_announcemsghdr *ifan;
- struct if_msghdr *ifm;
- struct rt_msghdr *rtm;
- union wpa_event_data event;
- struct ieee80211_michael_event *mic;
- int n;
-
- n = read(sock, buf, sizeof(buf));
- if (n < 0) {
- if (errno != EINTR && errno != EAGAIN)
- perror("read(PF_ROUTE)");
- return;
- }
-
- rtm = (struct rt_msghdr *) buf;
- if (rtm->rtm_version != RTM_VERSION) {
- wpa_printf(MSG_DEBUG, "Routing message version %d not "
- "understood\n", rtm->rtm_version);
- return;
- }
- memset(&event, 0, sizeof(event));
- switch (rtm->rtm_type) {
- case RTM_IFANNOUNCE:
- ifan = (struct if_announcemsghdr *) rtm;
- if (ifan->ifan_index != drv->ifindex)
- break;
- strlcpy(event.interface_status.ifname, drv->ifname,
- sizeof(event.interface_status.ifname));
- switch (ifan->ifan_what) {
- case IFAN_DEPARTURE:
- event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
- default:
- return;
- }
- wpa_printf(MSG_DEBUG, "RTM_IFANNOUNCE: Interface '%s' %s",
- event.interface_status.ifname,
- ifan->ifan_what == IFAN_DEPARTURE ?
- "removed" : "added");
- wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event);
- break;
- case RTM_IEEE80211:
- ifan = (struct if_announcemsghdr *) rtm;
- if (ifan->ifan_index != drv->ifindex)
- break;
- switch (ifan->ifan_what) {
- case RTM_IEEE80211_ASSOC:
- case RTM_IEEE80211_REASSOC:
- wpa_supplicant_event(ctx, EVENT_ASSOC, NULL);
- break;
- case RTM_IEEE80211_DISASSOC:
- wpa_supplicant_event(ctx, EVENT_DISASSOC, NULL);
- break;
- case RTM_IEEE80211_SCAN:
- wpa_supplicant_event(ctx, EVENT_SCAN_RESULTS, NULL);
- break;
- case RTM_IEEE80211_REPLAY:
- /* ignore */
- break;
- case RTM_IEEE80211_MICHAEL:
- mic = (struct ieee80211_michael_event *) &ifan[1];
- wpa_printf(MSG_DEBUG,
- "Michael MIC failure wireless event: "
- "keyix=%u src_addr=" MACSTR, mic->iev_keyix,
- MAC2STR(mic->iev_src));
-
- memset(&event, 0, sizeof(event));
- event.michael_mic_failure.unicast =
- !IEEE80211_IS_MULTICAST(mic->iev_dst);
- wpa_supplicant_event(ctx, EVENT_MICHAEL_MIC_FAILURE,
- &event);
- break;
- }
- break;
- case RTM_IFINFO:
- ifm = (struct if_msghdr *) rtm;
- if (ifm->ifm_index != drv->ifindex)
- break;
- if ((rtm->rtm_flags & RTF_UP) == 0) {
- strlcpy(event.interface_status.ifname, drv->ifname,
- sizeof(event.interface_status.ifname));
- event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
- wpa_printf(MSG_DEBUG, "RTM_IFINFO: Interface '%s' DOWN",
- event.interface_status.ifname);
- wpa_supplicant_event(ctx, EVENT_INTERFACE_STATUS, &event);
- }
- break;
- }
-}
-
-static int
-getmaxrate(const uint8_t rates[15], uint8_t nrates)
-{
- int i, maxrate = -1;
-
- for (i = 0; i < nrates; i++) {
- int rate = rates[i] & IEEE80211_RATE_VAL;
- if (rate > maxrate)
- rate = maxrate;
- }
- return maxrate;
-}
-
-/* unalligned little endian access */
-#define LE_READ_4(p) \
- ((u_int32_t) \
- ((((const u_int8_t *)(p))[0] ) | \
- (((const u_int8_t *)(p))[1] << 8) | \
- (((const u_int8_t *)(p))[2] << 16) | \
- (((const u_int8_t *)(p))[3] << 24)))
-
-static int __inline
-iswpaoui(const u_int8_t *frm)
-{
- return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
-}
-
-
-static void
-wpa_driver_bsd_add_scan_entry(struct wpa_scan_results *res,
- struct ieee80211req_scan_result *sr)
-{
- struct wpa_scan_res *result, **tmp;
- size_t extra_len;
- u8 *pos;
-
- extra_len = 2 + sr->isr_ssid_len;
- extra_len += 2 + sr->isr_nrates;
- extra_len += 3; /* ERP IE */
- extra_len += sr->isr_ie_len;
-
- result = os_zalloc(sizeof(*result) + extra_len);
- if (result == NULL)
- return;
- os_memcpy(result->bssid, sr->isr_bssid, ETH_ALEN);
- result->freq = sr->isr_freq;
- result->beacon_int = sr->isr_intval;
- result->caps = sr->isr_capinfo;
- result->qual = sr->isr_rssi;
- result->noise = sr->isr_noise;
-
- pos = (u8 *)(result + 1);
-
- *pos++ = WLAN_EID_SSID;
- *pos++ = sr->isr_ssid_len;
- os_memcpy(pos, sr + 1, sr->isr_ssid_len);
- pos += sr->isr_ssid_len;
-
- /*
- * Deal all rates as supported rate.
- * Because net80211 doesn't report extended supported rate or not.
- */
- *pos++ = WLAN_EID_SUPP_RATES;
- *pos++ = sr->isr_nrates;
- os_memcpy(pos, sr->isr_rates, sr->isr_nrates);
- pos += sr->isr_nrates;
-
- *pos++ = WLAN_EID_ERP_INFO;
- *pos++ = 1;
- *pos++ = sr->isr_erp;
-
- os_memcpy(pos, (u8 *)(sr + 1) + sr->isr_ssid_len, sr->isr_ie_len);
- pos += sr->isr_ie_len;
-
- result->ie_len = pos - (u8 *)(result + 1);
-
- tmp = os_realloc(res->res,
- (res->num + 1) * sizeof(struct wpa_scan_res *));
- if (tmp == NULL) {
- os_free(result);
- return;
- }
- tmp[res->num++] = result;
- res->res = tmp;
-}
-
-static struct wpa_scan_results *
-wpa_driver_bsd_get_scan_results2(void *priv)
-{
- struct ieee80211req_scan_result *sr;
- struct wpa_scan_results *res;
- int len, rest;
- uint8_t buf[24*1024], *pos;
-
- len = get80211var(priv, IEEE80211_IOC_SCAN_RESULTS, buf, 24*1024);
- if (len < 0)
- return NULL;
-
- res = os_zalloc(sizeof(*res));
- if (res == NULL)
- return NULL;
-
- pos = buf;
- rest = len;
- while (rest >= sizeof(struct ieee80211req_scan_result)) {
- sr = (struct ieee80211req_scan_result *)pos;
- wpa_driver_bsd_add_scan_entry(res, sr);
- pos += sr->isr_len;
- rest -= sr->isr_len;
- }
-
- wpa_printf(MSG_DEBUG, "Received %d bytes of scan results (%lu BSSes)",
- len, (unsigned long)res->num);
-
- return (res);
-}
-
-
-#define GETPARAM(drv, param, v) \
- (((v) = get80211param(drv, param)) != -1)
-#define IEEE80211_C_BGSCAN 0x20000000
-
-/*
- * Set the scan cache valid threshold to 1.5 x bg scan interval
- * to force all scan requests to consult the cache unless they
- * explicitly bypass it.
- */
-static int
-setscanvalid(struct wpa_driver_bsd_data *drv)
-{
- int bgscan, scanvalid;
-
- if (!GETPARAM(drv, IEEE80211_IOC_SCANVALID, drv->prev_scanvalid) ||
- !GETPARAM(drv, IEEE80211_IOC_BGSCAN_INTERVAL, bgscan))
- return -1;
- scanvalid = 3*bgscan/2;
- return (drv->prev_scanvalid < scanvalid) ?
- set80211param(drv, IEEE80211_IOC_SCANVALID, scanvalid) : 0;
-}
-
-static void *
-wpa_driver_bsd_init(void *ctx, const char *ifname)
-{
- struct wpa_driver_bsd_data *drv;
- struct ieee80211_devcaps_req devcaps;
- int flags;
-
- drv = malloc(sizeof(*drv));
- if (drv == NULL)
- return NULL;
- memset(drv, 0, sizeof(*drv));
- /*
- * NB: We require the interface name be mappable to an index.
- * This implies we do not support having wpa_supplicant
- * wait for an interface to appear. This seems ok; that
- * doesn't belong here; it's really the job of devd.
- */
- drv->ifindex = if_nametoindex(ifname);
- if (drv->ifindex == 0) {
- wpa_printf(MSG_DEBUG, "%s: interface %s does not exist",
- __func__, ifname);
- goto fail1;
- }
- drv->sock = socket(PF_INET, SOCK_DGRAM, 0);
- if (drv->sock < 0)
- goto fail1;
- drv->ctx = ctx;
- strncpy(drv->ifname, ifname, sizeof(drv->ifname));
-
- /*
- * Mark the interface as down to ensure wpa_supplicant has exclusive
- * access to the net80211 state machine, do this before opening the
- * route socket to avoid a false event that the interface disappeared.
- */
- if (getifflags(drv, &flags) == 0)
- (void) setifflags(drv, flags &~ IFF_UP);
-
- drv->route = socket(PF_ROUTE, SOCK_RAW, 0);
- if (drv->route < 0)
- goto fail;
- eloop_register_read_sock(drv->route,
- wpa_driver_bsd_event_receive, ctx, drv);
-
- if (get80211var(drv, IEEE80211_IOC_DEVCAPS, &devcaps, sizeof(devcaps)) < 0) {
- wpa_printf(MSG_DEBUG,
- "%s: failed to get device capabilities: %s",
- __func__, strerror(errno));
- goto fail;
- }
- drv->drivercaps = devcaps.dc_drivercaps;
- drv->cryptocaps = devcaps.dc_cryptocaps;
-
- if (!GETPARAM(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming)) {
- wpa_printf(MSG_DEBUG, "%s: failed to get roaming state: %s",
- __func__, strerror(errno));
- goto fail;
- }
- if (!GETPARAM(drv, IEEE80211_IOC_PRIVACY, drv->prev_privacy)) {
- wpa_printf(MSG_DEBUG, "%s: failed to get privacy state: %s",
- __func__, strerror(errno));
- goto fail;
- }
- if (!GETPARAM(drv, IEEE80211_IOC_WPA, drv->prev_wpa)) {
- wpa_printf(MSG_DEBUG, "%s: failed to get wpa state: %s",
- __func__, strerror(errno));
- goto fail;
- }
- if (set80211param(drv, IEEE80211_IOC_ROAMING, IEEE80211_ROAMING_MANUAL) < 0) {
- wpa_printf(MSG_DEBUG, "%s: failed to set wpa_supplicant-based "
- "roaming: %s", __func__, strerror(errno));
- goto fail;
- }
- if (drv->drivercaps & IEEE80211_C_BGSCAN) {
- /*
- * Driver does background scanning; force the scan valid
- * setting to 1.5 x bg scan interval so the scan cache is
- * always consulted before we force a foreground scan.
- */
- if (setscanvalid(drv) < 0) {
- wpa_printf(MSG_DEBUG,
- "%s: warning, failed to set scanvalid, scanning "
- "may be suboptimal: %s", __func__, strerror(errno));
- }
- }
- if (set80211param(drv, IEEE80211_IOC_WPA, 1+2) < 0) {
- wpa_printf(MSG_DEBUG, "%s: failed to enable WPA support %s",
- __func__, strerror(errno));
- goto fail;
- }
- drv->opmode = get80211opmode(drv);
-
- return drv;
-fail:
- close(drv->sock);
-fail1:
- free(drv);
- return NULL;
-}
-#undef GETPARAM
-
-static void
-wpa_driver_bsd_deinit(void *priv)
-{
- struct wpa_driver_bsd_data *drv = priv;
- int flags;
-
- /* NB: mark interface down */
- if (getifflags(drv, &flags) == 0)
- (void) setifflags(drv, flags &~ IFF_UP);
-
- wpa_driver_bsd_set_wpa_internal(drv, drv->prev_wpa, drv->prev_privacy);
- if (set80211param(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming) < 0) {
- /* NB: don't whinge if device ejected or equivalent */
- if (errno != ENXIO)
- wpa_printf(MSG_DEBUG, "%s: failed to restore roaming "
- "state", __func__);
- }
- if (drv->drivercaps & IEEE80211_C_BGSCAN) {
- /* XXX check return value */
- (void) set80211param(drv, IEEE80211_IOC_SCANVALID,
- drv->prev_scanvalid);
- }
-
- (void) close(drv->route); /* ioctl socket */
- (void) close(drv->sock); /* event socket */
- free(drv);
-}
-
-
-struct wpa_driver_ops wpa_driver_bsd_ops = {
- .name = "bsd",
- .desc = "BSD 802.11 support (Atheros, etc.)",
- .init = wpa_driver_bsd_init,
- .deinit = wpa_driver_bsd_deinit,
- .get_bssid = wpa_driver_bsd_get_bssid,
- .get_ssid = wpa_driver_bsd_get_ssid,
- .set_key = wpa_driver_bsd_set_key,
- .set_countermeasures = wpa_driver_bsd_set_countermeasures,
- .scan2 = wpa_driver_bsd_scan,
- .get_scan_results2 = wpa_driver_bsd_get_scan_results2,
- .deauthenticate = wpa_driver_bsd_deauthenticate,
- .disassociate = wpa_driver_bsd_disassociate,
- .associate = wpa_driver_bsd_associate,
-};
diff --git a/usr.sbin/ypserv/yp_access.c b/usr.sbin/ypserv/yp_access.c
index c0e4804..c82f8c7 100644
--- a/usr.sbin/ypserv/yp_access.c
+++ b/usr.sbin/ypserv/yp_access.c
@@ -97,6 +97,10 @@ struct securenet *securenets;
#define LINEBUFSZ 1024
+#ifdef TCP_WRAPPER
+int hosts_ctl(char *, char *, char *, char *);
+#endif
+
/*
* Read /var/yp/securenets file and initialize the securenets
* list. If the file doesn't exist, we set up a dummy entry that
diff --git a/usr.sbin/ypserv/yp_dnslookup.c b/usr.sbin/ypserv/yp_dnslookup.c
index 4ea6a13..dfb5594 100644
--- a/usr.sbin/ypserv/yp_dnslookup.c
+++ b/usr.sbin/ypserv/yp_dnslookup.c
@@ -456,7 +456,7 @@ yp_async_lookup_name(struct svc_req *rqstp, char *name, int af)
pending++;
if (debug)
- yp_error("queueing async DNS name lookup (%d)", q->id);
+ yp_error("queueing async DNS name lookup (%lu)", q->id);
yp_prune_dnsq();
return(YP_TRUE);
@@ -544,7 +544,7 @@ yp_async_lookup_addr(struct svc_req *rqstp, char *addr, int af)
pending++;
if (debug)
- yp_error("queueing async DNS address lookup (%d)", q->id);
+ yp_error("queueing async DNS address lookup (%lu)", q->id);
yp_prune_dnsq();
return(YP_TRUE);
diff --git a/usr.sbin/ypserv/yp_main.c b/usr.sbin/ypserv/yp_main.c
index 60bd6a1..958d3a6 100644
--- a/usr.sbin/ypserv/yp_main.c
+++ b/usr.sbin/ypserv/yp_main.c
@@ -329,9 +329,8 @@ create_service(const int sock, const struct netconfig *nconf,
return -1;
}
memset(slep, 0, sizeof(*slep));
- memcpy(&slep->sle_ss,
- (struct sockaddr *)(res->ai_addr),
- sizeof(res->ai_addr));
+ memcpy(&slep->sle_ss, res->ai_addr,
+ res->ai_addrlen);
slep->sle_sock = s;
SLIST_INSERT_HEAD(&sle_head, slep, sle_next);
OpenPOWER on IntegriCloud