mirror of
https://github.com/samba-team/samba.git
synced 2025-02-24 13:57:43 +03:00
this isn't a big commit, it just looks like it :-)
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 commit is contained in:
parent
4488d8932f
commit
a776058900
@ -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 */
|
||||
|
||||
|
@ -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)));
|
||||
}
|
||||
|
||||
|
@ -3716,24 +3716,28 @@ void reset_globals_after_fork()
|
||||
/*******************************************************************
|
||||
return the DNS name of the client
|
||||
******************************************************************/
|
||||
char *client_name(void)
|
||||
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)
|
||||
if (global_client_name_done && last_fd == fd)
|
||||
return name_buf;
|
||||
|
||||
last_fd = fd;
|
||||
global_client_name_done = False;
|
||||
|
||||
strcpy(name_buf,"UNKNOWN");
|
||||
|
||||
if (Client == -1) {
|
||||
if (fd == -1) {
|
||||
return name_buf;
|
||||
}
|
||||
|
||||
if (getpeername(Client, &sa, &length) < 0) {
|
||||
if (getpeername(fd, &sa, &length) < 0) {
|
||||
DEBUG(0,("getpeername failed\n"));
|
||||
return name_buf;
|
||||
}
|
||||
@ -3742,12 +3746,12 @@ char *client_name(void)
|
||||
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);
|
||||
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()));
|
||||
DEBUG(0,("Matchname failed on %s %s\n",name_buf,client_addr(fd)));
|
||||
strcpy(name_buf,"UNKNOWN");
|
||||
}
|
||||
}
|
||||
@ -3758,23 +3762,27 @@ char *client_name(void)
|
||||
/*******************************************************************
|
||||
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;
|
||||
static int last_fd = -1;
|
||||
|
||||
if (global_client_addr_done)
|
||||
if (global_client_addr_done && fd == last_fd)
|
||||
return addr_buf;
|
||||
|
||||
last_fd = fd;
|
||||
global_client_addr_done = False;
|
||||
|
||||
strcpy(addr_buf,"0.0.0.0");
|
||||
|
||||
if (Client == -1) {
|
||||
if (fd == -1) {
|
||||
return addr_buf;
|
||||
}
|
||||
|
||||
if (getpeername(Client, &sa, &length) < 0) {
|
||||
if (getpeername(fd, &sa, &length) < 0) {
|
||||
DEBUG(0,("getpeername failed\n"));
|
||||
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;
|
||||
|
@ -228,9 +228,10 @@ 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;
|
||||
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;
|
||||
|
@ -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) ||
|
||||
|
@ -1640,19 +1640,19 @@ 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))
|
||||
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)
|
||||
{
|
||||
if (home) {
|
||||
extern int Client;
|
||||
sprintf(rhostsfile, "%s/.rhosts", home);
|
||||
if (check_user_equiv(user,client_name(),rhostsfile))
|
||||
if (check_user_equiv(user,client_name(Client),rhostsfile))
|
||||
return(True);
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user