Page 1 of 1

[Nagios-devel] PATCH: Allow escaping ! in check args (utils.c)

Posted: Tue May 16, 2006 11:38 am
by Guest
------=_20060516123758_45196
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

Resending this patch, as I didn't see it appear on the list...

Please find attached a patch (in unified diff context,) for the following:

My work had me create a patch for the get_raw_command_line() function in
utils.c to allow us to "escape" the "!" argument separator within check
command arguments.

I generalized it such that you can actually escape any character by
prefacing it with a backslash ('\'). So, now you can have command args
that include exclamations points as part of the argmument string.

For example:

check_command check_web!www.nagios.org!80!\!Test\!String\!!10!20

This will pass the third argument as: "!Test!String!" (sans quotes)

Bob

------=_20060516123758_45196
Content-Type: text/plain; name="utils.c.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="utils.c.diff"

--- utils.c 2006-04-07 15:45:33.000000000 -0600
+++ ../../nagios-2.2/base/utils.c 2006-04-20 13:21:29.000000000 -0600
@@ -2937,6 +2937,7 @@
command *temp_command;
int x,y;
int arg_index;
+ int escape_me;

#ifdef DEBUG0
printf("get_raw_command_line() start\n");
@@ -2969,9 +2970,19 @@
/* lookup the command... */

/* get the command name */
- for(x=0,y=0;y<buffer_length-1;x++){
- if(cmd[x]=='!' || cmd[x]=='\x0')
- break;
+ escape_me = 0;
+ for(x=0,y=0;y<buffer_length-1 && cmd[x];x++){
+ if (!escape_me) {
+ if (cmd[x]=='\\') {
+ escape_me = 1;
+ continue;
+ }
+
+ if(cmd[x]=='!')
+ break;
+ }
+ else
+ escape_me = 0;
raw_command[y]=cmd[x];
y++;
}
@@ -2989,9 +3000,18 @@
strip(raw_command);

/* skip the command name (we're about to get the arguments)... */
- for(arg_index=0;;arg_index++){
- if(cmd[arg_index]=='!' || cmd[arg_index]=='\x0')
- break;
+ escape_me = 0;
+ for(arg_index=0; cmd[arg_index]; arg_index++){
+ if (!escape_me) {
+ if (cmd[arg_index]=='\\') {
+ escape_me = 1;
+ continue;
+ }
+ if(cmd[arg_index]=='!')
+ break;
+ }
+ else
+ escape_me = 0;
}

/* get the command arguments */
@@ -3003,9 +3023,18 @@

/* get the next argument */
/* can't use strtok(), as that's used in process_macros... */
- for(arg_index++,y=0;y<sizeof(temp_arg)-1;arg_index++){
- if(cmd[arg_index]=='!' || cmd[arg_index]=='\x0')
- break;
+ escape_me = 0;
+ for(arg_index++,y=0; y<sizeof(temp_arg)-1 && cmd[arg_index]; arg_index++){
+ if (!escape_me) {
+ if (cmd[arg_index]=='\\') {
+ escape_me = 1;
+ continue;
+ }
+ if(cmd[arg_index]=='!')
+ break;
+ }
+ else
+ escape_me = 0;
temp_arg[y]=cmd[arg_index];
y++;
}
@@ -3017,6 +3046,9 @@

strip(arg_buffer);
macro_argv[x]=strdup(arg_buffer);
+#ifdef DEBUG1
+ printf("\ttempArg[%d]: %s\n",x,temp_arg);
+#endif
}

#ifdef DEBUG1


------=_20060516123758_45196--







This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]