[Samba] A question about samba and quote

Robert LeBlanc robert at leblancnet.us
Fri Dec 4 11:01:25 MST 2009


On Fri, Dec 4, 2009 at 12:59 AM, Alexander Födisch <foedisch at eva.mpg.de>wrote:

> Hi Robert,
>
> how did you implement the quota script in smb.conf? with parameter "dfree"?
> can you show us your quota script, please?
>
> thanks very much!
> alex
>
> Here is my script, place it at /root/bin/sambaquota.sh
--------8<----------------------------8<---------------------
#! /bin/bash

if [ "$2" == "4" ]; then
 echo "2 0 0 0 0 0 0"
 exit 0
fi

DIRECTORY=`/bin/pwd`
if [ "$DIRECTORY" == "/ls/users" ]; then
  QUOTA=`quota -w -v $3 | awk
'{if(/^\/dev\/mapper\/ldrive-users/){sub(/\*/,"");sub(/        /," 0");print
$2,$3,$4,$6,$7,$8}}'`
elif [ "$DIRECTORY" == "/ls/groups" ]; then
 USER=`wbinfo --uid-info=$3 | awk -F ":" '{ print $1 }'`
groups $USER | grep lfsci-csr > /dev/null
 EXIT=$?
if [ $EXIT -ne "0" ]; then
  QUOTA=`wbinfo -r $USER | xargs quota -w -g | awk
'{if(/\/dev\/mapper\/ldrive-groups/){sub(/        /," 0"); tbused+=$2;
tbsoft+=$3; tbhard+=$4; tfused+=$6; tfsoft+=$7; tfhard+=$8 }} END {print
tbused,tbsoft,tbhard,tfused,tfsoft,tfhard}'`
  if [ "${#QUOTA}" -lt "6" ]; then
   QUOTA="1 1 1 0 0 0"
  fi
 else
  QUOTA="0 0 0 0 0 0"
 fi
fi

echo "2 "$QUOTA
------------8<------------------------------8<-------------------
The first case is if samba is asking for default quotas, really don't know
how a default quota works so we send back nothing. The second case get where
the script if being run from (the share being accessed), then if it's the
user's share, send back the output from the quota command. The quota command
is not very nice in that if the user is over quota it adds an extra field in
the middle of the output, that is what the blank space in the awk commands
does is inserts that field if it is missing. If they are accessing the group
space, then add up all the quotas of all the groups the person belongs to
and use that, otherwise send back an empty quota. The only problem with this
script is that when a person does not have access to the share, it show the
entire disk status (free and size) which I really don't want people seeing.
The reason for this is that we open up the share at the share level and use
ACLs to manage access (much easier than managing hundreds of shares and with
"hide unreadable = true" it seems just as good.

Then in smb.conf add/edit this line:
  get quota command = /root/bin/sambaquota.sh

Hope that helps.


Robert LeBlanc
Life Sciences & Undergraduate Education Computer Support
Brigham Young University


More information about the samba mailing list