1 |
adx |
30 |
/* |
2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
9101 |
* Copyright (c) 1997-2020 ircd-hybrid development team |
5 |
adx |
30 |
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
adx |
30 |
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
5563 |
/*! \file user.c |
23 |
michael |
2916 |
* \brief User related functions. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
michael |
1011 |
#include "list.h" |
29 |
michael |
3347 |
#include "user.h" |
30 |
adx |
30 |
#include "channel.h" |
31 |
|
|
#include "channel_mode.h" |
32 |
|
|
#include "client.h" |
33 |
|
|
#include "hash.h" |
34 |
michael |
6161 |
#include "id.h" |
35 |
adx |
30 |
#include "irc_string.h" |
36 |
|
|
#include "ircd.h" |
37 |
|
|
#include "listener.h" |
38 |
|
|
#include "motd.h" |
39 |
|
|
#include "numeric.h" |
40 |
michael |
1309 |
#include "conf.h" |
41 |
michael |
7304 |
#include "conf_gecos.h" |
42 |
michael |
1309 |
#include "log.h" |
43 |
michael |
3347 |
#include "server.h" |
44 |
adx |
30 |
#include "send.h" |
45 |
|
|
#include "memory.h" |
46 |
|
|
#include "packet.h" |
47 |
michael |
982 |
#include "rng_mt.h" |
48 |
michael |
3347 |
#include "misc.h" |
49 |
michael |
1243 |
#include "parse.h" |
50 |
michael |
9750 |
#include "monitor.h" |
51 |
michael |
6185 |
#include "isupport.h" |
52 |
michael |
7105 |
#include "tls.h" |
53 |
michael |
8729 |
#include "patchlevel.h" |
54 |
michael |
9684 |
#include "server_capab.h" /* TBR: RHOST compatibility mode */ |
55 |
adx |
30 |
|
56 |
michael |
8063 |
static char umode_buffer[UMODE_MAX_STR]; |
57 |
adx |
30 |
|
58 |
michael |
5392 |
const struct user_modes *umode_map[256]; |
59 |
|
|
const struct user_modes umode_tab[] = |
60 |
adx |
30 |
{ |
61 |
michael |
9775 |
{ 'B', UMODE_BOT }, |
62 |
michael |
5392 |
{ 'D', UMODE_DEAF }, |
63 |
|
|
{ 'F', UMODE_FARCONNECT }, |
64 |
|
|
{ 'G', UMODE_SOFTCALLERID }, |
65 |
|
|
{ 'H', UMODE_HIDDEN }, |
66 |
michael |
8963 |
{ 'X', UMODE_EXPIRATION }, |
67 |
michael |
5392 |
{ 'R', UMODE_REGONLY }, |
68 |
michael |
9157 |
{ 'S', UMODE_SECURE }, |
69 |
michael |
5392 |
{ 'W', UMODE_WEBIRC }, |
70 |
|
|
{ 'a', UMODE_ADMIN }, |
71 |
|
|
{ 'c', UMODE_CCONN }, |
72 |
|
|
{ 'd', UMODE_DEBUG }, |
73 |
|
|
{ 'e', UMODE_EXTERNAL }, |
74 |
michael |
9638 |
{ 'f', UMODE_FLOOD }, |
75 |
michael |
5392 |
{ 'g', UMODE_CALLERID }, |
76 |
|
|
{ 'i', UMODE_INVISIBLE }, |
77 |
|
|
{ 'j', UMODE_REJ }, |
78 |
|
|
{ 'k', UMODE_SKILL }, |
79 |
|
|
{ 'l', UMODE_LOCOPS }, |
80 |
|
|
{ 'n', UMODE_NCHANGE }, |
81 |
|
|
{ 'o', UMODE_OPER }, |
82 |
|
|
{ 'p', UMODE_HIDECHANS }, |
83 |
|
|
{ 'q', UMODE_HIDEIDLE }, |
84 |
|
|
{ 'r', UMODE_REGISTERED }, |
85 |
|
|
{ 's', UMODE_SERVNOTICE }, |
86 |
|
|
{ 'w', UMODE_WALLOP }, |
87 |
|
|
{ 'y', UMODE_SPY }, |
88 |
|
|
{ '\0', 0 } |
89 |
adx |
30 |
}; |
90 |
|
|
|
91 |
|
|
void |
92 |
michael |
6189 |
user_modes_init(void) |
93 |
adx |
30 |
{ |
94 |
|
|
char *umode_buffer_ptr = umode_buffer; |
95 |
|
|
|
96 |
michael |
5392 |
for (const struct user_modes *tab = umode_tab; tab->c; ++tab) |
97 |
|
|
{ |
98 |
|
|
umode_map[tab->c] = tab; |
99 |
|
|
*umode_buffer_ptr++ = tab->c; |
100 |
|
|
} |
101 |
adx |
30 |
|
102 |
|
|
*umode_buffer_ptr = '\0'; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
/* show_lusers() |
106 |
|
|
* |
107 |
|
|
* inputs - pointer to client |
108 |
|
|
* output - NONE |
109 |
|
|
* side effects - display to client user counts etc. |
110 |
|
|
*/ |
111 |
|
|
void |
112 |
michael |
9250 |
show_lusers(struct Client *client) |
113 |
adx |
30 |
{ |
114 |
michael |
9250 |
if (ConfigServerHide.hide_servers == 0 || HasUMode(client, UMODE_OPER)) |
115 |
|
|
sendto_one_numeric(client, &me, RPL_LUSERCLIENT, (dlink_list_length(&global_client_list) - Count.invisi), |
116 |
michael |
4209 |
Count.invisi, dlink_list_length(&global_server_list)); |
117 |
adx |
30 |
else |
118 |
michael |
9250 |
sendto_one_numeric(client, &me, RPL_LUSERCLIENT, (dlink_list_length(&global_client_list) - Count.invisi), |
119 |
michael |
4724 |
Count.invisi, 1); |
120 |
adx |
30 |
|
121 |
michael |
3375 |
if (Count.oper) |
122 |
michael |
9250 |
sendto_one_numeric(client, &me, RPL_LUSEROP, Count.oper); |
123 |
adx |
30 |
|
124 |
michael |
3375 |
if (dlink_list_length(&unknown_list)) |
125 |
michael |
9250 |
sendto_one_numeric(client, &me, RPL_LUSERUNKNOWN, dlink_list_length(&unknown_list)); |
126 |
adx |
30 |
|
127 |
michael |
8439 |
if (dlink_list_length(channel_get_list())) |
128 |
michael |
9250 |
sendto_one_numeric(client, &me, RPL_LUSERCHANNELS, dlink_list_length(channel_get_list())); |
129 |
adx |
30 |
|
130 |
michael |
9250 |
if (ConfigServerHide.hide_servers == 0 || HasUMode(client, UMODE_OPER)) |
131 |
adx |
30 |
{ |
132 |
michael |
9250 |
sendto_one_numeric(client, &me, RPL_LUSERME, dlink_list_length(&local_client_list), dlink_list_length(&local_server_list)); |
133 |
|
|
sendto_one_numeric(client, &me, RPL_LOCALUSERS, dlink_list_length(&local_client_list), Count.max_loc); |
134 |
|
|
sendto_one_numeric(client, &me, RPL_GLOBALUSERS, dlink_list_length(&global_client_list), Count.max_tot); |
135 |
|
|
sendto_one_numeric(client, &me, RPL_STATSCONN, Count.max_loc_con, Count.max_loc, Count.totalrestartcount); |
136 |
adx |
30 |
} |
137 |
|
|
else |
138 |
|
|
{ |
139 |
michael |
9250 |
sendto_one_numeric(client, &me, RPL_LUSERME, dlink_list_length(&global_client_list), 0); |
140 |
|
|
sendto_one_numeric(client, &me, RPL_LOCALUSERS, dlink_list_length(&global_client_list), Count.max_tot); |
141 |
|
|
sendto_one_numeric(client, &me, RPL_GLOBALUSERS, dlink_list_length(&global_client_list), Count.max_tot); |
142 |
adx |
30 |
} |
143 |
|
|
} |
144 |
|
|
|
145 |
michael |
3272 |
/* report_and_set_user_flags() |
146 |
|
|
* |
147 |
michael |
9250 |
* inputs - pointer to client |
148 |
michael |
3272 |
* - pointer to conf for this user |
149 |
|
|
* output - NONE |
150 |
|
|
* side effects - Report to user any special flags |
151 |
|
|
* they are getting, and set them. |
152 |
|
|
*/ |
153 |
|
|
static void |
154 |
michael |
9250 |
report_and_set_user_flags(struct Client *client, const struct MaskItem *conf) |
155 |
michael |
3272 |
{ |
156 |
|
|
/* If this user is being spoofed, tell them so */ |
157 |
|
|
if (IsConfDoSpoofIp(conf)) |
158 |
michael |
9250 |
sendto_one_notice(client, &me, ":*** Spoofing your IP"); |
159 |
michael |
3272 |
|
160 |
michael |
4856 |
/* If this user is in the exception class, set it "E lined" */ |
161 |
michael |
3272 |
if (IsConfExemptKline(conf)) |
162 |
|
|
{ |
163 |
michael |
9250 |
AddFlag(client, FLAGS_EXEMPTKLINE); |
164 |
|
|
sendto_one_notice(client, &me, ":*** You are exempt from K/D lines"); |
165 |
michael |
3272 |
} |
166 |
|
|
|
167 |
michael |
5985 |
if (IsConfExemptXline(conf)) |
168 |
|
|
{ |
169 |
michael |
9250 |
AddFlag(client, FLAGS_EXEMPTXLINE); |
170 |
|
|
sendto_one_notice(client, &me, ":*** You are exempt from X lines"); |
171 |
michael |
5985 |
} |
172 |
|
|
|
173 |
michael |
3272 |
if (IsConfExemptResv(conf)) |
174 |
|
|
{ |
175 |
michael |
9250 |
AddFlag(client, FLAGS_EXEMPTRESV); |
176 |
|
|
sendto_one_notice(client, &me, ":*** You are exempt from resvs"); |
177 |
michael |
3272 |
} |
178 |
|
|
|
179 |
|
|
/* If this user is exempt from user limits set it "F lined" */ |
180 |
|
|
if (IsConfExemptLimits(conf)) |
181 |
|
|
{ |
182 |
michael |
9250 |
AddFlag(client, FLAGS_NOLIMIT); |
183 |
|
|
sendto_one_notice(client, &me, ":*** You are exempt from user limits"); |
184 |
michael |
3272 |
} |
185 |
|
|
|
186 |
|
|
if (IsConfCanFlood(conf)) |
187 |
|
|
{ |
188 |
michael |
9250 |
AddFlag(client, FLAGS_CANFLOOD); |
189 |
|
|
sendto_one_notice(client, &me, ":*** You are exempt from flood protection"); |
190 |
michael |
3272 |
} |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
/* introduce_client() |
194 |
|
|
* |
195 |
michael |
9250 |
* inputs - client |
196 |
michael |
3272 |
* output - NONE |
197 |
|
|
* side effects - This common function introduces a client to the rest |
198 |
|
|
* of the net, either from a local client connect or |
199 |
|
|
* from a remote connect. |
200 |
|
|
*/ |
201 |
|
|
static void |
202 |
michael |
9250 |
introduce_client(struct Client *client) |
203 |
michael |
3272 |
{ |
204 |
michael |
8059 |
dlink_node *node; |
205 |
michael |
8063 |
char buf[UMODE_MAX_STR] = ""; |
206 |
michael |
3272 |
|
207 |
michael |
9250 |
send_umode(client, MyConnect(client), 0, buf); |
208 |
michael |
9750 |
monitor_signon(client); |
209 |
michael |
3272 |
|
210 |
michael |
8063 |
if (buf[0] == '\0') |
211 |
michael |
3272 |
{ |
212 |
michael |
8063 |
buf[0] = '+'; |
213 |
|
|
buf[1] = '\0'; |
214 |
michael |
3272 |
} |
215 |
|
|
|
216 |
michael |
4815 |
DLINK_FOREACH(node, local_server_list.head) |
217 |
michael |
3272 |
{ |
218 |
michael |
9264 |
struct Client *server = node->data; |
219 |
michael |
3272 |
|
220 |
michael |
9264 |
if (server == client->from) |
221 |
michael |
3272 |
continue; |
222 |
|
|
|
223 |
michael |
9684 |
/* TBR: compatibility mode */ |
224 |
|
|
if (IsCapable(server, CAPAB_RHOST)) |
225 |
|
|
sendto_one(server, ":%s UID %s %u %ju %s %s %s %s %s %s %s :%s", |
226 |
|
|
client->servptr->id, |
227 |
|
|
client->name, client->hopcount+1, |
228 |
|
|
client->tsinfo, |
229 |
|
|
buf, client->username, client->host, client->realhost, |
230 |
|
|
client->sockhost, client->id, |
231 |
|
|
client->account, |
232 |
|
|
client->info); |
233 |
|
|
else |
234 |
|
|
sendto_one(server, ":%s UID %s %u %ju %s %s %s %s %s %s :%s", |
235 |
|
|
client->servptr->id, |
236 |
|
|
client->name, client->hopcount+1, |
237 |
|
|
client->tsinfo, |
238 |
|
|
buf, client->username, client->host, |
239 |
|
|
client->sockhost, client->id, |
240 |
|
|
client->account, |
241 |
|
|
client->info); |
242 |
michael |
3272 |
|
243 |
michael |
9408 |
if (!EmptyString(client->tls_certfp)) |
244 |
|
|
sendto_one(server, ":%s CERTFP %s", client->id, client->tls_certfp); |
245 |
michael |
3272 |
} |
246 |
|
|
} |
247 |
|
|
|
248 |
|
|
/* user_welcome() |
249 |
|
|
* |
250 |
|
|
* inputs - client pointer to client to welcome |
251 |
|
|
* output - NONE |
252 |
|
|
* side effects - |
253 |
|
|
*/ |
254 |
|
|
static void |
255 |
michael |
9250 |
user_welcome(struct Client *client) |
256 |
michael |
3272 |
{ |
257 |
|
|
static const char built_date[] = __DATE__ " at " __TIME__; |
258 |
|
|
|
259 |
michael |
9250 |
if (HasFlag(client, FLAGS_TLS)) |
260 |
michael |
3272 |
{ |
261 |
michael |
9250 |
AddUMode(client, UMODE_SECURE); |
262 |
michael |
9411 |
|
263 |
|
|
client->tls_cipher = xstrdup(tls_get_cipher(&client->connection->fd->tls)); |
264 |
michael |
9250 |
sendto_one_notice(client, &me, ":*** Connected securely via %s", |
265 |
michael |
9411 |
client->tls_cipher); |
266 |
michael |
3272 |
} |
267 |
|
|
|
268 |
michael |
9250 |
sendto_one_numeric(client, &me, RPL_WELCOME, ConfigServerInfo.network_name, |
269 |
|
|
client->name, client->username, client->realhost); |
270 |
|
|
sendto_one_numeric(client, &me, RPL_YOURHOST, |
271 |
|
|
listener_get_name(client->connection->listener), PATCHLEVEL); |
272 |
|
|
sendto_one_numeric(client, &me, RPL_CREATED, built_date); |
273 |
|
|
sendto_one_numeric(client, &me, RPL_MYINFO, me.name, PATCHLEVEL, umode_buffer); |
274 |
michael |
6252 |
|
275 |
michael |
9250 |
isupport_show(client); |
276 |
|
|
show_lusers(client); |
277 |
|
|
motd_signon(client); |
278 |
michael |
3272 |
} |
279 |
|
|
|
280 |
michael |
3317 |
/*! \brief This function is called when both NICK and USER messages |
281 |
michael |
3316 |
* have been accepted for the client, in whatever order. Only |
282 |
|
|
* after this, is the UID message propagated. |
283 |
michael |
9250 |
* \param client Pointer to given client to introduce |
284 |
michael |
3316 |
*/ |
285 |
adx |
30 |
void |
286 |
michael |
9250 |
register_local_user(struct Client *client) |
287 |
adx |
30 |
{ |
288 |
michael |
1632 |
const struct MaskItem *conf = NULL; |
289 |
adx |
30 |
|
290 |
michael |
9250 |
assert(client == client->from); |
291 |
|
|
assert(client->connection->registration == 0); |
292 |
|
|
assert(MyConnect(client)); |
293 |
|
|
assert(IsUnknown(client)); |
294 |
adx |
30 |
|
295 |
michael |
4340 |
if (ConfigGeneral.ping_cookie) |
296 |
adx |
30 |
{ |
297 |
michael |
9250 |
if (!HasFlag(client, FLAGS_PINGSENT) && client->connection->random_ping == 0) |
298 |
adx |
30 |
{ |
299 |
michael |
983 |
do |
300 |
michael |
9250 |
client->connection->random_ping = genrand_int32(); |
301 |
|
|
while (client->connection->random_ping == 0); |
302 |
michael |
983 |
|
303 |
michael |
9250 |
sendto_one(client, "PING :%u", client->connection->random_ping); |
304 |
|
|
AddFlag(client, FLAGS_PINGSENT); |
305 |
adx |
30 |
return; |
306 |
|
|
} |
307 |
|
|
|
308 |
michael |
9250 |
if (!HasFlag(client, FLAGS_PING_COOKIE)) |
309 |
adx |
30 |
return; |
310 |
|
|
} |
311 |
|
|
|
312 |
michael |
9250 |
if (conf_check_client(client) == false) |
313 |
adx |
30 |
return; |
314 |
|
|
|
315 |
michael |
9250 |
conf = client->connection->confs.head->data; |
316 |
adx |
30 |
|
317 |
michael |
9250 |
if (!HasFlag(client, FLAGS_GOTID)) |
318 |
adx |
30 |
{ |
319 |
michael |
9431 |
char username[USERLEN + 1]; |
320 |
adx |
30 |
unsigned int i = 0; |
321 |
|
|
|
322 |
michael |
1632 |
if (IsNeedIdentd(conf)) |
323 |
adx |
30 |
{ |
324 |
michael |
896 |
++ServerStats.is_ref; |
325 |
michael |
9250 |
sendto_one_notice(client, &me, ":*** Notice -- You need to install " |
326 |
michael |
3110 |
"identd to use this server"); |
327 |
michael |
9250 |
exit_client(client, "Install identd"); |
328 |
adx |
30 |
return; |
329 |
|
|
} |
330 |
|
|
|
331 |
michael |
9250 |
strlcpy(username, client->username, sizeof(username)); |
332 |
adx |
30 |
|
333 |
michael |
1632 |
if (!IsNoTilde(conf)) |
334 |
michael |
9250 |
client->username[i++] = '~'; |
335 |
adx |
30 |
|
336 |
michael |
6357 |
for (const char *p = username; *p && i < USERLEN; ++p) |
337 |
michael |
9250 |
client->username[i++] = *p; |
338 |
adx |
30 |
|
339 |
michael |
9250 |
client->username[i] = '\0'; |
340 |
adx |
30 |
} |
341 |
|
|
|
342 |
michael |
3317 |
/* Password check */ |
343 |
michael |
1632 |
if (!EmptyString(conf->passwd)) |
344 |
adx |
30 |
{ |
345 |
michael |
9250 |
if (match_conf_password(client->connection->password, conf) == false) |
346 |
adx |
30 |
{ |
347 |
michael |
896 |
++ServerStats.is_ref; |
348 |
michael |
3109 |
|
349 |
michael |
9250 |
sendto_one_numeric(client, &me, ERR_PASSWDMISMATCH); |
350 |
|
|
exit_client(client, "Bad Password"); |
351 |
adx |
30 |
return; |
352 |
|
|
} |
353 |
|
|
} |
354 |
|
|
|
355 |
michael |
9319 |
xfree(client->connection->password); |
356 |
|
|
client->connection->password = NULL; |
357 |
adx |
30 |
|
358 |
michael |
3317 |
/* |
359 |
michael |
9250 |
* Report if user has &^>= etc. and set flags as needed in client |
360 |
michael |
3317 |
*/ |
361 |
michael |
9250 |
report_and_set_user_flags(client, conf); |
362 |
adx |
30 |
|
363 |
michael |
9250 |
if (IsDead(client)) |
364 |
michael |
980 |
return; |
365 |
|
|
|
366 |
michael |
3317 |
/* |
367 |
|
|
* Limit clients - |
368 |
adx |
30 |
* We want to be able to have servers and F-line clients |
369 |
|
|
* connect, so save room for "buffer" connections. |
370 |
|
|
* Smaller servers may want to decrease this, and it should |
371 |
|
|
* probably be just a percentage of the MAXCLIENTS... |
372 |
|
|
* -Taner |
373 |
|
|
*/ |
374 |
michael |
7969 |
if ((dlink_list_length(&local_client_list) >= GlobalSetOptions.maxclients + MAX_BUFFER) || |
375 |
michael |
9250 |
(dlink_list_length(&local_client_list) >= GlobalSetOptions.maxclients && !HasFlag(client, FLAGS_NOLIMIT))) |
376 |
adx |
30 |
{ |
377 |
michael |
9637 |
sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, |
378 |
adx |
30 |
"Too many clients, rejecting %s[%s].", |
379 |
michael |
9250 |
client->name, client->host); |
380 |
michael |
896 |
++ServerStats.is_ref; |
381 |
michael |
9250 |
exit_client(client, "Sorry, server is full - try later"); |
382 |
adx |
30 |
return; |
383 |
|
|
} |
384 |
|
|
|
385 |
michael |
9250 |
if (valid_username(client->username, true) == false) |
386 |
adx |
30 |
{ |
387 |
michael |
9764 |
char buf[sizeof("Invalid username []") + sizeof(client->username)]; |
388 |
adx |
30 |
|
389 |
michael |
1618 |
sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, |
390 |
|
|
"Invalid username: %s (%s@%s)", |
391 |
michael |
9250 |
client->name, client->username, client->host); |
392 |
michael |
896 |
++ServerStats.is_ref; |
393 |
michael |
9250 |
snprintf(buf, sizeof(buf), "Invalid username [%s]", client->username); |
394 |
|
|
exit_client(client, buf); |
395 |
adx |
30 |
return; |
396 |
|
|
} |
397 |
|
|
|
398 |
michael |
9250 |
if (!HasFlag(client, FLAGS_EXEMPTXLINE)) |
399 |
michael |
9106 |
{ |
400 |
michael |
9250 |
const struct GecosItem *gecos = gecos_find(client->info, match); |
401 |
michael |
9106 |
if (gecos) |
402 |
|
|
{ |
403 |
|
|
sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE, |
404 |
|
|
"X-line Rejecting [%s] [%s], user %s [%s]", |
405 |
michael |
9250 |
client->info, gecos->reason, |
406 |
|
|
client_get_name(client, HIDE_IP), |
407 |
|
|
client->sockhost); |
408 |
michael |
9106 |
++ServerStats.is_ref; |
409 |
michael |
9250 |
exit_client(client, "Bad user info"); |
410 |
michael |
9106 |
return; |
411 |
|
|
} |
412 |
|
|
} |
413 |
adx |
30 |
|
414 |
michael |
7570 |
const char *id; |
415 |
michael |
3215 |
while (hash_find_id((id = uid_get()))) |
416 |
michael |
1115 |
; |
417 |
michael |
573 |
|
418 |
michael |
9250 |
strlcpy(client->id, id, sizeof(client->id)); |
419 |
|
|
hash_add_id(client); |
420 |
adx |
30 |
|
421 |
michael |
1618 |
sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE, |
422 |
michael |
1137 |
"Client connecting: %s (%s@%s) [%s] {%s} [%s] <%s>", |
423 |
michael |
9250 |
client->name, client->username, client->realhost, |
424 |
|
|
client->sockhost, |
425 |
|
|
get_client_class(&client->connection->confs), |
426 |
|
|
client->info, client->id); |
427 |
adx |
30 |
|
428 |
michael |
4340 |
if (ConfigGeneral.invisible_on_connect) |
429 |
michael |
159 |
{ |
430 |
michael |
9250 |
AddUMode(client, UMODE_INVISIBLE); |
431 |
michael |
980 |
++Count.invisi; |
432 |
michael |
159 |
} |
433 |
adx |
30 |
|
434 |
michael |
9250 |
SetClient(client); |
435 |
michael |
9361 |
|
436 |
|
|
client->servptr = &me; |
437 |
michael |
9250 |
client->connection->last_privmsg = event_base->time.sec_monotonic; |
438 |
michael |
8710 |
|
439 |
michael |
9250 |
dlinkAdd(client, &client->lnode, &client->servptr->serv->client_list); |
440 |
|
|
dlinkAdd(client, &client->node, &global_client_list); |
441 |
michael |
1080 |
|
442 |
michael |
9250 |
assert(dlinkFind(&unknown_list, client)); |
443 |
michael |
1013 |
|
444 |
michael |
9250 |
dlink_move_node(&client->connection->lclient_node, |
445 |
michael |
1126 |
&unknown_list, &local_client_list); |
446 |
adx |
30 |
|
447 |
michael |
7969 |
if (dlink_list_length(&local_client_list) > Count.max_loc) |
448 |
|
|
{ |
449 |
|
|
Count.max_loc = dlink_list_length(&local_client_list); |
450 |
|
|
|
451 |
|
|
if (!(Count.max_loc % 10)) |
452 |
|
|
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
453 |
|
|
"New maximum local client connections: %u", |
454 |
|
|
Count.max_loc); |
455 |
|
|
} |
456 |
|
|
|
457 |
michael |
8001 |
if ((dlink_list_length(&local_client_list) + |
458 |
|
|
dlink_list_length(&local_server_list)) > Count.max_loc_con) |
459 |
|
|
Count.max_loc_con = dlink_list_length(&local_client_list) + |
460 |
|
|
dlink_list_length(&local_server_list); |
461 |
|
|
|
462 |
michael |
7965 |
if (dlink_list_length(&global_client_list) > Count.max_tot) |
463 |
|
|
Count.max_tot = dlink_list_length(&global_client_list); |
464 |
|
|
++Count.totalrestartcount; |
465 |
|
|
|
466 |
michael |
9250 |
user_welcome(client); |
467 |
adx |
30 |
|
468 |
michael |
9250 |
introduce_client(client); |
469 |
adx |
30 |
} |
470 |
|
|
|
471 |
|
|
/* register_remote_user() |
472 |
|
|
* |
473 |
michael |
9250 |
* inputs - client remote or directly connected client |
474 |
adx |
30 |
* - username to register as |
475 |
|
|
* - host name to register as |
476 |
|
|
* - server name |
477 |
|
|
* output - NONE |
478 |
|
|
* side effects - This function is called when a remote client |
479 |
|
|
* is introduced by a server. |
480 |
|
|
*/ |
481 |
|
|
void |
482 |
michael |
9250 |
register_remote_user(struct Client *client) |
483 |
adx |
30 |
{ |
484 |
michael |
9250 |
assert(client->servptr->from == client->from); |
485 |
adx |
30 |
|
486 |
michael |
1167 |
/* |
487 |
|
|
* If the nick has been introduced by a services server, |
488 |
|
|
* make it a service as well. |
489 |
|
|
*/ |
490 |
michael |
9250 |
if (HasFlag(client->servptr, FLAGS_SERVICE)) |
491 |
|
|
AddFlag(client, FLAGS_SERVICE); |
492 |
michael |
1167 |
|
493 |
michael |
9250 |
SetClient(client); |
494 |
|
|
dlinkAdd(client, &client->lnode, &client->servptr->serv->client_list); |
495 |
|
|
dlinkAdd(client, &client->node, &global_client_list); |
496 |
michael |
7965 |
|
497 |
|
|
if (dlink_list_length(&global_client_list) > Count.max_tot) |
498 |
|
|
Count.max_tot = dlink_list_length(&global_client_list); |
499 |
|
|
|
500 |
michael |
9250 |
if (HasFlag(client->servptr, FLAGS_EOB)) |
501 |
michael |
5743 |
sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE, |
502 |
|
|
"Client connecting at %s: %s (%s@%s) [%s] [%s] <%s>", |
503 |
michael |
9250 |
client->servptr->name, |
504 |
|
|
client->name, client->username, client->realhost, |
505 |
|
|
client->sockhost, client->info, client->id); |
506 |
michael |
1976 |
|
507 |
michael |
9250 |
introduce_client(client); |
508 |
adx |
30 |
} |
509 |
|
|
|
510 |
|
|
/* valid_hostname() |
511 |
|
|
* |
512 |
|
|
* Inputs - pointer to hostname |
513 |
|
|
* Output - 1 if valid, 0 if not |
514 |
|
|
* Side effects - check hostname for validity |
515 |
|
|
* |
516 |
|
|
* NOTE: this doesn't allow a hostname to begin with a dot and |
517 |
|
|
* will not allow more dots than chars. |
518 |
|
|
*/ |
519 |
michael |
8658 |
bool |
520 |
adx |
30 |
valid_hostname(const char *hostname) |
521 |
|
|
{ |
522 |
|
|
const char *p = hostname; |
523 |
|
|
|
524 |
michael |
3235 |
assert(p); |
525 |
adx |
30 |
|
526 |
michael |
2352 |
if (EmptyString(p) || *p == '.' || *p == ':') |
527 |
michael |
8658 |
return false; |
528 |
adx |
30 |
|
529 |
michael |
1080 |
for (; *p; ++p) |
530 |
adx |
30 |
if (!IsHostChar(*p)) |
531 |
michael |
8658 |
return false; |
532 |
adx |
30 |
|
533 |
michael |
1795 |
return p - hostname <= HOSTLEN; |
534 |
adx |
30 |
} |
535 |
|
|
|
536 |
|
|
/* valid_username() |
537 |
|
|
* |
538 |
|
|
* Inputs - pointer to user |
539 |
|
|
* Output - 1 if valid, 0 if not |
540 |
|
|
* Side effects - check username for validity |
541 |
|
|
* |
542 |
|
|
* Absolutely always reject any '*' '!' '?' '@' in an user name |
543 |
|
|
* reject any odd control characters names. |
544 |
|
|
* Allow '.' in username to allow for "first.last" |
545 |
|
|
* style of username |
546 |
|
|
*/ |
547 |
michael |
8658 |
bool |
548 |
michael |
8660 |
valid_username(const char *username, bool local) |
549 |
adx |
30 |
{ |
550 |
|
|
const char *p = username; |
551 |
|
|
|
552 |
michael |
3235 |
assert(p); |
553 |
adx |
30 |
|
554 |
michael |
1080 |
if (*p == '~') |
555 |
adx |
30 |
++p; |
556 |
|
|
|
557 |
michael |
2067 |
/* |
558 |
|
|
* Reject usernames that don't start with an alphanum |
559 |
adx |
30 |
* i.e. reject jokers who have '-@somehost' or '.@somehost' |
560 |
|
|
* or "-hi-@somehost", "h-----@somehost" would still be accepted. |
561 |
|
|
*/ |
562 |
|
|
if (!IsAlNum(*p)) |
563 |
michael |
8658 |
return false; |
564 |
adx |
30 |
|
565 |
michael |
2067 |
if (local) |
566 |
adx |
30 |
{ |
567 |
michael |
6756 |
unsigned int dots = 0; |
568 |
|
|
|
569 |
michael |
2067 |
while (*++p) |
570 |
adx |
30 |
{ |
571 |
michael |
4340 |
if (*p == '.' && ConfigGeneral.dots_in_ident) |
572 |
michael |
2067 |
{ |
573 |
michael |
4340 |
if (++dots > ConfigGeneral.dots_in_ident) |
574 |
michael |
8658 |
return false; |
575 |
michael |
2067 |
if (!IsUserChar(*(p + 1))) |
576 |
michael |
8658 |
return false; |
577 |
michael |
2067 |
} |
578 |
|
|
else if (!IsUserChar(*p)) |
579 |
michael |
8658 |
return false; |
580 |
adx |
30 |
} |
581 |
|
|
} |
582 |
michael |
2067 |
else |
583 |
|
|
{ |
584 |
|
|
while (*++p) |
585 |
|
|
if (!IsUserChar(*p)) |
586 |
michael |
8658 |
return false; |
587 |
michael |
2067 |
} |
588 |
adx |
30 |
|
589 |
michael |
3656 |
return p - username <= USERLEN; |
590 |
adx |
30 |
} |
591 |
|
|
|
592 |
michael |
1165 |
/* clean_nick_name() |
593 |
|
|
* |
594 |
|
|
* input - nickname |
595 |
|
|
* - whether it's a local nick (1) or remote (0) |
596 |
|
|
* output - none |
597 |
|
|
* side effects - walks through the nickname, returning 0 if erroneous |
598 |
|
|
*/ |
599 |
michael |
8658 |
bool |
600 |
michael |
8660 |
valid_nickname(const char *nickname, bool local) |
601 |
michael |
1165 |
{ |
602 |
|
|
const char *p = nickname; |
603 |
michael |
3318 |
|
604 |
michael |
4982 |
assert(p); |
605 |
michael |
1165 |
|
606 |
michael |
3317 |
/* |
607 |
|
|
* Nicks can't start with a digit or - or be 0 length. |
608 |
|
|
*/ |
609 |
michael |
4709 |
if (EmptyString(p) || *p == '-' || (IsDigit(*p) && local)) |
610 |
michael |
8658 |
return false; |
611 |
michael |
1165 |
|
612 |
|
|
for (; *p; ++p) |
613 |
|
|
if (!IsNickChar(*p)) |
614 |
michael |
8658 |
return false; |
615 |
michael |
1165 |
|
616 |
michael |
1431 |
return p - nickname <= NICKLEN; |
617 |
michael |
1165 |
} |
618 |
|
|
|
619 |
michael |
7599 |
/*! \brief Builds a mode change string to buffer pointed by \a buf |
620 |
michael |
9250 |
* \param client Pointer to client |
621 |
|
|
* \param dispatch Whether to send a MODE message to client |
622 |
|
|
* \param old Old user mode to compare against when building new mode buffer |
623 |
|
|
* \param buf Pointer to buffer to build string in |
624 |
adx |
30 |
*/ |
625 |
|
|
void |
626 |
michael |
9250 |
send_umode(struct Client *client, bool dispatch, unsigned int old, char *buf) |
627 |
adx |
30 |
{ |
628 |
michael |
7599 |
char *m = buf; |
629 |
adx |
30 |
int what = 0; |
630 |
|
|
|
631 |
michael |
56 |
/* |
632 |
michael |
3317 |
* Build a string in umode_buf to represent the change in the user's |
633 |
michael |
9250 |
* mode between the new (client->umodes) and 'old'. |
634 |
adx |
30 |
*/ |
635 |
michael |
5392 |
for (const struct user_modes *tab = umode_tab; tab->c; ++tab) |
636 |
adx |
30 |
{ |
637 |
michael |
9250 |
if ((tab->flag & old) && !HasUMode(client, tab->flag)) |
638 |
adx |
30 |
{ |
639 |
|
|
if (what == MODE_DEL) |
640 |
michael |
5392 |
*m++ = tab->c; |
641 |
adx |
30 |
else |
642 |
|
|
{ |
643 |
|
|
what = MODE_DEL; |
644 |
|
|
*m++ = '-'; |
645 |
michael |
5392 |
*m++ = tab->c; |
646 |
adx |
30 |
} |
647 |
|
|
} |
648 |
michael |
9250 |
else if (!(tab->flag & old) && HasUMode(client, tab->flag)) |
649 |
adx |
30 |
{ |
650 |
|
|
if (what == MODE_ADD) |
651 |
michael |
5392 |
*m++ = tab->c; |
652 |
adx |
30 |
else |
653 |
|
|
{ |
654 |
|
|
what = MODE_ADD; |
655 |
|
|
*m++ = '+'; |
656 |
michael |
5392 |
*m++ = tab->c; |
657 |
adx |
30 |
} |
658 |
|
|
} |
659 |
|
|
} |
660 |
|
|
|
661 |
|
|
*m = '\0'; |
662 |
|
|
|
663 |
michael |
8658 |
if (dispatch == true && *buf) |
664 |
michael |
9250 |
sendto_one(client, ":%s!%s@%s MODE %s :%s", |
665 |
|
|
client->name, client->username, |
666 |
|
|
client->host, client->name, buf); |
667 |
adx |
30 |
} |
668 |
|
|
|
669 |
|
|
/* send_umode_out() |
670 |
|
|
* |
671 |
|
|
* inputs - |
672 |
|
|
* output - NONE |
673 |
|
|
* side effects - Only send ubuf out to servers that know about this client |
674 |
|
|
*/ |
675 |
|
|
void |
676 |
michael |
9250 |
send_umode_out(struct Client *client, unsigned int old) |
677 |
adx |
30 |
{ |
678 |
michael |
8063 |
char buf[UMODE_MAX_STR] = ""; |
679 |
adx |
30 |
|
680 |
michael |
9250 |
send_umode(client, MyConnect(client), old, buf); |
681 |
adx |
30 |
|
682 |
michael |
573 |
if (buf[0]) |
683 |
michael |
9250 |
sendto_server(client, 0, 0, ":%s MODE %s :%s", |
684 |
|
|
client->id, client->id, buf); |
685 |
adx |
30 |
} |
686 |
|
|
|
687 |
michael |
1819 |
void |
688 |
michael |
9250 |
user_set_hostmask(struct Client *client, const char *hostname) |
689 |
michael |
1819 |
{ |
690 |
michael |
8059 |
dlink_node *node; |
691 |
michael |
2141 |
|
692 |
michael |
9250 |
if (strcmp(client->host, hostname) == 0) |
693 |
michael |
2145 |
return; |
694 |
michael |
2141 |
|
695 |
michael |
4340 |
if (ConfigGeneral.cycle_on_host_change) |
696 |
michael |
9250 |
sendto_common_channels_local(client, false, 0, CAP_CHGHOST, ":%s!%s@%s QUIT :Changing hostname", |
697 |
|
|
client->name, client->username, client->host); |
698 |
michael |
2145 |
|
699 |
michael |
9250 |
sendto_common_channels_local(client, true, CAP_CHGHOST, 0, ":%s!%s@%s CHGHOST %s %s", |
700 |
|
|
client->name, client->username, |
701 |
|
|
client->host, client->username, hostname); |
702 |
michael |
6774 |
|
703 |
michael |
9250 |
strlcpy(client->host, hostname, sizeof(client->host)); |
704 |
michael |
2145 |
|
705 |
michael |
9250 |
if (MyConnect(client)) |
706 |
michael |
2137 |
{ |
707 |
michael |
9250 |
sendto_one_numeric(client, &me, RPL_VISIBLEHOST, client->host); |
708 |
|
|
clear_ban_cache_list(&client->channel); |
709 |
michael |
2137 |
} |
710 |
michael |
2141 |
|
711 |
michael |
8512 |
if (ConfigGeneral.cycle_on_host_change == 0) |
712 |
michael |
2283 |
return; |
713 |
|
|
|
714 |
michael |
9250 |
DLINK_FOREACH(node, client->channel.head) |
715 |
michael |
2141 |
{ |
716 |
michael |
6904 |
char modebuf[CMEMBER_STATUS_FLAGS_LEN + 1]; |
717 |
|
|
char nickbuf[CMEMBER_STATUS_FLAGS_LEN * NICKLEN + CMEMBER_STATUS_FLAGS_LEN] = ""; |
718 |
michael |
2141 |
char *p = modebuf; |
719 |
|
|
int len = 0; |
720 |
michael |
9081 |
const struct ChannelMember *member = node->data; |
721 |
michael |
2141 |
|
722 |
michael |
9598 |
if (member_has_flags(member, CHFL_CHANOP) == true) |
723 |
michael |
2283 |
{ |
724 |
michael |
2141 |
*p++ = 'o'; |
725 |
michael |
9250 |
len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", client->name); |
726 |
michael |
2141 |
} |
727 |
|
|
|
728 |
michael |
9598 |
if (member_has_flags(member, CHFL_HALFOP) == true) |
729 |
michael |
2283 |
{ |
730 |
michael |
2141 |
*p++ = 'h'; |
731 |
michael |
9250 |
len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", client->name); |
732 |
michael |
2141 |
} |
733 |
|
|
|
734 |
michael |
9598 |
if (member_has_flags(member, CHFL_VOICE) == true) |
735 |
michael |
2283 |
{ |
736 |
michael |
2141 |
*p++ = 'v'; |
737 |
michael |
9250 |
len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", client->name); |
738 |
michael |
2141 |
} |
739 |
|
|
|
740 |
|
|
*p = '\0'; |
741 |
|
|
|
742 |
michael |
9250 |
sendto_channel_local(client, member->channel, 0, CAP_EXTENDED_JOIN, CAP_CHGHOST, ":%s!%s@%s JOIN %s %s :%s", |
743 |
|
|
client->name, client->username, |
744 |
|
|
client->host, member->channel->name, |
745 |
|
|
client->account, client->info); |
746 |
|
|
sendto_channel_local(client, member->channel, 0, 0, CAP_EXTENDED_JOIN | CAP_CHGHOST, ":%s!%s@%s JOIN :%s", |
747 |
|
|
client->name, client->username, |
748 |
|
|
client->host, member->channel->name); |
749 |
michael |
4792 |
|
750 |
michael |
2141 |
if (nickbuf[0]) |
751 |
michael |
9250 |
sendto_channel_local(client, member->channel, 0, 0, CAP_CHGHOST, ":%s MODE %s +%s %s", |
752 |
|
|
client->servptr->name, member->channel->name, |
753 |
michael |
6759 |
modebuf, nickbuf); |
754 |
michael |
2141 |
} |
755 |
michael |
6777 |
|
756 |
michael |
9250 |
if (client->away[0]) |
757 |
|
|
sendto_common_channels_local(client, false, CAP_AWAY_NOTIFY, CAP_CHGHOST, |
758 |
michael |
6777 |
":%s!%s@%s AWAY :%s", |
759 |
michael |
9250 |
client->name, client->username, |
760 |
|
|
client->host, client->away); |
761 |
michael |
1819 |
} |