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 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" |
42 |
> |
#include "auth.h" |
43 |
> |
#include "conf.h" |
44 |
|
#include "client.h" |
43 |
– |
#include "common.h" |
45 |
|
#include "event.h" |
45 |
– |
#include "hook.h" |
46 |
|
#include "irc_string.h" |
47 |
– |
#include "sprintf_irc.h" |
47 |
|
#include "ircd.h" |
49 |
– |
#include "numeric.h" |
48 |
|
#include "packet.h" |
49 |
< |
#include "irc_res.h" |
49 |
> |
#include "res.h" |
50 |
|
#include "s_bsd.h" |
51 |
< |
#include "s_log.h" |
51 |
> |
#include "log.h" |
52 |
|
#include "send.h" |
53 |
+ |
#include "mempool.h" |
54 |
|
|
55 |
|
|
56 |
< |
static const char *HeaderMessages[] = { |
57 |
< |
":%s NOTICE AUTH :*** Looking up your hostname...", |
58 |
< |
":%s NOTICE AUTH :*** Found your hostname", |
59 |
< |
":%s NOTICE AUTH :*** Couldn't look up your hostname", |
60 |
< |
":%s NOTICE AUTH :*** Checking Ident", |
61 |
< |
":%s NOTICE AUTH :*** Got Ident response", |
62 |
< |
":%s NOTICE AUTH :*** No Ident response", |
63 |
< |
":%s NOTICE AUTH :*** Your forward and reverse DNS do not match, ignoring hostname.", |
64 |
< |
":%s NOTICE AUTH :*** Your hostname is too long, ignoring hostname" |
56 |
> |
static const char *const HeaderMessages[] = |
57 |
> |
{ |
58 |
> |
":*** Looking up your hostname", |
59 |
> |
":*** Found your hostname", |
60 |
> |
":*** Couldn't look up your hostname", |
61 |
> |
":*** Checking Ident", |
62 |
> |
":*** Got Ident response", |
63 |
> |
":*** No Ident response", |
64 |
> |
":*** Your forward and reverse DNS do not match, ignoring hostname", |
65 |
> |
":*** Your hostname is too long, ignoring hostname" |
66 |
|
}; |
67 |
|
|
68 |
< |
enum { |
68 |
> |
enum |
69 |
> |
{ |
70 |
|
REPORT_DO_DNS, |
71 |
|
REPORT_FIN_DNS, |
72 |
|
REPORT_FAIL_DNS, |
77 |
|
REPORT_HOST_TOOLONG |
78 |
|
}; |
79 |
|
|
80 |
< |
#define sendheader(c, i) sendto_one((c), HeaderMessages[(i)], me.name) |
80 |
< |
|
81 |
< |
static BlockHeap *auth_heap = NULL; |
82 |
< |
static dlink_list auth_doing_list = { NULL, NULL, 0 }; |
83 |
< |
|
84 |
< |
static EVH timeout_auth_queries_event; |
80 |
> |
#define sendheader(c, i) sendto_one_notice((c), &me, HeaderMessages[(i)]) |
81 |
|
|
82 |
+ |
static dlink_list auth_pending_list; |
83 |
|
static PF read_auth_reply; |
84 |
|
static CNCB auth_connect_callback; |
88 |
– |
static CBFUNC start_auth; |
89 |
– |
|
90 |
– |
struct Callback *auth_cb = NULL; |
85 |
|
|
92 |
– |
/* init_auth() |
93 |
– |
* |
94 |
– |
* Initialise the auth code |
95 |
– |
*/ |
96 |
– |
void |
97 |
– |
init_auth(void) |
98 |
– |
{ |
99 |
– |
auth_heap = BlockHeapCreate("auth", sizeof(struct AuthRequest), AUTH_HEAP_SIZE); |
100 |
– |
auth_cb = register_callback("start_auth", start_auth); |
101 |
– |
eventAddIsh("timeout_auth_queries_event", timeout_auth_queries_event, NULL, 1); |
102 |
– |
} |
86 |
|
|
87 |
|
/* |
88 |
|
* make_auth_request - allocate a new auth request |
90 |
|
static struct AuthRequest * |
91 |
|
make_auth_request(struct Client *client) |
92 |
|
{ |
93 |
< |
struct AuthRequest *request = BlockHeapAlloc(auth_heap); |
93 |
> |
struct AuthRequest *request = &client->localClient->auth; |
94 |
> |
|
95 |
> |
memset(request, 0, sizeof(*request)); |
96 |
|
|
97 |
< |
client->localClient->auth = request; |
98 |
< |
request->client = client; |
114 |
< |
request->timeout = CurrentTime + CONNECTTIMEOUT; |
97 |
> |
request->client = client; |
98 |
> |
request->timeout = CurrentTime + CONNECTTIMEOUT; |
99 |
|
|
100 |
|
return request; |
101 |
|
} |
113 |
|
if (IsDoingAuth(auth) || IsDNSPending(auth)) |
114 |
|
return; |
115 |
|
|
116 |
< |
client->localClient->auth = NULL; |
117 |
< |
dlinkDelete(&auth->node, &auth_doing_list); |
118 |
< |
BlockHeapFree(auth_heap, auth); |
116 |
> |
if (IsInAuth(auth)) |
117 |
> |
{ |
118 |
> |
dlinkDelete(&auth->node, &auth_pending_list); |
119 |
> |
ClearInAuth(auth); |
120 |
> |
} |
121 |
|
|
122 |
|
/* |
123 |
|
* When a client has auth'ed, we want to start reading what it sends |
127 |
|
client->localClient->allow_read = MAX_FLOOD; |
128 |
|
comm_setflush(&client->localClient->fd, 1000, flood_recalc, client); |
129 |
|
|
130 |
< |
dlinkAdd(client, &client->node, &global_client_list); |
131 |
< |
|
132 |
< |
client->since = client->lasttime = client->firsttime = CurrentTime; |
130 |
> |
client->localClient->since = CurrentTime; |
131 |
> |
client->localClient->lasttime = CurrentTime; |
132 |
> |
client->localClient->firsttime = CurrentTime; |
133 |
|
client->flags |= FLAGS_FINISHED_AUTH; |
134 |
|
|
135 |
|
read_packet(&client->localClient->fd, client); |
136 |
|
} |
137 |
< |
|
137 |
> |
|
138 |
|
/* |
139 |
|
* auth_dns_callback - called when resolver query finishes |
140 |
|
* if the query resulted in a successful search, name will contain |
143 |
|
* of success of failure |
144 |
|
*/ |
145 |
|
static void |
146 |
< |
auth_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name) |
146 |
> |
auth_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength) |
147 |
|
{ |
148 |
|
struct AuthRequest *auth = vptr; |
149 |
|
|
150 |
|
ClearDNSPending(auth); |
151 |
|
|
152 |
< |
if (name != NULL) |
152 |
> |
if (!EmptyString(name)) |
153 |
|
{ |
154 |
|
const struct sockaddr_in *v4, *v4dns; |
155 |
|
#ifdef IPV6 |
156 |
|
const struct sockaddr_in6 *v6, *v6dns; |
171 |
– |
#endif |
172 |
– |
int good = 1; |
157 |
|
|
174 |
– |
#ifdef IPV6 |
158 |
|
if (auth->client->localClient->ip.ss.ss_family == AF_INET6) |
159 |
|
{ |
160 |
|
v6 = (const struct sockaddr_in6 *)&auth->client->localClient->ip; |
161 |
|
v6dns = (const struct sockaddr_in6 *)addr; |
162 |
+ |
|
163 |
|
if (memcmp(&v6->sin6_addr, &v6dns->sin6_addr, sizeof(struct in6_addr)) != 0) |
164 |
|
{ |
165 |
|
sendheader(auth->client, REPORT_IP_MISMATCH); |
166 |
< |
good = 0; |
166 |
> |
release_auth_client(auth); |
167 |
> |
return; |
168 |
|
} |
169 |
|
} |
170 |
|
else |
172 |
|
{ |
173 |
|
v4 = (const struct sockaddr_in *)&auth->client->localClient->ip; |
174 |
|
v4dns = (const struct sockaddr_in *)addr; |
175 |
< |
if(v4->sin_addr.s_addr != v4dns->sin_addr.s_addr) |
175 |
> |
|
176 |
> |
if (v4->sin_addr.s_addr != v4dns->sin_addr.s_addr) |
177 |
|
{ |
178 |
|
sendheader(auth->client, REPORT_IP_MISMATCH); |
179 |
< |
good = 0; |
179 |
> |
release_auth_client(auth); |
180 |
> |
return; |
181 |
|
} |
182 |
|
} |
183 |
< |
if (good && strlen(name) <= HOSTLEN) |
183 |
> |
|
184 |
> |
if (namelength > HOSTLEN) |
185 |
> |
sendheader(auth->client, REPORT_HOST_TOOLONG); |
186 |
> |
else |
187 |
|
{ |
188 |
< |
strlcpy(auth->client->host, name, |
199 |
< |
sizeof(auth->client->host)); |
188 |
> |
strlcpy(auth->client->host, name, sizeof(auth->client->host)); |
189 |
|
sendheader(auth->client, REPORT_FIN_DNS); |
190 |
|
} |
202 |
– |
else if (strlen(name) > HOSTLEN) |
203 |
– |
sendheader(auth->client, REPORT_HOST_TOOLONG); |
191 |
|
} |
192 |
|
else |
193 |
|
sendheader(auth->client, REPORT_FAIL_DNS); |
213 |
|
} |
214 |
|
|
215 |
|
/* |
216 |
< |
* start_auth_query - Flag the client to show that an attempt to |
216 |
> |
* start_auth_query - Flag the client to show that an attempt to |
217 |
|
* contact the ident server on |
218 |
|
* the client's host. The connect and subsequently the socket are all put |
219 |
|
* into 'non-blocking' mode. Should the connect or any later phase of the |
235 |
|
if (comm_open(&auth->fd, auth->client->localClient->ip.ss.ss_family, |
236 |
|
SOCK_STREAM, 0, "ident") == -1) |
237 |
|
{ |
238 |
< |
report_error(L_ALL, "creating auth stream socket %s:%s", |
239 |
< |
get_client_name(auth->client, SHOW_IP), errno); |
240 |
< |
ilog(L_ERROR, "Unable to create auth socket for %s", |
238 |
> |
report_error(L_ALL, "creating auth stream socket %s:%s", |
239 |
> |
get_client_name(auth->client, SHOW_IP), errno); |
240 |
> |
ilog(LOG_TYPE_IRCD, "Unable to create auth socket for %s", |
241 |
|
get_client_name(auth->client, SHOW_IP)); |
242 |
|
++ServerStats.is_abad; |
243 |
|
return 0; |
245 |
|
|
246 |
|
sendheader(auth->client, REPORT_DO_ID); |
247 |
|
|
248 |
< |
/* |
248 |
> |
/* |
249 |
|
* get the local address of the client and bind to that to |
250 |
|
* make the auth request. This used to be done only for |
251 |
|
* ifdef VIRTUAL_HOST, but needs to be done for all clients |
267 |
|
#endif |
268 |
|
localaddr.ss_port = htons(0); |
269 |
|
|
270 |
< |
comm_connect_tcp(&auth->fd, auth->client->sockhost, 113, |
271 |
< |
(struct sockaddr *)&localaddr, localaddr.ss_len, auth_connect_callback, |
272 |
< |
auth, auth->client->localClient->ip.ss.ss_family, |
270 |
> |
comm_connect_tcp(&auth->fd, auth->client->sockhost, RFC1413_PORT, |
271 |
> |
(struct sockaddr *)&localaddr, localaddr.ss_len, auth_connect_callback, |
272 |
> |
auth, auth->client->localClient->ip.ss.ss_family, |
273 |
|
GlobalSetOptions.ident_timeout); |
274 |
|
return 1; /* We suceed here for now */ |
275 |
|
} |
276 |
|
|
277 |
|
/* |
278 |
< |
* GetValidIdent - parse ident query reply from identd server |
292 |
< |
* |
293 |
< |
* Inputs - pointer to ident buf |
294 |
< |
* Output - NULL if no valid ident found, otherwise pointer to name |
295 |
< |
* Side effects - |
296 |
< |
*/ |
297 |
< |
/* |
298 |
< |
* A few questions have been asked about this mess, obviously |
299 |
< |
* it should have been commented better the first time. |
300 |
< |
* The original idea was to remove all references to libc from ircd-hybrid. |
301 |
< |
* Instead of having to write a replacement for sscanf(), I did a |
302 |
< |
* rather gruseome parser here so we could remove this function call. |
303 |
< |
* Note, that I had also removed a few floating point printfs as well (though |
304 |
< |
* now we are still stuck with a few...) |
305 |
< |
* Remember, we have a replacement ircd sprintf, we have bleeps fputs lib |
306 |
< |
* it would have been nice to remove some unneeded code. |
307 |
< |
* Oh well. If we don't remove libc stuff totally, then it would be |
308 |
< |
* far cleaner to use sscanf() |
309 |
< |
* |
310 |
< |
* - Dianora |
311 |
< |
*/ |
312 |
< |
static char * |
313 |
< |
GetValidIdent(char *buf) |
314 |
< |
{ |
315 |
< |
int remp = 0; |
316 |
< |
int locp = 0; |
317 |
< |
char* colon1Ptr; |
318 |
< |
char* colon2Ptr; |
319 |
< |
char* colon3Ptr; |
320 |
< |
char* commaPtr; |
321 |
< |
char* remotePortString; |
322 |
< |
|
323 |
< |
/* All this to get rid of a sscanf() fun. */ |
324 |
< |
remotePortString = buf; |
325 |
< |
|
326 |
< |
if ((colon1Ptr = strchr(remotePortString,':')) == NULL) |
327 |
< |
return 0; |
328 |
< |
*colon1Ptr = '\0'; |
329 |
< |
colon1Ptr++; |
330 |
< |
|
331 |
< |
if ((colon2Ptr = strchr(colon1Ptr,':')) == NULL) |
332 |
< |
return 0; |
333 |
< |
*colon2Ptr = '\0'; |
334 |
< |
colon2Ptr++; |
335 |
< |
|
336 |
< |
if ((commaPtr = strchr(remotePortString, ',')) == NULL) |
337 |
< |
return 0; |
338 |
< |
*commaPtr = '\0'; |
339 |
< |
commaPtr++; |
340 |
< |
|
341 |
< |
if ((remp = atoi(remotePortString)) == 0) |
342 |
< |
return 0; |
343 |
< |
|
344 |
< |
if ((locp = atoi(commaPtr)) == 0) |
345 |
< |
return 0; |
346 |
< |
|
347 |
< |
/* look for USERID bordered by first pair of colons */ |
348 |
< |
if (strstr(colon1Ptr, "USERID") == NULL) |
349 |
< |
return 0; |
350 |
< |
|
351 |
< |
if ((colon3Ptr = strchr(colon2Ptr,':')) == NULL) |
352 |
< |
return 0; |
353 |
< |
*colon3Ptr = '\0'; |
354 |
< |
colon3Ptr++; |
355 |
< |
return (colon3Ptr); |
356 |
< |
} |
357 |
< |
|
358 |
< |
/* |
359 |
< |
* start_auth |
278 |
> |
* start_auth |
279 |
|
* |
280 |
|
* inputs - pointer to client to auth |
281 |
|
* output - NONE |
282 |
|
* side effects - starts auth (identd) and dns queries for a client |
283 |
|
*/ |
284 |
< |
static void * |
285 |
< |
start_auth(va_list args) |
284 |
> |
void |
285 |
> |
start_auth(struct Client *client_p) |
286 |
|
{ |
368 |
– |
struct Client *client = va_arg(args, struct Client *); |
287 |
|
struct AuthRequest *auth = NULL; |
288 |
|
|
289 |
< |
assert(client != NULL); |
289 |
> |
assert(client_p); |
290 |
|
|
291 |
< |
auth = make_auth_request(client); |
292 |
< |
dlinkAdd(auth, &auth->node, &auth_doing_list); |
291 |
> |
auth = make_auth_request(client_p); |
292 |
> |
SetInAuth(auth); |
293 |
> |
dlinkAddTail(auth, &auth->node, &auth_pending_list); |
294 |
|
|
295 |
< |
sendheader(client, REPORT_DO_DNS); |
295 |
> |
sendheader(client_p, REPORT_DO_DNS); |
296 |
|
|
297 |
|
SetDNSPending(auth); |
298 |
|
|
299 |
< |
if (ConfigFileEntry.disable_auth == 0) |
299 |
> |
if (ConfigGeneral.disable_auth == 0) |
300 |
|
{ |
301 |
|
SetDoingAuth(auth); |
302 |
|
start_auth_query(auth); |
303 |
|
} |
304 |
|
|
305 |
< |
gethost_byaddr(auth_dns_callback, auth, &client->localClient->ip); |
387 |
< |
|
388 |
< |
return NULL; |
305 |
> |
gethost_byaddr(auth_dns_callback, auth, &client_p->localClient->ip); |
306 |
|
} |
307 |
|
|
308 |
|
/* |
312 |
|
static void |
313 |
|
timeout_auth_queries_event(void *notused) |
314 |
|
{ |
315 |
< |
dlink_node *ptr = NULL, *next_ptr = NULL; |
315 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
316 |
|
|
317 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, auth_doing_list.head) |
317 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, auth_pending_list.head) |
318 |
|
{ |
319 |
|
struct AuthRequest *auth = ptr->data; |
320 |
|
|
321 |
|
if (auth->timeout > CurrentTime) |
322 |
< |
continue; |
322 |
> |
break; |
323 |
|
|
324 |
|
if (IsDoingAuth(auth)) |
325 |
< |
{ |
325 |
> |
{ |
326 |
|
++ServerStats.is_abad; |
327 |
|
fd_close(&auth->fd); |
328 |
|
ClearAuth(auth); |
336 |
|
sendheader(auth->client, REPORT_FAIL_DNS); |
337 |
|
} |
338 |
|
|
339 |
< |
ilog(L_INFO, "DNS/AUTH timeout %s", |
339 |
> |
ilog(LOG_TYPE_IRCD, "DNS/AUTH timeout %s", |
340 |
|
get_client_name(auth->client, SHOW_IP)); |
341 |
|
release_auth_client(auth); |
342 |
|
} |
362 |
|
char authbuf[32]; |
363 |
|
socklen_t ulen = sizeof(struct irc_ssaddr); |
364 |
|
socklen_t tlen = sizeof(struct irc_ssaddr); |
365 |
< |
u_int16_t uport, tport; |
365 |
> |
uint16_t uport, tport; |
366 |
|
#ifdef IPV6 |
367 |
|
struct sockaddr_in6 *v6; |
368 |
|
#else |
375 |
|
return; |
376 |
|
} |
377 |
|
|
378 |
< |
if (getsockname(auth->client->localClient->fd.fd, (struct sockaddr *)&us, |
379 |
< |
&ulen) || |
463 |
< |
getpeername(auth->client->localClient->fd.fd, (struct sockaddr *)&them, |
464 |
< |
&tlen)) |
378 |
> |
if (getsockname(auth->client->localClient->fd.fd, (struct sockaddr *)&us, &ulen) || |
379 |
> |
getpeername(auth->client->localClient->fd.fd, (struct sockaddr *)&them, &tlen)) |
380 |
|
{ |
381 |
< |
ilog(L_INFO, "auth get{sock,peer}name error for %s", |
382 |
< |
get_client_name(auth->client, SHOW_IP)); |
381 |
> |
ilog(LOG_TYPE_IRCD, "auth get{sock,peer}name error for %s", |
382 |
> |
get_client_name(auth->client, SHOW_IP)); |
383 |
|
auth_error(auth); |
384 |
|
return; |
385 |
|
} |
399 |
|
us.ss_len = ulen; |
400 |
|
them.ss_len = tlen; |
401 |
|
#endif |
402 |
< |
|
403 |
< |
ircsprintf(authbuf, "%u , %u\r\n", tport, uport); |
402 |
> |
|
403 |
> |
snprintf(authbuf, sizeof(authbuf), "%u, %u\r\n", tport, uport); |
404 |
|
|
405 |
|
if (send(fd->fd, authbuf, strlen(authbuf), 0) == -1) |
406 |
|
{ |
408 |
|
return; |
409 |
|
} |
410 |
|
|
411 |
< |
read_auth_reply(&auth->fd, auth); |
411 |
> |
comm_setselect(fd, COMM_SELECT_READ, read_auth_reply, auth, 0); |
412 |
> |
} |
413 |
> |
|
414 |
> |
/** Enum used to index ident reply fields in a human-readable way. */ |
415 |
> |
enum IdentReplyFields |
416 |
> |
{ |
417 |
> |
IDENT_PORT_NUMBERS, |
418 |
> |
IDENT_REPLY_TYPE, |
419 |
> |
IDENT_OS_TYPE, |
420 |
> |
IDENT_INFO, |
421 |
> |
USERID_TOKEN_COUNT |
422 |
> |
}; |
423 |
> |
|
424 |
> |
/** Parse an ident reply line and extract the userid from it. |
425 |
> |
* \param reply The ident reply line. |
426 |
> |
* \return The userid, or NULL on parse failure. |
427 |
> |
*/ |
428 |
> |
static const char * |
429 |
> |
check_ident_reply(char *reply) |
430 |
> |
{ |
431 |
> |
char *token = NULL, *end = NULL; |
432 |
> |
char *vector[USERID_TOKEN_COUNT]; |
433 |
> |
int count = token_vector(reply, ':', vector, USERID_TOKEN_COUNT); |
434 |
> |
|
435 |
> |
if (USERID_TOKEN_COUNT != count) |
436 |
> |
return NULL; |
437 |
> |
|
438 |
> |
/* |
439 |
> |
* Second token is the reply type |
440 |
> |
*/ |
441 |
> |
token = vector[IDENT_REPLY_TYPE]; |
442 |
> |
|
443 |
> |
if (EmptyString(token)) |
444 |
> |
return NULL; |
445 |
> |
|
446 |
> |
while (IsSpace(*token)) |
447 |
> |
++token; |
448 |
> |
|
449 |
> |
if (strncmp(token, "USERID", 6)) |
450 |
> |
return NULL; |
451 |
> |
|
452 |
> |
/* |
453 |
> |
* Third token is the os type |
454 |
> |
*/ |
455 |
> |
token = vector[IDENT_OS_TYPE]; |
456 |
> |
|
457 |
> |
if (EmptyString(token)) |
458 |
> |
return NULL; |
459 |
> |
|
460 |
> |
while (IsSpace(*token)) |
461 |
> |
++token; |
462 |
> |
|
463 |
> |
/* |
464 |
> |
* Unless "OTHER" is specified as the operating system type, the server |
465 |
> |
* is expected to return the "normal" user identification of the owner |
466 |
> |
* of this connection. "Normal" in this context may be taken to mean a |
467 |
> |
* string of characters which uniquely identifies the connection owner |
468 |
> |
* such as a user identifier assigned by the system administrator and |
469 |
> |
* used by such user as a mail identifier, or as the "user" part of a |
470 |
> |
* user/password pair used to gain access to system resources. When an |
471 |
> |
* operating system is specified (e.g., anything but "OTHER"), the user |
472 |
> |
* identifier is expected to be in a more or less immediately useful |
473 |
> |
* form - e.g., something that could be used as an argument to "finger" |
474 |
> |
* or as a mail address. |
475 |
> |
*/ |
476 |
> |
if (!strncmp(token, "OTHER", 5)) |
477 |
> |
return NULL; |
478 |
> |
|
479 |
> |
/* |
480 |
> |
* Fourth token is the username |
481 |
> |
*/ |
482 |
> |
token = vector[IDENT_INFO]; |
483 |
> |
|
484 |
> |
if (EmptyString(token)) |
485 |
> |
return NULL; |
486 |
> |
|
487 |
> |
while (IsSpace(*token)) |
488 |
> |
++token; |
489 |
> |
|
490 |
> |
while (*token == '~' || *token == '^') |
491 |
> |
++token; |
492 |
> |
|
493 |
> |
/* |
494 |
> |
* Look for the end of the username, terminators are '\0, @, <SPACE>, :' |
495 |
> |
*/ |
496 |
> |
for (end = token; *end; ++end) |
497 |
> |
if (IsSpace(*end) || '@' == *end || ':' == *end) |
498 |
> |
break; |
499 |
> |
*end = '\0'; |
500 |
> |
|
501 |
> |
return token; |
502 |
|
} |
503 |
|
|
504 |
|
/* |
505 |
< |
* read_auth_reply - read the reply (if any) from the ident server |
505 |
> |
* read_auth_reply - read the reply (if any) from the ident server |
506 |
|
* we connected to. |
507 |
|
* We only give it one shot, if the reply isn't good the first time |
508 |
|
* fail the authentication entirely. --Bleep |
509 |
|
*/ |
505 |
– |
#define AUTH_BUFSIZ 128 |
506 |
– |
|
510 |
|
static void |
511 |
|
read_auth_reply(fde_t *fd, void *data) |
512 |
|
{ |
513 |
|
struct AuthRequest *auth = data; |
514 |
< |
char *s = NULL; |
515 |
< |
char *t = NULL; |
516 |
< |
int len; |
514 |
< |
int count; |
515 |
< |
char buf[AUTH_BUFSIZ + 1]; /* buffer to read auth reply into */ |
516 |
< |
|
517 |
< |
/* Why? |
518 |
< |
* Well, recv() on many POSIX systems is a per-packet operation, |
519 |
< |
* and we do not necessarily want this, because on lowspec machines, |
520 |
< |
* the ident response may come back fragmented, thus resulting in an |
521 |
< |
* invalid ident response, even if the ident response was really OK. |
522 |
< |
* |
523 |
< |
* So PLEASE do not change this code to recv without being aware of the |
524 |
< |
* consequences. |
525 |
< |
* |
526 |
< |
* --nenolod |
527 |
< |
*/ |
528 |
< |
len = read(fd->fd, buf, AUTH_BUFSIZ); |
529 |
< |
|
530 |
< |
if (len < 0) |
531 |
< |
{ |
532 |
< |
if (ignoreErrno(errno)) |
533 |
< |
comm_setselect(fd, COMM_SELECT_READ, read_auth_reply, auth, 0); |
534 |
< |
else |
535 |
< |
auth_error(auth); |
536 |
< |
return; |
537 |
< |
} |
514 |
> |
const char *username = NULL; |
515 |
> |
ssize_t len = 0; |
516 |
> |
char buf[RFC1413_BUFSIZ + 1]; |
517 |
|
|
518 |
< |
if (len > 0) |
518 |
> |
if ((len = recv(fd->fd, buf, RFC1413_BUFSIZ, 0)) > 0) |
519 |
|
{ |
520 |
|
buf[len] = '\0'; |
521 |
< |
|
543 |
< |
if ((s = GetValidIdent(buf))) |
544 |
< |
{ |
545 |
< |
t = auth->client->username; |
546 |
< |
|
547 |
< |
while (*s == '~' || *s == '^') |
548 |
< |
s++; |
549 |
< |
|
550 |
< |
for (count = USERLEN; *s && count; s++) |
551 |
< |
{ |
552 |
< |
if (*s == '@') |
553 |
< |
break; |
554 |
< |
if (!IsSpace(*s) && *s != ':' && *s != '[') |
555 |
< |
{ |
556 |
< |
*t++ = *s; |
557 |
< |
count--; |
558 |
< |
} |
559 |
< |
} |
560 |
< |
|
561 |
< |
*t = '\0'; |
562 |
< |
} |
521 |
> |
username = check_ident_reply(buf); |
522 |
|
} |
523 |
|
|
524 |
|
fd_close(fd); |
525 |
|
|
526 |
|
ClearAuth(auth); |
527 |
|
|
528 |
< |
if (s == NULL) |
528 |
> |
if (EmptyString(username)) |
529 |
|
{ |
530 |
|
sendheader(auth->client, REPORT_FAIL_ID); |
531 |
|
++ServerStats.is_abad; |
532 |
|
} |
533 |
|
else |
534 |
|
{ |
535 |
+ |
strlcpy(auth->client->username, username, sizeof(auth->client->username)); |
536 |
|
sendheader(auth->client, REPORT_FIN_ID); |
537 |
|
++ServerStats.is_asuc; |
538 |
|
SetGotId(auth->client); |
544 |
|
/* |
545 |
|
* delete_auth() |
546 |
|
*/ |
547 |
< |
void |
547 |
> |
void |
548 |
|
delete_auth(struct AuthRequest *auth) |
549 |
|
{ |
550 |
|
if (IsDNSPending(auth)) |
553 |
|
if (IsDoingAuth(auth)) |
554 |
|
fd_close(&auth->fd); |
555 |
|
|
556 |
< |
dlinkDelete(&auth->node, &auth_doing_list); |
557 |
< |
BlockHeapFree(auth_heap, auth); |
556 |
> |
if (IsInAuth(auth)) |
557 |
> |
{ |
558 |
> |
dlinkDelete(&auth->node, &auth_pending_list); |
559 |
> |
ClearInAuth(auth); |
560 |
> |
} |
561 |
> |
} |
562 |
> |
|
563 |
> |
/* auth_init |
564 |
> |
* |
565 |
> |
* Initialise the auth code |
566 |
> |
*/ |
567 |
> |
void |
568 |
> |
auth_init(void) |
569 |
> |
{ |
570 |
> |
static struct event timeout_auth_queries = |
571 |
> |
{ |
572 |
> |
.name = "timeout_auth_queries_event", |
573 |
> |
.handler = timeout_auth_queries_event, |
574 |
> |
.when = 1 |
575 |
> |
}; |
576 |
> |
|
577 |
> |
event_add(&timeout_auth_queries, NULL); |
578 |
|
} |