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"
58 static void report_and_set_user_flags(struct Client
*, struct ConfItem
*);
59 void user_welcome(struct Client
*source_p
);
63 static int orphaned_umodes
= 0;
64 int user_modes
[256] = {
65 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
66 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
67 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
68 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
86 UMODE_NOFORWARD
, /* Q */
87 UMODE_REGONLYMSG
, /* R */
88 UMODE_SERVICE
, /* S */
95 UMODE_SSLCLIENT
, /* Z */
96 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
103 UMODE_CALLERID
, /* g */
105 UMODE_INVISIBLE
, /* i */
108 UMODE_LOCOPS
, /* l */
115 UMODE_SERVNOTICE
, /* s */
119 UMODE_WALLOP
, /* w */
122 UMODE_OPERWALL
, /* z */
123 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
124 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
125 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
126 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
127 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
128 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
129 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
130 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
131 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
138 * inputs - pointer to client
140 * side effects - display to client user counts etc.
143 show_lusers(struct Client
*source_p
)
145 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)MaxClientCount
)
146 MaxClientCount
= rb_dlink_list_length(&lclient_list
);
148 if((rb_dlink_list_length(&lclient_list
) + rb_dlink_list_length(&serv_list
)) >
149 (unsigned long)MaxConnectionCount
)
150 MaxConnectionCount
= rb_dlink_list_length(&lclient_list
) +
151 rb_dlink_list_length(&serv_list
);
153 sendto_one_numeric(source_p
, RPL_LUSERCLIENT
, form_str(RPL_LUSERCLIENT
),
154 (Count
.total
- Count
.invisi
),
156 (int)rb_dlink_list_length(&global_serv_list
));
158 if(rb_dlink_list_length(&oper_list
) > 0)
159 sendto_one_numeric(source_p
, RPL_LUSEROP
,
160 form_str(RPL_LUSEROP
), rb_dlink_list_length(&oper_list
));
162 if(rb_dlink_list_length(&unknown_list
) > 0)
163 sendto_one_numeric(source_p
, RPL_LUSERUNKNOWN
,
164 form_str(RPL_LUSERUNKNOWN
),
165 (int)rb_dlink_list_length(&unknown_list
));
167 if(rb_dlink_list_length(&global_channel_list
) > 0)
168 sendto_one_numeric(source_p
, RPL_LUSERCHANNELS
,
169 form_str(RPL_LUSERCHANNELS
),
170 rb_dlink_list_length(&global_channel_list
));
172 sendto_one_numeric(source_p
, RPL_LUSERME
, form_str(RPL_LUSERME
),
173 (int)rb_dlink_list_length(&lclient_list
),
174 (int)rb_dlink_list_length(&serv_list
));
176 sendto_one_numeric(source_p
, RPL_LOCALUSERS
,
177 form_str(RPL_LOCALUSERS
),
178 (int)rb_dlink_list_length(&lclient_list
),
180 (int)rb_dlink_list_length(&lclient_list
),
183 sendto_one_numeric(source_p
, RPL_GLOBALUSERS
, form_str(RPL_GLOBALUSERS
),
184 Count
.total
, Count
.max_tot
,
185 Count
.total
, Count
.max_tot
);
187 sendto_one_numeric(source_p
, RPL_STATSCONN
,
188 form_str(RPL_STATSCONN
),
189 MaxConnectionCount
, MaxClientCount
,
190 Count
.totalrestartcount
);
196 ** register_local_user
197 ** This function is called when both NICK and USER messages
198 ** have been accepted for the client, in whatever order. Only
199 ** after this, is the USER message propagated.
201 ** NICK's must be propagated at once when received, although
202 ** it would be better to delay them too until full info is
203 ** available. Doing it is not so simple though, would have
204 ** to implement the following:
206 ** (actually it has been implemented already for a while) -orabidoo
208 ** 1) user telnets in and gives only "NICK foobar" and waits
209 ** 2) another user far away logs in normally with the nick
210 ** "foobar" (quite legal, as this server didn't propagate
212 ** 3) now this server gets nick "foobar" from outside, but
213 ** has alread the same defined locally. Current server
214 ** would just issue "KILL foobar" to clean out dups. But,
215 ** this is not fair. It should actually request another
216 ** nick from local user or kill him/her...
220 register_local_user(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
222 struct ConfItem
*aconf
, *xconf
;
223 struct User
*user
= source_p
->user
;
224 char tmpstr2
[IRCD_BUFSIZE
];
225 char ipaddr
[HOSTIPLEN
];
226 char myusername
[USERLEN
+1];
229 s_assert(NULL
!= source_p
);
230 s_assert(MyConnect(source_p
));
231 s_assert(source_p
->username
!= username
);
236 if(IsAnyDead(source_p
))
239 if(ConfigFileEntry
.ping_cookie
)
241 if(!(source_p
->flags
& FLAGS_PINGSENT
) && source_p
->localClient
->random_ping
== 0)
243 source_p
->localClient
->random_ping
= (unsigned long) (rand() * rand()) << 1;
244 sendto_one(source_p
, "PING :%08lX",
245 (unsigned long) source_p
->localClient
->random_ping
);
246 source_p
->flags
|= FLAGS_PINGSENT
;
249 if(!(source_p
->flags
& FLAGS_PING_COOKIE
))
255 /* hasnt finished client cap negotiation */
256 if(source_p
->flags
& FLAGS_CLICAP
)
259 /* still has DNSbls to validate against */
260 if(rb_dlink_list_length(&source_p
->preClient
->dnsbl_queries
) > 0)
263 client_p
->localClient
->last
= rb_current_time();
265 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
266 if(!IsGotId(source_p
) && (strchr(username
, '[') != NULL
))
273 while(*p
&& i
< USERLEN
)
276 myusername
[i
++] = *p
;
280 myusername
[i
] = '\0';
281 username
= myusername
;
284 if((status
= check_client(client_p
, source_p
, username
)) < 0)
285 return (CLIENT_EXITED
);
287 /* Apply nick override */
288 if(*source_p
->preClient
->spoofnick
)
290 char note
[NICKLEN
+ 10];
292 del_from_client_hash(source_p
->name
, source_p
);
293 rb_strlcpy(source_p
->name
, source_p
->preClient
->spoofnick
, NICKLEN
+ 1);
294 add_to_client_hash(source_p
->name
, source_p
);
296 rb_snprintf(note
, NICKLEN
+ 10, "Nick: %s", source_p
->name
);
297 rb_note(source_p
->localClient
->F
, note
);
300 if(!valid_hostname(source_p
->host
))
302 sendto_one_notice(source_p
, ":*** Notice -- You have an illegal character in your hostname");
304 rb_strlcpy(source_p
->host
, source_p
->sockhost
, sizeof(source_p
->host
));
308 aconf
= source_p
->localClient
->att_conf
;
312 exit_client(client_p
, source_p
, &me
, "*** Not Authorised");
313 return (CLIENT_EXITED
);
316 if(IsConfSSLNeeded(aconf
) && !IsSSL(source_p
))
318 ServerStats
.is_ref
++;
319 sendto_one_notice(source_p
, ":*** Notice -- You need to use SSL/TLS to use this server");
320 exit_client(client_p
, source_p
, &me
, "Use SSL/TLS");
321 return (CLIENT_EXITED
);
324 if(!IsGotId(source_p
))
329 if(IsNeedIdentd(aconf
))
331 ServerStats
.is_ref
++;
332 sendto_one_notice(source_p
, ":*** Notice -- You need to install identd to use this server");
333 exit_client(client_p
, source_p
, &me
, "Install identd");
334 return (CLIENT_EXITED
);
337 /* dont replace username if its supposed to be spoofed --fl */
338 if(!IsConfDoSpoofIp(aconf
) || !strchr(aconf
->info
.name
, '@'))
342 if(!IsNoTilde(aconf
))
343 source_p
->username
[i
++] = '~';
345 while (*p
&& i
< USERLEN
)
348 source_p
->username
[i
++] = *p
;
352 source_p
->username
[i
] = '\0';
356 if(IsNeedSasl(aconf
) && !*user
->suser
)
358 ServerStats
.is_ref
++;
359 sendto_one_notice(source_p
, ":*** Notice -- You need to identify via SASL to use this server");
360 exit_client(client_p
, source_p
, &me
, "SASL access only");
361 return (CLIENT_EXITED
);
365 if(!EmptyString(aconf
->passwd
))
369 if(EmptyString(source_p
->localClient
->passwd
))
371 else if(IsConfEncrypted(aconf
))
372 encr
= rb_crypt(source_p
->localClient
->passwd
, aconf
->passwd
);
374 encr
= source_p
->localClient
->passwd
;
376 if(encr
== NULL
|| strcmp(encr
, aconf
->passwd
))
378 ServerStats
.is_ref
++;
379 sendto_one(source_p
, form_str(ERR_PASSWDMISMATCH
), me
.name
, source_p
->name
);
380 exit_client(client_p
, source_p
, &me
, "Bad Password");
381 return (CLIENT_EXITED
);
384 /* clear password only if used now, otherwise send it
385 * to services -- jilles */
386 if(source_p
->localClient
->passwd
)
388 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
389 rb_free(source_p
->localClient
->passwd
);
390 source_p
->localClient
->passwd
= NULL
;
394 /* report if user has &^>= etc. and set flags as needed in source_p */
395 report_and_set_user_flags(source_p
, aconf
);
399 * We want to be able to have servers and F-line clients
400 * connect, so save room for "buffer" connections.
401 * Smaller servers may want to decrease this, and it should
402 * probably be just a percentage of the MAXCLIENTS...
405 /* Except "F:" clients */
406 if(rb_dlink_list_length(&lclient_list
) >=
407 (unsigned long)GlobalSetOptions
.maxclients
&& !IsConfExemptLimits(aconf
))
409 sendto_realops_snomask(SNO_FULL
, L_ALL
,
410 "Too many clients, rejecting %s[%s].", source_p
->name
, source_p
->host
);
412 ServerStats
.is_ref
++;
413 exit_client(client_p
, source_p
, &me
, "Sorry, server is full - try later");
414 return (CLIENT_EXITED
);
417 /* kline exemption extends to xline too */
418 if(!IsExemptKline(source_p
) &&
419 (xconf
= find_xline(source_p
->info
, 1)) != NULL
)
421 ServerStats
.is_ref
++;
422 add_reject(source_p
, xconf
->host
, NULL
);
423 exit_client(client_p
, source_p
, &me
, "Bad user info");
424 return CLIENT_EXITED
;
428 if (source_p
->preClient
->dnsbl_listed
!= NULL
)
430 if (IsExemptKline(source_p
) || IsConfExemptDNSBL(aconf
))
431 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s, but you are exempt",
432 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
435 rb_dlink_list varlist
= { NULL
, NULL
, 0 };
437 substitution_append_var(&varlist
, "nick", source_p
->name
);
438 substitution_append_var(&varlist
, "ip", source_p
->sockhost
);
439 substitution_append_var(&varlist
, "host", source_p
->host
);
440 substitution_append_var(&varlist
, "dnsbl-host", source_p
->preClient
->dnsbl_listed
->host
);
441 substitution_append_var(&varlist
, "network-name", ServerInfo
.network_name
);
443 ServerStats
.is_ref
++;
445 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
446 me
.name
, source_p
->name
,
447 substitution_parse(source_p
->preClient
->dnsbl_listed
->reject_reason
, &varlist
));
449 substitution_free(&varlist
);
451 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s",
452 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
453 source_p
->preClient
->dnsbl_listed
->hits
++;
454 add_reject(source_p
, NULL
, NULL
);
455 exit_client(client_p
, source_p
, &me
, "*** Banned (DNS blacklist)");
456 return CLIENT_EXITED
;
460 /* valid user name check */
462 if(!valid_username(source_p
->username
))
464 sendto_realops_snomask(SNO_REJ
, L_ALL
,
465 "Invalid username: %s (%s@%s)",
466 source_p
->name
, source_p
->username
, source_p
->host
);
467 ServerStats
.is_ref
++;
468 sendto_one_notice(source_p
, ":*** Your username is invalid. Please make sure that your username contains "
469 "only alphanumeric characters.");
470 rb_sprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
471 exit_client(client_p
, source_p
, &me
, tmpstr2
);
472 return (CLIENT_EXITED
);
475 /* end of valid user name check */
477 /* Store original hostname -- jilles */
478 rb_strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
480 /* Spoof user@host */
481 if(*source_p
->preClient
->spoofuser
)
482 rb_strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
483 if(*source_p
->preClient
->spoofhost
)
485 rb_strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
486 if (irccmp(source_p
->host
, source_p
->orighost
))
487 SetDynSpoof(source_p
);
490 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
& ~orphaned_umodes
;
492 call_hook(h_new_local_user
, source_p
);
494 /* If they have died in send_* or were thrown out by the
495 * new_local_user hook don't do anything. */
496 if(IsAnyDead(source_p
))
497 return CLIENT_EXITED
;
499 /* To avoid inconsistencies, do not abort the registration
500 * starting from this point -- jilles
502 rb_inet_ntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
504 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
505 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
506 source_p
->name
, source_p
->username
, source_p
->orighost
,
507 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
508 get_client_class(source_p
), source_p
->info
);
510 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
511 "CLICONN %s %s %s %s %s %s 0 %s",
512 source_p
->name
, source_p
->username
, source_p
->orighost
,
513 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
514 get_client_class(source_p
),
515 /* mirc can sometimes send ips here */
516 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
519 add_to_hostname_hash(source_p
->orighost
, source_p
);
521 /* Allocate a UID if it was not previously allocated.
522 * If this already occured, it was probably during SASL auth...
526 strcpy(source_p
->id
, generate_uid());
527 add_to_id_hash(source_p
->id
, source_p
);
531 source_p
->umodes
|= UMODE_SSLCLIENT
;
533 if (source_p
->umodes
& UMODE_INVISIBLE
)
536 s_assert(!IsClient(source_p
));
537 rb_dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
540 source_p
->servptr
= &me
;
541 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
543 /* Increment our total user count here */
544 if(++Count
.total
> Count
.max_tot
)
545 Count
.max_tot
= Count
.total
;
547 Count
.totalrestartcount
++;
549 s_assert(source_p
->localClient
!= NULL
);
551 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
553 Count
.max_loc
= rb_dlink_list_length(&lclient_list
);
554 if(!(Count
.max_loc
% 10))
555 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
556 "New Max Local Clients: %d", Count
.max_loc
);
559 /* they get a reduced limit */
560 if(find_tgchange(source_p
->sockhost
))
561 source_p
->localClient
->targets_free
= TGCHANGE_INITIAL_LOW
;
563 source_p
->localClient
->targets_free
= TGCHANGE_INITIAL
;
565 monitor_signon(source_p
);
566 user_welcome(source_p
);
568 free_pre_client(source_p
);
570 return (introduce_client(client_p
, source_p
, user
, source_p
->name
, 1));
578 * side effects - This common function introduces a client to the rest
579 * of the net, either from a local client connect or
580 * from a remote connect.
583 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
585 static char ubuf
[12];
586 struct Client
*identifyservice_p
;
588 hook_data_umode_changed hdata
;
589 hook_data_client hdata2
;
590 char sockhost
[HOSTLEN
];
592 if(MyClient(source_p
))
593 send_umode(source_p
, source_p
, 0, 0, ubuf
);
595 send_umode(NULL
, source_p
, 0, 0, ubuf
);
603 s_assert(has_id(source_p
));
605 if(source_p
->sockhost
[0] == ':')
609 rb_strlcat(sockhost
, source_p
->sockhost
, sizeof(sockhost
));
611 strcpy(sockhost
, source_p
->sockhost
);
614 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
615 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
616 source_p
->servptr
->id
, nick
,
617 source_p
->hopcount
+ 1,
618 (long) source_p
->tsinfo
, ubuf
,
619 source_p
->username
, source_p
->host
,
620 IsIPSpoof(source_p
) ? "0" : sockhost
,
622 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
623 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
626 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
627 ":%s UID %s %d %ld %s %s %s %s %s :%s",
628 source_p
->servptr
->id
, nick
,
629 source_p
->hopcount
+ 1,
630 (long) source_p
->tsinfo
, ubuf
,
631 source_p
->username
, source_p
->host
,
632 IsIPSpoof(source_p
) ? "0" : sockhost
,
633 source_p
->id
, source_p
->info
);
635 if(!EmptyString(source_p
->certfp
))
636 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
637 ":%s ENCAP * CERTFP :%s",
638 use_id(source_p
), source_p
->certfp
);
640 if (IsDynSpoof(source_p
))
642 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
643 use_id(source_p
), source_p
->orighost
);
646 if (!EmptyString(source_p
->user
->suser
))
648 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
649 use_id(source_p
), source_p
->user
->suser
);
652 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
654 if (!EmptyString(ConfigFileEntry
.identifyservice
) &&
655 !EmptyString(ConfigFileEntry
.identifycommand
))
657 /* use user@server */
658 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
660 identifyservice_p
= find_named_client(p
+ 1);
662 identifyservice_p
= NULL
;
663 if (identifyservice_p
!= NULL
)
665 if (!EmptyString(source_p
->localClient
->auth_user
))
666 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s %s",
667 get_id(source_p
, identifyservice_p
),
668 ConfigFileEntry
.identifyservice
,
669 ConfigFileEntry
.identifycommand
,
670 source_p
->localClient
->auth_user
,
671 source_p
->localClient
->passwd
);
673 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
674 get_id(source_p
, identifyservice_p
),
675 ConfigFileEntry
.identifyservice
,
676 ConfigFileEntry
.identifycommand
,
677 source_p
->localClient
->passwd
);
680 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
681 rb_free(source_p
->localClient
->passwd
);
682 source_p
->localClient
->passwd
= NULL
;
685 /* let modules providing usermodes know that we've got a new user,
686 * why is this here? -- well, some modules need to be able to send out new
687 * information about a client, so this was the best place to do it
690 hdata
.client
= source_p
;
692 hdata
.oldsnomask
= 0;
693 call_hook(h_umode_changed
, &hdata
);
695 /* On the other hand, some modules need to know when a client is
696 * being introduced, period.
699 hdata2
.client
= client_p
;
700 hdata2
.target
= source_p
;
701 call_hook(h_introduce_client
, &hdata2
);
707 * valid_hostname - check hostname for validity
709 * Inputs - pointer to user
710 * Output - YES if valid, NO if not
711 * Side effects - NONE
713 * NOTE: this doesn't allow a hostname to begin with a dot and
714 * will not allow more dots than chars.
717 valid_hostname(const char *hostname
)
719 const char *p
= hostname
, *last_slash
= 0;
727 if('.' == *p
|| ':' == *p
|| '/' == *p
)
734 if(*p
== '.' || *p
== ':')
747 if(last_slash
&& IsDigit(last_slash
[1]))
754 * valid_username - check username for validity
756 * Inputs - pointer to user
757 * Output - YES if valid, NO if not
758 * Side effects - NONE
760 * Absolutely always reject any '*' '!' '?' '@' in an user name
761 * reject any odd control characters names.
762 * Allow '.' in username to allow for "first.last"
766 valid_username(const char *username
)
769 const char *p
= username
;
779 /* reject usernames that don't start with an alphanum
780 * i.e. reject jokers who have '-@somehost' or '.@somehost'
781 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
788 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
791 if(dots
> ConfigFileEntry
.dots_in_ident
)
793 if(!IsUserChar(p
[1]))
796 else if(!IsUserChar(*p
))
802 /* report_and_set_user_flags
804 * Inputs - pointer to source_p
805 * - pointer to aconf for this user
808 * Report to user any special flags they are getting, and set them.
812 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
814 /* If this user is being spoofed, tell them so */
815 if(IsConfDoSpoofIp(aconf
))
817 sendto_one_notice(source_p
, ":*** Spoofing your IP");
820 /* If this user is in the exception class, Set it "E lined" */
821 if(IsConfExemptKline(aconf
))
823 SetExemptKline(source_p
);
824 sendto_one_notice(source_p
, ":*** You are exempt from K/X lines");
827 if(IsConfExemptDNSBL(aconf
))
828 /* kline exempt implies this, don't send both */
829 if(!IsConfExemptKline(aconf
))
830 sendto_one_notice(source_p
, ":*** You are exempt from DNS blacklists");
832 /* If this user is exempt from user limits set it F lined" */
833 if(IsConfExemptLimits(aconf
))
835 sendto_one_notice(source_p
, ":*** You are exempt from user limits");
838 if(IsConfExemptFlood(aconf
))
840 SetExemptFlood(source_p
);
841 sendto_one_notice(source_p
, ":*** You are exempt from flood limits");
844 if(IsConfExemptSpambot(aconf
))
846 SetExemptSpambot(source_p
);
847 sendto_one_notice(source_p
, ":*** You are exempt from spambot checks");
850 if(IsConfExemptJupe(aconf
))
852 SetExemptJupe(source_p
);
853 sendto_one_notice(source_p
, ":*** You are exempt from juped channel warnings");
856 if(IsConfExemptResv(aconf
))
858 SetExemptResv(source_p
);
859 sendto_one_notice(source_p
, ":*** You are exempt from resvs");
862 if(IsConfExemptShide(aconf
))
864 SetExemptShide(source_p
);
865 sendto_one_notice(source_p
, ":*** You are exempt from serverhiding");
870 show_other_user_mode(struct Client
*source_p
, struct Client
*target_p
)
879 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
880 if (target_p
->umodes
& user_modes
[i
])
884 if (MyConnect(target_p
) && target_p
->snomask
!= 0)
885 sendto_one_notice(source_p
, ":Modes for %s are %s %s",
887 construct_snobuf(target_p
->snomask
));
889 sendto_one_notice(source_p
, ":Modes for %s are %s",
890 target_p
->name
, buf
);
894 * user_mode - set get current users mode
896 * m_umode() added 15/10/91 By Darren Reed.
897 * parv[1] - username to change mode for
898 * parv[2] - modes to change
901 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
907 struct Client
*target_p
;
909 int badflag
= NO
; /* Only send one bad flag notice */
910 int showsnomask
= NO
;
911 unsigned int setsnomask
;
913 hook_data_umode_changed hdata
;
919 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
923 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
925 if(MyConnect(source_p
))
926 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
927 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
931 /* Dont know why these were commented out..
932 * put them back using new sendto() funcs
935 if(IsServer(source_p
))
937 sendto_realops_snomask(SNO_GENERAL
, L_ADMIN
,
938 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
942 if(source_p
!= target_p
)
944 if (MyOper(source_p
) && parc
< 3)
945 show_other_user_mode(source_p
, target_p
);
947 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
956 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
957 if (source_p
->umodes
& user_modes
[i
])
961 sendto_one_numeric(source_p
, RPL_UMODEIS
, form_str(RPL_UMODEIS
), buf
);
963 if (source_p
->snomask
!= 0)
964 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
965 construct_snobuf(source_p
->snomask
));
970 /* find flags already set for user */
971 setflags
= source_p
->umodes
;
972 setsnomask
= source_p
->snomask
;
975 * parse mode change string(s)
977 for (pm
= parv
[2]; *pm
; pm
++)
990 if(IsServer(client_p
) && !IsOper(source_p
))
994 rb_dlinkAddAlloc(source_p
, &oper_list
);
999 /* Only decrement the oper counts if an oper to begin with
1000 * found by Pat Szuta, Perly , perly@xnet.com
1003 if(!IsOper(source_p
))
1006 ClearOper(source_p
);
1010 if(MyConnect(source_p
))
1012 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
1013 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
1015 source_p
->snomask
= 0;
1018 source_p
->flags2
&= ~OPER_FLAGS
;
1020 rb_free(source_p
->localClient
->opername
);
1021 source_p
->localClient
->opername
= NULL
;
1023 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1024 privilegeset_unref(source_p
->localClient
->privset
);
1025 source_p
->localClient
->privset
= NULL
;
1028 rb_dlinkFindDestroy(source_p
, &oper_list
);
1032 /* we may not get these,
1033 * but they shouldnt be in default
1036 /* can only be set on burst */
1046 if (MyConnect(source_p
))
1048 if(!IsOper(source_p
)
1049 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
1051 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1056 if(what
== MODE_ADD
)
1059 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1061 source_p
->snomask
|= SNO_GENERAL
;
1064 source_p
->snomask
= 0;
1065 if (source_p
->snomask
!= 0)
1066 source_p
->umodes
|= UMODE_SERVNOTICE
;
1068 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1073 if (MyConnect(source_p
) && *pm
== 'Q' && !ConfigChannel
.use_forward
)
1079 if((flag
= user_modes
[(unsigned char) *pm
]))
1081 if(MyConnect(source_p
)
1082 && ((!IsOper(source_p
)
1083 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1084 || (orphaned_umodes
& flag
)))
1086 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1091 if(what
== MODE_ADD
)
1092 source_p
->umodes
|= flag
;
1094 source_p
->umodes
&= ~flag
;
1099 if(MyConnect(source_p
))
1106 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1108 if(MyClient(source_p
) && (source_p
->snomask
& SNO_NCHANGE
) && !IsOperN(source_p
))
1110 sendto_one_notice(source_p
, ":*** You need oper and nick_changes flag for +s +n");
1111 source_p
->snomask
&= ~SNO_NCHANGE
; /* only tcm's really need this */
1114 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1116 sendto_one_notice(source_p
, ":*** You need oper and operwall flag for +z");
1117 source_p
->umodes
&= ~UMODE_OPERWALL
;
1120 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1121 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1123 sendto_one_notice(source_p
, ":*** You need oper and admin flag for +a");
1124 source_p
->umodes
&= ~UMODE_ADMIN
;
1127 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1128 hdata
.client
= source_p
;
1129 hdata
.oldumodes
= setflags
;
1130 hdata
.oldsnomask
= setsnomask
;
1131 call_hook(h_umode_changed
, &hdata
);
1133 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1135 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1138 * compare new flags with old flags and send string which
1139 * will cause servers to update correctly.
1141 send_umode_out(client_p
, source_p
, setflags
);
1142 if (showsnomask
&& MyConnect(source_p
))
1143 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1144 construct_snobuf(source_p
->snomask
));
1150 * send the MODE string for user (user) to connection client_p
1154 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, int sendmask
, char *umode_buf
)
1162 * build a string in umode_buf to represent the change in the user's
1163 * mode between the new (source_p->flag) and 'old'.
1168 for (i
= 0; i
< 128; i
++)
1170 flag
= user_modes
[i
];
1172 if((flag
& old
) && !(source_p
->umodes
& flag
))
1174 if(what
== MODE_DEL
)
1183 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1185 if(what
== MODE_ADD
)
1197 if(*umode_buf
&& client_p
)
1198 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1209 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1211 struct Client
*target_p
;
1215 send_umode(NULL
, source_p
, old
, 0, buf
);
1217 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1219 target_p
= ptr
->data
;
1221 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1223 sendto_one(target_p
, ":%s MODE %s :%s",
1224 get_id(source_p
, target_p
),
1225 get_id(source_p
, target_p
), buf
);
1229 if(client_p
&& MyClient(client_p
))
1230 send_umode(client_p
, source_p
, old
, 0, buf
);
1236 * inputs - client pointer to client to welcome
1241 user_welcome(struct Client
*source_p
)
1243 sendto_one_numeric(source_p
, RPL_WELCOME
, form_str(RPL_WELCOME
), ServerInfo
.network_name
, source_p
->name
);
1244 sendto_one_numeric(source_p
, RPL_YOURHOST
, form_str(RPL_YOURHOST
),
1245 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1246 sendto_one_numeric(source_p
, RPL_CREATED
, form_str(RPL_CREATED
), creation
);
1247 sendto_one_numeric(source_p
, RPL_MYINFO
, form_str(RPL_MYINFO
), me
.name
, ircd_version
, umodebuf
, cflagsmyinfo
);
1249 show_isupport(source_p
);
1251 show_lusers(source_p
);
1253 if(ConfigFileEntry
.short_motd
)
1255 sendto_one_notice(source_p
, ":*** Notice -- motd was last changed at %s", user_motd_changed
);
1256 sendto_one_notice(source_p
, ":*** Notice -- Please read the motd if you haven't read it");
1258 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1259 me
.name
, source_p
->name
, me
.name
);
1261 sendto_one(source_p
, form_str(RPL_MOTD
),
1262 me
.name
, source_p
->name
, "*** This is the short motd ***");
1264 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1267 send_user_motd(source_p
);
1272 * inputs - pointer to given client to oper
1273 * - pointer to ConfItem to use
1275 * side effects - opers up source_p using aconf for reference
1278 oper_up(struct Client
*source_p
, struct oper_conf
*oper_p
)
1280 unsigned int old
= source_p
->umodes
, oldsnomask
= source_p
->snomask
;
1281 hook_data_umode_changed hdata
;
1286 source_p
->umodes
|= oper_p
->umodes
;
1287 else if(ConfigFileEntry
.oper_umodes
)
1288 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1290 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1292 if (oper_p
->snomask
)
1294 source_p
->snomask
|= oper_p
->snomask
;
1295 source_p
->umodes
|= UMODE_SERVNOTICE
;
1297 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1299 /* Only apply these if +s is already set -- jilles */
1300 if (ConfigFileEntry
.oper_snomask
)
1301 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1303 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1308 SetExemptKline(source_p
);
1310 source_p
->flags2
|= oper_p
->flags
;
1311 source_p
->localClient
->opername
= rb_strdup(oper_p
->name
);
1312 source_p
->localClient
->privset
= privilegeset_ref(oper_p
->privset
);
1314 rb_dlinkAddAlloc(source_p
, &local_oper_list
);
1315 rb_dlinkAddAlloc(source_p
, &oper_list
);
1317 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1318 source_p
->umodes
|= UMODE_ADMIN
;
1319 if(!IsOperN(source_p
))
1320 source_p
->snomask
&= ~SNO_NCHANGE
;
1321 if(!IsOperOperwall(source_p
))
1322 source_p
->umodes
&= ~UMODE_OPERWALL
;
1323 hdata
.client
= source_p
;
1324 hdata
.oldumodes
= old
;
1325 hdata
.oldsnomask
= oldsnomask
;
1326 call_hook(h_umode_changed
, &hdata
);
1328 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1329 "%s (%s!%s@%s) is now an operator", oper_p
->name
, source_p
->name
,
1330 source_p
->username
, source_p
->host
);
1331 if(!(old
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1333 if((old
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1335 send_umode_out(source_p
, source_p
, old
);
1336 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1337 construct_snobuf(source_p
->snomask
));
1338 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1339 sendto_one_notice(source_p
, ":*** Oper privilege set is %s", oper_p
->privset
->name
);
1340 sendto_one_notice(source_p
, ":*** Oper privs are %s", oper_p
->privset
->privs
);
1341 send_oper_motd(source_p
);
1350 * outputs - an available umode bitmask or
1351 * 0 if no umodes are available
1352 * side effects - NONE
1355 find_umode_slot(void)
1357 unsigned int all_umodes
= 0, my_umode
= 0, i
;
1359 for (i
= 0; i
< 128; i
++)
1360 all_umodes
|= user_modes
[i
];
1362 for (my_umode
= 1; my_umode
&& (all_umodes
& my_umode
);
1369 construct_umodebuf(void)
1372 char *ptr
= umodebuf
;
1373 static int prev_user_modes
[128];
1377 for (i
= 0; i
< 128; i
++)
1379 if (prev_user_modes
[i
] != 0 && prev_user_modes
[i
] != user_modes
[i
])
1381 if (user_modes
[i
] == 0)
1383 orphaned_umodes
|= prev_user_modes
[i
];
1384 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Umode +%c is now orphaned", i
);
1388 orphaned_umodes
&= ~prev_user_modes
[i
];
1389 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Orphaned umode +%c is picked up by module", i
);
1391 user_modes
[i
] = prev_user_modes
[i
];
1394 prev_user_modes
[i
] = user_modes
[i
];
1403 change_nick_user_host(struct Client
*target_p
, const char *nick
, const char *user
,
1404 const char *host
, int newts
, const char *format
, ...)
1407 struct Channel
*chptr
;
1408 struct membership
*mscptr
;
1409 int changed
= irccmp(target_p
->name
, nick
);
1410 int changed_case
= strcmp(target_p
->name
, nick
);
1411 int do_qjm
= irccmp(target_p
->username
, user
) || irccmp(target_p
->host
, host
);
1412 char mode
[10], modeval
[NICKLEN
* 2 + 2], reason
[256], *mptr
;
1419 target_p
->tsinfo
= newts
;
1420 monitor_signoff(target_p
);
1422 invalidate_bancache_user(target_p
);
1426 va_start(ap
, format
);
1427 vsnprintf(reason
, 255, format
, ap
);
1430 sendto_common_channels_local_butone(target_p
, NOCAPS
, ":%s!%s@%s QUIT :%s",
1431 target_p
->name
, target_p
->username
, target_p
->host
,
1434 RB_DLINK_FOREACH(ptr
, target_p
->user
->channel
.head
)
1437 chptr
= mscptr
->chptr
;
1440 if(is_chanop(mscptr
))
1443 strcat(modeval
, nick
);
1444 strcat(modeval
, " ");
1447 if(is_voiced(mscptr
))
1450 strcat(modeval
, nick
);
1455 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, NOCAPS
, CLICAP_EXTENDED_JOIN
, chptr
,
1456 ":%s!%s@%s JOIN %s", nick
, user
, host
, chptr
->chname
);
1457 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, CLICAP_EXTENDED_JOIN
, NOCAPS
, chptr
,
1458 ":%s!%s@%s JOIN %s %s :%s", nick
, user
, host
, chptr
->chname
,
1459 EmptyString(target_p
->user
->suser
) ? "*" : target_p
->user
->suser
,
1463 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
,
1464 ":%s MODE %s +%s %s",
1465 target_p
->servptr
->name
,
1466 chptr
->chname
, mode
, modeval
);
1471 /* Resend away message to away-notify enabled clients. */
1472 if (target_p
->user
->away
)
1473 sendto_common_channels_local_butone(target_p
, CLICAP_AWAY_NOTIFY
, ":%s!%s@%s AWAY :%s",
1474 target_p
->name
, target_p
->username
, target_p
->host
,
1475 target_p
->user
->away
);
1477 if(MyClient(target_p
) && changed_case
)
1478 sendto_one(target_p
, ":%s!%s@%s NICK %s",
1479 target_p
->name
, target_p
->username
, target_p
->host
, nick
);
1481 /* TODO: send some snotes to SNO_NCHANGE/SNO_CCONN/SNO_CCONNEXT? */
1483 else if(changed_case
)
1485 sendto_common_channels_local(target_p
, NOCAPS
, ":%s!%s@%s NICK :%s",
1486 target_p
->name
, target_p
->username
,
1487 target_p
->host
, nick
);
1489 if(MyConnect(target_p
))
1490 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
1491 "Nick change: From %s to %s [%s@%s]",
1492 target_p
->name
, nick
,
1493 target_p
->username
, target_p
->host
);
1496 rb_strlcpy(target_p
->username
, user
, sizeof target_p
->username
);
1497 rb_strlcpy(target_p
->host
, host
, sizeof target_p
->host
);
1500 add_history(target_p
, 1);
1502 del_from_client_hash(target_p
->name
, target_p
);
1503 rb_strlcpy(target_p
->name
, nick
, NICKLEN
);
1504 add_to_client_hash(target_p
->name
, target_p
);
1508 monitor_signon(target_p
);
1509 del_all_accepts(target_p
);