[Git][NTPsec/ntpsec][master] 4 commits: More Python 3 correctness.

Eric S. Raymond gitlab at mg.gitlab.com
Sun Nov 27 10:41:52 UTC 2016


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


Commits:
5b8a226f by Eric S. Raymond at 2016-11-27T05:40:41-05:00
More Python 3 correctness.

- - - - -
77c8a205 by Eric S. Raymond at 2016-11-27T05:40:41-05:00
Pass baudrate into the refclock_open() function correctly.

- - - - -
82220634 by Eric S. Raymond at 2016-11-27T05:40:41-05:00
In pyntpdig, make repr() for packets work.

- - - - -
c233afea by Eric S. Raymond at 2016-11-27T05:40:41-05:00
Document --early-droproot.

- - - - -


3 changed files:

- INSTALL
- ntpd/refclock_nmea.c
- pylib/packet.py


Changes:

=====================================
INSTALL
=====================================
--- a/INSTALL
+++ b/INSTALL
@@ -226,6 +226,15 @@ of options.
 refclocks are enabled with `--refclock=<n1,n2,n3..> or --refclock=all'
 `waf configure --list' will print a list of available refclocks.
 
+=== --enable-early-droproot ===
+
+Drop root privileges as early as possible.  This requires the refclock
+devices to be owned by the same owner or group that ntpd will be
+running under (most likely that group will be named "ntp") so that it
+can still open the devices.  This can be accomplished by adding
+`GROUP="ntp"` or `OWNER="ntp"` to the udev rules that create the
+device symlinks for the refclocks.
+
 == Developer options ==
 
 --enable-debug-gdb::


=====================================
ntpd/refclock_nmea.c
=====================================
--- a/ntpd/refclock_nmea.c
+++ b/ntpd/refclock_nmea.c
@@ -475,7 +475,7 @@ nmea_start(
 	/* Open serial port. Use CLK line discipline, if available. */
 	snprintf(device, sizeof(device), DEVICE, unit);
 	pp->io.fd = refclock_open(peer->path ? peer->path : device,
-				  peer->baud ? peer->baud : baudrate,
+				  baudrate,
 				  LDISC_CLK);
 	if (0 >= pp->io.fd) {
 		pp->io.fd = nmead_open(device);


=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -180,9 +180,10 @@ A Mode 6 packet cannot have extension fields.
 """
 # SPDX-License-Identifier: BSD-2-clause
 from __future__ import print_function, division
-import sys, socket, select, struct, collections
+import sys, socket, select, struct, collections, string
 import getpass, hashlib, time
 from ntp.ntpc import lfptofloat
+import ntp.util
 
 # General notes on Python 2/3 compatibility:
 #
@@ -478,7 +479,7 @@ class SyncPacket(Packet):
 
     def refid_as_string(self):
         "Sometimes it's a clock name or KOD type"
-        return polystr(struct.pack("BBBB" % self.refid_octets()))
+        return polystr(struct.pack(*(("BBBB",) + self.refid_octets())))
 
     def refid_as_address(self):
         "Sometimes it's an IPV4 address."
@@ -495,11 +496,11 @@ class SyncPacket(Packet):
 
     def __repr__(self):
         "Represent a posixized sync packet in an eyeball-friendly format."
-        r = "<NTP:%s:%d%:%d" % (self.leap(), self.version(), self.mode())
-        r += "%f:%f:" % (self.root_delay, self.root_dispersion)
+        r = "<NTP:%s:%d:%d" % (self.leap(), self.version(), self.mode())
+        r += "%f:%f" % (self.root_delay, self.root_dispersion)
         rs = self.refid_as_string()
-        if not rs.isprint():
-            rd = self.refid_as_address()
+        if not all(c in string.printable for c in rs):
+            rs = self.refid_as_address()
         r += ":" + rs 
         r += ":" + ntp.util.rfc3339(SyncPacket.ntp_to_posix(self.reference_timestamp))
         r += ":" + ntp.util.rfc3339(SyncPacket.ntp_to_posix(self.origin_timestamp))
@@ -626,7 +627,7 @@ def dump_hex_printable(xdata):
         restart = i
         for idx in range(16):
             if idx < llen:
-                sys.stdout.write("%02x " % ord(xdata[i]))
+                sys.stdout.write("%02x " % polyord(xdata[i]))
                 i += 1
             else:
                 sys.stdout.write("   ")
@@ -1105,7 +1106,7 @@ class ControlSession:
         # in reslist responses.
         response = ""
         for c in self.response:
-            if ord(c) > 0 and ord(c) < 127:
+            if polyord(c) > 0 and polyord(c) < 127:
                 response += c
         response = response.rstrip()
         items = []



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/1c7af70bad933803ec1ad83b2d6b2589283355d3...c233afea21be10a23316aecb9d5c8771d5746ac1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161127/e5602a8a/attachment.html>


More information about the vc mailing list