From 8c17ab29a5bdd3c96b0fc125727f45ac65744b80 Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Wed, 15 Jul 2015 00:47:17 +0200 Subject: [PATCH] add passwd support --- lib/resources/passwd.rb | 63 +++++++++++++++++++++++++++++++++++++++++ lib/vulcano.rb | 1 + 2 files changed, 64 insertions(+) create mode 100644 lib/resources/passwd.rb diff --git a/lib/resources/passwd.rb b/lib/resources/passwd.rb new file mode 100644 index 000000000..cc4d40786 --- /dev/null +++ b/lib/resources/passwd.rb @@ -0,0 +1,63 @@ +module Serverspec + module Type + + class Passwd < File + + attr_accessor :uid + + def to_s + %Q[Passwd] + end + + def determine_uid () + parsed = parse() + uids = Array.new + parsed.each {|x| + if ( x.at(2) == "#{@uid}") then + uids.push(x.at(0)) + end + } + uids + end + + def username + uids = determine_uid() + uids.at(0) + end + + def uids + determine_uid() + end + + def count + arr = determine_uid() + arr.length + end + + def homedirs + parsed = parse() + parsed.map {|x| + x.at(5) + } + end + + def parse + entries = Array.new + content().split("\n").each do |line| + entries.push(line.split(':')) + end + entries + end + + end + + def passwd(filename, uid=nil) + i = Passwd.new(filename) + i.uid = uid + i + end + + end +end + +include Serverspec::Type \ No newline at end of file diff --git a/lib/vulcano.rb b/lib/vulcano.rb index 9a4003c77..3b76ecdce 100644 --- a/lib/vulcano.rb +++ b/lib/vulcano.rb @@ -22,6 +22,7 @@ require 'resources/file' require 'resources/group_policy' require 'resources/mysql_conf' require 'resources/mysql_session' +require 'resources/passwd' require 'resources/postgres_conf' require 'resources/postgres_session' require 'resources/processes'