Bincimap 2.0.16
Easy Imapping
Loading...
Searching...
No Matches
operator-login.cc
Go to the documentation of this file.
1
7#include <unistd.h>
8#include <sys/types.h>
9#include <signal.h>
10#include <errno.h>
11
12#include <string>
13#include <iostream>
14
15#include "authenticate.h"
16#include "depot.h"
17#include "iodevice.h"
18#include "iofactory.h"
19#include "globals.h"
20#include "operators.h"
21#include "recursivedescent.h"
22#include "session.h"
23
24using namespace ::std;
25using namespace Binc;
26
27//----------------------------------------------------------------------
29{
30}
31
32//----------------------------------------------------------------------
34{
35}
36
37//----------------------------------------------------------------------
38const string LoginOperator::getName(void) const
39{
40 return "LOGIN";
41}
42
43//----------------------------------------------------------------------
45{
47}
48
49//------------------------------------------------------------------------
51 Request &command)
52{
53 Session &session = Session::getInstance();
54
55 if (!session.command.ssl
56 && !session.hasEnv("ALLOW_NONSSL_PLAINTEXT_LOGINS")) {
57 session.setLastError("Plain text password authentication is disallowd. "
58 "Please enable StartTLS or TLS in your mail client.");
59 return NO;
60 }
61
62 session.setEnv("BINCIMAP_LOGIN", "LOGIN+" + command.getTag());
63 string challenge;
64
65 switch (authenticate(depot, command.getUserID(), command.getPassword(), challenge)) {
66 case 1:
67 session.setLastError("An internal error occurred when you attempted "
68 "to log in to the IMAP server. Please contact "
69 "your system administrator.");
70 return NO;
71 case 2:
72 session.setLastError("Login failed. Either your user name "
73 "or your password was wrong. Please try again, "
74 "and if the problem persists, please contact "
75 "your system administrator.");
76 return NO;
77 case 3:
78 bincClient << "* BYE Timeout after " << IDLE_TIMEOUT
79 << " seconds of inactivity." << endl;
80 break;
81 case -1:
82 bincClient << "* BYE The server died unexpectedly. Please contact "
83 "your system administrator for more information." << endl;
84 break;
85 }
86
87 // go to logout
89
90 return NOTHING;
91}
92
93//----------------------------------------------------------------------
95{
96 Session &session = Session::getInstance();
97
98 if (c_in.getUidMode()) return REJECT;
99
101 if ((res = expectSPACE()) != ACCEPT) {
102 session.setLastError("Expected single SPACE after LOGIN");
103 return res;
104 }
105
106 string username;
107 if ((res = expectAstring(username)) != ACCEPT) {
108 session.setLastError("Expected username after LOGIN SPACE");
109 return res;
110 }
111
112 c_in.setUserID(username);
113 session.setEnv("USER", username);
114 session.setEnv("AUTH_USER", username);
115 session.setEnv("AUTH", "LOGIN::User");
116
117 if ((res = expectSPACE()) != ACCEPT) {
118 session.setLastError("Expected SPACE after LOGIN SPACE username");
119 return res;
120 }
121
122 string password;
123 if ((res = expectAstring(password)) != ACCEPT) {
124 session.setLastError("Expected password after LOGIN "
125 "SPACE username SPACE");
126 return res;
127 }
128
129 if ((res = expectCRLF()) != ACCEPT) {
130 session.setLastError("Expected CRLF after password");
131 return res;
132 }
133
134 c_in.setPassword(password);
135 c_in.setName("LOGIN");
136
137 return ACCEPT;
138}
Declaration of the common authentication mechanism.
virtual ParseResult parse(Request &) const
int getState(void) const
ProcessResult process(Depot &, Request &)
const std::string getName(void) const
const std::string & getTag(void) const
Definition: imapparser.cc:52
const std::string & getUserID(void) const
Definition: imapparser.cc:137
void setPassword(const std::string &s_in)
Definition: imapparser.cc:143
void setName(const std::string &s_in)
Definition: imapparser.cc:70
const std::string & getPassword(void) const
Definition: imapparser.cc:149
void setUserID(const std::string &s_in)
Definition: imapparser.cc:131
bool getUidMode(void) const
Definition: imapparser.cc:40
void setEnv(const std::string &key, const std::string &value)
Definition: session.cc:237
void setLastError(const std::string &error) const
Definition: session.cc:185
void setState(int n)
Definition: session.cc:46
@ NONAUTHENTICATED
Definition: session.h:36
bool ssl
Definition: session.h:30
struct Binc::Session::@3 command
static Session & getInstance(void)
Definition: session.cc:33
bool hasEnv(const std::string &key) const
Definition: session.cc:224
Global constants.
Declaration of the IODevice class.
Declaration of the IOFactory class.
#define bincClient
Definition: iofactory.h:31
Definition: bincimapd.cc:9
int authenticate(Depot &, const std::string &username, const std::string &password, const std::string &challenge)
Operator::ParseResult expectAstring(std::string &s_in)
Operator::ParseResult expectSPACE(void)
Operator::ParseResult expectCRLF(void)
Declaration of all operators.
Declaration of a recursive descent IMAP command parser.