예제 #1
0
AMQPExchange::AMQPExchange(amqp_connection_state_t * cnn, int channelNum, string name) {
	this->cnn = cnn;
	this->channelNum = channelNum;
	this->name = name;

	openChannel();
}
예제 #2
0
파일: SSH.cpp 프로젝트: subutai-io/launcher
 void SSH::openShell()
 {
     if (_bShellOpen)
     {
         return;
     }
     if (!_bChanOpen)
     {
         openChannel();
     }
     _logger->debug("Opening SSH shell");
     int rc;
     rc = ssh_channel_request_pty(_channel);
     if (rc != SSH_OK) 
     {
         throw SSHException("Failed to request PTY from remote host", SSHErrorCode::E_PTY_REQUEST_FAILED);
     }
     rc = ssh_channel_change_pty_size(_channel, 80, 24);
     if (rc != SSH_OK) 
     {
         throw SSHException("Failed to change PTY size", SSHErrorCode::E_PTY_SIZE_FAILED);
     }
     rc = ssh_channel_request_shell(_channel);
     if (rc != SSH_OK) 
     {
         throw SSHException("Failed to request remote shell", SSHErrorCode::E_SHELL_REQUEST_FAILED);
     }
     _bShellOpen = true;
 }
예제 #3
0
int main(int argc, char ** argv)
{
	int inputChannel, outputChannel;
	clientState state;
	//char msg[2048];
	//u_int16_t length;

	/* Mandatory arguments */
	if( !argv[1] || !argv[2] || !argv[3] || !argv[4] ) {
		fprintf(stderr,"client [server->client fifo] [client->server fifo] [password file] [username]\n");
		exit(1);
	}

	/* Create connection with the server */
	fprintf(stderr,"Create connection...\n");
	outputChannel = openChannel(argv[2]);
	inputChannel  = openChannel(argv[1]);
	
	
	if(askConnection(inputChannel , outputChannel) == -1) //handshake error
	{
		fprintf(stderr , "handshake falied \n");
		state = CLOSING;	
	}
	else
	{
		fprintf(stderr , "handshake succeded \n");
		state = CLOSING;
	}
	
	switch(state){
			
			case HANDSHAKE : break;//call authenication
			
			case AUTHENTICATED : break; //call for key exchange
				
			case COMMUNICATION : break; //communication 
				
			case CLOSING : 
				closeConnection(inputChannel , outputChannel); 
				break;
				
			default : break;
	}
	
	return 0;
}
예제 #4
0
int openFifo(const char * pathname){
	/* Recreate the FIFO in pathname */
	unlink(pathname);
	if(mkfifo(pathname,0600) < 0 ) {
		perror("mkfifo()");
		return -1;
	}

	/* Open the channel */
	return (openChannel(pathname));
}
예제 #5
0
파일: SSH.cpp 프로젝트: subutai-io/launcher
    std::string SSH::execute(const std::string& command)
    {
        _logger->trace("Executing SSH command: %s", command);
        int rc;
        char buffer[1024];
        int nbytes;
        memset(buffer, 0, 1024);
        if (_ssh == NULL)
        {
            _logger->debug("Initializing SSH");
            _ssh = ssh_new();
        }
        if (_ssh == NULL) {
            throw SubutaiException("Failed to start SSH session");
        }

        if (!_bChanOpen)
        {
            rc = openChannel();
            if (rc != E_NOERR)
            {
                _logger->error("Couldn't open SSH channel: %d", rc);
                return "";
            }
        }

        _logger->trace("Starting SSH command execution");
        rc = ssh_channel_request_exec(_channel, command.c_str());
        if (rc != SSH_OK) {
            closeChannel();
            throw SSHException("Failed to execute SSH command", SSHErrorCode::E_CMD_EXEC_FAILED);
        }

        _logger->trace("Reading from channel");
        nbytes = ssh_channel_read(_channel, buffer, sizeof(buffer), 0);

        std::string pBuffer("");

        while (nbytes > 0)
        {
            pBuffer.append(buffer);
            nbytes = ssh_channel_read(_channel, buffer, sizeof(buffer), 0);
        }

        if (nbytes < 0) 
        {
            closeChannel();
            throw SSHException("Output channel is empty", SSHErrorCode::E_EMPTY_OUTPUT_CHAN);
        }

        closeChannel();
        _logger->debug("SSH Execution output: %s", pBuffer);
        return Poco::trim(pBuffer);
    }
예제 #6
0
BOOL SendTestFrames( FT_HANDLE ftHandle )
{
  CANMsg msg;

  if ( !openChannel( ftHandle, 6 ) ) {
    printf("Failed to open channel\n");
    return FALSE;
  }

  // Send extended frame
  msg.flags = CANMSG_EXTENDED;
  msg.id = 0x123456;
  msg.len = 2;
  msg.data[0] = 1;
  msg.data[1] = 2;

  if ( !sendFrame( ftHandle, &msg ) ) {
    printf("Failed to send frame\n");
    return FALSE;
  }

  // Send standard frame
  msg.flags = 0;
  msg.id = 0x123;
  msg.len = 2;
  msg.data[0] = 1;
  msg.data[1] = 2;

  if ( !sendFrame( ftHandle, &msg ) ) {
    printf("Failed to send frame\n");
    return FALSE;
  }
  

  FT_Purge( ftHandle, FT_PURGE_TX );

  if ( !closeChannel( ftHandle ) ) {
    printf("Failed to close channel\n");
    return FALSE;
  }
  
  return TRUE;
}
예제 #7
0
BOOL GetTestFrames( FT_HANDLE ftHandle )
{
  gnReceivedFrames = 0;

  if ( !openChannel( ftHandle, 6 ) ) {
    printf("Failed to open channel\n");
    return FALSE;
  }

  printf("Waiting to receive five frames (ctrl-c to abort)...\n");
  while ( gnReceivedFrames < 5 ) {
    readFrame( ftHandle );
  }

  if ( !closeChannel( ftHandle ) ) {
    printf("Failed to close channel\n");
    return FALSE;
  }

  return TRUE;
}
예제 #8
0
AMQPExchange::AMQPExchange(amqp_connection_state_t * cnn, int channelNum) {
	this->cnn = cnn;
	this->channelNum = channelNum;

	openChannel();
}
void QProcessPrivate::startProcess()
{
    Q_Q(QProcess);

    bool success = false;

    if (pid) {
        CloseHandle(pid->hThread);
        CloseHandle(pid->hProcess);
        delete pid;
        pid = 0;
    }
    pid = new PROCESS_INFORMATION;
    memset(pid, 0, sizeof(PROCESS_INFORMATION));

    q->setProcessState(QProcess::Starting);

    if (!openChannel(stdinChannel) ||
        !openChannel(stdoutChannel) ||
        !openChannel(stderrChannel))
        return;

    QString args = qt_create_commandline(program, arguments);
    QByteArray envlist;
    if (environment.d.constData())
        envlist = qt_create_environment(environment.d.constData()->hash);
    if (!nativeArguments.isEmpty()) {
        if (!args.isEmpty())
             args += QLatin1Char(' ');
        args += nativeArguments;
    }

#if defined QPROCESS_DEBUG
    qDebug("Creating process");
    qDebug("   program : [%s]", program.toLatin1().constData());
    qDebug("   args : %s", args.toLatin1().constData());
    qDebug("   pass environment : %s", environment.isEmpty() ? "no" : "yes");
#endif

    // We cannot unconditionally set the CREATE_NO_WINDOW flag, because this
    // will render the stdout/stderr handles connected to a console useless
    // (this typically affects ForwardedChannels mode).
    // However, we also do not want console tools launched from a GUI app to
    // create new console windows (behavior consistent with UNIX).
    DWORD dwCreationFlags = (GetConsoleWindow() ? 0 : CREATE_NO_WINDOW);
    dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
    STARTUPINFOW startupInfo = { sizeof( STARTUPINFO ), 0, 0, 0,
                                 (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
                                 (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
                                 0, 0, 0,
                                 STARTF_USESTDHANDLES,
                                 0, 0, 0,
                                 stdinChannel.pipe[0], stdoutChannel.pipe[1], stderrChannel.pipe[1]
    };
    success = CreateProcess(0, (wchar_t*)args.utf16(),
                            0, 0, TRUE, dwCreationFlags,
                            environment.isEmpty() ? 0 : envlist.data(),
                            workingDirectory.isEmpty() ? 0 : (wchar_t*)QDir::toNativeSeparators(workingDirectory).utf16(),
                            &startupInfo, pid);
    if (!success) {
        // Capture the error string before we do CloseHandle below
        q->setErrorString(QProcess::tr("Process failed to start: %1").arg(qt_error_string()));
    }

    if (stdinChannel.pipe[0] != INVALID_Q_PIPE) {
        CloseHandle(stdinChannel.pipe[0]);
        stdinChannel.pipe[0] = INVALID_Q_PIPE;
    }
    if (stdoutChannel.pipe[1] != INVALID_Q_PIPE) {
        CloseHandle(stdoutChannel.pipe[1]);
        stdoutChannel.pipe[1] = INVALID_Q_PIPE;
    }
    if (stderrChannel.pipe[1] != INVALID_Q_PIPE) {
        CloseHandle(stderrChannel.pipe[1]);
        stderrChannel.pipe[1] = INVALID_Q_PIPE;
    }

    if (!success) {
        cleanup();
        processError = QProcess::FailedToStart;
        emit q->error(processError);
        q->setProcessState(QProcess::NotRunning);
        return;
    }

    q->setProcessState(QProcess::Running);
    // User can call kill()/terminate() from the stateChanged() slot
    // so check before proceeding
    if (!pid)
        return;

    if (threadData->hasEventDispatcher()) {
        processFinishedNotifier = new QWinEventNotifier(pid->hProcess, q);
        QObject::connect(processFinishedNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_processDied()));
        processFinishedNotifier->setEnabled(true);
        notifier = new QTimer(q);
        QObject::connect(notifier, SIGNAL(timeout()), q, SLOT(_q_notified()));
        notifier->start(NOTIFYTIMEOUT);
    }

    _q_startupNotification();
}
예제 #10
0
파일: sshclient.cpp 프로젝트: aopui/gnash
// Channel operations
ssh_channel
SSHClient::openChannel()
{
//    GNASH_REPORT_FUNCTION;
    return openChannel(_session);
}