diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-02-28 04:27:28 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-02-28 04:27:28 +0000 |
commit | 32cbc596422de6fa82572b4cb2232c4aa417012b (patch) | |
tree | a836d2076bbf25dd5ee7dc96cfa91f731e2cc6ff | |
parent | 8b5f70911d7486a5cab69377c1988f1e35d88d2e (diff) | |
download | puppet-32cbc596422de6fa82572b4cb2232c4aa417012b.tar.gz puppet-32cbc596422de6fa82572b4cb2232c4aa417012b.tar.xz puppet-32cbc596422de6fa82572b4cb2232c4aa417012b.zip |
Fixing #70. We now have user and group management on FreeBSD.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@958 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r-- | lib/puppet/type.rb | 3 | ||||
-rwxr-xr-x | lib/puppet/type/group.rb | 3 | ||||
-rwxr-xr-x | lib/puppet/type/nameservice.rb | 2 | ||||
-rw-r--r-- | lib/puppet/type/nameservice/pw.rb | 94 | ||||
-rwxr-xr-x | lib/puppet/type/user.rb | 3 | ||||
-rwxr-xr-x | test/types/user.rb | 3 |
6 files changed, 106 insertions, 2 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index a8cfe592a..2df667e0b 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1655,7 +1655,7 @@ class Type < Puppet::Element def statechanges # If we are changing the existence of the object, then none of # the other states matter. - changes = nil + changes = [] if @states.include?(:ensure) and ! @states[:ensure].insync? #self.info "ensuring %s from %s" % # [@states[:ensure].should, @states[:ensure].is] @@ -1681,7 +1681,6 @@ class Type < Puppet::Element if Puppet[:debug] and changes.length > 0 self.debug("Changing " + changes.collect { |ch| - self.info ch.state.class ch.state.name }.join(",") ) diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb index e5e69848c..344614190 100755 --- a/lib/puppet/type/group.rb +++ b/lib/puppet/type/group.rb @@ -27,6 +27,9 @@ module Puppet when "Darwin": @parentstate = Puppet::NameService::NetInfo::NetInfoState @parentmodule = Puppet::NameService::NetInfo + when "FreeBSD": + @parentstate = Puppet::NameService::PW::PWGroup + @parentmodule = Puppet::NameService::PW else @parentstate = Puppet::NameService::ObjectAdd::ObjectAddGroup @parentmodule = Puppet::NameService::ObjectAdd diff --git a/lib/puppet/type/nameservice.rb b/lib/puppet/type/nameservice.rb index 1f132ee68..9a9b280e5 100755 --- a/lib/puppet/type/nameservice.rb +++ b/lib/puppet/type/nameservice.rb @@ -224,6 +224,8 @@ end case Facter["operatingsystem"].value when "Darwin": require 'puppet/type/nameservice/netinfo' +when "FreeBSD": + require 'puppet/type/nameservice/pw' else require 'puppet/type/nameservice/objectadd' end diff --git a/lib/puppet/type/nameservice/pw.rb b/lib/puppet/type/nameservice/pw.rb new file mode 100644 index 000000000..421472149 --- /dev/null +++ b/lib/puppet/type/nameservice/pw.rb @@ -0,0 +1,94 @@ +require 'puppet' +require 'puppet/type/nameservice/objectadd' + +module Puppet + module NameService + module PW + # Verify that we've got the commands necessary to manage flat files. + def self.test + system("which pw > /dev/null 2>&1") + + if $? == 0 + return true + else + Puppet.err "Could not find pw" + return false + end + end + + # Does the object already exist? + def self.exists?(obj) + if obj.getinfo + return true + else + return false + end + end + + # The state class for doing group operations using groupadd or whatever. + # I could probably have abstracted the User and Group classes into + # a single class, but eh, it just didn't seem worth it. + class PWGroup < ObjectAdd::ObjectAddGroup + def addcmd + cmd = ["pw", "groupadd", @parent[:name]] + if gid = @parent.should(:gid) + unless gid == :auto + cmd << self.class.objectaddflag << gid + end + end + + return cmd.join(" ") + end + + def deletecmd + "pw groupdel %s" % @parent[:name] + end + + def modifycmd + [ + "pw", + "groupmod", + @parent[:name], + self.class.objectaddflag, + "'%s'" % self.should + ].join(" ") + end + end + + # The class for adding users using 'adduser'. + class PWUser < ObjectAdd::ObjectAddUser + def addcmd + cmd = ["pw", "useradd", @parent[:name], "-w", "no"] + @parent.eachstate { |state| + next if state.name == :ensure + # the value needs to be quoted, mostly because -c might + # have spaces in it + cmd << state.class.objectaddflag << "'%s'" % state.should + } + # stupid fedora + case Facter["operatingsystem"].value + when "Fedora", "RedHat": + cmd << "-M" + end + + cmd.join(" ") + end + + def deletecmd + ["pw", "userdel", @parent[:name]].join(" ") + end + + def modifycmd + cmd = [ + "pw", + "usermod", + @parent[:name], + "-w", "no", + self.class.objectaddflag, + "'%s'" % self.should + ].join(" ") + end + end + end + end +end diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb index b789ad61d..ed9c79211 100755 --- a/lib/puppet/type/user.rb +++ b/lib/puppet/type/user.rb @@ -9,6 +9,9 @@ module Puppet when "Darwin": @parentstate = Puppet::NameService::NetInfo::NetInfoState @parentmodule = Puppet::NameService::NetInfo + when "FreeBSD": + @parentstate = Puppet::NameService::PW::PWUser + @parentmodule = Puppet::NameService::PW else @parentstate = Puppet::NameService::ObjectAdd::ObjectAddUser @parentmodule = Puppet::NameService::ObjectAdd diff --git a/test/types/user.rb b/test/types/user.rb index 6a7767054..81be56788 100755 --- a/test/types/user.rb +++ b/test/types/user.rb @@ -365,6 +365,9 @@ class TestUser < Test::Unit::TestCase Puppet.err "Not testing attr %s of user" % test end } + + user[:ensure] = :absent + assert_apply(user) end def test_autorequire |