ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/branches/newio/modules/m_webirc.c
Revision: 1543
Committed: Sun Sep 30 11:23:41 2012 UTC (13 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/contrib/m_webirc.c
File size: 5687 byte(s)
Error occurred while calculating annotation data.
Log Message:
- m_webirc.c: fixed typo in comment

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

Properties

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