Skip to content

Commit

Permalink
Add escape parsing to generic plugin option parser.
Browse files Browse the repository at this point in the history
Backport the new escaping of the ':' using '\:' to all existing plugin
config parsers. This code comes from the new cephfs-fd and gfapi-fd
plugins.

Fixes #428: bpipe plugin on windows and colon character problem
  • Loading branch information
Marco van Wieringen authored and pstorz committed Mar 27, 2015
1 parent 89db075 commit f9214b8
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 28 deletions.
38 changes: 34 additions & 4 deletions src/plugins/dird/python-dir.c
Expand Up @@ -321,6 +321,27 @@ static bRC handlePluginEvent(bpContext *ctx, bDirEvent *event, void *value)
return retval;
}

/*
* Strip any backslashes in the string.
*/
static inline void strip_back_slashes(char *value)
{
char *bp;

bp = value;
while (*bp) {
switch (*bp) {
case '\\':
bstrinlinecpy(bp, bp + 1);
break;
default:
break;
}

bp++;
}
}

/*
* Parse a integer value.
*/
Expand Down Expand Up @@ -352,6 +373,7 @@ static inline void set_string(char **destination, char *value)
}

*destination = bstrdup(value);
strip_back_slashes(*destination);
}

/*
Expand Down Expand Up @@ -412,10 +434,18 @@ static bRC parse_plugin_definition(bpContext *ctx, void *value)
/*
* See if there are more arguments and setup for the next run.
*/
bp = strchr(argument_value, ':');
if (bp) {
*bp++ = '\0';
}
bp = argument_value;
do {
bp = strchr(bp, ':');
if (bp) {
if (*(bp - 1) != '\\') {
*bp++ = '\0';
break;
} else {
bp++;
}
}
} while (bp);

for (i = 0; plugin_arguments[i].name; i++) {
if (bstrcasecmp(argument, plugin_arguments[i].name)) {
Expand Down
55 changes: 47 additions & 8 deletions src/plugins/filed/bpipe-fd.c
Expand Up @@ -622,6 +622,27 @@ static char *apply_rp_codes(struct plugin_ctx * p_ctx)
return omsg;
}

/*
* Strip any backslashes in the string.
*/
static inline void strip_back_slashes(char *value)
{
char *bp;

bp = value;
while (*bp) {
switch (*bp) {
case '\\':
bstrinlinecpy(bp, bp + 1);
break;
default:
break;
}

bp++;
}
}

/*
* Parse a boolean value e.g. check if its yes or true anything else translates to false.
*/
Expand All @@ -642,6 +663,7 @@ static inline void set_string_if_null(char **destination, char *value)
{
if (!*destination) {
*destination = bstrdup(value);
strip_back_slashes(*destination);
}
}

Expand All @@ -655,6 +677,7 @@ static inline void set_string(char **destination, char *value)
}

*destination = bstrdup(value);
strip_back_slashes(*destination);
}

/*
Expand Down Expand Up @@ -754,10 +777,18 @@ static bRC parse_plugin_definition(bpContext *ctx, void *value)
/*
* See if there are more arguments and setup for the next run.
*/
bp = strchr(argument, ':');
if (bp) {
*bp++ = '\0';
}
bp = argument_value;
do {
bp = strchr(bp, ':');
if (bp) {
if (*(bp - 1) != '\\') {
*bp++ = '\0';
break;
} else {
bp++;
}
}
} while (bp);

/*
* See which field this is in the argument string.
Expand Down Expand Up @@ -795,10 +826,18 @@ static bRC parse_plugin_definition(bpContext *ctx, void *value)
/*
* See if there are more arguments and setup for the next run.
*/
bp = strchr(argument_value, ':');
if (bp) {
*bp++ = '\0';
}
bp = argument_value;
do {
bp = strchr(bp, ':');
if (bp) {
if (*(bp - 1) != '\\') {
*bp++ = '\0';
break;
} else {
bp++;
}
}
} while (bp);

for (i = 0; plugin_arguments[i].name; i++) {
if (bstrncasecmp(argument, plugin_arguments[i].name, plugin_arguments[i].cmp_length)) {
Expand Down
39 changes: 35 additions & 4 deletions src/plugins/filed/python-fd.c
Expand Up @@ -806,6 +806,27 @@ static bRC setXattr(bpContext *ctx, xattr_pkt *xp)
return retval;
}

/*
* Strip any backslashes in the string.
*/
static inline void strip_back_slashes(char *value)
{
char *bp;

bp = value;
while (*bp) {
switch (*bp) {
case '\\':
bstrinlinecpy(bp, bp + 1);
break;
default:
break;
}

bp++;
}
}

/*
* Parse a boolean value e.g. check if its yes or true anything else translates to false.
*/
Expand All @@ -826,6 +847,7 @@ static inline void set_string_if_null(char **destination, char *value)
{
if (!*destination) {
*destination = bstrdup(value);
strip_back_slashes(*destination);
}
}

Expand All @@ -839,6 +861,7 @@ static inline void set_string(char **destination, char *value)
}

*destination = bstrdup(value);
strip_back_slashes(*destination);
}

/*
Expand Down Expand Up @@ -902,10 +925,18 @@ static bRC parse_plugin_definition(bpContext *ctx, void *value)
/*
* See if there are more arguments and setup for the next run.
*/
bp = strchr(argument_value, ':');
if (bp) {
*bp++ = '\0';
}
bp = argument_value;
do {
bp = strchr(bp, ':');
if (bp) {
if (*(bp - 1) != '\\') {
*bp++ = '\0';
break;
} else {
bp++;
}
}
} while (bp);

for (i = 0; plugin_arguments[i].name; i++) {
if (bstrcasecmp(argument, plugin_arguments[i].name)) {
Expand Down
39 changes: 35 additions & 4 deletions src/plugins/filed/rados-fd.c
Expand Up @@ -506,6 +506,27 @@ static bRC endBackupFile(bpContext *ctx)
return get_next_object_to_backup(ctx);
}

/*
* Strip any backslashes in the string.
*/
static inline void strip_back_slashes(char *value)
{
char *bp;

bp = value;
while (*bp) {
switch (*bp) {
case '\\':
bstrinlinecpy(bp, bp + 1);
break;
default:
break;
}

bp++;
}
}

/*
* Parse a boolean value e.g. check if its yes or true anything else translates to false.
*/
Expand All @@ -526,6 +547,7 @@ static inline void set_string_if_null(char **destination, char *value)
{
if (!*destination) {
*destination = bstrdup(value);
strip_back_slashes(*destination);
}
}

Expand All @@ -539,6 +561,7 @@ static inline void set_string(char **destination, char *value)
}

*destination = bstrdup(value);
strip_back_slashes(*destination);
}

/*
Expand Down Expand Up @@ -602,10 +625,18 @@ static bRC parse_plugin_definition(bpContext *ctx, void *value)
/*
* See if there are more arguments and setup for the next run.
*/
bp = strchr(argument_value, ':');
if (bp) {
*bp++ = '\0';
}
bp = argument_value;
do {
bp = strchr(bp, ':');
if (bp) {
if (*(bp - 1) != '\\') {
*bp++ = '\0';
break;
} else {
bp++;
}
}
} while (bp);

for (i = 0; plugin_arguments[i].name; i++) {
if (bstrcasecmp(argument, plugin_arguments[i].name)) {
Expand Down
38 changes: 34 additions & 4 deletions src/plugins/stored/python-sd.c
Expand Up @@ -341,6 +341,27 @@ static bRC handlePluginEvent(bpContext *ctx, bsdEvent *event, void *value)
return retval;
}

/*
* Strip any backslashes in the string.
*/
static inline void strip_back_slashes(char *value)
{
char *bp;

bp = value;
while (*bp) {
switch (*bp) {
case '\\':
bstrinlinecpy(bp, bp + 1);
break;
default:
break;
}

bp++;
}
}

/*
* Parse a integer value.
*/
Expand Down Expand Up @@ -372,6 +393,7 @@ static inline void set_string(char **destination, char *value)
}

*destination = bstrdup(value);
strip_back_slashes(*destination);
}

/*
Expand Down Expand Up @@ -432,10 +454,18 @@ static bRC parse_plugin_definition(bpContext *ctx, void *value)
/*
* See if there are more arguments and setup for the next run.
*/
bp = strchr(argument_value, ':');
if (bp) {
*bp++ = '\0';
}
bp = argument_value;
do {
bp = strchr(bp, ':');
if (bp) {
if (*(bp - 1) != '\\') {
*bp++ = '\0';
break;
} else {
bp++;
}
}
} while (bp);

for (i = 0; plugin_arguments[i].name; i++) {
if (bstrcasecmp(argument, plugin_arguments[i].name)) {
Expand Down

0 comments on commit f9214b8

Please sign in to comment.