Skip to content

Commit 94611c2

Browse files
committed
feat: use deepin-immutable-ctrl to wrap and call locale-gen
Avoiding permission issues caused by immutable systems Log: use `deepin-immutable-ctrl` to wrap and call `locale-gen`
1 parent 9cffdd8 commit 94611c2

2 files changed

Lines changed: 40 additions & 10 deletions

File tree

locale-helper/main.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ import (
1111

1212
"github.com/linuxdeepin/go-lib/dbusutil"
1313
"github.com/linuxdeepin/go-lib/log"
14+
dutils "github.com/linuxdeepin/go-lib/utils"
1415
)
1516

1617
//go:generate dbusutil-gen em -type Helper
1718

1819
const (
19-
dbusServiceName = "org.deepin.dde.LocaleHelper1"
20-
dbusPath = "/org/deepin/dde/LocaleHelper1"
21-
dbusInterface = dbusServiceName
22-
localeGenBin = "/usr/sbin/locale-gen"
20+
dbusServiceName = "org.deepin.dde.LocaleHelper1"
21+
dbusPath = "/org/deepin/dde/LocaleHelper1"
22+
dbusInterface = dbusServiceName
23+
localeGenBin = "/usr/sbin/locale-gen"
24+
deepinImmutableCtlBin = "/usr/sbin/deepin-immutable-ctl"
2325
)
2426

2527
type Helper struct {
@@ -90,10 +92,32 @@ func (h *Helper) canQuit() bool {
9092
}
9193

9294
func (h *Helper) doGenLocale() error {
93-
return exec.Command(localeGenBin).Run()
95+
if !dutils.IsFileExist(deepinImmutableCtlBin) {
96+
logger.Warning("deepin-immutable-ctl not found, use locale-gen directly")
97+
return exec.Command(localeGenBin).Run()
98+
} else {
99+
// TODO 在磐石适配 locale-gen 前使用 deepin-immutable-ctl 执行 locale-gen,否则有权限问题
100+
output, err := exec.Command(deepinImmutableCtlBin, "admin", "exec", localeGenBin).CombinedOutput()
101+
if err != nil {
102+
logger.Warning("deepin-immutable-ctl exec locale-gen failed, err:", err, "output:", string(output))
103+
return err
104+
}
105+
return nil
106+
}
94107
}
95108

96109
// locales version <= 2.13
97110
func (h *Helper) doGenLocaleWithParam(locale string) error {
98-
return exec.Command(localeGenBin, locale).Run()
111+
if !dutils.IsFileExist(deepinImmutableCtlBin) {
112+
logger.Warning("deepin-immutable-ctl not found, use locale-gen directly")
113+
return exec.Command(localeGenBin, locale).Run()
114+
} else {
115+
// TODO 在磐石适配 locale-gen 前使用 deepin-immutable-ctl 执行 locale-gen,否则有权限问题
116+
output, err := exec.Command(deepinImmutableCtlBin, "admin", "exec", "--", localeGenBin, locale).CombinedOutput()
117+
if err != nil {
118+
logger.Warning("deepin-immutable-ctl exec locale-gen failed, err:", err, "output:", string(output))
119+
return err
120+
}
121+
return nil
122+
}
99123
}

misc/systemd/system/deepin-locale-helper.service

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ ExecStart=/usr/lib/deepin-api/locale-helper
1212

1313
ReadWritePaths=/etc/default/locale
1414
ReadWritePaths=/etc/locale.gen
15-
ReadWritePaths=/usr/lib/locale/
16-
ExecPaths=/usr/sbin/locale-gen
15+
16+
# Temporary workaround: ReadWritePaths conflicts with deepin-immutable-ctl
17+
# TODO: Remove this comment when immutable system wraps locale-gen properly
18+
# ReadWritePaths=/usr/lib/locale/
1719

1820
DevicePolicy=closed
1921

20-
ProtectSystem=full
22+
ProtectSystem=strict
2123
ProtectHome=yes
2224
PrivateTmp=yes
2325
PrivateDevices=yes
@@ -29,7 +31,11 @@ ProtectKernelModules=yes
2931
ProtectKernelLogs=yes
3032
ProtectControlGroups=yes
3133
RestrictAddressFamilies=AF_UNIX
32-
RestrictNamespaces=yes
34+
35+
# Need to call /usr/sbin/deepin-immutable-ctl command
36+
# TODO: Remove this comment when immutable system wraps locale-gen properly
37+
# RestrictNamespaces=yes
38+
3339
LockPersonality=yes
3440
RestrictRealtime=yes
3541
RestrictSUIDSGID=yes

0 commit comments

Comments
 (0)