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