ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/user.c
Revision: 849
Committed: Mon Feb 19 19:41:59 2007 UTC (18 years, 6 months ago) by db
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/src/s_user.c
File size: 43172 byte(s)
Log Message:
- Add +C 
- add etrace -full

Reviewed by: cryogen, bear

File Contents

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

Properties

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