Skip to content

Commit

Permalink
Merge 95b55fd into e207968
Browse files Browse the repository at this point in the history
  • Loading branch information
raphink committed Oct 17, 2018
2 parents e207968 + 95b55fd commit 10a0223
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
42 changes: 31 additions & 11 deletions lib/puppet/provider/pam/augeas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def self.target(resource = nil)
end
end

def self.position_path (position, type)
def self.position_path(position, type)
placement, identifier, value = position.split(/ /)
key = !!value
if PAM_POSITION_ALIASES[key].has_key? identifier
Expand Down Expand Up @@ -77,25 +77,45 @@ def in_position?
end
end

def self.instances_targets
['/etc/pam.conf', '/etc/pam.d/*']
end

def self.instances
augopen do |aug|
lens_name = lens[/[^\.]+/]
# Load all default files
aug.transform(
:lens => lens,
:name => lens_name,
:incl => instances_targets,
:excl => []
)
aug.load
resources = []
aug.match("$target/*[label()!='#comment']").each do |spath|
instances_target_paths = [instances_targets].flatten.map { |t| "/files"+t }.join("|")
aug.match("(#{instances_target_paths})//*[label()!='#comment']").each do |spath|
optional = aug.match("#{spath}/optional").empty?.to_s.to_sym
type = aug.get("#{spath}/type")
control = aug.get("#{spath}/control")
mod = aug.get("#{spath}/module")
arguments = aug.match("#{spath}/argument").map { |p| aug.get(p) }
entry = {:ensure => :present,
:optional => optional,
:type => type,
:control => control,
:module => mod,
:arguments => arguments}
if target == '/etc/pam.conf'
entry[:service] = aug.get("#{spath}/service")
if mod
target = '/'+spath.split('/')[2..-2].join('/')
service = nil
if spath.start_with? '/files/etc/pam.conf/'
service = aug.get("#{spath}/service")
else
service = spath.split('/')[4]
end
entry = {:name => "#{service}/#{mod}/#{type} in #{target}",
:ensure => :present,
:optional => optional,
:control => control,
:arguments => arguments,
}
resources << new(entry)
end
resources << new(entry)
end
resources
end
Expand Down
15 changes: 13 additions & 2 deletions lib/puppet/type/pam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,33 @@ def munge_boolean(value)
end

newparam(:name) do
desc "The name of the resource, has no bearing on anything"
isnamevar
desc "The name of the resource, has no bearing on anything"
isnamevar
end

newparam(:service) do
desc "The PAM service this entry will be placed in. Typically this is the same as the
filename under /etc/pam.d"
isnamevar
end

newparam(:type) do
desc "The PAM service type of the setting: account, auth, password, session."
newvalues(:account, :auth, :password, :session)
isnamevar
end

newparam(:module) do
desc "The name of the specific PAM module to load."
isnamevar
end

def self.title_patterns
[
[ /(([^\/]+)\/([^\/]+)\/([^\/]+)\sin\s(.*))/, [ [:name], [:service], [:module], [:type], [:target] ] ],
[ /(([^\/]+)\/([^\/]+)\/([^\/]+))/, [ [:name], [:service], [:module], [:type] ] ],
[ /(.*)/, [ [:name] ] ],
]
end

newproperty(:optional, :boolean => true) do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/puppet/provider/pam/augeas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
let(:target) { tmptarget.path }

it "should list instances" do
provider_class.stubs(:target).returns(target)
provider_class.stubs(:instances_targets).returns(target)
inst = provider_class.instances.map { |p|
{
:ensure => p.get(:ensure),
Expand Down

0 comments on commit 10a0223

Please sign in to comment.