private void DatabaseInfo(byte[] items, byte[] buffer, int bufferLength) { try { Xdr.Write(IscCodes.op_info_database); Xdr.Write(_handle); Xdr.Write(Incarnation); Xdr.WriteBuffer(items, items.Length); Xdr.Write(bufferLength); Xdr.Flush(); var response = (GenericResponse)ReadResponse(); var responseLength = bufferLength; if (response.Data.Length < bufferLength) { responseLength = response.Data.Length; } Buffer.BlockCopy(response.Data, 0, buffer, 0, responseLength); } catch (IOException ex) { throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } }
public override async Task AttachWithTrustedAuth(DatabaseParameterBufferBase dpb, string dataSource, int port, string database, byte[] cryptKey, AsyncWrappingCommonArgs async) { try { using (var sspiHelper = new SspiHelper()) { var authData = sspiHelper.InitializeClientSecurity(); await SendTrustedAuthToBuffer(dpb, authData, async).ConfigureAwait(false); await SendAttachToBuffer(dpb, database, async).ConfigureAwait(false); await Xdr.Flush(async).ConfigureAwait(false); var response = await ReadResponse(async).ConfigureAwait(false); response = await ProcessTrustedAuthResponse(sspiHelper, response, async).ConfigureAwait(false); await ProcessAttachResponse((GenericResponse)response, async).ConfigureAwait(false); } } catch (IscException) { await SafelyDetach(async).ConfigureAwait(false); throw; } catch (IOException ex) { await SafelyDetach(async).ConfigureAwait(false); throw IscException.ForIOException(ex); } await AfterAttachActions(async).ConfigureAwait(false); }
public override async Task Attach(DatabaseParameterBufferBase dpb, string dataSource, int port, string database, byte[] cryptKey, AsyncWrappingCommonArgs async) { try { await SendAttachToBuffer(dpb, database, async).ConfigureAwait(false); await Xdr.Flush(async).ConfigureAwait(false); var response = await ReadResponse(async).ConfigureAwait(false); response = await ProcessCryptCallbackResponseIfNeeded(response, cryptKey, async).ConfigureAwait(false); await ProcessAttachResponse((GenericResponse)response, async).ConfigureAwait(false); } catch (IscException) { await SafelyDetach(async).ConfigureAwait(false); throw; } catch (IOException ex) { await SafelyDetach(async).ConfigureAwait(false); throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } await AfterAttachActions(async).ConfigureAwait(false); }
private async Task DatabaseInfo(byte[] items, byte[] buffer, int bufferLength, AsyncWrappingCommonArgs async) { try { await Xdr.Write(IscCodes.op_info_database, async).ConfigureAwait(false); await Xdr.Write(_handle, async).ConfigureAwait(false); await Xdr.Write(Incarnation, async).ConfigureAwait(false); await Xdr.WriteBuffer(items, items.Length, async).ConfigureAwait(false); await Xdr.Write(bufferLength, async).ConfigureAwait(false); await Xdr.Flush(async).ConfigureAwait(false); var response = (GenericResponse) await ReadResponse(async).ConfigureAwait(false); var responseLength = bufferLength; if (response.Data.Length < bufferLength) { responseLength = response.Data.Length; } Buffer.BlockCopy(response.Data, 0, buffer, 0, responseLength); } catch (IOException ex) { throw IscException.ForIOException(ex); } }
public override void AttachWithTrustedAuth(DatabaseParameterBufferBase dpb, string dataSource, int port, string database, byte[] cryptKey) { try { using (var sspiHelper = new SspiHelper()) { var authData = sspiHelper.InitializeClientSecurity(); SendTrustedAuthToBuffer(dpb, authData); SendAttachToBuffer(dpb, database); Xdr.Flush(); var response = ReadResponse(); ProcessTrustedAuthResponse(sspiHelper, ref response); ProcessAttachResponse((GenericResponse)response); } } catch (IscException) { SafelyDetach(); throw; } catch (IOException ex) { SafelyDetach(); throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } AfterAttachActions(); }
public void QueueEvents(RemoteEvent remoteEvent) { try { if (_eventManager == null) { ConnectionRequest(out var auxHandle, out var ipAddress, out var portNumber); _eventManager = new GdsEventManager(auxHandle, ipAddress, portNumber); var dummy = _eventManager.WaitForEventsAsync(remoteEvent); } remoteEvent.LocalId++; var epb = remoteEvent.BuildEpb(); var epbData = epb.ToArray(); Xdr.Write(IscCodes.op_que_events); Xdr.Write(_handle); Xdr.WriteBuffer(epbData); Xdr.Write(AddressOfAstRoutine); Xdr.Write(ArgumentToAstRoutine); Xdr.Write(remoteEvent.LocalId); Xdr.Flush(); var response = (GenericResponse)ReadResponse(); remoteEvent.RemoteId = response.ObjectHandle; } catch (IOException ex) { throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } }
public override void QueueEvents(RemoteEvent remoteEvent) { try { if (_eventManager == null) { var(auxHandle, ipAddress, portNumber, timeout) = ConnectionRequest(); _eventManager = new GdsEventManager(auxHandle, ipAddress, portNumber, timeout); _eventManager.Open(); var dummy = _eventManager.StartWaitingForEvents(remoteEvent); } remoteEvent.LocalId++; var epb = remoteEvent.BuildEpb(); var epbData = epb.ToArray(); Xdr.Write(IscCodes.op_que_events); Xdr.Write(_handle); Xdr.WriteBuffer(epbData); Xdr.Write(AddressOfAstRoutine); Xdr.Write(ArgumentToAstRoutine); Xdr.Write(remoteEvent.LocalId); Xdr.Flush(); var response = (GenericResponse)ReadResponse(); remoteEvent.RemoteId = response.ObjectHandle; } catch (IOException ex) { throw IscException.ForIOException(ex); } }
public virtual async Task <(int auxHandle, string ipAddress, int portNumber)> ConnectionRequest(AsyncWrappingCommonArgs async) { try { await Xdr.Write(IscCodes.op_connect_request, async).ConfigureAwait(false); await Xdr.Write(IscCodes.P_REQ_async, async).ConfigureAwait(false); await Xdr.Write(_handle, async).ConfigureAwait(false); await Xdr.Write(PartnerIdentification, async).ConfigureAwait(false); await Xdr.Flush(async).ConfigureAwait(false); await ReadOperation(async).ConfigureAwait(false); var auxHandle = await Xdr.ReadInt32(async).ConfigureAwait(false); var garbage1 = new byte[8]; await Xdr.ReadBytes(garbage1, 8, async).ConfigureAwait(false); var respLen = await Xdr.ReadInt32(async).ConfigureAwait(false); respLen += respLen % 4; var sin_family = new byte[2]; await Xdr.ReadBytes(sin_family, 2, async).ConfigureAwait(false); respLen -= 2; var sin_port = new byte[2]; await Xdr.ReadBytes(sin_port, 2, async).ConfigureAwait(false); var portNumber = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(sin_port, 0)); respLen -= 2; // * The address returned by the server may be incorrect if it is behind a NAT box // * so we must use the address that was used to connect the main socket, not the // * address reported by the server. var sin_addr = new byte[4]; await Xdr.ReadBytes(sin_addr, 4, async).ConfigureAwait(false); var ipAddress = _connection.IPAddress.ToString(); respLen -= 4; var garbage2 = new byte[respLen]; await Xdr.ReadBytes(garbage2, respLen, async).ConfigureAwait(false); await Xdr.ReadStatusVector(async).ConfigureAwait(false); return(auxHandle, ipAddress, portNumber); } catch (IOException ex) { throw IscException.ForIOException(ex); } }
protected void ProcessTrustedAuthResponse(SspiHelper sspiHelper, ref IResponse response) { while (response is AuthResponse) { var authData = sspiHelper.GetClientSecurity(((AuthResponse)response).Data); Xdr.Write(IscCodes.op_trusted_auth); Xdr.WriteBuffer(authData); Xdr.Flush(); response = ReadResponse(); } }
protected internal IResponse ProcessCryptCallbackResponseIfNeeded(IResponse response, byte[] cryptKey) { while (response is CryptKeyCallbackResponse) { Xdr.Write(IscCodes.op_crypt_key_callback); Xdr.WriteBuffer(cryptKey); Xdr.Flush(); response = ReadResponse(); } return(response); }
public virtual async Task Detach(AsyncWrappingCommonArgs async) { if (TransactionCount > 0) { throw IscException.ForErrorCodeIntParam(IscCodes.isc_open_trans, TransactionCount); } try { await CloseEventManager(async).ConfigureAwait(false); var detach = _handle != -1; if (detach) { await Xdr.Write(IscCodes.op_detach, async).ConfigureAwait(false); await Xdr.Write(_handle, async).ConfigureAwait(false); } await Xdr.Write(IscCodes.op_disconnect, async).ConfigureAwait(false); await Xdr.Flush(async).ConfigureAwait(false); if (detach) { await ReadResponse(async).ConfigureAwait(false); } await CloseConnection(async).ConfigureAwait(false); } catch (IOException ex) { try { await CloseConnection(async).ConfigureAwait(false); } catch (IOException ex2) { throw IscException.ForErrorCode(IscCodes.isc_network_error, ex2); } throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } finally { _connection = null; _charset = null; _eventManager = null; _serverVersion = null; _dialect = 0; _handle = -1; _packetSize = 0; _warningMessage = null; _transactionCount = 0; } }
public virtual void ConnectionRequest(out int auxHandle, out string ipAddress, out int portNumber) { try { Xdr.Write(IscCodes.op_connect_request); Xdr.Write(IscCodes.P_REQ_async); Xdr.Write(_handle); Xdr.Write(PartnerIdentification); Xdr.Flush(); ReadOperation(); auxHandle = Xdr.ReadInt32(); var garbage1 = new byte[8]; Xdr.ReadBytes(garbage1, 8); var respLen = Xdr.ReadInt32(); respLen += respLen % 4; var sin_family = new byte[2]; Xdr.ReadBytes(sin_family, 2); respLen -= 2; var sin_port = new byte[2]; Xdr.ReadBytes(sin_port, 2); portNumber = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(sin_port, 0)); respLen -= 2; // * The address returned by the server may be incorrect if it is behind a NAT box // * so we must use the address that was used to connect the main socket, not the // * address reported by the server. var sin_addr = new byte[4]; Xdr.ReadBytes(sin_addr, 4); //ipAddress = string.Format( // CultureInfo.InvariantCulture, // "{0}.{1}.{2}.{3}", // buffer[0], buffer[1], buffer[2], buffer[3]); ipAddress = _connection.IPAddress.ToString(); respLen -= 4; var garbage2 = new byte[respLen]; Xdr.ReadBytes(garbage2, respLen); Xdr.ReadStatusVector(); } catch (IOException ex) { throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } }
public override void CreateDatabase(DatabaseParameterBufferBase dpb, string database, byte[] cryptKey) { try { SendCreateToBuffer(dpb, database); Xdr.Flush(); ProcessCreateResponse((GenericResponse)ReadResponse()); } catch (IOException ex) { throw IscException.ForIOException(ex); } }
public virtual void ReleaseObject(int op, int id) { try { SendReleaseObjectToBuffer(op, id); Xdr.Flush(); ProcessReleaseObjectResponse(ReadResponse()); } catch (IOException ex) { throw IscException.ForIOException(ex); } }
public virtual void CreateDatabase(DatabaseParameterBuffer dpb, string dataSource, int port, string database, byte[] cryptKey) { try { SendCreateToBuffer(dpb, database); Xdr.Flush(); ProcessCreateResponse(ReadResponse <GenericResponse>()); } catch (IOException ex) { throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } }
public virtual void ReleaseObject(int op, int id) { try { DoReleaseObjectPacket(op, id); Xdr.Flush(); ProcessReleaseObjectResponse(ReadResponse()); } catch (IOException ex) { throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } }
public override void CancelOperation(int kind) { try { SendCancelOperationToBuffer(kind); Xdr.Flush(); // no response, this is async } catch (IOException ex) { throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } }
public override void CancelOperation(int kind) { try { SendCancelOperationToBuffer(kind); Xdr.Flush(); // no response, this is out-of-band } catch (IOException ex) { throw IscException.ForIOException(ex); } }
public virtual void Detach() { if (TransactionCount > 0) { throw IscException.ForErrorCodeIntParam(IscCodes.isc_open_trans, TransactionCount); } try { CloseEventManager(); var detach = _handle != -1; if (detach) { Xdr.Write(IscCodes.op_detach); Xdr.Write(_handle); } Xdr.Write(IscCodes.op_disconnect); Xdr.Flush(); if (detach) { ReadResponse(); } CloseConnection(); } catch (IOException ex) { try { CloseConnection(); } catch (IOException ex2) { throw IscException.ForErrorCode(IscCodes.isc_network_error, ex2); } throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } finally { _connection = null; _charset = null; _eventManager = null; _serverVersion = null; _dialect = 0; _handle = -1; _packetSize = 0; _warningMessage = null; _transactionCount = 0; } }
public override async Task CreateDatabase(DatabaseParameterBufferBase dpb, string dataSource, int port, string database, byte[] cryptKey, AsyncWrappingCommonArgs async) { try { await SendCreateToBuffer(dpb, database, async).ConfigureAwait(false); await Xdr.Flush(async).ConfigureAwait(false); await ProcessCreateResponse((GenericResponse)await ReadResponse(async).ConfigureAwait(false), async).ConfigureAwait(false); } catch (IOException ex) { throw IscException.ForIOException(ex); } }
internal async Task <IResponse> ProcessCryptCallbackResponseIfNeeded(IResponse response, byte[] cryptKey, AsyncWrappingCommonArgs async) { while (response is CryptKeyCallbackResponse cryptResponse) { await Xdr.Write(IscCodes.op_crypt_key_callback, async).ConfigureAwait(false); await Xdr.WriteBuffer(cryptKey, async).ConfigureAwait(false); await Xdr.Flush(async).ConfigureAwait(false); response = await ReadResponse(async).ConfigureAwait(false); } return(response); }
public override void CreateDatabaseWithTrustedAuth(DatabaseParameterBufferBase dpb, string dataSource, int port, string database, byte[] cryptKey) { using (var sspiHelper = new SspiHelper()) { var authData = sspiHelper.InitializeClientSecurity(); SendTrustedAuthToBuffer(dpb, authData); SendCreateToBuffer(dpb, database); Xdr.Flush(); var response = ReadResponse(); ProcessTrustedAuthResponse(sspiHelper, ref response); ProcessCreateResponse((GenericResponse)response); } }
public virtual async Task ReleaseObject(int op, int id, AsyncWrappingCommonArgs async) { try { await SendReleaseObjectToBuffer(op, id, async).ConfigureAwait(false); await Xdr.Flush(async).ConfigureAwait(false); await ProcessReleaseObjectResponse(await ReadResponse(async).ConfigureAwait(false), async).ConfigureAwait(false); } catch (IOException ex) { throw IscException.ForIOException(ex); } }
public virtual (int auxHandle, string ipAddress, int portNumber, int timeout) ConnectionRequest() { try { Xdr.Write(IscCodes.op_connect_request); Xdr.Write(IscCodes.P_REQ_async); Xdr.Write(_handle); Xdr.Write(PartnerIdentification); Xdr.Flush(); ReadOperation(); var auxHandle = Xdr.ReadInt32(); var garbage1 = new byte[8]; Xdr.ReadBytes(garbage1, 8); var respLen = Xdr.ReadInt32(); respLen += respLen % 4; var sin_family = new byte[2]; Xdr.ReadBytes(sin_family, 2); respLen -= 2; var sin_port = new byte[2]; Xdr.ReadBytes(sin_port, 2); var portNumber = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(sin_port, 0)); respLen -= 2; // * The address returned by the server may be incorrect if it is behind a NAT box // * so we must use the address that was used to connect the main socket, not the // * address reported by the server. var sin_addr = new byte[4]; Xdr.ReadBytes(sin_addr, 4); var ipAddress = _connection.IPAddress.ToString(); respLen -= 4; var garbage2 = new byte[respLen]; Xdr.ReadBytes(garbage2, respLen); Xdr.ReadStatusVector(); return(auxHandle, ipAddress, portNumber, _connection.Timeout); } catch (IOException ex) { throw IscException.ForIOException(ex); } }
public override void Attach(DatabaseParameterBufferBase dpb, string database, byte[] cryptKey) { try { SendAttachToBuffer(dpb, database); Xdr.Flush(); var response = ReadResponse(); if (response is ContAuthResponse) { while (response is ContAuthResponse contAuthResponse) { AuthBlock.Start(contAuthResponse.ServerData, contAuthResponse.AcceptPluginName, contAuthResponse.IsAuthenticated, contAuthResponse.ServerKeys); AuthBlock.SendContAuthToBuffer(Xdr); Xdr.Flush(); response = AuthBlock.ProcessContAuthResponse(Xdr); response = ProcessCryptCallbackResponseIfNeeded(response, cryptKey); } var genericResponse = (GenericResponse)response; ProcessAttachResponse(genericResponse); if (genericResponse.Data.Any()) { AuthBlock.SendWireCryptToBuffer(Xdr); Xdr.Flush(); AuthBlock.ProcessWireCryptResponse(Xdr, _connection); } } else { response = ProcessCryptCallbackResponseIfNeeded(response, cryptKey); ProcessAttachResponse((GenericResponse)response); AuthBlock.Complete(); } AuthBlock.WireCryptValidate(IscCodes.PROTOCOL_VERSION13); } catch (IscException) { SafelyDetach(); throw; } catch (IOException ex) { SafelyDetach(); throw IscException.ForIOException(ex); } AfterAttachActions(); }
public override void Detach() { if (TransactionCount > 0) { throw IscException.ForErrorCodeIntParam(IscCodes.isc_open_trans, TransactionCount); } try { CloseEventManager(); var detach = _handle != -1; if (detach) { Xdr.Write(IscCodes.op_detach); Xdr.Write(_handle); } Xdr.Write(IscCodes.op_disconnect); Xdr.Flush(); if (detach) { ReadResponse(); } CloseConnection(); } catch (IOException ex) { try { CloseConnection(); } catch (IOException) { } throw IscException.ForIOException(ex); } finally { _connection = null; Charset = null; _eventManager = null; ServerVersion = null; Dialect = 0; _handle = -1; PacketSize = 0; WarningMessage = null; TransactionCount = 0; } }
public override async Task CancelOperation(int kind, AsyncWrappingCommonArgs async) { try { await SendCancelOperationToBuffer(kind, async).ConfigureAwait(false); await Xdr.Flush(async).ConfigureAwait(false); // no response, this is async } catch (IOException ex) { throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } }
public override async Task CancelOperation(int kind, AsyncWrappingCommonArgs async) { try { await SendCancelOperationToBuffer(kind, async).ConfigureAwait(false); await Xdr.Flush(async).ConfigureAwait(false); // no response, this is out-of-band } catch (IOException ex) { throw IscException.ForIOException(ex); } }
public override void CreateDatabase(DatabaseParameterBuffer dpb, string dataSource, int port, string database, byte[] cryptKey) { try { SendCreateToBuffer(dpb, database); Xdr.Flush(); var response = ReadResponse(); response = ProcessCryptCallbackResponseIfNeeded(response, cryptKey); ProcessCreateResponse(response as GenericResponse); } catch (IOException ex) { throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } }
protected async Task <IResponse> ProcessTrustedAuthResponse(SspiHelper sspiHelper, IResponse response, AsyncWrappingCommonArgs async) { while (response is AuthResponse) { var authData = sspiHelper.GetClientSecurity(((AuthResponse)response).Data); await Xdr.Write(IscCodes.op_trusted_auth, async).ConfigureAwait(false); await Xdr.WriteBuffer(authData, async).ConfigureAwait(false); await Xdr.Flush(async).ConfigureAwait(false); response = await ReadResponse(async).ConfigureAwait(false); } return(response); }