~ubuntu-branches/ubuntu/utopic/dropbear/utopic-proposed

« back to all changes in this revision

Viewing changes to svr-runopts.c

  • Committer: Bazaar Package Importer
  • Author(s): Gerrit Pape, Matt Johnston, Gerrit Pape
  • Date: 2008-03-27 20:08:06 UTC
  • mfrom: (1.4.1 upstream) (9 hardy)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20080327200806-c1hhdgt3ht2gk496
Tags: 0.51-1
[ Matt Johnston ]
* New upstream release.
  - Wait until a process exits before the server closes a connection,
    so that an exit code can be sent. This fixes problems with exit
    codes not being returned, which could cause scp to fail (closes:
    #448397, #472483).

[ Gerrit Pape ]
* debian/dropbear.postinst: don't print an error message if the
  update-service program is not installed (thx Matt).

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
svr_runopts svr_opts; /* GLOBAL */
33
33
 
34
34
static void printhelp(const char * progname);
 
35
static void addportandaddress(char* spec);
35
36
 
36
37
static void printhelp(const char * progname) {
37
38
 
70
71
                                        "-k             Disable remote port forwarding\n"
71
72
                                        "-a             Allow connections to forwarded ports from any host\n"
72
73
#endif
73
 
                                        "-p port                Listen on specified tcp port, up to %d can be specified\n"
74
 
                                        "               (default %s if none specified)\n"
 
74
                                        "-p [address:]port\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"
 
79
                                        "               (default %s)\n"
75
80
#ifdef INETD_MODE
76
81
                                        "-i             Start for inetd\n"
77
82
#endif
 
83
                                        "-W <receive_window_buffer> (default %d, larger may be faster, max 1MB)\n"
 
84
                                        "-K <keepalive>  (0 is never, default %d)\n"
78
85
#ifdef DEBUG_TRACE
79
86
                                        "-v             verbose\n"
80
87
#endif
85
92
#ifdef DROPBEAR_RSA
86
93
                                        RSA_PRIV_FILENAME,
87
94
#endif
88
 
                                        DROPBEAR_MAX_PORTS, DROPBEAR_DEFPORT);
 
95
                                        DROPBEAR_MAX_PORTS, DROPBEAR_DEFPORT, DROPBEAR_PIDFILE,
 
96
                                        DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE);
89
97
}
90
98
 
91
99
void svr_getopts(int argc, char ** argv) {
92
100
 
93
101
        unsigned int i;
94
102
        char ** next = 0;
 
103
        int nextisport = 0;
 
104
        char* recv_window_arg = NULL;
 
105
        char* keepalive_arg = NULL;
95
106
 
96
107
        /* see printhelp() for options */
97
108
        svr_opts.rsakeyfile = NULL;
105
116
        svr_opts.inetdmode = 0;
106
117
        svr_opts.portcount = 0;
107
118
        svr_opts.hostkey = NULL;
 
119
        svr_opts.pidfile = DROPBEAR_PIDFILE;
108
120
#ifdef ENABLE_SVR_LOCALTCPFWD
109
121
        svr_opts.nolocaltcp = 0;
110
122
#endif
121
133
#ifndef DISABLE_SYSLOG
122
134
        svr_opts.usingsyslog = 1;
123
135
#endif
 
136
        opts.recv_window = DEFAULT_RECV_WINDOW;
 
137
        opts.keepalive_secs = DEFAULT_KEEPALIVE;        
 
138
        
124
139
#ifdef ENABLE_SVR_REMOTETCPFWD
125
140
        opts.listen_fwd_all = 0;
126
141
#endif
127
142
 
128
143
        for (i = 1; i < (unsigned int)argc; i++) {
 
144
                if (nextisport) {
 
145
                        addportandaddress(argv[i]);
 
146
                        nextisport = 0;
 
147
                        continue;
 
148
                }
 
149
          
129
150
                if (next) {
130
151
                        *next = argv[i];
131
152
                        if (*next == NULL) {
177
198
                                        break;
178
199
#endif
179
200
                                case 'p':
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++;
186
 
                                        }
 
201
                                  nextisport = 1;
 
202
                                  break;
 
203
                                case 'P':
 
204
                                        next = &svr_opts.pidfile;
187
205
                                        break;
188
206
#ifdef DO_MOTD
189
207
                                /* motd is displayed by default, -m turns it off */
194
212
                                case 'w':
195
213
                                        svr_opts.norootlogin = 1;
196
214
                                        break;
 
215
                                case 'W':
 
216
                                        next = &recv_window_arg;
 
217
                                        break;
 
218
                                case 'K':
 
219
                                        next = &keepalive_arg;
 
220
                                        break;
197
221
#if defined(ENABLE_SVR_PASSWORD_AUTH) || defined(ENABLE_SVR_PAM_AUTH)
198
222
                                case 's':
199
223
                                        svr_opts.noauthpass = 1;
206
230
                                        printhelp(argv[0]);
207
231
                                        exit(EXIT_FAILURE);
208
232
                                        break;
 
233
                                case 'u':
 
234
                                        /* backwards compatibility with old urandom option */
 
235
                                        break;
209
236
#ifdef DEBUG_TRACE
210
237
                                case 'v':
211
238
                                        debug_trace = 1;
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;
227
 
        } else {
228
 
                /* we may have been given a -p option but no argument to go with
229
 
                 * it */
230
 
                if (svr_opts.ports[svr_opts.portcount-1] == NULL) {
231
 
                        svr_opts.portcount--;
232
 
                }
233
255
        }
234
 
 
 
256
        
235
257
        if (svr_opts.dsskeyfile == NULL) {
236
258
                svr_opts.dsskeyfile = DSS_PRIV_FILENAME;
237
259
        }
257
279
                                        svr_opts.bannerfile);
258
280
                }
259
281
                buf_setpos(svr_opts.banner, 0);
260
 
        }
261
 
 
 
282
 
 
283
        }
 
284
        
 
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)
 
288
                {
 
289
                        dropbear_exit("Bad recv window '%s'", recv_window_arg);
 
290
                }
 
291
        }
 
292
        
 
293
        if (keepalive_arg) {
 
294
                opts.keepalive_secs = strtoul(keepalive_arg, NULL, 10);
 
295
                if (opts.keepalive_secs == 0 && errno == EINVAL)
 
296
                {
 
297
                        dropbear_exit("Bad keepalive '%s'", keepalive_arg);
 
298
                }
 
299
        }
 
300
}
 
301
 
 
302
static void addportandaddress(char* spec) {
 
303
 
 
304
        char *myspec = NULL;
 
305
 
 
306
        if (svr_opts.portcount < DROPBEAR_MAX_PORTS) {
 
307
 
 
308
                /* We don't free it, it becomes part of the runopt state */
 
309
                myspec = m_strdup(spec);
 
310
 
 
311
                /* search for ':', that separates address and port */
 
312
                svr_opts.ports[svr_opts.portcount] = strchr(myspec, ':');
 
313
 
 
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;
 
317
                } else {
 
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;
 
322
                }
 
323
 
 
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);
 
327
                }
 
328
 
 
329
                if (svr_opts.ports[svr_opts.portcount][0] == '\0') {
 
330
                        /* empty port -> exit */
 
331
                        dropbear_exit("Bad port");
 
332
                }
 
333
 
 
334
                svr_opts.portcount++;
 
335
        }
262
336
}
263
337
 
264
338
static void disablekey(int type, const char* filename) {