public void Intersect_Null()
        {
            EventLogPermission elp = new EventLogPermission(PermissionState.None);

            // No intersection with null
            Assert.IsNull(elp.Intersect(null), "None N null");
        }
示例#2
0
        internal CEventLogPermDialog(EventLogPermission perm)
        {
            this.Text = CResourceStore.GetString("EventLogPermission:PermName");

            m_PermControls = new CEventLogPermControls(perm, this);
            Init();
        } // CEventLogPermDialog
 public static EventLogPermission GetEventLogPermission() {
     EventLogPermission logPermission = new EventLogPermission();
     EventLogPermissionEntry permEntry =
             new EventLogPermissionEntry(EventLogPermissionAccess.Administer, ".");
     logPermission.PermissionEntries.Add(permEntry);
     return logPermission;
 }
示例#4
0
        public static void WriteEvent(string sourceName, string eventMessage, int eventType, int eventID)
        {
            if (!System.Diagnostics.EventLog.SourceExists(sourceName))
            {
                EventSourceCreationData SourceData = new EventSourceCreationData("", "");
                SourceData.LogName     = _logName;
                SourceData.MachineName = ".";
                SourceData.Source      = sourceName;
                System.Diagnostics.EventLog.CreateEventSource(SourceData);

                EventLogPermission eventLogPerm = new EventLogPermission(EventLogPermissionAccess.Administer, ".");
                eventLogPerm.PermitOnly();
            }
            System.Diagnostics.EventLogEntryType type = (System.Diagnostics.EventLogEntryType)eventType;

            while (true)
            {
                int logMaxLength = 31000;   // Log entry string written to the event log cannot exceed 32766 characters

                if (eventMessage.Length <= logMaxLength)
                {
                    EventLog.WriteEntry(sourceName, eventMessage, type, eventID);
                    break;
                }
                else
                {
                    EventLog.WriteEntry(sourceName, eventMessage.Substring(0, logMaxLength), type, eventID);
                    eventMessage = eventMessage.Substring(logMaxLength, eventMessage.Length - logMaxLength);
                }
            }
        }
        public IEnumerable <EventLogEntry> GetEntries()
        {
            EventLogPermission evtPermission = new EventLogPermission(EventLogPermissionAccess.Administer, MachineName);

            evtPermission.Demand();
            return(Log?.Entries.Cast <EventLogEntry>().Where(evt => evt.Source == SourceName));
        }
        public void PermissionState_Bad()
        {
            PermissionState    ps  = (PermissionState)77;
            EventLogPermission elp = new EventLogPermission(ps);

            Assert.IsFalse(elp.IsUnrestricted(), "IsUnrestricted");
        }
        public void EventLogPermissionAccesss_Bad()
        {
            EventLogPermissionAccess elpa = (EventLogPermissionAccess)Int32.MinValue;
            EventLogPermission       elp  = new EventLogPermission(elpa, "localhost");

            Assert.AreEqual(1, elp.PermissionEntries.Count, "Count");
            Assert.AreEqual((EventLogPermissionAccess)Int32.MinValue, elp.PermissionEntries [0].PermissionAccess, "PermissionAccess");
        }
        public static EventLogPermission GetEventLogPermission()
        {
            EventLogPermission      permission = new EventLogPermission();
            EventLogPermissionEntry entry      = new EventLogPermissionEntry(EventLogPermissionAccess.Administer, ".");

            permission.PermissionEntries.Add(entry);
            return(permission);
        }
 public void IsSubset_Self()
 {
     foreach (EventLogPermissionAccess elpa in AllAccess)
     {
         EventLogPermission elp = new EventLogPermission(PermissionState.None);
         elp.PermissionEntries.Add(new EventLogPermissionEntry(elpa, elpa.ToString()));
         Assert.IsTrue(elp.IsSubsetOf(elp), elpa.ToString());
     }
 }
        public void FromXml_WrongVersion()
        {
            EventLogPermission elp = new EventLogPermission(PermissionState.None);
            SecurityElement    se  = elp.ToXml();

            se.Attributes.Remove("version");
            se.Attributes.Add("version", "2");
            elp.FromXml(se);
        }
        public void FromXml_WrongTagCase()
        {
            EventLogPermission elp = new EventLogPermission(PermissionState.None);
            SecurityElement    se  = elp.ToXml();

            se.Tag = "IPERMISSION"; // instead of IPermission
            elp.FromXml(se);
            // note: normally IPermission classes (in corlib) DO care about the
            // IPermission tag
        }
        public void Union_Null()
        {
            EventLogPermission elp = new EventLogPermission(PermissionState.None);

            elp.PermissionEntries.Add(new EventLogPermissionEntry(EventLogPermissionAccess.None, "localhost"));
            // Union with null is a simple copy
            EventLogPermission union = (EventLogPermission)elp.Union(null);

            Assert.IsNotNull(elp.PermissionEntries.Count, "Count");
        }
        public void FromXml_NoVersion()
        {
            EventLogPermission elp = new EventLogPermission(PermissionState.None);
            SecurityElement    se  = elp.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("class", se.Attribute("class"));
            elp.FromXml(w);
        }
        public void IsSubset_Null()
        {
            EventLogPermission elp = new EventLogPermission(PermissionState.None);

#if NET_2_0
            Assert.IsTrue(elp.IsSubsetOf(null), "null");
#else
            Assert.IsFalse(elp.IsSubsetOf(null), "null");
#endif
        }
        public void ClearLog()
        {
            EventLogPermission evtPermission = new EventLogPermission(EventLogPermissionAccess.Administer, MachineName);

            evtPermission.Demand();
            if (!IsNonCustomLog())
            {
                Log?.Clear();
            }
        }
示例#16
0
        internal CEventLogPermControls(IPermission perm, Object oParent) : base(perm, oParent)
        {
            // If they don't have a permission for this permission set, we will
            // feed our property page a 'none' permission state.

            if (perm == null)
            {
                m_perm = new EventLogPermission(PermissionState.None);
            }
        }// CEventLogPermControls
 public void Union_Self()
 {
     foreach (EventLogPermissionAccess elpa in AllAccess)
     {
         EventLogPermission elp = new EventLogPermission(PermissionState.None);
         elp.PermissionEntries.Add(new EventLogPermissionEntry(elpa, elpa.ToString()));
         EventLogPermission union = (EventLogPermission)elp.Union(elp);
         Assert.IsFalse(union.IsUnrestricted(), "IsUnrestricted " + elpa.ToString());
         Assert.AreEqual(1, union.PermissionEntries.Count, "Count " + elpa.ToString());
     }
 }
        public void WriteToLog(string message, EventLogEntryType type, CategoryType category, EventIDType eventID, byte[] rawData)
        {
            if (Log == null)
            {
                throw (new ArgumentNullException(nameof(Log), "This Event Log has not been opened or has been closed."));
            }
            EventLogPermission evtPermission = new EventLogPermission(EventLogPermissionAccess.Write, MachineName);

            evtPermission.Demand();
            Log.WriteEntry(message, type, (int)eventID, (short)category, rawData);
        }
        public void FromXml_NoClass()
        {
            EventLogPermission elp = new EventLogPermission(PermissionState.None);
            SecurityElement    se  = elp.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("version", se.Attribute("version"));
            elp.FromXml(w);
            // doesn't even care of the class attribute presence
        }
 public void Copy()
 {
     foreach (EventLogPermissionAccess elpa in AllAccess)
     {
         EventLogPermission      elp  = new EventLogPermission(PermissionState.None);
         EventLogPermissionEntry elpe = new EventLogPermissionEntry(elpa, elpa.ToString());
         elp.PermissionEntries.Add(elpe);
         EventLogPermission copy = (EventLogPermission)elp.Copy();
         Assert.AreEqual(1, copy.PermissionEntries.Count, "Count==1");
         Assert.AreEqual(elpa, elp.PermissionEntries [0].PermissionAccess, elpa.ToString());
     }
 }
        public void Default()
        {
            EventLogPermissionAttribute a = new EventLogPermissionAttribute(SecurityAction.Assert);

            Assert.AreEqual(a.ToString(), a.TypeId.ToString(), "TypeId");
            Assert.IsFalse(a.Unrestricted, "Unrestricted");
            Assert.AreEqual(".", a.MachineName, "MachineName");
            Assert.AreEqual(EventLogPermissionAccess.Write, a.PermissionAccess, "PermissionAccess");
            EventLogPermission sp = (EventLogPermission)a.CreatePermission();

            Assert.IsFalse(sp.IsUnrestricted(), "IsUnrestricted");
        }
        public void Unrestricted()
        {
            EventLogPermissionAttribute a = new EventLogPermissionAttribute(SecurityAction.Assert);

            a.Unrestricted = true;
            EventLogPermission wp = (EventLogPermission)a.CreatePermission();

            Assert.IsTrue(wp.IsUnrestricted(), "IsUnrestricted");

            a.Unrestricted = false;
            wp             = (EventLogPermission)a.CreatePermission();
            Assert.IsFalse(wp.IsUnrestricted(), "!IsUnrestricted");
        }
        public void FromXml_WrongClass()
        {
            EventLogPermission elp = new EventLogPermission(PermissionState.None);
            SecurityElement    se  = elp.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("class", "Wrong" + se.Attribute("class"));
            w.AddAttribute("version", se.Attribute("version"));
            elp.FromXml(w);
            // doesn't care of the class name at that stage
            // anyway the class has already be created so...
        }
示例#24
0
        }// CreateDataTable

        protected override void PutValuesinPage()
        {
            // Put in the text for the radio buttons
            m_radUnrestricted.Text             = CResourceStore.GetString("EventLogPermission:GrantUnrestrict");
            m_radGrantFollowingPermission.Text = CResourceStore.GetString("EventLogPermission:GrantFollowing");


            EventLogPermission perm = (EventLogPermission)m_perm;

            CheckUnrestricted(perm);

            if (!perm.IsUnrestricted())
            {
                // Run through the list of socket permissions we have to accept connections
                IEnumerator enumer = perm.PermissionEntries.GetEnumerator();
                while (enumer.MoveNext())
                {
                    EventLogPermissionEntry elpp = (EventLogPermissionEntry)enumer.Current;
                    DataRow newRow;
                    newRow = m_dt.NewRow();

                    newRow["Machine"] = elpp.MachineName;

                    String sAccess = CResourceStore.GetString("None");
                    if ((elpp.PermissionAccess & EventLogPermissionAccess.Audit) == EventLogPermissionAccess.Audit)
                    {
                        sAccess = CResourceStore.GetString("EventLogPermission:Audit");
                    }
                    else if ((elpp.PermissionAccess & EventLogPermissionAccess.Instrument) == EventLogPermissionAccess.Instrument)
                    {
                        sAccess = CResourceStore.GetString("EventLogPermission:Instrument");
                    }
                    else if ((elpp.PermissionAccess & EventLogPermissionAccess.Browse) == EventLogPermissionAccess.Browse)
                    {
                        sAccess = CResourceStore.GetString("EventLogPermission:Browse");
                    }

                    newRow["Access"] = new DataGridComboBoxEntry(sAccess);


                    m_dt.Rows.Add(newRow);
                }
            }

            // We want at least 1 row so it looks pretty
            while (m_dt.Rows.Count < 1)
            {
                AddEmptyRow(m_dt);
            }
        }// PutValuesinPage
        public void IsSubset_None()
        {
            // IsSubset with none
            // a. source (this) is none -> target is never a subset
            // b. destination (target) is none -> target is always a subset
            EventLogPermission elp1 = new EventLogPermission(PermissionState.None);

            foreach (EventLogPermissionAccess elpa in AllAccess)
            {
                EventLogPermission elp2 = new EventLogPermission(PermissionState.None);
                elp2.PermissionEntries.Add(new EventLogPermissionEntry(elpa, elpa.ToString()));
                Assert.IsTrue(elp1.IsSubsetOf(elp2), "target " + elpa.ToString());
                Assert.IsFalse(elp2.IsSubsetOf(elp1), "source " + elpa.ToString());
            }
        }
        public void Intersect_None()
        {
            EventLogPermission elp1 = new EventLogPermission(PermissionState.None);
            EventLogPermission elp2 = new EventLogPermission(PermissionState.None);
            // 1. None N None
            EventLogPermission result = (EventLogPermission)elp1.Intersect(elp2);

            Assert.IsNull(result, "Empty N Empty");
            // 2. None N Entry
            elp2.PermissionEntries.Add(new EventLogPermissionEntry(EventLogPermissionAccess.None, "localhost"));
            result = (EventLogPermission)elp1.Intersect(elp2);
            Assert.IsNull(result, "Empty N Entry");
            // 3. Entry N None
            result = (EventLogPermission)elp2.Intersect(elp1);
            Assert.IsNull(result, "Entry N Empty");
        }
        public void Union_None()
        {
            EventLogPermission elp1 = new EventLogPermission(PermissionState.None);

            foreach (EventLogPermissionAccess elpa in AllAccess)
            {
                EventLogPermission elp2 = new EventLogPermission(PermissionState.None);
                elp2.PermissionEntries.Add(new EventLogPermissionEntry(elpa, elpa.ToString()));
                EventLogPermission union = (EventLogPermission)elp1.Union(elp2);
                Assert.IsFalse(union.IsUnrestricted(), "target.IsUnrestricted " + elpa.ToString());
                Assert.AreEqual(1, union.PermissionEntries.Count, "target.Count " + elpa.ToString());

                union = (EventLogPermission)elp2.Union(elp1);
                Assert.IsFalse(union.IsUnrestricted(), "source.IsUnrestricted " + elpa.ToString());
                Assert.AreEqual(1, union.PermissionEntries.Count, "source.Count " + elpa.ToString());
            }
        }
示例#28
0
        public void WriteToLog(string message, EventLogEntryType type,
                               CategoryType category, EventIDType eventID)
        {
            if (Log == null)
            {
                throw new ArgumentNullException(nameof(Log),
                                                "This Event Log has not been opened or has been closed.");
            }

            EventLogPermission eventLogPermission =
                new EventLogPermission(EventLogPermissionAccess.Write, MachineName);

            eventLogPermission.Demand();

            // If you get a SecurityException here, see the notes at the
            // top of the class
            Log.WriteEntry(message, type, (int)eventID, (short)category);
        }
示例#29
0
        private static void DeleteEventLogSource(string serviceName, string machineName)
        {
            if (!EventLog.SourceExists(serviceName))
            {
                return;
            }
            try
            {
                var permission = new EventLogPermission(EventLogPermissionAccess.Administer, machineName);
                permission.Assert();

                EventLog.DeleteEventSource(serviceName, machineName);
            }
            catch (Exception e)
            {
                Log.Error(e, e.Message);
            }
        }
示例#30
0
        }// AddEmptyRow

        internal override IPermission GetCurrentPermission()
        {
            // Change cells so we get data committed to the grid
            m_dg.CurrentCell = new DataGridCell(0, 1);
            m_dg.CurrentCell = new DataGridCell(0, 0);

            EventLogPermission perm = null;

            if (m_radUnrestricted.Checked == true)
            {
                perm = new EventLogPermission(PermissionState.Unrestricted);
            }
            else
            {
                perm = new EventLogPermission(PermissionState.None);
                for (int i = 0; i < m_dt.Rows.Count; i++)
                {
                    // Make sure we have a socket permission to add
                    if (m_dg[i, 0] is String && ((String)m_dg[i, 0]).Length > 0)
                    {
                        String sName = (String)m_dg[i, 0];

                        EventLogPermissionAccess elpa = EventLogPermissionAccess.None;

                        if (((String)m_dg[i, 1]).Equals(CResourceStore.GetString("EventLogPermission:Browse")))
                        {
                            elpa |= EventLogPermissionAccess.Browse;
                        }
                        else if (((String)m_dg[i, 1]).Equals(CResourceStore.GetString("EventLogPermission:Instrument")))
                        {
                            elpa |= EventLogPermissionAccess.Instrument;
                        }
                        else if (((String)m_dg[i, 1]).Equals(CResourceStore.GetString("EventLogPermission:Audit")))
                        {
                            elpa |= EventLogPermissionAccess.Audit;
                        }

                        perm.PermissionEntries.Add(new EventLogPermissionEntry(elpa, sName));
                    }
                }
            }
            return(perm);
        }// GetCurrentPermission
        public void PermissionState_Unrestricted()
        {
            PermissionState    ps  = PermissionState.Unrestricted;
            EventLogPermission elp = new EventLogPermission(ps);

            Assert.AreEqual(0, elp.PermissionEntries.Count, "PermissionEntries");
            Assert.IsTrue(elp.IsUnrestricted(), "IsUnrestricted");

            SecurityElement se = elp.ToXml();

            // only class and version are present
            Assert.AreEqual("true", se.Attribute("Unrestricted"), "Xml-Unrestricted");
            Assert.IsNull(se.Children, "Xml-Children");

            EventLogPermission copy = (EventLogPermission)elp.Copy();

            Assert.IsFalse(Object.ReferenceEquals(elp, copy), "ReferenceEquals");
            Assert.AreEqual(elp.PermissionEntries.Count, copy.PermissionEntries.Count, "copy-PermissionEntries");
            Assert.AreEqual(elp.IsUnrestricted(), copy.IsUnrestricted(), "copy-IsUnrestricted ()");
        }