1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* s_user.c: User related functions. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "tools.h" |
27 |
#include "s_user.h" |
28 |
#include "s_misc.h" |
29 |
#include "channel.h" |
30 |
#include "channel_mode.h" |
31 |
#include "client.h" |
32 |
#include "common.h" |
33 |
#include "fdlist.h" |
34 |
#include "hash.h" |
35 |
#include "irc_string.h" |
36 |
#include "sprintf_irc.h" |
37 |
#include "s_bsd.h" |
38 |
#include "ircd.h" |
39 |
#include "list.h" |
40 |
#include "listener.h" |
41 |
#include "motd.h" |
42 |
#include "numeric.h" |
43 |
#include "s_conf.h" |
44 |
#include "s_log.h" |
45 |
#include "s_serv.h" |
46 |
#include "send.h" |
47 |
#include "supported.h" |
48 |
#include "whowas.h" |
49 |
#include "memory.h" |
50 |
#include "packet.h" |
51 |
#include "rng_mt.h" |
52 |
#include "userhost.h" |
53 |
#include "hook.h" |
54 |
#include "s_misc.h" |
55 |
#include "msg.h" |
56 |
#include "pcre.h" |
57 |
#include "watch.h" |
58 |
|
59 |
int MaxClientCount = 1; |
60 |
int MaxConnectionCount = 1; |
61 |
struct Callback *entering_umode_cb = NULL; |
62 |
struct Callback *umode_cb = NULL; |
63 |
struct Callback *uid_get_cb = NULL; |
64 |
|
65 |
static char umode_buffer[IRCD_BUFSIZE]; |
66 |
|
67 |
static void user_welcome(struct Client *); |
68 |
static void report_and_set_user_flags(struct Client *, const struct AccessItem *); |
69 |
static int check_xline(struct Client *); |
70 |
static void introduce_client(struct Client *, struct Client *); |
71 |
static void *uid_get(va_list); |
72 |
|
73 |
/* Used for building up the isupport string, |
74 |
* used with init_isupport, add_isupport, delete_isupport |
75 |
*/ |
76 |
|
77 |
struct Isupport |
78 |
{ |
79 |
dlink_node node; |
80 |
char *name; |
81 |
char *options; |
82 |
int number; |
83 |
}; |
84 |
|
85 |
static dlink_list support_list = { NULL, NULL, 0 }; |
86 |
MessageFile *isupportFile; |
87 |
|
88 |
/* memory is cheap. map 0-255 to equivalent mode */ |
89 |
unsigned int user_modes[256] = |
90 |
{ |
91 |
/* 0x00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x0F */ |
92 |
/* 0x10 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x1F */ |
93 |
/* 0x20 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x2F */ |
94 |
/* 0x30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x3F */ |
95 |
0, /* @ */ |
96 |
0, /* A */ |
97 |
0, /* B */ |
98 |
UMODE_CCONN_FULL, /* C */ |
99 |
UMODE_DEAF, /* D */ |
100 |
0, /* E */ |
101 |
0, /* F */ |
102 |
UMODE_SOFTCALLERID, /* G */ |
103 |
0, /* H */ |
104 |
0, /* I */ |
105 |
0, /* J */ |
106 |
0, /* K */ |
107 |
0, /* L */ |
108 |
0, /* M */ |
109 |
0, /* N */ |
110 |
0, /* O */ |
111 |
0, /* P */ |
112 |
0, /* Q */ |
113 |
0, /* R */ |
114 |
0, /* S */ |
115 |
0, /* T */ |
116 |
0, /* U */ |
117 |
0, /* V */ |
118 |
0, /* W */ |
119 |
0, /* X */ |
120 |
0, /* Y */ |
121 |
0, /* Z 0x5A */ |
122 |
0, 0, 0, 0, 0, /* 0x5F */ |
123 |
0, /* 0x60 */ |
124 |
UMODE_ADMIN, /* a */ |
125 |
UMODE_BOTS, /* b */ |
126 |
UMODE_CCONN, /* c */ |
127 |
UMODE_DEBUG, /* d */ |
128 |
0, /* e */ |
129 |
UMODE_FULL, /* f */ |
130 |
UMODE_CALLERID, /* g */ |
131 |
0, /* h */ |
132 |
UMODE_INVISIBLE, /* i */ |
133 |
0, /* j */ |
134 |
UMODE_SKILL, /* k */ |
135 |
UMODE_LOCOPS, /* l */ |
136 |
0, /* m */ |
137 |
UMODE_NCHANGE, /* n */ |
138 |
UMODE_OPER, /* o */ |
139 |
0, /* p */ |
140 |
0, /* q */ |
141 |
UMODE_REJ, /* r */ |
142 |
UMODE_SERVNOTICE, /* s */ |
143 |
0, /* t */ |
144 |
UMODE_UNAUTH, /* u */ |
145 |
0, /* v */ |
146 |
UMODE_WALLOP, /* w */ |
147 |
UMODE_EXTERNAL, /* x */ |
148 |
UMODE_SPY, /* y */ |
149 |
UMODE_OPERWALL, /* z 0x7A */ |
150 |
0,0,0,0,0, /* 0x7B - 0x7F */ |
151 |
|
152 |
/* 0x80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x8F */ |
153 |
/* 0x90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x9F */ |
154 |
/* 0xA0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xAF */ |
155 |
/* 0xB0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xBF */ |
156 |
/* 0xC0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xCF */ |
157 |
/* 0xD0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xDF */ |
158 |
/* 0xE0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xEF */ |
159 |
/* 0xF0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* 0xFF */ |
160 |
}; |
161 |
|
162 |
void |
163 |
assemble_umode_buffer(void) |
164 |
{ |
165 |
unsigned int idx = 0; |
166 |
char *umode_buffer_ptr = umode_buffer; |
167 |
|
168 |
for (; idx < (sizeof(user_modes) / sizeof(int)); ++idx) |
169 |
if (user_modes[idx]) |
170 |
*umode_buffer_ptr++ = idx; |
171 |
|
172 |
*umode_buffer_ptr = '\0'; |
173 |
} |
174 |
|
175 |
/* show_lusers() |
176 |
* |
177 |
* inputs - pointer to client |
178 |
* output - NONE |
179 |
* side effects - display to client user counts etc. |
180 |
*/ |
181 |
void |
182 |
show_lusers(struct Client *source_p) |
183 |
{ |
184 |
const char *from, *to; |
185 |
|
186 |
if (!MyConnect(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p)) |
187 |
{ |
188 |
from = me.id; |
189 |
to = source_p->id; |
190 |
} |
191 |
else |
192 |
{ |
193 |
from = me.name; |
194 |
to = source_p->name; |
195 |
} |
196 |
|
197 |
if (!ConfigServerHide.hide_servers || IsOper(source_p)) |
198 |
sendto_one(source_p, form_str(RPL_LUSERCLIENT), |
199 |
from, to, (Count.total-Count.invisi), |
200 |
Count.invisi, dlink_list_length(&global_serv_list)); |
201 |
else |
202 |
sendto_one(source_p, form_str(RPL_LUSERCLIENT), from, to, |
203 |
(Count.total-Count.invisi), Count.invisi, 1); |
204 |
|
205 |
if (Count.oper > 0) |
206 |
sendto_one(source_p, form_str(RPL_LUSEROP), |
207 |
from, to, Count.oper); |
208 |
|
209 |
if (dlink_list_length(&unknown_list) > 0) |
210 |
sendto_one(source_p, form_str(RPL_LUSERUNKNOWN), |
211 |
from, to, dlink_list_length(&unknown_list)); |
212 |
|
213 |
if (dlink_list_length(&global_channel_list) > 0) |
214 |
sendto_one(source_p, form_str(RPL_LUSERCHANNELS), |
215 |
from, to, dlink_list_length(&global_channel_list)); |
216 |
|
217 |
if (!ConfigServerHide.hide_servers || IsOper(source_p)) |
218 |
{ |
219 |
sendto_one(source_p, form_str(RPL_LUSERME), |
220 |
from, to, Count.local, Count.myserver); |
221 |
sendto_one(source_p, form_str(RPL_LOCALUSERS), |
222 |
from, to, Count.local, Count.max_loc, |
223 |
Count.local, Count.max_loc); |
224 |
} |
225 |
else |
226 |
{ |
227 |
sendto_one(source_p, form_str(RPL_LUSERME), |
228 |
from, to, Count.total, 0); |
229 |
sendto_one(source_p, form_str(RPL_LOCALUSERS), |
230 |
from, to, Count.total, Count.max_tot, |
231 |
Count.total, Count.max_tot); |
232 |
} |
233 |
|
234 |
sendto_one(source_p, form_str(RPL_GLOBALUSERS), |
235 |
from, to, Count.total, Count.max_tot, |
236 |
Count.total, Count.max_tot); |
237 |
|
238 |
if (!ConfigServerHide.hide_servers || IsOper(source_p)) |
239 |
sendto_one(source_p, form_str(RPL_STATSCONN), from, to, |
240 |
MaxConnectionCount, MaxClientCount, Count.totalrestartcount); |
241 |
|
242 |
if (Count.local > MaxClientCount) |
243 |
MaxClientCount = Count.local; |
244 |
|
245 |
if ((Count.local + Count.myserver) > MaxConnectionCount) |
246 |
MaxConnectionCount = Count.local + Count.myserver; |
247 |
} |
248 |
|
249 |
/* show_isupport() |
250 |
* |
251 |
* inputs - pointer to client |
252 |
* output - NONE |
253 |
* side effects - display to client what we support (for them) |
254 |
*/ |
255 |
void |
256 |
show_isupport(struct Client *source_p) |
257 |
{ |
258 |
send_message_file(source_p, isupportFile); |
259 |
} |
260 |
|
261 |
/* |
262 |
** register_local_user |
263 |
** This function is called when both NICK and USER messages |
264 |
** have been accepted for the client, in whatever order. Only |
265 |
** after this, is the USER message propagated. |
266 |
** |
267 |
** NICK's must be propagated at once when received, although |
268 |
** it would be better to delay them too until full info is |
269 |
** available. Doing it is not so simple though, would have |
270 |
** to implement the following: |
271 |
** |
272 |
** (actually it has been implemented already for a while) -orabidoo |
273 |
** |
274 |
** 1) user telnets in and gives only "NICK foobar" and waits |
275 |
** 2) another user far away logs in normally with the nick |
276 |
** "foobar" (quite legal, as this server didn't propagate |
277 |
** it). |
278 |
** 3) now this server gets nick "foobar" from outside, but |
279 |
** has alread the same defined locally. Current server |
280 |
** would just issue "KILL foobar" to clean out dups. But, |
281 |
** this is not fair. It should actually request another |
282 |
** nick from local user or kill him/her... |
283 |
*/ |
284 |
void |
285 |
register_local_user(struct Client *client_p, struct Client *source_p, |
286 |
const char *nick, const char *username) |
287 |
{ |
288 |
const struct AccessItem *aconf = NULL; |
289 |
dlink_node *ptr = NULL; |
290 |
dlink_node *m = NULL; |
291 |
|
292 |
assert(source_p != NULL); |
293 |
assert(MyConnect(source_p)); |
294 |
assert(source_p->username != username); |
295 |
assert(!source_p->localClient->registration); |
296 |
|
297 |
ClearCap(client_p, CAP_TS6); |
298 |
|
299 |
if (ConfigFileEntry.ping_cookie) |
300 |
{ |
301 |
if (!IsPingSent(source_p) && |
302 |
source_p->localClient->random_ping == 0) |
303 |
{ |
304 |
do |
305 |
source_p->localClient->random_ping = genrand_int32(); |
306 |
while (!source_p->localClient->random_ping); |
307 |
|
308 |
sendto_one(source_p, "PING :%u", |
309 |
source_p->localClient->random_ping); |
310 |
SetPingSent(source_p); |
311 |
return; |
312 |
} |
313 |
|
314 |
if (!HasPingCookie(source_p)) |
315 |
return; |
316 |
} |
317 |
|
318 |
source_p->localClient->last = CurrentTime; |
319 |
/* Straight up the maximum rate of flooding... */ |
320 |
source_p->localClient->allow_read = MAX_FLOOD_BURST; |
321 |
|
322 |
if (!execute_callback(client_check_cb, source_p, username)) |
323 |
return; |
324 |
|
325 |
if (valid_hostname(source_p->host) == 0) |
326 |
{ |
327 |
sendto_one(source_p, ":%s NOTICE %s :*** Notice -- You have an illegal " |
328 |
"character in your hostname", me.name, source_p->name); |
329 |
strlcpy(source_p->host, source_p->sockhost, |
330 |
sizeof(source_p->host)); |
331 |
} |
332 |
|
333 |
ptr = source_p->localClient->confs.head; |
334 |
aconf = map_to_conf(ptr->data); |
335 |
|
336 |
if (!IsGotId(source_p)) |
337 |
{ |
338 |
const char *p = NULL; |
339 |
unsigned int i = 0; |
340 |
|
341 |
if (IsNeedIdentd(aconf)) |
342 |
{ |
343 |
++ServerStats.is_ref; |
344 |
sendto_one(source_p, ":%s NOTICE %s :*** Notice -- You need to install " |
345 |
"identd to use this server", me.name, source_p->name); |
346 |
exit_client(source_p, &me, "Install identd"); |
347 |
return; |
348 |
} |
349 |
|
350 |
p = username; |
351 |
|
352 |
if (!IsNoTilde(aconf)) |
353 |
source_p->username[i++] = '~'; |
354 |
|
355 |
while (*p && i < USERLEN) |
356 |
{ |
357 |
if (*p != '[') |
358 |
source_p->username[i++] = *p; |
359 |
p++; |
360 |
} |
361 |
|
362 |
source_p->username[i] = '\0'; |
363 |
} |
364 |
|
365 |
/* password check */ |
366 |
if (!EmptyString(aconf->passwd)) |
367 |
{ |
368 |
const char *pass = source_p->localClient->passwd; |
369 |
|
370 |
if (!match_conf_password(pass, aconf)) |
371 |
{ |
372 |
++ServerStats.is_ref; |
373 |
sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), |
374 |
me.name, source_p->name); |
375 |
exit_client(source_p, &me, "Bad Password"); |
376 |
return; |
377 |
} |
378 |
} |
379 |
|
380 |
/* don't free source_p->localClient->passwd here - it can be required |
381 |
* by masked /stats I if there are auth{} blocks with need_password = no; |
382 |
* --adx |
383 |
*/ |
384 |
|
385 |
/* report if user has &^>= etc. and set flags as needed in source_p */ |
386 |
report_and_set_user_flags(source_p, aconf); |
387 |
|
388 |
if (IsDead(client_p)) |
389 |
return; |
390 |
|
391 |
/* Limit clients - |
392 |
* We want to be able to have servers and F-line clients |
393 |
* connect, so save room for "buffer" connections. |
394 |
* Smaller servers may want to decrease this, and it should |
395 |
* probably be just a percentage of the MAXCLIENTS... |
396 |
* -Taner |
397 |
*/ |
398 |
/* Except "F:" clients */ |
399 |
if ((Count.local >= ServerInfo.max_clients + MAX_BUFFER) || |
400 |
(Count.local >= ServerInfo.max_clients && !IsExemptLimits(source_p))) |
401 |
{ |
402 |
sendto_realops_flags(UMODE_FULL, L_ALL, |
403 |
"Too many clients, rejecting %s[%s].", |
404 |
nick, source_p->host); |
405 |
++ServerStats.is_ref; |
406 |
exit_client(source_p, &me, "Sorry, server is full - try later"); |
407 |
return; |
408 |
} |
409 |
|
410 |
/* valid user name check */ |
411 |
if (valid_username(source_p->username) == 0) |
412 |
{ |
413 |
char tmpstr2[IRCD_BUFSIZE]; |
414 |
|
415 |
sendto_realops_flags(UMODE_REJ, L_ALL, "Invalid username: %s (%s@%s)", |
416 |
nick, source_p->username, source_p->host); |
417 |
++ServerStats.is_ref; |
418 |
ircsprintf(tmpstr2, "Invalid username [%s]", source_p->username); |
419 |
exit_client(source_p, &me, tmpstr2); |
420 |
return; |
421 |
} |
422 |
|
423 |
assert(source_p == client_p); |
424 |
|
425 |
if (check_xline(source_p)) |
426 |
return; |
427 |
|
428 |
if (me.id[0]) |
429 |
{ |
430 |
const char *id = execute_callback(uid_get_cb, source_p); |
431 |
|
432 |
while (hash_find_id(id) != NULL) |
433 |
id = uid_get(NULL); |
434 |
|
435 |
strlcpy(source_p->id, id, sizeof(source_p->id)); |
436 |
hash_add_id(source_p); |
437 |
} |
438 |
|
439 |
sendto_realops_flags(UMODE_CCONN, L_ALL, |
440 |
"Client connecting: %s (%s@%s) [%s] {%s} [%s]", |
441 |
nick, source_p->username, source_p->host, |
442 |
ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ? |
443 |
"255.255.255.255" : source_p->sockhost, |
444 |
get_client_class(source_p), |
445 |
source_p->info); |
446 |
|
447 |
sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, |
448 |
"CLICONN %s %s %s %s %s %s %s 0 %s", |
449 |
nick, source_p->username, source_p->host, |
450 |
ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ? |
451 |
"255.255.255.255" : source_p->sockhost, |
452 |
get_client_class(source_p), |
453 |
ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ? |
454 |
"<hidden>" : source_p->client_host, |
455 |
ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ? |
456 |
"<hidden>" : source_p->client_server, |
457 |
source_p->info); |
458 |
|
459 |
|
460 |
if (ConfigFileEntry.invisible_on_connect) |
461 |
{ |
462 |
source_p->umodes |= UMODE_INVISIBLE; |
463 |
++Count.invisi; |
464 |
} |
465 |
|
466 |
if ((++Count.local) > Count.max_loc) |
467 |
{ |
468 |
Count.max_loc = Count.local; |
469 |
|
470 |
if (!(Count.max_loc % 10)) |
471 |
sendto_realops_flags(UMODE_ALL, L_ALL, "New Max Local Clients: %d", |
472 |
Count.max_loc); |
473 |
} |
474 |
|
475 |
SetClient(source_p); |
476 |
|
477 |
source_p->servptr = &me; |
478 |
dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list); |
479 |
|
480 |
/* Increment our total user count here */ |
481 |
if (++Count.total > Count.max_tot) |
482 |
Count.max_tot = Count.total; |
483 |
++Count.totalrestartcount; |
484 |
|
485 |
source_p->localClient->allow_read = MAX_FLOOD_BURST; |
486 |
|
487 |
if ((m = dlinkFindDelete(&unknown_list, source_p)) != NULL) |
488 |
{ |
489 |
free_dlink_node(m); |
490 |
dlinkAdd(source_p, &source_p->localClient->lclient_node, &local_client_list); |
491 |
} |
492 |
else assert(0); |
493 |
|
494 |
user_welcome(source_p); |
495 |
add_user_host(source_p->username, source_p->host, 0); |
496 |
SetUserHost(source_p); |
497 |
|
498 |
introduce_client(client_p, source_p); |
499 |
} |
500 |
|
501 |
/* register_remote_user() |
502 |
* |
503 |
* inputs - client_p directly connected client |
504 |
* - source_p remote or directly connected client |
505 |
* - username to register as |
506 |
* - host name to register as |
507 |
* - server name |
508 |
* - realname (gecos) |
509 |
* output - NONE |
510 |
* side effects - This function is called when a remote client |
511 |
* is introduced by a server. |
512 |
*/ |
513 |
void |
514 |
register_remote_user(struct Client *client_p, struct Client *source_p, |
515 |
const char *username, const char *host, const char *server, |
516 |
const char *realname) |
517 |
{ |
518 |
struct Client *target_p = NULL; |
519 |
|
520 |
assert(source_p != NULL); |
521 |
assert(source_p->username != username); |
522 |
|
523 |
strlcpy(source_p->host, host, sizeof(source_p->host)); |
524 |
strlcpy(source_p->username, username, sizeof(source_p->username)); |
525 |
|
526 |
/* |
527 |
* coming from another server, take the servers word for it |
528 |
*/ |
529 |
source_p->servptr = find_server(server); |
530 |
|
531 |
/* Super GhostDetect: |
532 |
* If we can't find the server the user is supposed to be on, |
533 |
* then simply blow the user away. -Taner |
534 |
*/ |
535 |
if (source_p->servptr == NULL) |
536 |
{ |
537 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
538 |
"No server %s for user %s[%s@%s] from %s", |
539 |
server, source_p->name, source_p->username, |
540 |
source_p->host, source_p->from->name); |
541 |
kill_client(client_p, source_p, "%s (Server doesn't exist)", me.name); |
542 |
|
543 |
SetKilled(source_p); |
544 |
exit_client(source_p, &me, "Ghosted Client"); |
545 |
return; |
546 |
} |
547 |
|
548 |
if ((target_p = source_p->servptr) && target_p->from != source_p->from) |
549 |
{ |
550 |
sendto_realops_flags(UMODE_DEBUG, L_ALL, |
551 |
"Bad User [%s] :%s USER %s@%s %s, != %s[%s]", |
552 |
client_p->name, source_p->name, source_p->username, |
553 |
source_p->host, source_p->servptr->name, |
554 |
target_p->name, target_p->from->name); |
555 |
kill_client(client_p, source_p, |
556 |
"%s (NICK from wrong direction (%s != %s))", |
557 |
me.name, source_p->servptr->name, target_p->from->name); |
558 |
SetKilled(source_p); |
559 |
exit_client(source_p, &me, "USER server wrong direction"); |
560 |
return; |
561 |
} |
562 |
|
563 |
/* Increment our total user count here */ |
564 |
if (++Count.total > Count.max_tot) |
565 |
Count.max_tot = Count.total; |
566 |
|
567 |
SetClient(source_p); |
568 |
dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list); |
569 |
add_user_host(source_p->username, source_p->host, 1); |
570 |
SetUserHost(source_p); |
571 |
|
572 |
introduce_client(client_p, source_p); |
573 |
} |
574 |
|
575 |
/* introduce_client() |
576 |
* |
577 |
* inputs - client_p |
578 |
* - source_p |
579 |
* output - NONE |
580 |
* side effects - This common function introduces a client to the rest |
581 |
* of the net, either from a local client connect or |
582 |
* from a remote connect. |
583 |
*/ |
584 |
static void |
585 |
introduce_client(struct Client *client_p, struct Client *source_p) |
586 |
{ |
587 |
dlink_node *server_node = NULL; |
588 |
static char ubuf[12]; |
589 |
|
590 |
if (MyClient(source_p)) |
591 |
send_umode(source_p, source_p, 0, SEND_UMODES, ubuf); |
592 |
else |
593 |
send_umode(NULL, source_p, 0, SEND_UMODES, ubuf); |
594 |
|
595 |
watch_check_hash(source_p, RPL_LOGON); |
596 |
|
597 |
if (*ubuf == '\0') |
598 |
{ |
599 |
ubuf[0] = '+'; |
600 |
ubuf[1] = '\0'; |
601 |
} |
602 |
|
603 |
DLINK_FOREACH(server_node, serv_list.head) |
604 |
{ |
605 |
struct Client *server = server_node->data; |
606 |
|
607 |
if (server == client_p) |
608 |
continue; |
609 |
|
610 |
if (IsCapable(server, CAP_TS6) && HasID(source_p)) |
611 |
sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s", |
612 |
source_p->servptr->id, |
613 |
source_p->name, source_p->hopcount+1, |
614 |
(unsigned long)source_p->tsinfo, |
615 |
ubuf, source_p->username, source_p->host, |
616 |
(MyClient(source_p) && IsIPSpoof(source_p)) ? |
617 |
"0" : source_p->sockhost, source_p->id, source_p->info); |
618 |
else |
619 |
sendto_one(server, "NICK %s %d %lu %s %s %s %s :%s", |
620 |
source_p->name, source_p->hopcount+1, |
621 |
(unsigned long)source_p->tsinfo, |
622 |
ubuf, source_p->username, source_p->host, |
623 |
source_p->servptr->name, source_p->info); |
624 |
} |
625 |
} |
626 |
|
627 |
/* valid_hostname() |
628 |
* |
629 |
* Inputs - pointer to hostname |
630 |
* Output - 1 if valid, 0 if not |
631 |
* Side effects - check hostname for validity |
632 |
* |
633 |
* NOTE: this doesn't allow a hostname to begin with a dot and |
634 |
* will not allow more dots than chars. |
635 |
*/ |
636 |
int |
637 |
valid_hostname(const char *hostname) |
638 |
{ |
639 |
const char *p = hostname; |
640 |
|
641 |
assert(p != NULL); |
642 |
|
643 |
if ('.' == *p || ':' == *p) |
644 |
return 0; |
645 |
|
646 |
while (*p) |
647 |
{ |
648 |
if (!IsHostChar(*p)) |
649 |
return 0; |
650 |
p++; |
651 |
} |
652 |
|
653 |
return 1; |
654 |
} |
655 |
|
656 |
/* valid_username() |
657 |
* |
658 |
* Inputs - pointer to user |
659 |
* Output - 1 if valid, 0 if not |
660 |
* Side effects - check username for validity |
661 |
* |
662 |
* Absolutely always reject any '*' '!' '?' '@' in an user name |
663 |
* reject any odd control characters names. |
664 |
* Allow '.' in username to allow for "first.last" |
665 |
* style of username |
666 |
*/ |
667 |
int |
668 |
valid_username(const char *username) |
669 |
{ |
670 |
int dots = 0; |
671 |
const char *p = username; |
672 |
|
673 |
assert(p != NULL); |
674 |
|
675 |
if ('~' == *p) |
676 |
++p; |
677 |
|
678 |
/* reject usernames that don't start with an alphanum |
679 |
* i.e. reject jokers who have '-@somehost' or '.@somehost' |
680 |
* or "-hi-@somehost", "h-----@somehost" would still be accepted. |
681 |
*/ |
682 |
if (!IsAlNum(*p)) |
683 |
return 0; |
684 |
|
685 |
while (*++p) |
686 |
{ |
687 |
if ((*p == '.') && ConfigFileEntry.dots_in_ident) |
688 |
{ |
689 |
dots++; |
690 |
|
691 |
if (dots > ConfigFileEntry.dots_in_ident) |
692 |
return 0; |
693 |
if (!IsUserChar(p[1])) |
694 |
return 0; |
695 |
} |
696 |
else if (!IsUserChar(*p)) |
697 |
return 0; |
698 |
} |
699 |
|
700 |
return 1; |
701 |
} |
702 |
|
703 |
/* report_and_set_user_flags() |
704 |
* |
705 |
* inputs - pointer to source_p |
706 |
* - pointer to aconf for this user |
707 |
* output - NONE |
708 |
* side effects - Report to user any special flags |
709 |
* they are getting, and set them. |
710 |
*/ |
711 |
static void |
712 |
report_and_set_user_flags(struct Client *source_p, const struct AccessItem *aconf) |
713 |
{ |
714 |
/* If this user is being spoofed, tell them so */ |
715 |
if (IsConfDoSpoofIp(aconf)) |
716 |
{ |
717 |
sendto_one(source_p, |
718 |
":%s NOTICE %s :*** Spoofing your IP. congrats.", |
719 |
me.name, source_p->name); |
720 |
} |
721 |
|
722 |
/* If this user is in the exception class, Set it "E lined" */ |
723 |
if (IsConfExemptKline(aconf)) |
724 |
{ |
725 |
SetExemptKline(source_p); |
726 |
sendto_one(source_p, |
727 |
":%s NOTICE %s :*** You are exempt from K/D/G lines. congrats.", |
728 |
me.name, source_p->name); |
729 |
} |
730 |
|
731 |
/* The else here is to make sure that G line exempt users |
732 |
* do not get noticed twice. |
733 |
*/ |
734 |
else if (IsConfExemptGline(aconf)) |
735 |
{ |
736 |
SetExemptGline(source_p); |
737 |
sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from G lines.", |
738 |
me.name, source_p->name); |
739 |
} |
740 |
|
741 |
if (IsConfExemptResv(aconf)) |
742 |
{ |
743 |
SetExemptResv(source_p); |
744 |
sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from resvs.", |
745 |
me.name, source_p->name); |
746 |
} |
747 |
|
748 |
/* If this user is exempt from user limits set it "F lined" */ |
749 |
if (IsConfExemptLimits(aconf)) |
750 |
{ |
751 |
SetExemptLimits(source_p); |
752 |
sendto_one(source_p, |
753 |
":%s NOTICE %s :*** You are exempt from user limits. congrats.", |
754 |
me.name,source_p->name); |
755 |
} |
756 |
|
757 |
/* If this user is exempt from idle time outs */ |
758 |
if (IsConfIdlelined(aconf)) |
759 |
{ |
760 |
SetIdlelined(source_p); |
761 |
sendto_one(source_p, |
762 |
":%s NOTICE %s :*** You are exempt from idle limits. congrats.", |
763 |
me.name, source_p->name); |
764 |
} |
765 |
|
766 |
if (IsConfCanFlood(aconf)) |
767 |
{ |
768 |
SetCanFlood(source_p); |
769 |
sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from flood " |
770 |
"protection, aren't you fearsome.", |
771 |
me.name, source_p->name); |
772 |
} |
773 |
} |
774 |
|
775 |
/* do_local_user() |
776 |
* |
777 |
* inputs - |
778 |
* output - NONE |
779 |
* side effects - |
780 |
*/ |
781 |
void |
782 |
do_local_user(const char *nick, struct Client *client_p, struct Client *source_p, |
783 |
const char *username, const char *host, const char *server, |
784 |
const char *realname) |
785 |
{ |
786 |
assert(source_p != NULL); |
787 |
assert(source_p->username != username); |
788 |
|
789 |
if (source_p == NULL) |
790 |
return; |
791 |
|
792 |
if (!IsUnknown(source_p)) |
793 |
{ |
794 |
sendto_one(source_p, form_str(ERR_ALREADYREGISTRED), |
795 |
me.name, nick); |
796 |
return; |
797 |
} |
798 |
|
799 |
source_p->localClient->registration &= ~REG_NEED_USER; |
800 |
|
801 |
/* |
802 |
* don't take the clients word for it, ever |
803 |
*/ |
804 |
source_p->servptr = &me; |
805 |
|
806 |
strlcpy(source_p->info, realname, sizeof(source_p->info)); |
807 |
|
808 |
/* stash for later */ |
809 |
strlcpy(source_p->client_host, host, sizeof(source_p->client_host)); |
810 |
strlcpy(source_p->client_server, server, sizeof(source_p->client_server)); |
811 |
|
812 |
if (!IsGotId(source_p)) |
813 |
{ |
814 |
/* save the username in the client |
815 |
* If you move this you'll break ping cookies..you've been warned |
816 |
*/ |
817 |
strlcpy(source_p->username, username, sizeof(source_p->username)); |
818 |
} |
819 |
|
820 |
if (!source_p->localClient->registration) |
821 |
/* NICK already received, now I have USER... */ |
822 |
register_local_user(client_p, source_p, source_p->name, username); |
823 |
} |
824 |
|
825 |
/* change_simple_umode() |
826 |
* |
827 |
* this callback can be hooked to allow special handling of |
828 |
* certain usermodes |
829 |
*/ |
830 |
static void * |
831 |
change_simple_umode(va_list args) |
832 |
{ |
833 |
struct Client *client_p; |
834 |
struct Client *source_p; |
835 |
int what; |
836 |
unsigned int flag; |
837 |
|
838 |
client_p = va_arg(args, struct Client *); |
839 |
source_p = va_arg(args, struct Client *); |
840 |
what = va_arg(args, int); |
841 |
flag = va_arg(args, unsigned int); |
842 |
|
843 |
if (what == MODE_ADD) |
844 |
source_p->umodes |= flag; |
845 |
else |
846 |
source_p->umodes &= ~flag; |
847 |
|
848 |
return NULL; |
849 |
} |
850 |
|
851 |
/* set_user_mode() |
852 |
* |
853 |
* added 15/10/91 By Darren Reed. |
854 |
* parv[0] - sender |
855 |
* parv[1] - username to change mode for |
856 |
* parv[2] - modes to change |
857 |
*/ |
858 |
void |
859 |
set_user_mode(struct Client *client_p, struct Client *source_p, |
860 |
int parc, char *parv[]) |
861 |
{ |
862 |
unsigned int flag, setflags; |
863 |
char **p, *m, buf[IRCD_BUFSIZE]; |
864 |
struct Client *target_p; |
865 |
int what = MODE_ADD, badflag = 0, i; |
866 |
|
867 |
assert(!(parc < 2)); |
868 |
|
869 |
if ((target_p = find_person(client_p, parv[1])) == NULL) |
870 |
{ |
871 |
if (MyConnect(source_p)) |
872 |
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
873 |
me.name, source_p->name, parv[1]); |
874 |
return; |
875 |
} |
876 |
|
877 |
if (IsServer(source_p)) |
878 |
{ |
879 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, "*** Mode for User %s from %s", |
880 |
parv[1], source_p->name); |
881 |
return; |
882 |
} |
883 |
|
884 |
if (source_p != target_p || target_p->from != source_p->from) |
885 |
{ |
886 |
sendto_one(source_p, form_str(ERR_USERSDONTMATCH), |
887 |
me.name, source_p->name); |
888 |
return; |
889 |
} |
890 |
|
891 |
if (parc < 3) |
892 |
{ |
893 |
m = buf; |
894 |
*m++ = '+'; |
895 |
|
896 |
for (i = 0; i < 128; i++) |
897 |
if (source_p->umodes & user_modes[i]) |
898 |
*m++ = (char)i; |
899 |
*m = '\0'; |
900 |
|
901 |
sendto_one(source_p, form_str(RPL_UMODEIS), |
902 |
me.name, source_p->name, buf); |
903 |
return; |
904 |
} |
905 |
|
906 |
execute_callback(entering_umode_cb, client_p, source_p); |
907 |
|
908 |
/* find flags already set for user */ |
909 |
setflags = source_p->umodes; |
910 |
|
911 |
/* parse mode change string(s) */ |
912 |
for (p = &parv[2]; p && *p; p++) |
913 |
{ |
914 |
for (m = *p; *m; m++) |
915 |
{ |
916 |
switch (*m) |
917 |
{ |
918 |
case '+': |
919 |
what = MODE_ADD; |
920 |
break; |
921 |
case '-': |
922 |
what = MODE_DEL; |
923 |
break; |
924 |
case 'o': |
925 |
if (what == MODE_ADD) |
926 |
{ |
927 |
if (IsServer(client_p) && !IsOper(source_p)) |
928 |
{ |
929 |
++Count.oper; |
930 |
SetOper(source_p); |
931 |
} |
932 |
} |
933 |
else |
934 |
{ |
935 |
/* Only decrement the oper counts if an oper to begin with |
936 |
* found by Pat Szuta, Perly , perly@xnet.com |
937 |
*/ |
938 |
if (!IsOper(source_p)) |
939 |
break; |
940 |
|
941 |
ClearOper(source_p); |
942 |
source_p->umodes &= ~ConfigFileEntry.oper_only_umodes; |
943 |
Count.oper--; |
944 |
|
945 |
if (MyConnect(source_p)) |
946 |
{ |
947 |
dlink_node *dm; |
948 |
|
949 |
detach_conf(source_p, OPER_TYPE); |
950 |
ClearOperFlags(source_p); |
951 |
|
952 |
if ((dm = dlinkFindDelete(&oper_list, source_p)) != NULL) |
953 |
free_dlink_node(dm); |
954 |
} |
955 |
} |
956 |
|
957 |
break; |
958 |
|
959 |
/* we may not get these, |
960 |
* but they shouldnt be in default |
961 |
*/ |
962 |
case ' ' : |
963 |
case '\n': |
964 |
case '\r': |
965 |
case '\t': |
966 |
break; |
967 |
|
968 |
default: |
969 |
if ((flag = user_modes[(unsigned char)*m])) |
970 |
{ |
971 |
if (MyConnect(source_p) && !IsOper(source_p) && |
972 |
(ConfigFileEntry.oper_only_umodes & flag)) |
973 |
{ |
974 |
badflag = 1; |
975 |
} |
976 |
else |
977 |
execute_callback(umode_cb, client_p, source_p, what, flag); |
978 |
} |
979 |
else |
980 |
{ |
981 |
if (MyConnect(source_p)) |
982 |
badflag = 1; |
983 |
} |
984 |
|
985 |
break; |
986 |
} |
987 |
} |
988 |
} |
989 |
|
990 |
if (badflag) |
991 |
sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG), |
992 |
me.name, source_p->name); |
993 |
|
994 |
if ((source_p->umodes & UMODE_NCHANGE) && !IsOperN(source_p)) |
995 |
{ |
996 |
sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;", |
997 |
me.name, source_p->name); |
998 |
source_p->umodes &= ~UMODE_NCHANGE; /* only tcm's really need this */ |
999 |
} |
1000 |
|
1001 |
if (MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) && |
1002 |
!IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p)) |
1003 |
{ |
1004 |
sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;", |
1005 |
me.name, source_p->name); |
1006 |
source_p->umodes &= ~UMODE_ADMIN; |
1007 |
} |
1008 |
|
1009 |
if (!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p)) |
1010 |
++Count.invisi; |
1011 |
if ((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p)) |
1012 |
--Count.invisi; |
1013 |
|
1014 |
/* |
1015 |
* compare new flags with old flags and send string which |
1016 |
* will cause servers to update correctly. |
1017 |
*/ |
1018 |
send_umode_out(client_p, source_p, setflags); |
1019 |
} |
1020 |
|
1021 |
/* send_umode() |
1022 |
* send the MODE string for user (user) to connection client_p |
1023 |
* -avalon |
1024 |
* |
1025 |
* inputs - client_p |
1026 |
* - source_p |
1027 |
* - int old |
1028 |
* - sendmask mask of modes to send |
1029 |
* - suplied umode_buf |
1030 |
* output - NONE |
1031 |
*/ |
1032 |
void |
1033 |
send_umode(struct Client *client_p, struct Client *source_p, |
1034 |
unsigned int old, unsigned int sendmask, char *umode_buf) |
1035 |
{ |
1036 |
int what = 0; |
1037 |
unsigned int i; |
1038 |
unsigned int flag; |
1039 |
char *m = umode_buf; |
1040 |
|
1041 |
/* |
1042 |
* build a string in umode_buf to represent the change in the user's |
1043 |
* mode between the new (source_p->umodes) and 'old'. |
1044 |
*/ |
1045 |
for (i = 0; i < 128; i++) |
1046 |
{ |
1047 |
flag = user_modes[i]; |
1048 |
if (!flag) |
1049 |
continue; |
1050 |
|
1051 |
if (MyClient(source_p) && !(flag & sendmask)) |
1052 |
continue; |
1053 |
|
1054 |
if ((flag & old) && !(source_p->umodes & flag)) |
1055 |
{ |
1056 |
if (what == MODE_DEL) |
1057 |
*m++ = (char)i; |
1058 |
else |
1059 |
{ |
1060 |
what = MODE_DEL; |
1061 |
*m++ = '-'; |
1062 |
*m++ = (char)i; |
1063 |
} |
1064 |
} |
1065 |
else if (!(flag & old) && (source_p->umodes & flag)) |
1066 |
{ |
1067 |
if (what == MODE_ADD) |
1068 |
*m++ = (char)i; |
1069 |
else |
1070 |
{ |
1071 |
what = MODE_ADD; |
1072 |
*m++ = '+'; |
1073 |
*m++ = (char)i; |
1074 |
} |
1075 |
} |
1076 |
} |
1077 |
|
1078 |
*m = '\0'; |
1079 |
|
1080 |
if (*umode_buf && client_p) |
1081 |
sendto_one(client_p, ":%s!%s@%s MODE %s :%s", |
1082 |
source_p->name, source_p->username, |
1083 |
source_p->host, source_p->name, umode_buf); |
1084 |
} |
1085 |
|
1086 |
/* send_umode_out() |
1087 |
* |
1088 |
* inputs - |
1089 |
* output - NONE |
1090 |
* side effects - Only send ubuf out to servers that know about this client |
1091 |
*/ |
1092 |
void |
1093 |
send_umode_out(struct Client *client_p, struct Client *source_p, |
1094 |
unsigned int old) |
1095 |
{ |
1096 |
char buf[IRCD_BUFSIZE] = { '\0' }; |
1097 |
dlink_node *ptr = NULL; |
1098 |
|
1099 |
send_umode(NULL, source_p, old, IsOperHiddenAdmin(source_p) ? |
1100 |
SEND_UMODES & ~UMODE_ADMIN : SEND_UMODES, buf); |
1101 |
|
1102 |
if (buf[0]) |
1103 |
{ |
1104 |
DLINK_FOREACH(ptr, serv_list.head) |
1105 |
{ |
1106 |
struct Client *target_p = ptr->data; |
1107 |
|
1108 |
if ((target_p != client_p) && (target_p != source_p)) |
1109 |
sendto_one(target_p, ":%s MODE %s :%s", |
1110 |
ID_or_name(source_p, target_p), |
1111 |
ID_or_name(source_p, target_p), buf); |
1112 |
} |
1113 |
} |
1114 |
|
1115 |
if (client_p && MyClient(client_p)) |
1116 |
send_umode(client_p, source_p, old, 0xffffffff, buf); |
1117 |
} |
1118 |
|
1119 |
/* user_welcome() |
1120 |
* |
1121 |
* inputs - client pointer to client to welcome |
1122 |
* output - NONE |
1123 |
* side effects - |
1124 |
*/ |
1125 |
static void |
1126 |
user_welcome(struct Client *source_p) |
1127 |
{ |
1128 |
#if defined(__TIME__) && defined(__DATE__) |
1129 |
static const char built_date[] = __DATE__ " at " __TIME__; |
1130 |
#else |
1131 |
static const char built_date[] = "unknown"; |
1132 |
#endif |
1133 |
|
1134 |
#ifdef HAVE_LIBCRYPTO |
1135 |
if (source_p->localClient->fd.ssl != NULL) |
1136 |
sendto_one(source_p, ":%s NOTICE %s :*** Connected securely via %s", |
1137 |
me.name, source_p->name, |
1138 |
ssl_get_cipher(source_p->localClient->fd.ssl)); |
1139 |
#endif |
1140 |
|
1141 |
sendto_one(source_p, form_str(RPL_WELCOME), me.name, source_p->name, |
1142 |
ServerInfo.network_name, source_p->name); |
1143 |
sendto_one(source_p, form_str(RPL_YOURHOST), me.name, source_p->name, |
1144 |
get_listener_name(source_p->localClient->listener), ircd_version); |
1145 |
sendto_one(source_p, form_str(RPL_CREATED), |
1146 |
me.name, source_p->name, built_date); |
1147 |
sendto_one(source_p, form_str(RPL_MYINFO), |
1148 |
me.name, source_p->name, me.name, ircd_version, umode_buffer); |
1149 |
show_isupport(source_p); |
1150 |
|
1151 |
if (source_p->id[0] != '\0') |
1152 |
sendto_one(source_p, form_str(RPL_YOURID), me.name, |
1153 |
source_p->name, source_p->id); |
1154 |
|
1155 |
show_lusers(source_p); |
1156 |
|
1157 |
if (ConfigFileEntry.short_motd) |
1158 |
{ |
1159 |
sendto_one(source_p, "NOTICE %s :*** Notice -- motd was last changed at %s", |
1160 |
source_p->name, ConfigFileEntry.motd.lastChangedDate); |
1161 |
sendto_one(source_p, |
1162 |
"NOTICE %s :*** Notice -- Please read the motd if you haven't " |
1163 |
"read it", source_p->name); |
1164 |
sendto_one(source_p, form_str(RPL_MOTDSTART), |
1165 |
me.name, source_p->name, me.name); |
1166 |
sendto_one(source_p, form_str(RPL_MOTD), |
1167 |
me.name, source_p->name, |
1168 |
"*** This is the short motd ***"); |
1169 |
sendto_one(source_p, form_str(RPL_ENDOFMOTD), |
1170 |
me.name, source_p->name); |
1171 |
} |
1172 |
else |
1173 |
send_message_file(source_p, &ConfigFileEntry.motd); |
1174 |
} |
1175 |
|
1176 |
/* check_xline() |
1177 |
* |
1178 |
* inputs - pointer to client to test |
1179 |
* outupt - 1 if exiting 0 if ok |
1180 |
* side effects - |
1181 |
*/ |
1182 |
static int |
1183 |
check_xline(struct Client *source_p) |
1184 |
{ |
1185 |
struct ConfItem *conf = NULL; |
1186 |
const char *reason = NULL; |
1187 |
|
1188 |
if ((conf = find_matching_name_conf(XLINE_TYPE, source_p->info, NULL, NULL, 0)) || |
1189 |
(conf = find_matching_name_conf(RXLINE_TYPE, source_p->info, NULL, NULL, 0))) |
1190 |
{ |
1191 |
struct MatchItem *reg = map_to_conf(conf); |
1192 |
|
1193 |
++reg->count; |
1194 |
|
1195 |
if (reg->reason != NULL) |
1196 |
reason = reg->reason; |
1197 |
else |
1198 |
reason = "No Reason"; |
1199 |
|
1200 |
sendto_realops_flags(UMODE_REJ, L_ALL, |
1201 |
"X-line Rejecting [%s] [%s], user %s [%s]", |
1202 |
source_p->info, reason, |
1203 |
get_client_name(source_p, HIDE_IP), |
1204 |
source_p->sockhost); |
1205 |
|
1206 |
++ServerStats.is_ref; |
1207 |
if (REJECT_HOLD_TIME > 0) |
1208 |
{ |
1209 |
sendto_one(source_p, ":%s NOTICE %s :Bad user info", |
1210 |
me.name, source_p->name); |
1211 |
source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME; |
1212 |
SetCaptured(source_p); |
1213 |
} |
1214 |
else |
1215 |
exit_client(source_p, &me, "Bad user info"); |
1216 |
return 1; |
1217 |
} |
1218 |
|
1219 |
return 0; |
1220 |
} |
1221 |
|
1222 |
/* oper_up() |
1223 |
* |
1224 |
* inputs - pointer to given client to oper |
1225 |
* output - NONE |
1226 |
* side effects - Blindly opers up given source_p, using aconf info |
1227 |
* all checks on passwords have already been done. |
1228 |
* This could also be used by rsa oper routines. |
1229 |
*/ |
1230 |
void |
1231 |
oper_up(struct Client *source_p) |
1232 |
{ |
1233 |
unsigned int old = source_p->umodes; |
1234 |
const char *operprivs = ""; |
1235 |
const struct AccessItem *oconf = NULL; |
1236 |
|
1237 |
assert(source_p->localClient->confs.head); |
1238 |
oconf = map_to_conf((source_p->localClient->confs.head)->data); |
1239 |
|
1240 |
++Count.oper; |
1241 |
SetOper(source_p); |
1242 |
|
1243 |
if (oconf->modes) |
1244 |
source_p->umodes |= oconf->modes; |
1245 |
else if (ConfigFileEntry.oper_umodes) |
1246 |
source_p->umodes |= ConfigFileEntry.oper_umodes; |
1247 |
else |
1248 |
source_p->umodes |= (UMODE_SERVNOTICE|UMODE_OPERWALL| |
1249 |
UMODE_WALLOP|UMODE_LOCOPS); |
1250 |
|
1251 |
if (!(old & UMODE_INVISIBLE) && IsInvisible(source_p)) |
1252 |
++Count.invisi; |
1253 |
if ((old & UMODE_INVISIBLE) && !IsInvisible(source_p)) |
1254 |
--Count.invisi; |
1255 |
|
1256 |
assert(dlinkFind(&oper_list, source_p) == NULL); |
1257 |
dlinkAdd(source_p, make_dlink_node(), &oper_list); |
1258 |
|
1259 |
operprivs = oper_privs_as_string(oconf->port); |
1260 |
|
1261 |
SetOFlag(source_p, oconf->port); |
1262 |
|
1263 |
if (IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p)) |
1264 |
source_p->umodes |= UMODE_ADMIN; |
1265 |
if (!IsOperN(source_p)) |
1266 |
source_p->umodes &= ~UMODE_NCHANGE; |
1267 |
|
1268 |
sendto_realops_flags(UMODE_ALL, L_ALL, "%s (%s@%s) is now an operator", |
1269 |
source_p->name, source_p->username, source_p->host); |
1270 |
send_umode_out(source_p, source_p, old); |
1271 |
sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); |
1272 |
sendto_one(source_p, ":%s NOTICE %s :*** Oper privs are %s", |
1273 |
me.name, source_p->name, operprivs); |
1274 |
send_message_file(source_p, &ConfigFileEntry.opermotd); |
1275 |
} |
1276 |
|
1277 |
static char new_uid[TOTALSIDUID + 1]; /* allow for \0 */ |
1278 |
|
1279 |
int |
1280 |
valid_sid(const char *sid) |
1281 |
{ |
1282 |
|
1283 |
if (strlen(sid) == IRC_MAXSID) |
1284 |
if (IsDigit(*sid)) |
1285 |
if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2))) |
1286 |
return 1; |
1287 |
|
1288 |
return 0; |
1289 |
} |
1290 |
|
1291 |
/* |
1292 |
* init_uid() |
1293 |
* |
1294 |
* inputs - NONE |
1295 |
* output - NONE |
1296 |
* side effects - new_uid is filled in with server id portion (sid) |
1297 |
* (first 3 bytes) or defaulted to 'A'. |
1298 |
* Rest is filled in with 'A' |
1299 |
*/ |
1300 |
void |
1301 |
init_uid(void) |
1302 |
{ |
1303 |
int i; |
1304 |
|
1305 |
memset(new_uid, 0, sizeof(new_uid)); |
1306 |
|
1307 |
if (ServerInfo.sid != NULL) |
1308 |
{ |
1309 |
strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid)); |
1310 |
strlcpy(me.id, ServerInfo.sid, sizeof(me.id)); |
1311 |
|
1312 |
hash_add_id(&me); |
1313 |
} |
1314 |
|
1315 |
for (i = 0; i < IRC_MAXSID; i++) |
1316 |
if (new_uid[i] == '\0') |
1317 |
new_uid[i] = 'A'; |
1318 |
|
1319 |
/* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */ |
1320 |
/* Yes nenolod, I have known it was off by one ever since I wrote it |
1321 |
* But *JUST* for you, though, it really doesn't look as *pretty* |
1322 |
* -Dianora |
1323 |
*/ |
1324 |
memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID); |
1325 |
|
1326 |
entering_umode_cb = register_callback("entering_umode", NULL); |
1327 |
umode_cb = register_callback("changing_umode", change_simple_umode); |
1328 |
uid_get_cb = register_callback("uid_get", uid_get); |
1329 |
} |
1330 |
|
1331 |
/* |
1332 |
* add_one_to_uid |
1333 |
* |
1334 |
* inputs - index number into new_uid |
1335 |
* output - NONE |
1336 |
* side effects - new_uid is incremented by one |
1337 |
* note this is a recursive function |
1338 |
*/ |
1339 |
static void |
1340 |
add_one_to_uid(int i) |
1341 |
{ |
1342 |
if (i != IRC_MAXSID) /* Not reached server SID portion yet? */ |
1343 |
{ |
1344 |
if (new_uid[i] == 'Z') |
1345 |
new_uid[i] = '0'; |
1346 |
else if (new_uid[i] == '9') |
1347 |
{ |
1348 |
new_uid[i] = 'A'; |
1349 |
add_one_to_uid(i-1); |
1350 |
} |
1351 |
else |
1352 |
++new_uid[i]; |
1353 |
} |
1354 |
else |
1355 |
{ |
1356 |
/* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */ |
1357 |
if (new_uid[i] == 'Z') |
1358 |
memcpy(new_uid + IRC_MAXSID, "AAAAAA", IRC_MAXUID); |
1359 |
else |
1360 |
++new_uid[i]; |
1361 |
} |
1362 |
} |
1363 |
|
1364 |
/* |
1365 |
* uid_get |
1366 |
* |
1367 |
* inputs - struct Client * |
1368 |
* output - new UID is returned to caller |
1369 |
* side effects - new_uid is incremented by one. |
1370 |
*/ |
1371 |
static void * |
1372 |
uid_get(va_list args) |
1373 |
{ |
1374 |
add_one_to_uid(TOTALSIDUID - 1); /* index from 0 */ |
1375 |
return new_uid; |
1376 |
} |
1377 |
|
1378 |
/* |
1379 |
* init_isupport() |
1380 |
* |
1381 |
* input - NONE |
1382 |
* output - NONE |
1383 |
* side effects - Must be called before isupport is enabled |
1384 |
*/ |
1385 |
void |
1386 |
init_isupport(void) |
1387 |
{ |
1388 |
isupportFile = init_MessageLine(); |
1389 |
|
1390 |
add_isupport("CALLERID", NULL, -1); |
1391 |
add_isupport("CASEMAPPING", CASEMAP, -1); |
1392 |
add_isupport("DEAF", "D", -1); |
1393 |
add_isupport("KICKLEN", NULL, KICKLEN); |
1394 |
add_isupport("MODES", NULL, MAXMODEPARAMS); |
1395 |
add_isupport("NICKLEN", NULL, NICKLEN-1); |
1396 |
#ifdef HALFOPS |
1397 |
add_isupport("PREFIX", "(ohv)@%+", -1); |
1398 |
add_isupport("STATUSMSG", "@%+", -1); |
1399 |
#else |
1400 |
add_isupport("PREFIX", "(ov)@+", -1); |
1401 |
add_isupport("STATUSMSG", "@+", -1); |
1402 |
#endif |
1403 |
add_isupport("TOPICLEN", NULL, TOPICLEN); |
1404 |
} |
1405 |
|
1406 |
/* |
1407 |
* add_isupport() |
1408 |
* |
1409 |
* input - name of supported function |
1410 |
* - options if any |
1411 |
* - number if any |
1412 |
* output - NONE |
1413 |
* side effects - Each supported item must call this when activated |
1414 |
*/ |
1415 |
void |
1416 |
add_isupport(const char *name, const char *options, int n) |
1417 |
{ |
1418 |
dlink_node *ptr; |
1419 |
struct Isupport *support; |
1420 |
|
1421 |
DLINK_FOREACH(ptr, support_list.head) |
1422 |
{ |
1423 |
support = ptr->data; |
1424 |
if (irccmp(support->name, name) == 0) |
1425 |
{ |
1426 |
MyFree(support->name); |
1427 |
MyFree(support->options); |
1428 |
break; |
1429 |
} |
1430 |
} |
1431 |
|
1432 |
if (ptr == NULL) |
1433 |
{ |
1434 |
support = MyMalloc(sizeof(*support)); |
1435 |
dlinkAddTail(support, &support->node, &support_list); |
1436 |
} |
1437 |
|
1438 |
DupString(support->name, name); |
1439 |
if (options != NULL) |
1440 |
DupString(support->options, options); |
1441 |
support->number = n; |
1442 |
|
1443 |
rebuild_isupport_message_line(); |
1444 |
} |
1445 |
|
1446 |
/* |
1447 |
* delete_isupport() |
1448 |
* |
1449 |
* input - name of supported function |
1450 |
* output - NONE |
1451 |
* side effects - Each supported item must call this when deactivated |
1452 |
*/ |
1453 |
void |
1454 |
delete_isupport(const char *name) |
1455 |
{ |
1456 |
dlink_node *ptr; |
1457 |
struct Isupport *support; |
1458 |
|
1459 |
DLINK_FOREACH(ptr, support_list.head) |
1460 |
{ |
1461 |
support = ptr->data; |
1462 |
if (irccmp(support->name, name) == 0) |
1463 |
{ |
1464 |
dlinkDelete(ptr, &support_list); |
1465 |
MyFree(support->name); |
1466 |
MyFree(support->options); |
1467 |
MyFree(support); |
1468 |
break; |
1469 |
} |
1470 |
} |
1471 |
|
1472 |
rebuild_isupport_message_line(); |
1473 |
} |
1474 |
|
1475 |
/* |
1476 |
* rebuild_isupport_message_line |
1477 |
* |
1478 |
* input - NONE |
1479 |
* output - NONE |
1480 |
* side effects - Destroy the isupport MessageFile lines, and rebuild. |
1481 |
*/ |
1482 |
void |
1483 |
rebuild_isupport_message_line(void) |
1484 |
{ |
1485 |
char isupportbuffer[IRCD_BUFSIZE]; |
1486 |
char *p = isupportbuffer; |
1487 |
dlink_node *ptr = NULL; |
1488 |
int n = 0; |
1489 |
int tokens = 0; |
1490 |
size_t len = 0; |
1491 |
size_t reserve = strlen(me.name) + HOSTLEN + strlen(form_str(RPL_ISUPPORT)); |
1492 |
|
1493 |
destroy_MessageLine(isupportFile); |
1494 |
|
1495 |
DLINK_FOREACH(ptr, support_list.head) |
1496 |
{ |
1497 |
struct Isupport *support = ptr->data; |
1498 |
|
1499 |
p += (n = ircsprintf(p, "%s", support->name)); |
1500 |
len += n; |
1501 |
|
1502 |
if (support->options != NULL) |
1503 |
{ |
1504 |
p += (n = ircsprintf(p, "=%s", support->options)); |
1505 |
len += n; |
1506 |
} |
1507 |
|
1508 |
if (support->number > 0) |
1509 |
{ |
1510 |
p += (n = ircsprintf(p, "=%d", support->number)); |
1511 |
len += n; |
1512 |
} |
1513 |
|
1514 |
*p++ = ' '; |
1515 |
len++; |
1516 |
*p = '\0'; |
1517 |
|
1518 |
if (++tokens == (MAXPARA-2) || len >= (sizeof(isupportbuffer)-reserve)) |
1519 |
{ /* arbritrary for now */ |
1520 |
if (*--p == ' ') |
1521 |
*p = '\0'; |
1522 |
|
1523 |
addto_MessageLine(isupportFile, isupportbuffer); |
1524 |
p = isupportbuffer; |
1525 |
len = 0; |
1526 |
n = tokens = 0; |
1527 |
} |
1528 |
} |
1529 |
|
1530 |
if (len != 0) |
1531 |
{ |
1532 |
if (*--p == ' ') |
1533 |
*p = '\0'; |
1534 |
addto_MessageLine(isupportFile, isupportbuffer); |
1535 |
} |
1536 |
} |