fixed homedir management and error handling

This commit is contained in:
Roland Gruber 2006-09-09 11:45:22 +00:00
parent d4cdd87d0a
commit 10e3d9219b
2 changed files with 43 additions and 31 deletions

View File

@ -116,11 +116,16 @@ function lamdaemonSSH($commands) {
$entry = ldap_get_entries($_SESSION['ldap']->server(), $sr); $entry = ldap_get_entries($_SESSION['ldap']->server(), $sr);
$userName = $entry[0]['uid'][0]; $userName = $entry[0]['uid'][0];
if (!$userName) return array(); if (!$userName) return array();
ssh2_auth_password($handle, $userName, $credentials[1]); if (@ssh2_auth_password($handle, $userName, $credentials[1])) {
$shell = ssh2_exec($handle, "sudo " . $_SESSION['config']->scriptPath); $shell = ssh2_exec($handle, "sudo " . $_SESSION['config']->scriptPath);
fwrite($shell, $commands); fwrite($shell, $commands);
$return = array(); $return = array();
$time = time() + (sizeof($commands) * 30);
while (sizeof($return) < sizeof($commands)) { while (sizeof($return) < sizeof($commands)) {
if ($time < time()) {
$return = array("ERROR," . _("Timeout while executing lamdaemon commands!") . ",");
return $return;
}
usleep(100); usleep(100);
$read = split("\n", trim(fread($shell, 100000))); $read = split("\n", trim(fread($shell, 100000)));
if ((sizeof($read) == 1) && (!isset($read[0]) || ($read[0] == ""))) continue; if ((sizeof($read) == 1) && (!isset($read[0]) || ($read[0] == ""))) continue;
@ -130,6 +135,11 @@ function lamdaemonSSH($commands) {
} }
return $return; return $return;
} }
else {
$return = array("ERROR," . _('Unable to connect to remote server!') . "," . $_SESSION['config']->scriptServer);
return $return;
}
}
return array(); return array();
} }

View File

@ -122,9 +122,10 @@ if ($< == 0 ) { # we are root
if (-e '/usr/sbin/useradd.local') { if (-e '/usr/sbin/useradd.local') {
system '/usr/sbin/useradd.local', $user[0]; # run useradd-script system '/usr/sbin/useradd.local', $user[0]; # run useradd-script
} }
$return = "Ok";
} }
else { else {
$return = "ERROR,Lamdaemon,Homedirectory already exists.:$return"; $return = "ERROR,Lamdaemon,Home directory already exists.";
} }
($<, $>) = ($>, $<); # Give up root previleges ($<, $>) = ($>, $<); # Give up root previleges
last switch2; last switch2;
@ -137,20 +138,21 @@ if ($< == 0 ) { # we are root
if (-e '/usr/sbin/userdel.local') { if (-e '/usr/sbin/userdel.local') {
system '/usr/sbin/userdel.local', $user[0]; system '/usr/sbin/userdel.local', $user[0];
} }
$return = "Ok";
} }
else { else {
$return = "ERROR,Lamdaemon,Homedirectory not owned by $user[2].:$return"; $return = "ERROR,Lamdaemon,Home directory not owned by $user[2].";
} }
} }
else { else {
$return = "ERROR,Lamdaemon,Homedirectory doesn't exists.:$return"; $return = "ERROR,Lamdaemon,Home directory does not exist.";
} }
($<, $>) = ($>, $<); # Give up root previleges ($<, $>) = ($>, $<); # Give up root previleges
last switch2; last switch2;
}; };
}
# Show error if undfined command is used # Show error if undfined command is used
$return = "ERROR,Lamdaemon,Unknown command $vals[2].:$return"; $return = "ERROR,Lamdaemon,Unknown command $vals[2].";
}
last switch; last switch;
}; };
$vals[1] eq 'quota' && do { $vals[1] eq 'quota' && do {
@ -223,11 +225,11 @@ if ($< == 0 ) { # we are root
($<, $>) = ($>, $<); # Give up root previleges ($<, $>) = ($>, $<); # Give up root previleges
last switch2; last switch2;
}; };
$return = "ERROR,Lamdaemon,Unknown command $vals[2].:$return"; $return = "ERROR,Lamdaemon,Unknown command $vals[2].";
} }
}; };
last switch; last switch;
$return = "ERROR,Lamdaemon,Unknown command $vals[1].:$return"; $return = "ERROR,Lamdaemon,Unknown command $vals[1].";
}; };
print "$return\n"; print "$return\n";
} }