/* X-Chat * Copyright (C) 1998 Peter Zelezny. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * MS Proxy (ISA server) support is (c) 2006 Pavel Fedin * based on Dante source code * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 * Inferno Nettverk A/S, Norway. All rights reserved. */ /*#define DEBUG_MSPROXY*/ #include #include #include #include #ifndef WIN32 #include #endif #define WANTSOCKET #define WANTARPA #include "inet.h" #include "hexchat.h" #include "network.h" #include "hexchatc.h" #include "server.h" #include "msproxy.h" #ifdef USE_MSPROXY #include static int send_msprequest(s, state, request, end) int s; struct msproxy_state_t *state; struct msproxy_request_t *request; char *end; { ssize_t w; size_t l; request->magic25 = htonl(MSPROXY_VERSION); request->serverack = state->seq_recv; /* don't start incrementing sequence until we are acking packet #2. */ request->sequence = (unsigned char)(request->serverack >= 2 ? state->seq_sent + 1 : 0); memcpy(request->RWSP, "RWSP", sizeof(request->RWSP)); l = end - (char *)request; /* all requests must be atleast MSPROXY_MINLENGTH it seems. */ if (l < MSPROXY_MINLENGTH) { bzero(end, (size_t)(MSPROXY_MINLENGTH - l)); l = MSPROXY_MINLENGTH; } if ((w = send(s, request, l, 0)) != l) { #ifdef DEBUG_MSPROXY printf ("send_msprequest(): send() failed (%d bytes sent instead of %d\n", w, l); perror ("Error is"); #endif return -1; } state->seq_sent = request->sequence; return w; } static int recv_mspresponse(s, state, response) int s; struct msproxy_state_t *state; struct msproxy_response_t *response; { ssize_t r; do { if ((r = recv (s, response, sizeof (*response), 0)) < MSPROXY_MINLENGTH) { #ifdef DEBUG_MSPROXY printf ("recv_mspresponse(): expected to read atleast %d, read %d\n", MSPROXY_MINLENGTH, r); #endif return -1; } if (state->seq_recv == 0) break; /* not started incrementing yet. */ #ifdef DEBUG_MSPROXY if (response->sequence == state->seq_recv) printf ("seq_recv: %d, dup response, seqnumber: 0x%x\n", state->seq_recv, response->sequence); #endif } while (response->sequence == state->seq_recv); state->seq_recv = response->sequence; return r; } int traverse_msproxy (int sok, char *serverAddr, int port, struct msproxy_state_t *state, netstore *ns_proxy, int csok4, int csok6, int *csok, char bound) { struct msproxy_request_t req; struct msproxy_response_t res; char *data, *p; char hostname[NT_MAXNAMELEN]; char ntdomain[NT_MAXNAMELEN]; char challenge[8]; netstore *ns_client; int clientport; guint32 destaddr; guint32 flags; if (!prefs.hex_net_proxy_auth || !prefs.hex_net_proxy_user[0] || !prefs.hex_net_proxy_pass[0] ) return 1; /* MS proxy protocol implementation currently doesn't support IPv6 */ destaddr = net_getsockaddr_v4 (ns_proxy); if (!destaddr) return 1; state->seq_recv = 0; state->seq_sent = 0; #ifdef DEBUG_MSPROXY printf ("Connecting to %s:%d via MS proxy\n", serverAddr, port); #endif gethostname (hostname, NT_MAXNAMELEN); p = strchr (hostname, '.'); if (p) *p = '\0'; bzero (&req, sizeof(req)); req.clientid = htonl(0x0a000000); /* Initial client ID is always 0x0a */ req.command = htons(MSPROXY_HELLO); /* HELLO command */ req.packet.hello.magic5 = htons(0x4b00); /* Fill in magic values */ req.packet.hello.magic10 = htons(0x1400); req.packet.hello.magic15 = htons(0x0400); req.packet.hello.magic20 = htons(0x5704); req.packet.hello.magic25 = htons(0x0004); req.packet.hello.magic30 = htons(0x0100); req.packet.hello.magic35 = htons(0x4a02); req.packet.hello.magic40 = htons(0x3000); req.packet.hello.magic45 = htons(0x4400); req.packet.hello.magic50 = htons(0x3900); data = req.packet.hello.data; strcpy (data, prefs.hex_net_proxy_user); /* Append a username */ data += strlen (prefs.hex_net_proxy_user)+2; /* +2 automatically creates second empty string */ strcpy (data, MSPROXY_EXECUTABLE); /* Append an application name */ data += strlen (MSPROXY_EXECUTABLE)+1; strcpy (data, hostname); /* Append a hostname */ data += strlen (hostname)+1; if (send_msprequest(sok, state, &req, data) == -1) return 1; if (recv_mspresponse(sok, state, &res) == -1) return 1; if (strcmp(res.RWSP, "RWSP") != 0) { #ifdef DEBUG_MSPROXY printf ("Received mailformed packet (no RWSP signature)\n"); #endif return 1; } if (ntohs(res.command) >> 8 != 0x10) { #ifdef DEBUG_MSPROXY printf ("expected res.command = 10??, is %x", ntohs(res.command));
#include <fcntl.h>
#include "thread.h"

thread *
thread_new (void)
{
	thread *th;

	th = calloc (1, sizeof (*th));
	if (!th)
	{
		return NULL;
	}

	if (_pipe (th->pipe_fd, 4096, _O_BINARY) == -1)
	{
		free (th);
		return NULL;
	}

	return th;
}

int
thread_start (thread *th, void *(*start_routine)(void *), void *arg)
{
	DWORD