size_t ssl_socket::write( const void* buffer, size_t size ) { return write_impl(buffer, size); }
std::streamsize write(const char* s, std::streamsize n) { std::streamsize amt = write_impl(s, n); if (amt != 0) { crc_.process_bytes(s, amt); pos_ += amt; } return amt; }
ns_error basis_iostream::write(const std::string& vl, timeouttype tmout) { checkconnect(); if (state_ == connected) { is_timout = false; is_data_ready = false; is_error = false; is_connect = true; error_cod = 0; try { set_wb(vl); io_service_.reset(); //DEBUG_STR_DVNCI(SET ASYNCWRITE) write_impl(); //DEBUG_STR_DVNCI(SET ASYNCTIME) tmout_timer_.expires_from_now(boost::posix_time::milliseconds(tmout ? tmout : timout())); tmout_timer_.async_wait(boost::bind( &basis_iostream::io_handle_timout_expire, shared_from_this(), boost::asio::placeholders::error)); io_service_.run(); } catch (dvncierror& errd) { if (errd.code() == ERROR_IO_SERVICE_LOCK) throw errd; return (errd.code()); } catch (...) { DEBUG_STR_DVNCI(ERROR RESULT); return NS_ERROR_NODEF; } //DEBUG_STR_DVNCI(SET RESULT) if (is_timout) { error_cod = ERROR_IO_TIMOUT_EXPIRE; return error_cod; } if (is_error) { error_cod = ERROR_FAILNET_CONNECTED; return error_cod; } return 0; } return ERROR_IO_LINK_NOT_CONNECTION; }
inline wawo::u32_t write_u32(u32_t const& val, OutIt const& out) { return write_impl(val, out); }
void write(std::ostream& out, const multifamily_pedigree_t& ped) const { L_DEBUG("Printing multifamily pedigree with " << get_brief_description() << " writer..."); write_impl(out, ped); };
LONG ssl_socket::client_disconnect( PCredHandle phCreds, CtxtHandle* phContext ) { DWORD dwType; PBYTE pbMessage; DWORD cbMessage; DWORD cbData; SecBufferDesc OutBuffer; SecBuffer OutBuffers[1]; DWORD dwSSPIFlags; DWORD dwSSPIOutFlags; TimeStamp tsExpiry; DWORD Status; dwType = SCHANNEL_SHUTDOWN; OutBuffers[0].pvBuffer = &dwType; OutBuffers[0].BufferType = SECBUFFER_TOKEN; OutBuffers[0].cbBuffer = sizeof(dwType); OutBuffer.cBuffers = 1; OutBuffer.pBuffers = OutBuffers; OutBuffer.ulVersion = SECBUFFER_VERSION; do { Status = g_sspi->ApplyControlToken(phContext, &OutBuffer); if (FAILED(Status)) { break; } dwSSPIFlags = ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT | ISC_REQ_CONFIDENTIALITY | ISC_RET_EXTENDED_ERROR | ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM; OutBuffers[0].pvBuffer = NULL; OutBuffers[0].BufferType = SECBUFFER_TOKEN; OutBuffers[0].cbBuffer = 0; OutBuffer.cBuffers = 1; OutBuffer.pBuffers = OutBuffers; OutBuffer.ulVersion = SECBUFFER_VERSION; Status = g_sspi->InitializeSecurityContext( phCreds, phContext, NULL, dwSSPIFlags, 0, SECURITY_NATIVE_DREP, NULL, 0, phContext, &OutBuffer, &dwSSPIOutFlags, &tsExpiry); if (FAILED(Status)) { break; } pbMessage = (BYTE*)(OutBuffers[0].pvBuffer); cbMessage = OutBuffers[0].cbBuffer; if (pbMessage != NULL && cbMessage != 0) { m_bAllowPlainText = TRUE; m_bConInit = FALSE; cbData = static_cast<DWORD>(write_impl(pbMessage, static_cast<size_t>(cbMessage))); m_bAllowPlainText = FALSE; if (cbData == SOCKET_ERROR || cbData == 0) { Status = SEC_E_INTERNAL_ERROR; break; } g_sspi->FreeContextBuffer(pbMessage); } } while (FALSE); g_sspi->DeleteSecurityContext(phContext); return Status; }
SECURITY_STATUS ssl_socket::client_handshake_loop( PCredHandle phCreds, CtxtHandle* phContext, BOOL fDoInitialRead, SecBuffer* pExtraData ) { SecBufferDesc InBuffer; SecBuffer InBuffers[2]; SecBufferDesc OutBuffer; SecBuffer OutBuffers[1]; DWORD dwSSPIFlags; DWORD dwSSPIOutFlags; TimeStamp tsExpiry; SECURITY_STATUS scRet; DWORD cbData; PUCHAR IoBuffer; DWORD cbIoBuffer; BOOL fDoRead; dwSSPIFlags = ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT | ISC_REQ_CONFIDENTIALITY | ISC_RET_EXTENDED_ERROR | ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM; IoBuffer = new BYTE[IO_BUFFER_SIZE]; if (IoBuffer == NULL) { return SEC_E_INTERNAL_ERROR; } cbIoBuffer = 0; fDoRead = fDoInitialRead; scRet = SEC_I_CONTINUE_NEEDED; while (scRet == SEC_I_CONTINUE_NEEDED || scRet == SEC_E_INCOMPLETE_MESSAGE || scRet == SEC_I_INCOMPLETE_CREDENTIALS) { if (cbIoBuffer == 0 || scRet == SEC_E_INCOMPLETE_MESSAGE) { if (fDoRead) { m_bAllowPlainText = TRUE; cbData = static_cast<DWORD>(read_impl(IoBuffer + cbIoBuffer, static_cast<size_t>(IO_BUFFER_SIZE - cbIoBuffer))); m_bAllowPlainText = FALSE; if (cbData == SOCKET_ERROR) { scRet = SEC_E_INTERNAL_ERROR; break; } else if (cbData == 0) { scRet = SEC_E_INTERNAL_ERROR; break; } cbIoBuffer += cbData; } else { fDoRead = TRUE; } } InBuffers[0].pvBuffer = IoBuffer; InBuffers[0].cbBuffer = cbIoBuffer; InBuffers[0].BufferType = SECBUFFER_TOKEN; InBuffers[1].pvBuffer = NULL; InBuffers[1].cbBuffer = 0; InBuffers[1].BufferType = SECBUFFER_EMPTY; InBuffer.cBuffers = 2; InBuffer.pBuffers = InBuffers; InBuffer.ulVersion = SECBUFFER_VERSION; OutBuffers[0].pvBuffer = NULL; OutBuffers[0].BufferType = SECBUFFER_TOKEN; OutBuffers[0].cbBuffer = 0; OutBuffer.cBuffers = 1; OutBuffer.pBuffers = OutBuffers; OutBuffer.ulVersion = SECBUFFER_VERSION; scRet = g_sspi->InitializeSecurityContext(phCreds, phContext, NULL, dwSSPIFlags, 0, SECURITY_NATIVE_DREP, &InBuffer, 0, NULL, &OutBuffer, &dwSSPIOutFlags, &tsExpiry); if (scRet == SEC_E_OK || scRet == SEC_I_CONTINUE_NEEDED || FAILED(scRet) && (dwSSPIOutFlags & ISC_RET_EXTENDED_ERROR)) { if (OutBuffers[0].cbBuffer != 0 && OutBuffers[0].pvBuffer != NULL) { m_bAllowPlainText = TRUE; cbData = static_cast<DWORD>(write_impl(OutBuffers[0].pvBuffer, static_cast<size_t>(OutBuffers[0].cbBuffer))); m_bAllowPlainText = FALSE; if (cbData == SOCKET_ERROR || cbData == 0) { g_sspi->FreeContextBuffer(OutBuffers[0].pvBuffer); g_sspi->DeleteSecurityContext(phContext); return SEC_E_INTERNAL_ERROR; } g_sspi->FreeContextBuffer(OutBuffers[0].pvBuffer); OutBuffers[0].pvBuffer = NULL; } } if (scRet == SEC_E_INCOMPLETE_MESSAGE) { continue; } if (scRet == SEC_E_OK) { if (InBuffers[1].BufferType == SECBUFFER_EXTRA) { pExtraData->pvBuffer = new BYTE[InBuffers[1].cbBuffer]; if (pExtraData->pvBuffer == NULL) { return SEC_E_INTERNAL_ERROR; } MoveMemory(pExtraData->pvBuffer, IoBuffer + (cbIoBuffer - InBuffers[1].cbBuffer), InBuffers[1].cbBuffer); pExtraData->cbBuffer = InBuffers[1].cbBuffer; pExtraData->BufferType = SECBUFFER_TOKEN; } else { pExtraData->pvBuffer = NULL; pExtraData->cbBuffer = 0; pExtraData->BufferType = SECBUFFER_EMPTY; } break; } if (scRet == SEC_E_UNTRUSTED_ROOT) { scRet = SEC_E_OK; } // if (FAILED(scRet) // { // break; // } if (scRet == SEC_I_INCOMPLETE_CREDENTIALS) { break; } if (InBuffers[1].BufferType == SECBUFFER_EXTRA) { MoveMemory(IoBuffer, IoBuffer + (cbIoBuffer - InBuffers[1].cbBuffer), InBuffers[1].cbBuffer); cbIoBuffer = InBuffers[1].cbBuffer; } else { cbIoBuffer = 0; } } if (FAILED(scRet)) { g_sspi->DeleteSecurityContext(phContext); } if (IoBuffer) { delete[] IoBuffer; } return scRet; }
SECURITY_STATUS ssl_socket::client_handshake( PCredHandle phCreds, const string_ref server_name, CtxtHandle* phContext, SecBuffer* pExtraData ) { SecBufferDesc OutBuffer; SecBuffer OutBuffers[1]; DWORD dwSSPIFlags; DWORD dwSSPIOutFlags; TimeStamp tsExpiry; SECURITY_STATUS scRet; DWORD cbData; dwSSPIFlags = ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT | ISC_REQ_CONFIDENTIALITY | ISC_RET_EXTENDED_ERROR | ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM; OutBuffers[0].pvBuffer = NULL; OutBuffers[0].BufferType = SECBUFFER_TOKEN; OutBuffers[0].cbBuffer = 0; OutBuffer.cBuffers = 1; OutBuffer.pBuffers = OutBuffers; OutBuffer.ulVersion = SECBUFFER_VERSION; scRet = g_sspi->InitializeSecurityContext( phCreds, NULL, (TCHAR*)server_name.get_buffer(), dwSSPIFlags, 0, SECURITY_NATIVE_DREP, NULL, 0, phContext, &OutBuffer, &dwSSPIOutFlags, &tsExpiry); if (scRet != SEC_I_CONTINUE_NEEDED) { return scRet; } if (OutBuffers[0].cbBuffer != 0 && OutBuffers[0].pvBuffer != NULL) { m_bAllowPlainText = TRUE; cbData = static_cast<DWORD>(write_impl(OutBuffers[0].pvBuffer, static_cast<size_t>(OutBuffers[0].cbBuffer))); m_bAllowPlainText = FALSE; if (cbData == SOCKET_ERROR || cbData == 0) { g_sspi->FreeContextBuffer(OutBuffers[0].pvBuffer); g_sspi->DeleteSecurityContext(phContext); return SEC_E_INTERNAL_ERROR; } g_sspi->FreeContextBuffer(OutBuffers[0].pvBuffer); OutBuffers[0].pvBuffer = NULL; } SECURITY_STATUS rc = client_handshake_loop(phCreds, phContext, TRUE, pExtraData); if (pExtraData->pvBuffer) { delete[] pExtraData->pvBuffer; } return rc; }
void write(Sink& sink, Args const& ... args) { sink_adapter_type<Sink> sink_adapter(sink); write_impl(sink_adapter, args...); }
void write_impl(Sink& sink, Value const& value, Args const& ... args) { type_adapter<Value>::format(sink, value); write_impl(sink, args...); }
void write(OStream & ost, Args const & ...) const { auto s = here::unescape<String, I, E, typename OStream::char_type>(type_seq<> {}); write_impl(ost, s); }