summaryrefslogtreecommitdiff
path: root/src/operator-starttls.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/operator-starttls.cc')
-rw-r--r--src/operator-starttls.cc62
1 files changed, 28 insertions, 34 deletions
diff --git a/src/operator-starttls.cc b/src/operator-starttls.cc
index fcc7b3b..3ba5dd0 100644
--- a/src/operator-starttls.cc
+++ b/src/operator-starttls.cc
@@ -1,33 +1,30 @@
/** --------------------------------------------------------------------
* @file operator-starttls.cc
- * @brief Implementation of the STARTTLS command - based on sslserver
+ * @brief Implementation of the STARTTLS command - based on sslserver
* @author Andreas Aardal Hanssen, Erwin Hoffmann
* @date 2002-2005, 2023
* ----------------------------------------------------------------- **/
-#include <string>
-#include <iostream>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include "recursivedescent.h"
+#include "depot.h"
#include "iodevice.h"
#include "iofactory.h"
-#include "session.h"
-#include "depot.h"
#include "operators.h"
+#include "recursivedescent.h"
+#include "session.h"
+
+#include <iostream>
+#include <string>
+
+#include <fcntl.h>
+#include <unistd.h>
using namespace ::std;
using namespace Binc;
//----------------------------------------------------------------------
-StarttlsOperator::StarttlsOperator(void)
-{
-}
+StarttlsOperator::StarttlsOperator(void) {}
//----------------------------------------------------------------------
-StarttlsOperator::~StarttlsOperator(void)
-{
-}
+StarttlsOperator::~StarttlsOperator(void) {}
//----------------------------------------------------------------------
const string StarttlsOperator::getName(void) const
@@ -38,13 +35,11 @@ const string StarttlsOperator::getName(void) const
//----------------------------------------------------------------------
int StarttlsOperator::getState(void) const
{
- return Session::NONAUTHENTICATED
- | Session::AUTHENTICATED
- | Session::SELECTED;
+ return Session::NONAUTHENTICATED | Session::AUTHENTICATED | Session::SELECTED;
}
//----------------------------------------------------------------------
-int StarttlsOperator::goStartTLS (void) const
+int StarttlsOperator::goStartTLS(void) const
{
Session &session = Session::getInstance();
@@ -54,30 +49,29 @@ int StarttlsOperator::goStartTLS (void) const
fdstr = session.getEnv("SSLCTLFD");
fd = std::stoi(fdstr);
- if (write(fd,"Y",1) < 1) return NOTHING;
- bincClient.flush(); // flush all previous received data
+ if (write(fd, "Y", 1) < 1) return NOTHING;
+ bincClient.flush(); // flush all previous received data
fdstr = session.getEnv("SSLREADFD");
fd = std::stoi(fdstr);
- if (fcntl(fd,F_GETFL,0) == -1) return NOTHING;
- close (0);
- if (fcntl(fd,F_DUPFD,0) == -1) return NOTHING;
- close (fd);
+ if (fcntl(fd, F_GETFL, 0) == -1) return NOTHING;
+ close(0);
+ if (fcntl(fd, F_DUPFD, 0) == -1) return NOTHING;
+ close(fd);
fdstr = session.getEnv("SSLWRITEFD");
fd = std::stoi(fdstr);
- if (fcntl(fd,F_GETFL,0) == -1) return NOTHING;
- close (1);
- if (fcntl(fd,F_DUPFD,1) == -1) return NOTHING;
- close (fd);
+ if (fcntl(fd, F_GETFL, 0) == -1) return NOTHING;
+ close(1);
+ if (fcntl(fd, F_DUPFD, 1) == -1) return NOTHING;
+ close(fd);
}
return ACCEPT;
}
//------------------------------------------------------------------------
-Operator::ProcessResult StarttlsOperator::process(Depot &depot,
- Request &command)
+Operator::ProcessResult StarttlsOperator::process(Depot &depot, Request &command)
{
Session &session = Session::getInstance();
if (session.command.ssl) {
@@ -88,9 +82,9 @@ Operator::ProcessResult StarttlsOperator::process(Depot &depot,
bincClient << "* ENABLED StartTLS - begin negotiation now" << endl;
bincClient << command.getTag() << " OK STARTTLS completed" << endl;
- if (goStartTLS() == ACCEPT)
+ if (goStartTLS() == ACCEPT)
session.command.ssl = true;
- else
+ else
return NO;
return NOTHING;
@@ -108,7 +102,7 @@ Operator::ParseResult StarttlsOperator::parse(Request &c_in) const
session.setLastError("Expected CRLF");
return res;
}
-
+
c_in.setName("STARTTLS");
return ACCEPT;