View | Details | Raw Unified | Return to bug 250795 | Differences between
and this patch

Collapse All | Expand All

(-)rfb.c (-38 / +84 lines)
Lines 221-226 Link Here
221
	sinfo.pixfmt.red_shift = 16;
221
	sinfo.pixfmt.red_shift = 16;
222
	sinfo.pixfmt.green_shift = 8;
222
	sinfo.pixfmt.green_shift = 8;
223
	sinfo.pixfmt.blue_shift = 0;
223
	sinfo.pixfmt.blue_shift = 0;
224
	sinfo.pixfmt.pad[0] = 0;
225
	sinfo.pixfmt.pad[1] = 0;
226
	sinfo.pixfmt.pad[2] = 0;
224
	sinfo.namelen = htonl(strlen("bhyve"));
227
	sinfo.namelen = htonl(strlen("bhyve"));
225
	(void)stream_write(cfd, &sinfo, sizeof(sinfo));
228
	(void)stream_write(cfd, &sinfo, sizeof(sinfo));
226
	(void)stream_write(cfd, "bhyve", strlen("bhyve"));
229
	(void)stream_write(cfd, "bhyve", strlen("bhyve"));
Lines 623-629 Link Here
623
626
624
627
625
static void
628
static void
626
rfb_recv_update_msg(struct rfb_softc *rc, int cfd, int discardonly)
629
rfb_recv_update_msg(struct rfb_softc *rc, int cfd)
627
{
630
{
628
	struct rfb_updt_msg updt_msg;
631
	struct rfb_updt_msg updt_msg;
629
	struct bhyvegc_image *gc_image;
632
	struct bhyvegc_image *gc_image;
Lines 638-655 Link Here
638
	updt_msg.width = htons(updt_msg.width);
641
	updt_msg.width = htons(updt_msg.width);
639
	updt_msg.height = htons(updt_msg.height);
642
	updt_msg.height = htons(updt_msg.height);
640
643
641
	if (updt_msg.width != gc_image->width ||
644
	if (updt_msg.incremental == 0) {
642
	    updt_msg.height != gc_image->height) {
645
		rfb_send_screen(rc, cfd, 1);
643
		rc->width = gc_image->width;
646
	} else {
644
		rc->height = gc_image->height;
647
		if (updt_msg.width != gc_image->width ||
645
		if (rc->enc_resize_ok)
648
		    updt_msg.height != gc_image->height) {
646
			rfb_send_resize_update_msg(rc, cfd);
649
			rc->width = gc_image->width;
650
			rc->height = gc_image->height;
651
			if (rc->enc_resize_ok)
652
				rfb_send_resize_update_msg(rc, cfd);
653
		}
647
	}
654
	}
648
649
	if (discardonly)
650
		return;
651
652
	rfb_send_screen(rc, cfd, 1);
653
}
655
}
654
656
655
static void
657
static void
Lines 756-762 Link Here
756
	DES_key_schedule ks;
758
	DES_key_schedule ks;
757
	int i;
759
	int i;
758
#endif
760
#endif
759
761
	uint8_t client_ver;
762
	uint8_t auth_type;
760
	pthread_t tid;
763
	pthread_t tid;
761
	uint32_t sres = 0;
764
	uint32_t sres = 0;
762
	int len;
765
	int len;
Lines 769-795 Link Here
769
772
770
	/* 1b. Read client version */
773
	/* 1b. Read client version */
771
	len = read(cfd, buf, sizeof(buf));
774
	len = read(cfd, buf, sizeof(buf));
775
	if (len == strlen(vbuf) && !strncmp(vbuf, buf, 10)) {
776
		client_ver = buf[10];
777
	}
778
	if (client_ver != '8' && client_ver != '7') {
779
		/* only recognize 3.3, 3.7 & 3.8. Others dflt to 3.3 */
780
		client_ver = '3';
781
	}
772
782
773
	/* 2a. Send security type */
783
	/* 2a. Send security type */
774
	buf[0] = 1;
784
	/* In versions 3.7 & 3.8, it's 2-way handshake */
785
	/* For version 3.3, server says what the authentication type must be */
775
#ifndef NO_OPENSSL
786
#ifndef NO_OPENSSL
776
	if (rc->password) 
787
	if (rc->password) {
777
		buf[1] = SECURITY_TYPE_VNC_AUTH;
788
		auth_type = SECURITY_TYPE_VNC_AUTH;
778
	else
789
	} else {
779
		buf[1] = SECURITY_TYPE_NONE;
790
		auth_type = SECURITY_TYPE_NONE;
791
	}
780
#else
792
#else
781
	buf[1] = SECURITY_TYPE_NONE;
793
	auth_type = SECURITY_TYPE_NONE;
782
#endif
794
#endif
795
	switch (client_ver) {
796
	case '7':
797
	case '8':
798
		buf[0] = 1;
799
		buf[1] = auth_type;
800
		stream_write(cfd, buf, 2);
783
801
784
	stream_write(cfd, buf, 2);
802
		/* 2b. Read agreed security type */
803
		len = stream_read(cfd, buf, 1);
804
		if (buf[0] != auth_type) {
805
			/* deny */
806
			sres = htonl(1);
807
			message = "Auth failed: authentication type mismatch";
808
			goto report_and_done;
809
		}
810
		break;
811
	case '3':
812
	default:
813
		be32enc(buf, auth_type);
814
		stream_write(cfd, buf, 4);
815
		break;
816
	}
785
817
786
	/* 2b. Read agreed security type */
787
	len = stream_read(cfd, buf, 1);
788
789
	/* 2c. Do VNC authentication */
818
	/* 2c. Do VNC authentication */
790
	switch (buf[0]) {
819
	switch (auth_type) {
791
	case SECURITY_TYPE_NONE:
820
	case SECURITY_TYPE_NONE:
792
		sres = 0;
793
		break;
821
		break;
794
	case SECURITY_TYPE_VNC_AUTH:
822
	case SECURITY_TYPE_VNC_AUTH:
795
		/*
823
		/*
Lines 837-846 Link Here
837
		if (memcmp(crypt_expected, buf, AUTH_LENGTH) != 0) {
865
		if (memcmp(crypt_expected, buf, AUTH_LENGTH) != 0) {
838
			message = "Auth Failed: Invalid Password.";
866
			message = "Auth Failed: Invalid Password.";
839
			sres = htonl(1);
867
			sres = htonl(1);
840
		} else
868
		} else {
841
			sres = 0;
869
			sres = 0;
870
		}
842
#else
871
#else
843
		sres = 0;
872
		sres = htonl(1);
844
		WPRINTF(("Auth not supported, no OpenSSL in your system"));
873
		WPRINTF(("Auth not supported, no OpenSSL in your system"));
845
#endif
874
#endif
846
875
Lines 847-862 Link Here
847
		break;
876
		break;
848
	}
877
	}
849
878
850
	/* 2d. Write back a status */
879
	switch (client_ver) {
851
	stream_write(cfd, &sres, 4);
880
	case '7':
881
	case '8':
882
report_and_done:
883
		/* 2d. Write back a status */
884
		stream_write(cfd, &sres, 4);
852
885
853
	if (sres) {
886
		if (sres) {
854
		be32enc(buf, strlen(message));
887
			/* 3.7 does not want string explaining cause */
855
		stream_write(cfd, buf, 4);
888
			if (client_ver == '8') {
856
		stream_write(cfd, message, strlen(message));
889
				be32enc(buf, strlen(message));
857
		goto done;
890
				stream_write(cfd, buf, 4);
891
				stream_write(cfd, message, strlen(message));
892
			}
893
			goto done;
894
		}
895
		break;
896
	case '3':
897
	default:
898
		/* for VNC auth case send status */
899
		if (auth_type == SECURITY_TYPE_VNC_AUTH) {
900
			/* 2d. Write back a status */
901
			stream_write(cfd, &sres, 4);
902
		}
903
		if (sres) {
904
			goto done;
905
		}
906
		break;
858
	}
907
	}
859
860
	/* 3a. Read client shared-flag byte */
908
	/* 3a. Read client shared-flag byte */
861
	len = stream_read(cfd, buf, 1);
909
	len = stream_read(cfd, buf, 1);
862
910
Lines 868-875 Link Here
868
		assert(rc->zbuf != NULL);
916
		assert(rc->zbuf != NULL);
869
	}
917
	}
870
918
871
	rfb_send_screen(rc, cfd, 1);
872
873
	perror = pthread_create(&tid, NULL, rfb_wr_thr, rc);
919
	perror = pthread_create(&tid, NULL, rfb_wr_thr, rc);
874
	if (perror == 0)
920
	if (perror == 0)
875
		pthread_set_name_np(tid, "rfbout");
921
		pthread_set_name_np(tid, "rfbout");
Lines 890-896 Link Here
890
			rfb_recv_set_encodings_msg(rc, cfd);
936
			rfb_recv_set_encodings_msg(rc, cfd);
891
			break;
937
			break;
892
		case 3:
938
		case 3:
893
			rfb_recv_update_msg(rc, cfd, 1);
939
			rfb_recv_update_msg(rc, cfd);
894
			break;
940
			break;
895
		case 4:
941
		case 4:
896
			rfb_recv_key_msg(rc, cfd);
942
			rfb_recv_key_msg(rc, cfd);

Return to bug 250795