/[svn]/ircd-hybrid/trunk/modules/m_webirc.c
ViewVC logotype

Contents of /ircd-hybrid/trunk/modules/m_webirc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1689 - (show annotations)
Wed Dec 19 21:43:32 2012 UTC (7 years, 6 months ago) by michael
File MIME type: text/x-chdr
File size: 5606 byte(s)
- Fixed WEBIRC module

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 * Usage:
42 *
43 * auth {
44 * user = "webirc@<cgiirc ip>"; # if identd used, put ident username instead
45 * password = "<password>"; # encryption possible
46 * spoof = "webirc."
47 * class = "users";
48 * encrypted = yes; # [Using encryption is highly recommended]
49 * };
50 *
51 * Possible flags:
52 * kline_exempt - k/g lines on the cgiirc ip are ignored
53 * gline_exempt - glines on the cgiirc ip are ignored
54 *
55 * dlines are checked on the cgiirc ip (of course).
56 * k/d/g/x lines, auth blocks, user limits, etc are checked using the
57 * real host/ip.
58 *
59 * The password should be specified unencrypted in webirc_password in
60 * cgiirc.config
61 */
62
63 static int
64 invalid_hostname(const char *hostname)
65 {
66 const char *p = hostname;
67 unsigned int has_sep = 0;
68
69 assert(p != NULL);
70
71 if (*p == '.' || *p == ':')
72 return 1;
73
74 for (; *p; ++p)
75 {
76 if (!IsHostChar(*p))
77 return 1;
78 if (*p == '.' || *p == ':')
79 ++has_sep;
80 }
81
82 return !has_sep;
83 }
84
85 /*
86 * mr_webirc
87 * parv[0] = sender prefix
88 * parv[1] = password
89 * parv[2] = fake username (we ignore this)
90 * parv[3] = fake hostname
91 * parv[4] = fake ip
92 */
93 static void
94 mr_webirc(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
95 {
96 struct MaskItem *conf = NULL;
97 struct addrinfo hints, *res;
98
99 assert(source_p == client_p);
100
101 if (invalid_hostname(parv[4]))
102 {
103 sendto_one(source_p, ":%s NOTICE %s :CGI:IRC: Invalid IP", me.name,
104 source_p->name[0] ? source_p->name : "*");
105 return;
106 }
107
108 conf = find_address_conf(source_p->host,
109 IsGotId(source_p) ? source_p->username : "webirc",
110 &source_p->localClient->ip,
111 source_p->localClient->aftype, parv[1]);
112 if (conf == NULL || !IsConfClient(conf))
113 return;
114
115 if (!IsConfDoSpoofIp(conf) || irccmp(conf->name, "webirc."))
116 {
117 sendto_one(source_p, ":%s NOTICE %s :Not a CGI:IRC auth block", me.name,
118 source_p->name[0] ? source_p->name : "*");
119 return;
120 }
121
122 if (EmptyString(conf->passwd))
123 {
124 sendto_one(source_p, ":%s NOTICE %s :CGI:IRC auth blocks must have a password",
125 me.name, source_p->name[0] ? source_p->name : "*");
126 return;
127 }
128
129 if (!match_conf_password(parv[1], conf))
130 {
131 sendto_one(source_p, ":%s NOTICE %s :CGI:IRC password incorrect",
132 me.name, source_p->name[0] ? source_p->name : "*");
133 return;
134 }
135
136 memset(&hints, 0, sizeof(hints));
137
138 hints.ai_family = AF_UNSPEC;
139 hints.ai_socktype = SOCK_STREAM;
140 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
141
142 if (getaddrinfo(parv[4], NULL, &hints, &res))
143 {
144
145 sendto_one(source_p, ":%s NOTICE %s :Invalid CGI:IRC IP %s", me.name,
146 source_p->name[0] ? source_p->name : "*", parv[4]);
147 return;
148 }
149
150 assert(res != NULL);
151
152 memcpy(&source_p->localClient->ip, res->ai_addr, res->ai_addrlen);
153 source_p->localClient->ip.ss_len = res->ai_addrlen;
154 source_p->localClient->ip.ss.ss_family = res->ai_family;
155 source_p->localClient->aftype = res->ai_family;
156 freeaddrinfo(res);
157
158 strlcpy(source_p->sockhost, parv[4], sizeof(source_p->sockhost));
159
160 if (strlen(parv[3]) <= HOSTLEN)
161 strlcpy(source_p->host, parv[3], sizeof(source_p->host));
162 else
163 strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
164
165 /* Check dlines now, k/glines will be checked on registration */
166 if ((conf = find_dline_conf(&client_p->localClient->ip,
167 client_p->localClient->aftype)))
168 {
169 if (!(conf->type == CONF_EXEMPT))
170 {
171 exit_client(client_p, &me, "D-lined");
172 return;
173 }
174 }
175
176 sendto_one(source_p, ":%s NOTICE %s :CGI:IRC host/IP set to %s %s", me.name,
177 source_p->name[0] ? source_p->name : "*", parv[3], parv[4]);
178 }
179
180 static struct Message webirc_msgtab = {
181 "WEBIRC", 0, 0, 5, MAXPARA, MFLG_SLOW, 0,
182 { mr_webirc, m_ignore, m_ignore, m_ignore, m_ignore, m_ignore }
183 };
184
185 static void
186 module_init(void)
187 {
188 mod_add_cmd(&webirc_msgtab);
189 }
190
191 static void
192 module_exit(void)
193 {
194 mod_del_cmd(&webirc_msgtab);
195 }
196
197 struct module module_entry = {
198 .node = { NULL, NULL, NULL },
199 .name = NULL,
200 .version = "$Revision$",
201 .handle = NULL,
202 .modinit = module_init,
203 .modexit = module_exit,
204 .flags = 0
205 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28