Beispiel #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);
        }
        /// <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;
        }