ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_webirc.c
Revision: 2274
Committed: Tue Jun 18 16:01:57 2013 UTC (12 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 4885 byte(s)
Log Message:
- Sort out unused header includes

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 "send.h"
32 #include "irc_string.h"
33 #include "parse.h"
34 #include "modules.h"
35 #include "conf.h"
36 #include "hostmask.h"
37
38
39 static int
40 invalid_hostname(const char *hostname)
41 {
42 const char *p = hostname;
43 unsigned int has_sep = 0;
44
45 assert(p != NULL);
46
47 if (*p == '.' || *p == ':')
48 return 1;
49
50 for (; *p; ++p)
51 {
52 if (!IsHostChar(*p))
53 return 1;
54 if (*p == '.' || *p == ':')
55 ++has_sep;
56 }
57
58 return !has_sep;
59 }
60
61 /*
62 * mr_webirc
63 * parv[0] = sender prefix
64 * parv[1] = password
65 * parv[2] = fake username (we ignore this)
66 * parv[3] = fake hostname
67 * parv[4] = fake ip
68 */
69 static void
70 mr_webirc(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
71 {
72 struct MaskItem *conf = NULL;
73 struct addrinfo hints, *res;
74
75 assert(source_p == client_p);
76
77 if (invalid_hostname(parv[4]))
78 {
79 sendto_one(source_p, ":%s NOTICE %s :CGI:IRC: Invalid IP", me.name,
80 source_p->name[0] ? source_p->name : "*");
81 return;
82 }
83
84 conf = find_address_conf(source_p->host,
85 IsGotId(source_p) ? source_p->username : "webirc",
86 &source_p->localClient->ip,
87 source_p->localClient->aftype, parv[1]);
88 if (conf == NULL || !IsConfClient(conf))
89 return;
90
91 if (!IsConfWebIRC(conf))
92 {
93 sendto_one(source_p, ":%s NOTICE %s :Not a CGI:IRC auth block", me.name,
94 source_p->name[0] ? source_p->name : "*");
95 return;
96 }
97
98 if (EmptyString(conf->passwd))
99 {
100 sendto_one(source_p, ":%s NOTICE %s :CGI:IRC auth blocks must have a password",
101 me.name, source_p->name[0] ? source_p->name : "*");
102 return;
103 }
104
105 if (!match_conf_password(parv[1], conf))
106 {
107 sendto_one(source_p, ":%s NOTICE %s :CGI:IRC password incorrect",
108 me.name, source_p->name[0] ? source_p->name : "*");
109 return;
110 }
111
112 memset(&hints, 0, sizeof(hints));
113
114 hints.ai_family = AF_UNSPEC;
115 hints.ai_socktype = SOCK_STREAM;
116 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
117
118 if (getaddrinfo(parv[4], NULL, &hints, &res))
119 {
120
121 sendto_one(source_p, ":%s NOTICE %s :Invalid CGI:IRC IP %s", me.name,
122 source_p->name[0] ? source_p->name : "*", parv[4]);
123 return;
124 }
125
126 assert(res != NULL);
127
128 memcpy(&source_p->localClient->ip, res->ai_addr, res->ai_addrlen);
129 source_p->localClient->ip.ss_len = res->ai_addrlen;
130 source_p->localClient->ip.ss.ss_family = res->ai_family;
131 source_p->localClient->aftype = res->ai_family;
132 freeaddrinfo(res);
133
134 strlcpy(source_p->sockhost, parv[4], sizeof(source_p->sockhost));
135
136 if (strlen(parv[3]) <= HOSTLEN)
137 strlcpy(source_p->host, parv[3], sizeof(source_p->host));
138 else
139 strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
140
141 /* Check dlines now, k/glines will be checked on registration */
142 if ((conf = find_dline_conf(&client_p->localClient->ip,
143 client_p->localClient->aftype)))
144 {
145 if (!(conf->type == CONF_EXEMPT))
146 {
147 exit_client(client_p, &me, "D-lined");
148 return;
149 }
150 }
151
152 sendto_one(source_p, ":%s NOTICE %s :CGI:IRC host/IP set to %s %s", me.name,
153 source_p->name[0] ? source_p->name : "*", parv[3], parv[4]);
154 }
155
156 static struct Message webirc_msgtab = {
157 "WEBIRC", 0, 0, 5, MAXPARA, MFLG_SLOW, 0,
158 { mr_webirc, m_ignore, m_ignore, m_ignore, m_ignore, m_ignore }
159 };
160
161 static void
162 module_init(void)
163 {
164 mod_add_cmd(&webirc_msgtab);
165 }
166
167 static void
168 module_exit(void)
169 {
170 mod_del_cmd(&webirc_msgtab);
171 }
172
173 struct module module_entry = {
174 .node = { NULL, NULL, NULL },
175 .name = NULL,
176 .version = "$Revision$",
177 .handle = NULL,
178 .modinit = module_init,
179 .modexit = module_exit,
180 .flags = 0
181 };

Properties

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