mirror of
https://github.com/clearml/dropbear
synced 2025-03-03 18:52:00 +00:00
Change the way we load keys/ports so we don't print error messages into our
socket. --HG-- extra : convert_revision : b830e790bd08933685502f36d8e7838f143f2f2f
This commit is contained in:
parent
f3761a3eda
commit
aaac206345
@ -52,7 +52,7 @@ typedef struct svr_runopts {
|
|||||||
int usingsyslog;
|
int usingsyslog;
|
||||||
|
|
||||||
/* ports is an array of the portcount listening ports */
|
/* ports is an array of the portcount listening ports */
|
||||||
uint16_t *ports;
|
char *ports[DROPBEAR_MAX_PORTS];
|
||||||
unsigned int portcount;
|
unsigned int portcount;
|
||||||
|
|
||||||
int inetdmode;
|
int inetdmode;
|
||||||
@ -81,6 +81,7 @@ typedef struct svr_runopts {
|
|||||||
extern svr_runopts svr_opts;
|
extern svr_runopts svr_opts;
|
||||||
|
|
||||||
void svr_getopts(int argc, char ** argv);
|
void svr_getopts(int argc, char ** argv);
|
||||||
|
void loadhostkeys();
|
||||||
|
|
||||||
/* Uncompleted XXX matt */
|
/* Uncompleted XXX matt */
|
||||||
typedef struct cli_runopts {
|
typedef struct cli_runopts {
|
||||||
|
16
svr-main.c
16
svr-main.c
@ -139,6 +139,10 @@ void main_noinetd() {
|
|||||||
|
|
||||||
commonsetup();
|
commonsetup();
|
||||||
|
|
||||||
|
/* Now we can setup the hostkeys - needs to be after logging is on,
|
||||||
|
* otherwise we might end up blatting error messages to the socket */
|
||||||
|
loadhostkeys();
|
||||||
|
|
||||||
/* should be done after syslog is working */
|
/* should be done after syslog is working */
|
||||||
if (svr_opts.forkbg) {
|
if (svr_opts.forkbg) {
|
||||||
dropbear_log(LOG_INFO, "Running in background");
|
dropbear_log(LOG_INFO, "Running in background");
|
||||||
@ -358,21 +362,23 @@ static void commonsetup() {
|
|||||||
static int listensockets(int *sock, int sockcount, int *maxfd) {
|
static int listensockets(int *sock, int sockcount, int *maxfd) {
|
||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
char portstring[NI_MAXSERV];
|
|
||||||
char* errstring = NULL;
|
char* errstring = NULL;
|
||||||
unsigned int sockpos = 0;
|
unsigned int sockpos = 0;
|
||||||
int nsock;
|
int nsock;
|
||||||
|
|
||||||
|
TRACE(("listensockets: %d to try\n", svr_opts.portcount));
|
||||||
|
|
||||||
for (i = 0; i < svr_opts.portcount; i++) {
|
for (i = 0; i < svr_opts.portcount; i++) {
|
||||||
|
|
||||||
snprintf(portstring, sizeof(portstring), "%d", svr_opts.ports[i]);
|
TRACE(("listening on '%s'", svr_opts.ports[i]));
|
||||||
nsock = dropbear_listen(NULL, portstring, &sock[sockpos],
|
|
||||||
|
nsock = dropbear_listen(NULL, svr_opts.ports[i], &sock[sockpos],
|
||||||
sockcount - sockpos,
|
sockcount - sockpos,
|
||||||
&errstring, maxfd);
|
&errstring, maxfd);
|
||||||
|
|
||||||
if (nsock < 0) {
|
if (nsock < 0) {
|
||||||
dropbear_log(LOG_WARNING, "Failed listening on port %s: %s",
|
dropbear_log(LOG_WARNING, "Failed listening on '%s': %s",
|
||||||
portstring, errstring);
|
svr_opts.ports[i], errstring);
|
||||||
m_free(errstring);
|
m_free(errstring);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,6 @@
|
|||||||
|
|
||||||
svr_runopts svr_opts; /* GLOBAL */
|
svr_runopts svr_opts; /* GLOBAL */
|
||||||
|
|
||||||
static sign_key * loadhostkeys(const char * dsskeyfile,
|
|
||||||
const char * rsakeyfile);
|
|
||||||
static void printhelp(const char * progname);
|
static void printhelp(const char * progname);
|
||||||
|
|
||||||
static void printhelp(const char * progname) {
|
static void printhelp(const char * progname) {
|
||||||
@ -86,16 +84,13 @@ static void printhelp(const char * progname) {
|
|||||||
#ifdef DROPBEAR_RSA
|
#ifdef DROPBEAR_RSA
|
||||||
RSA_PRIV_FILENAME,
|
RSA_PRIV_FILENAME,
|
||||||
#endif
|
#endif
|
||||||
DROPBEAR_MAX_PORTS, DROPBEAR_PORT);
|
DROPBEAR_MAX_PORTS, DROPBEAR_DEFPORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void svr_getopts(int argc, char ** argv) {
|
void svr_getopts(int argc, char ** argv) {
|
||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
char ** next = 0;
|
char ** next = 0;
|
||||||
unsigned int portnum = 0;
|
|
||||||
char *portstring[DROPBEAR_MAX_PORTS];
|
|
||||||
unsigned int longport;
|
|
||||||
|
|
||||||
/* see printhelp() for options */
|
/* see printhelp() for options */
|
||||||
svr_opts.rsakeyfile = NULL;
|
svr_opts.rsakeyfile = NULL;
|
||||||
@ -107,6 +102,8 @@ void svr_getopts(int argc, char ** argv) {
|
|||||||
svr_opts.noauthpass = 0;
|
svr_opts.noauthpass = 0;
|
||||||
svr_opts.norootpass = 0;
|
svr_opts.norootpass = 0;
|
||||||
svr_opts.inetdmode = 0;
|
svr_opts.inetdmode = 0;
|
||||||
|
svr_opts.portcount = 0;
|
||||||
|
svr_opts.hostkey = NULL;
|
||||||
opts.nolocaltcp = 0;
|
opts.nolocaltcp = 0;
|
||||||
opts.noremotetcp = 0;
|
opts.noremotetcp = 0;
|
||||||
/* not yet
|
/* not yet
|
||||||
@ -169,10 +166,12 @@ void svr_getopts(int argc, char ** argv) {
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'p':
|
case 'p':
|
||||||
if (portnum < DROPBEAR_MAX_PORTS) {
|
if (svr_opts.portcount < DROPBEAR_MAX_PORTS) {
|
||||||
portstring[portnum] = NULL;
|
svr_opts.ports[svr_opts.portcount] = NULL;
|
||||||
next = &portstring[portnum];
|
next = &svr_opts.ports[svr_opts.portcount];
|
||||||
portnum++;
|
/* Note: if it doesn't actually get set, we'll
|
||||||
|
* decrement it after the loop */
|
||||||
|
svr_opts.portcount++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#ifdef DO_MOTD
|
#ifdef DO_MOTD
|
||||||
@ -201,14 +200,6 @@ void svr_getopts(int argc, char ** argv) {
|
|||||||
debug_trace = 1;
|
debug_trace = 1;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
/*
|
|
||||||
case '4':
|
|
||||||
svr_opts.ipv4 = 0;
|
|
||||||
break;
|
|
||||||
case '6':
|
|
||||||
svr_opts.ipv6 = 0;
|
|
||||||
break;
|
|
||||||
*/
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unknown argument %s\n", argv[i]);
|
fprintf(stderr, "Unknown argument %s\n", argv[i]);
|
||||||
printhelp(argv[0]);
|
printhelp(argv[0]);
|
||||||
@ -218,13 +209,24 @@ 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.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) {
|
||||||
svr_opts.dsskeyfile = DSS_PRIV_FILENAME;
|
svr_opts.dsskeyfile = DSS_PRIV_FILENAME;
|
||||||
}
|
}
|
||||||
if (svr_opts.rsakeyfile == NULL) {
|
if (svr_opts.rsakeyfile == NULL) {
|
||||||
svr_opts.rsakeyfile = RSA_PRIV_FILENAME;
|
svr_opts.rsakeyfile = RSA_PRIV_FILENAME;
|
||||||
}
|
}
|
||||||
svr_opts.hostkey = loadhostkeys(svr_opts.dsskeyfile, svr_opts.rsakeyfile);
|
|
||||||
|
|
||||||
if (svr_opts.bannerfile) {
|
if (svr_opts.bannerfile) {
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
@ -246,35 +248,6 @@ void svr_getopts(int argc, char ** argv) {
|
|||||||
buf_setpos(svr_opts.banner, 0);
|
buf_setpos(svr_opts.banner, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* not yet
|
|
||||||
if (!(svr_opts.ipv4 || svr_opts.ipv6)) {
|
|
||||||
fprintf(stderr, "You can't disable ipv4 and ipv6.\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* create the array of listening ports */
|
|
||||||
if (portnum == 0) {
|
|
||||||
/* non specified */
|
|
||||||
svr_opts.portcount = 1;
|
|
||||||
svr_opts.ports = m_malloc(sizeof(uint16_t));
|
|
||||||
svr_opts.ports[0] = DROPBEAR_PORT;
|
|
||||||
} else {
|
|
||||||
svr_opts.portcount = portnum;
|
|
||||||
svr_opts.ports = (uint16_t*)m_malloc(sizeof(uint16_t)*portnum);
|
|
||||||
for (i = 0; i < portnum; i++) {
|
|
||||||
if (portstring[i]) {
|
|
||||||
longport = atoi(portstring[i]);
|
|
||||||
if (longport <= 65535 && longport > 0) {
|
|
||||||
svr_opts.ports[i] = (uint16_t)longport;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(stderr, "Bad port '%s'\n",
|
|
||||||
portstring[i] ? portstring[i] : "null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void disablekey(int type, const char* filename) {
|
static void disablekey(int type, const char* filename) {
|
||||||
@ -287,47 +260,45 @@ static void disablekey(int type, const char* filename) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Failed reading '%s', disabling %s\n", filename,
|
dropbear_log(LOG_WARNING, "Failed reading '%s', disabling %s", filename,
|
||||||
type == DROPBEAR_SIGNKEY_DSS ? "DSS" : "RSA");
|
type == DROPBEAR_SIGNKEY_DSS ? "DSS" : "RSA");
|
||||||
}
|
}
|
||||||
|
|
||||||
static sign_key * loadhostkeys(const char * dsskeyfile,
|
/* Must be called after syslog/etc is working */
|
||||||
const char * rsakeyfile) {
|
void loadhostkeys() {
|
||||||
|
|
||||||
sign_key * hostkey;
|
|
||||||
int ret;
|
int ret;
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
TRACE(("enter loadhostkeys"));
|
TRACE(("enter loadhostkeys"));
|
||||||
|
|
||||||
hostkey = new_sign_key();
|
svr_opts.hostkey = new_sign_key();
|
||||||
|
|
||||||
#ifdef DROPBEAR_RSA
|
#ifdef DROPBEAR_RSA
|
||||||
type = DROPBEAR_SIGNKEY_RSA;
|
type = DROPBEAR_SIGNKEY_RSA;
|
||||||
ret = readhostkey(rsakeyfile, hostkey, &type);
|
ret = readhostkey(svr_opts.rsakeyfile, svr_opts.hostkey, &type);
|
||||||
if (ret == DROPBEAR_FAILURE) {
|
if (ret == DROPBEAR_FAILURE) {
|
||||||
disablekey(DROPBEAR_SIGNKEY_RSA, rsakeyfile);
|
disablekey(DROPBEAR_SIGNKEY_RSA, svr_opts.rsakeyfile);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef DROPBEAR_DSS
|
#ifdef DROPBEAR_DSS
|
||||||
type = DROPBEAR_SIGNKEY_DSS;
|
type = DROPBEAR_SIGNKEY_DSS;
|
||||||
ret = readhostkey(dsskeyfile, hostkey, &type);
|
ret = readhostkey(svr_opts.dsskeyfile, svr_opts.hostkey, &type);
|
||||||
if (ret == DROPBEAR_FAILURE) {
|
if (ret == DROPBEAR_FAILURE) {
|
||||||
disablekey(DROPBEAR_SIGNKEY_DSS, dsskeyfile);
|
disablekey(DROPBEAR_SIGNKEY_DSS, svr_opts.dsskeyfile);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( 1
|
if ( 1
|
||||||
#ifdef DROPBEAR_DSS
|
#ifdef DROPBEAR_DSS
|
||||||
&& hostkey->dsskey == NULL
|
&& svr_opts.hostkey->dsskey == NULL
|
||||||
#endif
|
#endif
|
||||||
#ifdef DROPBEAR_RSA
|
#ifdef DROPBEAR_RSA
|
||||||
&& hostkey->rsakey == NULL
|
&& svr_opts.hostkey->rsakey == NULL
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
dropbear_exit("No hostkeys available");
|
dropbear_exit("No hostkeys available");
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE(("leave loadhostkeys"));
|
TRACE(("leave loadhostkeys"));
|
||||||
return hostkey;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user