mirror of
https://github.com/openwrt/openwrt.git
synced 2026-11-27 16:50:30 +04:00
ppp: keep credentials off the ujail command line
Read the username and password from a file to avoid exposing the
password in the `ujail` command line.
pppd parses options files itself, so backslash and double quote in
the username and password are escaped with a backslash when the file
is written. Values passed on the command line are not parsed and
needed no escaping.
Use `net-init-script` to delete the temporary file after `pppd` has
read its options, and unconditionally delete it when the interface
is brought down.
Fixes: b855f33ea9 ("ppp: run pppd in ujail as an unprivileged user")
Signed-off-by: Andy Chiang <AndyChiang_git@outlook.com>
Link: https://github.com/openwrt/openwrt/pull/26293
Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
1 parent
b55b1b0ee1
commit
ab60d82ca5
3 files changed
+34
-2
No files matched your search
@@ -10,7 +10,7 @@ include $(INCLUDE_DIR)/kernel.mk
|
||||
|
||||
PKG_NAME:=ppp
|
||||
PKG_VERSION:=2.5.4
|
||||
PKG_RELEASE:=3
|
||||
PKG_RELEASE:=4
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://download.samba.org/pub/ppp
|
||||
@@ -220,6 +220,7 @@ define Package/ppp/install
|
||||
$(INSTALL_BIN) ./files/lib/netifd/ppp-up $(1)/lib/netifd/
|
||||
$(INSTALL_BIN) ./files/lib/netifd/ppp6-up $(1)/lib/netifd/
|
||||
$(INSTALL_BIN) ./files/lib/netifd/ppp-down $(1)/lib/netifd/
|
||||
$(INSTALL_BIN) ./files/lib/netifd/ppp-net-init $(1)/lib/netifd/
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./files/50-ppp-secrets-mode.sh $(1)/etc/uci-defaults
|
||||
endef
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
# pppd net-init script. It runs once the ppp unit is known, which is after
|
||||
# pppd has parsed its options, so the credentials file written by ppp.sh is
|
||||
# no longer needed.
|
||||
# $1 ifname $2 tty $3 speed $4 ipparam (the netifd interface name)
|
||||
[ -n "$4" ] && rm -f "/var/run/pppd/$4.opts"
|
||||
exit 0
|
||||
@@ -65,6 +65,20 @@ ppp_exitcode_tostring()
|
||||
esac
|
||||
}
|
||||
|
||||
ppp_opt_quote() {
|
||||
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
|
||||
}
|
||||
|
||||
ppp_write_auth_file() {
|
||||
local file="$1" user="$2" pass="$3"
|
||||
|
||||
(
|
||||
umask 077
|
||||
printf 'user "%s"\npassword "%s"\n' \
|
||||
"$(ppp_opt_quote "$user")" "$(ppp_opt_quote "$pass")" > "$file"
|
||||
)
|
||||
}
|
||||
|
||||
ppp_generic_init_config() {
|
||||
proto_config_add_string username
|
||||
proto_config_add_string password
|
||||
@@ -163,6 +177,14 @@ ppp_generic_setup() {
|
||||
done
|
||||
}
|
||||
|
||||
local optfile
|
||||
[ -n "$username" ] && {
|
||||
optfile="/var/run/pppd/$config.opts"
|
||||
mkdir -p /var/run/pppd
|
||||
ppp_write_auth_file "$optfile" "$username" "$password"
|
||||
[ -n "$jail" ] && chown ppp "$optfile"
|
||||
}
|
||||
|
||||
proto_run_command "$config" $jail /usr/sbin/pppd \
|
||||
nodetach ipparam "$config" \
|
||||
ifname "$pppname" \
|
||||
@@ -180,7 +202,7 @@ ppp_generic_setup() {
|
||||
usepeerdns \
|
||||
$demand $persist maxfail $maxfail \
|
||||
${holdoff:+holdoff "$holdoff"} \
|
||||
${username:+user "$username" password "$password"} \
|
||||
${optfile:+file "$optfile" net-init-script /lib/netifd/ppp-net-init} \
|
||||
${connect:+connect "$connect"} \
|
||||
${disconnect:+disconnect "$disconnect"} \
|
||||
ip-up-script /lib/netifd/ppp-up \
|
||||
@@ -195,6 +217,8 @@ ppp_generic_teardown() {
|
||||
local interface="$1"
|
||||
local errorstring=$(ppp_exitcode_tostring $ERROR)
|
||||
|
||||
rm -f "/var/run/pppd/$interface.opts"
|
||||
|
||||
case "$ERROR" in
|
||||
0)
|
||||
;;
|
||||
|
||||
Reference in new issue
Block a user