blob: beb640b2b1fea3ae605e30cc00d4f1401567fd79 [file] [log] [blame]
Max Kellermann5b76f682008-01-29 13:42:48 +00001/* Code to restore the iptables state, from file by ip6tables-save.
András Kis-Szabó2f523792001-02-27 09:59:48 +00002 * Author: Andras Kis-Szabo <kisza@sch.bme.hu>
3 *
4 * based on iptables-restore
5 * Authors:
Max Kellermann5b76f682008-01-29 13:42:48 +00006 * Harald Welte <laforge@gnumonks.org>
7 * Rusty Russell <rusty@linuxcare.com.au>
András Kis-Szabó0c4188f2002-08-14 11:40:41 +00008 * This code is distributed under the terms of GNU GPL v2
András Kis-Szabó2f523792001-02-27 09:59:48 +00009 *
Martin Josefsson357d59d2004-12-27 19:49:28 +000010 * $Id$
András Kis-Szabó2f523792001-02-27 09:59:48 +000011 */
12
13#include <getopt.h>
14#include <sys/errno.h>
Jan Engelhardtc021c3c2009-01-27 15:10:05 +010015#include <stdbool.h>
András Kis-Szabó2f523792001-02-27 09:59:48 +000016#include <string.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include "ip6tables.h"
Yasuyuki KOZAKAI0b82e8e2007-07-24 05:47:40 +000020#include "xtables.h"
András Kis-Szabó2f523792001-02-27 09:59:48 +000021#include "libiptc/libip6tc.h"
Jan Engelhardt33690a12008-02-11 00:54:00 +010022#include "ip6tables-multi.h"
András Kis-Szabó2f523792001-02-27 09:59:48 +000023
24#ifdef DEBUG
25#define DEBUGP(x, args...) fprintf(stderr, x, ## args)
26#else
Max Kellermann5b76f682008-01-29 13:42:48 +000027#define DEBUGP(x, args...)
András Kis-Szabó2f523792001-02-27 09:59:48 +000028#endif
29
András Kis-Szabó2f523792001-02-27 09:59:48 +000030static int binary = 0, counters = 0, verbose = 0, noflush = 0;
31
32/* Keeping track of external matches and targets. */
Gáspár Lajos7bc3cb72008-03-27 08:20:39 +010033static const struct option options[] = {
34 {.name = "binary", .has_arg = false, .val = 'b'},
35 {.name = "counters", .has_arg = false, .val = 'c'},
36 {.name = "verbose", .has_arg = false, .val = 'v'},
37 {.name = "test", .has_arg = false, .val = 't'},
38 {.name = "help", .has_arg = false, .val = 'h'},
39 {.name = "noflush", .has_arg = false, .val = 'n'},
40 {.name = "modprobe", .has_arg = true, .val = 'M'},
41 {NULL},
András Kis-Szabó2f523792001-02-27 09:59:48 +000042};
43
44static void print_usage(const char *name, const char *version) __attribute__((noreturn));
45
46static void print_usage(const char *name, const char *version)
47{
Martin Josefsson60044392004-02-02 20:12:33 +000048 fprintf(stderr, "Usage: %s [-b] [-c] [-v] [-t] [-h]\n"
András Kis-Szabó2f523792001-02-27 09:59:48 +000049 " [ --binary ]\n"
50 " [ --counters ]\n"
51 " [ --verbose ]\n"
Martin Josefsson4e5e29a2004-02-02 19:59:17 +000052 " [ --test ]\n"
András Kis-Szabó2f523792001-02-27 09:59:48 +000053 " [ --help ]\n"
Harald Welte58918652001-06-16 18:25:25 +000054 " [ --noflush ]\n"
Max Kellermann5b76f682008-01-29 13:42:48 +000055 " [ --modprobe=<command>]\n", name);
56
András Kis-Szabó2f523792001-02-27 09:59:48 +000057 exit(1);
58}
59
Jan Engelhardtc3541052008-11-18 12:26:26 +010060static struct ip6tc_handle *create_handle(const char *tablename)
András Kis-Szabó2f523792001-02-27 09:59:48 +000061{
Jan Engelhardtfd187312008-11-10 16:59:27 +010062 struct ip6tc_handle *handle;
András Kis-Szabó2f523792001-02-27 09:59:48 +000063
64 handle = ip6tc_init(tablename);
Harald Welte58918652001-06-16 18:25:25 +000065
66 if (!handle) {
András Kis-Szabó97fd91a2002-03-03 09:44:31 +000067 /* try to insmod the module if iptc_init failed */
Jan Engelhardtc021c3c2009-01-27 15:10:05 +010068 xtables_load_ko(xtables_modprobe_program, false);
András Kis-Szabó97fd91a2002-03-03 09:44:31 +000069 handle = ip6tc_init(tablename);
Harald Welte58918652001-06-16 18:25:25 +000070 }
71
András Kis-Szabó2f523792001-02-27 09:59:48 +000072 if (!handle) {
Patrick McHardy5b098ac2007-02-14 13:59:12 +000073 exit_error(PARAMETER_PROBLEM, "%s: unable to initialize "
András Kis-Szabó2f523792001-02-27 09:59:48 +000074 "table '%s'\n", program_name, tablename);
75 exit(1);
76 }
77 return handle;
78}
79
Lutz Jaenickee78c69c2006-12-09 13:06:04 +000080static int parse_counters(char *string, struct ip6t_counters *ctr)
András Kis-Szabó2f523792001-02-27 09:59:48 +000081{
Patrick McHardy875441e2007-10-17 08:48:58 +000082 unsigned long long pcnt, bcnt;
83 int ret;
Patrick McHardy31f51c62007-10-16 08:49:31 +000084
Patrick McHardy875441e2007-10-17 08:48:58 +000085 ret = sscanf(string, "[%llu:%llu]",
86 (unsigned long long *)&pcnt,
87 (unsigned long long *)&bcnt);
88 ctr->pcnt = pcnt;
89 ctr->bcnt = bcnt;
90 return ret == 2;
András Kis-Szabó2f523792001-02-27 09:59:48 +000091}
92
Harald Welte885c6eb2001-10-04 08:30:46 +000093/* global new argv and argc */
94static char *newargv[255];
95static int newargc;
96
Max Kellermann5b76f682008-01-29 13:42:48 +000097/* function adding one argument to newargv, updating newargc
András Kis-Szabó97fd91a2002-03-03 09:44:31 +000098 * returns true if argument added, false otherwise */
Harald Welte885c6eb2001-10-04 08:30:46 +000099static int add_argv(char *what) {
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000100 DEBUGP("add_argv: %s\n", what);
101 if (what && ((newargc + 1) < sizeof(newargv)/sizeof(char *))) {
102 newargv[newargc] = strdup(what);
103 newargc++;
104 return 1;
Max Kellermann5b76f682008-01-29 13:42:48 +0000105 } else
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000106 return 0;
Harald Welte885c6eb2001-10-04 08:30:46 +0000107}
108
109static void free_argv(void) {
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000110 int i;
Harald Welte885c6eb2001-10-04 08:30:46 +0000111
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000112 for (i = 0; i < newargc; i++)
113 free(newargv[i]);
Harald Welte885c6eb2001-10-04 08:30:46 +0000114}
115
Hann-Huei Chiou4bc48332007-10-23 14:22:34 +0000116#ifdef IPTABLES_MULTI
117int ip6tables_restore_main(int argc, char *argv[])
118#else
András Kis-Szabó2f523792001-02-27 09:59:48 +0000119int main(int argc, char *argv[])
Hann-Huei Chiou4bc48332007-10-23 14:22:34 +0000120#endif
András Kis-Szabó2f523792001-02-27 09:59:48 +0000121{
Jan Engelhardtfd187312008-11-10 16:59:27 +0100122 struct ip6tc_handle *handle = NULL;
András Kis-Szabó2f523792001-02-27 09:59:48 +0000123 char buffer[10240];
András Kis-Szabó2f523792001-02-27 09:59:48 +0000124 int c;
125 char curtable[IP6T_TABLE_MAXNAMELEN + 1];
András Kis-Szabó2f523792001-02-27 09:59:48 +0000126 FILE *in;
Martin Josefsson4e5e29a2004-02-02 19:59:17 +0000127 int in_table = 0, testing = 0;
András Kis-Szabó2f523792001-02-27 09:59:48 +0000128
129 program_name = "ip6tables-restore";
Jan Engelhardtdacafa52009-01-27 20:56:23 +0100130 program_version = IPTABLES_VERSION;
Harald Weltea8658ca2003-03-05 07:46:15 +0000131 line = 0;
András Kis-Szabó2f523792001-02-27 09:59:48 +0000132
Jan Engelhardtdacafa52009-01-27 20:56:23 +0100133 xtables_program_name = program_name;
Jan Engelhardt39bf9c82009-01-27 15:59:06 +0100134 xtables_init();
Harald Welte3efb6ea2001-08-06 18:50:21 +0000135#ifdef NO_SHARED_LIBS
136 init_extensions();
137#endif
138
Martin Josefsson4e5e29a2004-02-02 19:59:17 +0000139 while ((c = getopt_long(argc, argv, "bcvthnM:", options, NULL)) != -1) {
András Kis-Szabó2f523792001-02-27 09:59:48 +0000140 switch (c) {
141 case 'b':
142 binary = 1;
143 break;
144 case 'c':
145 counters = 1;
146 break;
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000147 case 'v':
148 verbose = 1;
149 break;
Martin Josefsson4e5e29a2004-02-02 19:59:17 +0000150 case 't':
151 testing = 1;
152 break;
András Kis-Szabó2f523792001-02-27 09:59:48 +0000153 case 'h':
154 print_usage("ip6tables-restore",
Jan Engelhardtdacafa52009-01-27 20:56:23 +0100155 IPTABLES_VERSION);
András Kis-Szabó2f523792001-02-27 09:59:48 +0000156 break;
157 case 'n':
158 noflush = 1;
159 break;
Harald Welte58918652001-06-16 18:25:25 +0000160 case 'M':
Jan Engelhardtc021c3c2009-01-27 15:10:05 +0100161 xtables_modprobe_program = optarg;
Harald Welte58918652001-06-16 18:25:25 +0000162 break;
András Kis-Szabó2f523792001-02-27 09:59:48 +0000163 }
164 }
Max Kellermann5b76f682008-01-29 13:42:48 +0000165
András Kis-Szabó2f523792001-02-27 09:59:48 +0000166 if (optind == argc - 1) {
167 in = fopen(argv[optind], "r");
168 if (!in) {
Pavel Rusnak972af092007-05-10 15:00:39 +0000169 fprintf(stderr, "Can't open %s: %s\n", argv[optind],
András Kis-Szabó2f523792001-02-27 09:59:48 +0000170 strerror(errno));
171 exit(1);
172 }
173 }
174 else if (optind < argc) {
Pavel Rusnak972af092007-05-10 15:00:39 +0000175 fprintf(stderr, "Unknown arguments found on commandline\n");
András Kis-Szabó2f523792001-02-27 09:59:48 +0000176 exit(1);
177 }
178 else in = stdin;
Max Kellermann5b76f682008-01-29 13:42:48 +0000179
András Kis-Szabó2f523792001-02-27 09:59:48 +0000180 /* Grab standard input. */
181 while (fgets(buffer, sizeof(buffer), in)) {
Martin Josefssoncc536282004-02-02 20:14:56 +0000182 int ret = 0;
András Kis-Szabó2f523792001-02-27 09:59:48 +0000183
184 line++;
Martin Josefsson5065afa2004-01-31 19:33:47 +0000185 if (buffer[0] == '\n')
186 continue;
András Kis-Szabó2f523792001-02-27 09:59:48 +0000187 else if (buffer[0] == '#') {
Martin Josefsson3673dcb2004-01-31 19:41:49 +0000188 if (verbose)
189 fputs(buffer, stdout);
András Kis-Szabó2f523792001-02-27 09:59:48 +0000190 continue;
Harald Weltea8658ca2003-03-05 07:46:15 +0000191 } else if ((strcmp(buffer, "COMMIT\n") == 0) && (in_table)) {
Martin Josefsson4e5e29a2004-02-02 19:59:17 +0000192 if (!testing) {
193 DEBUGP("Calling commit\n");
Jan Engelhardt1c9015b2008-11-10 17:00:41 +0100194 ret = ip6tc_commit(handle);
195 ip6tc_free(handle);
196 handle = NULL;
Martin Josefsson4e5e29a2004-02-02 19:59:17 +0000197 } else {
198 DEBUGP("Not calling commit, testing\n");
199 ret = 1;
200 }
Harald Weltea8658ca2003-03-05 07:46:15 +0000201 in_table = 0;
202 } else if ((buffer[0] == '*') && (!in_table)) {
András Kis-Szabó2f523792001-02-27 09:59:48 +0000203 /* New table */
204 char *table;
205
206 table = strtok(buffer+1, " \t\n");
207 DEBUGP("line %u, table '%s'\n", line, table);
208 if (!table) {
Max Kellermann5b76f682008-01-29 13:42:48 +0000209 exit_error(PARAMETER_PROBLEM,
András Kis-Szabó2f523792001-02-27 09:59:48 +0000210 "%s: line %u table name invalid\n",
211 program_name, line);
212 exit(1);
213 }
214 strncpy(curtable, table, IP6T_TABLE_MAXNAMELEN);
Karsten Desler073df8f2004-01-31 15:33:55 +0000215 curtable[IP6T_TABLE_MAXNAMELEN] = '\0';
András Kis-Szabó2f523792001-02-27 09:59:48 +0000216
Martin Josefsson841e4ae2003-05-02 15:30:11 +0000217 if (handle)
Jan Engelhardt1c9015b2008-11-10 17:00:41 +0100218 ip6tc_free(handle);
Martin Josefsson841e4ae2003-05-02 15:30:11 +0000219
Jan Engelhardtc3541052008-11-18 12:26:26 +0100220 handle = create_handle(table);
András Kis-Szabó2f523792001-02-27 09:59:48 +0000221 if (noflush == 0) {
222 DEBUGP("Cleaning all chains of table '%s'\n",
223 table);
Max Kellermann5b76f682008-01-29 13:42:48 +0000224 for_each_chain(flush_entries, verbose, 1,
Jan Engelhardt1c9015b2008-11-10 17:00:41 +0100225 handle);
Max Kellermann5b76f682008-01-29 13:42:48 +0000226
András Kis-Szabó2f523792001-02-27 09:59:48 +0000227 DEBUGP("Deleting all user-defined chains "
228 "of table '%s'\n", table);
Max Kellermann5b76f682008-01-29 13:42:48 +0000229 for_each_chain(delete_chain, verbose, 0,
Jan Engelhardt1c9015b2008-11-10 17:00:41 +0100230 handle);
András Kis-Szabó2f523792001-02-27 09:59:48 +0000231 }
232
233 ret = 1;
Harald Weltea8658ca2003-03-05 07:46:15 +0000234 in_table = 1;
András Kis-Szabó2f523792001-02-27 09:59:48 +0000235
Harald Weltea8658ca2003-03-05 07:46:15 +0000236 } else if ((buffer[0] == ':') && (in_table)) {
András Kis-Szabó2f523792001-02-27 09:59:48 +0000237 /* New chain. */
238 char *policy, *chain;
239
240 chain = strtok(buffer+1, " \t\n");
241 DEBUGP("line %u, chain '%s'\n", line, chain);
242 if (!chain) {
243 exit_error(PARAMETER_PROBLEM,
244 "%s: line %u chain name invalid\n",
245 program_name, line);
246 exit(1);
247 }
András Kis-Szabó2f523792001-02-27 09:59:48 +0000248
Harald Weltedf1c71c2004-08-30 16:00:32 +0000249 if (ip6tc_builtin(chain, handle) <= 0) {
Charlie Brady595e4932005-06-12 15:54:15 +0000250 if (noflush && ip6tc_is_chain(chain, handle)) {
251 DEBUGP("Flushing existing user defined chain '%s'\n", chain);
Jan Engelhardt1c9015b2008-11-10 17:00:41 +0100252 if (!ip6tc_flush_entries(chain, handle))
Charlie Brady595e4932005-06-12 15:54:15 +0000253 exit_error(PARAMETER_PROBLEM,
254 "error flushing chain "
255 "'%s':%s\n", chain,
256 strerror(errno));
257 } else {
258 DEBUGP("Creating new chain '%s'\n", chain);
Jan Engelhardt1c9015b2008-11-10 17:00:41 +0100259 if (!ip6tc_create_chain(chain, handle))
Charlie Brady595e4932005-06-12 15:54:15 +0000260 exit_error(PARAMETER_PROBLEM,
261 "error creating chain "
262 "'%s':%s\n", chain,
263 strerror(errno));
264 }
Harald Welte885c6eb2001-10-04 08:30:46 +0000265 }
András Kis-Szabó2f523792001-02-27 09:59:48 +0000266
267 policy = strtok(NULL, " \t\n");
268 DEBUGP("line %u, policy '%s'\n", line, policy);
269 if (!policy) {
270 exit_error(PARAMETER_PROBLEM,
271 "%s: line %u policy invalid\n",
272 program_name, line);
273 exit(1);
274 }
275
276 if (strcmp(policy, "-") != 0) {
277 struct ip6t_counters count;
278
279 if (counters) {
280 char *ctrs;
281 ctrs = strtok(NULL, " \t\n");
282
Harald Welte6f38a302006-02-09 14:35:38 +0000283 if (!ctrs || !parse_counters(ctrs, &count))
284 exit_error(PARAMETER_PROBLEM,
285 "invalid policy counters "
286 "for chain '%s'\n", chain);
András Kis-Szabó2f523792001-02-27 09:59:48 +0000287
288 } else {
Max Kellermann5b76f682008-01-29 13:42:48 +0000289 memset(&count, 0,
András Kis-Szabó2f523792001-02-27 09:59:48 +0000290 sizeof(struct ip6t_counters));
291 }
292
293 DEBUGP("Setting policy of chain %s to %s\n",
294 chain, policy);
295
296 if (!ip6tc_set_policy(chain, policy, &count,
Jan Engelhardt1c9015b2008-11-10 17:00:41 +0100297 handle))
András Kis-Szabó2f523792001-02-27 09:59:48 +0000298 exit_error(OTHER_PROBLEM,
299 "Can't set policy `%s'"
300 " on `%s' line %u: %s\n",
301 chain, policy, line,
302 ip6tc_strerror(errno));
303 }
304
305 ret = 1;
306
Harald Weltea8658ca2003-03-05 07:46:15 +0000307 } else if (in_table) {
Harald Welte885c6eb2001-10-04 08:30:46 +0000308 int a;
András Kis-Szabó2f523792001-02-27 09:59:48 +0000309 char *ptr = buffer;
310 char *pcnt = NULL;
311 char *bcnt = NULL;
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000312 char *parsestart;
Harald Welte885c6eb2001-10-04 08:30:46 +0000313
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000314 /* the parser */
Max Kellermann3bf54df2008-01-29 13:45:29 +0000315 char *curchar;
316 int quote_open, escaped;
317 size_t param_len;
Harald Welte885c6eb2001-10-04 08:30:46 +0000318
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000319 /* reset the newargv */
320 newargc = 0;
András Kis-Szabó2f523792001-02-27 09:59:48 +0000321
322 if (buffer[0] == '[') {
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000323 /* we have counters in our input */
András Kis-Szabó2f523792001-02-27 09:59:48 +0000324 ptr = strchr(buffer, ']');
325 if (!ptr)
326 exit_error(PARAMETER_PROBLEM,
327 "Bad line %u: need ]\n",
328 line);
Harald Welte885c6eb2001-10-04 08:30:46 +0000329
András Kis-Szabó2f523792001-02-27 09:59:48 +0000330 pcnt = strtok(buffer+1, ":");
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000331 if (!pcnt)
332 exit_error(PARAMETER_PROBLEM,
333 "Bad line %u: need :\n",
334 line);
Harald Welte885c6eb2001-10-04 08:30:46 +0000335
András Kis-Szabó2f523792001-02-27 09:59:48 +0000336 bcnt = strtok(NULL, "]");
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000337 if (!bcnt)
338 exit_error(PARAMETER_PROBLEM,
339 "Bad line %u: need ]\n",
340 line);
András Kis-Szabó2f523792001-02-27 09:59:48 +0000341
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000342 /* start command parsing after counter */
343 parsestart = ptr + 1;
344 } else {
345 /* start command parsing at start of line */
346 parsestart = buffer;
András Kis-Szabó2f523792001-02-27 09:59:48 +0000347 }
András Kis-Szabó2f523792001-02-27 09:59:48 +0000348
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000349 add_argv(argv[0]);
350 add_argv("-t");
351 add_argv((char *) &curtable);
Max Kellermann5b76f682008-01-29 13:42:48 +0000352
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000353 if (counters && pcnt && bcnt) {
354 add_argv("--set-counters");
355 add_argv((char *) pcnt);
356 add_argv((char *) bcnt);
357 }
András Kis-Szabó2f523792001-02-27 09:59:48 +0000358
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000359 /* After fighting with strtok enough, here's now
360 * a 'real' parser. According to Rusty I'm now no
361 * longer a real hacker, but I can live with that */
András Kis-Szabó2f523792001-02-27 09:59:48 +0000362
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000363 quote_open = 0;
Max Kellermann3bf54df2008-01-29 13:45:29 +0000364 escaped = 0;
365 param_len = 0;
Max Kellermann5b76f682008-01-29 13:42:48 +0000366
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000367 for (curchar = parsestart; *curchar; curchar++) {
Max Kellermann3bf54df2008-01-29 13:45:29 +0000368 char param_buffer[1024];
369
Max Kellermann3bf54df2008-01-29 13:45:29 +0000370 if (quote_open) {
Max Kellermannfe05c762008-01-29 13:46:01 +0000371 if (escaped) {
372 param_buffer[param_len++] = *curchar;
373 escaped = 0;
374 continue;
375 } else if (*curchar == '\\') {
Max Kellermann3bf54df2008-01-29 13:45:29 +0000376 escaped = 1;
377 continue;
378 } else if (*curchar == '"') {
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000379 quote_open = 0;
380 *curchar = ' ';
381 } else {
Max Kellermann3bf54df2008-01-29 13:45:29 +0000382 param_buffer[param_len++] = *curchar;
383 continue;
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000384 }
Max Kellermann3bf54df2008-01-29 13:45:29 +0000385 } else {
386 if (*curchar == '"') {
387 quote_open = 1;
388 continue;
389 }
390 }
391
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000392 if (*curchar == ' '
393 || *curchar == '\t'
394 || * curchar == '\n') {
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000395 if (!param_len) {
396 /* two spaces? */
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000397 continue;
398 }
Max Kellermann3bf54df2008-01-29 13:45:29 +0000399
400 param_buffer[param_len] = '\0';
Harald Weltebb41f882001-10-21 14:11:54 +0000401
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000402 /* check if table name specified */
Jan Engelhardtd0cbf5f2008-08-04 12:51:01 +0200403 if (!strncmp(param_buffer, "-t", 2)
Harald Welte48a6f902001-10-22 15:16:21 +0000404 || !strncmp(param_buffer, "--table", 8)) {
Max Kellermann5b76f682008-01-29 13:42:48 +0000405 exit_error(PARAMETER_PROBLEM,
Harald Weltebb41f882001-10-21 14:11:54 +0000406 "Line %u seems to have a "
407 "-t table option.\n", line);
408 exit(1);
409 }
410
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000411 add_argv(param_buffer);
Max Kellermann3bf54df2008-01-29 13:45:29 +0000412 param_len = 0;
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000413 } else {
Max Kellermann3bf54df2008-01-29 13:45:29 +0000414 /* regular character, copy to buffer */
415 param_buffer[param_len++] = *curchar;
416
417 if (param_len >= sizeof(param_buffer))
418 exit_error(PARAMETER_PROBLEM,
419 "Parameter too long!");
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000420 }
421 }
Harald Welte885c6eb2001-10-04 08:30:46 +0000422
423 DEBUGP("calling do_command6(%u, argv, &%s, handle):\n",
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000424 newargc, curtable);
Harald Welte885c6eb2001-10-04 08:30:46 +0000425
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000426 for (a = 0; a < newargc; a++)
András Kis-Szabó2f523792001-02-27 09:59:48 +0000427 DEBUGP("argv[%u]: %s\n", a, newargv[a]);
428
Max Kellermann5b76f682008-01-29 13:42:48 +0000429 ret = do_command6(newargc, newargv,
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000430 &newargv[2], &handle);
Harald Welte885c6eb2001-10-04 08:30:46 +0000431
András Kis-Szabó97fd91a2002-03-03 09:44:31 +0000432 free_argv();
Henrik Nordstromd2137602008-05-12 20:51:45 +0200433 fflush(stdout);
András Kis-Szabó2f523792001-02-27 09:59:48 +0000434 }
435 if (!ret) {
436 fprintf(stderr, "%s: line %u failed\n",
437 program_name, line);
438 exit(1);
439 }
440 }
Martin Josefssone0dc5812004-02-02 19:58:36 +0000441 if (in_table) {
442 fprintf(stderr, "%s: COMMIT expected at line %u\n",
443 program_name, line + 1);
444 exit(1);
445 }
András Kis-Szabó2f523792001-02-27 09:59:48 +0000446
447 return 0;
448}