source: branches/samba-3.2.x/source/utils/net_time.c@ 228

Last change on this file since 228 was 133, checked in by Paul Smedley, 18 years ago

Update trunk to 3.2.0pre3

File size: 4.5 KB
Line 
1/*
2 Samba Unix/Linux SMB client library
3 net time command
4 Copyright (C) 2001 Andrew Tridgell ([email protected])
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#include "includes.h"
20#include "utils/net.h"
21
22
23/*
24 return the time on a server. This does not require any authentication
25*/
26static time_t cli_servertime(const char *host, struct sockaddr_storage *pss, int *zone)
27{
28 struct nmb_name calling, called;
29 time_t ret = 0;
30 struct cli_state *cli = NULL;
31 NTSTATUS status;
32
33 cli = cli_initialise();
34 if (!cli) {
35 goto done;
36 }
37
38 status = cli_connect(cli, host, pss);
39 if (!NT_STATUS_IS_OK(status)) {
40 fprintf(stderr,"Can't contact server %s. Error %s\n", host, nt_errstr(status));
41 goto done;
42 }
43
44 make_nmb_name(&calling, global_myname(), 0x0);
45 if (host) {
46 make_nmb_name(&called, host, 0x20);
47 } else {
48 make_nmb_name(&called, "*SMBSERVER", 0x20);
49 }
50
51 if (!cli_session_request(cli, &calling, &called)) {
52 fprintf(stderr,"Session request failed\n");
53 goto done;
54 }
55 if (!cli_negprot(cli)) {
56 fprintf(stderr,"Protocol negotiation failed\n");
57 goto done;
58 }
59
60 ret = cli->servertime;
61 if (zone) *zone = cli->serverzone;
62
63done:
64 if (cli) {
65 cli_shutdown(cli);