ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_connect.c
Revision: 7065
Committed: Tue Jan 19 17:18:28 2016 UTC (8 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 8287 byte(s)
Log Message:
- m_connect.c: improve CONNECT logging

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 7007 * Copyright (c) 1997-2016 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 michael 4564 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_connect.c
23     * \brief Includes required functions for processing the CONNECT command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28     #include "client.h"
29     #include "ircd.h"
30     #include "irc_string.h"
31     #include "numeric.h"
32 michael 1309 #include "conf.h"
33     #include "log.h"
34 michael 3347 #include "server.h"
35 adx 30 #include "send.h"
36     #include "parse.h"
37     #include "hash.h"
38     #include "modules.h"
39    
40    
41 michael 3300 /*! \brief CONNECT command handler
42 adx 30 *
43 michael 3300 * \param source_p Pointer to allocated Client struct from which the message
44     * originally comes from. This can be a local or remote client.
45     * \param parc Integer holding the number of supplied arguments.
46     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
47     * pointers.
48     * \note Valid arguments for this command are:
49     * - parv[0] = command
50     * - parv[1] = target server
51     * - parv[2] = port number
52     * - parv[3] = nickname/servername
53 adx 30 */
54 michael 2820 static int
55 michael 3156 mo_connect(struct Client *source_p, int parc, char *parv[])
56 adx 30 {
57 michael 7057 int port = 0;
58 michael 1632 struct MaskItem *conf = NULL;
59 michael 971 const struct Client *target_p = NULL;
60 adx 30
61 michael 971 if (EmptyString(parv[1]))
62 adx 30 {
63 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "CONNECT");
64 michael 2820 return 0;
65 adx 30 }
66    
67 michael 971 if (parc > 3)
68     {
69 michael 2012 if (!HasOFlag(source_p, OPER_FLAG_CONNECT_REMOTE))
70 michael 971 {
71 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "connect:remote");
72 michael 2820 return 0;
73 michael 971 }
74 adx 30
75 michael 4682 if (hunt_server(source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
76 michael 2820 return 0;
77 adx 30 }
78 michael 2012 else if (!HasOFlag(source_p, OPER_FLAG_CONNECT))
79     {
80 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "connect");
81 michael 2820 return 0;
82 michael 2012 }
83 adx 30
84     /*
85 michael 2820 * Try to find the name, then host, if both fail notify ops and bail
86 adx 30 */
87 michael 4682 if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0)) &&
88 michael 4688 !(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0)))
89 adx 30 {
90 michael 4686 sendto_one_notice(source_p, &me, ":Connect: Host %s not listed in configuration file", parv[1]);
91 michael 4682 return 0;
92 adx 30 }
93 michael 971
94 michael 4681 if ((target_p = hash_find_server(conf->name)))
95     {
96 michael 7065 sendto_one_notice(source_p, &me, ":Connect: Server %s already exists from %s",
97 michael 4681 target_p->name, target_p->from->name);
98     return 0;
99     }
100    
101 michael 2345 /*
102     * Get port number from user, if given. If not specified,
103 michael 7057 * use the default from configuration structure.
104 adx 30 */
105     if (parc > 2 && !EmptyString(parv[2]))
106 michael 7057 port = atoi(parv[2]);
107     if (port == 0)
108     port = conf->port;
109     if (port <= 0)
110 adx 30 {
111 michael 7057 sendto_one_notice(source_p, &me, ":Connect: Illegal port number");
112 michael 2820 return 0;
113 adx 30 }
114    
115     if (find_servconn_in_progress(conf->name))
116     {
117 michael 7065 sendto_one_notice(source_p, &me, ":Connect: a connection to %s is already in progress.",
118     conf->name);
119 michael 2820 return 0;
120 adx 30 }
121    
122     /*
123     * Notify all operators about remote connect requests
124     */
125 michael 7065 ilog(LOG_TYPE_IRCD, "CONNECT %s %d from %s",
126     parv[1], port, get_oper_name(source_p));
127 adx 30
128 michael 7057 const int tmpport = conf->port;
129 michael 1632 conf->port = port;
130 adx 30
131 michael 2345 /*
132 michael 2820 * At this point we should be calling connect_server with a valid
133 michael 3300 * connect{} block and a valid port in the connect{} block
134 adx 30 */
135 michael 1632 if (serv_connect(conf, source_p))
136 adx 30 {
137 michael 1219 if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
138 michael 3110 sendto_one_notice(source_p, &me, ":*** Connecting to %s[%s].%d",
139     conf->host, conf->name, conf->port);
140 adx 30 else
141 michael 3110 sendto_one_notice(source_p, &me, ":*** Connecting to %s.%d",
142     conf->name, conf->port);
143 adx 30 }
144     else
145 michael 3110 sendto_one_notice(source_p, &me, ":*** Couldn't connect to %s.%d",
146     conf->name, conf->port);
147 adx 30
148 michael 2345 /*
149     * Client is either connecting with all the data it needs or has been
150 adx 30 * destroyed
151     */
152 michael 1632 conf->port = tmpport;
153 michael 2820 return 0;
154 adx 30 }
155    
156 michael 3300 /*! \brief CONNECT command handler
157 adx 30 *
158 michael 3300 * \param source_p Pointer to allocated Client struct from which the message
159     * originally comes from. This can be a local or remote client.
160     * \param parc Integer holding the number of supplied arguments.
161     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
162     * pointers.
163     * \note Valid arguments for this command are:
164     * - parv[0] = command
165     * - parv[1] = target server
166     * - parv[2] = port number
167     * - parv[3] = nickname/servername
168 adx 30 */
169 michael 2820 static int
170 michael 3156 ms_connect(struct Client *source_p, int parc, char *parv[])
171 adx 30 {
172 michael 7057 int port = 0;
173 michael 1632 struct MaskItem *conf = NULL;
174 michael 971 const struct Client *target_p = NULL;
175 adx 30
176 michael 4685 if (parc < 4 || EmptyString(parv[3]))
177 adx 30 {
178 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "CONNECT");
179 michael 2820 return 0;
180 adx 30 }
181    
182 michael 4685 if (hunt_server(source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
183     return 0;
184    
185 adx 30 /*
186 michael 2820 * Try to find the name, then host, if both fail notify ops and bail
187 adx 30 */
188 michael 4682 if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0)) &&
189 michael 4688 !(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0)))
190 michael 3795 {
191 michael 4686 sendto_one_notice(source_p, &me, ":Connect: Host %s not listed in configuration file", parv[1]);
192 michael 4682 return 0;
193 adx 30 }
194    
195 michael 4681 if ((target_p = hash_find_server(conf->name)))
196     {
197 michael 7065 sendto_one_notice(source_p, &me, ":Connect: Server %s already exists from %s",
198 michael 4681 target_p->name, target_p->from->name);
199     return 0;
200     }
201    
202 michael 2345 /*
203     * Get port number from user, if given. If not specified,
204 michael 7055 * use the default from configuration structure.
205 adx 30 */
206 michael 7055 port = atoi(parv[2]);
207 adx 30
208 michael 7055 if (port == 0)
209     port = conf->port;
210     if (port <= 0)
211 adx 30 {
212 michael 7055 sendto_one_notice(source_p, &me, ":Connect: Illegal port number");
213 michael 2820 return 0;
214 adx 30 }
215    
216     if (find_servconn_in_progress(conf->name))
217     {
218 michael 7065 sendto_one_notice(source_p, &me, ":Connect: a connection to %s is already in progress",
219     conf->name);
220 michael 2820 return 0;
221 adx 30 }
222    
223     /*
224     * Notify all operators about remote connect requests
225     */
226 michael 6317 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_GLOBAL, "from %s: Remote CONNECT %s %d from %s",
227 michael 7065 me.name, parv[1], port, get_oper_name(source_p));
228     sendto_server(NULL, 0, 0, ":%s GLOBOPS :Remote CONNECT %s %d from %s",
229     me.id, parv[1], port, get_oper_name(source_p));
230 adx 30
231 michael 7065 ilog(LOG_TYPE_IRCD, "Remote CONNECT %s %d from %s",
232     parv[1], port, get_oper_name(source_p));
233 adx 30
234 michael 7057 const int tmpport = conf->port;
235 michael 1632 conf->port = port;
236 adx 30
237 michael 885 /*
238     * At this point we should be calling connect_server with a valid
239 michael 3300 * connect{} block and a valid port in the connect{} block
240 adx 30 */
241 michael 1632 if (serv_connect(conf, source_p))
242 michael 3110 sendto_one_notice(source_p, &me, ":*** Connecting to %s.%d",
243     conf->name, conf->port);
244 adx 30 else
245 michael 3110 sendto_one_notice(source_p, &me, ":*** Couldn't connect to %s.%d",
246     conf->name, conf->port);
247 michael 885 /*
248     * Client is either connecting with all the data it needs or has been
249 adx 30 * destroyed
250     */
251 michael 1632 conf->port = tmpport;
252 michael 2820 return 0;
253 adx 30 }
254 michael 1230
255 michael 2820 static struct Message connect_msgtab =
256     {
257 michael 5880 .cmd = "CONNECT",
258     .args_min = 2,
259     .args_max = MAXPARA,
260     .handlers[UNREGISTERED_HANDLER] = m_unregistered,
261     .handlers[CLIENT_HANDLER] = m_not_oper,
262     .handlers[SERVER_HANDLER] = ms_connect,
263     .handlers[ENCAP_HANDLER] = m_ignore,
264     .handlers[OPER_HANDLER] = mo_connect
265 michael 1230 };
266    
267     static void
268     module_init(void)
269     {
270     mod_add_cmd(&connect_msgtab);
271     }
272    
273     static void
274     module_exit(void)
275     {
276     mod_del_cmd(&connect_msgtab);
277     }
278    
279 michael 2820 struct module module_entry =
280     {
281 michael 1230 .version = "$Revision$",
282     .modinit = module_init,
283     .modexit = module_exit,
284     };

Properties

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