ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/user.c
Revision: 982
Committed: Thu Aug 13 22:15:08 2009 UTC (16 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/src/s_user.c
File size: 41303 byte(s)
Log Message:
- added a mersenne twister basedn prng

File Contents

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

Properties

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