@@ -23,20 +23,12 @@ import (
2323 "io/ioutil"
2424 "time"
2525
26+ "github.com/rmohr/bazeldnf/pkg/xattr"
2627 "github.com/sassoftware/go-rpmutils/cpio"
2728)
2829
29- const (
30- capabilities_header = "SCHILY.xattr.security.capability"
31- )
32-
33- var cap_empty_bitmask = []byte {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }
34- var supported_capabilities = map [string ][]byte {
35- "cap_net_bind_service" : {1 , 0 , 0 , 2 , 0 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
36- }
37-
3830// Extract the contents of a cpio stream from and writes it as a tar file into the provided writer
39- func Tar (rs io.Reader , tarfile * tar.Writer , noSymlinksAndDirs bool , capabilities map [string ][]string ) error {
31+ func Tar (rs io.Reader , tarfile * tar.Writer , noSymlinksAndDirs bool , capabilities map [string ][]string , selinuxLabels map [ string ] string ) error {
4032 hardLinks := map [int ][]* tar.Header {}
4133 inodes := map [int ]string {}
4234
@@ -54,18 +46,13 @@ func Tar(rs io.Reader, tarfile *tar.Writer, noSymlinksAndDirs bool, capabilities
5446
5547 pax := map [string ]string {}
5648 if caps , exists := capabilities [entry .Header .Filename ()]; exists {
57- for _ , cap := range caps {
58- if _ , supported := supported_capabilities [cap ]; ! supported {
59- return fmt .Errorf ("Requested capability '%s' for file '%s' is not supported" , cap , entry .Header .Filename ())
60- }
61- if _ , exists := pax [capabilities_header ]; ! exists {
62- pax [capabilities_header ] = string (cap_empty_bitmask )
63- }
64- val := []byte (pax [capabilities_header ])
65- for i , b := range supported_capabilities [cap ] {
66- val [i ] = val [i ] | b
67- }
68- pax [capabilities_header ] = string (val )
49+ if err := xattr .AddCapabilities (pax , caps ); err != nil {
50+ return fmt .Errorf ("failed setting capabilities on %s: %v" , entry .Header .Filename (), err )
51+ }
52+ }
53+ if label , exists := selinuxLabels [entry .Header .Filename ()]; exists {
54+ if err := xattr .SetSELinuxLabel (pax , label ); err != nil {
55+ return fmt .Errorf ("failed setting selinux label on %s: %v" , entry .Header .Filename (), err )
6956 }
7057 }
7158
0 commit comments