comparison svr-runopts.c @ 1164:8b6cba298768

Enable bundling
author Guilhem Moulin <guilhem@fripost.org>
date Fri, 06 Nov 2015 23:54:24 +0800
parents 1b583b2994ba
children 424822a6f8ee
comparison
equal deleted inserted replaced
1163:0a1891e23b18 1164:8b6cba298768
110 DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE, DEFAULT_IDLE_TIMEOUT); 110 DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE, DEFAULT_IDLE_TIMEOUT);
111 } 111 }
112 112
113 void svr_getopts(int argc, char ** argv) { 113 void svr_getopts(int argc, char ** argv) {
114 114
115 unsigned int i; 115 unsigned int i, j;
116 char ** next = 0; 116 char ** next = 0;
117 int nextisport = 0; 117 int nextisport = 0;
118 char* recv_window_arg = NULL; 118 char* recv_window_arg = NULL;
119 char* keepalive_arg = NULL; 119 char* keepalive_arg = NULL;
120 char* idle_timeout_arg = NULL; 120 char* idle_timeout_arg = NULL;
121 char* keyfile = NULL; 121 char* keyfile = NULL;
122 char c;
122 123
123 124
124 /* see printhelp() for options */ 125 /* see printhelp() for options */
125 svr_opts.bannerfile = NULL; 126 svr_opts.bannerfile = NULL;
126 svr_opts.banner = NULL; 127 svr_opts.banner = NULL;
166 #ifdef ENABLE_SVR_REMOTETCPFWD 167 #ifdef ENABLE_SVR_REMOTETCPFWD
167 opts.listen_fwd_all = 0; 168 opts.listen_fwd_all = 0;
168 #endif 169 #endif
169 170
170 for (i = 1; i < (unsigned int)argc; i++) { 171 for (i = 1; i < (unsigned int)argc; i++) {
171 if (nextisport) { 172 if (argv[i][0] != '-' || argv[i][1] == '\0')
172 addportandaddress(argv[i]); 173 dropbear_exit("Invalid argument: %s", argv[i]);
173 nextisport = 0; 174
174 continue; 175 for (j = 1; (c = argv[i][j]) != '\0' && !next && !nextisport; j++) {
175 }
176
177 if (next) {
178 *next = argv[i];
179 if (*next == NULL) {
180 dropbear_exit("Invalid null argument");
181 }
182 next = 0x00;
183
184 if (keyfile) {
185 addhostkey(keyfile);
186 keyfile = NULL;
187 }
188 continue;
189 }
190
191 if (argv[i][0] == '-') {
192 char c = argv[i][1];
193 if (strlen(argv[i]) != 2) {
194 /* We only handle one flag per hyphen */
195 fprintf(stderr, "Warning, trailing '%s' of '%s' is ignored.\n",
196 &argv[i][2], argv[i]);
197 }
198 switch (c) { 176 switch (c) {
199 case 'b': 177 case 'b':
200 next = &svr_opts.bannerfile; 178 next = &svr_opts.bannerfile;
201 break; 179 break;
202 case 'd': 180 case 'd':
282 case 'V': 260 case 'V':
283 print_version(); 261 print_version();
284 exit(EXIT_SUCCESS); 262 exit(EXIT_SUCCESS);
285 break; 263 break;
286 default: 264 default:
287 fprintf(stderr, "Unknown argument %s\n", argv[i]); 265 fprintf(stderr, "Invalid option -%c\n", c);
288 printhelp(argv[0]); 266 printhelp(argv[0]);
289 exit(EXIT_FAILURE); 267 exit(EXIT_FAILURE);
290 break; 268 break;
269 }
270 }
271
272 if (!next && !nextisport)
273 continue;
274
275 if (c == '\0') {
276 i++;
277 j = 0;
278 if (!argv[i]) {
279 dropbear_exit("Missing argument");
280 }
281 }
282
283 if (nextisport) {
284 addportandaddress(&argv[i][j]);
285 nextisport = 0;
286 } else if (next) {
287 *next = &argv[i][j];
288 if (*next == NULL) {
289 dropbear_exit("Invalid null argument");
290 }
291 next = 0x00;
292
293 if (keyfile) {
294 addhostkey(keyfile);
295 keyfile = NULL;
291 } 296 }
292 } 297 }
293 } 298 }
294 299
295 /* Set up listening ports */ 300 /* Set up listening ports */