From 7f3850df826f892f19ee47c9fb99344540aff8c8 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 11 Oct 2016 18:08:53 +0200 Subject: [xscreensaver] Create .xscreensaver to disable fading and apply our own dpms timeouts --- remote/modules/run-virt/winres/winres.c | 53 ++++++++++++++++++++-- .../data/etc/X11/Xsession.d/95-xscreensaver | 33 ++++++++++++-- 2 files changed, 77 insertions(+), 9 deletions(-) diff --git a/remote/modules/run-virt/winres/winres.c b/remote/modules/run-virt/winres/winres.c index d92b6521..44654161 100644 --- a/remote/modules/run-virt/winres/winres.c +++ b/remote/modules/run-virt/winres/winres.c @@ -33,6 +33,7 @@ DEFINE_GUID(ID_MMDeviceEnumerator, 0xBCDE0395, 0xE52F, 0x467C, 0x8E, 0x3D, 0xC4, typedef struct { const char* path; + const char* pathIp; const char* letter; const char* shortcut; const char* user; @@ -46,6 +47,8 @@ static const ssize_t KEYLEN = 16; #define SETTINGS_FILE "B:\\OPENSLX.INI" #define SETTINGS_FILE_W L"B:\\OPENSLX.INI" +static BOOL _debug = FALSE; + static HINSTANCE hKernel32, hShell32; static OSVERSIONINFO winVer; static BOOL bGetShares = FALSE; @@ -309,6 +312,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine _startTime = GetTickCount(); loadPaths(); if (lpCmdLine != NULL && strstr(lpCmdLine, "debug") != NULL) { + _debug = TRUE; alog("Windows Version %d.%d", (int)winVer.dwMajorVersion, (int)winVer.dwMinorVersion); } // Mute sound by default @@ -564,6 +568,37 @@ static char* getToken(char **ptr, BOOL doDup) return dest; } +const char* uncReplaceFqdnByIp(const char* path) +{ + if (path == NULL || path[0] != '\\' || path[1] != '\\') + return NULL; + const char *host = path + 2; + const char *rest = strchr(host, '\\'); + if (rest == NULL || rest - host >= 200) + return NULL; + char name[201]; + strncpy(name, host, rest - host); + name[rest-host] = '\0'; + if (_debug) { + alog("Trying to resolve '%s'...", name); + } + struct hostent *remote = gethostbyname(name); + if (remote == NULL || remote->h_addrtype != AF_INET || remote->h_addr_list[0] == 0) + return NULL; + struct in_addr addr; + addr.s_addr = *(u_long*)remote->h_addr_list[0]; + char *ip = inet_ntoa(addr); + if (ip == NULL) + return NULL; + size_t len = 2 /* \\ */ + strlen(ip) /* 1.2.3.4 */ + strlen(rest) /* \path\to\share */ + 1 /* nullchar */; + char *retval = malloc(len); + snprintf(retval, len, "\\\\%s%s", ip, rest); + if (_debug) { + alog("Turned '%s' into '%s'", path, retval); + } + return retval; +} + #define FREENULL(x) do { free((void*)(x)); (x) = NULL; } while (0) static void readShareFile() @@ -595,6 +630,9 @@ static void readShareFile() if (d->path == NULL || d->path[0] == '\0') goto drive_fail; d->success = FALSE; + // Hack: For unknown reasons, with some servers mounting fails using a fqdn, but using the ip address instead succeeds. + d->pathIp = uncReplaceFqdnByIp(d->path); + // idx++; continue; drive_fail: @@ -749,11 +787,14 @@ static void postSuccessfulMount(const netdrive_t *d, wchar_t *letter) } } -static BOOL mountNetworkShare(const netdrive_t *d) +static BOOL mountNetworkShare(const netdrive_t *d, BOOL useIp) { wchar_t path[BUFLEN] = L"", user[BUFLEN] = L"", pass[BUFLEN] = L"", letter[10] = L"", shortcut[BUFLEN] = L""; int ok = -1; - ok &= MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)d->path, -1, (LPWSTR)path, BUFLEN) > 0; + if (useIp && d->pathIp[0] == '\0') + return FALSE; + const char *uncPath = useIp ? d->pathIp : d->path; + ok &= MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)uncPath, -1, (LPWSTR)path, BUFLEN) > 0; if (d->letter != NULL) { ok &= MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)d->letter, -1, (LPWSTR)letter, 10) > 0; } @@ -767,7 +808,7 @@ static BOOL mountNetworkShare(const netdrive_t *d) ok &= MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)d->shortcut, -1, (LPWSTR)shortcut, BUFLEN) > 0; } if (!ok || path[0] == 0) { // Convert failed/no path - return true anyways since retrying wouldn't change anything - alog("mountNetworkShare: utf8 to utf16 failed, or path empty (src: '%s')", d->path); + alog("mountNetworkShare: utf8 to utf16 failed, or path empty (src: '%s')", uncPath); return TRUE; } DWORD retval; @@ -826,7 +867,9 @@ static BOOL mountNetworkShares() break; if (drives[i].success) continue; - if (mountNetworkShare(&drives[i])) { + if (mountNetworkShare(&drives[i], FALSE)) { + drives[i].success = TRUE; + } else if (mountNetworkShare(&drives[i], TRUE)) { drives[i].success = TRUE; } else { failCount++; @@ -870,7 +913,7 @@ static void remapViaSharedFolder() } } // Map vmware shared folder - mountNetworkShare(&d); + mountNetworkShare(&d, FALSE); } static char* xorString(const uint8_t* text, int len, const uint8_t* key) diff --git a/remote/modules/xscreensaver/data/etc/X11/Xsession.d/95-xscreensaver b/remote/modules/xscreensaver/data/etc/X11/Xsession.d/95-xscreensaver index 385a8280..fc6588ae 100755 --- a/remote/modules/xscreensaver/data/etc/X11/Xsession.d/95-xscreensaver +++ b/remote/modules/xscreensaver/data/etc/X11/Xsession.d/95-xscreensaver @@ -1,8 +1,33 @@ #!/bin/ash -if ! which xscreensaver; then - echo "Failed to find xscreensaver in '$PATH'!" - return 1 +if which xscreensaver; then + [ -z "$UID" ] && UID=$(id -u) + [ -z "$HOME" ] && HOME="$(getent passwd "$UID" | head -n 1 | awk -F ':' '{print $6}')" + if ! [ -s "$HOME/.xscreensaver" ]; then + . /opt/openslx/config + NUM=${SLX_SCREEN_STANDBY_TIMEOUT} + if [ -n "$NUM" ] && [ "$NUM" -gt 60 ]; then + SECS=0$(( NUM % 60 )) + MINS=0$(( ( NUM / 60 ) % 60 )) + HRS=0$(( ( NUM / 3600 ) % 60 )) + STANDBY="${HRS:$(( ${#HRS} - 2 )):2}:${MINS:$(( ${#MINS} - 2 )):2}:${SECS:$(( ${#SECS} - 2 )):2}" + else + STANDBY=0:00:00 + fi + cat > "$HOME/.xscreensaver" <