dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System/Diagnostics EventLogPermissio


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System/Diagnostics EventLogPermission.cs,NONE,1.1 EventLogPermissionAttribute.cs,NONE,1.1EventLogPermissionEntry.cs,NONE,1.1 EventLogPermissionEntryCollection.cs,NONE,1.1 DefaultTraceListener.cs,1.1,1.2
Date: Sat, 12 Apr 2003 02:27:21 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System/Diagnostics
In directory subversions:/tmp/cvs-serv27106/System/Diagnostics

Modified Files:
        DefaultTraceListener.cs 
Added Files:
        EventLogPermission.cs EventLogPermissionAttribute.cs 
        EventLogPermissionEntry.cs 
        EventLogPermissionEntryCollection.cs 
Log Message:


Implement event log permission classes; exit when assertions fail.


--- NEW FILE ---
/*
 * EventLogPermission.cs - Implementation of the
 *                      "System.Diagnostics.EventLogPermission" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Diagnostics
{

#if !ECMA_COMPAT

using System.Security.Permissions;

[Serializable]
public class EventLogPermission : ResourcePermissionBase
{
        // Constructors.
        public EventLogPermission() : this(PermissionState.None) {}
        public EventLogPermission(PermissionState state)
                        : base(state)
                        {
                                PermissionAccessType = 
typeof(EventLogPermissionAccess);
                                TagNames = new String [] {"Machine"};
                        }
        public EventLogPermission
                                (EventLogPermissionEntry[] 
permissionAccessEntries)
                        : this(PermissionState.None)
                        {
                                foreach(EventLogPermissionEntry entry in
                                                        permissionAccessEntries)
                                {
                                        
AddPermissionAccess(entry.ToResourceEntry());
                                }
                        }
        public EventLogPermission
                                (EventLogPermissionAccess access, String 
machineName)
                        : this(PermissionState.None)
                        {
                                AddPermissionAccess
                                        (new EventLogPermissionEntry(access, 
machineName)
                                                .ToResourceEntry());
                        }

        // Get the permission entries in this collection.
        public EventLogPermissionEntryCollection PermissionEntries
                        {
                                get
                                {
                                        EventLogPermissionEntryCollection coll;
                                        coll = new 
EventLogPermissionEntryCollection(this);
                                        ResourcePermissionBaseEntry[] entries;
                                        entries = GetPermissionEntries();
                                        
foreach(EventLogPermissionEntry.EventLogResourceEntry
                                                                entry in 
entries)
                                        {
                                                coll.AddDirect(entry.ToEntry());
                                        }
                                        return coll;
                                }
                        }

        // Helper methods for "EventLogPermissionEntryCollection".
        internal new void Clear()
                        {
                                base.Clear();
                        }
        internal void Add(EventLogPermissionEntry entry)
                        {
                                AddPermissionAccess(entry.ToResourceEntry());
                        }
        internal void Remove(EventLogPermissionEntry entry)
                        {
                                RemovePermissionAccess(entry.ToResourceEntry());
                        }

}; // class EventLogPermission

#endif // !ECMA_COMPAT

}; // namespace System.Diagnostics

--- NEW FILE ---
/*
 * EventLogPermissionAttribute.cs - Implementation of the
 *                      "System.Diagnostics.EventLogPermissionAttribute" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Diagnostics
{

#if !ECMA_COMPAT

using System.Security;
using System.Security.Permissions;

[Serializable]
[AttributeUsage(AttributeTargets.Assembly |
                                AttributeTargets.Class |
                                AttributeTargets.Struct |
                                AttributeTargets.Constructor |
                                AttributeTargets.Method |
                                AttributeTargets.Event)]
public class EventLogPermissionAttribute : CodeAccessSecurityAttribute
{
        // Internal state.
        private String machineName;
        private EventLogPermissionAccess permissionAccess;

        // Constructors.
        public EventLogPermissionAttribute(SecurityAction action)
                        : base(action)
                        {
                                machineName = ".";
                                permissionAccess = 
EventLogPermissionAccess.Browse;
                        }

        // Get or set the attribute's properties.
        public String MachineName
                        {
                                get
                                {
                                        return machineName;
                                }
                                set
                                {
                                        if(value == null)
                                        {
                                                throw new 
ArgumentNullException("value");
                                        }
                                        machineName = value;
                                }
                        }
        public EventLogPermissionAccess PermissionAccess
                        {
                                get
                                {
                                        return permissionAccess;
                                }
                                set
                                {
                                        permissionAccess = value;
                                }
                        }

        // Create a permission object from this attribute.
        public override IPermission CreatePermission()
                        {
                                if(Unrestricted)
                                {
                                        return new EventLogPermission
                                                (PermissionState.Unrestricted);
                                }
                                else
                                {
                                        return new EventLogPermission
                                                (permissionAccess, machineName);
                                }
                        }

}; // class EventLogPermissionAttribute

#endif // !ECMA_COMPAT

}; // namespace System.Diagnostics

--- NEW FILE ---
/*
 * EventLogPermissionEntry.cs - Implementation of the
 *                      "System.Diagnostics.EventLogPermissionEntry" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Diagnostics
{

#if !ECMA_COMPAT

using System.Security.Permissions;

[Serializable]
public class EventLogPermissionEntry
{
        // Internal state.
        private EventLogPermissionAccess access;
        private String machineName;
        private EventLogResourceEntry resourceEntry;

        // Constructor.
        public EventLogPermissionEntry(EventLogPermissionAccess access,
                                                                   String 
machineName)
                        {
                                this.access = access;
                                this.machineName = machineName;
                                resourceEntry = new EventLogResourceEntry
                                        (this, (int)access, new String [] 
{machineName});
                        }

        // Get this object's properties.
        public String MachineName
                        {
                                get
                                {
                                        return machineName;
                                }
                        }
        public EventLogPermissionAccess PermissionAccess
                        {
                                get
                                {
                                        return access;
                                }
                        }

        // Convert this object into a resource entry.
        internal ResourcePermissionBaseEntry ToResourceEntry()
                        {
                                return resourceEntry;
                        }

        // Resource wrapper class.
        internal class EventLogResourceEntry : ResourcePermissionBaseEntry
        {
                // Internal state.
                private EventLogPermissionEntry entry;

                // Constructor.
                public EventLogResourceEntry(EventLogPermissionEntry entry,
                                                                         int 
access, String[] path)
                                : base(access, path)
                                {
                                        this.entry = entry;
                                }

                // Convert this object into an event log permission entry.
                public EventLogPermissionEntry ToEntry()
                                {
                                        return entry;
                                }

        }; // class EventLogResourceEntry

}; // class EventLogPermissionEntry

#endif // !ECMA_COMPAT

}; // namespace System.Diagnostics

--- NEW FILE ---
/*
 * EventLogPermissionEntryCollection.cs - Implementation of the
 *                      "System.Diagnostics.EventLogPermissionEntryCollection" 
class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Diagnostics
{

#if !ECMA_COMPAT

using System.Collections;

[Serializable]
public class EventLogPermissionEntryCollection : CollectionBase
{
        // Internal state.
        private EventLogPermission perm;

        // Constructor.
        internal EventLogPermissionEntryCollection(EventLogPermission perm)
                        {
                                this.perm = perm;
                        }

        // Get or set a collection member.
        public EventLogPermissionEntry this[int index]
                        {
                                get
                                {
                                        return 
(EventLogPermissionEntry)(((IList)this)[index]);
                                }
                                set
                                {
                                        ((IList)this)[index] = value;
                                }
                        }

        // Add an element to this collection.
        public int Add(EventLogPermissionEntry value)
                        {
                                return ((IList)this).Add(value);
                        }
        internal void AddDirect(EventLogPermissionEntry value)
                        {
                                InnerList.Add(value);
                        }

        // Add a range of elements to this collection.
        public void AddRange(EventLogPermissionEntry[] value)
                        {
                                if(value == null)
                                {
                                        throw new 
ArgumentNullException("value");
                                }
                                foreach(EventLogPermissionEntry val in value)
                                {
                                        Add(val);
                                }
                        }
        public void AddRange(EventLogPermissionEntryCollection value)
                        {
                                if(value == null)
                                {
                                        throw new 
ArgumentNullException("value");
                                }
                                foreach(EventLogPermissionEntry val in value)
                                {
                                        Add(val);
                                }
                        }

        // Determine if an item exists in this collection.
        public bool Contains(EventLogPermissionEntry value)
                        {
                                return ((IList)this).Contains(value);
                        }

        // Copy the elements in this collection to an array.
        public void CopyTo(EventLogPermissionEntry[] array, int index)
                        {
                                ((IList)this).CopyTo(array, index);
                        }

        // Get the index of a specific element in this collection.
        public int IndexOf(EventLogPermissionEntry value)
                        {
                                return ((IList)this).IndexOf(value);
                        }

        // Insert an element into this collection.
        public void Insert(int index, EventLogPermissionEntry value)
                        {
                                ((IList)this).Insert(index, value);
                        }

        // Remove an element from this collection.
        public virtual void Remove(EventLogPermissionEntry value)
                        {
                                ((IList)this).Remove(value);
                        }

        // Detect when the collection is cleared.
        protected override void OnClear()
                        {
                                perm.Clear();
                        }

        // Detect when an item is inserted.
        protected override void OnInsert(int index, Object value)
                        {
                                perm.Add((EventLogPermissionEntry)value);
                        }

        // Detect when an item is removed.
        protected override void OnRemove(int index, Object value)
                        {
                                perm.Remove((EventLogPermissionEntry)value);
                        }

        // Detect when an item is changed.
        protected override void OnSet(int index, Object oldValue, Object 
newValue)
                        {
                                perm.Remove((EventLogPermissionEntry)oldValue);
                                perm.Add((EventLogPermissionEntry)newValue);
                        }

}; // class EventLogPermissionEntryCollection

#endif // !ECMA_COMPAT

}; // namespace System.Diagnostics

Index: DefaultTraceListener.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System/Diagnostics/DefaultTraceListener.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** DefaultTraceListener.cs     11 Apr 2003 07:52:38 -0000      1.1
--- DefaultTraceListener.cs     12 Apr 2003 06:27:19 -0000      1.2
***************
*** 108,111 ****
--- 108,114 ----
                                        Write(trace);
                                }
+ 
+                               // Exit from the application after reporting 
the failure.
+                               Environment.Exit(1);
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]