ACC SHELL
/**
* File: modules/Pam.ycp
* Package: yast2-pam
* Summary: YaST intrerface for /etc/pam.d/* files
* Authors: Jiri Suchomel <jsuchome@suse.cz>
* Flags: Unstable
*
* $Id: Pam.ycp 57400 2009-06-02 20:39:28Z jsuchome $
*
*/
{
module "Pam";
/**
* Query PAM configuration for status of given module
* @param string PAM module (e.g. ldap, cracklib)
* @return map <string,list> keys are 'management groups' (e.g. auth), values
* are lists of options
*/
global map Query (string mod) {
map ret = $[];
map out = (map)SCR::Execute (.target.bash_output, "pam-config -q --" + mod);
if (out["exit"]:0 != 0)
{
y2warning ("pam-config for %1 returned %2", mod, out);
return ret;
}
foreach (string line, splitstring (out["stdout"]:"", "\n"), {
list l = splitstring (line, ":");
if (line == "" || size (l) < 2) return;
string key = l[0]:"";
ret[key] =
filter (string o, splitstring (l[1]:"", " \t"), ``(o != ""));
});
return ret;
}
/**
* Ask if given PAM module is enabled
*/
global boolean Enabled (string mod) {
return size (Query(mod)) > 0;
}
/**
* Add options or new PAM module
* @param string PAM module or option
* @return success
*/
global boolean Add (string mod) {
map out = (map)SCR::Execute (.target.bash_output, "pam-config -a --" + mod);
if (out["exit"]:0 != 0)
{
y2warning ("pam-config for %1 returned %2", mod, out);
return false;
}
return true;
}
/**
* Remove options or PAM module
* @param string PAM module or option
* @return success
*/
global boolean Remove (string mod) {
map out = (map)SCR::Execute (.target.bash_output, "pam-config -d --" + mod);
if (out["exit"]:0 != 0)
{
y2warning ("pam-config for %1 returned %2", mod, out);
return false;
}
return true;
}
/**
* Add/Remove option or PAM module
* @param string PAM module or option
* @param boolean true for adding, false for removing
* @return success
*/
global boolean Set (string mod, boolean set) {
return set ? Add (mod) : Remove (mod);
}
}//EOF
ACC SHELL 2018