37 return "AUTHENTICATE";
66 if (b64usr !=
"" && b64usr[0] ==
'*') {
67 session.
setLastError(
"Authentication cancelled by user");
86 if (b64pwd !=
"" && b64pwd[0] ==
'*') {
87 session.
setLastError(
"Authentication cancelled by user");
93 session.
setEnv(
"AUTH",
"AUTH::Login");
112 if (c ==
'\n')
break;
117 if (b64.size() >= 1 && b64[0] ==
'*') {
118 session.
setLastError(
"Authentication cancelled by user");
123 string::size_type pos = 0;
125 if ((pos = plain.find(
'\0')) == string::npos) {
126 session.
setLastError(
"Authentication failed. In PLAIN mode, "
127 "there must be at least two null characters "
128 "in the input string, but none were found");
132 plain = plain.substr(pos + 1);
133 if ((pos = plain.find(
'\0')) == string::npos) {
134 session.
setLastError(
"Authentication failed. In PLAIN mode, "
135 "there must be at least two null characters "
136 "in the input string, but only one was found");
140 username = plain.substr(0, pos);
141 password = plain.substr(pos + 1);
142 session.
setEnv(
"AUTH",
"AUTH::Plain");
156 y2k.tm_hour = 0; y2k.tm_min = 0; y2k.tm_sec = 0;
157 y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;
160 timestamp = difftime(timer,mktime(&y2k));
163 challenge += to_string(session.
getPid());
165 challenge += to_string(timestamp);
167 challenge += session.
getEnv(
"TCPLOCALHOST");
178 if (c ==
'\n')
break;
184 string::size_type pos = 0;
186 if ((pos = response.find(
' ')) == string::npos) {
187 session.
setLastError(
"Authentication failed. In CRAM-MD5 mode, "
188 "there must be a white space in the "
189 "input string between username and digest");
193 username = response.substr(0, pos);
194 password = response.substr(pos + 1);
195 session.
setEnv(
"AUTH",
"AUTH::CramMD5");
213 if (authtype ==
"LOGIN") {
217 && !session.
hasEnv(
"ALLOW_NONSSL_PLAINTEXT_LOGINS")) {
218 session.
setLastError(
"Plain text password authentication is disallowd. "
219 "Please enable StartTLS or TLS in your mail client.");
222 if ((r =
Login(username, password)) !=
OK)
return r;
224 }
else if (authtype ==
"PLAIN") {
227 && !session.
hasEnv(
"ALLOW_NONSSL_PLAINTEXT_LOGINS")) {
228 session.
setLastError(
"Plain text password authentication is disallowd. "
229 "Please enable StartTLS or TLS in your mail client.");
232 if ((r =
Plain(username, password)) !=
OK)
return r;
234 }
else if (authtype ==
"CRAM-MD5" ) {
236 if ((r =
Cram(username, password, challenge)) !=
OK)
return r;
242 "Please try again with a different method. "
243 "There is built in support for \"PLAIN\" "
248 putenv(strdup((
"BINCIMAP_LOGIN=AUTHENTICATE+" + command.
getTag()).c_str()));
251 session.
setEnv(
"USER", username);
252 session.
setEnv(
"AUTH_USER", username);
258 switch (
authenticate(depot, username, password, challenge)) {
260 session.
setLastError(
"An internal error occurred when you attempted "
261 "to log in to the IMAP server. Please contact "
262 "your system administrator.");
265 session.
setLastError(
"Login failed. Either your user name "
266 "or your password was wrong. Please try again, "
267 "and if the problem persists, please contact "
268 "your system administrator.");
271 bincClient <<
"* BYE Timeout after " << IDLE_TIMEOUT
272 <<
" seconds of inactivity." << endl;
275 bincClient <<
"* BYE The server died unexpectedly. Please contact "
276 "your system administrator for more information." << endl;
299 session.
setLastError(
"Expected single SPACE after AUTHENTICATE");
305 session.
setLastError(
"Expected auth_type after AUTHENTICATE SPACE");
310 session.
setLastError(
"Expected CRLF after AUTHENTICATE SPACE auth_type");
Declaration of the common authentication mechanism.
Declaration of base64 Utilities.
ProcessResult Plain(std::string &username, std::string &password)
virtual ParseResult parse(Request &) const
ProcessResult Cram(std::string &username, std::string &password, std::string &challenge)
AuthenticateOperator(void)
ProcessResult process(Depot &, Request &)
ProcessResult Login(std::string &username, std::string &password)
~AuthenticateOperator(void)
const std::string getName(void) const
const std::string & getTag(void) const
void setName(const std::string &s_in)
bool getUidMode(void) const
void setAuthType(const std::string &s_in)
const std::string & getAuthType(void) const
void setEnv(const std::string &key, const std::string &value)
void setLastError(const std::string &error) const
struct Binc::Session::@3 command
static Session & getInstance(void)
std::string getEnv(const std::string &key)
bool hasEnv(const std::string &key) const
Declaration of miscellaneous convertion functions.
Declaration of the IODevice class.
Declaration of the IOFactory class.
int authenticate(Depot &, const std::string &username, const std::string &password, const std::string &challenge)
std::string toImapString(const std::string &s_in)
Operator::ParseResult expectSPACE(void)
std::string base64decode(const std::string &s_in)
std::string base64encode(const std::string &s_in)
Operator::ParseResult expectAtom(std::string &s_in)
void uppercase(std::string &input)
Operator::ParseResult expectCRLF(void)
Declaration of all operators.
Declaration of a recursive descent IMAP command parser.