mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
Added pin protection to mobile lib.
This commit is contained in:
committed by
Cuong Manh Le
parent
9515db7faf
commit
faa0ed06b6
@@ -802,6 +802,15 @@ func RunMobile(appConfig *AppConfig, appCallback *AppCallback, stopCh chan struc
|
||||
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.
|
||||
func run(appCallback *AppCallback, stopCh chan struct{}) {
|
||||
if stopCh == nil {
|
||||
@@ -2090,7 +2099,12 @@ func checkDeactivationPin(s service.Service) error {
|
||||
mainLog.Load().Err(err).Msg("could not check deactivation pin")
|
||||
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 {
|
||||
return nil // ctrld is not running.
|
||||
}
|
||||
|
||||
@@ -61,13 +61,13 @@ func mapCallback(callback AppCallback) cli.AppCallback {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) Stop() bool {
|
||||
if c.stopCh != nil {
|
||||
func (c *Controller) Stop(Pin int64) int {
|
||||
errorCode := cli.CheckDeactivationPin(Pin)
|
||||
if errorCode == 0 && c.stopCh != nil {
|
||||
close(c.stopCh)
|
||||
c.stopCh = nil
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return errorCode
|
||||
}
|
||||
|
||||
func (c *Controller) IsRunning() bool {
|
||||
|
||||
Reference in New Issue
Block a user