void rfbProcessClientSecurityType(rfbClientPtr cl)
{
  int n, count, i;
  CARD8 chosenType;

  /* Read the security type */
  n = ReadExact(cl, (char *)&chosenType, 1);
  if (n <= 0) {
    if (n == 0)
      rfbLog("rfbProcessClientSecurityType: client gone\n");
    else
      rfbLogPerror("rfbProcessClientSecurityType: read");
    rfbCloseClient(cl);
    return;
  }

  /* Make sure it was present in the list sent by the server */
  count = (int)cl->securityTypes[0];
  for (i = 1; i <= count; i++) {
    if (chosenType == cl->securityTypes[i])
      break;
  }
  if (i > count) {
    rfbLog("rfbProcessClientSecurityType: wrong security type requested\n");
    rfbCloseClient(cl);
    return;
  }

  cl->selectedAuthType = chosenType;
  switch (chosenType) {
    case rfbSecTypeNone:
      /* No authentication needed */
      rfbClientAuthSucceeded(cl, rfbAuthNone);
      break;
    case rfbSecTypeVncAuth:
      /* Begin the Standard VNC authentication procedure */
      rfbVncAuthSendChallenge(cl);
      break;
    case rfbSecTypeTight:
      /* The viewer supports TightVNC extensions */
      rfbLog("Enabling TightVNC protocol extensions\n");
      /* Switch to protocol 3.7t/3.8t */
      cl->protocol_tightvnc = TRUE;
      /* Advertise our tunneling capabilities */
      rfbSendTunnelingCaps(cl);
      break;
    case rfbSecTypeVeNCrypt:
      /* The viewer supports VeNCrypt extensions */
      rfbLog("Enabling VeNCrypt protocol extensions\n");
      rfbVeNCryptAuthenticate(cl);
      break;
    default:
      rfbLog("rfbProcessClientSecurityType: unknown authentication scheme\n");
      rfbCloseClient(cl);
      break;
  }
}
void rfbProcessClientSecurityType(rfbClientPtr cl)
{
  int n, count, i;
  CARD8 chosenType;

   
  n = ReadExact(cl, (char *)&chosenType, 1);
  if (n <= 0) {
    if (n == 0)
      rfbLog("rfbProcessClientSecurityType: client gone\n");
    else
      rfbLogPerror("rfbProcessClientSecurityType: read");
    rfbCloseClient(cl);
    return;
  }

   
  count = (int)cl->securityTypes[0];
  for (i = 1; i <= count; i++) {
    if (chosenType == cl->securityTypes[i])
      break;
  }
  if (i > count) {
    rfbLog("rfbProcessClientSecurityType: wrong security type requested\n");
    rfbCloseClient(cl);
    return;
  }

  cl->selectedAuthType = chosenType;
  switch (chosenType) {
    case rfbSecTypeNone:
       
      rfbClientAuthSucceeded(cl, rfbAuthNone);
      break;
    case rfbSecTypeVncAuth:
       
      rfbVncAuthSendChallenge(cl);
      break;
    case rfbSecTypeTight:
       
      rfbLog("Enabling TightVNC protocol extensions\n");
       
      cl->protocol_tightvnc = TRUE;
       
      rfbSendTunnelingCaps(cl);
      break;
    case rfbSecTypeVeNCrypt:
       
      rfbLog("Enabling VeNCrypt protocol extensions\n");
      rfbVeNCryptAuthenticate(cl);
      break;
    default:
      rfbLog("rfbProcessClientSecurityType: unknown authentication scheme\n");
      rfbCloseClient(cl);
      break;
  }
}