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
37 #include "s_newconf.h"
43 #include "supported.h"
51 #include "substitution.h"
55 static void report_and_set_user_flags(struct Client
*, struct ConfItem
*);
56 void user_welcome(struct Client
*source_p
);
60 static int orphaned_umodes
= 0;
61 int user_modes
[256] = {
62 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
63 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
64 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
65 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
83 UMODE_NOFORWARD
, /* Q */
84 UMODE_REGONLYMSG
, /* R */
85 UMODE_SERVICE
, /* S */
92 UMODE_SSLCLIENT
, /* Z */
93 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
100 UMODE_CALLERID
, /* g */
102 UMODE_INVISIBLE
, /* i */
105 UMODE_LOCOPS
, /* l */
112 UMODE_SERVNOTICE
, /* s */
116 UMODE_WALLOP
, /* w */
119 UMODE_OPERWALL
, /* z */
120 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
121 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
122 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
123 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
124 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
125 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
126 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
127 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
128 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
135 * inputs - pointer to client
137 * side effects - display to client user counts etc.
140 show_lusers(struct Client
*source_p
)
142 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)MaxClientCount
)
143 MaxClientCount
= rb_dlink_list_length(&lclient_list
);
145 if((rb_dlink_list_length(&lclient_list
) + rb_dlink_list_length(&serv_list
)) >
146 (unsigned long)MaxConnectionCount
)
147 MaxConnectionCount
= rb_dlink_list_length(&lclient_list
) +
148 rb_dlink_list_length(&serv_list
);
150 sendto_one_numeric(source_p
, RPL_LUSERCLIENT
, form_str(RPL_LUSERCLIENT
),
151 (Count
.total
- Count
.invisi
),
153 (int)rb_dlink_list_length(&global_serv_list
));
155 if(rb_dlink_list_length(&oper_list
) > 0)
156 sendto_one_numeric(source_p
, RPL_LUSEROP
,
157 form_str(RPL_LUSEROP
),
158 (int)rb_dlink_list_length(&oper_list
));
160 if(rb_dlink_list_length(&unknown_list
) > 0)
161 sendto_one_numeric(source_p
, RPL_LUSERUNKNOWN
,
162 form_str(RPL_LUSERUNKNOWN
),
163 (int)rb_dlink_list_length(&unknown_list
));
165 if(rb_dlink_list_length(&global_channel_list
) > 0)
166 sendto_one_numeric(source_p
, RPL_LUSERCHANNELS
,
167 form_str(RPL_LUSERCHANNELS
),
168 rb_dlink_list_length(&global_channel_list
));
170 sendto_one_numeric(source_p
, RPL_LUSERME
, form_str(RPL_LUSERME
),
171 (int)rb_dlink_list_length(&lclient_list
),
172 (int)rb_dlink_list_length(&serv_list
));
174 sendto_one_numeric(source_p
, RPL_LOCALUSERS
,
175 form_str(RPL_LOCALUSERS
),
176 (int)rb_dlink_list_length(&lclient_list
),
178 (int)rb_dlink_list_length(&lclient_list
),
181 sendto_one_numeric(source_p
, RPL_GLOBALUSERS
, form_str(RPL_GLOBALUSERS
),
182 Count
.total
, Count
.max_tot
,
183 Count
.total
, Count
.max_tot
);
185 sendto_one_numeric(source_p
, RPL_STATSCONN
,
186 form_str(RPL_STATSCONN
),
187 MaxConnectionCount
, MaxClientCount
,
188 Count
.totalrestartcount
);
192 ** register_local_user
193 ** This function is called when both NICK and USER messages
194 ** have been accepted for the client, in whatever order. Only
195 ** after this, is the USER message propagated.
197 ** NICK's must be propagated at once when received, although
198 ** it would be better to delay them too until full info is
199 ** available. Doing it is not so simple though, would have
200 ** to implement the following:
202 ** (actually it has been implemented already for a while) -orabidoo
204 ** 1) user telnets in and gives only "NICK foobar" and waits
205 ** 2) another user far away logs in normally with the nick
206 ** "foobar" (quite legal, as this server didn't propagate
208 ** 3) now this server gets nick "foobar" from outside, but
209 ** has alread the same defined locally. Current server
210 ** would just issue "KILL foobar" to clean out dups. But,
211 ** this is not fair. It should actually request another
212 ** nick from local user or kill him/her...
216 register_local_user(struct Client
*client_p
, struct Client
*source_p
)
218 struct ConfItem
*aconf
, *xconf
;
219 struct User
*user
= source_p
->user
;
220 char tmpstr2
[BUFSIZE
];
221 char ipaddr
[HOSTIPLEN
];
222 char myusername
[USERLEN
+1];
225 s_assert(NULL
!= source_p
);
226 s_assert(MyConnect(source_p
));
231 if(IsAnyDead(source_p
))
234 if(ConfigFileEntry
.ping_cookie
)
236 if(!(source_p
->flags
& FLAGS_PINGSENT
) && source_p
->localClient
->random_ping
== 0)
238 source_p
->localClient
->random_ping
= (unsigned long) (rand() * rand()) << 1;
239 sendto_one(source_p
, "PING :%08lX",
240 (unsigned long) source_p
->localClient
->random_ping
);
241 source_p
->flags
|= FLAGS_PINGSENT
;
244 if(!(source_p
->flags
& FLAGS_PING_COOKIE
))
250 /* hasnt finished client cap negotiation */
251 if(source_p
->flags
& FLAGS_CLICAP
)
254 /* Waiting on authd */
255 if(source_p
->preClient
->authd_cid
)
258 client_p
->localClient
->last
= rb_current_time();
260 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
261 if(!IsGotId(source_p
) && (strchr(source_p
->username
, '[') != NULL
))
266 p
= source_p
->username
;
268 while(*p
&& i
< USERLEN
)
271 myusername
[i
++] = *p
;
275 myusername
[i
] = '\0';
278 rb_strlcpy(myusername
, source_p
->username
, sizeof myusername
);
280 if((status
= check_client(client_p
, source_p
, myusername
)) < 0)
281 return (CLIENT_EXITED
);
283 /* Apply nick override */
284 if(*source_p
->preClient
->spoofnick
)
286 char note
[NICKLEN
+ 10];
288 del_from_client_hash(source_p
->name
, source_p
);
289 rb_strlcpy(source_p
->name
, source_p
->preClient
->spoofnick
, NICKLEN
+ 1);
290 add_to_client_hash(source_p
->name
, source_p
);
292 snprintf(note
, NICKLEN
+ 10, "Nick: %s", source_p
->name
);
293 rb_note(source_p
->localClient
->F
, note
);
296 if(!valid_hostname(source_p
->host
))
298 sendto_one_notice(source_p
, ":*** Notice -- You have an illegal character in your hostname");
300 rb_strlcpy(source_p
->host
, source_p
->sockhost
, sizeof(source_p
->host
));
303 aconf
= source_p
->localClient
->att_conf
;
307 exit_client(client_p
, source_p
, &me
, "*** Not Authorised");
308 return (CLIENT_EXITED
);
311 if(IsConfSSLNeeded(aconf
) && !IsSSL(source_p
))
313 ServerStats
.is_ref
++;
314 sendto_one_notice(source_p
, ":*** Notice -- You need to use SSL/TLS to use this server");
315 exit_client(client_p
, source_p
, &me
, "Use SSL/TLS");
316 return (CLIENT_EXITED
);
319 if(!IsGotId(source_p
))
324 if(IsNeedIdentd(aconf
))
326 ServerStats
.is_ref
++;
327 sendto_one_notice(source_p
, ":*** Notice -- You need to install identd to use this server");
328 exit_client(client_p
, source_p
, &me
, "Install identd");
329 return (CLIENT_EXITED
);
332 /* dont replace username if its supposed to be spoofed --fl */
333 if(!IsConfDoSpoofIp(aconf
) || !strchr(aconf
->info
.name
, '@'))
337 if(!IsNoTilde(aconf
))
338 source_p
->username
[i
++] = '~';
340 while (*p
&& i
< USERLEN
)
343 source_p
->username
[i
++] = *p
;
347 source_p
->username
[i
] = '\0';
351 if(IsNeedSasl(aconf
) && !*user
->suser
)
353 ServerStats
.is_ref
++;
354 sendto_one_notice(source_p
, ":*** Notice -- You need to identify via SASL to use this server");
355 exit_client(client_p
, source_p
, &me
, "SASL access only");
356 return (CLIENT_EXITED
);
360 if(!EmptyString(aconf
->passwd
))
364 if(EmptyString(source_p
->localClient
->passwd
))
366 else if(IsConfEncrypted(aconf
))
367 encr
= rb_crypt(source_p
->localClient
->passwd
, aconf
->passwd
);
369 encr
= source_p
->localClient
->passwd
;
371 if(encr
== NULL
|| strcmp(encr
, aconf
->passwd
))
373 ServerStats
.is_ref
++;
374 sendto_one(source_p
, form_str(ERR_PASSWDMISMATCH
), me
.name
, source_p
->name
);
375 exit_client(client_p
, source_p
, &me
, "Bad Password");
376 return (CLIENT_EXITED
);
379 /* clear password only if used now, otherwise send it
380 * to services -- jilles */
381 if(source_p
->localClient
->passwd
)
383 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
384 rb_free(source_p
->localClient
->passwd
);
385 source_p
->localClient
->passwd
= NULL
;
389 /* report if user has &^>= etc. and set flags as needed in source_p */
390 report_and_set_user_flags(source_p
, aconf
);
394 * We want to be able to have servers and F-line clients
395 * connect, so save room for "buffer" connections.
396 * Smaller servers may want to decrease this, and it should
397 * probably be just a percentage of the MAXCLIENTS...
400 /* Except "F:" clients */
401 if(rb_dlink_list_length(&lclient_list
) >=
402 (unsigned long)GlobalSetOptions
.maxclients
&& !IsConfExemptLimits(aconf
))
404 sendto_realops_snomask(SNO_FULL
, L_ALL
,
405 "Too many clients, rejecting %s[%s].", source_p
->name
, source_p
->host
);
407 ServerStats
.is_ref
++;
408 exit_client(client_p
, source_p
, &me
, "Sorry, server is full - try later");
409 return (CLIENT_EXITED
);
412 /* kline exemption extends to xline too */
413 if(!IsExemptKline(source_p
) &&
414 (xconf
= find_xline(source_p
->info
, 1)) != NULL
)
416 ServerStats
.is_ref
++;
417 add_reject(source_p
, xconf
->host
, NULL
);
418 exit_client(client_p
, source_p
, &me
, "Bad user info");
419 return CLIENT_EXITED
;
422 /* authd rejection check */
423 if(source_p
->preClient
->authd_accepted
== false)
425 struct blacklist_stats
*stats
;
426 rb_dlink_list varlist
= { NULL
, NULL
, 0 };
429 substitution_append_var(&varlist
, "nick", source_p
->name
);
430 substitution_append_var(&varlist
, "ip", source_p
->sockhost
);
431 substitution_append_var(&varlist
, "host", source_p
->host
);
432 substitution_append_var(&varlist
, "dnsbl-host", source_p
->preClient
->authd_data
);
433 substitution_append_var(&varlist
, "network-name", ServerInfo
.network_name
);
434 reason
= substitution_parse(source_p
->preClient
->authd_reason
, &varlist
);
436 switch(source_p
->preClient
->authd_cause
)
438 case 'B': /* Blacklists */
439 if((stats
= rb_dictionary_retrieve(bl_stats
, source_p
->preClient
->authd_data
)) != NULL
)
442 if(IsExemptKline(source_p
) || IsConfExemptDNSBL(aconf
))
444 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s, but you are exempt",
445 source_p
->sockhost
, source_p
->preClient
->authd_data
);
449 sendto_realops_snomask(SNO_REJ
, L_NETWIDE
,
450 "Listed on DNSBL %s: %s (%s@%s) [%s] [%s]",
451 source_p
->preClient
->authd_data
,
453 source_p
->username
, source_p
->host
,
454 IsIPSpoof(source_p
) ? "255.255.255.255" : source_p
->sockhost
,
457 ServerStats
.is_ref
++;
459 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
460 me
.name
, source_p
->name
, reason
);
462 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s",
463 source_p
->sockhost
, source_p
->preClient
->authd_data
);
464 add_reject(source_p
, NULL
, NULL
);
465 exit_client(client_p
, source_p
, &me
, "*** Banned (DNS blacklist)");
466 substitution_free(&varlist
);
467 return CLIENT_EXITED
;
471 if(IsExemptKline(source_p
) || IsConfExemptProxy(aconf
))
473 sendto_one_notice(source_p
, ":*** Your IP address %s has been detected as an open proxy (ip:port %s), but you are exempt",
474 source_p
->sockhost
, source_p
->preClient
->authd_data
);
478 sendto_realops_snomask(SNO_REJ
, L_NETWIDE
,
479 "Open proxy %s: %s (%s@%s) [%s] [%s]",
480 source_p
->preClient
->authd_data
,
482 source_p
->username
, source_p
->host
,
483 IsIPSpoof(source_p
) ? "255.255.255.255" : source_p
->sockhost
,
486 ServerStats
.is_ref
++;
488 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
489 me
.name
, source_p
->name
, reason
);
491 sendto_one_notice(source_p
, ":*** Your IP address %s has been detected as an open proxy (ip:port %s)",
492 source_p
->sockhost
, source_p
->preClient
->authd_data
);
493 add_reject(source_p
, NULL
, NULL
);
494 exit_client(client_p
, source_p
, &me
, "*** Banned (Open proxy)");
495 substitution_free(&varlist
);
496 return CLIENT_EXITED
;
498 default: /* Unknown, but handle the case properly */
499 if (IsExemptKline(source_p
))
501 sendto_one_notice(source_p
, ":*** You were rejected, but you are exempt (reason: %s)",
506 sendto_realops_snomask(SNO_REJ
, L_NETWIDE
,
507 "Rejected by authentication system (reason %s): %s (%s@%s) [%s] [%s]",
508 reason
, source_p
->name
, source_p
->username
, source_p
->host
,
509 IsIPSpoof(source_p
) ? "255.255.255.255" : source_p
->sockhost
,
512 ServerStats
.is_ref
++;
514 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
515 me
.name
, source_p
->name
, reason
);
517 sendto_one_notice(source_p
, ":*** Rejected by authentication system: %s",
519 add_reject(source_p
, NULL
, NULL
);
520 exit_client(client_p
, source_p
, &me
, "*** Banned (authentication system)");
521 substitution_free(&varlist
);
522 return CLIENT_EXITED
;
526 substitution_free(&varlist
);
529 /* valid user name check */
531 if(!valid_username(source_p
->username
))
533 sendto_realops_snomask(SNO_REJ
, L_ALL
,
534 "Invalid username: %s (%s@%s)",
535 source_p
->name
, source_p
->username
, source_p
->host
);
536 ServerStats
.is_ref
++;
537 sendto_one_notice(source_p
, ":*** Your username is invalid. Please make sure that your username contains "
538 "only alphanumeric characters.");
539 sprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
540 exit_client(client_p
, source_p
, &me
, tmpstr2
);
541 return (CLIENT_EXITED
);
544 /* end of valid user name check */
546 /* Store original hostname -- jilles */
547 rb_strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
549 /* Spoof user@host */
550 if(*source_p
->preClient
->spoofuser
)
551 rb_strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
552 if(*source_p
->preClient
->spoofhost
)
554 rb_strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
555 if (irccmp(source_p
->host
, source_p
->orighost
))
556 SetDynSpoof(source_p
);
559 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
& ~orphaned_umodes
;
561 call_hook(h_new_local_user
, source_p
);
563 /* If they have died in send_* or were thrown out by the
564 * new_local_user hook don't do anything. */
565 if(IsAnyDead(source_p
))
566 return CLIENT_EXITED
;
568 /* To avoid inconsistencies, do not abort the registration
569 * starting from this point -- jilles
571 rb_inet_ntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
573 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
574 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
575 source_p
->name
, source_p
->username
, source_p
->orighost
,
576 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
577 get_client_class(source_p
), source_p
->info
);
579 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
580 "CLICONN %s %s %s %s %s %s 0 %s",
581 source_p
->name
, source_p
->username
, source_p
->orighost
,
582 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
583 get_client_class(source_p
),
584 /* mirc can sometimes send ips here */
585 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
588 add_to_hostname_hash(source_p
->orighost
, source_p
);
590 /* Allocate a UID if it was not previously allocated.
591 * If this already occured, it was probably during SASL auth...
595 strcpy(source_p
->id
, generate_uid());
596 add_to_id_hash(source_p
->id
, source_p
);
600 source_p
->umodes
|= UMODE_SSLCLIENT
;
602 if (source_p
->umodes
& UMODE_INVISIBLE
)
605 s_assert(!IsClient(source_p
));
606 rb_dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
609 source_p
->servptr
= &me
;
610 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
612 /* Increment our total user count here */
613 if(++Count
.total
> Count
.max_tot
)
614 Count
.max_tot
= Count
.total
;
616 Count
.totalrestartcount
++;
618 s_assert(source_p
->localClient
!= NULL
);
620 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
622 Count
.max_loc
= rb_dlink_list_length(&lclient_list
);
623 if(!(Count
.max_loc
% 10))
624 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
625 "New Max Local Clients: %d", Count
.max_loc
);
628 /* they get a reduced limit */
629 if(find_tgchange(source_p
->sockhost
))
630 source_p
->localClient
->targets_free
= TGCHANGE_INITIAL_LOW
;
632 source_p
->localClient
->targets_free
= TGCHANGE_INITIAL
;
634 monitor_signon(source_p
);
635 user_welcome(source_p
);
637 free_pre_client(source_p
);
639 introduce_client(client_p
, source_p
, user
, source_p
->name
, 1);
648 * side effects - This common function introduces a client to the rest
649 * of the net, either from a local client connect or
650 * from a remote connect.
653 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
656 struct Client
*identifyservice_p
;
658 hook_data_umode_changed hdata
;
659 hook_data_client hdata2
;
661 if(MyClient(source_p
))
662 send_umode(source_p
, source_p
, 0, ubuf
);
664 send_umode(NULL
, source_p
, 0, ubuf
);
672 s_assert(has_id(source_p
));
675 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
676 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
677 source_p
->servptr
->id
, nick
,
678 source_p
->hopcount
+ 1,
679 (long) source_p
->tsinfo
, ubuf
,
680 source_p
->username
, source_p
->host
,
681 IsIPSpoof(source_p
) ? "0" : source_p
->sockhost
,
683 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
684 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
687 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
688 ":%s UID %s %d %ld %s %s %s %s %s :%s",
689 source_p
->servptr
->id
, nick
,
690 source_p
->hopcount
+ 1,
691 (long) source_p
->tsinfo
, ubuf
,
692 source_p
->username
, source_p
->host
,
693 IsIPSpoof(source_p
) ? "0" : source_p
->sockhost
,
694 source_p
->id
, source_p
->info
);
696 if(!EmptyString(source_p
->certfp
))
697 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
698 ":%s ENCAP * CERTFP :%s",
699 use_id(source_p
), source_p
->certfp
);
701 if (IsDynSpoof(source_p
))
703 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
704 use_id(source_p
), source_p
->orighost
);
707 if (!EmptyString(source_p
->user
->suser
))
709 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
710 use_id(source_p
), source_p
->user
->suser
);
713 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
715 if (!EmptyString(ConfigFileEntry
.identifyservice
) &&
716 !EmptyString(ConfigFileEntry
.identifycommand
))
718 /* use user@server */
719 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
721 identifyservice_p
= find_named_client(p
+ 1);
723 identifyservice_p
= NULL
;
724 if (identifyservice_p
!= NULL
)
726 if (!EmptyString(source_p
->localClient
->auth_user
))
727 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s %s",
728 get_id(source_p
, identifyservice_p
),
729 ConfigFileEntry
.identifyservice
,
730 ConfigFileEntry
.identifycommand
,
731 source_p
->localClient
->auth_user
,
732 source_p
->localClient
->passwd
);
734 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
735 get_id(source_p
, identifyservice_p
),
736 ConfigFileEntry
.identifyservice
,
737 ConfigFileEntry
.identifycommand
,
738 source_p
->localClient
->passwd
);
741 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
742 rb_free(source_p
->localClient
->passwd
);
743 source_p
->localClient
->passwd
= NULL
;
746 /* let modules providing usermodes know that we've got a new user,
747 * why is this here? -- well, some modules need to be able to send out new
748 * information about a client, so this was the best place to do it
751 hdata
.client
= source_p
;
753 hdata
.oldsnomask
= 0;
754 call_hook(h_umode_changed
, &hdata
);
756 /* On the other hand, some modules need to know when a client is
757 * being introduced, period.
760 hdata2
.client
= client_p
;
761 hdata2
.target
= source_p
;
762 call_hook(h_introduce_client
, &hdata2
);
766 * valid_hostname - check hostname for validity
768 * Inputs - pointer to user
769 * Output - true if valid, false if not
770 * Side effects - NONE
772 * NOTE: this doesn't allow a hostname to begin with a dot and
773 * will not allow more dots than chars.
776 valid_hostname(const char *hostname
)
778 const char *p
= hostname
, *last_slash
= 0;
786 if(!strcmp(hostname
, "localhost"))
789 if('.' == *p
|| ':' == *p
|| '/' == *p
)
796 if(*p
== '.' || *p
== ':')
809 if(last_slash
&& IsDigit(last_slash
[1]))
816 * valid_username - check username for validity
818 * Inputs - pointer to user
819 * Output - true if valid, false if not
820 * Side effects - NONE
822 * Absolutely always reject any '*' '!' '?' '@' in an user name
823 * reject any odd control characters names.
824 * Allow '.' in username to allow for "first.last"
828 valid_username(const char *username
)
831 const char *p
= username
;
841 /* reject usernames that don't start with an alphanum
842 * i.e. reject jokers who have '-@somehost' or '.@somehost'
843 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
850 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
853 if(dots
> ConfigFileEntry
.dots_in_ident
)
855 if(!IsUserChar(p
[1]))
858 else if(!IsUserChar(*p
))
864 /* report_and_set_user_flags
866 * Inputs - pointer to source_p
867 * - pointer to aconf for this user
870 * Report to user any special flags they are getting, and set them.
874 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
876 /* If this user is being spoofed, tell them so */
877 if(IsConfDoSpoofIp(aconf
))
879 sendto_one_notice(source_p
, ":*** Spoofing your IP");
882 /* If this user is in the exception class, Set it "E lined" */
883 if(IsConfExemptKline(aconf
))
885 SetExemptKline(source_p
);
886 sendto_one_notice(source_p
, ":*** You are exempt from K/X lines");
889 if(IsConfExemptDNSBL(aconf
))
890 /* kline exempt implies this, don't send both */
891 if(!IsConfExemptKline(aconf
))
892 sendto_one_notice(source_p
, ":*** You are exempt from DNS blacklists");
894 /* If this user is exempt from user limits set it F lined" */
895 if(IsConfExemptLimits(aconf
))
897 sendto_one_notice(source_p
, ":*** You are exempt from user limits");
900 if(IsConfExemptFlood(aconf
))
902 SetExemptFlood(source_p
);
903 sendto_one_notice(source_p
, ":*** You are exempt from flood limits");
906 if(IsConfExemptSpambot(aconf
))
908 SetExemptSpambot(source_p
);
909 sendto_one_notice(source_p
, ":*** You are exempt from spambot checks");
912 if(IsConfExemptJupe(aconf
))
914 SetExemptJupe(source_p
);
915 sendto_one_notice(source_p
, ":*** You are exempt from juped channel warnings");
918 if(IsConfExemptResv(aconf
))
920 SetExemptResv(source_p
);
921 sendto_one_notice(source_p
, ":*** You are exempt from resvs");
924 if(IsConfExemptShide(aconf
))
926 SetExemptShide(source_p
);
927 sendto_one_notice(source_p
, ":*** You are exempt from serverhiding");
930 if(IsConfExtendChans(aconf
))
932 SetExtendChans(source_p
);
933 sendto_one_notice(source_p
, ":*** You are exempt from normal channel limits");
938 show_other_user_mode(struct Client
*source_p
, struct Client
*target_p
)
947 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
948 if (target_p
->umodes
& user_modes
[i
])
952 if (MyConnect(target_p
) && target_p
->snomask
!= 0)
953 sendto_one_notice(source_p
, ":Modes for %s are %s %s",
955 construct_snobuf(target_p
->snomask
));
957 sendto_one_notice(source_p
, ":Modes for %s are %s",
958 target_p
->name
, buf
);
962 * user_mode - set get current users mode
964 * m_umode() added 15/10/91 By Darren Reed.
965 * parv[1] - username to change mode for
966 * parv[2] - modes to change
969 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
975 struct Client
*target_p
;
977 bool badflag
= false; /* Only send one bad flag notice */
978 bool showsnomask
= false;
979 unsigned int setsnomask
;
981 hook_data_umode_changed hdata
;
987 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
991 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
993 if(MyConnect(source_p
))
994 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
995 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
999 /* Dont know why these were commented out..
1000 * put them back using new sendto() funcs
1003 if(IsServer(source_p
))
1005 sendto_realops_snomask(SNO_GENERAL
, L_ADMIN
,
1006 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
1010 if(source_p
!= target_p
)
1012 if (MyOper(source_p
) && parc
< 3)
1013 show_other_user_mode(source_p
, target_p
);
1015 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
1024 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
1025 if (source_p
->umodes
& user_modes
[i
])
1029 sendto_one_numeric(source_p
, RPL_UMODEIS
, form_str(RPL_UMODEIS
), buf
);
1031 if (source_p
->snomask
!= 0)
1032 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1033 construct_snobuf(source_p
->snomask
));
1038 /* find flags already set for user */
1039 setflags
= source_p
->umodes
;
1040 setsnomask
= source_p
->snomask
;
1043 * parse mode change string(s)
1045 for (pm
= parv
[2]; *pm
; pm
++)
1056 if(what
== MODE_ADD
)
1058 if(IsServer(client_p
) && !IsOper(source_p
))
1062 rb_dlinkAddAlloc(source_p
, &oper_list
);
1067 /* Only decrement the oper counts if an oper to begin with
1068 * found by Pat Szuta, Perly , perly@xnet.com
1071 if(!IsOper(source_p
))
1074 ClearOper(source_p
);
1078 if(MyConnect(source_p
))
1080 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
1081 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
1083 source_p
->snomask
= 0;
1086 source_p
->flags2
&= ~OPER_FLAGS
;
1088 rb_free(source_p
->localClient
->opername
);
1089 source_p
->localClient
->opername
= NULL
;
1091 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1092 privilegeset_unref(source_p
->localClient
->privset
);
1093 source_p
->localClient
->privset
= NULL
;
1096 rb_dlinkFindDestroy(source_p
, &oper_list
);
1100 /* we may not get these,
1101 * but they shouldnt be in default
1104 /* can only be set on burst */
1114 if (MyConnect(source_p
))
1116 if(!IsOper(source_p
)
1117 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
1119 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1124 if(what
== MODE_ADD
)
1127 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1129 source_p
->snomask
|= SNO_GENERAL
;
1132 source_p
->snomask
= 0;
1133 if (source_p
->snomask
!= 0)
1134 source_p
->umodes
|= UMODE_SERVNOTICE
;
1136 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1141 if (MyConnect(source_p
) && *pm
== 'Q' && !ConfigChannel
.use_forward
)
1147 if((flag
= user_modes
[(unsigned char) *pm
]))
1149 if(MyConnect(source_p
)
1150 && ((!IsOper(source_p
)
1151 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1152 || (orphaned_umodes
& flag
)))
1154 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1159 if(what
== MODE_ADD
)
1160 source_p
->umodes
|= flag
;
1162 source_p
->umodes
&= ~flag
;
1167 if(MyConnect(source_p
))
1174 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1176 if(MyClient(source_p
) && (source_p
->snomask
& SNO_NCHANGE
) && !IsOperN(source_p
))
1178 sendto_one_notice(source_p
, ":*** You need oper and nick_changes flag for +s +n");
1179 source_p
->snomask
&= ~SNO_NCHANGE
; /* only tcm's really need this */
1182 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1184 sendto_one_notice(source_p
, ":*** You need oper and operwall flag for +z");
1185 source_p
->umodes
&= ~UMODE_OPERWALL
;
1188 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1189 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1191 sendto_one_notice(source_p
, ":*** You need oper and admin flag for +a");
1192 source_p
->umodes
&= ~UMODE_ADMIN
;
1195 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1196 hdata
.client
= source_p
;
1197 hdata
.oldumodes
= setflags
;
1198 hdata
.oldsnomask
= setsnomask
;
1199 call_hook(h_umode_changed
, &hdata
);
1201 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1203 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1206 * compare new flags with old flags and send string which
1207 * will cause servers to update correctly.
1209 send_umode_out(client_p
, source_p
, setflags
);
1210 if (showsnomask
&& MyConnect(source_p
))
1211 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1212 construct_snobuf(source_p
->snomask
));
1218 * send the MODE string for user (user) to connection client_p
1222 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, char *umode_buf
)
1230 * build a string in umode_buf to represent the change in the user's
1231 * mode between the new (source_p->flag) and 'old'.
1236 for (i
= 0; i
< 128; i
++)
1238 flag
= user_modes
[i
];
1240 if((flag
& old
) && !(source_p
->umodes
& flag
))
1242 if(what
== MODE_DEL
)
1251 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1253 if(what
== MODE_ADD
)
1265 if(*umode_buf
&& client_p
)
1266 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1277 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1279 struct Client
*target_p
;
1283 send_umode(NULL
, source_p
, old
, buf
);
1285 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1287 target_p
= ptr
->data
;
1289 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1291 sendto_one(target_p
, ":%s MODE %s :%s",
1292 get_id(source_p
, target_p
),
1293 get_id(source_p
, target_p
), buf
);
1297 if(client_p
&& MyClient(client_p
))
1298 send_umode(client_p
, source_p
, old
, buf
);
1304 * inputs - client pointer to client to welcome
1309 user_welcome(struct Client
*source_p
)
1311 sendto_one_numeric(source_p
, RPL_WELCOME
, form_str(RPL_WELCOME
), ServerInfo
.network_name
, source_p
->name
);
1312 sendto_one_numeric(source_p
, RPL_YOURHOST
, form_str(RPL_YOURHOST
),
1313 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1314 sendto_one_numeric(source_p
, RPL_CREATED
, form_str(RPL_CREATED
), creation
);
1315 sendto_one_numeric(source_p
, RPL_MYINFO
, form_str(RPL_MYINFO
), me
.name
, ircd_version
, umodebuf
, cflagsmyinfo
);
1317 show_isupport(source_p
);
1319 show_lusers(source_p
);
1321 if(ConfigFileEntry
.short_motd
)
1323 sendto_one_notice(source_p
, ":*** Notice -- motd was last changed at %s", user_motd_changed
);
1324 sendto_one_notice(source_p
, ":*** Notice -- Please read the motd if you haven't read it");
1326 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1327 me
.name
, source_p
->name
, me
.name
);
1329 sendto_one(source_p
, form_str(RPL_MOTD
),
1330 me
.name
, source_p
->name
, "*** This is the short motd ***");
1332 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1335 send_user_motd(source_p
);
1340 * inputs - pointer to given client to oper
1341 * - pointer to ConfItem to use
1343 * side effects - opers up source_p using aconf for reference
1346 oper_up(struct Client
*source_p
, struct oper_conf
*oper_p
)
1348 unsigned int old
= source_p
->umodes
, oldsnomask
= source_p
->snomask
;
1349 hook_data_umode_changed hdata
;
1354 source_p
->umodes
|= oper_p
->umodes
;
1355 else if(ConfigFileEntry
.oper_umodes
)
1356 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1358 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1360 if (oper_p
->snomask
)
1362 source_p
->snomask
|= oper_p
->snomask
;
1363 source_p
->umodes
|= UMODE_SERVNOTICE
;
1365 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1367 /* Only apply these if +s is already set -- jilles */
1368 if (ConfigFileEntry
.oper_snomask
)
1369 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1371 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1376 SetExtendChans(source_p
);
1377 SetExemptKline(source_p
);
1379 source_p
->flags2
|= oper_p
->flags
;
1380 source_p
->localClient
->opername
= rb_strdup(oper_p
->name
);
1381 source_p
->localClient
->privset
= privilegeset_ref(oper_p
->privset
);
1383 rb_dlinkAddAlloc(source_p
, &local_oper_list
);
1384 rb_dlinkAddAlloc(source_p
, &oper_list
);
1386 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1387 source_p
->umodes
|= UMODE_ADMIN
;
1388 if(!IsOperN(source_p
))
1389 source_p
->snomask
&= ~SNO_NCHANGE
;
1390 if(!IsOperOperwall(source_p
))
1391 source_p
->umodes
&= ~UMODE_OPERWALL
;
1392 hdata
.client
= source_p
;
1393 hdata
.oldumodes
= old
;
1394 hdata
.oldsnomask
= oldsnomask
;
1395 call_hook(h_umode_changed
, &hdata
);
1397 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1398 "%s (%s!%s@%s) is now an operator", oper_p
->name
, source_p
->name
,
1399 source_p
->username
, source_p
->host
);
1400 if(!(old
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1402 if((old
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1404 send_umode_out(source_p
, source_p
, old
);
1405 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1406 construct_snobuf(source_p
->snomask
));
1407 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1408 sendto_one_notice(source_p
, ":*** Oper privilege set is %s", oper_p
->privset
->name
);
1409 sendto_one_notice(source_p
, ":*** Oper privs are %s", oper_p
->privset
->privs
);
1410 send_oper_motd(source_p
);
1417 * outputs - an available umode bitmask or
1418 * 0 if no umodes are available
1419 * side effects - NONE
1422 find_umode_slot(void)
1424 unsigned int all_umodes
= 0, my_umode
= 0, i
;
1426 for (i
= 0; i
< 128; i
++)
1427 all_umodes
|= user_modes
[i
];
1429 for (my_umode
= 1; my_umode
&& (all_umodes
& my_umode
);
1436 construct_umodebuf(void)
1439 char *ptr
= umodebuf
;
1440 static int prev_user_modes
[128];
1444 for (i
= 0; i
< 128; i
++)
1446 if (prev_user_modes
[i
] != 0 && prev_user_modes
[i
] != user_modes
[i
])
1448 if (user_modes
[i
] == 0)
1450 orphaned_umodes
|= prev_user_modes
[i
];
1451 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Umode +%c is now orphaned", i
);
1455 orphaned_umodes
&= ~prev_user_modes
[i
];
1456 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Orphaned umode +%c is picked up by module", i
);
1458 user_modes
[i
] = prev_user_modes
[i
];
1461 prev_user_modes
[i
] = user_modes
[i
];
1470 change_nick_user_host(struct Client
*target_p
, const char *nick
, const char *user
,
1471 const char *host
, int newts
, const char *format
, ...)
1474 struct Channel
*chptr
;
1475 struct membership
*mscptr
;
1476 int changed
= irccmp(target_p
->name
, nick
);
1477 int changed_case
= strcmp(target_p
->name
, nick
);
1478 int do_qjm
= irccmp(target_p
->username
, user
) || irccmp(target_p
->host
, host
);
1479 char mode
[10], modeval
[NICKLEN
* 2 + 2], reason
[256], *mptr
;
1486 target_p
->tsinfo
= newts
;
1487 monitor_signoff(target_p
);
1489 invalidate_bancache_user(target_p
);
1493 va_start(ap
, format
);
1494 vsnprintf(reason
, 255, format
, ap
);
1497 sendto_common_channels_local_butone(target_p
, NOCAPS
, CLICAP_CHGHOST
, ":%s!%s@%s QUIT :%s",
1498 target_p
->name
, target_p
->username
, target_p
->host
,
1501 RB_DLINK_FOREACH(ptr
, target_p
->user
->channel
.head
)
1504 chptr
= mscptr
->chptr
;
1507 if(is_chanop(mscptr
))
1510 strcat(modeval
, nick
);
1511 strcat(modeval
, " ");
1514 if(is_voiced(mscptr
))
1517 strcat(modeval
, nick
);
1522 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, NOCAPS
, CLICAP_EXTENDED_JOIN
| CLICAP_CHGHOST
, chptr
,
1523 ":%s!%s@%s JOIN %s", nick
, user
, host
, chptr
->chname
);
1524 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, CLICAP_EXTENDED_JOIN
, CLICAP_CHGHOST
, chptr
,
1525 ":%s!%s@%s JOIN %s %s :%s", nick
, user
, host
, chptr
->chname
,
1526 EmptyString(target_p
->user
->suser
) ? "*" : target_p
->user
->suser
,
1530 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, NOCAPS
, CLICAP_CHGHOST
, chptr
,
1531 ":%s MODE %s +%s %s", target_p
->servptr
->name
, chptr
->chname
, mode
, modeval
);
1536 /* Resend away message to away-notify enabled clients. */
1537 if (target_p
->user
->away
)
1538 sendto_common_channels_local_butone(target_p
, CLICAP_AWAY_NOTIFY
, CLICAP_CHGHOST
, ":%s!%s@%s AWAY :%s",
1540 target_p
->user
->away
);
1542 sendto_common_channels_local_butone(target_p
, CLICAP_CHGHOST
, NOCAPS
,
1543 ":%s!%s@%s CHGHOST %s %s",
1544 target_p
->name
, target_p
->username
, target_p
->host
, user
, host
);
1546 if(MyClient(target_p
) && changed_case
)
1547 sendto_one(target_p
, ":%s!%s@%s NICK %s",
1548 target_p
->name
, user
, host
, nick
);
1550 /* TODO: send some snotes to SNO_NCHANGE/SNO_CCONN/SNO_CCONNEXT? */
1552 else if(changed_case
)
1554 sendto_common_channels_local(target_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
1555 target_p
->name
, user
, host
, nick
);
1557 if(MyConnect(target_p
))
1558 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
1559 "Nick change: From %s to %s [%s@%s]",
1560 target_p
->name
, nick
,
1561 target_p
->username
, target_p
->host
);
1564 if (user
!= target_p
->username
)
1565 rb_strlcpy(target_p
->username
, user
, sizeof target_p
->username
);
1567 rb_strlcpy(target_p
->host
, host
, sizeof target_p
->host
);
1570 whowas_add_history(target_p
, 1);
1572 del_from_client_hash(target_p
->name
, target_p
);
1573 rb_strlcpy(target_p
->name
, nick
, NICKLEN
);
1574 add_to_client_hash(target_p
->name
, target_p
);
1578 monitor_signon(target_p
);
1579 del_all_accepts(target_p
);