mirror of
https://github.com/nmap/nmap.git
synced 2025-12-20 14:39:02 +00:00
Perform the proxy connexion hook in connect_internal().
This allows to generically handle all kinds of connexions instead of manually providing a handler for tcp connect, ssl connect... The drawback is that would it makes it harder to implement support of SSL proxies. Not sure whether there's a need though, looks like regular clients don't handle them at least.
This commit is contained in:
@@ -155,12 +155,38 @@ int nsock_setup_udp(nsock_pool nsp, nsock_iod ms_iod, int af) {
|
|||||||
void nsock_connect_internal(mspool *ms, msevent *nse, int type, int proto, struct sockaddr_storage *ss, size_t sslen,
|
void nsock_connect_internal(mspool *ms, msevent *nse, int type, int proto, struct sockaddr_storage *ss, size_t sslen,
|
||||||
unsigned short port) {
|
unsigned short port) {
|
||||||
|
|
||||||
struct sockaddr_in *sin = (struct sockaddr_in *)ss;
|
struct sockaddr_in *sin;
|
||||||
#if HAVE_IPV6
|
#if HAVE_IPV6
|
||||||
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)ss;
|
struct sockaddr_in6 *sin6;
|
||||||
#endif
|
#endif
|
||||||
msiod *iod = nse->iod;
|
msiod *iod = nse->iod;
|
||||||
|
|
||||||
|
if (iod->px_ctx && (nse->handler != nsock_proxy_ev_dispatch)) {
|
||||||
|
struct proxy_node *current;
|
||||||
|
|
||||||
|
current = proxy_ctx_node_current(iod->px_ctx);
|
||||||
|
assert(current != NULL);
|
||||||
|
|
||||||
|
memcpy(&iod->px_ctx->target_ss, ss, sslen);
|
||||||
|
iod->px_ctx->target_sslen = sslen;
|
||||||
|
iod->px_ctx->target_port = port;
|
||||||
|
|
||||||
|
ss = ¤t->ss;
|
||||||
|
sslen = current->sslen;
|
||||||
|
port = current->port;
|
||||||
|
|
||||||
|
iod->px_ctx->target_handler = nse->handler;
|
||||||
|
nse->handler = nsock_proxy_ev_dispatch;
|
||||||
|
|
||||||
|
iod->px_ctx->target_ev_type = nse->type;
|
||||||
|
nse->type = NSE_TYPE_CONNECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
sin = (struct sockaddr_in *)ss;
|
||||||
|
#if HAVE_IPV6
|
||||||
|
sin6 = (struct sockaddr_in6 *)ss;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Now it is time to actually attempt the connection */
|
/* Now it is time to actually attempt the connection */
|
||||||
if (nsock_make_socket(ms, iod, ss->ss_family, type, proto) == -1) {
|
if (nsock_make_socket(ms, iod, ss->ss_family, type, proto) == -1) {
|
||||||
nse->event_done = 1;
|
nse->event_done = 1;
|
||||||
@@ -264,33 +290,6 @@ nsock_event_id nsock_connect_unixsock_datagram(nsock_pool nsp, nsock_iod nsiod,
|
|||||||
nsock_event_id nsock_connect_tcp(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler handler, int timeout_msecs,
|
nsock_event_id nsock_connect_tcp(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler handler, int timeout_msecs,
|
||||||
void *userdata, struct sockaddr *saddr, size_t sslen, unsigned short port) {
|
void *userdata, struct sockaddr *saddr, size_t sslen, unsigned short port) {
|
||||||
msiod *nsi = (msiod *)ms_iod;
|
msiod *nsi = (msiod *)ms_iod;
|
||||||
|
|
||||||
if (nsi->px_ctx) {
|
|
||||||
struct proxy_node *current;
|
|
||||||
|
|
||||||
current = proxy_ctx_node_current(nsi->px_ctx);
|
|
||||||
assert(current != NULL);
|
|
||||||
|
|
||||||
memcpy(&nsi->px_ctx->target_ss, saddr, sslen);
|
|
||||||
nsi->px_ctx->target_sslen = sslen;
|
|
||||||
nsi->px_ctx->target_port = port;
|
|
||||||
nsi->px_ctx->target_handler = handler;
|
|
||||||
|
|
||||||
saddr = (struct sockaddr *)¤t->ss;
|
|
||||||
sslen = current->sslen;
|
|
||||||
port = current->port;
|
|
||||||
handler = nsock_proxy_ev_dispatch;
|
|
||||||
|
|
||||||
return nsock_connect_tcp_direct(nsp, ms_iod, handler, timeout_msecs, userdata, saddr, sslen, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
return nsock_connect_tcp_direct(nsp, ms_iod, handler, timeout_msecs, userdata, saddr, sslen, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsock_event_id nsock_connect_tcp_direct(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler handler,
|
|
||||||
int timeout_msecs, void *userdata, struct sockaddr *saddr,
|
|
||||||
size_t sslen, unsigned short port) {
|
|
||||||
msiod *nsi = (msiod *)ms_iod;
|
|
||||||
mspool *ms = (mspool *)nsp;
|
mspool *ms = (mspool *)nsp;
|
||||||
msevent *nse;
|
msevent *nse;
|
||||||
struct sockaddr_storage *ss = (struct sockaddr_storage *)saddr;
|
struct sockaddr_storage *ss = (struct sockaddr_storage *)saddr;
|
||||||
|
|||||||
@@ -425,7 +425,7 @@ void forward_event(nsock_pool nspool, nsock_event nsevent, void *udata) {
|
|||||||
cached_type = nse->type;
|
cached_type = nse->type;
|
||||||
cached_status = nse->status;
|
cached_status = nse->status;
|
||||||
|
|
||||||
nse->type = NSE_TYPE_CONNECT;
|
nse->type = nse->iod->px_ctx->target_ev_type;
|
||||||
|
|
||||||
if (nse->status != NSE_STATUS_SUCCESS)
|
if (nse->status != NSE_STATUS_SUCCESS)
|
||||||
nse->status = NSE_STATUS_PROXYERROR;
|
nse->status = NSE_STATUS_PROXYERROR;
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ struct proxy_chain_context {
|
|||||||
|
|
||||||
/* Those fields are used to store information about the final target
|
/* Those fields are used to store information about the final target
|
||||||
* to reach. */
|
* to reach. */
|
||||||
|
enum nse_type target_ev_type;
|
||||||
struct sockaddr_storage target_ss;
|
struct sockaddr_storage target_ss;
|
||||||
size_t target_sslen;
|
size_t target_sslen;
|
||||||
unsigned short target_port;
|
unsigned short target_port;
|
||||||
|
|||||||
Reference in New Issue
Block a user