mirror of
https://github.com/clearml/dropbear
synced 2025-04-27 17:31:16 +00:00
Add -p [address:]port option for binding to addresses, patch from
Max-Gerd Retzlaff --HG-- extra : convert_revision : a9b0496634cdd25647b65e585cc3240f3fa699ee
This commit is contained in:
parent
46d53c37fa
commit
66643fa5c7
@ -14,6 +14,11 @@
|
|||||||
#define DROPBEAR_DEFPORT "22"
|
#define DROPBEAR_DEFPORT "22"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DROPBEAR_DEFADDRESS
|
||||||
|
/* Listen on all interfaces */
|
||||||
|
#define DROPBEAR_DEFADDRESS ""
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Default hostkey paths - these can be specified on the command line */
|
/* Default hostkey paths - these can be specified on the command line */
|
||||||
#ifndef DSS_PRIV_FILENAME
|
#ifndef DSS_PRIV_FILENAME
|
||||||
#define DSS_PRIV_FILENAME "/etc/dropbear/dropbear_dss_host_key"
|
#define DSS_PRIV_FILENAME "/etc/dropbear/dropbear_dss_host_key"
|
||||||
|
@ -55,6 +55,7 @@ typedef struct svr_runopts {
|
|||||||
/* ports is an array of the portcount listening ports */
|
/* ports is an array of the portcount listening ports */
|
||||||
char *ports[DROPBEAR_MAX_PORTS];
|
char *ports[DROPBEAR_MAX_PORTS];
|
||||||
unsigned int portcount;
|
unsigned int portcount;
|
||||||
|
char *addresses[DROPBEAR_MAX_PORTS];
|
||||||
|
|
||||||
int inetdmode;
|
int inetdmode;
|
||||||
|
|
||||||
|
@ -397,9 +397,9 @@ static size_t listensockets(int *sock, size_t sockcount, int *maxfd) {
|
|||||||
|
|
||||||
for (i = 0; i < svr_opts.portcount; i++) {
|
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,
|
sockcount - sockpos,
|
||||||
&errstring, maxfd);
|
&errstring, maxfd);
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
svr_runopts svr_opts; /* GLOBAL */
|
svr_runopts svr_opts; /* GLOBAL */
|
||||||
|
|
||||||
static void printhelp(const char * progname);
|
static void printhelp(const char * progname);
|
||||||
|
static void addportandaddress(char* spec);
|
||||||
|
|
||||||
static void printhelp(const char * progname) {
|
static void printhelp(const char * progname) {
|
||||||
|
|
||||||
@ -70,8 +71,10 @@ static void printhelp(const char * progname) {
|
|||||||
"-k Disable remote port forwarding\n"
|
"-k Disable remote port forwarding\n"
|
||||||
"-a Allow connections to forwarded ports from any host\n"
|
"-a Allow connections to forwarded ports from any host\n"
|
||||||
#endif
|
#endif
|
||||||
"-p port Listen on specified tcp port, up to %d can be specified\n"
|
"-p [address:]port\n"
|
||||||
" (default %s if none specified)\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"
|
||||||
#ifdef INETD_MODE
|
#ifdef INETD_MODE
|
||||||
"-i Start for inetd\n"
|
"-i Start for inetd\n"
|
||||||
#endif
|
#endif
|
||||||
@ -92,6 +95,7 @@ void svr_getopts(int argc, char ** argv) {
|
|||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
char ** next = 0;
|
char ** next = 0;
|
||||||
|
int nextisport = 0;
|
||||||
|
|
||||||
/* see printhelp() for options */
|
/* see printhelp() for options */
|
||||||
svr_opts.rsakeyfile = NULL;
|
svr_opts.rsakeyfile = NULL;
|
||||||
@ -126,6 +130,12 @@ void svr_getopts(int argc, char ** argv) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (i = 1; i < (unsigned int)argc; i++) {
|
for (i = 1; i < (unsigned int)argc; i++) {
|
||||||
|
if (nextisport) {
|
||||||
|
addportandaddress(argv[i]);
|
||||||
|
nextisport = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (next) {
|
if (next) {
|
||||||
*next = argv[i];
|
*next = argv[i];
|
||||||
if (*next == NULL) {
|
if (*next == NULL) {
|
||||||
@ -177,14 +187,8 @@ void svr_getopts(int argc, char ** argv) {
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'p':
|
case 'p':
|
||||||
if (svr_opts.portcount < DROPBEAR_MAX_PORTS) {
|
nextisport = 1;
|
||||||
svr_opts.ports[svr_opts.portcount] = NULL;
|
break;
|
||||||
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;
|
|
||||||
#ifdef DO_MOTD
|
#ifdef DO_MOTD
|
||||||
/* motd is displayed by default, -m turns it off */
|
/* motd is displayed by default, -m turns it off */
|
||||||
case 'm':
|
case 'm':
|
||||||
@ -223,13 +227,8 @@ void svr_getopts(int argc, char ** argv) {
|
|||||||
/* Set up listening ports */
|
/* Set up listening ports */
|
||||||
if (svr_opts.portcount == 0) {
|
if (svr_opts.portcount == 0) {
|
||||||
svr_opts.ports[0] = m_strdup(DROPBEAR_DEFPORT);
|
svr_opts.ports[0] = m_strdup(DROPBEAR_DEFPORT);
|
||||||
|
svr_opts.addresses[0] = m_strdup(DROPBEAR_DEFADDRESS);
|
||||||
svr_opts.portcount = 1;
|
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) {
|
if (svr_opts.dsskeyfile == NULL) {
|
||||||
@ -261,6 +260,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) {
|
static void disablekey(int type, const char* filename) {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
Loading…
Reference in New Issue
Block a user