annotate dbutil.c @ 122:cb7ef2f63bf0 private-rez

propagate of f51a272341ee12268fe7028bc2f2bad66c603069 and ab35ee4292ea910d4871c3609d6100fe34300720 from branch 'matt.dbclient.rez' to 'matt.dbclient.work'
author Matt Johnston <matt@ucc.asn.au>
date Tue, 14 Sep 2004 13:09:29 +0000
parents e0acad552a92
children a0db9a23f6d4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /*
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 * Dropbear - a SSH2 server
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 * Copyright (c) 2002,2003 Matt Johnston
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 * All rights reserved.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 * of this software and associated documentation files (the "Software"), to deal
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 * in the Software without restriction, including without limitation the rights
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 * copies of the Software, and to permit persons to whom the Software is
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 * furnished to do so, subject to the following conditions:
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 * The above copyright notice and this permission notice shall be included in
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 * all copies or substantial portions of the Software.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
fe6bca95afa7 Makefile.in contains updated files required
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
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 * SOFTWARE.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 * strlcat() is copyright as follows:
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 * Copyright (c) 1998 Todd C. Miller <[email protected]>
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 * All rights reserved.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 * Redistribution and use in source and binary forms, with or without
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 * modification, are permitted provided that the following conditions
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 * are met:
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 * 1. Redistributions of source code must retain the above copyright
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 * notice, this list of conditions and the following disclaimer.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 * 2. Redistributions in binary form must reproduce the above copyright
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 * notice, this list of conditions and the following disclaimer in the
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 * documentation and/or other materials provided with the distribution.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 * 3. The name of the author may not be used to endorse or promote products
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 * derived from this software without specific prior written permission.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 #include "includes.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 #include "dbutil.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 #include "buffer.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 #include "session.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 #include "atomicio.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 #define MAX_FMT 100
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58
73
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
59 static void generic_dropbear_exit(int exitcode, const char* format,
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
60 va_list param);
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
61 static void generic_dropbear_log(int priority, const char* format,
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
62 va_list param);
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
63
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
64 void (*_dropbear_exit)(int exitcode, const char* format, va_list param)
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
65 = generic_dropbear_exit;
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
66 void (*_dropbear_log)(int priority, const char* format, va_list param)
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
67 = generic_dropbear_log;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68
94
c85c88500ea6 DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents: 73
diff changeset
69 #ifdef DEBUG_TRACE
c85c88500ea6 DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents: 73
diff changeset
70 int debug_trace = 0;
c85c88500ea6 DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents: 73
diff changeset
71 #endif
c85c88500ea6 DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents: 73
diff changeset
72
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 int usingsyslog = 0; /* set by runopts, but required externally to sessions */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 #ifndef DISABLE_SYSLOG
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 void startsyslog() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 openlog(PROGNAME, LOG_PID, LOG_AUTHPRIV);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 #endif /* DISABLE_SYSLOG */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 /* the "format" string must be <= 100 characters */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 void dropbear_close(const char* format, ...) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 va_list param;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 va_start(param, format);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 _dropbear_exit(EXIT_SUCCESS, format, param);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 va_end(param);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 void dropbear_exit(const char* format, ...) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 va_list param;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 va_start(param, format);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 _dropbear_exit(EXIT_FAILURE, format, param);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 va_end(param);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101
73
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
102 static void generic_dropbear_exit(int exitcode, const char* format,
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
103 va_list param) {
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
104
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
105 char fmtbuf[300];
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
106
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
107 snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s", format);
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
108
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
109 _dropbear_log(LOG_INFO, fmtbuf, param);
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
110
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
111 exit(exitcode);
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
112 }
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
113
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
114 static void generic_dropbear_log(int UNUSED(priority), const char* format,
73
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
115 va_list param) {
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
116
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
117 char printbuf[1024];
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
118
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
119 vsnprintf(printbuf, sizeof(printbuf), format, param);
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
120
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
121 fprintf(stderr, "%s\n", printbuf);
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
122
0bf5cebe622c Dropbearkey can now print out pubkey portions
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
123 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 /* this is what can be called to write arbitrary log messages */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 void dropbear_log(int priority, const char* format, ...) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128 va_list param;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 va_start(param, format);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 _dropbear_log(priority, format, param);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132 va_end(param);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 #ifdef DEBUG_TRACE
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 void dropbear_trace(const char* format, ...) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 va_list param;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140
94
c85c88500ea6 DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents: 73
diff changeset
141 if (!debug_trace) {
c85c88500ea6 DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents: 73
diff changeset
142 return;
c85c88500ea6 DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents: 73
diff changeset
143 }
c85c88500ea6 DEBUG_TRACE now only triggers with -v on the cmdline
Matt Johnston <matt@ucc.asn.au>
parents: 73
diff changeset
144
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 va_start(param, format);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146 fprintf(stderr, "TRACE: ");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147 vfprintf(stderr, format, param);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148 fprintf(stderr, "\n");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 va_end(param);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 #endif /* DEBUG_TRACE */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
153 /* Listen on address:port. Unless address is NULL, in which case listen on
63
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
154 * everything. If called with address == "", we'll listen on localhost/loopback.
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
155 * Returns the number of sockets bound on success, or -1 on failure. On
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
156 * failure, if errstring wasn't NULL, it'll be a newly malloced error
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
157 * string.*/
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
158 int dropbear_listen(const char* address, const char* port,
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
159 int *socks, unsigned int sockcount, char **errstring, int *maxfd) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
160
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 68
diff changeset
161 struct addrinfo hints, *res = NULL, *res0 = NULL;
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
162 int err;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
163 unsigned int nsock;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
164 struct linger linger;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
165 int val;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
166 int sock;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
167
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
168 TRACE(("enter dropbear_listen"));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
169
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
170 memset(&hints, 0, sizeof(hints));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
171 hints.ai_family = AF_UNSPEC; /* TODO: let them flag v4 only etc */
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
172 hints.ai_socktype = SOCK_STREAM;
63
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
173
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
174 if (address && address[0] == '\0') {
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
175 TRACE(("dropbear_listen: local loopback"));
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
176 address = NULL;
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
177 } else {
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
178 TRACE(("dropbear_listen: not local loopback"));
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
179 hints.ai_flags = AI_PASSIVE;
dcc43965928f - A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
180 }
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
181 err = getaddrinfo(address, port, &hints, &res0);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
182
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
183 if (err) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
184 if (errstring != NULL && *errstring == NULL) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
185 int len;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
186 len = 20 + strlen(gai_strerror(err));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
187 *errstring = (char*)m_malloc(len);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
188 snprintf(*errstring, len, "Error resolving: %s", gai_strerror(err));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
189 }
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
190 TRACE(("leave dropbear_listen: failed resolving"));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
191 return -1;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
192 }
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
193
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
194
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
195 nsock = 0;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
196 for (res = res0; res != NULL && nsock < sockcount;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
197 res = res->ai_next) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
198
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
199 /* Get a socket */
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
200 socks[nsock] = socket(res->ai_family, res->ai_socktype,
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
201 res->ai_protocol);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
202
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
203 sock = socks[nsock]; /* For clarity */
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
204
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
205 if (sock < 0) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
206 err = errno;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
207 TRACE(("socket() failed"));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
208 continue;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
209 }
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
210
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
211 /* Various useful socket options */
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
212 val = 1;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
213 /* set to reuse, quick timeout */
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
214 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*) &val, sizeof(val));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
215 linger.l_onoff = 1;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
216 linger.l_linger = 5;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
217 setsockopt(sock, SOL_SOCKET, SO_LINGER, (void*)&linger, sizeof(linger));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
218
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
219 /* disable nagle */
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
220 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&val, sizeof(val));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
221
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
222 if (bind(sock, res->ai_addr, res->ai_addrlen) < 0) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
223 err = errno;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
224 close(sock);
64
efb5e0b335cf TCP forwarding works.
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
225 TRACE(("bind(%s) failed", port));
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
226 continue;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
227 }
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
228
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
229 if (listen(sock, 20) < 0) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
230 err = errno;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
231 close(sock);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
232 TRACE(("listen() failed"));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
233 continue;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
234 }
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
235
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
236 *maxfd = MAX(*maxfd, sock);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
237
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
238 nsock++;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
239 }
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
240
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
241 if (nsock == 0) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
242 if (errstring != NULL && *errstring == NULL) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
243 int len;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
244 len = 20 + strlen(strerror(err));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
245 *errstring = (char*)m_malloc(len);
64
efb5e0b335cf TCP forwarding works.
Matt Johnston <matt@ucc.asn.au>
parents: 63
diff changeset
246 snprintf(*errstring, len, "Error listening: %s", strerror(err));
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
247 TRACE(("leave dropbear_listen: failure, %s", strerror(err)));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
248 return -1;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
249 }
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
250 }
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
251
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
252 TRACE(("leave dropbear_listen: success, %d socks bound", nsock));
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
253 return nsock;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
254 }
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
255
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
256 /* Connect via TCP to a host. Connection will try ipv4 or ipv6, will
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
257 * return immediately if nonblocking is set. On failure, if errstring
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
258 * wasn't null, it will be a newly malloced error message */
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
259
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
260 /* TODO: maxfd */
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
261 int connect_remote(const char* remotehost, const char* remoteport,
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
262 int nonblocking, char ** errstring) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
263
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
264 struct addrinfo *res0 = NULL, *res = NULL, hints;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
265 int sock;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
266 int err;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
267
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
268 TRACE(("enter connect_remote"));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
269
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
270 if (errstring != NULL) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
271 *errstring = NULL;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
272 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
273
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
274 memset(&hints, 0, sizeof(hints));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
275 hints.ai_socktype = SOCK_STREAM;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
276 hints.ai_family = PF_UNSPEC;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
277
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
278 err = getaddrinfo(remotehost, remoteport, &hints, &res0);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
279 if (err) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
280 if (errstring != NULL && *errstring == NULL) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
281 int len;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
282 len = 20 + strlen(gai_strerror(err));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
283 *errstring = (char*)m_malloc(len);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
284 snprintf(*errstring, len, "Error resolving: %s", gai_strerror(err));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
285 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
286 TRACE(("Error resolving: %s", gai_strerror(err)));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
287 return -1;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
288 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
289
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
290 sock = -1;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
291 err = EADDRNOTAVAIL;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
292 for (res = res0; res; res = res->ai_next) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
293
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
294 sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
295 if (sock < 0) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
296 err = errno;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
297 continue;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
298 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
299
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
300 if (nonblocking) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
301 if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
302 close(sock);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
303 sock = -1;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
304 if (errstring != NULL && *errstring == NULL) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
305 *errstring = m_strdup("Failed non-blocking");
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
306 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
307 TRACE(("Failed non-blocking: %s", strerror(errno)));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
308 continue;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
309 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
310 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
311
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
312 if (connect(sock, res->ai_addr, res->ai_addrlen) < 0) {
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 68
diff changeset
313 if (errno == EINPROGRESS && nonblocking) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
314 TRACE(("Connect in progress"));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
315 break;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
316 } else {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
317 err = errno;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
318 close(sock);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
319 sock = -1;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
320 continue;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
321 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
322 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
323
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
324 break; /* Success */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
325 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
326
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 68
diff changeset
327 if (sock < 0 && !(errno == EINPROGRESS && nonblocking)) {
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
328 /* Failed */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
329 if (errstring != NULL && *errstring == NULL) {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
330 int len;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
331 len = 20 + strlen(strerror(err));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
332 *errstring = (char*)m_malloc(len);
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
333 snprintf(*errstring, len, "Error connecting: %s", strerror(err));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
334 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
335 TRACE(("Error connecting: %s", strerror(err)));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
336 } else {
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
337 /* Success */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
338 /* (err is used as a dummy var here) */
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
339 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void*)&err, sizeof(err));
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
340 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
341
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
342 freeaddrinfo(res0);
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
343 if (sock > 0 && errstring != NULL && *errstring != NULL) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
344 m_free(*errstring);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
345 }
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
346
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
347 TRACE(("leave connect_remote: sock %d\n", sock));
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
348 return sock;
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
349 }
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
350
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
351 /* Return a string representation of the socket address passed. The return
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
352 * value is allocated with malloc() */
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
353 unsigned char * getaddrstring(struct sockaddr_storage* addr, int withport) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
354
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
355 char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
356 char *retstring = NULL;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
357 int ret;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
358 unsigned int len;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
359
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
360 len = sizeof(struct sockaddr_storage);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
361
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
362 ret = getnameinfo((struct sockaddr*)addr, len, hbuf, sizeof(hbuf),
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
363 sbuf, sizeof(sbuf), NI_NUMERICSERV | NI_NUMERICHOST);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
364
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
365 if (ret != 0) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
366 /* This is a fairly bad failure - it'll fallback to IP if it
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
367 * just can't resolve */
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
368 dropbear_exit("failed lookup (%d, %d)", ret, errno);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
369 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
370
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
371 if (withport) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
372 len = strlen(hbuf) + 2 + strlen(sbuf);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
373 retstring = (char*)m_malloc(len);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
374 snprintf(retstring, len, "%s:%s", hbuf, sbuf);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
375 } else {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
376 retstring = m_strdup(hbuf);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
377 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
378
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
379 return retstring;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
380
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
381 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
382
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
383 /* Get the hostname corresponding to the address addr. On failure, the IP
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
384 * address is returned. The return value is allocated with strdup() */
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
385 char* getaddrhostname(struct sockaddr_storage * addr) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
386
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
387 char hbuf[NI_MAXHOST];
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
388 char sbuf[NI_MAXSERV];
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
389 int ret;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
390 unsigned int len;
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
391
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
392 len = sizeof(struct sockaddr_storage);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
393
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
394 ret = getnameinfo((struct sockaddr*)addr, len, hbuf, sizeof(hbuf),
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
395 sbuf, sizeof(sbuf), NI_NUMERICSERV);
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
396
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
397 if (ret != 0) {
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
398 /* On some systems (Darwin does it) we get EINTR from getnameinfo
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
399 * somehow. Eew. So we'll just return the IP, since that doesn't seem
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
400 * to exhibit that behaviour. */
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
401 return getaddrstring(addr, 0);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
402 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
403
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
404 return m_strdup(hbuf);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
405 }
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 51
diff changeset
406
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
407 #ifdef DEBUG_TRACE
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
408 void printhex(unsigned char* buf, int len) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
409
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
410 int i;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
411
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
412 for (i = 0; i < len; i++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
413 fprintf(stderr, "%02x", buf[i]);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
414 if (i % 16 == 15) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
415 fprintf(stderr, "\n");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
416 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
417 else if (i % 2 == 1) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
418 fprintf(stderr, " ");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
419 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
420 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
421 fprintf(stderr, "\n");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
422 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
423 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
424
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
425 /* Strip all control characters from text (a null-terminated string), except
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
426 * for '\n', '\r' and '\t'.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
427 * The result returned is a newly allocated string, this must be free()d after
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
428 * use */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
429 char * stripcontrol(const char * text) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
430
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
431 char * ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
432 int len, pos;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
433 int i;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
434
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
435 len = strlen(text);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
436 ret = m_malloc(len+1);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
437
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
438 pos = 0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
439 for (i = 0; i < len; i++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
440 if ((text[i] <= '~' && text[i] >= ' ') /* normal printable range */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
441 || text[i] == '\n' || text[i] == '\r' || text[i] == '\t') {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
442 ret[pos] = text[i];
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
443 pos++;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
444 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
445 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
446 ret[pos] = 0x0;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
447 return ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
448 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
449
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
450
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
451 /* reads the contents of filename into the buffer buf, from the current
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
452 * position, either to the end of the file, or the buffer being full.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
453 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
454 int buf_readfile(buffer* buf, const char* filename) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
455
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
456 int fd;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
457 int len;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
458 int maxlen;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
459
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
460 fd = open(filename, O_RDONLY);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
461
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
462 if (fd < 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
463 close(fd);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
464 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
465 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
466
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
467 do {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
468 maxlen = buf->size - buf->pos;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
469 len = read(fd, buf_getwriteptr(buf, maxlen),
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
470 maxlen);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
471 buf_incrwritepos(buf, len);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
472 } while (len < maxlen && len > 0);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
473
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
474 close(fd);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
475 return DROPBEAR_SUCCESS;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
476 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
477
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
478 /* get a line from the file into buffer in the style expected for an
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
479 * authkeys file.
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
480 * Will return DROPBEAR_SUCCESS if data is read, or DROPBEAR_FAILURE on EOF.*/
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
481 /* Only used for ~/.ssh/known_hosts and ~/.ssh/authorized_keys */
68
eee77ac31ccc cleaning up the pubkey defines
Matt Johnston <matt@ucc.asn.au>
parents: 64
diff changeset
482 #if defined(DROPBEAR_CLIENT) || defined(ENABLE_SVR_PUBKEY_AUTH)
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
483 int buf_getline(buffer * line, FILE * authfile) {
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
484
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
485 int c = EOF;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
486
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
487 TRACE(("enter buf_getline"));
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
488
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
489 buf_setpos(line, 0);
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
490 buf_setlen(line, 0);
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
491
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
492 while (line->pos < line->size) {
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
493
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
494 c = fgetc(authfile); /*getc() is weird with some uClibc systems*/
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
495 if (c == EOF || c == '\n' || c == '\r') {
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
496 goto out;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
497 }
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
498
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
499 buf_putbyte(line, (unsigned char)c);
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
500 }
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
501
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
502 TRACE(("leave getauthline: line too long"));
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
503 /* We return success, but the line length will be zeroed - ie we just
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
504 * ignore that line */
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
505 buf_setlen(line, 0);
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
506
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
507 out:
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
508
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
509
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
510 /* if we didn't read anything before EOF or error, exit */
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
511 if (c == EOF && line->pos == 0) {
117
e0acad552a92 Read the last line of a file without a finishing '\n' correctly
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
512 TRACE(("leave buf_getline: failure"));
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
513 return DROPBEAR_FAILURE;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
514 } else {
117
e0acad552a92 Read the last line of a file without a finishing '\n' correctly
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
515 TRACE(("leave buf_getline: success"));
e0acad552a92 Read the last line of a file without a finishing '\n' correctly
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
516 buf_setpos(line, 0);
51
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
517 return DROPBEAR_SUCCESS;
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
518 }
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
519
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
520 }
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
521 #endif
095d689fed16 - Hostkey checking is mostly there, just aren't appending yet.
Matt Johnston <matt@ucc.asn.au>
parents: 45
diff changeset
522
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
523 /* loop until the socket is closed (in case of EINTR) or
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
524 * we get and error.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
525 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
526 int m_close(int fd) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
527
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
528 int val;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
529 do {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
530 val = close(fd);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
531 } while (val < 0 && errno == EINTR);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
532
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
533 if (val == 0 || errno == EBADF) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
534 return DROPBEAR_SUCCESS;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
535 } else {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
536 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
537 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
538 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
539
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
540 void * m_malloc(size_t size) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
541
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
542 void* ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
543
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
544 if (size == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
545 dropbear_exit("m_malloc failed");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
546 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
547 ret = malloc(size);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
548 if (ret == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
549 dropbear_exit("m_malloc failed");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
550 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
551 return ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
552
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
553 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
554
11
f76c9389e9e0 Mostly done with the listener changeover
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
555 void * m_strdup(const char * str) {
f76c9389e9e0 Mostly done with the listener changeover
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
556 char* ret;
f76c9389e9e0 Mostly done with the listener changeover
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
557
f76c9389e9e0 Mostly done with the listener changeover
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
558 ret = strdup(str);
f76c9389e9e0 Mostly done with the listener changeover
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
559 if (ret == NULL) {
f76c9389e9e0 Mostly done with the listener changeover
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
560 dropbear_exit("m_strdup failed");
f76c9389e9e0 Mostly done with the listener changeover
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
561 }
f76c9389e9e0 Mostly done with the listener changeover
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
562 return ret;
f76c9389e9e0 Mostly done with the listener changeover
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
563 }
f76c9389e9e0 Mostly done with the listener changeover
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
564
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
565 void __m_free(void* ptr) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
566 if (ptr != NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
567 free(ptr);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
568 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
569 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
570
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
571 void * m_realloc(void* ptr, size_t size) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
572
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
573 void *ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
574
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
575 if (size == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
576 dropbear_exit("m_realloc failed");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
577 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
578 ret = realloc(ptr, size);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
579 if (ret == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
580 dropbear_exit("m_realloc failed");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
581 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
582 return ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
583 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
584
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
585 /* Clear the data, based on the method in David Wheeler's
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
586 * "Secure Programming for Linux and Unix HOWTO" */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
587 void m_burn(void *data, unsigned int len) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
588 volatile char *p = data;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
589
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
590 if (data == NULL)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
591 return;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
592 while (len--) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
593 *p++ = 0x66;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
594 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
595 }
26
0969767bca0d snapshot of stuff
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
596
109
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
597
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
598 void setnonblocking(int fd) {
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
599
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
600 TRACE(("setnonblocking: %d", fd));
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
601
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
602 if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
603 dropbear_exit("Couldn't set nonblocking");
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
604 }
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
605 TRACE(("leave setnonblocking"));
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
606 }