Mercurial > dropbear
diff svr-runopts.c @ 118:5312ca05ed48 private-rez
propagate of 717950f4061f1123659ee87c7c168805af920ab7 and 839f98f136788cc1466e4641bf796f96040a085d from branch 'matt.dbclient.authpam' to 'matt.dbclient.rez'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 12 Sep 2004 04:56:50 +0000 |
parents | 298098b2a61e |
children | 9337c9f9a607 |
line wrap: on
line diff
--- a/svr-runopts.c Sun Aug 08 16:57:37 2004 +0000 +++ b/svr-runopts.c Sun Sep 12 04:56:50 2004 +0000 @@ -31,8 +31,6 @@ 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) { @@ -61,7 +59,7 @@ "-m Don't display the motd on login\n" #endif "-w Disallow root logins\n" -#ifdef DROPBEAR_PASSWORD_AUTH +#ifdef ENABLE_SVR_PASSWORD_AUTH "-s Disable password logins\n" "-g Disable password logins for root\n" #endif @@ -72,9 +70,13 @@ "-k Disable remote port forwarding\n" #endif "-p port Listen on specified tcp port, up to %d can be specified\n" - " (default %d if none specified)\n" -/* "-4/-6 Disable listening on ipv4/ipv6 respectively\n"*/ - + " (default %s if none specified)\n" +#ifdef INETD_MODE + "-i Start for inetd\n" +#endif +#ifdef DEBUG_TRACE + "-v verbose\n" +#endif ,DROPBEAR_VERSION, progname, #ifdef DROPBEAR_DSS DSS_PRIV_FILENAME, @@ -82,16 +84,13 @@ #ifdef DROPBEAR_RSA RSA_PRIV_FILENAME, #endif - DROPBEAR_MAX_PORTS, DROPBEAR_PORT); + DROPBEAR_MAX_PORTS, DROPBEAR_DEFPORT); } void svr_getopts(int argc, char ** argv) { unsigned int i; char ** next = 0; - unsigned int portnum = 0; - char *portstring[DROPBEAR_MAX_PORTS]; - unsigned int longport; /* see printhelp() for options */ svr_opts.rsakeyfile = NULL; @@ -102,6 +101,9 @@ svr_opts.norootlogin = 0; svr_opts.noauthpass = 0; svr_opts.norootpass = 0; + svr_opts.inetdmode = 0; + svr_opts.portcount = 0; + svr_opts.hostkey = NULL; opts.nolocaltcp = 0; opts.noremotetcp = 0; /* not yet @@ -158,11 +160,18 @@ opts.noremotetcp = 1; break; #endif +#ifdef INETD_MODE + case 'i': + svr_opts.inetdmode = 1; + break; +#endif case 'p': - if (portnum < DROPBEAR_MAX_PORTS) { - portstring[portnum] = NULL; - next = &portstring[portnum]; - portnum++; + 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; #ifdef DO_MOTD @@ -174,7 +183,7 @@ case 'w': svr_opts.norootlogin = 1; break; -#ifdef DROPBEAR_PASSWORD_AUTH +#ifdef ENABLE_SVR_PASSWORD_AUTH case 's': svr_opts.noauthpass = 1; break; @@ -186,14 +195,11 @@ printhelp(argv[0]); exit(EXIT_FAILURE); break; - /* - case '4': - svr_opts.ipv4 = 0; +#ifdef DEBUG_TRACE + case 'v': + debug_trace = 1; break; - case '6': - svr_opts.ipv6 = 0; - break; - */ +#endif default: fprintf(stderr, "Unknown argument %s\n", argv[i]); printhelp(argv[0]); @@ -203,13 +209,24 @@ } } + /* 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) { svr_opts.dsskeyfile = DSS_PRIV_FILENAME; } if (svr_opts.rsakeyfile == NULL) { svr_opts.rsakeyfile = RSA_PRIV_FILENAME; } - svr_opts.hostkey = loadhostkeys(svr_opts.dsskeyfile, svr_opts.rsakeyfile); if (svr_opts.bannerfile) { struct stat buf; @@ -231,35 +248,6 @@ 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) { @@ -272,47 +260,45 @@ 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"); } -static sign_key * loadhostkeys(const char * dsskeyfile, - const char * rsakeyfile) { +/* Must be called after syslog/etc is working */ +void loadhostkeys() { - sign_key * hostkey; int ret; int type; TRACE(("enter loadhostkeys")); - hostkey = new_sign_key(); + svr_opts.hostkey = new_sign_key(); #ifdef DROPBEAR_RSA type = DROPBEAR_SIGNKEY_RSA; - ret = readhostkey(rsakeyfile, hostkey, &type); + ret = readhostkey(svr_opts.rsakeyfile, svr_opts.hostkey, &type); if (ret == DROPBEAR_FAILURE) { - disablekey(DROPBEAR_SIGNKEY_RSA, rsakeyfile); + disablekey(DROPBEAR_SIGNKEY_RSA, svr_opts.rsakeyfile); } #endif #ifdef DROPBEAR_DSS - type = DROPBEAR_SIGNKEY_RSA; - ret = readhostkey(dsskeyfile, hostkey, &type); + type = DROPBEAR_SIGNKEY_DSS; + ret = readhostkey(svr_opts.dsskeyfile, svr_opts.hostkey, &type); if (ret == DROPBEAR_FAILURE) { - disablekey(DROPBEAR_SIGNKEY_DSS, dsskeyfile); + disablekey(DROPBEAR_SIGNKEY_DSS, svr_opts.dsskeyfile); } #endif if ( 1 #ifdef DROPBEAR_DSS - && hostkey->dsskey == NULL + && svr_opts.hostkey->dsskey == NULL #endif #ifdef DROPBEAR_RSA - && hostkey->rsakey == NULL + && svr_opts.hostkey->rsakey == NULL #endif ) { dropbear_exit("No hostkeys available"); } TRACE(("leave loadhostkeys")); - return hostkey; }