ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/user.c
Revision: 1080
Committed: Wed Mar 10 23:09:36 2010 UTC (15 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.3/src/s_user.c
File size: 40690 byte(s)
Log Message:
- Sort out unneeded arguments of some user registration functions

File Contents

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

Properties

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