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 $
34 #include "irc_string.h"
35 #include "sprintf_irc.h"
41 #include "s_newconf.h"
47 #include "supported.h"
55 #include "blacklist.h"
56 #include "substitution.h"
58 static void report_and_set_user_flags(struct Client
*, struct ConfItem
*);
59 void user_welcome(struct Client
*source_p
);
65 static int orphaned_umodes
= 0;
66 int user_modes
[256] = {
67 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
68 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
69 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
70 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
88 UMODE_NOFORWARD
, /* Q */
89 UMODE_REGONLYMSG
, /* R */
90 UMODE_SERVICE
, /* S */
97 UMODE_SSLCLIENT
, /* Z */
98 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
105 UMODE_CALLERID
, /* g */
107 UMODE_INVISIBLE
, /* i */
110 UMODE_LOCOPS
, /* l */
117 UMODE_SERVNOTICE
, /* s */
121 UMODE_WALLOP
, /* w */
124 UMODE_OPERWALL
, /* z */
125 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
126 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
127 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
128 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
129 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
130 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
131 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
132 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
133 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
140 * inputs - pointer to client
142 * side effects - display to client user counts etc.
145 show_lusers(struct Client
*source_p
)
147 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)MaxClientCount
)
148 MaxClientCount
= rb_dlink_list_length(&lclient_list
);
150 if((rb_dlink_list_length(&lclient_list
) + rb_dlink_list_length(&serv_list
)) >
151 (unsigned long)MaxConnectionCount
)
152 MaxConnectionCount
= rb_dlink_list_length(&lclient_list
) +
153 rb_dlink_list_length(&serv_list
);
155 sendto_one_numeric(source_p
, RPL_LUSERCLIENT
, form_str(RPL_LUSERCLIENT
),
156 (Count
.total
- Count
.invisi
),
157 Count
.invisi
, rb_dlink_list_length(&global_serv_list
));
159 if(rb_dlink_list_length(&oper_list
) > 0)
160 sendto_one_numeric(source_p
, RPL_LUSEROP
,
161 form_str(RPL_LUSEROP
), rb_dlink_list_length(&oper_list
));
163 if(rb_dlink_list_length(&unknown_list
) > 0)
164 sendto_one_numeric(source_p
, RPL_LUSERUNKNOWN
,
165 form_str(RPL_LUSERUNKNOWN
),
166 rb_dlink_list_length(&unknown_list
));
168 if(rb_dlink_list_length(&global_channel_list
) > 0)
169 sendto_one_numeric(source_p
, RPL_LUSERCHANNELS
,
170 form_str(RPL_LUSERCHANNELS
),
171 rb_dlink_list_length(&global_channel_list
));
173 sendto_one_numeric(source_p
, RPL_LUSERME
, form_str(RPL_LUSERME
),
174 rb_dlink_list_length(&lclient_list
),
175 rb_dlink_list_length(&serv_list
));
177 sendto_one_numeric(source_p
, RPL_LOCALUSERS
,
178 form_str(RPL_LOCALUSERS
),
179 rb_dlink_list_length(&lclient_list
),
181 rb_dlink_list_length(&lclient_list
),
184 sendto_one_numeric(source_p
, RPL_GLOBALUSERS
, form_str(RPL_GLOBALUSERS
),
185 Count
.total
, Count
.max_tot
,
186 Count
.total
, Count
.max_tot
);
188 sendto_one_numeric(source_p
, RPL_STATSCONN
,
189 form_str(RPL_STATSCONN
),
190 MaxConnectionCount
, MaxClientCount
,
191 Count
.totalrestartcount
);
197 ** register_local_user
198 ** This function is called when both NICK and USER messages
199 ** have been accepted for the client, in whatever order. Only
200 ** after this, is the USER message propagated.
202 ** NICK's must be propagated at once when received, although
203 ** it would be better to delay them too until full info is
204 ** available. Doing it is not so simple though, would have
205 ** to implement the following:
207 ** (actually it has been implemented already for a while) -orabidoo
209 ** 1) user telnets in and gives only "NICK foobar" and waits
210 ** 2) another user far away logs in normally with the nick
211 ** "foobar" (quite legal, as this server didn't propagate
213 ** 3) now this server gets nick "foobar" from outside, but
214 ** has alread the same defined locally. Current server
215 ** would just issue "KILL foobar" to clean out dups. But,
216 ** this is not fair. It should actually request another
217 ** nick from local user or kill him/her...
221 register_local_user(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
223 struct ConfItem
*aconf
, *xconf
;
224 struct User
*user
= source_p
->user
;
225 char tmpstr2
[IRCD_BUFSIZE
];
226 char ipaddr
[HOSTIPLEN
];
227 char myusername
[USERLEN
+1];
230 s_assert(NULL
!= source_p
);
231 s_assert(MyConnect(source_p
));
232 s_assert(source_p
->username
!= username
);
237 if(IsAnyDead(source_p
))
240 if(ConfigFileEntry
.ping_cookie
)
242 if(!(source_p
->flags
& FLAGS_PINGSENT
) && source_p
->localClient
->random_ping
== 0)
244 source_p
->localClient
->random_ping
= (unsigned long) (rand() * rand()) << 1;
245 sendto_one(source_p
, "PING :%08lX",
246 (unsigned long) source_p
->localClient
->random_ping
);
247 source_p
->flags
|= FLAGS_PINGSENT
;
250 if(!(source_p
->flags
& FLAGS_PING_COOKIE
))
256 /* hasnt finished client cap negotiation */
257 if(source_p
->flags
& FLAGS_CLICAP
)
260 /* still has DNSbls to validate against */
261 if(rb_dlink_list_length(&source_p
->preClient
->dnsbl_queries
) > 0)
264 client_p
->localClient
->last
= rb_current_time();
265 /* Straight up the maximum rate of flooding... */
266 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
268 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
269 if(!IsGotId(source_p
) && (strchr(username
, '[') != NULL
))
276 while(*p
&& i
< USERLEN
)
279 myusername
[i
++] = *p
;
283 myusername
[i
] = '\0';
284 username
= myusername
;
287 if((status
= check_client(client_p
, source_p
, username
)) < 0)
288 return (CLIENT_EXITED
);
290 /* Apply nick override */
291 if(*source_p
->preClient
->spoofnick
)
293 char note
[NICKLEN
+ 10];
295 del_from_client_hash(source_p
->name
, source_p
);
296 strlcpy(source_p
->name
, source_p
->preClient
->spoofnick
, NICKLEN
+ 1);
297 add_to_client_hash(source_p
->name
, source_p
);
299 rb_snprintf(note
, NICKLEN
+ 10, "Nick: %s", source_p
->name
);
300 rb_note(source_p
->localClient
->F
, note
);
303 if(!valid_hostname(source_p
->host
))
305 sendto_one_notice(source_p
, ":*** Notice -- You have an illegal character in your hostname");
307 strlcpy(source_p
->host
, source_p
->sockhost
, sizeof(source_p
->host
));
311 aconf
= source_p
->localClient
->att_conf
;
315 exit_client(client_p
, source_p
, &me
, "*** Not Authorised");
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
->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
= crypt(source_p
->localClient
->passwd
, aconf
->passwd
);
369 encr
= source_p
->localClient
->passwd
;
371 if(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
->name
, NULL
);
418 exit_client(client_p
, source_p
, &me
, "Bad user info");
419 return CLIENT_EXITED
;
423 if (source_p
->preClient
->dnsbl_listed
!= NULL
)
425 if (IsExemptKline(source_p
) || IsConfExemptDNSBL(aconf
))
426 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s, but you are exempt",
427 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
430 rb_dlink_list varlist
= { NULL
, NULL
, 0 };
432 substitution_append_var(&varlist
, "nick", source_p
->name
);
433 substitution_append_var(&varlist
, "ip", source_p
->sockhost
);
434 substitution_append_var(&varlist
, "host", source_p
->host
);
435 substitution_append_var(&varlist
, "dnsbl-host", source_p
->preClient
->dnsbl_listed
->host
);
436 substitution_append_var(&varlist
, "network-name", ServerInfo
.network_name
);
438 ServerStats
.is_ref
++;
440 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
441 me
.name
, source_p
->name
,
442 substitution_parse(source_p
->preClient
->dnsbl_listed
->reject_reason
, &varlist
));
444 substitution_free(&varlist
);
446 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s",
447 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
448 source_p
->preClient
->dnsbl_listed
->hits
++;
449 add_reject(source_p
, NULL
, NULL
);
450 exit_client(client_p
, source_p
, &me
, "*** Banned (DNS blacklist)");
451 return CLIENT_EXITED
;
455 /* valid user name check */
457 if(!valid_username(source_p
->username
))
459 sendto_realops_snomask(SNO_REJ
, L_ALL
,
460 "Invalid username: %s (%s@%s)",
461 source_p
->name
, source_p
->username
, source_p
->host
);
462 ServerStats
.is_ref
++;
463 sendto_one_notice(source_p
, ":*** Your username is invalid. Please make sure that your username contains "
464 "only alphanumeric characters.");
465 rb_sprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
466 exit_client(client_p
, source_p
, &me
, tmpstr2
);
467 return (CLIENT_EXITED
);
470 /* end of valid user name check */
472 /* Store original hostname -- jilles */
473 strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
475 /* Spoof user@host */
476 if(*source_p
->preClient
->spoofuser
)
477 strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
478 if(*source_p
->preClient
->spoofhost
)
480 strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
481 if (irccmp(source_p
->host
, source_p
->orighost
))
482 SetDynSpoof(source_p
);
485 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
& ~orphaned_umodes
;
487 call_hook(h_new_local_user
, source_p
);
489 /* If they have died in send_* or were thrown out by the
490 * new_local_user hook don't do anything. */
491 if(IsAnyDead(source_p
))
492 return CLIENT_EXITED
;
494 /* To avoid inconsistencies, do not abort the registration
495 * starting from this point -- jilles
497 inetntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
499 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
500 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
501 source_p
->name
, source_p
->username
, source_p
->orighost
,
502 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
503 get_client_class(source_p
), source_p
->info
);
505 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
506 "CLICONN %s %s %s %s %s %s 0 %s",
507 source_p
->name
, source_p
->username
, source_p
->orighost
,
508 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
509 get_client_class(source_p
),
510 /* mirc can sometimes send ips here */
511 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
514 add_to_hostname_hash(source_p
->orighost
, source_p
);
516 /* Allocate a UID if it was not previously allocated.
517 * If this already occured, it was probably during SASL auth...
521 strcpy(source_p
->id
, generate_uid());
522 add_to_id_hash(source_p
->id
, source_p
);
526 source_p
->umodes
|= UMODE_SSLCLIENT
;
528 if (source_p
->umodes
& UMODE_INVISIBLE
)
531 s_assert(!IsClient(source_p
));
532 del_unknown_ip(source_p
);
533 rb_dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
536 source_p
->servptr
= &me
;
537 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
539 /* Increment our total user count here */
540 if(++Count
.total
> Count
.max_tot
)
541 Count
.max_tot
= Count
.total
;
543 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
545 Count
.totalrestartcount
++;
547 s_assert(source_p
->localClient
!= NULL
);
549 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
551 Count
.max_loc
= rb_dlink_list_length(&lclient_list
);
552 if(!(Count
.max_loc
% 10))
553 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
554 "New Max Local Clients: %d", Count
.max_loc
);
557 /* they get a reduced limit */
558 if(find_tgchange(source_p
->sockhost
))
559 USED_TARGETS(source_p
) = 6;
561 monitor_signon(source_p
);
562 user_welcome(source_p
);
564 free_pre_client(source_p
);
566 return (introduce_client(client_p
, source_p
, user
, source_p
->name
, 1));
574 * side effects - This common function introduces a client to the rest
575 * of the net, either from a local client connect or
576 * from a remote connect.
579 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
581 static char ubuf
[12];
582 struct Client
*identifyservice_p
;
584 hook_data_umode_changed hdata
;
585 hook_data_client hdata2
;
587 if(MyClient(source_p
))
588 send_umode(source_p
, source_p
, 0, 0, ubuf
);
590 send_umode(NULL
, source_p
, 0, 0, ubuf
);
598 /* if it has an ID, introduce it with its id to TS6 servers,
599 * otherwise introduce it normally to all.
603 char sockhost
[HOSTLEN
];
604 if(source_p
->sockhost
[0] == ':')
608 strlcat(sockhost
, source_p
->sockhost
, sizeof(sockhost
));
610 strcpy(sockhost
, source_p
->sockhost
);
613 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
614 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
615 source_p
->servptr
->id
, nick
,
616 source_p
->hopcount
+ 1,
617 (long) source_p
->tsinfo
, ubuf
,
618 source_p
->username
, source_p
->host
,
619 IsIPSpoof(source_p
) ? "0" : sockhost
,
621 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
622 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
625 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
626 ":%s UID %s %d %ld %s %s %s %s %s :%s",
627 source_p
->servptr
->id
, nick
,
628 source_p
->hopcount
+ 1,
629 (long) source_p
->tsinfo
, ubuf
,
630 source_p
->username
, source_p
->host
,
631 IsIPSpoof(source_p
) ? "0" : sockhost
,
632 source_p
->id
, source_p
->info
);
634 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
,
635 "NICK %s %d %ld %s %s %s %s :%s",
636 nick
, source_p
->hopcount
+ 1,
637 (long) source_p
->tsinfo
,
638 ubuf
, source_p
->username
, source_p
->host
,
639 source_p
->servptr
->name
, source_p
->info
);
642 sendto_server(client_p
, NULL
, NOCAPS
, NOCAPS
,
643 "NICK %s %d %ld %s %s %s %s :%s",
644 nick
, source_p
->hopcount
+ 1,
645 (long) source_p
->tsinfo
,
646 ubuf
, source_p
->username
, source_p
->host
,
647 source_p
->servptr
->name
, source_p
->info
);
649 if (IsDynSpoof(source_p
))
651 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
652 use_id(source_p
), source_p
->orighost
);
653 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s ENCAP * REALHOST %s",
654 source_p
->name
, source_p
->orighost
);
656 if (!EmptyString(source_p
->user
->suser
))
658 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
659 use_id(source_p
), source_p
->user
->suser
);
660 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s ENCAP * LOGIN %s",
661 source_p
->name
, source_p
->user
->suser
);
664 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
666 if (ConfigFileEntry
.identifyservice
[0] != '\0' &&
667 ConfigFileEntry
.identifycommand
[0] != '\0')
669 /* use user@server */
670 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
672 identifyservice_p
= find_named_client(p
+ 1);
674 identifyservice_p
= NULL
;
675 if (identifyservice_p
!= NULL
)
676 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
677 get_id(source_p
, identifyservice_p
),
678 ConfigFileEntry
.identifyservice
,
679 ConfigFileEntry
.identifycommand
,
680 source_p
->localClient
->passwd
);
682 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
683 rb_free(source_p
->localClient
->passwd
);
684 source_p
->localClient
->passwd
= NULL
;
687 /* let modules providing usermodes know that we've got a new user,
688 * why is this here? -- well, some modules need to be able to send out new
689 * information about a client, so this was the best place to do it
692 hdata
.client
= source_p
;
694 hdata
.oldsnomask
= 0;
695 call_hook(h_umode_changed
, &hdata
);
697 /* On the other hand, some modules need to know when a client is
698 * being introduced, period.
701 hdata2
.client
= client_p
;
702 hdata2
.target
= source_p
;
703 call_hook(h_introduce_client
, &hdata2
);
709 * valid_hostname - check hostname for validity
711 * Inputs - pointer to user
712 * Output - YES if valid, NO if not
713 * Side effects - NONE
715 * NOTE: this doesn't allow a hostname to begin with a dot and
716 * will not allow more dots than chars.
719 valid_hostname(const char *hostname
)
721 const char *p
= hostname
;
729 if('.' == *p
|| ':' == *p
)
736 if(*p
== '.' || *p
== ':')
748 * valid_username - check username for validity
750 * Inputs - pointer to user
751 * Output - YES if valid, NO if not
752 * Side effects - NONE
754 * Absolutely always reject any '*' '!' '?' '@' in an user name
755 * reject any odd control characters names.
756 * Allow '.' in username to allow for "first.last"
760 valid_username(const char *username
)
763 const char *p
= username
;
773 /* reject usernames that don't start with an alphanum
774 * i.e. reject jokers who have '-@somehost' or '.@somehost'
775 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
782 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
785 if(dots
> ConfigFileEntry
.dots_in_ident
)
787 if(!IsUserChar(p
[1]))
790 else if(!IsUserChar(*p
))
796 /* report_and_set_user_flags
798 * Inputs - pointer to source_p
799 * - pointer to aconf for this user
802 * Report to user any special flags they are getting, and set them.
806 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
808 /* If this user is being spoofed, tell them so */
809 if(IsConfDoSpoofIp(aconf
))
811 sendto_one_notice(source_p
, ":*** Spoofing your IP. congrats.");
814 /* If this user is in the exception class, Set it "E lined" */
815 if(IsConfExemptKline(aconf
))
817 SetExemptKline(source_p
);
818 sendto_one_notice(source_p
, ":*** You are exempt from K/X lines. congrats.");
821 if(IsConfExemptDNSBL(aconf
))
822 /* kline exempt implies this, don't send both */
823 if(!IsConfExemptKline(aconf
))
824 sendto_one_notice(source_p
, ":*** You are exempt from DNS blacklists.");
826 /* If this user is exempt from user limits set it F lined" */
827 if(IsConfExemptLimits(aconf
))
829 sendto_one_notice(source_p
, ":*** You are exempt from user limits. congrats.");
832 if(IsConfExemptFlood(aconf
))
834 SetExemptFlood(source_p
);
835 sendto_one_notice(source_p
, ":*** You are exempt from flood limits.");
838 if(IsConfExemptSpambot(aconf
))
840 SetExemptSpambot(source_p
);
841 sendto_one_notice(source_p
, ":*** You are exempt from spambot checks.");
844 if(IsConfExemptJupe(aconf
))
846 SetExemptJupe(source_p
);
847 sendto_one_notice(source_p
, ":*** You are exempt from juped channel warnings.");
850 if(IsConfExemptResv(aconf
))
852 SetExemptResv(source_p
);
853 sendto_one_notice(source_p
, ":*** You are exempt from resvs.");
856 if(IsConfExemptShide(aconf
))
858 SetExemptShide(source_p
);
859 sendto_one_notice(source_p
, ":*** You are exempt from serverhiding.");
864 * user_mode - set get current users mode
866 * m_umode() added 15/10/91 By Darren Reed.
868 * parv[1] - username to change mode for
869 * parv[2] - modes to change
872 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
878 struct Client
*target_p
;
880 int badflag
= NO
; /* Only send one bad flag notice */
881 int showsnomask
= NO
;
882 unsigned int setsnomask
;
884 hook_data_umode_changed hdata
;
890 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
894 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
896 if(MyConnect(source_p
))
897 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
898 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
902 /* Dont know why these were commented out..
903 * put them back using new sendto() funcs
906 if(IsServer(source_p
))
908 sendto_realops_snomask(SNO_GENERAL
, L_ADMIN
,
909 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
913 if(source_p
!= target_p
|| target_p
->from
!= source_p
->from
)
915 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
924 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
925 if (source_p
->umodes
& user_modes
[i
])
929 sendto_one_numeric(source_p
, RPL_UMODEIS
, form_str(RPL_UMODEIS
), buf
);
931 if (source_p
->snomask
!= 0)
932 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
933 construct_snobuf(source_p
->snomask
));
938 /* find flags already set for user */
939 setflags
= source_p
->umodes
;
940 setsnomask
= source_p
->snomask
;
943 * parse mode change string(s)
945 for (pm
= parv
[2]; *pm
; pm
++)
958 if(IsServer(client_p
) && !IsOper(source_p
))
962 rb_dlinkAddAlloc(source_p
, &oper_list
);
967 /* Only decrement the oper counts if an oper to begin with
968 * found by Pat Szuta, Perly , perly@xnet.com
971 if(!IsOper(source_p
))
978 if(MyConnect(source_p
))
980 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
981 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
983 source_p
->snomask
= 0;
986 source_p
->flags2
&= ~OPER_FLAGS
;
988 rb_free(source_p
->localClient
->opername
);
989 source_p
->localClient
->opername
= NULL
;
991 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
994 rb_dlinkFindDestroy(source_p
, &oper_list
);
998 /* we may not get these,
999 * but they shouldnt be in default
1002 /* can only be set on burst */
1012 if (MyConnect(source_p
))
1014 if(!IsOper(source_p
)
1015 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
1017 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1022 if(what
== MODE_ADD
)
1025 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1027 source_p
->snomask
|= SNO_GENERAL
;
1030 source_p
->snomask
= 0;
1031 if (source_p
->snomask
!= 0)
1032 source_p
->umodes
|= UMODE_SERVNOTICE
;
1034 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1039 if (MyConnect(source_p
) && *pm
== 'Q' && !ConfigChannel
.use_forward
) {
1044 if((flag
= user_modes
[(unsigned char) *pm
]))
1046 if(MyConnect(source_p
)
1047 && ((!IsOper(source_p
)
1048 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1049 || (orphaned_umodes
& flag
)))
1051 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1056 if(what
== MODE_ADD
)
1057 source_p
->umodes
|= flag
;
1059 source_p
->umodes
&= ~flag
;
1064 if(MyConnect(source_p
))
1071 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1073 if(MyClient(source_p
) && (source_p
->snomask
& SNO_NCHANGE
) && !IsOperN(source_p
))
1075 sendto_one_notice(source_p
, ":*** You need oper and nick_changes flag for +s +n");
1076 source_p
->snomask
&= ~SNO_NCHANGE
; /* only tcm's really need this */
1079 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1081 sendto_one_notice(source_p
, ":*** You need oper and operwall flag for +z");
1082 source_p
->umodes
&= ~UMODE_OPERWALL
;
1085 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1086 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1088 sendto_one_notice(source_p
, ":*** You need oper and admin flag for +a");
1089 source_p
->umodes
&= ~UMODE_ADMIN
;
1092 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1093 hdata
.client
= source_p
;
1094 hdata
.oldumodes
= setflags
;
1095 hdata
.oldsnomask
= setsnomask
;
1096 call_hook(h_umode_changed
, &hdata
);
1098 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1100 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1103 * compare new flags with old flags and send string which
1104 * will cause servers to update correctly.
1106 send_umode_out(client_p
, source_p
, setflags
);
1107 if (showsnomask
&& MyConnect(source_p
))
1108 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1109 construct_snobuf(source_p
->snomask
));
1115 * send the MODE string for user (user) to connection client_p
1119 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, int sendmask
, char *umode_buf
)
1127 * build a string in umode_buf to represent the change in the user's
1128 * mode between the new (source_p->flag) and 'old'.
1133 for (i
= 0; i
< 128; i
++)
1135 flag
= user_modes
[i
];
1137 if((flag
& old
) && !(source_p
->umodes
& flag
))
1139 if(what
== MODE_DEL
)
1148 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1150 if(what
== MODE_ADD
)
1162 if(*umode_buf
&& client_p
)
1163 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1174 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1176 struct Client
*target_p
;
1180 send_umode(NULL
, source_p
, old
, 0, buf
);
1182 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1184 target_p
= ptr
->data
;
1186 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1188 sendto_one(target_p
, ":%s MODE %s :%s",
1189 get_id(source_p
, target_p
),
1190 get_id(source_p
, target_p
), buf
);
1194 if(client_p
&& MyClient(client_p
))
1195 send_umode(client_p
, source_p
, old
, 0, buf
);
1201 * inputs - client pointer to client to welcome
1206 user_welcome(struct Client
*source_p
)
1208 sendto_one_numeric(source_p
, RPL_WELCOME
, form_str(RPL_WELCOME
), ServerInfo
.network_name
, source_p
->name
);
1209 sendto_one_numeric(source_p
, RPL_YOURHOST
, form_str(RPL_YOURHOST
),
1210 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1211 sendto_one_numeric(source_p
, RPL_CREATED
, form_str(RPL_CREATED
), creation
);
1212 sendto_one_numeric(source_p
, RPL_MYINFO
, form_str(RPL_MYINFO
), me
.name
, ircd_version
, umodebuf
);
1214 show_isupport(source_p
);
1216 show_lusers(source_p
);
1218 if(ConfigFileEntry
.short_motd
)
1220 sendto_one_notice(source_p
, ":*** Notice -- motd was last changed at %s", user_motd_changed
);
1221 sendto_one_notice(source_p
, ":*** Notice -- Please read the motd if you haven't read it");
1223 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1224 me
.name
, source_p
->name
, me
.name
);
1226 sendto_one(source_p
, form_str(RPL_MOTD
),
1227 me
.name
, source_p
->name
, "*** This is the short motd ***");
1229 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1232 send_user_motd(source_p
);
1237 * inputs - pointer to given client to oper
1238 * - pointer to ConfItem to use
1240 * side effects - opers up source_p using aconf for reference
1243 oper_up(struct Client
*source_p
, struct oper_conf
*oper_p
)
1245 unsigned int old
= source_p
->umodes
, oldsnomask
= source_p
->snomask
;
1246 hook_data_umode_changed hdata
;
1251 source_p
->umodes
|= oper_p
->umodes
;
1252 else if(ConfigFileEntry
.oper_umodes
)
1253 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1255 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1257 if (oper_p
->snomask
)
1259 source_p
->snomask
|= oper_p
->snomask
;
1260 source_p
->umodes
|= UMODE_SERVNOTICE
;
1262 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1264 /* Only apply these if +s is already set -- jilles */
1265 if (ConfigFileEntry
.oper_snomask
)
1266 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1268 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1273 SetExemptKline(source_p
);
1275 source_p
->flags2
|= oper_p
->flags
;
1276 source_p
->localClient
->opername
= rb_strdup(oper_p
->name
);
1278 rb_dlinkAddAlloc(source_p
, &local_oper_list
);
1279 rb_dlinkAddAlloc(source_p
, &oper_list
);
1281 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1282 source_p
->umodes
|= UMODE_ADMIN
;
1283 if(!IsOperN(source_p
))
1284 source_p
->snomask
&= ~SNO_NCHANGE
;
1285 if(!IsOperOperwall(source_p
))
1286 source_p
->umodes
&= ~UMODE_OPERWALL
;
1287 hdata
.client
= source_p
;
1288 hdata
.oldumodes
= old
;
1289 hdata
.oldsnomask
= oldsnomask
;
1290 call_hook(h_umode_changed
, &hdata
);
1292 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1293 "%s (%s@%s) is now an operator", source_p
->name
,
1294 source_p
->username
, source_p
->host
);
1295 if(!(old
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1297 if((old
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1299 send_umode_out(source_p
, source_p
, old
);
1300 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1301 construct_snobuf(source_p
->snomask
));
1302 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1303 sendto_one_notice(source_p
, ":*** Oper privs are %s", get_oper_privs(oper_p
->flags
));
1304 send_oper_motd(source_p
);
1313 * outputs - an available umode bitmask or
1314 * 0 if no umodes are available
1315 * side effects - NONE
1318 find_umode_slot(void)
1320 unsigned int all_umodes
= 0, my_umode
= 0, i
;
1322 for (i
= 0; i
< 128; i
++)
1323 all_umodes
|= user_modes
[i
];
1325 for (my_umode
= 1; my_umode
&& (all_umodes
& my_umode
);
1332 construct_umodebuf(void)
1335 char *ptr
= umodebuf
;
1336 static int prev_user_modes
[128];
1340 for (i
= 0; i
< 128; i
++)
1342 if (prev_user_modes
[i
] != 0 && prev_user_modes
[i
] != user_modes
[i
])
1344 if (user_modes
[i
] == 0)
1346 orphaned_umodes
|= prev_user_modes
[i
];
1347 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Umode +%c is now orphaned", i
);
1351 orphaned_umodes
&= ~prev_user_modes
[i
];
1352 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Orphaned umode +%c is picked up by module", i
);
1354 user_modes
[i
] = prev_user_modes
[i
];
1357 prev_user_modes
[i
] = user_modes
[i
];
1366 change_nick_user_host(struct Client
*target_p
, const char *nick
, const char *user
,
1367 const char *host
, int newts
, const char *format
, ...)
1370 struct Channel
*chptr
;
1371 struct membership
*mscptr
;
1372 int changed
= irccmp(target_p
->name
, nick
);
1373 int changed_case
= strcmp(target_p
->name
, nick
);
1374 int do_qjm
= irccmp(target_p
->username
, user
) || irccmp(target_p
->host
, host
);
1375 char mode
[10], modeval
[NICKLEN
* 2 + 2], reason
[256], *mptr
;
1382 target_p
->tsinfo
= newts
;
1383 monitor_signoff(target_p
);
1385 invalidate_bancache_user(target_p
);
1389 va_start(ap
, format
);
1390 vsnprintf(reason
, 255, format
, ap
);
1393 sendto_common_channels_local_butone(target_p
, ":%s!%s@%s QUIT :%s",
1394 target_p
->name
, target_p
->username
, target_p
->host
,
1397 RB_DLINK_FOREACH(ptr
, target_p
->user
->channel
.head
)
1400 chptr
= mscptr
->chptr
;
1403 if(is_chanop(mscptr
))
1406 strcat(modeval
, nick
);
1407 strcat(modeval
, " ");
1410 if(is_voiced(mscptr
))
1413 strcat(modeval
, nick
);
1418 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
1419 nick
, user
, host
, chptr
->chname
);
1421 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
,
1422 ":%s MODE %s +%s %s",
1423 target_p
->servptr
->name
,
1424 chptr
->chname
, mode
, modeval
);
1429 if(MyClient(target_p
) && changed_case
)
1430 sendto_one(target_p
, ":%s!%s@%s NICK %s",
1431 target_p
->name
, target_p
->username
, target_p
->host
, nick
);
1433 else if(changed_case
)
1435 sendto_common_channels_local(target_p
, ":%s!%s@%s NICK :%s",
1436 target_p
->name
, target_p
->username
,
1437 target_p
->host
, nick
);
1440 strlcpy(target_p
->username
, user
, sizeof target_p
->username
);
1441 strlcpy(target_p
->host
, host
, sizeof target_p
->host
);
1444 add_history(target_p
, 1);
1446 del_from_client_hash(target_p
->name
, target_p
);
1447 strlcpy(target_p
->name
, nick
, NICKLEN
);
1448 add_to_client_hash(target_p
->name
, target_p
);
1452 monitor_signon(target_p
);
1453 del_all_accepts(target_p
);