|
Lines 71-76
Link Here
|
| 71 |
#endif |
71 |
#endif |
| 72 |
|
72 |
|
| 73 |
#include "SocketListener.h" |
73 |
#include "SocketListener.h" |
|
|
74 |
#include "SSLSupport.h" |
| 74 |
|
75 |
|
| 75 |
#include "tptp/TransportSupport.h" |
76 |
#include "tptp/TransportSupport.h" |
| 76 |
#include "tptp/TPTPSupportUtils.h" |
77 |
#include "tptp/TPTPSupportUtils.h" |
|
Lines 82-92
Link Here
|
| 82 |
#define DEFAULT_PORT_NUM 10002 |
83 |
#define DEFAULT_PORT_NUM 10002 |
| 83 |
#define PROTO_VERSION 1 |
84 |
#define PROTO_VERSION 1 |
| 84 |
|
85 |
|
| 85 |
#define CONFIGURATION_HOME "TPTP_AC_HOME" |
|
|
| 86 |
|
| 87 |
#define CERTF "cert.pem" |
| 88 |
#define KEYF "key.pem" |
| 89 |
|
| 90 |
/** thread status */ |
86 |
/** thread status */ |
| 91 |
enum ThreadStatus { IDLE, RUNNING } ; |
87 |
enum ThreadStatus { IDLE, RUNNING } ; |
| 92 |
|
88 |
|
|
Lines 95-101
Link Here
|
| 95 |
/*====================================================================*/ |
91 |
/*====================================================================*/ |
| 96 |
THREAD_USER_FUNC_RET_TYPE processClientRequest(LPVOID args) ; |
92 |
THREAD_USER_FUNC_RET_TYPE processClientRequest(LPVOID args) ; |
| 97 |
THREAD_USER_FUNC_RET_TYPE doListening(LPVOID args) ; |
93 |
THREAD_USER_FUNC_RET_TYPE doListening(LPVOID args) ; |
|
|
94 |
THREAD_USER_FUNC_RET_TYPE doSecureListening(LPVOID args) ; |
| 98 |
int serveRequest(SOCKET serverSock, server_block_ptr_t pServerData) ; |
95 |
int serveRequest(SOCKET serverSock, server_block_ptr_t pServerData) ; |
|
|
96 |
int serveSecureRequest(server_block_ptr_t pServerData) ; |
| 99 |
int sendThisMessage(server_block_t* pServerData, tptp_uint32 connectionID, tptp_uint32 cmdSize, tptp_string* pCmdBlock, BOOL shouldAddHeader) ; |
97 |
int sendThisMessage(server_block_t* pServerData, tptp_uint32 connectionID, tptp_uint32 cmdSize, tptp_string* pCmdBlock, BOOL shouldAddHeader) ; |
| 100 |
int addMessageHeader(char * pCmdBlock, int cmdSize, char * buffer, int *pBufferLength, unsigned int flags) ; |
98 |
int addMessageHeader(char * pCmdBlock, int cmdSize, char * buffer, int *pBufferLength, unsigned int flags) ; |
| 101 |
int processCONNECTCall(request_block_ptr_t pBlk, char *pMsg, int flags) ; |
99 |
int processCONNECTCall(request_block_ptr_t pBlk, char *pMsg, int flags) ; |
|
Lines 111-118
Link Here
|
| 111 |
int handleCONNECT(request_block_ptr_t pBlk, char *pMsg) ; |
109 |
int handleCONNECT(request_block_ptr_t pBlk, char *pMsg) ; |
| 112 |
|
110 |
|
| 113 |
int handleCONNECT_DATA(request_block_ptr_t pBlk, char *pMsg) ; |
111 |
int handleCONNECT_DATA(request_block_ptr_t pBlk, char *pMsg) ; |
| 114 |
tptp_int32 closeConnection(request_block_ptr_t pBlock); |
112 |
int closeConnection(request_block_ptr_t pBlock); |
| 115 |
int closeSocket (int socket); |
113 |
int recvData(request_block_ptr_t pRdb, char *buffer, int length, int *bytesRead); |
|
|
114 |
int writeData(request_block_ptr_t pBlock, char* buffer, int length); |
| 115 |
int setSSL(request_block_ptr_t pBlk); |
| 116 |
int handleAUTHENTICATE(request_block_ptr_t pBlk, char *pMsg); |
| 116 |
|
117 |
|
| 117 |
/** |
118 |
/** |
| 118 |
********************************************************* |
119 |
********************************************************* |
|
Lines 162-168
Link Here
|
| 162 |
|
163 |
|
| 163 |
addBasicMsgHeader(cmd, cmdLength, &buffer, &bufferLength, flags) ; |
164 |
addBasicMsgHeader(cmd, cmdLength, &buffer, &bufferLength, flags) ; |
| 164 |
/* send the response */ |
165 |
/* send the response */ |
| 165 |
writeToSocket(pBlk->clientSock, buffer, bufferLength); |
166 |
writeData(pBlk, buffer, bufferLength); |
| 166 |
|
167 |
|
| 167 |
if (cmd) tptp_free(cmd); |
168 |
if (cmd) tptp_free(cmd); |
| 168 |
if (buffer) tptp_free(buffer); |
169 |
if (buffer) tptp_free(buffer); |
|
Lines 187-197
Link Here
|
| 187 |
TPTP_LOG_DEBUG_MSG(pBlk->pServerData, "Socket: handle CONNECT request (Control channel)."); |
188 |
TPTP_LOG_DEBUG_MSG(pBlk->pServerData, "Socket: handle CONNECT request (Control channel)."); |
| 188 |
pBlk->connectionType = CONTROL_CHANNEL ; |
189 |
pBlk->connectionType = CONTROL_CHANNEL ; |
| 189 |
|
190 |
|
|
|
191 |
if (pBlk->pServerData->securityEnabled && !pBlk->secured) { |
| 192 |
processCONNECTCall(pBlk, pMsg, CONNECTION_REFUSED | SECURITY_REQUIRED); |
| 193 |
return setSSL(pBlk); |
| 194 |
} |
| 195 |
|
| 190 |
/* tell the agent controller about the new connection */ |
196 |
/* tell the agent controller about the new connection */ |
| 191 |
/* and receive the assigned connection id */ |
197 |
/* and receive the assigned connection id */ |
| 192 |
pFunc = pBlk->pServerData->agentControllerDataBlk.addConnectionEntry ; |
198 |
pFunc = pBlk->pServerData->agentControllerDataBlk.addConnectionEntry ; |
| 193 |
pFunc(pBlk->pServerData->cmo, pBlk->pServerData->agentControllerDataBlk.transportID, |
199 |
pFunc(pBlk->pServerData->cmo, pBlk->pServerData->agentControllerDataBlk.transportID, |
| 194 |
&(pBlk->connectionId)) ; |
200 |
&(pBlk->connectionId)); |
| 195 |
|
201 |
|
| 196 |
|
202 |
|
| 197 |
/* save the socket and the control block away */ |
203 |
/* save the socket and the control block away */ |
|
Lines 203-209
Link Here
|
| 203 |
pTab = pBlk->pServerData->connectionTable ; |
209 |
pTab = pBlk->pServerData->connectionTable ; |
| 204 |
tablePut(pTab, connId, (Entry_value_ptr_t) pBlk) ; |
210 |
tablePut(pTab, connId, (Entry_value_ptr_t) pBlk) ; |
| 205 |
|
211 |
|
| 206 |
processCONNECTCall(pBlk, pMsg, CONNECTION_COMPLETE); |
212 |
if (pBlk->pServerData->securityEnabled && !pBlk->authenticated) { |
|
|
213 |
processCONNECTCall(pBlk, pMsg, CONNECTION_COMPLETE | AUTHENTICATION_FAILED); |
| 214 |
} |
| 215 |
else { |
| 216 |
processCONNECTCall(pBlk, pMsg, CONNECTION_COMPLETE); |
| 217 |
pBlk->authenticated = TRUE; |
| 218 |
} |
| 207 |
|
219 |
|
| 208 |
return 0 ; |
220 |
return 0 ; |
| 209 |
} |
221 |
} |
|
Lines 224-229
Link Here
|
| 224 |
|
236 |
|
| 225 |
TPTP_LOG_DEBUG_MSG(pBlk->pServerData, "Socket: handle CONNECT_DATA/CONNECT_CONSOLE request (Data channel)."); |
237 |
TPTP_LOG_DEBUG_MSG(pBlk->pServerData, "Socket: handle CONNECT_DATA/CONNECT_CONSOLE request (Data channel)."); |
| 226 |
|
238 |
|
|
|
239 |
if (pBlk->pServerData->securityEnabled && !pBlk->secured) { |
| 240 |
processCONNECTCall(pBlk, pMsg, CONNECTION_REFUSED | SECURITY_REQUIRED); |
| 241 |
return setSSL(pBlk); |
| 242 |
} |
| 243 |
|
| 227 |
pBlk->connectionType = DATA_CHANNEL ; |
244 |
pBlk->connectionType = DATA_CHANNEL ; |
| 228 |
|
245 |
|
| 229 |
/* tell the agent controller about the new connection */ |
246 |
/* tell the agent controller about the new connection */ |
|
Lines 234-241
Link Here
|
| 234 |
|
251 |
|
| 235 |
pFunc = pBlk->pServerData->agentControllerDataBlk.addDataConnectionEntry ; |
252 |
pFunc = pBlk->pServerData->agentControllerDataBlk.addDataConnectionEntry ; |
| 236 |
pFunc(pBlk->pServerData->cmo, pBlk->pServerData->agentControllerDataBlk.transportID, |
253 |
pFunc(pBlk->pServerData->cmo, pBlk->pServerData->agentControllerDataBlk.transportID, |
| 237 |
pBlk->flags, |
254 |
pBlk->flags, &(pBlk->connectionId)) ; |
| 238 |
&(pBlk->connectionId)) ; |
|
|
| 239 |
|
255 |
|
| 240 |
/* save the socket and the control block away */ |
256 |
/* save the socket and the control block away */ |
| 241 |
/* use the connection id as the index into the array for fast lookup */ |
257 |
/* use the connection id as the index into the array for fast lookup */ |
|
Lines 261-282
Link Here
|
| 261 |
*********************************************************/ |
277 |
*********************************************************/ |
| 262 |
int handleDISCONNECT(request_block_ptr_t pBlk, char *pMsg) |
278 |
int handleDISCONNECT(request_block_ptr_t pBlk, char *pMsg) |
| 263 |
{ |
279 |
{ |
|
|
280 |
|
| 264 |
TPTP_LOG_DEBUG_MSG(pBlk->pServerData, "Socket: handle DISCONNECT request."); |
281 |
TPTP_LOG_DEBUG_MSG(pBlk->pServerData, "Socket: handle DISCONNECT request."); |
| 265 |
if (pBlk->connectionType == DATA_CHANNEL) |
282 |
if (pBlk->connectionType == DATA_CHANNEL) |
| 266 |
{ |
283 |
{ |
| 267 |
/* pass the command to the agent controller to be processed */ |
284 |
/* pass the command to the agent controller to be processed */ |
| 268 |
removeConnectionEntry_ptr_t pRemoveFunc = |
285 |
removeConnectionEntry_ptr_t pRemoveFunc = |
| 269 |
pBlk->pServerData->agentControllerDataBlk.removeConnectionEntry ; |
286 |
pBlk->pServerData->agentControllerDataBlk.removeDataConnectionEntry; |
| 270 |
|
287 |
|
| 271 |
pRemoveFunc(pBlk->pServerData->cmo, pBlk->connectionId) ; |
288 |
pRemoveFunc(pBlk->pServerData->cmo, pBlk->connectionId); |
| 272 |
} |
289 |
} |
| 273 |
else |
290 |
else |
| 274 |
{ |
291 |
{ |
| 275 |
/* pass the command to the agent controller to be processed */ |
292 |
/* pass the command to the agent controller to be processed */ |
| 276 |
removeDataConnectionEntry_ptr_t pDataRemoveFunc = |
293 |
removeDataConnectionEntry_ptr_t pDataRemoveFunc = |
| 277 |
pBlk->pServerData->agentControllerDataBlk.removeDataConnectionEntry ; |
294 |
pBlk->pServerData->agentControllerDataBlk.removeConnectionEntry; |
| 278 |
|
295 |
|
| 279 |
pDataRemoveFunc(pBlk->pServerData->cmo, pBlk->connectionId) ; |
296 |
pDataRemoveFunc(pBlk->pServerData->cmo, pBlk->connectionId); |
| 280 |
} |
297 |
} |
| 281 |
|
298 |
|
| 282 |
return 0 ; |
299 |
return 0 ; |
|
Lines 309-323
Link Here
|
| 309 |
/* read in the payload length */ |
326 |
/* read in the payload length */ |
| 310 |
pMsg = readUINTFromBuffer(pMsg, pPayLoadLength) ; |
327 |
pMsg = readUINTFromBuffer(pMsg, pPayLoadLength) ; |
| 311 |
|
328 |
|
| 312 |
if ((flags & CONNECT) != 0) |
329 |
if ((flags & CONNECT) != 0) { |
| 313 |
{ |
|
|
| 314 |
handleCONNECT(pBlk, pMsg) ; |
330 |
handleCONNECT(pBlk, pMsg) ; |
| 315 |
|
331 |
|
| 316 |
/* prevent it from forwarding to the AC */ |
332 |
/* prevent it from forwarding to the AC */ |
| 317 |
pMsg = NULL ; |
333 |
pMsg = NULL ; |
| 318 |
} |
334 |
} |
| 319 |
else if (((flags & CONNECT_DATA) != 0) || |
335 |
else if (((flags & CONNECT_DATA) != 0) || ((flags & CONNECT_CONSOLE) != 0)) |
| 320 |
((flags & CONNECT_CONSOLE) != 0)) |
|
|
| 321 |
{ |
336 |
{ |
| 322 |
if ((flags & CONNECT_CONSOLE) != 0) |
337 |
if ((flags & CONNECT_CONSOLE) != 0) |
| 323 |
pBlk->isForConsole = TRUE; |
338 |
pBlk->isForConsole = TRUE; |
|
Lines 334-339
Link Here
|
| 334 |
/* prevent it from forwarding to the AC */ |
349 |
/* prevent it from forwarding to the AC */ |
| 335 |
pMsg = NULL ; |
350 |
pMsg = NULL ; |
| 336 |
} |
351 |
} |
|
|
352 |
else if (pBlk->pServerData->securityEnabled && !pBlk->secured) { |
| 353 |
pMsg = NULL ; |
| 354 |
} |
| 355 |
else if ((flags & AUTHENTICATE) != 0) { |
| 356 |
handleAUTHENTICATE(pBlk, pMsg) ; |
| 357 |
pMsg = NULL ; |
| 358 |
} |
| 359 |
else if (pBlk->pServerData->securityEnabled && !pBlk->authenticated) { |
| 360 |
processCONNECTCall(pBlk, pMsg, AUTHENTICATION_FAILED); |
| 361 |
pMsg = NULL ; |
| 362 |
} |
| 337 |
else |
363 |
else |
| 338 |
{ |
364 |
{ |
| 339 |
if (flags != 0) |
365 |
if (flags != 0) |
|
Lines 560-566
Link Here
|
| 560 |
|
586 |
|
| 561 |
/* Another message might come in while we're processing |
587 |
/* Another message might come in while we're processing |
| 562 |
* so we read until the pipe is empty */ |
588 |
* so we read until the pipe is empty */ |
| 563 |
while ( (rc = readFromSocket(pRdb->clientSock, buffer, bufferLength, &bytesRead)) > 0) |
589 |
while ( (rc = recvData(pRdb, buffer, bufferLength, &bytesRead)) > 0) |
| 564 |
{ |
590 |
{ |
| 565 |
TPTP_LOG_DEBUG_MSG1(pRdb->pServerData, "Socket processClientRequest: Read %d bytes.", bytesRead) ; |
591 |
TPTP_LOG_DEBUG_MSG1(pRdb->pServerData, "Socket processClientRequest: Read %d bytes.", bytesRead) ; |
| 566 |
|
592 |
|
|
Lines 616-621
Link Here
|
| 616 |
pRequestDataBlock->pServerData = pServerData ; |
642 |
pRequestDataBlock->pServerData = pServerData ; |
| 617 |
pRequestDataBlock->connectionId = 0 ; |
643 |
pRequestDataBlock->connectionId = 0 ; |
| 618 |
pRequestDataBlock->connectionType = 0 ; |
644 |
pRequestDataBlock->connectionType = 0 ; |
|
|
645 |
|
| 646 |
pRequestDataBlock->ssl_socket = NULL; |
| 647 |
pRequestDataBlock->authenticated = FALSE; |
| 648 |
pRequestDataBlock->secured = FALSE; |
| 619 |
|
649 |
|
| 620 |
pRequestDataBlock->isForConsole = FALSE ; |
650 |
pRequestDataBlock->isForConsole = FALSE ; |
| 621 |
|
651 |
|
|
Lines 677-682
Link Here
|
| 677 |
return ( rc ) ; |
707 |
return ( rc ) ; |
| 678 |
} |
708 |
} |
| 679 |
|
709 |
|
|
|
710 |
/** |
| 711 |
********************************************************* |
| 712 |
* |
| 713 |
* @brief |
| 714 |
* main running thread that accepts connection, |
| 715 |
* set up the environment and process it in a new separate thread |
| 716 |
* |
| 717 |
* @return |
| 718 |
* 0 - Success |
| 719 |
* nonzero - Error. |
| 720 |
*********************************************************/ |
| 721 |
int serveSecureRequest(server_block_ptr_t pServerData) { |
| 722 |
int rc = 0 ; |
| 723 |
request_block_ptr_t pRequestDataBlock = NULL; |
| 724 |
TID threadId; |
| 725 |
HANDLE threadHandle; |
| 726 |
ssl_socket_t ssl_socket; |
| 727 |
|
| 728 |
/* initial status before the thread is running */ |
| 729 |
pServerData->threadStatus = RUNNING ; |
| 730 |
|
| 731 |
/* accept and process one connection at a time */ |
| 732 |
while (pServerData->threadStatus == RUNNING) { |
| 733 |
ssl_socket = ssl_accept(); |
| 734 |
if (ssl_socket == NULL) break; |
| 735 |
|
| 736 |
/* set up the data block for each request */ |
| 737 |
pRequestDataBlock = getInitRequestDataBlock(0, pServerData); |
| 738 |
pRequestDataBlock->ssl_socket = ssl_socket; |
| 739 |
|
| 740 |
/* go create a new thread to process each incoming connection request */ |
| 741 |
rc = tptpStartThread(processClientRequest, (LPVOID) pRequestDataBlock, &threadId, &threadHandle); |
| 742 |
} |
| 743 |
|
| 744 |
return rc; |
| 745 |
} |
| 680 |
|
746 |
|
| 681 |
/** |
747 |
/** |
| 682 |
********************************************************* |
748 |
********************************************************* |
|
Lines 723-728
Link Here
|
| 723 |
********************************************************* |
789 |
********************************************************* |
| 724 |
* |
790 |
* |
| 725 |
* @brief |
791 |
* @brief |
|
|
792 |
* place to set up listening incoming secure requests |
| 793 |
* |
| 794 |
* @return |
| 795 |
* 0 - Success |
| 796 |
* nonzero - Error. |
| 797 |
*********************************************************/ |
| 798 |
THREAD_USER_FUNC_RET_TYPE doSecureListening(LPVOID args) { |
| 799 |
server_block_ptr_t pServerData = (server_block_ptr_t) args; |
| 800 |
|
| 801 |
/* ready to accept incoming connection requests */ |
| 802 |
serveSecureRequest(pServerData); |
| 803 |
|
| 804 |
return 0; |
| 805 |
} |
| 806 |
|
| 807 |
/** |
| 808 |
********************************************************* |
| 809 |
* |
| 810 |
* @brief |
| 726 |
* create a socket listener instance |
811 |
* create a socket listener instance |
| 727 |
* |
812 |
* |
| 728 |
* @return |
813 |
* @return |
|
Lines 731-778
Link Here
|
| 731 |
*********************************************************/ |
816 |
*********************************************************/ |
| 732 |
tptp_int32 createSocketListener(tptp_object* cmo, transport_layer_data_t * pTransportData, tptp_object* tlo) |
817 |
tptp_int32 createSocketListener(tptp_object* cmo, transport_layer_data_t * pTransportData, tptp_object* tlo) |
| 733 |
{ |
818 |
{ |
| 734 |
int rc = 0 ; |
819 |
server_block_t* pServerData; |
|
|
820 |
SocketConfigInfo socketInfo; |
| 821 |
int rc; |
| 735 |
|
822 |
|
| 736 |
rc = initForSocketCalls() ; |
823 |
rc = initForSocketCalls() ; |
|
|
824 |
if (rc != 0) { |
| 825 |
if (pTransportData->logEventEntry) |
| 826 |
pTransportData->logEventEntry(cmo, "Socket TL", pTransportData->transportID, __FILE__, __LINE__, TPTP_FATAL, "Unable to initialize socket library."); |
| 827 |
|
| 828 |
return rc; |
| 829 |
} |
| 737 |
|
830 |
|
| 738 |
if (rc == 0) |
831 |
/* prepare the globally available server data block */ |
| 739 |
{ |
832 |
pServerData = (server_block_ptr_t) malloc(sizeof(server_block_t)) ; |
| 740 |
server_block_t* pServerData; |
833 |
pServerData->cmo = cmo; |
| 741 |
SocketConfigInfo socketInfo; |
834 |
pServerData->threadStatus = 0 ; |
| 742 |
|
835 |
pServerData->agentControllerDataBlk = *pTransportData ; |
| 743 |
/* prepare the globally available server data block */ |
836 |
|
| 744 |
pServerData = (server_block_ptr_t) malloc(sizeof(server_block_t)) ; |
837 |
/* allocate connection table */ |
| 745 |
pServerData->cmo = cmo; |
838 |
pServerData->connectionTable = tableCreate(); |
| 746 |
pServerData->threadStatus = 0 ; |
839 |
|
| 747 |
pServerData->agentControllerDataBlk = *pTransportData ; |
840 |
rc = getSocketConfigInfo(pTransportData->configurationData, &socketInfo); |
| 748 |
|
841 |
if (rc != -1) |
| 749 |
/* allocate connection table */ |
842 |
{ |
| 750 |
pServerData->connectionTable = tableCreate(); |
843 |
pServerData->port = socketInfo.portNumber; |
| 751 |
|
844 |
pServerData->securityEnabled = socketInfo.securityEnabled; |
| 752 |
rc = getSocketConfigInfo(pTransportData->configurationData, &socketInfo); |
845 |
pServerData->sslProviderLib = socketInfo.sslProviderLib; |
| 753 |
if (rc != -1) |
846 |
pServerData->params = socketInfo.params; |
| 754 |
{ |
847 |
} |
| 755 |
pServerData->port = socketInfo.portNumber; |
848 |
else |
| 756 |
} |
849 |
{ |
| 757 |
else |
850 |
pServerData->port = DEFAULT_PORT_NUM; |
| 758 |
{ |
851 |
pServerData->securityEnabled = FALSE; |
| 759 |
pServerData->port = DEFAULT_PORT_NUM; |
852 |
pServerData->sslProviderLib = NULL; |
| 760 |
} |
853 |
pServerData->params = NULL; |
|
|
854 |
} |
| 761 |
|
855 |
|
| 762 |
tlo->data = pServerData; |
856 |
tlo->data = pServerData; |
| 763 |
tlo->objectID = SOCKET_LISTENER_OBJECT_ID; |
857 |
tlo->objectID = SOCKET_LISTENER_OBJECT_ID; |
| 764 |
|
858 |
|
| 765 |
TPTP_LOG_DEBUG_MSG(pServerData, "createTransportListener (socket)") ; |
859 |
TPTP_LOG_DEBUG_MSG(pServerData, "createTransportListener (socket)") ; |
| 766 |
} |
|
|
| 767 |
else |
| 768 |
{ |
| 769 |
if ( pTransportData->logEventEntry ) |
| 770 |
{ |
| 771 |
pTransportData->logEventEntry( cmo, "Socket TL", pTransportData->transportID, __FILE__, __LINE__, TPTP_FATAL, "Unable to initialize socket library." ); |
| 772 |
} |
| 773 |
} |
| 774 |
|
860 |
|
| 775 |
return ( rc ) ; |
861 |
return rc; |
| 776 |
} |
862 |
} |
| 777 |
|
863 |
|
| 778 |
/** |
864 |
/** |
|
Lines 800-807
Link Here
|
| 800 |
pServerData->threadStatus = IDLE ; |
886 |
pServerData->threadStatus = IDLE ; |
| 801 |
|
887 |
|
| 802 |
/* stop accepting connection */ |
888 |
/* stop accepting connection */ |
| 803 |
sock = pServerData->serverSock ; |
889 |
if (pServerData->securityEnabled) { |
| 804 |
rc = closeSocket(sock) ; |
890 |
ssl_reset(); |
|
|
891 |
} else { |
| 892 |
sock = pServerData->serverSock ; |
| 893 |
rc = closeSocket(sock) ; |
| 894 |
} |
| 805 |
|
895 |
|
| 806 |
/* free the connection table */ |
896 |
/* free the connection table */ |
| 807 |
tableDelete( pServerData->connectionTable ); |
897 |
tableDelete( pServerData->connectionTable ); |
|
Lines 849-864
Link Here
|
| 849 |
TPTP_LOG_DEBUG_MSG(pServerData, "startTransportListener (socket)") ; |
939 |
TPTP_LOG_DEBUG_MSG(pServerData, "startTransportListener (socket)") ; |
| 850 |
|
940 |
|
| 851 |
/* create new thread to listen for incoming connection requests */ |
941 |
/* create new thread to listen for incoming connection requests */ |
| 852 |
rc = tptpStartThread(doListening, |
942 |
if (pServerData->securityEnabled) { |
| 853 |
(LPVOID) pServerData, &threadId, &threadHandle) ; |
943 |
if (ssl_init(pServerData)) return -1; |
|
|
944 |
rc = tptpStartThread(doSecureListening,(LPVOID) pServerData, &threadId, &threadHandle); |
| 945 |
} |
| 946 |
else { |
| 947 |
rc = tptpStartThread(doListening,(LPVOID) pServerData, &threadId, &threadHandle); |
| 948 |
} |
| 854 |
|
949 |
|
| 855 |
return ( rc ) ; |
950 |
return rc; |
| 856 |
} |
951 |
} |
| 857 |
|
952 |
|
| 858 |
tptp_int32 closeConnection(request_block_ptr_t pBlock) { |
953 |
int closeConnection(request_block_ptr_t pBlock) { |
|
|
954 |
int rc=0; |
| 859 |
if (pBlock == NULL) return -1; |
955 |
if (pBlock == NULL) return -1; |
| 860 |
|
956 |
|
| 861 |
return closeSocket(pBlock->clientSock); |
957 |
if (pBlock->ssl_socket != NULL) { |
|
|
958 |
rc = ssl_close(pBlock->ssl_socket); |
| 959 |
pBlock->ssl_socket = NULL; |
| 960 |
} |
| 961 |
else { |
| 962 |
rc = closeSocket(pBlock->clientSock); |
| 963 |
} |
| 964 |
|
| 965 |
pBlock->secured = FALSE; |
| 966 |
pBlock->authenticated = FALSE; |
| 967 |
|
| 968 |
return rc; |
| 862 |
} |
969 |
} |
| 863 |
|
970 |
|
| 864 |
/** |
971 |
/** |
|
Lines 951-957
Link Here
|
| 951 |
tptp_getWriteLock( & pBlock->locker ); |
1058 |
tptp_getWriteLock( & pBlock->locker ); |
| 952 |
|
1059 |
|
| 953 |
/* go send the message */ |
1060 |
/* go send the message */ |
| 954 |
bytesSent = writeToSocket(pBlock->clientSock, pSendBuffer, bufferLength); |
1061 |
bytesSent = writeData(pBlock, pSendBuffer, bufferLength); |
| 955 |
if (bytesSent < 0) |
1062 |
if (bytesSent < 0) |
| 956 |
{ |
1063 |
{ |
| 957 |
TPTP_LOG_ERROR_MSG1(pServerData, "Socket: Failed to send data on connection ID %d", connectionID); |
1064 |
TPTP_LOG_ERROR_MSG1(pServerData, "Socket: Failed to send data on connection ID %d", connectionID); |
|
Lines 1195-1201
Link Here
|
| 1195 |
if (pBlock == NULL) return -1; |
1302 |
if (pBlock == NULL) return -1; |
| 1196 |
|
1303 |
|
| 1197 |
/* go send the message */ |
1304 |
/* go send the message */ |
| 1198 |
bytesSent = writeToSocket(pBlock->clientSock, pDataBlock, dataSize); |
1305 |
bytesSent = writeData(pBlock, pDataBlock, dataSize); |
| 1199 |
if (bytesSent < 0) |
1306 |
if (bytesSent < 0) |
| 1200 |
{ |
1307 |
{ |
| 1201 |
TPTP_LOG_ERROR_MSG1(pServerData,"Socket: Failed to send data on connection ID %d", connectionID); |
1308 |
TPTP_LOG_ERROR_MSG1(pServerData,"Socket: Failed to send data on connection ID %d", connectionID); |
|
Lines 1261-1283
Link Here
|
| 1261 |
return (forwardDataToPartner(pBlk, dataLen, pBuffer)) ; |
1368 |
return (forwardDataToPartner(pBlk, dataLen, pBuffer)) ; |
| 1262 |
} |
1369 |
} |
| 1263 |
|
1370 |
|
| 1264 |
#ifdef __linux__ |
1371 |
/** |
| 1265 |
int closeSocket (int socket) { |
1372 |
********************************************************* |
| 1266 |
struct linger linger; |
1373 |
* |
| 1267 |
int rc; |
1374 |
* @brief |
|
|
1375 |
* handle the AUTHENTICATE request |
| 1376 |
* |
| 1377 |
*********************************************************/ |
| 1378 |
int handleAUTHENTICATE(request_block_ptr_t pBlk, char *pMsg) { |
| 1379 |
char *name=NULL, *psw=NULL; |
| 1380 |
BOOL success; |
| 1381 |
|
| 1382 |
pMsg = readStringFromBuffer(pMsg, &name); |
| 1383 |
pMsg = readStringFromBuffer(pMsg, &psw); |
| 1384 |
|
| 1385 |
if (name != NULL && psw != NULL) { |
| 1386 |
success = vrfusrpwd(name, psw) > 0; |
| 1387 |
} |
| 1388 |
else{ |
| 1389 |
success = FALSE; |
| 1390 |
} |
| 1391 |
|
| 1392 |
if (success) { |
| 1393 |
TPTP_LOG_DEBUG_MSG1(pBlk->pServerData, "User %s is authenticated", name); |
| 1394 |
} |
| 1395 |
else if (name != NULL) { |
| 1396 |
TPTP_LOG_DEBUG_MSG1(pBlk->pServerData, "User %s is not authenticated", name); |
| 1397 |
} |
| 1398 |
else { |
| 1399 |
TPTP_LOG_DEBUG_MSG(pBlk->pServerData, "User <null> is not authenticated"); |
| 1400 |
} |
| 1401 |
|
| 1402 |
pBlk->authenticated = success; |
| 1403 |
if (success) { |
| 1404 |
processCONNECTCall(pBlk, pMsg, AUTHENTICATION_SUCCESSFUL); |
| 1405 |
} |
| 1406 |
else { |
| 1407 |
processCONNECTCall(pBlk, pMsg, AUTHENTICATION_FAILED); |
| 1408 |
} |
| 1409 |
|
| 1410 |
if (name != NULL) tptp_free(name); |
| 1411 |
if (psw != NULL) tptp_free(psw); |
| 1412 |
|
| 1413 |
return 0 ; |
| 1414 |
} |
| 1268 |
|
1415 |
|
| 1269 |
linger.l_onoff = 1; |
1416 |
int setSSL(request_block_ptr_t pBlk) { |
| 1270 |
linger.l_linger = 0; |
1417 |
int err = ssl_handshake(pBlk->ssl_socket); |
|
|
1418 |
if (err) { |
| 1419 |
TPTP_LOG_DEBUG_MSG(pBlk->pServerData, "SSL: ssl_handshake error"); |
| 1420 |
ssl_close(pBlk->ssl_socket); |
| 1421 |
pBlk->ssl_socket = NULL; |
| 1422 |
} |
| 1423 |
else { |
| 1424 |
pBlk->secured = TRUE; |
| 1425 |
} |
| 1271 |
|
1426 |
|
| 1272 |
rc = setsockopt(socket, SOL_SOCKET, SO_LINGER, (const char*) &linger, |
1427 |
return err; |
| 1273 |
sizeof(linger)); |
1428 |
} |
| 1274 |
|
1429 |
|
| 1275 |
close (socket); |
1430 |
int recvData(request_block_ptr_t pRdb, char *buffer, int length, int *bytesRead) { |
| 1276 |
|
1431 |
int result; |
| 1277 |
return rc; |
1432 |
|
|
|
1433 |
if (pRdb->pServerData->securityEnabled) { |
| 1434 |
result = ssl_read(pRdb->ssl_socket, buffer, length); |
| 1435 |
*bytesRead = result; |
| 1436 |
} |
| 1437 |
else { |
| 1438 |
result = readFromSocket(pRdb->clientSock, buffer, length, bytesRead); |
| 1439 |
} |
| 1440 |
|
| 1441 |
return result; |
| 1278 |
} |
1442 |
} |
| 1279 |
#else |
1443 |
|
| 1280 |
int closeSocket (int socket) { |
1444 |
int writeData(request_block_ptr_t pBlock, char* buffer, int length) { |
| 1281 |
return closeThisSocket(socket); |
1445 |
if (pBlock->pServerData->securityEnabled) { |
|
|
1446 |
return ssl_write(pBlock->ssl_socket, buffer, length); |
| 1447 |
} |
| 1448 |
else { |
| 1449 |
return writeToSocket(pBlock->clientSock, buffer, length); |
| 1450 |
} |
| 1282 |
} |
1451 |
} |
| 1283 |
#endif |
|
|