summaryrefslogtreecommitdiff
path: root/svr-runopts.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2007-02-22 14:53:49 +0000
committerMatt Johnston <matt@ucc.asn.au>2007-02-22 14:53:49 +0000
commit02b8e1410a4b458b45f3ab4a0dd8cd42ed340d04 (patch)
tree092cac6797947f7b23fcdcc2c081b19c390c5bc4 /svr-runopts.c
parentd2607cc80dbb4f251f7b1dd47f61b4604568d3a5 (diff)
parentcd285c0398271ce8064a29398d8e0a23a5712070 (diff)
downloaddropbear-02b8e1410a4b458b45f3ab4a0dd8cd42ed340d04.tar.gz
merge of 'a9b0496634cdd25647b65e585cc3240f3fa699ee'
and 'c22be8b8f570b48e9662dac32c7b3e7148a42206'
Diffstat (limited to 'svr-runopts.c')
-rw-r--r--svr-runopts.c69
1 files changed, 52 insertions, 17 deletions
diff --git a/svr-runopts.c b/svr-runopts.c
index 784e0ca..2f51096 100644
--- a/svr-runopts.c
+++ b/svr-runopts.c
@@ -32,6 +32,7 @@
svr_runopts svr_opts; /* GLOBAL */
static void printhelp(const char * progname);
+static void addportandaddress(char* spec);
static void printhelp(const char * progname) {
@@ -70,8 +71,10 @@ static void printhelp(const char * progname) {
"-k Disable remote port forwarding\n"
"-a Allow connections to forwarded ports from any host\n"
#endif
- "-p port Listen on specified tcp port, up to %d can be specified\n"
- " (default %s if none specified)\n"
+ "-p [address:]port\n"
+ " Listen on specified tcp port (and optionally address),\n"
+ " up to %d can be specified\n"
+ " (default port is %s if none specified)\n"
"-P PidFile Create pid file PidFile\n"
" (default %s)\n"
#ifdef INETD_MODE
@@ -94,6 +97,7 @@ void svr_getopts(int argc, char ** argv) {
unsigned int i;
char ** next = 0;
+ int nextisport = 0;
/* see printhelp() for options */
svr_opts.rsakeyfile = NULL;
@@ -129,6 +133,12 @@ void svr_getopts(int argc, char ** argv) {
#endif
for (i = 1; i < (unsigned int)argc; i++) {
+ if (nextisport) {
+ addportandaddress(argv[i]);
+ nextisport = 0;
+ continue;
+ }
+
if (next) {
*next = argv[i];
if (*next == NULL) {
@@ -180,14 +190,8 @@ void svr_getopts(int argc, char ** argv) {
break;
#endif
case 'p':
- if (svr_opts.portcount < DROPBEAR_MAX_PORTS) {
- svr_opts.ports[svr_opts.portcount] = NULL;
- next = &svr_opts.ports[svr_opts.portcount];
- /* Note: if it doesn't actually get set, we'll
- * decrement it after the loop */
- svr_opts.portcount++;
- }
- break;
+ nextisport = 1;
+ break;
case 'P':
next = &svr_opts.pidfile;
break;
@@ -229,15 +233,10 @@ void svr_getopts(int argc, char ** argv) {
/* Set up listening ports */
if (svr_opts.portcount == 0) {
svr_opts.ports[0] = m_strdup(DROPBEAR_DEFPORT);
+ svr_opts.addresses[0] = m_strdup(DROPBEAR_DEFADDRESS);
svr_opts.portcount = 1;
- } else {
- /* we may have been given a -p option but no argument to go with
- * it */
- if (svr_opts.ports[svr_opts.portcount-1] == NULL) {
- svr_opts.portcount--;
- }
}
-
+
if (svr_opts.dsskeyfile == NULL) {
svr_opts.dsskeyfile = DSS_PRIV_FILENAME;
}
@@ -267,6 +266,42 @@ void svr_getopts(int argc, char ** argv) {
}
+static void addportandaddress(char* spec) {
+
+ char *myspec = NULL;
+
+ if (svr_opts.portcount < DROPBEAR_MAX_PORTS) {
+
+ /* We don't free it, it becomes part of the runopt state */
+ myspec = m_strdup(spec);
+
+ /* search for ':', that separates address and port */
+ svr_opts.ports[svr_opts.portcount] = strchr(myspec, ':');
+
+ if (svr_opts.ports[svr_opts.portcount] == NULL) {
+ /* no ':' -> the whole string specifies just a port */
+ svr_opts.ports[svr_opts.portcount] = myspec;
+ } else {
+ /* Split the address/port */
+ svr_opts.ports[svr_opts.portcount][0] = '\0';
+ svr_opts.ports[svr_opts.portcount]++;
+ svr_opts.addresses[svr_opts.portcount] = myspec;
+ }
+
+ if (svr_opts.addresses[svr_opts.portcount] == NULL) {
+ /* no address given -> fill in the default address */
+ svr_opts.addresses[svr_opts.portcount] = m_strdup(DROPBEAR_DEFADDRESS);
+ }
+
+ if (svr_opts.ports[svr_opts.portcount][0] == '\0') {
+ /* empty port -> exit */
+ dropbear_exit("Bad port");
+ }
+
+ svr_opts.portcount++;
+ }
+}
+
static void disablekey(int type, const char* filename) {
int i;