- added support for Amiga-unix (based on BSD I think)
authorAndrew Tridgell <tridge@samba.org>
Sat, 17 Aug 1996 11:37:44 +0000 (11:37 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sat, 17 Aug 1996 11:37:44 +0000 (11:37 +0000)
- changed the order of PROGS and SPROGS in Makefile (SPROGS first)

- another 64 bit cleanup (for INADDR_NONE)

- added paranoia code in DirCacheAdd() to detect looping

- fixed important DirCache flush bug

- rewrote the NetServerEnum code after I found it could return servers
from multiple workgroups at once, and this could cause browsing
havoc. Now a null workgroup query is equivalent to a query for the
servers primary workgroup

- got rid of my_workgroup()

- got rid of "workgroup = *" comment in Makefile. We no longer support
a workgroup of *, users must set the workgroup explicitly

- the wins.dat file was being stored in a different format to what it
was being loaded in - this could cause havoc. fixed.

- uppercase our netbios name and the workgroup name at startup

- if accept fails in main loop when running as a daemon then continue,
don't just exit!

- don't use ./ on smbclient in smbtar

- better code to detect if a process exists
(This used to be commit ec3d53963064b50ff33e8eff47812aac82f164ba)

12 files changed:
source3/include/proto.h
source3/lib/access.c
source3/lib/util.c
source3/namedbname.c
source3/nameserv.c
source3/nmbd/nmbd.c
source3/param/loadparm.c
source3/script/smbtar
source3/smbd/dir.c
source3/smbd/ipc.c
source3/smbd/reply.c
source3/smbd/server.c

index d3e9f42ae8ff2fb04ae41ccc625c2f94108380a6..c1697dc6416c2b39b71dabd3a937ff6ba73cde78 100644 (file)
@@ -249,7 +249,6 @@ BOOL lp_load(char *pszFname,BOOL global_only);
 int lp_numservices(void);
 void lp_dump(void);
 int lp_servicenumber(char *pszServiceName);
-char *my_workgroup(void);
 char *volume_label(int snum);
 
 /*The following definitions come from  locking.c  */
index 079253cdbdc8b1f2d6660eb3ee7ef8998a657b07..8f57c37c26f4f1be3963ffccd544cfed423aee12 100644 (file)
@@ -15,7 +15,7 @@ should be sent to samba-bugs@samba.anu.edu.au
 extern int DEBUGLEVEL;
 
 #ifndef        INADDR_NONE
-#define        INADDR_NONE     ((unsigned long)~0)
+#define        INADDR_NONE     ((uint32)~0)
 #endif
 
 
index aeaac29ae12cbad87220282c9b3a3809cb061823..5ef1d21a7aabe27da5836a198f505412abb19516 100644 (file)
@@ -3089,11 +3089,8 @@ BOOL process_exists(int pid)
     }
   }
 
-  /* a best guess for non root access */
-  if (geteuid() != 0) return(True);
-
-  /* otherwise use kill */
-  return(pid == getpid() || kill(pid,0) == 0);
+  /* CGH 8/16/96 - added ESRCH test */
+  return(pid == getpid() || kill(pid,0) == 0 || errno != ESRCH);
 #endif
 }
 
index 42ad9ad009fd3fedd6f649b673fc7236d580c6aa..214926cfc97d1a2c257e1f2843ca023fa0f95ff4 100644 (file)
@@ -230,17 +230,14 @@ void dump_names(void)
     {
       if (f && ip_equal(d->bcast_ip, ipgrp) && n->source == REGISTER)
       {
-        fstring data;
-
-      /* XXXX i have little imagination as to how to output nb_flags as
-         anything other than as a hexadecimal number :-) */
-
-        sprintf(data, "%s#%02x %s %2x %ld",
-              n->name.name,n->name.name_type, /* XXXX ignore scope for now */
-              inet_ntoa(n->ip),
-              n->nb_flags,
-              n->death_time);
-           fprintf(f, "%s\n", data);
+       /* XXXX i have little imagination as to how to output nb_flags as
+          anything other than as a hexadecimal number :-) */
+
+        fprintf(f, "%s#%02x %s %2x %ld\n",
+               n->name.name,n->name.name_type, /* XXXX ignore scope for now */
+               inet_ntoa(n->ip),
+               n->nb_flags,
+               n->death_time);
       }
 
          DEBUG(3,("%15s ", inet_ntoa(d->bcast_ip)));
@@ -294,12 +291,12 @@ void load_netbios_names(void)
       int type = 0;
       int nb_flags;
       time_t ttd;
-         struct in_addr ipaddr;
+      struct in_addr ipaddr;
 
-         enum name_source source;
+      enum name_source source;
 
       char *ptr;
-         int count = 0;
+      int count = 0;
 
       char *p;
 
@@ -307,24 +304,24 @@ void load_netbios_names(void)
 
       if (*line == '#') continue;
 
-       ptr = line;
-
-       if (next_token(&ptr,name_str    ,NULL)) ++count;
-       if (next_token(&ptr,ip_str      ,NULL)) ++count;
-       if (next_token(&ptr,ttd_str     ,NULL)) ++count;
-       if (next_token(&ptr,nb_flags_str,NULL)) ++count;
-
-       if (count <= 0) continue;
-
-       if (count != 4) {
-         DEBUG(0,("Ill formed wins line"));
-         DEBUG(0,("[%s]: name#type ip nb_flags abs_time\n",line));
-         continue;
-       }
+      ptr = line;
 
+      if (next_token(&ptr,name_str    ,NULL)) ++count;
+      if (next_token(&ptr,ip_str      ,NULL)) ++count;
+      if (next_token(&ptr,nb_flags_str,NULL)) ++count;
+      if (next_token(&ptr,ttd_str     ,NULL)) ++count;
+      
+      if (count <= 0) continue;
+      
+      if (count != 4) {
+       DEBUG(0,("Ill formed wins line"));
+       DEBUG(0,("[%s]: name#type ip nb_flags abs_time\n",line));
+       continue;
+      }
+      
       /* netbios name. # divides the name from the type (hex): netbios#xx */
       strcpy(name,name_str);
-
+      
       p = strchr(name,'#');
 
       if (p) {
index 07b94ced5f3b88ce92c524aa5cc28b169280b14a..0297fee3316ce2fa2975172f9ffbbcbdbbee2ecb 100644 (file)
@@ -198,7 +198,7 @@ void add_my_names(void)
 
        if (lp_domain_logons()) {
          /* 0x1c is used to find logon servers for a domain */
-         add_my_name_entry(d, my_workgroup(),0x1c,nb_type|NB_ACTIVE|NB_GROUP);
+         add_my_name_entry(d, lp_workgroup(),0x1c,nb_type|NB_ACTIVE|NB_GROUP);
        }
   }
   if (lp_domain_master() && (d = find_subnet(ipgrp)))
index 1ee11edbcfb0a8ff424564011bdc1294a0b81e20..a4b303923dd72b63b773b87f6186d08e96e1c1cc 100644 (file)
@@ -376,6 +376,7 @@ static BOOL init_structs()
     strcpy(myname,myhostname);
     p = strchr(myname,'.');
     if (p) *p = 0;
+    strupper(myname);
   }
 
   return True;
@@ -388,19 +389,14 @@ static void usage(char *pname)
 {
   DEBUG(0,("Incorrect program usage - is the command line correct?\n"));
 
-  printf("Usage: %s [-n name] [-B bcast address] [-D] [-p port] [-d debuglevel] [-l log basename]\n",pname);
+  printf("Usage: %s [-n name] [-D] [-p port] [-d debuglevel] [-l log basename]\n",pname);
   printf("Version %s\n",VERSION);
   printf("\t-D                    become a daemon\n");
   printf("\t-p port               listen on the specified port\n");
   printf("\t-d debuglevel         set the debuglevel\n");
   printf("\t-l log basename.      Basename for log/debug files\n");
   printf("\t-n netbiosname.       the netbios name to advertise for this host\n");
-  printf("\t-B broadcast address  the address to use for broadcasts\n");
-  printf("\t-N netmask           the netmask to use for subnet determination\n");
   printf("\t-H hosts file        load a netbios hosts file\n");
-  printf("\t-G group name        add a group name to be part of\n");
-  printf("\t-I ip-address        override the IP address\n");
-  printf("\t-C comment           sets the machine comment that appears in browse lists\n");
   printf("\n");
 }
 
@@ -416,7 +412,6 @@ static void usage(char *pname)
   extern char *optarg;
   fstring group;
 
-  *group = 0;
   *host_file = 0;
 
   StartupTime = time(NULL);
@@ -451,26 +446,19 @@ static void usage(char *pname)
        case 's':
          strcpy(servicesf,optarg);
          break;          
+       case 'N':
+       case 'B':
+       case 'I':
        case 'C':
-         strcpy(ServerComment,optarg);
-         break;
        case 'G':
-         strcpy(group,optarg);
+         DEBUG(0,("Obsolete option '%c' used\n",opt));
          break;
        case 'H':
          strcpy(host_file,optarg);
          break;
-       case 'I':
-         iface_set_default(optarg,NULL,NULL);
-         break;
-       case 'B':
-         iface_set_default(NULL,optarg,NULL);
-         break;
-       case 'N':
-         iface_set_default(NULL,NULL,optarg);
-         break;
        case 'n':
          strcpy(myname,optarg);
+         strupper(myname);
          break;
        case 'l':
          sprintf(debugf,"%s.nmb",optarg);
@@ -540,6 +528,11 @@ static void usage(char *pname)
   string_sub(ServerComment,"%h",myhostname);
 
   add_my_names();
+
+  if (strequal(lp_workgroup(),"*")) {
+    DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n"));
+  }
+
   add_my_subnets(lp_workgroup());
 
   DEBUG(3,("Checked names\n"));
index d0df198a6780b59f4d74506f058e049d90b4dafe..953613fd747a636dfec0eb8bd70a4686db5cc9bc 100644 (file)
@@ -1920,19 +1920,6 @@ int lp_servicenumber(char *pszServiceName)
    return (iService);
 }
 
-
-
-
-/*******************************************************************
-  get a workgroup - but map to standalone if '*'
-  ******************************************************************/
-char *my_workgroup(void)
-{
-  char *res = lp_workgroup();
-  if (*res == '*') return("STANDALONE");
-  return(res);
-}
-
 /*******************************************************************
   a useful volume label function
   ******************************************************************/
index 156375ce9c8deffd30b1b6d08f6606bc98538040..a947476dc6ba7629351a2eb083ca18313cda815c 100644 (file)
@@ -11,8 +11,8 @@ case $0 in
     # when called by absolute path, assume smbclient is in the same directory
     /*)
        SMBCLIENT="`dirname $0`/smbclient";;
-    *)  # edit this to show where your smbclient is
-       SMBCLIENT="./smbclient";;
+    *)  # you may need to edit this to show where your smbclient is
+       SMBCLIENT="smbclient";;
 esac
 
 # These are the default values. You could fill them in if you know what
index 55a5983468565e11c85299187c008fb016c2a356..42bd54c2703730514d01c9fc1281bf1cf0681d85 100644 (file)
@@ -631,6 +631,7 @@ add an entry to the directory cache
 ********************************************************************/
 void DirCacheAdd(char *path,char *name,char *dname,int snum)
 {
+  int count;
   struct dir_cache *entry = (struct dir_cache *)malloc(sizeof(*entry));
   if (!entry) return;
   entry->path = strdup(path);
@@ -647,7 +648,12 @@ void DirCacheAdd(char *path,char *name,char *dname,int snum)
   DEBUG(4,("Added dir cache entry %s %s -> %s\n",path,name,dname));
   
   if (dir_cache_size == DIRCACHESIZE) {
-    for (entry=dir_cache; entry->next; entry=entry->next) ;
+    for (entry=dir_cache, count=1; 
+        entry->next && count < dir_cache_size; 
+        entry=entry->next, count++) ;
+    if (entry->next || count != dir_cache_size) {
+      DEBUG(0,("DirCache bug - please report\n"));
+    }
     free(entry->path);
     free(entry->name);
     free(entry->dname);
@@ -695,6 +701,7 @@ void DirCacheFlush(int snum)
       if (entry->next) entry->next->prev = entry->prev;
       if (dir_cache == entry) dir_cache = entry->next; 
       free(entry);
+      dir_cache_size--;
     } else {
       next = entry->next;
     }
index 39b8f3f089cf3e9007354dc83d21c60205966cc4..78a98077694b1b8853f0b1b0ae06879f06461958 100644 (file)
@@ -748,78 +748,22 @@ static BOOL check_server_info(int uLevel, char* id)
   return True;
 }
 
-/* used for server information: client, nameserv and ipc */
 struct srv_info_struct
 {
   fstring name;
   uint32 type;
   fstring comment;
-  fstring domain; /* used ONLY in ipc.c NOT namework.c */
-  BOOL server_added; /* used ONLY in ipc.c NOT namework.c */
+  fstring domain;
+  BOOL server_added;
 };
 
-/*******************************************************************
-  filter out unwanted server info 
-  ******************************************************************/
-static BOOL filter_server_info(struct srv_info_struct *server, 
-                              BOOL domains,
-                              char *domain, uint32 request)
-{
-  if (*domain == 0)
-    {
-      if (strequal(lp_workgroup(), server->domain)) {
-       return True;
-      }
-      else if (domains)
-       {
-         DEBUG(4,("primary domain:reject %8x %s %s\n",request,server->name,server->domain));
-         return False;
-       }
-      else if ((request & SV_TYPE_DOMAIN_ENUM) &&
-              (server->type & SV_TYPE_DOMAIN_ENUM))
-       {
-         DEBUG(4,("rej:DOM %8x: %s %s\n",server->type,server->name,server->domain));
-         return False;
-       }
-      
-      return True;
-    }
-  else
-    {
-      if (strequal(domain, server->domain))
-       {
-         /*
-           if (request     == SV_TYPE_LOCAL_LIST_ONLY &&
-           !(server->type & SV_TYPE_LOCAL_LIST_ONLY))
-           {
-           DEBUG(4,("rej:LOC %8x: ok %s %s\n",request,server->name,server->domain));
-           return False;
-           }
-           */
-         if ((request == (SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM)) &&
-                               !(server->type&SV_TYPE_DOMAIN_ENUM))
-           {
-             DEBUG(4,("rej:LOCDOM %8x: ok %s %s\n",request,server->name,server->domain));
-             return False;
-           }
-         
-         return True;
-       }
-      else if (!domains)
-       {
-         DEBUG(4,("domain:%s %s %s\n",domain,server->name,server->domain));
-         return False;
-       }
-      return True;
-    }
-}
 
 /*******************************************************************
   get server info lists from the files saved by nmbd. Return the
   number of entries
   ******************************************************************/
 static int get_server_info(uint32 servertype, 
-                          struct srv_info_struct **servers, BOOL domains, 
+                          struct srv_info_struct **servers,
                           char *domain)
 {
   FILE *f;
@@ -843,7 +787,7 @@ static int get_server_info(uint32 servertype,
   /* request for everything is code for request all servers */
   if (servertype == SV_TYPE_ALL) servertype &= ~SV_TYPE_DOMAIN_ENUM;
 
-  DEBUG(4,("Servertype search: %8x domains:%s\n",servertype,BOOLSTR(domains)));
+  DEBUG(4,("Servertype search: %8x\n",servertype));
 
   while (!feof(f))
   {
@@ -870,7 +814,7 @@ static int get_server_info(uint32 servertype,
     if (!next_token(&ptr,s->comment, NULL)) continue;
     if (!next_token(&ptr,s->domain , NULL)) {
       /* this allows us to cope with an old nmbd */
-      strcpy(s->domain,my_workgroup()); 
+      strcpy(s->domain,lp_workgroup()); 
     }
     
     if (sscanf(stype,"%X",&s->type) != 1) { 
@@ -884,20 +828,16 @@ static int get_server_info(uint32 servertype,
       ok = False; 
     }
     
-    if ((servertype == ~SV_TYPE_DOMAIN_ENUM) &&
+    if ((servertype & SV_TYPE_DOMAIN_ENUM) != 
        (s->type & SV_TYPE_DOMAIN_ENUM))
       {
-       DEBUG(4,("s:all x dom  "));
+       DEBUG(4,("s: dom mismatch "));
        ok = False;
       }
     
-    if (domains && !(domain && *domain && strequal(domain, s->domain)))
+    if (!strequal(domain, s->domain) && !(servertype & SV_TYPE_DOMAIN_ENUM))
       {
-       if (!(s->type & SV_TYPE_DOMAIN_ENUM))
-         {
-           DEBUG(4,("r:dom enum  "));
-           ok = False;
-         }
+       ok = False;
       }
     
     if (ok)
@@ -905,7 +845,6 @@ static int get_server_info(uint32 servertype,
        DEBUG(4,("**SV** %20s %8x %25s %15s\n",
                 s->name, s->type, s->comment, s->domain));
        
-       s->type |= SV_TYPE_LOCAL_LIST_ONLY;
        s->server_added = True;
        count++;
       }
@@ -1026,16 +965,13 @@ static BOOL api_RNetServerEnum(int cnum, int uid, char *param, char *data,
   int counted=0,total=0;
   int i;
   fstring domain;
-  BOOL domains;
   BOOL domain_request;
   BOOL local_request = servertype & SV_TYPE_LOCAL_LIST_ONLY;
 
-  /*if (servertype == SV_TYPE_ALL) servertype &= ~(SV_TYPE_DOMAIN_ENUM|SV_TYPE_LOCAL_LIST_ONLY);*/
   if (servertype == SV_TYPE_ALL) servertype &= ~SV_TYPE_DOMAIN_ENUM;
 
-  domain_request = servertype & SV_TYPE_DOMAIN_ENUM;
+  domain_request = ((servertype & SV_TYPE_DOMAIN_ENUM) != 0);
 
-  domain[0] = 0;
   p += 8;
 
   if (!prefix_ok(str1,"WrLehD")) return False;
@@ -1045,20 +981,14 @@ static BOOL api_RNetServerEnum(int cnum, int uid, char *param, char *data,
   DEBUG(4, ("domains_req:%s ", BOOLSTR(domain_request)));
   DEBUG(4, ("local_only:%s\n", BOOLSTR(local_request)));
 
-  if (strcmp(str1, "WrLehDO") == 0)
-  {
-       domains = False;
-  }
-  else if (strcmp(str1, "WrLehDz") == 0)
-  {
-       domains = True;
+  if (strcmp(str1, "WrLehDz") == 0) {
     StrnCpy(domain, p, sizeof(fstring)-1);
+  } else {
+    StrnCpy(domain, lp_workgroup(), sizeof(fstring)-1);    
   }
 
   if (lp_browse_list())
-  {
-    total = get_server_info(servertype,&servers,domains,domain);
-  }
+    total = get_server_info(servertype,&servers,domain);
 
   data_len = fixed_len = string_len = 0;
 
@@ -1070,21 +1000,17 @@ static BOOL api_RNetServerEnum(int cnum, int uid, char *param, char *data,
     for (i=0;i<total;i++)
     {
       struct srv_info_struct *s = &servers[i];
-      if (filter_server_info(s,domains,domain,
-                            local_request|domain_request))
+      if (lastname && strequal(lastname,s->name)) continue;
+      lastname = s->name;
+      data_len += fill_srv_info(s,uLevel,0,&f_len,0,&s_len,0);
+      DEBUG(4,("fill_srv_info %20s %8x %25s %15s\n",
+              s->name, s->type, s->comment, s->domain));
+      
+      if (data_len <= buf_len)
        {
-         if (lastname && strequal(lastname,s->name)) continue;
-         lastname = s->name;
-         data_len += fill_srv_info(s,uLevel,0,&f_len,0,&s_len,0);
-         DEBUG(4,("fill_srv_info %20s %8x %25s %15s\n",
-                  s->name, s->type, s->comment, s->domain));
-         
-         if (data_len <= buf_len)
-           {
-             counted++;
-             fixed_len += f_len;
-             string_len += s_len;
-           }
+         counted++;
+         fixed_len += f_len;
+         string_len += s_len;
        }
     }
   }
@@ -1104,15 +1030,12 @@ static BOOL api_RNetServerEnum(int cnum, int uid, char *param, char *data,
     for (i = 0; i < total && count2;i++)
       {
        struct srv_info_struct *s = &servers[i];
-       if (filter_server_info(s,domains,domain,local_request|domain_request))
-         {
-           if (lastname && strequal(lastname,s->name)) continue;
-           lastname = s->name;
-           fill_srv_info(s,uLevel,&p,&f_len,&p2,&s_len,*rdata);
-           DEBUG(4,("fill_srv_info %20s %8x %25s %15s\n",
-                    s->name, s->type, s->comment, s->domain));
-           count2--;
-         }
+       if (lastname && strequal(lastname,s->name)) continue;
+       lastname = s->name;
+       fill_srv_info(s,uLevel,&p,&f_len,&p2,&s_len,*rdata);
+       DEBUG(4,("fill_srv_info %20s %8x %25s %15s\n",
+                s->name, s->type, s->comment, s->domain));
+       count2--;
       }
   }
   
@@ -1746,7 +1669,7 @@ static BOOL api_RNetServerGetInfo(int cnum,int uid, char *param,char *data,
 
       strcpy(comment,lp_serverstring());
 
-      if ((count=get_server_info(SV_TYPE_ALL,&servers,False,NULL))>0) {
+      if ((count=get_server_info(SV_TYPE_ALL,&servers,lp_workgroup()))>0) {
        for (i=0;i<count;i++)
          if (strequal(servers[i].name,local_machine)) {
            servertype = servers[i].type;
@@ -1829,7 +1752,7 @@ static BOOL api_NetWkstaGetInfo(int cnum,int uid, char *param,char *data,
   p += 4;
 
   SIVAL(p,0,PTR_DIFF(p2,*rdata));
-  strcpy(p2,my_workgroup());
+  strcpy(p2,lp_workgroup());
   p2 = skip_string(p2,1);
   p += 4;
 
@@ -1838,7 +1761,7 @@ static BOOL api_NetWkstaGetInfo(int cnum,int uid, char *param,char *data,
   p += 2;
 
   SIVAL(p,0,PTR_DIFF(p2,*rdata));
-  strcpy(p2,my_workgroup());   /* login domain?? */
+  strcpy(p2,lp_workgroup());   /* login domain?? */
   p2 = skip_string(p2,1);
   p += 4;
 
@@ -2103,7 +2026,7 @@ static BOOL api_WWkstaUserLogon(int cnum,int uid, char *param,char *data,
       strupper(mypath);
       PACKS(&desc,"z",mypath); /* computer */
     }
-    PACKS(&desc,"z",my_workgroup());/* domain */
+    PACKS(&desc,"z",lp_workgroup());/* domain */
     PACKS(&desc,"z",lp_logon_script());                /* script path */
     PACKI(&desc,"D",0);                /* reserved */
   }
index a97c8c9c9caa2a252db75a46c9521534a5dd025e..3c2e91d5f5c87bfa676010cceb254148c702e658 100644 (file)
@@ -431,7 +431,7 @@ int reply_sesssetup_and_X(char *inbuf,char *outbuf,int length,int bufsize)
     p = smb_buf(outbuf);
     strcpy(p,"Unix"); p = skip_string(p,1);
     strcpy(p,"Samba "); strcat(p,VERSION); p = skip_string(p,1);
-    strcpy(p,my_workgroup()); p = skip_string(p,1);
+    strcpy(p,lp_workgroup()); p = skip_string(p,1);
     outsize = set_message(outbuf,3,PTR_DIFF(p,smb_buf(outbuf)),False);
     /* perhaps grab OS version here?? */
   }
index 170062a5311e14f58db9a2ad8c74d031da57bedd..3889440975a7620d4f4e3e386deeaecadd77767b 100644 (file)
@@ -1670,7 +1670,7 @@ static BOOL open_sockets(BOOL is_daemon,int port)
          if (Client == -1)
            {
              DEBUG(0,("accept: %s",strerror(errno)));
-             return False;
+             continue;
            }
 
 #ifdef NO_FORK_DEBUG