Mercurial > dropbear
changeset 435:337c45621e81
merge of 'a9b0496634cdd25647b65e585cc3240f3fa699ee'
and 'c22be8b8f570b48e9662dac32c7b3e7148a42206'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 22 Feb 2007 14:53:49 +0000 |
parents | 0aaaf68e97dc (diff) c216212001fc (current diff) |
children | 7282370416a0 |
files | libtomcrypt/src/headers/ltc_tommath.h libtomcrypt/src/headers/tommath_class.h libtomcrypt/src/headers/tommath_superclass.h libtomcrypt/src/misc/mpi/is_prime.c libtomcrypt/src/misc/mpi/mpi_to_ltc_error.c libtomcrypt/src/misc/mpi/rand_prime.c libtomcrypt/src/pk/asn1/der/sequence/der_decode_sequence.c libtomcrypt/src/pk/asn1/der/sequence/der_encode_sequence.c libtomcrypt/src/pk/dh/dh.c libtomcrypt/src/pk/dh/dh_sys.c libtomcrypt/src/pk/ecc/ecc_sys.c libtomcrypt/src/pk/packet_store_header.c libtomcrypt/src/pk/packet_valid_header.c libtomcrypt/testprof/dh_tests.c libtomcrypt/testprof/test.c libtommath/TODO libtommath/logs/sqr.old options.h runopts.h svr-main.c svr-runopts.c |
diffstat | 4 files changed, 60 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/options.h Fri Feb 16 14:42:08 2007 +0000 +++ b/options.h Thu Feb 22 14:53:49 2007 +0000 @@ -14,6 +14,11 @@ #define DROPBEAR_DEFPORT "22" #endif +#ifndef DROPBEAR_DEFADDRESS +/* Listen on all interfaces */ +#define DROPBEAR_DEFADDRESS "" +#endif + /* Default hostkey paths - these can be specified on the command line */ #ifndef DSS_PRIV_FILENAME #define DSS_PRIV_FILENAME "/etc/dropbear/dropbear_dss_host_key"
--- a/runopts.h Fri Feb 16 14:42:08 2007 +0000 +++ b/runopts.h Thu Feb 22 14:53:49 2007 +0000 @@ -55,6 +55,7 @@ /* ports is an array of the portcount listening ports */ char *ports[DROPBEAR_MAX_PORTS]; unsigned int portcount; + char *addresses[DROPBEAR_MAX_PORTS]; int inetdmode;
--- a/svr-main.c Fri Feb 16 14:42:08 2007 +0000 +++ b/svr-main.c Thu Feb 22 14:53:49 2007 +0000 @@ -403,9 +403,9 @@ for (i = 0; i < svr_opts.portcount; i++) { - TRACE(("listening on '%s'", svr_opts.ports[i])) + TRACE(("listening on '%s:%s'", svr_opts.addresses[i], svr_opts.ports[i])) - nsock = dropbear_listen("", svr_opts.ports[i], &sock[sockpos], + nsock = dropbear_listen(svr_opts.addresses[i], svr_opts.ports[i], &sock[sockpos], sockcount - sockpos, &errstring, maxfd);
--- a/svr-runopts.c Fri Feb 16 14:42:08 2007 +0000 +++ b/svr-runopts.c Thu Feb 22 14:53:49 2007 +0000 @@ -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 @@ "-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 @@ unsigned int i; char ** next = 0; + int nextisport = 0; /* see printhelp() for options */ svr_opts.rsakeyfile = NULL; @@ -129,6 +133,12 @@ #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 @@ 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 @@ /* 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 @@ } +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;