ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.0.x/modules/m_webirc.c
Revision: 1822
Committed: Sun Apr 14 12:36:55 2013 UTC (13 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 5756 byte(s)
Log Message:
- Added preliminary support for ISO 3166 alpha-2 two letter country code
  enabled auth{} blocks. Requires libGeoIP.
- Added no_join to auth::flags

File Contents

# Content
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 AccessItem *aconf = NULL;
97 struct ConfItem *conf = NULL;
98 struct addrinfo hints, *res;
99
100 assert(source_p == client_p);
101
102 if (invalid_hostname(parv[4]))
103 {
104 sendto_one(source_p, ":%s NOTICE %s :CGI:IRC: Invalid IP", me.name,
105 source_p->name[0] ? source_p->name : "*");
106 return;
107 }
108
109 aconf = find_address_conf(source_p->host,
110 IsGotId(source_p) ? source_p->username : "webirc",
111 &source_p->localClient->ip,
112 source_p->localClient->aftype, parv[1],
113 source_p->localClient->country_id);
114 if (aconf == NULL || !IsConfClient(aconf))
115 return;
116
117 conf = unmap_conf_item(aconf);
118
119 if (!IsConfDoSpoofIp(aconf) || irccmp(conf->name, "webirc."))
120 {
121 sendto_one(source_p, ":%s NOTICE %s :Not a CGI:IRC auth block", me.name,
122 source_p->name[0] ? source_p->name : "*");
123 return;
124 }
125
126 if (EmptyString(aconf->passwd))
127 {
128 sendto_one(source_p, ":%s NOTICE %s :CGI:IRC auth blocks must have a password",
129 me.name, source_p->name[0] ? source_p->name : "*");
130 return;
131 }
132
133 if (!match_conf_password(parv[1], aconf))
134 {
135 sendto_one(source_p, ":%s NOTICE %s :CGI:IRC password incorrect",
136 me.name, source_p->name[0] ? source_p->name : "*");
137 return;
138 }
139
140 memset(&hints, 0, sizeof(hints));
141
142 hints.ai_family = AF_UNSPEC;
143 hints.ai_socktype = SOCK_STREAM;
144 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
145
146 if (getaddrinfo(parv[4], NULL, &hints, &res))
147 {
148
149 sendto_one(source_p, ":%s NOTICE %s :Invalid CGI:IRC IP %s", me.name,
150 source_p->name[0] ? source_p->name : "*", parv[4]);
151 return;
152 }
153
154 assert(res != NULL);
155
156 memcpy(&source_p->localClient->ip, res->ai_addr, res->ai_addrlen);
157 source_p->localClient->ip.ss_len = res->ai_addrlen;
158 source_p->localClient->ip.ss.ss_family = res->ai_family;
159 source_p->localClient->aftype = res->ai_family;
160 freeaddrinfo(res);
161
162 strlcpy(source_p->sockhost, parv[4], sizeof(source_p->sockhost));
163
164 if (strlen(parv[3]) <= HOSTLEN)
165 strlcpy(source_p->host, parv[3], sizeof(source_p->host));
166 else
167 strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
168
169 /* Check dlines now, k/glines will be checked on registration */
170 if ((aconf = find_dline_conf(&client_p->localClient->ip,
171 client_p->localClient->aftype)))
172 {
173 if (!(aconf->status & CONF_EXEMPTDLINE))
174 {
175 exit_client(client_p, &me, "D-lined");
176 return;
177 }
178 }
179
180 sendto_one(source_p, ":%s NOTICE %s :CGI:IRC host/IP set to %s %s", me.name,
181 source_p->name[0] ? source_p->name : "*", parv[3], parv[4]);
182 }
183
184 static struct Message webirc_msgtab = {
185 "WEBIRC", 0, 0, 5, MAXPARA, MFLG_SLOW, 0,
186 { mr_webirc, m_ignore, m_ignore, m_ignore, m_ignore, m_ignore }
187 };
188
189 static void
190 module_init(void)
191 {
192 mod_add_cmd(&webirc_msgtab);
193 }
194
195 static void
196 module_exit(void)
197 {
198 mod_del_cmd(&webirc_msgtab);
199 }
200
201 struct module module_entry = {
202 .node = { NULL, NULL, NULL },
203 .name = NULL,
204 .version = "$Revision$",
205 .handle = NULL,
206 .modinit = module_init,
207 .modexit = module_exit,
208 .flags = 0
209 };

Properties

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