[Git][NTPsec/ntpsec][packet-raw-mod] 2 commits: Bool-ify mac_authdecrypt
Ian Bruene
gitlab at mg.gitlab.com
Tue Apr 11 04:05:24 UTC 2017
Ian Bruene pushed to branch packet-raw-mod at NTPsec / ntpsec
Commits:
a737b1f1 by Matt Selsky at 2017-04-10T23:53:45-04:00
Bool-ify mac_authdecrypt
And removed unneeded casts
- - - - -
0d193918 by Ian Bruene at 2017-04-11T04:04:59+00:00
Added raw return mode to mode 6 parser
- - - - -
3 changed files:
- include/ntp_stdlib.h
- libntp/macencrypt.c
- pylib/packet.py
Changes:
=====================================
include/ntp_stdlib.h
=====================================
--- a/include/ntp_stdlib.h
+++ b/include/ntp_stdlib.h
@@ -77,7 +77,7 @@ int ntp_getopt_long(int argc, char* const argv[], const char *optstring,
const struct option *longopts, int *longindex);
/* a_md5encrypt.c */
-extern int mac_authdecrypt (int, uint8_t *, uint32_t *, int, int);
+extern bool mac_authdecrypt (int, uint8_t *, uint32_t *, int, int);
extern int mac_authencrypt (int, uint8_t *, uint32_t *, int);
extern void mac_setkey (keyid_t, int, const uint8_t *, size_t);
extern uint32_t addr2refid (sockaddr_u *);
=====================================
libntp/macencrypt.c
=====================================
--- a/libntp/macencrypt.c
+++ b/libntp/macencrypt.c
@@ -78,9 +78,9 @@ mac_authencrypt(
/*
* mac_authdecrypt - verify MD5 message authenticator
*
- * Returns one if digest valid, zero if invalid.
+ * Returns true if digest valid, false if invalid.
*/
-int
+bool
mac_authdecrypt(
int type, /* hash algorithm */
uint8_t *key, /* key pointer */
@@ -103,7 +103,7 @@ mac_authdecrypt(
if (!EVP_DigestInit_ex(ctx, EVP_get_digestbynid(type), NULL)) {
msyslog(LOG_ERR,
"MAC decrypt: digest init failed");
- return (0);
+ return false;
}
EVP_DigestUpdate(ctx, key, cache_secretsize);
EVP_DigestUpdate(ctx, (uint8_t *)pkt, (u_int)length);
@@ -112,9 +112,9 @@ mac_authdecrypt(
if ((u_int)size != len + 4) {
msyslog(LOG_ERR,
"MAC decrypt: MAC length error");
- return (0);
+ return false;
}
- return (int)ctmemeq(digest, (char *)pkt + length + 4, len);
+ return ctmemeq(digest, (char *)pkt + length + 4, len);
}
/*
=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -1243,7 +1243,7 @@ class ControlSession:
idlist.sort(key=lambda a: a.associd)
return idlist
- def __parse_varlist(self):
+ def __parse_varlist(self, raw=False):
"Parse a response as a textual varlist."
# Strip out NULs and binary garbage from text;
# ntpd seems prone to generate these, especially
@@ -1268,11 +1268,18 @@ class ControlSession:
var = pair[:eq].strip()
val = pair[eq+1:].strip().replace("\xae", ",")
try:
- val = int(val, 0)
+ if raw is True:
+ val = (int(val, 0), val)
+ else:
+ val = int(val, 0)
except ValueError:
try:
- valf = float(val)
- if var == "delay":
+ if raw is True:
+ valf = (float(val), val)
+ else:
+ valf = float(val)
+ if (var == "delay") and (raw is False):
+ # raw==false, if true str returned anyway
# hack to pass string version
# so printout can handle .3f vs .6f
items.append(("delay-s", val))
@@ -1280,6 +1287,8 @@ class ControlSession:
except ValueError:
if val[0] == '"' and val[-1] == '"':
val = val[1:-1]
+ if raw is True:
+ val = (val, val)
items.append((var, val))
except ValueError:
# Yes, ntpd really does emit bare tags for empty
@@ -1288,14 +1297,14 @@ class ControlSession:
return ntp.util.OrderedDict(items)
def readvar(self, associd=0, varlist=None,
- opcode=ntp.control.CTL_OP_READVAR):
+ opcode=ntp.control.CTL_OP_READVAR, raw=False):
"Read system vars from the host as a dict, or throw an exception."
if varlist is None:
qdata = ""
else:
qdata = ",".join(varlist)
self.doquery(opcode, associd=associd, qdata=qdata)
- return self.__parse_varlist()
+ return self.__parse_varlist(raw)
def config(self, configtext):
"Send configuration text to the daemon. Return True if accepted."
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/f211b380eac02ad0b16df07843af9ba0f0ebb9f2...0d193918f6bd03546c021f7a453c0a465b4befdd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170411/4b93dcfd/attachment.html>
More information about the vc
mailing list