static Bool ReadAuthenticationResult(void) { CARD32 authResult; if (!ReadFromRFBServer((char *)&authResult, 4)) return False; authResult = Swap32IfLE(authResult); switch (authResult) { case rfbAuthOK: if (!appData.ffInfo) { fprintf(stderr, "Authentication successful\n"); } break; case rfbAuthFailed: if (protocolMinorVersion >= 8) { ReadConnFailedReason(); } else { fprintf(stderr, "Authentication failure\n"); } return False; case rfbAuthTooMany: fprintf(stderr, "Authentication failure, too many tries\n"); return False; default: fprintf(stderr, "Unknown result of authentication (%d)\n", (int)authResult); return False; } return True; }
static int SelectSecurityType(void) { CARD8 nSecTypes; char *secTypeNames[] = {"None", "VncAuth"}; CARD8 knownSecTypes[] = {rfbSecTypeNone, rfbSecTypeVncAuth}; int nKnownSecTypes = sizeof(knownSecTypes); CARD8 *secTypes; CARD8 secType = rfbSecTypeInvalid; int i, j; /* Read the list of secutiry types. */ if (!ReadFromRFBServer((char *)&nSecTypes, sizeof(nSecTypes))) return rfbSecTypeInvalid; if (nSecTypes == 0) { ReadConnFailedReason(); return rfbSecTypeInvalid; } secTypes = malloc(nSecTypes); if (!ReadFromRFBServer((char *)secTypes, nSecTypes)) return rfbSecTypeInvalid; /* Find out if the server supports TightVNC protocol extensions */ for (j = 0; j < (int)nSecTypes; j++) { if (secTypes[j] == rfbSecTypeTight) { free(secTypes); secType = rfbSecTypeTight; if (!WriteExact(rfbsock, (char *)&secType, sizeof(secType))) return rfbSecTypeInvalid; fprintf(stderr, "Enabling TightVNC protocol extensions\n"); return rfbSecTypeTight; } } /* Find first supported security type */ for (j = 0; j < (int)nSecTypes; j++) { for (i = 0; i < nKnownSecTypes; i++) { if (secTypes[j] == knownSecTypes[i]) { secType = secTypes[j]; if (!WriteExact(rfbsock, (char *)&secType, sizeof(secType))) { free(secTypes); return rfbSecTypeInvalid; } break; } } if (secType != rfbSecTypeInvalid) break; } free(secTypes); if (secType == rfbSecTypeInvalid) fprintf(stderr, "Server did not offer supported security type\n"); return (int)secType; }
static int ReadSecurityType(void) { CARD32 secType; /* Read the security type */ if (!ReadFromRFBServer((char *)&secType, sizeof(secType))) return rfbSecTypeInvalid; secType = Swap32IfLE(secType); if (secType == rfbSecTypeInvalid) { ReadConnFailedReason(); return rfbSecTypeInvalid; } if (secType != rfbSecTypeNone && secType != rfbSecTypeVncAuth) { fprintf(stderr, "Unknown security type from RFB server: %d\n", (int)secType); return rfbSecTypeInvalid; } return (int)secType; }