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
;
470 default: /* Unknown, but handle the case properly */
471 if (IsExemptKline(source_p
))
473 sendto_one_notice(source_p
, ":*** You were rejected, but you are exempt (reason: %s)",
478 sendto_realops_snomask(SNO_REJ
, L_NETWIDE
,
479 "Rejected by authentication system (reason %s): %s (%s@%s) [%s] [%s]",
480 reason
, source_p
->name
, source_p
->username
, source_p
->host
,
481 IsIPSpoof(source_p
) ? "255.255.255.255" : source_p
->sockhost
,
484 ServerStats
.is_ref
++;
486 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
487 me
.name
, source_p
->name
, reason
);
489 sendto_one_notice(source_p
, ":*** Rejected by authentication system: %s",
491 add_reject(source_p
, NULL
, NULL
);
492 exit_client(client_p
, source_p
, &me
, "*** Banned (authentication system)");
493 substitution_free(&varlist
);
494 return CLIENT_EXITED
;
498 substitution_free(&varlist
);
501 /* valid user name check */
503 if(!valid_username(source_p
->username
))
505 sendto_realops_snomask(SNO_REJ
, L_ALL
,
506 "Invalid username: %s (%s@%s)",
507 source_p
->name
, source_p
->username
, source_p
->host
);
508 ServerStats
.is_ref
++;
509 sendto_one_notice(source_p
, ":*** Your username is invalid. Please make sure that your username contains "
510 "only alphanumeric characters.");
511 sprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
512 exit_client(client_p
, source_p
, &me
, tmpstr2
);
513 return (CLIENT_EXITED
);
516 /* end of valid user name check */
518 /* Store original hostname -- jilles */
519 rb_strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
521 /* Spoof user@host */
522 if(*source_p
->preClient
->spoofuser
)
523 rb_strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
524 if(*source_p
->preClient
->spoofhost
)
526 rb_strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
527 if (irccmp(source_p
->host
, source_p
->orighost
))
528 SetDynSpoof(source_p
);
531 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
& ~orphaned_umodes
;
533 call_hook(h_new_local_user
, source_p
);
535 /* If they have died in send_* or were thrown out by the
536 * new_local_user hook don't do anything. */
537 if(IsAnyDead(source_p
))
538 return CLIENT_EXITED
;
540 /* To avoid inconsistencies, do not abort the registration
541 * starting from this point -- jilles
543 rb_inet_ntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
545 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
546 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
547 source_p
->name
, source_p
->username
, source_p
->orighost
,
548 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
549 get_client_class(source_p
), source_p
->info
);
551 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
552 "CLICONN %s %s %s %s %s %s 0 %s",
553 source_p
->name
, source_p
->username
, source_p
->orighost
,
554 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
555 get_client_class(source_p
),
556 /* mirc can sometimes send ips here */
557 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
560 add_to_hostname_hash(source_p
->orighost
, source_p
);
562 /* Allocate a UID if it was not previously allocated.
563 * If this already occured, it was probably during SASL auth...
567 strcpy(source_p
->id
, generate_uid());
568 add_to_id_hash(source_p
->id
, source_p
);
572 source_p
->umodes
|= UMODE_SSLCLIENT
;
574 if (source_p
->umodes
& UMODE_INVISIBLE
)
577 s_assert(!IsClient(source_p
));
578 rb_dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
581 source_p
->servptr
= &me
;
582 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
584 /* Increment our total user count here */
585 if(++Count
.total
> Count
.max_tot
)
586 Count
.max_tot
= Count
.total
;
588 Count
.totalrestartcount
++;
590 s_assert(source_p
->localClient
!= NULL
);
592 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
594 Count
.max_loc
= rb_dlink_list_length(&lclient_list
);
595 if(!(Count
.max_loc
% 10))
596 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
597 "New Max Local Clients: %d", Count
.max_loc
);
600 /* they get a reduced limit */
601 if(find_tgchange(source_p
->sockhost
))
602 source_p
->localClient
->targets_free
= TGCHANGE_INITIAL_LOW
;
604 source_p
->localClient
->targets_free
= TGCHANGE_INITIAL
;
606 monitor_signon(source_p
);
607 user_welcome(source_p
);
609 free_pre_client(source_p
);
611 introduce_client(client_p
, source_p
, user
, source_p
->name
, 1);
620 * side effects - This common function introduces a client to the rest
621 * of the net, either from a local client connect or
622 * from a remote connect.
625 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
628 struct Client
*identifyservice_p
;
630 hook_data_umode_changed hdata
;
631 hook_data_client hdata2
;
633 if(MyClient(source_p
))
634 send_umode(source_p
, source_p
, 0, ubuf
);
636 send_umode(NULL
, source_p
, 0, ubuf
);
644 s_assert(has_id(source_p
));
647 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
648 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
649 source_p
->servptr
->id
, nick
,
650 source_p
->hopcount
+ 1,
651 (long) source_p
->tsinfo
, ubuf
,
652 source_p
->username
, source_p
->host
,
653 IsIPSpoof(source_p
) ? "0" : source_p
->sockhost
,
655 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
656 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
659 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
660 ":%s UID %s %d %ld %s %s %s %s %s :%s",
661 source_p
->servptr
->id
, nick
,
662 source_p
->hopcount
+ 1,
663 (long) source_p
->tsinfo
, ubuf
,
664 source_p
->username
, source_p
->host
,
665 IsIPSpoof(source_p
) ? "0" : source_p
->sockhost
,
666 source_p
->id
, source_p
->info
);
668 if(!EmptyString(source_p
->certfp
))
669 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
670 ":%s ENCAP * CERTFP :%s",
671 use_id(source_p
), source_p
->certfp
);
673 if (IsDynSpoof(source_p
))
675 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
676 use_id(source_p
), source_p
->orighost
);
679 if (!EmptyString(source_p
->user
->suser
))
681 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
682 use_id(source_p
), source_p
->user
->suser
);
685 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
687 if (!EmptyString(ConfigFileEntry
.identifyservice
) &&
688 !EmptyString(ConfigFileEntry
.identifycommand
))
690 /* use user@server */
691 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
693 identifyservice_p
= find_named_client(p
+ 1);
695 identifyservice_p
= NULL
;
696 if (identifyservice_p
!= NULL
)
698 if (!EmptyString(source_p
->localClient
->auth_user
))
699 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s %s",
700 get_id(source_p
, identifyservice_p
),
701 ConfigFileEntry
.identifyservice
,
702 ConfigFileEntry
.identifycommand
,
703 source_p
->localClient
->auth_user
,
704 source_p
->localClient
->passwd
);
706 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
707 get_id(source_p
, identifyservice_p
),
708 ConfigFileEntry
.identifyservice
,
709 ConfigFileEntry
.identifycommand
,
710 source_p
->localClient
->passwd
);
713 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
714 rb_free(source_p
->localClient
->passwd
);
715 source_p
->localClient
->passwd
= NULL
;
718 /* let modules providing usermodes know that we've got a new user,
719 * why is this here? -- well, some modules need to be able to send out new
720 * information about a client, so this was the best place to do it
723 hdata
.client
= source_p
;
725 hdata
.oldsnomask
= 0;
726 call_hook(h_umode_changed
, &hdata
);
728 /* On the other hand, some modules need to know when a client is
729 * being introduced, period.
732 hdata2
.client
= client_p
;
733 hdata2
.target
= source_p
;
734 call_hook(h_introduce_client
, &hdata2
);
738 * valid_hostname - check hostname for validity
740 * Inputs - pointer to user
741 * Output - true if valid, false if not
742 * Side effects - NONE
744 * NOTE: this doesn't allow a hostname to begin with a dot and
745 * will not allow more dots than chars.
748 valid_hostname(const char *hostname
)
750 const char *p
= hostname
, *last_slash
= 0;
758 if(!strcmp(hostname
, "localhost"))
761 if('.' == *p
|| ':' == *p
|| '/' == *p
)
768 if(*p
== '.' || *p
== ':')
781 if(last_slash
&& IsDigit(last_slash
[1]))
788 * valid_username - check username for validity
790 * Inputs - pointer to user
791 * Output - true if valid, false if not
792 * Side effects - NONE
794 * Absolutely always reject any '*' '!' '?' '@' in an user name
795 * reject any odd control characters names.
796 * Allow '.' in username to allow for "first.last"
800 valid_username(const char *username
)
803 const char *p
= username
;
813 /* reject usernames that don't start with an alphanum
814 * i.e. reject jokers who have '-@somehost' or '.@somehost'
815 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
822 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
825 if(dots
> ConfigFileEntry
.dots_in_ident
)
827 if(!IsUserChar(p
[1]))
830 else if(!IsUserChar(*p
))
836 /* report_and_set_user_flags
838 * Inputs - pointer to source_p
839 * - pointer to aconf for this user
842 * Report to user any special flags they are getting, and set them.
846 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
848 /* If this user is being spoofed, tell them so */
849 if(IsConfDoSpoofIp(aconf
))
851 sendto_one_notice(source_p
, ":*** Spoofing your IP");
854 /* If this user is in the exception class, Set it "E lined" */
855 if(IsConfExemptKline(aconf
))
857 SetExemptKline(source_p
);
858 sendto_one_notice(source_p
, ":*** You are exempt from K/X lines");
861 if(IsConfExemptDNSBL(aconf
))
862 /* kline exempt implies this, don't send both */
863 if(!IsConfExemptKline(aconf
))
864 sendto_one_notice(source_p
, ":*** You are exempt from DNS blacklists");
866 /* If this user is exempt from user limits set it F lined" */
867 if(IsConfExemptLimits(aconf
))
869 sendto_one_notice(source_p
, ":*** You are exempt from user limits");
872 if(IsConfExemptFlood(aconf
))
874 SetExemptFlood(source_p
);
875 sendto_one_notice(source_p
, ":*** You are exempt from flood limits");
878 if(IsConfExemptSpambot(aconf
))
880 SetExemptSpambot(source_p
);
881 sendto_one_notice(source_p
, ":*** You are exempt from spambot checks");
884 if(IsConfExemptJupe(aconf
))
886 SetExemptJupe(source_p
);
887 sendto_one_notice(source_p
, ":*** You are exempt from juped channel warnings");
890 if(IsConfExemptResv(aconf
))
892 SetExemptResv(source_p
);
893 sendto_one_notice(source_p
, ":*** You are exempt from resvs");
896 if(IsConfExemptShide(aconf
))
898 SetExemptShide(source_p
);
899 sendto_one_notice(source_p
, ":*** You are exempt from serverhiding");
902 if(IsConfExtendChans(aconf
))
904 SetExtendChans(source_p
);
905 sendto_one_notice(source_p
, ":*** You are exempt from normal channel limits");
910 show_other_user_mode(struct Client
*source_p
, struct Client
*target_p
)
919 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
920 if (target_p
->umodes
& user_modes
[i
])
924 if (MyConnect(target_p
) && target_p
->snomask
!= 0)
925 sendto_one_notice(source_p
, ":Modes for %s are %s %s",
927 construct_snobuf(target_p
->snomask
));
929 sendto_one_notice(source_p
, ":Modes for %s are %s",
930 target_p
->name
, buf
);
934 * user_mode - set get current users mode
936 * m_umode() added 15/10/91 By Darren Reed.
937 * parv[1] - username to change mode for
938 * parv[2] - modes to change
941 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
947 struct Client
*target_p
;
949 bool badflag
= false; /* Only send one bad flag notice */
950 bool showsnomask
= false;
951 unsigned int setsnomask
;
953 hook_data_umode_changed hdata
;
959 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
963 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
965 if(MyConnect(source_p
))
966 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
967 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
971 /* Dont know why these were commented out..
972 * put them back using new sendto() funcs
975 if(IsServer(source_p
))
977 sendto_realops_snomask(SNO_GENERAL
, L_ADMIN
,
978 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
982 if(source_p
!= target_p
)
984 if (MyOper(source_p
) && parc
< 3)
985 show_other_user_mode(source_p
, target_p
);
987 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
996 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
997 if (source_p
->umodes
& user_modes
[i
])
1001 sendto_one_numeric(source_p
, RPL_UMODEIS
, form_str(RPL_UMODEIS
), buf
);
1003 if (source_p
->snomask
!= 0)
1004 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1005 construct_snobuf(source_p
->snomask
));
1010 /* find flags already set for user */
1011 setflags
= source_p
->umodes
;
1012 setsnomask
= source_p
->snomask
;
1015 * parse mode change string(s)
1017 for (pm
= parv
[2]; *pm
; pm
++)
1028 if(what
== MODE_ADD
)
1030 if(IsServer(client_p
) && !IsOper(source_p
))
1034 rb_dlinkAddAlloc(source_p
, &oper_list
);
1039 /* Only decrement the oper counts if an oper to begin with
1040 * found by Pat Szuta, Perly , perly@xnet.com
1043 if(!IsOper(source_p
))
1046 ClearOper(source_p
);
1050 if(MyConnect(source_p
))
1052 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
1053 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
1055 source_p
->snomask
= 0;
1058 source_p
->flags2
&= ~OPER_FLAGS
;
1060 rb_free(source_p
->localClient
->opername
);
1061 source_p
->localClient
->opername
= NULL
;
1063 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1064 privilegeset_unref(source_p
->localClient
->privset
);
1065 source_p
->localClient
->privset
= NULL
;
1068 rb_dlinkFindDestroy(source_p
, &oper_list
);
1072 /* we may not get these,
1073 * but they shouldnt be in default
1076 /* can only be set on burst */
1086 if (MyConnect(source_p
))
1088 if(!IsOper(source_p
)
1089 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
1091 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1096 if(what
== MODE_ADD
)
1099 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1101 source_p
->snomask
|= SNO_GENERAL
;
1104 source_p
->snomask
= 0;
1105 if (source_p
->snomask
!= 0)
1106 source_p
->umodes
|= UMODE_SERVNOTICE
;
1108 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1113 if (MyConnect(source_p
) && *pm
== 'Q' && !ConfigChannel
.use_forward
)
1119 if((flag
= user_modes
[(unsigned char) *pm
]))
1121 if(MyConnect(source_p
)
1122 && ((!IsOper(source_p
)
1123 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1124 || (orphaned_umodes
& flag
)))
1126 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1131 if(what
== MODE_ADD
)
1132 source_p
->umodes
|= flag
;
1134 source_p
->umodes
&= ~flag
;
1139 if(MyConnect(source_p
))
1146 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1148 if(MyClient(source_p
) && (source_p
->snomask
& SNO_NCHANGE
) && !IsOperN(source_p
))
1150 sendto_one_notice(source_p
, ":*** You need oper and nick_changes flag for +s +n");
1151 source_p
->snomask
&= ~SNO_NCHANGE
; /* only tcm's really need this */
1154 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1156 sendto_one_notice(source_p
, ":*** You need oper and operwall flag for +z");
1157 source_p
->umodes
&= ~UMODE_OPERWALL
;
1160 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1161 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1163 sendto_one_notice(source_p
, ":*** You need oper and admin flag for +a");
1164 source_p
->umodes
&= ~UMODE_ADMIN
;
1167 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1168 hdata
.client
= source_p
;
1169 hdata
.oldumodes
= setflags
;
1170 hdata
.oldsnomask
= setsnomask
;
1171 call_hook(h_umode_changed
, &hdata
);
1173 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1175 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1178 * compare new flags with old flags and send string which
1179 * will cause servers to update correctly.
1181 send_umode_out(client_p
, source_p
, setflags
);
1182 if (showsnomask
&& MyConnect(source_p
))
1183 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1184 construct_snobuf(source_p
->snomask
));
1190 * send the MODE string for user (user) to connection client_p
1194 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, char *umode_buf
)
1202 * build a string in umode_buf to represent the change in the user's
1203 * mode between the new (source_p->flag) and 'old'.
1208 for (i
= 0; i
< 128; i
++)
1210 flag
= user_modes
[i
];
1212 if((flag
& old
) && !(source_p
->umodes
& flag
))
1214 if(what
== MODE_DEL
)
1223 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1225 if(what
== MODE_ADD
)
1237 if(*umode_buf
&& client_p
)
1238 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1249 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1251 struct Client
*target_p
;
1255 send_umode(NULL
, source_p
, old
, buf
);
1257 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1259 target_p
= ptr
->data
;
1261 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1263 sendto_one(target_p
, ":%s MODE %s :%s",
1264 get_id(source_p
, target_p
),
1265 get_id(source_p
, target_p
), buf
);
1269 if(client_p
&& MyClient(client_p
))
1270 send_umode(client_p
, source_p
, old
, buf
);
1276 * inputs - client pointer to client to welcome
1281 user_welcome(struct Client
*source_p
)
1283 sendto_one_numeric(source_p
, RPL_WELCOME
, form_str(RPL_WELCOME
), ServerInfo
.network_name
, source_p
->name
);
1284 sendto_one_numeric(source_p
, RPL_YOURHOST
, form_str(RPL_YOURHOST
),
1285 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1286 sendto_one_numeric(source_p
, RPL_CREATED
, form_str(RPL_CREATED
), creation
);
1287 sendto_one_numeric(source_p
, RPL_MYINFO
, form_str(RPL_MYINFO
), me
.name
, ircd_version
, umodebuf
, cflagsmyinfo
);
1289 show_isupport(source_p
);
1291 show_lusers(source_p
);
1293 if(ConfigFileEntry
.short_motd
)
1295 sendto_one_notice(source_p
, ":*** Notice -- motd was last changed at %s", user_motd_changed
);
1296 sendto_one_notice(source_p
, ":*** Notice -- Please read the motd if you haven't read it");
1298 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1299 me
.name
, source_p
->name
, me
.name
);
1301 sendto_one(source_p
, form_str(RPL_MOTD
),
1302 me
.name
, source_p
->name
, "*** This is the short motd ***");
1304 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1307 send_user_motd(source_p
);
1312 * inputs - pointer to given client to oper
1313 * - pointer to ConfItem to use
1315 * side effects - opers up source_p using aconf for reference
1318 oper_up(struct Client
*source_p
, struct oper_conf
*oper_p
)
1320 unsigned int old
= source_p
->umodes
, oldsnomask
= source_p
->snomask
;
1321 hook_data_umode_changed hdata
;
1326 source_p
->umodes
|= oper_p
->umodes
;
1327 else if(ConfigFileEntry
.oper_umodes
)
1328 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1330 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1332 if (oper_p
->snomask
)
1334 source_p
->snomask
|= oper_p
->snomask
;
1335 source_p
->umodes
|= UMODE_SERVNOTICE
;
1337 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1339 /* Only apply these if +s is already set -- jilles */
1340 if (ConfigFileEntry
.oper_snomask
)
1341 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1343 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1348 SetExtendChans(source_p
);
1349 SetExemptKline(source_p
);
1351 source_p
->flags2
|= oper_p
->flags
;
1352 source_p
->localClient
->opername
= rb_strdup(oper_p
->name
);
1353 source_p
->localClient
->privset
= privilegeset_ref(oper_p
->privset
);
1355 rb_dlinkAddAlloc(source_p
, &local_oper_list
);
1356 rb_dlinkAddAlloc(source_p
, &oper_list
);
1358 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1359 source_p
->umodes
|= UMODE_ADMIN
;
1360 if(!IsOperN(source_p
))
1361 source_p
->snomask
&= ~SNO_NCHANGE
;
1362 if(!IsOperOperwall(source_p
))
1363 source_p
->umodes
&= ~UMODE_OPERWALL
;
1364 hdata
.client
= source_p
;
1365 hdata
.oldumodes
= old
;
1366 hdata
.oldsnomask
= oldsnomask
;
1367 call_hook(h_umode_changed
, &hdata
);
1369 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1370 "%s (%s!%s@%s) is now an operator", oper_p
->name
, source_p
->name
,
1371 source_p
->username
, source_p
->host
);
1372 if(!(old
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1374 if((old
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1376 send_umode_out(source_p
, source_p
, old
);
1377 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1378 construct_snobuf(source_p
->snomask
));
1379 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1380 sendto_one_notice(source_p
, ":*** Oper privilege set is %s", oper_p
->privset
->name
);
1381 sendto_one_notice(source_p
, ":*** Oper privs are %s", oper_p
->privset
->privs
);
1382 send_oper_motd(source_p
);
1389 * outputs - an available umode bitmask or
1390 * 0 if no umodes are available
1391 * side effects - NONE
1394 find_umode_slot(void)
1396 unsigned int all_umodes
= 0, my_umode
= 0, i
;
1398 for (i
= 0; i
< 128; i
++)
1399 all_umodes
|= user_modes
[i
];
1401 for (my_umode
= 1; my_umode
&& (all_umodes
& my_umode
);
1408 construct_umodebuf(void)
1411 char *ptr
= umodebuf
;
1412 static int prev_user_modes
[128];
1416 for (i
= 0; i
< 128; i
++)
1418 if (prev_user_modes
[i
] != 0 && prev_user_modes
[i
] != user_modes
[i
])
1420 if (user_modes
[i
] == 0)
1422 orphaned_umodes
|= prev_user_modes
[i
];
1423 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Umode +%c is now orphaned", i
);
1427 orphaned_umodes
&= ~prev_user_modes
[i
];
1428 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Orphaned umode +%c is picked up by module", i
);
1430 user_modes
[i
] = prev_user_modes
[i
];
1433 prev_user_modes
[i
] = user_modes
[i
];
1442 change_nick_user_host(struct Client
*target_p
, const char *nick
, const char *user
,
1443 const char *host
, int newts
, const char *format
, ...)
1446 struct Channel
*chptr
;
1447 struct membership
*mscptr
;
1448 int changed
= irccmp(target_p
->name
, nick
);
1449 int changed_case
= strcmp(target_p
->name
, nick
);
1450 int do_qjm
= irccmp(target_p
->username
, user
) || irccmp(target_p
->host
, host
);
1451 char mode
[10], modeval
[NICKLEN
* 2 + 2], reason
[256], *mptr
;
1458 target_p
->tsinfo
= newts
;
1459 monitor_signoff(target_p
);
1461 invalidate_bancache_user(target_p
);
1465 va_start(ap
, format
);
1466 vsnprintf(reason
, 255, format
, ap
);
1469 sendto_common_channels_local_butone(target_p
, NOCAPS
, CLICAP_CHGHOST
, ":%s!%s@%s QUIT :%s",
1470 target_p
->name
, target_p
->username
, target_p
->host
,
1473 RB_DLINK_FOREACH(ptr
, target_p
->user
->channel
.head
)
1476 chptr
= mscptr
->chptr
;
1479 if(is_chanop(mscptr
))
1482 strcat(modeval
, nick
);
1483 strcat(modeval
, " ");
1486 if(is_voiced(mscptr
))
1489 strcat(modeval
, nick
);
1494 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, NOCAPS
, CLICAP_EXTENDED_JOIN
| CLICAP_CHGHOST
, chptr
,
1495 ":%s!%s@%s JOIN %s", nick
, user
, host
, chptr
->chname
);
1496 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, CLICAP_EXTENDED_JOIN
, CLICAP_CHGHOST
, chptr
,
1497 ":%s!%s@%s JOIN %s %s :%s", nick
, user
, host
, chptr
->chname
,
1498 EmptyString(target_p
->user
->suser
) ? "*" : target_p
->user
->suser
,
1502 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, NOCAPS
, CLICAP_CHGHOST
, chptr
,
1503 ":%s MODE %s +%s %s", target_p
->servptr
->name
, chptr
->chname
, mode
, modeval
);
1508 /* Resend away message to away-notify enabled clients. */
1509 if (target_p
->user
->away
)
1510 sendto_common_channels_local_butone(target_p
, CLICAP_AWAY_NOTIFY
, CLICAP_CHGHOST
, ":%s!%s@%s AWAY :%s",
1512 target_p
->user
->away
);
1514 sendto_common_channels_local_butone(target_p
, CLICAP_CHGHOST
, NOCAPS
,
1515 ":%s!%s@%s CHGHOST %s %s",
1516 target_p
->name
, target_p
->username
, target_p
->host
, user
, host
);
1518 if(MyClient(target_p
) && changed_case
)
1519 sendto_one(target_p
, ":%s!%s@%s NICK %s",
1520 target_p
->name
, user
, host
, nick
);
1522 /* TODO: send some snotes to SNO_NCHANGE/SNO_CCONN/SNO_CCONNEXT? */
1524 else if(changed_case
)
1526 sendto_common_channels_local(target_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
1527 target_p
->name
, user
, host
, nick
);
1529 if(MyConnect(target_p
))
1530 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
1531 "Nick change: From %s to %s [%s@%s]",
1532 target_p
->name
, nick
,
1533 target_p
->username
, target_p
->host
);
1536 if (user
!= target_p
->username
)
1537 rb_strlcpy(target_p
->username
, user
, sizeof target_p
->username
);
1539 rb_strlcpy(target_p
->host
, host
, sizeof target_p
->host
);
1542 whowas_add_history(target_p
, 1);
1544 del_from_client_hash(target_p
->name
, target_p
);
1545 rb_strlcpy(target_p
->name
, nick
, NICKLEN
);
1546 add_to_client_hash(target_p
->name
, target_p
);
1550 monitor_signon(target_p
);
1551 del_all_accepts(target_p
);