Mercurial > dropbear
annotate cli-runopts.c @ 123:a0db9a23f6d4
calloc memory rather than mallocing it - can't hurt too much, and is
probably a bit safer
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 14 Sep 2004 13:18:16 +0000 |
parents | 68b84c20ca1e |
children | 6b306ad5f5b5 |
rev | line source |
---|---|
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 * Dropbear - a SSH2 server |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 * Copyright (c) 2002,2003 Matt Johnston |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * All rights reserved. |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * Permission is hereby granted, free of charge, to any person obtaining a copy |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 * of this software and associated documentation files (the "Software"), to deal |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 * in the Software without restriction, including without limitation the rights |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 * copies of the Software, and to permit persons to whom the Software is |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 * furnished to do so, subject to the following conditions: |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 * |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 * The above copyright notice and this permission notice shall be included in |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 * all copies or substantial portions of the Software. |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 * |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
0883c0906870
tty raw mode support works mostly
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 |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 * SOFTWARE. */ |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 #include "includes.h" |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 #include "runopts.h" |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 #include "signkey.h" |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 #include "buffer.h" |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 #include "dbutil.h" |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 #include "algo.h" |
64 | 31 #include "tcpfwd.h" |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 cli_runopts cli_opts; /* GLOBAL */ |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 |
47 | 35 static void printhelp(); |
36 static void parsehostname(char* userhostarg); | |
68
eee77ac31ccc
cleaning up the pubkey defines
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
37 #ifdef ENABLE_CLI_PUBKEY_AUTH |
47 | 38 static void loadidentityfile(const char* filename); |
39 #endif | |
64 | 40 #ifdef ENABLE_CLI_ANYTCPFWD |
41 static void addforward(char* str, struct TCPFwdList** fwdlist); | |
42 #endif | |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 |
47 | 44 static void printhelp() { |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 fprintf(stderr, "Dropbear client v%s\n" |
66
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
47 "Usage: %s [options] [user@]host\n" |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
48 "Options are:\n" |
47 | 49 "-p <remoteport>\n" |
56
6f091656c100
newlines which weren't there
Matt Johnston <matt@ucc.asn.au>
parents:
47
diff
changeset
|
50 "-t Allocate a pty\n" |
6f091656c100
newlines which weren't there
Matt Johnston <matt@ucc.asn.au>
parents:
47
diff
changeset
|
51 "-T Don't allocate a pty\n" |
68
eee77ac31ccc
cleaning up the pubkey defines
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
52 #ifdef ENABLE_CLI_PUBKEY_AUTH |
56
6f091656c100
newlines which weren't there
Matt Johnston <matt@ucc.asn.au>
parents:
47
diff
changeset
|
53 "-i <identityfile> (multiple allowed)\n" |
47 | 54 #endif |
64 | 55 #ifdef ENABLE_CLI_LOCALTCPFWD |
62 | 56 "-L <listenport:remotehsot:reportport> Local port forwarding\n" |
57 #endif | |
64 | 58 #ifdef ENABLE_CLI_REMOTETCPFWD |
62 | 59 "-R <listenport:remotehost:remoteport> Remote port forwarding\n" |
60 #endif | |
66
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
61 "-l <username>\n" |
94
c85c88500ea6
DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents:
68
diff
changeset
|
62 #ifdef DEBUG_TRACE |
c85c88500ea6
DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents:
68
diff
changeset
|
63 "-v verbose\n" |
c85c88500ea6
DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents:
68
diff
changeset
|
64 #endif |
47 | 65 ,DROPBEAR_VERSION, cli_opts.progname); |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
66 } |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 void cli_getopts(int argc, char ** argv) { |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
69 |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
70 unsigned int i, j; |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
71 char ** next = 0; |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
72 unsigned int cmdlen; |
68
eee77ac31ccc
cleaning up the pubkey defines
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
73 #ifdef ENABLE_CLI_PUBKEY_AUTH |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
74 int nextiskey = 0; /* A flag if the next argument is a keyfile */ |
47 | 75 #endif |
64 | 76 #ifdef ENABLE_CLI_LOCALTCPFWD |
62 | 77 int nextislocal = 0; |
78 #endif | |
64 | 79 #ifdef ENABLE_CLI_REMOTETCPFWD |
62 | 80 int nextisremote = 0; |
81 #endif | |
66
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
82 char* dummy = NULL; /* Not used for anything real */ |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
83 |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
84 /* see printhelp() for options */ |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
85 cli_opts.progname = argv[0]; |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 cli_opts.remotehost = NULL; |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
87 cli_opts.remoteport = NULL; |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
88 cli_opts.username = NULL; |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
89 cli_opts.cmd = NULL; |
47 | 90 cli_opts.wantpty = 9; /* 9 means "it hasn't been touched", gets set later */ |
68
eee77ac31ccc
cleaning up the pubkey defines
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
91 #ifdef ENABLE_CLI_PUBKEY_AUTH |
47 | 92 cli_opts.pubkeys = NULL; |
93 #endif | |
64 | 94 #ifdef ENABLE_CLI_LOCALTCPFWD |
95 cli_opts.localfwds = NULL; | |
62 | 96 #endif |
64 | 97 #ifdef ENABLE_CLI_REMOTETCPFWD |
98 cli_opts.remotefwds = NULL; | |
62 | 99 #endif |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
100 opts.nolocaltcp = 0; |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 opts.noremotetcp = 0; |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 /* not yet |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
103 opts.ipv4 = 1; |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
104 opts.ipv6 = 1; |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
105 */ |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 |
47 | 107 /* Iterate all the arguments */ |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
108 for (i = 1; i < (unsigned int)argc; i++) { |
68
eee77ac31ccc
cleaning up the pubkey defines
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
109 #ifdef ENABLE_CLI_PUBKEY_AUTH |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
110 if (nextiskey) { |
47 | 111 /* Load a hostkey since the previous argument was "-i" */ |
112 loadidentityfile(argv[i]); | |
113 nextiskey = 0; | |
114 continue; | |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
115 } |
47 | 116 #endif |
64 | 117 #ifdef ENABLE_CLI_REMOTETCPFWD |
118 if (nextisremote) { | |
119 TRACE(("nextisremote true")); | |
120 addforward(argv[i], &cli_opts.remotefwds); | |
121 nextisremote = 0; | |
122 continue; | |
123 } | |
124 #endif | |
125 #ifdef ENABLE_CLI_LOCALTCPFWD | |
126 if (nextislocal) { | |
127 TRACE(("nextislocal true")); | |
128 addforward(argv[i], &cli_opts.localfwds); | |
129 nextislocal = 0; | |
130 continue; | |
131 } | |
132 #endif | |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 if (next) { |
47 | 134 /* The previous flag set a value to assign */ |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
135 *next = argv[i]; |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
136 if (*next == NULL) { |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
137 dropbear_exit("Invalid null argument"); |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
138 } |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
139 next = NULL; |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 continue; |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
141 } |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
142 |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
143 if (argv[i][0] == '-') { |
47 | 144 /* A flag *waves* */ |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
145 |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
146 switch (argv[i][1]) { |
47 | 147 case 'p': /* remoteport */ |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
148 next = &cli_opts.remoteport; |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
149 break; |
68
eee77ac31ccc
cleaning up the pubkey defines
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
150 #ifdef ENABLE_CLI_PUBKEY_AUTH |
47 | 151 case 'i': /* an identityfile */ |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
152 nextiskey = 1; |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
153 break; |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
154 #endif |
47 | 155 case 't': /* we want a pty */ |
156 cli_opts.wantpty = 1; | |
157 break; | |
158 case 'T': /* don't want a pty */ | |
159 cli_opts.wantpty = 0; | |
160 break; | |
64 | 161 #ifdef ENABLE_CLI_LOCALTCPFWD |
162 case 'L': | |
163 nextislocal = 1; | |
164 break; | |
165 #endif | |
166 #ifdef ENABLE_CLI_REMOTETCPFWD | |
167 case 'R': | |
168 nextisremote = 1; | |
169 break; | |
170 #endif | |
66
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
171 case 'l': |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
172 next = &cli_opts.username; |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
173 break; |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
174 case 'h': |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
175 printhelp(); |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
176 exit(EXIT_SUCCESS); |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
177 break; |
94
c85c88500ea6
DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents:
68
diff
changeset
|
178 #ifdef DEBUG_TRACE |
c85c88500ea6
DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents:
68
diff
changeset
|
179 case 'v': |
c85c88500ea6
DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents:
68
diff
changeset
|
180 debug_trace = 1; |
c85c88500ea6
DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents:
68
diff
changeset
|
181 break; |
c85c88500ea6
DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents:
68
diff
changeset
|
182 #endif |
66
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
183 case 'F': |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
184 case 'e': |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
185 case 'c': |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
186 case 'm': |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
187 case 'D': |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
188 #ifndef ENABLE_CLI_REMOTETCPFWD |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
189 case 'R': |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
190 #endif |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
191 #ifndef ENABLE_CLI_LOCALTCPFWD |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
192 case 'L': |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
193 #endif |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
194 case 'o': |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
195 case 'b': |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
196 next = &dummy; |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
197 default: |
66
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
198 fprintf(stderr, |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
199 "WARNING: Ignoring unknown argument '%s'\n", argv[i]); |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
200 break; |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
201 } /* Switch */ |
105 | 202 |
203 /* Now we handle args where they might be "-luser" (no spaces)*/ | |
204 if (next && strlen(argv[i]) > 2) { | |
205 *next = &argv[i][2]; | |
206 next = NULL; | |
207 } | |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
208 |
47 | 209 continue; /* next argument */ |
210 | |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
211 } else { |
64 | 212 TRACE(("non-flag arg: '%s'", argv[i])); |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
213 |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
214 /* Either the hostname or commands */ |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
215 |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
216 if (cli_opts.remotehost == NULL) { |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
217 |
47 | 218 parsehostname(argv[i]); |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
219 |
47 | 220 } else { |
46
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
221 |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
222 /* this is part of the commands to send - after this we |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
223 * don't parse any more options, and flags are sent as the |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
224 * command */ |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
225 cmdlen = 0; |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
226 for (j = i; j < (unsigned int)argc; j++) { |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
227 cmdlen += strlen(argv[j]) + 1; /* +1 for spaces */ |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
228 } |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
229 /* Allocate the space */ |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
230 cli_opts.cmd = (char*)m_malloc(cmdlen); |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
231 cli_opts.cmd[0] = '\0'; |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
232 |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
233 /* Append all the bits */ |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
234 for (j = i; j < (unsigned int)argc; j++) { |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
235 strlcat(cli_opts.cmd, argv[j], cmdlen); |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
236 strlcat(cli_opts.cmd, " ", cmdlen); |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
237 } |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
238 /* It'll be null-terminated here */ |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
239 |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
240 /* We've eaten all the options and flags */ |
3bea78e1b175
Filled out a bit, with commandline support etc
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
241 break; |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
242 } |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
243 } |
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
244 } |
47 | 245 |
246 if (cli_opts.remotehost == NULL) { | |
66
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
247 printhelp(); |
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
248 exit(EXIT_FAILURE); |
47 | 249 } |
250 | |
251 if (cli_opts.remoteport == NULL) { | |
252 cli_opts.remoteport = "22"; | |
253 } | |
254 | |
255 /* If not explicitly specified with -t or -T, we don't want a pty if | |
256 * there's a command, but we do otherwise */ | |
257 if (cli_opts.wantpty == 9) { | |
258 if (cli_opts.cmd == NULL) { | |
259 cli_opts.wantpty = 1; | |
260 } else { | |
261 cli_opts.wantpty = 0; | |
262 } | |
263 } | |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
264 } |
47 | 265 |
68
eee77ac31ccc
cleaning up the pubkey defines
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
266 #ifdef ENABLE_CLI_PUBKEY_AUTH |
47 | 267 static void loadidentityfile(const char* filename) { |
268 | |
269 struct PubkeyList * nextkey; | |
270 sign_key *key; | |
271 int keytype; | |
272 | |
273 key = new_sign_key(); | |
274 keytype = DROPBEAR_SIGNKEY_ANY; | |
275 if ( readhostkey(filename, key, &keytype) != DROPBEAR_SUCCESS ) { | |
276 | |
277 fprintf(stderr, "Failed loading keyfile '%s'\n", filename); | |
278 sign_key_free(key); | |
279 | |
280 } else { | |
281 | |
282 nextkey = (struct PubkeyList*)m_malloc(sizeof(struct PubkeyList)); | |
283 nextkey->key = key; | |
284 nextkey->next = cli_opts.pubkeys; | |
285 nextkey->type = keytype; | |
286 cli_opts.pubkeys = nextkey; | |
287 } | |
288 } | |
289 #endif | |
290 | |
291 | |
292 /* Parses a [user@]hostname argument. userhostarg is the argv[i] corresponding | |
293 * - note that it will be modified */ | |
64 | 294 static void parsehostname(char* orighostarg) { |
47 | 295 |
296 uid_t uid; | |
297 struct passwd *pw = NULL; | |
64 | 298 char *userhostarg = NULL; |
299 | |
300 /* We probably don't want to be editing argvs */ | |
301 userhostarg = m_strdup(orighostarg); | |
47 | 302 |
303 cli_opts.remotehost = strchr(userhostarg, '@'); | |
304 if (cli_opts.remotehost == NULL) { | |
305 /* no username portion, the cli-auth.c code can figure the | |
306 * local user's name */ | |
307 cli_opts.remotehost = userhostarg; | |
308 } else { | |
309 cli_opts.remotehost[0] = '\0'; /* Split the user/host */ | |
310 cli_opts.remotehost++; | |
311 cli_opts.username = userhostarg; | |
312 } | |
313 | |
314 if (cli_opts.username == NULL) { | |
315 uid = getuid(); | |
316 | |
317 pw = getpwuid(uid); | |
318 if (pw == NULL || pw->pw_name == NULL) { | |
319 dropbear_exit("Unknown own user"); | |
320 } | |
321 | |
322 cli_opts.username = m_strdup(pw->pw_name); | |
323 } | |
324 | |
325 if (cli_opts.remotehost[0] == '\0') { | |
326 dropbear_exit("Bad hostname"); | |
327 } | |
328 } | |
64 | 329 |
330 #ifdef ENABLE_CLI_ANYTCPFWD | |
331 /* Turn a "listenport:remoteaddr:remoteport" string into into a forwarding | |
332 * set, and add it to the forwarding list */ | |
333 static void addforward(char* origstr, struct TCPFwdList** fwdlist) { | |
334 | |
335 char * listenport = NULL; | |
336 char * connectport = NULL; | |
337 char * connectaddr = NULL; | |
338 struct TCPFwdList* newfwd = NULL; | |
339 char * str = NULL; | |
340 | |
341 TRACE(("enter addforward")); | |
342 | |
343 /* We probably don't want to be editing argvs */ | |
344 str = m_strdup(origstr); | |
345 | |
346 listenport = str; | |
347 | |
348 connectaddr = strchr(str, ':'); | |
349 if (connectaddr == NULL) { | |
350 TRACE(("connectaddr == NULL")); | |
351 goto fail; | |
352 } | |
353 | |
354 connectaddr[0] = '\0'; | |
355 connectaddr++; | |
356 | |
357 connectport = strchr(connectaddr, ':'); | |
358 if (connectport == NULL) { | |
359 TRACE(("connectport == NULL")); | |
360 goto fail; | |
361 } | |
362 | |
363 connectport[0] = '\0'; | |
364 connectport++; | |
365 | |
366 newfwd = (struct TCPFwdList*)m_malloc(sizeof(struct TCPFwdList)); | |
367 | |
368 /* Now we check the ports - note that the port ints are unsigned, | |
369 * the check later only checks for >= MAX_PORT */ | |
370 newfwd->listenport = strtol(listenport, NULL, 10); | |
371 if (errno != 0) { | |
372 TRACE(("bad listenport strtol")); | |
373 goto fail; | |
374 } | |
375 | |
376 newfwd->connectport = strtol(connectport, NULL, 10); | |
377 if (errno != 0) { | |
378 TRACE(("bad connectport strtol")); | |
379 goto fail; | |
380 } | |
381 | |
382 newfwd->connectaddr = connectaddr; | |
383 | |
384 if (newfwd->listenport > 65535) { | |
385 TRACE(("listenport > 65535")); | |
386 goto badport; | |
387 } | |
388 | |
389 if (newfwd->connectport > 65535) { | |
390 TRACE(("connectport > 65535")); | |
391 goto badport; | |
392 } | |
393 | |
394 newfwd->next = *fwdlist; | |
395 *fwdlist = newfwd; | |
396 | |
397 TRACE(("leave addforward: done")); | |
398 return; | |
399 | |
400 fail: | |
401 dropbear_exit("Bad TCP forward '%s'", origstr); | |
402 | |
403 badport: | |
404 dropbear_exit("Bad TCP port in '%s'", origstr); | |
405 } | |
406 #endif |