Class: MacAdmin::DSLocalNode

Inherits:
Object
  • Object
show all
Defined in:
lib/macadmin/dslocal/dslocalnode.rb

Overview

DSLocalNode

  • constructs and manages Local OpenDirectory nodes

  • takes one parameter: name

  • if no name param is passed, ‘Default’ node is used

Constant Summary collapse

SANDBOX_FILE =
'/System/Library/Sandbox/Profiles/com.apple.opendirectoryd.sb'
PREFERENCES =
'/Library/Preferences/OpenDirectory/Configurations/Search.plist'
PREFERENCES_LEGACY =
'/Library/Preferences/DirectoryService/SearchNodeConfig.plist'
CHILD_DIRS =
['aliases', 'computer_lists', 'computergroups', 'computers', 'config', 'groups', 'networks', 'users']
DSLOCAL_ROOT =
'/private/var/db/dslocal/nodes'
DIRMODE =
16832
FILEMODE =
33152
OWNER =
0
GROUP =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = 'Default') ⇒ DSLocalNode

Returns a new instance of DSLocalNode.



26
27
28
29
30
31
32
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 26

def initialize(name='Default')
  @name   = name
  @label  = "/Local/#{name}"
  @root   = "#{DSLOCAL_ROOT}/#{name}"
  load_configuration_file
  self
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



24
25
26
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 24

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 24

def name
  @name
end

#rootObject (readonly)

Returns the value of attribute root.



24
25
26
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 24

def root
  @root
end

Instance Method Details

#activateObject

Add the node to the list of searchable directory services

  • also: add a sandbox configuration if required



88
89
90
91
92
93
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 88

def activate
  activate_sandbox if needs_sandbox?
  insert_node
  set_custom_searchpolicy
  save_config
end

#active?Boolean

Test whether or not the node is in the search path

  • also: test the sandbox configuration if required

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 58

def active?
  if needs_sandbox?
    return false unless sandbox_active?
  end
  load_configuration_file
  if self.name.eql? 'Default'
    case policy = self.searchpolicy
    when Integer
      return true if policy < 3
    else
      return true if policy =~ /\AdsAttrTypeStandard:[LN]SPSearchPath\z/
    end
  end
  return false if cspsearchpath.nil?
  return false unless searchpolicy_is_custom?
  cspsearchpath.member?(@label)
end

#createObject

Create the directory structure



77
78
79
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 77

def create
  create_directories
end

#create_and_activateObject

Compound method: create and then activate the node



35
36
37
38
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 35

def create_and_activate
  create
  activate
end

#cspsearchpathObject

Returns the search path array



118
119
120
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 118

def cspsearchpath
  eval @paths_key
end

#cspsearchpath=(array) ⇒ Object

Replaces the search path array



123
124
125
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 123

def cspsearchpath=(array)
  eval @paths_key+"= array"
end

#deactivateObject

Remove the node to the list of searchable directory services

  • also: remove a sandbox configuration if required



97
98
99
100
101
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 97

def deactivate
  deactivate_sandbox if needs_sandbox?
  remove_node
  save_config
end

#destroyObject

Destroy the directory structure



82
83
84
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 82

def destroy
  FileUtils.rm_rf @root
end

#destroy_and_deactivateObject

Compound method: destroy and then deactivate the node



41
42
43
44
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 41

def destroy_and_deactivate
  destroy
  deactivate
end

#exists?Boolean

Does the directory structure exist?

Returns:

  • (Boolean)


52
53
54
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 52

def exists?
  validate_directory_structure
end

#exists_and_active?Boolean

Compound method: does the node exist and is it active?

Returns:

  • (Boolean)


47
48
49
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 47

def exists_and_active?
  exists? and active?
end

#searchpolicyObject

Returns the search policy



104
105
106
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 104

def searchpolicy
  eval @policy_key
end

#searchpolicy=(val) ⇒ Object

Replaces the search policy



109
110
111
112
113
114
115
# File 'lib/macadmin/dslocal/dslocalnode.rb', line 109

def searchpolicy=(val)
  if val.is_a?(String)
    eval @policy_key+"= val"
  else
    eval @policy_key+"= #{val}"
  end
end