Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart De Schuymer committed Sep 28, 2005
1 parent 005f638 commit 83a1b0f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion communication.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ static int store_counters_in_file(char *filename, struct ebt_u_replace *repl)

/* Gets executed after ebt_deliver_table. Delivers the counters to the kernel
* and resets the counterchanges to CNT_NORM */
void ebt_deliver_counters(struct ebt_u_replace *u_repl, int exec_style)
void ebt_deliver_counters(struct ebt_u_replace *u_repl)
{
struct ebt_counter *old, *new, *newcounters;
socklen_t optlen;
Expand Down
7 changes: 2 additions & 5 deletions ebtables.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,13 +1008,10 @@ int do_command(int argc, char *argv[], int exec_style,
replace->flags |= OPT_COMMAND;
{
char *tmp = replace->filename;
int init = 1;

if (c == 10)
init = 0;
/* Get the kernel table */
replace->filename = NULL;
ebt_get_kernel_table(replace, init);
ebt_get_kernel_table(replace, c == 10 ? 0 : 1);
replace->filename = tmp;
}
break;
Expand Down Expand Up @@ -1208,7 +1205,7 @@ int do_command(int argc, char *argv[], int exec_style,
ebt_deliver_table(replace);

if (replace->nentries)
ebt_deliver_counters(replace, EXEC_STYLE_PRG);
ebt_deliver_counters(replace);
}
return 0;
}
25 changes: 15 additions & 10 deletions ebtablesd.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc_, char *argv_[])
char *argv[EBTD_ARGC_MAX], *args[4], name[] = "mkdir",
mkdir_option[] = "-p", mkdir_dir[] = EBTD_PIPE_DIR,
cmdline[EBTD_CMDLINE_MAXLN];
int readfd, base = 0, offset = 0, n = 0, ret = 0;
int readfd, base = 0, offset = 0, n = 0, ret = 0, quotemode = 0;

/* Make sure the pipe directory exists */
args[0] = name;
Expand Down Expand Up @@ -104,15 +104,16 @@ int main(int argc_, char *argv_[])
continue;
ntot += offset;
continue_read:
/* Change all ' ' into '\0'. This implies that the user is not
* allowed to use spaces (that don't distinguish options or
* commands) in her rules. This comes down to not allowing spaces
* in options like the string of --ulog-prefix (use '_' instead).
*/
/* Put '\0' between arguments. */
for (; offset < ntot; n++, offset++) {
if (cmdline[offset] == ' ')
if (cmdline[offset] == '\"') {
quotemode ^= 1;
cmdline[offset] = '\0';
if (cmdline[offset] == '\n') {
} else if (!quotemode && cmdline[offset] == ' ') {
cmdline[offset] = '\0';
} else if (cmdline[offset] == '\n') {
if (quotemode)
ebt_print_error("ebtablesd: wrong number of \" delimiters");
cmdline[offset] = '\0';
break;
}
Expand Down Expand Up @@ -145,6 +146,10 @@ int main(int argc_, char *argv_[])
n2 = 0;
argc = 0;
while (n2 < n && argc < EBTD_ARGC_MAX) {
if (*(cmdline + base + n2) == '\0') {
n2++;
continue;
}
argv[argc++] = cmdline + base + n2;
n2 += strlen(cmdline + base + n2) + 1;
}
Expand Down Expand Up @@ -303,7 +308,7 @@ int main(int argc_, char *argv_[])
replace[i].num_counters = 0;
ebt_deliver_table(&replace[i]);
if (ebt_errormsg[0] == '\0' && open_method[i] == OPEN_METHOD_KERNEL)
ebt_deliver_counters(&replace[i], EXEC_STYLE_DAEMON);
ebt_deliver_counters(&replace[i]);
goto write_msg;
} else if (!strcmp(argv[1], "fcommit")) {
if (argc != 4) {
Expand Down Expand Up @@ -333,7 +338,7 @@ int main(int argc_, char *argv_[])
strcpy(replace[i].filename, argv[3]);
ebt_deliver_table(&replace[i]);
if (ebt_errormsg[0] == '\0' && open_method[i] == OPEN_METHOD_KERNEL)
ebt_deliver_counters(&replace[i], EXEC_STYLE_DAEMON);
ebt_deliver_counters(&replace[i]);
free(replace[i].filename);
replace[i].filename = NULL;
goto write_msg;
Expand Down
3 changes: 2 additions & 1 deletion ebtablesu.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ int main(int argc, char *argv[])
pos = arguments;
for (i = 0; i < argc; i++) {
strcpy(pos, argv[i]);
pos += strlen(argv[i]) + 1;
pos += strlen(argv[i]);
*(pos++) = ' ';
}

*(pos-1) = '\n';
Expand Down
2 changes: 1 addition & 1 deletion include/ebtables_u.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void __ebt_print_error(char *format, ...);
/* communication.c */

int ebt_get_table(struct ebt_u_replace *repl, int init);
void ebt_deliver_counters(struct ebt_u_replace *repl, int exec_style);
void ebt_deliver_counters(struct ebt_u_replace *repl);
void ebt_deliver_table(struct ebt_u_replace *repl);

/* useful_functions.c */
Expand Down
4 changes: 2 additions & 2 deletions libebtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,8 @@ void __ebt_print_error(char *format, ...)
vsnprintf(ebt_errormsg, ERRORMSG_MAXLEN, format, l);
va_end(l);
} else {
vprintf(format, l);
printf(".\n");
vfprintf(stderr, format, l);
fprintf(stderr, ".\n");
va_end(l);
exit (-1);
}
Expand Down

0 comments on commit 83a1b0f

Please sign in to comment.