Fix all warnings in source3 with gcc4.3.
[ira/wip.git] / source3 / utils / net_time.c
index f8eb2b45a086f38cde667419bc1b0a4cb23b74f7..b6198376afd2657c1595acbf3e6bfab2ec695440 100644 (file)
@@ -51,8 +51,10 @@ static time_t cli_servertime(const char *host, struct sockaddr_storage *pss, int
                fprintf(stderr,"Session request failed\n");
                goto done;
        }
-       if (!cli_negprot(cli)) {
-               fprintf(stderr,"Protocol negotiation failed\n");
+       status = cli_negprot(cli);
+       if (!NT_STATUS_IS_OK(status)) {
+               fprintf(stderr, "Protocol negotiation failed: %s\n",
+                       nt_errstr(status));
                goto done;
        }
 
@@ -93,10 +95,10 @@ static const char *systime(time_t t)
 int net_time_usage(struct net_context *c, int argc, const char **argv)
 {
        d_printf(
-"net time\n\tdisplays time on a server\n\n"\
-"net time system\n\tdisplays time on a server in a format ready for /bin/date\n\n"\
-"net time set\n\truns /bin/date with the time from the server\n\n"\
-"net time zone\n\tdisplays the timezone in hours from GMT on the remote computer\n\n"\
+"net time\n\tdisplays time on a server\n\n"
+"net time system\n\tdisplays time on a server in a format ready for /bin/date\n\n"
+"net time set\n\truns /bin/date with the time from the server\n\n"
+"net time zone\n\tdisplays the timezone in hours from GMT on the remote computer\n\n"
 "\n");
        net_common_flags_usage(c, argc, argv);
        return -1;
@@ -114,7 +116,9 @@ static int net_time_set(struct net_context *c, int argc, const char **argv)
        /* yes, I know this is cheesy. Use "net time system" if you want to
           roll your own. I'm putting this in as it works on a large number
           of systems and the user has a choice in whether its used or not */
-       asprintf(&cmd, "/bin/date %s", systime(t));
+       if (asprintf(&cmd, "/bin/date %s", systime(t)) == -1) {
+               return -1;
+       }
        result = system(cmd);
        if (result)
                d_fprintf(stderr, "%s failed.  Error was (%s)\n",
@@ -127,8 +131,17 @@ static int net_time_set(struct net_context *c, int argc, const char **argv)
 /* display the time on a remote box in a format ready for /bin/date */
 static int net_time_system(struct net_context *c, int argc, const char **argv)
 {
-       time_t t = nettime(c, NULL);
+       time_t t;
+
+       if (c->display_usage) {
+               d_printf("Usage:\n"
+                        "net time system\n"
+                        "    Output remote time server time in a format ready "
+                        "for /bin/date\n");
+               return 0;
+       }
 
+       t = nettime(c, NULL);
        if (t == 0) return -1;
 
        printf("%s\n", systime(t));
@@ -136,7 +149,7 @@ static int net_time_system(struct net_context *c, int argc, const char **argv)
        return 0;
 }
 
-/* display the time on a remote box in a format ready for /bin/date */
+/* display the remote time server's offset to UTC */
 static int net_time_zone(struct net_context *c, int argc, const char **argv)
 {
        int zone = 0;
@@ -144,6 +157,13 @@ static int net_time_zone(struct net_context *c, int argc, const char **argv)
        char zsign;
        time_t t;
 
+       if (c->display_usage) {
+               d_printf("Usage:\n"
+                        "net time zone\n"
+                        "   Display the remote time server's offset to UTC\n");
+               return 0;
+       }
+
        t = nettime(c, &zone);
 
        if (t == 0) return -1;
@@ -165,20 +185,48 @@ int net_time(struct net_context *c, int argc, const char **argv)
 {
        time_t t;
        struct functable func[] = {
-               {"SYSTEM", net_time_system},
-               {"SET", net_time_set},
-               {"ZONE", net_time_zone},
-               {"HELP", net_time_usage},
-               {NULL, NULL}
+               {
+                       "system",
+                       net_time_system,
+                       NET_TRANSPORT_LOCAL,
+                       "Display time ready for /bin/date",
+                       "net time system\n"
+                       "    Display time ready for /bin/date"
+               },
+               {
+                       "set",
+                       net_time_set,
+                       NET_TRANSPORT_LOCAL,
+                       "Set the system time from time server",
+                       "net time set\n"
+                       "    Set the system time from time server"
+               },
+               {
+                       "zone",
+                       net_time_zone,
+                       NET_TRANSPORT_LOCAL,
+                       "Display timezone offset from UTC",
+                       "net time zone\n"
+                       "    Display timezone offset from UTC"
+               },
+               {NULL, NULL, 0, NULL, NULL}
        };
 
        if (argc != 0) {
-               return net_run_function(c, argc, argv, func, net_time_usage);
+               return net_run_function(c, argc, argv, "net time", func);
+       }
+
+       if (c->display_usage) {
+               d_printf("Usage:\n");
+               d_printf("net time\n"
+                        "    Display the remote time server's time\n");
+               net_display_usage_from_functable(func);
+               return 0;
        }
 
        if (!c->opt_host && !c->opt_have_ip &&
            !find_master_ip(c->opt_target_workgroup, &c->opt_dest_ip)) {
-               d_fprintf(stderr, "Could not locate a time server.  Try "\
+               d_fprintf(stderr, "Could not locate a time server.  Try "
                                 "specifying a target host.\n");
                net_time_usage(c, argc,argv);
                return -1;