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
38 #include "s_newconf.h"
44 #include "supported.h"
52 #include "blacklist.h"
53 #include "substitution.h"
57 static void report_and_set_user_flags(struct Client
*, struct ConfItem
*);
58 void user_welcome(struct Client
*source_p
);
62 static int orphaned_umodes
= 0;
63 int user_modes
[256] = {
64 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
65 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
66 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
67 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
85 UMODE_NOFORWARD
, /* Q */
86 UMODE_REGONLYMSG
, /* R */
87 UMODE_SERVICE
, /* S */
94 UMODE_SSLCLIENT
, /* Z */
95 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
102 UMODE_CALLERID
, /* g */
104 UMODE_INVISIBLE
, /* i */
107 UMODE_LOCOPS
, /* l */
114 UMODE_SERVNOTICE
, /* s */
118 UMODE_WALLOP
, /* w */
121 UMODE_OPERWALL
, /* z */
122 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
123 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
124 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
125 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
126 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
127 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
128 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
129 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
130 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
137 * inputs - pointer to client
139 * side effects - display to client user counts etc.
142 show_lusers(struct Client
*source_p
)
144 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)MaxClientCount
)
145 MaxClientCount
= rb_dlink_list_length(&lclient_list
);
147 if((rb_dlink_list_length(&lclient_list
) + rb_dlink_list_length(&serv_list
)) >
148 (unsigned long)MaxConnectionCount
)
149 MaxConnectionCount
= rb_dlink_list_length(&lclient_list
) +
150 rb_dlink_list_length(&serv_list
);
152 sendto_one_numeric(source_p
, RPL_LUSERCLIENT
, form_str(RPL_LUSERCLIENT
),
153 (Count
.total
- Count
.invisi
),
155 (int)rb_dlink_list_length(&global_serv_list
));
157 if(rb_dlink_list_length(&oper_list
) > 0)
158 sendto_one_numeric(source_p
, RPL_LUSEROP
,
159 form_str(RPL_LUSEROP
),
160 (int)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
);
194 ** register_local_user
195 ** This function is called when both NICK and USER messages
196 ** have been accepted for the client, in whatever order. Only
197 ** after this, is the USER message propagated.
199 ** NICK's must be propagated at once when received, although
200 ** it would be better to delay them too until full info is
201 ** available. Doing it is not so simple though, would have
202 ** to implement the following:
204 ** (actually it has been implemented already for a while) -orabidoo
206 ** 1) user telnets in and gives only "NICK foobar" and waits
207 ** 2) another user far away logs in normally with the nick
208 ** "foobar" (quite legal, as this server didn't propagate
210 ** 3) now this server gets nick "foobar" from outside, but
211 ** has alread the same defined locally. Current server
212 ** would just issue "KILL foobar" to clean out dups. But,
213 ** this is not fair. It should actually request another
214 ** nick from local user or kill him/her...
218 register_local_user(struct Client
*client_p
, struct Client
*source_p
)
220 struct ConfItem
*aconf
, *xconf
;
221 struct User
*user
= source_p
->user
;
222 char tmpstr2
[IRCD_BUFSIZE
];
223 char ipaddr
[HOSTIPLEN
];
224 char myusername
[USERLEN
+1];
227 s_assert(NULL
!= source_p
);
228 s_assert(MyConnect(source_p
));
233 if(IsAnyDead(source_p
))
236 if(ConfigFileEntry
.ping_cookie
)
238 if(!(source_p
->flags
& FLAGS_PINGSENT
) && source_p
->localClient
->random_ping
== 0)
240 source_p
->localClient
->random_ping
= (unsigned long) (rand() * rand()) << 1;
241 sendto_one(source_p
, "PING :%08lX",
242 (unsigned long) source_p
->localClient
->random_ping
);
243 source_p
->flags
|= FLAGS_PINGSENT
;
246 if(!(source_p
->flags
& FLAGS_PING_COOKIE
))
252 /* hasnt finished client cap negotiation */
253 if(source_p
->flags
& FLAGS_CLICAP
)
256 /* still has DNSbls to validate against */
257 if(rb_dlink_list_length(&source_p
->preClient
->dnsbl_queries
) > 0)
260 client_p
->localClient
->last
= rb_current_time();
262 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
263 if(!IsGotId(source_p
) && (strchr(source_p
->username
, '[') != NULL
))
268 p
= source_p
->username
;
270 while(*p
&& i
< USERLEN
)
273 myusername
[i
++] = *p
;
277 myusername
[i
] = '\0';
280 rb_strlcpy(myusername
, source_p
->username
, sizeof myusername
);
282 if((status
= check_client(client_p
, source_p
, myusername
)) < 0)
283 return (CLIENT_EXITED
);
285 /* Apply nick override */
286 if(*source_p
->preClient
->spoofnick
)
288 char note
[NICKLEN
+ 10];
290 del_from_client_hash(source_p
->name
, source_p
);
291 rb_strlcpy(source_p
->name
, source_p
->preClient
->spoofnick
, NICKLEN
+ 1);
292 add_to_client_hash(source_p
->name
, source_p
);
294 snprintf(note
, NICKLEN
+ 10, "Nick: %s", source_p
->name
);
295 rb_note(source_p
->localClient
->F
, note
);
298 if(!valid_hostname(source_p
->host
))
300 sendto_one_notice(source_p
, ":*** Notice -- You have an illegal character in your hostname");
302 rb_strlcpy(source_p
->host
, source_p
->sockhost
, sizeof(source_p
->host
));
306 aconf
= source_p
->localClient
->att_conf
;
310 exit_client(client_p
, source_p
, &me
, "*** Not Authorised");
311 return (CLIENT_EXITED
);
314 if(IsConfSSLNeeded(aconf
) && !IsSSL(source_p
))
316 ServerStats
.is_ref
++;
317 sendto_one_notice(source_p
, ":*** Notice -- You need to use SSL/TLS to use this server");
318 exit_client(client_p
, source_p
, &me
, "Use SSL/TLS");
319 return (CLIENT_EXITED
);
322 if(!IsGotId(source_p
))
327 if(IsNeedIdentd(aconf
))
329 ServerStats
.is_ref
++;
330 sendto_one_notice(source_p
, ":*** Notice -- You need to install identd to use this server");
331 exit_client(client_p
, source_p
, &me
, "Install identd");
332 return (CLIENT_EXITED
);
335 /* dont replace username if its supposed to be spoofed --fl */
336 if(!IsConfDoSpoofIp(aconf
) || !strchr(aconf
->info
.name
, '@'))
340 if(!IsNoTilde(aconf
))
341 source_p
->username
[i
++] = '~';
343 while (*p
&& i
< USERLEN
)
346 source_p
->username
[i
++] = *p
;
350 source_p
->username
[i
] = '\0';
354 if(IsNeedSasl(aconf
) && !*user
->suser
)
356 ServerStats
.is_ref
++;
357 sendto_one_notice(source_p
, ":*** Notice -- You need to identify via SASL to use this server");
358 exit_client(client_p
, source_p
, &me
, "SASL access only");
359 return (CLIENT_EXITED
);
363 if(!EmptyString(aconf
->passwd
))
367 if(EmptyString(source_p
->localClient
->passwd
))
369 else if(IsConfEncrypted(aconf
))
370 encr
= rb_crypt(source_p
->localClient
->passwd
, aconf
->passwd
);
372 encr
= source_p
->localClient
->passwd
;
374 if(encr
== NULL
|| strcmp(encr
, aconf
->passwd
))
376 ServerStats
.is_ref
++;
377 sendto_one(source_p
, form_str(ERR_PASSWDMISMATCH
), me
.name
, source_p
->name
);
378 exit_client(client_p
, source_p
, &me
, "Bad Password");
379 return (CLIENT_EXITED
);
382 /* clear password only if used now, otherwise send it
383 * to services -- jilles */
384 if(source_p
->localClient
->passwd
)
386 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
387 rb_free(source_p
->localClient
->passwd
);
388 source_p
->localClient
->passwd
= NULL
;
392 /* report if user has &^>= etc. and set flags as needed in source_p */
393 report_and_set_user_flags(source_p
, aconf
);
397 * We want to be able to have servers and F-line clients
398 * connect, so save room for "buffer" connections.
399 * Smaller servers may want to decrease this, and it should
400 * probably be just a percentage of the MAXCLIENTS...
403 /* Except "F:" clients */
404 if(rb_dlink_list_length(&lclient_list
) >=
405 (unsigned long)GlobalSetOptions
.maxclients
&& !IsConfExemptLimits(aconf
))
407 sendto_realops_snomask(SNO_FULL
, L_ALL
,
408 "Too many clients, rejecting %s[%s].", source_p
->name
, source_p
->host
);
410 ServerStats
.is_ref
++;
411 exit_client(client_p
, source_p
, &me
, "Sorry, server is full - try later");
412 return (CLIENT_EXITED
);
415 /* kline exemption extends to xline too */
416 if(!IsExemptKline(source_p
) &&
417 (xconf
= find_xline(source_p
->info
, 1)) != NULL
)
419 ServerStats
.is_ref
++;
420 add_reject(source_p
, xconf
->host
, NULL
);
421 exit_client(client_p
, source_p
, &me
, "Bad user info");
422 return CLIENT_EXITED
;
426 if (source_p
->preClient
->dnsbl_listed
!= NULL
)
428 if (IsExemptKline(source_p
) || IsConfExemptDNSBL(aconf
))
429 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s, but you are exempt",
430 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
433 sendto_realops_snomask(SNO_REJ
, L_NETWIDE
,
434 "Listed on DNSBL %s: %s (%s@%s) [%s] [%s]",
435 source_p
->preClient
->dnsbl_listed
->host
,
437 source_p
->username
, source_p
->host
,
438 IsIPSpoof(source_p
) ? "255.255.255.255" : source_p
->sockhost
,
441 rb_dlink_list varlist
= { NULL
, NULL
, 0 };
443 substitution_append_var(&varlist
, "nick", source_p
->name
);
444 substitution_append_var(&varlist
, "ip", source_p
->sockhost
);
445 substitution_append_var(&varlist
, "host", source_p
->host
);
446 substitution_append_var(&varlist
, "dnsbl-host", source_p
->preClient
->dnsbl_listed
->host
);
447 substitution_append_var(&varlist
, "network-name", ServerInfo
.network_name
);
449 ServerStats
.is_ref
++;
451 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
452 me
.name
, source_p
->name
,
453 substitution_parse(source_p
->preClient
->dnsbl_listed
->reject_reason
, &varlist
));
455 substitution_free(&varlist
);
457 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s",
458 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
459 source_p
->preClient
->dnsbl_listed
->hits
++;
460 add_reject(source_p
, NULL
, NULL
);
461 exit_client(client_p
, source_p
, &me
, "*** Banned (DNS blacklist)");
462 return CLIENT_EXITED
;
466 /* valid user name check */
468 if(!valid_username(source_p
->username
))
470 sendto_realops_snomask(SNO_REJ
, L_ALL
,
471 "Invalid username: %s (%s@%s)",
472 source_p
->name
, source_p
->username
, source_p
->host
);
473 ServerStats
.is_ref
++;
474 sendto_one_notice(source_p
, ":*** Your username is invalid. Please make sure that your username contains "
475 "only alphanumeric characters.");
476 sprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
477 exit_client(client_p
, source_p
, &me
, tmpstr2
);
478 return (CLIENT_EXITED
);
481 /* end of valid user name check */
483 /* Store original hostname -- jilles */
484 rb_strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
486 /* Spoof user@host */
487 if(*source_p
->preClient
->spoofuser
)
488 rb_strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
489 if(*source_p
->preClient
->spoofhost
)
491 rb_strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
492 if (irccmp(source_p
->host
, source_p
->orighost
))
493 SetDynSpoof(source_p
);
496 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
& ~orphaned_umodes
;
498 call_hook(h_new_local_user
, source_p
);
500 /* If they have died in send_* or were thrown out by the
501 * new_local_user hook don't do anything. */
502 if(IsAnyDead(source_p
))
503 return CLIENT_EXITED
;
505 /* To avoid inconsistencies, do not abort the registration
506 * starting from this point -- jilles
508 rb_inet_ntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
510 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
511 "Client connecting: %s (%s@%s) [%s] {%s} [%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
), source_p
->info
);
516 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
517 "CLICONN %s %s %s %s %s %s 0 %s",
518 source_p
->name
, source_p
->username
, source_p
->orighost
,
519 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
520 get_client_class(source_p
),
521 /* mirc can sometimes send ips here */
522 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
525 add_to_hostname_hash(source_p
->orighost
, source_p
);
527 /* Allocate a UID if it was not previously allocated.
528 * If this already occured, it was probably during SASL auth...
532 strcpy(source_p
->id
, generate_uid());
533 add_to_id_hash(source_p
->id
, source_p
);
537 source_p
->umodes
|= UMODE_SSLCLIENT
;
539 if (source_p
->umodes
& UMODE_INVISIBLE
)
542 s_assert(!IsClient(source_p
));
543 rb_dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
546 source_p
->servptr
= &me
;
547 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
549 /* Increment our total user count here */
550 if(++Count
.total
> Count
.max_tot
)
551 Count
.max_tot
= Count
.total
;
553 Count
.totalrestartcount
++;
555 s_assert(source_p
->localClient
!= NULL
);
557 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
559 Count
.max_loc
= rb_dlink_list_length(&lclient_list
);
560 if(!(Count
.max_loc
% 10))
561 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
562 "New Max Local Clients: %d", Count
.max_loc
);
565 /* they get a reduced limit */
566 if(find_tgchange(source_p
->sockhost
))
567 source_p
->localClient
->targets_free
= TGCHANGE_INITIAL_LOW
;
569 source_p
->localClient
->targets_free
= TGCHANGE_INITIAL
;
571 monitor_signon(source_p
);
572 user_welcome(source_p
);
574 free_pre_client(source_p
);
576 introduce_client(client_p
, source_p
, user
, source_p
->name
, 1);
585 * side effects - This common function introduces a client to the rest
586 * of the net, either from a local client connect or
587 * from a remote connect.
590 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
593 struct Client
*identifyservice_p
;
595 hook_data_umode_changed hdata
;
596 hook_data_client hdata2
;
598 if(MyClient(source_p
))
599 send_umode(source_p
, source_p
, 0, ubuf
);
601 send_umode(NULL
, source_p
, 0, ubuf
);
609 s_assert(has_id(source_p
));
612 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
613 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
614 source_p
->servptr
->id
, nick
,
615 source_p
->hopcount
+ 1,
616 (long) source_p
->tsinfo
, ubuf
,
617 source_p
->username
, source_p
->host
,
618 IsIPSpoof(source_p
) ? "0" : source_p
->sockhost
,
620 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
621 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
624 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
625 ":%s UID %s %d %ld %s %s %s %s %s :%s",
626 source_p
->servptr
->id
, nick
,
627 source_p
->hopcount
+ 1,
628 (long) source_p
->tsinfo
, ubuf
,
629 source_p
->username
, source_p
->host
,
630 IsIPSpoof(source_p
) ? "0" : source_p
->sockhost
,
631 source_p
->id
, source_p
->info
);
633 if(!EmptyString(source_p
->certfp
))
634 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
635 ":%s ENCAP * CERTFP :%s",
636 use_id(source_p
), source_p
->certfp
);
638 if (IsDynSpoof(source_p
))
640 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
641 use_id(source_p
), source_p
->orighost
);
644 if (!EmptyString(source_p
->user
->suser
))
646 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
647 use_id(source_p
), source_p
->user
->suser
);
650 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
652 if (!EmptyString(ConfigFileEntry
.identifyservice
) &&
653 !EmptyString(ConfigFileEntry
.identifycommand
))
655 /* use user@server */
656 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
658 identifyservice_p
= find_named_client(p
+ 1);
660 identifyservice_p
= NULL
;
661 if (identifyservice_p
!= NULL
)
663 if (!EmptyString(source_p
->localClient
->auth_user
))
664 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s %s",
665 get_id(source_p
, identifyservice_p
),
666 ConfigFileEntry
.identifyservice
,
667 ConfigFileEntry
.identifycommand
,
668 source_p
->localClient
->auth_user
,
669 source_p
->localClient
->passwd
);
671 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
672 get_id(source_p
, identifyservice_p
),
673 ConfigFileEntry
.identifyservice
,
674 ConfigFileEntry
.identifycommand
,
675 source_p
->localClient
->passwd
);
678 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
679 rb_free(source_p
->localClient
->passwd
);
680 source_p
->localClient
->passwd
= NULL
;
683 /* let modules providing usermodes know that we've got a new user,
684 * why is this here? -- well, some modules need to be able to send out new
685 * information about a client, so this was the best place to do it
688 hdata
.client
= source_p
;
690 hdata
.oldsnomask
= 0;
691 call_hook(h_umode_changed
, &hdata
);
693 /* On the other hand, some modules need to know when a client is
694 * being introduced, period.
697 hdata2
.client
= client_p
;
698 hdata2
.target
= source_p
;
699 call_hook(h_introduce_client
, &hdata2
);
703 * valid_hostname - check hostname for validity
705 * Inputs - pointer to user
706 * Output - true if valid, false if not
707 * Side effects - NONE
709 * NOTE: this doesn't allow a hostname to begin with a dot and
710 * will not allow more dots than chars.
713 valid_hostname(const char *hostname
)
715 const char *p
= hostname
, *last_slash
= 0;
723 if(!strcmp(hostname
, "localhost"))
726 if('.' == *p
|| ':' == *p
|| '/' == *p
)
733 if(*p
== '.' || *p
== ':')
746 if(last_slash
&& IsDigit(last_slash
[1]))
753 * valid_username - check username for validity
755 * Inputs - pointer to user
756 * Output - true if valid, false if not
757 * Side effects - NONE
759 * Absolutely always reject any '*' '!' '?' '@' in an user name
760 * reject any odd control characters names.
761 * Allow '.' in username to allow for "first.last"
765 valid_username(const char *username
)
768 const char *p
= username
;
778 /* reject usernames that don't start with an alphanum
779 * i.e. reject jokers who have '-@somehost' or '.@somehost'
780 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
787 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
790 if(dots
> ConfigFileEntry
.dots_in_ident
)
792 if(!IsUserChar(p
[1]))
795 else if(!IsUserChar(*p
))
801 /* report_and_set_user_flags
803 * Inputs - pointer to source_p
804 * - pointer to aconf for this user
807 * Report to user any special flags they are getting, and set them.
811 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
813 /* If this user is being spoofed, tell them so */
814 if(IsConfDoSpoofIp(aconf
))
816 sendto_one_notice(source_p
, ":*** Spoofing your IP");
819 /* If this user is in the exception class, Set it "E lined" */
820 if(IsConfExemptKline(aconf
))
822 SetExemptKline(source_p
);
823 sendto_one_notice(source_p
, ":*** You are exempt from K/X lines");
826 if(IsConfExemptDNSBL(aconf
))
827 /* kline exempt implies this, don't send both */
828 if(!IsConfExemptKline(aconf
))
829 sendto_one_notice(source_p
, ":*** You are exempt from DNS blacklists");
831 /* If this user is exempt from user limits set it F lined" */
832 if(IsConfExemptLimits(aconf
))
834 sendto_one_notice(source_p
, ":*** You are exempt from user limits");
837 if(IsConfExemptFlood(aconf
))
839 SetExemptFlood(source_p
);
840 sendto_one_notice(source_p
, ":*** You are exempt from flood limits");
843 if(IsConfExemptSpambot(aconf
))
845 SetExemptSpambot(source_p
);
846 sendto_one_notice(source_p
, ":*** You are exempt from spambot checks");
849 if(IsConfExemptJupe(aconf
))
851 SetExemptJupe(source_p
);
852 sendto_one_notice(source_p
, ":*** You are exempt from juped channel warnings");
855 if(IsConfExemptResv(aconf
))
857 SetExemptResv(source_p
);
858 sendto_one_notice(source_p
, ":*** You are exempt from resvs");
861 if(IsConfExemptShide(aconf
))
863 SetExemptShide(source_p
);
864 sendto_one_notice(source_p
, ":*** You are exempt from serverhiding");
867 if(IsConfExtendChans(aconf
))
869 SetExtendChans(source_p
);
870 sendto_one_notice(source_p
, ":*** You are exempt from normal channel limits");
875 show_other_user_mode(struct Client
*source_p
, struct Client
*target_p
)
884 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
885 if (target_p
->umodes
& user_modes
[i
])
889 if (MyConnect(target_p
) && target_p
->snomask
!= 0)
890 sendto_one_notice(source_p
, ":Modes for %s are %s %s",
892 construct_snobuf(target_p
->snomask
));
894 sendto_one_notice(source_p
, ":Modes for %s are %s",
895 target_p
->name
, buf
);
899 * user_mode - set get current users mode
901 * m_umode() added 15/10/91 By Darren Reed.
902 * parv[1] - username to change mode for
903 * parv[2] - modes to change
906 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
912 struct Client
*target_p
;
914 bool badflag
= false; /* Only send one bad flag notice */
915 bool showsnomask
= false;
916 unsigned int setsnomask
;
918 hook_data_umode_changed hdata
;
924 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
928 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
930 if(MyConnect(source_p
))
931 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
932 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
936 /* Dont know why these were commented out..
937 * put them back using new sendto() funcs
940 if(IsServer(source_p
))
942 sendto_realops_snomask(SNO_GENERAL
, L_ADMIN
,
943 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
947 if(source_p
!= target_p
)
949 if (MyOper(source_p
) && parc
< 3)
950 show_other_user_mode(source_p
, target_p
);
952 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
961 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
962 if (source_p
->umodes
& user_modes
[i
])
966 sendto_one_numeric(source_p
, RPL_UMODEIS
, form_str(RPL_UMODEIS
), buf
);
968 if (source_p
->snomask
!= 0)
969 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
970 construct_snobuf(source_p
->snomask
));
975 /* find flags already set for user */
976 setflags
= source_p
->umodes
;
977 setsnomask
= source_p
->snomask
;
980 * parse mode change string(s)
982 for (pm
= parv
[2]; *pm
; pm
++)
995 if(IsServer(client_p
) && !IsOper(source_p
))
999 rb_dlinkAddAlloc(source_p
, &oper_list
);
1004 /* Only decrement the oper counts if an oper to begin with
1005 * found by Pat Szuta, Perly , perly@xnet.com
1008 if(!IsOper(source_p
))
1011 ClearOper(source_p
);
1015 if(MyConnect(source_p
))
1017 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
1018 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
1020 source_p
->snomask
= 0;
1023 source_p
->flags2
&= ~OPER_FLAGS
;
1025 rb_free(source_p
->localClient
->opername
);
1026 source_p
->localClient
->opername
= NULL
;
1028 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1029 privilegeset_unref(source_p
->localClient
->privset
);
1030 source_p
->localClient
->privset
= NULL
;
1033 rb_dlinkFindDestroy(source_p
, &oper_list
);
1037 /* we may not get these,
1038 * but they shouldnt be in default
1041 /* can only be set on burst */
1051 if (MyConnect(source_p
))
1053 if(!IsOper(source_p
)
1054 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
1056 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1061 if(what
== MODE_ADD
)
1064 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1066 source_p
->snomask
|= SNO_GENERAL
;
1069 source_p
->snomask
= 0;
1070 if (source_p
->snomask
!= 0)
1071 source_p
->umodes
|= UMODE_SERVNOTICE
;
1073 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1078 if (MyConnect(source_p
) && *pm
== 'Q' && !ConfigChannel
.use_forward
)
1084 if((flag
= user_modes
[(unsigned char) *pm
]))
1086 if(MyConnect(source_p
)
1087 && ((!IsOper(source_p
)
1088 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1089 || (orphaned_umodes
& flag
)))
1091 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1096 if(what
== MODE_ADD
)
1097 source_p
->umodes
|= flag
;
1099 source_p
->umodes
&= ~flag
;
1104 if(MyConnect(source_p
))
1111 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1113 if(MyClient(source_p
) && (source_p
->snomask
& SNO_NCHANGE
) && !IsOperN(source_p
))
1115 sendto_one_notice(source_p
, ":*** You need oper and nick_changes flag for +s +n");
1116 source_p
->snomask
&= ~SNO_NCHANGE
; /* only tcm's really need this */
1119 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1121 sendto_one_notice(source_p
, ":*** You need oper and operwall flag for +z");
1122 source_p
->umodes
&= ~UMODE_OPERWALL
;
1125 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1126 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1128 sendto_one_notice(source_p
, ":*** You need oper and admin flag for +a");
1129 source_p
->umodes
&= ~UMODE_ADMIN
;
1132 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1133 hdata
.client
= source_p
;
1134 hdata
.oldumodes
= setflags
;
1135 hdata
.oldsnomask
= setsnomask
;
1136 call_hook(h_umode_changed
, &hdata
);
1138 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1140 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1143 * compare new flags with old flags and send string which
1144 * will cause servers to update correctly.
1146 send_umode_out(client_p
, source_p
, setflags
);
1147 if (showsnomask
&& MyConnect(source_p
))
1148 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1149 construct_snobuf(source_p
->snomask
));
1155 * send the MODE string for user (user) to connection client_p
1159 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, char *umode_buf
)
1167 * build a string in umode_buf to represent the change in the user's
1168 * mode between the new (source_p->flag) and 'old'.
1173 for (i
= 0; i
< 128; i
++)
1175 flag
= user_modes
[i
];
1177 if((flag
& old
) && !(source_p
->umodes
& flag
))
1179 if(what
== MODE_DEL
)
1188 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1190 if(what
== MODE_ADD
)
1202 if(*umode_buf
&& client_p
)
1203 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1214 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1216 struct Client
*target_p
;
1220 send_umode(NULL
, source_p
, old
, buf
);
1222 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1224 target_p
= ptr
->data
;
1226 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1228 sendto_one(target_p
, ":%s MODE %s :%s",
1229 get_id(source_p
, target_p
),
1230 get_id(source_p
, target_p
), buf
);
1234 if(client_p
&& MyClient(client_p
))
1235 send_umode(client_p
, source_p
, old
, buf
);
1241 * inputs - client pointer to client to welcome
1246 user_welcome(struct Client
*source_p
)
1248 sendto_one_numeric(source_p
, RPL_WELCOME
, form_str(RPL_WELCOME
), ServerInfo
.network_name
, source_p
->name
);
1249 sendto_one_numeric(source_p
, RPL_YOURHOST
, form_str(RPL_YOURHOST
),
1250 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1251 sendto_one_numeric(source_p
, RPL_CREATED
, form_str(RPL_CREATED
), creation
);
1252 sendto_one_numeric(source_p
, RPL_MYINFO
, form_str(RPL_MYINFO
), me
.name
, ircd_version
, umodebuf
, cflagsmyinfo
);
1254 show_isupport(source_p
);
1256 show_lusers(source_p
);
1258 if(ConfigFileEntry
.short_motd
)
1260 sendto_one_notice(source_p
, ":*** Notice -- motd was last changed at %s", user_motd_changed
);
1261 sendto_one_notice(source_p
, ":*** Notice -- Please read the motd if you haven't read it");
1263 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1264 me
.name
, source_p
->name
, me
.name
);
1266 sendto_one(source_p
, form_str(RPL_MOTD
),
1267 me
.name
, source_p
->name
, "*** This is the short motd ***");
1269 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1272 send_user_motd(source_p
);
1277 * inputs - pointer to given client to oper
1278 * - pointer to ConfItem to use
1280 * side effects - opers up source_p using aconf for reference
1283 oper_up(struct Client
*source_p
, struct oper_conf
*oper_p
)
1285 unsigned int old
= source_p
->umodes
, oldsnomask
= source_p
->snomask
;
1286 hook_data_umode_changed hdata
;
1291 source_p
->umodes
|= oper_p
->umodes
;
1292 else if(ConfigFileEntry
.oper_umodes
)
1293 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1295 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1297 if (oper_p
->snomask
)
1299 source_p
->snomask
|= oper_p
->snomask
;
1300 source_p
->umodes
|= UMODE_SERVNOTICE
;
1302 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1304 /* Only apply these if +s is already set -- jilles */
1305 if (ConfigFileEntry
.oper_snomask
)
1306 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1308 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1313 SetExtendChans(source_p
);
1314 SetExemptKline(source_p
);
1316 source_p
->flags2
|= oper_p
->flags
;
1317 source_p
->localClient
->opername
= rb_strdup(oper_p
->name
);
1318 source_p
->localClient
->privset
= privilegeset_ref(oper_p
->privset
);
1320 rb_dlinkAddAlloc(source_p
, &local_oper_list
);
1321 rb_dlinkAddAlloc(source_p
, &oper_list
);
1323 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1324 source_p
->umodes
|= UMODE_ADMIN
;
1325 if(!IsOperN(source_p
))
1326 source_p
->snomask
&= ~SNO_NCHANGE
;
1327 if(!IsOperOperwall(source_p
))
1328 source_p
->umodes
&= ~UMODE_OPERWALL
;
1329 hdata
.client
= source_p
;
1330 hdata
.oldumodes
= old
;
1331 hdata
.oldsnomask
= oldsnomask
;
1332 call_hook(h_umode_changed
, &hdata
);
1334 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1335 "%s (%s!%s@%s) is now an operator", oper_p
->name
, source_p
->name
,
1336 source_p
->username
, source_p
->host
);
1337 if(!(old
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1339 if((old
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1341 send_umode_out(source_p
, source_p
, old
);
1342 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1343 construct_snobuf(source_p
->snomask
));
1344 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1345 sendto_one_notice(source_p
, ":*** Oper privilege set is %s", oper_p
->privset
->name
);
1346 sendto_one_notice(source_p
, ":*** Oper privs are %s", oper_p
->privset
->privs
);
1347 send_oper_motd(source_p
);
1354 * outputs - an available umode bitmask or
1355 * 0 if no umodes are available
1356 * side effects - NONE
1359 find_umode_slot(void)
1361 unsigned int all_umodes
= 0, my_umode
= 0, i
;
1363 for (i
= 0; i
< 128; i
++)
1364 all_umodes
|= user_modes
[i
];
1366 for (my_umode
= 1; my_umode
&& (all_umodes
& my_umode
);
1373 construct_umodebuf(void)
1376 char *ptr
= umodebuf
;
1377 static int prev_user_modes
[128];
1381 for (i
= 0; i
< 128; i
++)
1383 if (prev_user_modes
[i
] != 0 && prev_user_modes
[i
] != user_modes
[i
])
1385 if (user_modes
[i
] == 0)
1387 orphaned_umodes
|= prev_user_modes
[i
];
1388 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Umode +%c is now orphaned", i
);
1392 orphaned_umodes
&= ~prev_user_modes
[i
];
1393 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Orphaned umode +%c is picked up by module", i
);
1395 user_modes
[i
] = prev_user_modes
[i
];
1398 prev_user_modes
[i
] = user_modes
[i
];
1407 change_nick_user_host(struct Client
*target_p
, const char *nick
, const char *user
,
1408 const char *host
, int newts
, const char *format
, ...)
1411 struct Channel
*chptr
;
1412 struct membership
*mscptr
;
1413 int changed
= irccmp(target_p
->name
, nick
);
1414 int changed_case
= strcmp(target_p
->name
, nick
);
1415 int do_qjm
= irccmp(target_p
->username
, user
) || irccmp(target_p
->host
, host
);
1416 char mode
[10], modeval
[NICKLEN
* 2 + 2], reason
[256], *mptr
;
1423 target_p
->tsinfo
= newts
;
1424 monitor_signoff(target_p
);
1426 invalidate_bancache_user(target_p
);
1430 va_start(ap
, format
);
1431 vsnprintf(reason
, 255, format
, ap
);
1434 sendto_common_channels_local_butone(target_p
, NOCAPS
, CLICAP_CHGHOST
, ":%s!%s@%s QUIT :%s",
1435 target_p
->name
, target_p
->username
, target_p
->host
,
1438 RB_DLINK_FOREACH(ptr
, target_p
->user
->channel
.head
)
1441 chptr
= mscptr
->chptr
;
1444 if(is_chanop(mscptr
))
1447 strcat(modeval
, nick
);
1448 strcat(modeval
, " ");
1451 if(is_voiced(mscptr
))
1454 strcat(modeval
, nick
);
1459 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, NOCAPS
, CLICAP_EXTENDED_JOIN
| CLICAP_CHGHOST
, chptr
,
1460 ":%s!%s@%s JOIN %s", nick
, user
, host
, chptr
->chname
);
1461 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, CLICAP_EXTENDED_JOIN
, CLICAP_CHGHOST
, chptr
,
1462 ":%s!%s@%s JOIN %s %s :%s", nick
, user
, host
, chptr
->chname
,
1463 EmptyString(target_p
->user
->suser
) ? "*" : target_p
->user
->suser
,
1467 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, NOCAPS
, CLICAP_CHGHOST
, chptr
,
1468 ":%s MODE %s +%s %s", target_p
->servptr
->name
, chptr
->chname
, mode
, modeval
);
1473 /* Resend away message to away-notify enabled clients. */
1474 if (target_p
->user
->away
)
1475 sendto_common_channels_local_butone(target_p
, CLICAP_AWAY_NOTIFY
, CLICAP_CHGHOST
, ":%s!%s@%s AWAY :%s",
1477 target_p
->user
->away
);
1479 sendto_common_channels_local_butone(target_p
, CLICAP_CHGHOST
, NOCAPS
,
1480 ":%s!%s@%s CHGHOST %s %s",
1481 target_p
->name
, target_p
->username
, target_p
->host
, user
, host
);
1483 if(MyClient(target_p
) && changed_case
)
1484 sendto_one(target_p
, ":%s!%s@%s NICK %s",
1485 target_p
->name
, user
, host
, nick
);
1487 /* TODO: send some snotes to SNO_NCHANGE/SNO_CCONN/SNO_CCONNEXT? */
1489 else if(changed_case
)
1491 sendto_common_channels_local(target_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
1492 target_p
->name
, user
, host
, nick
);
1494 if(MyConnect(target_p
))
1495 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
1496 "Nick change: From %s to %s [%s@%s]",
1497 target_p
->name
, nick
,
1498 target_p
->username
, target_p
->host
);
1501 if (user
!= target_p
->username
)
1502 rb_strlcpy(target_p
->username
, user
, sizeof target_p
->username
);
1504 rb_strlcpy(target_p
->host
, host
, sizeof target_p
->host
);
1507 whowas_add_history(target_p
, 1);
1509 del_from_client_hash(target_p
->name
, target_p
);
1510 rb_strlcpy(target_p
->name
, nick
, NICKLEN
);
1511 add_to_client_hash(target_p
->name
, target_p
);
1515 monitor_signon(target_p
);
1516 del_all_accepts(target_p
);