utils: Fix 'net time' segfault.
authorAndreas Schneider <asn@samba.org>
Tue, 13 Jan 2015 16:04:26 +0000 (17:04 +0100)
committerMichael Adam <obnox@samba.org>
Mon, 19 Jan 2015 05:48:05 +0000 (06:48 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11058

This is part two of the bugfix. Make sure we pass the IP we found to
cli_servertime(). Hence we always pass at least one of name or IP.

Pair-Programmed-With: Michael Adam <obnox@samba.org>

Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/utils/net_time.c

index 56ce8f71ad669ce07cf7443ffac6c34e5ef7854f..595d903c0be5f05471cc20bb28d8cb5316e201fc 100644 (file)
@@ -226,16 +226,23 @@ int net_time(struct net_context *c, int argc, const char **argv)
                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 "
-                                   "specifying a target host.\n"));
-               net_time_usage(c, argc,argv);
-               return -1;
+       if (c->opt_host == NULL && !c->opt_have_ip) {
+               bool ok;
+
+               ok = find_master_ip(c->opt_target_workgroup, &c->opt_dest_ip);
+               if (!ok) {
+                       d_fprintf(stderr,
+                                 _("Could not locate a time server.  "
+                                   "Try specifying a target host.\n"));
+                       net_time_usage(c, argc, argv);
+                       return -1;
+               }
+               c->opt_have_ip = true;
        }
 
        /* default - print the time */
-       t = cli_servertime(c->opt_host, c->opt_have_ip? &c->opt_dest_ip : NULL,
+       t = cli_servertime(c->opt_host,
+                          c->opt_have_ip? &c->opt_dest_ip : NULL,
                           NULL);
        if (t == 0) return -1;