# modlibinetd is only used by rc.inetd INETD_CONF="/var/mod/etc/inetd.conf" [ "$INETD_IPV6_SUPPORT" == "yes" -a -d /proc/sys/net/ipv6 ] && local inetd_ipv6=6 update_user() { cat /tmp/flash/inetd/inetd.user 2>/dev/null > $INETD_CONF [ "$?" -eq 0 ] && echo "# END OF CUSTOM CONFIG" >> $INETD_CONF } update_line() { line="$single_port\t$inetdcfg_sock\t$inetdcfg_proto\t$inetdcfg_flags" line="$line\t$inetdcfg_user\t$inetdcfg_exe\t$inetdcfg_arg0 $inetdcfg_args" [ "$1" = escape ] && line=$(echo -n "$line" | sed -e 's@/@\\/@g') echo -en "$line" } update_file() { local pkg_path=$1 local pkg_subd=$(echo $pkg_path | sed -e 's@^/etc/default\.[^/]*/\([^/]*\)\.inetd$@\1@') local pkg_name=$(echo $pkg_path | sed -e 's@^/etc/default\.\([^/]*\)/[^/]*\.inetd$@\1@') if [ ! -e "/etc/init.d/rc.$pkg_name" ]; then echo "$DAEMON: package $pkg_name has no rc script, failed." exit 1 fi . $pkg_path "$inetd_ipv6" if [ "$pkg_name" != "$pkg_subd" ]; then sub_status=$(/etc/init.d/rc.$pkg_name status_$pkg_subd) local pkg_out="$pkg_name ($pkg_subd)" pkg_inetd=${pkg_name}_$pkg_subd else sub_status= local pkg_out="$pkg_name" pkg_inetd=$pkg_name fi echo -n "$pkg_out is updating inetd ... " sed -i -e "/#:$pkg_inetd:/ { n; s/^\([^#].*\)/##\1/ }" $INETD_CONF for single_port in $inetdcfg_port; do if ! grep -q "#:$pkg_inetd:$single_port:" $INETD_CONF; then echo >> $INETD_CONF echo "#:$pkg_inetd:$single_port: $inetdcfg_desc" >> $INETD_CONF echo "##$(update_line)" >> $INETD_CONF fi if [ "inetd" == "$(/etc/init.d/rc.$pkg_name status)" -o "inetd" == "$sub_status" ]; then sed -i -e "/#:$pkg_inetd:$single_port:/ { n; s/^.*/$(update_line escape)/ }" $INETD_CONF local pkg_status="active." fi done echo "${pkg_status:-inactive.}" } update_main() { if [ $# -eq 0 ]; then echo -e '\nConfiguring inetd: ...' update_user for package in $(ls /etc/default.*/*.inetd); do update_file $package done echo 'Configuring inetd: done.' else for package; do package_main=$(ls /etc/default.$package/*.inetd 2>/dev/null) if [ -n "$package_main" ]; then for package_sub in $package_main; do update_file "$package_sub" done else echo "$DAEMON: package $package has no default inetd file, failed." fi done fi # check if we could listen on socket grep -vE "^$|^#" $INETD_CONF | while read line; do local cleanline="$(echo "$line" | sed 's/[[:space:]]*/ /g;s/^ //g')" local listener=$(echo "$cleanline" | cut -d " " -f1) local ip_proto=$(echo "$cleanline" | cut -d " " -f3) if [ "$(grep -E "^$listener[[:space:]]*(stream|dgram|raw|seqpacket)[[:space:]]*$ip_proto" $INETD_CONF 2>/dev/null | wc -l)" -gt 1 ]; then echo -n "WARNING: inetd could not listen on '$listener/$ip_proto' multiple times: " if grep "$line" -B1 $INETD_CONF | head -n1 | grep -q "^#"; then grep "$line" -B1 $INETD_CONF | head -n1 else echo "$line" fi fi done } [ ! -e $INETD_CONF ] && update_user