From eb93130cd3a846650dfbb972194190e91564df02 Mon Sep 17 00:00:00 2001 From: TingPing Date: Tue, 1 Oct 2013 11:21:28 -0400 Subject: Remove gtkspell support --- src/fe-gtk/Makefile.am | 9 ++---- src/fe-gtk/fe-gtk.c | 4 --- src/fe-gtk/fe-gtk.h | 10 ------ src/fe-gtk/fkeys.c | 11 ------- src/fe-gtk/maingui.c | 86 +------------------------------------------------- src/fe-gtk/setup.c | 31 ++---------------- 6 files changed, 5 insertions(+), 146 deletions(-) (limited to 'src/fe-gtk') diff --git a/src/fe-gtk/Makefile.am b/src/fe-gtk/Makefile.am index 9ae2d084..259d2c89 100644 --- a/src/fe-gtk/Makefile.am +++ b/src/fe-gtk/Makefile.am @@ -18,16 +18,11 @@ if DO_PLUGIN plugingui_c = plugingui.c endif -if USE_LIBSEXY -sexy_spell = \ - sexy-iso-codes.c sexy-marshal.c sexy-spell-entry.c -endif - hexchat_SOURCES = ascii.c banlist.c chanlist.c chanview.c custom-list.c \ dccgui.c editlist.c fe-gtk.c fkeys.c gtkutil.c ignoregui.c joind.c menu.c \ maingui.c notifygui.c palette.c pixmaps.c plugin-tray.c $(plugingui_c) \ - rawlog.c resources.c servlistgui.c setup.c $(sexy_spell) textgui.c \ - urlgrab.c userlistgui.c xtext.c + rawlog.c resources.c servlistgui.c setup.c sexy-iso-codes.c sexy-marshal.c \ + sexy-spell-entry.c textgui.c urlgrab.c userlistgui.c xtext.c resources.c: ../../data/hexchat.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=../../data --generate-dependencies ../../data/hexchat.gresource.xml) $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=../../data --generate-source $< diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c index 7fce696c..97067f90 100644 --- a/src/fe-gtk/fe-gtk.c +++ b/src/fe-gtk/fe-gtk.c @@ -240,11 +240,7 @@ fe_args (int argc, char *argv[]) const char cursor_color_rc[] = "style \"xc-ib-st\"" "{" -#ifdef USE_GTKSPELL - "GtkTextView::cursor-color=\"#%02x%02x%02x\"" -#else "GtkEntry::cursor-color=\"#%02x%02x%02x\"" -#endif "}" "widget \"*.hexchat-inputbox\" style : application \"xc-ib-st\""; diff --git a/src/fe-gtk/fe-gtk.h b/src/fe-gtk/fe-gtk.h index 440d98ea..6f5b47c5 100644 --- a/src/fe-gtk/fe-gtk.h +++ b/src/fe-gtk/fe-gtk.h @@ -197,21 +197,11 @@ typedef struct session_gui extern GdkPixmap *channelwin_pix; extern GdkPixmap *dialogwin_pix; - -#ifdef USE_GTKSPELL -char *SPELL_ENTRY_GET_TEXT (GtkWidget *entry); -#define SPELL_ENTRY_SET_TEXT(e,txt) gtk_text_buffer_set_text (gtk_text_view_get_buffer(GTK_TEXT_VIEW(e)),txt,-1); -#define SPELL_ENTRY_SET_EDITABLE(e,v) gtk_text_view_set_editable(GTK_TEXT_VIEW(e), v) -int SPELL_ENTRY_GET_POS (GtkWidget *entry); -void SPELL_ENTRY_SET_POS (GtkWidget *entry, int pos); -void SPELL_ENTRY_INSERT (GtkWidget *entry, const char *text, int len, int *pos); -#else #define SPELL_ENTRY_GET_TEXT(e) ((char *)(gtk_entry_get_text (GTK_ENTRY(e)))) #define SPELL_ENTRY_SET_TEXT(e,txt) gtk_entry_set_text(GTK_ENTRY(e),txt) #define SPELL_ENTRY_SET_EDITABLE(e,v) gtk_editable_set_editable(GTK_EDITABLE(e),v) #define SPELL_ENTRY_GET_POS(e) gtk_editable_get_position(GTK_EDITABLE(e)) #define SPELL_ENTRY_SET_POS(e,p) gtk_editable_set_position(GTK_EDITABLE(e),p); #define SPELL_ENTRY_INSERT(e,t,l,p) gtk_editable_insert_text(GTK_EDITABLE(e),t,l,p) -#endif #endif diff --git a/src/fe-gtk/fkeys.c b/src/fe-gtk/fkeys.c index 52f5d901..bf21c452 100644 --- a/src/fe-gtk/fkeys.c +++ b/src/fe-gtk/fkeys.c @@ -300,17 +300,6 @@ key_handle_key_press (GtkWidget *wid, GdkEventKey *evt, session *sess) case GDK_KEY_space: key_action_tab_clean (); break; - -#if defined(USE_GTKSPELL)/* && !defined(WIN32) */ - /* gtktextview has no 'activate' event, so we trap ENTER here */ - case GDK_KEY_Return: - case GDK_KEY_KP_Enter: - if (!(evt->state & STATE_CTRL)) - { - g_signal_stop_emission_by_name (G_OBJECT (wid), "key_press_event"); - mg_inputbox_cb (wid, sess->gui); - } -#endif } return 0; diff --git a/src/fe-gtk/maingui.c b/src/fe-gtk/maingui.c index 933d6948..f064c7f7 100644 --- a/src/fe-gtk/maingui.c +++ b/src/fe-gtk/maingui.c @@ -50,14 +50,7 @@ #include "pixmaps.h" #include "plugin-tray.h" #include "xtext.h" - -#ifdef USE_GTKSPELL -#include -#endif - -#ifdef USE_LIBSEXY #include "sexy-spell-entry.h" -#endif #define GUI_SPACING (3) #define GUI_BORDER (0) @@ -99,59 +92,6 @@ static PangoAttrList *nickseen_list; static PangoAttrList *newmsg_list; static PangoAttrList *plain_list = NULL; - -#ifdef USE_GTKSPELL - -/* use these when it's a GtkTextView instead of GtkEntry */ - -char * -SPELL_ENTRY_GET_TEXT (GtkWidget *entry) -{ - static char *last = NULL; /* warning: don't overlap 2 GET_TEXT calls! */ - GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (entry)); - GtkTextIter start_iter, end_iter; - - gtk_text_buffer_get_iter_at_offset (buf, &start_iter, 0); - gtk_text_buffer_get_end_iter (buf, &end_iter); - g_free (last); - last = gtk_text_buffer_get_text (buf, &start_iter, &end_iter, FALSE); - return last; -} - -void -SPELL_ENTRY_SET_POS (GtkWidget *entry, int pos) -{ - GtkTextIter iter; - GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (entry)); - - gtk_text_buffer_get_iter_at_offset (buf, &iter, pos); - gtk_text_buffer_place_cursor (buf, &iter); -} - -int -SPELL_ENTRY_GET_POS (GtkWidget *entry) -{ - GtkTextIter cursor; - GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (entry)); - - gtk_text_buffer_get_iter_at_mark (buf, &cursor, gtk_text_buffer_get_insert (buf)); - return gtk_text_iter_get_offset (&cursor); -} - -void -SPELL_ENTRY_INSERT (GtkWidget *entry, const char *text, int len, int *pos) -{ - GtkTextIter iter; - GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (entry)); - - /* len is bytes. pos is chars. */ - gtk_text_buffer_get_iter_at_offset (buf, &iter, *pos); - gtk_text_buffer_insert (buf, &iter, text, len); - *pos += g_utf8_strlen (text, len); -} - -#endif - static PangoAttrList * mg_attr_list_create (GdkColor *col, int size) { @@ -2999,9 +2939,6 @@ static void mg_create_entry (session *sess, GtkWidget *box) { GtkWidget *hbox, *but, *entry; -#ifdef USE_GTKSPELL - GtkWidget *sw; -#endif session_gui *gui = sess->gui; hbox = gtk_hbox_new (FALSE, 0); @@ -3017,34 +2954,13 @@ mg_create_entry (session *sess, GtkWidget *box) g_signal_connect (G_OBJECT (but), "clicked", G_CALLBACK (mg_nickclick_cb), NULL); -#ifdef USE_GTKSPELL - gui->input_box = entry = gtk_text_view_new (); - gtk_widget_set_size_request (entry, 0, 1); - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (entry), GTK_WRAP_NONE); - gtk_text_view_set_accepts_tab (GTK_TEXT_VIEW (entry), FALSE); - if (prefs.hex_gui_input_spell) - gtkspell_new_attach (GTK_TEXT_VIEW (entry), NULL, NULL); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), - GTK_SHADOW_IN); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_NEVER, - GTK_POLICY_AUTOMATIC); - gtk_container_add (GTK_CONTAINER (sw), entry); - gtk_container_add (GTK_CONTAINER (hbox), sw); -#else -#ifdef USE_LIBSEXY gui->input_box = entry = sexy_spell_entry_new (); sexy_spell_entry_set_checked ((SexySpellEntry *)entry, prefs.hex_gui_input_spell); -#else - gui->input_box = entry = gtk_entry_new (); -#endif + gtk_entry_set_max_length (GTK_ENTRY (gui->input_box), 0); g_signal_connect (G_OBJECT (entry), "activate", G_CALLBACK (mg_inputbox_cb), gui); gtk_container_add (GTK_CONTAINER (hbox), entry); -#endif gtk_widget_set_name (entry, "hexchat-inputbox"); g_signal_connect (G_OBJECT (entry), "key_press_event", diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c index 41b50ac7..3dd09568 100644 --- a/src/fe-gtk/setup.c +++ b/src/fe-gtk/setup.c @@ -40,12 +40,7 @@ #ifdef WIN32 #include "../common/fe.h" #endif -#ifdef USE_GTKSPELL -#include -#endif -#ifdef USE_LIBSEXY #include "sexy-spell-entry.h" -#endif GtkStyle *create_input_style (GtkStyle *); @@ -194,7 +189,7 @@ static const setting inputbox_settings[] = {ST_TOGGLE, N_("Use the Text box font and colors"), P_OFFINTNL(hex_gui_input_style),0,0,0}, {ST_TOGGLE, N_("Show nick box"), P_OFFINTNL(hex_gui_input_nick),0,0,1}, {ST_TOGGLE, N_("Show user mode icon in nick box"), P_OFFINTNL(hex_gui_input_icon),0,0,0}, -#ifdef HAVE_ISO_CODES /* Defined with static spelling */ +#ifdef USE_SPELL {ST_TOGGLE, N_("Spell checking"), P_OFFINTNL(hex_gui_input_spell),0,0,1}, {ST_ENTRY, N_("Dictionaries to use:"), P_OFFSETNL(hex_text_spell_langs),0,0,sizeof prefs.hex_text_spell_langs}, #ifdef WIN32 @@ -202,10 +197,6 @@ static const setting inputbox_settings[] = #else {ST_LABEL, N_("Use language codes. Separate multiple entries with commas.")}, #endif -#else -#if defined(USE_GTKSPELL) || defined(USE_LIBSEXY) - {ST_TOGGLE, N_("Spell checking"), P_OFFINTNL(hex_gui_input_spell),0,0,0}, -#endif #endif {ST_HEADER, N_("Nick Completion"),0,0,0}, @@ -2004,10 +1995,6 @@ setup_apply_entry_style (GtkWidget *entry) static void setup_apply_to_sess (session_gui *gui) { -#ifdef USE_GTKSPELL - GtkSpell *spell; -#endif - mg_update_xtext (gui->xtext); if (prefs.hex_gui_ulist_style) @@ -2034,21 +2021,7 @@ setup_apply_to_sess (session_gui *gui) else gtk_widget_hide (gui->button_box); -#ifdef USE_GTKSPELL - spell = gtkspell_get_from_text_view (GTK_TEXT_VIEW (gui->input_box)); - if (prefs.hex_gui_input_spell) - { - if (!spell) - gtkspell_new_attach (GTK_TEXT_VIEW (gui->input_box), NULL, NULL); - } - else - { - if (spell) - gtkspell_detach (spell); - } -#endif - -#ifdef USE_LIBSEXY +#ifdef USE_SPELL /* update active languages */ sexy_spell_entry_deactivate_language((SexySpellEntry *)gui->input_box,NULL); sexy_spell_entry_activate_default_languages((SexySpellEntry *)gui->input_box); -- cgit 1.4.1



























                                                                                 

                  



                   



























































































                                                                                                                                                      
                                                                                                       
































                                                                                                                  

                                                                                                                  

































































































































                                                                                                                                          
                                                                                                                                          




                                                                                                                                  
                                                                                                                                          









                                                                                                                                  
                                                                                                                                          

                                                                                
                                               




























































































































































                                                                                                                                  
/* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 *
 * MS Proxy (ISA server) support is (c) 2006 Pavel Fedin <sonic_amiga@rambler.ru>
 * 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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>

#ifndef WIN32
#include <unistd.h>
#endif

#define WANTSOCKET
#define WANTARPA
#include "inet.h"

#include "xchat.h"
#include "network.h"
#include "xchatc.h"
#include "server.h"
#include "msproxy.h"


#ifdef USE_MSPROXY
#include <ntlm.h>

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));
#endif
		return 1;
	}

	state->clientid	= htonl(rand());
	state->serverid	= res.serverid;

#ifdef DEBUG_MSPROXY
	printf ("clientid: 0x%x, serverid: 0x%0x\n", state->clientid, state->serverid);
	printf ("packet #2\n");
#endif

	/* almost identical. */
	req.clientid	= state->clientid;
	req.serverid	= state->serverid;

	if (send_msprequest(sok, state, &req, data) == -1)
		return 1;

	if (recv_mspresponse(sok, state, &res) == -1)
		return 1;

	if (res.serverid != state->serverid) {
#ifdef DEBUG_MSPROXY
		printf ("expected serverid = 0x%x, is 0x%x\n",state->serverid, res.serverid);
#endif
		return 1;
	}

	if (res.sequence != 0x01) {
#ifdef DEBUG_MSPROXY
		printf ("expected res.sequence = 0x01, is 0x%x\n", res.sequence);
#endif
		return 1;
	}

	if (ntohs(res.command) != MSPROXY_USERINFO_ACK) {
#ifdef DEBUG_MSPROXY
		printf ("expected res.command = 0x%x, is 0x%x\n", MSPROXY_USERINFO_ACK, ntohs(res.command));
#endif
		return 1;
	}

#ifdef DEBUG_MSPROXY
	printf ("packet #3\n");
#endif

	bzero(&req, sizeof(req));
	req.clientid			= state->clientid;
	req.serverid			= state->serverid;
	req.command			= htons(MSPROXY_AUTHENTICATE);
	memcpy(req.packet.auth.NTLMSSP, "NTLMSSP", sizeof("NTLMSSP"));
	req.packet.auth.bindaddr	= htonl(0x02000000);
	req.packet.auth.msgtype		= htonl(0x01000000);
	/* NTLM flags:	0x80000000 Negotiate LAN Manager key
			0x10000000 Negotiate sign
			0x04000000 Request target
			0x02000000 Negotiate OEM
			0x00800000 Always sign
			0x00020000 Negotiate NTLM
	*/
	req.packet.auth.flags		= htonl(0x06020000);

	if (send_msprequest(sok, state, &req, &req.packet.auth.data) == -1)
		return 1;

	if (recv_mspresponse(sok, state, &res) == -1)
		return 1;

	if (res.serverid != state->serverid) {
#ifdef DEBUG_MSPROXY
		printf ("expected serverid = 0x%x, is 0x%x\n", state->serverid, res.serverid);
#endif
		return 1;
	}

	if (ntohs(res.command) != MSPROXY_AUTHENTICATE_ACK) {
#ifdef DEBUG_MSPROXY
		printf ("expected res.command = 0x%x, is 0x%x\n", MSPROXY_AUTHENTICATE_ACK, ntohs(res.command));
#endif
		return 1;
	}

	flags = res.packet.auth.flags & htonl(0x00020000);			/* Remember if the server supports NTLM */
	memcpy(challenge, &res.packet.auth.challenge, sizeof(challenge));
	memcpy(ntdomain, &res.packet.auth.NTLMSSP[res.packet.auth.target.offset], res.packet.auth.target.len);
	ntdomain[res.packet.auth.target.len] = 0;

#ifdef DEBUG_MSPROXY
	printf ("ntdomain: \"%s\"\n", ntdomain);
	printf ("packet #4\n");
#endif

	bzero(&req, sizeof(req));
	req.clientid			= state->clientid;
	req.serverid			= state->serverid;
	req.command			= htons(MSPROXY_AUTHENTICATE_2);	/* Authentication response			*/
	req.packet.auth2.magic3		= htons(0x0200);			/* Something					*/
	memcpy(req.packet.auth2.NTLMSSP, "NTLMSSP", sizeof("NTLMSSP"));		/* Start of NTLM message				*/
	req.packet.auth2.msgtype		= htonl(0x03000000);			/* Message type 2				*/
	req.packet.auth2.flags		= flags | htonl(0x02000000);		/* Choose authentication method			*/
	data = req.packet.auth2.data;
	if (flags) {
		req.packet.auth2.lm_resp.len	= 0;				/* We are here if NTLM is supported,		*/
		req.packet.auth2.lm_resp.alloc	= 0;				/* Do not fill in insecure LM response		*/
		req.packet.auth2.lm_resp.offset	= data - req.packet.auth2.NTLMSSP;
		req.packet.auth2.ntlm_resp.len = 24;				/* Fill in NTLM response security buffer	*/
		req.packet.auth2.ntlm_resp.alloc = 24;
		req.packet.auth2.ntlm_resp.offset = data - req.packet.auth2.NTLMSSP;
		ntlm_smb_nt_encrypt(prefs.hex_net_proxy_pass, challenge, data);		/* Append an NTLM response			*/
		data += 24;	
	} else {
		req.packet.auth2.lm_resp.len	= 24;				/* Fill in LM response security buffer		*/
		req.packet.auth2.lm_resp.alloc	= 24;
		req.packet.auth2.lm_resp.offset	= data - req.packet.auth2.NTLMSSP;
		ntlm_smb_encrypt(prefs.hex_net_proxy_pass, challenge, data);		/* Append an LM response			*/
		data += 24;
		req.packet.auth2.ntlm_resp.len = 0;				/* NTLM response is empty			*/
		req.packet.auth2.ntlm_resp.alloc = 0;
		req.packet.auth2.ntlm_resp.offset = data - req.packet.auth2.NTLMSSP;
	}
	req.packet.auth2.ntdomain_buf.len = strlen(ntdomain);			/* Domain name					*/
	req.packet.auth2.ntdomain_buf.alloc = req.packet.auth2.ntdomain_buf.len;
	req.packet.auth2.ntdomain_buf.offset = data - req.packet.auth2.NTLMSSP;
	strcpy(data, ntdomain);
	data += req.packet.auth2.ntdomain_buf.len;
	req.packet.auth2.username_buf.len = strlen(prefs.hex_net_proxy_user);		/* Username					*/
	req.packet.auth2.username_buf.alloc = req.packet.auth2.username_buf.len;
	req.packet.auth2.username_buf.offset = data - req.packet.auth2.NTLMSSP;
	strcpy(data, prefs.hex_net_proxy_user);
	data += req.packet.auth2.username_buf.len;
	req.packet.auth2.clienthost_buf.len = strlen(hostname);			/* Hostname					*/
	req.packet.auth2.clienthost_buf.alloc = req.packet.auth2.clienthost_buf.len;
	req.packet.auth2.clienthost_buf.offset = data - req.packet.auth2.NTLMSSP;
	strcpy(data, hostname);
	data += req.packet.auth2.clienthost_buf.len;
	req.packet.auth2.sessionkey_buf.len = 0;				/* Session key (we don't use it)		*/
	req.packet.auth2.sessionkey_buf.alloc = 0;
	req.packet.auth2.sessionkey_buf.offset = data - req.packet.auth2.NTLMSSP;

	if (send_msprequest(sok, state, &req, data) == -1)
		return 1;

	if (recv_mspresponse(sok, state, &res) == -1)
		return 1;

	if (res.serverid != state->serverid) {
#ifdef DEBUG_MSPROXY
		printf ("expected res.serverid = 0x%x, is 0x%x\n", state->serverid, res.serverid);
#endif
		return 1;
	}

	if (res.clientack != 0x01) {
#ifdef DEBUG_MSPROXY
		printf ("expected res.clientack = 0x01, is 0x%x\n", res.clientack);
#endif
		return 1;
	}

	if (ntohs(res.command) >> 8 != 0x47) {
#ifdef DEBUG_MSPROXY
		printf ("expected res.command = 47??, is 0x%x\n", ntohs(res.command));
#endif
		return 1;
	}

	if (ntohs(res.command) ==  MSPROXY_AUTHENTICATE_2_NAK) {
#ifdef DEBUG_MSPROXY
		printf ("Authentication failed\n");
#endif
		return -1;
	}

#ifdef DEBUG_MSPROXY
	printf ("packet #5\n");
#endif

	bzero(&req, sizeof(req));
	req.clientid			= state->clientid;
	req.serverid			= state->serverid;
	req.command			= htons(MSPROXY_CONNECT);
	req.packet.connect.magic2	= htons(0x0200);
	req.packet.connect.magic6	= htons(0x0200);
	req.packet.connect.destport	= htons(port);
	req.packet.connect.destaddr	= destaddr;
	data = req.packet.connect.executable;
	strcpy(data, MSPROXY_EXECUTABLE);
	data += strlen(MSPROXY_EXECUTABLE) + 1;

	/*
	 * need to tell server what port we will connect from, so we bind our sockets.
	 */
	ns_client = net_store_new ();
	if (!bound) {
		net_store_fill_any (ns_client);
		net_bind(ns_client, csok4, csok6);
#ifdef DEBUG_MSPROXY
		perror ("bind() result");
#endif
	}
 	clientport = net_getsockport(csok4, csok6);
	if (clientport == -1) {
#ifdef DEBUG_MSPROXY
		printf ("Unable to obtain source port\n");
#endif
		return 1;
	}
	req.packet.connect.srcport = clientport;

	if (send_msprequest(sok, state, &req, data) == -1)
		return 1;

	if (recv_mspresponse(sok, state, &res) == -1)
		return 1;

	if (ntohs(res.command) != MSPROXY_CONNECT_ACK) {
#ifdef DEBUG_MSPROXY
		printf ("expected res.command = 0x%x, is 0x%x\n",MSPROXY_CONNECT_ACK, ntohs(res.command));
#endif
		return 1;
	}

	net_store_fill_v4 (ns_client, res.packet.connect.clientaddr, res.packet.connect.clientport);

#ifdef DEBUG_MSPROXY
	printf ("Connecting...\n");
#endif
	if (net_connect (ns_client, csok4, csok6, csok) != 0) {
#ifdef DEBUG_MSPROXY
		printf ("Failed to connect to port %d\n", htons(res.packet.connect.clientport));
#endif
		net_store_destroy (ns_client);
		return 1;
	}
	net_store_destroy (ns_client);
#ifdef DEBUG_MSPROXY
	printf ("packet #6\n");
#endif

	req.clientid	= state->clientid;
	req.serverid	= state->serverid;
	req.command	= htons(MSPROXY_USERINFO_ACK);		

	if (send_msprequest(sok, state, &req, req.packet.connack.data) == -1)
		return 1;

	return 0;
}

void
msproxy_keepalive (void)
{
	server *serv;
	GSList *list = serv_list;
	struct msproxy_request_t req;
	struct msproxy_response_t res;

	while (list)
	{
		serv = list->data;
		if (serv->connected && (serv->proxy_sok != -1))
		{
#ifdef DEBUG_MSPROXY
			printf ("sending MS proxy keepalive packet\n");
#endif

			bzero(&req, sizeof(req));
			req.clientid	= serv->msp_state.clientid;
			req.serverid	= serv->msp_state.serverid;
			req.command	= htons(MSPROXY_HELLO);
			
			if (send_msprequest(serv->proxy_sok, &serv->msp_state, &req, req.packet.hello.data) == -1)
				continue;

			recv_mspresponse(serv->proxy_sok, &serv->msp_state, &res);

#ifdef DEBUG_MSPROXY
			if (ntohs(res.command) != MSPROXY_USERINFO_ACK)
				printf ("expected res.command = 0x%x, is 0x%x\n", MSPROXY_USERINFO_ACK, ntohs(res.command));
#endif
		}
		list = list->next;
	}
}

#endif