pax_global_header00006660000000000000000000000064141070565450014521gustar00rootroot0000000000000052 comment=905fa62e1a842efab0a16d4c37bff27f0ad414e2 openrdate-1.10.2/000077500000000000000000000000001410705654500135635ustar00rootroot00000000000000openrdate-1.10.2/.github/000077500000000000000000000000001410705654500151235ustar00rootroot00000000000000openrdate-1.10.2/.github/workflows/000077500000000000000000000000001410705654500171605ustar00rootroot00000000000000openrdate-1.10.2/.github/workflows/full-check.yml000066400000000000000000000012011410705654500217120ustar00rootroot00000000000000name: full-check on: [push, pull_request] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: install_dependencies run: sudo apt install libbsd-dev - name: first_build run: | ./autogen.sh ./configure make sudo make install sudo make uninstall make distclean - name: second_build run: | ./autogen.sh ./configure make sudo make install - name: run_program run: | rdate 2>&1 | grep Usage rdate -pn4v ntp.on.br openrdate-1.10.2/AUTHORS000066400000000000000000000022731410705654500146370ustar00rootroot00000000000000The original authors and copyright holders of this code are as follows: David Mazieres Thomas Roessler - thanx for the arc4random code! N.M. Maclaren Thorston "mirabile" Glaser Christos Zoulas The last maintainer in SF.net, between 2005 and 2008 was David Snyder . There are other people helping to fix the source code over time. The SF address is https://sourceforge.net/projects/openrdate/ Since 2019 the source code is being maintained by Joao Eriberto Mota Filho and volunteers at https://github.com/resurrecting-open-source-projects/openrdate The following messages were written by David Snyder inside this AUTHORS file: 20050211 - It has been my supreme pleasure to turn this piece of OpenBSD software into a package for use by non-OpenBSD users. All copyrights and licenses are that of the original coder (I abhor borrowed plumage) and have applied my copyright to only the code I've added. But that being said, all errors and omissions are mine and mine alone. If you find any, feel free to email at the address below. 20060918 - Well, after a long absence, I've gone and updated the code the latest OBSD version of rdate. openrdate-1.10.2/CONTRIBUTING.md000066400000000000000000000017461410705654500160240ustar00rootroot00000000000000## HOW TO CONTRIBUTE TO OPENRDATE DEVELOPMENT OpenRdate is available at https://github.com/resurrecting-open-source-projects/openrdate If you are interested in contribute to OpenRdate development, please, follow these steps: 1. Send a patch that fix an issue or that implement a new feature. Alternatively, you can do a 'pull request'[1] in GitHub. [1] https://help.github.com/articles/about-pull-requests 2. Ask for join to the OpenRdate project in GitHub, if you want to work officially. Note that this second step is not compulsory. However, to accept you in project, is needed a minimum previous collaboration. To find issues and bugs to fix, you can check these addresses: - https://github.com/resurrecting-open-source-projects/openrdate - https://bugs.debian.org/cgi-bin/pkgreport.cgi?dist=unstable;package=rdate - https://bugs.launchpad.net/ubuntu/+source/rdate/+bugs If you want to join, please make a contact. -- Eriberto, Tue, 24 Sep 2019 22:06:53 -0300. openrdate-1.10.2/COPYING000077700000000000000000000000001410705654500156162LICENSEustar00rootroot00000000000000openrdate-1.10.2/ChangeLog000066400000000000000000000071631410705654500153440ustar00rootroot000000000000002021-08-17 Joao Eriberto Mota Filho Version 1.10.2 [ Joao Eriberto Mota Filho ] * Ran astyle command to reorganize the source code. * Updated install system, removed warnings and bumped required autoconf to 2.69. 2021-06-14 Joao Eriberto Mota Filho Version 1.10.1 [ Joao Eriberto Mota Filho ] * Created a CI test workflow for GitHub (full-check.yml). * Fixed a grammatical error in CONTRIBUTING.md. * Manpage: added new notes about -n, -o and -u options, to make clear that SNTP (RFC 5905) will always use UDP protocol. Thanks to artur128 , via Debian bug #988649. 2019-09-29 Joao Eriberto Mota Filho Version 1.10 [ Joao Eriberto Mota Filho ] * Autotools files: - Added a check for bsd/stdlib.h presence in configure.ac. - Added a distclean-local target in Makefile.am. - Added the autogen.sh file. - Improved the configure.ac and Makefile.am files. - Moved some build lines from Makefile.am to src/Makefile.am. - Removed all autogenerated files. - Removed no longer used checks for libs and headers. * Created CONTRIBUTING.md and HISTORY files. * Fixed some building warnings. * Removed no longer needed files (and includes for headers): arc4random.c and arc4random.h. * Removed not used variables rcsid and RCSId. * Reorganized AUTHORS, ChangeLog and NEWS files. * Rewritten README file. * Updated all headers and rights. * Using an updated LICENSE file. * Using txt2man to produce an updated manpage. [ Cyril Brulebois ] * Use libbsd instead of arc4random. Patch from Debian (see Debian bug #538695). [ Jakub Wilk ] * Allow rdate connect NTP via IPv6. Patch from Debian (see Debian bug #515219). [ Jérémy Bobbio ] * Added progress. Patch from Debian (see Debian bug #491540). [ Joey Hess ] * Avoid libnss files library. Patch from Debian (see Debian bug #434452). [ Pedro Zorzenon Neto ] * Added -b and -t options. Patch from Debian (see Debian bug #523513). [ Steve Langasek ] * Fixed unaligned access in ntp code triggers SIGBUS on sparc. Patch from Debian (see Debian bug #434140). ============================================================ === OLD CHANGELOG, by David Snyder === ============================================================ 20081121 - Updated the arc4random.c to the latest OpenBSD version. Modified the configure and arc4random to use the urandom dev instead of the sysctl since this is being deprecated in linux kernels >= 2.6.19. 20071111 - Updated the arc4random.c file and the rdate.8 manpage to the latest OpenBSD version. Also, rejiggered the makefiles just 'cause I could. 20061002 - Updated the arc4random.c file to the latest OpenBSD version. 20060928 - Ok, I've gotten around to restructuring the source directory structure. I know it's a bit of an overkill for such a small project, I wanted to try it. 20060918 - Finally updated the package to the latest OpenBSD rdate version. I know I should have done it sooner, but, you know, things pile up. The primary difference is that ntp.c has been set to handle ntp responses with ALARM status. 20050211 - First packaging and deployment of openrdate. Added configuration and makefile files. Defined a SA_LEN macro in ntp.c. Added an inclusion of config.h and changed an #ifdef in rdate.c =========================================== === Old versions and dates, from SF.net === =========================================== 2008-11-21: version 1.2 2007-11-11: version 1.1.3 2006-10-02: version 1.1.2 2006-09-28: version 1.1.1 2006-09-20: version 1.1 2005-03-05: version 1.0 openrdate-1.10.2/HISTORY000066400000000000000000000061501410705654500146510ustar00rootroot00000000000000-------------------------------- A brief of the openrdate history -------------------------------- * Christos Zoulas developed rdate in 1994 and subsequent years (versions 1.0 up to 1.4) for OpenBSD project. * Between 2005 and 2008, David Snyder (and other volunteers later) developed openrdate[1], fully based in rdate (but it is another project). There are several contributions from other projects as Debian. * Since 2019, the project is being maintained by new volunteers[2]. openrdate is being packaged in Debian, openSUSE, Fedora and other distributions[3]. [1] https://sourceforge.net/projects/openrdate [2] https://github.com/resurrecting-open-source-projects/openrdate [3] https://repology.org/project/openrdate/versions -- Joao Eriberto Mota Filho Thu, 26 Sep 2019 11:18:09 -0300 --------------------------- David Snyder - Original POV --------------------------- David Snyder wrote a README file for openrdate with some reports. See below the most interesting parts. -------------------------------------- 1. Motivations for OpenRdate I came over to Linux from OpenBSD. With that sort of background, it wasn't too hard to get around Linux. The only thing which bugged me was the lack of a proper 'rdate'. There was a dodgy little utility called 'netdate', but this didn't work on my, primarily, OpenBSD system. So, I asked, why isn't there rdate. Well, there is one (http://freshmeat.net/projects/rdate/), but it's only half the rdate I was used to on OpenBSD. It only hit the RFC 868 side-of-the-house, and I wanted the full monty (as it were :) ). Therefore, I did this little project. It'll hit and set the time on the machine both from RFC 868 time-servers (on the inetd's time port 37) and RFC 2030 protocol SNTP/NTP servers (on ntpd's port 123). As an added bonus, I also got to port an OpenBSD app to the outside world. --------------------------------------- 2. Changes The changes/additions to the files of the original OpenBSD rdate have been minimal. Only two files have had to be changed (due to the excellent *BSD coders): rdate.c - Added a check and inclusion of 'config.h' and changed an #ifndef from NO_UTIL to #ifdef HAVE_UTIL_H ntp.c - Added a check for __GLIBC__ and made a definition for SA_LEN (which Linux doesn't define for their sockaddr). Other than that, not much had to be changed or added. I thought I had a problem with getaddrinfo(), but that was only due to, as we said in the Army, 'vapor lock on the brain'. ---------------------------------------- 3. Attributions and Copywrite I've tried to put the proper attributions for the code for openrdate in the AUTHORS file. If I've missed you, let me know. The license of this software is, as shown in the parts and pieces of this project, BSD. Hopefully, I've covered all the different types of BSD-licenses used in the code in the COPYING file, but, once again, tell me if I missed one or another. Finally, I'd like to thank the coders, bug-hunters, and users of OpenBSD. You all run a tightship, and it's been a pleasure to work with some of your code. David Snyder dasnyderx at yahoo dot com openrdate-1.10.2/LICENSE000066400000000000000000000126671410705654500146040ustar00rootroot00000000000000The main source code for openrdate is under BSD-4-Clause. The following text was taken from openrdate 1.2. Please, check each header for updates. Note that files src/arc4random.c and src/arc4random.h are no longer used and were removed in 1.10 version. Consequently, the text about their licensing were dropped too. See HISTORY file for more details about the chain of development and licensing. -- Joao Eriberto Mota Filho Mon, 23 Sep 2019 12:18:33 -0300 === From 1.2 version=== The code for openrdate is under various versions of the BSD-license. The following are the different licenses and the files they apply to. rdate.c, rfc868time.c: /* * Copyright 1994 Christos Zoulas * All rights reserved. * * With slight modifications by David Snyder, copyright (c) 2005 * * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Christos Zoulas. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * 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. */ ntpleaps.c, ntpleaps.h: /* * Copyright (c) 2002 Thorsten Glaser. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - 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 COPYRIGHT HOLDERS AND CONTRIBUTORS * "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 * COPYRIGHT HOLDERS OR CONTRIBUTORS 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. * */ ntp.c: /* * Copyright (c) 1996, 1997 by N.M. Maclaren. All rights reserved. * Copyright (c) 1996, 1997 by University of Cambridge. All rights reserved. * Copyright (c) 2002 by Thorsten "mirabile" Glaser. * * With very slight modifications by David Snyder, copyright (c) 2004,2006,2007 * * 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. * 3. Neither the name of the author nor the university may be used to * endorse or promote products derived from this software without * specific prior written permission. * * 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. */ openrdate-1.10.2/Makefile.am000066400000000000000000000012171410705654500156200ustar00rootroot00000000000000# Copyright 2005-2007 David Snyder # Copyright 2009 Cyril Brulebois # Copyright 2019 Joao Eriberto Mota Filho # # This file is under the same terms described by # LICENSE file for the main source code (rdate.c). SUBDIRS = src man_MANS= docs/rdate.8 EXTRA_DIST= docs/rdate.8 distclean-local: rm -rf autom4te.cache/ rm -f aclocal.m4 \ compile \ config.* \ configure \ depcomp \ INSTALL \ install-sh \ Makefile.in \ missing \ src/Makefile.in openrdate-1.10.2/NEWS000066400000000000000000000017371410705654500142720ustar00rootroot00000000000000======================================================= === OLD NEWS, by David Snyder === ======================================================= 20081121 - Updated to the latest version of arc4random. Also implemented the use of the urandom device for linux kernel version >= 2.6.19 (see http://lwn.net/Articles/247243/). Thanks to Dr. Markus Waldeck. 20071111 - Updated everything to the latest OpenBSD version. Also, rejiggered the makefiles just 'cause I could. 20061002 - Updated the arc4random.c to the latest OpenBSD version 20060928 - Restructured source directory and files layout 20060918 - Updated to latest OpenBSD rdate version 20050211 - First release of openrdate =========================================== === Old versions and dates, from SF.net === =========================================== 2008-11-21: version 1.2 2007-11-11: version 1.1.3 2006-10-02: version 1.1.2 2006-09-28: version 1.1.1 2006-09-20: version 1.1 2005-03-05: version 1.0 openrdate-1.10.2/README000077700000000000000000000000001410705654500157152README.mdustar00rootroot00000000000000openrdate-1.10.2/README.md000066400000000000000000000052201410705654500150410ustar00rootroot00000000000000# OpenRdate #### openrdate - set the system's date from a remote host ## Help this project ## openrdate needs your help. **If you are a programmer** and if you wants to help a nice project, this is your opportunity. openrdate was imported from some tarballs (the original homepage[1] and developers are inactive). After this, all patches found in Debian project and other places for this program were applied. All initial work was registered in ChangeLog file (version 1.10 and later releases). openrdate is being packaged in Debian[2] Project. If you are interested to help openrdate, read the [CONTRIBUTING.md](CONTRIBUTING.md) file. [1]: https://sourceforge.net/projects/openrdate [2]: https://tracker.debian.org/pkg/openrdate ## What is OpenRdate? ## OpenRdate or openrdate or rdate 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 868 TCP protocol server, which is usually implemented as a built-in service of inetd(8), or an RFC 5905 protocol SNTP/NTP server. By default, rdate uses the RFC 868 TCP protocol. OpenRdate supports IPv4 and IPv6 protocols. OpenRdate was originally developed by David Snyder and was based in rdate, created by Christos Zoulas in 1994 for OpenBSD Project. Over time, OpenRdate got several contributions from people. Please, see AUTHORS and HISTORY files in source code for more details. ## Build and Install ## OpenRdate depends of libbsd[3] to build. [3]: https://libbsd.freedesktop.org/wiki/ To build and install, run the following commands: $ ./autogen.sh $ ./configure $ make # make install To return to original source code you can use '$ make distclean' command. On Debian systems you can use '# apt install rdate'. ## How to set a time server in Debian ## For test purposes, you can set your own time server. However, how to make it will depend of your system. For Debian systems, you can set it easily. ### For time protocol (RFC 868, port 37 TCP/UDP): ### # apt-get install xinetd # nano /etc/xinetd.d/time Change the lines: disable = yes to disable = no Restart the xinetd daemon: # systemctl restart xinetd Verify the open ports: # ss -tunlp Test rdate: # rdate ### For SNTP protocol (RFC 5905, port 123 UDP) ### You can set a SNTP server using several available options. However, there are lot of public servers on Internet. So, you can use: # rdate -n pool.ntp.org ## Author ## OpenRdate was originally developed by David Snyder under BSD-4-Clause license. Currently, the source code and newer versions are available at https://github.com/resurrecting-open-source-projects/openrdate openrdate-1.10.2/autogen.sh000077500000000000000000000044461410705654500155740ustar00rootroot00000000000000#!/bin/sh # autogen.sh with clean option, v0.1-rdate # Copyright 2019 Joao Eriberto Mota Filho # # This file is under BSD-3-Clause license. # # 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. # 3. Neither the name of the authors nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. # Use clean option if [ "$1" = "clean" -a ! -e Makefile ] then echo "Vanishing the code" rm -rf aclocal.m4 autom4te.cache/ compile config.* configure depcomp \ INSTALL install-sh Makefile.in missing src/Makefile.in exit 0 fi # Do not use clean option if [ "$1" = "clean" -a -e Makefile ] then echo "I can not clean. Use '$ make distclean'." exit 0 fi # Do autoreconf autoreconf -i \ && { echo " "; \ echo "Done. You can use the 'clean' option to vanish the source code."; \ echo "Example of use: $ ./autogen.sh clean"; \ echo " "; \ echo "Now run ./configure, make, and make install."; \ } \ || { echo "We have a problem..."; exit 1; } openrdate-1.10.2/configure.ac000066400000000000000000000047251410705654500160610ustar00rootroot00000000000000# Copyright 2005-2008 David Snyder # Copyright 2019-2021 Joao Eriberto Mota Filho # # This file is under the same terms described by # LICENSE file for the main source code (rdate.c). AC_PREREQ([2.69]) AC_INIT([openrdate],[1.10.2],[https://github.com/resurrecting-open-source-projects/openrdate/issues]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([src/rdate.c]) AC_CONFIG_HEADERS([config.h]) AC_ARG_VAR([kernel_version], [the version of the kernel to build against]) # Checks for programs. AC_PROG_CC if test -n "$GCC"; then CFLAGS="$CFLAGS -Wall" fi AC_PROG_INSTALL AC_PROG_RANLIB AC_PROG_EGREP # Checks for libraries. AC_CHECK_LIB([c], [fork]) AC_CHECK_LIB([util], [malloc]) # # Checks for header files. AC_CHECK_HEADERS([arpa/inet.h fcntl.h float.h limits.h netdb.h \ netinet/in.h stdlib.h string.h sys/param.h sys/socket.h \ sys/time.h unistd.h util.h]) AC_CHECK_HEADERS([bsd/stdlib.h], [], \ [echo "ERROR: previous header not found."; exit -1]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_C_INLINE AC_TYPE_OFF_T AC_TYPE_PID_T AC_TYPE_SIZE_T AC_STRUCT_TM # Checks for library functions. AC_FUNC_MALLOC AC_FUNC_SELECT_ARGTYPES AC_FUNC_STRFTIME AC_CHECK_FUNCS([gettimeofday memset select socket]) # Check for uname prog AC_PATH_PROG([UNAME], [uname], [:]) AC_CANONICAL_HOST # Determine the particulars of the host case "${host}" in *-*-linux*) AC_DEFINE([__LINUX__], [1], [Define Linux compile-time condition.]) # See whether to use sysctl depending on the linux kernel version # See http://lwn.net/Articles/247243/ if test "x${kernel_version}" = "x" && test "x${UNAME}" != "x:" ; then UNAMEOUT=`nice ${UNAME} -r 2> /dev/null` if test "x${UNAMEOUT}" != "x"; then NO_SYSCTL=`echo ${UNAMEOUT} | ${AWK} -F '.' '{ if ($1 >= 2 && $2 >= 6 && $3 >= 19) print "1"; else print "0"; }'` if test "x${NO_SYSCTL}" = "x1"; then AC_DEFINE([__NO_SYSCTL__], [1], [Do not use the sysctl calls.]) fi fi fi break;; default) ;; esac AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT openrdate-1.10.2/docs/000077500000000000000000000000001410705654500145135ustar00rootroot00000000000000openrdate-1.10.2/docs/UPDATE-CHECK000066400000000000000000000004601410705654500162330ustar00rootroot00000000000000When updating, change the following files (if needed): - Update rights - ChangeLog - Check for spelling errors in ChangeLog, manpage and README. - Check final manpage with man command. - configure.ac (VERSION) - docs/create-man.sh (DATE, version) - Generate a new manpage. - README - Test in Debian Sid openrdate-1.10.2/docs/create-man.sh000077500000000000000000000011501410705654500170630ustar00rootroot00000000000000#!/bin/bash # Copyright 2015-2019 Joao Eriberto Mota Filho # Create a manpage using txt2man command. # # This script can be used under BSD-3-Clause license. T2M_DATE="14 Jun 2021" T2M_NAME=rdate T2M_VERSION=1.10.1 T2M_LEVEL=8 T2M_DESC="set the system's date from a remote host" # Don't change the following lines TEST=$(txt2man -h 2> /dev/null) [ "$TEST" ] || { echo -e "\nYou need to install txt2man, from https://github.com/mvertes/txt2man.\n"; exit 1; } txt2man -d "$T2M_DATE" -t $T2M_NAME -r $T2M_NAME-$T2M_VERSION -s $T2M_LEVEL -v "$T2M_DESC" $T2M_NAME.txt > $T2M_NAME.$T2M_LEVEL openrdate-1.10.2/docs/rdate.8000066400000000000000000000070221410705654500157040ustar00rootroot00000000000000.\" Text automatically generated by txt2man .TH rdate 8 "14 Jun 2021" "rdate-1.10.1" "set the system's date from a remote host" .SH NAME \fBrdate \fP- set the system's date from a remote host \fB .SH SYNOPSIS .nf .fam C \fBrdate\fP [\fB-46acnpsuv\fP] [\fB-b\fP \fIsec\fP] [\fB-o\fP \fIport\fP] [\fB-t\fP \fImsec\fP] \fIhost\fP .fam T .fi .fam T .fi .SH DESCRIPTION \fBrdate\fP displays and sets the local date and time from the \fIhost\fP name or address given as the argument. The time source may be an RFC 868 TCP protocol server, which is usually implemented as a built-in service of \fBinetd\fP(8), or an RFC 5905 protocol SNTP/NTP server. By default, \fBrdate\fP uses the RFC 868 TCP protocol. .PP OpenRdate supports IPv4 and IPv6 protocols. .SH OPTIONS .TP .B \fB-4\fP Force \fBrdate\fP to use IPv4 addresses only. .TP .B \fB-6\fP Force \fBrdate\fP to use IPv6 addresses only. .TP .B \fB-a\fP Use the \fBadjtime\fP(2) call to gradually skew the local time to the remote time rather than just hopping. .TP .B \fB-b\fP \fIsec\fP Use adjtime if clock difference is at most \fIsec\fP seconds or hop if difference is greater. This is the same as including of removing the option \fB-a\fP, based on clock difference. .TP .B \fB-c\fP Correct leap seconds. Sometimes required when synchronizing to an NTP server. When synchronizing using the RFC 868 protocol, use this option only if the server does not correctly account for leap seconds. You can determine if you need this parameter if you sync against an NTP server (with this parameter) or (recommended) check with a local radio controlled watch or phone service. .TP .B \fB-n\fP Use SNTP (old RFC 2030, currently RFC 5905) instead of the RFC 868 time protocol. SNTP will always use UDP protocol and its default \fIport\fP is 123. .TP .B \fB-o\fP \fIport\fP Use \fIport\fP '\fIport\fP' instead of \fIport\fP 37 (RFC 868) or 123 (SNTP, RFC 5905). .TP .B \fB-p\fP Do not set, just print the remote time. .TP .B \fB-s\fP Do not print the time. .TP .B \fB-u\fP Use UDP instead of TCP as transport (for RFC 868 only; see \fB-n\fP option). .TP .B \fB-t\fP \fImsec\fP Does not set time if it took more than \fImsec\fP milliseconds to fetch time from network. .TP .B \fB-v\fP Verbose output. Always show the adjustment. .SH FILES .TP .B /var/log/wtmp Record of date resets and time changes. .SH EXAMPLES To get the legal time in Germany, set the /etc/localtime symlink to /usr/share/zoneinfo/right/Europe/Berlin and issue the following command: .PP .nf .fam C # rdate -ncv ptbtime1.ptb.de .fam T .fi The command of course assumes you have a working internet connection and DNS set up to connect to the server at Physikalisch-Technische Bundesanstalt in Braunschweig, Germany. .PP To gradually adjust time once an hour after the first "step" adjustment, put the following line into root's crontab: .PP .nf .fam C 58 * * * * rdate -ncav ptbtime1.ptb.de | logger -t NTP .fam T .fi To set the time through an ssh tunnel, use something like so: .PP .nf .fam C ssh -f -L 10037:time.example.com:37 tyr.example.com sleep 10 rdate -a -o 10037 localhost .fam T .fi .SH SEE ALSO \fBdate\fP(1), \fBadjtime\fP(2), \fBinetd\fP(8), \fBntpd\fP(8), \fBntpdate\fP(8), \fBtimed\fP(8) .SH AUTHORS OpenRdate was originally developed by David Snyder and was based in \fBrdate\fP, created by Christos Zoulas in 1994 for OpenBSD Project. Over time, OpenRdate got several contributions from people. .PP This manual page was written by Christos Zoulas. It was changed by Anibal Monsalve Salazar for the Debian Project and updated by Joao Eriberto Mota Filho. openrdate-1.10.2/docs/rdate.txt000066400000000000000000000057761410705654500163720ustar00rootroot00000000000000NAME rdate - set the system's date from a remote host SYNOPSIS rdate [-46acnpsuv] [-b sec] [-o port] [-t msec] host DESCRIPTION rdate 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 868 TCP protocol server, which is usually implemented as a built-in service of inetd(8), or an RFC 5905 protocol SNTP/NTP server. By default, rdate uses the RFC 868 TCP protocol. OpenRdate supports IPv4 and IPv6 protocols. OPTIONS -4 Force rdate to use IPv4 addresses only. -6 Force rdate to use IPv6 addresses only. -a Use the adjtime(2) call to gradually skew the local time to the remote time rather than just hopping. -b sec Use adjtime if clock difference is at most sec seconds or hop if difference is greater. This is the same as including of removing the option -a, based on clock difference. -c Correct leap seconds. Sometimes required when synchronizing to an NTP server. When synchronizing using the RFC 868 protocol, use this option only if the server does not correctly account for leap seconds. You can determine if you need this parameter if you sync against an NTP server (with this parameter) or (recommended) check with a local radio controlled watch or phone service. -n Use SNTP (old RFC 2030, currently RFC 5905) instead of the RFC 868 time protocol. SNTP will always use UDP protocol and its default port is 123. -o port Use port 'port' instead of port 37 (RFC 868) or 123 (SNTP, RFC 5905). -p Do not set, just print the remote time. -s Do not print the time. -u Use UDP instead of TCP as transport (for RFC 868 only; see -n option). -t msec Does not set time if it took more than msec milliseconds to fetch time from network. -v Verbose output. Always show the adjustment. FILES /var/log/wtmp Record of date resets and time changes. EXAMPLES To get the legal time in Germany, set the /etc/localtime symlink to /usr/share/zoneinfo/right/Europe/Berlin and issue the following command: # rdate -ncv ptbtime1.ptb.de The command of course assumes you have a working internet connection and DNS set up to connect to the server at Physikalisch-Technische Bundesanstalt in Braunschweig, Germany. To gradually adjust time once an hour after the first "step" adjustment, put the following line into root's crontab: 58 * * * * rdate -ncav ptbtime1.ptb.de | logger -t NTP To set the time through an ssh tunnel, use something like so: ssh -f -L 10037:time.example.com:37 tyr.example.com sleep 10 rdate -a -o 10037 localhost SEE ALSO date(1), adjtime(2), inetd(8), ntpd(8), ntpdate(8), timed(8) AUTHORS OpenRdate was originally developed by David Snyder and was based in rdate, created by Christos Zoulas in 1994 for OpenBSD Project. Over time, OpenRdate got several contributions from people. This manual page was written by Christos Zoulas. It was changed by Anibal Monsalve Salazar for the Debian Project and updated by Joao Eriberto Mota Filho. openrdate-1.10.2/src/000077500000000000000000000000001410705654500143525ustar00rootroot00000000000000openrdate-1.10.2/src/Makefile.am000066400000000000000000000010121410705654500164000ustar00rootroot00000000000000# Copyright 2007 David Snyder # Copyright 2009 Cyril Brulebois # Copyright 2019 Joao Eriberto Mota Filho # # This file is under the same terms described by # LICENSE file for the main source code (rdate.c). bin_PROGRAMS = rdate rdate_SOURCES = rdate.c rdate_LDADD = librdate.a -lbsd noinst_LIBRARIES = librdate.a librdate_a_SOURCES = \ ntp.c \ ntpleaps.c \ rfc868time.c \ ntpleaps.h openrdate-1.10.2/src/ntp.c000066400000000000000000000351671410705654500153330ustar00rootroot00000000000000/* $OpenBSD: ntp.c,v 1.29 2006/09/17 17:03:56 ckuethe Exp $ */ /* * Copyright 1996-1997 N.M. Maclaren. All rights reserved. * Copyright 1996-1997 University of Cambridge. * Copyright 2002 Thorsten "mirabile" Glaser * Copyright 2005-2007 David Snyder * Copyright 2007 Joey Hess * Copyright 2007 Steve Langasek * Copyright 2008 Jérémy Bobbio * Copyright 2009 Cyril Brulebois * Copyright 2009 Jakub Wilk * 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. * 3. Neither the name of the author nor the university may be used to * endorse or promote products derived from this software without * specific prior written permission. * * 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. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ntpleaps.h" #include /* * NTP definitions. Note that these assume 8-bit bytes - sigh. There * is little point in parameterising everything, as it is neither * feasible nor useful. It would be very useful if more fields could * be defined as unspecified. The NTP packet-handling routines * contain a lot of extra assumptions. */ #define JAN_1970 2208988800.0 /* 1970 - 1900 in seconds */ #define NTP_SCALE 4294967296.0 /* 2^32, of course! */ #define NTP_MODE_CLIENT 3 /* NTP client mode */ #define NTP_MODE_SERVER 4 /* NTP server mode */ #define NTP_VERSION 4 /* The current version */ #define NTP_VERSION_MIN 1 /* The minum valid version */ #define NTP_VERSION_MAX 4 /* The maximum valid version */ #define NTP_STRATUM_MAX 14 /* The maximum valid stratum */ #define NTP_INSANITY 3600.0 /* Errors beyond this are hopeless */ #define NTP_PACKET_MIN 48 /* Without authentication */ #define NTP_PACKET_MAX 68 /* With authentication (ignored) */ #define NTP_DISP_FIELD 8 /* Offset of dispersion field */ #define NTP_REFERENCE 16 /* Offset of reference timestamp */ #define NTP_ORIGINATE 24 /* Offset of originate timestamp */ #define NTP_RECEIVE 32 /* Offset of receive timestamp */ #define NTP_TRANSMIT 40 /* Offset of transmit timestamp */ #define STATUS_NOWARNING 0 /* No Leap Indicator */ #define STATUS_LEAPHIGH 1 /* Last Minute Has 61 Seconds */ #define STATUS_LEAPLOW 2 /* Last Minute Has 59 Seconds */ #define STATUS_ALARM 3 /* Server Clock Not Synchronized */ #define MAX_QUERIES 25 #define MAX_DELAY 15 #define MILLION_L 1000000l /* For conversion to/from timeval */ #define MILLION_D 1.0e6 /* Must be equal to MILLION_L */ struct ntp_data { u_char status; u_char version; u_char mode; u_char stratum; double receive; double transmit; double current; u_int64_t recvck; /* Local State */ double originate; u_int64_t xmitck; }; void ntp_client(const char *, int, struct timeval *, struct timeval *, int, int, int); int sync_ntp(int, const struct sockaddr *, socklen_t, double *, double *, int); int write_packet(int, struct ntp_data *); int read_packet(int, struct ntp_data *, double *, double *); void unpack_ntp(struct ntp_data *, u_char *); double current_time(double); void create_timeval(double, struct timeval *, struct timeval *); #ifdef DEBUG void print_packet(const struct ntp_data *); #endif int corrleaps; void ntp_client(const char *hostname, int family, struct timeval *new, struct timeval *adjust, int leapflag, int port, int verbose) { struct addrinfo hints, *res0, *res; double offset, error; int accept = 0, ret, s, ierror; memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_socktype = SOCK_DGRAM; ierror = getaddrinfo(hostname, port ? NULL : "ntp", &hints, &res0); if (ierror) { errx(1, "%s: %s", hostname, gai_strerror(ierror)); /*NOTREACHED*/ } corrleaps = leapflag; if (corrleaps) ntpleaps_init(); s = -1; for (res = res0; res; res = res->ai_next) { s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (s < 0) continue; if (port) { ((struct sockaddr_in*)res->ai_addr)->sin_port = htons(port); } ret = sync_ntp(s, res->ai_addr, res->ai_addrlen, &offset, &error, verbose); if (ret < 0) { #ifdef DEBUG fprintf(stderr, "try the next address\n"); #endif close(s); s = -1; continue; } accept++; break; } freeaddrinfo(res0); #ifdef DEBUG fprintf(stderr, "Correction: %.6f +/- %.6f\n", offset, error); #endif if (accept < 1) errx(1, "Unable to get a reasonable time estimate"); create_timeval(offset, new, adjust); } int sync_ntp(int fd, const struct sockaddr *peer, socklen_t addrlen, double *offset, double *error, int verbose) { int attempts = 0, accepts = 0, rejects = 0; int delay = MAX_DELAY, ret; double deadline; double a, b, x, y; double minerr = 0.1; /* Maximum ignorable variation */ struct ntp_data data; deadline = current_time(JAN_1970) + delay; *offset = 0.0; *error = NTP_INSANITY; if (connect(fd, peer, addrlen) < 0) { warn("Failed to connect to server"); return (-1); } while (accepts < MAX_QUERIES && attempts < 2 * MAX_QUERIES) { if (verbose >= 2) { fprintf(stderr, ".\n"); fflush(stderr); } memset(&data, 0, sizeof(data)); if (current_time(JAN_1970) > deadline) { warnx("Not enough valid responses received in time"); return (-1); } if (write_packet(fd, &data) < 0) return (-1); ret = read_packet(fd, &data, &x, &y); if (ret < 0) return (-1); else if (ret > 0) { #ifdef DEBUG print_packet(&data); #endif if (++rejects > MAX_QUERIES) { warnx("Too many bad or lost packets"); return (-1); } else continue; } else ++accepts; #ifdef DEBUG fprintf(stderr, "Offset: %.6f +/- %.6f\n", x, y); #endif if ((a = x - *offset) < 0.0) a = -a; if (accepts <= 1) a = 0.0; b = *error + y; if (y < *error) { *offset = x; *error = y; } #ifdef DEBUG fprintf(stderr, "Best: %.6f +/- %.6f\n", *offset, *error); #endif if (a > b) { warnx("Inconsistent times received from NTP server"); return (-1); } if ((data.status & STATUS_ALARM) == STATUS_ALARM) { warnx("Ignoring NTP server with alarm flag set"); return (-1); } if (*error <= minerr) break; } return (accepts); } /* Send out NTP packet. */ int write_packet(int fd, struct ntp_data *data) { u_char packet[NTP_PACKET_MIN]; ssize_t length; memset(packet, 0, sizeof(packet)); packet[0] = (NTP_VERSION << 3) | (NTP_MODE_CLIENT); data->xmitck = (u_int64_t)arc4random() << 32 | arc4random(); /* * Send out a random 64-bit number as our transmit time. The NTP * server will copy said number into the originate field on the * response that it sends us. This is totally legal per the SNTP spec. * * The impact of this is two fold: we no longer send out the current * system time for the world to see (which may aid an attacker), and * it gives us a (not very secure) way of knowing that we're not * getting spoofed by an attacker that can't capture our traffic * but can spoof packets from the NTP server we're communicating with. * * No endian concerns here. Since we're running as a strict * unicast client, we don't have to worry about anyone else finding * the transmit field intelligible. */ *(u_int64_t *)(packet + NTP_TRANSMIT) = data->xmitck; data->originate = current_time(JAN_1970); length = write(fd, packet, sizeof(packet)); if (length != sizeof(packet)) { warn("Unable to send NTP packet to server"); return (-1); } return (0); } /* * Check the packet and work out the offset and optionally the error. * Note that this contains more checking than xntp does. Return 0 for * success, 1 for failure. Note that it must not change its arguments * if it fails. */ int read_packet(int fd, struct ntp_data *data, double *off, double *error) { u_char receive[NTP_PACKET_MAX]; struct timeval tv; double x, y; int length, r; fd_set *rfds; rfds = calloc(howmany(fd + 1, NFDBITS), sizeof(fd_mask)); if (rfds == NULL) err(1, "calloc"); FD_SET(fd, rfds); retry: tv.tv_sec = 0; tv.tv_usec = 1000000 * MAX_DELAY / MAX_QUERIES; r = select(fd + 1, rfds, NULL, NULL, &tv); if (r < 0) { if (errno == EINTR) goto retry; else warn("select"); free(rfds); return (r); } if (r != 1 || !FD_ISSET(fd, rfds)) { free(rfds); return (1); } free(rfds); length = read(fd, receive, NTP_PACKET_MAX); if (length < 0) { warn("Unable to receive NTP packet from server"); return (-1); } if (length < NTP_PACKET_MIN || length > NTP_PACKET_MAX) { warnx("Invalid NTP packet size, packet rejected"); return (1); } unpack_ntp(data, receive); if (data->recvck != data->xmitck) { warnx("Invalid cookie received, packet rejected"); return (1); } if (data->version < NTP_VERSION_MIN || data->version > NTP_VERSION_MAX) { warnx("Received NTP version %u, need %u or lower", data->version, NTP_VERSION); return (1); } if (data->mode != NTP_MODE_SERVER) { warnx("Invalid NTP server mode, packet rejected"); return (1); } if (data->stratum > NTP_STRATUM_MAX) { warnx("Invalid stratum received, packet rejected"); return (1); } if (data->transmit == 0.0) { warnx("Server clock invalid, packet rejected"); return (1); } x = data->receive - data->originate; y = data->transmit - data->current; *off = (x + y) / 2; *error = x - y; x = (data->current - data->originate) / 2; if (x > *error) *error = x; return (0); } /* * Unpack the essential data from an NTP packet, bypassing struct * layout and endian problems. Note that it ignores fields irrelevant * to SNTP. */ void unpack_ntp(struct ntp_data *data, u_char *packet) { int i; double d; data->current = current_time(JAN_1970); data->status = (packet[0] >> 6); data->version = (packet[0] >> 3) & 0x07; data->mode = packet[0] & 0x07; data->stratum = packet[1]; for (i = 0, d = 0.0; i < 8; ++i) d = 256.0*d+packet[NTP_RECEIVE+i]; data->receive = d / NTP_SCALE; for (i = 0, d = 0.0; i < 8; ++i) d = 256.0*d+packet[NTP_TRANSMIT+i]; data->transmit = d / NTP_SCALE; /* See write_packet for why this isn't an endian problem. */ memcpy(&data->recvck,packet+NTP_ORIGINATE,8); } /* * Get the current UTC time in seconds since the Epoch plus an offset * (usually the time from the beginning of the century to the Epoch) */ double current_time(double offset) { struct timeval current; u_int64_t t; if (gettimeofday(¤t, NULL)) err(1, "Could not get local time of day"); /* * At this point, current has the current TAI time. * Now subtract leap seconds to set the posix tick. */ t = SEC_TO_TAI64(current.tv_sec); if (corrleaps) ntpleaps_sub(&t); return (offset + TAI64_TO_SEC(t) + 1.0e-6 * current.tv_usec); } /* * Change offset into current UTC time. This is portable, even if * struct timeval uses an unsigned long for tv_sec. */ void create_timeval(double difference, struct timeval *new, struct timeval *adjust) { struct timeval old; long n; /* Start by converting to timeval format. Note that we have to * cater for negative, unsigned values. */ if ((n = (long) difference) > difference) --n; adjust->tv_sec = n; adjust->tv_usec = (long) (MILLION_D * (difference-n)); errno = 0; if (gettimeofday(&old, NULL)) err(1, "Could not get local time of day"); new->tv_sec = old.tv_sec + adjust->tv_sec; new->tv_usec = (n = (long) old.tv_usec + (long) adjust->tv_usec); if (n < 0) { new->tv_usec += MILLION_L; --new->tv_sec; } else if (n >= MILLION_L) { new->tv_usec -= MILLION_L; ++new->tv_sec; } } #ifdef DEBUG void print_packet(const struct ntp_data *data) { printf("status: %u\n", data->status); printf("version: %u\n", data->version); printf("mode: %u\n", data->mode); printf("stratum: %u\n", data->stratum); printf("originate: %f\n", data->originate); printf("receive: %f\n", data->receive); printf("transmit: %f\n", data->transmit); printf("current: %f\n", data->current); printf("xmitck: 0x%0llX\n", data->xmitck); printf("recvck: 0x%0llX\n", data->recvck); }; #endif openrdate-1.10.2/src/ntpleaps.c000066400000000000000000000116301410705654500163450ustar00rootroot00000000000000/* $OpenBSD: ntpleaps.c,v 1.9 2007/11/26 09:28:34 martynas Exp $ */ /* * Copyright 2002 Thorsten Glaser. * Copyright 2005-2008 David Snyder * Copyright 2019 Joao Eriberto Mota Filho * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - 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 COPYRIGHT HOLDERS AND CONTRIBUTORS * "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 * COPYRIGHT HOLDERS OR CONTRIBUTORS 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. * */ /* Leap second support for NTP clients (generic) */ /* * I could include tzfile.h, but this would make the code unportable * at no real benefit. Read tzfile.h for why. */ #include #include #include #include #include #include #include #include "ntpleaps.h" static u_int64_t *leapsecs; static unsigned int leapsecs_num; int ntpleaps_init(void) { static int doneinit; static int donewarn; if (doneinit) return (0); if (ntpleaps_read() == 0) { doneinit = 1; return (0); } /* This does not really hurt, but users will complain about * off-by-22-seconds (at time of coding) errors if we don't warn. */ if (!donewarn) { fputs("Warning: error reading tzfile. You will NOT be\n" "able to get legal time or posix compliance!\n", stderr); donewarn = 1; /* put it only once */ } return (-1); } int ntpleaps_sub(u_int64_t *t) { unsigned int i = 0; u_int64_t u; int r = 1; if (ntpleaps_init() == -1) return (-1); u = *t; while (i < leapsecs_num) { if (u < leapsecs[i]) { r--; break; } if (u == leapsecs[i++]) break; } *t = u - i; return (r); } u_int32_t read_be_dword(u_int8_t *ptr) { u_int32_t res; memcpy(&res, ptr, 4); return (ntohl(res)); } int ntpleaps_read(void) { int fd; unsigned int r; u_int8_t buf[32]; u_int32_t m1, m2, m3; u_int64_t s; u_int64_t *l; fd = open("/usr/share/zoneinfo/right/UTC", O_RDONLY | O_NDELAY); if (fd == -1) return (-1); /* Check signature */ if (read(fd, buf, 4)) {}; buf[4] = 0; if (strcmp((const char *)buf, "TZif")) { close(fd); return (-1); } /* Pre-initialize buf[24..27] so we need not check read(2) result */ buf[24] = 0; buf[25] = 0; buf[26] = 0; buf[27] = 0; /* Skip uninteresting parts of header */ if (read(fd, buf, 28)) {}; /* Read number of leap second entries */ r = read_be_dword(&buf[24]); /* Check for plausibility - arbitrary values */ if ((r < 20) || (r > 60000)) { close(fd); return (-1); } if ((l = (u_int64_t *)malloc(r << 3)) == NULL) { close(fd); return (-1); } /* Skip further uninteresting stuff */ if (read(fd, buf, 12)) {}; m1 = read_be_dword(buf); m2 = read_be_dword(&buf[4]); m3 = read_be_dword(&buf[8]); m3 += (m1 << 2)+m1+(m2 << 2)+(m2 << 1); lseek(fd, (off_t)m3, SEEK_CUR); /* Now go parse the tzfile leap second info */ for (m1 = 0; m1 < r; m1++) { if (read(fd, buf, 8) != 8) { free(l); close(fd); return (-1); } s = SEC_TO_TAI64(read_be_dword(buf)); /* * Assume just _one_ leap second on each entry, and compensate * the lacking error checking by validating the first entry * against the known value */ if (!m1 && s != 0x4000000004B2580AULL) { free(l); close(fd); return (-1); } l[m1] = s; } /* Clean up and activate the table */ close(fd); if (leapsecs != NULL) free(leapsecs); leapsecs = l; leapsecs_num = r; return (0); } openrdate-1.10.2/src/ntpleaps.h000066400000000000000000000062071410705654500163560ustar00rootroot00000000000000/* $OpenBSD: ntpleaps.h,v 1.4 2007/11/25 16:40:04 jmc Exp $ */ /* * Copyright 2002 Thorsten Glaser. * Copyright 2005-2008 David Snyder * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - 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 COPYRIGHT HOLDERS AND CONTRIBUTORS * "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 * COPYRIGHT HOLDERS OR CONTRIBUTORS 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. * */ /* Leap second support for SNTP clients * This header file and its corresponding C file provide generic * ability for NTP or SNTP clients to correctly handle leap seconds * by reading them from an always existing file and subtracting the * leap seconds from the NTP return value before setting the posix * clock. This is fairly portable between operating systems and may * be used for patching other ntp clients, too. The tzfile used is: * /usr/share/zoneinfo/right/UTC which is available on any unix-like * platform with the Olson tz library, which is necessary to get real * leap second zoneinfo files and userland support anyways. */ #ifndef _NTPLEAPS_H #define _NTPLEAPS_H /* Offset between struct timeval.tv_sec and a tai64_t */ #define NTPLEAPS_OFFSET (4611686018427387914ULL) /* Hide this ugly value from programmes */ #define SEC_TO_TAI64(s) (NTPLEAPS_OFFSET + (u_int64_t)(s)) #define TAI64_TO_SEC(t) ((t) - NTPLEAPS_OFFSET) /* Initializes the leap second table. Does not need to be called * before usage of the subtract function, but calls ntpleaps_read. * returns 0 on success, -1 on error (displays a warning on stderr) */ int ntpleaps_init(void); /* Re-reads the leap second table, thus consuming quite much time. * Ought to be called from within daemons at least once a month to * ensure the in-memory table is always up-to-date. * returns 0 on success, -1 on error (leap seconds will not be available) */ int ntpleaps_read(void); /* Subtracts leap seconds from the given value (converts NTP time * to posix clock tick time. * returns 0 on success, -1 on error (time is unchanged), 1 on leap second */ int ntpleaps_sub(u_int64_t *); #endif openrdate-1.10.2/src/rdate.c000066400000000000000000000174511410705654500156250ustar00rootroot00000000000000/* $OpenBSD: rdate.c,v 1.22 2004/02/18 20:10:53 jmc Exp $ */ /* $NetBSD: rdate.c,v 1.4 1996/03/16 12:37:45 pk Exp $ */ /* * Copyright 1994 Christos Zoulas * Copyright 2005 David Snyder * Copyright 2007 Joey Hess * Copyright 2008 Jérémy Bobbio * Copyright 2009 Pedro Zorzenon Neto * Copyright 2019 Joao Eriberto Mota Filho * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Christos Zoulas. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * 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. * Time is returned as the number of seconds since * midnight January 1st 1900. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include #include #include #include #include #include /* there are systems without libutil; for portability */ #ifdef HAVE_UTIL_H #include #else #define logwtmp(a,b,c) #endif void rfc868time_client (const char *, int, struct timeval *, struct timeval *, int, int, int); void ntp_client (const char *, int, struct timeval *, struct timeval *, int, int, int); extern char *__progname; void usage(void) { (void) fprintf(stderr, "Usage: %s [-46acnpsv] [ -b sec ] [-o port] [ -t msec ] host\n", __progname); (void) fprintf(stderr, " -4: use IPv4 only\n"); (void) fprintf(stderr, " -6: use IPv6 only\n"); (void) fprintf(stderr, " -a: use adjtime instead of instant change\n"); (void) fprintf(stderr, " -b num: use instant change if difference is greater than\n" " num seconds, or else use adjtime\n"); (void) fprintf(stderr, " -c: correct leap second count\n"); (void) fprintf(stderr, " -n: use SNTP instead of RFC868 time protocol\n"); (void) fprintf(stderr, " -o num: override time port with num\n"); (void) fprintf(stderr, " -p: just print, don't set\n"); (void) fprintf(stderr, " -s: just set, don't print\n"); (void) fprintf(stderr, " -u: use UDP instead of TCP as transport\n"); (void) fprintf(stderr, " -t msec: does not set clock if network delay greater than msec\n"); (void) fprintf(stderr, " -v: verbose output\n"); } int main(int argc, char **argv) { int pr = 0, silent = 0, ntp = 0, verbose = 0; int slidetime = 0, corrleaps = 0, useudp = 0; char *hname; extern int optind; int c; int family = PF_UNSPEC; int port = 0; struct timeval new, adjust; int maxdelay = 0; int netdelay = 0; struct timeval netdelay1, netdelay2; struct timezone tz; int conditionalslide = 0; while ((c = getopt(argc, argv, "46psancvuo:t:b:")) != -1) switch (c) { case '4': family = PF_INET; break; case '6': family = PF_INET6; break; case 'p': pr++; break; case 's': silent++; break; case 'a': slidetime++; break; case 'n': ntp++; break; case 'c': corrleaps = 1; break; case 'v': verbose++; break; case 'u': useudp++; break; case 'o': port = atoi(optarg); break; case 't': maxdelay = atoi(optarg); break; case 'b': conditionalslide = atoi(optarg); break; default: usage(); return 1; } if (argc - 1 != optind) { usage(); return 1; } hname = argv[optind]; if (maxdelay) { gettimeofday(&netdelay1, &tz); } if (ntp) ntp_client(hname, family, &new, &adjust, corrleaps, port, verbose); else rfc868time_client(hname, family, &new, &adjust, corrleaps, useudp, port); if (maxdelay) { gettimeofday(&netdelay2, &tz); netdelay = (netdelay2.tv_sec - netdelay1.tv_sec) * 1000; netdelay += (netdelay2.tv_usec - netdelay1.tv_usec) / 1000; if (netdelay > maxdelay) { fprintf(stderr, "%s: Network delay exceeded (%i msec)\n", __progname, netdelay); exit(2); } } if (!pr) { if (conditionalslide) { if (((adjust.tv_sec > 0) && (adjust.tv_sec > conditionalslide)) || ((adjust.tv_sec < 0) && ((-adjust.tv_sec) > conditionalslide))) { slidetime = 0; } else { slidetime = 1; } } if (!slidetime) { logwtmp("|", "date", ""); if (settimeofday(&new, NULL) == -1) err(1, "Could not set time of day"); logwtmp("{", "date", ""); } else { if (adjtime(&adjust, NULL) == -1) err(1, "Could not adjust time of day"); } } if (!silent) { struct tm *ltm; char buf[80]; time_t tim = new.tv_sec; double adjsec; ltm = localtime(&tim); (void) strftime(buf, sizeof buf, "%a %b %e %H:%M:%S %Z %Y\n", ltm); (void) fputs(buf, stdout); adjsec = adjust.tv_sec + adjust.tv_usec / 1.0e6; if (slidetime || verbose) { char slidemsg[32]; if (conditionalslide) { if (slidetime) { strcpy(slidemsg," (adjtime)"); } else { strcpy(slidemsg," (instant change)"); } } else { strcpy(slidemsg,""); } if (ntp) (void) fprintf(stdout, "%s: adjust local clock by %.6f seconds%s\n", __progname, adjsec, slidemsg); else (void) fprintf(stdout, "%s: adjust local clock by %ld seconds%s\n", __progname, adjust.tv_sec, slidemsg); } if (verbose && maxdelay) { (void) fprintf(stdout, "%s: network delay %i msecs\n", __progname, netdelay); } } return 0; } openrdate-1.10.2/src/rfc868time.c000066400000000000000000000103661410705654500164230ustar00rootroot00000000000000/* $OpenBSD: rfc868time.c,v 1.6 2004/02/16 21:25:41 jakob Exp $ */ /* $NetBSD: rdate.c,v 1.4 1996/03/16 12:37:45 pk Exp $ */ /* * Copyright 1994 Christos Zoulas * Copyright 2005 David Snyder * Copyright 2007 Joey Hess * Copyright 2019 Joao Eriberto Mota Filho * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Christos Zoulas. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * 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 #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, int useudp, int port) { 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 = useudp ? SOCK_DGRAM : SOCK_STREAM; /* XXX what about rfc868 UDP * probably not due to the Y2038 issue -mirabile */ error = getaddrinfo(hostname, port ? NULL : "time", &hints, &res0); if (error) { errx(1, "%s: %s", hostname, gai_strerror(error)); /*NOTREACHED*/ } s = -1; for (res = res0; res; res = res->ai_next) { s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (s < 0) continue; if (port) { ((struct sockaddr_in*)res->ai_addr)->sin_port = htons(port); } if (connect(s, res->ai_addr, res->ai_addrlen) < 0) { close(s); s = -1; continue; } break; } if (s < 0) err(1, "Could not connect socket"); freeaddrinfo(res0); /* UDP requires us to send an empty datagram first */ if (useudp) send(s, NULL, 0, 0); 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; }