Exemplo n.º 1
0
void FSPath::SetItem( int n, int cs, const void* v ) // n>=0 && n<=Count(); если n == Count то в конец добавляется еще один элемент
{
	if ( n < 0 || n > Count() ) { return; }

	cacheCs = -2;

	if ( n == Count() ) { data.append( FSString( cs, v ) ); }
	else { data[n] = FSString( cs, v ); }
}
Exemplo n.º 2
0
FSString FSWin32Net::Uri( FSPath& path )
{
	NETRESOURCEW* p = _res.Get();

	if ( p && p->lpRemoteName )
	{
		return FSString( Utf16ToUnicode( p->lpRemoteName ).data() );
	}

	return FSString( "Network" );
}
Exemplo n.º 3
0
bool ParzeLink( FSPath& path, FSString& link )
{
	FSPath t( link );

	if ( !path.IsAbsolute() && !t.IsAbsolute() ) { return false; } //не абсолютный путь

	int first = 0;

	if ( t.IsAbsolute() )
	{
		path.Clear();
		path.PushStr( FSString( "" ) );
		first = 1;
	}

	for ( int i = first; i < t.Count(); i++ )
	{
		FSString p = *( t.GetItem( i ) );

		if ( p.IsDot() ) { continue; }

		if ( p.Is2Dot() )
		{
			if ( path.Count() > 1 ) { path.Pop(); }
		}
		else
		{
			path.PushStr( p );
		}
	}

	return true;
}
Exemplo n.º 4
0
clPtr<FS> ParzeFtpURI( const unicode_t* uri, FSPath& path, clPtr<FS>* checkFS, int count )
{
	path.Set( rootPathStr );

	if ( !uri[0] ) { return clPtr<FS>(); }

	FSFtpParam param;

	const unicode_t* userDelimiter = FindFirstChar( uri, '@' );

	if ( *userDelimiter )
	{
		param.user = FSString( CS_UNICODE, uri, userDelimiter - uri ).GetUnicode();
		uri = userDelimiter + 1;
		param.anonymous = false;
	}
	else
	{
		param.anonymous = true;
	}


	const unicode_t* host_port_End = FindFirstChar( uri, '/' );
	const unicode_t* host_End = FindFirstChar( uri, ':' );

	FSString host( CS_UNICODE, uri, ( ( host_End < host_port_End ) ? host_End :  host_port_End )  - uri );

	int port  = 0;

	for ( const unicode_t* s = host_End + 1; s < host_port_End; s++ )
		if ( *s >= '0' && *s <= '9' ) { port = port * 10 + ( *s - '0' ); }
		else { break; }

	if ( port > 0 && port < 65536 ) { param.port = port; }

	param.server = host.GetUnicode();

	uri = host_port_End;

	FSString link = uri;

	if ( !ParzeLink( path, link ) ) { return clPtr<FS>(); }

	for ( int i = 0; i < count; i++ )
		if ( checkFS[i].Ptr() && checkFS[i]->Type() == FS::FTP )
		{
			FSFtp* p = ( FSFtp* )checkFS[i].Ptr();
			FSFtpParam checkParam;
			p->GetParam( &checkParam );

			if (  !CmpStr<const unicode_t>( param.server.Data(), checkParam.server.Data() ) &&
			      ( param.anonymous == checkParam.anonymous && ( param.anonymous || !CmpStr<const unicode_t>( param.user.Data(), checkParam.user.Data() ) ) ) &&
			      param.port == checkParam.port )
			{
				return checkFS[i];
			}
		}

	return new FSFtp( &param );
}
Exemplo n.º 5
0
    void FSTable::setValues(const char* anArray[], int size)
    {
        values.resize(size);

        for (int i=0; i<size; i++)
            values[i] = FSString(anArray[i]);
    }
Exemplo n.º 6
0
void KbIntCallback(
   const char* name, int name_len,
   const char* instruction, int instruction_len,
   int num_prompts,
   const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts,
   LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses,
   void** anstract )
{
	if ( num_prompts <= 0 ) { return; }

	if ( !kbdIntInfo ) { return; }

	try
	{

		std::vector<FSPromptData> pData( num_prompts );
		int i;

		for ( i = 0; i < num_prompts; i++ )
		{
			pData[i].visible = prompts[i].echo != 0;
			pData[i].prompt = utf8_to_unicode( CopyToStrZ( prompts[i].text, prompts[i].length ).data() ).data();
		}

		static unicode_t userSymbol = '@';

		if ( !kbdIntInfo->Prompt(
		        utf8_to_unicode( "SFTP" ).data(),
		        carray_cat<unicode_t>( kbdIntParam->user.Data(), &userSymbol, kbdIntParam->server.Data() ).data(),
		        pData.data(), num_prompts ) ) { return; }

		for ( i = 0; i < num_prompts; i++ )
		{
			std::vector<char> str = new_char_str( ( char* )FSString( pData[i].prompt.Data() ).Get( kbdIntParam->charset ) );

			if ( str.data() )
			{
				int l = strlen( str.data() );
				responses[i].length = l;
				responses[i].text = ( char* ) malloc( l + 1 );

				if ( responses[i].text ) { strcpy( responses[i].text, str.data() ); }

			}
		}

	}
	catch ( cexception* ex )
	{
		fprintf( stderr, "exception in kbdint callback used with libssh2: %s\n", ex->message() );
		ex->destroy();
	}
	catch ( ... )
	{
		fprintf( stderr, "excention (...) in kbdint callback used with libssh2\n" );
	}
}
Exemplo n.º 7
0
// 2. Delegate file Uri to baseBS. Folder Uri is tmp:///folder/name#baseFSRootUri
//   - appears to work 
FSString FSTmp::Uri(FSPath& path)
{
	FSTmpNode* n = rootDir.findByFsPath(&path);
	if (n && n->nodeType == FSTmpNode::NODE_FILE)
		return baseFS->Uri(n->baseFSPath);
	else
	{
		std::string ret(std::string("tmp://") + path.GetUtf8('/') + "#" + baseFS->Uri(rootPathName).GetUtf8());
		return FSString(ret.c_str());
	}
}
Exemplo n.º 8
0
void FSPath::_Set( int cs, const void* v )
{
	data.clear();
	cacheCs = -2;

	if ( cs == CS_UNICODE )
	{
		unicode_t* p = ( unicode_t* )v;

		if ( !*p ) { return; }

		while ( *p )
		{
			unicode_t* t = p;

			while ( *t != '\\' && *t != '/' && *t ) { t++; }

			int len = t - p;
			data.append( FSString( cs, p, len ) );
			p = ( *t ) ? t + 1 : t;
		}
	}
	else
	{
		char* p = ( char* )v;

		if ( !p || !*p ) { return; }

		while ( *p )
		{
			char* t = p;

			while ( *t != '\\' && *t != '/' && *t ) { t++; }

			int len = t - p;

			data.append( FSString( cs, p, len ) );
			p = ( *t ) ? t + 1 : t;
		}
	}
}
Exemplo n.º 9
0
FSString FSWin32Net::StrError( int err )
{
	if ( err == ERRNOSUPPORT )
	{
		return FSString( "Operation not supported by net fs" );
	}

	FSString ret;
	sys_char_t buf[1024];
	ret.SetSys( sys_error_str( err, buf, 0x100 ) );

	return ret;
}
Exemplo n.º 10
0
static void stripPathFromLastItem(FSPath& path)
{
	FSString* lastItem = path.GetItem(path.Count() - 1);
	if (lastItem)
	{
		const unicode_t* lastU = lastItem->GetUnicode();
		const unicode_t* lastDelim = unicode_strrchr(lastU, DIR_SPLITTER);
		if (lastDelim != 0)
		{
			path.SetItemStr(path.Count() - 1,FSString(lastDelim + 1));
		}
	}
}
Exemplo n.º 11
0
FSString FSSftp::Uri( FSPath& path )
{
	MutexLock lock( &infoMutex ); //infoMutex!!!

	std::vector<char> a;

	char port[0x100];
	snprintf( port, sizeof( port ), ":%i", _infoParam.port );

	FSString server( _infoParam.server.Data() );

	FSString user( _infoParam.user.Data() );
	a = carray_cat<char>( "sftp://", user.GetUtf8(), "@",  server.GetUtf8(), port, path.GetUtf8( '/' ) );

	return FSString( CS_UTF8, a.data() );
}
Exemplo n.º 12
0
    void FSTable::decodeFromStream(FSInputStream* aStream)
    {
#ifdef _DEBUG
        aStream->startDecoding(className());
#endif
        FSActionObject::decodeFromStream(aStream);

        int attributeCount = aStream->read(FSStream::UnsignedWord, 16);
            
        if (attributeCount > 0)
        {
#ifdef _DEBUG
            aStream->startDecoding("array");
#endif
            for (int i=0; i<attributeCount; i++)
            {
                char* str = aStream->readString();

                values.push_back(FSString(str));

                delete [] str;
            }
#ifdef _DEBUG
            aStream->endDecoding("array");
#endif
        }
        else
        {
            /*
             * Reset the length as Macromedia is using the length of a 
             * table to hide coded following an empty table.
             */
            length = 2;
        }
#ifdef _DEBUG
        aStream->endDecoding(className());
#endif
    }
Exemplo n.º 13
0
FSString FSSmb::Uri( FSPath& path )
{
	MutexLock lock( &mutex );
	std::vector<char> a;

	if ( _param.server[0] )
	{
		if ( _param.user[0] )
		{
			a = carray_cat<char>( "smb://", const_cast<char*>( _param.user ), "@",  const_cast<char*>( _param.server ), path.GetUtf8() );
		}
		else
		{
			a = carray_cat<char>( "smb://", const_cast<char*>( _param.server ), path.GetUtf8() );
		}
	}
	else
	{
		a = carray_cat<char>( "smb:/", path.GetUtf8() );
	}

	return FSString( CS_UTF8, a.data() );
}
Exemplo n.º 14
0
FSString FSSys::Uri( FSPath& path )
{
	unicode_t pref[0x100];
	unicode_t* p = pref;

	if ( _drive > 0 && _drive < 'z' - 'a' + 1 ) //+1 ???
	{
		*( p++ ) = 'A' + _drive;
		*( p++ ) = ':';
	}
	else if ( _drive == -1 )
	{
		*( p++ ) = '\\';
	}
	else
	{
		*( p++ ) = '?';
		*( p++ ) = ':';
	}

	*p = 0;

	return FSString( carray_cat<unicode_t>( pref, path.GetUnicode() ).data() );
}
Exemplo n.º 15
0
	virtual FSString StrError( int err ) override { return FSString( "Operation is not supported" ); }
Exemplo n.º 16
0
FSString FSSftp::StrError( int err )
{
	const char* s = "";

	if ( err < -500 )
	{
		switch ( err + 1000 )
		{
			case LIBSSH2_ERROR_SOCKET_NONE:
				s = "LIBSSH2_ERROR_SOCKET_NONE";
				break;

			case LIBSSH2_ERROR_BANNER_RECV:
				s = "LIBSSH2_ERROR_BANNER_RECV";
				break;

			case LIBSSH2_ERROR_BANNER_SEND:
				s = "LIBSSH2_ERROR_BANNER_SEND";
				break;

			case LIBSSH2_ERROR_INVALID_MAC:
				s = "LIBSSH2_ERROR_INVALID_MAC";
				break;

			case LIBSSH2_ERROR_KEX_FAILURE:
				s = "LIBSSH2_ERROR_KEX_FAILURE";
				break;

			case LIBSSH2_ERROR_ALLOC:
				s = "LIBSSH2_ERROR_ALLOC";
				break;

			case LIBSSH2_ERROR_SOCKET_SEND:
				s = "LIBSSH2_ERROR_SOCKET_SEND";
				break;

			case LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE:
				s = "LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE";
				break;

			case LIBSSH2_ERROR_TIMEOUT:
				s = "LIBSSH2_ERROR_TIMEOUT";
				break;

			case LIBSSH2_ERROR_HOSTKEY_INIT:
				s = "LIBSSH2_ERROR_HOSTKEY_INIT";
				break;

			case LIBSSH2_ERROR_HOSTKEY_SIGN:
				s = "LIBSSH2_ERROR_HOSTKEY_SIGN";
				break;

			case LIBSSH2_ERROR_DECRYPT:
				s = "LIBSSH2_ERROR_DECRYPT";
				break;

			case LIBSSH2_ERROR_SOCKET_DISCONNECT:
				s = "LIBSSH2_ERROR_SOCKET_DISCONNECT";
				break;

			case LIBSSH2_ERROR_PROTO:
				s = "LIBSSH2_ERROR_PROTO";
				break;

			case LIBSSH2_ERROR_PASSWORD_EXPIRED:
				s = "LIBSSH2_ERROR_PASSWORD_EXPIRED";
				break;

			case LIBSSH2_ERROR_FILE:
				s = "LIBSSH2_ERROR_FILE";
				break;

			case LIBSSH2_ERROR_METHOD_NONE:
				s = "LIBSSH2_ERROR_METHOD_NONE";
				break;

			case LIBSSH2_ERROR_AUTHENTICATION_FAILED:
				s = "Authentication failed";
				break;

			case LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED:
				s = "LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED";
				break;

			case LIBSSH2_ERROR_CHANNEL_OUTOFORDER:
				s = "LIBSSH2_ERROR_CHANNEL_OUTOFORDER";
				break;

			case LIBSSH2_ERROR_CHANNEL_FAILURE:
				s = "LIBSSH2_ERROR_CHANNEL_FAILURE";
				break;

			case LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED:
				s = "LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED";
				break;

			case LIBSSH2_ERROR_CHANNEL_UNKNOWN:
				s = "LIBSSH2_ERROR_CHANNEL_UNKNOWN";
				break;

			case LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED:
				s = "LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED";
				break;

			case LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED:
				s = "LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED";
				break;

			case LIBSSH2_ERROR_CHANNEL_CLOSED:
				s = "LIBSSH2_ERROR_CHANNEL_CLOSED";
				break;

			case LIBSSH2_ERROR_CHANNEL_EOF_SENT:
				s = "LIBSSH2_ERROR_CHANNEL_EOF_SENT";
				break;

			case LIBSSH2_ERROR_SCP_PROTOCOL:
				s = "LIBSSH2_ERROR_SCP_PROTOCOL";
				break;

			case LIBSSH2_ERROR_ZLIB:
				s = "LIBSSH2_ERROR_ZLIB";
				break;

			case LIBSSH2_ERROR_SOCKET_TIMEOUT:
				s = "LIBSSH2_ERROR_SOCKET_TIMEOUT";
				break;

			case LIBSSH2_ERROR_SFTP_PROTOCOL:
				s = "LIBSSH2_ERROR_SFTP_PROTOCOL";
				break;

			case LIBSSH2_ERROR_REQUEST_DENIED:
				s = "LIBSSH2_ERROR_REQUEST_DENIED";
				break;

			case LIBSSH2_ERROR_METHOD_NOT_SUPPORTED:
				s = "LIBSSH2_ERROR_METHOD_NOT_SUPPORTED";
				break;

			case LIBSSH2_ERROR_INVAL:
				s = "LIBSSH2_ERROR_INVAL";
				break;

			case LIBSSH2_ERROR_INVALID_POLL_TYPE:
				s = "LIBSSH2_ERROR_INVALID_POLL_TYPE";
				break;

			case LIBSSH2_ERROR_PUBLICKEY_PROTOCOL:
				s = "LIBSSH2_ERROR_PUBLICKEY_PROTOCOL";
				break;

			case LIBSSH2_ERROR_EAGAIN:
				s = "LIBSSH2_ERROR_EAGAIN";
				break;

			case LIBSSH2_ERROR_BUFFER_TOO_SMALL:
				s = "LIBSSH2_ERROR_BUFFER_TOO_SMALL";
				break;

			case LIBSSH2_ERROR_BAD_USE:
				s = "LIBSSH2_ERROR_BAD_USE";
				break;

			case LIBSSH2_ERROR_COMPRESS:
				s = "LIBSSH2_ERROR_COMPRESS";
				break;

			case LIBSSH2_ERROR_OUT_OF_BOUNDARY:
				s = "LIBSSH2_ERROR_OUT_OF_BOUNDARY";
				break;

			case LIBSSH2_ERROR_AGENT_PROTOCOL:
				s = "LIBSSH2_ERROR_AGENT_PROTOCOL";
				break;

			case LIBSSH2_ERROR_SOCKET_RECV:
				s = "LIBSSH2_ERROR_SOCKET_RECV";
				break;

			case LIBSSH2_ERROR_ENCRYPT:
				s = "LIBSSH2_ERROR_ENCRYPT";
				break;

			case LIBSSH2_ERROR_BAD_SOCKET:
				s = "LIBSSH2_ERROR_BAD_SOCKET";
				break;

			default:
				s = "LIBSSH2_ERROR_???";
				break;
		}

	}
	else
	{
		switch ( err )
		{
			case SSH_INTERROR_NOTSUPPORT:
				s = "not supported operation";
				break;

			case SSH_INTERROR_X3:
				s = "X3";
				break;

			case SSH_INTERROR_CONNECT:
				s = "connection failed";
				break;

			case SSH_INTERROR_AUTH:
				s = "authorization failed";
				break;

			case SSH_INTERROR_FATAL:
				s = "fatal ssh error";
				break;

			case SSH_INTERROR_STOPPED:
				s = "Process stopped";
				break;

			default:
				if ( err >= 0 )
				{
					sys_char_t buf[0x100];
					FSString str;
					str.SetSys( sys_error_str( err, buf, 0x100 ) );
					return str;
				}

				char buf[0x100];
				snprintf( buf, sizeof( buf ), "err : %i ???", err );
				FSString str( CS_UTF8, buf );
				return str;
		}
	}

	return FSString( CS_UTF8, s );
}
Exemplo n.º 17
0
int FSSftp::CheckSession( int* err, FSCInfo* info )
{

	if ( sshSession ) { return 0; }

	try
	{

		unsigned ip;
		int e;

		if ( !GetHostIp( unicode_to_utf8( _operParam.server.Data() ).data(), &ip, &e ) )
		{
			throw int( e );
		}

		_sock.Create();
		_sock.Connect( ntohl( ip ), _operParam.port );

		sshSession = libssh2_session_init();

		if ( !sshSession ) { throw int( SSH_INTERROR_X3 ); }

		libssh2_session_set_blocking( sshSession, 0 );

		WHILE_EAGAIN_( e, libssh2_session_handshake( sshSession, _sock.Id() ) );

		if ( e ) { throw int( e - 1000 ); }

		FSString userName = "";

		if ( _operParam.user.Data()[0] )
		{
			userName = _operParam.user.Data();
		}
		else
		{
#ifndef _WIN32
			char* ret = getenv( "LOGNAME" );

			if ( ret )
			{
				userName = FSString( sys_charset_id, ret );
				_operParam.user = userName.GetUnicode();

				MutexLock infoLock( &infoMutex );
				_infoParam.user = userName.GetUnicode();
			}

#endif
		};

		char* authList = 0;

		char* charUserName = ( char* )userName.Get( _operParam.charset );

		while ( true )
		{
			authList = libssh2_userauth_list( sshSession, charUserName, strlen( charUserName ) );

			if ( authList ) { break; }

			CheckSessionEagain();
			WaitSocket( info );
		}


		//publickey,password,keyboard-interactive
		static const char passId[] = "password";
		static const char kInterId[] = "keyboard-interactive";


		static unicode_t userSymbol = '@';

		while ( true )
		{
			if ( !strncmp( authList, passId, strlen( passId ) ) )
			{
				FSPromptData data;
				data.visible = false;
				data.prompt = utf8_to_unicode( "Password:"******"SFTP_" ).data(),
				        carray_cat<unicode_t>( userName.GetUnicode(), &userSymbol, _operParam.server.Data() ).data(),
				        &data, 1 ) ) { throw int( SSH_INTERROR_STOPPED ); }

				int ret;
				WHILE_EAGAIN_( ret, libssh2_userauth_password( sshSession,
				                                               ( char* )FSString( _operParam.user.Data() ).Get( _operParam.charset ),
				                                               ( char* )FSString( data.prompt.Data() ).Get( _operParam.charset ) ) );

				if ( ret ) { throw int( ret - 1000 ); }

				break; //!!!
			}
			else if ( !strncmp( authList, kInterId, strlen( kInterId ) ) )
			{
				MutexLock lock( &kbdIntMutex );
				kbdIntInfo = info;
				kbdIntParam = &_operParam;

				int ret;
				WHILE_EAGAIN_( ret,
				               libssh2_userauth_keyboard_interactive( sshSession,
				                                                      ( char* )FSString( _operParam.user.Data() ).Get( _operParam.charset ),
				                                                      KbIntCallback )
				             );

				if ( ret ) { throw int( ret - 1000 ); }

				break; //!!!
			}

			char* s = authList;

			while ( *s && *s != ',' ) { s++; }

			if ( !*s ) { break; }

			authList = s + 1;
		};


		while ( true )
		{
			sftpSession = libssh2_sftp_init( sshSession );

			if ( sftpSession ) { break; }

			if ( !sftpSession )
			{
				int e = libssh2_session_last_errno( sshSession );

				if ( e != LIBSSH2_ERROR_EAGAIN ) { throw int( e - 1000 ); }
			}

			WaitSocket( info );
		}

		return 0;

	}
	catch ( int e )
	{
		if ( err ) { *err = e; }

		//if (sftpSession) ??? похоже закрытие сессии все решает
		if ( sshSession ) { libssh2_session_free( sshSession ); }

		sshSession = 0;
		sftpSession = 0;
		_sock.Close( false );
		return ( e == -2 ) ? -2 : -1;
	}

}
Exemplo n.º 18
0
FSString FSSftp::StrError( int err )
{
	const char* s = "";

	switch ( err )
	{
		case SSH_INTERROR_NOTSUPPORT:
			s = "not supported operation";
			break;

		case SSH_INTERROR_X3:
			s = "X3";
			break;

		case SSH_INTERROR_CONNECT:
			s = "connection failed";
			break;

		case SSH_INTERROR_AUTH:
			s = "authorization failed";
			break;

		case SSH_INTERROR_FATAL:
			s = "fatal ssh error";
			break;

		case SSH_INTERROR_STOPPED:
			s = "Process stopped";
			break;

		case SSH_FX_OK:
			s = "No error";
			break;

		case SSH_FX_EOF:
			s = "End-of-file encountered";
			break;

		case SSH_FX_NO_SUCH_FILE:
			s = "File doesn't exist";
			break;

		case SSH_FX_PERMISSION_DENIED:
			s = "Permission denied";
			break;

		case SSH_FX_FAILURE:
			s = "Generic failure";
			break;

		case SSH_FX_BAD_MESSAGE:
			s = "Garbage received from server";
			break;

		case SSH_FX_NO_CONNECTION:
			s = "No connection has been set up";
			break;

		case SSH_FX_CONNECTION_LOST:
			s = "There was a connection, but we lost it";
			break;

		case SSH_FX_OP_UNSUPPORTED:
			s = "Operation not supported by the server";
			break;

		case SSH_FX_INVALID_HANDLE:
			s = "Invalid file handle";
			break;

		case SSH_FX_NO_SUCH_PATH:
			s = "No such file or directory path exists";
			break;

		case SSH_FX_FILE_ALREADY_EXISTS:
			s = "An attempt to create an already existing file or directory has been made";
			break;

		case SSH_FX_WRITE_PROTECT:
			s = "We are trying to write on a write-protected filesystem";
			break;

		case SSH_FX_NO_MEDIA:
			s = "No media in remote drive";
			break;


			/* case SSH_NO_ERROR: s = "no error"; break;
			   case SSH_REQUEST_DENIED: s = "recoverable error"; break;
			   case SSH_FATAL: s = "fatal ssh error"; break;
			   case SSH_INTERROR_OUTOF: s = "out of invernal sftp vfs resources"; break;
			*/
		default:
			s = "???";
			break;
	}

	return FSString( CS_UTF8, s );
}
Exemplo n.º 19
0
int FSSftp::CheckSession( int* err, FSCInfo* info )
{
	if ( sshSession ) { return 0; }

	try
	{
		sshSession = ssh_new();

		if ( !sshSession ) { throw int( SSH_INTERROR_X3 ); }

		if ( ssh_options_set( sshSession, SSH_OPTIONS_HOST, unicode_to_utf8( _operParam.server.Data() ).ptr() ) )
		{
			throw int( SSH_INTERROR_X3 );
		}

		int port = _operParam.port;

		if ( ssh_options_set( sshSession, SSH_OPTIONS_PORT, &port ) )
		{
			throw int( SSH_INTERROR_X3 );
		}


		FSString userName = "";

		if ( _operParam.user.Data()[0] )
		{
			userName = _operParam.user.Data();
		}
		else
		{
			char* ret = getenv( "LOGNAME" );

			if ( ret )
			{
				userName = FSString( sys_charset_id, ret );
				_operParam.user = userName.GetUnicode();

				MutexLock infoLock( &infoMutex );
				_infoParam.user = userName.GetUnicode();
			}
		};

		if ( ssh_options_set( sshSession, SSH_OPTIONS_USER, ( char* )userName.Get( _operParam.charset ) ) ) //есть сомнения, что надо все таки в utf8
		{
			throw int( SSH_INTERROR_X3 );
		}

		if ( ssh_connect( sshSession ) != SSH_OK )
		{
			throw int( SSH_INTERROR_CONNECT );
		}


		int method = ssh_userauth_list( sshSession, 0 );

		int ret;


		static unicode_t userSymbol = '@';

		if ( method & SSH_AUTH_METHOD_PASSWORD )
		{
			FSPromptData data;
			data.visible = false;
			data.prompt = utf8_to_unicode( "Password:"******"SFTP_" ).ptr(),
			        carray_cat<unicode_t>( userName.GetUnicode(), &userSymbol, _operParam.server.Data() ).ptr(),
			        &data, 1 ) ) { throw int( SSH_INTERROR_STOPPED ); }

			ret = ssh_userauth_password( sshSession,
			                             ( char* )FSString( _operParam.user.Data() ).Get( _operParam.charset ),
			                             ( char* )FSString( data.prompt.Data() ).Get( _operParam.charset ) );
		}

		if ( ret != SSH_AUTH_SUCCESS &&
		     ( method & SSH_AUTH_METHOD_INTERACTIVE ) != 0 )
		{
			while ( true )
			{
				ret = ssh_userauth_kbdint( sshSession, 0, 0 );

				if ( ret != SSH_AUTH_INFO ) { break; }

				const char* instruction = ssh_userauth_kbdint_getinstruction( sshSession );

				if ( !instruction ) { instruction = ""; }

				int n = ssh_userauth_kbdint_getnprompts( sshSession );

				if ( n <= 0 ) { continue; }

				std::vector<FSPromptData> pData( n );
				int i;

				for ( i = 0; i < n; i++ )
				{
					char echo;
					const char* prompt = ssh_userauth_kbdint_getprompt( sshSession, i, &echo );

					if ( !prompt ) { break; }

					pData[i].visible = echo != 0;
					pData[i].prompt = utf8_to_unicode( prompt ).ptr();
				}

				if ( !info ) { throw int( SSH_INTERROR_AUTH ); }

				if ( !info->Prompt(
				        utf8_to_unicode( "SFTP" ).ptr(),
				        carray_cat<unicode_t>( userName.GetUnicode(), &userSymbol, _operParam.server.Data() ).ptr(),
				        pData.ptr(), n ) ) { throw int( SSH_INTERROR_STOPPED ); }

				for ( i = 0; i < n; i++ )
				{
					if ( ssh_userauth_kbdint_setanswer( sshSession, i, ( char* )FSString( pData[i].prompt.Data() ).Get( _operParam.charset ) ) < 0 )
					{
						throw int( SSH_INTERROR_AUTH );
					}
				}
			}
		}

		if ( ret != SSH_AUTH_SUCCESS )
		{
			if ( ret == SSH_AUTH_PARTIAL )
			{
				throw int( SSH_INTERROR_UNSUPPORTED_AUTH );
			}
			else
			{
				throw int( SSH_INTERROR_AUTH );
			}
		}

		sftpSession = sftp_new( sshSession );

		if ( !sftpSession ) { throw int( SSH_INTERROR_FATAL ); }

		if ( sftp_init( sftpSession ) != SSH_OK ) { throw int( SSH_INTERROR_FATAL ); }

	}
	catch ( int e )
	{
		if ( err ) { *err = e; }

		if ( sftpSession ) { sftp_free( sftpSession ); }

		if ( sshSession ) { ssh_free( sshSession ); }

		sshSession = 0;
		sftpSession = 0;
		return ( e == SSH_INTERROR_STOPPED ) ? -2 : -1;
	}

	return 0;
}
Exemplo n.º 20
0
	clFileAttributesWin( NCDialogParent* parent, PanelWin* Panel )
	 : NCVertDialog( ::createDialogAsChild, 0, parent, utf8_to_unicode(_LT("Attributes")).data(), bListOkCancel )
	 , m_Panel( Panel )
	 , m_Node( Panel ? Panel->GetCurrent() : nullptr )
	 , m_URI( Panel ? Panel->UriOfCurrent() : FSString() )
	 , m_Layout( 17, 3 )
	 , m_CaptionText( 0, this, utf8_to_unicode( _LT( "" ) ).data(), nullptr, StaticLine::CENTER )
	 , m_FileNameText( uiValue, this, utf8_to_unicode( _LT( "" ) ).data(), nullptr, StaticLine::CENTER )
#if defined(_WIN32)
	 , m_ReadOnly( uiVariable, this, utf8_to_unicode( _LT( "Read only" ) ).data(), 0, false )
	 , m_Archive( uiVariable, this, utf8_to_unicode( _LT( "Archive" ) ).data(), 0, false )
	 , m_Hidden( uiVariable, this, utf8_to_unicode( _LT( "Hidden" ) ).data(), 0, false )
	 , m_System( uiVariable, this, utf8_to_unicode( _LT( "System" ) ).data(), 0, false )
	 , m_Compressed( 0, this, utf8_to_unicode( _LT( "Compressed" ) ).data(), 0, false )
	 , m_Encrypted( 0, this, utf8_to_unicode( _LT( "Encrypted" ) ).data(), 0, false )
	 , m_NotIndexed( 0, this, utf8_to_unicode( _LT( "NotIndexed" ) ).data(), 0, false )
	 , m_Sparse( 0, this, utf8_to_unicode( _LT( "Sparse" ) ).data(), 0, false )
	 , m_Temporary( 0, this, utf8_to_unicode( _LT( "Temporary" ) ).data(), 0, false )
	 , m_Offline( 0, this, utf8_to_unicode( _LT( "Offline" ) ).data(), 0, false )
	 , m_ReparsePoint( 0, this, utf8_to_unicode( _LT( "ReparsePoint" ) ).data(), 0, false )
	 , m_Virtual( 0, this, utf8_to_unicode( _LT( "Virtual" ) ).data(), 0, false )
#else
	 , m_UserRead( uiVariable, this, utf8_to_unicode( _LT( "User &read" ) ).data(), 0, false )
	 , m_UserWrite( uiVariable, this, utf8_to_unicode( _LT( "User &write" ) ).data(), 0, false )
    , m_UserExecute( uiVariable, this, utf8_to_unicode( _LT( "User e&xecute" ) ).data(), 0, false )
	 , m_GroupRead( uiVariable, this, utf8_to_unicode( _LT( "&Group read" ) ).data(), 0, false )
	 , m_GroupWrite( uiVariable, this, utf8_to_unicode( _LT( "Group write" ) ).data(), 0, false )
	 , m_GroupExecute( uiVariable, this, utf8_to_unicode( _LT( "Group execute" ) ).data(), 0, false )
	 , m_OthersRead( uiVariable, this, utf8_to_unicode( _LT( "&Others read" ) ).data(), 0, false )
	 , m_OthersWrite( uiVariable, this, utf8_to_unicode( _LT( "Others write" ) ).data(), 0, false )
	 , m_OthersExecute( uiVariable, this, utf8_to_unicode( _LT( "Others execute" ) ).data(), 0, false )
#endif
	// time
	 , m_LastWriteTimeLabel( 0, this, utf8_to_unicode( _LT( "Last write time" ) ).data(), nullptr, StaticLine::LEFT )
	 , m_CreationTimeLabel( 0, this, utf8_to_unicode( _LT( "Creation time" ) ).data(), nullptr, StaticLine::LEFT )
	 , m_LastAccessTimeLabel( 0, this, utf8_to_unicode( _LT( "Last access time" ) ).data(), nullptr, StaticLine::LEFT )
	 , m_ChangeTimeLabel( 0, this, utf8_to_unicode( _LT( "Change time" ) ).data(), nullptr, StaticLine::LEFT )
	 //
	 , m_LastWriteDate( 0, this, nullptr, utf8_to_unicode( _LT( "DD.MM.YYYY" ) ).data(), 9 )
	 , m_CreationDate( 0, this, nullptr, utf8_to_unicode( _LT( "DD.MM.YYYY" ) ).data(), 9 )
	 , m_LastAccessDate( 0, this, nullptr, utf8_to_unicode( _LT( "DD.MM.YYYY" ) ).data(), 9 )
	 , m_ChangeDate( 0, this, nullptr, utf8_to_unicode( _LT( "DD.MM.YYYY" ) ).data(), 9 )
	 //
	 , m_LastWriteTime( 0, this, nullptr, utf8_to_unicode( _LT( "HH:MM:SS" ) ).data(), 13 )
	 , m_CreationTime( 0, this, nullptr, utf8_to_unicode( _LT( "HH:MM:SS" ) ).data(), 13 )
	 , m_LastAccessTime( 0, this, nullptr, utf8_to_unicode( _LT( "HH:MM:SS" ) ).data(), 13 )
	 , m_ChangeTime( 0, this, nullptr, utf8_to_unicode( _LT( "HH:MM:SS" ) ).data(), 13 )
	{
		if ( m_Panel )
		{
			const unicode_t* FileName = m_Panel->GetCurrentFileName();

			m_FileNameText.SetText( FileName );
		}

		if ( m_Node && m_Node->IsDir() )
		{
			m_CaptionText.SetText( utf8_to_unicode( _LT("Change attributes for folder:") ).data() );
		}
		else
		{
			m_CaptionText.SetText( utf8_to_unicode( _LT("Change file attributes for:") ).data() );
		}

		int Row = 0;

		m_Layout.AddWinAndEnable( &m_CaptionText, Row, 0, Row, 2 ); Row++;
		m_Layout.AddWinAndEnable( &m_FileNameText, Row, 0, Row, 2 ); Row++;

		int TRow = Row;

#if defined(_WIN32)
		m_Layout.AddWinAndEnable( &m_ReadOnly, Row++, 0 );
		m_Layout.AddWinAndEnable( &m_Archive, Row++, 0 );
		m_Layout.AddWinAndEnable( &m_Hidden, Row++, 0 );
		m_Layout.AddWinAndEnable( &m_System, Row++, 0 );
		m_Layout.AddWinAndEnable( &m_Compressed, Row++, 0 );
		m_Layout.AddWinAndEnable( &m_Encrypted, Row++, 0 );
		Row = TRow;
		m_Layout.AddWinAndEnable( &m_NotIndexed, Row++, 1 );
		m_Layout.AddWinAndEnable( &m_Sparse, Row++, 1 );
		m_Layout.AddWinAndEnable( &m_Temporary, Row++, 1 );
		m_Layout.AddWinAndEnable( &m_Offline, Row++, 1 );
		m_Layout.AddWinAndEnable( &m_ReparsePoint, Row++, 1 );
		m_Layout.AddWinAndEnable( &m_Virtual, Row++, 1 );

		// disable editing of these properties
		m_Compressed.Enable( false );
		m_Encrypted.Enable( false );
		m_NotIndexed.Enable( false );
		m_Sparse.Enable( false );
		m_Temporary.Enable( false );
		m_Offline.Enable( false );
		m_ReparsePoint.Enable( false );
		m_Virtual.Enable( false );
#else
		m_Layout.AddWinAndEnable( &m_UserRead, Row, 0 );
		m_Layout.AddWinAndEnable( &m_UserWrite, Row, 1 );
		m_Layout.AddWinAndEnable( &m_UserExecute, Row, 2 );
		Row++;
		m_Layout.AddWinAndEnable( &m_GroupRead, Row, 0 );
		m_Layout.AddWinAndEnable( &m_GroupWrite, Row, 1 );
		m_Layout.AddWinAndEnable( &m_GroupExecute, Row, 2 );
		Row++;
		m_Layout.AddWinAndEnable( &m_OthersRead, Row, 0 );
		m_Layout.AddWinAndEnable( &m_OthersWrite, Row, 1 );
		m_Layout.AddWinAndEnable( &m_OthersExecute, Row, 2 );
#endif

		m_Layout.LineSet( Row++, 5 );

		TRow = Row;
		m_Layout.AddWinAndEnable( &m_LastWriteTimeLabel, Row++, 0 );
		m_Layout.AddWinAndEnable( &m_CreationTimeLabel, Row++, 0 );
		m_Layout.AddWinAndEnable( &m_LastAccessTimeLabel, Row++, 0 );
#if defined(HAS_CHANGETIME)
		m_Layout.AddWinAndEnable( &m_ChangeTimeLabel, Row++, 0 );
#endif
		Row = TRow;
		m_Layout.AddWinAndEnable( &m_LastWriteDate, Row++, 1 );
		m_Layout.AddWinAndEnable( &m_CreationDate, Row++, 1 );
		m_Layout.AddWinAndEnable( &m_LastAccessDate, Row++, 1 );
#if defined(HAS_CHANGETIME)
		m_Layout.AddWinAndEnable( &m_ChangeDate, Row++, 1 );
#endif
		Row = TRow;
		m_Layout.AddWinAndEnable( &m_LastWriteTime, Row++, 2 );
		m_Layout.AddWinAndEnable( &m_CreationTime, Row++, 2 );
		m_Layout.AddWinAndEnable( &m_LastAccessTime, Row++, 2 );
#if defined(HAS_CHANGETIME)
		m_Layout.AddWinAndEnable( &m_ChangeTime, Row++, 2 );
#endif

		m_LastWriteDate.SetValidator( new clDateValidator() );
		m_LastWriteDate.SetReplaceMode( true );
		m_CreationDate.SetValidator( new clDateValidator() );
		m_CreationDate.SetReplaceMode( true );
		m_LastAccessDate.SetValidator( new clDateValidator() );
		m_LastAccessDate.SetReplaceMode( true );
#if defined(HAS_CHANGETIME)
		m_ChangeDate.SetValidator( new clDateValidator() );
		m_ChangeDate.SetReplaceMode( true );
#endif
		m_LastWriteTime.SetValidator( new clTimeValidator() );
		m_LastWriteTime.SetReplaceMode( true );
		m_CreationTime.SetValidator( new clTimeValidator() );
		m_CreationTime.SetReplaceMode( true );
		m_LastAccessTime.SetValidator( new clTimeValidator() );
		m_LastAccessTime.SetReplaceMode( true );
#if defined(HAS_CHANGETIME)
		m_ChangeTime.SetValidator( new clTimeValidator() );
		m_ChangeTime.SetReplaceMode( true );
#endif

		UpdateAttributes( m_Node );
		
		AddLayout( &m_Layout );

		order.clear();
#if defined(_WIN32)
		order.append(&m_ReadOnly);
		order.append(&m_Archive);
		order.append(&m_Hidden);
		order.append(&m_System);
#else
		order.append(&m_UserRead);
		order.append(&m_UserWrite);
		order.append(&m_UserExecute);
		order.append(&m_GroupRead);
		order.append(&m_GroupWrite);
		order.append(&m_GroupExecute);
		order.append(&m_OthersRead);
		order.append(&m_OthersWrite);
		order.append(&m_OthersExecute);
#endif // _WIN32
		order.append(&m_LastWriteDate);
		order.append(&m_LastWriteTime);
		order.append(&m_CreationDate);
		order.append(&m_CreationTime);
		order.append(&m_LastAccessDate);
		order.append(&m_LastAccessTime);
#if defined(HAS_CHANGETIME)
		order.append(&m_ChangeDate);
		order.append(&m_ChangeTime);
#endif // HAS_CHANGETIME

		SetEnterCmd( CMD_OK );
		SetPosition();
	}
Exemplo n.º 21
0
FSString FSSys::Uri( FSPath& path )
{
	return FSString( path.GetUnicode() );
}
Exemplo n.º 22
0
	virtual FSString Uri( FSPath& path ) override
	{
		FSPath FilePath( m_Uri );
		std::string ret( FilePath.GetItem( FilePath.Count() - 1 )->GetUtf8() + std::string( ":" ) + path.GetUtf8( '/' ) );
		return FSString( ret.c_str() );
	}