Skip to content

Commit

Permalink
log client ip with pid, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
jsorg71 committed Oct 2, 2013
1 parent 7176f14 commit 2536946
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
35 changes: 35 additions & 0 deletions common/os_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,41 @@ g_tcp_accept(int sck)
return ret ;
}

/*****************************************************************************/
int APP_CC
g_sck_accept(int sck, char *addr, int addr_bytes, char *port, int port_bytes)
{
int ret;
char ipAddr[256];
struct sockaddr_in s;
#if defined(_WIN32)
signed int i;
#else
unsigned int i;
#endif

i = sizeof(struct sockaddr_in);
memset(&s, 0, i);
ret = accept(sck, (struct sockaddr *)&s, &i);
if (ret > 0)
{
g_snprintf(ipAddr, 255, "A connection received from: %s port %d",
inet_ntoa(s.sin_addr), ntohs(s.sin_port));
log_message(LOG_LEVEL_INFO,ipAddr);
if (s.sin_family == AF_INET)
{
g_snprintf(addr, addr_bytes, "%s", inet_ntoa(s.sin_addr));
g_snprintf(port, port_bytes, "%d", ntohs(s.sin_port));
}
if (s.sin_family == AF_UNIX)
{
g_strncpy(addr, "", addr_bytes - 1);
g_strncpy(port, "", port_bytes - 1);
}
}
return ret;
}

/*****************************************************************************/
void APP_CC
g_write_ip_address(int rcv_sck, char *ip_address, int bytes)
Expand Down
2 changes: 2 additions & 0 deletions common/os_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ int APP_CC g_tcp_local_bind(int sck, const char* port);
int APP_CC g_tcp_bind_address(int sck, const char* port, const char* address);
int APP_CC g_tcp_listen(int sck);
int APP_CC g_tcp_accept(int sck);
int APP_CC g_sck_accept(int sck, char *addr, int addr_bytes,
char *port, int port_bytes);
int APP_CC g_tcp_recv(int sck, void* ptr, int len, int flags);
int APP_CC g_tcp_send(int sck, const void* ptr, int len, int flags);
int APP_CC g_tcp_last_error_would_block(int sck);
Expand Down
7 changes: 5 additions & 2 deletions common/trans.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ trans_check_wait_objs(struct trans *self)
{
if (g_tcp_can_recv(self->sck, 0))
{
in_sck = g_tcp_accept(self->sck);
in_sck = g_sck_accept(self->sck, self->addr, sizeof(self->addr),
self->port, sizeof(self->port));

if (in_sck == -1)
{
Expand All @@ -223,6 +224,8 @@ trans_check_wait_objs(struct trans *self)
in_trans->type1 = TRANS_TYPE_SERVER;
in_trans->status = TRANS_STATUS_UP;
in_trans->is_term = self->is_term;
g_strncpy(in_trans->addr, self->addr, sizeof(self->addr) - 1);
g_strncpy(in_trans->port, self->port, sizeof(self->port) - 1);

if (self->trans_conn_in(self, in_trans) != 0)
{
Expand Down Expand Up @@ -466,7 +469,7 @@ trans_write_copy(struct trans *self)
{
temp_s = (struct stream *) (temp_s->next_packet);
}
temp_s->next_packet = wait_s;
temp_s->next_packet = (char *) wait_s;
}
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions common/trans.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct trans
char* listen_filename;
tis_term is_term; /* used to test for exit */
struct stream* wait_s;
char addr[256];
char port[256];
};

struct trans* APP_CC
Expand Down
2 changes: 2 additions & 0 deletions common/xrdp_client_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ struct xrdp_client_info
int pointer_flags; /* 0 color, 1 new, 2 no new */
int use_fast_path;
int require_credentials; /* when true, credentials *must* be passed on cmd line */
char client_addr[256];
char client_port[256];
};

#endif
8 changes: 8 additions & 0 deletions libxrdp/xrdp_rdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,14 @@ xrdp_rdp_incoming(struct xrdp_rdp *self)
MCS_USERCHANNEL_BASE;
xrdp_rdp_parse_client_mcs_data(self);
DEBUG(("out xrdp_rdp_incoming mcs channel %d", self->mcs_channel));

g_strncpy(self->client_info.client_addr,
self->sec_layer->mcs_layer->iso_layer->tcp_layer->trans->addr,
sizeof(self->client_info.client_addr) - 1);
g_strncpy(self->client_info.client_port,
self->sec_layer->mcs_layer->iso_layer->tcp_layer->trans->port,
sizeof(self->client_info.client_port) - 1);

return 0;
}

Expand Down
8 changes: 6 additions & 2 deletions xup/xup.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,12 @@ lib_mod_log_peer(struct mod *mod)
my_pid = g_getpid();
if (g_sck_get_peer_cred(mod->sck, &pid, &uid, &gid) == 0)
{
log_message(LOG_LEVEL_INFO, "lib_mod_log_peer: xrdp pid %d connected "
"to X11rdp pid %d", my_pid, pid);
log_message(LOG_LEVEL_INFO, "lib_mod_log_peer: xrdp_pid=%d connected "
"to X11rdp_pid=%d X11rdp_uid=%d X11rdp_gid=%d "
"client_ip=%s client_port=%s",
my_pid, pid, uid, gid,
mod->client_info.client_addr,
mod->client_info.client_port);
}
else
{
Expand Down

0 comments on commit 2536946

Please sign in to comment.