Merge pull request #137 from selvanair/echo

Parse ECHO directives from openvpn

Acked-by: Gert Doering <gert@greenie.muc.de>
pull/160/head
Selva Nair 2017-03-16 10:22:05 -04:00 committed by GitHub
commit d7b0fcbe5b
4 changed files with 40 additions and 0 deletions

1
main.c
View File

@ -121,6 +121,7 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance,
{ stop, OnStop }, { stop, OnStop },
{ needok, OnNeedOk }, { needok, OnNeedOk },
{ needstr, OnNeedStr }, { needstr, OnNeedStr },
{ echo, OnEcho },
{ 0, NULL } { 0, NULL }
}; };
InitManagement(handler); InitManagement(handler);

View File

@ -322,6 +322,11 @@ OnManagement(SOCKET sk, LPARAM lParam)
if (rtmsg_handler[needstr]) if (rtmsg_handler[needstr])
rtmsg_handler[needstr](c, pos + 9); rtmsg_handler[needstr](c, pos + 9);
} }
else if (strncmp(pos, "ECHO:", 5) == 0)
{
if (rtmsg_handler[echo])
rtmsg_handler[echo](c, pos + 5);
}
} }
else if (c->manage.cmd_queue) else if (c->manage.cmd_queue)
{ {

View File

@ -108,6 +108,7 @@ OnReady(connection_t *c, UNUSED char *msg)
{ {
ManagementCommand(c, "state on", NULL, regular); ManagementCommand(c, "state on", NULL, regular);
ManagementCommand(c, "log all on", OnLogLine, combined); ManagementCommand(c, "log all on", OnLogLine, combined);
ManagementCommand(c, "echo all on", OnEcho, combined);
} }
@ -693,6 +694,38 @@ out:
return ret; return ret;
} }
/*
* Handle >ECHO: request from OpenVPN management interface
* Expect msg = timestamp,message
*/
void
OnEcho(connection_t *c, char *msg)
{
WCHAR errmsg[256];
PrintDebug(L"OnEcho with msg = %S", msg);
if (!(msg = strchr(msg, ',')))
{
PrintDebug(L"OnEcho: msg format not recognized");
return;
}
msg++;
if (strcmp(msg, "forget-passwords") == 0)
{
DeleteSavedPasswords(c->config_name);
}
else if (strcmp(msg, "save-passwords") == 0)
{
c->flags |= (FLAG_SAVE_KEY_PASS | FLAG_SAVE_AUTH_PASS);
}
else
{
_sntprintf_0(errmsg, L"WARNING: Unknown ECHO directive '%S' ignored.", msg);
WriteStatusLog(c, L"GUI> ", errmsg, false);
}
}
/* /*
* Handle >PASSWORD: request from OpenVPN management interface * Handle >PASSWORD: request from OpenVPN management interface
*/ */

View File

@ -37,6 +37,7 @@ void OnPassword(connection_t *, char *);
void OnStop(connection_t *, char *); void OnStop(connection_t *, char *);
void OnNeedOk(connection_t *, char *); void OnNeedOk(connection_t *, char *);
void OnNeedStr(connection_t *, char *); void OnNeedStr(connection_t *, char *);
void OnEcho(connection_t *, char *);
void ResetSavePasswords(connection_t *); void ResetSavePasswords(connection_t *);