Handle hostnames with upper-case letters
[webmin.git] / quota / useradmin_update.pl
1
2 do 'quota-lib.pl';
3
4 # useradmin_create_user(&details)
5 # Sets quotas on chosen filesystems
6 sub useradmin_create_user
7 {
8 local ($anysync) = grep { /^sync_/ } (keys %config);
9 return if (!$anysync);
10 local ($k, $fs, $i, %fslist);
11 foreach $fs (&list_filesystems()) {
12         if ($fs->[4] && $fs->[5]) {
13                 $fslist{$fs->[0]}++;
14                 }
15         }
16 foreach $k (keys %config) {
17         if ($k =~ /^sync_(\S+)$/ && $fslist{$1}) {
18                 # found a filesystem to set quotas on
19                 $fs = $1;
20                 @quot = split(/\s+/, $config{$k});
21                 &edit_user_quota($_[0]->{'user'}, $fs, @quot);
22                 }
23         }
24 }
25
26 # useradmin_delete_user(&details)
27 # Zero the quotas of a deleted user
28 sub useradmin_delete_user
29 {
30 foreach $fs (&list_filesystems()) {
31         if ($fs->[4] && $fs->[5]) {
32                 $fslist{$fs->[0]}++;
33                 }
34         }
35 $n = &user_filesystems($_[0]->{'user'});
36 for($i=0; $i<$n; $i++) {
37         $f = $filesys{$i,'filesys'};
38         if ($fslist{$f}) {
39                 # user has quota, and filesystem is local
40                 &edit_user_quota($_[0]->{'user'}, $f, 0, 0, 0, 0);
41                 }
42         }
43 }
44
45 # useradmin_modify_user(&details)
46 # Quotas are stored by UID, so no need to change anything
47 # when a username changes.
48 sub useradmin_modify_user
49 {
50 # XXX should change if UID changes?
51 }
52
53
54 # useradmin_create_group(&details)
55 # Sets quotas on chosen filesystems
56 sub useradmin_create_group
57 {
58 local ($anysync) = grep { /^gsync_/ } (keys %config);
59 return if (!$anysync);
60 return if (!defined(&edit_group_quota) || !defined(&group_filesystems));
61 local ($k, $fs, $i, %fslist);
62 foreach $fs (&list_filesystems()) {
63         if ($fs->[4] && $fs->[5]) {
64                 $fslist{$fs->[0]}++;
65                 }
66         }
67 foreach $k (keys %config) {
68         if ($k =~ /^gsync_(\S+)$/ && $fslist{$1}) {
69                 # found a filesystem to set quotas on
70                 $fs = $1;
71                 @quot = split(/\s+/, $config{$k});
72                 &edit_group_quota($_[0]->{'group'}, $fs, @quot);
73                 }
74         }
75 }
76
77 # useradmin_delete_group(&details)
78 # Zero the quotas of a deleted group
79 sub useradmin_delete_group
80 {
81 return if (!defined(&edit_group_quota) || !defined(&group_filesystems));
82 foreach $fs (&list_filesystems()) {
83         if ($fs->[4] && $fs->[5]) {
84                 $fslist{$fs->[0]}++;
85                 }
86         }
87 $n = &group_filesystems($_[0]->{'group'});
88 for($i=0; $i<$n; $i++) {
89         $f = $filesys{$i,'filesys'};
90         if ($fslist{$f}) {
91                 # group has quota, and filesystem is local
92                 &edit_group_quota($_[0]->{'group'}, $f, 0, 0, 0, 0);
93                 }
94         }
95 }
96
97 # useradmin_modify_group(&details)
98 # Quotas are stored by UID, so no need to change anything
99 # when a group name changes.
100 sub useradmin_modify_group
101 {
102 return if (!defined(&edit_group_quota) || !defined(&group_filesystems));
103 # XXX should change if UID changes?
104 }
105
106
107 1;
108