@@ -64,12 +64,7 @@ SChannelConnection::SChannelConnection()
6464
6565SChannelConnection::~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
7570SECURITY_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+
447451void SChannelConnection::close ()
448452{
449- // TODO
453+ destroyContext ();
454+ socket.close ();
450455}
451456
452457bool SChannelConnection::valid ()
0 commit comments