NAS-Port should be 32bits
[freeradius.git] / src / main / auth.c
1 /*
2  * auth.c       User authentication.
3  *
4  * Version:     $Id$
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
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  * Copyright 2000,2006  The FreeRADIUS server project
21  * Copyright 2000  Miquel van Smoorenburg <miquels@cistron.nl>
22  * Copyright 2000  Jeff Carneal <jeff@apex.net>
23  */
24 RCSID("$Id$")
25
26 #include <freeradius-devel/radiusd.h>
27 #include <freeradius-devel/modules.h>
28 #include <freeradius-devel/state.h>
29 #include <freeradius-devel/rad_assert.h>
30
31 #include <ctype.h>
32
33 /*
34  *      Return a short string showing the terminal server, port
35  *      and calling station ID.
36  */
37 char *auth_name(char *buf, size_t buflen, REQUEST *request, bool do_cli)
38 {
39         VALUE_PAIR      *cli;
40         VALUE_PAIR      *pair;
41         uint32_t        port = 0;       /* RFC 2865 NAS-Port is 4 bytes */
42         char const      *tls = "";
43
44         if ((cli = fr_pair_find_by_num(request->packet->vps, PW_CALLING_STATION_ID, 0, TAG_ANY)) == NULL) {
45                 do_cli = false;
46         }
47
48         if ((pair = fr_pair_find_by_num(request->packet->vps, PW_NAS_PORT, 0, TAG_ANY)) != NULL) {
49                 port = pair->vp_integer;
50         }
51
52         if (request->packet->dst_port == 0) {
53                 if (fr_pair_find_by_num(request->packet->vps, PW_FREERADIUS_PROXIED_TO, 0, TAG_ANY)) {
54                         tls = " via TLS tunnel";
55                 } else {
56                         tls = " via proxy to virtual server";
57                 }
58         }
59
60         snprintf(buf, buflen, "from client %.128s port %u%s%.128s%s",
61                         request->client->shortname, port,
62                  (do_cli ? " cli " : ""), (do_cli ? cli->vp_strvalue : ""),
63                  tls);
64
65         return buf;
66 }
67
68
69
70 /*
71  * Make sure user/pass are clean
72  * and then log them
73  */
74 static int rad_authlog(char const *msg, REQUEST *request, int goodpass)
75 {
76         int logit;
77         char const *extra_msg = NULL;
78         char clean_password[1024];
79         char clean_username[1024];
80         char buf[1024];
81         char extra[1024];
82         char *p;
83         VALUE_PAIR *username = NULL;
84
85         if (!request->root->log_auth) {
86                 return 0;
87         }
88
89         /*
90          * Get the correct username based on the configured value
91          */
92         if (!log_stripped_names) {
93                 username = fr_pair_find_by_num(request->packet->vps, PW_USER_NAME, 0, TAG_ANY);
94         } else {
95                 username = request->username;
96         }
97
98         /*
99          *      Clean up the username
100          */
101         if (username == NULL) {
102                 strcpy(clean_username, "<no User-Name attribute>");
103         } else {
104                 fr_prints(clean_username, sizeof(clean_username), username->vp_strvalue, username->vp_length, '\0');
105         }
106
107         /*
108          *      Clean up the password
109          */
110         if (request->root->log_auth_badpass || request->root->log_auth_goodpass) {
111                 if (!request->password) {
112                         VALUE_PAIR *auth_type;
113
114                         auth_type = fr_pair_find_by_num(request->config, PW_AUTH_TYPE, 0, TAG_ANY);
115                         if (auth_type) {
116                                 snprintf(clean_password, sizeof(clean_password),
117                                          "<via Auth-Type = %s>",
118                                          dict_valnamebyattr(PW_AUTH_TYPE, 0,
119                                                             auth_type->vp_integer));
120                         } else {
121                                 strcpy(clean_password, "<no User-Password attribute>");
122                         }
123                 } else if (fr_pair_find_by_num(request->packet->vps, PW_CHAP_PASSWORD, 0, TAG_ANY)) {
124                         strcpy(clean_password, "<CHAP-Password>");
125                 } else {
126                         fr_prints(clean_password, sizeof(clean_password),
127                                   request->password->vp_strvalue, request->password->vp_length, '\0');
128                 }
129         }
130
131         if (goodpass) {
132                 logit = request->root->log_auth_goodpass;
133                 extra_msg = request->root->auth_goodpass_msg;
134         } else {
135                 logit = request->root->log_auth_badpass;
136                 extra_msg = request->root->auth_badpass_msg;
137         }
138
139         if (extra_msg) {
140                 extra[0] = ' ';
141                 p = extra + 1;
142                 if (radius_xlat(p, sizeof(extra) - 1, request, extra_msg, NULL, NULL) < 0) {
143                         return -1;
144                 }
145         } else {
146                 *extra = '\0';
147         }
148
149         RAUTH("%s: [%s%s%s] (%s)%s",
150                        msg,
151                        clean_username,
152                        logit ? "/" : "",
153                        logit ? clean_password : "",
154                        auth_name(buf, sizeof(buf), request, 1),
155                        extra);
156
157         return 0;
158 }
159
160 /*
161  *      Check password.
162  *
163  *      Returns:        0  OK
164  *                      -1 Password fail
165  *                      -2 Rejected (Auth-Type = Reject, send Port-Message back)
166  *                      1  End check & return, don't reply
167  *
168  *      NOTE: NOT the same as the RLM_ values !
169  */
170 static int CC_HINT(nonnull) rad_check_password(REQUEST *request)
171 {
172         vp_cursor_t cursor;
173         VALUE_PAIR *auth_type_pair;
174         int auth_type = -1;
175         int result;
176         int auth_type_count = 0;
177
178         /*
179          *      Look for matching check items. We skip the whole lot
180          *      if the authentication type is PW_AUTH_TYPE_ACCEPT or
181          *      PW_AUTH_TYPE_REJECT.
182          */
183         fr_cursor_init(&cursor, &request->config);
184         while ((auth_type_pair = fr_cursor_next_by_num(&cursor, PW_AUTH_TYPE, 0, TAG_ANY))) {
185                 auth_type = auth_type_pair->vp_integer;
186                 auth_type_count++;
187
188                 RDEBUG2("Found Auth-Type = %s", dict_valnamebyattr(PW_AUTH_TYPE, 0, auth_type));
189                 if (auth_type == PW_AUTH_TYPE_REJECT) {
190                         RDEBUG2("Auth-Type = Reject, rejecting user");
191
192                         return -2;
193                 }
194         }
195
196         /*
197          *      Warn if more than one Auth-Type was found, because only the last
198          *      one found will actually be used.
199          */
200         if ((auth_type_count > 1) && (rad_debug_lvl)) {
201                 RERROR("Warning:  Found %d auth-types on request for user '%s'",
202                         auth_type_count, request->username->vp_strvalue);
203         }
204
205         /*
206          *      This means we have a proxy reply or an accept and it wasn't
207          *      rejected in the above loop. So that means it is accepted and we
208          *      do no further authentication.
209          */
210         if ((auth_type == PW_AUTH_TYPE_ACCEPT)
211 #ifdef WITH_PROXY
212             || (request->proxy)
213 #endif
214             ) {
215                 RDEBUG2("Auth-Type = Accept, accepting the user");
216                 return 0;
217         }
218
219         /*
220          *      Check that Auth-Type has been set, and reject if not.
221          *
222          *      Do quick checks to see if Cleartext-Password or Crypt-Password have
223          *      been set, and complain if so.
224          */
225         if (auth_type < 0) {
226                 if (fr_pair_find_by_num(request->config, PW_CRYPT_PASSWORD, 0, TAG_ANY) != NULL) {
227                         RWDEBUG2("Please update your configuration, and remove 'Auth-Type = Crypt'");
228                         RWDEBUG2("Use the PAP module instead");
229                 }
230                 else if (fr_pair_find_by_num(request->config, PW_CLEARTEXT_PASSWORD, 0, TAG_ANY) != NULL) {
231                         RWDEBUG2("Please update your configuration, and remove 'Auth-Type = Local'");
232                         RWDEBUG2("Use the PAP or CHAP modules instead");
233                 }
234
235                 /*
236                  *      The admin hasn't told us how to
237                  *      authenticate the user, so we reject them!
238                  *
239                  *      This is fail-safe.
240                  */
241
242                 REDEBUG2("No Auth-Type found: rejecting the user via Post-Auth-Type = Reject");
243                 return -2;
244         }
245
246         /*
247          *      See if there is a module that handles
248          *      this Auth-Type, and turn the RLM_ return
249          *      status into the values as defined at
250          *      the top of this function.
251          */
252         result = process_authenticate(auth_type, request);
253         switch (result) {
254         /*
255          *      An authentication module FAIL
256          *      return code, or any return code that
257          *      is not expected from authentication,
258          *      is the same as an explicit REJECT!
259          */
260         case RLM_MODULE_FAIL:
261         case RLM_MODULE_INVALID:
262         case RLM_MODULE_NOOP:
263         case RLM_MODULE_NOTFOUND:
264         case RLM_MODULE_REJECT:
265         case RLM_MODULE_UPDATED:
266         case RLM_MODULE_USERLOCK:
267         default:
268                 result = -1;
269                 break;
270
271         case RLM_MODULE_OK:
272                 result = 0;
273                 break;
274
275         case RLM_MODULE_HANDLED:
276                 result = 1;
277                 break;
278         }
279
280         return result;
281 }
282
283 /*
284  *      Post-authentication step processes the response before it is
285  *      sent to the NAS. It can receive both Access-Accept and Access-Reject
286  *      replies.
287  */
288 int rad_postauth(REQUEST *request)
289 {
290         int     result;
291         int     postauth_type = 0;
292         VALUE_PAIR *vp;
293
294         if (request->reply->code == PW_CODE_ACCESS_CHALLENGE) {
295                 fr_pair_delete_by_num(&request->config, PW_POST_AUTH_TYPE, 0, TAG_ANY);
296                 vp = pair_make_config("Post-Auth-Type", "Challenge", T_OP_SET);
297                 if (!vp) return RLM_MODULE_OK;
298
299         } else if (request->reply->code == PW_CODE_ACCESS_REJECT) {
300                 fr_pair_delete_by_num(&request->config, PW_POST_AUTH_TYPE, 0, TAG_ANY);
301                 vp = pair_make_config("Post-Auth-Type", "Reject", T_OP_SET);
302                 if (!vp) return RLM_MODULE_OK;
303
304         } else {
305                 vp = fr_pair_find_by_num(request->config, PW_POST_AUTH_TYPE, 0, TAG_ANY);
306         }
307
308         /*
309          *      If a method was chosen, use that.
310          */
311         if (vp) {
312                 postauth_type = vp->vp_integer;
313                 RDEBUG2("Using Post-Auth-Type %s",
314                         dict_valnamebyattr(PW_POST_AUTH_TYPE, 0, postauth_type));
315         }
316
317         result = process_post_auth(postauth_type, request);
318         switch (result) {
319         /*
320          *      The module failed, or said to reject the user: Do so.
321          */
322         case RLM_MODULE_FAIL:
323         case RLM_MODULE_INVALID:
324         case RLM_MODULE_REJECT:
325         case RLM_MODULE_USERLOCK:
326         default:
327                 /*
328                  *      We WERE going to have a nice reply, but
329                  *      something went wrong.  So we've got to run
330                  *      Post-Auth-Type Reject, which is defined in the
331                  *      dictionaries as having value "1".
332                  */
333                 if (request->reply->code != PW_CODE_ACCESS_REJECT) {
334                         RDEBUG("Using Post-Auth-Type Reject");
335
336                         process_post_auth(1, request);
337                 }
338
339                 fr_state_discard(request, request->packet);
340                 result = RLM_MODULE_REJECT;
341                 break;
342         /*
343          *      The module handled the request, cancel the reply.
344          */
345         case RLM_MODULE_HANDLED:
346                 /* FIXME */
347                 break;
348         /*
349          *      The module had a number of OK return codes.
350          */
351         case RLM_MODULE_NOOP:
352         case RLM_MODULE_NOTFOUND:
353         case RLM_MODULE_OK:
354         case RLM_MODULE_UPDATED:
355                 result = RLM_MODULE_OK;
356
357                 if (request->reply->code == PW_CODE_ACCESS_CHALLENGE) {
358                         fr_state_put_vps(request, request->packet, request->reply);
359
360                 } else {
361                         fr_state_discard(request, request->packet);
362                 }
363                 break;
364         }
365
366         /*
367          *      Rejects during authorize, etc. are handled by the
368          *      earlier code, which logs a reason for the rejection.
369          *      If the packet is rejected in post-auth, we need to log
370          *      that as a separate reason.
371          */
372         if (result == RLM_MODULE_REJECT) {
373                 if (request->reply->code != RLM_MODULE_REJECT) {
374                         rad_authlog("Rejected in post-auth", request, 0);
375                 }
376                 request->reply->code = PW_CODE_ACCESS_REJECT;
377         }
378
379         /*
380          *      If we're still accepting the user, say so.
381          */
382         if (request->reply->code == PW_CODE_ACCESS_ACCEPT) {
383                 if ((vp = fr_pair_find_by_num(request->packet->vps, PW_MODULE_SUCCESS_MESSAGE, 0, TAG_ANY)) != NULL) {
384                         char msg[MAX_STRING_LEN+12];
385
386                         snprintf(msg, sizeof(msg), "Login OK (%s)",
387                                  vp->vp_strvalue);
388                         rad_authlog(msg, request, 1);
389                 } else {
390                         rad_authlog("Login OK", request, 1);
391                 }
392         }
393
394         return result;
395 }
396
397 /*
398  *      Process and reply to an authentication request
399  *
400  *      The return value of this function isn't actually used right now, so
401  *      it's not entirely clear if it is returning the right things. --Pac.
402  */
403 int rad_authenticate(REQUEST *request)
404 {
405 #ifdef WITH_SESSION_MGMT
406         VALUE_PAIR      *check_item;
407 #endif
408         VALUE_PAIR      *module_msg;
409         VALUE_PAIR      *tmp = NULL;
410         int             result;
411         char            autz_retry = 0;
412         int             autz_type = 0;
413
414 #ifdef WITH_PROXY
415         /*
416          *      If this request got proxied to another server, we need
417          *      to check whether it authenticated the request or not.
418          *
419          *      request->proxy gets set only AFTER authorization, so
420          *      it's safe to check it here.  If it exists, it means
421          *      we're doing a second pass through rad_authenticate().
422          */
423         if (request->proxy) {
424                 int code = 0;
425
426                 if (request->proxy_reply) code = request->proxy_reply->code;
427
428                 switch (code) {
429                 /*
430                  *      Reply of ACCEPT means accept, thus set Auth-Type
431                  *      accordingly.
432                  */
433                 case PW_CODE_ACCESS_ACCEPT:
434                         tmp = radius_pair_create(request,
435                                                 &request->config,
436                                                 PW_AUTH_TYPE, 0);
437                         if (tmp) tmp->vp_integer = PW_AUTH_TYPE_ACCEPT;
438                         goto authenticate;
439
440                 /*
441                  *      Challenges are punted back to the NAS without any
442                  *      further processing.
443                  */
444                 case PW_CODE_ACCESS_CHALLENGE:
445                         request->reply->code = PW_CODE_ACCESS_CHALLENGE;
446                         fr_state_put_vps(request, request->packet, request->reply);
447                         return RLM_MODULE_OK;
448
449                 /*
450                  *      ALL other replies mean reject. (this is fail-safe)
451                  *
452                  *      Do NOT do any authorization or authentication. They
453                  *      are being rejected, so we minimize the amount of work
454                  *      done by the server, by rejecting them here.
455                  */
456                 case PW_CODE_ACCESS_REJECT:
457                         rad_authlog("Login incorrect (Home Server says so)",
458                                     request, 0);
459                         request->reply->code = PW_CODE_ACCESS_REJECT;
460                         fr_state_discard(request, request->packet);
461                         return RLM_MODULE_REJECT;
462
463                 default:
464                         rad_authlog("Login incorrect (Home Server failed to respond)",
465                                     request, 0);
466                         fr_state_discard(request, request->packet);
467                         return RLM_MODULE_REJECT;
468                 }
469         }
470 #endif
471         /*
472          *      Look for, and cache, passwords.
473          */
474         if (!request->password) {
475                 request->password = fr_pair_find_by_num(request->packet->vps, PW_USER_PASSWORD, 0, TAG_ANY);
476         }
477         if (!request->password) {
478                 request->password = fr_pair_find_by_num(request->packet->vps, PW_CHAP_PASSWORD, 0, TAG_ANY);
479         }
480
481         /*
482          *      Grab the VPS associated with the State attribute.
483          */
484         fr_state_get_vps(request, request->packet);
485
486         /*
487          *      Get the user's authorization information from the database
488          */
489 autz_redo:
490         result = process_authorize(autz_type, request);
491         switch (result) {
492         case RLM_MODULE_NOOP:
493         case RLM_MODULE_NOTFOUND:
494         case RLM_MODULE_OK:
495         case RLM_MODULE_UPDATED:
496                 break;
497         case RLM_MODULE_HANDLED:
498                 return result;
499         case RLM_MODULE_FAIL:
500         case RLM_MODULE_INVALID:
501         case RLM_MODULE_REJECT:
502         case RLM_MODULE_USERLOCK:
503         default:
504                 if ((module_msg = fr_pair_find_by_num(request->packet->vps, PW_MODULE_FAILURE_MESSAGE, 0, TAG_ANY)) != NULL) {
505                         char msg[MAX_STRING_LEN + 16];
506                         snprintf(msg, sizeof(msg), "Invalid user (%s)",
507                                  module_msg->vp_strvalue);
508                         rad_authlog(msg,request,0);
509                 } else {
510                         rad_authlog("Invalid user", request, 0);
511                 }
512                 request->reply->code = PW_CODE_ACCESS_REJECT;
513                 return result;
514         }
515         if (!autz_retry) {
516                 tmp = fr_pair_find_by_num(request->config, PW_AUTZ_TYPE, 0, TAG_ANY);
517                 if (tmp) {
518                         autz_type = tmp->vp_integer;
519                         RDEBUG2("Using Autz-Type %s",
520                                 dict_valnamebyattr(PW_AUTZ_TYPE, 0, autz_type));
521                         autz_retry = 1;
522                         goto autz_redo;
523                 }
524         }
525
526         /*
527          *      If we haven't already proxied the packet, then check
528          *      to see if we should.  Maybe one of the authorize
529          *      modules has decided that a proxy should be used. If
530          *      so, get out of here and send the packet.
531          */
532         if (
533 #ifdef WITH_PROXY
534             (request->proxy == NULL) &&
535 #endif
536             ((tmp = fr_pair_find_by_num(request->config, PW_PROXY_TO_REALM, 0, TAG_ANY)) != NULL)) {
537                 REALM *realm;
538
539                 realm = realm_find2(tmp->vp_strvalue);
540
541                 /*
542                  *      Don't authenticate, as the request is going to
543                  *      be proxied.
544                  */
545                 if (realm && realm->auth_pool) {
546                         return RLM_MODULE_OK;
547                 }
548
549                 /*
550                  *      Catch users who set Proxy-To-Realm to a LOCAL
551                  *      realm (sigh).  But don't complain if it is
552                  *      *the* LOCAL realm.
553                  */
554                 if (realm &&(strcmp(realm->name, "LOCAL") != 0)) {
555                         RWDEBUG2("You set Proxy-To-Realm = %s, but it is a LOCAL realm!  Cancelling proxy request.", realm->name);
556                 }
557
558                 if (!realm) {
559                         RWDEBUG2("You set Proxy-To-Realm = %s, but the realm does not exist!  Cancelling invalid proxy request.", tmp->vp_strvalue);
560                 }
561         }
562
563 #ifdef WITH_PROXY
564 authenticate:
565 #endif
566
567         /*
568          *      Validate the user
569          */
570         do {
571                 result = rad_check_password(request);
572                 if (result > 0) {
573                         return RLM_MODULE_HANDLED;
574                 }
575
576         } while(0);
577
578         /*
579          *      Failed to validate the user.
580          *
581          *      We PRESUME that the code which failed will clean up
582          *      request->reply->vps, to be ONLY the reply items it
583          *      wants to send back.
584          */
585         if (result < 0) {
586                 RDEBUG2("Failed to authenticate the user");
587                 request->reply->code = PW_CODE_ACCESS_REJECT;
588
589                 if ((module_msg = fr_pair_find_by_num(request->packet->vps, PW_MODULE_FAILURE_MESSAGE, 0, TAG_ANY)) != NULL){
590                         char msg[MAX_STRING_LEN+19];
591
592                         snprintf(msg, sizeof(msg), "Login incorrect (%s)",
593                                  module_msg->vp_strvalue);
594                         rad_authlog(msg, request, 0);
595                 } else {
596                         rad_authlog("Login incorrect", request, 0);
597                 }
598
599                 if (request->password) {
600                         VERIFY_VP(request->password);
601                         /* double check: maybe the secret is wrong? */
602                         if ((rad_debug_lvl > 1) && (request->password->da->attr == PW_USER_PASSWORD)) {
603                                 uint8_t const *p;
604
605                                 p = (uint8_t const *) request->password->vp_strvalue;
606                                 while (*p) {
607                                         int size;
608
609                                         size = fr_utf8_char(p, -1);
610                                         if (!size) {
611                                                 RWDEBUG("Unprintable characters in the password.  Double-check the "
612                                                         "shared secret on the server and the NAS!");
613                                                 break;
614                                         }
615                                         p += size;
616                                 }
617                         }
618                 }
619         }
620
621 #ifdef WITH_SESSION_MGMT
622         if (result >= 0 &&
623             (check_item = fr_pair_find_by_num(request->config, PW_SIMULTANEOUS_USE, 0, TAG_ANY)) != NULL) {
624                 int r, session_type = 0;
625                 char            logstr[1024];
626                 char            umsg[MAX_STRING_LEN + 1];
627
628                 tmp = fr_pair_find_by_num(request->config, PW_SESSION_TYPE, 0, TAG_ANY);
629                 if (tmp) {
630                         session_type = tmp->vp_integer;
631                         RDEBUG2("Using Session-Type %s",
632                                 dict_valnamebyattr(PW_SESSION_TYPE, 0, session_type));
633                 }
634
635                 /*
636                  *      User authenticated O.K. Now we have to check
637                  *      for the Simultaneous-Use parameter.
638                  */
639                 if (request->username &&
640                     (r = process_checksimul(session_type, request, check_item->vp_integer)) != 0) {
641                         char mpp_ok = 0;
642
643                         if (r == 2){
644                                 /* Multilink attempt. Check if port-limit > simultaneous-use */
645                                 VALUE_PAIR *port_limit;
646
647                                 if ((port_limit = fr_pair_find_by_num(request->reply->vps, PW_PORT_LIMIT, 0, TAG_ANY)) != NULL &&
648                                         port_limit->vp_integer > check_item->vp_integer){
649                                         RDEBUG2("MPP is OK");
650                                         mpp_ok = 1;
651                                 }
652                         }
653                         if (!mpp_ok){
654                                 if (check_item->vp_integer > 1) {
655                                         snprintf(umsg, sizeof(umsg), "%s (%u)", main_config.denied_msg,
656                                                  check_item->vp_integer);
657                                 } else {
658                                         strlcpy(umsg, main_config.denied_msg, sizeof(umsg));
659                                 }
660
661                                 request->reply->code = PW_CODE_ACCESS_REJECT;
662
663                                 /*
664                                  *      They're trying to log in too many times.
665                                  *      Remove ALL reply attributes.
666                                  */
667                                 fr_pair_list_free(&request->reply->vps);
668                                 pair_make_reply("Reply-Message", umsg, T_OP_SET);
669
670                                 snprintf(logstr, sizeof(logstr), "Multiple logins (max %d) %s",
671                                         check_item->vp_integer,
672                                         r == 2 ? "[MPP attempt]" : "");
673                                 rad_authlog(logstr, request, 1);
674
675                                 result = -1;
676                         }
677                 }
678         }
679 #endif
680
681         /*
682          *      Result should be >= 0 here - if not, it means the user
683          *      is rejected, so we just process post-auth and return.
684          */
685         if (result < 0) {
686                 return RLM_MODULE_REJECT;
687         }
688
689         /*
690          *      Set the reply to Access-Accept, if it hasn't already
691          *      been set to something.  (i.e. Access-Challenge)
692          */
693         if (request->reply->code == 0) {
694                 request->reply->code = PW_CODE_ACCESS_ACCEPT;
695         }
696
697         return result;
698 }
699
700 /*
701  *      Run a virtual server auth and postauth
702  *
703  */
704 int rad_virtual_server(REQUEST *request)
705 {
706         VALUE_PAIR *vp;
707         int result;
708
709         RDEBUG("Virtual server %s received request", request->server);
710         rdebug_pair_list(L_DBG_LVL_1, request, request->packet->vps, NULL);
711
712         RDEBUG("server %s {", request->server);
713         RINDENT();
714
715         /*
716          *      We currently only handle AUTH packets here.
717          *      This could be expanded to handle other packets as well if required.
718          */
719         rad_assert(request->packet->code == PW_CODE_ACCESS_REQUEST);
720
721         result = rad_authenticate(request);
722
723         if (request->reply->code == PW_CODE_ACCESS_REJECT) {
724                 fr_pair_delete_by_num(&request->config, PW_POST_AUTH_TYPE, 0, TAG_ANY);
725                 vp = pair_make_config("Post-Auth-Type", "Reject", T_OP_SET);
726                 if (vp) rad_postauth(request);
727         }
728
729         if (request->reply->code == PW_CODE_ACCESS_ACCEPT) {
730                 rad_postauth(request);
731         }
732
733         REXDENT();
734         RDEBUG("} # server %s", request->server);
735
736         RDEBUG("Virtual server sending reply");
737         rdebug_pair_list(L_DBG_LVL_1, request, request->reply->vps, NULL);
738
739         return result;
740 }