示例#1
0
static void
remmina_ssh_tunnel_close_all_channels (RemminaSSHTunnel *tunnel)
{
	int i;

	for (i = 0; i < tunnel->num_channels; i++)
	{
		close (tunnel->sockets[i]);
		remmina_ssh_tunnel_buffer_free (tunnel->socketbuffers[i]);
		channel_close (tunnel->channels[i]);
		channel_free (tunnel->channels[i]);
	}

	g_free(tunnel->channels);
	tunnel->channels = NULL;
	g_free(tunnel->sockets);
	tunnel->sockets = NULL;
	g_free(tunnel->socketbuffers);
	tunnel->socketbuffers = NULL;

	tunnel->num_channels = 0;
	tunnel->max_channels = 0;

	if (tunnel->x11_channel)
	{
		channel_close (tunnel->x11_channel);
		channel_free (tunnel->x11_channel);
		tunnel->x11_channel = NULL;
	}
}
void
test_body (void)
{
    const gchar chunk[] = "This is a body text.";
    const gchar *packet;
    gsize packet_size;
    gsize packed_size;

    test_end_of_header();
    channel_free();

    reply_continue();

    cut_assert_true(milter_server_context_body(context, chunk, strlen(chunk)));
    pump_all_events();
    milter_test_assert_state(BODY);
    milter_test_assert_status(NOT_CHANGE);

    milter_command_encoder_encode_body(encoder, &packet, &packet_size,
                                       chunk, strlen(chunk), &packed_size);
    milter_test_assert_packet(channel, packet, packet_size);
    cut_assert_equal_uint(strlen(chunk), packed_size);

    cut_assert_equal_uint(0, n_message_processed);
}
void
test_header (void)
{
    const gchar name[] = "X-HEADER-NAME";
    const gchar value[] = "MilterServerContext test";
    const gchar *packet;
    gsize packet_size;

    test_data();
    channel_free();

    reply_continue();

    cut_assert_true(milter_server_context_header(context, name, value));
    pump_all_events();
    milter_test_assert_state(HEADER);
    milter_test_assert_status(NOT_CHANGE);

    milter_command_encoder_encode_header(encoder,
                                         &packet, &packet_size,
                                         name, value);
    milter_test_assert_packet(channel, packet, packet_size);

    cut_assert_equal_uint(0, n_message_processed);
}
示例#4
0
void
test_ofp_table_stats_reply_create_null(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct channel *channel = channel_alloc_ip4addr("127.0.0.1", "1000", 0x01);
  struct pbuf_list *pbuf_list = NULL;
  struct ofp_header xid_header;

  ret = ofp_table_stats_reply_create(NULL, &pbuf_list, &tstats_list,
                                     &xid_header);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (channel)");

  ret = ofp_table_stats_reply_create(channel, NULL, &tstats_list,
                                     &xid_header);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (pbuf)");

  ret = ofp_table_stats_reply_create(channel, &pbuf_list, NULL, &xid_header);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (ofp_table_stats_list)");

  ret = ofp_table_stats_reply_create(channel, &pbuf_list, &tstats_list,
                                     NULL);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (xid_header)");

  channel_free(channel);
}
void
test_quit (void)
{
    const gchar *packet;
    gsize packet_size;

    test_end_of_message_without_chunk();
    channel_free();

    reply_continue();

    cut_assert_true(milter_server_context_quit(context));
    pump_all_events();
    milter_test_assert_state(QUIT);
    milter_test_assert_status(NOT_CHANGE);

    milter_command_encoder_encode_quit(encoder, &packet, &packet_size);
    milter_test_assert_packet(channel, packet, packet_size);

    cut_assert_equal_uint(1, n_message_processed);
    milter_test_assert_result("*****@*****.**",
                              RECIPIENTS("*****@*****.**", NULL),
                              HEADERS("X-HEADER-NAME",
                                      "MilterServerContext test",
                                      NULL),
                              20,
                              STATE(END_OF_MESSAGE_REPLIED),
                              STATUS(NOT_CHANGE),
                              HEADERS(NULL),
                              HEADERS(NULL),
                              FALSE);
}
void
test_ofp_queue_get_config_handle_null(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct channel *channel = channel_alloc_ip4addr("127.0.0.1", "1000", 0x01);
  struct pbuf *pbuf = pbuf_alloc(65535);
  struct ofp_header ofp_header;
  struct ofp_error error;

  ret = ofp_queue_get_config_request_handle(NULL, pbuf, &ofp_header, &error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (channel)");

  ret = ofp_queue_get_config_request_handle(channel, NULL, &ofp_header, &error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (pbuf)");

  ret = ofp_queue_get_config_request_handle(channel, pbuf, NULL, &error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (ofp_header)");

  ret = ofp_queue_get_config_request_handle(channel, pbuf, &ofp_header, NULL);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (ofp_error)");
  channel_free(channel);
  pbuf_free(pbuf);
}
示例#7
0
static Channel *
server_request_session(void)
{
	Channel *c;

	debug("input_session_request");
	packet_check_eom();

	if (no_more_sessions) {
		packet_disconnect("Possible attack: attempt to open a session "
		    "after additional sessions disabled");
	}

	/*
	 * A server session has no fd to read or write until a
	 * CHANNEL_REQUEST for a shell is made, so we set the type to
	 * SSH_CHANNEL_LARVAL.  Additionally, a callback for handling all
	 * CHANNEL_REQUEST messages is registered.
	 */
	c = channel_new("session", SSH_CHANNEL_LARVAL,
	    -1, -1, -1, /*window size*/0, CHAN_SES_PACKET_DEFAULT,
	    0, "server-session", 1);
	if (session_open(the_authctxt, c->self) != 1) {
		debug("session open failed, free channel %d", c->self);
		channel_free(c);
		return NULL;
	}
	channel_register_cleanup(c->self, session_close_by_channel, 0);
	return c;
}
void
test_ofp_barrier_reply_create_null(void) {
  lagopus_result_t ret;
  struct barrier barrier;
  struct event_manager *em = event_manager_alloc();
  struct channel *channel =
    channel_alloc_ip4addr("127.0.0.1", "1000", em, 0x01);
  struct pbuf *pbuf;

  ret = ofp_barrier_reply_create(NULL, &barrier,
                                 &pbuf);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_INVALID_ARGS,
                            "ofp_barrier_reply_create error.");

  ret = ofp_barrier_reply_create(channel, NULL,
                                 &pbuf);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_INVALID_ARGS,
                            "ofp_barrier_reply_create error.");

  ret = ofp_barrier_reply_create(channel, &barrier,
                                 NULL);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_INVALID_ARGS,
                            "ofp_barrier_reply_create error.");
  /* after. */
  channel_free(channel);
  event_manager_free(em);
}
void
test_ofp_role_request_handle_with_null_agument(void) {
  /* Case of invlid argument.*/
  struct channel *channel =
    channel_alloc_ip4addr("127.0.0.1", "1000", 0x01);
  struct pbuf pbuf;
  struct ofp_header xid_header;
  lagopus_result_t ret;
  struct ofp_error error;

  /* struct ofp_error error; */
  ret = ofp_role_request_handle(NULL, &pbuf, &xid_header, &error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL should be treated as invalid arguments");
  ret = ofp_role_request_handle(channel, NULL, &xid_header, &error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL should be treated as invalid arguments");
  ret = ofp_role_request_handle(channel, &pbuf, NULL, &error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL should be treated as invalid arguments");
  ret = ofp_role_request_handle(channel, &pbuf, &xid_header, NULL);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL should be treated as invalid arguments");

  channel_free(channel);
}
void
test_ofp_get_async_request_handle_invalid_argument(void) {
  /* Case of invalid argument.*/
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct event_manager *em = event_manager_alloc();
  struct channel *channel = channel_alloc_ip4addr("127.0.0.1", "1000",
                            em, 0x01);
  struct pbuf *pbuf = pbuf_alloc(65535);
  struct ofp_header xid_header;
  struct ofp_error ignored_error = {0, 0, {NULL}};

  ret = ofp_get_async_request_handle(NULL, pbuf, &xid_header, &ignored_error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL checking is requred.");

  ret = ofp_get_async_request_handle(channel, NULL, &xid_header,
                                     &ignored_error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL checking is requred.");

  ret = ofp_get_async_request_handle(channel, pbuf, NULL, &ignored_error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL checking is requred.");

  ret = ofp_get_async_request_handle(channel, pbuf, &xid_header, NULL);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL checking is requred.");

  channel_free(channel);
  pbuf_free(pbuf);
  event_manager_free(em);
}
示例#11
0
static Channel *
server_request_session(struct ssh *ssh)
{
	Channel *c;
	int r;

	debug("input_session_request");
	if ((r = sshpkt_get_end(ssh)) != 0)
		fatal("%s: %s", __func__, ssh_err(r));

	if (no_more_sessions) {
		ssh_packet_disconnect(ssh,
		    "Possible attack: attempt to open a session "
		    "after additional sessions disabled");
	}

	/*
	 * A server session has no fd to read or write until a
	 * CHANNEL_REQUEST for a shell is made, so we set the type to
	 * SSH_CHANNEL_LARVAL.  Additionally, a callback for handling all
	 * CHANNEL_REQUEST messages is registered.
	 */
	c = channel_new(ssh, "session", SSH_CHANNEL_LARVAL,
	    -1, -1, -1, /*window size*/0, CHAN_SES_PACKET_DEFAULT,
	    0, "server-session", 1);
	if (session_open(ssh, c->self) != 1) {
		debug("session open failed, free channel %d", c->self);
		channel_free(c);
		return NULL;
	}
	channel_register_cleanup(c->self, session_close_by_channel, 0);
	return c;
}
void
test_ofp_group_mod_handle_wrap_null(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct event_manager *em = event_manager_alloc();
  struct channel *channel = channel_alloc_ip4addr("127.0.0.1", "1000",
                            em, 0x01);
  struct pbuf *pbuf = pbuf_alloc(65535);
  struct ofp_header xid_header;
  struct ofp_error error;

  ret = ofp_group_mod_handle(NULL, pbuf, &xid_header, &error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (channel)");

  ret = ofp_group_mod_handle(channel, NULL, &xid_header, &error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (pbuf)");

  ret = ofp_group_mod_handle(channel, pbuf, NULL, &error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (xid_header)");

  ret = ofp_group_mod_handle(channel, pbuf, &xid_header, NULL);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (xid_header)");

  channel_free(channel);
  pbuf_free(pbuf);
  event_manager_free(em);
}
void
test_ofp_role_reply_create_with_null_agument(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct channel *channel =
    channel_alloc_ip4addr("127.0.0.1", "1000", 0x01);
  struct pbuf *pbuf;
  struct ofp_header xid_header;
  struct ofp_role_request role_request;
  role_request.role = OFPCR_ROLE_SLAVE;
  role_request.generation_id = 0x01;

  /* TODO add error as a 4th argument */
  /* struct ofp_error error; */
  ret = ofp_role_reply_create(NULL, &pbuf, &xid_header, &role_request);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL should be treated as invalid arguments");
  ret = ofp_role_reply_create(channel, NULL, &xid_header, &role_request);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL should be treated as invalid arguments");
  ret = ofp_role_reply_create(channel, &pbuf, NULL, &role_request);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL should be treated as invalid arguments");

  channel_free(channel);
}
void
test_ofp_queue_get_config_reply_create_null(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct channel *channel = channel_alloc_ip4addr("127.0.0.1", "1000", 0x01);
  struct pbuf *pbuf = pbuf_alloc(65535);
  static struct packet_queue_list packet_queue_list;
  struct ofp_header ofp_header;

  ret = ofp_queue_get_config_reply_create(NULL, &pbuf, 0,
                                          &packet_queue_list,
                                          &ofp_header);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (channel)");

  ret = ofp_queue_get_config_reply_create(channel, NULL, 0,
                                          &packet_queue_list,
                                          &ofp_header);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (pbuf)");

  ret = ofp_queue_get_config_reply_create(channel, &pbuf, 0,
                                          NULL, &ofp_header);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (packet_queue_list)");

  ret = ofp_queue_get_config_reply_create(channel, &pbuf, 0,
                                          &packet_queue_list,
                                          NULL);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "NULL-check error. (ofp_header)");

  channel_free(channel);
  pbuf_free(pbuf);
}
示例#15
0
void
test_ofp_queue_stats_request_handle_null(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct pbuf *pbuf = pbuf_alloc(65535);
  struct ofp_header xid_header;
  struct ofp_error error;
  struct channel *channel = channel_alloc_ip4addr("127.0.0.1", "1000", 0x01);

  ret = ofp_queue_stats_request_handle(NULL, pbuf, &xid_header, &error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "ofp_queue_stats_request_handle error.");

  ret = ofp_queue_stats_request_handle(channel, NULL, &xid_header, &error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "ofp_queue_stats_request_handle error.");

  ret = ofp_queue_stats_request_handle(channel, pbuf, NULL, &error);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "ofp_queue_stats_request_handle error.");

  ret = ofp_queue_stats_request_handle(channel, pbuf, &xid_header, NULL);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "ofp_queue_stats_request_handle error.");

  /* after. */
  channel_free(channel);
  pbuf_free(pbuf);
}
void
test_abort_and_quit (void)
{
    const gchar *packet;
    gsize packet_size;

    test_envelope_recipient();
    channel_free();

    cut_assert_true(milter_server_context_abort(context));
    pump_all_events();
    milter_test_assert_state(ABORT);
    milter_test_assert_status(ABORT);

    cut_assert_true(milter_server_context_quit(context));
    pump_all_events();
    milter_test_assert_state(QUIT);
    milter_test_assert_status(ABORT);

    milter_command_encoder_encode_abort(encoder, &packet, &packet_size);
    packet_string = g_string_new_len(packet, packet_size);

    milter_command_encoder_encode_quit(encoder, &packet, &packet_size);
    g_string_append_len(packet_string, packet, packet_size);

    milter_test_assert_packet(channel, packet_string->str, packet_string->len);
}
示例#17
0
文件: scp.c 项目: CUEBoxer/OpenStudio
int ssh_scp_close(ssh_scp scp){
  char buffer[128];
  int err;
  if(scp->channel != NULL){
    if(channel_send_eof(scp->channel) == SSH_ERROR){
      scp->state=SSH_SCP_ERROR;
      return SSH_ERROR;
    }
    /* avoid situations where data are buffered and
     * not yet stored on disk. This can happen if the close is sent
     * before we got the EOF back
     */
    while(!channel_is_eof(scp->channel)){
      err=channel_read(scp->channel,buffer,sizeof(buffer),0);
      if(err==SSH_ERROR)
        break;
    }
    if(channel_close(scp->channel) == SSH_ERROR){
      scp->state=SSH_SCP_ERROR;
      return SSH_ERROR;
    }
    channel_free(scp->channel);
    scp->channel=NULL;
  }
  scp->state=SSH_SCP_NEW;
  return SSH_OK;
}
示例#18
0
文件: eventloop.c 项目: alco90/soml
/** Remove channels from monitoring of the EventLoop.
 *
 * The EventLoop calls this function on its own when sockets have been released
 * using eventloop_socket_release(). You probably want to use that one instead.
 *
 * \param source SockEvtSource to remove and free
 * \see eventloop_socket_release, channel_free
 */
void eventloop_socket_remove(SockEvtSource* source)
{
  Channel* ch = (Channel*)source;

  eventloop_socket_activate(source, 0);

  /* Update the linked list */
  if (self.channels == ch) {
    self.channels = ch->next;

  } else {
    Channel* prev = self.channels;
    Channel* p = prev->next;

    while (p != NULL) {
      if (p == ch) {
        prev->next = ch->next;
        p = NULL; /* We're done */
      } else {
        prev = p;
        p = p->next;
      }
    }
  }

  channel_free(ch);
}
void
test_ofp_experimenter_reply_create_null(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct pbuf *pbuf = pbuf_alloc(65535);
  struct ofp_header xid_header;
  struct event_manager *em = event_manager_alloc();
  struct channel *channel = channel_alloc_ip4addr("127.0.0.1", "1000",
                            em, 0x01);
  struct ofp_experimenter_header exper_req;

  ret = ofp_experimenter_reply_create(NULL, &pbuf, &xid_header, &exper_req);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "ofp_experimenter_reply_create error.");

  ret = ofp_experimenter_reply_create(channel, NULL, &xid_header, &exper_req);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "ofp_experimenter_reply_create error.");

  ret = ofp_experimenter_reply_create(channel, &pbuf, NULL, &exper_req);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "ofp_experimenter_reply_create error.");

  ret = ofp_experimenter_reply_create(channel, &pbuf, &xid_header, NULL);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret,
                            "ofp_experimenter_reply_create error.");

  /* after. */
  channel_free(channel);
  event_manager_free(em);
  pbuf_free(pbuf);
}
示例#20
0
/** Test destroy cell queue with no interference from other queues. */
static void
test_cmux_destroy_cell_queue(void *arg)
{
  circuitmux_t *cmux = NULL;
  channel_t *ch = NULL;
  circuit_t *circ = NULL;
  cell_queue_t *cq = NULL;
  packed_cell_t *pc = NULL;
  tor_libevent_cfg cfg;

  memset(&cfg, 0, sizeof(cfg));

  tor_libevent_initialize(&cfg);
  scheduler_init();

#ifdef ENABLE_MEMPOOLS
  init_cell_pool();
#endif /* ENABLE_MEMPOOLS */
  (void) arg;

  cmux = circuitmux_alloc();
  tt_assert(cmux);
  ch = new_fake_channel();
  ch->has_queued_writes = has_queued_writes;
  ch->wide_circ_ids = 1;

  circ = circuitmux_get_first_active_circuit(cmux, &cq);
  tt_assert(!circ);
  tt_assert(!cq);

  circuitmux_append_destroy_cell(ch, cmux, 100, 10);
  circuitmux_append_destroy_cell(ch, cmux, 190, 6);
  circuitmux_append_destroy_cell(ch, cmux, 30, 1);

  tt_int_op(circuitmux_num_cells(cmux), OP_EQ, 3);

  circ = circuitmux_get_first_active_circuit(cmux, &cq);
  tt_assert(!circ);
  tt_assert(cq);

  tt_int_op(cq->n, OP_EQ, 3);

  pc = cell_queue_pop(cq);
  tt_assert(pc);
  tt_mem_op(pc->body, OP_EQ, "\x00\x00\x00\x64\x04\x0a\x00\x00\x00", 9);
  packed_cell_free(pc);
  pc = NULL;

  tt_int_op(circuitmux_num_cells(cmux), OP_EQ, 2);

 done:
  circuitmux_free(cmux);
  channel_free(ch);
  packed_cell_free(pc);

#ifdef ENABLE_MEMPOOLS
  free_cell_pool();
#endif /* ENABLE_MEMPOOLS */
}
示例#21
0
文件: scp.c 项目: CUEBoxer/OpenStudio
void ssh_scp_free(ssh_scp scp){
  if(scp->state != SSH_SCP_NEW)
    ssh_scp_close(scp);
  if(scp->channel)
    channel_free(scp->channel);
  SAFE_FREE(scp->location);
  SAFE_FREE(scp->request_name);
  SAFE_FREE(scp->warning);
  SAFE_FREE(scp);
}
示例#22
0
void
remmina_nx_session_free (RemminaNXSession *nx)
{
    pthread_t thread;

    if (nx->proxy_watch_source)
    {
        g_source_remove (nx->proxy_watch_source);
        nx->proxy_watch_source = 0;
    }
    if (nx->proxy_pid)
    {
        kill (nx->proxy_pid, SIGTERM);
        g_spawn_close_pid (nx->proxy_pid);
        nx->proxy_pid = 0;
    }
    thread = nx->thread;
    if (thread)
    {
        nx->running = FALSE;
        pthread_cancel (thread);
        pthread_join (thread, NULL);
        nx->thread = 0;
    }
    if (nx->channel)
    {
        channel_close (nx->channel);
        channel_free (nx->channel);
    }
    if (nx->server_sock >= 0)
    {
        close (nx->server_sock);
        nx->server_sock = -1;
    }

    g_free (nx->server);
    g_free (nx->error);
    g_hash_table_destroy (nx->session_parameters);
    g_string_free (nx->response, TRUE);
    g_free (nx->version);
    g_free (nx->session_id);
    g_free (nx->proxy_cookie);

    if (nx->session_list)
    {
        g_object_unref (nx->session_list);
        nx->session_list = NULL;
    }
    if (nx->session)
    {
        ssh_free (nx->session);
        nx->session = NULL;
    }
    g_free (nx);
}
示例#23
0
static void
s_destroy_channel(struct channel *channel) {
  if (channel != NULL) {
    lagopus_result_t ret;
    ret = channel_free(channel);
    if (ret != LAGOPUS_RESULT_OK) {
      lagopus_msg_fatal("channel_free error (%s)\n",
                        lagopus_error_get_string(ret));
    }
  }
}
示例#24
0
static void
remmina_ssh_tunnel_remove_channel (RemminaSSHTunnel *tunnel, gint n)
{
	channel_close (tunnel->channels[n]);
	channel_free (tunnel->channels[n]);
	close (tunnel->sockets[n]);
	remmina_ssh_tunnel_buffer_free (tunnel->socketbuffers[n]);
	tunnel->num_channels--;
	tunnel->channels[n] = tunnel->channels[tunnel->num_channels];
	tunnel->channels[tunnel->num_channels] = NULL;
	tunnel->sockets[n] = tunnel->sockets[tunnel->num_channels];
	tunnel->socketbuffers[n] = tunnel->socketbuffers[tunnel->num_channels];
}
void
test_connect_with_macro (void)
{
    struct sockaddr_in address;
    const gchar host_name[] = "mx.local.net";
    const gchar ip_address[] = "192.168.123.123";
    guint16 port;
    const gchar *packet;
    gsize packet_size;

    test_negotiate();
    channel_free();

    reply_negotiate();

    port = g_htons(50443);
    address.sin_family = AF_INET;
    address.sin_port = port;
    inet_pton(AF_INET, ip_address, &(address.sin_addr));

    macros = gcut_hash_table_string_string_new("G", "g",
                                               "N", "n",
                                               "U", "u",
                                               NULL);
    milter_protocol_agent_set_macros_hash_table(MILTER_PROTOCOL_AGENT(context),
                                                MILTER_COMMAND_CONNECT,
                                                macros);
    milter_command_encoder_encode_define_macro(encoder,
                                               &packet, &packet_size,
                                               MILTER_COMMAND_CONNECT,
                                               macros);
    cut_assert_true(milter_server_context_connect(context, host_name,
                                                  (struct sockaddr *)&address,
                                                  sizeof(address)));
    pump_all_events();
    milter_test_assert_state(CONNECT);
    milter_test_assert_status(NOT_CHANGE);

    packet_string = g_string_new_len(packet, packet_size);
    milter_command_encoder_encode_connect(encoder,
                                          &packet, &packet_size,
                                          host_name,
                                          (const struct sockaddr *)&address,
                                          sizeof(address));
    g_string_append_len(packet_string, packet, packet_size);
    milter_test_assert_packet(channel, packet_string->str, packet_string->len);

    cut_assert_equal_uint(0, n_message_processed);
}
示例#26
0
// Connect to a SSH server.
// When the connection is established, read data from stdin and send it to the server.
void client_pipe(char *host, int port)
{
    ssh_session s = ssh_new();
    ssh_options_set(s, SSH_OPTIONS_HOST, host);
    ssh_options_set(s, SSH_OPTIONS_PORT, &port);
    ssh_options_set(s, SSH_OPTIONS_USER, "xya");
    //ssh_options_set(s, SSH_OPTIONS_LOG_VERBOSITY_STR, "5");
    if(ssh_connect(s) != SSH_OK)
        return session_error(s, "connect");
    
    char *hash = pubkey_hash(ssh_get_pubkey(s));
    if(authenticate(hash, 0))
    {
        session_event(s, "authenticated", hash);
        free(hash);
    }
    else
    {
        free(hash);
        exit(1);
    }
    
    int keytype;
    ssh_string pub = publickey_from_file(s, "test-client-key.pub", &keytype);
    if(!pub)
        session_error(s, "open-public-key");
    if(SSH_AUTH_SUCCESS != ssh_userauth_offer_pubkey(s, NULL, keytype, pub))
        session_error(s, "offer-public-key");
    
    ssh_private_key priv = privatekey_from_file(s, "test-client-key", keytype, NULL);
    if(!priv)
        session_error(s, "open-private-key");
    if(SSH_AUTH_SUCCESS != ssh_userauth_pubkey(s, NULL, pub, priv))
        session_error(s, "user-auth");
    string_free(pub);
    privatekey_free(priv);
    
    ssh_channel chan = channel_new(s);
    if(!chan)
        session_error(s, "create-channel");
    if(channel_open_session(chan) < 0)
        session_error(s, "open-channel");
    session_event(s, "channel-opened", NULL);
    channel_from_file(chan, 0);
    channel_free(chan);
    ssh_disconnect(s);
    ssh_finalize();
}
示例#27
0
static void do_lost_connection(struct channel_t* channel)
{
	UT_VERIFY_TRUE(0 != channel);
	UT_VERIFY_TRUE(0 != channel->net);
	/*通知回调函数,连接断开*/
	channel->net->lost_func(channel->net, channel->index, channel->net->net_data, channel->channel_data);
	/*关闭socket句柄*/
	sock_close(channel->sock);
	channel->sock = -1;
	/*释放通道资源*/
	channel_free(channel->net, channel);
	/*从epoll中删除*/
	epoll_ctl(channel->net->epoll_handle, EPOLL_CTL_DEL, channel->sock, 0);

FAIL:
	return;
}
void
test_abort (void)
{
    const gchar *packet;
    gsize packet_size;

    test_body();
    channel_free();

    cut_assert_true(milter_server_context_abort(context));
    pump_all_events();
    milter_test_assert_state(ABORT);
    milter_test_assert_status(ABORT);

    milter_command_encoder_encode_abort(encoder, &packet, &packet_size);
    milter_test_assert_packet(channel, packet, packet_size);
}
示例#29
0
static lagopus_result_t
channel_delete_internal(const char *key) {
  lagopus_result_t ret;
  struct channel *chan;

  ret = lagopus_hashmap_find(&main_table, (void *)key, (void **)&chan);
  if (ret != LAGOPUS_RESULT_OK) {
    return ret;
  }

  channel_disable(chan);

  ret = channel_free(chan);
  if (ret != LAGOPUS_RESULT_OK) {
    return ret;
  }

  return lagopus_hashmap_delete(&main_table, (void *)key, NULL, false);
}
示例#30
0
文件: packet.c 项目: JabirTech/Source
void
packet_free(packet_t *pkt)
{
	exthdr_t *eh;

	if (pkt->refcnt-- > 0)
		return;

	while ((eh = STAILQ_FIRST(&pkt->extlist)) != NULL) {
		STAILQ_REMOVE_HEAD(&pkt->extlist, next);
		free(eh);
	}

	pkt->chan->refcnt--;
	if (pkt->chan->refcnt == 0)
		channel_free(pkt->chan);

	free(pkt);
}