1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
< |
* s_auth.c: Functions for querying a users ident. |
2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
4 |
> |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
|
* |
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 |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
* USA |
20 |
< |
* |
21 |
< |
* $Id$ |
20 |
> |
*/ |
21 |
> |
|
22 |
> |
/*! \file s_auth.c |
23 |
> |
* \brief Functions for querying a users ident. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
/* |
34 |
|
* any messages from it. |
35 |
|
* --Bleep Thomas Helvey <tomh@inxpress.net> |
36 |
|
*/ |
37 |
+ |
|
38 |
|
#include "stdinc.h" |
39 |
|
#include "list.h" |
40 |
|
#include "ircd_defs.h" |
41 |
|
#include "fdlist.h" |
42 |
|
#include "s_auth.h" |
43 |
< |
#include "s_conf.h" |
41 |
< |
#include "balloc.h" |
43 |
> |
#include "conf.h" |
44 |
|
#include "client.h" |
45 |
|
#include "event.h" |
46 |
|
#include "hook.h" |
49 |
|
#include "packet.h" |
50 |
|
#include "irc_res.h" |
51 |
|
#include "s_bsd.h" |
52 |
< |
#include "s_log.h" |
52 |
> |
#include "log.h" |
53 |
|
#include "send.h" |
54 |
+ |
#include "mempool.h" |
55 |
|
|
56 |
|
|
57 |
< |
static const char *HeaderMessages[] = { |
57 |
> |
static const char *HeaderMessages[] = |
58 |
> |
{ |
59 |
|
":%s NOTICE AUTH :*** Looking up your hostname...", |
60 |
|
":%s NOTICE AUTH :*** Found your hostname", |
61 |
|
":%s NOTICE AUTH :*** Couldn't look up your hostname", |
66 |
|
":%s NOTICE AUTH :*** Your hostname is too long, ignoring hostname" |
67 |
|
}; |
68 |
|
|
69 |
< |
enum { |
69 |
> |
enum |
70 |
> |
{ |
71 |
|
REPORT_DO_DNS, |
72 |
|
REPORT_FIN_DNS, |
73 |
|
REPORT_FAIL_DNS, |
80 |
|
|
81 |
|
#define sendheader(c, i) sendto_one((c), HeaderMessages[(i)], me.name) |
82 |
|
|
78 |
– |
static BlockHeap *auth_heap = NULL; |
83 |
|
static dlink_list auth_doing_list = { NULL, NULL, 0 }; |
84 |
|
|
85 |
|
static EVH timeout_auth_queries_event; |
86 |
|
|
87 |
|
static PF read_auth_reply; |
88 |
|
static CNCB auth_connect_callback; |
85 |
– |
static CBFUNC start_auth; |
86 |
– |
|
87 |
– |
struct Callback *auth_cb = NULL; |
89 |
|
|
90 |
< |
/* init_auth() |
90 |
> |
/* auth_init |
91 |
|
* |
92 |
|
* Initialise the auth code |
93 |
|
*/ |
94 |
|
void |
95 |
< |
init_auth(void) |
95 |
> |
auth_init(void) |
96 |
|
{ |
96 |
– |
auth_heap = BlockHeapCreate("auth", sizeof(struct AuthRequest), AUTH_HEAP_SIZE); |
97 |
– |
auth_cb = register_callback("start_auth", start_auth); |
97 |
|
eventAddIsh("timeout_auth_queries_event", timeout_auth_queries_event, NULL, 1); |
98 |
|
} |
99 |
|
|
103 |
|
static struct AuthRequest * |
104 |
|
make_auth_request(struct Client *client) |
105 |
|
{ |
106 |
< |
struct AuthRequest *request = BlockHeapAlloc(auth_heap); |
106 |
> |
struct AuthRequest *request = &client->localClient->auth; |
107 |
> |
|
108 |
> |
memset(request, 0, sizeof(*request)); |
109 |
|
|
110 |
< |
client->localClient->auth = request; |
111 |
< |
request->client = client; |
111 |
< |
request->timeout = CurrentTime + CONNECTTIMEOUT; |
110 |
> |
request->client = client; |
111 |
> |
request->timeout = CurrentTime + CONNECTTIMEOUT; |
112 |
|
|
113 |
|
return request; |
114 |
|
} |
126 |
|
if (IsDoingAuth(auth) || IsDNSPending(auth)) |
127 |
|
return; |
128 |
|
|
129 |
< |
client->localClient->auth = NULL; |
130 |
< |
dlinkDelete(&auth->node, &auth_doing_list); |
131 |
< |
BlockHeapFree(auth_heap, auth); |
129 |
> |
if (dlinkFind(&auth_doing_list, auth)) |
130 |
> |
dlinkDelete(&auth->node, &auth_doing_list); |
131 |
|
|
132 |
|
/* |
133 |
|
* When a client has auth'ed, we want to start reading what it sends |
146 |
|
|
147 |
|
read_packet(&client->localClient->fd, client); |
148 |
|
} |
149 |
< |
|
149 |
> |
|
150 |
|
/* |
151 |
|
* auth_dns_callback - called when resolver query finishes |
152 |
|
* if the query resulted in a successful search, name will contain |
194 |
|
if (good && strlen(name) <= HOSTLEN) |
195 |
|
{ |
196 |
|
strlcpy(auth->client->host, name, |
197 |
< |
sizeof(auth->client->host)); |
197 |
> |
sizeof(auth->client->host)); |
198 |
|
sendheader(auth->client, REPORT_FIN_DNS); |
199 |
|
} |
200 |
|
else if (strlen(name) > HOSTLEN) |
224 |
|
} |
225 |
|
|
226 |
|
/* |
227 |
< |
* start_auth_query - Flag the client to show that an attempt to |
227 |
> |
* start_auth_query - Flag the client to show that an attempt to |
228 |
|
* contact the ident server on |
229 |
|
* the client's host. The connect and subsequently the socket are all put |
230 |
|
* into 'non-blocking' mode. Should the connect or any later phase of the |
246 |
|
if (comm_open(&auth->fd, auth->client->localClient->ip.ss.ss_family, |
247 |
|
SOCK_STREAM, 0, "ident") == -1) |
248 |
|
{ |
249 |
< |
report_error(L_ALL, "creating auth stream socket %s:%s", |
250 |
< |
get_client_name(auth->client, SHOW_IP), errno); |
251 |
< |
ilog(L_ERROR, "Unable to create auth socket for %s", |
249 |
> |
report_error(L_ALL, "creating auth stream socket %s:%s", |
250 |
> |
get_client_name(auth->client, SHOW_IP), errno); |
251 |
> |
ilog(LOG_TYPE_IRCD, "Unable to create auth socket for %s", |
252 |
|
get_client_name(auth->client, SHOW_IP)); |
253 |
|
++ServerStats.is_abad; |
254 |
|
return 0; |
256 |
|
|
257 |
|
sendheader(auth->client, REPORT_DO_ID); |
258 |
|
|
259 |
< |
/* |
259 |
> |
/* |
260 |
|
* get the local address of the client and bind to that to |
261 |
|
* make the auth request. This used to be done only for |
262 |
|
* ifdef VIRTUAL_HOST, but needs to be done for all clients |
278 |
|
#endif |
279 |
|
localaddr.ss_port = htons(0); |
280 |
|
|
281 |
< |
comm_connect_tcp(&auth->fd, auth->client->sockhost, 113, |
282 |
< |
(struct sockaddr *)&localaddr, localaddr.ss_len, auth_connect_callback, |
283 |
< |
auth, auth->client->localClient->ip.ss.ss_family, |
281 |
> |
comm_connect_tcp(&auth->fd, auth->client->sockhost, 113, |
282 |
> |
(struct sockaddr *)&localaddr, localaddr.ss_len, auth_connect_callback, |
283 |
> |
auth, auth->client->localClient->ip.ss.ss_family, |
284 |
|
GlobalSetOptions.ident_timeout); |
285 |
|
return 1; /* We suceed here for now */ |
286 |
|
} |
287 |
|
|
288 |
|
/* |
289 |
|
* GetValidIdent - parse ident query reply from identd server |
290 |
< |
* |
290 |
> |
* |
291 |
|
* Inputs - pointer to ident buf |
292 |
|
* Output - NULL if no valid ident found, otherwise pointer to name |
293 |
|
* Side effects - |
320 |
|
|
321 |
|
/* All this to get rid of a sscanf() fun. */ |
322 |
|
remotePortString = buf; |
323 |
< |
|
323 |
> |
|
324 |
|
if ((colon1Ptr = strchr(remotePortString,':')) == NULL) |
325 |
|
return 0; |
326 |
|
*colon1Ptr = '\0'; |
330 |
|
return 0; |
331 |
|
*colon2Ptr = '\0'; |
332 |
|
colon2Ptr++; |
333 |
< |
|
333 |
> |
|
334 |
|
if ((commaPtr = strchr(remotePortString, ',')) == NULL) |
335 |
|
return 0; |
336 |
|
*commaPtr = '\0'; |
338 |
|
|
339 |
|
if ((remp = atoi(remotePortString)) == 0) |
340 |
|
return 0; |
341 |
< |
|
341 |
> |
|
342 |
|
if ((locp = atoi(commaPtr)) == 0) |
343 |
|
return 0; |
344 |
|
|
354 |
|
} |
355 |
|
|
356 |
|
/* |
357 |
< |
* start_auth |
357 |
> |
* start_auth |
358 |
|
* |
359 |
|
* inputs - pointer to client to auth |
360 |
|
* output - NONE |
361 |
|
* side effects - starts auth (identd) and dns queries for a client |
362 |
|
*/ |
363 |
< |
static void * |
364 |
< |
start_auth(va_list args) |
363 |
> |
void |
364 |
> |
start_auth(struct Client *client) |
365 |
|
{ |
367 |
– |
struct Client *client = va_arg(args, struct Client *); |
366 |
|
struct AuthRequest *auth = NULL; |
367 |
|
|
368 |
|
assert(client != NULL); |
381 |
|
} |
382 |
|
|
383 |
|
gethost_byaddr(auth_dns_callback, auth, &client->localClient->ip); |
386 |
– |
|
387 |
– |
return NULL; |
384 |
|
} |
385 |
|
|
386 |
|
/* |
400 |
|
continue; |
401 |
|
|
402 |
|
if (IsDoingAuth(auth)) |
403 |
< |
{ |
403 |
> |
{ |
404 |
|
++ServerStats.is_abad; |
405 |
|
fd_close(&auth->fd); |
406 |
|
ClearAuth(auth); |
414 |
|
sendheader(auth->client, REPORT_FAIL_DNS); |
415 |
|
} |
416 |
|
|
417 |
< |
ilog(L_INFO, "DNS/AUTH timeout %s", |
417 |
> |
ilog(LOG_TYPE_IRCD, "DNS/AUTH timeout %s", |
418 |
|
get_client_name(auth->client, SHOW_IP)); |
419 |
|
release_auth_client(auth); |
420 |
|
} |
458 |
|
getpeername(auth->client->localClient->fd.fd, (struct sockaddr *)&them, |
459 |
|
&tlen)) |
460 |
|
{ |
461 |
< |
ilog(L_INFO, "auth get{sock,peer}name error for %s", |
461 |
> |
ilog(LOG_TYPE_IRCD, "auth get{sock,peer}name error for %s", |
462 |
|
get_client_name(auth->client, SHOW_IP)); |
463 |
|
auth_error(auth); |
464 |
|
return; |
479 |
|
us.ss_len = ulen; |
480 |
|
them.ss_len = tlen; |
481 |
|
#endif |
482 |
< |
|
482 |
> |
|
483 |
|
snprintf(authbuf, sizeof(authbuf), "%u , %u\r\n", tport, uport); |
484 |
|
|
485 |
|
if (send(fd->fd, authbuf, strlen(authbuf), 0) == -1) |
492 |
|
} |
493 |
|
|
494 |
|
/* |
495 |
< |
* read_auth_reply - read the reply (if any) from the ident server |
495 |
> |
* read_auth_reply - read the reply (if any) from the ident server |
496 |
|
* we connected to. |
497 |
|
* We only give it one shot, if the reply isn't good the first time |
498 |
|
* fail the authentication entirely. --Bleep |
579 |
|
/* |
580 |
|
* delete_auth() |
581 |
|
*/ |
582 |
< |
void |
582 |
> |
void |
583 |
|
delete_auth(struct AuthRequest *auth) |
584 |
|
{ |
585 |
|
if (IsDNSPending(auth)) |
588 |
|
if (IsDoingAuth(auth)) |
589 |
|
fd_close(&auth->fd); |
590 |
|
|
591 |
< |
dlinkDelete(&auth->node, &auth_doing_list); |
592 |
< |
BlockHeapFree(auth_heap, auth); |
591 |
> |
if (dlinkFind(&auth_doing_list, auth)) |
592 |
> |
dlinkDelete(&auth->node, &auth_doing_list); |
593 |
|
} |