Package: pork
Version: 0.99.5-2
Severity: normal
Tags: patch

although the bundled libfaim does support SOCKS5 proxies, pork does
not; this means that the otrproxy for secure, deniable IM from

http://www.cypherpunks.ca/otr/

does not work. i've attached a patch that changes pork to use the
libfaim connection code so that this works. to use it, type e.g.

otrproxy &
env SOCKS5_PROXY=127.0.0.1 pork

and you'll have secured im. this should work with other SOCKS5 proxies
too (useful from behind some firewalls), but otrproxy is the only one
i have tested it with.

patch is also online at

http://xent.com/~bsittler/pork-0.99.7-socks5.diff

-- System Information:
Debian Release: 3.1
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.4.22-1-k7
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)

Versions of packages pork depends on:
ii  libc6                       2.3.2.ds1-19 GNU C Library: Shared libraries an
ii  libncurses5                 5.4-4        Shared libraries for terminal hand
ii  libperl5.8                  5.8.4-6      Shared Perl library

-- no debconf information
diff -u --recursive pork-0.99.7.orig/src/pork_aim.c pork-0.99.7/src/pork_aim.c
--- pork-0.99.7.orig/src/pork_aim.c	2004-12-10 19:15:49.000000000 -0800
+++ pork-0.99.7/src/pork_aim.c	2005-02-15 20:01:44.262712696 -0800
@@ -58,10 +58,6 @@
 								const char *name,
 								int exchange);
 
-static int aim_sock_connect(const char *ip,
-							struct sockaddr_storage *laddr,
-							int *sock);
-
 static int aim_report_idle(struct pork_acct *acct, int mode);
 static int aim_connect_abort(struct pork_acct *acct);
 static int aim_set_away(struct pork_acct *acct, char *away_msg);
@@ -115,48 +111,6 @@
 #endif
 }
 
-static int aim_sock_connect(const char *ip,
-							struct sockaddr_storage *laddr,
-							int *sock)
-{
-	struct sockaddr_storage ss;
-	char *addr;
-	char *port;
-	in_port_t port_num = FAIM_LOGIN_PORT;
-
-	port = getenv("AIM_PORT");
-	if (port != NULL) {
-		u_int32_t temp;
-
-		if (str_to_uint(port, &temp) != -1)
-			port_num = temp;
-	}
-
-	addr = xstrdup(ip);
-
-	port = strchr(addr, ':');
-	if (port != NULL) {
-		*port++ = '\0';
-
-		if (get_port(port, &port_num) != 0) {
-			screen_err_msg("Error: Invalid port: %s", port);
-			goto err_out;
-		}
-	}
-
-	if (get_addr(addr, &ss) != 0) {
-		screen_err_msg("Error: Invalid host: %s", addr);
-		goto err_out;
-	}
-
-	free(addr);
-	return (nb_connect(&ss, laddr, port_num, sock));
-
-err_out:
-	free(addr);
-	return (-1);
-}
-
 static void aim_print_info(	char *user,
 							char *profile,
 							char *away_msg,
@@ -1483,27 +1437,18 @@
 
 	if (redirect->group == AIM_CONN_TYPE_CHATNAV) {
 		aim_conn_t *chatnav;
-		int sock;
-		int ret;
 
-		chatnav = aim_newconn(session, AIM_CONN_TYPE_CHATNAV, NULL);
+		chatnav = aim_newconn(session, AIM_CONN_TYPE_CHATNAV, redirect->ip);
 		if (chatnav == NULL) {
 			screen_err_msg("Unable to connect to the chatnav server: %s",
 				strerror(errno));
 			return (0);
 		}
 
-		ret = aim_sock_connect(redirect->ip, &acct->laddr, &sock);
-		if (ret == 0) {
-			aim_connected(sock, 0, chatnav);
-		} else if (ret == -EINPROGRESS) {
-			chatnav->status |= AIM_CONN_STATUS_INPROGRESS;
-			pork_io_add(sock, IO_COND_WRITE, chatnav, chatnav, aim_connected);
+		if (! (chatnav->status | AIM_CONN_STATUS_INPROGRESS)) {
+			aim_connected(chatnav->fd, 0, chatnav);
 		} else {
-			aim_conn_kill(session, &chatnav);
-			screen_err_msg("Unable to connect to the chatnav server: %s",
-				strerror(errno));
-			return (0);
+			pork_io_add(chatnav->fd, IO_COND_WRITE, chatnav, chatnav, aim_connected);
 		}
 
 		aim_conn_addhandler(session, chatnav, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNDEAD, aim_conn_dead, 0);
@@ -1517,27 +1462,19 @@
 		struct aim_chat *a_chat;
 		struct imwindow *win;
 		char buf[128];
-		int sock;
-		int ret;
 		char *chat_title;
 
-		chat_conn = aim_newconn(session, AIM_CONN_TYPE_CHAT, NULL);
+		chat_conn = aim_newconn(session, AIM_CONN_TYPE_CHAT, redirect->ip);
 		if (chat_conn == NULL) {
 			screen_err_msg("Unable to connect to the chat server");
 			return (0);
 		}
 
-		ret = aim_sock_connect(redirect->ip, &acct->laddr, &sock);
-		if (ret == 0) {
-			aim_connected(sock, 0, chat_conn);
-		} else if (ret == -EINPROGRESS) {
-			chat_conn->status |= AIM_CONN_STATUS_INPROGRESS;
-			pork_io_add(sock, IO_COND_WRITE, chat_conn, chat_conn,
-				aim_connected);
+		if (! (chat_conn->status | AIM_CONN_STATUS_INPROGRESS)) {
+			aim_connected(chat_conn->fd, 0, chat_conn);
 		} else {
-			aim_conn_kill(session, &chat_conn);
-			screen_err_msg("Unable to connect to the chatnav server");
-			return (0);
+			pork_io_add(chat_conn->fd, IO_COND_WRITE, chat_conn, chat_conn,
+				aim_connected);
 		}
 
 		chat_title = get_chatname(redirect->chat.room);
@@ -2013,8 +1950,6 @@
 	struct aim_authresp_info *authresp;
 	aim_conn_t *bos_conn;
 	struct pork_acct *acct = session->aux_data;
-	int ret;
-	int sock;
 	struct sockaddr_storage local;
 
 	pork_io_del(fr->conn);
@@ -2060,27 +1995,21 @@
 		return (1);
 	}
 
-	bos_conn = aim_newconn(session, AIM_CONN_TYPE_BOS, NULL);
+	bos_conn = aim_newconn(session, AIM_CONN_TYPE_BOS, authresp->bosip);
 	if (bos_conn == NULL) {
 		aim_conn_kill(session, &bos_conn);
-		screen_err_msg("Unable to connect to the AIM BOS server");
+		screen_err_msg("Unable to connect to the BOS server");
 		return (1);
 	}
 
 	memcpy(&local, &acct->laddr, sizeof(local));
 	sin_set_port(&local, acct->lport);
 
-	ret = aim_sock_connect(authresp->bosip, &local, &sock);
-	if (ret == 0) {
-		aim_connected(sock, 0, bos_conn);
-	} else if (ret == -EINPROGRESS) {
-		bos_conn->status |= AIM_CONN_STATUS_INPROGRESS;
-		pork_io_add(sock, IO_COND_WRITE, bos_conn, bos_conn,
-			aim_connected);
+	if (! (bos_conn->status | AIM_CONN_STATUS_INPROGRESS)) {
+		aim_connected(bos_conn->fd, 0, bos_conn);
 	} else {
-		aim_conn_kill(session, &bos_conn);
-		screen_err_msg("Unable to connect to the BOS server");
-		return (0);
+		pork_io_add(bos_conn->fd, IO_COND_WRITE, bos_conn, bos_conn,
+			aim_connected);
 	}
 
 	aim_conn_addhandler(session, bos_conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNDEAD, aim_conn_dead, 0);
@@ -2120,19 +2049,48 @@
 
 static int aim_login(struct pork_acct *acct) {
 	struct aim_priv *priv = acct->data;
-	int ret;
-	int sock;
 	aim_conn_t *auth_conn;
 	char *server;
+	char *port;
+	in_port_t port_num = FAIM_LOGIN_PORT;
+	const char *socks5_server, *socks5_user, *socks5_passwd;
+
+	socks5_server = getenv("SOCKS5_SERVER");
+	if (socks5_server == NULL)
+		socks5_server = getenv("SOCKS_SERVER");
+	socks5_user = getenv("SOCKS5_USER");
+	socks5_passwd = getenv("SOCKS5_PASSWD");
+	aim_setupproxy(&priv->aim_session, socks5_server, socks5_user, socks5_passwd);
 
 	server = getenv("AIM_SERVER");
 	if (server == NULL)
 		server = FAIM_LOGIN_SERVER;
 
+	port = getenv("AIM_PORT");
+	if (port != NULL) {
+		u_int32_t temp;
+
+		if (str_to_uint(port, &temp) != -1)
+			port_num = temp;
+	}
+
+	server = xstrdup(server);
+	if ((port_num != FAIM_LOGIN_PORT) && ! strchr(server, ':'))
+	{
+		size_t len = strlen(server);
+		char buf[7];
+
+		sprintf(buf, ":%hu", (unsigned short) port_num);
+		server = realloc(server, len + 7);
+		strcpy(server, buf);
+	}
+
 	acct->connected = 0;
 	screen_status_msg_ts("Logging in as %s...", acct->username);
 
-	auth_conn = aim_newconn(&priv->aim_session, AIM_CONN_TYPE_AUTH, NULL);
+	auth_conn = aim_newconn(&priv->aim_session, AIM_CONN_TYPE_AUTH, server);
+	free(server);
+
 	if (auth_conn == NULL) {
 		screen_err_msg("Connection error while logging in as %s",
 			acct->username);
@@ -2140,17 +2098,10 @@
 		return (-1);
 	}
 
-	ret = aim_sock_connect(server, &acct->laddr, &sock);
-	if (ret == 0) {
-		aim_connected(sock, 0, auth_conn);
-	} else if (ret == -EINPROGRESS) {
-		auth_conn->status |= AIM_CONN_STATUS_INPROGRESS;
-		pork_io_add(sock, IO_COND_WRITE, auth_conn, auth_conn, aim_connected);
-	} else {
-		screen_err_msg("Error connecting to the authorizer server as %s",
-			acct->username);
-		aim_conn_kill(&priv->aim_session, &auth_conn);
-		return (-1);
+	if (! (auth_conn->status | AIM_CONN_STATUS_INPROGRESS)) {
+		aim_connected(auth_conn->fd, 0, auth_conn);
+	} else {
+		pork_io_add(auth_conn->fd, IO_COND_WRITE, auth_conn, auth_conn, aim_connected);
 	}
 
 	aim_conn_addhandler(&priv->aim_session, auth_conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR, aim_connerr, 0);
@@ -2167,7 +2118,7 @@
 
 	memset(session, 0, sizeof(*session));
 
-	aim_session_init(session, 0, 0);
+	aim_session_init(session, 1, 0);
 	aim_setdebuggingcb(session, aim_debug);
 
 	aim_tx_setenqueue(session, AIM_TX_IMMEDIATE, NULL);
@@ -2996,8 +2947,6 @@
 	struct aim_oft_info *oft_info;
 	struct aim_priv *priv = xfer->acct->data;
 	char buf[512];
-	int ret;
-	int sock;
 
 	oft_info = xfer->data;
 
@@ -3005,7 +2954,7 @@
 		oft_info->port);
 
 	oft_info->conn = aim_newconn(&priv->aim_session,
-						AIM_CONN_TYPE_RENDEZVOUS, NULL);
+						AIM_CONN_TYPE_RENDEZVOUS, buf);
 
 	if (oft_info->conn == NULL) {
 		screen_err_msg("Error connecting to [EMAIL PROTECTED] while receiving %s",
@@ -3016,18 +2965,11 @@
 	oft_info->conn->subtype = AIM_CONN_SUBTYPE_OFT_SENDFILE;
 	oft_info->conn->priv = xfer;
 
-	ret = aim_sock_connect(buf, &xfer->acct->laddr, &sock);
-	if (ret == 0) {
-		aim_connected(sock, 0, oft_info->conn);
-	} else if (ret == -EINPROGRESS) {
-		oft_info->conn->status |= AIM_CONN_STATUS_INPROGRESS;
-		pork_io_add(sock, IO_COND_WRITE, oft_info->conn, oft_info->conn,
-			aim_connected);
+	if (! (oft_info->conn->status | AIM_CONN_STATUS_INPROGRESS)) {
+		aim_connected(oft_info->conn->fd, 0, oft_info->conn);
 	} else {
-		aim_conn_kill(&priv->aim_session, &oft_info->conn);
-		screen_err_msg("Error connecting to [EMAIL PROTECTED] while receiving %s",
-			xfer->peer_username, buf, xfer->fname_local);
-		return (-1);
+		pork_io_add(oft_info->conn->fd, IO_COND_WRITE, oft_info->conn, oft_info->conn,
+			aim_connected);
 	}
 
 	aim_conn_addhandler(&priv->aim_session, oft_info->conn,

Reply via email to