fix(shutdown): Fix shutdown command

This commit is contained in:
Björn Benouarets
2025-11-11 20:38:49 +01:00
parent 8ed56f7ba0
commit b8964d7763
4 changed files with 115 additions and 21 deletions

View File

@@ -60,25 +60,52 @@ func ExtractAuthFromPacket(data []byte) (string, string, []byte, bool) {
return "", "", nil, false
}
// Extract authentication part
authEnd := strings.Index(dataStr[len(AuthPrefix):], ":")
if authEnd == -1 {
// Find the first colon after "AUTH:" (end of username)
searchStart := len(AuthPrefix)
firstColon := strings.Index(dataStr[searchStart:], ":")
if firstColon == -1 {
return "", "", nil, false
}
authEnd += len(AuthPrefix)
firstColon += searchStart
// Find the second colon after the first one (end of password)
secondColon := strings.Index(dataStr[firstColon+1:], ":")
if secondColon == -1 {
// If no second colon, the password might be followed directly by binary data
// In this case, we need to find where the magic packet starts (6 bytes of 0xFF)
// Look for the magic packet header starting after the password
passwordEnd := len(dataStr)
for i := firstColon + 1; i < len(data) && i < firstColon+100; i++ {
// Check if we found the magic packet header (6 consecutive 0xFF bytes)
if i+5 < len(data) {
allFF := true
for j := 0; j < 6; j++ {
if data[i+j] != 0xFF {
allFF = false
break
}
}
if allFF {
passwordEnd = i
break
}
}
}
username := dataStr[searchStart:firstColon]
password := dataStr[firstColon+1 : passwordEnd]
magicPacketData := data[passwordEnd:]
return username, password, magicPacketData, true
}
secondColon += firstColon + 1
// Extract username and password
authPart := dataStr[len(AuthPrefix):authEnd]
parts := strings.Split(authPart, ":")
if len(parts) != 2 {
return "", "", nil, false
}
username := parts[0]
password := parts[1]
username := dataStr[searchStart:firstColon]
password := dataStr[firstColon+1 : secondColon]
// Extract magic packet part (after "AUTH:username:password:")
magicPacketStart := authEnd + 1
magicPacketStart := secondColon + 1
if magicPacketStart >= len(data) {
return "", "", nil, false
}