includes.h: Added USE_SETSID for SGI.
[kai/samba.git] / source / nmbsync.c
index 5a4d93f1a000b93b8460fe04fde85bb4effc8a73..7f5d608998a865b1e1e37efcb22ff20fb4694d6c 100644 (file)
@@ -2,7 +2,7 @@
    Unix SMB/Netbios implementation.
    Version 1.9.
    NBT netbios routines to synchronise browse lists
-   Copyright (C) Andrew Tridgell 1994-1995
+   Copyright (C) Andrew Tridgell 1994-1997
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -48,7 +48,7 @@ fudge for getpass function
 ****************************************************************************/
 char *getsmbpass(char *pass)
 {
-    return "dummy"; /* return anything: it should be ignored anyway */
+       return "dummy"; /* return anything: it should be ignored anyway */
 }
 
 /****************************************************************************
@@ -84,46 +84,43 @@ static BOOL add_info(struct subnet_record *d, struct work_record *work, int serv
   p = skip_string(p,1);
   
   if (cli_call_api(PTR_DIFF(p,param),0, 8,10000,
-           &rprcnt,&rdrcnt, param,NULL,
-           &rparam,&rdata))
+                  &rprcnt,&rdrcnt, param,NULL,
+                  &rparam,&rdata))
     {
       int res = SVAL(rparam,0);
       int converter=SVAL(rparam,2);
       int i;
       
       if (res == 0)
-    {
-      count=SVAL(rparam,4);
-      p = rdata;
-      
-      for (i = 0;i < count;i++, p += 26)
-        {
-          char *sname = p;
-          uint32 stype = IVAL(p,18);
-          int comment_offset = IVAL(p,22) & 0xFFFF;
-          char *cmnt = comment_offset?(rdata+comment_offset-converter):"";
-          
-          struct work_record *w = work;
-          
-          DEBUG(4, ("\t%-16.16s     %08x    %s\n", sname, stype, cmnt));
-          
-        if (stype & SV_TYPE_DOMAIN_ENUM)
-        {
-          /* creates workgroup on remote subnet */
-          if ((w = find_workgroupstruct(d,sname,True)))
-            {
-              announce_request(w, d->bcast_ip);
-            }
-        }
-
-        if (w)
-        {
-          add_server_entry(d,w,sname,stype & ~SV_TYPE_LOCAL_LIST_ONLY,
-                           lp_max_ttl(),cmnt,False);
-        }
-      }
+       {
+         count=SVAL(rparam,4);
+         p = rdata;
+         
+         for (i = 0;i < count;i++, p += 26)
+           {
+             char *sname = p;
+             uint32 stype = IVAL(p,18);
+             int comment_offset = IVAL(p,22) & 0xFFFF;
+             char *cmnt = comment_offset?(rdata+comment_offset-converter):"";
+             
+             struct work_record *w = work;
+             
+             DEBUG(4, ("\t%-16.16s     %08x    %s\n", sname, stype, cmnt));
+             
+             if (stype & SV_TYPE_DOMAIN_ENUM)
+               {
+                 /* creates workgroup on remote subnet */
+                 if ((w = find_workgroupstruct(d,sname,True)))
+                   {
+                     announce_request(w, d->bcast_ip);
+                   }
+               }
+             
+          if (w)
+               add_server_entry(d,w,sname,stype,lp_max_ttl(),cmnt,False);
+           }
+       }
     }
-  }
   
   if (rparam) free(rparam);
   if (rdata) free(rdata);
@@ -139,11 +136,17 @@ static BOOL add_info(struct subnet_record *d, struct work_record *work, int serv
   do a NetServerEnum and update our server and workgroup databases.
   ******************************************************************/
 void sync_browse_lists(struct subnet_record *d, struct work_record *work,
-        char *name, int nm_type, struct in_addr ip, BOOL local)
+               char *name, int nm_type, struct in_addr ip, BOOL local)
 {
   uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0;
 
-  if (!d || !work || !AM_MASTER(work)) return;
+  if (!d || !work ) return;
+
+  if(d != wins_subnet) {
+      DEBUG(0,
+        ("sync_browse_lists: ERROR sync requested on non-WINS subnet.\n"));
+      return;
+  }
 
   pid = getpid();
   uid = getuid();
@@ -153,8 +156,8 @@ void sync_browse_lists(struct subnet_record *d, struct work_record *work,
   
   got_pass = True;
   
-  DEBUG(4,("sync browse lists with %s for %s %s\n",
-        work->work_group, name, inet_ntoa(ip)));
+  DEBUG(0,("sync_browse_lists: Sync browse lists with %s for %s %s\n",
+           work->work_group, name, inet_ntoa(ip)));
   
   strcpy(workgroup,work->work_group);
   strcpy(desthost,name);
@@ -173,11 +176,11 @@ void sync_browse_lists(struct subnet_record *d, struct work_record *work,
   if (cli_open_sockets(SMB_PORT))
     {
       if (cli_send_login(NULL,NULL,True,True))
-    {
-      add_info(d, work, local_type|SV_TYPE_DOMAIN_ENUM);
-      add_info(d, work, local_type|(SV_TYPE_ALL&
+       {
+         add_info(d, work, local_type|SV_TYPE_DOMAIN_ENUM);
+         add_info(d, work, local_type|(SV_TYPE_ALL&
                       ~(SV_TYPE_DOMAIN_ENUM|SV_TYPE_LOCAL_LIST_ONLY)));
-    }
+       }
       
       close_sockets();
     }