Implemented client IP logging

ulab-original
Nicola Ruggero 14 years ago
parent 87297c5014
commit d797b2cf49

@ -492,6 +492,35 @@ g_tcp_accept(int sck)
return accept(sck, (struct sockaddr*)&s, &i); return accept(sck, (struct sockaddr*)&s, &i);
} }
/*****************************************************************************/
void APP_CC
g_write_ip_address(int rcv_sck, char* ip_address)
{
struct sockaddr_in s;
struct in_addr in;
int len;
int ip_port;
memset(&s,0,sizeof(&s));
len = sizeof(s);
getpeername(rcv_sck,(struct sockaddr*)&s, &len);
memset(&in,0,sizeof(in));
in.s_addr = s.sin_addr.s_addr;
ip_port = ntohs(s.sin_port);
if (ip_port != 0)
{
sprintf(ip_address, "%s:%d - socket: %d", inet_ntoa(in), ip_port, rcv_sck);
}
else
{
sprintf(ip_address, "NULL:NULL - socket: %d", rcv_sck);
}
}
/*****************************************************************************/ /*****************************************************************************/
void APP_CC void APP_CC
g_sleep(int msecs) g_sleep(int msecs)

@ -100,6 +100,8 @@ g_tcp_can_recv(int sck, int millis);
int APP_CC int APP_CC
g_tcp_select(int sck1, int sck2); g_tcp_select(int sck1, int sck2);
void APP_CC void APP_CC
g_write_ip_address(int rcv_sck, char* ip_address);
void APP_CC
g_sleep(int msecs); g_sleep(int msecs);
tbus APP_CC tbus APP_CC
g_create_wait_obj(char* name); g_create_wait_obj(char* name);

@ -63,6 +63,7 @@ struct xrdp_client_info
int rdp5_performanceflags; int rdp5_performanceflags;
int brush_cache_code; /* 0 = no cache 1 = 8x8 standard cache int brush_cache_code; /* 0 = no cache 1 = 8x8 standard cache
2 = arbitrary dimensions */ 2 = arbitrary dimensions */
char client_ip[256];
}; };
struct xrdp_brush struct xrdp_brush

@ -145,6 +145,7 @@ xrdp_rdp_create(struct xrdp_session* session, struct trans* trans)
self->client_info.cache2_size = 1024; self->client_info.cache2_size = 1024;
self->client_info.cache3_entries = 262; self->client_info.cache3_entries = 262;
self->client_info.cache3_size = 4096; self->client_info.cache3_size = 4096;
g_write_ip_address(trans->sck, self->client_info.client_ip); /* load client ip info */
DEBUG(("out xrdp_rdp_create")); DEBUG(("out xrdp_rdp_create"));
return self; return self;
} }

@ -268,6 +268,28 @@ scp_session_set_directory(struct SCP_SESSION* s, char* str)
return 0; return 0;
} }
/*******************************************************************/
int
scp_session_set_client_ip(struct SCP_SESSION* s, char* str)
{
if (0 == str)
{
log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_client_ip: null ip", __LINE__);
return 1;
}
if (0 != s->client_ip)
{
g_free(s->client_ip);
}
s->client_ip = g_strdup(str);
if (0 == s->client_ip)
{
log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_client_ip: strdup error", __LINE__);
return 1;
}
return 0;
}
/*******************************************************************/ /*******************************************************************/
int int
scp_session_set_hostname(struct SCP_SESSION* s, char* str) scp_session_set_hostname(struct SCP_SESSION* s, char* str)
@ -380,6 +402,7 @@ scp_session_destroy(struct SCP_SESSION* s)
g_free(s->domain); g_free(s->domain);
g_free(s->program); g_free(s->program);
g_free(s->directory); g_free(s->directory);
g_free(s->client_ip);
g_free(s->errstr); g_free(s->errstr);
g_free(s->mng); g_free(s->mng);
g_free(s); g_free(s);

@ -77,6 +77,9 @@ scp_session_set_program(struct SCP_SESSION* s, char* str);
int int
scp_session_set_directory(struct SCP_SESSION* s, char* str); scp_session_set_directory(struct SCP_SESSION* s, char* str);
int
scp_session_set_client_ip(struct SCP_SESSION* s, char* str);
int int
scp_session_set_hostname(struct SCP_SESSION* s, char* str); scp_session_set_hostname(struct SCP_SESSION* s, char* str);

@ -86,6 +86,7 @@ struct SCP_SESSION
char* domain; char* domain;
char* program; char* program;
char* directory; char* directory;
char* client_ip;
}; };
struct SCP_DISCONNECTED_SESSION struct SCP_DISCONNECTED_SESSION

@ -265,6 +265,17 @@ scp_v0s_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s, int skipVchk)
scp_session_set_directory(session, buf); scp_session_set_directory(session, buf);
} }
} }
if (s_check_rem(c->in_s, 2))
{
/* reading client IP address */
in_uint16_be(c->in_s, sz);
if (sz > 0)
{
in_uint8a(c->in_s, buf, sz);
buf[sz] = '\0';
scp_session_set_client_ip(session, buf);
}
}
} }
else else
{ {

@ -45,6 +45,14 @@ scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
if (s_item != 0) if (s_item != 0)
{ {
display = s_item->display; display = s_item->display;
if (0 != s->client_ip)
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ reconnected session: username %s, display :%d.0, session_pid %d, ip %s", s->username, display, s_item->pid, s->client_ip);
}
else
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ reconnected session: username %s, display :%d.0, session_pid %d", s->username, display, s_item->pid);
}
auth_end(data); auth_end(data);
/* don't set data to null here */ /* don't set data to null here */
} }
@ -53,20 +61,28 @@ scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
LOG_DBG(&(g_cfg->log), "pre auth"); LOG_DBG(&(g_cfg->log), "pre auth");
if (1 == access_login_allowed(s->username)) if (1 == access_login_allowed(s->username))
{ {
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "granted TS access to user %s", s->username); if (0 != s->client_ip)
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ created session (access granted): username %s, ip %s", s->username, s->client_ip);
}
else
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ created session (access granted): username %s", s->username);
}
if (SCP_SESSION_TYPE_XVNC == s->type) if (SCP_SESSION_TYPE_XVNC == s->type)
{ {
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting Xvnc session..."); log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting Xvnc session...");
display = session_start(s->width, s->height, s->bpp, s->username, display = session_start(s->width, s->height, s->bpp, s->username,
s->password, data, SESMAN_SESSION_TYPE_XVNC, s->password, data, SESMAN_SESSION_TYPE_XVNC,
s->domain, s->program, s->directory); s->domain, s->program, s->directory, s->client_ip);
} }
else else
{ {
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting X11rdp session..."); log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting X11rdp session...");
display = session_start(s->width, s->height, s->bpp, s->username, display = session_start(s->width, s->height, s->bpp, s->username,
s->password, data, SESMAN_SESSION_TYPE_XRDP, s->password, data, SESMAN_SESSION_TYPE_XRDP,
s->domain, s->program, s->directory); s->domain, s->program, s->directory, s->client_ip);
} }
} }
else else

@ -107,20 +107,27 @@ scp_v1_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
if (scount == 0) if (scount == 0)
{ {
/* no disconnected sessions - start a new one */ /* no disconnected sessions - start a new one */
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "granted TS access to user %s", s->username); if (0 != s->client_ip)
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ created session (access granted): username %s, ip %s", s->username, s->client_ip);
}
else
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ created session (access granted): username %s", s->username);
}
if (SCP_SESSION_TYPE_XVNC == s->type) if (SCP_SESSION_TYPE_XVNC == s->type)
{ {
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting Xvnc session..."); log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting Xvnc session...");
display = session_start(s->width, s->height, s->bpp, s->username, display = session_start(s->width, s->height, s->bpp, s->username,
s->password, data, SESMAN_SESSION_TYPE_XVNC, s->password, data, SESMAN_SESSION_TYPE_XVNC,
s->domain, s->program, s->directory); s->domain, s->program, s->directory, s->client_ip);
} }
else else
{ {
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting X11rdp session..."); log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting X11rdp session...");
display = session_start(s->width, s->height, s->bpp, s->username, display = session_start(s->width, s->height, s->bpp, s->username,
s->password, data, SESMAN_SESSION_TYPE_XRDP, s->password, data, SESMAN_SESSION_TYPE_XRDP,
s->domain, s->program, s->directory); s->domain, s->program, s->directory, s->client_ip);
} }
e = scp_v1s_connect_new_session(c, display); e = scp_v1s_connect_new_session(c, display);
@ -160,8 +167,14 @@ scp_v1_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
display=sitem->display; display=sitem->display;
/*e=scp_v1s_reconnect_session(c, sitem, display);*/ /*e=scp_v1s_reconnect_session(c, sitem, display);*/
e=scp_v1s_reconnect_session(c, display); e=scp_v1s_reconnect_session(c, display);
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "User %s reconnected to session %d on port %d", \ if (0 != s->client_ip)
s->username, sitem->pid, display); {
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ reconnected session: username %s, display :%d.0, session_pid %d, ip %s", s->username, display, sitem->pid, s->client_ip);
}
else
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ reconnected session: username %s, display :%d.0, session_pid %d", s->username, display, sitem->pid);
}
g_free(sitem); g_free(sitem);
} }
break; break;

@ -45,6 +45,7 @@ static char* g_sync_password;
static char* g_sync_domain; static char* g_sync_domain;
static char* g_sync_program; static char* g_sync_program;
static char* g_sync_directory; static char* g_sync_directory;
static char* g_sync_client_ip;
static tbus g_sync_data; static tbus g_sync_data;
static tui8 g_sync_type; static tui8 g_sync_type;
static int g_sync_result; static int g_sync_result;
@ -305,7 +306,7 @@ wait_for_xserver(int display)
static int APP_CC static int APP_CC
session_start_fork(int width, int height, int bpp, char* username, session_start_fork(int width, int height, int bpp, char* username,
char* password, tbus data, tui8 type, char* domain, char* password, tbus data, tui8 type, char* domain,
char* program, char* directory) char* program, char* directory, char* client_ip)
{ {
int display = 0; int display = 0;
int pid = 0; int pid = 0;
@ -556,6 +557,7 @@ session_start_fork(int width, int height, int bpp, char* username,
temp->item->height = height; temp->item->height = height;
temp->item->bpp = bpp; temp->item->bpp = bpp;
temp->item->data = data; temp->item->data = data;
g_strncpy(temp->item->client_ip, client_ip, 255); /* store client ip data */
g_strncpy(temp->item->name, username, 255); g_strncpy(temp->item->name, username, 255);
ltime = g_time1(); ltime = g_time1();
@ -584,7 +586,7 @@ session_start_fork(int width, int height, int bpp, char* username,
int DEFAULT_CC int DEFAULT_CC
session_start(int width, int height, int bpp, char* username, char* password, session_start(int width, int height, int bpp, char* username, char* password,
long data, tui8 type, char* domain, char* program, long data, tui8 type, char* domain, char* program,
char* directory) char* directory, char* client_ip)
{ {
int display; int display;
@ -599,6 +601,7 @@ session_start(int width, int height, int bpp, char* username, char* password,
g_sync_domain = domain; g_sync_domain = domain;
g_sync_program = program; g_sync_program = program;
g_sync_directory = directory; g_sync_directory = directory;
g_sync_client_ip = client_ip;
g_sync_data = data; g_sync_data = data;
g_sync_type = type; g_sync_type = type;
/* set event for main thread to see */ /* set event for main thread to see */
@ -620,7 +623,7 @@ session_sync_start(void)
g_sync_result = session_start_fork(g_sync_width, g_sync_height, g_sync_bpp, g_sync_result = session_start_fork(g_sync_width, g_sync_height, g_sync_bpp,
g_sync_username, g_sync_password, g_sync_username, g_sync_password,
g_sync_data, g_sync_type, g_sync_domain, g_sync_data, g_sync_type, g_sync_domain,
g_sync_program, g_sync_directory); g_sync_program, g_sync_directory, g_sync_client_ip);
lock_sync_sem_release(); lock_sync_sem_release();
return 0; return 0;
} }
@ -662,8 +665,7 @@ session_kill(int pid)
if (tmp->item->pid == pid) if (tmp->item->pid == pid)
{ {
/* deleting the session */ /* deleting the session */
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "session %d - user %s - " log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ terminated session: username %s, display :%d.0, session_pid %d, ip %s", tmp->item->name, tmp->item->display, tmp->item->pid, tmp->item->client_ip);
"terminated", tmp->item->pid, tmp->item->name);
g_free(tmp->item); g_free(tmp->item);
if (prev == 0) if (prev == 0)
{ {

@ -75,6 +75,7 @@ struct session_item
struct session_date connect_time; struct session_date connect_time;
struct session_date disconnect_time; struct session_date disconnect_time;
struct session_date idle_time; struct session_date idle_time;
char client_ip[256];
}; };
struct session_chain struct session_chain
@ -104,7 +105,7 @@ session_get_bydata(char* name, int width, int height, int bpp, int type);
int DEFAULT_CC int DEFAULT_CC
session_start(int width, int height, int bpp, char* username, char* password, session_start(int width, int height, int bpp, char* username, char* password,
long data, tui8 type, char* domain, char* program, long data, tui8 type, char* domain, char* program,
char* directory); char* directory, char* client_ip);
/** /**
* *

@ -172,11 +172,19 @@ xrdp_mm_send_login(struct xrdp_mm* self)
index = g_strlen(self->wm->client_info->program); index = g_strlen(self->wm->client_info->program);
out_uint16_be(s, index); out_uint16_be(s, index);
out_uint8a(s, self->wm->client_info->program, index); out_uint8a(s, self->wm->client_info->program, index);
/* send directory */ /* send directory */
index = g_strlen(self->wm->client_info->directory); index = g_strlen(self->wm->client_info->directory);
out_uint16_be(s, index); out_uint16_be(s, index);
out_uint8a(s, self->wm->client_info->directory, index); out_uint8a(s, self->wm->client_info->directory, index);
/* send client ip */
index = g_strlen(self->wm->client_info->client_ip);
out_uint16_be(s, index);
out_uint8a(s, self->wm->client_info->client_ip, index);
s_mark_end(s); s_mark_end(s);
s_pop_layer(s, channel_hdr); s_pop_layer(s, channel_hdr);
out_uint32_be(s, 0); /* version */ out_uint32_be(s, 0); /* version */
index = (int)(s->end - s->data); index = (int)(s->end - s->data);

Loading…
Cancel
Save