/[svn]/branches/newio/src/s_user.c
ViewVC logotype

Contents of /branches/newio/src/s_user.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2692 - (show annotations)
Tue Dec 17 18:56:15 2013 UTC (8 years, 11 months ago) by michael
File MIME type: text/x-chdr
File size: 41797 byte(s)
- Avoid magically sized temporary buffers

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

Properties

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

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