ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/releases/ircd-hybrid-8.0.0beta1/modules/m_connect.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (15 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_connect.c
File size: 8899 byte(s)
Log Message:
- cleanup module loader. Make module api more flexible

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "handlers.h"
27     #include "client.h"
28     #include "ircd.h"
29     #include "irc_string.h"
30     #include "numeric.h"
31     #include "fdlist.h"
32     #include "s_bsd.h"
33     #include "s_conf.h"
34     #include "s_log.h"
35     #include "s_serv.h"
36     #include "send.h"
37     #include "msg.h"
38     #include "parse.h"
39     #include "hash.h"
40     #include "modules.h"
41    
42    
43     /*
44     * mo_connect - CONNECT command handler
45     *
46     * Added by Jto 11 Feb 1989
47     *
48     * m_connect
49     * parv[0] = sender prefix
50     * parv[1] = servername
51     * parv[2] = port number
52     * parv[3] = remote server
53     */
54     static void
55 michael 971 mo_connect(struct Client *client_p, struct Client *source_p,
56     int parc, char *parv[])
57 adx 30 {
58     int port;
59     int tmpport;
60     struct ConfItem *conf = NULL;
61     struct AccessItem *aconf = NULL;
62 michael 971 const struct Client *target_p = NULL;
63 adx 30
64 michael 971 if (EmptyString(parv[1]))
65 adx 30 {
66 michael 971 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
67     me.name, source_p->name, "CONNECT");
68 adx 30 return;
69     }
70    
71 michael 971 if (parc > 3)
72     {
73 michael 1219 if (!HasOFlag(source_p, OPER_FLAG_REMOTE))
74 michael 971 {
75     sendto_one(source_p, form_str(ERR_NOPRIVS),
76     me.name, source_p->name, "connect");
77     return;
78     }
79 adx 30
80 michael 971 if (hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3,
81     parc, parv) != HUNTED_ISME)
82     return;
83 adx 30 }
84    
85 michael 1169 if ((target_p = hash_find_server(parv[1])))
86 adx 30 {
87     sendto_one(source_p,
88     ":%s NOTICE %s :Connect: Server %s already exists from %s.",
89     me.name, source_p->name, parv[1], target_p->from->name);
90     return;
91     }
92    
93     /*
94     * try to find the name, then host, if both fail notify ops and bail
95     */
96     if ((conf = find_matching_name_conf(SERVER_TYPE,
97     parv[1], NULL, NULL, 0)) != NULL)
98     aconf = (struct AccessItem *)map_to_conf(conf);
99     else if ((conf = find_matching_name_conf(SERVER_TYPE,
100     NULL, NULL, parv[1], 0)) != NULL)
101     aconf = (struct AccessItem *)map_to_conf(conf);
102    
103 michael 971 if (conf == NULL || aconf == NULL)
104 adx 30 {
105     sendto_one(source_p,
106     ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
107     me.name, source_p->name, parv[1]);
108     return;
109     }
110 michael 971
111 adx 30 /* Get port number from user, if given. If not specified,
112     * use the default form configuration structure. If missing
113     * from there, then use the precompiled default.
114     */
115     tmpport = port = aconf->port;
116    
117     if (parc > 2 && !EmptyString(parv[2]))
118     {
119     if ((port = atoi(parv[2])) <= 0)
120     {
121     sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number",
122     me.name, source_p->name);
123     return;
124     }
125     }
126     else if (port <= 0 && (port = PORTNUM) <= 0)
127     {
128     sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number",
129     me.name, source_p->name);
130     return;
131     }
132    
133     if (find_servconn_in_progress(conf->name))
134     {
135     sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
136     "is already in progress.", me.name, source_p->name, conf->name);
137     return;
138     }
139    
140     /*
141     * Notify all operators about remote connect requests
142     */
143     ilog(L_TRACE, "CONNECT From %s : %s %s",
144     source_p->name, parv[1], parv[2] ? parv[2] : "");
145    
146     aconf->port = port;
147    
148     /* at this point we should be calling connect_server with a valid
149     * C:line and a valid port in the C:line
150     */
151     if (serv_connect(aconf, source_p))
152     {
153 michael 1219 if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
154 adx 30 sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d",
155     me.name, source_p->name, aconf->host,
156     conf->name, aconf->port);
157     else
158     sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
159     me.name, source_p->name, conf->name, aconf->port);
160     }
161     else
162     {
163     sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
164     me.name, source_p->name, conf->name, aconf->port);
165     }
166    
167     /* client is either connecting with all the data it needs or has been
168     * destroyed
169     */
170     aconf->port = tmpport;
171     }
172    
173     /*
174     * ms_connect - CONNECT command handler
175     *
176     * Added by Jto 11 Feb 1989
177     *
178     * m_connect
179     * parv[0] = sender prefix
180     * parv[1] = servername
181     * parv[2] = port number
182     * parv[3] = remote server
183     */
184     static void
185     ms_connect(struct Client *client_p, struct Client *source_p,
186     int parc, char *parv[])
187     {
188     int port;
189     int tmpport;
190     struct ConfItem *conf = NULL;
191     struct AccessItem *aconf = NULL;
192 michael 971 const struct Client *target_p = NULL;
193 adx 30
194     if (hunt_server(client_p, source_p,
195     ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
196     return;
197    
198     if (*parv[1] == '\0')
199     {
200     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
201     me.name, source_p->name, "CONNECT");
202     return;
203     }
204    
205 michael 1169 if ((target_p = hash_find_server(parv[1])))
206 adx 30 {
207     sendto_one(source_p,
208     ":%s NOTICE %s :Connect: Server %s already exists from %s.",
209     me.name, source_p->name, parv[1], target_p->from->name);
210     return;
211     }
212    
213     /*
214     * try to find the name, then host, if both fail notify ops and bail
215     */
216     if ((conf = find_matching_name_conf(SERVER_TYPE,
217     parv[1], NULL, NULL, 0)) != NULL)
218 michael 971 aconf = map_to_conf(conf);
219 adx 30 else if ((conf = find_matching_name_conf(SERVER_TYPE,
220     NULL, NULL, parv[1], 0)) != NULL)
221 michael 971 aconf = map_to_conf(conf);
222 adx 30
223 michael 971 if (conf == NULL || aconf == NULL)
224 adx 30 {
225     sendto_one(source_p,
226     ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
227     me.name, source_p->name, parv[1]);
228     return;
229     }
230    
231     /* Get port number from user, if given. If not specified,
232     * use the default form configuration structure. If missing
233     * from there, then use the precompiled default.
234     */
235     tmpport = port = aconf->port;
236    
237     if (parc > 2 && !EmptyString(parv[2]))
238     {
239     port = atoi(parv[2]);
240    
241     /* if someone sends port 0, and we have a config port.. use it */
242     if (port == 0 && aconf->port)
243     port = aconf->port;
244     else if (port <= 0)
245     {
246     sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number",
247     me.name, source_p->name);
248     return;
249     }
250     }
251     else if (port <= 0 && (port = PORTNUM) <= 0)
252     {
253     sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number",
254     me.name, source_p->name);
255     return;
256     }
257    
258     if (find_servconn_in_progress(conf->name))
259     {
260     sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
261     "is already in progress.", me.name, source_p->name, conf->name);
262     return;
263     }
264    
265     /*
266     * Notify all operators about remote connect requests
267     */
268     sendto_wallops_flags(UMODE_WALLOP, &me, "Remote CONNECT %s %d from %s",
269     parv[1], port, source_p->name);
270 michael 885 sendto_server(NULL, NULL, NOCAPS, NOCAPS,
271 adx 30 ":%s WALLOPS :Remote CONNECT %s %d from %s",
272     me.name, parv[1], port, source_p->name);
273    
274     ilog(L_TRACE, "CONNECT From %s : %s %d",
275     source_p->name, parv[1], port);
276    
277     aconf->port = port;
278    
279 michael 885 /*
280     * At this point we should be calling connect_server with a valid
281 adx 30 * C:line and a valid port in the C:line
282     */
283     if (serv_connect(aconf, source_p))
284     sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
285     me.name, source_p->name, conf->name, aconf->port);
286     else
287     sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
288     me.name, source_p->name, conf->name, aconf->port);
289 michael 885 /*
290     * Client is either connecting with all the data it needs or has been
291 adx 30 * destroyed
292     */
293     aconf->port = tmpport;
294     }
295 michael 1230
296     static struct Message connect_msgtab = {
297     "CONNECT", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
298     { m_unregistered, m_not_oper, ms_connect, m_ignore, mo_connect, m_ignore }
299     };
300    
301     static void
302     module_init(void)
303     {
304     mod_add_cmd(&connect_msgtab);
305     }
306    
307     static void
308     module_exit(void)
309     {
310     mod_del_cmd(&connect_msgtab);
311     }
312    
313     struct module module_entry = {
314     .node = { NULL, NULL, NULL },
315     .name = NULL,
316     .version = "$Revision$",
317     .handle = NULL,
318     .modinit = module_init,
319     .modexit = module_exit,
320     .flags = 0
321     };

Properties

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