示例#1
0
static void client_destroy(struct client *client)
{
	char **app;

	i_set_failure_prefix("imap-urlauth[%s](%s): ",
			     my_pid, client->access_user);

	if (client->url != NULL) {
		/* deinitialize url */
		i_stream_close(client->input);
		o_stream_close(client->output);
		(void)client_run_url(client);
		i_assert(client->url == NULL);
	}

	imap_urlauth_worker_client_count--;
	DLLIST_REMOVE(&imap_urlauth_worker_clients, client);

	if (client->urlauth_ctx != NULL)
		imap_urlauth_deinit(&client->urlauth_ctx);

	if (client->mail_user != NULL)
		mail_user_unref(&client->mail_user);

	if (client->io != NULL)
		io_remove(&client->io);
	if (client->ctrl_io != NULL)
		io_remove(&client->ctrl_io);
	if (client->to_idle != NULL)
		timeout_remove(&client->to_idle);

	if (client->input != NULL)
		i_stream_destroy(&client->input);
	if (client->output != NULL)
		o_stream_destroy(&client->output);

	if (client->ctrl_input != NULL)
		i_stream_destroy(&client->ctrl_input);
	if (client->ctrl_output != NULL)
		o_stream_destroy(&client->ctrl_output);

	if (client->fd_in >= 0)
		net_disconnect(client->fd_in);
	if (client->fd_out >= 0 && client->fd_in != client->fd_out)
		net_disconnect(client->fd_out);
	if (client->fd_ctrl >= 0)
		net_disconnect(client->fd_ctrl);

	if (client->service_user != NULL)
		mail_storage_service_user_free(&client->service_user);
	i_free(client->access_user);
	array_foreach_modifiable(&client->access_apps, app)
		i_free(*app);
	array_free(&client->access_apps);
	i_free(client);

	imap_urlauth_worker_refresh_proctitle();
	master_service_client_connection_destroyed(master_service);
}
示例#2
0
/**
 * connect to server and returns the socket
 */
socket_t net_connect(const char *server_name, int server_port) {
  socket_t sock;
  uint32_t inaddr;
  struct sockaddr_in ad;

  net_init();

  memset(&ad, 0, sizeof(ad));
  ad.sin_family = AF_INET;

  if ((inaddr = inet_addr(server_name)) == INADDR_NONE) {
    struct hostent *hp = gethostbyname(server_name);
    if (hp == NULL) {
      return -1;
    }
    memcpy(&ad.sin_addr, hp->h_addr, hp->h_length);
  } else {
    memcpy(&ad.sin_addr, &inaddr, sizeof(inaddr));
  }

  ad.sin_port = htons(server_port);
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock <= 0) {
    return sock;
  }
  if (connect(sock, (struct sockaddr *)&ad, sizeof(ad)) < 0) {
    net_disconnect(sock);
    return -1;
  }
  return sock;
}
void auth_client_connection_destroy(struct auth_client_connection **_conn)
{
        struct auth_client_connection *conn = *_conn;

	*_conn = NULL;
	if (conn->fd == -1)
		return;

	DLLIST_REMOVE(&auth_client_connections, conn);

	i_stream_close(conn->input);
	o_stream_close(conn->output);

	if (conn->io != NULL)
		io_remove(&conn->io);

	net_disconnect(conn->fd);
	conn->fd = -1;

	if (conn->request_handler != NULL) {
		auth_request_handler_abort_requests(conn->request_handler);
		auth_request_handler_destroy(&conn->request_handler);
	}

        master_service_client_connection_destroyed(master_service);
        auth_client_connection_unref(&conn);
}
示例#4
0
文件: dcc-chat.c 项目: irssi/irssi
/* input function: DCC CHAT - someone tried to connect to our socket */
static void dcc_chat_listen(CHAT_DCC_REC *dcc)
{
	IPADDR ip;
        GIOChannel *handle;
	int port;

	g_return_if_fail(IS_DCC_CHAT(dcc));

	/* accept connection */
	handle = net_accept(dcc->handle, &ip, &port);
	if (handle == NULL)
		return;

	/* TODO: add paranoia check - see dcc-files.c */

	net_disconnect(dcc->handle);
	g_source_remove(dcc->tagconn);
	dcc->tagconn = -1;

	dcc->starttime = time(NULL);
	dcc->handle = handle;
	dcc->sendbuf = net_sendbuffer_create(handle, 0);
	memcpy(&dcc->addr, &ip, sizeof(IPADDR));
	net_ip2host(&dcc->addr, dcc->addrstr);
	dcc->port = port;
	dcc->tagread = g_input_add(handle, G_INPUT_READ,
				   (GInputFunction) dcc_chat_input, dcc);

	signal_emit("dcc connected", 1, dcc);
}
示例#5
0
static void connect_downlink(BOTNET_REC *botnet, int handle,
			     IPADDR *ip, const char *host)
{
	BOT_DOWNLINK_REC *downlink;
	BOT_REC *bot;

	g_return_if_fail(botnet != NULL);

	/* identify the bot who's trying to connect.. */
	downlink = bot_downlink_find(botnet, ip, host);
	if (downlink == NULL || downlink->password == NULL) {
		/* unknown bot, close connection /
		   bot didn't have password, don't let it connect to us */
		net_disconnect(handle);
		return;
	}

	bot = g_new0(BOT_REC, 1);
	bot->botnet = botnet;
	bot->link = downlink;
	g_node_append_data(botnet->bots, bot);

	/* connected.. */
	bot->handle = handle;
	bot->read_tag = g_input_add(handle, G_INPUT_READ, (GInputFunction) sig_bot_read, bot);
}
示例#6
0
/* input function: DCC SEND - someone tried to connect to our socket */
static void dcc_send_connected(SEND_DCC_REC *dcc)
{
        GIOChannel *handle;
	IPADDR addr;
	int port;

	/* accept connection */
	handle = net_accept(dcc->handle, &addr, &port);
	if (handle == NULL)
		return;

	/* TODO: some kind of paranoia check would be nice. it would check
	   that the host of the nick who we sent the request matches the
	   address who connected us. */

	net_disconnect(dcc->handle);
	g_source_remove(dcc->tagconn);
        dcc->tagconn = -1;

	dcc->starttime = time(NULL);
	dcc->handle = handle;
	memcpy(&dcc->addr, &addr, sizeof(IPADDR));
	net_ip2host(&dcc->addr, dcc->addrstr);
	dcc->port = port;

	dcc->tagread = g_input_add(handle, G_INPUT_READ,
				   (GInputFunction) dcc_send_read_size, dcc);
	dcc->tagwrite = g_input_add(handle, G_INPUT_WRITE,
				    (GInputFunction) dcc_send_data, dcc);

	signal_emit("dcc connected", 1, dcc);
}
示例#7
0
void lmtp_client_close(struct lmtp_client *client)
{
	if (client->dns_lookup != NULL)
		dns_lookup_abort(&client->dns_lookup);
	if (client->to != NULL)
		timeout_remove(&client->to);
	if (client->io != NULL)
		io_remove(&client->io);
	if (client->input != NULL)
		i_stream_close(client->input);
	if (client->output != NULL)
		o_stream_close(client->output);
	if (client->fd != -1) {
		net_disconnect(client->fd);
		client->fd = -1;
	}
	if (client->data_input != NULL)
		i_stream_unref(&client->data_input);
	client->output_finished = TRUE;

	if (!client->finish_called) {
		client->finish_called = TRUE;
		client->finish_callback(client->finish_context);
	}
}
/*---------------------------------------------------------------------*/
BOOL  net_tcp_connect_to_host   (Network* self, char* ip_address, int port)
{
  int error;

  if(self->file_descriptor != -1) net_disconnect(self);

  error = self->local_file_descriptor = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  if(error == -1)
    {
      perror("Unable to create a TCP socket");
      goto out;
    }

  self->remote_port = port;
  net_init_remote_port(self, port);
  inet_pton(AF_INET, ip_address, &(self->remote_address.sin_addr));
  error = connect(self->local_file_descriptor, (struct sockaddr* )&self->remote_address, 
                  self->remote_address_length);
  if(error == -1)
    {
      perror("Unable to connect to a remote host");
      goto out;
    }
  self->file_descriptor = self->local_file_descriptor;

 out:
  return (error == -1) ? 0 : 1;
}
示例#9
0
文件: switch.c 项目: duthils/netvirt
static void on_input(netc_t *netc)
{
	DNDSMessage_t *msg;
	struct session *session;
	mbuf_t **mbuf_itr;
	pdu_PR pdu;

	mbuf_itr = &netc->queue_msg;
	session = (struct session *)netc->ext_ptr;
	if (session->state == SESSION_STATE_PURGE) {
		jlog(L_NOTICE, "purge node: %s", session->cert_name);
		net_disconnect(netc);
		return;
	}

	while (*mbuf_itr != NULL) {
		msg = (DNDSMessage_t *)(*mbuf_itr)->ext_buf;
		DNDSMessage_get_pdu(msg, &pdu);

		switch (pdu) {
		case pdu_PR_dnm:	/* DNDS protocol */
			dispatch_operation(session, msg);
			break;
		case pdu_PR_ethernet:	/* Ethernet */
			forward_ethernet(session, msg);
			break;
		default:
			/* TODO disconnect session */
			jlog(L_ERROR, "invalid PDU");
			break;
		}
		mbuf_del(mbuf_itr, *mbuf_itr);
	}
}
示例#10
0
文件: dcc.c 项目: svn2github/irssi
/* Destroy DCC record */
void dcc_destroy(DCC_REC *dcc)
{
	g_return_if_fail(dcc != NULL);
	if (dcc->destroyed) return;

	dcc_conns = g_slist_remove(dcc_conns, dcc);
	dcc_remove_chat_refs(dcc);

	dcc->destroyed = TRUE;
	signal_emit("dcc destroyed", 1, dcc);

	if (dcc->fhandle != -1) close(dcc->fhandle);
	if (dcc->handle != -1) net_disconnect(dcc->handle);
	if (dcc->tagread != -1) g_source_remove(dcc->tagread);
	if (dcc->tagwrite != -1) g_source_remove(dcc->tagwrite);

	if (dcc->type == DCC_TYPE_CHAT)
		line_split_free((LINEBUF_REC *) dcc->databuf);
	else if (dcc->databuf != NULL)
		g_free(dcc->databuf);

	g_free_not_null(dcc->file);
	g_free_not_null(dcc->ircnet);
	g_free(dcc->mynick);
	g_free(dcc->nick);
	g_free(dcc->arg);
	g_free(dcc);
}
示例#11
0
文件: login-proxy.c 项目: bjacke/core
static void login_proxy_disconnect(struct login_proxy *proxy)
{
	if (proxy->to != NULL)
		timeout_remove(&proxy->to);
	if (proxy->to_notify != NULL)
		timeout_remove(&proxy->to_notify);

	if (!proxy->num_waiting_connections_updated) {
		i_assert(proxy->state_rec->num_waiting_connections > 0);
		proxy->state_rec->num_waiting_connections--;
	}
	if (proxy->connected) {
		i_assert(proxy->state_rec->num_proxying_connections > 0);
		proxy->state_rec->num_proxying_connections--;
	}

	if (proxy->server_io != NULL)
		io_remove(&proxy->server_io);
	if (proxy->server_input != NULL)
		i_stream_destroy(&proxy->server_input);
	if (proxy->server_output != NULL)
		o_stream_destroy(&proxy->server_output);
	if (proxy->server_fd != -1)
		net_disconnect(proxy->server_fd);
}
示例#12
0
static void login_proxy_free_final(struct login_proxy *proxy)
{
	if (proxy->delayed_disconnect) {
		DLLIST_REMOVE(&login_proxies_disconnecting, proxy);

		i_assert(proxy->state_rec->num_delayed_client_disconnects > 0);
		if (--proxy->state_rec->num_delayed_client_disconnects == 0)
			proxy->state_rec->num_disconnects_since_ts = 0;
		timeout_remove(&proxy->to);
	}

	if (proxy->client_io != NULL)
		io_remove(&proxy->client_io);
	if (proxy->client_input != NULL)
		i_stream_destroy(&proxy->client_input);
	if (proxy->client_output != NULL)
		o_stream_destroy(&proxy->client_output);
	if (proxy->client_fd != -1)
		net_disconnect(proxy->client_fd);
	if (proxy->ssl_server_proxy != NULL) {
		ssl_proxy_destroy(proxy->ssl_server_proxy);
		ssl_proxy_free(&proxy->ssl_server_proxy);
	}
	i_free(proxy->host);
	i_free(proxy);
}
示例#13
0
void master_login_auth_disconnect(struct master_login_auth *auth)
{
	struct master_login_auth_request *request;

	while (auth->request_head != NULL) {
		request = auth->request_head;
		DLLIST2_REMOVE(&auth->request_head,
			       &auth->request_tail, request);

		request_internal_failure(request,
			"Disconnected from auth server, aborting");
		i_free(request);
	}
	hash_table_clear(auth->requests, FALSE);

	if (auth->to != NULL)
		timeout_remove(&auth->to);
	if (auth->io != NULL)
		io_remove(&auth->io);
	if (auth->fd != -1) {
		i_stream_destroy(&auth->input);
		o_stream_destroy(&auth->output);

		net_disconnect(auth->fd);
		auth->fd = -1;
	}
	auth->version_received = FALSE;
}
示例#14
0
/*---------------------------------------------------------------------*/
BOOL net_udp_connect(Network* self, int receive_port)
{
  int error, b=1;

  if(self->file_descriptor != -1) net_disconnect(self);

  error = self->file_descriptor = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if(error == -1)
    {
      perror("unable to create a UDP socket\n"); 
      goto out;
    }

  self->remote_port = receive_port;
  error = net_bind_port(self->file_descriptor, (char*)"0.0.0.0", receive_port);
  if(error == -1)
    { 
      perror("unable to bind UDP socket\n");
      goto out;
    }
    
  error = setsockopt(self->file_descriptor, SOL_SOCKET, SO_BROADCAST, &b, sizeof(b));
    
 out:
  return (error == -1) ? NO : YES;
} 
示例#15
0
static void net_disconnect_remove(NET_DISCONNECT_REC *rec)
{
	disconnects = g_slist_remove(disconnects, rec);

	g_source_remove(rec->tag);
        net_disconnect(rec->handle);
	g_free(rec);
}
示例#16
0
void Runtime::debugStop() {
  if (g_debugee != -1) {
    net_print(g_debugee, "q\n");
    net_disconnect(g_debugee);
    g_debugee = -1;
    appLog("Closed debug session");
  }
}
示例#17
0
/*---------------------------------------------------------------------*/
Network*  net_destroy           (Network* self)
{
  if(self != NULL)
    {
      net_disconnect(self);
      free(self);
    }
  return (Network*) NULL;
}
示例#18
0
文件: listen.c 项目: svn2github/irssi
void remove_client(PLUGIN_DATA *data, CLIENT_REC *rec)
{
    data->clients = g_slist_remove(data->clients, rec);

    net_disconnect(rec->handle);
    g_source_remove(rec->tag);
    line_split_free(rec->buffer);
    g_free(rec);
}
示例#19
0
/* Destroy the buffer. `close' specifies if socket handle should be closed. */
void net_sendbuffer_destroy(NET_SENDBUF_REC *rec, int close)
{
	buffers = g_slist_remove(buffers, rec);

        if (rec->send_tag != -1) g_source_remove(rec->send_tag);
	if (close) net_disconnect(rec->handle);
	g_free_not_null(rec->buffer);
	g_free(rec);
}
示例#20
0
文件: listen.c 项目: svn2github/irssi
void plugin_proxy_listen_deinit(PLUGIN_DATA *data)
{
    g_return_if_fail(data != NULL);

    g_string_free(next_line, TRUE);
    while (data->clients != NULL)
        remove_client(data, data->clients->data);

    net_disconnect(data->listen_handle);
    g_source_remove(data->listen_tag);
}
示例#21
0
static void replicator_connection_disconnect(struct replicator_connection *conn)
{
	if (conn->fd == -1)
		return;

	replicator_abort_all_requests(conn);
	io_remove(&conn->io);
	i_stream_destroy(&conn->input);
	o_stream_destroy(&conn->output);
	net_disconnect(conn->fd);
	conn->fd = -1;
}
示例#22
0
static void remove_listen(LISTEN_REC *rec)
{
	proxy_listens = g_slist_remove(proxy_listens, rec);

	while (rec->clients != NULL)
		remove_client(rec->clients->data);

	net_disconnect(rec->handle);
	g_source_remove(rec->tag);
	g_free(rec->ircnet);
	g_free(rec);
}
示例#23
0
static void on_connect(netc_t *netc)
{
	struct session *session;
	session = session_new();

	if (session == NULL) {
		net_disconnect(netc);
		return;
	}

	session->netc = netc;
	netc->ext_ptr = session;
}
示例#24
0
文件: net.c 项目: bensteinberg/aleph
// disconnect from parameters
void net_disconnect_params(void) {
  int i;
  int j;
  int t = net->numIns; // test target
  for(i=0; i<net->numParams; ++i) {
    for(j=0; j<net->numOuts; ++j) {
      if(net->outs[j].target == t) {
	net_disconnect(j);
      }
    }
    t++;
  }
}
示例#25
0
static int ssl_proxy_destroy(struct ssl_proxy *proxy)
{
	if (--proxy->refcount > 0)
		return TRUE;

	hash_table_remove(ssl_proxies, proxy);

	gnutls_deinit(proxy->session);

	if (proxy->io_ssl != NULL)
		io_remove(proxy->io_ssl);
	if (proxy->io_plain != NULL)
		io_remove(proxy->io_plain);

	(void)net_disconnect(proxy->fd_ssl);
	(void)net_disconnect(proxy->fd_plain);

	i_free(proxy);

	main_unref();
	return FALSE;
}
示例#26
0
文件: main.c 项目: jkerihuel/dovecot
static void
client_connected_finish(const struct master_service_connection *conn)
{
	struct client *client;
	struct ssl_proxy *proxy;
	struct ip_addr local_ip;
	const struct login_settings *set;
	const struct master_service_ssl_settings *ssl_set;
	unsigned int local_port;
	pool_t pool;
	int fd_ssl;
	void **other_sets;

	if (net_getsockname(conn->fd, &local_ip, &local_port) < 0) {
		memset(&local_ip, 0, sizeof(local_ip));
		local_port = 0;
	}

	pool = pool_alloconly_create("login client", 8*1024);
	set = login_settings_read(pool, &local_ip,
				  &conn->remote_ip, NULL, &ssl_set, &other_sets);

	if (!ssl_connections && !conn->ssl) {
		client = client_create(conn->fd, FALSE, pool,
				       set, ssl_set, other_sets,
				       &local_ip, &conn->remote_ip);
	} else {
		fd_ssl = ssl_proxy_alloc(conn->fd, &conn->remote_ip, pool,
					 set, ssl_set, &proxy);
		if (fd_ssl == -1) {
			net_disconnect(conn->fd);
			pool_unref(&pool);
			master_service_client_connection_destroyed(master_service);
			return;
		}

		client = client_create(fd_ssl, TRUE, pool,
				       set, ssl_set, other_sets,
				       &local_ip, &conn->remote_ip);
		client->ssl_proxy = proxy;
		ssl_proxy_set_client(proxy, client);
		ssl_proxy_start(proxy);
	}

	client->real_remote_port = client->remote_port = conn->remote_port;
	client->real_local_port = client->local_port = local_port;

	if (auth_client_to != NULL)
		timeout_remove(&auth_client_to);
}
示例#27
0
文件: net.c 项目: doomglue/aleph
// destroy last operator created
s16 net_pop_op(void) {
  const s16 opIdx = net->numOps - 1;
  op_t* op = net->ops[opIdx];
  int i=0;
  int x, y;

  app_pause();
  // bail if system op
  if(net_op_flag (opIdx, eOpFlagSys)) { return 1; }
  // de-init
  op_deinit(op);
  // store the global index of the first input
  x = net_op_in_idx(opIdx, 0);
  y = x + op->numInputs;

  // check if anything connects here
  for(i=0; i<net->numOuts; i++) {
    // this check works b/c we know this is last op in list
    if( net->outs[i].target >= x ) {
      if( net->outs[i].target < y) {
	net_disconnect(i);
      } else {
	//	net->outs[i].target -= op->numInputs;
	net_connect(i, net->outs[i].target - op->numInputs); 
      }
    }
  }
  // erase input nodes
  while(x < y) {
    net_init_inode(x++);
  }
  // store the global index of the first output
  x = net_op_out_idx(opIdx, 0);
  y = x + op->numOutputs;
  // erase output nodes
  while(x < y) {
    net_init_onode(x++);
  }

  net->numIns -= op->numInputs;
  net->numOuts -= op->numOutputs;

  net->opPoolOffset -= op_registry[op->type].size;
  net->numOps -= 1;

  app_resume();
  return 0;

}
示例#28
0
文件: botnet.c 项目: svn2github/irssi
void bot_disconnect(BOT_REC *bot)
{
	bot->disconnect = TRUE;

	signal_emit("bot disconnected", 1, bot);

	if (bot->read_tag != -1) {
		g_source_remove(bot->read_tag);
		bot->read_tag = -1;
	}
	if (bot->handle != -1) {
		net_disconnect(bot->handle);
		bot->handle = -1;
	}
}
示例#29
0
static void sig_host_got(RESOLVED_NAME_REC *name, BOT_CONNECT_REC *rec)
{
	BOTNET_REC *botnet;

	botnet = botnet_find(rec->botnet);
	if (botnet == NULL || !botnet->connected) {
		/* this botnet isn't connected anymore.. */
		net_disconnect(rec->handle);
	} else {
		connect_downlink(botnet, rec->handle, &rec->ip,
				 name->error ? NULL : name->name);
	}
        g_free(rec->botnet);
	g_free(rec);
}
示例#30
0
文件: servers.c 项目: vague666/irssi
void server_connect_unref(SERVER_CONNECT_REC *conn)
{
    g_return_if_fail(IS_SERVER_CONNECT(conn));

    if (--conn->refcount > 0)
        return;
    if (conn->refcount < 0) {
        g_warning("Connection '%s' refcount = %d",
                  conn->tag, conn->refcount);
    }

    CHAT_PROTOCOL(conn)->destroy_server_connect(conn);

    if (conn->connect_handle != NULL)
        net_disconnect(conn->connect_handle);

    g_free_not_null(conn->proxy);
    g_free_not_null(conn->proxy_string);
    g_free_not_null(conn->proxy_string_after);
    g_free_not_null(conn->proxy_password);

    g_free_not_null(conn->tag);
    g_free_not_null(conn->address);
    g_free_not_null(conn->chatnet);

    g_free_not_null(conn->own_ip4);
    g_free_not_null(conn->own_ip6);

    g_free_not_null(conn->password);
    g_free_not_null(conn->nick);
    g_free_not_null(conn->username);
    g_free_not_null(conn->realname);

    g_free_not_null(conn->tls_cert);
    g_free_not_null(conn->tls_pkey);
    g_free_not_null(conn->tls_pass);
    g_free_not_null(conn->tls_cafile);
    g_free_not_null(conn->tls_capath);
    g_free_not_null(conn->tls_ciphers);
    g_free_not_null(conn->tls_pinned_cert);
    g_free_not_null(conn->tls_pinned_pubkey);

    g_free_not_null(conn->channels);
    g_free_not_null(conn->away_reason);

    conn->type = 0;
    g_free(conn);
}