Patch: WinsBrowsing

Peter Astrand peter at student.liu.se
Sat Oct 9 09:53:14 GMT 1999


Summary
-------
This patch integrates the WINS and Browsing functions of nmbd. Clients are
automatically added to a special workgroup upon WINS-registration. 

Background 
---------- 
Here at Linkoping University, Sweden, many students have access to a LAN
from their apartments. The network has about 3000 nodes, and SMB is
heavily used. About 1500 clients are sharing files via SMB, in ~100
workgroups. All kinds of clients are used. Since many computers are
shutdowned/restarted often, browsing has always been a big problem. 

We are running Samba as WINS-server and Domain Master Browser. Since nmbd
deals with both WINS and Browsing, it's possible to make these functions
cooperate. The patch included below makes nmbd do this. All clients
registering their Netbios-name with the WINS-server are added to a special
WINS-workgroup (if sharing files). The result is an almost complete
browse-list. 

Configuration and usage
-----------------------
The patch is intended to be applied to WINS-servers also running as DMBs.
The workgroup must be set to WINS. I recommend a smb.conf like this:

   workgroup = WINS
   netbios name = YOURNAME
   security = share
   domain master = yes 
   local master = yes
   os level = 255
   preferred master = yes
   wins support = yes

The browsing is intended to be used more like client/server. Therefore,
it's not recommended with Local Master Browsers for the WINS-workgroup. No
clients should be members of the WINS-workgroup. The WINS-workgroup will
not be visible in "Network Neighbourhood" in Windows. Instead, one can get
it directly from the WINS-server by: 

1) Start->Run, entering \\YOURNAME, and pressing backspace.  
or 
2) Use a shortcut to the WINS-workgroup, placed on the desktop, for
example.

Samba users can get the browselist with smbclient -L YOURNAME -W WINS. 

Caveats and TODO
----------------
The patch has hardcoded references to the WINS-workgroup. This should be
changed to the servers current workgroup. 
The WinsBrowse feature should be enabled/disabled via smb.conf. 
The comment-field is set to the clients IP-adress. 

The patch is included below.

/Peter Åstrand <peter at student.liu.se>, Linkoping University, Sweden. 

----

diff -ur samba-2.0.5a/source/nmbd/nmbd_winsserver.c samba_wb/source/nmbd/nmbd_winsserver.c
--- samba-2.0.5a/source/nmbd/nmbd_winsserver.c	Wed Jul 21 03:25:11 1999
+++ samba_wb/source/nmbd/nmbd_winsserver.c	Fri Oct  8 23:12:53 1999
@@ -636,7 +636,14 @@
   int ttl = get_ttl_from_packet(nmb);
   struct name_record *namerec = NULL;
   struct in_addr from_ip;
-  BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False;;
+  BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False;
+
+  struct work_record *work;
+  struct server_record *servrec;
+
+  pstring short_nmb_name;
+  int nmb_type = 0;
+  char *ptr;
 
   putip((char *)&from_ip,&nmb->additional->rdata[2]);
 
@@ -657,6 +664,46 @@
   DEBUG(3,("wins_process_name_registration_request: %s name registration for name %s \
 IP %s\n", registering_group_name ? "Group" : "Unique", nmb_namestr(question), inet_ntoa(from_ip) ));
 
+
+  /* winsbrowse */
+  /* Add this host to the special workgroup WINS */
+  /* Divide name and type */
+  pstrcpy(short_nmb_name, nmb_namestr(question));
+  if((ptr = strchr(short_nmb_name,'<')) != NULL)
+    {
+      *ptr = 0;
+      sscanf(ptr+1,"%x",&nmb_type);
+    } 
+
+  /* If this is a server resource name (#20), add it to the WINS workgroup */
+  if(nmb_type == 0x20) {
+    work = find_workgroup_on_subnet(unicast_subnet, "WINS");
+    if (!work) {
+      DEBUG(2,("winsbrowse: Workgroup WINS is missing!\n"));
+    } else {
+      servrec = find_server_in_workgroup(work, short_nmb_name); 
+    }
+    
+    if(!servrec) 
+      { 
+	DEBUG(2,("winsbrowse: Created server %s on workgroup %s\n", 
+		 short_nmb_name, work->work_group)); 
+	/* Create the server entry with its IP as comment */ 
+	create_server_on_workgroup(work, short_nmb_name,  
+				   SV_TYPE_WORKSTATION | SV_TYPE_SERVER_NT 
+				   | SV_TYPE_NT | SV_TYPE_SERVER,
+				   lp_max_ttl(), inet_ntoa(from_ip)); 
+      }  
+    else  
+      { 
+	DEBUG(2,("winsbrowse: Updating TTL for server %s on workgroup %s\n", 
+		 short_nmb_name, work->work_group)); 
+	update_server_ttl(servrec, lp_max_ttl()); 
+      } 
+  } 
+  /* end winsbrowse */
+
+
   /*
    * See if the name already exists.
    */
@@ -1416,7 +1463,13 @@
   uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
   struct name_record *namerec = NULL;
   struct in_addr from_ip;
-  BOOL releasing_group_name = (nb_flags & NB_GROUP) ? True : False;;
+  BOOL releasing_group_name = (nb_flags & NB_GROUP) ? True : False;
+
+  pstring short_nmb_name;
+  int nmb_type = 0;
+  char *ptr;
+  struct work_record *work;
+  struct server_record *servrec;
 
   putip((char *)&from_ip,&nmb->additional->rdata[2]);
 
@@ -1501,6 +1554,38 @@
   if (namerec->data.num_ips == 0)
     remove_name_from_namelist(subrec, namerec);
 
+
+  /* winsbrowse: Remove computer from workgroup list upon release */
+  /* Divide name and type */
+  pstrcpy(short_nmb_name, nmb_namestr(question));
+  if((ptr = strchr(short_nmb_name,'<')) != NULL)
+    {
+      *ptr = 0;
+      sscanf(ptr+1,"%x",&nmb_type);
+    } 
+  
+  /* If this is a server resource name (#20), remove it from the WINS workgroup */
+  if(nmb_type == 0x20) {
+    work = find_workgroup_on_subnet(unicast_subnet, "WINS");
+    if (!work) {
+      DEBUG(2,("winsbrowse: Workgroup WINS is missing!\n"));
+    } else {
+      servrec = find_server_in_workgroup(work, short_nmb_name); 
+    }
+    
+    if(servrec) 
+      { 
+	DEBUG(2,("winsbrowse: Removed server %s on workgroup %s\n", short_nmb_name, work->work_group)); 
+	remove_server_from_workgroup(work, servrec);
+	  }  
+    else  
+      { 
+	DEBUG(2,("winsbrowse: Couldn't find server %s on workgroup %s\n", 
+		 short_nmb_name, work->work_group)); 
+      } 
+  }
+  /* end winsbrowse */
+  
 }
 
 /*******************************************************************









More information about the samba-technical mailing list