lib9p

Go 9P library.
Log | Files | Refs | LICENSE

uid.go (830B)


      1 //go:build unix || windows
      2 
      3 package diskfs
      4 
      5 import (
      6 	"os/user"
      7 )
      8 
      9 // assume that the group leader has the same name as uid
     10 func isGroupLeader(group, uid string) bool {
     11 	if group != uid {
     12 		return false
     13 	}
     14 	usr, err := user.Lookup(uid)
     15 	if err != nil {
     16 		return false
     17 	}
     18 	gids, err := usr.GroupIds()
     19 	if err != nil {
     20 		return false
     21 	}
     22 	grp, err := user.LookupGroup(group)
     23 	if err != nil {
     24 		return false
     25 	}
     26 	for _, gid := range gids {
     27 		if grp.Gid == gid {
     28 			return true
     29 		}
     30 	}
     31 	return false
     32 }
     33 
     34 func isGroupMember(group, uid string) bool {
     35 	usr, err := user.Lookup(uid)
     36 	if err != nil {
     37 		return false
     38 	}
     39 	gids, err := usr.GroupIds()
     40 	if err != nil {
     41 		return false
     42 	}
     43 	grp, err := user.LookupGroup(group)
     44 	if err != nil {
     45 		return false
     46 	}
     47 	for _, gid := range gids {
     48 		if grp.Gid == gid {
     49 			return true
     50 		}
     51 	}
     52 	return false
     53 }