Module: OpenDirectoryUtils::CommandsGroups
- Includes:
- CleanCheck, CommandsBase
- Included in:
- CommandsUserCreateRemove, Connection
- Defined in:
- lib/open_directory_utils/commands_groups.rb
Overview
-
these commands were derived from the following resrouces:
this is a long list of pre-built dscl commands affecting groups to accomplish common actions
Instance Method Summary collapse
-
#group_create_full(attribs, dir_info) ⇒ Object
(also: #group_create)
create group – dscl .
- #group_create_min(attribs, dir_info) ⇒ Object
-
#group_delete(attribs, dir_info) ⇒ Object
dscl .
- #group_exists?(attribs, dir_info) ⇒ Boolean
-
#group_get_info(attribs, dir_info) ⇒ Object
(also: #group_info)
dscl .
- #group_set_primary_group_id(attribs, dir_info) ⇒ Object
- #group_set_real_name(attribs, dir_info) ⇒ Object
-
#user_in_group?(attribs, dir_info) ⇒ Boolean
dscl .
Methods included from CommandsBase
#build_dscl_command, #build_dseditgroup_command, #build_pwpolicy_command, #dscl, #dseditgroup, #pwpolicy
Methods included from CleanCheck
#assert, #check_critical_attribute, #group_record_name_alternatives, #tidy_attribs, #user_record_name_alternatives
Instance Method Details
#group_create_full(attribs, dir_info) ⇒ Object Also known as: group_create
create group – dscl . -create /Groups/ladmins add group passwd – dscl . -create /Groups/ladmins passwd “*”add group name – dscl . -create /Groups/ladmins RealName “Local Admins”group ID number – dscl . -create /Groups/ladmins gid 400 group id number – dscl . -create /Groups/GROUP PrimaryGroupID GID
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/open_directory_utils/commands_groups.rb', line 131 def group_create_full(attribs, dir_info) attribs = group_record_name_alternatives(attribs) answer = [] attribs[:value] = nil answer << group_create_min( attribs, dir_info ) attribs[:value] = nil answer << group_set_primary_group_id( attribs, dir_info ) attribs[:value] = nil answer << group_set_real_name( attribs, dir_info ) # attribs[:value] = nil # answer << group_set_password( attribs, dir_info ) return answer end |
#group_create_min(attribs, dir_info) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/open_directory_utils/commands_groups.rb', line 74 def group_create_min(attribs, dir_info) attribs = group_record_name_alternatives(attribs) check_critical_attribute( attribs, :record_name ) command = {action: 'create', scope: 'Groups', attribute: nil, value: nil} user_attrs = attribs.merge(command) dscl( user_attrs, dir_info ) end |
#group_delete(attribs, dir_info) ⇒ Object
dscl . -delete /Groups/yourGroupName tutorialforlinux.com/2011/09/15/delete-users-and-groups-from-terminal/
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/open_directory_utils/commands_groups.rb', line 63 def group_delete(attribs, dir_info) attribs = group_record_name_alternatives(attribs) check_critical_attribute( attribs, :record_name ) command = {action: 'delete', scope: 'Groups', attribute: nil, value: nil} user_attrs = attribs.merge(command) dscl( user_attrs, dir_info ) end |
#group_exists?(attribs, dir_info) ⇒ Boolean
30 31 32 |
# File 'lib/open_directory_utils/commands_groups.rb', line 30 def group_exists?(attribs, dir_info) group_get_info(attribs, dir_info) end |
#group_get_info(attribs, dir_info) ⇒ Object Also known as: group_info
dscl . read /Groups/ladmins
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/open_directory_utils/commands_groups.rb', line 18 def group_get_info(attribs, dir_info) attribs = group_record_name_alternatives(attribs) check_critical_attribute( attribs, :record_name ) command = {action: 'read', scope: 'Groups', value: nil} user_attrs = attribs.merge(command) dscl( user_attrs, dir_info ) end |
#group_set_primary_group_id(attribs, dir_info) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/open_directory_utils/commands_groups.rb', line 85 def group_set_primary_group_id(attribs, dir_info) attribs = group_record_name_alternatives(attribs) attribs[:value] = attribs[:value] || attribs[:primary_group_id] attribs[:value] = attribs[:value] || attribs[:group_number] attribs[:value] = attribs[:value] || attribs[:groupnumber] attribs[:value] = attribs[:value] || attribs[:gidnumber] attribs[:value] = attribs[:value] || attribs[:group_id] check_critical_attribute( attribs, :record_name ) check_critical_attribute( attribs, :value, :group_id ) command = {action: 'create', scope: 'Groups', attribute: 'PrimaryGroupID'} user_attrs = attribs.merge(command) dscl( user_attrs, dir_info ) end |
#group_set_real_name(attribs, dir_info) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/open_directory_utils/commands_groups.rb', line 103 def group_set_real_name(attribs, dir_info) attribs = group_record_name_alternatives(attribs) attribs[:value] = attribs[:value] || attribs[:real_name] attribs[:value] = attribs[:value] || attribs[:long_name] attribs[:value] = attribs[:value] || attribs[:longname] attribs[:value] = attribs[:value] || attribs[:full_name] attribs[:value] = attribs[:value] || attribs[:fullname] attribs[:value] = attribs[:value] || attribs[:name] attribs[:value] = attribs[:value] || attribs[:group_name] attribs[:value] = attribs[:value] || attribs[:groupname] attribs[:value] = attribs[:value] || attribs[:gid] attribs[:value] = attribs[:value] || attribs[:cn] check_critical_attribute( attribs, :record_name ) check_critical_attribute( attribs, :value, :real_name ) command = {action: 'create', scope: 'Groups', attribute: 'RealName'} user_attrs = attribs.merge(command) dscl( user_attrs, dir_info ) end |
#user_in_group?(attribs, dir_info) ⇒ Boolean
dscl . -read /Groups/ladmins TODO: switch to dseditgroup -o checkmember -m username groupname dseditgroup -o checkmember -m btihen employee
yes btihen is a member of employee
dseditgroup -o checkmember -m btihen student
no btihen is NOT a member of student
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/open_directory_utils/commands_groups.rb', line 40 def user_in_group?(attribs, dir_info) temp = user_record_name_alternatives(attribs) username = temp[:record_name] # pp username # pp attribs attribs = group_record_name_alternatives(attribs) # groupname = attribs[:record_name] attribs[:value] = username # pp attribs check_critical_attribute( attribs, :value, :username ) check_critical_attribute( attribs, :record_name, :groupname ) attribs = tidy_attribs(attribs) command = {action: 'read', scope: 'Groups', attribute: nil, value: nil} cmd_attribs = attribs.merge(command) dscl( cmd_attribs, dir_info ) end |