Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 195644 | Differences between
and this patch

Collapse All | Expand All

(-)src-native-new/src/transport/transportSupport/TransportSupportSocket.c (+18 lines)
Lines 470-474 Link Here
470
	return ( send(sock, buffer, byteCount, 0) ) ;
470
	return ( send(sock, buffer, byteCount, 0) ) ;
471
}
471
}
472
472
473
#ifdef __linux__
474
int closeSocket (int socket) {
475
	struct linger linger;
476
	int rc;
473
477
478
	linger.l_onoff = 1;
479
	linger.l_linger = 0;
474
480
481
	rc = setsockopt(socket, SOL_SOCKET, SO_LINGER, (const char*) &linger, 
482
				sizeof(linger));
483
484
	close (socket);
485
	
486
	return rc;
487
}
488
#else
489
int closeSocket (int socket) {
490
	return closeThisSocket(socket);
491
}
492
#endif
(-)src-native-new/src/transport/transportSupport/TransportSupport.def (+1 lines)
Lines 52-55 Link Here
52
	ipcCloseMem                    	  @49
52
	ipcCloseMem                    	  @49
53
	isMemOpen						  @50
53
	isMemOpen						  @50
54
	ipcMemDetach					  @51
54
	ipcMemDetach					  @51
55
	closeSocket						  @52
55
	
56
	
(-)src-native-new/src/shared/TPTPUtil/TPTUtil.def (-1 / +3 lines)
Lines 99-102 Link Here
99
	terminateXMLPlatformUtils
99
	terminateXMLPlatformUtils
100
	parseHostList
100
	parseHostList
101
	getExecutableName
101
	getExecutableName
102
	readStringFromBuffer
102
	readStringFromBuffer
103
	vrfusrpwd
104
	
(-)src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp (-78 / +150 lines)
Lines 27-32 Link Here
27
#include <malloc.h>
27
#include <malloc.h>
28
28
29
#include "tptp/TPTPUtils.h"
29
#include "tptp/TPTPUtils.h"
30
#include "tptp/TPTPConfig.h"
30
31
31
#ifdef _WIN32
32
#ifdef _WIN32
32
	#include <sys/types.h>
33
	#include <sys/types.h>
Lines 44-49 Link Here
44
	#include <sys/types.h>
45
	#include <sys/types.h>
45
	#include <linux/stat.h>  //for mode S_IXUSR
46
	#include <linux/stat.h>  //for mode S_IXUSR
46
	#define STAT stat
47
	#define STAT stat
48
  	#include <signal.h>
49
  	#include <sys/wait.h>
47
	#include <ctype.h>
50
	#include <ctype.h>
48
#endif
51
#endif
49
52
Lines 103-110 Link Here
103
                  tptp_list_t**		paramList )
106
                  tptp_list_t**		paramList )
104
{
107
{
105
	try {
108
	try {
106
		char *tempnodename = 0;
107
108
		//Initialize the XML parser
109
		//Initialize the XML parser
109
		DOMImplementation *impl		= DOMImplementationRegistry::getDOMImplementation(&chNull);
110
		DOMImplementation *impl		= DOMImplementationRegistry::getDOMImplementation(&chNull);
110
		DOMBuilder        *parser	= ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
111
		DOMBuilder        *parser	= ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
Lines 949-1020 Link Here
949
	return ++endIdx; //Move past the closing delim for the value
950
	return ++endIdx; //Move past the closing delim for the value
950
}
951
}
951
952
952
int getSocketConfigInfo( const char* config, SocketConfigInfo *socketInfo )
953
int getSocketConfigInfo(const char* config, SocketConfigInfo *socketInfo) {
953
{
954
	tptp_param_t* param;
954
	char* tagName=NULL;
955
	tptp_node_t*  node;
955
	char* elementName=NULL;
956
	char* elementValue=NULL;
957
	int mstrIdx=0;
958
	int nextIdx=0;
959
	int endIdx = strlen(config);
960
961
	nextIdx = getTagName(config, &tagName);
962
	if ((nextIdx == -1) || (tagName == NULL)) goto errorReturn; //Error: badly formed cmd
963
964
	if (!isEqualString(tagName, "Configuration") ) goto errorReturn; //Error: Don't have a "Cmd"
965
	mstrIdx += nextIdx;
966
	mstrIdx++;
967
	tptp_free(tagName); tagName=NULL;
968
956
969
	socketInfo->securityEnabled = 0;	// default
957
	socketInfo->securityEnabled = 0;	// default
958
	socketInfo->sslProviderLib = NULL;
959
	socketInfo->params = NULL;
970
	
960
	
971
	while (1)
961
	if (getXMLElements(config, &socketInfo->params) < 0) return -1;
972
	{ 
973
		nextIdx = getConfigElementName(&(config[mstrIdx]), &elementName);
974
		if (isEqualString(elementName, "/Configuration")) break;
975
		
976
		if ((nextIdx == -1) || (elementName == NULL)) goto errorReturn; //Error: badly formed cmd
977
		mstrIdx += nextIdx;
978
 
979
		nextIdx = getConfigElementValue(&(config[mstrIdx]), &elementValue);
980
		if ((nextIdx == -1) || (elementValue == NULL)) goto errorReturn; //Error: badly formed cmd
981
		mstrIdx += nextIdx;
982
983
		nextIdx = skipConfigElementClose(&(config[mstrIdx]));
984
		if (nextIdx == -1) goto errorReturn; //Error: badly formed cmd
985
		mstrIdx += nextIdx;
986
987
		if (isEqualString(elementName, "Port"))
988
		{
989
			socketInfo->portNumber = atoi(elementValue);
990
		}
991
		else if (isEqualString(elementName, "SecurityEnabled"))
992
		{
993
			socketInfo->securityEnabled = isEqualString(elementValue, "true");
994
		}
995
		else if (isEqualString(elementName, "Hosts Configuration"))
996
		{
997
			socketInfo->hostConfig = elementValue;
998
		}
999
		else if (isEqualString(elementName, "Allow host"))
1000
		{
1001
			socketInfo->allowHosts = elementValue;
1002
		}
1003
962
1004
		tptp_free(elementName); elementName=NULL;
963
	for (node = socketInfo->params->head; node != 0; node = node->next) {
1005
		tptp_free(elementValue); elementValue=NULL;
964
		param = (tptp_param_t*) node->data;
965
		if (param == NULL) continue;
966
967
		if (isEqualString(param->name, "Port")) {
968
			socketInfo->portNumber = atoi(param->value);
969
		} 
970
		else if (isEqualString(param->name, "SecurityEnabled")) {
971
			socketInfo->securityEnabled = isEqualString(param->value, "true");
972
		} 
973
		else if (isEqualString(param->name, "Hosts Configuration")) {
974
			socketInfo->hostConfig = param->value;
975
		} 
976
		else if (isEqualString(param->name, "Allow host")) {
977
			socketInfo->allowHosts = param->value;
978
		} 
979
		else if (isEqualString(param->name, "SSLproviderLib")) {
980
			socketInfo->sslProviderLib = param->value;
981
		} 
1006
	}
982
	}
1007
983
1008
	if (elementName) {tptp_free(elementName); elementName=NULL;}
1009
	if (elementValue) {tptp_free(elementValue); elementValue=NULL;}
1010
1011
	return 0;
984
	return 0;
1012
1013
errorReturn:
1014
	if (tagName != NULL) tptp_free(tagName);
1015
	if (elementName != NULL) tptp_free(elementName);
1016
	if (elementValue != NULL) tptp_free(elementValue);
1017
	return -1; //TODO: replace with real error codes
1018
}
985
}
1019
986
1020
int getNamedPipeConfigInfo( const char* config, char **pipeName )
987
int getNamedPipeConfigInfo( const char* config, char **pipeName )
Lines 1263-1269 Link Here
1263
		tptp_list_setNodeDestructor(*paramList, destroyParamNode);
1230
		tptp_list_setNodeDestructor(*paramList, destroyParamNode);
1264
		tptp_list_setNodeCopier(*paramList, copyParamNode);
1231
		tptp_list_setNodeCopier(*paramList, copyParamNode);
1265
1232
1266
		bool	isCmdRoot = false;
1267
		DOMImplementation *impl		= DOMImplementationRegistry::getDOMImplementation(&chNull);
1233
		DOMImplementation *impl		= DOMImplementationRegistry::getDOMImplementation(&chNull);
1268
		DOMBuilder        *parser	= ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
1234
		DOMBuilder        *parser	= ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
1269
		
1235
		
Lines 1281-1303 Link Here
1281
		XERCES_CPP_NAMESPACE::DOMDocument *doc = parser->parse(*domBufIS);
1247
		XERCES_CPP_NAMESPACE::DOMDocument *doc = parser->parse(*domBufIS);
1282
		DOMTreeWalker* iter = doc->createTreeWalker(doc->getDocumentElement(),DOMNodeFilter::SHOW_ELEMENT,NULL,true);
1248
		DOMTreeWalker* iter = doc->createTreeWalker(doc->getDocumentElement(),DOMNodeFilter::SHOW_ELEMENT,NULL,true);
1283
        
1249
        
1284
		//Got the Node after the Root - The assumption here is that there is an encapsulating element around the 
1285
		//<Cmd></Cmd> tags
1286
		char *roottag = XMLString::transcode(iter->getCurrentNode()->getNodeName());
1287
		if(strcmp(roottag, "Cmd")==0)
1288
		{
1289
			isCmdRoot = true;
1290
		}
1291
		XMLString::release(&roottag);
1292
		DOMNode *node; 
1293
		if(!isCmdRoot){node = iter->firstChild();}
1294
1295
		DOMNode *curr = iter->getCurrentNode();
1250
		DOMNode *curr = iter->getCurrentNode();
1296
		if(curr != NULL)
1251
		if(curr != NULL)
1297
		{
1252
		{
1298
			char *tempparmval = "\0";
1253
			char *tempparmval = "\0";
1299
			tptp_param_t* newParam;
1254
			tptp_param_t* newParam;
1300
			char *tempparmname = XMLString::transcode(curr->getNodeName());	
1255
			char *tempparmname = XMLString::transcode(curr->getNodeName());
1256
 				
1301
			newParam = initParamT(tempparmname, tempparmval);
1257
			newParam = initParamT(tempparmname, tempparmval);
1302
			tptp_list_add(*paramList, (void*)newParam);
1258
			tptp_list_add(*paramList, (void*)newParam);
1303
			addElementAttrs(curr, *paramList);
1259
			addElementAttrs(curr, *paramList);
Lines 1727-1736 Link Here
1727
		TPTPParserErrorHandler* tptp_dom_err = new TPTPParserErrorHandler();
1683
		TPTPParserErrorHandler* tptp_dom_err = new TPTPParserErrorHandler();
1728
		parser->setErrorHandler(tptp_dom_err);
1684
		parser->setErrorHandler(tptp_dom_err);
1729
1685
1730
		char* executable=NULL;
1731
		char* path=NULL;
1732
		char* location=NULL;
1733
1734
		XERCES_CPP_NAMESPACE::DOMDocument *doc = parser->parse(*domBufIS);
1686
		XERCES_CPP_NAMESPACE::DOMDocument *doc = parser->parse(*domBufIS);
1735
1687
1736
		//Initialize the list to NULL... just so that we can check it later.
1688
		//Initialize the list to NULL... just so that we can check it later.
Lines 1914-1916 Link Here
1914
		return -1;
1866
		return -1;
1915
	}
1867
	}
1916
}
1868
}
1869
1870
/*
1871
 * --------------------------------------------------------------------------------
1872
 * All the platform-dependent vrfusrpwd() functions below
1873
 * --------------------------------------------------------------------------------
1874
 */
1875
1876
#if defined(_WIN32)
1877
/*
1878
 *	Windows/IA32 section, in-process authentication
1879
 */
1880
int vrfusrpwd(tptp_string *userid, tptp_string *password) {
1881
	HANDLE handle;
1882
	return LogonUser(userid, NULL, password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &handle) ? 1 : 0;
1883
}
1884
#elif defined(__MVS__)
1885
/*
1886
 *	OS/390 section, in-process authentication. BPX.DAEMON is needed.
1887
 */
1888
int vrfusrpwd(tptp_string *userid, tptp_string *password) {
1889
	return __passwd(userid, password, NULL) ? 0 : 1;
1890
}
1891
#elif defined(__OS400__)
1892
/*
1893
 *	OS/400 section, in-process authentication
1894
 */
1895
int vrfusrpwd(tptp_string *userid, tptp_string *password) {
1896
	struct error_code_t errorCode;
1897
	char profileHandle[12];  /* profile handle, required by QSYGETPH API */
1898
	char useridBuf[10] = "          ";
1899
1900
	/* In descrypted case, the password is in code page of 437 */
1901
	errorCode.bytesProvided = 64;
1902
	errorCode.bytesAvailable = 0;
1903
1904
	if(userid[0] == '*') {
1905
		return 0;
1906
	}
1907
	else if(strlen(userid) > 10) {
1908
		return 0;
1909
	}
1910
	else {
1911
		int i;
1912
		for(i = 0; i < strlen(userid); i++) {
1913
			useridBuf[i] = toupper(userid[i]); /* change it all to upper case */
1914
		}
1915
	}
1916
1917
	QSYGETPH(useridBuf, password, profileHandle, &errorCode, strlen(password), 37); /* CCSID of password is 37 (EBCDIC) */
1918
1919
	if(errorCode.bytesAvailable > 0) {
1920
		char *exc = (char*)ra_malloc(sizeof(char) * 8);
1921
		BZERO(exc, 8);
1922
		strncpy(exc, errorCode.exceptionID, 7);
1923
		ra_free(exc);
1924
1925
		return 0;
1926
	}
1927
	else {
1928
		return 1;  /* authentication successful */
1929
	}
1930
}
1931
#else /* non-Windows, non-OS/400 */
1932
/*
1933
 * Launch a separate process to authenticate user name and password
1934
 */
1935
int vrfusrpwd(tptp_string *userid, tptp_string *password) {
1936
	FILE *fp;
1937
	int success = 0; // FALSE
1938
	char *serverHome;
1939
	char *authCmd;
1940
	int authLen;
1941
	int status;
1942
	int rc=0;
1943
1944
	struct sigaction ignoreHandler; /* Use this handler for bypassing pre-configured signal handler */
1945
	struct sigaction oldHandler; /* Used to temporary storing the configured signal handler */
1946
1947
	serverHome = getCacheEnv("default", "RASERVER_HOME");
1948
	/* Do not pass user ID and password since they will be shown by running 'ps' */
1949
	authLen = strlen(serverHome) + 1 + strlen("bin") + 1 + strlen("ChkPass") + 1; /* Bug 168705 : need a null at the end for strcat() */
1950
	authCmd = (char*)malloc(sizeof(char) * authLen);
1951
	BZERO(authCmd, authLen);
1952
	strcpy(authCmd, serverHome);
1953
	strcat(authCmd, "/");
1954
	strcat(authCmd, "bin");
1955
	strcat(authCmd, "/");
1956
	strcat(authCmd, "ChkPass");
1957
1958
	/* Disable default SIGCHLD handler since system() call doesn't work with user-supplied signal handlers */
1959
	BZERO(&ignoreHandler, sizeof(struct sigaction));
1960
	BZERO(&oldHandler, sizeof(struct sigaction));
1961
1962
	ignoreHandler.sa_handler = SIG_DFL; /* Reset to default SIGCHLD handler */
1963
	sigaction(SIGCHLD, &ignoreHandler, &oldHandler); /* Store the previous signal handler */
1964
1965
	fp = popen(authCmd, "w");
1966
	fprintf(fp, "%s\n", userid);
1967
	fprintf(fp, "%s\n", password);
1968
	status = pclose(fp);
1969
	if(WIFEXITED(status)) {
1970
		rc = WEXITSTATUS(status);
1971
	}
1972
1973
	if(rc == 100) { /* 100 indicates success */
1974
		success = 1;
1975
	}
1976
	else {
1977
		success = 0;
1978
	}
1979
1980
	/* Re-enable the user-specified SIGCHLD handler */
1981
	sigaction(SIGCHLD, &oldHandler, NULL);
1982
1983
	free(authCmd);
1984
1985
	return success;
1986
}
1987
1988
#endif
(-)src-native-new/src/shared/TPTPUtil/TPTPSupportUtils.c (-2 / +6 lines)
Lines 75-83 Link Here
75
}
75
}
76
76
77
unsigned char* readStringFromBuffer(unsigned char *buffer, char** str) {
77
unsigned char* readStringFromBuffer(unsigned char *buffer, char** str) {
78
	int len;
78
	int len, padding;
79
	
79
	
80
	buffer = readUINTFromBuffer(buffer, &len);
80
	buffer = readUINTFromBuffer(buffer, &len);
81
81
	if (len == 0)
82
	if (len == 0)
82
		*str = NULL;
83
		*str = NULL;
83
	else {
84
	else {
Lines 87-91 Link Here
87
		buffer += len;
88
		buffer += len;
88
	}
89
	}
89
	
90
	
90
	return buffer;
91
	padding = 4 - len%4;
92
	if (padding == 4) padding = 0;
93
	
94
	return buffer + padding;
91
}
95
}
(-)src-native-new/include/tptp/TransportSupportSocket.h (-2 / +1 lines)
Lines 196-203 Link Here
196
196
197
int getPeerName(SOCKET sock, unsigned char *pAddr);
197
int getPeerName(SOCKET sock, unsigned char *pAddr);
198
198
199
199
int closeSocket(int socket);
200
201
200
202
#ifdef __cplusplus
201
#ifdef __cplusplus
203
}
202
}
(-)src-native-new/include/tptp/TPTPUtils.h (+4 lines)
Lines 80-85 Link Here
80
	char *hostConfig;
80
	char *hostConfig;
81
	char *allowHosts;
81
	char *allowHosts;
82
	int securityEnabled;
82
	int securityEnabled;
83
	char *sslProviderLib;
84
	tptp_list_t* params;
83
} SocketConfigInfo;
85
} SocketConfigInfo;
84
86
85
/* Define the various types of host addressing wildcards and types */
87
/* Define the various types of host addressing wildcards and types */
Lines 268-273 Link Here
268
270
269
int parseHostList(const char *initString, network_list_t **nList);
271
int parseHostList(const char *initString, network_list_t **nList);
270
272
273
int vrfusrpwd(tptp_string *userid, tptp_string *password);
274
271
#ifdef __cplusplus
275
#ifdef __cplusplus
272
} /* Ends extern C */
276
} /* Ends extern C */
273
#endif
277
#endif
(-)src-native-new/src/transport/socketTL/SocketListener.h (+9 lines)
Lines 22-27 Link Here
22
#include "tptp/TPTPMessageHeader.h"
22
#include "tptp/TPTPMessageHeader.h"
23
#include "tptp/hashtable.h"
23
#include "tptp/hashtable.h"
24
24
25
#include "SSLTypes.h"
26
25
#define SOCKET_LISTENER_OBJECT_ID  20001
27
#define SOCKET_LISTENER_OBJECT_ID  20001
26
28
27
/** instance-specific data block */
29
/** instance-specific data block */
Lines 32-38 Link Here
32
	tptp_object*            cmo ;
34
	tptp_object*            cmo ;
33
	transport_layer_data_t	agentControllerDataBlk ;
35
	transport_layer_data_t	agentControllerDataBlk ;
34
	processMessage_ptr_t    processMessage;
36
	processMessage_ptr_t    processMessage;
37
	int						securityEnabled;
38
	char*					sslProviderLib;
35
	tptp_object*            nexto;
39
	tptp_object*            nexto;
40
	tptp_list_t* 		 	params;
36
41
37
	/* hash table of connections for easy and fast search */
42
	/* hash table of connections for easy and fast search */
38
    HashTable               *  connectionTable ;
43
    HashTable               *  connectionTable ;
Lines 197-202 Link Here
197
	sendData_ptr_t      pSendFunc ;
202
	sendData_ptr_t      pSendFunc ;
198
	tptp_object*        partner;
203
	tptp_object*        partner;
199
	int                 connectionPartnerID ;
204
	int                 connectionPartnerID ;
205
	
206
	ssl_socket_t		ssl_socket;
207
	BOOL				secured;
208
	BOOL				authenticated;
200
209
201
	BOOL                isForConsole ;
210
	BOOL                isForConsole ;
202
	
211
	
(-)src-native-new/src/transport/socketTL/SocketListener.c (-81 / +249 lines)
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
(-)src-native-new/src/transport/socketTL/SocketTL.dsp (+8 lines)
Lines 105-110 Link Here
105
SOURCE=.\socketTL.def
105
SOURCE=.\socketTL.def
106
# PROP Exclude_From_Build 1
106
# PROP Exclude_From_Build 1
107
# End Source File
107
# End Source File
108
# Begin Source File
109
110
SOURCE=.\SSLSupport.c
111
# End Source File
108
# End Group
112
# End Group
109
# Begin Group "Header Files"
113
# Begin Group "Header Files"
110
114
Lines 121-126 Link Here
121
125
122
SOURCE=.\SocketTLLog.h
126
SOURCE=.\SocketTLLog.h
123
# End Source File
127
# End Source File
128
# Begin Source File
129
130
SOURCE=.\SSLSupport.h
131
# End Source File
124
# End Group
132
# End Group
125
# Begin Group "Resource Files"
133
# Begin Group "Resource Files"
126
134
(-)src-native-new/src/transport/socketTL/SSLSupport.c (+128 lines)
Added Link Here
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
5
#include "SSLTypes.h"
6
#include "SSLSupport.h"
7
#include "SocketTLLog.h"
8
#include "tptp/TPTPUtils.h"
9
#include "tptp/tptpSSLProvider.h"
10
11
/* Resolved SSL functions */
12
static ssl_provider_accept_t ssl_provider_accept; 
13
static ssl_provider_handshake_t ssl_provider_handshake; 
14
static ssl_provider_read_t ssl_provider_read; 
15
static ssl_provider_write_t ssl_provider_write; 
16
static ssl_provider_close_t ssl_provider_close; 
17
static ssl_provider_reset_t ssl_provider_reset; 
18
static ssl_provider_reset_t ssl_provider_reset; 
19
static ssl_provider_getValue_t ssl_provider_getValue; 
20
static ssl_provider_setValue_t ssl_provider_setValue; 
21
static ssl_provider_getName_t ssl_provider_getName; 
22
23
int ssl_init(server_block_ptr_t pServerData) {
24
	tptp_param_t* param;
25
	tptp_node_t*  node;
26
	log_service_t* logService;
27
28
	DLL_REFERENCE sslLibrary;
29
	ssl_provider_init_t ssl_provider_init;
30
	int rc;
31
32
	if (!pServerData->securityEnabled) return 0;
33
34
	if (pServerData->sslProviderLib == NULL) {
35
		TPTP_LOG_ERROR_MSG(pServerData, "No ssl provider library supplied");
36
		return -1;
37
	}
38
39
	sslLibrary = LOAD_LIBRARY(pServerData->sslProviderLib);
40
	if (sslLibrary == NULL) {
41
		TPTP_LOG_ERROR_MSG1(pServerData, "Unable to find ssl provider library %s", pServerData->sslProviderLib);
42
		return -1;
43
	}
44
45
	ssl_provider_init = (ssl_provider_init_t) RESOLVE_ENTRY_POINT(sslLibrary, SSL_INIT);
46
	ssl_provider_accept = (ssl_provider_accept_t) RESOLVE_ENTRY_POINT(sslLibrary, SSL_ACCEPT); 
47
	ssl_provider_handshake = (ssl_provider_handshake_t) RESOLVE_ENTRY_POINT(sslLibrary, SSL_HANDSHAKE); 
48
	ssl_provider_read = (ssl_provider_read_t) RESOLVE_ENTRY_POINT(sslLibrary, SSL_READ); 
49
	ssl_provider_write = (ssl_provider_write_t) RESOLVE_ENTRY_POINT(sslLibrary, SSL_WRITE); 
50
	ssl_provider_close = (ssl_provider_close_t) RESOLVE_ENTRY_POINT(sslLibrary, SSL_CLOSE); 
51
	ssl_provider_reset = (ssl_provider_reset_t) RESOLVE_ENTRY_POINT(sslLibrary, SSL_RESET); 
52
	ssl_provider_getValue = (ssl_provider_getValue_t) RESOLVE_ENTRY_POINT(sslLibrary, SSL_GET_VALUE); 
53
	ssl_provider_setValue = (ssl_provider_setValue_t) RESOLVE_ENTRY_POINT(sslLibrary, SSL_SET_VALUE); 
54
	ssl_provider_getName = (ssl_provider_getName_t) RESOLVE_ENTRY_POINT(sslLibrary, SSL_GET_PROVIDER_NAME); 
55
	
56
    /* Check to make sure we found everything */ 
57
    if (ssl_provider_init &&
58
    	ssl_provider_accept &&
59
    	ssl_provider_handshake &&
60
    	ssl_provider_read &&
61
    	ssl_provider_write &&
62
    	ssl_provider_close &&
63
    	ssl_provider_reset &&
64
    	ssl_provider_getValue &&
65
    	ssl_provider_setValue &&
66
    	ssl_provider_getName) {
67
68
		for (node = pServerData->params->head; node != 0; node = node->next) {
69
			param = (tptp_param_t*) node->data;
70
			if (param != NULL && param->name != NULL && param->value != NULL) {
71
				ssl_setValue(param->name, param->value);
72
			}
73
		}
74
    	
75
    	logService = (log_service_t*) tptp_malloc(sizeof(log_service_t));
76
    	logService->cmo = pServerData->cmo;
77
    	logService->logEventEntry = pServerData->agentControllerDataBlk.logEventEntry;
78
    	
79
		rc = (*ssl_provider_init)(logService, pServerData->port);
80
		if (rc) {
81
			TPTP_LOG_ERROR_MSG1(pServerData, "Unable to initialize ssl provider %s", pServerData->sslProviderLib);
82
		} else {
83
			TPTP_LOG_DEBUG_MSG1(pServerData, "SSL provider \"%s\" successfully initialized", ssl_getProviderName());
84
		}
85
    } 
86
	else {
87
		TPTP_LOG_ERROR_MSG1(pServerData, "Unable to resolve ssl provider library %s", pServerData->sslProviderLib);
88
		rc = -1;
89
	}
90
	
91
	return rc;
92
}
93
94
ssl_socket_t ssl_accept() {
95
	return (ssl_provider_accept == NULL) ? NULL : (*ssl_provider_accept)();
96
}
97
98
int ssl_handshake(ssl_socket_t ssl_socket) {
99
	return (ssl_socket == NULL || ssl_provider_handshake == NULL) ? -1 : (*ssl_provider_handshake)(ssl_socket);
100
}
101
102
int ssl_read(ssl_socket_t ssl_socket, char* buffer, int length) {
103
	return (ssl_socket == NULL || ssl_provider_read == NULL) ? -1 : (*ssl_provider_read)(ssl_socket, buffer, length);
104
}
105
106
int ssl_write(ssl_socket_t ssl_socket, char* buffer, int length) {
107
	return (ssl_socket == NULL || ssl_provider_write == NULL) ? -1 : (*ssl_provider_write)(ssl_socket, buffer, length);
108
}
109
110
int ssl_close(ssl_socket_t ssl_socket) {
111
	return (ssl_socket == NULL || ssl_provider_close == NULL) ? -1 : (*ssl_provider_close)(ssl_socket);
112
}
113
114
int ssl_reset() {
115
	return (ssl_provider_reset == NULL) ? -1 : (*ssl_provider_reset)();
116
}
117
118
char* ssl_getValue(const char* name) {
119
	return (ssl_provider_getValue == NULL) ? NULL : (*ssl_provider_getValue)(name);
120
}
121
122
void ssl_setValue(const char* name, const char* value) {
123
	if (ssl_provider_setValue != NULL) (*ssl_provider_setValue)(name, value);
124
}
125
126
char* ssl_getProviderName() {
127
	return (ssl_provider_getName == NULL) ? NULL : (*ssl_provider_getName)();
128
}
(-)src-native-new/src/transport/socketTL/SSLSupport.h (+18 lines)
Added Link Here
1
#ifndef SSLSUPPORT_H
2
#define SSLSUPPORT_H
3
4
#include "SocketListener.h"
5
#include "SSLTypes.h"
6
7
extern int ssl_init(server_block_ptr_t pServerData);
8
extern ssl_socket_t ssl_accept();
9
extern int ssl_handshake(ssl_socket_t ssl_socket);
10
extern int ssl_read(ssl_socket_t ssl_socket, char* buffer, int length);
11
extern int ssl_write(ssl_socket_t ssl_socket, char* buffer, int length);
12
extern int ssl_close(ssl_socket_t ssl_socket);
13
extern int ssl_reset();
14
extern char* ssl_getValue(const char* name);
15
extern void ssl_setValue(const char* name, const char* value);
16
extern char* ssl_getProviderName();
17
18
#endif
(-)src-native-new/src/transport/socketTL/SSLTypes.h (+30 lines)
Added Link Here
1
#ifndef _SSLTypes_H
2
#define _SSLTypes_H
3
4
typedef void* ssl_socket_t;
5
6
/* Function names to be imported */
7
#define SSL_INIT 		"sslInit"
8
#define SSL_ACCEPT 		"sslAccept"
9
#define SSL_HANDSHAKE 	"sslHandshake"
10
#define SSL_READ 		"sslRead"
11
#define SSL_WRITE 		"sslWrite"
12
#define SSL_CLOSE 		"sslClose"
13
#define SSL_RESET 		"sslReset"
14
#define SSL_GET_VALUE 	"sslGetValue"
15
#define SSL_SET_VALUE 	"sslSetValue"
16
#define SSL_GET_PROVIDER_NAME "sslGetProviderName"
17
18
/* SSL function types */
19
typedef int (*ssl_provider_init_t)();
20
typedef ssl_socket_t (*ssl_provider_accept_t)();
21
typedef int (*ssl_provider_handshake_t)();
22
typedef int (*ssl_provider_read_t)();
23
typedef int (*ssl_provider_write_t)();
24
typedef int (*ssl_provider_close_t)();
25
typedef int (*ssl_provider_reset_t)();
26
typedef char* (*ssl_provider_getValue_t)(const char*);
27
typedef void (*ssl_provider_setValue_t)(const char*, const char*);
28
typedef char* (*ssl_provider_getName_t)();
29
30
#endif
(-)src-native-new/include/tptp/tptpSSLProvider.h (+24 lines)
Added Link Here
1
#ifndef _TPTP_SSL_PROVIDER_H
2
#define _TPTP_SSL_PROVIDER_H
3
4
typedef struct {
5
  	tptp_object* cmo;
6
  	logEventEntry_ptr_t logEventEntry;
7
} log_service_t;
8
9
/*
10
 * Interface functions for SSL provider
11
 */
12
int sslInit(log_service_t *logService, int port);
13
14
void* sslAccept();
15
int sslHandshake(void* handle);
16
int sslRead(void* handle, char* buffer, int length);
17
int sslWrite(void* handle, char* buffer, int length);
18
int sslClose(void* handle);
19
int sslReset();
20
char* sslGetProviderName();
21
char* sslGetValue(const char* name);
22
void sslSetValue(const char* name, const char* value);
23
24
#endif

Return to bug 195644