83: def set_selinux_context(file, value, component = false)
84: return nil unless selinux_support? && selinux_label_support?(file)
85:
86: if component
87:
88: context = Selinux.lgetfilecon(file)[1]
89: if context == -1
90:
91:
92:
93: Puppet.warning "Can't set SELinux context on file unless the file already has some kind of context"
94: return nil
95: end
96: context = context.split(':')
97: case component
98: when :seluser
99: context[0] = value
100: when :selrole
101: context[1] = value
102: when :seltype
103: context[2] = value
104: when :selrange
105: context[3] = value
106: else
107: raise ArguementError, "set_selinux_context component must be one of :seluser, :selrole, :seltype, or :selrange"
108: end
109: context = context.join(':')
110: else
111: context = value
112: end
113:
114: retval = Selinux.lsetfilecon(file, context)
115: if retval == 0
116: return true
117: else
118: Puppet.warning "Failed to set SELinux context #{context} on #{file}"
119: return false
120: end
121: end