refactoring

This commit is contained in:
Roland Gruber 2009-06-14 14:18:26 +00:00
parent 98fa964b89
commit a665c3649f
1 changed files with 72 additions and 61 deletions

View File

@ -109,68 +109,23 @@ while (1) {
chop($input); chop($input);
$return = ""; $return = "";
@vals = split (' ', $input); @vals = split (' ', $input);
switch: {
# test if lamdaemon can be run
if (($vals[1] eq 'test')) {
runTest();
last switch;
}
# Get user information # Get user information
if (($vals[3] eq 'user') || ($vals[1] eq 'home')) { @user = getpwnam($vals[0]); } if (($vals[3] eq 'user') || ($vals[1] eq 'home')) { @user = getpwnam($vals[0]); }
else { @user = getgrnam($vals[0]); } else { @user = getgrnam($vals[0]); }
if ($vals[1] eq 'home') { # run tests
if ($vals[2] eq 'add') { if (($vals[1] eq 'test')) {
createHomedir(); runTest();
} }
elsif ($vals[2] eq 'rem') { elsif ($vals[1] eq 'home') {
removeHomedir(); manageHomedirs();
}
elsif ($vals[1] eq 'quota') {
manageQuotas();
} }
else { else {
# Show error if undefined command is used
$return = "ERROR,Lamdaemon ($hostname),Unknown home command $vals[2].";
logMessage(LOG_ERR, "Unknown command $vals[2]");
}
last switch;
};
if ($vals[1] eq 'quota') {
require Quota; # Needed to get and set quotas
get_fs(); # Load list of devices with enabled quotas
# Store quota information in array
@quota_temp1 = split (':', $vals[4]);
$group=0;
$i=0;
while ($quota_temp1[$i]) {
$j=0;
@temp = split (',', $quota_temp1[$i]);
while ($temp[$j]) {
$quota[$i][$j] = $temp[$j];
$j++;
}
$i++;
}
if ($vals[3] eq 'user') { $group=false; }
else {
$group=1;
@quota_usr = @quota_grp;
}
if ($vals[2] eq 'rem') {
remQuotas();
}
elsif ($vals[2] eq 'set') {
setQuotas();
}
elsif ($vals[2] eq 'get') {
getQuotas();
}
else {
$return = "ERROR,Lamdaemon ($hostname),Unknown quota command $vals[2].";
logMessage(LOG_ERR, "Unknown command $vals[2].");
}
};
last switch;
$return = "ERROR,Lamdaemon ($hostname),Unknown command $vals[1]."; $return = "ERROR,Lamdaemon ($hostname),Unknown command $vals[1].";
logMessage(LOG_ERR, "Unknown command $vals[1]."); logMessage(LOG_ERR, "Unknown command $vals[1].");
}; }
print "$return\n"; print "$return\n";
} }
@ -189,6 +144,23 @@ sub runTest {
} }
} }
#
# Handles all homedir related commands
#
sub manageHomedirs {
if ($vals[2] eq 'add') {
createHomedir();
}
elsif ($vals[2] eq 'rem') {
removeHomedir();
}
else {
# Show error if undefined command is used
$return = "ERROR,Lamdaemon ($hostname),Unknown home command $vals[2].";
logMessage(LOG_ERR, "Unknown command $vals[2]");
}
}
# #
# Creates the homedirectory of the user # Creates the homedirectory of the user
# #
@ -245,6 +217,45 @@ sub removeHomedir {
($<, $>) = ($>, $<); # Give up root previleges ($<, $>) = ($>, $<); # Give up root previleges
} }
#
# Handles all quota related commands
#
sub manageQuotas {
require Quota; # Needed to get and set quotas
get_fs(); # Load list of devices with enabled quotas
# Store quota information in array
@quota_temp1 = split (':', $vals[4]);
$group=0;
$i=0;
while ($quota_temp1[$i]) {
$j=0;
@temp = split (',', $quota_temp1[$i]);
while ($temp[$j]) {
$quota[$i][$j] = $temp[$j];
$j++;
}
$i++;
}
if ($vals[3] eq 'user') { $group=false; }
else {
$group=1;
@quota_usr = @quota_grp;
}
if ($vals[2] eq 'rem') {
remQuotas();
}
elsif ($vals[2] eq 'set') {
setQuotas();
}
elsif ($vals[2] eq 'get') {
getQuotas();
}
else {
$return = "ERROR,Lamdaemon ($hostname),Unknown quota command $vals[2].";
logMessage(LOG_ERR, "Unknown command $vals[2].");
}
}
# #
# Removes the quotas of a user or group # Removes the quotas of a user or group
# #