summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Beier <dontmind@freeshell.org>2018-11-18 20:22:15 +0100
committerGitHub <noreply@github.com>2018-11-18 20:22:15 +0100
commitcfdbb94038e76ff002e3d68dc6b1ca0df2606ef6 (patch)
tree4a965c5899ccbbdc77a9d9b473faa813339ca782
parentaa8a1aa76880ffb8f23b98d0dbe35988b2609877 (diff)
parent5f9a07d7e1613dbccd5a27e845dbb8a7f2a27b2e (diff)
downloadlibtdevnc-cfdbb94038e76ff002e3d68dc6b1ca0df2606ef6.tar.gz
libtdevnc-cfdbb94038e76ff002e3d68dc6b1ca0df2606ef6.zip
Merge pull request #263 from veyon/custom-auth-handlers
LibVNCClient: add support for custom auth handlers
-rw-r--r--client_examples/backchannel.c4
-rw-r--r--libvncclient/rfbproto.c29
-rw-r--r--rfb/rfbclient.h3
3 files changed, 35 insertions, 1 deletions
diff --git a/client_examples/backchannel.c b/client_examples/backchannel.c
index 04d154e..a7db9a0 100644
--- a/client_examples/backchannel.c
+++ b/client_examples/backchannel.c
@@ -71,7 +71,9 @@ static rfbClientProtocolExtension backChannel = {
backChannelEncodings, /* encodings */
NULL, /* handleEncoding */
handleBackChannelMessage, /* handleMessage */
- NULL /* next extension */
+ NULL, /* next extension */
+ NULL, /* securityTypes */
+ NULL /* handleAuthentication */
};
int
diff --git a/libvncclient/rfbproto.c b/libvncclient/rfbproto.c
index 5679b06..4541e0d 100644
--- a/libvncclient/rfbproto.c
+++ b/libvncclient/rfbproto.c
@@ -474,9 +474,11 @@ ReadSupportedSecurityType(rfbClient* client, uint32_t *result, rfbBool subAuth)
uint8_t count=0;
uint8_t loop=0;
uint8_t flag=0;
+ rfbBool extAuthHandler;
uint8_t tAuth[256];
char buf1[500],buf2[10];
uint32_t authScheme;
+ rfbClientProtocolExtension* e;
if (!ReadFromRFBServer(client, (char *)&count, 1)) return FALSE;
@@ -495,7 +497,18 @@ ReadSupportedSecurityType(rfbClient* client, uint32_t *result, rfbBool subAuth)
if (!ReadFromRFBServer(client, (char *)&tAuth[loop], 1)) return FALSE;
rfbClientLog("%d) Received security type %d\n", loop, tAuth[loop]);
if (flag) continue;
+ extAuthHandler=FALSE;
+ for (e = rfbClientExtensions; e; e = e->next) {
+ if (!e->handleAuthentication) continue;
+ uint32_t const* secType;
+ for (secType = e->securityTypes; secType && *secType; secType++) {
+ if (tAuth[loop]==*secType) {
+ extAuthHandler=TRUE;
+ }
+ }
+ }
if (tAuth[loop]==rfbVncAuth || tAuth[loop]==rfbNoAuth ||
+ extAuthHandler ||
#if defined(LIBVNCSERVER_HAVE_GNUTLS) || defined(LIBVNCSERVER_HAVE_LIBSSL)
tAuth[loop]==rfbVeNCrypt ||
#endif
@@ -1176,6 +1189,22 @@ InitialiseRFBConnection(rfbClient* client)
break;
default:
+ {
+ rfbBool authHandled=FALSE;
+ rfbClientProtocolExtension* e;
+ for (e = rfbClientExtensions; e; e = e->next) {
+ uint32_t const* secType;
+ if (!e->handleAuthentication) continue;
+ for (secType = e->securityTypes; secType && *secType; secType++) {
+ if (authScheme==*secType) {
+ if (!e->handleAuthentication(client, authScheme)) return FALSE;
+ if (!rfbHandleAuthResult(client)) return FALSE;
+ authHandled=TRUE;
+ }
+ }
+ }
+ if (authHandled) break;
+ }
rfbClientLog("Unknown authentication scheme from VNC server: %d\n",
(int)authScheme);
return FALSE;
diff --git a/rfb/rfbclient.h b/rfb/rfbclient.h
index 87f4eaa..1a80f0d 100644
--- a/rfb/rfbclient.h
+++ b/rfb/rfbclient.h
@@ -620,6 +620,9 @@ typedef struct _rfbClientProtocolExtension {
rfbBool (*handleMessage)(rfbClient* cl,
rfbServerToClientMsg* message);
struct _rfbClientProtocolExtension* next;
+ uint32_t const* securityTypes;
+ /** returns TRUE if it handled the authentication */
+ rfbBool (*handleAuthentication)(rfbClient* cl, uint32_t authScheme);
} rfbClientProtocolExtension;
void rfbClientRegisterExtension(rfbClientProtocolExtension* e);