Bincimap 2.0.16
Easy Imapping
Loading...
Searching...
No Matches
operator-starttls.cc
Go to the documentation of this file.
1
7#include <string>
8#include <iostream>
9#include <unistd.h>
10#include <fcntl.h>
11
12#include "recursivedescent.h"
13#include "iodevice.h"
14#include "iofactory.h"
15#include "session.h"
16#include "depot.h"
17#include "operators.h"
18
19using namespace ::std;
20using namespace Binc;
21
22//----------------------------------------------------------------------
24{
25}
26
27//----------------------------------------------------------------------
29{
30}
31
32//----------------------------------------------------------------------
33const string StarttlsOperator::getName(void) const
34{
35 return "STARTTLS";
36}
37
38//----------------------------------------------------------------------
40{
44}
45
46//----------------------------------------------------------------------
48{
49 Session &session = Session::getInstance();
50
51 if (getenv("UCSPITLS")) {
52 string fdstr;
53 int fd;
54
55 fdstr = session.getEnv("SSLCTLFD");
56 fd = std::stoi(fdstr);
57 if (write(fd,"Y",1) < 1) return NOTHING;
58 bincClient.flush(); // flush all previous received data
59
60 fdstr = session.getEnv("SSLREADFD");
61 fd = std::stoi(fdstr);
62 if (fcntl(fd,F_GETFL,0) == -1) return NOTHING;
63 close (0);
64 if (fcntl(fd,F_DUPFD,0) == -1) return NOTHING;
65 close (fd);
66
67 fdstr = session.getEnv("SSLWRITEFD");
68 fd = std::stoi(fdstr);
69 if (fcntl(fd,F_GETFL,0) == -1) return NOTHING;
70 close (1);
71 if (fcntl(fd,F_DUPFD,1) == -1) return NOTHING;
72 close (fd);
73 }
74
75 return ACCEPT;
76}
77
78//------------------------------------------------------------------------
80 Request &command)
81{
82 Session &session = Session::getInstance();
83 if (session.command.ssl) {
84 session.setLastError("Already in TLS mode");
85 return BAD;
86 }
87
88 bincClient << "* ENABLED StartTLS - begin negotiation now" << endl;
89 bincClient << command.getTag() << " OK STARTTLS completed" << endl;
90
91 if (goStartTLS() == ACCEPT)
92 session.command.ssl = true;
93 else
94 return NO;
95
96 return NOTHING;
97}
98
99//----------------------------------------------------------------------
101{
102 Session &session = Session::getInstance();
103
104 if (c_in.getUidMode()) return REJECT;
105
107 if ((res = expectCRLF()) != ACCEPT) {
108 session.setLastError("Expected CRLF");
109 return res;
110 }
111
112 c_in.setName("STARTTLS");
113
114 return ACCEPT;
115}
const std::string & getTag(void) const
Definition: imapparser.cc:52
void setName(const std::string &s_in)
Definition: imapparser.cc:70
bool getUidMode(void) const
Definition: imapparser.cc:40
void setLastError(const std::string &error) const
Definition: session.cc:185
@ NONAUTHENTICATED
Definition: session.h:36
@ AUTHENTICATED
Definition: session.h:37
bool ssl
Definition: session.h:30
struct Binc::Session::@3 command
static Session & getInstance(void)
Definition: session.cc:33
std::string getEnv(const std::string &key)
Definition: session.cc:230
virtual ParseResult parse(Request &) const
int goStartTLS(void) const
ProcessResult process(Depot &, Request &)
const std::string getName(void) const
Declaration of the IODevice class.
Declaration of the IOFactory class.
#define bincClient
Definition: iofactory.h:31
Definition: bincimapd.cc:9
Operator::ParseResult expectCRLF(void)
Declaration of all operators.
Declaration of a recursive descent IMAP command parser.