1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
diff -rup a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt 2016-12-30 14:01:28.000000000 +0100
+++ b/CMakeLists.txt 2018-11-03 23:17:24.323450995 +0100
@@ -18,7 +18,6 @@ set(VERSION_PATCHLEVEL "11")
set(VERSION_SO "0")
set(PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCHLEVEL}")
set(PROJECT_BUGREPORT_PATH "http://sourceforge.net/projects/libvncserver")
-set(CMAKE_C_FLAGS "-O2 -W -Wall -g")
set(LIBVNCSERVER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libvncserver)
set(COMMON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/common)
set(LIBVNCCLIENT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libvncclient)
@@ -192,7 +191,7 @@ TEST_BIG_ENDIAN(LIBVNCSERVER_WORDS_BIGEN
# LIBVNCSERVER_ENOENT_WORKAROUND
# inline
-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rfb/rfbconfig.h.cmake ${CMAKE_BINARY_DIR}/rfb/rfbconfig.h)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rfb/rfbconfig.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/rfb/rfbconfig.h)
set(LIBVNCSERVER_SOURCES
${LIBVNCSERVER_DIR}/main.c
@@ -315,6 +314,11 @@ target_link_libraries(vncserver
${WEBSOCKET_LIBRARIES}
)
+target_include_directories(vncserver
+ INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
+ INTERFACE ${CMAKE_CURRENT_BINARY_DIR}
+ )
+
SET_TARGET_PROPERTIES(vncclient vncserver
PROPERTIES SOVERSION "${VERSION_SO}" VERSION "${PACKAGE_VERSION}"
)
@@ -378,19 +382,6 @@ if(HAVE_FFMPEG)
)
endif(HAVE_FFMPEG)
-
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/examples)
-foreach(test ${LIBVNCSERVER_TESTS})
- add_executable(examples_${test} ${LIBVNCSRVTEST_DIR}/${test}.c)
- target_link_libraries(examples_${test} vncserver ${CMAKE_THREAD_LIBS_INIT})
-endforeach(test ${LIBVNCSERVER_TESTS})
-
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/client_examples)
-foreach(test ${LIBVNCCLIENT_TESTS})
- add_executable(client_examples_${test} ${LIBVNCCLITEST_DIR}/${test}.c ${LIBVNCCLITEST_DIR}/${${test}_EXTRA_SOURCES} )
- target_link_libraries(client_examples_${test} vncclient ${CMAKE_THREAD_LIBS_INIT} ${X11_LIBRARIES} ${SDL_LIBRARY} ${FFMPEG_LIBRARIES})
-endforeach(test ${LIBVNCCLIENT_TESTS})
-
install_targets(/lib vncserver)
install_targets(/lib vncclient)
install_files(/include/rfb FILES
diff -rup a/libvncclient/listen.c b/libvncclient/listen.c
--- a/libvncclient/listen.c 2016-12-30 14:01:28.000000000 +0100
+++ b/libvncclient/listen.c 2018-11-03 23:17:24.318450981 +0100
@@ -85,7 +85,7 @@ listenForIncomingConnections(rfbClient*
int r;
/* reap any zombies */
int status, pid;
- while ((pid= wait3(&status, WNOHANG, (struct rusage *)0))>0);
+ while ((pid = waitpid(-1, &status, WNOHANG))>0);
/* TODO: callback for discard any events (like X11 events) */
diff -rup a/libvncclient/tls_openssl.c b/libvncclient/tls_openssl.c
--- a/libvncclient/tls_openssl.c 2016-12-30 14:01:28.000000000 +0100
+++ b/libvncclient/tls_openssl.c 2018-11-03 23:17:24.318450981 +0100
@@ -189,7 +189,7 @@ ssl_verify (int ok, X509_STORE_CTX *ctx)
ssl = X509_STORE_CTX_get_ex_data (ctx, SSL_get_ex_data_X509_STORE_CTX_idx ());
- client = SSL_CTX_get_app_data (ssl->ctx);
+ client = SSL_CTX_get_app_data (SSL_get_SSL_CTX (ssl));
cert = X509_STORE_CTX_get_current_cert (ctx);
err = X509_STORE_CTX_get_error (ctx);
@@ -287,11 +287,10 @@ open_ssl_connection (rfbClient *client,
{
if (wait_for_data(ssl, n, 1) != 1)
{
- finished = 1;
- if (ssl->ctx)
- SSL_CTX_free (ssl->ctx);
- SSL_free(ssl);
+ finished = 1;
SSL_shutdown (ssl);
+ SSL_free(ssl);
+ SSL_CTX_free (ssl_ctx);
return NULL;
}
@@ -365,10 +364,11 @@ return TRUE;
static rfbBool
ReadVeNCryptSecurityType(rfbClient* client, uint32_t *result)
{
+ static const unsigned int max_auth = 256;
uint8_t count=0;
uint8_t loop=0;
uint8_t flag=0;
- uint32_t tAuth[256], t;
+ uint32_t tAuth[max_auth], t;
char buf1[500],buf2[10];
uint32_t authScheme;
@@ -380,9 +380,9 @@ ReadVeNCryptSecurityType(rfbClient* clie
return FALSE;
}
- if (count>sizeof(tAuth))
+ if (count>=max_auth)
{
- rfbClientLog("%d security types are too many; maximum is %d\n", count, sizeof(tAuth));
+ rfbClientLog("%d security types are too many; maximum is %d\n", count, max_auth);
return FALSE;
}
diff -rup a/libvncserver/main.c b/libvncserver/main.c
--- a/libvncserver/main.c 2016-12-30 14:01:28.000000000 +0100
+++ b/libvncserver/main.c 2018-11-03 23:17:24.320450987 +0100
@@ -561,6 +561,7 @@ clientInput(void *data)
}
}
+ rfbLog("input: waiting for output thread");
/* Get rid of the output thread. */
LOCK(cl->updateMutex);
TSIGNAL(cl->updateCond);
@@ -569,6 +570,8 @@ clientInput(void *data)
rfbClientConnectionGone(cl);
+ rfbLog("input: exit thread");
+
return NULL;
}
@@ -945,7 +948,7 @@ rfbScreenInfoPtr rfbGetScreen(int* argc,
void rfbNewFramebuffer(rfbScreenInfoPtr screen, char *framebuffer,
int width, int height,
int bitsPerSample, int samplesPerPixel,
- int bytesPerPixel)
+ int bytesPerPixel, int bytesPerRow)
{
rfbPixelFormat old_format;
rfbBool format_changed = FALSE;
@@ -962,7 +965,7 @@ void rfbNewFramebuffer(rfbScreenInfoPtr
screen->width = width;
screen->height = height;
screen->bitsPerPixel = screen->depth = 8*bytesPerPixel;
- screen->paddedWidthInBytes = width*bytesPerPixel;
+ screen->paddedWidthInBytes = bytesPerRow;
rfbInitServerFormat(screen, bitsPerSample);
@@ -1062,22 +1065,30 @@ void rfbInitServer(rfbScreenInfoPtr scre
#endif
}
-void rfbShutdownServer(rfbScreenInfoPtr screen,rfbBool disconnectClients) {
+void rfbShutdownServer(rfbScreenInfoPtr screen, rfbBool disconnectClients) {
+ rfbShutdownSockets(screen);
+ rfbHttpShutdownSockets(screen);
+
if(disconnectClients) {
rfbClientPtr cl;
- rfbClientIteratorPtr iter = rfbGetClientIterator(screen);
- while( (cl = rfbClientIteratorNext(iter)) ) {
- if (cl->sock > -1) {
- /* we don't care about maxfd here, because the server goes away */
- rfbCloseClient(cl);
- rfbClientConnectionGone(cl);
- }
+
+ cl = screen->clientHead;
+
+ while (cl) {
+ rfbClientPtr next = cl->next;
+ if (cl->sock != -1) {
+ rfbCloseClient(cl);
+ if (screen->backgroundLoop) {
+ pthread_join(cl->client_thread, NULL);
+ } else {
+ rfbClientConnectionGone(cl);
+ }
+ }
+ cl = next;
}
- rfbReleaseClientIterator(iter);
}
- rfbShutdownSockets(screen);
- rfbHttpShutdownSockets(screen);
+
}
#ifndef LIBVNCSERVER_HAVE_GETTIMEOFDAY
diff -rup a/libvncserver/rfbserver.c b/libvncserver/rfbserver.c
--- a/libvncserver/rfbserver.c 2016-12-30 14:01:28.000000000 +0100
+++ b/libvncserver/rfbserver.c 2018-11-03 23:17:24.320450987 +0100
@@ -552,8 +552,10 @@ rfbClientConnectionGone(rfbClientPtr cl)
do {
LOCK(cl->refCountMutex);
i=cl->refCount;
- if(i>0)
- WAIT(cl->deleteCond,cl->refCountMutex);
+ if(i>0) {
+ rfbLog("Client %s still has %d refs\n",cl->host, i);
+ WAIT(cl->deleteCond, cl->refCountMutex);
+ }
UNLOCK(cl->refCountMutex);
} while(i>0);
}
diff -rup a/libvncserver/rfbssl_openssl.c b/libvncserver/rfbssl_openssl.c
--- a/libvncserver/rfbssl_openssl.c 2016-12-30 14:01:28.000000000 +0100
+++ b/libvncserver/rfbssl_openssl.c 2018-11-03 23:17:24.320450987 +0100
@@ -56,7 +56,7 @@ int rfbssl_init(rfbClientPtr cl)
rfbErr("OOM\n");
} else if (!cl->screen->sslcertfile || !cl->screen->sslcertfile[0]) {
rfbErr("SSL connection but no cert specified\n");
- } else if (NULL == (ctx->ssl_ctx = SSL_CTX_new(TLSv1_server_method()))) {
+ } else if (NULL == (ctx->ssl_ctx = SSL_CTX_new(TLS_server_method()))) {
rfbssl_error();
} else if (SSL_CTX_use_PrivateKey_file(ctx->ssl_ctx, keyfile, SSL_FILETYPE_PEM) <= 0) {
rfbErr("Unable to load private key file %s\n", keyfile);
diff -rup a/rfb/rfb.h b/rfb/rfb.h
--- a/rfb/rfb.h 2016-12-30 14:01:28.000000000 +0100
+++ b/rfb/rfb.h 2018-11-03 23:17:24.320450987 +0100
@@ -1034,7 +1034,7 @@ extern void rfbInitServer(rfbScreenInfoP
extern void rfbShutdownServer(rfbScreenInfoPtr rfbScreen,rfbBool disconnectClients);
extern void rfbNewFramebuffer(rfbScreenInfoPtr rfbScreen,char *framebuffer,
int width,int height, int bitsPerSample,int samplesPerPixel,
- int bytesPerPixel);
+ int bytesPerPixel, int bytesPerRow);
extern void rfbScreenCleanup(rfbScreenInfoPtr screenInfo);
extern void rfbSetServerVersionIdentity(rfbScreenInfoPtr screen, char *fmt, ...);
|