home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd2.bin / suse / inst-sys / lib / YaST2 / clients / inst_user.ycp < prev    next >
Encoding:
Text File  |  2000-03-30  |  11.5 KB  |  324 lines

  1. /**
  2.  * Module:         inst_user.ycp
  3.  *
  4.  * Authors:         Klaus Kaempf (kkaempf@suse.de)
  5.  *
  6.  * Purpose:         - Ask the user for:
  7.  *                - first name
  8.  *                - last name
  9.  *                - login name
  10.  *                - password
  11.  *            - Check login name and password for validation
  12.  *            - Set user_settings with these values
  13.  *
  14.  * user_settings:    add:    forename
  15.  *            add:    surname
  16.  *            add:    upassword
  17.  *            add:    loginname
  18.  *
  19.  * scr:                   -
  20.  *
  21.  * $Id: inst_user.ycp,v 1.64 2000/02/25 12:58:09 sh Exp $
  22.  */
  23. {
  24.   //
  25.   // A sample (non-root) user is created
  26.   //
  27.  
  28.   string  forename  = lookup ( user_settings, "forename", "" );
  29.   string  surname   = lookup ( user_settings, "surname", "" );
  30.   string  password  = lookup ( user_settings, "upassword", "" );
  31.   string  loginname = lookup ( user_settings, "loginname", "" );
  32.   boolean test_mode = lookup ( user_settings, "test_mode", false );
  33.   boolean this_is_for_real = ! test_mode;
  34.  
  35.  
  36.   // Information about the user.  This info is used to create an initial
  37.   // user account: first name, surname, login name and password.  Data
  38.   // will be written to /etc/passwd.
  39.   // "Personify" is also the name of the dialog.
  40.   locale title = _("Personalize");
  41.  
  42.   term contents =
  43.       `HSquash(
  44.            `VBox(
  45.              // User account information, forename or first name
  46.              `TextEntry(`id("forename"), _("Your first name please:"), forename),
  47.              // User account information, surname or family name
  48.              `TextEntry(`id("surname"), _("Your last name please:"), surname),
  49.              // entry widget for login-name and pushbutton to generate a login name from forename and surname
  50.              `VSquash(`HBox (`TextEntry(`id("loginname"), _("User login:"), loginname),
  51.                      `Bottom (`PushButton(`id(`propose), _("&Suggestion"))))),
  52.              // User account information, first version of user password, both versions must match
  53.              `Password(`id("pw1"), _("Enter a password:"), ""),
  54.              // User account information, second version of user password, retyped to avoid typos
  55.              `Password(`id("pw2"), _("Re-enter the password for verification:"), "")
  56.              )
  57.            );
  58.  
  59.   // help text (description of what to do, some background information)
  60.   // html-format
  61.   // help part 1 of 5
  62.   string helptext = UI(_("<p>
  63. Linux is a multiuser system; several different users can log in on the system
  64. and work there. In order to avoid confusion of data, each user must identify
  65. himself uniquely if he wants to use Linux.
  66. </p>"));
  67.  
  68.   // help part 2 of 5
  69.   helptext = helptext + UI(_("<p>
  70. If you fill out the fields (<b>First Name</b> and <b>Last Name</b>),
  71. an account is created for an user with this name and a <b>Password</b> is stored.
  72. When entering a password, you must distinguish between upper and lower case; a
  73. password should have at least 5 characters, and as a rule,
  74. not contain any umlauts."));
  75.  
  76.    // help part 3 of 5
  77.    helptext = helptext + UI(_("
  78. Possible characters in addition are
  79. <tt>#*,.;:._-+!$</tt><tt>%&/|?{[()]}</tt> and blanks and digits
  80. <tt>0</tt> to <tt>9</tt>.
  81. Often it's enough to use a length of approx. 8 signs for the password.
  82. To ensure that the password was entered correctly, you are asked to repeat it
  83. exactly in a second field. Make sure you don't forget your password!
  84. </p>"));
  85.  
  86.    // help part 4 of 5
  87.    helptext = helptext + UI(_("
  88. <p>
  89. The so-called username is created from components of the full name
  90. and presented to you in one of the following dialogs.  If unsure, let
  91. YaST2 <tt>suggest</tt> an username.  You're allowed to modify it, but
  92. only use <em>lower</em> case letters (no umlauts!), digits and <tt>._-</tt>
  93. - yes, for usernames there's a closer restriction than for passwords!
  94. </p>"));
  95.  
  96.    // help part 5 of 5
  97.    helptext = helptext + UI(_("
  98.  <p>
  99. If you want to work with Linux, you must first enter the username and
  100. the password; this starting procedure is traditionally known as the
  101. <b>Login</b>.
  102. </p>
  103. <br>"));
  104.  
  105.  
  106.   UI(`SetWizardContents(title, contents, helptext, Args(0), Args(1)));
  107.  
  108.   UI(`SetFocus(`id(`next)));
  109.   UI(`SetFocus(`id("forename")));
  110.   string valid_logname_chars = "0123456789abcdefghijklmnopqrstuvwxyz";
  111.  
  112.   any ret = nil;
  113.   while (true) {
  114.  
  115.       // FIXME: check login against passwd contents
  116.       // Please leave this FIXME in, even when fixed, because this might
  117.       // need adjustments from release to release.
  118.       list predef_accounts = ReadY2 ("accounts.ycp");
  119.  
  120.       // Clear password fields on every round, unless `propose was
  121.       // selected.
  122.       if (ret != `propose)
  123.       {
  124.       UI(`ChangeWidget(`id("pw1"), `Value, ""));
  125.       UI(`ChangeWidget(`id("pw2"), `Value, ""));
  126.       }
  127.       ret = UI(`UserInput());
  128.  
  129.       if (ret == `propose)
  130.       {
  131.  
  132.          string default_login_name = "lxuser";
  133.          integer part_len = 3;
  134.          integer login_len = part_len * 2;
  135.  
  136.          forename = UI(`QueryWidget(`id("forename"), `Value));
  137.          string f_name = filterchars(tolower(forename), valid_logname_chars);
  138.          integer f_len = size( f_name );
  139.  
  140.          surname = UI(`QueryWidget(`id("surname"), `Value));
  141.          string s_name = filterchars(tolower(surname), valid_logname_chars);
  142.          integer s_len = size( s_name );
  143.  
  144.          if ( f_len == 0 && s_len == 0 )    // both are missing
  145.          {
  146.             loginname = default_login_name;    // default login
  147.          }
  148.          else                    // at least one is given
  149.          {
  150.             if ( f_len >= part_len )
  151.             {
  152.                if ( s_len >= part_len )            // forename and surname long enough
  153.            {
  154.                   f_len = part_len;        // take part_len chars from each
  155.                   s_len = part_len;
  156.            }
  157.                else                // surname shorter than 3 chars
  158.            {
  159.                   f_len = login_len - s_len;    // fill up with forename
  160.            }
  161.             }
  162.             else                // forename shorter than 3 chars
  163.             {
  164.                s_len = login_len - f_len;    // fill up with surname
  165.             }
  166.  
  167.             // build login name
  168.             loginname = substring( f_name, 0, f_len ) + substring( s_name, 0, s_len );
  169.         if (size (loginname) < 2) loginname = default_login_name;
  170.         else {
  171.           string firstchar = substring(loginname, 0, 1);
  172.           if (firstchar < "a" || firstchar > "z")
  173.         loginname = default_login_name;
  174.         }
  175.      }
  176.  
  177.          // check login against passwd contents (default login in case of conflict)
  178.  
  179.          if ( contains( predef_accounts, loginname )) loginname = default_login_name;
  180.  
  181.          UI(`ChangeWidget( `id("loginname"), `Value, loginname ));
  182.       }
  183.  
  184.       else if (ret == `cancel) break;
  185.  
  186.       else
  187.       {
  188.       forename   = UI(`QueryWidget(`id("forename"), `Value));
  189.       surname    = UI(`QueryWidget(`id("surname"), `Value));
  190.       loginname  = UI(`QueryWidget(`id("loginname"), `Value));
  191.       string pw1 = UI(`QueryWidget(`id("pw1"), `Value));
  192.       string pw2 = UI(`QueryWidget(`id("pw2"), `Value));
  193.  
  194.       user_settings = add (user_settings, "forename", forename);
  195.       user_settings = add (user_settings, "surname", surname);
  196.       user_settings = add (user_settings, "loginname", loginname);
  197.  
  198.       if (ret == `back) break;
  199.  
  200.       if ( this_is_for_real && (forename == "") && (surname == "") )
  201.       {
  202.               // There is a check whether the information from the UI is
  203.               // correct and complete.  The name information is not
  204.               // complete, the user is asked to complete the information
  205.           UI(`DisplayMessage(_("Please enter your name.")));
  206.           UI(`SetFocus(`id("forename")));
  207.           continue;
  208.       }
  209.  
  210.       if ( this_is_for_real && loginname == "" )
  211.       {
  212.              // There is a check whether the information from the UI is
  213.              // correct and complete.  The loginname is empty (no user
  214.              // input).
  215.          UI(`DisplayMessage(_("You didn't enter a loginname.\nPlease try again.")));
  216.          UI(`SetFocus(`id("loginname")));
  217.          continue;
  218.       }
  219.  
  220.       if  ( this_is_for_real && ( size( loginname ) < 2 || size( loginname ) > 8 ) )
  221.       {
  222.          // There is a check whether the information from the UI is
  223.          // correct and complete.  The loginname must have a size
  224.          // between 2 and 8 characters.
  225.          UI(`DisplayMessage(_("The login name must have a size between 2 and 8 characters.\nPlease try again.")));
  226.          UI(`SetFocus(`id("loginname")));
  227.          continue;
  228.       }
  229.  
  230.       string firstchar = substring(loginname, 0, 1);
  231.       
  232.       if ( this_is_for_real &&
  233.            ( ! (firstchar >= "a" && firstchar <= "z") ||
  234.          nil != findfirstnotof( loginname, valid_logname_chars ) ) )
  235.       {
  236.          // There is a check whether the information from the UI is
  237.          // correct and complete.  The login name may contain only
  238.          // certain characters and must begin with a letter.
  239.              UI(`DisplayMessage(_("The login name may contain only\nlower case letters and digits\nand must begin with a letter.\nPlease try again.")));
  240.          UI(`SetFocus(`id("loginname")));
  241.          continue;
  242.       }
  243.  
  244.           // check login against passwd contents
  245.  
  246.           if ( contains( predef_accounts, loginname ))
  247.       {
  248.              // Tell the user that the login he entered conflicts with
  249.              // predefined logins in the passwd file.
  250.              UI(`DisplayMessage(_("\
  251. There is a conflict between the entered\n\
  252. login name and a predefined login name.\n\n\
  253. Please try another one.")));
  254.          continue;
  255.       }
  256.  
  257.       if ( this_is_for_real && pw1 != pw2 )
  258.       {
  259.           // There is a check whether the information from the UI is
  260.           // correct and complete.  The two user password information
  261.           // do not match
  262.           UI(`DisplayMessage(_("The first and the second version\nof the password are different.\nPlease try again.")));
  263.               password = "";
  264.           // Invalidate any old password
  265.           user_settings = add(user_settings, "upassword", password);
  266.           UI(`SetFocus(`id("pw1")));
  267.           continue;
  268.       }
  269.  
  270.       // Use the old password (if any) if no passwords were entered.
  271.       // only check pw1 here, its identical with pw2 as checked before
  272.       if ( this_is_for_real && ( (pw1 != "") || (password == "") ) )
  273.       {
  274.           if ( pw1 == "" )
  275.           {
  276.             // There is a check whether the information from the
  277.             // UI is correct and complete.  The first user password
  278.             // information is empty (no user input)
  279.             UI(`DisplayMessage(_("You didn't enter a password.\nPlease try again.")));
  280.                 password = "";
  281.             // Invalidate any old password
  282.             user_settings = add(user_settings, "upassword", password);
  283.             UI(`SetFocus(`id("pw1")));
  284.             continue;
  285.           }
  286.           if ( size (pw1) < 5 )
  287.           {
  288.             // There is a check whether the information from the
  289.             // UI is correct and complete.  The user password
  290.             // information must have a minimal size - 5 characters.
  291.             UI(`DisplayMessage(_("The password must have at least 5 characters.\nPlease try again.")));
  292.                     password = "";
  293.             // Invalidate any old password
  294.             user_settings = add(user_settings, "upassword", password);
  295.             UI(`SetFocus(`id("pw1")));
  296.             continue;
  297.           }
  298.  
  299.           if ( size(pw1) >= 5 )
  300.           {
  301.          if ( nil != findfirstnotof( pw1, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#* ,.;:._-+!$%&/|\?{[()]}" ) )
  302.          {
  303.             // There is a check whether the information from the
  304.             // UI is correct and complete.  The user password may
  305.             // contain only certain characters
  306.             UI(`DisplayMessage(_("The password may only contain the following characters:\n 0..9, a..z, A..Z, and any of \"#* ,.;:._-+!$%&/|\?{[()]}\".\nPlease try again.")));
  307.                     password = "";
  308.             // Invalidate any old password
  309.             user_settings = add(user_settings, "upassword", password);
  310.             UI(`SetFocus(`id("pw1")));
  311.             continue;
  312.          }
  313.           }
  314.           password = crypt (pw1);
  315.       }
  316.  
  317.       user_settings = add(user_settings, "upassword", password);
  318.       break;
  319.       }
  320.   }
  321.  
  322.   return ret;
  323. }
  324.