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);
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 */
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)));
}
/*******************************************************************
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;
}
/*******************************************************************
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;
******************************************************************/
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;
****************************************************************************/
BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear)
{
+ extern int Client;
struct connect_record crec;
pstring fname;
int fd=-1;
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) ||
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);
{
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");
}
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");
}
}
{
+ 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,
****************************************************************************/
void close_cnum(int cnum, uint16 vuid)
{
+ extern int Client;
DirCacheFlush(SNUM(cnum));
unbecome_user();
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,
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");
+}
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);