Skip to content

Commit

Permalink
Allow IP addresses with /32 suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Feb 15, 2014
1 parent 06a5b48 commit 4d4a43f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/lib/valuepair.c
Expand Up @@ -1285,10 +1285,9 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value)
* cannot be resolved, or resolve later!
*/
p = NULL;
cs = value;

{
fr_ipaddr_t ipaddr;
char ipv4[16];

/*
* Convert things which are obviously integers to IP addresses
Expand All @@ -1301,6 +1300,25 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value)
break;
}

/*
* Certain applications/databases print IPv4 addresses with a
* /32 suffix. Strip it off if the mask is 32, else error out.
*/
p = strchr(value, '/');
if (p) {
if ((p[1] != '3') || (p[2] != '2')) {
fr_strerror_printf("Invalid IP address suffix \"%s\". Only '/32' permitted "
"for non-prefix types", p);
return false;
}

strlcpy(ipv4, value, sizeof(ipv4));
ipv4[p - value] = '\0';
cs = ipv4;
} else {
cs = value;
}

if (ip_hton(cs, AF_INET, &ipaddr) < 0) {
fr_strerror_printf("Failed to find IP address for %s", cs);
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/rlm_sql/sql.c
Expand Up @@ -255,7 +255,7 @@ int sql_userparse(TALLOC_CTX *ctx, VALUE_PAIR **head, rlm_sql_row_t row)
}
} else {
if (!pairparsevalue(vp, value)) {
ERROR("rlm_sql: Error parsing value");
ERROR("rlm_sql: Error parsing value: %s", fr_strerror());

talloc_free(vp);
return -1;
Expand Down Expand Up @@ -422,7 +422,7 @@ int sql_getvpdata(rlm_sql_t * inst, rlm_sql_handle_t **handle,
if (!row)
break;
if (sql_userparse(ctx, pair, row) != 0) {
ERROR("rlm_sql (%s): Error getting data from database", inst->config->xlat_name);
ERROR("rlm_sql (%s): Error parsing user data from database result", inst->config->xlat_name);

(inst->module->sql_finish_select_query)(*handle, inst->config);

Expand Down
4 changes: 4 additions & 0 deletions src/tests/unit/condition.txt
Expand Up @@ -334,3 +334,7 @@ data &User-Name == "%{sql: blah}"

condition <ipaddr>127.0.0.1 == 2130706433
data true

# /32 suffix should be trimmed for this type
condition <ipaddr>127.0.0.1/32 == 127.0.0.1
data true

0 comments on commit 4d4a43f

Please sign in to comment.