Exemple #1
0
        public static void Initialize(XenGuestAgentLib.XenGuestServices service)
        {
            Program.AssertOffEventThread();
            Thread thread;
            string evname;
            EventWaitHandleSecurity evsec;
            EventWaitHandleAccessRule evrule;
            string user;
            xgsc = service;
            alertList = Program.GetAlertList();

            evname = xgsc.RegisterAlertsEvent();
            user = Environment.UserDomainName + "\\" + Environment.UserName;
            evalerts = EventWaitHandle.OpenExisting(evname,
                EventWaitHandleRights.ReadPermissions | EventWaitHandleRights.ChangePermissions);
            evsec = evalerts.GetAccessControl();
            evrule = new EventWaitHandleAccessRule(user,
                EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify,
                AccessControlType.Deny);
            evsec.RemoveAccessRule(evrule);

            evrule = new EventWaitHandleAccessRule(user,
                EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify,
                AccessControlType.Allow);
            evsec.AddAccessRule(evrule);
            evalerts.SetAccessControl(evsec);

            evalerts = EventWaitHandle.OpenExisting(evname);

            thread = new Thread(alertUpdater);
            thread.Name = "XenClient Alert Thread";
            thread.IsBackground = true;

            thread.Start();
        }
        private static bool OnlyOneCopy()
        {
            bool isnew;
            s_setup_mutex = new Mutex(true, SETUP_MUTEX_NAME, out isnew);

            RestoreEvent = null;
            try
            {
#if RELEASE
                RestoreEvent = AutoResetEvent.OpenExisting(EVENT_NAME);
                RestoreEvent.Set();
                return false;
            }
            catch (WaitHandleCannotBeOpenedException)
            {
#endif
                string user = Environment.UserDomainName + "\\" + Environment.UserName;
                EventWaitHandleSecurity evh_sec = new EventWaitHandleSecurity();

                EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(user,
                    EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify,
                    AccessControlType.Allow);
                evh_sec.AddAccessRule(rule);

                bool was_created;
                RestoreEvent = new EventWaitHandle(false, EventResetMode.AutoReset, 
                    EVENT_NAME, out was_created, evh_sec);
            }
            catch (Exception)
            {
            }

            return true;
        }
Exemple #3
0
        public static EventWaitHandleSecurity EventSecurity()
            {
            SecurityIdentifier user = GetEveryoneSID();
            EventWaitHandleSecurity result = new EventWaitHandleSecurity();

            EventWaitHandleAccessRule  rule = new EventWaitHandleAccessRule(user, EventWaitHandleRights.FullControl, AccessControlType.Allow);
            result.AddAccessRule(rule);

            return result;
            }
        public static bool Create(string name, EventResetMode mode, out EventWaitHandle signal)
        {
            var users = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
            var rule = new EventWaitHandleAccessRule(users, EventWaitHandleRights.Synchronize |
            EventWaitHandleRights.Modify, AccessControlType.Allow);
            var security = new EventWaitHandleSecurity();
            security.AddAccessRule(rule);

            bool created;
            signal = new EventWaitHandle(false, mode, @"Global\" + name, out created, security);

            return created;
        }
Exemple #5
0
        public static EventWaitHandle GetOrCreateEvent(string name)
        {
            EventWaitHandle eventWaitHandle = null;

            if (!EventWaitHandle.TryOpenExisting(@"Global\" + name, out eventWaitHandle))
            {
                SecurityIdentifier users = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
                EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(users, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, AccessControlType.Allow);
                EventWaitHandleSecurity security = new EventWaitHandleSecurity();
                security.AddAccessRule(rule);

                bool created;
                eventWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, @"Global\" + name, out created, security);
            }

            return eventWaitHandle;
        }
Exemple #6
0
        static SysWaiter() {
            string user = Environment.UserDomainName + "\\" + Environment.UserName;
            var rule = new EventWaitHandleAccessRule(user,
                                                     EventWaitHandleRights.FullControl,
                                                     AccessControlType.Allow);
            var security = new EventWaitHandleSecurity();
            security.AddAccessRule(rule);

            bool createdNew;
            _signal_interrupt = new EventWaitHandle(false,
                                                    EventResetMode.ManualReset,
                                                    @"Global\InterruptKey",
                                                    out createdNew,
                                                    security);

            HotKeyGlobal.DefineHotKey(MOD_NONE, VK_ESCAPE, ProcInterrupt);
        }
        private bool SetupUpdateEvent()
        {
            bool createdNew;

            //Setup Security, all authenticated users can open and signal
            EventWaitHandleSecurity ewhs = new EventWaitHandleSecurity();
            SecurityIdentifier wellKnownAuthUsers = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
            EventWaitHandleAccessRule ewhar = new EventWaitHandleAccessRule(wellKnownAuthUsers,EventWaitHandleRights.Modify|EventWaitHandleRights.Synchronize,AccessControlType.Allow);
            ewhs.AddAccessRule(ewhar);
                    
            //Create the update named event
            try
            {
                mRunUpdateEvent = new EventWaitHandle(false, EventResetMode.ManualReset, TRIGGER_EVENT_NAME, out createdNew, ewhs);
            }
            catch (Exception e)
            {
                System.Diagnostics.EventLog.WriteEntry(this.ServiceName, "Software Update Service threw an exception when trying to create the update trigger event. Detail="+e.ToString());
                return false;
            }

            return true;            
        }
        private void ConfigureDropListener()
        {
            var sid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
            var accessRule = new EventWaitHandleAccessRule(sid, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, AccessControlType.Allow);

            var security = new EventWaitHandleSecurity();
            security.AddAccessRule(accessRule);

            bool newlyCreated = false;
            var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "ExtensionsForOneDrive_DataAvailableEvent", out newlyCreated, security);

            if (!newlyCreated)
            {
                throw new InvalidOperationException("Configuration Changed event already exists.");
            }

            _changeListenerTask = Task.Factory.StartNew(() =>
            {
                while (waitHandle.WaitOne())
                {
                    GetPublicLinkAndStore();
                }
            });
        }
 public void SetAccessRule(EventWaitHandleAccessRule rule)
 {
 }
 public void RemoveAccessRuleAll(EventWaitHandleAccessRule rule)
 {
 }
Exemple #11
0
 public void RemoveAccessRuleSpecific(EventWaitHandleAccessRule rule)
 {
     base.RemoveAccessRuleSpecific(rule);
 }
Exemple #12
0
 public bool RemoveAccessRule(EventWaitHandleAccessRule rule)
 {
     return(base.RemoveAccessRule(rule));
 }
 public void AddAccessRule(EventWaitHandleAccessRule rule)
 {
     base.AddAccessRule(rule);
 }
 public bool RemoveAccessRule(EventWaitHandleAccessRule rule)
 {
     return base.RemoveAccessRule(rule);
 }
        private EventWaitHandle CreateGlobalEventWaitHandle(string name)
        {
            var users = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
            var rule = new EventWaitHandleAccessRule(users, EventWaitHandleRights.Synchronize |
                EventWaitHandleRights.Modify, AccessControlType.Allow);
            var security = new EventWaitHandleSecurity();
            security.AddAccessRule(rule);

            bool createdNew;
            return new EventWaitHandle(false, EventResetMode.AutoReset, name, out createdNew, security);
        }
Exemple #16
0
        public static void Initialize()
        {
            Program.AssertOffEventThread();
            Thread thread;
            string evname;
            EventWaitHandleSecurity evsec;
            EventWaitHandleAccessRule evrule;
            string user;

            xgs = Program.GetXGS();

            evname = xgs.GetVmsEventName();
            user = Environment.UserDomainName + "\\" + Environment.UserName;
            evvms = EventWaitHandle.OpenExisting(evname,
                EventWaitHandleRights.ReadPermissions | EventWaitHandleRights.ChangePermissions);
            evsec = evvms.GetAccessControl();
            evrule = new EventWaitHandleAccessRule(user,
                EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify,
                AccessControlType.Deny);
            evsec.RemoveAccessRule(evrule);

            evrule = new EventWaitHandleAccessRule(user,
                EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify,
                AccessControlType.Allow);
            evsec.AddAccessRule(evrule);
            evvms.SetAccessControl(evsec);

            evvms = EventWaitHandle.OpenExisting(evname);

            // Start the monitor thread
            thread = new Thread(CacheXgsMonitor);
            thread.Name = "XenClient Cache Thread";
            thread.IsBackground = true;

            thread.Start();
        }
		public void SetAccessRule (EventWaitHandleAccessRule rule)
		{
			throw new NotImplementedException ();
		}
		public void RemoveAccessRuleSpecific (EventWaitHandleAccessRule rule)
		{
			throw new NotImplementedException ();
		}
		public bool RemoveAccessRule (EventWaitHandleAccessRule rule)
		{
			throw new NotImplementedException ();
		}
Exemple #20
0
        /************************************************************************
         * Constructor
         * 
         * *********************************************************************/

        private Logger ()
        {
            m_NoClients = 0;
            m_levellist = new Dictionary<string, ErrorLevel> ();

            /* Make sure LogCtl can write to the event log using "LogCtl" as the event source
             * ------------------------------------------------------------------------------
             * Vista makes this difficult, and we need to add some messy code to deal with this.
             * Throw an exception if we can't set up the event source */

            EnsureEventSourceExists ();

            try
            {
                using (RegistryKey logkey = Registry.LocalMachine.OpenSubKey ("SOFTWARE\\SWI\\LogCtl", false))
                {
                    m_Filename = logkey.GetValue ("LogFile").ToString ();
                    using (RegistryKey rk = logkey.OpenSubKey ("LogLevel"))
                    {
                        foreach (string s in rk.GetValueNames ())
                        {
                            if (string.IsNullOrEmpty (s))
                            {
                                m_defaultlevel = Trans (rk.GetValue (s).ToString ());
                            }
                            else
                            {
                                m_levellist.Add (s, Trans (rk.GetValue (s).ToString ()));
                            }
                        }
                    }
                    try
                    {
                        m_bIfTrace = ((int) logkey.GetValue ("IfTrace")) != 0;

                        TextWriterTraceListener tw = new TextWriterTraceListener (logkey.GetValue ("TraceFile").ToString ());
                        System.Diagnostics.Trace.Listeners.Add (tw);
                        System.Diagnostics.Trace.AutoFlush = true;
                        System.Diagnostics.Trace.WriteLine ("Logger() built.");
                    }
                    catch (Exception)
                    {
                        EmergencyMessage (EventLogEntryType.Warning, "Missing TraceFile in registry");
                    }
                    try
                    {
                        m_bIfUseFixedFormatting = ((int) logkey.GetValue ("IfUseFixedFormatting")) != 0;
                        string FixedFormatting = logkey.GetValue ("FixedFormatting").ToString ();
                        string[] ar = FixedFormatting.Split (new char[] { ',', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
                        if (ar.GetUpperBound (0) != 5)
                        {
                            EmergencyMessage (EventLogEntryType.Warning, "The FixedFormatting registry entry is not specifying 6 column widths as expected.");
                            m_bIfUseFixedFormatting = false;
                        }
                        for (int i = 0; i < 6; i++)
                        {
                            m_ColumnWidths[i] = int.Parse (ar[i]);
                        }
                    }
                    catch (Exception)
                    {
                        EmergencyMessage (EventLogEntryType.Warning, "IfUseFixedFormatting or FixedFormatting registry entries");
                    }
                }
            }
            catch (Exception)
            {
                /* Possibly this is the first time LogCtl has ever been used
                 * ---------------------------------------------------------
                 * so create some default settings */

                try
                {
                    using (RegistryKey logkey = Registry.LocalMachine.CreateSubKey ("SOFTWARE\\SWI\\LogCtl"))
                    {
                        logkey.SetValue ("LogFile", "C:\\Logs\\log.log");
                        using (RegistryKey rk = logkey.CreateSubKey ("LogLevel"))
                        {
                            rk.SetValue ("", "INF");
                        }
                        logkey.SetValue ("IfTrace", 0);
                        logkey.SetValue ("TraceFile", "C:\\Logs\\trace.log");
                        logkey.SetValue ("RenameEventName", "Global\\STE LogCtl-Rename");
                        logkey.SetValue ("IfUseFixedFormatting", 0);
                        logkey.SetValue ("FixedFormatting", "20 12 5 4 13 26");
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    throw new Exception ("LogCtl could not read or write initialization settings. Please run as administrator and try again.");
                }
                catch (Exception e)
                {
                    throw new Exception (string.Format ("Unexpected exception encountered in LogCtl. {0}", e.Message));
                }
            }

            /* Prepare m_RenameEvent
             * ---------------------
             * add retries, Sept 17, 2009 -- B.Muth */

            int retries = 0;
TryAgain:
            
            try
            {
                using (RegistryKey logkey = Registry.LocalMachine.OpenSubKey ("SOFTWARE\\SWI\\LogCtl", false))
                {
                    string RenameEventName;


                    RenameEventName = logkey.GetValue ("RenameEventName").ToString ();

                    EventWaitHandleSecurity sec = new EventWaitHandleSecurity ();
                    //EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule ("Everyone",
                    //                                                                EventWaitHandleRights.Modify | EventWaitHandleRights.Synchronize,
                    //                                                                AccessControlType.Allow);
                    //EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule (new SecurityIdentifier ("S-1-1-0"), EventWaitHandleRights.FullControl, AccessControlType.Allow);
                    // change from 'Everyone' to 'Users'
                    EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule (new SecurityIdentifier ("S-1-5-32-545"), EventWaitHandleRights.FullControl, AccessControlType.Allow);
                    sec.AddAccessRule (rule);
                    bool bCreated;

                    try
                    {
                        m_RenameEvent = new EventWaitHandle (true, EventResetMode.ManualReset, RenameEventName, out bCreated, sec);
                    }
                    catch (Exception e)
                    {
                        EmergencyMessage (EventLogEntryType.Error, string.Format ("EventWaitHandle() failed in an attempt to create the RenameEventname. {0}", e.Message));
                        if (++retries < 10)
                        {
                            Thread.Sleep (500);
                            goto TryAgain;
                        }
                        m_RenameEvent = null;
                    }
                }
            }
            catch (Exception )
            {
                throw new Exception ("RenameEventName registry entry is missing, or other exception encoutered. Please check the Application Event log.");
            }
        }
Exemple #21
0
 private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
 {
     EventWaitHandle result;
     EventWaitHandle.TryOpenExisting(@"Global\FinishedLoading",
         EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, out result);
     if (result != null)
         eHandle = result;
     else
     {
         var users = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
         var rule = new EventWaitHandleAccessRule(users, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify,
                       AccessControlType.Allow);
         var security = new EventWaitHandleSecurity();
         security.AddAccessRule(rule);
         bool created;
         eHandle = new EventWaitHandle(false, EventResetMode.AutoReset, @"Global\FinishedLoading", out created, security);
     }
     Refresh(this,new RoutedEventArgs());
 }
 public void ResetAccessRule(EventWaitHandleAccessRule rule)
 {
     throw new NotImplementedException();
 }
 public bool RemoveAccessRule(EventWaitHandleAccessRule rule)
 {
     return(RemoveAccessRule((AccessRule)rule));
 }
 public void SetAccessRule(EventWaitHandleAccessRule rule)
 {
     base.SetAccessRule(rule);
 }
 public void RemoveAccessRuleSpecific(EventWaitHandleAccessRule rule)
 {
     RemoveAccessRuleSpecific((AccessRule)rule);
 }
Exemple #26
0
 public void AddAccessRule(EventWaitHandleAccessRule rule)
 {
     base.AddAccessRule(rule);
 }
        /// <summary>
        ///   Initializes the synchronization objects needed to deal with multiple instances of the same application.
        /// </summary>
        /// <param name = "baseName">The base name of the synchronization objects.</param>
        /// <param name = "identity">The identity to be associated to the synchronization objects.</param>
        private void InitializeSynchronizationObjects(string baseName, IdentityReference identity)
        {
            string firstInstanceMutexName = baseName + "_FirstInstance";
            string serviceInitializationMutexName = baseName + "_ServiceInitialization";
            string serviceReadySemaphoreName = baseName + "_ServiceReady";
            string signaledToFirstInstanceSemaphoreName = baseName + "_SignaledToFirstInstance";

            bool isNew;
            var eventRule = new EventWaitHandleAccessRule(identity, EventWaitHandleRights.FullControl, AccessControlType.Allow);
            var eventSecurity = new EventWaitHandleSecurity();
            eventSecurity.AddAccessRule(eventRule);

            var mutexRule = new MutexAccessRule(identity, MutexRights.FullControl, AccessControlType.Allow);
            var mutexSecurity = new MutexSecurity();
            mutexSecurity.AddAccessRule(mutexRule);

            m_FirstInstanceMutex = new Mutex(false, firstInstanceMutexName, out isNew, mutexSecurity);
            m_ServiceInitializationMutex = new Mutex(false, serviceInitializationMutexName, out isNew, mutexSecurity);
            m_ServiceReadySemaphore = new EventWaitHandle(false, EventResetMode.ManualReset, serviceReadySemaphoreName, out isNew, eventSecurity);
            m_SignaledToFirstInstanceSemaphore = new EventWaitHandle(false, EventResetMode.AutoReset, signaledToFirstInstanceSemaphoreName, out isNew, eventSecurity);
        }
 public void AddAccessRule(EventWaitHandleAccessRule rule)
 {
     AddAccessRule((AccessRule)rule);
 }
Exemple #29
0
 public bool RemoveAccessRule(EventWaitHandleAccessRule rule)
 {
     return(default(bool));
 }
 public void RemoveAccessRuleAll(EventWaitHandleAccessRule rule)
 {
     RemoveAccessRuleAll((AccessRule)rule);
 }
Exemple #31
0
 public void ResetAccessRule(EventWaitHandleAccessRule rule)
 {
 }
 public void SetAccessRule(EventWaitHandleAccessRule rule)
 {
     SetAccessRule((AccessRule)rule);
 }
Exemple #33
0
 /// <summary>不论 <see cref="T:System.Security.AccessControl.AccessControlType" /> 如何,移除与指定的规则具有相同用户的所有访问控制规则,然后添加指定的规则。</summary>
 /// <param name="rule">要相加的 <see cref="T:System.Security.AccessControl.EventWaitHandleAccessRule" />。由此规则指定的用户确定在添加此规则之前要移除的规则。</param>
 /// <exception cref="T:System.ArgumentNullException">
 /// <paramref name="rule" /> 为 null。</exception>
 public void ResetAccessRule(EventWaitHandleAccessRule rule)
 {
     this.ResetAccessRule((AccessRule)rule);
 }
Exemple #34
0
 public void ResetAccessRule(EventWaitHandleAccessRule rule)
 {
     base.ResetAccessRule(rule);
 }
		public void AddAccessRule (EventWaitHandleAccessRule rule)
		{
			AddAccessRule ((AccessRule)rule);
		}
Exemple #36
0
 public void RemoveAccessRuleAll(EventWaitHandleAccessRule rule)
 {
     base.RemoveAccessRuleAll(rule);
 }
		public bool RemoveAccessRule (EventWaitHandleAccessRule rule)
		{
			return RemoveAccessRule ((AccessRule)rule);
		}
 public bool RemoveAccessRule(EventWaitHandleAccessRule rule)
 {
   return default(bool);
 }
		public void ResetAccessRule (EventWaitHandleAccessRule rule)
		{
			ResetAccessRule ((AccessRule)rule);
		}
 public void RemoveAccessRuleSpecific(EventWaitHandleAccessRule rule)
 {
 }
 public bool RemoveAccessRule(EventWaitHandleAccessRule rule)
 {
     throw new NotImplementedException();
 }
    public TvServiceThread()
    {
      // set working dir from application.exe
      string applicationPath = Application.ExecutablePath;
      applicationPath = System.IO.Path.GetFullPath(applicationPath);
      applicationPath = System.IO.Path.GetDirectoryName(applicationPath);
      System.IO.Directory.SetCurrentDirectory(applicationPath);

      _powerEventHandlers = new List<PowerEventHandler>();
      GlobalServiceProvider.Instance.Add<IPowerEventHandler>(this);
      AddPowerEventHandler(OnPowerEventHandler);
      try
      {
        Log.Debug("Setting up EventWaitHandle with name: {0}", RemoteControl.InitializedEventName);

        EventWaitHandleAccessRule rule =
          new EventWaitHandleAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null),
                                        EventWaitHandleRights.FullControl, AccessControlType.Allow);
        EventWaitHandleSecurity sec = new EventWaitHandleSecurity();
        sec.AddAccessRule(rule);
        bool eventCreated;
        _InitializedEvent = new EventWaitHandle(false, EventResetMode.ManualReset, RemoteControl.InitializedEventName,
                                                out eventCreated, sec);
        if (!eventCreated)
        {
          Log.Info("{0} was not created", RemoteControl.InitializedEventName);
        }
      }
      catch (Exception ex)
      {
        Log.Write(ex);
      }
      // setup the remoting channels
      try
      {
        string remotingFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
        // process the remoting configuration file
        RemotingConfiguration.Configure(remotingFile, false);
      }
      catch (Exception ex)
      {
        Log.Write(ex);
      }
    }
 public void RemoveAccessRuleSpecific(EventWaitHandleAccessRule rule)
 {
     throw new NotImplementedException();
 }