github.com/apptainer/singularity@v3.1.1+incompatible/internal/pkg/util/priv/priv.go (about)

     1  // Copyright (c) 2018, Sylabs Inc. All rights reserved.
     2  // This software is licensed under a 3-clause BSD license. Please consult the
     3  // LICENSE.md file distributed with the sources of this project regarding your
     4  // rights to use or distribute this software.
     5  
     6  package priv
     7  
     8  import (
     9  	"os"
    10  	"syscall"
    11  )
    12  
    13  // Escalate escalates thread privileges
    14  func Escalate() error {
    15  	uid := os.Getuid()
    16  	return syscall.Setresuid(uid, 0, uid)
    17  }
    18  
    19  // Drop drops thread privileges
    20  func Drop() error {
    21  	uid := os.Getuid()
    22  	return syscall.Setresuid(uid, uid, 0)
    23  }