mirror of https://github.com/OpenVPN/openvpn-gui
Detach persistent connections on switch user
This allows a new user to attach to the mgmt i/f of persistent connections which would be otherwise blocked by the previously logged in user. Signed-off-by: Selva Nair <selva.nair@gmail.com>pull/519/head
parent
7f794eec3d
commit
44990cd83d
44
main.c
44
main.c
|
@ -537,6 +537,40 @@ ManagePersistent(HWND hwnd, UINT UNUSED msg, UINT_PTR id, DWORD UNUSED now)
|
||||||
SetTimer(hwnd, id, 10000, ManagePersistent);
|
SetTimer(hwnd, id, 10000, ManagePersistent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Detach from the mgmt i/f of all atatched persistent
|
||||||
|
* connections. Called on session lock so that another
|
||||||
|
* user can attach to these.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
HandleSessionLock(void)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < o.num_configs; i++)
|
||||||
|
{
|
||||||
|
if (o.conn[i].flags & FLAG_DAEMON_PERSISTENT
|
||||||
|
&& (o.conn[i].state != disconnected && o.conn[i].state != detached))
|
||||||
|
{
|
||||||
|
o.conn[i].auto_connect = false;
|
||||||
|
DetachOpenVPN(&o.conn[i]);
|
||||||
|
o.conn[i].flags |= FLAG_WAIT_UNLOCK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Undo any actions done at session lock/disconnect.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
HandleSessionUnlock(void)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < o.num_configs; i++)
|
||||||
|
{
|
||||||
|
if (o.conn[i].flags & FLAG_WAIT_UNLOCK)
|
||||||
|
{
|
||||||
|
o.conn[i].auto_connect = true; /* so that ManagePersistent will trigger attach */
|
||||||
|
o.conn[i].flags &= ~ FLAG_WAIT_UNLOCK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* This function is called by the Windows function DispatchMessage() */
|
/* This function is called by the Windows function DispatchMessage() */
|
||||||
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
@ -675,13 +709,23 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
|
||||||
case WM_WTSSESSION_CHANGE:
|
case WM_WTSSESSION_CHANGE:
|
||||||
switch (wParam) {
|
switch (wParam) {
|
||||||
case WTS_SESSION_LOCK:
|
case WTS_SESSION_LOCK:
|
||||||
|
PrintDebug(L"Session lock triggered");
|
||||||
o.session_locked = TRUE;
|
o.session_locked = TRUE;
|
||||||
|
/* Detach persistent connections so that other users can connect to it */
|
||||||
|
HandleSessionLock();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WTS_SESSION_UNLOCK:
|
case WTS_SESSION_UNLOCK:
|
||||||
|
PrintDebug(L"Session unlock triggered");
|
||||||
o.session_locked = FALSE;
|
o.session_locked = FALSE;
|
||||||
|
HandleSessionUnlock();
|
||||||
if (CountConnState(suspended) != 0)
|
if (CountConnState(suspended) != 0)
|
||||||
ResumeConnections();
|
ResumeConnections();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
PrintDebug(L"Session change with wParam = %lu", wParam);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,7 @@ typedef struct {
|
||||||
#define FLAG_DISABLE_SAVE_PASS (1<<6)
|
#define FLAG_DISABLE_SAVE_PASS (1<<6)
|
||||||
#define FLAG_DISABLE_ECHO_MSG (1<<7)
|
#define FLAG_DISABLE_ECHO_MSG (1<<7)
|
||||||
#define FLAG_DAEMON_PERSISTENT (1<<8)
|
#define FLAG_DAEMON_PERSISTENT (1<<8)
|
||||||
|
#define FLAG_WAIT_UNLOCK (1<<9)
|
||||||
|
|
||||||
#define CONFIG_VIEW_AUTO (0)
|
#define CONFIG_VIEW_AUTO (0)
|
||||||
#define CONFIG_VIEW_FLAT (1)
|
#define CONFIG_VIEW_FLAT (1)
|
||||||
|
|
Loading…
Reference in New Issue