12. YaPI::USERS

This package is the public YaST2 API for Users/Groups management

12.1. List of Global Functions

12.2. Functions

12.2.1. $error UserAdd ($config_hash, $data_hash);

Creates new user. User attributes are described in $data_hash, $config_hash describes special configuration data.

Example 315. 

  my $config    = { "type"              => "ldap",
                    "plugins"           => [ "UsersPluginLDAPAll" ],
                    "bind_dn"           => "uid=admin,dc=example,dc=com",
  };
  my $data      = { "uid"               => "ll",
                    "uidnumber"         => 1111,
                    "userpassword"      => "qqqqq"
                    "givenName"         => "l",
                    "cn"                => [ "ll" ]
                    "description"       => [ "first", "second" ],
  };
  # create new LDAP user
  my $error     = UserAdd ($config, $data);

  # create new local user 'hh'; use all available defaults
  UserAdd ({}, { "uid"  => "hh" });

Example 316. 

  You can see on example that LDAP attributes could be passed either
  as list of value or as strings, which is just the same case as a list
  with one value.
 

12.2.2. $error UserModify ($config_hash, $data_hash);

Modifies existing user. User attributes which should be changed are described in $data_hash, $config_hash describes special configuration data, especially user identification.

Example 317. 

  my $config    = { "type"              => "ldap",
                    "uidnumber"         => 500
  };
  my $data      = { "userpassword"      => "wwwww"
  };
  # changes a password of LDAP user (identified with id)
  my $error     = UserModify ($config, $data);

  # change GID value of local user (identified with name)
  $error        = UserModify ({ "uid" => "hh" }, { "gidnumber" => 5555 });

12.2.3. $error UserFeatureAdd ($config_hash);

Adds a new feature (plugin) to the given user.

Example 318. 

  my $config    = { "type"              => "ldap",
                    "plugins"           => [ "UsersPluginSambaAccount" ],
                    "bind_dn"           => "uid=admin,dc=example,dc=com",
                    "uid"               => "ll"
  };
  # adds 'SambaAccount' plugin to the user
  my $error     = UserFeatureAdd ($config);

12.2.4. $error UserFeatureDelete ($config_hash);

Deletes a new feature (plugin) to the given user.

Example 319. 

  my $config    = { "type"              => "ldap",
                    "plugins"           => [
                        "UsersPluginSambaAccount",
                        "UsersPluginMail"
                    ],
                    "uid"               => "ll"
  };
  # removes 'SambaAccount' and 'Mail' plugin from the user 
  my $error     = UserFeatureDelete ($config);

12.2.5. $error UserDelete ($config_hash);

Deletes existing user. Identification of user selected for delete is stored in $config_hash.

Example 320. 

  my $config    = { "type"              => "ldap",
                    "dn"                => "uid=ll,dc=example,dc=com",
                    "delete_home"       => YaST::YCP::Boolean (1)
  };
  # deletes LDAP user together with its home directory
  my $error     = UserDelete ($config);

  $error        = UserDelete ({ "uid" => "hh", "type" => "local" });

12.2.6. $error UserDisable ($config_hash);

Disables existing user to log in. Identification of user selected for delete is stored in $config_hash.

Example 321. 

  my $config    = { "type"              => "ldap",
                    "uidnumber"         => 500,
  };
  # disables LDAP user (as it is defined its plugins)
  my $error     = UserDisable ($config);

12.2.7. $error UserEnable ($config_hash);

Enables existing user to log in. Identification of user selected for delete is stored in $config_hash.

Example 322. 

  my $config    = { "type"              => "ldap",
                    "uidnumber"         => 500,
  };
  # enables LDAP user (in a default way, defined for LDAP users)
  my $error     = UserEnable ($config);

12.2.8. $data_hash UserGet ($config_hash);

Returns a map describing selected user.

Example 323. 

  my $config    = { "type"              => "ldap",
                    "user_attributes"   => [ "uid", "uidnumber", "cn" ],
                    "uidnumber"         => 500
  };
  # searches for LDAP user with uidnumber 500 and returns the hash with given
  # attributes
  
  my $user      = UserGet ($config);

  $config       = { "type"              => "ldap",
                    "uid"               => "my_user",
                    "user_base"         => "ou=people,dc=example,dc=com",
                    "bind_dn"           => "uid=admin,dc=example,dc=com",
  };
  # searches for LDAP user with uid "my_user" in given search base and
  # returns the hash with all user's non-empty attributes
  $user         = UserGet ($config);

12.2.9. $users_hash UsersGet ($config_hash);

Returns a hash describing the set of users. By default, the hash is indexed by UID number, unless statet otherwise in $config_hash.

Example 324. 

  my $config    = { "type"              => "ldap",
                    "user_attributes"   => [ "uid", "uidnumber", "cn" ],
                    "user_base"         => "ou=people,dc=example,dc=com",
                    "user_scope"        => YaST::YCP::Integer (2),
                    "user_filter"       => [ "objectclass=posixAccount" ]
                    "index"             => "dn"
  };
  # searches for LDAP users in given search base and returns the hash
  # indexed by DN's with the hash values containing users with given attributes
  my $users     = UsersGet ($config);

12.2.10. $error GroupAdd ($config_hash, $data_hash);

Creates new group. Group attributes are described in $data_hash, $config_hash describes special configuration data.

Example 325. 

  my $config    = { "type"              => "ldap",
                    "group_plugins"     => [ "GroupsPluginsLDAPAll" ],
                    "bind_dn"           => "uid=admin,dc=example,dc=com",
                    "group_base"        => "ou=groups,dc=example,dc=com"
  };
  my $data      = { "gidnumber"         => 5555,
                    "cn"                => "lgroup",
                    "member"            => {
                        "uid=test,ou=people,dc=example,dc=com"  => 1,
                        "uid=ll,ou=people,dc=example,dc=com"    => 1
                    }
  };
  # create new LDAP group

  my $error     = GroupAdd ($config, $data);

  # create new system group 
  GroupAdd ({ "type" => "system" }, {
        "cn"            => "ggg",
        "userlist"      => {
            "root"      => 1,
            "hh"        => 1
        }
  );

12.2.11. $error GroupModify ($config_hash, $data_hash);

Modifies existing group. Group attributes which should be changed are described in $data_hash, $config_hash describes special configuration data, especially group identification.

Example 326. 

  # change GID value of local group (identified with name)
  my $error     = GroupModify ({ "cn" => "users" }, { "gidnumber" => 101 });

  my $config    = { "type"              => "ldap",
                    "gidnumber"         => 5555
  };
  my $data      = { "member"            => [
                        "uid=test,ou=people,dc=example,dc=com",
                        "uid=ll,ou=people,dc=example,dc=com",
                        "uid=admin,dc=example,dc=com"
                    ]
  };
  # changes a member attribute of LDAP group (identified with id)
  $error        = GroupModify ($config, $data);

    

Example 327. 

  You can see on example that "member" attribute could be passed either
  as an array (which could one expect for LDAP attribute) or as hash,
  (which is used by YaST for internal representation) as shown in example
  for GroupAdd () function. YaST always takes care of it and does the
  necessary conversions.

12.2.12. $error GroupMemberAdd ($config_hash, $user_hash);

Adds a new member to the given group. User is described in $user_hash, group identification is passwd in $config_hash.

Example 328. 

  my $config    = { "type"              => "ldap",
                    "bind_dn"           => "uid=admin,dc=example,dc=com",
                    "gidnumber"         => 5555
  };
  my $user      = { "uid"               => "my_user" }
  };

  my $error     = GroupMemberAdd ($config, $user);

12.2.13. $error GroupMemberDelete ($config_hash, $user_hash);

Deletes a member from the group.

Example 329. 

  my $config    = { "type"              => "ldap",
                    "dn"                => "cn=lgroup,dc=example,dc=com"
  };
  my $user      = { "uidnumber"         => 1000 }

  # removes user with given uidnumber from group with given DN
  my $error     = GroupMemberDelete ($config, $user);

12.2.14. $error GroupDelete ($config_hash);

Deletes existing group. Identification of group is stored in $config_hash.

Example 330. 

  my $config    = { "type"              => "local",
                    "uid"               => "users"
  };
  my $error     = GroupDelete ($config);

12.2.15. $data_hash GroupGet ($config_hash);

Returns a map describing selected group.

Example 331. 

  my $config    = { "type"              => "ldap",
                    "group_attributes"  => [ "cn", "gidnumber", "member" ],
                    "gidnumber"         => 500
  };
  # searches for LDAP group with gidnumber 500 and returns the hash
  # with given attributes
  my $group     = GroupGet ($config);

12.2.16. $groups_hash GroupsGet ($config_hash);

Returns a hash describing the set of groups. By default, the hash is indexed by GID number, unless statet otherwise in $config_hash.

Example 332. 

  # searches for LDAP groups in default base and returns the hash
  # indexed by GID's with the hash values containing groups with all
  # non-empty attributes
  my $groups    = GroupsGet ({ "type" => "ldap" });

  # returns hash with all NIS groups
  $groups       = GroupsGet ({ "type" => "nis" });

12.2.17. $groups_hash GroupsGetByUser ($config_hash, $user_hash);

Returns a hash describing the set of groups. By default, the hash is indexed by GID number, unless statet otherwise in $config_hash.

Example 333. 

  my $config    = { "type"      => "ldap",
                    "index"     => "dn"
                    "group_scope"       => YaST::YCP::Integer (2),
  };
  my $user      = { "dn"        => "uid=ll,ou=people,dc=example,dc=com" };

  # searches for LDAP groups in default base and returns the hash
  # indexed by DN's with the hash values containing groups with all
  # non-empty attributes
  my $groups    = GroupsGetByUser ($config, $user);