summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin')
-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/bhyve/atpic.c17
-rw-r--r--usr.sbin/bhyve/bhyverun.c8
-rw-r--r--usr.sbin/bhyve/pci_emul.c74
-rw-r--r--usr.sbin/bhyve/pci_emul.h2
-rw-r--r--usr.sbin/bhyve/pci_virtio_net.c83
-rw-r--r--usr.sbin/bsdconfig/include/messages.subr12
-rw-r--r--usr.sbin/bsdconfig/networking/share/Makefile2
-rw-r--r--usr.sbin/bsdconfig/networking/share/services.subr54
-rw-r--r--usr.sbin/bsdconfig/share/media/cdrom.subr6
-rw-r--r--usr.sbin/bsdconfig/share/media/common.subr19
-rw-r--r--usr.sbin/bsdconfig/share/media/directory.subr6
-rw-r--r--usr.sbin/bsdconfig/share/media/dos.subr4
-rw-r--r--usr.sbin/bsdconfig/share/media/floppy.subr2
-rw-r--r--usr.sbin/bsdconfig/share/media/ftp.subr15
-rw-r--r--usr.sbin/bsdconfig/share/media/nfs.subr6
-rw-r--r--usr.sbin/bsdconfig/share/media/ufs.subr4
-rw-r--r--usr.sbin/bsdconfig/share/media/usb.subr4
-rwxr-xr-xusr.sbin/bsdconfig/share/packages/index.subr43
-rwxr-xr-xusr.sbin/bsdconfig/share/packages/packages.subr272
-rw-r--r--usr.sbin/bsdconfig/share/script.subr6
-rw-r--r--usr.sbin/bsdconfig/share/variable.subr23
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_hast/BEGEMOT-HAST-MIB.txt14
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_hast/hast_snmp.c5
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_hast/hast_tree.def1
-rw-r--r--usr.sbin/newsyslog/newsyslog.c20
-rw-r--r--usr.sbin/nfsd/nfsv4.416
-rw-r--r--usr.sbin/pkg_install/add/extract.c3
-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/powerd/powerd.850
-rw-r--r--usr.sbin/powerd/powerd.c16
-rw-r--r--usr.sbin/pw/pw_user.c8
-rw-r--r--usr.sbin/rwhod/rwhod.c628
-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.c934
48 files changed, 1103 insertions, 2250 deletions
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/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 66883be..ae22de2 100644
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -734,7 +734,13 @@ main(int argc, char *argv[])
init_mem();
init_inout();
- init_pci(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 37f1778..00adf62 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) { \
@@ -139,20 +140,15 @@ pci_parse_slot(char *opt, int legacy)
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(opt);
@@ -666,11 +662,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));
@@ -688,12 +686,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
@@ -993,7 +994,7 @@ 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;
@@ -1013,8 +1014,10 @@ init_pci(struct vmctx *ctx)
if (si->si_name != NULL) {
pde = pci_emul_finddev(si->si_name);
assert(pde != NULL);
- pci_emul_init(ctx, pde, slot, func,
- si->si_param);
+ error = pci_emul_init(ctx, pde, slot, func,
+ si->si_param);
+ if (error)
+ return (error);
}
}
}
@@ -1051,6 +1054,8 @@ init_pci(struct vmctx *ctx)
error = register_mem_fallback(&memp);
assert(error == 0);
+
+ return (0);
}
int
@@ -1224,20 +1229,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 654b2f6..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,
diff --git a/usr.sbin/bhyve/pci_virtio_net.c b/usr.sbin/bhyve/pci_virtio_net.c
index 4c03463..19f9ffe 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>
@@ -638,6 +639,30 @@ pci_vtnet_ring_init(struct pci_vtnet_softc *sc, uint64_t pfn)
}
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;
@@ -646,6 +671,9 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
char tname[MAXCOMLEN + 1];
struct pci_vtnet_softc *sc;
const char *env_msi;
+ char *devname;
+ char *vtopts;
+ int mac_provided;
sc = malloc(sizeof(struct pci_vtnet_softc));
memset(sc, 0, sizeof(struct pci_vtnet_softc));
@@ -664,14 +692,31 @@ pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
}
/*
- * 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_macaddr);
+ 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) {
@@ -701,29 +746,25 @@ 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_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];
}
- 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);
diff --git a/usr.sbin/bsdconfig/include/messages.subr b/usr.sbin/bsdconfig/include/messages.subr
index 8f486fc..39434ae 100644
--- a/usr.sbin/bsdconfig/include/messages.subr
+++ b/usr.sbin/bsdconfig/include/messages.subr
@@ -34,6 +34,8 @@ 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."
@@ -174,6 +176,7 @@ 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"
@@ -196,6 +199,7 @@ msg_length_of_specified_url_is_too_long="Length of specified URL is %u character
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"
@@ -238,6 +242,7 @@ msg_no_dos_primary_partitions_found="No DOS primary partitions found! This inst
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)"
@@ -250,7 +255,9 @@ msg_ok="OK"
msg_options="Options"
msg_options_editor="Options Editor"
msg_other="other"
+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."
@@ -258,6 +265,7 @@ 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_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):"
@@ -301,6 +309,7 @@ msg_quick_start_how_to_use_this_menu_system="Quick start - How to use this menu
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!"
@@ -334,6 +343,7 @@ 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"
@@ -358,8 +368,10 @@ 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"
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/services.subr b/usr.sbin/bsdconfig/networking/share/services.subr
new file mode 100644
index 0000000..ae7bce3
--- /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 (INLUDING, 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/share/media/cdrom.subr b/usr.sbin/bsdconfig/share/media/cdrom.subr
index 6f7afcd..4350367 100644
--- a/usr.sbin/bsdconfig/share/media/cdrom.subr
+++ b/usr.sbin/bsdconfig/share/media/cdrom.subr
@@ -146,8 +146,8 @@ f_media_init_cdrom()
# f_media_get_cdrom $device $file [$probe_only]
#
-# 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_only is present and non-NULL, returns success if $file exists.
#
f_media_get_cdrom()
{
@@ -156,7 +156,7 @@ f_media_get_cdrom()
f_dprintf "f_media_get_cdrom: dev=[%s] file=[%s] probe_only=%s" \
"$dev" "$file" "$probe_only"
- f_media_generic_get "$MOUNTPOINT" "$file"
+ f_media_generic_get "$MOUNTPOINT" "$file" "$probe_only"
}
# f_media_shutdown_cdrom $device
diff --git a/usr.sbin/bsdconfig/share/media/common.subr b/usr.sbin/bsdconfig/share/media/common.subr
index 581e501..4550d70 100644
--- a/usr.sbin/bsdconfig/share/media/common.subr
+++ b/usr.sbin/bsdconfig/share/media/common.subr
@@ -83,16 +83,18 @@ f_media_verify()
f_struct device_media || f_media_get_type
}
-# f_media_generic_get $base $file
+# f_media_generic_get $base $file [$probe_only]
#
-# 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_only is present and non-NULL, returns success if $file exists.
#
f_media_generic_get()
{
- local base="$1" file="$2"
+ local base="$1" file="$2" probe_only="$3"
local fname=f_media_generic_get
- f_dprintf "%s: base=[%s] files=[%s]" $fname "$base" "$file"
+ f_dprintf "%s: base=[%s] files=[%s] probe_only=%s" \
+ $fname "$base" "$file" "$probe_only"
local rel path
f_getvar $VAR_RELNAME rel
@@ -104,10 +106,19 @@ f_media_generic_get()
; do
if [ -f "$path" -a -r "$path" ]; then
f_dprintf "%s: file exists path=[%s]" $fname "$path"
+ [ "$probe_only" ] && 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"
+ [ "$probe_only" ] && return $SUCCESS
+ elif [ "$probe_only" ]; then
+ 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 cd0fd41..82c1b8c 100644
--- a/usr.sbin/bsdconfig/share/media/directory.subr
+++ b/usr.sbin/bsdconfig/share/media/directory.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
@@ -117,7 +118,8 @@ f_media_init_directory()
# f_media_get_directory $device $file [$probe_only]
#
# 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_only is present and non-NULL, returns success if $file
+# exists.
#
f_media_get_directory()
{
@@ -127,7 +129,7 @@ f_media_get_directory()
"$dev" "$file" "$probe_only"
device_$dev get private path
- f_media_generic_get "$path" "$file"
+ f_media_generic_get "$path" "$file" "$probe_only"
}
# f_media_shutdown_directory $device
diff --git a/usr.sbin/bsdconfig/share/media/dos.subr b/usr.sbin/bsdconfig/share/media/dos.subr
index ab15097..9320c2c 100644
--- a/usr.sbin/bsdconfig/share/media/dos.subr
+++ b/usr.sbin/bsdconfig/share/media/dos.subr
@@ -125,7 +125,7 @@ f_media_init_dos()
# f_media_get_dos $device $file [$probe_only]
#
# 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_only is present and non-NULL, returns success if $file exists.
#
f_media_get_dos()
{
@@ -134,7 +134,7 @@ f_media_get_dos()
f_dprintf "f_media_get_dos: dev=[%s] file=[%s] probe_only=%s" \
"$dev" "$file" "$probe_only"
- f_media_generic_get "$MOUNTPOINT" "$file"
+ f_media_generic_get "$MOUNTPOINT" "$file" "$probe_only"
}
# f_media_shutdown_dos $device
diff --git a/usr.sbin/bsdconfig/share/media/floppy.subr b/usr.sbin/bsdconfig/share/media/floppy.subr
index bb78518..beb574e 100644
--- a/usr.sbin/bsdconfig/share/media/floppy.subr
+++ b/usr.sbin/bsdconfig/share/media/floppy.subr
@@ -178,6 +178,8 @@ f_media_get_floppy()
f_media_init_floppy "$dev" || return $FAILURE
nretries=$(( $nretries - 1 ))
done
+ elif [ "$probe_only" ]; then
+ return $SUCCESS
fi
cat "$fp"
}
diff --git a/usr.sbin/bsdconfig/share/media/ftp.subr b/usr.sbin/bsdconfig/share/media/ftp.subr
index c2c7e6a..fb96b91 100644
--- a/usr.sbin/bsdconfig/share/media/ftp.subr
+++ b/usr.sbin/bsdconfig/share/media/ftp.subr
@@ -792,8 +792,8 @@ f_media_init_ftp()
#
# 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_only is present and non-NULL,
+# returns success if $file exists.
#
# Variables from variable.subr used to configure the connection are as follows
# (all of which are configured by f_media_set_ftp above):
@@ -900,6 +900,17 @@ f_media_get_ftp()
f_dprintf "sending ftp request for: %s" "ftp://$host$port/$dir/$file"
+ if [ "$probe_only" ]; then
+ local url="ftp://$userpass$host$port/$dir/$file"
+ [ "$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"
+ return $FAILURE
+ fi
+ 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/nfs.subr b/usr.sbin/bsdconfig/share/media/nfs.subr
index b1dad4f..86bdde2 100644
--- a/usr.sbin/bsdconfig/share/media/nfs.subr
+++ b/usr.sbin/bsdconfig/share/media/nfs.subr
@@ -210,8 +210,8 @@ f_media_init_nfs()
# f_media_get_nfs $device $file [$probe_only]
#
-# 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_only is present and non-NULL, returns success if $file exists.
#
f_media_get_nfs()
{
@@ -220,7 +220,7 @@ f_media_get_nfs()
f_dprintf "f_media_get_nfs: dev=[%s] file=[%s] probe_only=%s" \
"$dev" "$file" "$probe_only"
- f_media_generic_get "$MOUNTPOINT" "$file"
+ f_media_generic_get "$MOUNTPOINT" "$file" "$probe_only"
}
# f_media_shutdown_nfs $device
diff --git a/usr.sbin/bsdconfig/share/media/ufs.subr b/usr.sbin/bsdconfig/share/media/ufs.subr
index 5a4113e..14e2081 100644
--- a/usr.sbin/bsdconfig/share/media/ufs.subr
+++ b/usr.sbin/bsdconfig/share/media/ufs.subr
@@ -155,7 +155,7 @@ f_media_init_ufs()
# f_media_get_ufs $device $file [$probe_only]
#
# 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_only is present and non-NULL, returns success if $file exists.
#
f_media_get_ufs()
{
@@ -164,7 +164,7 @@ f_media_get_ufs()
f_dprintf "f_media_get_ufs: dev=[%s] file=[%s] probe_only=%s" \
"$dev" "$file" "$probe_only"
- f_media_generic_get "$MOUNTPOINT" "$file"
+ f_media_generic_get "$MOUNTPOINT" "$file" "$probe_only"
}
# f_media_shutdown_ufs $device
diff --git a/usr.sbin/bsdconfig/share/media/usb.subr b/usr.sbin/bsdconfig/share/media/usb.subr
index 4117e51..c2ece47 100644
--- a/usr.sbin/bsdconfig/share/media/usb.subr
+++ b/usr.sbin/bsdconfig/share/media/usb.subr
@@ -135,7 +135,7 @@ f_media_init_usb()
# f_media_get_usb $device $file [$probe_only]
#
# Returns data from $file on a mounted USB disk device. Similar to cat(1).
-# $probe_only is currently unused by this media type.
+# If $probe_only is present and non-NULL, returns success if $file exists.
#
f_media_get_usb()
{
@@ -144,7 +144,7 @@ f_media_get_usb()
f_dprintf "f_media_get_usb: dev=[%s] file=[%s] probe_only=%s" \
"$dev" "$file" "$probe_only"
- f_media_generic_get "$MOUNTPOINT" "$file"
+ f_media_generic_get "$MOUNTPOINT" "$file" "$probe_only"
}
# f_media_shutdown_usb $device
diff --git a/usr.sbin/bsdconfig/share/packages/index.subr b/usr.sbin/bsdconfig/share/packages/index.subr
index 7525ae6..bc26f50 100755
--- a/usr.sbin/bsdconfig/share/packages/index.subr
+++ b/usr.sbin/bsdconfig/share/packages/index.subr
@@ -207,7 +207,8 @@ f_index_read()
# f_index_extract_pages $var_to_get $var_basename $pagesize [$category]
#
-# Extracts the package INDEX into a series of sequential variables
+# 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.
@@ -217,7 +218,7 @@ f_index_read()
#
f_index_extract_pages()
{
- local var_to_get="$1" var_basename="$2" pagesize="$3"
+ local var_to_get="${1:-PACKAGE_INDEX}" var_basename="$2" pagesize="$3"
local category="$4" # Optional
eval "$(
@@ -241,6 +242,44 @@ f_index_extract_pages()
)"
}
+# 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
diff --git a/usr.sbin/bsdconfig/share/packages/packages.subr b/usr.sbin/bsdconfig/share/packages/packages.subr
index 388fd24..1a9bdf9 100755
--- a/usr.sbin/bsdconfig/share/packages/packages.subr
+++ b/usr.sbin/bsdconfig/share/packages/packages.subr
@@ -32,6 +32,8 @@ 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
@@ -48,8 +50,17 @@ f_include_lang $BSDCFG_LIBE/include/messages.subr
############################################################ GLOBALS
-PACKAGE_CATEGORIES=
-SELECTED_PACKAGES=
+#
+# 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
@@ -157,6 +168,15 @@ f_package_deselect()
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
@@ -608,25 +628,16 @@ f_package_review()
#
# Process each of the selected packages:
- # + First, process dependencies.
- # + Second, process packages marked for Install.
- # + Third, process packages marked for Re-install.
+ # + 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
f_getvar _mark_$varpkg mark
- [ "$mark" = "D" ] || continue
- # XXX Install dependency
- f_package_deselect "$package"
- done
- for package in $SELECTED_PACKAGES; do
- mark=
- f_str2varname "$package" varpkg
- f_getvar _mark_$varpkg mark
[ "$mark" = "I" ] || continue
- # XXX Install package
+ f_package_add "$package" || continue
f_package_deselect "$package"
done
for package in $SELECTED_PACKAGES; do
@@ -646,9 +657,6 @@ f_package_review()
f_package_deselect "$package"
done
- # XXX
- f_show_msg "Coming soon..."
-
return $SUCCESS
}
@@ -812,6 +820,236 @@ f_package_config()
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_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"
+
+ # 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
+
+ local fname=f_package_extract
+
+ # We have a path, call the device strategy routine to get the file
+ local pkg_ext probe_only=1 found=
+ for pkg_ext in "" $PACKAGE_EXTENSIONS; do
+ if f_device_get $device "$path$pkg_ext" $probe_only; 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
+}
+
############################################################ MAIN
f_dprintf "%s: Successfully loaded." packages/packages.subr
diff --git a/usr.sbin/bsdconfig/share/script.subr b/usr.sbin/bsdconfig/share/script.subr
index 8b8c8e2..5574863 100644
--- a/usr.sbin/bsdconfig/share/script.subr
+++ b/usr.sbin/bsdconfig/share/script.subr
@@ -34,6 +34,8 @@ f_dprintf "%s: loading includes..." script.subr
f_include $BSDCFG_SHARE/device.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
@@ -187,8 +189,12 @@ 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
# variable.subr
f_resword_new installVarDefaults f_variable_set_defaults
diff --git a/usr.sbin/bsdconfig/share/variable.subr b/usr.sbin/bsdconfig/share/variable.subr
index e841029..27010f9 100644
--- a/usr.sbin/bsdconfig/share/variable.subr
+++ b/usr.sbin/bsdconfig/share/variable.subr
@@ -106,6 +106,8 @@ f_variable_get_value()
#
f_variable_set_defaults()
{
+ f_dprintf "f_variable_set_defaults: Initializing defaults..."
+
#
# Initialize various user-edittable values to their defaults
#
@@ -120,6 +122,27 @@ f_variable_set_defaults()
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."
}
diff --git a/usr.sbin/bsnmpd/modules/snmp_hast/BEGEMOT-HAST-MIB.txt b/usr.sbin/bsnmpd/modules/snmp_hast/BEGEMOT-HAST-MIB.txt
index df64c497..6e20bdd 100644
--- a/usr.sbin/bsnmpd/modules/snmp_hast/BEGEMOT-HAST-MIB.txt
+++ b/usr.sbin/bsnmpd/modules/snmp_hast/BEGEMOT-HAST-MIB.txt
@@ -57,6 +57,9 @@ begemotHast MODULE-IDENTITY
REVISION "201304130000Z"
DESCRIPTION
"Initial revision."
+ REVISION "201307010000Z"
+ DESCRIPTION
+ "Added hastResourceWorkerPid."
::= { begemot 220 }
begemotHastObjects OBJECT IDENTIFIER ::= { begemotHast 1 }
@@ -116,7 +119,8 @@ HastResourceEntry ::= SEQUENCE {
hastResourceReadErrors Counter64,
hastResourceWriteErrors Counter64,
hastResourceDeleteErrors Counter64,
- hastResourceFlushErrors Counter64
+ hastResourceFlushErrors Counter64,
+ hastResourceWorkerPid INTEGER
}
hastResourceIndex OBJECT-TYPE
@@ -295,4 +299,12 @@ hastResourceFlushErrors OBJECT-TYPE
"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/hast_snmp.c b/usr.sbin/bsnmpd/modules/snmp_hast/hast_snmp.c
index c5abd64..ef8832a 100644
--- a/usr.sbin/bsnmpd/modules/snmp_hast/hast_snmp.c
+++ b/usr.sbin/bsnmpd/modules/snmp_hast/hast_snmp.c
@@ -78,6 +78,7 @@ struct hast_snmp_resource {
uint64_t write_errors;
uint64_t delete_errors;
uint64_t flush_errors;
+ pid_t workerpid;
};
static TAILQ_HEAD(, hast_snmp_resource) resources =
@@ -343,6 +344,7 @@ update_resources(void)
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);
@@ -498,6 +500,9 @@ op_hastResourceTable(struct snmp_context *context __unused,
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;
diff --git a/usr.sbin/bsnmpd/modules/snmp_hast/hast_tree.def b/usr.sbin/bsnmpd/modules/snmp_hast/hast_tree.def
index 289c608..3769bd2 100644
--- a/usr.sbin/bsnmpd/modules/snmp_hast/hast_tree.def
+++ b/usr.sbin/bsnmpd/modules/snmp_hast/hast_tree.def
@@ -59,6 +59,7 @@
(19 hastResourceWriteErrors COUNTER64 GET)
(20 hastResourceDeleteErrors COUNTER64 GET)
(21 hastResourceFlushErrors COUNTER64 GET)
+ (22 hastResourceWorkerPid INTEGER GET)
)
)
)
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c
index 7a7e26f..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';
}
diff --git a/usr.sbin/nfsd/nfsv4.4 b/usr.sbin/nfsd/nfsv4.4
index e0e6023..8d9bc80 100644
--- a/usr.sbin/nfsd/nfsv4.4
+++ b/usr.sbin/nfsd/nfsv4.4
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 1, 2013
+.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
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/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/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/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/rwhod/rwhod.c b/usr.sbin/rwhod/rwhod.c
index 16bf948..26b0500 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,100 @@ 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) {
+ 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;
+}
+
+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(*name) || !isalnum(*name) || ispunct(*name))
+ return (0);
+ name++;
+ size++;
+ }
+ *name = '\0';
+ return (size > 0);
+}
- cc = recvfrom(s, (char *)&wd, sizeof(struct whod), 0,
- (struct sockaddr *)&from, &len);
+void
+receiver_process(void)
+{
+ struct sockaddr_in from;
+ struct stat st;
+ 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);
+ }
+ if (cap_rights_limit(dirfd, CAP_CREATE | CAP_WRITE | CAP_FTRUNCATE |
+ CAP_SEEK | CAP_LOOKUP | CAP_FSTAT) < 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 +386,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;
}
+ if (cap_rights_limit(whod, CAP_WRITE | CAP_FTRUNCATE |
+ CAP_FSTAT) < 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 +433,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) close(dirfd);
}
void
-run_as(uid, gid)
- uid_t *uid;
- gid_t *gid;
+sender_process(void)
{
- 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
-onalrm(int signo __unused)
-{
- 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 +547,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 +575,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 +599,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 +636,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 +678,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 +709,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 +746,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/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 24a0b9c..0000000
--- a/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c
+++ /dev/null
@@ -1,934 +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;
- /*
- * the rssi value reported by the kernel is in 0.5dB steps relative to
- * the reported noise floor. see ieee80211_node.h for details.
- */
- result->level = sr->isr_rssi / 2 + 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,
-};
OpenPOWER on IntegriCloud