On 7 Jun 2013 23:49:06 GMT, Peter Pearson <ppea...@nowhere.invalid> wrote:
> I'd like to read the CMOS clock from a Python script, and
> what "sudo hwclock -r" prints would be just fine, but it
> seems like poor security to run the Python script as root,
> and hwclock won't give me the time of day (hee! - sorry) if
> it's not run as root.
Many thanks to the several helpful people who troubled to
address this question, which turned out (this keeps happening)
to be more complicated than I expected.
Here's the "permissions situation" on my Debian system:
$ ls -l /dev/rtc*
lrwxrwxrwx 1 root root 4 Jun 2 17:41 /dev/rtc -> rtc0
crw------- 1 root root 254, 0 Jun 2 17:41 /dev/rtc0
$ /sbin/hwclock -r --debug
hwclock from util-linux-ng 2.17.2
hwclock: Open of /dev/rtc failed, errno=13: Permission denied.
No usable clock interface found.
Cannot access the Hardware Clock via any known method.
I interpret this to mean that non-root people are forbidden to use
/dev/rtc0, and therefore /dev/rtc. One suggestion was to change
/lib/udev/rules.d/50-udev-default.rule by adding MODE="0644", and
to chmod 644 /dev/rtc0. This leads to the question, How can I be sure
that relaxing restrictions on this device doesn't harm security?
Yes, I can easily imagine that someone defining the default
Debian configuration removed those permissions for No Good Reason;
but unfortunately I'm not competent to declare it so. (Of course,
if granting universal read access is insecure, then at least one
of the respondents is vulnerable.)
For completeness of this record, one respondent found that the chrony
daemon, chronyd, was keeping /dev/rtc open, resulting in a "device or
resource busy" error message instead of "permission denied".