Skip to content

Commit a60010b

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 a60010b

2 files changed

Lines changed: 35 additions & 9 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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ ExecStart=/usr/lib/deepin-api/locale-helper
1313
ReadWritePaths=/etc/default/locale
1414
ReadWritePaths=/etc/locale.gen
1515
ReadWritePaths=/usr/lib/locale/
16-
ExecPaths=/usr/sbin/locale-gen
1716

1817
DevicePolicy=closed
1918

20-
ProtectSystem=full
19+
ProtectSystem=strict
2120
ProtectHome=yes
2221
PrivateTmp=yes
2322
PrivateDevices=yes
@@ -29,7 +28,10 @@ ProtectKernelModules=yes
2928
ProtectKernelLogs=yes
3029
ProtectControlGroups=yes
3130
RestrictAddressFamilies=AF_UNIX
32-
RestrictNamespaces=yes
31+
32+
# Need to call /usr/sbin/deepin-immutable-ctl command
33+
# RestrictNamespaces=yes
34+
3335
LockPersonality=yes
3436
RestrictRealtime=yes
3537
RestrictSUIDSGID=yes

0 commit comments

Comments
 (0)