2 * ircd-ratbox: A slightly useful ircd.
3 * s_user.c: User related functions.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 #include "irc_string.h"
34 #include "sprintf_irc.h"
41 #include "s_newconf.h"
47 #include "supported.h"
56 #include "blacklist.h"
58 static void report_and_set_user_flags(struct Client
*, struct ConfItem
*);
59 void user_welcome(struct Client
*source_p
);
65 int user_modes
[256] = {
66 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
67 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
68 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
69 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
87 UMODE_NOFORWARD
, /* Q */
88 UMODE_REGONLYMSG
, /* R */
89 UMODE_SERVICE
, /* S */
97 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
104 UMODE_CALLERID
, /* g */
106 UMODE_INVISIBLE
, /* i */
113 UMODE_OVERRIDE
, /* p */
116 UMODE_SERVNOTICE
, /* s */
120 UMODE_WALLOP
, /* w */
123 UMODE_OPERWALL
, /* z */
124 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
125 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
126 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
127 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
128 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
129 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
130 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
131 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
132 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
139 * inputs - pointer to client
141 * side effects - display to client user counts etc.
144 show_lusers(struct Client
*source_p
)
146 sendto_one_numeric(source_p
, RPL_LUSERCLIENT
, form_str(RPL_LUSERCLIENT
),
147 (Count
.total
- Count
.invisi
),
148 Count
.invisi
, dlink_list_length(&global_serv_list
));
150 if(dlink_list_length(&oper_list
) > 0)
151 sendto_one_numeric(source_p
, RPL_LUSEROP
,
152 form_str(RPL_LUSEROP
), dlink_list_length(&oper_list
));
154 if(dlink_list_length(&unknown_list
) > 0)
155 sendto_one_numeric(source_p
, RPL_LUSERUNKNOWN
,
156 form_str(RPL_LUSERUNKNOWN
),
157 dlink_list_length(&unknown_list
));
159 if(dlink_list_length(&global_channel_list
) > 0)
160 sendto_one_numeric(source_p
, RPL_LUSERCHANNELS
,
161 form_str(RPL_LUSERCHANNELS
),
162 dlink_list_length(&global_channel_list
));
164 sendto_one_numeric(source_p
, RPL_LUSERME
, form_str(RPL_LUSERME
),
165 dlink_list_length(&lclient_list
),
166 dlink_list_length(&serv_list
));
168 sendto_one_numeric(source_p
, RPL_LOCALUSERS
,
169 form_str(RPL_LOCALUSERS
),
170 dlink_list_length(&lclient_list
),
172 dlink_list_length(&lclient_list
),
175 sendto_one_numeric(source_p
, RPL_GLOBALUSERS
, form_str(RPL_GLOBALUSERS
),
176 Count
.total
, Count
.max_tot
,
177 Count
.total
, Count
.max_tot
);
179 sendto_one_numeric(source_p
, RPL_STATSCONN
,
180 form_str(RPL_STATSCONN
),
181 MaxConnectionCount
, MaxClientCount
,
182 Count
.totalrestartcount
);
184 if(dlink_list_length(&lclient_list
) > (unsigned long)MaxClientCount
)
185 MaxClientCount
= dlink_list_length(&lclient_list
);
187 if((dlink_list_length(&lclient_list
) + dlink_list_length(&serv_list
)) >
188 (unsigned long)MaxConnectionCount
)
189 MaxConnectionCount
= dlink_list_length(&lclient_list
) +
190 dlink_list_length(&serv_list
);
196 ** register_local_user
197 ** This function is called when both NICK and USER messages
198 ** have been accepted for the client, in whatever order. Only
199 ** after this, is the USER message propagated.
201 ** NICK's must be propagated at once when received, although
202 ** it would be better to delay them too until full info is
203 ** available. Doing it is not so simple though, would have
204 ** to implement the following:
206 ** (actually it has been implemented already for a while) -orabidoo
208 ** 1) user telnets in and gives only "NICK foobar" and waits
209 ** 2) another user far away logs in normally with the nick
210 ** "foobar" (quite legal, as this server didn't propagate
212 ** 3) now this server gets nick "foobar" from outside, but
213 ** has alread the same defined locally. Current server
214 ** would just issue "KILL foobar" to clean out dups. But,
215 ** this is not fair. It should actually request another
216 ** nick from local user or kill him/her...
220 register_local_user(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
222 struct ConfItem
*aconf
;
223 struct User
*user
= source_p
->user
;
224 char tmpstr2
[IRCD_BUFSIZE
];
225 char ipaddr
[HOSTIPLEN
];
226 char myusername
[USERLEN
+1];
229 s_assert(NULL
!= source_p
);
230 s_assert(MyConnect(source_p
));
231 s_assert(source_p
->username
!= username
);
236 if(IsAnyDead(source_p
))
239 if(ConfigFileEntry
.ping_cookie
)
241 if(!(source_p
->flags
& FLAGS_PINGSENT
) && source_p
->localClient
->random_ping
== 0)
243 source_p
->localClient
->random_ping
= (unsigned long) (rand() * rand()) << 1;
244 sendto_one(source_p
, "PING :%08lX",
245 (unsigned long) source_p
->localClient
->random_ping
);
246 source_p
->flags
|= FLAGS_PINGSENT
;
249 if(!(source_p
->flags2
& FLAGS2_PING_COOKIE
))
255 /* hasnt finished client cap negotiation */
256 if(source_p
->flags2
& FLAGS2_CLICAP
)
259 /* still has DNSbls to validate against */
260 if(dlink_list_length(&source_p
->preClient
->dnsbl_queries
) > 0)
263 client_p
->localClient
->last
= CurrentTime
;
264 /* Straight up the maximum rate of flooding... */
265 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
267 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
268 if(!IsGotId(source_p
) && (strchr(username
, '[') != NULL
))
275 while(*p
&& i
< USERLEN
)
278 myusername
[i
++] = *p
;
282 myusername
[i
] = '\0';
283 username
= myusername
;
286 if((status
= check_client(client_p
, source_p
, username
)) < 0)
287 return (CLIENT_EXITED
);
289 /* Apply nick override */
290 if(*source_p
->preClient
->spoofnick
)
292 del_from_client_hash(source_p
->name
, source_p
);
293 strlcpy(source_p
->name
, source_p
->preClient
->spoofnick
, NICKLEN
+ 1);
294 add_to_client_hash(source_p
->name
, source_p
);
295 comm_note(source_p
->localClient
->fd
, "Nick: %s", source_p
->name
);
298 if(!valid_hostname(source_p
->host
))
301 ":%s NOTICE %s :*** Notice -- You have an illegal character in your hostname",
302 me
.name
, source_p
->name
);
304 strlcpy(source_p
->host
, source_p
->sockhost
, sizeof(source_p
->host
));
307 if(ConfigFileEntry
.dot_in_ip6_addr
== 1)
308 strlcat(source_p
->host
, ".", sizeof(source_p
->host
));
313 aconf
= source_p
->localClient
->att_conf
;
317 exit_client(client_p
, source_p
, &me
, "*** Not Authorised");
318 return (CLIENT_EXITED
);
321 if(!IsGotId(source_p
))
326 if(IsNeedIdentd(aconf
))
328 ServerStats
->is_ref
++;
330 ":%s NOTICE %s :*** Notice -- You need to install identd to use this server",
331 me
.name
, client_p
->name
);
332 exit_client(client_p
, source_p
, &me
, "Install identd");
333 return (CLIENT_EXITED
);
336 /* dont replace username if its supposed to be spoofed --fl */
337 if(!IsConfDoSpoofIp(aconf
) || !strchr(aconf
->name
, '@'))
341 if(!IsNoTilde(aconf
))
342 source_p
->username
[i
++] = '~';
344 while (*p
&& i
< USERLEN
)
347 source_p
->username
[i
++] = *p
;
351 source_p
->username
[i
] = '\0';
355 if(IsNeedSasl(aconf
) && !*user
->suser
)
357 ServerStats
->is_ref
++;
359 ":%s NOTICE %s :*** Notice -- You need to identify via SASL to use this server",
360 me
.name
, client_p
->name
);
361 exit_client(client_p
, source_p
, &me
, "SASL access only");
362 return (CLIENT_EXITED
);
366 if(!EmptyString(aconf
->passwd
))
370 if(EmptyString(source_p
->localClient
->passwd
))
372 else if(IsConfEncrypted(aconf
))
373 encr
= crypt(source_p
->localClient
->passwd
, aconf
->passwd
);
375 encr
= source_p
->localClient
->passwd
;
377 if(strcmp(encr
, aconf
->passwd
))
379 ServerStats
->is_ref
++;
380 sendto_one(source_p
, form_str(ERR_PASSWDMISMATCH
), me
.name
, source_p
->name
);
381 exit_client(client_p
, source_p
, &me
, "Bad Password");
382 return (CLIENT_EXITED
);
385 /* clear password only if used now, otherwise send it
386 * to services -- jilles */
387 if(source_p
->localClient
->passwd
)
389 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
390 MyFree(source_p
->localClient
->passwd
);
391 source_p
->localClient
->passwd
= NULL
;
395 /* report if user has &^>= etc. and set flags as needed in source_p */
396 report_and_set_user_flags(source_p
, aconf
);
400 * We want to be able to have servers and F-line clients
401 * connect, so save room for "buffer" connections.
402 * Smaller servers may want to decrease this, and it should
403 * probably be just a percentage of the MAXCLIENTS...
406 /* Except "F:" clients */
407 if(((dlink_list_length(&lclient_list
) + 1) >=
408 ((unsigned long)GlobalSetOptions
.maxclients
+ MAX_BUFFER
) ||
409 (dlink_list_length(&lclient_list
) + 1) >=
410 ((unsigned long)GlobalSetOptions
.maxclients
- 5)) && !(IsExemptLimits(source_p
)))
412 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
413 "Too many clients, rejecting %s[%s].", source_p
->name
, source_p
->host
);
415 ServerStats
->is_ref
++;
416 exit_client(client_p
, source_p
, &me
, "Sorry, server is full - try later");
417 return (CLIENT_EXITED
);
420 /* valid user name check */
422 if(!valid_username(source_p
->username
))
424 sendto_realops_snomask(SNO_REJ
, L_NETWIDE
,
425 "Invalid username: %s (%s@%s)",
426 source_p
->name
, source_p
->username
, source_p
->host
);
427 ServerStats
->is_ref
++;
428 ircsprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
429 exit_client(client_p
, source_p
, &me
, tmpstr2
);
430 return (CLIENT_EXITED
);
433 /* end of valid user name check */
435 /* kline exemption extends to xline too */
436 if(!IsExemptKline(source_p
) &&
437 find_xline(source_p
->info
, 1) != NULL
)
439 ServerStats
->is_ref
++;
440 add_reject(source_p
);
441 exit_client(client_p
, source_p
, &me
, "Bad user info");
442 return CLIENT_EXITED
;
446 if (source_p
->preClient
->dnsbl_listed
!= NULL
)
448 if (IsExemptKline(source_p
) || IsConfExemptDNSBL(aconf
))
449 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s, but you are exempt",
450 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
453 ServerStats
->is_ref
++;
454 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
455 me
.name
, source_p
->name
,
456 source_p
->preClient
->dnsbl_listed
->reject_reason
);
457 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s",
458 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
459 source_p
->preClient
->dnsbl_listed
->hits
++;
460 add_reject(source_p
);
461 exit_client(client_p
, source_p
, &me
, "*** Banned (DNS blacklist)");
462 return CLIENT_EXITED
;
466 /* Store original hostname -- jilles */
467 strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
469 /* Spoof user@host */
470 if(*source_p
->preClient
->spoofuser
)
471 strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
472 if(*source_p
->preClient
->spoofhost
)
474 strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
475 if (irccmp(source_p
->host
, source_p
->orighost
))
476 SetDynSpoof(source_p
);
479 if(IsAnyDead(client_p
))
480 return CLIENT_EXITED
;
482 inetntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
484 sendto_realops_snomask(SNO_CCONN
, L_NETWIDE
,
485 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
486 source_p
->name
, source_p
->username
, source_p
->orighost
,
487 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
488 get_client_class(source_p
), source_p
->info
);
490 sendto_realops_snomask(SNO_CCONNEXT
, L_NETWIDE
,
491 "CLICONN %s %s %s %s %s %s 0 %s",
492 source_p
->name
, source_p
->username
, source_p
->orighost
,
493 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
494 get_client_class(source_p
),
495 /* mirc can sometimes send ips here */
496 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
499 /* If they have died in send_* don't do anything. */
500 if(IsAnyDead(source_p
))
501 return CLIENT_EXITED
;
503 add_to_hostname_hash(source_p
->orighost
, source_p
);
505 /* Allocate a UID if it was not previously allocated.
506 * If this already occured, it was probably during SASL auth...
510 strcpy(source_p
->id
, generate_uid());
511 add_to_id_hash(source_p
->id
, source_p
);
514 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
;
516 if (source_p
->umodes
& UMODE_INVISIBLE
)
519 s_assert(!IsClient(source_p
));
520 dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
523 /* XXX source_p->servptr is &me, since local client */
524 source_p
->servptr
= find_server(NULL
, user
->server
);
525 dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
526 /* Increment our total user count here */
527 if(++Count
.total
> Count
.max_tot
)
528 Count
.max_tot
= Count
.total
;
529 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
531 Count
.totalrestartcount
++;
533 s_assert(source_p
->localClient
!= NULL
);
535 if(dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
537 Count
.max_loc
= dlink_list_length(&lclient_list
);
538 if(!(Count
.max_loc
% 10))
539 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
540 "New Max Local Clients: %d", Count
.max_loc
);
543 /* they get a reduced limit */
544 if(find_tgchange(source_p
->sockhost
))
545 USED_TARGETS(source_p
) = 6;
547 call_hook(h_new_local_user
, source_p
);
549 monitor_signon(source_p
);
550 user_welcome(source_p
);
552 free_pre_client(source_p
);
554 return (introduce_client(client_p
, source_p
, user
, source_p
->name
, 1));
562 * side effects - This common function introduces a client to the rest
563 * of the net, either from a local client connect or
564 * from a remote connect.
567 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
569 static char ubuf
[12];
570 struct Client
*identifyservice_p
;
572 hook_data_umode_changed hdata
;
573 hook_data_client hdata2
;
575 if(MyClient(source_p
))
576 send_umode(source_p
, source_p
, 0, 0, ubuf
);
578 send_umode(NULL
, source_p
, 0, 0, ubuf
);
586 /* if it has an ID, introduce it with its id to TS6 servers,
587 * otherwise introduce it normally to all.
591 char sockhost
[HOSTLEN
];
592 if(source_p
->sockhost
[0] == ':')
596 strlcat(sockhost
, source_p
->sockhost
, sizeof(sockhost
));
598 strcpy(sockhost
, source_p
->sockhost
);
601 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
602 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
603 source_p
->servptr
->id
, nick
,
604 source_p
->hopcount
+ 1,
605 (long) source_p
->tsinfo
, ubuf
,
606 source_p
->username
, source_p
->host
,
607 IsIPSpoof(source_p
) ? "0" : sockhost
,
609 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
610 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
613 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
614 ":%s UID %s %d %ld %s %s %s %s %s :%s",
615 source_p
->servptr
->id
, nick
,
616 source_p
->hopcount
+ 1,
617 (long) source_p
->tsinfo
, ubuf
,
618 source_p
->username
, source_p
->host
,
619 IsIPSpoof(source_p
) ? "0" : sockhost
,
620 source_p
->id
, source_p
->info
);
622 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
,
623 "NICK %s %d %ld %s %s %s %s :%s",
624 nick
, source_p
->hopcount
+ 1,
625 (long) source_p
->tsinfo
,
626 ubuf
, source_p
->username
, source_p
->host
,
627 user
->server
, source_p
->info
);
630 sendto_server(client_p
, NULL
, NOCAPS
, NOCAPS
,
631 "NICK %s %d %ld %s %s %s %s :%s",
632 nick
, source_p
->hopcount
+ 1,
633 (long) source_p
->tsinfo
,
634 ubuf
, source_p
->username
, source_p
->host
,
635 user
->server
, source_p
->info
);
637 if (IsDynSpoof(source_p
))
639 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
640 use_id(source_p
), source_p
->orighost
);
641 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s ENCAP * REALHOST %s",
642 source_p
->name
, source_p
->orighost
);
644 if (!EmptyString(source_p
->user
->suser
))
646 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
647 use_id(source_p
), source_p
->user
->suser
);
648 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s ENCAP * LOGIN %s",
649 source_p
->name
, source_p
->user
->suser
);
652 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
654 if (ConfigFileEntry
.identifyservice
[0] != '\0' &&
655 ConfigFileEntry
.identifycommand
[0] != '\0')
657 /* use user@server */
658 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
660 identifyservice_p
= find_named_client(p
+ 1);
662 identifyservice_p
= NULL
;
663 if (identifyservice_p
!= NULL
)
664 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
665 get_id(source_p
, identifyservice_p
),
666 ConfigFileEntry
.identifyservice
,
667 ConfigFileEntry
.identifycommand
,
668 source_p
->localClient
->passwd
);
670 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
671 MyFree(source_p
->localClient
->passwd
);
672 source_p
->localClient
->passwd
= NULL
;
675 /* let modules providing usermodes know that we've got a new user,
676 * why is this here? -- well, some modules need to be able to send out new
677 * information about a client, so this was the best place to do it
680 hdata
.client
= source_p
;
682 hdata
.oldsnomask
= 0;
683 call_hook(h_umode_changed
, &hdata
);
685 /* On the other hand, some modules need to know when a client is
686 * being introduced, period.
689 hdata2
.client
= client_p
;
690 hdata2
.target
= source_p
;
691 call_hook(h_introduce_client
, &hdata2
);
697 * valid_hostname - check hostname for validity
699 * Inputs - pointer to user
700 * Output - YES if valid, NO if not
701 * Side effects - NONE
703 * NOTE: this doesn't allow a hostname to begin with a dot and
704 * will not allow more dots than chars.
707 valid_hostname(const char *hostname
)
709 const char *p
= hostname
;
717 if('.' == *p
|| ':' == *p
|| '/' == *p
)
724 if(*p
== '.' || *p
== ':' || *p
== '/')
736 * valid_username - check username for validity
738 * Inputs - pointer to user
739 * Output - YES if valid, NO if not
740 * Side effects - NONE
742 * Absolutely always reject any '*' '!' '?' '@' in an user name
743 * reject any odd control characters names.
744 * Allow '.' in username to allow for "first.last"
748 valid_username(const char *username
)
751 const char *p
= username
;
761 /* reject usernames that don't start with an alphanum
762 * i.e. reject jokers who have '-@somehost' or '.@somehost'
763 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
770 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
773 if(dots
> ConfigFileEntry
.dots_in_ident
)
775 if(!IsUserChar(p
[1]))
778 else if(!IsUserChar(*p
))
784 /* report_and_set_user_flags
786 * Inputs - pointer to source_p
787 * - pointer to aconf for this user
790 * Report to user any special flags they are getting, and set them.
794 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
796 /* If this user is being spoofed, tell them so */
797 if(IsConfDoSpoofIp(aconf
))
800 ":%s NOTICE %s :*** Spoofing your IP. congrats.",
801 me
.name
, source_p
->name
);
804 /* If this user is in the exception class, Set it "E lined" */
805 if(IsConfExemptKline(aconf
))
807 SetExemptKline(source_p
);
809 ":%s NOTICE %s :*** You are exempt from K/D/X lines. congrats.",
810 me
.name
, source_p
->name
);
813 if(IsConfExemptDNSBL(aconf
))
814 /* kline exempt implies this, don't send both */
815 if(!IsConfExemptKline(aconf
))
817 ":%s NOTICE %s :*** You are exempt from DNS blacklists.",
818 me
.name
, source_p
->name
);
820 /* If this user is exempt from user limits set it F lined" */
821 if(IsConfExemptLimits(aconf
))
823 SetExemptLimits(source_p
);
825 ":%s NOTICE %s :*** You are exempt from user limits. congrats.",
826 me
.name
, source_p
->name
);
829 /* If this user is exempt from idle time outs */
830 if(IsConfIdlelined(aconf
))
832 SetIdlelined(source_p
);
834 ":%s NOTICE %s :*** You are exempt from idle limits. congrats.",
835 me
.name
, source_p
->name
);
838 if(IsConfExemptFlood(aconf
))
840 SetExemptFlood(source_p
);
842 ":%s NOTICE %s :*** You are exempt from flood limits.",
843 me
.name
, source_p
->name
);
846 if(IsConfExemptSpambot(aconf
))
848 SetExemptSpambot(source_p
);
850 ":%s NOTICE %s :*** You are exempt from spambot checks.",
851 me
.name
, source_p
->name
);
854 if(IsConfExemptJupe(aconf
))
856 SetExemptJupe(source_p
);
858 ":%s NOTICE %s :*** You are exempt from juped channel warnings.",
859 me
.name
, source_p
->name
);
862 if(IsConfExemptResv(aconf
))
864 SetExemptResv(source_p
);
866 ":%s NOTICE %s :*** You are exempt from resvs.",
867 me
.name
, source_p
->name
);
870 if(IsConfExemptShide(aconf
))
872 SetExemptShide(source_p
);
874 ":%s NOTICE %s :*** You are exempt from serverhiding.",
875 me
.name
, source_p
->name
);
880 * user_mode - set get current users mode
882 * m_umode() added 15/10/91 By Darren Reed.
884 * parv[1] - username to change mode for
885 * parv[2] - modes to change
888 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
894 struct Client
*target_p
;
896 int badflag
= NO
; /* Only send one bad flag notice */
897 int showsnomask
= NO
;
898 unsigned int setsnomask
;
900 hook_data_umode_changed hdata
;
906 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
910 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
912 if(MyConnect(source_p
))
913 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
914 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
918 /* Dont know why these were commented out..
919 * put them back using new sendto() funcs
922 if(IsServer(source_p
))
924 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
925 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
929 if(source_p
!= target_p
|| target_p
->from
!= source_p
->from
)
931 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
940 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
941 if (source_p
->umodes
& user_modes
[i
])
945 sendto_one(source_p
, form_str(RPL_UMODEIS
), me
.name
, source_p
->name
, buf
);
946 if (source_p
->snomask
!= 0)
947 sendto_one(source_p
, form_str(RPL_SNOMASK
), me
.name
, source_p
->name
,
948 construct_snobuf(source_p
->snomask
));
952 /* find flags already set for user */
953 setflags
= source_p
->umodes
;
954 setsnomask
= source_p
->snomask
;
957 * parse mode change string(s)
959 for (pm
= parv
[2]; *pm
; pm
++)
972 if(IsServer(client_p
) && !IsOper(source_p
))
976 dlinkAddAlloc(source_p
, &oper_list
);
981 /* Only decrement the oper counts if an oper to begin with
982 * found by Pat Szuta, Perly , perly@xnet.com
985 if(!IsOper(source_p
))
992 if(MyConnect(source_p
))
994 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
995 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
997 source_p
->snomask
= 0;
1000 source_p
->operflags
= 0;
1002 MyFree(source_p
->localClient
->opername
);
1003 source_p
->localClient
->opername
= NULL
;
1005 dlinkFindDestroy(source_p
, &local_oper_list
);
1008 dlinkFindDestroy(source_p
, &oper_list
);
1012 /* we may not get these,
1013 * but they shouldnt be in default
1016 /* can only be set on burst */
1025 if (MyConnect(source_p
))
1027 if(!IsOper(source_p
)
1028 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
1030 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1035 if(what
== MODE_ADD
)
1038 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1040 source_p
->snomask
|= SNO_GENERAL
;
1043 source_p
->snomask
= 0;
1044 if (source_p
->snomask
!= 0)
1045 source_p
->umodes
|= UMODE_SERVNOTICE
;
1047 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1052 if((flag
= user_modes
[(unsigned char) *pm
]))
1054 if(MyConnect(source_p
)
1055 && !IsOper(source_p
)
1056 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1058 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1063 if(what
== MODE_ADD
)
1064 source_p
->umodes
|= flag
;
1066 source_p
->umodes
&= ~flag
;
1071 if(MyConnect(source_p
))
1078 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1080 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1082 if(IsOper(source_p
))
1083 sendto_one(source_p
,
1084 ":%s NOTICE %s :*** You need the operwall flag for +z", me
.name
, parv
[0]);
1086 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1087 source_p
->umodes
&= ~UMODE_OPERWALL
;
1090 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1091 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1093 if(IsOper(source_p
))
1094 sendto_one(source_p
,
1095 ":%s NOTICE %s :*** You need the A flag for +a", me
.name
, parv
[0]);
1097 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1098 source_p
->umodes
&= ~UMODE_ADMIN
;
1101 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_HELPER
) && !IsOperHelper(source_p
))
1103 if(IsOper(source_p
))
1104 sendto_one(source_p
,
1105 ":%s NOTICE %s :*** You need the helper flag for +T", me
.name
, parv
[0]);
1107 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1109 source_p
->umodes
&= ~UMODE_HELPER
;
1112 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OVERRIDE
) && !IsOperOverride(source_p
))
1114 if(IsOper(source_p
))
1115 sendto_one(source_p
,
1116 ":%s NOTICE %s :*** You need the override flag for +p", me
.name
, parv
[0]);
1118 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1120 source_p
->umodes
&= ~UMODE_OVERRIDE
;
1123 if(MyClient(source_p
) &&
1124 ((source_p
->snomask
& source_p
->allowed_snomask
) != source_p
->snomask
))
1126 sendto_one(source_p
,
1127 ":%s NOTICE %s :*** Server notices not granted: %s",
1128 me
.name
, source_p
->name
,
1129 construct_snobuf(source_p
->snomask
& ~source_p
->allowed_snomask
));
1130 source_p
->snomask
&= source_p
->allowed_snomask
;
1133 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1134 hdata
.client
= source_p
;
1135 hdata
.oldumodes
= setflags
;
1136 hdata
.oldsnomask
= setsnomask
;
1137 call_hook(h_umode_changed
, &hdata
);
1139 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1141 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1144 * compare new flags with old flags and send string which
1145 * will cause servers to update correctly.
1147 send_umode_out(client_p
, source_p
, setflags
);
1148 if (showsnomask
&& MyConnect(source_p
))
1149 sendto_one(source_p
, form_str(RPL_SNOMASK
), me
.name
, source_p
->name
,
1150 construct_snobuf(source_p
->snomask
));
1156 * send the MODE string for user (user) to connection client_p
1160 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, int sendmask
, char *umode_buf
)
1168 * build a string in umode_buf to represent the change in the user's
1169 * mode between the new (source_p->flag) and 'old'.
1174 for (i
= 0; i
< 128; i
++)
1176 flag
= user_modes
[i
];
1178 if((flag
& old
) && !(source_p
->umodes
& flag
))
1180 if(what
== MODE_DEL
)
1189 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1191 if(what
== MODE_ADD
)
1203 if(*umode_buf
&& client_p
)
1204 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1215 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1217 struct Client
*target_p
;
1221 send_umode(NULL
, source_p
, old
, 0, buf
);
1223 DLINK_FOREACH(ptr
, serv_list
.head
)
1225 target_p
= ptr
->data
;
1227 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1229 sendto_one(target_p
, ":%s MODE %s :%s",
1230 get_id(source_p
, target_p
),
1231 get_id(source_p
, target_p
), buf
);
1235 if(client_p
&& MyClient(client_p
))
1236 send_umode(client_p
, source_p
, old
, 0, buf
);
1242 * inputs - client pointer to client to welcome
1247 user_welcome(struct Client
*source_p
)
1249 sendto_one(source_p
, form_str(RPL_WELCOME
), me
.name
, source_p
->name
,
1250 ServerInfo
.network_name
, source_p
->name
);
1251 sendto_one(source_p
, form_str(RPL_YOURHOST
), me
.name
,
1253 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1255 sendto_one(source_p
, form_str(RPL_CREATED
), me
.name
, source_p
->name
, creation
);
1256 sendto_one(source_p
, form_str(RPL_MYINFO
), me
.name
, source_p
->name
, me
.name
, ircd_version
, umodebuf
);
1258 show_isupport(source_p
);
1260 show_lusers(source_p
);
1262 if(ConfigFileEntry
.short_motd
)
1264 sendto_one(source_p
,
1265 "NOTICE %s :*** Notice -- motd was last changed at %s",
1266 source_p
->name
, user_motd_changed
);
1268 sendto_one(source_p
,
1269 "NOTICE %s :*** Notice -- Please read the motd if you haven't read it",
1272 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1273 me
.name
, source_p
->name
, me
.name
);
1275 sendto_one(source_p
, form_str(RPL_MOTD
),
1276 me
.name
, source_p
->name
, "*** This is the short motd ***");
1278 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1281 send_user_motd(source_p
);
1284 /* {{{ int oper_up()
1286 * Opers up client pointed to by source_p, using aconf for reference.
1289 oper_up (struct Client
*source_p
, struct oper_conf
*oper_p
)
1291 unsigned int old_umodes
= source_p
->umodes
;
1292 unsigned int old_snomask
= source_p
->snomask
;
1293 hook_data_umode_changed hdata
;
1296 SetExemptKline(source_p
);
1300 source_p
->umodes
|= oper_p
->umodes
;
1301 else if (ConfigFileEntry
.oper_umodes
)
1302 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1304 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1306 if (oper_p
->snomask
)
1308 source_p
->umodes
|= UMODE_SERVNOTICE
;
1309 source_p
->snomask
|= oper_p
->snomask
& oper_p
->allowed_snomask
;
1311 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1313 /* Only apply these if +s is already set -- jilles */
1314 if (ConfigFileEntry
.oper_snomask
)
1315 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1317 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1320 source_p
->allowed_snomask
= oper_p
->allowed_snomask
;
1321 source_p
->operflags
= oper_p
->flags
;
1322 DupString(source_p
->localClient
->opername
, oper_p
->name
);
1324 dlinkAddAlloc(source_p
, &local_oper_list
);
1325 dlinkAddAlloc(source_p
, &oper_list
);
1327 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1328 source_p
->umodes
|= UMODE_ADMIN
;
1329 if(!IsOperOperwall(source_p
))
1330 source_p
->umodes
&= ~UMODE_OPERWALL
;
1332 hdata
.client
= source_p
;
1333 hdata
.oldumodes
= old_umodes
;
1334 hdata
.oldsnomask
= old_snomask
;
1335 call_hook(h_umode_changed
, &hdata
);
1337 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
1338 "%s (%s@%s) is now an operator", source_p
->name
,
1339 source_p
->username
, source_p
->host
);
1341 send_umode_out(source_p
, source_p
, old_umodes
);
1342 sendto_one(source_p
, form_str(RPL_SNOMASK
), me
.name
, source_p
->name
,
1343 construct_snobuf(source_p
->snomask
));
1345 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1346 sendto_one(source_p
, ":%s NOTICE %s :*** Oper privs are %s", me
.name
,
1347 source_p
->name
, get_oper_privs(oper_p
->flags
));
1348 sendto_one(source_p
, ":%s NOTICE %s :*** Allowed snomasks are %s", me
.name
,
1349 source_p
->name
, construct_snobuf(source_p
->allowed_snomask
));
1351 send_oper_motd(source_p
);
1353 sendto_server(source_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s ENCAP * OPER %s",
1354 use_id(source_p
), get_oper_privs(oper_p
->flags
));
1356 sendto_server(source_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s ENCAP * OPER %s",
1357 source_p
->name
, get_oper_privs(oper_p
->flags
));
1363 construct_umodebuf(void)
1366 char *ptr
= umodebuf
;
1370 for (i
= 0; i
< 128; i
++)
1378 change_nick_user_host(struct Client
*target_p
, const char *nick
, const char *user
,
1379 const char *host
, int newts
, char *format
, ...)
1382 struct Channel
*chptr
;
1383 struct membership
*mscptr
;
1384 int changed
= irccmp(target_p
->name
, nick
);
1385 int changed_case
= strcmp(target_p
->name
, nick
);
1386 int do_qjm
= irccmp(target_p
->username
, user
) || irccmp(target_p
->host
, host
);
1387 char mode
[10], modeval
[NICKLEN
* 2 + 2], reason
[256], *mptr
;
1394 target_p
->tsinfo
= newts
;
1395 monitor_signoff(target_p
);
1397 invalidate_bancache_user(target_p
);
1401 va_start(ap
, format
);
1402 vsnprintf(reason
, 255, format
, ap
);
1405 sendto_common_channels_local_butone(target_p
, ":%s!%s@%s QUIT :%s",
1406 target_p
->name
, target_p
->username
, target_p
->host
,
1409 DLINK_FOREACH(ptr
, target_p
->user
->channel
.head
)
1412 chptr
= mscptr
->chptr
;
1415 if(is_real_chanop(mscptr
))
1418 strcat(modeval
, nick
);
1419 strcat(modeval
, " ");
1422 if(is_voiced(mscptr
))
1425 strcat(modeval
, nick
);
1430 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
1431 nick
, user
, host
, chptr
->chname
);
1433 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
,
1434 ":%s MODE %s +%s %s",
1435 target_p
->servptr
->name
,
1436 chptr
->chname
, mode
, modeval
);
1441 if(MyClient(target_p
) && changed_case
)
1442 sendto_one(target_p
, ":%s!%s@%s NICK %s",
1443 target_p
->name
, target_p
->username
, target_p
->host
, nick
);
1445 else if(changed_case
)
1447 sendto_common_channels_local(target_p
, ":%s!%s@%s NICK :%s",
1448 target_p
->name
, target_p
->username
,
1449 target_p
->host
, nick
);
1452 strlcpy(target_p
->username
, user
, USERLEN
);
1453 strlcpy(target_p
->host
, host
, HOSTLEN
);
1456 add_history(target_p
, 1);
1458 del_from_client_hash(target_p
->name
, target_p
);
1459 strlcpy(target_p
->name
, nick
, NICKLEN
);
1460 add_to_client_hash(target_p
->name
, target_p
);
1464 monitor_signon(target_p
);
1465 del_all_accepts(target_p
);