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 ++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 18 deletions(-) (limited to 'source3/rpcclient/cmd_atsvc.c') 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; } -- cgit