99 "crypto/sha256"
1010 "encoding/hex"
1111 "encoding/json"
12- "errors"
1312 "fmt"
1413 "io"
1514 "os"
@@ -23,16 +22,13 @@ import (
2322 "time"
2423 "unicode/utf8"
2524
26- "github.com/linuxdeepin/dde-api/polkit"
2725 utils2 "github.com/linuxdeepin/go-lib/utils"
2826 "github.com/linuxdeepin/lastore-daemon/src/internal/config"
2927 "github.com/linuxdeepin/lastore-daemon/src/internal/system"
3028 "github.com/linuxdeepin/lastore-daemon/src/internal/system/apt"
3129
3230 "github.com/godbus/dbus/v5"
33- "github.com/linuxdeepin/go-lib/dbusutil"
3431 "github.com/linuxdeepin/go-lib/procfs"
35- "github.com/linuxdeepin/go-lib/strv"
3632)
3733
3834var _urlReg = regexp .MustCompile (`^[ ]*deb .*((?:https?|ftp|file|p2p|delivery)://[^ ]+)` )
@@ -270,82 +266,6 @@ func parseAutoDownloadRange(idleDownloadConfig idleDownloadConfig, now time.Time
270266 return NewTimeRange (beginTime , endTime ), nil
271267}
272268
273- const (
274- appStoreDaemonPath = "/usr/bin/deepin-app-store-daemon"
275- oldAppStoreDaemonPath = "/usr/bin/deepin-appstore-daemon"
276- printerPath = "/usr/bin/dde-printer"
277- printerHelperPath = "/usr/bin/dde-printer-helper"
278- sessionDaemonPath = "/usr/lib/deepin-daemon/dde-session-daemon"
279- langSelectorPath = "/usr/lib/deepin-daemon/langselector"
280- controlCenterPath = "/usr/bin/dde-control-center"
281- controlCenterCmdLine = "/usr/share/applications/dde-control-center.deskto" // 缺个 p 是因为 deepin-turbo 修改命令的时候 buffer 不够用, 所以截断了.
282- oldControlCenterPath = "/usr/lib/x86_64-linux-gnu/dde-control-center/dde-control-center-old"
283- dataTransferPath = "/usr/bin/deepin-data-transfer"
284- amDaemonPath = "/usr/bin/dde-application-manager"
285- launcherPath = "/usr/bin/dde-launcher"
286- amDaemonCompatPath = "/usr/libexec/dde-application-wizard-daemon-compat"
287- )
288-
289- // TODO delete
290- var (
291- allowInstallPackageExecPaths = strv.Strv {
292- appStoreDaemonPath ,
293- oldAppStoreDaemonPath ,
294- printerPath ,
295- printerHelperPath ,
296- langSelectorPath ,
297- controlCenterPath ,
298- oldControlCenterPath ,
299- dataTransferPath ,
300- }
301- allowRemovePackageExecPaths = strv.Strv {
302- appStoreDaemonPath ,
303- oldAppStoreDaemonPath ,
304- sessionDaemonPath ,
305- langSelectorPath ,
306- controlCenterPath ,
307- oldControlCenterPath ,
308- amDaemonPath ,
309- launcherPath ,
310- amDaemonCompatPath ,
311- }
312- )
313-
314- // execPath和cmdLine可以有一个为空,其中一个存在即可作为判断调用者的依据
315- func getExecutablePathAndCmdline (service * dbusutil.Service , sender dbus.Sender ) (string , string , error ) {
316- pid , err := service .GetConnPID (string (sender ))
317- if err != nil {
318- return "" , "" , err
319- }
320-
321- proc := procfs .Process (pid )
322- execPath , err := proc .Exe ()
323- if err != nil {
324- // 当调用者在使用过程中发生了更新,则在获取该进程的exe时,会出现lstat xxx (deleted)此类的error,如果发生的是覆盖,则该路径依旧存在,因此增加以下判断
325- var pErr * os.PathError
326- ok := errors .As (err , & pErr )
327- if ok {
328- if os .IsNotExist (pErr .Err ) {
329- errExecPath := strings .Replace (pErr .Path , "(deleted)" , "" , - 1 )
330- oldExecPath := strings .TrimSpace (errExecPath )
331- if system .NormalFileExists (oldExecPath ) {
332- execPath = oldExecPath
333- err = nil
334- }
335- }
336- }
337- }
338-
339- cmdLine , err1 := proc .Cmdline ()
340- if err != nil && err1 != nil {
341- return "" , "" , errors .New (strings .Join ([]string {
342- err .Error (),
343- err1 .Error (),
344- }, ";" ))
345- }
346- return execPath , strings .Join (cmdLine , " " ), nil
347- }
348-
349269// 根据类型过滤数据
350270func getFilterPackages (infosMap map [string ][]string , updateType system.UpdateType ) []string {
351271 var r []string
@@ -556,62 +476,13 @@ func getCoreListOnline() []string {
556476 return pkgs
557477}
558478
559- var _initProcNsMnt string
560- var _once sync.Once
561-
562- // 通过判断/proc/pid/ns/mnt 和 /proc/1/ns/mnt是否相同,如果不相同,则进程exe字段不可信
563- func checkSenderNsMntValid (pid uint32 ) bool {
564- _once .Do (func () {
565- out , err := os .Readlink ("/proc/1/ns/mnt" )
566- if err != nil {
567- fmt .Println (err )
568- return
569- }
570- _initProcNsMnt = strings .TrimSpace (out )
571- })
572- c , err := os .Readlink (fmt .Sprintf ("/proc/%v/ns/mnt" , pid ))
573- if err != nil {
574- fmt .Println (err )
575- return false
576- }
577- defer func () {
578- fmt .Printf ("pid 1 mnt ns is %v,pid %v mnt ns is %v\n " , _initProcNsMnt , pid , strings .TrimSpace (c ))
579- }()
580- return strings .TrimSpace (c ) == _initProcNsMnt
581- }
582-
583479const (
584480 polkitActionChangeOwnData = "com.deepin.lastore.user-administration"
585481 polkitActionChangeUpgradeDelivery = "com.deepin.lastore.doUpgradeDelivery"
586482 polkitActionEnableUpgradeDelivery = "com.deepin.lastore.enableUpgradeDelivery"
587483 polkitActionDisableUpgradeDelivery = "com.deepin.lastore.disableUpgradeDelivery"
588484)
589485
590- func checkInvokePermission (service * dbusutil.Service , sender dbus.Sender ) error {
591- uid , err := service .GetConnUID (string (sender ))
592- if err != nil {
593- return fmt .Errorf ("failed to get sender conn uid:%v" , err )
594- }
595- if uid != 0 {
596- execPath , cmdLine , err := getExecutablePathAndCmdline (service , sender )
597- if err != nil {
598- logger .Warning (err )
599- return polkit .CheckAuth (polkitActionChangeOwnData , string (sender ), nil )
600- }
601- caller := mapMethodCaller (execPath , cmdLine )
602- if methodCallerControlCenter == caller {
603- return nil
604- } else {
605- logger .Infof ("not allow %v call this method ,need check auth by polkit" , caller )
606- return polkit .CheckAuth (polkitActionChangeOwnData , string (sender ), nil )
607- }
608-
609- } else {
610- logger .Info ("caller's uid is 0,allow to call this method" )
611- return nil
612- }
613- }
614-
615486type UpdateSourceConfig map [config.RepoType ]* RepoInfo
616487type RepoInfo struct {
617488 /*
0 commit comments