ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/auth.c
(Generate patch)

Comparing:
ircd-hybrid-7.3/src/s_auth.c (file contents), Revision 1124 by michael, Mon Feb 7 11:45:27 2011 UTC vs.
ircd-hybrid/trunk/src/auth.c (file contents), Revision 4588 by michael, Tue Aug 26 15:59:07 2014 UTC

# Line 1 | Line 1
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
# Line 16 | Line 15
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 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
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   /*
# Line 32 | Line 34
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 "ircd.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,
# Line 74 | Line 77 | enum {
77    REPORT_HOST_TOOLONG
78   };
79  
80 < #define sendheader(c, i) sendto_one((c), HeaderMessages[(i)], me.name)
78 <
79 < static BlockHeap *auth_heap = NULL;
80 < static dlink_list auth_doing_list = { NULL, NULL, 0 };
80 > #define sendheader(c, i) sendto_one_notice((c), &me, HeaderMessages[(i)])
81  
82 < static EVH timeout_auth_queries_event;
82 > static dlink_list auth_pending_list;
83 > static void read_auth_reply(fde_t *, void *);
84 > static void auth_connect_callback(fde_t *, int, void *);
85  
84 static PF read_auth_reply;
85 static CNCB auth_connect_callback;
86 static CBFUNC start_auth;
87
88 struct Callback *auth_cb = NULL;
89
90 /* init_auth()
91 *
92 * Initialise the auth code
93 */
94 void
95 init_auth(void)
96 {
97  auth_heap = BlockHeapCreate("auth", sizeof(struct AuthRequest), AUTH_HEAP_SIZE);
98  auth_cb = register_callback("start_auth", start_auth);
99  eventAddIsh("timeout_auth_queries_event", timeout_auth_queries_event, NULL, 1);
100 }
86  
87   /*
88   * make_auth_request - allocate a new auth request
# Line 105 | Line 90 | init_auth(void)
90   static struct AuthRequest *
91   make_auth_request(struct Client *client)
92   {
93 <  struct AuthRequest *request = BlockHeapAlloc(auth_heap);
93 >  struct AuthRequest *request = &client->connection->auth;
94 >
95 >  memset(request, 0, sizeof(*request));
96  
97 <  client->localClient->auth = request;
98 <  request->client           = client;
112 <  request->timeout          = CurrentTime + CONNECTTIMEOUT;
97 >  request->client  = client;
98 >  request->timeout = CurrentTime + CONNECTTIMEOUT;
99  
100    return request;
101   }
# Line 127 | Line 113 | release_auth_client(struct AuthRequest *
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
124     * us. This is what read_packet() does.
125     *     -- adrian
126     */
127 <  client->localClient->allow_read = MAX_FLOOD;
128 <  comm_setflush(&client->localClient->fd, 1000, flood_recalc, client);
127 >  client->connection->allow_read = MAX_FLOOD;
128 >  comm_setflush(&client->connection->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->connection->since     = CurrentTime;
131 >  client->connection->lasttime  = CurrentTime;
132 >  client->connection->firsttime = CurrentTime;
133    client->flags |= FLAGS_FINISHED_AUTH;
134  
135 <  read_packet(&client->localClient->fd, client);
135 >  read_packet(&client->connection->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
# Line 155 | Line 143 | release_auth_client(struct AuthRequest *
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;
167 #ifdef IPV6
155      const struct sockaddr_in6 *v6, *v6dns;
169 #endif
170    int good = 1;
156  
157 < #ifdef IPV6
173 <    if (auth->client->localClient->ip.ss.ss_family == AF_INET6)
157 >    if (auth->client->connection->ip.ss.ss_family == AF_INET6)
158      {
159 <      v6 = (const struct sockaddr_in6 *)&auth->client->localClient->ip;
159 >      v6 = (const struct sockaddr_in6 *)&auth->client->connection->ip;
160        v6dns = (const struct sockaddr_in6 *)addr;
161 +
162        if (memcmp(&v6->sin6_addr, &v6dns->sin6_addr, sizeof(struct in6_addr)) != 0)
163        {
164          sendheader(auth->client, REPORT_IP_MISMATCH);
165 <        good = 0;
165 >        release_auth_client(auth);
166 >        return;
167        }
168      }
169      else
184 #endif
170      {
171 <      v4 = (const struct sockaddr_in *)&auth->client->localClient->ip;
171 >      v4 = (const struct sockaddr_in *)&auth->client->connection->ip;
172        v4dns = (const struct sockaddr_in *)addr;
173 <      if(v4->sin_addr.s_addr != v4dns->sin_addr.s_addr)
173 >
174 >      if (v4->sin_addr.s_addr != v4dns->sin_addr.s_addr)
175        {
176          sendheader(auth->client, REPORT_IP_MISMATCH);
177 <        good = 0;
177 >        release_auth_client(auth);
178 >        return;
179        }
180      }
181 <    if (good && strlen(name) <= HOSTLEN)
181 >
182 >    if (namelength > HOSTLEN)
183 >      sendheader(auth->client, REPORT_HOST_TOOLONG);
184 >    else
185      {
186 <      strlcpy(auth->client->host, name,
197 <              sizeof(auth->client->host));
186 >      strlcpy(auth->client->host, name, sizeof(auth->client->host));
187        sendheader(auth->client, REPORT_FIN_DNS);
188      }
200    else if (strlen(name) > HOSTLEN)
201      sendheader(auth->client, REPORT_HOST_TOOLONG);
189    }
190    else
191      sendheader(auth->client, REPORT_FAIL_DNS);
# Line 224 | Line 211 | auth_error(struct AuthRequest *auth)
211   }
212  
213   /*
214 < * start_auth_query - Flag the client to show that an attempt to
214 > * start_auth_query - Flag the client to show that an attempt to
215   * contact the ident server on
216   * the client's host.  The connect and subsequently the socket are all put
217   * into 'non-blocking' mode.  Should the connect or any later phase of the
# Line 236 | Line 223 | start_auth_query(struct AuthRequest *aut
223   {
224    struct irc_ssaddr localaddr;
225    socklen_t locallen = sizeof(struct irc_ssaddr);
239 #ifdef IPV6
226    struct sockaddr_in6 *v6;
241 #else
242  struct sockaddr_in *v4;
243 #endif
227  
228    /* open a socket of the same type as the client socket */
229 <  if (comm_open(&auth->fd, auth->client->localClient->ip.ss.ss_family,
229 >  if (comm_open(&auth->fd, auth->client->connection->ip.ss.ss_family,
230                  SOCK_STREAM, 0, "ident") == -1)
231    {
232 <    report_error(L_ALL, "creating auth stream socket %s:%s",
233 <        get_client_name(auth->client, SHOW_IP), errno);
234 <    ilog(L_ERROR, "Unable to create auth socket for %s",
232 >    report_error(L_ALL, "creating auth stream socket %s:%s",
233 >                 get_client_name(auth->client, SHOW_IP), errno);
234 >    ilog(LOG_TYPE_IRCD, "Unable to create auth socket for %s",
235          get_client_name(auth->client, SHOW_IP));
236      ++ServerStats.is_abad;
237      return 0;
# Line 256 | Line 239 | start_auth_query(struct AuthRequest *aut
239  
240    sendheader(auth->client, REPORT_DO_ID);
241  
242 <  /*
242 >  /*
243     * get the local address of the client and bind to that to
244     * make the auth request.  This used to be done only for
245     * ifdef VIRTUAL_HOST, but needs to be done for all clients
# Line 264 | Line 247 | start_auth_query(struct AuthRequest *aut
247     * and machines with multiple IP addresses are common now
248     */
249    memset(&localaddr, 0, locallen);
250 <  getsockname(auth->client->localClient->fd.fd, (struct sockaddr*)&localaddr,
250 >  getsockname(auth->client->connection->fd.fd, (struct sockaddr*)&localaddr,
251        &locallen);
252  
270 #ifdef IPV6
253    remove_ipv6_mapping(&localaddr);
254    v6 = (struct sockaddr_in6 *)&localaddr;
255    v6->sin6_port = htons(0);
274 #else
275  localaddr.ss_len = locallen;
276  v4 = (struct sockaddr_in *)&localaddr;
277  v4->sin_port = htons(0);
278 #endif
256    localaddr.ss_port = htons(0);
257  
258 <  comm_connect_tcp(&auth->fd, auth->client->sockhost, 113,
259 <      (struct sockaddr *)&localaddr, localaddr.ss_len, auth_connect_callback,
260 <      auth, auth->client->localClient->ip.ss.ss_family,
258 >  comm_connect_tcp(&auth->fd, auth->client->sockhost, RFC1413_PORT,
259 >      (struct sockaddr *)&localaddr, localaddr.ss_len, auth_connect_callback,
260 >      auth, auth->client->connection->ip.ss.ss_family,
261        GlobalSetOptions.ident_timeout);
262    return 1; /* We suceed here for now */
263   }
264  
265   /*
266 < * GetValidIdent - parse ident query reply from identd server
290 < *
291 < * Inputs        - pointer to ident buf
292 < * Output        - NULL if no valid ident found, otherwise pointer to name
293 < * Side effects  -
294 < */
295 < /*
296 < * A few questions have been asked about this mess, obviously
297 < * it should have been commented better the first time.
298 < * The original idea was to remove all references to libc from ircd-hybrid.
299 < * Instead of having to write a replacement for sscanf(), I did a
300 < * rather gruseome parser here so we could remove this function call.
301 < * Note, that I had also removed a few floating point printfs as well (though
302 < * now we are still stuck with a few...)
303 < * Remember, we have a replacement ircd sprintf, we have bleeps fputs lib
304 < * it would have been nice to remove some unneeded code.
305 < * Oh well. If we don't remove libc stuff totally, then it would be
306 < * far cleaner to use sscanf()
307 < *
308 < * - Dianora
309 < */
310 < static char *
311 < GetValidIdent(char *buf)
312 < {
313 <  int   remp = 0;
314 <  int   locp = 0;
315 <  char* colon1Ptr;
316 <  char* colon2Ptr;
317 <  char* colon3Ptr;
318 <  char* commaPtr;
319 <  char* remotePortString;
320 <
321 <  /* All this to get rid of a sscanf() fun. */
322 <  remotePortString = buf;
323 <  
324 <  if ((colon1Ptr = strchr(remotePortString,':')) == NULL)
325 <    return 0;
326 <  *colon1Ptr = '\0';
327 <  colon1Ptr++;
328 <
329 <  if ((colon2Ptr = strchr(colon1Ptr,':')) == NULL)
330 <    return 0;
331 <  *colon2Ptr = '\0';
332 <  colon2Ptr++;
333 <  
334 <  if ((commaPtr = strchr(remotePortString, ',')) == NULL)
335 <    return 0;
336 <  *commaPtr = '\0';
337 <  commaPtr++;
338 <
339 <  if ((remp = atoi(remotePortString)) == 0)
340 <    return 0;
341 <              
342 <  if ((locp = atoi(commaPtr)) == 0)
343 <    return 0;
344 <
345 <  /* look for USERID bordered by first pair of colons */
346 <  if (strstr(colon1Ptr, "USERID") == NULL)
347 <    return 0;
348 <
349 <  if ((colon3Ptr = strchr(colon2Ptr,':')) == NULL)
350 <    return 0;
351 <  *colon3Ptr = '\0';
352 <  colon3Ptr++;
353 <  return (colon3Ptr);
354 < }
355 <
356 < /*
357 < * start_auth
266 > * start_auth
267   *
268   * inputs       - pointer to client to auth
269   * output       - NONE
270   * side effects - starts auth (identd) and dns queries for a client
271   */
272 < static void *
273 < start_auth(va_list args)
272 > void
273 > start_auth(struct Client *client_p)
274   {
366  struct Client *client = va_arg(args, struct Client *);
275    struct AuthRequest *auth = NULL;
276  
277 <  assert(client != NULL);
277 >  assert(client_p);
278  
279 <  auth = make_auth_request(client);
280 <  dlinkAdd(auth, &auth->node, &auth_doing_list);
279 >  auth = make_auth_request(client_p);
280 >  SetInAuth(auth);
281 >  dlinkAddTail(auth, &auth->node, &auth_pending_list);
282  
283 <  sendheader(client, REPORT_DO_DNS);
283 >  sendheader(client_p, REPORT_DO_DNS);
284  
285    SetDNSPending(auth);
286  
287 <  if (ConfigFileEntry.disable_auth == 0)
287 >  if (ConfigGeneral.disable_auth == 0)
288    {
289      SetDoingAuth(auth);
290      start_auth_query(auth);
291    }
292  
293 <  gethost_byaddr(auth_dns_callback, auth, &client->localClient->ip);
385 <
386 <  return NULL;
293 >  gethost_byaddr(auth_dns_callback, auth, &client_p->connection->ip);
294   }
295  
296   /*
# Line 393 | Line 300 | start_auth(va_list args)
300   static void
301   timeout_auth_queries_event(void *notused)
302   {
303 <  dlink_node *ptr = NULL, *next_ptr = NULL;
303 >  dlink_node *ptr = NULL, *ptr_next = NULL;
304  
305 <  DLINK_FOREACH_SAFE(ptr, next_ptr, auth_doing_list.head)
305 >  DLINK_FOREACH_SAFE(ptr, ptr_next, auth_pending_list.head)
306    {
307      struct AuthRequest *auth = ptr->data;
308  
309      if (auth->timeout > CurrentTime)
310 <      continue;
310 >      break;
311  
312      if (IsDoingAuth(auth))
313 <    {  
313 >    {
314        ++ServerStats.is_abad;
315        fd_close(&auth->fd);
316        ClearAuth(auth);
# Line 417 | Line 324 | timeout_auth_queries_event(void *notused
324        sendheader(auth->client, REPORT_FAIL_DNS);
325      }
326  
327 <    ilog(L_INFO, "DNS/AUTH timeout %s",
327 >    ilog(LOG_TYPE_IRCD, "DNS/AUTH timeout %s",
328           get_client_name(auth->client, SHOW_IP));
329      release_auth_client(auth);
330    }
# Line 444 | Line 351 | auth_connect_callback(fde_t *fd, int err
351    socklen_t ulen = sizeof(struct irc_ssaddr);
352    socklen_t tlen = sizeof(struct irc_ssaddr);
353    uint16_t uport, tport;
447 #ifdef IPV6
354    struct sockaddr_in6 *v6;
449 #else
450  struct sockaddr_in *v4;
451 #endif
355  
356    if (error != COMM_OK)
357    {
# Line 456 | Line 359 | auth_connect_callback(fde_t *fd, int err
359      return;
360    }
361  
362 <  if (getsockname(auth->client->localClient->fd.fd, (struct sockaddr *)&us,
363 <      &ulen) ||
461 <      getpeername(auth->client->localClient->fd.fd, (struct sockaddr *)&them,
462 <      &tlen))
362 >  if (getsockname(auth->client->connection->fd.fd, (struct sockaddr *)&us, &ulen) ||
363 >      getpeername(auth->client->connection->fd.fd, (struct sockaddr *)&them, &tlen))
364    {
365 <    ilog(L_INFO, "auth get{sock,peer}name error for %s",
366 <        get_client_name(auth->client, SHOW_IP));
365 >    ilog(LOG_TYPE_IRCD, "auth get{sock,peer}name error for %s",
366 >         get_client_name(auth->client, SHOW_IP));
367      auth_error(auth);
368      return;
369    }
370  
470 #ifdef IPV6
371    v6 = (struct sockaddr_in6 *)&us;
372    uport = ntohs(v6->sin6_port);
373    v6 = (struct sockaddr_in6 *)&them;
374    tport = ntohs(v6->sin6_port);
375    remove_ipv6_mapping(&us);
376    remove_ipv6_mapping(&them);
377 < #else
378 <  v4 = (struct sockaddr_in *)&us;
479 <  uport = ntohs(v4->sin_port);
480 <  v4 = (struct sockaddr_in *)&them;
481 <  tport = ntohs(v4->sin_port);
482 <  us.ss_len = ulen;
483 <  them.ss_len = tlen;
484 < #endif
485 <  
486 <  snprintf(authbuf, sizeof(authbuf), "%u , %u\r\n", tport, uport);
377 >
378 >  snprintf(authbuf, sizeof(authbuf), "%u, %u\r\n", tport, uport);
379  
380    if (send(fd->fd, authbuf, strlen(authbuf), 0) == -1)
381    {
# Line 491 | Line 383 | auth_connect_callback(fde_t *fd, int err
383      return;
384    }
385  
386 <  read_auth_reply(&auth->fd, auth);
386 >  comm_setselect(fd, COMM_SELECT_READ, read_auth_reply, auth, 0);
387 > }
388 >
389 > /** Enum used to index ident reply fields in a human-readable way. */
390 > enum IdentReplyFields
391 > {
392 >  IDENT_PORT_NUMBERS,
393 >  IDENT_REPLY_TYPE,
394 >  IDENT_OS_TYPE,
395 >  IDENT_INFO,
396 >  USERID_TOKEN_COUNT
397 > };
398 >
399 > /** Parse an ident reply line and extract the userid from it.
400 > * \param reply The ident reply line.
401 > * \return The userid, or NULL on parse failure.
402 > */
403 > static const char *
404 > check_ident_reply(char *reply)
405 > {
406 >  char *token = NULL, *end = NULL;
407 >  char *vector[USERID_TOKEN_COUNT];
408 >  int count = token_vector(reply, ':', vector, USERID_TOKEN_COUNT);
409 >
410 >  if (USERID_TOKEN_COUNT != count)
411 >    return NULL;
412 >
413 >  /*
414 >   * Second token is the reply type
415 >   */
416 >  token = vector[IDENT_REPLY_TYPE];
417 >
418 >  if (EmptyString(token))
419 >    return NULL;
420 >
421 >  while (IsSpace(*token))
422 >    ++token;
423 >
424 >  if (strncmp(token, "USERID", 6))
425 >    return NULL;
426 >
427 >  /*
428 >   * Third token is the os type
429 >   */
430 >  token = vector[IDENT_OS_TYPE];
431 >
432 >  if (EmptyString(token))
433 >    return NULL;
434 >
435 >  while (IsSpace(*token))
436 >   ++token;
437 >
438 >  /*
439 >   * Unless "OTHER" is specified as the operating system type, the server
440 >   * is expected to return the "normal" user identification of the owner
441 >   * of this connection. "Normal" in this context may be taken to mean a
442 >   * string of characters which uniquely identifies the connection owner
443 >   * such as a user identifier assigned by the system administrator and
444 >   * used by such user as a mail identifier, or as the "user" part of a
445 >   * user/password pair used to gain access to system resources. When an
446 >   * operating system is specified (e.g., anything but "OTHER"), the user
447 >   * identifier is expected to be in a more or less immediately useful
448 >   * form - e.g., something that could be used as an argument to "finger"
449 >   * or as a mail address.
450 >   */
451 >  if (!strncmp(token, "OTHER", 5))
452 >    return NULL;
453 >
454 >  /*
455 >   * Fourth token is the username
456 >   */
457 >  token = vector[IDENT_INFO];
458 >
459 >  if (EmptyString(token))
460 >    return NULL;
461 >
462 >  while (IsSpace(*token))
463 >    ++token;
464 >
465 >  while (*token == '~' || *token == '^')
466 >    ++token;
467 >
468 >  /*
469 >   * Look for the end of the username, terminators are '\0, @, <SPACE>, :'
470 >   */
471 >  for (end = token; *end; ++end)
472 >    if (IsSpace(*end) || '@' == *end || ':' == *end)
473 >      break;
474 >  *end = '\0';
475 >
476 >  return token;
477   }
478  
479   /*
480 < * read_auth_reply - read the reply (if any) from the ident server
480 > * read_auth_reply - read the reply (if any) from the ident server
481   * we connected to.
482   * We only give it one shot, if the reply isn't good the first time
483   * fail the authentication entirely. --Bleep
484   */
503 #define AUTH_BUFSIZ 128
504
485   static void
486   read_auth_reply(fde_t *fd, void *data)
487   {
488    struct AuthRequest *auth = data;
489 <  char *s = NULL;
490 <  char *t = NULL;
491 <  int len;
512 <  int count;
513 <  char buf[AUTH_BUFSIZ + 1]; /* buffer to read auth reply into */
514 <
515 <  /* Why?
516 <   * Well, recv() on many POSIX systems is a per-packet operation,
517 <   * and we do not necessarily want this, because on lowspec machines,
518 <   * the ident response may come back fragmented, thus resulting in an
519 <   * invalid ident response, even if the ident response was really OK.
520 <   *
521 <   * So PLEASE do not change this code to recv without being aware of the
522 <   * consequences.
523 <   *
524 <   *    --nenolod
525 <   */
526 <  len = read(fd->fd, buf, AUTH_BUFSIZ);
489 >  const char *username = NULL;
490 >  ssize_t len = 0;
491 >  char buf[RFC1413_BUFSIZ + 1];
492  
493 <  if (len < 0)
529 <  {
530 <    if (ignoreErrno(errno))
531 <      comm_setselect(fd, COMM_SELECT_READ, read_auth_reply, auth, 0);
532 <    else
533 <      auth_error(auth);
534 <    return;
535 <  }
536 <
537 <  if (len > 0)
493 >  if ((len = recv(fd->fd, buf, RFC1413_BUFSIZ, 0)) > 0)
494    {
495      buf[len] = '\0';
496 <
541 <    if ((s = GetValidIdent(buf)))
542 <    {
543 <      t = auth->client->username;
544 <
545 <      while (*s == '~' || *s == '^')
546 <        s++;
547 <
548 <      for (count = USERLEN; *s && count; s++)
549 <      {
550 <        if (*s == '@')
551 <          break;
552 <        if (!IsSpace(*s) && *s != ':' && *s != '[')
553 <        {
554 <          *t++ = *s;
555 <          count--;
556 <        }
557 <      }
558 <
559 <      *t = '\0';
560 <    }
496 >    username = check_ident_reply(buf);
497    }
498  
499    fd_close(fd);
500  
501    ClearAuth(auth);
502  
503 <  if (s == NULL)
503 >  if (EmptyString(username))
504    {
505      sendheader(auth->client, REPORT_FAIL_ID);
506      ++ServerStats.is_abad;
507    }
508    else
509    {
510 +    strlcpy(auth->client->username, username, sizeof(auth->client->username));
511      sendheader(auth->client, REPORT_FIN_ID);
512      ++ServerStats.is_asuc;
513      SetGotId(auth->client);
# Line 582 | Line 519 | read_auth_reply(fde_t *fd, void *data)
519   /*
520   * delete_auth()
521   */
522 < void
522 > void
523   delete_auth(struct AuthRequest *auth)
524   {
525    if (IsDNSPending(auth))
# Line 591 | Line 528 | delete_auth(struct AuthRequest *auth)
528    if (IsDoingAuth(auth))
529      fd_close(&auth->fd);
530  
531 <  dlinkDelete(&auth->node, &auth_doing_list);
532 <  BlockHeapFree(auth_heap, auth);
531 >  if (IsInAuth(auth))
532 >  {
533 >    dlinkDelete(&auth->node, &auth_pending_list);
534 >    ClearInAuth(auth);
535 >  }
536 > }
537 >
538 > /* auth_init
539 > *
540 > * Initialise the auth code
541 > */
542 > void
543 > auth_init(void)
544 > {
545 >  static struct event timeout_auth_queries =
546 >  {
547 >    .name = "timeout_auth_queries_event",
548 >    .handler = timeout_auth_queries_event,
549 >    .when = 1
550 >  };
551 >
552 >  event_add(&timeout_auth_queries, NULL);
553   }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)