moved MSBROWSE into nameserv.h
[samba.git] / source3 / namedb.c
index fc14c4d5c60a45196773c769f35f39c1b788a3c3..81b6c0204881eeb3fee0cf5e93be38a91a2c14d3 100644 (file)
 #include "includes.h"
 #include "smb.h"
 #include "loadparm.h"
-#include "localnet.h"
+
+extern int ClientNMB;
+extern int ClientDGRAM;
 
 extern int DEBUGLEVEL;
 
 extern time_t StartupTime;
 extern pstring myname;
 extern pstring scope;
-extern struct in_addr bcast_ip;
+
+extern struct in_addr ipgrp;
 
 /* this is our browse master/backup cache database */
 struct browse_cache_record *browserlist = NULL;
@@ -54,9 +57,6 @@ int workgroup_count = 0; /* unique index key: one for each workgroup */
                        SV_TYPE_TIME_SOURCE | SV_TYPE_SERVER_UNIX | \
                        SV_TYPE_PRINTQ_SERVER | SV_TYPE_POTENTIAL_BROWSER)
 
-/* here are my election parameters */
-#define MSBROWSE "\001\002__MSBROWSE__\002"
-
 
 /****************************************************************************
   add a workgroup into the domain list
@@ -305,7 +305,8 @@ void expire_browse_cache(time_t t)
   that it get created/added anyway. this allows us to force entries in
   lmhosts file to be added.
   **************************************************************************/
-struct work_record *find_workgroupstruct(struct domain_record *d, fstring name, BOOL add)
+struct work_record *find_workgroupstruct(struct domain_record *d, 
+                                        fstring name, BOOL add)
 {
   struct work_record *ret, *work;
   
@@ -323,28 +324,31 @@ struct work_record *find_workgroupstruct(struct domain_record *d, fstring name,
       return NULL;
     }
   
-  for (ret = d->workgrouplist; ret; ret = ret->next)
-    {
-      if (!strcmp(ret->work_group,name))
-       {
-         DEBUG(4, ("found\n"));
-         return(ret);
-       }
+  for (ret = d->workgrouplist; ret; ret = ret->next) {
+    if (!strcmp(ret->work_group,name)) {
+      DEBUG(4, ("found\n"));
+      return(ret);
     }
-  
-  DEBUG(4, ("not found: creating\n"));
+  }
+
+  if (!add) {
+    DEBUG(4, ("not found\n"));
+    return NULL;
+  }
+
+  DEBUG(4,("not found: creating\n"));
   
   if ((work = make_workgroup(name)))
     {
       if (lp_preferred_master() &&
          strequal(lp_workgroup(), name) &&
-         ip_equal(d->bcast_ip, bcast_ip))
+         ismybcast(d->bcast_ip))
        {
          DEBUG(3, ("preferred master startup for %s\n", work->work_group));
          work->needelection = True;
          work->ElectionCriterion |= (1<<3);
        }
-      if (!ip_equal(bcast_ip, d->bcast_ip))
+      if (!ismybcast(d->bcast_ip))
        {
          work->needelection = False;
        }
@@ -379,7 +383,7 @@ struct domain_record *find_domain(struct in_addr source_ip)
 /****************************************************************************
   dump a copy of the workgroup/domain database
   **************************************************************************/
-static void dump_workgroups(void)
+void dump_workgroups(void)
 {
   struct domain_record *d;
   
@@ -444,9 +448,10 @@ struct domain_record *add_domain_entry(struct in_addr source_ip,
   struct domain_record *d;
   struct in_addr ip;
   
-  ip = *interpret_addr2("255.255.255.255");
+  ip = ipgrp;
   
-  if (zero_ip(source_ip)) source_ip = bcast_ip;
+  if (zero_ip(source_ip)) 
+    source_ip = *iface_bcast(source_ip);
   
   /* add the domain into our domain database */
   if ((d = find_domain(source_ip)) ||
@@ -454,6 +459,8 @@ struct domain_record *add_domain_entry(struct in_addr source_ip,
     {
       struct work_record *w = find_workgroupstruct(d, name, add);
       
+      if (!w) return NULL;
+
       /* add WORKGROUP(1e) and WORKGROUP(00) entries into name database
         or register with WINS server, if it's our workgroup */
       if (strequal(lp_workgroup(), name))
@@ -516,7 +523,8 @@ struct browse_cache_record *add_browser_entry(char *name, int type, char *wg,
   b->ip     = ip;
   b->type   = type;
   
-  if (newentry || ttl < b->sync_time) b->sync_time = ttl;
+  if (newentry || ttl < b->sync_time) 
+    b->sync_time = ttl;
   
   if (newentry)
     {
@@ -576,10 +584,11 @@ struct server_record *add_server_entry(struct domain_record *d,
       bzero((char *)s,sizeof(*s));
     }
   
-  if (ip_equal(bcast_ip, d->bcast_ip) &&
+  if (ismybcast(d->bcast_ip) &&
       strequal(lp_workgroup(),work->work_group))
     {
-      servertype |= SV_TYPE_LOCAL_LIST_ONLY;
+      if (servertype)
+       servertype |= SV_TYPE_LOCAL_LIST_ONLY;
     }
   else
     {
@@ -592,6 +601,9 @@ struct server_record *add_server_entry(struct domain_record *d,
   strupper(s->serv.name);
   s->serv.type  = servertype;
   s->death_time = ttl?time(NULL)+ttl*3:0;
+
+  if (servertype == 0)
+    s->death_time = time(NULL)-1;
   
   /* for a domain entry, the comment field refers to the server name */