internal override object ReadAsync(out uint error, ref object handle) { IntPtr readPacketPtr = IntPtr.Zero; error = SNINativeMethodWrapper.SNIReadAsync((SNIHandle)handle, ref readPacketPtr); return(readPacketPtr); }
private void LoadSSPILibrary() { if (TdsParserStateObjectFactory.UseManagedSNI) { return; } // Outer check so we don't acquire lock once it's loaded. if (!s_fSSPILoaded) { lock (s_tdsParserLock) { // re-check inside lock if (!s_fSSPILoaded) { // use local for ref param to defer setting s_maxSSPILength until we know the call succeeded. uint maxLength = 0; if (0 != SNINativeMethodWrapper.SNISecInitPackage(ref maxLength)) { SSPIError(SQLMessage.SSPIInitializeError(), TdsEnums.INIT_SSPI_PACKAGE); } s_maxSSPILength = maxLength; s_fSSPILoaded = true; } } } if (s_maxSSPILength > int.MaxValue) { throw SQL.InvalidSSPIPacketSize(); // SqlBu 332503 } }
// creates a physical connection internal SNIHandle( SNINativeMethodWrapper.ConsumerInfo myInfo, string serverName, byte[] spnBuffer, bool ignoreSniOpenTimeout, int timeout, out byte[] instanceName, bool flushCache, bool fSync, bool fParallel) : base(IntPtr.Zero, true) { try { } finally { _fSync = fSync; instanceName = new byte[256]; // Size as specified by netlibs. if (ignoreSniOpenTimeout) { timeout = Timeout.Infinite; // -1 == native SNIOPEN_TIMEOUT_VALUE / INFINITE } _status = SNINativeMethodWrapper.SNIOpenSyncEx(myInfo, serverName, ref base.handle, spnBuffer, instanceName, flushCache, fSync, timeout, fParallel); } }
// constructs SNI Handle for MARS session internal SNIHandle(SNINativeMethodWrapper.ConsumerInfo myInfo, SNIHandle parent) : base(IntPtr.Zero, true) { RuntimeHelpers.PrepareConstrainedRegions(); try {} finally { _status = SNINativeMethodWrapper.SNIOpenMarsSession(myInfo, parent, ref base.handle, parent._fSync); } }
private SNIErrorDetails GetSniErrorDetails() { SNIErrorDetails details = new SNIErrorDetails(); if (TdsParserStateObjectFactory.UseManagedSNI) { SNIError sniError = SNIProxy.Singleton.GetLastError(); details.sniErrorNumber = sniError.sniError; details.errorMessage = sniError.errorMessage; details.nativeError = sniError.nativeError; details.provider = (int)sniError.provider; details.lineNumber = sniError.lineNumber; details.function = sniError.function; details.exception = sniError.exception; } else { SNINativeMethodWrapper.SNI_Error sniError; SNINativeMethodWrapper.SNIGetLastError(out sniError); details.sniErrorNumber = sniError.sniError; details.errorMessage = sniError.errorMessage; details.nativeError = sniError.nativeError; details.provider = (int)sniError.provider; details.lineNumber = sniError.lineNumber; details.function = sniError.function; } return(details); }
// creates a physical connection internal SNIHandle( SNINativeMethodWrapper.ConsumerInfo myInfo, string serverName, byte[] spnBuffer, bool ignoreSniOpenTimeout, int timeout, out byte[] instanceName, bool flushCache, bool fSync, bool fParallel, TransparentNetworkResolutionState transparentNetworkResolutionState, int totalTimeout) : base(IntPtr.Zero, true) { RuntimeHelpers.PrepareConstrainedRegions(); try {} finally { _fSync = fSync; instanceName = new byte[256]; // Size as specified by netlibs. if (ignoreSniOpenTimeout) { // timeout = Timeout.Infinite; // -1 == native SNIOPEN_TIMEOUT_VALUE / INFINITE } int transparentNetworkResolutionStateNo = (int)transparentNetworkResolutionState; _status = SNINativeMethodWrapper.SNIOpenSyncEx(myInfo, serverName, ref base.handle, spnBuffer, instanceName, flushCache, fSync, timeout, fParallel, transparentNetworkResolutionStateNo, totalTimeout, ADP.IsAzureSqlServerEndpoint(serverName)); } }
// constructs SNI Handle for MARS session internal SNIHandle(SNINativeMethodWrapper.ConsumerInfo myInfo, SNIHandle parent) : base(IntPtr.Zero, true) { try { } finally { _status = SNINativeMethodWrapper.SNIOpenMarsSession(myInfo, parent, ref base.handle, parent._fSync); } }
internal SNIPacket(SafeHandle sniHandle) : base(IntPtr.Zero, true) { SNINativeMethodWrapper.SNIPacketAllocate(sniHandle, SNINativeMethodWrapper.IOType.WRITE, ref base.handle); if (IntPtr.Zero == base.handle) { throw SQL.SNIPacketAllocationFailure(); } }
protected override bool ReleaseHandle() { IntPtr handle = base.handle; base.handle = IntPtr.Zero; if (IntPtr.Zero != handle) { SNINativeMethodWrapper.SNIPacketRelease(handle); } return(true); }
protected override bool ReleaseHandle() { IntPtr handle = base.handle; base.handle = IntPtr.Zero; if ((IntPtr.Zero != handle) && (SNINativeMethodWrapper.SNIClose(handle) != 0)) { return(false); } return(true); }
override protected bool ReleaseHandle() { // NOTE: The SafeHandle class guarantees this will be called exactly once. IntPtr ptr = base.handle; base.handle = IntPtr.Zero; if (IntPtr.Zero != ptr) { SNINativeMethodWrapper.SNIPacketRelease(ptr); } return(true); }
internal SNIHandle(SNINativeMethodWrapper.ConsumerInfo myInfo, string serverName, SNIHandle parent) : base(IntPtr.Zero, true) { this._status = uint.MaxValue; RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { this._status = SNINativeMethodWrapper.SNIOpen(myInfo, serverName, parent, ref this.handle, parent._fSync); } }
internal SNIHandle(SNINativeMethodWrapper.ConsumerInfo myInfo, string serverName, SNIHandle parent) : base(IntPtr.Zero, true) { this._status = uint.MaxValue; RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { this._status = SNINativeMethodWrapper.SNIOpen(myInfo, serverName, parent, ref this.handle, parent._fSync); } }
internal override PacketHandle ReadSyncOverAsync(int timeoutRemaining, out uint error) { SNIHandle handle = Handle; if (handle == null) { throw ADP.ClosedConnectionError(); } IntPtr readPacketPtr = IntPtr.Zero; error = SNINativeMethodWrapper.SNIReadSyncOverAsync(handle, ref readPacketPtr, GetTimeoutRemaining()); return(PacketHandle.FromNativePointer(readPacketPtr)); }
protected override bool ReleaseHandle() { if (base.handle != IntPtr.Zero) { if (this._sniStatus == 0) { LocalDBAPI.ReleaseDLLHandles(); SNINativeMethodWrapper.SNITerminate(); } base.handle = IntPtr.Zero; } return(true); }
override protected bool ReleaseHandle() { if (base.handle != IntPtr.Zero) { if (TdsEnums.SNI_SUCCESS == _sniStatus) { LocalDBAPI.ReleaseDLLHandles(); SNINativeMethodWrapper.SNITerminate(); } base.handle = IntPtr.Zero; } return(true); }
internal override object GetResetWritePacket() { if (_sniPacket != null) { SNINativeMethodWrapper.SNIPacketReset(Handle, SNINativeMethodWrapper.IOType.WRITE, _sniPacket, SNINativeMethodWrapper.ConsumerNumber.SNI_Consumer_SNI); } else { lock (_writePacketLockObject) { _sniPacket = _writePacketCache.Take(Handle); } } return(_sniPacket); }
override protected bool ReleaseHandle() { // NOTE: The SafeHandle class guarantees this will be called exactly once. IntPtr ptr = base.handle; base.handle = IntPtr.Zero; if (IntPtr.Zero != ptr) { if (0 != SNINativeMethodWrapper.SNIClose(ptr)) { return(false); // SNIClose should never fail. } } return(true); }
public SNIPacket Take(SNIHandle sniHandle) { SNIPacket packet; if (_packets.Count > 0) { // Success - reset the packet packet = _packets.Pop(); SNINativeMethodWrapper.SNIPacketReset(sniHandle, SNINativeMethodWrapper.IOType.WRITE, packet, SNINativeMethodWrapper.ConsumerNumber.SNI_Consumer_SNI); } else { // Failed to take a packet - create a new one packet = new SNIPacket(sniHandle); } return(packet); }
internal SNIHandle(SNINativeMethodWrapper.ConsumerInfo myInfo, string serverName, byte[] spnBuffer, bool ignoreSniOpenTimeout, int timeout, out byte[] instanceName, bool flushCache, bool fSync, bool fParallel) : base(IntPtr.Zero, true) { this._status = uint.MaxValue; RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { this._fSync = fSync; instanceName = new byte[0x100]; if (ignoreSniOpenTimeout) { timeout = -1; } this._status = SNINativeMethodWrapper.SNIOpenSyncEx(myInfo, serverName, ref this.handle, spnBuffer, instanceName, flushCache, fSync, timeout, fParallel); } }
internal SNIHandle(SNINativeMethodWrapper.ConsumerInfo myInfo, string serverName, byte[] spnBuffer, bool ignoreSniOpenTimeout, int timeout, out byte[] instanceName, bool flushCache, bool fSync, bool fParallel) : base(IntPtr.Zero, true) { this._status = uint.MaxValue; RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { this._fSync = fSync; instanceName = new byte[0x100]; if (ignoreSniOpenTimeout) { timeout = -1; } this._status = SNINativeMethodWrapper.SNIOpenSyncEx(myInfo, serverName, ref this.handle, spnBuffer, instanceName, flushCache, fSync, timeout, fParallel); } }
private SNILoadHandle() : base(IntPtr.Zero, true) { this.ReadAsyncCallbackDispatcher = new SNINativeMethodWrapper.SqlAsyncCallbackDelegate(SNILoadHandle.ReadDispatcher); this.WriteAsyncCallbackDispatcher = new SNINativeMethodWrapper.SqlAsyncCallbackDelegate(SNILoadHandle.WriteDispatcher); this._sniStatus = uint.MaxValue; RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { this._sniStatus = SNINativeMethodWrapper.SNIInitialize(); uint qInfo = 0; if (this._sniStatus == 0) { SNINativeMethodWrapper.SNIQueryInfo(SNINativeMethodWrapper.QTypes.SNI_QUERY_CLIENT_ENCRYPT_POSSIBLE, ref qInfo); } this._encryptionOption = (qInfo == 0) ? EncryptionOptions.NOT_SUP : EncryptionOptions.OFF; base.handle = (IntPtr)1; } }
private static void ObtainProcessDispatcher() { byte[] data = SNINativeMethodWrapper.GetData(); if (data == null) { Bid.NotificationsTrace("<sc.SqlDependency.ObtainProcessDispatcher|DEP> nativeStorage null, obtaining dispatcher AppDomain and creating ProcessDispatcher.\n"); _AppDomain defaultAppDomain = SNINativeMethodWrapper.GetDefaultAppDomain(); if (defaultAppDomain != null) { ObjectHandle handle = CreateProcessDispatcher(defaultAppDomain); if (handle != null) { SqlDependencyProcessDispatcher dispatcher = (SqlDependencyProcessDispatcher)handle.Unwrap(); if (dispatcher != null) { _processDispatcher = dispatcher.SingletonProcessDispatcher; ObjRef objRef = GetObjRef(_processDispatcher); BinaryFormatter formatter2 = new BinaryFormatter(); MemoryStream stream = new MemoryStream(); GetSerializedObject(objRef, formatter2, stream); SNINativeMethodWrapper.SetData(stream.GetBuffer()); return; } Bid.NotificationsTrace("<sc.SqlDependency.ObtainProcessDispatcher|DEP|ERR> ERROR - ObjectHandle.Unwrap returned null!\n"); throw ADP.InternalError(ADP.InternalErrorCode.SqlDependencyObtainProcessDispatcherFailureObjectHandle); } Bid.NotificationsTrace("<sc.SqlDependency.ObtainProcessDispatcher|DEP|ERR> ERROR - AppDomain.CreateInstance returned null!\n"); throw ADP.InternalError(ADP.InternalErrorCode.SqlDependencyProcessDispatcherFailureCreateInstance); } Bid.NotificationsTrace("<sc.SqlDependency.ObtainProcessDispatcher|DEP|ERR> ERROR - unable to obtain default AppDomain!\n"); throw ADP.InternalError(ADP.InternalErrorCode.SqlDependencyProcessDispatcherFailureAppDomain); } Bid.NotificationsTrace("<sc.SqlDependency.ObtainProcessDispatcher|DEP> nativeStorage not null, obtaining existing dispatcher AppDomain and ProcessDispatcher.\n"); BinaryFormatter formatter = new BinaryFormatter(); MemoryStream stream2 = new MemoryStream(data); _processDispatcher = GetDeserializedObject(formatter, stream2); Bid.NotificationsTrace("<sc.SqlDependency.ObtainProcessDispatcher|DEP> processDispatcher obtained, ID: %d\n", _processDispatcher.ObjectID); }
private SNILoadHandle() : base(IntPtr.Zero, true) { // SQL BU DT 346588 - from security review - SafeHandle guarantees this is only called once. // The reason for the safehandle is guaranteed initialization and termination of SNI to // ensure SNI terminates and cleans up properly. RuntimeHelpers.PrepareConstrainedRegions(); try {} finally { _sniStatus = SNINativeMethodWrapper.SNIInitialize(); UInt32 value = 0; // VSDevDiv 479597: If initialize fails, don't call QueryInfo. if (TdsEnums.SNI_SUCCESS == _sniStatus) { // Query OS to find out whether encryption is supported. SNINativeMethodWrapper.SNIQueryInfo(SNINativeMethodWrapper.QTypes.SNI_QUERY_CLIENT_ENCRYPT_POSSIBLE, ref value); } _encryptionOption = (value == 0) ? EncryptionOptions.NOT_SUP : EncryptionOptions.OFF; base.handle = (IntPtr)1; // Initialize to non-zero dummy variable. } }
internal override uint WaitForSSLHandShakeToComplete() => SNINativeMethodWrapper.SNIWaitForSSLHandshakeToComplete(Handle, GetTimeoutRemaining());
internal override uint SniGetConnectionId(ref Guid clientConnectionId) => SNINativeMethodWrapper.SniGetConnectionId(Handle, ref clientConnectionId);
// constructs SNI Handle for MARS session internal SNIHandle(SNINativeMethodWrapper.ConsumerInfo myInfo, SNIHandle parent) : base(IntPtr.Zero, true) { try { } finally { _status = SNINativeMethodWrapper.SNIOpenMarsSession(myInfo, parent, ref base.handle, parent._fSync); } }
internal override uint EnableMars(ref uint info) => SNINativeMethodWrapper.SNIAddProvider(Handle, SNINativeMethodWrapper.ProviderEnum.SMUX_PROV, ref info);
internal override uint DisabeSsl() => SNINativeMethodWrapper.SNIRemoveProvider(Handle, SNINativeMethodWrapper.ProviderEnum.SSL_PROV);
// constructs SNI Handle for MARS session internal SNIHandle(SNINativeMethodWrapper.ConsumerInfo myInfo, SNIHandle parent) : base(IntPtr.Zero, true) { RuntimeHelpers.PrepareConstrainedRegions(); try {} finally { _status = SNINativeMethodWrapper.SNIOpenMarsSession(myInfo, parent, ref base.handle, parent._fSync); } }
internal override uint EnableSsl(ref uint info) { // Add SSL (Encryption) SNI provider. return(SNINativeMethodWrapper.SNIAddProvider(Handle, SNINativeMethodWrapper.ProviderEnum.SSL_PROV, ref info)); }
// creates a physical connection internal SNIHandle( SNINativeMethodWrapper.ConsumerInfo myInfo, string serverName, byte[] spnBuffer, bool ignoreSniOpenTimeout, int timeout, out byte[] instanceName, bool flushCache, bool fSync, bool fParallel) : base(IntPtr.Zero, true) { RuntimeHelpers.PrepareConstrainedRegions(); try {} finally { _fSync = fSync; instanceName = new byte[256]; // Size as specified by netlibs. if (ignoreSniOpenTimeout) { // timeout = Timeout.Infinite; // -1 == native SNIOPEN_TIMEOUT_VALUE / INFINITE } _status = SNINativeMethodWrapper.SNIOpenSyncEx(myInfo, serverName, ref base.handle, spnBuffer, instanceName, flushCache, fSync, timeout, fParallel); } }
internal override uint SetConnectionBufferSize(ref uint unsignedPacketSize) => SNINativeMethodWrapper.SNISetInfo(Handle, SNINativeMethodWrapper.QTypes.SNI_QUERY_CONN_BUFSIZE, ref unsignedPacketSize);
internal override uint GenerateSspiClientContext(byte[] receivedBuff, uint receivedLength, ref byte[] sendBuff, ref uint sendLength, byte[] _sniSpnBuffer) => SNINativeMethodWrapper.SNISecGenClientContext(Handle, receivedBuff, receivedLength, sendBuff, ref sendLength, _sniSpnBuffer);
private static extern uint SNIGetInfoWrapper([In] SNIHandle pConn, SNINativeMethodWrapper.QTypes QType, out Guid pbQInfo);
protected override uint SNIPacketGetData(PacketHandle packet, byte[] _inBuff, ref uint dataSize) { Debug.Assert(packet.Type == PacketHandle.NativePointerType, "unexpected packet type when requiring NativePointer"); return(SNINativeMethodWrapper.SNIPacketGetData(packet.NativePointer, _inBuff, ref dataSize)); }