ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_connect.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 8804 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


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

Properties

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