Calling policies is now done by foo(), not by "call foo"
authoraland <aland>
Wed, 8 Dec 2004 22:05:31 +0000 (22:05 +0000)
committeraland <aland>
Wed, 8 Dec 2004 22:05:31 +0000 (22:05 +0000)
src/modules/rlm_policy/evaluate.c
src/modules/rlm_policy/parse.c
src/modules/rlm_policy/rlm_policy.c
src/modules/rlm_policy/rlm_policy.h

index 1262bab..53cec7c 100644 (file)
@@ -867,13 +867,11 @@ static int evaluate_call(policy_state_t *state, const policy_item_t *item)
 {\r
        int rcode;\r
        const policy_call_t *this;\r
-       rlm_policy_name_t mypolicy;\r
        const rlm_policy_name_t *policy;\r
 \r
        this = (const policy_call_t *) item;\r
 \r
-       strNcpy(mypolicy.name, this->name, sizeof(mypolicy.name));\r
-       policy = rbtree_finddata(state->inst->policies, &mypolicy);\r
+       policy = rlm_policy_find(state->inst->policies, this->name);\r
        if (!policy) return 0;  /* not found... */\r
        \r
        DEBUG2("rlm_policy: Evaluating policy %s", this->name);\r
index 1bec67a..3a2589f 100644 (file)
@@ -501,7 +501,6 @@ const LRAD_NAME_NUMBER policy_reserved_words[] = {
        { "debug", POLICY_RESERVED_DEBUG },
        { "print", POLICY_RESERVED_PRINT },
        { "policy", POLICY_RESERVED_POLICY },
-       { "call", POLICY_RESERVED_CALL },
        { "control", POLICY_RESERVED_CONTROL },
        { "request", POLICY_RESERVED_REQUEST },
        { "reply", POLICY_RESERVED_REPLY },
@@ -834,6 +833,7 @@ static int parse_named_policy(policy_lex_file_t *lexer, policy_item_t **tail)
        policy_lex_t token;
        char mystring[256];
        policy_named_t *this;
+       DICT_ATTR *dattr;
 
        tail = tail;            /* -Wunused */
 
@@ -854,6 +854,14 @@ static int parse_named_policy(policy_lex_file_t *lexer, policy_item_t **tail)
                return 0;
        }
 
+       dattr = dict_attrbyname(mystring);
+       if (dattr) {
+               fprintf(stderr, "%s[%d]: Invalid policy name \"%s\": it is already defined as a dictionary attribute\n",
+                       lexer->filename, lexer->lineno, mystring);
+               rlm_policy_free_item((policy_item_t *) this);
+               return 0;
+       }
+
        rcode = parse_block(lexer, &(this->policy));
        if (!rcode) {
                rlm_policy_free_item((policy_item_t *) this);
@@ -886,30 +894,37 @@ static int parse_named_policy(policy_lex_file_t *lexer, policy_item_t **tail)
 /*
  *     Parse a reference to a named policy "call foo"
  */
-static int parse_call(policy_lex_file_t *lexer, policy_item_t **tail)
+static int parse_call(policy_lex_file_t *lexer, policy_item_t **tail,
+                     const char *name)
 {
        policy_lex_t token;
-       char mystring[256];
        policy_call_t *this;
 
        debug_tokens("[CALL] ");
 
-       this = rad_malloc(sizeof(*this));
-       memset(this, 0, sizeof(*this));
-
-       this->item.type = POLICY_TYPE_CALL;
-       this->item.lineno = lexer->lineno;
+       token = policy_lex_file(lexer, 0, NULL, 0);
+       if (token != POLICY_LEX_L_BRACKET) {
+               fprintf(stderr, "%s[%d]: Expected left bracket, got \"%s\"\n",
+                       lexer->filename, lexer->lineno,
+                       lrad_int2str(rlm_policy_tokens, token, "?"));
+               return 0;
+       }
 
-       token = policy_lex_file(lexer, 0, mystring, sizeof(mystring));
-       if (token != POLICY_LEX_BARE_WORD) {
-               fprintf(stderr, "%s[%d]: Expected policy name, got \"%s\"\n",
+       token = policy_lex_file(lexer, 0, NULL, 0);
+       if (token != POLICY_LEX_R_BRACKET) {
+               fprintf(stderr, "%s[%d]: Expected right bracket, got \"%s\"\n",
                        lexer->filename, lexer->lineno,
                        lrad_int2str(rlm_policy_tokens, token, "?"));
-               rlm_policy_free_item((policy_item_t *) this);
                return 0;
        }
 
-       this->name = strdup(mystring);
+       this = rad_malloc(sizeof(*this));
+       memset(this, 0, sizeof(*this));
+
+       this->item.type = POLICY_TYPE_CALL;
+       this->item.lineno = lexer->lineno;
+
+       this->name = strdup(name);
 
        *tail = (policy_item_t *) this;
 
@@ -1029,14 +1044,13 @@ static int parse_statement(policy_lex_file_t *lexer, policy_item_t **tail)
                        return 0;
                        break;
 
-               case POLICY_RESERVED_CALL:
-                       if (parse_call(lexer, tail)) {
-                               return 1;
+               case POLICY_RESERVED_UNKNOWN: /* wasn't a reserved word */
+                       if (rlm_policy_find(lexer->policies, lhs)) {
+                               if (parse_call(lexer, tail, lhs)) {
+                                       return 1;
+                               }
                        }
-                       return 0;
-                       break;
 
-               case POLICY_RESERVED_UNKNOWN: /* wasn't a reserved word */
                        /*
                         *      Maybe include another file.
                         */
index aba5e76..7579366 100644 (file)
@@ -152,6 +152,18 @@ int rlm_policy_insert(rbtree_t *head, const char *name, policy_item_t *policy)
 
 
 /*
+ *     Insert a named policy into a list.
+ */
+rlm_policy_name_t *rlm_policy_find(rbtree_t *head, const char *name)
+{
+       rlm_policy_name_t mypolicy;
+
+       strNcpy(mypolicy.name, name, sizeof(mypolicy.name));
+       return rbtree_finddata(head, &mypolicy);
+}
+
+
+/*
  *     Find the named user in this modules database.  Create the set
  *     of attribute-value pairs to check and reply with for this user
  *     from the database. The authentication code only needs to check
index ed83db9..f2db8c5 100644 (file)
@@ -108,7 +108,6 @@ typedef enum policy_reserved_word_t {
        POLICY_RESERVED_DEBUG,
        POLICY_RESERVED_PRINT,
        POLICY_RESERVED_POLICY,
-       POLICY_RESERVED_CALL,
        POLICY_RESERVED_NUM_WORDS
 } policy_reserved_word_t;
 
@@ -239,6 +238,7 @@ extern const LRAD_NAME_NUMBER policy_reserved_words[];
 
 extern int rlm_policy_insert(rbtree_t *head, const char *name,
                             policy_item_t *policy);
+extern rlm_policy_name_t *rlm_policy_find(rbtree_t *head, const char *name);
 
 extern int rlm_policy_parse(rlm_policy_t * inst, const char *filename);
 extern void rlm_policy_free_item(policy_item_t *item);