Debian Codegraph @

modules/protocol/ts6-generic.c

raw
1 /*
2 * Copyright (c) 2003-2004 E. Will et al.
3 * Copyright (c) 2005-2007 Atheme Development Group
4 * Rights to this code are documented in doc/LICENSE.
5 *
6 * This file contains protocol support for TS6-based ircd.
7 */
8
9 /*
10 * protocol/ts6-generic
11 *
12 * This module is not very useful on it's own. It implements
13 * the basis of the TS6 extended linking profile, which is used
14 * by charybdis, ratbox (--enable-services), weircd and others.
15 *
16 * Everything in this module can be subclassed. To do so, we
17 * recommend either directly subclassing this module, or subclassing
18 * the module your ircd is based on. You can override (or redirect)
19 * IRC messages to your protocol and leave the bulk of the command
20 * processing and message sending in this module, which should
21 * "just work" unless your IRCd is broken.
22 *
23 * A note to IRCd developers:
24 *
25 * If you are working with TS6 as your linking protocol, it is
26 * important that you follow the TS6 standards exactly. If you are
27 * confused on what you should do, look at this module. This
28 * module describes all of the hardcoded requirements of the
29 * extended linking profile.
30 *
31 * This module is designed where it can downgrade to TS6 strict, or
32 * TS5/TS3. Earlier link protocol versions than TS3 will likely not
33 * work.
34 */
35
36 #include "atheme.h"
37 #include "uplink.h"
38 #include "pmodule.h"
39
40 DECLARE_MODULE_V1("protocol/ts6-generic", true, _modinit, NULL, PACKAGE_STRING, VENDOR_STRING);
41
42 static bool use_rserv_support = false;
43 static bool use_tb = false;
44 static bool use_euid = false;
45 static bool use_eopmod = false;
46 static bool use_mlock = false;
47
48 static void server_eob(server_t *s);
49 static server_t *sid_find(char *name);
50
51 static char ts6sid[3 + 1] = "";
52
53 static bool ts6_is_valid_host(const char *host)
54 {
55 const char *p;
56
57 for (p = host; *p != '\0'; p++)
58 if (!((*p >= '0' && *p <= '9') || (*p >= 'A' && *p <= 'Z') ||
59 (*p >= 'a' && *p <= 'z') || *p == '.'
60 || *p == ':' || *p == '-'))
61 return false;
62 return true;
63 }
64
65 /* login to our uplink */
66 static unsigned int ts6_server_login(void)
67 {
68 int ret = 1;
69
70 if (!me.numeric)
71 {
72 ircd->uses_uid = false;
73 ret = sts("PASS %s :TS", curr_uplink->send_pass);
74 }
75 else if (strlen(me.numeric) == 3 && isdigit((unsigned char)*me.numeric))
76 {
77 ircd->uses_uid = true;
78 ret = sts("PASS %s TS 6 :%s", curr_uplink->send_pass, me.numeric);
79 }
80 else
81 {
82 slog(LG_ERROR, "Invalid numeric (SID) %s", me.numeric);
83 }
84 if (ret == 1)
85 return 1;
86
87 me.bursting = true;
88
89 sts("CAPAB :QS EX IE KLN UNKLN ENCAP TB SERVICES EUID EOPMOD MLOCK");
90 sts("SERVER %s 1 :%s%s", me.name, me.hidden ? "(H) " : "", me.desc);
91 sts("SVINFO %d 3 0 :%lu", ircd->uses_uid ? 6 : 5,
92 (unsigned long)CURRTIME);
93
94 return 0;
95 }
96
97 /* introduce a client */
98 static void ts6_introduce_nick(user_t *u)
99 {
100 const char *umode = user_get_umodestr(u);
101
102 if (ircd->uses_uid && use_euid)
103 sts(":%s EUID %s 1 %lu %s %s %s 0 %s * * :%s", me.numeric, u->nick, (unsigned long)u->ts, umode, u->user, u->host, u->uid, u->gecos);
104 else if (ircd->uses_uid)
105 sts(":%s UID %s 1 %lu %s %s %s 0 %s :%s", me.numeric, u->nick, (unsigned long)u->ts, umode, u->user, u->host, u->uid, u->gecos);
106 else
107 sts("NICK %s 1 %lu %s %s %s %s :%s", u->nick, (unsigned long)u->ts, umode, u->user, u->host, me.name, u->gecos);
108 }
109
110 /* invite a user to a channel */
111 static void ts6_invite_sts(user_t *sender, user_t *target, channel_t *channel)
112 {
113 sts(":%s INVITE %s %s", CLIENT_NAME(sender), CLIENT_NAME(target), channel->name);
114 }
115
116 static void ts6_quit_sts(user_t *u, const char *reason)
117 {
118 sts(":%s QUIT :%s", CLIENT_NAME(u), reason);
119 }
120
121 /* WALLOPS wrapper */
122 static void ts6_wallops_sts(const char *text)
123 {
124 sts(":%s WALLOPS :%s", ME, text);
125 }
126
127 /* join a channel */
128 static void ts6_join_sts(channel_t *c, user_t *u, bool isnew, char *modes)
129 {
130 if (isnew)
131 sts(":%s SJOIN %lu %s %s :@%s", ME, (unsigned long)c->ts,
132 c->name, modes, CLIENT_NAME(u));
133 else
134 sts(":%s SJOIN %lu %s + :@%s", ME, (unsigned long)c->ts,
135 c->name, CLIENT_NAME(u));
136 }
137
138 static void ts6_chan_lowerts(channel_t *c, user_t *u)
139 {
140 slog(LG_DEBUG, "ts6_chan_lowerts(): lowering TS for %s to %lu",
141 c->name, (unsigned long)c->ts);
142 sts(":%s SJOIN %lu %s %s :@%s", ME, (unsigned long)c->ts, c->name,
143 channel_modes(c, true), CLIENT_NAME(u));
144 if (ircd->uses_uid)
145 chanban_clear(c);
146 }
147
148 /* kicks a user from a channel */
149 static void ts6_kick(user_t *source, channel_t *c, user_t *u, const char *reason)
150 {
151 if (c->ts != 0 || chanuser_find(c, source))
152 sts(":%s KICK %s %s :%s", CLIENT_NAME(source), c->name, CLIENT_NAME(u), reason);
153 else
154 sts(":%s KICK %s %s :%s", ME, c->name, CLIENT_NAME(u), reason);
155
156 chanuser_delete(c, u);
157 }
158
159 /* PRIVMSG wrapper */
160 static void ts6_msg(const char *from, const char *target, const char *fmt, ...)
161 {
162 va_list ap;
163 char buf[BUFSIZE];
164 user_t *u = user_find(from);
165 user_t *t = user_find(target);
166
167 if (!u)
168 return;
169
170 va_start(ap, fmt);
171 vsnprintf(buf, BUFSIZE, fmt, ap);
172 va_end(ap);
173
174 /* If this is to a channel, it's the snoop channel so chanserv
175 * is on it -- jilles
176 *
177 * Well, now it's operserv, but yes it's safe to assume that
178 * the source would be able to send to whatever target it is
179 * sending to. --nenolod
180 */
181 sts(":%s PRIVMSG %s :%s", CLIENT_NAME(u), t ? CLIENT_NAME(t) : target, buf);
182 }
183
184 static void ts6_msg_global_sts(user_t *from, const char *mask, const char *text)
185 {
186 mowgli_node_t *n;
187 tld_t *tld;
188
189 if (!strcmp(mask, "*"))
190 {
191 MOWGLI_ITER_FOREACH(n, tldlist.head)
192 {
193 tld = n->data;
194 sts(":%s PRIVMSG %s*%s :%s", from ? CLIENT_NAME(from) : ME, ircd->tldprefix, tld->name, text);
195 }
196 }
197 else
198 sts(":%s PRIVMSG %s%s :%s", from ? CLIENT_NAME(from) : ME, ircd->tldprefix, mask, text);
199 }
200
201 /* NOTICE wrapper */
202 static void ts6_notice_user_sts(user_t *from, user_t *target, const char *text)
203 {
204 sts(":%s NOTICE %s :%s", from ? CLIENT_NAME(from) : ME, CLIENT_NAME(target), text);
205 }
206
207 static void ts6_notice_global_sts(user_t *from, const char *mask, const char *text)
208 {
209 mowgli_node_t *n;
210 tld_t *tld;
211
212 if (!strcmp(mask, "*"))
213 {
214 MOWGLI_ITER_FOREACH(n, tldlist.head)
215 {
216 tld = n->data;
217 sts(":%s NOTICE %s*%s :%s", from ? CLIENT_NAME(from) : ME, ircd->tldprefix, tld->name, text);
218 }
219 }
220 else
221 sts(":%s NOTICE %s%s :%s", from ? CLIENT_NAME(from) : ME, ircd->tldprefix, mask, text);
222 }
223
224 static void ts6_notice_channel_sts(user_t *from, channel_t *target, const char *text)
225 {
226 if (from == NULL || chanuser_find(target, from))
227 sts(":%s NOTICE %s :%s", from ? CLIENT_NAME(from) : ME, target->name, text);
228 else
229 sts(":%s NOTICE %s :[%s:%s] %s", ME, target->name, from->nick, target->name, text);
230 }
231
232 static void ts6_wallchops(user_t *sender, channel_t *channel, const char *message)
233 {
234 if (chanuser_find(channel, sender))
235 sts(":%s NOTICE @%s :%s", CLIENT_NAME(sender), channel->name,
236 message);
237 else /* do not join for this, everyone would see -- jilles */
238 generic_wallchops(sender, channel, message);
239 }
240
241 /* numeric wrapper */
242 static void ts6_numeric_sts(server_t *from, int numeric, user_t *target, const char *fmt, ...)
243 {
244 va_list ap;
245 char buf[BUFSIZE];
246
247 va_start(ap, fmt);
248 vsnprintf(buf, BUFSIZE, fmt, ap);
249 va_end(ap);
250
251 sts(":%s %d %s %s", SERVER_NAME(from), numeric, CLIENT_NAME(target), buf);
252 }
253
254 /* KILL wrapper */
255 static void ts6_kill_id_sts(user_t *killer, const char *id, const char *reason)
256 {
257 if (killer != NULL)
258 sts(":%s KILL %s :%s!%s (%s)", CLIENT_NAME(killer), id, killer->host, killer->nick, reason);
259 else
260 sts(":%s KILL %s :%s (%s)", ME, id, me.name, reason);
261 }
262
263 /* PART wrapper */
264 static void ts6_part_sts(channel_t *c, user_t *u)
265 {
266 sts(":%s PART %s", CLIENT_NAME(u), c->name);
267 }
268
269 /* server-to-server KLINE wrapper */
270 static void ts6_kline_sts(const char *server, const char *user, const char *host, long duration, const char *reason)
271 {
272 service_t *svs;
273
274 svs = service_find("operserv");
275 sts(":%s ENCAP %s KLINE %ld %s %s :%s", svs != NULL ? CLIENT_NAME(svs->me) : ME, server, duration, user, host, reason);
276 }
277
278 /* server-to-server UNKLINE wrapper */
279 static void ts6_unkline_sts(const char *server, const char *user, const char *host)
280 {
281 service_t *svs;
282
283 svs = service_find("operserv");
284 sts(":%s ENCAP %s UNKLINE %s %s", svs != NULL ? CLIENT_NAME(svs->me) : ME, server, user, host);
285 }
286
287 /* server-to-server XLINE wrapper */
288 static void ts6_xline_sts(const char *server, const char *realname, long duration, const char *reason)
289 {
290 service_t *svs;
291
292 svs = service_find("operserv");
293 sts(":%s ENCAP %s XLINE %ld %s 2 :%s", svs != NULL ? CLIENT_NAME(svs->me) : ME, server, duration, realname, reason);
294 }
295
296 /* server-to-server UNXLINE wrapper */
297 static void ts6_unxline_sts(const char *server, const char *realname)
298 {
299 service_t *svs;
300
301 svs = service_find("operserv");
302 sts(":%s ENCAP %s UNXLINE %s", svs != NULL ? CLIENT_NAME(svs->me) : ME, server, realname);
303 }
304
305 /* server-to-server QLINE wrapper */
306 static void ts6_qline_sts(const char *server, const char *name, long duration, const char *reason)
307 {
308 service_t *svs;
309
310 svs = service_find("operserv");
311 sts(":%s ENCAP %s RESV %ld %s 0 :%s", svs != NULL ? CLIENT_NAME(svs->me) : ME, server, duration, name, reason);
312 }
313
314 /* server-to-server UNQLINE wrapper */
315 static void ts6_unqline_sts(const char *server, const char *name)
316 {
317 service_t *svs;
318
319 svs = service_find("operserv");
320 sts(":%s ENCAP %s UNRESV %s", svs != NULL ? CLIENT_NAME(svs->me) : ME, server, name);
321 }
322
323 /* server-to-server DLINE wrapper */
324 static void ts6_dline_sts(const char *server, const char *host, long duration, const char *reason)
325 {
326 service_t *svs;
327
328 svs = service_find("operserv");
329 sts(":%s ENCAP %s DLINE %ld %s :%s", svs != NULL ? CLIENT_NAME(svs->me) : ME, server, duration, host, reason);
330 }
331
332 /* server-to-server UNDLINE wrapper */
333 static void ts6_undline_sts(const char *server, const char *host)
334 {
335 service_t *svs;
336
337 svs = service_find("operserv");
338 sts(":%s ENCAP %s UNDLINE %s", svs != NULL ? CLIENT_NAME(svs->me) : ME, server, host);
339 }
340
341 /* topic wrapper */
342 static void ts6_topic_sts(channel_t *c, user_t *source, const char *setter, time_t ts, time_t prevts, const char *topic)
343 {
344 int joined = 0;
345
346 return_if_fail(c != NULL);
347 return_if_fail(source != NULL);
348
349 /* If possible, try to use ETB */
350 if (use_eopmod && (c->ts > 0 || ts > prevts))
351 {
352 sts(":%s ETB 0 %s %lu %s :%s",
353 CLIENT_NAME(source),
354 c->name, (unsigned long)ts, setter, topic);
355 return;
356 }
357
358 /* If possible, try to use TB
359 * Note that because TOPIC does not contain topicTS, it may be
360 * off a few seconds on other servers, hence the 60 seconds here.
361 * -- jilles */
362 if (use_tb && *topic != '\0')
363 {
364 /* Restoring old topic */
365 if (ts < prevts || prevts == 0)
366 {
367 if (prevts != 0 && ts + 60 > prevts)
368 ts = prevts - 60;
369 sts(":%s TB %s %lu %s :%s", ME, c->name, (unsigned long)ts, setter, topic);
370 c->topicts = ts;
371 return;
372 }
373 /* Tweaking a topic */
374 else if (ts == prevts)
375 {
376 ts -= 60;
377 sts(":%s TB %s %lu %s :%s", ME, c->name, (unsigned long)ts, setter, topic);
378 c->topicts = ts;
379 return;
380 }
381 }
382 /* We have to be on channel to change topic.
383 * We cannot nicely change topic from the server:
384 * :server.name TOPIC doesn't propagate and TB requires
385 * us to specify an older topicts.
386 * -- jilles
387 */
388 if (!chanuser_find(c, source))
389 {
390 sts(":%s SJOIN %lu %s + :@%s", ME, (unsigned long)c->ts, c->name, CLIENT_NAME(source));
391 joined = 1;
392 }
393 sts(":%s TOPIC %s :%s", CLIENT_NAME(source), c->name, topic);
394 if (joined)
395 sts(":%s PART %s :Topic set for %s",
396 CLIENT_NAME(source), c->name, setter);
397 c->topicts = CURRTIME;
398 }
399
400 /* mode wrapper */
401 static void ts6_mode_sts(char *sender, channel_t *target, char *modes)
402 {
403 user_t *u;
404
405 return_if_fail(sender != NULL);
406 return_if_fail(target != NULL);
407 return_if_fail(modes != NULL);
408
409 u = user_find(sender);
410
411 return_if_fail(u != NULL);
412
413 if (ircd->uses_uid)
414 sts(":%s TMODE %lu %s %s", CLIENT_NAME(u), (unsigned long)target->ts, target->name, modes);
415 else
416 sts(":%s MODE %s %s", CLIENT_NAME(u), target->name, modes);
417 }
418
419 /* ping wrapper */
420 static void ts6_ping_sts(void)
421 {
422 sts("PING :%s", me.name);
423 }
424
425 /* protocol-specific stuff to do on login */
426 static void ts6_on_login(user_t *u, myuser_t *mu, const char *wantedhost)
427 {
428 if (!use_rserv_support)
429 return;
430
431 return_if_fail(u != NULL);
432
433 sts(":%s ENCAP * SU %s %s", ME, CLIENT_NAME(u), entity(mu)->name);
434 }
435
436 /* protocol-specific stuff to do on login */
437 static bool ts6_on_logout(user_t *u, const char *account)
438 {
439 if (!use_rserv_support)
440 return false;
441
442 return_val_if_fail(u != NULL, false);
443
444 sts(":%s ENCAP * SU %s", ME, CLIENT_NAME(u));
445 return false;
446 }
447
448 /* XXX we don't have an appropriate API for this, what about making JUPE
449 * serverside like in P10?
450 * --nenolod
451 */
452 static void ts6_jupe(const char *server, const char *reason)
453 {
454 service_t *svs;
455
456 server_delete(server);
457
458 svs = service_find("operserv");
459 sts(":%s SQUIT %s :%s", svs != NULL ? CLIENT_NAME(svs->me) : ME, server, reason);
460 sts(":%s SERVER %s 2 :(H) %s", me.name, server, reason);
461 }
462
463 static void ts6_sethost_sts(user_t *source, user_t *target, const char *host)
464 {
465 if (use_euid)
466 sts(":%s CHGHOST %s :%s", ME, CLIENT_NAME(target), host);
467 else
468 sts(":%s ENCAP * CHGHOST %s :%s", ME, target->nick, host);
469 }
470
471 static void ts6_fnc_sts(user_t *source, user_t *u, const char *newnick, int type)
472 {
473 /* XXX assumes the server will accept this -- jilles */
474 sts(":%s ENCAP %s RSFNC %s %s %lu %lu", ME,
475 u->server->name,
476 CLIENT_NAME(u), newnick,
477 (unsigned long)(CURRTIME - 60),
478 (unsigned long)u->ts);
479 }
480
481 static void ts6_svslogin_sts(char *target, char *nick, char *user, char *host, myuser_t *account)
482 {
483 user_t *tu = user_find(target);
484 server_t *s;
485
486 if(tu)
487 s = tu->server;
488 else if(ircd->uses_uid) /* Non-announced UID - must be a SASL client. */
489 s = sid_find(target);
490 else
491 return;
492
493 sts(":%s ENCAP %s SVSLOGIN %s %s %s %s %s", ME, s->name,
494 target, nick, user, host, entity(account)->name);
495 }
496
497 static void ts6_sasl_sts(char *target, char mode, char *data)
498 {
499 service_t *svs;
500 server_t *s = sid_find(target);
501
502 if(s == NULL)
503 return;
504
505 svs = service_find("saslserv");
506 if (svs == NULL)
507 {
508 slog(LG_ERROR, "ts6_sasl_sts(): saslserv does not exist!");
509 return;
510 }
511
512 sts(":%s ENCAP %s SASL %s %s %c %s", ME, s->name,
513 svs->me->uid,
514 target,
515 mode,
516 data);
517 }
518
519 static void ts6_sasl_mechlist_sts(const char *mechlist)
520 {
521 sts(":%s ENCAP * MECHLIST :%s", ME, mechlist);
522 }
523
524 static void ts6_holdnick_sts(user_t *source, int duration, const char *nick, myuser_t *mu)
525 {
526 if (use_euid)
527 sts(":%s ENCAP * NICKDELAY %d %s", ME, duration, nick);
528 else
529 {
530 if (duration == 0)
531 return; /* can't do this safely */
532 sts(":%s ENCAP * RESV %d %s 0 :Reserved by %s for nickname owner (%s)",
533 CLIENT_NAME(source), duration > 300 ? 300 : duration,
534 nick, source->nick,
535 mu ? entity(mu)->name : nick);
536 }
537 }
538
539 static void ts6_mlock_sts(channel_t *c)
540 {
541 mychan_t *mc = mychan_from(c);
542
543 if (use_mlock == false)
544 return;
545
546 if (mc == NULL)
547 return;
548
549 sts(":%s MLOCK %lu %s :%s", ME, (unsigned long)c->ts, c->name,
550 mychan_get_sts_mlock(mc));
551 }
552
553 static void m_mlock(sourceinfo_t *si, int parc, char *parv[])
554 {
555 channel_t *c;
556 mychan_t *mc;
557 const char *mlock;
558
559 /* Ignore MLOCK if the server isn't bursting, to avoid 'war' conditions */
560 if (si->s->flags & SF_EOB)
561 return;
562
563 if (!(c = channel_find(parv[1])))
564 return;
565
566 if (!(mc = mychan_from(c)))
567 {
568 /* Unregistered channel. Clear the MLOCK. */
569 sts(":%s MLOCK %lu %s :", ME, (unsigned long)c->ts, c->name);
570 return;
571 }
572
573 time_t ts = atol(parv[0]);
574 if (ts > c->ts)
575 return;
576
577 mlock = mychan_get_sts_mlock(mc);
578 if (0 != strcmp(parv[2], mlock))
579 {
580 /* MLOCK is changing, with the same TS. Bounce back the correct one. */
581 sts(":%s MLOCK %lu %s :%s", ME, (unsigned long)c->ts, c->name,
582 mlock);
583 }
584 }
585
586
587 static void m_topic(sourceinfo_t *si, int parc, char *parv[])
588 {
589 channel_t *c = channel_find(parv[0]);
590
591 if (c == NULL)
592 return;
593
594 handle_topic_from(si, c, si->su->nick, CURRTIME, parv[1]);
595 }
596
597 static void m_tb(sourceinfo_t *si, int parc, char *parv[])
598 {
599 channel_t *c = channel_find(parv[0]);
600 time_t ts = atol(parv[1]);
601
602 if (c == NULL)
603 return;
604
605 if (c->topic != NULL && c->topicts <= ts)
606 {
607 slog(LG_DEBUG, "m_tb(): ignoring newer topic on %s", c->name);
608 return;
609 }
610
611 handle_topic_from(si, c, parc > 3 ? parv[2] : si->s->name, ts, parv[parc - 1]);
612 }
613
614 static void m_etb(sourceinfo_t *si, int parc, char *parv[])
615 {
616 channel_t *c = channel_find(parv[1]);
617 time_t channelts;
618 time_t topicts;
619
620 if (c == NULL)
621 return;
622
623 /* Our uplink is trying to change the topic during burst,
624 * and we have already set a topic. Assume our change won.
625 * -- jilles */
626 if (si->s != NULL && si->s->uplink == me.me &&
627 !(si->s->flags & SF_EOB) && c->topic != NULL)
628 return;
629
630 channelts = atol(parv[0]);
631 topicts = atol(parv[2]);
632 if (c->topic == NULL || channelts < c->ts || (channelts == c->ts && topicts > c->topicts))
633 handle_topic_from(si, c, parv[3], topicts, parv[parc - 1]);
634 }
635
636 static void m_ping(sourceinfo_t *si, int parc, char *parv[])
637 {
638 /* reply to PING's */
639 sts(":%s PONG %s %s", ME, me.name, parv[0]);
640 }
641
642 static void m_pong(sourceinfo_t *si, int parc, char *parv[])
643 {
644 server_t *s;
645
646 /* someone replied to our PING */
647 if (!parv[0])
648 return;
649 s = server_find(parv[0]);
650 if (s == NULL)
651 return;
652 handle_eob(s);
653
654 if (s != si->s)
655 return;
656
657 me.uplinkpong = CURRTIME;
658
659 /* -> :test.projectxero.net PONG test.projectxero.net :shrike.malkier.net */
660 if (me.bursting)
661 {
662 #ifdef HAVE_GETTIMEOFDAY
663 e_time(burstime, &burstime);
664
665 slog(LG_INFO, "m_pong(): finished synching with uplink (%d %s)", (tv2ms(&burstime) > 1000) ? (tv2ms(&burstime) / 1000) : tv2ms(&burstime), (tv2ms(&burstime) > 1000) ? "s" : "ms");
666
667 wallops("Finished synchronizing with network in %d %s.", (tv2ms(&burstime) > 1000) ? (tv2ms(&burstime) / 1000) : tv2ms(&burstime), (tv2ms(&burstime) > 1000) ? "s" : "ms");
668 #else
669 slog(LG_INFO, "m_pong(): finished synching with uplink");
670 wallops("Finished synchronizing with network.");
671 #endif
672
673 me.bursting = false;
674 }
675 }
676
677 static void m_privmsg(sourceinfo_t *si, int parc, char *parv[])
678 {
679 if (parc != 2)
680 return;
681
682 handle_message(si, parv[0], false, parv[1]);
683 }
684
685 static void m_notice(sourceinfo_t *si, int parc, char *parv[])
686 {
687 if (parc != 2)
688 return;
689
690 handle_message(si, parv[0], true, parv[1]);
691 }
692
693 static void m_sjoin(sourceinfo_t *si, int parc, char *parv[])
694 {
695 /* -> :proteus.malkier.net SJOIN 1073516550 #shrike +tn :@sycobuny @+rakaur */
696
697 channel_t *c;
698 bool keep_new_modes = true;
699 unsigned int userc;
700 char *userv[256];
701 unsigned int i;
702 time_t ts;
703 char *p;
704
705 /* :origin SJOIN ts chan modestr [key or limits] :users */
706 c = channel_find(parv[1]);
707 ts = atol(parv[0]);
708
709 if (!c)
710 {
711 slog(LG_DEBUG, "m_sjoin(): new channel: %s", parv[1]);
712 c = channel_add(parv[1], ts, si->s);
713 }
714
715 if (ts == 0 || c->ts == 0)
716 {
717 if (c->ts != 0)
718 slog(LG_INFO, "m_sjoin(): server %s changing TS on %s from %lu to 0", si->s->name, c->name, (unsigned long)c->ts);
719 c->ts = 0;
720 hook_call_channel_tschange(c);
721 }
722 else if (ts < c->ts)
723 {
724 chanuser_t *cu;
725 mowgli_node_t *n;
726
727 /* the TS changed. a TS change requires the following things
728 * to be done to the channel: reset all modes to nothing, remove
729 * all status modes on known users on the channel (including ours),
730 * and set the new TS.
731 *
732 * if the source does TS6, also remove all bans
733 * note that JOIN does not do this
734 */
735
736 clear_simple_modes(c);
737 if (si->s->sid != NULL)
738 chanban_clear(c);
739
740 MOWGLI_ITER_FOREACH(n, c->members.head)
741 {
742 cu = (chanuser_t *)n->data;
743 if (cu->user->server == me.me)
744 {
745 /* it's a service, reop */
746 sts(":%s PART %s :Reop", CLIENT_NAME(cu->user), c->name);
747 sts(":%s SJOIN %lu %s + :@%s", ME, (unsigned long)ts, c->name, CLIENT_NAME(cu->user));
748 cu->modes = CSTATUS_OP;
749 }
750 else
751 cu->modes = 0;
752 }
753
754 slog(LG_DEBUG, "m_sjoin(): TS changed for %s (%lu -> %lu)", c->name, (unsigned long)c->ts, (unsigned long)ts);
755
756 c->ts = ts;
757 hook_call_channel_tschange(c);
758 }
759 else if (ts > c->ts)
760 keep_new_modes = false;
761
762 if (keep_new_modes)
763 channel_mode(NULL, c, parc - 3, parv + 2);
764
765 userc = sjtoken(parv[parc - 1], ' ', userv);
766
767 if (keep_new_modes)
768 for (i = 0; i < userc; i++)
769 chanuser_add(c, userv[i]);
770 else
771 for (i = 0; i < userc; i++)
772 {
773 p = userv[i];
774 while (*p == '@' || *p == '%' || *p == '+')
775 p++;
776 /* XXX for TS5 we should mark them deopped
777 * if they were opped and drop modes from them
778 * -- jilles */
779 chanuser_add(c, p);
780 }
781
782 if (c->nummembers == 0 && !(c->modes & ircd->perm_mode))
783 channel_delete(c);
784 }
785
786 static void m_join(sourceinfo_t *si, int parc, char *parv[])
787 {
788 /* -> :1JJAAAAAB JOIN 1127474195 #test +tn */
789 bool keep_new_modes = true;
790 mowgli_node_t *n, *tn;
791 channel_t *c;
792 chanuser_t *cu;
793 time_t ts;
794
795 /* JOIN 0 is really a part from all channels */
796 /* be sure to allow joins to TS 0 channels -- jilles */
797 if (parv[0][0] == '0' && parc <= 2)
798 {
799 MOWGLI_ITER_FOREACH_SAFE(n, tn, si->su->channels.head)
800 {
801 cu = (chanuser_t *)n->data;
802 chanuser_delete(cu->chan, si->su);
803 }
804 return;
805 }
806
807 /* :user JOIN ts chan modestr [key or limits] */
808 c = channel_find(parv[1]);
809 ts = atol(parv[0]);
810
811 if (!c)
812 {
813 slog(LG_DEBUG, "m_join(): new channel: %s", parv[1]);
814 c = channel_add(parv[1], ts, si->su->server);
815 }
816
817 if (ts == 0 || c->ts == 0)
818 {
819 if (c->ts != 0)
820 slog(LG_INFO, "m_join(): server %s changing TS on %s from %lu to 0", si->su->server->name, c->name, (unsigned long)c->ts);
821 c->ts = 0;
822 hook_call_channel_tschange(c);
823 }
824 else if (ts < c->ts)
825 {
826 /* the TS changed. a TS change requires the following things
827 * to be done to the channel: reset all modes to nothing, remove
828 * all status modes on known users on the channel (including ours),
829 * and set the new TS.
830 */
831 clear_simple_modes(c);
832
833 MOWGLI_ITER_FOREACH(n, c->members.head)
834 {
835 cu = (chanuser_t *)n->data;
836 if (cu->user->server == me.me)
837 {
838 /* it's a service, reop */
839 sts(":%s PART %s :Reop", CLIENT_NAME(cu->user), c->name);
840 sts(":%s SJOIN %lu %s + :@%s", ME, (unsigned long)ts, c->name, CLIENT_NAME(cu->user));
841 cu->modes = CSTATUS_OP;
842 }
843 else
844 cu->modes = 0;
845 }
846 slog(LG_DEBUG, "m_join(): TS changed for %s (%lu -> %lu)", c->name, (unsigned long)c->ts, (unsigned long)ts);
847 c->ts = ts;
848 hook_call_channel_tschange(c);
849 }
850 else if (ts > c->ts)
851 keep_new_modes = false;
852
853 if (keep_new_modes)
854 channel_mode(NULL, c, parc - 2, parv + 2);
855
856 chanuser_add(c, CLIENT_NAME(si->su));
857 }
858
859 static void m_bmask(sourceinfo_t *si, int parc, char *parv[])
860 {
861 unsigned int ac, i;
862 char *av[256];
863 channel_t *c = channel_find(parv[1]);
864 int type;
865
866 /* :1JJ BMASK 1127474361 #services b :*!*@*evil* *!*eviluser1@* */
867 if (!c)
868 {
869 slog(LG_DEBUG, "m_bmask(): got bmask for unknown channel");
870 return;
871 }
872
873 if (atol(parv[0]) > c->ts)
874 return;
875
876 type = *parv[2];
877 if (!strchr(ircd->ban_like_modes, type))
878 {
879 slog(LG_DEBUG, "m_bmask(): got unknown type '%c'", type);
880 return;
881 }
882
883 ac = sjtoken(parv[parc - 1], ' ', av);
884
885 for (i = 0; i < ac; i++)
886 chanban_add(c, av[i], type);
887 }
888
889 static void m_part(sourceinfo_t *si, int parc, char *parv[])
890 {
891 int chanc;
892 char *chanv[256];
893 int i;
894
895 chanc = sjtoken(parv[0], ',', chanv);
896 for (i = 0; i < chanc; i++)
897 {
898 slog(LG_DEBUG, "m_part(): user left channel: %s -> %s", si->su->nick, chanv[i]);
899
900 chanuser_delete(channel_find(chanv[i]), si->su);
901 }
902 }
903
904 static void m_nick(sourceinfo_t *si, int parc, char *parv[])
905 {
906 server_t *s;
907 user_t *u;
908
909 /* got the right number of args for an introduction? */
910 if (parc == 8)
911 {
912 s = server_find(parv[6]);
913 if (!s)
914 {
915 slog(LG_DEBUG, "m_nick(): new user on nonexistent server: %s", parv[6]);
916 return;
917 }
918
919 slog(LG_DEBUG, "m_nick(): new user on `%s': %s", s->name, parv[0]);
920
921 u = user_add(parv[0], parv[4], parv[5], NULL, NULL, NULL, parv[7], s, atoi(parv[2]));
922 if (u == NULL)
923 return;
924
925 user_mode(u, parv[3]);
926 if (strchr(parv[3], 'S'))
927 u->flags |= UF_IMMUNE;
928
929 /* If server is not yet EOB we will do this later.
930 * This avoids useless "please identify" -- jilles */
931 if (s->flags & SF_EOB)
932 handle_nickchange(user_find(parv[0]));
933 }
934
935 /* if it's only 2 then it's a nickname change */
936 else if (parc == 2)
937 {
938 if (!si->su)
939 {
940 slog(LG_DEBUG, "m_nick(): server trying to change nick: %s", si->s != NULL ? si->s->name : "<none>");
941 return;
942 }
943
944 slog(LG_DEBUG, "m_nick(): nickname change from `%s': %s", si->su->nick, parv[0]);
945
946 if (user_changenick(si->su, parv[0], atoi(parv[1])))
947 return;
948
949 /* It could happen that our PING arrived late and the
950 * server didn't acknowledge EOB yet even though it is
951 * EOB; don't send double notices in that case -- jilles */
952 if (si->su->server->flags & SF_EOB)
953 handle_nickchange(si->su);
954 }
955 else
956 {
957 int i;
958 slog(LG_DEBUG, "m_nick(): got NICK with wrong number of params");
959
960 for (i = 0; i < parc; i++)
961 slog(LG_DEBUG, "m_nick(): parv[%d] = %s", i, parv[i]);
962 }
963 }
964
965 static void m_uid(sourceinfo_t *si, int parc, char *parv[])
966 {
967 server_t *s;
968 user_t *u;
969
970 /* got the right number of args for an introduction? */
971 if (parc == 9)
972 {
973 s = si->s;
974 slog(LG_DEBUG, "m_uid(): new user on `%s': %s", s->name, parv[0]);
975
976 u = user_add(parv[0], parv[4], parv[5], NULL, parv[6], parv[7], parv[8], s, atoi(parv[2]));
977 if (u == NULL)
978 return;
979
980 user_mode(u, parv[3]);
981 if (strchr(parv[3], 'S'))
982 u->flags |= UF_IMMUNE;
983
984 /* If server is not yet EOB we will do this later.
985 * This avoids useless "please identify" -- jilles
986 */
987 if (s->flags & SF_EOB)
988 handle_nickchange(user_find(parv[0]));
989 }
990 else
991 {
992 int i;
993 slog(LG_DEBUG, "m_uid(): got UID with wrong number of params");
994
995 for (i = 0; i < parc; i++)
996 slog(LG_DEBUG, "m_uid(): parv[%d] = %s", i, parv[i]);
997 }
998 }
999
1000 static void m_euid(sourceinfo_t *si, int parc, char *parv[])
1001 {
1002 server_t *s;
1003 user_t *u;
1004
1005 /* got the right number of args for an introduction? */
1006 if (parc >= 11)
1007 {
1008 s = si->s;
1009 slog(LG_DEBUG, "m_euid(): new user on `%s': %s", s->name, parv[0]);
1010
1011 u = user_add(parv[0], /* nick */
1012 parv[4], /* user */
1013 *parv[8] != '*' ? parv[8] : parv[5], /* hostname */
1014 parv[5], /* hostname (visible) */
1015 parv[6], /* ip */
1016 parv[7], /* uid */
1017 parv[parc - 1], /* gecos */
1018 s, /* object parent (server) */
1019 atoi(parv[2])); /* hopcount */
1020 if (u == NULL)
1021 return;
1022
1023 user_mode(u, parv[3]);
1024 /* Services cannot be kicked.
1025 * They are assumed not to set/clear oper immune.
1026 */
1027 if (strchr(parv[3], 'S'))
1028 u->flags |= UF_IMMUNE;
1029
1030 if (*parv[9] != '*')
1031 handle_burstlogin(u, parv[9], 0);
1032
1033 /* server_eob() cannot know if a user was introduced
1034 * with NICK/UID or EUID and handle_nickchange() must
1035 * be called exactly once for each new user -- jilles */
1036 if (s->flags & SF_EOB)
1037 handle_nickchange(u);
1038 }
1039 else
1040 {
1041 int i;
1042 slog(LG_DEBUG, "m_euid(): got EUID with wrong number of params");
1043
1044 for (i = 0; i < parc; i++)
1045 slog(LG_DEBUG, "m_euid(): parv[%d] = %s", i, parv[i]);
1046 }
1047 }
1048
1049 static void m_quit(sourceinfo_t *si, int parc, char *parv[])
1050 {
1051 slog(LG_DEBUG, "m_quit(): user leaving: %s", si->su->nick);
1052
1053 /* user_delete() takes care of removing channels and so forth */
1054 user_delete(si->su, parv[0]);
1055 }
1056
1057 static void m_mode(sourceinfo_t *si, int parc, char *parv[])
1058 {
1059 if (*parv[0] == '#')
1060 channel_mode(NULL, channel_find(parv[0]), parc - 1, &parv[1]);
1061 else
1062 user_mode(user_find(parv[0]), parv[1]);
1063 }
1064
1065 static void m_tmode(sourceinfo_t *si, int parc, char *parv[])
1066 {
1067 channel_t *c;
1068
1069 /* -> :1JJAAAAAB TMODE 1127511579 #new +o 2JJAAAAAB */
1070 c = channel_find(parv[1]);
1071 if (c == NULL)
1072 {
1073 slog(LG_DEBUG, "m_tmode(): nonexistent channel %s", parv[1]);
1074 return;
1075 }
1076
1077 if (atol(parv[0]) > c->ts)
1078 return;
1079
1080 channel_mode(NULL, c, parc - 2, &parv[2]);
1081 }
1082
1083 static void m_kick(sourceinfo_t *si, int parc, char *parv[])
1084 {
1085 user_t *u = user_find(parv[1]);
1086 channel_t *c = channel_find(parv[0]);
1087
1088 /* -> :rakaur KICK #shrike rintaun :test */
1089 slog(LG_DEBUG, "m_kick(): user was kicked: %s -> %s", parv[1], parv[0]);
1090
1091 if (!u)
1092 {
1093 slog(LG_DEBUG, "m_kick(): got kick for nonexistent user %s", parv[1]);
1094 return;
1095 }
1096
1097 if (!c)
1098 {
1099 slog(LG_DEBUG, "m_kick(): got kick in nonexistent channel: %s", parv[0]);
1100 return;
1101 }
1102
1103 if (!chanuser_find(c, u))
1104 {
1105 slog(LG_DEBUG, "m_kick(): got kick for %s not in %s", u->nick, c->name);
1106 return;
1107 }
1108
1109 chanuser_delete(c, u);
1110
1111 /* if they kicked us, let's rejoin */
1112 if (is_internal_client(u))
1113 {
1114 slog(LG_DEBUG, "m_kick(): %s got kicked from %s; rejoining", u->nick, parv[0]);
1115 join(parv[0], u->nick);
1116 }
1117 }
1118
1119 static void m_kill(sourceinfo_t *si, int parc, char *parv[])
1120 {
1121 handle_kill(si, parv[0], parc > 1 ? parv[1] : "<No reason given>");
1122 }
1123
1124 static void m_squit(sourceinfo_t *si, int parc, char *parv[])
1125 {
1126 slog(LG_DEBUG, "m_squit(): server leaving: %s from %s", parv[0], parv[1]);
1127 server_delete(parv[0]);
1128 }
1129
1130 static void m_server(sourceinfo_t *si, int parc, char *parv[])
1131 {
1132 server_t *s;
1133
1134 slog(LG_DEBUG, "m_server(): new server: %s", parv[0]);
1135 s = handle_server(si, parv[0], si->s || !ircd->uses_uid ? NULL : ts6sid, atoi(parv[1]), parv[2]);
1136
1137 if (s != NULL && s->uplink != me.me)
1138 {
1139 /* elicit PONG for EOB detection; pinging uplink is
1140 * already done elsewhere -- jilles
1141 */
1142 sts(":%s PING %s %s", ME, me.name, s->name);
1143 }
1144 }
1145
1146 static void m_sid(sourceinfo_t *si, int parc, char *parv[])
1147 {
1148 /* -> :1JJ SID file. 2 00F :telnet server */
1149 server_t *s;
1150
1151 slog(LG_DEBUG, "m_sid(): new server: %s", parv[0]);
1152 s = handle_server(si, parv[0], parv[2], atoi(parv[1]), parv[3]);
1153
1154 if (s != NULL && s->uplink != me.me)
1155 {
1156 /* elicit PONG for EOB detection; pinging uplink is
1157 * already done elsewhere -- jilles
1158 */
1159 sts(":%s PING %s %s", ME, me.name, s->sid);
1160 }
1161 }
1162
1163 static void m_stats(sourceinfo_t *si, int parc, char *parv[])
1164 {
1165 handle_stats(si->su, parv[0][0]);
1166 }
1167
1168 static void m_admin(sourceinfo_t *si, int parc, char *parv[])
1169 {
1170 handle_admin(si->su);
1171 }
1172
1173 static void m_version(sourceinfo_t *si, int parc, char *parv[])
1174 {
1175 handle_version(si->su);
1176 }
1177
1178 static void m_info(sourceinfo_t *si, int parc, char *parv[])
1179 {
1180 handle_info(si->su);
1181 }
1182
1183 static void m_whois(sourceinfo_t *si, int parc, char *parv[])
1184 {
1185 handle_whois(si->su, parv[1]);
1186 }
1187
1188 static void m_trace(sourceinfo_t *si, int parc, char *parv[])
1189 {
1190 handle_trace(si->su, parv[0], parc >= 2 ? parv[1] : NULL);
1191 }
1192
1193 static void m_away(sourceinfo_t *si, int parc, char *parv[])
1194 {
1195 handle_away(si->su, parc >= 1 ? parv[0] : NULL);
1196 }
1197
1198 static void m_pass(sourceinfo_t *si, int parc, char *parv[])
1199 {
1200 /* TS5: PASS mypassword :TS
1201 * TS6: PASS mypassword TS 6 :sid */
1202 if (strcmp(curr_uplink->receive_pass, parv[0]))
1203 {
1204 slog(LG_INFO, "m_pass(): password mismatch from uplink; aborting");
1205 runflags |= RF_SHUTDOWN;
1206 }
1207
1208 if (ircd->uses_uid && parc > 3 && atoi(parv[2]) >= 6)
1209 mowgli_strlcpy(ts6sid, parv[3], sizeof(ts6sid));
1210 else
1211 {
1212 if (ircd->uses_uid)
1213 {
1214 slog(LG_INFO, "m_pass(): uplink does not support TS6, falling back to TS5");
1215 ircd->uses_uid = false;
1216 }
1217 ts6sid[0] = '\0';
1218 }
1219 }
1220
1221 static void m_error(sourceinfo_t *si, int parc, char *parv[])
1222 {
1223 slog(LG_INFO, "m_error(): error from server: %s", parv[0]);
1224 }
1225
1226 static void m_encap(sourceinfo_t *si, int parc, char *parv[])
1227 {
1228 user_t *u;
1229
1230 if (match(parv[0], me.name))
1231 return;
1232 if (!irccasecmp(parv[1], "LOGIN"))
1233 {
1234 /* :jilles ENCAP * LOGIN jilles */
1235 if (!use_rserv_support)
1236 return;
1237 if (parc < 3)
1238 return;
1239 u = si->su;
1240 if (u == NULL)
1241 return;
1242 /* We used to throw out LOGINs outside of a burst,
1243 * but we can't do that anymore since it's used for
1244 * SASL users.
1245 * --gxti
1246 */
1247 handle_burstlogin(u, parv[2], 0);
1248 }
1249 else if (!irccasecmp(parv[1], "SU"))
1250 {
1251 /* :services. ENCAP * SU jilles_ jilles */
1252 /* :services. ENCAP * SU jilles_ */
1253 if (!use_rserv_support)
1254 return;
1255 if (parc < 3)
1256 return;
1257 u = user_find(parv[2]);
1258 if (u == NULL)
1259 return;
1260 if (parc == 3)
1261 handle_clearlogin(si, u);
1262 else
1263 handle_setlogin(si, u, parv[3], 0);
1264 }
1265 else if (!irccasecmp(parv[1], "REALHOST"))
1266 {
1267 /* :1JJAAAAAC ENCAP * REALHOST localhost.stack.nl */
1268 if (parc < 3)
1269 return;
1270 u = si->su;
1271 if (u == NULL)
1272 return;
1273
1274 strshare_unref(u->host);
1275 u->host = strshare_get(parv[2]);
1276 }
1277 else if (!irccasecmp(parv[1], "CHGHOST"))
1278 {
1279 if (parc < 4)
1280 return;
1281 u = user_find(parv[2]);
1282 if (u == NULL)
1283 return;
1284
1285 strshare_unref(u->vhost);
1286 u->vhost = strshare_get(parv[3]);
1287
1288 slog(LG_DEBUG, "m_encap(): chghost %s -> %s", u->nick,
1289 u->vhost);
1290 }
1291 else if (!irccasecmp(parv[1], "SASL"))
1292 {
1293 /* :08C ENCAP * SASL 08CAAAAAE * S d29vTklOSkFTAGRhdGEgaW4gZmlyc3QgbGluZQ== */
1294 sasl_message_t smsg;
1295
1296 if (parc < 6)
1297 return;
1298
1299 smsg.uid = parv[2];
1300 smsg.mode = *parv[4];
1301 smsg.buf = parv[5];
1302 smsg.ext = parc >= 6 ? parv[6] : NULL;
1303 smsg.server = si->s ? si->s : NULL;
1304 hook_call_sasl_input(&smsg);
1305 }
1306 else if (!irccasecmp(parv[1], "RSMSG"))
1307 {
1308 char buf[512];
1309 char dest[NICKLEN + HOSTLEN];
1310 int i;
1311
1312 if (parc < 4)
1313 return;
1314 buf[0] = '\0';
1315 for (i = 3; i < parc; i++)
1316 {
1317 if (i > 3)
1318 mowgli_strlcat(buf, " ", sizeof buf);
1319 mowgli_strlcat(buf, parv[i], sizeof buf);
1320 }
1321 snprintf(dest, sizeof dest, "%s@%s", parv[2], me.name);
1322 handle_message(si, dest, false, buf);
1323 }
1324 else if (!irccasecmp(parv[1], "CERTFP"))
1325 {
1326 if (parc < 3)
1327 return;
1328
1329 u = si->su;
1330 if (u == NULL)
1331 return;
1332
1333 handle_certfp(si, u, parv[2]);
1334 }
1335 }
1336
1337 static void m_signon(sourceinfo_t *si, int parc, char *parv[])
1338 {
1339 user_t *u;
1340
1341 if((u = user_find(parv[0])) == NULL)
1342 return;
1343
1344 /* NICK */
1345 if (user_changenick(u, parv[0], atoi(parv[3])))
1346 return;
1347
1348 handle_nickchange(u); /* If they're logging out, this will bug them about identifying. Or something. */
1349
1350 /* USER */
1351 strshare_unref(u->user);
1352 u->user = strshare_get(parv[1]);
1353
1354 /* HOST */
1355 strshare_unref(u->vhost);
1356 u->vhost = strshare_get(parv[2]);
1357
1358 /* LOGIN */
1359 if(*parv[4] == '*') /* explicitly unchanged */
1360 return;
1361 if (!strcmp(parv[4], "0"))
1362 handle_clearlogin(si, u);
1363 else
1364 handle_setlogin(si, u, parv[4], 0);
1365 }
1366
1367 static void m_capab(sourceinfo_t *si, int parc, char *parv[])
1368 {
1369 char *p;
1370
1371 use_euid = false;
1372 use_rserv_support = false;
1373 use_tb = false;
1374 use_eopmod = false;
1375 use_mlock = false;
1376 for (p = strtok(parv[0], " "); p != NULL; p = strtok(NULL, " "))
1377 {
1378 if (!irccasecmp(p, "EUID"))
1379 {
1380 slog(LG_DEBUG, "m_capab(): uplink supports EUID, enabling support.");
1381 use_euid = true;
1382 }
1383 if (!irccasecmp(p, "SERVICES"))
1384 {
1385 slog(LG_DEBUG, "m_capab(): uplink has rserv extensions, enabling support.");
1386 use_rserv_support = true;
1387 }
1388 if (!irccasecmp(p, "TB"))
1389 {
1390 slog(LG_DEBUG, "m_capab(): uplink does topic bursting, using if appropriate.");
1391 use_tb = true;
1392 }
1393 if (!irccasecmp(p, "EOPMOD"))
1394 {
1395 slog(LG_DEBUG, "m_capab(): uplink supports EOPMOD, enabling support.");
1396 use_eopmod = true;
1397 }
1398 if (!irccasecmp(p, "MLOCK"))
1399 {
1400 slog(LG_DEBUG, "m_capab(): uplink supports MLOCK, enabling support.");
1401 use_mlock = true;
1402 }
1403 }
1404
1405 /* Now we know whether or not we should enable services support,
1406 * so burst the clients.
1407 * --nenolod
1408 */
1409 services_init();
1410 }
1411
1412 static void m_chghost(sourceinfo_t *si, int parc, char *parv[])
1413 {
1414 user_t *u = user_find(parv[0]);
1415
1416 if (!u)
1417 return;
1418
1419 strshare_unref(u->vhost);
1420 u->vhost = strshare_get(parv[1]);
1421 }
1422
1423 static void m_motd(sourceinfo_t *si, int parc, char *parv[])
1424 {
1425 handle_motd(si->su);
1426 }
1427
1428 /* Server ended their burst: warn all their users if necessary -- jilles */
1429 static void server_eob(server_t *s)
1430 {
1431 mowgli_node_t *n;
1432
1433 MOWGLI_ITER_FOREACH(n, s->userlist.head)
1434 {
1435 handle_nickchange((user_t *)n->data);
1436 }
1437 }
1438
1439 /* Channel drop hook: clear MLOCK when a channel becomes unregistered. */
1440 static void channel_drop(mychan_t *mc)
1441 {
1442 if (use_mlock == false)
1443 return;
1444
1445 if (mc->chan == NULL)
1446 return;
1447
1448 sts(":%s MLOCK %lu %s :", ME, (unsigned long)mc->chan->ts,
1449 mc->chan->name);
1450 }
1451
1452 static server_t *sid_find(char *name)
1453 {
1454 char sid[4];
1455 mowgli_strlcpy(sid, name, 4);
1456 return server_find(sid);
1457 }
1458
1459 void _modinit(module_t * m)
1460 {
1461 MODULE_TRY_REQUEST_DEPENDENCY(m, "transport/rfc1459");
1462 MODULE_TRY_REQUEST_DEPENDENCY(m, "protocol/base36uid");
1463
1464 /* Symbol relocation voodoo. */
1465 server_login = &ts6_server_login;
1466 introduce_nick = &ts6_introduce_nick;
1467 quit_sts = &ts6_quit_sts;
1468 wallops_sts = &ts6_wallops_sts;
1469 join_sts = &ts6_join_sts;
1470 chan_lowerts = &ts6_chan_lowerts;
1471 kick = &ts6_kick;
1472 msg = &ts6_msg;
1473 msg_global_sts = &ts6_msg_global_sts;
1474 notice_user_sts = &ts6_notice_user_sts;
1475 notice_global_sts = &ts6_notice_global_sts;
1476 notice_channel_sts = &ts6_notice_channel_sts;
1477 wallchops = &ts6_wallchops;
1478 numeric_sts = &ts6_numeric_sts;
1479 kill_id_sts = &ts6_kill_id_sts;
1480 part_sts = &ts6_part_sts;
1481 kline_sts = &ts6_kline_sts;
1482 unkline_sts = &ts6_unkline_sts;
1483 xline_sts = &ts6_xline_sts;
1484 unxline_sts = &ts6_unxline_sts;
1485 qline_sts = &ts6_qline_sts;
1486 unqline_sts = &ts6_unqline_sts;
1487 topic_sts = &ts6_topic_sts;
1488 mode_sts = &ts6_mode_sts;
1489 ping_sts = &ts6_ping_sts;
1490 ircd_on_login = &ts6_on_login;
1491 ircd_on_logout = &ts6_on_logout;
1492 jupe = &ts6_jupe;
1493 sethost_sts = &ts6_sethost_sts;
1494 fnc_sts = &ts6_fnc_sts;
1495 invite_sts = &ts6_invite_sts;
1496 holdnick_sts = &ts6_holdnick_sts;
1497 svslogin_sts = &ts6_svslogin_sts;
1498 sasl_sts = &ts6_sasl_sts;
1499 sasl_mechlist_sts = &ts6_sasl_mechlist_sts;
1500 is_valid_host = &ts6_is_valid_host;
1501 mlock_sts = &ts6_mlock_sts;
1502 dline_sts = &ts6_dline_sts;
1503 undline_sts = &ts6_undline_sts;
1504
1505 pcommand_add("PING", m_ping, 1, MSRC_USER | MSRC_SERVER);
1506 pcommand_add("PONG", m_pong, 1, MSRC_SERVER);
1507 pcommand_add("PRIVMSG", m_privmsg, 2, MSRC_USER);
1508 pcommand_add("NOTICE", m_notice, 2, MSRC_UNREG | MSRC_USER | MSRC_SERVER);
1509 pcommand_add("SJOIN", m_sjoin, 4, MSRC_SERVER);
1510 pcommand_add("PART", m_part, 1, MSRC_USER);
1511 pcommand_add("NICK", m_nick, 2, MSRC_USER | MSRC_SERVER);
1512 pcommand_add("QUIT", m_quit, 1, MSRC_USER);
1513 pcommand_add("MODE", m_mode, 2, MSRC_USER | MSRC_SERVER);
1514 pcommand_add("KICK", m_kick, 2, MSRC_USER | MSRC_SERVER);
1515 pcommand_add("KILL", m_kill, 1, MSRC_USER | MSRC_SERVER);
1516 pcommand_add("SQUIT", m_squit, 1, MSRC_USER | MSRC_SERVER);
1517 pcommand_add("SERVER", m_server, 3, MSRC_UNREG | MSRC_SERVER);
1518 pcommand_add("STATS", m_stats, 2, MSRC_USER);
1519 pcommand_add("ADMIN", m_admin, 1, MSRC_USER);
1520 pcommand_add("VERSION", m_version, 1, MSRC_USER);
1521 pcommand_add("INFO", m_info, 1, MSRC_USER);
1522 pcommand_add("WHOIS", m_whois, 2, MSRC_USER);
1523 pcommand_add("TRACE", m_trace, 1, MSRC_USER);
1524 pcommand_add("AWAY", m_away, 0, MSRC_USER);
1525 pcommand_add("JOIN", m_join, 1, MSRC_USER);
1526 pcommand_add("PASS", m_pass, 1, MSRC_UNREG);
1527 pcommand_add("ERROR", m_error, 1, MSRC_UNREG | MSRC_SERVER);
1528 pcommand_add("TOPIC", m_topic, 2, MSRC_USER);
1529 pcommand_add("TB", m_tb, 3, MSRC_SERVER);
1530 pcommand_add("ETB", m_etb, 5, MSRC_USER | MSRC_SERVER);
1531 pcommand_add("ENCAP", m_encap, 2, MSRC_USER | MSRC_SERVER);
1532 pcommand_add("CAPAB", m_capab, 1, MSRC_UNREG);
1533 pcommand_add("UID", m_uid, 9, MSRC_SERVER);
1534 pcommand_add("BMASK", m_bmask, 4, MSRC_SERVER);
1535 pcommand_add("TMODE", m_tmode, 3, MSRC_USER | MSRC_SERVER);
1536 pcommand_add("SID", m_sid, 4, MSRC_SERVER);
1537 pcommand_add("CHGHOST", m_chghost, 2, MSRC_USER | MSRC_SERVER);
1538 pcommand_add("MOTD", m_motd, 1, MSRC_USER);
1539 pcommand_add("SIGNON", m_signon, 5, MSRC_USER);
1540 pcommand_add("EUID", m_euid, 11, MSRC_SERVER);
1541 pcommand_add("MLOCK", m_mlock, 3, MSRC_SERVER);
1542
1543 hook_add_event("server_eob");
1544 hook_add_event("channel_drop");
1545 hook_add_server_eob(server_eob);
1546 hook_add_channel_drop(channel_drop);
1547
1548 m->mflags = MODTYPE_CORE;
1549 }
1550
1551 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
1552 * vim:ts=8
1553 * vim:sw=8
1554 * vim:noexpandtab
1555 */