Exemple #1
0
/**************************************************************
SocketOnConnected(SOCKET s, const char *lpszName)
	
		If the security is enabled then perform te SSL neogotiation
		otherwise just return a success and let the plain text FTP handles
		the comunication

		To let the server know that we are looking for SSL or TLS we need to
		send the following command
		FEAT  
		The Feature negotiation mechanism for the File Transfer Protocol 
		
		To ask the server for SSL or TLS negotiation 
		we will send the AUTH command.

		A parameter for the AUTH command to indicate that TLS is
		required.  It is recommended that 'TLS', 'TLS-C', 'SSL' and 'TLS-P'
		are acceptable, and mean the following :-

		 'TLS' or 'TLS-C' - the TLS protocol or the SSL protocol will be
			negotiated on the control connection.  The default protection
			setting for the Data connection is 'Clear'.

			'SSL' or 'TLS-P' - the TLS protocol or the SSL protocol will be
			negotiated on the control connection.  The default protection
			setting for the Data connection is 'Private'.  This is primarily
			for backward compatibility.

	Notice that we will first send a TLS P to select The highest implementation.
	the server might response with the response
	503 unknown security mechanism 

	if this happened we will issue an Auth SSL command.

Param:
	SOCKET s		- The newly created socket 
	lpszName		- apointer to the host name we are attempting to connect to


Return:
	UTE_NO_RESPONSE - Server did not response to our command
	UTE_CONNECT_FAIL_NO_SSL_SUPPORT - Server does not support SSL.
	UTE_CONNECT_FAILED	-	 The connection have failed
	security  errors   - This function may fail with other error
			UTE_LOAD_SECURITY_LIBRARIES_FAILED
			UTE_OUT_OF_MEMORY
			UTE_FAILED_TO_GET_SECURITY_STREAM_SIZE
			UTE_OUT_OF_MEMORY
			UTE_FAILED_TO_QUERY_CERTIFICATE
			UTE_NULL_PARAM
			UTE_PARAMETER_INVALID_VALUE
			UTE_FAILED_TO_GET_CERTIFICATE_CHAIN
			UTE_FAILED_TO_VERIFY_CERTIFICATE_CHAIN
			UTE_FAILED_TO_VERIFY_CERTIFICATE_TRUST
	UTE_POP3_TLS_NOT_SUPPORTED - server does not support the STLS command	
**************************************************************/
int CUT_POP3Client::SocketOnConnected(SOCKET s, const char *lpszName){

	int		rt = UTE_SUCCESS;	

#ifdef CUT_SECURE_SOCKET
	
	BOOL bSecFlag = GetSecurityEnabled();
	
	if(bSecFlag)
	{
		
		// disable the secure comunication so we can send the plain data 
		SetSecurityEnabled(FALSE);
		
		// get server response
		if( !GetResponseCode(m_nPOP3TimeOut))
			rt = UTE_CONNECT_FAILED;
		else{
			
			
			Send("STLS\r\n");
			
			// get response
			if( GetResponseCode(m_nPOP3TimeOut))
			{
				// reset back the security so we can proceed with negotiation
				SetSecurityEnabled(bSecFlag);
				rt =  CUT_SecureSocketClient::SocketOnConnected(s, lpszName);
			}
			else
				rt = UTE_POP3_TLS_NOT_SUPPORTED;
		}
		
		return rt;
		
	}
	else
	{
		
		return UTE_SUCCESS;
	}

#else 
// v4.2 non-secure builds result in unref'd param warns VC6
	UNREFERENCED_PARAMETER(s);
	UNREFERENCED_PARAMETER(lpszName);

// v4.2 unreachable code in secure build
	return OnError(rt);
// v4.22 check this - was retuning UTE_SUCCESS
#endif

}
Exemple #2
0
int CUT_POP3Client::POP3Connect(LPCSTR mailHost, LPCSTR user, LPCSTR password) {

    int     error;

    //close any open connection
    POP3Close();

    //connect
    if((error = Connect(m_nPort, mailHost, m_nConnectTimeout)) != UTE_SUCCESS) 
        return OnError(error);
    
    //get the response code
	if(GetResponseCode(m_nPOP3TimeOut) == FALSE)
		return OnError(UTE_CONNECT_TIMEOUT);

    //send the user name
    Send("USER ");
    Send(user);
    Send("\r\n");

    if(GetResponseCode(m_nPOP3TimeOut) == FALSE)
        return OnError(UTE_USER_FAILED);

    if(IsAborted())         // Test for abortion flag
        return OnError(UTE_ABORTED);

    //send the password
    Send("PASS ");
    Send(password);
    Send("\r\n");

    if(GetResponseCode(m_nPOP3TimeOut) == FALSE)
        return OnError(UTE_PASS_FAILED);


    return OnError(UTE_SUCCESS);
}
CommandStatus CommandResponder :: HandleControl(const Setpoint& aControl, size_t aIndex)
{
	CommandStatus cs = CS_TOO_MANY_OPS;
	if ( mLinkStatuses ) {
		try {
			Transaction t(mpObs);
			mpObs->Update(SetpointStatus(aControl.GetValue(), SetpointStatus::ONLINE), aIndex);
			cs = CS_SUCCESS;
			LOG_BLOCK(LEV_INFO, "Updated SetpointStatus " << aIndex << " with " << aControl.GetValue() << "." );
		}
		catch (Exception& ex) {
			LOG_BLOCK(LEV_WARNING, "Failure trying to update point in response to control. " << ex.GetErrorString());
			cs = CS_FORMAT_ERROR;
		}
	}
	else {
		cs = GetResponseCode(false, aIndex);
	}
	LOG_BLOCK(LEV_INFO, "[" << aIndex << "] - " <<  aControl.ToString() << " returning " << ToString(cs));
	return cs;
}
CommandStatus CommandResponder :: HandleControl(const BinaryOutput& aControl, size_t aIndex)
{
	CommandStatus cs = CS_TOO_MANY_OPS;
	if ( mLinkStatuses && (aControl.GetCode() == CC_LATCH_ON || aControl.GetCode() == CC_LATCH_OFF)) {
		try {
			Transaction t(mpObs);
			bool val = aControl.GetCode() == CC_LATCH_ON ? true : false;
			mpObs->Update(ControlStatus(val, ControlStatus::ONLINE), aIndex);
			cs = CS_SUCCESS;
			LOG_BLOCK(LEV_INFO, "Updated ControlStatus " << aIndex << " with " << val << "." );
		}
		catch (Exception& ex) {
			LOG_BLOCK(LEV_WARNING, "Failure trying to update point in response to control. " << ex.GetErrorString());
			cs = CS_FORMAT_ERROR;
		}
	}
	else {
		cs = GetResponseCode(true, aIndex);
	}
	LOG_BLOCK(LEV_INFO, "[" << aIndex << "] - " <<  aControl.ToString() << " returning " << ToString(cs));
	return cs;
}