annotate svr-x11fwd.c @ 1763:c05b76c541c9

Added signature for changeset 5879c5829e85
author Matt Johnston <matt@ucc.asn.au>
date Thu, 29 Oct 2020 21:40:34 +0800
parents 79eef94ccea9
children a7cc3332d8ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /*
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 * Dropbear - a SSH2 server
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 *
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 * Copyright (c) 2002,2003 Matt Johnston
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 * All rights reserved.
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 *
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 * of this software and associated documentation files (the "Software"), to deal
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 * in the Software without restriction, including without limitation the rights
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 * copies of the Software, and to permit persons to whom the Software is
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 * furnished to do so, subject to the following conditions:
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 *
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 * The above copyright notice and this permission notice shall be included in
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 * all copies or substantial portions of the Software.
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 *
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
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
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 * SOFTWARE. */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 #include "includes.h"
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1259
diff changeset
27 #if DROPBEAR_X11FWD
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 #include "x11fwd.h"
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 #include "session.h"
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 #include "ssh.h"
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 #include "dbutil.h"
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 #include "chansession.h"
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 #include "channel.h"
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 #include "packet.h"
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 #include "buffer.h"
475
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
36 #include "auth.h"
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 #define X11BASEPORT 6000
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 #define X11BINDBASE 6010
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40
1460
58a74cb829b8 Pointer parameter could be declared as pointing to const (callback)
Francois Perrad <francois.perrad@gadz.org>
parents: 1459
diff changeset
41 static void x11accept(const struct Listener* listener, int sock);
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 static int bindport(int fd);
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1295
diff changeset
43 static int send_msg_channel_open_x11(int fd, const struct sockaddr_in* addr);
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44
1229
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
45 /* Check untrusted xauth strings for metacharacters */
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
46 /* Returns DROPBEAR_SUCCESS/DROPBEAR_FAILURE */
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
47 static int
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
48 xauth_valid_string(const char *s)
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
49 {
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
50 size_t i;
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
51
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
52 for (i = 0; s[i] != '\0'; i++) {
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
53 if (!isalnum(s[i]) &&
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
54 s[i] != '.' && s[i] != ':' && s[i] != '/' &&
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
55 s[i] != '-' && s[i] != '_') {
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
56 return DROPBEAR_FAILURE;
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
57 }
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
58 }
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
59 return DROPBEAR_SUCCESS;
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
60 }
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
61
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
62
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 /* called as a request for a session channel, sets up listening X11 */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 /* returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 int x11req(struct ChanSess * chansess) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66
1229
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
67 int fd = -1;
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68
475
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
69 if (!svr_pubkey_allows_x11fwd()) {
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
70 return DROPBEAR_FAILURE;
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
71 }
52a644e7b8e1 * Patch from Frédéric Moulins adding options to authorized_keys.
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
72
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 /* we already have an x11 connection */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 if (chansess->x11listener != NULL) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 return DROPBEAR_FAILURE;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
78 chansess->x11singleconn = buf_getbool(ses.payload);
1122
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1095
diff changeset
79 chansess->x11authprot = buf_getstring(ses.payload, NULL);
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1095
diff changeset
80 chansess->x11authcookie = buf_getstring(ses.payload, NULL);
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 chansess->x11screennum = buf_getint(ses.payload);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82
1229
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
83 if (xauth_valid_string(chansess->x11authprot) == DROPBEAR_FAILURE ||
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
84 xauth_valid_string(chansess->x11authcookie) == DROPBEAR_FAILURE) {
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
85 dropbear_log(LOG_WARNING, "Bad xauth request");
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
86 goto fail;
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
87 }
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 /* create listening socket */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 fd = socket(PF_INET, SOCK_STREAM, 0);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 if (fd < 0) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 goto fail;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 /* allocate port and bind */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 chansess->x11port = bindport(fd);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 if (chansess->x11port < 0) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 goto fail;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 /* listen */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 if (listen(fd, 20) < 0) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 goto fail;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 /* set non-blocking */
109
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 95
diff changeset
106 setnonblocking(fd);
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 /* listener code will handle the socket now.
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 * No cleanup handler needed, since listener_remove only happens
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 * from our cleanup anyway */
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
111 chansess->x11listener = new_listener( &fd, 1, 0, chansess, x11accept, NULL);
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112 if (chansess->x11listener == NULL) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 goto fail;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 return DROPBEAR_SUCCESS;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 fail:
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 /* cleanup */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 m_free(chansess->x11authprot);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 m_free(chansess->x11authcookie);
1259
3a383aaeb487 m_close() rather than close()
Matt Johnston <matt@ucc.asn.au>
parents: 1247
diff changeset
122 m_close(fd);
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 return DROPBEAR_FAILURE;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 /* accepts a new X11 socket */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128 /* returns DROPBEAR_FAILURE or DROPBEAR_SUCCESS */
1460
58a74cb829b8 Pointer parameter could be declared as pointing to const (callback)
Francois Perrad <francois.perrad@gadz.org>
parents: 1459
diff changeset
129 static void x11accept(const struct Listener* listener, int sock) {
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 int fd;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132 struct sockaddr_in addr;
1095
877256d1b3fb Expect len to be a type of socklen_t [-Werror=pointer-sign]
Gaël PORTAY <gael.portay@gmail.com>
parents: 1094
diff changeset
133 socklen_t len;
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 int ret;
13
db2c8e6fb284 Fixed stupid agentfwd error (using the listening FD, not the accepted on. gah)
Matt Johnston <matt@ucc.asn.au>
parents: 12
diff changeset
135 struct ChanSess * chansess = (struct ChanSess *)(listener->typedata);
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 len = sizeof(addr);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138
62
20563735e8b5 just checkpointing
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
139 fd = accept(sock, (struct sockaddr*)&addr, &len);
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140 if (fd < 0) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 return;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 /* if single-connection we close it up */
13
db2c8e6fb284 Fixed stupid agentfwd error (using the listening FD, not the accepted on. gah)
Matt Johnston <matt@ucc.asn.au>
parents: 12
diff changeset
145 if (chansess->x11singleconn) {
db2c8e6fb284 Fixed stupid agentfwd error (using the listening FD, not the accepted on. gah)
Matt Johnston <matt@ucc.asn.au>
parents: 12
diff changeset
146 x11cleanup(chansess);
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 ret = send_msg_channel_open_x11(fd, &addr);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 if (ret == DROPBEAR_FAILURE) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 close(fd);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 /* This is called after switching to the user, and sets up the xauth
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 * and environment variables. */
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1295
diff changeset
157 void x11setauth(const struct ChanSess *chansess) {
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 char display[20]; /* space for "localhost:12345.123" */
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
160 FILE * authprog = NULL;
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 int val;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 if (chansess->x11listener == NULL) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164 return;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 /* create the DISPLAY string */
1237
888e3d17e962 Fix print format specifier
Chocobo1 <Chocobo1@users.noreply.github.com>
parents: 1122
diff changeset
168 val = snprintf(display, sizeof(display), "localhost:%d.%u",
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169 chansess->x11port - X11BASEPORT, chansess->x11screennum);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
170 if (val < 0 || val >= (int)sizeof(display)) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171 /* string was truncated */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
172 return;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 addnewvar("DISPLAY", display);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177 /* create the xauth string */
1237
888e3d17e962 Fix print format specifier
Chocobo1 <Chocobo1@users.noreply.github.com>
parents: 1122
diff changeset
178 val = snprintf(display, sizeof(display), "unix:%d.%u",
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
179 chansess->x11port - X11BASEPORT, chansess->x11screennum);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
180 if (val < 0 || val >= (int)sizeof(display)) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 /* string was truncated */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182 return;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
184
1229
a3e8389e01ff Validate xauth input
Matt Johnston <matt@ucc.asn.au>
parents: 1122
diff changeset
185 /* code is strongly based on OpenSSH's */
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186 authprog = popen(XAUTH_COMMAND, "w");
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187 if (authprog) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
188 fprintf(authprog, "add %s %s %s\n",
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
189 display, chansess->x11authprot, chansess->x11authcookie);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190 pclose(authprog);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191 } else {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192 fprintf(stderr, "Failed to run %s\n", XAUTH_COMMAND);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195
13
db2c8e6fb284 Fixed stupid agentfwd error (using the listening FD, not the accepted on. gah)
Matt Johnston <matt@ucc.asn.au>
parents: 12
diff changeset
196 void x11cleanup(struct ChanSess *chansess) {
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198 m_free(chansess->x11authprot);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
199 m_free(chansess->x11authcookie);
95
b855bf63766c Don't try to remove non-eixtant listeners
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
200
1038
d3925ed45a85 Fix for old compilers, variable declarations at beginning of functions
Thorsten Horstmann <thorsten.horstmann@web.de>
parents: 941
diff changeset
201 TRACE(("chansess %p", (void*)chansess))
95
b855bf63766c Don't try to remove non-eixtant listeners
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
202 if (chansess->x11listener != NULL) {
b855bf63766c Don't try to remove non-eixtant listeners
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
203 remove_listener(chansess->x11listener);
b855bf63766c Don't try to remove non-eixtant listeners
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
204 chansess->x11listener = NULL;
b855bf63766c Don't try to remove non-eixtant listeners
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
205 }
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
206 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
207
941
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 723
diff changeset
208 static int x11_inithandler(struct Channel *channel) {
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 723
diff changeset
209 channel->prio = DROPBEAR_CHANNEL_PRIO_INTERACTIVE;
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 723
diff changeset
210 return 0;
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 723
diff changeset
211 }
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 723
diff changeset
212
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
213 static const struct ChanType chan_x11 = {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
214 0, /* sepfds */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
215 "x11",
941
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 723
diff changeset
216 x11_inithandler, /* inithandler */
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
217 NULL, /* checkclose */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
218 NULL, /* reqhandler */
1625
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
219 NULL, /* closehandler */
79eef94ccea9 Split ChanType closehandler() and cleanup() so that dbclient doesn't
Matt Johnston <matt@ucc.asn.au>
parents: 1460
diff changeset
220 NULL /* cleanup */
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
221 };
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
222
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
223
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1295
diff changeset
224 static int send_msg_channel_open_x11(int fd, const struct sockaddr_in* addr) {
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
225
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
226 char* ipstring = NULL;
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
227
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
228 if (send_msg_channel_open_init(fd, &chan_x11) == DROPBEAR_SUCCESS) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
229 ipstring = inet_ntoa(addr->sin_addr);
1122
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1095
diff changeset
230 buf_putstring(ses.writepayload, ipstring, strlen(ipstring));
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
231 buf_putint(ses.writepayload, addr->sin_port);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
232
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
233 encrypt_packet();
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
234 return DROPBEAR_SUCCESS;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
235 } else {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
236 return DROPBEAR_FAILURE;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
237 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
238
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
239 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
240
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
241 /* returns the port bound to, or -1 on failure.
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
242 * Will attempt to bind to a port X11BINDBASE (6010 usually) or upwards */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
243 static int bindport(int fd) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
244
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
245 struct sockaddr_in addr;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
246 uint16_t port;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
247
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
248 memset((void*)&addr, 0x0, sizeof(addr));
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249 addr.sin_family = AF_INET;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
251
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
252 /* if we can't find one in 2000 ports free, something's wrong */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
253 for (port = X11BINDBASE; port < X11BINDBASE + 2000; port++) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
254 addr.sin_port = htons(port);
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
255 if (bind(fd, (struct sockaddr*)&addr,
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256 sizeof(struct sockaddr_in)) == 0) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
257 /* success */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
258 return port;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
259 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
260 if (errno == EADDRINUSE) {
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
261 /* try the next port */
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
262 continue;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
263 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
264 /* otherwise it was an error we don't know about */
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 475
diff changeset
265 dropbear_log(LOG_DEBUG, "Failed to bind x11 socket");
10
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
266 break;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
267 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
268 return -1;
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
269 }
0f7d69d31b9d - renaming x11fwd.c to svr-x11fwd.c, to testing monotone
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
270 #endif /* DROPBEAR_X11FWD */