mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-05-15 00:50:25 +02:00
Added pin protection to mobile lib.
This commit is contained in:
committed by
Cuong Manh Le
parent
9515db7faf
commit
faa0ed06b6
+15
-1
@@ -802,6 +802,15 @@ func RunMobile(appConfig *AppConfig, appCallback *AppCallback, stopCh chan struc
|
|||||||
run(appCallback, stopCh)
|
run(appCallback, stopCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckDeactivationPin checks if deactivation pin is valid
|
||||||
|
func CheckDeactivationPin(pin int64) int {
|
||||||
|
deactivationPin = pin
|
||||||
|
if err := checkDeactivationPin(nil); errors.Is(err, errInvalidDeactivationPin) {
|
||||||
|
return deactivationPinInvalidExitCode
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
// run runs ctrld cli with given app callback and stop channel.
|
// run runs ctrld cli with given app callback and stop channel.
|
||||||
func run(appCallback *AppCallback, stopCh chan struct{}) {
|
func run(appCallback *AppCallback, stopCh chan struct{}) {
|
||||||
if stopCh == nil {
|
if stopCh == nil {
|
||||||
@@ -2090,7 +2099,12 @@ func checkDeactivationPin(s service.Service) error {
|
|||||||
mainLog.Load().Err(err).Msg("could not check deactivation pin")
|
mainLog.Load().Err(err).Msg("could not check deactivation pin")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cc := newSocketControlClient(s, dir)
|
var cc *controlClient
|
||||||
|
if s == nil {
|
||||||
|
cc = newControlClient(filepath.Join(dir, ctrldControlUnixSock))
|
||||||
|
} else {
|
||||||
|
cc = newSocketControlClient(s, dir)
|
||||||
|
}
|
||||||
if cc == nil {
|
if cc == nil {
|
||||||
return nil // ctrld is not running.
|
return nil // ctrld is not running.
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,13 +61,13 @@ func mapCallback(callback AppCallback) cli.AppCallback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) Stop() bool {
|
func (c *Controller) Stop(Pin int64) int {
|
||||||
if c.stopCh != nil {
|
errorCode := cli.CheckDeactivationPin(Pin)
|
||||||
|
if errorCode == 0 && c.stopCh != nil {
|
||||||
close(c.stopCh)
|
close(c.stopCh)
|
||||||
c.stopCh = nil
|
c.stopCh = nil
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
return errorCode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) IsRunning() bool {
|
func (c *Controller) IsRunning() bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user