Example #1
0
bool
SftpClient::PutFile(const string& local, const string& remote, ftp_mode mode)
{
	bool rc = false;
	int len;
	//XXX: handle mode ?
	BString cmd("put");
	cmd << " " << local.c_str() << " " << remote.c_str() << "\n";
	SendCommand(cmd.String());
	BString reply;

	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("Uploading") < 0)
		return false;

	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("sftp>") < 0)
		return false;

	rc = true;
	return rc;
}
Example #2
0
bool
SftpClient::Chmod(const string& path, const string& mod)
{
	bool rc = false;
	int len;
	//XXX: handle mode ?
	BString cmd("chmod");
	cmd << " " << mod.c_str() << " " << path.c_str() << "\n";
	SendCommand(cmd.String());
	BString reply;

	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("Changing") < 0)
		return false;

	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("sftp>") < 0)
		return false;

	rc = true;
	return rc;
}
Example #3
0
bool
SftpClient::Connect(const string& server, const string& login, 
	const string& passwd)
{
	bool rc = false;
	BString cmd("sftp ");
	BString host(server.c_str());
	BString port;
	if (host.FindFirst(':'))
		host.MoveInto(port, host.FindFirst(':'), host.Length());
	port.RemoveAll(":");
	if (port.Length())
		cmd << "-oPort=" << port << " ";
	cmd << login.c_str();
	cmd << "@" << host.String();
	printf("COMMAND: '%s'\n", cmd.String());
	SetCommandLine(cmd.String());
	rc = SpawningUploadClient::Connect(server, login, passwd);
	BString reply;
	ssize_t len;
	
	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetLongReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("Connecting to ") != 0)
		return false;
	
	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetLongReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst(/*[pP]*/"assword:") < 0)
		return false;
	
	write(OutputPipe(), passwd.c_str(), strlen(passwd.c_str()));
	write(OutputPipe(), "\n", 1);
	
	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetLongReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply != "\n")
		return false;
	
	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetLongReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("sftp>") < 0)
		return false;
	return rc;
}
Example #4
0
SMTP_REPLY_CODE LSmtp::AUTH_PLAIN(const std::string& authid, const std::string& userid, const std::string& passwd)
{
	char cmdAUTH_PLAIN[sizeof("AUTH PLAIN ")-1+((255+1+255+1+255+1)*4/3+4)+sizeof("\r\n")-1]="AUTH PLAIN ";//должно хватить на все
	size_t start_offset=sizeof("AUTH PLAIN ")-1;
	size_t offset = start_offset;
	if(!authid.empty()){
		memcpy(cmdAUTH_PLAIN+offset, &authid[0], authid.length());
		offset+=authid.length();
	}
	cmdAUTH_PLAIN[offset]='\0';
	++offset;
	if(!userid.empty()){
		memcpy(cmdAUTH_PLAIN+offset, &userid[0], userid.length());
		offset+=userid.length();
	}
	cmdAUTH_PLAIN[offset]='\0';
	++offset;
	if(!passwd.empty()){
		memcpy(cmdAUTH_PLAIN+offset, &passwd[0], passwd.length());
		offset+=passwd.length();
	}
	cmdAUTH_PLAIN[offset]='\0';
	++offset;
	offset=start_offset+Base64InplaceEnc(cmdAUTH_PLAIN+start_offset, offset-start_offset);
	cmdAUTH_PLAIN[offset]='\r';
	++offset;
	cmdAUTH_PLAIN[offset]='\n';
	++offset;

	m_BS->RawSend(cmdAUTH_PLAIN, offset);

	return ReadReply();
}
Example #5
0
int
Logout(
	   SOCKET	connsock
	   )
{
	_int8								PduBuffer[MAX_REQUEST_SIZE];
	PLANSCSI_LOGOUT_REQUEST_PDU_HEADER	pRequestHeader;
	PLANSCSI_LOGOUT_REPLY_PDU_HEADER	pReplyHeader;
	LANSCSI_PDU							pdu;
	int									iResult;
	
	memset(PduBuffer, 0, MAX_REQUEST_SIZE);
	
	pRequestHeader = (PLANSCSI_LOGOUT_REQUEST_PDU_HEADER)PduBuffer;
	pRequestHeader->Opcode = LOGOUT_REQUEST;
	pRequestHeader->F = 1;
	pRequestHeader->HPID = htonl(HPID);
	pRequestHeader->RPID = htons(RPID);
	pRequestHeader->CPSlot = 0;
	pRequestHeader->DataSegLen = 0;
	pRequestHeader->AHSLen = 0;
	pRequestHeader->CSubPacketSeq = 0;
	pRequestHeader->PathCommandTag = htonl(++iTag);
	
	// Send Request.
	pdu.pH2RHeader = (PLANSCSI_H2R_PDU_HEADER)pRequestHeader;

	if(SendRequest(connsock, &pdu) != 0) {

		PrintError(WSAGetLastError(), "[LanScsiCli]Logout: Send Request ");
		return -1;
	}
	
	// Read Request.
	iResult = ReadReply(connsock, (PCHAR)PduBuffer, &pdu);
	if(iResult == SOCKET_ERROR) {
		fprintf(stderr, "[LanScsiCli]Logout: Can't Read Reply.\n");
		return -1;
	}
	
	// Check Request Header.
	pReplyHeader = (PLANSCSI_LOGOUT_REPLY_PDU_HEADER)pdu.pR2HHeader;

	if((pReplyHeader->Opcode != LOGOUT_RESPONSE)
		|| (pReplyHeader->F == 0)) {
		
		fprintf(stderr, "[LanScsiCli]Logout: BAD Reply Header.\n");
		return -1;
	}
	
	if(pReplyHeader->Response != LANSCSI_RESPONSE_SUCCESS) {
		fprintf(stderr, "[LanScsiCli]Logout: Failed.\n");
		return -1;
	}
	
	iSessionPhase = FLAG_SECURITY_PHASE;

	return 0;
}
Example #6
0
SMTP_REPLY_CODE LSmtp::QUIT()
{
	const char cmdQUIT[]="QUIT\r\n";

	m_BS->RawSend(cmdQUIT, sizeof(cmdQUIT)-1);//учитываем завершающий '\0';

	return ReadReply();
}
Example #7
0
// Note: this only works for local remote moves, cross filesystem moves
// will not work
bool
SftpClient::MoveFile(const string& oldPath, const string& newPath)
{
	bool rc = false;
	int len;
	
	// sftpd can't rename to an existing file...
	BString cmd("rm");
	cmd << " " << newPath.c_str() << "\n";
	fprintf(stderr, "CMD: '%s'\n", cmd.String());
	SendCommand(cmd.String());
	BString reply;

	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	// we don't care if it worked or not.
	//if (reply.FindFirst("Removing") != 0 && reply.FindFirst("Couldn't") )
	//	return false;

	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("sftp>") < 0)
		return false;

	cmd = "rename";
	cmd << " " << oldPath.c_str() << " " << newPath.c_str() << "\n";
	SendCommand(cmd.String());
	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("sftp>") < 0)
		return false;
	rc = true;
	return rc;
}
Example #8
0
SMTP_REPLY_CODE LSmtp::NOOP()
{
	//NOOP <CRLF>

	const char cmdNOOP[]="NOOP\r\n";

	m_BS->RawSend(cmdNOOP, sizeof(cmdNOOP)-1);//учитываем завершающий '\0';

	return ReadReply();
}
Example #9
0
SMTP_REPLY_CODE LSmtp::RSET()
{
	//RSET <CRLF>

	const char cmdRSET[]="RSET\r\n";

	m_BS->RawSend(cmdRSET, sizeof(cmdRSET)-1);//учитываем завершающий '\0';

	return ReadReply();
}
Example #10
0
SMTP_REPLY_CODE LSmtp::EHLO(const std::string& domain, std::vector<std::string>* Extensions)
{
	//ASSERT(domain.size()<=64);
	char cmdEHLO[sizeof("EHLO ")-1+64+sizeof("\r\n")-1 + 1];//должно хватить
	size_t size = sprintf(cmdEHLO, "EHLO %.64s\r\n", domain.c_str());
	//ASSERT(size<sizeof(cmdEHLO));

	m_BS->RawSend(cmdEHLO, size);

	return ReadReply(Extensions);
}
Example #11
0
SMTP_REPLY_CODE LSmtp::HELO(const std::string& domain)//RFC0821: The maximum total length of a domain name or number is 64 characters
{
	//ASSERT(domain.size()<=64);
	char cmdHELO[sizeof("HELO ")-1+64+sizeof("\r\n")-1 + 1];//должно хватить
	size_t size = sprintf(cmdHELO, "HELO %.64s\r\n", domain.c_str());
	//ASSERT(size<sizeof(cmdHELO));

	m_BS->RawSend(cmdHELO, size);

	return ReadReply();
}
Example #12
0
//RFC0821: The maximum total length of a reverse-path or forward-path is 256 characters (including the punctuation and element separators)
SMTP_REPLY_CODE LSmtp::MAIL(const std::string& reverse_path)
{
	//ASSERT(reverse_path.size()<=256);

	//MAIL <SP> FROM:<reverse-path> <CRLF>

	char cmdMAIL[sizeof("MAIL FROM:<")-1+256+sizeof(">\r\n")-1 + 1];//должно хватить
	size_t size = sprintf(cmdMAIL, "MAIL FROM:<%.256s>\r\n", reverse_path.c_str());
	//ASSERT(size<sizeof(cmdMAIL));

	m_BS->RawSend(cmdMAIL, size);

	return ReadReply();
}
Example #13
0
//RFC0821: The maximum total length of a reverse-path or forward-path is 256 characters (including the punctuation and element separators)
SMTP_REPLY_CODE LSmtp::RCPT(const std::string& forward_path)
{
	//ASSERT(forward_path.size()<=256);

	//RCPT <SP> TO:<forward-path> <CRLF>

	char cmdRCPT[sizeof("RCPT TO:<")-1+256+sizeof(">\r\n")-1 + 1];//должно хватить
	size_t size = sprintf(cmdRCPT, "RCPT TO:<%.256s>\r\n", forward_path.c_str());
	//ASSERT(size<sizeof(cmdRCPT));

	m_BS->RawSend(cmdRCPT, size);

	return ReadReply();
}
Example #14
0
SMTP_REPLY_CODE LSmtp::STARTTLS(LSSLByteStream* SSLBS)
{
	//STARTTLS<CRLF>

	const char cmdSTARTTLS[]="STARTTLS\r\n";

	m_BS->RawSend(cmdSTARTTLS, sizeof(cmdSTARTTLS)-1);//учитываем завершающий '\0';

	SMTP_REPLY_CODE R = ReadReply();
	if(R){//подменяем стрим только в случае успешного выполнения команды
		m_BS = SSLBS;
	}
	return R;
}
Example #15
0
SMTP_REPLY_CODE LSmtp::DATA(const char* msg, size_t sz)
{
	//int sz = msg.size();
	if(sz<5||!('\r'==msg[sz-5]&&'\n'==msg[sz-4]&&'.'==msg[sz-3]&&'\r'==msg[sz-2]&&'\n'==msg[sz-1])){
		//ASSERT(false);//неправильно оформленное письмо. должно оканчиваться "\r\n.\r\n"
		return "501";
	}

	const char cmdDATA[]="DATA\r\n";

	m_BS->RawSend(cmdDATA, sizeof(cmdDATA)-1);//учитываем завершающий '\0';

	SMTP_REPLY_CODE RC = ReadReply();
	if(RC=="354"){//If accepted, the receiver-SMTP returns a 354 Intermediate reply and considers all succeeding lines to be the message text.
		m_BS->RawSend(msg, sz);
		/*int sz = msg.size();
		const char cmdDOTCRLF[]="\r\n.\r\n";
		m_BS->RawSend(cmdDOTCRLF, sizeof(cmdDOTCRLF)-1);//учитываем завершающий '\0';
		*/
		return ReadReply();
	}
	return RC;
}
Example #16
0
bool
SftpClient::ChangeDir(const string& dir)
{
	bool rc = false;
	int len;
	BString cmd("cd");
	BString reply;
	cmd << " " << dir.c_str() << "\n";
	SendCommand(cmd.String());
	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("sftp>") < 0)
		return false;
	rc = true;
	return rc;
}
Example #17
0
bool
SftpClient::ListDirContents(string& listing)
{
	bool rc = false;
	int len;
	SendCommand("ls\n");
	BString reply;
	do {
		if ((len = ReadReply(&reply)) < 0) {
			fprintf(stderr, _GetReadText(), len);
			return false;
		}
		fprintf(stderr, _GetReplyText(), reply.String());
		printf("%s", reply.String());
		if (reply.FindFirst("sftp>") == 0)
			return true;
	} while (true);
	return rc;
}
Example #18
0
int
TextTargetList(
			   SOCKET	connsock
			   )
{
	_int8								PduBuffer[MAX_REQUEST_SIZE];
	PLANSCSI_TEXT_REQUEST_PDU_HEADER	pRequestHeader;
	PLANSCSI_TEXT_REPLY_PDU_HEADER		pReplyHeader;
	PBIN_PARAM_TARGET_LIST				pParam;
	LANSCSI_PDU							pdu;
	int									iResult;
	
	memset(PduBuffer, 0, MAX_REQUEST_SIZE);
	
	pRequestHeader = (PLANSCSI_TEXT_REQUEST_PDU_HEADER)PduBuffer;
	pRequestHeader->Opcode = TEXT_REQUEST;
	pRequestHeader->F = 1;
	pRequestHeader->HPID = htonl(HPID);
	pRequestHeader->RPID = htons(RPID);
	pRequestHeader->CPSlot = 0;
	pRequestHeader->DataSegLen = htonl(BIN_PARAM_SIZE_TEXT_TARGET_LIST_REQUEST);
	pRequestHeader->AHSLen = 0;
	pRequestHeader->CSubPacketSeq = 0;
	pRequestHeader->PathCommandTag = htonl(++iTag);
	pRequestHeader->ParameterType = PARAMETER_TYPE_BINARY;
	pRequestHeader->ParameterVer = PARAMETER_CURRENT_VERSION;
	
	// Make Parameter.
	pParam = (PBIN_PARAM_TARGET_LIST)&PduBuffer[sizeof(LANSCSI_H2R_PDU_HEADER)];
	pParam->ParamType = BIN_PARAM_TYPE_TARGET_LIST;
	
	// Send Request.
	pdu.pH2RHeader = (PLANSCSI_H2R_PDU_HEADER)pRequestHeader;
	pdu.pDataSeg = (char *)pParam;

	if(SendRequest(connsock, &pdu) != 0) {
		PrintError(WSAGetLastError(), "TextTargetList: Send First Request ");
		return -1;
	}
	
	// Read Request.
	iResult = ReadReply(connsock, (PCHAR)PduBuffer, &pdu);
	if(iResult == SOCKET_ERROR) {
		fprintf(stderr, "[LanScsiCli]TextTargetList: Can't Read Reply.\n");
		return -1;
	}
	
	pReplyHeader = (PLANSCSI_TEXT_REPLY_PDU_HEADER)pdu.pR2HHeader;

	// Check Request Header.
	if((pReplyHeader->Opcode != TEXT_RESPONSE)
		|| (pReplyHeader->F == 0)
		|| (pReplyHeader->ParameterType != PARAMETER_TYPE_BINARY)
		|| (pReplyHeader->ParameterVer != PARAMETER_CURRENT_VERSION)) {
		
		fprintf(stderr, "[LanScsiCli]TextTargetList: BAD Reply Header.\n");
		return -1;
	}
	
	if(pReplyHeader->Response != LANSCSI_RESPONSE_SUCCESS) {
		fprintf(stderr, "[LanScsiCli]TextTargetList: Failed.\n");
		return -1;
	}
	
	if(ntohl(pReplyHeader->DataSegLen) < BIN_PARAM_SIZE_REPLY) {
		fprintf(stderr, "[LanScsiCli]TextTargetList: No Data Segment.\n");
		return -1;		
	}

	pParam = (PBIN_PARAM_TARGET_LIST)pdu.pDataSeg;
	if(pParam->ParamType != BIN_PARAM_TYPE_TARGET_LIST) {
		fprintf(stderr, "TEXT: Bad Parameter Type.\n");
		return -1;			
	}
	TRACE("[LanScsiCli]TextTargetList: NR Targets : %d\n", pParam->NRTarget);
	NRTarget = pParam->NRTarget;
	
	for(int i = 0; i < pParam->NRTarget; i++) {
		PBIN_PARAM_TARGET_LIST_ELEMENT	pTarget;
		int								iTargetId;
		
		pTarget = &pParam->PerTarget[i];
		iTargetId = ntohl(pTarget->TargetID);
		
		TRACE("[LanScsiCli]TextTargetList: Target ID: %d, NR_RW: %d, NR_RO: %d, Data: %I64d \n",  
			ntohl(pTarget->TargetID), 
			pTarget->NRRWHost,
			pTarget->NRROHost,
			pTarget->TargetData
			);
		
		PerTarget[iTargetId].bPresent = TRUE;
		PerTarget[iTargetId].NRRWHost = pTarget->NRRWHost;
		PerTarget[iTargetId].NRROHost = pTarget->NRROHost;
		PerTarget[iTargetId].TargetData = pTarget->TargetData;
	}
	
	return 0;
}
Example #19
0
void ScreamerNode::Update(void)
{
	switch(m_state){
		case WAIT:{
			if(m_waitreply == false){
				m_waitreply = true;

				m_jobfile.clear();
				m_jobfile.open(m_job.c_str(),std::ios::out);

				m_jobfile << "wait";

				m_jobfile.close();

				SetAvailable(true);
			}else{
				if(ReadReply(WAIT) == true){
					m_waitreply = false;
				}
			}
		}break;

		case INIT:{
			if(m_waitreply == false){
				m_waitreply = true;

				m_jobfile.clear();
				m_jobfile.open(m_job.c_str(),std::ios::out);

				m_jobfile << "init";

				m_jobfile.close();

				SetAvailable(false);
			}else{
				if(ReadReply(INIT) == true){
					m_waitreply = false;
					m_state			= CONTENT;
				}
			}
		}break;

		case CONTENT:{
			if(m_waitreply == false){
				m_waitreply = true;

				m_jobfile.clear();
				m_jobfile.open(m_job.c_str(),std::ios::out);


				m_jobfile << "content " << m_contentdir << std::endl;

				m_jobfile.close();
			}else{
				if(ReadReply(CONTENT) == true){
					m_waitreply = false;
					m_state			= LOAD;
				}
			}
		}break;

		case LOAD:{
			if(m_waitreply == false){
				m_waitreply = true;

				m_jobfile.clear();
				m_jobfile.open(m_job.c_str(),std::ios::out);

				m_jobfile << "load" << std::endl << m_scenefile;

				m_jobfile.close();
			}else{
				if(ReadReply(LOAD) == true){
					m_waitreply	=	false;

					m_state			=	RENDERWAIT;
				}
			}
		}break;

		case RENDERWAIT:{
			if(m_waitreply == false){
				m_waitreply = true;

				m_jobfile.clear();
				m_jobfile.open(m_job.c_str(),std::ios::out);

				m_jobfile << "wait";

				m_jobfile.close();
			}else{
				if(ReadReply(WAIT) == true){
					switch(m_renderstate){
						case REQ_BATCH:{
							m_scene->RequestBatch(m_start,m_end,m_step);

							m_state				=	RENDER;
							m_renderstate = RENDERING;
	
							SetFrames();

							m_waitreply = false;

							if(m_start == SCENE_COMPLETE){
								SetAvailable(true);

								ClearScene();
								ClearFrames();

								m_state	= WAIT;
							}
						}break;

						case RENDERING:{
							m_scene->FrameComplete();
							scene_view->Update(m_scene->GetID());

							if(m_start >= m_end){
								m_renderstate = REQ_BATCH;
							}else{
								m_waitreply	= false;

								m_state	=	RENDER;

								m_start++;
							}
						}
					};
				}
			}
		}break;

		case RENDERPAUSE:{
			if(m_waitreply == false){
				m_waitreply = true;
			}else{
				m_waitreply = false;
			}
		}break;

		case RENDER:{
			if(m_waitreply == false){
				m_waitreply = true;

				m_jobfile.clear();
				m_jobfile.open(m_job.c_str(),std::ios::out);

				m_jobfile << "render " << m_start << " " << m_start << " " << m_step;

				m_jobfile.close();
			}else{

				if(ReadReply(RENDER) == true){
					m_waitreply	= false;
					m_state			= RENDERWAIT;
				}
			}
		}break;


	};

	screamer_view->Update(m_number);
}
Example #20
0
int
VenderCommand(
			  SOCKET			connsock,
			  UCHAR				cOperation,
			  unsigned _int64	*pParameter
			  )
{
	_int8								PduBuffer[MAX_REQUEST_SIZE];
	PLANSCSI_VENDER_REQUEST_PDU_HEADER	pRequestHeader;
	PLANSCSI_VENDER_REPLY_PDU_HEADER	pReplyHeader;
	LANSCSI_PDU							pdu;
	int									iResult;
	
	memset(PduBuffer, 0, MAX_REQUEST_SIZE);
	
	pRequestHeader = (PLANSCSI_VENDER_REQUEST_PDU_HEADER)PduBuffer;
	pRequestHeader->Opcode = VENDER_SPECIFIC_COMMAND;
	pRequestHeader->F = 1;
	pRequestHeader->HPID = htonl(HPID);
	pRequestHeader->RPID = htons(RPID);
	pRequestHeader->CPSlot = 0;
	pRequestHeader->DataSegLen = 0;
	pRequestHeader->AHSLen = 0;
	pRequestHeader->CSubPacketSeq = 0;
	pRequestHeader->PathCommandTag = htonl(++iTag);
	pRequestHeader->VenderID = ntohs(NKC_VENDER_ID);
	pRequestHeader->VenderOpVersion = VENDER_OP_CURRENT_VERSION;
	pRequestHeader->VenderOp = cOperation;
	pRequestHeader->VenderParameter = *pParameter;
	
	TRACE("VenderCommand: Operation %d, Parameter %I64d\n", cOperation, NTOHLL(*pParameter));

	// Send Request.
	pdu.pH2RHeader = (PLANSCSI_H2R_PDU_HEADER)pRequestHeader;

	if(SendRequest(connsock, &pdu) != 0) {
		PrintError(WSAGetLastError(), "VenderCommand: Send First Request ");
		return -1;
	}
	
	// Read Request.
	iResult = ReadReply(connsock, (PCHAR)PduBuffer, &pdu);
	if(iResult == SOCKET_ERROR) {
		fprintf(stderr, "[LanScsiCli]VenderCommand: Can't Read Reply.\n");
		return -1;
	}
	
	// Check Request Header.
	pReplyHeader = (PLANSCSI_VENDER_REPLY_PDU_HEADER)pdu.pR2HHeader;


	if((pReplyHeader->Opcode != VENDER_SPECIFIC_RESPONSE)
		|| (pReplyHeader->F == 0)) {
		
		fprintf(stderr, "[LanScsiCli]VenderCommand: BAD Reply Header. %d 0x%x\n", pReplyHeader->Opcode, pReplyHeader->F);
		return -1;
	}
	
	if(pReplyHeader->Response != LANSCSI_RESPONSE_SUCCESS) {
		fprintf(stderr, "[LanScsiCli]VenderCommand: Failed.\n");
		return -1;
	}
	
	*pParameter = pReplyHeader->VenderParameter;

	return 0;
}
Example #21
0
int
TextTargetData(
			   SOCKET	connsock,
			   UCHAR	cGetorSet,
			   UINT		TargetID
			   )
{
	_int8								PduBuffer[MAX_REQUEST_SIZE];
	PLANSCSI_TEXT_REQUEST_PDU_HEADER	pRequestHeader;
	PLANSCSI_TEXT_REPLY_PDU_HEADER		pReplyHeader;
	PBIN_PARAM_TARGET_DATA				pParam;
	LANSCSI_PDU							pdu;
	int									iResult;
	
	memset(PduBuffer, 0, MAX_REQUEST_SIZE);
	
	pRequestHeader = (PLANSCSI_TEXT_REQUEST_PDU_HEADER)PduBuffer;
	pRequestHeader->Opcode = TEXT_REQUEST;
	pRequestHeader->F = 1;
	pRequestHeader->HPID = htonl(HPID);
	pRequestHeader->RPID = htons(RPID);
	pRequestHeader->CPSlot = 0;
	pRequestHeader->DataSegLen = htonl(BIN_PARAM_SIZE_TEXT_TARGET_DATA_REQUEST);
	pRequestHeader->AHSLen = 0;
	pRequestHeader->CSubPacketSeq = 0;
	pRequestHeader->PathCommandTag = htonl(++iTag);
	pRequestHeader->ParameterType = PARAMETER_TYPE_BINARY;
	pRequestHeader->ParameterVer = PARAMETER_CURRENT_VERSION;
	
	// Make Parameter.
	pParam = (PBIN_PARAM_TARGET_DATA)&PduBuffer[sizeof(LANSCSI_H2R_PDU_HEADER)];
	pParam->ParamType = BIN_PARAM_TYPE_TARGET_DATA;
	pParam->GetOrSet = cGetorSet;
	pParam->TargetData = PerTarget[TargetID].TargetData;
	pParam->TargetID = htonl(TargetID);
	
	TRACE("TargetID %d, %I64d\n", ntohl(pParam->TargetID), pParam->TargetData);

	// Send Request.
	pdu.pH2RHeader = (PLANSCSI_H2R_PDU_HEADER)pRequestHeader;
	pdu.pDataSeg = (char *)pParam;

	if(SendRequest(connsock, &pdu) != 0) {
		PrintError(WSAGetLastError(), "TextTargetData: Send First Request ");
		return -1;
	}
	
	// Read Request.
	iResult = ReadReply(connsock, (PCHAR)PduBuffer, &pdu);
	if(iResult == SOCKET_ERROR) {
		fprintf(stderr, "[LanScsiCli]TextTargetData: Can't Read Reply.\n");
		return -1;
	}
	
	// Check Request Header.
	pReplyHeader = (PLANSCSI_TEXT_REPLY_PDU_HEADER)pdu.pR2HHeader;


	if((pReplyHeader->Opcode != TEXT_RESPONSE)
		|| (pReplyHeader->F == 0)
		|| (pReplyHeader->ParameterType != PARAMETER_TYPE_BINARY)
		|| (pReplyHeader->ParameterVer != PARAMETER_CURRENT_VERSION)) {
		
		fprintf(stderr, "[LanScsiCli]TextTargetData: BAD Reply Header.\n");
		return -1;
	}
	
	if(pReplyHeader->Response != LANSCSI_RESPONSE_SUCCESS) {
		fprintf(stderr, "[LanScsiCli]TextTargetData: Failed.\n");
		return -1;
	}
	
	if(pReplyHeader->DataSegLen < BIN_PARAM_SIZE_REPLY) {
		fprintf(stderr, "[LanScsiCli]TextTargetData: No Data Segment.\n");
		return -1;		
	}
	pParam = (PBIN_PARAM_TARGET_DATA)pdu.pDataSeg;

	if(pParam->ParamType != BIN_PARAM_TYPE_TARGET_DATA) {
		fprintf(stderr, "TextTargetData: Bad Parameter Type. %d\n", pParam->ParamType);
	//	return -1;			
	}

	PerTarget[TargetID].TargetData = pParam->TargetData;

	TRACE("[LanScsiCli]TextTargetList: TargetID : %d, GetorSet %d, Target Data %d\n", 
		ntohl(pParam->TargetID), pParam->GetOrSet, PerTarget[TargetID].TargetData);
	
	return 0;
}
Example #22
0
int
Login(
	  SOCKET			connsock,
	  UCHAR				cLoginType,
	  _int32			iUserID,
	  unsigned _int64	iKey
	  )
{
	_int8								PduBuffer[MAX_REQUEST_SIZE];
	PLANSCSI_LOGIN_REQUEST_PDU_HEADER	pLoginRequestPdu;
	PLANSCSI_LOGIN_REPLY_PDU_HEADER		pLoginReplyHeader;
	PBIN_PARAM_SECURITY					pParamSecu;
	PBIN_PARAM_NEGOTIATION				pParamNego;
	PAUTH_PARAMETER_CHAP				pParamChap;
	LANSCSI_PDU							pdu;
	int									iSubSequence;
	int									iResult;
	unsigned							CHAP_I;
	
	//
	// Init.
	//
	iSubSequence = 0;
	iSessionPhase = FLAG_SECURITY_PHASE;

	// 
	// First Packet.
	//
	memset(PduBuffer, 0, MAX_REQUEST_SIZE);
	
	pLoginRequestPdu = (PLANSCSI_LOGIN_REQUEST_PDU_HEADER)PduBuffer;
	
	pLoginRequestPdu->Opcode = LOGIN_REQUEST;
	pLoginRequestPdu->HPID = htonl(HPID);
	pLoginRequestPdu->DataSegLen = htonl(BIN_PARAM_SIZE_LOGIN_FIRST_REQUEST);
	pLoginRequestPdu->CSubPacketSeq = htons(iSubSequence);
	pLoginRequestPdu->PathCommandTag = htonl(iTag);
	pLoginRequestPdu->ParameterType = 1;
	pLoginRequestPdu->ParameterVer = 0;
	pLoginRequestPdu->VerMax = 0;
	pLoginRequestPdu->VerMin = 0;
	
	pParamSecu = (PBIN_PARAM_SECURITY)&PduBuffer[sizeof(LANSCSI_LOGIN_REQUEST_PDU_HEADER)];
	
	pParamSecu->ParamType = BIN_PARAM_TYPE_SECURITY;
	pParamSecu->LoginType = cLoginType;
	pParamSecu->AuthMethod = htons(AUTH_METHOD_CHAP);
	
	// Send Request.
	pdu.pH2RHeader = (PLANSCSI_H2R_PDU_HEADER)pLoginRequestPdu;
	pdu.pDataSeg = (char *)pParamSecu;

	if(SendRequest(connsock, &pdu) != 0) {
		PrintError(WSAGetLastError(), "Login: Send First Request ");
		return -1;
	}

	// Read Request.
	iResult = ReadReply(connsock, (PCHAR)PduBuffer, &pdu);
	if(iResult == SOCKET_ERROR) {
		fprintf(stderr, "[LanScsiCli]login: First Can't Read Reply.\n");
		return -1;
	}
	
	// Check Request Header.
	pLoginReplyHeader = (PLANSCSI_LOGIN_REPLY_PDU_HEADER)pdu.pR2HHeader;
	if((pLoginReplyHeader->Opcode != LOGIN_RESPONSE)
		|| (pLoginReplyHeader->T != 0)
		|| (pLoginReplyHeader->CSG != FLAG_SECURITY_PHASE)
		|| (pLoginReplyHeader->NSG != FLAG_SECURITY_PHASE)
		|| (pLoginReplyHeader->VerActive > LANSCSI_CURRENT_VERSION)
		|| (pLoginReplyHeader->ParameterType != PARAMETER_TYPE_BINARY)
		|| (pLoginReplyHeader->ParameterVer != PARAMETER_CURRENT_VERSION)) {
		
		fprintf(stderr, "[LanScsiCli]login: BAD First Reply Header.\n");
		return -1;
	}
	
	if(pLoginReplyHeader->Response != LANSCSI_RESPONSE_SUCCESS) {
		fprintf(stderr, "[LanScsiCli]login: First Failed.\n");
		return -1;
	}
	
	// Store Data.
	RPID = ntohs(pLoginReplyHeader->RPID);
	
	pParamSecu = (PBIN_PARAM_SECURITY)pdu.pDataSeg;
	TRACE("[LanScsiCli]login: Version %d Auth %d\n", 
		pLoginReplyHeader->VerActive, 
		ntohs(pParamSecu->AuthMethod)
		);
	
	// 
	// Second Packet.
	//
	memset(PduBuffer, 0, MAX_REQUEST_SIZE);
	
	pLoginRequestPdu = (PLANSCSI_LOGIN_REQUEST_PDU_HEADER)PduBuffer;
	
	pLoginRequestPdu->Opcode = LOGIN_REQUEST;
	pLoginRequestPdu->HPID = htonl(HPID);
	pLoginRequestPdu->RPID = htons(RPID);
	pLoginRequestPdu->DataSegLen = htonl(BIN_PARAM_SIZE_LOGIN_SECOND_REQUEST);
	pLoginRequestPdu->CSubPacketSeq = htons(++iSubSequence);
	pLoginRequestPdu->PathCommandTag = htonl(iTag);
	pLoginRequestPdu->ParameterType = 1;
	pLoginRequestPdu->ParameterVer = 0;
	
	pParamSecu = (PBIN_PARAM_SECURITY)&PduBuffer[sizeof(LANSCSI_LOGIN_REQUEST_PDU_HEADER)];
	
	pParamSecu->ParamType = BIN_PARAM_TYPE_SECURITY;
	pParamSecu->LoginType = cLoginType;
	pParamSecu->AuthMethod = htons(AUTH_METHOD_CHAP);
	
	pParamChap = (PAUTH_PARAMETER_CHAP)pParamSecu->AuthParamter;
	pParamChap->CHAP_A = ntohl(HASH_ALGORITHM_MD5);
	
	// Send Request.
	pdu.pH2RHeader = (PLANSCSI_H2R_PDU_HEADER)pLoginRequestPdu;
	pdu.pDataSeg = (char *)pParamSecu;

	if(SendRequest(connsock, &pdu) != 0) {
		PrintError(WSAGetLastError(), "[LanScsiCli]Login: Send Second Request ");
		return -1;
	}

	// Read Request.
	iResult = ReadReply(connsock, (PCHAR)PduBuffer, &pdu);
	if(iResult == SOCKET_ERROR) {
		fprintf(stderr, "[LanScsiCli]login: Second Can't Read Reply.\n");
		return -1;
	}
	
	// Check Request Header.
	pLoginReplyHeader = (PLANSCSI_LOGIN_REPLY_PDU_HEADER)pdu.pR2HHeader;
	if((pLoginReplyHeader->Opcode != LOGIN_RESPONSE)
		|| (pLoginReplyHeader->T != 0)
		|| (pLoginReplyHeader->CSG != FLAG_SECURITY_PHASE)
		|| (pLoginReplyHeader->NSG != FLAG_SECURITY_PHASE)
		|| (pLoginReplyHeader->VerActive > LANSCSI_CURRENT_VERSION)
		|| (pLoginReplyHeader->ParameterType != PARAMETER_TYPE_BINARY)
		|| (pLoginReplyHeader->ParameterVer != PARAMETER_CURRENT_VERSION)) {
		
		fprintf(stderr, "[LanScsiCli]login: BAD Second Reply Header.\n");
		return -1;
	}
	
	if(pLoginReplyHeader->Response != LANSCSI_RESPONSE_SUCCESS) {
		fprintf(stderr, "[LanScsiCli]login: Second Failed.\n");
		return -1;
	}
	
	// Check Data segment.
	if((ntohl(pLoginReplyHeader->DataSegLen) < BIN_PARAM_SIZE_REPLY)	// Minus AuthParamter[1]
		|| (pdu.pDataSeg == NULL)) {
		
		fprintf(stderr, "[LanScsiCli]login: BAD Second Reply Data.\n");
		return -1;
	}	
	pParamSecu = (PBIN_PARAM_SECURITY)pdu.pDataSeg;
	if(pParamSecu->ParamType != BIN_PARAM_TYPE_SECURITY
		|| pParamSecu->LoginType != cLoginType
		|| pParamSecu->AuthMethod != htons(AUTH_METHOD_CHAP)) {
		
		fprintf(stderr, "[LanScsiCli]login: BAD Second Reply Parameters.\n");
		return -1;
	}
	
	// Store Challenge.	
	pParamChap = &pParamSecu->ChapParam;
	CHAP_I = ntohl(pParamChap->CHAP_I);
	CHAP_C = ntohl(pParamChap->CHAP_C[0]);
	
	TRACE("[LanScsiCli]login: Hash %d, Challenge %d\n", 
		ntohl(pParamChap->CHAP_A), 
		CHAP_C
		);
	
	// 
	// Third Packet.
	//
	memset(PduBuffer, 0, MAX_REQUEST_SIZE);
	
	pLoginRequestPdu = (PLANSCSI_LOGIN_REQUEST_PDU_HEADER)PduBuffer;
	pLoginRequestPdu->Opcode = LOGIN_REQUEST;
	pLoginRequestPdu->T = 1;
	pLoginRequestPdu->CSG = FLAG_SECURITY_PHASE;
	pLoginRequestPdu->NSG = FLAG_LOGIN_OPERATION_PHASE;
	pLoginRequestPdu->HPID = htonl(HPID);
	pLoginRequestPdu->RPID = htons(RPID);
	pLoginRequestPdu->DataSegLen = htonl(BIN_PARAM_SIZE_LOGIN_THIRD_REQUEST);
	pLoginRequestPdu->CSubPacketSeq = htons(++iSubSequence);
	pLoginRequestPdu->PathCommandTag = htonl(iTag);
	pLoginRequestPdu->ParameterType = 1;
	pLoginRequestPdu->ParameterVer = 0;
	
	pParamSecu = (PBIN_PARAM_SECURITY)&PduBuffer[sizeof(LANSCSI_LOGIN_REQUEST_PDU_HEADER)];
	
	pParamSecu->ParamType = BIN_PARAM_TYPE_SECURITY;
	pParamSecu->LoginType = cLoginType;
	pParamSecu->AuthMethod = htons(AUTH_METHOD_CHAP);
	
	pParamChap = (PAUTH_PARAMETER_CHAP)pParamSecu->AuthParamter;
	pParamChap->CHAP_A = htonl(HASH_ALGORITHM_MD5);
	pParamChap->CHAP_I = htonl(CHAP_I);
	pParamChap->CHAP_N = htonl(iUserID);
	
	Hash32To128((unsigned char*)&CHAP_C, (unsigned char*)pParamChap->CHAP_R, (PUCHAR)&iKey);
	
	
	// Send Request.
	pdu.pH2RHeader = (PLANSCSI_H2R_PDU_HEADER)pLoginRequestPdu;
	pdu.pDataSeg = (char *)pParamSecu;

	if(SendRequest(connsock, &pdu) != 0) {
		PrintError(WSAGetLastError(), "Login: Send Third Request ");
		return -1;
	}
	
	// Read Request.
	iResult = ReadReply(connsock, (PCHAR)PduBuffer, &pdu);
	if(iResult == SOCKET_ERROR) {
		fprintf(stderr, "[LanScsiCli]login: Second Can't Read Reply.\n");
		return -1;
	}
	
	// Check Request Header.
	pLoginReplyHeader = (PLANSCSI_LOGIN_REPLY_PDU_HEADER)pdu.pR2HHeader;
	if((pLoginReplyHeader->Opcode != LOGIN_RESPONSE)
		|| (pLoginReplyHeader->T == 0)
		|| (pLoginReplyHeader->CSG != FLAG_SECURITY_PHASE)
		|| (pLoginReplyHeader->NSG != FLAG_LOGIN_OPERATION_PHASE)
		|| (pLoginReplyHeader->VerActive > LANSCSI_CURRENT_VERSION)
		|| (pLoginReplyHeader->ParameterType != PARAMETER_TYPE_BINARY)
		|| (pLoginReplyHeader->ParameterVer != PARAMETER_CURRENT_VERSION)) {
		
		fprintf(stderr, "[LanScsiCli]login: BAD Third Reply Header.\n");
		return -1;
	}
	
	if(pLoginReplyHeader->Response != LANSCSI_RESPONSE_SUCCESS) {
		fprintf(stderr, "[LanScsiCli]login: Third Failed.\n");
		return -1;
	}
	
	// Check Data segment.
	if((ntohl(pLoginReplyHeader->DataSegLen) < BIN_PARAM_SIZE_REPLY)	// Minus AuthParamter[1]
		|| (pdu.pDataSeg == NULL)) {
		
		fprintf(stderr, "[LanScsiCli]login: BAD Third Reply Data.\n");
		return -1;
	}	
	pParamSecu = (PBIN_PARAM_SECURITY)pdu.pDataSeg;
	if(pParamSecu->ParamType != BIN_PARAM_TYPE_SECURITY
		|| pParamSecu->LoginType != cLoginType
		|| pParamSecu->AuthMethod != htons(AUTH_METHOD_CHAP)) {
		
		fprintf(stderr, "[LanScsiCli]login: BAD Third Reply Parameters.\n");
		return -1;
	}
	
	iSessionPhase = FLAG_LOGIN_OPERATION_PHASE;

	// 
	// Fourth Packet.
	//
	memset(PduBuffer, 0, MAX_REQUEST_SIZE);
	
	pLoginRequestPdu = (PLANSCSI_LOGIN_REQUEST_PDU_HEADER)PduBuffer;
	pLoginRequestPdu->Opcode = LOGIN_REQUEST;
	pLoginRequestPdu->T = 1;
	pLoginRequestPdu->CSG = FLAG_LOGIN_OPERATION_PHASE;
	pLoginRequestPdu->NSG = FLAG_FULL_FEATURE_PHASE;
	pLoginRequestPdu->HPID = htonl(HPID);
	pLoginRequestPdu->RPID = htons(RPID);
	pLoginRequestPdu->DataSegLen = htonl(BIN_PARAM_SIZE_LOGIN_FOURTH_REQUEST);
	pLoginRequestPdu->CSubPacketSeq = htons(++iSubSequence);
	pLoginRequestPdu->PathCommandTag = htonl(iTag);
	pLoginRequestPdu->ParameterType = 1;
	pLoginRequestPdu->ParameterVer = 0;
	
	pParamNego = (PBIN_PARAM_NEGOTIATION)&PduBuffer[sizeof(LANSCSI_LOGIN_REQUEST_PDU_HEADER)];
	
	pParamNego->ParamType = BIN_PARAM_TYPE_NEGOTIATION;
	
	// Send Request.
	pdu.pH2RHeader = (PLANSCSI_H2R_PDU_HEADER)pLoginRequestPdu;
	pdu.pDataSeg = (char *)pParamNego;

	if(SendRequest(connsock, &pdu) != 0) {
		PrintError(WSAGetLastError(), "Login: Send Fourth Request ");
		return -1;
	}
	
	// Read Request.
	iResult = ReadReply(connsock, (PCHAR)PduBuffer, &pdu);
	if(iResult == SOCKET_ERROR) {
		fprintf(stderr, "[LanScsiCli]login: Fourth Can't Read Reply.\n");
		return -1;
	}
	
	// Check Request Header.
	pLoginReplyHeader = (PLANSCSI_LOGIN_REPLY_PDU_HEADER)pdu.pR2HHeader;
	if((pLoginReplyHeader->Opcode != LOGIN_RESPONSE)
		|| (pLoginReplyHeader->T == 0)
		|| ((pLoginReplyHeader->Flags & LOGIN_FLAG_CSG_MASK) != (FLAG_LOGIN_OPERATION_PHASE << 2))
		|| ((pLoginReplyHeader->Flags & LOGIN_FLAG_NSG_MASK) != FLAG_FULL_FEATURE_PHASE)
		|| (pLoginReplyHeader->VerActive > LANSCSI_CURRENT_VERSION)
		|| (pLoginReplyHeader->ParameterType != PARAMETER_TYPE_BINARY)
		|| (pLoginReplyHeader->ParameterVer != PARAMETER_CURRENT_VERSION)) {
		
		fprintf(stderr, "[LanScsiCli]login: BAD Fourth Reply Header.\n");
		return -1;
	}
	
	if(pLoginReplyHeader->Response != LANSCSI_RESPONSE_SUCCESS) {
		fprintf(stderr, "[LanScsiCli]login: Fourth Failed.\n");
		return -1;
	}
	
	// Check Data segment.
	if((ntohl(pLoginReplyHeader->DataSegLen) < BIN_PARAM_SIZE_REPLY)	// Minus AuthParamter[1]
		|| (pdu.pDataSeg == NULL)) {
		
		fprintf(stderr, "[LanScsiCli]login: BAD Fourth Reply Data.\n");
		return -1;
	}	
	pParamNego = (PBIN_PARAM_NEGOTIATION)pdu.pDataSeg;
	if(pParamNego->ParamType != BIN_PARAM_TYPE_NEGOTIATION) {
		fprintf(stderr, "[LanScsiCli]login: BAD Fourth Reply Parameters.\n");
		return -1;
	}
	
	TRACE("[LanScsiCli]login: Hw Type %d, Hw Version %d, NRSlots %d, W %d, MT %d ML %d\n", 
		pParamNego->HWType, pParamNego->HWVersion,
		ntohl(pParamNego->NRSlot), ntohl(pParamNego->MaxBlocks),
		ntohl(pParamNego->MaxTargetID), ntohl(pParamNego->MaxLUNID)
		);
	TRACE("[LanScsiCli]login: Head Encrypt Algo %d, Head Digest Algo %d, Data Encrypt Algo %d, Data Digest Algo %d\n",
		ntohs(pParamNego->HeaderEncryptAlgo),
		ntohs(pParamNego->HeaderDigestAlgo),
		ntohs(pParamNego->DataEncryptAlgo),
		ntohs(pParamNego->DataDigestAlgo)
		);

	requestBlocks = ntohl(pParamNego->MaxBlocks);
	HeaderEncryptAlgo = ntohs(pParamNego->HeaderEncryptAlgo);
	DataEncryptAlgo = ntohs(pParamNego->DataEncryptAlgo);

	iSessionPhase = FLAG_FULL_FEATURE_PHASE;

	return 0;
}
Example #23
0
SMTP_REPLY_CODE LSmtp::Greeting()
{
	return ReadReply();
}