github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/helper/users/lookup.go (about)

     1  package users
     2  
     3  import (
     4  	"os/user"
     5  	"sync"
     6  )
     7  
     8  // lock is used to serialize all user lookup at the process level, because
     9  // some NSS implementations are not concurrency safe
    10  var lock sync.Mutex
    11  
    12  // Lookup username while holding a global process lock.
    13  func Lookup(username string) (*user.User, error) {
    14  	lock.Lock()
    15  	defer lock.Unlock()
    16  	return user.Lookup(username)
    17  }
    18  
    19  // LookupGroupId while holding a global process lock.
    20  func LookupGroupId(gid string) (*user.Group, error) {
    21  	lock.Lock()
    22  	defer lock.Unlock()
    23  	return user.LookupGroupId(gid)
    24  }
    25  
    26  // Current returns the current user, acquired while holding a global process
    27  // lock.
    28  func Current() (*user.User, error) {
    29  	lock.Lock()
    30  	defer lock.Unlock()
    31  	return user.Current()
    32  }