Skip to content

Commit

Permalink
create the users in the 1st stage directly
Browse files Browse the repository at this point in the history
do not save the data for the 2nd stage

- 3.1.1
  • Loading branch information
lslezak committed Oct 30, 2013
1 parent 61ac6c1 commit e6cab3a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 95 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0
3.1.1
7 changes: 7 additions & 0 deletions package/yast2-users.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Oct 30 14:09:52 UTC 2013 - lslezak@suse.cz

- do not save the data for the 2nd stage, create the users
in the 1st stage directly
- 3.1.1

-------------------------------------------------------------------
Thu Sep 19 17:45:35 UTC 2013 - lslezak@suse.cz

Expand Down
49 changes: 45 additions & 4 deletions src/clients/users_finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ class UsersFinishClient < Client
def main
textdomain "users"

Yast.import "Users"
Yast.import "UsersSimple"

@ret = nil
# GetInt()
Yast.include self, "users/routines.rb"

@func = ""
@param = {}

Expand All @@ -59,15 +62,53 @@ def main
"when" => [:installation, :live_installation, :autoinst]
}
elsif @func == "Write"
# disable UI (progress)
Users.SetGUI(false)

# write the root password
UsersSimple.Write

# import the users (TODO FIXME: taken from inst_user.rb, share the code somehow??)
@users = UsersSimple.GetUsers

if !@users.empty?
Users.Read
Users.ResetCurrentUser
Builtins.y2milestone("There are %1 users to import", @users.size)

@users.each do |user|
Ops.set(user, "encrypted", true)
# check if default group exists
if Builtins.haskey(user, "gidNumber")
g = Users.GetGroup(GetInt(Ops.get(user, "gidNumber"), -1), "")
if g == {}
g = Users.GetGroupByName(
Ops.get_string(user, "groupname", ""),
""
)
if g != {}
Ops.set(user, "gidNumber", Ops.get_integer(g, "gidNumber", -1))
else
user = Builtins.remove(user, "gidNumber")
end
end
end

error = Users.AddUser(user)
Builtins.y2error("error while adding user: %1", error) if error != ""
error = Users.CheckUser({})
Builtins.y2error("error while adding user: %1", error) if error != ""
Users.CommitUser
end

Users.Write
end
else
Builtins.y2error("unknown function: %1", @func)
@ret = nil
end

Builtins.y2debug("ret=%1", @ret)
Builtins.y2milestone("users_finish finished")
deep_copy(@ret)
nil
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions src/modules/Users.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4803,8 +4803,6 @@ sub Write {
$users_modified = 0;
$groups_modified = 0;

sleep (1);

return $ret;
}

Expand Down
93 changes: 5 additions & 88 deletions src/modules/UsersSimple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ my $import_available;
# if check for LDAP/Kerberos via DNS was done
my $network_methods_checked = 0;

# prevent re-reading data map with 1st stage settingss
my $first_stage_data_not_read = 1;

# note if users configuration should be run or skipped in 2nd stage (bnc#450231)
my $skip_user_creation = 0;

Expand Down Expand Up @@ -901,107 +898,27 @@ sub GetSystemUserNames {
##---------------------------------------------------------------------------
## Read/Write functions

# Writes the settings configured in 1st stage
# Writes the root password configured in the 1st stage
BEGIN { $TYPEINFO{Write} = ["function", "boolean"];}
sub Write {

my $self = shift;
my $user_defined = 0;
foreach my $user (@users) {
if (defined $user->{"userPassword"}) {
if (!defined $user->{"__imported"}) {
$user->{"userPassword"} =
$self->CryptPassword($user->{"userPassword"});
}
$user->{"encrypted"} = YaST::YCP::Integer (1);
}
$user_defined = 1;
}
my %data = (
"after_auth" => $after_auth,
"run_krb_config" => YaST::YCP::Integer ($run_krb_config),
"users" => \@users,
"encryption_method" => $encryption_method,
"root_alias" => $root_alias,
"autologin_user" => $autologin_user
);
if ($root_password) {
# indication to inst_root
$data{"root_password_written"} = YaST::YCP::Integer (1);
}
my $file = Directory->vardir()."/users_first_stage.ycp";
my $ret = SCR->Write (".target.ycp", $file, \%data);

y2milestone ("1st stage user information written: ", $ret);

# make the file root only readable
SCR->Execute (".target.bash", "chmod 600 $file") if ($ret);

my $redraw = 0;
if ($root_password) {
# write root password now
$self->WriteRootPassword ();
}
else {
y2milestone ("enabling step 'root' for second stage");
ProductControl->EnableModule ("root");
}
# enable inst_user to either run auth client or write first user
if ($after_auth ne "users" || $user_defined) {
# do not let both steps to run (bnc#672139)
if ($user_defined) {
y2milestone ("enabling 'user_non_interactive', disabling 'user' for second stage");
ProductControl->EnableModule ("user_non_interactive");
ProductControl->DisableModule ("user");
}
else {
y2milestone ("enabling 'user', disabling 'user_non_interactive' for second stage");
ProductControl->EnableModule ("user");
ProductControl->DisableModule ("user_non_interactive");
}
}
# no user entered + 2nd stage visible => enable clients (bnc#393722)
elsif (!ProductControl->GetUseAutomaticConfiguration ()) {
y2milestone ("enabling steps 'auth' and 'user' for second stage");
ProductControl->EnableModule ("auth");
ProductControl->EnableModule ("user");
return $self->WriteRootPassword ();
}

return $ret;
return bool (1);
}

# Read the settings configured in 1st stage
# Empty function (kept for backward compatibility)
BEGIN { $TYPEINFO{Read} = ["function", "boolean", "boolean"];}
sub Read {

my $self = shift;
my $force = shift;
my $file = Directory->vardir()."/users_first_stage.ycp";
my $ret = 0;

if (Stage->cont () && FileUtils->Exists ($file) &&
($force || $first_stage_data_not_read))
{
my $data = SCR->Read (".target.ycp", $file);
$first_stage_data_not_read = 0;
if (defined $data && ref ($data) eq "HASH") {

$autologin_user = $data->{"autologin_user"} || "";
$root_alias = $data->{"root_alias"} || "";
$after_auth = $data->{"after_auth"} || $after_auth;
$encryption_method =
$data->{"encryption_method"} || $encryption_method;
$run_krb_config = bool ($data->{"run_krb_config"});
if (ref ($data->{"users"}) eq "ARRAY") {
@users = @{$data->{"users"}};
}
$root_password_written = bool ($data->{"root_password_written"});
$users_written = bool ($data->{"users_written"});
$ret = 1;
}
# SCR->Execute (".target.remove", $file);
}
return bool ($ret);
return bool (1);
}

# Remove the private data from users_first_stage.ycp after they were
Expand Down

0 comments on commit e6cab3a

Please sign in to comment.