70
71
"-k Disable remote port forwarding\n"
71
72
"-a Allow connections to forwarded ports from any host\n"
73
"-p port Listen on specified tcp port, up to %d can be specified\n"
74
" (default %s if none specified)\n"
75
" Listen on specified tcp port (and optionally address),\n"
76
" up to %d can be specified\n"
77
" (default port is %s if none specified)\n"
78
"-P PidFile Create pid file PidFile\n"
76
81
"-i Start for inetd\n"
83
"-W <receive_window_buffer> (default %d, larger may be faster, max 1MB)\n"
84
"-K <keepalive> (0 is never, default %d)\n"
85
92
#ifdef DROPBEAR_RSA
88
DROPBEAR_MAX_PORTS, DROPBEAR_DEFPORT);
95
DROPBEAR_MAX_PORTS, DROPBEAR_DEFPORT, DROPBEAR_PIDFILE,
96
DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE);
91
99
void svr_getopts(int argc, char ** argv) {
104
char* recv_window_arg = NULL;
105
char* keepalive_arg = NULL;
96
107
/* see printhelp() for options */
97
108
svr_opts.rsakeyfile = NULL;
121
133
#ifndef DISABLE_SYSLOG
122
134
svr_opts.usingsyslog = 1;
136
opts.recv_window = DEFAULT_RECV_WINDOW;
137
opts.keepalive_secs = DEFAULT_KEEPALIVE;
124
139
#ifdef ENABLE_SVR_REMOTETCPFWD
125
140
opts.listen_fwd_all = 0;
128
143
for (i = 1; i < (unsigned int)argc; i++) {
145
addportandaddress(argv[i]);
131
152
if (*next == NULL) {
180
if (svr_opts.portcount < DROPBEAR_MAX_PORTS) {
181
svr_opts.ports[svr_opts.portcount] = NULL;
182
next = &svr_opts.ports[svr_opts.portcount];
183
/* Note: if it doesn't actually get set, we'll
184
* decrement it after the loop */
185
svr_opts.portcount++;
204
next = &svr_opts.pidfile;
189
207
/* motd is displayed by default, -m turns it off */
223
250
/* Set up listening ports */
224
251
if (svr_opts.portcount == 0) {
225
252
svr_opts.ports[0] = m_strdup(DROPBEAR_DEFPORT);
253
svr_opts.addresses[0] = m_strdup(DROPBEAR_DEFADDRESS);
226
254
svr_opts.portcount = 1;
228
/* we may have been given a -p option but no argument to go with
230
if (svr_opts.ports[svr_opts.portcount-1] == NULL) {
231
svr_opts.portcount--;
235
257
if (svr_opts.dsskeyfile == NULL) {
236
258
svr_opts.dsskeyfile = DSS_PRIV_FILENAME;
257
279
svr_opts.bannerfile);
259
281
buf_setpos(svr_opts.banner, 0);
285
if (recv_window_arg) {
286
opts.recv_window = atol(recv_window_arg);
287
if (opts.recv_window == 0 || opts.recv_window > MAX_RECV_WINDOW)
289
dropbear_exit("Bad recv window '%s'", recv_window_arg);
294
opts.keepalive_secs = strtoul(keepalive_arg, NULL, 10);
295
if (opts.keepalive_secs == 0 && errno == EINVAL)
297
dropbear_exit("Bad keepalive '%s'", keepalive_arg);
302
static void addportandaddress(char* spec) {
306
if (svr_opts.portcount < DROPBEAR_MAX_PORTS) {
308
/* We don't free it, it becomes part of the runopt state */
309
myspec = m_strdup(spec);
311
/* search for ':', that separates address and port */
312
svr_opts.ports[svr_opts.portcount] = strchr(myspec, ':');
314
if (svr_opts.ports[svr_opts.portcount] == NULL) {
315
/* no ':' -> the whole string specifies just a port */
316
svr_opts.ports[svr_opts.portcount] = myspec;
318
/* Split the address/port */
319
svr_opts.ports[svr_opts.portcount][0] = '\0';
320
svr_opts.ports[svr_opts.portcount]++;
321
svr_opts.addresses[svr_opts.portcount] = myspec;
324
if (svr_opts.addresses[svr_opts.portcount] == NULL) {
325
/* no address given -> fill in the default address */
326
svr_opts.addresses[svr_opts.portcount] = m_strdup(DROPBEAR_DEFADDRESS);
329
if (svr_opts.ports[svr_opts.portcount][0] == '\0') {
330
/* empty port -> exit */
331
dropbear_exit("Bad port");
334
svr_opts.portcount++;
264
338
static void disablekey(int type, const char* filename) {