From 32ba2c889fb7eaa0dde8a2951572da7e2a4da3ce Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Dec 2001 05:21:50 +0000 Subject: added a net time command. Allow display or set of system time based on a SMB server particularly useful for ADS is: net time set -S DOMAIN#1B this makes kerberos clock skew problems go away :) (This used to be commit b3ba2293d0e4eac3b6408c3abc3dcacfa3f67fe4) --- source3/utils/net_time.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 source3/utils/net_time.c (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c new file mode 100644 index 0000000000..f7f3f894b0 --- /dev/null +++ b/source3/utils/net_time.c @@ -0,0 +1,151 @@ +/* + Samba Unix/Linux SMB client library + Version 3.0 + net time command + Copyright (C) 2001 Andrew Tridgell (tridge@samba.org) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "includes.h" +#include "../utils/net.h" + + +/* + return the time on a server. This does not require any authentication +*/ +static time_t cli_servertime(const char *host, struct in_addr *ip) +{ + struct nmb_name calling, called; + time_t ret = 0; + extern pstring global_myname; + struct cli_state *cli = NULL; + + cli = cli_initialise(NULL); + if (!cli || !cli_connect(cli, host, ip)) goto done; + + make_nmb_name(&calling, global_myname, 0x0); + if (host) { + make_nmb_name(&called, host, 0x20); + } else { + make_nmb_name(&called, "*SMBSERVER", 0x20); + } + + if (!cli_session_request(cli, &calling, &called)) goto done; + if (!cli_negprot(cli)) goto done; + + ret = cli->servertime; + + cli_shutdown(cli); + +done: + if (cli) cli_shutdown(cli); + return ret; +} + +/* find the servers time on the opt_host host */ +static time_t nettime(void) +{ + extern BOOL opt_have_ip; + extern struct in_addr opt_dest_ip; + extern char *opt_host; + return cli_servertime(opt_host, opt_have_ip? &opt_dest_ip : NULL); +} + +/* return a time as a string ready to be passed to date -u */ +static char *systime(time_t t) +{ + static char s[100]; + struct tm *tm; + + tm = gmtime(&t); + + snprintf(s, sizeof(s), "%02d%02d%02d%02d%04d.%02d", + tm->tm_mon+1, tm->tm_mday, tm->tm_hour, + tm->tm_min, tm->tm_year + 1900, tm->tm_sec); + return s; +} + +int net_time_usage(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 -u with the time from the server\n\n"\ +"\n"); + general_rap_usage(argc, argv); + return -1; +} + +/* try to set the system clock using /bin/date */ +static int net_time_set(int argc, const char **argv) +{ + time_t t = nettime(); + char *cmd; + + if (t == 0) { + d_printf("Can't contact server\n"); + return -1; + } + + asprintf(&cmd, "/bin/date -u %s", systime(t)); + system(cmd); + free(cmd); + + return 0; +} + +/* display the time on a remote box in a format ready for /bin/date */ +static int net_time_system(int argc, const char **argv) +{ + time_t t = nettime(); + + if (t == 0) { + d_printf("Can't contact server\n"); + return -1; + } + + printf("%s\n", systime(t)); + + return 0; +} + +/* display or set the time on a host */ +int net_time(int argc, const char **argv) +{ + time_t t; + extern BOOL opt_have_ip; + extern struct in_addr opt_dest_ip; + extern char *opt_host; + struct functable func[] = { + {"SYSTEM", net_time_system}, + {"SET", net_time_set}, + {NULL, NULL} + }; + + if (!opt_host && !opt_have_ip) { + d_printf("You must specify a hostname or IP\n"); + return -1; + } + + if (argc != 0) { + return net_run_function(argc, argv, func, net_time_usage); + } + + /* default - print the time */ + t = cli_servertime(opt_host, opt_have_ip? &opt_dest_ip : NULL); + + d_printf("%s", ctime(&t)); + return 0; +} -- cgit From e5dbe13b58422535569476443ddb20250bb0114c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Dec 2001 05:28:56 +0000 Subject: added a comment about /bin/date (This used to be commit 2183c1f3b09db5c078327050279130ac825c71f8) --- source3/utils/net_time.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index f7f3f894b0..6c5f38c17a 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -98,7 +98,10 @@ static int net_time_set(int argc, const char **argv) d_printf("Can't contact server\n"); return -1; } - + + /* 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 -u %s", systime(t)); system(cmd); free(cmd); -- cgit From 6939dd050bdfc85fa632272594b2076f87b58760 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Dec 2001 05:47:26 +0000 Subject: better error handling (This used to be commit 75621d528433a9c1af3eada0b748dfbcfdb8ad62) --- source3/utils/net_time.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 6c5f38c17a..8d0c854e28 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -33,7 +33,12 @@ static time_t cli_servertime(const char *host, struct in_addr *ip) struct cli_state *cli = NULL; cli = cli_initialise(NULL); - if (!cli || !cli_connect(cli, host, ip)) goto done; + if (!cli) goto done; + + if (!cli_connect(cli, host, ip)) { + fprintf(stderr,"Can't contact server\n"); + goto done; + } make_nmb_name(&calling, global_myname, 0x0); if (host) { @@ -42,8 +47,14 @@ static time_t cli_servertime(const char *host, struct in_addr *ip) make_nmb_name(&called, "*SMBSERVER", 0x20); } - if (!cli_session_request(cli, &calling, &called)) goto done; - if (!cli_negprot(cli)) goto done; + if (!cli_session_request(cli, &calling, &called)) { + fprintf(stderr,"Session request failed\n"); + goto done; + } + if (!cli_negprot(cli)) { + fprintf(stderr,"Protocol negotiation failed\n"); + goto done; + } ret = cli->servertime; @@ -94,10 +105,7 @@ static int net_time_set(int argc, const char **argv) time_t t = nettime(); char *cmd; - if (t == 0) { - d_printf("Can't contact server\n"); - return -1; - } + if (t == 0) return -1; /* 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 @@ -114,10 +122,7 @@ static int net_time_system(int argc, const char **argv) { time_t t = nettime(); - if (t == 0) { - d_printf("Can't contact server\n"); - return -1; - } + if (t == 0) return -1; printf("%s\n", systime(t)); @@ -148,6 +153,7 @@ int net_time(int argc, const char **argv) /* default - print the time */ t = cli_servertime(opt_host, opt_have_ip? &opt_dest_ip : NULL); + if (t == 0) return -1; d_printf("%s", ctime(&t)); return 0; -- cgit From 3607b3ccab8d7f5c0dbc455dafbfdea5b8e72e37 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Dec 2001 10:37:00 +0000 Subject: prevent double free (This used to be commit 3628a978d1881aa2a0939594b1c752475468965e) --- source3/utils/net_time.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 8d0c854e28..f99eb9054d 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -58,8 +58,6 @@ static time_t cli_servertime(const char *host, struct in_addr *ip) ret = cli->servertime; - cli_shutdown(cli); - done: if (cli) cli_shutdown(cli); return ret; -- cgit From 60b53b3f6f96c90533264f9dcbfc0edb61f41b7e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 12 Dec 2001 09:37:17 +0000 Subject: added "net time zone" command to show the timezone on a computer (This used to be commit 4e2691b1c13a7db4770effa6eddeb19adb47f8ae) --- source3/utils/net_time.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index f99eb9054d..20d51e2a41 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -25,7 +25,7 @@ /* return the time on a server. This does not require any authentication */ -static time_t cli_servertime(const char *host, struct in_addr *ip) +static time_t cli_servertime(const char *host, struct in_addr *ip, int *zone) { struct nmb_name calling, called; time_t ret = 0; @@ -57,6 +57,7 @@ static time_t cli_servertime(const char *host, struct in_addr *ip) } ret = cli->servertime; + if (zone) *zone = cli->serverzone; done: if (cli) cli_shutdown(cli); @@ -64,12 +65,12 @@ done: } /* find the servers time on the opt_host host */ -static time_t nettime(void) +static time_t nettime(int *zone) { extern BOOL opt_have_ip; extern struct in_addr opt_dest_ip; extern char *opt_host; - return cli_servertime(opt_host, opt_have_ip? &opt_dest_ip : NULL); + return cli_servertime(opt_host, opt_have_ip? &opt_dest_ip : NULL, zone); } /* return a time as a string ready to be passed to date -u */ @@ -92,6 +93,7 @@ int net_time_usage(int argc, const char **argv) "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 -u 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"); general_rap_usage(argc, argv); return -1; @@ -100,7 +102,7 @@ int net_time_usage(int argc, const char **argv) /* try to set the system clock using /bin/date */ static int net_time_set(int argc, const char **argv) { - time_t t = nettime(); + time_t t = nettime(NULL); char *cmd; if (t == 0) return -1; @@ -118,7 +120,7 @@ static int net_time_set(int argc, const char **argv) /* display the time on a remote box in a format ready for /bin/date */ static int net_time_system(int argc, const char **argv) { - time_t t = nettime(); + time_t t = nettime(NULL); if (t == 0) return -1; @@ -127,6 +129,27 @@ static int net_time_system(int argc, const char **argv) return 0; } +/* display the time on a remote box in a format ready for /bin/date */ +static int net_time_zone(int argc, const char **argv) +{ + int zone = 0; + time_t t; + + t = nettime(&zone); + + if (t == 0) return -1; + + zone /= 60; + + if (zone % 60 == 0) { + printf("%+d\n", -zone / 60); + } else { + printf("%+.1f\n", ((double)-zone) / 60); + } + + return 0; +} + /* display or set the time on a host */ int net_time(int argc, const char **argv) { @@ -137,6 +160,7 @@ int net_time(int argc, const char **argv) struct functable func[] = { {"SYSTEM", net_time_system}, {"SET", net_time_set}, + {"ZONE", net_time_zone}, {NULL, NULL} }; @@ -150,7 +174,7 @@ int net_time(int argc, const char **argv) } /* default - print the time */ - t = cli_servertime(opt_host, opt_have_ip? &opt_dest_ip : NULL); + t = cli_servertime(opt_host, opt_have_ip? &opt_dest_ip : NULL, NULL); if (t == 0) return -1; d_printf("%s", ctime(&t)); -- cgit From d23723a3e4127763867e72cf6d08084afd5e8146 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 14 Dec 2001 01:15:14 +0000 Subject: don't use -u switch to /bin/date - too many systems don't honor it (This used to be commit 0839cf03a92673b38f1afa103271c708fa7162a2) --- source3/utils/net_time.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 20d51e2a41..dea1bcd677 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -73,13 +73,13 @@ static time_t nettime(int *zone) return cli_servertime(opt_host, opt_have_ip? &opt_dest_ip : NULL, zone); } -/* return a time as a string ready to be passed to date -u */ +/* return a time as a string ready to be passed to /bin/date */ static char *systime(time_t t) { static char s[100]; struct tm *tm; - tm = gmtime(&t); + tm = localtime(&t); snprintf(s, sizeof(s), "%02d%02d%02d%02d%04d.%02d", tm->tm_mon+1, tm->tm_mday, tm->tm_hour, @@ -92,7 +92,7 @@ int net_time_usage(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 -u with the time from the server\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"); general_rap_usage(argc, argv); @@ -110,7 +110,7 @@ static int net_time_set(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 -u %s", systime(t)); + asprintf(&cmd, "/bin/date %s", systime(t)); system(cmd); free(cmd); -- cgit From 9c7b042f31ee63a8b00aeeb9b530d1a405c715f5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 4 Jan 2002 23:02:14 +0000 Subject: print the timezone in the same format as 'date +%z' - much better for scripting (This used to be commit faa1b222f170abe34f6930bb3493cbe8b4df4082) --- source3/utils/net_time.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index dea1bcd677..02007c32ec 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -133,19 +133,22 @@ static int net_time_system(int argc, const char **argv) static int net_time_zone(int argc, const char **argv) { int zone = 0; + int hours, mins; + char zsign; time_t t; t = nettime(&zone); if (t == 0) return -1; + zsign = (zone > 0) ? '-' : '+'; + if (zone < 0) zone = -zone; + zone /= 60; + hours = zone / 60; + mins = zone % 60; - if (zone % 60 == 0) { - printf("%+d\n", -zone / 60); - } else { - printf("%+.1f\n", ((double)-zone) / 60); - } + printf("%c%02d%02d\n", zsign, hours, mins); return 0; } -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/utils/net_time.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 02007c32ec..a3a230e0da 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -1,6 +1,5 @@ /* Samba Unix/Linux SMB client library - Version 3.0 net time command Copyright (C) 2001 Andrew Tridgell (tridge@samba.org) -- cgit From bb38f48f6f2b5a5b8803c622e40107bb15876625 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 15 Mar 2002 20:03:07 +0000 Subject: Some help cleanups. Formatting and consistency issues. Line up text nicely, and make 'net help rap user' the same as 'net rap user help'...stuff like that (This used to be commit 17775dae28c724b11cc73f2aeac5f07f9656046c) --- source3/utils/net_time.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index a3a230e0da..3f5532109c 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -94,7 +94,7 @@ int net_time_usage(int argc, const char **argv) "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"); - general_rap_usage(argc, argv); + net_common_flags_usage(argc, argv); return -1; } @@ -168,6 +168,7 @@ int net_time(int argc, const char **argv) if (!opt_host && !opt_have_ip) { d_printf("You must specify a hostname or IP\n"); + net_time_usage(argc,argv); return -1; } -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/utils/net_time.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 3f5532109c..13c75c80b0 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -166,8 +166,10 @@ int net_time(int argc, const char **argv) {NULL, NULL} }; - if (!opt_host && !opt_have_ip) { - d_printf("You must specify a hostname or IP\n"); + if (!opt_host && !opt_have_ip && + !find_master_ip(opt_target_workgroup, &opt_dest_ip)) { + d_printf("Could not locate a time server. Try "\ + "specifying a target host.\n"); net_time_usage(argc,argv); return -1; } -- cgit From 2f194322d419350f35a48dff750066894d68eccf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Nov 2002 23:20:50 +0000 Subject: Removed global_myworkgroup, global_myname, global_myscope. Added liberal dashes of const. This is a rather large check-in, some things may break. It does compile though :-). Jeremy. (This used to be commit f755711df8f74f9b8e8c1a2b0d07d02a931eeb89) --- source3/utils/net_time.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 13c75c80b0..4cf923b1f7 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -28,7 +28,6 @@ static time_t cli_servertime(const char *host, struct in_addr *ip, int *zone) { struct nmb_name calling, called; time_t ret = 0; - extern pstring global_myname; struct cli_state *cli = NULL; cli = cli_initialise(NULL); @@ -39,7 +38,7 @@ static time_t cli_servertime(const char *host, struct in_addr *ip, int *zone) goto done; } - make_nmb_name(&calling, global_myname, 0x0); + make_nmb_name(&calling, global_myname(), 0x0); if (host) { make_nmb_name(&called, host, 0x20); } else { -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/utils/net_time.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 4cf923b1f7..40619a0796 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -65,9 +65,6 @@ done: /* find the servers time on the opt_host host */ static time_t nettime(int *zone) { - extern BOOL opt_have_ip; - extern struct in_addr opt_dest_ip; - extern char *opt_host; return cli_servertime(opt_host, opt_have_ip? &opt_dest_ip : NULL, zone); } @@ -155,9 +152,6 @@ static int net_time_zone(int argc, const char **argv) int net_time(int argc, const char **argv) { time_t t; - extern BOOL opt_have_ip; - extern struct in_addr opt_dest_ip; - extern char *opt_host; struct functable func[] = { {"SYSTEM", net_time_system}, {"SET", net_time_set}, -- cgit From 3a5dc7c2ecacecf7dd0cfd71ff1bb298d70b391b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 23 Jul 2003 12:33:59 +0000 Subject: convert snprintf() calls using pstrings & fstrings to pstr_sprintf() and fstr_sprintf() to try to standardize. lots of snprintf() calls were using len-1; some were using len. At least this helps to be consistent. (This used to be commit 9f835b85dd38cbe655eb19021ff763f31886ac00) --- source3/utils/net_time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 40619a0796..45c1783805 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -71,12 +71,12 @@ static time_t nettime(int *zone) /* return a time as a string ready to be passed to /bin/date */ static char *systime(time_t t) { - static char s[100]; + static fstring s; struct tm *tm; tm = localtime(&t); - snprintf(s, sizeof(s), "%02d%02d%02d%02d%04d.%02d", + fstr_sprintf(s, "%02d%02d%02d%02d%04d.%02d", tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_year + 1900, tm->tm_sec); return s; -- cgit From b4cf9e95059071df49b34ff8574e48cb96f42da1 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 7 Oct 2004 04:01:18 +0000 Subject: r2835: Since we always have -I. and -I$(srcdir) in CFLAGS, we can get rid of '..' from all #include preprocessor commands. This fixes bugzilla #1880 where OpenVMS gets confused about the '.' characters. (This used to be commit 7f161702fa4916979602cc0295919b541912acd6) --- source3/utils/net_time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 45c1783805..691adcea00 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -18,7 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "includes.h" -#include "../utils/net.h" +#include "utils/net.h" /* -- cgit From c42be9fd38556a1cc2e16c8d763a592beb863806 Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Tue, 17 Jan 2006 21:22:00 +0000 Subject: r12986: Use d_fprintf(stderr, ...) for any error message in net. All 'usage' messages are still printed to stdout. Fix some compiler warnings for system() calls where we didn't used the return code. Add appropriate error messages and return with the error code we got from system() or NT_STATUS_UNSUCCESSFUL. (This used to be commit f650e3bdafc4c6bcd7eb4bcf8b6b885b979919eb) --- source3/utils/net_time.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 691adcea00..1a7116d447 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -99,6 +99,7 @@ static int net_time_set(int argc, const char **argv) { time_t t = nettime(NULL); char *cmd; + int result; if (t == 0) return -1; @@ -106,10 +107,13 @@ static int net_time_set(int argc, const char **argv) 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)); - system(cmd); + result = system(cmd); + if (result) + d_fprintf(stderr, "%s failed. Error was (%s)\n", + cmd, strerror(errno)); free(cmd); - return 0; + return result; } /* display the time on a remote box in a format ready for /bin/date */ @@ -161,7 +165,7 @@ int net_time(int argc, const char **argv) if (!opt_host && !opt_have_ip && !find_master_ip(opt_target_workgroup, &opt_dest_ip)) { - d_printf("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(argc,argv); return -1; -- cgit From a1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Jun 2006 21:36:49 +0000 Subject: r16230: Fix Klocwork #861 and others. localtime and asctime can return NULL. Ensure we check all returns correctly. Jeremy. (This used to be commit 6c61dc8ed6d84f310ef391fb7700e93ef42c4afc) --- source3/utils/net_time.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 1a7116d447..f6486286a6 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -69,12 +69,15 @@ static time_t nettime(int *zone) } /* return a time as a string ready to be passed to /bin/date */ -static char *systime(time_t t) +static const char *systime(time_t t) { static fstring s; struct tm *tm; tm = localtime(&t); + if (!tm) { + return "unknown"; + } fstr_sprintf(s, "%02d%02d%02d%02d%04d.%02d", tm->tm_mon+1, tm->tm_mday, tm->tm_hour, -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/utils/net_time.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index f6486286a6..f6269627da 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -30,8 +30,10 @@ static time_t cli_servertime(const char *host, struct in_addr *ip, int *zone) time_t ret = 0; struct cli_state *cli = NULL; - cli = cli_initialise(NULL); - if (!cli) goto done; + cli = cli_initialise(); + if (!cli) { + goto done; + } if (!cli_connect(cli, host, ip)) { fprintf(stderr,"Can't contact server\n"); @@ -58,7 +60,9 @@ static time_t cli_servertime(const char *host, struct in_addr *ip, int *zone) if (zone) *zone = cli->serverzone; done: - if (cli) cli_shutdown(cli); + if (cli) { + cli_shutdown(cli); + } return ret; } -- cgit From ce02d0dfcbeeeec316578322257d998589090c6f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 20 Jun 2007 17:38:42 +0000 Subject: r23554: Fix bug #4711 by makeing cli_connect return an NTSTATUS. Long overdue fix.... Jeremy. (This used to be commit 073fdc5a58139796dbaa7ea9833dca5308f11282) --- source3/utils/net_time.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index f6269627da..5e952780d3 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -29,14 +29,16 @@ static time_t cli_servertime(const char *host, struct in_addr *ip, int *zone) struct nmb_name calling, called; time_t ret = 0; struct cli_state *cli = NULL; + NTSTATUS status; cli = cli_initialise(); if (!cli) { goto done; } - if (!cli_connect(cli, host, ip)) { - fprintf(stderr,"Can't contact server\n"); + status = cli_connect(cli, host, ip); + if (!NT_STATUS_IS_OK(status)) { + fprintf(stderr,"Can't contact server %s. Error %s\n", host, nt_errstr(status)); goto done; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/utils/net_time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 5e952780d3..7426e49ccc 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/utils/net_time.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 7426e49ccc..510807730e 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + along with this program. If not, see . */ #include "includes.h" #include "utils/net.h" -- cgit From f88b7a076be74a29a3bf876b4e2705f4a1ecf42b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Oct 2007 14:16:54 -0700 Subject: This is a large patch (sorry). Migrate from struct in_addr to struct sockaddr_storage in most places that matter (ie. not the nmbd and NetBIOS lookups). This passes make test on an IPv4 box, but I'll have to do more work/testing on IPv6 enabled boxes. This should now give us a framework for testing and finishing the IPv6 migration. It's at the state where someone with a working IPv6 setup should (theorecically) be able to type : smbclient //ipv6-address/share and have it work. Jeremy. (This used to be commit 98e154c3125d5732c37a72d74b0eb5cd7b6155fd) --- source3/utils/net_time.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 510807730e..7375206af6 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -23,7 +23,7 @@ /* return the time on a server. This does not require any authentication */ -static time_t cli_servertime(const char *host, struct in_addr *ip, int *zone) +static time_t cli_servertime(const char *host, struct sockaddr_storage *pss, int *zone) { struct nmb_name calling, called; time_t ret = 0; @@ -35,7 +35,7 @@ static time_t cli_servertime(const char *host, struct in_addr *ip, int *zone) goto done; } - status = cli_connect(cli, host, ip); + status = cli_connect(cli, host, pss); if (!NT_STATUS_IS_OK(status)) { fprintf(stderr,"Can't contact server %s. Error %s\n", host, nt_errstr(status)); goto done; @@ -83,9 +83,9 @@ static const char *systime(time_t t) if (!tm) { return "unknown"; } - - fstr_sprintf(s, "%02d%02d%02d%02d%04d.%02d", - tm->tm_mon+1, tm->tm_mday, tm->tm_hour, + + fstr_sprintf(s, "%02d%02d%02d%02d%04d.%02d", + tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_year + 1900, tm->tm_sec); return s; } @@ -110,8 +110,8 @@ static int net_time_set(int argc, const char **argv) int result; if (t == 0) return -1; - - /* yes, I know this is cheesy. Use "net time system" if you want to + + /* 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)); -- cgit From f5769109447d8da0f09b102d444a816ad97a00dc Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Fri, 9 May 2008 23:22:12 +0200 Subject: net: Remove globals (This used to be commit 1e9319cf88b65a2a8d4f5099a1fe5297e405ed2e) --- source3/utils/net_time.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 7375206af6..48417fbc0f 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -14,8 +14,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - + along with this program. If not, see . +*/ #include "includes.h" #include "utils/net.h" @@ -68,9 +68,10 @@ done: } /* find the servers time on the opt_host host */ -static time_t nettime(int *zone) +static time_t nettime(struct net_context *c, int *zone) { - return cli_servertime(opt_host, opt_have_ip? &opt_dest_ip : NULL, zone); + return cli_servertime(c->opt_host, + c->opt_have_ip? &c->opt_dest_ip : NULL, zone); } /* return a time as a string ready to be passed to /bin/date */ @@ -90,7 +91,7 @@ static const char *systime(time_t t) return s; } -int net_time_usage(int argc, const char **argv) +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"\ @@ -98,14 +99,14 @@ int net_time_usage(int argc, const char **argv) "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(argc, argv); + net_common_flags_usage(c, argc, argv); return -1; } /* try to set the system clock using /bin/date */ -static int net_time_set(int argc, const char **argv) +static int net_time_set(struct net_context *c, int argc, const char **argv) { - time_t t = nettime(NULL); + time_t t = nettime(c, NULL); char *cmd; int result; @@ -125,9 +126,9 @@ static int net_time_set(int argc, const char **argv) } /* display the time on a remote box in a format ready for /bin/date */ -static int net_time_system(int argc, const char **argv) +static int net_time_system(struct net_context *c, int argc, const char **argv) { - time_t t = nettime(NULL); + time_t t = nettime(c, NULL); if (t == 0) return -1; @@ -137,14 +138,14 @@ static int net_time_system(int argc, const char **argv) } /* display the time on a remote box in a format ready for /bin/date */ -static int net_time_zone(int argc, const char **argv) +static int net_time_zone(struct net_context *c, int argc, const char **argv) { int zone = 0; int hours, mins; char zsign; time_t t; - t = nettime(&zone); + t = nettime(c, &zone); if (t == 0) return -1; @@ -161,7 +162,7 @@ static int net_time_zone(int argc, const char **argv) } /* display or set the time on a host */ -int net_time(int argc, const char **argv) +int net_time(struct net_context *c, int argc, const char **argv) { time_t t; struct functable func[] = { @@ -171,20 +172,21 @@ int net_time(int argc, const char **argv) {NULL, NULL} }; - if (!opt_host && !opt_have_ip && - !find_master_ip(opt_target_workgroup, &opt_dest_ip)) { + 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(argc,argv); + net_time_usage(c, argc,argv); return -1; } if (argc != 0) { - return net_run_function(argc, argv, func, net_time_usage); + return net_run_function(c, argc, argv, func, net_time_usage); } /* default - print the time */ - t = cli_servertime(opt_host, opt_have_ip? &opt_dest_ip : NULL, NULL); + t = cli_servertime(c->opt_host, c->opt_have_ip? &c->opt_dest_ip : NULL, + NULL); if (t == 0) return -1; d_printf("%s", ctime(&t)); -- cgit From 4206d9754486d2c1e18217cbcdbaad8f31f5244b Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Thu, 8 May 2008 11:23:38 +0200 Subject: net: more whitespace cleanup (This used to be commit ef0184d580500734fc7af51e1c790b075180a3d0) --- source3/utils/net_time.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 48417fbc0f..73f0315b1d 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -1,5 +1,5 @@ -/* - Samba Unix/Linux SMB client library +/* + Samba Unix/Linux SMB client library net time command Copyright (C) 2001 Andrew Tridgell (tridge@samba.org) @@ -7,12 +7,12 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ -- cgit From 6e8d46d40df86a8f6c5820852eb1eab95049be41 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Mon, 19 May 2008 00:33:02 +0200 Subject: net: Don't try to look up a server if net time is called with a command. (This used to be commit 37ef7c28163a5c538f325729855ec47ef6fac6bd) --- source3/utils/net_time.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 73f0315b1d..f8eb2b45a0 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -19,7 +19,6 @@ #include "includes.h" #include "utils/net.h" - /* return the time on a server. This does not require any authentication */ @@ -169,9 +168,14 @@ int net_time(struct net_context *c, int argc, const char **argv) {"SYSTEM", net_time_system}, {"SET", net_time_set}, {"ZONE", net_time_zone}, + {"HELP", net_time_usage}, {NULL, NULL} }; + if (argc != 0) { + return net_run_function(c, argc, argv, func, net_time_usage); + } + 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 "\ @@ -180,10 +184,6 @@ int net_time(struct net_context *c, int argc, const char **argv) return -1; } - if (argc != 0) { - return net_run_function(c, argc, argv, func, net_time_usage); - } - /* default - print the time */ t = cli_servertime(c->opt_host, c->opt_have_ip? &c->opt_dest_ip : NULL, NULL); -- cgit From b1ef38de9fcfc5299f7963a4200ac4b3807e73a0 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Mon, 19 May 2008 16:19:37 +0200 Subject: net: Make "net time" use functable3 (This used to be commit 28991ad74a387ebfe931860b380d25d5b0b67c7d) --- source3/utils/net_time.c | 70 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 13 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index f8eb2b45a0..a60e308867 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -93,10 +93,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; @@ -127,8 +127,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)); @@ -144,6 +153,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; @@ -164,21 +180,49 @@ static int net_time_zone(struct net_context *c, int argc, const char **argv) 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} + struct functable3 func[] = { + { + "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_function3(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; -- cgit From 7870908a0d51d1ab96274c11eee0d9e4ab78bbaa Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Thu, 5 Jun 2008 22:14:38 +0200 Subject: net: Fix comment for net_time_zone() (This used to be commit aea3466d12e31f8f506c21b856235e2e2aa40090) --- source3/utils/net_time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index a60e308867..43f907ddb7 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -145,7 +145,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; -- cgit From 255bdb26025a5025bc60637dd924f6ec71c49ee5 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Sat, 7 Jun 2008 02:25:08 +0200 Subject: net: Rename functable3 to functable, get rid of old functables (This used to be commit bb7c5fc4ec77db4073d3beccf12af12910b6bd07) --- source3/utils/net_time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_time.c') diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 43f907ddb7..f569538fac 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -180,7 +180,7 @@ static int net_time_zone(struct net_context *c, int argc, const char **argv) int net_time(struct net_context *c, int argc, const char **argv) { time_t t; - struct functable3 func[] = { + struct functable func[] = { { "system", net_time_system, @@ -209,7 +209,7 @@ int net_time(struct net_context *c, int argc, const char **argv) }; if (argc != 0) { - return net_run_function3(c, argc, argv, "net time", func); + return net_run_function(c, argc, argv, "net time", func); } if (c->display_usage) { -- cgit