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-8/src/s_auth.c (file contents), Revision 1309 by michael, Sun Mar 25 11:24:18 2012 UTC vs.
ircd-hybrid/trunk/src/auth.c (file contents), Revision 7668 by michael, Wed Jul 20 17:09:49 2016 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-2016 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 37 | Line 39
39   #include "list.h"
40   #include "ircd_defs.h"
41   #include "fdlist.h"
42 < #include "s_auth.h"
42 > #include "auth.h"
43   #include "conf.h"
42 #include "balloc.h"
44   #include "client.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 "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...",
57 <  ":%s NOTICE AUTH :*** Found your hostname",
58 <  ":%s NOTICE AUTH :*** Couldn't look up your hostname",
59 <  ":%s NOTICE AUTH :*** Checking Ident",
60 <  ":%s NOTICE AUTH :*** Got Ident response",
61 <  ":%s NOTICE AUTH :*** No Ident response",
62 <  ":%s NOTICE AUTH :*** Your forward and reverse DNS do not match, ignoring hostname.",
63 <  ":%s NOTICE AUTH :*** Your hostname is too long, ignoring hostname"
64 < };
65 <
66 < enum {
56 > enum
57 > {
58    REPORT_DO_DNS,
59    REPORT_FIN_DNS,
60    REPORT_FAIL_DNS,
# Line 74 | Line 65 | enum {
65    REPORT_HOST_TOOLONG
66   };
67  
68 < #define sendheader(c, i) sendto_one((c), HeaderMessages[(i)], me.name)
69 <
70 < static BlockHeap *auth_heap = NULL;
71 < static dlink_list auth_doing_list = { NULL, NULL, 0 };
72 <
73 < static EVH timeout_auth_queries_event;
68 > static const char *const HeaderMessages[] =
69 > {
70 >  [REPORT_DO_DNS] = ":*** Looking up your hostname",
71 >  [REPORT_FIN_DNS] = ":*** Found your hostname",
72 >  [REPORT_FAIL_DNS] = ":*** Couldn't look up your hostname",
73 >  [REPORT_DO_ID] = ":*** Checking Ident",
74 >  [REPORT_FIN_ID] = ":*** Got Ident response",
75 >  [REPORT_FAIL_ID] = ":*** No Ident response",
76 >  [REPORT_IP_MISMATCH] = ":*** Your forward and reverse DNS do not match, ignoring hostname",
77 >  [REPORT_HOST_TOOLONG] = ":*** Your hostname is too long, ignoring hostname"
78 > };
79  
80 < static PF read_auth_reply;
85 < static CNCB auth_connect_callback;
86 < static CBFUNC start_auth;
80 > #define sendheader(c, i) sendto_one_notice((c), &me, "%s", HeaderMessages[(i)])
81  
82 < struct Callback *auth_cb = NULL;
82 > static dlink_list auth_list;
83 > static void read_auth_reply(fde_t *, void *);
84 > static void auth_connect_callback(fde_t *, int, void *);
85  
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 *const auth = &client->connection->auth;
94 >
95 >  memset(auth, 0, sizeof(*auth));
96  
97 <  client->localClient->auth = request;
98 <  request->client           = client;
112 <  request->timeout          = CurrentTime + CONNECTTIMEOUT;
97 >  auth->client = client;
98 >  auth->timeout = CurrentTime + CONNECTTIMEOUT;
99  
100 <  return request;
100 >  return auth;
101   }
102  
103   /*
# Line 122 | Line 108 | make_auth_request(struct Client *client)
108   void
109   release_auth_client(struct AuthRequest *auth)
110   {
111 <  struct Client *client = auth->client;
111 >  struct Client *const client = auth->client;
112  
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_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);
141 <
142 <  dlinkAdd(client, &client->node, &global_client_list);
127 >  client->connection->allow_read = MAX_FLOOD;
128 >  comm_setflush(&client->connection->fd, 1000, flood_recalc, client);
129  
130 <  client->localClient->since     = CurrentTime;
131 <  client->localClient->lasttime  = CurrentTime;
132 <  client->localClient->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 157 | 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;
148 >  struct AuthRequest *const auth = vptr;
149  
150    ClearDNSPending(auth);
151  
152 <  if (name != NULL)
152 >  if (!EmptyString(name))
153    {
154 <    const struct sockaddr_in *v4, *v4dns;
169 < #ifdef IPV6
170 <    const struct sockaddr_in6 *v6, *v6dns;
171 < #endif
172 <    int good = 1;
173 <
174 < #ifdef IPV6
175 <    if (auth->client->localClient->ip.ss.ss_family == AF_INET6)
154 >    if (auth->client->connection->ip.ss.ss_family == AF_INET6)
155      {
156 <      v6 = (const struct sockaddr_in6 *)&auth->client->localClient->ip;
157 <      v6dns = (const struct sockaddr_in6 *)addr;
158 <      if (memcmp(&v6->sin6_addr, &v6dns->sin6_addr, sizeof(struct in6_addr)) != 0)
156 >      const struct sockaddr_in6 *const v6 = (const struct sockaddr_in6 *)&auth->client->connection->ip;
157 >      const struct sockaddr_in6 *const v6dns = (const struct sockaddr_in6 *)addr;
158 >
159 >      if (memcmp(&v6->sin6_addr, &v6dns->sin6_addr, sizeof(struct in6_addr)))
160        {
161          sendheader(auth->client, REPORT_IP_MISMATCH);
162 <        good = 0;
162 >        release_auth_client(auth);
163 >        return;
164        }
165      }
166      else
186 #endif
167      {
168 <      v4 = (const struct sockaddr_in *)&auth->client->localClient->ip;
169 <      v4dns = (const struct sockaddr_in *)addr;
170 <      if(v4->sin_addr.s_addr != v4dns->sin_addr.s_addr)
168 >      const struct sockaddr_in *const v4 = (const struct sockaddr_in *)&auth->client->connection->ip;
169 >      const struct sockaddr_in *const v4dns = (const struct sockaddr_in *)addr;
170 >
171 >      if (v4->sin_addr.s_addr != v4dns->sin_addr.s_addr)
172        {
173          sendheader(auth->client, REPORT_IP_MISMATCH);
174 <        good = 0;
174 >        release_auth_client(auth);
175 >        return;
176        }
177      }
178 <    if (good && strlen(name) <= HOSTLEN)
178 >
179 >    if (namelength > HOSTLEN)
180 >      sendheader(auth->client, REPORT_HOST_TOOLONG);
181 >    else
182      {
183 <      strlcpy(auth->client->host, name,
199 <              sizeof(auth->client->host));
183 >      strlcpy(auth->client->host, name, sizeof(auth->client->host));
184        sendheader(auth->client, REPORT_FIN_DNS);
185      }
202    else if (strlen(name) > HOSTLEN)
203      sendheader(auth->client, REPORT_HOST_TOOLONG);
186    }
187    else
188      sendheader(auth->client, REPORT_FAIL_DNS);
# Line 226 | Line 208 | auth_error(struct AuthRequest *auth)
208   }
209  
210   /*
211 < * start_auth_query - Flag the client to show that an attempt to
211 > * start_auth_query - Flag the client to show that an attempt to
212   * contact the ident server on
213   * the client's host.  The connect and subsequently the socket are all put
214   * into 'non-blocking' mode.  Should the connect or any later phase of the
215   * identifing process fail, it is aborted and the user is given a username
216   * of "unknown".
217   */
218 < static int
218 > static void
219   start_auth_query(struct AuthRequest *auth)
220   {
221    struct irc_ssaddr localaddr;
222    socklen_t locallen = sizeof(struct irc_ssaddr);
241 #ifdef IPV6
223    struct sockaddr_in6 *v6;
243 #else
244  struct sockaddr_in *v4;
245 #endif
224  
225    /* open a socket of the same type as the client socket */
226 <  if (comm_open(&auth->fd, auth->client->localClient->ip.ss.ss_family,
226 >  if (comm_open(&auth->fd, auth->client->connection->ip.ss.ss_family,
227                  SOCK_STREAM, 0, "ident") == -1)
228    {
229 <    report_error(L_ALL, "creating auth stream socket %s:%s",
230 <        get_client_name(auth->client, SHOW_IP), errno);
253 <    ilog(LOG_TYPE_IRCD, "Unable to create auth socket for %s",
254 <        get_client_name(auth->client, SHOW_IP));
229 >    report_error(L_ALL, "creating auth stream socket %s:%s",
230 >                 get_client_name(auth->client, SHOW_IP), errno);
231      ++ServerStats.is_abad;
232 <    return 0;
232 >    return;
233    }
234  
235 +  SetDoingAuth(auth);
236    sendheader(auth->client, REPORT_DO_ID);
237  
238 <  /*
239 <   * get the local address of the client and bind to that to
240 <   * make the auth request.  This used to be done only for
264 <   * ifdef VIRTUAL_HOST, but needs to be done for all clients
265 <   * since the ident request must originate from that same address--
266 <   * and machines with multiple IP addresses are common now
238 >  /*
239 >   * Get the local address of the client and bind to that to
240 >   * make the auth request.
241     */
242    memset(&localaddr, 0, locallen);
243 <  getsockname(auth->client->localClient->fd.fd, (struct sockaddr*)&localaddr,
243 >  getsockname(auth->client->connection->fd.fd, (struct sockaddr*)&localaddr,
244        &locallen);
245  
272 #ifdef IPV6
246    remove_ipv6_mapping(&localaddr);
247    v6 = (struct sockaddr_in6 *)&localaddr;
248    v6->sin6_port = htons(0);
276 #else
277  localaddr.ss_len = locallen;
278  v4 = (struct sockaddr_in *)&localaddr;
279  v4->sin_port = htons(0);
280 #endif
249    localaddr.ss_port = htons(0);
250  
251 <  comm_connect_tcp(&auth->fd, auth->client->sockhost, 113,
252 <      (struct sockaddr *)&localaddr, localaddr.ss_len, auth_connect_callback,
253 <      auth, auth->client->localClient->ip.ss.ss_family,
251 >  comm_connect_tcp(&auth->fd, auth->client->sockhost, RFC1413_PORT,
252 >      (struct sockaddr *)&localaddr, localaddr.ss_len, auth_connect_callback,
253 >      auth, auth->client->connection->ip.ss.ss_family,
254        GlobalSetOptions.ident_timeout);
287  return 1; /* We suceed here for now */
255   }
256  
257   /*
258 < * 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
258 > * start_auth
259   *
260   * inputs       - pointer to client to auth
261   * output       - NONE
262   * side effects - starts auth (identd) and dns queries for a client
263   */
264 < static void *
265 < start_auth(va_list args)
264 > void
265 > start_auth(struct Client *client_p)
266   {
267 <  struct Client *client = va_arg(args, struct Client *);
369 <  struct AuthRequest *auth = NULL;
370 <
371 <  assert(client != NULL);
267 >  struct AuthRequest *const auth = make_auth_request(client_p);
268  
269 <  auth = make_auth_request(client);
270 <  dlinkAdd(auth, &auth->node, &auth_doing_list);
269 >  SetInAuth(auth);
270 >  dlinkAddTail(auth, &auth->node, &auth_list);
271  
272 <  sendheader(client, REPORT_DO_DNS);
272 >  sendheader(client_p, REPORT_DO_DNS);
273  
274    SetDNSPending(auth);
275  
276 <  if (ConfigFileEntry.disable_auth == 0)
381 <  {
382 <    SetDoingAuth(auth);
276 >  if (ConfigGeneral.disable_auth == 0)
277      start_auth_query(auth);
384  }
385
386  gethost_byaddr(auth_dns_callback, auth, &client->localClient->ip);
278  
279 <  return NULL;
279 >  gethost_byaddr(auth_dns_callback, auth, &client_p->connection->ip);
280   }
281  
282   /*
# Line 395 | Line 286 | start_auth(va_list args)
286   static void
287   timeout_auth_queries_event(void *notused)
288   {
289 <  dlink_node *ptr = NULL, *next_ptr = NULL;
289 >  dlink_node *node = NULL, *node_next = NULL;
290  
291 <  DLINK_FOREACH_SAFE(ptr, next_ptr, auth_doing_list.head)
291 >  DLINK_FOREACH_SAFE(node, node_next, auth_list.head)
292    {
293 <    struct AuthRequest *auth = ptr->data;
293 >    struct AuthRequest *auth = node->data;
294  
295      if (auth->timeout > CurrentTime)
296 <      continue;
296 >      break;
297  
298      if (IsDoingAuth(auth))
299 <    {  
299 >    {
300        ++ServerStats.is_abad;
301        fd_close(&auth->fd);
302        ClearAuth(auth);
# Line 419 | Line 310 | timeout_auth_queries_event(void *notused
310        sendheader(auth->client, REPORT_FAIL_DNS);
311      }
312  
422    ilog(LOG_TYPE_IRCD, "DNS/AUTH timeout %s",
423         get_client_name(auth->client, SHOW_IP));
313      release_auth_client(auth);
314    }
315   }
# Line 439 | Line 328 | timeout_auth_queries_event(void *notused
328   static void
329   auth_connect_callback(fde_t *fd, int error, void *data)
330   {
331 <  struct AuthRequest *auth = data;
331 >  struct AuthRequest *const auth = data;
332    struct irc_ssaddr us;
333    struct irc_ssaddr them;
334 <  char authbuf[32];
334 >  char authbuf[16];
335 >  ssize_t len = 0;
336    socklen_t ulen = sizeof(struct irc_ssaddr);
337    socklen_t tlen = sizeof(struct irc_ssaddr);
338    uint16_t uport, tport;
449 #ifdef IPV6
339    struct sockaddr_in6 *v6;
451 #else
452  struct sockaddr_in *v4;
453 #endif
340  
341    if (error != COMM_OK)
342    {
# Line 458 | Line 344 | auth_connect_callback(fde_t *fd, int err
344      return;
345    }
346  
347 <  if (getsockname(auth->client->localClient->fd.fd, (struct sockaddr *)&us,
348 <      &ulen) ||
463 <      getpeername(auth->client->localClient->fd.fd, (struct sockaddr *)&them,
464 <      &tlen))
347 >  if (getsockname(auth->client->connection->fd.fd, (struct sockaddr *)&us, &ulen) ||
348 >      getpeername(auth->client->connection->fd.fd, (struct sockaddr *)&them, &tlen))
349    {
350 <    ilog(LOG_TYPE_IRCD, "auth get{sock,peer}name error for %s",
351 <        get_client_name(auth->client, SHOW_IP));
350 >    report_error(L_ALL, "auth get{sock,peer}name error %s:%s",
351 >                 get_client_name(auth->client, SHOW_IP), errno);
352      auth_error(auth);
353      return;
354    }
355  
472 #ifdef IPV6
356    v6 = (struct sockaddr_in6 *)&us;
357    uport = ntohs(v6->sin6_port);
358    v6 = (struct sockaddr_in6 *)&them;
359    tport = ntohs(v6->sin6_port);
477  remove_ipv6_mapping(&us);
478  remove_ipv6_mapping(&them);
479 #else
480  v4 = (struct sockaddr_in *)&us;
481  uport = ntohs(v4->sin_port);
482  v4 = (struct sockaddr_in *)&them;
483  tport = ntohs(v4->sin_port);
484  us.ss_len = ulen;
485  them.ss_len = tlen;
486 #endif
487  
488  snprintf(authbuf, sizeof(authbuf), "%u , %u\r\n", tport, uport);
360  
361 <  if (send(fd->fd, authbuf, strlen(authbuf), 0) == -1)
361 >  len = snprintf(authbuf, sizeof(authbuf), "%u, %u\r\n", tport, uport);
362 >
363 >  if (send(fd->fd, authbuf, len, 0) != len)
364    {
365      auth_error(auth);
366      return;
367    }
368  
369 <  read_auth_reply(&auth->fd, auth);
369 >  comm_setselect(fd, COMM_SELECT_READ, read_auth_reply, auth, 0);
370 > }
371 >
372 > /** Enum used to index ident reply fields in a human-readable way. */
373 > enum IdentReplyFields
374 > {
375 >  IDENT_PORT_NUMBERS,
376 >  IDENT_REPLY_TYPE,
377 >  IDENT_OS_TYPE,
378 >  IDENT_INFO,
379 >  USERID_TOKEN_COUNT
380 > };
381 >
382 > /** Parse an ident reply line and extract the userid from it.
383 > * \param reply The ident reply line.
384 > * \return The userid, or NULL on parse failure.
385 > */
386 > static const char *
387 > check_ident_reply(char *const reply)
388 > {
389 >  char *token = NULL, *end = NULL;
390 >  char *vector[USERID_TOKEN_COUNT];
391 >  const unsigned int count = token_vector(reply, ':', vector, USERID_TOKEN_COUNT);
392 >
393 >  if (USERID_TOKEN_COUNT != count)
394 >    return NULL;
395 >
396 >  /*
397 >   * Second token is the reply type
398 >   */
399 >  token = vector[IDENT_REPLY_TYPE];
400 >
401 >  if (EmptyString(token))
402 >    return NULL;
403 >
404 >  while (IsSpace(*token))
405 >    ++token;
406 >
407 >  if (strncmp(token, "USERID", 6))
408 >    return NULL;
409 >
410 >  /*
411 >   * Third token is the os type
412 >   */
413 >  token = vector[IDENT_OS_TYPE];
414 >
415 >  if (EmptyString(token))
416 >    return NULL;
417 >
418 >  while (IsSpace(*token))
419 >   ++token;
420 >
421 >  /*
422 >   * Unless "OTHER" is specified as the operating system type, the server
423 >   * is expected to return the "normal" user identification of the owner
424 >   * of this connection. "Normal" in this context may be taken to mean a
425 >   * string of characters which uniquely identifies the connection owner
426 >   * such as a user identifier assigned by the system administrator and
427 >   * used by such user as a mail identifier, or as the "user" part of a
428 >   * user/password pair used to gain access to system resources. When an
429 >   * operating system is specified (e.g., anything but "OTHER"), the user
430 >   * identifier is expected to be in a more or less immediately useful
431 >   * form - e.g., something that could be used as an argument to "finger"
432 >   * or as a mail address.
433 >   */
434 >  if (!strncmp(token, "OTHER", 5))
435 >    return NULL;
436 >
437 >  /*
438 >   * Fourth token is the username
439 >   */
440 >  token = vector[IDENT_INFO];
441 >
442 >  if (EmptyString(token))
443 >    return NULL;
444 >
445 >  while (IsSpace(*token))
446 >    ++token;
447 >
448 >  while (*token == '~' || *token == '^')
449 >    ++token;
450 >
451 >  /*
452 >   * Look for the end of the username, terminators are '\0, @, <SPACE>, :'
453 >   */
454 >  for (end = token; *end; ++end)
455 >    if (IsSpace(*end) || '@' == *end || ':' == *end)
456 >      break;
457 >  *end = '\0';
458 >
459 >  return token;
460   }
461  
462   /*
463 < * read_auth_reply - read the reply (if any) from the ident server
463 > * read_auth_reply - read the reply (if any) from the ident server
464   * we connected to.
465   * We only give it one shot, if the reply isn't good the first time
466   * fail the authentication entirely. --Bleep
467   */
505 #define AUTH_BUFSIZ 128
506
468   static void
469   read_auth_reply(fde_t *fd, void *data)
470   {
471 <  struct AuthRequest *auth = data;
472 <  char *s = NULL;
473 <  char *t = NULL;
474 <  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);
471 >  struct AuthRequest *const auth = data;
472 >  const char *username = NULL;
473 >  ssize_t len = 0;
474 >  char buf[RFC1413_BUFSIZ + 1];
475  
476 <  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 <  }
538 <
539 <  if (len > 0)
476 >  if ((len = recv(fd->fd, buf, RFC1413_BUFSIZ, 0)) > 0)
477    {
478      buf[len] = '\0';
479 <
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 <    }
479 >    username = check_ident_reply(buf);
480    }
481  
482    fd_close(fd);
483  
484    ClearAuth(auth);
485  
486 <  if (s == NULL)
486 >  if (EmptyString(username))
487    {
488      sendheader(auth->client, REPORT_FAIL_ID);
489      ++ServerStats.is_abad;
490    }
491    else
492    {
493 +    strlcpy(auth->client->username, username, sizeof(auth->client->username));
494      sendheader(auth->client, REPORT_FIN_ID);
495      ++ServerStats.is_asuc;
496 <    SetGotId(auth->client);
496 >    AddFlag(auth->client, FLAGS_GOTID);
497    }
498  
499    release_auth_client(auth);
# Line 584 | Line 502 | read_auth_reply(fde_t *fd, void *data)
502   /*
503   * delete_auth()
504   */
505 < void
505 > void
506   delete_auth(struct AuthRequest *auth)
507   {
508    if (IsDNSPending(auth))
# Line 593 | Line 511 | delete_auth(struct AuthRequest *auth)
511    if (IsDoingAuth(auth))
512      fd_close(&auth->fd);
513  
514 <  dlinkDelete(&auth->node, &auth_doing_list);
515 <  BlockHeapFree(auth_heap, auth);
514 >  if (IsInAuth(auth))
515 >  {
516 >    dlinkDelete(&auth->node, &auth_list);
517 >    ClearInAuth(auth);
518 >  }
519 > }
520 >
521 > /* auth_init
522 > *
523 > * Initialise the auth code
524 > */
525 > void
526 > auth_init(void)
527 > {
528 >  static struct event timeout_auth_queries =
529 >  {
530 >    .name = "timeout_auth_queries_event",
531 >    .handler = timeout_auth_queries_event,
532 >    .when = 1
533 >  };
534 >
535 >  event_add(&timeout_auth_queries, NULL);
536   }

Comparing:
ircd-hybrid-8/src/s_auth.c (property svn:keywords), Revision 1309 by michael, Sun Mar 25 11:24:18 2012 UTC vs.
ircd-hybrid/trunk/src/auth.c (property svn:keywords), Revision 7668 by michael, Wed Jul 20 17:09:49 2016 UTC

# Line 1 | Line 1
1 < Id Revision
1 > Id

Diff Legend

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