Skip to content

Commit

Permalink
Server: Optionally redirect messages to system log
Browse files Browse the repository at this point in the history
  • Loading branch information
dcommander committed Sep 17, 2024
1 parent 908bd7d commit 5eb457c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 16 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
1. Added a new Xvnc command-line option (`-noserverkeymap`) that can be used to
disable the server-side key mapping feature introduced in 3.1 beta1[4].

2. Added a new Xvnc command-line option (`-syslog`) that can be used to
redirect all TurboVNC Server and X.org errors, warnings, and messages to the
system log.


3.1.2
=====
Expand Down
5 changes: 5 additions & 0 deletions unix/Xvnc/programs/Xserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ foreach(typeof typeof __typeof__)
break()
endif()
endforeach()
check_symbol_exists(syslog syslog.h HAVE_SYSLOG)
check_symbol_exists(vsyslog syslog.h HAVE_VSYSLOG)
if(HAVE_SYSLOG AND HAVE_VSYSLOG)
add_definitions(-DDDXOSVERRORF)
endif()
set(CMAKE_REQUIRED_LIBRARIES rt)
check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
if(HAVE_CLOCK_GETTIME)
Expand Down
75 changes: 65 additions & 10 deletions unix/Xvnc/programs/Xserver/hw/vnc/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ from the X Consortium.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifdef DDXOSVERRORF
#include <syslog.h>
#endif
#include <unistd.h>
#include <sys/types.h>
#include <netdb.h>
Expand Down Expand Up @@ -116,6 +120,9 @@ static Bool noCursor = FALSE;
char *desktopName = DEFAULT_DESKTOP_NAME;
int traceLevel = 0;
int rfbLEDState = (int)rfbLEDUnknown;
#ifdef DDXOSVERRORF
static Bool sysLog = FALSE;
#endif

char rfbThisHost[256];

Expand Down Expand Up @@ -706,6 +713,13 @@ int ddxProcessArgument(int argc, char *argv[], int i)
}
#endif

#ifdef DDXOSVERRORF
if (strcasecmp(argv[i], "-syslog") == 0) {
sysLog = TRUE;
return 1;
}
#endif

if (strcasecmp(argv[i], "-verbose") == 0) {
LogSetParameter(XLOG_VERBOSITY, X_DEBUG);
return 1;
Expand Down Expand Up @@ -1663,6 +1677,15 @@ void DDXRingBell(int percent, int pitch, int duration)
}


#ifdef DDXOSVERRORF
static void OsVendorVErrorF(const char *f, va_list args)
{
if (sysLog)
vsyslog(LOG_ERR, f, args);
}
#endif


void OsVendorInit(void)
{
InitRFB();
Expand Down Expand Up @@ -1697,11 +1720,21 @@ void OsVendorInit(void)
rfbAuthPAMSession = FALSE;
}
#endif
#ifdef DDXOSVERRORF
if (!OsVendorVErrorFProc && sysLog)
OsVendorVErrorFProc = OsVendorVErrorF;
#endif
}


void OsVendorFatalError(const char *f, va_list args)
{
#ifdef DDXOSVERRORF
if (sysLog) {
syslog(LOG_ERR, "Fatal server error:");
vsyslog(LOG_ERR, f, args);
}
#endif
}


Expand Down Expand Up @@ -1839,14 +1872,18 @@ void ddxUseMsg(void)
ErrorF("==============================\n");
#ifndef TURBOVNC_STATIC_XORG_PATHS
ErrorF("-registrydir dir specify directory containing protocol.txt\n");
#endif
#ifdef DDXOSVERRORF
ErrorF("-syslog redirect all errors/warnings/messages to the system log\n");
#endif
ErrorF("-verbose print all X.org errors, warnings, and messages\n");
ErrorF("-version report Xvnc version on stderr\n\n");
}


/*
* rfbLog prints a time-stamped message to the log file (stderr.)
* rfbLog prints a time-stamped message to the log file (stderr or the system
* log.)
*/

void rfbLog(char *format, ...)
Expand All @@ -1858,23 +1895,41 @@ void rfbLog(char *format, ...)

va_start(args, format);

time(&clock);
strftime(buf, 255, "%d/%m/%Y %H:%M:%S ", localtime(&clock));
for (i = 0; i < traceLevel; i++)
snprintf(&buf[strlen(buf)], 256 - strlen(buf), " ");
fputs(buf, stderr);
#ifdef DDXOSVERRORF
if (sysLog)
/* NOTE: System log entries already have a timestamp. */
vsyslog(LOG_INFO, format, args);
else
#endif
{
time(&clock);
strftime(buf, 255, "%d/%m/%Y %H:%M:%S ", localtime(&clock));
for (i = 0; i < traceLevel; i++)
snprintf(&buf[strlen(buf)], 256 - strlen(buf), " ");
fputs(buf, stderr);

vfprintf(stderr, format, args);
fflush(stderr);
vfprintf(stderr, format, args);
fflush(stderr);
}

va_end(args);
}


void rfbLogPerror(char *str)
{
rfbLog("");
perror(str);
#ifdef DDXOSVERRORF
if (sysLog) {
if (str && strlen(str) > 0)
syslog(LOG_ERR, "%s: %s\n", str, strerror(errno));
else
syslog(LOG_ERR, "%s\n", strerror(errno));
} else
#endif
{
rfbLog("");
perror(str);
}
}


Expand Down
2 changes: 1 addition & 1 deletion unix/Xvnc/programs/Xserver/hw/vnc/rfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ extern int traceLevel;

/*
* Print a time-stamped message, prefixed by the client ID, to the log file
* (stderr.)
* (stderr or the system log.)
*/
#define RFBLOGID(format, ...) rfbLog("[%u] " format, cl->id, ##__VA_ARGS__)

Expand Down
12 changes: 7 additions & 5 deletions unix/Xvnc/programs/Xserver/hw/vnc/rfbssl_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ static void rfbErr(const char *format, ...)

static void rfbssl_error(const char *function)
{
char buf[1024];
char buf[BUFSIZE];
unsigned long e = crypto.ERR_get_error();

while (e) {
Expand All @@ -354,6 +354,7 @@ rfbSslCtx *rfbssl_init(rfbClientPtr cl, Bool anon)
DSA *dsa = NULL;
int flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3, priority = 0;
const char *list = NULL;
char buf[BUFSIZE];

#ifdef DLOPENSSL
if (loadFunctions() == -1)
Expand Down Expand Up @@ -443,14 +444,15 @@ rfbSslCtx *rfbssl_init(rfbClientPtr cl, Bool anon)
rfbssl_error("SSL_new()");
goto bailout;
}
RFBLOGID("Available cipher suites: ");
snprintf(buf, BUFSIZE, "Available cipher suites: ");
list = ssl.SSL_get_cipher_list(ctx->ssl, priority++);
while (list) {
fprintf(stderr, "%s", list);
snprintf(&buf[strlen(buf)], BUFSIZE - strlen(buf), "%s", list);
list = ssl.SSL_get_cipher_list(ctx->ssl, priority++);
if (list) fprintf(stderr, ":");
if (list) snprintf(&buf[strlen(buf)], BUFSIZE - strlen(buf), ":");
}
fprintf(stderr, "\n");
snprintf(&buf[strlen(buf)], BUFSIZE - strlen(buf), "\n");
RFBLOGID("%s", buf);
if (!(ssl.SSL_set_fd(ctx->ssl, cl->sock))) {
rfbssl_error("SSL_set_fd()");
goto bailout;
Expand Down

0 comments on commit 5eb457c

Please sign in to comment.