From d9b6cbb89fb165a26b42d5afc7655b1dff30f529 Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 16:06:26 +0000 Subject: [PATCH] Remove unreachable code reported by go vet --- cmd/grumble/client.go | 5 ++-- cmd/grumble/server.go | 11 ++++---- pkg/acl/acl.go | 4 +-- pkg/acl/group.go | 66 +++++++++++++++++++++---------------------- 4 files changed, 40 insertions(+), 46 deletions(-) diff --git a/cmd/grumble/client.go b/cmd/grumble/client.go index 8fb1650..3272414 100644 --- a/cmd/grumble/client.go +++ b/cmd/grumble/client.go @@ -392,10 +392,9 @@ func (client *Client) SendUDP(buf []byte) error { crypted := make([]byte, len(buf)+client.crypt.Overhead()) client.crypt.Encrypt(crypted, buf) return client.server.SendUDP(crypted, client.udpaddr) - } else { - return client.sendMessage(buf) } - panic("unreachable") + + return client.sendMessage(buf) } // Send a Message to the client. The Message in msg to the client's diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go index 8dc0f21..3638616 100644 --- a/cmd/grumble/server.go +++ b/cmd/grumble/server.go @@ -869,13 +869,12 @@ func (server *Server) sendClientPermissions(client *Client, channel *Channel) { } // fixme(mkrautz): re-add when we have ACL caching - return - perm := acl.Permission(acl.NonePermission) - client.sendMessage(&mumbleproto.PermissionQuery{ - ChannelId: proto.Uint32(uint32(channel.Id)), - Permissions: proto.Uint32(uint32(perm)), - }) + // perm := acl.Permission(acl.NonePermission) + // client.sendMessage(&mumbleproto.PermissionQuery{ + // ChannelId: proto.Uint32(uint32(channel.Id)), + // Permissions: proto.Uint32(uint32(perm)), + // }) } type ClientPredicate func(client *Client) bool diff --git a/pkg/acl/acl.go b/pkg/acl/acl.go index 68e0601..867a304 100644 --- a/pkg/acl/acl.go +++ b/pkg/acl/acl.go @@ -161,9 +161,7 @@ func HasPermission(ctx *Context, user User, perm Permission) bool { // permissions exccept SpeakPermission and WhisperPermission. if perm != SpeakPermission && perm != WhisperPermission { return (granted & (perm | WritePermission)) != NonePermission - } else { - return (granted & perm) != NonePermission } - return false + return (granted & perm) != NonePermission } diff --git a/pkg/acl/group.go b/pkg/acl/group.go index c533668..55d5050 100644 --- a/pkg/acl/group.go +++ b/pkg/acl/group.go @@ -298,42 +298,40 @@ func GroupMemberCheck(current *Context, acl *Context, name string, user User) (o pdepth := len(userChain) - 1 return pdepth >= mindepth && pdepth <= maxdepth - } else { - // Non-magic groups - groups := []Group{} - - iter := channel - for iter != nil { - if group, ok := iter.Groups[name]; ok { - // Skip non-inheritable groups if we're in parents - // of our evaluated context. - if iter != channel && !group.Inheritable { - break - } - // Prepend group - groups = append([]Group{group}, groups...) - // If this group does not inherit from groups in its ancestors, stop looking - // for more ancestor groups. - if !group.Inherit { - break - } - } - iter = iter.Parent - } - - isMember := false - for _, group := range groups { - if group.AddContains(user.UserId()) || group.TemporaryContains(user.UserId()) || group.TemporaryContains(-int(user.Session())) { - isMember = true - } - if group.RemoveContains(user.UserId()) { - isMember = false - } - } - return isMember } - return false + // Non-magic groups + groups := []Group{} + + iter := channel + for iter != nil { + if group, ok := iter.Groups[name]; ok { + // Skip non-inheritable groups if we're in parents + // of our evaluated context. + if iter != channel && !group.Inheritable { + break + } + // Prepend group + groups = append([]Group{group}, groups...) + // If this group does not inherit from groups in its ancestors, stop looking + // for more ancestor groups. + if !group.Inherit { + break + } + } + iter = iter.Parent + } + + isMember := false + for _, group := range groups { + if group.AddContains(user.UserId()) || group.TemporaryContains(user.UserId()) || group.TemporaryContains(-int(user.Session())) { + isMember = true + } + if group.RemoveContains(user.UserId()) { + isMember = false + } + } + return isMember } // GroupNames gets the list of group names for the given ACL context.