93: def set_selinux_context(file, value, component = false)
94: unless selinux_support?
95: return nil
96: end
97:
98: if component
99:
100: context = Selinux.lgetfilecon(file)[1]
101: if context == -1
102:
103:
104:
105: Puppet.warning "Can't set SELinux context on file unless the file already has some kind of context"
106: return nil
107: end
108: context = context.split(':')
109: case component
110: when :seluser
111: context[0] = value
112: when :selrole
113: context[1] = value
114: when :seltype
115: context[2] = value
116: when :selrange
117: context[3] = value
118: else
119: raise ArguementError, "set_selinux_context component must be one of :seluser, :selrole, :seltype, or :selrange"
120: end
121: context = context.join(':')
122: else
123: context = value
124: end
125:
126: retval = Selinux.lsetfilecon(file, context)
127: if retval == 0
128: return true
129: else
130: Puppet.warning "Failed to set SELinux context %s on %s" % [context, file]
131: return false
132: end
133: end