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

Diff of /radius/radiusd/files.c

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

revision 1.84 by gray, Wed Oct 1 19:52:40 2003 UTC revision 1.85 by gray, Tue Oct 14 07:10:42 2003 UTC
# Line 53  Line 53 
53  #include <raddbm.h>  #include <raddbm.h>
54  #include <obstack1.h>  #include <obstack1.h>
55    
56    typedef struct locus_name {
57            struct locus_name *next;
58            char *filename;
59            size_t refcnt;
60    } Locus_symbol;
61    
62    static Symtab *locus_tab;
63    
64    void
65    locus_dup(LOCUS *dst, LOCUS *src)
66    {
67            Locus_symbol *sp;
68            
69            if (!locus_tab)
70                    locus_tab = symtab_create(sizeof(Locus_symbol), NULL);
71            sp = (Locus_symbol*) sym_lookup_or_install(locus_tab, src->file, 1);
72            sp->refcnt++;
73            dst->file = sp->filename;
74            dst->line = src->line;
75    }
76    
77    void
78    locus_free(LOCUS *loc)
79    {
80            Locus_symbol *sp = (Locus_symbol*) sym_lookup(locus_tab, loc->file);
81            if (--sp->refcnt == 0)
82                    symtab_delete(locus_tab, (Symbol*) sp);
83    }
84    
85  /*  /*
86   * Symbol tables and lists   * Symbol tables and lists
87   */   */
# Line 139  comp_op(int op, int result) Line 168  comp_op(int op, int result)
168   * parser   * parser
169   */   */
170  int  int
171  add_user_entry(Symtab *symtab, char *filename, int line,  add_user_entry(void *closure, LOCUS *loc,
172                 char *name, VALUE_PAIR *check, VALUE_PAIR *reply)                 char *name, VALUE_PAIR *check, VALUE_PAIR *reply)
173  {  {
174            Symtab *symtab = closure;
175          User_symbol *sym;          User_symbol *sym;
176    
177          /* Special handling for DEFAULT names: strip any trailing          /* Special handling for DEFAULT names: strip any trailing
# Line 153  add_user_entry(Symtab *symtab, char *fil Line 183  add_user_entry(Symtab *symtab, char *fil
183                  name = "BEGIN";                  name = "BEGIN";
184    
185          if ((check == NULL && reply == NULL)          if ((check == NULL && reply == NULL)
186              || fix_check_pairs(CF_USERS, filename, line, name, &check)              || fix_check_pairs(CF_USERS, loc, name, &check)
187              || fix_reply_pairs(CF_USERS, filename, line, name, &reply)) {              || fix_reply_pairs(CF_USERS, loc, name, &reply)) {
188                  radlog(L_ERR,                  radlog_loc(L_ERR, loc,
189                         _("%s:%d: discarding user `%s'"),                             _("discarding user `%s'"),
190                         filename,                             name);
                        line, name);  
191                  avl_free(check);                  avl_free(check);
192                  avl_free(reply);                  avl_free(reply);
193                  return 0;                  return 0;
# Line 168  add_user_entry(Symtab *symtab, char *fil Line 197  add_user_entry(Symtab *symtab, char *fil
197                    
198          sym->check = check;          sym->check = check;
199          sym->reply = reply;          sym->reply = reply;
200          sym->lineno = line;          locus_dup(&sym->loc, loc);
201          return 0;          return 0;
202  }  }
203    
204  static int  static int
205  free_user_entry(User_symbol *sym)  free_user_entry(User_symbol *sym)
206  {  {
207            locus_free(&sym->loc);
208          avl_free(sym->check);          avl_free(sym->check);
209          avl_free(sym->reply);          avl_free(sym->reply);
210          return 0;          return 0;
# Line 187  struct temp_list { Line 217  struct temp_list {
217  };  };
218    
219  int  int
220  add_pairlist(struct temp_list *closure, char *filename, int line,  add_pairlist(void *closure, LOCUS *loc,
221               char *name, VALUE_PAIR *lhs, VALUE_PAIR *rhs)               char *name, VALUE_PAIR *lhs, VALUE_PAIR *rhs)
222  {  {
223            struct temp_list *tlist = closure;
224          MATCHING_RULE *pl;          MATCHING_RULE *pl;
225                    
226          if ((lhs == NULL && rhs == NULL)          if ((lhs == NULL && rhs == NULL)
227              || fix_check_pairs(closure->cf_file, filename, line, name, &lhs)              || fix_check_pairs(tlist->cf_file, loc, name, &lhs)
228              || fix_reply_pairs(closure->cf_file, filename, line, name, &rhs)) {              || fix_reply_pairs(tlist->cf_file, loc, name, &rhs)) {
229                  radlog(L_ERR,                  radlog_loc(L_ERR, loc, _("discarding entry `%s'"), name);
                        _("%s:%d: discarding entry `%s'"),  
                        filename,  
                        line, name);  
230                  avl_free(lhs);                  avl_free(lhs);
231                  avl_free(rhs);                  avl_free(rhs);
232                  return 0;                  return 0;
# Line 208  add_pairlist(struct temp_list *closure, Line 236  add_pairlist(struct temp_list *closure,
236          pl->name = estrdup(name);          pl->name = estrdup(name);
237          pl->lhs = lhs;          pl->lhs = lhs;
238          pl->rhs = rhs;          pl->rhs = rhs;
239          pl->lineno = line;          locus_dup(&pl->loc, loc);
240          if (closure->tail)          if (tlist->tail)
241                  closure->tail->next = pl;                  tlist->tail->next = pl;
242          else          else
243                  closure->head = pl;                  tlist->head = pl;
244          closure->tail = pl;          tlist->tail = pl;
245          return  0;          return  0;
246  }  }
247    
# Line 376  match_user(User_symbol *sym, RADIUS_REQ Line 404  match_user(User_symbol *sym, RADIUS_REQ
404                  }                  }
405                  if (!fallthrough(sym->reply))                  if (!fallthrough(sym->reply))
406                          break;                          break;
407                  debug(1, ("fall through near line %d", sym->lineno));                  debug(1, ("fall through near %s:%lu",
408                              sym->loc.file, (unsigned long) sym->loc.line));
409          } while (sym = sym_next((Symbol*)sym));          } while (sym = sym_next((Symbol*)sym));
410    
411          return found;          return found;
# Line 520  userparse(char *buffer, VALUE_PAIR **fir Line 549  userparse(char *buffer, VALUE_PAIR **fir
549          int             op;          int             op;
550          static char errbuf[512];          static char errbuf[512];
551          char token[256];          char token[256];
552            LOCUS loc;
553    
554            loc.file = "<stdin>"; /* FIXME */
555            loc.line = 0;
556            
557          state = PS_LHS;          state = PS_LHS;
558          while (nextkn(&buffer, token, sizeof(token))) {          while (nextkn(&buffer, token, sizeof(token))) {
559                  switch (state) {                  switch (state) {
# Line 550  userparse(char *buffer, VALUE_PAIR **fir Line 583  userparse(char *buffer, VALUE_PAIR **fir
583                          break;                          break;
584                                                    
585                  case PS_RHS:                  case PS_RHS:
586                          pair = install_pair("<stdin>", 0, attr->name,                          pair = install_pair(&loc, attr->name, op, token);
                                              op, token);  
587                          if (!pair) {                          if (!pair) {
588                                  snprintf(errbuf, sizeof(errbuf),                                  snprintf(errbuf, sizeof(errbuf),
589                                           _("install_pair failed on %s"),                                           _("install_pair failed on %s"),
# Line 606  hints_eval_compat(RADIUS_REQ *req, VALUE Line 638  hints_eval_compat(RADIUS_REQ *req, VALUE
638          if ((tmp = avl_find(i->rhs, DA_REWRITE_FUNCTION))          if ((tmp = avl_find(i->rhs, DA_REWRITE_FUNCTION))
639              || (tmp = avl_find(i->lhs, DA_REWRITE_FUNCTION))) {              || (tmp = avl_find(i->lhs, DA_REWRITE_FUNCTION))) {
640                  if (rewrite_eval(tmp->avp_strvalue, req, NULL, NULL)) {                  if (rewrite_eval(tmp->avp_strvalue, req, NULL, NULL)) {
641                          radlog(L_ERR, "hints:%d: %s(): %s",                          radlog_loc(L_ERR, &i->loc, "%s(): %s",
642                                 i->lineno,                                     tmp->avp_strvalue,
643                                 tmp->avp_strvalue,                                     _("not defined"));
                                _("not defined"));  
644                  }                  }
645          }          }
646  }  }
# Line 678  hints_setup(RADIUS_REQ *req) Line 709  hints_setup(RADIUS_REQ *req)
709    
710                  matched++;                  matched++;
711                                    
712                  debug(1, ("matched %s at hints:%d", i->name, i->lineno));                  debug(1, ("matched %s at %s:%lu", i->name, i->loc.file,
713                              (unsigned long) i->loc.line));
714                    
715                  add = avl_dup(i->rhs);                  add = avl_dup(i->rhs);
716                    
# Line 751  huntgroup_match(RADIUS_REQ *req, char *h Line 783  huntgroup_match(RADIUS_REQ *req, char *h
783                  if (strcmp(pl->name, huntgroup) != 0)                  if (strcmp(pl->name, huntgroup) != 0)
784                          continue;                          continue;
785                  if (paircmp(req, pl->lhs, NULL) == 0) {                  if (paircmp(req, pl->lhs, NULL) == 0) {
786                          debug(1, ("matched %s at huntgroups:%d",                          debug(1, ("matched %s at %s:%lu",
787                                   pl->name, pl->lineno));                                    pl->name, pl->loc.file,
788                                      (unsigned long) pl->loc.line));
789                          break;                          break;
790                  }                  }
791          }          }
# Line 783  huntgroup_access(RADIUS_REQ *radreq) Line 816  huntgroup_access(RADIUS_REQ *radreq)
816                   */                   */
817                  if (paircmp(radreq, pl->lhs, NULL) != 0)                  if (paircmp(radreq, pl->lhs, NULL) != 0)
818                          continue;                          continue;
819                  debug(1, ("matched huntgroup at huntgroups:%d", pl->lineno));                  debug(1, ("matched huntgroup at %s:%lu", pl->loc.file,
820                              (unsigned long) pl->loc.line));
821                  r = paircmp(radreq, pl->rhs, NULL) == 0;                  r = paircmp(radreq, pl->rhs, NULL) == 0;
822                  break;                  break;
823          }          }
# Line 792  huntgroup_access(RADIUS_REQ *radreq) Line 826  huntgroup_access(RADIUS_REQ *radreq)
826          if (pl &&          if (pl &&
827              (pair = avl_find(pl->lhs, DA_REWRITE_FUNCTION)) != NULL) {              (pair = avl_find(pl->lhs, DA_REWRITE_FUNCTION)) != NULL) {
828                  if (rewrite_eval(pair->avp_strvalue, radreq, NULL, NULL)) {                  if (rewrite_eval(pair->avp_strvalue, radreq, NULL, NULL)) {
829                          radlog(L_ERR, "huntgroups:%d: %s(): %s",                          radlog_loc(L_ERR, &pl->loc, "%s(): %s",
830                                 pl->lineno,                                     pair->avp_strvalue,
831                                 pair->avp_strvalue,                                     _("not defined"));
                                _("not defined"));  
832                  }                  }
833          }          }
834  #endif    #endif  
# Line 822  read_naslist_file(char *file) Line 855  read_naslist_file(char *file)
855   */   */
856  /*ARGSUSED*/  /*ARGSUSED*/
857  int  int
858  read_clients_entry(void *u ARG_UNUSED, int fc, char **fv,  read_clients_entry(void *u ARG_UNUSED, int fc, char **fv, LOCUS *loc)
                    char *file, int lineno)  
859  {  {
860          CLIENT *cp;          CLIENT *cp;
861                    
862          if (fc != 2) {          if (fc != 2) {
863                  radlog(L_ERR, "%s:%d: %s",                  radlog_loc(L_ERR, loc, "%s", _("wrong number of fields"));
                        file, lineno,  
                        _("wrong number of fields"));  
864                  return -1;                  return -1;
865          }          }
866    
# Line 912  client_lookup_name(UINT4 ipaddr, char *b Line 942  client_lookup_name(UINT4 ipaddr, char *b
942   */   */
943  /*ARGSUSED*/  /*ARGSUSED*/
944  int  int
945  read_nastypes_entry(void *u ARG_UNUSED, int fc, char **fv,  read_nastypes_entry(void *u ARG_UNUSED, int fc, char **fv, LOCUS *loc)
                     char *file, int lineno)  
946  {  {
947          RADCK_TYPE *mp;          RADCK_TYPE *mp;
948          int method;          int method;
949    
950          if (fc < 2) {          if (fc < 2) {
951                  radlog(L_ERR, "%s:%d: %s", file, lineno,                  radlog_loc(L_ERR, loc, "%s", _("too few fields"));
                        _("too few fields"));  
952                  return -1;                  return -1;
953          }          }
954    
# Line 931  read_nastypes_entry(void *u ARG_UNUSED, Line 959  read_nastypes_entry(void *u ARG_UNUSED,
959          else if (strcmp(fv[1], "ext") == 0)          else if (strcmp(fv[1], "ext") == 0)
960                  method = METHOD_EXT;                  method = METHOD_EXT;
961          else {          else {
962                  radlog(L_ERR, "%s:%d: %s", file, lineno, _("unknown method"));                  radlog_loc(L_ERR, loc, "%s", _("unknown method"));
963                  return -1;                  return -1;
964          }          }
965                                                    
# Line 997  add_deny(char *user) Line 1025  add_deny(char *user)
1025    
1026  /*ARGSUSED*/  /*ARGSUSED*/
1027  int  int
1028  read_denylist_entry(int *denycnt, int fc, char **fv, char *file, int lineno)  read_denylist_entry(void *closure, int fc, char **fv, LOCUS *loc)
1029  {  {
1030          if (fc != 1) {          int *denycnt = closure;
1031                  radlog(L_ERR,          if (fc != 1) {
1032                         "%s:%d: %s",                  radlog_loc(L_ERR, loc, "%s", _("wrong number of fields"));
                        file, lineno,  
                        _("wrong number of fields"));  
1033                  return -1;                  return -1;
1034          }          }
1035    
1036          if (get_deny(fv[0]))          if (get_deny(fv[0]))
1037                  radlog(L_ERR, _("user `%s' already found in %s"),                  radlog_loc(L_ERR, loc, _("user `%s' already found in %s"),
1038                      fv[0], RADIUS_DENY);                             fv[0], RADIUS_DENY);
1039          else {          else {
1040                  add_deny(fv[0]);                  add_deny(fv[0]);
1041                  (*denycnt)++;                  (*denycnt)++;

Legend:
Removed from v.1.84  
changed lines
  Added in v.1.85

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