|
1 | 1 | /* |
2 | 2 | * ProFTPD - mod_proxy FTP data transfer routines |
3 | | - * Copyright (c) 2013-2024 TJ Saunders |
| 3 | + * Copyright (c) 2013-2025 TJ Saunders |
4 | 4 | * |
5 | 5 | * This program is free software; you can redistribute it and/or modify |
6 | 6 | * it under the terms of the GNU General Public License as published by |
@@ -550,25 +550,43 @@ const pr_netaddr_t *proxy_ftp_xfer_prepare_passive(int policy_id, cmd_rec *cmd, |
550 | 550 |
|
551 | 551 | remote_port = ntohs(pr_netaddr_get_port(remote_addr)); |
552 | 552 |
|
553 | | - if (!(proxy_opts & PROXY_OPT_ALLOW_FOREIGN_ADDRESS)) { |
554 | | - /* Make sure that the given address matches the address to which we |
555 | | - * originally connected. |
556 | | - */ |
| 553 | + /* See if the given address matches the address to which we originally |
| 554 | + * connected. |
| 555 | + */ |
| 556 | + if (pr_netaddr_cmp(remote_addr, |
| 557 | + proxy_sess->backend_ctrl_conn->remote_addr) != 0) { |
| 558 | + |
| 559 | + pr_trace_msg(trace_channel, 2, |
| 560 | + "backend passive transfer address %s does not match backend control " |
| 561 | + "connection address %s", pr_netaddr_get_ipstr(remote_addr), |
| 562 | + pr_netaddr_get_ipstr(proxy_sess->backend_ctrl_conn->remote_addr)); |
557 | 563 |
|
558 | | - if (pr_netaddr_cmp(remote_addr, |
559 | | - proxy_sess->backend_ctrl_conn->remote_addr) != 0) { |
| 564 | + if (proxy_opts & PROXY_OPT_IGNORE_FOREIGN_ADDRESS) { |
560 | 565 | (void) pr_log_writefile(proxy_logfd, MOD_PROXY_VERSION, |
561 | | - "Refused %s address %s (address mismatch with %s)", |
562 | | - (char *) pasv_cmd->argv[0], pr_netaddr_get_ipstr(remote_addr), |
| 566 | + "Ignoring %s address %s per IgnoreForeignAddress ProxyOption, using %s " |
| 567 | + "instead", (char *) pasv_cmd->argv[0], |
| 568 | + pr_netaddr_get_ipstr(remote_addr), |
563 | 569 | pr_netaddr_get_ipstr(proxy_sess->backend_ctrl_conn->remote_addr)); |
564 | | - xerrno = EPERM; |
565 | 570 |
|
566 | | - pr_response_add_err(error_code, "%s: %s", (char *) cmd->argv[0], |
567 | | - strerror(xerrno)); |
568 | | - pr_response_flush(&resp_err_list); |
| 571 | + remote_addr = pr_netaddr_dup(proxy_sess->dataxfer_pool, |
| 572 | + proxy_sess->backend_ctrl_conn->remote_addr); |
| 573 | + pr_netaddr_set_port2(remote_addr, remote_port); |
| 574 | + |
| 575 | + } else { |
| 576 | + if (!(proxy_opts & PROXY_OPT_ALLOW_FOREIGN_ADDRESS)) { |
| 577 | + (void) pr_log_writefile(proxy_logfd, MOD_PROXY_VERSION, |
| 578 | + "Refused %s address %s (address mismatch with %s)", |
| 579 | + (char *) pasv_cmd->argv[0], pr_netaddr_get_ipstr(remote_addr), |
| 580 | + pr_netaddr_get_ipstr(proxy_sess->backend_ctrl_conn->remote_addr)); |
| 581 | + xerrno = EPERM; |
569 | 582 |
|
570 | | - errno = xerrno; |
571 | | - return NULL; |
| 583 | + pr_response_add_err(error_code, "%s: %s", (char *) cmd->argv[0], |
| 584 | + strerror(xerrno)); |
| 585 | + pr_response_flush(&resp_err_list); |
| 586 | + |
| 587 | + errno = xerrno; |
| 588 | + return NULL; |
| 589 | + } |
572 | 590 | } |
573 | 591 | } |
574 | 592 |
|
|
0 commit comments