Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
configure ModifyVendorAttribute
update manpage
update ChangeLog
  • Loading branch information
Fabian Mauchle committed Apr 24, 2019
1 parent 51630d4 commit f4aace9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog
@@ -1,6 +1,7 @@
changes since 1.7.2
New features:
- Rewrite: supplement attribute (add attribute if not present) (#19)
- Rewrite: modify vendor attribute
- Rewrite whitelist mode

Misc:
Expand Down
5 changes: 3 additions & 2 deletions radsecproxy.c
Expand Up @@ -2629,7 +2629,7 @@ int confrewrite_cb(struct gconffile **cf, void *arg, char *block, char *opt, cha
char **rmattrs = NULL, **rmvattrs = NULL;
char **wlattrs = NULL, **wlvattrs = NULL;
char **addattrs = NULL, **addvattrs = NULL;
char **modattrs = NULL;
char **modattrs = NULL, **modvattrs = NULL;
char **supattrs = NULL, **supvattrs = NULL;

debug(DBG_DBG, "confrewrite_cb called for %s", block);
Expand All @@ -2643,12 +2643,13 @@ int confrewrite_cb(struct gconffile **cf, void *arg, char *block, char *opt, cha
"addAttribute", CONF_MSTR, &addattrs,
"addVendorAttribute", CONF_MSTR, &addvattrs,
"modifyAttribute", CONF_MSTR, &modattrs,
"modifyVendorAttribute", CONF_MSTR, &modvattrs,
"supplementAttribute", CONF_MSTR, &supattrs,
"supplementVendorAttriute", CONF_MSTR, &supvattrs,
NULL))
debugx(1, DBG_ERR, "configuration error");
addrewrite(val, whitelist_mode, whitelist_mode? wlattrs : rmattrs, whitelist_mode? wlvattrs : rmvattrs,
addattrs, addvattrs, modattrs, supattrs, supvattrs);
addattrs, addvattrs, modattrs, modvattrs, supattrs, supvattrs);

freegconfmstr(whitelist_mode? rmattrs : wlattrs);
freegconfmstr(whitelist_mode? rmvattrs : wlvattrs);
Expand Down
7 changes: 7 additions & 0 deletions radsecproxy.conf.5
Expand Up @@ -857,6 +857,13 @@ above, \fIattribute\fR must be specified by a numerical value. Example usage:
modifyAttribute 1:/^(.*)@local$/\e1@example.com/
.RE

.BI "ModifyVendorAttribute " vendor \fR: subattribute \fR:/ regex \fR/ replace \fR/
.RS
Modify the given \fIsubattribute\fR of given \fIvendor\fR using the \fIregex\fR
\fIreplace\fR pattern. Other than the added vendor, the same syntax as for
\fBModifyAttribute\fR applies.
.RE

.BI "RemoveAttribute " attribute
.RS
Remove all attributes with the given id.
Expand Down
35 changes: 32 additions & 3 deletions rewrite.c
Expand Up @@ -139,14 +139,29 @@ struct modattr *extractmodattr(char *nameval) {
return m;
}

struct modattr *extractmodvattr(char *nameval) {
uint32_t vendor;
char *s;
struct modattr *modvattr;

s = strchr(nameval, ':');
vendor = atoi(nameval);
if (!s || !vendor || !strchr(s,':'))
return NULL;
modvattr = extractmodattr(s+1);
if (modvattr)
modvattr ->vendor = vendor;
return modvattr;
}

void addrewrite(char *value, uint8_t whitelist_mode, char **rmattrs, char **rmvattrs, char **addattrs,
char **addvattrs, char **modattrs, char **supattrs, char** supvattrs)
char **addvattrs, char **modattrs, char **modvattrs, char **supattrs, char** supvattrs)
{
struct rewrite *rewrite = NULL;
int i, n;
uint8_t *rma = NULL;
uint32_t *p, *rmva = NULL;
struct list *adda = NULL, *moda = NULL, *supa = NULL;
struct list *adda = NULL, *moda = NULL, *modva = NULL, *supa = NULL;
struct tlv *a;
struct modattr *m;

Expand Down Expand Up @@ -219,6 +234,20 @@ void addrewrite(char *value, uint8_t whitelist_mode, char **rmattrs, char **rmva
freegconfmstr(modattrs);
}

if (modvattrs) {
modva = list_create();
if (!modva)
debugx(1, DBG_ERR, "malloc failed");
for (i = 0; modvattrs[i]; i++) {
m = extractmodvattr(modvattrs[i]);
if (!m)
debugx(1, DBG_ERR, "addrewrite: modifying invalid vendor attribute %s", modvattrs[i]);
if (!list_push(modva, m))
debugx(1, DBG_ERR, "malloc failed");
}
freegconfmstr(modvattrs);
}

if (supattrs) {
supa = list_create();
if (!supa)
Expand Down Expand Up @@ -257,7 +286,7 @@ void addrewrite(char *value, uint8_t whitelist_mode, char **rmattrs, char **rmva
rewrite->removevendorattrs = rmva;
rewrite->addattrs = adda;
rewrite->modattrs = moda;
rewrite->modvattrs = NULL;
rewrite->modvattrs = modva;
rewrite->supattrs = supa;
}

Expand Down
2 changes: 1 addition & 1 deletion rewrite.h
Expand Up @@ -26,7 +26,7 @@ struct rewrite {
};

void addrewrite(char *value, uint8_t whitelist_mode, char **rmattrs, char **rmvattrs, char **addattrs,
char **addvattrs, char **modattrs, char **supattrs, char** supvattrs);
char **addvattrs, char **modattrs, char **modvattrs, char **supattrs, char** supvattrs);
int dorewrite(struct radmsg *msg, struct rewrite *rewrite);
struct modattr *extractmodattr(char *nameval);
struct rewrite *getrewrite(char *alt1, char *alt2);
Expand Down

0 comments on commit f4aace9

Please sign in to comment.