Make xrdp_wm_log_msg() log its output

Accept variable arguments and the log level in xrdp_wm_log_msg(). Remove
logging that is done automatically now.
master
Pavel Roskin 9 years ago
parent 27ba5b4e86
commit a1b7de5679

@ -37,6 +37,7 @@
#include "file.h" #include "file.h"
#include "file_loc.h" #include "file_loc.h"
#include "xrdp_client_info.h" #include "xrdp_client_info.h"
#include "log.h"
/* xrdp.c */ /* xrdp.c */
long APP_CC long APP_CC
@ -140,7 +141,8 @@ xrdp_wm_delete_all_children(struct xrdp_wm* self);
int APP_CC int APP_CC
xrdp_wm_show_log(struct xrdp_wm *self); xrdp_wm_show_log(struct xrdp_wm *self);
int APP_CC int APP_CC
xrdp_wm_log_msg(struct xrdp_wm* self, char* msg); xrdp_wm_log_msg(struct xrdp_wm *self, enum logLevels loglevel,
const char *fmt, ...) printflike(3, 4);
int APP_CC int APP_CC
xrdp_wm_get_wait_objs(struct xrdp_wm* self, tbus* robjs, int* rc, xrdp_wm_get_wait_objs(struct xrdp_wm* self, tbus* robjs, int* rc,
tbus* wobjs, int* wc, int* timeout); tbus* wobjs, int* wc, int* timeout);

@ -176,8 +176,8 @@ xrdp_mm_send_login(struct xrdp_mm *self)
char *name; char *name;
char *value; char *value;
xrdp_wm_log_msg(self->wm, "sending login info to session manager, " xrdp_wm_log_msg(self->wm, LOG_LEVEL_DEBUG,
"please wait..."); "sending login info to session manager, please wait...");
username = 0; username = 0;
password = 0; password = 0;
self->code = 0; self->code = 0;
@ -210,7 +210,8 @@ xrdp_mm_send_login(struct xrdp_mm *self)
if ((username == 0) || (password == 0)) if ((username == 0) || (password == 0))
{ {
xrdp_wm_log_msg(self->wm, "Error finding username and password"); xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
"Error finding username and password");
return 1; return 1;
} }
@ -277,7 +278,8 @@ xrdp_mm_send_login(struct xrdp_mm *self)
if (rv != 0) if (rv != 0)
{ {
xrdp_wm_log_msg(self->wm, "xrdp_mm_send_login: xrdp_mm_send_login failed"); xrdp_wm_log_msg(self->wm, LOG_LEVEL_WARNING,
"xrdp_mm_send_login: xrdp_mm_send_login failed");
} }
return rv; return rv;
@ -339,18 +341,18 @@ xrdp_mm_setup_mod1(struct xrdp_mm *self)
if (xrdp_mm_get_value(self, "lib", lib, 255) != 0) if (xrdp_mm_get_value(self, "lib", lib, 255) != 0)
{ {
g_snprintf(text, 255, "no library name specified in xrdp.ini, please add " xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
"lib=libxrdp-vnc.so or similar"); "no library name specified in xrdp.ini, please add "
xrdp_wm_log_msg(self->wm, text); "lib=libxrdp-vnc.so or similar");
return 1; return 1;
} }
if (lib[0] == 0) if (lib[0] == 0)
{ {
g_snprintf(text, 255, "empty library name specified in xrdp.ini, please " xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
"add lib=libxrdp-vnc.so or similar"); "empty library name specified in xrdp.ini, please "
xrdp_wm_log_msg(self->wm, text); "add lib=libxrdp-vnc.so or similar");
return 1; return 1;
} }
@ -372,10 +374,9 @@ xrdp_mm_setup_mod1(struct xrdp_mm *self)
if (func == 0) if (func == 0)
{ {
g_snprintf(text, 255, "error finding proc mod_init in %s, not a valid " xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
"xrdp backend", lib); "error finding proc mod_init in %s, "
xrdp_wm_log_msg(self->wm, text); "not a valid xrdp backend", lib);
log_message(LOG_LEVEL_ERROR, "%s", text);
} }
self->mod_init = (struct xrdp_mod * ( *)(void))func; self->mod_init = (struct xrdp_mod * ( *)(void))func;
@ -388,10 +389,9 @@ xrdp_mm_setup_mod1(struct xrdp_mm *self)
if (func == 0) if (func == 0)
{ {
g_snprintf(text, 255, "error finding proc mod_exit in %s, not a valid " xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
"xrdp backend", lib); "error finding proc mod_exit in %s, "
xrdp_wm_log_msg(self->wm, text); "not a valid xrdp backend", lib);
log_message(LOG_LEVEL_ERROR, "%s", text);
} }
self->mod_exit = (int ( *)(struct xrdp_mod *))func; self->mod_exit = (int ( *)(struct xrdp_mod *))func;
@ -413,10 +413,10 @@ xrdp_mm_setup_mod1(struct xrdp_mm *self)
} }
else else
{ {
g_snprintf(text, 255, "error loading %s specified in xrdp.ini, please " xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
"add a valid entry like lib=libxrdp-vnc.so or similar", lib); "error loading %s specified in xrdp.ini, please "
xrdp_wm_log_msg(self->wm, text); "add a valid entry like lib=libxrdp-vnc.so or "
log_message(LOG_LEVEL_ERROR, "%s", text); "similar", lib);
return 1; return 1;
} }
@ -1192,7 +1192,6 @@ xrdp_mm_process_login_response(struct xrdp_mm *self, struct stream *s)
int ok; int ok;
int display; int display;
int rv; int rv;
char text[256];
char ip[256]; char ip[256];
char port[256]; char port[256];
@ -1203,9 +1202,9 @@ xrdp_mm_process_login_response(struct xrdp_mm *self, struct stream *s)
if (ok) if (ok)
{ {
self->display = display; self->display = display;
g_snprintf(text, 255, "xrdp_mm_process_login_response: login successful " xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,
"for display %d", display); "xrdp_mm_process_login_response: login successful "
xrdp_wm_log_msg(self->wm, text); "for display %d", display);
if (xrdp_mm_setup_mod1(self) == 0) if (xrdp_mm_setup_mod1(self) == 0)
{ {
@ -1231,10 +1230,8 @@ xrdp_mm_process_login_response(struct xrdp_mm *self, struct stream *s)
} }
else else
{ {
xrdp_wm_log_msg(self->wm, "xrdp_mm_process_login_response: " xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,
"login failed"); "xrdp_mm_process_login_response: login failed");
log_message(LOG_LEVEL_INFO,"xrdp_mm_process_login_response: "
"login failed");
xrdp_wm_show_log(self->wm); xrdp_wm_show_log(self->wm);
if (self->wm->hide_log_window) if (self->wm->hide_log_window)
{ {
@ -1398,8 +1395,9 @@ xrdp_mm_sesman_data_in(struct trans *trans)
error = xrdp_mm_process_login_response(self, s); error = xrdp_mm_process_login_response(self, s);
break; break;
default: default:
xrdp_wm_log_msg(self->wm, "An undefined reply code was received from sesman"); xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
log_message(LOG_LEVEL_ERROR,"Fatal xrdp_mm_sesman_data_in: unknown cmd code %d", code); "Undefined reply code %d received from sesman",
code);
cleanup_sesman_connection(self); cleanup_sesman_connection(self);
break; break;
} }
@ -1801,8 +1799,6 @@ xrdp_mm_connect(struct xrdp_mm *self)
char *name; char *name;
char *value; char *value;
char ip[256]; char ip[256];
char errstr[256];
char text[256];
char port[8]; char port[8];
char chansrvport[256]; char chansrvport[256];
#ifdef ACCESS #ifdef ACCESS
@ -1820,8 +1816,6 @@ xrdp_mm_connect(struct xrdp_mm *self)
/* make sure we start in correct state */ /* make sure we start in correct state */
cleanup_states(self); cleanup_states(self);
g_memset(ip, 0, sizeof(ip)); g_memset(ip, 0, sizeof(ip));
g_memset(errstr, 0, sizeof(errstr));
g_memset(text, 0, sizeof(text));
g_memset(port, 0, sizeof(port)); g_memset(port, 0, sizeof(port));
g_memset(chansrvport, 0, sizeof(chansrvport)); g_memset(chansrvport, 0, sizeof(chansrvport));
rv = 0; /* success */ rv = 0; /* success */
@ -1884,10 +1878,10 @@ xrdp_mm_connect(struct xrdp_mm *self)
if (use_pam_auth) if (use_pam_auth)
{ {
int reply; int reply;
char replytxt[128];
char pam_error[128]; char pam_error[128];
const char *additionalError; const char *additionalError;
xrdp_wm_log_msg(self->wm, "Please wait, we now perform access control..."); xrdp_wm_log_msg(self->wm, LOG_LEVEL_DEBUG,
"Please wait, we now perform access control...");
/* g_writeln("we use pam modules to check if we can approve this user"); */ /* g_writeln("we use pam modules to check if we can approve this user"); */
if (!g_strncmp(pam_auth_username, "same", 255)) if (!g_strncmp(pam_auth_username, "same", 255))
@ -1905,19 +1899,14 @@ xrdp_mm_connect(struct xrdp_mm *self)
/* access_control return 0 on success */ /* access_control return 0 on success */
reply = access_control(pam_auth_username, pam_auth_password, pam_auth_sessionIP); reply = access_control(pam_auth_username, pam_auth_password, pam_auth_sessionIP);
g_sprintf(replytxt, "Reply from access control: %s", xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO,
getPAMError(reply, pam_error, 127)); "Reply from access control: %s",
getPAMError(reply, pam_error, 127));
xrdp_wm_log_msg(self->wm, replytxt);
log_message(LOG_LEVEL_INFO, "%s", replytxt);
additionalError = getPAMAdditionalErrorInfo(reply, self); additionalError = getPAMAdditionalErrorInfo(reply, self);
if (additionalError) if (additionalError && additionalError[0])
{ {
g_snprintf(replytxt, 127, "%s", additionalError); xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO, "%s", additionalError);
if (replytxt[0])
{
xrdp_wm_log_msg(self->wm, replytxt);
}
} }
if (reply != 0) if (reply != 0)
@ -1936,8 +1925,8 @@ xrdp_mm_connect(struct xrdp_mm *self)
self->sesman_trans = trans_create(TRANS_MODE_TCP, 8192, 8192); self->sesman_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
self->sesman_trans->is_term = g_is_term; self->sesman_trans->is_term = g_is_term;
xrdp_mm_get_sesman_port(port, sizeof(port)); xrdp_mm_get_sesman_port(port, sizeof(port));
g_snprintf(text, 255, "connecting to sesman ip %s port %s", ip, port); xrdp_wm_log_msg(self->wm, LOG_LEVEL_DEBUG,
xrdp_wm_log_msg(self->wm, text); "connecting to sesman ip %s port %s", ip, port);
/* xrdp_mm_sesman_data_in is the callback that is called when data arrives */ /* xrdp_mm_sesman_data_in is the callback that is called when data arrives */
self->sesman_trans->trans_data_in = xrdp_mm_sesman_data_in; self->sesman_trans->trans_data_in = xrdp_mm_sesman_data_in;
self->sesman_trans->header_size = 8; self->sesman_trans->header_size = 8;
@ -1961,16 +1950,15 @@ xrdp_mm_connect(struct xrdp_mm *self)
if (ok) if (ok)
{ {
/* fully connect */ /* fully connect */
xrdp_wm_log_msg(self->wm, "sesman connect ok"); xrdp_wm_log_msg(self->wm, LOG_LEVEL_INFO, "sesman connect ok");
self->connected_state = 1; self->connected_state = 1;
rv = xrdp_mm_send_login(self); rv = xrdp_mm_send_login(self);
} }
else else
{ {
g_snprintf(errstr, 255, "Failure to connect to sesman: %s port: %s", xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
ip, port); "Error connecting to sesman: %s port: %s",
xrdp_wm_log_msg(self->wm, errstr); ip, port);
log_message(LOG_LEVEL_ERROR, "%s", errstr);
trans_delete(self->sesman_trans); trans_delete(self->sesman_trans);
self->sesman_trans = 0; self->sesman_trans = 0;
self->sesman_trans_up = 0; self->sesman_trans_up = 0;
@ -1989,9 +1977,8 @@ xrdp_mm_connect(struct xrdp_mm *self)
else else
{ {
/* connect error */ /* connect error */
g_snprintf(errstr, 255, "Failure to connect to: %s", ip); xrdp_wm_log_msg(self->wm, LOG_LEVEL_ERROR,
log_message(LOG_LEVEL_ERROR, "%s", errstr); "Error connecting to: %s", ip);
xrdp_wm_log_msg(self->wm, errstr);
rv = 1; /* failure */ rv = 1; /* failure */
} }
} }
@ -2664,7 +2651,7 @@ server_msg(struct xrdp_mod *mod, char *msg, int code)
} }
wm = (struct xrdp_wm *)(mod->wm); wm = (struct xrdp_wm *)(mod->wm);
return xrdp_wm_log_msg(wm, msg); return xrdp_wm_log_msg(wm, LOG_LEVEL_DEBUG, "%s", msg);
} }
/*****************************************************************************/ /*****************************************************************************/

@ -18,6 +18,8 @@
* simple window manager * simple window manager
*/ */
#include <stdarg.h>
#include <stdio.h>
#include "xrdp.h" #include "xrdp.h"
#include "log.h" #include "log.h"
@ -678,8 +680,9 @@ xrdp_wm_init(struct xrdp_wm *self)
{ {
/* requested module name not found in xrdp.ini */ /* requested module name not found in xrdp.ini */
g_writeln(" xrdp_wm_init: file_read_section returned non-zero, requested section not found in xrdp.ini"); g_writeln(" xrdp_wm_init: file_read_section returned non-zero, requested section not found in xrdp.ini");
xrdp_wm_log_msg(self, "ERROR: The requested xrdp module not found in xrdp.ini," xrdp_wm_log_msg(self, LOG_LEVEL_ERROR,
" falling back to login window"); "ERROR: The requested xrdp module not found in "
"xrdp.ini, falling back to login window");
} }
list_delete(names); list_delete(names);
@ -1965,8 +1968,17 @@ xrdp_wm_show_log(struct xrdp_wm *self)
/*****************************************************************************/ /*****************************************************************************/
int APP_CC int APP_CC
xrdp_wm_log_msg(struct xrdp_wm *self, char *msg) xrdp_wm_log_msg(struct xrdp_wm *self, enum logLevels loglevel,
const char *fmt, ...)
{ {
va_list ap;
char msg[256];
va_start(ap, fmt);
vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
log_message(loglevel, "xrdp_wm_log_msg: %s", msg);
add_string_to_logwindow(msg, self->log); add_string_to_logwindow(msg, self->log);
return 0; return 0;
} }

Loading…
Cancel
Save