da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or http://www.opensolaris.org/os/licensing.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright#include <sys/tzfile.h>
8d7e41661dc4633488e93b13363137523ce59977jose borrego#include <errno.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <stdlib.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <stdio.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <unistd.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <syslog.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <string.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <strings.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <time.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <synch.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <netdb.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <sys/socket.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <arpa/inet.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as#include <smbsrv/libsmb.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/libsmbns.h>
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <smbsrv/smb.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/mailslot.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbns_browser.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbns_netbios.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego/*
8d7e41661dc4633488e93b13363137523ce59977jose borrego * ntdomain_info
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Temporary. It should be removed once NBTD is integrated.
8d7e41661dc4633488e93b13363137523ce59977jose borrego */
8d7e41661dc4633488e93b13363137523ce59977jose borregosmb_ntdomain_t ntdomain_info;
8d7e41661dc4633488e93b13363137523ce59977jose borregomutex_t ntdomain_mtx;
8d7e41661dc4633488e93b13363137523ce59977jose borregocond_t ntdomain_cv;
8d7e41661dc4633488e93b13363137523ce59977jose borrego
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define SMB_SERVER_SIGNATURE 0xaa550415
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjbtypedef struct smb_hostinfo {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb list_node_t hi_lnd;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_nic_t hi_nic;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb char hi_nbname[NETBIOS_NAME_SZ];
7b59d02d2a384be9a08087b14defadd214b3c1ddjb name_entry_t hi_netname;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb uint32_t hi_nextannouce;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb int hi_reps;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb int hi_interval;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb uint8_t hi_updatecnt;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb uint32_t hi_type;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_version_t hi_version;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb} smb_hostinfo_t;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbtypedef struct smb_browserinfo {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb list_t bi_hlist;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb int bi_hcnt;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb rwlock_t bi_hlist_rwl;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb boolean_t bi_changed;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb mutex_t bi_mtx;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb} smb_browserinfo_t;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic smb_browserinfo_t smb_binfo;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic int smb_browser_init(void);
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic void smb_browser_infoinit(void);
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic void smb_browser_infoterm(void);
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic void smb_browser_infofree(void);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
8d7e41661dc4633488e93b13363137523ce59977jose borrego
7b59d02d2a384be9a08087b14defadd214b3c1ddjbvoid
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_browser_reconfig(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) mutex_lock(&smb_binfo.bi_mtx);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_binfo.bi_changed = B_TRUE;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) mutex_unlock(&smb_binfo.bi_mtx);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 3. Browser Overview
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Hosts involved in the browsing process can be separated into two
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * distinct groups, browser clients and browser servers (often referred to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * simply as "browsers").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A browser is a server which maintains information about servers -
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * primarily the domain they are in and the services that they are running
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * -- and about domains. Browsers may assume several different roles in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * their lifetimes, and dynamically switch between them.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Browser clients are of two types: workstations and (non-browser)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * servers. In the context of browsing, workstations query browsers for the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information they contain; servers supply browsers the information by
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * registering with them. Note that, at times, browsers may themselves
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * behave as browser clients and query other browsers.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * For the purposes of this specification, a domain is simply a name with
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * which to associate a group of resources such as computers, servers and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * users. Domains allow a convenient means for browser clients to restrict
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the scope of a search when they query browser servers. Every domain has
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * a "master" server called the Primary Domain Controller (PDC) that
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * manages various activities within the domain.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * One browser for each domain on a subnet is designated the Local Master
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Browser for that domain. Servers in its domain on the subnet register
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * with it, as do the Local Master Browsers for other domains on the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * subnet. It uses these registrations to maintain authoritative
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information about its domain on its subnet. If there are other subnets
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in the network, it also knows the name of the server running the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * domain's Domain Master Browser; it registers with it, and uses it to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * obtain information about the rest of the network (see below).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Clients on a subnet query browsers designated as the Backup Browsers for
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the subnet (not the Master Browser). Backup Browsers maintain a copy of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the information on the Local Master Browser; they get it by periodically
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * querying the Local Master Browser for all of its information. Clients
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * find the Backup Browsers by asking the Local Master Browser. Clients are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * expected to spread their queries evenly across Backup Browsers to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * balance the load.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The Local Master Browser is dynamically elected automatically. Multiple
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Backup Browser Servers may exist per subnet; they are selected from
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * among the potential browser servers by the Local Master Browser, which
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is configured to select enough to handle the expected query load.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When there are multiple subnets, a Domain Master Browser is assigned
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the task of keeping the multiple subnets in synchronization. The Primary
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Domain Controller (PDC) always acts as the Domain Master Browser. The
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Domain Master Browser periodically acts as a client and queries all the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Local Master Browsers for its domain, asking them for a list containing
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * all the domains and all the servers in their domain known within their
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * subnets; it merges all the replies into a single master list. This
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * allows a Domain Master Browser server to act as a collection point for
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * inter-subnet browsing information. Local Master Browsers periodically
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * query the Domain Master Browser to retrieve the network-wide information
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * it maintains.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When a domain spans only a single subnet, there will not be any distinct
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Local Master Browser; this role will be handled by the Domain Master
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Browser. Similarly, the Domain Master Browser is always the Local Master
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Browser for the subnet it is on.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When a browser client suspects that the Local Master Browser has failed,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the client will instigate an election in which the browser servers
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * participate, and some browser servers may change roles.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Some characteristics of a good browsing mechanism include:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . minimal network traffic
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . minimum server discovery time
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . minimum change discovery latency
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . immunity to machine failures
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Historically, Browser implementations had been very closely tied to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * NETBIOS and datagrams. The early implementations caused a lot of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * broadcast traffic. See Appendix D for an overview that presents how the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Browser specification evolved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 4. Browsing Protocol Architecture
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This section first describes the how the browsing protocol is layered,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * then describes the roles of clients, servers, and browsers in the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * browsing subsystem.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 4.1 Layering of Browsing Protocol Requests
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Most of the browser functionality is implemented using mailslots.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Mailslots provide a mechanism for fast, unreliable unidirectional data
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * transfer; they are named via ASCII "mailslot (path) name". Mailslots are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * implemented using the CIFS Transact SMB which is encapsulated in a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * NETBIOS datagram. Browser protocol requests are sent to browser specific
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * mailslots using some browser-specific NETBIOS names. These datagrams can
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * either be unicast or broadcast, depending on whether the NETBIOS name is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * a "unique name" or a "group name". Various data structures, which are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * detailed subsequently within this document, flow as the data portion of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the Transact SMB.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Here is an example of a generic browser SMB, showing how a browser
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * request is encapsulated in a TRANSACT SMB request. Note that the PID,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * TID, MID, UID, and Flags are all 0 in mailslot requests.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: C transact, File = \MAILSLOT\BROWSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: SMB Status = Error Success
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Error class = No Error
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Error code = No Error
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Header: PID = 0x0000 TID = 0x0000 MID = 0x0000 UID = 0x0000
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Tree ID (TID) = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Process ID (PID) = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: User ID (UID) = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Multiplex ID (MID) = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Flags Summary = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Command = C transact
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Word count = 17
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Word parameters
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Total parm bytes = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Total data bytes = 33
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Max parm bytes = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Max data bytes = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Max setup words = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Transact Flags Summary = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: ...............0 = Leave session intact
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: ..............0. = Response required
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Transact timeout = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Parameter bytes = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Parameter offset = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Data bytes = 33 (0x21)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Data offset = 86 (0x56)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Setup word count = 3
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Setup words
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Mailslot opcode = Write mailslot
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Transaction priority = 1
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Mailslot class = Unreliable (broadcast)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Byte count = 50
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Byte parameters
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Path name = \MAILSLOT\BROWSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Transaction data
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Data: Number of data bytes remaining = 33 (0x0021)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Note the SMB command is Transact, the opcode within the Transact SMB is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Mailslot Write, and the browser data structure is carried as the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Transact data.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The Transaction data begins with an opcode, that signifies the operation
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and determines the size and structure of data that follows. This opcode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is named as per one of the below:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * HostAnnouncement 1
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * AnnouncementRequest 2
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * RequestElection 8
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * GetBackupListReq 9
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * GetBackupListResp 10
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * BecomeBackup 11
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * DomainAnnouncment 12
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * MasterAnnouncement 13
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * LocalMasterAnnouncement 15
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Browser datagrams are often referred to as simply browser frames. The
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * frames are in particular, referred to by the name of the opcode within
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the Transaction data e.g. a GetBackupListReq browser frame, a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * RequestElection browser frame, etc.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The structures that are sent as the data portion of the Transact SMB are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * described in section(s) 6.2 through 6.12 in this document. These
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * structures are tightly packed, i.e. there are no intervening pad bytes
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in the structure, unless they are explicitly described as being there.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * All quantities are sent in native Intel format and multi-byte values are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * transmitted least significant byte first.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Besides mailslots and Transaction SMBs, the other important piece of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * browser architecture is the NetServerEnum2 request. This request that
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * allows an application to interrogate a Browser Server and obtain a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * complete list of resources (servers, domains, etc) known to that Browser
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * server. Details of the NetServerEnum2 request are presented in section
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 6.4. Some examples of the NetServerEnum2 request being used are when a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Local Master Browser sends a NetServerEnum2 request to the Domain Master
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Browser and vice versa. Another example is when a browser client sends a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * NetServerEnum2 request to a Backup Browser server.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 4.3 Non-Browser Server
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A non-browser server is a server that has some resource(s) or service(s)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * it wishes to advertise as being available using the browsing protocol.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Examples of non-browser servers would be an SQL server, print server,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * etc.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A non-browser server MUST periodically send a HostAnnouncement browser
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * frame, specifying the type of resources or services it is advertising.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Details are in section 6.5.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A non-browser server SHOULD announce itself relatively frequently when
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * it first starts up in order to make its presence quickly known to the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * browsers and thence to potential clients. The frequency of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * announcements SHOULD then be gradually stretched, so as to minimize
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * network traffic. Typically, non-browser servers announce themselves
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * once every minute upon start up and then gradually adjust the frequency
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * of the announcements to once every 12 minutes.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A non-browser server SHOULD send a HostAnnouncement browser frame
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * specifying a type of 0 just prior to shutting down, to allow it to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * quickly be removed from the list of available servers.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A non-browser server MUST receive and process AnnouncementRequest frames
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * from the Local Master Browser, and MUST respond with a HostAnnouncement
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * frame, after a delay chosen randomly from the interval [0,30] seconds.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * AnnouncementRequests typically happen when a Local Master Browser starts
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * up with an empty list of servers for the domain, and wants to fill it
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * quickly. The 30 second range for responses prevents the Master Browser
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * from becoming overloaded and losing replies, as well as preventing the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * network from being flooded with responses.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 4.4 Browser Servers
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The following sections describe the roles of the various types of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * browser servers.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 4.4.1 Potential Browser Server
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Potential Browser server is a browser server that is capable of being
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * a Backup Browser server or Master Browser server, but is not currently
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fulfilling either of those roles.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Potential Browser MUST set type SV_TYPE_POTENTIAL_BROWSER (see section
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 6.4.1) in its HostAnnouncement until it is ready to shut down. In its
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * last HostAnnouncement frame before it shuts down, it SHOULD specify a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * type of 0.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Potential Browser server MUST receive and process BecomeBackup frames
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * (see section 6.9) and become a backup browser upon their receipt.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Potential Browser MUST participate in browser elections (see section
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 6.8).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 4.4.2 Backup Browser
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Backup Browser servers are a subset of the Potential Browsers that have
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * been chosen by the Master Browser on their subnet to be the Backup
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Browsers for the subnet.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Backup Browser MUST set type SV_TYPE_BACKUP_BROWSER (see section
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 6.4.1) in its HostAnnouncement until it is ready to shut down. In its
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * last HostAnnouncement frame before it shuts down, it SHOULD specify a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * type of 0.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Backup Browser MUST listen for a LocalMasterAnnouncement frame (see
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * section 6.10) from the Local Master Browser, and use it to set the name
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * of the Master Browser it queries for the server and domain lists.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Backup Browsers MUST periodically make a NetServerEnum2 request of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the Master Browser on its subnet for its domain to get a list of servers
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in that domain, as well as a list of domains. The period is a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * configuration option balancing currency of the information with network
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * traffic costs - a typical value is 15 minutes.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Backup Browser SHOULD force an election by sending a RequestElection
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * frame (see section 6.7) if it does not get a response to its periodic
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * NetServeEnum2 request to the Master Browser.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Backup Browser MUST receive and process NetServerEnum2 requests from
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * browser clients, for its own domain and others. If the request is for a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * list of servers in its domain, or for a list of domains, it can answer
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * from its internal lists. If the request is for a list of servers in a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * domain different than the one it serves, it sends a NetServerEnum2
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * request to the Domain Master Browser for that domain (which it can in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * find in its list of domains and their Domain Master Browsers).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Backup Browser MUST participate in browser elections (see section
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 6.8).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 4.4.3 Master Browser
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Master Browsers are responsible for:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . indicating it is a Master Browser
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . receiving server announcements and building a list of such servers
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and keeping it reasonably up-to-date.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . returning lists of Backup Browsers to browser clients.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . ensuring an appropriate number of Backup Browsers are available.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . announcing their existence to other Master Browsers on their subnet,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to the Domain Master Browser for their domain, and to all browsers in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * their domain on their subnet
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . forwarding requests for lists of servers on other domains to the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Master Browser for that domain
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . keeping a list of domains in its subnet
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . synchronizing with the Domain Master Browser (if any) for its domain
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . participating in browser elections
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . ensuring that there is only one Master Browser on its subnet
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser MUST set type SV_TYPE_MASTER_BROWSER (see section
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 6.4.1) in its HostAnnouncement until it is ready to shut down. In its
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * last HostAnnouncement frame before it shuts down, it SHOULD specify a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * type of 0.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser MUST receive and process HostAnnouncement frames from
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * servers, adding the server name and other information to its servers
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * list; it must mark them as "local" entries. Periodically, it MUST check
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * all local server entries to see if a server's HostAnnouncement has timed
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * out (no HostAnnouncement received for three times the periodicity the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * server gave in the last received HostAnnouncement) and remove timed-out
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * servers from its list.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser MUST receive and process DomainAnnouncement frames (see
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * section 6.12) and maintain the domain names and their associated (Local)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Master Browsers in its internal domain list until they time out; it must
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * mark these as "local" entries. Periodically, it MUST check all local
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * domain entries to see if a server's DomainAnnouncement has timed out (no
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * DomainAnnouncement received for three times the periodicity the server
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * gave in the last received DomainAnnouncement) and remove timed-out
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * servers from its list.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser MUST receive and process GetBackupListRequest frames
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * from clients, returning GetBackupListResponse frames containing a list
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * of the Backup Servers for its domain.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser MUST eventually send BecomeBackup frames (see section
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 6.9) to one or more Potential Browser servers to increase the number of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Backup Browsers if there are not enough Backup Browsers to handle the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * anticipated query load. Note: possible good times for checking for
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sufficient backup browsers are after being elected, when timing out
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * server HostAnnouncements, and when receiving a server's HostAnnouncement
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * for the first time.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser MUST periodically announce itself and the domain it
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * serves to other (Local) Master Browsers on its subnet, by sending a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * DomainAnnouncement frame (see section 6.12) to its subnet.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser MUST send a MasterAnnouncement frame (see section 6.11)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to the Domain Master Browser after it is first elected, and periodically
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * thereafter. This informs the Domain Master Browser of the presence of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * all the Master Browsers.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser MUST periodically announce itself to all browsers for
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * its domain on its subnet by sending a LocalMasterAnnouncement frame (see
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * section 6.10).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser MUST receive and process NetServerEnum2 requests from
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * browser clients, for its own domain and others. If the request is for a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * list of servers in its domain, or for a list of domains, it can answer
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * from its internal lists. Entries in its list marked "local" MUST have
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the SV_TYPE_LOCAL_LIST_ONLY bit set in the returned results; it must be
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * clear for all other entries. If the request is for a list of servers in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * a domain different than the one it serves, it sends a NetServerEnum2
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * request to the Domain Master Browser for that domain (which it can in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * find in its list of domains and their Domain Master Browsers).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Note: The list of servers that the Master Browser maintains and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * returns to the Backup Browsers, is limited in size to 64K of
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * data. This will limit the number of systems that can be in a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * browse list in a single workgroup or domain to approximately two
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * thousand systems.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser SHOULD request all servers to register with it by
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * sending an AnnouncementRequest frame, if, on becoming the Master Browser
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * by winning an election, its server list is empty. Otherwise, clients
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * might get an incomplete list of servers until the servers' periodic
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * registrations fill the server list.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the Master Browser on a subnet is not the Primary Domain Controller
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * (PDC), then it is a Local Master Browser.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Local Master Browser MUST periodically synchronize with the Domain
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Master Browser (which is the PDC). This synchronization is performed by
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * making a NetServerEnum2 request to the Domain Master Browser and merging
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the results with its list of servers and domains. An entry from the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Domain Master Browser should be marked "non-local", and must not
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * overwrite an entry with the same name marked "local". The Domain Master
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Browser is located as specified in Appendix B.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser MUST participate in browser elections (see section
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 6.8).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser MUST, if it receives a HostAnnouncement,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * DomainAnnouncement, or LocalMasterAnnouncement frame another system that
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * claims to be the Master Browser for its domain, demote itself from
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Master Browser and force an election. This ensures that there is only
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ever one Master Browser in each workgroup or domain.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Master Browser SHOULD, if it loses an election, become a Backup
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Browser (without being told to do so by the new Master Browser). Since
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * it has more up-to-date information in its lists than a Potential
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Browser, it is more efficient to have it be a Backup Browser than to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * promote a Potential Browser.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 4.4.3.1 Preferred Master Browser
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Preferred Master Browser supports exactly the same protocol elements
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * as a Potential Browser, except as follows.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Preferred Master Browser MUST always force an election when it starts
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * up.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Preferred Master Browser MUST participate in browser elections (see
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * section 6.8).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Preferred Master Browser MUST set the Preferred Master bit in the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * RequestElection frame (see section 6.7) to bias the election in its
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * favor.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A Preferred Master Browser SHOULD, if it loses an election,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * automatically become a Backup Browser, without being told to do so by
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the Master Browser.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 4.4.4 Domain Master Browser
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Since the Domain Master Browser always runs on the PDC, it must
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * implement all the protocols required of a PDC in addition to the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * browsing protocol, and that is way beyond the scope of this
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * specification.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 5. Mailslot Protocol Specification
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The only transaction allowed to a mailslot is a mailslot write. Mailslot
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * writes requests are encapsulated in TRANSACT SMBs. The following table
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * shows the interpretation of the TRANSACT SMB parameters for a mailslot
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * transaction:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Name Value Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Command SMB_COM_TRANSACTION
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Name <name> STRING name of mail slot to write;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * must start with "\\MAILSLOT\\"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SetupCount 3 Always 3 for mailslot writes
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Setup[0] 1 Command code == write mailslot
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Setup[1] Ignored
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Setup[2] Ignored
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * TotalDataCount n Size of data in bytes to write to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the mailslot
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Data[ n ] The data to write to the mailslot
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: C transact, File = \MAILSLOT\BROWSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: SMB Status = Error Success
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Error class = No Error
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Error code = No Error
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Header: PID = 0x0000 TID = 0x0000 MID = 0x0000 UID = 0x0000
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Tree ID (TID) = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Process ID (PID) = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: User ID (UID) = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Multiplex ID (MID) = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Flags Summary = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Command = C transact
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Word count = 17
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Word parameters
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Total parm bytes = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Total data bytes = 33
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Max parm bytes = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Max data bytes = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Max setup words = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Transact Flags Summary = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: ...............0 = Leave session intact
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: ..............0. = Response required
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Transact timeout = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Parameter bytes = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Parameter offset = 0 (0x0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Data bytes = 33 (0x21)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Data offset = 86 (0x56)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Setup word count = 3
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Setup words
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Mailslot opcode = Write mailslot
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Transaction priority = 1
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Mailslot class = Unreliable (broadcast)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Byte count = 50
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Byte parameters
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Path name = \MAILSLOT\BROWSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Transaction data
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SMB: Data: Number of data bytes remaining = 33 (0x0021)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 5. Mailslot Protocol Specification
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The only transaction allowed to a mailslot is a mailslot write. Mailslot
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * writes requests are encapsulated in TRANSACT SMBs. The following table
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * shows the interpretation of the TRANSACT SMB parameters for a mailslot
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * transaction:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Name Value Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Command SMB_COM_TRANSACTION
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Name <name> STRING name of mail slot to write;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * must start with "\MAILSLOT\"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SetupCount 3 Always 3 for mailslot writes
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Setup[0] 1 Command code == write mailslot
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Setup[1] Ignored
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Setup[2] Ignored
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * TotalDataCount n Size of data in bytes to write to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the mailslot
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Data[ n ] The data to write to the mailslot
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Magic 0xFF 'S' 'M' 'B'
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_com a byte, the "first" command
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Error a 4-byte union, ignored in a request
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_flg a one byte set of eight flags
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_flg2 a two byte set of 16 flags
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * . twelve reserved bytes, have a role
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in connectionless transports (IPX, UDP?)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_tid a 16-bit tree ID, a mount point sorta,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 0xFFFF is this command does not have
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or require a tree context
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_pid a 16-bit process ID
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_uid a 16-bit user ID, specific to this "session"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and mapped to a system (bona-fide) UID
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_mid a 16-bit multiplex ID, used to differentiate
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * multiple simultaneous requests from the same
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * process (pid) (ref RPC "xid")
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_browser_load_transact_header(unsigned char *buffer, int maxcnt,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb int data_count, int reply, char *mailbox)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_msgbuf_t mb;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int mailboxlen;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *fmt;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int result;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw short class = (reply == ONE_WAY_TRANSACTION) ? 2 : 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the mailboxlen is an even number we need to pad the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * header so that the data starts on a word boundary.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw fmt = "Mb4.bw20.bwwwwb.wl2.wwwwb.wwwws";
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw mailboxlen = strlen(mailbox) + 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((mailboxlen & 0x01) == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ++mailboxlen;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw fmt = "Mb4.bw20.bwwwwb.wl2.wwwwb.wwwws.";
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bzero(buffer, maxcnt);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_msgbuf_init(&mb, buffer, maxcnt, 0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw result = smb_msgbuf_encode(&mb, fmt,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw SMB_COM_TRANSACTION, /* Command */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0x18,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0x3,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 17, /* Count of parameter words */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0, /* Total Parameter words sent */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw data_count, /* Total Data bytes sent */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 2, /* Max Parameters to return */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0, /* Max data bytes to return */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0, /* Max setup bytes to return */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw reply, /* No reply */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0xffffffff, /* Timeout */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0, /* Parameter bytes sent */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0, /* Parameter offset */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw data_count, /* Data bytes sent */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 69 + mailboxlen, /* Data offset */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 3, /* Setup word count */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 1, /* Setup word[0] */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0, /* Setup word[1] */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw class, /* Setup word[2] */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw mailboxlen + data_count, /* Total request bytes */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw mailbox); /* Mailbox address */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_msgbuf_term(&mb);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (result);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_browser_addr_of_subnet(struct name_entry *name, smb_hostinfo_t *hinfo,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct name_entry *result)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t ipaddr, mask, saddr;
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright addr_entry_t *addr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (name == NULL)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (hinfo->hi_nic.nic_smbflags & SMB_NICF_ALIAS)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego ipaddr = hinfo->hi_nic.nic_ip.a_ipv4;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb mask = hinfo->hi_nic.nic_mask;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *result = *name;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw addr = &name->addr_list;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw do {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw saddr = addr->sin.sin_addr.s_addr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((saddr & mask) == (ipaddr & mask)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *result = *name;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw result->addr_list = *addr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw result->addr_list.forw = result->addr_list.back =
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &result->addr_list;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw addr = addr->forw;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } while (addr != &name->addr_list);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_browser_bcast_addr_of_subnet(struct name_entry *name, uint32_t bcast,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct name_entry *result)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (name != NULL && name != result)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *result = *name;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw result->addr_list.sin.sin_family = AF_INET;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw result->addr_list.sinlen = sizeof (result->addr_list.sin);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb result->addr_list.sin.sin_addr.s_addr = bcast;
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright result->addr_list.sin.sin_port = htons(IPPORT_NETBIOS_DGM);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw result->addr_list.forw = result->addr_list.back = &result->addr_list;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 6.5 HostAnnouncement Browser Frame
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * To advertise its presence, i.e. to publish itself as being available, a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * non-browser server sends a HostAnnouncement browser frame. If the server
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is a member of domain "D", this frame is sent to the NETBIOS unique name
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * D(1d) and mailslot "\\MAILSLOT\\BROWSE". The definition of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * HostAnnouncement frame is:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * struct {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * unsigned short Opcode;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * unsigned char UpdateCount;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * uint32_t Periodicity;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * unsigned char ServerName[];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * unsigned char VersionMajor;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * unsigned char VersionMinor;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * uint32_t Type;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * uint32_t Signature;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * unsigned char Comment[];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * where:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Opcode - Identifies this structure as a browser server
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * announcement and is defined as HostAnnouncement with a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * value of decimal 1.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UpdateCount - must be sent as zero and ignored on receipt.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Periodicity - The announcement frequency of the server (in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * seconds). The server will be removed from the browse list
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * if it has not been heard from in 3X its announcement
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * frequency. In no case will the server be removed from the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * browse list before the period 3X has elapsed. Actual
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * implementations may take more than 3X to actually remove
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the server from the browse list.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ServerName - Null terminated ASCII server name (up to 16 bytes
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in length).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * VersionMajor - The major version number of the OS the server
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is running. it will be returned by NetServerEnum2.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * VersionMinor - The minor version number of the OS the server
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is running. This is entirely informational and does not
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * have any significance for the browsing protocol.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Type - Specifies the type of the server. The server type bits
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * are specified in the NetServerEnum2 section.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Signature - The browser protocol minor version number in the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * low 8 bits, the browser protocol major version number in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the next higher 8 bits and the signature 0xaa55 in the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * high 16 bits of this field. Thus, for this version of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * browser protocol (1.15) this field has the value
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 0xaa55010f. This may used to isolate browser servers that
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * are running out of revision browser software; otherwise,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * it is ignored.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Comment - Null terminated ASCII comment for the server.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Limited to 43 bytes.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When a non-browser server starts up, it announces itself in the manner
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * described once every minute. The frequency of these statements is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * gradually stretched to once every 12 minutes.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Note: older non-browser servers in a domain "D" sent HostAnnouncement
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * frames to the NETBIOS group name D(00). Non-Browser servers supporting
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * version 1.15 of the browsing protocol SHOULD NOT use this NETBIOS name,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * but for backwards compatibility Master Browsers MAY receive and process
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * HostAnnouncement frames on this name as described above for D(1d).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic void
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_browser_send_HostAnnouncement(smb_hostinfo_t *hinfo,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb uint32_t next_announcement, boolean_t remove,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright addr_entry_t *addr, char suffix)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_msgbuf_t mb;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int offset, announce_len, data_length;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct name_entry dest_name;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char *buffer;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t type;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char resource_domain[SMB_PI_MAX_DOMAIN];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (smb_getdomainname(resource_domain, SMB_PI_MAX_DOMAIN) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as return;
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown (void) smb_strupr(resource_domain);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (addr == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Local master Browser */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_init_name_struct((unsigned char *)resource_domain, suffix,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0, 0, 0, 0, 0, &dest_name);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (smb_browser_bcast_addr_of_subnet(0, hinfo->hi_nic.nic_bcast,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb &dest_name) < 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_init_name_struct((unsigned char *)resource_domain, suffix,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0, 0, 0, 0, 0, &dest_name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw dest_name.addr_list = *addr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw dest_name.addr_list.forw = dest_name.addr_list.back =
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &dest_name.addr_list;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* give some extra room */
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright buffer = malloc(MAX_DATAGRAM_LENGTH * 2);
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright if (buffer == NULL) {
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright syslog(LOG_DEBUG, "smb browser: HostAnnouncement: %m");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw data_length = 1 + 1 + 4 + 16 + 1 + 1 + 4 + 4 +
7b59d02d2a384be9a08087b14defadd214b3c1ddjb strlen(hinfo->hi_nic.nic_cmnt) + 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb offset = smb_browser_load_transact_header(buffer,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw MAX_DATAGRAM_LENGTH, data_length, ONE_WAY_TRANSACTION,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb MAILSLOT_BROWSE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (offset < 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(buffer);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * A non-browser server SHOULD send a HostAnnouncement browser frame
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * specifying a type of 0 just prior to shutting down, to allow it to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * quickly be removed from the list of available servers.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright if (remove || (!smb_netbios_running()))
7b59d02d2a384be9a08087b14defadd214b3c1ddjb type = 0;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb else
7b59d02d2a384be9a08087b14defadd214b3c1ddjb type = hinfo->hi_type;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_msgbuf_init(&mb, buffer + offset, MAX_DATAGRAM_LENGTH - offset, 0);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw announce_len = smb_msgbuf_encode(&mb, "bbl16cbblls",
7b59d02d2a384be9a08087b14defadd214b3c1ddjb HOST_ANNOUNCEMENT,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb ++hinfo->hi_updatecnt,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw next_announcement * 60000, /* Periodicity in MilliSeconds */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_nbname,
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (uint8_t)hinfo->hi_version.sv_major,
fd9ee8b58485b20072eeef1310a88ff348d5e7fajoyce mcintosh (uint8_t)hinfo->hi_version.sv_minor,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb type,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb SMB_SERVER_SIGNATURE,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_nic.nic_cmnt);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (announce_len > 0)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) smb_netbios_datagram_send(&hinfo->hi_netname, &dest_name,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw buffer, offset + announce_len);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(buffer);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_msgbuf_term(&mb);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_browser_process_AnnouncementRequest(struct datagram *datagram,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *mailbox)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_hostinfo_t *hinfo;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb uint32_t next_announcement;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t delay = random() % 29; /* in seconds */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb boolean_t h_found = B_FALSE;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (strcmp(mailbox, MAILSLOT_LANMAN) != 0) {
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright syslog(LOG_DEBUG, "smb browser: wrong mailbox (%s)", mailbox);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright smb_netbios_sleep(delay);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_rdlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo = list_head(&smb_binfo.bi_hlist);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb while (hinfo) {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if ((hinfo->hi_nic.nic_ip.a_ipv4 &
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego hinfo->hi_nic.nic_mask) ==
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (datagram->src.addr_list.sin.sin_addr.s_addr &
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_nic.nic_mask)) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb h_found = B_TRUE;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb break;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo = list_next(&smb_binfo.bi_hlist, hinfo);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (h_found) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb next_announcement = hinfo->hi_nextannouce * 60 * 1000;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_browser_send_HostAnnouncement(hinfo, next_announcement,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright B_FALSE, &datagram->src.addr_list, NBT_MB);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_unlock(&smb_binfo.bi_hlist_rwl);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwvoid *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_browser_dispatch(void *arg)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct datagram *datagram = (struct datagram *)arg;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_msgbuf_t mb;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int rc;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char command;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char parameter_words;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short total_parameter_words;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short total_data_count;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short max_parameters_to_return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short max_data_to_return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char max_setup_bytes_to_return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short reply;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short parameter_bytes_sent;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short parameter_offset;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short data_bytes_sent;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short data_offset;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char setup_word_count;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short setup_word_0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short setup_word_1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short setup_word_2;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned short total_request_bytes;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char *mailbox;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char message_type;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw unsigned char *data;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int datalen;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright syslog(LOG_DEBUG, "smb browser: packet received");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_msgbuf_init(&mb, datagram->data, datagram->data_length, 0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smb_msgbuf_decode(&mb, "Mb27.bwwwwb.w6.wwwwb.wwwws",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &command, /* Command */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &parameter_words, /* Count of parameter words */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &total_parameter_words, /* Total Parameter words sent */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &total_data_count, /* Total Data bytes sent */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &max_parameters_to_return, /* Max Parameters to return */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &max_data_to_return, /* Max data bytes to return */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &max_setup_bytes_to_return, /* Max setup bytes to return */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &reply, /* No reply */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &parameter_bytes_sent, /* Parameter bytes sent */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &parameter_offset, /* Parameter offset */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &data_bytes_sent, /* Data bytes sent */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &data_offset, /* Data offset */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &setup_word_count, /* Setup word count */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &setup_word_0, /* Setup word[0] */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &setup_word_1, /* Setup word[1] */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &setup_word_2, /* Setup word[2] */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &total_request_bytes, /* Total request bytes */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &mailbox); /* Mailbox address */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc < 0) {
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright syslog(LOG_ERR, "smb browser: decode error");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_msgbuf_term(&mb);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(datagram);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw data = &datagram->data[data_offset];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw datalen = datagram->data_length - data_offset;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The PDC location protocol, i.e. anything on the \\NET
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * mailslot, is handled by the smb_netlogon module.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (strncasecmp("\\MAILSLOT\\NET\\", mailbox, 14) == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_netlogon_receive(datagram, mailbox, data, datalen);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_msgbuf_term(&mb);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(datagram);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If it's not a netlogon message, assume it's a browser request.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This is not the most elegant way to extract the command byte
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * but at least we no longer use it to get the netlogon opcode.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw message_type = datagram->data[data_offset];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (message_type) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case ANNOUNCEMENT_REQUEST :
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_browser_process_AnnouncementRequest(datagram, mailbox);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw default:
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright syslog(LOG_DEBUG, "smb browser: invalid message type(%d, %x)",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw message_type, message_type);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_msgbuf_term(&mb);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(datagram);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 11.1 Registered unique names
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * <COMPUTER>(00)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This name is used by all servers and clients to receive second
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * class mailslot messages. A system must add this name in order to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * receive mailslot messages. The only browser requests that should
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * appear on this name are BecomeBackup, GetBackupListResp,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * MasterAnnouncement, and LocalMasterAnnouncement frames. All other
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * datagrams (other than the expected non-browser datagrams) may be
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ignored and an error logged.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * <DOMAIN>(1d)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This name is used to identify a master browser server for domain
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * "DOMAIN" on a subnet. A master browser server adds this name as a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * unique NETBIOS name when it becomes master browser. If the attempt
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to add the name fails, the master browser server assumes that there
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is another master in the domain and will fail to come up. It may
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * log an error if the failure occurs more than 3 times in a row (this
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * either indicates some form of network misconfiguration or a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * software error). The only requests that should appear on this name
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * are GetBackupListRequest and HostAnnouncement requests. All other
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * datagrams on this name may be ignored (and an error logged). If
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * running a NETBIOS name service (NBNS, such as WINS), this name
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * should not be registered with the NBNS.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * <DOMAIN>(1b)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This name is used to identify the Domain Master Browser for domain
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * "DOMAIN" (which is also the primary domain controller). It is a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * unique name added only by the primary domain controller. The
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * primary domain controller will respond to GetBackupListRequest on
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * this name just as it responds to these requests on the <DOMAIN>(1d)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * name.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 11.2 Registered group names
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * (01)(02)__MSBROWSE__(02)(01)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This name is used by Master Browsers to announce themselves to the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * other Master Browsers on a subnet. It is added as a group name by
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * all Master Browser servers. The only broadcasts that should appear
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * on this name is DomainAnnouncement requests. All other datagrams
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * can be ignored.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * <DOMAIN>(00)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This name is used by clients and servers in domain "DOMAIN" to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * process server announcements. The only requests that should appear
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * on this name that the browser is interested in are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * AnnouncementRequest and NETLOGON_QUERY (to locate the PDC) packets.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * All other unidentifiable requests may be ignored (and an error
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * logged).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * <DOMAIN>(1E)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This name is used for announcements to browsers for domain "DOMAIN"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * on a subnet. This name is registered by all the browser servers in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the domain. The only requests that should appear on this name are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * RequestElection and AnnouncementRequest packets. All other
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * datagrams may be ignored (and an error logged).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * <DOMAIN>(1C)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This name is registered by Primary Domain Controllers.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_browser_config(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_hostinfo_t *hinfo;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct name_entry name;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct name_entry master;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct name_entry dest;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct name_entry *entry;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char resource_domain[SMB_PI_MAX_DOMAIN];
7b59d02d2a384be9a08087b14defadd214b3c1ddjb int rc;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (smb_browser_init() != 0)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (smb_getdomainname(resource_domain, SMB_PI_MAX_DOMAIN) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as return;
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown (void) smb_strupr(resource_domain);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* domain<00> */
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright smb_init_name_struct((unsigned char *)resource_domain, NBT_WKSTA,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0, 0, 0, 0, 0, &name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw entry = smb_name_find_name(&name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_name_unlock_name(entry);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_rdlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo = list_head(&smb_binfo.bi_hlist);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb while (hinfo) {
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright smb_init_name_struct((unsigned char *)resource_domain,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright NBT_WKSTA, 0, hinfo->hi_nic.nic_ip.a_ipv4,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright htons(IPPORT_NETBIOS_DGM), NAME_ATTR_GROUP,
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego NAME_ATTR_LOCAL, &name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) smb_name_add_name(&name);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo = list_next(&smb_binfo.bi_hlist, hinfo);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_unlock(&smb_binfo.bi_hlist_rwl);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* All our local master browsers */
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright smb_init_name_struct((unsigned char *)resource_domain, NBT_MB,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0, 0, 0, 0, 0, &dest);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw entry = smb_name_find_name(&dest);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (entry) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_rdlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo = list_head(&smb_binfo.bi_hlist);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb while (hinfo) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb rc = smb_browser_addr_of_subnet(entry, hinfo, &master);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (rc == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw syslog(LOG_DEBUG,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright "smb browser: master browser found at %s",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw inet_ntoa(master.addr_list.sin.sin_addr));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo = list_next(&smb_binfo.bi_hlist, hinfo);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_unlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_name_unlock_name(entry);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* Domain master browser */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_init_name_struct((unsigned char *)resource_domain,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright NBT_DMB, 0, 0, 0, 0, 0, &dest);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((entry = smb_name_find_name(&dest)) != 0) {
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright syslog(LOG_DEBUG,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright "smb browser: domain master browser for %s is %s",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw resource_domain,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw inet_ntoa(entry->addr_list.sin.sin_addr));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_name_unlock_name(entry);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic int
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_browser_init(void)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_hostinfo_t *hinfo;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_niciter_t ni;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb uint32_t type;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_version_t version;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States smb_config_get_version(&version);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_wrlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_browser_infofree();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (smb_nic_getfirst(&ni) != SMB_NIC_SUCCESS) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_unlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (-1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb type = MY_SERVER_TYPE;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (smb_config_get_secmode() == SMB_SECMODE_DOMAIN)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb type |= SV_DOMAIN_MEMBER;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb do {
8d7e41661dc4633488e93b13363137523ce59977jose borrego if ((ni.ni_nic.nic_smbflags & SMB_NICF_NBEXCL) ||
8d7e41661dc4633488e93b13363137523ce59977jose borrego (ni.ni_nic.nic_smbflags & SMB_NICF_ALIAS))
7b59d02d2a384be9a08087b14defadd214b3c1ddjb continue;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo = malloc(sizeof (smb_hostinfo_t));
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (hinfo == NULL) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_browser_infofree();
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_unlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (-1);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_nic = ni.ni_nic;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* One Minute announcements for first five */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_nextannouce = 1;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_interval = 1;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_reps = 5;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_updatecnt = 0;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_type = type;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States hinfo->hi_version = version;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* This is the name used for HostAnnouncement */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) strlcpy(hinfo->hi_nbname, hinfo->hi_nic.nic_host,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb NETBIOS_NAME_SZ);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown (void) smb_strupr(hinfo->hi_nbname);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* 0x20: file server service */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_init_name_struct((unsigned char *)hinfo->hi_nbname,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright NBT_SERVER, 0, hinfo->hi_nic.nic_ip.a_ipv4,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright htons(IPPORT_NETBIOS_DGM),
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright NAME_ATTR_UNIQUE, NAME_ATTR_LOCAL,
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego &hinfo->hi_netname);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb list_insert_tail(&smb_binfo.bi_hlist, hinfo);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_binfo.bi_hcnt++;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States } while (smb_nic_getnext(&ni) == SMB_NIC_SUCCESS);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_unlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_browser_non_master_duties
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * To advertise its presence, i.e. to publish itself as being available, a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * non-browser server sends a HostAnnouncement browser frame. If the server
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is a member of domain "D", this frame is sent to the NETBIOS unique name
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * D(1d) and mailslot "\\MAILSLOT\\BROWSE".
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic void
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_browser_non_master_duties(smb_hostinfo_t *hinfo, boolean_t remove)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct name_entry name;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct name_entry *dest;
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright addr_entry_t addr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw char resource_domain[SMB_PI_MAX_DOMAIN];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_browser_send_HostAnnouncement(hinfo, hinfo->hi_interval,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright remove, 0, NBT_MB);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (smb_getdomainname(resource_domain, SMB_PI_MAX_DOMAIN) != 0)
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as return;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown (void) smb_strupr(resource_domain);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright smb_init_name_struct((unsigned char *)resource_domain, NBT_MB,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw 0, 0, 0, 0, 0, &name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((dest = smb_name_find_name(&name))) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw addr = dest->addr_list;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw addr.forw = addr.back = &addr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_name_unlock_name(dest);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_browser_send_HostAnnouncement(hinfo, hinfo->hi_interval,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright remove, &addr, NBT_MB);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } else {
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright smb_init_name_struct((unsigned char *)resource_domain,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright NBT_DMB, 0, 0, 0, 0, 0, &name);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((dest = smb_name_find_name(&name))) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw addr = dest->addr_list;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw addr.forw = addr.back = &addr;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_name_unlock_name(dest);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_browser_send_HostAnnouncement(hinfo,
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright remove, hinfo->hi_interval, &addr, NBT_DMB);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * One Minute announcements for first five
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * minutes, one minute longer each round
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * until 12 minutes and every 12 minutes
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * thereafter.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (--hinfo->hi_reps == 0) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (hinfo->hi_interval < 12)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_interval++;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_reps = 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_nextannouce = hinfo->hi_interval;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright * SMB NetBIOS Browser Service
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*ARGSUSED*/
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwvoid *
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wrightsmb_browser_service(void *arg)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_hostinfo_t *hinfo;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_browser_infoinit();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smb_browser_config();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright smb_netbios_event(NETBIOS_EVENT_BROWSER_START);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjbrestart:
7b59d02d2a384be9a08087b14defadd214b3c1ddjb do {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_rdlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo = list_head(&smb_binfo.bi_hlist);
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright
7b59d02d2a384be9a08087b14defadd214b3c1ddjb while (hinfo) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (--hinfo->hi_nextannouce > 0 ||
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo->hi_nic.nic_bcast == 0) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo = list_next(&smb_binfo.bi_hlist, hinfo);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw continue;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_browser_non_master_duties(hinfo, B_FALSE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* Check to see whether reconfig is needed */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) mutex_lock(&smb_binfo.bi_mtx);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (smb_binfo.bi_changed) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_binfo.bi_changed = B_FALSE;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) mutex_unlock(&smb_binfo.bi_mtx);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_unlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_browser_config();
7b59d02d2a384be9a08087b14defadd214b3c1ddjb goto restart;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) mutex_unlock(&smb_binfo.bi_mtx);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo = list_next(&smb_binfo.bi_hlist, hinfo);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_unlock(&smb_binfo.bi_hlist_rwl);
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright smb_netbios_sleep(SECSPERMIN); /* 1 minute */
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright } while (smb_netbios_running());
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_browser_infoterm();
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright smb_netbios_event(NETBIOS_EVENT_BROWSER_STOP);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * smb_browser_netlogon
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * Sends SAMLOGON/NETLOGON request for all host/ips, except
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * aliases, to find a domain controller.
8d7e41661dc4633488e93b13363137523ce59977jose borrego *
8d7e41661dc4633488e93b13363137523ce59977jose borrego * The dc argument will be set if a DC is found.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
8d7e41661dc4633488e93b13363137523ce59977jose borregoboolean_t
8d7e41661dc4633488e93b13363137523ce59977jose borregosmb_browser_netlogon(char *domain, char *dc, uint32_t dc_len)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_hostinfo_t *hinfo;
8d7e41661dc4633488e93b13363137523ce59977jose borrego boolean_t found = B_FALSE;
8d7e41661dc4633488e93b13363137523ce59977jose borrego timestruc_t to;
8d7e41661dc4633488e93b13363137523ce59977jose borrego int err;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_rdlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo = list_head(&smb_binfo.bi_hlist);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb while (hinfo) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if ((hinfo->hi_nic.nic_smbflags & SMB_NICF_ALIAS) == 0)
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright smb_netlogon_request(&hinfo->hi_netname, domain);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb hinfo = list_next(&smb_binfo.bi_hlist, hinfo);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_unlock(&smb_binfo.bi_hlist_rwl);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego bzero(dc, dc_len);
8d7e41661dc4633488e93b13363137523ce59977jose borrego to.tv_sec = 30;
8d7e41661dc4633488e93b13363137523ce59977jose borrego to.tv_nsec = 0;
8d7e41661dc4633488e93b13363137523ce59977jose borrego (void) mutex_lock(&ntdomain_mtx);
8d7e41661dc4633488e93b13363137523ce59977jose borrego while (ntdomain_info.n_ipaddr == 0) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego err = cond_reltimedwait(&ntdomain_cv, &ntdomain_mtx, &to);
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (err == ETIME)
8d7e41661dc4633488e93b13363137523ce59977jose borrego break;
8d7e41661dc4633488e93b13363137523ce59977jose borrego }
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego if (ntdomain_info.n_ipaddr != 0) {
8d7e41661dc4633488e93b13363137523ce59977jose borrego (void) strlcpy(dc, ntdomain_info.n_name, dc_len);
8d7e41661dc4633488e93b13363137523ce59977jose borrego found = B_TRUE;
8d7e41661dc4633488e93b13363137523ce59977jose borrego }
8d7e41661dc4633488e93b13363137523ce59977jose borrego (void) mutex_unlock(&ntdomain_mtx);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (found);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * smb_browser_infoinit
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright * This function is called only once when the browser starts
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright * to initialize the global smb_binfo structure.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic void
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_browser_infoinit(void)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
8d7e41661dc4633488e93b13363137523ce59977jose borrego (void) mutex_lock(&ntdomain_mtx);
8d7e41661dc4633488e93b13363137523ce59977jose borrego bzero(&ntdomain_info, sizeof (ntdomain_info));
8d7e41661dc4633488e93b13363137523ce59977jose borrego (void) mutex_unlock(&ntdomain_mtx);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_wrlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb list_create(&smb_binfo.bi_hlist, sizeof (smb_hostinfo_t),
7b59d02d2a384be9a08087b14defadd214b3c1ddjb offsetof(smb_hostinfo_t, hi_lnd));
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_binfo.bi_hcnt = 0;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_unlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) mutex_lock(&smb_binfo.bi_mtx);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_binfo.bi_changed = B_FALSE;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) mutex_unlock(&smb_binfo.bi_mtx);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * smb_browser_infoterm
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright * This function is called only once when the browser stops
a0aa776e20803c84edd153d9cb584fd67163aef3Alan Wright * to destroy the smb_binfo structure.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic void
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_browser_infoterm(void)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_wrlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_browser_infofree();
7b59d02d2a384be9a08087b14defadd214b3c1ddjb list_destroy(&smb_binfo.bi_hlist);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (void) rw_unlock(&smb_binfo.bi_hlist_rwl);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * smb_browser_infofree
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * Removes all the hostinfo structures from the browser list
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * and frees the allocated memory
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic void
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_browser_infofree(void)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_hostinfo_t *hinfo;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb while ((hinfo = list_head(&smb_binfo.bi_hlist)) != NULL) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb list_remove(&smb_binfo.bi_hlist, hinfo);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb free(hinfo);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb smb_binfo.bi_hcnt = 0;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}