Rerun of failed installation adds repeated lines to config files. #159

Closed
opened 2026-04-05 20:25:37 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @naudefj on 11/28/2024

CloudPanel version(s) affected

2.5.0

Description

File "/var/lib/dpkg/info/cloudpanel.postinst" may write duplicate lines to config files. Note the two lines with ">>" in the function below.

setupSshRestrictionRules()
{
  local SECURITY_ACCESS_FILE="/etc/security/access.conf"
  echo "session optional pam_umask.so umask=0002" >> /etc/pam.d/common-session
  if [ "$IS_LXC" = "0" ]; then
    sed -i "s/.*PasswordAuthentication no/PasswordAuthentication yes/g" /etc/ssh/sshd_config
    sed -i "s/.*PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config
  fi
  echo "DenyUsers clp" >> /etc/ssh/sshd_config
  echo "account required pam_access.so" > /tmp/cloudpanel/pam_sshd
  cat /etc/pam.d/sshd >> /tmp/cloudpanel/pam_sshd
  cat /tmp/cloudpanel/pam_sshd > /etc/pam.d/sshd
  /etc/init.d/ssh restart
}

How to reproduce

Re-try failed installation.
Note duplicate entries in /etc/pam.d/common-session and /etc/ssh/sshd_config.

Possible Solution

Check if entries exists before adding it indiscriminately.
For example:

if ! grep -q 'DenyUsers clp' /etc/ssh/sshd_config; then
...
fi

Additional Context

No response

*Originally created by @naudefj on 11/28/2024* ### CloudPanel version(s) affected 2.5.0 ### Description File "/var/lib/dpkg/info/cloudpanel.postinst" may write duplicate lines to config files. Note the two lines with ">>" in the function below. ``` setupSshRestrictionRules() { local SECURITY_ACCESS_FILE="/etc/security/access.conf" echo "session optional pam_umask.so umask=0002" >> /etc/pam.d/common-session if [ "$IS_LXC" = "0" ]; then sed -i "s/.*PasswordAuthentication no/PasswordAuthentication yes/g" /etc/ssh/sshd_config sed -i "s/.*PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config fi echo "DenyUsers clp" >> /etc/ssh/sshd_config echo "account required pam_access.so" > /tmp/cloudpanel/pam_sshd cat /etc/pam.d/sshd >> /tmp/cloudpanel/pam_sshd cat /tmp/cloudpanel/pam_sshd > /etc/pam.d/sshd /etc/init.d/ssh restart } ``` ### How to reproduce Re-try failed installation. Note duplicate entries in /etc/pam.d/common-session and /etc/ssh/sshd_config. ### Possible Solution Check if entries exists before adding it indiscriminately. For example: if ! grep -q 'DenyUsers clp' /etc/ssh/sshd_config; then ... fi ### Additional Context _No response_
Sign in to join this conversation.