Path: blob/main/ftp/libfilezilla/files/patch-lib_impersonation.cpp
18157 views
FreeBSD defines crypt_r() via <unistd.h>.12--- lib/impersonation.cpp.orig 2023-06-28 13:00:47 UTC3+++ lib/impersonation.cpp4@@ -8,8 +8,6 @@5#include <tuple>67#if FZ_UNIX8-#include <crypt.h>9-#include <shadow.h>10#endif11#include <grp.h>12#include <limits.h>13@@ -98,43 +96,7 @@ std::optional<gid_t> get_group(native_string const& gn14return {};15}1617-#if FZ_UNIX18-struct shadow_holder {19- shadow_holder() = default;20- shadow_holder(shadow_holder const&) = delete;21- shadow_holder(shadow_holder &&) = default;22-23- shadow_holder& operator=(shadow_holder const&) = delete;24- shadow_holder& operator=(shadow_holder &&) = default;25-26- ~shadow_holder() noexcept = default;27-28- struct spwd* shadow_{};29-30- struct spwd shadow_buffer_;31- buffer buf_{};32-};33-34-shadow_holder get_shadow(native_string const& username)35-{36- shadow_holder ret;37-38- size_t s = 1024;39- int res{};40- do {41- s *= 2;42- ret.buf_.get(s);43- res = getspnam_r(username.c_str(), &ret.shadow_buffer_, reinterpret_cast<char*>(ret.buf_.get(s)), s, &ret.shadow_);44- } while (res == ERANGE);45-46- if (res) {47- ret.shadow_ = nullptr;48- }49-50- return ret;51}52-#endif53-}5455class impersonation_token_impl final56{57@@ -191,14 +153,7 @@ bool check_auth(native_string const& username, native_58bool check_auth(native_string const& username, native_string const& password)59{60#if FZ_UNIX61- auto shadow = get_shadow(username);62- if (shadow.shadow_) {63- struct crypt_data data{};64- char* encrypted = crypt_r(password.c_str(), shadow.shadow_->sp_pwdp, &data);65- if (encrypted && !strcmp(encrypted, shadow.shadow_->sp_pwdp)) {66- return true;67- }68- }69+ return false; // FreeBSD does not have shadow.h support70#elif FZ_MAC71bool ret{};72737475