예제 #1
0
        public static ImpersonationContext SetTargetSQLServerImpersonationContext()
        {
            ImpersonationContext ic = m_ImpersonationContext;

            m_ImpersonationContext = ImpersonationContext.TargetSQLServer;
            if (ic != ImpersonationContext.TargetSQLServer)
            {
                using (logX.loggerX.VerboseCall())
                {
                    if (ic == ImpersonationContext.TargetComputer)
                    {
                        if (m_targetImpersionationContext != null)
                        {
                            logX.loggerX.Verbose(string.Format("Leaving Target Computer Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name));
                            m_targetImpersionationContext.Undo();
                            m_targetImpersionationContext.Dispose();
                            m_targetImpersionationContext = null;
                        }
                        else
                        {
                            if (TargetServer != null)
                            {
                                logX.loggerX.Verbose(string.Format("Leaving Target Computer Bind Context: {0}", m_targetUserName));
                                TargetServer.Unbind();
                            }
                        }
                    }
                    else if (ic == ImpersonationContext.Local)
                    {
                        logX.loggerX.Verbose(string.Format("Leaving Local Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name));
                        //if (m_LocalImpersionationContext != null)
                        //{
                        //    m_LocalImpersionationContext.Undo();
                        //    m_LocalImpersionationContext.Dispose();
                        //    m_LocalImpersionationContext = null;
                        //}
                    }
                    if (m_targetSQLServerIdentity != null)
                    {
                        m_targetSQLServerImpersionationContext = m_targetSQLServerIdentity.Impersonate();
                        logX.loggerX.Verbose(string.Format("Entering Target SQL Server Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name));
                    }
                    else
                    {
                        if (m_UserSQLAuthentication)
                        {
                            logX.loggerX.Verbose("Using SQL Server Credentials");
                        }
                        else
                        {
                            logX.loggerX.Verbose("Failed to Enter Target SQL Server Impersonation Context");
                            logX.loggerX.Verbose(string.Format("Using Local User Context for Target SQL Server: {0}", WindowsIdentity.GetCurrent().Name));
                        }
                    }
                }
            }
            return(ic);
        }
        public void NotifyCredentialsAuthenticated(Uri uri)
        {
            if (m_ctxt == null)
            {
                return;
            }

            m_ctxt.Dispose();
            m_ctxt = null;
        }
예제 #3
0
 /// <summary>
 /// Ends the current impersonation context.
 /// </summary>
 public void EndImpersonationContext()
 {
     //if the context exists undo it and dispose of the object
     if (impersonationContext != null)
     {
         //end the impersonation context and dispose of the object
         impersonationContext.Undo();
         impersonationContext.Dispose();
     }
     //mark the impersonation flag false
     impersonating = false;
 }
        /// <summary>
        /// Executes a supplied delegate while impersonating the application pool
        /// account.
        /// </summary>
        ///
        /// <param name="del">The delegate to execute.</param>
        ///
        internal static void ImpersonateAppPool(VoidDelegate del)
        {
            try
            {
                WindowsImpersonationContext m_context = null;
                try
                {
#if false
                    m_context = AppPoolIdentity.Impersonate();
#else
                    m_context = WindowsIdentity.Impersonate(IntPtr.Zero);
#endif
                    del();
                }
                finally
                {
                    if (m_context != null)
                    {
                        m_context.Dispose();
                    }
                }
            }
            catch
            {
                // prevent exception filter exploits
                throw;
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            // Initialize the Console (sets up logging, etc.).
            startup();

            // Start splash screen.
            Thread splashThread = new Thread(new ThreadStart(ShowSplashScreen));

            splashThread.Start();

            // Start the application.
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            StyleManager.Load(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "Idera.SQLsecure.UI.Console.Styles.Office2007Black.isl"));

            gController = new Controller(); // Contruct this object in this order
            Application.Run(new MainForm());

            // Save the user options.
            Utility.UserData.Current.Save();

            //Start-SQLsecure 3.1 (Tushar)--Supporting windows auth for repository connection
            if (targetRepositoryImpersonationContext != null)
            {
                targetRepositoryImpersonationContext.Undo();
                targetRepositoryImpersonationContext.Dispose();
                targetRepositoryImpersonationContext = null;
            }
            //End-SQLsecure 3.1 (Tushar)--Supporting windows auth for repository connection
            // Exiting utility, do shutdown processing.
            shutdown();
        }
예제 #6
0
        public void Dispose()
        {
            _context.Undo(); // Stop impersonating the thread.

            _id.Dispose();
            _context.Dispose();
        }
예제 #7
0
        public void Dispose(bool disposing)
        {
            RevertToSelf();
            IntPtr secCtx = SafeNativeMethods.CoSwitchCallContext(oldSecurityObject);

            if (IntPtr.Zero == secCtx)
            {
                // this has to be a failfast since not having a security context can compromise security
                DiagnosticUtility.FailFast("Security Context was should not be null");
            }

            if (Marshal.GetObjectForIUnknown(secCtx) != this)
            {
                // this has to be a failfast since being in the wrong security context can compromise security
                DiagnosticUtility.FailFast("Security Context was modified from underneath us");
            }
            Marshal.Release(secCtx);
            if (disposing)
            {
                clientIdentity = null;
                if (impersonateContext != null)
                {
                    impersonateContext.Dispose();
                }
            }
        }
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        public void CanLoadResource()
        {
            FileStream stream = null;
            WindowsImpersonationContext imp = null;

            try
            {
                //IIdentity i = Thread.CurrentPrincipal.Identity;
                //imp = ((WindowsIdentity)i).Impersonate();

                stream = File.OpenRead(Server.MapPath("resource.txt"));

                WriteToPage("Access to file allowed.");
            }
            catch (UnauthorizedAccessException)
            {
                WriteException("Access to file denied.");
            }
            finally
            {
                if (imp != null)
                {
                    imp.Undo();
                    imp.Dispose();
                }

                if (stream != null)
                {
                    stream.Dispose();
                }
            }
        }
예제 #9
0
 public void Dispose()
 {
     Console.WriteLine("Closeing Impersonation context");
     impersonationContext?.Dispose();
     windowsIdentity?.Dispose();
     identityToken.Dispose();
 }
예제 #10
0
 /// <summary>
 /// This method Impersonates to the current user account and notifies
 /// the web part that it's be done.
 /// </summary>
 public void Dispose()
 {
     if (m_context != null)
     {
         m_context.Dispose();
     }
 }
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    if (_identity != null)
                    {
                        _identity.Dispose();
                        _identity = null;
                    }
                }

                if (_context != null)
                {
                    _context.Undo();
                    _context.Dispose();
                    _context = null;
                }

                if (_token != IntPtr.Zero)
                {
                    CloseHandle(_token);
                    _token = IntPtr.Zero;
                }

                _disposed = true;
            }
        }
 public static void UndoImpersonation()
 {
     // restore original identity
     _windowsImpersonationContext?.Undo();
     _windowsImpersonationContext?.Dispose();
     _windowsImpersonationContext = null;
 }
예제 #13
0
 public void Undo()
 {
     if (_impersonationContext != null)
     {
         _impersonationContext.Undo();
         _impersonationContext.Dispose();
     }
 }
예제 #14
0
        public static ImpersonationContext SetTargetImpersonationContext()
        {
            ImpersonationContext ic = m_ImpersonationContext;

            m_ImpersonationContext = ImpersonationContext.TargetComputer;
            if (ic != ImpersonationContext.TargetComputer)
            {
                using (logX.loggerX.VerboseCall())
                {
                    if (ic == ImpersonationContext.TargetSQLServer)
                    {
                        if (m_targetSQLServerImpersionationContext != null)
                        {
                            logX.loggerX.Verbose(string.Format("Leaving Target SQL Server Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name));
                            m_targetSQLServerImpersionationContext.Undo();
                            m_targetSQLServerImpersionationContext.Dispose();
                            m_targetSQLServerImpersionationContext = null;
                        }
                    }
                    else if (ic == ImpersonationContext.Local)
                    {
                        logX.loggerX.Verbose(string.Format("Leaving Local Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name));
                        //if (m_LocalImpersionationContext != null)
                        //{
                        //    m_LocalImpersionationContext.Undo();
                        //    m_LocalImpersionationContext.Dispose();
                        //    m_LocalImpersionationContext = null;
                        //}
                    }
                    if (m_targetIdentity != null)
                    {
                        m_targetImpersionationContext = m_targetIdentity.Impersonate();
                        logX.loggerX.Verbose(string.Format("Entering Target Computer Impersonation Context: {0}", WindowsIdentity.GetCurrent().Name));
                    }
                    else
                    {
                        if (TargetServer != null)
                        {
                            bool results = TargetServer.Bind();
                            logX.loggerX.Verbose(string.Format("Entering Target Computer Bind Context: {0}", m_targetUserName));
                        }
                    }
                }
            }
            return(ic);
        }
예제 #15
0
 public void Dispose()
 {
     if (wic != null)
     {
         wic.Dispose();
     }
     RevertToSelf();
 }
예제 #16
0
파일: UTL.cs 프로젝트: pfs-haibv/projpscd
 public void Revert()
 {
     if (context != null)
     {
         context.Undo();
         context.Dispose();
     }
 }
예제 #17
0
 /// <summary>
 /// Ends impersonation of the WCF client's Windows credentials.
 /// </summary>
 public void Dispose()
 {
     if (_windowsImpersonationContext != null)
     {
         _windowsImpersonationContext.Dispose();
         _windowsImpersonationContext = null;
     }
 }
예제 #18
0
            public void Dispose()
            {
                WindowsImpersonationContext wic = Context;

                if (wic != null)
                {
                    wic.Dispose();
                }
            }
예제 #19
0
        public void Dispose()
        {
            if (m_impersonationContext != null)
            {
                m_impersonationContext.Dispose();

                m_impersonationContext = null;
            }
        }
예제 #20
0
 public void Undo()
 {
     if (m_ImpersonationContext != null)
     {
         m_ImpersonationContext.Undo();
         m_ImpersonationContext.Dispose();
         Console.WriteLine("After finished impersonation: " + WindowsIdentity.GetCurrent().Name);
     }
 }
예제 #21
0
        public void Dispose()
        {
            if (LastContext == null)
            {
                return;
            }

            LastContext.Undo();
            LastContext.Dispose();
        }
예제 #22
0
        /// <summary>
        /// Dispose all allocated resources.
        /// </summary>
        public void Dispose()
        {
            if (_impersonationContext == null)
            {
                return;
            }

            _impersonationContext.Dispose();

            _impersonationContext = null;
        }
 /// <summary>
 /// 释放资源
 /// </summary>
 /// <param name="dispose"></param>
 protected virtual void Disposing(bool dispose)
 {
     if (dispose)
     {
         if (_fContext != null)
         {
             _fContext.Undo();
             _fContext.Dispose();
         }
     }
 }
예제 #24
0
 private static void UndoImpersonation(WindowsImpersonationContext context)
 {
     using (logX.loggerX.InfoCall())
     {
         if (context != null)
         {
             context.Undo();
             context.Dispose();
         }
     }
 }
 public void EndImpersonate()
 {
     if (_newId != null)
     {
         _newId.Dispose();
     }
     if (_impersonatedUser != null)
     {
         _impersonatedUser.Dispose();
     }
 }
예제 #26
0
        internal static void UndoContext(ref WindowsImpersonationContext context)
        {
            WindowsImpersonationContext windowsImpersonationContext = context;

            context = null;
            if (windowsImpersonationContext != null)
            {
                windowsImpersonationContext.Undo();
                windowsImpersonationContext.Dispose();
            }
        }
예제 #27
0
 public void Dispose()
 {
     if (_context != null)
     {
         _context.Dispose();
     }
     if (_handle != null)
     {
         this._handle.Dispose();
     }
 }
예제 #28
0
 private void Unmount()
 {
     if (context != null)
     {
         context.Undo();
         context.Dispose();
     }
     if (identity != null)
     {
         identity.Dispose();
     }
 }
예제 #29
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         _impersonationContext.Undo();
         _impersonationContext.Dispose();
         _disposed = true;
     }
     else
     {
         throw new ObjectDisposedException("ProcessIdentityScope");
     }
 }
예제 #30
0
 /// <summary>
 /// Revert to original user and cleanup.
 /// </summary>
 protected virtual void Dispose(bool disposing)
 {
     if (!disposing)
     {
         return;
     }
     // Revert to original user identity
     UndoImpersonation();
     if (_impersonationContext != null)
     {
         _impersonationContext.Dispose();
     }
 }