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 $
34 #include "irc_string.h"
35 #include "sprintf_irc.h"
41 #include "s_newconf.h"
47 #include "supported.h"
55 #include "blacklist.h"
56 #include "substitution.h"
58 static void report_and_set_user_flags(struct Client
*, struct ConfItem
*);
59 void user_welcome(struct Client
*source_p
);
65 static int orphaned_umodes
= 0;
66 int user_modes
[256] = {
67 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
68 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
69 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
70 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
88 UMODE_NOFORWARD
, /* Q */
89 UMODE_REGONLYMSG
, /* R */
90 UMODE_SERVICE
, /* S */
98 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
105 UMODE_CALLERID
, /* g */
107 UMODE_INVISIBLE
, /* i */
110 UMODE_LOCOPS
, /* l */
117 UMODE_SERVNOTICE
, /* s */
121 UMODE_WALLOP
, /* w */
124 UMODE_OPERWALL
, /* z */
125 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
126 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
127 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
128 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
129 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
130 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
131 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
132 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
133 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
140 * inputs - pointer to client
142 * side effects - display to client user counts etc.
145 show_lusers(struct Client
*source_p
)
147 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)MaxClientCount
)
148 MaxClientCount
= rb_dlink_list_length(&lclient_list
);
150 if((rb_dlink_list_length(&lclient_list
) + rb_dlink_list_length(&serv_list
)) >
151 (unsigned long)MaxConnectionCount
)
152 MaxConnectionCount
= rb_dlink_list_length(&lclient_list
) +
153 rb_dlink_list_length(&serv_list
);
155 sendto_one_numeric(source_p
, RPL_LUSERCLIENT
, form_str(RPL_LUSERCLIENT
),
156 (Count
.total
- Count
.invisi
),
157 Count
.invisi
, rb_dlink_list_length(&global_serv_list
));
159 if(rb_dlink_list_length(&oper_list
) > 0)
160 sendto_one_numeric(source_p
, RPL_LUSEROP
,
161 form_str(RPL_LUSEROP
), rb_dlink_list_length(&oper_list
));
163 if(rb_dlink_list_length(&unknown_list
) > 0)
164 sendto_one_numeric(source_p
, RPL_LUSERUNKNOWN
,
165 form_str(RPL_LUSERUNKNOWN
),
166 rb_dlink_list_length(&unknown_list
));
168 if(rb_dlink_list_length(&global_channel_list
) > 0)
169 sendto_one_numeric(source_p
, RPL_LUSERCHANNELS
,
170 form_str(RPL_LUSERCHANNELS
),
171 rb_dlink_list_length(&global_channel_list
));
173 sendto_one_numeric(source_p
, RPL_LUSERME
, form_str(RPL_LUSERME
),
174 rb_dlink_list_length(&lclient_list
),
175 rb_dlink_list_length(&serv_list
));
177 sendto_one_numeric(source_p
, RPL_LOCALUSERS
,
178 form_str(RPL_LOCALUSERS
),
179 rb_dlink_list_length(&lclient_list
),
181 rb_dlink_list_length(&lclient_list
),
184 sendto_one_numeric(source_p
, RPL_GLOBALUSERS
, form_str(RPL_GLOBALUSERS
),
185 Count
.total
, Count
.max_tot
,
186 Count
.total
, Count
.max_tot
);
188 sendto_one_numeric(source_p
, RPL_STATSCONN
,
189 form_str(RPL_STATSCONN
),
190 MaxConnectionCount
, MaxClientCount
,
191 Count
.totalrestartcount
);
197 ** register_local_user
198 ** This function is called when both NICK and USER messages
199 ** have been accepted for the client, in whatever order. Only
200 ** after this, is the USER message propagated.
202 ** NICK's must be propagated at once when received, although
203 ** it would be better to delay them too until full info is
204 ** available. Doing it is not so simple though, would have
205 ** to implement the following:
207 ** (actually it has been implemented already for a while) -orabidoo
209 ** 1) user telnets in and gives only "NICK foobar" and waits
210 ** 2) another user far away logs in normally with the nick
211 ** "foobar" (quite legal, as this server didn't propagate
213 ** 3) now this server gets nick "foobar" from outside, but
214 ** has alread the same defined locally. Current server
215 ** would just issue "KILL foobar" to clean out dups. But,
216 ** this is not fair. It should actually request another
217 ** nick from local user or kill him/her...
221 register_local_user(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
223 struct ConfItem
*aconf
, *xconf
;
224 struct User
*user
= source_p
->user
;
225 char tmpstr2
[IRCD_BUFSIZE
];
226 char ipaddr
[HOSTIPLEN
];
227 char myusername
[USERLEN
+1];
230 s_assert(NULL
!= source_p
);
231 s_assert(MyConnect(source_p
));
232 s_assert(source_p
->username
!= username
);
237 if(IsAnyDead(source_p
))
240 if(ConfigFileEntry
.ping_cookie
)
242 if(!(source_p
->flags
& FLAGS_PINGSENT
) && source_p
->localClient
->random_ping
== 0)
244 source_p
->localClient
->random_ping
= (unsigned long) (rand() * rand()) << 1;
245 sendto_one(source_p
, "PING :%08lX",
246 (unsigned long) source_p
->localClient
->random_ping
);
247 source_p
->flags
|= FLAGS_PINGSENT
;
250 if(!(source_p
->flags
& FLAGS_PING_COOKIE
))
256 /* hasnt finished client cap negotiation */
257 if(source_p
->flags
& FLAGS_CLICAP
)
260 /* still has DNSbls to validate against */
261 if(rb_dlink_list_length(&source_p
->preClient
->dnsbl_queries
) > 0)
264 client_p
->localClient
->last
= rb_current_time();
265 /* Straight up the maximum rate of flooding... */
266 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
268 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
269 if(!IsGotId(source_p
) && (strchr(username
, '[') != NULL
))
276 while(*p
&& i
< USERLEN
)
279 myusername
[i
++] = *p
;
283 myusername
[i
] = '\0';
284 username
= myusername
;
287 if((status
= check_client(client_p
, source_p
, username
)) < 0)
288 return (CLIENT_EXITED
);
290 /* Apply nick override */
291 if(*source_p
->preClient
->spoofnick
)
293 del_from_client_hash(source_p
->name
, source_p
);
294 strlcpy(source_p
->name
, source_p
->preClient
->spoofnick
, NICKLEN
+ 1);
295 add_to_client_hash(source_p
->name
, source_p
);
296 rb_note(source_p
->localClient
->F
->fd
, "Nick: %s", source_p
->name
);
299 if(!valid_hostname(source_p
->host
))
301 sendto_one_notice(source_p
, ":*** Notice -- You have an illegal character in your hostname");
303 strlcpy(source_p
->host
, source_p
->sockhost
, sizeof(source_p
->host
));
307 aconf
= source_p
->localClient
->att_conf
;
311 exit_client(client_p
, source_p
, &me
, "*** Not Authorised");
312 return (CLIENT_EXITED
);
315 if(!IsGotId(source_p
))
320 if(IsNeedIdentd(aconf
))
322 ServerStats
->is_ref
++;
323 sendto_one_notice(source_p
, ":*** Notice -- You need to install identd to use this server");
324 exit_client(client_p
, source_p
, &me
, "Install identd");
325 return (CLIENT_EXITED
);
328 /* dont replace username if its supposed to be spoofed --fl */
329 if(!IsConfDoSpoofIp(aconf
) || !strchr(aconf
->name
, '@'))
333 if(!IsNoTilde(aconf
))
334 source_p
->username
[i
++] = '~';
336 while (*p
&& i
< USERLEN
)
339 source_p
->username
[i
++] = *p
;
343 source_p
->username
[i
] = '\0';
347 if(IsNeedSasl(aconf
) && !*user
->suser
)
349 ServerStats
->is_ref
++;
350 sendto_one_notice(source_p
, ":*** Notice -- You need to identify via SASL to use this server");
351 exit_client(client_p
, source_p
, &me
, "SASL access only");
352 return (CLIENT_EXITED
);
356 if(!EmptyString(aconf
->passwd
))
360 if(EmptyString(source_p
->localClient
->passwd
))
362 else if(IsConfEncrypted(aconf
))
363 encr
= crypt(source_p
->localClient
->passwd
, aconf
->passwd
);
365 encr
= source_p
->localClient
->passwd
;
367 if(strcmp(encr
, aconf
->passwd
))
369 ServerStats
->is_ref
++;
370 sendto_one(source_p
, form_str(ERR_PASSWDMISMATCH
), me
.name
, source_p
->name
);
371 exit_client(client_p
, source_p
, &me
, "Bad Password");
372 return (CLIENT_EXITED
);
375 /* clear password only if used now, otherwise send it
376 * to services -- jilles */
377 if(source_p
->localClient
->passwd
)
379 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
380 rb_free(source_p
->localClient
->passwd
);
381 source_p
->localClient
->passwd
= NULL
;
385 /* report if user has &^>= etc. and set flags as needed in source_p */
386 report_and_set_user_flags(source_p
, aconf
);
390 * We want to be able to have servers and F-line clients
391 * connect, so save room for "buffer" connections.
392 * Smaller servers may want to decrease this, and it should
393 * probably be just a percentage of the MAXCLIENTS...
396 /* Except "F:" clients */
397 if(rb_dlink_list_length(&lclient_list
) >=
398 (unsigned long)GlobalSetOptions
.maxclients
&& !IsConfExemptLimits(aconf
))
400 sendto_realops_snomask(SNO_FULL
, L_ALL
,
401 "Too many clients, rejecting %s[%s].", source_p
->name
, source_p
->host
);
403 ServerStats
->is_ref
++;
404 exit_client(client_p
, source_p
, &me
, "Sorry, server is full - try later");
405 return (CLIENT_EXITED
);
408 /* kline exemption extends to xline too */
409 if(!IsExemptKline(source_p
) &&
410 (xconf
= find_xline(source_p
->info
, 1)) != NULL
)
412 ServerStats
->is_ref
++;
413 add_reject(source_p
, xconf
->name
, NULL
);
414 exit_client(client_p
, source_p
, &me
, "Bad user info");
415 return CLIENT_EXITED
;
419 if (source_p
->preClient
->dnsbl_listed
!= NULL
)
421 if (IsExemptKline(source_p
) || IsConfExemptDNSBL(aconf
))
422 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s, but you are exempt",
423 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
426 rb_dlink_list varlist
= { NULL
, NULL
, 0 };
428 substitution_append_var(&varlist
, "nick", source_p
->name
);
429 substitution_append_var(&varlist
, "ip", source_p
->sockhost
);
430 substitution_append_var(&varlist
, "host", source_p
->host
);
431 substitution_append_var(&varlist
, "dnsbl-host", source_p
->preClient
->dnsbl_listed
->host
);
432 substitution_append_var(&varlist
, "network-name", ServerInfo
.network_name
);
434 ServerStats
->is_ref
++;
436 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
437 me
.name
, source_p
->name
,
438 substitution_parse(source_p
->preClient
->dnsbl_listed
->reject_reason
, &varlist
));
440 substitution_free(&varlist
);
442 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s",
443 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
444 source_p
->preClient
->dnsbl_listed
->hits
++;
445 add_reject(source_p
, NULL
, NULL
);
446 exit_client(client_p
, source_p
, &me
, "*** Banned (DNS blacklist)");
447 return CLIENT_EXITED
;
451 /* valid user name check */
453 if(!valid_username(source_p
->username
))
455 sendto_realops_snomask(SNO_REJ
, L_ALL
,
456 "Invalid username: %s (%s@%s)",
457 source_p
->name
, source_p
->username
, source_p
->host
);
458 ServerStats
->is_ref
++;
459 sendto_one_notice(source_p
, ":*** Your username is invalid. Please make sure that your username contains "
460 "only alphanumeric characters.");
461 rb_sprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
462 exit_client(client_p
, source_p
, &me
, tmpstr2
);
463 return (CLIENT_EXITED
);
466 /* end of valid user name check */
468 /* Store original hostname -- jilles */
469 strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
471 /* Spoof user@host */
472 if(*source_p
->preClient
->spoofuser
)
473 strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
474 if(*source_p
->preClient
->spoofhost
)
476 strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
477 if (irccmp(source_p
->host
, source_p
->orighost
))
478 SetDynSpoof(source_p
);
481 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
& ~orphaned_umodes
;
483 call_hook(h_new_local_user
, source_p
);
485 /* If they have died in send_* or were thrown out by the
486 * new_local_user hook don't do anything. */
487 if(IsAnyDead(source_p
))
488 return CLIENT_EXITED
;
490 /* To avoid inconsistencies, do not abort the registration
491 * starting from this point -- jilles
493 inetntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
495 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
496 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
497 source_p
->name
, source_p
->username
, source_p
->orighost
,
498 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
499 get_client_class(source_p
), source_p
->info
);
501 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
502 "CLICONN %s %s %s %s %s %s 0 %s",
503 source_p
->name
, source_p
->username
, source_p
->orighost
,
504 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
505 get_client_class(source_p
),
506 /* mirc can sometimes send ips here */
507 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
510 add_to_hostname_hash(source_p
->orighost
, source_p
);
512 /* Allocate a UID if it was not previously allocated.
513 * If this already occured, it was probably during SASL auth...
517 strcpy(source_p
->id
, generate_uid());
518 add_to_id_hash(source_p
->id
, source_p
);
521 if (source_p
->umodes
& UMODE_INVISIBLE
)
524 s_assert(!IsClient(source_p
));
525 del_unknown_ip(source_p
);
526 rb_dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
529 source_p
->servptr
= &me
;
530 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
532 /* Increment our total user count here */
533 if(++Count
.total
> Count
.max_tot
)
534 Count
.max_tot
= Count
.total
;
536 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
538 Count
.totalrestartcount
++;
540 s_assert(source_p
->localClient
!= NULL
);
542 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
544 Count
.max_loc
= rb_dlink_list_length(&lclient_list
);
545 if(!(Count
.max_loc
% 10))
546 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
547 "New Max Local Clients: %d", Count
.max_loc
);
550 /* they get a reduced limit */
551 if(find_tgchange(source_p
->sockhost
))
552 USED_TARGETS(source_p
) = 6;
554 monitor_signon(source_p
);
555 user_welcome(source_p
);
557 free_pre_client(source_p
);
559 return (introduce_client(client_p
, source_p
, user
, source_p
->name
, 1));
567 * side effects - This common function introduces a client to the rest
568 * of the net, either from a local client connect or
569 * from a remote connect.
572 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
574 static char ubuf
[12];
575 struct Client
*identifyservice_p
;
577 hook_data_umode_changed hdata
;
578 hook_data_client hdata2
;
580 if(MyClient(source_p
))
581 send_umode(source_p
, source_p
, 0, 0, ubuf
);
583 send_umode(NULL
, source_p
, 0, 0, ubuf
);
591 /* if it has an ID, introduce it with its id to TS6 servers,
592 * otherwise introduce it normally to all.
596 char sockhost
[HOSTLEN
];
597 if(source_p
->sockhost
[0] == ':')
601 strlcat(sockhost
, source_p
->sockhost
, sizeof(sockhost
));
603 strcpy(sockhost
, source_p
->sockhost
);
606 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
607 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
608 source_p
->servptr
->id
, nick
,
609 source_p
->hopcount
+ 1,
610 (long) source_p
->tsinfo
, ubuf
,
611 source_p
->username
, source_p
->host
,
612 IsIPSpoof(source_p
) ? "0" : sockhost
,
614 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
615 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
618 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
619 ":%s UID %s %d %ld %s %s %s %s %s :%s",
620 source_p
->servptr
->id
, nick
,
621 source_p
->hopcount
+ 1,
622 (long) source_p
->tsinfo
, ubuf
,
623 source_p
->username
, source_p
->host
,
624 IsIPSpoof(source_p
) ? "0" : sockhost
,
625 source_p
->id
, source_p
->info
);
627 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
,
628 "NICK %s %d %ld %s %s %s %s :%s",
629 nick
, source_p
->hopcount
+ 1,
630 (long) source_p
->tsinfo
,
631 ubuf
, source_p
->username
, source_p
->host
,
632 source_p
->servptr
->name
, source_p
->info
);
635 sendto_server(client_p
, NULL
, NOCAPS
, NOCAPS
,
636 "NICK %s %d %ld %s %s %s %s :%s",
637 nick
, source_p
->hopcount
+ 1,
638 (long) source_p
->tsinfo
,
639 ubuf
, source_p
->username
, source_p
->host
,
640 source_p
->servptr
->name
, source_p
->info
);
642 if (IsDynSpoof(source_p
))
644 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
645 use_id(source_p
), source_p
->orighost
);
646 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s ENCAP * REALHOST %s",
647 source_p
->name
, source_p
->orighost
);
649 if (!EmptyString(source_p
->user
->suser
))
651 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
652 use_id(source_p
), source_p
->user
->suser
);
653 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s ENCAP * LOGIN %s",
654 source_p
->name
, source_p
->user
->suser
);
657 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
659 if (ConfigFileEntry
.identifyservice
[0] != '\0' &&
660 ConfigFileEntry
.identifycommand
[0] != '\0')
662 /* use user@server */
663 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
665 identifyservice_p
= find_named_client(p
+ 1);
667 identifyservice_p
= NULL
;
668 if (identifyservice_p
!= NULL
)
669 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
670 get_id(source_p
, identifyservice_p
),
671 ConfigFileEntry
.identifyservice
,
672 ConfigFileEntry
.identifycommand
,
673 source_p
->localClient
->passwd
);
675 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
676 rb_free(source_p
->localClient
->passwd
);
677 source_p
->localClient
->passwd
= NULL
;
680 /* let modules providing usermodes know that we've got a new user,
681 * why is this here? -- well, some modules need to be able to send out new
682 * information about a client, so this was the best place to do it
685 hdata
.client
= source_p
;
687 hdata
.oldsnomask
= 0;
688 call_hook(h_umode_changed
, &hdata
);
690 /* On the other hand, some modules need to know when a client is
691 * being introduced, period.
694 hdata2
.client
= client_p
;
695 hdata2
.target
= source_p
;
696 call_hook(h_introduce_client
, &hdata2
);
702 * valid_hostname - check hostname for validity
704 * Inputs - pointer to user
705 * Output - YES if valid, NO if not
706 * Side effects - NONE
708 * NOTE: this doesn't allow a hostname to begin with a dot and
709 * will not allow more dots than chars.
712 valid_hostname(const char *hostname
)
714 const char *p
= hostname
;
722 if('.' == *p
|| ':' == *p
)
729 if(*p
== '.' || *p
== ':')
741 * valid_username - check username for validity
743 * Inputs - pointer to user
744 * Output - YES if valid, NO if not
745 * Side effects - NONE
747 * Absolutely always reject any '*' '!' '?' '@' in an user name
748 * reject any odd control characters names.
749 * Allow '.' in username to allow for "first.last"
753 valid_username(const char *username
)
756 const char *p
= username
;
766 /* reject usernames that don't start with an alphanum
767 * i.e. reject jokers who have '-@somehost' or '.@somehost'
768 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
775 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
778 if(dots
> ConfigFileEntry
.dots_in_ident
)
780 if(!IsUserChar(p
[1]))
783 else if(!IsUserChar(*p
))
789 /* report_and_set_user_flags
791 * Inputs - pointer to source_p
792 * - pointer to aconf for this user
795 * Report to user any special flags they are getting, and set them.
799 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
801 /* If this user is being spoofed, tell them so */
802 if(IsConfDoSpoofIp(aconf
))
804 sendto_one_notice(source_p
, ":*** Spoofing your IP. congrats.");
807 /* If this user is in the exception class, Set it "E lined" */
808 if(IsConfExemptKline(aconf
))
810 SetExemptKline(source_p
);
811 sendto_one_notice(source_p
, ":*** You are exempt from K/G/X lines. congrats.");
814 if(IsConfExemptGline(aconf
))
816 SetExemptGline(source_p
);
818 /* dont send both a kline and gline exempt notice */
819 if(!IsConfExemptKline(aconf
))
820 sendto_one_notice(source_p
, ":*** You are exempt from G lines.");
823 if(IsConfExemptDNSBL(aconf
))
824 /* kline exempt implies this, don't send both */
825 if(!IsConfExemptKline(aconf
))
826 sendto_one_notice(source_p
, ":*** You are exempt from DNS blacklists.");
828 /* If this user is exempt from user limits set it F lined" */
829 if(IsConfExemptLimits(aconf
))
831 sendto_one_notice(source_p
, ":*** You are exempt from user limits. congrats.");
834 if(IsConfExemptFlood(aconf
))
836 SetExemptFlood(source_p
);
837 sendto_one_notice(source_p
, ":*** You are exempt from flood limits.");
840 if(IsConfExemptSpambot(aconf
))
842 SetExemptSpambot(source_p
);
843 sendto_one_notice(source_p
, ":*** You are exempt from spambot checks.");
846 if(IsConfExemptJupe(aconf
))
848 SetExemptJupe(source_p
);
849 sendto_one_notice(source_p
, ":*** You are exempt from juped channel warnings.");
852 if(IsConfExemptResv(aconf
))
854 SetExemptResv(source_p
);
855 sendto_one_notice(source_p
, ":*** You are exempt from resvs.");
858 if(IsConfExemptShide(aconf
))
860 SetExemptShide(source_p
);
861 sendto_one_notice(source_p
, ":*** You are exempt from serverhiding.");
866 * user_mode - set get current users mode
868 * m_umode() added 15/10/91 By Darren Reed.
870 * parv[1] - username to change mode for
871 * parv[2] - modes to change
874 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
880 struct Client
*target_p
;
882 int badflag
= NO
; /* Only send one bad flag notice */
883 int showsnomask
= NO
;
884 unsigned int setsnomask
;
886 hook_data_umode_changed hdata
;
892 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
896 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
898 if(MyConnect(source_p
))
899 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
900 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
904 /* Dont know why these were commented out..
905 * put them back using new sendto() funcs
908 if(IsServer(source_p
))
910 sendto_realops_snomask(SNO_GENERAL
, L_ADMIN
,
911 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
915 if(source_p
!= target_p
|| target_p
->from
!= source_p
->from
)
917 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
926 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
927 if (source_p
->umodes
& user_modes
[i
])
931 sendto_one_numeric(source_p
, RPL_UMODEIS
, form_str(RPL_UMODEIS
), buf
);
933 if (source_p
->snomask
!= 0)
934 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
935 construct_snobuf(source_p
->snomask
));
940 /* find flags already set for user */
941 setflags
= source_p
->umodes
;
942 setsnomask
= source_p
->snomask
;
945 * parse mode change string(s)
947 for (pm
= parv
[2]; *pm
; pm
++)
960 if(IsServer(client_p
) && !IsOper(source_p
))
964 rb_dlinkAddAlloc(source_p
, &oper_list
);
969 /* Only decrement the oper counts if an oper to begin with
970 * found by Pat Szuta, Perly , perly@xnet.com
973 if(!IsOper(source_p
))
980 if(MyConnect(source_p
))
982 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
983 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
985 source_p
->snomask
= 0;
988 source_p
->flags2
&= ~OPER_FLAGS
;
990 rb_free(source_p
->localClient
->opername
);
991 source_p
->localClient
->opername
= NULL
;
993 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
996 rb_dlinkFindDestroy(source_p
, &oper_list
);
1000 /* we may not get these,
1001 * but they shouldnt be in default
1004 /* can only be set on burst */
1013 if (MyConnect(source_p
))
1015 if(!IsOper(source_p
)
1016 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
1018 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1023 if(what
== MODE_ADD
)
1026 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1028 source_p
->snomask
|= SNO_GENERAL
;
1031 source_p
->snomask
= 0;
1032 if (source_p
->snomask
!= 0)
1033 source_p
->umodes
|= UMODE_SERVNOTICE
;
1035 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1040 if (MyConnect(source_p
) && *pm
== 'Q' && !ConfigChannel
.use_forward
) {
1045 if((flag
= user_modes
[(unsigned char) *pm
]))
1047 if(MyConnect(source_p
)
1048 && ((!IsOper(source_p
)
1049 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1050 || (orphaned_umodes
& flag
)))
1052 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1057 if(what
== MODE_ADD
)
1058 source_p
->umodes
|= flag
;
1060 source_p
->umodes
&= ~flag
;
1065 if(MyConnect(source_p
))
1072 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1074 if(MyClient(source_p
) && (source_p
->snomask
& SNO_NCHANGE
) && !IsOperN(source_p
))
1076 sendto_one_notice(source_p
, ":*** You need oper and nick_changes flag for +s +n");
1077 source_p
->snomask
&= ~SNO_NCHANGE
; /* only tcm's really need this */
1080 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1082 sendto_one_notice(source_p
, ":*** You need oper and operwall flag for +z");
1083 source_p
->umodes
&= ~UMODE_OPERWALL
;
1086 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1087 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1089 sendto_one_notice(source_p
, ":*** You need oper and admin flag for +a");
1090 source_p
->umodes
&= ~UMODE_ADMIN
;
1093 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1094 hdata
.client
= source_p
;
1095 hdata
.oldumodes
= setflags
;
1096 hdata
.oldsnomask
= setsnomask
;
1097 call_hook(h_umode_changed
, &hdata
);
1099 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1101 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1104 * compare new flags with old flags and send string which
1105 * will cause servers to update correctly.
1107 send_umode_out(client_p
, source_p
, setflags
);
1108 if (showsnomask
&& MyConnect(source_p
))
1109 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1110 construct_snobuf(source_p
->snomask
));
1116 * send the MODE string for user (user) to connection client_p
1120 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, int sendmask
, char *umode_buf
)
1128 * build a string in umode_buf to represent the change in the user's
1129 * mode between the new (source_p->flag) and 'old'.
1134 for (i
= 0; i
< 128; i
++)
1136 flag
= user_modes
[i
];
1138 if((flag
& old
) && !(source_p
->umodes
& flag
))
1140 if(what
== MODE_DEL
)
1149 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1151 if(what
== MODE_ADD
)
1163 if(*umode_buf
&& client_p
)
1164 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1175 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1177 struct Client
*target_p
;
1181 send_umode(NULL
, source_p
, old
, 0, buf
);
1183 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1185 target_p
= ptr
->data
;
1187 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1189 sendto_one(target_p
, ":%s MODE %s :%s",
1190 get_id(source_p
, target_p
),
1191 get_id(source_p
, target_p
), buf
);
1195 if(client_p
&& MyClient(client_p
))
1196 send_umode(client_p
, source_p
, old
, 0, buf
);
1202 * inputs - client pointer to client to welcome
1207 user_welcome(struct Client
*source_p
)
1209 sendto_one_numeric(source_p
, RPL_WELCOME
, form_str(RPL_WELCOME
), ServerInfo
.network_name
, source_p
->name
);
1210 sendto_one_numeric(source_p
, RPL_YOURHOST
, form_str(RPL_YOURHOST
),
1211 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1212 sendto_one_numeric(source_p
, RPL_CREATED
, form_str(RPL_CREATED
), creation
);
1213 sendto_one_numeric(source_p
, RPL_MYINFO
, form_str(RPL_MYINFO
), me
.name
, ircd_version
, umodebuf
);
1215 show_isupport(source_p
);
1217 show_lusers(source_p
);
1219 if(ConfigFileEntry
.short_motd
)
1221 sendto_one_notice(source_p
, ":*** Notice -- motd was last changed at %s", user_motd_changed
);
1222 sendto_one_notice(source_p
, ":*** Notice -- Please read the motd if you haven't read it");
1224 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1225 me
.name
, source_p
->name
, me
.name
);
1227 sendto_one(source_p
, form_str(RPL_MOTD
),
1228 me
.name
, source_p
->name
, "*** This is the short motd ***");
1230 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1233 send_user_motd(source_p
);
1238 * inputs - pointer to given client to oper
1239 * - pointer to ConfItem to use
1241 * side effects - opers up source_p using aconf for reference
1244 oper_up(struct Client
*source_p
, struct oper_conf
*oper_p
)
1246 unsigned int old
= source_p
->umodes
, oldsnomask
= source_p
->snomask
;
1247 hook_data_umode_changed hdata
;
1252 source_p
->umodes
|= oper_p
->umodes
;
1253 else if(ConfigFileEntry
.oper_umodes
)
1254 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1256 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1258 if (oper_p
->snomask
)
1260 source_p
->snomask
|= oper_p
->snomask
;
1261 source_p
->umodes
|= UMODE_SERVNOTICE
;
1263 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1265 /* Only apply these if +s is already set -- jilles */
1266 if (ConfigFileEntry
.oper_snomask
)
1267 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1269 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1274 SetExemptKline(source_p
);
1276 source_p
->flags2
|= oper_p
->flags
;
1277 source_p
->localClient
->opername
= rb_strdup(oper_p
->name
);
1279 rb_dlinkAddAlloc(source_p
, &local_oper_list
);
1280 rb_dlinkAddAlloc(source_p
, &oper_list
);
1282 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1283 source_p
->umodes
|= UMODE_ADMIN
;
1284 if(!IsOperN(source_p
))
1285 source_p
->snomask
&= ~SNO_NCHANGE
;
1286 if(!IsOperOperwall(source_p
))
1287 source_p
->umodes
&= ~UMODE_OPERWALL
;
1288 hdata
.client
= source_p
;
1289 hdata
.oldumodes
= old
;
1290 hdata
.oldsnomask
= oldsnomask
;
1291 call_hook(h_umode_changed
, &hdata
);
1293 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1294 "%s (%s@%s) is now an operator", source_p
->name
,
1295 source_p
->username
, source_p
->host
);
1296 if(!(old
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1298 if((old
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1300 send_umode_out(source_p
, source_p
, old
);
1301 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1302 construct_snobuf(source_p
->snomask
));
1303 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1304 sendto_one_notice(source_p
, ":*** Oper privs are %s", get_oper_privs(oper_p
->flags
));
1305 send_oper_motd(source_p
);
1314 * outputs - an available umode bitmask or
1315 * 0 if no umodes are available
1316 * side effects - NONE
1319 find_umode_slot(void)
1321 unsigned int all_umodes
= 0, my_umode
= 0, i
;
1323 for (i
= 0; i
< 128; i
++)
1324 all_umodes
|= user_modes
[i
];
1326 for (my_umode
= 1; my_umode
&& (all_umodes
& my_umode
);
1333 construct_umodebuf(void)
1336 char *ptr
= umodebuf
;
1337 static int prev_user_modes
[128];
1341 for (i
= 0; i
< 128; i
++)
1343 if (prev_user_modes
[i
] != 0 && prev_user_modes
[i
] != user_modes
[i
])
1345 if (user_modes
[i
] == 0)
1347 orphaned_umodes
|= prev_user_modes
[i
];
1348 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Umode +%c is now orphaned", i
);
1352 orphaned_umodes
&= ~prev_user_modes
[i
];
1353 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Orphaned umode +%c is picked up by module", i
);
1355 user_modes
[i
] = prev_user_modes
[i
];
1358 prev_user_modes
[i
] = user_modes
[i
];
1367 change_nick_user_host(struct Client
*target_p
, const char *nick
, const char *user
,
1368 const char *host
, int newts
, char *format
, ...)
1371 struct Channel
*chptr
;
1372 struct membership
*mscptr
;
1373 int changed
= irccmp(target_p
->name
, nick
);
1374 int changed_case
= strcmp(target_p
->name
, nick
);
1375 int do_qjm
= irccmp(target_p
->username
, user
) || irccmp(target_p
->host
, host
);
1376 char mode
[10], modeval
[NICKLEN
* 2 + 2], reason
[256], *mptr
;
1383 target_p
->tsinfo
= newts
;
1384 monitor_signoff(target_p
);
1386 invalidate_bancache_user(target_p
);
1390 va_start(ap
, format
);
1391 vsnprintf(reason
, 255, format
, ap
);
1394 sendto_common_channels_local_butone(target_p
, ":%s!%s@%s QUIT :%s",
1395 target_p
->name
, target_p
->username
, target_p
->host
,
1398 RB_DLINK_FOREACH(ptr
, target_p
->user
->channel
.head
)
1401 chptr
= mscptr
->chptr
;
1404 if(is_chanop(mscptr
))
1407 strcat(modeval
, nick
);
1408 strcat(modeval
, " ");
1411 if(is_voiced(mscptr
))
1414 strcat(modeval
, nick
);
1419 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
1420 nick
, user
, host
, chptr
->chname
);
1422 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
,
1423 ":%s MODE %s +%s %s",
1424 target_p
->servptr
->name
,
1425 chptr
->chname
, mode
, modeval
);
1430 if(MyClient(target_p
) && changed_case
)
1431 sendto_one(target_p
, ":%s!%s@%s NICK %s",
1432 target_p
->name
, target_p
->username
, target_p
->host
, nick
);
1434 else if(changed_case
)
1436 sendto_common_channels_local(target_p
, ":%s!%s@%s NICK :%s",
1437 target_p
->name
, target_p
->username
,
1438 target_p
->host
, nick
);
1441 strlcpy(target_p
->username
, user
, sizeof target_p
->username
);
1442 strlcpy(target_p
->host
, host
, sizeof target_p
->host
);
1445 add_history(target_p
, 1);
1447 del_from_client_hash(target_p
->name
, target_p
);
1448 strlcpy(target_p
->name
, nick
, NICKLEN
);
1449 add_to_client_hash(target_p
->name
, target_p
);
1453 monitor_signon(target_p
);
1454 del_all_accepts(target_p
);