[Samba] get quota command - Example
I know when I went looking for a complete example of how to interface with samba's quota system there was no good ones, so here it is. I developed this yesterday with a lot of trial and error. Feel free to use this in any way people feel fit. With this script I can now get correct used/free reporting based on the output of quota for both users and groups. I developed this because samba could not recognize a combination of NFS and LVM's ext3 quota's through automount. It was developed on CentOS4.3 on a poweredge 2800 with shared SCSI storage. It should work on many more systems than the default because it uses the mount and quota commands directly, although this may cause some problems in very large systems due to constant use of perl in the background. If nothing else this will serve as a starting point for those attempting to make heads or tails of the documentation. Cheers, Eric Warnke Systems Administrator - Research IT State University of New York at Albany #!/usr/bin/perl # # Copyright 2006 Eric Warnke <[EMAIL PROTECTED]> # This application may be used for any purpose as long # as credit is givin to Eric Warnke and to SUNY Albany # # This application interfaced SAMBA 3.X series cifs server with # quota information available through the command line # application /usr/bin/quota on Centos 4.3 # # THIS APPLICATION WORKS FOR ME, BUT YOU MAY NEED TO MAKE # CHANGES FOR IT TO WORK PROPERLY IN YOUR ENVIRONMENT! # # USE AT YOUR OWN RISK # # Setup safe env so that perl doesn't complain $ENV{PATH} = ( '/bin', '/usr/bin' ); # Capture environment variables # Directory for whom quota is to be checked $directory = $ARGV[0]; # Type of query 2 = user 4 = group 1,3 not quite sure how they work in reality $type = $ARGV[1]; if ( $type =~ /([1-4])/ ) { $type = $1; # untaint } else { die("Incorrect type flag"); } # UID or GID to be checked $id = $ARGV[2]; if ( $id =~ /(\d+)/ ) { $id = $1; # untaint } else { die("Is that really a uid or gid?"); } # For some reason, despite what documentation states, samba always # appears to pass the directory as "." ( quotes part of string ) # this maps to pwd of the script. # # This should be changed in samba to always be the full string or be dropped # as an unnecessary argument # if ( $directory eq '"."' ) { $directory = `/bin/pwd`; chomp($directory); } # Debugging, useful for capturing arguments passed to script #open(LOG,">>/tmp/log.txt"); #print LOG "$directory,$type,$id\n"; #close(LOG); # Don't know what to do with these since they are never called if ( $type == 1 || $type == 3 ) { print "0 0 0 0 0 0 0\n"; exit; } # Capture the mount point mappings in the system # this could have also been done through /proc open(MOUNT, "/bin/mount|"); while ($line = ) { ($def, $temp1, $mp, $temp2) = split(/ /, $line); #print "$def,$mp\n"; $mount_point{$mp} = $def; } close(MOUNT); # Find the mapping for the directory, we may have to loop here # since with LVM we have to find the DEVICE that it's mapped to # # !! THIS MAY NEED TO BE CHANGED FOR YOUR SYSTEM !! # do { @dirsplit = split(/\//,$directory); for([EMAIL PROTECTED]; $i!=0; $i--) { $test_dir = join("/",@dirsplit[0 .. $i]); #print "t $test_dir\n"; last if ( $mount_point{$test_dir} ne "" ); } $directory = $mount_point{$test_dir}; } until ( ($directory =~ /^\/dev\//)||($directory=~/^\S+:/) ); # Build the quota command necessary # if ( $type == 4 ) { $typearg = "-g"; } else { $typearg = ""; } $cmd = "/usr/bin/quota $typearg $id"; # Open the output from quota, scan for the mountpoint device # and then regurgitate the line with some small changes so that # samba can understand it. # open(QUOTA,"$cmd|"); while ( $line = ) { if ( $line =~ /$directory/ ) { $line = ; print "2"; print join(" ",split(/\s+/,$line)); print "\n"; exit; } } print "0 0 0 0 0 0 0\n"; -- To unsubscribe from this list go to the following URL and read the instructions: https://lists.samba.org/mailman/listinfo/samba
[Samba] get quota command
In the "get quota command" option of smb.conf I point to a script which outputs this line: 1 156484 10 20 6748 0 0 when called passing the uid of the user whose quota is to be checked as third parameter. Also the script has read and execution permission for any user. I have this problems: - The clients don't get this information right (it shows instead the total disk space of the partition and the samba logs say that the output of the command is invalid) - Samba always calls this script with "." as first parameter. I thought I could use this parameter to know for which of the shared folders is it asking the quota limits, but it always passes that parameter so I can't. Could this be a bug? - (To developers) Wouldn't it be better to report to the clients the hard quota limit instead of the soft limit? This can cause that Windows doesn't upload the profile at logoff when the used space is over the soft limit, when actually it could be uploaded because the hard limit hasn't been exceeded. -- To unsubscribe from this list go to the following URL and read the instructions: https://lists.samba.org/mailman/listinfo/samba
Re: [Samba] get quota command
I found the answer to my own question in a round about sort of way.. My NFS server is Solaris w/UFS - thus no group quota support. It seems when samba queries for user quotas and group quotas, it gets unhappy when no group quota is returned, so the quotas are thrown out and the windows boxes see the entire volume's free, used and capacity. To fix this I set the two options in my conf file: vfs objects = default_quota:quotasettings quotasettings: gid = 65534 Rick Brown wrote: > I've discovered that if I make a share from a local filesystem, > the PC's mounting the share see their quota (hard limit, not > soft which is another matter) as their capacity and their > appropriate free space... this is good. I found in the source that the hard limit is used instead of the soft limit if the user is over quota. > When I share ouf the NFS mounted volume, the PC's see the entire > volume size and free space. Not so good. Okay fine, so I > wrote a little cheesy script to run run quota and report back and > defined it as "get quota command = myscript" in smb.conf. > This works great... mostly.I wasn't seeing the values I > expected to see, so I started dumping the arguments samba was > passing to my scipt. I expected 3 fields: Path, type of query, and > user/group ID.something like: > "." 1 32849 (user quota) > "." 3 1178(group quota) > > instead, I'm seeing samba pass: > "." 2 32849 (default user quota) > "." 4 1178(default group quota) > > Why is samba asking for the default user and group quotas instead of > the actual user and group quotas? From the documentation I would > have expected that if field 2 was a 2 or 4, then the uid/gid would be > -1. How can I make samba request the actual user and group's quota > instead of the defaults? And since I didn't easily find any examples of a "get quota command" I'll share my super-cheesy script which totally ignores the values passed to it by samba. It's not pretty, but it works. #!/bin/ksh PATH=/usr/bin:/usr/sbin:/bin IAM=`id -un` # find the user's home file system. DIR=`ypmatch $IAM passwd | awk -F: '{print $6}' | cut -f 2 -d "/"` #check and see if they're over quota, as it will affect output OVER=`quota -F rpc -v $IAM | grep $DIR | wc -w` #OVER=`quota -f rpc -v $IAM | grep $DIR | egrep -i "expired|days" #if [ $? -ne 0]; then # over quota if [ $OVER -gt 7 ]; then RET=`quota -v $IAM | grep ${DIR} | awk -F" " '{print "2 "$2" "$3" "$4" "$7" "$8" "$9}'` else # not over quota RET=`quota -v $IAM | grep ${DIR} | awk -F" " '{print "2 "$2" "$3" "$4" "$5" "$6" "$7}'` fi # linux "quota" puts a * after the used blocks if the user is over quota STRIPPED=`echo $RET | sed 's/*/ /g'` echo $STRIPPED -- [ Rick Brown ][ (404) 894-6175 ] [ Office of Information Technology ][[EMAIL PROTECTED] ] [ Georgia Institute of Technology ][ 258 4th street. Atlanta, GA ] -- To unsubscribe from this list go to the following URL and read the instructions: https://lists.samba.org/mailman/listinfo/samba
[Samba] get quota command
I'm running samba 3.0.13 on a debian box, sharing out NFS filesystems from a solaris box. I know, bad idea.. file locking, etc... non-issues at the moment. I've discovered that if I make a share from a local filesystem, the PC's mounting the share see their quota (hard limit, not soft which is another matter) as their capacity and their appropriate free space... this is good. When I share ouf the NFS mounted volume, the PC's see the entire volume size and free space. Not so good. Okay fine, so I wrote a little cheesy script to run run quota and report back and defined it as "get quota command = myscript" in smb.conf. This works great... mostly.I wasn't seeing the values I expected to see, so I started dumping the arguments samba was passing to my scipt. I expected 3 fields: Path, type of query, and user/group ID.something like: "." 1 32849 (user quota) "." 3 1178 (group quota) instead, I'm seeing samba pass: "." 2 32849 (default user quota) "." 4 1178 (default group quota) Why is samba asking for the default user and group quotas instead of the actual user and group quotas? From the documentation I would have expected that if field 2 was a 2 or 4, then the uid/gid would be -1. How can I make samba request the actual user and group's quota instead of the defaults? -- [ Rick Brown ][ (404) 894-6175 ] [ Office of Information Technology ][[EMAIL PROTECTED] ] [ Georgia Institute of Technology ][ 258 4th street. Atlanta, GA ] -- To unsubscribe from this list go to the following URL and read the instructions: https://lists.samba.org/mailman/listinfo/samba
[Samba] get quota command
I'm running samba 3.0.13 on a debian box, sharing out NFS filesystems from a solaris box. I know, bad idea.. file locking, etc... non-issues at the moment. I've discovered that if I make a share from a local filesystem, the PC's mounting the share see their quota (hard limit, not soft which is another matter) as their capacity and their appropriate free space... this is good. When I share ouf the NFS mounted volume, the PC's see the entire volume size and free space. Not so good. Okay fine, so I wrote a little cheesy script to run run quota and report back and defined it as "get quota command = myscript" in smb.conf. This works great... mostly.I wasn't seeing the values I expected to see, so I started dumping the arguments samba was passing to my scipt. I expected 3 fields: Path, type of query, and user/group ID.something like: "." 1 32849 (user quota) "." 3 1178 (group quota) instead, I'm seeing samba pass: "." 2 32849 (default user quota) "." 4 1178 (default group quota) Why is samba asking for the default user and group quotas instead of the actual user and group quotas? From the documentation I would have expected that if field 2 was a 2 or 4, then the uid/gid would be -1. How can I make samba request the actual user and group's quota instead of the defaults? -- [ Rick Brown ][ (404) 894-6175 ] [ Office of Information Technology ][[EMAIL PROTECTED] ] [ Georgia Institute of Technology ][ 258 4th street. Atlanta, GA ] - End forwarded message - -- [ Rick Brown ][ (404) 894-6175 ] [ Office of Information Technology ][[EMAIL PROTECTED] ] [ Georgia Institute of Technology ][ 258 4th street. Atlanta, GA ] -- To unsubscribe from this list go to the following URL and read the instructions: https://lists.samba.org/mailman/listinfo/samba
[Samba] get quota command bugs?
First of all: Thanks Samba-Team for a job well-done on Samba-3.0.0 (nice new features) Now some problems: 1. We're use Veritas filesystem on our RedHat AS 2.1 server and quota don't seem to work at this moment (/usr/include/sys/fs/vx_quota.h is missing). So I thought that using "get quota command" would do the trick (just call vxquota and parse output). But nothing happend!!! Script was OK. After poking around in lib/sysquotas.c I found that "get quota command" was only called if HAVE_SYS_QUOTA is defined. I thought that "get quota command"should always be called upon when it is defined in smb.conf. 2. The man page of smb.conf seems to imply that the output of the "get quota command" should be returned as one result per line. This is wrongf: all results must be returned on one line comma seperated. Also the "set quota command" has some docu bug (some nroff tags are shown). 3. In the Samba-HOWTO-Docu... it says on page 141 that mapping domadm group to the "Domain Admins" group is done with a "net groupmap add" command. I think this should be "net groupmap modify" command. I ended up with a new "Domain Admins"-group having another RID which lead to some confusion (I am a domain admin but not). Keep up the good work, René Nieuwenhuizen Afdeling Informatietechnologie Centraal Planbureau Bezoekadres: Van Stolkweg 14, 2585 JR Den Haag Postadres: Postbus 80510, 2508 GM Den Haag T (070) 3383 342 F (070) 3383 350 I http://www.cpb.nl/nl/general/org/afdelingen/it/ -- Aan dit bericht kunnen geen rechten worden ontleend. Het bericht is alleen bestemd voor de geadresseerde. Indien dit bericht niet voor u is bestemd, verzoeken wij u dit onmiddellijk aan ons te melden en de inhoud van het bericht te vernietigen. This message shall not constitute any obligations. This message is intended solely for the addressee. If you have received this message in error, please inform us immediately and delete its contents. -- To unsubscribe from this list go to the following URL and read the instructions: http://lists.samba.org/mailman/listinfo/samba