NAME

Setup::Unix::User - Setup Unix user (existence, home dir, group memberships)

VERSION

version 0.10

FAQ

How to create user without creating a group with the same name as that user?

By default, group is set to the same name as the user. This will create group with the same name as the user (if the group didn't exist). You can set group to an existing group, e.g. users and the setup function will not create a new group with the same name as user. But note that the group must already exist (if it does not, you can create it first using Setup::Unix::Group).

SEE ALSO

Setup

Setup::Unix::Group

DESCRIPTION

This module has Rinci metadata.

FUNCTIONS

None are exported by default, but they are exportable.

add_delete_user_groups(%args) -> [status, msg, result, meta]

Add/delete user from group memberships.

This function is idempotent (repeated invocations with same arguments has the same effect as single invocation). This function supports transactions.

Arguments ('*' denotes required arguments):

  • add_to* => array

  • delete_from* => array

  • etc_dir => str (default: "/etc")

    Location of passwd files.

  • user => str

    User name.

Special arguments:

Return value:

Returns an enveloped result (an array). First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

adduser(%args) -> [status, msg, result, meta]

Add user.

This function is idempotent (repeated invocations with same arguments has the same effect as single invocation). This function supports transactions.

Arguments ('*' denotes required arguments):

  • etc_dir => str (default: "/etc")

    Location of passwd files.

  • gecos => str

  • gid => int

    When creating group, use specific GID.

    If not specified, will search an unused GID from min_gid to max_gid.

  • home => str

  • max_gid => int (default: 65534)

  • max_uid => int (default: 65534)

  • min_gid => int (default: 1000)

  • min_uid => int (default: 1000)

  • pass => str

  • shell => str

  • uid => int

    Add with specified UID.

    If not specified, will search an unused UID from min_uid to max_uid.

  • user => str

    User name.

Special arguments:

Return value:

Returns an enveloped result (an array). First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

deluser(%args) -> [status, msg, result, meta]

Delete user.

This function is idempotent (repeated invocations with same arguments has the same effect as single invocation). This function supports transactions.

Arguments ('*' denotes required arguments):

  • etc_dir => str (default: "/etc")

    Location of passwd files.

  • user => str

    User name.

Special arguments:

Return value:

Returns an enveloped result (an array). First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

setup_unix_user(%args) -> [status, msg, result, meta]

Setup Unix user (existence, group memberships).

On do, will create Unix user if not already exists. And also make sure user belong to specified groups (and not belong to unwanted groups). Return the created UID/GID in the result.

On undo, will delete Unix user (along with its initially created home dir and files) if it was created by this function. Also will restore old group memberships.

This function is idempotent (repeated invocations with same arguments has the same effect as single invocation). This function supports transactions.

Arguments ('*' denotes required arguments):

  • create_home => bool (default: 1)

    Whether to create home directory when creating user.

  • member_of => array

    List of Unix group names that the user must be member of.

    If not specified, member_of will be set to just the primary group. The primary group will always be added even if not specified.

  • new_gecos => str

  • new_gid => int

    When creating group, use specific GID.

    If not specified, will search an unused GID from min_gid to max_gid.

  • new_home => str

  • new_max_gid => int (default: 65534)

  • new_max_uid => int (default: 65534)

  • new_min_gid => int (default: 1000)

  • new_min_uid => int (default: 1000)

  • new_pass => str

  • new_shell => str

  • new_uid => int

    Add with specified UID.

    If not specified, will search an unused UID from min_uid to max_uid.

  • not_member_of => array

    List of Unix group names that the user must NOT be member of.

  • should_already_exist => bool

    Whether user should already exist.

  • should_exist => bool (default: 1)

    Whether user should exist.

  • skel_dir => str (default: "/etc/skel")

    Directory to get skeleton files when creating user.

  • use_skel => bool (default: 1)

    Whether to copy files from skeleton dir when creating user.

  • user => str

    User name.

Special arguments:

Return value:

Returns an enveloped result (an array). First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.