Module: Wright::Util::User Private

Defined in:
lib/wright/util/user.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Various user utility functions.

Class Method Summary collapse

Class Method Details

.group_to_gid(group) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a group’s gid.

Examples:

Wright::Util::User.group_to_gid('root')
# => 0

Wright::Util::User.group_to_gid(0)
# => 0

Parameters:

  • group (String, Integer)

    the group’s name or gid

Returns:

  • (Integer)

    the integer gid of the given group or nil if group was nil



37
38
39
# File 'lib/wright/util/user.rb', line 37

def self.group_to_gid(group)
  to_id(group, :group)
end

.next_free_gid(gid_range) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the next free gid in a range.

Examples:

Wright::Util::User.next_free_gid(1...500)
# => 11

Parameters:

  • gid_range (Range)

    the gid range

Returns:

  • (Integer)

    the next free gid

Raises:

  • (RuntimeError)

    if there are no free gids in the range



73
74
75
# File 'lib/wright/util/user.rb', line 73

def self.next_free_gid(gid_range)
  next_free_id(gid_range, :gid)
end

.next_free_uid(uid_range) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the next free uid in a range.

Examples:

Wright::Util::User.next_free_uid(1...500)
# => 2

Parameters:

  • uid_range (Range)

    the uid range

Returns:

  • (Integer)

    the next free uid

Raises:

  • (RuntimeError)

    if there are no free uids in the range



59
60
61
# File 'lib/wright/util/user.rb', line 59

def self.next_free_uid(uid_range)
  next_free_id(uid_range, :uid)
end

.safe_getgrnam(groupname) ⇒ Struct::Group?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a group entry.

Examples:

Wright::Util::User.safe_getgrnam('this_group_does_not_exist')
# => nil

Parameters:

  • groupname (String)

    the name of the group

Returns:

  • (Struct::Group, nil)

    the group entry or nil if the group does not exist



122
123
124
125
126
# File 'lib/wright/util/user.rb', line 122

def self.safe_getgrnam(groupname)
  Etc.getgrnam(groupname)
rescue ArgumentError
  nil
end

.safe_getpwnam(username) ⇒ Struct::Passwd?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a user entry.

Examples:

Wright::Util::User.safe_getpwnam('this_user_does_not_exist')
# => nil

Parameters:

  • username (String)

    the name of the user

Returns:

  • (Struct::Passwd, nil)

    the user entry or nil if the user does not exist



106
107
108
109
110
# File 'lib/wright/util/user.rb', line 106

def self.safe_getpwnam(username)
  Etc.getpwnam(username)
rescue ArgumentError
  nil
end

.user_to_uid(user) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a user’s uid.

Examples:

Wright::Util::User.user_to_uid('root')
# => 0

Wright::Util::User.user_to_uid(0)
# => 0

Parameters:

  • user (String, Integer)

    the user’s name or uid

Returns:

  • (Integer)

    the integer uid of the given user or nil if user was nil



20
21
22
# File 'lib/wright/util/user.rb', line 20

def self.user_to_uid(user)
  to_id(user, :user)
end