From 3e6bd73fa6dd9fa90fb46c15920461c32215358c Mon Sep 17 00:00:00 2001 From: Fabian Mauchle Date: Thu, 18 Apr 2019 15:43:57 +0200 Subject: [PATCH] test and fix supplementVendorAttriute update manpage --- radsecproxy.conf.5 | 7 +++++++ rewrite.c | 4 ++-- tests/t_rewrite.c | 22 +++++++++++++++++++++- tests/t_rewrite_config.c | 2 +- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/radsecproxy.conf.5 b/radsecproxy.conf.5 index 2b00fe1..b45e5be 100644 --- a/radsecproxy.conf.5 +++ b/radsecproxy.conf.5 @@ -842,6 +842,13 @@ the attribute is not yet present on the message. The format of \fIvalue\fR is the same as for \fBaddAttribute\fR above. .RE +.BI "SupplementVendorAttribute " vendor \fR: subattribute \fR: value +.RS +Add a vendor attribute to the radius message only if the \fIsubattribute\fR of +this \fIvendor\fR is not yet present on the message. The format of is the same +as for \fBaddVendorAttribute\fR above. +.RE + .BI "ModifyAttribute " attribute \fR:/ regex \fR/ replace \fR/ .RS Modify the given \fIattribute\fR using the \fIregex\fR \fIreplace\fR pattern. As diff --git a/rewrite.c b/rewrite.c index da4f53f..925e22c 100644 --- a/rewrite.c +++ b/rewrite.c @@ -447,13 +447,13 @@ int dorewritesup(struct radmsg *msg, struct list *supattrs) { exist = 1; break; } else if (supattr->t == RAD_Attr_Vendor_Specific && attr->t == RAD_Attr_Vendor_Specific && - memcmp (supattr->v, attr->v, 4)) { + memcmp (supattr->v, attr->v, 4)==0) { if (!attrvalidate(attr->v+4, attr->l-4)) { debug(DBG_INFO, "dorewritesup: vendor attribute validation failed, no rewrite"); return 0; } vendortype = (uint8_t *)supattr->v+4; - for (v=attr->v+4; v < attr->v + attr->l; v += *(v+1) + 2){ + for (v=attr->v+4; v < attr->v + attr->l; v += *(v+1)){ if (*v == *vendortype) { exist = 1; break; diff --git a/tests/t_rewrite.c b/tests/t_rewrite.c index bc4fd33..05ea72f 100644 --- a/tests/t_rewrite.c +++ b/tests/t_rewrite.c @@ -58,7 +58,7 @@ void _reset_rewrite(struct rewrite *rewrite) { int main (int argc, char *argv[]) { - int testcount = 22; + int testcount = 23; struct list *origattrs, *expectedattrs; struct rewrite rewrite; char *username = "user@realm"; @@ -298,6 +298,26 @@ main (int argc, char *argv[]) _reset_rewrite(&rewrite); } + /* test supplement vendor*/ + { + uint8_t value = 42; + uint8_t vendor_long1_in[] = {0,0,0,42,2,3,0,1,3,0}; + + list_push(rewrite.supattrs, makevendortlv(42, maketlv(1, 1, &value))); + list_push(rewrite.supattrs, makevendortlv(42, maketlv(3, 1, &value))); + list_push(origattrs, maketlv(26, sizeof(vendor_long1_in), vendor_long1_in)); + list_push(expectedattrs, maketlv(26, sizeof(vendor_long1_in), vendor_long1_in)); + list_push(expectedattrs, makevendortlv(42, maketlv(3, 1, &value))); + + if (_check_rewrite(origattrs, &rewrite, expectedattrs, 0)) + printf("not "); + printf("ok %d - suppattrs vendor\n", testcount++); + + _list_clear(origattrs); + _list_clear(expectedattrs); + _reset_rewrite(&rewrite); + } + /* test modify no match*/ { char *value = "hello world"; diff --git a/tests/t_rewrite_config.c b/tests/t_rewrite_config.c index 2c79331..ecf1ada 100644 --- a/tests/t_rewrite_config.c +++ b/tests/t_rewrite_config.c @@ -28,7 +28,7 @@ main (int argc, char *argv[]) expected = maketlv(1,5,expectedvalue); - addrewrite(rewritename, NULL, NULL, addattrs, + addrewrite(rewritename, 0, NULL, NULL, addattrs, NULL, NULL, NULL, NULL); result = getrewrite(rewritename, NULL);