[Git][NTPsec/ntpsec][master] 2 commits: Instrument ntpq a little to make it easier to reverse-engineer.

Eric S. Raymond gitlab at mg.gitlab.com
Mon Oct 17 02:26:33 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
fc34ea36 by Eric S. Raymond at 2016-10-16T20:43:42-04:00
Instrument ntpq a little to make it easier to reverse-engineer.

- - - - -
09e68d75 by Eric S. Raymond at 2016-10-16T22:25:51-04:00
Add a method to read and analyze peer status packets.

- - - - -


3 changed files:

- ntpq/ntpq.c
- ntpq/pyntpq
- pylib/packet.py


Changes:

=====================================
ntpq/ntpq.c
=====================================
--- a/ntpq/ntpq.c
+++ b/ntpq/ntpq.c
@@ -1213,6 +1213,25 @@ sendrequest(
 		return 1;
 	}
 
+	if (debug >= 3) {
+	    static const char *opnames[] = {
+		"CTL_OP_UNSPEC",
+		"CTL_OP_READSTAT",
+		"CTL_OP_READVAR",
+		"CTL_OP_WRITEVAR",
+		"CTL_OP_READCLOCK",
+		"CTL_OP_WRITECLOCK",
+		"CTL_OP_SETTRAP",
+		"CTL_OP_ASYNCMSG",
+		"CTL_OP_CONFIGURE",
+		"CTL_OP_READ_MRU",
+		"CTL_OP_READ_ORDLIST_A",
+		"CTL_OP_REQ_NONCE",
+	    };
+	    int oi = (opcode >= (int)(sizeof(opnames)/sizeof(opnames[0])) ? 0 : opcode);
+	    printf("Sending %s operation for associd %d\n",
+		   opnames[oi], associd);
+	}
 	/*
 	 * Fill in the packet
 	 */


=====================================
ntpq/pyntpq
=====================================
--- a/ntpq/pyntpq
+++ b/ntpq/pyntpq
@@ -243,7 +243,7 @@ usage: timeout [ msec ]
 
     def collect_display(self, associd, variables, decodestatus):
         "Query and display a collection of variables from the system."
-        msg = self.session.readvars([v[0] for v in variables])
+        msg = self.session.readvar(associd, [v[0] for v in variables])
         if type(msg) == str:
             print(msg)
             return
@@ -646,7 +646,7 @@ usage: readvar [ assocID ] [ varname1 ] [ varname2 ] [ varname3 ]
 
     def do_rv(self, line):
         "read system or peer variables"
-        pass
+        self.do_readvar(line)
 
     def help_rv(self):
         sys.stdout.write("""\
@@ -773,7 +773,7 @@ usage: pstats assocID
 
     def do_peers(self, line):
         "obtain and print a list of the server's peers [IP version]"
-        pass
+        print(self.session.readstat())
 
     def help_peers(self):
         sys.stdout.write("""\


=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -532,13 +532,27 @@ class ntpq_session:
         # Return None on success, otherwise an error string
         return res
 
-    def readvars(self, varlist=None):
+    def readstat(self, associd=0):
+        "Read peer status."
+        self.doquery(opcode=CTL_OP_READSTAT, associd=associd, quiet=True)
+        if self.response.startswith("*"):
+            return self.response
+        idlist = []
+        if associd == 0:
+            print("I see %d chars" % len(self.response))
+            for i in range(len(self.response)//4):
+                data = self.response[4*i:4*i+4]
+                print("Foo! %d %d %s" % (i, len(data), data))
+                idlist.append(struct.unpack("!HH", data))
+        return idlist
+
+    def readvar(self, associd=0, varlist=None):
         "Read system vars from the host as a dict, or return an error string."
         if varlist == None:
             qdata = ""
         else:
             qdata = ",".join(varlist)
-        self.doquery(opcode=CTL_OP_READVAR, qdata=qdata, quiet=True)
+        self.doquery(opcode=CTL_OP_READVAR, associd=associd, qdata=qdata, quiet=True)
         if self.response.startswith("*"):
             return self.response
         else:



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/7dfc1fc46dd2b01e5a90d22f179f5cea6c4b32a6...09e68d7527f5c82fe6ec9f5f0a028c47f2968068
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161017/55be2cdb/attachment.html>


More information about the vc mailing list