Cleanup code so it builds with C++ again
[ircu2.10.12-pk.git] / ircd / s_auth.c
1 /************************************************************************
2  *   IRC - Internet Relay Chat, src/s_auth.c
3  *   Copyright (C) 1992 Darren Reed
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 1, or (at your option)
8  *   any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *   GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program; if not, write to the Free Software
17  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  *   $Id$
20  *
21  * Changes:
22  *   July 6, 1999 - Rewrote most of the code here. When a client connects
23  *     to the server and passes initial socket validation checks, it
24  *     is owned by this module (auth) which returns it to the rest of the
25  *     server when dns and auth queries are finished. Until the client is
26  *     released, the server does not know it exists and does not process
27  *     any messages from it.
28  *     --Bleep  Thomas Helvey <tomh@inxpress.net>
29  */
30 #include "config.h"
31
32 #include "s_auth.h"
33 #include "client.h"
34 #include "IPcheck.h"
35 #include "ircd.h"
36 #include "ircd_alloc.h"
37 #include "ircd_chattr.h"
38 #include "ircd_events.h"
39 #include "ircd_features.h"
40 #include "ircd_log.h"
41 #include "ircd_osdep.h"
42 #include "ircd_snprintf.h"
43 #include "ircd_string.h"
44 #include "list.h"
45 #include "numeric.h"
46 #include "querycmds.h"
47 #include "res.h"
48 #include "s_bsd.h"
49 #include "s_debug.h"
50 #include "s_misc.h"
51 #include "send.h"
52 #include "struct.h"
53 #include "sys.h"               /* TRUE bleah */
54
55 #include <arpa/inet.h>         /* inet_netof */
56 #include <netdb.h>             /* struct hostent */
57 #include <string.h>
58 #include <stdlib.h>
59 #include <unistd.h>
60 #include <errno.h>
61 #include <fcntl.h>
62 #include <assert.h>
63 #include <sys/socket.h>
64 #include <sys/file.h>
65 #include <sys/ioctl.h>
66
67 /*
68  * a bit different approach
69  * this replaces the original sendheader macros
70  */
71 static struct {
72   const char*  message;
73   unsigned int length;
74 } HeaderMessages [] = {
75   /* 123456789012345678901234567890123456789012345678901234567890 */
76   { "NOTICE AUTH :*** Looking up your hostname\r\n",       43 },
77   { "NOTICE AUTH :*** Found your hostname\r\n",            38 },
78   { "NOTICE AUTH :*** Found your hostname, cached\r\n",    46 },
79   { "NOTICE AUTH :*** Couldn't look up your hostname\r\n", 49 },
80   { "NOTICE AUTH :*** Checking Ident\r\n",                 33 },
81   { "NOTICE AUTH :*** Got ident response\r\n",             37 },
82   { "NOTICE AUTH :*** No ident response\r\n",              36 },
83   { "NOTICE AUTH :*** Your forward and reverse DNS do not match, "
84     "ignoring hostname.\r\n",                              80 },
85   {"NOTICE AUTH :*** Invalid hostname\r\n",                35 }
86 };
87
88 typedef enum {
89   REPORT_DO_DNS,
90   REPORT_FIN_DNS,
91   REPORT_FIN_DNSC,
92   REPORT_FAIL_DNS,
93   REPORT_DO_ID,
94   REPORT_FIN_ID,
95   REPORT_FAIL_ID,
96   REPORT_IP_MISMATCH,
97   REPORT_INVAL_DNS
98 } ReportType;
99
100 #define sendheader(c, r) \
101    send(cli_fd(c), HeaderMessages[(r)].message, HeaderMessages[(r)].length, 0)
102
103 struct AuthRequest* AuthPollList = 0; /* GLOBAL - auth queries pending io */
104 static struct AuthRequest* AuthIncompleteList = 0;
105
106 enum { AUTH_TIMEOUT = 60 };
107
108 static void release_auth_client(struct Client* client);
109 static void unlink_auth_request(struct AuthRequest* request,
110                                 struct AuthRequest** list);
111 void free_auth_request(struct AuthRequest* auth);
112
113 /* auth_verify_hostname - verify that a hostname is valid, i.e., only
114  * contains characters valid for a hostname and that a hostname is not
115  * too long.
116  */
117 static int
118 auth_verify_hostname(char *host, int maxlen)
119 {
120   int i;
121
122   /* Walk through the host name */
123   for (i = 0; host[i]; i++)
124     /* If it's not a hostname character or if it's too long, return false */
125     if (!IsHostChar(host[i]) || i >= maxlen)
126       return 0;
127
128   return 1; /* it's a valid hostname */
129 }
130
131 /*
132  * auth_timeout - timeout a given auth request
133  */
134 static void auth_timeout_callback(struct Event* ev)
135 {
136   struct AuthRequest* auth;
137
138   assert(0 != ev_timer(ev));
139   assert(0 != t_data(ev_timer(ev)));
140
141   auth = (struct AuthRequest*) t_data(ev_timer(ev));
142
143   if (ev_type(ev) == ET_DESTROY) { /* being destroyed */
144     auth->flags &= ~AM_TIMEOUT;
145
146     if (!(auth->flags & AM_FREE_MASK)) {
147       Debug((DEBUG_LIST, "Freeing auth from timeout callback; %p [%p]", auth,
148              ev_timer(ev)));
149       MyFree(auth); /* done with it, finally */
150     }
151   } else {
152     assert(ev_type(ev) == ET_EXPIRE);
153
154     destroy_auth_request(auth, 1);
155   }
156 }
157
158 /*
159  * auth_sock_callback - called when an event occurs on the socket
160  */
161 static void auth_sock_callback(struct Event* ev)
162 {
163   struct AuthRequest* auth;
164
165   assert(0 != ev_socket(ev));
166   assert(0 != s_data(ev_socket(ev)));
167
168   auth = (struct AuthRequest*) s_data(ev_socket(ev));
169
170   switch (ev_type(ev)) {
171   case ET_DESTROY: /* being destroyed */
172     auth->flags &= ~AM_SOCKET;
173
174     if (!(auth->flags & AM_FREE_MASK)) {
175       Debug((DEBUG_LIST, "Freeing auth from sock callback; %p [%p]", auth,
176              ev_socket(ev)));
177       MyFree(auth); /* done with it finally */
178     }
179     break;
180
181   case ET_CONNECT: /* socket connection completed */
182     Debug((DEBUG_LIST, "Connection completed for auth %p [%p]; sending query",
183            auth, ev_socket(ev)));
184     socket_state(&auth->socket, SS_CONNECTED);
185     send_auth_query(auth);
186     break;
187
188   case ET_READ: /* socket is readable */
189   case ET_EOF: /* end of file on socket */
190   case ET_ERROR: /* error on socket */
191     Debug((DEBUG_LIST, "Auth socket %p [%p] readable", auth, ev_socket(ev)));
192     read_auth_reply(auth);
193     break;
194
195   default:
196 #ifndef NDEBUG
197     abort(); /* unrecognized event */
198 #endif
199     break;
200   }
201 }
202
203 /*
204  * destroy_auth_request - stop an auth request completely
205  */
206 void destroy_auth_request(struct AuthRequest* auth, int send_reports)
207 {
208   struct AuthRequest** authList;
209
210   if (IsDoingAuth(auth)) {
211     authList = &AuthPollList;
212     if (-1 < auth->fd) {
213       close(auth->fd);
214       auth->fd = -1;
215       socket_del(&auth->socket);
216     }
217
218     if (send_reports && IsUserPort(auth->client))
219       sendheader(auth->client, REPORT_FAIL_ID);
220   } else
221     authList = &AuthIncompleteList;
222
223   if (IsDNSPending(auth)) {
224     delete_resolver_queries(auth);
225     if (send_reports && IsUserPort(auth->client))
226       sendheader(auth->client, REPORT_FAIL_DNS);
227   }
228
229   if (send_reports) {
230     log_write(LS_RESOLVER, L_INFO, 0, "DNS/AUTH timeout %s",
231               get_client_name(auth->client, HIDE_IP));
232     release_auth_client(auth->client);
233   }
234
235   unlink_auth_request(auth, authList);
236   free_auth_request(auth);
237 }
238
239 /*
240  * make_auth_request - allocate a new auth request
241  */
242 static struct AuthRequest* make_auth_request(struct Client* client)
243 {
244   struct AuthRequest* auth = 
245                (struct AuthRequest*) MyMalloc(sizeof(struct AuthRequest));
246   assert(0 != auth);
247   memset(auth, 0, sizeof(struct AuthRequest));
248   auth->flags   = AM_TIMEOUT;
249   auth->fd      = -1;
250   auth->client  = client;
251   cli_auth(client) = auth;
252   timer_add(timer_init(&auth->timeout), auth_timeout_callback, (void*) auth,
253             TT_RELATIVE, AUTH_TIMEOUT);
254   return auth;
255 }
256
257 /*
258  * free_auth_request - cleanup auth request allocations
259  */
260 void free_auth_request(struct AuthRequest* auth)
261 {
262   if (-1 < auth->fd) {
263     close(auth->fd);
264     Debug((DEBUG_LIST, "Deleting auth socket for %p", auth->client));
265     socket_del(&auth->socket);
266   }
267   Debug((DEBUG_LIST, "Deleting auth timeout timer for %p", auth->client));
268   timer_del(&auth->timeout);
269 }
270
271 /*
272  * unlink_auth_request - remove auth request from a list
273  */
274 static void unlink_auth_request(struct AuthRequest* request,
275                                 struct AuthRequest** list)
276 {
277   if (request->next)
278     request->next->prev = request->prev;
279   if (request->prev)
280     request->prev->next = request->next;
281   else
282     *list = request->next;
283 }
284
285 /*
286  * link_auth_request - add auth request to a list
287  */
288 static void link_auth_request(struct AuthRequest* request,
289                               struct AuthRequest** list)
290 {
291   request->prev = 0;
292   request->next = *list;
293   if (*list)
294     (*list)->prev = request;
295   *list = request;
296 }
297
298 /*
299  * release_auth_client - release auth client from auth system
300  * this adds the client into the local client lists so it can be read by
301  * the main io processing loop
302  */
303 static void release_auth_client(struct Client* client)
304 {
305   assert(0 != client);
306   cli_auth(client) = 0;
307   cli_lasttime(client) = cli_since(client) = CurrentTime;
308   if (cli_fd(client) > HighestFd)
309     HighestFd = cli_fd(client);
310   LocalClientArray[cli_fd(client)] = client;
311
312   add_client_to_list(client);
313   socket_events(&(cli_socket(client)), SOCK_ACTION_SET | SOCK_EVENT_READABLE);
314   Debug((DEBUG_INFO, "Auth: release_auth_client %s@%s[%s]",
315          cli_username(client), cli_sockhost(client), cli_sock_ip(client)));
316 }
317  
318 static void auth_kill_client(struct AuthRequest* auth)
319 {
320   assert(0 != auth);
321
322   unlink_auth_request(auth, (IsDoingAuth(auth)) ? &AuthPollList : &AuthIncompleteList);
323
324   if (IsDNSPending(auth))
325     delete_resolver_queries(auth);
326   IPcheck_disconnect(auth->client);
327   Count_unknowndisconnects(UserStats);
328   cli_auth(auth->client) = 0;
329   free_client(auth->client);
330   free_auth_request(auth);
331 }
332
333 /*
334  * auth_dns_callback - called when resolver query finishes
335  * if the query resulted in a successful search, hp will contain
336  * a non-null pointer, otherwise hp will be null.
337  * set the client on it's way to a connection completion, regardless
338  * of success of failure
339  */
340 static void auth_dns_callback(void* vptr, struct hostent* hp)
341 {
342   struct AuthRequest* auth = (struct AuthRequest*) vptr;
343   assert(auth);
344   /*
345    * need to do this here so auth_kill_client doesn't
346    * try have the resolver delete the query it's about
347    * to delete anyways. --Bleep
348    */
349   ClearDNSPending(auth);
350
351   if (hp) {
352     int i;
353     /*
354      * Verify that the host to ip mapping is correct both ways and that
355      * the ip#(s) for the socket is listed for the host.
356      */
357     for (i = 0; hp->h_addr_list[i]; ++i) {
358       if (0 == memcmp(hp->h_addr_list[i], &(cli_ip(auth->client)),
359                       sizeof(struct in_addr)))
360          break;
361     }
362     if (!hp->h_addr_list[i]) {
363       if (IsUserPort(auth->client))
364         sendheader(auth->client, REPORT_IP_MISMATCH);
365       sendto_opmask_butone(0, SNO_IPMISMATCH, "IP# Mismatch: %s != %s[%s]",
366                            cli_sock_ip(auth->client), hp->h_name, 
367                            ircd_ntoa(hp->h_addr_list[0]));
368       if (feature_bool(FEAT_KILL_IPMISMATCH)) {
369         auth_kill_client(auth);
370         return;
371       }
372     }
373     else if (!auth_verify_hostname(hp->h_name, HOSTLEN))
374     {
375       if (IsUserPort(auth->client))
376         sendheader(auth->client, REPORT_INVAL_DNS);
377     }
378     else
379     {
380       cli_dns_reply(auth->client) = hp;
381       ircd_strncpy(cli_sockhost(auth->client), hp->h_name, HOSTLEN);
382       if (IsUserPort(auth->client))
383         sendheader(auth->client, REPORT_FIN_DNS);
384     }
385   }
386   else {
387     /*
388      * this should have already been done by s_bsd.c in add_connection
389      *
390      * strcpy(auth->client->sockhost, auth->client->sock_ip);
391      */
392     if (IsUserPort(auth->client))
393       sendheader(auth->client, REPORT_FAIL_DNS);
394   }
395   if (!IsDoingAuth(auth)) {
396     release_auth_client(auth->client);
397     unlink_auth_request(auth, &AuthIncompleteList);
398     free_auth_request(auth);
399   }
400 }
401
402 /*
403  * authsenderr - handle auth send errors
404  */
405 static void auth_error(struct AuthRequest* auth, int kill)
406 {
407   ++ServerStats->is_abad;
408
409   assert(0 != auth);
410   close(auth->fd);
411   auth->fd = -1;
412   socket_del(&auth->socket);
413
414   if (IsUserPort(auth->client))
415     sendheader(auth->client, REPORT_FAIL_ID);
416
417   if (kill) {
418     /*
419      * we can't read the client info from the client socket,
420      * close the client connection and free the client
421      * Need to do this before we ClearAuth(auth) so we know
422      * which list to remove the query from. --Bleep
423      */
424     auth_kill_client(auth);
425     return;
426   }
427
428   ClearAuth(auth);
429   unlink_auth_request(auth, &AuthPollList);
430
431   if (IsDNSPending(auth))
432     link_auth_request(auth, &AuthIncompleteList);
433   else {
434     release_auth_client(auth->client);
435     free_auth_request(auth);
436   }
437 }
438
439 /*
440  * start_auth_query - Flag the client to show that an attempt to 
441  * contact the ident server on the client's host.  The connect and
442  * subsequently the socket are all put into 'non-blocking' mode.  
443  * Should the connect or any later phase of the identifing process fail,
444  * it is aborted and the user is given a username of "unknown".
445  */
446 static int start_auth_query(struct AuthRequest* auth)
447 {
448   struct sockaddr_in remote_addr;
449   struct sockaddr_in local_addr;
450   int                fd;
451   IOResult           result;
452
453   assert(0 != auth);
454   assert(0 != auth->client);
455
456   if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
457     ++ServerStats->is_abad;
458     return 0;
459   }
460   if ((MAXCONNECTIONS - 10) < fd) {
461     close(fd);
462     return 0;
463   }
464   if (!os_set_nonblocking(fd)) {
465     close(fd);
466     return 0;
467   }
468   if (IsUserPort(auth->client))
469     sendheader(auth->client, REPORT_DO_ID);
470   /* 
471    * get the local address of the client and bind to that to
472    * make the auth request.  This used to be done only for
473    * ifdef VIRTTUAL_HOST, but needs to be done for all clients
474    * since the ident request must originate from that same address--
475    * and machines with multiple IP addresses are common now
476    */
477   memset(&local_addr, 0, sizeof(struct sockaddr_in));
478   os_get_sockname(cli_fd(auth->client), &local_addr);
479   local_addr.sin_port = htons(0);
480
481   if (bind(fd, (struct sockaddr*) &local_addr, sizeof(struct sockaddr_in))) {
482     close(fd);
483     return 0;
484   }
485
486   remote_addr.sin_addr.s_addr = (cli_ip(auth->client)).s_addr;
487   remote_addr.sin_port = htons(113);
488   remote_addr.sin_family = AF_INET;
489
490   if ((result = os_connect_nonb(fd, &remote_addr)) == IO_FAILURE ||
491       !socket_add(&auth->socket, auth_sock_callback, (void*) auth,
492                   result == IO_SUCCESS ? SS_CONNECTED : SS_CONNECTING,
493                   SOCK_EVENT_READABLE, fd)) {
494     ServerStats->is_abad++;
495     /*
496      * No error report from this...
497      */
498     close(fd);
499     if (IsUserPort(auth->client))
500       sendheader(auth->client, REPORT_FAIL_ID);
501     return 0;
502   }
503
504   auth->flags |= AM_SOCKET;
505   auth->fd = fd;
506
507   SetAuthConnect(auth);
508   if (result == IO_SUCCESS)
509     send_auth_query(auth); /* this does a SetAuthPending(auth) for us */
510
511   return 1;
512 }
513
514
515 enum IdentReplyFields {
516   IDENT_PORT_NUMBERS,
517   IDENT_REPLY_TYPE,
518   IDENT_OS_TYPE,
519   IDENT_INFO,
520   USERID_TOKEN_COUNT
521 };
522
523 static char* check_ident_reply(char* reply)
524 {
525   char* token;
526   char* end;
527   char* vector[USERID_TOKEN_COUNT];
528   int count = token_vector(reply, ':', vector, USERID_TOKEN_COUNT);
529
530   if (USERID_TOKEN_COUNT != count)
531     return 0;
532   /*
533    * second token is the reply type
534    */
535   token = vector[IDENT_REPLY_TYPE];
536   if (EmptyString(token))
537     return 0;
538
539   while (IsSpace(*token))
540     ++token;
541
542   if (0 != strncmp(token, "USERID", 6))
543     return 0;
544
545   /*
546    * third token is the os type
547    */
548   token = vector[IDENT_OS_TYPE];
549   if (EmptyString(token))
550     return 0;
551   while (IsSpace(*token))
552    ++token;
553
554   /*
555    * Unless "OTHER" is specified as the operating system
556    * type, the server is expected to return the "normal"
557    * user identification of the owner of this connection.
558    * "Normal" in this context may be taken to mean a string
559    * of characters which uniquely identifies the connection
560    * owner such as a user identifier assigned by the system
561    * administrator and used by such user as a mail
562    * identifier, or as the "user" part of a user/password
563    * pair used to gain access to system resources.  When an
564    * operating system is specified (e.g., anything but
565    * "OTHER"), the user identifier is expected to be in a
566    * more or less immediately useful form - e.g., something
567    * that could be used as an argument to "finger" or as a
568    * mail address.
569    */
570   if (0 == strncmp(token, "OTHER", 5))
571     return 0;
572   /*
573    * fourth token is the username
574    */
575   token = vector[IDENT_INFO];
576   if (EmptyString(token))
577     return 0;
578   while (IsSpace(*token))
579     ++token;
580   /*
581    * look for the end of the username, terminators are '\0, @, <SPACE>, :'
582    */
583   for (end = token; *end; ++end) {
584     if (IsSpace(*end) || '@' == *end || ':' == *end)
585       break;
586   }
587   *end = '\0'; 
588   return token;
589 }
590
591 /*
592  * start_auth - starts auth (identd) and dns queries for a client
593  */
594 enum { LOOPBACK = 127 };
595
596 void start_auth(struct Client* client)
597 {
598   struct AuthRequest* auth = 0;
599
600   assert(0 != client);
601
602   auth = make_auth_request(client);
603   assert(0 != auth);
604
605   Debug((DEBUG_INFO, "Beginning auth request on client %p", client));
606
607   if (!feature_bool(FEAT_NODNS)) {
608     if (LOOPBACK == inet_netof(cli_ip(client)))
609       strcpy(cli_sockhost(client), cli_name(&me));
610     else {
611       struct DNSQuery query;
612
613       query.vptr     = auth;
614       query.callback = auth_dns_callback;
615
616       if (IsUserPort(auth->client))
617         sendheader(client, REPORT_DO_DNS);
618
619       gethost_byaddr((const char*) &(cli_ip(client)), &query);
620       SetDNSPending(auth);
621     }
622   }
623
624   if (start_auth_query(auth)) {
625     Debug((DEBUG_LIST, "identd query for %p initiated successfully",
626            auth->client));
627     link_auth_request(auth, &AuthPollList);
628   } else if (IsDNSPending(auth)) {
629     Debug((DEBUG_LIST, "identd query for %p not initiated successfully; "
630            "waiting on DNS", auth->client));
631     link_auth_request(auth, &AuthIncompleteList);
632   } else {
633     Debug((DEBUG_LIST, "identd query for %p not initiated successfully; "
634            "no DNS pending; releasing immediately", auth->client));
635     free_auth_request(auth);
636     release_auth_client(client);
637   }
638 }
639
640 /*
641  * send_auth_query - send the ident server a query giving "theirport , ourport"
642  * The write is only attempted *once* so it is deemed to be a fail if the
643  * entire write doesn't write all the data given.  This shouldnt be a
644  * problem since the socket should have a write buffer far greater than
645  * this message to store it in should problems arise. -avalon
646  */
647 void send_auth_query(struct AuthRequest* auth)
648 {
649   struct sockaddr_in us;
650   struct sockaddr_in them;
651   char               authbuf[32];
652   unsigned int       count;
653
654   assert(0 != auth);
655   assert(0 != auth->client);
656
657   if (!os_get_sockname(cli_fd(auth->client), &us) ||
658       !os_get_peername(cli_fd(auth->client), &them)) {
659     auth_error(auth, 1);
660     return;
661   }
662   ircd_snprintf(0, authbuf, sizeof(authbuf), "%u , %u\r\n",
663                 (unsigned int) ntohs(them.sin_port),
664                 (unsigned int) ntohs(us.sin_port));
665
666   if (IO_SUCCESS == os_send_nonb(auth->fd, authbuf, strlen(authbuf), &count)) {
667     ClearAuthConnect(auth);
668     SetAuthPending(auth);
669   }
670   else
671     auth_error(auth, 0);
672 }
673
674
675 /*
676  * read_auth_reply - read the reply (if any) from the ident server 
677  * we connected to.
678  * We only give it one shot, if the reply isn't good the first time
679  * fail the authentication entirely. --Bleep
680  */
681 void read_auth_reply(struct AuthRequest* auth)
682 {
683   char*        username = 0;
684   unsigned int len;
685   /*
686    * rfc1453 sez we MUST accept 512 bytes
687    */
688   char   buf[BUFSIZE + 1];
689
690   assert(0 != auth);
691   assert(0 != auth->client);
692   assert(auth == cli_auth(auth->client));
693
694   if (IO_SUCCESS == os_recv_nonb(auth->fd, buf, BUFSIZE, &len)) {
695     buf[len] = '\0';
696     Debug((DEBUG_LIST, "Auth %p [%p] reply: %s", auth, &auth->socket, buf));
697     username = check_ident_reply(buf);
698     Debug((DEBUG_LIST, "Username: %s", username));
699   }
700
701   close(auth->fd);
702   auth->fd = -1;
703   Debug((DEBUG_LIST, "Deleting auth [%p] socket %p", auth, &auth->socket));
704   socket_del(&auth->socket);
705   ClearAuth(auth);
706   
707   if (!EmptyString(username)) {
708     ircd_strncpy(cli_username(auth->client), username, USERLEN);
709     /*
710      * Not needed, struct is zeroed by memset
711      * auth->client->username[USERLEN] = '\0';
712      */
713     SetGotId(auth->client);
714     ++ServerStats->is_asuc;
715     if (IsUserPort(auth->client))
716       sendheader(auth->client, REPORT_FIN_ID);
717   }
718   else {
719     ++ServerStats->is_abad;
720   }
721   unlink_auth_request(auth, &AuthPollList);
722
723   if (IsDNSPending(auth))
724     link_auth_request(auth, &AuthIncompleteList);
725   else {
726     release_auth_client(auth->client);
727     free_auth_request(auth);
728   }
729 }