Prototype: useringroup(user)

Return type: boolean

Description: Return whether a user is a member of a given group

Looks up the group "group_name" in the group database located in /etc/group and checks whether "user_name" is one of its members. This function is not available on Windows.

Arguments:

  • user_name: string - User name - in the range: .*
  • group_name: string - Group name - in the range: .*

Example:

code
body common control 
{
    bundlesequence => { "example" };
}
bundle agent example
{
    classes:
        "root_in_root" expression => useringroup("root", "root");

    reports:
        root_in_root::
            "root is indeed in the root group";
        !root_in_root::
            "something went wrong";
}

Output:

code
R: root is indeed in the root group

History:

  • Added in CFEngine 3.26.0