You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

  1. #!/bin/bash
  2. ##
  3. ## code
  4. ##
  5. chmod 440 /etc/sudoers.d/* -R
  6. KEYS=/etc/rsync/keys
  7. RSYNC_HOME=/var/lib/rsync
  8. mkdir -p "$RSYNC_HOME/.ssh"
  9. if ! egrep '^[^:]+:x:101:101:' /etc/passwd; then
  10. ## Then it is a first run of this container, users
  11. ## need to be created. Notice that container will be
  12. ## re-created anew if user config was changed.
  13. for user_dir in /etc/rsync/keys/admin/*; do
  14. [ -d "$user_dir" ] || continue
  15. user="${user_dir##*/}"
  16. [ "$user" != "rsync" ] || continue
  17. adduser -S "$user" -h "$user_dir" -G rsync &&
  18. chown "$user":rsync "$user_dir" || {
  19. echo "Error: couldn't create user $user or chown '$user_dir'." >&2
  20. exit 1
  21. }
  22. ## Without this, account is concidered locked by SSH
  23. sed -ri "s/^$user:\!:/$user:*NP*:/g" /etc/shadow
  24. ## Withouth this, force-command will not run
  25. sed -ri "s%^($user.*:)[^:]+$%\1/bin/bash%g" /etc/passwd
  26. done
  27. fi
  28. log="/var/log/rsync/ssh-admin-cmd-validate.log"
  29. touch "$log"
  30. chown rsync:rsync "$log"
  31. chmod g+rw "$log"
  32. ssh-update-keys
  33. ## Give back PID 1 so that ssh can receive signals
  34. exec /usr/sbin/sshd -D -e