Exemple #1
0
static int botnet_listen(BOTNET_REC *botnet)
{
	IPADDR addr;
	int port;

	g_return_val_if_fail(botnet != NULL, FALSE);

	if (botnet->port <= 0)
		return FALSE;

	port = botnet->port;
	if (botnet->addr == NULL)
		botnet->listen_handle = net_listen(NULL, &port);
	else {
		net_host2ip(botnet->addr, &addr);
		botnet->listen_handle = net_listen(&addr, &port);
	}

	if (botnet->listen_handle == -1) {
		g_warning("Couldn't start listening botnet\n");
		return FALSE;
	}

	botnet->listen_tag = g_input_add(botnet->listen_handle, G_INPUT_READ,
					 (GInputFunction) sig_botnet_listen, botnet);

	return TRUE;
}
Exemple #2
0
/* Connect to specified IP address using the correct own_ip. */
GIOChannel *dcc_connect_ip(IPADDR *ip, int port)
{
	IPADDR *own_ip, temp_ip;
	const char *own_ip_str;
	GIOChannel *handle;

	own_ip_str = settings_get_str("dcc_own_ip");
	own_ip = NULL;
	if (*own_ip_str != '\0') {
                /* use the specified interface for connecting */
		net_host2ip(own_ip_str, &temp_ip);
		if (IPADDR_IS_V6(ip) == IPADDR_IS_V6(&temp_ip))
			own_ip = &temp_ip;
	}

	if (own_ip == NULL)
		own_ip = IPADDR_IS_V6(ip) ? source_host_ip6 : source_host_ip4;

	handle = net_connect_ip(ip, port, own_ip);
	if (handle == NULL && errno == EADDRNOTAVAIL && own_ip != NULL) {
		/* dcc_own_ip is external address */
		own_ip = IPADDR_IS_V6(ip) ? source_host_ip6 : source_host_ip4;
		handle = net_connect_ip(ip, port, own_ip);
	}
	return handle;
}
Exemple #3
0
static void
lm_open_cb(LmConnection *connection, gboolean success,
    gpointer user_data)
{
	XMPP_SERVER_REC *server;
	IPADDR ip;
	char *host;
	char *recoded_user, *recoded_password, *recoded_resource;

	if ((server = XMPP_SERVER(user_data)) == NULL || !success)
		return;
	/* get the server address */
	host = lm_connection_get_local_host(server->lmconn);
	if (host != NULL) {
		net_host2ip(host, &ip);
		signal_emit("server connecting", 2, server, &ip);
		g_free(host);
	} else
		signal_emit("server connecting", 1, server);
	if (server->connrec->use_ssl)
		signal_emit("xmpp server status", 2, server, 
		    "Using SSL encryption.");
	else if (lm_ssl_get_use_starttls(lm_connection_get_ssl(server->lmconn)))
		signal_emit("xmpp server status", 2, server,
		    "Using STARTTLS encryption.");
	recoded_user = xmpp_recode_out(server->user);

	/* prompt for password or re-use typed password */
	if (server->connrec->prompted_password != NULL) {
		g_free_not_null(server->connrec->password);
		server->connrec->password =
		    g_strdup(server->connrec->prompted_password);
	} else if (server->connrec->password == NULL
	    || *(server->connrec->password) == '\0'
	    || *(server->connrec->password) == '\r') {
		g_free_not_null(server->connrec->password);
		server->connrec->prompted_password = get_password();
		signal_emit("send command", 1, "redraw");
		if (server->connrec->prompted_password != NULL)
			server->connrec->password =
			    g_strdup(server->connrec->prompted_password);
		else
			server->connrec->password = g_strdup("");
	}

	recoded_password = xmpp_recode_out(server->connrec->password);
	recoded_resource = xmpp_recode_out(server->resource);
	lm_connection_authenticate(connection, recoded_user,
	    recoded_password, recoded_resource, lm_auth_cb, server,
	    NULL, NULL);
	g_free(recoded_user);
	g_free(recoded_password);
	g_free(recoded_resource);
}
Exemple #4
0
static void dcc_get_address(const char *str, IPADDR *ip)
{
	unsigned long addr;

	if (strchr(str, ':') == NULL) {
		/* normal IPv4 address in 32bit number form */
		addr = atol(str);
		ip->family = AF_INET;
		addr = (unsigned long) ntohl(addr);
		memcpy(&ip->addr, &addr, 4);
	} else {
		/* IPv6 - in standard form */
		net_host2ip(str, ip);
	}
}
Exemple #5
0
void dcc_str2ip(const char *str, IPADDR *ip)
{
	guint32 addr;

	if (strchr(str, ':') == NULL) {
		/* normal IPv4 address in 32bit number form */
                addr = strtoul(str, NULL, 10);
		ip->family = AF_INET;
		addr = (guint32) ntohl(addr);
		memcpy(&ip->ip, &addr, sizeof(addr));
	} else {
		/* IPv6 - in standard form */
		net_host2ip(str, ip);
	}
}
Exemple #6
0
void dcc_ip2str(IPADDR *ip, char *host)
{
	IPADDR temp_ip;
	guint32 addr;

	if (*settings_get_str("dcc_own_ip") != '\0') {
                /* overridden IP address */
		net_host2ip(settings_get_str("dcc_own_ip"), &temp_ip);
                ip = &temp_ip;
	}

	if (IPADDR_IS_V6(ip)) {
		/* IPv6 */
		net_ip2host(ip, host);
	} else {
		memcpy(&addr, &ip->ip, sizeof(addr));
		g_snprintf(host, MAX_IP_LEN, "%lu",
			   (unsigned long) htonl(addr));
	}
}
Exemple #7
0
gboolean proxy_init(void)
{

    gchar ipaddr[MAX_IP_LEN];

    const char *password;
    const char *addr;
    int port;

    proxy_settings_init();

    proxy_data = g_new0(PLUGIN_DATA, 1);
    password = settings_get_str("proxy_listen_password");
    addr = settings_get_str("proxy_listen_addr");
    port = settings_get_int("proxy_listen_port");

    plug = module_find("proxy");
    proxy_data->plugin = plug;

    if (*password != '\0')
    {
       	/* args = password */
       	proxy_data->password = g_strdup(password);
    }
    if (*addr != '\0')
    {
       	/* specify ip address to listen */
       	net_host2ip(addr, &proxy_data->ip);
    }
    if (port != 0)
    {
       	/* specify port to use */
       	proxy_data->port = port;
    }
    
    if (proxy_data->password == NULL)
    {
    	/* no password - bad idea! */
    	printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, "Warning!! Password not specified, everyone can use this proxy! Use /set proxy_listen_password <password> to set it");
    }

    if (servers == NULL)
    {
    	/* FIXME: not good */
    	printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "You need to specify IP address to listen with /set proxy_listen_addr <address>");
    	deinit();
    	return FALSE;
    }
    else
    {
    	SERVER_REC *server;

    	server = servers->data;
    	if (net_getsockname(net_sendbuffer_handle(server->handle), &proxy_data->ip, NULL))
    	{
	    deinit();
	    return FALSE;
	}
    }

    net_ip2host(&proxy_data->ip, ipaddr);
    printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, "Proxy plugin loaded - listening in interface %s port %d", ipaddr, proxy_data->port);

    plugin_proxy_listen_init(proxy_data);

    proxy_data->loaded = TRUE;
    return TRUE;
}