mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-13 17:22:08 -04:00
greeter: Add support for Debian greetd user/group name (#1685)
* greeter: Detect user and group used by greetd On most distros greetd runs as user and group "greeter", but on Debian the user and group "_greetd" are used. * greeter: Use correct group in sync command * greeter: more generic group detection --------- Co-authored-by: bbedward <bbedward@gmail.com>
This commit is contained in:
committed by
GitHub
parent
f2a6d2c7da
commit
81bce74612
37
core/internal/utils/group.go
Normal file
37
core/internal/utils/group.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func HasGroup(groupName string) bool {
|
||||
return HasGroupIn(groupName, "/etc/group")
|
||||
}
|
||||
|
||||
func HasGroupIn(groupName, path string) bool {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return HasGroupData(groupName, string(data))
|
||||
}
|
||||
|
||||
func HasGroupData(groupName, data string) bool {
|
||||
prefix := groupName + ":"
|
||||
for line := range strings.SplitSeq(data, "\n") {
|
||||
if strings.HasPrefix(line, prefix) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func FindGroupData(data string, candidates ...string) (string, bool) {
|
||||
for _, candidate := range candidates {
|
||||
if HasGroupData(candidate, data) {
|
||||
return candidate, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
Reference in New Issue
Block a user