diff options
author | elie <elie> | 2013-05-04 12:12:49 +0000 |
---|---|---|
committer | elie <elie> | 2013-05-04 12:12:49 +0000 |
commit | 2855379f969cec57a9f9003300f63ce7cb5264db (patch) | |
tree | db335f1aa1514632e71508ec0b1082f779eb6c1a /pysnmp/proto | |
parent | 91461dcd78a1eb4a2d0cb0cfaa65062da07b8c9f (diff) | |
download | pysnmp-2855379f969cec57a9f9003300f63ce7cb5264db.tar.gz |
the snmpCommunityTable row selection improved to follow RFC2576, clause 5.2.1
Diffstat (limited to 'pysnmp/proto')
-rw-r--r-- | pysnmp/proto/secmod/rfc2576.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/pysnmp/proto/secmod/rfc2576.py b/pysnmp/proto/secmod/rfc2576.py index c80ce35..1c05511 100644 --- a/pysnmp/proto/secmod/rfc2576.py +++ b/pysnmp/proto/secmod/rfc2576.py @@ -270,13 +270,24 @@ class SnmpV1SecurityModel(base.AbstractSecurityModel): debug.logger & debug.flagSM and debug.logger('_com2sec: built tag & community to securityName map (securityModel %s), version %s: %s' % (self.securityModelID, self.__communityBranchId, self.__tagAndCommunityToSecurityMap)) if communityName in self.__communityToTagMap: - if self.__emptyTag in self.__communityToTagMap[communityName]: - return self.__tagAndCommunityToSecurityMap[(self.__emptyTag, communityName)] - if transportInformation in self.__transportToTagMap: tags = self.__transportToTagMap[transportInformation].intersection(self.__communityToTagMap[communityName]) - if tags: - return self.__tagAndCommunityToSecurityMap[(tags.pop(), communityName)] + candidateSecurityNames = [ + self.__tagAndCommunityToSecurityMap[(t, communityName)] for t in tags + ] + else: + candidateSecurityNames = [] + + if self.__emptyTag in self.__communityToTagMap[communityName]: + candidateSecurityNames.append( + self.__tagAndCommunityToSecurityMap[(self.__emptyTag, communityName)] + ) + + # 5.2.1 (row selection in snmpCommunityTable) + if candidateSecurityNames: + chosenSecurityName = min(candidateSecurityNames, key=lambda x:str(x[0])) + debug.logger & debug.flagSM and debug.logger('_com2sec: securityName candidates for communityName \'%s\' are %s; choosing securityName \'%s\'' % (communityName, candidateSecurityNames, chosenSecurityName[0])) + return chosenSecurityName raise error.StatusInformation() |