示例#1
0
        public void Handle(SnmpContext context, ObjectStore store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            int index = 0;
            IList <Variable> result = new List <Variable>();

            foreach (Variable v in context.Request.Pdu.Variables)
            {
                index++;
                try
                {
                    ScalarObject next = store.GetNextObject(v.Id);
                    result.Add(next == null ? new Variable(v.Id, new EndOfMibView()) : next.Variable);
                }
                catch (Exception)
                {
                    context.CopyRequest(ErrorCode.GenError, index);
                    return;
                }
            }

            context.GenerateResponse(result);
        }
        public void Handle(SnmpContext context, ObjectStore store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            
            int index = 0;
            IList<Variable> result = new List<Variable>();
            foreach (Variable v in context.Request.Pdu.Variables)
            {
                index++;
                try
                {
                    ScalarObject next = store.GetNextObject(v.Id);
                    result.Add(next == null ? new Variable(v.Id, new EndOfMibView()) : next.Variable);
                }
                catch (Exception)
                {
                    context.CopyRequest(ErrorCode.GenError, index);
                    return;
                }
            }

            context.GenerateResponse(result);
        }
 public void Log(SnmpContext context)
 {
     if (Logger.IsInfoEnabled)
     {
         Logger.Info(GetLogEntry(context));
     }
 }
示例#4
0
        private void ListenerMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            ISnmpMessage    request     = e.Message;
            SnmpContext     context     = SnmpContextFactory.Create(request, e.Sender, Listener.Users, _group, e.Binding);
            SnmpApplication application = _factory.Create(context);

            application.Process();
        }
 /// <summary>
 /// Authenticates the request.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public bool AuthenticateRequest(SnmpContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     
     return context.Request.Version == Version && context.HandleMembership();
 }
        /// <summary>
        /// Authenticates the request.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public bool AuthenticateRequest(SnmpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            return(context.Request.Version == Version && context.HandleMembership());
        }
示例#7
0
        public void Handle(SnmpContext context, ObjectStore store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            int       index  = 0;
            ErrorCode status = ErrorCode.NoError;

            IList <Variable> result = new List <Variable>();

            foreach (Variable v in context.Request.Pdu.Variables)
            {
                index++;
                ScalarObject obj = store.GetObject(v.Id);
                if (obj != null)
                {
                    try
                    {
                        obj.Data = v.Data;
                    }
                    catch (AccessFailureException)
                    {
                        status = ErrorCode.NoSuchName;
                    }
                    catch (ArgumentException)
                    {
                        status = ErrorCode.BadValue;
                    }
                    catch (Exception)
                    {
                        status = ErrorCode.GenError;
                    }
                }
                else
                {
                    status = ErrorCode.NoSuchName;
                }

                if (status != ErrorCode.NoError)
                {
                    context.CopyRequest(status, index);
                    return;
                }

                result.Add(v);
            }

            context.GenerateResponse(result);
        }
        public void Handle(SnmpContext context, ObjectStore store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            
            int index = 0;
            ErrorCode status = ErrorCode.NoError;

            IList<Variable> result = new List<Variable>();
            foreach (Variable v in context.Request.Pdu.Variables)
            {
                index++;
                ScalarObject obj = store.GetObject(v.Id);
                if (obj != null)
                {
                    try
                    {
                        obj.Data = v.Data;
                    }
                    catch (AccessFailureException)
                    {
                        status = ErrorCode.NoSuchName;
                    }
                    catch (ArgumentException)
                    {
                        status = ErrorCode.BadValue;
                    }
                    catch (Exception)
                    {
                        status = ErrorCode.GenError;
                    }
                }
                else
                {
                    status = ErrorCode.NoSuchName;
                }

                if (status != ErrorCode.NoError)
                {
                    context.CopyRequest(status, index);
                    return;
                }

                result.Add(v);
            }

            context.GenerateResponse(result);
        }
        /// <summary>
        /// Handles the specified message.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="store">The object store.</param>
        /// <returns></returns>
        public void Handle(SnmpContext context, ObjectStore store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            InvokeMessageReceived(new MessageReceivedEventArgs <TrapV1Message>(context.Sender, (TrapV1Message)context.Request, context.Binding));
        }
 /// <summary>
 /// Handles the specified message.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="store">The object store.</param>
 /// <returns></returns>
 public void Handle(SnmpContext context, ObjectStore store)
 {
     if (store == null)
     {
         throw new ArgumentNullException("store");
     }
     
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     
     InvokeMessageReceived(new MessageReceivedEventArgs<TrapV2Message>(context.Sender, (TrapV2Message)context.Request, context.Binding));
 }
 /// <summary>
 /// Handles the specified message.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="store">The object store.</param>
 /// <returns></returns>
 public void Handle(SnmpContext context, ObjectStore store)
 {
     if (store == null)
     {
         throw new ArgumentNullException("store");
     }
     
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     
     InvokeMessageReceived(new MessageReceivedEventArgs<InformRequestMessage>(context.Sender, (InformRequestMessage)context.Request, context.Binding));
     context.CopyRequest(ErrorCode.NoError, 0);
 }
示例#12
0
        /// <summary>
        /// Handles the specified message.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="store">The object store.</param>
        /// <returns></returns>
        public void Handle(SnmpContext context, ObjectStore store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            InvokeMessageReceived(new MessageReceivedEventArgs <InformRequestMessage>(context.Sender, (InformRequestMessage)context.Request, context.Binding));
            context.CopyRequest(ErrorCode.NoError, 0);
        }
 private static string GetLogEntry(SnmpContext context)
 {
     return string.Format(
         CultureInfo.InvariantCulture,
         "{0} {1} {2} {3} {4} {5} {6} {7} {8} {9}",
         DateTime.UtcNow,
         context.Binding.Endpoint.Address,
         context.Request.Pdu.TypeCode == SnmpType.Unknown ? Empty : context.Request.Pdu.TypeCode.ToString(),
         GetStem(context.Request.Pdu.Variables),
         context.Binding.Endpoint.Port,
         context.Request.Parameters.UserName,
         context.Sender.Address,
         (context.Response == null) ? Empty : context.Response.Pdu.ErrorStatus.ToErrorCode().ToString(),
         context.Request.Version,
         DateTime.Now.Subtract(context.CreatedTime).TotalMilliseconds);
 }
        public void Handle(SnmpContext context, ObjectStore store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ErrorCode        status = ErrorCode.NoError;
            int              index  = 0;
            IList <Variable> result = new List <Variable>();

            foreach (Variable v in context.Request.Pdu.Variables)
            {
                index++;
                try
                {
                    ScalarObject next = store.GetNextObject(v.Id);
                    if (next == null)
                    {
                        status = ErrorCode.NoSuchName;
                    }
                    else
                    {
                        // TODO: how to handle write only object here?
                        result.Add(next.Variable);
                    }
                }
                catch (Exception)
                {
                    context.CopyRequest(ErrorCode.GenError, index);
                    return;
                }

                if (status != ErrorCode.NoError)
                {
                    context.CopyRequest(status, index);
                    return;
                }
            }

            context.GenerateResponse(result);
        }
        public void Handle(SnmpContext context, ObjectStore store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            
            ErrorCode status = ErrorCode.NoError;
            int index = 0;
            IList<Variable> result = new List<Variable>();
            foreach (Variable v in context.Request.Pdu.Variables)
            {
                index++;
                try
                {
                    ScalarObject next = store.GetNextObject(v.Id);
                    if (next == null)
                    {
                        status = ErrorCode.NoSuchName;
                    }
                    else
                    {
                        // TODO: how to handle write only object here?
                        result.Add(next.Variable);
                    }
                }
                catch (Exception)
                {
                    context.CopyRequest(ErrorCode.GenError, index);
                    return;
                }
                
                if (status != ErrorCode.NoError)
                {
                    context.CopyRequest(status, index);
                    return;
                }
            }

            context.GenerateResponse(result);
        }
        public void Handle(SnmpContext context, ObjectStore store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            int index = 0;
            IList <Variable> result = new List <Variable>();

            foreach (Variable v in context.Request.Pdu.Variables)
            {
                index++;
                try
                {
                    ScalarObject obj = store.GetObject(v.Id);
                    if (obj == null)
                    {
                        result.Add(new Variable(v.Id, new NoSuchInstance()));
                    }
                    else
                    {
                        Variable item = obj.Variable;
                        result.Add(item);
                    }
                }
                catch (AccessFailureException)
                {
                    result.Add(new Variable(v.Id, new NoSuchObject()));
                }
                catch (Exception)
                {
                    context.CopyRequest(ErrorCode.GenError, index);
                    return;
                }
            }

            context.GenerateResponse(result);
        }
        /// <summary>
        /// Creates a pipeline for the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public SnmpApplication Create(SnmpContext context)
        {
            SnmpApplication result = null;
            lock (_root)
            {
                if (_queue.Count > 0)
                {
                    result = _queue.Dequeue();
                }
            }

            if (result == null)
            {
                result = new SnmpApplication(this, _logger, _store, _membershipProvider, _factory);              
            }

            result.Init(context);
            return result;
        }
        public void Handle(SnmpContext context, ObjectStore store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            
            int index = 0;
            IList<Variable> result = new List<Variable>();
            foreach (Variable v in context.Request.Pdu.Variables)
            {
                index++;
                try
                {
                    ScalarObject obj = store.GetObject(v.Id);
                    if (obj == null)
                    {
                        result.Add(new Variable(v.Id, new NoSuchInstance()));
                    }
                    else
                    {
                        Variable item = obj.Variable;
                        result.Add(item);
                    }
                }
                catch (AccessFailureException)
                {
                    result.Add(new Variable(v.Id, new NoSuchObject()));
                }
                catch (Exception)
                {
                    context.CopyRequest(ErrorCode.GenError, index);
                    return;
                }
            }

            context.GenerateResponse(result);
        }
        /// <summary>
        /// Authenticates the request.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public bool AuthenticateRequest(SnmpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            
            if (context.Request.Version != Version)
            {
                return false;
            }

            var parameters = context.Request.Parameters;
            if (context.Request.Pdu.TypeCode == SnmpType.SetRequestPdu)
            {
                return parameters.UserName == _set;
            }

            return parameters.UserName == _get;
        }
示例#20
0
        /// <summary>
        /// Creates a pipeline for the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public SnmpApplication Create(SnmpContext context)
        {
            SnmpApplication result = null;

            lock (_root)
            {
                if (_queue.Count > 0)
                {
                    result = _queue.Dequeue();
                }
            }

            if (result == null)
            {
                result = new SnmpApplication(this, _logger, _store, _membershipProvider, _factory);
            }

            result.Init(context);
            return(result);
        }
        /// <summary>
        /// Authenticates the request.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public bool AuthenticateRequest(SnmpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (context.Request.Version != Version)
            {
                return(false);
            }

            var parameters = context.Request.Parameters;

            if (context.Request.Pdu.TypeCode == SnmpType.SetRequestPdu)
            {
                return(parameters.UserName == _set);
            }

            return(parameters.UserName == _get);
        }
示例#22
0
        public void Handle(SnmpContext context, ObjectStore store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ISnmpPdu         pdu    = context.Request.Pdu;
            IList <Variable> result = new List <Variable>();
            int index        = 0;
            int nonrepeaters = pdu.ErrorStatus.ToInt32();
            var variables    = pdu.Variables;

            for (int i = 0; i < nonrepeaters; i++)
            {
                Variable v = variables[i];
                index++;
                try
                {
                    ScalarObject next = store.GetNextObject(v.Id);
                    result.Add(next == null ? new Variable(v.Id, new EndOfMibView()) : next.Variable);
                }
                catch (Exception)
                {
                    context.CopyRequest(ErrorCode.GenError, index);
                    return;
                }
            }

            for (int j = nonrepeaters; j < variables.Count; j++)
            {
                Variable v = variables[j];
                index++;
                Variable temp       = v;
                int      repetition = pdu.ErrorIndex.ToInt32();
                while (repetition-- > 0)
                {
                    try
                    {
                        ScalarObject next = store.GetNextObject(temp.Id);
                        if (next == null)
                        {
                            temp = new Variable(temp.Id, new EndOfMibView());
                            result.Add(temp);
                            break;
                        }

                        // TODO: how to handle write only object here?
                        result.Add(next.Variable);
                        temp = next.Variable;
                    }
                    catch (Exception)
                    {
                        context.CopyRequest(ErrorCode.GenError, index);
                        return;
                    }
                }
            }

            context.GenerateResponse(result);
        }
 /// <summary>
 /// Handles the specified message.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="store">The object store.</param>
 /// <returns></returns>
 public void Handle(SnmpContext context, ObjectStore store)
 {
 }
 /// <summary>
 /// Authenticates the request.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public bool AuthenticateRequest(SnmpContext context)
 {
     return _providers.Any(provider => provider.AuthenticateRequest(context));
 }
        public void Handle(SnmpContext context, ObjectStore store)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            
            ISnmpPdu pdu = context.Request.Pdu;
            IList<Variable> result = new List<Variable>();
            int index = 0;
            int nonrepeaters = pdu.ErrorStatus.ToInt32();
            var variables = pdu.Variables;
            for (int i = 0; i < nonrepeaters; i++)
            {
                Variable v = variables[i];
                index++;
                try
                {
                    ScalarObject next = store.GetNextObject(v.Id);
                    result.Add(next == null ? new Variable(v.Id, new EndOfMibView()) : next.Variable);
                }
                catch (Exception)
                {
                    context.CopyRequest(ErrorCode.GenError, index);
                    return;
                }
            }

            for (int j = nonrepeaters; j < variables.Count; j++)
            {
                Variable v = variables[j];
                index++;
                Variable temp = v;
                int repetition = pdu.ErrorIndex.ToInt32();
                while (repetition-- > 0)
                {
                    try
                    {
                        ScalarObject next = store.GetNextObject(temp.Id);
                        if (next == null)
                        {
                            temp = new Variable(temp.Id, new EndOfMibView());
                            result.Add(temp);
                            break;
                        }

                        // TODO: how to handle write only object here?
                        result.Add(next.Variable);
                        temp = next.Variable;
                    }
                    catch (Exception)
                    {
                        context.CopyRequest(ErrorCode.GenError, index);
                        return;
                    }
                }
            }

            context.GenerateResponse(result);
        }
示例#26
0
 /// <summary>
 /// Authenticates the request.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <returns></returns>
 public bool AuthenticateRequest(SnmpContext context)
 {
     return(_providers.Any(provider => provider.AuthenticateRequest(context)));
 }