Skip to content

Commit

Permalink
Fix norduser user group detection
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszWojciechO authored and Savolro committed May 10, 2024
1 parent cad9517 commit 6e02ef8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 7 additions & 7 deletions norduser/group_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ func getUID(username string) (userIDs, error) {
func (n *NordvpnGroupMonitor) handleGroupUpdate(currentGroupMembers userSet, newGroupMembers userSet) {
for member := range currentGroupMembers {
// member not modified, do nothing
if ok := newGroupMembers[member]; ok {
if _, ok := newGroupMembers[member]; ok {
newGroupMembers[member] = true
continue
}

userIDs, err := getUID(member)
if err != nil {
log.Println("failed to look up UID/GID of deleted group member:", err)
log.Println("failed to look up UID/GID of deleted group member: ", err)
continue
}

Expand Down Expand Up @@ -144,6 +144,8 @@ func (n *NordvpnGroupMonitor) handleGroupUpdate(currentGroupMembers userSet, new
if err := n.norduserd.Enable(userID.uid, userID.gid, userID.home); err != nil {
log.Println("enabling norduserd for member:", err)
}

newGroupMembers[member] = true
}
}

Expand All @@ -158,6 +160,8 @@ func (n *NordvpnGroupMonitor) startForEveryGroupMember(groupMembers userSet) {
if err := n.norduserd.Enable(user.uid, user.gid, user.home); err != nil {
log.Println("failed to start norduser for group member:", err)
}

groupMembers[member] = true
}
}

Expand Down Expand Up @@ -209,11 +213,7 @@ func (n *NordvpnGroupMonitor) Start() error {
newGroupMembers, err := getNordvpnGroupMembers()
if err == nil {
n.handleGroupUpdate(currentGrupMembers, newGroupMembers)
if err != nil {
log.Println("Failed to read new group members after groupfile has changed:", err)
} else {
currentGrupMembers = newGroupMembers
}
currentGrupMembers = newGroupMembers
} else {
log.Println("Failed to get new group members:", err)
}
Expand Down
10 changes: 10 additions & 0 deletions norduser/group_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ func Test_getGroupMembers(t *testing.T) {
groupEntry: "nordvpn:x:996:",
expectedResult: userSet{},
},
{
name: "group name starts with nordvpn",
groupEntry: "nordvpn_ddd:x:996:",
expectedResult: userSet{},
},
{
name: "group name starts with nordvpn",
groupEntry: "nordvpn:",
expectedResult: userSet{},
},
}

for _, test := range tests {
Expand Down

0 comments on commit 6e02ef8

Please sign in to comment.