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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
use bitflags::bitflags;
use std::fmt::Formatter;
use std::ops::Range;
use std::{
fmt::{self, Debug, Display},
net::{IpAddr, Ipv4Addr},
};
pub(crate) const DEFAULT_GREETING: &str = "Welcome to the libunftp FTP server";
pub(crate) const DEFAULT_IDLE_SESSION_TIMEOUT_SECS: u64 = 600;
pub(crate) const DEFAULT_PASSIVE_HOST: PassiveHost = PassiveHost::FromConnection;
pub(crate) const DEFAULT_PASSIVE_PORTS: Range<u16> = 49152..65535;
pub(crate) const DEFAULT_FTPS_REQUIRE: FtpsRequired = FtpsRequired::None;
pub(crate) const DEFAULT_FTPS_TRUST_STORE: &str = "./trusted.pem";
#[derive(Debug, PartialEq, Clone)]
pub enum PassiveHost {
FromConnection,
Ip(Ipv4Addr),
Dns(String),
}
impl Eq for PassiveHost {}
impl From<Ipv4Addr> for PassiveHost {
fn from(ip: Ipv4Addr) -> Self {
PassiveHost::Ip(ip)
}
}
impl From<[u8; 4]> for PassiveHost {
fn from(ip: [u8; 4]) -> Self {
PassiveHost::Ip(ip.into())
}
}
impl From<&str> for PassiveHost {
fn from(dns_or_ip: &str) -> Self {
match dns_or_ip.parse() {
Ok(IpAddr::V4(ip)) => PassiveHost::Ip(ip),
_ => PassiveHost::Dns(dns_or_ip.to_string()),
}
}
}
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum FtpsRequired {
All,
Accounts,
None,
}
impl Eq for FtpsRequired {}
impl From<bool> for FtpsRequired {
fn from(on: bool) -> Self {
match on {
true => FtpsRequired::All,
false => FtpsRequired::None,
}
}
}
impl Display for FtpsRequired {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(
f,
"{}",
match self {
FtpsRequired::All => "All users, including anonymous, requires FTPS",
FtpsRequired::Accounts => "All non-anonymous users requires FTPS",
FtpsRequired::None => "FTPS not enforced",
}
)
}
}
bitflags! {
pub struct TlsFlags: u32 {
const V1_2 = 0b00000001;
const V1_3 = 0b00000010;
const RESUMPTION_SESS_ID = 0b00001000;
const RESUMPTION_TICKETS = 0b00010000;
const LATEST_VERSIONS = Self::V1_2.bits | Self::V1_3.bits;
}
}
impl Default for TlsFlags {
fn default() -> TlsFlags {
TlsFlags::V1_2 | TlsFlags::RESUMPTION_SESS_ID | TlsFlags::RESUMPTION_TICKETS
}
}
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum FtpsClientAuth {
Off,
Request,
Require,
}
impl Eq for FtpsClientAuth {}
impl Default for FtpsClientAuth {
fn default() -> FtpsClientAuth {
FtpsClientAuth::Off
}
}
impl From<bool> for FtpsClientAuth {
fn from(on: bool) -> Self {
match on {
true => FtpsClientAuth::Require,
false => FtpsClientAuth::Off,
}
}
}
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum SiteMd5 {
All,
Accounts,
None,
}
impl Default for SiteMd5 {
fn default() -> SiteMd5 {
SiteMd5::Accounts
}
}