diff --git a/sesman/session.c b/sesman/session.c index 0540bc11..4e51867f 100644 --- a/sesman/session.c +++ b/sesman/session.c @@ -688,8 +688,11 @@ session_start_fork(tbus data, tui8 type, struct SCP_SESSION *s) g_snprintf(authfile, 255, "%s", ".Xauthority"); } - /* Add the entry in XAUTHORITY file */ - add_xauth_cookie(display, authfile); + /* Add the entry in XAUTHORITY file or exit if error */ + if (add_xauth_cookie(display, authfile) != 0) + { + g_exit(1); + } if (type == SESMAN_SESSION_TYPE_XORG) { diff --git a/sesman/xauth.c b/sesman/xauth.c index b4375b4f..c019b782 100644 --- a/sesman/xauth.c +++ b/sesman/xauth.c @@ -1,7 +1,8 @@ /** * xrdp: A Remote Desktop Protocol server. * - * Copyright (C) Jay Sorg 2004-2013 + * Copyright (C) Jay Sorg 2004-2017 + * Copyright (C) Emmanuel Blindauer 2004-2017 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,6 @@ * * @file xauth.c * @brief XAUTHORITY handling code - * @author Emmaunel Blindauer * */ @@ -34,24 +34,16 @@ int DEFAULT_CC add_xauth_cookie(int display, const char *file) { FILE *dp; - char cookie[33]; - char char_cookie[16]; + char cookie_str[33]; + char cookie_bin[16]; char xauth_str[256]; int ret; - g_random(char_cookie, 16); - g_bytes_to_hexstr(char_cookie, 16, cookie, 33); - cookie[32] = '\0'; + g_random(cookie_bin, 16); + g_bytes_to_hexstr(cookie_bin, 16, cookie_str, 33); - if (file == NULL) - { - g_sprintf(xauth_str, "xauth -q add :%d . %s", display, cookie); - } - else - { - g_sprintf(xauth_str, "xauth -q -f %s add :%d . %s", - file, display, cookie); - } + g_sprintf(xauth_str, "xauth -q -f %s add :%d . %s", + file, display, cookie_str); dp = popen(xauth_str, "r"); if (dp == NULL)