ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_connect.c
Revision: 614
Committed: Sat May 20 15:06:23 2006 UTC (19 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 9294 byte(s)
Log Message:
- Use get_oper_name() in each place an oper action is logged.
  (KLINE/XLINE/DLINE, etc.)

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_connect.c: Connects to a remote IRC server.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "handlers.h"
27 #include "client.h"
28 #include "ircd.h"
29 #include "numeric.h"
30 #include "s_conf.h"
31 #include "s_serv.h"
32 #include "send.h"
33 #include "msg.h"
34 #include "parse.h"
35 #include "hash.h"
36 #include "conf/modules.h"
37
38 static void mo_connect(struct Client *, struct Client *, int, char *[]);
39 static void ms_connect(struct Client *, struct Client *, int, char *[]);
40
41 struct Message connect_msgtab = {
42 "CONNECT", 0, 0, 2, 0, MFLG_SLOW, 0,
43 { m_unregistered, m_not_oper, ms_connect, m_ignore, mo_connect, m_ignore }
44 };
45
46 INIT_MODULE(m_connect, "$Revision$")
47 {
48 mod_add_cmd(&connect_msgtab);
49 }
50
51 CLEANUP_MODULE
52 {
53 mod_del_cmd(&connect_msgtab);
54 }
55
56 /*! \brief CONNECT command handler (called for operators only)
57 *
58 * \param client_p Pointer to allocated Client struct with physical connection
59 * to this server, i.e. with an open socket connected.
60 * \param source_p Pointer to allocated Client struct from which the message
61 * originally comes from. This can be a local or remote client.
62 * \param parc Integer holding the number of supplied arguments.
63 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
64 * pointers.
65 * \note Valid arguments for this command are:
66 * - parv[0] = sender prefix
67 * - parv[1] = servername
68 * - parv[2] = port number
69 * - parv[3] = remote server
70 */
71 static void
72 mo_connect(struct Client *client_p, struct Client *source_p,
73 int parc, char *parv[])
74 {
75 int port = 0;
76 struct ConfItem *conf = NULL;
77 struct AccessItem *aconf = NULL;
78 struct Client *target_p = NULL;
79
80 /* always privileged with handlers */
81 if (MyConnect(source_p) && !IsOperRemote(source_p) && parc > 3)
82 {
83 sendto_one(source_p, form_str(ERR_NOPRIVS),
84 me.name, source_p->name, "connect");
85 return;
86 }
87
88 if (hunt_server(source_p, ":%s CONNECT %s %s :%s", 3,
89 parc, parv) != HUNTED_ISME)
90 return;
91
92 if (EmptyString(parv[1]))
93 {
94 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
95 me.name, source_p->name, "CONNECT");
96 return;
97 }
98
99 if ((target_p = find_server(parv[1])))
100 {
101 sendto_one(source_p,
102 ":%s NOTICE %s :Connect: Server %s already exists from %s.",
103 me.name, source_p->name, parv[1], target_p->from->name);
104 return;
105 }
106
107 /*
108 * Try to find the name, then host, if both fail notify ops and bail
109 */
110 if ((conf = find_matching_name_conf(SERVER_TYPE,
111 parv[1], NULL, NULL, 0)) != NULL)
112 aconf = &conf->conf.AccessItem;
113 else if ((conf = find_matching_name_conf(SERVER_TYPE,
114 NULL, NULL, parv[1], 0)) != NULL)
115 aconf = &conf->conf.AccessItem;
116
117 if (conf == NULL)
118 {
119 sendto_one(source_p,
120 ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
121 me.name, source_p->name, parv[1]);
122 return;
123 }
124
125 /*
126 * Get port number from user, if given. If not specified,
127 * use the default from configuration structure.
128 */
129 port = aconf->port;
130
131 if (parc > 2 && !EmptyString(parv[2]))
132 port = atoi(parv[2]);
133
134 if (port <= 0 || port > 0xFFFF)
135 {
136 sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal or missing port number",
137 me.name, source_p->name);
138 return;
139 }
140
141 if (find_servconn_in_progress(conf->name))
142 {
143 sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
144 "is already in progress.", me.name, source_p->name, conf->name);
145 return;
146 }
147
148 /*
149 * Notify all operators about remote connect requests
150 */
151 ilog(L_TRACE, "CONNECT From %s : %s %s",
152 get_oper_name(source_p), parv[1], parv[2] ? parv[2] : "");
153
154 /*
155 * At this point we should be calling connect_server with a valid
156 * connect{} and a valid port in the connect{}
157 */
158 if (serv_connect(aconf, source_p, port))
159 {
160 if (!ConfigServerHide.hide_server_ips && IsAdmin(source_p))
161 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d",
162 me.name, source_p->name, aconf->host,
163 conf->name, port);
164 else
165 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
166 me.name, source_p->name, conf->name, port);
167 }
168 else
169 sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
170 me.name, source_p->name, conf->name, port);
171 /*
172 * Client is either connecting with all the data it needs or has been
173 * destroyed
174 */
175 }
176
177 /*! \brief CONNECT command handler (called for remote clients only)
178 *
179 * \param client_p Pointer to allocated Client struct with physical connection
180 * to this server, i.e. with an open socket connected.
181 * \param source_p Pointer to allocated Client struct from which the message
182 * originally comes from. This can be a local or remote client.
183 * \param parc Integer holding the number of supplied arguments.
184 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
185 * pointers.
186 * \note Valid arguments for this command are:
187 * - parv[0] = sender prefix
188 * - parv[1] = servername
189 * - parv[2] = port number
190 * - parv[3] = remote server
191 */
192 static void
193 ms_connect(struct Client *client_p, struct Client *source_p,
194 int parc, char *parv[])
195 {
196 int port = 0;
197 struct ConfItem *conf = NULL;
198 struct AccessItem *aconf = NULL;
199 struct Client *target_p = NULL;
200
201 if (hunt_server(source_p, ":%s CONNECT %s %s :%s", 3,
202 parc, parv) != HUNTED_ISME)
203 return;
204
205 if (EmptyString(parv[1]))
206 {
207 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
208 me.name, source_p->name, "CONNECT");
209 return;
210 }
211
212 if ((target_p = find_server(parv[1])))
213 {
214 sendto_one(source_p,
215 ":%s NOTICE %s :Connect: Server %s already exists from %s.",
216 me.name, source_p->name, parv[1], target_p->from->name);
217 return;
218 }
219
220 /*
221 * Try to find the name, then host, if both fail notify ops and bail
222 */
223 if ((conf = find_matching_name_conf(SERVER_TYPE,
224 parv[1], NULL, NULL, 0)) != NULL)
225 aconf = &conf->conf.AccessItem;
226 else if ((conf = find_matching_name_conf(SERVER_TYPE,
227 NULL, NULL, parv[1], 0)) != NULL)
228 aconf = &conf->conf.AccessItem;
229
230 if (aconf == NULL)
231 {
232 sendto_one(source_p,
233 ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
234 me.name, source_p->name, parv[1]);
235 return;
236 }
237
238 assert(aconf != NULL);
239
240 /*
241 * Get port number from user, if given. If not specified,
242 * use the default from configuration structure.
243 */
244 port = aconf->port;
245
246 if (parc > 2 && !EmptyString(parv[2]))
247 {
248 port = atoi(parv[2]);
249
250 /* if someone sends port 0, use the config port instead */
251 if (port == 0)
252 port = aconf->port;
253 }
254
255 if (port <= 0 || port > 0xFFFF)
256 {
257 sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal or missing port number",
258 me.name, source_p->name);
259 return;
260 }
261
262 if (find_servconn_in_progress(conf->name))
263 {
264 sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
265 "is already in progress.", me.name, source_p->name, conf->name);
266 return;
267 }
268
269 /*
270 * Notify all operators about remote connect requests
271 */
272 sendto_wallops_flags(UMODE_WALLOP, &me, "Remote CONNECT %s %d from %s",
273 parv[1], port, source_p->name);
274 sendto_server(NULL, NULL, NULL, NOCAPS, NOCAPS,
275 ":%s WALLOPS :Remote CONNECT %s %d from %s",
276 me.name, parv[1], port, source_p->name);
277
278 ilog(L_TRACE, "CONNECT From %s : %s %d",
279 get_oper_name(source_p), parv[1], port);
280
281 /*
282 * At this point we should be calling connect_server with a valid
283 * connect{} and a valid port in the connect{}
284 */
285 if (serv_connect(aconf, source_p, port))
286 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
287 me.name, source_p->name, conf->name, port);
288 else
289 sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
290 me.name, source_p->name, conf->name, port);
291
292 /*
293 * Client is either connecting with all the data it needs or has been
294 * destroyed
295 */
296 }

Properties

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