ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/user.c
Revision: 3272
Committed: Sun Apr 6 11:34:14 2014 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/s_user.c
File size: 38356 byte(s)
Log Message:
- s_user.c: reformating

File Contents

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

Properties

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