#!/bin/sh

#
# rsync-backup-client - check if ssh command is allowed for this user
#
# Copyright (C) 2020 Thorsten Kukuk <kukuk@thkukuk.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

export LANG=C

if [ -n "$SSH_ORIGINAL_COMMAND" ]
then
  case "$SSH_ORIGINAL_COMMAND" in
    "rsync --server --sender -vlHogDtpre."*" --numeric-ids . /"*)
      logger "rsync-backup started for ${SSH_ORIGINAL_COMMAND#*numeric-ids . }"
      exec sudo ${SSH_ORIGINAL_COMMAND}
      ;;
    *)
      logger "DENIED: $(/bin/date) - $SSH_ORIGINAL_COMMAND"
      exit 1
      ;;
  esac
fi
exit 1
