Skip to content

Commit

Permalink
Delete remaining dead code for encrypted homes (bsc#1127138, fate#323…
Browse files Browse the repository at this point in the history
…541)

The trigger was discovering a call to 'cryptconfig' that no longer
exists.
  • Loading branch information
mvidner committed Feb 27, 2019
1 parent e9421f9 commit 2585d2d
Show file tree
Hide file tree
Showing 10 changed files with 0 additions and 471 deletions.
4 changes: 0 additions & 4 deletions src/include/users/widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1143,10 +1143,6 @@ def DeleteUserPopup
no_home = false
# check if dir exists with this owner
stat = Convert.to_map(SCR.Read(path(".target.stat"), home))
crypted_img = UsersRoutines.CryptedImagePath(username)
if crypted_img != "" # check crypted dir image
stat = Convert.to_map(SCR.Read(path(".target.stat"), crypted_img))
end
if type == "ldap" && !Ldap.file_server ||
Ops.get_integer(stat, "uid", -1) != uid
no_home = true
Expand Down
18 changes: 0 additions & 18 deletions src/modules/Users.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4093,17 +4093,6 @@ sub PreDeleteUsers {
return $ret;
}

# Remove crypted direcotries - because of 'cryptconfig pm-disable' call, this
# must be done when user is still known to PAM...
sub DeleteCryptedHomes {

my $ret = 1;
foreach my $home (keys %removed_homes) {
$ret = $ret && UsersRoutines->DeleteCryptedHome ($home, $removed_homes{$home});
};
return $ret;
}

##------------------------------------
# 1. remove home directories,
# 2. execute USERDEL_POSTCMD scripts for deleted local/system users
Expand Down Expand Up @@ -4448,13 +4437,6 @@ sub Write {
$plugin_error = GetPluginError ($args, $result);
}
}
# remove the crypted directories now, so cryptconfig still knows them
if (!DeleteCryptedHomes ()) {
# error popup
$ret = __("An error occurred while removing users.");
Report->Error ($ret);
return $ret;
}
# -------------------------------------- write /etc/passwd
if ($plugin_error eq "" && !WritePasswd ()) {
$ret = Message->ErrorWritingFile ("$base_directory/passwd");
Expand Down
1 change: 0 additions & 1 deletion src/modules/UsersLDAP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,6 @@ sub WriteUsers {
else {
if ($server && $delete_home) {
UsersRoutines->DeleteHome ($home);
UsersRoutines->DeleteCryptedHome ($home, $org_username);
}
y2usernote ("LDAP user '$username' was deleted.");
}
Expand Down
186 changes: 0 additions & 186 deletions src/modules/UsersRoutines.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,12 @@ our %TYPEINFO;
##------------------------------------
##------------------- global imports

YaST::YCP::Import ("FileUtils");
YaST::YCP::Import ("Pam");
YaST::YCP::Import ("Report");
YaST::YCP::Import ("SCR");
YaST::YCP::Import ("String");

##------------------------------------
##------------------- global variables

# path to cryptconfig
my $cryptconfig = "/usr/sbin/cryptconfig";

# path to pam_mount configuration file
my $pam_mount_path = "/etc/security/pam_mount.conf.xml";

# 'volume' information from pam_mount (info about crypted homes)
my $pam_mount = undef;

# owners of img files
my $img2user = undef;

# owners of key files
my $key2user = undef;

# could we use pam_mount? currntly not if fingerprint dev is in use (bnc#390810)
my $crypted_homes_enabled = undef;

# path to btrfs
my $btrfs = "/usr/sbin/btrfs";

Expand Down Expand Up @@ -313,170 +292,5 @@ sub DeleteHome {
return 1;
}

##------------------------------------
# Delete the crypted directory
# @param home path to home directory
# @param user name (to know the key and img name)
# @return success
BEGIN { $TYPEINFO{DeleteCryptedHome} = ["function", "boolean", "string", "string"];}
sub DeleteCryptedHome {

my $self = shift;
my $home = shift;
my $username = shift;
my $ret = 1;

return 0 if ((not defined $home) || (not defined $username));

my $img_path = $self->CryptedImagePath ($username);
my $key_path = $self->CryptedKeyPath ($username);

if (%{SCR->Read (".target.stat", $key_path)}) {
my $cmd = "/usr/bin/rm -rf '".String->Quote($key_path)."'";
my $out = SCR->Execute (".target.bash_output", $cmd);
if (($out->{"exit"} || 0) ne 0) {
y2error ("error while removing $key_path file: ", $out->{"stderr"} || "");
$ret = 0;
}
y2usernote ("Encrypted directory key removed: '$cmd'");
}
if (%{SCR->Read (".target.stat", $img_path)}) {
my $cmd = "/usr/bin/rm -rf '".String->Quote($img_path)."'";
my $out = SCR->Execute (".target.bash_output", $cmd);
if (($out->{"exit"} || 0) ne 0) {
y2error ("error while removing $img_path file: ", $out->{"stderr"} || "");
$ret = 0;
}
y2usernote ("Encrypted directory image removed: '$cmd'");
$cmd = "$cryptconfig pm-disable '".String->Quote($username)."'";
$out = SCR->Execute (".target.bash_output", $cmd);
if ($out->{"exit"} ne 0 && $out->{"stderr"}) {
y2error ("error calling $cmd: ", $out->{"stderr"});
Report->Error ($out->{"stderr"});
$ret = 0;
}
y2usernote ("Disabled pam_mount for $username: '$cmd'");
}
return $ret;
}

##------------------------------------
# Return size of given file in MB (rounded down)
# @param path to file
# @return size
BEGIN { $TYPEINFO{FileSizeInMB} = ["function", "string", "string"];}
sub FileSizeInMB {
my $self = shift;
my $file = shift;

return "0" if not defined $file;

my $stat = SCR->Read (".target.stat", $file);

my $size = $stat->{"size"};
return "0" if not $size;

my $mb = 1024 * 1024;
return ($size < $mb) ? "1" : sprintf ("%i", $size / $mb);
}

# Read the 'volume' data from pam_mount config file and fill in the global map
BEGIN { $TYPEINFO{ReadCryptedHomesInfo} = ["function", "boolean"];}
sub ReadCryptedHomesInfo {

return 1 if (defined $pam_mount);
y2milestone ("pam_mount not read yet, doing it now");
if (FileUtils->Exists ($pam_mount_path)) {
my $pam_mount_cont = SCR->Read (".anyxml", $pam_mount_path);
if (defined $pam_mount_cont &&
defined $pam_mount_cont->{"pam_mount"}[0]{"volume"})
{
my $volumes = $pam_mount_cont->{"pam_mount"}[0]{"volume"};
if (ref ($volumes) eq "ARRAY") {
foreach my $usermap (@{$volumes}) {
my $username = $usermap->{"user"};
next if !defined $username;
$pam_mount->{$username} = $usermap;
my $img = $usermap->{"path"} || "";
$img2user->{$img} = $username if $img;
my $key = $usermap->{"fskeypath"} || "";
$key2user->{$key} = $username if $key;
}
}
}
return 1 if defined $pam_mount;
}
else {
y2milestone ("file $pam_mount_path not found");
$pam_mount = {};
}
return 0;
}

##------------------------------------
# Return the owner of given crypted directory image
# @param image name
# @return string
BEGIN { $TYPEINFO{CryptedImageOwner} = ["function", "string", "string"];}
sub CryptedImageOwner {

my $self = shift;
my $img_file= shift;

if ($self->ReadCryptedHomesInfo ()) {
return $img2user->{$img_file} || "";
}
return "";
}

##------------------------------------
# Return the owner of given crypted directory key
# @param key name
# @return string
BEGIN { $TYPEINFO{CryptedKeyOwner} = ["function", "string", "string"];}
sub CryptedKeyOwner {

my $self = shift;
my $key_file= shift;

if ($self->ReadCryptedHomesInfo ()) {
return $key2user->{$key_file} || "";
}
return "";
}

##------------------------------------
# Return the path to user's crypted directory image; returns empty string if there is none defined
# @param user name
# @return string
BEGIN { $TYPEINFO{CryptedImagePath} = ["function", "string", "string"];}
sub CryptedImagePath {

my $self = shift;
my $user = shift;

if ($self->ReadCryptedHomesInfo ()) {
return $pam_mount->{$user}{"path"} || "";
}
return "";
}

##------------------------------------
# Return the path to user's crypted directory key; returns empty string if there is none defined
# @param user name
# @return string
BEGIN { $TYPEINFO{CryptedKeyPath} = ["function", "string", "string"];}
sub CryptedKeyPath {

my $self = shift;
my $user = shift;

if ($self->ReadCryptedHomesInfo ()) {
return $pam_mount->{$user}{"fskeypath"} || "";
}
return "";
}


1
# EOF
Empty file.
17 changes: 0 additions & 17 deletions testsuite/tests/CryptedDirTests.out

This file was deleted.

89 changes: 0 additions & 89 deletions testsuite/tests/CryptedDirTests.rb

This file was deleted.

Empty file.

0 comments on commit 2585d2d

Please sign in to comment.