Patches from Joe Maimon to fix some edge conditions
authoraland <aland>
Tue, 18 Oct 2005 19:05:40 +0000 (19:05 +0000)
committeraland <aland>
Tue, 18 Oct 2005 19:05:40 +0000 (19:05 +0000)
src/modules/rlm_policy/evaluate.c
src/modules/rlm_policy/parse.c

index b38a150..a3cf2be 100644 (file)
@@ -356,6 +356,7 @@ static int policy_stack_pop(policy_state_t *state, const policy_item_t **pitem)
         *      Named policies are on the stack for catching recursion.
         */
        if ((*pitem)->type == POLICY_TYPE_NAMED_POLICY) {
+               state->depth--;
                goto redo;
        }
 
@@ -490,7 +491,7 @@ static int evaluate_condition(policy_state_t *state, const policy_item_t *item)
 {
        int rcode;
        const policy_condition_t *this;
-       VALUE_PAIR *vp;
+       VALUE_PAIR *vp = NULL;
        const char *data = NULL;
        int compare;
 #ifdef HAVE_REGEX_H
@@ -534,6 +535,15 @@ static int evaluate_condition(policy_state_t *state, const policy_item_t *item)
                rcode = (rcode == FALSE); /* reverse sense of test */
                break;
 
+       case POLICY_LEX_CMP_FALSE: /* non-existence */
+               if (this->lhs_type == POLICY_LEX_BARE_WORD) {
+                       vp = find_vp(state->request, this->lhs);
+                       rcode = (vp == NULL);
+               } else {
+                       rcode = (data == NULL);
+               }
+               break;
+
        case POLICY_LEX_CMP_TRUE: /* existence */
                if (this->lhs_type == POLICY_LEX_BARE_WORD) {
                        vp = find_vp(state->request, this->lhs);
@@ -562,24 +572,22 @@ static int evaluate_condition(policy_state_t *state, const policy_item_t *item)
                if (this->lhs_type == POLICY_LEX_BARE_WORD) {
                        VALUE_PAIR *myvp;
 
-
                        vp = find_vp(state->request, this->lhs);
+
+                       /*
+                        *      A op B always returns FALSE if A doesn't
+                        *      exist.
+                        */
+                       if (!vp) return FALSE; /* not in the request */
+
                        /*
                         *      FIXME: Move sanity checks to
                         *      post-parse code, so we don't do
                         *      it on every packet.
                         */
-                       if (vp) {
-                               vp_prints_value(buffer, sizeof(buffer), vp, 0);
-                               myvp = pairmake(vp->name, this->rhs, T_OP_EQ);
-                       } else {
-                               buffer[0] = '\0';
-                               myvp = pairmake(this->lhs, this->rhs, T_OP_EQ);
-                       }
+                       vp_prints_value(buffer, sizeof(buffer), vp, 0);
+                       myvp = pairmake(vp->name, this->rhs, T_OP_EQ);
                        data = buffer;
-                       if (!myvp) {
-                               return FALSE;
-                       }
 
                        /*
                         *      FIXME: What to do about comparisons
index 25f592f..129ad2e 100644 (file)
@@ -98,6 +98,8 @@ const LRAD_NAME_NUMBER rlm_policy_tokens[] = {
        { "=", POLICY_LEX_ASSIGN },
        { "==", POLICY_LEX_CMP_EQUALS },
        { "!=", POLICY_LEX_CMP_NOT_EQUALS },
+       { "=*", POLICY_LEX_CMP_TRUE },
+       { "!*", POLICY_LEX_CMP_FALSE },
        { "<", POLICY_LEX_LT },
        { ">", POLICY_LEX_GT },
        { "<=", POLICY_LEX_LE },
@@ -699,8 +701,8 @@ static int parse_condition(policy_lex_file_t *lexer, policy_item_t **tail)
                                        lrad_int2str(rlm_policy_tokens, token, "?"));
                                return 0;
                        }
-                       goto check;
                } /* else it's a comparison? */
+               goto check;
 
        case POLICY_LEX_DOUBLE_QUOTED_STRING:
                this->lhs_type = token;
@@ -723,6 +725,8 @@ static int parse_condition(policy_lex_file_t *lexer, policy_item_t **tail)
                case POLICY_LEX_CMP_NOT_EQUALS:
                case POLICY_LEX_RX_EQUALS:
                case POLICY_LEX_RX_NOT_EQUALS:
+               case POLICY_LEX_CMP_TRUE:
+               case POLICY_LEX_CMP_FALSE:
                case POLICY_LEX_LT:
                case POLICY_LEX_GT:
                case POLICY_LEX_LE: