ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/s_user.c
Revision: 716
Committed: Sat Jul 15 10:22:58 2006 UTC (19 years, 1 month ago) by adx
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/src/s_user.c
File size: 42227 byte(s)
Log Message:
+ added DEAF isupport

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * s_user.c: User related functions.
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 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "tools.h"
27 #include "s_user.h"
28 #include "s_misc.h"
29 #include "channel.h"
30 #include "channel_mode.h"
31 #include "client.h"
32 #include "common.h"
33 #include "fdlist.h"
34 #include "hash.h"
35 #include "irc_string.h"
36 #include "sprintf_irc.h"
37 #include "s_bsd.h"
38 #include "irc_getnameinfo.h"
39 #include "ircd.h"
40 #include "list.h"
41 #include "listener.h"
42 #include "motd.h"
43 #include "numeric.h"
44 #include "s_conf.h"
45 #include "s_log.h"
46 #include "s_serv.h"
47 #include "s_stats.h"
48 #include "send.h"
49 #include "supported.h"
50 #include "whowas.h"
51 #include "memory.h"
52 #include "packet.h"
53 #include "userhost.h"
54 #include "hook.h"
55 #include "s_misc.h"
56 #include "msg.h"
57 #include "pcre.h"
58
59 int MaxClientCount = 1;
60 int MaxConnectionCount = 1;
61 struct Callback *entering_umode_cb = NULL;
62 struct Callback *umode_cb = NULL;
63 struct Callback *uid_get_cb = NULL;
64
65 static char umode_buffer[IRCD_BUFSIZE];
66
67 static void user_welcome(struct Client *);
68 static void report_and_set_user_flags(struct Client *, const struct AccessItem *);
69 static int check_xline(struct Client *);
70 static void introduce_client(struct Client *, struct Client *);
71 static void *uid_get(va_list);
72
73 /* Used for building up the isupport string,
74 * used with init_isupport, add_isupport, delete_isupport
75 */
76
77 struct Isupport
78 {
79 dlink_node node;
80 char *name;
81 char *options;
82 int number;
83 };
84
85 static dlink_list support_list = { NULL, NULL, 0 };
86 MessageFile *isupportFile;
87
88 /* memory is cheap. map 0-255 to equivalent mode */
89 unsigned int user_modes[256] =
90 {
91 /* 0x00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x0F */
92 /* 0x10 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x1F */
93 /* 0x20 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x2F */
94 /* 0x30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x3F */
95 0, /* @ */
96 0, /* A */
97 0, /* B */
98 0, /* C */
99 UMODE_DEAF, /* D */
100 0, /* E */
101 0, /* F */
102 UMODE_SOFTCALLERID, /* G */
103 0, /* H */
104 0, /* I */
105 0, /* J */
106 0, /* K */
107 0, /* L */
108 0, /* M */
109 0, /* N */
110 0, /* O */
111 0, /* P */
112 0, /* Q */
113 0, /* R */
114 0, /* S */
115 0, /* T */
116 0, /* U */
117 0, /* V */
118 0, /* W */
119 0, /* X */
120 0, /* Y */
121 0, /* Z 0x5A */
122 0, 0, 0, 0, 0, /* 0x5F */
123 0, /* 0x60 */
124 UMODE_ADMIN, /* a */
125 UMODE_BOTS, /* b */
126 UMODE_CCONN, /* c */
127 UMODE_DEBUG, /* d */
128 0, /* e */
129 UMODE_FULL, /* f */
130 UMODE_CALLERID, /* g */
131 0, /* h */
132 UMODE_INVISIBLE, /* i */
133 0, /* j */
134 UMODE_SKILL, /* k */
135 UMODE_LOCOPS, /* l */
136 0, /* m */
137 UMODE_NCHANGE, /* n */
138 UMODE_OPER, /* o */
139 0, /* p */
140 0, /* q */
141 UMODE_REJ, /* r */
142 UMODE_SERVNOTICE, /* s */
143 0, /* t */
144 UMODE_UNAUTH, /* u */
145 0, /* v */
146 UMODE_WALLOP, /* w */
147 UMODE_EXTERNAL, /* x */
148 UMODE_SPY, /* y */
149 UMODE_OPERWALL, /* z 0x7A */
150 0,0,0,0,0, /* 0x7B - 0x7F */
151
152 /* 0x80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x8F */
153 /* 0x90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x9F */
154 /* 0xA0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xAF */
155 /* 0xB0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xBF */
156 /* 0xC0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xCF */
157 /* 0xD0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xDF */
158 /* 0xE0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xEF */
159 /* 0xF0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* 0xFF */
160 };
161
162 void
163 assemble_umode_buffer(void)
164 {
165 unsigned int idx = 0;
166 char *umode_buffer_ptr = umode_buffer;
167
168 for (; idx < (sizeof(user_modes) / sizeof(int)); ++idx)
169 if (user_modes[idx])
170 *umode_buffer_ptr++ = idx;
171
172 *umode_buffer_ptr = '\0';
173 }
174
175 /* show_lusers()
176 *
177 * inputs - pointer to client
178 * output - NONE
179 * side effects - display to client user counts etc.
180 */
181 void
182 show_lusers(struct Client *source_p)
183 {
184 const char *from, *to;
185
186 if (!MyConnect(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
187 {
188 from = me.id;
189 to = source_p->id;
190 }
191 else
192 {
193 from = me.name;
194 to = source_p->name;
195 }
196
197 if (!ConfigServerHide.hide_servers || IsOper(source_p))
198 sendto_one(source_p, form_str(RPL_LUSERCLIENT),
199 from, to, (Count.total-Count.invisi),
200 Count.invisi, dlink_list_length(&global_serv_list));
201 else
202 sendto_one(source_p, form_str(RPL_LUSERCLIENT), from, to,
203 (Count.total-Count.invisi), Count.invisi, 1);
204
205 if (Count.oper > 0)
206 sendto_one(source_p, form_str(RPL_LUSEROP),
207 from, to, Count.oper);
208
209 if (dlink_list_length(&unknown_list) > 0)
210 sendto_one(source_p, form_str(RPL_LUSERUNKNOWN),
211 from, to, dlink_list_length(&unknown_list));
212
213 if (dlink_list_length(&global_channel_list) > 0)
214 sendto_one(source_p, form_str(RPL_LUSERCHANNELS),
215 from, to, dlink_list_length(&global_channel_list));
216
217 if (!ConfigServerHide.hide_servers || IsOper(source_p))
218 {
219 sendto_one(source_p, form_str(RPL_LUSERME),
220 from, to, Count.local, Count.myserver);
221 sendto_one(source_p, form_str(RPL_LOCALUSERS),
222 from, to, Count.local, Count.max_loc,
223 Count.local, Count.max_loc);
224 }
225 else
226 {
227 sendto_one(source_p, form_str(RPL_LUSERME),
228 from, to, Count.total, 0);
229 sendto_one(source_p, form_str(RPL_LOCALUSERS),
230 from, to, Count.total, Count.max_tot,
231 Count.total, Count.max_tot);
232 }
233
234 sendto_one(source_p, form_str(RPL_GLOBALUSERS),
235 from, to, Count.total, Count.max_tot,
236 Count.total, Count.max_tot);
237
238 if (!ConfigServerHide.hide_servers || IsOper(source_p))
239 sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
240 MaxConnectionCount, MaxClientCount, Count.totalrestartcount);
241
242 if (Count.local > MaxClientCount)
243 MaxClientCount = Count.local;
244
245 if ((Count.local + Count.myserver) > MaxConnectionCount)
246 MaxConnectionCount = Count.local + Count.myserver;
247 }
248
249 /* show_isupport()
250 *
251 * inputs - pointer to client
252 * output - NONE
253 * side effects - display to client what we support (for them)
254 */
255 void
256 show_isupport(struct Client *source_p)
257 {
258 send_message_file(source_p, isupportFile);
259 }
260
261 /*
262 ** register_local_user
263 ** This function is called when both NICK and USER messages
264 ** have been accepted for the client, in whatever order. Only
265 ** after this, is the USER message propagated.
266 **
267 ** NICK's must be propagated at once when received, although
268 ** it would be better to delay them too until full info is
269 ** available. Doing it is not so simple though, would have
270 ** to implement the following:
271 **
272 ** (actually it has been implemented already for a while) -orabidoo
273 **
274 ** 1) user telnets in and gives only "NICK foobar" and waits
275 ** 2) another user far away logs in normally with the nick
276 ** "foobar" (quite legal, as this server didn't propagate
277 ** it).
278 ** 3) now this server gets nick "foobar" from outside, but
279 ** has alread the same defined locally. Current server
280 ** would just issue "KILL foobar" to clean out dups. But,
281 ** this is not fair. It should actually request another
282 ** nick from local user or kill him/her...
283 */
284 void
285 register_local_user(struct Client *client_p, struct Client *source_p,
286 const char *nick, const char *username)
287 {
288 const struct AccessItem *aconf = NULL;
289 char ipaddr[HOSTIPLEN];
290 dlink_node *ptr = NULL;
291 dlink_node *m = NULL;
292
293 assert(source_p != NULL);
294 assert(MyConnect(source_p));
295 assert(source_p->username != username);
296 assert(!source_p->localClient->registration);
297
298 ClearCap(client_p, CAP_TS6);
299
300 if (ConfigFileEntry.ping_cookie)
301 {
302 if (!IsPingSent(source_p) &&
303 source_p->localClient->random_ping == 0)
304 {
305 source_p->localClient->random_ping = (unsigned long)rand();
306 sendto_one(source_p, "PING :%lu",
307 source_p->localClient->random_ping);
308 SetPingSent(source_p);
309 return;
310 }
311
312 if (!HasPingCookie(source_p))
313 return;
314 }
315
316 source_p->localClient->last = CurrentTime;
317 /* Straight up the maximum rate of flooding... */
318 source_p->localClient->allow_read = MAX_FLOOD_BURST;
319
320 if (!execute_callback(client_check_cb, source_p, username))
321 return;
322
323 if (valid_hostname(source_p->host) == 0)
324 {
325 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- You have an illegal "
326 "character in your hostname", me.name, source_p->name);
327 strlcpy(source_p->host, source_p->sockhost,
328 sizeof(source_p->host));
329 }
330
331 ptr = source_p->localClient->confs.head;
332 aconf = map_to_conf(ptr->data);
333
334 if (!IsGotId(source_p))
335 {
336 const char *p = NULL;
337 unsigned int i = 0;
338
339 if (IsNeedIdentd(aconf))
340 {
341 ServerStats->is_ref++;
342 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- You need to install "
343 "identd to use this server", me.name, source_p->name);
344 exit_client(source_p, &me, "Install identd");
345 return;
346 }
347
348 p = username;
349
350 if (!IsNoTilde(aconf))
351 source_p->username[i++] = '~';
352
353 while (*p && i < USERLEN)
354 {
355 if (*p != '[')
356 source_p->username[i++] = *p;
357 p++;
358 }
359
360 source_p->username[i] = '\0';
361 }
362
363 /* password check */
364 if (!EmptyString(aconf->passwd))
365 {
366 const char *pass = source_p->localClient->passwd;
367
368 if (!match_conf_password(pass, aconf))
369 {
370 ServerStats->is_ref++;
371 sendto_one(source_p, form_str(ERR_PASSWDMISMATCH),
372 me.name, source_p->name);
373 exit_client(source_p, &me, "Bad Password");
374 return;
375 }
376 }
377
378 /* don't free source_p->localClient->passwd here - it can be required
379 * by masked /stats I if there are auth{} blocks with need_password = no;
380 * --adx
381 */
382
383 /* report if user has &^>= etc. and set flags as needed in source_p */
384 report_and_set_user_flags(source_p, aconf);
385
386 /* Limit clients -
387 * We want to be able to have servers and F-line clients
388 * connect, so save room for "buffer" connections.
389 * Smaller servers may want to decrease this, and it should
390 * probably be just a percentage of the MAXCLIENTS...
391 * -Taner
392 */
393 /* Except "F:" clients */
394 if ((Count.local >= ServerInfo.max_clients + MAX_BUFFER) ||
395 (Count.local >= ServerInfo.max_clients && !IsExemptLimits(source_p)))
396 {
397 sendto_realops_flags(UMODE_FULL, L_ALL,
398 "Too many clients, rejecting %s[%s].",
399 nick, source_p->host);
400 ServerStats->is_ref++;
401 exit_client(source_p, &me, "Sorry, server is full - try later");
402 return;
403 }
404
405 /* valid user name check */
406 if (valid_username(source_p->username) == 0)
407 {
408 char tmpstr2[IRCD_BUFSIZE];
409
410 sendto_realops_flags(UMODE_REJ, L_ALL, "Invalid username: %s (%s@%s)",
411 nick, source_p->username, source_p->host);
412 ServerStats->is_ref++;
413 ircsprintf(tmpstr2, "Invalid username [%s]", source_p->username);
414 exit_client(source_p, &me, tmpstr2);
415 return;
416 }
417
418 assert(source_p == client_p);
419
420 if (check_xline(source_p))
421 return;
422
423 if (IsDead(client_p))
424 return;
425
426 if (me.id[0])
427 {
428 const char *id = execute_callback(uid_get_cb, source_p);
429
430 while (hash_find_id(id) != NULL)
431 id = uid_get(NULL);
432
433 strlcpy(source_p->id, id, sizeof(source_p->id));
434 hash_add_id(source_p);
435 }
436
437 irc_getnameinfo((struct sockaddr *)&source_p->localClient->ip,
438 source_p->localClient->ip.ss_len, ipaddr,
439 HOSTIPLEN, NULL, 0, NI_NUMERICHOST);
440
441 sendto_realops_flags(UMODE_CCONN, L_ALL,
442 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
443 nick, source_p->username, source_p->host,
444 ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
445 "255.255.255.255" : ipaddr, get_client_class(source_p),
446 source_p->info);
447
448 /* If they have died in send_* don't do anything. */
449 if (IsDead(source_p))
450 return;
451
452 if (ConfigFileEntry.invisible_on_connect)
453 {
454 source_p->umodes |= UMODE_INVISIBLE;
455 Count.invisi++;
456 }
457
458 if ((++Count.local) > Count.max_loc)
459 {
460 Count.max_loc = Count.local;
461
462 if (!(Count.max_loc % 10))
463 sendto_realops_flags(UMODE_ALL, L_ALL, "New Max Local Clients: %d",
464 Count.max_loc);
465 }
466
467 SetClient(source_p);
468
469 source_p->servptr = &me;
470 dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users);
471
472 /* Increment our total user count here */
473 if (++Count.total > Count.max_tot)
474 Count.max_tot = Count.total;
475 Count.totalrestartcount++;
476
477 source_p->localClient->allow_read = MAX_FLOOD_BURST;
478
479 if ((m = dlinkFindDelete(&unknown_list, source_p)) != NULL)
480 {
481 free_dlink_node(m);
482 dlinkAdd(source_p, &source_p->localClient->lclient_node, &local_client_list);
483 }
484 else assert(0);
485
486 user_welcome(source_p);
487 add_user_host(source_p->username, source_p->host, 0);
488 SetUserHost(source_p);
489
490 introduce_client(client_p, source_p);
491 }
492
493 /* register_remote_user()
494 *
495 * inputs - client_p directly connected client
496 * - source_p remote or directly connected client
497 * - username to register as
498 * - host name to register as
499 * - server name
500 * - realname (gecos)
501 * output - NONE
502 * side effects - This function is called when a remote client
503 * is introduced by a server.
504 */
505 void
506 register_remote_user(struct Client *client_p, struct Client *source_p,
507 const char *username, const char *host, const char *server,
508 const char *realname)
509 {
510 struct Client *target_p = NULL;
511
512 assert(source_p != NULL);
513 assert(source_p->username != username);
514
515 strlcpy(source_p->host, host, sizeof(source_p->host));
516 strlcpy(source_p->info, realname, sizeof(source_p->info));
517 strlcpy(source_p->username, username, sizeof(source_p->username));
518
519 /*
520 * coming from another server, take the servers word for it
521 */
522 source_p->servptr = find_server(server);
523
524 /* Super GhostDetect:
525 * If we can't find the server the user is supposed to be on,
526 * then simply blow the user away. -Taner
527 */
528 if (source_p->servptr == NULL)
529 {
530 sendto_realops_flags(UMODE_ALL, L_ALL,
531 "No server %s for user %s[%s@%s] from %s",
532 server, source_p->name, source_p->username,
533 source_p->host, source_p->from->name);
534 kill_client(client_p, source_p, "%s (Server doesn't exist)", me.name);
535
536 SetKilled(source_p);
537 exit_client(source_p, &me, "Ghosted Client");
538 return;
539 }
540
541 if ((target_p = source_p->servptr) && target_p->from != source_p->from)
542 {
543 sendto_realops_flags(UMODE_DEBUG, L_ALL,
544 "Bad User [%s] :%s USER %s@%s %s, != %s[%s]",
545 client_p->name, source_p->name, source_p->username,
546 source_p->host, source_p->servptr->name,
547 target_p->name, target_p->from->name);
548 kill_client(client_p, source_p,
549 "%s (NICK from wrong direction (%s != %s))",
550 me.name, source_p->servptr->name, target_p->from->name);
551 SetKilled(source_p);
552 exit_client(source_p, &me, "USER server wrong direction");
553 return;
554 }
555
556 /* Increment our total user count here */
557 if (++Count.total > Count.max_tot)
558 Count.max_tot = Count.total;
559
560 ++source_p->from->serv->dep_users;
561
562 SetClient(source_p);
563 dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->users);
564 add_user_host(source_p->username, source_p->host, 1);
565 SetUserHost(source_p);
566
567 introduce_client(client_p, source_p);
568 }
569
570 /* introduce_client()
571 *
572 * inputs - client_p
573 * - source_p
574 * output - NONE
575 * side effects - This common function introduces a client to the rest
576 * of the net, either from a local client connect or
577 * from a remote connect.
578 */
579 static void
580 introduce_client(struct Client *client_p, struct Client *source_p)
581 {
582 dlink_node *server_node = NULL;
583 static char ubuf[12];
584
585 if (MyClient(source_p))
586 send_umode(source_p, source_p, 0, SEND_UMODES, ubuf);
587 else
588 send_umode(NULL, source_p, 0, SEND_UMODES, ubuf);
589
590 if (*ubuf == '\0')
591 {
592 ubuf[0] = '+';
593 ubuf[1] = '\0';
594 }
595
596 /* arghhh one could try not introducing new nicks to ll leafs
597 * but then you have to introduce them "on the fly" in SJOIN
598 * not fun.
599 * Its not going to cost much more bandwidth to simply let new
600 * nicks just ride on through.
601 */
602
603 /* We now introduce nicks "on the fly" in SJOIN anyway --
604 * you _need_ to if you aren't going to burst everyone initially.
605 *
606 * Only send to non CAP_LL servers, unless we're a lazylink leaf,
607 * in that case just send it to the uplink.
608 * -davidt
609 * rewritten to cope with SIDs .. eww eww eww --is
610 */
611 if (!ServerInfo.hub && uplink && IsCapable(uplink, CAP_LL) &&
612 client_p != uplink)
613 {
614 if (IsCapable(uplink, CAP_TS6) && HasID(source_p))
615 {
616 sendto_one(uplink, ":%s UID %s %d %lu %s %s %s %s %s :%s",
617 source_p->servptr->id,
618 source_p->name, source_p->hopcount+1,
619 (unsigned long)source_p->tsinfo,
620 ubuf, source_p->username, source_p->host,
621 (MyClient(source_p) && IsIPSpoof(source_p)) ?
622 "0" : source_p->sockhost, source_p->id, source_p->info);
623 }
624 else
625 {
626 sendto_one(uplink, "NICK %s %d %lu %s %s %s %s :%s",
627 source_p->name, source_p->hopcount+1,
628 (unsigned long)source_p->tsinfo,
629 ubuf, source_p->username, source_p->host,
630 source_p->servptr->name, source_p->info);
631 }
632 }
633 else
634 {
635 DLINK_FOREACH(server_node, serv_list.head)
636 {
637 struct Client *server = server_node->data;
638
639 if (IsCapable(server, CAP_LL) || server == client_p)
640 continue;
641
642 if (IsCapable(server, CAP_TS6) && HasID(source_p))
643 sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
644 source_p->servptr->id,
645 source_p->name, source_p->hopcount+1,
646 (unsigned long)source_p->tsinfo,
647 ubuf, source_p->username, source_p->host,
648 (MyClient(source_p) && IsIPSpoof(source_p)) ?
649 "0" : source_p->sockhost, source_p->id, source_p->info);
650 else
651 sendto_one(server, "NICK %s %d %lu %s %s %s %s :%s",
652 source_p->name, source_p->hopcount+1,
653 (unsigned long)source_p->tsinfo,
654 ubuf, source_p->username, source_p->host,
655 source_p->servptr->name, source_p->info);
656 }
657 }
658 }
659
660 /* valid_hostname()
661 *
662 * Inputs - pointer to hostname
663 * Output - 1 if valid, 0 if not
664 * Side effects - check hostname for validity
665 *
666 * NOTE: this doesn't allow a hostname to begin with a dot and
667 * will not allow more dots than chars.
668 */
669 int
670 valid_hostname(const char *hostname)
671 {
672 const char *p = hostname;
673
674 assert(p != NULL);
675
676 if ('.' == *p || ':' == *p)
677 return 0;
678
679 while (*p)
680 {
681 if (!IsHostChar(*p))
682 return 0;
683 p++;
684 }
685
686 return 1;
687 }
688
689 /* valid_username()
690 *
691 * Inputs - pointer to user
692 * Output - 1 if valid, 0 if not
693 * Side effects - check username for validity
694 *
695 * Absolutely always reject any '*' '!' '?' '@' in an user name
696 * reject any odd control characters names.
697 * Allow '.' in username to allow for "first.last"
698 * style of username
699 */
700 int
701 valid_username(const char *username)
702 {
703 int dots = 0;
704 const char *p = username;
705
706 assert(p != NULL);
707
708 if ('~' == *p)
709 ++p;
710
711 /* reject usernames that don't start with an alphanum
712 * i.e. reject jokers who have '-@somehost' or '.@somehost'
713 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
714 */
715 if (!IsAlNum(*p))
716 return 0;
717
718 while (*++p)
719 {
720 if ((*p == '.') && ConfigFileEntry.dots_in_ident)
721 {
722 dots++;
723
724 if (dots > ConfigFileEntry.dots_in_ident)
725 return 0;
726 if (!IsUserChar(p[1]))
727 return 0;
728 }
729 else if (!IsUserChar(*p))
730 return 0;
731 }
732
733 return 1;
734 }
735
736 /* report_and_set_user_flags()
737 *
738 * inputs - pointer to source_p
739 * - pointer to aconf for this user
740 * output - NONE
741 * side effects - Report to user any special flags
742 * they are getting, and set them.
743 */
744 static void
745 report_and_set_user_flags(struct Client *source_p, const struct AccessItem *aconf)
746 {
747 /* If this user is being spoofed, tell them so */
748 if (IsConfDoSpoofIp(aconf))
749 {
750 sendto_one(source_p,
751 ":%s NOTICE %s :*** Spoofing your IP. congrats.",
752 me.name, source_p->name);
753 }
754
755 /* If this user is in the exception class, Set it "E lined" */
756 if (IsConfExemptKline(aconf))
757 {
758 SetExemptKline(source_p);
759 sendto_one(source_p,
760 ":%s NOTICE %s :*** You are exempt from K/D/G lines. congrats.",
761 me.name, source_p->name);
762 }
763
764 /* The else here is to make sure that G line exempt users
765 * do not get noticed twice.
766 */
767 else if (IsConfExemptGline(aconf))
768 {
769 SetExemptGline(source_p);
770 sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from G lines.",
771 me.name, source_p->name);
772 }
773
774 if (IsConfExemptResv(aconf))
775 {
776 SetExemptResv(source_p);
777 sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from resvs.",
778 me.name, source_p->name);
779 }
780
781 /* If this user is exempt from user limits set it "F lined" */
782 if (IsConfExemptLimits(aconf))
783 {
784 SetExemptLimits(source_p);
785 sendto_one(source_p,
786 ":%s NOTICE %s :*** You are exempt from user limits. congrats.",
787 me.name,source_p->name);
788 }
789
790 /* If this user is exempt from idle time outs */
791 if (IsConfIdlelined(aconf))
792 {
793 SetIdlelined(source_p);
794 sendto_one(source_p,
795 ":%s NOTICE %s :*** You are exempt from idle limits. congrats.",
796 me.name, source_p->name);
797 }
798
799 if (IsConfCanFlood(aconf))
800 {
801 SetCanFlood(source_p);
802 sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from flood "
803 "protection, aren't you fearsome.",
804 me.name, source_p->name);
805 }
806 }
807
808 /* do_local_user()
809 *
810 * inputs -
811 * output - NONE
812 * side effects -
813 */
814 void
815 do_local_user(const char *nick, struct Client *client_p, struct Client *source_p,
816 const char *username, const char *host, const char *server,
817 const char *realname)
818 {
819 assert(source_p != NULL);
820 assert(source_p->username != username);
821
822 if (source_p == NULL)
823 return;
824
825 if (!IsUnknown(source_p))
826 {
827 sendto_one(source_p, form_str(ERR_ALREADYREGISTRED),
828 me.name, nick);
829 return;
830 }
831
832 source_p->localClient->registration &= ~REG_NEED_USER;
833
834 /*
835 * don't take the clients word for it, ever
836 */
837 source_p->servptr = &me;
838
839 strlcpy(source_p->info, realname, sizeof(source_p->info));
840
841 if (!IsGotId(source_p))
842 {
843 /* save the username in the client
844 * If you move this you'll break ping cookies..you've been warned
845 */
846 strlcpy(source_p->username, username, sizeof(source_p->username));
847 }
848
849 if (!source_p->localClient->registration)
850 /* NICK already received, now I have USER... */
851 register_local_user(client_p, source_p, source_p->name, username);
852 }
853
854 /* change_simple_umode()
855 *
856 * this callback can be hooked to allow special handling of
857 * certain usermodes
858 */
859 static void *
860 change_simple_umode(va_list args)
861 {
862 struct Client *client_p;
863 struct Client *source_p;
864 int what;
865 unsigned int flag;
866
867 client_p = va_arg(args, struct Client *);
868 source_p = va_arg(args, struct Client *);
869 what = va_arg(args, int);
870 flag = va_arg(args, unsigned int);
871
872 if (what == MODE_ADD)
873 source_p->umodes |= flag;
874 else
875 source_p->umodes &= ~flag;
876
877 return NULL;
878 }
879
880 /* set_user_mode()
881 *
882 * added 15/10/91 By Darren Reed.
883 * parv[0] - sender
884 * parv[1] - username to change mode for
885 * parv[2] - modes to change
886 */
887 void
888 set_user_mode(struct Client *client_p, struct Client *source_p,
889 int parc, char *parv[])
890 {
891 unsigned int flag, setflags;
892 char **p, *m, buf[IRCD_BUFSIZE];
893 struct Client *target_p;
894 int what = MODE_ADD, badflag = 0, i;
895
896 assert(!(parc < 2));
897
898 if ((target_p = find_person(client_p, parv[1])) == NULL)
899 {
900 if (MyConnect(source_p))
901 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
902 me.name, source_p->name, parv[1]);
903 return;
904 }
905
906 if (IsServer(source_p))
907 {
908 sendto_realops_flags(UMODE_ALL, L_ADMIN, "*** Mode for User %s from %s",
909 parv[1], source_p->name);
910 return;
911 }
912
913 if (source_p != target_p || target_p->from != source_p->from)
914 {
915 sendto_one(source_p, form_str(ERR_USERSDONTMATCH),
916 me.name, source_p->name);
917 return;
918 }
919
920 if (parc < 3)
921 {
922 m = buf;
923 *m++ = '+';
924
925 for (i = 0; i < 128; i++)
926 if (source_p->umodes & user_modes[i])
927 *m++ = (char)i;
928 *m = '\0';
929
930 sendto_one(source_p, form_str(RPL_UMODEIS),
931 me.name, source_p->name, buf);
932 return;
933 }
934
935 execute_callback(entering_umode_cb, client_p, source_p);
936
937 /* find flags already set for user */
938 setflags = source_p->umodes;
939
940 /* parse mode change string(s) */
941 for (p = &parv[2]; p && *p; p++)
942 {
943 for (m = *p; *m; m++)
944 {
945 switch (*m)
946 {
947 case '+':
948 what = MODE_ADD;
949 break;
950 case '-':
951 what = MODE_DEL;
952 break;
953 case 'o':
954 if (what == MODE_ADD)
955 {
956 if (IsServer(client_p) && !IsOper(source_p))
957 {
958 ++Count.oper;
959 SetOper(source_p);
960 }
961 }
962 else
963 {
964 /* Only decrement the oper counts if an oper to begin with
965 * found by Pat Szuta, Perly , perly@xnet.com
966 */
967 if (!IsOper(source_p))
968 break;
969
970 ClearOper(source_p);
971 source_p->umodes &= ~ConfigFileEntry.oper_only_umodes;
972 Count.oper--;
973
974 if (MyConnect(source_p))
975 {
976 dlink_node *dm;
977
978 detach_conf(source_p, OPER_TYPE);
979 ClearOperFlags(source_p);
980
981 if ((dm = dlinkFindDelete(&oper_list, source_p)) != NULL)
982 free_dlink_node(dm);
983 }
984 }
985
986 break;
987
988 /* we may not get these,
989 * but they shouldnt be in default
990 */
991 case ' ' :
992 case '\n':
993 case '\r':
994 case '\t':
995 break;
996
997 default:
998 if ((flag = user_modes[(unsigned char)*m]))
999 {
1000 if (MyConnect(source_p) && !IsOper(source_p) &&
1001 (ConfigFileEntry.oper_only_umodes & flag))
1002 {
1003 badflag = 1;
1004 }
1005 else
1006 execute_callback(umode_cb, client_p, source_p, what, flag);
1007 }
1008 else
1009 {
1010 if (MyConnect(source_p))
1011 badflag = 1;
1012 }
1013
1014 break;
1015 }
1016 }
1017 }
1018
1019 if (badflag)
1020 sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG),
1021 me.name, source_p->name);
1022
1023 if ((source_p->umodes & UMODE_NCHANGE) && !IsOperN(source_p))
1024 {
1025 sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;",
1026 me.name, source_p->name);
1027 source_p->umodes &= ~UMODE_NCHANGE; /* only tcm's really need this */
1028 }
1029
1030 if (MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) &&
1031 !IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p))
1032 {
1033 sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;",
1034 me.name, source_p->name);
1035 source_p->umodes &= ~UMODE_ADMIN;
1036 }
1037
1038 if (!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p))
1039 ++Count.invisi;
1040 if ((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p))
1041 --Count.invisi;
1042
1043 /*
1044 * compare new flags with old flags and send string which
1045 * will cause servers to update correctly.
1046 */
1047 send_umode_out(client_p, source_p, setflags);
1048 }
1049
1050 /* send_umode()
1051 * send the MODE string for user (user) to connection client_p
1052 * -avalon
1053 */
1054 void
1055 send_umode(struct Client *client_p, struct Client *source_p,
1056 unsigned int old, unsigned int sendmask, char *umode_buf)
1057 {
1058 int what = 0;
1059 unsigned int i;
1060 unsigned int flag;
1061 char *m = umode_buf;
1062
1063 /*
1064 * build a string in umode_buf to represent the change in the user's
1065 * mode between the new (source_p->umodes) and 'old'.
1066 */
1067 for (i = 0; i < 128; i++)
1068 {
1069 flag = user_modes[i];
1070 if (!flag)
1071 continue;
1072
1073 if (MyClient(source_p) && !(flag & sendmask))
1074 continue;
1075
1076 if ((flag & old) && !(source_p->umodes & flag))
1077 {
1078 if (what == MODE_DEL)
1079 *m++ = (char)i;
1080 else
1081 {
1082 what = MODE_DEL;
1083 *m++ = '-';
1084 *m++ = (char)i;
1085 }
1086 }
1087 else if (!(flag & old) && (source_p->umodes & flag))
1088 {
1089 if (what == MODE_ADD)
1090 *m++ = (char)i;
1091 else
1092 {
1093 what = MODE_ADD;
1094 *m++ = '+';
1095 *m++ = (char)i;
1096 }
1097 }
1098 }
1099
1100 *m = '\0';
1101
1102 if (*umode_buf && client_p)
1103 sendto_one(client_p, ":%s!%s@%s MODE %s :%s",
1104 source_p->name, source_p->username,
1105 source_p->host, source_p->name, umode_buf);
1106 }
1107
1108 /* send_umode_out()
1109 *
1110 * inputs -
1111 * output - NONE
1112 * side effects - Only send ubuf out to servers that know about this client
1113 */
1114 void
1115 send_umode_out(struct Client *client_p, struct Client *source_p,
1116 unsigned int old)
1117 {
1118 char buf[IRCD_BUFSIZE] = { '\0' };
1119 dlink_node *ptr = NULL;
1120
1121 send_umode(NULL, source_p, old, IsOperHiddenAdmin(source_p) ?
1122 SEND_UMODES & ~UMODE_ADMIN : SEND_UMODES, buf);
1123
1124 if (buf[0])
1125 {
1126 DLINK_FOREACH(ptr, serv_list.head)
1127 {
1128 struct Client *target_p = ptr->data;
1129
1130 if ((target_p != client_p) && (target_p != source_p))
1131 {
1132 if ((!(ServerInfo.hub && IsCapable(target_p, CAP_LL))) ||
1133 (target_p->localClient->serverMask &
1134 source_p->lazyLinkClientExists))
1135 sendto_one(target_p, ":%s MODE %s :%s",
1136 ID_or_name(source_p, target_p),
1137 ID_or_name(source_p, target_p), buf);
1138 }
1139 }
1140 }
1141
1142 if (client_p && MyClient(client_p))
1143 send_umode(client_p, source_p, old, 0xffffffff, buf);
1144 }
1145
1146 /* user_welcome()
1147 *
1148 * inputs - client pointer to client to welcome
1149 * output - NONE
1150 * side effects -
1151 */
1152 static void
1153 user_welcome(struct Client *source_p)
1154 {
1155 #if defined(__TIME__) && defined(__DATE__)
1156 static const char built_date[] = __DATE__ " at " __TIME__;
1157 #else
1158 static const char built_date[] = "unknown";
1159 #endif
1160
1161 #ifdef HAVE_LIBCRYPTO
1162 if (source_p->localClient->fd.ssl != NULL)
1163 sendto_one(source_p, ":%s NOTICE %s :*** Connected securely via %s",
1164 me.name, source_p->name,
1165 ssl_get_cipher(source_p->localClient->fd.ssl));
1166 #endif
1167
1168 sendto_one(source_p, form_str(RPL_WELCOME), me.name, source_p->name,
1169 ServerInfo.network_name, source_p->name);
1170 sendto_one(source_p, form_str(RPL_YOURHOST), me.name, source_p->name,
1171 get_listener_name(source_p->localClient->listener), ircd_version);
1172 sendto_one(source_p, form_str(RPL_CREATED),
1173 me.name, source_p->name, built_date);
1174 sendto_one(source_p, form_str(RPL_MYINFO),
1175 me.name, source_p->name, me.name, ircd_version, umode_buffer);
1176 show_isupport(source_p);
1177
1178 if (source_p->id[0] != '\0')
1179 sendto_one(source_p, form_str(RPL_YOURID), me.name,
1180 source_p->name, source_p->id);
1181
1182 show_lusers(source_p);
1183
1184 if (ConfigFileEntry.short_motd)
1185 {
1186 sendto_one(source_p, "NOTICE %s :*** Notice -- motd was last changed at %s",
1187 source_p->name, ConfigFileEntry.motd.lastChangedDate);
1188 sendto_one(source_p,
1189 "NOTICE %s :*** Notice -- Please read the motd if you haven't "
1190 "read it", source_p->name);
1191 sendto_one(source_p, form_str(RPL_MOTDSTART),
1192 me.name, source_p->name, me.name);
1193 sendto_one(source_p, form_str(RPL_MOTD),
1194 me.name, source_p->name,
1195 "*** This is the short motd ***");
1196 sendto_one(source_p, form_str(RPL_ENDOFMOTD),
1197 me.name, source_p->name);
1198 }
1199 else
1200 send_message_file(source_p, &ConfigFileEntry.motd);
1201 }
1202
1203 /* check_xline()
1204 *
1205 * inputs - pointer to client to test
1206 * outupt - 1 if exiting 0 if ok
1207 * side effects -
1208 */
1209 static int
1210 check_xline(struct Client *source_p)
1211 {
1212 struct ConfItem *conf = NULL;
1213 const char *reason = NULL;
1214
1215 if ((conf = find_matching_name_conf(XLINE_TYPE, source_p->info, NULL, NULL, 0)) ||
1216 (conf = find_matching_name_conf(RXLINE_TYPE, source_p->info, NULL, NULL, 0)))
1217 {
1218 struct MatchItem *reg = map_to_conf(conf);
1219
1220 ++reg->count;
1221
1222 if (reg->reason != NULL)
1223 reason = reg->reason;
1224 else
1225 reason = "No Reason";
1226
1227 sendto_realops_flags(UMODE_REJ, L_ALL,
1228 "X-line Rejecting [%s] [%s], user %s [%s]",
1229 source_p->info, reason,
1230 get_client_name(source_p, HIDE_IP),
1231 source_p->sockhost);
1232
1233 ServerStats->is_ref++;
1234 if (REJECT_HOLD_TIME > 0)
1235 {
1236 sendto_one(source_p, ":%s NOTICE %s :Bad user info",
1237 me.name, source_p->name);
1238 source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
1239 SetCaptured(source_p);
1240 }
1241 else
1242 exit_client(source_p, &me, "Bad user info");
1243 return 1;
1244 }
1245
1246 return 0;
1247 }
1248
1249 /* oper_up()
1250 *
1251 * inputs - pointer to given client to oper
1252 * output - NONE
1253 * side effects - Blindly opers up given source_p, using aconf info
1254 * all checks on passwords have already been done.
1255 * This could also be used by rsa oper routines.
1256 */
1257 void
1258 oper_up(struct Client *source_p)
1259 {
1260 unsigned int old = source_p->umodes;
1261 const char *operprivs = "";
1262 const struct AccessItem *oconf = NULL;
1263
1264 assert(source_p->localClient->confs.head);
1265 oconf = map_to_conf((source_p->localClient->confs.head)->data);
1266
1267 ++Count.oper;
1268 SetOper(source_p);
1269
1270 if (oconf->modes)
1271 source_p->umodes |= oconf->modes;
1272 else if (ConfigFileEntry.oper_umodes)
1273 source_p->umodes |= ConfigFileEntry.oper_umodes;
1274 else
1275 source_p->umodes |= (UMODE_SERVNOTICE|UMODE_OPERWALL|
1276 UMODE_WALLOP|UMODE_LOCOPS);
1277
1278 assert(dlinkFind(&oper_list, source_p) == NULL);
1279 dlinkAdd(source_p, make_dlink_node(), &oper_list);
1280
1281 operprivs = oper_privs_as_string(oconf->port);
1282
1283 SetOFlag(source_p, oconf->port);
1284
1285 if (IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p))
1286 source_p->umodes |= UMODE_ADMIN;
1287 if (!IsOperN(source_p))
1288 source_p->umodes &= ~UMODE_NCHANGE;
1289
1290 sendto_realops_flags(UMODE_ALL, L_ALL, "%s (%s@%s) is now an operator",
1291 source_p->name, source_p->username, source_p->host);
1292 send_umode_out(source_p, source_p, old);
1293 sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
1294 sendto_one(source_p, ":%s NOTICE %s :*** Oper privs are %s",
1295 me.name, source_p->name, operprivs);
1296 send_message_file(source_p, &ConfigFileEntry.opermotd);
1297 }
1298
1299 static char new_uid[TOTALSIDUID + 1]; /* allow for \0 */
1300
1301 int
1302 valid_sid(const char *sid)
1303 {
1304
1305 if (strlen(sid) == IRC_MAXSID)
1306 if (IsDigit(*sid))
1307 if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
1308 return 1;
1309
1310 return 0;
1311 }
1312
1313 /*
1314 * init_uid()
1315 *
1316 * inputs - NONE
1317 * output - NONE
1318 * side effects - new_uid is filled in with server id portion (sid)
1319 * (first 3 bytes) or defaulted to 'A'.
1320 * Rest is filled in with 'A'
1321 */
1322 void
1323 init_uid(void)
1324 {
1325 int i;
1326
1327 memset(new_uid, 0, sizeof(new_uid));
1328
1329 if (ServerInfo.sid != NULL)
1330 {
1331 strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid));
1332 strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
1333
1334 hash_add_id(&me);
1335 }
1336
1337 for (i = 0; i < IRC_MAXSID; i++)
1338 if (new_uid[i] == '\0')
1339 new_uid[i] = 'A';
1340
1341 /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1342 /* Yes nenolod, I have known it was off by one ever since I wrote it
1343 * But *JUST* for you, though, it really doesn't look as *pretty*
1344 * -Dianora
1345 */
1346 memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1347
1348 entering_umode_cb = register_callback("entering_umode", NULL);
1349 umode_cb = register_callback("changing_umode", change_simple_umode);
1350 uid_get_cb = register_callback("uid_get", uid_get);
1351 }
1352
1353 /*
1354 * add_one_to_uid
1355 *
1356 * inputs - index number into new_uid
1357 * output - NONE
1358 * side effects - new_uid is incremented by one
1359 * note this is a recursive function
1360 */
1361 static void
1362 add_one_to_uid(int i)
1363 {
1364 if (i != IRC_MAXSID) /* Not reached server SID portion yet? */
1365 {
1366 if (new_uid[i] == 'Z')
1367 new_uid[i] = '0';
1368 else if (new_uid[i] == '9')
1369 {
1370 new_uid[i] = 'A';
1371 add_one_to_uid(i-1);
1372 }
1373 else
1374 ++new_uid[i];
1375 }
1376 else
1377 {
1378 /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1379 if (new_uid[i] == 'Z')
1380 memcpy(new_uid + IRC_MAXSID, "AAAAAA", IRC_MAXUID);
1381 else
1382 ++new_uid[i];
1383 }
1384 }
1385
1386 /*
1387 * uid_get
1388 *
1389 * inputs - struct Client *
1390 * output - new UID is returned to caller
1391 * side effects - new_uid is incremented by one.
1392 */
1393 static void *
1394 uid_get(va_list args)
1395 {
1396 add_one_to_uid(TOTALSIDUID - 1); /* index from 0 */
1397 return new_uid;
1398 }
1399
1400 /*
1401 * init_isupport()
1402 *
1403 * input - NONE
1404 * output - NONE
1405 * side effects - Must be called before isupport is enabled
1406 */
1407 void
1408 init_isupport(void)
1409 {
1410 isupportFile = init_MessageLine();
1411
1412 add_isupport("CALLERID", NULL, -1);
1413 add_isupport("CASEMAPPING", CASEMAP, -1);
1414 add_isupport("DEAF", "D", -1);
1415 add_isupport("KICKLEN", NULL, KICKLEN);
1416 add_isupport("MODES", NULL, MAXMODEPARAMS);
1417 add_isupport("NICKLEN", NULL, NICKLEN-1);
1418 #ifdef HALFOPS
1419 add_isupport("PREFIX", "(ohv)@%+", -1);
1420 add_isupport("STATUSMSG", "@%+", -1);
1421 #else
1422 add_isupport("PREFIX", "(ov)@+", -1);
1423 add_isupport("STATUSMSG", "@+", -1);
1424 #endif
1425 add_isupport("TOPICLEN", NULL, TOPICLEN);
1426 }
1427
1428 /*
1429 * add_isupport()
1430 *
1431 * input - name of supported function
1432 * - options if any
1433 * - number if any
1434 * output - NONE
1435 * side effects - Each supported item must call this when activated
1436 */
1437 void
1438 add_isupport(const char *name, const char *options, int n)
1439 {
1440 dlink_node *ptr;
1441 struct Isupport *support;
1442
1443 DLINK_FOREACH(ptr, support_list.head)
1444 {
1445 support = ptr->data;
1446 if (irccmp(support->name, name) == 0)
1447 {
1448 MyFree(support->name);
1449 MyFree(support->options);
1450 break;
1451 }
1452 }
1453
1454 if (ptr == NULL)
1455 {
1456 support = MyMalloc(sizeof(*support));
1457 dlinkAddTail(support, &support->node, &support_list);
1458 }
1459
1460 DupString(support->name, name);
1461 if (options != NULL)
1462 DupString(support->options, options);
1463 support->number = n;
1464
1465 rebuild_isupport_message_line();
1466 }
1467
1468 /*
1469 * delete_isupport()
1470 *
1471 * input - name of supported function
1472 * output - NONE
1473 * side effects - Each supported item must call this when deactivated
1474 */
1475 void
1476 delete_isupport(const char *name)
1477 {
1478 dlink_node *ptr;
1479 struct Isupport *support;
1480
1481 DLINK_FOREACH(ptr, support_list.head)
1482 {
1483 support = ptr->data;
1484 if (irccmp(support->name, name) == 0)
1485 {
1486 dlinkDelete(ptr, &support_list);
1487 MyFree(support->name);
1488 MyFree(support->options);
1489 MyFree(support);
1490 break;
1491 }
1492 }
1493
1494 rebuild_isupport_message_line();
1495 }
1496
1497 /*
1498 * rebuild_isupport_message_line
1499 *
1500 * input - NONE
1501 * output - NONE
1502 * side effects - Destroy the isupport MessageFile lines, and rebuild.
1503 */
1504 void
1505 rebuild_isupport_message_line(void)
1506 {
1507 char isupportbuffer[IRCD_BUFSIZE];
1508 char *p = isupportbuffer;
1509 dlink_node *ptr = NULL;
1510 int n = 0;
1511 int tokens = 0;
1512 size_t len = 0;
1513 size_t reserve = strlen(me.name) + HOSTLEN + strlen(form_str(RPL_ISUPPORT));
1514
1515 destroy_MessageLine(isupportFile);
1516
1517 DLINK_FOREACH(ptr, support_list.head)
1518 {
1519 struct Isupport *support = ptr->data;
1520
1521 p += (n = ircsprintf(p, "%s", support->name));
1522 len += n;
1523
1524 if (support->options != NULL)
1525 {
1526 p += (n = ircsprintf(p, "=%s", support->options));
1527 len += n;
1528 }
1529
1530 if (support->number > 0)
1531 {
1532 p += (n = ircsprintf(p, "=%d", support->number));
1533 len += n;
1534 }
1535
1536 *p++ = ' ';
1537 len++;
1538 *p = '\0';
1539
1540 if (++tokens == (MAXPARA-2) || len >= (sizeof(isupportbuffer)-reserve))
1541 { /* arbritrary for now */
1542 if (*--p == ' ')
1543 *p = '\0';
1544
1545 addto_MessageLine(isupportFile, isupportbuffer);
1546 p = isupportbuffer;
1547 len = 0;
1548 n = tokens = 0;
1549 }
1550 }
1551
1552 if (len != 0)
1553 {
1554 if (*--p == ' ')
1555 *p = '\0';
1556 addto_MessageLine(isupportFile, isupportbuffer);
1557 }
1558 }

Properties

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