Esempio n. 1
0
login_proxy_free_full(struct login_proxy **_proxy, const char *reason,
		      bool delayed)
{
	struct login_proxy *proxy = *_proxy;
	struct client *client = proxy->client;
	const char *ipstr;
	unsigned int delay_ms = 0;

	*_proxy = NULL;

	if (proxy->destroying)
		return;
	proxy->destroying = TRUE;

	/* we'll disconnect server side in any case. */
	login_proxy_disconnect(proxy);

	if (proxy->client_fd != -1) {
		/* detached proxy */
		DLLIST_REMOVE(&login_proxies, proxy);

		if (delayed)
			delay_ms = login_proxy_delay_disconnect(proxy);

		ipstr = net_ip2addr(&proxy->client->ip);
		client_log(proxy->client, t_strdup_printf(
			"proxy(%s): disconnecting %s%s%s",
			proxy->client->virtual_user,
			ipstr != NULL ? ipstr : "",
			reason == NULL ? "" : t_strdup_printf(" (%s)", reason),
			delay_ms == 0 ? "" : t_strdup_printf(" - disconnecting client in %ums", delay_ms)));

		if (proxy->client_io != NULL)
			io_remove(&proxy->client_io);
	} else {
		i_assert(proxy->client_io == NULL);
		i_assert(proxy->client_input == NULL);
		i_assert(proxy->client_output == NULL);
		i_assert(proxy->client_fd == -1);

		DLLIST_REMOVE(&login_proxies_pending, proxy);

		if (proxy->callback != NULL)
			proxy->callback(proxy->client);
	}
	if (delay_ms == 0)
		login_proxy_free_final(proxy);
	else {
		proxy->client_io = io_add_istream(proxy->client_input,
			proxy_client_disconnected_input, proxy);
	}

	client->login_proxy = NULL;
	client_unref(&client);
}
Esempio n. 2
0
/*---------------------------------------------------------------------------*/
void _rtp_timer_add_new_jobs (RTPTimerJob* toTimerList, RTPTimerJob* fromTimerList)
{
	RTPTimerJob *next;
	RTPTimerJob *newJob;
	RTPTimerJob *job;
	long timeDifference;		
	
	newJob = fromTimerList->next;
	while (newJob != fromTimerList)
	{
		next = newJob->next;

		newJob->scheduledTimeMsec += rtp_get_system_msec();
		
		job = toTimerList->next;		
		while (job != toTimerList)
		{
			timeDifference = (long) (job->scheduledTimeMsec - newJob->scheduledTimeMsec);
			if (timeDifference > 0)
			{
				break;
			}
			job = job->next;
		}
		
		DLLIST_REMOVE(newJob);
		DLLIST_INSERT_BEFORE(job, newJob);
		
		newJob->listId = RTP_TIMER_LIST_ACTIVE;

		newJob = next;
	}
}
Esempio n. 3
0
void login_connection_deinit(struct login_connection **_conn)
{
	struct login_connection *conn = *_conn;

	*_conn = NULL;

	if (conn->destroyed)
		return;
	conn->destroyed = TRUE;

	DLLIST_REMOVE(&login_connections, conn);
	io_remove(&conn->io);
	if (conn->input != NULL)
		i_stream_destroy(&conn->input);
	o_stream_destroy(&conn->output);
	if (close(conn->fd) < 0)
		i_error("close(login connection) failed: %m");
	conn->fd = -1;

	if (conn->auth != NULL)
		auth_connection_deinit(&conn->auth);
	login_connection_unref(&conn);

	master_service_client_connection_destroyed(master_service);
}
Esempio n. 4
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);
}
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);
}
Esempio n. 6
0
void client_command_free(struct client_command_context **_cmd)
{
	struct client_command_context *cmd = *_cmd;
	struct client *client = cmd->client;
	enum client_command_state state = cmd->state;

	*_cmd = NULL;

	i_assert(client->output_cmd_lock == NULL);

	/* reset input idle time because command output might have taken a
	   long time and we don't want to disconnect client immediately then */
	client->last_input = ioloop_time;
	timeout_reset(client->to_idle);

	if (cmd->cancel) {
		cmd->cancel = FALSE;
		client_send_tagline(cmd, "NO Command cancelled.");
	}

	if (!cmd->param_error)
		client->bad_counter = 0;

	if (client->input_lock == cmd)
		client->input_lock = NULL;
	if (client->mailbox_change_lock == cmd)
		client->mailbox_change_lock = NULL;

	if (client->free_parser == NULL) {
		imap_parser_reset(cmd->parser);
		client->free_parser = cmd->parser;
	} else if (cmd->parser != NULL) {
		imap_parser_unref(&cmd->parser);
	}

	client->command_queue_size--;
	DLLIST_REMOVE(&client->command_queue, cmd);
	cmd = NULL;

	if (client->command_queue == NULL) {
		/* no commands left in the queue, we can clear the pool */
		p_clear(client->command_pool);
		if (client->to_idle_output != NULL)
			timeout_remove(&client->to_idle_output);
	}
	imap_client_notify_command_freed(client);
	imap_refresh_proctitle();

	/* if command finished from external event, check input for more
	   unhandled commands since we may not be executing from client_input
	   or client_output. */
	if (state == CLIENT_COMMAND_STATE_WAIT_EXTERNAL &&
	    !client->disconnected) {
		client_add_missing_io(client);
		if (client->to_delayed_input == NULL) {
			client->to_delayed_input =
				timeout_add(0, client_input, client);
		}
	}
}
Esempio n. 7
0
static void
io_loop_notify_free(struct ioloop_notify_handler_context *ctx,
		    struct io_notify *io)
{
	DLLIST_REMOVE(&ctx->notifies, io);
	i_free(io);
}
static void
auth_postfix_connection_destroy(struct auth_postfix_connection **_conn)
{
        struct auth_postfix_connection *conn = *_conn;

	*_conn = NULL;
	if (conn->destroyed)
		return;
	conn->destroyed = TRUE;

	DLLIST_REMOVE(&auth_postfix_connections, conn);

	if (conn->input != NULL)
		i_stream_close(conn->input);
	if (conn->output != NULL)
		o_stream_close(conn->output);
	if (conn->io != NULL)
		io_remove(&conn->io);
	if (conn->fd != -1) {
		if (close(conn->fd) < 0)
			i_error("close(%s): %m", conn->path);
		conn->fd = -1;
	}

	master_service_client_connection_destroyed(master_service);
	auth_postfix_connection_unref(&conn);
}
Esempio n. 9
0
void service_process_destroy(struct service_process *process)
{
	struct service *service = process->service;
	struct service_list *service_list = service->list;

	DLLIST_REMOVE(&service->processes, process);
	hash_table_remove(service_pids, POINTER_CAST(process->pid));

	if (process->available_count > 0)
		service->process_avail--;
	service->process_count--;
	i_assert(service->process_avail <= service->process_count);

	if (process->to_status != NULL)
		timeout_remove(&process->to_status);
	if (process->to_idle != NULL)
		timeout_remove(&process->to_idle);
	if (service->list->log_byes != NULL)
		service_process_notify_add(service->list->log_byes, process);

	process->destroyed = TRUE;
	service_process_unref(process);

	if (service->process_count < service->process_limit &&
	    service->type == SERVICE_TYPE_LOGIN)
		service_login_notify(service, FALSE);

	service_list_unref(service_list);
}
Esempio n. 10
0
/*---------------------------------------------------------------------------*/
void _rtp_timer_process_expired_jobs (RTPTimerJob* timerList)
{
	RTPTimerJob *job = timerList->next;
	long timeDifferenceMsec;
	unsigned long currentMsec = rtp_get_system_msec();
	void (*timerFunction) (int,void*);
	void* timerData;
	
	while (job != timerList)
	{
		rtpTimerNextToProcess = job->next;
		
		timeDifferenceMsec = (long) (currentMsec - job->scheduledTimeMsec);
		if (timeDifferenceMsec > 0)
		{
			DLLIST_REMOVE(job);

			if (job->repeat == RTP_TIMER_REPEAT_INFINITE)
			{
				DLLIST_INSERT_BEFORE(&rtpTimerNewList, job);				
				job->listId = RTP_TIMER_LIST_NEW;				
			}
			else
			{
				if (job->repeat > 0)
				{
					/* if this timer has more repeats left, add it to the 
					   new list */
					job->repeat--;
					DLLIST_INSERT_BEFORE(&rtpTimerNewList, job);				
					job->listId = RTP_TIMER_LIST_NEW;				
				}
				else
				{
					DLLIST_INIT(job);
					job->listId = RTP_TIMER_LIST_NONE;
				}
			}

			if (job->timerFunction)
			{
				timerFunction = job->timerFunction;
				timerData = job->timerData;
				rtp_sig_mutex_release(rtpTimerLock);
				timerFunction(0, timerData);
				rtp_sig_mutex_claim(rtpTimerLock);
			}
			
		}
		else
		{
			break;
		}

		job = rtpTimerNextToProcess;
	}

	rtpTimerNextToProcess = 0;
}
Esempio n. 11
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);
}
Esempio n. 12
0
/*---------------------------------------------------------------------------*/
void _HTTP_HostRemoveRealm (
		HTTPAuthenticationHost *host,
		HTTPAuthenticationRealm *realm
	)
{
	DLLIST_REMOVE(&realm->node);
	realm->host = 0;
}
Esempio n. 13
0
void login_proxy_detach(struct login_proxy *proxy)
{
	struct client *client = proxy->client;
	const unsigned char *data;
	size_t size;

	i_assert(proxy->client_fd == -1);
	i_assert(proxy->server_input != NULL);
	i_assert(proxy->server_output != NULL);

	if (proxy->to != NULL)
		timeout_remove(&proxy->to);

	proxy->client_fd = i_stream_get_fd(client->input);
	proxy->client_input = client->input;
	proxy->client_output = client->output;

	i_stream_set_persistent_buffers(client->input, FALSE);
	o_stream_set_max_buffer_size(client->output, (size_t)-1);
	o_stream_set_flush_callback(client->output, proxy_client_output, proxy);
	client->input = NULL;
	client->output = NULL;

	/* send all pending client input to proxy */
	data = i_stream_get_data(proxy->client_input, &size);
	if (size != 0)
		o_stream_nsend(proxy->server_output, data, size);

	/* from now on, just do dummy proxying */
	io_remove(&proxy->server_io);
	proxy->server_io =
		io_add(proxy->server_fd, IO_READ, server_input, proxy);
	proxy->client_io =
		io_add_istream(proxy->client_input, proxy_client_input, proxy);
	o_stream_set_flush_callback(proxy->server_output, server_output, proxy);
	i_stream_destroy(&proxy->server_input);

	if (proxy->notify_refresh_secs != 0) {
		proxy->to_notify =
			timeout_add(proxy->notify_refresh_secs * 1000,
				    login_proxy_notify, proxy);
	}

	proxy->callback = NULL;

	if (login_proxy_ipc_server == NULL) {
		login_proxy_ipc_server =
			ipc_server_init(LOGIN_PROXY_IPC_PATH,
					LOGIN_PROXY_IPC_NAME,
					login_proxy_ipc_cmd);
	}

	DLLIST_REMOVE(&login_proxies_pending, proxy);
	DLLIST_PREPEND(&login_proxies, proxy);

	client->fd = -1;
	client->login_proxy = NULL;
}
Esempio n. 14
0
static void stats_transaction_free(struct stats_user *suser,
				   struct stats_transaction_context *strans)
{
	DLLIST_REMOVE(&suser->transactions, strans);

	trans_stats_add(&suser->session_stats.trans_stats,
			&strans->trans->stats);
	i_free(strans);
}
Esempio n. 15
0
void connection_deinit(struct connection *conn)
{
	i_assert(conn->list->connections_count > 0);

	conn->list->connections_count--;
	DLLIST_REMOVE(&conn->list->connections, conn);

	connection_disconnect(conn);
	i_free(conn->name);
}
Esempio n. 16
0
static void
master_service_haproxy_conn_free(struct master_service_haproxy_conn *hpconn)
{
	struct master_service *service = hpconn->service;

	DLLIST_REMOVE(&service->haproxy_conns, hpconn);

	io_remove(&hpconn->io);
	timeout_remove(&hpconn->to);
	pool_unref(&hpconn->pool);
}
Esempio n. 17
0
void fifo_input_connection_destroy(struct fifo_input_connection **_conn)
{
	struct fifo_input_connection *conn = *_conn;

	*_conn = NULL;

	DLLIST_REMOVE(&fifo_conns, conn);
	io_remove(&conn->io);
	i_stream_destroy(&conn->input);
	if (close(conn->fd) < 0)
		i_error("close(conn) failed: %m");
	i_free(conn);
}
static void
master_service_haproxy_conn_free(struct master_service_haproxy_conn *hpconn)
{
	struct master_service *service = hpconn->service;

	DLLIST_REMOVE(&service->haproxy_conns, hpconn);

	if (hpconn->io != NULL)
		io_remove(&hpconn->io);
	if (hpconn->to != NULL)
		timeout_remove(&hpconn->to);
	i_free(hpconn);
}
Esempio n. 19
0
void config_connection_destroy(struct config_connection *conn)
{
	DLLIST_REMOVE(&config_connections, conn);

	io_remove(&conn->io);
	i_stream_destroy(&conn->input);
	o_stream_destroy(&conn->output);
	if (close(conn->fd) < 0)
		i_error("close(config conn) failed: %m");
	i_free(conn);

	master_service_client_connection_destroyed(master_service);
}
void notify_contexts_mail_transaction_rollback(struct mailbox_transaction_context *t)
{
	struct notify_context *ctx;
	struct notify_mail_txn *mail_txn;

	for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
		mail_txn = notify_context_find_mail_txn(ctx, t);
		if (ctx->v.mail_transaction_rollback != NULL)
			ctx->v.mail_transaction_rollback(mail_txn->txn);
		DLLIST_REMOVE(&ctx->mail_txn_list, mail_txn);
		i_free(mail_txn);
	}
}
Esempio n. 21
0
/* ----------
 * remoteListen_cleanup
 *
 * Free resources used by the remoteListen thread
 * ----------
 */
static void
remoteListen_cleanup(struct listat ** listat_head, struct listat ** listat_tail)
{
	struct listat *listat;

	/*
	 * Free the listen status list
	 */
	while ((listat = *listat_head) != NULL)
	{
		DLLIST_REMOVE(*listat_head, *listat_tail, listat);
		free(listat);
	}
}
void notify_unregister(struct notify_context *ctx)
{
	struct notify_mail_txn *mail_txn = ctx->mail_txn_list;

	for (; mail_txn != NULL; mail_txn = mail_txn->next) {
		if (ctx->v.mail_transaction_rollback != NULL)
			ctx->v.mail_transaction_rollback(mail_txn->txn);
	}
	if (ctx->mailbox_delete_txn != NULL &&
	    ctx->v.mailbox_delete_rollback != NULL)
		ctx->v.mailbox_delete_rollback(ctx->mailbox_delete_txn);
	DLLIST_REMOVE(&ctx_list, ctx);
	i_free(ctx);
}
Esempio n. 23
0
static void
http_client_request_remove(struct http_client_request *req)
{
	struct http_client *client = req->client;

	if (req->listed) {
		/* only decrease pending request counter if this request was submitted */
		DLLIST_REMOVE(&client->requests_list, req);
		client->requests_count--;
	}
	req->listed = FALSE;

	if (client->requests_count == 0 && client->ioloop != NULL)
		io_loop_stop(client->ioloop);
}
void notify_contexts_mail_transaction_commit(struct mailbox_transaction_context *t,
					     struct mail_transaction_commit_changes *changes)
{
	struct notify_context *ctx;
	struct notify_mail_txn *mail_txn;

	for (ctx = ctx_list; ctx != NULL; ctx = ctx->next) {
		if (ctx->v.mail_transaction_commit == NULL)
			continue;
		mail_txn = notify_context_find_mail_txn(ctx, t);
		if (ctx->v.mail_transaction_commit != NULL)
			ctx->v.mail_transaction_commit(mail_txn->txn, changes);
		DLLIST_REMOVE(&ctx->mail_txn_list, mail_txn);
		i_free(mail_txn);
	}
}
Esempio n. 25
0
static void stats_transaction_free(struct stats_user *suser,
				   struct stats_transaction_context *strans)
{
	const struct mailbox_transaction_stats *src = &strans->trans->stats;
	struct mailbox_transaction_stats *dest =
		&suser->finished_transaction_stats;

	DLLIST_REMOVE(&suser->transactions, strans);

	dest->open_lookup_count += src->open_lookup_count;
	dest->stat_lookup_count += src->stat_lookup_count;
	dest->fstat_lookup_count += src->fstat_lookup_count;
	dest->files_read_count += src->files_read_count;
	dest->files_read_bytes += src->files_read_bytes;
	dest->cache_hit_count += src->cache_hit_count;
	i_free(strans);
}
Esempio n. 26
0
void mail_index_transaction_unref(struct mail_index_transaction **_t)
{
	struct mail_index_transaction *t = *_t;

	*_t = NULL;
	if (--t->refcount > 0)
		return;

	mail_index_transaction_reset_v(t);

	DLLIST_REMOVE(&t->view->transactions_list, t);
	array_free(&t->module_contexts);
	mail_index_view_transaction_unref(t->view);
	if (t->latest_view != NULL)
		mail_index_view_close(&t->latest_view);
	mail_index_view_close(&t->view);
	i_free(t);
}
Esempio n. 27
0
static void notify_connection_destroy(struct notify_connection *conn)
{
	if (conn->destroyed)
		return;
	conn->destroyed = TRUE;

	DLLIST_REMOVE(&connections, conn);

	io_remove(&conn->io);
	i_stream_close(conn->input);
	o_stream_close(conn->output);
	if (close(conn->fd) < 0)
		i_error("close(notify connection) failed: %m");
	conn->fd = -1;

	notify_connection_unref(&conn);
	master_service_client_connection_destroyed(master_service);
}
static void notify_connection_destroy(struct notify_connection *conn)
{
    i_assert(conn->fd != -1);

    if (!CONNECTION_IS_FIFO(conn))
        master_service_client_connection_destroyed(master_service);

    DLLIST_REMOVE(&conns, conn);

    io_remove(&conn->io);
    i_stream_close(conn->input);
    if (conn->output != NULL)
        o_stream_close(conn->output);
    net_disconnect(conn->fd);
    conn->fd = -1;

    notify_connection_unref(conn);
}
Esempio n. 29
0
static void view_close(struct mail_index_view *view)
{
	i_assert(view->refcount == 0);
	i_assert(view->index->views != NULL);

	DLLIST_REMOVE(&view->index->views, view);

	mail_transaction_log_view_close(&view->log_view);

	if (array_is_created(&view->syncs_hidden))
		array_free(&view->syncs_hidden);
	mail_index_unmap(&view->map);
	if (array_is_created(&view->map_refs)) {
		mail_index_view_unref_maps(view);
		array_free(&view->map_refs);
	}
	array_free(&view->module_contexts);
	i_free(view);
}
Esempio n. 30
0
void client_destroy(struct client **_client)
{
	struct client *client = *_client;

	*_client = NULL;

	DLLIST_REMOVE(&clients, client);
	if (client->io != NULL)
		io_remove(&client->io);
	i_stream_destroy(&client->input);
	o_stream_destroy(&client->output);
	if (close(client->fd) < 0)
		i_error("close(client) failed: %m");

	client_unref_iters(client);
	pool_unref(&client->cmd_pool);
	i_free(client);

	master_service_client_connection_destroyed(master_service);
}