Skip to content

Commit e1173fe

Browse files
committed
Clean up some TODOs and FIXMEs
1 parent b26e82c commit e1173fe

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

src/windows/SChannelConnection.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,7 @@ SChannelConnection::SChannelConnection()
6464

6565
SChannelConnection::~SChannelConnection()
6666
{
67-
// TODO?
68-
if (CtxtHandle *context = static_cast<CtxtHandle*>(this->context))
69-
{
70-
DeleteSecurityContext(context);
71-
delete context;
72-
}
67+
destroyContext();
7368
}
7469

7570
SECURITY_STATUS InitializeSecurityContext(CredHandle *phCredential, std::unique_ptr<CtxtHandle>& phContext, const std::string& szTargetName, ULONG fContextReq, std::vector<char>& inputBuffer, std::vector<char>& outputBuffer, ULONG *pfContextAttr)
@@ -200,9 +195,9 @@ bool SChannelConnection::connect(const std::string &hostname, uint16_t port)
200195
sendData = true;
201196
break;
202197
default:
203-
debug << "Initialize done: " << outputBuffer.size() << " bytes of output and status " << ret << "\n";
198+
debug << "Initialize done: " << outputBuffer.size() << " bytes of output and unknown status " << ret << "\n";
204199
done = true;
205-
// TODO: error
200+
success = false;
206201
break;
207202
}
208203

@@ -232,7 +227,6 @@ bool SChannelConnection::connect(const std::string &hostname, uint16_t port)
232227
break;
233228
}
234229
}
235-
// TODO: A bunch of frees?
236230
} while (!done);
237231

238232
debug << "Done!\n";
@@ -254,7 +248,7 @@ bool SChannelConnection::connect(const std::string &hostname, uint16_t port)
254248
}
255249

256250
if (success)
257-
this->context = static_cast<void*>(context.release());
251+
this->context = context.release();
258252
else if (contextCreated)
259253
DeleteSecurityContext(context.get());
260254

@@ -444,9 +438,20 @@ size_t SChannelConnection::write(const char *buffer, size_t size)
444438
return size;
445439
}
446440

441+
void SChannelConnection::destroyContext()
442+
{
443+
if (context)
444+
{
445+
DeleteSecurityContext(context);
446+
delete context;
447+
context = nullptr;
448+
}
449+
}
450+
447451
void SChannelConnection::close()
448452
{
449-
// TODO
453+
destroyContext();
454+
socket.close();
450455
}
451456

452457
bool SChannelConnection::valid()

src/windows/SChannelConnection.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
#include <vector>
77

8+
struct _SecHandle;
9+
using CtxtHandle = _SecHandle;
10+
811
class SChannelConnection : public Connection
912
{
1013
public:
@@ -19,9 +22,10 @@ class SChannelConnection : public Connection
1922

2023
private:
2124
PlaintextConnection socket;
22-
void *context; // FIXME
25+
CtxtHandle *context;
2326
std::vector<char> encRecvBuffer;
2427
std::vector<char> decRecvBuffer;
2528

2629
size_t decrypt(char *buffer, size_t size, bool recurse = true);
30+
void destroyContext();
2731
};

0 commit comments

Comments
 (0)