Fix security check message

This commit is contained in:
世界
2026-08-30 17:41:44 +08:00
parent 086e0b87cf
commit b2f1f630d9
12 changed files with 50 additions and 30 deletions
+2 -2
View File
@@ -23,7 +23,7 @@ type applicationService struct {
}
func (s *applicationService) CheckConfig(ctx context.Context, request *ConfigContent) (*emptypb.Empty, error) {
err := s.startedService.CheckConfig(request.Content)
err := s.startedService.CheckConfig(ctx, request.Content)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
@@ -31,7 +31,7 @@ func (s *applicationService) CheckConfig(ctx context.Context, request *ConfigCon
}
func (s *applicationService) FormatConfig(ctx context.Context, request *ConfigContent) (*ConfigContent, error) {
content, err := s.startedService.FormatConfig(request.Content)
content, err := s.startedService.FormatConfig(ctx, request.Content)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
+1 -1
View File
@@ -87,7 +87,7 @@ func (s *desktopService) StartService(ctx context.Context, request *StartService
mergedOptions.OOMKillerDisabled = request.Options.OomKillerDisabled
mergedOptions.OOMMemoryLimit = request.Options.OomMemoryLimit
}
err = s.daemon.startServiceLocked(identity.UserID, request.ConfigContent, mergedOptions)
err = s.daemon.startServiceLocked(ctx, identity.UserID, request.ConfigContent, mergedOptions)
if err != nil {
return nil, s.daemon.cleanFailedStartLocked(identity.UserID, mergedOptions, err)
}
@@ -3,6 +3,7 @@
package main
import (
"context"
"fmt"
"os"
"path/filepath"
@@ -12,19 +13,19 @@ import (
E "github.com/sagernet/sing/common/exceptions"
)
func insecureFeatureError(feature string) error {
return E.New(fmt.Sprintf(locale.Current().InsecureFeatureMessage, feature, insecureModePlatformName()))
func insecureFeatureError(ctx context.Context, feature string) error {
return E.New(fmt.Sprintf(locale.FromContext(ctx).InsecureFeatureMessage, feature, insecureModePlatformName()))
}
type daemonSecurityPolicy struct {
daemon *Daemon
}
func (p *daemonSecurityPolicy) CheckFeature(feature string) error {
func (p *daemonSecurityPolicy) CheckFeature(ctx context.Context, feature string) error {
if p.daemon.insecureModeEnabled() {
return nil
}
return insecureFeatureError(feature)
return insecureFeatureError(ctx, feature)
}
type restrictedFileManager struct {
+3 -2
View File
@@ -1,6 +1,7 @@
package main
import (
"context"
"os"
"github.com/sagernet/sing-box/daemon"
@@ -27,7 +28,7 @@ func (h *managedHandler) ServiceStop() error {
return h.daemon.stopServiceLocked(ownerUserID)
}
func (h *managedHandler) ServiceReload() error {
func (h *managedHandler) ServiceReload(ctx context.Context) error {
if h.daemon.closed {
return os.ErrClosed
}
@@ -43,7 +44,7 @@ func (h *managedHandler) ServiceReload() error {
if err != nil {
return err
}
err = h.daemon.startServiceLocked(ownerUserID, configContent, options)
err = h.daemon.startServiceLocked(ctx, ownerUserID, configContent, options)
if err != nil {
return err
}
+5 -3
View File
@@ -27,6 +27,7 @@ import (
)
type Daemon struct {
ctx context.Context
logger log.ContextLogger
startedService *daemon.StartedService
server *grpc.Server
@@ -41,6 +42,7 @@ type Daemon struct {
func newDaemon() (*Daemon, error) {
ctx := include.Context(context.Background())
d := &Daemon{
ctx: ctx,
logger: log.StdLogger(),
runtimeWorkingDirectory: workingDirectory,
}
@@ -164,7 +166,7 @@ func (d *Daemon) restore() {
return
}
d.logger.Info("restoring service")
err = d.startServiceLocked(ownerUserID, configContent, options)
err = d.startServiceLocked(d.ctx, ownerUserID, configContent, options)
if err != nil {
d.logger.Error("restore service: ", err)
}
@@ -196,7 +198,7 @@ func (d *Daemon) configureWorkingDirectoryLocked(directory string) error {
return nil
}
func (d *Daemon) startServiceLocked(ownerUserID string, configContent string, options startOptions) error {
func (d *Daemon) startServiceLocked(ctx context.Context, ownerUserID string, configContent string, options startOptions) error {
directory := userWorkingDirectory(ownerUserID)
err := d.configureWorkingDirectoryLocked(directory)
if err != nil {
@@ -216,7 +218,7 @@ func (d *Daemon) startServiceLocked(ownerUserID string, configContent string, op
return err
}
}
err = d.startedService.StartOrReloadService(configContent, nil)
err = d.startedService.StartOrReloadService(ctx, configContent, nil)
if err != nil && d.platform != nil {
return E.Errors(err, d.platform.ResetPlatformOptions())
}