comparison cli-runopts.c @ 39:0883c0906870

tty raw mode support works mostly adding cli-{chansession,runopts}.c which were missing
author Matt Johnston <matt@ucc.asn.au>
date Fri, 30 Jul 2004 12:29:53 +0000
parents
children b4874d772210
comparison
equal deleted inserted replaced
38:5c6f9d27ea1c 39:0883c0906870
1 /*
2 * Dropbear - a SSH2 server
3 *
4 * Copyright (c) 2002,2003 Matt Johnston
5 * All rights reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE. */
24
25 #include "includes.h"
26 #include "runopts.h"
27 #include "signkey.h"
28 #include "buffer.h"
29 #include "dbutil.h"
30 #include "algo.h"
31
32 cli_runopts cli_opts; /* GLOBAL */
33
34 static void printhelp(const char * progname);
35
36 static void printhelp(const char * progname) {
37
38 fprintf(stderr, "Dropbear client v%s\n"
39 "Usage: %s [options] [email protected][:port]\n"
40 "Options are:\n"
41 "user Remote username\n"
42 "host Remote host\n"
43 "port Remote port\n"
44 ,DROPBEAR_VERSION, progname);
45 }
46
47 void cli_getopts(int argc, char ** argv) {
48
49 unsigned int i;
50 char ** next = 0;
51
52 uid_t uid;
53 struct passwd *pw;
54
55 char* userhostarg = NULL;
56
57 /* see printhelp() for options */
58 cli_opts.remotehost = NULL;
59 cli_opts.remoteport = NULL;
60 cli_opts.username = NULL;
61 cli_opts.cmd = NULL;
62 cli_opts.wantpty = 0;
63 opts.nolocaltcp = 0;
64 opts.noremotetcp = 0;
65 /* not yet
66 opts.ipv4 = 1;
67 opts.ipv6 = 1;
68 */
69
70 if (argc != 2) {
71 printhelp(argv[0]);
72 exit(EXIT_FAILURE);
73 }
74
75 /* We'll be editing it, should probably make a copy */
76 userhostarg = m_strdup(argv[1]);
77
78 cli_opts.remotehost = strchr(userhostarg, '@');
79 if (cli_opts.remotehost == NULL) {
80 /* no username portion, the cli-auth.c code can figure the local
81 * user's name */
82 cli_opts.remotehost = userhostarg;
83 } else {
84 cli_opts.remotehost[0] = '\0'; /* Split the user/host */
85 cli_opts.remotehost++;
86 cli_opts.username = userhostarg;
87 }
88
89 if (cli_opts.username == NULL) {
90 uid = getuid();
91
92 pw = getpwuid(uid);
93 if (pw == NULL || pw->pw_name == NULL) {
94 dropbear_exit("Couldn't find username for current user");
95 }
96
97 cli_opts.username = m_strdup(pw->pw_name);
98 }
99
100 if (cli_opts.remotehost[0] == '\0') {
101 dropbear_exit("Bad hostname argument");
102 }
103
104 cli_opts.remoteport = strchr(cli_opts.remotehost, ':');
105 if (cli_opts.remoteport == NULL) {
106 cli_opts.remoteport = "22";
107 } else {
108 cli_opts.remoteport[0] = '\0';
109 cli_opts.remoteport++;
110 }
111
112 #if 0
113 for (i = 1; i < (unsigned int)argc; i++) {
114 if (next) {
115 *next = argv[i];
116 if (*next == NULL) {
117 dropbear_exit("Invalid null argument");
118 }
119 next = 0x00;
120 continue;
121 }
122
123 if (argv[i][0] == '-') {
124 switch (argv[i][1]) {
125 case 'b':
126 next = &svr_opts.bannerfile;
127 break;
128 #ifdef DROPBEAR_DSS
129 case 'd':
130 next = &svr_opts.dsskeyfile;
131 break;
132 #endif
133 #ifdef DROPBEAR_RSA
134 case 'r':
135 next = &svr_opts.rsakeyfile;
136 break;
137 #endif
138 case 'F':
139 svr_opts.forkbg = 0;
140 break;
141 #ifndef DISABLE_SYSLOG
142 case 'E':
143 svr_opts.usingsyslog = 0;
144 break;
145 #endif
146 #ifndef DISABLE_LOCALTCPFWD
147 case 'j':
148 opts.nolocaltcp = 1;
149 break;
150 #endif
151 #ifndef DISABLE_REMOTETCPFWD
152 case 'k':
153 opts.noremotetcp = 1;
154 break;
155 #endif
156 case 'p':
157 if (portnum < DROPBEAR_MAX_PORTS) {
158 portstring[portnum] = NULL;
159 next = &portstring[portnum];
160 portnum++;
161 }
162 break;
163 #ifdef DO_MOTD
164 /* motd is displayed by default, -m turns it off */
165 case 'm':
166 svr_opts.domotd = 0;
167 break;
168 #endif
169 case 'w':
170 svr_opts.norootlogin = 1;
171 break;
172 #ifdef DROPBEAR_PASSWORD_AUTH
173 case 's':
174 svr_opts.noauthpass = 1;
175 break;
176 case 'g':
177 svr_opts.norootpass = 1;
178 break;
179 #endif
180 case 'h':
181 printhelp(argv[0]);
182 exit(EXIT_FAILURE);
183 break;
184 /*
185 case '4':
186 svr_opts.ipv4 = 0;
187 break;
188 case '6':
189 svr_opts.ipv6 = 0;
190 break;
191 */
192 default:
193 fprintf(stderr, "Unknown argument %s\n", argv[i]);
194 printhelp(argv[0]);
195 exit(EXIT_FAILURE);
196 break;
197 }
198 }
199 }
200 #endif
201
202 }