ACC SHELL
/**
* File: installation/general/inst_auth.ycp
* Package: Users configuration
* Summary: Ask for user authentication method
* Authors: Arvin Schnell <arvin@suse.de>
* Michal Svec <msvec@suse.cz>
*
* $Id: inst_auth.ycp 55812 2009-02-27 13:06:52Z jsuchome $
*/
{
textdomain "users";
import "Directory";
import "FileUtils";
import "GetInstArgs";
import "Label";
import "Ldap";
import "NetworkInterfaces";
import "NetworkService";
import "Package";
import "Popup";
import "Users";
import "UsersCache";
import "UsersSimple";
import "Wizard";
/**
* Helper function
* Ask user which users to import
*/
define list<string> choose_to_import (list<string> all, list<string> selected) {
list items = maplist (string u, all, ``(
`item (`id (u), u, contains (selected, u))
));
boolean all_checked = (size (all) == size (selected)) && size (all) > 0;
integer vsize = size (all) + 3;
if (vsize > 15) vsize = 15;
UI::OpenDialog (`opt(`decorated), `HBox(`VSpacing (vsize), `VBox (
`HSpacing(50),
// selection box label
`MultiSelectionBox (`id(`userlist), _("&Select Users to Read"), items),
// check box label
`Left (`CheckBox (
`id(`all),`opt(`notify),_("Select or Deselect &All"), all_checked
)),
`HBox (
`PushButton (`id(`ok), `opt(`default, `key_F10), Label::OKButton()),
`PushButton (`id(`cancel), `opt(`key_F9), Label::CancelButton())
)
)));
any ret = nil;
while (true)
{
ret = UI::UserInput ();
if (ret == `all)
{
boolean ch = (boolean)UI::QueryWidget (`id(`all),`Value);
if (ch != all_checked)
{
UI::ChangeWidget (`id(`userlist), `Items,
maplist (string u, all, ``(`item (`id (u), u, ch)))
);
all_checked = ch;
}
}
if (ret == `ok || ret == `cancel)
break;
}
if (ret == `ok)
{
selected = (list<string>)UI::QueryWidget(`id(`userlist),`SelectedItems);
}
UI::CloseDialog ();
return ret == `ok ? selected : nil;
}
//----------------------------------------- main body ----------------------
// first check if some settings were configured in first stage
if (!GetInstArgs::going_back()) {
Users::ReadSystemDefaults (false);
UsersSimple::Read (false);
if (UsersSimple::AfterAuth () != "users" || UsersSimple::GetUser () != $[])
{
Users::SetKerberosConfiguration (UsersSimple::KerberosConfiguration ());
Users::SetAfterAuth (UsersSimple::AfterAuth ());
y2milestone ("skipping authentication dialog...");
return `next;
}
}
// check if LDAP/Kerberos are available
UsersSimple::CheckNetworkMethodsAvailability ();
// Check if lan is configured
list<string> net_devices = NetworkInterfaces::ListDevicesExcept("dialup");
y2debug("net_devices: %1", net_devices);
boolean found = (size (net_devices) > 0) || NetworkService::IsManaged ();
if (!found && size (Ldap::initial_defaults) == 0) {
y2milestone ("network not available: no network based authentization");
UsersSimple::SetAfterAuth ("users");
return `auto;
}
boolean import_available = false;
string import_dir = Directory::vardir + "/imported/userdata/etc";
string base_dir = Users::GetBaseDirectory ();
list<string> user_names = [];
list<string> to_import = [];
if (FileUtils::Exists (import_dir))
{
if (FileUtils::Exists (import_dir + "/passwd") &&
FileUtils::Exists (import_dir + "/shadow"))
{
import_available = true;
}
}
if (import_available)
{
Users::SetBaseDirectory (import_dir);
string err = Users::ReadLocal ();
if (err != "")
{
y2warning ("Error during reading: %1", err);
}
else
{
UsersCache::Read ();
user_names = UsersCache::GetUsernames ("local");
}
if (size (user_names) < 1)
{
y2milestone ("No users to import");
import_available = false;
foreach (string file, [ "/passwd", "/shadow", "/group" ], {
SCR::Execute (.target.remove, import_dir + file);
});
}
Users::SetBaseDirectory (base_dir);
}
// caption for dialog "User Authentication Method"
string caption = _("User Authentication Method");
// help text for dialog "User Authentication Method" 1/3
string help = _("<p>
<b>Authentication</b><br>
Select the authentication method to use for users on your system.
</p>") +
// helptext 2/3
_("<p>Select <b>Local</b> to authenticate users only by using the local files <i>/etc/passwd</i> and <i>/etc/shadow</i>.</p>");
if (import_available)
// optional helptext 2.5/3 (local users continued)
help = help + _("If you have a previous installation or alternative system, it is possible to create users based on this source. To do so, select <b>Read User Data from a Previous Installation</b>. This option uses an existing or creates a new home directory for each user in the location specified for this installation.");
map button_labels = $[
// radiobutton to select ldap user auth.
"ldap": _("&LDAP"),
// radiobutton to select nis user auth.
"nis": _("N&IS"),
// radiobutton to select samba user auth.
"samba-old": _("&Samba"),
// radiobutton to select samba user auth.
"samba": _("&Windows Domain"),
// radiobutton to select local user auth.
"users": _("L&ocal (/etc/passwd)"),
// radiobutton to select local user auth.
"edir_ldap": _("eDirectory LDAP"),
];
list<string> available_clients = [ "users", "ldap" ];
if (found)
{
boolean available = false;
foreach (string client, string package, $[ "nis" : "yast2-nis-client",
"samba" : "yast2-samba-client", "edir_ldap" : "yast2-linux-user-mgmt" ], {
if (available == nil)
return;
available = Package::Installed (package) || Package::Available (package);
if (available == true)
available_clients = add (available_clients, client);
});
}
if (contains (available_clients, "nis"))
{
if (contains (available_clients, "samba"))
{
help = help +
// helptext 3/3 -- nis & samba & ldap avialable
_("<p>If you are using a NIS or LDAP server to store user data or if you want
to authenticate users against an NT server, choose the appropriate value. Then
press <b>Next</b> to continue with configuration of your client.</p>");
}
else
{
help = help +
// helptext 3/3 -- nis & ldap avialable
_("<p>If you are using a NIS or LDAP server to store user data, choose the
appropriate value. Then press <b>Next</b> to continue with configuration of your client.</p>");
}
}
else
{
if (contains (available_clients, "samba"))
{
help = help +
// helptext 3/3 -- samba &ldap available
_("<p>If you are using an LDAP server to store user data or if you want to
authenticate users against an NT server, choose the appropriate value. Then
press <b>Next</b> to continue with configuration of your client.</p>");
}
else
{
help = help +
// helptext 3/3 -- only ldap available
_("<p>If you are using an LDAP server to store user data, choose the
appropriate value. Then press <b>Next</b> to continue with configuration of your client.</p>");
}
}
// helptext: additional kerberos support
help = help + _("<p>Check <b>Set Up Kerberos Authentication</b> to configure Kerberos after configuring the user data source.</p>");
term buttons = `VBox (`VSpacing(0.5));
map display_info = UI::GetDisplayInfo ();
boolean text_mode = display_info["TextMode"]:false;
term import_checkbox = `Left (`CheckBox (`id (`import_ch),
// check box label
_("&Read User Data from a Previous Installation")
));
// button label
term import_button = `PushButton (`id(`import), _("&Choose"));
foreach (string client, available_clients, {
if (client == "users" && import_available)
buttons = add (buttons, `VBox (
`Left (`RadioButton (
`id(client), `opt (`notify), button_labels[client]:""
)),
`HBox (
`HSpacing (3),
text_mode ?
`VBox (import_checkbox, `Left (import_button)) :
`HBox (import_checkbox, import_button)
)
));
else
buttons = add (buttons, `Left(
`RadioButton(`id(client), `opt (`notify), button_labels[client]:"")
));
});
buttons = add (buttons, `VSpacing(0.5));
// set LDAP for default, if ldap-server was configured:
if (size (Ldap::initial_defaults) > 0)
UsersSimple::SetAfterAuth ("ldap");
term contents = `VBox (
`VStretch(),
`HBox (
`HStretch(),
`VBox (
// frame title for authentication methods
`Frame (_("Authentication Method"),
`RadioButtonGroup (`id (`method), buttons)
),
`VSpacing (),
// check box label
`Left (`CheckBox (`id(`krb), _("Set Up &Kerberos Authentication"),
UsersSimple::KerberosConfiguration ()))
),
`HStretch()
),
`VStretch()
);
Wizard::SetDesktopIcon("users");
Wizard::SetContents (caption, contents, help,
GetInstArgs::enable_back(), GetInstArgs::enable_next());
string after_client = UsersSimple::AfterAuth ();
// select and enable to correct buttons
foreach (string client, available_clients, ``{
UI::ChangeWidget (`id(client), `Value, after_client == client);
});
UI::ChangeWidget (`id (`krb), `Enabled,
after_client != "users" && after_client != "samba");
any ret = nil;
repeat {
ret = Wizard::UserInput();
if (ret == `abort)
{
if ( Popup::ConfirmAbort (`incomplete) )
break;
}
else if ( ret == `help )
{
Wizard::ShowHelp (help);
}
if (ret == `next && import_available && to_import == [] &&
UI::QueryWidget (`id(`import_ch), `Value) == true)
{
// force selecting when only checkbox is checked
list<string> selected = choose_to_import (user_names, to_import);
if (selected != nil)
to_import = selected;
else
{
ret = `notnext;
continue;
}
}
if (ret == `import)
{
list<string> selected = choose_to_import (user_names, to_import);
if (selected != nil)
to_import = selected;
UI::ChangeWidget (`id (`import_ch), `Value, size (to_import) > 0);
}
if (is (ret, string))
{
if (import_available)
{
UI::ChangeWidget (`id (`import_ch), `Enabled, ret == "users");
UI::ChangeWidget (`id (`import), `Enabled, ret == "users");
}
UI::ChangeWidget (`id(`krb),`Enabled, ret != "users" && ret != "samba");
}
} until ( ret == `next || ret == `back );
string method = (string)UI::QueryWidget (`id(`method), `CurrentButton);
UsersSimple::SetAfterAuth (method);
if (ret == `next && method == "users" && to_import != [])
{
UsersCache::SetUserType ("local");
list users_to_import = maplist (string name, to_import, {
Users::SelectUserByName (name);
map u = Users::GetCurrentUser ();
return u;
});
Users::SetUsersForImport (users_to_import);
}
if (ret == `next)
{
if (method == "users" || method == "samba")
UsersSimple::SetKerberosConfiguration (false);
else
UsersSimple::SetKerberosConfiguration (
(boolean)UI::QueryWidget (`id(`krb), `Value));
}
// remove the data with users information
if (import_available)
{
foreach (string file, [ "/passwd", "/shadow", "/group" ], {
SCR::Execute (.target.remove, import_dir + file);
});
}
return (symbol) ret;
/* EOF */
}
ACC SHELL 2018