From e3a888d5a935047367e531321981cbed8618c5a3 Mon Sep 17 00:00:00 2001 From: Matthew Chapman Date: Sat, 1 May 1999 05:56:55 +0000 Subject: Adding "time" rpcclient command which displays the remote time. Also added special "now" time to the "at" command, e.g.: at now /i cmd ; pops up a command prompt (This used to be commit f456dcf08ec96c631f5e6f2e857115d4bbf94d1b) --- source3/rpcclient/cmd_atsvc.c | 75 ++++++++++++++++++++++++++++++++---------- source3/rpcclient/cmd_srvsvc.c | 41 +++++++++++++++++++++++ source3/rpcclient/display.c | 4 +-- source3/rpcclient/rpcclient.c | 1 + 4 files changed, 101 insertions(+), 20 deletions(-) (limited to 'source3/rpcclient') diff --git a/source3/rpcclient/cmd_atsvc.c b/source3/rpcclient/cmd_atsvc.c index a7b771e48e..7e9f05fb6f 100644 --- a/source3/rpcclient/cmd_atsvc.c +++ b/source3/rpcclient/cmd_atsvc.c @@ -43,7 +43,6 @@ checks for a /OPTION:param style option static BOOL checkopt(char *input, char *optname, char **params) { char *inend; - int i, len; if (*input++ != '/') return False; @@ -85,7 +84,7 @@ static BOOL at_parse_days(char *str, uint32 *monthdays, uint8 *weekdays) *nexttok++ = 0; } - if (isdigit(*tok)) + if (isdigit((int)*tok)) { day = strtol(tok, NULL, 10); if (day == 0 || day > 31) @@ -131,6 +130,38 @@ static BOOL at_parse_days(char *str, uint32 *monthdays, uint8 *weekdays) return True; } +#define SOON_OFFSET 2 /* seconds */ + +/**************************************************************************** +schedule the job 'soon' +****************************************************************************/ +static BOOL at_soon(char *dest_srv, uint32 *hours, uint32 *minutes, uint32 *seconds) +{ + uint16 nt_pipe_fnum; + TIME_OF_DAY_INFO tod; + BOOL res = True; + + /* open srvsvc session. */ + res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False; + + /* enumerate files on server */ + res = res ? do_srv_net_remote_tod(smb_cli, nt_pipe_fnum, + dest_srv, &tod) : False; + + /* Close the session */ + cli_nt_session_close(smb_cli, nt_pipe_fnum); + + if (res) + { + *hours = (tod.hours - ((int)tod.zone/60)) % 24; + *minutes = tod.mins; + *seconds = (tod.secs + SOON_OFFSET) % 60; + return True; + } + + return False; +} + /**************************************************************************** scheduler add job @@ -168,28 +199,36 @@ void cmd_at(struct client_info *info) if (*p == 0) /* Entirely numeric field */ continue; - if ((p == temp) || (sscanf(temp, "%d:%d:%d", - &hours, &minutes, &seconds) < 2)) + if (!strcasecmp(temp, "NOW")) { - printf("at { time [/INTERACTIVE] [{/EVERY|/NEXT}:5,Sun,...] command | [/DEL] [jobid] }\n\n"); - return; + if (!at_soon(dest_wks, &hours, &minutes, &seconds)) + { + return; + } } - - p = strchr(temp, 0); - - if (!strcasecmp(p-2, "AM")) + else if (sscanf(temp, "%d:%d:%d", &hours, &minutes, &seconds) > 2) { - hours = (hours == 12) ? 0 : hours; - } + p = strchr(temp, 0); - if (!strcasecmp(p-2, "PM")) - { - hours = (hours == 12) ? 12 : hours + 12; - } + if (!strcasecmp(p-2, "AM")) + { + hours = (hours == 12) ? 0 : hours; + } + + if (!strcasecmp(p-2, "PM")) + { + hours = (hours == 12) ? 12 : hours + 12; + } - if (hours > 23 || minutes > 59 || seconds > 59) + if (hours > 23 || minutes > 59 || seconds > 59) + { + printf("\tInvalid time.\n\n"); + return; + } + } + else { - printf("\tInvalid time.\n\n"); + printf("at { {time | NOW} [/INTERACTIVE] [{/EVERY|/NEXT}:5,Sun,...] command\n\t| [/DEL] [jobid] }\n\n"); return; } diff --git a/source3/rpcclient/cmd_srvsvc.c b/source3/rpcclient/cmd_srvsvc.c index 1be35608ee..2cb741b966 100644 --- a/source3/rpcclient/cmd_srvsvc.c +++ b/source3/rpcclient/cmd_srvsvc.c @@ -331,3 +331,44 @@ void cmd_srv_enum_files(struct client_info *info) } } +/**************************************************************************** +display remote time +****************************************************************************/ +void cmd_time(struct client_info *info) +{ + uint16 nt_pipe_fnum; + fstring dest_srv; + TIME_OF_DAY_INFO tod; + BOOL res = True; + + fstrcpy(dest_srv, "\\\\"); + fstrcat(dest_srv, info->dest_host); + strupper(dest_srv); + + DEBUG(4,("cmd_time: server:%s\n", dest_srv)); + + /* open srvsvc session. */ + res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False; + + /* enumerate files on server */ + res = res ? do_srv_net_remote_tod(smb_cli, nt_pipe_fnum, + dest_srv, &tod) : False; + + if (res) + { + fprintf(out_hnd, "\tRemote Time:\t%s\n\n", + http_timestring(tod.elapsedt)); + } + + /* Close the session */ + cli_nt_session_close(smb_cli, nt_pipe_fnum); + + if (res) + { + DEBUG(5,("cmd_srv_enum_files: query succeeded\n")); + } + else + { + DEBUG(5,("cmd_srv_enum_files: query failed\n")); + } +} diff --git a/source3/rpcclient/display.c b/source3/rpcclient/display.c index e5c65fdec8..963b5b6249 100644 --- a/source3/rpcclient/display.c +++ b/source3/rpcclient/display.c @@ -1662,12 +1662,12 @@ void display_svc_info(FILE *out_hnd, enum action_type action, ENUM_SRVC_STATUS * } } -static char *get_at_time_str(uint32 time) +static char *get_at_time_str(uint32 t) { static fstring timestr; unsigned int hours, minutes, seconds; - hours = time / 1000; + hours = t / 1000; seconds = hours % 60; hours /= 60; minutes = hours % 60; diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 20cc3ad49b..255ec4c936 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -107,6 +107,7 @@ struct { {"svcenum", cmd_svc_enum, "[-i] Lists Services Manager"}, {"at", cmd_at, "Scheduler control (at /? for syntax)"}, + {"time", cmd_time, "Display remote time"}, {"regenum", cmd_reg_enum, " Registry Enumeration (keys, values)"}, {"regdeletekey",cmd_reg_delete_key, " Registry Key Delete"}, {"regcreatekey",cmd_reg_create_key, " [keyclass] Registry Key Create"}, -- cgit