github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/cmds/core/fusermount/fusermount_linux.go (about) 1 // Copyright 2018-2019 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import "golang.org/x/sys/unix" 8 9 var fileSystemUID, fileSystemGID int 10 11 func dropPrivs() error { 12 uid := unix.Getuid() 13 if uid == 0 { 14 return nil 15 } 16 17 var err error 18 fileSystemUID, err = unix.SetfsuidRetUid(uid) 19 if err != nil { 20 return err 21 } 22 fileSystemGID, err = unix.SetfsgidRetGid(unix.Getgid()) 23 return err 24 } 25 26 func restorePrivs() { 27 if unix.Getuid() == 0 { 28 return 29 } 30 // We're exiting, if there's an error, not much to do. 31 unix.Setfsuid(fileSystemUID) 32 unix.Setfsgid(fileSystemGID) 33 } 34 35 func preMount() error { 36 // I guess this umask is the thing to do. 37 unix.Umask(0o33) 38 return nil 39 }