#!/bin/bash #Unused for now. It should never fail, function checkuids { local optfix="" local alldomains local domain mismatch domainfileid domainfile local vminuid vmingid domainuser systemuid systemgid OPTIND=1 while getopts 'f' OPTION do case $OPTION in f) optfix=1 ;; ?) echo "Usage checkuids [-f] domains"; return 2;; esac done shift $(($OPTIND - 1)) alldomains="$@" vmindomainsconfdir="/etc/webmin/virtual-server/domains" mismatch=0 for domain in $alldomains; do domainfileid=$(virtualmin list-domains --domain $domain --id-only) domainfile=$vmindomainsconfdir/$domainfileid vminuid=$(cat $domainfile | grep -E "^uid" | cut -d"=" -f 2) vmingid=$(cat $domainfile | grep -E "^gid" | cut -d"=" -f 2) #domainuser=$(echo $domain | cut -d"." -f 1) #faster but not as safe domainuser=$(virtualmin list-domains --domain $domain --user-only) systemuid=$(id -u $domainuser) systemgid=$(id -g $domainuser) if [ "$vminuid" = "$systemuid" ] && [ "$vmingid" = "$systemgid" ]; then echo "Domain $domain : OK" else #Backing up just in case cp $domainfile $backupdir/$domainfileid-$(date +%Y-%m-%d_%H-%M-%S).bak if [ "$vminuid" != "$systemuid" ]; then mismatch=$(expr $mismatch + 1) echo "Domain $domain : systemuid=$systemuid, vminuid=$vminuid" if [ "$optfix" ]; then sed -i "s/^uid.*/uid=$systemuid/g" $domainfile echo "fixed..." fi fi if [ "$vmingid" != "$systemgid" ]; then mismatch=$(expr $mismatch + 1) echo "Domain $domain : systemgid=$systemgid, vmingid=$vmingid" if [ "$optfix" ]; then sed -i "s/^gid.*/gid=$systemgid/g" $domainfile echo "fixed..." fi fi fi done OPTIND=1 return $mismatch } function do_checkuids { # Report only : do_checkuids # Report and fix : do_checkuids -f #set -x #GLOBALS fixflag="-f" alldomainsfile=alldomainsfile.txt backupdir=/backup/virtualmin/domains mkdir -p $backupdir virtualmin list-domains --toplevel | sed '1,2d' | cut -d" " -f 1 > $alldomainsfile allvmindomains=$(cat $alldomainsfile) checkuids $1 $allvmindomains retval=$? if [ "$retval" = "0" ]; then echo "All OK!" else echo -n "Found $retval mismatches" if [ "$1" = "$fixflag" ]; then echo " and fixed them all" #Restart webmin debian/ubuntu specific /etc/init.d/webmin restart else echo "" fi fi } # -f : fix #Usage checkids [-f] domain1 domain2 .. checkuids $@ #Or for all domains uncomment following #do_checkuids # Report only #do_checkuids -f # Report and fix