summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/file/win32.rb
blob: da6db1e8cf567922d5c8405392c5b7056b0cd608 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Puppet::Type.type(:file).provide :microsoft_windows do
    desc "Uses Microsoft Windows functionality to manage file's users and rights."

    confine :feature => :microsoft_windows

    include Puppet::Util::Warnings

    require 'sys/admin' if Puppet.features.microsoft_windows?

    def id2name(id)
        return id.to_s if id.is_a?(Symbol)
        return nil if id > Puppet[:maximum_uid].to_i
        # should translate ID numbers to usernames
        return id
    end

    def insync?(current, should)
        return true unless should

        should.each do |value|
            if value =~ /^\d+$/
                uid = Integer(value)
            elsif value.is_a?(String)
                fail "Could not find user %s" % value unless uid = uid(value)
            else
                uid = value
            end

            return true if uid == current
        end

        unless Puppet.features.root?
            warnonce "Cannot manage ownership unless running as root"
            return true
        end

        return false
    end

    # Determine if the user is valid, and if so, return the UID
    def validuser?(value)
        info "Is '%s' a valid user?" % value
        return 0
        begin
            number = Integer(value)
            return number
        rescue ArgumentError
            number = nil
        end
        if number = uid(value)
            return number
        else
            return false
        end
    end

    def retrieve(resource)
        unless stat = resource.stat(false)
            return :absent
        end

        currentvalue = stat.uid

        # On OS X, files that are owned by -2 get returned as really
        # large UIDs instead of negative ones.  This isn't a Ruby bug,
        # it's an OS X bug, since it shows up in perl, too.
        if currentvalue > Puppet[:maximum_uid].to_i
            self.warning "Apparently using negative UID (%s) on a platform that does not consistently handle them" % currentvalue
            currentvalue = :silly
        end

        return currentvalue
    end

    def sync(path, links, should)
        info("should set '%s'%%owner to '%s'" % [path, should])
    end
end