From 9a517b34f0f4eb546c46ad4185260f4b66773a8c Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Sun, 4 Dec 2016 15:39:10 -0800 Subject: [PATCH] vnc: code cleanup --- common/os_calls.c | 28 ++++++++++++++++++++++++++++ common/os_calls.h | 2 ++ sesman/session.c | 17 +++-------------- vnc/vnc.c | 10 +--------- xrdp/xrdp_mm.c | 2 +- 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/common/os_calls.c b/common/os_calls.c index d8e711b8..9ebaa880 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -2530,6 +2530,34 @@ g_htoi(char *str) return rv; } +/*****************************************************************************/ +/* returns number of bytes copied into out_str */ +int APP_CC +g_bytes_to_hexstr(const void *bytes, int num_bytes, char *out_str, + int bytes_out_str) +{ + int rv; + int index; + char *lout_str; + const tui8 *lbytes; + + rv = 0; + lbytes = (const tui8 *) bytes; + lout_str = out_str; + for (index = 0; index < num_bytes; index++) + { + if (bytes_out_str < 3) + { + break; + } + g_snprintf(lout_str, bytes_out_str, "%2.2x", lbytes[index]); + lout_str += 2; + bytes_out_str -= 2; + rv += 2; + } + return rv; +} + /*****************************************************************************/ int APP_CC g_pos(const char *str, const char *to_find) diff --git a/common/os_calls.h b/common/os_calls.h index 00e91a1d..6a206726 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -134,6 +134,8 @@ int APP_CC g_strcasecmp(const char* c1, const char* c2); int APP_CC g_strncasecmp(const char* c1, const char* c2, int len); int APP_CC g_atoi(const char* str); int APP_CC g_htoi(char* str); +int APP_CC g_bytes_to_hexstr(const void *bytes, int num_bytes, char *out_str, + int bytes_out_str); int APP_CC g_pos(const char* str, const char* to_find); int APP_CC g_mbstowcs(twchar* dest, const char* src, int n); int APP_CC g_wcstombs(char* dest, const twchar* src, int n); diff --git a/sesman/session.c b/sesman/session.c index 778e8b4c..de3b9f70 100644 --- a/sesman/session.c +++ b/sesman/session.c @@ -697,20 +697,9 @@ session_start_fork(tbus data, tui8 type, struct SCP_SESSION *s) } else if (type == SESMAN_SESSION_TYPE_XVNC) { - if (s->guid != 0) - { - char guid_str[64]; - char *pguid_str; - int index; - pguid_str = guid_str; - for (index = 0; index < 16; index++) - { - g_snprintf(pguid_str, 4, "%2.2x", s->guid[index]); - pguid_str += 2; - } - guid_str[32] = 0; - env_check_password_file(passwd_file, guid_str); - } + char guid_str[64]; + g_bytes_to_hexstr(s->guid, 16, guid_str, 64); + env_check_password_file(passwd_file, guid_str); xserver_params = list_create(); xserver_params->auto_free = 1; diff --git a/vnc/vnc.c b/vnc/vnc.c index 040a67c4..8fe3a8bc 100644 --- a/vnc/vnc.c +++ b/vnc/vnc.c @@ -1097,15 +1097,7 @@ lib_mod_connect(struct vnc *v) if (v->got_guid) { char guid_str[64]; - char *pguid_str; - int index; - pguid_str = guid_str; - for (index = 0; index < 16; index++) - { - g_snprintf(pguid_str, 4, "%2.2x", v->guid[index]); - pguid_str += 2; - } - guid_str[32] = 0; + g_bytes_to_hexstr(v->guid, 16, guid_str, 64); rfbHashEncryptBytes(s->data, guid_str); } else diff --git a/xrdp/xrdp_mm.c b/xrdp/xrdp_mm.c index 8d1c251c..715a18fc 100644 --- a/xrdp/xrdp_mm.c +++ b/xrdp/xrdp_mm.c @@ -565,7 +565,7 @@ xrdp_mm_setup_mod2(struct xrdp_mm *self, tui8 *guid) self->mod->mod_set_param(self->mod, "keylayout", text); if (guid != 0) { - self->mod->mod_set_param(self->mod, "guid", (char*)guid); + self->mod->mod_set_param(self->mod, "guid", (char *) guid); } for (i = 0; i < self->login_names->count; i++)