Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports
Path: blob/main/ftp/libfilezilla/files/patch-lib_impersonation.cpp
18157 views
1
FreeBSD defines crypt_r() via <unistd.h>.
2
3
--- lib/impersonation.cpp.orig 2023-06-28 13:00:47 UTC
4
+++ lib/impersonation.cpp
5
@@ -8,8 +8,6 @@
6
#include <tuple>
7
8
#if FZ_UNIX
9
-#include <crypt.h>
10
-#include <shadow.h>
11
#endif
12
#include <grp.h>
13
#include <limits.h>
14
@@ -98,43 +96,7 @@ std::optional<gid_t> get_group(native_string const& gn
15
return {};
16
}
17
18
-#if FZ_UNIX
19
-struct shadow_holder {
20
- shadow_holder() = default;
21
- shadow_holder(shadow_holder const&) = delete;
22
- shadow_holder(shadow_holder &&) = default;
23
-
24
- shadow_holder& operator=(shadow_holder const&) = delete;
25
- shadow_holder& operator=(shadow_holder &&) = default;
26
-
27
- ~shadow_holder() noexcept = default;
28
-
29
- struct spwd* shadow_{};
30
-
31
- struct spwd shadow_buffer_;
32
- buffer buf_{};
33
-};
34
-
35
-shadow_holder get_shadow(native_string const& username)
36
-{
37
- shadow_holder ret;
38
-
39
- size_t s = 1024;
40
- int res{};
41
- do {
42
- s *= 2;
43
- ret.buf_.get(s);
44
- res = getspnam_r(username.c_str(), &ret.shadow_buffer_, reinterpret_cast<char*>(ret.buf_.get(s)), s, &ret.shadow_);
45
- } while (res == ERANGE);
46
-
47
- if (res) {
48
- ret.shadow_ = nullptr;
49
- }
50
-
51
- return ret;
52
}
53
-#endif
54
-}
55
56
class impersonation_token_impl final
57
{
58
@@ -191,14 +153,7 @@ bool check_auth(native_string const& username, native_
59
bool check_auth(native_string const& username, native_string const& password)
60
{
61
#if FZ_UNIX
62
- auto shadow = get_shadow(username);
63
- if (shadow.shadow_) {
64
- struct crypt_data data{};
65
- char* encrypted = crypt_r(password.c_str(), shadow.shadow_->sp_pwdp, &data);
66
- if (encrypted && !strcmp(encrypted, shadow.shadow_->sp_pwdp)) {
67
- return true;
68
- }
69
- }
70
+ return false; // FreeBSD does not have shadow.h support
71
#elif FZ_MAC
72
bool ret{};
73
74
75