ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/s_user.c
Revision: 139
Committed: Sun Oct 16 06:01:13 2005 UTC (20 years, 9 months ago) by db
Content type: text/x-csrc
File size: 42590 byte(s)
Log Message:
- get rid of map_conf_item and unmap_conf_item
- Use an union in struct ConfItem, but only allocate memory needed


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

Properties

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