made the library code support generic 'octets' type (raw hex)
authoraland <aland>
Tue, 31 Aug 1999 00:31:37 +0000 (00:31 +0000)
committeraland <aland>
Tue, 31 Aug 1999 00:31:37 +0000 (00:31 +0000)
made library use raw octets for ascend 'abinary' type, even if
the ascend code isn't compiled in.

src/lib/dict.c
src/lib/print.c
src/lib/radius.c
src/lib/valuepair.c
src/main/radclient.c

index bea4f73..c3f67db 100644 (file)
@@ -32,9 +32,8 @@ static char *dtypes[] = {
        "integer",
        "ipaddr",
        "date",
-#ifdef ASCEND_BINARY
        "abinary",
-#endif
+       "octets",
        NULL,
 };
 
index 5d9b65c..e9f0df5 100644 (file)
@@ -134,12 +134,22 @@ int vp_prints(char *out, int outlen, VALUE_PAIR *vp)
                        else
                                a = ip_ntoa(NULL, vp->lvalue);
                        break;
-#ifdef ASCEND_BINARY
                case PW_TYPE_ABINARY:
+#ifdef ASCEND_BINARY
                  a = buf;
                  print_abinary(vp, buf, sizeof(buf));
                  break;
 #endif
+               case PW_TYPE_OCTETS:
+                 strcpy(buf, "0x");
+                 a = buf + 2;
+                 for (t = 0; t < vp->length; t++) {
+                   sprintf(a, "%02x", vp->strvalue[t]);
+                   a += 2;
+                 }
+                 a = buf;
+                 break;
+
                default:
                        a = "UNKNOWN-TYPE";
                        break;
index fa7b171..663b1df 100644 (file)
@@ -173,7 +173,12 @@ int rad_send(RADIUS_PACKET *packet, int activefd, char *secret)
                        if (reply->length == 0 && reply->strvalue[0] != 0)
                                reply->length = strlen(reply->strvalue);
 
+#ifndef ASCEND_BINARY
+               case PW_TYPE_ABINARY:
+#endif
+               case PW_TYPE_OCTETS:
                        len = reply->length;
+
                        if (len >= MAX_STRING_LEN) {
                                len = MAX_STRING_LEN - 1;
                        }
index fdf8626..7a11862 100644 (file)
@@ -356,7 +356,7 @@ VALUE_PAIR *pairmake(char *attribute, char *value, int operator)
        DICT_ATTR       *da;
        DICT_VALUE      *dval;
        VALUE_PAIR      *vp;
-       char            *p, *s;
+       u_char          *p, *s;
 
        if ((da = dict_attrbyname(attribute)) == NULL) {
                librad_log("unknown attribute %s", attribute);
@@ -384,6 +384,9 @@ VALUE_PAIR *pairmake(char *attribute, char *value, int operator)
        switch(da->type) {
                case PW_TYPE_STRING:
                        vp->length = strlen(value);
+                       if (vp->length >= MAX_STRING_LEN) {
+                         vp->length = MAX_STRING_LEN - 1;
+                       }
                        break;
                case PW_TYPE_IPADDR:
                        /*
@@ -437,8 +440,8 @@ VALUE_PAIR *pairmake(char *attribute, char *value, int operator)
                        }
                        vp->length = 4;
                        break;
-#ifdef ASCEND_BINARY
                case PW_TYPE_ABINARY:
+#ifdef ASCEND_BINARY
                        /*
                         * special case to convert filter to binary
                         */
@@ -451,9 +454,27 @@ VALUE_PAIR *pairmake(char *attribute, char *value, int operator)
                        break;
 
 #endif
+                       /* raw octets: 0x01020304... */
+               case PW_TYPE_OCTETS:
+                 vp->length = 0;
+                 if (strncasecmp(value, "0x", 2) == 0) {
+                   p = value + 2;
+                   s = vp->strvalue;
+                   while (*p && vp->length < MAX_STRING_LEN) {
+                     unsigned int tmp;
+
+                     if (sscanf(p, "%02x", &tmp) != 1) break;
+                     p += 2;
+                     *(s++) = tmp;
+                     vp->length++;
+                   }
+                   *s = '\0';
+                 }
+                 break;
+
                default:
                        free(vp);
-                       librad_log("unknown attribute type");
+                       librad_log("unknown attribute type %d", da->type);
                        return NULL;
        }
        return vp;
index 325c370..0fdf696 100644 (file)
@@ -109,6 +109,7 @@ int main(int argc, char **argv)
                        librad_debug = 1;
                        break;
                case 't':
+                       if (!isdigit(*optarg)) usage();
                        timeout = atoi(optarg);
                        break;
                default: