[tor-commits] [tlsdate/debian-master] tlsdate: add optional --showtime support for "raw"

ioerror at torproject.org ioerror at torproject.org
Thu Oct 31 10:51:32 UTC 2013


commit eb5bdfc0f9980991a49151e9bb513f0e83b489e1
Author: Will Drewry <wad at chromium.org>
Date:   Fri Sep 13 15:57:10 2013 -0500

    tlsdate: add optional --showtime support for "raw"
    
    Add support for optional arguments to --showtime, "raw" and "human".
    
    Human readable output is what --showtime and -V do already.  Passing
    in --showtime=raw will tell tlsdate-helper to write the raw
    unix time directly to stdout in host byte order.
    
    The purpose of this change is to provide easier integration of
    privilege isolation for time setting.  If tlsdate is called from
    a wrapper, like tlsdated, it should be possible to pass the time back
    to a privileged time-setter with the minimum of needed parsing.
---
 src/tlsdate-helper.c |    7 +++++++
 src/tlsdate.c        |    7 ++++---
 src/tlsdate.h        |    1 +
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/tlsdate-helper.c b/src/tlsdate-helper.c
index cd44c97..4058f5e 100644
--- a/src/tlsdate-helper.c
+++ b/src/tlsdate-helper.c
@@ -1071,6 +1071,7 @@ main(int argc, char **argv)
   uint32_t server_time_s;
   int setclock;
   int showtime;
+  int showtime_raw;
   int timewarp;
   int leap;
 
@@ -1085,6 +1086,7 @@ main(int argc, char **argv)
   verbose = (0 != strcmp ("quiet", argv[5]));
   setclock = (0 == strcmp ("setclock", argv[7]));
   showtime = (0 == strcmp ("showtime", argv[8]));
+  showtime_raw = (0 == strcmp ("showtime=raw", argv[8]));
   timewarp = (0 == strcmp ("timewarp", argv[9]));
   leap = (0 == strcmp ("leapaway", argv[10]));
   proxy = (0 == strcmp ("none", argv[11]) ? NULL : argv[11]);
@@ -1205,6 +1207,11 @@ main(int argc, char **argv)
       "server or run it again\n", TLS_RTT_THRESHOLD);
   }
 
+  if (showtime_raw)
+  {
+    fwrite(&server_time_s, sizeof(server_time_s), 1, stdout);
+  }
+
   if (showtime)
   {
      struct tm  ltm;
diff --git a/src/tlsdate.c b/src/tlsdate.c
index c8bc09c..c19ef69 100644
--- a/src/tlsdate.c
+++ b/src/tlsdate.c
@@ -91,7 +91,7 @@ usage(void)
           " [-P|--protocol] [sslv23|sslv3|tlsv1]\n"
           " [-C|--certcontainer] [dirname|filename]\n"
           " [-v|--verbose]\n"
-          " [-V|--showtime]\n"
+          " [-V|--showtime] [human|raw]\n"
           " [-t|--timewarp]\n"
           " [-l|--leap]\n"
     " [-x|--proxy] [url]\n");
@@ -132,7 +132,7 @@ main(int argc, char **argv)
     static struct option long_options[] =
       {
         {"verbose", 0, 0, 'v'},
-        {"showtime", 0, 0, 'V'},
+        {"showtime", 2, 0, 'R'},
         {"skip-verification", 0, 0, 's'},
         {"help", 0, 0, 'h'},
         {"host", 0, 0, 'H'},
@@ -154,6 +154,7 @@ main(int argc, char **argv)
     switch (c) {
       case 'v': verbose = 1; break;
       case 'V': showtime = 1; break;
+      case 'R': showtime = (optarg && 0 == strcmp("raw", optarg) ? 2:1); break;
       case 's': ca_racket = 0; break;
       case 'h': usage(); exit(1); break;
       case 'H': host = optarg; break;
@@ -190,7 +191,7 @@ main(int argc, char **argv)
     (verbose ? "verbose" : "quiet"),
     ca_cert_container,
     (setclock ? "setclock" : "dont-set-clock"),
-    (showtime ? "showtime" : "no-showtime"),
+    (showtime ? (showtime == 2 ? "showtime=raw" : "showtime") : "no-showtime"),
     (timewarp ? "timewarp" : "no-fun"),
     (leap ? "leapaway" : "holdfast"),
     (proxy ? proxy : "none"),
diff --git a/src/tlsdate.h b/src/tlsdate.h
index 978396d..ccd8e51 100644
--- a/src/tlsdate.h
+++ b/src/tlsdate.h
@@ -14,6 +14,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <getopt.h>
 #include <time.h>
 #include <unistd.h>





More information about the tor-commits mailing list