-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change notification settings only for members of the NordVPN group
- Loading branch information
1 parent
a70aae6
commit f64e535
Showing
4 changed files
with
51 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
"os/user" | ||
) | ||
|
||
var allowedGroups []string = []string{"nordvpn"} | ||
var ErrNoPermission error = fmt.Errorf("requesting user does not have permissions") | ||
|
||
// IsInAllowedGroup returns true if user with the given UID is in nordvpn privileged group | ||
func IsInAllowedGroup(uid uint32) (bool, error) { | ||
userInfo, err := user.LookupId(fmt.Sprintf("%d", uid)) | ||
if err != nil { | ||
return false, fmt.Errorf("authenticate user, lookup user info: %s", err) | ||
} | ||
// user belongs to the allowed group? | ||
groups, err := userInfo.GroupIds() | ||
if err != nil { | ||
return false, fmt.Errorf("authenticate user, check user groups: %s", err) | ||
} | ||
|
||
for _, groupId := range groups { | ||
groupInfo, err := user.LookupGroupId(groupId) | ||
if err != nil { | ||
return false, fmt.Errorf("authenticate user, check user group: %s", err) | ||
} | ||
for _, allowGroupName := range allowedGroups { | ||
if groupInfo.Name == allowGroupName { | ||
return true, nil | ||
} | ||
} | ||
} | ||
|
||
return false, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters