Mercurial > dropbear
annotate cli-main.c @ 180:743fce568f49
Merge in Debian package changes from 0.45-3, grab the dbclient manpage
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 13 Mar 2005 16:22:36 +0000 |
parents | 0cfba3034be5 |
children | 740e782679be 1afa503e33f5 |
rev | line source |
---|---|
74
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
1 /* |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
2 * Dropbear - a SSH2 server |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
3 * SSH client implementation |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
4 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
5 * Copyright (c) 2002,2003 Matt Johnston |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
6 * Copyright (c) 2004 by Mihnea Stoenescu |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
7 * All rights reserved. |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
8 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
9 * Permission is hereby granted, free of charge, to any person obtaining a copy |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
10 * of this software and associated documentation files (the "Software"), to deal |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
11 * in the Software without restriction, including without limitation the rights |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
13 * copies of the Software, and to permit persons to whom the Software is |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
14 * furnished to do so, subject to the following conditions: |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
15 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
16 * The above copyright notice and this permission notice shall be included in |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
17 * all copies or substantial portions of the Software. |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
18 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
25 * SOFTWARE. */ |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
26 |
33 | 27 #include "includes.h" |
28 #include "dbutil.h" | |
29 #include "runopts.h" | |
30 #include "session.h" | |
26 | 31 |
33 | 32 static void cli_dropbear_exit(int exitcode, const char* format, va_list param); |
33 static void cli_dropbear_log(int priority, const char* format, va_list param); | |
34 | |
35 #if defined(DBMULTI_dbclient) || !defined(DROPBEAR_MULTI) | |
36 #if defined(DBMULTI_dbclient) && defined(DROPBEAR_MULTI) | |
37 int cli_main(int argc, char ** argv) { | |
38 #else | |
26 | 39 int main(int argc, char ** argv) { |
33 | 40 #endif |
26 | 41 |
42 int sock; | |
43 char* error = NULL; | |
44 char* hostandport; | |
45 int len; | |
46 | |
47 _dropbear_exit = cli_dropbear_exit; | |
48 _dropbear_log = cli_dropbear_log; | |
49 | |
50 cli_getopts(argc, argv); | |
51 | |
33 | 52 TRACE(("user='%s' host='%s' port='%s'", cli_opts.username, |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
109
diff
changeset
|
53 cli_opts.remotehost, cli_opts.remoteport)) |
33 | 54 |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
55 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { |
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
56 dropbear_exit("signal() error"); |
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
57 } |
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
58 |
26 | 59 sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport, |
60 0, &error); | |
61 | |
62 if (sock < 0) { | |
63 dropbear_exit("%s", error); | |
64 } | |
65 | |
66 /* Set up the host:port log */ | |
67 len = strlen(cli_opts.remotehost); | |
68 len += 10; /* 16 bit port and leeway*/ | |
69 hostandport = (char*)m_malloc(len); | |
33 | 70 snprintf(hostandport, len, "%s:%s", |
26 | 71 cli_opts.remotehost, cli_opts.remoteport); |
72 | |
73 cli_session(sock, hostandport); | |
74 | |
75 /* not reached */ | |
76 return -1; | |
77 } | |
33 | 78 #endif /* DBMULTI stuff */ |
79 | |
80 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) { | |
81 | |
82 char fmtbuf[300]; | |
83 | |
84 if (!sessinitdone) { | |
85 snprintf(fmtbuf, sizeof(fmtbuf), "exited: %s", | |
86 format); | |
87 } else { | |
88 snprintf(fmtbuf, sizeof(fmtbuf), | |
89 "connection to %s@%s:%s exited: %s", | |
90 cli_opts.username, cli_opts.remotehost, | |
91 cli_opts.remoteport, format); | |
92 } | |
93 | |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
94 /* Do the cleanup first, since then the terminal will be reset */ |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
95 cli_session_cleanup(); |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
96 common_session_cleanup(); |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
97 |
33 | 98 _dropbear_log(LOG_INFO, fmtbuf, param); |
99 | |
100 exit(exitcode); | |
101 } | |
102 | |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
74
diff
changeset
|
103 static void cli_dropbear_log(int UNUSED(priority), |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
74
diff
changeset
|
104 const char* format, va_list param) { |
33 | 105 |
106 char printbuf[1024]; | |
107 | |
108 vsnprintf(printbuf, sizeof(printbuf), format, param); | |
109 | |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
110 fprintf(stderr, "%s: %s\n", cli_opts.progname, printbuf); |
33 | 111 |
112 } |