]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
nts: save server name in client dump file
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 29 Sep 2020 12:59:35 +0000 (14:59 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 1 Oct 2020 10:58:17 +0000 (12:58 +0200)
Save the NTS-KE server name and require it to match the name of the
instance loading the file.

nts_ntp_client.c
test/simulation/139-nts

index 42946887d8c0fe70c0fe1ae072af0400d14e90d8..ecc401e883fbddb1f1cc3465119b452a8f4d283a 100644 (file)
@@ -541,7 +541,7 @@ save_cookies(NNC_Instance inst)
   FILE *f;
   int i;
 
-  if (inst->num_cookies < 1 || !UTI_IsIPReal(&inst->nts_address.ip_addr))
+  if (inst->num_cookies < 1 || !inst->name || !UTI_IsIPReal(&inst->nts_address.ip_addr))
     return;
 
   dump_dir = CNF_GetNtsDumpDir();
@@ -558,9 +558,10 @@ save_cookies(NNC_Instance inst)
   context_time = inst->last_nke_success - SCH_GetLastEventMonoTime();
   context_time += UTI_TimespecToDouble(&now);
 
-  if (fprintf(f, "%s%.1f\n%s %d\n%u %d ",
-              DUMP_IDENTIFIER, context_time, UTI_IPToString(&inst->ntp_address->ip_addr),
-              inst->ntp_address->port, inst->context_id, (int)inst->context.algorithm) < 0 ||
+  if (fprintf(f, "%s%s\n%.1f\n%s %d\n%u %d ",
+              DUMP_IDENTIFIER, inst->name, context_time,
+              UTI_IPToString(&inst->ntp_address->ip_addr), inst->ntp_address->port,
+              inst->context_id, (int)inst->context.algorithm) < 0 ||
       !UTI_BytesToHex(inst->context.s2c.key, inst->context.s2c.length, buf, sizeof (buf)) ||
       fprintf(f, "%s ", buf) < 0 ||
       !UTI_BytesToHex(inst->context.c2s.key, inst->context.c2s.length, buf, sizeof (buf)) ||
@@ -621,6 +622,8 @@ load_cookies(NNC_Instance inst)
   inst->siv = NULL;
 
   if (!fgets(line, sizeof (line), f) || strcmp(line, DUMP_IDENTIFIER) != 0 ||
+      !fgets(line, sizeof (line), f) || UTI_SplitString(line, words, MAX_WORDS) != 1 ||
+        !inst->name || strcmp(words[0], inst->name) != 0 ||
       !fgets(line, sizeof (line), f) || UTI_SplitString(line, words, MAX_WORDS) != 1 ||
         sscanf(words[0], "%lf", &context_time) != 1 ||
       !fgets(line, sizeof (line), f) || UTI_SplitString(line, words, MAX_WORDS) != 2 ||
index 91c7f2b0a6a14b32aeb04d376fa824f959c51475..74b8981a86b8c0724943b553572fa97a30822cc9 100755 (executable)
@@ -63,7 +63,7 @@ check_file_messages "20.*123\.1.* 111 111 1111" 99 103 measurements.log || test_
 check_file_messages "20.*123\.1.* 111 001 0000" 0 0 measurements.log || test_fail
 check_file_messages "  2       1       .*      4460    " 350 390 log.packets || test_fail
 check_file_messages "." 6 6 ntskeys || test_fail
-check_file_messages "." 11 12 192.168.123.1.nts || test_fail
+check_file_messages "." 12 13 192.168.123.1.nts || test_fail
 rm -f tmp/measurements.log
 
 export CLKNETSIM_START_DATE=$(date -d 'Jan  1 00:00:00 UTC 2010 + 40000 sec' +'%s')
@@ -83,7 +83,7 @@ check_file_messages "20.*123\.1.* 111 001 0000" 0 0 measurements.log || test_fai
 check_file_messages "  2       1       .*      4460    " 6 10 log.packets || test_fail
 check_file_messages "^9\.......e+03    2       1       .*      4460    " 6 10 log.packets || test_fail
 check_file_messages "." 6 6 ntskeys || test_fail
-check_file_messages "." 11 12 192.168.123.1.nts || test_fail
+check_file_messages "." 12 13 192.168.123.1.nts || test_fail
 rm -f tmp/measurements.log
 
 client_conf="