From: Alan T. DeKok Date: Tue, 22 Nov 2011 17:29:06 +0000 (+0100) Subject: Don't use lvalue, use the correct struct name X-Git-Tag: release_3_0_0_beta0~484 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f3048a875a117e011703722e30a7669607b3395;p=thirdparty%2Ffreeradius-server.git Don't use lvalue, use the correct struct name In preparation for removing lvalue. --- diff --git a/src/lib/dhcp.c b/src/lib/dhcp.c index a7f84178a56..5b62055af75 100644 --- a/src/lib/dhcp.c +++ b/src/lib/dhcp.c @@ -746,7 +746,7 @@ int fr_dhcp_decode(RADIUS_PACKET *packet) * DHCP Opcode is request */ vp = pairfind(head, 256, DHCP_MAGIC_VENDOR); - if (vp && vp->lvalue == 3) { + if (vp && vp->vp_integer == 3) { /* * Vendor is "MSFT 98" */ @@ -757,7 +757,7 @@ int fr_dhcp_decode(RADIUS_PACKET *packet) /* * Reply should be broadcast. */ - if (vp) vp->lvalue |= 0x8000; + if (vp) vp->vp_integer |= 0x8000; packet->data[10] |= 0x80; } } diff --git a/src/lib/valuepair.c b/src/lib/valuepair.c index d32d0550610..96bf02de362 100644 --- a/src/lib/valuepair.c +++ b/src/lib/valuepair.c @@ -1358,6 +1358,7 @@ static VALUE_PAIR *pairmake_any(const char *attribute, const char *value, char *q; VALUE_PAIR *vp; DICT_VENDOR *dv; + const DICT_ATTR *da; /* * Unknown attributes MUST be of type 'octets' @@ -1533,6 +1534,23 @@ static VALUE_PAIR *pairmake_any(const char *attribute, const char *value, return NULL; } } + + /* + * Maybe we're reading an old detail/config file, where + * it didn't know about a particular attribute and dumped + * it as hex. Now the dictionaries have been updated, + * and we know about it. So... convert it to the + * appropriate type. + * + * FIXME: call data2vp_any. + */ + da = dict_attrbyvalue(attr, vendor); + if (da) { + /* + * FIXME: convert hex to the data type. + */ + return NULL; + } /* * We've now parsed the attribute properly, Let's create @@ -1550,46 +1568,16 @@ static VALUE_PAIR *pairmake_any(const char *attribute, const char *value, size = strlen(value + 2); data = vp->vp_octets; - /* - * We may be reading something like Attr-5. i.e. - * who-ever wrote the text didn't understand it, but we - * do. - */ - switch (vp->type) { - default: - if (size == (vp->length * 2)) break; - vp->type = PW_TYPE_OCTETS; - /* FALL-THROUGH */ - - case PW_TYPE_OCTETS: - case PW_TYPE_ABINARY: - vp->length = size >> 1; - if (vp->length > sizeof(vp->vp_octets)) { - vp->vp_tlv = malloc(vp->length); - if (!vp->vp_tlv) { - fr_strerror_printf("Out of memory"); - free(vp); - return NULL; - } - data = vp->vp_tlv; - vp->type |= PW_FLAG_LONG; - } - break; - - case PW_TYPE_STRING: - vp->length = size >> 1; - memset(&vp->vp_strvalue, 0, sizeof(vp->vp_strvalue)); - if (vp->length >= sizeof(vp->vp_strvalue)) { - vp->vp_tlv = malloc(vp->length); - if (!vp->vp_tlv) { - fr_strerror_printf("Out of memory"); - free(vp); - return NULL; - } - data = vp->vp_tlv; - vp->type |= PW_FLAG_LONG; + vp->length = size >> 1; + if (vp->length > sizeof(vp->vp_octets)) { + vp->vp_tlv = malloc(vp->length); + if (!vp->vp_tlv) { + fr_strerror_printf("Out of memory"); + free(vp); + return NULL; } - break; + data = vp->vp_tlv; + vp->type |= PW_FLAG_LONG; } if (fr_hex2bin(value + 2, data, size) != vp->length) { @@ -1598,22 +1586,6 @@ static VALUE_PAIR *pairmake_any(const char *attribute, const char *value, return NULL; } - /* - * Move contents around based on type. This is - * to work around the historical use of "lvalue". - */ - switch (vp->type) { - case PW_TYPE_DATE: - case PW_TYPE_IPADDR: - case PW_TYPE_INTEGER: - memcpy(&vp->lvalue, vp->vp_octets, sizeof(vp->lvalue)); - vp->vp_strvalue[0] = '\0'; - break; - - default: - break; - } - return vp; } diff --git a/src/lib/vqp.c b/src/lib/vqp.c index bb1d21f021b..b60c84d858d 100644 --- a/src/lib/vqp.c +++ b/src/lib/vqp.c @@ -435,34 +435,34 @@ int vqp_decode(RADIUS_PACKET *packet) tail = &packet->vps; - vp = paircreate(PW_VQP_PACKET_TYPE, 0, PW_TYPE_OCTETS); + vp = paircreate(PW_VQP_PACKET_TYPE, 0, PW_TYPE_INTEGER); if (!vp) { fr_strerror_printf("No memory"); return -1; } - vp->lvalue = packet->data[1]; + vp->vp_integer = packet->data[1]; debug_pair(vp); *tail = vp; tail = &(vp->next); - vp = paircreate(PW_VQP_ERROR_CODE, 0, PW_TYPE_OCTETS); + vp = paircreate(PW_VQP_ERROR_CODE, 0, PW_TYPE_INTEGER); if (!vp) { fr_strerror_printf("No memory"); return -1; } - vp->lvalue = packet->data[2]; + vp->vp_integer = packet->data[2]; debug_pair(vp); *tail = vp; tail = &(vp->next); - vp = paircreate(PW_VQP_SEQUENCE_NUMBER, 0, PW_TYPE_OCTETS); + vp = paircreate(PW_VQP_SEQUENCE_NUMBER, 0, PW_TYPE_INTEGER); if (!vp) { fr_strerror_printf("No memory"); return -1; } - vp->lvalue = packet->id; /* already set by vqp_recv */ + vp->vp_integer = packet->id; /* already set by vqp_recv */ debug_pair(vp); *tail = vp; @@ -562,7 +562,7 @@ int vqp_encode(RADIUS_PACKET *packet, RADIUS_PACKET *original) return -1; } - code = vp->lvalue; + code = vp->vp_integer; if ((code < 1) || (code > 4)) { fr_strerror_printf("Invalid value %d for VQP-Packet-Type", code); return -1; @@ -616,7 +616,7 @@ int vqp_encode(RADIUS_PACKET *packet, RADIUS_PACKET *original) if (!vp) { ptr[2] = 0; } else { - ptr[2] = vp->lvalue & 0xff; + ptr[2] = vp->vp_integer & 0xff; return 0; } diff --git a/src/main/xlat.c b/src/main/xlat.c index f302a76edcf..32631480104 100644 --- a/src/main/xlat.c +++ b/src/main/xlat.c @@ -212,7 +212,7 @@ static size_t xlat_packet(void *instance, REQUEST *request, case PW_TYPE_DATE: case PW_TYPE_SHORT: case PW_TYPE_BYTE: - snprintf(out, outlen, "%u", vp->lvalue); + snprintf(out, outlen, "%u", vp->vp_integer); return strlen(out); case PW_TYPE_SIGNED: diff --git a/src/modules/rlm_acct_unique/rlm_acct_unique.c b/src/modules/rlm_acct_unique/rlm_acct_unique.c index 1b0d1a719ff..88a064db4a3 100644 --- a/src/modules/rlm_acct_unique/rlm_acct_unique.c +++ b/src/modules/rlm_acct_unique/rlm_acct_unique.c @@ -215,7 +215,7 @@ static int add_unique_id(void *instance, REQUEST *request) hack.type = cur->dattr->type; hack.operator = T_OP_EQ; hack.length = 4; - hack.lvalue = request->packet->src_ipaddr.ipaddr.ip4addr.s_addr; + hack.vp_ipaddr = request->packet->src_ipaddr.ipaddr.ip4addr.s_addr; vp = &hack; } else { RDEBUG2("WARNING: Attribute %s was not found in request, unique ID MAY be inconsistent", cur->dattr->name); diff --git a/src/modules/rlm_preprocess/rlm_preprocess.c b/src/modules/rlm_preprocess/rlm_preprocess.c index 9fcbce5e8f9..41e200e158b 100644 --- a/src/modules/rlm_preprocess/rlm_preprocess.c +++ b/src/modules/rlm_preprocess/rlm_preprocess.c @@ -78,7 +78,7 @@ static int fallthrough(VALUE_PAIR *vp) VALUE_PAIR *tmp; tmp = pairfind(vp, PW_FALL_THROUGH, 0); - return tmp ? tmp->lvalue : 0; + return tmp ? tmp->vp_integer : 0; } /*