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
24 * $Id: s_user.c 3586 2007-11-20 11:16:43Z nenolod $
35 #include "irc_string.h"
36 #include "sprintf_irc.h"
43 #include "s_newconf.h"
49 #include "supported.h"
58 #include "blacklist.h"
59 #include "substitution.h"
61 static void report_and_set_user_flags(struct Client
*, struct ConfItem
*);
62 void user_welcome(struct Client
*source_p
);
68 static int orphaned_umodes
= 0;
69 int user_modes
[256] = {
70 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
71 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
72 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
73 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
91 UMODE_NOFORWARD
, /* Q */
92 UMODE_REGONLYMSG
, /* R */
93 UMODE_SERVICE
, /* S */
101 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
108 UMODE_CALLERID
, /* g */
110 UMODE_INVISIBLE
, /* i */
113 UMODE_LOCOPS
, /* l */
120 UMODE_SERVNOTICE
, /* s */
124 UMODE_WALLOP
, /* w */
127 UMODE_OPERWALL
, /* z */
128 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
129 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
130 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
131 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
132 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
133 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
134 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
135 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
136 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
143 * inputs - pointer to client
145 * side effects - display to client user counts etc.
148 show_lusers(struct Client
*source_p
)
150 if(dlink_list_length(&lclient_list
) > (unsigned long)MaxClientCount
)
151 MaxClientCount
= dlink_list_length(&lclient_list
);
153 if((dlink_list_length(&lclient_list
) + dlink_list_length(&serv_list
)) >
154 (unsigned long)MaxConnectionCount
)
155 MaxConnectionCount
= dlink_list_length(&lclient_list
) +
156 dlink_list_length(&serv_list
);
158 sendto_one_numeric(source_p
, RPL_LUSERCLIENT
, form_str(RPL_LUSERCLIENT
),
159 (Count
.total
- Count
.invisi
),
160 Count
.invisi
, dlink_list_length(&global_serv_list
));
162 if(dlink_list_length(&oper_list
) > 0)
163 sendto_one_numeric(source_p
, RPL_LUSEROP
,
164 form_str(RPL_LUSEROP
), dlink_list_length(&oper_list
));
166 if(dlink_list_length(&unknown_list
) > 0)
167 sendto_one_numeric(source_p
, RPL_LUSERUNKNOWN
,
168 form_str(RPL_LUSERUNKNOWN
),
169 dlink_list_length(&unknown_list
));
171 if(dlink_list_length(&global_channel_list
) > 0)
172 sendto_one_numeric(source_p
, RPL_LUSERCHANNELS
,
173 form_str(RPL_LUSERCHANNELS
),
174 dlink_list_length(&global_channel_list
));
176 sendto_one_numeric(source_p
, RPL_LUSERME
, form_str(RPL_LUSERME
),
177 dlink_list_length(&lclient_list
),
178 dlink_list_length(&serv_list
));
180 sendto_one_numeric(source_p
, RPL_LOCALUSERS
,
181 form_str(RPL_LOCALUSERS
),
182 dlink_list_length(&lclient_list
),
184 dlink_list_length(&lclient_list
),
187 sendto_one_numeric(source_p
, RPL_GLOBALUSERS
, form_str(RPL_GLOBALUSERS
),
188 Count
.total
, Count
.max_tot
,
189 Count
.total
, Count
.max_tot
);
191 sendto_one_numeric(source_p
, RPL_STATSCONN
,
192 form_str(RPL_STATSCONN
),
193 MaxConnectionCount
, MaxClientCount
,
194 Count
.totalrestartcount
);
200 ** register_local_user
201 ** This function is called when both NICK and USER messages
202 ** have been accepted for the client, in whatever order. Only
203 ** after this, is the USER message propagated.
205 ** NICK's must be propagated at once when received, although
206 ** it would be better to delay them too until full info is
207 ** available. Doing it is not so simple though, would have
208 ** to implement the following:
210 ** (actually it has been implemented already for a while) -orabidoo
212 ** 1) user telnets in and gives only "NICK foobar" and waits
213 ** 2) another user far away logs in normally with the nick
214 ** "foobar" (quite legal, as this server didn't propagate
216 ** 3) now this server gets nick "foobar" from outside, but
217 ** has alread the same defined locally. Current server
218 ** would just issue "KILL foobar" to clean out dups. But,
219 ** this is not fair. It should actually request another
220 ** nick from local user or kill him/her...
224 register_local_user(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
226 struct ConfItem
*aconf
, *xconf
;
227 struct User
*user
= source_p
->user
;
228 char tmpstr2
[IRCD_BUFSIZE
];
229 char ipaddr
[HOSTIPLEN
];
230 char myusername
[USERLEN
+1];
233 s_assert(NULL
!= source_p
);
234 s_assert(MyConnect(source_p
));
235 s_assert(source_p
->username
!= username
);
240 if(IsAnyDead(source_p
))
243 if(ConfigFileEntry
.ping_cookie
)
245 if(!(source_p
->flags
& FLAGS_PINGSENT
) && source_p
->localClient
->random_ping
== 0)
247 source_p
->localClient
->random_ping
= (unsigned long) (rand() * rand()) << 1;
248 sendto_one(source_p
, "PING :%08lX",
249 (unsigned long) source_p
->localClient
->random_ping
);
250 source_p
->flags
|= FLAGS_PINGSENT
;
253 if(!(source_p
->flags
& FLAGS_PING_COOKIE
))
259 /* hasnt finished client cap negotiation */
260 if(source_p
->flags
& FLAGS_CLICAP
)
263 /* still has DNSbls to validate against */
264 if(dlink_list_length(&source_p
->preClient
->dnsbl_queries
) > 0)
267 client_p
->localClient
->last
= CurrentTime
;
268 /* Straight up the maximum rate of flooding... */
269 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
271 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
272 if(!IsGotId(source_p
) && (strchr(username
, '[') != NULL
))
279 while(*p
&& i
< USERLEN
)
282 myusername
[i
++] = *p
;
286 myusername
[i
] = '\0';
287 username
= myusername
;
290 if((status
= check_client(client_p
, source_p
, username
)) < 0)
291 return (CLIENT_EXITED
);
293 /* Apply nick override */
294 if(*source_p
->preClient
->spoofnick
)
296 del_from_client_hash(source_p
->name
, source_p
);
297 strlcpy(source_p
->name
, source_p
->preClient
->spoofnick
, NICKLEN
+ 1);
298 add_to_client_hash(source_p
->name
, source_p
);
299 comm_note(source_p
->localClient
->fd
, "Nick: %s", source_p
->name
);
302 if(!valid_hostname(source_p
->host
))
304 sendto_one_notice(source_p
, ":*** Notice -- You have an illegal character in your hostname");
306 strlcpy(source_p
->host
, source_p
->sockhost
, sizeof(source_p
->host
));
310 aconf
= source_p
->localClient
->att_conf
;
314 exit_client(client_p
, source_p
, &me
, "*** Not Authorised");
315 return (CLIENT_EXITED
);
318 if(!IsGotId(source_p
))
323 if(IsNeedIdentd(aconf
))
325 ServerStats
->is_ref
++;
326 sendto_one_notice(source_p
, ":*** Notice -- You need to install identd to use this server");
327 exit_client(client_p
, source_p
, &me
, "Install identd");
328 return (CLIENT_EXITED
);
331 /* dont replace username if its supposed to be spoofed --fl */
332 if(!IsConfDoSpoofIp(aconf
) || !strchr(aconf
->name
, '@'))
336 if(!IsNoTilde(aconf
))
337 source_p
->username
[i
++] = '~';
339 while (*p
&& i
< USERLEN
)
342 source_p
->username
[i
++] = *p
;
346 source_p
->username
[i
] = '\0';
350 if(IsNeedSasl(aconf
) && !*user
->suser
)
352 ServerStats
->is_ref
++;
353 sendto_one_notice(source_p
, ":*** Notice -- You need to identify via SASL to use this server");
354 exit_client(client_p
, source_p
, &me
, "SASL access only");
355 return (CLIENT_EXITED
);
359 if(!EmptyString(aconf
->passwd
))
363 if(EmptyString(source_p
->localClient
->passwd
))
365 else if(IsConfEncrypted(aconf
))
366 encr
= crypt(source_p
->localClient
->passwd
, aconf
->passwd
);
368 encr
= source_p
->localClient
->passwd
;
370 if(strcmp(encr
, aconf
->passwd
))
372 ServerStats
->is_ref
++;
373 sendto_one(source_p
, form_str(ERR_PASSWDMISMATCH
), me
.name
, source_p
->name
);
374 exit_client(client_p
, source_p
, &me
, "Bad Password");
375 return (CLIENT_EXITED
);
378 /* clear password only if used now, otherwise send it
379 * to services -- jilles */
380 if(source_p
->localClient
->passwd
)
382 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
383 MyFree(source_p
->localClient
->passwd
);
384 source_p
->localClient
->passwd
= NULL
;
388 /* report if user has &^>= etc. and set flags as needed in source_p */
389 report_and_set_user_flags(source_p
, aconf
);
393 * We want to be able to have servers and F-line clients
394 * connect, so save room for "buffer" connections.
395 * Smaller servers may want to decrease this, and it should
396 * probably be just a percentage of the MAXCLIENTS...
399 /* Except "F:" clients */
400 if(dlink_list_length(&lclient_list
) >=
401 (unsigned long)GlobalSetOptions
.maxclients
&& !IsExemptLimits(source_p
))
403 sendto_realops_snomask(SNO_FULL
, L_ALL
,
404 "Too many clients, rejecting %s[%s].", source_p
->name
, source_p
->host
);
406 ServerStats
->is_ref
++;
407 exit_client(client_p
, source_p
, &me
, "Sorry, server is full - try later");
408 return (CLIENT_EXITED
);
411 /* kline exemption extends to xline too */
412 if(!IsExemptKline(source_p
) &&
413 (xconf
= find_xline(source_p
->info
, 1)) != NULL
)
415 ServerStats
->is_ref
++;
416 add_reject(source_p
, xconf
->name
, NULL
);
417 exit_client(client_p
, source_p
, &me
, "Bad user info");
418 return CLIENT_EXITED
;
422 if (source_p
->preClient
->dnsbl_listed
!= NULL
)
424 if (IsExemptKline(source_p
) || IsConfExemptDNSBL(aconf
))
425 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s, but you are exempt",
426 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
429 dlink_list varlist
= { NULL
, NULL
, 0 };
431 substitution_append_var(&varlist
, "nick", source_p
->name
);
432 substitution_append_var(&varlist
, "ip", source_p
->sockhost
);
433 substitution_append_var(&varlist
, "host", source_p
->host
);
434 substitution_append_var(&varlist
, "dnsbl-host", source_p
->preClient
->dnsbl_listed
->host
);
435 substitution_append_var(&varlist
, "network-name", ServerInfo
.network_name
);
437 ServerStats
->is_ref
++;
439 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
440 me
.name
, source_p
->name
,
441 substitution_parse(source_p
->preClient
->dnsbl_listed
->reject_reason
, &varlist
));
443 substitution_free(&varlist
);
445 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s",
446 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
447 source_p
->preClient
->dnsbl_listed
->hits
++;
448 add_reject(source_p
, NULL
, NULL
);
449 exit_client(client_p
, source_p
, &me
, "*** Banned (DNS blacklist)");
450 return CLIENT_EXITED
;
454 /* valid user name check */
456 if(!valid_username(source_p
->username
))
458 sendto_realops_snomask(SNO_REJ
, L_ALL
,
459 "Invalid username: %s (%s@%s)",
460 source_p
->name
, source_p
->username
, source_p
->host
);
461 ServerStats
->is_ref
++;
462 sendto_one_notice(source_p
, ":*** Your username is invalid. Please make sure that your username contains "
463 "only alphanumeric characters.");
464 ircsprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
465 exit_client(client_p
, source_p
, &me
, tmpstr2
);
466 return (CLIENT_EXITED
);
469 /* end of valid user name check */
471 /* Store original hostname -- jilles */
472 strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
474 /* Spoof user@host */
475 if(*source_p
->preClient
->spoofuser
)
476 strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
477 if(*source_p
->preClient
->spoofhost
)
479 strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
480 if (irccmp(source_p
->host
, source_p
->orighost
))
481 SetDynSpoof(source_p
);
484 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
& ~orphaned_umodes
;
486 call_hook(h_new_local_user
, source_p
);
488 /* If they have died in send_* or were thrown out by the
489 * new_local_user hook don't do anything. */
490 if(IsAnyDead(source_p
))
491 return CLIENT_EXITED
;
493 /* To avoid inconsistencies, do not abort the registration
494 * starting from this point -- jilles
496 inetntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
498 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
499 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
500 source_p
->name
, source_p
->username
, source_p
->orighost
,
501 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
502 get_client_class(source_p
), source_p
->info
);
504 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
505 "CLICONN %s %s %s %s %s %s 0 %s",
506 source_p
->name
, source_p
->username
, source_p
->orighost
,
507 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
508 get_client_class(source_p
),
509 /* mirc can sometimes send ips here */
510 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
513 add_to_hostname_hash(source_p
->orighost
, source_p
);
515 /* Allocate a UID if it was not previously allocated.
516 * If this already occured, it was probably during SASL auth...
520 strcpy(source_p
->id
, generate_uid());
521 add_to_id_hash(source_p
->id
, source_p
);
524 if (source_p
->umodes
& UMODE_INVISIBLE
)
527 s_assert(!IsClient(source_p
));
528 del_unknown_ip(source_p
);
529 dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
532 source_p
->servptr
= &me
;
533 dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
535 /* Increment our total user count here */
536 if(++Count
.total
> Count
.max_tot
)
537 Count
.max_tot
= Count
.total
;
539 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
541 Count
.totalrestartcount
++;
543 s_assert(source_p
->localClient
!= NULL
);
545 if(dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
547 Count
.max_loc
= dlink_list_length(&lclient_list
);
548 if(!(Count
.max_loc
% 10))
549 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
550 "New Max Local Clients: %d", Count
.max_loc
);
553 /* they get a reduced limit */
554 if(find_tgchange(source_p
->sockhost
))
555 USED_TARGETS(source_p
) = 6;
557 monitor_signon(source_p
);
558 user_welcome(source_p
);
560 free_pre_client(source_p
);
562 return (introduce_client(client_p
, source_p
, user
, source_p
->name
, 1));
570 * side effects - This common function introduces a client to the rest
571 * of the net, either from a local client connect or
572 * from a remote connect.
575 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
577 static char ubuf
[12];
578 struct Client
*identifyservice_p
;
580 hook_data_umode_changed hdata
;
581 hook_data_client hdata2
;
583 if(MyClient(source_p
))
584 send_umode(source_p
, source_p
, 0, 0, ubuf
);
586 send_umode(NULL
, source_p
, 0, 0, ubuf
);
594 /* if it has an ID, introduce it with its id to TS6 servers,
595 * otherwise introduce it normally to all.
599 char sockhost
[HOSTLEN
];
600 if(source_p
->sockhost
[0] == ':')
604 strlcat(sockhost
, source_p
->sockhost
, sizeof(sockhost
));
606 strcpy(sockhost
, source_p
->sockhost
);
609 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
610 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
611 source_p
->servptr
->id
, nick
,
612 source_p
->hopcount
+ 1,
613 (long) source_p
->tsinfo
, ubuf
,
614 source_p
->username
, source_p
->host
,
615 IsIPSpoof(source_p
) ? "0" : sockhost
,
617 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
618 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
621 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
622 ":%s UID %s %d %ld %s %s %s %s %s :%s",
623 source_p
->servptr
->id
, nick
,
624 source_p
->hopcount
+ 1,
625 (long) source_p
->tsinfo
, ubuf
,
626 source_p
->username
, source_p
->host
,
627 IsIPSpoof(source_p
) ? "0" : sockhost
,
628 source_p
->id
, source_p
->info
);
630 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
,
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 source_p
->servptr
->name
, source_p
->info
);
638 sendto_server(client_p
, NULL
, NOCAPS
, NOCAPS
,
639 "NICK %s %d %ld %s %s %s %s :%s",
640 nick
, source_p
->hopcount
+ 1,
641 (long) source_p
->tsinfo
,
642 ubuf
, source_p
->username
, source_p
->host
,
643 source_p
->servptr
->name
, source_p
->info
);
645 if (IsDynSpoof(source_p
))
647 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
648 use_id(source_p
), source_p
->orighost
);
649 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s ENCAP * REALHOST %s",
650 source_p
->name
, source_p
->orighost
);
652 if (!EmptyString(source_p
->user
->suser
))
654 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
655 use_id(source_p
), source_p
->user
->suser
);
656 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s ENCAP * LOGIN %s",
657 source_p
->name
, source_p
->user
->suser
);
660 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
662 if (ConfigFileEntry
.identifyservice
[0] != '\0' &&
663 ConfigFileEntry
.identifycommand
[0] != '\0')
665 /* use user@server */
666 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
668 identifyservice_p
= find_named_client(p
+ 1);
670 identifyservice_p
= NULL
;
671 if (identifyservice_p
!= NULL
)
672 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
673 get_id(source_p
, identifyservice_p
),
674 ConfigFileEntry
.identifyservice
,
675 ConfigFileEntry
.identifycommand
,
676 source_p
->localClient
->passwd
);
678 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
679 MyFree(source_p
->localClient
->passwd
);
680 source_p
->localClient
->passwd
= NULL
;
683 /* let modules providing usermodes know that we've got a new user,
684 * why is this here? -- well, some modules need to be able to send out new
685 * information about a client, so this was the best place to do it
688 hdata
.client
= source_p
;
690 hdata
.oldsnomask
= 0;
691 call_hook(h_umode_changed
, &hdata
);
693 /* On the other hand, some modules need to know when a client is
694 * being introduced, period.
697 hdata2
.client
= client_p
;
698 hdata2
.target
= source_p
;
699 call_hook(h_introduce_client
, &hdata2
);
705 * valid_hostname - check hostname for validity
707 * Inputs - pointer to user
708 * Output - YES if valid, NO if not
709 * Side effects - NONE
711 * NOTE: this doesn't allow a hostname to begin with a dot and
712 * will not allow more dots than chars.
715 valid_hostname(const char *hostname
)
717 const char *p
= hostname
;
725 if('.' == *p
|| ':' == *p
)
732 if(*p
== '.' || *p
== ':')
744 * valid_username - check username for validity
746 * Inputs - pointer to user
747 * Output - YES if valid, NO if not
748 * Side effects - NONE
750 * Absolutely always reject any '*' '!' '?' '@' in an user name
751 * reject any odd control characters names.
752 * Allow '.' in username to allow for "first.last"
756 valid_username(const char *username
)
759 const char *p
= username
;
769 /* reject usernames that don't start with an alphanum
770 * i.e. reject jokers who have '-@somehost' or '.@somehost'
771 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
778 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
781 if(dots
> ConfigFileEntry
.dots_in_ident
)
783 if(!IsUserChar(p
[1]))
786 else if(!IsUserChar(*p
))
792 /* report_and_set_user_flags
794 * Inputs - pointer to source_p
795 * - pointer to aconf for this user
798 * Report to user any special flags they are getting, and set them.
802 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
804 /* If this user is being spoofed, tell them so */
805 if(IsConfDoSpoofIp(aconf
))
807 sendto_one_notice(source_p
, ":*** Spoofing your IP. congrats.");
810 /* If this user is in the exception class, Set it "E lined" */
811 if(IsConfExemptKline(aconf
))
813 SetExemptKline(source_p
);
814 sendto_one_notice(source_p
, ":*** You are exempt from K/D/G/X lines. congrats.");
817 if(IsConfExemptGline(aconf
))
819 SetExemptGline(source_p
);
821 /* dont send both a kline and gline exempt notice */
822 if(!IsConfExemptKline(aconf
))
823 sendto_one_notice(source_p
, ":*** You are exempt from G lines.");
826 if(IsConfExemptDNSBL(aconf
))
827 /* kline exempt implies this, don't send both */
828 if(!IsConfExemptKline(aconf
))
829 sendto_one_notice(source_p
, ":*** You are exempt from DNS blacklists.");
831 /* If this user is exempt from user limits set it F lined" */
832 if(IsConfExemptLimits(aconf
))
834 SetExemptLimits(source_p
);
835 sendto_one_notice(source_p
, "*** You are exempt from user limits. congrats.");
838 /* If this user is exempt from idle time outs */
839 if(IsConfIdlelined(aconf
))
841 SetIdlelined(source_p
);
842 sendto_one_notice(source_p
, ":*** You are exempt from idle limits. congrats.");
845 if(IsConfExemptFlood(aconf
))
847 SetExemptFlood(source_p
);
848 sendto_one_notice(source_p
, ":*** You are exempt from flood limits.");
851 if(IsConfExemptSpambot(aconf
))
853 SetExemptSpambot(source_p
);
854 sendto_one_notice(source_p
, ":*** You are exempt from spambot checks.");
857 if(IsConfExemptJupe(aconf
))
859 SetExemptJupe(source_p
);
860 sendto_one_notice(source_p
, ":*** You are exempt from juped channel warnings.");
863 if(IsConfExemptResv(aconf
))
865 SetExemptResv(source_p
);
866 sendto_one_notice(source_p
, ":*** You are exempt from resvs.");
869 if(IsConfExemptShide(aconf
))
871 SetExemptShide(source_p
);
872 sendto_one_notice(source_p
, ":*** You are exempt from serverhiding.");
877 * user_mode - set get current users mode
879 * m_umode() added 15/10/91 By Darren Reed.
881 * parv[1] - username to change mode for
882 * parv[2] - modes to change
885 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
891 struct Client
*target_p
;
893 int badflag
= NO
; /* Only send one bad flag notice */
894 int showsnomask
= NO
;
895 unsigned int setsnomask
;
897 hook_data_umode_changed hdata
;
903 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
907 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
909 if(MyConnect(source_p
))
910 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
911 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
915 /* Dont know why these were commented out..
916 * put them back using new sendto() funcs
919 if(IsServer(source_p
))
921 sendto_realops_snomask(SNO_GENERAL
, L_ADMIN
,
922 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
926 if(source_p
!= target_p
|| target_p
->from
!= source_p
->from
)
928 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
937 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
938 if (source_p
->umodes
& user_modes
[i
])
942 sendto_one_numeric(source_p
, RPL_UMODEIS
, form_str(RPL_UMODEIS
), buf
);
944 if (source_p
->snomask
!= 0)
945 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
946 construct_snobuf(source_p
->snomask
));
951 /* find flags already set for user */
952 setflags
= source_p
->umodes
;
953 setsnomask
= source_p
->snomask
;
956 * parse mode change string(s)
958 for (pm
= parv
[2]; *pm
; pm
++)
971 if(IsServer(client_p
) && !IsOper(source_p
))
975 dlinkAddAlloc(source_p
, &oper_list
);
980 /* Only decrement the oper counts if an oper to begin with
981 * found by Pat Szuta, Perly , perly@xnet.com
984 if(!IsOper(source_p
))
991 if(MyConnect(source_p
))
993 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
994 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
996 source_p
->snomask
= 0;
999 source_p
->flags2
&= ~OPER_FLAGS
;
1001 MyFree(source_p
->localClient
->opername
);
1002 source_p
->localClient
->opername
= NULL
;
1004 dlinkFindDestroy(source_p
, &local_oper_list
);
1007 dlinkFindDestroy(source_p
, &oper_list
);
1011 /* we may not get these,
1012 * but they shouldnt be in default
1015 /* can only be set on burst */
1024 if (MyConnect(source_p
))
1026 if(!IsOper(source_p
)
1027 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
1029 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1034 if(what
== MODE_ADD
)
1037 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1039 source_p
->snomask
|= SNO_GENERAL
;
1042 source_p
->snomask
= 0;
1043 if (source_p
->snomask
!= 0)
1044 source_p
->umodes
|= UMODE_SERVNOTICE
;
1046 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1051 if (MyConnect(source_p
) && *pm
== 'Q' && !ConfigChannel
.use_forward
) {
1056 if((flag
= user_modes
[(unsigned char) *pm
]))
1058 if(MyConnect(source_p
)
1059 && ((!IsOper(source_p
)
1060 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1061 || (orphaned_umodes
& flag
)))
1063 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1068 if(what
== MODE_ADD
)
1069 source_p
->umodes
|= flag
;
1071 source_p
->umodes
&= ~flag
;
1076 if(MyConnect(source_p
))
1083 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1085 if(MyClient(source_p
) && (source_p
->snomask
& SNO_NCHANGE
) && !IsOperN(source_p
))
1087 sendto_one_notice(source_p
, ":*** You need oper and N flag for +s +n");
1088 source_p
->snomask
&= ~SNO_NCHANGE
; /* only tcm's really need this */
1091 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1093 sendto_one_notice(source_p
, ":*** You need oper and operwall flag for +z");
1094 source_p
->umodes
&= ~UMODE_OPERWALL
;
1097 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1098 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1100 sendto_one_notice(source_p
, ":*** You need oper and A flag for +a");
1101 source_p
->umodes
&= ~UMODE_ADMIN
;
1104 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1105 hdata
.client
= source_p
;
1106 hdata
.oldumodes
= setflags
;
1107 hdata
.oldsnomask
= setsnomask
;
1108 call_hook(h_umode_changed
, &hdata
);
1110 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1112 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1115 * compare new flags with old flags and send string which
1116 * will cause servers to update correctly.
1118 send_umode_out(client_p
, source_p
, setflags
);
1119 if (showsnomask
&& MyConnect(source_p
))
1120 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1121 construct_snobuf(source_p
->snomask
));
1127 * send the MODE string for user (user) to connection client_p
1131 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, int sendmask
, char *umode_buf
)
1139 * build a string in umode_buf to represent the change in the user's
1140 * mode between the new (source_p->flag) and 'old'.
1145 for (i
= 0; i
< 128; i
++)
1147 flag
= user_modes
[i
];
1149 if((flag
& old
) && !(source_p
->umodes
& flag
))
1151 if(what
== MODE_DEL
)
1160 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1162 if(what
== MODE_ADD
)
1174 if(*umode_buf
&& client_p
)
1175 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1186 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1188 struct Client
*target_p
;
1192 send_umode(NULL
, source_p
, old
, 0, buf
);
1194 DLINK_FOREACH(ptr
, serv_list
.head
)
1196 target_p
= ptr
->data
;
1198 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1200 sendto_one(target_p
, ":%s MODE %s :%s",
1201 get_id(source_p
, target_p
),
1202 get_id(source_p
, target_p
), buf
);
1206 if(client_p
&& MyClient(client_p
))
1207 send_umode(client_p
, source_p
, old
, 0, buf
);
1213 * inputs - client pointer to client to welcome
1218 user_welcome(struct Client
*source_p
)
1220 sendto_one_numeric(source_p
, RPL_WELCOME
, form_str(RPL_WELCOME
), ServerInfo
.network_name
, source_p
->name
);
1221 sendto_one_numeric(source_p
, RPL_YOURHOST
, form_str(RPL_YOURHOST
),
1222 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1223 sendto_one_numeric(source_p
, RPL_CREATED
, form_str(RPL_CREATED
), creation
);
1224 sendto_one_numeric(source_p
, RPL_MYINFO
, form_str(RPL_MYINFO
), me
.name
, ircd_version
, umodebuf
);
1226 show_isupport(source_p
);
1228 show_lusers(source_p
);
1230 if(ConfigFileEntry
.short_motd
)
1232 sendto_one_notice(source_p
, ":*** Notice -- motd was last changed at %s", user_motd_changed
);
1233 sendto_one_notice(source_p
, ":*** Notice -- Please read the motd if you haven't read it");
1235 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1236 me
.name
, source_p
->name
, me
.name
);
1238 sendto_one(source_p
, form_str(RPL_MOTD
),
1239 me
.name
, source_p
->name
, "*** This is the short motd ***");
1241 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1244 send_user_motd(source_p
);
1249 * inputs - pointer to given client to oper
1250 * - pointer to ConfItem to use
1252 * side effects - opers up source_p using aconf for reference
1255 oper_up(struct Client
*source_p
, struct oper_conf
*oper_p
)
1257 unsigned int old
= source_p
->umodes
, oldsnomask
= source_p
->snomask
;
1258 hook_data_umode_changed hdata
;
1263 source_p
->umodes
|= oper_p
->umodes
;
1264 else if(ConfigFileEntry
.oper_umodes
)
1265 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1267 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1269 if (oper_p
->snomask
)
1271 source_p
->snomask
|= oper_p
->snomask
;
1272 source_p
->umodes
|= UMODE_SERVNOTICE
;
1274 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1276 /* Only apply these if +s is already set -- jilles */
1277 if (ConfigFileEntry
.oper_snomask
)
1278 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1280 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1285 SetExemptKline(source_p
);
1287 source_p
->flags2
|= oper_p
->flags
;
1288 DupString(source_p
->localClient
->opername
, oper_p
->name
);
1290 dlinkAddAlloc(source_p
, &local_oper_list
);
1291 dlinkAddAlloc(source_p
, &oper_list
);
1293 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1294 source_p
->umodes
|= UMODE_ADMIN
;
1295 if(!IsOperN(source_p
))
1296 source_p
->snomask
&= ~SNO_NCHANGE
;
1297 if(!IsOperOperwall(source_p
))
1298 source_p
->umodes
&= ~UMODE_OPERWALL
;
1299 hdata
.client
= source_p
;
1300 hdata
.oldumodes
= old
;
1301 hdata
.oldsnomask
= oldsnomask
;
1302 call_hook(h_umode_changed
, &hdata
);
1304 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1305 "%s (%s@%s) is now an operator", source_p
->name
,
1306 source_p
->username
, source_p
->host
);
1307 if(!(old
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1309 if((old
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1311 send_umode_out(source_p
, source_p
, old
);
1312 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1313 construct_snobuf(source_p
->snomask
));
1314 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1315 sendto_one_notice(source_p
, ":*** Oper privs are %s", get_oper_privs(oper_p
->flags
));
1316 send_oper_motd(source_p
);
1325 * outputs - an available umode bitmask or
1326 * 0 if no umodes are available
1327 * side effects - NONE
1330 find_umode_slot(void)
1332 unsigned int all_umodes
= 0, my_umode
= 0, i
;
1334 for (i
= 0; i
< 128; i
++)
1335 all_umodes
|= user_modes
[i
];
1337 for (my_umode
= 1; my_umode
&& (all_umodes
& my_umode
);
1344 construct_umodebuf(void)
1347 char *ptr
= umodebuf
;
1348 static int prev_user_modes
[128];
1352 for (i
= 0; i
< 128; i
++)
1354 if (prev_user_modes
[i
] != 0 && prev_user_modes
[i
] != user_modes
[i
])
1356 if (user_modes
[i
] == 0)
1358 orphaned_umodes
|= prev_user_modes
[i
];
1359 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Umode +%c is now orphaned", i
);
1363 orphaned_umodes
&= ~prev_user_modes
[i
];
1364 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Orphaned umode +%c is picked up by module", i
);
1366 user_modes
[i
] = prev_user_modes
[i
];
1369 prev_user_modes
[i
] = user_modes
[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_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
, sizeof target_p
->username
);
1453 strlcpy(target_p
->host
, host
, sizeof target_p
->host
);
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
);