~ubuntu-branches/ubuntu/natty/freeradius/natty-updates

« back to all changes in this revision

Viewing changes to src/lib/valuepair.c

  • Committer: Bazaar Package Importer
  • Author(s): Josip Rodin
  • Date: 2009-11-23 03:57:37 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20091123035737-zsgtzhfych8hir68
Tags: 2.1.7+dfsg-1
* Adopting the package, closes: #536623.
* New upstream version, closes: #513484.
  + Fixes the blooper in unlang evaluation logic, closes: #526175.
* Used quilt (and added README.source), and moved upstream file patching
  into debian/patches/. The source is no longer in collab-maint git
  (to make it simpler for me to finally get this out the door), but
  kept the .gitignore should we need that again.
* Dropped the dialup_admin/bin/backup_radacct patch (integrated upstream).
* Dropped the raddb/Makefile patch (problem no longer exists upstream).
* Dropped the lib/packet.c lib/radius.c main/listen.c patches (was from
  upstream 2.0.5 anyway).
* Dropped references to otp.conf, it no longer exists upstream.
  Keep removing the conffile statoverride in prerm.
* Dropped references to snmp.conf, it no longer exists upstream.
  Keep removing the conffile statoverride in prerm.
* Ship /etc/freeradius/modules/* in the freeradius package.
* Stop shipping sites-enabled symlinks in the package and instead create
  them only on initial install, thanks to Matej Vela, closes: #533396.
* Add export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" to the init script
  at the request of John Morrissey, closes: #550143.
* Stop installing /var/run/freeradius in the package to silence Lintian.
  The init script already recreates it at will.
* Remove executable bit from example.pl to silence Lintian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * valuepair.c  Functions to handle VALUE_PAIRs
3
3
 *
4
 
 * Version:     $Id: valuepair.c,v 1.141 2008/04/18 14:09:56 aland Exp $
 
4
 * Version:     $Id$
5
5
 *
6
6
 *   This library is free software; you can redistribute it and/or
7
7
 *   modify it under the terms of the GNU Lesser General Public
21
21
 */
22
22
 
23
23
#include <freeradius-devel/ident.h>
24
 
RCSID("$Id: valuepair.c,v 1.141 2008/04/18 14:09:56 aland Exp $")
 
24
RCSID("$Id$")
25
25
 
26
26
#include        <freeradius-devel/libradius.h>
27
27
 
100
100
                case PW_TYPE_INTEGER:
101
101
                case PW_TYPE_IPADDR:
102
102
                case PW_TYPE_DATE:
 
103
                case PW_TYPE_SIGNED:
103
104
                        vp->length = 4;
104
105
                        break;
105
106
 
119
120
                        vp->length = sizeof(vp->vp_ether);
120
121
                        break;
121
122
 
 
123
                case PW_TYPE_TLV:
 
124
                        vp->vp_tlv = NULL;
 
125
                        vp->length = 0;
 
126
                        break;
 
127
 
 
128
                case PW_TYPE_COMBO_IP:
122
129
                default:
123
130
                        vp->length = 0;
124
131
                        break;
138
145
 
139
146
        da = dict_attrbyvalue(attr);
140
147
        if ((vp = pairalloc(da)) == NULL) {
141
 
                librad_log("out of memory");
 
148
                fr_strerror_printf("out of memory");
142
149
                return NULL;
143
150
        }
144
151
        vp->operator = T_OP_EQ;
169
176
 */
170
177
void pairbasicfree(VALUE_PAIR *pair)
171
178
{
 
179
        if (pair->type == PW_TYPE_TLV) free(pair->vp_tlv);
172
180
        /* clear the memory here */
173
181
        memset(pair, 0, sizeof(*pair));
174
182
        free(pair);
308
316
        }
309
317
        
310
318
        if ((n = malloc(sizeof(*n) + name_len)) == NULL) {
311
 
                librad_log("out of memory");
 
319
                fr_strerror_printf("out of memory");
312
320
                return NULL;
313
321
        }
314
322
        memcpy(n, vp, sizeof(*n) + name_len);
315
323
        n->next = NULL;
 
324
 
 
325
        if ((n->type == PW_TYPE_TLV) &&
 
326
            (n->vp_tlv != NULL)) {
 
327
                n->vp_tlv = malloc(n->length);
 
328
                memcpy(n->vp_tlv, vp->vp_tlv, n->length);
 
329
        }
 
330
 
316
331
        return n;
317
332
}
318
333
 
806
821
 *  double-check the parsed value, to be sure it's legal for that
807
822
 *  type (length, etc.)
808
823
 */
 
824
static uint32_t getint(const char *value, char **end)
 
825
{
 
826
        if ((value[0] == '0') && (value[1] == 'x')) {
 
827
                return strtoul(value, end, 16);
 
828
        }
 
829
 
 
830
        return strtoul(value, end, 10);
 
831
}
 
832
 
809
833
VALUE_PAIR *pairparsevalue(VALUE_PAIR *vp, const char *value)
810
834
{
811
835
        char            *p, *s=0;
814
838
        size_t          length;
815
839
        DICT_VALUE      *dval;
816
840
 
 
841
        if (!value) return NULL;
 
842
 
817
843
        /*
818
844
         *      Even for integers, dates and ip addresses we
819
845
         *      keep the original string in vp->vp_strvalue.
820
846
         */
821
 
        strlcpy(vp->vp_strvalue, value, sizeof(vp->vp_strvalue));
822
 
        vp->length = strlen(vp->vp_strvalue);
 
847
        if (vp->type != PW_TYPE_TLV) {
 
848
                strlcpy(vp->vp_strvalue, value, sizeof(vp->vp_strvalue));
 
849
                vp->length = strlen(vp->vp_strvalue);
 
850
        }
823
851
 
824
852
        switch(vp->type) {
825
853
                case PW_TYPE_STRING:
911
939
 
912
940
                                if (ip_hton(cs, AF_INET, &ipaddr) < 0) {
913
941
                                        free(s);
914
 
                                        librad_log("Failed to find IP address for %s", cs);
 
942
                                        fr_strerror_printf("Failed to find IP address for %s", cs);
915
943
                                        return NULL;
916
944
                                }
917
945
 
922
950
                        break;
923
951
 
924
952
                case PW_TYPE_BYTE:
925
 
                        if (value && (value[0] == '0') && (value[1] == 'x')) {
926
 
                                goto do_octets;
927
 
                        }
928
 
 
929
953
                        /*
930
954
                         *      Note that ALL integers are unsigned!
931
955
                         */
932
 
                        vp->vp_integer = (uint32_t) strtoul(value, &p, 10);
 
956
                        vp->vp_integer = getint(value, &p);
933
957
                        if (!*p) {
934
958
                                if (vp->vp_integer > 255) {
935
 
                                        librad_log("Byte value \"%s\" is larger than 255", value);
 
959
                                        fr_strerror_printf("Byte value \"%s\" is larger than 255", value);
936
960
                                        return NULL;
937
961
                                }
938
962
                                vp->length = 1;
944
968
                         *      attribute.
945
969
                         */
946
970
                        if ((dval = dict_valbyname(vp->attribute, value)) == NULL) {
947
 
                                librad_log("Unknown value %s for attribute %s",
 
971
                                fr_strerror_printf("Unknown value %s for attribute %s",
948
972
                                           value, vp->name);
949
973
                                return NULL;
950
974
                        }
956
980
                        /*
957
981
                         *      Note that ALL integers are unsigned!
958
982
                         */
959
 
                        vp->vp_integer = (uint32_t) strtoul(value, &p, 10);
 
983
                        vp->vp_integer = getint(value, &p);
960
984
                        if (!*p) {
961
985
                                if (vp->vp_integer > 65535) {
962
 
                                        librad_log("Byte value \"%s\" is larger than 65535", value);
 
986
                                        fr_strerror_printf("Byte value \"%s\" is larger than 65535", value);
963
987
                                        return NULL;
964
988
                                }
965
989
                                vp->length = 2;
971
995
                         *      attribute.
972
996
                         */
973
997
                        if ((dval = dict_valbyname(vp->attribute, value)) == NULL) {
974
 
                                librad_log("Unknown value %s for attribute %s",
 
998
                                fr_strerror_printf("Unknown value %s for attribute %s",
975
999
                                           value, vp->name);
976
1000
                                return NULL;
977
1001
                        }
983
1007
                        /*
984
1008
                         *      Note that ALL integers are unsigned!
985
1009
                         */
986
 
                        vp->vp_integer = (uint32_t) strtoul(value, &p, 10);
 
1010
                        vp->vp_integer = getint(value, &p);
987
1011
                        if (!*p) {
988
1012
                                vp->length = 4;
989
1013
                                break;
994
1018
                         *      attribute.
995
1019
                         */
996
1020
                        if ((dval = dict_valbyname(vp->attribute, value)) == NULL) {
997
 
                                librad_log("Unknown value %s for attribute %s",
 
1021
                                fr_strerror_printf("Unknown value %s for attribute %s",
998
1022
                                           value, vp->name);
999
1023
                                return NULL;
1000
1024
                        }
1013
1037
                                time_t date;
1014
1038
 
1015
1039
                                if (gettime(value, &date) < 0) {
1016
 
                                        librad_log("failed to parse time string "
 
1040
                                        fr_strerror_printf("failed to parse time string "
1017
1041
                                                   "\"%s\"", value);
1018
1042
                                        return NULL;
1019
1043
                                }
1031
1055
                        }
1032
1056
 
1033
1057
                        if (ascend_parse_filter(vp) < 0 ) {
1034
 
                                librad_log("failed to parse Ascend binary attribute: %s",
1035
 
                                           librad_errstr);
 
1058
                                fr_strerror_printf("failed to parse Ascend binary attribute: %s",
 
1059
                                           fr_strerror());
1036
1060
                                return NULL;
1037
1061
                        }
1038
1062
                        break;
1042
1066
                         *      then fall through to raw octets, so that
1043
1067
                         *      the user can at least make them by hand...
1044
1068
                         */
1045
 
#endif
1046
1069
        do_octets:
 
1070
#endif
1047
1071
                        /* raw octets: 0x01020304... */
1048
1072
                case PW_TYPE_OCTETS:
1049
1073
                        if (strncasecmp(value, "0x", 2) == 0) {
1058
1082
                                 *      die.
1059
1083
                                 */
1060
1084
                                if ((strlen(cp) & 0x01) != 0) {
1061
 
                                        librad_log("Hex string is not an even length string.");
 
1085
                                        fr_strerror_printf("Hex string is not an even length string.");
1062
1086
                                        return NULL;
1063
1087
                                }
1064
1088
 
1068
1092
                                        unsigned int tmp;
1069
1093
 
1070
1094
                                        if (sscanf(cp, "%02x", &tmp) != 1) {
1071
 
                                                librad_log("Non-hex characters at %c%c", cp[0], cp[1]);
 
1095
                                                fr_strerror_printf("Non-hex characters at %c%c", cp[0], cp[1]);
1072
1096
                                                return NULL;
1073
1097
                                        }
1074
1098
 
1081
1105
 
1082
1106
                case PW_TYPE_IFID:
1083
1107
                        if (ifid_aton(value, (void *) &vp->vp_ifid) == NULL) {
1084
 
                                librad_log("failed to parse interface-id "
 
1108
                                fr_strerror_printf("failed to parse interface-id "
1085
1109
                                           "string \"%s\"", value);
1086
1110
                                return NULL;
1087
1111
                        }
1090
1114
 
1091
1115
                case PW_TYPE_IPV6ADDR:
1092
1116
                        if (inet_pton(AF_INET6, value, &vp->vp_ipv6addr) <= 0) {
1093
 
                                librad_log("failed to parse IPv6 address "
 
1117
                                fr_strerror_printf("failed to parse IPv6 address "
1094
1118
                                           "string \"%s\"", value);
1095
1119
                                return NULL;
1096
1120
                        }
1100
1124
                case PW_TYPE_IPV6PREFIX:
1101
1125
                        p = strchr(value, '/');
1102
1126
                        if (!p || ((p - value) >= 256)) {
1103
 
                                librad_log("invalid IPv6 prefix "
 
1127
                                fr_strerror_printf("invalid IPv6 prefix "
1104
1128
                                           "string \"%s\"", value);
1105
1129
                                return NULL;
1106
1130
                        } else {
1111
1135
                                buffer[p - value] = '\0';
1112
1136
 
1113
1137
                                if (inet_pton(AF_INET6, buffer, vp->vp_octets + 2) <= 0) {
1114
 
                                        librad_log("failed to parse IPv6 address "
 
1138
                                        fr_strerror_printf("failed to parse IPv6 address "
1115
1139
                                                   "string \"%s\"", value);
1116
1140
                                        return NULL;
1117
1141
                                }
1118
1142
 
1119
1143
                                prefix = strtoul(p + 1, &eptr, 10);
1120
1144
                                if ((prefix > 128) || *eptr) {
1121
 
                                        librad_log("failed to parse IPv6 address "
 
1145
                                        fr_strerror_printf("failed to parse IPv6 address "
1122
1146
                                                   "string \"%s\"", value);
1123
1147
                                        return NULL;
1124
1148
                                }
1150
1174
                                                c1 = c2 = NULL;
1151
1175
                                        }
1152
1176
                                        if (!c1 || !c2 || (length >= sizeof(vp->vp_ether))) {
1153
 
                                                librad_log("failed to parse Ethernet address \"%s\"", value);
 
1177
                                                fr_strerror_printf("failed to parse Ethernet address \"%s\"", value);
1154
1178
                                                return NULL;
1155
1179
                                        }
1156
1180
                                        vp->vp_ether[length] = ((c1-hextab)<<4) + (c2-hextab);
1160
1184
                        vp->length = 6;
1161
1185
                        break;
1162
1186
 
 
1187
                case PW_TYPE_COMBO_IP:
 
1188
                        if (inet_pton(AF_INET6, value, vp->vp_strvalue) > 0) {
 
1189
                                vp->type = PW_TYPE_IPV6ADDR;
 
1190
                                vp->length = 16; /* length of IPv6 address */
 
1191
                                vp->vp_strvalue[vp->length] = '\0';
 
1192
 
 
1193
                        } else {
 
1194
                                fr_ipaddr_t ipaddr;
 
1195
 
 
1196
                                if (ip_hton(value, AF_INET, &ipaddr) < 0) {
 
1197
                                        fr_strerror_printf("Failed to find IPv4 address for %s", value);
 
1198
                                        return NULL;
 
1199
                                }
 
1200
 
 
1201
                                vp->type = PW_TYPE_IPADDR;
 
1202
                                vp->vp_ipaddr = ipaddr.ipaddr.ip4addr.s_addr;
 
1203
                                vp->length = 4;
 
1204
                        }
 
1205
                        break;
 
1206
 
 
1207
                case PW_TYPE_SIGNED: /* Damned code for 1 WiMAX attribute */
 
1208
                        vp->vp_signed = (int32_t) strtol(value, &p, 10);
 
1209
                        vp->length = 4;
 
1210
                        break;
 
1211
 
 
1212
                case PW_TYPE_TLV: /* don't use this! */
 
1213
                        if (strncasecmp(value, "0x", 2) != 0) {
 
1214
                                fr_strerror_printf("Invalid TLV specification");
 
1215
                                return NULL;
 
1216
                        }
 
1217
                        length = strlen(value + 2) / 2;
 
1218
                        if (vp->length < length) {
 
1219
                                free(vp->vp_tlv);
 
1220
                                vp->vp_tlv = NULL;
 
1221
                        }
 
1222
                        vp->vp_tlv = malloc(length);
 
1223
                        if (!vp->vp_tlv) {
 
1224
                                fr_strerror_printf("No memory");
 
1225
                                return NULL;
 
1226
                        }
 
1227
                        if (fr_hex2bin(value + 2, vp->vp_tlv,
 
1228
                                       length) != length) {
 
1229
                                fr_strerror_printf("Invalid hex data in TLV");
 
1230
                                return NULL;
 
1231
                        }
 
1232
                        vp->length = length;
 
1233
                        break;
 
1234
 
1163
1235
                        /*
1164
1236
                         *  Anything else.
1165
1237
                         */
1166
1238
                default:
1167
 
                        librad_log("unknown attribute type %d", vp->type);
 
1239
                        fr_strerror_printf("unknown attribute type %d", vp->type);
1168
1240
                        return NULL;
1169
1241
        }
1170
1242
 
1192
1264
         *      Unknown attributes MUST be of type 'octets'
1193
1265
         */
1194
1266
        if (value && (strncasecmp(value, "0x", 2) != 0)) {
1195
 
                librad_log("Invalid octet string \"%s\" for attribute name \"%s\"", value, attribute);
 
1267
                fr_strerror_printf("Invalid octet string \"%s\" for attribute name \"%s\"", value, attribute);
1196
1268
                return NULL;
1197
1269
        }
1198
1270
 
1199
 
        attr = vendor = 0;
 
1271
        vendor = 0;
1200
1272
 
1201
1273
        /*
1202
1274
         *      Pull off vendor prefix first.
1205
1277
                if (strncasecmp(p, "Vendor-", 7) == 0) {
1206
1278
                        vendor = (int) strtol(p + 7, &q, 10);
1207
1279
                        if ((vendor == 0) || (vendor > 65535)) {
1208
 
                                librad_log("Invalid vendor value in attribute name \"%s\"", attribute);
 
1280
                                fr_strerror_printf("Invalid vendor value in attribute name \"%s\"", attribute);
1209
1281
                                return NULL;
1210
1282
                        }
1211
1283
 
1217
1289
                        q = strchr(p, '-');
1218
1290
 
1219
1291
                        if (!q) {
1220
 
                                librad_log("Invalid vendor name in attribute name \"%s\"", attribute);
 
1292
                                fr_strerror_printf("Invalid vendor name in attribute name \"%s\"", attribute);
1221
1293
                                return NULL;
1222
1294
                        }
1223
1295
 
1224
1296
                        if ((size_t) (q - p) >= sizeof(buffer)) {
1225
 
                                librad_log("Vendor name too long in attribute name \"%s\"", attribute);
 
1297
                                fr_strerror_printf("Vendor name too long in attribute name \"%s\"", attribute);
1226
1298
                                return NULL;
1227
1299
                        }
1228
1300
 
1231
1303
 
1232
1304
                        vendor = dict_vendorbyname(buffer);
1233
1305
                        if (!vendor) {
1234
 
                                librad_log("Unknown vendor name in attribute name \"%s\"", attribute);
 
1306
                                fr_strerror_printf("Unknown vendor name in attribute name \"%s\"", attribute);
1235
1307
                                return NULL;
1236
1308
                        }
1237
1309
 
1239
1311
                }
1240
1312
 
1241
1313
                if (*p != '-') {
1242
 
                        librad_log("Invalid text following vendor definition in attribute name \"%s\"", attribute);
 
1314
                        fr_strerror_printf("Invalid text following vendor definition in attribute name \"%s\"", attribute);
1243
1315
                        return NULL;
1244
1316
                }
1245
1317
                p++;
1249
1321
         *      Attr-%d
1250
1322
         */
1251
1323
        if (strncasecmp(p, "Attr-", 5) != 0) {
1252
 
                librad_log("Invalid format in attribute name \"%s\"", attribute);
 
1324
                fr_strerror_printf("Invalid format in attribute name \"%s\"", attribute);
1253
1325
                return NULL;
1254
1326
        }
1255
1327
 
1259
1331
         *      Invalid, or trailing text after number.
1260
1332
         */
1261
1333
        if ((attr == 0) || *q) {
1262
 
                librad_log("Invalid value in attribute name \"%s\"", attribute);
 
1334
                fr_strerror_printf("Invalid value in attribute name \"%s\"", attribute);
1263
1335
                return NULL;
1264
1336
        }
1265
1337
 
1272
1344
                if (!dv) {
1273
1345
                        if (attr > 255) {
1274
1346
                        attr_error:
1275
 
                                librad_log("Invalid attribute number in attribute name \"%s\"", attribute);
 
1347
                                fr_strerror_printf("Invalid attribute number in attribute name \"%s\"", attribute);
1276
1348
                                return NULL;
1277
1349
                        }
1278
1350
 
1290
1362
                                break;
1291
1363
 
1292
1364
                        default:
1293
 
                                librad_log("Internal sanity check failed");
 
1365
                                fr_strerror_printf("Internal sanity check failed");
1294
1366
                                return NULL;
1295
1367
                }
1296
1368
        }
1303
1375
         *      dictionary, and creates the appropriate type for it.
1304
1376
         */
1305
1377
        if ((vp = paircreate(attr, PW_TYPE_OCTETS)) == NULL) {
1306
 
                librad_log("out of memory");
 
1378
                fr_strerror_printf("out of memory");
1307
1379
                return NULL;
1308
1380
        }
1309
1381
 
1328
1400
        }
1329
1401
 
1330
1402
        if (fr_hex2bin(value + 2, vp->vp_octets, size) != vp->length) {
1331
 
                librad_log("Invalid hex string");
 
1403
                fr_strerror_printf("Invalid hex string");
1332
1404
                free(vp);
1333
1405
                return NULL;
1334
1406
        }
1365
1437
        char            *tc, *ts;
1366
1438
        signed char     tag;
1367
1439
        int             found_tag;
1368
 
#ifdef HAVE_REGEX_H
1369
 
        int             res;
1370
 
        regex_t         cre;
1371
 
#endif
1372
1440
        char            buffer[64];
1373
1441
        const char      *attrname = attribute;
1374
1442
 
1380
1448
 
1381
1449
        ts = strrchr(attribute, ':');
1382
1450
        if (ts && !ts[1]) {
1383
 
                librad_log("Invalid tag for attribute %s", attribute);
 
1451
                fr_strerror_printf("Invalid tag for attribute %s", attribute);
1384
1452
                return NULL;
1385
1453
        }
1386
1454
 
1401
1469
                                 *ts = 0;
1402
1470
                         else tag = 0;
1403
1471
                 } else {
1404
 
                         librad_log("Invalid tag for attribute %s", attribute);
 
1472
                         fr_strerror_printf("Invalid tag for attribute %s", attribute);
1405
1473
                         return NULL;
1406
1474
                 }
1407
1475
                 found_tag = 1;
1416
1484
        }
1417
1485
 
1418
1486
        if ((vp = pairalloc(da)) == NULL) {
1419
 
                librad_log("out of memory");
 
1487
                fr_strerror_printf("out of memory");
1420
1488
                return NULL;
1421
1489
        }
1422
1490
        vp->operator = (operator == 0) ? T_OP_EQ : operator;
1429
1497
        if (value && (*value == ':' && da->flags.has_tag)) {
1430
1498
                /* If we already found a tag, this is invalid */
1431
1499
                if(found_tag) {
1432
 
                        pairbasicfree(vp);
1433
 
                        librad_log("Duplicate tag %s for attribute %s",
 
1500
                        fr_strerror_printf("Duplicate tag %s for attribute %s",
1434
1501
                                   value, vp->name);
1435
1502
                        DEBUG("Duplicate tag %s for attribute %s\n",
1436
1503
                                   value, vp->name);
 
1504
                        pairbasicfree(vp);
1437
1505
                        return NULL;
1438
 
 
1439
1506
                }
1440
1507
                /* Colon found and attribute allows a tag */
1441
1508
                if (value[1] == '*' && value[2] == ':') {
1478
1545
                 */
1479
1546
        case T_OP_REG_EQ:       /* =~ */
1480
1547
        case T_OP_REG_NE:       /* !~ */
1481
 
                if (vp->type == PW_TYPE_INTEGER) {
1482
 
                        return vp;
1483
 
                }
1484
 
#ifdef HAVE_REGEX_H
1485
 
                /*
1486
 
                 *      Regular expression match with no regular
1487
 
                 *      expression is wrong.
1488
 
                 */
1489
1548
                if (!value) {
1490
 
                        pairfree(&vp);
1491
 
                        return NULL;
1492
 
                }
1493
 
 
1494
 
                res = regcomp(&cre, value, REG_EXTENDED|REG_NOSUB);
1495
 
                if (res != 0) {
1496
 
                        char    msg[128];
1497
 
 
1498
 
                        regerror(res, &cre, msg, sizeof(msg));
1499
 
                        librad_log("Illegal regular expression in attribute: %s: %s",
1500
 
                                vp->name, msg);
1501
 
                        pairbasicfree(vp);
1502
 
                        return NULL;
1503
 
                }
1504
 
                regfree(&cre);
1505
 
#else
1506
 
                librad_log("Regular expressions not enabled in this build, error in attribute %s",
1507
 
                                vp->name);
1508
 
                pairbasicfree(vp);
1509
 
                return NULL;
1510
 
#endif
 
1549
                        fr_strerror_printf("No regular expression found in %s",
 
1550
                                           vp->name);
 
1551
                        pairbasicfree(vp);
 
1552
                        return NULL;
 
1553
                }
 
1554
          
 
1555
                strlcpy(vp->vp_strvalue, value, sizeof(vp->vp_strvalue));
 
1556
                vp->length = strlen(vp->vp_strvalue);
 
1557
                /*
 
1558
                 *      If anything goes wrong, this is a run-time error,
 
1559
                 *      not a compile-time error.
 
1560
                 */
 
1561
                return vp;
 
1562
 
1511
1563
        }
1512
1564
 
1513
1565
        /*
1557
1609
{
1558
1610
        char            buf[64];
1559
1611
        char            attr[64];
1560
 
        char            value[512], *q;
 
1612
        char            value[1024], *q;
1561
1613
        const char      *p;
1562
1614
        FR_TOKEN        token, t, xlat;
1563
1615
        VALUE_PAIR      *vp;
1570
1622
 
1571
1623
        if (!*p) {
1572
1624
                *eol = T_OP_INVALID;
1573
 
                librad_log("No token read where we expected an attribute name");
 
1625
                fr_strerror_printf("No token read where we expected an attribute name");
1574
1626
                return NULL;
1575
1627
        }
1576
1628
 
1577
1629
        if (*p == '#') {
1578
1630
                *eol = T_HASH;
1579
 
                librad_log("Read a comment instead of a token");
 
1631
                fr_strerror_printf("Read a comment instead of a token");
1580
1632
                return NULL;
1581
1633
        }
1582
1634
 
1591
1643
 
1592
1644
        if (len == sizeof(attr)) {
1593
1645
                *eol = T_OP_INVALID;
1594
 
                librad_log("Attribute name is too long");
 
1646
                fr_strerror_printf("Attribute name is too long");
1595
1647
                return NULL;
1596
1648
        }
1597
1649
 
1609
1661
        /* Now we should have an operator here. */
1610
1662
        token = gettoken(ptr, buf, sizeof(buf));
1611
1663
        if (token < T_EQSTART || token > T_EQEND) {
1612
 
                librad_log("expecting operator");
 
1664
                fr_strerror_printf("expecting operator");
1613
1665
                return NULL;
1614
1666
        }
1615
1667
 
1616
1668
        /* Read value.  Note that empty string values are allowed */
1617
1669
        xlat = gettoken(ptr, value, sizeof(value));
1618
1670
        if (xlat == T_EOL) {
1619
 
                librad_log("failed to get value");
 
1671
                fr_strerror_printf("failed to get value");
1620
1672
                return NULL;
1621
1673
        }
1622
1674
 
1626
1678
        p = *ptr;
1627
1679
        t = gettoken(&p, buf, sizeof(buf));
1628
1680
        if (t != T_EOL && t != T_COMMA && t != T_HASH) {
1629
 
                librad_log("Expected end of line or comma");
 
1681
                fr_strerror_printf("Expected end of line or comma");
1630
1682
                return NULL;
1631
1683
        }
1632
1684
 
1651
1703
                p = strchr(value, '%');
1652
1704
                if (p && (p[1] == '{')) {
1653
1705
                        if (strlen(value) >= sizeof(vp->vp_strvalue)) {
1654
 
                                librad_log("Value too long");
 
1706
                                fr_strerror_printf("Value too long");
1655
1707
                                return NULL;
1656
1708
                        }
1657
1709
                        vp = pairmake(attr, NULL, token);
1664
1716
                        vp->flags.do_xlat = 1;
1665
1717
                        vp->length = 0;
1666
1718
                } else {
 
1719
                        /*
 
1720
                         *      Parse && escape it, as defined by the
 
1721
                         *      data type.
 
1722
                         */
1667
1723
                        vp = pairmake(attr, value, token);
1668
 
                }
1669
 
                break;
1670
 
 
 
1724
                        if (!vp) {
 
1725
                                *eol = T_OP_INVALID;
 
1726
                                return NULL;
 
1727
                        }
 
1728
                }
 
1729
                break;
 
1730
 
 
1731
        case T_SINGLE_QUOTED_STRING:
 
1732
                vp = pairmake(attr, NULL, token);
 
1733
                if (!vp) {
 
1734
                        *eol = T_OP_INVALID;
 
1735
                        return NULL;
 
1736
                }
 
1737
 
 
1738
                /*
 
1739
                 *      String and octet types get copied verbatim.
 
1740
                 */
 
1741
                if ((vp->type == PW_TYPE_STRING) ||
 
1742
                    (vp->type == PW_TYPE_OCTETS)) {
 
1743
                        strlcpy(vp->vp_strvalue, value,
 
1744
                                sizeof(vp->vp_strvalue));
 
1745
                        vp->length = strlen(vp->vp_strvalue);
 
1746
 
 
1747
                        /*
 
1748
                         *      Everything else gets parsed: it's
 
1749
                         *      DATA, not a string!
 
1750
                         */
 
1751
                } else if (!pairparsevalue(vp, value)) {
 
1752
                        pairfree(&vp);
 
1753
                        *eol = T_OP_INVALID;
 
1754
                        return NULL;
 
1755
                }
 
1756
                break;
1671
1757
 
1672
1758
                /*
1673
1759
                 *      Mark the pair to be allocated later.
1674
1760
                 */
1675
1761
        case T_BACK_QUOTED_STRING:
1676
1762
                if (strlen(value) >= sizeof(vp->vp_strvalue)) {
1677
 
                        librad_log("Value too long");
 
1763
                        fr_strerror_printf("Value too long");
1678
1764
                        return NULL;
1679
1765
                }
1680
1766
 
1779
1865
                last_token = userparse(buf, &vp);
1780
1866
                if (!vp) {
1781
1867
                        if (last_token != T_EOL) {
1782
 
                                librad_perror("%s", errprefix);
 
1868
                                fr_perror("%s", errprefix);
1783
1869
                                error = 1;
1784
1870
                                break;
1785
1871
                        }
1809
1895
 *      e.g. "foo" != "bar"
1810
1896
 *
1811
1897
 *      Returns true (comparison is true), or false (comparison is not true);
 
1898
 *
 
1899
 *      FIXME: Ignores tags!
1812
1900
 */
1813
1901
int paircmp(VALUE_PAIR *one, VALUE_PAIR *two)
1814
1902
{
1838
1926
                                          REG_EXTENDED);
1839
1927
                        if (compare != 0) {
1840
1928
                                regerror(compare, &reg, buffer, sizeof(buffer));
1841
 
                                librad_log("Illegal regular expression in attribute: %s: %s",
 
1929
                                fr_strerror_printf("Illegal regular expression in attribute: %s: %s",
1842
1930
                                           one->name, buffer);
1843
1931
                                return -1;
1844
1932
                        }