diff --git a/crypto/openssh/readconf.c b/crypto/openssh/readconf.c index e87cc4d9081e..0e271f76ef00 100644 --- a/crypto/openssh/readconf.c +++ b/crypto/openssh/readconf.c @@ -18,6 +18,7 @@ __RCSID("$FreeBSD$"); #include #include #include +#include #include @@ -245,7 +246,19 @@ add_local_forward(Options *options, const Forward *newfwd) Forward *fwd; #ifndef NO_IPPORT_RESERVED_CONCEPT extern uid_t original_real_uid; - if (newfwd->listen_port < IPPORT_RESERVED && original_real_uid != 0) + int ipport_reserved; +#ifdef __FreeBSD__ + size_t len_ipport_reserved = sizeof(ipport_reserved); + + if (sysctlbyname("net.inet.ip.portrange.reservedhigh", + &ipport_reserved, &len_ipport_reserved, NULL, 0) != 0) + ipport_reserved = IPPORT_RESERVED; + else + ipport_reserved++; +#else + ipport_reserved = IPPORT_RESERVED; +#endif + if (newfwd->listen_port < ipport_reserved && original_real_uid != 0) fatal("Privileged ports can only be forwarded by root."); #endif if (options->num_local_forwards >= SSH_MAX_FORWARDS_PER_DIRECTION)