Cpanels Disk Quota Warning BUG and fix

patrickb

Registered
Dec 8, 2003
4
0
151
We have always received reports from some users that they were recieving false email warnings about their disk quota usage. As an example, one user recently has been having this problem. He has 20gigs of HD space alloted to him, and only about 181megs of actual space used, but he kept getting email warnings saying he was using 90% of his space.

After reviewing how cpanel checks quota usage for these warnings, I found the problem in this section of /scripts/quotacheck

Code:
   } else {
      if ($quotalines =~ /-/ || $quotalines =~ /\+/) {
         $username = substr($quotalines,0,10);
         if ($username =~ /^#(\d+)/) {
            $username = (getpwuid($1))[0];
         }
         $used = substr($quotalines,12,8);
         $hard = substr($quotalines,28,8);
         $username =~ s/\s//g;
         $used =~ s/\s//g;
         $hard =~ s/\s//g;
         if ($username !~ /^\d*$/) {
            $USED{$username} = $USED{$username} + $used;
            if ($hard > 0) {$LIMIT{$username} = $hard;}
         }
      }
   }
Now, the problem with that is that /usr/sbin/repquota does not report quotas in a fixed format and length. Cpanel seems to have assumed this would always be set in stone. Anything over 10gigs as reported by repquota would break their substr usage for $hard. Note: This was on a Red Hat 9 box running kernel 2.4.25-ow1. This may or may not apply in other distros.

Now, for the fix, replace all of the above code with:

Code:
   } else {
      if ($quotalines =~ /-/ || $quotalines =~ /\+/) {
         @quotasplit = split(/\ +/, $quotalines);
         $username = $quotasplit[0];
         if ($username =~ /^#(\d+)/) {
            $username = (getpwuid($1))[0];
         }
         $used = $quotasplit[2];
         $hard = $quotasplit[4];
         if ($username !~ /^\d*$/) {
            $USED{$username} = $USED{$username} + $used;
            if ($hard > 0) {$LIMIT{$username} = $hard;}
         }
      }
   }
Again, this may or may not apply to other distros, but maybe someone here running something different can verify this. At SSH type '/usr/sbin/repquota -auv' and see if the lengths of the returned output varies if you have any accounts over the 10gig mark.

To CPanel: Could you correct this in a future release, like soon!
 
Last edited:

apodigm

Well-Known Member
May 12, 2003
67
0
156
This definitely seems to make sense.

Does this file get overwritten often? I dont like to chattr too much, but it seems like this is one of those files that cpanel likes to change automatically.
 

shiv

Member
Jul 26, 2004
16
0
151
Bangalore
No luck Please help

Hi,,

I was not able to run the script after adding the changes specified. Here is the error:


[email protected] [~]# /scripts/quotacheck
Quantifier follows nothing before HERE mark in regex m/+ << HERE / at /scripts/quotacheck line 92.


Please advise soon.
 

patrickb

Registered
Dec 8, 2003
4
0
151
apodigm: So far I don't think this file has changed one bit since my original posting. If you don't want to chattr it, then make a copy of it and stick it somewhere to have on hand when you encounter the problem.

shiv: That problem is because the forum software here isn't showing the "\" in what I pasted. To fix it, find the line in your file and it should look like "if ($quotalines =~ /-/ || $quotalines =~ /+/) {". Add the backwards slash right before the + sign on that line and it will work again. Sorry, I never caught that in the original post.
 

cPDan

cPanel Staff
Staff member
Mar 9, 2004
721
13
243
patrickb said:
Code:
   } else {
      if ($quotalines =~ /-/ || $quotalines =~ /\+/) {
You have to escape the plus sign so its a plus sign and not a quantifier quantifying nothing.
 

patrickb

Registered
Dec 8, 2003
4
0
151
Yes, that is the technical explanation for it. :) I changed the original post to use CODE tags instead of the PHP tags and it now displays my original entries properly with the escape included so anyone else wanting to cut-n-paste the code can now without having to worry about the problem pointed out by shiv.
 

cPDan

cPanel Staff
Staff member
Mar 9, 2004
721
13
243
Thats fine, I'd just had a couple tickets about it and figured I'd exaplain the error :)
Yeah, CODE is better than PHP :) PHP always causes problems!