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