summaryrefslogtreecommitdiff
path: root/pysnmp/smi
diff options
context:
space:
mode:
authorelie <elie>2015-11-22 13:22:05 +0000
committerelie <elie>2015-11-22 13:22:05 +0000
commit0d1b42e1f8964bdc916893733db68efc5f6b3a03 (patch)
tree04b6f047f732836639c2411607685ed47d9af2c9 /pysnmp/smi
parent2d7329e6a2d554729e4a34f2f30c509e95cb858b (diff)
downloadpysnmp-git-0d1b42e1f8964bdc916893733db68efc5f6b3a03.tar.gz
* SNMP table row consistency check added. This change may break
valid SNMP SET operations on tables if RowStatus column is not passed at the very end of var-binds.
Diffstat (limited to 'pysnmp/smi')
-rw-r--r--pysnmp/smi/mibs/PYSNMP-USM-MIB.py12
-rw-r--r--pysnmp/smi/mibs/SNMPv2-SMI.py21
2 files changed, 25 insertions, 8 deletions
diff --git a/pysnmp/smi/mibs/PYSNMP-USM-MIB.py b/pysnmp/smi/mibs/PYSNMP-USM-MIB.py
index 44827fe3..29337596 100644
--- a/pysnmp/smi/mibs/PYSNMP-USM-MIB.py
+++ b/pysnmp/smi/mibs/PYSNMP-USM-MIB.py
@@ -38,9 +38,9 @@ pysnmpUsmSecretEntry = MibTableRow((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 2, 1),
if mibBuilder.loadTexts: pysnmpUsmSecretEntry.setDescription('Information about a particular USM user credentials.')
pysnmpUsmSecretUserName = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 2, 1, 1), SnmpAdminString().subtype(subtypeSpec=ValueSizeConstraint(1,32)))
if mibBuilder.loadTexts: pysnmpUsmSecretUserName.setDescription('The username string for which a row in this table\n represents a configuration.')
-pysnmpUsmSecretAuthKey = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 2, 1, 2), OctetString().subtype(subtypeSpec=ValueSizeConstraint(8,65535)))
+pysnmpUsmSecretAuthKey = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 2, 1, 2), OctetString('\x00\x00\x00\x00\x00\x00\x00\x00').subtype(subtypeSpec=ValueSizeConstraint(8,65535)))
if mibBuilder.loadTexts: pysnmpUsmSecretAuthKey.setDescription("User's authentication passphrase used for localized key generation.")
-pysnmpUsmSecretPrivKey = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 2, 1, 3), OctetString().subtype(subtypeSpec=ValueSizeConstraint(8,65535)))
+pysnmpUsmSecretPrivKey = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 2, 1, 3), OctetString('\x00\x00\x00\x00\x00\x00\x00\x00').subtype(subtypeSpec=ValueSizeConstraint(8,65535)))
if mibBuilder.loadTexts: pysnmpUsmSecretPrivKey.setDescription("User's encryption passphrase used for localized key generation.")
pysnmpUsmSecretStatus = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 2, 1, 4), RowStatus()).setMaxAccess("readcreate")
if mibBuilder.loadTexts: pysnmpUsmSecretStatus.setDescription('Table status')
@@ -50,13 +50,13 @@ pysnmpUsmKeyEntry = MibTableRow((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 3, 1), )
usmUserEntry.registerAugmentions(("PYSNMP-USM-MIB", "pysnmpUsmKeyEntry"))
pysnmpUsmKeyEntry.setIndexNames(*usmUserEntry.getIndexNames())
if mibBuilder.loadTexts: pysnmpUsmKeyEntry.setDescription('Information about a particular USM user credentials.')
-pysnmpUsmKeyAuthLocalized = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 3, 1, 1), OctetString().subtype(subtypeSpec=ValueSizeConstraint(8,32)))
+pysnmpUsmKeyAuthLocalized = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 3, 1, 1), OctetString('\x00\x00\x00\x00\x00\x00\x00\x00').subtype(subtypeSpec=ValueSizeConstraint(8,32)))
if mibBuilder.loadTexts: pysnmpUsmKeyAuthLocalized.setDescription("User's localized key used for authentication.")
-pysnmpUsmKeyPrivLocalized = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 3, 1, 2), OctetString().subtype(subtypeSpec=ValueSizeConstraint(8,32)))
+pysnmpUsmKeyPrivLocalized = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 3, 1, 2), OctetString('\x00\x00\x00\x00\x00\x00\x00\x00').subtype(subtypeSpec=ValueSizeConstraint(8,32)))
if mibBuilder.loadTexts: pysnmpUsmKeyPrivLocalized.setDescription("User's localized key used for encryption.")
-pysnmpUsmKeyAuth = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 3, 1, 3), OctetString().subtype(subtypeSpec=ValueSizeConstraint(8,32)))
+pysnmpUsmKeyAuth = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 3, 1, 3), OctetString('\x00\x00\x00\x00\x00\x00\x00\x00').subtype(subtypeSpec=ValueSizeConstraint(8,32)))
if mibBuilder.loadTexts: pysnmpUsmKeyAuth.setDescription("User's non-localized key used for authentication.")
-pysnmpUsmKeyPriv = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 3, 1, 4), OctetString().subtype(subtypeSpec=ValueSizeConstraint(8,32)))
+pysnmpUsmKeyPriv = MibTableColumn((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 3, 1, 4), OctetString('\x00\x00\x00\x00\x00\x00\x00\x00').subtype(subtypeSpec=ValueSizeConstraint(8,32)))
if mibBuilder.loadTexts: pysnmpUsmKeyPriv.setDescription("User's non-localized key used for encryption.")
pysnmpUsmMIBCompliances = MibIdentifier((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 2, 1))
pysnmpUsmMIBGroups = MibIdentifier((1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 2, 2))
diff --git a/pysnmp/smi/mibs/SNMPv2-SMI.py b/pysnmp/smi/mibs/SNMPv2-SMI.py
index bdc26997..ce7da0ec 100644
--- a/pysnmp/smi/mibs/SNMPv2-SMI.py
+++ b/pysnmp/smi/mibs/SNMPv2-SMI.py
@@ -878,7 +878,11 @@ class MibTableColumn(MibScalar):
MibScalar.writeTest(self, name, val, idx, acInfo)
# ...otherwise proceed with creating new column
except (error.NoSuchInstanceError, error.RowCreationWanted):
- self.__rowOpWanted[name] = error.RowCreationWanted()
+ excValue = sys.exc_info()[1]
+ if isinstance(excValue, error.RowCreationWanted):
+ self.__rowOpWanted[name] = excValue
+ else:
+ self.__rowOpWanted[name] = error.RowCreationWanted()
self.createTest(name, val, idx, acInfo)
except error.RowDestructionWanted:
self.__rowOpWanted[name] = error.RowDestructionWanted()
@@ -911,6 +915,8 @@ class MibTableColumn(MibScalar):
raise e
def writeUndo(self, name, val, idx, acInfo):
+ if name in self.__rowOpWanted:
+ self.__rowOpWanted[name] = error.RowDestructionWanted()
self.__delegateWrite('Undo', name, val, idx, acInfo)
if name in self.__rowOpWanted:
e = self.__rowOpWanted[name]
@@ -1076,6 +1082,7 @@ class MibTableRow(MibTree):
def __delegate(self, subAction, name, val, idx, acInfo):
# Relay operation request to column, expect row operation request.
+ rowIsActive = False
try:
getattr(self.getBranch(name, idx), 'write'+subAction)(
name, val, idx, acInfo
@@ -1091,6 +1098,9 @@ class MibTableRow(MibTree):
'create'+subAction, name, None, idx, acInfo
)
+ # watch for RowStatus == 'stActive'
+ rowIsActive = sys.exc_info()[1].get('syntax', 0) == 1
+
except error.RowDestructionWanted:
self.__manageColumns(
'destroy'+subAction, name[:len(self.name)+1],
@@ -1101,11 +1111,18 @@ class MibTableRow(MibTree):
'destroy'+subAction, name, None, idx, acInfo
)
+ return rowIsActive
+
def writeTest(self, name, val, idx, acInfo):
self.__delegate('Test', name, val, idx, acInfo)
def writeCommit(self, name, val, idx, acInfo):
- self.__delegate('Commit', name, val, idx, acInfo)
+ rowIsActive = self.__delegate('Commit', name, val, idx, acInfo)
+ if rowIsActive:
+ for mibNode in self._vars.values():
+ colNode = mibNode.getNode(mibNode.name + name[len(self.name)+1:])
+ if not colNode.syntax.hasValue():
+ raise error.InconsistentValueError(msg='Row consistency check failed for %r' % colNode)
def writeCleanup(self, name, val, idx, acInfo):
self.branchVersionId += 1