ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/src/s_user.c
Revision: 948
Committed: Tue Jul 21 17:34:06 2009 UTC (14 years, 8 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/src/s_user.c
File size: 41443 byte(s)
Log Message:
- lp64\llp64\ilp32 portability fixes

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

Properties

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