Exemple #1
0
        public override bool HandleMembership()
        {
            var request    = Request;
            var parameters = request.Parameters;
            var typeCode   = Request.TypeCode();

            if (typeCode == SnmpType.Unknown)
            {
                HandleFailure(Group.DecryptionError);
                return(false);
            }

            if (typeCode != SnmpType.TrapV2Pdu && parameters.EngineId != Group.EngineId)
            {
                HandleDiscovery();
                return(true);
            }

            var user = Users.Find(parameters.UserName);

            if (user == null)
            {
                HandleFailure(Group.UnknownSecurityName);
                return(false);
            }

            if (typeCode == SnmpType.TrapV2Pdu && (user.EngineIds == null || !user.EngineIds.Contains(parameters.EngineId)))
            {
                HandleFailure(Group.UnknownEngineId);
                return(false);
            }

            if (parameters.IsInvalid)
            {
                HandleFailure(Group.AuthenticationFailure);
                return(false);
            }

            if (typeCode == SnmpType.TrapV2Pdu)
            {
                return(true);
            }

            if ((user.ToSecurityLevel() | Levels.Reportable) != request.Header.SecurityLevel)
            {
                HandleFailure(Group.UnsupportedSecurityLevel);
                return(false);
            }

            var inTime = EngineGroup.IsInTime(Group.EngineTimeData, parameters.EngineBoots.ToInt32(), parameters.EngineTime.ToInt32());

            if (!inTime)
            {
                HandleFailure(Group.NotInTimeWindow);
                return(false);
            }

            return(true);
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SnmpContextBase"/> class.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="users">The users.</param>
 /// <param name="group">The engine core group.</param>
 /// <param name="binding">The binding.</param>
 protected SnmpContextBase(ISnmpMessage request, IPEndPoint sender, UserRegistry users, EngineGroup group, IListenerBinding binding)
 {
     Request = request;
     Binding = binding;
     Users = users;
     Sender = sender;
     CreatedTime = DateTime.Now;
     Group = group;
 }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SnmpContextBase"/> class.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="users">The users.</param>
 /// <param name="group">The engine core group.</param>
 /// <param name="binding">The binding.</param>
 protected SnmpContextBase(ISnmpMessage request, IPEndPoint sender, UserRegistry users, EngineGroup group, IListenerBinding binding)
 {
     Request     = request;
     Binding     = binding;
     Users       = users;
     Sender      = sender;
     CreatedTime = DateTime.Now;
     Group       = group;
 }
        /// <summary>
        /// Creates the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="sender">The sender.</param>
        /// <param name="users">The users.</param>
        /// <param name="group">The engine group.</param>
        /// <param name="binding">The binding.</param>
        /// <returns></returns>
        public static SnmpContext Create(ISnmpMessage request, IPEndPoint sender, UserRegistry users, EngineGroup group, IListenerBinding binding)
        {
            if (request.Version == VersionCode.V3)
            {
                return new SecureSnmpContext(request, sender, users, group, binding);
            }

            return new NormalSnmpContext(request, sender, users, binding);
        }
        /// <summary>
        /// Handles the membership.
        /// </summary>
        /// <returns></returns>
        public override bool HandleMembership()
        {
            var request = Request;
            var parameters = request.Parameters;
            var typeCode = Request.TypeCode();
            if (parameters.EngineId != Group.EngineId && typeCode != SnmpType.Unknown)
            {
                HandleDiscovery();
                return true;
            }

            var user = Users.Find(parameters.UserName);
            if (user == null) 
            {
                HandleFailure(Group.UnknownSecurityName);
                return false;
            }

            if (typeCode == SnmpType.Unknown)
            {
                HandleFailure(Group.DecryptionError);
                return false;
            }

            if (parameters.IsInvalid)
            {
                HandleFailure(Group.AuthenticationFailure);
                return false;
            }

            if ((user.ToSecurityLevel() | Levels.Reportable) != request.Header.SecurityLevel)
            {
                HandleFailure(Group.UnsupportedSecurityLevel);
                return false;
            }

            // TODO: improve here, so if request's EngineBoots = agent's EngineBoots - 1 we can calculate if it is in time.
            if (parameters.EngineBoots.ToInt32() != Group.EngineBoots)
            {
                HandleFailure(Group.NotInTimeWindow);
                return false;
            }

            var inTime = EngineGroup.IsInTime(Group.EngineTime, parameters.EngineTime.ToInt32());
            if (!inTime)
            {
                HandleFailure(Group.NotInTimeWindow);
                return false;
            }

            return true;
        }
Exemple #6
0
        /// <summary>
        /// Creates the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="sender">The sender.</param>
        /// <param name="users">The users.</param>
        /// <param name="group">The engine group.</param>
        /// <param name="binding">The binding.</param>
        /// <returns></returns>
        public static ISnmpContext Create(ISnmpMessage request, IPEndPoint sender, UserRegistry users, EngineGroup group, IListenerBinding binding)
        {
            if (request.Version == VersionCode.V3)
            {
                return new SecureSnmpContext(request, sender, users, group, binding);
            }

            return new NormalSnmpContext(request, sender, users, binding);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SnmpEngine"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="listener">The listener.</param>
 /// <param name="group">Engine core @group.</param>
 public SnmpEngine(SnmpApplicationFactory factory, Listener listener, EngineGroup @group)
 {
     _factory = factory;
     Listener = listener;
     _group   = group;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SecureSnmpContext"/> class.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="users">The users.</param>
 /// <param name="group">The engine core group.</param>
 /// <param name="binding">The binding.</param>
 public SecureSnmpContext(ISnmpMessage request, IPEndPoint sender, UserRegistry users, EngineGroup group, IListenerBinding binding)
     : base(request, sender, users, group, binding)
 {
 }
Exemple #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SecureSnmpContext"/> class.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="users">The users.</param>
 /// <param name="group">The engine core group.</param>
 /// <param name="binding">The binding.</param>
 public SecureSnmpContext(ISnmpMessage request, IPEndPoint sender, UserRegistry users, EngineGroup group, IListenerBinding binding)
     : base(request, sender, users, group, binding)
 {
 }
Exemple #10
-1
 /// <summary>
 /// Initializes a new instance of the <see cref="SnmpEngine"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="listener">The listener.</param>
 /// <param name="group">Engine core group.</param>
 public SnmpEngine(SnmpApplicationFactory factory, Listener listener, EngineGroup group)
 {
     _factory = factory;
     Listener = listener;
     _group = group;
 }