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
),
155 Count
.invisi
, 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
), rb_dlink_list_length(&oper_list
));
161 if(rb_dlink_list_length(&unknown_list
) > 0)
162 sendto_one_numeric(source_p
, RPL_LUSERUNKNOWN
,
163 form_str(RPL_LUSERUNKNOWN
),
164 rb_dlink_list_length(&unknown_list
));
166 if(rb_dlink_list_length(&global_channel_list
) > 0)
167 sendto_one_numeric(source_p
, RPL_LUSERCHANNELS
,
168 form_str(RPL_LUSERCHANNELS
),
169 rb_dlink_list_length(&global_channel_list
));
171 sendto_one_numeric(source_p
, RPL_LUSERME
, form_str(RPL_LUSERME
),
172 rb_dlink_list_length(&lclient_list
),
173 rb_dlink_list_length(&serv_list
));
175 sendto_one_numeric(source_p
, RPL_LOCALUSERS
,
176 form_str(RPL_LOCALUSERS
),
177 rb_dlink_list_length(&lclient_list
),
179 rb_dlink_list_length(&lclient_list
),
182 sendto_one_numeric(source_p
, RPL_GLOBALUSERS
, form_str(RPL_GLOBALUSERS
),
183 Count
.total
, Count
.max_tot
,
184 Count
.total
, Count
.max_tot
);
186 sendto_one_numeric(source_p
, RPL_STATSCONN
,
187 form_str(RPL_STATSCONN
),
188 MaxConnectionCount
, MaxClientCount
,
189 Count
.totalrestartcount
);
195 ** register_local_user
196 ** This function is called when both NICK and USER messages
197 ** have been accepted for the client, in whatever order. Only
198 ** after this, is the USER message propagated.
200 ** NICK's must be propagated at once when received, although
201 ** it would be better to delay them too until full info is
202 ** available. Doing it is not so simple though, would have
203 ** to implement the following:
205 ** (actually it has been implemented already for a while) -orabidoo
207 ** 1) user telnets in and gives only "NICK foobar" and waits
208 ** 2) another user far away logs in normally with the nick
209 ** "foobar" (quite legal, as this server didn't propagate
211 ** 3) now this server gets nick "foobar" from outside, but
212 ** has alread the same defined locally. Current server
213 ** would just issue "KILL foobar" to clean out dups. But,
214 ** this is not fair. It should actually request another
215 ** nick from local user or kill him/her...
219 register_local_user(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
221 struct ConfItem
*aconf
, *xconf
;
222 struct User
*user
= source_p
->user
;
223 char tmpstr2
[IRCD_BUFSIZE
];
224 char ipaddr
[HOSTIPLEN
];
225 char myusername
[USERLEN
+1];
228 s_assert(NULL
!= source_p
);
229 s_assert(MyConnect(source_p
));
230 s_assert(source_p
->username
!= username
);
235 if(IsAnyDead(source_p
))
238 if(ConfigFileEntry
.ping_cookie
)
240 if(!(source_p
->flags
& FLAGS_PINGSENT
) && source_p
->localClient
->random_ping
== 0)
242 source_p
->localClient
->random_ping
= (unsigned long) (rand() * rand()) << 1;
243 sendto_one(source_p
, "PING :%08lX",
244 (unsigned long) source_p
->localClient
->random_ping
);
245 source_p
->flags
|= FLAGS_PINGSENT
;
248 if(!(source_p
->flags
& FLAGS_PING_COOKIE
))
254 /* hasnt finished client cap negotiation */
255 if(source_p
->flags
& FLAGS_CLICAP
)
258 /* still has DNSbls to validate against */
259 if(rb_dlink_list_length(&source_p
->preClient
->dnsbl_queries
) > 0)
262 client_p
->localClient
->last
= rb_current_time();
263 /* Straight up the maximum rate of flooding... */
264 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
266 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
267 if(!IsGotId(source_p
) && (strchr(username
, '[') != NULL
))
274 while(*p
&& i
< USERLEN
)
277 myusername
[i
++] = *p
;
281 myusername
[i
] = '\0';
282 username
= myusername
;
285 if((status
= check_client(client_p
, source_p
, username
)) < 0)
286 return (CLIENT_EXITED
);
288 /* Apply nick override */
289 if(*source_p
->preClient
->spoofnick
)
291 char note
[NICKLEN
+ 10];
293 del_from_client_hash(source_p
->name
, source_p
);
294 rb_strlcpy(source_p
->name
, source_p
->preClient
->spoofnick
, NICKLEN
+ 1);
295 add_to_client_hash(source_p
->name
, source_p
);
297 rb_snprintf(note
, NICKLEN
+ 10, "Nick: %s", source_p
->name
);
298 rb_note(source_p
->localClient
->F
, note
);
301 if(!valid_hostname(source_p
->host
))
303 sendto_one_notice(source_p
, ":*** Notice -- You have an illegal character in your hostname");
305 rb_strlcpy(source_p
->host
, source_p
->sockhost
, sizeof(source_p
->host
));
309 aconf
= source_p
->localClient
->att_conf
;
313 exit_client(client_p
, source_p
, &me
, "*** Not Authorised");
314 return (CLIENT_EXITED
);
317 if(IsConfSSLNeeded(aconf
) && !IsSSL(source_p
))
319 ServerStats
.is_ref
++;
320 sendto_one_notice(source_p
, ":*** Notice -- You need to use SSL/TLS to use this server");
321 exit_client(client_p
, source_p
, &me
, "Use SSL/TLS");
322 return (CLIENT_EXITED
);
325 if(!IsGotId(source_p
))
330 if(IsNeedIdentd(aconf
))
332 ServerStats
.is_ref
++;
333 sendto_one_notice(source_p
, ":*** Notice -- You need to install identd to use this server");
334 exit_client(client_p
, source_p
, &me
, "Install identd");
335 return (CLIENT_EXITED
);
338 /* dont replace username if its supposed to be spoofed --fl */
339 if(!IsConfDoSpoofIp(aconf
) || !strchr(aconf
->name
, '@'))
343 if(!IsNoTilde(aconf
))
344 source_p
->username
[i
++] = '~';
346 while (*p
&& i
< USERLEN
)
349 source_p
->username
[i
++] = *p
;
353 source_p
->username
[i
] = '\0';
357 if(IsNeedSasl(aconf
) && !*user
->suser
)
359 ServerStats
.is_ref
++;
360 sendto_one_notice(source_p
, ":*** Notice -- You need to identify via SASL to use this server");
361 exit_client(client_p
, source_p
, &me
, "SASL access only");
362 return (CLIENT_EXITED
);
366 if(!EmptyString(aconf
->passwd
))
370 if(EmptyString(source_p
->localClient
->passwd
))
372 else if(IsConfEncrypted(aconf
))
373 encr
= rb_crypt(source_p
->localClient
->passwd
, aconf
->passwd
);
375 encr
= source_p
->localClient
->passwd
;
377 if(strcmp(encr
, aconf
->passwd
))
379 ServerStats
.is_ref
++;
380 sendto_one(source_p
, form_str(ERR_PASSWDMISMATCH
), me
.name
, source_p
->name
);
381 exit_client(client_p
, source_p
, &me
, "Bad Password");
382 return (CLIENT_EXITED
);
385 /* clear password only if used now, otherwise send it
386 * to services -- jilles */
387 if(source_p
->localClient
->passwd
)
389 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
390 rb_free(source_p
->localClient
->passwd
);
391 source_p
->localClient
->passwd
= NULL
;
395 /* report if user has &^>= etc. and set flags as needed in source_p */
396 report_and_set_user_flags(source_p
, aconf
);
400 * We want to be able to have servers and F-line clients
401 * connect, so save room for "buffer" connections.
402 * Smaller servers may want to decrease this, and it should
403 * probably be just a percentage of the MAXCLIENTS...
406 /* Except "F:" clients */
407 if(rb_dlink_list_length(&lclient_list
) >=
408 (unsigned long)GlobalSetOptions
.maxclients
&& !IsConfExemptLimits(aconf
))
410 sendto_realops_snomask(SNO_FULL
, L_ALL
,
411 "Too many clients, rejecting %s[%s].", source_p
->name
, source_p
->host
);
413 ServerStats
.is_ref
++;
414 exit_client(client_p
, source_p
, &me
, "Sorry, server is full - try later");
415 return (CLIENT_EXITED
);
418 /* kline exemption extends to xline too */
419 if(!IsExemptKline(source_p
) &&
420 (xconf
= find_xline(source_p
->info
, 1)) != NULL
)
422 ServerStats
.is_ref
++;
423 add_reject(source_p
, xconf
->name
, NULL
);
424 exit_client(client_p
, source_p
, &me
, "Bad user info");
425 return CLIENT_EXITED
;
429 if (source_p
->preClient
->dnsbl_listed
!= NULL
)
431 if (IsExemptKline(source_p
) || IsConfExemptDNSBL(aconf
))
432 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s, but you are exempt",
433 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
436 rb_dlink_list varlist
= { NULL
, NULL
, 0 };
438 substitution_append_var(&varlist
, "nick", source_p
->name
);
439 substitution_append_var(&varlist
, "ip", source_p
->sockhost
);
440 substitution_append_var(&varlist
, "host", source_p
->host
);
441 substitution_append_var(&varlist
, "dnsbl-host", source_p
->preClient
->dnsbl_listed
->host
);
442 substitution_append_var(&varlist
, "network-name", ServerInfo
.network_name
);
444 ServerStats
.is_ref
++;
446 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
447 me
.name
, source_p
->name
,
448 substitution_parse(source_p
->preClient
->dnsbl_listed
->reject_reason
, &varlist
));
450 substitution_free(&varlist
);
452 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s",
453 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
454 source_p
->preClient
->dnsbl_listed
->hits
++;
455 add_reject(source_p
, NULL
, NULL
);
456 exit_client(client_p
, source_p
, &me
, "*** Banned (DNS blacklist)");
457 return CLIENT_EXITED
;
461 /* valid user name check */
463 if(!valid_username(source_p
->username
))
465 sendto_realops_snomask(SNO_REJ
, L_ALL
,
466 "Invalid username: %s (%s@%s)",
467 source_p
->name
, source_p
->username
, source_p
->host
);
468 ServerStats
.is_ref
++;
469 sendto_one_notice(source_p
, ":*** Your username is invalid. Please make sure that your username contains "
470 "only alphanumeric characters.");
471 rb_sprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
472 exit_client(client_p
, source_p
, &me
, tmpstr2
);
473 return (CLIENT_EXITED
);
476 /* end of valid user name check */
478 /* Store original hostname -- jilles */
479 rb_strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
481 /* Spoof user@host */
482 if(*source_p
->preClient
->spoofuser
)
483 rb_strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
484 if(*source_p
->preClient
->spoofhost
)
486 rb_strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
487 if (irccmp(source_p
->host
, source_p
->orighost
))
488 SetDynSpoof(source_p
);
491 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
& ~orphaned_umodes
;
493 call_hook(h_new_local_user
, source_p
);
495 /* If they have died in send_* or were thrown out by the
496 * new_local_user hook don't do anything. */
497 if(IsAnyDead(source_p
))
498 return CLIENT_EXITED
;
500 /* To avoid inconsistencies, do not abort the registration
501 * starting from this point -- jilles
503 rb_inet_ntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
505 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
506 "Client connecting: %s (%s@%s) [%s] {%s} [%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
), source_p
->info
);
511 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
512 "CLICONN %s %s %s %s %s %s 0 %s",
513 source_p
->name
, source_p
->username
, source_p
->orighost
,
514 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
515 get_client_class(source_p
),
516 /* mirc can sometimes send ips here */
517 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
520 add_to_hostname_hash(source_p
->orighost
, source_p
);
522 /* Allocate a UID if it was not previously allocated.
523 * If this already occured, it was probably during SASL auth...
527 strcpy(source_p
->id
, generate_uid());
528 add_to_id_hash(source_p
->id
, source_p
);
532 source_p
->umodes
|= UMODE_SSLCLIENT
;
534 if (source_p
->umodes
& UMODE_INVISIBLE
)
537 s_assert(!IsClient(source_p
));
538 rb_dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
541 source_p
->servptr
= &me
;
542 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
544 /* Increment our total user count here */
545 if(++Count
.total
> Count
.max_tot
)
546 Count
.max_tot
= Count
.total
;
548 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
550 Count
.totalrestartcount
++;
552 s_assert(source_p
->localClient
!= NULL
);
554 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
556 Count
.max_loc
= rb_dlink_list_length(&lclient_list
);
557 if(!(Count
.max_loc
% 10))
558 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
559 "New Max Local Clients: %d", Count
.max_loc
);
562 /* they get a reduced limit */
563 if(find_tgchange(source_p
->sockhost
))
564 USED_TARGETS(source_p
) = 6;
566 monitor_signon(source_p
);
567 user_welcome(source_p
);
569 free_pre_client(source_p
);
571 return (introduce_client(client_p
, source_p
, user
, source_p
->name
, 1));
579 * side effects - This common function introduces a client to the rest
580 * of the net, either from a local client connect or
581 * from a remote connect.
584 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
586 static char ubuf
[12];
587 struct Client
*identifyservice_p
;
589 hook_data_umode_changed hdata
;
590 hook_data_client hdata2
;
591 char sockhost
[HOSTLEN
];
593 if(MyClient(source_p
))
594 send_umode(source_p
, source_p
, 0, 0, ubuf
);
596 send_umode(NULL
, source_p
, 0, 0, ubuf
);
604 s_assert(has_id(source_p
));
606 if(source_p
->sockhost
[0] == ':')
610 rb_strlcat(sockhost
, source_p
->sockhost
, sizeof(sockhost
));
612 strcpy(sockhost
, source_p
->sockhost
);
615 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
616 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
617 source_p
->servptr
->id
, nick
,
618 source_p
->hopcount
+ 1,
619 (long) source_p
->tsinfo
, ubuf
,
620 source_p
->username
, source_p
->host
,
621 IsIPSpoof(source_p
) ? "0" : sockhost
,
623 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
624 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
627 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
628 ":%s UID %s %d %ld %s %s %s %s %s :%s",
629 source_p
->servptr
->id
, nick
,
630 source_p
->hopcount
+ 1,
631 (long) source_p
->tsinfo
, ubuf
,
632 source_p
->username
, source_p
->host
,
633 IsIPSpoof(source_p
) ? "0" : sockhost
,
634 source_p
->id
, source_p
->info
);
636 if (IsDynSpoof(source_p
))
638 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
639 use_id(source_p
), source_p
->orighost
);
642 if (!EmptyString(source_p
->user
->suser
))
644 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
645 use_id(source_p
), source_p
->user
->suser
);
648 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
650 if (ConfigFileEntry
.identifyservice
[0] != '\0' &&
651 ConfigFileEntry
.identifycommand
[0] != '\0')
653 /* use user@server */
654 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
656 identifyservice_p
= find_named_client(p
+ 1);
658 identifyservice_p
= NULL
;
659 if (identifyservice_p
!= NULL
)
661 if (!EmptyString(source_p
->localClient
->auth_user
))
662 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s %s",
663 get_id(source_p
, identifyservice_p
),
664 ConfigFileEntry
.identifyservice
,
665 ConfigFileEntry
.identifycommand
,
666 source_p
->localClient
->auth_user
,
667 source_p
->localClient
->passwd
);
669 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
670 get_id(source_p
, identifyservice_p
),
671 ConfigFileEntry
.identifyservice
,
672 ConfigFileEntry
.identifycommand
,
673 source_p
->localClient
->passwd
);
676 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
677 rb_free(source_p
->localClient
->passwd
);
678 source_p
->localClient
->passwd
= NULL
;
681 /* let modules providing usermodes know that we've got a new user,
682 * why is this here? -- well, some modules need to be able to send out new
683 * information about a client, so this was the best place to do it
686 hdata
.client
= source_p
;
688 hdata
.oldsnomask
= 0;
689 call_hook(h_umode_changed
, &hdata
);
691 /* On the other hand, some modules need to know when a client is
692 * being introduced, period.
695 hdata2
.client
= client_p
;
696 hdata2
.target
= source_p
;
697 call_hook(h_introduce_client
, &hdata2
);
703 * valid_hostname - check hostname for validity
705 * Inputs - pointer to user
706 * Output - YES if valid, NO 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
;
723 if('.' == *p
|| ':' == *p
)
730 if(*p
== '.' || *p
== ':')
742 * valid_username - check username for validity
744 * Inputs - pointer to user
745 * Output - YES if valid, NO if not
746 * Side effects - NONE
748 * Absolutely always reject any '*' '!' '?' '@' in an user name
749 * reject any odd control characters names.
750 * Allow '.' in username to allow for "first.last"
754 valid_username(const char *username
)
757 const char *p
= username
;
767 /* reject usernames that don't start with an alphanum
768 * i.e. reject jokers who have '-@somehost' or '.@somehost'
769 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
776 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
779 if(dots
> ConfigFileEntry
.dots_in_ident
)
781 if(!IsUserChar(p
[1]))
784 else if(!IsUserChar(*p
))
790 /* report_and_set_user_flags
792 * Inputs - pointer to source_p
793 * - pointer to aconf for this user
796 * Report to user any special flags they are getting, and set them.
800 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
802 /* If this user is being spoofed, tell them so */
803 if(IsConfDoSpoofIp(aconf
))
805 sendto_one_notice(source_p
, ":*** Spoofing your IP");
808 /* If this user is in the exception class, Set it "E lined" */
809 if(IsConfExemptKline(aconf
))
811 SetExemptKline(source_p
);
812 sendto_one_notice(source_p
, ":*** You are exempt from K/X lines");
815 if(IsConfExemptDNSBL(aconf
))
816 /* kline exempt implies this, don't send both */
817 if(!IsConfExemptKline(aconf
))
818 sendto_one_notice(source_p
, ":*** You are exempt from DNS blacklists");
820 /* If this user is exempt from user limits set it F lined" */
821 if(IsConfExemptLimits(aconf
))
823 sendto_one_notice(source_p
, ":*** You are exempt from user limits");
826 if(IsConfExemptFlood(aconf
))
828 SetExemptFlood(source_p
);
829 sendto_one_notice(source_p
, ":*** You are exempt from flood limits");
832 if(IsConfExemptSpambot(aconf
))
834 SetExemptSpambot(source_p
);
835 sendto_one_notice(source_p
, ":*** You are exempt from spambot checks");
838 if(IsConfExemptJupe(aconf
))
840 SetExemptJupe(source_p
);
841 sendto_one_notice(source_p
, ":*** You are exempt from juped channel warnings");
844 if(IsConfExemptResv(aconf
))
846 SetExemptResv(source_p
);
847 sendto_one_notice(source_p
, ":*** You are exempt from resvs");
850 if(IsConfExemptShide(aconf
))
852 SetExemptShide(source_p
);
853 sendto_one_notice(source_p
, ":*** You are exempt from serverhiding");
858 show_other_user_mode(struct Client
*source_p
, struct Client
*target_p
)
867 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
868 if (target_p
->umodes
& user_modes
[i
])
872 if (MyConnect(target_p
) && target_p
->snomask
!= 0)
873 sendto_one_notice(source_p
, ":Modes for %s are %s %s",
875 construct_snobuf(target_p
->snomask
));
877 sendto_one_notice(source_p
, ":Modes for %s are %s",
878 target_p
->name
, buf
);
882 * user_mode - set get current users mode
884 * m_umode() added 15/10/91 By Darren Reed.
885 * parv[1] - username to change mode for
886 * parv[2] - modes to change
889 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
895 struct Client
*target_p
;
897 int badflag
= NO
; /* Only send one bad flag notice */
898 int showsnomask
= NO
;
899 unsigned int setsnomask
;
901 hook_data_umode_changed hdata
;
907 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
911 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
913 if(MyConnect(source_p
))
914 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
915 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
919 /* Dont know why these were commented out..
920 * put them back using new sendto() funcs
923 if(IsServer(source_p
))
925 sendto_realops_snomask(SNO_GENERAL
, L_ADMIN
,
926 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
930 if(source_p
!= target_p
)
932 if (MyOper(source_p
) && parc
< 3)
933 show_other_user_mode(source_p
, target_p
);
935 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
944 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
945 if (source_p
->umodes
& user_modes
[i
])
949 sendto_one_numeric(source_p
, RPL_UMODEIS
, form_str(RPL_UMODEIS
), buf
);
951 if (source_p
->snomask
!= 0)
952 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
953 construct_snobuf(source_p
->snomask
));
958 /* find flags already set for user */
959 setflags
= source_p
->umodes
;
960 setsnomask
= source_p
->snomask
;
963 * parse mode change string(s)
965 for (pm
= parv
[2]; *pm
; pm
++)
978 if(IsServer(client_p
) && !IsOper(source_p
))
982 rb_dlinkAddAlloc(source_p
, &oper_list
);
987 /* Only decrement the oper counts if an oper to begin with
988 * found by Pat Szuta, Perly , perly@xnet.com
991 if(!IsOper(source_p
))
998 if(MyConnect(source_p
))
1000 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
1001 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
1003 source_p
->snomask
= 0;
1006 source_p
->flags2
&= ~OPER_FLAGS
;
1008 rb_free(source_p
->localClient
->opername
);
1009 source_p
->localClient
->opername
= NULL
;
1011 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1012 privilegeset_unref(source_p
->localClient
->privset
);
1013 source_p
->localClient
->privset
= NULL
;
1016 rb_dlinkFindDestroy(source_p
, &oper_list
);
1020 /* we may not get these,
1021 * but they shouldnt be in default
1024 /* can only be set on burst */
1034 if (MyConnect(source_p
))
1036 if(!IsOper(source_p
)
1037 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
1039 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1044 if(what
== MODE_ADD
)
1047 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1049 source_p
->snomask
|= SNO_GENERAL
;
1052 source_p
->snomask
= 0;
1053 if (source_p
->snomask
!= 0)
1054 source_p
->umodes
|= UMODE_SERVNOTICE
;
1056 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1061 if (MyConnect(source_p
) && *pm
== 'Q' && !ConfigChannel
.use_forward
) {
1066 if((flag
= user_modes
[(unsigned char) *pm
]))
1068 if(MyConnect(source_p
)
1069 && ((!IsOper(source_p
)
1070 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1071 || (orphaned_umodes
& flag
)))
1073 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1078 if(what
== MODE_ADD
)
1079 source_p
->umodes
|= flag
;
1081 source_p
->umodes
&= ~flag
;
1086 if(MyConnect(source_p
))
1093 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1095 if(MyClient(source_p
) && (source_p
->snomask
& SNO_NCHANGE
) && !IsOperN(source_p
))
1097 sendto_one_notice(source_p
, ":*** You need oper and nick_changes flag for +s +n");
1098 source_p
->snomask
&= ~SNO_NCHANGE
; /* only tcm's really need this */
1101 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1103 sendto_one_notice(source_p
, ":*** You need oper and operwall flag for +z");
1104 source_p
->umodes
&= ~UMODE_OPERWALL
;
1107 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1108 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1110 sendto_one_notice(source_p
, ":*** You need oper and admin flag for +a");
1111 source_p
->umodes
&= ~UMODE_ADMIN
;
1114 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1115 hdata
.client
= source_p
;
1116 hdata
.oldumodes
= setflags
;
1117 hdata
.oldsnomask
= setsnomask
;
1118 call_hook(h_umode_changed
, &hdata
);
1120 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1122 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1125 * compare new flags with old flags and send string which
1126 * will cause servers to update correctly.
1128 send_umode_out(client_p
, source_p
, setflags
);
1129 if (showsnomask
&& MyConnect(source_p
))
1130 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1131 construct_snobuf(source_p
->snomask
));
1137 * send the MODE string for user (user) to connection client_p
1141 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, int sendmask
, char *umode_buf
)
1149 * build a string in umode_buf to represent the change in the user's
1150 * mode between the new (source_p->flag) and 'old'.
1155 for (i
= 0; i
< 128; i
++)
1157 flag
= user_modes
[i
];
1159 if((flag
& old
) && !(source_p
->umodes
& flag
))
1161 if(what
== MODE_DEL
)
1170 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1172 if(what
== MODE_ADD
)
1184 if(*umode_buf
&& client_p
)
1185 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1196 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1198 struct Client
*target_p
;
1202 send_umode(NULL
, source_p
, old
, 0, buf
);
1204 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1206 target_p
= ptr
->data
;
1208 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1210 sendto_one(target_p
, ":%s MODE %s :%s",
1211 get_id(source_p
, target_p
),
1212 get_id(source_p
, target_p
), buf
);
1216 if(client_p
&& MyClient(client_p
))
1217 send_umode(client_p
, source_p
, old
, 0, buf
);
1223 * inputs - client pointer to client to welcome
1228 user_welcome(struct Client
*source_p
)
1230 sendto_one_numeric(source_p
, RPL_WELCOME
, form_str(RPL_WELCOME
), ServerInfo
.network_name
, source_p
->name
);
1231 sendto_one_numeric(source_p
, RPL_YOURHOST
, form_str(RPL_YOURHOST
),
1232 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1233 sendto_one_numeric(source_p
, RPL_CREATED
, form_str(RPL_CREATED
), creation
);
1234 sendto_one_numeric(source_p
, RPL_MYINFO
, form_str(RPL_MYINFO
), me
.name
, ircd_version
, umodebuf
, cflagsmyinfo
);
1236 show_isupport(source_p
);
1238 show_lusers(source_p
);
1240 if(ConfigFileEntry
.short_motd
)
1242 sendto_one_notice(source_p
, ":*** Notice -- motd was last changed at %s", user_motd_changed
);
1243 sendto_one_notice(source_p
, ":*** Notice -- Please read the motd if you haven't read it");
1245 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1246 me
.name
, source_p
->name
, me
.name
);
1248 sendto_one(source_p
, form_str(RPL_MOTD
),
1249 me
.name
, source_p
->name
, "*** This is the short motd ***");
1251 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1254 send_user_motd(source_p
);
1259 * inputs - pointer to given client to oper
1260 * - pointer to ConfItem to use
1262 * side effects - opers up source_p using aconf for reference
1265 oper_up(struct Client
*source_p
, struct oper_conf
*oper_p
)
1267 unsigned int old
= source_p
->umodes
, oldsnomask
= source_p
->snomask
;
1268 hook_data_umode_changed hdata
;
1273 source_p
->umodes
|= oper_p
->umodes
;
1274 else if(ConfigFileEntry
.oper_umodes
)
1275 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1277 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1279 if (oper_p
->snomask
)
1281 source_p
->snomask
|= oper_p
->snomask
;
1282 source_p
->umodes
|= UMODE_SERVNOTICE
;
1284 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1286 /* Only apply these if +s is already set -- jilles */
1287 if (ConfigFileEntry
.oper_snomask
)
1288 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1290 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1295 SetExemptKline(source_p
);
1297 source_p
->flags2
|= oper_p
->flags
;
1298 source_p
->localClient
->opername
= rb_strdup(oper_p
->name
);
1299 source_p
->localClient
->privset
= privilegeset_ref(oper_p
->privset
);
1301 rb_dlinkAddAlloc(source_p
, &local_oper_list
);
1302 rb_dlinkAddAlloc(source_p
, &oper_list
);
1304 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1305 source_p
->umodes
|= UMODE_ADMIN
;
1306 if(!IsOperN(source_p
))
1307 source_p
->snomask
&= ~SNO_NCHANGE
;
1308 if(!IsOperOperwall(source_p
))
1309 source_p
->umodes
&= ~UMODE_OPERWALL
;
1310 hdata
.client
= source_p
;
1311 hdata
.oldumodes
= old
;
1312 hdata
.oldsnomask
= oldsnomask
;
1313 call_hook(h_umode_changed
, &hdata
);
1315 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1316 "%s (%s@%s) is now an operator", source_p
->name
,
1317 source_p
->username
, source_p
->host
);
1318 if(!(old
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1320 if((old
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1322 send_umode_out(source_p
, source_p
, old
);
1323 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1324 construct_snobuf(source_p
->snomask
));
1325 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1326 sendto_one_notice(source_p
, ":*** Oper privilege set is %s", oper_p
->privset
->name
);
1327 sendto_one_notice(source_p
, ":*** Oper privs are %s", oper_p
->privset
->privs
);
1328 send_oper_motd(source_p
);
1337 * outputs - an available umode bitmask or
1338 * 0 if no umodes are available
1339 * side effects - NONE
1342 find_umode_slot(void)
1344 unsigned int all_umodes
= 0, my_umode
= 0, i
;
1346 for (i
= 0; i
< 128; i
++)
1347 all_umodes
|= user_modes
[i
];
1349 for (my_umode
= 1; my_umode
&& (all_umodes
& my_umode
);
1356 construct_umodebuf(void)
1359 char *ptr
= umodebuf
;
1360 static int prev_user_modes
[128];
1364 for (i
= 0; i
< 128; i
++)
1366 if (prev_user_modes
[i
] != 0 && prev_user_modes
[i
] != user_modes
[i
])
1368 if (user_modes
[i
] == 0)
1370 orphaned_umodes
|= prev_user_modes
[i
];
1371 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Umode +%c is now orphaned", i
);
1375 orphaned_umodes
&= ~prev_user_modes
[i
];
1376 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Orphaned umode +%c is picked up by module", i
);
1378 user_modes
[i
] = prev_user_modes
[i
];
1381 prev_user_modes
[i
] = user_modes
[i
];
1390 change_nick_user_host(struct Client
*target_p
, const char *nick
, const char *user
,
1391 const char *host
, int newts
, const char *format
, ...)
1394 struct Channel
*chptr
;
1395 struct membership
*mscptr
;
1396 int changed
= irccmp(target_p
->name
, nick
);
1397 int changed_case
= strcmp(target_p
->name
, nick
);
1398 int do_qjm
= irccmp(target_p
->username
, user
) || irccmp(target_p
->host
, host
);
1399 char mode
[10], modeval
[NICKLEN
* 2 + 2], reason
[256], *mptr
;
1406 target_p
->tsinfo
= newts
;
1407 monitor_signoff(target_p
);
1409 invalidate_bancache_user(target_p
);
1413 va_start(ap
, format
);
1414 vsnprintf(reason
, 255, format
, ap
);
1417 sendto_common_channels_local_butone(target_p
, ":%s!%s@%s QUIT :%s",
1418 target_p
->name
, target_p
->username
, target_p
->host
,
1421 RB_DLINK_FOREACH(ptr
, target_p
->user
->channel
.head
)
1424 chptr
= mscptr
->chptr
;
1427 if(is_chanop(mscptr
))
1430 strcat(modeval
, nick
);
1431 strcat(modeval
, " ");
1434 if(is_voiced(mscptr
))
1437 strcat(modeval
, nick
);
1442 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
1443 nick
, user
, host
, chptr
->chname
);
1445 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
,
1446 ":%s MODE %s +%s %s",
1447 target_p
->servptr
->name
,
1448 chptr
->chname
, mode
, modeval
);
1453 if(MyClient(target_p
) && changed_case
)
1454 sendto_one(target_p
, ":%s!%s@%s NICK %s",
1455 target_p
->name
, target_p
->username
, target_p
->host
, nick
);
1457 else if(changed_case
)
1459 sendto_common_channels_local(target_p
, ":%s!%s@%s NICK :%s",
1460 target_p
->name
, target_p
->username
,
1461 target_p
->host
, nick
);
1464 rb_strlcpy(target_p
->username
, user
, sizeof target_p
->username
);
1465 rb_strlcpy(target_p
->host
, host
, sizeof target_p
->host
);
1468 add_history(target_p
, 1);
1470 del_from_client_hash(target_p
->name
, target_p
);
1471 rb_strlcpy(target_p
->name
, nick
, NICKLEN
);
1472 add_to_client_hash(target_p
->name
, target_p
);
1476 monitor_signon(target_p
);
1477 del_all_accepts(target_p
);