comparison cli-runopts.c @ 66:38c3146aa23d

Some more sanity-checking of args, and just warn and ignore OpenSSH args
author Matt Johnston <matt@ucc.asn.au>
date Thu, 12 Aug 2004 14:19:05 +0000
parents efb5e0b335cf
children eee77ac31ccc
comparison
equal deleted inserted replaced
65:02e4a7f614f8 66:38c3146aa23d
42 #endif 42 #endif
43 43
44 static void printhelp() { 44 static void printhelp() {
45 45
46 fprintf(stderr, "Dropbear client v%s\n" 46 fprintf(stderr, "Dropbear client v%s\n"
47 "Usage: %s [options] user@host\n" 47 "Usage: %s [options] [user@]host\n"
48 "Options are:\n" 48 "Options are:\n"
49 "-p <remoteport>\n" 49 "-p <remoteport>\n"
50 "-t Allocate a pty\n" 50 "-t Allocate a pty\n"
51 "-T Don't allocate a pty\n" 51 "-T Don't allocate a pty\n"
52 #ifdef DROPBEAR_PUBKEY_AUTH 52 #ifdef DROPBEAR_PUBKEY_AUTH
56 "-L <listenport:remotehsot:reportport> Local port forwarding\n" 56 "-L <listenport:remotehsot:reportport> Local port forwarding\n"
57 #endif 57 #endif
58 #ifdef ENABLE_CLI_REMOTETCPFWD 58 #ifdef ENABLE_CLI_REMOTETCPFWD
59 "-R <listenport:remotehost:remoteport> Remote port forwarding\n" 59 "-R <listenport:remotehost:remoteport> Remote port forwarding\n"
60 #endif 60 #endif
61 "-l <username>\n"
61 ,DROPBEAR_VERSION, cli_opts.progname); 62 ,DROPBEAR_VERSION, cli_opts.progname);
62 } 63 }
63 64
64 void cli_getopts(int argc, char ** argv) { 65 void cli_getopts(int argc, char ** argv) {
65 66
73 int nextislocal = 0; 74 int nextislocal = 0;
74 #endif 75 #endif
75 #ifdef ENABLE_CLI_REMOTETCPFWD 76 #ifdef ENABLE_CLI_REMOTETCPFWD
76 int nextisremote = 0; 77 int nextisremote = 0;
77 #endif 78 #endif
79 char* dummy = NULL; /* Not used for anything real */
78 80
79 /* see printhelp() for options */ 81 /* see printhelp() for options */
80 cli_opts.progname = argv[0]; 82 cli_opts.progname = argv[0];
81 cli_opts.remotehost = NULL; 83 cli_opts.remotehost = NULL;
82 cli_opts.remoteport = NULL; 84 cli_opts.remoteport = NULL;
136 } 138 }
137 139
138 if (argv[i][0] == '-') { 140 if (argv[i][0] == '-') {
139 /* A flag *waves* */ 141 /* A flag *waves* */
140 142
143 if (strlen(argv[i]) > 2) {
144 fprintf(stderr,
145 "WARNING: Ignoring unknown argument '%s'\n", argv[i]);
146 continue;
147 }
148
141 switch (argv[i][1]) { 149 switch (argv[i][1]) {
142 case 'p': /* remoteport */ 150 case 'p': /* remoteport */
143 next = &cli_opts.remoteport; 151 next = &cli_opts.remoteport;
144 break; 152 break;
145 #ifdef DROPBEAR_PUBKEY_AUTH 153 #ifdef DROPBEAR_PUBKEY_AUTH
161 #ifdef ENABLE_CLI_REMOTETCPFWD 169 #ifdef ENABLE_CLI_REMOTETCPFWD
162 case 'R': 170 case 'R':
163 nextisremote = 1; 171 nextisremote = 1;
164 break; 172 break;
165 #endif 173 #endif
174 case 'l':
175 next = &cli_opts.username;
176 break;
177 case 'h':
178 printhelp();
179 exit(EXIT_SUCCESS);
180 break;
181 case 'F':
182 case 'e':
183 case 'c':
184 case 'm':
185 case 'D':
186 #ifndef ENABLE_CLI_REMOTETCPFWD
187 case 'R':
188 #endif
189 #ifndef ENABLE_CLI_LOCALTCPFWD
190 case 'L':
191 #endif
192 case 'o':
193 case 'b':
194 next = &dummy;
166 default: 195 default:
167 fprintf(stderr, "Unknown argument '%s'\n", argv[i]); 196 fprintf(stderr,
168 printhelp(); 197 "WARNING: Ignoring unknown argument '%s'\n", argv[i]);
169 exit(EXIT_FAILURE);
170 break; 198 break;
171 } /* Switch */ 199 } /* Switch */
172 200
173 continue; /* next argument */ 201 continue; /* next argument */
174 202
206 } 234 }
207 } 235 }
208 } 236 }
209 237
210 if (cli_opts.remotehost == NULL) { 238 if (cli_opts.remotehost == NULL) {
211 dropbear_exit("Bad syntax"); 239 printhelp();
240 exit(EXIT_FAILURE);
212 } 241 }
213 242
214 if (cli_opts.remoteport == NULL) { 243 if (cli_opts.remoteport == NULL) {
215 cli_opts.remoteport = "22"; 244 cli_opts.remoteport = "22";
216 } 245 }