Mercurial > dropbear
comparison svr-tcpfwd.c @ 63:dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
- still a checkpoint-ish commit
- sorted out listening on localhost only
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 11 Aug 2004 17:26:47 +0000 |
parents | 20563735e8b5 |
children | efb5e0b335cf |
comparison
equal
deleted
inserted
replaced
62:20563735e8b5 | 63:dcc43965928f |
---|---|
102 static int matchtcp(void* typedata1, void* typedata2) { | 102 static int matchtcp(void* typedata1, void* typedata2) { |
103 | 103 |
104 const struct TCPListener *info1 = (struct TCPListener*)typedata1; | 104 const struct TCPListener *info1 = (struct TCPListener*)typedata1; |
105 const struct TCPListener *info2 = (struct TCPListener*)typedata2; | 105 const struct TCPListener *info2 = (struct TCPListener*)typedata2; |
106 | 106 |
107 return (info1->port == info2->port) | 107 return (info1->sendport == info2->sendport) |
108 && (info1->chantype == info2->chantype) | 108 && (info1->chantype == info2->chantype) |
109 && (strcmp(info1->addr, info2->addr) == 0); | 109 && (strcmp(info1->sendaddr, info2->sendaddr) == 0); |
110 } | 110 } |
111 | 111 |
112 static int svr_cancelremotetcp() { | 112 static int svr_cancelremotetcp() { |
113 | 113 |
114 int ret = DROPBEAR_FAILURE; | 114 int ret = DROPBEAR_FAILURE; |
126 goto out; | 126 goto out; |
127 } | 127 } |
128 | 128 |
129 port = buf_getint(ses.payload); | 129 port = buf_getint(ses.payload); |
130 | 130 |
131 tcpinfo.addr = bindaddr; | 131 tcpinfo.sendaddr = bindaddr; |
132 tcpinfo.port = port; | 132 tcpinfo.sendport = port; |
133 listener = get_listener(CHANNEL_ID_TCPFORWARDED, &tcpinfo, matchtcp); | 133 listener = get_listener(CHANNEL_ID_TCPFORWARDED, &tcpinfo, matchtcp); |
134 if (listener) { | 134 if (listener) { |
135 remove_listener( listener ); | 135 remove_listener( listener ); |
136 ret = DROPBEAR_SUCCESS; | 136 ret = DROPBEAR_SUCCESS; |
137 } | 137 } |
150 struct TCPListener *tcpinfo = NULL; | 150 struct TCPListener *tcpinfo = NULL; |
151 unsigned int port; | 151 unsigned int port; |
152 | 152 |
153 TRACE(("enter remotetcpreq")); | 153 TRACE(("enter remotetcpreq")); |
154 | 154 |
155 /* NOTE: at this stage, we ignore bindaddr. see below and listen_tcpfwd */ | |
155 bindaddr = buf_getstring(ses.payload, &addrlen); | 156 bindaddr = buf_getstring(ses.payload, &addrlen); |
156 if (addrlen > MAX_IP_LEN) { | 157 if (addrlen > MAX_IP_LEN) { |
157 TRACE(("addr len too long: %d", addrlen)); | 158 TRACE(("addr len too long: %d", addrlen)); |
158 goto out; | 159 goto out; |
159 } | 160 } |
174 TRACE(("can't assign port < 1024 for non-root")); | 175 TRACE(("can't assign port < 1024 for non-root")); |
175 goto out; | 176 goto out; |
176 } | 177 } |
177 | 178 |
178 tcpinfo = (struct TCPListener*)m_malloc(sizeof(struct TCPListener)); | 179 tcpinfo = (struct TCPListener*)m_malloc(sizeof(struct TCPListener)); |
179 tcpinfo->addr = bindaddr; | 180 tcpinfo->sendaddr = bindaddr; |
180 tcpinfo->port = port; | 181 TRACE(("sendport = %d", port)); |
181 tcpinfo->localport = -1; | 182 tcpinfo->sendport = port; |
182 tcpinfo->chantype = &svr_chan_tcpremote; | 183 tcpinfo->chantype = &svr_chan_tcpremote; |
183 | 184 |
185 /* Note: bindaddr is actually ignored by listen_tcpfwd, since | |
186 * we only want to bind to localhost */ | |
184 ret = listen_tcpfwd(tcpinfo); | 187 ret = listen_tcpfwd(tcpinfo); |
185 | 188 |
186 out: | 189 out: |
187 if (ret == DROPBEAR_FAILURE) { | 190 if (ret == DROPBEAR_FAILURE) { |
188 /* we only free it if a listener wasn't created, since the listener | 191 /* we only free it if a listener wasn't created, since the listener |
189 * has to remember it if it's to be cancelled */ | 192 * has to remember it if it's to be cancelled */ |
190 m_free(tcpinfo->addr); | 193 m_free(tcpinfo->sendaddr); |
191 m_free(tcpinfo); | 194 m_free(tcpinfo); |
192 } | 195 } |
193 TRACE(("leave remotetcpreq")); | 196 TRACE(("leave remotetcpreq")); |
194 return ret; | 197 return ret; |
195 } | 198 } |