3.1 A Beautiful Day in the Network Neighborhood
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Where am I?" "In the Village." -- The Prisoner |
The houses are painted in cheerful colors, there are flowers in the window boxes, people greet you as you walk down the street, and the dogs never bark after sunset. It seems a lovely place in which to open a small teashop and perhaps, someday, retire. Before you decide to move in, though, there are a few things you probably need to know about the Network Neighborhood. Behind the picture-postcard facade there lies a complex political and social structure, collectively known as the Browse Service. Many people consider the Browse Service to be mysterious and secretive, perhaps because most of its business is handled discreetly, out of the view of the casual tourists. The Browse Service lurks in the background, gathering, maintaining, and distributing the Browse List--the list of available servers and workgroups. You can sneak a peek at the Browse List by clicking the Network Neighborhood icon on a Microsoft Windows desktop. If all is working as it should, you will be presented with a neatly organized graphical view of the available SMB filesharing environment. It will look something like the image in figure 3.1. By selecting icons you can traverse the SMB hierarchy and view workgroups, servers, print queues, shares, directories, and files. In CIFS terms, this is called "browsing" the network1. 3.1.1 History: From Frontier Town to Bustling MetropolisThe original Browse Service staked its claim alongside the
LANMAN1.0 dialect, back in the frontier days of OS/2. Its
descendants stayed on and prospered through the LM1.2X002 and
LANMAN2.1 days, and then quietly faded into legend. There
aren't many systems around today that still earn their keep by running
LAN Manager style browsing, as it is known, yet the legacy lives on.
Windows systems generally have a server configuration check-box to
enable LAN Manager browser announcements, and Samba has an
LM ANNOUNCE parameter for the same purpose.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
These are the conditions that prevail. -- Jimmy Durante |
When WindowsNT rode into town, it brought along a newfangled Browse Service. Like its predecessor, the new system was built upon the NetBIOS API. It was an improvement over the older version in that it could exchange and combine Browse Lists with remote Browsers on distant LANs, thus bringing the world a little closer together. That version of the Browse Service is the same one most folks still use today, and it is the one we will be studying in detail. Then came the Information Superhighway, and Windows2000 arrived in a bright blue limousine with a fancy new Browse Service hanging on its arm. The W2K browsing system is designed to run on naked TCP transport, and it is built on top of Active Directory and the LDAP protocol. As you may have come to expect by now, covering Directory Services is more than this book is trying to achieve so we won't spend a lot of time on W2K browsing. Besides, Windows2000 and WindowsXP are both backward-compatible with previous Windows versions, and can still support the older NetBIOS-based Windows Browse Service. Another thing that has changed since Windows2000 arrived is the name of the Network Neighborhood. These days, it is called "My Network Places". A discussion of the implications of the shift in metaphor from one relating the network environment to a cohesive and open community to one of self-centered virtual oligarchy is also way the heck beyond the scope of this book. 3.1.2 SociologyThe Browse Service, as was stated earlier, has a social structure. SMB servers and clients are expected to be members of cliques known as "workgroups" or "domains". The basic difference between a workgroup and a domain is that the latter provides central authentication services via Domain Controllers. Just to make life more interesting, there are two types of domain to consider:
A workgroup, quite simply, is defined by its NetBIOS name. The workgroup name is typically assigned in the node's configuration, although utilities like smbclient and toolkits like jCIFS allow the workgroup name to be specified at run-time. As with the node's machine name, the workgroup name is used as the basis for NetBIOS names that are actually registered--just add the appropriate suffix byte. Systems do not need to register any name based on the workgroup unless they are offering services to the workgroup as a whole. Some example workgroup names:
That just scratches the surface, and doesn't really tell us anything about NT Domains. Fully explaining what workgroups and NT Domains are all about and how the names listed above are used is something of a recursive problem because the sociology of the Browse Service is intertwined with the politics. 3.1.3 PoliticsOn the local level, the Windows Browse Service is a volunteer organization. Nodes that are willing and able to donate some memory and CPU cycles make themselves available to the community by registering a special NetBIOS group name with a suffix byte value of 0x1E, as shown in the table above. That name is then used to hold an election and choose a workgroup leader2. The election winner is given the title of "Master Browser", and it registers a unique NetBIOS name with a suffix byte value of 0x1D. It also registers the strangely-formatted group name "\x01\x02__MSBROWSE__\x02\x01" (that last '\x01' is actually the suffix byte). As you may recall from the rant in section 1.7, Microsoft's WINS server provides special handling for unique names with the 0x1D suffix. Though the Master Browser may register this name with the WINS server, WINS will deny knowledge of the name when queried. WINS also returns 255.255.255.255 in response to name queries for group names. Most third-party NBNS implementations behave the same way in order to be WINS-compatible. Two key things happen as a result:
This is highly unusual behavior for NetBIOS names but, on the plus side, each subnet in the Network Neighborhood gets to have its own elected leader. On the minus side, the Master Browsers cannot exchange information because they cannot talk to one another. Figure 3.2 shows three separate workgroups, all with the same base
name: "WORKGROUP". They are distinct because they
cannot exchange and combine Browse Lists. In order to bring these
three together, we need yet another special node: the "Domain
Master Browser".
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The Domain Master Browser (DMB) is the workgroup president. Unlike the democratically elected LMB, the DMB is appointed. The Network Manager (that's a human being) must select and configure a node to serve as DMB. The DMB will register the unique NetBIOS name workgroup<1B> to identify itself. Since the goal here is to bring together Browse Lists from separate subnets, there must also be an NBNS available so that all of the LMBs on all of the subnets can find the DMB. Figure 3.3 (which is, admittedly, a bit complex) shows a single, unified workgroup. Node AMOS has been designated to act as the NBNS, and node DENNY has been given the job of Domain Master Browser. Nodes TZUKE and MCSHEE are Local Master Browsers for their own subnets. They will query the NBNS for the name WORKGROUP<1B>, and then contact the DMB in order to exchange Browse Lists. Note that the DMB takes on the role of LMB on its own subnet. 3.1.3.1 When is a Workgroup not a Workgroup?A workgroup is not a workgroup when it is an NT Domain. The difference between a workgroup and an NT Domain is that the latter has a Domain Controller, which is an authentication server. The Domain Controller keeps track of usernames and passwords, and all of the SMB file servers within the NT Domain are expected to consult with the Domain Controller whenever a client sends a SESSION SETUP REQUEST SMB. In the Windows world, the DMB service is always offered by a Primary Domain Controller (PDC). The two are considered inseparable so, if you are using Windows, you must set up a PDC in order to offer DMB services, and vice versa. This is probably why the DMB is called a Domain Master Browser. Samba, on the other hand, lets you set up a DMB without the requirement that you also set up a PDC. Since DMB services do not, in fact, rely upon any NT Domain functionality the DMB can operate independently. On the other hand, if you do wish to set up a PDC, then the PDC node must also be the DMB--even with Samba. This latter restriction is a bit goofy. The reason for the requirement is that Microsoft's WINS (and, therefore, any WINS-compatible NBNS) provides special handling for a group name registered by the Domain Controllers. Consider the following table:
The goofy bit, which has been described elsewhere in this book, is that the WINS server keeps track of up to 25 IPs for the <1C> group name. WINS also ensures that the IP address of the node registering the <1B> name is always the first in the <1C> name's IP list. That last quirk is the only real linkage between the DMB and PDC names: Within the NBT namespace, the Primary Domain Controller is distinguished from the Backup Domain Controllers by the fact that it also runs the DMB service and, therefore, registers the <1B> name. This all brings up a small nomenclature problem: If there is a DMB running without a PDC (as Samba allows), is the result a workgroup or a domain? That situation was not anticipated by Microsoft, so the terminology doesn't quite work. (Can you call it a Domain Master Browser if there's no NT Domain?)
3.1.3.2 Delegating ResponsibilitySo far, we have described Local Master Browsers and Domain Master Browsers. There are two additional types to consider.
...and now we can explain that a "Browser" is any node that participates in the creation and maintenance of the Browse Service. As we have shown, browsers are categorized as Potential, Backup, Local Master, or Domain Master. Browser roles are cumulative, and the Domain Master is at the top of the heap. If the socio-political system seems overly complex, keep in mind that:
...all of which plays into the design of the Windows Browse Service. The key thing to remember is that the Local Master Browser (unless it is also the DMB) is a volunteer, and being a Browser is not its primary function. The LMB node is, most likely, running as an SMB server or desktop system, or doing some other work. Allowing the Browse Service to interfere with someone's word processing or spreadsheet recalculations would be a bad thing. So, on subnets with a lot of nodes, the LMB may select some of the Potential Browsers to act as Backup Browsers. When a client wants a copy of the Browse List, the LMB may direct the client to one or more Backup Browsers instead. The client will cache the IP addresses of the Backup Browsers, and from that point forward send all Browse List queries to one of those nodes. The Backup Browsers are also the most likely nodes to replace the current LMB if it goes down, and the backup copies of the Browse List that they maintain will ensure stability in the Network Neighborhood. 3.2 Meet the Neighbors
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
She cooks as good |
We started off with a brief overview of the history and socio-political structure of the Browse Service. Basic guidebook stuff. Now we will meet some of the local citizens, learn about their roles in society, and find out how they interact with one another on a personal level. We will introduce them to you one at a time so you can get to know them before you see them in action. Hopefully, that will help you feel more comfortable as you explore the backstreets of the Network Neighborhood. A quick note before we go visiting... The Browse Service is built on top of other CIFS services and protocols. Layered protocols have a habit of causing terminology confusion, particularly when the talk turns to "clients" and "servers". The thing to keep in mind is that everything is relative. In this case, everything is relative to the service being offered and the client making use of it. An SMB filesharing client may also be a Browse Service server, and a Browse Service server may also be a Browse Service client, and a Browse Service client...the permutations and combinations are practically (though not actually) endless. Don't let yourself get confused. To help abate the ensuing chaos a few new, context-specific terms will need to be defined as we go along. You may want to take notes. 3.2.1 Browse Service ClienteleThe Browse Service has two types of clients:
Think of it in terms of the classified advertising section of your local newspaper. Classifieds are available to people who have something to sell and also to people who are looking to buy. Both of these are clients of the newspaper. In some of the available documentation, systems that wish to announce services via the Browse List are referred to as "Non-Browser Servers". That's really icky terminology, since those systems could be [Potential|Backup|Local Master] Browsers as well. We will refer to nodes that announce services as "Providers", without trying to straighten out what kind of Browser nodes or SMB servers they may or may not be. To add a sense of symmetry, we will use the term "Consumer" to identify the other kind of Browse Service client--the kind that wants to find services on the network. So, for our purposes:
We promised to introduce the neighbors one at a time. Let's start with the Providers. 3.2.1.1 ProvidersProviders announce themselves to the Local Master Browser by periodically broadcasting a message called a HostAnnouncement Browser Frame. The message is sent as an IP broadcast so any NBT node could listen in, but the NBT destination given in the message header is the workgroup<1D> name, so the LMB is obviously the intended recipient. When a node first starts up, it generally announces itself once per minute. After it has been running for a while it will slow down, typically sending an announcement once every 12 minutes. Different implementations behave differently, of course, but the suggestion is that the Provider start with a delay of one minute and double the delay until it exceeds 12 minutes, at which point it should settle on 12 minute intervals. If a Provider stops announcing itself, its entry in the Browse List will (eventually) time out. The time out formula generally given in the documentation is three times the last known announcement period. In testing, however, some systems reported the Periodicity value incorrectly so it is probably safer to assume an announcement period of 12 minutes and use a fixed timeout value of (3 × 12) = 36 minutes. Providers can also remove themselves from the Browse List by
sending a HostAnnouncement message with an empty list of
services. This indicates to the LMB that the host is no longer
providing any services. If possible, a Provider should send an empty
HostAnnouncement Browser Frame when it shuts down.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
It's a beautiful day |
3.2.1.2 ConsumersIt is important to be polite when dealing with your local government. The LMB is your neighbor, after all, and the time it spends handling the Browse List is volunteer time (unless it is also the appointed DMB). It may have other responsibilities as well--a spouse, kids, a day job as a word processor or fileserver... If everyone in the neighborhood is constantly asking for help, the LMB may wish that it had never been elected. The polite thing for a Browse Service Consumer to do is to ask the LMB for a list of Backup Browsers. We will call this the "BB List" (short for Backup Browser List) to distinguish it from the Browse List. The Consumer should keep track of the BB List so that any time it needs an updated copy of the Browse List it can query one of the Browsers on that list. That's how the workload is distributed in the Network Neighborhood. Keeping in mind that Browse Service duties are cumulative, the LMB will probably include itself in the BB List. On small LANs there may not be any Backup Browsers hanging around, so the LMB may be the only Browser listed in the BB List. The request for the BB List is sent as a broadcast NBT datagram. The request message, as indicated in figure 3.4, is known as a GetBackupListRequest Browser Frame. If the Consumer does not receive a response to the initial request, it should try again a couple of times. If no reply is received at all, the client may call for a new election--once only--and then try again to get a BB list. It may be the case that there are no Potential Browsers on the LAN at all, resulting in no LMB and no local Browse List. Continually calling for new elections in this situation would be futile (and rude). ...but let's hope that there is an LMB and that it does respond. The reply from an LMB is known as a GetBackupListResponse Browser Frame. It is not sent as a broadcast. Instead, the response is sent back to the requester in a unicast datagram (in NBT terminology, a DIRECT UNIQUE DATAGRAM). ...and that's what it takes to find out where copies of the Browse List are kept. At this point in the proceedings the Consumer has obtained the NBT name of a Browser (a Backup Browser or the LMB), and is ready to send a query to obtain the Browse List. (See figure 3.5.) This step is a little more complex than the previous ones. The Browse List might be very large, in which case (recalling the limitations of the NBT Datagram Service) an NBT datagram might not be big enough to hold it all. So instead of using the Datagram Service the Browse List query is sent using the Remote Administration Protocol (RAP) which rides on top of the SMB_COM_TRANSACTION message (aka. SMBtrans). SMBtrans, in turn, allows for data transfers of up to 64K. 3.2.2 The Local Master BrowserIt's time to meet your elected officials. All Browser nodes register the workgroup<1E> NetBIOS name. The Local Master Browser, as you already know, identifies itself by registering two additional NetBIOS names: workgroup<1D> and MSBROWSE<01>. NetBIOS names represent communications end-points--services or applications that are using the NetBIOS API to listen for connections or messages--and on the other side of these particular names there is software waiting to hear the chatter of the Browse Service. The LMB has the following duties:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I'm lost. I have gone to look for myself. If I get back before I return, please ask me to wait. -- Sign on a cubewall |
3.2.3 Becoming a Backup BrowserA Potential Browser becomes a Backup Browser in one of three ways:
At the time that the Browse Service was created it may have been reasonable to be concerned about one computer bearing the brunt of all of the client requests, particularly on a LAN with a very large number of nodes. Today's computers are capable of handling the load and their own work without breaking a sweat. It would take an effort (a purposeful Denial of Service attack, for instance) to cause the LMB any real trouble. 3.2.4 Crossing the Street with the DMBBrowser roles are cumulative, as we keep saying, so the Domain Master Browser is also the Local Master Browser for its subnet and it must handle all of the duties of an LMB. One such duty is participation in local Browser Elections. Of course, since the DMB is the appointed workgroup president it is expected to win the election--which it will do because the election is rigged. More on that when we go into detail regarding the election process. The DMB listens on the workgroup<1B> name for (unicast) MasterAnnouncement messages from Local Master Browsers on remote subnets. It keeps track of these announcements and, periodically, it contacts the LMBs and asks for a new copy of their local Browse List. The DMB merges the local Browse Lists collected from the various LMBs (including its own) into a master Browse List for the entire workgroup. The LMBs, in turn, will periodically query the DMB and add the remote entries collected in the workgroup master list to their own local Browse Lists. That's how local LANs get a complete copy of the combined workgroup Browse List. The key to making this all work is the NBT Name Service, the
NetBIOS Name Server (NBNS) in particular.
The scattered LMBs use the NBNS (aka. WINS server) to find the
workgroup<1B> name, which is registered by the
DMB. Without that, cross-subnet browsing would not work because the
LMBs would be unable to announce themselves to the DMB, and would also
be unable to request copies of the DMB's master list.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Don't cross, don't cross, |
Note that B mode NBT nodes do not talk to the NBNS and, therefore, cannot find a remote Domain Master Browser. That's okay, though, because the scope of a B mode NBT LAN is limited to the local IP subnet anyway. Even if a B node could do cross-subnet browsing, it wouldn't (shouldn't) be able to connect to a server on a remote subnet. In contrast, P nodes must transact all of their Browse Service business directly with the Domain Master Browser. The NBT Scope available to a P node is the set of names it can resolve via the NBNS. It doesn't do broadcasts, so the only Browser node that it can find is the DMB because the DMB is the only Browser node with a name that can be properly resolved via the NBNS. M and H nodes have the best of both worlds. They can send broadcasts and use the NBNS to resolve names. Now that you have a basic idea of how this stuff works, think about what might have happened if Microsoft had correctly implemented group name handling in their WINS implementation and had also provided a working NetBIOS Datagram Distribution Server (NBDD). If they had done that, the broadcast datagrams used by the Browse Service--the announcements and election requests and such--would have reached the entire extent of the virtual NetBIOS LAN even if it spanned multiple subnets, even across WAN links and such. For better or worse, that would have changed the design and workings of the Browse Service entirely. 3.2.5 ElectionsBrowser elections are fun to watch. They have more in common with
the noise and chaos of a party convention than they do with an actual
election. The process is something of a shouting match, and the
winner is the last one left shouting at the end.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Starting an election is a lot like picking a fight. Some punk computer somewhere on the LAN sends out a challenge, called a RequestElection Browser Frame. The message lets all of the Potential Browsers on the LAN know how tough the sender thinks it is. (See figure 3.7.) The Potential Browsers respond by broadcasting their own RequestElection messages, also declaring how tough they think they are. The Potential Browsers don't really want to fight about it, though, so when they hear a RequestElection message from a node that is tougher than they are, they shut up. The specifics of the election criteria will be covered when the we study the browser frames in detail. Just to complete the fighting analogy, each transmission of a RequestElection message during a browser election is called a "round". There are typically four rounds because the eventual winner of the election will repeat its RequestElection message four times to ensure that all of its challengers have given up. Once the winner is confident in its victory it sends a LocalMasterAnnouncement Browser Frame, which has two purposes. First, it lets all of the Backup Browsers know where to find the LMB. Second, the LocalMasterAnnouncement message announces the end of the election. Any further RequestElection messages heard on the wire will signal a new Browser Election. Elections can be forced by sending an empty RequestElection Browser Frame. That is, one that announces the sender as being a complete wimp. All of the Potential Browsers on the LAN will have better credentials, so they will try to respond. Elections may be called when a Consumer can no longer find the LMB, or when a new node joins the workgroup and thinks that it has what it takes to be the LMB. When a Domain Master Browser starts up, for instance, it will always call for elections (since it must take over the role of LMB). The RequestElection message is another NBT broadcast datagram. It is meant to be sent to the workgroup<1E> name but it turns out that many clients will accept this message if it is sent to the MSBROWSE<01> name as well, so you can actually cause all of the workgroups on a single subnet to hold elections at the same time. 3.3 Infrastructure: The Mailslot and Named Pipe AbstractionsWe touched on the Mailslots and Named Pipes back in section 2.9.4.1, and then we pulled our collective hand away really fast as if those subjects were much too hot to handle. We will need to be brave and give them another go, though, because the Browse Service relies on them. Sorry 'bout that, folks. Mailslots and Named Pipes are like the wiring and plumbing in an old house4. It probably all made sense when it was installed, but over the years new construction has built upon the old. Some parts have been re-used, some replaced, and other bits and pieces recycled in ways that make it seem as though no one remembers their original purpose. As long as it looks good on the surface (and isn't a fire hazard), it's okay. ...and it really is okay. The old stuff has held up remarkably well. So well, in fact, that it is sometimes forgotten--which is exactly why we need to take a closer look at it. The goal here is to provide a basic understanding of the Named Pipe and Mailslot concepts. We won't be going in too deep. If you want, you can find more detail in the X/Open book IPC Mechanisms for SMB. Named Pipes and Mailslots are nifty constructs, and are worthy of further study when you have the time. 3.3.1 Meet the Plumbing: Named PipesAs you are by now well aware, SMB is a protocol that implements a network filesystem and, of course, a network filesystem is the result of extrapolating the general concepts that lie behind a disk-based filesystem. The difference is that the network variety uses higher level protocols to stretch things out across a network. Some disk-based filesystems (such as those used in Unix and its kin) can handle the inclusion of objects that aren't really files at all, but which--through the use of some clever abstraction layers--can be made to look and work like files. For those familiar with such things, common examples include device nodes, the contents of /proc, and Named Pipes. We are interested in the latter. A Named Pipe is, at its heart, an interprocess communications channel. It allows two programs running independently to exchange messages. The SMB protocol, as you have already guessed, provides support for Named Pipes, but it can stretch them out over the network so that programs on different machines can talk to one another. A Named Pipe is "named" so that it can be identified by the programs that want to use it. It is a "pipe" because data is shoved in at one end and then falls gracefully out the other. CIFS Named Pipes have some additional qualities:
These features make CIFS Named Pipes ideal for transporting network function calls, which is one of the key ways (but not the only way) they are used. The Remote Administration Protocol (RAP) and Microsoft's Remote Procedure Call implementation (MS-RPC) are both built on top of Named Pipes. Although they are filesystem abstractions, CIFS Named Pipes are kept separate from the real files and directories made available by the SMB Server Service. They are placed in a special share--the IPC$ share--which is "hidden". You won't be able to browse to it using the Windows Network Neighborhood tool. If you know it's there, however, you can access it just as you would any other SMB share. Specifically, by sending a SESSION SETUP followed by a TREE CONNECT.
Named Pipes within the IPC$ share have names that match the following format: \PIPE\pipename ...where pipename is determined by the service that created the pipe. Because they are filesystem abstractions, it would be logical to assume that the full name of a Named Pipe (in UNC format) would look something like this: \\server\IPC$\PIPE\pipename As it turns out, however, the DOS, OS/2, and Windows functions that manipulate Named Pipes abbreviate the name by removing "\IPC$" from the string, which gives: \\server\PIPE\pipename Named Pipes are created on the SMB server side by applications and tools that are willing to provide specialized services. The architecture is quite analogous to services that register NetBIOS names to make themselves available, it's just that there are more intervening protocol layers which provide additional features. For example, Named Pipes can take advantage of the SMB authentication and MAC signing mechanisms. Microsoft has created several services that use Named Pipes, but the set of services that are actually available will vary depending upon the host OS and/or the CIFS implementation. Luke K. C. Leighton's book DCE/RPC over SMB: Samba and Windows NT Domain Internals (which we have referenced often) lists several known pipes that offer services based on MS-RPC. Our particular interest, however, is with the specific Named Pipe that will connect us to the Remote Administration Protocol service. That pipe is: \PIPE\LANMAN We will be using it a little later on, when we dig into the one RAP function that is commonly used by the Browser Service: the NetServerEnum2 function. ...and that is really all we have to say about CIFS Named Pipes. There is, of course, a lot more that could be said. Named Pipes can be used in a variety of ways to support a variety of different kinds of operations. Our goal, however, is to explore the Browse Service, so the scope of this discussion is purposfully limited. 3.3.2 The Mailslot MetaphorCIFS supports two kinds of Mailslot:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Mailslots, like Named Pipes, exist within the IPC$ share. Mailslot names have a familiar format, as shown below.
The Browse Service uses Class 2 Mailslots extensively. With the exception of the NetServerEnum2 RAP call, all Browse Service announcements and requests are sent using Class 2 Mailslots. In general, if the destination is local a Browse Service Mailslot message will be sent as a broadcast at the IP level. Unicast UDP datagrams are used if the destination is on a remote subnet (eg., a remote DMB). Broadcast messages that contain an NBT group name in the DESTINATION_NAME field are considered Multicast at the NBT level. If the DESTINATION_NAME is unique, the message may still be broadcast to avoid the need to resolve the name using the NBT Name Service. As suggested in figure 3.9, the receiver of a broadcast datagram should discard the message if it is not listening on the DESTINATION_NAME or the given Mailslot name. Class 2 Mailslot messages are kind of quirky. Even though they use the NBT Datagram Service, they are formatted as SMB_COM_TRANSACTION (that is, SMBtrans) messages. That's right: SMB over UDP. Go figure. This may be the result of someone being overly enthusiastic about re-using existing code. In any case, it means that we will be learning how to format an SMBtrans message.
3.4 The Talk on the Street
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Seems whatever I do, I do to the extreme. -- Bring the Rain Judie Tzuke |
Enough descriptive hyperbole. Let's get to work. SMBtrans is an SMB message with the SMB_COM_TRANSACTION command byte specified in the header. It is also the transport for all Browse Service messages. The on-the-wire layout of the body of the SMBtrans, in C-style notation, is as follows: typedef struct { uchar WordCount; /* SetupCount + 14 */ struct /* SMB-layer parameters */ { ushort TotalParamCount; /* Total param bytes to send */ ushort TotalDataCount; /* Total data bytes to send */ ushort MaxParameterCount; /* Max param bytes to return */ ushort MaxDataCount; /* Max data bytes to return */ ushort MaxSetupCount; /* Max setup words to return */ ushort Flags; /* Explained below */ ulong Timeout; /* Operation timeout */ ushort Reserved; /* Unused word */ ushort ParameterCount; /* Param bytes in this msg */ ushort ParameterOffset; /* Param offset within SMB */ ushort DataCount; /* Data bytes in this msg */ ushort DataOffset; /* Data offset within SMB */ ushort SetupCount; /* Setup word count */ ushort Setup[]; /* Setup words */ } Words; ushort ByteCount; /* Number of SMB data bytes */ struct /* SMB-layer data */ { uchar Name[]; /* Transaction service name */ uchar Pad[]; /* Pad to word boundary */ uchar Parameters[]; /* Parameter bytes */ uchar Pad1[]; /* Pad to word boundary */ uchar Data[]; /* Data bytes */ } Bytes; } smb_Trans_Req; We can, in fact, make some sense of all that. ...really we can. 3.4.1 Making Sense of SMBtransAs has already been pointed out, we are dealing with layered protocols and layered protocols can cause some terminology confusion. For example, earlier in the book SMB messages were described as having a header, a parameter section, and a data section. (...and there was a cute picture of an insect to highlight the anatomy.) SMB transactions--half a protocol layer up--also have parameters and data. The terms get recycled, as demonstrated by the structure presented above in which the Parameters[] and Data[] fields are both carried within the SMB_DATA block (the Bytes) of the SMB message. SMB transaction messages generally represent some sort of network function call. In an SMB transaction:
That's a very general description, and it may be slightly inaccurate in practice. It works well enough in theory, though, and it provides a conceptual foothold. If you want, you can go one step further and think of the SetupCount and Setup[] fields as the transaction header. Okay, now that we have that out of the way, here's what the SMBtrans fields are all about:
There is a lot more information in both the X/Open documentation and the Leach/Naik CIFS drafts. For some reason, specific details regarding SMBtrans were left out of the SNIA doc, although there is a discussion of Mailslots and Named Pipes (and the other transaction types are covered). All of the listed docs do explain how secondary transaction messages may be used to transfer Setup[], Parameter[], and/or Data[] blocks that are larger than the allowed SMB buffer size. There are also some warnings given in the SNIA doc regarding variations in implementation. It seems you need to be careful with CIFS (no surprise there). See the last paragraph of section 3.15.3 in the SNIA doc if'n your curious. ...but now it's time for some code. Listing 3.1 is a bit dense, but it does a decent job of putting together an SMBtrans message from parts. It doesn't fill in the NBT or SMB headers, but there are code examples and descriptions elsewhere in the book that cover those issues. What it does do is provide a starting point for managing SMBtrans transactions, particularly those that might exceed the server's SMB buffer limit and need to be fragmented. The smb_Transaction_Request structure in the listing differs from the wire-format version. The former is designed to keep track of a transaction while it is being built and until it has been completely transmitted. With a little more code, it should be able to compose secondary transaction messages too. Fortunately, all of the Browse Service requests are small enough to fit into a typical SMB buffer, so you shouldn't have to worry about sending secondary SMB transaction messages. At least not right away. On the other hand, a Browse Server's reply to a NetServerEnum2 call can easily exceed the SMB buffer size so you may need to know how to rebuild a fragmented response. With that in mind, we will explain how multi-part messages work when we cover NetServerEnum2. It is probably worth noting, at this point, just how many layers of abstraction we're dealing with. If you look at a packet capture of an NetServerEnum2 request, you'll find that it is way the heck down at the bottom of a large pile: Ethernet II + IP + TCP + NBT Session Service + SMB (SMB_COM_TRANSACTION) + SMB Pipe Protocol + Microsoft Windows Remote Administration Protocol + NetServerEnum2 It sure is getting deep around here... All those layers make things seem more complicated than they really are, but if we chip away at it one small workable piece at a time it will all be easier to understand. 3.4.2 Browse Service Mailslot MessagesThe vast bulk of the Browser Protocol consists of Mailslot messages. These are also relatively simple, which is why we are starting with them instead of RAP. Still, there are a lot of layers to go through in order to get a Mailslot message out onto the wire. Let's get chipping...
A few more general notes about Mailslot messages before we forge ahead...
Yet one more additional general note regarding Mailslot messages: the first byte of the Data block is always an OpCode indicating which of the \MAILSLOT\BROWSE (or \MAILSLOT\LANMAN) functions is being called. Here's a list of the available functions:
The next step is to describe each of those functions. 3.4.2.1 Announcement RequestThe AnnouncementRequest frame is fairly simple, so it's a good place to start. The message structure (carried in the smb_Trans_Req.Bytes.Data section) looks like this: struct { uchar OpCode; uchar Unused; uchar *ResponseName; } AnnouncementRequest; Which means that the AnnouncementRequest frame is made up of an OpCode, an unused byte, and a character string. (The unused byte may have been reserved for use as a flags field at one time.) The following values are assigned: NBT_Datagram { MsgType = 0x11 (DIRECT_GROUP DATAGRAM) SourceName = machine<00> DestinationName = workgroup<00> } smb_Transaction_Request { TotalDataCount = 3 + strlen( ResponseName ) Name = "\MAILSLOT\BROWSE" Data { OpCode = 0x02 (AnnouncementRequest) ResponseName = <NetBIOS machine name, no suffix> } } This frame may also be sent to the MSBROWSE<01> name to request responses from LMBs for foreign workgroups. The TotalDataCount is calculated by adding:
Don't forget those string terminators. There is no direct reply to this request, so the SourceName and ResponseName fields in the packet are ignored. Providers that receive this message are expected to broadcast a HostAnnouncement frame (described next) to re-announce their services. They are supposed to wait a random amount of time between 0 and 30 seconds before sending the announcement, to avoid network traffic congestion. In testing, however, many systems ignored this message. Under the older LAN Manager style browsing, a similar message was sent to the \MAILSLOT\LANMAN Mailslot. The LAN Manager AnnounceRequest and Announce frame formats are described in section 5.3.3 of the X/Open doc IPC Mechanisms for SMB. 3.4.2.2 Host AnnouncementThe HostAnnouncement is a bit more complicated than the AnnouncementRequest. Here's its structure: struct { uchar Opcode; uchar UpdateCount; ulong Periodicity; uchar *ServerName; uchar OSMajorVers; uchar OSMinorVers; ulong ServerType; uchar BroMajorVers; uchar BroMinorVers; ushort Signature; uchar *Comment; } HostAnnouncement; ...and here's how it all pans out: NBT_Datagram { MsgType = 0x11 (DIRECT_GROUP DATAGRAM) SourceName = machine<00> DestinationName = workgroup<1D> } smb_Transaction_Request { TotalDataCount = 18 + strlen( ServerName + Comment ) Name = "\MAILSLOT\BROWSE" Data { OpCode = 0x01 (HostAnnouncement) UpdateCount = <Incremented after each announcement> Periodicity = <Time until next announcement, in ms> ServerName = <NetBIOS machine name, no suffix> OSMajorVers = 4 <Windows OS version to mimic> OSMinorVers = 5 <Windows OS point version to mimic> ServerType = <Discussion below> BroMajorVers = 15 BroMinorVers = 1 Signature = 0xaa55 Comment = <Server description, max 43 bytes> } } That needs a once-over. The announcement is broadcast at the IP level, but the DestinationName is the local LMB name so the message should only be picked up by the Local Master. Other nodes could, in theory, listen in and keep their own local Browse List copies up-to-date. The Leach/Naik Browser Draft says that the UpdateCount should be zero and should be ignored by recipients. In practice, it appears that many systems increment that counter for each HostAnnouncement frame that they send. No harm done. The Periodicity field announces the amount of time, in milliseconds, that the sender plans to wait until it sends another HostAnnouncement frame. As described earlier, the initial period is one minute, but it doubles for each announcement until it would exceed 12 minutes, at which point it is pegged at 12 minutes. In theory, the LMB should remove a host from the Browse List if it has not heard an update from that host after 3 periods have elapsed. In practice, some systems get this value wrong so the LMB should wait 36 minutes. The ServerType field is a complex bitmap. We will dissect it later, as it is also used by the NetServerEnum2 RAP call. The Browser version number (15.1) and the Signature field are specified in the Leach/Naik Browser draft. Some Windows systems (particularly the Windows9x family) use a Browser version number of 21.4. No one, it seems, knows why and it doesn't appear that there are any protocol differences between the two versions. 3.4.2.3 Election RequestThe RequestElection frame is used to start or participate in a Browser Election. It looks like this: struct { uchar Opcode; uchar Version; ulong Criteria; ulong UpTime; ulong Reserved; uchar *ServerName; } RequestElection; In its simplest form, the RequestElection can be filled in with zeros. This gives it the lowest possible election criteria. All Potential Browsers in the same workgroup on the same LAN will be able to out-bid the zero-filled request, so a full-scale election will ensue as all Potential Browsers are eligible to participate. NBT_Datagram { MsgType = 0x11 (DIRECT_GROUP DATAGRAM) SourceName = machine<00> DestinationName = workgroup<1E> } smb_Transaction_Request { TotalDataCount = 15 Name = "\MAILSLOT\BROWSE" Data { OpCode = 0x08 (RequestElection) } } In testing, it was discovered that some Potential Browsers are willing to receive RequestElection frames on just about any registered NetBIOS name, including the MSBROWSE<01> name. Once the election gets going, the particpants will all try to out-vote their competition. The details of the election process are convoluted, so they will be set aside for just a little while longer. In the mean time, here is a complete election message, with election criteria filled in. NBT_Datagram { MsgType = 0x11 (DIRECT_GROUP DATAGRAM) SourceName = machine<00> DestinationName = workgroup<1E> } smb_Transaction_Request { TotalDataCount = 15 + strlen( ServerName ) Name = "\MAILSLOT\BROWSE" Data { OpCode = 0x08 (RequestElection) Version = 1 Criteria = <Another complex bitmap> UpTime = <Time since last reboot, in milliseconds> ServerName = <NetBIOS machine name, no suffix> } } The Criteria bitmap will be covered along with the election details. Basically, though, it is read as an unsigned long integer and higher values "win". 3.4.2.4 Get Backup List RequestAnother simple one. The message looks like this: struct { uchar OpCode; uchar ReqCount; ulong Token; } GetBackupListRequest; The Ethereal Network Protocol Analyzer and its many authors should be given a good heaping helping of appreciation just about now. The primary reference for the Browse Service data structures is the expired Leach/Naik Browser Internet Draft, but that document was a draft and is now expired. It cannot be expected that it will be completely accurate. It doesn't include the ReqCount field in its description, and it lists the Token as an unsigned short. That doesn't match what's on the wire. Thankfully, Ethereal knows better. NBT_Datagram { MsgType = 0x11 (DIRECT_GROUP DATAGRAM) SourceName = machine<00> DestinationName = workgroup<1D> } smb_Transaction_Request { TotalDataCount = 6 Name = "\MAILSLOT\BROWSE" Data { OpCode = 0x09 (GetBackupListRequest) ReqCount = <Number of browsers requested> Token = <Whatever> } } The ReqCount field lets the LMB know how large a list of Backup Browsers the client (the Consumer) would like to receive. The Token field is echoed back by the LMB when it sends the GetBackupListResponse. Echoing back the Token is supposed to let the Consumer match the response to the request. This is necessary because the SourceName in the GetBackupListResponse is generally the LMB's machine name, so there is nothing in the response that indicates the workgroup. If the Consumer is trying to query multiple workgroups it could easily lose track. 3.4.2.5 Get Backup List ResponseThis message is sent in response (but not as a reply) to a GetBackupListRequest. The structure is fairly straight-forward: struct { uchar OpCode; uchar BackupCount; ulong Token; uchar *BackupList; } GetBackupListResponse; NBT_Datagram { MsgType = 0x10 (DIRECT_UNIQUE DATAGRAM) SourceName = machine<00> DestinationName = <Source name from the request> } smb_Transaction_Request { TotalDataCount = 7 + <length of BackupList> Name = "\MAILSLOT\BROWSE" Data { OpCode = 0x0A (GetBackupListResponse) BackupCount = <Number of browser names returned> Token = <Echo of the request Token> BackupList = <List of Backup Browsers, nul-delimited> } } At the IP level this message is unicast, and at the NBT level it is sent as a DIRECT_UNIQUE DATAGRAM. This is the closest thing to a Mailslot "reply" that you'll see. The Token is a copy of the Token that was sent in the GetBackupList Request that triggered the response. The BackupCount value represents the number of names listed in the BackupList field, which may be less than the number requested. The BackupList will contain a string of nul-delimited substrings. For example, you might get something like this: Data { OpCode = 0x0A (GetBackupListResponse) BackupCount = 2 Token = 0x61706C65 BackupList = "STEFFOND\0CONRAD" } ...which indicates that nodes STEFFOND and CONRAD are both Backup Browsers (and one of them may also be the LMB) for the workgroup. Oh... that string is, of course, nul-terminated as well. Note that you can't use a normal strlen() call to calculate the length of the BackupList. It would just return the length of the first name. 3.4.2.6 Local Master AnnouncementThe LocalMasterAnnouncement is broadcast by the Local Master Browser. Other nodes, particularly Backup Browsers, can listen for this message and use it to keep track of the whereabouts of the LMB service. If the Local Master Browser for a workgroup hears another node announce itself as the LMB for the same workgroup, then it can call for a new election. This message is also used to end a Browser Election. The winner
declares itself by sending a LocalMasterAnnouncement frame.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There's talk on the street it sounds so familiar -- New Kid In Town Eagles |
The LocalMasterAnnouncement is identical in structure to the HostAnnouncement frame except for its OpCode: smb_Transaction_Request { Data { OpCode = 0x0F (LocalMasterAnnouncement) } } The Leach/Naik draft says that LMBs do not need to send HostAnnouncement frames because the LocalMasterAnnouncement accomplishes the same thing. The real reason that the LMB doesn't need to send HostAnnouncement frames is that HostAnnouncement frames are sent to the LMB, and there's no reason for an LMB to announce itself to itself. 3.4.2.7 Master AnnouncementThe MasterAnnouncement is sent by the LMB to the DMB to let the DMB know that the LMB exists. The message contains the OpCode field and the SMB Server Service name of the LMB. The Server Service name will be registered with the NBNS, so the DMB will be able to look it up as needed. struct { uchar OpCode; uchar *ServerName; } MasterAnnouncement; NBT_Datagram { MsgType = 0x10 (DIRECT_UNIQUE DATAGRAM) SourceName = machine<00> DestinationName = workgroup<1B> } smb_Transaction_Request { TotalDataCount = 2 + strlen( ServerName ) Name = "\MAILSLOT\BROWSE" Data { OpCode = 0x0D (MasterAnnouncement) ServerName = <NetBIOS machine name, no suffix> } } When the DMB receives a MasterAnnouncement, it should perform a NetServerEnum2 synchronization with the LMB. It should also keep track of remote LMBs in its workgroup and periodically (every 15 minutes) synchronize Browse Lists with them. Likewise, an LMB will periodically query the DMB. This is how the Browse List is propagated across multiple subnets. Note that this message is unicast. A broadcast datagram would not reach a remote DMB. 3.4.2.8 Domain AnnouncementThe DomainAnnouncement has the same structure as the HostAnnouncement and LocalMasterAnnouncement frames. The difference is in the content. The DomainAnnouncement is sent to the MSBROWSE<01> name, so that all of the foreign LMBs on the subnet will receive it. Instead of the NetBIOS machine name, the ServerName field contains the workgroup name. The NetBIOS machine name is also reported, but it is placed into the Comment field. NBT_Datagram { MsgType = 0x11 (DIRECT_GROUP DATAGRAM) SourceName = machine<00> DestinationName = "\01\02__MSBROWSE__\02<01>" } smb_Transaction_Request { TotalDataCount = 18 + strlen( ServerName + Comment ) Name = "\MAILSLOT\BROWSE" Data { OpCode = 0x0C (DomainAnnouncement) UpdateCount = <Incremented after each announcement> Periodicity = <Time until next announcement, in ms> ServerName = <NetBIOS workgroup name, no suffix> OSMajorVers = 4 <Windows OS version to mimic> OSMinorVers = 5 <Windows OS point version to mimic> ServerType = <Discussion below> BroMajorVers = 15 BroMinorVers = 1 Signature = 0xaa55 Comment = <LMB NetBIOS machine name, no suffix> } } A note of caution on this one. Some Windows systems send what appears to be garblage in the BroMajorVers, BroMinorVers, and Signature fields. Ethereal compensates by combining these three into a single longword which it calls "Mysterious Field". 3.4.2.9 Become Backup RequestThis message is sent by the LMB when it wants to promote a Potential Browser to Backup Browser status. struct { uchar OpCode; uchar *BrowserName; } BecomeBackupRequest; NBT_Datagram { MsgType = 0x11 (DIRECT_GROUP DATAGRAM) SourceName = machine<00> DestinationName = workgroup<1E> } smb_Transaction_Request { TotalDataCount = 2 + strlen( BrowserName ) Name = "\MAILSLOT\BROWSE" Data { OpCode = 0x0B (BecomeBackupRequest) BrowserName = <NetBIOS machine name of promoted node> } } The message is an NBT multicast datagram sent to all Potential Browsers in the workgroup. The BrowserName field contains the name of the node that is being promoted (no suffix byte). That node will respond by sending a new HostAnnouncement frame and obtaining a fresh copy of the Browse List from the LMB. The newly promoted Backup Browser should refresh its Browse List copy every 15 minutes. 3.4.2.10 The Undocumented ResetIt is difficult to find documentation on this message--it's not written up in the Leach/Naik draft--but there is some information hiding around the web if you dig a little. ...and, of course, we're describing it here. Big things come in small packages. Here's the ResetBrowserState frame: struct { uchar OpCode; uchar Command; } ResetBrowserState; Not much to it, but it can have an impact. This is how it's filled in: NBT_Datagram { MsgType = 0x11 (DIRECT_GROUP DATAGRAM) SourceName = machine<00> DestinationName = workgroup<1D> } smb_Transaction_Request { TotalDataCount = 2 Name = "\MAILSLOT\BROWSE" Data { OpCode = 0x0E (ResetBrowserState) Command = <Bitfield - see below> } } The ResetBrowserState message can mess with a Local Master Browser's mind. There are three bits defined for the Command field, and here's what they do:
3.4.2.11 It's All In The DeliveryWould a little more code be useful? The code gets rather dull at this level because all we are really doing is packing and unpacking bytes. Unfortunately, that's what network protocols are all about. Not very glamorous, is it? Listing 3.2 packs a RequestElection message into a byte block so that it can be handed to the smb_TransRequest() function via the smb_Transaction_Request structure. Sending election requests to a busy LAN can be kinda fun...and possibly a little disruptive. 3.4.3 RAPtureUnderstand this at the outset: examining a function of the RAP protocol is like studying the runic carvings on the lid of Pandora's box. They might just be large friendly letters...or they could be the manufacturer's warning label. We are not going to open the box. The NetServerEnum2 function can be implemented without having to fully understand the inner workings of RAP, so there really is no need. If you want to, you can rummage around in the RAP functions by reading through Appendix B of the X/Open book Protocols for X/Open PC Interworking: SMB, Version 2. After that, there is yet again another additional further Leach/Naik draft already. You can find the Leach/Naik CIFS Remote Administration Protocol Preliminary Draft under the filename cifsrap2.txt on Microsoft's FTP server. It is definitely a draft, but it provides a lot of good information if you read it carefully. One more resource a die-hard RAP-per will want to check is Remoted Net API Format Strings, which is an email message that was sent to Microsoft's CIFS mailing list by Paul Leach. It provides details on the formatting of RAP messages. All of these sources are, of course, listed in the References section. One of the downsides of RAP, from our perspective, is that it defines yet another layer of parameters and data...and there's a heap, too. Gotta love layers. RAP provides a formula for marshalling its parameters, data, & heap, passing them over a network connection, and then passing the results back again. A complete RAP implementation would most likely automate the marshalling and unmarshalling process, and the human eye would never need to see it. That would be overkill in our case, so we're stuck doing things the easy way--by hand. RAP functions are sent via a Named Pipe, not a Mailslot, so the whole communications process is different. Like the Mailslot-based functions, RAP functions are packed into an SMBtrans transaction, but that's just about all that's really the same. The steps which must be followed in order to execute a RAP call are:
You can see all of this very clearly in a packet capture. Having a sniff handy as you read through this section is highly recommended, by the way. Don't forget to listen on 139/TCP instead of (or in addition to) 138/UDP. 3.4.3.1 NetServerEnum2 RequestYou can generate a NetServerEnum2 exchange in a variety of ways. For example, you can refresh the server list in the Windows Network Neighborhood or use the jCIFS List.java utility with the URL "smb://workgroup/". The request, as displayed by the packet sniffer, should look something like this: + Transmission Control Protocol + NetBIOS Session Service + SMB (Server Message Block Protocol) SMB Pipe Protocol - Microsoft Windows Lanman Remote API Protocol Function Code: NetServerEnum2 (104) Parameter Descriptor: WrLehDz Return Descriptor: B16BBDz Detail Level: 1 Receive Buffer Length: 65535 Server Type: 0xffffffff Enumeration Domain: WORKGROUP The Descriptor fields are a distinctive feature of RAP requests. These are the cryptic runes of which we spoke earlier. They are format strings, used to define the structure of the parameters and data being sent as well as that expected in the reply. They can be used to automate the packing and unpacking of the packets, or they can be stuffed into the packet as constants with no regard to their meaning. The latter is the simpler course. With that in mind, here is the (simplified, but still correct) C-style format of a NetServerEnum2 request: struct { ushort RAPCode; uchar *ParamDesc; uchar *DataDesc; struct { ushort InfoLevel; ushort BufrSize; ulong ServerType; uchar *Workgroup; } Params; } NetServerEnum2Req; So, given the above structure, the NetServerEnum2 request is filled in as shown below. Note that, at the SMBtrans-level, there are no Setup[] words, the Data[] section is empty, and all of the above structure is bundled into the Parameter[] block. smb_Transaction_Request { TotalParamCount = 27 + strlen( Workgroup ) MaxParameterCount = 8 MaxDataCount = <Size of the reply buffer> Name = "\PIPE\LANMAN" Data { RAPCode = 104 (0x0068) ParamDesc = "WrLehDz" DataDesc = "B16BBDz" RAP_Params { InfoLevel = 1 <See below> BufrSize = <Same as MaxDataCount> ServerType = <See below> Workgroup = <Name of the workgroup to list> } } } A few of those fields need a little discussion.
...and that is "all you need to know" about the NetServerEnum2 request message. 3.4.3.2 NetServerEnum2 ReplyThe response message is a bit more involved, so you may want to take notes. A packet capture, once again, is a highly recommended visual aide. Starting at the top... The TotalParamCount field in the SMBtrans reply message will have a value of 8, indicating the size of the SMBtrans-level Parameter[] block. Those bytes fall out as follows: struct { ushort Status; /* Error Code */ ushort Convert; /* See below */ ushort EntryCount; /* Entries returned */ ushort AvailCount; /* Entries available */ }
That's all there is to the Parameter[] block. It's nicely simple, but things get a little wilder as we move on. Do keep track of that Convert value... The SMB-level Data[] block will start with a series of ServerInfo_1 structures, as described below: struct { uchar Name[16]; /* Provider name */ uchar OSMajorVers; /* Provider OS Rev */ uchar OSMinorVers; /* Provider OS Point */ ulong ServerType; /* See below */ uchar *Comment; /* Pointer */ } ServerInfo_1; There will be <EntryCount> such structures packed neatly together. It is fairly easy to parse them out, because the Name field is a fixed-length, nul-padded string and the Comment field really is a pointer. The Leach/Naik Browser draft suggests that the Comment strings themselves may follow each ServerInfo_1 structure, but all examples seen on the wire show four bytes. Hang on to those four bytes...we'll explain in a moment. Anywhich, the above structure has a fixed length--26 bytes, to be precise. That makes it easy to parse ServerInfo_1 structures from the Data[] block. The values in the ServerInfo_1 are the same ones announced by the Provider in its HostAnnouncement or DomainAnnouncement frames. They are stored in an internal database on the browser node. Some of these fields have been discussed before, but a detailed description of the ServerType field has been postponed at every opportunity. Similarly, the pointer value in the Comment field really needs some clarification. Let's start with the Comment pointer... The Comment pointer may just possibly be a relic of the long lost days of DOS. Those who know more about 16-bit DOS internals may judge. In any case, what you need to do is this:
Well that was easy. This stuff is so lovable you just want to give it a hug, don't you? Some further notes:
Right... Having tilted that windmill, let's take a look at the (more sensible, but also much more verbose) ServerType field. We have delayed describing this field for quite a while. Here, finally, it is. ...well, mostly. The list below is based on Samba sources. It is close to Ethereal's list, and less close to the list given in the Leach/Naik draft. Let the buyer beware.
Just to polish this subject off, here's a little code that can parse a NetServerEnum2 response message and print the results: 3.4.3.3 On the Outskirts of TownThere is another RAP call that you need to know about. It comes in handy at times. It doesn't really belong to the Browse Service, but you may have heard its name mentioned in that context. It lives on the edge, somewhere between browsing and filesharing, and it goes by the name NetShareEnum. The NetShareEnum RAP call has the job of listing the shares offered by a server. The shares, as you already know, are the virtual roots of the directory trees made available via SMB. The wire format of the request is as follows: struct { ushort RAPCode; uchar *ParamDesc; uchar *DataDesc; struct { ushort InfoLevel; ushort BufrSize; } Params; } NetShareEnumReq;...and it is filled in like so: NetShareEnumReq { RAPCode = 0 (NetShareEnum) ParamDesc = "WrLeh" DataDesc = "B13BWz" Params { InfoLevel = 1 (No other values defined) BufrSize = <Same as smb_Transaction_Request.MaxDataCount> } } Yes, the RAP code for NetShareEnum is zero (0). There's not much to that call, particularly once you've gotten the NetServerEnum2 figured out. The response also contains some familiar concepts. In fact, the Parameter[] section is exactly the same. The RAP-level data section is supposed to contain an array of ShareInfo_1 structures, which look like this: struct { uchar ShareName[13]; uchar pad; ushort ShareType; uchar *Comment; } ShareInfo_1; Again, there are many similarities to what we have seen before. In this case, though, the ShareType field has a smaller set of possible values than the comparable ServerType field.
...and that is "all you need to know" about the NetShareEnum call. Oh, wait... There is one more thing...
3.4.3.4 Transaction FragmentationA promise is a promise, and we did promise to cover fragmented transactions6. The idea is fairly simple. If you have twenty-five sacks of grain to bring to town, and a wagon that can hold only twelve sacks, then you will need to make a few trips. Likewise with transactions. Due to the limits of the negotiated buffer size, a transaction may attempt to transfer more data than can be carried in a single SMB. The solution is to split up the data and send them using multiple SMB messages. The mechanism used is the same for SMBtrans, Trans2, and NTtrans. There are slight differences between the transaction request and the transaction response, though, so pay attention. Sending a fragmented transaction request works like this:
Now go back and take a look at listing 3.1. Note that the smb_Transaction_Request structure keeps track of the number of Parameter[] and Data[] bytes already packed for shipping. That makes it easy to build the secondary messages should they be needed. Fragmenting a transaction response is a simpler process. The response SMBs all have the same structure (no special secondary messages) and they all have an SMB header, which may contain an error code if necessary. So, the server can just send as many transaction response SMBs as needed to transfer all of the results. That's it. 3.4.3.5 RAP AnnoyancesRAP can be quite annoying--that's just its nature. There are two particular annoyances of which you should be aware:
So, now you know. 3.5 The Better Browser BureauHold on to your hoopskirts everyone, we're not there yet. We have a few more things to learn about the Network Neighborhood. 3.5.1 Running an Election
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
People who love sausage and respect the law should never watch either one being made. -- Samuel Clemens (Mark Twain) |
Elections may be called whenever a Consumer is unable to find a Local Master Browser, or when a jealous rival (known as a Preferred Master Browser) shows up. An election can also be forced by sending a zero-filled RequestElection frame. When a RequestElection frame is received by a Potential Browser (including Backup Browsers, the LMB, and the DMB) the Potential Browser switches into election mode. The browser stays in election mode until a winner declares itself by sending a LocalMasterAnnouncement frame. While in election mode, the browser sends and receives RequestElection frames. If another browser's credentials are better, then the browser knows that it has lost the election, and will politely shut up and will not participate further in the current election. 3.5.1.1 VotingThere is a bit of timing involved in the election process. If all Potential Browsers were to respond at once, things could get a little noisy7. So, as with the AnnouncementRequest frame, when a browser receives a RequestElection frame it will wait a random amount of time before sending its response. The amount of time to wait varies by the status of the node, however. A Potential Browser that is more likely to win the election will send its response to the RequestElection frame sooner than one that is less likely. It's supposed to work like this:
The goal here is to cut down on network broadcast traffic. If the likely candidate votes first, the chances are good that the others won't have to vote at all. After sending a RequestElection frame, a candidate should wait two or three seconds to be sure that all other candidates have voted. After that, if the candidate has won the round it can send another RequestElection frame. This marks the start of another round. The election runs four rounds, after which the browser still standing (there should only be one) declares itself the winner by sending a LocalMasterAnnouncement frame. The timings above are provided in the Leach/Naik Browser draft. Whether existing implementations follow these guidelines or not is a question for further study. 3.5.1.2 The BallotThe ballot is contained within the RequestElection frame which, just to review, looks like this: struct { uchar Opcode; uchar Version; ulong Criteria; ulong UpTime; ulong Reserved; uchar *ServerName; } RequestElection; The Opcode and Reserved fields can be ignored. The rest comprise the election ballot. The winner of the election is determined by comparing the ballots using a somewhat arcane formula. Here, plain and simple, is how it works:
There is one more test suggested in the Leach/Naik Browser draft. It might be "Test 0" in the list above. Test 0 says, essentially, that a browser that has recently lost an election is still a loser and should remain a loser until several seconds have passed. Let's rip apart that Criteria field, shall we? The Criteria field is handled like an unsigned long integer, but it can also be divided into four subfields, like so: struct { uchar OSlevel; uchar BroMajorVers; uchar BroMinorVers; uchar Role; } Criteria; The OSlevel is the highest order byte and, therefore, has the most impact when Criteria values are compared as unsigned longs. There are some known, predefined values, as shown: 0x01 = Windows for Workgroups and Windows9x The higher you crank the OSlevel, the better your chances of winning an election. Moving along, the next subfields are the major and minor Browser Protocol Version numbers. In theory, they should have the values 15 and 1, respectively, but Windows9x systems use 21 and 4 instead. The final subfield is known as the Role field. It is a bitflag field. There seems to be some disagreement regarding the bits, though. Different sources provide different interpretations. The table below provides reasonable approximations.
It was stated earlier that the LMB election can be rigged so that a specific node always wins. For example, it is necessary that the DMB become the LMB for the LAN.
The thing is, there is no guarantee that a third-party browse server will obey the criteria conventions used in Windows. For example, a Samba server can be configured to have an OS level of 255 which would cause it to win the election over the Domain Master. Ouch. 3.5.2 Timing is EverythingSeveral different Microsoft documents provide Browse Service timing information, much of which has already been presented. For the sake of clarity, the Browse Service timings are collected in the table below. These values may be verified against the Microsoft article Browsing and Windows 95 Networking as well as the Leach/Naik draft.
If you like playing with numbers (and really, who doesn't) you can spend some time going through the mental exercise of figuring out how long it takes for Host and Domain entries to time out across subnets. ...or you could take a nice quiet walk in the forest. The forest sounds good. Yep. Forest. 3.6 Samba Browse Service EnhancementsSit back and think about it for a minute... There are a lot of ways to fiddle with the Browse Service. That could be good, or it could be bad. (Now would be a good time to check your firewall configuration.) Samba takes advantage of the fiddlability of the Browse Protocol to improve the workings of the Network Neighborhood. It may break a few rules, but it gets the job done. ...sort of like Chicago10. Samba's Browse Service enhancements are worth a bit of study, because knowing how to gracefully break the rules can provide a better insight on the proper workings of the system. 3.6.1 Automatic LANMAN
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Nothing lasts longer than a provisional arrangement. -- Unknown (Thanks to Olaf Barthel) |
There may still be systems out there that run the old LAN Manager style browsing. Things like that don't die, they fade away. ...but, just when you think they've finally faded entirely they reach a skeletal hand up through the damp earth and grab your ankle. It's best to be prepared for such events, and Samba offers a very simple clove of garlic. Samba's smb.conf configuration file provides the LM ANNOUNCE parameter, which is used to enable or disable the transmission of LAN Manager Browse Service announcements. This parameter has three possible values: TRUE, FALSE, or AUTO. The third option is the interesting one. In LM ANNOUNCE = AUTO mode, Samba will not send any LAN Manager-style announcements until (and unless) it hears a LAN Manager Browse Service message from another system. If it hears such a message, it knows that LAN Manager style browsing is being used on the local wire and will start participating. This mode is the default for Samba, and it means that System Administrators don't ever need to think about configuring LAN Manager style browsing. It's automagical! 3.6.2 UnBrowsableThe BROWSABLE parameter can be used to completely hide a share. Share names ending with a dollar sign ("$") are supposed to be hidden, but it is up to the client to decide whether or not to display these names. They are included in the reply to the NetShareEnum RAP call, so the client can do as it pleases with them. Samba can be told not to include a share in the NetShareEnum reply message simply by setting BROWSABLE = NO in the share declaration. This moves control to the server side, and allows a System Administrator to really truly hide a share. 3.6.3 NBNS Wildcard DMB Queries and Enhanced BrowsingSamba's implementation of the NBNS supports a non-standard wildcard Domain Master Browser query. You can send a query for the name "*<1B>" (that's an asterisk, followed by 14 bytes of either space or nul padding, with a suffix byte value of 0x1B), and Samba's NBNS will return a list of all of the IP addresses of all Domain Master Browsers that have registered with it. In other words, all of the IP addresses for all of the <1B> names in its database. If the ENHANCED BROWSING parameter is set to TRUE (the default) a Samba DMB will periodically send a query for "*<1B>" to the NBNS to get the list of DMB IPs. The Samba DMB will then go through the list of IPs and send a NODE STATUS REQUEST message to any IP address that it doesn't already recognize. The reply will contain the registered workgroup<1B> name of the "foreign" DMB. This trick is used by Samba to short-cut the building of the workgroup list. The normal mechanism relies on Local Master Browsers to discover foreign workgroups on their own subnet and report them back to the DMB. That process is slow and, as shown in figure 3.10, workgroups can be isolated on separate subnets where they will never see or be seen by foreigners. By querying the NBNS for the list of DMBs, Samba does a better job of ensuring that all of the workgroups within the NBT namespace know about one another. ...but it's not perfect. There might be workgroups out there that don't have a DMB, in which case querying the NBNS for DMB names won't help much. With Enhanced Browsing enabled, a Samba DMB will try to find lost workgroups by periodically querying other DMBs to see if they know about them. The Samba DMB then adds any missing workgroups to its internal list. There is a downside to this second trick, which is that bogus or expired workgroup names, once added to the Browse List, may never disappear. Samba DMBs may wind up sending the bogus names back and forth like an urban legend. This is known as the "Dead Workgroup" problem. The comments under ENHANCED BROWSING in the smb.conf manual page suggest disabling this feature if empty workgroups won't go away. Note that Windows also has a work-around for this problem. You can specify foreign DMBs in the LMHOSTS file on a known DMB, and the DMB will include the foreign names in its Browse List and try to synchronize with them. 3.6.4 Remote AnnounceThe Remote Announce feature allows a Samba server to announce itself to Local and Domain Master Browsers anywhere across the internetwork. The format of the REMOTE ANNOUNCE parameter is: remote announce = [IP[/workgroup]{" "IP[/workgroup]}] That is, a list of zero or more entries, separated by spaces, in which each entry consists of an IP address and an optional workgroup name. The IP and workgroup are separated by a slash. The Samba server will send HostAnnouncement Browser Frames to the specified IP address (which could be either a host or a broadcast address). If the workgroup name is specified, the Samba server will announce itself as a member of that workgroup, otherwise it will use the name specified by the smb.conf WORKGROUP parameter. As a result of using this feature...
Be careful, though, a misconfiguration can really mess things up. 3.6.5 Remote Browse SyncSamba servers running as Local Master Browsers can be configured to synchronize with one another directly, without the need for a DMB. The notes in the smb.conf manual page explain that this is done in a Samba-specific way. The trick is fairly simple, though. Samba unicasts a MasterAnnouncement Browser Frame to the remote IP address. You may recall that MasterAnnouncement messages are supposed to be sent to DMBs. An LMB sends them to let the DMB know that the LMB exists. The DMB periodically sends NetServerEnum2 requests to each LMB to collect its Browse List and merge it with the master list... but you knew that. Samba's extension is that a Samba LMB will also respond to a MasterAnnouncement message and synchronize with the sender. It is suggested, in the smb.conf docs, that the destination addresses be specified as subnet broadcast addresses. Current network best practices recommend against allowing directed broadcasts, however, so on most networks you won't be able to send a broadcast message to a remote subnet. To really make this feature work, you will need to know the IP address of the Local Master Browser on the remote subnet. One way to do this is to ensure that a specific Samba server on that remote LAN always wins the LMB election. You can fiddle the PREFERRED MASTER and OS LEVEL parameters such that Samba will always win the election. 3.6.6 DMB != PDCA Windows system cannot offer DMB services unless it is also the PDC. Samba can. Note that it doesn't work the other way 'round. If Samba is configured to be a PDC then, like Windows, it must also be the DMB for the NT Domain it serves. 3.7 It Can't Happen Here
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Debugging browsing problems is difficult to say the least... -- Benjamin Carter in an e'mail message to the Samba-Technical mailing list. |
Trouble in the Network Neighborhood? What could possibly happen to disrupt the peace and prosperity of such a stable, well run, and deliberately happy place? Well, any society that puts presentation ahead of principle is bound to suffer. The Network Neighborhood is far from being an exception. Many things, most of them trivial, can throw a monkey-wrench into the works. To its credit, the Browse Service is fairly resilient and it recovers quickly once the problem has been rectified. It also helps that it's a non-critical system. Still, fixing the problems generally requires intervention by a qualified expert. Unfortunatly, there aren't many of those around so trained professionals wind up with the job, poor dears. Let's see what we can do to help them... 3.7.1 Misconfigured HostsOne of the most common and obvious problems, once you know what to look for, is a misconfigured host. Things that can go wrong include:
3.7.2 Misconfigured NetworksNetwork configuration errors can also upset the teacart.
3.7.3 Implementation BugsThis is unverified12, but reliable sources report that Windows9x systems running as Local Master Browsers do not bother to synchronize properly with the Domain Master Browser. If true, it would cause a bit of a problem with cross-subnet browsing. The common solution is to grab an old, outdated PC and load an Open Source OS on it. Then install Samba and configure it to win elections. 3.7.4 TroublemakersBack several years, there was a bug in a release of Samba (somewhere in the 1.9.16 series) that would cause a Samba server to register the <1B> DMB name instead of the <1D> when it won a local election and became an LMB. This bug caused all sorts of trouble, particularly with regard to the Primary Domain Controller which, due to the rules of NetBIOS naming, was unable to register itself. 3.7.5 Design FlawsNow that you know how it works, you can decide for yourself. 3.8 At Home in the Network NeighborhoodThe first time you visit a foreign country, things may seem strange and even a bit daunting. After a while, however, the scenery starts to become familiar, the customs seem less surprising, and even the rhythm of the language starts to feel comfortable. The Browse Service is a complex system built on top of a complex
set of protocols. It can also seem strange and daunting at first.
Now that you have travelled through it and spent some time getting to
know the inhabitants, you should feel much more at home.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
By studying the Browse Service, we have also managed to provide an introduction to some of the more difficult sub-systems in the CIFS protocol suite--things like Named Pipes and SMB transactions. Understanding these is a prerequisite to dealing with the more advanced topics and sub-protocols that we have so carefully avoided. Coverage of the Browse Service concludes our study of CIFS. Between the information presented here, the suggested references, and a good protocol analyzer there is more than enough information available to build a solid CIFS client implementation and probably a working server--but you won't really know until you try. Welcome to the Network Neighborhood. |
1 IBM and Microsoft should not be blamed for any confusion between Network Neighborhood browsing and Web browsing. They started using the term "browse" well before the advent of the web.
2 Mnemonic: 0x1Election
3 From here on out, we use "MSBROWSE<01>" as a shorthand for "\x01\x02__MSBROWSE__\x02\x01" because it's really annoying to have to type all of those hex escapes and underscores every time.
4 "Old" is a relative term. In Minnesota, a 100-year-old house is considered old. In cities like Charleston, SC, the houses go back 300 years or so. ...and that's nothing compared to what they've got in places like Japan, Europe, the Middle East, etc.
5 It is possible that Class 1 Mailslots are not used. At all.
6 Maybe we could cover them with leaves and fallen branches and just let them compost themselves quietly in an out-of-the-way place or something.
7 It is possible that the reason behind this is that some older IP implementations would overflow their buffers if too many UDP packets all arrived at once. There is anecdotal evidence that such a problem did, at one time, exist.
8 The maximum UpTime is a little less than 50 days, after which the 32-bit counter will wrap around to zero again.
9 Chances are good that this node is still bitter.
10 Don't argue... I used to live there.
11 Do election storms really happen? I have heard reports of them, but never seen one first-hand.
12 ...mostly because I don't have enough equipment to really test it.
Copyright © 2002,2003 Christopher R. Hertel All rights reserved. $Revision: 1.67 $ |