Skip to content

Commit

Permalink
Add patch and modification notice
Browse files Browse the repository at this point in the history
  • Loading branch information
cclerget committed Oct 6, 2018
1 parent c95f76c commit 2814f49
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions image/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Modifications by: Sylabs Inc.
// Add u+w if we aren't root to allow extraction
//

package image

Expand Down Expand Up @@ -273,6 +277,13 @@ func unpackLayerEntry(dest string, header *tar.Header, reader io.Reader, entries
}
}

// SINGULARITY_PATCH
// Add u+w if we aren't root to allow extractions
extraPerms := os.FileMode(0000)
if os.Getuid() != 0 {
extraPerms = 0600
}

switch header.Typeflag {
case tar.TypeDir:
fi, err := os.Lstat(path)
Expand All @@ -284,14 +295,14 @@ func unpackLayerEntry(dest string, header *tar.Header, reader io.Reader, entries
if err != nil && !os.IsNotExist(err) {
return false, err
}
err = os.MkdirAll(path, info.Mode())
err = os.MkdirAll(path, info.Mode()|extraPerms)
if err != nil {
return false, err
}
}

case tar.TypeReg, tar.TypeRegA:
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, info.Mode())
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, info.Mode()|extraPerms)
if err != nil {
return false, errors.Wrap(err, "unable to open file")
}
Expand Down

0 comments on commit 2814f49

Please sign in to comment.