summary refs log blame commit diff stats
path: root/src/common/inbound.h
blob: bbba2e223c3e290fe6abb77da56d1eea4d4254ed (plain) (tree)


















                                                                            

                      

                         
 



                                                                                                    




















                                                                                                    













                                                                                                                          

                                                                                                     



                                                                                                            





                                                                                                      

                                                                                                    


                                                                                             

                                                                  

                                                                                             


                                                                                            

                                                                                             
                                       






                                                                                              

                                                          
                                                            

                                                                     



                                                    
/* HexChat
 * Copyright (C) 1998-2010 Peter Zelezny.
 * Copyright (C) 2009-2013 Berke Viktor.
 *
 * 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
 */

#include "proto-irc.h"

#ifndef HEXCHAT_INBOUND_H
#define HEXCHAT_INBOUND_H

void inbound_next_nick (session *sess, char *nick, int error,
								const message_tags_data *tags_data);
void inbound_uback (server *serv, const message_tags_data *tags_data);
void inbound_uaway (server *serv, const message_tags_data *tags_data);
void inbound_account (server *serv, char *nick, char *account,
							 const message_tags_data *tags_data);
void inbound_part (server *serv, char *chan, char *user, char *ip, char *reason,
						 const message_tags_data *tags_data);
void inbound_upart (server *serv, char *chan, char *ip, char *reason,
						  const message_tags_data *tags_data);
void inbound_ukick (server *serv, char *chan, char *kicker, char *reason,
						  const message_tags_data *tags_data);
void inbound_kick (server *serv, char *chan, char *user, char *kicker,
						 char *reason, const message_tags_data *tags_data);
void inbound_notice (server *serv, char *to, char *nick, char *msg, char *ip,
							int id, const message_tags_data *tags_data);
void inbound_quit (server *serv, char *nick, char *ip, char *reason,
						 const message_tags_data *tags_data);
void inbound_topicnew (server *serv, char *nick, char *chan, char *topic,
							  const message_tags_data *tags_data);
void inbound_join (server *serv, char *chan, char *user, char *ip, 
						 char *account, char *realname, 
						 const message_tags_data *tags_data);
void inbound_ujoin (server *serv, char *chan, char *nick, char *ip,
						  const message_tags_data *tags_data);
void inbound_topictime (server *serv, char *chan, char *nick, time_t stamp,
								const message_tags_data *tags_data);
void inbound_topic (server *serv, char *chan, char *topic_text,
						  const message_tags_data *tags_data);
void inbound_user_info_start (session *sess, char *nick,
										const message_tags_data *tags_data);
void inbound_user_info (session *sess, char *chan, char *user, char *host,
								char *servname, char *nick, char *realname, char *account,
								unsigned int away, const message_tags_data *tags_data);
void inbound_foundip (session *sess, char *ip, 
							 const message_tags_data *tags_data);
int inbound_banlist (session *sess, time_t stamp, char *chan, char *mask, 
							char *banner, int is_exemption,
							const message_tags_data *tags_data);
void inbound_ping_reply (session *sess, char *timestring, char *from,
								 const message_tags_data *tags_data);
void inbound_nameslist (server *serv, char *chan, char *names,
								const message_tags_data *tags_data);
int inbound_nameslist_end (server *serv, char *chan,
									const message_tags_data *tags_data);
void inbound_away (server *serv, char *nick, char *msg,
						 const message_tags_data *tags_data);
void inbound_away_notify (server *serv, char *nick, char *reason,
								  const message_tags_data *tags_data);
void inbound_login_start (session *sess, char *nick, char *servname,
								  const message_tags_data *tags_data);
void inbound_login_end (session *sess, char *text,
								const message_tags_data *tags_data);
void inbound_chanmsg (server *serv, session *sess, char *chan, char *from,
							 char *text, char fromme, int id, 
							 const message_tags_data *tags_data);
void clear_channel (session *sess);
void set_topic (session *sess, char *topic, char *stripped_topic);
void inbound_privmsg (server *serv, char *from, char *ip, char *text, int id, 
							 const message_tags_data *tags_data);
void inbound_action (session *sess, char *chan, char *from, char *ip,
							char *text, int fromme, int id,
							const message_tags_data *tags_data);
void inbound_newnick (server *serv, char *nick, char *newnick, int quiet,
							 const message_tags_data *tags_data);
void inbound_identified (server *serv);
void inbound_cap_ack (server *serv, char *nick, char *extensions,
							 const message_tags_data *tags_data);
void inbound_cap_ls (server *serv, char *nick, char *extensions,
							const message_tags_data *tags_data);
void inbound_cap_nak (server *serv, const message_tags_data *tags_data);
void inbound_cap_list (server *serv, char *nick, char *extensions,
							  const message_tags_data *tags_data);
void inbound_sasl_authenticate (server *serv, char *data);
int inbound_sasl_error (server *serv);
void inbound_sasl_supportedmechs (server *serv, char *list);
void do_dns (session *sess, char *nick, char *host,
				 const message_tags_data *tags_data);
gboolean alert_match_word (char *word, char *masks);
gboolean alert_match_text (char *text, char *masks);

#endif
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.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.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.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.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