/[svn]/ircd-hybrid-7.2/src/s_user.c
ViewVC logotype

Contents of /ircd-hybrid-7.2/src/s_user.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 582 - (show annotations)
Tue May 2 20:47:11 2006 UTC (14 years, 3 months ago) by michael
File MIME type: text/x-chdr
File size: 42965 byte(s)
- The 2nd and 3rd character of a SID may be a digit as well.
  Spotted by ThaPrince
- Fixed compile warnings in log_user_exit()

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 int check_regexp_xline(struct Client *);
71 static void introduce_client(struct Client *, struct Client *);
72 static void *uid_get(va_list);
73
74 /* Used for building up the isupport string,
75 * used with init_isupport, add_isupport, delete_isupport
76 */
77
78 struct Isupport
79 {
80 dlink_node node;
81 char *name;
82 char *options;
83 int number;
84 };
85
86 static dlink_list support_list = { NULL, NULL, 0 };
87 MessageFile *isupportFile;
88
89 /* memory is cheap. map 0-255 to equivalent mode */
90 unsigned int user_modes[256] =
91 {
92 /* 0x00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x0F */
93 /* 0x10 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x1F */
94 /* 0x20 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x2F */
95 /* 0x30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x3F */
96 0, /* @ */
97 0, /* A */
98 0, /* B */
99 0, /* C */
100 UMODE_DEAF, /* D */
101 0, /* E */
102 0, /* F */
103 UMODE_SOFTCALLERID, /* G */
104 0, /* H */
105 0, /* I */
106 0, /* J */
107 0, /* K */
108 0, /* L */
109 0, /* M */
110 0, /* N */
111 0, /* O */
112 0, /* P */
113 0, /* Q */
114 0, /* R */
115 0, /* S */
116 0, /* T */
117 0, /* U */
118 0, /* V */
119 0, /* W */
120 0, /* X */
121 0, /* Y */
122 0, /* Z 0x5A */
123 0, 0, 0, 0, 0, /* 0x5F */
124 0, /* 0x60 */
125 UMODE_ADMIN, /* a */
126 UMODE_BOTS, /* b */
127 UMODE_CCONN, /* c */
128 UMODE_DEBUG, /* d */
129 0, /* e */
130 UMODE_FULL, /* f */
131 UMODE_CALLERID, /* g */
132 0, /* h */
133 UMODE_INVISIBLE, /* i */
134 0, /* j */
135 UMODE_SKILL, /* k */
136 UMODE_LOCOPS, /* l */
137 0, /* m */
138 UMODE_NCHANGE, /* n */
139 UMODE_OPER, /* o */
140 0, /* p */
141 0, /* q */
142 UMODE_REJ, /* r */
143 UMODE_SERVNOTICE, /* s */
144 0, /* t */
145 UMODE_UNAUTH, /* u */
146 0, /* v */
147 UMODE_WALLOP, /* w */
148 UMODE_EXTERNAL, /* x */
149 UMODE_SPY, /* y */
150 UMODE_OPERWALL, /* z 0x7A */
151 0,0,0,0,0, /* 0x7B - 0x7F */
152
153 /* 0x80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x8F */
154 /* 0x90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x9F */
155 /* 0xA0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xAF */
156 /* 0xB0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xBF */
157 /* 0xC0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xCF */
158 /* 0xD0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xDF */
159 /* 0xE0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xEF */
160 /* 0xF0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* 0xFF */
161 };
162
163 void
164 assemble_umode_buffer(void)
165 {
166 unsigned int idx = 0;
167 char *umode_buffer_ptr = umode_buffer;
168
169 for (; idx < (sizeof(user_modes) / sizeof(int)); ++idx)
170 if (user_modes[idx])
171 *umode_buffer_ptr++ = idx;
172
173 *umode_buffer_ptr = '\0';
174 }
175
176 /* show_lusers()
177 *
178 * inputs - pointer to client
179 * output - NONE
180 * side effects - display to client user counts etc.
181 */
182 void
183 show_lusers(struct Client *source_p)
184 {
185 const char *from, *to;
186
187 if (!MyConnect(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
188 {
189 from = me.id;
190 to = source_p->id;
191 }
192 else
193 {
194 from = me.name;
195 to = source_p->name;
196 }
197
198 if (!ConfigServerHide.hide_servers || IsOper(source_p))
199 sendto_one(source_p, form_str(RPL_LUSERCLIENT),
200 from, to, (Count.total-Count.invisi),
201 Count.invisi, dlink_list_length(&global_serv_list));
202 else
203 sendto_one(source_p, form_str(RPL_LUSERCLIENT), from, to,
204 (Count.total-Count.invisi), Count.invisi, 1);
205
206 if (Count.oper > 0)
207 sendto_one(source_p, form_str(RPL_LUSEROP),
208 from, to, Count.oper);
209
210 if (dlink_list_length(&unknown_list) > 0)
211 sendto_one(source_p, form_str(RPL_LUSERUNKNOWN),
212 from, to, dlink_list_length(&unknown_list));
213
214 if (dlink_list_length(&global_channel_list) > 0)
215 sendto_one(source_p, form_str(RPL_LUSERCHANNELS),
216 from, to, dlink_list_length(&global_channel_list));
217
218 if (!ConfigServerHide.hide_servers || IsOper(source_p))
219 {
220 sendto_one(source_p, form_str(RPL_LUSERME),
221 from, to, Count.local, Count.myserver);
222 sendto_one(source_p, form_str(RPL_LOCALUSERS),
223 from, to, Count.local, Count.max_loc,
224 Count.local, Count.max_loc);
225 }
226 else
227 {
228 sendto_one(source_p, form_str(RPL_LUSERME),
229 from, to, Count.total, 0);
230 sendto_one(source_p, form_str(RPL_LOCALUSERS),
231 from, to, Count.total, Count.max_tot,
232 Count.total, Count.max_tot);
233 }
234
235 sendto_one(source_p, form_str(RPL_GLOBALUSERS),
236 from, to, Count.total, Count.max_tot,
237 Count.total, Count.max_tot);
238
239 if (!ConfigServerHide.hide_servers || IsOper(source_p))
240 sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
241 MaxConnectionCount, MaxClientCount, Count.totalrestartcount);
242
243 if (Count.local > MaxClientCount)
244 MaxClientCount = Count.local;
245
246 if ((Count.local + Count.myserver) > MaxConnectionCount)
247 MaxConnectionCount = Count.local + Count.myserver;
248 }
249
250 /* show_isupport()
251 *
252 * inputs - pointer to client
253 * output - NONE
254 * side effects - display to client what we support (for them)
255 */
256 void
257 show_isupport(struct Client *source_p)
258 {
259 send_message_file(source_p, isupportFile);
260 }
261
262 /*
263 ** register_local_user
264 ** This function is called when both NICK and USER messages
265 ** have been accepted for the client, in whatever order. Only
266 ** after this, is the USER message propagated.
267 **
268 ** NICK's must be propagated at once when received, although
269 ** it would be better to delay them too until full info is
270 ** available. Doing it is not so simple though, would have
271 ** to implement the following:
272 **
273 ** (actually it has been implemented already for a while) -orabidoo
274 **
275 ** 1) user telnets in and gives only "NICK foobar" and waits
276 ** 2) another user far away logs in normally with the nick
277 ** "foobar" (quite legal, as this server didn't propagate
278 ** it).
279 ** 3) now this server gets nick "foobar" from outside, but
280 ** has alread the same defined locally. Current server
281 ** would just issue "KILL foobar" to clean out dups. But,
282 ** this is not fair. It should actually request another
283 ** nick from local user or kill him/her...
284 */
285 void
286 register_local_user(struct Client *client_p, struct Client *source_p,
287 const char *nick, const char *username)
288 {
289 const struct AccessItem *aconf = NULL;
290 char ipaddr[HOSTIPLEN];
291 dlink_node *ptr = NULL;
292 dlink_node *m = NULL;
293
294 assert(source_p != NULL);
295 assert(MyConnect(source_p));
296 assert(source_p->username != username);
297 assert(!source_p->localClient->registration);
298
299 if (ConfigFileEntry.ping_cookie)
300 {
301 if (!IsPingSent(source_p) &&
302 source_p->localClient->random_ping == 0)
303 {
304 source_p->localClient->random_ping = (unsigned long)rand();
305 sendto_one(source_p, "PING :%lu",
306 source_p->localClient->random_ping);
307 SetPingSent(source_p);
308 return;
309 }
310
311 if (!HasPingCookie(source_p))
312 return;
313 }
314
315 source_p->localClient->last = CurrentTime;
316 /* Straight up the maximum rate of flooding... */
317 source_p->localClient->allow_read = MAX_FLOOD_BURST;
318
319 if (!execute_callback(client_check_cb, source_p, username))
320 return;
321
322 if (valid_hostname(source_p->host) == 0)
323 {
324 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- You have an illegal "
325 "character in your hostname", me.name, source_p->name);
326 strlcpy(source_p->host, source_p->sockhost,
327 sizeof(source_p->host));
328 }
329
330 ptr = source_p->localClient->confs.head;
331 aconf = map_to_conf(ptr->data);
332
333 if (!IsGotId(source_p))
334 {
335 const char *p = NULL;
336 unsigned int i = 0;
337
338 if (IsNeedIdentd(aconf))
339 {
340 ServerStats->is_ref++;
341 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- You need to install "
342 "identd to use this server", me.name, source_p->name);
343 exit_client(source_p, &me, "Install identd");
344 return;
345 }
346
347 p = username;
348
349 if (!IsNoTilde(aconf))
350 source_p->username[i++] = '~';
351
352 while (*p && i < USERLEN)
353 {
354 if (*p != '[')
355 source_p->username[i++] = *p;
356 p++;
357 }
358
359 source_p->username[i] = '\0';
360 }
361
362 /* password check */
363 if (!EmptyString(aconf->passwd))
364 {
365 const char *pass = source_p->localClient->passwd;
366
367 if (!match_conf_password(pass, aconf))
368 {
369 ServerStats->is_ref++;
370 sendto_one(source_p, form_str(ERR_PASSWDMISMATCH),
371 me.name, source_p->name);
372 exit_client(source_p, &me, "Bad Password");
373 return;
374 }
375 }
376
377 /* don't free source_p->localClient->passwd here - it can be required
378 * by masked /stats I if there are auth{} blocks with need_password = no;
379 * --adx
380 */
381
382 /* report if user has &^>= etc. and set flags as needed in source_p */
383 report_and_set_user_flags(source_p, aconf);
384
385 /* Limit clients -
386 * We want to be able to have servers and F-line clients
387 * connect, so save room for "buffer" connections.
388 * Smaller servers may want to decrease this, and it should
389 * probably be just a percentage of the MAXCLIENTS...
390 * -Taner
391 */
392 /* Except "F:" clients */
393 if ((Count.local >= ServerInfo.max_clients + MAX_BUFFER) ||
394 (Count.local >= ServerInfo.max_clients && !IsExemptLimits(source_p)))
395 {
396 sendto_realops_flags(UMODE_FULL, L_ALL,
397 "Too many clients, rejecting %s[%s].",
398 nick, source_p->host);
399 ServerStats->is_ref++;
400 exit_client(source_p, &me, "Sorry, server is full - try later");
401 return;
402 }
403
404 /* valid user name check */
405 if (valid_username(source_p->username) == 0)
406 {
407 char tmpstr2[IRCD_BUFSIZE];
408
409 sendto_realops_flags(UMODE_REJ, L_ALL, "Invalid username: %s (%s@%s)",
410 nick, source_p->username, source_p->host);
411 ServerStats->is_ref++;
412 ircsprintf(tmpstr2, "Invalid username [%s]", source_p->username);
413 exit_client(source_p, &me, tmpstr2);
414 return;
415 }
416
417 assert(source_p == client_p);
418
419 /* end of valid user name check */
420 if (check_xline(source_p) || check_regexp_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 *source_p;
863 int what;
864 unsigned int flag;
865
866 va_arg(args, struct Client *);
867 source_p = va_arg(args, struct Client *);
868 what = va_arg(args, int);
869 flag = va_arg(args, unsigned int);
870
871 if (what == MODE_ADD)
872 source_p->umodes |= flag;
873 else
874 source_p->umodes &= ~flag;
875
876 return NULL;
877 }
878
879 /* set_user_mode()
880 *
881 * added 15/10/91 By Darren Reed.
882 * parv[0] - sender
883 * parv[1] - username to change mode for
884 * parv[2] - modes to change
885 */
886 void
887 set_user_mode(struct Client *client_p, struct Client *source_p,
888 int parc, char *parv[])
889 {
890 unsigned int flag, setflags;
891 char **p, *m, buf[IRCD_BUFSIZE];
892 struct Client *target_p;
893 int what = MODE_ADD, badflag = 0, i;
894
895 assert(!(parc < 2));
896
897 if ((target_p = find_person(client_p, parv[1])) == NULL)
898 {
899 if (MyConnect(source_p))
900 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
901 me.name, source_p->name, parv[1]);
902 return;
903 }
904
905 if (IsServer(source_p))
906 {
907 sendto_realops_flags(UMODE_ALL, L_ADMIN, "*** Mode for User %s from %s",
908 parv[1], source_p->name);
909 return;
910 }
911
912 if (source_p != target_p || target_p->from != source_p->from)
913 {
914 sendto_one(source_p, form_str(ERR_USERSDONTMATCH),
915 me.name, source_p->name);
916 return;
917 }
918
919 if (parc < 3)
920 {
921 m = buf;
922 *m++ = '+';
923
924 for (i = 0; i < 128; i++)
925 if (source_p->umodes & user_modes[i])
926 *m++ = (char)i;
927 *m = '\0';
928
929 sendto_one(source_p, form_str(RPL_UMODEIS),
930 me.name, source_p->name, buf);
931 return;
932 }
933
934 execute_callback(entering_umode_cb, client_p, source_p);
935
936 /* find flags already set for user */
937 setflags = source_p->umodes;
938
939 /* parse mode change string(s) */
940 for (p = &parv[2]; p && *p; p++)
941 {
942 for (m = *p; *m; m++)
943 {
944 switch (*m)
945 {
946 case '+':
947 what = MODE_ADD;
948 break;
949 case '-':
950 what = MODE_DEL;
951 break;
952 case 'o':
953 if (what == MODE_ADD)
954 {
955 if (IsServer(client_p) && !IsOper(source_p))
956 {
957 ++Count.oper;
958 SetOper(source_p);
959 }
960 }
961 else
962 {
963 /* Only decrement the oper counts if an oper to begin with
964 * found by Pat Szuta, Perly , perly@xnet.com
965 */
966 if (!IsOper(source_p))
967 break;
968
969 ClearOper(source_p);
970 source_p->umodes &= ~ConfigFileEntry.oper_only_umodes;
971 Count.oper--;
972
973 if (MyConnect(source_p))
974 {
975 dlink_node *dm;
976
977 detach_conf(source_p, OPER_TYPE);
978 ClearOperFlags(source_p);
979
980 if ((dm = dlinkFindDelete(&oper_list, source_p)) != NULL)
981 free_dlink_node(dm);
982 }
983 }
984
985 break;
986
987 /* we may not get these,
988 * but they shouldnt be in default
989 */
990 case ' ' :
991 case '\n':
992 case '\r':
993 case '\t':
994 break;
995
996 default:
997 if ((flag = user_modes[(unsigned char)*m]))
998 {
999 if (MyConnect(source_p) && !IsOper(source_p) &&
1000 (ConfigFileEntry.oper_only_umodes & flag))
1001 {
1002 badflag = 1;
1003 }
1004 else
1005 execute_callback(umode_cb, client_p, source_p, what, flag);
1006 }
1007 else
1008 {
1009 if (MyConnect(source_p))
1010 badflag = 1;
1011 }
1012
1013 break;
1014 }
1015 }
1016 }
1017
1018 if (badflag)
1019 sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG),
1020 me.name, source_p->name);
1021
1022 if ((source_p->umodes & UMODE_NCHANGE) && !IsOperN(source_p))
1023 {
1024 sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;",
1025 me.name, source_p->name);
1026 source_p->umodes &= ~UMODE_NCHANGE; /* only tcm's really need this */
1027 }
1028
1029 if (MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) &&
1030 !IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p))
1031 {
1032 sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;",
1033 me.name, source_p->name);
1034 source_p->umodes &= ~UMODE_ADMIN;
1035 }
1036
1037 if (!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p))
1038 ++Count.invisi;
1039 if ((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p))
1040 --Count.invisi;
1041
1042 /*
1043 * compare new flags with old flags and send string which
1044 * will cause servers to update correctly.
1045 */
1046 send_umode_out(client_p, source_p, setflags);
1047 }
1048
1049 /* send_umode()
1050 * send the MODE string for user (user) to connection client_p
1051 * -avalon
1052 */
1053 void
1054 send_umode(struct Client *client_p, struct Client *source_p,
1055 unsigned int old, unsigned int sendmask, char *umode_buf)
1056 {
1057 int what = 0;
1058 unsigned int i;
1059 unsigned int flag;
1060 char *m = umode_buf;
1061
1062 /*
1063 * build a string in umode_buf to represent the change in the user's
1064 * mode between the new (source_p->umodes) and 'old'.
1065 */
1066 for (i = 0; i < 128; i++)
1067 {
1068 flag = user_modes[i];
1069 if (!flag)
1070 continue;
1071
1072 if (MyClient(source_p) && !(flag & sendmask))
1073 continue;
1074
1075 if ((flag & old) && !(source_p->umodes & flag))
1076 {
1077 if (what == MODE_DEL)
1078 *m++ = (char)i;
1079 else
1080 {
1081 what = MODE_DEL;
1082 *m++ = '-';
1083 *m++ = (char)i;
1084 }
1085 }
1086 else if (!(flag & old) && (source_p->umodes & flag))
1087 {
1088 if (what == MODE_ADD)
1089 *m++ = (char)i;
1090 else
1091 {
1092 what = MODE_ADD;
1093 *m++ = '+';
1094 *m++ = (char)i;
1095 }
1096 }
1097 }
1098
1099 *m = '\0';
1100
1101 if (*umode_buf && client_p)
1102 sendto_one(client_p, ":%s!%s@%s MODE %s :%s",
1103 source_p->name, source_p->username,
1104 source_p->host, source_p->name, umode_buf);
1105 }
1106
1107 /* send_umode_out()
1108 *
1109 * inputs -
1110 * output - NONE
1111 * side effects - Only send ubuf out to servers that know about this client
1112 */
1113 void
1114 send_umode_out(struct Client *client_p, struct Client *source_p,
1115 unsigned int old)
1116 {
1117 char buf[IRCD_BUFSIZE] = { '\0' };
1118 dlink_node *ptr = NULL;
1119
1120 send_umode(NULL, source_p, old, IsOperHiddenAdmin(source_p) ?
1121 SEND_UMODES & ~UMODE_ADMIN : SEND_UMODES, buf);
1122
1123 if (buf[0])
1124 {
1125 DLINK_FOREACH(ptr, serv_list.head)
1126 {
1127 struct Client *target_p = ptr->data;
1128
1129 if ((target_p != client_p) && (target_p != source_p))
1130 {
1131 if ((!(ServerInfo.hub && IsCapable(target_p, CAP_LL))) ||
1132 (target_p->localClient->serverMask &
1133 source_p->lazyLinkClientExists))
1134 sendto_one(target_p, ":%s MODE %s :%s",
1135 ID_or_name(source_p, target_p),
1136 ID_or_name(source_p, target_p), buf);
1137 }
1138 }
1139 }
1140
1141 if (client_p && MyClient(client_p))
1142 send_umode(client_p, source_p, old, 0xffffffff, buf);
1143 }
1144
1145 /* user_welcome()
1146 *
1147 * inputs - client pointer to client to welcome
1148 * output - NONE
1149 * side effects -
1150 */
1151 static void
1152 user_welcome(struct Client *source_p)
1153 {
1154 #if defined(__TIME__) && defined(__DATE__)
1155 static const char built_date[] = __DATE__ " at " __TIME__;
1156 #else
1157 static const char built_date[] = "unknown";
1158 #endif
1159
1160 #ifdef HAVE_LIBCRYPTO
1161 if (source_p->localClient->fd.ssl != NULL)
1162 sendto_one(source_p, ":%s NOTICE %s :*** Connected securely via %s",
1163 me.name, source_p->name,
1164 ssl_get_cipher(source_p->localClient->fd.ssl));
1165 #endif
1166
1167 sendto_one(source_p, form_str(RPL_WELCOME), me.name, source_p->name,
1168 ServerInfo.network_name, source_p->name);
1169 sendto_one(source_p, form_str(RPL_YOURHOST), me.name, source_p->name,
1170 get_listener_name(source_p->localClient->listener), ircd_version);
1171 sendto_one(source_p, form_str(RPL_CREATED),
1172 me.name, source_p->name, built_date);
1173 sendto_one(source_p, form_str(RPL_MYINFO),
1174 me.name, source_p->name, me.name, ircd_version, umode_buffer);
1175 show_isupport(source_p);
1176
1177 if (source_p->id[0] != '\0')
1178 sendto_one(source_p, form_str(RPL_YOURID), me.name,
1179 source_p->name, source_p->id);
1180
1181 show_lusers(source_p);
1182
1183 if (ConfigFileEntry.short_motd)
1184 {
1185 sendto_one(source_p, "NOTICE %s :*** Notice -- motd was last changed at %s",
1186 source_p->name, ConfigFileEntry.motd.lastChangedDate);
1187 sendto_one(source_p,
1188 "NOTICE %s :*** Notice -- Please read the motd if you haven't "
1189 "read it", source_p->name);
1190 sendto_one(source_p, form_str(RPL_MOTDSTART),
1191 me.name, source_p->name, me.name);
1192 sendto_one(source_p, form_str(RPL_MOTD),
1193 me.name, source_p->name,
1194 "*** This is the short motd ***");
1195 sendto_one(source_p, form_str(RPL_ENDOFMOTD),
1196 me.name, source_p->name);
1197 }
1198 else
1199 send_message_file(source_p, &ConfigFileEntry.motd);
1200 }
1201
1202 /* check_xline()
1203 *
1204 * inputs - pointer to client to test
1205 * outupt - 1 if exiting 0 if ok
1206 * side effects -
1207 */
1208 static int
1209 check_xline(struct Client *source_p)
1210 {
1211 struct ConfItem *conf;
1212 struct MatchItem *xconf;
1213 const char *reason;
1214
1215 if ((conf = find_matching_name_conf(XLINE_TYPE, source_p->info,
1216 NULL, NULL, 0)) != NULL)
1217 {
1218 xconf = map_to_conf(conf);
1219 xconf->count++;
1220
1221 if (xconf->reason != NULL)
1222 reason = xconf->reason;
1223 else
1224 reason = "No Reason";
1225
1226 sendto_realops_flags(UMODE_REJ, L_ALL,
1227 "X-line Rejecting [%s] [%s], user %s [%s]",
1228 source_p->info, reason,
1229 get_client_name(source_p, HIDE_IP),
1230 source_p->sockhost);
1231
1232 ServerStats->is_ref++;
1233 if (REJECT_HOLD_TIME > 0)
1234 {
1235 sendto_one(source_p, ":%s NOTICE %s :Bad user info",
1236 me.name, source_p->name);
1237 source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
1238 SetCaptured(source_p);
1239 }
1240 else
1241 exit_client(source_p, &me, "Bad user info");
1242 return 1;
1243 }
1244
1245 return 0;
1246 }
1247
1248 static int
1249 check_regexp_xline(struct Client *source_p)
1250 {
1251 struct ConfItem *conf = NULL;
1252 const char *reason = NULL;
1253
1254 if ((conf = find_matching_name_conf(RXLINE_TYPE, source_p->info, NULL, NULL, 0)))
1255 {
1256 struct MatchItem *reg = map_to_conf(conf);
1257
1258 ++reg->count;
1259
1260 if (reg->reason != NULL)
1261 reason = reg->reason;
1262 else
1263 reason = "No Reason";
1264
1265 sendto_realops_flags(UMODE_REJ, L_ALL,
1266 "X-line (REGEX) Rejecting [%s] [%s], user %s [%s]",
1267 source_p->info, reason,
1268 get_client_name(source_p, HIDE_IP),
1269 source_p->sockhost);
1270
1271 ServerStats->is_ref++;
1272 exit_client(source_p, &me, "Bad user info");
1273 return 1;
1274 }
1275
1276 return 0;
1277 }
1278
1279 /* oper_up()
1280 *
1281 * inputs - pointer to given client to oper
1282 * output - NONE
1283 * side effects - Blindly opers up given source_p, using aconf info
1284 * all checks on passwords have already been done.
1285 * This could also be used by rsa oper routines.
1286 */
1287 void
1288 oper_up(struct Client *source_p)
1289 {
1290 unsigned int old = source_p->umodes;
1291 const char *operprivs = "";
1292 const struct AccessItem *oconf = NULL;
1293
1294 assert(source_p->localClient->confs.head);
1295 oconf = map_to_conf((source_p->localClient->confs.head)->data);
1296
1297 ++Count.oper;
1298 SetOper(source_p);
1299
1300 if (oconf->modes)
1301 source_p->umodes |= oconf->modes;
1302 else if (ConfigFileEntry.oper_umodes)
1303 source_p->umodes |= ConfigFileEntry.oper_umodes;
1304 else
1305 source_p->umodes |= (UMODE_SERVNOTICE|UMODE_OPERWALL|
1306 UMODE_WALLOP|UMODE_LOCOPS);
1307
1308 assert(dlinkFind(&oper_list, source_p) == NULL);
1309 dlinkAdd(source_p, make_dlink_node(), &oper_list);
1310
1311 operprivs = oper_privs_as_string(oconf->port);
1312
1313 SetOFlag(source_p, oconf->port);
1314
1315 if (IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p))
1316 source_p->umodes |= UMODE_ADMIN;
1317 if (!IsOperN(source_p))
1318 source_p->umodes &= ~UMODE_NCHANGE;
1319
1320 sendto_realops_flags(UMODE_ALL, L_ALL, "%s (%s@%s) is now an operator",
1321 source_p->name, source_p->username, source_p->host);
1322 send_umode_out(source_p, source_p, old);
1323 sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
1324 sendto_one(source_p, ":%s NOTICE %s :*** Oper privs are %s",
1325 me.name, source_p->name, operprivs);
1326 send_message_file(source_p, &ConfigFileEntry.opermotd);
1327 }
1328
1329 static char new_uid[TOTALSIDUID + 1]; /* allow for \0 */
1330
1331 int
1332 valid_sid(const char *sid)
1333 {
1334
1335 if (strlen(sid) == IRC_MAXSID)
1336 if (IsDigit(*sid))
1337 if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
1338 return 1;
1339
1340 return 0;
1341 }
1342
1343 /*
1344 * init_uid()
1345 *
1346 * inputs - NONE
1347 * output - NONE
1348 * side effects - new_uid is filled in with server id portion (sid)
1349 * (first 3 bytes) or defaulted to 'A'.
1350 * Rest is filled in with 'A'
1351 */
1352 void
1353 init_uid(void)
1354 {
1355 int i;
1356
1357 memset(new_uid, 0, sizeof(new_uid));
1358
1359 if (ServerInfo.sid != NULL)
1360 {
1361 strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid));
1362 strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
1363
1364 hash_add_id(&me);
1365 }
1366
1367 for (i = 0; i < IRC_MAXSID; i++)
1368 if (new_uid[i] == '\0')
1369 new_uid[i] = 'A';
1370
1371 /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1372 /* Yes nenolod, I have known it was off by one ever since I wrote it
1373 * But *JUST* for you, though, it really doesn't look as *pretty*
1374 * -Dianora
1375 */
1376 memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1377
1378 entering_umode_cb = register_callback("entering_umode", NULL);
1379 umode_cb = register_callback("changing_umode", change_simple_umode);
1380 uid_get_cb = register_callback("uid_get", uid_get);
1381 }
1382
1383 /*
1384 * add_one_to_uid
1385 *
1386 * inputs - index number into new_uid
1387 * output - NONE
1388 * side effects - new_uid is incremented by one
1389 * note this is a recursive function
1390 */
1391 static void
1392 add_one_to_uid(int i)
1393 {
1394 if (i != IRC_MAXSID) /* Not reached server SID portion yet? */
1395 {
1396 if (new_uid[i] == 'Z')
1397 new_uid[i] = '0';
1398 else if (new_uid[i] == '9')
1399 {
1400 new_uid[i] = 'A';
1401 add_one_to_uid(i-1);
1402 }
1403 else
1404 ++new_uid[i];
1405 }
1406 else
1407 {
1408 /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1409 if (new_uid[i] == 'Z')
1410 memcpy(new_uid + IRC_MAXSID, "AAAAAA", IRC_MAXUID);
1411 else
1412 ++new_uid[i];
1413 }
1414 }
1415
1416 /*
1417 * uid_get
1418 *
1419 * inputs - struct Client *
1420 * output - new UID is returned to caller
1421 * side effects - new_uid is incremented by one.
1422 */
1423 static void *
1424 uid_get(va_list args)
1425 {
1426 add_one_to_uid(TOTALSIDUID - 1); /* index from 0 */
1427 return new_uid;
1428 }
1429
1430 /*
1431 * init_isupport()
1432 *
1433 * input - NONE
1434 * output - NONE
1435 * side effects - Must be called before isupport is enabled
1436 */
1437 void
1438 init_isupport(void)
1439 {
1440 isupportFile = init_MessageLine();
1441
1442 add_isupport("CALLERID", NULL, -1);
1443 add_isupport("CASEMAPPING", CASEMAP, -1);
1444 add_isupport("KICKLEN", NULL, KICKLEN);
1445 add_isupport("MODES", NULL, MAXMODEPARAMS);
1446 add_isupport("NICKLEN", NULL, NICKLEN-1);
1447 #ifdef HALFOPS
1448 add_isupport("PREFIX", "(ohv)@%+", -1);
1449 add_isupport("STATUSMSG", "@%+", -1);
1450 #else
1451 add_isupport("PREFIX", "(ov)@+", -1);
1452 add_isupport("STATUSMSG", "@+", -1);
1453 #endif
1454 add_isupport("TOPICLEN", NULL, TOPICLEN);
1455 }
1456
1457 /*
1458 * add_isupport()
1459 *
1460 * input - name of supported function
1461 * - options if any
1462 * - number if any
1463 * output - NONE
1464 * side effects - Each supported item must call this when activated
1465 */
1466 void
1467 add_isupport(const char *name, const char *options, int n)
1468 {
1469 dlink_node *ptr;
1470 struct Isupport *support;
1471
1472 DLINK_FOREACH(ptr, support_list.head)
1473 {
1474 support = ptr->data;
1475 if (irccmp(support->name, name) == 0)
1476 {
1477 MyFree(support->name);
1478 MyFree(support->options);
1479 break;
1480 }
1481 }
1482
1483 if (ptr == NULL)
1484 {
1485 support = MyMalloc(sizeof(*support));
1486 dlinkAddTail(support, &support->node, &support_list);
1487 }
1488
1489 DupString(support->name, name);
1490 if (options != NULL)
1491 DupString(support->options, options);
1492 support->number = n;
1493
1494 rebuild_isupport_message_line();
1495 }
1496
1497 /*
1498 * delete_isupport()
1499 *
1500 * input - name of supported function
1501 * output - NONE
1502 * side effects - Each supported item must call this when deactivated
1503 */
1504 void
1505 delete_isupport(const char *name)
1506 {
1507 dlink_node *ptr;
1508 struct Isupport *support;
1509
1510 DLINK_FOREACH(ptr, support_list.head)
1511 {
1512 support = ptr->data;
1513 if (irccmp(support->name, name) == 0)
1514 {
1515 dlinkDelete(ptr, &support_list);
1516 MyFree(support->name);
1517 MyFree(support->options);
1518 MyFree(support);
1519 break;
1520 }
1521 }
1522
1523 rebuild_isupport_message_line();
1524 }
1525
1526 /*
1527 * rebuild_isupport_message_line
1528 *
1529 * input - NONE
1530 * output - NONE
1531 * side effects - Destroy the isupport MessageFile lines, and rebuild.
1532 */
1533 void
1534 rebuild_isupport_message_line(void)
1535 {
1536 char isupportbuffer[IRCD_BUFSIZE];
1537 char *p = isupportbuffer;
1538 dlink_node *ptr = NULL;
1539 int n = 0;
1540 int tokens = 0;
1541 size_t len = 0;
1542 size_t reserve = strlen(me.name) + HOSTLEN + strlen(form_str(RPL_ISUPPORT));
1543
1544 destroy_MessageLine(isupportFile);
1545
1546 DLINK_FOREACH(ptr, support_list.head)
1547 {
1548 struct Isupport *support = ptr->data;
1549
1550 p += (n = ircsprintf(p, "%s", support->name));
1551 len += n;
1552
1553 if (support->options != NULL)
1554 {
1555 p += (n = ircsprintf(p, "=%s", support->options));
1556 len += n;
1557 }
1558
1559 if (support->number > 0)
1560 {
1561 p += (n = ircsprintf(p, "=%d", support->number));
1562 len += n;
1563 }
1564
1565 *p++ = ' ';
1566 len++;
1567 *p = '\0';
1568
1569 if (++tokens == (MAXPARA-2) || len >= (sizeof(isupportbuffer)-reserve))
1570 { /* arbritrary for now */
1571 if (*--p == ' ')
1572 *p = '\0';
1573
1574 addto_MessageLine(isupportFile, isupportbuffer);
1575 p = isupportbuffer;
1576 len = 0;
1577 n = tokens = 0;
1578 }
1579 }
1580
1581 if (len != 0)
1582 {
1583 if (*--p == ' ')
1584 *p = '\0';
1585 addto_MessageLine(isupportFile, isupportbuffer);
1586 }
1587 }

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28