this isn't a big commit, it just looks like it :-)
authorAndrew Tridgell <tridge@samba.org>
Tue, 17 Mar 1998 12:31:43 +0000 (12:31 +0000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 17 Mar 1998 12:31:43 +0000 (12:31 +0000)
I needed the client_name() and client_addr() functions in swat so I
could tell who was connecting from where. The problem was that these
functions didn't take a file descriptor parameter they just used
the global "Client".

So I needed to change all calls to pass a parameter ... lots of files.
(This used to be commit a776058900a727591bd7b69debdaa25c0e31d693)

source3/include/proto.h
source3/lib/access.c
source3/lib/util.c
source3/rpc_server/srv_netlog.c
source3/smbd/connection.c
source3/smbd/password.c
source3/smbd/reply.c
source3/smbd/server.c
source3/web/cgi.c
source3/web/swat.c

index dfd9ca8be8ced9fb50570f6300a29e688f047c89..b7c64cbc251028dfb3d8fc6be3f92338136565a4 100644 (file)
@@ -1873,8 +1873,8 @@ uint32 interpret_addr(char *str);
 struct in_addr *interpret_addr2(char *str);
 BOOL zero_ip(struct in_addr ip);
 void reset_globals_after_fork();
-char *client_name(void);
-char *client_addr(void);
+char *client_name(int fd);
+char *client_addr(int fd);
 char *automount_server(char *user_name);
 char *automount_path(char *user_name);
 void standard_sub_basic(char *str);
@@ -1927,6 +1927,8 @@ void cgi_setup(char *rootdir, int auth_required);
 char *cgi_baseurl(void);
 char *cgi_rooturl(void);
 char *cgi_pathinfo(void);
+char *cgi_remote_host(void);
+char *cgi_remote_addr(void);
 
 /*The following definitions come from  web/diagnose.c  */
 
index c338517ed6746ab9a35f2a2e4a4cef726fd4c7e7..cc2bf8632b77cb331122f6cd046fa0880d4b10e1 100644 (file)
@@ -60,18 +60,19 @@ BOOL check_access(int snum)
 
   if (!ret)
     {
-      if (allow_access(denyl,allowl,client_name(),client_addr()))
+      extern int Client;
+      if (allow_access(denyl,allowl,client_name(Client),client_addr(Client)))
        {
          if (snum >= 0)
            DEBUG(2,("Allowed connection from %s (%s) to %s\n",
-                    client_name(),client_addr(),
+                    client_name(Client),client_addr(Client),
                     lp_servicename(snum)));
          ret = True;
        }
       else
        if (snum >= 0)
          DEBUG(0,("%s Denied connection from %s (%s) to %s\n",
-                  timestring(), client_name(),client_addr(),
+                  timestring(), client_name(Client),client_addr(Client),
                   lp_servicename(snum)));
     }
 
index e9ece491703487a498562e7026b6d8622d5565af..8c30aad68e02e8c7615725f7913218c8215b8df0 100644 (file)
@@ -3716,73 +3716,81 @@ void reset_globals_after_fork()
 /*******************************************************************
  return the DNS name of the client 
  ******************************************************************/
-char *client_name(void)
-{
-  struct sockaddr sa;
-  struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
-  int     length = sizeof(sa);
-  static pstring name_buf;
-  struct hostent *hp;
-
-  if (global_client_name_done) 
-    return name_buf;
-
-  strcpy(name_buf,"UNKNOWN");
-
-  if (Client == -1) {
-         return name_buf;
-  }
-
-  if (getpeername(Client, &sa, &length) < 0) {
-    DEBUG(0,("getpeername failed\n"));
-    return name_buf;
-  }
-
-  /* Look up the remote host name. */
-  if ((hp = gethostbyaddr((char *) &sockin->sin_addr,
-                         sizeof(sockin->sin_addr),
-                         AF_INET)) == 0) {
-    DEBUG(1,("Gethostbyaddr failed for %s\n",client_addr()));
-    StrnCpy(name_buf,client_addr(),sizeof(name_buf) - 1);
-  } else {
-    StrnCpy(name_buf,(char *)hp->h_name,sizeof(name_buf) - 1);
-    if (!matchname(name_buf, sockin->sin_addr)) {
-      DEBUG(0,("Matchname failed on %s %s\n",name_buf,client_addr()));
-      strcpy(name_buf,"UNKNOWN");
-    }
-  }
-  global_client_name_done = True;
-  return name_buf;
+char *client_name(int fd)
+{
+       struct sockaddr sa;
+       struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
+       int     length = sizeof(sa);
+       static pstring name_buf;
+       struct hostent *hp;
+       static int last_fd=-1;
+       
+       if (global_client_name_done && last_fd == fd) 
+               return name_buf;
+       
+       last_fd = fd;
+       global_client_name_done = False;
+       
+       strcpy(name_buf,"UNKNOWN");
+       
+       if (fd == -1) {
+               return name_buf;
+       }
+       
+       if (getpeername(fd, &sa, &length) < 0) {
+               DEBUG(0,("getpeername failed\n"));
+               return name_buf;
+       }
+       
+       /* Look up the remote host name. */
+       if ((hp = gethostbyaddr((char *) &sockin->sin_addr,
+                               sizeof(sockin->sin_addr),
+                               AF_INET)) == 0) {
+               DEBUG(1,("Gethostbyaddr failed for %s\n",client_addr(fd)));
+               StrnCpy(name_buf,client_addr(fd),sizeof(name_buf) - 1);
+       } else {
+               StrnCpy(name_buf,(char *)hp->h_name,sizeof(name_buf) - 1);
+               if (!matchname(name_buf, sockin->sin_addr)) {
+                       DEBUG(0,("Matchname failed on %s %s\n",name_buf,client_addr(fd)));
+                       strcpy(name_buf,"UNKNOWN");
+               }
+       }
+       global_client_name_done = True;
+       return name_buf;
 }
 
 /*******************************************************************
  return the IP addr of the client as a string 
  ******************************************************************/
-char *client_addr(void)
+char *client_addr(int fd)
 {
-  struct sockaddr sa;
-  struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
-  int     length = sizeof(sa);
-  static fstring addr_buf;
+       struct sockaddr sa;
+       struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
+       int     length = sizeof(sa);
+       static fstring addr_buf;
+       static int last_fd = -1;
 
-  if (global_client_addr_done
-    return addr_buf;
+       if (global_client_addr_done && fd == last_fd
+               return addr_buf;
 
-  strcpy(addr_buf,"0.0.0.0");
+       last_fd = fd;
+       global_client_addr_done = False;
 
-  if (Client == -1) {
-         return addr_buf;
-  }
+       strcpy(addr_buf,"0.0.0.0");
 
-  if (getpeername(Client, &sa, &length) < 0) {
-    DEBUG(0,("getpeername failed\n"));
-    return addr_buf;
-  }
-
-  fstrcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr));
-
-  global_client_addr_done = True;
-  return addr_buf;
+       if (fd == -1) {
+               return addr_buf;
+       }
+       
+       if (getpeername(fd, &sa, &length) < 0) {
+               DEBUG(0,("getpeername failed\n"));
+               return addr_buf;
+       }
+       
+       fstrcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr));
+       
+       global_client_addr_done = True;
+       return addr_buf;
 }
 
 /*******************************************************************
@@ -3946,9 +3954,9 @@ void standard_sub_basic(char *str)
                                break;
                        }
                        case 'N' : string_sub(p,"%N", automount_server(username)); break;
-                       case 'I' : string_sub(p,"%I", client_addr()); break;
+                       case 'I' : string_sub(p,"%I", client_addr(Client)); break;
                        case 'L' : string_sub(p,"%L", local_machine); break;
-                       case 'M' : string_sub(p,"%M", client_name()); break;
+                       case 'M' : string_sub(p,"%M", client_name(Client)); break;
                        case 'R' : string_sub(p,"%R", remote_proto); break;
                        case 'T' : string_sub(p,"%T", timestring()); break;
                        case 'U' : string_sub(p,"%U", username); break;
index 94d6faa99253d1d788bf1804c708784332fb4eb4..f85330fd3c478aecfc8112ff0b9b872355952dd3 100644 (file)
@@ -227,10 +227,11 @@ static void net_reply_sam_logoff(NET_Q_SAM_LOGOFF *q_s, prs_struct *rdata,
  ******************************************************************/
 static BOOL get_md4pw(char *md4pw, char *mach_name, char *mach_acct)
 {
-    struct smb_passwd *smb_pass;
+       struct smb_passwd *smb_pass;
+       extern int Client;
 
        if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
-                         client_name(), client_addr()))
+                         client_name(Client), client_addr(Client)))
        {
                DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
                return False;
index 610afbc3e55fd463c69d805806531f9c2cc4d685..5cf8b800f2c6ee02c9b1330b4ac8f8d7726a4384 100644 (file)
@@ -115,6 +115,7 @@ simple routines to do connection counting
 ****************************************************************************/
 BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear)
 {
+       extern int Client;
        struct connect_record crec;
        pstring fname;
        int fd=-1;
@@ -200,7 +201,7 @@ BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear)
        crec.start = time(NULL);
        
        StrnCpy(crec.machine,remote_machine,sizeof(crec.machine)-1);
-       StrnCpy(crec.addr,client_addr(),sizeof(crec.addr)-1);
+       StrnCpy(crec.addr,client_addr(Client),sizeof(crec.addr)-1);
        
        /* make our mark */
        if (lseek(fd,foundi*sizeof(crec),SEEK_SET) != foundi*sizeof(crec) ||
index bb0aacac7e572b76913c3d5fc5ac6cc72a15af42..ffa75d7d0bc37b6d1d8e1f6f52e469349cd83926 100644 (file)
@@ -1640,21 +1640,21 @@ BOOL check_hosts_equiv(char *user)
   fname = lp_hosts_equiv();
 
   /* note: don't allow hosts.equiv on root */
-  if (fname && *fname && (pass->pw_uid != 0))
-    {
-      if (check_user_equiv(user,client_name(),fname))
-       return(True);
-    }
+  if (fname && *fname && (pass->pw_uid != 0)) {
+         extern int Client;
+         if (check_user_equiv(user,client_name(Client),fname))
+                 return(True);
+  }
   
   if (lp_use_rhosts())
     {
       char *home = get_home_dir(user);
-      if (home)
-       {
-         sprintf(rhostsfile, "%s/.rhosts", home);
-         if (check_user_equiv(user,client_name(),rhostsfile))
-           return(True);
-       }
+      if (home) {
+             extern int Client;
+             sprintf(rhostsfile, "%s/.rhosts", home);
+             if (check_user_equiv(user,client_name(Client),rhostsfile))
+                     return(True);
+      }
     }
 
   return(False);
index 4d163d70a0939f44e2cb26b2e72b88a056f8847a..8afda69b3214ba33fcd54ff4bc36c4bfe23e16fb 100644 (file)
@@ -57,7 +57,7 @@ static void overflow_attack(int len)
 {
        DEBUG(0,("%s: ERROR: Invalid password length %d\n", timestring(), len));
        DEBUG(0,("your machine may be under attack by a user exploiting an old bug\n"));
-       DEBUG(0,("Attack was from IP=%s\n", client_addr()));
+       DEBUG(0,("Attack was from IP=%s\n", client_addr(Client)));
        exit_server("possible attack");
 }
 
index 248a2cee5f4f5e6cd5f6c556eec88b5319f1fa16..f51342d0e512daa6144ab92f22bd2b8700d54fb5 100644 (file)
@@ -2625,7 +2625,7 @@ static void process_smb(char *inbuf, char *outbuf)
                   name" */
                  static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81};
                  DEBUG(1,("%s Connection denied from %s\n",
-                          timestring(),client_addr()));
+                          timestring(),client_addr(Client)));
                  send_smb(Client,(char *)buf);
                  exit_server("connection denied");
          }
@@ -3597,10 +3597,11 @@ int make_connection(char *service,char *user,char *password, int pwlen, char *de
   }
 
   {
+    extern int Client;
     DEBUG(IS_IPC(cnum)?3:1,("%s %s (%s) connect to service %s as user %s (uid=%d,gid=%d) (pid %d)\n",
                            timestring(),
                            remote_machine,
-                           client_addr(),
+                           client_addr(Client),
                            lp_servicename(SNUM(cnum)),user,
                            pcon->uid,
                            pcon->gid,
@@ -4143,6 +4144,7 @@ close a cnum
 ****************************************************************************/
 void close_cnum(int cnum, uint16 vuid)
 {
+  extern int Client;
   DirCacheFlush(SNUM(cnum));
 
   unbecome_user();
@@ -4155,7 +4157,7 @@ void close_cnum(int cnum, uint16 vuid)
 
   DEBUG(IS_IPC(cnum)?3:1,("%s %s (%s) closed connection to service %s\n",
                          timestring(),
-                         remote_machine,client_addr(),
+                         remote_machine,client_addr(Client),
                          lp_servicename(SNUM(cnum))));
 
   yield_connection(cnum,
index 46654b1303d24fd8d7e29fde09943102d20b87d2..9931ca1468897dd69ae04fbaa0c665893d427e5d 100644 (file)
@@ -665,3 +665,24 @@ char *cgi_pathinfo(void)
        return r;
 }
 
+/***************************************************************************
+return the hostname of the client
+  ***************************************************************************/
+char *cgi_remote_host(void)
+{
+       if (baseurl) {
+               return client_name(1);
+       }
+       return getenv("REMOTE_HOST");
+}
+
+/***************************************************************************
+return the hostname of the client
+  ***************************************************************************/
+char *cgi_remote_addr(void)
+{
+       if (baseurl) {
+               return client_addr(1);
+       }
+       return getenv("REMOTE_ADDR");
+}
index a41249a9eefa66994cf396f77f6f218f7e4c605b..7378cf682bcb500a2b1807959967f484b55e6276 100644 (file)
@@ -172,6 +172,7 @@ static void show_parameters(int snum, int allparameters, int advanced, int print
 static void write_config(FILE *f, BOOL show_defaults)
 {
        fprintf(f, "# Samba config file created using SWAT\n");
+       fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
        fprintf(f, "# Date: %s\n\n", timestring());
        
        lp_dump(f, show_defaults);