summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt2
-rw-r--r--pysnmp/entity/config.py35
-rw-r--r--pysnmp/hlapi/asyncio/cmdgen.py12
-rw-r--r--pysnmp/hlapi/asyncio/ntforg.py4
-rw-r--r--pysnmp/hlapi/asyncore/cmdgen.py14
-rw-r--r--pysnmp/hlapi/asyncore/ntforg.py2
-rw-r--r--pysnmp/hlapi/lcd.py30
-rw-r--r--pysnmp/hlapi/twisted/cmdgen.py12
-rw-r--r--pysnmp/hlapi/twisted/ntforg.py5
9 files changed, 70 insertions, 46 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index ed0d26bd..2f9166e7 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -7,6 +7,8 @@ Revision 4.4.7, released 2018-11-XX
the stack frames (ultimately shown in traceback/debugger)
- Fixed hlapi/v3arch transport target caching to ensure transport targets
are different even if just timeout/retries options differ
+- Fixed hlapi LCD configurator to include `contextName`. Prior to this fix
+ sending SNMPv3 TRAP with non-default `contextName` would fail.
Revision 4.4.6, released 2018-09-13
-----------------------------------
diff --git a/pysnmp/entity/config.py b/pysnmp/entity/config.py
index e2ca92bb..4c069c72 100644
--- a/pysnmp/entity/config.py
+++ b/pysnmp/entity/config.py
@@ -560,12 +560,13 @@ def addVacmUser(snmpEngine, securityModel, securityName, securityLevel,
def delVacmUser(snmpEngine, securityModel, securityName, securityLevel,
- readSubTree=(), writeSubTree=(), notifySubTree=()):
+ readSubTree=(), writeSubTree=(), notifySubTree=(),
+ contextName=null):
(groupName, securityLevel, readView, writeView,
notifyView) = __cookVacmUserInfo(snmpEngine, securityModel,
securityName, securityLevel)
delVacmGroup(snmpEngine, securityModel, securityName)
- delVacmAccess(snmpEngine, groupName, null, securityModel, securityLevel)
+ delVacmAccess(snmpEngine, groupName, contextName, securityModel, securityLevel)
if readSubTree:
delVacmView(
snmpEngine, readView, readSubTree
@@ -582,36 +583,40 @@ def delVacmUser(snmpEngine, securityModel, securityName, securityLevel,
# Obsolete shortcuts for add/delVacmUser() wrappers
-def addRoUser(snmpEngine, securityModel, securityName, securityLevel, subTree):
- addVacmUser(snmpEngine, securityModel, securityName,
- securityLevel, subTree)
+def addRoUser(snmpEngine, securityModel, securityName, securityLevel,
+ subTree, contextName=null):
+ addVacmUser(snmpEngine, securityModel, securityName, securityLevel,
+ subTree, contextName=contextName)
-def delRoUser(snmpEngine, securityModel, securityName, securityLevel, subTree):
+def delRoUser(snmpEngine, securityModel, securityName, securityLevel,
+ subTree, contextName=null):
delVacmUser(snmpEngine, securityModel, securityName, securityLevel,
- subTree)
+ subTree, contextName=contextName)
-def addRwUser(snmpEngine, securityModel, securityName, securityLevel, subTree):
+def addRwUser(snmpEngine, securityModel, securityName, securityLevel,
+ subTree, contextName=null):
addVacmUser(snmpEngine, securityModel, securityName, securityLevel,
- subTree, subTree)
+ subTree, subTree, contextName=contextName)
-def delRwUser(snmpEngine, securityModel, securityName, securityLevel, subTree):
+def delRwUser(snmpEngine, securityModel, securityName, securityLevel,
+ subTree, contextName=null):
delVacmUser(snmpEngine, securityModel, securityName, securityLevel,
- subTree, subTree)
+ subTree, subTree, contextName=contextName)
def addTrapUser(snmpEngine, securityModel, securityName,
- securityLevel, subTree):
+ securityLevel, subTree, contextName=null):
addVacmUser(snmpEngine, securityModel, securityName, securityLevel,
- (), (), subTree)
+ (), (), subTree, contextName=contextName)
def delTrapUser(snmpEngine, securityModel, securityName,
- securityLevel, subTree):
+ securityLevel, subTree, contextName=null):
delVacmUser(snmpEngine, securityModel, securityName, securityLevel,
- (), (), subTree)
+ (), (), subTree, contextName=contextName)
# Notification target setup
diff --git a/pysnmp/hlapi/asyncio/cmdgen.py b/pysnmp/hlapi/asyncio/cmdgen.py
index 8c69fd19..46e58aa6 100644
--- a/pysnmp/hlapi/asyncio/cmdgen.py
+++ b/pysnmp/hlapi/asyncio/cmdgen.py
@@ -148,7 +148,8 @@ def getCmd(snmpEngine, authData, transportTarget, contextData,
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
)
- addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = lcd.configure(
+ snmpEngine, authData, transportTarget, contextData.contextName)
future = asyncio.Future()
@@ -254,7 +255,8 @@ def setCmd(snmpEngine, authData, transportTarget, contextData,
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
)
- addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = lcd.configure(
+ snmpEngine, authData, transportTarget, contextData.contextName)
future = asyncio.Future()
@@ -366,7 +368,8 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData,
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
)
- addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = lcd.configure(
+ snmpEngine, authData, transportTarget, contextData.contextName)
future = asyncio.Future()
@@ -507,7 +510,8 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData,
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
)
- addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = lcd.configure(
+ snmpEngine, authData, transportTarget, contextData.contextName)
future = asyncio.Future()
diff --git a/pysnmp/hlapi/asyncio/ntforg.py b/pysnmp/hlapi/asyncio/ntforg.py
index b4f6fb3a..be75b3a5 100644
--- a/pysnmp/hlapi/asyncio/ntforg.py
+++ b/pysnmp/hlapi/asyncio/ntforg.py
@@ -139,8 +139,8 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData,
)
notifyName = lcd.configure(
- snmpEngine, authData, transportTarget, notifyType
- )
+ snmpEngine, authData, transportTarget, notifyType,
+ contextData.contextName)
future = asyncio.Future()
diff --git a/pysnmp/hlapi/asyncore/cmdgen.py b/pysnmp/hlapi/asyncore/cmdgen.py
index 4cedfa82..c7b8a2d3 100644
--- a/pysnmp/hlapi/asyncore/cmdgen.py
+++ b/pysnmp/hlapi/asyncore/cmdgen.py
@@ -121,7 +121,8 @@ def getCmd(snmpEngine, authData, transportTarget, contextData,
snmpEngine, varBinds, lookupMib
), cbCtx)
- addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = lcd.configure(
+ snmpEngine, authData, transportTarget, contextData.contextName)
return cmdgen.GetCommandGenerator().sendVarBinds(
snmpEngine, addrName, contextData.contextEngineId,
@@ -232,7 +233,8 @@ def setCmd(snmpEngine, authData, transportTarget, contextData,
snmpEngine, varBinds, lookupMib
), cbCtx)
- addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = lcd.configure(
+ snmpEngine, authData, transportTarget, contextData.contextName)
return cmdgen.SetCommandGenerator().sendVarBinds(
snmpEngine, addrName, contextData.contextEngineId,
@@ -343,7 +345,9 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData,
varBindTable],
cbCtx)
- addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = lcd.configure(
+ snmpEngine, authData, transportTarget, contextData.contextName)
+
return cmdgen.NextCommandGenerator().sendVarBinds(
snmpEngine, addrName,
contextData.contextEngineId, contextData.contextName,
@@ -483,7 +487,9 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData,
[vbProcessor.unmakeVarBinds(snmpEngine, varBindTableRow, lookupMib) for varBindTableRow in
varBindTable], cbCtx)
- addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = lcd.configure(
+ snmpEngine, authData, transportTarget, contextData.contextName)
+
return cmdgen.BulkCommandGenerator().sendVarBinds(
snmpEngine, addrName, contextData.contextEngineId,
contextData.contextName, nonRepeaters, maxRepetitions,
diff --git a/pysnmp/hlapi/asyncore/ntforg.py b/pysnmp/hlapi/asyncore/ntforg.py
index ecd418c1..b35bdba9 100644
--- a/pysnmp/hlapi/asyncore/ntforg.py
+++ b/pysnmp/hlapi/asyncore/ntforg.py
@@ -131,7 +131,7 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData,
)
notifyName = lcd.configure(snmpEngine, authData, transportTarget,
- notifyType)
+ notifyType, contextData.contextName)
return ntforg.NotificationOriginator().sendVarBinds(
snmpEngine, notifyName,
diff --git a/pysnmp/hlapi/lcd.py b/pysnmp/hlapi/lcd.py
index 1d61c491..43bfc101 100644
--- a/pysnmp/hlapi/lcd.py
+++ b/pysnmp/hlapi/lcd.py
@@ -8,6 +8,8 @@ from pysnmp.entity import config
from pysnmp import nextid, error
from pysnmp.hlapi.auth import *
+from pyasn1.compat.octets import null
+
__all__ = ['CommandGeneratorLcdConfigurator',
'NotificationOriginatorLcdConfigurator']
@@ -24,17 +26,17 @@ class AbstractLcdConfigurator(object):
snmpEngine.setUserContext(**{cacheId: cache})
return cache
- def configure(self, snmpEngine, authData, transportTarget, *options):
+ def configure(self, snmpEngine, *args, **kwargs):
pass
- def unconfigure(self, snmpEngine, authData=None):
+ def unconfigure(self, snmpEngine, *args, **kwargs):
pass
class CommandGeneratorLcdConfigurator(AbstractLcdConfigurator):
cacheKeys = ['auth', 'parm', 'tran', 'addr']
- def configure(self, snmpEngine, authData, transportTarget, *options):
+ def configure(self, snmpEngine, authData, transportTarget, contextName, **options):
cache = self._getCache(snmpEngine)
if isinstance(authData, CommunityData):
if authData.communityIndex not in cache['auth']:
@@ -117,7 +119,7 @@ class CommandGeneratorLcdConfigurator(AbstractLcdConfigurator):
return addrName, paramsName
- def unconfigure(self, snmpEngine, authData=None):
+ def unconfigure(self, snmpEngine, authData=None, contextName=null, **options):
cache = self._getCache(snmpEngine)
if authData:
if isinstance(authData, CommunityData):
@@ -198,9 +200,9 @@ class NotificationOriginatorLcdConfigurator(AbstractLcdConfigurator):
cacheKeys = ['auth', 'name']
_cmdGenLcdCfg = CommandGeneratorLcdConfigurator()
- def configure(self, snmpEngine, authData, transportTarget, *options):
+ def configure(self, snmpEngine, authData, transportTarget, notifyType,
+ contextName, **options):
cache = self._getCache(snmpEngine)
- notifyType = options and options[0] or 'trap'
notifyName = None
# Create matching transport tags if not given by user. Not good!
@@ -211,7 +213,8 @@ class NotificationOriginatorLcdConfigurator(AbstractLcdConfigurator):
if isinstance(authData, CommunityData) and not authData.tag:
authData.tag = transportTarget.tagList.split()[0]
- addrName, paramsName = self._cmdGenLcdCfg.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = self._cmdGenLcdCfg.configure(
+ snmpEngine, authData, transportTarget, contextName, **options)
tagList = transportTarget.tagList.split()
if not tagList:
tagList = ['']
@@ -230,7 +233,7 @@ class NotificationOriginatorLcdConfigurator(AbstractLcdConfigurator):
notifyType
)
cache['name'][notifyNameKey] = notifyName, paramsName, 1
- authDataKey = authData.securityName, authData.securityModel
+ authDataKey = authData.securityName, authData.securityModel, authData.securityLevel, contextName
if authDataKey in cache['auth']:
authDataX, subTree, useCount = cache['auth'][authDataKey]
cache['auth'][authDataKey] = authDataX, subTree, useCount + 1
@@ -238,23 +241,24 @@ class NotificationOriginatorLcdConfigurator(AbstractLcdConfigurator):
subTree = (1, 3, 6)
config.addTrapUser(snmpEngine, authData.securityModel,
authData.securityName, authData.securityLevel,
- subTree)
+ subTree, contextName=contextName)
cache['auth'][authDataKey] = authData, subTree, 1
return notifyName
- def unconfigure(self, snmpEngine, authData=None):
+ def unconfigure(self, snmpEngine, authData=None, contextName=null, **options):
cache = self._getCache(snmpEngine)
if authData:
- authDataKey = authData.securityName, authData.securityModel
+ authDataKey = authData.securityName, authData.securityModel, authData.securityLevel, contextName
if authDataKey in cache['auth']:
authDataKeys = (authDataKey,)
else:
raise error.PySnmpError('Unknown authData %s' % (authData,))
else:
- authDataKeys = tuple(cache['auth'].keys())
+ authDataKeys = tuple(cache['auth'])
- addrNames, paramsNames = self._cmdGenLcdCfg.unconfigure(snmpEngine, authData)
+ addrNames, paramsNames = self._cmdGenLcdCfg.unconfigure(
+ snmpEngine, authData, contextName, **options)
notifyAndParamsNames = [(cache['name'][x], x) for x in cache['name'].keys() if x[0] in paramsNames]
diff --git a/pysnmp/hlapi/twisted/cmdgen.py b/pysnmp/hlapi/twisted/cmdgen.py
index 9cfb9822..611de050 100644
--- a/pysnmp/hlapi/twisted/cmdgen.py
+++ b/pysnmp/hlapi/twisted/cmdgen.py
@@ -129,7 +129,8 @@ def getCmd(snmpEngine, authData, transportTarget, contextData,
else:
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
- addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = lcd.configure(
+ snmpEngine, authData, transportTarget, contextData.contextName)
deferred = Deferred()
@@ -246,7 +247,8 @@ def setCmd(snmpEngine, authData, transportTarget, contextData,
else:
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
- addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = lcd.configure(
+ snmpEngine, authData, transportTarget, contextData.contextName)
deferred = Deferred()
@@ -377,7 +379,8 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData,
else:
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
- addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = lcd.configure(
+ snmpEngine, authData, transportTarget, contextData.contextName)
deferred = Deferred()
@@ -536,7 +539,8 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData,
else:
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
- addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
+ addrName, paramsName = lcd.configure(
+ snmpEngine, authData, transportTarget, contextData.contextName)
deferred = Deferred()
diff --git a/pysnmp/hlapi/twisted/ntforg.py b/pysnmp/hlapi/twisted/ntforg.py
index 0b8f6053..a33e226d 100644
--- a/pysnmp/hlapi/twisted/ntforg.py
+++ b/pysnmp/hlapi/twisted/ntforg.py
@@ -137,9 +137,8 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData,
else:
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
- notifyName = lcd.configure(
- snmpEngine, authData, transportTarget, notifyType
- )
+ notifyName = lcd.configure(snmpEngine, authData, transportTarget,
+ notifyType, contextData.contextName)
def __trapFun(deferred):
deferred.callback((0, 0, []))