Skip to content

Commit

Permalink
Implemented client IP logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolar committed Nov 4, 2010
1 parent 87297c5 commit d797b2c
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 14 deletions.
29 changes: 29 additions & 0 deletions common/os_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,35 @@ g_tcp_accept(int sck)
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
g_sleep(int msecs)
Expand Down
2 changes: 2 additions & 0 deletions common/os_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ g_tcp_can_recv(int sck, int millis);
int APP_CC
g_tcp_select(int sck1, int sck2);
void APP_CC
g_write_ip_address(int rcv_sck, char* ip_address);
void APP_CC
g_sleep(int msecs);
tbus APP_CC
g_create_wait_obj(char* name);
Expand Down
1 change: 1 addition & 0 deletions libxrdp/libxrdpinc.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct xrdp_client_info
int rdp5_performanceflags;
int brush_cache_code; /* 0 = no cache 1 = 8x8 standard cache
2 = arbitrary dimensions */
char client_ip[256];
};

struct xrdp_brush
Expand Down
1 change: 1 addition & 0 deletions libxrdp/xrdp_rdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ xrdp_rdp_create(struct xrdp_session* session, struct trans* trans)
self->client_info.cache2_size = 1024;
self->client_info.cache3_entries = 262;
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"));
return self;
}
Expand Down
23 changes: 23 additions & 0 deletions sesman/libscp/libscp_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,28 @@ scp_session_set_directory(struct SCP_SESSION* s, char* str)
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
scp_session_set_hostname(struct SCP_SESSION* s, char* str)
Expand Down Expand Up @@ -380,6 +402,7 @@ scp_session_destroy(struct SCP_SESSION* s)
g_free(s->domain);
g_free(s->program);
g_free(s->directory);
g_free(s->client_ip);
g_free(s->errstr);
g_free(s->mng);
g_free(s);
Expand Down
3 changes: 3 additions & 0 deletions sesman/libscp/libscp_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ scp_session_set_program(struct SCP_SESSION* s, char* str);
int
scp_session_set_directory(struct SCP_SESSION* s, char* str);

int
scp_session_set_client_ip(struct SCP_SESSION* s, char* str);

int
scp_session_set_hostname(struct SCP_SESSION* s, char* str);

Expand Down
1 change: 1 addition & 0 deletions sesman/libscp/libscp_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct SCP_SESSION
char* domain;
char* program;
char* directory;
char* client_ip;
};

struct SCP_DISCONNECTED_SESSION
Expand Down
11 changes: 11 additions & 0 deletions sesman/libscp/libscp_v0.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,17 @@ scp_v0s_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s, int skipVchk)
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
{
Expand Down
22 changes: 19 additions & 3 deletions sesman/scp_v0.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
if (s_item != 0)
{
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);
/* don't set data to null here */
}
Expand All @@ -53,20 +61,28 @@ scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
LOG_DBG(&(g_cfg->log), "pre auth");
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)
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting Xvnc session...");
display = session_start(s->width, s->height, s->bpp, s->username,
s->password, data, SESMAN_SESSION_TYPE_XVNC,
s->domain, s->program, s->directory);
s->domain, s->program, s->directory, s->client_ip);
}
else
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting X11rdp session...");
display = session_start(s->width, s->height, s->bpp, s->username,
s->password, data, SESMAN_SESSION_TYPE_XRDP,
s->domain, s->program, s->directory);
s->domain, s->program, s->directory, s->client_ip);
}
}
else
Expand Down
23 changes: 18 additions & 5 deletions sesman/scp_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,27 @@ scp_v1_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
if (scount == 0)
{
/* 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)
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting Xvnc session...");
display = session_start(s->width, s->height, s->bpp, s->username,
s->password, data, SESMAN_SESSION_TYPE_XVNC,
s->domain, s->program, s->directory);
s->domain, s->program, s->directory, s->client_ip);
}
else
{
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting X11rdp session...");
display = session_start(s->width, s->height, s->bpp, s->username,
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);
Expand Down Expand Up @@ -160,8 +167,14 @@ scp_v1_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
display=sitem->display;
/*e=scp_v1s_reconnect_session(c, sitem, 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", \
s->username, sitem->pid, 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, 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);
}
break;
Expand Down
12 changes: 7 additions & 5 deletions sesman/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static char* g_sync_password;
static char* g_sync_domain;
static char* g_sync_program;
static char* g_sync_directory;
static char* g_sync_client_ip;
static tbus g_sync_data;
static tui8 g_sync_type;
static int g_sync_result;
Expand Down Expand Up @@ -305,7 +306,7 @@ wait_for_xserver(int display)
static int APP_CC
session_start_fork(int width, int height, int bpp, char* username,
char* password, tbus data, tui8 type, char* domain,
char* program, char* directory)
char* program, char* directory, char* client_ip)
{
int display = 0;
int pid = 0;
Expand Down Expand Up @@ -556,6 +557,7 @@ session_start_fork(int width, int height, int bpp, char* username,
temp->item->height = height;
temp->item->bpp = bpp;
temp->item->data = data;
g_strncpy(temp->item->client_ip, client_ip, 255); /* store client ip data */
g_strncpy(temp->item->name, username, 255);

ltime = g_time1();
Expand Down Expand Up @@ -584,7 +586,7 @@ session_start_fork(int width, int height, int bpp, char* username,
int DEFAULT_CC
session_start(int width, int height, int bpp, char* username, char* password,
long data, tui8 type, char* domain, char* program,
char* directory)
char* directory, char* client_ip)
{
int display;

Expand All @@ -599,6 +601,7 @@ session_start(int width, int height, int bpp, char* username, char* password,
g_sync_domain = domain;
g_sync_program = program;
g_sync_directory = directory;
g_sync_client_ip = client_ip;
g_sync_data = data;
g_sync_type = type;
/* set event for main thread to see */
Expand All @@ -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_username, g_sync_password,
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();
return 0;
}
Expand Down Expand Up @@ -662,8 +665,7 @@ session_kill(int pid)
if (tmp->item->pid == pid)
{
/* deleting the session */
log_message(&(g_cfg->log), LOG_LEVEL_INFO, "session %d - user %s - "
"terminated", tmp->item->pid, tmp->item->name);
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);
g_free(tmp->item);
if (prev == 0)
{
Expand Down
3 changes: 2 additions & 1 deletion sesman/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct session_item
struct session_date connect_time;
struct session_date disconnect_time;
struct session_date idle_time;
char client_ip[256];
};

struct session_chain
Expand Down Expand Up @@ -104,7 +105,7 @@ session_get_bydata(char* name, int width, int height, int bpp, int type);
int DEFAULT_CC
session_start(int width, int height, int bpp, char* username, char* password,
long data, tui8 type, char* domain, char* program,
char* directory);
char* directory, char* client_ip);

/**
*
Expand Down
8 changes: 8 additions & 0 deletions xrdp/xrdp_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,19 @@ xrdp_mm_send_login(struct xrdp_mm* self)
index = g_strlen(self->wm->client_info->program);
out_uint16_be(s, index);
out_uint8a(s, self->wm->client_info->program, index);

/* send directory */
index = g_strlen(self->wm->client_info->directory);
out_uint16_be(s, 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_pop_layer(s, channel_hdr);
out_uint32_be(s, 0); /* version */
index = (int)(s->end - s->data);
Expand Down

0 comments on commit d797b2c

Please sign in to comment.