ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/src/s_user.c
Revision: 1011
Committed: Fri Sep 18 10:14:09 2009 UTC (14 years, 6 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/src/s_user.c
File size: 41329 byte(s)
Log Message:
- move list manipulation routines from tools.c to list.c
- mem_frob() goes to memory.c
- sort out redundant/unneeded header includes

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

Properties

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