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,19 +116,29 @@ 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();
while (sizeof($return) < sizeof($commands)) { $time = time() + (sizeof($commands) * 30);
usleep(100); while (sizeof($return) < sizeof($commands)) {
$read = split("\n", trim(fread($shell, 100000))); if ($time < time()) {
if ((sizeof($read) == 1) && (!isset($read[0]) || ($read[0] == ""))) continue; $return = array("ERROR," . _("Timeout while executing lamdaemon commands!") . ",");
for ($i = 0; $i < sizeof($read); $i++) { return $return;
$return[] = $read[$i]; }
usleep(100);
$read = split("\n", trim(fread($shell, 100000)));
if ((sizeof($read) == 1) && (!isset($read[0]) || ($read[0] == ""))) continue;
for ($i = 0; $i < sizeof($read); $i++) {
$return[] = $read[$i];
}
} }
return $return;
}
else {
$return = array("ERROR," . _('Unable to connect to remote server!') . "," . $_SESSION['config']->scriptServer);
return $return;
} }
return $return;
} }
return array(); return array();
} }

View File

@ -104,7 +104,7 @@ if ($< == 0 ) { # we are root
switch: { 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]); }
$vals[1] eq 'home' && do { $vals[1] eq 'home' && do {
switch2: { switch2: {
$vals[2] eq 'add' && do { $vals[2] eq 'add' && do {
@ -113,44 +113,46 @@ if ($< == 0 ) { # we are root
$path =~ s,/(?:[^/]*)$,,; $path =~ s,/(?:[^/]*)$,,;
($<, $>) = ($>, $<); # Get root privileges ($<, $>) = ($>, $<); # Get root privileges
if (! -e $path) { if (! -e $path) {
system 'mkdir', '-m', '0755', '-p', $path; # Create paths to homedir system 'mkdir', '-m', '0755', '-p', $path; # Create paths to homedir
} }
if (! -e $user[7]) { if (! -e $user[7]) {
system 'mkdir', '-m', '0755', $user[7]; # Create homedir itself system 'mkdir', '-m', '0755', $user[7]; # Create homedir itself
system ("(cd /etc/skel && tar cf - .) | (cd $user[7] && tar xmf -)"); # Copy /etc/sekl into homedir system ("(cd /etc/skel && tar cf - .) | (cd $user[7] && tar xmf -)"); # Copy /etc/sekl into homedir
system 'chown', '-hR', "$user[2]:$user[3]" , $user[7]; # Change owner to new user system 'chown', '-hR', "$user[2]:$user[3]" , $user[7]; # Change owner to new user
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;
}; };
$vals[2] eq 'rem' && do { $vals[2] eq 'rem' && do {
($<, $>) = ($>, $<); # Get root previliges ($<, $>) = ($>, $<); # Get root previliges
if (-d $user[7] && $user[7] ne '/') { if (-d $user[7] && $user[7] ne '/') {
if ((stat($user[7]))[4] eq $user[2]) { if ((stat($user[7]))[4] eq $user[2]) {
system 'rm', '-R', $user[7]; # Delete Homedirectory system 'rm', '-R', $user[7]; # Delete Homedirectory
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 {
$return = "ERROR,Lamdaemon,Homedirectory not owned by $user[2].:$return";
}
} }
else {
$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
$return = "ERROR,Lamdaemon,Unknown command $vals[2].";
} }
# Show error if undfined command is used
$return = "ERROR,Lamdaemon,Unknown command $vals[2].:$return";
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";
} }