Parse attributes that are string
authorAlan T. DeKok <aland@freeradius.org>
Wed, 1 Oct 2008 12:11:21 +0000 (14:11 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 15 Oct 2008 13:18:13 +0000 (15:18 +0200)
Foo = "bar baz"

  This needs to be parsed as a type, not as a string, if Foo is date,
for example.

src/lib/valuepair.c

index 22a9f34..f4086ab 100644 (file)
@@ -1701,16 +1701,45 @@ VALUE_PAIR *pairread(const char **ptr, FR_TOKEN *eol)
                        vp->flags.do_xlat = 1;
                        vp->length = 0;
                } else {
-               case T_SINGLE_QUOTED_STRING:
-                       vp = pairmake(attr, NULL, token);
-                       if (vp) {
-                               strlcpy(vp->vp_strvalue, value,
-                                       sizeof(vp->vp_strvalue));
-                               vp->length = strlen(vp->vp_strvalue);
+                       /*
+                        *      Parse && escape it, as defined by the
+                        *      data type.
+                        */
+                       vp = pairmake(attr, value, token);
+                       if (!vp) {
+                               *eol = T_OP_INVALID;
+                               return NULL;
                        }
                }
                break;
 
+       case T_SINGLE_QUOTED_STRING:
+               vp = pairmake(attr, NULL, token);
+               if (!vp) {
+                       *eol = T_OP_INVALID;
+                       return NULL;
+               }
+
+               /*
+                *      String and octet types get copied verbatim.
+                */
+               if ((vp->type == PW_TYPE_STRING) ||
+                   (vp->type == PW_TYPE_OCTETS)) {
+                       strlcpy(vp->vp_strvalue, value,
+                               sizeof(vp->vp_strvalue));
+                       vp->length = strlen(vp->vp_strvalue);
+
+                       /*
+                        *      Everything else gets parsed: it's
+                        *      DATA, not a string!
+                        */
+               } else if (!pairparsevalue(vp, value)) {
+                               pairfree(&pair);
+                               *eol = T_OP_INVALID;
+                               return NULL;
+                       }
+               }
+               break;
 
                /*
                 *      Mark the pair to be allocated later.