From bde5dd66713cec177846627bf026d8bcddbb41a8 Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Sat, 26 May 2012 17:24:04 -0700 Subject: [PATCH] added g_close_wait_obj and size parameter to g_write_ip_address --- common/os_calls.c | 43 +++++++++++++++++++++++++++++-------------- common/os_calls.h | 4 +++- libxrdp/xrdp_rdp.c | 5 ++++- xrdp/xrdp.c | 4 ++-- xrdp/xrdp_listen.c | 2 +- 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/common/os_calls.c b/common/os_calls.c index 466cdbdf..65c6808a 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -562,31 +562,33 @@ g_tcp_accept(int sck) /*****************************************************************************/ void APP_CC -g_write_ip_address(int rcv_sck, char* ip_address) +g_write_ip_address(int rcv_sck, char* ip_address, int bytes) { struct sockaddr_in s; struct in_addr in; int len; int ip_port; + int ok; - memset(&s,0,sizeof(&s)); + ok = 0; + 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) + if (getpeername(rcv_sck,(struct sockaddr*)&s, &len) == 0) { - sprintf(ip_address, "%s:%d - socket: %d", inet_ntoa(in), ip_port, rcv_sck); + memset(&in, 0, sizeof(in)); + in.s_addr = s.sin_addr.s_addr; + ip_port = ntohs(s.sin_port); + if (ip_port != 0) + { + ok = 1; + snprintf(ip_address, bytes, "%s:%d - socket: %d", inet_ntoa(in), + ip_port, rcv_sck); + } } - else + if (!ok) { - sprintf(ip_address, "NULL:NULL - socket: %d", rcv_sck); + snprintf(ip_address, bytes, "NULL:NULL - socket: %d", rcv_sck); } - } /*****************************************************************************/ @@ -995,6 +997,19 @@ g_delete_wait_obj(tbus obj) #endif } +/*****************************************************************************/ +/* returns error */ +/* close but do not delete the wait obj, used after fork */ +int APP_CC +g_close_wait_obj(tbus obj) +{ +#ifdef _WIN32 +#else + close((int)obj); +#endif + return 0; +} + /*****************************************************************************/ /* returns error */ int APP_CC diff --git a/common/os_calls.h b/common/os_calls.h index 5c7d848e..009a9079 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -104,7 +104,7 @@ 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); +g_write_ip_address(int rcv_sck, char* ip_address, int bytes); void APP_CC g_sleep(int msecs); tbus APP_CC @@ -122,6 +122,8 @@ g_is_wait_obj_set(tbus obj); int APP_CC g_delete_wait_obj(tbus obj); int APP_CC +g_close_wait_obj(tbus obj); +int APP_CC g_obj_wait(tbus* read_objs, int rcount, tbus* write_objs, int wcount, int mstimeout); void APP_CC diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index bdbeed48..f25ec274 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -136,6 +136,7 @@ struct xrdp_rdp* APP_CC xrdp_rdp_create(struct xrdp_session* session, struct trans* trans) { struct xrdp_rdp* self = (struct xrdp_rdp *)NULL; + int bytes; DEBUG(("in xrdp_rdp_create")); self = (struct xrdp_rdp*)g_malloc(sizeof(struct xrdp_rdp), 1); @@ -153,7 +154,9 @@ 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 */ + /* load client ip info */ + bytes = sizeof(self->client_info.client_ip) - 1; + g_write_ip_address(trans->sck, self->client_info.client_ip, bytes); #if defined(XRDP_FREERDP1) self->mppc_enc = mppc_enc_new(PROTO_RDP_50); #endif diff --git a/xrdp/xrdp.c b/xrdp/xrdp.c index d43870f2..d88fd677 100644 --- a/xrdp/xrdp.c +++ b/xrdp/xrdp.c @@ -111,8 +111,8 @@ xrdp_child_fork(void) char text[256]; /* close, don't delete these */ - g_tcp_close((int)g_term_event); - g_tcp_close((int)g_sync_event); + g_close_wait_obj(g_term_event); + g_close_wait_obj(g_sync_event); pid = g_getpid(); g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid); g_term_event = g_create_wait_obj(text); diff --git a/xrdp/xrdp_listen.c b/xrdp/xrdp_listen.c index dd85d245..36980b15 100644 --- a/xrdp/xrdp_listen.c +++ b/xrdp/xrdp_listen.c @@ -204,7 +204,7 @@ xrdp_listen_fork(struct xrdp_listen* self, struct trans* server_trans) xrdp_child_fork(); /* recreate the process done wait object, not used in fork mode */ /* close, don't delete this */ - g_tcp_close((int)(self->pro_done_event)); + g_close_wait_obj(self->pro_done_event); xrdp_listen_create_pro_done(self); /* delete listener, child need not listen */ trans_delete(self->listen_trans);