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/src/s_auth.c (file contents), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid/trunk/src/auth.c (file contents), Revision 4854 by michael, Thu Nov 6 17:39:26 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: s_auth.c,v 7.160 2005/09/24 09:27:18 michael Exp $
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"
36 #include "tools.h"
39   #include "list.h"
40 < #include "s_auth.h"
41 < #include "s_conf.h"
40 > #include "ircd_defs.h"
41 > #include "fdlist.h"
42 > #include "auth.h"
43 > #include "conf.h"
44   #include "client.h"
41 #include "common.h"
45   #include "event.h"
43 #include "fdlist.h"              /* fdlist_add */
44 #include "hook.h"
46   #include "irc_string.h"
46 #include "sprintf_irc.h"
47   #include "ircd.h"
48 #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"
53 < #include "s_stats.h"
51 > #include "log.h"
52   #include "send.h"
53 < #include "memory.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 76 | Line 77 | enum {
77    REPORT_HOST_TOOLONG
78   };
79  
80 < #define sendheader(c, i) sendto_one((c), HeaderMessages[(i)], me.name)
80 <
81 < /*
82 < * Ok, the original was confusing.
83 < * Now there are two lists, an auth request can be on both at the same time
84 < * or only on one or the other.
85 < * - Dianora
86 < */
87 < static dlink_list auth_doing_dns_list   = { NULL, NULL, 0 };
88 < static dlink_list auth_doing_ident_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  
92 static PF read_auth_reply;
93 static CNCB auth_connect_callback;
94 static CBFUNC start_auth;
95
96 struct Callback *auth_cb = NULL;
97
98 /* init_auth()
99 *
100 * Initialise the auth code
101 */
102 void
103 init_auth(void)
104 {
105  auth_cb = register_callback("start_auth", start_auth);
106  eventAddIsh("timeout_auth_queries_event", timeout_auth_queries_event, NULL, 1);
107 }
86  
87   /*
88   * make_auth_request - allocate a new auth request
# Line 112 | Line 90 | init_auth(void)
90   static struct AuthRequest *
91   make_auth_request(struct Client *client)
92   {
93 <  struct AuthRequest *request = MyMalloc(sizeof(struct AuthRequest));
93 >  struct AuthRequest *const request = &client->connection->auth;
94 >
95 >  memset(request, 0, sizeof(*request));
96  
97    request->client  = client;
98    request->timeout = CurrentTime + CONNECTTIMEOUT;
99  
100 <  return (request);
100 >  return request;
101   }
102  
103   /*
# Line 126 | Line 106 | make_auth_request(struct Client *client)
106   * the main io processing loop
107   */
108   void
109 < release_auth_client(struct Client *client)
109 > release_auth_client(struct AuthRequest *auth)
110   {
111 +  struct Client *const client = auth->client;
112 +
113 +  if (IsDoingAuth(auth) || IsDNSPending(auth))
114 +    return;
115 +
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);
129 <  if ((client->node.prev != NULL) || (client->node.next != NULL))
130 <  {
131 <    sendto_realops_flags(UMODE_ALL, L_OPER,
132 <                         "already linked %s at %s:%d", client->name,
133 <                         __FILE__, __LINE__);
134 <    ilog(L_ERROR, "already linked %s at %s:%d", client->name,
135 <         __FILE__, __LINE__);
145 <    assert(0==5);
146 <  }
147 <  else
148 <    dlinkAdd(client, &client->node, &global_client_list);
149 <  read_packet(&client->localClient->fd, client);
127 >  client->connection->allow_read = MAX_FLOOD;
128 >  comm_setflush(&client->connection->fd, 1000, flood_recalc, client);
129 >
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->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, hp will contain
141 < * a non-null pointer, otherwise hp will be null.
140 > * if the query resulted in a successful search, name will contain
141 > * a non-NULL pointer, otherwise name will be NULL.
142   * set the client on it's way to a connection completion, regardless
143   * of success of failure
144   */
145   static void
146 < auth_dns_callback(void *vptr, struct DNSReply *reply)
146 > auth_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name, size_t namelength)
147   {
148 <  struct AuthRequest *auth = (struct AuthRequest *)vptr;
148 >  struct AuthRequest *const auth = vptr;
149  
164  dlinkDelete(&auth->dns_node, &auth_doing_dns_list);
150    ClearDNSPending(auth);
151  
152 <  if (reply != NULL)
152 >  if (!EmptyString(name))
153    {
154 <    struct sockaddr_in *v4, *v4dns;
155 < #ifdef IPV6
171 <    struct sockaddr_in6 *v6, *v6dns;
172 < #endif
173 <    int good = 1;
154 >    const struct sockaddr_in *v4, *v4dns;
155 >    const struct sockaddr_in6 *v6, *v6dns;
156  
157 < #ifdef IPV6
176 <    if (auth->client->localClient->ip.ss.ss_family == AF_INET6)
157 >    if (auth->client->connection->ip.ss.ss_family == AF_INET6)
158      {
159 <      v6 = (struct sockaddr_in6 *)&auth->client->localClient->ip;
160 <      v6dns = (struct sockaddr_in6 *)&reply->addr;
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
187 #endif
170      {
171 <      v4 = (struct sockaddr_in *)&auth->client->localClient->ip;
172 <      v4dns = (struct sockaddr_in *)&reply->addr;
173 <      if(v4->sin_addr.s_addr != v4dns->sin_addr.s_addr)
171 >      v4 = (const struct sockaddr_in *)&auth->client->connection->ip;
172 >      v4dns = (const struct sockaddr_in *)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(reply->h_name) <= HOSTLEN)
181 >
182 >    if (namelength > HOSTLEN)
183 >      sendheader(auth->client, REPORT_HOST_TOOLONG);
184 >    else
185      {
186 <      strlcpy(auth->client->host, reply->h_name,
200 <              sizeof(auth->client->host));
186 >      strlcpy(auth->client->host, name, sizeof(auth->client->host));
187        sendheader(auth->client, REPORT_FIN_DNS);
188      }
203    else if (strlen(reply->h_name) > HOSTLEN)
204      sendheader(auth->client, REPORT_HOST_TOOLONG);
189    }
190    else
191 <      sendheader(auth->client, REPORT_FAIL_DNS);
191 >    sendheader(auth->client, REPORT_FAIL_DNS);
192  
193 <  MyFree(auth->client->localClient->dns_query);
210 <  auth->client->localClient->dns_query = NULL;
211 <
212 <  if (!IsDoingAuth(auth))
213 <  {
214 <    struct Client *client_p = auth->client;
215 <    MyFree(auth);
216 <    release_auth_client(client_p);
217 <  }
193 >  release_auth_client(auth);
194   }
195  
196   /*
# Line 223 | Line 199 | auth_dns_callback(void *vptr, struct DNS
199   static void
200   auth_error(struct AuthRequest *auth)
201   {
202 <  ++ServerStats->is_abad;
202 >  ++ServerStats.is_abad;
203  
204    fd_close(&auth->fd);
205  
230  dlinkDelete(&auth->ident_node, &auth_doing_ident_list);
206    ClearAuth(auth);
207  
208    sendheader(auth->client, REPORT_FAIL_ID);
209  
210 <  if (!IsDNSPending(auth) && !IsCrit(auth))
236 <  {
237 <    release_auth_client(auth->client);
238 <    MyFree(auth);
239 <  }
210 >  release_auth_client(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 252 | Line 223 | start_auth_query(struct AuthRequest *aut
223   {
224    struct irc_ssaddr localaddr;
225    socklen_t locallen = sizeof(struct irc_ssaddr);
255 #ifdef IPV6
226    struct sockaddr_in6 *v6;
257 #else
258  struct sockaddr_in *v4;
259 #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",
268 <        get_client_name(auth->client, SHOW_IP));
269 <    ++ServerStats->is_abad;
232 >    report_error(L_ALL, "creating auth stream socket %s:%s",
233 >                 get_client_name(auth->client, SHOW_IP), errno);
234 >    ++ServerStats.is_abad;
235      return 0;
236    }
237  
238    sendheader(auth->client, REPORT_DO_ID);
239  
240 <  /*
240 >  /*
241     * get the local address of the client and bind to that to
242     * make the auth request.  This used to be done only for
243     * ifdef VIRTUAL_HOST, but needs to be done for all clients
# Line 280 | Line 245 | start_auth_query(struct AuthRequest *aut
245     * and machines with multiple IP addresses are common now
246     */
247    memset(&localaddr, 0, locallen);
248 <  getsockname(auth->client->localClient->fd.fd, (struct sockaddr*)&localaddr,
248 >  getsockname(auth->client->connection->fd.fd, (struct sockaddr*)&localaddr,
249        &locallen);
250  
286 #ifdef IPV6
251    remove_ipv6_mapping(&localaddr);
252    v6 = (struct sockaddr_in6 *)&localaddr;
253    v6->sin6_port = htons(0);
290 #else
291  localaddr.ss_len = locallen;
292  v4 = (struct sockaddr_in *)&localaddr;
293  v4->sin_port = htons(0);
294 #endif
254    localaddr.ss_port = htons(0);
255  
256 <  SetDoingAuth(auth);
257 <  dlinkAdd(auth, &auth->ident_node, &auth_doing_ident_list);
258 <
300 <  comm_connect_tcp(&auth->fd, auth->client->sockhost, 113,
301 <      (struct sockaddr *)&localaddr, localaddr.ss_len, auth_connect_callback,
302 <      auth, auth->client->localClient->ip.ss.ss_family,
256 >  comm_connect_tcp(&auth->fd, auth->client->sockhost, RFC1413_PORT,
257 >      (struct sockaddr *)&localaddr, localaddr.ss_len, auth_connect_callback,
258 >      auth, auth->client->connection->ip.ss.ss_family,
259        GlobalSetOptions.ident_timeout);
260    return 1; /* We suceed here for now */
261   }
262  
263   /*
264 < * GetValidIdent - parse ident query reply from identd server
309 < *
310 < * Inputs        - pointer to ident buf
311 < * Output        - NULL if no valid ident found, otherwise pointer to name
312 < * Side effects  -
313 < */
314 < /*
315 < * A few questions have been asked about this mess, obviously
316 < * it should have been commented better the first time.
317 < * The original idea was to remove all references to libc from ircd-hybrid.
318 < * Instead of having to write a replacement for sscanf(), I did a
319 < * rather gruseome parser here so we could remove this function call.
320 < * Note, that I had also removed a few floating point printfs as well (though
321 < * now we are still stuck with a few...)
322 < * Remember, we have a replacement ircd sprintf, we have bleeps fputs lib
323 < * it would have been nice to remove some unneeded code.
324 < * Oh well. If we don't remove libc stuff totally, then it would be
325 < * far cleaner to use sscanf()
326 < *
327 < * - Dianora
328 < */
329 < static char *
330 < GetValidIdent(char *buf)
331 < {
332 <  int   remp = 0;
333 <  int   locp = 0;
334 <  char* colon1Ptr;
335 <  char* colon2Ptr;
336 <  char* colon3Ptr;
337 <  char* commaPtr;
338 <  char* remotePortString;
339 <
340 <  /* All this to get rid of a sscanf() fun. */
341 <  remotePortString = buf;
342 <  
343 <  if ((colon1Ptr = strchr(remotePortString,':')) == NULL)
344 <    return 0;
345 <  *colon1Ptr = '\0';
346 <  colon1Ptr++;
347 <
348 <  if ((colon2Ptr = strchr(colon1Ptr,':')) == NULL)
349 <    return 0;
350 <  *colon2Ptr = '\0';
351 <  colon2Ptr++;
352 <  
353 <  if ((commaPtr = strchr(remotePortString, ',')) == NULL)
354 <    return 0;
355 <  *commaPtr = '\0';
356 <  commaPtr++;
357 <
358 <  if ((remp = atoi(remotePortString)) == 0)
359 <    return 0;
360 <              
361 <  if ((locp = atoi(commaPtr)) == 0)
362 <    return 0;
363 <
364 <  /* look for USERID bordered by first pair of colons */
365 <  if (strstr(colon1Ptr, "USERID") == NULL)
366 <    return 0;
367 <
368 <  if ((colon3Ptr = strchr(colon2Ptr,':')) == NULL)
369 <    return 0;
370 <  *colon3Ptr = '\0';
371 <  colon3Ptr++;
372 <  return (colon3Ptr);
373 < }
374 <
375 < /*
376 < * start_auth
264 > * start_auth
265   *
266   * inputs       - pointer to client to auth
267   * output       - NONE
268   * side effects - starts auth (identd) and dns queries for a client
269   */
270 < static void *
271 < start_auth(va_list args)
270 > void
271 > start_auth(struct Client *client_p)
272   {
273 <  struct Client *client = va_arg(args, struct Client *);
386 <  struct AuthRequest *auth = NULL;
387 <
388 <  assert(client != NULL);
273 >  struct AuthRequest *const auth = make_auth_request(client_p);
274  
275 <  auth = make_auth_request(client);
276 <  SetCrit(auth);
275 >  SetInAuth(auth);
276 >  dlinkAddTail(auth, &auth->node, &auth_pending_list);
277  
278 <  client->localClient->dns_query = MyMalloc(sizeof(struct DNSQuery));
394 <  client->localClient->dns_query->ptr = auth;
395 <  client->localClient->dns_query->callback = auth_dns_callback;
278 >  sendheader(client_p, REPORT_DO_DNS);
279  
280 <  sendheader(client, REPORT_DO_DNS);
280 >  SetDNSPending(auth);
281  
282 <  if (ConfigFileEntry.disable_auth == 0)
282 >  if (ConfigGeneral.disable_auth == 0)
283 >  {
284 >    SetDoingAuth(auth);
285      start_auth_query(auth);
286 +  }
287  
288 <  /* auth order changed, before gethost_byaddr can immediately call
403 <   * dns callback under win32 when the lookup cannot be started.
404 <   * And that would do MyFree(auth) etc -adx */
405 <  SetDNSPending(auth);
406 <  dlinkAdd(auth, &auth->dns_node, &auth_doing_dns_list);
407 <  ClearCrit(auth);
408 <  gethost_byaddr(&client->localClient->ip, client->localClient->dns_query);
409 <
410 <  return NULL;
288 >  gethost_byaddr(auth_dns_callback, auth, &client_p->connection->ip);
289   }
290  
291   /*
# Line 417 | Line 295 | start_auth(va_list args)
295   static void
296   timeout_auth_queries_event(void *notused)
297   {
298 <  dlink_node *ptr;
421 <  dlink_node *next_ptr;
422 <  struct AuthRequest* auth;
298 >  dlink_node *node = NULL, *node_next = NULL;
299  
300 <  DLINK_FOREACH_SAFE(ptr, next_ptr, auth_doing_ident_list.head)
300 >  DLINK_FOREACH_SAFE(node, node_next, auth_pending_list.head)
301    {
302 <    auth = ptr->data;
302 >    struct AuthRequest *auth = node->data;
303  
304 <    if (auth->timeout <= CurrentTime)
304 >    if (auth->timeout > CurrentTime)
305 >      break;
306 >
307 >    if (IsDoingAuth(auth))
308      {
309 +      ++ServerStats.is_abad;
310        fd_close(&auth->fd);
311 <
432 <      ++ServerStats->is_abad;
311 >      ClearAuth(auth);
312        sendheader(auth->client, REPORT_FAIL_ID);
313 +    }
314  
315 <      if (IsDNSPending(auth))
316 <      {
317 <        struct Client *client_p = auth->client;
318 <
319 <        dlinkDelete(&auth->dns_node, &auth_doing_dns_list);
440 <        if (client_p->localClient->dns_query != NULL)
441 <        {
442 <          delete_resolver_queries(client_p->localClient->dns_query);
443 <          MyFree(client_p->localClient->dns_query);
444 <        }
445 <        auth->client->localClient->dns_query = NULL;
446 <        sendheader(client_p, REPORT_FAIL_DNS);
447 <      }
448 <
449 <      ilog(L_INFO, "DNS/AUTH timeout %s",
450 <           get_client_name(auth->client, SHOW_IP));
451 <
452 <      dlinkDelete(&auth->ident_node, &auth_doing_ident_list);
453 <      release_auth_client(auth->client);
454 <      MyFree(auth);
315 >    if (IsDNSPending(auth))
316 >    {
317 >      delete_resolver_queries(auth);
318 >      ClearDNSPending(auth);
319 >      sendheader(auth->client, REPORT_FAIL_DNS);
320      }
321 +
322 +    release_auth_client(auth);
323    }
324   }
325  
# Line 476 | Line 343 | auth_connect_callback(fde_t *fd, int err
343    char authbuf[32];
344    socklen_t ulen = sizeof(struct irc_ssaddr);
345    socklen_t tlen = sizeof(struct irc_ssaddr);
346 <  u_int16_t uport, tport;
480 < #ifdef IPV6
346 >  uint16_t uport, tport;
347    struct sockaddr_in6 *v6;
482 #else
483  struct sockaddr_in *v4;
484 #endif
348  
349    if (error != COMM_OK)
350    {
# Line 489 | Line 352 | auth_connect_callback(fde_t *fd, int err
352      return;
353    }
354  
355 <  if (getsockname(auth->client->localClient->fd.fd, (struct sockaddr *) &us,
356 <      (socklen_t *) &ulen) ||
494 <      getpeername(auth->client->localClient->fd.fd, (struct sockaddr *) &them,
495 <      (socklen_t *) &tlen))
355 >  if (getsockname(auth->client->connection->fd.fd, (struct sockaddr *)&us, &ulen) ||
356 >      getpeername(auth->client->connection->fd.fd, (struct sockaddr *)&them, &tlen))
357    {
358 <    ilog(L_INFO, "auth get{sock,peer}name error for %s",
359 <        get_client_name(auth->client, SHOW_IP));
358 >    ilog(LOG_TYPE_IRCD, "auth get{sock,peer}name error for %s",
359 >         get_client_name(auth->client, SHOW_IP));
360      auth_error(auth);
361      return;
362    }
363  
503 #ifdef IPV6
364    v6 = (struct sockaddr_in6 *)&us;
365    uport = ntohs(v6->sin6_port);
366    v6 = (struct sockaddr_in6 *)&them;
367    tport = ntohs(v6->sin6_port);
368    remove_ipv6_mapping(&us);
369    remove_ipv6_mapping(&them);
370 < #else
371 <  v4 = (struct sockaddr_in *)&us;
512 <  uport = ntohs(v4->sin_port);
513 <  v4 = (struct sockaddr_in *)&them;
514 <  tport = ntohs(v4->sin_port);
515 <  us.ss_len = ulen;
516 <  them.ss_len = tlen;
517 < #endif
518 <  
519 <  ircsprintf(authbuf, "%u , %u\r\n", tport, uport);
370 >
371 >  snprintf(authbuf, sizeof(authbuf), "%u, %u\r\n", tport, uport);
372  
373    if (send(fd->fd, authbuf, strlen(authbuf), 0) == -1)
374    {
375      auth_error(auth);
376      return;
377    }
378 <  read_auth_reply(&auth->fd, auth);
378 >
379 >  comm_setselect(fd, COMM_SELECT_READ, read_auth_reply, auth, 0);
380 > }
381 >
382 > /** Enum used to index ident reply fields in a human-readable way. */
383 > enum IdentReplyFields
384 > {
385 >  IDENT_PORT_NUMBERS,
386 >  IDENT_REPLY_TYPE,
387 >  IDENT_OS_TYPE,
388 >  IDENT_INFO,
389 >  USERID_TOKEN_COUNT
390 > };
391 >
392 > /** Parse an ident reply line and extract the userid from it.
393 > * \param reply The ident reply line.
394 > * \return The userid, or NULL on parse failure.
395 > */
396 > static const char *
397 > check_ident_reply(char *reply)
398 > {
399 >  char *token = NULL, *end = NULL;
400 >  char *vector[USERID_TOKEN_COUNT];
401 >  int count = token_vector(reply, ':', vector, USERID_TOKEN_COUNT);
402 >
403 >  if (USERID_TOKEN_COUNT != count)
404 >    return NULL;
405 >
406 >  /*
407 >   * Second token is the reply type
408 >   */
409 >  token = vector[IDENT_REPLY_TYPE];
410 >
411 >  if (EmptyString(token))
412 >    return NULL;
413 >
414 >  while (IsSpace(*token))
415 >    ++token;
416 >
417 >  if (strncmp(token, "USERID", 6))
418 >    return NULL;
419 >
420 >  /*
421 >   * Third token is the os type
422 >   */
423 >  token = vector[IDENT_OS_TYPE];
424 >
425 >  if (EmptyString(token))
426 >    return NULL;
427 >
428 >  while (IsSpace(*token))
429 >   ++token;
430 >
431 >  /*
432 >   * Unless "OTHER" is specified as the operating system type, the server
433 >   * is expected to return the "normal" user identification of the owner
434 >   * of this connection. "Normal" in this context may be taken to mean a
435 >   * string of characters which uniquely identifies the connection owner
436 >   * such as a user identifier assigned by the system administrator and
437 >   * used by such user as a mail identifier, or as the "user" part of a
438 >   * user/password pair used to gain access to system resources. When an
439 >   * operating system is specified (e.g., anything but "OTHER"), the user
440 >   * identifier is expected to be in a more or less immediately useful
441 >   * form - e.g., something that could be used as an argument to "finger"
442 >   * or as a mail address.
443 >   */
444 >  if (!strncmp(token, "OTHER", 5))
445 >    return NULL;
446 >
447 >  /*
448 >   * Fourth token is the username
449 >   */
450 >  token = vector[IDENT_INFO];
451 >
452 >  if (EmptyString(token))
453 >    return NULL;
454 >
455 >  while (IsSpace(*token))
456 >    ++token;
457 >
458 >  while (*token == '~' || *token == '^')
459 >    ++token;
460 >
461 >  /*
462 >   * Look for the end of the username, terminators are '\0, @, <SPACE>, :'
463 >   */
464 >  for (end = token; *end; ++end)
465 >    if (IsSpace(*end) || '@' == *end || ':' == *end)
466 >      break;
467 >  *end = '\0';
468 >
469 >  return token;
470   }
471  
472   /*
473 < * read_auth_reply - read the reply (if any) from the ident server
473 > * read_auth_reply - read the reply (if any) from the ident server
474   * we connected to.
475   * We only give it one shot, if the reply isn't good the first time
476   * fail the authentication entirely. --Bleep
477   */
535 #define AUTH_BUFSIZ 128
536
478   static void
479   read_auth_reply(fde_t *fd, void *data)
480   {
481 <  struct AuthRequest *auth = data;
482 <  char *s = NULL;
483 <  char *t = NULL;
484 <  int len;
544 <  int count;
545 <  char buf[AUTH_BUFSIZ + 1]; /* buffer to read auth reply into */
546 <
547 <  len = recv(fd->fd, buf, AUTH_BUFSIZ, 0);
548 <  
549 <  if (len < 0)
550 <  {
551 < #ifdef _WIN32
552 <    errno = WSAGetLastError();
553 < #endif
554 <    if (ignoreErrno(errno))
555 <      comm_setselect(fd, COMM_SELECT_READ, read_auth_reply, auth, 0);
556 <    else
557 <      auth_error(auth);
558 <    return;
559 <  }
481 >  struct AuthRequest *const auth = data;
482 >  const char *username = NULL;
483 >  ssize_t len = 0;
484 >  char buf[RFC1413_BUFSIZ + 1];
485  
486 <  if (len > 0)
486 >  if ((len = recv(fd->fd, buf, RFC1413_BUFSIZ, 0)) > 0)
487    {
488      buf[len] = '\0';
489 <
565 <    if ((s = GetValidIdent(buf)))
566 <    {
567 <      t = auth->client->username;
568 <
569 <      while (*s == '~' || *s == '^')
570 <        s++;
571 <
572 <      for (count = USERLEN; *s && count; s++)
573 <      {
574 <        if (*s == '@')
575 <          break;
576 <        if (!IsSpace(*s) && *s != ':' && *s != '[')
577 <        {
578 <          *t++ = *s;
579 <          count--;
580 <        }
581 <      }
582 <
583 <      *t = '\0';
584 <    }
489 >    username = check_ident_reply(buf);
490    }
491  
492    fd_close(fd);
493  
589  dlinkDelete(&auth->ident_node, &auth_doing_ident_list);  
494    ClearAuth(auth);
495  
496 <  if (s == NULL)
496 >  if (EmptyString(username))
497    {
498      sendheader(auth->client, REPORT_FAIL_ID);
499 <    ++ServerStats->is_abad;
499 >    ++ServerStats.is_abad;
500    }
501    else
502    {
503 +    strlcpy(auth->client->username, username, sizeof(auth->client->username));
504      sendheader(auth->client, REPORT_FIN_ID);
505 <    ++ServerStats->is_asuc;
505 >    ++ServerStats.is_asuc;
506      SetGotId(auth->client);
507    }
508  
509 <  if (!IsDNSPending(auth) && !IsCrit(auth))
605 <  {
606 <    release_auth_client(auth->client);
607 <    MyFree(auth);
608 <  }
509 >  release_auth_client(auth);
510   }
511  
512   /*
513   * delete_auth()
514   */
515 < void
516 < delete_auth(struct Client *target_p)
515 > void
516 > delete_auth(struct AuthRequest *auth)
517   {
518 <  dlink_node *ptr;
519 <  dlink_node *next_ptr;
619 <  struct AuthRequest *auth;
620 <
621 <  if (!IsUnknown(target_p))
622 <    return;
518 >  if (IsDNSPending(auth))
519 >    delete_resolver_queries(auth);
520  
521 <  if (target_p->localClient->dns_query != NULL)
522 <    DLINK_FOREACH_SAFE(ptr, next_ptr, auth_doing_dns_list.head)
626 <    {
627 <      auth = ptr->data;
628 <
629 <      if (auth->client == target_p)
630 <      {
631 <        delete_resolver_queries(target_p->localClient->dns_query);
521 >  if (IsDoingAuth(auth))
522 >    fd_close(&auth->fd);
523  
524 <        dlinkDelete(&auth->dns_node, &auth_doing_dns_list);
634 <        if (!IsDoingAuth(auth))
635 <        {
636 <          MyFree(auth);
637 <          return;
638 <        }
639 <      }
640 <    }
641 <
642 <  DLINK_FOREACH_SAFE(ptr, next_ptr, auth_doing_ident_list.head)
524 >  if (IsInAuth(auth))
525    {
526 <    auth = ptr->data;
526 >    dlinkDelete(&auth->node, &auth_pending_list);
527 >    ClearInAuth(auth);
528 >  }
529 > }
530  
531 <    if (auth->client == target_p)
532 <    {
533 <      fd_close(&auth->fd);
531 > /* auth_init
532 > *
533 > * Initialise the auth code
534 > */
535 > void
536 > auth_init(void)
537 > {
538 >  static struct event timeout_auth_queries =
539 >  {
540 >    .name = "timeout_auth_queries_event",
541 >    .handler = timeout_auth_queries_event,
542 >    .when = 1
543 >  };
544  
545 <      dlinkDelete(&auth->ident_node, &auth_doing_ident_list);
651 <      MyFree(auth);
652 <    }
653 <  }
545 >  event_add(&timeout_auth_queries, NULL);
546   }

Comparing:
ircd-hybrid/src/s_auth.c (property svn:keywords), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid/trunk/src/auth.c (property svn:keywords), Revision 4854 by michael, Thu Nov 6 17:39:26 2014 UTC

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

Diff Legend

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