Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/grumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOla Bini <ola@autonomia.digital>2020-03-26 18:00:08 +0300
committerOla Bini <ola@autonomia.digital>2020-03-26 18:00:08 +0300
commitdd9b5531a3dc4ee55b7bff86ec924e56ec573be5 (patch)
tree29d4f70e4c3ed197736e79d3c3d10e8327f34007
parenta6dc45193af2512a7d51919708ad27e2c4f81236 (diff)
Extract more generic versions of setting and checking configuration passwords
-rw-r--r--cmd/grumble/server.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go
index 64b4dd8..bca43aa 100644
--- a/cmd/grumble/server.go
+++ b/cmd/grumble/server.go
@@ -175,8 +175,7 @@ func (server *Server) RootChannel() *Channel {
return root
}
-// Set password as the new SuperUser password
-func (server *Server) SetSuperUserPassword(password string) {
+func (server *Server) setConfigPassword(key, password string) {
saltBytes := make([]byte, 24)
_, err := rand.Read(saltBytes)
if err != nil {
@@ -190,7 +189,6 @@ func (server *Server) SetSuperUserPassword(password string) {
digest := hex.EncodeToString(hasher.Sum(nil))
// Could be racy, but shouldn't really matter...
- key := "SuperUserPassword"
val := "sha1$" + salt + "$" + digest
server.cfg.Set(key, val)
@@ -199,9 +197,13 @@ func (server *Server) SetSuperUserPassword(password string) {
}
}
-// CheckSuperUserPassword checks whether password matches the set SuperUser password.
-func (server *Server) CheckSuperUserPassword(password string) bool {
- parts := strings.Split(server.cfg.StringValue("SuperUserPassword"), "$")
+// Set password as the new SuperUser password
+func (server *Server) SetSuperUserPassword(password string) {
+ server.setConfigPassword("SuperUserPassword", password)
+}
+
+func (server *Server) checkConfigPassword(key, password string) bool {
+ parts := strings.Split(server.cfg.StringValue(key), "$")
if len(parts) != 3 {
return false
}
@@ -239,6 +241,11 @@ func (server *Server) CheckSuperUserPassword(password string) bool {
return false
}
+// CheckSuperUserPassword checks whether password matches the set SuperUser password.
+func (server *Server) CheckSuperUserPassword(password string) bool {
+ return server.checkConfigPassword("SuperUserPassword", password)
+}
+
// Called by the server to initiate a new client connection.
func (server *Server) handleIncomingClient(conn net.Conn) (err error) {
client := new(Client)