Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/check empty password #663

Merged
merged 4 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pkg/app/appcommon/proc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"os"
"strings"

"github.com/google/uuid"
"github.com/skycoin/dmsg/cipher"
Expand Down Expand Up @@ -106,6 +107,48 @@ func (c *ProcConfig) Envs() []string {
return append(c.ProcEnvs, fmt.Sprintf(format, EnvProcConfig, string(c.encodeJSON())))
}

// ContainsFlag checks if a given flag has been passed to the ProcConfig.
func (c *ProcConfig) ContainsFlag(flag string) bool {
for _, arg := range c.ProcArgs {
if argEqualsFlag(arg, flag) {
return true
}
}
return false
}

// ArgVal returns the value associated in ProcConfig with a given flag.
func (c *ProcConfig) ArgVal(flag string) string {
for idx, arg := range c.ProcArgs {
if argEqualsFlag(arg, flag) && idx+1 < len(c.ProcArgs) {
return c.ProcArgs[idx+1]
}
}

return ""
}

func argEqualsFlag(arg, flag string) bool {
arg = strings.TrimSpace(arg)

// strip prefixed '-'s.
for {
if len(arg) < 1 {
return false
}
if arg[0] == '-' {
arg = arg[1:]
continue
}
break
}

// strip anything after (inclusive) of '='.
arg = strings.Split(arg, "=")[0]

return arg == flag
}

func (c *ProcConfig) encodeJSON() []byte {
b, err := json.Marshal(c)
if err != nil {
Expand Down
33 changes: 1 addition & 32 deletions pkg/app/appdisc/factory.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package appdisc

import (
"strings"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -65,7 +64,7 @@ func (f *Factory) AppUpdater(conf appcommon.ProcConfig) (Updater, bool) {
log := f.Log.WithField("appName", conf.AppName)

// Do not update in proxy discovery if passcode-protected.
if containsFlag(conf.ProcArgs, "passcode") {
if conf.ContainsFlag("passcode") && conf.ArgVal("passcode") != "" {
return &emptyUpdater{}, false
}

Expand Down Expand Up @@ -94,33 +93,3 @@ func (f *Factory) AppUpdater(conf appcommon.ProcConfig) (Updater, bool) {
return &emptyUpdater{}, false
}
}

func containsFlag(args []string, flag string) bool {
for _, arg := range args {
if argEqualsFlag(arg, flag) {
return true
}
}
return false
}

func argEqualsFlag(arg, flag string) bool {
arg = strings.TrimSpace(arg)

// strip prefixed '-'s.
for {
if len(arg) < 1 {
return false
}
if arg[0] == '-' {
arg = arg[1:]
continue
}
break
}

// strip anything after (inclusive) of '='.
arg = strings.Split(arg, "=")[0]

return arg == flag
}