summaryrefslogtreecommitdiff
path: root/ftp/libfilezilla/files/patch-lib_impersonation.cpp
blob: 423e5bf90e44694a2acf0e14152084cf10bc5601 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
FreeBSD defines crypt_r() via <unistd.h>.

--- lib/impersonation.cpp.orig	2023-06-28 13:00:47 UTC
+++ lib/impersonation.cpp
@@ -8,8 +8,6 @@
 #include <tuple>
 
 #if FZ_UNIX
-#include <crypt.h>
-#include <shadow.h>
 #endif
 #include <grp.h>
 #include <limits.h>
@@ -98,43 +96,7 @@ std::optional<gid_t> get_group(native_string const& gn
 	return {};
 }
 
-#if FZ_UNIX
-struct shadow_holder {
-	shadow_holder() = default;
-	shadow_holder(shadow_holder const&) = delete;
-	shadow_holder(shadow_holder &&) = default;
-
-	shadow_holder& operator=(shadow_holder const&) = delete;
-	shadow_holder& operator=(shadow_holder &&) = default;
-
-	~shadow_holder() noexcept = default;
-
-	struct spwd* shadow_{};
-
-	struct spwd shadow_buffer_;
-	buffer buf_{};
-};
-
-shadow_holder get_shadow(native_string const& username)
-{
-	shadow_holder ret;
-
-	size_t s = 1024;
-	int res{};
-	do {
-		s *= 2;
-		ret.buf_.get(s);
-		res = getspnam_r(username.c_str(), &ret.shadow_buffer_, reinterpret_cast<char*>(ret.buf_.get(s)), s, &ret.shadow_);
-	} while (res == ERANGE);
-
-	if (res) {
-		ret.shadow_ = nullptr;
-	}
-
-	return ret;
 }
-#endif
-}
 
 class impersonation_token_impl final
 {
@@ -191,14 +153,7 @@ bool check_auth(native_string const& username, native_
 bool check_auth(native_string const& username, native_string const& password)
 {
 #if FZ_UNIX
-	auto shadow = get_shadow(username);
-	if (shadow.shadow_) {
-		struct crypt_data data{};
-		char* encrypted = crypt_r(password.c_str(), shadow.shadow_->sp_pwdp, &data);
-		if (encrypted && !strcmp(encrypted, shadow.shadow_->sp_pwdp)) {
-			return true;
-		}
-	}
+	return false; // FreeBSD does not have shadow.h support
 #elif FZ_MAC
 	bool ret{};