ACC SHELL

Path : /usr/share/YaST2/clients/
File Upload :
Current File : //usr/share/YaST2/clients/inst_root_first.ycp

/**
 * File:	clients/inst_root.ycp
 * Package:	Configuration of users and groups
 * Summary:
 * Dialog for setting root's password during 1st stage of the installation
 * Authors:     Jiri Suchomel <jsuchome@suse.cz>
 *
 * $Id: inst_root_first.ycp 61365 2010-03-18 08:19:52Z jsuchome $
 */
{
    textdomain "users";

    import "GetInstArgs";
    import "Mode";
    import "Popup";
    import "ProductFeatures";
    import "Report";
    import "UsersSimple";
    import "Wizard";

    if (UsersSimple::RootPasswordDialogSkipped ())
    {
	y2milestone ("root password was set with first user, skipping");
	return `auto;
    }

    boolean check_CA_constraints	=
	(ProductFeatures::GetBooleanFeature ("globals","root_password_ca_check") == true);

    // minimal pw length for CA-management (F#300438)
    integer pw_min_CA			= 4;

    // Title for root-password dialogue
    string title = _("Password for the System Administrator \"root\"");

    string password	= UsersSimple::GetRootPassword ();
    if (password == nil)
	password	= "";

    term contents = `VBox (
        `VStretch (),
        `HSquash (`VBox (
            // advise user to remember his new password
            `Label(_("Do not forget what you enter here.")),
            `VSpacing(0.8),
            `Password (`id(`pw1), `opt (`hstretch),
		// Label: get password for user root
		_("&Password for root User"), password),
            `VSpacing(0.8),
            `Password (`id(`pw2), `opt (`hstretch),
		// Label: get same password again for verification
		_("Con&firm Password"), password)
        )),
        `VStretch ()
    );

    // help text ( explain what the user "root" is and does ) 1/5
    string helptext = _("<p>
Unlike normal users of the system, who write texts, create
graphics, or browse the Internet, the user \"root\" exists on
every system and is called into action whenever
administrative tasks need to be performed. Only log in as root
when you need to be the system administrator.
</p>
");

    // help text, continued 2/5
    helptext = helptext + _("<p>
Because the root user is equipped with extensive permissions, the password
for \"root\" should be chosen carefully. A combination of letters and numbers
is recommended. To ensure that the password was entered correctly,
reenter it in a second field.
</p>
");

    // help text, continued 3/5
    helptext = helptext + _("<p>
All the rules for user passwords apply to the \"root\" password:
Distinguish between uppercase and lowercase. A password should have at
least 5 characters and, as a rule, not contain any accented letters or umlauts.
</p>
");

    helptext = helptext + UsersSimple::ValidPasswordHelptext ();

    // help text, continued 5/5
    helptext = helptext + _("<p>
Do not forget this \"root\" password.
</p>");

    if (check_CA_constraints)
    {
	helptext = helptext + sformat (
// additional help text about password
_("<p>If you intend to use this password for creating certificates,
it has to be at least %1 characters long.</p>"), pw_min_CA);
    }

    if (Mode::normal ()) Wizard::CreateDialog (); // for testing only

    Wizard::SetTitleIcon("yast-users");
    Wizard::SetContents (title, contents, helptext,
        GetInstArgs::enable_back() || Mode::normal (),
	GetInstArgs::enable_next() || Mode::normal ());

    symbol ret = nil;

    repeat
    {
	if (ret != `abort)
	{
	    UI::SetFocus ( `id(`pw1) );
	}
	ret = (symbol) Wizard::UserInput();

	if (ret == `abort || ret == `cancel)
	{
	    if ( Popup::ConfirmAbort (`incomplete) )
		return `abort;
	    else
	    {
		ret = `notnext;
		continue;
	    }
	}
	if (ret == `accept) // from proposal
	    ret	= `next;

	if (ret == `next)
	{
	    string pw1 = (string) UI::QueryWidget(`id(`pw1), `Value);
	    string pw2 = (string) UI::QueryWidget(`id(`pw2), `Value);

	    if (pw1 != pw2)
	    {
		// report misspellings of the password
		Popup::Message (_("The passwords do not match.
Try again."));
		ret = `notnext;
		continue;
	    }
	    if (pw1 == "")
	    {
		// yes-no popup headline
		if (Popup::YesNoHeadline(_("No Password Entered"),
		    // yes-no popup contents
		    _("If you leave the password empty,
you will be asked for it later during the configuration sequence.

Leave it empty for now?")))
		{
		    y2milestone ("root password setting skipped, will occur later");
		    UsersSimple::SetRootPassword (pw1);
		    break;
		}
		else
		{
		    ret = `notnext;
		    continue;
		}
	    }
	    string error = UsersSimple::CheckPassword (pw1, "local");
	    if (error != "")
	    {
		Report::Error (error);
		ret = `notnext;
		UI::SetFocus (`id (`pw1));
		continue;
	    }
	    // map returned from CheckPasswordUI functions
	    map error_map			= $[];
	    // map with id's of confirmed questions
	    map<string,any> ui_map	= $[];
	    boolean failed			= false;

	    if (!UsersSimple::LoadCracklib ())
	    {
		y2error ("loading cracklib failed, not used for pw check");
		UsersSimple::UseCrackLib (false);
	    }

	    list<string> errors	= UsersSimple::CheckPasswordUI ($[
		    "uid"		: "root",
		    "userPassword"	: pw1,
		    "type"		: "system",
	    ]);

	    if (check_CA_constraints && (size (pw1) < pw_min_CA))
	    {
		errors	= add (errors, sformat (
// yes/no popup question, %1 is a number
_("If you intend to create certificates,
the password should have at least %1 characters."), pw_min_CA));
	    }

	    if (errors != [])
	    {
		string message	= mergestring (errors, "\n\n") +
		    // last part of message popup
		    "\n\n" + _("Really use this password?");
		if (!Popup::YesNo (message))
		{
		    ret = `notnext;
		    continue;
		}
	    }

	    UsersSimple::SetRootPassword (pw1);
	    UsersSimple::UnLoadCracklib ();
	}
    } until (ret == `next || ret == `back || ret == `abort);

    if (Mode::normal ()) Wizard::CloseDialog ();
    return ret;
}

ACC SHELL 2018