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 $
40 #include "s_newconf.h"
46 #include "supported.h"
54 #include "blacklist.h"
55 #include "substitution.h"
59 static void report_and_set_user_flags(struct Client
*, struct ConfItem
*);
60 void user_welcome(struct Client
*source_p
);
64 static int orphaned_umodes
= 0;
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 */
96 UMODE_SSLCLIENT
, /* Z */
97 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
104 UMODE_CALLERID
, /* g */
106 UMODE_INVISIBLE
, /* i */
109 UMODE_LOCOPS
, /* l */
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 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)MaxClientCount
)
147 MaxClientCount
= rb_dlink_list_length(&lclient_list
);
149 if((rb_dlink_list_length(&lclient_list
) + rb_dlink_list_length(&serv_list
)) >
150 (unsigned long)MaxConnectionCount
)
151 MaxConnectionCount
= rb_dlink_list_length(&lclient_list
) +
152 rb_dlink_list_length(&serv_list
);
154 sendto_one_numeric(source_p
, RPL_LUSERCLIENT
, form_str(RPL_LUSERCLIENT
),
155 (Count
.total
- Count
.invisi
),
157 (int)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
),
162 (int)rb_dlink_list_length(&oper_list
));
164 if(rb_dlink_list_length(&unknown_list
) > 0)
165 sendto_one_numeric(source_p
, RPL_LUSERUNKNOWN
,
166 form_str(RPL_LUSERUNKNOWN
),
167 (int)rb_dlink_list_length(&unknown_list
));
169 if(rb_dlink_list_length(&global_channel_list
) > 0)
170 sendto_one_numeric(source_p
, RPL_LUSERCHANNELS
,
171 form_str(RPL_LUSERCHANNELS
),
172 rb_dlink_list_length(&global_channel_list
));
174 sendto_one_numeric(source_p
, RPL_LUSERME
, form_str(RPL_LUSERME
),
175 (int)rb_dlink_list_length(&lclient_list
),
176 (int)rb_dlink_list_length(&serv_list
));
178 sendto_one_numeric(source_p
, RPL_LOCALUSERS
,
179 form_str(RPL_LOCALUSERS
),
180 (int)rb_dlink_list_length(&lclient_list
),
182 (int)rb_dlink_list_length(&lclient_list
),
185 sendto_one_numeric(source_p
, RPL_GLOBALUSERS
, form_str(RPL_GLOBALUSERS
),
186 Count
.total
, Count
.max_tot
,
187 Count
.total
, Count
.max_tot
);
189 sendto_one_numeric(source_p
, RPL_STATSCONN
,
190 form_str(RPL_STATSCONN
),
191 MaxConnectionCount
, MaxClientCount
,
192 Count
.totalrestartcount
);
198 ** register_local_user
199 ** This function is called when both NICK and USER messages
200 ** have been accepted for the client, in whatever order. Only
201 ** after this, is the USER message propagated.
203 ** NICK's must be propagated at once when received, although
204 ** it would be better to delay them too until full info is
205 ** available. Doing it is not so simple though, would have
206 ** to implement the following:
208 ** (actually it has been implemented already for a while) -orabidoo
210 ** 1) user telnets in and gives only "NICK foobar" and waits
211 ** 2) another user far away logs in normally with the nick
212 ** "foobar" (quite legal, as this server didn't propagate
214 ** 3) now this server gets nick "foobar" from outside, but
215 ** has alread the same defined locally. Current server
216 ** would just issue "KILL foobar" to clean out dups. But,
217 ** this is not fair. It should actually request another
218 ** nick from local user or kill him/her...
222 register_local_user(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
224 struct ConfItem
*aconf
, *xconf
;
225 struct User
*user
= source_p
->user
;
226 char tmpstr2
[IRCD_BUFSIZE
];
227 char ipaddr
[HOSTIPLEN
];
228 char myusername
[USERLEN
+1];
231 s_assert(NULL
!= source_p
);
232 s_assert(MyConnect(source_p
));
233 s_assert(source_p
->username
!= username
);
238 if(IsAnyDead(source_p
))
241 if(ConfigFileEntry
.ping_cookie
)
243 if(!(source_p
->flags
& FLAGS_PINGSENT
) && source_p
->localClient
->random_ping
== 0)
245 source_p
->localClient
->random_ping
= (unsigned long) (rand() * rand()) << 1;
246 sendto_one(source_p
, "PING :%08lX",
247 (unsigned long) source_p
->localClient
->random_ping
);
248 source_p
->flags
|= FLAGS_PINGSENT
;
251 if(!(source_p
->flags
& FLAGS_PING_COOKIE
))
257 /* hasnt finished client cap negotiation */
258 if(source_p
->flags
& FLAGS_CLICAP
)
261 /* still has DNSbls to validate against */
262 if(rb_dlink_list_length(&source_p
->preClient
->dnsbl_queries
) > 0)
265 client_p
->localClient
->last
= rb_current_time();
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 char note
[NICKLEN
+ 10];
294 del_from_client_hash(source_p
->name
, source_p
);
295 rb_strlcpy(source_p
->name
, source_p
->preClient
->spoofnick
, NICKLEN
+ 1);
296 add_to_client_hash(source_p
->name
, source_p
);
298 rb_snprintf(note
, NICKLEN
+ 10, "Nick: %s", source_p
->name
);
299 rb_note(source_p
->localClient
->F
, note
);
302 if(!valid_hostname(source_p
->host
))
304 sendto_one_notice(source_p
, ":*** Notice -- You have an illegal character in your hostname");
306 rb_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(IsConfSSLNeeded(aconf
) && !IsSSL(source_p
))
320 ServerStats
.is_ref
++;
321 sendto_one_notice(source_p
, ":*** Notice -- You need to use SSL/TLS to use this server");
322 exit_client(client_p
, source_p
, &me
, "Use SSL/TLS");
323 return (CLIENT_EXITED
);
326 if(!IsGotId(source_p
))
331 if(IsNeedIdentd(aconf
))
333 ServerStats
.is_ref
++;
334 sendto_one_notice(source_p
, ":*** Notice -- You need to install identd to use this server");
335 exit_client(client_p
, source_p
, &me
, "Install identd");
336 return (CLIENT_EXITED
);
339 /* dont replace username if its supposed to be spoofed --fl */
340 if(!IsConfDoSpoofIp(aconf
) || !strchr(aconf
->info
.name
, '@'))
344 if(!IsNoTilde(aconf
))
345 source_p
->username
[i
++] = '~';
347 while (*p
&& i
< USERLEN
)
350 source_p
->username
[i
++] = *p
;
354 source_p
->username
[i
] = '\0';
358 if(IsNeedSasl(aconf
) && !*user
->suser
)
360 ServerStats
.is_ref
++;
361 sendto_one_notice(source_p
, ":*** Notice -- You need to identify via SASL to use this server");
362 exit_client(client_p
, source_p
, &me
, "SASL access only");
363 return (CLIENT_EXITED
);
367 if(!EmptyString(aconf
->passwd
))
371 if(EmptyString(source_p
->localClient
->passwd
))
373 else if(IsConfEncrypted(aconf
))
374 encr
= rb_crypt(source_p
->localClient
->passwd
, aconf
->passwd
);
376 encr
= source_p
->localClient
->passwd
;
378 if(encr
== NULL
|| strcmp(encr
, aconf
->passwd
))
380 ServerStats
.is_ref
++;
381 sendto_one(source_p
, form_str(ERR_PASSWDMISMATCH
), me
.name
, source_p
->name
);
382 exit_client(client_p
, source_p
, &me
, "Bad Password");
383 return (CLIENT_EXITED
);
386 /* clear password only if used now, otherwise send it
387 * to services -- jilles */
388 if(source_p
->localClient
->passwd
)
390 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
391 rb_free(source_p
->localClient
->passwd
);
392 source_p
->localClient
->passwd
= NULL
;
396 /* report if user has &^>= etc. and set flags as needed in source_p */
397 report_and_set_user_flags(source_p
, aconf
);
401 * We want to be able to have servers and F-line clients
402 * connect, so save room for "buffer" connections.
403 * Smaller servers may want to decrease this, and it should
404 * probably be just a percentage of the MAXCLIENTS...
407 /* Except "F:" clients */
408 if(rb_dlink_list_length(&lclient_list
) >=
409 (unsigned long)GlobalSetOptions
.maxclients
&& !IsConfExemptLimits(aconf
))
411 sendto_realops_snomask(SNO_FULL
, L_ALL
,
412 "Too many clients, rejecting %s[%s].", source_p
->name
, source_p
->host
);
414 ServerStats
.is_ref
++;
415 exit_client(client_p
, source_p
, &me
, "Sorry, server is full - try later");
416 return (CLIENT_EXITED
);
419 /* kline exemption extends to xline too */
420 if(!IsExemptKline(source_p
) &&
421 (xconf
= find_xline(source_p
->info
, 1)) != NULL
)
423 ServerStats
.is_ref
++;
424 add_reject(source_p
, xconf
->host
, NULL
);
425 exit_client(client_p
, source_p
, &me
, "Bad user info");
426 return CLIENT_EXITED
;
430 if (source_p
->preClient
->dnsbl_listed
!= NULL
)
432 if (IsExemptKline(source_p
) || IsConfExemptDNSBL(aconf
))
433 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s, but you are exempt",
434 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
437 sendto_realops_snomask(SNO_REJ
, L_NETWIDE
,
438 "DNSBL listed: %s!%s@%s{%s} %s (%s)", source_p
->name
,
439 source_p
->username
, source_p
->host
, source_p
->sockhost
, source_p
->info
,
440 source_p
->preClient
->dnsbl_listed
->host
);
442 rb_dlink_list varlist
= { NULL
, NULL
, 0 };
444 substitution_append_var(&varlist
, "nick", source_p
->name
);
445 substitution_append_var(&varlist
, "ip", source_p
->sockhost
);
446 substitution_append_var(&varlist
, "host", source_p
->host
);
447 substitution_append_var(&varlist
, "dnsbl-host", source_p
->preClient
->dnsbl_listed
->host
);
448 substitution_append_var(&varlist
, "network-name", ServerInfo
.network_name
);
450 ServerStats
.is_ref
++;
452 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
453 me
.name
, source_p
->name
,
454 substitution_parse(source_p
->preClient
->dnsbl_listed
->reject_reason
, &varlist
));
456 substitution_free(&varlist
);
458 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s",
459 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
460 source_p
->preClient
->dnsbl_listed
->hits
++;
461 add_reject(source_p
, NULL
, NULL
);
462 exit_client(client_p
, source_p
, &me
, "*** Banned (DNS blacklist)");
463 return CLIENT_EXITED
;
467 /* valid user name check */
469 if(!valid_username(source_p
->username
))
471 sendto_realops_snomask(SNO_REJ
, L_ALL
,
472 "Invalid username: %s (%s@%s)",
473 source_p
->name
, source_p
->username
, source_p
->host
);
474 ServerStats
.is_ref
++;
475 sendto_one_notice(source_p
, ":*** Your username is invalid. Please make sure that your username contains "
476 "only alphanumeric characters.");
477 rb_sprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
478 exit_client(client_p
, source_p
, &me
, tmpstr2
);
479 return (CLIENT_EXITED
);
482 /* end of valid user name check */
484 /* Store original hostname -- jilles */
485 rb_strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
487 /* Spoof user@host */
488 if(*source_p
->preClient
->spoofuser
)
489 rb_strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
490 if(*source_p
->preClient
->spoofhost
)
492 rb_strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
493 if (irccmp(source_p
->host
, source_p
->orighost
))
494 SetDynSpoof(source_p
);
497 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
& ~orphaned_umodes
;
499 call_hook(h_new_local_user
, source_p
);
501 /* If they have died in send_* or were thrown out by the
502 * new_local_user hook don't do anything. */
503 if(IsAnyDead(source_p
))
504 return CLIENT_EXITED
;
506 /* To avoid inconsistencies, do not abort the registration
507 * starting from this point -- jilles
509 rb_inet_ntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
511 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
512 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
513 source_p
->name
, source_p
->username
, source_p
->orighost
,
514 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
515 get_client_class(source_p
), source_p
->info
);
517 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
518 "CLICONN %s %s %s %s %s %s 0 %s",
519 source_p
->name
, source_p
->username
, source_p
->orighost
,
520 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
521 get_client_class(source_p
),
522 /* mirc can sometimes send ips here */
523 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
526 add_to_hostname_hash(source_p
->orighost
, source_p
);
528 /* Allocate a UID if it was not previously allocated.
529 * If this already occured, it was probably during SASL auth...
533 strcpy(source_p
->id
, generate_uid());
534 add_to_id_hash(source_p
->id
, source_p
);
538 source_p
->umodes
|= UMODE_SSLCLIENT
;
540 if (source_p
->umodes
& UMODE_INVISIBLE
)
543 s_assert(!IsClient(source_p
));
544 rb_dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
547 source_p
->servptr
= &me
;
548 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
550 /* Increment our total user count here */
551 if(++Count
.total
> Count
.max_tot
)
552 Count
.max_tot
= Count
.total
;
554 Count
.totalrestartcount
++;
556 s_assert(source_p
->localClient
!= NULL
);
558 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
560 Count
.max_loc
= rb_dlink_list_length(&lclient_list
);
561 if(!(Count
.max_loc
% 10))
562 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
563 "New Max Local Clients: %d", Count
.max_loc
);
566 /* they get a reduced limit */
567 if(find_tgchange(source_p
->sockhost
))
568 source_p
->localClient
->targets_free
= TGCHANGE_INITIAL_LOW
;
570 source_p
->localClient
->targets_free
= TGCHANGE_INITIAL
;
572 monitor_signon(source_p
);
573 user_welcome(source_p
);
575 free_pre_client(source_p
);
577 return (introduce_client(client_p
, source_p
, user
, source_p
->name
, 1));
585 * side effects - This common function introduces a client to the rest
586 * of the net, either from a local client connect or
587 * from a remote connect.
590 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
592 static char ubuf
[12];
593 struct Client
*identifyservice_p
;
595 hook_data_umode_changed hdata
;
596 hook_data_client hdata2
;
597 char sockhost
[HOSTLEN
];
599 if(MyClient(source_p
))
600 send_umode(source_p
, source_p
, 0, 0, ubuf
);
602 send_umode(NULL
, source_p
, 0, 0, ubuf
);
610 s_assert(has_id(source_p
));
612 if(source_p
->sockhost
[0] == ':')
616 rb_strlcat(sockhost
, source_p
->sockhost
, sizeof(sockhost
));
618 strcpy(sockhost
, source_p
->sockhost
);
621 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
622 ":%s EUID %s %d %ld %s %s %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
,
629 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
630 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
633 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
634 ":%s UID %s %d %ld %s %s %s %s %s :%s",
635 source_p
->servptr
->id
, nick
,
636 source_p
->hopcount
+ 1,
637 (long) source_p
->tsinfo
, ubuf
,
638 source_p
->username
, source_p
->host
,
639 IsIPSpoof(source_p
) ? "0" : sockhost
,
640 source_p
->id
, source_p
->info
);
642 if(!EmptyString(source_p
->certfp
))
643 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
644 ":%s ENCAP * CERTFP :%s",
645 use_id(source_p
), source_p
->certfp
);
647 if (IsDynSpoof(source_p
))
649 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
650 use_id(source_p
), source_p
->orighost
);
653 if (!EmptyString(source_p
->user
->suser
))
655 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
656 use_id(source_p
), source_p
->user
->suser
);
659 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
661 if (!EmptyString(ConfigFileEntry
.identifyservice
) &&
662 !EmptyString(ConfigFileEntry
.identifycommand
))
664 /* use user@server */
665 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
667 identifyservice_p
= find_named_client(p
+ 1);
669 identifyservice_p
= NULL
;
670 if (identifyservice_p
!= NULL
)
672 if (!EmptyString(source_p
->localClient
->auth_user
))
673 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s %s",
674 get_id(source_p
, identifyservice_p
),
675 ConfigFileEntry
.identifyservice
,
676 ConfigFileEntry
.identifycommand
,
677 source_p
->localClient
->auth_user
,
678 source_p
->localClient
->passwd
);
680 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
681 get_id(source_p
, identifyservice_p
),
682 ConfigFileEntry
.identifyservice
,
683 ConfigFileEntry
.identifycommand
,
684 source_p
->localClient
->passwd
);
687 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
688 rb_free(source_p
->localClient
->passwd
);
689 source_p
->localClient
->passwd
= NULL
;
692 /* let modules providing usermodes know that we've got a new user,
693 * why is this here? -- well, some modules need to be able to send out new
694 * information about a client, so this was the best place to do it
697 hdata
.client
= source_p
;
699 hdata
.oldsnomask
= 0;
700 call_hook(h_umode_changed
, &hdata
);
702 /* On the other hand, some modules need to know when a client is
703 * being introduced, period.
706 hdata2
.client
= client_p
;
707 hdata2
.target
= source_p
;
708 call_hook(h_introduce_client
, &hdata2
);
714 * valid_hostname - check hostname for validity
716 * Inputs - pointer to user
717 * Output - YES if valid, NO if not
718 * Side effects - NONE
720 * NOTE: this doesn't allow a hostname to begin with a dot and
721 * will not allow more dots than chars.
724 valid_hostname(const char *hostname
)
726 const char *p
= hostname
, *last_slash
= 0;
734 if('.' == *p
|| ':' == *p
|| '/' == *p
)
741 if(*p
== '.' || *p
== ':')
754 if(last_slash
&& IsDigit(last_slash
[1]))
761 * valid_username - check username for validity
763 * Inputs - pointer to user
764 * Output - YES if valid, NO if not
765 * Side effects - NONE
767 * Absolutely always reject any '*' '!' '?' '@' in an user name
768 * reject any odd control characters names.
769 * Allow '.' in username to allow for "first.last"
773 valid_username(const char *username
)
776 const char *p
= username
;
786 /* reject usernames that don't start with an alphanum
787 * i.e. reject jokers who have '-@somehost' or '.@somehost'
788 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
795 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
798 if(dots
> ConfigFileEntry
.dots_in_ident
)
800 if(!IsUserChar(p
[1]))
803 else if(!IsUserChar(*p
))
809 /* report_and_set_user_flags
811 * Inputs - pointer to source_p
812 * - pointer to aconf for this user
815 * Report to user any special flags they are getting, and set them.
819 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
821 /* If this user is being spoofed, tell them so */
822 if(IsConfDoSpoofIp(aconf
))
824 sendto_one_notice(source_p
, ":*** Spoofing your IP");
827 /* If this user is in the exception class, Set it "E lined" */
828 if(IsConfExemptKline(aconf
))
830 SetExemptKline(source_p
);
831 sendto_one_notice(source_p
, ":*** You are exempt from K/X lines");
834 if(IsConfExemptDNSBL(aconf
))
835 /* kline exempt implies this, don't send both */
836 if(!IsConfExemptKline(aconf
))
837 sendto_one_notice(source_p
, ":*** You are exempt from DNS blacklists");
839 /* If this user is exempt from user limits set it F lined" */
840 if(IsConfExemptLimits(aconf
))
842 sendto_one_notice(source_p
, ":*** You are exempt from user limits");
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 show_other_user_mode(struct Client
*source_p
, struct Client
*target_p
)
886 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
887 if (target_p
->umodes
& user_modes
[i
])
891 if (MyConnect(target_p
) && target_p
->snomask
!= 0)
892 sendto_one_notice(source_p
, ":Modes for %s are %s %s",
894 construct_snobuf(target_p
->snomask
));
896 sendto_one_notice(source_p
, ":Modes for %s are %s",
897 target_p
->name
, buf
);
901 * user_mode - set get current users mode
903 * m_umode() added 15/10/91 By Darren Reed.
904 * parv[1] - username to change mode for
905 * parv[2] - modes to change
908 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
914 struct Client
*target_p
;
916 int badflag
= NO
; /* Only send one bad flag notice */
917 int showsnomask
= NO
;
918 unsigned int setsnomask
;
920 hook_data_umode_changed hdata
;
926 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
930 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
932 if(MyConnect(source_p
))
933 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
934 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
938 /* Dont know why these were commented out..
939 * put them back using new sendto() funcs
942 if(IsServer(source_p
))
944 sendto_realops_snomask(SNO_GENERAL
, L_ADMIN
,
945 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
949 if(source_p
!= target_p
)
951 if (MyOper(source_p
) && parc
< 3)
952 show_other_user_mode(source_p
, target_p
);
954 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
963 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
964 if (source_p
->umodes
& user_modes
[i
])
968 sendto_one_numeric(source_p
, RPL_UMODEIS
, form_str(RPL_UMODEIS
), buf
);
970 if (source_p
->snomask
!= 0)
971 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
972 construct_snobuf(source_p
->snomask
));
977 /* find flags already set for user */
978 setflags
= source_p
->umodes
;
979 setsnomask
= source_p
->snomask
;
982 * parse mode change string(s)
984 for (pm
= parv
[2]; *pm
; pm
++)
997 if(IsServer(client_p
) && !IsOper(source_p
))
1001 rb_dlinkAddAlloc(source_p
, &oper_list
);
1006 /* Only decrement the oper counts if an oper to begin with
1007 * found by Pat Szuta, Perly , perly@xnet.com
1010 if(!IsOper(source_p
))
1013 ClearOper(source_p
);
1017 if(MyConnect(source_p
))
1019 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
1020 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
1022 source_p
->snomask
= 0;
1025 source_p
->flags2
&= ~OPER_FLAGS
;
1027 rb_free(source_p
->localClient
->opername
);
1028 source_p
->localClient
->opername
= NULL
;
1030 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1031 privilegeset_unref(source_p
->localClient
->privset
);
1032 source_p
->localClient
->privset
= NULL
;
1035 rb_dlinkFindDestroy(source_p
, &oper_list
);
1039 /* we may not get these,
1040 * but they shouldnt be in default
1043 /* can only be set on burst */
1053 if (MyConnect(source_p
))
1055 if(!IsOper(source_p
)
1056 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
1058 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1063 if(what
== MODE_ADD
)
1066 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1068 source_p
->snomask
|= SNO_GENERAL
;
1071 source_p
->snomask
= 0;
1072 if (source_p
->snomask
!= 0)
1073 source_p
->umodes
|= UMODE_SERVNOTICE
;
1075 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1080 if (MyConnect(source_p
) && *pm
== 'Q' && !ConfigChannel
.use_forward
)
1086 if((flag
= user_modes
[(unsigned char) *pm
]))
1088 if(MyConnect(source_p
)
1089 && ((!IsOper(source_p
)
1090 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1091 || (orphaned_umodes
& flag
)))
1093 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1098 if(what
== MODE_ADD
)
1099 source_p
->umodes
|= flag
;
1101 source_p
->umodes
&= ~flag
;
1106 if(MyConnect(source_p
))
1113 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1115 if(MyClient(source_p
) && (source_p
->snomask
& SNO_NCHANGE
) && !IsOperN(source_p
))
1117 sendto_one_notice(source_p
, ":*** You need oper and nick_changes flag for +s +n");
1118 source_p
->snomask
&= ~SNO_NCHANGE
; /* only tcm's really need this */
1121 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1123 sendto_one_notice(source_p
, ":*** You need oper and operwall flag for +z");
1124 source_p
->umodes
&= ~UMODE_OPERWALL
;
1127 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1128 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1130 sendto_one_notice(source_p
, ":*** You need oper and admin flag for +a");
1131 source_p
->umodes
&= ~UMODE_ADMIN
;
1134 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1135 hdata
.client
= source_p
;
1136 hdata
.oldumodes
= setflags
;
1137 hdata
.oldsnomask
= setsnomask
;
1138 call_hook(h_umode_changed
, &hdata
);
1140 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1142 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1145 * compare new flags with old flags and send string which
1146 * will cause servers to update correctly.
1148 send_umode_out(client_p
, source_p
, setflags
);
1149 if (showsnomask
&& MyConnect(source_p
))
1150 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1151 construct_snobuf(source_p
->snomask
));
1157 * send the MODE string for user (user) to connection client_p
1161 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, int sendmask
, char *umode_buf
)
1169 * build a string in umode_buf to represent the change in the user's
1170 * mode between the new (source_p->flag) and 'old'.
1175 for (i
= 0; i
< 128; i
++)
1177 flag
= user_modes
[i
];
1179 if((flag
& old
) && !(source_p
->umodes
& flag
))
1181 if(what
== MODE_DEL
)
1190 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1192 if(what
== MODE_ADD
)
1204 if(*umode_buf
&& client_p
)
1205 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1216 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1218 struct Client
*target_p
;
1222 send_umode(NULL
, source_p
, old
, 0, buf
);
1224 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1226 target_p
= ptr
->data
;
1228 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1230 sendto_one(target_p
, ":%s MODE %s :%s",
1231 get_id(source_p
, target_p
),
1232 get_id(source_p
, target_p
), buf
);
1236 if(client_p
&& MyClient(client_p
))
1237 send_umode(client_p
, source_p
, old
, 0, buf
);
1243 * inputs - client pointer to client to welcome
1248 user_welcome(struct Client
*source_p
)
1250 sendto_one_numeric(source_p
, RPL_WELCOME
, form_str(RPL_WELCOME
), ServerInfo
.network_name
, source_p
->name
);
1251 sendto_one_numeric(source_p
, RPL_YOURHOST
, form_str(RPL_YOURHOST
),
1252 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1253 sendto_one_numeric(source_p
, RPL_CREATED
, form_str(RPL_CREATED
), creation
);
1254 sendto_one_numeric(source_p
, RPL_MYINFO
, form_str(RPL_MYINFO
), me
.name
, ircd_version
, umodebuf
, cflagsmyinfo
);
1256 show_isupport(source_p
);
1258 show_lusers(source_p
);
1260 if(ConfigFileEntry
.short_motd
)
1262 sendto_one_notice(source_p
, ":*** Notice -- motd was last changed at %s", user_motd_changed
);
1263 sendto_one_notice(source_p
, ":*** Notice -- Please read the motd if you haven't read it");
1265 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1266 me
.name
, source_p
->name
, me
.name
);
1268 sendto_one(source_p
, form_str(RPL_MOTD
),
1269 me
.name
, source_p
->name
, "*** This is the short motd ***");
1271 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1274 send_user_motd(source_p
);
1279 * inputs - pointer to given client to oper
1280 * - pointer to ConfItem to use
1282 * side effects - opers up source_p using aconf for reference
1285 oper_up(struct Client
*source_p
, struct oper_conf
*oper_p
)
1287 unsigned int old
= source_p
->umodes
, oldsnomask
= source_p
->snomask
;
1288 hook_data_umode_changed hdata
;
1293 source_p
->umodes
|= oper_p
->umodes
;
1294 else if(ConfigFileEntry
.oper_umodes
)
1295 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1297 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1299 if (oper_p
->snomask
)
1301 source_p
->snomask
|= oper_p
->snomask
;
1302 source_p
->umodes
|= UMODE_SERVNOTICE
;
1304 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1306 /* Only apply these if +s is already set -- jilles */
1307 if (ConfigFileEntry
.oper_snomask
)
1308 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1310 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1315 SetExemptKline(source_p
);
1317 source_p
->flags2
|= oper_p
->flags
;
1318 source_p
->localClient
->opername
= rb_strdup(oper_p
->name
);
1319 source_p
->localClient
->privset
= privilegeset_ref(oper_p
->privset
);
1321 rb_dlinkAddAlloc(source_p
, &local_oper_list
);
1322 rb_dlinkAddAlloc(source_p
, &oper_list
);
1324 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1325 source_p
->umodes
|= UMODE_ADMIN
;
1326 if(!IsOperN(source_p
))
1327 source_p
->snomask
&= ~SNO_NCHANGE
;
1328 if(!IsOperOperwall(source_p
))
1329 source_p
->umodes
&= ~UMODE_OPERWALL
;
1330 hdata
.client
= source_p
;
1331 hdata
.oldumodes
= old
;
1332 hdata
.oldsnomask
= oldsnomask
;
1333 call_hook(h_umode_changed
, &hdata
);
1335 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1336 "%s (%s!%s@%s) is now an operator", oper_p
->name
, source_p
->name
,
1337 source_p
->username
, source_p
->host
);
1338 if(!(old
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1340 if((old
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1342 send_umode_out(source_p
, source_p
, old
);
1343 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1344 construct_snobuf(source_p
->snomask
));
1345 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1346 sendto_one_notice(source_p
, ":*** Oper privilege set is %s", oper_p
->privset
->name
);
1347 sendto_one_notice(source_p
, ":*** Oper privs are %s", oper_p
->privset
->privs
);
1348 send_oper_motd(source_p
);
1357 * outputs - an available umode bitmask or
1358 * 0 if no umodes are available
1359 * side effects - NONE
1362 find_umode_slot(void)
1364 unsigned int all_umodes
= 0, my_umode
= 0, i
;
1366 for (i
= 0; i
< 128; i
++)
1367 all_umodes
|= user_modes
[i
];
1369 for (my_umode
= 1; my_umode
&& (all_umodes
& my_umode
);
1376 construct_umodebuf(void)
1379 char *ptr
= umodebuf
;
1380 static int prev_user_modes
[128];
1384 for (i
= 0; i
< 128; i
++)
1386 if (prev_user_modes
[i
] != 0 && prev_user_modes
[i
] != user_modes
[i
])
1388 if (user_modes
[i
] == 0)
1390 orphaned_umodes
|= prev_user_modes
[i
];
1391 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Umode +%c is now orphaned", i
);
1395 orphaned_umodes
&= ~prev_user_modes
[i
];
1396 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Orphaned umode +%c is picked up by module", i
);
1398 user_modes
[i
] = prev_user_modes
[i
];
1401 prev_user_modes
[i
] = user_modes
[i
];
1410 change_nick_user_host(struct Client
*target_p
, const char *nick
, const char *user
,
1411 const char *host
, int newts
, const char *format
, ...)
1414 struct Channel
*chptr
;
1415 struct membership
*mscptr
;
1416 int changed
= irccmp(target_p
->name
, nick
);
1417 int changed_case
= strcmp(target_p
->name
, nick
);
1418 int do_qjm
= irccmp(target_p
->username
, user
) || irccmp(target_p
->host
, host
);
1419 char mode
[10], modeval
[NICKLEN
* 2 + 2], reason
[256], *mptr
;
1426 target_p
->tsinfo
= newts
;
1427 monitor_signoff(target_p
);
1429 invalidate_bancache_user(target_p
);
1433 va_start(ap
, format
);
1434 vsnprintf(reason
, 255, format
, ap
);
1437 sendto_common_channels_local_butone(target_p
, NOCAPS
, ":%s!%s@%s QUIT :%s",
1438 target_p
->name
, target_p
->username
, target_p
->host
,
1441 RB_DLINK_FOREACH(ptr
, target_p
->user
->channel
.head
)
1444 chptr
= mscptr
->chptr
;
1447 if(is_chanop(mscptr
))
1450 strcat(modeval
, nick
);
1451 strcat(modeval
, " ");
1454 if(is_voiced(mscptr
))
1457 strcat(modeval
, nick
);
1462 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, NOCAPS
, CLICAP_EXTENDED_JOIN
, chptr
,
1463 ":%s!%s@%s JOIN %s", nick
, user
, host
, chptr
->chname
);
1464 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, CLICAP_EXTENDED_JOIN
, NOCAPS
, chptr
,
1465 ":%s!%s@%s JOIN %s %s :%s", nick
, user
, host
, chptr
->chname
,
1466 EmptyString(target_p
->user
->suser
) ? "*" : target_p
->user
->suser
,
1470 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
,
1471 ":%s MODE %s +%s %s",
1472 target_p
->servptr
->name
,
1473 chptr
->chname
, mode
, modeval
);
1478 /* Resend away message to away-notify enabled clients. */
1479 if (target_p
->user
->away
)
1480 sendto_common_channels_local_butone(target_p
, CLICAP_AWAY_NOTIFY
, ":%s!%s@%s AWAY :%s",
1481 target_p
->name
, target_p
->username
, target_p
->host
,
1482 target_p
->user
->away
);
1484 if(MyClient(target_p
) && changed_case
)
1485 sendto_one(target_p
, ":%s!%s@%s NICK %s",
1486 target_p
->name
, target_p
->username
, target_p
->host
, nick
);
1488 /* TODO: send some snotes to SNO_NCHANGE/SNO_CCONN/SNO_CCONNEXT? */
1490 else if(changed_case
)
1492 sendto_common_channels_local(target_p
, NOCAPS
, ":%s!%s@%s NICK :%s",
1493 target_p
->name
, target_p
->username
,
1494 target_p
->host
, nick
);
1496 if(MyConnect(target_p
))
1497 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
1498 "Nick change: From %s to %s [%s@%s]",
1499 target_p
->name
, nick
,
1500 target_p
->username
, target_p
->host
);
1503 rb_strlcpy(target_p
->username
, user
, sizeof target_p
->username
);
1504 rb_strlcpy(target_p
->host
, host
, sizeof target_p
->host
);
1507 add_history(target_p
, 1);
1509 del_from_client_hash(target_p
->name
, target_p
);
1510 rb_strlcpy(target_p
->name
, nick
, NICKLEN
);
1511 add_to_client_hash(target_p
->name
, target_p
);
1515 monitor_signon(target_p
);
1516 del_all_accepts(target_p
);