/[radius]/radius/radiusd/radius.c
ViewVC logotype

Diff of /radius/radiusd/radius.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.56 by gray, Thu Oct 16 06:40:56 2003 UTC revision 1.57 by gray, Thu Oct 16 11:23:56 2003 UTC
# Line 22  Line 22 
22  #endif  #endif
23    
24  #include <radiusd.h>  #include <radiusd.h>
25    #include <obstack1.h>
26    
27  /* Build and send a reply to the incoming request.  /* Build and send a reply to the incoming request.
28     Input: code        -- Reply code.     Input: code        -- Reply code.
# Line 482  radius_respond(REQUEST *req) Line 483  radius_respond(REQUEST *req)
483                             radreq->code);                             radreq->code);
484                  return -1;                  return -1;
485          }                }      
486    
487            radius_trace_path(radreq);
488            
489          return 0;          return 0;
490  }  }
491    
492  void  void
493  radius_req_register_locus(RADIUS_REQ *req, LOCUS *loc)  radius_req_register_locus(RADIUS_REQ *req, LOCUS *loc)
494  {  {
495          /*if (!some_global_flag)          switch (req->code) {
496               return; */          case RT_AUTHENTICATION_REQUEST:
497            case RT_AUTHENTICATION_ACK:
498            case RT_AUTHENTICATION_REJECT:
499            case RT_ACCESS_CHALLENGE:
500                    if (!auth_trace_rules)
501                            return;
502                    break;
503                    
504            case RT_ACCOUNTING_REQUEST:
505            case RT_ACCOUNTING_RESPONSE:
506            case RT_ACCOUNTING_STATUS:
507            case RT_ACCOUNTING_MESSAGE:
508                    if (!acct_trace_rules)
509                            return;
510                    break;
511    
512            default:
513                    return;
514            }
515    
516            if (!req->locus_list)
517                    req->locus_list = list_create();
518            
519          list_prepend(req->locus_list, loc);          list_prepend(req->locus_list, loc);
520  }  }
521    
522    struct trace_data {
523            struct obstack stk;
524            char *file;
525    };
526    
527    static char *
528    skip_common_substring(char *str, char *pat)
529    {
530            char *start = str;
531    
532            while (*str == *pat++)
533                    if (*str++ == '/')
534                            start = str;
535            return start;
536    }
537    
538    static int
539    _trace_path_compose(void *item, void *data)
540    {
541            LOCUS *loc = item;
542            struct trace_data *td = data;
543            char buf[64];
544            
545            if (!td->file) {
546                    td->file = loc->file;
547                    obstack_grow(&td->stk, loc->file, strlen(loc->file));
548                    obstack_1grow(&td->stk, ':');
549            } else if (strcmp(td->file, loc->file) == 0) {
550                    obstack_1grow(&td->stk, ',');
551            } else {
552                    char *p;
553                    
554                    obstack_1grow(&td->stk, ';');
555                    obstack_1grow(&td->stk, ' ');
556                    
557                    p = skip_common_substring(loc->file, td->file);
558                    obstack_grow(&td->stk, p, strlen(p));
559                    obstack_1grow(&td->stk, ':');
560                    td->file = loc->file;
561            }
562    
563            snprintf(buf, sizeof buf, "%lu", (unsigned long) loc->line);
564            obstack_grow(&td->stk, buf, strlen(buf));
565            
566            return 0;
567    }
568    
569    void
570    radius_trace_path(RADIUS_REQ *req)
571    {
572            struct trace_data td;
573            char *p;
574            
575            if (!req->locus_list)
576                    return;
577            
578            obstack_init(&td.stk);
579            td.file = NULL;
580            list_iterate(req->locus_list, _trace_path_compose, &td);
581            p = obstack_finish(&td.stk);
582            radlog_req(L_INFO, req, _("rule trace: %s"), p);
583            obstack_free(&td.stk, NULL);
584    }

Legend:
Removed from v.1.56  
changed lines
  Added in v.1.57

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26