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.

API:

  • private

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:

  • the group’s name or gid

Returns:

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

API:

  • private



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

Raises:

  • if there are no free gids in the range

Parameters:

  • the gid range

Returns:

  • the next free gid

API:

  • private



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

Raises:

  • if there are no free uids in the range

Parameters:

  • the uid range

Returns:

  • the next free uid

API:

  • private



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:

  • the name of the group

Returns:

  • the group entry or nil if the group does not exist

API:

  • private



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:

  • the name of the user

Returns:

  • the user entry or nil if the user does not exist

API:

  • private



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:

  • the user’s name or uid

Returns:

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

API:

  • private



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

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