Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 1 | /* Code to restore the iptables state, from file by iptables-save. |
Harald Welte | 10a907f | 2002-08-07 09:07:41 +0000 | [diff] [blame] | 2 | * (C) 2000-2002 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 3 | * based on previous code from Rusty Russell <rusty@linuxcare.com.au> |
| 4 | * |
Harald Welte | 10a907f | 2002-08-07 09:07:41 +0000 | [diff] [blame] | 5 | * This code is distributed under the terms of GNU GPL v2 |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 6 | * |
Harald Welte | 10a907f | 2002-08-07 09:07:41 +0000 | [diff] [blame] | 7 | * $Id: iptables-restore.c,v 1.21 2002/05/29 13:08:15 laforge Exp $ |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 10 | #include <getopt.h> |
| 11 | #include <sys/errno.h> |
| 12 | #include <string.h> |
| 13 | #include <stdio.h> |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 14 | #include <stdlib.h> |
| 15 | #include "iptables.h" |
| 16 | #include "libiptc/libiptc.h" |
| 17 | |
| 18 | #ifdef DEBUG |
Harald Welte | c45c315 | 2000-12-06 08:11:24 +0000 | [diff] [blame] | 19 | #define DEBUGP(x, args...) fprintf(stderr, x, ## args) |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 20 | #else |
Harald Welte | c45c315 | 2000-12-06 08:11:24 +0000 | [diff] [blame] | 21 | #define DEBUGP(x, args...) |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 22 | #endif |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 23 | |
Harald Welte | a9d2708 | 2000-12-19 16:10:42 +0000 | [diff] [blame] | 24 | static int binary = 0, counters = 0, verbose = 0, noflush = 0; |
| 25 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 26 | /* Keeping track of external matches and targets. */ |
| 27 | static struct option options[] = { |
Harald Welte | a9d2708 | 2000-12-19 16:10:42 +0000 | [diff] [blame] | 28 | { "binary", 0, 0, 'b' }, |
| 29 | { "counters", 0, 0, 'c' }, |
Marc Boucher | 1277b59 | 2001-12-06 15:06:34 +0000 | [diff] [blame] | 30 | { "verbose", 1, 0, 'v' }, |
Harald Welte | a9d2708 | 2000-12-19 16:10:42 +0000 | [diff] [blame] | 31 | { "help", 0, 0, 'h' }, |
| 32 | { "noflush", 0, 0, 'n'}, |
Harald Welte | 5891865 | 2001-06-16 18:25:25 +0000 | [diff] [blame] | 33 | { "modprobe", 1, 0, 'M'}, |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 34 | { 0 } |
| 35 | }; |
| 36 | |
| 37 | static void print_usage(const char *name, const char *version) __attribute__((noreturn)); |
| 38 | |
| 39 | static void print_usage(const char *name, const char *version) |
| 40 | { |
Harald Welte | a9d2708 | 2000-12-19 16:10:42 +0000 | [diff] [blame] | 41 | fprintf(stderr, "Usage: %s [-b] [-c] [-v] [-h]\n" |
| 42 | " [ --binary ]\n" |
| 43 | " [ --counters ]\n" |
| 44 | " [ --verbose ]\n" |
| 45 | " [ --help ]\n" |
Harald Welte | 5891865 | 2001-06-16 18:25:25 +0000 | [diff] [blame] | 46 | " [ --noflush ]\n" |
| 47 | " [ --modprobe=<command>]\n", name); |
Harald Welte | a9d2708 | 2000-12-19 16:10:42 +0000 | [diff] [blame] | 48 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 49 | exit(1); |
| 50 | } |
| 51 | |
Harald Welte | 5891865 | 2001-06-16 18:25:25 +0000 | [diff] [blame] | 52 | iptc_handle_t create_handle(const char *tablename, const char* modprobe ) |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 53 | { |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 54 | iptc_handle_t handle; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 55 | |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 56 | handle = iptc_init(tablename); |
Harald Welte | 5891865 | 2001-06-16 18:25:25 +0000 | [diff] [blame] | 57 | |
| 58 | if (!handle) { |
| 59 | /* try to insmod the module if iptc_init failed */ |
| 60 | iptables_insmod("ip_tables", modprobe); |
| 61 | handle = iptc_init(tablename); |
| 62 | } |
| 63 | |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 64 | if (!handle) { |
| 65 | exit_error(PARAMETER_PROBLEM, "%s: unable to initialize" |
| 66 | "table '%s'\n", program_name, tablename); |
| 67 | exit(1); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 68 | } |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 69 | return handle; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Harald Welte | d8e6563 | 2001-01-05 15:20:07 +0000 | [diff] [blame] | 72 | int parse_counters(char *string, struct ipt_counters *ctr) |
| 73 | { |
| 74 | return (sscanf(string, "[%llu:%llu]", &ctr->pcnt, &ctr->bcnt) == 2); |
| 75 | } |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 76 | |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 77 | /* global new argv and argc */ |
Harald Welte | 26e643f | 2001-05-03 20:50:03 +0000 | [diff] [blame] | 78 | static char *newargv[255]; |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 79 | static int newargc; |
| 80 | |
| 81 | /* function adding one argument to newargv, updating newargc |
| 82 | * returns true if argument added, false otherwise */ |
| 83 | static int add_argv(char *what) { |
Harald Welte | bb41f88 | 2001-10-21 14:11:54 +0000 | [diff] [blame] | 84 | DEBUGP("add_argv: %s\n", what); |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 85 | if (what && ((newargc + 1) < sizeof(newargv)/sizeof(char *))) { |
Harald Welte | 26e643f | 2001-05-03 20:50:03 +0000 | [diff] [blame] | 86 | newargv[newargc] = strdup(what); |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 87 | newargc++; |
| 88 | return 1; |
| 89 | } else |
| 90 | return 0; |
| 91 | } |
| 92 | |
Harald Welte | 26e643f | 2001-05-03 20:50:03 +0000 | [diff] [blame] | 93 | static void free_argv(void) { |
| 94 | int i; |
| 95 | |
| 96 | for (i = 0; i < newargc; i++) |
| 97 | free(newargv[i]); |
| 98 | } |
| 99 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 100 | int main(int argc, char *argv[]) |
| 101 | { |
| 102 | iptc_handle_t handle; |
| 103 | char buffer[10240]; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 104 | unsigned int line = 0; |
Harald Welte | a9d2708 | 2000-12-19 16:10:42 +0000 | [diff] [blame] | 105 | int c; |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 106 | char curtable[IPT_TABLE_MAXNAMELEN + 1]; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 107 | FILE *in; |
Harald Welte | 5891865 | 2001-06-16 18:25:25 +0000 | [diff] [blame] | 108 | const char *modprobe = 0; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 109 | |
| 110 | program_name = "iptables-restore"; |
Harald Welte | 80fe35d | 2002-05-29 13:08:15 +0000 | [diff] [blame] | 111 | program_version = IPTABLES_VERSION; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 112 | |
Harald Welte | 3efb6ea | 2001-08-06 18:50:21 +0000 | [diff] [blame] | 113 | #ifdef NO_SHARED_LIBS |
| 114 | init_extensions(); |
| 115 | #endif |
| 116 | |
Harald Welte | 5891865 | 2001-06-16 18:25:25 +0000 | [diff] [blame] | 117 | while ((c = getopt_long(argc, argv, "bcvhnM:", options, NULL)) != -1) { |
Harald Welte | a9d2708 | 2000-12-19 16:10:42 +0000 | [diff] [blame] | 118 | switch (c) { |
| 119 | case 'b': |
| 120 | binary = 1; |
| 121 | break; |
| 122 | case 'c': |
| 123 | counters = 1; |
| 124 | break; |
Marc Boucher | 1277b59 | 2001-12-06 15:06:34 +0000 | [diff] [blame] | 125 | case 'v': |
| 126 | verbose = 1; |
| 127 | break; |
Harald Welte | a9d2708 | 2000-12-19 16:10:42 +0000 | [diff] [blame] | 128 | case 'h': |
| 129 | print_usage("iptables-restore", |
Harald Welte | 80fe35d | 2002-05-29 13:08:15 +0000 | [diff] [blame] | 130 | IPTABLES_VERSION); |
Harald Welte | a9d2708 | 2000-12-19 16:10:42 +0000 | [diff] [blame] | 131 | break; |
| 132 | case 'n': |
| 133 | noflush = 1; |
| 134 | break; |
Harald Welte | 5891865 | 2001-06-16 18:25:25 +0000 | [diff] [blame] | 135 | case 'M': |
| 136 | modprobe = optarg; |
| 137 | break; |
Harald Welte | a9d2708 | 2000-12-19 16:10:42 +0000 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 141 | if (optind == argc - 1) { |
| 142 | in = fopen(argv[optind], "r"); |
| 143 | if (!in) { |
| 144 | fprintf(stderr, "Can't open %s: %s", argv[optind], |
| 145 | strerror(errno)); |
| 146 | exit(1); |
| 147 | } |
| 148 | } |
| 149 | else if (optind < argc) { |
| 150 | fprintf(stderr, "Unknown arguments found on commandline"); |
| 151 | exit(1); |
| 152 | } |
| 153 | else in = stdin; |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 154 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 155 | /* Grab standard input. */ |
| 156 | while (fgets(buffer, sizeof(buffer), in)) { |
| 157 | int ret; |
| 158 | |
| 159 | line++; |
| 160 | if (buffer[0] == '\n') continue; |
| 161 | else if (buffer[0] == '#') { |
| 162 | if (verbose) fputs(buffer, stdout); |
| 163 | continue; |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 164 | } else if (strcmp(buffer, "COMMIT\n") == 0) { |
| 165 | DEBUGP("Calling commit\n"); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 166 | ret = iptc_commit(&handle); |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 167 | } else if (buffer[0] == '*') { |
| 168 | /* New table */ |
| 169 | char *table; |
| 170 | |
| 171 | table = strtok(buffer+1, " \t\n"); |
| 172 | DEBUGP("line %u, table '%s'\n", line, table); |
| 173 | if (!table) { |
| 174 | exit_error(PARAMETER_PROBLEM, |
| 175 | "%s: line %u table name invalid\n", |
| 176 | program_name, line); |
| 177 | exit(1); |
| 178 | } |
| 179 | strncpy(curtable, table, IPT_TABLE_MAXNAMELEN); |
| 180 | |
Harald Welte | 5891865 | 2001-06-16 18:25:25 +0000 | [diff] [blame] | 181 | handle = create_handle(table, modprobe); |
Harald Welte | a9d2708 | 2000-12-19 16:10:42 +0000 | [diff] [blame] | 182 | if (noflush == 0) { |
| 183 | DEBUGP("Cleaning all chains of table '%s'\n", |
| 184 | table); |
| 185 | for_each_chain(flush_entries, verbose, 1, |
| 186 | &handle); |
| 187 | |
| 188 | DEBUGP("Deleting all user-defined chains " |
| 189 | "of table '%s'\n", table); |
| 190 | for_each_chain(delete_chain, verbose, 0, |
| 191 | &handle) ; |
| 192 | } |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 193 | |
| 194 | ret = 1; |
| 195 | |
| 196 | } else if (buffer[0] == ':') { |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 197 | /* New chain. */ |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 198 | char *policy, *chain; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 199 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 200 | chain = strtok(buffer+1, " \t\n"); |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 201 | DEBUGP("line %u, chain '%s'\n", line, chain); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 202 | if (!chain) { |
| 203 | exit_error(PARAMETER_PROBLEM, |
| 204 | "%s: line %u chain name invalid\n", |
| 205 | program_name, line); |
| 206 | exit(1); |
| 207 | } |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 208 | |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 209 | if (!iptc_builtin(chain, handle)) { |
| 210 | DEBUGP("Creating new chain '%s'\n", chain); |
Harald Welte | 26e643f | 2001-05-03 20:50:03 +0000 | [diff] [blame] | 211 | if (!iptc_create_chain(chain, &handle)) |
| 212 | exit_error(PARAMETER_PROBLEM, |
| 213 | "error creating chain " |
| 214 | "'%s':%s\n", chain, |
| 215 | strerror(errno)); |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 216 | } |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 217 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 218 | policy = strtok(NULL, " \t\n"); |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 219 | DEBUGP("line %u, policy '%s'\n", line, policy); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 220 | if (!policy) { |
| 221 | exit_error(PARAMETER_PROBLEM, |
| 222 | "%s: line %u policy invalid\n", |
| 223 | program_name, line); |
| 224 | exit(1); |
| 225 | } |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 226 | |
| 227 | if (strcmp(policy, "-") != 0) { |
Harald Welte | d8e6563 | 2001-01-05 15:20:07 +0000 | [diff] [blame] | 228 | struct ipt_counters count; |
| 229 | |
| 230 | if (counters) { |
| 231 | char *ctrs; |
| 232 | ctrs = strtok(NULL, " \t\n"); |
| 233 | |
| 234 | parse_counters(ctrs, &count); |
| 235 | |
| 236 | } else { |
| 237 | memset(&count, 0, |
| 238 | sizeof(struct ipt_counters)); |
| 239 | } |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 240 | |
| 241 | DEBUGP("Setting policy of chain %s to %s\n", |
| 242 | chain, policy); |
| 243 | |
Harald Welte | d8e6563 | 2001-01-05 15:20:07 +0000 | [diff] [blame] | 244 | if (!iptc_set_policy(chain, policy, &count, |
| 245 | &handle)) |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 246 | exit_error(OTHER_PROBLEM, |
| 247 | "Can't set policy `%s'" |
| 248 | " on `%s' line %u: %s\n", |
| 249 | chain, policy, line, |
| 250 | iptc_strerror(errno)); |
| 251 | } |
| 252 | |
| 253 | ret = 1; |
| 254 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 255 | } else { |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 256 | int a; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 257 | char *ptr = buffer; |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 258 | char *pcnt = NULL; |
| 259 | char *bcnt = NULL; |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 260 | char *parsestart; |
| 261 | |
Harald Welte | 26e643f | 2001-05-03 20:50:03 +0000 | [diff] [blame] | 262 | /* the parser */ |
| 263 | char *param_start, *curchar; |
| 264 | int quote_open; |
| 265 | |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 266 | /* reset the newargv */ |
| 267 | newargc = 0; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 268 | |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 269 | if (buffer[0] == '[') { |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 270 | /* we have counters in our input */ |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 271 | ptr = strchr(buffer, ']'); |
| 272 | if (!ptr) |
| 273 | exit_error(PARAMETER_PROBLEM, |
| 274 | "Bad line %u: need ]\n", |
| 275 | line); |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 276 | |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 277 | pcnt = strtok(buffer+1, ":"); |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 278 | if (!pcnt) |
| 279 | exit_error(PARAMETER_PROBLEM, |
| 280 | "Bad line %u: need :\n", |
| 281 | line); |
| 282 | |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 283 | bcnt = strtok(NULL, "]"); |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 284 | if (!bcnt) |
| 285 | exit_error(PARAMETER_PROBLEM, |
| 286 | "Bad line %u: need ]\n", |
| 287 | line); |
| 288 | |
| 289 | /* start command parsing after counter */ |
| 290 | parsestart = ptr + 1; |
| 291 | } else { |
| 292 | /* start command parsing at start of line */ |
| 293 | parsestart = buffer; |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 294 | } |
Rusty Russell | 7e53bf9 | 2000-03-20 07:03:28 +0000 | [diff] [blame] | 295 | |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 296 | add_argv(argv[0]); |
| 297 | add_argv("-t"); |
| 298 | add_argv((char *) &curtable); |
| 299 | |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 300 | if (counters && pcnt && bcnt) { |
Harald Welte | 9f7fa49 | 2001-03-15 15:12:02 +0000 | [diff] [blame] | 301 | add_argv("--set-counters"); |
| 302 | add_argv((char *) pcnt); |
| 303 | add_argv((char *) bcnt); |
Harald Welte | ccd49e5 | 2001-01-23 22:54:34 +0000 | [diff] [blame] | 304 | } |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 305 | |
Harald Welte | 26e643f | 2001-05-03 20:50:03 +0000 | [diff] [blame] | 306 | /* After fighting with strtok enough, here's now |
| 307 | * a 'real' parser. According to Rusty I'm now no |
| 308 | * longer a real hacker, but I can live with that */ |
| 309 | |
| 310 | quote_open = 0; |
| 311 | param_start = parsestart; |
| 312 | |
| 313 | for (curchar = parsestart; *curchar; curchar++) { |
| 314 | if (*curchar == '"') { |
| 315 | if (quote_open) { |
| 316 | quote_open = 0; |
| 317 | *curchar = ' '; |
| 318 | } else { |
| 319 | quote_open = 1; |
| 320 | param_start++; |
| 321 | } |
| 322 | } |
| 323 | if (*curchar == ' ' |
| 324 | || *curchar == '\t' |
| 325 | || * curchar == '\n') { |
| 326 | char param_buffer[1024]; |
| 327 | int param_len = curchar-param_start; |
| 328 | |
| 329 | if (quote_open) |
| 330 | continue; |
| 331 | |
Harald Welte | 974d010 | 2001-05-26 04:41:56 +0000 | [diff] [blame] | 332 | if (!param_len) { |
| 333 | /* two spaces? */ |
| 334 | param_start++; |
| 335 | continue; |
| 336 | } |
Harald Welte | 26e643f | 2001-05-03 20:50:03 +0000 | [diff] [blame] | 337 | |
| 338 | /* end of one parameter */ |
| 339 | strncpy(param_buffer, param_start, |
| 340 | param_len); |
| 341 | *(param_buffer+param_len) = '\0'; |
Harald Welte | bb41f88 | 2001-10-21 14:11:54 +0000 | [diff] [blame] | 342 | |
| 343 | /* check if table name specified */ |
Harald Welte | 48a6f90 | 2001-10-22 15:16:21 +0000 | [diff] [blame] | 344 | if (!strncmp(param_buffer, "-t", 3) |
| 345 | || !strncmp(param_buffer, "--table", 8)) { |
Harald Welte | bb41f88 | 2001-10-21 14:11:54 +0000 | [diff] [blame] | 346 | exit_error(PARAMETER_PROBLEM, |
| 347 | "Line %u seems to have a " |
| 348 | "-t table option.\n", line); |
| 349 | exit(1); |
| 350 | } |
| 351 | |
Harald Welte | 26e643f | 2001-05-03 20:50:03 +0000 | [diff] [blame] | 352 | add_argv(param_buffer); |
| 353 | param_start += param_len + 1; |
| 354 | } else { |
| 355 | /* regular character, skip */ |
| 356 | } |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Harald Welte | 26e643f | 2001-05-03 20:50:03 +0000 | [diff] [blame] | 359 | DEBUGP("calling do_command(%u, argv, &%s, handle):\n", |
| 360 | newargc, curtable); |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 361 | |
Harald Welte | fa48fc8 | 2001-10-16 09:51:33 +0000 | [diff] [blame] | 362 | for (a = 0; a < newargc; a++) |
Harald Welte | ae1ff9f | 2000-12-01 14:26:20 +0000 | [diff] [blame] | 363 | DEBUGP("argv[%u]: %s\n", a, newargv[a]); |
| 364 | |
Harald Welte | 26e643f | 2001-05-03 20:50:03 +0000 | [diff] [blame] | 365 | ret = do_command(newargc, newargv, |
| 366 | &newargv[2], &handle); |
| 367 | |
| 368 | free_argv(); |
Marc Boucher | e6869a8 | 2000-03-20 06:03:29 +0000 | [diff] [blame] | 369 | } |
| 370 | if (!ret) { |
| 371 | fprintf(stderr, "%s: line %u failed\n", |
| 372 | program_name, line); |
| 373 | exit(1); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | return 0; |
| 378 | } |