ACC SHELL

Path : /usr/share/YaST2/include/users/
File Upload :
Current File : //usr/share/YaST2/include/users/routines.ycp

/**
 * File:	include/users/routines.ycp
 * Package:	Configuration of users and groups
 * Summary:	various routines
 * Authors:	Jiri Suchomel <jsuchome@suse.cz>
 *
 * $Id: routines.ycp 45217 2008-03-05 14:52:46Z jsuchome $
 *
 */
{
import "Mode";

textdomain "users";

/**
 * check if this is installation stage -
 * adding user during firstboot should be same as during 2nd stage
 */
define boolean installation () {
    return Stage::cont () || Stage::firstboot ();
}

/**
 * helper function: return the 'any' value as integer
 */
define integer GetInt (any value, integer default_value) {

    if (value == nil)
	return default_value;
    if (is (value, integer))
	return (integer) value;
    if (is (value, string) && value != "")
	return tointeger ((string)value);
    return default_value;
}

/**
 * helper function: return the 'any' value as string
 */
define string GetString (any value, string default_value) {

    if (value == nil)
	return default_value;
    return sformat ("%1", value);
}


/**
 * Split cn (fullname) in forename and surname.
 * @param what `surname or `forename
 * @param cn fullname
 * @param type user type
 * @return string selected part of user name
 */
define string SplitFullName(symbol what,string cn) ``{

    if( cn == nil )
        cn = "";

    // if cn is to be substituted, do not try to resolve givenName/sn
    if (issubstring (cn, "%"))
	return "";

    list<string> strs    = splitstring(cn , " ");
    integer i       = 1;
    string sn  = "";
    string givenName = "";

    foreach(string str, strs, ``{
        if ( i < size( strs) )
        {
        if( givenName == "" ) givenName = str;
        else givenName = givenName + " " + str;
        }
        else  sn = str;
        i = i + 1;
    });
    if ( what == `sn  ) return sn;
    if ( what == `givenName ) return givenName;
}

// if the user has log on system
define boolean UserLogged (string name) {

    map out	= (map) SCR::Execute (.target.bash_output,
	sformat ("ps --no-headers -u %1", name));
    string proc = out["stdout"]:"";
    return (size (proc) != 0 && !Mode::config ());
}


} // EOF

ACC SHELL 2018