[Git][NTPsec/ntpsec][master] 3 commits: ntpsnmpd now responds to incorrect sessionID
Ian Bruene
gitlab at mg.gitlab.com
Mon Nov 20 17:13:56 UTC 2017
Ian Bruene pushed to branch master at NTPsec / ntpsec
Commits:
480d93cb by Ian Bruene at 2017-11-20T11:13:34-06:00
ntpsnmpd now responds to incorrect sessionID
- - - - -
aec26773 by Ian Bruene at 2017-11-20T11:13:34-06:00
First dynamic MIB lookup complete
- - - - -
792b44fe by Ian Bruene at 2017-11-20T11:13:34-06:00
Removed obsolete write switches from read callbacks
- - - - -
1 changed file:
- ntpclients/ntpsnmpd
Changes:
=====================================
ntpclients/ntpsnmpd
=====================================
--- a/ntpclients/ntpsnmpd
+++ b/ntpclients/ntpsnmpd
@@ -71,19 +71,19 @@ class DataSource: # This may be broken up in future to be less NTP-specific
node(None, None, True,
# ntpNetSoftwareName utf8str
{1: node((lambda oid:
- self.cbr_systemInfo(oid, None, "name")),
+ self.cbr_systemInfo(oid, "name")),
None, True, None),
# ntpEntSoftwareVersion utf8str
2: node((lambda oid:
- self.cbr_systemInfo(oid, None, "version")),
+ self.cbr_systemInfo(oid, "version")),
None, True, None),
# ntpEntSoftwareVendor utf8str
3: node((lambda oid:
- self.cbr_systemInfo(oid, None, "vendor")),
+ self.cbr_systemInfo(oid, "vendor")),
None, True, None),
# ntpEntSystemType utf8str
4: node((lambda oid:
- self.cbr_systemInfo(oid, None, "system")),
+ self.cbr_systemInfo(oid, "system")),
None, True, None),
# ntpEntTimeResolution uint32
5: node(self.cbr_timeResolution, None, True, None),
@@ -158,7 +158,8 @@ class DataSource: # This may be broken up in future to be less NTP-specific
{1:
node(None, None, True,
# ntpAssocId uint32 (1..99999)
- {1: node(self.cbr_assocID, None, True, None),
+ {1: node(None, None, False,
+ self.sub_assocID),
# ntpAssocName utf8str
2: node(self.cbr_assocName,
None, True, None),
@@ -250,6 +251,7 @@ class DataSource: # This may be broken up in future to be less NTP-specific
self.setVarbinds = [] # Varbind of the current set operation
self.setHandlers = [] # Handlers for commit/undo/cleanup of set
self.setUndoData = [] # Previous values for undoing
+ self.sentNotifications = 0
# Notify bits, these should be saved to disk
# Also they currently have no effect
self.notifyModeChange = False # 1
@@ -337,216 +339,179 @@ class DataSource: # This may be broken up in future to be less NTP-specific
#########################
- def cbr_systemInfo(self, oid, write=None, category=None):
- if write is None:
- if category == "name": # The product name of the running NTP
- data = "NTPsec"
- elif category == "version": # version string
- data = ntp.util.stdversion()
- elif category == "vendor": # vendor/author name
- data = "Internet Civil Engineering Institute"
- elif category == "system": # system / hardware info
- proc = subprocess.Popen(["uname", "-srm"],
- stdout=subprocess.PIPE)
- data = proc.communicate()[0]
- vb = ax.Varbind(ax.VALUE_OCTET_STR, oid, data)
- return vb
-
- def cbr_timeResolution(self, oid, write=None): # DUMMY
+ def cbr_systemInfo(self, oid, category=None):
+ if category == "name": # The product name of the running NTP
+ data = "NTPsec"
+ elif category == "version": # version string
+ data = ntp.util.stdversion()
+ elif category == "vendor": # vendor/author name
+ data = "Internet Civil Engineering Institute"
+ elif category == "system": # system / hardware info
+ proc = subprocess.Popen(["uname", "-srm"],
+ stdout=subprocess.PIPE)
+ data = proc.communicate()[0]
+ vb = ax.Varbind(ax.VALUE_OCTET_STR, oid, data)
+ return vb
+
+ def cbr_timeResolution(self, oid): # DUMMY
# Uinteger32
- if write is None:
- return ax.Varbind(ax.VALUE_GAUGE32, oid, 42)
+ return ax.Varbind(ax.VALUE_GAUGE32, oid, 42)
def cbr_timePrecision(self, oid, write=None):
- if write is None:
- data = self.session.readvar(0, ["precision"])
- return ax.Varbind(ax.VALUE_INTEGER, oid, data["precision"])
+ data = self.session.readvar(0, ["precision"])
+ return ax.Varbind(ax.VALUE_INTEGER, oid, data["precision"])
- def cbr_timeDistance(self, oid, write=None): # DUMMY
+ def cbr_timeDistance(self, oid): # DUMMY
# Displaystring
- if write is None:
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, "foo")
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, "foo")
#############################
- def cbr_statusCurrentMode(self, oid, write=None): # DUMMY
+ def cbr_statusCurrentMode(self, oid): # DUMMY
# Range of integers
- if write is None:
- return ax.Varbind(ax.VALUE_INTEGER, oid, 15)
+ return ax.Varbind(ax.VALUE_INTEGER, oid, 15)
- def cbr_statusStratum(self, oid, write=None):
+ def cbr_statusStratum(self, oid):
# NTPstratum
- if write is None:
- data = self.session.readvar(0, ["stratum"])
- return ax.Varbind(ax.VALUE_GAUGE32, oid, data["stratum"])
+ data = self.session.readvar(0, ["stratum"])
+ return ax.Varbind(ax.VALUE_GAUGE32, oid, data["stratum"])
- def cbr_statusActiveRefSourceID(self, oid, write=None): # DUMMY
+ def cbr_statusActiveRefSourceID(self, oid): # DUMMY
# range of uint32
- if write is None:
- return ax.Varbind(ax.VALUE_GAUGE32, oid, 1024)
+ return ax.Varbind(ax.VALUE_GAUGE32, oid, 1024)
- def cbr_statusActiveRefSourceName(self, oid, write=None):
+ def cbr_statusActiveRefSourceName(self, oid):
# utf8
- if write is None: # TODO: pretty sure this is right, just need DNS
- data = self.session.readvar(0, ["peeradr"])
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, data["peeradr"])
+ # TODO: pretty sure this is right, just need DNS
+ data = self.session.readvar(0, ["peeradr"])
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, data["peeradr"])
- def cbr_statusActiveOffset(self, oid, write=None):
+ def cbr_statusActiveOffset(self, oid):
# DisplayString
- if write is None:
- data = self.session.readvar(0, ["koffset"], raw=True)
- data = ntp.util.unitifyvar(data["koffset"][1], "koffset",
- width=None, unitSpace=True)
- print("\n\n\nactive offset:", repr(data))
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, data)
-
- def cbr_statusNumRefSources(self, oid, write=None):
+ data = self.session.readvar(0, ["koffset"], raw=True)
+ data = ntp.util.unitifyvar(data["koffset"][1], "koffset",
+ width=None, unitSpace=True)
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, data)
+
+ def cbr_statusNumRefSources(self, oid):
# range of uint32
- if write is None:
- data = self.session.readstat()
- return ax.Varbind(ax.VALUE_GAUGE32, oid, len(data))
+ data = self.session.readstat()
+ return ax.Varbind(ax.VALUE_GAUGE32, oid, len(data))
- def cbr_statusDispersion(self, oid, write=None):
+ def cbr_statusDispersion(self, oid):
# DisplayString
- if write is None:
- data = self.session.readvar(0, ["rootdisp"], raw=True)
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, data["rootdisp"][1])
+ data = self.session.readvar(0, ["rootdisp"], raw=True)
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, data["rootdisp"][1])
- def cbr_statusEntityUptime(self, oid, write=None): # DUMMY
+ def cbr_statusEntityUptime(self, oid): # DUMMY
# TimeTicks
- if write is None:
- return ax.Varbind(ax.VALUE_TIME_TICKS, oid, 8)
+ return ax.Varbind(ax.VALUE_TIME_TICKS, oid, 8)
- def cbr_statusDateTime(self, oid, write=None):
+ def cbr_statusDateTime(self, oid):
# NtpDateTime
- if write is None:
- data = self.session.readvar(0, ["reftime"])
- txt = data["reftime"]
- txt = txt[2:] # Strip '0x'
- txt = "".join(txt.split(".")) # Strip '.'
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, txt)
-
- def cbr_statusLeapSecond(self, oid, write=None): # DUMMY
+ data = self.session.readvar(0, ["reftime"])
+ txt = data["reftime"]
+ txt = txt[2:] # Strip '0x'
+ txt = "".join(txt.split(".")) # Strip '.'
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, txt)
+
+ def cbr_statusLeapSecond(self, oid): # DUMMY
# NtpDateTime
- if write is None:
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, "blah")
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, "blah")
- def cbr_statusLeapSecDirection(self, oid, write=None): # DUMMY
+ def cbr_statusLeapSecDirection(self, oid): # DUMMY
# range of int32
- if write is None:
- return ax.Varbind(ax.VALUE_INTEGER, oid, -1)
+ return ax.Varbind(ax.VALUE_INTEGER, oid, -1)
- def cbr_statusInPkts(self, oid, write=None):
- if write is None:
- data = self.session.readvar(0, ["io_received"])
- return ax.Varbind(ax.VALUE_COUNTER32, oid, data["io_received"])
+ def cbr_statusInPkts(self, oid):
+ data = self.session.readvar(0, ["io_received"])
+ return ax.Varbind(ax.VALUE_COUNTER32, oid, data["io_received"])
- def cbr_statusOutPkts(self, oid, write=None):
- if write is None:
- data = self.session.readvar(0, ["io_sent"])
- return ax.Varbind(ax.VALUE_COUNTER32, oid, data["io_sent"])
+ def cbr_statusOutPkts(self, oid):
+ data = self.session.readvar(0, ["io_sent"])
+ return ax.Varbind(ax.VALUE_COUNTER32, oid, data["io_sent"])
- def cbr_statusBadVersion(self, oid, write=None):
- if write is None:
- data = self.session.readvar(0, ["ss_oldver"])
- return ax.Varbind(ax.VALUE_COUNTER32, oid, data["ss_oldver"])
+ def cbr_statusBadVersion(self, oid):
+ data = self.session.readvar(0, ["ss_oldver"])
+ return ax.Varbind(ax.VALUE_COUNTER32, oid, data["ss_oldver"])
- def cbr_statusProtocolError(self, oid, write=None): # DUMMY
- if write is None:
- return ax.Varbind(ax.VALUE_COUNTER32, oid, 400)
+ def cbr_statusProtocolError(self, oid): # DUMMY
+ return ax.Varbind(ax.VALUE_COUNTER32, oid, 400)
- def cbr_statusNotifications(self, oid, write=None): # DUMMY
- if write is None:
- return ax.Varbind(ax.VALUE_COUNTER32, oid, 500)
+ def cbr_statusNotifications(self, oid):
+ return ax.Varbind(ax.VALUE_COUNTER32, oid, self.sentNotifications)
##############################
- def cbr_assocID(self, oid, write=None): # DUMMY
- if write is None:
- return ax.Varbind(ax.VALUE_GAUGE32, oid, 1)
+ # assocID: dynamic
- def cbr_assocName(self, oid, write=None): # DUMMY
- if write is None:
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, "It")
+ def cbr_assocName(self, oid): # DUMMY
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, "It")
- def cbr_assocRefID(self, oid, write=None): # DUMMY
+ def cbr_assocRefID(self, oid): # DUMMY
# DisplayString
- if write is None:
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, "says;")
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, "says;")
- def cbr_assocAddrType(self, oid, write=None): # DUMMY
+ def cbr_assocAddrType(self, oid): # DUMMY
# InetAddressType (range of ints)
- if write is None:
- return ax.Varbind(ax.VALUE_INTEGER, oid, 3)
+ return ax.Varbind(ax.VALUE_INTEGER, oid, 3)
- def cbr_assocAddr(self, oid, write=None): # DUMMY
+ def cbr_assocAddr(self, oid): # DUMMY
# InetAddress
- if write is None:
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, "\x01\x02\x03\x04")
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, "\x01\x02\x03\x04")
- def cbr_assocOffset(self, oid, write=None): # DUMMY
+ def cbr_assocOffset(self, oid): # DUMMY
# DisplayString
- if write is None:
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, "Would")
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, "Would")
- def cbr_assocStratum(self, oid, write=None): # DUMMY
+ def cbr_assocStratum(self, oid): # DUMMY
# NTPStratum
- if write is None:
- return ax.Varbind(ax.VALUE_GAUGE32, oid, 12)
+ return ax.Varbind(ax.VALUE_GAUGE32, oid, 12)
- def cbr_assocStatusJitter(self, oid, write=None): # DUMMY
+ def cbr_assocStatusJitter(self, oid): # DUMMY
# DisplayString
- if write is None:
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, "You")
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, "You")
- def cbr_assocStatusDelay(self, oid, write=None): # DUMMY
+ def cbr_assocStatusDelay(self, oid): # DUMMY
# DisplayString
- if write is None:
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, "Kindly?")
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, "Kindly?")
- def cbr_assocStatusDisp(self, oid, write=None): # DUMMY
+ def cbr_assocStatusDisp(self, oid): # DUMMY
# DisplayString
- if write is None:
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, "*thunk*")
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, "*thunk*")
- def cbr_assocStatInPkts(self, oid, write=None): # DUMMY
- if write is None:
- return ax.Varbind(ax.VALUE_COUNTER32, oid, 2)
+ def cbr_assocStatInPkts(self, oid): # DUMMY
+ return ax.Varbind(ax.VALUE_COUNTER32, oid, 2)
- def cbr_assocStatOutPkts(self, oid, write=None): # DUMMY
- if write is None:
- return ax.Varbind(ax.VALUE_COUNTER32, oid, 4)
+ def cbr_assocStatOutPkts(self, oid): # DUMMY
+ return ax.Varbind(ax.VALUE_COUNTER32, oid, 4)
- def cbr_assocStatProtoErr(self, oid, write=None): # DUMMY
- if write is None:
- return ax.Varbind(ax.VALUE_COUNTER32, oid, 8)
+ def cbr_assocStatProtoErr(self, oid): # DUMMY
+ return ax.Varbind(ax.VALUE_COUNTER32, oid, 8)
#########################
- def cbr_entHeartbeatInterval(self, oid, write=None): # DUMMY
+ def cbr_entHeartbeatInterval(self, oid): # DUMMY
# uint32
- if write is None:
- return ax.Varbind(ax.VALUE_GAUGE32, oid, 16)
+ return ax.Varbind(ax.VALUE_GAUGE32, oid, 16)
- def cbr_entNotifBits(self, oid, write=None): # DUMMY
+ def cbr_entNotifBits(self, oid): # DUMMY
# BITS
- if write is None:
- data = ax.bools2Bits((self.notifyModeChange,
- self.notifyStratumChange,
- self.notifySyspeerChange,
- self.notifyAddAssociation,
- self.notifyRMAssociation,
- self.notifyConfigChange,
- self.notifyLeapSecondAnnounced,
- self.notifyHeartbeat))
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, data)
+ data = ax.bools2Bits((self.notifyModeChange,
+ self.notifyStratumChange,
+ self.notifySyspeerChange,
+ self.notifyAddAssociation,
+ self.notifyRMAssociation,
+ self.notifyConfigChange,
+ self.notifyLeapSecondAnnounced,
+ self.notifyHeartbeat))
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, data)
##########################
- def cbr_entNotifMessage(self, oid, write=None): # DUMMY
+ def cbr_entNotifMessage(self, oid): # DUMMY
# utf8str
- if write is None:
- return ax.Varbind(ax.VALUE_OCTET_STR, oid, "jabber")
+ return ax.Varbind(ax.VALUE_OCTET_STR, oid, "jabber")
#########################
@@ -584,6 +549,36 @@ class DataSource: # This may be broken up in future to be less NTP-specific
elif action == "cleanup":
pass
+ # =====================================
+ # Dynamic tree generator callbacks
+ # =====================================
+
+ def sub_assocID(self):
+ def readCallback(oid): # DUMMY
+ index = oid.subids[-1] # if called properly this works (Ha!)
+ return ax.Varbind(ax.VALUE_GAUGE32, oid, index)
+ subs = {}
+ peers = self.session.readstat()
+ for i in range(len(peers)):
+ subs[i] = ax.mibnode(readCallback, None, None, None)
+ return subs
+
+ # =====================================
+ # Misc data helpers (not part of the MIB proper)
+ # =====================================
+
+ def getPeerData(self): # TODO: cache!
+ # not fully implemented
+ peers = self.session.readstat()
+ peerdata = {}
+ for peer in peers:
+ try:
+ variables = self.session.readvar(peer.associd, raw=True)
+ except IOError as e:
+ continue
+ peerdata[peer.associd] = variables
+ return peerdata
+
def dolog(text, level):
if debug >= level:
@@ -640,6 +635,12 @@ class PacketControl:
self.packetEater()
while len(self.recievedPackets) > 0:
packet = self.recievedPackets.pop(0)
+ if packet.sessionID != self.sessionID:
+ resp = ax.ResponsePDU(True, packet.sessionID,
+ packet.transactioID, packet.packetID,
+ 0, ax.REPERR_NOT_OPEN, 0)
+ self.sendPacket(resp, False)
+ continue
ptype = packet.pduType
if ptype in self.pduHandlers:
self.pduHandlers[ptype](packet)
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/d9b515b39279fde347e5fbfd50f468f30c960c82...792b44fe9f09d704d43683e372304b6e51c72c04
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/d9b515b39279fde347e5fbfd50f468f30c960c82...792b44fe9f09d704d43683e372304b6e51c72c04
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20171120/2baeeebd/attachment.html>
More information about the vc
mailing list