Current patch for DHCP discovery of WINS servers

Andrew Bartlett abartlet at pcug.org.au
Sun Jan 13 05:30:11 GMT 2002


Tridge:
I've regenerated (bug not tested) this against current HEAD.  Probably
best to make it use the generic cache you were talking about on IRC. 
I've #if 0'ed out the dhcp-discover version.  Its probably fine, but I
had reservations at the time I was looking at this.

Shirish:
Have you updated this patch since you first proposed it?  Its starting
to get the serious attention it deserves, so it may yet see the light of
day :-)

Andrew Bartlett

-- 
Andrew Bartlett                                 abartlet at pcug.org.au
Manager, Authentication Subsystems, Samba Team  abartlet at samba.org
Student Network Administrator, Hawker College   abartlet at hawkerc.net
http://samba.org     http://build.samba.org     http://hawkerc.net
-------------- next part --------------
? include/nmbd_dhcp_for_wins.h
? nmbd/nmbd_dhcp_for_wins.c
? nsswitch/.libs
Index: Makefile.in
===================================================================
RCS file: /data/cvs/samba/source/Makefile.in,v
retrieving revision 1.433
diff -u -r1.433 Makefile.in
--- Makefile.in	12 Jan 2002 23:57:09 -0000	1.433
+++ Makefile.in	13 Jan 2002 13:19:18 -0000
@@ -249,7 +249,8 @@
             nmbd/nmbd_processlogon.o nmbd/nmbd_responserecordsdb.o \
             nmbd/nmbd_sendannounce.o nmbd/nmbd_serverlistdb.o \
             nmbd/nmbd_subnetdb.o nmbd/nmbd_winsproxy.o nmbd/nmbd_winsserver.o \
-            nmbd/nmbd_workgroupdb.o nmbd/nmbd_synclists.o
+            nmbd/nmbd_workgroupdb.o nmbd/nmbd_synclists.o \
+	    nmbd/nmbd_dhcp_for_wins.o
 
 NMBD_OBJ = $(NMBD_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) $(UBIQX_OBJ) \
            $(PROFILE_OBJ) $(LIB_OBJ)
Index: nmbd/nmbd.c
===================================================================
RCS file: /data/cvs/samba/source/nmbd/nmbd.c,v
retrieving revision 1.129
diff -u -r1.129 nmbd.c
--- nmbd/nmbd.c	30 Dec 2001 01:46:37 -0000	1.129
+++ nmbd/nmbd.c	13 Jan 2002 13:19:22 -0000
@@ -261,6 +261,8 @@
 static BOOL reload_nmbd_services(BOOL test)
 {
   BOOL ret;
+  struct in_addr wins_server;
+
   extern fstring remote_machine;
 
   fstrcpy( remote_machine, "nmbd" );
@@ -288,6 +290,17 @@
     reload_nmbd_services( True );
   }
 
+  /* Here, we discover wins servers using dhcp if asked to */
+  if (lp_dhcp_for_wins()) {
+	  if(discover_wins_server(&wins_server)) {
+		  set_wins_server(wins_server);
+		  DEBUG(3, ("reload_nmbd_services: Configured WINS server as %s using DHCP.\n", inet_ntoa(wins_server)) );
+
+	  } else {
+		  DEBUG(0, ("reload_nmbd_services: Failed to configure WINS server setting using DHCP.\n") );
+	  }
+  }
+
   /* Do a sanity check for a misconfigured nmbd */
   if( lp_wins_support() && wins_srv_count() )
     {
@@ -773,8 +786,21 @@
   DEBUG( 1, ( "Netbios nameserver version %s started.\n", VERSION ) );
   DEBUGADD( 1, ( "Copyright Andrew Tridgell 1994-1998\n" ) );
 
+  if (!is_daemon && !is_a_socket(0))
+  {
+    DEBUG(0,("standard input is not a socket, assuming -D option\n"));
+    is_daemon = True;
+  }
+  
+  if (is_daemon && !opt_interactive)
+  {
+    DEBUG( 2, ( "Becoming a daemon.\n" ) );
+    become_daemon();
+  }
+
   if ( !reload_nmbd_services(False) )
     return(-1);
+	return True;
 
   if(!init_structs())
     return -1;
@@ -790,18 +816,6 @@
   }
 
   set_samba_nb_type();
-
-  if (!is_daemon && !is_a_socket(0))
-  {
-    DEBUG(0,("standard input is not a socket, assuming -D option\n"));
-    is_daemon = True;
-  }
-  
-  if (is_daemon && !opt_interactive)
-  {
-    DEBUG( 2, ( "Becoming a daemon.\n" ) );
-    become_daemon();
-  }
 
 #if HAVE_SETPGID
   /*
Index: param/loadparm.c
===================================================================
RCS file: /data/cvs/samba/source/param/loadparm.c,v
retrieving revision 1.371
diff -u -r1.371 loadparm.c
--- param/loadparm.c	9 Jan 2002 04:17:24 -0000	1.371
+++ param/loadparm.c	13 Jan 2002 13:19:31 -0000
@@ -2525,15 +2525,46 @@
 /***************************************************************************
  Handle the WINS SERVER list
 ***************************************************************************/
+static struct in_addr wins_server = { 0 };
+static BOOL dhcp_for_wins_flag = False;
+
 static BOOL handle_wins_server_list( char *pszParmValue, char **ptr )
-  {
-  if( !wins_srv_load_list( pszParmValue ) )
-    return( False );  /* Parse failed. */
-
-  string_set( ptr, pszParmValue );
-  return( True );
-  }
+{
+	  if (strncmp(pszParmValue, "dhcp", 5)) {
+		  if( !wins_srv_load_list( pszParmValue ) )
+			  return( False );  /* Parse failed. */
+
+		  string_set( ptr, pszParmValue );
+		  return True;
+	  }
+
+	  /* Discover the WINS server using DHCP if we haven't done it
+	     one already 
+	  */
+	  if (wins_server.s_addr != 0) {
+		  string_set(ptr, inet_ntoa(wins_server));
+		  return True;
+	  }
+	  
+	  dhcp_for_wins_flag = True;
+
+	  string_set(ptr, "");
+	  return True;
+}
+
+BOOL lp_dhcp_for_wins()
+{
+	return dhcp_for_wins_flag;
+}
 
+void set_wins_server(struct in_addr srv)
+{
+	if (!wins_srv_load_list(inet_ntoa(srv)))
+		return False;
+	
+	wins_server.s_addr = srv.s_addr;
+	string_set(&Globals.szWINSserver, inet_ntoa(srv));
+}
 
 /***************************************************************************
  Handle the DEBUG level list


More information about the samba-technical mailing list