diff --git a/usr.sbin/rdate/Makefile b/usr.sbin/rdate/Makefile index 44361d12c99..2ca709ac1b2 100644 --- a/usr.sbin/rdate/Makefile +++ b/usr.sbin/rdate/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.7 2003/11/20 23:23:09 avsm Exp $ +# $OpenBSD: Makefile,v 1.8 2026/03/27 14:33:58 deraadt Exp $ PROG= rdate -SRCS= rdate.c rfc868time.c ntp.c ntpleaps.c +SRCS= rdate.c ntp.c ntpleaps.c CFLAGS+=-Wall DPADD+= ${LIBUTIL} LDADD+= -lutil diff --git a/usr.sbin/rdate/rdate.8 b/usr.sbin/rdate/rdate.8 index 5efe6e019ea..08d3c645f2d 100644 --- a/usr.sbin/rdate/rdate.8 +++ b/usr.sbin/rdate/rdate.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: rdate.8,v 1.40 2023/11/12 18:53:22 otto Exp $ +.\" $OpenBSD: rdate.8,v 1.41 2026/03/27 14:33:58 deraadt Exp $ .\" $NetBSD: rdate.8,v 1.4 1996/04/08 20:55:17 jtc Exp $ .\" .\" Copyright (c) 1994 Christos Zoulas @@ -24,7 +24,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: November 12 2023 $ +.Dd $Mdocdate: March 27 2026 $ .Dt RDATE 8 .Os .Sh NAME @@ -32,19 +32,13 @@ .Nd set the system's date from a remote host .Sh SYNOPSIS .Nm rdate -.Op Fl 46acnopsv +.Op Fl 46acnpsv .Ar host .Sh DESCRIPTION .Nm displays and sets the local date and time from the host name or address given as the argument. -The time source may be an RFC 5905 protocol SNTP/NTP server -or an RFC 868 TCP protocol server, -which is usually implemented as a built-in service of -.Xr inetd 8 . -By default, -.Nm -uses the RFC 5905 SNTP/NTP protocol. +The time source is an RFC 5905 protocol SNTP/NTP server. .Pp The options are as follows: .Bl -tag -width Ds @@ -66,14 +60,10 @@ Correct leap seconds. This should be used only when synchronizing to a server which does not correctly account for leap seconds. .It Fl n -Use SNTP (RFC 5905) instead of the RFC 868 time protocol. +Use SNTP (RFC 5905). This is the default. This protocol counts 32 bits of seconds from January 1, 1900 and will handle rollover to a new NTP era in February 2036. -.It Fl o -Use an RFC 868 TCP protocol server instead of SNTP. -This protocol is obsolete as it is not capable of representing -dates past January 19, 2038 03:14:07 GMT. .It Fl p Do not set, just print the remote time. .It Fl s diff --git a/usr.sbin/rdate/rdate.c b/usr.sbin/rdate/rdate.c index 95a6c506d81..e6c77711b4d 100644 --- a/usr.sbin/rdate/rdate.c +++ b/usr.sbin/rdate/rdate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rdate.c,v 1.37 2023/01/04 13:00:11 jsg Exp $ */ +/* $OpenBSD: rdate.c,v 1.38 2026/03/27 14:33:58 deraadt Exp $ */ /* $NetBSD: rdate.c,v 1.4 1996/03/16 12:37:45 pk Exp $ */ /* @@ -52,7 +52,6 @@ #define logwtmp(a,b,c) #endif -void rfc868time_client(const char *, int, struct timeval *, struct timeval *, int); void ntp_client(const char *, int, struct timeval *, struct timeval *, int); extern char *__progname; @@ -67,14 +66,14 @@ struct { __dead void usage(void) { - (void) fprintf(stderr, "usage: %s [-46acnopsv] host\n", __progname); + (void) fprintf(stderr, "usage: %s [-46acnpsv] host\n", __progname); exit(1); } int main(int argc, char **argv) { - int pr = 0, silent = 0, ntp = 1, verbose = 0; + int pr = 0, silent = 0, verbose = 0; int slidetime = 0, corrleaps = 0; char *hname; int c, p[2], pid; @@ -103,11 +102,7 @@ main(int argc, char **argv) break; case 'n': - ntp = 1; - break; - - case 'o': - ntp = 0; + /* noop */ break; case 'c': @@ -149,12 +144,8 @@ main(int argc, char **argv) setvbuf(stdout, NULL, _IOFBF, 0); setvbuf(stderr, NULL, _IOFBF, 0); - if (ntp) - ntp_client(hname, family, &pdata.new, - &pdata.adjust, corrleaps); - else - rfc868time_client(hname, family, &pdata.new, - &pdata.adjust, corrleaps); + ntp_client(hname, family, &pdata.new, + &pdata.adjust, corrleaps); if (write(STDOUT_FILENO, &pdata, sizeof pdata) != sizeof pdata) exit(1); @@ -207,14 +198,9 @@ main(int argc, char **argv) adjsec = pdata.adjust.tv_sec + pdata.adjust.tv_usec / 1.0e6; if (slidetime || verbose) { - if (ntp) - (void) fprintf(stdout, - "%s: adjust local clock by %.6f seconds\n", - __progname, adjsec); - else - (void) fprintf(stdout, - "%s: adjust local clock by %lld seconds\n", - __progname, (long long)pdata.adjust.tv_sec); + (void) fprintf(stdout, + "%s: adjust local clock by %.6f seconds\n", + __progname, adjsec); } } diff --git a/usr.sbin/rdate/rfc868time.c b/usr.sbin/rdate/rfc868time.c deleted file mode 100644 index fc81f7aff63..00000000000 --- a/usr.sbin/rdate/rfc868time.c +++ /dev/null @@ -1,119 +0,0 @@ -/* $OpenBSD: rfc868time.c,v 1.13 2023/01/04 13:00:11 jsg Exp $ */ -/* $NetBSD: rdate.c,v 1.4 1996/03/16 12:37:45 pk Exp $ */ - -/* - * Copyright (c) 1994 Christos Zoulas - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * rdate.c: Set the date from the specified host - * - * Uses the rfc868 time protocol at socket 37 (tcp). - * Time is returned as the number of seconds since - * midnight January 1st 1900. - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -/* Obviously it is not just for SNTP clients... */ -#include "ntpleaps.h" - -/* seconds from midnight Jan 1900 - 1970 */ -#define DIFFERENCE 2208988800UL - -void -rfc868time_client(const char *hostname, int family, struct timeval *new, - struct timeval *adjust, int leapflag); - - -void -rfc868time_client(const char *hostname, int family, struct timeval *new, - struct timeval *adjust, int leapflag) -{ - struct addrinfo hints, *res0, *res; - struct timeval old; - u_int32_t tim; /* RFC 868 states clearly this is an uint32 */ - int s; - int error; - u_int64_t td; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = family; - hints.ai_socktype = SOCK_STREAM; - error = getaddrinfo(hostname, "time", &hints, &res0); - if (error) { - errx(1, "%s: %s", hostname, gai_strerror(error)); - /*NOTREACHED*/ - } - - if (pledge("stdio inet", NULL) == -1) - err(1, "pledge"); - - s = -1; - for (res = res0; res; res = res->ai_next) { - s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); - if (s == -1) - continue; - - if (connect(s, res->ai_addr, res->ai_addrlen) == -1) { - close(s); - s = -1; - continue; - } - - break; - } - if (s == -1) - err(1, "Could not connect socket"); - freeaddrinfo(res0); - - if (read(s, &tim, sizeof(tim)) != sizeof(tim)) - err(1, "Could not read data"); - - (void) close(s); - tim = ntohl(tim) - DIFFERENCE; - - if (gettimeofday(&old, NULL) == -1) - err(1, "Could not get local time of day"); - - td = SEC_TO_TAI64(old.tv_sec); - if (leapflag) - ntpleaps_sub(&td); - - adjust->tv_sec = tim - TAI64_TO_SEC(td); - adjust->tv_usec = 0; - - new->tv_sec = old.tv_sec + adjust->tv_sec; - new->tv_usec = 0; -}