123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- #include "includes.h"
- #include "runopts.h"
- #include "signkey.h"
- #include "buffer.h"
- #include "dbutil.h"
- #include "auth.h"
- #include "algo.h"
- #include "dbrandom.h"
- runopts opts;
- int readhostkey(const char * filename, sign_key * hostkey,
- enum signkey_type *type) {
- int ret = DROPBEAR_FAILURE;
- buffer *buf;
- buf = buf_new(MAX_PRIVKEY_SIZE);
- if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) {
- goto out;
- }
- buf_setpos(buf, 0);
- addrandom(buf_getptr(buf, buf->len), buf->len);
- if (buf_get_priv_key(buf, hostkey, type) == DROPBEAR_FAILURE) {
- goto out;
- }
- ret = DROPBEAR_SUCCESS;
- out:
- buf_burn_free(buf);
- return ret;
- }
- #if DROPBEAR_USER_ALGO_LIST
- void
- parse_ciphers_macs() {
- int printed_help = 0;
- if (opts.cipher_list) {
- if (strcmp(opts.cipher_list, "help") == 0) {
- char *ciphers = algolist_string(sshciphers);
- dropbear_log(LOG_INFO, "Available ciphers: %s", ciphers);
- m_free(ciphers);
- printed_help = 1;
- } else {
- if (check_user_algos(opts.cipher_list, sshciphers, "cipher") == 0) {
- dropbear_exit("No valid ciphers specified for '-c'");
- }
- }
- }
- if (opts.mac_list) {
- if (strcmp(opts.mac_list, "help") == 0) {
- char *macs = algolist_string(sshhashes);
- dropbear_log(LOG_INFO, "Available MACs: %s", macs);
- m_free(macs);
- printed_help = 1;
- } else {
- if (check_user_algos(opts.mac_list, sshhashes, "MAC") == 0) {
- dropbear_exit("No valid MACs specified for '-m'");
- }
- }
- }
- if (printed_help) {
- dropbear_exit(".");
- }
- }
- #endif
- void print_version() {
- fprintf(stderr, "Dropbear v%s\n", DROPBEAR_VERSION);
- }
- void parse_recv_window(const char* recv_window_arg) {
- int ret;
- unsigned int rw;
- ret = m_str_to_uint(recv_window_arg, &rw);
- if (ret == DROPBEAR_FAILURE || rw == 0 || rw > MAX_RECV_WINDOW) {
- if (rw > MAX_RECV_WINDOW) {
- opts.recv_window = MAX_RECV_WINDOW;
- }
- dropbear_log(LOG_WARNING, "Bad recv window '%s', using %d",
- recv_window_arg, opts.recv_window);
- } else {
- opts.recv_window = rw;
- }
- }
- int split_address_port(const char* spec, char **first, char ** second) {
- char *spec_copy = NULL, *addr = NULL, *colon = NULL;
- int ret = DROPBEAR_FAILURE;
- *first = NULL;
- *second = NULL;
- spec_copy = m_strdup(spec);
- addr = spec_copy;
- if (*addr == '[') {
- addr++;
- colon = strchr(addr, ']');
- if (!colon) {
- dropbear_log(LOG_WARNING, "Bad address '%s'", spec);
- goto out;
- }
- *colon = '\0';
- colon++;
- if (*colon == '\0') {
-
- colon = NULL;
- } else if (*colon != ':') {
- dropbear_log(LOG_WARNING, "Bad address '%s'", spec);
- goto out;
- }
- } else {
-
- colon = strrchr(addr, ':');
- }
-
- if (colon) {
-
- *colon = '\0';
- colon++;
- *second = m_strdup(colon);
- }
- if (strlen(addr)) {
- *first = m_strdup(addr);
- }
- ret = DROPBEAR_SUCCESS;
- out:
- m_free(spec_copy);
- return ret;
- }
|