1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_webirc.c: Makes CGI:IRC users appear as coming from their real host |
4 |
* |
5 |
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center |
6 |
* Copyright (C) 2002-2006 ircd-ratbox development team |
7 |
* Copyright (C) 1996-2012 Hybrid Development Team |
8 |
* |
9 |
* This program is free software; you can redistribute it and/or modify |
10 |
* it under the terms of the GNU General Public License as published by |
11 |
* the Free Software Foundation; either version 2 of the License, or |
12 |
* (at your option) any later version. |
13 |
* |
14 |
* This program is distributed in the hope that it will be useful, |
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
* GNU General Public License for more details. |
18 |
* |
19 |
* You should have received a copy of the GNU General Public License |
20 |
* along with this program; if not, write to the Free Software |
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
22 |
* USA |
23 |
* |
24 |
* $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "client.h" |
30 |
#include "ircd.h" |
31 |
#include "numeric.h" |
32 |
#include "send.h" |
33 |
#include "irc_string.h" |
34 |
#include "hash.h" |
35 |
#include "parse.h" |
36 |
#include "modules.h" |
37 |
#include "conf.h" |
38 |
#include "hostmask.h" |
39 |
|
40 |
|
41 |
static int |
42 |
invalid_hostname(const char *hostname) |
43 |
{ |
44 |
const char *p = hostname; |
45 |
unsigned int has_sep = 0; |
46 |
|
47 |
assert(p != NULL); |
48 |
|
49 |
if (*p == '.' || *p == ':') |
50 |
return 1; |
51 |
|
52 |
for (; *p; ++p) |
53 |
{ |
54 |
if (!IsHostChar(*p)) |
55 |
return 1; |
56 |
if (*p == '.' || *p == ':') |
57 |
++has_sep; |
58 |
} |
59 |
|
60 |
return !has_sep; |
61 |
} |
62 |
|
63 |
/* |
64 |
* mr_webirc |
65 |
* parv[0] = sender prefix |
66 |
* parv[1] = password |
67 |
* parv[2] = fake username (we ignore this) |
68 |
* parv[3] = fake hostname |
69 |
* parv[4] = fake ip |
70 |
*/ |
71 |
static void |
72 |
mr_webirc(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) |
73 |
{ |
74 |
struct MaskItem *conf = NULL; |
75 |
struct addrinfo hints, *res; |
76 |
|
77 |
assert(source_p == client_p); |
78 |
|
79 |
if (invalid_hostname(parv[4])) |
80 |
{ |
81 |
sendto_one(source_p, ":%s NOTICE %s :CGI:IRC: Invalid IP", me.name, |
82 |
source_p->name[0] ? source_p->name : "*"); |
83 |
return; |
84 |
} |
85 |
|
86 |
conf = find_address_conf(source_p->host, |
87 |
IsGotId(source_p) ? source_p->username : "webirc", |
88 |
&source_p->localClient->ip, |
89 |
source_p->localClient->aftype, parv[1]); |
90 |
if (conf == NULL || !IsConfClient(conf)) |
91 |
return; |
92 |
|
93 |
if (!IsConfWebIRC(conf)) |
94 |
{ |
95 |
sendto_one(source_p, ":%s NOTICE %s :Not a CGI:IRC auth block", me.name, |
96 |
source_p->name[0] ? source_p->name : "*"); |
97 |
return; |
98 |
} |
99 |
|
100 |
if (EmptyString(conf->passwd)) |
101 |
{ |
102 |
sendto_one(source_p, ":%s NOTICE %s :CGI:IRC auth blocks must have a password", |
103 |
me.name, source_p->name[0] ? source_p->name : "*"); |
104 |
return; |
105 |
} |
106 |
|
107 |
if (!match_conf_password(parv[1], conf)) |
108 |
{ |
109 |
sendto_one(source_p, ":%s NOTICE %s :CGI:IRC password incorrect", |
110 |
me.name, source_p->name[0] ? source_p->name : "*"); |
111 |
return; |
112 |
} |
113 |
|
114 |
memset(&hints, 0, sizeof(hints)); |
115 |
|
116 |
hints.ai_family = AF_UNSPEC; |
117 |
hints.ai_socktype = SOCK_STREAM; |
118 |
hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; |
119 |
|
120 |
if (getaddrinfo(parv[4], NULL, &hints, &res)) |
121 |
{ |
122 |
|
123 |
sendto_one(source_p, ":%s NOTICE %s :Invalid CGI:IRC IP %s", me.name, |
124 |
source_p->name[0] ? source_p->name : "*", parv[4]); |
125 |
return; |
126 |
} |
127 |
|
128 |
assert(res != NULL); |
129 |
|
130 |
memcpy(&source_p->localClient->ip, res->ai_addr, res->ai_addrlen); |
131 |
source_p->localClient->ip.ss_len = res->ai_addrlen; |
132 |
source_p->localClient->ip.ss.ss_family = res->ai_family; |
133 |
source_p->localClient->aftype = res->ai_family; |
134 |
freeaddrinfo(res); |
135 |
|
136 |
strlcpy(source_p->sockhost, parv[4], sizeof(source_p->sockhost)); |
137 |
|
138 |
if (strlen(parv[3]) <= HOSTLEN) |
139 |
strlcpy(source_p->host, parv[3], sizeof(source_p->host)); |
140 |
else |
141 |
strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host)); |
142 |
|
143 |
/* Check dlines now, k/glines will be checked on registration */ |
144 |
if ((conf = find_dline_conf(&client_p->localClient->ip, |
145 |
client_p->localClient->aftype))) |
146 |
{ |
147 |
if (!(conf->type == CONF_EXEMPT)) |
148 |
{ |
149 |
exit_client(client_p, &me, "D-lined"); |
150 |
return; |
151 |
} |
152 |
} |
153 |
|
154 |
sendto_one(source_p, ":%s NOTICE %s :CGI:IRC host/IP set to %s %s", me.name, |
155 |
source_p->name[0] ? source_p->name : "*", parv[3], parv[4]); |
156 |
} |
157 |
|
158 |
static struct Message webirc_msgtab = { |
159 |
"WEBIRC", 0, 0, 5, MAXPARA, MFLG_SLOW, 0, |
160 |
{ mr_webirc, m_ignore, m_ignore, m_ignore, m_ignore, m_ignore } |
161 |
}; |
162 |
|
163 |
static void |
164 |
module_init(void) |
165 |
{ |
166 |
mod_add_cmd(&webirc_msgtab); |
167 |
} |
168 |
|
169 |
static void |
170 |
module_exit(void) |
171 |
{ |
172 |
mod_del_cmd(&webirc_msgtab); |
173 |
} |
174 |
|
175 |
struct module module_entry = { |
176 |
.node = { NULL, NULL, NULL }, |
177 |
.name = NULL, |
178 |
.version = "$Revision$", |
179 |
.handle = NULL, |
180 |
.modinit = module_init, |
181 |
.modexit = module_exit, |
182 |
.flags = 0 |
183 |
}; |