annotate common-runopts.c @ 1938:77bc00dcc19f default tip main master

Bump version to 2022.82
author Matt Johnston <matt@ucc.asn.au>
date Fri, 01 Apr 2022 14:43:27 +0800
parents 4528afefe45d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /*
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 * Dropbear - a SSH2 server
1922
70f05f7d4d11 Default options comments, ignore localoptions.h
Begley Brothers Inc <begleybrothers@gmail.com>
parents: 1912
diff changeset
3 *
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 * Copyright (c) 2002,2003 Matt Johnston
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 * All rights reserved.
1922
70f05f7d4d11 Default options comments, ignore localoptions.h
Begley Brothers Inc <begleybrothers@gmail.com>
parents: 1912
diff changeset
6 *
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 * of this software and associated documentation files (the "Software"), to deal
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 * in the Software without restriction, including without limitation the rights
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 * copies of the Software, and to permit persons to whom the Software is
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 * furnished to do so, subject to the following conditions:
1922
70f05f7d4d11 Default options comments, ignore localoptions.h
Begley Brothers Inc <begleybrothers@gmail.com>
parents: 1912
diff changeset
13 *
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 * The above copyright notice and this permission notice shall be included in
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 * all copies or substantial portions of the Software.
1922
70f05f7d4d11 Default options comments, ignore localoptions.h
Begley Brothers Inc <begleybrothers@gmail.com>
parents: 1912
diff changeset
16 *
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 * SOFTWARE. */
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 #include "includes.h"
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 #include "runopts.h"
47
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
27 #include "signkey.h"
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
28 #include "buffer.h"
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
29 #include "dbutil.h"
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
30 #include "auth.h"
682
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
31 #include "algo.h"
858
220f55d540ae rename random.h to dbrandom.h since some OSes have a system random.h
Matt Johnston <matt@ucc.asn.au>
parents: 841
diff changeset
32 #include "dbrandom.h"
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 runopts opts; /* GLOBAL */
47
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
35
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
36 /* returns success or failure, and the keytype in *type. If we want
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
37 * to restrict the type, type can contain a type to return */
1922
70f05f7d4d11 Default options comments, ignore localoptions.h
Begley Brothers Inc <begleybrothers@gmail.com>
parents: 1912
diff changeset
38 int readhostkey(const char * filename, sign_key * hostkey,
841
d4ce5269a439 Fix specifying a keysize for key generation, fix key name arguments
Matt Johnston <matt@ucc.asn.au>
parents: 713
diff changeset
39 enum signkey_type *type) {
47
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
40
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
41 int ret = DROPBEAR_FAILURE;
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
42 buffer *buf;
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
43
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
44 buf = buf_new(MAX_PRIVKEY_SIZE);
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
45
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
46 if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) {
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
47 goto out;
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
48 }
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
49 buf_setpos(buf, 0);
687
167fdc091c05 Improve RNG seeding.
Matt Johnston <matt@ucc.asn.au>
parents: 682
diff changeset
50
167fdc091c05 Improve RNG seeding.
Matt Johnston <matt@ucc.asn.au>
parents: 682
diff changeset
51 addrandom(buf_getptr(buf, buf->len), buf->len);
167fdc091c05 Improve RNG seeding.
Matt Johnston <matt@ucc.asn.au>
parents: 682
diff changeset
52
47
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
53 if (buf_get_priv_key(buf, hostkey, type) == DROPBEAR_FAILURE) {
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
54 goto out;
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
55 }
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
56
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
57 ret = DROPBEAR_SUCCESS;
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
58 out:
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
59
1912
8b4274d34fe8 Use buf_burn_free() instead of two calls
Matt Johnston <matt@ucc.asn.au>
parents: 1834
diff changeset
60 buf_burn_free(buf);
47
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
61 return ret;
4b53a43f0082 - client pubkey auth works
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
62 }
682
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
63
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 948
diff changeset
64 #if DROPBEAR_USER_ALGO_LIST
682
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
65 void
1687
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
66 parse_ciphers_macs() {
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
67 int printed_help = 0;
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
68 if (opts.cipher_list) {
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
69 if (strcmp(opts.cipher_list, "help") == 0) {
682
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
70 char *ciphers = algolist_string(sshciphers);
1687
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
71 dropbear_log(LOG_INFO, "Available ciphers: %s", ciphers);
682
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
72 m_free(ciphers);
1687
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
73 printed_help = 1;
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
74 } else {
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
75 if (check_user_algos(opts.cipher_list, sshciphers, "cipher") == 0) {
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
76 dropbear_exit("No valid ciphers specified for '-c'");
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
77 }
682
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
78 }
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
79 }
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
80
1687
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
81 if (opts.mac_list) {
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
82 if (strcmp(opts.mac_list, "help") == 0) {
682
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
83 char *macs = algolist_string(sshhashes);
1687
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
84 dropbear_log(LOG_INFO, "Available MACs: %s", macs);
682
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
85 m_free(macs);
1687
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
86 printed_help = 1;
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
87 } else {
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
88 if (check_user_algos(opts.mac_list, sshhashes, "MAC") == 0) {
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
89 dropbear_exit("No valid MACs specified for '-m'");
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
90 }
682
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
91 }
1687
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
92 }
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
93 if (printed_help) {
f8d8af12ac14 Make "dbclient -m help -c help" work
Matt Johnston <matt@ucc.asn.au>
parents: 1685
diff changeset
94 dropbear_exit(".");
682
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
95 }
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
96 }
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
97 #endif
4edea9f363d0 Add rough support for choosing ciphers/hashes with "-c" or "-m"
Matt Johnston <matt@ucc.asn.au>
parents: 47
diff changeset
98
948
f92eb625c48d - Don't use multichar constants since recent gcc complains
Matt Johnston <matt@ucc.asn.au>
parents: 946
diff changeset
99 void print_version() {
f92eb625c48d - Don't use multichar constants since recent gcc complains
Matt Johnston <matt@ucc.asn.au>
parents: 946
diff changeset
100 fprintf(stderr, "Dropbear v%s\n", DROPBEAR_VERSION);
946
17d874ae93a1 Add '-V' for version
Matt Johnston <matt@ucc.asn.au>
parents: 858
diff changeset
101 }
17d874ae93a1 Add '-V' for version
Matt Johnston <matt@ucc.asn.au>
parents: 858
diff changeset
102
1834
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
103 void parse_recv_window(const char* recv_window_arg) {
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
104 int ret;
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
105 unsigned int rw;
946
17d874ae93a1 Add '-V' for version
Matt Johnston <matt@ucc.asn.au>
parents: 858
diff changeset
106
1834
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
107 ret = m_str_to_uint(recv_window_arg, &rw);
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
108 if (ret == DROPBEAR_FAILURE || rw == 0 || rw > MAX_RECV_WINDOW) {
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
109 if (rw > MAX_RECV_WINDOW) {
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
110 opts.recv_window = MAX_RECV_WINDOW;
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
111 }
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
112 dropbear_log(LOG_WARNING, "Bad recv window '%s', using %d",
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
113 recv_window_arg, opts.recv_window);
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
114 } else {
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
115 opts.recv_window = rw;
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
116 }
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
117
94dc11094e26 Increase max window size to 10MB, fallback rather than
Matt Johnston <matt@codeconstruct.com.au>
parents: 1687
diff changeset
118 }
1936
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
119
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
120 /* Splits addr:port. Handles IPv6 [2001:0011::4]:port style format.
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
121 Returns first/second parts as malloced strings, second will
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
122 be NULL if no separator is found.
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
123 :port -> (NULL, "port")
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
124 port -> (port, NULL)
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
125 addr:port (addr, port)
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
126 addr: -> (addr, "")
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
127 Returns DROPBEAR_SUCCESS/DROPBEAR_FAILURE */
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
128 int split_address_port(const char* spec, char **first, char ** second) {
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
129 char *spec_copy = NULL, *addr = NULL, *colon = NULL;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
130 int ret = DROPBEAR_FAILURE;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
131
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
132 *first = NULL;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
133 *second = NULL;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
134 spec_copy = m_strdup(spec);
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
135 addr = spec_copy;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
136
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
137 if (*addr == '[') {
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
138 addr++;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
139 colon = strchr(addr, ']');
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
140 if (!colon) {
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
141 dropbear_log(LOG_WARNING, "Bad address '%s'", spec);
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
142 goto out;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
143 }
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
144 *colon = '\0';
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
145 colon++;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
146 if (*colon == '\0') {
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
147 /* No port part */
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
148 colon = NULL;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
149 } else if (*colon != ':') {
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
150 dropbear_log(LOG_WARNING, "Bad address '%s'", spec);
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
151 goto out;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
152 }
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
153 } else {
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
154 /* search for ':', that separates address and port */
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
155 colon = strrchr(addr, ':');
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
156 }
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
157
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
158 /* colon points to ':' now, or is NULL */
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
159 if (colon) {
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
160 /* Split the address/port */
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
161 *colon = '\0';
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
162 colon++;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
163 *second = m_strdup(colon);
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
164 }
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
165 if (strlen(addr)) {
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
166 *first = m_strdup(addr);
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
167 }
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
168 ret = DROPBEAR_SUCCESS;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
169
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
170 out:
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
171 m_free(spec_copy);
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
172 return ret;
4528afefe45d Fix IPv6 address parsing for dbclient -b
Matt Johnston <matt@ucc.asn.au>
parents: 1922
diff changeset
173 }