2011-10-27 00:21:53 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
# Copyright (C) 2011 OpenWrt.org
|
|
|
|
|
|
|
|
START=98
|
|
|
|
|
2013-07-11 17:00:35 +00:00
|
|
|
USE_PROCD=1
|
|
|
|
PROG=/usr/sbin/ntpd
|
2014-11-28 11:41:25 +00:00
|
|
|
HOTPLUG_SCRIPT=/usr/sbin/ntpd-hotplug
|
2011-10-27 00:21:53 +00:00
|
|
|
|
2016-05-23 12:30:57 +00:00
|
|
|
get_dhcp_ntp_servers() {
|
|
|
|
local interfaces="$1"
|
|
|
|
local filter="*"
|
|
|
|
local interface ntpservers ntpserver
|
|
|
|
|
|
|
|
for interface in $interfaces; do
|
|
|
|
[ "$filter" = "*" ] && filter="@.interface='$interface'" || filter="$filter,@.interface='$interface'"
|
|
|
|
done
|
|
|
|
|
|
|
|
ntpservers=$(ubus call network.interface dump | jsonfilter -e "@.interface[$filter]['data']['ntpserver']")
|
|
|
|
|
|
|
|
for ntpserver in $ntpservers; do
|
|
|
|
local duplicate=0
|
|
|
|
local entry
|
|
|
|
for entry in $server; do
|
|
|
|
[ "$ntpserver" = "$entry" ] && duplicate=1
|
|
|
|
done
|
|
|
|
[ "$duplicate" = 0 ] && server="$server $ntpserver"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2013-11-13 10:49:41 +00:00
|
|
|
validate_ntp_section() {
|
2019-01-12 18:14:22 +00:00
|
|
|
uci_load_validate system timeserver "$1" "$2" \
|
2016-05-23 12:30:57 +00:00
|
|
|
'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0' 'use_dhcp:bool:1' 'dhcp_interface:list(string)'
|
2013-11-13 10:49:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 18:14:22 +00:00
|
|
|
start_ntpd_instance() {
|
|
|
|
local peer
|
2011-10-27 00:21:53 +00:00
|
|
|
|
2019-01-12 18:14:22 +00:00
|
|
|
[ "$2" = 0 ] || {
|
2013-11-13 10:49:41 +00:00
|
|
|
echo "validation failed"
|
|
|
|
return 1
|
|
|
|
}
|
enable ntpd server for busybox
hi
Another version, in this one the enable_server option is in the timeserver ntp part of the "system" config file
You can patch trunk and bacfire (tested both)
You can put busybox ntpd in client mode (if you put server), in client & server (by putting enable_server to 1, ntpd listen to udp 123), and also in server mode only (if you didn't put any servers in the config and still put enable_server 1, ntpd will answer with the time of the router)
I've replaced "config_foreach getpeers timeserver" with "config_get peers ntp server" because we want ntp timeserver, not random ones (to pre-answer if someone want to say that it's intrusive ...)
Signed-off-by: Etienne CHAMPETIER <etienne.champetier@free.fr>
Le 27/03/2012 20:41, Etienne Champetier a écrit :
> I've now tested my trunk patch and it works fine
> But I still can't find were $PROG is defined (is this a mistake, or some sort of built in variable???)
> (I've made some grep and nothing)
>
> Le 23/03/2012 02:19, Philip Prindeville a écrit :
>> Maybe:
>>
>> [ -n "$PROG" -a -x "$PROG" ] || return 1
>>
>> instead?
>>
>>
>> On 3/22/12 4:34 PM, Etienne Champetier wrote:
>>> Hi
>>>
>>> The 2 attached patchs (trunk & bacfire) add busybox ntpd enable_server option, as busybox ntpd server is compiled by default.
>>> We only need 1 client/server daemon (olipro patch was launching 2 daemons)
>>> I've fully tested the bacfire patch, and as i don't have a running openwrt trunk i'm not sure for the trunk patch (i'm sure about my modifications, but i'm not sure about "[ -x $PROG ] || return 1", as "$PROG" isn't defined ?!)
>>>
>>> Signed-off-by: Etienne CHAMPETIER <etienne.champetier@free.fr>
>>>
>>>
>>> Le 16/01/2012 01:57, Philip Prindeville a écrit :
>>>> On 1/14/12 11:37 AM, Olipro wrote:
>>>>> On Saturday 14 Jan 2012 02:45:59 Philip Prindeville wrote:
>>>>>> Don't we already have a 'disabled' option? Now we're adding an
>>>>>> 'enable_server' option?
>>>>>>
>>>>>> That seems confusing for no useful reason.
>>>>>>
>>>>> have you bothered to read what I originally wrote? your response would make
>>>>> me inclined to believe that you didn't.
>>>>>
>>>>> currently the ntpd initscript only runs it as a CLIENT - this patch enables
>>>>> you to have one instance running as a client and another as a SERVER that
>>>>> other hosts can synchronise with.
>>>>>
>>>>> Or perhaps I'm misunderstanding, what would you propose for allowing the
>>>>> built-in busybox ntpd to be utilised as a server? a separate init script
>>>>> entirely perhaps?
>>>> Or separate config sections... instead of 'config ntp' have 'config ntp-server' and 'config ntp-client'.
>>>>
>>>> -Philip
>>>>
>>>>
>>>> _______________________________________________
>>>> openwrt-devel mailing list
>>>> openwrt-devel@lists.openwrt.org
>>>> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
>> _______________________________________________
>> openwrt-devel mailing list
>> openwrt-devel@lists.openwrt.org
>> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
SVN-Revision: 31374
2012-04-20 15:05:38 +00:00
|
|
|
|
2014-06-27 07:55:03 +00:00
|
|
|
[ $enabled = 0 ] && return
|
|
|
|
|
2016-05-23 12:30:57 +00:00
|
|
|
[ $use_dhcp = 1 ] && get_dhcp_ntp_servers "$dhcp_interface"
|
|
|
|
|
2017-03-06 22:20:37 +00:00
|
|
|
[ -z "$server" -a "$enable_server" = "0" ] && return
|
2011-10-27 00:21:53 +00:00
|
|
|
|
2013-07-11 17:00:35 +00:00
|
|
|
procd_open_instance
|
2016-05-29 07:26:37 +00:00
|
|
|
procd_set_param command "$PROG" -n -N
|
2013-11-13 10:49:41 +00:00
|
|
|
[ "$enable_server" = "1" ] && procd_append_param command -l
|
2014-11-28 11:41:25 +00:00
|
|
|
[ -x "$HOTPLUG_SCRIPT" ] && procd_append_param command -S "$HOTPLUG_SCRIPT"
|
2014-03-17 14:52:18 +00:00
|
|
|
for peer in $server; do
|
2013-11-13 10:49:41 +00:00
|
|
|
procd_append_param command -p $peer
|
|
|
|
done
|
2013-09-17 21:45:30 +00:00
|
|
|
procd_set_param respawn
|
2020-11-27 23:45:54 +00:00
|
|
|
[ -x /sbin/ujail -a -e /etc/capabilities/ntpd.json ] && {
|
2021-01-01 12:45:48 +00:00
|
|
|
procd_add_jail ntpd ubus
|
|
|
|
procd_add_jail_mount "$HOTPLUG_SCRIPT"
|
|
|
|
procd_add_jail_mount "/usr/share/libubox/jshn.sh"
|
|
|
|
procd_add_jail_mount "/usr/bin/env"
|
|
|
|
procd_add_jail_mount "/usr/bin/jshn"
|
|
|
|
procd_add_jail_mount "/bin/ubus"
|
2020-10-19 20:22:30 +00:00
|
|
|
procd_set_param capabilities /etc/capabilities/ntpd.json
|
2020-10-25 17:24:03 +00:00
|
|
|
procd_set_param user ntp
|
|
|
|
procd_set_param group ntp
|
2020-10-19 20:22:30 +00:00
|
|
|
procd_set_param no_new_privs 1
|
|
|
|
}
|
2013-07-11 17:00:35 +00:00
|
|
|
procd_close_instance
|
2011-10-27 00:21:53 +00:00
|
|
|
}
|
2013-09-17 21:45:30 +00:00
|
|
|
|
2019-01-12 18:14:22 +00:00
|
|
|
start_service() {
|
|
|
|
validate_ntp_section ntp start_ntpd_instance
|
|
|
|
}
|
|
|
|
|
2016-05-23 12:30:57 +00:00
|
|
|
service_triggers() {
|
|
|
|
local script name use_dhcp
|
|
|
|
|
|
|
|
script=$(readlink -f "$initscript")
|
|
|
|
name=$(basename ${script:-$initscript})
|
|
|
|
|
|
|
|
procd_add_config_trigger "config.change" "system" /etc/init.d/$name reload
|
|
|
|
|
|
|
|
config_load system
|
|
|
|
config_get use_dhcp ntp use_dhcp 1
|
|
|
|
|
|
|
|
[ $use_dhcp = 1 ] && {
|
|
|
|
local dhcp_interface
|
|
|
|
config_get dhcp_interface ntp dhcp_interface
|
|
|
|
|
|
|
|
if [ -n "$dhcp_interface" ]; then
|
|
|
|
for n in $dhcp_interface; do
|
|
|
|
procd_add_interface_trigger "interface.*" $n /etc/init.d/$name reload
|
|
|
|
done
|
|
|
|
else
|
|
|
|
procd_add_raw_trigger "interface.*" 1000 /etc/init.d/$name reload
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-11-13 10:49:41 +00:00
|
|
|
procd_add_validation validate_ntp_section
|
2013-09-17 21:45:30 +00:00
|
|
|
}
|