~ubuntu-branches/debian/sid/ircd-hybrid/sid

« back to all changes in this revision

Viewing changes to modules/m_trace.c

  • Committer: Package Import Robot
  • Author(s): Dominic Hargreaves
  • Date: 2015-04-19 15:53:09 UTC
  • mfrom: (1.2.13)
  • Revision ID: package-import@ubuntu.com-20150419155309-06y59x2at2ax5ou3
Tags: 1:8.2.7+dfsg.1-1
* Remove Suggests: hybserv since it doesn't really work with
  ircd-hybrid 8 and above
* New upstream release
  - update debian/copyright with minor changes
  - update config files from new reference.conf
  - fixes DoS from localhost clients (Closes: #782859)
  - supports SSL certficate chaining (Closes: #769741)
* Debconf configuration script no longer ignores the result of
  upgrade questions (Closes: #779082)
* Don't display upgrade warnings on new installs (Closes: #782883)
* Add NEWS item about updated configuration

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3
3
 *
4
 
 *  Copyright (c) 1997-2014 ircd-hybrid development team
 
4
 *  Copyright (c) 1997-2015 ircd-hybrid development team
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
21
21
 
22
22
/*! \file m_trace.c
23
23
 * \brief Includes required functions for processing the TRACE command.
24
 
 * \version $Id: m_trace.c 4564 2014-08-24 10:24:47Z michael $
 
24
 * \version $Id: m_trace.c 5543 2015-02-12 13:40:13Z michael $
25
25
 */
26
26
 
27
27
#include "stdinc.h"
46
46
trace_get_dependent(unsigned int *const server,
47
47
                    unsigned int *const client, const struct Client *target_p)
48
48
{
49
 
  const dlink_node *ptr = NULL;
 
49
  const dlink_node *node = NULL;
50
50
 
51
51
  (*server)++;
52
52
  (*client) += dlink_list_length(&target_p->serv->client_list);
53
53
 
54
 
  DLINK_FOREACH(ptr, target_p->serv->server_list.head)
55
 
    trace_get_dependent(server, client, ptr->data);
 
54
  DLINK_FOREACH(node, target_p->serv->server_list.head)
 
55
    trace_get_dependent(server, client, node->data);
56
56
}
57
57
 
58
58
/*
64
64
static int
65
65
m_trace(struct Client *source_p, int parc, char *parv[])
66
66
{
67
 
  const char *tname = NULL;
 
67
  const char *name = NULL;
68
68
 
69
69
  if (parc > 1)
70
 
    tname = parv[1];
 
70
    name = parv[1];
71
71
  else
72
 
    tname = me.name;
 
72
    name = me.name;
73
73
 
74
 
  sendto_one_numeric(source_p, &me, RPL_ENDOFTRACE, tname);
 
74
  sendto_one_numeric(source_p, &me, RPL_ENDOFTRACE, name);
75
75
  return 0;
76
76
}
77
77
 
82
82
static int
83
83
mo_trace(struct Client *source_p, int parc, char *parv[])
84
84
{
85
 
  dlink_node *ptr = NULL;
86
 
  const char *tname = NULL;
 
85
  dlink_node *node = NULL;
 
86
  const char *name = NULL;
87
87
 
88
88
  if (parc > 2)
89
89
    if (hunt_server(source_p, ":%s TRACE %s :%s", 2, parc, parv) != HUNTED_ISME)
90
90
      return 0;
91
91
 
92
92
  if (parc > 1)
93
 
    tname = parv[1];
 
93
    name = parv[1];
94
94
  else
95
 
    tname = me.name;
 
95
    name = me.name;
96
96
 
97
97
  switch (hunt_server(source_p, ":%s TRACE :%s", 1, parc, parv))
98
98
  {
100
100
    {
101
101
      struct Client *ac2ptr = NULL;
102
102
 
103
 
      if ((ac2ptr = hash_find_client(tname)) == NULL)
 
103
      if ((ac2ptr = hash_find_client(name)) == NULL)
104
104
      {
105
 
        DLINK_FOREACH(ptr, global_client_list.head)
 
105
        DLINK_FOREACH(node, global_client_list.head)
106
106
        {
107
 
          ac2ptr = ptr->data;
 
107
          ac2ptr = node->data;
108
108
 
109
 
          if (!match(tname, ac2ptr->name))
 
109
          if (!match(name, ac2ptr->name))
110
110
            break;
111
111
          else
112
112
            ac2ptr = NULL;
115
115
 
116
116
      if (ac2ptr)
117
117
        sendto_one_numeric(source_p, &me, RPL_TRACELINK,
118
 
                           ircd_version, tname, ac2ptr->from->name);
 
118
                           ircd_version, name, ac2ptr->from->name);
119
119
      else
120
120
        sendto_one_numeric(source_p, &me, RPL_TRACELINK,
121
 
                           ircd_version, tname, "ac2ptr_is_NULL!!");
 
121
                           ircd_version, name, "ac2ptr_is_NULL!!");
122
122
      return 0;
123
123
    }
124
124
 
155
155
  struct Client *target_p = NULL;
156
156
  int doall = 0;
157
157
  int wilds, dow;
158
 
  dlink_node *ptr;
159
 
  const char *tname;
 
158
  dlink_node *node;
 
159
  const char *name;
160
160
 
161
161
  if (parc > 1)
162
 
    tname = parv[1];
 
162
    name = parv[1];
163
163
  else
164
 
    tname = me.name;
 
164
    name = me.name;
165
165
 
166
166
  sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
167
167
                       "TRACE requested by %s (%s@%s) [%s]",
168
168
                       source_p->name, source_p->username,
169
169
                       source_p->host, source_p->servptr->name);
170
170
 
171
 
  if (!match(tname, me.name))
 
171
  if (!match(name, me.name))
172
172
    doall = 1;
173
 
  else if (!MyClient(source_p) && !strcmp(tname, me.id))
 
173
  else if (!MyClient(source_p) && !strcmp(name, me.id))
174
174
  {
175
175
    doall = 1;
176
 
    tname = me.name;
 
176
    name = me.name;
177
177
  }
178
178
 
179
 
  wilds = !parv[1] || has_wildcards(tname);
 
179
  wilds = !parv[1] || has_wildcards(name);
180
180
  dow = wilds || doall;
181
181
 
182
182
  if (!HasUMode(source_p, UMODE_OPER) || !dow) /* non-oper traces must be full nicks */
183
183
                              /* lets also do this for opers tracing nicks */
184
184
  {
185
 
    const char *name;
186
 
    target_p = hash_find_client(tname);
 
185
    target_p = hash_find_client(name);
187
186
 
188
187
    if (target_p && IsClient(target_p))
189
188
    {
190
 
      name = get_client_name(target_p, HIDE_IP);
191
 
 
192
189
      if (HasUMode(target_p, UMODE_OPER))
193
190
      {
194
191
        sendto_one_numeric(source_p, &me, RPL_TRACEOPERATOR,
195
 
                   get_client_class(&target_p->localClient->confs), name,
196
 
                   IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost,
197
 
                   CurrentTime - target_p->localClient->lasttime,
198
 
                   idle_time_get(source_p, target_p));
 
192
                   get_client_class(&target_p->connection->confs), get_client_name(target_p, HIDE_IP),
 
193
                   target_p->sockhost,
 
194
                   CurrentTime - target_p->connection->lasttime,
 
195
                   client_get_idle_time(source_p, target_p));
199
196
      }
200
197
      else
201
198
      {
202
199
        sendto_one_numeric(source_p, &me, RPL_TRACEUSER,
203
 
                   get_client_class(&target_p->localClient->confs), name,
204
 
                   IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost,
205
 
                   CurrentTime - target_p->localClient->lasttime,
206
 
                   idle_time_get(source_p, target_p));
 
200
                   get_client_class(&target_p->connection->confs), get_client_name(target_p, HIDE_IP),
 
201
                   target_p->sockhost,
 
202
                   CurrentTime - target_p->connection->lasttime,
 
203
                   client_get_idle_time(source_p, target_p));
207
204
      }
208
205
    }
209
206
 
210
 
    sendto_one_numeric(source_p, &me, RPL_ENDOFTRACE, tname);
 
207
    sendto_one_numeric(source_p, &me, RPL_ENDOFTRACE, name);
211
208
    return;
212
209
  }
213
210
 
214
211
  /* report all direct connections */
215
 
  DLINK_FOREACH(ptr, local_client_list.head)
 
212
  DLINK_FOREACH(node, local_client_list.head)
216
213
  {
217
 
    target_p = ptr->data;
 
214
    target_p = node->data;
218
215
 
219
216
    if (HasUMode(target_p, UMODE_INVISIBLE) && dow &&
220
217
        !(MyConnect(source_p) && HasUMode(source_p, UMODE_OPER)) &&
221
218
        !HasUMode(target_p, UMODE_OPER) && (target_p != source_p))
222
219
      continue;
223
 
    if (!doall && wilds && match(tname, target_p->name))
 
220
    if (!doall && wilds && match(name, target_p->name))
224
221
      continue;
225
 
    if (!dow && irccmp(tname, target_p->name))
 
222
    if (!dow && irccmp(name, target_p->name))
226
223
      continue;
227
224
 
228
225
    report_this_status(source_p, target_p, dow);
229
226
  }
230
227
 
231
 
  DLINK_FOREACH(ptr, local_server_list.head)
 
228
  DLINK_FOREACH(node, local_server_list.head)
232
229
  {
233
 
    target_p = ptr->data;
 
230
    target_p = node->data;
234
231
 
235
 
    if (!doall && wilds && match(tname, target_p->name))
 
232
    if (!doall && wilds && match(name, target_p->name))
236
233
      continue;
237
 
    if (!dow && irccmp(tname, target_p->name))
 
234
    if (!dow && irccmp(name, target_p->name))
238
235
      continue;
239
236
 
240
237
    report_this_status(source_p, target_p, dow);
241
238
  }
242
239
 
243
240
  /* This section is to report the unknowns */
244
 
  DLINK_FOREACH(ptr, unknown_list.head)
 
241
  DLINK_FOREACH(node, unknown_list.head)
245
242
  {
246
 
    target_p = ptr->data;
 
243
    target_p = node->data;
247
244
 
248
 
    if (!doall && wilds && match(tname, target_p->name))
 
245
    if (!doall && wilds && match(name, target_p->name))
249
246
      continue;
250
 
    if (!dow && irccmp(tname, target_p->name))
 
247
    if (!dow && irccmp(name, target_p->name))
251
248
      continue;
252
249
 
253
250
    report_this_status(source_p, target_p, dow);
254
251
  }
255
252
 
256
 
  DLINK_FOREACH(ptr, class_get_list()->head)
 
253
  DLINK_FOREACH(node, class_get_list()->head)
257
254
  {
258
 
    const struct ClassItem *class = ptr->data;
 
255
    const struct ClassItem *class = node->data;
259
256
 
260
257
    if (class->ref_count > 0)
261
258
      sendto_one_numeric(source_p, &me, RPL_TRACECLASS, class->name, class->ref_count);
262
259
  }
263
260
 
264
 
  sendto_one_numeric(source_p, &me, RPL_ENDOFTRACE, tname);
 
261
  sendto_one_numeric(source_p, &me, RPL_ENDOFTRACE, name);
265
262
}
266
263
 
267
264
/* report_this_status()
278
275
  const char *class_name;
279
276
 
280
277
  name = get_client_name(target_p, HIDE_IP);
281
 
  class_name = get_client_class(&target_p->localClient->confs);
 
278
  class_name = get_client_class(&target_p->connection->confs);
282
279
 
283
280
  switch (target_p->status)
284
281
  {
285
282
    case STAT_CONNECTING:
286
283
      sendto_one_numeric(source_p, &me, RPL_TRACECONNECTING, class_name,
287
 
                 HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name);
 
284
                         HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name);
288
285
      break;
289
286
    case STAT_HANDSHAKE:
290
287
      sendto_one_numeric(source_p, &me, RPL_TRACEHANDSHAKE, class_name,
291
 
                 HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name);
 
288
                         HasUMode(source_p, UMODE_ADMIN) ? name : target_p->name);
292
289
      break;
293
290
    case STAT_ME:
294
291
      break;
295
292
    case STAT_UNKNOWN:
296
 
      /* added time -Taner */
297
293
      sendto_one_numeric(source_p, &me, RPL_TRACEUNKNOWN, class_name,
298
 
                 name, target_p->sockhost,
299
 
                 CurrentTime - target_p->localClient->firsttime);
 
294
                         name, target_p->sockhost,
 
295
                         CurrentTime - target_p->connection->firsttime);
300
296
      break;
301
297
    case STAT_CLIENT:
302
 
      /*
303
 
       * Only opers see users if there is a wildcard
304
 
       * but anyone can see all the opers.
305
 
       */
306
 
      if ((HasUMode(source_p, UMODE_OPER) &&
307
 
           (MyClient(source_p) || !(dow && HasUMode(target_p, UMODE_INVISIBLE))))
308
 
          || !dow || HasUMode(target_p, UMODE_OPER))
309
 
        {
310
 
          if (HasUMode(target_p, UMODE_ADMIN) && !ConfigGeneral.hide_spoof_ips)
311
 
            sendto_one_numeric(source_p, &me, RPL_TRACEOPERATOR, class_name, name,
312
 
                       HasUMode(source_p, UMODE_ADMIN) ? target_p->sockhost : "255.255.255.255",
313
 
                       CurrentTime - target_p->localClient->lasttime,
314
 
                       idle_time_get(source_p, target_p));
315
 
 
316
 
          else if (HasUMode(target_p, UMODE_OPER))
317
 
          {
318
 
            if (ConfigGeneral.hide_spoof_ips)
319
 
              sendto_one_numeric(source_p, &me, RPL_TRACEOPERATOR, class_name, name,
320
 
                         IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost,
321
 
                         CurrentTime - target_p->localClient->lasttime,
322
 
                         idle_time_get(source_p, target_p));
323
 
            else
324
 
              sendto_one_numeric(source_p, &me, RPL_TRACEOPERATOR, class_name, name,
325
 
                         MyOper(source_p) ? target_p->sockhost :
326
 
                         (IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost),
327
 
                         CurrentTime - target_p->localClient->lasttime,
328
 
                         idle_time_get(source_p, target_p));
329
 
          }
330
 
          else
331
 
          {
332
 
            if (ConfigGeneral.hide_spoof_ips)
333
 
              sendto_one_numeric(source_p, &me, RPL_TRACEUSER, class_name, name,
334
 
                         IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost,
335
 
                         CurrentTime - target_p->localClient->lasttime,
336
 
                         idle_time_get(source_p, target_p));
337
 
            else
338
 
              sendto_one_numeric(source_p, &me, RPL_TRACEUSER, class_name, name,
339
 
                         MyOper(source_p) ? target_p->sockhost :
340
 
                         (IsIPSpoof(target_p) ? "255.255.255.255" : target_p->sockhost),
341
 
                         CurrentTime - target_p->localClient->lasttime,
342
 
                         idle_time_get(source_p, target_p));
343
 
          }
344
 
        }
 
298
      if (HasUMode(target_p, UMODE_OPER))
 
299
        sendto_one_numeric(source_p, &me, RPL_TRACEOPERATOR, class_name, name,
 
300
                           target_p->sockhost,
 
301
                           CurrentTime - target_p->connection->lasttime,
 
302
                           client_get_idle_time(source_p, target_p));
 
303
      else
 
304
        sendto_one_numeric(source_p, &me, RPL_TRACEUSER, class_name, name,
 
305
                           target_p->sockhost,
 
306
                           CurrentTime - target_p->connection->lasttime,
 
307
                           client_get_idle_time(source_p, target_p));
345
308
      break;
346
309
    case STAT_SERVER:
347
310
    {
354
317
        name = get_client_name(target_p, MASK_IP);
355
318
 
356
319
      sendto_one_numeric(source_p, &me, RPL_TRACESERVER, class_name, servers,
357
 
                 clients, name, *(target_p->serv->by) ?
358
 
                 target_p->serv->by : "*", "*",
359
 
                 me.name, CurrentTime - target_p->localClient->lasttime);
 
320
                         clients, name, *(target_p->serv->by) ?
 
321
                         target_p->serv->by : "*", "*",
 
322
                         me.name, CurrentTime - target_p->connection->lasttime);
360
323
      break;
361
324
    }
362
325
 
388
351
{
389
352
  .node    = { NULL, NULL, NULL },
390
353
  .name    = NULL,
391
 
  .version = "$Revision: 4564 $",
 
354
  .version = "$Revision: 5543 $",
392
355
  .handle  = NULL,
393
356
  .modinit = module_init,
394
357
  .modexit = module_exit,