forked from External/grumble
Fix protobuf enum types.
This commit is contained in:
parent
0161969df1
commit
92e6ac5276
3 changed files with 39 additions and 43 deletions
24
client.go
24
client.go
|
|
@ -181,14 +181,14 @@ func (client *Client) ForceDisconnect() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reject an authentication attempt
|
// Reject an authentication attempt
|
||||||
func (client *Client) RejectAuth(kind, reason string) {
|
func (client *Client) RejectAuth(rejectType mumbleproto.Reject_RejectType, reason string) {
|
||||||
var reasonString *string = nil
|
var reasonString *string = nil
|
||||||
if len(reason) > 0 {
|
if len(reason) > 0 {
|
||||||
reasonString = proto.String(reason)
|
reasonString = proto.String(reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
client.sendProtoMessage(&mumbleproto.Reject{
|
client.sendProtoMessage(&mumbleproto.Reject{
|
||||||
Type: mumbleproto.NewReject_RejectType(mumbleproto.Reject_RejectType_value[kind]),
|
Type: mumbleproto.NewReject_RejectType(rejectType),
|
||||||
Reason: reasonString,
|
Reason: reasonString,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -245,16 +245,15 @@ func (c *Client) sendProtoMessage(msg interface{}) (err os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send permission denied by type
|
// Send permission denied by type
|
||||||
func (c *Client) sendPermissionDeniedType(kind string) {
|
func (c *Client) sendPermissionDeniedType(denyType mumbleproto.PermissionDenied_DenyType) {
|
||||||
c.sendPermissionDeniedTypeUser(kind, nil)
|
c.sendPermissionDeniedTypeUser(denyType, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send permission denied by type (and user)
|
// Send permission denied by type (and user)
|
||||||
func (c *Client) sendPermissionDeniedTypeUser(kind string, user *Client) {
|
func (c *Client) sendPermissionDeniedTypeUser(denyType mumbleproto.PermissionDenied_DenyType, user *Client) {
|
||||||
val, ok := mumbleproto.PermissionDenied_DenyType_value[kind]
|
pd := &mumbleproto.PermissionDenied{
|
||||||
if ok {
|
Type: mumbleproto.NewPermissionDenied_DenyType(denyType),
|
||||||
pd := &mumbleproto.PermissionDenied{}
|
}
|
||||||
pd.Type = mumbleproto.NewPermissionDenied_DenyType(val)
|
|
||||||
if user != nil {
|
if user != nil {
|
||||||
pd.Session = proto.Uint32(uint32(user.Session))
|
pd.Session = proto.Uint32(uint32(user.Session))
|
||||||
}
|
}
|
||||||
|
|
@ -267,9 +266,6 @@ func (c *Client) sendPermissionDeniedTypeUser(kind string, user *Client) {
|
||||||
buf: d,
|
buf: d,
|
||||||
kind: mumbleproto.MessagePermissionDenied,
|
kind: mumbleproto.MessagePermissionDenied,
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
c.Panicf("Unknown permission denied type.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send permission denied by who, what, where
|
// Send permission denied by who, what, where
|
||||||
|
|
@ -290,9 +286,9 @@ func (c *Client) sendPermissionDenied(who *Client, where *Channel, what Permissi
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send permission denied fallback
|
// Send permission denied fallback
|
||||||
func (c *Client) sendPermissionDeniedFallback(kind string, version uint32, text string) {
|
func (c *Client) sendPermissionDeniedFallback(denyType mumbleproto.PermissionDenied_DenyType, version uint32, text string) {
|
||||||
// fixme(mkrautz): Do fallback kind of stuff...
|
// fixme(mkrautz): Do fallback kind of stuff...
|
||||||
c.sendPermissionDeniedType(kind)
|
c.sendPermissionDeniedType(denyType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UDP receiver.
|
// UDP receiver.
|
||||||
|
|
|
||||||
24
message.go
24
message.go
|
|
@ -196,7 +196,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) {
|
||||||
if chanstate.Description != nil {
|
if chanstate.Description != nil {
|
||||||
description, err = server.FilterText(*chanstate.Description)
|
description, err = server.FilterText(*chanstate.Description)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.sendPermissionDeniedType("TextTooLong")
|
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TextTooLong)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -221,7 +221,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) {
|
||||||
}
|
}
|
||||||
for _, iter := range evalp.children {
|
for _, iter := range evalp.children {
|
||||||
if iter.Name == name {
|
if iter.Name == name {
|
||||||
client.sendPermissionDeniedType("ChannelName")
|
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_ChannelName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -248,13 +248,13 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) {
|
||||||
|
|
||||||
// Only registered users can create channels.
|
// Only registered users can create channels.
|
||||||
if !client.IsRegistered() && !client.HasCertificate() {
|
if !client.IsRegistered() && !client.HasCertificate() {
|
||||||
client.sendPermissionDeniedTypeUser("MissingCertificate", client)
|
client.sendPermissionDeniedTypeUser(mumbleproto.PermissionDenied_MissingCertificate, client)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can't add channels to a temporary channel
|
// We can't add channels to a temporary channel
|
||||||
if parent.Temporary {
|
if parent.Temporary {
|
||||||
client.sendPermissionDeniedType("TemporaryChannel")
|
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TemporaryChannel)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -372,7 +372,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) {
|
||||||
|
|
||||||
// A temporary channel must not have any subchannels, so deny it.
|
// A temporary channel must not have any subchannels, so deny it.
|
||||||
if parent.Temporary {
|
if parent.Temporary {
|
||||||
client.sendPermissionDeniedType("TemporaryChannel")
|
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TemporaryChannel)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -391,7 +391,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) {
|
||||||
// If a sibling of parent already has this name, don't allow it.
|
// If a sibling of parent already has this name, don't allow it.
|
||||||
for _, iter := range parent.children {
|
for _, iter := range parent.children {
|
||||||
if iter.Name == channel.Name {
|
if iter.Name == channel.Name {
|
||||||
client.sendPermissionDeniedType("ChannelName")
|
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_ChannelName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -604,7 +604,7 @@ func (server *Server) handleUserStateMessage(client *Client, msg *Message) {
|
||||||
if userstate.Mute != nil || userstate.Deaf != nil || userstate.Suppress != nil || userstate.PrioritySpeaker != nil {
|
if userstate.Mute != nil || userstate.Deaf != nil || userstate.Suppress != nil || userstate.PrioritySpeaker != nil {
|
||||||
// Disallow for SuperUser
|
// Disallow for SuperUser
|
||||||
if target.IsSuperUser() {
|
if target.IsSuperUser() {
|
||||||
client.sendPermissionDeniedType("SuperUser")
|
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_SuperUser)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -636,14 +636,14 @@ func (server *Server) handleUserStateMessage(client *Client, msg *Message) {
|
||||||
|
|
||||||
// Only allow empty text.
|
// Only allow empty text.
|
||||||
if len(comment) > 0 {
|
if len(comment) > 0 {
|
||||||
client.sendPermissionDeniedType("TextTooLong")
|
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TextTooLong)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
filtered, err := server.FilterText(comment)
|
filtered, err := server.FilterText(comment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.sendPermissionDeniedType("TextTooLong")
|
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TextTooLong)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -654,7 +654,7 @@ func (server *Server) handleUserStateMessage(client *Client, msg *Message) {
|
||||||
if userstate.Texture != nil {
|
if userstate.Texture != nil {
|
||||||
maximg := server.cfg.IntValue("MaxImageMessageLength")
|
maximg := server.cfg.IntValue("MaxImageMessageLength")
|
||||||
if maximg > 0 && len(userstate.Texture) > maximg {
|
if maximg > 0 && len(userstate.Texture) > maximg {
|
||||||
client.sendPermissionDeniedType("TextTooLong")
|
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TextTooLong)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -674,7 +674,7 @@ func (server *Server) handleUserStateMessage(client *Client, msg *Message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(target.CertHash) == 0 {
|
if len(target.CertHash) == 0 {
|
||||||
client.sendPermissionDeniedTypeUser("MissingCertificate", target)
|
client.sendPermissionDeniedTypeUser(mumbleproto.PermissionDenied_MissingCertificate, target)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -961,7 +961,7 @@ func (server *Server) handleTextMessage(client *Client, msg *Message) {
|
||||||
|
|
||||||
filtered, err := server.FilterText(*txtmsg.Message)
|
filtered, err := server.FilterText(*txtmsg.Message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.sendPermissionDeniedType("TextTooLong")
|
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TextTooLong)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
12
server.go
12
server.go
|
|
@ -427,7 +427,7 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) {
|
||||||
|
|
||||||
// Did we get a username?
|
// Did we get a username?
|
||||||
if auth.Username == nil || len(*auth.Username) == 0 {
|
if auth.Username == nil || len(*auth.Username) == 0 {
|
||||||
client.RejectAuth("InvalidUsername", "Please specify a username to log in")
|
client.RejectAuth(mumbleproto.Reject_InvalidUsername, "Please specify a username to log in")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -449,17 +449,17 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) {
|
||||||
|
|
||||||
if client.Username == "SuperUser" {
|
if client.Username == "SuperUser" {
|
||||||
if auth.Password == nil {
|
if auth.Password == nil {
|
||||||
client.RejectAuth("WrongUserPW", "")
|
client.RejectAuth(mumbleproto.Reject_WrongUserPW, "")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
if server.CheckSuperUserPassword(*auth.Password) {
|
if server.CheckSuperUserPassword(*auth.Password) {
|
||||||
client.user, ok = server.UserNameMap[client.Username]
|
client.user, ok = server.UserNameMap[client.Username]
|
||||||
if !ok {
|
if !ok {
|
||||||
client.RejectAuth("InvalidUsername", "")
|
client.RejectAuth(mumbleproto.Reject_InvalidUsername, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
client.RejectAuth("WrongUserPW", "")
|
client.RejectAuth(mumbleproto.Reject_WrongUserPW, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -470,7 +470,7 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) {
|
||||||
if len(client.CertHash) > 0 && user.CertHash == client.CertHash {
|
if len(client.CertHash) > 0 && user.CertHash == client.CertHash {
|
||||||
client.user = user
|
client.user = user
|
||||||
} else {
|
} else {
|
||||||
client.RejectAuth("WrongUserPW", "Wrong certificate hash")
|
client.RejectAuth(mumbleproto.Reject_WrongUserPW, "Wrong certificate hash")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -538,7 +538,7 @@ func (server *Server) finishAuthenticate(client *Client) {
|
||||||
// The user is already present on the server.
|
// The user is already present on the server.
|
||||||
if found {
|
if found {
|
||||||
// todo(mkrautz): Do the address checking.
|
// todo(mkrautz): Do the address checking.
|
||||||
client.RejectAuth("UsernameInUse", "A client is already connected using those credentials.")
|
client.RejectAuth(mumbleproto.Reject_UsernameInUse, "A client is already connected using those credentials.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue