2 # Quota functions for UnixWare 7
11 # Returns 1 for user quotas, 2 for group quotas or 3 for both
17 # free_space(filesystem)
18 # Returns an array containing btotal, bfree, ftotal, ffree
23 $out =~ /(\d+) blocks\s+(\d+) files\n.*\s+(\d+) blocks\s+(\d+) files/;
24 return ($3, $1, $4, $2);
27 # quota_can(&mnttab, &fstab)
28 # Can this filesystem type support quotas?
29 # 0 = No quota support (or not turned on in /etc/fstab)
30 # 1 = User quotas only
31 # 2 = Group quotas only
32 # 3 = User and group quotas
35 return $_[0]->[2] eq "ufs" || $_[0]->[2] eq "vxfs" ? 1 : 0;
38 # quota_now(&mnttab, &fstab)
39 # Are quotas currently active?
41 # 1 = User quotas active
42 # 2 = Group quotas active
46 return $_[0]->[3] =~ /,quota/ || $_[0]->[3] =~ /^quota/ ? 1 : 0;
49 # filesystem_users(filesystem)
50 # Fills the array %user with information about all users with quotas
51 # on this filesystem. This may not be all users on the system..
54 local($rep, @rep, $n, %hasu, $u);
55 $rep = &backquote_logged("$config{'user_repquota_command'} $_[0] 2>&1");
56 if ($?) { return -1; }
58 while(@uinfo = getpwent()) {
61 endpwent() if ($gconfig{'os_type'} ne 'hpux');
62 @rep = split(/\n/, $rep); @rep = @rep[3..$#rep];
63 for($n=0; $n<@rep; $n++) {
64 if ($rep[$n] =~ /(\S+)\s+..\s+(\d+)\s+(\d+)\s+(\d+).*(\d+)\s+(\d+)\s+(\d+)/ || $rep[$n] =~ /(\S+)\s+..(.{7})(.{7})(.{7}).{13}(.{7})(.{7})(.{7})/) {
65 $user{$n,'user'} = $1;
66 $user{$n,'ublocks'} = int($2);
67 $user{$n,'sblocks'} = int($3);
68 $user{$n,'hblocks'} = int($4);
69 $user{$n,'ufiles'} = int($5);
70 $user{$n,'sfiles'} = int($6);
71 $user{$n,'hfiles'} = int($7);
72 $user{$n,'user'} =~ s/^#//g;
73 if ($user{$n,'user'} !~ /^\d+$/ && !$hasu{$user{$n,'user'}}) {
74 # Username was truncated! Try to find him..
75 foreach $u (keys %hasu) {
76 if (substr($u, 0, length($user{$n,'user'})) eq
79 $user{$n,'user'} = $u;
89 # edit_quota_file(data, filesys, sblocks, hblocks, sfiles, hfiles)
93 foreach $line (split(/\n/, $_[0])) {
94 if ($line =~ /^fs (\S+) blocks \(soft = (\d+), hard = (\d+)\) inodes \(soft = (\d+), hard = (\d+)\)$/ && $1 eq $_[1]) {
95 # found line to change
96 $line = "fs $_[1] blocks (soft = $_[2], hard = $_[3]) inodes (soft = $_[4], hard = $_[5])";
103 # quotaon(filesystem, mode)
104 # Activate quotas and create quota file for some filesystem. The mode can
105 # be 1 for user only, 2 for group only or 3 for user and group
108 return if (&is_readonly_mode());
110 $qf = "$_[0]/quotas";
112 &open_tempfile(QUOTAFILE, ">$qf", 0, 1);
113 &close_tempfile(QUOTAFILE);
114 &set_ownership_permissions(undef, undef, 0600, $qf);
116 $out = &backquote_logged("$config{'user_quotaon_command'} $_[0] 2>&1");
117 if ($?) { return $out; }
121 # quotaoff(filesystem, mode)
122 # Turn off quotas for some filesystem
125 return if (&is_readonly_mode());
127 $out = &backquote_logged("$config{'user_quotaoff_command'} $_[0] 2>&1");
128 if ($?) { return $out; }
132 # quotacheck(filesystem, mode)
133 # Runs quotacheck on some filesystem
136 $out = &backquote_logged("$config{'quotacheck_command'} $_[0] 2>&1");
137 if ($?) { return $out; }
141 # copy_user_quota(user, [user]+)
142 # Copy the quotas for some user to many others
145 for($i=1; $i<@_; $i++) {
146 $out = &backquote_logged("$config{'user_copy_command'} ".
147 quotemeta($_[0])." ".quotemeta($_[$i])." 2>&1");
148 if ($?) { return $out; }
153 # user_filesystems(user)
154 # Fills the array %filesys with details of all filesystems some user has
159 open(QUOTA, "$config{'user_quota_command'} ".quotemeta($_[0])." |");
160 $n=0; while(<QUOTA>) {
162 if (/^(Disk|Filesystem)/) { next; }
164 # Bogus wrapped line!
165 $filesys{$n,'filesys'} = $1;
166 <QUOTA> =~ /^.{13}(.{7})(.{7})(.{7}).{12}(.{7})(.{7})(.{7})/;
167 $filesys{$n,'ublocks'} = int($1);
168 $filesys{$n,'sblocks'} = int($2);
169 $filesys{$n,'hblocks'} = int($3);
170 $filesys{$n,'ufiles'} = int($4);
171 $filesys{$n,'sfiles'} = int($5);
172 $filesys{$n,'hfiles'} = int($6);
175 elsif (/^(.{13})(.{7})(.{7})(.{7}).{12}(.{7})(.{7})(.{7})/) {
176 $filesys{$n,'filesys'} = $1;
177 $filesys{$n,'ublocks'} = int($2);
178 $filesys{$n,'sblocks'} = int($3);
179 $filesys{$n,'hblocks'} = int($4);
180 $filesys{$n,'ufiles'} = int($5);
181 $filesys{$n,'sfiles'} = int($6);
182 $filesys{$n,'hfiles'} = int($7);
183 $filesys{$n,'filesys'} =~ s/\s+$//g;
191 # get_user_grace(filesystem)
192 # Returns an array containing btime, bunits, ftime, funits
193 # The units can be 0=sec, 1=min, 2=hour, 3=day, 4=week, 5=month
197 $ENV{'EDITOR'} = $ENV{'VISUAL'} = "cat";
198 open(GRACE, "$config{'user_grace_command'} |");
200 if (/^fs (\S+) blocks time limit = ([0-9\.]+) (\S+), files time limit = ([0-9\.]+) (\S+)/ && $1 eq $_[0]) {
201 if ($2 == 0) { push(@rv, 0, 0); }
202 else { push(@rv, $2, $name_to_unit{$3}); }
203 if ($4 == 0) { push(@rv, 0, 0); }
204 else { push(@rv, $4, $name_to_unit{$5}); }
212 # Returns 0 if grace time can be 0, 1 if zero grace means default
218 # edit_grace_file(data, filesystem, btime, bunits, ftime, funits)
222 foreach $line (split(/\n/, $_[0])) {
223 if ($line =~ /^fs (\S+) blocks time limit = ([0-9\.]+) (\S+), files time limit = ([0-9\.]+) (\S+)/ && $1 eq $_[1]) {
225 $line = "fs $_[1] blocks time limit = $_[2] $unit_to_name{$_[3]}, files time limit = $_[4] $unit_to_name{$_[5]}";
233 # Returns an array of possible units for grace periods
236 return ($text{'grace_seconds'}, $text{'grace_minutes'}, $text{'grace_hours'},
237 $text{'grace_days'}, $text{'grace_weeks'}, $text{'grace_months'});
240 %name_to_unit = ( "sec", 0, "secs", 0,
242 "hour", 2, "hours", 2,
244 "week", 4, "weeks", 4,
245 "month", 5, "months", 5
247 foreach $k (keys %name_to_unit) {
248 $unit_to_name{$name_to_unit{$k}} = $k;