Commit graph

187 commits

Author SHA1 Message Date
J William Piggott
969bffb748 hwclock: --set and --predict segmentation fault
Segmentation fault for --set or --predict when the
--date option is not included.

* sys-utils/hwclock.c: exit with an error message when
    the required --date option is missing.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-04-18 22:39:05 -04:00
J William Piggott
039a0ceccf hwclock: make epoch functions alpha only
It's been 19.1315 years since the comment below was written and the kernel
has actually gone further away from allowing an RTC epoch on ISA machines.

/*
 * Maintenance note: This should work on non-Alpha machines, but the
 * evidence today (98.03.04) indicates that the kernel only keeps the epoch
 * value on Alphas. If that is ever fixed, this function should be changed.
 */

The current behavior is to accept the epoch options on ISA machines
only to print a lengthy message explaining that you cannot use them.

This patch removes that behavior, making the epoch functions truly Alpha
only, as the man-page states that they are.

* sys-utils/hwclock.c: make epoch function alpha only.
* sys-utils/hwclock.h: same.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-04-18 22:39:05 -04:00
J William Piggott
8b73ff9633 hwclock: improve default function handling
Removes long default function test. Instead handle the
default when the options are parsed.

Also fixes the non-linux build failure reported by Rudi:
http://marc.info/?l=util-linux-ng&m=149189833115871

Reported-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-04-18 22:39:05 -04:00
J William Piggott
657a55681a hwclock: use errtryhelp()
* sys-utils/hwclock.c: use errtryhelp() instead of usage().

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-04-10 14:22:30 -04:00
J William Piggott
af68bd014a hwclock: remove unused 'silent' arg
The 'silent' argument for get_epoch_rtc() was used
to silence error messages when querying the rtc
driver for an alpha epoch while using cmos direct
access. Alpha cmos has since been removed so
'silent' is no longer used.

* sys-utils/hwclock.h: remove 'silent' argument
* sys-utils/hwclock.c: same
* sys-utils/hwclock-rtc.c: same

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-03-31 10:04:53 -04:00
J William Piggott
c47a61894b hwclock: remove alpha cmos
Remove alpha direct I/O access, use RTC instead:
http://marc.info/?l=util-linux-ng&m=141682406902804

Resolves the alpha 2020 issue for util-linux:
http://marc.info/?l=util-linux-ng&m=148387021519787

Now it is only the kernel's RTC problem.

* sys-utils/hwclock.c: remove alpha cmos
* sys-utils/hwclock-cmos.c: same
* sys-utils/hwclock.h: same
* sys-utils/hwclock.8.in: same

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-03-31 10:04:53 -04:00
J William Piggott
f6374e1fb3 hwclock: remove 1994 Award BIOS workaround
Remove the 1994 Award BIOS bug workaround as
previously discussed more than two years ago:
http://marc.info/?l=util-linux-ng&m=141682406902804&w=2

* sys-utils/hwclock.c: remove badyear option
* sys-utils/hwclock.h: same
* sys-utils/hwclock.8.in: same

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-03-31 12:56:03 +02:00
J William Piggott
7a3000f7ba hwclock: use parse_date function
* hwclock.c: replace interpret_date_string() with parse_date().
   Eliminates shell injection vulnerability from popen() date(1).
   Removes system dependency on date(1).
   Reduction in hwclock execution time.
   Significant cleanup of hwclock.c code.

* Bug fix for "hwclock --predict --date 'bad_date'" printing:
    hwclock: No usable set-to time.  Cannot set clock.

  The message now matches date(1) for an invalid --date argument.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-03-04 11:04:10 -05:00
Sami Kerola
2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola
8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Yuri Chornoivan
a7349ee315 docs: Fix word repetitions 2017-02-13 14:10:12 +01:00
Karel Zak
a18f17ad2b hwclock: remove if-if-condition 2017-02-09 11:42:01 +01:00
Sami Kerola
92931ab28d
hwclock: remove --compare option
Compare functionality was printing nonsense values.  There is no knowledge
of anyone using this broken functionality.  Instead of deprecating the code
for months, and removing it after few release, it is removed immediately.
Needless to say this is unusual removal.

Reference: http://marc.info/?l=util-linux-ng&m=148396210506652&w=2
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola
9c65888e82
hwclock: make --date=argument less prone to injection
This change should not improve security much.  One hopes hwclock --set is
restricted for root only.  Where hwclock is allowed to run via sudo, or has
setuid setup, there is a pretty easy privilege escalation via subshell.

$ sudo ./hwclock --set --date='2000-10-20$(touch /tmp/hwclock.inject)'

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola
85932da89e
hwclock: remove division by zero [asan]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola
6b3cb18669
hwclock: remove magic constants from interpret_date_string()
The constants function returned were not used.  In same go clean up
execution flow a little bit.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola
0f32118e70
hwclock: use symbolic magic values passed in between functions
The manipulate_clock() is seeing return value from
busywait_for_rtc_clock_tick().

And the get_permissions_cmos() can see i386_iopl() return value.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola
a8775f4e7f
hwclock: initialize struct adjtime members
Avoid any chance of using uninitialized values.  It looks like the earlier
code did take care of that, but it was less obvious about the fact.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola
710684e81d
hwclock: alloate date_resp parsing buffer in interpret_date_string()
This makes overflowing the variable in question impossible.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola
4aca5fe247
hwclock: simplify save_adjtime() execution flow
Return early to avoid excessive nesting.  In same go remove any chance of
overflow by using appropriate allocation.  And update variable names to be
easier to understand.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola
c6ea9ef6cb
hwclock: remove dead code and other minor fixes
Use #ifdef rather than #if to avoid undefined preprocessor identifier
warning.

Remove dead code.  The #if 0 ensured the code has not been used for long
time, which is good because the linux/mc146818rtc.h is not been part of
user-api for long time.

Value of the adjtime_p->last_calib_time is checked if it has value of zero,
so testing none-zero bit later is necessarily true, and therefore does not
need to be checked.

And at the and remove unnecessary boolean variable.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola
8f729d60fa
hwclock: move error messages to determine_clock_access_method()
This makes main() a little bit shorter.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola
336f7c5f68
hwclock: move command-line options to control structure
The control structure is read-only everywhere else but in main().  Almost
all changes are about how variables are referred, with one exception.  Calls
to read_adjtime() from manipulate_clock() and compare_clock() are moved to
main().  This way it is possible to keep variable that tells if hwclock is
using UTC-0 be part of control structure.

Changes within #ifdef __alpha__ segments were tested by flipping the
preprocessor directivive otherway around and getting good compilaton all the
way to the point where linking on none-alpha system failed.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola
b68e1f44ab
hwclock: remove unnecessary type casts
Most of the casts did nothing, with exception of couple printouts where
format specifier is updated to match with the variable type.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola
183a2715b1
hwclock: do not hardcode date command magic string twice
Variable 'magic' already contains string 'seconds-into-epoch'.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola
48e7ed5e3f
hwclock: remove hwclock_exit() indirection
Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:36 +00:00
Sami Kerola
1030c325c0
hwclock: remove FLOOR macro in favour of floor(3)
Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:30 +00:00
Sami Kerola
12f1cdda3d
hwclock: remove UTC-0 localization hack
Use timegm(3) instead rather than re-implement same functionality with
mktime(3) combined with removal of TZ localization.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-03 22:31:18 +00:00
Karel Zak
677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Karel Zak
f4e61504a4 hwclock: don't check for permissions
The right place to verify user permissions is kernel. The current
situation is too strict (due to previous attempts to use hwclock as
suid that has never been supported).

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-09 09:47:33 +01:00
Sami Kerola
984a60965a
misc: always check setenv(3) return value
At least glibc setenv(3) can fail when system runs out of memory.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-08-12 21:25:36 +01:00
Karel Zak
7c678f819b hwclock: use strtimeval_iso()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-24 11:10:10 +02:00
Karel Zak
a8b122f229 hwclock: use labs() for long
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-19 11:38:04 +01:00
J William Piggott
e05ac5aae0 hwclock.c, hwclock.8.in: new --show format
* hwclock.c: change --get and --show functions to the ISO 8601
  format and concatenate fractional seconds to the time display.

* hwclock.8.in: document this.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2016-02-16 19:37:32 -05:00
Ruediger Meier
c211401801 misc: always cast timeval.tv_usec to long rather than int
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-12 14:32:42 +01:00
Karel Zak
ea7f53cdc5 hwclock: remove extra space from --show output
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-01 13:43:22 +01:00
Anna Jonna Ármannsdóttir
dadaad0187 Change of output format and documentation. 2016-01-28 19:03:20 +00:00
Karel Zak
fbed7e09f8 hwclock: change audit message
The preferred layout is name=value for audit messages.

References: https://bugzilla.redhat.com/show_bug.cgi?id=1296278
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-07 13:23:24 +01:00
Sami Kerola
a4aeb5bd80 script, hwclock: check file exist with access(3) rather than stat(3)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-11-09 09:56:14 +01:00
Andreas Henriksson
e8c0003481 hwclock: fix format warning in alpha code
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2015-09-07 08:50:39 +02:00
Andreas Henriksson
88294abaf9 hwclock: fix signed/unsigned comparison warning on alpha
Fixes the following warning:
sys-utils/hwclock.c: In function 'manipulate_epoch':
sys-utils/hwclock.c:1465:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (epoch_opt == -1)

Full build log available on:
https://buildd.debian.org/status/fetch.php?pkg=util-linux&arch=alpha&ver=2.26.2-9&stamp=1440078034

Detected by/via:
https://qa.debian.org/bls/packages/u/util-linux.html

Please note that this has never actually been (build-)tested on alpha,
but should hopefully resolve the warning. Note also that limits.h is
already included.

Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2015-08-24 10:55:39 +02:00
Karel Zak
a172badb03 hwclock: make static analyzes more happy
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-29 14:20:06 +02:00
Karel Zak
687cc5d589 hwclock: don't allow non-root access
Fortunately very few people are crazy enough to install hwclock as
setuid. Some comments in code and unfortunately also man page
advertising that setuid is no problem. That's pretty stupid promise.

The code quality is poor and it's obviously not designed to be secure
(things like popen() without drop privileges, etc.).

This patch removes all notes about "setuid support" and for sure
disable hwclock execution for non-root users.

Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=786804
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-26 10:32:38 +02:00
Alexey Galakhov
ff22953890 hwclock: flush stdout in hwclock -c
This allows using hwclock -c in automated test scripts that parse
its output line-by-line. The standard output is flushed before
each 10 second delay.

Signed-off-by: Alexey Galakhov <agalakhov@gmail.com>
2015-04-27 10:26:18 +02:00
J William Piggott
165ae38f0d hwclock: Remove TZUTC
commit d53f8ecfbf
introduced the TZUTC environment variable to
facilitate use of the zoneinfo 'right' database.
This was incorrect. Either the TZDIR environment
variable should be used or a system-wide
configuration for the 'right' database should be
used.

See hwclock(8) POSIX vs 'RIGHT' for more details.

TZUTC was undocumented and should be safe to remove.

The commit also caused a regression when using
musl libc, because when TZUTC is unset getenv()
returns a NULL pointer.
Reported-by: Isaac Dunham <ibid.ag@gmail.com>

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2015-04-27 10:00:15 +02:00
J William Piggott
a0e215fb2d hwclock: non-root access in test mode
Allow a non-root user to call all hwclock
functions when the --test option is used.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2015-03-17 10:17:26 -04:00
J William Piggott
a36a9026ea hwclock: increase debug output precision
Increased the precision in debug output showing
the clock drift and the time lapsed.

Showing a clock drift of 0.0 while giving a value that the
drift factor was adjusted by makes no sense.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2015-03-17 10:17:26 -04:00
Sami Kerola
559a5b6cf2 sulogin, hwclock: use xusleep() instead of usleep()
As said in include/c.h the usleep() is marked as obsolete, so do the same
that most of the other util-linux calls do with this interface.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-02-10 13:21:24 +01:00
J William Piggott
97c9060b92 hwclock: remove automatic ISA fallback
The old behavior when hwclock was unable to access
the rtc device was to fallback to direct ISA I/O.

This was sometimes allowing two processes to access
the Hardware Clock at the same time and hanging the
system. This is the reason the rtc device driver
only allows one process to open it.

Now hwclock defaults to using the rtc device and only
uses direct ISA when that option is given.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2015-01-13 20:29:21 -05:00
Karel Zak
1c50f02612 hwclock: exclude also i386 from CMOS auto-probing 2015-01-13 13:47:48 +01:00